@mindik/mailchimp-nestjs
TypeScript icon, indicating that this package has built-in type declarations

1.2.3 • Public • Published

Mailchimp -- generated by @nestjsplus/dyn-schematics


License: MIT Built with NestJS Built with @nestjsplus/dyn-schematics


About

The module is a thin wrapper for the Mailchimp Transactional API.


Installation

npm i @mindik/mailchimp-nestjs

Quick Start

Import the module and pass your api key to it

// app.module.ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { MailchimpModule } from '@mindik/mailchimp-nestjs';

@Module({
  imports: [MailchimpModule.forRoot(/* API_KEY */)],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

..or use forRootAsync({ })

// app.module.ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { MailchimpModule } from '@mindik/mailchimp-nestjs';

@Module({
  imports: [
    MailchimpModule.forRootAsync({
      imports: [/* ConfigModule */]
      /* 
        useExisting 
        useFactory 
        useClass 
      */
      useFactory: async () => /* API_KEY */, 
      inject: [/* ConfigService */]
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Inject Mailchimp in your service

// app.service.ts
import { InjectMailchimp } from '@mindik/mailchimp-nestjs';
import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
  constructor(
    /*
      or 
      @Inject(MAILCHIMP_TOKEN) private readonly mail
    */
    @InjectMailchimp() private readonly mail
  ) {}

  // Test connection function ( == this.mail.users.ping())
  async checkMailchimp(): Promise<any> {
    return this.mail.pingPong();
  }
}

You can use a decorator

@InjectMailchimp() private readonly mail

that is an alias for a longer entry

@Inject(MAILCHIMP_TOKEN) private readonly mail

Further use in the application is no different from other modules...

Add the export to the decorator @Module()

// app.module.ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { MailchimpModule } from '@mindik/mailchimp-nestjs';

@Module({
  imports: [MailchimpModule.forRoot(/* API_KEY */)],
  controllers: [AppController],
  providers: [AppService],
  exports: [AppService],
})
export class AppModule {}

Import service in some module

// some.module.ts
import { Module } from '@nestjs/common';
import { AppService } from 'src/app.service';
import { SomeController } from './some.controller';
import { SomeService } from './some.service';

@Module({
  controllers: [SomeController],
  providers: [AppService, SomeService],
})
export class SomeModule {}

Use in your some service

// some.service.ts
import { Injectable } from '@nestjs/common';
import { AppService } from 'src/app.service';

@Injectable()
export class SomeService {
  constructor(private readonly appService: AppService) {}

  async getPong(): Promise<any> {
    return 'SOME SERVICE ' + (await this.appService.checkMailchimp());
  }
}

Contributing

Any suggestions for improving the project are welcome.

  1. Fork the repository
  2. Create your branch (git checkout -b my-branch)
  3. Commit any changes to your branch
  4. Push your changes to your remote branch
  5. Open a pull request

License

Distributed under the MIT License. See LICENSE for more information.


Acknowledgements

Readme

Keywords

Package Sidebar

Install

npm i @mindik/mailchimp-nestjs

Weekly Downloads

179

Version

1.2.3

License

MIT

Unpacked Size

34.3 kB

Total Files

31

Last publish

Collaborators

  • mindik