@metamask-previews/logging-controller 8.0.2-preview-823dcff → 9.0.0-preview-9c0f91815
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 +11 -4
- package/dist/LoggingController.cjs +20 -11
- package/dist/LoggingController.cjs.map +1 -1
- package/dist/LoggingController.d.cts +3 -1
- package/dist/LoggingController.d.cts.map +1 -1
- package/dist/LoggingController.d.mts +3 -1
- package/dist/LoggingController.d.mts.map +1 -1
- package/dist/LoggingController.mjs +21 -12
- package/dist/LoggingController.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [9.0.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **BREAKING:** Add optional `expiryTime` constructor argument, by default logs are pruned after 7 days ([#9839](https://github.com/MetaMask/core/pull/9839))
|
|
15
|
+
|
|
10
16
|
### Changed
|
|
11
17
|
|
|
12
18
|
- Bump `@metamask/controller-utils` from `^12.0.0` to `^12.3.0` ([#8774](https://github.com/MetaMask/core/pull/8774), [#9058](https://github.com/MetaMask/core/pull/9058), [#9083](https://github.com/MetaMask/core/pull/9083), [#9218](https://github.com/MetaMask/core/pull/9218))
|
|
@@ -79,8 +85,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
79
85
|
|
|
80
86
|
### Changed
|
|
81
87
|
|
|
82
|
-
- Bump `@metamask/base-controller` from `^7.0.2` to `^8.0.0` ([#5079](https://github.com/MetaMask/core/pull/5079)
|
|
83
|
-
- Bump `@metamask/controller-utils` from `^11.4.4` to `^11.5.0` ([#5135](https://github.com/MetaMask/core/pull/5135)
|
|
88
|
+
- Bump `@metamask/base-controller` from `^7.0.2` to `^8.0.0` ([#5079](https://github.com/MetaMask/core/pull/5079), [#5305](https://github.com/MetaMask/core/pull/5305))
|
|
89
|
+
- Bump `@metamask/controller-utils` from `^11.4.4` to `^11.5.0` ([#5135](https://github.com/MetaMask/core/pull/5135), [#5272](https://github.com/MetaMask/core/pull/5272))
|
|
84
90
|
|
|
85
91
|
## [6.0.3]
|
|
86
92
|
|
|
@@ -107,7 +113,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
107
113
|
["Are the Types Wrong?"](https://arethetypeswrong.github.io/) tool as
|
|
108
114
|
["masquerading as CJS"](https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseCJS.md).
|
|
109
115
|
All of the ATTW checks now pass.
|
|
110
|
-
- Remove chunk files ([#4648](https://github.com/MetaMask/core/pull/4648))
|
|
116
|
+
- Remove chunk files ([#4648](https://github.com/MetaMask/core/pull/4648))
|
|
111
117
|
- Previously, the build tool we used to generate JavaScript files extracted
|
|
112
118
|
common code to "chunk" files. While this was intended to make this package
|
|
113
119
|
more tree-shakeable, it also made debugging more difficult for our
|
|
@@ -226,7 +232,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
226
232
|
- Initial Release
|
|
227
233
|
- Add logging controller ([#1089](https://github.com/MetaMask/core.git/pull/1089))
|
|
228
234
|
|
|
229
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/logging-controller@
|
|
235
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/logging-controller@9.0.0...HEAD
|
|
236
|
+
[9.0.0]: https://github.com/MetaMask/core/compare/@metamask/logging-controller@8.0.2...@metamask/logging-controller@9.0.0
|
|
230
237
|
[8.0.2]: https://github.com/MetaMask/core/compare/@metamask/logging-controller@8.0.1...@metamask/logging-controller@8.0.2
|
|
231
238
|
[8.0.1]: https://github.com/MetaMask/core/compare/@metamask/logging-controller@8.0.0...@metamask/logging-controller@8.0.1
|
|
232
239
|
[8.0.0]: https://github.com/MetaMask/core/compare/@metamask/logging-controller@7.0.1...@metamask/logging-controller@8.0.0
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
2
8
|
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
9
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
12
|
};
|
|
7
|
-
var
|
|
13
|
+
var _LoggingController_expiryTime;
|
|
8
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
15
|
exports.LoggingController = void 0;
|
|
10
16
|
const base_controller_1 = require("@metamask/base-controller");
|
|
17
|
+
const utils_1 = require("@metamask/utils");
|
|
11
18
|
const uuid_1 = require("uuid");
|
|
12
19
|
const name = 'LoggingController';
|
|
13
20
|
const MESSENGER_EXPOSED_METHODS = ['add', 'clear'];
|
|
@@ -32,8 +39,9 @@ class LoggingController extends base_controller_1.BaseController {
|
|
|
32
39
|
* @param options - Constructor options
|
|
33
40
|
* @param options.messenger - An instance of the Messenger
|
|
34
41
|
* @param options.state - Initial state to set on this controller.
|
|
42
|
+
* @param options.expiryTime - The number of milliseconds before we consider a log entry expired.
|
|
35
43
|
*/
|
|
36
|
-
constructor({ messenger, state, }) {
|
|
44
|
+
constructor({ messenger, state, expiryTime = (0, utils_1.inMilliseconds)(7, utils_1.Duration.Day), }) {
|
|
37
45
|
super({
|
|
38
46
|
name,
|
|
39
47
|
metadata,
|
|
@@ -43,7 +51,8 @@ class LoggingController extends base_controller_1.BaseController {
|
|
|
43
51
|
...state,
|
|
44
52
|
},
|
|
45
53
|
});
|
|
46
|
-
|
|
54
|
+
_LoggingController_expiryTime.set(this, void 0);
|
|
55
|
+
__classPrivateFieldSet(this, _LoggingController_expiryTime, expiryTime, "f");
|
|
47
56
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
48
57
|
}
|
|
49
58
|
/**
|
|
@@ -53,11 +62,17 @@ class LoggingController extends base_controller_1.BaseController {
|
|
|
53
62
|
*/
|
|
54
63
|
add(log) {
|
|
55
64
|
const newLog = {
|
|
56
|
-
id:
|
|
65
|
+
id: (0, uuid_1.v4)(),
|
|
57
66
|
timestamp: Date.now(),
|
|
58
67
|
log,
|
|
59
68
|
};
|
|
69
|
+
const expiry = Date.now() - __classPrivateFieldGet(this, _LoggingController_expiryTime, "f");
|
|
60
70
|
this.update((state) => {
|
|
71
|
+
for (const [id, entry] of Object.entries(state.logs)) {
|
|
72
|
+
if (entry.timestamp < expiry) {
|
|
73
|
+
delete state.logs[id];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
61
76
|
state.logs[newLog.id] = newLog;
|
|
62
77
|
});
|
|
63
78
|
}
|
|
@@ -71,11 +86,5 @@ class LoggingController extends base_controller_1.BaseController {
|
|
|
71
86
|
}
|
|
72
87
|
}
|
|
73
88
|
exports.LoggingController = LoggingController;
|
|
74
|
-
|
|
75
|
-
let id = (0, uuid_1.v1)();
|
|
76
|
-
while (id in this.state.logs) {
|
|
77
|
-
id = (0, uuid_1.v1)();
|
|
78
|
-
}
|
|
79
|
-
return id;
|
|
80
|
-
};
|
|
89
|
+
_LoggingController_expiryTime = new WeakMap();
|
|
81
90
|
//# sourceMappingURL=LoggingController.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LoggingController.cjs","sourceRoot":"","sources":["../src/LoggingController.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LoggingController.cjs","sourceRoot":"","sources":["../src/LoggingController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,+DAA2D;AAE3D,2CAA2D;AAC3D,+BAAkC;AA2BlC,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,MAAa,iBAAkB,SAAQ,gCAItC;IAGC;;;;;;;OAOG;IACH,YAAY,EACV,SAAS,EACT,KAAK,EACL,UAAU,GAAG,IAAA,sBAAc,EAAC,CAAC,EAAE,gBAAQ,CAAC,GAAG,CAAC,GAK7C;QACC,KAAK,CAAC;YACJ,IAAI;YACJ,QAAQ;YACR,SAAS;YACT,KAAK,EAAE;gBACL,GAAG,YAAY;gBACf,GAAG,KAAK;aACT;SACF,CAAC,CAAC;QA3BI,gDAAoB;QA6B3B,uBAAA,IAAI,iCAAe,UAAU,MAAA,CAAC;QAE9B,IAAI,CAAC,SAAS,CAAC,4BAA4B,CACzC,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,GAAQ;QACV,MAAM,MAAM,GAAa;YACvB,EAAE,EAAE,IAAA,SAAI,GAAE;YACV,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,GAAG;SACJ,CAAC;QAEF,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,uBAAA,IAAI,qCAAY,CAAC;QAE7C,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrD,IAAI,KAAK,CAAC,SAAS,GAAG,MAAM,EAAE,CAAC;oBAC7B,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACxB,CAAC;YACH,CAAC;YACD,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;AA1ED,8CA0EC","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 { Duration, inMilliseconds } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport type { LoggingControllerMethodActions } from './LoggingController-method-action-types.js';\nimport type { Log } from './logTypes/index.js';\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 readonly #expiryTime: number;\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 * @param options.expiryTime - The number of milliseconds before we consider a log entry expired.\n */\n constructor({\n messenger,\n state,\n expiryTime = inMilliseconds(7, Duration.Day),\n }: {\n messenger: LoggingControllerMessenger;\n state?: Partial<LoggingControllerState>;\n expiryTime?: number;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: {\n ...defaultState,\n ...state,\n },\n });\n\n this.#expiryTime = expiryTime;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\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: uuid(),\n timestamp: Date.now(),\n log,\n };\n\n const expiry = Date.now() - this.#expiryTime;\n\n this.update((state) => {\n for (const [id, entry] of Object.entries(state.logs)) {\n if (entry.timestamp < expiry) {\n delete state.logs[id];\n }\n }\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"]}
|
|
@@ -40,10 +40,12 @@ export declare class LoggingController extends BaseController<typeof name, Loggi
|
|
|
40
40
|
* @param options - Constructor options
|
|
41
41
|
* @param options.messenger - An instance of the Messenger
|
|
42
42
|
* @param options.state - Initial state to set on this controller.
|
|
43
|
+
* @param options.expiryTime - The number of milliseconds before we consider a log entry expired.
|
|
43
44
|
*/
|
|
44
|
-
constructor({ messenger, state, }: {
|
|
45
|
+
constructor({ messenger, state, expiryTime, }: {
|
|
45
46
|
messenger: LoggingControllerMessenger;
|
|
46
47
|
state?: Partial<LoggingControllerState>;
|
|
48
|
+
expiryTime?: number;
|
|
47
49
|
});
|
|
48
50
|
/**
|
|
49
51
|
* Add log to the state.
|
|
@@ -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;
|
|
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;AAIrD,OAAO,KAAK,EAAE,8BAA8B,EAAE,oDAAmD;AACjG,OAAO,KAAK,EAAE,GAAG,EAAE,6BAA4B;AAE/C;;;;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;AAIjC,MAAM,MAAM,+BAA+B,GAAG,wBAAwB,CACpE,OAAO,IAAI,EACX,sBAAsB,CACvB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAChC,+BAA+B,GAC/B,8BAA8B,CAAC;AAEnC,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,sBAAsB,EACtB,0BAA0B,CAC3B;;IAGC;;;;;;;OAOG;gBACS,EACV,SAAS,EACT,KAAK,EACL,UAA4C,GAC7C,EAAE;QACD,SAAS,EAAE,0BAA0B,CAAC;QACtC,KAAK,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAC;QACxC,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB;IAmBD;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,GAAG;IAmBZ;;OAEG;IACH,KAAK;CAKN"}
|
|
@@ -40,10 +40,12 @@ export declare class LoggingController extends BaseController<typeof name, Loggi
|
|
|
40
40
|
* @param options - Constructor options
|
|
41
41
|
* @param options.messenger - An instance of the Messenger
|
|
42
42
|
* @param options.state - Initial state to set on this controller.
|
|
43
|
+
* @param options.expiryTime - The number of milliseconds before we consider a log entry expired.
|
|
43
44
|
*/
|
|
44
|
-
constructor({ messenger, state, }: {
|
|
45
|
+
constructor({ messenger, state, expiryTime, }: {
|
|
45
46
|
messenger: LoggingControllerMessenger;
|
|
46
47
|
state?: Partial<LoggingControllerState>;
|
|
48
|
+
expiryTime?: number;
|
|
47
49
|
});
|
|
48
50
|
/**
|
|
49
51
|
* Add log to the state.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LoggingController.d.mts","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;
|
|
1
|
+
{"version":3,"file":"LoggingController.d.mts","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;AAIrD,OAAO,KAAK,EAAE,8BAA8B,EAAE,oDAAmD;AACjG,OAAO,KAAK,EAAE,GAAG,EAAE,6BAA4B;AAE/C;;;;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;AAIjC,MAAM,MAAM,+BAA+B,GAAG,wBAAwB,CACpE,OAAO,IAAI,EACX,sBAAsB,CACvB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAChC,+BAA+B,GAC/B,8BAA8B,CAAC;AAEnC,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,sBAAsB,EACtB,0BAA0B,CAC3B;;IAGC;;;;;;;OAOG;gBACS,EACV,SAAS,EACT,KAAK,EACL,UAA4C,GAC7C,EAAE;QACD,SAAS,EAAE,0BAA0B,CAAC;QACtC,KAAK,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAC;QACxC,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB;IAmBD;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,GAAG;IAmBZ;;OAEG;IACH,KAAK;CAKN"}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
1
7
|
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
8
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
11
|
};
|
|
6
|
-
var
|
|
12
|
+
var _LoggingController_expiryTime;
|
|
7
13
|
import { BaseController } from "@metamask/base-controller";
|
|
8
|
-
import {
|
|
14
|
+
import { Duration, inMilliseconds } from "@metamask/utils";
|
|
15
|
+
import { v4 as uuid } from "uuid";
|
|
9
16
|
const name = 'LoggingController';
|
|
10
17
|
const MESSENGER_EXPOSED_METHODS = ['add', 'clear'];
|
|
11
18
|
const metadata = {
|
|
@@ -29,8 +36,9 @@ export class LoggingController extends BaseController {
|
|
|
29
36
|
* @param options - Constructor options
|
|
30
37
|
* @param options.messenger - An instance of the Messenger
|
|
31
38
|
* @param options.state - Initial state to set on this controller.
|
|
39
|
+
* @param options.expiryTime - The number of milliseconds before we consider a log entry expired.
|
|
32
40
|
*/
|
|
33
|
-
constructor({ messenger, state, }) {
|
|
41
|
+
constructor({ messenger, state, expiryTime = inMilliseconds(7, Duration.Day), }) {
|
|
34
42
|
super({
|
|
35
43
|
name,
|
|
36
44
|
metadata,
|
|
@@ -40,7 +48,8 @@ export class LoggingController extends BaseController {
|
|
|
40
48
|
...state,
|
|
41
49
|
},
|
|
42
50
|
});
|
|
43
|
-
|
|
51
|
+
_LoggingController_expiryTime.set(this, void 0);
|
|
52
|
+
__classPrivateFieldSet(this, _LoggingController_expiryTime, expiryTime, "f");
|
|
44
53
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
45
54
|
}
|
|
46
55
|
/**
|
|
@@ -50,11 +59,17 @@ export class LoggingController extends BaseController {
|
|
|
50
59
|
*/
|
|
51
60
|
add(log) {
|
|
52
61
|
const newLog = {
|
|
53
|
-
id:
|
|
62
|
+
id: uuid(),
|
|
54
63
|
timestamp: Date.now(),
|
|
55
64
|
log,
|
|
56
65
|
};
|
|
66
|
+
const expiry = Date.now() - __classPrivateFieldGet(this, _LoggingController_expiryTime, "f");
|
|
57
67
|
this.update((state) => {
|
|
68
|
+
for (const [id, entry] of Object.entries(state.logs)) {
|
|
69
|
+
if (entry.timestamp < expiry) {
|
|
70
|
+
delete state.logs[id];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
58
73
|
state.logs[newLog.id] = newLog;
|
|
59
74
|
});
|
|
60
75
|
}
|
|
@@ -67,11 +82,5 @@ export class LoggingController extends BaseController {
|
|
|
67
82
|
});
|
|
68
83
|
}
|
|
69
84
|
}
|
|
70
|
-
|
|
71
|
-
let id = random();
|
|
72
|
-
while (id in this.state.logs) {
|
|
73
|
-
id = random();
|
|
74
|
-
}
|
|
75
|
-
return id;
|
|
76
|
-
};
|
|
85
|
+
_LoggingController_expiryTime = new WeakMap();
|
|
77
86
|
//# sourceMappingURL=LoggingController.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LoggingController.mjs","sourceRoot":"","sources":["../src/LoggingController.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LoggingController.mjs","sourceRoot":"","sources":["../src/LoggingController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,wBAAwB;AAC3D,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AA2BlC,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;IAGC;;;;;;;OAOG;IACH,YAAY,EACV,SAAS,EACT,KAAK,EACL,UAAU,GAAG,cAAc,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC,GAK7C;QACC,KAAK,CAAC;YACJ,IAAI;YACJ,QAAQ;YACR,SAAS;YACT,KAAK,EAAE;gBACL,GAAG,YAAY;gBACf,GAAG,KAAK;aACT;SACF,CAAC,CAAC;QA3BI,gDAAoB;QA6B3B,uBAAA,IAAI,iCAAe,UAAU,MAAA,CAAC;QAE9B,IAAI,CAAC,SAAS,CAAC,4BAA4B,CACzC,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,GAAQ;QACV,MAAM,MAAM,GAAa;YACvB,EAAE,EAAE,IAAI,EAAE;YACV,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,GAAG;SACJ,CAAC;QAEF,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,uBAAA,IAAI,qCAAY,CAAC;QAE7C,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrD,IAAI,KAAK,CAAC,SAAS,GAAG,MAAM,EAAE,CAAC;oBAC7B,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACxB,CAAC;YACH,CAAC;YACD,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","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 { Duration, inMilliseconds } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport type { LoggingControllerMethodActions } from './LoggingController-method-action-types.js';\nimport type { Log } from './logTypes/index.js';\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 readonly #expiryTime: number;\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 * @param options.expiryTime - The number of milliseconds before we consider a log entry expired.\n */\n constructor({\n messenger,\n state,\n expiryTime = inMilliseconds(7, Duration.Day),\n }: {\n messenger: LoggingControllerMessenger;\n state?: Partial<LoggingControllerState>;\n expiryTime?: number;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: {\n ...defaultState,\n ...state,\n },\n });\n\n this.#expiryTime = expiryTime;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\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: uuid(),\n timestamp: Date.now(),\n log,\n };\n\n const expiry = Date.now() - this.#expiryTime;\n\n this.update((state) => {\n for (const [id, entry] of Object.entries(state.logs)) {\n if (entry.timestamp < expiry) {\n delete state.logs[id];\n }\n }\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/logging-controller",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-preview-9c0f91815",
|
|
4
4
|
"description": "Manages logging data to assist users and support staff",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@metamask/base-controller": "^9.1.0",
|
|
59
|
-
"@metamask/controller-utils": "^12.3.0",
|
|
60
59
|
"@metamask/messenger": "^2.0.0",
|
|
60
|
+
"@metamask/utils": "^11.11.0",
|
|
61
61
|
"uuid": "^8.3.2"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|