From 3efadc417a7661ebf191fdedb4d56f550e7f5341 Mon Sep 17 00:00:00 2001 From: Dhoni77 Date: Mon, 13 Nov 2023 19:11:37 +0530 Subject: [PATCH 01/11] feat: migrate to node sdk --- .../one-signal/src/lib/one-signal.provider.ts | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/providers/one-signal/src/lib/one-signal.provider.ts b/providers/one-signal/src/lib/one-signal.provider.ts index fd1079f4150..f9568358bf7 100644 --- a/providers/one-signal/src/lib/one-signal.provider.ts +++ b/providers/one-signal/src/lib/one-signal.provider.ts @@ -4,23 +4,26 @@ import { IPushOptions, IPushProvider, } from '@novu/stateless'; -import * as OneSignal from 'onesignal-node'; +import * as OneSignal from '@onesignal/node-onesignal'; export class OneSignalPushProvider implements IPushProvider { id = 'one-signal'; channelType = ChannelTypeEnum.PUSH as ChannelTypeEnum.PUSH; + private configuration: OneSignal.Configuration; - private oneSignal: OneSignal.Client; + private oneSignal: OneSignal.DefaultApi; constructor( private config: { appId: string; - apiKey: string; + appKey: string; + userKey: string; } ) { - this.oneSignal = new OneSignal.Client( - this.config.appId, - this.config.apiKey - ); + this.configuration = OneSignal.createConfiguration({ + appKey: this.config.appKey, + userKey: this.config.userKey, + }); + this.oneSignal = new OneSignal.DefaultApi(this.configuration); } async sendMessage( @@ -28,14 +31,15 @@ export class OneSignalPushProvider implements IPushProvider { ): Promise { const { sound, badge, ...overrides } = options.overrides ?? {}; - const res = await this.oneSignal.createNotification({ + const notification: OneSignal.Notification = { include_player_ids: options.target, + app_id: this.config.appId, headings: { en: options.title }, contents: { en: options.content }, subtitle: { en: overrides.subtitle }, data: options.payload, - ios_badgeType: 'Increase', - ios_badgeCount: 1, + ios_badge_type: 'Increase', + ios_badge_count: 1, ios_sound: sound, android_sound: sound, mutable_content: overrides.mutableContent, @@ -45,10 +49,12 @@ export class OneSignalPushProvider implements IPushProvider { chrome_icon: overrides.icon, firefox_icon: overrides.icon, ios_category: overrides.categoryId, - }); + }; + + const res = await this.oneSignal.createNotification(notification); return { - id: res.body.id, + id: res.id, date: new Date().toISOString(), }; } From 1447cf2878406c020001331a72d23daef7ee46a4 Mon Sep 17 00:00:00 2001 From: Dhoni77 Date: Mon, 13 Nov 2023 19:14:11 +0530 Subject: [PATCH 02/11] chore: update unit tests --- .../one-signal/src/lib/one-signal.provider.spec.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/providers/one-signal/src/lib/one-signal.provider.spec.ts b/providers/one-signal/src/lib/one-signal.provider.spec.ts index e427876286e..a6ba0a7615c 100644 --- a/providers/one-signal/src/lib/one-signal.provider.spec.ts +++ b/providers/one-signal/src/lib/one-signal.provider.spec.ts @@ -3,7 +3,8 @@ import { OneSignalPushProvider } from './one-signal.provider'; test('should trigger OneSignal library correctly', async () => { const provider = new OneSignalPushProvider({ appId: 'test-app-id', - apiKey: 'test-key', + appKey: 'test-key', + userKey: 'test-user-key', }); const spy = jest @@ -12,7 +13,7 @@ test('should trigger OneSignal library correctly', async () => { .spyOn(provider.oneSignal, 'createNotification') .mockImplementation(async () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any - return { body: { id: 'result' } } as any; + return { id: 'result' }; }); await provider.sendMessage({ @@ -34,6 +35,7 @@ test('should trigger OneSignal library correctly', async () => { expect(provider.oneSignal).toBeDefined(); expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalledWith({ + app_id: 'test-app-id', include_player_ids: ['tester'], headings: { en: 'Test' }, contents: { en: 'Test push' }, @@ -41,8 +43,8 @@ test('should trigger OneSignal library correctly', async () => { data: { sound: 'test_sound', }, - ios_badgeType: 'Increase', - ios_badgeCount: 1, + ios_badge_type: 'Increase', + ios_badge_count: 1, ios_sound: undefined, android_sound: undefined, mutable_content: undefined, From 9a50aca7fbd9b477658d5e0ddc255fbf834ceedf Mon Sep 17 00:00:00 2001 From: Dhoni77 Date: Mon, 13 Nov 2023 19:22:24 +0530 Subject: [PATCH 03/11] feat: update handler and interface --- .../src/entities/integration/credential.interface.ts | 2 ++ .../src/factories/push/handlers/one-signal.handler.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libs/shared/src/entities/integration/credential.interface.ts b/libs/shared/src/entities/integration/credential.interface.ts index 43461059350..cf0c9851e85 100644 --- a/libs/shared/src/entities/integration/credential.interface.ts +++ b/libs/shared/src/entities/integration/credential.interface.ts @@ -41,4 +41,6 @@ export interface ICredentials { imageUrl?: string; state?: string; externalLink?: string; + userKey?: string; + appKey?: string; } diff --git a/packages/application-generic/src/factories/push/handlers/one-signal.handler.ts b/packages/application-generic/src/factories/push/handlers/one-signal.handler.ts index f344e25b6fc..595e3b2665a 100644 --- a/packages/application-generic/src/factories/push/handlers/one-signal.handler.ts +++ b/packages/application-generic/src/factories/push/handlers/one-signal.handler.ts @@ -8,13 +8,18 @@ export class OneSignalHandler extends BasePushHandler { } buildProvider(credentials: ICredentials) { - if (!credentials.apiKey || !credentials.applicationId) { + if ( + !credentials.userKey || + !credentials.applicationId || + !credentials.appKey + ) { throw Error('Config is not valid for OneSignal'); } this.provider = new OneSignalPushProvider({ appId: credentials.applicationId, - apiKey: credentials.apiKey, + appKey: credentials.appKey, + userKey: credentials.userKey, }); } } From 813491bbe181673dc780f15f0168e4bb7e879a8a Mon Sep 17 00:00:00 2001 From: Dhoni77 Date: Mon, 13 Nov 2023 19:23:43 +0530 Subject: [PATCH 04/11] feat: add onenode-signal package --- pnpm-lock.yaml | 222 +++++++----------------------- providers/one-signal/package.json | 2 +- 2 files changed, 47 insertions(+), 177 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 01d35c31e64..e54db9c0af9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -137,7 +137,7 @@ importers: version: 8.8.0(eslint@8.38.0) eslint-import-resolver-webpack: specifier: ^0.13.7 - version: 0.13.7(eslint-plugin-import@2.28.1)(webpack@5.88.2) + version: 0.13.7(eslint-plugin-import@2.28.1)(webpack@5.78.0) eslint-plugin-eslint-comments: specifier: ^3.2.0 version: 3.2.0(eslint@8.38.0) @@ -4748,9 +4748,9 @@ importers: '@novu/stateless': specifier: ^0.21.0 version: link:../../packages/stateless - onesignal-node: - specifier: ^3.4.0 - version: 3.4.0 + '@onesignal/node-onesignal': + specifier: 2.0.1-beta2 + version: 2.0.1-beta2 devDependencies: '@istanbuljs/nyc-config-typescript': specifier: ~1.0.1 @@ -5745,7 +5745,7 @@ importers: version: 27.1.5(@babel/core@7.23.2)(@types/jest@29.5.1)(jest@27.5.1)(typescript@4.9.5) ts-node: specifier: ~10.9.1 - version: 10.9.1(@types/node@20.5.1)(typescript@4.9.5) + version: 10.9.1(@types/node@14.18.42)(typescript@4.9.5) typedoc: specifier: ^0.24.0 version: 0.24.6(typescript@4.9.5) @@ -7654,7 +7654,7 @@ packages: '@azure/core-auth': 1.4.0 '@azure/core-tracing': 1.0.0-preview.11 '@azure/logger': 1.0.4 - '@types/node-fetch': 2.6.5 + '@types/node-fetch': 2.6.6 '@types/tunnel': 0.0.1 form-data: 3.0.1 node-fetch: 2.7.0 @@ -7677,7 +7677,7 @@ packages: '@azure/core-tracing': 1.0.0-preview.13 '@azure/core-util': 1.3.0 '@azure/logger': 1.0.4 - '@types/node-fetch': 2.6.5 + '@types/node-fetch': 2.6.6 '@types/tunnel': 0.0.3 form-data: 4.0.0 node-fetch: 2.7.0 @@ -7700,7 +7700,7 @@ packages: '@azure/core-tracing': 1.0.0-preview.13 '@azure/core-util': 1.3.0 '@azure/logger': 1.0.4 - '@types/node-fetch': 2.6.5 + '@types/node-fetch': 2.6.6 '@types/tunnel': 0.0.3 form-data: 4.0.0 node-fetch: 2.7.0 @@ -7895,7 +7895,7 @@ packages: '@babel/traverse': 7.23.2 '@babel/types': 7.23.0 convert-source-map: 2.0.0 - debug: 4.3.4 + debug: 4.3.4(supports-color@8.1.1) gensync: 1.0.0-beta.2 json5: 2.2.3 semver: 6.3.1 @@ -11531,7 +11531,7 @@ packages: '@babel/helper-split-export-declaration': 7.22.6 '@babel/parser': 7.23.0 '@babel/types': 7.23.0 - debug: 4.3.4 + debug: 4.3.4(supports-color@8.1.1) globals: 11.12.0 transitivePeerDependencies: - supports-color @@ -17357,6 +17357,20 @@ packages: '@octokit/openapi-types': 16.0.0 dev: true + /@onesignal/node-onesignal@2.0.1-beta2: + resolution: {integrity: sha512-UP1QNhXN3qtqrs2aeMP4bctCEggC0VMHgUjnwu5RGKOArUUN/lWFLJuMqcZzW3PldOvH6h9Q8f9HRouXc0QPWg==} + dependencies: + '@types/node': 20.5.1 + '@types/node-fetch': 2.6.6 + btoa: 1.2.1 + es6-promise: 4.2.8 + form-data: 2.5.1 + node-fetch: 2.7.0 + url-parse: 1.5.10 + transitivePeerDependencies: + - encoding + dev: false + /@opencensus/web-types@0.0.7: resolution: {integrity: sha512-xB+w7ZDAu3YBzqH44rCmG9/RlrOmFuDPt/bpf17eJr8eZSrLt7nc7LnWdxM9Mmoj/YKMHpxRg28txu3TcpiL+g==} engines: {node: '>=6.0'} @@ -22300,7 +22314,7 @@ packages: '@storybook/types': 7.4.2 '@types/find-cache-dir': 3.2.1 '@types/node': 16.11.7 - '@types/node-fetch': 2.6.5 + '@types/node-fetch': 2.6.6 '@types/pretty-hrtime': 1.0.1 chalk: 4.1.2 esbuild: 0.18.20 @@ -24026,18 +24040,11 @@ packages: resolution: {integrity: sha512-1jqbAMf6pKjAPJ8NC6VqZoylpBR6kejuw4qL3Mk8dworih+AXADki4WaUIWTzo7ERm6aykPl8xt1/J1invp6Mg==} dev: false - /@types/node-fetch@2.6.5: - resolution: {integrity: sha512-OZsUlr2nxvkqUFLSaY2ZbA+P1q22q+KrlxWOn/38RX+u5kTkYL2mTujEpzUhGkS+K/QCYp9oagfXG39XOzyySg==} - dependencies: - '@types/node': 14.18.42 - form-data: 4.0.0 - /@types/node-fetch@2.6.6: resolution: {integrity: sha512-95X8guJYhfqiuVVhRFxVQcf4hW/2bCuoPwDasMf/531STFoNoWTT7YDnWdXHEZKqAGUigmpG31r2FE70LwnzJw==} dependencies: '@types/node': 14.18.42 form-data: 4.0.0 - dev: false /@types/node-mailjet@3.3.9: resolution: {integrity: sha512-OSwpRjw0DPNCfRQTCcYOAT42uCcbOmAufZjHbqRW+MDsO3QOBTYajwT8J0JlRdgMdBrMEcEkIqLCbc0OSfSiRQ==} @@ -24066,7 +24073,6 @@ packages: /@types/node@20.5.1: resolution: {integrity: sha512-4tT2UrL5LBqDwoed9wZ6N3umC4Yhz3W3FloMmiiG4JwmUJWpie0c7lcnUNd4gtMKuDEO4wRVS8B6Xa0uMRsMKg==} requiresBuild: true - dev: true /@types/nodemailer@6.4.11: resolution: {integrity: sha512-Ld2c0frwpGT4VseuoeboCXQ7UJIkK3X7Lx/4YsZEiUHtHsthWAOCYtf6PAiLhMtfwV0cWJRabLBS3+LD8x6Nrw==} @@ -25653,7 +25659,7 @@ packages: resolution: {integrity: sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==} engines: {node: '>= 6.0.0'} dependencies: - debug: 4.3.4 + debug: 4.3.4(supports-color@8.1.1) transitivePeerDependencies: - supports-color @@ -27473,6 +27479,12 @@ packages: engines: {node: '>=14.20.1'} dev: false + /btoa@1.2.1: + resolution: {integrity: sha512-SB4/MIGlsiVkMcHmT+pSmIPoNDoHg+7cMzmt3Uxt628MTz2487DKSqK/fuhFBrkuqrYv5UCEnACpF4dTFNKc/g==} + engines: {node: '>= 0.4.0'} + hasBin: true + dev: false + /buffer-crc32@0.2.13: resolution: {integrity: sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==} @@ -29987,17 +29999,6 @@ packages: dependencies: ms: 2.0.0 - /debug@3.2.7: - resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==} - peerDependencies: - supports-color: '*' - peerDependenciesMeta: - supports-color: - optional: true - dependencies: - ms: 2.1.3 - dev: true - /debug@3.2.7(supports-color@5.5.0): resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==} peerDependencies: @@ -30033,17 +30034,6 @@ packages: ms: 2.1.2 dev: false - /debug@4.3.4: - resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} - engines: {node: '>=6.0'} - peerDependencies: - supports-color: '*' - peerDependenciesMeta: - supports-color: - optional: true - dependencies: - ms: 2.1.2 - /debug@4.3.4(supports-color@8.1.1): resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} engines: {node: '>=6.0'} @@ -30963,6 +30953,10 @@ packages: resolution: {integrity: sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==} dev: true + /es6-promise@4.2.8: + resolution: {integrity: sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==} + dev: false + /esbuild-plugin-alias@0.2.1: resolution: {integrity: sha512-jyfL/pwPqaFXyKnj8lP8iLk6Z0m099uXR45aSN8Av1XD4vhvQutxxPzgA2bTcAwQpa1zCXDcWOlhFgyP3GKqhQ==} dev: true @@ -31206,7 +31200,7 @@ packages: /eslint-import-resolver-node@0.3.7: resolution: {integrity: sha512-gozW2blMLJCeFpBwugLTGyvVjNoeo1knonXAcatC6bjPBZitotxdWf7Gimr25N4c0AAOo4eOUfaG82IJPDpqCA==} dependencies: - debug: 3.2.7 + debug: 3.2.7(supports-color@8.1.1) is-core-module: 2.13.0 resolve: 1.22.2 transitivePeerDependencies: @@ -31237,30 +31231,6 @@ packages: - supports-color dev: true - /eslint-import-resolver-webpack@0.13.7(eslint-plugin-import@2.28.1)(webpack@5.88.2): - resolution: {integrity: sha512-2a+meyMeABBRO4K53Oj1ygkmt5lhQS79Lmx2f684Qnv6gjvD4RLOM5jfPGTXwQ0A2K03WSoKt3HRQu/uBgxF7w==} - engines: {node: '>= 6'} - peerDependencies: - eslint-plugin-import: '>=1.4.0' - webpack: '>=1.11.0' - dependencies: - array.prototype.find: 2.2.2 - debug: 3.2.7 - enhanced-resolve: 0.9.1 - eslint-plugin-import: 2.28.1(@typescript-eslint/parser@5.58.0)(eslint-import-resolver-webpack@0.13.7)(eslint@8.38.0) - find-root: 1.1.0 - has: 1.0.3 - interpret: 1.4.0 - is-core-module: 2.13.0 - is-regex: 1.1.4 - lodash: 4.17.21 - resolve: 2.0.0-next.4 - semver: 5.7.2 - webpack: 5.88.2 - transitivePeerDependencies: - - supports-color - dev: true - /eslint-module-utils@2.8.0(@typescript-eslint/parser@5.58.0)(eslint-import-resolver-node@0.3.7)(eslint-import-resolver-webpack@0.13.7)(eslint@8.38.0): resolution: {integrity: sha512-aWajIYfsqCKRDgUfjEXNN/JlrzauMuSEy5sbd7WXbtW3EH6A6MpwEh42c7qD+MqQo9QMJ6fWLAeIJynx0g6OAw==} engines: {node: '>=4'} @@ -31283,10 +31253,10 @@ packages: optional: true dependencies: '@typescript-eslint/parser': 5.58.0(eslint@8.38.0)(typescript@4.9.5) - debug: 3.2.7 + debug: 3.2.7(supports-color@8.1.1) eslint: 8.38.0 eslint-import-resolver-node: 0.3.7 - eslint-import-resolver-webpack: 0.13.7(eslint-plugin-import@2.28.1)(webpack@5.88.2) + eslint-import-resolver-webpack: 0.13.7(eslint-plugin-import@2.28.1)(webpack@5.78.0) transitivePeerDependencies: - supports-color dev: true @@ -31394,7 +31364,7 @@ packages: array.prototype.findlastindex: 1.2.3 array.prototype.flat: 1.3.1 array.prototype.flatmap: 1.3.1 - debug: 3.2.7 + debug: 3.2.7(supports-color@8.1.1) doctrine: 2.1.0 eslint: 8.38.0 eslint-import-resolver-node: 0.3.7 @@ -34394,7 +34364,7 @@ packages: dependencies: '@tootallnate/once': 1.1.2 agent-base: 6.0.2 - debug: 4.3.4 + debug: 4.3.4(supports-color@8.1.1) transitivePeerDependencies: - supports-color dev: true @@ -34511,7 +34481,7 @@ packages: engines: {node: '>= 6'} dependencies: agent-base: 6.0.2 - debug: 4.3.4 + debug: 4.3.4(supports-color@8.1.1) transitivePeerDependencies: - supports-color @@ -35653,7 +35623,7 @@ packages: resolution: {integrity: sha512-n3s8EwkdFIJCG3BPKBYvskgXGoy88ARzvegkitk60NxRdwltLOTaH7CUiMRXvwYorl0Q712iEjcWB+fK/MrWVw==} engines: {node: '>=10'} dependencies: - debug: 4.3.4 + debug: 4.3.4(supports-color@8.1.1) istanbul-lib-coverage: 3.2.0 source-map: 0.6.1 transitivePeerDependencies: @@ -35902,7 +35872,7 @@ packages: pretty-format: 27.5.1 slash: 3.0.0 strip-json-comments: 3.1.1 - ts-node: 10.9.1(@types/node@20.5.1)(typescript@4.9.5) + ts-node: 10.9.1(@types/node@14.18.42)(typescript@4.9.5) transitivePeerDependencies: - bufferutil - canvas @@ -40865,14 +40835,6 @@ packages: fn.name: 1.1.0 dev: false - /onesignal-node@3.4.0: - resolution: {integrity: sha512-9dNpfU5Xp6VhJLkdZT4kVqmOaU36RJOgp+6REQHyv+hLOcgqqa4/FRXxuHbjRCE51x9BK4jIC/gn2Mnw0gQgFQ==} - engines: {node: '>=8.13.0'} - dependencies: - request: 2.88.2 - request-promise: 4.2.6(request@2.88.2) - dev: false - /onetime@2.0.1: resolution: {integrity: sha512-oyyPpiMaKARvvcgip+JV+7zci5L8D1W9RZIz2l1o08AM3pfspitVWnPt3mzHcBPp12oYMTy0pqrFs/C+m3EwsQ==} engines: {node: '>=4'} @@ -45157,30 +45119,6 @@ packages: dependencies: throttleit: 1.0.0 - /request-promise-core@1.1.4(request@2.88.2): - resolution: {integrity: sha512-TTbAfBBRdWD7aNNOoVOBH4pN/KigV6LyapYNNlAPA8JwbovRti1E88m3sYAwsLi5ryhPKsE9APwnjFTgdUjTpw==} - engines: {node: '>=0.10.0'} - peerDependencies: - request: ^2.34 - dependencies: - lodash: 4.17.21 - request: 2.88.2 - dev: false - - /request-promise@4.2.6(request@2.88.2): - resolution: {integrity: sha512-HCHI3DJJUakkOr8fNoCc73E5nU5bqITjOYFMDrKHYOXWXrgD/SBaC7LjwuPymUprRyuF06UK7hd/lMHkmUXglQ==} - engines: {node: '>=0.10.0'} - deprecated: request-promise has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142 - peerDependencies: - request: ^2.34 - dependencies: - bluebird: 3.7.2 - request: 2.88.2 - request-promise-core: 1.1.4(request@2.88.2) - stealthy-require: 1.1.1 - tough-cookie: 4.1.3 - dev: false - /request@2.88.2: resolution: {integrity: sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==} engines: {node: '>= 6'} @@ -45502,7 +45440,7 @@ packages: jest-worker: 26.6.2 rollup: 2.79.1 serialize-javascript: 4.0.0 - terser: 5.16.9 + terser: 5.22.0 dev: true /rollup-plugin-terser@7.0.2(rollup@3.20.2): @@ -46729,11 +46667,6 @@ packages: resolution: {integrity: sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==} engines: {node: '>= 0.8'} - /stealthy-require@1.1.1: - resolution: {integrity: sha512-ZnWpYnYugiOVEY5GkcuJK1io5V8QmNYChG62gSit9pQVGErXtrKuPC55ITaVSukmMta5qpMU7vqLt2Lnni4f/g==} - engines: {node: '>=0.10.0'} - dev: false - /stop-iteration-iterator@1.0.0: resolution: {integrity: sha512-iCGQj+0l0HOdZ2AEeBADlsRC+vsnDsZsbdSiH1yNSjcfKM7fdpCMfqAL/dwF5BLiw/XhRft/Wax6zQbhq2BcjQ==} engines: {node: '>= 0.4'} @@ -47788,30 +47721,6 @@ packages: webpack: 5.78.0 dev: true - /terser-webpack-plugin@5.3.9(webpack@5.88.2): - resolution: {integrity: sha512-ZuXsqE07EcggTWQjXUj+Aot/OMcD0bMKGgF63f7UxYcu5/AJF53aIpK1YoP5xR9l6s/Hy2b+t1AM0bLNPRuhwA==} - engines: {node: '>= 10.13.0'} - peerDependencies: - '@swc/core': '*' - esbuild: '*' - uglify-js: '*' - webpack: ^5.1.0 - peerDependenciesMeta: - '@swc/core': - optional: true - esbuild: - optional: true - uglify-js: - optional: true - dependencies: - '@jridgewell/trace-mapping': 0.3.19 - jest-worker: 27.5.1 - schema-utils: 3.3.0 - serialize-javascript: 6.0.1 - terser: 5.22.0 - webpack: 5.88.2 - dev: true - /terser@4.8.1: resolution: {integrity: sha512-4GnLC0x667eJG0ewJTa6z/yXrbLGv80D9Ru6HIpCQmO+Q4PfEtBFi0ObSckqwL6VyQv/7ENJieXHo2ANmdQwgw==} engines: {node: '>=6.0.0'} @@ -48493,6 +48402,7 @@ packages: v8-compile-cache-lib: 3.0.1 yn: 3.1.1 dev: true + optional: true /ts-node@9.1.1(typescript@4.9.5): resolution: {integrity: sha512-hPlt7ZACERQGf03M253ytLY3dHbGNGrAq9qIHWUY9XHYl1z7wYngSr3OQ5xmui8o2AaxsONxIzjafLUiWBo1Fg==} @@ -50233,46 +50143,6 @@ packages: - esbuild - uglify-js - /webpack@5.88.2: - resolution: {integrity: sha512-JmcgNZ1iKj+aiR0OvTYtWQqJwq37Pf683dY9bVORwVbUrDhLhdn/PlO2sHsFHPkj7sHNQF3JwaAkp49V+Sq1tQ==} - engines: {node: '>=10.13.0'} - hasBin: true - peerDependencies: - webpack-cli: '*' - peerDependenciesMeta: - webpack-cli: - optional: true - dependencies: - '@types/eslint-scope': 3.7.4 - '@types/estree': 1.0.1 - '@webassemblyjs/ast': 1.11.5 - '@webassemblyjs/wasm-edit': 1.11.5 - '@webassemblyjs/wasm-parser': 1.11.5 - acorn: 8.10.0 - acorn-import-assertions: 1.9.0(acorn@8.10.0) - browserslist: 4.21.10 - chrome-trace-event: 1.0.3 - enhanced-resolve: 5.15.0 - es-module-lexer: 1.2.1 - eslint-scope: 5.1.1 - events: 3.3.0 - glob-to-regexp: 0.4.1 - graceful-fs: 4.2.11 - json-parse-even-better-errors: 2.3.1 - loader-runner: 4.3.0 - mime-types: 2.1.35 - neo-async: 2.6.2 - schema-utils: 3.3.0 - tapable: 2.2.1 - terser-webpack-plugin: 5.3.9(webpack@5.88.2) - watchpack: 2.4.0 - webpack-sources: 3.2.3 - transitivePeerDependencies: - - '@swc/core' - - esbuild - - uglify-js - dev: true - /webpack@5.88.2(esbuild@0.18.17): resolution: {integrity: sha512-JmcgNZ1iKj+aiR0OvTYtWQqJwq37Pf683dY9bVORwVbUrDhLhdn/PlO2sHsFHPkj7sHNQF3JwaAkp49V+Sq1tQ==} engines: {node: '>=10.13.0'} diff --git a/providers/one-signal/package.json b/providers/one-signal/package.json index d88b62727c1..ad265b1f1f8 100644 --- a/providers/one-signal/package.json +++ b/providers/one-signal/package.json @@ -31,7 +31,7 @@ }, "dependencies": { "@novu/stateless": "^0.21.0", - "onesignal-node": "^3.4.0" + "@onesignal/node-onesignal": "2.0.1-beta2" }, "devDependencies": { "@istanbuljs/nyc-config-typescript": "~1.0.1", From c92a895907dc0d69e8477966d4be4163858d2860 Mon Sep 17 00:00:00 2001 From: Dhoni77 Date: Tue, 14 Nov 2023 15:35:31 +0530 Subject: [PATCH 05/11] feat: use one-signal rest api to send notifications --- .../one-signal/src/lib/one-signal.provider.ts | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/providers/one-signal/src/lib/one-signal.provider.ts b/providers/one-signal/src/lib/one-signal.provider.ts index f9568358bf7..03020f19195 100644 --- a/providers/one-signal/src/lib/one-signal.provider.ts +++ b/providers/one-signal/src/lib/one-signal.provider.ts @@ -1,29 +1,27 @@ +import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'; + import { ChannelTypeEnum, ISendMessageSuccessResponse, IPushOptions, IPushProvider, } from '@novu/stateless'; -import * as OneSignal from '@onesignal/node-onesignal'; export class OneSignalPushProvider implements IPushProvider { id = 'one-signal'; channelType = ChannelTypeEnum.PUSH as ChannelTypeEnum.PUSH; - private configuration: OneSignal.Configuration; + private axiosInstance: AxiosInstance; + public readonly BASE_URL = 'https://onesignal.com/api/v1'; - private oneSignal: OneSignal.DefaultApi; constructor( private config: { appId: string; - appKey: string; - userKey: string; + apiKey: string; } ) { - this.configuration = OneSignal.createConfiguration({ - appKey: this.config.appKey, - userKey: this.config.userKey, + this.axiosInstance = axios.create({ + baseURL: this.BASE_URL, }); - this.oneSignal = new OneSignal.DefaultApi(this.configuration); } async sendMessage( @@ -31,7 +29,7 @@ export class OneSignalPushProvider implements IPushProvider { ): Promise { const { sound, badge, ...overrides } = options.overrides ?? {}; - const notification: OneSignal.Notification = { + const notification = { include_player_ids: options.target, app_id: this.config.appId, headings: { en: options.title }, @@ -51,10 +49,22 @@ export class OneSignalPushProvider implements IPushProvider { ios_category: overrides.categoryId, }; - const res = await this.oneSignal.createNotification(notification); + const notificationOptions: AxiosRequestConfig = { + url: '/notifications', + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: `Basic ${this.config.apiKey}`, + }, + data: JSON.stringify(notification), + }; + + const res = await this.axiosInstance.request<{ id: string }>( + notificationOptions + ); return { - id: res.id, + id: res?.data.id, date: new Date().toISOString(), }; } From 917fdd81792ffc8b16f69d47412132225aa5c25a Mon Sep 17 00:00:00 2001 From: Dhoni77 Date: Tue, 14 Nov 2023 15:37:01 +0530 Subject: [PATCH 06/11] chore: udpate tests --- .../src/lib/one-signal.provider.spec.ts | 92 +++++++++---------- 1 file changed, 42 insertions(+), 50 deletions(-) diff --git a/providers/one-signal/src/lib/one-signal.provider.spec.ts b/providers/one-signal/src/lib/one-signal.provider.spec.ts index a6ba0a7615c..bf16e285f43 100644 --- a/providers/one-signal/src/lib/one-signal.provider.spec.ts +++ b/providers/one-signal/src/lib/one-signal.provider.spec.ts @@ -1,58 +1,50 @@ import { OneSignalPushProvider } from './one-signal.provider'; +import axios from 'axios'; +import { IPushOptions } from 'packages/stateless/build/main'; -test('should trigger OneSignal library correctly', async () => { - const provider = new OneSignalPushProvider({ - appId: 'test-app-id', - appKey: 'test-key', - userKey: 'test-user-key', +jest.mock('axios'); + +const mockNotificationOptions: IPushOptions = { + title: 'Test', + content: 'Test push', + target: ['tester'], + payload: { + sound: 'test_sound', + }, + subscriber: {}, + step: { + digest: false, + events: [{}], + total_count: 1, + }, +}; + +describe('test onesignal notification api', () => { + const mockedAxios = axios as jest.Mocked; + + beforeEach(() => { + mockedAxios.create.mockReturnThis(); }); - const spy = jest - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-expect-error - .spyOn(provider.oneSignal, 'createNotification') - .mockImplementation(async () => { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return { id: 'result' }; + test('should trigger OneSignal library correctly', async () => { + const provider = new OneSignalPushProvider({ + appId: 'test-app-id', + apiKey: 'test-key', }); - await provider.sendMessage({ - title: 'Test', - content: 'Test push', - target: ['tester'], - payload: { - sound: 'test_sound', - }, - subscriber: {}, - step: { - digest: false, - events: [{}], - total_count: 1, - }, - }); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-expect-error - expect(provider.oneSignal).toBeDefined(); - expect(spy).toHaveBeenCalled(); - expect(spy).toHaveBeenCalledWith({ - app_id: 'test-app-id', - include_player_ids: ['tester'], - headings: { en: 'Test' }, - contents: { en: 'Test push' }, - subtitle: { en: undefined }, - data: { - sound: 'test_sound', - }, - ios_badge_type: 'Increase', - ios_badge_count: 1, - ios_sound: undefined, - android_sound: undefined, - mutable_content: undefined, - android_channel_id: undefined, - small_icon: undefined, - large_icon: undefined, - chrome_icon: undefined, - firefox_icon: undefined, - ios_category: undefined, + const response = { + data: { + id: 'result', + }, + }; + + mockedAxios.request.mockResolvedValue(response); + + const spy = jest.spyOn(provider, 'sendMessage'); + + const res = await provider.sendMessage(mockNotificationOptions); + expect(mockedAxios.request).toHaveBeenCalled(); + expect(spy).toHaveBeenCalledWith(mockNotificationOptions); + expect(res.id).toEqual(response.data.id); }); }); From 4124ccf0b0a6d8f943caf024ecedb90f8f8a5f18 Mon Sep 17 00:00:00 2001 From: Dhoni77 Date: Tue, 14 Nov 2023 15:38:50 +0530 Subject: [PATCH 07/11] chore: revert changes --- .../src/entities/integration/credential.interface.ts | 2 -- .../src/factories/push/handlers/one-signal.handler.ts | 9 ++------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/libs/shared/src/entities/integration/credential.interface.ts b/libs/shared/src/entities/integration/credential.interface.ts index cf0c9851e85..43461059350 100644 --- a/libs/shared/src/entities/integration/credential.interface.ts +++ b/libs/shared/src/entities/integration/credential.interface.ts @@ -41,6 +41,4 @@ export interface ICredentials { imageUrl?: string; state?: string; externalLink?: string; - userKey?: string; - appKey?: string; } diff --git a/packages/application-generic/src/factories/push/handlers/one-signal.handler.ts b/packages/application-generic/src/factories/push/handlers/one-signal.handler.ts index 595e3b2665a..f344e25b6fc 100644 --- a/packages/application-generic/src/factories/push/handlers/one-signal.handler.ts +++ b/packages/application-generic/src/factories/push/handlers/one-signal.handler.ts @@ -8,18 +8,13 @@ export class OneSignalHandler extends BasePushHandler { } buildProvider(credentials: ICredentials) { - if ( - !credentials.userKey || - !credentials.applicationId || - !credentials.appKey - ) { + if (!credentials.apiKey || !credentials.applicationId) { throw Error('Config is not valid for OneSignal'); } this.provider = new OneSignalPushProvider({ appId: credentials.applicationId, - appKey: credentials.appKey, - userKey: credentials.userKey, + apiKey: credentials.apiKey, }); } } From 1025be83de4c7bee51de439476fbb27da327645c Mon Sep 17 00:00:00 2001 From: Dhoni77 Date: Tue, 14 Nov 2023 15:39:29 +0530 Subject: [PATCH 08/11] chore: update package.json --- providers/one-signal/jest.config.js | 3 +++ providers/one-signal/package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/providers/one-signal/jest.config.js b/providers/one-signal/jest.config.js index e86e13bab91..61faa20934a 100644 --- a/providers/one-signal/jest.config.js +++ b/providers/one-signal/jest.config.js @@ -2,4 +2,7 @@ module.exports = { preset: 'ts-jest', testEnvironment: 'node', + moduleNameMapper: { + axios: 'axios/dist/node/axios.cjs', + }, }; diff --git a/providers/one-signal/package.json b/providers/one-signal/package.json index ad265b1f1f8..1443a4fce27 100644 --- a/providers/one-signal/package.json +++ b/providers/one-signal/package.json @@ -31,7 +31,7 @@ }, "dependencies": { "@novu/stateless": "^0.21.0", - "@onesignal/node-onesignal": "2.0.1-beta2" + "axios": "1.3.4" }, "devDependencies": { "@istanbuljs/nyc-config-typescript": "~1.0.1", From 2968f8f6b574f4109c48e779dc729a5a56385fe4 Mon Sep 17 00:00:00 2001 From: Dhoni77 Date: Tue, 14 Nov 2023 15:40:40 +0530 Subject: [PATCH 09/11] chore: update lock file --- pnpm-lock.yaml | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e54db9c0af9..69d6d810631 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4748,9 +4748,9 @@ importers: '@novu/stateless': specifier: ^0.21.0 version: link:../../packages/stateless - '@onesignal/node-onesignal': - specifier: 2.0.1-beta2 - version: 2.0.1-beta2 + axios: + specifier: 1.3.4 + version: 1.3.4 devDependencies: '@istanbuljs/nyc-config-typescript': specifier: ~1.0.1 @@ -17357,20 +17357,6 @@ packages: '@octokit/openapi-types': 16.0.0 dev: true - /@onesignal/node-onesignal@2.0.1-beta2: - resolution: {integrity: sha512-UP1QNhXN3qtqrs2aeMP4bctCEggC0VMHgUjnwu5RGKOArUUN/lWFLJuMqcZzW3PldOvH6h9Q8f9HRouXc0QPWg==} - dependencies: - '@types/node': 20.5.1 - '@types/node-fetch': 2.6.6 - btoa: 1.2.1 - es6-promise: 4.2.8 - form-data: 2.5.1 - node-fetch: 2.7.0 - url-parse: 1.5.10 - transitivePeerDependencies: - - encoding - dev: false - /@opencensus/web-types@0.0.7: resolution: {integrity: sha512-xB+w7ZDAu3YBzqH44rCmG9/RlrOmFuDPt/bpf17eJr8eZSrLt7nc7LnWdxM9Mmoj/YKMHpxRg28txu3TcpiL+g==} engines: {node: '>=6.0'} @@ -24073,6 +24059,8 @@ packages: /@types/node@20.5.1: resolution: {integrity: sha512-4tT2UrL5LBqDwoed9wZ6N3umC4Yhz3W3FloMmiiG4JwmUJWpie0c7lcnUNd4gtMKuDEO4wRVS8B6Xa0uMRsMKg==} requiresBuild: true + dev: true + optional: true /@types/nodemailer@6.4.11: resolution: {integrity: sha512-Ld2c0frwpGT4VseuoeboCXQ7UJIkK3X7Lx/4YsZEiUHtHsthWAOCYtf6PAiLhMtfwV0cWJRabLBS3+LD8x6Nrw==} @@ -27479,12 +27467,6 @@ packages: engines: {node: '>=14.20.1'} dev: false - /btoa@1.2.1: - resolution: {integrity: sha512-SB4/MIGlsiVkMcHmT+pSmIPoNDoHg+7cMzmt3Uxt628MTz2487DKSqK/fuhFBrkuqrYv5UCEnACpF4dTFNKc/g==} - engines: {node: '>= 0.4.0'} - hasBin: true - dev: false - /buffer-crc32@0.2.13: resolution: {integrity: sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==} @@ -30953,10 +30935,6 @@ packages: resolution: {integrity: sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==} dev: true - /es6-promise@4.2.8: - resolution: {integrity: sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==} - dev: false - /esbuild-plugin-alias@0.2.1: resolution: {integrity: sha512-jyfL/pwPqaFXyKnj8lP8iLk6Z0m099uXR45aSN8Av1XD4vhvQutxxPzgA2bTcAwQpa1zCXDcWOlhFgyP3GKqhQ==} dev: true @@ -45440,7 +45418,7 @@ packages: jest-worker: 26.6.2 rollup: 2.79.1 serialize-javascript: 4.0.0 - terser: 5.22.0 + terser: 5.16.9 dev: true /rollup-plugin-terser@7.0.2(rollup@3.20.2): From 77a6a924d558f76cc7f495f074bb0d3e16e7d9f7 Mon Sep 17 00:00:00 2001 From: Dhoni77 Date: Tue, 14 Nov 2023 18:42:28 +0530 Subject: [PATCH 10/11] chore: update axios --- pnpm-lock.yaml | 8 ++++---- providers/one-signal/package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 69d6d810631..8523e50ee21 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4749,8 +4749,8 @@ importers: specifier: ^0.21.0 version: link:../../packages/stateless axios: - specifier: 1.3.4 - version: 1.3.4 + specifier: ^1.6.0 + version: 1.6.0 devDependencies: '@istanbuljs/nyc-config-typescript': specifier: ~1.0.1 @@ -31382,7 +31382,7 @@ packages: eslint: 8.51.0 eslint-import-resolver-node: 0.3.7 eslint-module-utils: 2.8.0(@typescript-eslint/parser@5.58.0)(eslint-import-resolver-node@0.3.7)(eslint-import-resolver-webpack@0.13.7)(eslint@8.51.0) - has: 1.0.3 + has: 1.0.4 is-core-module: 2.13.0 is-glob: 4.0.3 minimatch: 3.1.2 @@ -45418,7 +45418,7 @@ packages: jest-worker: 26.6.2 rollup: 2.79.1 serialize-javascript: 4.0.0 - terser: 5.16.9 + terser: 5.22.0 dev: true /rollup-plugin-terser@7.0.2(rollup@3.20.2): diff --git a/providers/one-signal/package.json b/providers/one-signal/package.json index 1443a4fce27..ee5c64add80 100644 --- a/providers/one-signal/package.json +++ b/providers/one-signal/package.json @@ -31,7 +31,7 @@ }, "dependencies": { "@novu/stateless": "^0.21.0", - "axios": "1.3.4" + "axios":"^1.6.0" }, "devDependencies": { "@istanbuljs/nyc-config-typescript": "~1.0.1", From 3cb5760a8068fc996a4bb4c3e357093ab4fa5147 Mon Sep 17 00:00:00 2001 From: Aldrin <53973174+Dhoni77@users.noreply.github.com> Date: Wed, 15 Nov 2023 22:26:22 +0530 Subject: [PATCH 11/11] Update providers/one-signal/src/lib/one-signal.provider.spec.ts Co-authored-by: Dima Grossman --- providers/one-signal/src/lib/one-signal.provider.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/one-signal/src/lib/one-signal.provider.spec.ts b/providers/one-signal/src/lib/one-signal.provider.spec.ts index bf16e285f43..2f29235972c 100644 --- a/providers/one-signal/src/lib/one-signal.provider.spec.ts +++ b/providers/one-signal/src/lib/one-signal.provider.spec.ts @@ -1,6 +1,6 @@ import { OneSignalPushProvider } from './one-signal.provider'; import axios from 'axios'; -import { IPushOptions } from 'packages/stateless/build/main'; +import { IPushOptions } from '@novu/stateless'; jest.mock('axios');