@devgurusio/nest-commercetools
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

NestJS commercetools

Install

npm i @devgurusio/nest-commercetools --save

@devgurusio/nest-commercetools This library contains two NestJS modules

CommercetoolsPlatformModule

This module can be used for create a byProjectKeyRequest from requestBuilder and inject repositories from commercetools-sdk-repositories.

Dependencies

This module requires commercetools-sdk-repositories

npm i @devgurusio/commercetools-sdk-repositories

Usage

Create a byProjectKeyRequest

Before injecting repositories to a module, it is necessary to create a byProjectKeyRequest. If config options needs an asynchronous load, forFeatureAsync can be used

Synchronous

Build an object that matches CommercetoolsPlatformModuleOptions interface and import CommercetoolsPlatformModule.forRoot method in app.module.ts

import { Module } from '@nestjs/common';
import { CommercetoolsPlatformModule } from '@devgurusio/nest-commercetools';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
    imports: [
        CommercetoolsPlatformModule.forRoot({
            auth: {
              host: 'https://auth.commercetools.co',
              projectKey: 'projectKey',
              credentials: {
                clientId: 'clientId',
                clientSecret: 'clientSecret'
              }
              httpClient: fetch,
            }
            http: {
              host: 'https://api.commercetools.co',
              enableRetry: true,
              retryConfig: {
                maxRetries: 3
              },
              httpClient: fetch,
            },
            logger: false;
            queue:  { concurrency: 10 };
            projectKey: 'projectKey';
        }),
    ],
    controllers: [AppController],
    providers: [AppService],
})
export class AppModule {}
Asynchronous

Build an object that mathes CommercetoolsPlatformModuleAsyncOptions and import CommercetoolsPlatformModule.forRootAsync method in app.module.ts

import { Module } from '@nestjs/common';
import { CommercetoolsPlatformModule } from '@devgurusio/nest-commercetools';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { CommercetoolsConfigModule } from './commercetools-config/commercetools-config.module';
import { CommercetoolsConfigService } from './commercetools-config/commercetools-config.service';

@Module({
    imports: [
        CommercetoolsPlatformModule.forRootAsync({
            imports: [CommercetoolsConfigModule],
            useClass: CommercetoolsConfigService,
        })
    ],
    controllers: [AppController],
    providers: [AppService],
})
export class AppModule {}

CommercetoolsConfigService should implement a createCommercetoolsPlatformOptions function that returns a CommercetoolsPlatformModuleOptions or Promise

CommercetoolsAuthorizationModule

This module can be used for create a SdkAuth client to work with CT HTTP API Authorization.

Dependencies

This module requires a fetch function

Usage

Instantiate the service

Synchronous

Build an object that matches CommercetoolsAuthorizationModuleOptions interface and import CommercetoolsAuthorizationModule.register method in the module you need to inject service.

import { Module } from '@nestjs/common';
import { CommercetoolsAuthorizationModule } from '@devgurusio/nest-commercetools';
import fetch from 'node-fetch';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
    imports: [
        CommercetoolsAuthorizationModule.registerAsync({
          host: 'https://auth.commercetools.co',
          token: string
          projectKey: 'projectKey',
          scopes: ['manage_my_profile:projectKey']
          fetch,
        }),
    ],
    controllers: [AppController],
    providers: [AppService],
})
export class AppModule {}
Asynchronous

Build an object that mathes CommercetoolsAuthorizationModuleAsyncOptions and import CommercetoolsAuthorizationModule.registerAsync method in app.module.ts

import { Module } from '@nestjs/common';
import { CommercetoolsAuthorizationModule } from '@devgurusio/nest-commercetools';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { CommercetoolsConfigModule } from './commercetools-config/commercetools-config.module';
import { CommercetoolsAuthrizationConfigService } from './commercetools-config/commercetools-authorization-config.service';

@Module({
    imports: [
        CommercetoolsAuthorizationModule.forRootAsync({
            imports: [CommercetoolsConfigModule],
            useClass: CommercetoolsAuthorizationConfigService,
        })
    ],
    controllers: [AppController],
    providers: [AppService],
})
export class AppModule {}

CommercetoolsAuthorizationConfigService should implement a createCommercetoolsAuthorizationOptions function that returns a CommercetoolsAuthorizationModuleOptions or Promise

If you want more extended info about async configuration for nest modules check out (NestJS Dynamic modules documentation)[https://docs.nestjs.com/fundamentals/dynamic-modules]

Readme

Keywords

none

Package Sidebar

Install

npm i @devgurusio/nest-commercetools

Weekly Downloads

109

Version

2.0.1

License

ISC

Unpacked Size

235 kB

Total Files

72

Last publish

Collaborators

  • dsanchezdmi
  • rubenbrieva
  • jahernandez13
  • xemayebenes
  • smarcilla
  • damarna
  • fmoro
  • martosoler