@metamask/notification-services-controller 22.0.0 → 23.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/CHANGELOG.md +43 -1
  2. package/dist/NotificationServicesController/NotificationServicesController-method-action-types.cjs +7 -0
  3. package/dist/NotificationServicesController/NotificationServicesController-method-action-types.cjs.map +1 -0
  4. package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.cts +198 -0
  5. package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.cts.map +1 -0
  6. package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.mts +198 -0
  7. package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.mts.map +1 -0
  8. package/dist/NotificationServicesController/NotificationServicesController-method-action-types.mjs +6 -0
  9. package/dist/NotificationServicesController/NotificationServicesController-method-action-types.mjs.map +1 -0
  10. package/dist/NotificationServicesController/NotificationServicesController.cjs +55 -19
  11. package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
  12. package/dist/NotificationServicesController/NotificationServicesController.d.cts +7 -20
  13. package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
  14. package/dist/NotificationServicesController/NotificationServicesController.d.mts +7 -20
  15. package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
  16. package/dist/NotificationServicesController/NotificationServicesController.mjs +55 -19
  17. package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
  18. package/dist/NotificationServicesController/index.cjs +3 -7
  19. package/dist/NotificationServicesController/index.cjs.map +1 -1
  20. package/dist/NotificationServicesController/index.d.cts +3 -3
  21. package/dist/NotificationServicesController/index.d.cts.map +1 -1
  22. package/dist/NotificationServicesController/index.d.mts +3 -3
  23. package/dist/NotificationServicesController/index.d.mts.map +1 -1
  24. package/dist/NotificationServicesController/index.mjs +2 -3
  25. package/dist/NotificationServicesController/index.mjs.map +1 -1
  26. package/dist/NotificationServicesController/mocks/mock-feature-announcements.cjs +2 -2
  27. package/dist/NotificationServicesController/mocks/mock-feature-announcements.cjs.map +1 -1
  28. package/dist/NotificationServicesController/mocks/mock-feature-announcements.d.cts.map +1 -1
  29. package/dist/NotificationServicesController/mocks/mock-feature-announcements.d.mts.map +1 -1
  30. package/dist/NotificationServicesController/mocks/mock-feature-announcements.mjs +2 -2
  31. package/dist/NotificationServicesController/mocks/mock-feature-announcements.mjs.map +1 -1
  32. package/dist/NotificationServicesController/services/feature-announcements.cjs +10 -1
  33. package/dist/NotificationServicesController/services/feature-announcements.cjs.map +1 -1
  34. package/dist/NotificationServicesController/services/feature-announcements.d.cts.map +1 -1
  35. package/dist/NotificationServicesController/services/feature-announcements.d.mts.map +1 -1
  36. package/dist/NotificationServicesController/services/feature-announcements.mjs +10 -1
  37. package/dist/NotificationServicesController/services/feature-announcements.mjs.map +1 -1
  38. package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.cjs +7 -0
  39. package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.cjs.map +1 -0
  40. package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.d.cts +60 -0
  41. package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.d.cts.map +1 -0
  42. package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.d.mts +60 -0
  43. package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.d.mts.map +1 -0
  44. package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.mjs +6 -0
  45. package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.mjs.map +1 -0
  46. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +40 -10
  47. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
  48. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +13 -19
  49. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
  50. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +13 -19
  51. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
  52. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +40 -11
  53. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
  54. package/dist/NotificationServicesPushController/index.cjs +3 -7
  55. package/dist/NotificationServicesPushController/index.cjs.map +1 -1
  56. package/dist/NotificationServicesPushController/index.d.cts +3 -3
  57. package/dist/NotificationServicesPushController/index.d.cts.map +1 -1
  58. package/dist/NotificationServicesPushController/index.d.mts +3 -3
  59. package/dist/NotificationServicesPushController/index.d.mts.map +1 -1
  60. package/dist/NotificationServicesPushController/index.mjs +2 -3
  61. package/dist/NotificationServicesPushController/index.mjs.map +1 -1
  62. package/dist/NotificationServicesPushController/mocks/mockResponse.cjs +9 -1
  63. package/dist/NotificationServicesPushController/mocks/mockResponse.cjs.map +1 -1
  64. package/dist/NotificationServicesPushController/mocks/mockResponse.d.cts +2 -1
  65. package/dist/NotificationServicesPushController/mocks/mockResponse.d.cts.map +1 -1
  66. package/dist/NotificationServicesPushController/mocks/mockResponse.d.mts +2 -1
  67. package/dist/NotificationServicesPushController/mocks/mockResponse.d.mts.map +1 -1
  68. package/dist/NotificationServicesPushController/mocks/mockResponse.mjs +7 -0
  69. package/dist/NotificationServicesPushController/mocks/mockResponse.mjs.map +1 -1
  70. package/dist/NotificationServicesPushController/services/services.cjs +31 -1
  71. package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
  72. package/dist/NotificationServicesPushController/services/services.d.cts +22 -0
  73. package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
  74. package/dist/NotificationServicesPushController/services/services.d.mts +22 -0
  75. package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
  76. package/dist/NotificationServicesPushController/services/services.mjs +29 -0
  77. package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
  78. package/package.json +14 -9
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,iDAA6C;AAE9D,QAAA,MAAM,kCAAkC,mBAAa,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,kCAAkC,CAAC;AAClD,yDAAqD;AACrD,YAAY,KAAK,KAAK,0BAAgB;AACtC,uCAA6B;AAC7B,OAAO,KAAK,KAAK,0BAAgB;AACjC,kCAAwB;AACxB,OAAO,KAAK,KAAK,0BAAgB"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kCAAkC,EAAE,iDAA6C;AAE1F,OAAO,EAAE,kCAAkC,IAAI,UAAU,EAAE,CAAC;AAC5D,eAAe,kCAAkC,CAAC;AAClD,yDAAqD;AACrD,YAAY,KAAK,KAAK,0BAAgB;AACtC,uCAA6B;AAC7B,OAAO,KAAK,KAAK,0BAAgB;AACjC,kCAAwB;AACxB,OAAO,KAAK,KAAK,0BAAgB;AAEjC,YAAY,EACV,oEAAoE,EACpE,+DAA+D,EAC/D,gEAAgE,EAChE,sEAAsE,EACtE,mEAAmE,EACnE,+CAA+C,GAChD,qEAAiE"}
@@ -1,6 +1,5 @@
1
- import Controller from "./NotificationServicesPushController.mjs";
2
- const NotificationServicesPushController = Controller;
3
- export { Controller };
1
+ import { NotificationServicesPushController } from "./NotificationServicesPushController.mjs";
2
+ export { NotificationServicesPushController as Controller };
4
3
  export default NotificationServicesPushController;
5
4
  export * from "./NotificationServicesPushController.mjs";
6
5
  export * as Utils from "./utils/index.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,iDAA6C;AAE9D,MAAM,kCAAkC,GAAG,UAAU,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,kCAAkC,CAAC;AAClD,yDAAqD;AAGrD,OAAO,KAAK,KAAK,0BAAgB;AACjC,kCAAwB;AACxB,OAAO,KAAK,KAAK,0BAAgB","sourcesContent":["import Controller from './NotificationServicesPushController';\n\nconst NotificationServicesPushController = Controller;\nexport { Controller };\nexport default NotificationServicesPushController;\nexport * from './NotificationServicesPushController';\nexport type * as Types from './types';\nexport type * from './types';\nexport * as Utils from './utils';\nexport * from './utils';\nexport * as Mocks from './mocks';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kCAAkC,EAAE,iDAA6C;AAE1F,OAAO,EAAE,kCAAkC,IAAI,UAAU,EAAE,CAAC;AAC5D,eAAe,kCAAkC,CAAC;AAClD,yDAAqD;AAGrD,OAAO,KAAK,KAAK,0BAAgB;AACjC,kCAAwB;AACxB,OAAO,KAAK,KAAK,0BAAgB","sourcesContent":["import { NotificationServicesPushController } from './NotificationServicesPushController';\n\nexport { NotificationServicesPushController as Controller };\nexport default NotificationServicesPushController;\nexport * from './NotificationServicesPushController';\nexport type * as Types from './types';\nexport type * from './types';\nexport * as Utils from './utils';\nexport * from './utils';\nexport * as Mocks from './mocks';\n\nexport type {\n NotificationServicesPushControllerSubscribeToPushNotificationsAction,\n NotificationServicesPushControllerEnablePushNotificationsAction,\n NotificationServicesPushControllerDisablePushNotificationsAction,\n NotificationServicesPushControllerUpdateTriggerPushNotificationsAction,\n NotificationServicesPushControllerDeletePushNotificationLinksAction,\n NotificationServicesPushControllerMethodActions,\n} from './NotificationServicesPushController-method-action-types';\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getMockDeleteFCMRegistrationTokenResponse = exports.getMockCreateFCMRegistrationTokenResponse = exports.MOCK_FCM_RESPONSE = exports.getMockUpdatePushNotificationLinksResponse = exports.MOCK_REG_TOKEN = void 0;
3
+ exports.getMockDeleteFCMRegistrationTokenResponse = exports.getMockCreateFCMRegistrationTokenResponse = exports.MOCK_FCM_RESPONSE = exports.getMockDeletePushNotificationLinksResponse = exports.getMockUpdatePushNotificationLinksResponse = exports.MOCK_REG_TOKEN = void 0;
4
4
  const endpoints_1 = require("../services/endpoints.cjs");
5
5
  exports.MOCK_REG_TOKEN = 'REG_TOKEN';
6
6
  const getMockUpdatePushNotificationLinksResponse = () => {
@@ -11,6 +11,14 @@ const getMockUpdatePushNotificationLinksResponse = () => {
11
11
  };
12
12
  };
13
13
  exports.getMockUpdatePushNotificationLinksResponse = getMockUpdatePushNotificationLinksResponse;
14
+ const getMockDeletePushNotificationLinksResponse = () => {
15
+ return {
16
+ url: (0, endpoints_1.REGISTRATION_TOKENS_ENDPOINT)(),
17
+ requestMethod: 'DELETE',
18
+ response: null,
19
+ };
20
+ };
21
+ exports.getMockDeletePushNotificationLinksResponse = getMockDeletePushNotificationLinksResponse;
14
22
  exports.MOCK_FCM_RESPONSE = {
15
23
  name: '',
16
24
  token: 'fcm-token',
@@ -1 +1 @@
1
- {"version":3,"file":"mockResponse.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":";;;AAAA,yDAAqE;AAQxD,QAAA,cAAc,GAAG,WAAW,CAAC;AAEnC,MAAM,0CAA0C,GAAG,GAAiB,EAAE;IAC3E,OAAO;QACL,GAAG,EAAE,IAAA,wCAA4B,GAAE;QACnC,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,IAAI;KACQ,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,0CAA0C,8CAMrD;AAEW,QAAA,iBAAiB,GAAG;IAC/B,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,WAAW;IAClB,GAAG,EAAE;QACH,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,EAAE;QACR,iBAAiB,EAAE,EAAE;KACtB;CACF,CAAC;AAEK,MAAM,yCAAyC,GAAG,GAAiB,EAAE;IAC1E,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,yBAAiB;KACL,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,yCAAyC,6CAMpD;AAEK,MAAM,yCAAyC,GAAG,GAAiB,EAAE;IAC1E,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,EAAE;KACU,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,yCAAyC,6CAMpD","sourcesContent":["import { REGISTRATION_TOKENS_ENDPOINT } from '../services/endpoints';\n\ntype MockResponse = {\n url: string | RegExp;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_REG_TOKEN = 'REG_TOKEN';\n\nexport const getMockUpdatePushNotificationLinksResponse = (): MockResponse => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT(),\n requestMethod: 'POST',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const MOCK_FCM_RESPONSE = {\n name: '',\n token: 'fcm-token',\n web: {\n endpoint: '',\n p256dh: '',\n auth: '',\n applicationPubKey: '',\n },\n};\n\nexport const getMockCreateFCMRegistrationTokenResponse = (): MockResponse => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: MOCK_FCM_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockDeleteFCMRegistrationTokenResponse = (): MockResponse => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: {},\n } satisfies MockResponse;\n};\n"]}
1
+ {"version":3,"file":"mockResponse.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":";;;AAAA,yDAAqE;AAQxD,QAAA,cAAc,GAAG,WAAW,CAAC;AAEnC,MAAM,0CAA0C,GAAG,GAAiB,EAAE;IAC3E,OAAO;QACL,GAAG,EAAE,IAAA,wCAA4B,GAAE;QACnC,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,IAAI;KACQ,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,0CAA0C,8CAMrD;AAEK,MAAM,0CAA0C,GAAG,GAAiB,EAAE;IAC3E,OAAO;QACL,GAAG,EAAE,IAAA,wCAA4B,GAAE;QACnC,aAAa,EAAE,QAAQ;QACvB,QAAQ,EAAE,IAAI;KACQ,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,0CAA0C,8CAMrD;AAEW,QAAA,iBAAiB,GAAG;IAC/B,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,WAAW;IAClB,GAAG,EAAE;QACH,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,EAAE;QACR,iBAAiB,EAAE,EAAE;KACtB;CACF,CAAC;AAEK,MAAM,yCAAyC,GAAG,GAAiB,EAAE;IAC1E,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,yBAAiB;KACL,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,yCAAyC,6CAMpD;AAEK,MAAM,yCAAyC,GAAG,GAAiB,EAAE;IAC1E,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,EAAE;KACU,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,yCAAyC,6CAMpD","sourcesContent":["import { REGISTRATION_TOKENS_ENDPOINT } from '../services/endpoints';\n\ntype MockResponse = {\n url: string | RegExp;\n requestMethod: 'GET' | 'POST' | 'PUT' | 'DELETE';\n response: unknown;\n};\n\nexport const MOCK_REG_TOKEN = 'REG_TOKEN';\n\nexport const getMockUpdatePushNotificationLinksResponse = (): MockResponse => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT(),\n requestMethod: 'POST',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const getMockDeletePushNotificationLinksResponse = (): MockResponse => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT(),\n requestMethod: 'DELETE',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const MOCK_FCM_RESPONSE = {\n name: '',\n token: 'fcm-token',\n web: {\n endpoint: '',\n p256dh: '',\n auth: '',\n applicationPubKey: '',\n },\n};\n\nexport const getMockCreateFCMRegistrationTokenResponse = (): MockResponse => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: MOCK_FCM_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockDeleteFCMRegistrationTokenResponse = (): MockResponse => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: {},\n } satisfies MockResponse;\n};\n"]}
@@ -1,10 +1,11 @@
1
1
  type MockResponse = {
2
2
  url: string | RegExp;
3
- requestMethod: 'GET' | 'POST' | 'PUT';
3
+ requestMethod: 'GET' | 'POST' | 'PUT' | 'DELETE';
4
4
  response: unknown;
5
5
  };
6
6
  export declare const MOCK_REG_TOKEN = "REG_TOKEN";
7
7
  export declare const getMockUpdatePushNotificationLinksResponse: () => MockResponse;
8
+ export declare const getMockDeletePushNotificationLinksResponse: () => MockResponse;
8
9
  export declare const MOCK_FCM_RESPONSE: {
9
10
  name: string;
10
11
  token: string;
@@ -1 +1 @@
1
- {"version":3,"file":"mockResponse.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,aAAa,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,CAAC;IACtC,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,cAAc,cAAc,CAAC;AAE1C,eAAO,MAAM,0CAA0C,QAAO,YAM7D,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;CAS7B,CAAC;AAEF,eAAO,MAAM,yCAAyC,QAAO,YAM5D,CAAC;AAEF,eAAO,MAAM,yCAAyC,QAAO,YAM5D,CAAC"}
1
+ {"version":3,"file":"mockResponse.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,aAAa,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;IACjD,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,cAAc,cAAc,CAAC;AAE1C,eAAO,MAAM,0CAA0C,QAAO,YAM7D,CAAC;AAEF,eAAO,MAAM,0CAA0C,QAAO,YAM7D,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;CAS7B,CAAC;AAEF,eAAO,MAAM,yCAAyC,QAAO,YAM5D,CAAC;AAEF,eAAO,MAAM,yCAAyC,QAAO,YAM5D,CAAC"}
@@ -1,10 +1,11 @@
1
1
  type MockResponse = {
2
2
  url: string | RegExp;
3
- requestMethod: 'GET' | 'POST' | 'PUT';
3
+ requestMethod: 'GET' | 'POST' | 'PUT' | 'DELETE';
4
4
  response: unknown;
5
5
  };
6
6
  export declare const MOCK_REG_TOKEN = "REG_TOKEN";
7
7
  export declare const getMockUpdatePushNotificationLinksResponse: () => MockResponse;
8
+ export declare const getMockDeletePushNotificationLinksResponse: () => MockResponse;
8
9
  export declare const MOCK_FCM_RESPONSE: {
9
10
  name: string;
10
11
  token: string;
@@ -1 +1 @@
1
- {"version":3,"file":"mockResponse.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,aAAa,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,CAAC;IACtC,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,cAAc,cAAc,CAAC;AAE1C,eAAO,MAAM,0CAA0C,QAAO,YAM7D,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;CAS7B,CAAC;AAEF,eAAO,MAAM,yCAAyC,QAAO,YAM5D,CAAC;AAEF,eAAO,MAAM,yCAAyC,QAAO,YAM5D,CAAC"}
1
+ {"version":3,"file":"mockResponse.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,aAAa,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;IACjD,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,cAAc,cAAc,CAAC;AAE1C,eAAO,MAAM,0CAA0C,QAAO,YAM7D,CAAC;AAEF,eAAO,MAAM,0CAA0C,QAAO,YAM7D,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;CAS7B,CAAC;AAEF,eAAO,MAAM,yCAAyC,QAAO,YAM5D,CAAC;AAEF,eAAO,MAAM,yCAAyC,QAAO,YAM5D,CAAC"}
@@ -7,6 +7,13 @@ export const getMockUpdatePushNotificationLinksResponse = () => {
7
7
  response: null,
8
8
  };
9
9
  };
10
+ export const getMockDeletePushNotificationLinksResponse = () => {
11
+ return {
12
+ url: REGISTRATION_TOKENS_ENDPOINT(),
13
+ requestMethod: 'DELETE',
14
+ response: null,
15
+ };
16
+ };
10
17
  export const MOCK_FCM_RESPONSE = {
11
18
  name: '',
12
19
  token: 'fcm-token',
@@ -1 +1 @@
1
- {"version":3,"file":"mockResponse.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,kCAA8B;AAQrE,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAE1C,MAAM,CAAC,MAAM,0CAA0C,GAAG,GAAiB,EAAE;IAC3E,OAAO;QACL,GAAG,EAAE,4BAA4B,EAAE;QACnC,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,IAAI;KACQ,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,WAAW;IAClB,GAAG,EAAE;QACH,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,EAAE;QACR,iBAAiB,EAAE,EAAE;KACtB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,yCAAyC,GAAG,GAAiB,EAAE;IAC1E,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,iBAAiB;KACL,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,yCAAyC,GAAG,GAAiB,EAAE;IAC1E,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,EAAE;KACU,CAAC;AAC3B,CAAC,CAAC","sourcesContent":["import { REGISTRATION_TOKENS_ENDPOINT } from '../services/endpoints';\n\ntype MockResponse = {\n url: string | RegExp;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_REG_TOKEN = 'REG_TOKEN';\n\nexport const getMockUpdatePushNotificationLinksResponse = (): MockResponse => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT(),\n requestMethod: 'POST',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const MOCK_FCM_RESPONSE = {\n name: '',\n token: 'fcm-token',\n web: {\n endpoint: '',\n p256dh: '',\n auth: '',\n applicationPubKey: '',\n },\n};\n\nexport const getMockCreateFCMRegistrationTokenResponse = (): MockResponse => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: MOCK_FCM_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockDeleteFCMRegistrationTokenResponse = (): MockResponse => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: {},\n } satisfies MockResponse;\n};\n"]}
1
+ {"version":3,"file":"mockResponse.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,kCAA8B;AAQrE,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAE1C,MAAM,CAAC,MAAM,0CAA0C,GAAG,GAAiB,EAAE;IAC3E,OAAO;QACL,GAAG,EAAE,4BAA4B,EAAE;QACnC,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,IAAI;KACQ,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,0CAA0C,GAAG,GAAiB,EAAE;IAC3E,OAAO;QACL,GAAG,EAAE,4BAA4B,EAAE;QACnC,aAAa,EAAE,QAAQ;QACvB,QAAQ,EAAE,IAAI;KACQ,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,WAAW;IAClB,GAAG,EAAE;QACH,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,EAAE;QACR,iBAAiB,EAAE,EAAE;KACtB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,yCAAyC,GAAG,GAAiB,EAAE;IAC1E,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,iBAAiB;KACL,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,yCAAyC,GAAG,GAAiB,EAAE;IAC1E,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,EAAE;KACU,CAAC;AAC3B,CAAC,CAAC","sourcesContent":["import { REGISTRATION_TOKENS_ENDPOINT } from '../services/endpoints';\n\ntype MockResponse = {\n url: string | RegExp;\n requestMethod: 'GET' | 'POST' | 'PUT' | 'DELETE';\n response: unknown;\n};\n\nexport const MOCK_REG_TOKEN = 'REG_TOKEN';\n\nexport const getMockUpdatePushNotificationLinksResponse = (): MockResponse => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT(),\n requestMethod: 'POST',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const getMockDeletePushNotificationLinksResponse = (): MockResponse => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT(),\n requestMethod: 'DELETE',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const MOCK_FCM_RESPONSE = {\n name: '',\n token: 'fcm-token',\n web: {\n endpoint: '',\n p256dh: '',\n auth: '',\n applicationPubKey: '',\n },\n};\n\nexport const getMockCreateFCMRegistrationTokenResponse = (): MockResponse => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: MOCK_FCM_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockDeleteFCMRegistrationTokenResponse = (): MockResponse => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: {},\n } satisfies MockResponse;\n};\n"]}
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.deactivatePushNotifications = exports.activatePushNotifications = exports.updateLinksAPI = void 0;
26
+ exports.deactivatePushNotifications = exports.activatePushNotifications = exports.deleteLinksAPI = exports.updateLinksAPI = void 0;
27
27
  const endpoints = __importStar(require("./endpoints.cjs"));
28
28
  /**
29
29
  * Updates the push notification links on a remote API.
@@ -52,6 +52,36 @@ async function updateLinksAPI(params) {
52
52
  }
53
53
  }
54
54
  exports.updateLinksAPI = updateLinksAPI;
55
+ /**
56
+ * Deletes push notification links for addresses and platform.
57
+ *
58
+ * @param params - params for deleting registration links
59
+ * @returns A promise that resolves with true if the delete request was successful, false otherwise.
60
+ */
61
+ async function deleteLinksAPI(params) {
62
+ try {
63
+ const body = {
64
+ addresses: params.addresses,
65
+ registration_token: {
66
+ platform: params.platform,
67
+ token: params.token,
68
+ },
69
+ };
70
+ const response = await fetch(endpoints.REGISTRATION_TOKENS_ENDPOINT(params.env), {
71
+ method: 'DELETE',
72
+ headers: {
73
+ Authorization: `Bearer ${params.bearerToken}`,
74
+ 'Content-Type': 'application/json',
75
+ },
76
+ body: JSON.stringify(body),
77
+ });
78
+ return response.ok;
79
+ }
80
+ catch {
81
+ return false;
82
+ }
83
+ }
84
+ exports.deleteLinksAPI = deleteLinksAPI;
55
85
  /**
56
86
  * Enables push notifications by registering the device and linking triggers.
57
87
  *
@@ -1 +1 @@
1
- {"version":3,"file":"services.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2DAAyC;AAoCzC;;;;;GAKG;AACI,KAAK,UAAU,cAAc,CAClC,MAA6B;IAE7B,IAAI,CAAC;QACH,MAAM,IAAI,GAAqB;YAC7B,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,kBAAkB,EAAE,MAAM,CAAC,QAAQ;SACpC,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,SAAS,CAAC,4BAA4B,CAAC,MAAM,CAAC,GAAG,CAAC,EAClD;YACE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,aAA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c,CAAC,GAAG,CAAC,CAAC;IACxD,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAhBD,kEAgBC","sourcesContent":["import type { ENV } from './endpoints';\nimport * as endpoints from './endpoints';\nimport type { PushNotificationEnv } from '../types';\nimport type {\n CreateRegToken,\n DeleteRegToken,\n} from '../types/push-service-interface';\n\nexport type RegToken = {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n locale: string;\n oldToken?: string;\n};\n\n/**\n * Links API Response Shape\n */\nexport type PushTokenRequest = {\n addresses: string[];\n // API response uses snake_case for this property\n // eslint-disable-next-line @typescript-eslint/naming-convention\n registration_token: {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n locale: string;\n oldToken?: string;\n };\n};\n\ntype UpdatePushTokenParams = {\n bearerToken: string;\n addresses: string[];\n regToken: RegToken;\n env?: ENV;\n};\n\n/**\n * Updates the push notification links on a remote API.\n *\n * @param params - params for invoking update reg token\n * @returns A promise that resolves with true if the update was successful, false otherwise.\n */\nexport async function updateLinksAPI(\n params: UpdatePushTokenParams,\n): Promise<boolean> {\n try {\n const body: PushTokenRequest = {\n addresses: params.addresses,\n registration_token: params.regToken,\n };\n const response = await fetch(\n endpoints.REGISTRATION_TOKENS_ENDPOINT(params.env),\n {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${params.bearerToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n },\n );\n return response.ok;\n } catch {\n return false;\n }\n}\n\ntype ActivatePushNotificationsParams = {\n // Create Push Token\n env: PushNotificationEnv;\n createRegToken: CreateRegToken;\n controllerEnv?: ENV;\n\n // Other Request Parameters\n bearerToken: string;\n addresses: string[];\n regToken: Pick<RegToken, 'locale' | 'platform' | 'oldToken'>;\n};\n\n/**\n * Enables push notifications by registering the device and linking triggers.\n *\n * @param params - Activate Push Params\n * @returns A promise that resolves with an object containing the success status and the BearerToken token.\n */\nexport async function activatePushNotifications(\n params: ActivatePushNotificationsParams,\n): Promise<string | null> {\n const { env, createRegToken } = params;\n\n const regToken = await createRegToken(env).catch(() => null);\n if (!regToken) {\n return null;\n }\n\n await updateLinksAPI({\n bearerToken: params.bearerToken,\n addresses: params.addresses,\n regToken: {\n token: regToken,\n platform: params.regToken.platform,\n locale: params.regToken.locale,\n oldToken: params.regToken.oldToken,\n },\n env: params.controllerEnv,\n });\n\n return regToken;\n}\n\ntype DeactivatePushNotificationsParams = {\n // Push Links\n regToken: string;\n\n // Push Un-registration\n env: PushNotificationEnv;\n deleteRegToken: DeleteRegToken;\n};\n\n/**\n * Disables push notifications by removing the registration token\n * We do not need to unlink triggers, and remove old reg tokens (this is cleaned up in the back-end)\n *\n * @param params - Deactivate Push Params\n * @returns A promise that resolves with true if push notifications were successfully disabled, false otherwise.\n */\nexport async function deactivatePushNotifications(\n params: DeactivatePushNotificationsParams,\n): Promise<boolean> {\n const { regToken, env, deleteRegToken } = params;\n\n // if we don't have a reg token, then we can early return\n if (!regToken) {\n return true;\n }\n\n const isTokenRemovedFromFCM = await deleteRegToken(env);\n if (!isTokenRemovedFromFCM) {\n return false;\n }\n\n return true;\n}\n"]}
1
+ {"version":3,"file":"services.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2DAAyC;AAgDzC;;;;;GAKG;AACI,KAAK,UAAU,cAAc,CAClC,MAA6B;IAE7B,IAAI,CAAC;QACH,MAAM,IAAI,GAAqB;YAC7B,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,kBAAkB,EAAE,MAAM,CAAC,QAAQ;SACpC,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,SAAS,CAAC,4BAA4B,CAAC,MAAM,CAAC,GAAG,CAAC,EAClD;YACE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,aAAa,EAAE,UA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AED,MAAM,cAAc,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,QAAQ,EAAE;YACR,KAAK,EAAE,QAAQ;YACf,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ;YAClC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM;YAC9B,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ;SACnC;QACD,GAAG,EAAE,MAAM,CAAC,aAAa;KAC1B,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC;AAvBD,8DAuBC;AAWD;;;;;;GAMG;AACI,KAAK,UAAU,2BAA2B,CAC/C,MAAyC;IAEzC,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC;IAEjD,yDAAyD;IACzD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,qBAAqB,GAAG,MAAM,cAAc,CAAC,GAAG,CAAC,CAAC;IACxD,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAhBD,kEAgBC","sourcesContent":["import type { ENV } from './endpoints';\nimport * as endpoints from './endpoints';\nimport type { PushNotificationEnv } from '../types';\nimport type {\n CreateRegToken,\n DeleteRegToken,\n} from '../types/push-service-interface';\n\nexport type RegToken = {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n locale: string;\n oldToken?: string;\n};\n\nexport type RegistrationPlatform = 'extension' | 'mobile';\n\n/**\n * Links API Response Shape\n */\nexport type PushTokenRequest = {\n addresses: string[];\n // API response uses snake_case for this property\n // eslint-disable-next-line @typescript-eslint/naming-convention\n registration_token: {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n locale: string;\n oldToken?: string;\n };\n};\n\nexport type DeletePushTokenRequest = {\n addresses: string[];\n // API request uses snake_case for this property\n // eslint-disable-next-line @typescript-eslint/naming-convention\n registration_token: {\n platform: RegistrationPlatform;\n token: string;\n };\n};\n\ntype UpdatePushTokenParams = {\n bearerToken: string;\n addresses: string[];\n regToken: RegToken;\n env?: ENV;\n};\n\n/**\n * Updates the push notification links on a remote API.\n *\n * @param params - params for invoking update reg token\n * @returns A promise that resolves with true if the update was successful, false otherwise.\n */\nexport async function updateLinksAPI(\n params: UpdatePushTokenParams,\n): Promise<boolean> {\n try {\n const body: PushTokenRequest = {\n addresses: params.addresses,\n registration_token: params.regToken,\n };\n const response = await fetch(\n endpoints.REGISTRATION_TOKENS_ENDPOINT(params.env),\n {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${params.bearerToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n },\n );\n return response.ok;\n } catch {\n return false;\n }\n}\n\ntype DeletePushTokenParams = {\n bearerToken: string;\n addresses: string[];\n platform: RegistrationPlatform;\n token: string;\n env?: ENV;\n};\n\n/**\n * Deletes push notification links for addresses and platform.\n *\n * @param params - params for deleting registration links\n * @returns A promise that resolves with true if the delete request was successful, false otherwise.\n */\nexport async function deleteLinksAPI(\n params: DeletePushTokenParams,\n): Promise<boolean> {\n try {\n const body: DeletePushTokenRequest = {\n addresses: params.addresses,\n registration_token: {\n platform: params.platform,\n token: params.token,\n },\n };\n const response = await fetch(\n endpoints.REGISTRATION_TOKENS_ENDPOINT(params.env),\n {\n method: 'DELETE',\n headers: {\n Authorization: `Bearer ${params.bearerToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n },\n );\n return response.ok;\n } catch {\n return false;\n }\n}\n\ntype ActivatePushNotificationsParams = {\n // Create Push Token\n env: PushNotificationEnv;\n createRegToken: CreateRegToken;\n controllerEnv?: ENV;\n\n // Other Request Parameters\n bearerToken: string;\n addresses: string[];\n regToken: Pick<RegToken, 'locale' | 'platform' | 'oldToken'>;\n};\n\n/**\n * Enables push notifications by registering the device and linking triggers.\n *\n * @param params - Activate Push Params\n * @returns A promise that resolves with an object containing the success status and the BearerToken token.\n */\nexport async function activatePushNotifications(\n params: ActivatePushNotificationsParams,\n): Promise<string | null> {\n const { env, createRegToken } = params;\n\n const regToken = await createRegToken(env).catch(() => null);\n if (!regToken) {\n return null;\n }\n\n await updateLinksAPI({\n bearerToken: params.bearerToken,\n addresses: params.addresses,\n regToken: {\n token: regToken,\n platform: params.regToken.platform,\n locale: params.regToken.locale,\n oldToken: params.regToken.oldToken,\n },\n env: params.controllerEnv,\n });\n\n return regToken;\n}\n\ntype DeactivatePushNotificationsParams = {\n // Push Links\n regToken: string;\n\n // Push Un-registration\n env: PushNotificationEnv;\n deleteRegToken: DeleteRegToken;\n};\n\n/**\n * Disables push notifications by removing the registration token\n * We do not need to unlink triggers, and remove old reg tokens (this is cleaned up in the back-end)\n *\n * @param params - Deactivate Push Params\n * @returns A promise that resolves with true if push notifications were successfully disabled, false otherwise.\n */\nexport async function deactivatePushNotifications(\n params: DeactivatePushNotificationsParams,\n): Promise<boolean> {\n const { regToken, env, deleteRegToken } = params;\n\n // if we don't have a reg token, then we can early return\n if (!regToken) {\n return true;\n }\n\n const isTokenRemovedFromFCM = await deleteRegToken(env);\n if (!isTokenRemovedFromFCM) {\n return false;\n }\n\n return true;\n}\n"]}
@@ -7,6 +7,7 @@ export type RegToken = {
7
7
  locale: string;
8
8
  oldToken?: string;
9
9
  };
10
+ export type RegistrationPlatform = 'extension' | 'mobile';
10
11
  /**
11
12
  * Links API Response Shape
12
13
  */
@@ -19,6 +20,13 @@ export type PushTokenRequest = {
19
20
  oldToken?: string;
20
21
  };
21
22
  };
23
+ export type DeletePushTokenRequest = {
24
+ addresses: string[];
25
+ registration_token: {
26
+ platform: RegistrationPlatform;
27
+ token: string;
28
+ };
29
+ };
22
30
  type UpdatePushTokenParams = {
23
31
  bearerToken: string;
24
32
  addresses: string[];
@@ -32,6 +40,20 @@ type UpdatePushTokenParams = {
32
40
  * @returns A promise that resolves with true if the update was successful, false otherwise.
33
41
  */
34
42
  export declare function updateLinksAPI(params: UpdatePushTokenParams): Promise<boolean>;
43
+ type DeletePushTokenParams = {
44
+ bearerToken: string;
45
+ addresses: string[];
46
+ platform: RegistrationPlatform;
47
+ token: string;
48
+ env?: ENV;
49
+ };
50
+ /**
51
+ * Deletes push notification links for addresses and platform.
52
+ *
53
+ * @param params - params for deleting registration links
54
+ * @returns A promise that resolves with true if the delete request was successful, false otherwise.
55
+ */
56
+ export declare function deleteLinksAPI(params: DeletePushTokenParams): Promise<boolean>;
35
57
  type ActivatePushNotificationsParams = {
36
58
  env: PushNotificationEnv;
37
59
  createRegToken: CreateRegToken;
@@ -1 +1 @@
1
- {"version":3,"file":"services.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAoB;AAEvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAAiB;AACpD,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACf,4CAAwC;AAEzC,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,EAAE,CAAC;IAGpB,kBAAkB,EAAE;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;QAC/C,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,GAAG,CAAC,EAAE,GAAG,CAAC;CACX,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,OAAO,CAAC,CAqBlB;AAED,KAAK,+BAA+B,GAAG;IAErC,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;IAC/B,aAAa,CAAC,EAAE,GAAG,CAAC;IAGpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,+BAA+B,GACtC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAqBxB;AAED,KAAK,iCAAiC,GAAG;IAEvC,QAAQ,EAAE,MAAM,CAAC;IAGjB,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,iCAAiC,GACxC,OAAO,CAAC,OAAO,CAAC,CAclB"}
1
+ {"version":3,"file":"services.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAoB;AAEvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAAiB;AACpD,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACf,4CAAwC;AAEzC,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf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/B,aAAa,CAAC,EAAE,GAAG,CAAC;IAGpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,+BAA+B,GACtC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAqBxB;AAED,KAAK,iCAAiC,GAAG;IAEvC,QAAQ,EAAE,MAAM,CAAC;IAGjB,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,iCAAiC,GACxC,OAAO,CAAC,OAAO,CAAC,CAclB"}
@@ -7,6 +7,7 @@ export type RegToken = {
7
7
  locale: string;
8
8
  oldToken?: string;
9
9
  };
10
+ export type RegistrationPlatform = 'extension' | 'mobile';
10
11
  /**
11
12
  * Links API Response Shape
12
13
  */
@@ -19,6 +20,13 @@ export type PushTokenRequest = {
19
20
  oldToken?: string;
20
21
  };
21
22
  };
23
+ export type DeletePushTokenRequest = {
24
+ addresses: string[];
25
+ registration_token: {
26
+ platform: RegistrationPlatform;
27
+ token: string;
28
+ };
29
+ };
22
30
  type UpdatePushTokenParams = {
23
31
  bearerToken: string;
24
32
  addresses: string[];
@@ -32,6 +40,20 @@ type UpdatePushTokenParams = {
32
40
  * @returns A promise that resolves with true if the update was successful, false otherwise.
33
41
  */
34
42
  export declare function updateLinksAPI(params: UpdatePushTokenParams): Promise<boolean>;
43
+ type DeletePushTokenParams = {
44
+ bearerToken: string;
45
+ addresses: string[];
46
+ platform: RegistrationPlatform;
47
+ token: string;
48
+ env?: ENV;
49
+ };
50
+ /**
51
+ * Deletes push notification links for addresses and platform.
52
+ *
53
+ * @param params - params for deleting registration links
54
+ * @returns A promise that resolves with true if the delete request was successful, false otherwise.
55
+ */
56
+ export declare function deleteLinksAPI(params: DeletePushTokenParams): Promise<boolean>;
35
57
  type ActivatePushNotificationsParams = {
36
58
  env: PushNotificationEnv;
37
59
  createRegToken: CreateRegToken;
@@ -1 +1 @@
1
- {"version":3,"file":"services.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAoB;AAEvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAAiB;AACpD,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACf,4CAAwC;AAEzC,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,EAAE,CAAC;IAGpB,kBAAkB,EAAE;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;QAC/C,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,GAAG,CAAC,EAAE,GAAG,CAAC;CACX,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,OAAO,CAAC,CAqBlB;AAED,KAAK,+BAA+B,GAAG;IAErC,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;IAC/B,aAAa,CAAC,EAAE,GAAG,CAAC;IAGpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,+BAA+B,GACtC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAqBxB;AAED,KAAK,iCAAiC,GAAG;IAEvC,QAAQ,EAAE,MAAM,CAAC;IAGjB,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,iCAAiC,GACxC,OAAO,CAAC,OAAO,CAAC,CAclB"}
1
+ {"version":3,"file":"services.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAoB;AAEvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAAiB;AACpD,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACf,4CAAwC;AAEzC,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,EAAE,CAAC;IAGpB,kBAAkB,EAAE;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GA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AO,CAAC,MAAM,GAAG,IAAI,CAAC,CAqBxB;AAED,KAAK,iCAAiC,GAAG;IAEvC,QAAQ,EAAE,MAAM,CAAC;IAGjB,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,iCAAiC,GACxC,OAAO,CAAC,OAAO,CAAC,CAclB"}
@@ -25,6 +25,35 @@ export async function updateLinksAPI(params) {
25
25
  return false;
26
26
  }
27
27
  }
28
+ /**
29
+ * Deletes push notification links for addresses and platform.
30
+ *
31
+ * @param params - params for deleting registration links
32
+ * @returns A promise that resolves with true if the delete request was successful, false otherwise.
33
+ */
34
+ export async function deleteLinksAPI(params) {
35
+ try {
36
+ const body = {
37
+ addresses: params.addresses,
38
+ registration_token: {
39
+ platform: params.platform,
40
+ token: params.token,
41
+ },
42
+ };
43
+ const response = await fetch(endpoints.REGISTRATION_TOKENS_ENDPOINT(params.env), {
44
+ method: 'DELETE',
45
+ headers: {
46
+ Authorization: `Bearer ${params.bearerToken}`,
47
+ 'Content-Type': 'application/json',
48
+ },
49
+ body: JSON.stringify(body),
50
+ });
51
+ return response.ok;
52
+ }
53
+ catch {
54
+ return false;
55
+ }
56
+ }
28
57
  /**
29
58
  * Enables push notifications by registering the device and linking triggers.
30
59
  *
@@ -1 +1 @@
1
- {"version":3,"file":"services.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,SAAS,wBAAoB;AAoCzC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAA6B;IAE7B,IAAI,CAAC;QACH,MAAM,IAAI,GAAqB;YAC7B,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,kBAAkB,EAAE,MAAM,CAAC,QAAQ;SACpC,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,SAAS,CA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C,QAAQ,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,qBAAqB,GAAG,MAAM,cAAc,CAAC,GAAG,CAAC,CAAC;IACxD,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { ENV } from './endpoints';\nimport * as endpoints from './endpoints';\nimport type { PushNotificationEnv } from '../types';\nimport type {\n CreateRegToken,\n DeleteRegToken,\n} from '../types/push-service-interface';\n\nexport type RegToken = {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n locale: string;\n oldToken?: string;\n};\n\n/**\n * Links API Response Shape\n */\nexport type PushTokenRequest = {\n addresses: string[];\n // API response uses snake_case for this property\n // eslint-disable-next-line @typescript-eslint/naming-convention\n registration_token: {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n locale: string;\n oldToken?: string;\n };\n};\n\ntype UpdatePushTokenParams = {\n bearerToken: string;\n addresses: string[];\n regToken: RegToken;\n env?: ENV;\n};\n\n/**\n * Updates the push notification links on a remote API.\n *\n * @param params - params for invoking update reg token\n * @returns A promise that resolves with true if the update was successful, false otherwise.\n */\nexport async function updateLinksAPI(\n params: UpdatePushTokenParams,\n): Promise<boolean> {\n try {\n const body: PushTokenRequest = {\n addresses: params.addresses,\n registration_token: params.regToken,\n };\n const response = await fetch(\n endpoints.REGISTRATION_TOKENS_ENDPOINT(params.env),\n {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${params.bearerToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n },\n );\n return response.ok;\n } catch {\n return false;\n }\n}\n\ntype ActivatePushNotificationsParams = {\n // Create Push Token\n env: PushNotificationEnv;\n createRegToken: CreateRegToken;\n controllerEnv?: ENV;\n\n // Other Request Parameters\n bearerToken: string;\n addresses: string[];\n regToken: Pick<RegToken, 'locale' | 'platform' | 'oldToken'>;\n};\n\n/**\n * Enables push notifications by registering the device and linking triggers.\n *\n * @param params - Activate Push Params\n * @returns A promise that resolves with an object containing the success status and the BearerToken token.\n */\nexport async function activatePushNotifications(\n params: ActivatePushNotificationsParams,\n): Promise<string | null> {\n const { env, createRegToken } = params;\n\n const regToken = await createRegToken(env).catch(() => null);\n if (!regToken) {\n return null;\n }\n\n await updateLinksAPI({\n bearerToken: params.bearerToken,\n addresses: params.addresses,\n regToken: {\n token: regToken,\n platform: params.regToken.platform,\n locale: params.regToken.locale,\n oldToken: params.regToken.oldToken,\n },\n env: params.controllerEnv,\n });\n\n return regToken;\n}\n\ntype DeactivatePushNotificationsParams = {\n // Push Links\n regToken: string;\n\n // Push Un-registration\n env: PushNotificationEnv;\n deleteRegToken: DeleteRegToken;\n};\n\n/**\n * Disables push notifications by removing the registration token\n * We do not need to unlink triggers, and remove old reg tokens (this is cleaned up in the back-end)\n *\n * @param params - Deactivate Push Params\n * @returns A promise that resolves with true if push notifications were successfully disabled, false otherwise.\n */\nexport async function deactivatePushNotifications(\n params: DeactivatePushNotificationsParams,\n): Promise<boolean> {\n const { regToken, env, deleteRegToken } = params;\n\n // if we don't have a reg token, then we can early return\n if (!regToken) {\n return true;\n }\n\n const isTokenRemovedFromFCM = await deleteRegToken(env);\n if (!isTokenRemovedFromFCM) {\n return false;\n }\n\n return true;\n}\n"]}
1
+ {"version":3,"file":"services.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,SAAS,wBAAoB;AAgDzC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAA6B;IAE7B,IAAI,CAAC;QACH,MAAM,IAAI,GAAqB;YAC7B,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,kBAAkB,EAAE,MAAM,CAAC,QAAQ;SACpC,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,SAAS,CAAC,4BAA4B,CAAC,MAAM,CAAC,GAA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,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,cAAc,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,QAAQ,EAAE;YACR,KAAK,EAAE,QAAQ;YACf,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ;YAClC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM;YAC9B,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ;SACnC;QACD,GAAG,EAAE,MAAM,CAAC,aAAa;KAC1B,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC;AAWD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,MAAyC;IAEzC,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC;IAEjD,yDAAyD;IACzD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,qBAAqB,GAAG,MAAM,cAAc,CAAC,GAAG,CAAC,CAAC;IACxD,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { ENV } from './endpoints';\nimport * as endpoints from './endpoints';\nimport type { PushNotificationEnv } from '../types';\nimport type {\n CreateRegToken,\n DeleteRegToken,\n} from '../types/push-service-interface';\n\nexport type RegToken = {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n locale: string;\n oldToken?: string;\n};\n\nexport type RegistrationPlatform = 'extension' | 'mobile';\n\n/**\n * Links API Response Shape\n */\nexport type PushTokenRequest = {\n addresses: string[];\n // API response uses snake_case for this property\n // eslint-disable-next-line @typescript-eslint/naming-convention\n registration_token: {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n locale: string;\n oldToken?: string;\n };\n};\n\nexport type DeletePushTokenRequest = {\n addresses: string[];\n // API request uses snake_case for this property\n // eslint-disable-next-line @typescript-eslint/naming-convention\n registration_token: {\n platform: RegistrationPlatform;\n token: string;\n };\n};\n\ntype UpdatePushTokenParams = {\n bearerToken: string;\n addresses: string[];\n regToken: RegToken;\n env?: ENV;\n};\n\n/**\n * Updates the push notification links on a remote API.\n *\n * @param params - params for invoking update reg token\n * @returns A promise that resolves with true if the update was successful, false otherwise.\n */\nexport async function updateLinksAPI(\n params: UpdatePushTokenParams,\n): Promise<boolean> {\n try {\n const body: PushTokenRequest = {\n addresses: params.addresses,\n registration_token: params.regToken,\n };\n const response = await fetch(\n endpoints.REGISTRATION_TOKENS_ENDPOINT(params.env),\n {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${params.bearerToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n },\n );\n return response.ok;\n } catch {\n return false;\n }\n}\n\ntype DeletePushTokenParams = {\n bearerToken: string;\n addresses: string[];\n platform: RegistrationPlatform;\n token: string;\n env?: ENV;\n};\n\n/**\n * Deletes push notification links for addresses and platform.\n *\n * @param params - params for deleting registration links\n * @returns A promise that resolves with true if the delete request was successful, false otherwise.\n */\nexport async function deleteLinksAPI(\n params: DeletePushTokenParams,\n): Promise<boolean> {\n try {\n const body: DeletePushTokenRequest = {\n addresses: params.addresses,\n registration_token: {\n platform: params.platform,\n token: params.token,\n },\n };\n const response = await fetch(\n endpoints.REGISTRATION_TOKENS_ENDPOINT(params.env),\n {\n method: 'DELETE',\n headers: {\n Authorization: `Bearer ${params.bearerToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n },\n );\n return response.ok;\n } catch {\n return false;\n }\n}\n\ntype ActivatePushNotificationsParams = {\n // Create Push Token\n env: PushNotificationEnv;\n createRegToken: CreateRegToken;\n controllerEnv?: ENV;\n\n // Other Request Parameters\n bearerToken: string;\n addresses: string[];\n regToken: Pick<RegToken, 'locale' | 'platform' | 'oldToken'>;\n};\n\n/**\n * Enables push notifications by registering the device and linking triggers.\n *\n * @param params - Activate Push Params\n * @returns A promise that resolves with an object containing the success status and the BearerToken token.\n */\nexport async function activatePushNotifications(\n params: ActivatePushNotificationsParams,\n): Promise<string | null> {\n const { env, createRegToken } = params;\n\n const regToken = await createRegToken(env).catch(() => null);\n if (!regToken) {\n return null;\n }\n\n await updateLinksAPI({\n bearerToken: params.bearerToken,\n addresses: params.addresses,\n regToken: {\n token: regToken,\n platform: params.regToken.platform,\n locale: params.regToken.locale,\n oldToken: params.regToken.oldToken,\n },\n env: params.controllerEnv,\n });\n\n return regToken;\n}\n\ntype DeactivatePushNotificationsParams = {\n // Push Links\n regToken: string;\n\n // Push Un-registration\n env: PushNotificationEnv;\n deleteRegToken: DeleteRegToken;\n};\n\n/**\n * Disables push notifications by removing the registration token\n * We do not need to unlink triggers, and remove old reg tokens (this is cleaned up in the back-end)\n *\n * @param params - Deactivate Push Params\n * @returns A promise that resolves with true if push notifications were successfully disabled, false otherwise.\n */\nexport async function deactivatePushNotifications(\n params: DeactivatePushNotificationsParams,\n): Promise<boolean> {\n const { regToken, env, deleteRegToken } = params;\n\n // if we don't have a reg token, then we can early return\n if (!regToken) {\n return true;\n }\n\n const isTokenRemovedFromFCM = await deleteRegToken(env);\n if (!isTokenRemovedFromFCM) {\n return false;\n }\n\n return true;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/notification-services-controller",
3
- "version": "22.0.0",
3
+ "version": "23.0.0",
4
4
  "description": "Manages New MetaMask decentralized Notification system",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -92,7 +92,9 @@
92
92
  "build:docs": "typedoc",
93
93
  "changelog:update": "../../scripts/update-changelog.sh @metamask/notification-services-controller",
94
94
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/notification-services-controller",
95
- "publish:preview": "yarn npm publish --tag preview",
95
+ "generate-method-action-types": "yarn generate-method-action-types:notifications-services-controller \"$@\" && yarn generate-method-action-types:notifications-services-push-controller \"$@\"",
96
+ "generate-method-action-types:notifications-services-controller": "tsx ../../scripts/generate-method-action-types.ts src/NotificationServicesController",
97
+ "generate-method-action-types:notifications-services-push-controller": "tsx ../../scripts/generate-method-action-types.ts src/NotificationServicesPushController",
96
98
  "since-latest-release": "../../scripts/since-latest-release.sh",
97
99
  "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
98
100
  "test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
@@ -102,13 +104,14 @@
102
104
  "dependencies": {
103
105
  "@contentful/rich-text-html-renderer": "^16.5.2",
104
106
  "@metamask/base-controller": "^9.0.0",
105
- "@metamask/controller-utils": "^11.18.0",
107
+ "@metamask/controller-utils": "^11.19.0",
106
108
  "@metamask/keyring-controller": "^25.1.0",
107
109
  "@metamask/messenger": "^0.3.0",
108
- "@metamask/profile-sync-controller": "^27.1.0",
110
+ "@metamask/profile-sync-controller": "^28.0.0",
109
111
  "@metamask/utils": "^11.9.0",
110
112
  "bignumber.js": "^9.1.2",
111
113
  "firebase": "^11.2.0",
114
+ "lodash": "^4.17.21",
112
115
  "loglevel": "^1.8.1",
113
116
  "semver": "^7.6.3",
114
117
  "uuid": "^8.3.2"
@@ -118,16 +121,18 @@
118
121
  "@lavamoat/preinstall-always-fail": "^2.1.0",
119
122
  "@metamask/auto-changelog": "^3.4.4",
120
123
  "@ts-bridge/cli": "^0.6.4",
121
- "@types/jest": "^27.5.2",
124
+ "@types/jest": "^29.5.14",
125
+ "@types/lodash": "^4.14.191",
122
126
  "@types/readable-stream": "^2.3.0",
123
127
  "@types/semver": "^7",
124
128
  "contentful": "^10.15.0",
125
129
  "deepmerge": "^4.2.2",
126
- "jest": "^27.5.1",
127
- "jest-environment-jsdom": "^27.5.1",
130
+ "jest": "^29.7.0",
131
+ "jest-environment-jsdom": "^29.7.0",
128
132
  "nock": "^13.3.1",
129
- "ts-jest": "^27.1.5",
130
- "typedoc": "^0.24.8",
133
+ "ts-jest": "^29.2.5",
134
+ "tsx": "^4.20.5",
135
+ "typedoc": "^0.25.13",
131
136
  "typedoc-plugin-missing-exports": "^2.0.0",
132
137
  "typescript": "~5.3.3"
133
138
  },