@metamask-previews/announcement-controller 8.0.0-preview-ee982ebe → 8.0.0-preview-91b0ac79

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.
@@ -1 +1 @@
1
- {"version":3,"file":"AnnouncementController.cjs","sourceRoot":"","sources":["../src/AnnouncementController.ts"],"names":[],"mappings":";;;;;;;;;AAKA,+DAA2D;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,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,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;gBACvD,YAAY,CAAC,OAAO,GAAG,KAAK,CAAC;aAC9B;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;gBACnD,aAAa,CAAC,EAAE,CAAC,CAAC,OAAO,GAAG,SAAS,CAAC,EAAE,CAAC,CAAC;aAC3C;QACH,CAAC,CAAC,CAAC;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","sourceRoot":"","sources":["../src/AnnouncementController.ts"],"names":[],"mappings":";;;;;;;;;AAKA,+DAA2D;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,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,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;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 +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;gBACvD,YAAY,CAAC,OAAO,GAAG,KAAK,CAAC;aAC9B;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;gBACnD,aAAa,CAAC,EAAE,CAAC,CAAC,OAAO,GAAG,SAAS,CAAC,EAAE,CAAC,CAAC;aAC3C;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;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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/announcement-controller",
3
- "version": "8.0.0-preview-ee982ebe",
3
+ "version": "8.0.0-preview-91b0ac79",
4
4
  "description": "Manages in-app announcements",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -60,7 +60,7 @@
60
60
  "ts-jest": "^27.1.4",
61
61
  "typedoc": "^0.24.8",
62
62
  "typedoc-plugin-missing-exports": "^2.0.0",
63
- "typescript": "~5.2.2"
63
+ "typescript": "~5.3.3"
64
64
  },
65
65
  "engines": {
66
66
  "node": "^18.18 || >=20"