@metamask-previews/announcement-controller 8.1.0-preview-8bfa290fb → 9.0.0-preview-0a30e47

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 (33) hide show
  1. package/CHANGELOG.md +13 -5
  2. package/dist/{AnnouncementController-method-action-types.d.mts → AnnouncementController-method-action-types.d.ts} +2 -2
  3. package/dist/AnnouncementController-method-action-types.d.ts.map +1 -0
  4. package/dist/{AnnouncementController-method-action-types.mjs → AnnouncementController-method-action-types.js} +1 -1
  5. package/dist/AnnouncementController-method-action-types.js.map +1 -0
  6. package/dist/{AnnouncementController.d.cts → AnnouncementController.d.ts} +5 -5
  7. package/dist/AnnouncementController.d.ts.map +1 -0
  8. package/dist/{AnnouncementController.mjs → AnnouncementController.js} +18 -17
  9. package/dist/AnnouncementController.js.map +1 -0
  10. package/dist/{index.d.cts → index.d.ts} +4 -4
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +2 -0
  13. package/dist/index.js.map +1 -0
  14. package/package.json +14 -18
  15. package/dist/AnnouncementController-method-action-types.cjs +0 -7
  16. package/dist/AnnouncementController-method-action-types.cjs.map +0 -1
  17. package/dist/AnnouncementController-method-action-types.d.cts +0 -27
  18. package/dist/AnnouncementController-method-action-types.d.cts.map +0 -1
  19. package/dist/AnnouncementController-method-action-types.d.mts.map +0 -1
  20. package/dist/AnnouncementController-method-action-types.mjs.map +0 -1
  21. package/dist/AnnouncementController.cjs +0 -75
  22. package/dist/AnnouncementController.cjs.map +0 -1
  23. package/dist/AnnouncementController.d.cts.map +0 -1
  24. package/dist/AnnouncementController.d.mts +0 -71
  25. package/dist/AnnouncementController.d.mts.map +0 -1
  26. package/dist/AnnouncementController.mjs.map +0 -1
  27. package/dist/index.cjs +0 -6
  28. package/dist/index.cjs.map +0 -1
  29. package/dist/index.d.cts.map +0 -1
  30. package/dist/index.d.mts +0 -4
  31. package/dist/index.d.mts.map +0 -1
  32. package/dist/index.mjs +0 -2
  33. package/dist/index.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,10 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [9.0.0]
11
+
10
12
  ### Changed
11
13
 
12
- - Bump `@metamask/messenger` from `^1.0.0` to `^2.0.0` ([#8364](https://github.com/MetaMask/core/pull/8364), [#8373](https://github.com/MetaMask/core/pull/8373), [#8632](https://github.com/MetaMask/core/pull/8632), [#9392](https://github.com/MetaMask/core/pull/9392))
13
- - Bump `@metamask/base-controller` from `^9.0.1` to `^9.1.0` ([#8457](https://github.com/MetaMask/core/pull/8457))
14
+ - **BREAKING:** Drop CommonJS support ([#9536](https://github.com/MetaMask/core/pull/9536))
15
+ - This package is now ESM-only, but can still be used in CommonJS projects via `require(esm)` in modern Node.js versions (22+), or dynamic imports in older Node.js versions.
16
+ - **BREAKING:** Bump minimum Node.js version to 22 ([#9976](https://github.com/MetaMask/core/pull/9976))
17
+ - **BREAKING:** Bump TypeScript target to ES2022 ([#10019](https://github.com/MetaMask/core/pull/10019))
18
+ - This package now ships ES2022 code, requiring a compatible modern environment or bundler configuration to consume.
19
+ - Bump `@metamask/messenger` from `^1.0.0` to `^3.0.0` ([#8364](https://github.com/MetaMask/core/pull/8364), [#8373](https://github.com/MetaMask/core/pull/8373), [#8632](https://github.com/MetaMask/core/pull/8632), [#9392](https://github.com/MetaMask/core/pull/9392), [#10160](https://github.com/MetaMask/core/pull/10160))
20
+ - Bump `@metamask/base-controller` from `^9.0.1` to `^10.0.0` ([#8457](https://github.com/MetaMask/core/pull/8457), [#10160](https://github.com/MetaMask/core/pull/10160))
14
21
 
15
22
  ## [8.1.0]
16
23
 
@@ -56,7 +63,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
56
63
 
57
64
  ### Changed
58
65
 
59
- - Bump `@metamask/base-controller` from `^7.0.2` to `^8.0.0` ([#5079](https://github.com/MetaMask/core/pull/5079)), ([#5135](https://github.com/MetaMask/core/pull/5135)), ([#5305](https://github.com/MetaMask/core/pull/5305))
66
+ - Bump `@metamask/base-controller` from `^7.0.2` to `^8.0.0` ([#5079](https://github.com/MetaMask/core/pull/5079), [#5135](https://github.com/MetaMask/core/pull/5135), [#5305](https://github.com/MetaMask/core/pull/5305))
60
67
 
61
68
  ## [7.0.2]
62
69
 
@@ -80,7 +87,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
80
87
  ["Are the Types Wrong?"](https://arethetypeswrong.github.io/) tool as
81
88
  ["masquerading as CJS"](https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseCJS.md).
82
89
  All of the ATTW checks now pass.
83
- - Remove chunk files ([#4648](https://github.com/MetaMask/core/pull/4648)).
90
+ - Remove chunk files. ([#4648](https://github.com/MetaMask/core/pull/4648))
84
91
  - Previously, the build tool we used to generate JavaScript files extracted
85
92
  common code to "chunk" files. While this was intended to make this package
86
93
  more tree-shakeable, it also made debugging more difficult for our
@@ -219,7 +226,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
219
226
 
220
227
  All changes listed after this point were applied to this package following the monorepo conversion.
221
228
 
222
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/announcement-controller@8.1.0...HEAD
229
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/announcement-controller@9.0.0...HEAD
230
+ [9.0.0]: https://github.com/MetaMask/core/compare/@metamask/announcement-controller@8.1.0...@metamask/announcement-controller@9.0.0
223
231
  [8.1.0]: https://github.com/MetaMask/core/compare/@metamask/announcement-controller@8.0.0...@metamask/announcement-controller@8.1.0
224
232
  [8.0.0]: https://github.com/MetaMask/core/compare/@metamask/announcement-controller@7.1.1...@metamask/announcement-controller@8.0.0
225
233
  [7.1.1]: https://github.com/MetaMask/core/compare/@metamask/announcement-controller@7.1.0...@metamask/announcement-controller@7.1.1
@@ -2,7 +2,7 @@
2
2
  * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
- import type { AnnouncementController } from "./AnnouncementController.mjs";
5
+ import type { AnnouncementController } from './AnnouncementController.js';
6
6
  /**
7
7
  * Resets the isShown status for all announcements
8
8
  */
@@ -24,4 +24,4 @@ export type AnnouncementControllerUpdateViewedAction = {
24
24
  * Union of all AnnouncementController action types.
25
25
  */
26
26
  export type AnnouncementControllerMethodActions = AnnouncementControllerResetViewedAction | AnnouncementControllerUpdateViewedAction;
27
- //# sourceMappingURL=AnnouncementController-method-action-types.d.mts.map
27
+ //# sourceMappingURL=AnnouncementController-method-action-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnnouncementController-method-action-types.d.ts","sourceRoot":"","sources":["../src/AnnouncementController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAE1E;;GAEG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,sBAAsB,CAAC,aAAa,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,sBAAsB,CAAC,cAAc,CAAC,CAAC;CACjD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mCAAmC,GAC3C,uCAAuC,GACvC,wCAAwC,CAAC"}
@@ -3,4 +3,4 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
  export {};
6
- //# sourceMappingURL=AnnouncementController-method-action-types.mjs.map
6
+ //# sourceMappingURL=AnnouncementController-method-action-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnnouncementController-method-action-types.js","sourceRoot":"","sources":["../src/AnnouncementController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { AnnouncementController } from './AnnouncementController.js';\n\n/**\n * Resets the isShown status for all announcements\n */\nexport type AnnouncementControllerResetViewedAction = {\n type: `AnnouncementController:resetViewed`;\n handler: AnnouncementController['resetViewed'];\n};\n\n/**\n * Updates the status of the status of the specified announcements\n * once it is read by the user.\n *\n * @param viewedIds - The announcement IDs to mark as viewed.\n */\nexport type AnnouncementControllerUpdateViewedAction = {\n type: `AnnouncementController:updateViewed`;\n handler: AnnouncementController['updateViewed'];\n};\n\n/**\n * Union of all AnnouncementController action types.\n */\nexport type AnnouncementControllerMethodActions =\n | AnnouncementControllerResetViewedAction\n | AnnouncementControllerUpdateViewedAction;\n"]}
@@ -1,7 +1,7 @@
1
- import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
- import { BaseController } from "@metamask/base-controller";
3
- import type { Messenger } from "@metamask/messenger";
4
- import type { AnnouncementControllerMethodActions } from "./AnnouncementController-method-action-types.cjs";
1
+ import type { ControllerGetStateAction, ControllerStateChangeEvent } from '@metamask/base-controller';
2
+ import { BaseController } from '@metamask/base-controller';
3
+ import type { Messenger } from '@metamask/messenger';
4
+ import type { AnnouncementControllerMethodActions } from './AnnouncementController-method-action-types.js';
5
5
  type ViewedAnnouncement = {
6
6
  [id: number]: boolean;
7
7
  };
@@ -68,4 +68,4 @@ export declare class AnnouncementController extends BaseController<typeof contro
68
68
  updateViewed(viewedIds: ViewedAnnouncement): void;
69
69
  }
70
70
  export {};
71
- //# sourceMappingURL=AnnouncementController.d.cts.map
71
+ //# sourceMappingURL=AnnouncementController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnnouncementController.d.ts","sourceRoot":"","sources":["../src/AnnouncementController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EA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BAAgB,GACjB,EAAE;QACD,SAAS,EAAE,+BAA+B,CAAC;QAC3C,KAAK,CAAC,EAAE,2BAA2B,CAAC;QACpC,gBAAgB,EAAE,eAAe,CAAC;KACnC,EAQA;IAoBD;;OAEG;IACH,WAAW,IAAI,IAAI,CAMlB;IAED;;;;;OAKG;IACH,YAAY,CAAC,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAMhD;CACF"}
@@ -1,10 +1,4 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var _AnnouncementController_instances, _AnnouncementController_addAnnouncements;
7
- import { BaseController } from "@metamask/base-controller";
1
+ import { BaseController } from '@metamask/base-controller';
8
2
  const controllerName = 'AnnouncementController';
9
3
  const MESSENGER_EXPOSED_METHODS = ['resetViewed', 'updateViewed'];
10
4
  const defaultState = {
@@ -33,9 +27,23 @@ export class AnnouncementController extends BaseController {
33
27
  constructor({ messenger, state, allAnnouncements, }) {
34
28
  const mergedState = { ...defaultState, ...state };
35
29
  super({ messenger, metadata, name: controllerName, state: mergedState });
36
- _AnnouncementController_instances.add(this);
37
30
  this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
38
- __classPrivateFieldGet(this, _AnnouncementController_instances, "m", _AnnouncementController_addAnnouncements).call(this, allAnnouncements);
31
+ this.#addAnnouncements(allAnnouncements);
32
+ }
33
+ /**
34
+ * Compares the announcements in state with the announcements from file
35
+ * to check if there are any new announcements
36
+ * if yes, the new announcement will be added to the state with a flag indicating
37
+ * that the announcement is not seen by the user.
38
+ *
39
+ * @param allAnnouncements - all announcements to compare with the announcements from state
40
+ */
41
+ #addAnnouncements(allAnnouncements) {
42
+ this.update((state) => {
43
+ Object.values(allAnnouncements).forEach((announcement) => {
44
+ state.announcements[announcement.id] = state.announcements[announcement.id] ?? { ...announcement, isShown: false };
45
+ });
46
+ });
39
47
  }
40
48
  /**
41
49
  * Resets the isShown status for all announcements
@@ -61,11 +69,4 @@ export class AnnouncementController extends BaseController {
61
69
  });
62
70
  }
63
71
  }
64
- _AnnouncementController_instances = new WeakSet(), _AnnouncementController_addAnnouncements = function _AnnouncementController_addAnnouncements(allAnnouncements) {
65
- this.update((state) => {
66
- Object.values(allAnnouncements).forEach((announcement) => {
67
- state.announcements[announcement.id] = state.announcements[announcement.id] ?? { ...announcement, isShown: false };
68
- });
69
- });
70
- };
71
- //# sourceMappingURL=AnnouncementController.mjs.map
72
+ //# sourceMappingURL=AnnouncementController.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnnouncementController.js","sourceRoot":"","sources":["../src/AnnouncementController.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAsD3D,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAEhD,MAAM,yBAAyB,GAAG,CAAC,aAAa,EAAE,cAAc,CAAU,CAAC;AAE3E,MAAM,YAAY,GAAG;IACnB,aAAa,EAAE,EAAE;CAClB,CAAC;AAEF,MAAM,QAAQ,GAA+C;IAC3D,aAAa,EAAE;QACb,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAQF;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,cAI3C;IACC;;;;;;;OAOG;IACH,YAAY,EACV,SAAS,EACT,KAAK,EACL,gBAAgB,GAKjB;QACC,MAAM,WAAW,GAAG,EAAE,GAAG,YAAY,EAAE,GAAG,KAAK,EAAE,CAAC;QAClD,KAAK,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,cAAc,EAAE,KA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ateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type { AnnouncementControllerMethodActions } from './AnnouncementController-method-action-types.js';\n\ntype ViewedAnnouncement = {\n [id: number]: boolean;\n};\n\ntype Announcement = {\n id: number;\n date: string;\n};\n\n/**\n * A map of announcement ids to Announcement objects\n */\nexport type AnnouncementMap = {\n [id: number]: Announcement;\n};\n\ntype StateAnnouncement = Announcement & { isShown: boolean };\n\n/**\n * A map of announcement ids to StateAnnouncement objects\n */\nexport type StateAnnouncementMap = {\n [id: number]: StateAnnouncement;\n};\n\n/**\n * Announcement state will hold all the seen and unseen announcements\n * that are still active\n */\nexport type AnnouncementControllerState = {\n announcements: StateAnnouncementMap;\n};\n\nexport type AnnouncementControllerActions =\n | AnnouncementControllerGetStateAction\n | AnnouncementControllerMethodActions;\nexport type AnnouncementControllerEvents =\n AnnouncementControllerStateChangeEvent;\n\nexport type AnnouncementControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AnnouncementControllerState\n>;\n\nexport type AnnouncementControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AnnouncementControllerState\n>;\n\nconst controllerName = 'AnnouncementController';\n\nconst MESSENGER_EXPOSED_METHODS = ['resetViewed', 'updateViewed'] as const;\n\nconst defaultState = {\n announcements: {},\n};\n\nconst metadata: StateMetadata<AnnouncementControllerState> = {\n announcements: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n};\n\nexport type AnnouncementControllerMessenger = Messenger<\n typeof controllerName,\n AnnouncementControllerActions,\n AnnouncementControllerEvents\n>;\n\n/**\n * Controller for managing in-app announcements.\n */\nexport class AnnouncementController extends BaseController<\n typeof controllerName,\n AnnouncementControllerState,\n AnnouncementControllerMessenger\n> {\n /**\n * Creates a AnnouncementController instance.\n *\n * @param args - The arguments to this function.\n * @param args.messenger - Messenger used to communicate with BaseV2 controller.\n * @param args.state - Initial state to set on this controller.\n * @param args.allAnnouncements - Announcements to be passed through to #addAnnouncements\n */\n constructor({\n messenger,\n state,\n allAnnouncements,\n }: {\n messenger: AnnouncementControllerMessenger;\n state?: AnnouncementControllerState;\n allAnnouncements: AnnouncementMap;\n }) {\n const mergedState = { ...defaultState, ...state };\n super({ messenger, metadata, name: controllerName, state: mergedState });\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n this.#addAnnouncements(allAnnouncements);\n }\n\n /**\n * Compares the announcements in state with the announcements from file\n * to check if there are any new announcements\n * if yes, the new announcement will be added to the state with a flag indicating\n * that the announcement is not seen by the user.\n *\n * @param allAnnouncements - all announcements to compare with the announcements from state\n */\n #addAnnouncements(allAnnouncements: AnnouncementMap): void {\n this.update((state) => {\n Object.values(allAnnouncements).forEach((announcement: Announcement) => {\n state.announcements[announcement.id] = state.announcements[\n announcement.id\n ] ?? { ...announcement, isShown: false };\n });\n });\n }\n\n /**\n * Resets the isShown status for all announcements\n */\n resetViewed(): void {\n this.update(({ announcements }) => {\n for (const announcement of Object.values(announcements)) {\n announcement.isShown = false;\n }\n });\n }\n\n /**\n * Updates the status of the status of the specified announcements\n * once it is read by the user.\n *\n * @param viewedIds - The announcement IDs to mark as viewed.\n */\n updateViewed(viewedIds: ViewedAnnouncement): void {\n this.update(({ announcements }) => {\n for (const id of Object.keys(viewedIds).map(Number)) {\n announcements[id].isShown = viewedIds[id];\n }\n });\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- export type { AnnouncementControllerResetViewedAction, AnnouncementControllerUpdateViewedAction, } from "./AnnouncementController-method-action-types.cjs";
2
- export type { AnnouncementMap, StateAnnouncementMap, AnnouncementControllerState, AnnouncementControllerActions, AnnouncementControllerEvents, AnnouncementControllerGetStateAction, AnnouncementControllerStateChangeEvent, AnnouncementControllerMessenger, } from "./AnnouncementController.cjs";
3
- export { AnnouncementController } from "./AnnouncementController.cjs";
4
- //# sourceMappingURL=index.d.cts.map
1
+ export type { AnnouncementControllerResetViewedAction, AnnouncementControllerUpdateViewedAction, } from './AnnouncementController-method-action-types.js';
2
+ export type { AnnouncementMap, StateAnnouncementMap, AnnouncementControllerState, AnnouncementControllerActions, AnnouncementControllerEvents, AnnouncementControllerGetStateAction, AnnouncementControllerStateChangeEvent, AnnouncementControllerMessenger, } from './AnnouncementController.js';
3
+ export { AnnouncementController } from './AnnouncementController.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,uCAAuC,EACvC,wCAAwC,GACzC,MAAM,iDAAiD,CAAC;AACzD,YAAY,EACV,eAAe,EACf,oBAAoB,EACpB,2BAA2B,EAC3B,6BAA6B,EAC7B,4BAA4B,EAC5B,oCAAoC,EACpC,sCAAsC,EACtC,+BAA+B,GAChC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { AnnouncementController } from './AnnouncementController.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC","sourcesContent":["export type {\n AnnouncementControllerResetViewedAction,\n AnnouncementControllerUpdateViewedAction,\n} from './AnnouncementController-method-action-types.js';\nexport type {\n AnnouncementMap,\n StateAnnouncementMap,\n AnnouncementControllerState,\n AnnouncementControllerActions,\n AnnouncementControllerEvents,\n AnnouncementControllerGetStateAction,\n AnnouncementControllerStateChangeEvent,\n AnnouncementControllerMessenger,\n} from './AnnouncementController.js';\nexport { AnnouncementController } from './AnnouncementController.js';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/announcement-controller",
3
- "version": "8.1.0-preview-8bfa290fb",
3
+ "version": "9.0.0-preview-0a30e47",
4
4
  "description": "Manages in-app announcements",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -18,19 +18,12 @@
18
18
  "files": [
19
19
  "dist/"
20
20
  ],
21
+ "type": "module",
21
22
  "sideEffects": false,
22
- "main": "./dist/index.cjs",
23
- "types": "./dist/index.d.cts",
24
23
  "exports": {
25
24
  ".": {
26
- "import": {
27
- "types": "./dist/index.d.mts",
28
- "default": "./dist/index.mjs"
29
- },
30
- "require": {
31
- "types": "./dist/index.d.cts",
32
- "default": "./dist/index.cjs"
33
- }
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
34
27
  },
35
28
  "./package.json": "./package.json"
36
29
  },
@@ -39,9 +32,11 @@
39
32
  "registry": "https://registry.npmjs.org/"
40
33
  },
41
34
  "scripts": {
42
- "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
43
- "build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
35
+ "build": "tsc --project tsconfig.build.json",
36
+ "build:all": "tsc --build tsconfig.build.json --verbose",
37
+ "build:clean": "yarn build:only-clean && yarn build",
44
38
  "build:docs": "typedoc",
39
+ "build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
45
40
  "changelog:update": "../../scripts/update-changelog.sh @metamask/announcement-controller",
46
41
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/announcement-controller",
47
42
  "lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
@@ -55,22 +50,23 @@
55
50
  "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
56
51
  },
57
52
  "dependencies": {
58
- "@metamask/base-controller": "^9.1.0",
59
- "@metamask/messenger": "^2.0.0"
53
+ "@metamask/base-controller": "^10.0.0",
54
+ "@metamask/messenger": "^3.0.0"
60
55
  },
61
56
  "devDependencies": {
62
57
  "@metamask/auto-changelog": "^6.1.0",
63
- "@ts-bridge/cli": "^0.6.4",
64
58
  "@types/jest": "^30.0.0",
59
+ "@typescript/native": "npm:typescript@^7.0.2",
65
60
  "deepmerge": "^4.2.2",
66
61
  "jest": "^30.4.2",
62
+ "rimraf": "^5.0.5",
67
63
  "ts-jest": "^29.4.11",
68
64
  "tsx": "^4.20.5",
69
65
  "typedoc": "^0.25.13",
70
66
  "typedoc-plugin-missing-exports": "^2.0.0",
71
- "typescript": "~5.3.3"
67
+ "typescript": "npm:@typescript/typescript6@^6.0.2"
72
68
  },
73
69
  "engines": {
74
- "node": "^18.18 || >=20"
70
+ "node": "^22.14.0 || ^24"
75
71
  }
76
72
  }
@@ -1,7 +0,0 @@
1
- "use strict";
2
- /**
3
- * This file is auto generated.
4
- * Do not edit manually.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- //# sourceMappingURL=AnnouncementController-method-action-types.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AnnouncementController-method-action-types.cjs","sourceRoot":"","sources":["../src/AnnouncementController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { AnnouncementController } from './AnnouncementController.js';\n\n/**\n * Resets the isShown status for all announcements\n */\nexport type AnnouncementControllerResetViewedAction = {\n type: `AnnouncementController:resetViewed`;\n handler: AnnouncementController['resetViewed'];\n};\n\n/**\n * Updates the status of the status of the specified announcements\n * once it is read by the user.\n *\n * @param viewedIds - The announcement IDs to mark as viewed.\n */\nexport type AnnouncementControllerUpdateViewedAction = {\n type: `AnnouncementController:updateViewed`;\n handler: AnnouncementController['updateViewed'];\n};\n\n/**\n * Union of all AnnouncementController action types.\n */\nexport type AnnouncementControllerMethodActions =\n | AnnouncementControllerResetViewedAction\n | AnnouncementControllerUpdateViewedAction;\n"]}
@@ -1,27 +0,0 @@
1
- /**
2
- * This file is auto generated.
3
- * Do not edit manually.
4
- */
5
- import type { AnnouncementController } from "./AnnouncementController.cjs";
6
- /**
7
- * Resets the isShown status for all announcements
8
- */
9
- export type AnnouncementControllerResetViewedAction = {
10
- type: `AnnouncementController:resetViewed`;
11
- handler: AnnouncementController['resetViewed'];
12
- };
13
- /**
14
- * Updates the status of the status of the specified announcements
15
- * once it is read by the user.
16
- *
17
- * @param viewedIds - The announcement IDs to mark as viewed.
18
- */
19
- export type AnnouncementControllerUpdateViewedAction = {
20
- type: `AnnouncementController:updateViewed`;
21
- handler: AnnouncementController['updateViewed'];
22
- };
23
- /**
24
- * Union of all AnnouncementController action types.
25
- */
26
- export type AnnouncementControllerMethodActions = AnnouncementControllerResetViewedAction | AnnouncementControllerUpdateViewedAction;
27
- //# sourceMappingURL=AnnouncementController-method-action-types.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AnnouncementController-method-action-types.d.cts","sourceRoot":"","sources":["../src/AnnouncementController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,qCAAoC;AAE1E;;GAEG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,sBAAsB,CAAC,aAAa,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,sBAAsB,CAAC,cAAc,CAAC,CAAC;CACjD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mCAAmC,GAC3C,uCAAuC,GACvC,wCAAwC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"AnnouncementController-method-action-types.d.mts","sourceRoot":"","sources":["../src/AnnouncementController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,qCAAoC;AAE1E;;GAEG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,sBAAsB,CAAC,aAAa,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,sBAAsB,CAAC,cAAc,CAAC,CAAC;CACjD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mCAAmC,GAC3C,uCAAuC,GACvC,wCAAwC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"AnnouncementController-method-action-types.mjs","sourceRoot":"","sources":["../src/AnnouncementController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { AnnouncementController } from './AnnouncementController.js';\n\n/**\n * Resets the isShown status for all announcements\n */\nexport type AnnouncementControllerResetViewedAction = {\n type: `AnnouncementController:resetViewed`;\n handler: AnnouncementController['resetViewed'];\n};\n\n/**\n * Updates the status of the status of the specified announcements\n * once it is read by the user.\n *\n * @param viewedIds - The announcement IDs to mark as viewed.\n */\nexport type AnnouncementControllerUpdateViewedAction = {\n type: `AnnouncementController:updateViewed`;\n handler: AnnouncementController['updateViewed'];\n};\n\n/**\n * Union of all AnnouncementController action types.\n */\nexport type AnnouncementControllerMethodActions =\n | AnnouncementControllerResetViewedAction\n | AnnouncementControllerUpdateViewedAction;\n"]}
@@ -1,75 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
- };
7
- var _AnnouncementController_instances, _AnnouncementController_addAnnouncements;
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.AnnouncementController = void 0;
10
- const base_controller_1 = require("@metamask/base-controller");
11
- const controllerName = 'AnnouncementController';
12
- const MESSENGER_EXPOSED_METHODS = ['resetViewed', 'updateViewed'];
13
- const defaultState = {
14
- announcements: {},
15
- };
16
- const metadata = {
17
- announcements: {
18
- includeInStateLogs: true,
19
- persist: true,
20
- includeInDebugSnapshot: true,
21
- usedInUi: true,
22
- },
23
- };
24
- /**
25
- * Controller for managing in-app announcements.
26
- */
27
- class AnnouncementController extends base_controller_1.BaseController {
28
- /**
29
- * Creates a AnnouncementController instance.
30
- *
31
- * @param args - The arguments to this function.
32
- * @param args.messenger - Messenger used to communicate with BaseV2 controller.
33
- * @param args.state - Initial state to set on this controller.
34
- * @param args.allAnnouncements - Announcements to be passed through to #addAnnouncements
35
- */
36
- constructor({ messenger, state, allAnnouncements, }) {
37
- const mergedState = { ...defaultState, ...state };
38
- super({ messenger, metadata, name: controllerName, state: mergedState });
39
- _AnnouncementController_instances.add(this);
40
- this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
41
- __classPrivateFieldGet(this, _AnnouncementController_instances, "m", _AnnouncementController_addAnnouncements).call(this, allAnnouncements);
42
- }
43
- /**
44
- * Resets the isShown status for all announcements
45
- */
46
- resetViewed() {
47
- this.update(({ announcements }) => {
48
- for (const announcement of Object.values(announcements)) {
49
- announcement.isShown = false;
50
- }
51
- });
52
- }
53
- /**
54
- * Updates the status of the status of the specified announcements
55
- * once it is read by the user.
56
- *
57
- * @param viewedIds - The announcement IDs to mark as viewed.
58
- */
59
- updateViewed(viewedIds) {
60
- this.update(({ announcements }) => {
61
- for (const id of Object.keys(viewedIds).map(Number)) {
62
- announcements[id].isShown = viewedIds[id];
63
- }
64
- });
65
- }
66
- }
67
- exports.AnnouncementController = AnnouncementController;
68
- _AnnouncementController_instances = new WeakSet(), _AnnouncementController_addAnnouncements = function _AnnouncementController_addAnnouncements(allAnnouncements) {
69
- this.update((state) => {
70
- Object.values(allAnnouncements).forEach((announcement) => {
71
- state.announcements[announcement.id] = state.announcements[announcement.id] ?? { ...announcement, isShown: false };
72
- });
73
- });
74
- };
75
- //# sourceMappingURL=AnnouncementController.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AnnouncementController.cjs","sourceRoot":"","sources":["../src/AnnouncementController.ts"],"names":[],"mappings":";;;;;;;;;AAKA,+DAA2D;AAsD3D,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAEhD,MAAM,yBAAyB,GAAG,CAAC,aAAa,EAAE,cAAc,CAAU,CAAC;AAE3E,MAAM,YAAY,GAAG;IACnB,aAAa,EAAE,EAAE;CAClB,CAAC;AAEF,MAAM,QAAQ,GAA+C;IAC3D,aAAa,EAAE;QACb,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAQF;;GAEG;AACH,MAAa,sBAAuB,SAAQ,gCAI3C;IACC;;;;;;;OAOG;IACH,YAAY,EACV,SAAS,EACT,KAAK,EACL,gBAAgB,GAKjB;QACC,MAAM,WAAW,GAAG,EAAE,GAAG,YAAY,EAAE,GAAG,KAAK,EAAE,CAAC;QAClD,KAAK,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;;QACzE,IAAI,CAAC,SAAS,CAAC,4BAA4B,CACzC,IAAI,EACJ,yBAAyB,CAC1B,CAAC;QACF,uBAAA,IAAI,mFAAkB,MAAtB,IAAI,EAAmB,gBAAgB,CAAC,CAAC;IAC3C,CAAC;IAoBD;;OAEG;IACH,WAAW;QACT,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,aAAa,EAAE,EAAE,EAAE;YAChC,KAAK,MAAM,YAAY,IAAI,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;gBACxD,YAAY,CAAC,OAAO,GAAG,KAAK,CAAC;YAC/B,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,YAAY,CAAC,SAA6B;QACxC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,aAAa,EAAE,EAAE,EAAE;YAChC,KAAK,MAAM,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;gBACpD,aAAa,CAAC,EAAE,CAAC,CAAC,OAAO,GAAG,SAAS,CAAC,EAAE,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAzED,wDAyEC;gJAlCmB,gBAAiC;IACjD,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QACpB,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC,CAAC,YAA0B,EAAE,EAAE;YACrE,KAAK,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,aAAa,CACxD,YAAY,CAAC,EAAE,CAChB,IAAI,EAAE,GAAG,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type { AnnouncementControllerMethodActions } from './AnnouncementController-method-action-types.js';\n\ntype ViewedAnnouncement = {\n [id: number]: boolean;\n};\n\ntype Announcement = {\n id: number;\n date: string;\n};\n\n/**\n * A map of announcement ids to Announcement objects\n */\nexport type AnnouncementMap = {\n [id: number]: Announcement;\n};\n\ntype StateAnnouncement = Announcement & { isShown: boolean };\n\n/**\n * A map of announcement ids to StateAnnouncement objects\n */\nexport type StateAnnouncementMap = {\n [id: number]: StateAnnouncement;\n};\n\n/**\n * Announcement state will hold all the seen and unseen announcements\n * that are still active\n */\nexport type AnnouncementControllerState = {\n announcements: StateAnnouncementMap;\n};\n\nexport type AnnouncementControllerActions =\n | AnnouncementControllerGetStateAction\n | AnnouncementControllerMethodActions;\nexport type AnnouncementControllerEvents =\n AnnouncementControllerStateChangeEvent;\n\nexport type AnnouncementControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AnnouncementControllerState\n>;\n\nexport type AnnouncementControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AnnouncementControllerState\n>;\n\nconst controllerName = 'AnnouncementController';\n\nconst MESSENGER_EXPOSED_METHODS = ['resetViewed', 'updateViewed'] as const;\n\nconst defaultState = {\n announcements: {},\n};\n\nconst metadata: StateMetadata<AnnouncementControllerState> = {\n announcements: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n};\n\nexport type AnnouncementControllerMessenger = Messenger<\n typeof controllerName,\n AnnouncementControllerActions,\n AnnouncementControllerEvents\n>;\n\n/**\n * Controller for managing in-app announcements.\n */\nexport class AnnouncementController extends BaseController<\n typeof controllerName,\n AnnouncementControllerState,\n AnnouncementControllerMessenger\n> {\n /**\n * Creates a AnnouncementController instance.\n *\n * @param args - The arguments to this function.\n * @param args.messenger - Messenger used to communicate with BaseV2 controller.\n * @param args.state - Initial state to set on this controller.\n * @param args.allAnnouncements - Announcements to be passed through to #addAnnouncements\n */\n constructor({\n messenger,\n state,\n allAnnouncements,\n }: {\n messenger: AnnouncementControllerMessenger;\n state?: AnnouncementControllerState;\n allAnnouncements: AnnouncementMap;\n }) {\n const mergedState = { ...defaultState, ...state };\n super({ messenger, metadata, name: controllerName, state: mergedState });\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n this.#addAnnouncements(allAnnouncements);\n }\n\n /**\n * Compares the announcements in state with the announcements from file\n * to check if there are any new announcements\n * if yes, the new announcement will be added to the state with a flag indicating\n * that the announcement is not seen by the user.\n *\n * @param allAnnouncements - all announcements to compare with the announcements from state\n */\n #addAnnouncements(allAnnouncements: AnnouncementMap): void {\n this.update((state) => {\n Object.values(allAnnouncements).forEach((announcement: Announcement) => {\n state.announcements[announcement.id] = state.announcements[\n announcement.id\n ] ?? { ...announcement, isShown: false };\n });\n });\n }\n\n /**\n * Resets the isShown status for all announcements\n */\n resetViewed(): void {\n this.update(({ announcements }) => {\n for (const announcement of Object.values(announcements)) {\n announcement.isShown = false;\n }\n });\n }\n\n /**\n * Updates the status of the status of the specified announcements\n * once it is read by the user.\n *\n * @param viewedIds - The announcement IDs to mark as viewed.\n */\n updateViewed(viewedIds: ViewedAnnouncement): void {\n this.update(({ announcements }) => {\n for (const id of Object.keys(viewedIds).map(Number)) {\n announcements[id].isShown = viewedIds[id];\n }\n });\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"AnnouncementController.d.cts","sourceRoot":"","sources":["../src/AnnouncementController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,mCAAmC,EAAE,yDAAwD;AAE3G,KAAK,kBAAkB,GAAG;IACxB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB,CAAC;AAEF,KAAK,YAAY,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,CAAC,EAAE,EAAE,MAAM,GAAG,YAAY,CAAC;CAC5B,CAAC;AAEF,KAAK,iBAAiB,GAAG,YAAY,GAAG;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,CAAC,EAAE,EAAE,MAAM,GAAG,iBAAiB,CAAC;CACjC,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC,aAAa,EAAE,oBAAoB,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,6BAA6B,GACrC,oCAAoC,GACpC,mCAAmC,CAAC;AACxC,MAAM,MAAM,4BAA4B,GACtC,sCAAsC,CAAC;AAEzC,MAAM,MAAM,oCAAoC,GAAG,wBAAwB,CACzE,OAAO,cAAc,EACrB,2BAA2B,CAC5B,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG,0BAA0B,CAC7E,OAAO,cAAc,EACrB,2BAA2B,CAC5B,CAAC;AAEF,QAAA,MAAM,cAAc,2BAA2B,CAAC;AAiBhD,MAAM,MAAM,+BAA+B,GAAG,SAAS,CACrD,OAAO,cAAc,EACrB,6BAA6B,EAC7B,4BAA4B,CAC7B,CAAC;AAEF;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,cAAc,CACxD,OAAO,cAAc,EACrB,2BAA2B,EAC3B,+BAA+B,CAChC;;IACC;;;;;;;OAOG;gBACS,EACV,SAAS,EACT,KAAK,EACL,gBAAgB,GACjB,EAAE;QACD,SAAS,EAAE,+BAA+B,CAAC;QAC3C,KAAK,CAAC,EAAE,2BAA2B,CAAC;QACpC,gBAAgB,EAAE,eAAe,CAAC;KACnC;IA4BD;;OAEG;IACH,WAAW,IAAI,IAAI;IAQnB;;;;;OAKG;IACH,YAAY,CAAC,SAAS,EAAE,kBAAkB,GAAG,IAAI;CAOlD"}
@@ -1,71 +0,0 @@
1
- import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
- import { BaseController } from "@metamask/base-controller";
3
- import type { Messenger } from "@metamask/messenger";
4
- import type { AnnouncementControllerMethodActions } from "./AnnouncementController-method-action-types.mjs";
5
- type ViewedAnnouncement = {
6
- [id: number]: boolean;
7
- };
8
- type Announcement = {
9
- id: number;
10
- date: string;
11
- };
12
- /**
13
- * A map of announcement ids to Announcement objects
14
- */
15
- export type AnnouncementMap = {
16
- [id: number]: Announcement;
17
- };
18
- type StateAnnouncement = Announcement & {
19
- isShown: boolean;
20
- };
21
- /**
22
- * A map of announcement ids to StateAnnouncement objects
23
- */
24
- export type StateAnnouncementMap = {
25
- [id: number]: StateAnnouncement;
26
- };
27
- /**
28
- * Announcement state will hold all the seen and unseen announcements
29
- * that are still active
30
- */
31
- export type AnnouncementControllerState = {
32
- announcements: StateAnnouncementMap;
33
- };
34
- export type AnnouncementControllerActions = AnnouncementControllerGetStateAction | AnnouncementControllerMethodActions;
35
- export type AnnouncementControllerEvents = AnnouncementControllerStateChangeEvent;
36
- export type AnnouncementControllerGetStateAction = ControllerGetStateAction<typeof controllerName, AnnouncementControllerState>;
37
- export type AnnouncementControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, AnnouncementControllerState>;
38
- declare const controllerName = "AnnouncementController";
39
- export type AnnouncementControllerMessenger = Messenger<typeof controllerName, AnnouncementControllerActions, AnnouncementControllerEvents>;
40
- /**
41
- * Controller for managing in-app announcements.
42
- */
43
- export declare class AnnouncementController extends BaseController<typeof controllerName, AnnouncementControllerState, AnnouncementControllerMessenger> {
44
- #private;
45
- /**
46
- * Creates a AnnouncementController instance.
47
- *
48
- * @param args - The arguments to this function.
49
- * @param args.messenger - Messenger used to communicate with BaseV2 controller.
50
- * @param args.state - Initial state to set on this controller.
51
- * @param args.allAnnouncements - Announcements to be passed through to #addAnnouncements
52
- */
53
- constructor({ messenger, state, allAnnouncements, }: {
54
- messenger: AnnouncementControllerMessenger;
55
- state?: AnnouncementControllerState;
56
- allAnnouncements: AnnouncementMap;
57
- });
58
- /**
59
- * Resets the isShown status for all announcements
60
- */
61
- resetViewed(): void;
62
- /**
63
- * Updates the status of the status of the specified announcements
64
- * once it is read by the user.
65
- *
66
- * @param viewedIds - The announcement IDs to mark as viewed.
67
- */
68
- updateViewed(viewedIds: ViewedAnnouncement): void;
69
- }
70
- export {};
71
- //# sourceMappingURL=AnnouncementController.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AnnouncementController.d.mts","sourceRoot":"","sources":["../src/AnnouncementController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,mCAAmC,EAAE,yDAAwD;AAE3G,KAAK,kBAAkB,GAAG;IACxB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB,CAAC;AAEF,KAAK,YAAY,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,CAAC,EAAE,EAAE,MAAM,GAAG,YAAY,CAAC;CAC5B,CAAC;AAEF,KAAK,iBAAiB,GAAG,YAAY,GAAG;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,CAAC,EAAE,EAAE,MAAM,GAAG,iBAAiB,CAAC;CACjC,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC,aAAa,EAAE,oBAAoB,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,6BAA6B,GACrC,oCAAoC,GACpC,mCAAmC,CAAC;AACxC,MAAM,MAAM,4BAA4B,GACtC,sCAAsC,CAAC;AAEzC,MAAM,MAAM,oCAAoC,GAAG,wBAAwB,CACzE,OAAO,cAAc,EACrB,2BAA2B,CAC5B,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG,0BAA0B,CAC7E,OAAO,cAAc,EACrB,2BAA2B,CAC5B,CAAC;AAEF,QAAA,MAAM,cAAc,2BAA2B,CAAC;AAiBhD,MAAM,MAAM,+BAA+B,GAAG,SAAS,CACrD,OAAO,cAAc,EACrB,6BAA6B,EAC7B,4BAA4B,CAC7B,CAAC;AAEF;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,cAAc,CACxD,OAAO,cAAc,EACrB,2BAA2B,EAC3B,+BAA+B,CAChC;;IACC;;;;;;;OAOG;gBACS,EACV,SAAS,EACT,KAAK,EACL,gBAAgB,GACjB,EAAE;QACD,SAAS,EAAE,+BAA+B,CAAC;QAC3C,KAAK,CAAC,EAAE,2BAA2B,CAAC;QACpC,gBAAgB,EAAE,eAAe,CAAC;KACnC;IA4BD;;OAEG;IACH,WAAW,IAAI,IAAI;IAQnB;;;;;OAKG;IACH,YAAY,CAAC,SAAS,EAAE,kBAAkB,GAAG,IAAI;CAOlD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"AnnouncementController.mjs","sourceRoot":"","sources":["../src/AnnouncementController.ts"],"names":[],"mappings":";;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAsD3D,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAEhD,MAAM,yBAAyB,GAAG,CAAC,aAAa,EAAE,cAAc,CAAU,CAAC;AAE3E,MAAM,YAAY,GAAG;IACnB,aAAa,EAAE,EAAE;CAClB,CAAC;AAEF,MAAM,QAAQ,GAA+C;IAC3D,aAAa,EAAE;QACb,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAQF;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,cAI3C;IACC;;;;;;;OAOG;IACH,YAAY,EACV,SAAS,EACT,KAAK,EACL,gBAAgB,GAKjB;QACC,MAAM,WAAW,GAAG,EAAE,GAAG,YAAY,EAAE,GAAG,KAAK,EAAE,CAAC;QAClD,KAAK,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,WAAW,EAAE,C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base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type { AnnouncementControllerMethodActions } from './AnnouncementController-method-action-types.js';\n\ntype ViewedAnnouncement = {\n [id: number]: boolean;\n};\n\ntype Announcement = {\n id: number;\n date: string;\n};\n\n/**\n * A map of announcement ids to Announcement objects\n */\nexport type AnnouncementMap = {\n [id: number]: Announcement;\n};\n\ntype StateAnnouncement = Announcement & { isShown: boolean };\n\n/**\n * A map of announcement ids to StateAnnouncement objects\n */\nexport type StateAnnouncementMap = {\n [id: number]: StateAnnouncement;\n};\n\n/**\n * Announcement state will hold all the seen and unseen announcements\n * that are still active\n */\nexport type AnnouncementControllerState = {\n announcements: StateAnnouncementMap;\n};\n\nexport type AnnouncementControllerActions =\n | AnnouncementControllerGetStateAction\n | AnnouncementControllerMethodActions;\nexport type AnnouncementControllerEvents =\n AnnouncementControllerStateChangeEvent;\n\nexport type AnnouncementControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AnnouncementControllerState\n>;\n\nexport type AnnouncementControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AnnouncementControllerState\n>;\n\nconst controllerName = 'AnnouncementController';\n\nconst MESSENGER_EXPOSED_METHODS = ['resetViewed', 'updateViewed'] as const;\n\nconst defaultState = {\n announcements: {},\n};\n\nconst metadata: StateMetadata<AnnouncementControllerState> = {\n announcements: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n};\n\nexport type AnnouncementControllerMessenger = Messenger<\n typeof controllerName,\n AnnouncementControllerActions,\n AnnouncementControllerEvents\n>;\n\n/**\n * Controller for managing in-app announcements.\n */\nexport class AnnouncementController extends BaseController<\n typeof controllerName,\n AnnouncementControllerState,\n AnnouncementControllerMessenger\n> {\n /**\n * Creates a AnnouncementController instance.\n *\n * @param args - The arguments to this function.\n * @param args.messenger - Messenger used to communicate with BaseV2 controller.\n * @param args.state - Initial state to set on this controller.\n * @param args.allAnnouncements - Announcements to be passed through to #addAnnouncements\n */\n constructor({\n messenger,\n state,\n allAnnouncements,\n }: {\n messenger: AnnouncementControllerMessenger;\n state?: AnnouncementControllerState;\n allAnnouncements: AnnouncementMap;\n }) {\n const mergedState = { ...defaultState, ...state };\n super({ messenger, metadata, name: controllerName, state: mergedState });\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n this.#addAnnouncements(allAnnouncements);\n }\n\n /**\n * Compares the announcements in state with the announcements from file\n * to check if there are any new announcements\n * if yes, the new announcement will be added to the state with a flag indicating\n * that the announcement is not seen by the user.\n *\n * @param allAnnouncements - all announcements to compare with the announcements from state\n */\n #addAnnouncements(allAnnouncements: AnnouncementMap): void {\n this.update((state) => {\n Object.values(allAnnouncements).forEach((announcement: Announcement) => {\n state.announcements[announcement.id] = state.announcements[\n announcement.id\n ] ?? { ...announcement, isShown: false };\n });\n });\n }\n\n /**\n * Resets the isShown status for all announcements\n */\n resetViewed(): void {\n this.update(({ announcements }) => {\n for (const announcement of Object.values(announcements)) {\n announcement.isShown = false;\n }\n });\n }\n\n /**\n * Updates the status of the status of the specified announcements\n * once it is read by the user.\n *\n * @param viewedIds - The announcement IDs to mark as viewed.\n */\n updateViewed(viewedIds: ViewedAnnouncement): void {\n this.update(({ announcements }) => {\n for (const id of Object.keys(viewedIds).map(Number)) {\n announcements[id].isShown = viewedIds[id];\n }\n });\n }\n}\n"]}
package/dist/index.cjs DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AnnouncementController = void 0;
4
- var AnnouncementController_js_1 = require("./AnnouncementController.cjs");
5
- Object.defineProperty(exports, "AnnouncementController", { enumerable: true, get: function () { return AnnouncementController_js_1.AnnouncementController; } });
6
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAcA,0EAAqE;AAA5D,mIAAA,sBAAsB,OAAA","sourcesContent":["export type {\n AnnouncementControllerResetViewedAction,\n AnnouncementControllerUpdateViewedAction,\n} from './AnnouncementController-method-action-types.js';\nexport type {\n AnnouncementMap,\n StateAnnouncementMap,\n AnnouncementControllerState,\n AnnouncementControllerActions,\n AnnouncementControllerEvents,\n AnnouncementControllerGetStateAction,\n AnnouncementControllerStateChangeEvent,\n AnnouncementControllerMessenger,\n} from './AnnouncementController.js';\nexport { AnnouncementController } from './AnnouncementController.js';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,uCAAuC,EACvC,wCAAwC,GACzC,yDAAwD;AACzD,YAAY,EACV,eAAe,EACf,oBAAoB,EACpB,2BAA2B,EAC3B,6BAA6B,EAC7B,4BAA4B,EAC5B,oCAAoC,EACpC,sCAAsC,EACtC,+BAA+B,GAChC,qCAAoC;AACrC,OAAO,EAAE,sBAAsB,EAAE,qCAAoC"}
package/dist/index.d.mts DELETED
@@ -1,4 +0,0 @@
1
- export type { AnnouncementControllerResetViewedAction, AnnouncementControllerUpdateViewedAction, } from "./AnnouncementController-method-action-types.mjs";
2
- export type { AnnouncementMap, StateAnnouncementMap, AnnouncementControllerState, AnnouncementControllerActions, AnnouncementControllerEvents, AnnouncementControllerGetStateAction, AnnouncementControllerStateChangeEvent, AnnouncementControllerMessenger, } from "./AnnouncementController.mjs";
3
- export { AnnouncementController } from "./AnnouncementController.mjs";
4
- //# sourceMappingURL=index.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,uCAAuC,EACvC,wCAAwC,GACzC,yDAAwD;AACzD,YAAY,EACV,eAAe,EACf,oBAAoB,EACpB,2BAA2B,EAC3B,6BAA6B,EAC7B,4BAA4B,EAC5B,oCAAoC,EACpC,sCAAsC,EACtC,+BAA+B,GAChC,qCAAoC;AACrC,OAAO,EAAE,sBAAsB,EAAE,qCAAoC"}
package/dist/index.mjs DELETED
@@ -1,2 +0,0 @@
1
- export { AnnouncementController } from "./AnnouncementController.mjs";
2
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,sBAAsB,EAAE,qCAAoC","sourcesContent":["export type {\n AnnouncementControllerResetViewedAction,\n AnnouncementControllerUpdateViewedAction,\n} from './AnnouncementController-method-action-types.js';\nexport type {\n AnnouncementMap,\n StateAnnouncementMap,\n AnnouncementControllerState,\n AnnouncementControllerActions,\n AnnouncementControllerEvents,\n AnnouncementControllerGetStateAction,\n AnnouncementControllerStateChangeEvent,\n AnnouncementControllerMessenger,\n} from './AnnouncementController.js';\nexport { AnnouncementController } from './AnnouncementController.js';\n"]}