nestjs-soap
Advanced tools
export * from './soap.module'; | ||
export * from './soap-module-options.type'; | ||
export { Client, IOptions } from 'soap'; |
@@ -10,3 +10,3 @@ "use strict"; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
@@ -16,3 +16,2 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./soap-module-options.type"), exports); | ||
var soap_1 = require("soap"); | ||
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return soap_1.Client; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -1,1 +0,1 @@ | ||
export declare const SOAP_MODULE_OPTIONS = "SoapConfigOptions"; | ||
export declare const SOAP_MODULE_OPTIONS = "SOAP_MODULE_OPTIONS"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SOAP_MODULE_OPTIONS = void 0; | ||
exports.SOAP_MODULE_OPTIONS = 'SoapConfigOptions'; | ||
exports.SOAP_MODULE_OPTIONS = 'SOAP_MODULE_OPTIONS'; | ||
//# sourceMappingURL=soap-constants.js.map |
import { IOptions } from 'soap'; | ||
import { ModuleMetadata, Type } from '@nestjs/common'; | ||
export { Client, IOptions } from 'soap'; | ||
export declare type BasicAuth = { | ||
@@ -9,15 +10,16 @@ username: string; | ||
uri: string; | ||
name?: string; | ||
clientName: string; | ||
auth?: BasicAuth; | ||
clientOptions?: IOptions; | ||
}; | ||
export declare type SoapModuleOptionsFactoryType = Omit<SoapModuleOptions, 'clientName'>; | ||
export interface SoapModuleOptionsFactory { | ||
createSoapModuleOptions(): Promise<SoapModuleOptions> | SoapModuleOptions; | ||
createSoapModuleOptions(): Promise<SoapModuleOptionsFactoryType> | SoapModuleOptionsFactoryType; | ||
} | ||
export interface SoapModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> { | ||
name?: string; | ||
clientName: string; | ||
inject?: any[]; | ||
useClass?: Type<SoapModuleOptionsFactory>; | ||
useExisting?: Type<SoapModuleOptionsFactory>; | ||
useFactory?: (...args: any[]) => Promise<SoapModuleOptions> | SoapModuleOptions; | ||
useFactory?: (...args: any[]) => Promise<SoapModuleOptionsFactoryType> | SoapModuleOptionsFactoryType; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Client = void 0; | ||
var soap_1 = require("soap"); | ||
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return soap_1.Client; } }); | ||
//# sourceMappingURL=soap-module-options.type.js.map |
import { FactoryProvider, Provider } from '@nestjs/common'; | ||
import { SoapModuleAsyncOptions, SoapModuleOptions } from './soap-module-options.type'; | ||
export declare const buildProvidersAsync: (soapOptions: SoapModuleOptions[]) => FactoryProvider[]; | ||
export declare const createAsyncProviders: (options: SoapModuleAsyncOptions[]) => Provider[]; | ||
import { SoapModuleAsyncOptions } from './soap-module-options.type'; | ||
export declare const buildClientProvider: (clientName: string) => FactoryProvider; | ||
export declare const buildAsyncProviders: (soapAsyncOptions: SoapModuleAsyncOptions) => Provider[]; |
@@ -12,25 +12,24 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createAsyncProviders = exports.buildProvidersAsync = void 0; | ||
exports.buildAsyncProviders = exports.buildClientProvider = void 0; | ||
const soap_constants_1 = require("./soap-constants"); | ||
const soap_utils_1 = require("./soap-utils"); | ||
const buildProvider = (soapOption) => ({ | ||
provide: soapOption.name, | ||
useFactory: () => soap_utils_1.createSoapClient(soapOption), | ||
const soap_service_1 = require("./soap.service"); | ||
const buildClientProvider = (clientName) => ({ | ||
provide: clientName, | ||
useFactory: (soapService) => __awaiter(void 0, void 0, void 0, function* () { | ||
return yield soapService.createAsyncClient(); | ||
}), | ||
inject: [soap_service_1.SoapService], | ||
}); | ||
exports.buildProvidersAsync = (soapOptions) => soapOptions.map(buildProvider); | ||
exports.createAsyncProviders = (options) => { | ||
const asyncProviders = []; | ||
for (let option of options) { | ||
asyncProviders.push(...createAsyncProvider(option)); | ||
} | ||
return asyncProviders; | ||
exports.buildClientProvider = buildClientProvider; | ||
const buildAsyncProviders = (soapAsyncOptions) => { | ||
const { useClass, useExisting, useFactory } = soapAsyncOptions; | ||
if (useClass) | ||
return createUseClassProvider(soapAsyncOptions); | ||
if (useExisting) | ||
return createUseExistingProvider(soapAsyncOptions); | ||
if (useFactory) | ||
return createUseFactoryProvider(soapAsyncOptions); | ||
throw new Error('[SoapModule]: useClass, useExisting or useFactory must be filled when using async options.'); | ||
}; | ||
const createAsyncProvider = (option) => { | ||
if (option.useClass) | ||
return createUseClassProvider(option); | ||
if (option.useExisting) | ||
return createUseExistingProvider(option); | ||
if (option.useFactory) | ||
return createUseFactoryProvider(option); | ||
}; | ||
exports.buildAsyncProviders = buildAsyncProviders; | ||
const createUseClassProvider = (option) => { | ||
@@ -40,3 +39,3 @@ const useClass = option.useClass; | ||
{ | ||
provide: soap_constants_1.SOAP_MODULE_OPTIONS + option.name, | ||
provide: soap_constants_1.SOAP_MODULE_OPTIONS, | ||
useFactory: (optionsFactory) => __awaiter(void 0, void 0, void 0, function* () { return yield optionsFactory.createSoapModuleOptions(); }), | ||
@@ -54,3 +53,3 @@ inject: [useClass], | ||
{ | ||
provide: soap_constants_1.SOAP_MODULE_OPTIONS + option.name, | ||
provide: soap_constants_1.SOAP_MODULE_OPTIONS, | ||
useFactory: (optionsFactory) => __awaiter(void 0, void 0, void 0, function* () { return yield optionsFactory.createSoapModuleOptions(); }), | ||
@@ -64,3 +63,3 @@ inject: [option.useExisting], | ||
{ | ||
provide: soap_constants_1.SOAP_MODULE_OPTIONS + option.name, | ||
provide: soap_constants_1.SOAP_MODULE_OPTIONS, | ||
useFactory: option.useFactory, | ||
@@ -71,1 +70,2 @@ inject: option.inject || [], | ||
}; | ||
//# sourceMappingURL=soap-providers.js.map |
import { DynamicModule } from '@nestjs/common'; | ||
import { SoapModuleAsyncOptions, SoapModuleOptions } from './soap-module-options.type'; | ||
export declare class SoapModule { | ||
static registerAsync(soapOptions: SoapModuleOptions[]): DynamicModule; | ||
static forRoot(soapOptions: SoapModuleOptions[]): DynamicModule; | ||
static forRootAsync(soapOptions: SoapModuleAsyncOptions[]): DynamicModule; | ||
static register(soapOptions: SoapModuleOptions): DynamicModule; | ||
static forRoot(soapOptions: SoapModuleOptions): DynamicModule; | ||
static registerAsync(soapOptions: SoapModuleAsyncOptions): DynamicModule; | ||
static forRootAsync(soapOptions: SoapModuleAsyncOptions): DynamicModule; | ||
private static buildDynamicModule; | ||
private static buildAsyncDynamicModule; | ||
} |
@@ -14,34 +14,40 @@ "use strict"; | ||
const soap_constants_1 = require("./soap-constants"); | ||
const soap_utils_1 = require("./soap-utils"); | ||
const soap_service_1 = require("./soap.service"); | ||
let SoapModule = SoapModule_1 = class SoapModule { | ||
static register(soapOptions) { | ||
return this.buildDynamicModule(soapOptions); | ||
} | ||
static forRoot(soapOptions) { | ||
return this.buildDynamicModule(soapOptions); | ||
} | ||
static registerAsync(soapOptions) { | ||
const providers = soap_providers_1.buildProvidersAsync(soapOptions); | ||
return { | ||
module: SoapModule_1, | ||
providers: [...providers], | ||
exports: [...providers], | ||
return this.buildAsyncDynamicModule(soapOptions); | ||
} | ||
static forRootAsync(soapOptions) { | ||
return this.buildAsyncDynamicModule(soapOptions); | ||
} | ||
static buildDynamicModule(soapOptions) { | ||
const clientProvider = soap_providers_1.buildClientProvider(soapOptions.clientName); | ||
const optionsProvider = { | ||
provide: soap_constants_1.SOAP_MODULE_OPTIONS, | ||
useValue: soapOptions, | ||
}; | ||
} | ||
static forRoot(soapOptions) { | ||
const providers = soap_providers_1.buildProvidersAsync(soapOptions); | ||
return { | ||
module: SoapModule_1, | ||
providers: [...providers], | ||
exports: [...providers], | ||
providers: [ | ||
optionsProvider, | ||
clientProvider, | ||
soap_service_1.SoapService, | ||
], | ||
exports: [clientProvider, soap_service_1.SoapService], | ||
}; | ||
} | ||
static forRootAsync(soapOptions) { | ||
const providers = soapOptions.map((soapOption) => ({ | ||
inject: [soap_constants_1.SOAP_MODULE_OPTIONS + soapOption.name], | ||
provide: soapOption.name, | ||
useFactory: (options) => soap_utils_1.createSoapClient(options), | ||
})); | ||
const asyncProviders = soap_providers_1.createAsyncProviders(soapOptions); | ||
const exports = soapOptions.map(({ name }) => name); | ||
const imports = soap_utils_1.concatImports(soapOptions); | ||
static buildAsyncDynamicModule(soapOptions) { | ||
const clientProvider = soap_providers_1.buildClientProvider(soapOptions.clientName); | ||
const asyncOptionsProviders = soap_providers_1.buildAsyncProviders(soapOptions); | ||
return { | ||
module: SoapModule_1, | ||
exports, | ||
providers: [...asyncProviders, ...providers], | ||
imports, | ||
providers: [...asyncOptionsProviders, clientProvider, soap_service_1.SoapService], | ||
exports: [...asyncOptionsProviders, clientProvider, soap_service_1.SoapService], | ||
imports: soapOptions.imports || [], | ||
}; | ||
@@ -51,4 +57,8 @@ } | ||
SoapModule = SoapModule_1 = __decorate([ | ||
common_1.Module({}) | ||
common_1.Module({ | ||
providers: [soap_service_1.SoapService], | ||
exports: [soap_service_1.SoapService], | ||
}) | ||
], SoapModule); | ||
exports.SoapModule = SoapModule; | ||
//# sourceMappingURL=soap.module.js.map |
{ | ||
"name": "nestjs-soap", | ||
"version": "1.2.4", | ||
"version": "2.0.0", | ||
"description": "Nestjs module wrapper for soap", | ||
@@ -41,12 +41,12 @@ "main": "dist/index.js", | ||
"peerDependencies": { | ||
"@nestjs/common": "^7.0.0" | ||
"@nestjs/common": "^6.10.0 || ^7.0.0 || ^8.0.0" | ||
}, | ||
"dependencies": { | ||
"soap": "^0.37.0" | ||
"soap": "^0.42.0" | ||
}, | ||
"devDependencies": { | ||
"@nestjs/common": "^7.0.0", | ||
"@nestjs/core": "^7.0.0", | ||
"@nestjs/platform-express": "^8.0.2", | ||
"@nestjs/testing": "^7.3.2", | ||
"@nestjs/common": "^8.0.0", | ||
"@nestjs/core": "^8.0.0", | ||
"@nestjs/platform-express": "^8.0.0", | ||
"@nestjs/testing": "^8.0.0", | ||
"@types/jest": "25.1.4", | ||
@@ -60,3 +60,3 @@ "@types/node": "^13.13.14", | ||
"reflect-metadata": "^0.1.13", | ||
"rxjs": "^6.6.0", | ||
"rxjs": "^7.1.0", | ||
"supertest": "4.0.2", | ||
@@ -68,3 +68,3 @@ "ts-jest": "^26.1.2", | ||
"tslint": "5.16.0", | ||
"typescript": "3.9.6" | ||
"typescript": "4.3.5" | ||
}, | ||
@@ -71,0 +71,0 @@ "husky": { |
@@ -0,1 +1,5 @@ | ||
<a href="https://www.npmjs.com/nestjs-soap" target="_blank"><img src="https://img.shields.io/npm/v/nestjs-soap.svg" alt="NPM Version" /></a> | ||
<a href="https://www.npmjs.com/nestjs-soap" target="_blank"><img src="https://img.shields.io/npm/l/nestjs-soap.svg" alt="Package License" /></a> | ||
<a href="https://www.npmjs.com/nestjs-soap" target="_blank"><img src="https://img.shields.io/npm/dm/nestjs-soap.svg" alt="NPM Downloads" /></a> | ||
# Nestjs Soap | ||
@@ -17,3 +21,9 @@ | ||
## How to use | ||
## Documentation | ||
### [Upgrading to v2](./docs/upgrading-to-v2.md) | ||
### [v1 docs](./docs/v1.md) | ||
## Getting Started | ||
After installing the package, just import the SoapModule on the module you want to use the soap client. | ||
@@ -27,5 +37,5 @@ | ||
imports: [ | ||
SoapModule.registerAsync([ | ||
{ name: 'MY_SOAP_CLIENT', uri: 'http://yourserver/yourservice.wso?wsdl' }, | ||
]), | ||
SoapModule.register( | ||
{ clientName: 'MY_SOAP_CLIENT', uri: 'http://yourserver/yourservice.wso?wsdl' }, | ||
), | ||
], | ||
@@ -35,5 +45,5 @@ }) | ||
``` | ||
The `registerAsync` or `forRoot` function receives an array of [SoapModuleOptions](#SoapModuleOptions). This means you can create as many clients you need. You just need to create unique names for each one. | ||
The `register` or `forRoot` function receives a [SoapModuleOptions](#SoapModuleOptions) object. You can register as many clients as you need, each with an unique `clientName`. | ||
Another way to import the SoapModule is using `forRootAsync`, like other [factory provider](https://docs.nestjs.com/fundamentals/custom-providers#factory-providers-usefactory). Our factory function can be `async` and can inject dependencies through `inject`: | ||
Another way to import the SoapModule is using `forRootAsync` or `registerAsync`, like other [factory provider](https://docs.nestjs.com/fundamentals/custom-providers#factory-providers-usefactory). It receives a [SoapModuleAsyncOptions](#SoapModuleOptions) object. Our factory function can be `async` and can inject dependencies through `inject`: | ||
@@ -47,5 +57,5 @@ ```javascript | ||
imports: [ | ||
SoapModule.forRootAsync([ | ||
SoapModule.forRootAsync( | ||
{ | ||
name: 'MY_SOAP_CLIENT', | ||
clientName: 'MY_SOAP_CLIENT', | ||
imports: [ConfigModule], | ||
@@ -63,3 +73,3 @@ inject: [ConfigService], | ||
} | ||
]), | ||
), | ||
], | ||
@@ -71,3 +81,3 @@ }) | ||
Then inject the client where you want to use it. | ||
Then, inject the client where you want to use it. | ||
```javascript | ||
@@ -97,3 +107,3 @@ import { Inject, Injectable } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { SoapModuleOptions, SoapModuleOptionsFactory } from 'nestjs-soap'; | ||
import { SoapModuleOptionsFactory, SoapModuleOptionsFactoryType } from 'nestjs-soap'; | ||
@@ -106,3 +116,3 @@ @Injectable() | ||
createSoapModuleOptions(): SoapModuleOptions { | ||
createSoapModuleOptions(): SoapModuleOptionsFactoryType { | ||
return { | ||
@@ -118,5 +128,23 @@ uri: configService.get<string>('soap.uri'), | ||
``` | ||
Then, import it using `useClass` or `useExisting`: | ||
```typescript | ||
import { Module } from '@nestjs/common'; | ||
import { SoapModule, SoapModuleOptions } from 'nestjs-soap'; | ||
import { ExampleSoapConfigService } from './example-config' | ||
@Module({ | ||
imports: [ | ||
SoapModule.forRootAsync( | ||
{ | ||
clientName: 'MY_SOAP_CLIENT', | ||
useClass: ExampleSoapConfigService | ||
} | ||
), | ||
], | ||
}) | ||
export class ExampleModule {} | ||
``` | ||
Note: for the `useExisting` provider you need to import the module containing the `ExampleSoapConfigService` provider. | ||
### SoapModuleOptions | ||
`name`: The unique client name for class injection. | ||
`clientName`: The unique client name for class injection. | ||
@@ -128,1 +156,14 @@ `uri`: The SOAP service uri. | ||
`clientOptions`: The soap client options as in [soap repository](https://www.npmjs.com/package/soap#options) . | ||
### SoapModuleAsyncOptions | ||
`clientName`: The unique client name for class injection. | ||
`inject`: Array of dependencies to be injected. | ||
`useClass`: A class implementing `SoapModuleOptionsFactory`. | ||
`useExisting`: An injectable class implementing `SoapModuleOptionsFactory`. | ||
`useFactory`: A factory function returning a [SoapModuleOptions](#SoapModuleOptions) object. | ||
`imports`: Array of modules containing the injected dependencies. |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
24198
48.31%21
40%249
13.7%0
-100%160
34.45%1
Infinity%