@gapi/onesignal-notifications

中文文档
1.8.263发布于 2026/11/16MITTypeScriptESM + CJS近 30 天下载 5292

bash $ npm install @gapi/onesignal-notifications

原始使用文档

@gapi/onesignal-notifications

@Gapi OneSignal Notifications module @StrongTyped forked and re-written with typescript from onesignal-node

For questions/issues you can write ticket here
This module is intended to be used with GAPI

Installation and basic examples:

To install this Gapi module, run:
$ npm install @gapi/onesignal-notifications

Consuming @gapi/onesignal-notifications

Import inside AppModule or CoreModule
import { Module } from '@rxdi/core';
import { OneSignalModule } from '@gapi/onesignal-notifications';

@Module({
  imports: [
    OneSignalModule.forRoot({
      userAuthKey: 'ZmY2YjVkMjMtMjY0OC00Y2E2LTkxBTQtYTVmOWY1MmJhZDg1',
      app: {
        appAuthKey: 'MTa4NGIzNjQtNGFkMy00MzY4AWJjZTctNzNjYzYyODgzZDhh',
        appId: 'd856cd4h-f834-42cb-b541-22ee20bcf499',
      },
    }),
  ],
  services: [NotificationService],
  effects: [YourCustomEffects],
})
export class CoreModule {}
Create NotificationService
import { Service } from '@rxdi/core';
import { PurchasesType } from '../../../purchases/types/purchases.type';
import {
  OneSignalClientService,
  Notification,
} from '@gapi/onesignal-notifications';

@Service()
export class NotificationService {
  constructor(private client: OneSignalClientService) {}

  async createNotification(purchaseData: PurchasesType) {
    const notification: Notification = new Notification({
      contents: {
        en: 'Test notification',
        tr: 'Test mesajı',
        bg: 'Съобщение за проба',
      },
    });
    notification.setTargetDevices(['b188dd55-7c70-4072-b696-8b66a56f9c4c']);
    notification.setParameter('data', {
      type: 'notification-created',
      data: {},
    });
    return await this.client.sendNotification(notification);
  }

  async sendNotification() {
    const firstNotification = new Notification({
      contents: {
        en: 'Test notification',
        tr: 'Test mesajı',
        bg: 'Съобщение за проба',
      },
    });
    firstNotification.setTargetDevices([
      'b188dd55-7c70-4072-b696-8b66a56f9c4c',
    ]);
    firstNotification.setParameter('data', { abc: '123', foo: 'bar' });
    return await this.client.sendNotification(firstNotification);
  }
}
Then use it inside your Gapi Application for example inside Effects:
import { OfType, Effect } from '@rxdi/core';
import { GapiPubSubService } from '@gapi/core';
import { EffectTypes } from '../core/api-introspection/EffectTypes';
import { NotificationService } from '../core/services/notification/notification.service';

@Effect()
export class YourCustomEffects {
  constructor(private notificationService: NotificationService) {}

  @OfType<EffectTypes>(EffectTypes.myevent)
  async myEventTrigger(result, { payload }, context) {
    await this.notificationService.createNotification(result);
  }
}

More detailed DOCUMENTATION you can find inside original onesignal-node module Enjoy ! :)

版本与发布记录

@gapi/onesignal-notifications 共发布 662 个版本,首次发布于 2018/04/27;过去 12 个月发布了 116 个版本。

版本发布日期距今
1.8.263latest2026/11/16今天
1.8.2622026/11/132 天前
1.8.2612026/11/096 天前
1.8.2602026/11/097 天前
1.8.2592026/11/097 天前
1.8.2582026/11/078 天前

其他发布通道:nightly → 1.8.168-nightly.3。

关于 @gapi/onesignal-notifications 的常见问题

@gapi/onesignal-notifications 是什么?

bash $ npm install @gapi/onesignal-notifications

如何安装 @gapi/onesignal-notifications?

在项目目录运行 npm install @gapi/onesignal-notifications,或使用 pnpm add / yarn add / bun add。

@gapi/onesignal-notifications 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@gapi/onesignal-notifications 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@gapi/onesignal-notifications 可以商用吗?

@gapi/onesignal-notifications 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gapi/onesignal-notifications 的下载量有多少?

根据 npm 官方下载统计,@gapi/onesignal-notifications 在 2026/10/16 – 2026/11/14 这 30 天内被下载 5,292 次,日均约 176 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gapi/onesignal-notifications 还在维护吗?

最新版本 1.8.263 发布于 2026/11/16(今天);至今共发布 662 个版本,其中过去 12 个月发布了 116 个;首次发布于 2018/04/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。