@metamask-previews/error-reporting-service 2.2.1-preview-1f64ffa6 → 2.2.1-preview-63ea58af

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
@@ -27,8 +27,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
27
27
 
28
28
  ### Changed
29
29
 
30
- - **BREAKING:** Use new `Messenger` from `@metamask/messenger` ([#6462](https://github.com/MetaMask/core/pull/6462))
31
- - Previously, `ErrorReportingService` accepted a `RestrictedMessenger` instance from `@metamask/base-controller`.
32
30
  - Bump `@metamask/base-controller` from `^8.0.1` to `^8.4.0` ([#6284](https://github.com/MetaMask/core/pull/6284), [#6355](https://github.com/MetaMask/core/pull/6355), [#6465](https://github.com/MetaMask/core/pull/6465), [#6632](https://github.com/MetaMask/core/pull/6632))
33
31
 
34
32
  ## [2.0.0]
@@ -29,10 +29,12 @@ exports.ErrorReportingService = void 0;
29
29
  *
30
30
  * // Define the messenger type for the controller.
31
31
  * type AllowedActions = ErrorReportingServiceCaptureExceptionAction;
32
- * type ExampleControllerMessenger = Messenger<
32
+ * type ExampleControllerMessenger = RestrictedMessenger<
33
33
  * 'ExampleController',
34
34
  * AllowedActions,
35
35
  * never,
36
+ * AllowedActions['type'],
37
+ * never
36
38
  * >;
37
39
  *
38
40
  * // Define the controller.
@@ -44,7 +46,7 @@ exports.ErrorReportingService = void 0;
44
46
  * doSomething() {
45
47
  * // Imagine that we do something that produces an error and we want to
46
48
  * // report the error.
47
- * this.messenger.call(
49
+ * this.messagingSystem.call(
48
50
  * 'ErrorReportingService:captureException',
49
51
  * new Error('Something went wrong'),
50
52
  * );
@@ -57,43 +59,23 @@ exports.ErrorReportingService = void 0;
57
59
  * import { ErrorReportingService } from '@metamask/error-reporting-service';
58
60
  * import { ExampleController } from './example-controller';
59
61
  *
60
- * type AllActions = MessengerActions<ErrorReportingServiceMessenger>;
61
- *
62
- * type AllEvents = MessengerEvents<ErrorReportingServiceMessenger>;
63
- *
64
- * type RootMessenger = Messenger<'Root', AllActions, AllEvents>;
65
- *
66
62
  * // Create a global messenger.
67
63
  * const globalMessenger = new Messenger();
68
64
  *
69
65
  * // Register handler for the `ErrorReportingService:captureException`
70
66
  * // action in the global messenger.
71
- * const errorReportingServiceMessenger = new Messenger<
72
- * 'ErrorReportingService',
73
- * MessengerActions<ErrorReportingServiceMessenger>,
74
- * MessengerEvents<ErrorReportingServiceMessenger>,
75
- * RootMessenger
76
- * >({
77
- * namespace: 'ErrorReportingService',
78
- * parent: globalMessenger,
67
+ * const errorReportingServiceMessenger = globalMessenger.getRestricted({
68
+ * allowedActions: [],
69
+ * allowedEvents: [],
79
70
  * });
80
71
  * const errorReportingService = new ErrorReportingService({
81
72
  * messenger: errorReportingServiceMessenger,
82
73
  * captureException,
83
74
  * });
84
75
  *
85
- * const exampleControllerMessenger = new Messenger<
86
- * 'ExampleController',
87
- * MessengerActions<ExampleControllerMessenger>,
88
- * MessengerEvents<ExampleControllerMessenger>,
89
- * RootMessenger
90
- * >({
91
- * namespace: 'ExampleController',
92
- * parent: globalMessenger,
93
- * });
94
- * globalMessenger.delegate({
95
- * messenger: exampleControllerMessenger,
96
- * actions: ['ErrorReportingService:captureException'],
76
+ * const exampleControllerMessenger = globalMessenger.getRestricted({
77
+ * allowedActions: ['ErrorReportingService:captureException'],
78
+ * allowedEvents: [],
97
79
  * });
98
80
  * const exampleController = new ExampleController({
99
81
  * messenger: exampleControllerMessenger,
@@ -1 +1 @@
1
- {"version":3,"file":"error-reporting-service.cjs","sourceRoot":"","sources":["../src/error-reporting-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAqDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2FG;AACH,MAAa,qBAAqB;IAShC;;;;;;;;OAQG;IACH,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAgC;QAjBzE,SAAI,GAA4B,uBAAgC,CAAC;QAEjE,UAAK,GAAG,IAAI,CAAC;QAEJ,0DAAoE;QAEpE,mDAA2C;QAYlD,uBAAA,IAAI,oCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,2CAAqB,gBAAgB,MAAA,CAAC;QAE1C,uBAAA,IAAI,wCAAW,CAAC,qBAAqB,CACnC,wCAAwC,EACxC,uBAAA,IAAI,+CAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAClC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,KAAY;QAC3B,uBAAA,IAAI,+CAAkB,MAAtB,IAAI,EAAmB,KAAK,CAAC,CAAC;IAChC,CAAC;CACF;AApCD,sDAoCC","sourcesContent":["import type { Messenger } from '@metamask/messenger';\n\n/**\n * The action which can be used to report an error.\n */\nexport type ErrorReportingServiceCaptureExceptionAction = {\n type: 'ErrorReportingService:captureException';\n handler: ErrorReportingService['captureException'];\n};\n\n/**\n * All actions that {@link ErrorReportingService} registers so that other\n * modules can call them.\n */\nexport type ErrorReportingServiceActions =\n ErrorReportingServiceCaptureExceptionAction;\n\n/**\n * All events that {@link ErrorReportingService} publishes so that other modules\n * can subscribe to them.\n */\nexport type ErrorReportingServiceEvents = never;\n\n/**\n * All actions registered by other modules that {@link ErrorReportingService}\n * calls.\n */\ntype AllowedActions = never;\n\n/**\n * All events published by other modules that {@link ErrorReportingService}\n * subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events that\n * {@link ErrorReportingService} needs to access.\n */\nexport type ErrorReportingServiceMessenger = Messenger<\n 'ErrorReportingService',\n ErrorReportingServiceActions | AllowedActions,\n ErrorReportingServiceEvents | AllowedEvents\n>;\n\n/**\n * The options that {@link ErrorReportingService} takes.\n */\ntype ErrorReportingServiceOptions = {\n captureException: ErrorReportingService['captureException'];\n messenger: ErrorReportingServiceMessenger;\n};\n\n/**\n * `ErrorReportingService` is designed to log an error to an error reporting app\n * such as Sentry, but in an agnostic fashion.\n *\n * @example\n *\n * In this example, we have a controller, and something bad happens, but we want\n * to report an error instead of throwing it.\n *\n * ``` ts\n * // === Controller file ===\n *\n * import type { ErrorReportingServiceCaptureExceptionAction } from '@metamask/error-reporting-service';\n *\n * // Define the messenger type for the controller.\n * type AllowedActions = ErrorReportingServiceCaptureExceptionAction;\n * type ExampleControllerMessenger = Messenger<\n * 'ExampleController',\n * AllowedActions,\n * never,\n * >;\n *\n * // Define the controller.\n * class ExampleController extends BaseController<\n * 'ExampleController',\n * ExampleControllerState,\n * ExampleControllerMessenger\n * > {\n * doSomething() {\n * // Imagine that we do something that produces an error and we want to\n * // report the error.\n * this.messenger.call(\n * 'ErrorReportingService:captureException',\n * new Error('Something went wrong'),\n * );\n * }\n * }\n *\n * // === Initialization file ===\n *\n * import { captureException } from '@sentry/browser';\n * import { ErrorReportingService } from '@metamask/error-reporting-service';\n * import { ExampleController } from './example-controller';\n *\n * type AllActions = MessengerActions<ErrorReportingServiceMessenger>;\n *\n * type AllEvents = MessengerEvents<ErrorReportingServiceMessenger>;\n *\n * type RootMessenger = Messenger<'Root', AllActions, AllEvents>;\n *\n * // Create a global messenger.\n * const globalMessenger = new Messenger();\n *\n * // Register handler for the `ErrorReportingService:captureException`\n * // action in the global messenger.\n * const errorReportingServiceMessenger = new Messenger<\n * 'ErrorReportingService',\n * MessengerActions<ErrorReportingServiceMessenger>,\n * MessengerEvents<ErrorReportingServiceMessenger>,\n * RootMessenger\n * >({\n * namespace: 'ErrorReportingService',\n * parent: globalMessenger,\n * });\n * const errorReportingService = new ErrorReportingService({\n * messenger: errorReportingServiceMessenger,\n * captureException,\n * });\n *\n * const exampleControllerMessenger = new Messenger<\n * 'ExampleController',\n * MessengerActions<ExampleControllerMessenger>,\n * MessengerEvents<ExampleControllerMessenger>,\n * RootMessenger\n * >({\n * namespace: 'ExampleController',\n * parent: globalMessenger,\n * });\n * globalMessenger.delegate({\n * messenger: exampleControllerMessenger,\n * actions: ['ErrorReportingService:captureException'],\n * });\n * const exampleController = new ExampleController({\n * messenger: exampleControllerMessenger,\n * });\n *\n * // === Somewhere else ===\n *\n * // Now this will report an error without throwing it.\n * exampleController.doSomething();\n * ```\n */\nexport class ErrorReportingService {\n name: 'ErrorReportingService' = 'ErrorReportingService' as const;\n\n state = null;\n\n readonly #captureException: ErrorReportingServiceOptions['captureException'];\n\n readonly #messenger: ErrorReportingServiceMessenger;\n\n /**\n * Constructs a new ErrorReportingService.\n *\n * @param options - The options.\n * @param options.messenger - The messenger suited to this\n * ErrorReportingService.\n * @param options.captureException - A function that stores the given error in\n * the error reporting service.\n */\n constructor({ messenger, captureException }: ErrorReportingServiceOptions) {\n this.#messenger = messenger;\n this.#captureException = captureException;\n\n this.#messenger.registerActionHandler(\n 'ErrorReportingService:captureException',\n this.#captureException.bind(this),\n );\n }\n\n /**\n * Reports the given error to an external location.\n *\n * @param error - The error to report.\n */\n captureException(error: Error): void {\n this.#captureException(error);\n }\n}\n"]}
1
+ {"version":3,"file":"error-reporting-service.cjs","sourceRoot":"","sources":["../src/error-reporting-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAuDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,MAAa,qBAAqB;IAShC;;;;;;;;OAQG;IACH,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAgC;QAjBzE,SAAI,GAA4B,uBAAgC,CAAC;QAEjE,UAAK,GAAG,IAAI,CAAC;QAEJ,0DAAoE;QAEpE,mDAA2C;QAYlD,uBAAA,IAAI,oCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,2CAAqB,gBAAgB,MAAA,CAAC;QAE1C,uBAAA,IAAI,wCAAW,CAAC,qBAAqB,CACnC,wCAAwC,EACxC,uBAAA,IAAI,+CAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAClC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,KAAY;QAC3B,uBAAA,IAAI,+CAAkB,MAAtB,IAAI,EAAmB,KAAK,CAAC,CAAC;IAChC,CAAC;CACF;AApCD,sDAoCC","sourcesContent":["import type { RestrictedMessenger } from '@metamask/base-controller';\n\n/**\n * The action which can be used to report an error.\n */\nexport type ErrorReportingServiceCaptureExceptionAction = {\n type: 'ErrorReportingService:captureException';\n handler: ErrorReportingService['captureException'];\n};\n\n/**\n * All actions that {@link ErrorReportingService} registers so that other\n * modules can call them.\n */\nexport type ErrorReportingServiceActions =\n ErrorReportingServiceCaptureExceptionAction;\n\n/**\n * All events that {@link ErrorReportingService} publishes so that other modules\n * can subscribe to them.\n */\nexport type ErrorReportingServiceEvents = never;\n\n/**\n * All actions registered by other modules that {@link ErrorReportingService}\n * calls.\n */\ntype AllowedActions = never;\n\n/**\n * All events published by other modules that {@link ErrorReportingService}\n * subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events that\n * {@link ErrorReportingService} needs to access.\n */\nexport type ErrorReportingServiceMessenger = RestrictedMessenger<\n 'ErrorReportingService',\n ErrorReportingServiceActions | AllowedActions,\n ErrorReportingServiceEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * The options that {@link ErrorReportingService} takes.\n */\ntype ErrorReportingServiceOptions = {\n captureException: ErrorReportingService['captureException'];\n messenger: ErrorReportingServiceMessenger;\n};\n\n/**\n * `ErrorReportingService` is designed to log an error to an error reporting app\n * such as Sentry, but in an agnostic fashion.\n *\n * @example\n *\n * In this example, we have a controller, and something bad happens, but we want\n * to report an error instead of throwing it.\n *\n * ``` ts\n * // === Controller file ===\n *\n * import type { ErrorReportingServiceCaptureExceptionAction } from '@metamask/error-reporting-service';\n *\n * // Define the messenger type for the controller.\n * type AllowedActions = ErrorReportingServiceCaptureExceptionAction;\n * type ExampleControllerMessenger = RestrictedMessenger<\n * 'ExampleController',\n * AllowedActions,\n * never,\n * AllowedActions['type'],\n * never\n * >;\n *\n * // Define the controller.\n * class ExampleController extends BaseController<\n * 'ExampleController',\n * ExampleControllerState,\n * ExampleControllerMessenger\n * > {\n * doSomething() {\n * // Imagine that we do something that produces an error and we want to\n * // report the error.\n * this.messagingSystem.call(\n * 'ErrorReportingService:captureException',\n * new Error('Something went wrong'),\n * );\n * }\n * }\n *\n * // === Initialization file ===\n *\n * import { captureException } from '@sentry/browser';\n * import { ErrorReportingService } from '@metamask/error-reporting-service';\n * import { ExampleController } from './example-controller';\n *\n * // Create a global messenger.\n * const globalMessenger = new Messenger();\n *\n * // Register handler for the `ErrorReportingService:captureException`\n * // action in the global messenger.\n * const errorReportingServiceMessenger = globalMessenger.getRestricted({\n * allowedActions: [],\n * allowedEvents: [],\n * });\n * const errorReportingService = new ErrorReportingService({\n * messenger: errorReportingServiceMessenger,\n * captureException,\n * });\n *\n * const exampleControllerMessenger = globalMessenger.getRestricted({\n * allowedActions: ['ErrorReportingService:captureException'],\n * allowedEvents: [],\n * });\n * const exampleController = new ExampleController({\n * messenger: exampleControllerMessenger,\n * });\n *\n * // === Somewhere else ===\n *\n * // Now this will report an error without throwing it.\n * exampleController.doSomething();\n * ```\n */\nexport class ErrorReportingService {\n name: 'ErrorReportingService' = 'ErrorReportingService' as const;\n\n state = null;\n\n readonly #captureException: ErrorReportingServiceOptions['captureException'];\n\n readonly #messenger: ErrorReportingServiceMessenger;\n\n /**\n * Constructs a new ErrorReportingService.\n *\n * @param options - The options.\n * @param options.messenger - The messenger suited to this\n * ErrorReportingService.\n * @param options.captureException - A function that stores the given error in\n * the error reporting service.\n */\n constructor({ messenger, captureException }: ErrorReportingServiceOptions) {\n this.#messenger = messenger;\n this.#captureException = captureException;\n\n this.#messenger.registerActionHandler(\n 'ErrorReportingService:captureException',\n this.#captureException.bind(this),\n );\n }\n\n /**\n * Reports the given error to an external location.\n *\n * @param error - The error to report.\n */\n captureException(error: Error): void {\n this.#captureException(error);\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { Messenger } from "@metamask/messenger";
1
+ import type { RestrictedMessenger } from "@metamask/base-controller";
2
2
  /**
3
3
  * The action which can be used to report an error.
4
4
  */
@@ -30,7 +30,7 @@ type AllowedEvents = never;
30
30
  * The messenger restricted to actions and events that
31
31
  * {@link ErrorReportingService} needs to access.
32
32
  */
33
- export type ErrorReportingServiceMessenger = Messenger<'ErrorReportingService', ErrorReportingServiceActions | AllowedActions, ErrorReportingServiceEvents | AllowedEvents>;
33
+ export type ErrorReportingServiceMessenger = RestrictedMessenger<'ErrorReportingService', ErrorReportingServiceActions | AllowedActions, ErrorReportingServiceEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
34
34
  /**
35
35
  * The options that {@link ErrorReportingService} takes.
36
36
  */
@@ -54,10 +54,12 @@ type ErrorReportingServiceOptions = {
54
54
  *
55
55
  * // Define the messenger type for the controller.
56
56
  * type AllowedActions = ErrorReportingServiceCaptureExceptionAction;
57
- * type ExampleControllerMessenger = Messenger<
57
+ * type ExampleControllerMessenger = RestrictedMessenger<
58
58
  * 'ExampleController',
59
59
  * AllowedActions,
60
60
  * never,
61
+ * AllowedActions['type'],
62
+ * never
61
63
  * >;
62
64
  *
63
65
  * // Define the controller.
@@ -69,7 +71,7 @@ type ErrorReportingServiceOptions = {
69
71
  * doSomething() {
70
72
  * // Imagine that we do something that produces an error and we want to
71
73
  * // report the error.
72
- * this.messenger.call(
74
+ * this.messagingSystem.call(
73
75
  * 'ErrorReportingService:captureException',
74
76
  * new Error('Something went wrong'),
75
77
  * );
@@ -82,43 +84,23 @@ type ErrorReportingServiceOptions = {
82
84
  * import { ErrorReportingService } from '@metamask/error-reporting-service';
83
85
  * import { ExampleController } from './example-controller';
84
86
  *
85
- * type AllActions = MessengerActions<ErrorReportingServiceMessenger>;
86
- *
87
- * type AllEvents = MessengerEvents<ErrorReportingServiceMessenger>;
88
- *
89
- * type RootMessenger = Messenger<'Root', AllActions, AllEvents>;
90
- *
91
87
  * // Create a global messenger.
92
88
  * const globalMessenger = new Messenger();
93
89
  *
94
90
  * // Register handler for the `ErrorReportingService:captureException`
95
91
  * // action in the global messenger.
96
- * const errorReportingServiceMessenger = new Messenger<
97
- * 'ErrorReportingService',
98
- * MessengerActions<ErrorReportingServiceMessenger>,
99
- * MessengerEvents<ErrorReportingServiceMessenger>,
100
- * RootMessenger
101
- * >({
102
- * namespace: 'ErrorReportingService',
103
- * parent: globalMessenger,
92
+ * const errorReportingServiceMessenger = globalMessenger.getRestricted({
93
+ * allowedActions: [],
94
+ * allowedEvents: [],
104
95
  * });
105
96
  * const errorReportingService = new ErrorReportingService({
106
97
  * messenger: errorReportingServiceMessenger,
107
98
  * captureException,
108
99
  * });
109
100
  *
110
- * const exampleControllerMessenger = new Messenger<
111
- * 'ExampleController',
112
- * MessengerActions<ExampleControllerMessenger>,
113
- * MessengerEvents<ExampleControllerMessenger>,
114
- * RootMessenger
115
- * >({
116
- * namespace: 'ExampleController',
117
- * parent: globalMessenger,
118
- * });
119
- * globalMessenger.delegate({
120
- * messenger: exampleControllerMessenger,
121
- * actions: ['ErrorReportingService:captureException'],
101
+ * const exampleControllerMessenger = globalMessenger.getRestricted({
102
+ * allowedActions: ['ErrorReportingService:captureException'],
103
+ * allowedEvents: [],
122
104
  * });
123
105
  * const exampleController = new ExampleController({
124
106
  * messenger: exampleControllerMessenger,
@@ -1 +1 @@
1
- {"version":3,"file":"error-reporting-service.d.cts","sourceRoot":"","sources":["../src/error-reporting-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD;;GAEG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;CACpD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,4BAA4B,GACtC,2CAA2C,CAAC;AAE9C;;;GAGG;AACH,MAAM,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAEhD;;;GAGG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;;GAGG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,8BAA8B,GAAG,SAAS,CACpD,uBAAuB,EACvB,4BAA4B,GAAG,cAAc,EAC7C,2BAA2B,GAAG,aAAa,CAC5C,CAAC;AAEF;;GAEG;AACH,KAAK,4BAA4B,GAAG;IAClC,gBAAgB,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;IAC5D,SAAS,EAAE,8BAA8B,CAAC;CAC3C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2FG;AACH,qBAAa,qBAAqB;;IAChC,IAAI,EAAE,uBAAuB,CAAoC;IAEjE,KAAK,OAAQ;IAMb;;;;;;;;OAQG;gBACS,EAAE,SAAS,EAAE,gBAAgB,EAAE,EAAE,4BAA4B;IAUzE;;;;OAIG;IACH,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;CAGrC"}
1
+ {"version":3,"file":"error-reporting-service.d.cts","sourceRoot":"","sources":["../src/error-reporting-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,kCAAkC;AAErE;;GAEG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;CACpD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,4BAA4B,GACtC,2CAA2C,CAAC;AAE9C;;;GAGG;AACH,MAAM,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAEhD;;;GAGG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;;GAGG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,8BAA8B,GAAG,mBAAmB,CAC9D,uBAAuB,EACvB,4BAA4B,GAAG,cAAc,EAC7C,2BAA2B,GAAG,aAAa,EAC3C,cAAc,CAAC,MAAM,CAAC,EACtB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC;AAEF;;GAEG;AACH,KAAK,4BAA4B,GAAG;IAClC,gBAAgB,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;IAC5D,SAAS,EAAE,8BAA8B,CAAC;CAC3C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,qBAAa,qBAAqB;;IAChC,IAAI,EAAE,uBAAuB,CAAoC;IAEjE,KAAK,OAAQ;IAMb;;;;;;;;OAQG;gBACS,EAAE,SAAS,EAAE,gBAAgB,EAAE,EAAE,4BAA4B;IAUzE;;;;OAIG;IACH,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;CAGrC"}
@@ -1,4 +1,4 @@
1
- import type { Messenger } from "@metamask/messenger";
1
+ import type { RestrictedMessenger } from "@metamask/base-controller";
2
2
  /**
3
3
  * The action which can be used to report an error.
4
4
  */
@@ -30,7 +30,7 @@ type AllowedEvents = never;
30
30
  * The messenger restricted to actions and events that
31
31
  * {@link ErrorReportingService} needs to access.
32
32
  */
33
- export type ErrorReportingServiceMessenger = Messenger<'ErrorReportingService', ErrorReportingServiceActions | AllowedActions, ErrorReportingServiceEvents | AllowedEvents>;
33
+ export type ErrorReportingServiceMessenger = RestrictedMessenger<'ErrorReportingService', ErrorReportingServiceActions | AllowedActions, ErrorReportingServiceEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
34
34
  /**
35
35
  * The options that {@link ErrorReportingService} takes.
36
36
  */
@@ -54,10 +54,12 @@ type ErrorReportingServiceOptions = {
54
54
  *
55
55
  * // Define the messenger type for the controller.
56
56
  * type AllowedActions = ErrorReportingServiceCaptureExceptionAction;
57
- * type ExampleControllerMessenger = Messenger<
57
+ * type ExampleControllerMessenger = RestrictedMessenger<
58
58
  * 'ExampleController',
59
59
  * AllowedActions,
60
60
  * never,
61
+ * AllowedActions['type'],
62
+ * never
61
63
  * >;
62
64
  *
63
65
  * // Define the controller.
@@ -69,7 +71,7 @@ type ErrorReportingServiceOptions = {
69
71
  * doSomething() {
70
72
  * // Imagine that we do something that produces an error and we want to
71
73
  * // report the error.
72
- * this.messenger.call(
74
+ * this.messagingSystem.call(
73
75
  * 'ErrorReportingService:captureException',
74
76
  * new Error('Something went wrong'),
75
77
  * );
@@ -82,43 +84,23 @@ type ErrorReportingServiceOptions = {
82
84
  * import { ErrorReportingService } from '@metamask/error-reporting-service';
83
85
  * import { ExampleController } from './example-controller';
84
86
  *
85
- * type AllActions = MessengerActions<ErrorReportingServiceMessenger>;
86
- *
87
- * type AllEvents = MessengerEvents<ErrorReportingServiceMessenger>;
88
- *
89
- * type RootMessenger = Messenger<'Root', AllActions, AllEvents>;
90
- *
91
87
  * // Create a global messenger.
92
88
  * const globalMessenger = new Messenger();
93
89
  *
94
90
  * // Register handler for the `ErrorReportingService:captureException`
95
91
  * // action in the global messenger.
96
- * const errorReportingServiceMessenger = new Messenger<
97
- * 'ErrorReportingService',
98
- * MessengerActions<ErrorReportingServiceMessenger>,
99
- * MessengerEvents<ErrorReportingServiceMessenger>,
100
- * RootMessenger
101
- * >({
102
- * namespace: 'ErrorReportingService',
103
- * parent: globalMessenger,
92
+ * const errorReportingServiceMessenger = globalMessenger.getRestricted({
93
+ * allowedActions: [],
94
+ * allowedEvents: [],
104
95
  * });
105
96
  * const errorReportingService = new ErrorReportingService({
106
97
  * messenger: errorReportingServiceMessenger,
107
98
  * captureException,
108
99
  * });
109
100
  *
110
- * const exampleControllerMessenger = new Messenger<
111
- * 'ExampleController',
112
- * MessengerActions<ExampleControllerMessenger>,
113
- * MessengerEvents<ExampleControllerMessenger>,
114
- * RootMessenger
115
- * >({
116
- * namespace: 'ExampleController',
117
- * parent: globalMessenger,
118
- * });
119
- * globalMessenger.delegate({
120
- * messenger: exampleControllerMessenger,
121
- * actions: ['ErrorReportingService:captureException'],
101
+ * const exampleControllerMessenger = globalMessenger.getRestricted({
102
+ * allowedActions: ['ErrorReportingService:captureException'],
103
+ * allowedEvents: [],
122
104
  * });
123
105
  * const exampleController = new ExampleController({
124
106
  * messenger: exampleControllerMessenger,
@@ -1 +1 @@
1
- {"version":3,"file":"error-reporting-service.d.mts","sourceRoot":"","sources":["../src/error-reporting-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD;;GAEG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;CACpD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,4BAA4B,GACtC,2CAA2C,CAAC;AAE9C;;;GAGG;AACH,MAAM,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAEhD;;;GAGG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;;GAGG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,8BAA8B,GAAG,SAAS,CACpD,uBAAuB,EACvB,4BAA4B,GAAG,cAAc,EAC7C,2BAA2B,GAAG,aAAa,CAC5C,CAAC;AAEF;;GAEG;AACH,KAAK,4BAA4B,GAAG;IAClC,gBAAgB,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;IAC5D,SAAS,EAAE,8BAA8B,CAAC;CAC3C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2FG;AACH,qBAAa,qBAAqB;;IAChC,IAAI,EAAE,uBAAuB,CAAoC;IAEjE,KAAK,OAAQ;IAMb;;;;;;;;OAQG;gBACS,EAAE,SAAS,EAAE,gBAAgB,EAAE,EAAE,4BAA4B;IAUzE;;;;OAIG;IACH,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;CAGrC"}
1
+ {"version":3,"file":"error-reporting-service.d.mts","sourceRoot":"","sources":["../src/error-reporting-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,kCAAkC;AAErE;;GAEG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;CACpD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,4BAA4B,GACtC,2CAA2C,CAAC;AAE9C;;;GAGG;AACH,MAAM,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAEhD;;;GAGG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;;GAGG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,8BAA8B,GAAG,mBAAmB,CAC9D,uBAAuB,EACvB,4BAA4B,GAAG,cAAc,EAC7C,2BAA2B,GAAG,aAAa,EAC3C,cAAc,CAAC,MAAM,CAAC,EACtB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC;AAEF;;GAEG;AACH,KAAK,4BAA4B,GAAG;IAClC,gBAAgB,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;IAC5D,SAAS,EAAE,8BAA8B,CAAC;CAC3C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,qBAAa,qBAAqB;;IAChC,IAAI,EAAE,uBAAuB,CAAoC;IAEjE,KAAK,OAAQ;IAMb;;;;;;;;OAQG;gBACS,EAAE,SAAS,EAAE,gBAAgB,EAAE,EAAE,4BAA4B;IAUzE;;;;OAIG;IACH,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;CAGrC"}
@@ -26,10 +26,12 @@ var _ErrorReportingService_captureException, _ErrorReportingService_messenger;
26
26
  *
27
27
  * // Define the messenger type for the controller.
28
28
  * type AllowedActions = ErrorReportingServiceCaptureExceptionAction;
29
- * type ExampleControllerMessenger = Messenger<
29
+ * type ExampleControllerMessenger = RestrictedMessenger<
30
30
  * 'ExampleController',
31
31
  * AllowedActions,
32
32
  * never,
33
+ * AllowedActions['type'],
34
+ * never
33
35
  * >;
34
36
  *
35
37
  * // Define the controller.
@@ -41,7 +43,7 @@ var _ErrorReportingService_captureException, _ErrorReportingService_messenger;
41
43
  * doSomething() {
42
44
  * // Imagine that we do something that produces an error and we want to
43
45
  * // report the error.
44
- * this.messenger.call(
46
+ * this.messagingSystem.call(
45
47
  * 'ErrorReportingService:captureException',
46
48
  * new Error('Something went wrong'),
47
49
  * );
@@ -54,43 +56,23 @@ var _ErrorReportingService_captureException, _ErrorReportingService_messenger;
54
56
  * import { ErrorReportingService } from '@metamask/error-reporting-service';
55
57
  * import { ExampleController } from './example-controller';
56
58
  *
57
- * type AllActions = MessengerActions<ErrorReportingServiceMessenger>;
58
- *
59
- * type AllEvents = MessengerEvents<ErrorReportingServiceMessenger>;
60
- *
61
- * type RootMessenger = Messenger<'Root', AllActions, AllEvents>;
62
- *
63
59
  * // Create a global messenger.
64
60
  * const globalMessenger = new Messenger();
65
61
  *
66
62
  * // Register handler for the `ErrorReportingService:captureException`
67
63
  * // action in the global messenger.
68
- * const errorReportingServiceMessenger = new Messenger<
69
- * 'ErrorReportingService',
70
- * MessengerActions<ErrorReportingServiceMessenger>,
71
- * MessengerEvents<ErrorReportingServiceMessenger>,
72
- * RootMessenger
73
- * >({
74
- * namespace: 'ErrorReportingService',
75
- * parent: globalMessenger,
64
+ * const errorReportingServiceMessenger = globalMessenger.getRestricted({
65
+ * allowedActions: [],
66
+ * allowedEvents: [],
76
67
  * });
77
68
  * const errorReportingService = new ErrorReportingService({
78
69
  * messenger: errorReportingServiceMessenger,
79
70
  * captureException,
80
71
  * });
81
72
  *
82
- * const exampleControllerMessenger = new Messenger<
83
- * 'ExampleController',
84
- * MessengerActions<ExampleControllerMessenger>,
85
- * MessengerEvents<ExampleControllerMessenger>,
86
- * RootMessenger
87
- * >({
88
- * namespace: 'ExampleController',
89
- * parent: globalMessenger,
90
- * });
91
- * globalMessenger.delegate({
92
- * messenger: exampleControllerMessenger,
93
- * actions: ['ErrorReportingService:captureException'],
73
+ * const exampleControllerMessenger = globalMessenger.getRestricted({
74
+ * allowedActions: ['ErrorReportingService:captureException'],
75
+ * allowedEvents: [],
94
76
  * });
95
77
  * const exampleController = new ExampleController({
96
78
  * messenger: exampleControllerMessenger,
@@ -1 +1 @@
1
- {"version":3,"file":"error-reporting-service.mjs","sourceRoot":"","sources":["../src/error-reporting-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAqDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2FG;AACH,MAAM,OAAO,qBAAqB;IAShC;;;;;;;;OAQG;IACH,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAgC;QAjBzE,SAAI,GAA4B,uBAAgC,CAAC;QAEjE,UAAK,GAAG,IAAI,CAAC;QAEJ,0DAAoE;QAEpE,mDAA2C;QAYlD,uBAAA,IAAI,oCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,2CAAqB,gBAAgB,MAAA,CAAC;QAE1C,uBAAA,IAAI,wCAAW,CAAC,qBAAqB,CACnC,wCAAwC,EACxC,uBAAA,IAAI,+CAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAClC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,KAAY;QAC3B,uBAAA,IAAI,+CAAkB,MAAtB,IAAI,EAAmB,KAAK,CAAC,CAAC;IAChC,CAAC;CACF","sourcesContent":["import type { Messenger } from '@metamask/messenger';\n\n/**\n * The action which can be used to report an error.\n */\nexport type ErrorReportingServiceCaptureExceptionAction = {\n type: 'ErrorReportingService:captureException';\n handler: ErrorReportingService['captureException'];\n};\n\n/**\n * All actions that {@link ErrorReportingService} registers so that other\n * modules can call them.\n */\nexport type ErrorReportingServiceActions =\n ErrorReportingServiceCaptureExceptionAction;\n\n/**\n * All events that {@link ErrorReportingService} publishes so that other modules\n * can subscribe to them.\n */\nexport type ErrorReportingServiceEvents = never;\n\n/**\n * All actions registered by other modules that {@link ErrorReportingService}\n * calls.\n */\ntype AllowedActions = never;\n\n/**\n * All events published by other modules that {@link ErrorReportingService}\n * subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events that\n * {@link ErrorReportingService} needs to access.\n */\nexport type ErrorReportingServiceMessenger = Messenger<\n 'ErrorReportingService',\n ErrorReportingServiceActions | AllowedActions,\n ErrorReportingServiceEvents | AllowedEvents\n>;\n\n/**\n * The options that {@link ErrorReportingService} takes.\n */\ntype ErrorReportingServiceOptions = {\n captureException: ErrorReportingService['captureException'];\n messenger: ErrorReportingServiceMessenger;\n};\n\n/**\n * `ErrorReportingService` is designed to log an error to an error reporting app\n * such as Sentry, but in an agnostic fashion.\n *\n * @example\n *\n * In this example, we have a controller, and something bad happens, but we want\n * to report an error instead of throwing it.\n *\n * ``` ts\n * // === Controller file ===\n *\n * import type { ErrorReportingServiceCaptureExceptionAction } from '@metamask/error-reporting-service';\n *\n * // Define the messenger type for the controller.\n * type AllowedActions = ErrorReportingServiceCaptureExceptionAction;\n * type ExampleControllerMessenger = Messenger<\n * 'ExampleController',\n * AllowedActions,\n * never,\n * >;\n *\n * // Define the controller.\n * class ExampleController extends BaseController<\n * 'ExampleController',\n * ExampleControllerState,\n * ExampleControllerMessenger\n * > {\n * doSomething() {\n * // Imagine that we do something that produces an error and we want to\n * // report the error.\n * this.messenger.call(\n * 'ErrorReportingService:captureException',\n * new Error('Something went wrong'),\n * );\n * }\n * }\n *\n * // === Initialization file ===\n *\n * import { captureException } from '@sentry/browser';\n * import { ErrorReportingService } from '@metamask/error-reporting-service';\n * import { ExampleController } from './example-controller';\n *\n * type AllActions = MessengerActions<ErrorReportingServiceMessenger>;\n *\n * type AllEvents = MessengerEvents<ErrorReportingServiceMessenger>;\n *\n * type RootMessenger = Messenger<'Root', AllActions, AllEvents>;\n *\n * // Create a global messenger.\n * const globalMessenger = new Messenger();\n *\n * // Register handler for the `ErrorReportingService:captureException`\n * // action in the global messenger.\n * const errorReportingServiceMessenger = new Messenger<\n * 'ErrorReportingService',\n * MessengerActions<ErrorReportingServiceMessenger>,\n * MessengerEvents<ErrorReportingServiceMessenger>,\n * RootMessenger\n * >({\n * namespace: 'ErrorReportingService',\n * parent: globalMessenger,\n * });\n * const errorReportingService = new ErrorReportingService({\n * messenger: errorReportingServiceMessenger,\n * captureException,\n * });\n *\n * const exampleControllerMessenger = new Messenger<\n * 'ExampleController',\n * MessengerActions<ExampleControllerMessenger>,\n * MessengerEvents<ExampleControllerMessenger>,\n * RootMessenger\n * >({\n * namespace: 'ExampleController',\n * parent: globalMessenger,\n * });\n * globalMessenger.delegate({\n * messenger: exampleControllerMessenger,\n * actions: ['ErrorReportingService:captureException'],\n * });\n * const exampleController = new ExampleController({\n * messenger: exampleControllerMessenger,\n * });\n *\n * // === Somewhere else ===\n *\n * // Now this will report an error without throwing it.\n * exampleController.doSomething();\n * ```\n */\nexport class ErrorReportingService {\n name: 'ErrorReportingService' = 'ErrorReportingService' as const;\n\n state = null;\n\n readonly #captureException: ErrorReportingServiceOptions['captureException'];\n\n readonly #messenger: ErrorReportingServiceMessenger;\n\n /**\n * Constructs a new ErrorReportingService.\n *\n * @param options - The options.\n * @param options.messenger - The messenger suited to this\n * ErrorReportingService.\n * @param options.captureException - A function that stores the given error in\n * the error reporting service.\n */\n constructor({ messenger, captureException }: ErrorReportingServiceOptions) {\n this.#messenger = messenger;\n this.#captureException = captureException;\n\n this.#messenger.registerActionHandler(\n 'ErrorReportingService:captureException',\n this.#captureException.bind(this),\n );\n }\n\n /**\n * Reports the given error to an external location.\n *\n * @param error - The error to report.\n */\n captureException(error: Error): void {\n this.#captureException(error);\n }\n}\n"]}
1
+ {"version":3,"file":"error-reporting-service.mjs","sourceRoot":"","sources":["../src/error-reporting-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAuDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,MAAM,OAAO,qBAAqB;IAShC;;;;;;;;OAQG;IACH,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAgC;QAjBzE,SAAI,GAA4B,uBAAgC,CAAC;QAEjE,UAAK,GAAG,IAAI,CAAC;QAEJ,0DAAoE;QAEpE,mDAA2C;QAYlD,uBAAA,IAAI,oCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,2CAAqB,gBAAgB,MAAA,CAAC;QAE1C,uBAAA,IAAI,wCAAW,CAAC,qBAAqB,CACnC,wCAAwC,EACxC,uBAAA,IAAI,+CAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAClC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,KAAY;QAC3B,uBAAA,IAAI,+CAAkB,MAAtB,IAAI,EAAmB,KAAK,CAAC,CAAC;IAChC,CAAC;CACF","sourcesContent":["import type { RestrictedMessenger } from '@metamask/base-controller';\n\n/**\n * The action which can be used to report an error.\n */\nexport type ErrorReportingServiceCaptureExceptionAction = {\n type: 'ErrorReportingService:captureException';\n handler: ErrorReportingService['captureException'];\n};\n\n/**\n * All actions that {@link ErrorReportingService} registers so that other\n * modules can call them.\n */\nexport type ErrorReportingServiceActions =\n ErrorReportingServiceCaptureExceptionAction;\n\n/**\n * All events that {@link ErrorReportingService} publishes so that other modules\n * can subscribe to them.\n */\nexport type ErrorReportingServiceEvents = never;\n\n/**\n * All actions registered by other modules that {@link ErrorReportingService}\n * calls.\n */\ntype AllowedActions = never;\n\n/**\n * All events published by other modules that {@link ErrorReportingService}\n * subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events that\n * {@link ErrorReportingService} needs to access.\n */\nexport type ErrorReportingServiceMessenger = RestrictedMessenger<\n 'ErrorReportingService',\n ErrorReportingServiceActions | AllowedActions,\n ErrorReportingServiceEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * The options that {@link ErrorReportingService} takes.\n */\ntype ErrorReportingServiceOptions = {\n captureException: ErrorReportingService['captureException'];\n messenger: ErrorReportingServiceMessenger;\n};\n\n/**\n * `ErrorReportingService` is designed to log an error to an error reporting app\n * such as Sentry, but in an agnostic fashion.\n *\n * @example\n *\n * In this example, we have a controller, and something bad happens, but we want\n * to report an error instead of throwing it.\n *\n * ``` ts\n * // === Controller file ===\n *\n * import type { ErrorReportingServiceCaptureExceptionAction } from '@metamask/error-reporting-service';\n *\n * // Define the messenger type for the controller.\n * type AllowedActions = ErrorReportingServiceCaptureExceptionAction;\n * type ExampleControllerMessenger = RestrictedMessenger<\n * 'ExampleController',\n * AllowedActions,\n * never,\n * AllowedActions['type'],\n * never\n * >;\n *\n * // Define the controller.\n * class ExampleController extends BaseController<\n * 'ExampleController',\n * ExampleControllerState,\n * ExampleControllerMessenger\n * > {\n * doSomething() {\n * // Imagine that we do something that produces an error and we want to\n * // report the error.\n * this.messagingSystem.call(\n * 'ErrorReportingService:captureException',\n * new Error('Something went wrong'),\n * );\n * }\n * }\n *\n * // === Initialization file ===\n *\n * import { captureException } from '@sentry/browser';\n * import { ErrorReportingService } from '@metamask/error-reporting-service';\n * import { ExampleController } from './example-controller';\n *\n * // Create a global messenger.\n * const globalMessenger = new Messenger();\n *\n * // Register handler for the `ErrorReportingService:captureException`\n * // action in the global messenger.\n * const errorReportingServiceMessenger = globalMessenger.getRestricted({\n * allowedActions: [],\n * allowedEvents: [],\n * });\n * const errorReportingService = new ErrorReportingService({\n * messenger: errorReportingServiceMessenger,\n * captureException,\n * });\n *\n * const exampleControllerMessenger = globalMessenger.getRestricted({\n * allowedActions: ['ErrorReportingService:captureException'],\n * allowedEvents: [],\n * });\n * const exampleController = new ExampleController({\n * messenger: exampleControllerMessenger,\n * });\n *\n * // === Somewhere else ===\n *\n * // Now this will report an error without throwing it.\n * exampleController.doSomething();\n * ```\n */\nexport class ErrorReportingService {\n name: 'ErrorReportingService' = 'ErrorReportingService' as const;\n\n state = null;\n\n readonly #captureException: ErrorReportingServiceOptions['captureException'];\n\n readonly #messenger: ErrorReportingServiceMessenger;\n\n /**\n * Constructs a new ErrorReportingService.\n *\n * @param options - The options.\n * @param options.messenger - The messenger suited to this\n * ErrorReportingService.\n * @param options.captureException - A function that stores the given error in\n * the error reporting service.\n */\n constructor({ messenger, captureException }: ErrorReportingServiceOptions) {\n this.#messenger = messenger;\n this.#captureException = captureException;\n\n this.#messenger.registerActionHandler(\n 'ErrorReportingService:captureException',\n this.#captureException.bind(this),\n );\n }\n\n /**\n * Reports the given error to an external location.\n *\n * @param error - The error to report.\n */\n captureException(error: Error): void {\n this.#captureException(error);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/error-reporting-service",
3
- "version": "2.2.1-preview-1f64ffa6",
3
+ "version": "2.2.1-preview-63ea58af",
4
4
  "description": "Logs errors to an error reporting service such as Sentry",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -47,8 +47,7 @@
47
47
  "since-latest-release": "../../scripts/since-latest-release.sh"
48
48
  },
49
49
  "dependencies": {
50
- "@metamask/base-controller": "^8.4.2",
51
- "@metamask/messenger": "^0.3.0"
50
+ "@metamask/base-controller": "^8.4.2"
52
51
  },
53
52
  "devDependencies": {
54
53
  "@metamask/auto-changelog": "^3.4.4",