Added missing definitions

This commit is contained in:
Jonathan Jayet
2017-03-22 12:38:52 +01:00
parent 718ba6d3d4
commit 0db5feb77c
2 changed files with 51 additions and 40 deletions

16
soap/index.d.ts vendored
View File

@@ -1,4 +1,4 @@
// Type definitions for soap
// Type definitions for soap 0.18
// Project: https://www.npmjs.com/package/soap
// Definitions by: Leo Liang <https://github.com/aleung>, Cage Fox <https://github.com/cagefox>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -11,7 +11,15 @@ interface Security {
}
export interface SoapMethod {
(args: any, callback: (err: any, result: any) => void, options?: any, extraHeaders?: any): void;
(args: any, callback: (err: any, result: any) => void, options?: any, extraHeaders?: any): void;
}
export class BasicAuthSecurity implements Security {
constructor(username: string, password: string);
}
export class BearerSecurity implements Security {
constructor(token: string);
}
export class WSSecurity implements Security {
@@ -60,8 +68,8 @@ export interface Option {
forceSoap12Headers?: boolean;
httpClient?: HttpClient;
ignoreBaseNameSpaces?: boolean,
ignoredNamespaces?: string[] | {namespaces: string[], override: boolean};
overrideRootElement?: {namespace: string, xmlnsAttributes?: string[]};
ignoredNamespaces?: string[] | { namespaces: string[], override: boolean };
overrideRootElement?: { namespace: string, xmlnsAttributes?: string[] };
request?: (options: any, callback?: (error: any, res: any, body: any) => void) => void;
stream?: boolean;
valueKey?: string;

View File

@@ -23,10 +23,13 @@ const wsdlOptions = <soap.Option>{
xmlKey: '$xml'
};
soap.createClient(url, wsdlOptions, function(err: any, client: soap.Client) {
soap.createClient(url, wsdlOptions, (err: any, client: soap.Client) => {
let securityOptions = { hasTimeStamp: false };
client.setSecurity(new soap.WSSecurity('user', 'password', securityOptions));
let defaults = {rejectUnauthorized: false};
client.setSecurity(new soap.BasicAuthSecurity('user', 'password'));
client.setSecurity(new soap.BearerSecurity('token'));
client.setSecurity(new soap.WSSecurity('user', 'password', securityOptions));
let defaults = { rejectUnauthorized: false };
client.setSecurity(new soap.ClientSSLSecurity('/path/to/key', '/path/to/cert', '/path/to/ca', defaults));
client.setSecurity(new soap.ClientSSLSecurity('/path/to/key', '/path/to/cert', defaults));
client.setSecurity(new soap.ClientSSLSecurity('/path/to/key', '/path/to/cert', '/path/to/ca'));
@@ -43,54 +46,54 @@ soap.createClient(url, wsdlOptions, function(err: any, client: soap.Client) {
client.getHttpHeaders();
client.getSoapHeaders();
client.setSOAPAction('action');
(client['create'] as soap.SoapMethod)({ name: 'value' }, function(err: any, result: any) {
(client['create'] as soap.SoapMethod)({ name: 'value' }, (err: any, result: any) => {
// result is an object
});
(client['create'] as soap.SoapMethod)({ name: 'value' }, function(err: any, result: any) {
(client['create'] as soap.SoapMethod)({ name: 'value' }, (err: any, result: any) => {
// result is an object
}, {});
client.on('request', function(obj: any) {
client.on('request', (obj: any) => {
//obj is an object
});
});
var myService = {
MyService: {
MyPort: {
MyFunction: function(args: any) {
return {
name: args.name
};
},
MyService: {
MyPort: {
MyFunction: (args: any) => {
return {
name: args.name
};
},
// This is how to define an asynchronous function.
MyAsyncFunction: function(args: any, callback: any) {
// do some work
callback({
name: args.name
});
},
// This is how to define an asynchronous function.
MyAsyncFunction: (args: any, callback: any) => {
// do some work
callback({
name: args.name
});
},
// This is how to receive incoming headers
HeadersAwareFunction: function(args: any, cb: any, headers: any) {
return {
name: headers.Token
};
},
// This is how to receive incoming headers
HeadersAwareFunction: (args: any, cb: any, headers: any) => {
return {
name: headers.Token
};
},
// You can also inspect the original `req`
reallyDeatailedFunction: function(args: any, cb: any, headers: any, req: any) {
console.log('SOAP `reallyDeatailedFunction` request from ' + req.connection.remoteAddress);
return {
name: headers.Token
};
}
}
}
};
// You can also inspect the original `req`
reallyDeatailedFunction: (args: any, cb: any, headers: any, req: any) => {
console.log('SOAP `reallyDeatailedFunction` request from ' + req.connection.remoteAddress);
return {
name: headers.Token
};
}
}
}
};
var xml = fs.readFileSync('myservice.wsdl', 'utf8'),
server = http.createServer(function(request,response) {
server = http.createServer((request, response) => {
response.end('404: Not Found: ' + request.url);
});