Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nestjs-soap

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nestjs-soap

Nestjs module wrapper for soap

  • 1.2.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Nestjs Soap

Nestjs module wrapper for soap

This package internally uses soap npm package

Install

npm install nestjs-soap

Or, if you use yarn

yarn add nestjs-soap

How to use

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

The registerAsync or forRoot function receives an array of 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. 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 } 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.

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.

Soap Module Factory

You can also create your own factory implemeting SoapModuleOptionsFactory

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 .

Keywords

FAQs

Package last updated on 16 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc