Skip to content

Commit

Permalink
Merge branch 'v2'
Browse files Browse the repository at this point in the history
  • Loading branch information
lehh committed Oct 31, 2021
2 parents 7dcd99c + 5666ef4 commit 8cf94a5
Show file tree
Hide file tree
Showing 18 changed files with 10,283 additions and 526 deletions.
67 changes: 54 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<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

Nestjs module wrapper for soap
Expand All @@ -14,7 +18,13 @@ Or, if you use yarn
yarn add nestjs-soap
```

## 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.

```javascript
Expand All @@ -23,16 +33,16 @@ import { SoapModule } from 'nestjs-soap';

@Module({
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' },
),
],
})
export class ExampleModule {}
```
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`:

```javascript
import { Module } from '@nestjs/common';
Expand All @@ -41,9 +51,9 @@ import { ConfigService, ConfigModule } from '@nestjs/config';

@Module({
imports: [
SoapModule.forRootAsync([
SoapModule.forRootAsync(
{
name: 'MY_SOAP_CLIENT',
clientName: 'MY_SOAP_CLIENT',
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (
Expand All @@ -56,14 +66,14 @@ import { ConfigService, ConfigModule } from '@nestjs/config';
},
}),
}
]),
),
],
})
export class ExampleModule {}
```


Then inject the client where you want to use it.
Then, inject the client where you want to use it.
```javascript
import { Inject, Injectable } from '@nestjs/common';
import { Client } from 'nestjs-soap';
Expand All @@ -88,15 +98,15 @@ You can also create your own factory implemeting SoapModuleOptionsFactory
```typescript
import { Injectable, Inject } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { SoapModuleOptions, SoapModuleOptionsFactory } from 'nestjs-soap';
import { SoapModuleOptionsFactory, SoapModuleOptionsFactoryType } from 'nestjs-soap';

@Injectable()
export class ExampleSoapConfigService implements SoapModuleOptionsFactory {
constructor(
@Inject(ConfigService) private readonly configService: ConfigService
)

createSoapModuleOptions(): SoapModuleOptions {
createSoapModuleOptions(): SoapModuleOptionsFactoryType {
return {
uri: configService.get<string>('soap.uri'),
auth: {
Expand All @@ -107,12 +117,43 @@ export class ExampleSoapConfigService implements SoapModuleOptionsFactory {
}
}
```
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.

`uri`: The SOAP service uri.

`auth`: Basic authentication filling in the `username` and `password` fields when needed.

`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.
13 changes: 13 additions & 0 deletions docs/upgrading-to-v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Upgrading to V2

## Breaking Changes
- `forRoot`, `forRootAsync`, `register` and `registerAsync` doesn't receive an array of items anymore.
- `registerAsync` is now used to register async providers like: useFactory, useExisting or useClass.
- Property `name` was renamed to `clientName` in `SoapModuleOptions` and `SoapModuleAsyncOptions` interfaces;
- Defined `SoapModuleOptionsFactoryType` for `createSoapModuleOptions` and `useFactory` functions return types.

### So, what you need to do is basically:
- ***Create an import for each client;***
- ***Use `register` instead of `registerAsync`;***
- ***Use `clientName` instead of `name`;***
- ***Use `SoapModuleOptionsFactoryType` instead of `SoapModuleOptions` on the return type of the `createSoapModuleOptions`/`useFactory` function.***
105 changes: 105 additions & 0 deletions docs/v1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Nestjs Soap v1 Docs

***It's highly recommended to upgrade to v2 as v1 will not be maintained anymore.***

## Getting Started
After installing the package, just import the SoapModule on the module you want to use the soap client.

```javascript
import { Module } from '@nestjs/common';
import { SoapModule } from 'nestjs-soap';

@Module({
imports: [
SoapModule.registerAsync([
{ name: 'MY_SOAP_CLIENT', uri: 'http://yourserver/yourservice.wso?wsdl' },
]),
],
})
export class ExampleModule {}
```
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.

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`:

```javascript
import { Module } from '@nestjs/common';
import { SoapModule, SoapModuleOptions } from 'nestjs-soap';
import { ConfigService } from '@nestjs/config';

@Module({
imports: [
SoapModule.forRootAsync([
{
name: 'MY_SOAP_CLIENT',
inject: [ConfigService],
useFactory: async (
configService: ConfigService,
): Promise<SoapModuleOptions> => ({
uri: configService.get<string>('soap.uri'),
auth: {
username: configService.get<string>('soap.username'),
password: configService.get<string>('soap.password'),
},
}),
}
]),
],
})
export class ExampleModule {}
```


Then inject the client where you want to use it.
```javascript
import { Inject, Injectable } from '@nestjs/common';
import { Client } from 'nestjs-soap';

@Injectable()
export class ExampleService {
constructor(@Inject('MY_SOAP_CLIENT') private readonly mySoapClient: Client) {}

async exampleFunction() {
return await this.mySoapClient.YourFunctionAsync();
}
}

```

The injected Client is from the soap npm package. From here, please follow the use instructions on the [soap repository](https://www.npmjs.com/package/soap).

### Soap Module Factory

You can also create your own factory implemeting SoapModuleOptionsFactory

```typescript
import { Injectable, Inject } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { SoapModuleOptions, SoapModuleOptionsFactory } from 'nestjs-soap';

@Injectable()
export class ExampleSoapConfigService implements SoapModuleOptionsFactory {
constructor(
@Inject(ConfigService) private readonly configService: ConfigService
)

createSoapModuleOptions(): SoapModuleOptions {
return {
uri: configService.get<string>('soap.uri'),
auth: {
username: configService.get<string>('soap.username'),
password: configService.get<string>('soap.password'),
},
};
}
}
```

### SoapModuleOptions
`name`: The unique client name for class injection.

`uri`: The SOAP service uri.

`auth`: Basic authentication filling in the `username` and `password` fields when needed.

`clientOptions`: The soap client options as in [soap repository](https://www.npmjs.com/package/soap#options) .
Loading

0 comments on commit 8cf94a5

Please sign in to comment.