Git Product home page Git Product logo

nestjs-soap's Introduction

NPM Version Package License NPM Downloads

Nestjs Soap

Nestjs module wrapper for soap npm package

Compatibility

For nestjs < v8.4.0 use v2 package.

For nestjs >= v8.4.0 use v3 package.

Install

npm install nestjs-soap

Or, if you use yarn

yarn add nestjs-soap

Documentation

Getting Started

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

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

@Module({
  imports: [
    SoapModule.register(
      { clientName: 'MY_SOAP_CLIENT', uri: 'http://yourserver/yourservice.wso?wsdl' },
    ),
  ],
})
export class ExampleModule {}

The register or forRoot function receives a 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 or registerAsync, like other factory provider. It receives a SoapModuleAsyncOptions object. Our factory function can be async and can inject dependencies through inject:

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

@Module({
  imports: [
    SoapModule.forRootAsync(
      { 
        clientName: 'MY_SOAP_CLIENT',
        imports: [ConfigModule],
        inject: [ConfigService],
        useFactory: async (
          configService: ConfigService,
        ): Promise<SoapModuleOptions> => ({
          uri: configService.get<string>('soap.uri'),
          auth: {
            type: 'basic',
            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.

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. This example is using the soap method async from soap package. From here, please follow the Client use instructions on the soap repository.

Soap Module Factory

You can also create your own factory implemeting SoapModuleOptionsFactory

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

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

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

Then, import it using useClass or useExisting:

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

clientName: The unique client name for class injection.

uri: The SOAP service uri.

auth (optional): Basic or WSSecurity authentication. Fields type (basic or wssecurity), username and password are required. For the WSSecurity options field, refer to soap-repository

clientOptions (optional): The soap client options as in soap repository.

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

imports: Array of modules containing the injected dependencies.

scope: Injection scope of the injected provider.

nestjs-soap's People

Contributors

ammarnajjar avatar gmqz avatar kleberoliveira avatar kleberoliveira-sharecare avatar lehh avatar zier avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.