@metamask-previews/app-metadata-controller 2.0.0-preview-ee982ebe → 2.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":"AppMetadataController.cjs","sourceRoot":"","sources":["../src/AppMetadataController.ts"],"names":[],"mappings":";;;;;;;;;AAKA,+DAA2D;AAG3D,iCAAiC;AACjC,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAsB/C;;;;;;;GAOG;AACI,MAAM,oCAAoC,GAC/C,GAA+B,EAAE,CAAC,CAAC;IACjC,iBAAiB,EAAE,EAAE;IACrB,kBAAkB,EAAE,EAAE;IACtB,wBAAwB,EAAE,CAAC;IAC3B,uBAAuB,EAAE,CAAC;CAC3B,CAAC,CAAC;AANQ,QAAA,oCAAoC,wCAM5C;AAmDL;;;;GAIG;AACH,MAAM,kBAAkB,GAAG;IACzB,iBAAiB,EAAE;QACjB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;IACD,kBAAkB,EAAE;QAClB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;IACD,wBAAwB,EAAE;QACxB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;IACD,uBAAuB,EAAE;QACvB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;CACkD,CAAC;AAEtD;;;;;GAKG;AACH,MAAa,qBAAsB,SAAQ,gCAI1C;IACC;;;;;;;;OAQG;IACH,YAAY,EACV,KAAK,GAAG,EAAE,EACV,SAAS,EACT,iBAAiB,GAAG,EAAE,EACtB,uBAAuB,GAAG,CAAC,GACE;QAC7B,KAAK,CAAC;YACJ,IAAI,EAAE,cAAc;YACpB,QAAQ,EAAE,kBAAkB;YAC5B,KAAK,EAAE;gBACL,GAAG,IAAA,4CAAoC,GAAE;gBACzC,GAAG,KAAK;aACT;YACD,SAAS;SACV,CAAC,CAAC;;QAEH,uBAAA,IAAI,iFAAkB,MAAtB,IAAI,EAAmB,iBAAiB,CAAC,CAAC;QAE1C,uBAAA,IAAI,uFAAwB,MAA5B,IAAI,EAAyB,uBAAuB,CAAC,CAAC;IACxD,CAAC;CAiCF;AAlED,sDAkEC;6IA1BmB,aAAqB;IACrC,MAAM,oBAAoB,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC;IAE1D,IAAI,aAAa,KAAK,oBAAoB,EAAE;QAC1C,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,iBAAiB,GAAG,aAAa,CAAC;YACxC,KAAK,CAAC,kBAAkB,GAAG,oBAAoB,CAAC;QAClD,CAAC,CAAC,CAAC;KACJ;AACH,CAAC,yGAOuB,mBAA2B;IACjD,MAAM,0BAA0B,GAAG,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC;IAEtE,IAAI,mBAAmB,KAAK,0BAA0B,EAAE;QACtD,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,wBAAwB,GAAG,0BAA0B,CAAC;YAC5D,KAAK,CAAC,uBAAuB,GAAG,mBAAmB,CAAC;QACtD,CAAC,CAAC,CAAC;KACJ;AACH,CAAC","sourcesContent":["import type {\n StateMetadata,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\n// Unique name for the controller\nconst controllerName = 'AppMetadataController';\n\n/**\n * The options that AppMetadataController takes.\n */\nexport type AppMetadataControllerOptions = {\n state?: Partial<AppMetadataControllerState>;\n messenger: AppMetadataControllerMessenger;\n currentMigrationVersion?: number;\n currentAppVersion?: string;\n};\n\n/**\n * The state of the AppMetadataController\n */\nexport type AppMetadataControllerState = {\n currentAppVersion: string;\n previousAppVersion: string;\n previousMigrationVersion: number;\n currentMigrationVersion: number;\n};\n\n/**\n * Constructs the default {@link AppMetadataController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link AppMetadataController} state.\n */\nexport const getDefaultAppMetadataControllerState =\n (): AppMetadataControllerState => ({\n currentAppVersion: '',\n previousAppVersion: '',\n previousMigrationVersion: 0,\n currentMigrationVersion: 0,\n });\n\n/**\n * Returns the state of the {@link AppMetadataController}.\n */\nexport type AppMetadataControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AppMetadataControllerState\n>;\n\n/**\n * Actions exposed by the {@link AppMetadataController}.\n */\nexport type AppMetadataControllerActions = AppMetadataControllerGetStateAction;\n\n/**\n * Event emitted when the state of the {@link AppMetadataController} changes.\n */\nexport type AppMetadataControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AppMetadataControllerState\n>;\n\n/**\n * Events that can be emitted by the {@link AppMetadataController}\n */\nexport type AppMetadataControllerEvents = AppMetadataControllerStateChangeEvent;\n\n/**\n * Actions that this controller is allowed to call.\n * Currently set to never as this controller doesn't call any other controllers.\n */\ntype AllowedActions = never;\n\n/**\n * Events that this controller is allowed to subscribe.\n */\ntype AllowedEvents = never;\n\n/**\n * Messenger type for the {@link AppMetadataController}.\n *\n * @returns A restricted messenger type that defines the allowed actions and events\n * for the AppMetadataController\n */\nexport type AppMetadataControllerMessenger = Messenger<\n typeof controllerName,\n AppMetadataControllerActions | AllowedActions,\n AppMetadataControllerEvents | AllowedEvents\n>;\n\n/**\n * Metadata configuration for the {@link AppMetadataController}.\n *\n * Defines persistence and anonymity settings for each state property.\n */\nconst controllerMetadata = {\n currentAppVersion: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n previousAppVersion: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n previousMigrationVersion: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n currentMigrationVersion: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n} satisfies StateMetadata<AppMetadataControllerState>;\n\n/**\n * The AppMetadata controller stores metadata about the current extension instance,\n * including the currently and previously installed versions, and the most recently\n * run migration.\n *\n */\nexport class AppMetadataController extends BaseController<\n typeof controllerName,\n AppMetadataControllerState,\n AppMetadataControllerMessenger\n> {\n /**\n * Constructs a AppMetadata controller.\n *\n * @param options - the controller options\n * @param options.state - Initial controller state.\n * @param options.messenger - Messenger used to communicate with BaseV2 controller.\n * @param options.currentMigrationVersion - The migration version to store in state.\n * @param options.currentAppVersion - The app version to store in state.\n */\n constructor({\n state = {},\n messenger,\n currentAppVersion = '',\n currentMigrationVersion = 0,\n }: AppMetadataControllerOptions) {\n super({\n name: controllerName,\n metadata: controllerMetadata,\n state: {\n ...getDefaultAppMetadataControllerState(),\n ...state,\n },\n messenger,\n });\n\n this.#updateAppVersion(currentAppVersion);\n\n this.#updateMigrationVersion(currentMigrationVersion);\n }\n\n /**\n * Updates the currentAppVersion in state, and sets the previousAppVersion to the old currentAppVersion.\n *\n * @param newAppVersion - The new app version to store in state.\n */\n #updateAppVersion(newAppVersion: string): void {\n const oldCurrentAppVersion = this.state.currentAppVersion;\n\n if (newAppVersion !== oldCurrentAppVersion) {\n this.update((state) => {\n state.currentAppVersion = newAppVersion;\n state.previousAppVersion = oldCurrentAppVersion;\n });\n }\n }\n\n /**\n * Updates the migrationVersion in state.\n *\n * @param newMigrationVersion - The new migration version to store in state.\n */\n #updateMigrationVersion(newMigrationVersion: number): void {\n const oldCurrentMigrationVersion = this.state.currentMigrationVersion;\n\n if (newMigrationVersion !== oldCurrentMigrationVersion) {\n this.update((state) => {\n state.previousMigrationVersion = oldCurrentMigrationVersion;\n state.currentMigrationVersion = newMigrationVersion;\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"AppMetadataController.cjs","sourceRoot":"","sources":["../src/AppMetadataController.ts"],"names":[],"mappings":";;;;;;;;;AAKA,+DAA2D;AAG3D,iCAAiC;AACjC,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAsB/C;;;;;;;GAOG;AACI,MAAM,oCAAoC,GAC/C,GAA+B,EAAE,CAAC,CAAC;IACjC,iBAAiB,EAAE,EAAE;IACrB,kBAAkB,EAAE,EAAE;IACtB,wBAAwB,EAAE,CAAC;IAC3B,uBAAuB,EAAE,CAAC;CAC3B,CAAC,CAAC;AANQ,QAAA,oCAAoC,wCAM5C;AAmDL;;;;GAIG;AACH,MAAM,kBAAkB,GAAG;IACzB,iBAAiB,EAAE;QACjB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;IACD,kBAAkB,EAAE;QAClB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;IACD,wBAAwB,EAAE;QACxB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;IACD,uBAAuB,EAAE;QACvB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;CACkD,CAAC;AAEtD;;;;;GAKG;AACH,MAAa,qBAAsB,SAAQ,gCAI1C;IACC;;;;;;;;OAQG;IACH,YAAY,EACV,KAAK,GAAG,EAAE,EACV,SAAS,EACT,iBAAiB,GAAG,EAAE,EACtB,uBAAuB,GAAG,CAAC,GACE;QAC7B,KAAK,CAAC;YACJ,IAAI,EAAE,cAAc;YACpB,QAAQ,EAAE,kBAAkB;YAC5B,KAAK,EAAE;gBACL,GAAG,IAAA,4CAAoC,GAAE;gBACzC,GAAG,KAAK;aACT;YACD,SAAS;SACV,CAAC,CAAC;;QAEH,uBAAA,IAAI,iFAAkB,MAAtB,IAAI,EAAmB,iBAAiB,CAAC,CAAC;QAE1C,uBAAA,IAAI,uFAAwB,MAA5B,IAAI,EAAyB,uBAAuB,CAAC,CAAC;IACxD,CAAC;CAiCF;AAlED,sDAkEC;6IA1BmB,aAAqB;IACrC,MAAM,oBAAoB,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC;IAE1D,IAAI,aAAa,KAAK,oBAAoB,EAAE,CAAC;QAC3C,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,iBAAiB,GAAG,aAAa,CAAC;YACxC,KAAK,CAAC,kBAAkB,GAAG,oBAAoB,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,yGAOuB,mBAA2B;IACjD,MAAM,0BAA0B,GAAG,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC;IAEtE,IAAI,mBAAmB,KAAK,0BAA0B,EAAE,CAAC;QACvD,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,wBAAwB,GAAG,0BAA0B,CAAC;YAC5D,KAAK,CAAC,uBAAuB,GAAG,mBAAmB,CAAC;QACtD,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import type {\n StateMetadata,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\n// Unique name for the controller\nconst controllerName = 'AppMetadataController';\n\n/**\n * The options that AppMetadataController takes.\n */\nexport type AppMetadataControllerOptions = {\n state?: Partial<AppMetadataControllerState>;\n messenger: AppMetadataControllerMessenger;\n currentMigrationVersion?: number;\n currentAppVersion?: string;\n};\n\n/**\n * The state of the AppMetadataController\n */\nexport type AppMetadataControllerState = {\n currentAppVersion: string;\n previousAppVersion: string;\n previousMigrationVersion: number;\n currentMigrationVersion: number;\n};\n\n/**\n * Constructs the default {@link AppMetadataController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link AppMetadataController} state.\n */\nexport const getDefaultAppMetadataControllerState =\n (): AppMetadataControllerState => ({\n currentAppVersion: '',\n previousAppVersion: '',\n previousMigrationVersion: 0,\n currentMigrationVersion: 0,\n });\n\n/**\n * Returns the state of the {@link AppMetadataController}.\n */\nexport type AppMetadataControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AppMetadataControllerState\n>;\n\n/**\n * Actions exposed by the {@link AppMetadataController}.\n */\nexport type AppMetadataControllerActions = AppMetadataControllerGetStateAction;\n\n/**\n * Event emitted when the state of the {@link AppMetadataController} changes.\n */\nexport type AppMetadataControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AppMetadataControllerState\n>;\n\n/**\n * Events that can be emitted by the {@link AppMetadataController}\n */\nexport type AppMetadataControllerEvents = AppMetadataControllerStateChangeEvent;\n\n/**\n * Actions that this controller is allowed to call.\n * Currently set to never as this controller doesn't call any other controllers.\n */\ntype AllowedActions = never;\n\n/**\n * Events that this controller is allowed to subscribe.\n */\ntype AllowedEvents = never;\n\n/**\n * Messenger type for the {@link AppMetadataController}.\n *\n * @returns A restricted messenger type that defines the allowed actions and events\n * for the AppMetadataController\n */\nexport type AppMetadataControllerMessenger = Messenger<\n typeof controllerName,\n AppMetadataControllerActions | AllowedActions,\n AppMetadataControllerEvents | AllowedEvents\n>;\n\n/**\n * Metadata configuration for the {@link AppMetadataController}.\n *\n * Defines persistence and anonymity settings for each state property.\n */\nconst controllerMetadata = {\n currentAppVersion: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n previousAppVersion: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n previousMigrationVersion: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n currentMigrationVersion: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n} satisfies StateMetadata<AppMetadataControllerState>;\n\n/**\n * The AppMetadata controller stores metadata about the current extension instance,\n * including the currently and previously installed versions, and the most recently\n * run migration.\n *\n */\nexport class AppMetadataController extends BaseController<\n typeof controllerName,\n AppMetadataControllerState,\n AppMetadataControllerMessenger\n> {\n /**\n * Constructs a AppMetadata controller.\n *\n * @param options - the controller options\n * @param options.state - Initial controller state.\n * @param options.messenger - Messenger used to communicate with BaseV2 controller.\n * @param options.currentMigrationVersion - The migration version to store in state.\n * @param options.currentAppVersion - The app version to store in state.\n */\n constructor({\n state = {},\n messenger,\n currentAppVersion = '',\n currentMigrationVersion = 0,\n }: AppMetadataControllerOptions) {\n super({\n name: controllerName,\n metadata: controllerMetadata,\n state: {\n ...getDefaultAppMetadataControllerState(),\n ...state,\n },\n messenger,\n });\n\n this.#updateAppVersion(currentAppVersion);\n\n this.#updateMigrationVersion(currentMigrationVersion);\n }\n\n /**\n * Updates the currentAppVersion in state, and sets the previousAppVersion to the old currentAppVersion.\n *\n * @param newAppVersion - The new app version to store in state.\n */\n #updateAppVersion(newAppVersion: string): void {\n const oldCurrentAppVersion = this.state.currentAppVersion;\n\n if (newAppVersion !== oldCurrentAppVersion) {\n this.update((state) => {\n state.currentAppVersion = newAppVersion;\n state.previousAppVersion = oldCurrentAppVersion;\n });\n }\n }\n\n /**\n * Updates the migrationVersion in state.\n *\n * @param newMigrationVersion - The new migration version to store in state.\n */\n #updateMigrationVersion(newMigrationVersion: number): void {\n const oldCurrentMigrationVersion = this.state.currentMigrationVersion;\n\n if (newMigrationVersion !== oldCurrentMigrationVersion) {\n this.update((state) => {\n state.previousMigrationVersion = oldCurrentMigrationVersion;\n state.currentMigrationVersion = newMigrationVersion;\n });\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"AppMetadataController.mjs","sourceRoot":"","sources":["../src/AppMetadataController.ts"],"names":[],"mappings":";;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAG3D,iCAAiC;AACjC,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAsB/C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAC/C,GAA+B,EAAE,CAAC,CAAC;IACjC,iBAAiB,EAAE,EAAE;IACrB,kBAAkB,EAAE,EAAE;IACtB,wBAAwB,EAAE,CAAC;IAC3B,uBAAuB,EAAE,CAAC;CAC3B,CAAC,CAAC;AAmDL;;;;GAIG;AACH,MAAM,kBAAkB,GAAG;IACzB,iBAAiB,EAAE;QACjB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;IACD,kBAAkB,EAAE;QAClB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;IACD,wBAAwB,EAAE;QACxB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;IACD,uBAAuB,EAAE;QACvB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;CACkD,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,OAAO,qBAAsB,SAAQ,cAI1C;IACC;;;;;;;;OAQG;IACH,YAAY,EACV,KAAK,GAAG,EAAE,EACV,SAAS,EACT,iBAAiB,GAAG,EAAE,EACtB,uBAAuB,GAAG,CAAC,GACE;QAC7B,KAAK,CAAC;YACJ,IAAI,EAAE,cAAc;YACpB,QAAQ,EAAE,kBAAkB;YAC5B,KAAK,EAAE;gBACL,GAAG,oCAAoC,EAAE;gBACzC,GAAG,KAAK;aACT;YACD,SAAS;SACV,CAAC,CAAC;;QAEH,uBAAA,IAAI,iFAAkB,MAAtB,IAAI,EAAmB,iBAAiB,CAAC,CAAC;QAE1C,uBAAA,IAAI,uFAAwB,MAA5B,IAAI,EAAyB,uBAAuB,CAAC,CAAC;IACxD,CAAC;CAiCF;6IA1BmB,aAAqB;IACrC,MAAM,oBAAoB,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC;IAE1D,IAAI,aAAa,KAAK,oBAAoB,EAAE;QAC1C,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,iBAAiB,GAAG,aAAa,CAAC;YACxC,KAAK,CAAC,kBAAkB,GAAG,oBAAoB,CAAC;QAClD,CAAC,CAAC,CAAC;KACJ;AACH,CAAC,yGAOuB,mBAA2B;IACjD,MAAM,0BAA0B,GAAG,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC;IAEtE,IAAI,mBAAmB,KAAK,0BAA0B,EAAE;QACtD,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,wBAAwB,GAAG,0BAA0B,CAAC;YAC5D,KAAK,CAAC,uBAAuB,GAAG,mBAAmB,CAAC;QACtD,CAAC,CAAC,CAAC;KACJ;AACH,CAAC","sourcesContent":["import type {\n StateMetadata,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\n// Unique name for the controller\nconst controllerName = 'AppMetadataController';\n\n/**\n * The options that AppMetadataController takes.\n */\nexport type AppMetadataControllerOptions = {\n state?: Partial<AppMetadataControllerState>;\n messenger: AppMetadataControllerMessenger;\n currentMigrationVersion?: number;\n currentAppVersion?: string;\n};\n\n/**\n * The state of the AppMetadataController\n */\nexport type AppMetadataControllerState = {\n currentAppVersion: string;\n previousAppVersion: string;\n previousMigrationVersion: number;\n currentMigrationVersion: number;\n};\n\n/**\n * Constructs the default {@link AppMetadataController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link AppMetadataController} state.\n */\nexport const getDefaultAppMetadataControllerState =\n (): AppMetadataControllerState => ({\n currentAppVersion: '',\n previousAppVersion: '',\n previousMigrationVersion: 0,\n currentMigrationVersion: 0,\n });\n\n/**\n * Returns the state of the {@link AppMetadataController}.\n */\nexport type AppMetadataControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AppMetadataControllerState\n>;\n\n/**\n * Actions exposed by the {@link AppMetadataController}.\n */\nexport type AppMetadataControllerActions = AppMetadataControllerGetStateAction;\n\n/**\n * Event emitted when the state of the {@link AppMetadataController} changes.\n */\nexport type AppMetadataControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AppMetadataControllerState\n>;\n\n/**\n * Events that can be emitted by the {@link AppMetadataController}\n */\nexport type AppMetadataControllerEvents = AppMetadataControllerStateChangeEvent;\n\n/**\n * Actions that this controller is allowed to call.\n * Currently set to never as this controller doesn't call any other controllers.\n */\ntype AllowedActions = never;\n\n/**\n * Events that this controller is allowed to subscribe.\n */\ntype AllowedEvents = never;\n\n/**\n * Messenger type for the {@link AppMetadataController}.\n *\n * @returns A restricted messenger type that defines the allowed actions and events\n * for the AppMetadataController\n */\nexport type AppMetadataControllerMessenger = Messenger<\n typeof controllerName,\n AppMetadataControllerActions | AllowedActions,\n AppMetadataControllerEvents | AllowedEvents\n>;\n\n/**\n * Metadata configuration for the {@link AppMetadataController}.\n *\n * Defines persistence and anonymity settings for each state property.\n */\nconst controllerMetadata = {\n currentAppVersion: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n previousAppVersion: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n previousMigrationVersion: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n currentMigrationVersion: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n} satisfies StateMetadata<AppMetadataControllerState>;\n\n/**\n * The AppMetadata controller stores metadata about the current extension instance,\n * including the currently and previously installed versions, and the most recently\n * run migration.\n *\n */\nexport class AppMetadataController extends BaseController<\n typeof controllerName,\n AppMetadataControllerState,\n AppMetadataControllerMessenger\n> {\n /**\n * Constructs a AppMetadata controller.\n *\n * @param options - the controller options\n * @param options.state - Initial controller state.\n * @param options.messenger - Messenger used to communicate with BaseV2 controller.\n * @param options.currentMigrationVersion - The migration version to store in state.\n * @param options.currentAppVersion - The app version to store in state.\n */\n constructor({\n state = {},\n messenger,\n currentAppVersion = '',\n currentMigrationVersion = 0,\n }: AppMetadataControllerOptions) {\n super({\n name: controllerName,\n metadata: controllerMetadata,\n state: {\n ...getDefaultAppMetadataControllerState(),\n ...state,\n },\n messenger,\n });\n\n this.#updateAppVersion(currentAppVersion);\n\n this.#updateMigrationVersion(currentMigrationVersion);\n }\n\n /**\n * Updates the currentAppVersion in state, and sets the previousAppVersion to the old currentAppVersion.\n *\n * @param newAppVersion - The new app version to store in state.\n */\n #updateAppVersion(newAppVersion: string): void {\n const oldCurrentAppVersion = this.state.currentAppVersion;\n\n if (newAppVersion !== oldCurrentAppVersion) {\n this.update((state) => {\n state.currentAppVersion = newAppVersion;\n state.previousAppVersion = oldCurrentAppVersion;\n });\n }\n }\n\n /**\n * Updates the migrationVersion in state.\n *\n * @param newMigrationVersion - The new migration version to store in state.\n */\n #updateMigrationVersion(newMigrationVersion: number): void {\n const oldCurrentMigrationVersion = this.state.currentMigrationVersion;\n\n if (newMigrationVersion !== oldCurrentMigrationVersion) {\n this.update((state) => {\n state.previousMigrationVersion = oldCurrentMigrationVersion;\n state.currentMigrationVersion = newMigrationVersion;\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"AppMetadataController.mjs","sourceRoot":"","sources":["../src/AppMetadataController.ts"],"names":[],"mappings":";;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAG3D,iCAAiC;AACjC,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAsB/C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAC/C,GAA+B,EAAE,CAAC,CAAC;IACjC,iBAAiB,EAAE,EAAE;IACrB,kBAAkB,EAAE,EAAE;IACtB,wBAAwB,EAAE,CAAC;IAC3B,uBAAuB,EAAE,CAAC;CAC3B,CAAC,CAAC;AAmDL;;;;GAIG;AACH,MAAM,kBAAkB,GAAG;IACzB,iBAAiB,EAAE;QACjB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;IACD,kBAAkB,EAAE;QAClB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;IACD,wBAAwB,EAAE;QACxB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;IACD,uBAAuB,EAAE;QACvB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;CACkD,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,OAAO,qBAAsB,SAAQ,cAI1C;IACC;;;;;;;;OAQG;IACH,YAAY,EACV,KAAK,GAAG,EAAE,EACV,SAAS,EACT,iBAAiB,GAAG,EAAE,EACtB,uBAAuB,GAAG,CAAC,GACE;QAC7B,KAAK,CAAC;YACJ,IAAI,EAAE,cAAc;YACpB,QAAQ,EAAE,kBAAkB;YAC5B,KAAK,EAAE;gBACL,GAAG,oCAAoC,EAAE;gBACzC,GAAG,KAAK;aACT;YACD,SAAS;SACV,CAAC,CAAC;;QAEH,uBAAA,IAAI,iFAAkB,MAAtB,IAAI,EAAmB,iBAAiB,CAAC,CAAC;QAE1C,uBAAA,IAAI,uFAAwB,MAA5B,IAAI,EAAyB,uBAAuB,CAAC,CAAC;IACxD,CAAC;CAiCF;6IA1BmB,aAAqB;IACrC,MAAM,oBAAoB,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC;IAE1D,IAAI,aAAa,KAAK,oBAAoB,EAAE,CAAC;QAC3C,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,iBAAiB,GAAG,aAAa,CAAC;YACxC,KAAK,CAAC,kBAAkB,GAAG,oBAAoB,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,yGAOuB,mBAA2B;IACjD,MAAM,0BAA0B,GAAG,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC;IAEtE,IAAI,mBAAmB,KAAK,0BAA0B,EAAE,CAAC;QACvD,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,wBAAwB,GAAG,0BAA0B,CAAC;YAC5D,KAAK,CAAC,uBAAuB,GAAG,mBAAmB,CAAC;QACtD,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import type {\n StateMetadata,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\n// Unique name for the controller\nconst controllerName = 'AppMetadataController';\n\n/**\n * The options that AppMetadataController takes.\n */\nexport type AppMetadataControllerOptions = {\n state?: Partial<AppMetadataControllerState>;\n messenger: AppMetadataControllerMessenger;\n currentMigrationVersion?: number;\n currentAppVersion?: string;\n};\n\n/**\n * The state of the AppMetadataController\n */\nexport type AppMetadataControllerState = {\n currentAppVersion: string;\n previousAppVersion: string;\n previousMigrationVersion: number;\n currentMigrationVersion: number;\n};\n\n/**\n * Constructs the default {@link AppMetadataController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link AppMetadataController} state.\n */\nexport const getDefaultAppMetadataControllerState =\n (): AppMetadataControllerState => ({\n currentAppVersion: '',\n previousAppVersion: '',\n previousMigrationVersion: 0,\n currentMigrationVersion: 0,\n });\n\n/**\n * Returns the state of the {@link AppMetadataController}.\n */\nexport type AppMetadataControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AppMetadataControllerState\n>;\n\n/**\n * Actions exposed by the {@link AppMetadataController}.\n */\nexport type AppMetadataControllerActions = AppMetadataControllerGetStateAction;\n\n/**\n * Event emitted when the state of the {@link AppMetadataController} changes.\n */\nexport type AppMetadataControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AppMetadataControllerState\n>;\n\n/**\n * Events that can be emitted by the {@link AppMetadataController}\n */\nexport type AppMetadataControllerEvents = AppMetadataControllerStateChangeEvent;\n\n/**\n * Actions that this controller is allowed to call.\n * Currently set to never as this controller doesn't call any other controllers.\n */\ntype AllowedActions = never;\n\n/**\n * Events that this controller is allowed to subscribe.\n */\ntype AllowedEvents = never;\n\n/**\n * Messenger type for the {@link AppMetadataController}.\n *\n * @returns A restricted messenger type that defines the allowed actions and events\n * for the AppMetadataController\n */\nexport type AppMetadataControllerMessenger = Messenger<\n typeof controllerName,\n AppMetadataControllerActions | AllowedActions,\n AppMetadataControllerEvents | AllowedEvents\n>;\n\n/**\n * Metadata configuration for the {@link AppMetadataController}.\n *\n * Defines persistence and anonymity settings for each state property.\n */\nconst controllerMetadata = {\n currentAppVersion: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n previousAppVersion: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n previousMigrationVersion: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n currentMigrationVersion: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n} satisfies StateMetadata<AppMetadataControllerState>;\n\n/**\n * The AppMetadata controller stores metadata about the current extension instance,\n * including the currently and previously installed versions, and the most recently\n * run migration.\n *\n */\nexport class AppMetadataController extends BaseController<\n typeof controllerName,\n AppMetadataControllerState,\n AppMetadataControllerMessenger\n> {\n /**\n * Constructs a AppMetadata controller.\n *\n * @param options - the controller options\n * @param options.state - Initial controller state.\n * @param options.messenger - Messenger used to communicate with BaseV2 controller.\n * @param options.currentMigrationVersion - The migration version to store in state.\n * @param options.currentAppVersion - The app version to store in state.\n */\n constructor({\n state = {},\n messenger,\n currentAppVersion = '',\n currentMigrationVersion = 0,\n }: AppMetadataControllerOptions) {\n super({\n name: controllerName,\n metadata: controllerMetadata,\n state: {\n ...getDefaultAppMetadataControllerState(),\n ...state,\n },\n messenger,\n });\n\n this.#updateAppVersion(currentAppVersion);\n\n this.#updateMigrationVersion(currentMigrationVersion);\n }\n\n /**\n * Updates the currentAppVersion in state, and sets the previousAppVersion to the old currentAppVersion.\n *\n * @param newAppVersion - The new app version to store in state.\n */\n #updateAppVersion(newAppVersion: string): void {\n const oldCurrentAppVersion = this.state.currentAppVersion;\n\n if (newAppVersion !== oldCurrentAppVersion) {\n this.update((state) => {\n state.currentAppVersion = newAppVersion;\n state.previousAppVersion = oldCurrentAppVersion;\n });\n }\n }\n\n /**\n * Updates the migrationVersion in state.\n *\n * @param newMigrationVersion - The new migration version to store in state.\n */\n #updateMigrationVersion(newMigrationVersion: number): void {\n const oldCurrentMigrationVersion = this.state.currentMigrationVersion;\n\n if (newMigrationVersion !== oldCurrentMigrationVersion) {\n this.update((state) => {\n state.previousMigrationVersion = oldCurrentMigrationVersion;\n state.currentMigrationVersion = newMigrationVersion;\n });\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/app-metadata-controller",
3
- "version": "2.0.0-preview-ee982ebe",
3
+ "version": "2.0.0-preview-91b0ac79",
4
4
  "description": "Manages requests that for app metadata",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -61,7 +61,7 @@
61
61
  "ts-jest": "^27.1.4",
62
62
  "typedoc": "^0.24.8",
63
63
  "typedoc-plugin-missing-exports": "^2.0.0",
64
- "typescript": "~5.2.2"
64
+ "typescript": "~5.3.3"
65
65
  },
66
66
  "engines": {
67
67
  "node": "^18.18 || >=20"