@metamask-previews/error-reporting-service 2.1.0-preview-e5ce1e86 → 2.2.0-preview-622f3f09

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,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
+ ## [2.2.0]
11
+
12
+ ### Added
13
+
14
+ - Add `name` and `state` properties to support modular initialization ([#6781](https://github.com/MetaMask/core/pull/6781))
15
+
10
16
  ## [2.1.0]
11
17
 
12
18
  ### Changed
@@ -27,7 +33,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
27
33
 
28
34
  - Initial release ([#5882](https://github.com/MetaMask/core/pull/5882))
29
35
 
30
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/error-reporting-service@2.1.0...HEAD
36
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/error-reporting-service@2.2.0...HEAD
37
+ [2.2.0]: https://github.com/MetaMask/core/compare/@metamask/error-reporting-service@2.1.0...@metamask/error-reporting-service@2.2.0
31
38
  [2.1.0]: https://github.com/MetaMask/core/compare/@metamask/error-reporting-service@2.0.0...@metamask/error-reporting-service@2.1.0
32
39
  [2.0.0]: https://github.com/MetaMask/core/compare/@metamask/error-reporting-service@1.0.0...@metamask/error-reporting-service@2.0.0
33
40
  [1.0.0]: https://github.com/MetaMask/core/releases/tag/@metamask/error-reporting-service@1.0.0
@@ -98,6 +98,8 @@ class ErrorReportingService {
98
98
  * the error reporting service.
99
99
  */
100
100
  constructor({ messenger, captureException }) {
101
+ this.name = 'ErrorReportingService';
102
+ this.state = null;
101
103
  _ErrorReportingService_captureException.set(this, void 0);
102
104
  _ErrorReportingService_messenger.set(this, void 0);
103
105
  __classPrivateFieldSet(this, _ErrorReportingService_messenger, messenger, "f");
@@ -1 +1 @@
1
- {"version":3,"file":"error-reporting-service.cjs","sourceRoot":"","sources":["../src/error-reporting-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAuDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,MAAa,qBAAqB;IAKhC;;;;;;;;OAQG;IACH,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAgC;QAbhE,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;AAhCD,sDAgCC","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 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"]}
@@ -114,6 +114,8 @@ type ErrorReportingServiceOptions = {
114
114
  */
115
115
  export declare class ErrorReportingService {
116
116
  #private;
117
+ name: 'ErrorReportingService';
118
+ state: null;
117
119
  /**
118
120
  * Constructs a new ErrorReportingService.
119
121
  *
@@ -1 +1 @@
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;;IAKhC;;;;;;;;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"}
@@ -114,6 +114,8 @@ type ErrorReportingServiceOptions = {
114
114
  */
115
115
  export declare class ErrorReportingService {
116
116
  #private;
117
+ name: 'ErrorReportingService';
118
+ state: null;
117
119
  /**
118
120
  * Constructs a new ErrorReportingService.
119
121
  *
@@ -1 +1 @@
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;;IAKhC;;;;;;;;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"}
@@ -95,6 +95,8 @@ export class ErrorReportingService {
95
95
  * the error reporting service.
96
96
  */
97
97
  constructor({ messenger, captureException }) {
98
+ this.name = 'ErrorReportingService';
99
+ this.state = null;
98
100
  _ErrorReportingService_captureException.set(this, void 0);
99
101
  _ErrorReportingService_messenger.set(this, void 0);
100
102
  __classPrivateFieldSet(this, _ErrorReportingService_messenger, messenger, "f");
@@ -1 +1 @@
1
- {"version":3,"file":"error-reporting-service.mjs","sourceRoot":"","sources":["../src/error-reporting-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAuDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,MAAM,OAAO,qBAAqB;IAKhC;;;;;;;;OAQG;IACH,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAgC;QAbhE,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 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.1.0-preview-e5ce1e86",
3
+ "version": "2.2.0-preview-622f3f09",
4
4
  "description": "Logs errors to an error reporting service such as Sentry",
5
5
  "keywords": [
6
6
  "MetaMask",