@metamask-previews/announcement-controller 8.0.0-preview-6cb7e4bcf → 8.0.0-preview-3685bfb

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Added
11
+
12
+ - Expose `AnnouncementController` methods through its messenger ([#8206](https://github.com/MetaMask/core/pull/8206))
13
+ - The following actions are now available:
14
+ - `AnnouncementController:resetViewed`
15
+ - `AnnouncementController:updateViewed`
16
+ - Corresponding action types (e.g. `AnnouncementControllerResetViewedAction`) are available as well.
17
+
10
18
  ## [8.0.0]
11
19
 
12
20
  ### Changed
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * This file is auto generated by `scripts/generate-method-action-types.ts`.
4
+ * Do not edit manually.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=AnnouncementController-method-action-types.cjs.map
@@ -0,0 +1 @@
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 by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { AnnouncementController } from './AnnouncementController';\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"]}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * This file is auto generated by `scripts/generate-method-action-types.ts`.
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
@@ -0,0 +1 @@
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,qCAAiC;AAEvE;;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"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * This file is auto generated by `scripts/generate-method-action-types.ts`.
3
+ * Do not edit manually.
4
+ */
5
+ import type { AnnouncementController } from "./AnnouncementController.mjs";
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.mts.map
@@ -0,0 +1 @@
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,qCAAiC;AAEvE;;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"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This file is auto generated by `scripts/generate-method-action-types.ts`.
3
+ * Do not edit manually.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=AnnouncementController-method-action-types.mjs.map
@@ -0,0 +1 @@
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 by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { AnnouncementController } from './AnnouncementController';\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"]}
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.AnnouncementController = void 0;
10
10
  const base_controller_1 = require("@metamask/base-controller");
11
11
  const controllerName = 'AnnouncementController';
12
+ const MESSENGER_EXPOSED_METHODS = ['resetViewed', 'updateViewed'];
12
13
  const defaultState = {
13
14
  announcements: {},
14
15
  };
@@ -36,6 +37,7 @@ class AnnouncementController extends base_controller_1.BaseController {
36
37
  const mergedState = { ...defaultState, ...state };
37
38
  super({ messenger, metadata, name: controllerName, state: mergedState });
38
39
  _AnnouncementController_instances.add(this);
40
+ this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
39
41
  __classPrivateFieldGet(this, _AnnouncementController_instances, "m", _AnnouncementController_addAnnouncements).call(this, allAnnouncements);
40
42
  }
41
43
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"AnnouncementController.cjs","sourceRoot":"","sources":["../src/AnnouncementController.ts"],"names":[],"mappings":";;;;;;;;;AAKA,+DAA2D;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AC;IACL,CAAC;CACF;AArED,wDAqEC;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\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;\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 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.#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
+ {"version":3,"file":"AnnouncementController.cjs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AAK,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';\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,6 +1,7 @@
1
1
  import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
2
  import { BaseController } from "@metamask/base-controller";
3
3
  import type { Messenger } from "@metamask/messenger";
4
+ import type { AnnouncementControllerMethodActions } from "./AnnouncementController-method-action-types.cjs";
4
5
  type ViewedAnnouncement = {
5
6
  [id: number]: boolean;
6
7
  };
@@ -30,7 +31,7 @@ export type StateAnnouncementMap = {
30
31
  export type AnnouncementControllerState = {
31
32
  announcements: StateAnnouncementMap;
32
33
  };
33
- export type AnnouncementControllerActions = AnnouncementControllerGetStateAction;
34
+ export type AnnouncementControllerActions = AnnouncementControllerGetStateAction | AnnouncementControllerMethodActions;
34
35
  export type AnnouncementControllerEvents = AnnouncementControllerStateChangeEvent;
35
36
  export type AnnouncementControllerGetStateAction = ControllerGetStateAction<typeof controllerName, AnnouncementControllerState>;
36
37
  export type AnnouncementControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, AnnouncementControllerState>;
@@ -1 +1 @@
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,KAAK,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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,6 +1,7 @@
1
1
  import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
2
  import { BaseController } from "@metamask/base-controller";
3
3
  import type { Messenger } from "@metamask/messenger";
4
+ import type { AnnouncementControllerMethodActions } from "./AnnouncementController-method-action-types.mjs";
4
5
  type ViewedAnnouncement = {
5
6
  [id: number]: boolean;
6
7
  };
@@ -30,7 +31,7 @@ export type StateAnnouncementMap = {
30
31
  export type AnnouncementControllerState = {
31
32
  announcements: StateAnnouncementMap;
32
33
  };
33
- export type AnnouncementControllerActions = AnnouncementControllerGetStateAction;
34
+ export type AnnouncementControllerActions = AnnouncementControllerGetStateAction | AnnouncementControllerMethodActions;
34
35
  export type AnnouncementControllerEvents = AnnouncementControllerStateChangeEvent;
35
36
  export type AnnouncementControllerGetStateAction = ControllerGetStateAction<typeof controllerName, AnnouncementControllerState>;
36
37
  export type AnnouncementControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, AnnouncementControllerState>;
@@ -1 +1 @@
1
- {"version":3,"file":"AnnouncementController.d.mts","sourceRoot":"","sources":["../src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,+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;IAwBD;;OAEG;IACH,WAAW,IAAI,IAAI;IAQnB;;;;;OAKG;IACH,YAAY,CAAC,SAAS,EAAE,kBAAkB,GAAG,IAAI;CAOlD"}
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,yDAAqD;AAExG,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"}
@@ -6,6 +6,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
6
6
  var _AnnouncementController_instances, _AnnouncementController_addAnnouncements;
7
7
  import { BaseController } from "@metamask/base-controller";
8
8
  const controllerName = 'AnnouncementController';
9
+ const MESSENGER_EXPOSED_METHODS = ['resetViewed', 'updateViewed'];
9
10
  const defaultState = {
10
11
  announcements: {},
11
12
  };
@@ -33,6 +34,7 @@ export class AnnouncementController extends BaseController {
33
34
  const mergedState = { ...defaultState, ...state };
34
35
  super({ messenger, metadata, name: controllerName, state: mergedState });
35
36
  _AnnouncementController_instances.add(this);
37
+ this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
36
38
  __classPrivateFieldGet(this, _AnnouncementController_instances, "m", _AnnouncementController_addAnnouncements).call(this, allAnnouncements);
37
39
  }
38
40
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"AnnouncementController.mjs","sourceRoot":"","sources":["../src/AnnouncementController.ts"],"names":[],"mappings":";;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAmD3D,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAEhD,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,CAAC,CAAC;;QACzE,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;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\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;\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 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.#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
+ {"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,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;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';\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 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAUA,uEAAkE;AAAzD,gIAAA,sBAAsB,OAAA","sourcesContent":["export type {\n AnnouncementMap,\n StateAnnouncementMap,\n AnnouncementControllerState,\n AnnouncementControllerActions,\n AnnouncementControllerEvents,\n AnnouncementControllerGetStateAction,\n AnnouncementControllerStateChangeEvent,\n AnnouncementControllerMessenger,\n} from './AnnouncementController';\nexport { AnnouncementController } from './AnnouncementController';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAcA,uEAAkE;AAAzD,gIAAA,sBAAsB,OAAA","sourcesContent":["export type {\n AnnouncementControllerResetViewedAction,\n AnnouncementControllerUpdateViewedAction,\n} from './AnnouncementController-method-action-types';\nexport type {\n AnnouncementMap,\n StateAnnouncementMap,\n AnnouncementControllerState,\n AnnouncementControllerActions,\n AnnouncementControllerEvents,\n AnnouncementControllerGetStateAction,\n AnnouncementControllerStateChangeEvent,\n AnnouncementControllerMessenger,\n} from './AnnouncementController';\nexport { AnnouncementController } from './AnnouncementController';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,3 +1,4 @@
1
+ export type { AnnouncementControllerResetViewedAction, AnnouncementControllerUpdateViewedAction, } from "./AnnouncementController-method-action-types.cjs";
1
2
  export type { AnnouncementMap, StateAnnouncementMap, AnnouncementControllerState, AnnouncementControllerActions, AnnouncementControllerEvents, AnnouncementControllerGetStateAction, AnnouncementControllerStateChangeEvent, AnnouncementControllerMessenger, } from "./AnnouncementController.cjs";
2
3
  export { AnnouncementController } from "./AnnouncementController.cjs";
3
4
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,eAAe,EACf,oBAAoB,EACpB,2BAA2B,EAC3B,6BAA6B,EAC7B,4BAA4B,EAC5B,oCAAoC,EACpC,sCAAsC,EACtC,+BAA+B,GAChC,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,uCAAuC,EACvC,wCAAwC,GACzC,yDAAqD;AACtD,YAAY,EACV,eAAe,EACf,oBAAoB,EACpB,2BAA2B,EAC3B,6BAA6B,EAC7B,4BAA4B,EAC5B,oCAAoC,EACpC,sCAAsC,EACtC,+BAA+B,GAChC,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC"}
package/dist/index.d.mts CHANGED
@@ -1,3 +1,4 @@
1
+ export type { AnnouncementControllerResetViewedAction, AnnouncementControllerUpdateViewedAction, } from "./AnnouncementController-method-action-types.mjs";
1
2
  export type { AnnouncementMap, StateAnnouncementMap, AnnouncementControllerState, AnnouncementControllerActions, AnnouncementControllerEvents, AnnouncementControllerGetStateAction, AnnouncementControllerStateChangeEvent, AnnouncementControllerMessenger, } from "./AnnouncementController.mjs";
2
3
  export { AnnouncementController } from "./AnnouncementController.mjs";
3
4
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,eAAe,EACf,oBAAoB,EACpB,2BAA2B,EAC3B,6BAA6B,EAC7B,4BAA4B,EAC5B,oCAAoC,EACpC,sCAAsC,EACtC,+BAA+B,GAChC,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,uCAAuC,EACvC,wCAAwC,GACzC,yDAAqD;AACtD,YAAY,EACV,eAAe,EACf,oBAAoB,EACpB,2BAA2B,EAC3B,6BAA6B,EAC7B,4BAA4B,EAC5B,oCAAoC,EACpC,sCAAsC,EACtC,+BAA+B,GAChC,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,sBAAsB,EAAE,qCAAiC","sourcesContent":["export type {\n AnnouncementMap,\n StateAnnouncementMap,\n AnnouncementControllerState,\n AnnouncementControllerActions,\n AnnouncementControllerEvents,\n AnnouncementControllerGetStateAction,\n AnnouncementControllerStateChangeEvent,\n AnnouncementControllerMessenger,\n} from './AnnouncementController';\nexport { AnnouncementController } from './AnnouncementController';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,sBAAsB,EAAE,qCAAiC","sourcesContent":["export type {\n AnnouncementControllerResetViewedAction,\n AnnouncementControllerUpdateViewedAction,\n} from './AnnouncementController-method-action-types';\nexport type {\n AnnouncementMap,\n StateAnnouncementMap,\n AnnouncementControllerState,\n AnnouncementControllerActions,\n AnnouncementControllerEvents,\n AnnouncementControllerGetStateAction,\n AnnouncementControllerStateChangeEvent,\n AnnouncementControllerMessenger,\n} from './AnnouncementController';\nexport { AnnouncementController } from './AnnouncementController';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/announcement-controller",
3
- "version": "8.0.0-preview-6cb7e4bcf",
3
+ "version": "8.0.0-preview-3685bfb",
4
4
  "description": "Manages in-app announcements",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -40,6 +40,7 @@
40
40
  "build:docs": "typedoc",
41
41
  "changelog:update": "../../scripts/update-changelog.sh @metamask/announcement-controller",
42
42
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/announcement-controller",
43
+ "generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts",
43
44
  "since-latest-release": "../../scripts/since-latest-release.sh",
44
45
  "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
45
46
  "test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
@@ -57,6 +58,7 @@
57
58
  "deepmerge": "^4.2.2",
58
59
  "jest": "^29.7.0",
59
60
  "ts-jest": "^29.2.5",
61
+ "tsx": "^4.20.5",
60
62
  "typedoc": "^0.25.13",
61
63
  "typedoc-plugin-missing-exports": "^2.0.0",
62
64
  "typescript": "~5.3.3"