@metamask/notification-services-controller 22.1.0 → 23.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -1
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.cjs +7 -0
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.cjs.map +1 -0
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.cts +198 -0
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.cts.map +1 -0
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.mts +198 -0
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.mts.map +1 -0
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.mjs +6 -0
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.mjs.map +1 -0
- package/dist/NotificationServicesController/NotificationServicesController.cjs +47 -14
- package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.cts +6 -20
- package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.mts +6 -20
- package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.mjs +46 -14
- package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
- package/dist/NotificationServicesController/index.cjs +3 -7
- package/dist/NotificationServicesController/index.cjs.map +1 -1
- package/dist/NotificationServicesController/index.d.cts +3 -3
- package/dist/NotificationServicesController/index.d.cts.map +1 -1
- package/dist/NotificationServicesController/index.d.mts +3 -3
- package/dist/NotificationServicesController/index.d.mts.map +1 -1
- package/dist/NotificationServicesController/index.mjs +2 -3
- package/dist/NotificationServicesController/index.mjs.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.cjs +7 -0
- package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.cjs.map +1 -0
- package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.d.cts +60 -0
- package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.d.cts.map +1 -0
- package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.d.mts +60 -0
- package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.d.mts.map +1 -0
- package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.mjs +6 -0
- package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.mjs.map +1 -0
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +40 -10
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +12 -18
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +12 -18
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +40 -11
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
- package/dist/NotificationServicesPushController/index.cjs +3 -7
- package/dist/NotificationServicesPushController/index.cjs.map +1 -1
- package/dist/NotificationServicesPushController/index.d.cts +3 -3
- package/dist/NotificationServicesPushController/index.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/index.d.mts +3 -3
- package/dist/NotificationServicesPushController/index.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/index.mjs +2 -3
- package/dist/NotificationServicesPushController/index.mjs.map +1 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.cjs +9 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.cjs.map +1 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.d.cts +2 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.d.mts +2 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.mjs +7 -0
- package/dist/NotificationServicesPushController/mocks/mockResponse.mjs.map +1 -1
- package/dist/NotificationServicesPushController/services/services.cjs +31 -1
- package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
- package/dist/NotificationServicesPushController/services/services.d.cts +22 -0
- package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/services/services.d.mts +22 -0
- package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/services/services.mjs +29 -0
- package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
- package/package.json +5 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationServicesPushController.mjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAG3D,OAAO,IAAG,iBAAiB;;AAG3B,OAAO,EACL,yBAAyB,EACzB,2BAA2B,EAC5B,gCAA4B;AAK7B,MAAM,cAAc,GAAG,oCAAoC,CAAC;AAqE5D,MAAM,CAAC,MAAM,YAAY,GAA4C;IACnE,aAAa,EAAE,IAAI;IACnB,QAAQ,EAAE,EAAE;IACZ,kBAAkB,EAAE,KAAK;CAC1B,CAAC;AACF,MAAM,QAAQ,GAA2D;IACvE,aAAa,EAAE;QACb,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;IACD,QAAQ,EAAE;QACR,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;IACD,kBAAkB,EAAE;QAClB,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,IAAI;QAC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3B,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;YAClC,KAAK,CAAC,kBAAkB,GAAG,KAAK,CAAC;QACnC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,iDAAiD;YACjD,+EAA+E;YAC/E,KAAK,CAAC,aAAa,GAAG,KAAK,CAAC;YAC5B,KAAK,CAAC,kBAAkB,GAAG,KAAK,CAAC;QACnC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,aAAa,GAAG,IAAI,CAAC;YAC3B,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;YAClC,KAAK,CAAC,kBAAkB,GAAG,KAAK,CAAC;QACnC,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC;eAlGkB,kCAAkC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport log from 'loglevel';\n\nimport type { ENV } from './services/endpoints';\nimport {\n activatePushNotifications,\n deactivatePushNotifications,\n} from './services/services';\nimport type { PushNotificationEnv } from './types';\nimport type { PushService } from './types/push-service-interface';\nimport type { Types } from '../NotificationServicesController';\n\nconst controllerName = 'NotificationServicesPushController';\n\nexport type NotificationServicesPushControllerState = {\n isPushEnabled: boolean;\n fcmToken: string;\n isUpdatingFCMToken: boolean;\n};\n\nexport type NotificationServicesPushControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n NotificationServicesPushControllerState\n >;\n\nexport type NotificationServicesPushControllerEnablePushNotificationsAction = {\n type: `${typeof controllerName}:enablePushNotifications`;\n handler: NotificationServicesPushController['enablePushNotifications'];\n};\nexport type NotificationServicesPushControllerDisablePushNotificationsAction = {\n type: `${typeof controllerName}:disablePushNotifications`;\n handler: NotificationServicesPushController['disablePushNotifications'];\n};\nexport type NotificationServicesPushControllerUpdateTriggerPushNotificationsAction =\n {\n type: `${typeof controllerName}:updateTriggerPushNotifications`;\n handler: NotificationServicesPushController['updateTriggerPushNotifications'];\n };\nexport type NotificationServicesPushControllerSubscribeToNotificationsAction = {\n type: `${typeof controllerName}:subscribeToPushNotifications`;\n handler: NotificationServicesPushController['subscribeToPushNotifications'];\n};\n\nexport type Actions =\n | NotificationServicesPushControllerGetStateAction\n | NotificationServicesPushControllerEnablePushNotificationsAction\n | NotificationServicesPushControllerDisablePushNotificationsAction\n | NotificationServicesPushControllerUpdateTriggerPushNotificationsAction\n | NotificationServicesPushControllerSubscribeToNotificationsAction;\n\ntype AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerTokenAction;\n\nexport type NotificationServicesPushControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n NotificationServicesPushControllerState\n >;\n\nexport type NotificationServicesPushControllerOnNewNotificationEvent = {\n type: `${typeof controllerName}:onNewNotifications`;\n payload: [Types.INotification];\n};\n\nexport type NotificationServicesPushControllerPushNotificationClickedEvent = {\n type: `${typeof controllerName}:pushNotificationClicked`;\n payload: [Types.INotification];\n};\n\nexport type Events =\n | NotificationServicesPushControllerStateChangeEvent\n | NotificationServicesPushControllerOnNewNotificationEvent\n | NotificationServicesPushControllerPushNotificationClickedEvent;\n\nexport type NotificationServicesPushControllerMessenger = Messenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events\n>;\n\nexport const defaultState: NotificationServicesPushControllerState = {\n isPushEnabled: true,\n fcmToken: '',\n isUpdatingFCMToken: false,\n};\nconst metadata: StateMetadata<NotificationServicesPushControllerState> = {\n isPushEnabled: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n fcmToken: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n isUpdatingFCMToken: {\n includeInStateLogs: false,\n persist: false,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n};\n\nconst defaultPushEnv: PushNotificationEnv = {\n apiKey: '',\n authDomain: '',\n storageBucket: '',\n projectId: '',\n messagingSenderId: '',\n appId: '',\n measurementId: '',\n vapidKey: '',\n};\n\nexport type ControllerConfig = {\n /**\n * User locale for server push notifications\n */\n getLocale?: () => string;\n\n /**\n * Global switch to determine to use push notifications\n * Allows us to control Builds on extension (MV2 vs MV3)\n */\n isPushFeatureEnabled?: boolean;\n\n /**\n * determine the config used for push notification services\n */\n platform: 'extension' | 'mobile';\n\n /**\n * Push Service Interface\n * - create reg token\n * - delete reg token\n * - subscribe to push notifications\n */\n pushService: PushService;\n\n env?: ENV;\n};\n\ntype StateCommand =\n | { type: 'enable'; fcmToken: string }\n | { type: 'disable' }\n | { type: 'update'; fcmToken: string };\n\n/**\n * Manages push notifications for the application, including enabling, disabling, and updating triggers for push notifications.\n * This controller integrates with Firebase Cloud Messaging (FCM) to handle the registration and management of push notifications.\n * It is responsible for registering and unregistering the service worker that listens for push notifications,\n * managing the FCM token, and communicating with the server to register or unregister the device for push notifications.\n * Additionally, it provides functionality to update the server with new UUIDs that should trigger push notifications.\n */\nexport default class NotificationServicesPushController extends BaseController<\n typeof controllerName,\n NotificationServicesPushControllerState,\n NotificationServicesPushControllerMessenger\n> {\n #pushListenerUnsubscribe: (() => void) | undefined = undefined;\n\n readonly #env: PushNotificationEnv;\n\n readonly #config: ControllerConfig;\n\n constructor({\n messenger,\n state,\n env,\n config,\n }: {\n messenger: NotificationServicesPushControllerMessenger;\n state: NotificationServicesPushControllerState;\n /** Push Environment is only required for extension */\n env?: PushNotificationEnv;\n config: ControllerConfig;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...state },\n });\n\n this.#env = env ?? defaultPushEnv;\n this.#config = config;\n\n this.#registerMessageHandlers();\n this.#clearLoadingStates();\n }\n\n #registerMessageHandlers(): void {\n this.messenger.registerActionHandler(\n 'NotificationServicesPushController:enablePushNotifications',\n this.enablePushNotifications.bind(this),\n );\n this.messenger.registerActionHandler(\n 'NotificationServicesPushController:disablePushNotifications',\n this.disablePushNotifications.bind(this),\n );\n this.messenger.registerActionHandler(\n 'NotificationServicesPushController:updateTriggerPushNotifications',\n this.updateTriggerPushNotifications.bind(this),\n );\n this.messenger.registerActionHandler(\n 'NotificationServicesPushController:subscribeToPushNotifications',\n this.subscribeToPushNotifications.bind(this),\n );\n }\n\n #clearLoadingStates(): void {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n\n async #getAndAssertBearerToken(): Promise<string> {\n const bearerToken = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n if (!bearerToken) {\n throw new Error('BearerToken token is missing');\n }\n\n return bearerToken;\n }\n\n #updatePushState(command: StateCommand): void {\n if (command.type === 'enable') {\n this.update((state) => {\n state.isPushEnabled = true;\n state.fcmToken = command.fcmToken;\n state.isUpdatingFCMToken = false;\n });\n }\n\n if (command.type === 'disable') {\n this.update((state) => {\n // Note we do not want to clear the old FCM token\n // We can send it as an old token to our backend to cleanup next time turned on\n state.isPushEnabled = false;\n state.isUpdatingFCMToken = false;\n });\n }\n\n if (command.type === 'update') {\n this.update((state) => {\n state.isPushEnabled = true;\n state.fcmToken = command.fcmToken;\n state.isUpdatingFCMToken = false;\n });\n }\n }\n\n public async subscribeToPushNotifications(): Promise<void> {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n if (this.#pushListenerUnsubscribe) {\n this.#pushListenerUnsubscribe();\n this.#pushListenerUnsubscribe = undefined;\n }\n\n try {\n this.#pushListenerUnsubscribe =\n (await this.#config.pushService.subscribeToPushNotifications(\n this.#env,\n )) ?? undefined;\n } catch {\n // Do nothing, we are silently failing if push notification registration fails\n }\n }\n\n /**\n * Enables push notifications for the application.\n *\n * This method sets up the necessary infrastructure for handling push notifications by:\n * 1. Registering the service worker to listen for messages.\n * 2. Fetching the Firebase Cloud Messaging (FCM) token from Firebase.\n * 3. Sending the FCM token to the server responsible for sending notifications, to register the device.\n *\n * @param addresses - An array of addresses to enable push notifications for.\n */\n public async enablePushNotifications(addresses: string[]): Promise<void> {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n // Handle creating new reg token (if available)\n try {\n const bearerToken = await this.#getAndAssertBearerToken().catch(\n () => null,\n );\n\n // If there is a bearer token, lets try to refresh/create new reg token\n if (bearerToken) {\n // Activate Push Notifications\n const fcmToken = await activatePushNotifications({\n bearerToken,\n addresses,\n env: this.#env,\n createRegToken: this.#config.pushService.createRegToken,\n regToken: {\n platform: this.#config.platform,\n locale: this.#config.getLocale?.() ?? 'en',\n oldToken: this.state.fcmToken,\n },\n controllerEnv: this.#config.env ?? 'prd',\n });\n\n if (fcmToken) {\n this.#updatePushState({ type: 'enable', fcmToken });\n }\n }\n } catch {\n // Do nothing, we are silently failing\n }\n\n // New token created, (re)subscribe to push notifications\n try {\n await this.subscribeToPushNotifications();\n } catch {\n // Do nothing we are silently failing\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n\n /**\n * Disables push notifications for the application.\n * This removes the registration token on this device, and ensures we unsubscribe from any listeners\n */\n public async disablePushNotifications(): Promise<void> {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n try {\n // Send a request to the server to unregister the token/device\n await deactivatePushNotifications({\n env: this.#env,\n deleteRegToken: this.#config.pushService.deleteRegToken,\n regToken: this.state.fcmToken,\n });\n } catch (error) {\n const errorMessage = `Failed to disable push notifications: ${\n error as string\n }`;\n log.error(errorMessage);\n throw new Error(errorMessage);\n } finally {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n\n // Unsubscribe from push notifications\n this.#pushListenerUnsubscribe?.();\n\n // Update State\n this.#updatePushState({ type: 'disable' });\n }\n\n /**\n * Updates the triggers for push notifications.\n * This method is responsible for updating the server with the new set of addresses that should trigger push notifications.\n * It uses the current FCM token and a BearerToken for authentication.\n *\n * @param addresses - An array of addresses that should trigger push notifications.\n * @deprecated - this is not used anymore and will most likely be removed\n */\n public async updateTriggerPushNotifications(\n addresses: string[],\n ): Promise<void> {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n try {\n const bearerToken = await this.#getAndAssertBearerToken();\n const fcmToken = await activatePushNotifications({\n bearerToken,\n addresses,\n env: this.#env,\n createRegToken: this.#config.pushService.createRegToken,\n regToken: {\n platform: this.#config.platform,\n locale: this.#config.getLocale?.() ?? 'en',\n oldToken: this.state.fcmToken,\n },\n controllerEnv: this.#config.env ?? 'prd',\n });\n\n // update the state with the new FCM token\n if (fcmToken) {\n this.#updatePushState({ type: 'update', fcmToken });\n }\n } catch (error) {\n const errorMessage = `Failed to update triggers for push notifications: ${\n error as string\n }`;\n log.error(errorMessage);\n throw new Error(errorMessage);\n } finally {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"NotificationServicesPushController.mjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAG3D,OAAO,IAAG,iBAAiB;;AAI3B,OAAO,EACL,yBAAyB,EACzB,cAAc,EACd,2BAA2B,EAC5B,gCAA4B;AAK7B,MAAM,cAAc,GAAG,oCAAoC,CAAC;AAQ5D,MAAM,yBAAyB,GAAG;IAChC,8BAA8B;IAC9B,yBAAyB;IACzB,0BAA0B;IAC1B,gCAAgC;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Aa,GAAG,IAAI,CAAC;YAC3B,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;YAClC,KAAK,CAAC,kBAAkB,GAAG,KAAK,CAAC;QACnC,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport log from 'loglevel';\n\nimport type { NotificationServicesPushControllerMethodActions } from './NotificationServicesPushController-method-action-types';\nimport type { ENV } from './services/endpoints';\nimport {\n activatePushNotifications,\n deleteLinksAPI,\n deactivatePushNotifications,\n} from './services/services';\nimport type { PushNotificationEnv } from './types';\nimport type { PushService } from './types/push-service-interface';\nimport type { Types } from '../NotificationServicesController';\n\nconst controllerName = 'NotificationServicesPushController';\n\nexport type NotificationServicesPushControllerState = {\n isPushEnabled: boolean;\n fcmToken: string;\n isUpdatingFCMToken: boolean;\n};\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'subscribeToPushNotifications',\n 'enablePushNotifications',\n 'disablePushNotifications',\n 'updateTriggerPushNotifications',\n 'deletePushNotificationLinks',\n] as const;\n\nexport type NotificationServicesPushControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n NotificationServicesPushControllerState\n >;\n\nexport type Actions =\n | NotificationServicesPushControllerGetStateAction\n | NotificationServicesPushControllerMethodActions;\n\ntype AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerTokenAction;\n\nexport type NotificationServicesPushControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n NotificationServicesPushControllerState\n >;\n\nexport type NotificationServicesPushControllerOnNewNotificationEvent = {\n type: `${typeof controllerName}:onNewNotifications`;\n payload: [Types.INotification];\n};\n\nexport type NotificationServicesPushControllerPushNotificationClickedEvent = {\n type: `${typeof controllerName}:pushNotificationClicked`;\n payload: [Types.INotification];\n};\n\nexport type Events =\n | NotificationServicesPushControllerStateChangeEvent\n | NotificationServicesPushControllerOnNewNotificationEvent\n | NotificationServicesPushControllerPushNotificationClickedEvent;\n\nexport type NotificationServicesPushControllerMessenger = Messenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events\n>;\n\nexport const defaultState: NotificationServicesPushControllerState = {\n isPushEnabled: true,\n fcmToken: '',\n isUpdatingFCMToken: false,\n};\nconst metadata: StateMetadata<NotificationServicesPushControllerState> = {\n isPushEnabled: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n fcmToken: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n isUpdatingFCMToken: {\n includeInStateLogs: false,\n persist: false,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n};\n\nconst defaultPushEnv: PushNotificationEnv = {\n apiKey: '',\n authDomain: '',\n storageBucket: '',\n projectId: '',\n messagingSenderId: '',\n appId: '',\n measurementId: '',\n vapidKey: '',\n};\n\nexport type ControllerConfig = {\n /**\n * User locale for server push notifications\n */\n getLocale?: () => string;\n\n /**\n * Global switch to determine to use push notifications\n * Allows us to control Builds on extension (MV2 vs MV3)\n */\n isPushFeatureEnabled?: boolean;\n\n /**\n * determine the config used for push notification services\n */\n platform: 'extension' | 'mobile';\n\n /**\n * Push Service Interface\n * - create reg token\n * - delete reg token\n * - subscribe to push notifications\n */\n pushService: PushService;\n\n env?: ENV;\n};\n\ntype StateCommand =\n | { type: 'enable'; fcmToken: string }\n | { type: 'disable' }\n | { type: 'update'; fcmToken: string };\n\n/**\n * Manages push notifications for the application, including enabling, disabling, and updating triggers for push notifications.\n * This controller integrates with Firebase Cloud Messaging (FCM) to handle the registration and management of push notifications.\n * It is responsible for registering and unregistering the service worker that listens for push notifications,\n * managing the FCM token, and communicating with the server to register or unregister the device for push notifications.\n * Additionally, it provides functionality to update the server with new UUIDs that should trigger push notifications.\n */\nexport class NotificationServicesPushController extends BaseController<\n typeof controllerName,\n NotificationServicesPushControllerState,\n NotificationServicesPushControllerMessenger\n> {\n #pushListenerUnsubscribe: (() => void) | undefined = undefined;\n\n readonly #env: PushNotificationEnv;\n\n readonly #config: ControllerConfig;\n\n constructor({\n messenger,\n state,\n env,\n config,\n }: {\n messenger: NotificationServicesPushControllerMessenger;\n state: NotificationServicesPushControllerState;\n /** Push Environment is only required for extension */\n env?: PushNotificationEnv;\n config: ControllerConfig;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...state },\n });\n\n this.#env = env ?? defaultPushEnv;\n this.#config = config;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n this.#clearLoadingStates();\n }\n\n #clearLoadingStates(): void {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n\n async #getAndAssertBearerToken(): Promise<string> {\n const bearerToken = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n if (!bearerToken) {\n throw new Error('BearerToken token is missing');\n }\n\n return bearerToken;\n }\n\n #updatePushState(command: StateCommand): void {\n if (command.type === 'enable') {\n this.update((state) => {\n state.isPushEnabled = true;\n state.fcmToken = command.fcmToken;\n state.isUpdatingFCMToken = false;\n });\n }\n\n if (command.type === 'disable') {\n this.update((state) => {\n // Note we do not want to clear the old FCM token\n // We can send it as an old token to our backend to cleanup next time turned on\n state.isPushEnabled = false;\n state.isUpdatingFCMToken = false;\n });\n }\n\n if (command.type === 'update') {\n this.update((state) => {\n state.isPushEnabled = true;\n state.fcmToken = command.fcmToken;\n state.isUpdatingFCMToken = false;\n });\n }\n }\n\n public async subscribeToPushNotifications(): Promise<void> {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n if (this.#pushListenerUnsubscribe) {\n this.#pushListenerUnsubscribe();\n this.#pushListenerUnsubscribe = undefined;\n }\n\n try {\n this.#pushListenerUnsubscribe =\n (await this.#config.pushService.subscribeToPushNotifications(\n this.#env,\n )) ?? undefined;\n } catch {\n // Do nothing, we are silently failing if push notification registration fails\n }\n }\n\n /**\n * Enables push notifications for the application.\n *\n * This method sets up the necessary infrastructure for handling push notifications by:\n * 1. Registering the service worker to listen for messages.\n * 2. Fetching the Firebase Cloud Messaging (FCM) token from Firebase.\n * 3. Sending the FCM token to the server responsible for sending notifications, to register the device.\n *\n * @param addresses - An array of addresses to enable push notifications for.\n */\n public async enablePushNotifications(addresses: string[]): Promise<void> {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n // Handle creating new reg token (if available)\n try {\n const bearerToken = await this.#getAndAssertBearerToken().catch(\n () => null,\n );\n\n // If there is a bearer token, lets try to refresh/create new reg token\n if (bearerToken) {\n // Activate Push Notifications\n const fcmToken = await activatePushNotifications({\n bearerToken,\n addresses,\n env: this.#env,\n createRegToken: this.#config.pushService.createRegToken,\n regToken: {\n platform: this.#config.platform,\n locale: this.#config.getLocale?.() ?? 'en',\n oldToken: this.state.fcmToken,\n },\n controllerEnv: this.#config.env ?? 'prd',\n });\n\n if (fcmToken) {\n this.#updatePushState({ type: 'enable', fcmToken });\n }\n }\n } catch {\n // Do nothing, we are silently failing\n }\n\n // New token created, (re)subscribe to push notifications\n try {\n await this.subscribeToPushNotifications();\n } catch {\n // Do nothing we are silently failing\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n\n /**\n * Disables push notifications for the application.\n * This removes the registration token on this device, and ensures we unsubscribe from any listeners\n */\n public async disablePushNotifications(): Promise<void> {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n try {\n // Send a request to the server to unregister the token/device\n await deactivatePushNotifications({\n env: this.#env,\n deleteRegToken: this.#config.pushService.deleteRegToken,\n regToken: this.state.fcmToken,\n });\n } catch (error) {\n const errorMessage = `Failed to disable push notifications: ${\n error as string\n }`;\n log.error(errorMessage);\n throw new Error(errorMessage);\n } finally {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n\n // Unsubscribe from push notifications\n this.#pushListenerUnsubscribe?.();\n\n // Update State\n this.#updatePushState({ type: 'disable' });\n }\n\n /**\n * Deletes backend push notification links for the given addresses on the current platform.\n * This is used when accounts are removed (for example SRP removal), so backend can remove\n * all associated FCM tokens for those address/platform pairs.\n *\n * @param addresses - Addresses that should be unlinked from push notifications.\n * @returns Whether the delete request succeeded.\n */\n public async deletePushNotificationLinks(\n addresses: string[],\n ): Promise<boolean> {\n if (\n !this.#config.isPushFeatureEnabled ||\n addresses.length === 0 ||\n !this.state.fcmToken\n ) {\n return false;\n }\n\n try {\n const bearerToken = await this.#getAndAssertBearerToken();\n return await deleteLinksAPI({\n bearerToken,\n addresses,\n platform: this.#config.platform,\n token: this.state.fcmToken,\n env: this.#config.env ?? 'prd',\n });\n } catch {\n return false;\n }\n }\n\n /**\n * Updates the triggers for push notifications.\n * This method is responsible for updating the server with the new set of addresses that should trigger push notifications.\n * It uses the current FCM token and a BearerToken for authentication.\n *\n * @param addresses - An array of addresses that should trigger push notifications.\n * @deprecated - this is not used anymore and will most likely be removed\n */\n public async updateTriggerPushNotifications(\n addresses: string[],\n ): Promise<void> {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n try {\n const bearerToken = await this.#getAndAssertBearerToken();\n const fcmToken = await activatePushNotifications({\n bearerToken,\n addresses,\n env: this.#env,\n createRegToken: this.#config.pushService.createRegToken,\n regToken: {\n platform: this.#config.platform,\n locale: this.#config.getLocale?.() ?? 'en',\n oldToken: this.state.fcmToken,\n },\n controllerEnv: this.#config.env ?? 'prd',\n });\n\n // update the state with the new FCM token\n if (fcmToken) {\n this.#updatePushState({ type: 'update', fcmToken });\n }\n } catch (error) {\n const errorMessage = `Failed to update triggers for push notifications: ${\n error as string\n }`;\n log.error(errorMessage);\n throw new Error(errorMessage);\n } finally {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n }\n}\n"]}
|
|
@@ -25,15 +25,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
__setModuleDefault(result, mod);
|
|
26
26
|
return result;
|
|
27
27
|
};
|
|
28
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
-
};
|
|
31
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
29
|
exports.Mocks = exports.Utils = exports.Controller = void 0;
|
|
33
|
-
const NotificationServicesPushController_1 =
|
|
34
|
-
exports
|
|
35
|
-
|
|
36
|
-
exports.default = NotificationServicesPushController;
|
|
30
|
+
const NotificationServicesPushController_1 = require("./NotificationServicesPushController.cjs");
|
|
31
|
+
Object.defineProperty(exports, "Controller", { enumerable: true, get: function () { return NotificationServicesPushController_1.NotificationServicesPushController; } });
|
|
32
|
+
exports.default = NotificationServicesPushController_1.NotificationServicesPushController;
|
|
37
33
|
__exportStar(require("./NotificationServicesPushController.cjs"), exports);
|
|
38
34
|
exports.Utils = __importStar(require("./utils/index.cjs"));
|
|
39
35
|
__exportStar(require("./utils/index.cjs"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iGAA0F;AAE3C,2FAFtC,uEAAkC,OAEc;AACzD,kBAAe,uEAAkC,CAAC;AAClD,2EAAqD;AAGrD,2DAAiC;AACjC,oDAAwB;AACxB,2DAAiC","sourcesContent":["import { NotificationServicesPushController } from './NotificationServicesPushController';\n\nexport { NotificationServicesPushController as Controller };\nexport default NotificationServicesPushController;\nexport * from './NotificationServicesPushController';\nexport type * as Types from './types';\nexport type * from './types';\nexport * as Utils from './utils';\nexport * from './utils';\nexport * as Mocks from './mocks';\n\nexport type {\n NotificationServicesPushControllerSubscribeToPushNotificationsAction,\n NotificationServicesPushControllerEnablePushNotificationsAction,\n NotificationServicesPushControllerDisablePushNotificationsAction,\n NotificationServicesPushControllerUpdateTriggerPushNotificationsAction,\n NotificationServicesPushControllerDeletePushNotificationLinksAction,\n NotificationServicesPushControllerMethodActions,\n} from './NotificationServicesPushController-method-action-types';\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export { Controller };
|
|
1
|
+
import { NotificationServicesPushController } from "./NotificationServicesPushController.cjs";
|
|
2
|
+
export { NotificationServicesPushController as Controller };
|
|
4
3
|
export default NotificationServicesPushController;
|
|
5
4
|
export * from "./NotificationServicesPushController.cjs";
|
|
6
5
|
export type * as Types from "./types/index.cjs";
|
|
@@ -8,4 +7,5 @@ export type * from "./types/index.cjs";
|
|
|
8
7
|
export * as Utils from "./utils/index.cjs";
|
|
9
8
|
export * from "./utils/index.cjs";
|
|
10
9
|
export * as Mocks from "./mocks/index.cjs";
|
|
10
|
+
export type { NotificationServicesPushControllerSubscribeToPushNotificationsAction, NotificationServicesPushControllerEnablePushNotificationsAction, NotificationServicesPushControllerDisablePushNotificationsAction, NotificationServicesPushControllerUpdateTriggerPushNotificationsAction, NotificationServicesPushControllerDeletePushNotificationLinksAction, NotificationServicesPushControllerMethodActions, } from "./NotificationServicesPushController-method-action-types.cjs";
|
|
11
11
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kCAAkC,EAAE,iDAA6C;AAE1F,OAAO,EAAE,kCAAkC,IAAI,UAAU,EAAE,CAAC;AAC5D,eAAe,kCAAkC,CAAC;AAClD,yDAAqD;AACrD,YAAY,KAAK,KAAK,0BAAgB;AACtC,uCAA6B;AAC7B,OAAO,KAAK,KAAK,0BAAgB;AACjC,kCAAwB;AACxB,OAAO,KAAK,KAAK,0BAAgB;AAEjC,YAAY,EACV,oEAAoE,EACpE,+DAA+D,EAC/D,gEAAgE,EAChE,sEAAsE,EACtE,mEAAmE,EACnE,+CAA+C,GAChD,qEAAiE"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export { Controller };
|
|
1
|
+
import { NotificationServicesPushController } from "./NotificationServicesPushController.mjs";
|
|
2
|
+
export { NotificationServicesPushController as Controller };
|
|
4
3
|
export default NotificationServicesPushController;
|
|
5
4
|
export * from "./NotificationServicesPushController.mjs";
|
|
6
5
|
export type * as Types from "./types/index.mjs";
|
|
@@ -8,4 +7,5 @@ export type * from "./types/index.mjs";
|
|
|
8
7
|
export * as Utils from "./utils/index.mjs";
|
|
9
8
|
export * from "./utils/index.mjs";
|
|
10
9
|
export * as Mocks from "./mocks/index.mjs";
|
|
10
|
+
export type { NotificationServicesPushControllerSubscribeToPushNotificationsAction, NotificationServicesPushControllerEnablePushNotificationsAction, NotificationServicesPushControllerDisablePushNotificationsAction, NotificationServicesPushControllerUpdateTriggerPushNotificationsAction, NotificationServicesPushControllerDeletePushNotificationLinksAction, NotificationServicesPushControllerMethodActions, } from "./NotificationServicesPushController-method-action-types.mjs";
|
|
11
11
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kCAAkC,EAAE,iDAA6C;AAE1F,OAAO,EAAE,kCAAkC,IAAI,UAAU,EAAE,CAAC;AAC5D,eAAe,kCAAkC,CAAC;AAClD,yDAAqD;AACrD,YAAY,KAAK,KAAK,0BAAgB;AACtC,uCAA6B;AAC7B,OAAO,KAAK,KAAK,0BAAgB;AACjC,kCAAwB;AACxB,OAAO,KAAK,KAAK,0BAAgB;AAEjC,YAAY,EACV,oEAAoE,EACpE,+DAA+D,EAC/D,gEAAgE,EAChE,sEAAsE,EACtE,mEAAmE,EACnE,+CAA+C,GAChD,qEAAiE"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export { Controller };
|
|
1
|
+
import { NotificationServicesPushController } from "./NotificationServicesPushController.mjs";
|
|
2
|
+
export { NotificationServicesPushController as Controller };
|
|
4
3
|
export default NotificationServicesPushController;
|
|
5
4
|
export * from "./NotificationServicesPushController.mjs";
|
|
6
5
|
export * as Utils from "./utils/index.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kCAAkC,EAAE,iDAA6C;AAE1F,OAAO,EAAE,kCAAkC,IAAI,UAAU,EAAE,CAAC;AAC5D,eAAe,kCAAkC,CAAC;AAClD,yDAAqD;AAGrD,OAAO,KAAK,KAAK,0BAAgB;AACjC,kCAAwB;AACxB,OAAO,KAAK,KAAK,0BAAgB","sourcesContent":["import { NotificationServicesPushController } from './NotificationServicesPushController';\n\nexport { NotificationServicesPushController as Controller };\nexport default NotificationServicesPushController;\nexport * from './NotificationServicesPushController';\nexport type * as Types from './types';\nexport type * from './types';\nexport * as Utils from './utils';\nexport * from './utils';\nexport * as Mocks from './mocks';\n\nexport type {\n NotificationServicesPushControllerSubscribeToPushNotificationsAction,\n NotificationServicesPushControllerEnablePushNotificationsAction,\n NotificationServicesPushControllerDisablePushNotificationsAction,\n NotificationServicesPushControllerUpdateTriggerPushNotificationsAction,\n NotificationServicesPushControllerDeletePushNotificationLinksAction,\n NotificationServicesPushControllerMethodActions,\n} from './NotificationServicesPushController-method-action-types';\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMockDeleteFCMRegistrationTokenResponse = exports.getMockCreateFCMRegistrationTokenResponse = exports.MOCK_FCM_RESPONSE = exports.getMockUpdatePushNotificationLinksResponse = exports.MOCK_REG_TOKEN = void 0;
|
|
3
|
+
exports.getMockDeleteFCMRegistrationTokenResponse = exports.getMockCreateFCMRegistrationTokenResponse = exports.MOCK_FCM_RESPONSE = exports.getMockDeletePushNotificationLinksResponse = exports.getMockUpdatePushNotificationLinksResponse = exports.MOCK_REG_TOKEN = void 0;
|
|
4
4
|
const endpoints_1 = require("../services/endpoints.cjs");
|
|
5
5
|
exports.MOCK_REG_TOKEN = 'REG_TOKEN';
|
|
6
6
|
const getMockUpdatePushNotificationLinksResponse = () => {
|
|
@@ -11,6 +11,14 @@ const getMockUpdatePushNotificationLinksResponse = () => {
|
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
13
|
exports.getMockUpdatePushNotificationLinksResponse = getMockUpdatePushNotificationLinksResponse;
|
|
14
|
+
const getMockDeletePushNotificationLinksResponse = () => {
|
|
15
|
+
return {
|
|
16
|
+
url: (0, endpoints_1.REGISTRATION_TOKENS_ENDPOINT)(),
|
|
17
|
+
requestMethod: 'DELETE',
|
|
18
|
+
response: null,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
exports.getMockDeletePushNotificationLinksResponse = getMockDeletePushNotificationLinksResponse;
|
|
14
22
|
exports.MOCK_FCM_RESPONSE = {
|
|
15
23
|
name: '',
|
|
16
24
|
token: 'fcm-token',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mockResponse.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":";;;AAAA,yDAAqE;AAQxD,QAAA,cAAc,GAAG,WAAW,CAAC;AAEnC,MAAM,0CAA0C,GAAG,GAAiB,EAAE;IAC3E,OAAO;QACL,GAAG,EAAE,IAAA,wCAA4B,GAAE;QACnC,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,IAAI;KACQ,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,0CAA0C,8CAMrD;AAEW,QAAA,iBAAiB,GAAG;IAC/B,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,WAAW;IAClB,GAAG,EAAE;QACH,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,EAAE;QACR,iBAAiB,EAAE,EAAE;KACtB;CACF,CAAC;AAEK,MAAM,yCAAyC,GAAG,GAAiB,EAAE;IAC1E,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,yBAAiB;KACL,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,yCAAyC,6CAMpD;AAEK,MAAM,yCAAyC,GAAG,GAAiB,EAAE;IAC1E,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,EAAE;KACU,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,yCAAyC,6CAMpD","sourcesContent":["import { REGISTRATION_TOKENS_ENDPOINT } from '../services/endpoints';\n\ntype MockResponse = {\n url: string | RegExp;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_REG_TOKEN = 'REG_TOKEN';\n\nexport const getMockUpdatePushNotificationLinksResponse = (): MockResponse => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT(),\n requestMethod: 'POST',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const MOCK_FCM_RESPONSE = {\n name: '',\n token: 'fcm-token',\n web: {\n endpoint: '',\n p256dh: '',\n auth: '',\n applicationPubKey: '',\n },\n};\n\nexport const getMockCreateFCMRegistrationTokenResponse = (): MockResponse => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: MOCK_FCM_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockDeleteFCMRegistrationTokenResponse = (): MockResponse => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: {},\n } satisfies MockResponse;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"mockResponse.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":";;;AAAA,yDAAqE;AAQxD,QAAA,cAAc,GAAG,WAAW,CAAC;AAEnC,MAAM,0CAA0C,GAAG,GAAiB,EAAE;IAC3E,OAAO;QACL,GAAG,EAAE,IAAA,wCAA4B,GAAE;QACnC,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,IAAI;KACQ,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,0CAA0C,8CAMrD;AAEK,MAAM,0CAA0C,GAAG,GAAiB,EAAE;IAC3E,OAAO;QACL,GAAG,EAAE,IAAA,wCAA4B,GAAE;QACnC,aAAa,EAAE,QAAQ;QACvB,QAAQ,EAAE,IAAI;KACQ,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,0CAA0C,8CAMrD;AAEW,QAAA,iBAAiB,GAAG;IAC/B,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,WAAW;IAClB,GAAG,EAAE;QACH,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,EAAE;QACR,iBAAiB,EAAE,EAAE;KACtB;CACF,CAAC;AAEK,MAAM,yCAAyC,GAAG,GAAiB,EAAE;IAC1E,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,yBAAiB;KACL,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,yCAAyC,6CAMpD;AAEK,MAAM,yCAAyC,GAAG,GAAiB,EAAE;IAC1E,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,EAAE;KACU,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,yCAAyC,6CAMpD","sourcesContent":["import { REGISTRATION_TOKENS_ENDPOINT } from '../services/endpoints';\n\ntype MockResponse = {\n url: string | RegExp;\n requestMethod: 'GET' | 'POST' | 'PUT' | 'DELETE';\n response: unknown;\n};\n\nexport const MOCK_REG_TOKEN = 'REG_TOKEN';\n\nexport const getMockUpdatePushNotificationLinksResponse = (): MockResponse => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT(),\n requestMethod: 'POST',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const getMockDeletePushNotificationLinksResponse = (): MockResponse => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT(),\n requestMethod: 'DELETE',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const MOCK_FCM_RESPONSE = {\n name: '',\n token: 'fcm-token',\n web: {\n endpoint: '',\n p256dh: '',\n auth: '',\n applicationPubKey: '',\n },\n};\n\nexport const getMockCreateFCMRegistrationTokenResponse = (): MockResponse => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: MOCK_FCM_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockDeleteFCMRegistrationTokenResponse = (): MockResponse => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: {},\n } satisfies MockResponse;\n};\n"]}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
type MockResponse = {
|
|
2
2
|
url: string | RegExp;
|
|
3
|
-
requestMethod: 'GET' | 'POST' | 'PUT';
|
|
3
|
+
requestMethod: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
4
4
|
response: unknown;
|
|
5
5
|
};
|
|
6
6
|
export declare const MOCK_REG_TOKEN = "REG_TOKEN";
|
|
7
7
|
export declare const getMockUpdatePushNotificationLinksResponse: () => MockResponse;
|
|
8
|
+
export declare const getMockDeletePushNotificationLinksResponse: () => MockResponse;
|
|
8
9
|
export declare const MOCK_FCM_RESPONSE: {
|
|
9
10
|
name: string;
|
|
10
11
|
token: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mockResponse.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,aAAa,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"mockResponse.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,aAAa,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;IACjD,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,cAAc,cAAc,CAAC;AAE1C,eAAO,MAAM,0CAA0C,QAAO,YAM7D,CAAC;AAEF,eAAO,MAAM,0CAA0C,QAAO,YAM7D,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;CAS7B,CAAC;AAEF,eAAO,MAAM,yCAAyC,QAAO,YAM5D,CAAC;AAEF,eAAO,MAAM,yCAAyC,QAAO,YAM5D,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
type MockResponse = {
|
|
2
2
|
url: string | RegExp;
|
|
3
|
-
requestMethod: 'GET' | 'POST' | 'PUT';
|
|
3
|
+
requestMethod: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
4
4
|
response: unknown;
|
|
5
5
|
};
|
|
6
6
|
export declare const MOCK_REG_TOKEN = "REG_TOKEN";
|
|
7
7
|
export declare const getMockUpdatePushNotificationLinksResponse: () => MockResponse;
|
|
8
|
+
export declare const getMockDeletePushNotificationLinksResponse: () => MockResponse;
|
|
8
9
|
export declare const MOCK_FCM_RESPONSE: {
|
|
9
10
|
name: string;
|
|
10
11
|
token: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mockResponse.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,aAAa,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"mockResponse.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,aAAa,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;IACjD,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,cAAc,cAAc,CAAC;AAE1C,eAAO,MAAM,0CAA0C,QAAO,YAM7D,CAAC;AAEF,eAAO,MAAM,0CAA0C,QAAO,YAM7D,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;CAS7B,CAAC;AAEF,eAAO,MAAM,yCAAyC,QAAO,YAM5D,CAAC;AAEF,eAAO,MAAM,yCAAyC,QAAO,YAM5D,CAAC"}
|
|
@@ -7,6 +7,13 @@ export const getMockUpdatePushNotificationLinksResponse = () => {
|
|
|
7
7
|
response: null,
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
|
+
export const getMockDeletePushNotificationLinksResponse = () => {
|
|
11
|
+
return {
|
|
12
|
+
url: REGISTRATION_TOKENS_ENDPOINT(),
|
|
13
|
+
requestMethod: 'DELETE',
|
|
14
|
+
response: null,
|
|
15
|
+
};
|
|
16
|
+
};
|
|
10
17
|
export const MOCK_FCM_RESPONSE = {
|
|
11
18
|
name: '',
|
|
12
19
|
token: 'fcm-token',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mockResponse.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,kCAA8B;AAQrE,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAE1C,MAAM,CAAC,MAAM,0CAA0C,GAAG,GAAiB,EAAE;IAC3E,OAAO;QACL,GAAG,EAAE,4BAA4B,EAAE;QACnC,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,IAAI;KACQ,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,WAAW;IAClB,GAAG,EAAE;QACH,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,EAAE;QACR,iBAAiB,EAAE,EAAE;KACtB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,yCAAyC,GAAG,GAAiB,EAAE;IAC1E,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,iBAAiB;KACL,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,yCAAyC,GAAG,GAAiB,EAAE;IAC1E,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,EAAE;KACU,CAAC;AAC3B,CAAC,CAAC","sourcesContent":["import { REGISTRATION_TOKENS_ENDPOINT } from '../services/endpoints';\n\ntype MockResponse = {\n url: string | RegExp;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_REG_TOKEN = 'REG_TOKEN';\n\nexport const getMockUpdatePushNotificationLinksResponse = (): MockResponse => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT(),\n requestMethod: 'POST',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const MOCK_FCM_RESPONSE = {\n name: '',\n token: 'fcm-token',\n web: {\n endpoint: '',\n p256dh: '',\n auth: '',\n applicationPubKey: '',\n },\n};\n\nexport const getMockCreateFCMRegistrationTokenResponse = (): MockResponse => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: MOCK_FCM_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockDeleteFCMRegistrationTokenResponse = (): MockResponse => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: {},\n } satisfies MockResponse;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"mockResponse.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,kCAA8B;AAQrE,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAE1C,MAAM,CAAC,MAAM,0CAA0C,GAAG,GAAiB,EAAE;IAC3E,OAAO;QACL,GAAG,EAAE,4BAA4B,EAAE;QACnC,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,IAAI;KACQ,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,0CAA0C,GAAG,GAAiB,EAAE;IAC3E,OAAO;QACL,GAAG,EAAE,4BAA4B,EAAE;QACnC,aAAa,EAAE,QAAQ;QACvB,QAAQ,EAAE,IAAI;KACQ,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,WAAW;IAClB,GAAG,EAAE;QACH,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,EAAE;QACR,iBAAiB,EAAE,EAAE;KACtB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,yCAAyC,GAAG,GAAiB,EAAE;IAC1E,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,iBAAiB;KACL,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,yCAAyC,GAAG,GAAiB,EAAE;IAC1E,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,EAAE;KACU,CAAC;AAC3B,CAAC,CAAC","sourcesContent":["import { REGISTRATION_TOKENS_ENDPOINT } from '../services/endpoints';\n\ntype MockResponse = {\n url: string | RegExp;\n requestMethod: 'GET' | 'POST' | 'PUT' | 'DELETE';\n response: unknown;\n};\n\nexport const MOCK_REG_TOKEN = 'REG_TOKEN';\n\nexport const getMockUpdatePushNotificationLinksResponse = (): MockResponse => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT(),\n requestMethod: 'POST',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const getMockDeletePushNotificationLinksResponse = (): MockResponse => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT(),\n requestMethod: 'DELETE',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const MOCK_FCM_RESPONSE = {\n name: '',\n token: 'fcm-token',\n web: {\n endpoint: '',\n p256dh: '',\n auth: '',\n applicationPubKey: '',\n },\n};\n\nexport const getMockCreateFCMRegistrationTokenResponse = (): MockResponse => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: MOCK_FCM_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockDeleteFCMRegistrationTokenResponse = (): MockResponse => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: {},\n } satisfies MockResponse;\n};\n"]}
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.deactivatePushNotifications = exports.activatePushNotifications = exports.updateLinksAPI = void 0;
|
|
26
|
+
exports.deactivatePushNotifications = exports.activatePushNotifications = exports.deleteLinksAPI = exports.updateLinksAPI = void 0;
|
|
27
27
|
const endpoints = __importStar(require("./endpoints.cjs"));
|
|
28
28
|
/**
|
|
29
29
|
* Updates the push notification links on a remote API.
|
|
@@ -52,6 +52,36 @@ async function updateLinksAPI(params) {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
exports.updateLinksAPI = updateLinksAPI;
|
|
55
|
+
/**
|
|
56
|
+
* Deletes push notification links for addresses and platform.
|
|
57
|
+
*
|
|
58
|
+
* @param params - params for deleting registration links
|
|
59
|
+
* @returns A promise that resolves with true if the delete request was successful, false otherwise.
|
|
60
|
+
*/
|
|
61
|
+
async function deleteLinksAPI(params) {
|
|
62
|
+
try {
|
|
63
|
+
const body = {
|
|
64
|
+
addresses: params.addresses,
|
|
65
|
+
registration_token: {
|
|
66
|
+
platform: params.platform,
|
|
67
|
+
token: params.token,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
const response = await fetch(endpoints.REGISTRATION_TOKENS_ENDPOINT(params.env), {
|
|
71
|
+
method: 'DELETE',
|
|
72
|
+
headers: {
|
|
73
|
+
Authorization: `Bearer ${params.bearerToken}`,
|
|
74
|
+
'Content-Type': 'application/json',
|
|
75
|
+
},
|
|
76
|
+
body: JSON.stringify(body),
|
|
77
|
+
});
|
|
78
|
+
return response.ok;
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.deleteLinksAPI = deleteLinksAPI;
|
|
55
85
|
/**
|
|
56
86
|
* Enables push notifications by registering the device and linking triggers.
|
|
57
87
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2DAAyC;
|
|
1
|
+
{"version":3,"file":"services.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2DAAyC;AAgDzC;;;;;GAKG;AACI,KAAK,UAAU,cAAc,CAClC,MAA6B;IAE7B,IAAI,CAAC;QACH,MAAM,IAAI,GAAqB;YAC7B,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,kBAAkB,EAAE,MAAM,CAAC,QAAQ;SACpC,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,SAAS,CAAC,4BAA4B,CAAC,MAAM,CAAC,GAAG,CAAC,EAClD;YACE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,MAAM,CAAC,WAAW,EAAE;gBAC7C,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CACF,CAAC;QACF,OAAO,QAAQ,CAAC,EAAE,CAAC;IACrB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAvBD,wCAuBC;AAUD;;;;;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,QAAQ,CAAC,QAAQ;SACnC;QACD,GAAG,EAAE,MAAM,CAAC,aAAa;KAC1B,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC;AAvBD,8DAuBC;AAWD;;;;;;GAMG;AACI,KAAK,UAAU,2BAA2B,CAC/C,MAAyC;IAEzC,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC;IAEjD,yDAAyD;IACzD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,qBAAqB,GAAG,MAAM,cAAc,CAAC,GAAG,CAAC,CAAC;IACxD,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAhBD,kEAgBC","sourcesContent":["import type { ENV } from './endpoints';\nimport * as endpoints from './endpoints';\nimport type { PushNotificationEnv } from '../types';\nimport type {\n CreateRegToken,\n DeleteRegToken,\n} from '../types/push-service-interface';\n\nexport type RegToken = {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n locale: string;\n oldToken?: string;\n};\n\nexport type RegistrationPlatform = 'extension' | 'mobile';\n\n/**\n * Links API Response Shape\n */\nexport type PushTokenRequest = {\n addresses: string[];\n // API response uses snake_case for this property\n // eslint-disable-next-line @typescript-eslint/naming-convention\n registration_token: {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n locale: string;\n oldToken?: string;\n };\n};\n\nexport type DeletePushTokenRequest = {\n addresses: string[];\n // API request uses snake_case for this property\n // eslint-disable-next-line @typescript-eslint/naming-convention\n registration_token: {\n platform: RegistrationPlatform;\n token: string;\n };\n};\n\ntype UpdatePushTokenParams = {\n bearerToken: string;\n addresses: string[];\n regToken: RegToken;\n env?: ENV;\n};\n\n/**\n * Updates the push notification links on a remote API.\n *\n * @param params - params for invoking update reg token\n * @returns A promise that resolves with true if the update was successful, false otherwise.\n */\nexport async function updateLinksAPI(\n params: UpdatePushTokenParams,\n): Promise<boolean> {\n try {\n const body: PushTokenRequest = {\n addresses: params.addresses,\n registration_token: params.regToken,\n };\n const response = await fetch(\n endpoints.REGISTRATION_TOKENS_ENDPOINT(params.env),\n {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${params.bearerToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n },\n );\n return response.ok;\n } catch {\n return false;\n }\n}\n\ntype DeletePushTokenParams = {\n bearerToken: string;\n addresses: string[];\n platform: RegistrationPlatform;\n token: string;\n env?: ENV;\n};\n\n/**\n * Deletes push notification links for addresses and platform.\n *\n * @param params - params for deleting registration links\n * @returns A promise that resolves with true if the delete request was successful, false otherwise.\n */\nexport async function deleteLinksAPI(\n params: DeletePushTokenParams,\n): Promise<boolean> {\n try {\n const body: DeletePushTokenRequest = {\n addresses: params.addresses,\n registration_token: {\n platform: params.platform,\n token: params.token,\n },\n };\n const response = await fetch(\n endpoints.REGISTRATION_TOKENS_ENDPOINT(params.env),\n {\n method: 'DELETE',\n headers: {\n Authorization: `Bearer ${params.bearerToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n },\n );\n return response.ok;\n } catch {\n return false;\n }\n}\n\ntype ActivatePushNotificationsParams = {\n // Create Push Token\n env: PushNotificationEnv;\n createRegToken: CreateRegToken;\n controllerEnv?: ENV;\n\n // Other Request Parameters\n bearerToken: string;\n addresses: string[];\n regToken: Pick<RegToken, 'locale' | 'platform' | 'oldToken'>;\n};\n\n/**\n * Enables push notifications by registering the device and linking triggers.\n *\n * @param params - Activate Push Params\n * @returns A promise that resolves with an object containing the success status and the BearerToken token.\n */\nexport async function activatePushNotifications(\n params: ActivatePushNotificationsParams,\n): Promise<string | null> {\n const { env, createRegToken } = params;\n\n const regToken = await createRegToken(env).catch(() => null);\n if (!regToken) {\n return null;\n }\n\n await updateLinksAPI({\n bearerToken: params.bearerToken,\n addresses: params.addresses,\n regToken: {\n token: regToken,\n platform: params.regToken.platform,\n locale: params.regToken.locale,\n oldToken: params.regToken.oldToken,\n },\n env: params.controllerEnv,\n });\n\n return regToken;\n}\n\ntype DeactivatePushNotificationsParams = {\n // Push Links\n regToken: string;\n\n // Push Un-registration\n env: PushNotificationEnv;\n deleteRegToken: DeleteRegToken;\n};\n\n/**\n * Disables push notifications by removing the registration token\n * We do not need to unlink triggers, and remove old reg tokens (this is cleaned up in the back-end)\n *\n * @param params - Deactivate Push Params\n * @returns A promise that resolves with true if push notifications were successfully disabled, false otherwise.\n */\nexport async function deactivatePushNotifications(\n params: DeactivatePushNotificationsParams,\n): Promise<boolean> {\n const { regToken, env, deleteRegToken } = params;\n\n // if we don't have a reg token, then we can early return\n if (!regToken) {\n return true;\n }\n\n const isTokenRemovedFromFCM = await deleteRegToken(env);\n if (!isTokenRemovedFromFCM) {\n return false;\n }\n\n return true;\n}\n"]}
|
|
@@ -7,6 +7,7 @@ export type RegToken = {
|
|
|
7
7
|
locale: string;
|
|
8
8
|
oldToken?: string;
|
|
9
9
|
};
|
|
10
|
+
export type RegistrationPlatform = 'extension' | 'mobile';
|
|
10
11
|
/**
|
|
11
12
|
* Links API Response Shape
|
|
12
13
|
*/
|
|
@@ -19,6 +20,13 @@ export type PushTokenRequest = {
|
|
|
19
20
|
oldToken?: string;
|
|
20
21
|
};
|
|
21
22
|
};
|
|
23
|
+
export type DeletePushTokenRequest = {
|
|
24
|
+
addresses: string[];
|
|
25
|
+
registration_token: {
|
|
26
|
+
platform: RegistrationPlatform;
|
|
27
|
+
token: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
22
30
|
type UpdatePushTokenParams = {
|
|
23
31
|
bearerToken: string;
|
|
24
32
|
addresses: string[];
|
|
@@ -32,6 +40,20 @@ type UpdatePushTokenParams = {
|
|
|
32
40
|
* @returns A promise that resolves with true if the update was successful, false otherwise.
|
|
33
41
|
*/
|
|
34
42
|
export declare function updateLinksAPI(params: UpdatePushTokenParams): Promise<boolean>;
|
|
43
|
+
type DeletePushTokenParams = {
|
|
44
|
+
bearerToken: string;
|
|
45
|
+
addresses: string[];
|
|
46
|
+
platform: RegistrationPlatform;
|
|
47
|
+
token: string;
|
|
48
|
+
env?: ENV;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Deletes push notification links for addresses and platform.
|
|
52
|
+
*
|
|
53
|
+
* @param params - params for deleting registration links
|
|
54
|
+
* @returns A promise that resolves with true if the delete request was successful, false otherwise.
|
|
55
|
+
*/
|
|
56
|
+
export declare function deleteLinksAPI(params: DeletePushTokenParams): Promise<boolean>;
|
|
35
57
|
type ActivatePushNotificationsParams = {
|
|
36
58
|
env: PushNotificationEnv;
|
|
37
59
|
createRegToken: CreateRegToken;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAoB;AAEvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAAiB;AACpD,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACf,4CAAwC;AAEzC,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,EAAE,CAAC;IAGpB,kBAAkB,EAAE;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;QAC/C,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,GAAG,CAAC,EAAE,GAAG,CAAC;CACX,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,OAAO,CAAC,CAqBlB;AAED,KAAK,+BAA+B,GAAG;IAErC,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;IAC/B,aAAa,CAAC,EAAE,GAAG,CAAC;IAGpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,+BAA+B,GACtC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAqBxB;AAED,KAAK,iCAAiC,GAAG;IAEvC,QAAQ,EAAE,MAAM,CAAC;IAGjB,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,iCAAiC,GACxC,OAAO,CAAC,OAAO,CAAC,CAclB"}
|
|
1
|
+
{"version":3,"file":"services.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAoB;AAEvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAAiB;AACpD,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACf,4CAAwC;AAEzC,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WA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AmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;IAC/B,aAAa,CAAC,EAAE,GAAG,CAAC;IAGpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,+BAA+B,GACtC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAqBxB;AAED,KAAK,iCAAiC,GAAG;IAEvC,QAAQ,EAAE,MAAM,CAAC;IAGjB,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,iCAAiC,GACxC,OAAO,CAAC,OAAO,CAAC,CAclB"}
|
|
@@ -7,6 +7,7 @@ export type RegToken = {
|
|
|
7
7
|
locale: string;
|
|
8
8
|
oldToken?: string;
|
|
9
9
|
};
|
|
10
|
+
export type RegistrationPlatform = 'extension' | 'mobile';
|
|
10
11
|
/**
|
|
11
12
|
* Links API Response Shape
|
|
12
13
|
*/
|
|
@@ -19,6 +20,13 @@ export type PushTokenRequest = {
|
|
|
19
20
|
oldToken?: string;
|
|
20
21
|
};
|
|
21
22
|
};
|
|
23
|
+
export type DeletePushTokenRequest = {
|
|
24
|
+
addresses: string[];
|
|
25
|
+
registration_token: {
|
|
26
|
+
platform: RegistrationPlatform;
|
|
27
|
+
token: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
22
30
|
type UpdatePushTokenParams = {
|
|
23
31
|
bearerToken: string;
|
|
24
32
|
addresses: string[];
|
|
@@ -32,6 +40,20 @@ type UpdatePushTokenParams = {
|
|
|
32
40
|
* @returns A promise that resolves with true if the update was successful, false otherwise.
|
|
33
41
|
*/
|
|
34
42
|
export declare function updateLinksAPI(params: UpdatePushTokenParams): Promise<boolean>;
|
|
43
|
+
type DeletePushTokenParams = {
|
|
44
|
+
bearerToken: string;
|
|
45
|
+
addresses: string[];
|
|
46
|
+
platform: RegistrationPlatform;
|
|
47
|
+
token: string;
|
|
48
|
+
env?: ENV;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Deletes push notification links for addresses and platform.
|
|
52
|
+
*
|
|
53
|
+
* @param params - params for deleting registration links
|
|
54
|
+
* @returns A promise that resolves with true if the delete request was successful, false otherwise.
|
|
55
|
+
*/
|
|
56
|
+
export declare function deleteLinksAPI(params: DeletePushTokenParams): Promise<boolean>;
|
|
35
57
|
type ActivatePushNotificationsParams = {
|
|
36
58
|
env: PushNotificationEnv;
|
|
37
59
|
createRegToken: CreateRegToken;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAoB;AAEvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAAiB;AACpD,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACf,4CAAwC;AAEzC,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,EAAE,CAAC;IAGpB,kBAAkB,EAAE;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;QAC/C,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,GAAG,CAAC,EAAE,GAAG,CAAC;CACX,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,OAAO,CAAC,CAqBlB;AAED,KAAK,+BAA+B,GAAG;IAErC,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;IAC/B,aAAa,CAAC,EAAE,GAAG,CAAC;IAGpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,+BAA+B,GACtC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAqBxB;AAED,KAAK,iCAAiC,GAAG;IAEvC,QAAQ,EAAE,MAAM,CAAC;IAGjB,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,iCAAiC,GACxC,OAAO,CAAC,OAAO,CAAC,CAclB"}
|
|
1
|
+
{"version":3,"file":"services.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAoB;AAEvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAAiB;AACpD,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACf,4CAAwC;AAEzC,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QA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K,+BAA+B,GAAG;IAErC,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;IAC/B,aAAa,CAAC,EAAE,GAAG,CAAC;IAGpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,+BAA+B,GACtC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAqBxB;AAED,KAAK,iCAAiC,GAAG;IAEvC,QAAQ,EAAE,MAAM,CAAC;IAGjB,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,iCAAiC,GACxC,OAAO,CAAC,OAAO,CAAC,CAclB"}
|
|
@@ -25,6 +25,35 @@ export async function updateLinksAPI(params) {
|
|
|
25
25
|
return false;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Deletes push notification links for addresses and platform.
|
|
30
|
+
*
|
|
31
|
+
* @param params - params for deleting registration links
|
|
32
|
+
* @returns A promise that resolves with true if the delete request was successful, false otherwise.
|
|
33
|
+
*/
|
|
34
|
+
export async function deleteLinksAPI(params) {
|
|
35
|
+
try {
|
|
36
|
+
const body = {
|
|
37
|
+
addresses: params.addresses,
|
|
38
|
+
registration_token: {
|
|
39
|
+
platform: params.platform,
|
|
40
|
+
token: params.token,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const response = await fetch(endpoints.REGISTRATION_TOKENS_ENDPOINT(params.env), {
|
|
44
|
+
method: 'DELETE',
|
|
45
|
+
headers: {
|
|
46
|
+
Authorization: `Bearer ${params.bearerToken}`,
|
|
47
|
+
'Content-Type': 'application/json',
|
|
48
|
+
},
|
|
49
|
+
body: JSON.stringify(body),
|
|
50
|
+
});
|
|
51
|
+
return response.ok;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
28
57
|
/**
|
|
29
58
|
* Enables push notifications by registering the device and linking triggers.
|
|
30
59
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,SAAS,wBAAoB;
|
|
1
|
+
{"version":3,"file":"services.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,SAAS,wBAAoB;AAgDzC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAA6B;IAE7B,IAAI,CAAC;QACH,MAAM,IAAI,GAAqB;YAC7B,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,kBAAkB,EAAE,MAAM,CAAC,QAAQ;SACpC,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,SAAS,CAAC,4BAA4B,CAAC,MAAM,CAAC,GAAG,CAAC,EAClD;YACE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,MAAM,CAAC,WAAW,EAAE;gBAC7C,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CACF,CAAC;QACF,OAAO,QAAQ,CAAC,EAAE,CAAC;IACrB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAUD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAA6B;IAE7B,IAAI,CAAC;QACH,MAAM,IAAI,GAA2B;YACnC,SAAS,EAAE,MAA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B,CAAC;AAWD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,MAAyC;IAEzC,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC;IAEjD,yDAAyD;IACzD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,qBAAqB,GAAG,MAAM,cAAc,CAAC,GAAG,CAAC,CAAC;IACxD,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { ENV } from './endpoints';\nimport * as endpoints from './endpoints';\nimport type { PushNotificationEnv } from '../types';\nimport type {\n CreateRegToken,\n DeleteRegToken,\n} from '../types/push-service-interface';\n\nexport type RegToken = {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n locale: string;\n oldToken?: string;\n};\n\nexport type RegistrationPlatform = 'extension' | 'mobile';\n\n/**\n * Links API Response Shape\n */\nexport type PushTokenRequest = {\n addresses: string[];\n // API response uses snake_case for this property\n // eslint-disable-next-line @typescript-eslint/naming-convention\n registration_token: {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n locale: string;\n oldToken?: string;\n };\n};\n\nexport type DeletePushTokenRequest = {\n addresses: string[];\n // API request uses snake_case for this property\n // eslint-disable-next-line @typescript-eslint/naming-convention\n registration_token: {\n platform: RegistrationPlatform;\n token: string;\n };\n};\n\ntype UpdatePushTokenParams = {\n bearerToken: string;\n addresses: string[];\n regToken: RegToken;\n env?: ENV;\n};\n\n/**\n * Updates the push notification links on a remote API.\n *\n * @param params - params for invoking update reg token\n * @returns A promise that resolves with true if the update was successful, false otherwise.\n */\nexport async function updateLinksAPI(\n params: UpdatePushTokenParams,\n): Promise<boolean> {\n try {\n const body: PushTokenRequest = {\n addresses: params.addresses,\n registration_token: params.regToken,\n };\n const response = await fetch(\n endpoints.REGISTRATION_TOKENS_ENDPOINT(params.env),\n {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${params.bearerToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n },\n );\n return response.ok;\n } catch {\n return false;\n }\n}\n\ntype DeletePushTokenParams = {\n bearerToken: string;\n addresses: string[];\n platform: RegistrationPlatform;\n token: string;\n env?: ENV;\n};\n\n/**\n * Deletes push notification links for addresses and platform.\n *\n * @param params - params for deleting registration links\n * @returns A promise that resolves with true if the delete request was successful, false otherwise.\n */\nexport async function deleteLinksAPI(\n params: DeletePushTokenParams,\n): Promise<boolean> {\n try {\n const body: DeletePushTokenRequest = {\n addresses: params.addresses,\n registration_token: {\n platform: params.platform,\n token: params.token,\n },\n };\n const response = await fetch(\n endpoints.REGISTRATION_TOKENS_ENDPOINT(params.env),\n {\n method: 'DELETE',\n headers: {\n Authorization: `Bearer ${params.bearerToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n },\n );\n return response.ok;\n } catch {\n return false;\n }\n}\n\ntype ActivatePushNotificationsParams = {\n // Create Push Token\n env: PushNotificationEnv;\n createRegToken: CreateRegToken;\n controllerEnv?: ENV;\n\n // Other Request Parameters\n bearerToken: string;\n addresses: string[];\n regToken: Pick<RegToken, 'locale' | 'platform' | 'oldToken'>;\n};\n\n/**\n * Enables push notifications by registering the device and linking triggers.\n *\n * @param params - Activate Push Params\n * @returns A promise that resolves with an object containing the success status and the BearerToken token.\n */\nexport async function activatePushNotifications(\n params: ActivatePushNotificationsParams,\n): Promise<string | null> {\n const { env, createRegToken } = params;\n\n const regToken = await createRegToken(env).catch(() => null);\n if (!regToken) {\n return null;\n }\n\n await updateLinksAPI({\n bearerToken: params.bearerToken,\n addresses: params.addresses,\n regToken: {\n token: regToken,\n platform: params.regToken.platform,\n locale: params.regToken.locale,\n oldToken: params.regToken.oldToken,\n },\n env: params.controllerEnv,\n });\n\n return regToken;\n}\n\ntype DeactivatePushNotificationsParams = {\n // Push Links\n regToken: string;\n\n // Push Un-registration\n env: PushNotificationEnv;\n deleteRegToken: DeleteRegToken;\n};\n\n/**\n * Disables push notifications by removing the registration token\n * We do not need to unlink triggers, and remove old reg tokens (this is cleaned up in the back-end)\n *\n * @param params - Deactivate Push Params\n * @returns A promise that resolves with true if push notifications were successfully disabled, false otherwise.\n */\nexport async function deactivatePushNotifications(\n params: DeactivatePushNotificationsParams,\n): Promise<boolean> {\n const { regToken, env, deleteRegToken } = params;\n\n // if we don't have a reg token, then we can early return\n if (!regToken) {\n return true;\n }\n\n const isTokenRemovedFromFCM = await deleteRegToken(env);\n if (!isTokenRemovedFromFCM) {\n return false;\n }\n\n return true;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/notification-services-controller",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "23.0.0",
|
|
4
4
|
"description": "Manages New MetaMask decentralized Notification system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -92,6 +92,9 @@
|
|
|
92
92
|
"build:docs": "typedoc",
|
|
93
93
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/notification-services-controller",
|
|
94
94
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/notification-services-controller",
|
|
95
|
+
"generate-method-action-types": "yarn generate-method-action-types:notifications-services-controller \"$@\" && yarn generate-method-action-types:notifications-services-push-controller \"$@\"",
|
|
96
|
+
"generate-method-action-types:notifications-services-controller": "tsx ../../scripts/generate-method-action-types.ts src/NotificationServicesController",
|
|
97
|
+
"generate-method-action-types:notifications-services-push-controller": "tsx ../../scripts/generate-method-action-types.ts src/NotificationServicesPushController",
|
|
95
98
|
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
96
99
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
97
100
|
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
@@ -128,6 +131,7 @@
|
|
|
128
131
|
"jest-environment-jsdom": "^29.7.0",
|
|
129
132
|
"nock": "^13.3.1",
|
|
130
133
|
"ts-jest": "^29.2.5",
|
|
134
|
+
"tsx": "^4.20.5",
|
|
131
135
|
"typedoc": "^0.25.13",
|
|
132
136
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
133
137
|
"typescript": "~5.3.3"
|