@metamask-previews/notification-services-controller 0.18.0-preview-442894ce → 0.18.0-preview-9a5238f
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/dist/NotificationServicesController/NotificationServicesController.cjs +49 -48
- package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.cts +3 -3
- package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.mts +3 -3
- package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.mjs +49 -48
- package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
- package/dist/NotificationServicesController/index.cjs +0 -1
- package/dist/NotificationServicesController/index.cjs.map +1 -1
- package/dist/NotificationServicesController/index.d.cts +0 -1
- package/dist/NotificationServicesController/index.d.cts.map +1 -1
- package/dist/NotificationServicesController/index.d.mts +0 -1
- package/dist/NotificationServicesController/index.d.mts.map +1 -1
- package/dist/NotificationServicesController/index.mjs +0 -1
- package/dist/NotificationServicesController/index.mjs.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +40 -43
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +21 -19
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +21 -19
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +41 -44
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
- package/dist/NotificationServicesPushController/{types/push-service-interface.cjs → services/push/index.cjs} +1 -1
- package/dist/NotificationServicesPushController/services/push/index.cjs.map +1 -0
- package/dist/NotificationServicesPushController/services/push/index.d.cts +6 -0
- package/dist/NotificationServicesPushController/services/push/index.d.cts.map +1 -0
- package/dist/NotificationServicesPushController/services/push/index.d.mts +6 -0
- package/dist/NotificationServicesPushController/services/push/index.d.mts.map +1 -0
- package/dist/NotificationServicesPushController/services/push/index.mjs +2 -0
- package/dist/NotificationServicesPushController/services/push/index.mjs.map +1 -0
- package/dist/NotificationServicesPushController/{web/push-helpers.cjs → services/push/push-web.cjs} +8 -37
- package/dist/NotificationServicesPushController/services/push/push-web.cjs.map +1 -0
- package/dist/NotificationServicesPushController/services/push/push-web.d.cts +33 -0
- package/dist/NotificationServicesPushController/services/push/push-web.d.cts.map +1 -0
- package/dist/NotificationServicesPushController/services/push/push-web.d.mts +33 -0
- package/dist/NotificationServicesPushController/services/push/push-web.d.mts.map +1 -0
- package/dist/NotificationServicesPushController/{web/push-helpers.mjs → services/push/push-web.mjs} +7 -37
- package/dist/NotificationServicesPushController/services/push/push-web.mjs.map +1 -0
- package/dist/NotificationServicesPushController/services/services.cjs +28 -3
- package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
- package/dist/NotificationServicesPushController/services/services.d.cts +15 -1
- package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/services/services.d.mts +15 -1
- package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/services/services.mjs +26 -2
- package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
- package/dist/NotificationServicesPushController/types/index.cjs +15 -0
- package/dist/NotificationServicesPushController/types/index.cjs.map +1 -1
- package/dist/NotificationServicesPushController/types/index.d.cts +1 -2
- package/dist/NotificationServicesPushController/types/index.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/types/index.d.mts +1 -2
- package/dist/NotificationServicesPushController/types/index.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/types/index.mjs +1 -1
- package/dist/NotificationServicesPushController/types/index.mjs.map +1 -1
- package/package.json +2 -12
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.cjs +0 -14
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.cjs.map +0 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.cts +0 -3
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.cts.map +0 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.mts +0 -3
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.mts.map +0 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.mjs +0 -10
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.mjs.map +0 -1
- package/dist/NotificationServicesPushController/types/push-service-interface.cjs.map +0 -1
- package/dist/NotificationServicesPushController/types/push-service-interface.d.cts +0 -30
- package/dist/NotificationServicesPushController/types/push-service-interface.d.cts.map +0 -1
- package/dist/NotificationServicesPushController/types/push-service-interface.d.mts +0 -30
- package/dist/NotificationServicesPushController/types/push-service-interface.d.mts.map +0 -1
- package/dist/NotificationServicesPushController/types/push-service-interface.mjs +0 -2
- package/dist/NotificationServicesPushController/types/push-service-interface.mjs.map +0 -1
- package/dist/NotificationServicesPushController/web/index.cjs +0 -8
- package/dist/NotificationServicesPushController/web/index.cjs.map +0 -1
- package/dist/NotificationServicesPushController/web/index.d.cts +0 -2
- package/dist/NotificationServicesPushController/web/index.d.cts.map +0 -1
- package/dist/NotificationServicesPushController/web/index.d.mts +0 -2
- package/dist/NotificationServicesPushController/web/index.d.mts.map +0 -1
- package/dist/NotificationServicesPushController/web/index.mjs +0 -2
- package/dist/NotificationServicesPushController/web/index.mjs.map +0 -1
- package/dist/NotificationServicesPushController/web/push-helpers.cjs.map +0 -1
- package/dist/NotificationServicesPushController/web/push-helpers.d.cts +0 -37
- package/dist/NotificationServicesPushController/web/push-helpers.d.cts.map +0 -1
- package/dist/NotificationServicesPushController/web/push-helpers.d.mts +0 -37
- package/dist/NotificationServicesPushController/web/push-helpers.d.mts.map +0 -1
- package/dist/NotificationServicesPushController/web/push-helpers.mjs.map +0 -1
- package/push-services/web/package.json +0 -9
|
@@ -1,3 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./firebase.cjs"), exports);
|
|
3
18
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/index.ts"],"names":[],"mappings":"","sourcesContent":["export
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA2B","sourcesContent":["export * from './firebase';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/index.ts"],"names":[],"mappings":"AAAA,+BAA2B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/index.ts"],"names":[],"mappings":"AAAA,+BAA2B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from "./firebase.mjs";
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/index.ts"],"names":[],"mappings":"","sourcesContent":["export
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/index.ts"],"names":[],"mappings":"AAAA,+BAA2B","sourcesContent":["export * from './firebase';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/notification-services-controller",
|
|
3
|
-
"version": "0.18.0-preview-
|
|
3
|
+
"version": "0.18.0-preview-9a5238f",
|
|
4
4
|
"description": "Manages New MetaMask decentralized Notification system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -67,16 +67,6 @@
|
|
|
67
67
|
"default": "./dist/NotificationServicesPushController/index.cjs"
|
|
68
68
|
}
|
|
69
69
|
},
|
|
70
|
-
"./push-services/web": {
|
|
71
|
-
"import": {
|
|
72
|
-
"types": "./dist/NotificationServicesPushController/web/index.d.mts",
|
|
73
|
-
"default": "./dist/NotificationServicesPushController/web/index.mjs"
|
|
74
|
-
},
|
|
75
|
-
"require": {
|
|
76
|
-
"types": "./dist/NotificationServicesPushController/web/index.d.cts",
|
|
77
|
-
"default": "./dist/NotificationServicesPushController/web/index.cjs"
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
70
|
"./push-services/mocks": {
|
|
81
71
|
"import": {
|
|
82
72
|
"types": "./dist/NotificationServicesPushController/__fixtures__/index.d.mts",
|
|
@@ -112,7 +102,7 @@
|
|
|
112
102
|
"@contentful/rich-text-html-renderer": "^16.5.2",
|
|
113
103
|
"@metamask/base-controller": "^7.1.1",
|
|
114
104
|
"@metamask/controller-utils": "^11.4.5",
|
|
115
|
-
"@metamask/utils": "^11.0
|
|
105
|
+
"@metamask/utils": "^11.1.0",
|
|
116
106
|
"bignumber.js": "^9.1.2",
|
|
117
107
|
"firebase": "^11.2.0",
|
|
118
108
|
"loglevel": "^1.8.1",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildPushPlatformNotificationsControllerMessenger = void 0;
|
|
4
|
-
const base_controller_1 = require("@metamask/base-controller");
|
|
5
|
-
const buildPushPlatformNotificationsControllerMessenger = () => {
|
|
6
|
-
const globalMessenger = new base_controller_1.ControllerMessenger();
|
|
7
|
-
return globalMessenger.getRestricted({
|
|
8
|
-
name: 'NotificationServicesPushController',
|
|
9
|
-
allowedActions: ['AuthenticationController:getBearerToken'],
|
|
10
|
-
allowedEvents: [],
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
exports.buildPushPlatformNotificationsControllerMessenger = buildPushPlatformNotificationsControllerMessenger;
|
|
14
|
-
//# sourceMappingURL=mockMessenger.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mockMessenger.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/__fixtures__/mockMessenger.ts"],"names":[],"mappings":";;;AAAA,+DAAgE;AAQzD,MAAM,iDAAiD,GAC5D,GAAgD,EAAE;IAChD,MAAM,eAAe,GAAG,IAAI,qCAAmB,EAG5C,CAAC;IAEJ,OAAO,eAAe,CAAC,aAAa,CAGlC;QACA,IAAI,EAAE,oCAAoC;QAC1C,cAAc,EAAE,CAAC,yCAAyC,CAAC;QAC3D,aAAa,EAAE,EAAE;KAClB,CAAC,CAAC;AACL,CAAC,CAAC;AAfS,QAAA,iDAAiD,qDAe1D","sourcesContent":["import { ControllerMessenger } from '@metamask/base-controller';\n\nimport type {\n AllowedActions,\n AllowedEvents,\n NotificationServicesPushControllerMessenger,\n} from '..';\n\nexport const buildPushPlatformNotificationsControllerMessenger =\n (): NotificationServicesPushControllerMessenger => {\n const globalMessenger = new ControllerMessenger<\n AllowedActions,\n AllowedEvents\n >();\n\n return globalMessenger.getRestricted<\n 'NotificationServicesPushController',\n AllowedActions['type']\n >({\n name: 'NotificationServicesPushController',\n allowedActions: ['AuthenticationController:getBearerToken'],\n allowedEvents: [],\n });\n };\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mockMessenger.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/__fixtures__/mockMessenger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,2CAA2C,EAC5C,qBAAW;AAEZ,eAAO,MAAM,iDAAiD,mDAe3D,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mockMessenger.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/__fixtures__/mockMessenger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,2CAA2C,EAC5C,qBAAW;AAEZ,eAAO,MAAM,iDAAiD,mDAe3D,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ControllerMessenger } from "@metamask/base-controller";
|
|
2
|
-
export const buildPushPlatformNotificationsControllerMessenger = () => {
|
|
3
|
-
const globalMessenger = new ControllerMessenger();
|
|
4
|
-
return globalMessenger.getRestricted({
|
|
5
|
-
name: 'NotificationServicesPushController',
|
|
6
|
-
allowedActions: ['AuthenticationController:getBearerToken'],
|
|
7
|
-
allowedEvents: [],
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=mockMessenger.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mockMessenger.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/__fixtures__/mockMessenger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,kCAAkC;AAQhE,MAAM,CAAC,MAAM,iDAAiD,GAC5D,GAAgD,EAAE;IAChD,MAAM,eAAe,GAAG,IAAI,mBAAmB,EAG5C,CAAC;IAEJ,OAAO,eAAe,CAAC,aAAa,CAGlC;QACA,IAAI,EAAE,oCAAoC;QAC1C,cAAc,EAAE,CAAC,yCAAyC,CAAC;QAC3D,aAAa,EAAE,EAAE;KAClB,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { ControllerMessenger } from '@metamask/base-controller';\n\nimport type {\n AllowedActions,\n AllowedEvents,\n NotificationServicesPushControllerMessenger,\n} from '..';\n\nexport const buildPushPlatformNotificationsControllerMessenger =\n (): NotificationServicesPushControllerMessenger => {\n const globalMessenger = new ControllerMessenger<\n AllowedActions,\n AllowedEvents\n >();\n\n return globalMessenger.getRestricted<\n 'NotificationServicesPushController',\n AllowedActions['type']\n >({\n name: 'NotificationServicesPushController',\n allowedActions: ['AuthenticationController:getBearerToken'],\n allowedEvents: [],\n });\n };\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push-service-interface.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/push-service-interface.ts"],"names":[],"mappings":"","sourcesContent":["import type { PushNotificationEnv } from '.';\n\ntype Unsubscribe = () => void;\n\n/**\n * Firebase - allows creating of a registration token for push notifications\n */\nexport type CreateRegToken = (\n env: PushNotificationEnv,\n) => Promise<string | null>;\n\n/**\n * Firebase - allows deleting a reg token. Returns true if successful, otherwise false if failed\n */\nexport type DeleteRegToken = (env: PushNotificationEnv) => Promise<boolean>;\n\n/**\n * Firebase + Platform Specific Logic.\n * Will be used to subscribe to the `onMessage` and `onBackgroundMessage` handlers\n * But will also need client specific logic for showing a notification and clicking a notification\n * (browser APIs for web, and Notifee on mobile)\n *\n * We can either create \"creator\"/\"builder\" function in platform specific files (see push-web.ts),\n * Or the platform needs to correctly handle:\n * - subscriptions\n * - click events\n * - publishing PushController events using it's messenger\n */\nexport type SubscribeToPushNotifications = (\n env: PushNotificationEnv,\n) => Promise<Unsubscribe | null>;\n\nexport type PushService = {\n createRegToken: CreateRegToken;\n\n deleteRegToken: DeleteRegToken;\n\n subscribeToPushNotifications: SubscribeToPushNotifications;\n};\n"]}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { PushNotificationEnv } from "./index.cjs";
|
|
2
|
-
type Unsubscribe = () => void;
|
|
3
|
-
/**
|
|
4
|
-
* Firebase - allows creating of a registration token for push notifications
|
|
5
|
-
*/
|
|
6
|
-
export type CreateRegToken = (env: PushNotificationEnv) => Promise<string | null>;
|
|
7
|
-
/**
|
|
8
|
-
* Firebase - allows deleting a reg token. Returns true if successful, otherwise false if failed
|
|
9
|
-
*/
|
|
10
|
-
export type DeleteRegToken = (env: PushNotificationEnv) => Promise<boolean>;
|
|
11
|
-
/**
|
|
12
|
-
* Firebase + Platform Specific Logic.
|
|
13
|
-
* Will be used to subscribe to the `onMessage` and `onBackgroundMessage` handlers
|
|
14
|
-
* But will also need client specific logic for showing a notification and clicking a notification
|
|
15
|
-
* (browser APIs for web, and Notifee on mobile)
|
|
16
|
-
*
|
|
17
|
-
* We can either create "creator"/"builder" function in platform specific files (see push-web.ts),
|
|
18
|
-
* Or the platform needs to correctly handle:
|
|
19
|
-
* - subscriptions
|
|
20
|
-
* - click events
|
|
21
|
-
* - publishing PushController events using it's messenger
|
|
22
|
-
*/
|
|
23
|
-
export type SubscribeToPushNotifications = (env: PushNotificationEnv) => Promise<Unsubscribe | null>;
|
|
24
|
-
export type PushService = {
|
|
25
|
-
createRegToken: CreateRegToken;
|
|
26
|
-
deleteRegToken: DeleteRegToken;
|
|
27
|
-
subscribeToPushNotifications: SubscribeToPushNotifications;
|
|
28
|
-
};
|
|
29
|
-
export {};
|
|
30
|
-
//# sourceMappingURL=push-service-interface.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push-service-interface.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/push-service-interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAU;AAE7C,KAAK,WAAW,GAAG,MAAM,IAAI,CAAC;AAE9B;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAC3B,GAAG,EAAE,mBAAmB,KACrB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAE5E;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,4BAA4B,GAAG,CACzC,GAAG,EAAE,mBAAmB,KACrB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;AAEjC,MAAM,MAAM,WAAW,GAAG;IACxB,cAAc,EAAE,cAAc,CAAC;IAE/B,cAAc,EAAE,cAAc,CAAC;IAE/B,4BAA4B,EAAE,4BAA4B,CAAC;CAC5D,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { PushNotificationEnv } from "./index.mjs";
|
|
2
|
-
type Unsubscribe = () => void;
|
|
3
|
-
/**
|
|
4
|
-
* Firebase - allows creating of a registration token for push notifications
|
|
5
|
-
*/
|
|
6
|
-
export type CreateRegToken = (env: PushNotificationEnv) => Promise<string | null>;
|
|
7
|
-
/**
|
|
8
|
-
* Firebase - allows deleting a reg token. Returns true if successful, otherwise false if failed
|
|
9
|
-
*/
|
|
10
|
-
export type DeleteRegToken = (env: PushNotificationEnv) => Promise<boolean>;
|
|
11
|
-
/**
|
|
12
|
-
* Firebase + Platform Specific Logic.
|
|
13
|
-
* Will be used to subscribe to the `onMessage` and `onBackgroundMessage` handlers
|
|
14
|
-
* But will also need client specific logic for showing a notification and clicking a notification
|
|
15
|
-
* (browser APIs for web, and Notifee on mobile)
|
|
16
|
-
*
|
|
17
|
-
* We can either create "creator"/"builder" function in platform specific files (see push-web.ts),
|
|
18
|
-
* Or the platform needs to correctly handle:
|
|
19
|
-
* - subscriptions
|
|
20
|
-
* - click events
|
|
21
|
-
* - publishing PushController events using it's messenger
|
|
22
|
-
*/
|
|
23
|
-
export type SubscribeToPushNotifications = (env: PushNotificationEnv) => Promise<Unsubscribe | null>;
|
|
24
|
-
export type PushService = {
|
|
25
|
-
createRegToken: CreateRegToken;
|
|
26
|
-
deleteRegToken: DeleteRegToken;
|
|
27
|
-
subscribeToPushNotifications: SubscribeToPushNotifications;
|
|
28
|
-
};
|
|
29
|
-
export {};
|
|
30
|
-
//# sourceMappingURL=push-service-interface.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push-service-interface.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/push-service-interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAU;AAE7C,KAAK,WAAW,GAAG,MAAM,IAAI,CAAC;AAE9B;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAC3B,GAAG,EAAE,mBAAmB,KACrB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAE5E;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,4BAA4B,GAAG,CACzC,GAAG,EAAE,mBAAmB,KACrB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;AAEjC,MAAM,MAAM,WAAW,GAAG;IACxB,cAAc,EAAE,cAAc,CAAC;IAE/B,cAAc,EAAE,cAAc,CAAC;IAE/B,4BAA4B,EAAE,4BAA4B,CAAC;CAC5D,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push-service-interface.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/push-service-interface.ts"],"names":[],"mappings":"","sourcesContent":["import type { PushNotificationEnv } from '.';\n\ntype Unsubscribe = () => void;\n\n/**\n * Firebase - allows creating of a registration token for push notifications\n */\nexport type CreateRegToken = (\n env: PushNotificationEnv,\n) => Promise<string | null>;\n\n/**\n * Firebase - allows deleting a reg token. Returns true if successful, otherwise false if failed\n */\nexport type DeleteRegToken = (env: PushNotificationEnv) => Promise<boolean>;\n\n/**\n * Firebase + Platform Specific Logic.\n * Will be used to subscribe to the `onMessage` and `onBackgroundMessage` handlers\n * But will also need client specific logic for showing a notification and clicking a notification\n * (browser APIs for web, and Notifee on mobile)\n *\n * We can either create \"creator\"/\"builder\" function in platform specific files (see push-web.ts),\n * Or the platform needs to correctly handle:\n * - subscriptions\n * - click events\n * - publishing PushController events using it's messenger\n */\nexport type SubscribeToPushNotifications = (\n env: PushNotificationEnv,\n) => Promise<Unsubscribe | null>;\n\nexport type PushService = {\n createRegToken: CreateRegToken;\n\n deleteRegToken: DeleteRegToken;\n\n subscribeToPushNotifications: SubscribeToPushNotifications;\n};\n"]}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSubscribeToPushNotifications = exports.deleteRegToken = exports.createRegToken = void 0;
|
|
4
|
-
var push_helpers_1 = require("./push-helpers.cjs");
|
|
5
|
-
Object.defineProperty(exports, "createRegToken", { enumerable: true, get: function () { return push_helpers_1.createRegToken; } });
|
|
6
|
-
Object.defineProperty(exports, "deleteRegToken", { enumerable: true, get: function () { return push_helpers_1.deleteRegToken; } });
|
|
7
|
-
Object.defineProperty(exports, "createSubscribeToPushNotifications", { enumerable: true, get: function () { return push_helpers_1.createSubscribeToPushNotifications; } });
|
|
8
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/web/index.ts"],"names":[],"mappings":";;;AAAA,mDAIwB;AAHtB,8GAAA,cAAc,OAAA;AACd,8GAAA,cAAc,OAAA;AACd,kIAAA,kCAAkC,OAAA","sourcesContent":["export {\n createRegToken,\n deleteRegToken,\n createSubscribeToPushNotifications,\n} from './push-helpers';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/web/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,kCAAkC,GACnC,2BAAuB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/web/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,kCAAkC,GACnC,2BAAuB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/web/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,kCAAkC,EACnC,2BAAuB","sourcesContent":["export {\n createRegToken,\n deleteRegToken,\n createSubscribeToPushNotifications,\n} from './push-helpers';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push-helpers.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/web/push-helpers.ts"],"names":[],"mappings":";;;;;;AAIA,sCAAqD;AACrD,kDAA2D;AAC3D,8CAI+B;AAE/B,wDAA2B;AAG3B,mGAAkE;AAClE,8EAA4E;AAM5E,2BAA2B;AAC3B,uDAAuD;AAC5C,QAAA,cAAc,GAAmB,IAAI,CAAC;AAEjD,MAAM,mBAAmB,GAAG,KAAK,I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CAAC;QAEF,MAAM,WAAW,GAAG,GAAG,EAAE;YACvB,sBAAsB,EAAE,EAAE,CAAC;YAC3B,UAAU,EAAE,CAAC;QACf,CAAC,CAAC;QAEF,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC;AAtCD,gFAsCC","sourcesContent":["// We are defining that this file uses a webworker global scope.\n// eslint-disable-next-line spaced-comment\n/// <reference lib=\"webworker\" />\nimport type { FirebaseApp } from 'firebase/app';\nimport { getApp, initializeApp } from 'firebase/app';\nimport { getToken, deleteToken } from 'firebase/messaging';\nimport {\n getMessaging,\n onBackgroundMessage,\n isSupported,\n} from 'firebase/messaging/sw';\nimport type { Messaging, MessagePayload } from 'firebase/messaging/sw';\nimport log from 'loglevel';\n\nimport type { Types } from '../../NotificationServicesController';\nimport { Processors } from '../../NotificationServicesController';\nimport { toRawOnChainNotification } from '../../shared/to-raw-notification';\nimport type { NotificationServicesPushControllerMessenger } from '../NotificationServicesPushController';\nimport type { PushNotificationEnv } from '../types/firebase';\n\ndeclare const self: ServiceWorkerGlobalScope;\n\n// Exported to help testing\n// eslint-disable-next-line import-x/no-mutable-exports\nexport let supportedCache: boolean | null = null;\n\nconst getPushAvailability = async () => {\n supportedCache ??= await isSupported();\n return supportedCache;\n};\n\nconst createFirebaseApp = async (\n env: PushNotificationEnv,\n): Promise<FirebaseApp> => {\n try {\n return getApp();\n } catch {\n const firebaseConfig = {\n apiKey: env.apiKey,\n authDomain: env.authDomain,\n storageBucket: env.storageBucket,\n projectId: env.projectId,\n messagingSenderId: env.messagingSenderId,\n appId: env.appId,\n measurementId: env.measurementId,\n };\n return initializeApp(firebaseConfig);\n }\n};\n\nconst getFirebaseMessaging = async (\n env: PushNotificationEnv,\n): Promise<Messaging | null> => {\n const supported = await getPushAvailability();\n if (!supported) {\n return null;\n }\n\n const app = await createFirebaseApp(env);\n return getMessaging(app);\n};\n\n/**\n * Creates a registration token for Firebase Cloud Messaging.\n *\n * @param env - env to configure push notifications\n * @returns A promise that resolves with the registration token or null if an error occurs.\n */\nexport async function createRegToken(\n env: PushNotificationEnv,\n): Promise<string | null> {\n try {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return null;\n }\n\n const token = await getToken(messaging, {\n serviceWorkerRegistration: self.registration,\n vapidKey: env.vapidKey,\n });\n return token;\n } catch {\n return null;\n }\n}\n\n/**\n * Deletes the Firebase Cloud Messaging registration token.\n *\n * @param env - env to configure push notifications\n * @returns A promise that resolves with true if the token was successfully deleted, false otherwise.\n */\nexport async function deleteRegToken(\n env: PushNotificationEnv,\n): Promise<boolean> {\n try {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return true;\n }\n\n await deleteToken(messaging);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Service Worker Listener for when push notifications are received.\n *\n * @param env - push notification environment\n * @param handler - handler to actually showing notification, MUST BE PROVIDED\n * @returns unsubscribe handler\n */\nasync function listenToPushNotificationsReceived(\n env: PushNotificationEnv,\n handler: (notification: Types.INotification) => void | Promise<void>,\n): Promise<(() => void) | null> {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return null;\n }\n\n const unsubscribePushNotifications = onBackgroundMessage(\n messaging,\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (payload: MessagePayload) => {\n try {\n const data: Types.UnprocessedOnChainRawNotification | undefined =\n payload?.data?.data ? JSON.parse(payload?.data?.data) : undefined;\n\n if (!data) {\n return;\n }\n\n const notificationData = toRawOnChainNotification(data);\n const notification = Processors.processNotification(notificationData);\n await handler(notification);\n } catch (error) {\n // Do Nothing, cannot parse a bad notification\n log.error('Unable to send push notification:', {\n notification: payload?.data?.data,\n error,\n });\n throw new Error('Unable to send push notification');\n }\n },\n );\n\n const unsubscribe = () => unsubscribePushNotifications();\n return unsubscribe;\n}\n\n/**\n * Service Worker Listener for when a notification is clicked\n *\n * @param handler - listen to NotificationEvent from the service worker\n * @returns unsubscribe handler\n */\nfunction listenToPushNotificationsClicked(\n handler: (e: NotificationEvent, notification: Types.INotification) => void,\n) {\n const clickHandler = (event: NotificationEvent) => {\n // Get Data\n const data: Types.INotification = event?.notification?.data;\n handler(event, data);\n };\n\n self.addEventListener('notificationclick', clickHandler);\n const unsubscribe = () =>\n self.removeEventListener('notificationclick', clickHandler);\n return unsubscribe;\n}\n\n/**\n * A creator function that assists creating web-specific push notification subscription:\n * 1. Creates subscriptions for receiving and clicking notifications\n * 2. Creates click events when a notification is clicked\n * 3. Publishes controller messenger events\n *\n * @param props - props for this creator function.\n * @param props.onReceivedHandler - allows the developer to handle showing a notification\n * @param props.onClickHandler - allows the developer to handle clicking the notification\n * @param props.messenger - the controller messenger to publish the `onNewNotifications` and `pushNotificationsClicked` events\n * @returns a function that can be used by the controller\n */\nexport function createSubscribeToPushNotifications(props: {\n onReceivedHandler: (\n notification: Types.INotification,\n ) => void | Promise<void>;\n onClickHandler: (\n e: NotificationEvent,\n notification: Types.INotification,\n ) => void;\n messenger: NotificationServicesPushControllerMessenger;\n}) {\n return async function (env: PushNotificationEnv) {\n const onBackgroundMessageSub = await listenToPushNotificationsReceived(\n env,\n async (notification) => {\n props.messenger.publish(\n 'NotificationServicesPushController:onNewNotifications',\n notification,\n );\n await props.onReceivedHandler(notification);\n },\n );\n const onClickSub = listenToPushNotificationsClicked(\n (event, notification) => {\n props.messenger.publish(\n 'NotificationServicesPushController:pushNotificationClicked',\n notification,\n );\n props.onClickHandler(event, notification);\n },\n );\n\n const unsubscribe = () => {\n onBackgroundMessageSub?.();\n onClickSub();\n };\n\n return unsubscribe;\n };\n}\n"]}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/// <reference lib="webworker" />
|
|
2
|
-
import type { Types } from "../../NotificationServicesController/index.cjs";
|
|
3
|
-
import type { NotificationServicesPushControllerMessenger } from "../NotificationServicesPushController.cjs";
|
|
4
|
-
import type { PushNotificationEnv } from "../types/firebase.cjs";
|
|
5
|
-
export declare let supportedCache: boolean | null;
|
|
6
|
-
/**
|
|
7
|
-
* Creates a registration token for Firebase Cloud Messaging.
|
|
8
|
-
*
|
|
9
|
-
* @param env - env to configure push notifications
|
|
10
|
-
* @returns A promise that resolves with the registration token or null if an error occurs.
|
|
11
|
-
*/
|
|
12
|
-
export declare function createRegToken(env: PushNotificationEnv): Promise<string | null>;
|
|
13
|
-
/**
|
|
14
|
-
* Deletes the Firebase Cloud Messaging registration token.
|
|
15
|
-
*
|
|
16
|
-
* @param env - env to configure push notifications
|
|
17
|
-
* @returns A promise that resolves with true if the token was successfully deleted, false otherwise.
|
|
18
|
-
*/
|
|
19
|
-
export declare function deleteRegToken(env: PushNotificationEnv): Promise<boolean>;
|
|
20
|
-
/**
|
|
21
|
-
* A creator function that assists creating web-specific push notification subscription:
|
|
22
|
-
* 1. Creates subscriptions for receiving and clicking notifications
|
|
23
|
-
* 2. Creates click events when a notification is clicked
|
|
24
|
-
* 3. Publishes controller messenger events
|
|
25
|
-
*
|
|
26
|
-
* @param props - props for this creator function.
|
|
27
|
-
* @param props.onReceivedHandler - allows the developer to handle showing a notification
|
|
28
|
-
* @param props.onClickHandler - allows the developer to handle clicking the notification
|
|
29
|
-
* @param props.messenger - the controller messenger to publish the `onNewNotifications` and `pushNotificationsClicked` events
|
|
30
|
-
* @returns a function that can be used by the controller
|
|
31
|
-
*/
|
|
32
|
-
export declare function createSubscribeToPushNotifications(props: {
|
|
33
|
-
onReceivedHandler: (notification: Types.INotification) => void | Promise<void>;
|
|
34
|
-
onClickHandler: (e: NotificationEvent, notification: Types.INotification) => void;
|
|
35
|
-
messenger: NotificationServicesPushControllerMessenger;
|
|
36
|
-
}): (env: PushNotificationEnv) => Promise<() => void>;
|
|
37
|
-
//# sourceMappingURL=push-helpers.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push-helpers.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/web/push-helpers.ts"],"names":[],"mappings":";AAcA,OAAO,KAAK,EAAE,KAAK,EAAE,uDAA6C;AAGlE,OAAO,KAAK,EAAE,2CAA2C,EAAE,kDAA8C;AACzG,OAAO,KAAK,EAAE,mBAAmB,EAAE,8BAA0B;AAM7D,eAAO,IAAI,cAAc,EAAE,OAAO,GAAG,IAAW,CAAC;AAsCjD;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,mBAAmB,GACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAexB;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,mBAAmB,GACvB,OAAO,CAAC,OAAO,CAAC,CAYlB;AAqED;;;;;;;;;;;GAWG;AACH,wBAAgB,kCAAkC,CAAC,KAAK,EAAE;IACxD,iBAAiB,EAAE,CACjB,YAAY,EAAE,KAAK,CAAC,aAAa,KAC9B,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,cAAc,EAAE,CACd,CAAC,EAAE,iBAAiB,EACpB,YAAY,EAAE,KAAK,CAAC,aAAa,KAC9B,IAAI,CAAC;IACV,SAAS,EAAE,2CAA2C,CAAC;CACxD,SAC6B,mBAAmB,yBA4BhD"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/// <reference lib="webworker" />
|
|
2
|
-
import type { Types } from "../../NotificationServicesController/index.mjs";
|
|
3
|
-
import type { NotificationServicesPushControllerMessenger } from "../NotificationServicesPushController.mjs";
|
|
4
|
-
import type { PushNotificationEnv } from "../types/firebase.mjs";
|
|
5
|
-
export declare let supportedCache: boolean | null;
|
|
6
|
-
/**
|
|
7
|
-
* Creates a registration token for Firebase Cloud Messaging.
|
|
8
|
-
*
|
|
9
|
-
* @param env - env to configure push notifications
|
|
10
|
-
* @returns A promise that resolves with the registration token or null if an error occurs.
|
|
11
|
-
*/
|
|
12
|
-
export declare function createRegToken(env: PushNotificationEnv): Promise<string | null>;
|
|
13
|
-
/**
|
|
14
|
-
* Deletes the Firebase Cloud Messaging registration token.
|
|
15
|
-
*
|
|
16
|
-
* @param env - env to configure push notifications
|
|
17
|
-
* @returns A promise that resolves with true if the token was successfully deleted, false otherwise.
|
|
18
|
-
*/
|
|
19
|
-
export declare function deleteRegToken(env: PushNotificationEnv): Promise<boolean>;
|
|
20
|
-
/**
|
|
21
|
-
* A creator function that assists creating web-specific push notification subscription:
|
|
22
|
-
* 1. Creates subscriptions for receiving and clicking notifications
|
|
23
|
-
* 2. Creates click events when a notification is clicked
|
|
24
|
-
* 3. Publishes controller messenger events
|
|
25
|
-
*
|
|
26
|
-
* @param props - props for this creator function.
|
|
27
|
-
* @param props.onReceivedHandler - allows the developer to handle showing a notification
|
|
28
|
-
* @param props.onClickHandler - allows the developer to handle clicking the notification
|
|
29
|
-
* @param props.messenger - the controller messenger to publish the `onNewNotifications` and `pushNotificationsClicked` events
|
|
30
|
-
* @returns a function that can be used by the controller
|
|
31
|
-
*/
|
|
32
|
-
export declare function createSubscribeToPushNotifications(props: {
|
|
33
|
-
onReceivedHandler: (notification: Types.INotification) => void | Promise<void>;
|
|
34
|
-
onClickHandler: (e: NotificationEvent, notification: Types.INotification) => void;
|
|
35
|
-
messenger: NotificationServicesPushControllerMessenger;
|
|
36
|
-
}): (env: PushNotificationEnv) => Promise<() => void>;
|
|
37
|
-
//# sourceMappingURL=push-helpers.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push-helpers.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/web/push-helpers.ts"],"names":[],"mappings":";AAcA,OAAO,KAAK,EAAE,KAAK,EAAE,uDAA6C;AAGlE,OAAO,KAAK,EAAE,2CAA2C,EAAE,kDAA8C;AACzG,OAAO,KAAK,EAAE,mBAAmB,EAAE,8BAA0B;AAM7D,eAAO,IAAI,cAAc,EAAE,OAAO,GAAG,IAAW,CAAC;AAsCjD;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,mBAAmB,GACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAexB;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,mBAAmB,GACvB,OAAO,CAAC,OAAO,CAAC,CAYlB;AAqED;;;;;;;;;;;GAWG;AACH,wBAAgB,kCAAkC,CAAC,KAAK,EAAE;IACxD,iBAAiB,EAAE,CACjB,YAAY,EAAE,KAAK,CAAC,aAAa,KAC9B,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,cAAc,EAAE,CACd,CAAC,EAAE,iBAAiB,EACpB,YAAY,EAAE,KAAK,CAAC,aAAa,KAC9B,IAAI,CAAC;IACV,SAAS,EAAE,2CAA2C,CAAC;CACxD,SAC6B,mBAAmB,yBA4BhD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push-helpers.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/web/push-helpers.ts"],"names":[],"mappings":";;;;;;AAIA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,qBAAqB;AACrD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,2BAA2B;AAC3D,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,WAAW,EACZ,8BAA8B;AAE/B,OAAO,IAAG,iBAAiB;;AAG3B,OAAO,EAAE,UAAU,EAAE,uDAA6C;AAClE,OAAO,EAAE,wBAAwB,EAAE,6CAAyC;AAM5E,2BAA2B;AAC3B,uDAAuD;AACvD,MAAM,CAAC,IAAI,cAAc,GAAmB,IAAI,CAAC;AAEjD,MAAM,mBAAmB,GAAG,KAAK,IAAI,EAAE;IACrC,cAAc,KAAd,cAAc,GAAK,MAAM,WAAW,EAAE,EAAC;IACvC,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,KAAK,EAC7B,GAAwB,EACF,EAAE;IACxB,IAAI;QACF,OAAO,MAAM,EAAE,CAAC;KACjB;IAAC,MAAM;QACN,MAAM,cAAc,GAAG;YACrB,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,UAAU,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IAAI,GAAwB,KAAK,EAAE,YAAY,EAAE,IAAI,CAAC;QAC5D,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC,CAAC;IAEF,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;IACzD,MAAM,WAAW,GAAG,GAAG,EAAE,CACvB,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;IAC9D,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kCAAkC,CAAC,KASlD;IACC,OAAO,KAAK,WAAW,GAAwB;QAC7C,MAAM,sBAAsB,GAAG,MAAM,iCAAiC,CACpE,GAAG,EACH,KAAK,EAAE,YAAY,EAAE,EAAE;YACrB,KAAK,CAAC,SAAS,CAAC,OAAO,CACrB,uDAAuD,EACvD,YAAY,CACb,CAAC;YACF,MAAM,KAAK,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;QAC9C,CAAC,CACF,CAAC;QACF,MAAM,UAAU,GAAG,gCAAgC,CACjD,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE;YACtB,KAAK,CAAC,SAAS,CAAC,OAAO,CACrB,4DAA4D,EAC5D,YAAY,CACb,CAAC;YACF,KAAK,CAAC,cAAc,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;QAC5C,CAAC,CACF,CAAC;QAEF,MAAM,WAAW,GAAG,GAAG,EAAE;YACvB,sBAAsB,EAAE,EAAE,CAAC;YAC3B,UAAU,EAAE,CAAC;QACf,CAAC,CAAC;QAEF,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// We are defining that this file uses a webworker global scope.\n// eslint-disable-next-line spaced-comment\n/// <reference lib=\"webworker\" />\nimport type { FirebaseApp } from 'firebase/app';\nimport { getApp, initializeApp } from 'firebase/app';\nimport { getToken, deleteToken } from 'firebase/messaging';\nimport {\n getMessaging,\n onBackgroundMessage,\n isSupported,\n} from 'firebase/messaging/sw';\nimport type { Messaging, MessagePayload } from 'firebase/messaging/sw';\nimport log from 'loglevel';\n\nimport type { Types } from '../../NotificationServicesController';\nimport { Processors } from '../../NotificationServicesController';\nimport { toRawOnChainNotification } from '../../shared/to-raw-notification';\nimport type { NotificationServicesPushControllerMessenger } from '../NotificationServicesPushController';\nimport type { PushNotificationEnv } from '../types/firebase';\n\ndeclare const self: ServiceWorkerGlobalScope;\n\n// Exported to help testing\n// eslint-disable-next-line import-x/no-mutable-exports\nexport let supportedCache: boolean | null = null;\n\nconst getPushAvailability = async () => {\n supportedCache ??= await isSupported();\n return supportedCache;\n};\n\nconst createFirebaseApp = async (\n env: PushNotificationEnv,\n): Promise<FirebaseApp> => {\n try {\n return getApp();\n } catch {\n const firebaseConfig = {\n apiKey: env.apiKey,\n authDomain: env.authDomain,\n storageBucket: env.storageBucket,\n projectId: env.projectId,\n messagingSenderId: env.messagingSenderId,\n appId: env.appId,\n measurementId: env.measurementId,\n };\n return initializeApp(firebaseConfig);\n }\n};\n\nconst getFirebaseMessaging = async (\n env: PushNotificationEnv,\n): Promise<Messaging | null> => {\n const supported = await getPushAvailability();\n if (!supported) {\n return null;\n }\n\n const app = await createFirebaseApp(env);\n return getMessaging(app);\n};\n\n/**\n * Creates a registration token for Firebase Cloud Messaging.\n *\n * @param env - env to configure push notifications\n * @returns A promise that resolves with the registration token or null if an error occurs.\n */\nexport async function createRegToken(\n env: PushNotificationEnv,\n): Promise<string | null> {\n try {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return null;\n }\n\n const token = await getToken(messaging, {\n serviceWorkerRegistration: self.registration,\n vapidKey: env.vapidKey,\n });\n return token;\n } catch {\n return null;\n }\n}\n\n/**\n * Deletes the Firebase Cloud Messaging registration token.\n *\n * @param env - env to configure push notifications\n * @returns A promise that resolves with true if the token was successfully deleted, false otherwise.\n */\nexport async function deleteRegToken(\n env: PushNotificationEnv,\n): Promise<boolean> {\n try {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return true;\n }\n\n await deleteToken(messaging);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Service Worker Listener for when push notifications are received.\n *\n * @param env - push notification environment\n * @param handler - handler to actually showing notification, MUST BE PROVIDED\n * @returns unsubscribe handler\n */\nasync function listenToPushNotificationsReceived(\n env: PushNotificationEnv,\n handler: (notification: Types.INotification) => void | Promise<void>,\n): Promise<(() => void) | null> {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return null;\n }\n\n const unsubscribePushNotifications = onBackgroundMessage(\n messaging,\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (payload: MessagePayload) => {\n try {\n const data: Types.UnprocessedOnChainRawNotification | undefined =\n payload?.data?.data ? JSON.parse(payload?.data?.data) : undefined;\n\n if (!data) {\n return;\n }\n\n const notificationData = toRawOnChainNotification(data);\n const notification = Processors.processNotification(notificationData);\n await handler(notification);\n } catch (error) {\n // Do Nothing, cannot parse a bad notification\n log.error('Unable to send push notification:', {\n notification: payload?.data?.data,\n error,\n });\n throw new Error('Unable to send push notification');\n }\n },\n );\n\n const unsubscribe = () => unsubscribePushNotifications();\n return unsubscribe;\n}\n\n/**\n * Service Worker Listener for when a notification is clicked\n *\n * @param handler - listen to NotificationEvent from the service worker\n * @returns unsubscribe handler\n */\nfunction listenToPushNotificationsClicked(\n handler: (e: NotificationEvent, notification: Types.INotification) => void,\n) {\n const clickHandler = (event: NotificationEvent) => {\n // Get Data\n const data: Types.INotification = event?.notification?.data;\n handler(event, data);\n };\n\n self.addEventListener('notificationclick', clickHandler);\n const unsubscribe = () =>\n self.removeEventListener('notificationclick', clickHandler);\n return unsubscribe;\n}\n\n/**\n * A creator function that assists creating web-specific push notification subscription:\n * 1. Creates subscriptions for receiving and clicking notifications\n * 2. Creates click events when a notification is clicked\n * 3. Publishes controller messenger events\n *\n * @param props - props for this creator function.\n * @param props.onReceivedHandler - allows the developer to handle showing a notification\n * @param props.onClickHandler - allows the developer to handle clicking the notification\n * @param props.messenger - the controller messenger to publish the `onNewNotifications` and `pushNotificationsClicked` events\n * @returns a function that can be used by the controller\n */\nexport function createSubscribeToPushNotifications(props: {\n onReceivedHandler: (\n notification: Types.INotification,\n ) => void | Promise<void>;\n onClickHandler: (\n e: NotificationEvent,\n notification: Types.INotification,\n ) => void;\n messenger: NotificationServicesPushControllerMessenger;\n}) {\n return async function (env: PushNotificationEnv) {\n const onBackgroundMessageSub = await listenToPushNotificationsReceived(\n env,\n async (notification) => {\n props.messenger.publish(\n 'NotificationServicesPushController:onNewNotifications',\n notification,\n );\n await props.onReceivedHandler(notification);\n },\n );\n const onClickSub = listenToPushNotificationsClicked(\n (event, notification) => {\n props.messenger.publish(\n 'NotificationServicesPushController:pushNotificationClicked',\n notification,\n );\n props.onClickHandler(event, notification);\n },\n );\n\n const unsubscribe = () => {\n onBackgroundMessageSub?.();\n onClickSub();\n };\n\n return unsubscribe;\n };\n}\n"]}
|