@metamask/notification-services-controller 0.21.0 → 1.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 +22 -3
- package/dist/NotificationServicesController/NotificationServicesController.cjs +70 -78
- package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.cts +10 -34
- package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.mts +10 -34
- package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.mjs +71 -79
- package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
- package/dist/NotificationServicesController/__fixtures__/mock-notification-user-storage.cjs +1 -1
- package/dist/NotificationServicesController/__fixtures__/mock-notification-user-storage.cjs.map +1 -1
- package/dist/NotificationServicesController/__fixtures__/mock-notification-user-storage.d.cts.map +1 -1
- package/dist/NotificationServicesController/__fixtures__/mock-notification-user-storage.d.mts.map +1 -1
- package/dist/NotificationServicesController/__fixtures__/mock-notification-user-storage.mjs +1 -1
- package/dist/NotificationServicesController/__fixtures__/mock-notification-user-storage.mjs.map +1 -1
- package/dist/NotificationServicesController/__fixtures__/mockAddresses.cjs +6 -0
- package/dist/NotificationServicesController/__fixtures__/mockAddresses.cjs.map +1 -0
- package/dist/NotificationServicesController/__fixtures__/mockAddresses.d.cts +3 -0
- package/dist/NotificationServicesController/__fixtures__/mockAddresses.d.cts.map +1 -0
- package/dist/NotificationServicesController/__fixtures__/mockAddresses.d.mts +3 -0
- package/dist/NotificationServicesController/__fixtures__/mockAddresses.d.mts.map +1 -0
- package/dist/NotificationServicesController/__fixtures__/mockAddresses.mjs +3 -0
- package/dist/NotificationServicesController/__fixtures__/mockAddresses.mjs.map +1 -0
- package/dist/NotificationServicesController/index.cjs +1 -0
- package/dist/NotificationServicesController/index.cjs.map +1 -1
- package/dist/NotificationServicesController/index.d.cts +1 -0
- package/dist/NotificationServicesController/index.d.cts.map +1 -1
- package/dist/NotificationServicesController/index.d.mts +1 -0
- package/dist/NotificationServicesController/index.d.mts.map +1 -1
- package/dist/NotificationServicesController/index.mjs +1 -0
- package/dist/NotificationServicesController/index.mjs.map +1 -1
- package/dist/NotificationServicesController/services/onchain-notifications.cjs +1 -0
- package/dist/NotificationServicesController/services/onchain-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/services/onchain-notifications.d.cts.map +1 -1
- package/dist/NotificationServicesController/services/onchain-notifications.d.mts.map +1 -1
- package/dist/NotificationServicesController/services/onchain-notifications.mjs +2 -1
- package/dist/NotificationServicesController/services/onchain-notifications.mjs.map +1 -1
- package/dist/NotificationServicesController/utils/utils.cjs +28 -2
- package/dist/NotificationServicesController/utils/utils.cjs.map +1 -1
- package/dist/NotificationServicesController/utils/utils.d.cts +11 -1
- package/dist/NotificationServicesController/utils/utils.d.cts.map +1 -1
- package/dist/NotificationServicesController/utils/utils.d.mts +11 -1
- package/dist/NotificationServicesController/utils/utils.d.mts.map +1 -1
- package/dist/NotificationServicesController/utils/utils.mjs +26 -1
- package/dist/NotificationServicesController/utils/utils.mjs.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +97 -57
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +19 -24
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +19 -24
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +98 -58
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.cjs +14 -0
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.cjs.map +1 -0
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.cts +3 -0
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.cts.map +1 -0
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.mts +3 -0
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.mts.map +1 -0
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.mjs +10 -0
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.mjs.map +1 -0
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.cjs +1 -13
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.cjs.map +1 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.d.cts +0 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.d.mts +0 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.mjs +1 -12
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.mjs.map +1 -1
- package/dist/NotificationServicesPushController/services/services.cjs +19 -93
- package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
- package/dist/NotificationServicesPushController/services/services.d.cts +5 -29
- package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/services/services.d.mts +5 -29
- package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/services/services.mjs +18 -94
- package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
- package/dist/NotificationServicesPushController/types/index.cjs.map +1 -1
- package/dist/NotificationServicesPushController/types/index.d.cts +1 -0
- package/dist/NotificationServicesPushController/types/index.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/types/index.d.mts +1 -0
- package/dist/NotificationServicesPushController/types/index.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/types/index.mjs.map +1 -1
- package/dist/NotificationServicesPushController/{services/push/index.cjs → types/push-service-interface.cjs} +1 -1
- package/dist/NotificationServicesPushController/types/push-service-interface.cjs.map +1 -0
- package/dist/NotificationServicesPushController/types/push-service-interface.d.cts +30 -0
- package/dist/NotificationServicesPushController/types/push-service-interface.d.cts.map +1 -0
- package/dist/NotificationServicesPushController/types/push-service-interface.d.mts +30 -0
- package/dist/NotificationServicesPushController/types/push-service-interface.d.mts.map +1 -0
- package/dist/NotificationServicesPushController/types/push-service-interface.mjs +2 -0
- package/dist/NotificationServicesPushController/types/push-service-interface.mjs.map +1 -0
- package/dist/NotificationServicesPushController/utils/get-notification-message.cjs +1 -19
- package/dist/NotificationServicesPushController/utils/get-notification-message.cjs.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts +0 -7
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts +0 -7
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +0 -17
- package/dist/NotificationServicesPushController/utils/get-notification-message.mjs.map +1 -1
- package/dist/NotificationServicesPushController/web/index.cjs +8 -0
- package/dist/NotificationServicesPushController/web/index.cjs.map +1 -0
- package/dist/NotificationServicesPushController/web/index.d.cts +2 -0
- package/dist/NotificationServicesPushController/web/index.d.cts.map +1 -0
- package/dist/NotificationServicesPushController/web/index.d.mts +2 -0
- package/dist/NotificationServicesPushController/web/index.d.mts.map +1 -0
- package/dist/NotificationServicesPushController/web/index.mjs +2 -0
- package/dist/NotificationServicesPushController/web/index.mjs.map +1 -0
- package/dist/NotificationServicesPushController/web/push-utils.cjs +170 -0
- package/dist/NotificationServicesPushController/web/push-utils.cjs.map +1 -0
- package/dist/NotificationServicesPushController/web/push-utils.d.cts +37 -0
- package/dist/NotificationServicesPushController/web/push-utils.d.cts.map +1 -0
- package/dist/NotificationServicesPushController/web/push-utils.d.mts +37 -0
- package/dist/NotificationServicesPushController/web/push-utils.d.mts.map +1 -0
- package/dist/NotificationServicesPushController/web/push-utils.mjs +168 -0
- package/dist/NotificationServicesPushController/web/push-utils.mjs.map +1 -0
- package/dist/shared/index.cjs +19 -0
- package/dist/shared/index.cjs.map +1 -0
- package/dist/shared/index.d.cts +3 -0
- package/dist/shared/index.d.cts.map +1 -0
- package/dist/shared/index.d.mts +3 -0
- package/dist/shared/index.d.mts.map +1 -0
- package/dist/shared/index.mjs +3 -0
- package/dist/shared/index.mjs.map +1 -0
- package/dist/shared/is-onchain-notification.cjs +22 -0
- package/dist/shared/is-onchain-notification.cjs.map +1 -0
- package/dist/shared/is-onchain-notification.d.cts +9 -0
- package/dist/shared/is-onchain-notification.d.cts.map +1 -0
- package/dist/shared/is-onchain-notification.d.mts +9 -0
- package/dist/shared/is-onchain-notification.d.mts.map +1 -0
- package/dist/shared/is-onchain-notification.mjs +18 -0
- package/dist/shared/is-onchain-notification.mjs.map +1 -0
- package/package.json +14 -4
- package/push-services/web/package.json +9 -0
- package/dist/NotificationServicesPushController/constants.cjs +0 -14
- package/dist/NotificationServicesPushController/constants.cjs.map +0 -1
- package/dist/NotificationServicesPushController/constants.d.cts +0 -11
- package/dist/NotificationServicesPushController/constants.d.cts.map +0 -1
- package/dist/NotificationServicesPushController/constants.d.mts +0 -11
- package/dist/NotificationServicesPushController/constants.d.mts.map +0 -1
- package/dist/NotificationServicesPushController/constants.mjs +0 -11
- package/dist/NotificationServicesPushController/constants.mjs.map +0 -1
- package/dist/NotificationServicesPushController/services/push/index.cjs.map +0 -1
- package/dist/NotificationServicesPushController/services/push/index.d.cts +0 -6
- package/dist/NotificationServicesPushController/services/push/index.d.cts.map +0 -1
- package/dist/NotificationServicesPushController/services/push/index.d.mts +0 -6
- package/dist/NotificationServicesPushController/services/push/index.d.mts.map +0 -1
- package/dist/NotificationServicesPushController/services/push/index.mjs +0 -2
- package/dist/NotificationServicesPushController/services/push/index.mjs.map +0 -1
|
@@ -0,0 +1,37 @@
|
|
|
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-utils.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-utils.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/web/push-utils.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"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
function $importDefault(module) {
|
|
2
|
+
if (module?.__esModule) {
|
|
3
|
+
return module.default;
|
|
4
|
+
}
|
|
5
|
+
return module;
|
|
6
|
+
}
|
|
7
|
+
import { getApp, initializeApp } from "firebase/app";
|
|
8
|
+
import { getToken, deleteToken } from "firebase/messaging";
|
|
9
|
+
import { getMessaging, onBackgroundMessage, isSupported } from "firebase/messaging/sw";
|
|
10
|
+
import $log from "loglevel";
|
|
11
|
+
const log = $importDefault($log);
|
|
12
|
+
import { Processors } from "../../NotificationServicesController/index.mjs";
|
|
13
|
+
import { toRawOnChainNotification } from "../../shared/to-raw-notification.mjs";
|
|
14
|
+
// Exported to help testing
|
|
15
|
+
// eslint-disable-next-line import-x/no-mutable-exports
|
|
16
|
+
export let supportedCache = null;
|
|
17
|
+
const getPushAvailability = async () => {
|
|
18
|
+
supportedCache ?? (supportedCache = await isSupported());
|
|
19
|
+
return supportedCache;
|
|
20
|
+
};
|
|
21
|
+
const createFirebaseApp = async (env) => {
|
|
22
|
+
try {
|
|
23
|
+
return getApp();
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
const firebaseConfig = {
|
|
27
|
+
apiKey: env.apiKey,
|
|
28
|
+
authDomain: env.authDomain,
|
|
29
|
+
storageBucket: env.storageBucket,
|
|
30
|
+
projectId: env.projectId,
|
|
31
|
+
messagingSenderId: env.messagingSenderId,
|
|
32
|
+
appId: env.appId,
|
|
33
|
+
measurementId: env.measurementId,
|
|
34
|
+
};
|
|
35
|
+
return initializeApp(firebaseConfig);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const getFirebaseMessaging = async (env) => {
|
|
39
|
+
const supported = await getPushAvailability();
|
|
40
|
+
if (!supported) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const app = await createFirebaseApp(env);
|
|
44
|
+
return getMessaging(app);
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Creates a registration token for Firebase Cloud Messaging.
|
|
48
|
+
*
|
|
49
|
+
* @param env - env to configure push notifications
|
|
50
|
+
* @returns A promise that resolves with the registration token or null if an error occurs.
|
|
51
|
+
*/
|
|
52
|
+
export async function createRegToken(env) {
|
|
53
|
+
try {
|
|
54
|
+
const messaging = await getFirebaseMessaging(env);
|
|
55
|
+
if (!messaging) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const token = await getToken(messaging, {
|
|
59
|
+
serviceWorkerRegistration: self.registration,
|
|
60
|
+
vapidKey: env.vapidKey,
|
|
61
|
+
});
|
|
62
|
+
return token;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Deletes the Firebase Cloud Messaging registration token.
|
|
70
|
+
*
|
|
71
|
+
* @param env - env to configure push notifications
|
|
72
|
+
* @returns A promise that resolves with true if the token was successfully deleted, false otherwise.
|
|
73
|
+
*/
|
|
74
|
+
export async function deleteRegToken(env) {
|
|
75
|
+
try {
|
|
76
|
+
const messaging = await getFirebaseMessaging(env);
|
|
77
|
+
if (!messaging) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
await deleteToken(messaging);
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Service Worker Listener for when push notifications are received.
|
|
89
|
+
*
|
|
90
|
+
* @param env - push notification environment
|
|
91
|
+
* @param handler - handler to actually showing notification, MUST BE PROVIDED
|
|
92
|
+
* @returns unsubscribe handler
|
|
93
|
+
*/
|
|
94
|
+
async function listenToPushNotificationsReceived(env, handler) {
|
|
95
|
+
const messaging = await getFirebaseMessaging(env);
|
|
96
|
+
if (!messaging) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const unsubscribePushNotifications = onBackgroundMessage(messaging,
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
101
|
+
async (payload) => {
|
|
102
|
+
try {
|
|
103
|
+
const data = payload?.data?.data ? JSON.parse(payload?.data?.data) : undefined;
|
|
104
|
+
if (!data) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const notificationData = toRawOnChainNotification(data);
|
|
108
|
+
const notification = Processors.processNotification(notificationData);
|
|
109
|
+
await handler(notification);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
// Do Nothing, cannot parse a bad notification
|
|
113
|
+
log.error('Unable to send push notification:', {
|
|
114
|
+
notification: payload?.data?.data,
|
|
115
|
+
error,
|
|
116
|
+
});
|
|
117
|
+
throw new Error('Unable to send push notification');
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
const unsubscribe = () => unsubscribePushNotifications();
|
|
121
|
+
return unsubscribe;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Service Worker Listener for when a notification is clicked
|
|
125
|
+
*
|
|
126
|
+
* @param handler - listen to NotificationEvent from the service worker
|
|
127
|
+
* @returns unsubscribe handler
|
|
128
|
+
*/
|
|
129
|
+
function listenToPushNotificationsClicked(handler) {
|
|
130
|
+
const clickHandler = (event) => {
|
|
131
|
+
// Get Data
|
|
132
|
+
const data = event?.notification?.data;
|
|
133
|
+
handler(event, data);
|
|
134
|
+
};
|
|
135
|
+
self.addEventListener('notificationclick', clickHandler);
|
|
136
|
+
const unsubscribe = () => self.removeEventListener('notificationclick', clickHandler);
|
|
137
|
+
return unsubscribe;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* A creator function that assists creating web-specific push notification subscription:
|
|
141
|
+
* 1. Creates subscriptions for receiving and clicking notifications
|
|
142
|
+
* 2. Creates click events when a notification is clicked
|
|
143
|
+
* 3. Publishes controller messenger events
|
|
144
|
+
*
|
|
145
|
+
* @param props - props for this creator function.
|
|
146
|
+
* @param props.onReceivedHandler - allows the developer to handle showing a notification
|
|
147
|
+
* @param props.onClickHandler - allows the developer to handle clicking the notification
|
|
148
|
+
* @param props.messenger - the controller messenger to publish the `onNewNotifications` and `pushNotificationsClicked` events
|
|
149
|
+
* @returns a function that can be used by the controller
|
|
150
|
+
*/
|
|
151
|
+
export function createSubscribeToPushNotifications(props) {
|
|
152
|
+
return async function (env) {
|
|
153
|
+
const onBackgroundMessageSub = await listenToPushNotificationsReceived(env, async (notification) => {
|
|
154
|
+
props.messenger.publish('NotificationServicesPushController:onNewNotifications', notification);
|
|
155
|
+
await props.onReceivedHandler(notification);
|
|
156
|
+
});
|
|
157
|
+
const onClickSub = listenToPushNotificationsClicked((event, notification) => {
|
|
158
|
+
props.messenger.publish('NotificationServicesPushController:pushNotificationClicked', notification);
|
|
159
|
+
props.onClickHandler(event, notification);
|
|
160
|
+
});
|
|
161
|
+
const unsubscribe = () => {
|
|
162
|
+
onBackgroundMessageSub?.();
|
|
163
|
+
onClickSub();
|
|
164
|
+
};
|
|
165
|
+
return unsubscribe;
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=push-utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-utils.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/web/push-utils.ts"],"names":[],"mappings":"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","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"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./is-onchain-notification.cjs"), exports);
|
|
18
|
+
__exportStar(require("./to-raw-notification.cjs"), exports);
|
|
19
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA0C;AAC1C,4DAAsC","sourcesContent":["export * from './is-onchain-notification';\nexport * from './to-raw-notification';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,8CAA0C;AAC1C,0CAAsC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,8CAA0C;AAC1C,0CAAsC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,8CAA0C;AAC1C,0CAAsC","sourcesContent":["export * from './is-onchain-notification';\nexport * from './to-raw-notification';\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isOnChainRawNotification = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Checks if the given value is an OnChainRawNotification object.
|
|
6
|
+
*
|
|
7
|
+
* @param n - The value to check.
|
|
8
|
+
* @returns True if the value is an OnChainRawNotification object, false otherwise.
|
|
9
|
+
*/
|
|
10
|
+
function isOnChainRawNotification(n) {
|
|
11
|
+
const assumed = n;
|
|
12
|
+
// We don't have a validation/parsing library to check all possible types of an on chain notification
|
|
13
|
+
// It is safe enough just to check "some" fields, and catch any errors down the line if the shape is bad.
|
|
14
|
+
const isValidEnoughToBeOnChainNotification = [
|
|
15
|
+
assumed?.id,
|
|
16
|
+
assumed?.data,
|
|
17
|
+
assumed?.trigger_id,
|
|
18
|
+
].every((field) => field !== undefined);
|
|
19
|
+
return isValidEnoughToBeOnChainNotification;
|
|
20
|
+
}
|
|
21
|
+
exports.isOnChainRawNotification = isOnChainRawNotification;
|
|
22
|
+
//# sourceMappingURL=is-onchain-notification.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-onchain-notification.cjs","sourceRoot":"","sources":["../../src/shared/is-onchain-notification.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AACH,SAAgB,wBAAwB,CACtC,CAAU;IAEV,MAAM,OAAO,GAAG,CAA2B,CAAC;IAE5C,qGAAqG;IACrG,yGAAyG;IACzG,MAAM,oCAAoC,GAAG;QAC3C,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,UAAU;KACpB,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC;IACxC,OAAO,oCAAoC,CAAC;AAC9C,CAAC;AAbD,4DAaC","sourcesContent":["import type { OnChainRawNotification } from '../NotificationServicesController';\n\n/**\n * Checks if the given value is an OnChainRawNotification object.\n *\n * @param n - The value to check.\n * @returns True if the value is an OnChainRawNotification object, false otherwise.\n */\nexport function isOnChainRawNotification(\n n: unknown,\n): n is OnChainRawNotification {\n const assumed = n as OnChainRawNotification;\n\n // We don't have a validation/parsing library to check all possible types of an on chain notification\n // It is safe enough just to check \"some\" fields, and catch any errors down the line if the shape is bad.\n const isValidEnoughToBeOnChainNotification = [\n assumed?.id,\n assumed?.data,\n assumed?.trigger_id,\n ].every((field) => field !== undefined);\n return isValidEnoughToBeOnChainNotification;\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { OnChainRawNotification } from "../NotificationServicesController/index.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the given value is an OnChainRawNotification object.
|
|
4
|
+
*
|
|
5
|
+
* @param n - The value to check.
|
|
6
|
+
* @returns True if the value is an OnChainRawNotification object, false otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isOnChainRawNotification(n: unknown): n is OnChainRawNotification;
|
|
9
|
+
//# sourceMappingURL=is-onchain-notification.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-onchain-notification.d.cts","sourceRoot":"","sources":["../../src/shared/is-onchain-notification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,oDAA0C;AAEhF;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,CAAC,EAAE,OAAO,GACT,CAAC,IAAI,sBAAsB,CAW7B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { OnChainRawNotification } from "../NotificationServicesController/index.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the given value is an OnChainRawNotification object.
|
|
4
|
+
*
|
|
5
|
+
* @param n - The value to check.
|
|
6
|
+
* @returns True if the value is an OnChainRawNotification object, false otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isOnChainRawNotification(n: unknown): n is OnChainRawNotification;
|
|
9
|
+
//# sourceMappingURL=is-onchain-notification.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-onchain-notification.d.mts","sourceRoot":"","sources":["../../src/shared/is-onchain-notification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,oDAA0C;AAEhF;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,CAAC,EAAE,OAAO,GACT,CAAC,IAAI,sBAAsB,CAW7B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the given value is an OnChainRawNotification object.
|
|
3
|
+
*
|
|
4
|
+
* @param n - The value to check.
|
|
5
|
+
* @returns True if the value is an OnChainRawNotification object, false otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export function isOnChainRawNotification(n) {
|
|
8
|
+
const assumed = n;
|
|
9
|
+
// We don't have a validation/parsing library to check all possible types of an on chain notification
|
|
10
|
+
// It is safe enough just to check "some" fields, and catch any errors down the line if the shape is bad.
|
|
11
|
+
const isValidEnoughToBeOnChainNotification = [
|
|
12
|
+
assumed?.id,
|
|
13
|
+
assumed?.data,
|
|
14
|
+
assumed?.trigger_id,
|
|
15
|
+
].every((field) => field !== undefined);
|
|
16
|
+
return isValidEnoughToBeOnChainNotification;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=is-onchain-notification.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-onchain-notification.mjs","sourceRoot":"","sources":["../../src/shared/is-onchain-notification.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CACtC,CAAU;IAEV,MAAM,OAAO,GAAG,CAA2B,CAAC;IAE5C,qGAAqG;IACrG,yGAAyG;IACzG,MAAM,oCAAoC,GAAG;QAC3C,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,UAAU;KACpB,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC;IACxC,OAAO,oCAAoC,CAAC;AAC9C,CAAC","sourcesContent":["import type { OnChainRawNotification } from '../NotificationServicesController';\n\n/**\n * Checks if the given value is an OnChainRawNotification object.\n *\n * @param n - The value to check.\n * @returns True if the value is an OnChainRawNotification object, false otherwise.\n */\nexport function isOnChainRawNotification(\n n: unknown,\n): n is OnChainRawNotification {\n const assumed = n as OnChainRawNotification;\n\n // We don't have a validation/parsing library to check all possible types of an on chain notification\n // It is safe enough just to check \"some\" fields, and catch any errors down the line if the shape is bad.\n const isValidEnoughToBeOnChainNotification = [\n assumed?.id,\n assumed?.data,\n assumed?.trigger_id,\n ].every((field) => field !== undefined);\n return isValidEnoughToBeOnChainNotification;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/notification-services-controller",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Manages New MetaMask decentralized Notification system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -67,6 +67,16 @@
|
|
|
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
|
+
},
|
|
70
80
|
"./push-services/mocks": {
|
|
71
81
|
"import": {
|
|
72
82
|
"types": "./dist/NotificationServicesPushController/__fixtures__/index.d.mts",
|
|
@@ -102,7 +112,7 @@
|
|
|
102
112
|
"@contentful/rich-text-html-renderer": "^16.5.2",
|
|
103
113
|
"@metamask/base-controller": "^8.0.0",
|
|
104
114
|
"@metamask/controller-utils": "^11.5.0",
|
|
105
|
-
"@metamask/utils": "^11.
|
|
115
|
+
"@metamask/utils": "^11.2.0",
|
|
106
116
|
"bignumber.js": "^9.1.2",
|
|
107
117
|
"firebase": "^11.2.0",
|
|
108
118
|
"loglevel": "^1.8.1",
|
|
@@ -112,8 +122,8 @@
|
|
|
112
122
|
"@lavamoat/allow-scripts": "^3.0.4",
|
|
113
123
|
"@lavamoat/preinstall-always-fail": "^2.1.0",
|
|
114
124
|
"@metamask/auto-changelog": "^3.4.4",
|
|
115
|
-
"@metamask/keyring-controller": "^19.1
|
|
116
|
-
"@metamask/profile-sync-controller": "^8.
|
|
125
|
+
"@metamask/keyring-controller": "^19.2.1",
|
|
126
|
+
"@metamask/profile-sync-controller": "^8.1.1",
|
|
117
127
|
"@types/jest": "^27.4.1",
|
|
118
128
|
"@types/readable-stream": "^2.3.0",
|
|
119
129
|
"contentful": "^10.15.0",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VAPID_KEY = exports.FIREBASE_MEASUREMENT_ID = exports.FIREBASE_APP_ID = exports.FIREBASE_MESSAGING_SENDER_ID = exports.FIREBASE_PROJECT_ID = exports.FIREBASE_STORAGE_BUCKET = exports.FIREBASE_AUTH_DOMAIN = exports.FIREBASE_API_KEY = exports.PUSH_NOTIFICATIONS_SERVICE_URL = exports.ENABLE_MV3 = void 0;
|
|
4
|
-
exports.ENABLE_MV3 = true;
|
|
5
|
-
exports.PUSH_NOTIFICATIONS_SERVICE_URL = 'https://push.api.cx.metamask.io';
|
|
6
|
-
exports.FIREBASE_API_KEY = '';
|
|
7
|
-
exports.FIREBASE_AUTH_DOMAIN = '';
|
|
8
|
-
exports.FIREBASE_STORAGE_BUCKET = '';
|
|
9
|
-
exports.FIREBASE_PROJECT_ID = '';
|
|
10
|
-
exports.FIREBASE_MESSAGING_SENDER_ID = '';
|
|
11
|
-
exports.FIREBASE_APP_ID = '';
|
|
12
|
-
exports.FIREBASE_MEASUREMENT_ID = '';
|
|
13
|
-
exports.VAPID_KEY = '';
|
|
14
|
-
//# sourceMappingURL=constants.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG,IAAI,CAAC;AAClB,QAAA,8BAA8B,GAAG,iCAAiC,CAAC;AAEnE,QAAA,gBAAgB,GAAG,EAAE,CAAC;AACtB,QAAA,oBAAoB,GAAG,EAAE,CAAC;AAC1B,QAAA,uBAAuB,GAAG,EAAE,CAAC;AAC7B,QAAA,mBAAmB,GAAG,EAAE,CAAC;AACzB,QAAA,4BAA4B,GAAG,EAAE,CAAC;AAClC,QAAA,eAAe,GAAG,EAAE,CAAC;AACrB,QAAA,uBAAuB,GAAG,EAAE,CAAC;AAC7B,QAAA,SAAS,GAAG,EAAE,CAAC","sourcesContent":["export const ENABLE_MV3 = true;\nexport const PUSH_NOTIFICATIONS_SERVICE_URL = 'https://push.api.cx.metamask.io';\n\nexport const FIREBASE_API_KEY = '';\nexport const FIREBASE_AUTH_DOMAIN = '';\nexport const FIREBASE_STORAGE_BUCKET = '';\nexport const FIREBASE_PROJECT_ID = '';\nexport const FIREBASE_MESSAGING_SENDER_ID = '';\nexport const FIREBASE_APP_ID = '';\nexport const FIREBASE_MEASUREMENT_ID = '';\nexport const VAPID_KEY = '';\n"]}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare const ENABLE_MV3 = true;
|
|
2
|
-
export declare const PUSH_NOTIFICATIONS_SERVICE_URL = "https://push.api.cx.metamask.io";
|
|
3
|
-
export declare const FIREBASE_API_KEY = "";
|
|
4
|
-
export declare const FIREBASE_AUTH_DOMAIN = "";
|
|
5
|
-
export declare const FIREBASE_STORAGE_BUCKET = "";
|
|
6
|
-
export declare const FIREBASE_PROJECT_ID = "";
|
|
7
|
-
export declare const FIREBASE_MESSAGING_SENDER_ID = "";
|
|
8
|
-
export declare const FIREBASE_APP_ID = "";
|
|
9
|
-
export declare const FIREBASE_MEASUREMENT_ID = "";
|
|
10
|
-
export declare const VAPID_KEY = "";
|
|
11
|
-
//# sourceMappingURL=constants.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,OAAO,CAAC;AAC/B,eAAO,MAAM,8BAA8B,oCAAoC,CAAC;AAEhF,eAAO,MAAM,gBAAgB,KAAK,CAAC;AACnC,eAAO,MAAM,oBAAoB,KAAK,CAAC;AACvC,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,eAAO,MAAM,mBAAmB,KAAK,CAAC;AACtC,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAC/C,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,eAAO,MAAM,SAAS,KAAK,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare const ENABLE_MV3 = true;
|
|
2
|
-
export declare const PUSH_NOTIFICATIONS_SERVICE_URL = "https://push.api.cx.metamask.io";
|
|
3
|
-
export declare const FIREBASE_API_KEY = "";
|
|
4
|
-
export declare const FIREBASE_AUTH_DOMAIN = "";
|
|
5
|
-
export declare const FIREBASE_STORAGE_BUCKET = "";
|
|
6
|
-
export declare const FIREBASE_PROJECT_ID = "";
|
|
7
|
-
export declare const FIREBASE_MESSAGING_SENDER_ID = "";
|
|
8
|
-
export declare const FIREBASE_APP_ID = "";
|
|
9
|
-
export declare const FIREBASE_MEASUREMENT_ID = "";
|
|
10
|
-
export declare const VAPID_KEY = "";
|
|
11
|
-
//# sourceMappingURL=constants.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,OAAO,CAAC;AAC/B,eAAO,MAAM,8BAA8B,oCAAoC,CAAC;AAEhF,eAAO,MAAM,gBAAgB,KAAK,CAAC;AACnC,eAAO,MAAM,oBAAoB,KAAK,CAAC;AACvC,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,eAAO,MAAM,mBAAmB,KAAK,CAAC;AACtC,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAC/C,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,eAAO,MAAM,SAAS,KAAK,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const ENABLE_MV3 = true;
|
|
2
|
-
export const PUSH_NOTIFICATIONS_SERVICE_URL = 'https://push.api.cx.metamask.io';
|
|
3
|
-
export const FIREBASE_API_KEY = '';
|
|
4
|
-
export const FIREBASE_AUTH_DOMAIN = '';
|
|
5
|
-
export const FIREBASE_STORAGE_BUCKET = '';
|
|
6
|
-
export const FIREBASE_PROJECT_ID = '';
|
|
7
|
-
export const FIREBASE_MESSAGING_SENDER_ID = '';
|
|
8
|
-
export const FIREBASE_APP_ID = '';
|
|
9
|
-
export const FIREBASE_MEASUREMENT_ID = '';
|
|
10
|
-
export const VAPID_KEY = '';
|
|
11
|
-
//# sourceMappingURL=constants.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC;AAC/B,MAAM,CAAC,MAAM,8BAA8B,GAAG,iCAAiC,CAAC;AAEhF,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AACnC,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AACvC,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAC1C,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AACtC,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,CAAC;AAC/C,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAClC,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAC1C,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC","sourcesContent":["export const ENABLE_MV3 = true;\nexport const PUSH_NOTIFICATIONS_SERVICE_URL = 'https://push.api.cx.metamask.io';\n\nexport const FIREBASE_API_KEY = '';\nexport const FIREBASE_AUTH_DOMAIN = '';\nexport const FIREBASE_STORAGE_BUCKET = '';\nexport const FIREBASE_PROJECT_ID = '';\nexport const FIREBASE_MESSAGING_SENDER_ID = '';\nexport const FIREBASE_APP_ID = '';\nexport const FIREBASE_MEASUREMENT_ID = '';\nexport const VAPID_KEY = '';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../../src/NotificationServicesPushController/services/push/index.ts"],"names":[],"mappings":"","sourcesContent":["import type * as Web from './push-web';\n\nexport type CreateRegToken = typeof Web.createRegToken;\nexport type DeleteRegToken = typeof Web.deleteRegToken;\nexport type ListenToPushNotificationsReceived =\n typeof Web.listenToPushNotificationsReceived;\nexport type ListenToPushNotificationsClicked =\n typeof Web.listenToPushNotificationsClicked;\n"]}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type * as Web from "./push-web.cjs";
|
|
2
|
-
export type CreateRegToken = typeof Web.createRegToken;
|
|
3
|
-
export type DeleteRegToken = typeof Web.deleteRegToken;
|
|
4
|
-
export type ListenToPushNotificationsReceived = typeof Web.listenToPushNotificationsReceived;
|
|
5
|
-
export type ListenToPushNotificationsClicked = typeof Web.listenToPushNotificationsClicked;
|
|
6
|
-
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../../src/NotificationServicesPushController/services/push/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,uBAAmB;AAEvC,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,CAAC,cAAc,CAAC;AACvD,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,CAAC,cAAc,CAAC;AACvD,MAAM,MAAM,iCAAiC,GAC3C,OAAO,GAAG,CAAC,iCAAiC,CAAC;AAC/C,MAAM,MAAM,gCAAgC,GAC1C,OAAO,GAAG,CAAC,gCAAgC,CAAC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type * as Web from "./push-web.mjs";
|
|
2
|
-
export type CreateRegToken = typeof Web.createRegToken;
|
|
3
|
-
export type DeleteRegToken = typeof Web.deleteRegToken;
|
|
4
|
-
export type ListenToPushNotificationsReceived = typeof Web.listenToPushNotificationsReceived;
|
|
5
|
-
export type ListenToPushNotificationsClicked = typeof Web.listenToPushNotificationsClicked;
|
|
6
|
-
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../../src/NotificationServicesPushController/services/push/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,uBAAmB;AAEvC,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,CAAC,cAAc,CAAC;AACvD,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,CAAC,cAAc,CAAC;AACvD,MAAM,MAAM,iCAAiC,GAC3C,OAAO,GAAG,CAAC,iCAAiC,CAAC;AAC/C,MAAM,MAAM,gCAAgC,GAC1C,OAAO,GAAG,CAAC,gCAAgC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../src/NotificationServicesPushController/services/push/index.ts"],"names":[],"mappings":"","sourcesContent":["import type * as Web from './push-web';\n\nexport type CreateRegToken = typeof Web.createRegToken;\nexport type DeleteRegToken = typeof Web.deleteRegToken;\nexport type ListenToPushNotificationsReceived =\n typeof Web.listenToPushNotificationsReceived;\nexport type ListenToPushNotificationsClicked =\n typeof Web.listenToPushNotificationsClicked;\n"]}
|