UNPKG

ngx-soap

Version:

SOAP service for Angular

1,204 lines (1,196 loc) 140 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('sax'), require('lodash'), require('crypto-js/sha1'), require('crypto-js/enc-base64'), require('buffer'), require('url'), require('assert'), require('uuid/v4'), require('rxjs'), require('rxjs/operators'), require('@angular/common/http')) : typeof define === 'function' && define.amd ? define('ngx-soap', ['exports', '@angular/core', 'sax', 'lodash', 'crypto-js/sha1', 'crypto-js/enc-base64', 'buffer', 'url', 'assert', 'uuid/v4', 'rxjs', 'rxjs/operators', '@angular/common/http'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['ngx-soap'] = {}, global.ng.core, global.sax, global._, global.sha1, global.Base64, global.buffer, global.url, global.assert, global.uuid4, global.rxjs, global.rxjs.operators, global.ng.common.http)); }(this, (function (exports, i0, sax, _, sha1, Base64, buffer, url, assert, uuid4, rxjs, operators, i1) { 'use strict'; function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var sha1__default = /*#__PURE__*/_interopDefaultLegacy(sha1); var Base64__default = /*#__PURE__*/_interopDefaultLegacy(Base64); var uuid4__default = /*#__PURE__*/_interopDefaultLegacy(uuid4); /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = function () { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __rest(s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; } function __decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } function __param(paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); }; } function __metadata(metadataKey, metadataValue) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); } function __awaiter(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function () { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } var __createBinding = Object.create ? (function (o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } }); }) : (function (o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; }); function __exportStar(m, o) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p); } function __values(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } function __spreadArrays() { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; } ; function __await(v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } function __asyncGenerator(thisArg, _arguments, generator) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var g = generator.apply(thisArg, _arguments || []), i, q = []; return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } function fulfill(value) { resume("next", value); } function reject(value) { resume("throw", value); } function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } } function __asyncDelegator(o) { var i, p; return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i; function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; } } function __asyncValues(o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); } } function __makeTemplateObject(cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; } ; var __setModuleDefault = Object.create ? (function (o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function (o, v) { o["default"] = v; }; function __importStar(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; } function __importDefault(mod) { return (mod && mod.__esModule) ? mod : { default: mod }; } function __classPrivateFieldGet(receiver, privateMap) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return privateMap.get(receiver); } function __classPrivateFieldSet(receiver, privateMap, value) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to set private field on non-instance"); } privateMap.set(receiver, value); return value; } 'use strict'; var NamespaceScope = /** @class */ (function () { function NamespaceScope(parent) { this.getNamespaceURI = function (prefix, localOnly) { switch (prefix) { case 'xml': return 'http://www.w3.org/XML/1998/namespace'; case 'xmlns': return 'http://www.w3.org/2000/xmlns/'; default: var nsUri = this.namespaces[prefix]; /*jshint -W116 */ if (nsUri != null) { return nsUri.uri; } else if (!localOnly && this.parent) { return this.parent.getNamespaceURI(prefix); } else { return null; } } }; this.getNamespaceMapping = function (prefix) { switch (prefix) { case 'xml': return { uri: 'http://www.w3.org/XML/1998/namespace', prefix: 'xml', declared: true }; case 'xmlns': return { uri: 'http://www.w3.org/2000/xmlns/', prefix: 'xmlns', declared: true }; default: var mapping = this.namespaces[prefix]; /*jshint -W116 */ if (mapping != null) { return mapping; } else if (this.parent) { return this.parent.getNamespaceMapping(prefix); } else { return null; } } }; this.getPrefix = function (nsUri, localOnly) { switch (nsUri) { case 'http://www.w3.org/XML/1998/namespace': return 'xml'; case 'http://www.w3.org/2000/xmlns/': return 'xmlns'; default: for (var p in this.namespaces) { if (this.namespaces[p].uri === nsUri) { return p; } } if (!localOnly && this.parent) { return this.parent.getPrefix(nsUri); } else { return null; } } }; if (!(this instanceof NamespaceScope)) { return new NamespaceScope(parent); } this.parent = parent; this.namespaces = {}; } return NamespaceScope; }()); var NamespaceContext = /** @class */ (function () { function NamespaceContext() { this.addNamespace = function (prefix, nsUri, localOnly) { if (this.getNamespaceURI(prefix, localOnly) === nsUri) { return false; } if (this.currentScope) { this.currentScope.namespaces[prefix] = { uri: nsUri, prefix: prefix, declared: false }; return true; } return false; }; this.pushContext = function () { var scope = new NamespaceScope(this.currentScope); this.scopes.push(scope); this.currentScope = scope; return scope; }; this.popContext = function () { var scope = this.scopes.pop(); if (scope) { this.currentScope = scope.parent; } else { this.currentScope = null; } return scope; }; this.getNamespaceURI = function (prefix, localOnly) { return this.currentScope && this.currentScope.getNamespaceURI(prefix, localOnly); }; this.getPrefix = function (nsUri, localOnly) { return this.currentScope && this.currentScope.getPrefix(nsUri, localOnly); }; this.registerNamespace = function (nsUri) { var prefix = this.getPrefix(nsUri); if (prefix) { // If the namespace has already mapped to a prefix return prefix; } else { // Try to generate a unique namespace while (true) { prefix = 'ns' + (++this.prefixCount); if (!this.getNamespaceURI(prefix)) { // The prefix is not used break; } } } this.addNamespace(prefix, nsUri, true); return prefix; }; this.declareNamespace = function (prefix, nsUri) { if (this.currentScope) { var mapping = this.currentScope.getNamespaceMapping(prefix); if (mapping && mapping.uri === nsUri && mapping.declared) { return false; } this.currentScope.namespaces[prefix] = { uri: nsUri, prefix: prefix, declared: true }; return true; } return false; }; if (!(this instanceof NamespaceContext)) { return new NamespaceContext(); } this.scopes = []; this.pushContext(); this.prefixCount = 0; } return NamespaceContext; }()); var passwordDigest = function passwordDigest(nonce, created, password) { var rawNonce = new buffer.Buffer(nonce || '', 'base64').toString('binary'); return Base64__default['default'].stringify(sha1__default['default'](rawNonce + created + password, '')); }; var TNS_PREFIX = '__tns__'; // Prefix for targetNamespace /** * Find a key from an object based on the value * @param Namespace prefix/uri mapping * @param nsURI value * @returns The matching key */ var findPrefix = function (xmlnsMapping, nsURI) { for (var n in xmlnsMapping) { if (n === TNS_PREFIX) { continue; } if (xmlnsMapping[n] === nsURI) { return n; } } }; /* * Copyright (c) 2011 Vinay Pulim <vinay@milewise.com> * MIT Licensed * */ /*jshint proto:true*/ "use strict"; var stripBom = function (x) { // Catches EFBBBF (UTF-8 BOM) because the buffer-to-string // conversion translates it to FEFF (UTF-16 BOM) if (x.charCodeAt(0) === 0xFEFF) { return x.slice(1); } return x; }; var ɵ0 = stripBom; var TNS_PREFIX$1 = TNS_PREFIX; var findPrefix$1 = findPrefix; var Primitives = { string: 1, boolean: 1, decimal: 1, float: 1, double: 1, anyType: 1, byte: 1, int: 1, long: 1, short: 1, negativeInteger: 1, nonNegativeInteger: 1, positiveInteger: 1, nonPositiveInteger: 1, unsignedByte: 1, unsignedInt: 1, unsignedLong: 1, unsignedShort: 1, duration: 0, dateTime: 0, time: 0, date: 0, gYearMonth: 0, gYear: 0, gMonthDay: 0, gDay: 0, gMonth: 0, hexBinary: 0, base64Binary: 0, anyURI: 0, QName: 0, NOTATION: 0 }; function splitQName(nsName) { var i = typeof nsName === 'string' ? nsName.indexOf(':') : -1; return i < 0 ? { prefix: TNS_PREFIX$1, name: nsName } : { prefix: nsName.substring(0, i), name: nsName.substring(i + 1) }; } function xmlEscape(obj) { if (typeof (obj) === 'string') { if (obj.substr(0, 9) === '<![CDATA[' && obj.substr(-3) === "]]>") { return obj; } return obj .replace(/&/g, '&amp;') .replace(/</g, '&lt;') .replace(/>/g, '&gt;') .replace(/"/g, '&quot;') .replace(/'/g, '&apos;'); } return obj; } var trimLeft = /^[\s\xA0]+/; var trimRight = /[\s\xA0]+$/; function trim(text) { return text.replace(trimLeft, '').replace(trimRight, ''); } function deepMerge(destination, source) { return _.mergeWith(destination || {}, source, function (a, b) { return _.isArray(a) ? a.concat(b) : undefined; }); } var Element = function (nsName, attrs, options) { var parts = splitQName(nsName); this.nsName = nsName; this.prefix = parts.prefix; this.name = parts.name; this.children = []; this.xmlns = {}; this._initializeOptions(options); for (var key in attrs) { var match = /^xmlns:?(.*)$/.exec(key); if (match) { this.xmlns[match[1] ? match[1] : TNS_PREFIX$1] = attrs[key]; } else { if (key === 'value') { this[this.valueKey] = attrs[key]; } else { this['$' + key] = attrs[key]; } } } if (this.$targetNamespace !== undefined) { // Add targetNamespace to the mapping this.xmlns[TNS_PREFIX$1] = this.$targetNamespace; } }; var ɵ1 = Element; Element.prototype._initializeOptions = function (options) { if (options) { this.valueKey = options.valueKey || '$value'; this.xmlKey = options.xmlKey || '$xml'; this.ignoredNamespaces = options.ignoredNamespaces || []; } else { this.valueKey = '$value'; this.xmlKey = '$xml'; this.ignoredNamespaces = []; } }; Element.prototype.deleteFixedAttrs = function () { this.children && this.children.length === 0 && delete this.children; this.xmlns && Object.keys(this.xmlns).length === 0 && delete this.xmlns; delete this.nsName; delete this.prefix; delete this.name; }; Element.prototype.allowedChildren = []; Element.prototype.startElement = function (stack, nsName, attrs, options) { if (!this.allowedChildren) { return; } var ChildClass = this.allowedChildren[splitQName(nsName).name], element = null; if (ChildClass) { stack.push(new ChildClass(nsName, attrs, options)); } else { this.unexpected(nsName); } }; Element.prototype.endElement = function (stack, nsName) { if (this.nsName === nsName) { if (stack.length < 2) return; var parent = stack[stack.length - 2]; if (this !== stack[0]) { _.defaultsDeep(stack[0].xmlns, this.xmlns); // delete this.xmlns; parent.children.push(this); parent.addChild(this); } stack.pop(); } }; Element.prototype.addChild = function (child) { return; }; Element.prototype.unexpected = function (name) { throw new Error('Found unexpected element (' + name + ') inside ' + this.nsName); }; Element.prototype.description = function (definitions) { return this.$name || this.name; }; Element.prototype.init = function () { }; Element.createSubClass = function () { var root = this; var subElement = function () { root.apply(this, arguments); this.init(); }; // inherits(subElement, root); subElement.prototype.__proto__ = root.prototype; return subElement; }; var ElementElement = Element.createSubClass(); var AnyElement = Element.createSubClass(); var InputElement = Element.createSubClass(); var OutputElement = Element.createSubClass(); var SimpleTypeElement = Element.createSubClass(); var RestrictionElement = Element.createSubClass(); var ExtensionElement = Element.createSubClass(); var ChoiceElement = Element.createSubClass(); var EnumerationElement = Element.createSubClass(); var ComplexTypeElement = Element.createSubClass(); var ComplexContentElement = Element.createSubClass(); var SimpleContentElement = Element.createSubClass(); var SequenceElement = Element.createSubClass(); var AllElement = Element.createSubClass(); var MessageElement = Element.createSubClass(); var DocumentationElement = Element.createSubClass(); var SchemaElement = Element.createSubClass(); var TypesElement = Element.createSubClass(); var OperationElement = Element.createSubClass(); var PortTypeElement = Element.createSubClass(); var BindingElement = Element.createSubClass(); var PortElement = Element.createSubClass(); var ServiceElement = Element.createSubClass(); var DefinitionsElement = Element.createSubClass(); var ElementTypeMap = { types: [TypesElement, 'schema documentation'], schema: [SchemaElement, 'element complexType simpleType include import'], element: [ElementElement, 'annotation complexType'], any: [AnyElement, ''], simpleType: [SimpleTypeElement, 'restriction'], restriction: [RestrictionElement, 'enumeration all choice sequence'], extension: [ExtensionElement, 'all sequence choice'], choice: [ChoiceElement, 'element sequence choice any'], // group: [GroupElement, 'element group'], enumeration: [EnumerationElement, ''], complexType: [ComplexTypeElement, 'annotation sequence all complexContent simpleContent choice'], complexContent: [ComplexContentElement, 'extension'], simpleContent: [SimpleContentElement, 'extension'], sequence: [SequenceElement, 'element sequence choice any'], all: [AllElement, 'element choice'], service: [ServiceElement, 'port documentation'], port: [PortElement, 'address documentation'], binding: [BindingElement, '_binding SecuritySpec operation documentation'], portType: [PortTypeElement, 'operation documentation'], message: [MessageElement, 'part documentation'], operation: [OperationElement, 'documentation input output fault _operation'], input: [InputElement, 'body SecuritySpecRef documentation header'], output: [OutputElement, 'body SecuritySpecRef documentation header'], fault: [Element, '_fault documentation'], definitions: [DefinitionsElement, 'types message portType binding service import documentation'], documentation: [DocumentationElement, ''] }; function mapElementTypes(types) { var rtn = {}; types = types.split(' '); types.forEach(function (type) { rtn[type.replace(/^_/, '')] = (ElementTypeMap[type] || [Element])[0]; }); return rtn; } for (var n in ElementTypeMap) { var v = ElementTypeMap[n]; v[0].prototype.allowedChildren = mapElementTypes(v[1]); } MessageElement.prototype.init = function () { this.element = null; this.parts = null; }; SchemaElement.prototype.init = function () { this.complexTypes = {}; this.types = {}; this.elements = {}; this.includes = []; }; TypesElement.prototype.init = function () { this.schemas = {}; }; OperationElement.prototype.init = function () { this.input = null; this.output = null; this.inputSoap = null; this.outputSoap = null; this.style = ''; this.soapAction = ''; }; PortTypeElement.prototype.init = function () { this.methods = {}; }; BindingElement.prototype.init = function () { this.transport = ''; this.style = ''; this.methods = {}; }; PortElement.prototype.init = function () { this.location = null; }; ServiceElement.prototype.init = function () { this.ports = {}; }; DefinitionsElement.prototype.init = function () { if (this.name !== 'definitions') this.unexpected(this.nsName); this.messages = {}; this.portTypes = {}; this.bindings = {}; this.services = {}; this.schemas = {}; }; DocumentationElement.prototype.init = function () { }; SchemaElement.prototype.merge = function (source) { assert.ok(source instanceof SchemaElement); if (this.$targetNamespace === source.$targetNamespace) { _.merge(this.complexTypes, source.complexTypes); _.merge(this.types, source.types); _.merge(this.elements, source.elements); _.merge(this.xmlns, source.xmlns); } return this; }; SchemaElement.prototype.addChild = function (child) { if (child.$name in Primitives) return; if (child.name === 'include' || child.name === 'import') { var location = child.$schemaLocation || child.$location; if (location) { this.includes.push({ namespace: child.$namespace || child.$targetNamespace || this.$targetNamespace, location: location }); } } else if (child.name === 'complexType') { this.complexTypes[child.$name] = child; } else if (child.name === 'element') { this.elements[child.$name] = child; } else if (child.$name) { this.types[child.$name] = child; } this.children.pop(); // child.deleteFixedAttrs(); }; //fix#325 TypesElement.prototype.addChild = function (child) { assert.ok(child instanceof SchemaElement); var targetNamespace = child.$targetNamespace; if (!this.schemas.hasOwnProperty(targetNamespace)) { this.schemas[targetNamespace] = child; } else { console.error('Target-Namespace "' + targetNamespace + '" already in use by another Schema!'); } }; InputElement.prototype.addChild = function (child) { if (child.name === 'body') { this.use = child.$use; if (this.use === 'encoded') { this.encodingStyle = child.$encodingStyle; } this.children.pop(); } }; OutputElement.prototype.addChild = function (child) { if (child.name === 'body') { this.use = child.$use; if (this.use === 'encoded') { this.encodingStyle = child.$encodingStyle; } this.children.pop(); } }; OperationElement.prototype.addChild = function (child) { if (child.name === 'operation') { this.soapAction = child.$soapAction || ''; this.style = child.$style || ''; this.children.pop(); } }; BindingElement.prototype.addChild = function (child) { if (child.name === 'binding') { this.transport = child.$transport; this.style = child.$style; this.children.pop(); } }; PortElement.prototype.addChild = function (child) { if (child.name === 'address' && typeof (child.$location) !== 'undefined') { this.location = child.$location; } }; DefinitionsElement.prototype.addChild = function (child) { var self = this; if (child instanceof TypesElement) { // Merge types.schemas into definitions.schemas _.merge(self.schemas, child.schemas); } else if (child instanceof MessageElement) { self.messages[child.$name] = child; } else if (child.name === 'import') { self.schemas[child.$namespace] = new SchemaElement(child.$namespace, {}); self.schemas[child.$namespace].addChild(child); } else if (child instanceof PortTypeElement) { self.portTypes[child.$name] = child; } else if (child instanceof BindingElement) { if (child.transport === 'http://schemas.xmlsoap.org/soap/http' || child.transport === 'http://www.w3.org/2003/05/soap/bindings/HTTP/') self.bindings[child.$name] = child; } else if (child instanceof ServiceElement) { self.services[child.$name] = child; } else if (child instanceof DocumentationElement) { } this.children.pop(); }; MessageElement.prototype.postProcess = function (definitions) { var part = null; var child = undefined; var children = this.children || []; var ns = undefined; var nsName = undefined; var i = undefined; var type = undefined; for (i in children) { if ((child = children[i]).name === 'part') { part = child; break; } } if (!part) { return; } if (part.$element) { var lookupTypes = [], elementChildren = void 0; delete this.parts; nsName = splitQName(part.$element); ns = nsName.prefix; var schema = definitions.schemas[definitions.xmlns[ns]]; this.element = schema.elements[nsName.name]; if (!this.element) { // debug(nsName.name + " is not present in wsdl and cannot be processed correctly."); return; } this.element.targetNSAlias = ns; this.element.targetNamespace = definitions.xmlns[ns]; // set the optional $lookupType to be used within `client#_invoke()` when // calling `wsdl#objectToDocumentXML() this.element.$lookupType = part.$element; elementChildren = this.element.children; // get all nested lookup types (only complex types are followed) if (elementChildren.length > 0) { for (i = 0; i < elementChildren.length; i++) { lookupTypes.push(this._getNestedLookupTypeString(elementChildren[i])); } } // if nested lookup types where found, prepare them for furter usage if (lookupTypes.length > 0) { lookupTypes = lookupTypes. join('_'). split('_'). filter(function removeEmptyLookupTypes(type) { return type !== '^'; }); var schemaXmlns = definitions.schemas[this.element.targetNamespace].xmlns; for (i = 0; i < lookupTypes.length; i++) { lookupTypes[i] = this._createLookupTypeObject(lookupTypes[i], schemaXmlns); } } this.element.$lookupTypes = lookupTypes; if (this.element.$type) { type = splitQName(this.element.$type); var typeNs = schema.xmlns && schema.xmlns[type.prefix] || definitions.xmlns[type.prefix]; if (typeNs) { if (type.name in Primitives) { // this.element = this.element.$type; } else { // first check local mapping of ns alias to namespace schema = definitions.schemas[typeNs]; var ctype = schema.complexTypes[type.name] || schema.types[type.name] || schema.elements[type.name]; if (ctype) { this.parts = ctype.description(definitions, schema.xmlns); } } } } else { var method = this.element.description(definitions, schema.xmlns); this.parts = method[nsName.name]; } this.children.splice(0, 1); } else { // rpc encoding this.parts = {}; delete this.element; for (i = 0; part = this.children[i]; i++) { if (part.name === 'documentation') { // <wsdl:documentation can be present under <wsdl:message> continue; } assert.ok(part.name === 'part', 'Expected part element'); nsName = splitQName(part.$type); ns = definitions.xmlns[nsName.prefix]; type = nsName.name; var schemaDefinition = definitions.schemas[ns]; if (typeof schemaDefinition !== 'undefined') { this.parts[part.$name] = definitions.schemas[ns].types[type] || definitions.schemas[ns].complexTypes[type]; } else { this.parts[part.$name] = part.$type; } if (typeof this.parts[part.$name] === 'object') { this.parts[part.$name].prefix = nsName.prefix; this.parts[part.$name].xmlns = ns; } this.children.splice(i--, 1); } } this.deleteFixedAttrs(); }; /** * Takes a given namespaced String(for example: 'alias:property') and creates a lookupType * object for further use in as first (lookup) `parameterTypeObj` within the `objectToXML` * method and provides an entry point for the already existing code in `findChildSchemaObject`. * * @method _createLookupTypeObject * @param {String} nsString The NS String (for example "alias:type"). * @param {Object} xmlns The fully parsed `wsdl` definitions object (including all schemas). * @returns {Object} * @private */ MessageElement.prototype._createLookupTypeObject = function (nsString, xmlns) { var splittedNSString = splitQName(nsString), nsAlias = splittedNSString.prefix, splittedName = splittedNSString.name.split('#'), type = splittedName[0], name = splittedName[1], lookupTypeObj = {}; lookupTypeObj.$namespace = xmlns[nsAlias]; lookupTypeObj.$type = nsAlias + ':' + type; lookupTypeObj.$name = name; return lookupTypeObj; }; /** * Iterates through the element and every nested child to find any defined `$type` * property and returns it in a underscore ('_') separated String (using '^' as default * value if no `$type` property was found). * * @method _getNestedLookupTypeString * @param {Object} element The element which (probably) contains nested `$type` values. * @returns {String} * @private */ MessageElement.prototype._getNestedLookupTypeString = function (element) { var resolvedType = '^', excluded = this.ignoredNamespaces.concat('xs'); // do not process $type values wich start with if (element.hasOwnProperty('$type') && typeof element.$type === 'string') { if (excluded.indexOf(element.$type.split(':')[0]) === -1) { resolvedType += ('_' + element.$type + '#' + element.$name); } } if (element.children.length > 0) { var self_1 = this; element.children.forEach(function (child) { var resolvedChildType = self_1._getNestedLookupTypeString(child).replace(/\^_/, ''); if (resolvedChildType && typeof resolvedChildType === 'string') { resolvedType += ('_' + resolvedChildType); } }); } return resolvedType; }; OperationElement.prototype.postProcess = function (definitions, tag) { var children = this.children; for (var i = 0, child = void 0; child = children[i]; i++) { if (child.name !== 'input' && child.name !== 'output') continue; if (tag === 'binding') { this[child.name] = child; children.splice(i--, 1); continue; } var messageName = splitQName(child.$message).name; var message = definitions.messages[messageName]; message.postProcess(definitions); if (message.element) { definitions.messages[message.element.$name] = message; this[child.name] = message.element; } else { this[child.name] = message; } children.splice(i--, 1); } this.deleteFixedAttrs(); }; PortTypeElement.prototype.postProcess = function (definitions) { var children = this.children; if (typeof children === 'undefined') return; for (var i = 0, child = void 0; child = children[i]; i++) { if (child.name !== 'operation') continue; child.postProcess(definitions, 'portType'); this.methods[child.$name] = child; children.splice(i--, 1); } delete this.$name; this.deleteFixedAttrs(); }; BindingElement.prototype.postProcess = function (definitions) { var type = splitQName(this.$type).name, portType = definitions.portTypes[type], style = this.style, children = this.children; if (portType) { portType.postProcess(definitions); this.methods = portType.methods; for (var i = 0, child = void 0; child = children[i]; i++) { if (child.name !== 'operation') continue; child.postProcess(definitions, 'binding'); children.splice(i--, 1); child.style || (child.style = style); var method = this.methods[child.$name]; if (method) { method.style = child.style; method.soapAction = child.soapAction; method.inputSoap = child.input || null; method.outputSoap = child.output || null; method.inputSoap && method.inputSoap.deleteFixedAttrs(); method.outputSoap && method.outputSoap.deleteFixedAttrs(); } } } delete this.$name; delete this.$type; this.deleteFixedAttrs(); }; ServiceElement.prototype.postProcess = function (definitions) { var children = this.children, bindings = definitions.bindings; if (children && children.length > 0) { for (var i = 0, child = void 0; child = children[i]; i++) { if (child.name !== 'port') continue; var bindingName = splitQName(child.$binding).name; var binding = bindings[bindingName]; if (binding) { binding.postProcess(definitions); this.ports[child.$name] = { location: child.location, binding: binding }; children.splice(i--, 1); } } } delete this.$name; this.deleteFixedAttrs(); }; SimpleTypeElement.prototype.description = function (definitions) { var children = this.children; for (var i = 0, child = void 0; child = children[i]; i++) { if (child instanceof RestrictionElement) return this.$name + "|" + child.description(); } return {}; }; RestrictionElement.prototype.description = function (definitions, xmlns) { var children = this.children; var desc; for (var i = 0, child = void 0; child = children[i]; i++) { if (child instanceof SequenceElement || child instanceof ChoiceElement) { desc = child.description(definitions, xmlns); break; } } if (desc && this.$base) { var type = splitQName(this.$base), typeName = type.name, ns = xmlns && xmlns[type.prefix] || definitions.xmlns[type.prefix], schema_1 = definitions.schemas[ns], typeElement_1 = schema_1 && (schema_1.complexTypes[typeName] || schema_1.types[typeName] || schema_1.elements[typeName]); desc.getBase = function () { return typeElement_1.description(definitions, schema_1.xmlns); }; return desc; } // then simple element var base = this.$base ? this.$base + "|" : ""; return base + this.children.map(function (child) { return child.description(); }).join(","); }; ExtensionElement.prototype.description = function (definitions, xmlns) { var children = this.children; var desc = {}; for (var i = 0, child = void 0; child = children[i]; i++) { if (child instanceof SequenceElement || child instanceof ChoiceElement) { desc = child.description(definitions, xmlns); } } if (this.$base) { var type = splitQName(this.$base), typeName = type.name, ns = xmlns && xmlns[type.prefix] || definitions.xmlns[type.prefix], schema = definitions.schemas[ns]; if (typeName in Primitives) { return this.$base; } else { var typeElement = schema && (schema.complexTypes[typeName] || schema.types[typeName] || schema.elements[typeName]); if (typeElement) { var base = typeElement.description(definitions, schema.xmlns); desc = _.defaultsDeep(base, desc); } } } return desc; }; EnumerationElement.prototype.description = function () { return this[this.valueKey]; }; ComplexTypeElement.prototype.description = function (definitions, xmlns) { var children = this.children || []; for (var i = 0, child = void 0; child = children[i]; i++) { if (child instanceof ChoiceElement || child instanceof SequenceElement || child instanceof AllElement || child instanceof SimpleContentElement || child instanceof ComplexContentElement) { return child.description(definitions, xmlns); } } return {}; }; ComplexContentElement.prototype.description = function (definitions, xmlns) { var children = this.children; for (var i = 0, child = voi