[soap] Add type definition for options and HttpClient.

This commit is contained in:
mtgto
2017-03-03 20:32:19 +09:00
parent 580fac6fb4
commit e2a426db0a
2 changed files with 45 additions and 9 deletions

29
soap/index.d.ts vendored
View File

@@ -49,12 +49,31 @@ export interface Server extends events.EventEmitter {
log(type: any, data: any): any;
}
export function listen(server: any, path: string, service: any, wsdl: string): Server;
declare function createClient(wsdlPath: string, options: any, fn: (err: any, client: Client) => void): void;
declare function createClient(wsdlPath: string, options: Option, fn: (err: any, client: Client) => void): void;
export interface Option {
attributesKey?: string;
disableCache?: boolean;
endpoint?: string;
envelopeKey?: string;
escapeXML?: boolean;
forceSoap12Headers?: boolean;
httpClient?: HttpClient;
ignoreBaseNameSpaces?: boolean,
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;
wsdl_headers?: { [key: string]: any };
wsdl_options?: { [key: string]: any };
xmlKey?: string;
}
export class HttpClient {
constructor(options?: any);
buildRequest(rurl: string, data: any | string, exheaders?: any, exoptions?: any): any;
constructor(options?: Option);
buildRequest(rurl: string, data: any | string, exheaders?: { [key: string]: any }, exoptions?: { [key: string]: any }): any;
handleResponse(req: any, res: any, body: any | string): any | string;
request(rurl: string, data: any | string, callback: (err: any, res: any, body: any | string) => void, exheaders?: any, exoptions?: any): any;
requestStream(rurl: string, data: any | string, exheaders?: any, exoptions?: any): any;
request(rurl: string, data: any | string, callback: (err: any, res: any, body: any | string) => void, exheaders?: { [key: string]: any }, exoptions?: { [key: string]: any }): any;
requestStream(rurl: string, data: any | string, exheaders?: { [key: string]: any }, exoptions?: { [key: string]: any }): any;
}

View File

@@ -1,10 +1,27 @@
import * as soap from 'soap';
import * as events from 'events';
import * as fs from "fs";
import * as http from "http";
import * as fs from 'fs';
import * as http from 'http';
const url = 'http://example.com/wsdl?wsdl';
const wsdlOptions = { name: 'value', httpClient: new soap.HttpClient() };
// wsdlOptions set only default values
const wsdlOptions = <soap.Option>{
attributesKey: 'attributes',
disableCache: false,
endpoint: url,
envelopeKey: 'soap',
escapeXML: true,
forceSoap12Headers: false,
httpClient: new soap.HttpClient(),
ignoreBaseNameSpaces: false,
ignoredNamespaces: ['tns', 'targetNamespace', 'typedNamespace'],
request: require('request'),
stream: false,
wsdl_headers: [],
wsdl_options: [],
valueKey: '$value',
xmlKey: '$xml'
};
soap.createClient(url, wsdlOptions, function(err: any, client: soap.Client) {
let securityOptions = { hasTimeStamp: false };
@@ -74,7 +91,7 @@ var myService = {
var xml = fs.readFileSync('myservice.wsdl', 'utf8'),
server = http.createServer(function(request,response) {
response.end("404: Not Found: " + request.url);
response.end('404: Not Found: ' + request.url);
});
server.listen(8000);