# @gapi/onesignal-notifications 中文文档

规范地址：https://npmcn.com/package/%40gapi/onesignal-notifications/

版本：1\.8\.263
npm 元数据更新时间：2026-11-15T16:23:29.389Z
中文译文更新时间：2026-11-15T23:07:23.402Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40gapi/onesignal-notifications
原文对照：https://npmcn.com/package/%40gapi/onesignal-notifications/?lang=original
项目主页：https://github.com/Stradivario/onesignal-notifications#readme
源码仓库：https://github.com/Stradivario/onesignal-notifications

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：47.8 kB，35 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：1 个
- 首次发布：2018-04-27T12:10:18.583Z
- 最新版本发布：2026-11-15T16:23:29.227Z
- 近 30 天下载量：5292（2026-10-16 至 2026-11-14，npm 官方下载统计）
- 已发布版本数：662（近 12 个月 116 个）

## 中文简介

`bash $ npm install @gapi/onesignal-notifications`

## 安装

```sh
npm install @gapi/onesignal-notifications
```

也可以使用：`pnpm add @gapi/onesignal-notifications`、`yarn add @gapi/onesignal-notifications`、`bun add @gapi/onesignal-notifications`

## README

# @gapi/一个信号通知

#### @ Gapi OneSignal 通知模块 @ StrongTyped 叉出并重写了来自 [单信号节点](https://github.com/KolektifLabs/onesignal-node)

##### 问题/问题可写票 [这里](https://github.com/Stradivario/gapi/issues)

##### 本模块意在与 [冈比亚](https://github.com/Stradivario/gapi)

## 安装和基本实例:

##### 要安装 Gapi 模块, 请运行 :

```bash
$ npm install @gapi/onesignal-notifications
```

## 正在使用 @gapi/ 发信通知

##### 在 AppModule 或 CoreModule 内导入

```typescript
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 {}
```

##### 创建通知服务

```typescript
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);
  }
}
```

##### 然后在您的 Gapi 应用程序内使用, 例如在效果内 :

```typescript
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);
  }
}
```

更详细 [文件](https://github.com/KolektifLabs/onesignal-node) 您可以在原始的单向节点模块中找到 享受吧! (笑声)

## 常见问题

### @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 和提交记录判断。

