JSPM

nestjs-onesignal

2.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 44
  • Score
    100M100P100Q84387F
  • License MIT

Injectable OneSignal client for NestJS

Package Exports

  • nestjs-onesignal
  • nestjs-onesignal/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nestjs-onesignal) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

nestjs-onesignal

Nest Logo

💉 Injectable OneSignal client for NestJS.

codecov npm version miniziped size MIT licensed

Implementing the OneSignalModule from this package you gain access to OneSignal client through dependency injection with minimal setup.

Instalation

$ npm install --save @onesignal/node-onesignal nestjs-onesignal
$ yarn add @onesignal/node-onesignal nestjs-onesignal

Getting Started

To use OneSignal client we need to register module for example in app.module.ts

import { OneSignalModule } from 'nestjs-onesignal';

@Module({
    imports: [
        OneSignalModule.forRoot({
            appId: process.env.ONESIGNAL_APP_ID,
            apiKey: process.env.ONESIGNAL_API_KEY,
        }),
    ],
})
export class AppModule {}

If you are using the @nestjs/config package from Nest, you can use the ConfigModule using the registerAsync() function to inject your environment variables like this in your custom module:

import { OneSignalModule } from 'nestjs-onesignal';

@Module({
    imports: [
        OneSignalModule.forRootAsync({
            imports: [ConfigModule],
            useFactory: (configService: ConfigService) => ({
                appId: configService.get('ONESIGNAL_APP_ID'),
                apiKey: configService.get('ONESIGNAL_API_KEY'),
            }),
            inject: [ConfigService],
        }),
    ],
})
export class AppModule {}

Example usage in service.

import { OneSignalService } from 'nestjs-onesignal';

@Injectable()
export class AppService {
    public constructor(
        private readonly onesignalService: OneSignalService,
        private readonly configService: ConfigService,
    ) {}

    async sendNotification() {
        const playerId = this.configService.get(ONESIGNAL_PLAYER_ID);

        return await this.onesignalService.client.createNotification({
            contents: {
                en: 'Sent notification to spesific player id',
            },
            include_player_ids: [playerId],
        });
    }
}

For full Client Library see One Signal Node SDK reference here