@metamask-previews/logging-controller 7.0.1-preview-25d2d4502 → 8.0.0-preview-152e02d

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,8 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [8.0.0]
11
+
12
+ ### Added
13
+
14
+ - Expose missing public `LoggingController` methods through its messenger ([#8183](https://github.com/MetaMask/core/pull/8183))
15
+ - The following action is now available:
16
+ - `LoggingController:clear`
17
+ - Corresponding action type (`LoggingControllerClearAction`) is available as well.
18
+
10
19
  ### Changed
11
20
 
21
+ - **BREAKING:** Standardize names of `LoggingController` messenger action types ([#8183](https://github.com/MetaMask/core/pull/8183))
22
+ - All existing types for messenger actions have been renamed so they end in `Action` and include the controller name (e.g. `AddLog` -> `LoggingControllerAddAction`). You will need to update imports appropriately.
23
+ - This change only affects the types. The action type strings themselves have not changed, so you do not need to update the list of actions you pass when initializing `LoggingController` messengers.
12
24
  - Bump `@metamask/controller-utils` from `^11.16.0` to `^11.19.0` ([#7534](https://github.com/MetaMask/core/pull/7534), [#7583](https://github.com/MetaMask/core/pull/7583), [#7995](https://github.com/MetaMask/core/pull/7995))
13
25
 
14
26
  ## [7.0.1]
@@ -194,7 +206,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
194
206
  - Initial Release
195
207
  - Add logging controller ([#1089](https://github.com/MetaMask/core.git/pull/1089))
196
208
 
197
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/logging-controller@7.0.1...HEAD
209
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/logging-controller@8.0.0...HEAD
210
+ [8.0.0]: https://github.com/MetaMask/core/compare/@metamask/logging-controller@7.0.1...@metamask/logging-controller@8.0.0
198
211
  [7.0.1]: https://github.com/MetaMask/core/compare/@metamask/logging-controller@7.0.0...@metamask/logging-controller@7.0.1
199
212
  [7.0.0]: https://github.com/MetaMask/core/compare/@metamask/logging-controller@6.1.1...@metamask/logging-controller@7.0.0
200
213
  [6.1.1]: https://github.com/MetaMask/core/compare/@metamask/logging-controller@6.1.0...@metamask/logging-controller@6.1.1
@@ -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=LoggingController-method-action-types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LoggingController-method-action-types.cjs","sourceRoot":"","sources":["../src/LoggingController-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 { LoggingController } from './LoggingController';\n\n/**\n * Add log to the state.\n *\n * @param log - Log to add to the controller\n */\nexport type LoggingControllerAddAction = {\n type: `LoggingController:add`;\n handler: LoggingController['add'];\n};\n\n/**\n * Removes all log entries.\n */\nexport type LoggingControllerClearAction = {\n type: `LoggingController:clear`;\n handler: LoggingController['clear'];\n};\n\n/**\n * Union of all LoggingController action types.\n */\nexport type LoggingControllerMethodActions =\n | LoggingControllerAddAction\n | LoggingControllerClearAction;\n"]}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * This file is auto generated by `scripts/generate-method-action-types.ts`.
3
+ * Do not edit manually.
4
+ */
5
+ import type { LoggingController } from "./LoggingController.cjs";
6
+ /**
7
+ * Add log to the state.
8
+ *
9
+ * @param log - Log to add to the controller
10
+ */
11
+ export type LoggingControllerAddAction = {
12
+ type: `LoggingController:add`;
13
+ handler: LoggingController['add'];
14
+ };
15
+ /**
16
+ * Removes all log entries.
17
+ */
18
+ export type LoggingControllerClearAction = {
19
+ type: `LoggingController:clear`;
20
+ handler: LoggingController['clear'];
21
+ };
22
+ /**
23
+ * Union of all LoggingController action types.
24
+ */
25
+ export type LoggingControllerMethodActions = LoggingControllerAddAction | LoggingControllerClearAction;
26
+ //# sourceMappingURL=LoggingController-method-action-types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LoggingController-method-action-types.d.cts","sourceRoot":"","sources":["../src/LoggingController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAE7D;;;;GAIG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,uBAAuB,CAAC;IAC9B,OAAO,EAAE,iBAAiB,CAAC,KAAK,CAAC,CAAC;CACnC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,EAAE,yBAAyB,CAAC;IAChC,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;CACrC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,8BAA8B,GACtC,0BAA0B,GAC1B,4BAA4B,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * This file is auto generated by `scripts/generate-method-action-types.ts`.
3
+ * Do not edit manually.
4
+ */
5
+ import type { LoggingController } from "./LoggingController.mjs";
6
+ /**
7
+ * Add log to the state.
8
+ *
9
+ * @param log - Log to add to the controller
10
+ */
11
+ export type LoggingControllerAddAction = {
12
+ type: `LoggingController:add`;
13
+ handler: LoggingController['add'];
14
+ };
15
+ /**
16
+ * Removes all log entries.
17
+ */
18
+ export type LoggingControllerClearAction = {
19
+ type: `LoggingController:clear`;
20
+ handler: LoggingController['clear'];
21
+ };
22
+ /**
23
+ * Union of all LoggingController action types.
24
+ */
25
+ export type LoggingControllerMethodActions = LoggingControllerAddAction | LoggingControllerClearAction;
26
+ //# sourceMappingURL=LoggingController-method-action-types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LoggingController-method-action-types.d.mts","sourceRoot":"","sources":["../src/LoggingController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAE7D;;;;GAIG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,uBAAuB,CAAC;IAC9B,OAAO,EAAE,iBAAiB,CAAC,KAAK,CAAC,CAAC;CACnC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,EAAE,yBAAyB,CAAC;IAChC,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;CACrC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,8BAA8B,GACtC,0BAA0B,GAC1B,4BAA4B,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=LoggingController-method-action-types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LoggingController-method-action-types.mjs","sourceRoot":"","sources":["../src/LoggingController-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 { LoggingController } from './LoggingController';\n\n/**\n * Add log to the state.\n *\n * @param log - Log to add to the controller\n */\nexport type LoggingControllerAddAction = {\n type: `LoggingController:add`;\n handler: LoggingController['add'];\n};\n\n/**\n * Removes all log entries.\n */\nexport type LoggingControllerClearAction = {\n type: `LoggingController:clear`;\n handler: LoggingController['clear'];\n};\n\n/**\n * Union of all LoggingController action types.\n */\nexport type LoggingControllerMethodActions =\n | LoggingControllerAddAction\n | LoggingControllerClearAction;\n"]}
@@ -10,6 +10,7 @@ exports.LoggingController = void 0;
10
10
  const base_controller_1 = require("@metamask/base-controller");
11
11
  const uuid_1 = require("uuid");
12
12
  const name = 'LoggingController';
13
+ const MESSENGER_EXPOSED_METHODS = ['add', 'clear'];
13
14
  const metadata = {
14
15
  logs: {
15
16
  includeInStateLogs: true,
@@ -43,7 +44,7 @@ class LoggingController extends base_controller_1.BaseController {
43
44
  },
44
45
  });
45
46
  _LoggingController_instances.add(this);
46
- this.messenger.registerActionHandler(`${name}:add`, (log) => this.add(log));
47
+ this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
47
48
  }
48
49
  /**
49
50
  * Add log to the state.
@@ -1 +1 @@
1
- {"version":3,"file":"LoggingController.cjs","sourceRoot":"","sources":["../src/LoggingController.ts"],"names":[],"mappings":";;;;;;;;;AAKA,+DAA2D;AAE3D,+BAAoC;AA0BpC,MAAM,IAAI,GAAG,mBAAmB,CAAC;AA8BjC,MAAM,QAAQ,GAA0C;IACtD,IAAI,EAAE;QACJ,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,KAAK;KAChB;CACF,CAAC;AAEF,MAAM,YAAY,GAAG;IACnB,IAAI,EAAE,EAAE;CACT,CAAC;AAEF;;GAEG;AACH,MAAa,iBAAkB,SAAQ,gCAItC;IACC;;;;;;OAMG;IACH,YAAY,EACV,SAAS,EACT,KAAK,GAIN;QACC,KAAK,CAAC;YACJ,IAAI;YACJ,QAAQ;YACR,SAAS;YACT,KAAK,EAAE;gBACL,GAAG,YAAY;gBACf,GAAG,KAAK;aACT;SACF,CAAC,CAAC;;QAEH,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC,GAAG,IAAI,MAAe,EAAE,CAAC,GAAQ,EAAE,EAAE,CACxE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CACd,CAAC;IACJ,CAAC;IAmBD;;;;OAIG;IACH,GAAG,CAAC,GAAQ;QACV,MAAM,MAAM,GAAa;YACvB,EAAE,EAAE,uBAAA,IAAI,mEAAY,MAAhB,IAAI,CAAc;YACtB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,GAAG;SACJ,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,IAAI,GAAG,EAAE,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA5ED,8CA4EC;;IAhCG,IAAI,EAAE,GAAG,IAAA,SAAM,GAAE,CAAC;IAClB,OAAO,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAC7B,EAAE,GAAG,IAAA,SAAM,GAAE,CAAC;IAChB,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,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';\nimport { v1 as random } from 'uuid';\n\nimport type { Log } from './logTypes';\n\n/**\n * LogEntry is the entry that will be added to the logging controller state.\n * It consists of a entry key that must be on of the Log union types, and an\n * additional id and timestamp.\n */\nexport type LogEntry = {\n id: string;\n timestamp: number;\n log: Log;\n};\n\n/**\n * Logging controller state\n *\n * @property logs - An object of logs indexed by their ids\n */\nexport type LoggingControllerState = {\n logs: {\n [id: string]: LogEntry;\n };\n};\n\nconst name = 'LoggingController';\n\n/**\n * An action to add log messages to the controller state.\n */\nexport type AddLog = {\n type: `${typeof name}:add`;\n handler: LoggingController['add'];\n};\n\nexport type LoggingControllerGetStateAction = ControllerGetStateAction<\n typeof name,\n LoggingControllerState\n>;\n\nexport type LoggingControllerActions = LoggingControllerGetStateAction | AddLog;\n\nexport type LoggingControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof name,\n LoggingControllerState\n>;\n\nexport type LoggingControllerEvents = LoggingControllerStateChangeEvent;\n\nexport type LoggingControllerMessenger = Messenger<\n typeof name,\n LoggingControllerActions,\n LoggingControllerEvents\n>;\n\nconst metadata: StateMetadata<LoggingControllerState> = {\n logs: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n};\n\nconst defaultState = {\n logs: {},\n};\n\n/**\n * Controller that manages a list of logs for signature requests.\n */\nexport class LoggingController extends BaseController<\n typeof name,\n LoggingControllerState,\n LoggingControllerMessenger\n> {\n /**\n * Creates a LoggingController instance.\n *\n * @param options - Constructor options\n * @param options.messenger - An instance of the Messenger\n * @param options.state - Initial state to set on this controller.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: LoggingControllerMessenger;\n state?: Partial<LoggingControllerState>;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: {\n ...defaultState,\n ...state,\n },\n });\n\n this.messenger.registerActionHandler(`${name}:add` as const, (log: Log) =>\n this.add(log),\n );\n }\n\n /**\n * Method to generate a randomId and ensures no collision with existing ids.\n *\n * We may want to end up using a hashing mechanism to make ids deterministic\n * by the *data* passed in, and then make each key an array of logs that\n * match that id.\n *\n * @returns unique id\n */\n #generateId(): string {\n let id = random();\n while (id in this.state.logs) {\n id = random();\n }\n return id;\n }\n\n /**\n * Add log to the state.\n *\n * @param log - Log to add to the controller\n */\n add(log: Log) {\n const newLog: LogEntry = {\n id: this.#generateId(),\n timestamp: Date.now(),\n log,\n };\n\n this.update((state) => {\n state.logs[newLog.id] = newLog;\n });\n }\n\n /**\n * Removes all log entries.\n */\n clear() {\n this.update((state) => {\n state.logs = {};\n });\n }\n}\n"]}
1
+ {"version":3,"file":"LoggingController.cjs","sourceRoot":"","sources":["../src/LoggingController.ts"],"names":[],"mappings":";;;;;;;;;AAKA,+DAA2D;AAE3D,+BAAoC;AA2BpC,MAAM,IAAI,GAAG,mBAAmB,CAAC;AAEjC,MAAM,yBAAyB,GAAG,CAAC,KAAK,EAAE,OAAO,CAAU,CAAC;AAwB5D,MAAM,QAAQ,GA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,CAAC;AACZ,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';\nimport { v1 as random } from 'uuid';\n\nimport type { LoggingControllerMethodActions } from './LoggingController-method-action-types';\nimport type { Log } from './logTypes';\n\n/**\n * LogEntry is the entry that will be added to the logging controller state.\n * It consists of a entry key that must be on of the Log union types, and an\n * additional id and timestamp.\n */\nexport type LogEntry = {\n id: string;\n timestamp: number;\n log: Log;\n};\n\n/**\n * Logging controller state\n *\n * @property logs - An object of logs indexed by their ids\n */\nexport type LoggingControllerState = {\n logs: {\n [id: string]: LogEntry;\n };\n};\n\nconst name = 'LoggingController';\n\nconst MESSENGER_EXPOSED_METHODS = ['add', 'clear'] as const;\n\nexport type LoggingControllerGetStateAction = ControllerGetStateAction<\n typeof name,\n LoggingControllerState\n>;\n\nexport type LoggingControllerActions =\n | LoggingControllerGetStateAction\n | LoggingControllerMethodActions;\n\nexport type LoggingControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof name,\n LoggingControllerState\n>;\n\nexport type LoggingControllerEvents = LoggingControllerStateChangeEvent;\n\nexport type LoggingControllerMessenger = Messenger<\n typeof name,\n LoggingControllerActions,\n LoggingControllerEvents\n>;\n\nconst metadata: StateMetadata<LoggingControllerState> = {\n logs: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n};\n\nconst defaultState = {\n logs: {},\n};\n\n/**\n * Controller that manages a list of logs for signature requests.\n */\nexport class LoggingController extends BaseController<\n typeof name,\n LoggingControllerState,\n LoggingControllerMessenger\n> {\n /**\n * Creates a LoggingController instance.\n *\n * @param options - Constructor options\n * @param options.messenger - An instance of the Messenger\n * @param options.state - Initial state to set on this controller.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: LoggingControllerMessenger;\n state?: Partial<LoggingControllerState>;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: {\n ...defaultState,\n ...state,\n },\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Method to generate a randomId and ensures no collision with existing ids.\n *\n * We may want to end up using a hashing mechanism to make ids deterministic\n * by the *data* passed in, and then make each key an array of logs that\n * match that id.\n *\n * @returns unique id\n */\n #generateId(): string {\n let id = random();\n while (id in this.state.logs) {\n id = random();\n }\n return id;\n }\n\n /**\n * Add log to the state.\n *\n * @param log - Log to add to the controller\n */\n add(log: Log) {\n const newLog: LogEntry = {\n id: this.#generateId(),\n timestamp: Date.now(),\n log,\n };\n\n this.update((state) => {\n state.logs[newLog.id] = newLog;\n });\n }\n\n /**\n * Removes all log entries.\n */\n clear() {\n this.update((state) => {\n state.logs = {};\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 { LoggingControllerMethodActions } from "./LoggingController-method-action-types.cjs";
4
5
  import type { Log } from "./logTypes/index.cjs";
5
6
  /**
6
7
  * LogEntry is the entry that will be added to the logging controller state.
@@ -23,15 +24,8 @@ export type LoggingControllerState = {
23
24
  };
24
25
  };
25
26
  declare const name = "LoggingController";
26
- /**
27
- * An action to add log messages to the controller state.
28
- */
29
- export type AddLog = {
30
- type: `${typeof name}:add`;
31
- handler: LoggingController['add'];
32
- };
33
27
  export type LoggingControllerGetStateAction = ControllerGetStateAction<typeof name, LoggingControllerState>;
34
- export type LoggingControllerActions = LoggingControllerGetStateAction | AddLog;
28
+ export type LoggingControllerActions = LoggingControllerGetStateAction | LoggingControllerMethodActions;
35
29
  export type LoggingControllerStateChangeEvent = ControllerStateChangeEvent<typeof name, LoggingControllerState>;
36
30
  export type LoggingControllerEvents = LoggingControllerStateChangeEvent;
37
31
  export type LoggingControllerMessenger = Messenger<typeof name, LoggingControllerActions, LoggingControllerEvents>;
@@ -1 +1 @@
1
- {"version":3,"file":"LoggingController.d.cts","sourceRoot":"","sources":["../src/LoggingController.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;AAGrD,OAAO,KAAK,EAAE,GAAG,EAAE,6BAAmB;AAEtC;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,GAAG,CAAC;CACV,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE;QACJ,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,CAAC;KACxB,CAAC;CACH,CAAC;AAEF,QAAA,MAAM,IAAI,sBAAsB,CAAC;AAEjC;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,GAAG,OAAO,IAAI,MAAM,CAAC;IAC3B,OAAO,EAAE,iBAAiB,CAAC,KAAK,CAAC,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG,wBAAwB,CACpE,OAAO,IAAI,EACX,sBAAsB,CACvB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,+BAA+B,GAAG,MAAM,CAAC;AAEhF,MAAM,MAAM,iCAAiC,GAAG,0BAA0B,CACxE,OAAO,IAAI,EACX,sBAAsB,CACvB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,iCAAiC,CAAC;AAExE,MAAM,MAAM,0BAA0B,GAAG,SAAS,CAChD,OAAO,IAAI,EACX,wBAAwB,EACxB,uBAAuB,CACxB,CAAC;AAeF;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,cAAc,CACnD,OAAO,IAAI,EACX,s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IAAI,EACX,wBAAwB,EACxB,uBAAuB,CACxB,CAAC;AAeF;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,cAAc,CACnD,OAAO,IAAI,EACX,sBAAsB,EACtB,0BAA0B,CAC3B;;IACC;;;;;;OAMG;gBACS,EACV,SAAS,EACT,KAAK,GACN,EAAE;QACD,SAAS,EAAE,0BAA0B,CAAC;QACtC,KAAK,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAC;KACzC;IAkCD;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,GAAG;IAYZ;;OAEG;IACH,KAAK;CAKN"}
@@ -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 { LoggingControllerMethodActions } from "./LoggingController-method-action-types.mjs";
4
5
  import type { Log } from "./logTypes/index.mjs";
5
6
  /**
6
7
  * LogEntry is the entry that will be added to the logging controller state.
@@ -23,15 +24,8 @@ export type LoggingControllerState = {
23
24
  };
24
25
  };
25
26
  declare const name = "LoggingController";
26
- /**
27
- * An action to add log messages to the controller state.
28
- */
29
- export type AddLog = {
30
- type: `${typeof name}:add`;
31
- handler: LoggingController['add'];
32
- };
33
27
  export type LoggingControllerGetStateAction = ControllerGetStateAction<typeof name, LoggingControllerState>;
34
- export type LoggingControllerActions = LoggingControllerGetStateAction | AddLog;
28
+ export type LoggingControllerActions = LoggingControllerGetStateAction | LoggingControllerMethodActions;
35
29
  export type LoggingControllerStateChangeEvent = ControllerStateChangeEvent<typeof name, LoggingControllerState>;
36
30
  export type LoggingControllerEvents = LoggingControllerStateChangeEvent;
37
31
  export type LoggingControllerMessenger = Messenger<typeof name, LoggingControllerActions, LoggingControllerEvents>;
@@ -1 +1 @@
1
- {"version":3,"file":"LoggingController.d.mts","sourceRoot":"","sources":["../src/LoggingController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,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CAC3B;;IACC;;;;;;OAMG;gBACS,EACV,SAAS,EACT,KAAK,GACN,EAAE;QACD,SAAS,EAAE,0BAA0B,CAAC;QACtC,KAAK,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAC;KACzC;IAkCD;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,GAAG;IAYZ;;OAEG;IACH,KAAK;CAKN"}
@@ -7,6 +7,7 @@ var _LoggingController_instances, _LoggingController_generateId;
7
7
  import { BaseController } from "@metamask/base-controller";
8
8
  import { v1 as random } from "uuid";
9
9
  const name = 'LoggingController';
10
+ const MESSENGER_EXPOSED_METHODS = ['add', 'clear'];
10
11
  const metadata = {
11
12
  logs: {
12
13
  includeInStateLogs: true,
@@ -40,7 +41,7 @@ export class LoggingController extends BaseController {
40
41
  },
41
42
  });
42
43
  _LoggingController_instances.add(this);
43
- this.messenger.registerActionHandler(`${name}:add`, (log) => this.add(log));
44
+ this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
44
45
  }
45
46
  /**
46
47
  * Add log to the state.
@@ -1 +1 @@
1
- {"version":3,"file":"LoggingController.mjs","sourceRoot":"","sources":["../src/LoggingController.ts"],"names":[],"mappings":";;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,aAAa;AA0BpC,MAAM,IAAI,GAAG,mBAAmB,CAAC;AA8BjC,MAAM,QAAQ,GAA0C;IACtD,IAAI,EAAE;QACJ,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,KAAK;KAChB;CACF,CAAC;AAEF,MAAM,YAAY,GAAG;IACnB,IAAI,EAAE,EAAE;CACT,CAAC;AAEF;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,cAItC;IACC;;;;;;OAMG;IACH,YAAY,EACV,SAAS,EACT,KAAK,GAIN;QACC,KAAK,CAAC;YACJ,IAAI;YACJ,QAAQ;YACR,SAAS;YACT,KAAK,EAAE;gBACL,GAAG,YAAY;gBACf,GAAG,KAAK;aACT;SACF,CAAC,CAAC;;QAEH,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC,GAAG,IAAI,MAAe,EAAE,CAAC,GAAQ,EAAE,EAAE,CACxE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CACd,CAAC;IACJ,CAAC;IAmBD;;;;OAIG;IACH,GAAG,CAAC,GAAQ;QACV,MAAM,MAAM,GAAa;YACvB,EAAE,EAAE,uBAAA,IAAI,mEAAY,MAAhB,IAAI,CAAc;YACtB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,GAAG;SACJ,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,IAAI,GAAG,EAAE,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;;IAhCG,IAAI,EAAE,GAAG,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAC7B,EAAE,GAAG,MAAM,EAAE,CAAC;IAChB,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,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';\nimport { v1 as random } from 'uuid';\n\nimport type { Log } from './logTypes';\n\n/**\n * LogEntry is the entry that will be added to the logging controller state.\n * It consists of a entry key that must be on of the Log union types, and an\n * additional id and timestamp.\n */\nexport type LogEntry = {\n id: string;\n timestamp: number;\n log: Log;\n};\n\n/**\n * Logging controller state\n *\n * @property logs - An object of logs indexed by their ids\n */\nexport type LoggingControllerState = {\n logs: {\n [id: string]: LogEntry;\n };\n};\n\nconst name = 'LoggingController';\n\n/**\n * An action to add log messages to the controller state.\n */\nexport type AddLog = {\n type: `${typeof name}:add`;\n handler: LoggingController['add'];\n};\n\nexport type LoggingControllerGetStateAction = ControllerGetStateAction<\n typeof name,\n LoggingControllerState\n>;\n\nexport type LoggingControllerActions = LoggingControllerGetStateAction | AddLog;\n\nexport type LoggingControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof name,\n LoggingControllerState\n>;\n\nexport type LoggingControllerEvents = LoggingControllerStateChangeEvent;\n\nexport type LoggingControllerMessenger = Messenger<\n typeof name,\n LoggingControllerActions,\n LoggingControllerEvents\n>;\n\nconst metadata: StateMetadata<LoggingControllerState> = {\n logs: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n};\n\nconst defaultState = {\n logs: {},\n};\n\n/**\n * Controller that manages a list of logs for signature requests.\n */\nexport class LoggingController extends BaseController<\n typeof name,\n LoggingControllerState,\n LoggingControllerMessenger\n> {\n /**\n * Creates a LoggingController instance.\n *\n * @param options - Constructor options\n * @param options.messenger - An instance of the Messenger\n * @param options.state - Initial state to set on this controller.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: LoggingControllerMessenger;\n state?: Partial<LoggingControllerState>;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: {\n ...defaultState,\n ...state,\n },\n });\n\n this.messenger.registerActionHandler(`${name}:add` as const, (log: Log) =>\n this.add(log),\n );\n }\n\n /**\n * Method to generate a randomId and ensures no collision with existing ids.\n *\n * We may want to end up using a hashing mechanism to make ids deterministic\n * by the *data* passed in, and then make each key an array of logs that\n * match that id.\n *\n * @returns unique id\n */\n #generateId(): string {\n let id = random();\n while (id in this.state.logs) {\n id = random();\n }\n return id;\n }\n\n /**\n * Add log to the state.\n *\n * @param log - Log to add to the controller\n */\n add(log: Log) {\n const newLog: LogEntry = {\n id: this.#generateId(),\n timestamp: Date.now(),\n log,\n };\n\n this.update((state) => {\n state.logs[newLog.id] = newLog;\n });\n }\n\n /**\n * Removes all log entries.\n */\n clear() {\n this.update((state) => {\n state.logs = {};\n });\n }\n}\n"]}
1
+ {"version":3,"file":"LoggingController.mjs","sourceRoot":"","sources":["../src/LoggingController.ts"],"names":[],"mappings":";;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,aAAa;AA2BpC,MAAM,IAAI,GAAG,mBAAmB,CAAC;AAEjC,MAAM,yBAAyB,GAAG,CAAC,KAAK,EAAE,OAAO,CAAU,CAAC;AAwB5D,MAAM,QAAQ,GAA0C;IACtD,IAAI,EAAE;QACJ,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,KAAK;KAChB;CACF,CAAC;AAEF,MAAM,YAAY,GAAG;IACnB,IAAI,EAAE,EAAE;CACT,CAAC;AAEF;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,cAItC;IACC;;;;;;OAMG;IACH,YAAY,EACV,SAAS,EACT,KAAK,GAIN;QACC,KAAK,CAAC;YACJ,IAAI;YACJ,QAAQ;YACR,SAAS;YACT,KAAK,EAAE;gBACL,GAAG,YAAY;gBACf,GAAG,KAAK;aACT;SACF,CAAC,CAAC;;QAEH,IAAI,CAAC,SAAS,CAAC,4BAA4B,CACzC,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAmBD;;;;OAIG;IACH,GAAG,CAAC,GAAQ;QACV,MAAM,MAAM,GAAa;YACvB,EAAE,EAAE,uBAAA,IAAI,mEAAY,MAAhB,IAAI,CAAc;YACtB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,GAAG;SACJ,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,IAAI,GAAG,EAAE,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;;IAhCG,IAAI,EAAE,GAAG,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAC7B,EAAE,GAAG,MAAM,EAAE,CAAC;IAChB,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,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';\nimport { v1 as random } from 'uuid';\n\nimport type { LoggingControllerMethodActions } from './LoggingController-method-action-types';\nimport type { Log } from './logTypes';\n\n/**\n * LogEntry is the entry that will be added to the logging controller state.\n * It consists of a entry key that must be on of the Log union types, and an\n * additional id and timestamp.\n */\nexport type LogEntry = {\n id: string;\n timestamp: number;\n log: Log;\n};\n\n/**\n * Logging controller state\n *\n * @property logs - An object of logs indexed by their ids\n */\nexport type LoggingControllerState = {\n logs: {\n [id: string]: LogEntry;\n };\n};\n\nconst name = 'LoggingController';\n\nconst MESSENGER_EXPOSED_METHODS = ['add', 'clear'] as const;\n\nexport type LoggingControllerGetStateAction = ControllerGetStateAction<\n typeof name,\n LoggingControllerState\n>;\n\nexport type LoggingControllerActions =\n | LoggingControllerGetStateAction\n | LoggingControllerMethodActions;\n\nexport type LoggingControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof name,\n LoggingControllerState\n>;\n\nexport type LoggingControllerEvents = LoggingControllerStateChangeEvent;\n\nexport type LoggingControllerMessenger = Messenger<\n typeof name,\n LoggingControllerActions,\n LoggingControllerEvents\n>;\n\nconst metadata: StateMetadata<LoggingControllerState> = {\n logs: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n};\n\nconst defaultState = {\n logs: {},\n};\n\n/**\n * Controller that manages a list of logs for signature requests.\n */\nexport class LoggingController extends BaseController<\n typeof name,\n LoggingControllerState,\n LoggingControllerMessenger\n> {\n /**\n * Creates a LoggingController instance.\n *\n * @param options - Constructor options\n * @param options.messenger - An instance of the Messenger\n * @param options.state - Initial state to set on this controller.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: LoggingControllerMessenger;\n state?: Partial<LoggingControllerState>;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: {\n ...defaultState,\n ...state,\n },\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Method to generate a randomId and ensures no collision with existing ids.\n *\n * We may want to end up using a hashing mechanism to make ids deterministic\n * by the *data* passed in, and then make each key an array of logs that\n * match that id.\n *\n * @returns unique id\n */\n #generateId(): string {\n let id = random();\n while (id in this.state.logs) {\n id = random();\n }\n return id;\n }\n\n /**\n * Add log to the state.\n *\n * @param log - Log to add to the controller\n */\n add(log: Log) {\n const newLog: LogEntry = {\n id: this.#generateId(),\n timestamp: Date.now(),\n log,\n };\n\n this.update((state) => {\n state.logs[newLog.id] = newLog;\n });\n }\n\n /**\n * Removes all log entries.\n */\n clear() {\n this.update((state) => {\n state.logs = {};\n });\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAoC;AACpC,uDAA2B","sourcesContent":["export * from './LoggingController';\nexport * from './logTypes';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAoC;AAKpC,uDAA2B","sourcesContent":["export * from './LoggingController';\nexport type {\n LoggingControllerAddAction,\n LoggingControllerClearAction,\n} from './LoggingController-method-action-types';\nexport * from './logTypes';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./LoggingController.cjs";
2
+ export type { LoggingControllerAddAction, LoggingControllerClearAction, } from "./LoggingController-method-action-types.cjs";
2
3
  export * from "./logTypes/index.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,wCAAoC;AACpC,qCAA2B"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wCAAoC;AACpC,YAAY,EACV,0BAA0B,EAC1B,4BAA4B,GAC7B,oDAAgD;AACjD,qCAA2B"}
package/dist/index.d.mts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./LoggingController.mjs";
2
+ export type { LoggingControllerAddAction, LoggingControllerClearAction, } from "./LoggingController-method-action-types.mjs";
2
3
  export * from "./logTypes/index.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,wCAAoC;AACpC,qCAA2B"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wCAAoC;AACpC,YAAY,EACV,0BAA0B,EAC1B,4BAA4B,GAC7B,oDAAgD;AACjD,qCAA2B"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wCAAoC;AACpC,qCAA2B","sourcesContent":["export * from './LoggingController';\nexport * from './logTypes';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wCAAoC;AAKpC,qCAA2B","sourcesContent":["export * from './LoggingController';\nexport type {\n LoggingControllerAddAction,\n LoggingControllerClearAction,\n} from './LoggingController-method-action-types';\nexport * from './logTypes';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/logging-controller",
3
- "version": "7.0.1-preview-25d2d4502",
3
+ "version": "8.0.0-preview-152e02d",
4
4
  "description": "Manages logging data to assist users and support staff",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -40,6 +40,7 @@
40
40
  "build:docs": "typedoc",
41
41
  "changelog:update": "../../scripts/update-changelog.sh @metamask/logging-controller",
42
42
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/logging-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",
@@ -59,6 +60,7 @@
59
60
  "deepmerge": "^4.2.2",
60
61
  "jest": "^29.7.0",
61
62
  "ts-jest": "^29.2.5",
63
+ "tsx": "^4.20.5",
62
64
  "typedoc": "^0.25.13",
63
65
  "typedoc-plugin-missing-exports": "^2.0.0",
64
66
  "typescript": "~5.3.3"