UNPKG

ngx-soap-next

Version:

SOAP service for Angular

513 lines (500 loc) 17.7 kB
import { HttpClient } from '@angular/common/http'; import { EventEmitter } from 'events'; import { Observable } from 'rxjs'; import * as i0 from '@angular/core'; import { EnvironmentProviders } from '@angular/core'; interface IXmlAttribute { name: string; value: string; } /** * Custom WSDL cache interface * Allows implementing custom caching strategies for WSDL documents */ interface IWSDLCache { /** * Check if a WSDL is cached * @param key - Cache key (typically the WSDL URL) * @returns true if cached, false otherwise */ has(key: string): boolean; /** * Get a cached WSDL * @param key - Cache key (typically the WSDL URL) * @returns Cached WSDL definition or undefined if not found */ get(key: string): any; /** * Store a WSDL in cache * @param key - Cache key (typically the WSDL URL) * @param value - WSDL definition to cache */ set(key: string, value: any): void; } interface IWsdlBaseOptions { /** Key for XML attributes in parsed objects (default: 'attributes') */ attributesKey?: string; /** Key for element text values in parsed objects (default: '$value') */ valueKey?: string; /** Key for raw XML in parsed objects (default: '$xml') */ xmlKey?: string; /** Override root element namespace and attributes */ overrideRootElement?: { namespace: string; xmlnsAttributes?: IXmlAttribute[]; }; /** * Override element keys during WSDL parsing * Allows renaming elements to avoid conflicts or match expected names * @example { overrideElementKey: { 'OldElementName': 'NewElementName' } } */ overrideElementKey?: { [key: string]: string; }; /** Namespaces to ignore during parsing */ ignoredNamespaces?: boolean | string[] | { namespaces?: string[]; override?: boolean; }; /** Ignore base namespaces during serialization */ ignoreBaseNameSpaces?: boolean; /** Control XML escaping for special characters (default: true) */ escapeXML?: boolean; /** Return SOAP Faults as data instead of throwing errors (default: false) */ returnFault?: boolean; /** Treat xsi:nil as null instead of empty object (default: false) */ handleNilAsNull?: boolean; /** Headers to include in WSDL HTTP requests */ wsdl_headers?: { [key: string]: any; }; /** Options for WSDL HTTP requests */ wsdl_options?: { [key: string]: any; }; /** Add namespace to array elements (default: false) */ namespaceArrayElements?: boolean; /** Use self-closing tags for empty elements: <Tag /> instead of <Tag></Tag> (default: false) */ useEmptyTag?: boolean; /** Preserve leading and trailing whitespace in text content (default: false) */ preserveWhitespace?: boolean; /** Replace non-identifier characters in operation names with underscores (default: false) */ normalizeNames?: boolean; /** Hide stack traces in error messages (default: false) */ suppressStack?: boolean; /** Force schema xmlns usage even when not required (default: false) */ forceUseSchemaXmlns?: boolean; /** Custom envelope key prefix (default: 'soap') */ envelopeKey?: string; /** Override the suffix for promise-based methods (default: 'Async') */ overridePromiseSuffix?: string; } interface Definitions { descriptions: object; ignoredNamespaces: string[]; messages: WsdlMessages; portTypes: WsdlPortTypes; bindings: WsdlBindings; services: WsdlServices; schemas: WsdlSchemas; valueKey: string; xmlKey: string; xmlns: WsdlXmlns; '$targetNamespace': string; '$name': string; } interface WsdlSchemas { [prop: string]: WsdlSchema; } interface WsdlSchema extends XsdTypeBase { children: any[]; complexTypes?: WsdlElements; elements?: WsdlElements; includes: any[]; name: string; nsName: string; prefix: string; types?: WsdlElements; xmlns: WsdlXmlns; } interface WsdlElements { [prop: string]: XsdElement; } type XsdElement = XsdElementType | XsdComplexType; interface WsdlXmlns { wsu?: string; wsp?: string; wsam?: string; soap?: string; tns?: string; xsd?: string; __tns__?: string; [prop: string]: string | void; } interface XsdComplexType extends XsdTypeBase { children: XsdElement[] | void; name: string; nsName: string; prefix: string; '$name': string; [prop: string]: any; } interface XsdElementType extends XsdTypeBase { children: XsdElement[] | void; name: string; nsName: string; prefix: string; targetNSAlias: string; targetNamespace: string; '$lookupType': string; '$lookupTypes': any[]; '$name': string; '$type': string; [prop: string]: any; } interface WsdlMessages { [prop: string]: WsdlMessage; } interface WsdlMessage extends XsdTypeBase { element: XsdElement; parts: { [prop: string]: any; }; '$name': string; } interface WsdlPortTypes { [prop: string]: WsdlPortType; } interface WsdlPortType extends XsdTypeBase { methods: { [prop: string]: XsdElement; }; } interface WsdlBindings { [prop: string]: WsdlBinding; } interface WsdlBinding extends XsdTypeBase { methods: WsdlElements; style: string; transport: string; topElements: { [prop: string]: any; }; } interface WsdlServices { [prop: string]: WsdlService; } interface WsdlService extends XsdTypeBase { ports: { [prop: string]: any; }; } interface XsdTypeBase { ignoredNamespaces: string[]; valueKey: string; xmlKey: string; xmlns?: WsdlXmlns; } interface IOptions extends IWsdlBaseOptions { disableCache?: boolean; /** * Custom WSDL cache implementation * Allows providing a custom cache strategy for WSDL documents * @example { wsdlCache: new MyCustomCache() } */ wsdlCache?: IWSDLCache; /** Override the SOAP service endpoint address */ endpoint?: string; /** Custom envelope key prefix (default: 'soap') */ envelopeKey?: string; /** * Custom SOAP envelope namespace URL * Overrides the default SOAP 1.1 envelope URL * Will not be used when forceSoap12Headers is true * @default 'http://schemas.xmlsoap.org/soap/envelope/' * @example { envelopeSoapUrl: 'http://schemas.xmlsoap.org/soap/envelope/' } */ envelopeSoapUrl?: string; /** Angular HttpClient instance for HTTP requests */ httpClient?: HttpClient; stream?: boolean; /** Force SOAP 1.2 headers instead of SOAP 1.1 */ forceSoap12Headers?: boolean; /** Custom deserializer function */ customDeserializer?: any; /** Exchange ID for request/response tracking (auto-generated if not provided) */ exchangeId?: string; /** * Select specific service when WSDL has multiple services * If not specified, defaults to first service found * @example { serviceName: 'MyService' } */ serviceName?: string; /** * Select specific port when service has multiple ports * If not specified, defaults to first port found * @example { portName: 'MyServicePort' } */ portName?: string; /** * Response encoding charset * In browser environments, encoding is handled automatically by XMLHttpRequest * This option is provided for API compatibility with node-soap * @default 'utf-8' * @example { encoding: 'latin1' } */ encoding?: string; [key: string]: any; } interface WSDL { constructor(definition: any, uri: string, options?: IOptions): any; ignoredNamespaces: string[]; ignoreBaseNameSpaces: boolean; valueKey: string; xmlKey: string; xmlnsInEnvelope: string; onReady(callback: (err: Error) => void): void; processIncludes(callback: (err: Error) => void): void; describeServices(): { [k: string]: any; }; toXML(): string; xmlToObject(xml: any, callback?: (err: Error, result: any) => void): any; findSchemaObject(nsURI: string, qname: string): XsdElement | null | undefined; objectToDocumentXML(name: string, params: any, nsPrefix?: string, nsURI?: string, type?: string): any; objectToRpcXML(name: string, params: any, nsPrefix?: string, nsURI?: string, isParts?: any): string; isIgnoredNameSpace(ns: string): boolean; filterOutIgnoredNameSpace(ns: string): string; objectToXML(obj: any, name: string, nsPrefix?: any, nsURI?: string, isFirst?: boolean, xmlnsAttr?: any, schemaObject?: any, nsContext?: any): string; processAttributes(child: any, nsContext: any): string; findSchemaType(name: any, nsURI: any): any; findChildSchemaObject(parameterTypeObj: any, childName: any, backtrace?: any): any; uri: string; definitions: Definitions; } interface Client extends EventEmitter { constructor(wsdl: WSDL, endpoint?: string, options?: IOptions): any; addBodyAttribute(bodyAttribute: any, name?: string, namespace?: string, xmlns?: string): void; addHttpHeader(name: string, value: any): void; addSoapHeader(soapHeader: any, name?: string, namespace?: any, xmlns?: string): number; changeSoapHeader(index: number, soapHeader: any, name?: string, namespace?: string, xmlns?: string): void; clearBodyAttributes(): void; clearHttpHeaders(): void; clearSoapHeaders(): void; describe(): any; getBodyAttributes(): any[]; getHttpHeaders(): { [k: string]: string; }; getSoapHeaders(): string[]; setEndpoint(endpoint: string): void; setSOAPAction(action: string): void; setSecurity(security: ISecurity): void; wsdl: WSDL; [method: string]: ISoapMethod | WSDL | Function; call(method: string, body: any, options?: any, extraHeaders?: any): Observable<ISoapMethodResponse>; } interface ISoapMethod { (args: any, options?: any, extraHeaders?: any): Observable<ISoapMethodResponse>; } interface ISoapMethodResponse { err: any; header: any; responseBody: string; xml: string; result: any; } interface ISecurity { addOptions(options: any): void; toXML(): string; } interface BasicAuthSecurity$1 extends ISecurity { constructor(username: string, password: string, defaults?: any): any; addHeaders(headers: any): void; addOptions(options: any): void; toXML(): string; } interface BearerSecurity$1 extends ISecurity { constructor(token: string, defaults?: any): any; addHeaders(headers: any): void; addOptions(options: any): void; toXML(): string; } interface WSSecurity$1 extends ISecurity { constructor(username: string, password: string, options?: any): any; addOptions(options: any): void; toXML(): string; } interface NTLMSecurity$1 extends ISecurity { constructor(username: string, password: string, domain: string, workstation: any): any; addHeaders(headers: any): void; addOptions(options: any): void; toXML(): string; } declare function BasicAuthSecurity(username: any, password: any, defaults: any): void; declare function WSSecurity(username: any, password: any, options: any): void; declare function WSSecurityCert(privatePEM: any, publicP12PEM: any, password: any, options?: any): void; /** * WS-Security with both certificate and username token * Combines WSSecurityCert with UsernameToken for dual authentication * * @param privatePEM - Private key in PEM format * @param publicP12PEM - Public certificate in P12/PEM format * @param password - Certificate password * @param options - Additional options * @param options.username - Username for token authentication * @param options.password - Password for token authentication * @param options.passwordType - Type of password encoding ('PasswordText' or 'PasswordDigest') * @param options.hasTimeStamp - Include timestamp in security header (default: true) * @param options.hasNonce - Include nonce in security header * @param options.hasTokenCreated - Include created timestamp in token (default: true) * @param options.digestAlgorithm - Digest algorithm for signing (default: 'sha256') * @param options.signatureAlgorithm - Signature algorithm for signing * @param options.excludeReferencesFromSigning - Array of element names to exclude from signing * @param options.appendElement - Custom XML to append to security header * @param options.envelopeKey - Custom SOAP envelope prefix (default: 'soap') */ declare function WSSecurityCertWithToken(privatePEM: string | Buffer, publicP12PEM: string | Buffer, password: string, options: any): void; /** * Combined WSSecurity and WSSecurityCert * Allows using both username token and certificate security together * * @param wsSecurity - WSSecurity instance for username token * @param wsSecurityCert - WSSecurityCert instance for certificate */ declare function WSSecurityPlusCert(wsSecurity: any, wsSecurityCert: any): void; declare function BearerSecurity(token: any, defaults: any): void; declare function NTLMSecurity(username: any, password: any, domain: any, workstation: any): void; declare const security: { BasicAuthSecurity: typeof BasicAuthSecurity; BearerSecurity: typeof BearerSecurity; WSSecurity: typeof WSSecurity; WSSecurityCert: typeof WSSecurityCert; WSSecurityCertWithToken: typeof WSSecurityCertWithToken; WSSecurityPlusCert: typeof WSSecurityPlusCert; NTLMSecurity: typeof NTLMSecurity; }; /** * NgxSoapService - SOAP client service for Angular * * **Backwards Compatible:** Works with Angular 10+ (NgModule or standalone) * * This service creates SOAP clients from WSDL files and returns Promises for compatibility. * The returned Promise can be wrapped in Angular 20+ resource() or used directly. * * @example Basic usage (works in all Angular versions) * ```typescript * constructor(private soap: NgxSoapService) { * this.soap.createClient('assets/service.wsdl') * .then(client => this.client = client) * .catch(err => console.error(err)); * } * ``` * * @example Angular 20+ with resource() API * ```typescript * import { inject, resource } from '@angular/core'; * * private soap = inject(NgxSoapService); * * soapClient = resource({ * loader: () => this.soap.createClient('assets/service.wsdl') * }); * ``` * * @example Angular 16+ with signals * ```typescript * import { inject, signal } from '@angular/core'; * * private soap = inject(NgxSoapService); * client = signal<Client | null>(null); * * constructor() { * this.soap.createClient('assets/service.wsdl') * .then(client => this.client.set(client)); * } * ``` * * @since 0.10.0 */ declare class NgxSoapService { private http; constructor(http: HttpClient); /** * Creates a SOAP client from a WSDL URL * * @param wsdlUrl - URL to the WSDL file (can be relative or absolute) * @param options - Optional SOAP client configuration options * @param endpoint - Optional endpoint override (overrides WSDL endpoint) * @returns Promise that resolves to a SOAP Client * * @example * ```typescript * const client = await this.soap.createClient('assets/calculator.wsdl'); * (client as any).Add({ intA: 1, intB: 2 }).subscribe(result => { * console.log(result.AddResult); * }); * ``` */ createClient(wsdlUrl: string, options?: IOptions, endpoint?: string): Promise<Client>; static ɵfac: i0.ɵɵFactoryDeclaration<NgxSoapService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<NgxSoapService>; } /** * Provides NgxSoap services for standalone applications (Angular 14+) * * **Recommended for Angular 14+ standalone applications** * * This is the modern approach for Angular 14+ projects using standalone components. * Works seamlessly with Angular 20 features like signals, computed(), and resource(). * * @example * ```typescript * import { bootstrapApplication } from '@angular/platform-browser'; * import { provideHttpClient } from '@angular/common/http'; * import { provideNgxSoap } from 'ngx-soap-next'; * * bootstrapApplication(AppComponent, { * providers: [ * provideHttpClient(), * provideNgxSoap() * ] * }); * ``` * * @since 0.17.0 (Angular 14+) */ declare function provideNgxSoap(): EnvironmentProviders; /** * NgxSoapModule for traditional NgModule-based applications * * **Fully supported for NgModule-based applications (Angular 10+)** * * Use this module in traditional NgModule-based Angular applications. * Both NgModule and standalone approaches are fully supported for backwards compatibility. * * For new standalone applications, consider using `provideNgxSoap()` instead. * * @example NgModule-based application * ```typescript * import { NgModule } from '@angular/core'; * import { NgxSoapModule } from 'ngx-soap-next'; * import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; * * @NgModule({ * imports: [NgxSoapModule], * // Or provide HttpClient separately: * // providers: [provideHttpClient(withInterceptorsFromDi())] * }) * export class AppModule { } * ``` * * @since 0.10.0 (Angular 10+) */ declare class NgxSoapModule { static ɵfac: i0.ɵɵFactoryDeclaration<NgxSoapModule, never>; static ɵmod: i0.ɵɵNgModuleDeclaration<NgxSoapModule, never, never, never>; static ɵinj: i0.ɵɵInjectorDeclaration<NgxSoapModule>; } export { NgxSoapModule, NgxSoapService, provideNgxSoap, security }; export type { BasicAuthSecurity$1 as BasicAuthSecurity, BearerSecurity$1 as BearerSecurity, Client, IOptions, ISoapMethod, ISoapMethodResponse, IWsdlBaseOptions, NTLMSecurity$1 as NTLMSecurity, WSDL, WSSecurity$1 as WSSecurity };