@metamask-previews/approval-controller 9.0.2-preview-8bfa290fb → 10.0.0-preview-0a30e47

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +11 -2
  2. package/dist/{ApprovalController-method-action-types.d.mts → ApprovalController-method-action-types.d.ts} +2 -2
  3. package/dist/ApprovalController-method-action-types.d.ts.map +1 -0
  4. package/dist/{ApprovalController-method-action-types.mjs → ApprovalController-method-action-types.js} +1 -1
  5. package/dist/ApprovalController-method-action-types.js.map +1 -0
  6. package/dist/{ApprovalController.d.mts → ApprovalController.d.ts} +8 -8
  7. package/dist/ApprovalController.d.ts.map +1 -0
  8. package/dist/{ApprovalController.mjs → ApprovalController.js} +180 -141
  9. package/dist/ApprovalController.js.map +1 -0
  10. package/dist/{errors.d.cts → errors.d.ts} +1 -1
  11. package/dist/errors.d.ts.map +1 -0
  12. package/dist/{errors.mjs → errors.js} +1 -1
  13. package/dist/errors.js.map +1 -0
  14. package/dist/{index.d.cts → index.d.ts} +4 -4
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +3 -0
  17. package/dist/index.js.map +1 -0
  18. package/package.json +14 -18
  19. package/dist/ApprovalController-method-action-types.cjs +0 -7
  20. package/dist/ApprovalController-method-action-types.cjs.map +0 -1
  21. package/dist/ApprovalController-method-action-types.d.cts +0 -240
  22. package/dist/ApprovalController-method-action-types.d.cts.map +0 -1
  23. package/dist/ApprovalController-method-action-types.d.mts.map +0 -1
  24. package/dist/ApprovalController-method-action-types.mjs.map +0 -1
  25. package/dist/ApprovalController.cjs +0 -532
  26. package/dist/ApprovalController.cjs.map +0 -1
  27. package/dist/ApprovalController.d.cts +0 -416
  28. package/dist/ApprovalController.d.cts.map +0 -1
  29. package/dist/ApprovalController.d.mts.map +0 -1
  30. package/dist/ApprovalController.mjs.map +0 -1
  31. package/dist/errors.cjs +0 -34
  32. package/dist/errors.cjs.map +0 -1
  33. package/dist/errors.d.cts.map +0 -1
  34. package/dist/errors.d.mts +0 -16
  35. package/dist/errors.d.mts.map +0 -1
  36. package/dist/errors.mjs.map +0 -1
  37. package/dist/index.cjs +0 -19
  38. package/dist/index.cjs.map +0 -1
  39. package/dist/index.d.cts.map +0 -1
  40. package/dist/index.d.mts +0 -4
  41. package/dist/index.d.mts.map +0 -1
  42. package/dist/index.mjs +0 -3
  43. package/dist/index.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,10 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [10.0.0]
11
+
10
12
  ### Changed
11
13
 
14
+ - **BREAKING:** Drop CommonJS support ([#9536](https://github.com/MetaMask/core/pull/9536))
15
+ - This package is now ESM-only, but can still be used in CommonJS projects via `require(esm)` in modern Node.js versions (22+), or dynamic imports in older Node.js versions.
16
+ - **BREAKING:** Bump minimum Node.js version to 22 ([#9976](https://github.com/MetaMask/core/pull/9976))
17
+ - **BREAKING:** Bump TypeScript target to ES2022 ([#10019](https://github.com/MetaMask/core/pull/10019))
18
+ - This package now ships ES2022 code, requiring a compatible modern environment or bundler configuration to consume.
12
19
  - Bump `@metamask/utils` from `^11.9.0` to `^11.12.0` ([#9074](https://github.com/MetaMask/core/pull/9074), [#10076](https://github.com/MetaMask/core/pull/10076))
13
- - Bump `@metamask/messenger` from `^1.2.0` to `^2.0.0` ([#9392](https://github.com/MetaMask/core/pull/9392))
20
+ - Bump `@metamask/messenger` from `^1.2.0` to `^3.0.0` ([#9392](https://github.com/MetaMask/core/pull/9392), [#10160](https://github.com/MetaMask/core/pull/10160))
21
+ - Bump `@metamask/base-controller` from `^9.1.0` to `^10.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
14
22
 
15
23
  ## [9.0.2]
16
24
 
@@ -333,7 +341,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
333
341
 
334
342
  All changes listed after this point were applied to this package following the monorepo conversion.
335
343
 
336
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/approval-controller@9.0.2...HEAD
344
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/approval-controller@10.0.0...HEAD
345
+ [10.0.0]: https://github.com/MetaMask/core/compare/@metamask/approval-controller@9.0.2...@metamask/approval-controller@10.0.0
337
346
  [9.0.2]: https://github.com/MetaMask/core/compare/@metamask/approval-controller@9.0.1...@metamask/approval-controller@9.0.2
338
347
  [9.0.1]: https://github.com/MetaMask/core/compare/@metamask/approval-controller@9.0.0...@metamask/approval-controller@9.0.1
339
348
  [9.0.0]: https://github.com/MetaMask/core/compare/@metamask/approval-controller@8.0.0...@metamask/approval-controller@9.0.0
@@ -2,7 +2,7 @@
2
2
  * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
- import type { ApprovalController } from "./ApprovalController.mjs";
5
+ import type { ApprovalController } from './ApprovalController.js';
6
6
  /**
7
7
  * Adds an approval request per the given arguments, optionally showing
8
8
  * the approval request to the user.
@@ -237,4 +237,4 @@ export type ApprovalControllerShowErrorAction = {
237
237
  * Union of all ApprovalController action types.
238
238
  */
239
239
  export type ApprovalControllerMethodActions = ApprovalControllerAddRequestAction | ApprovalControllerAddAndShowApprovalRequestAction | ApprovalControllerAddAction | ApprovalControllerGetAction | ApprovalControllerGetApprovalCountAction | ApprovalControllerGetTotalApprovalCountAction | ApprovalControllerHasRequestAction | ApprovalControllerAcceptRequestAction | ApprovalControllerRejectRequestAction | ApprovalControllerClearRequestsAction | ApprovalControllerUpdateRequestStateAction | ApprovalControllerStartFlowAction | ApprovalControllerEndFlowAction | ApprovalControllerSetFlowLoadingTextAction | ApprovalControllerShowSuccessAction | ApprovalControllerShowErrorAction;
240
- //# sourceMappingURL=ApprovalController-method-action-types.d.mts.map
240
+ //# sourceMappingURL=ApprovalController-method-action-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApprovalController-method-action-types.d.ts","sourceRoot":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AC;IACrC,OAAO,EAAE,kBAAkB,CAAC,WAAW,CAAC,CAAC;CAC1C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,+BAA+B,GACvC,kCAAkC,GAClC,iDAAiD,GACjD,2BAA2B,GAC3B,2BAA2B,GAC3B,wCAAwC,GACxC,6CAA6C,GAC7C,kCAAkC,GAClC,qCAAqC,GACrC,qCAAqC,GACrC,qCAAqC,GACrC,0CAA0C,GAC1C,iCAAiC,GACjC,+BAA+B,GAC/B,0CAA0C,GAC1C,mCAAmC,GACnC,iCAAiC,CAAC"}
@@ -3,4 +3,4 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
  export {};
6
- //# sourceMappingURL=ApprovalController-method-action-types.mjs.map
6
+ //# sourceMappingURL=ApprovalController-method-action-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApprovalController-method-action-types.js","sourceRoot":"","sources":["../src/ApprovalController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ApprovalController } from './ApprovalController.js';\n\n/**\n * Adds an approval request per the given arguments, optionally showing\n * the approval request to the user.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * if any.\n * @param opts.requestState - Additional state associated with the request,\n * if any.\n * @param shouldShowRequest - Whether to show the approval request to the user.\n * @returns The approval promise.\n */\nexport type ApprovalControllerAddRequestAction = {\n type: `ApprovalController:addRequest`;\n handler: ApprovalController['addRequest'];\n};\n\n/**\n * Adds an approval request per the given arguments, calls the show approval\n * request function, and returns the associated approval promise resolving to\n * an AddResult object.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * @param opts.requestState - Additional state associated with the request,\n * if any.\n * @returns The approval promise resolving to an AddResult object.\n */\nexport type ApprovalControllerAddAndShowApprovalRequestAction = {\n type: `ApprovalController:addAndShowApprovalRequest`;\n handler: ApprovalController['addAndShowApprovalRequest'];\n};\n\n/**\n * Adds an approval request per the given arguments and returns the approval\n * promise resolving to an AddResult object.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * if any.\n * @returns The approval promise resolving to an AddResult object.\n */\nexport type ApprovalControllerAddAction = {\n type: `ApprovalController:add`;\n handler: ApprovalController['add'];\n};\n\n/**\n * Gets the info for the approval request with the given id.\n *\n * @param id - The id of the approval request.\n * @returns The approval request data associated with the id.\n */\nexport type ApprovalControllerGetAction = {\n type: `ApprovalController:get`;\n handler: ApprovalController['get'];\n};\n\n/**\n * Gets the number of pending approvals, by origin and/or type.\n *\n * If only `origin` is specified, all approvals for that origin will be\n * counted, regardless of type.\n * If only `type` is specified, all approvals for that type will be counted,\n * regardless of origin.\n * If both `origin` and `type` are specified, 0 or 1 will be returned.\n *\n * @param opts - The approval count options.\n * @param opts.origin - An approval origin.\n * @param opts.type - The type of the approval request.\n * @returns The current approval request count for the given origin and/or\n * type.\n */\nexport type ApprovalControllerGetApprovalCountAction = {\n type: `ApprovalController:getApprovalCount`;\n handler: ApprovalController['getApprovalCount'];\n};\n\n/**\n * Get the total count of all pending approval requests for all origins.\n *\n * @returns The total pending approval request count.\n */\nexport type ApprovalControllerGetTotalApprovalCountAction = {\n type: `ApprovalController:getTotalApprovalCount`;\n handler: ApprovalController['getTotalApprovalCount'];\n};\n\n/**\n * Checks if there's a pending approval request per the given parameters.\n * At least one parameter must be specified. An error will be thrown if the\n * parameters are invalid.\n *\n * If `id` is specified, all other parameters will be ignored.\n * If `id` is not specified, the method will check for requests that match\n * all of the specified parameters.\n *\n * @param opts - Options bag.\n * @param opts.id - The ID to check for.\n * @param opts.origin - The origin to check for.\n * @param opts.type - The type to check for.\n * @returns `true` if a matching approval is found, and `false` otherwise.\n */\nexport type ApprovalControllerHasRequestAction = {\n type: `ApprovalController:hasRequest`;\n handler: ApprovalController['hasRequest'];\n};\n\n/**\n * Resolves the promise of the approval with the given id, and deletes the\n * approval. Throws an error if no such approval exists.\n *\n * @param id - The id of the approval request.\n * @param value - The value to resolve the approval promise with.\n * @param options - Options bag.\n * @returns A promise that either resolves once a result is provided by\n * the creator of the approval request, or immediately if `options.waitForResult`\n * is `false` or `undefined`.\n */\nexport type ApprovalControllerAcceptRequestAction = {\n type: `ApprovalController:acceptRequest`;\n handler: ApprovalController['acceptRequest'];\n};\n\n/**\n * Rejects the promise of the approval with the given id, and deletes the\n * approval. Throws an error if no such approval exists.\n *\n * @param id - The id of the approval request.\n * @param error - The error to reject the approval promise with.\n */\nexport type ApprovalControllerRejectRequestAction = {\n type: `ApprovalController:rejectRequest`;\n handler: ApprovalController['rejectRequest'];\n};\n\n/**\n * Rejects and deletes all approval requests.\n *\n * @param rejectionError - The JsonRpcError to reject the approval\n * requests with.\n */\nexport type ApprovalControllerClearRequestsAction = {\n type: `ApprovalController:clearRequests`;\n handler: ApprovalController['clearRequests'];\n};\n\n/**\n * Updates the request state of the approval with the given id.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request.\n * @param opts.requestState - Additional data associated with the request\n */\nexport type ApprovalControllerUpdateRequestStateAction = {\n type: `ApprovalController:updateRequestState`;\n handler: ApprovalController['updateRequestState'];\n};\n\n/**\n * Starts a new approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval flow.\n * @param opts.loadingText - The loading text that will be associated to the approval flow.\n * @param opts.show - A flag to determine whether the approval should show to the user.\n * @returns The object containing the approval flow id.\n */\nexport type ApprovalControllerStartFlowAction = {\n type: `ApprovalController:startFlow`;\n handler: ApprovalController['startFlow'];\n};\n\n/**\n * Ends the current approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval flow that will be finished.\n */\nexport type ApprovalControllerEndFlowAction = {\n type: `ApprovalController:endFlow`;\n handler: ApprovalController['endFlow'];\n};\n\n/**\n * Sets the loading text for the approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The approval flow loading text that will be displayed.\n * @param opts.loadingText - The loading text that will be associated to the approval flow.\n */\nexport type ApprovalControllerSetFlowLoadingTextAction = {\n type: `ApprovalController:setFlowLoadingText`;\n handler: ApprovalController['setFlowLoadingText'];\n};\n\n/**\n * Show a success page.\n *\n * @param opts - Options bag.\n * @param opts.message - The message text or components to display in the page.\n * @param opts.header - The text or components to display in the header of the page.\n * @param opts.flowToEnd - The ID of the approval flow to end once the success page is approved.\n * @param opts.title - The title to display above the message. Shown by default but can be hidden with `null`.\n * @param opts.icon - The icon to display in the page. Shown by default but can be hidden with `null`.\n * @returns Empty object to support future additions.\n */\nexport type ApprovalControllerShowSuccessAction = {\n type: `ApprovalController:showSuccess`;\n handler: ApprovalController['showSuccess'];\n};\n\n/**\n * Show an error page.\n *\n * @param opts - Options bag.\n * @param opts.message - The message text or components to display in the page.\n * @param opts.header - The text or components to display in the header of the page.\n * @param opts.flowToEnd - The ID of the approval flow to end once the error page is approved.\n * @param opts.title - The title to display above the message. Shown by default but can be hidden with `null`.\n * @param opts.icon - The icon to display in the page. Shown by default but can be hidden with `null`.\n * @returns Empty object to support future additions.\n */\nexport type ApprovalControllerShowErrorAction = {\n type: `ApprovalController:showError`;\n handler: ApprovalController['showError'];\n};\n\n/**\n * Union of all ApprovalController action types.\n */\nexport type ApprovalControllerMethodActions =\n | ApprovalControllerAddRequestAction\n | ApprovalControllerAddAndShowApprovalRequestAction\n | ApprovalControllerAddAction\n | ApprovalControllerGetAction\n | ApprovalControllerGetApprovalCountAction\n | ApprovalControllerGetTotalApprovalCountAction\n | ApprovalControllerHasRequestAction\n | ApprovalControllerAcceptRequestAction\n | ApprovalControllerRejectRequestAction\n | ApprovalControllerClearRequestsAction\n | ApprovalControllerUpdateRequestStateAction\n | ApprovalControllerStartFlowAction\n | ApprovalControllerEndFlowAction\n | ApprovalControllerSetFlowLoadingTextAction\n | ApprovalControllerShowSuccessAction\n | ApprovalControllerShowErrorAction;\n"]}
@@ -1,10 +1,10 @@
1
- import { BaseController } from "@metamask/base-controller";
2
- import type { ControllerGetStateAction } from "@metamask/base-controller";
3
- import type { ControllerStateChangeEvent } from "@metamask/base-controller";
4
- import type { Messenger } from "@metamask/messenger";
5
- import type { JsonRpcError, DataWithOptionalCause } from "@metamask/rpc-errors";
6
- import type { Json, OptionalField } from "@metamask/utils";
7
- import type { ApprovalControllerMethodActions } from "./ApprovalController-method-action-types.mjs";
1
+ import { BaseController } from '@metamask/base-controller';
2
+ import type { ControllerGetStateAction } from '@metamask/base-controller';
3
+ import type { ControllerStateChangeEvent } from '@metamask/base-controller';
4
+ import type { Messenger } from '@metamask/messenger';
5
+ import type { JsonRpcError, DataWithOptionalCause } from '@metamask/rpc-errors';
6
+ import type { Json, OptionalField } from '@metamask/utils';
7
+ import type { ApprovalControllerMethodActions } from './ApprovalController-method-action-types.js';
8
8
  export declare const ORIGIN_METAMASK = "metamask";
9
9
  export declare const APPROVAL_TYPE_RESULT_ERROR = "result_error";
10
10
  export declare const APPROVAL_TYPE_RESULT_SUCCESS = "result_success";
@@ -413,4 +413,4 @@ export declare class ApprovalController extends BaseController<typeof controller
413
413
  showError(opts?: ErrorOptions): Promise<ErrorResult>;
414
414
  }
415
415
  export default ApprovalController;
416
- //# sourceMappingURL=ApprovalController.d.mts.map
416
+ //# sourceMappingURL=ApprovalController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApprovalController.d.ts","sourceRoot":"","sources":["../src/ApprovalController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,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;;;OAMG;IACH,kBAAkB,CAAC,IAAI,EAAE,yBAAyB,GAAG,IAAI,CASxD;IAED;;;;;;;;OAQG;IACH,SAAS,CAAC,IAAI,GAAE,gBAAqB,GAAG,uBAAuB,CAc9D;IAED;;;;;OAKG;IACH,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,cAAc,QAiB7B;IAED;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,yBAAyB,QAYhE;IAED;;;;;;;;;;OAUG;IACG,WAAW,CAAC,IAAI,GAAE,cAAmB,GAAG,OAAO,CAAC,aAAa,CAAC,CASnE;IAED;;;;;;;;;;OAUG;IACG,SAAS,CAAC,IAAI,GAAE,YAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAS7D;CAuNF;eAEc,kBAAkB"}
@@ -1,19 +1,7 @@
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
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _ApprovalController_instances, _ApprovalController_approvals, _ApprovalController_origins, _ApprovalController_showApprovalRequest, _ApprovalController_typesExcludedFromRateLimiting, _ApprovalController_add, _ApprovalController_validateAddParams, _ApprovalController_addPendingApprovalOrigin, _ApprovalController_addToStore, _ApprovalController_delete, _ApprovalController_getCallbacks, _ApprovalController_result;
13
- import { BaseController } from "@metamask/base-controller";
14
- import { rpcErrors } from "@metamask/rpc-errors";
15
- import { nanoid } from "nanoid";
16
- import { ApprovalRequestNotFoundError, ApprovalRequestNoResultSupportError, EndInvalidFlowError, NoApprovalFlowsError, MissingApprovalFlowError } from "./errors.mjs";
1
+ import { BaseController } from '@metamask/base-controller';
2
+ import { rpcErrors } from '@metamask/rpc-errors';
3
+ import { nanoid } from 'nanoid';
4
+ import { ApprovalRequestNotFoundError, ApprovalRequestNoResultSupportError, EndInvalidFlowError, NoApprovalFlowsError, MissingApprovalFlowError, } from './errors.js';
17
5
  // Constants
18
6
  // Avoiding dependency on controller-utils
19
7
  export const ORIGIN_METAMASK = 'metamask';
@@ -77,6 +65,10 @@ const MESSENGER_EXPOSED_METHODS = [
77
65
  * is approved or denied, respectively.
78
66
  */
79
67
  export class ApprovalController extends BaseController {
68
+ #approvals;
69
+ #origins;
70
+ #showApprovalRequest;
71
+ #typesExcludedFromRateLimiting;
80
72
  /**
81
73
  * Construct an Approval controller.
82
74
  *
@@ -94,17 +86,12 @@ export class ApprovalController extends BaseController {
94
86
  messenger,
95
87
  state: { ...getDefaultState(), ...state },
96
88
  });
97
- _ApprovalController_instances.add(this);
98
- _ApprovalController_approvals.set(this, void 0);
99
- _ApprovalController_origins.set(this, void 0);
100
- _ApprovalController_showApprovalRequest.set(this, void 0);
101
- _ApprovalController_typesExcludedFromRateLimiting.set(this, void 0);
102
- __classPrivateFieldSet(this, _ApprovalController_approvals, new Map(), "f");
103
- __classPrivateFieldSet(this, _ApprovalController_origins, new Map(), "f");
89
+ this.#approvals = new Map();
90
+ this.#origins = new Map();
104
91
  // TODO: Either fix this lint violation or explain why it's necessary to ignore.
105
92
  // eslint-disable-next-line @typescript-eslint/no-misused-promises
106
- __classPrivateFieldSet(this, _ApprovalController_showApprovalRequest, showApprovalRequest, "f");
107
- __classPrivateFieldSet(this, _ApprovalController_typesExcludedFromRateLimiting, typesExcludedFromRateLimiting, "f");
93
+ this.#showApprovalRequest = showApprovalRequest;
94
+ this.#typesExcludedFromRateLimiting = typesExcludedFromRateLimiting;
108
95
  this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
109
96
  }
110
97
  /**
@@ -130,12 +117,12 @@ export class ApprovalController extends BaseController {
130
117
  return this.add(opts);
131
118
  }
132
119
  addAndShowApprovalRequest(opts) {
133
- const promise = __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_add).call(this, opts.origin, opts.type, opts.id, opts.requestData, opts.requestState, opts.expectsResult);
134
- __classPrivateFieldGet(this, _ApprovalController_showApprovalRequest, "f").call(this);
120
+ const promise = this.#add(opts.origin, opts.type, opts.id, opts.requestData, opts.requestState, opts.expectsResult);
121
+ this.#showApprovalRequest();
135
122
  return promise;
136
123
  }
137
124
  add(opts) {
138
- return __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_add).call(this, opts.origin, opts.type, opts.id, opts.requestData, opts.requestState, opts.expectsResult);
125
+ return this.#add(opts.origin, opts.type, opts.id, opts.requestData, opts.requestState, opts.expectsResult);
139
126
  }
140
127
  /**
141
128
  * Gets the info for the approval request with the given id.
@@ -167,10 +154,10 @@ export class ApprovalController extends BaseController {
167
154
  }
168
155
  const { origin, type: _type } = opts;
169
156
  if (origin && _type) {
170
- return __classPrivateFieldGet(this, _ApprovalController_origins, "f").get(origin)?.get(_type) || 0;
157
+ return this.#origins.get(origin)?.get(_type) || 0;
171
158
  }
172
159
  if (origin) {
173
- return Array.from((__classPrivateFieldGet(this, _ApprovalController_origins, "f").get(origin) || new Map()).values()).reduce((total, value) => total + value, 0);
160
+ return Array.from((this.#origins.get(origin) || new Map()).values()).reduce((total, value) => total + value, 0);
174
161
  }
175
162
  // Only "type" was specified
176
163
  let count = 0;
@@ -210,7 +197,7 @@ export class ApprovalController extends BaseController {
210
197
  if (typeof id !== 'string') {
211
198
  throw new Error('May not specify non-string id.');
212
199
  }
213
- return __classPrivateFieldGet(this, _ApprovalController_approvals, "f").has(id);
200
+ return this.#approvals.has(id);
214
201
  }
215
202
  if (_type && typeof _type !== 'string') {
216
203
  throw new Error('May not specify non-string type.');
@@ -221,9 +208,9 @@ export class ApprovalController extends BaseController {
221
208
  }
222
209
  // Check origin and type pair if type also specified
223
210
  if (_type) {
224
- return Boolean(__classPrivateFieldGet(this, _ApprovalController_origins, "f").get(origin)?.get(_type));
211
+ return Boolean(this.#origins.get(origin)?.get(_type));
225
212
  }
226
- return __classPrivateFieldGet(this, _ApprovalController_origins, "f").has(origin);
213
+ return this.#origins.has(origin);
227
214
  }
228
215
  if (_type) {
229
216
  for (const approval of Object.values(this.state.pendingApprovals)) {
@@ -249,10 +236,10 @@ export class ApprovalController extends BaseController {
249
236
  acceptRequest(id, value, options) {
250
237
  // Safe to cast as the delete method below will throw if the ID is not found
251
238
  const approval = this.get(id);
252
- const requestPromise = __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_getCallbacks).call(this, id);
239
+ const requestPromise = this.#getCallbacks(id);
253
240
  let requestDeleted = false;
254
241
  if (!options?.deleteAfterResult || !options.waitForResult) {
255
- __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_delete).call(this, id);
242
+ this.#delete(id);
256
243
  requestDeleted = true;
257
244
  }
258
245
  return new Promise((resolve, reject) => {
@@ -274,7 +261,7 @@ export class ApprovalController extends BaseController {
274
261
  }
275
262
  }).finally(() => {
276
263
  if (!requestDeleted) {
277
- __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_delete).call(this, id);
264
+ this.#delete(id);
278
265
  }
279
266
  });
280
267
  }
@@ -286,8 +273,8 @@ export class ApprovalController extends BaseController {
286
273
  * @param error - The error to reject the approval promise with.
287
274
  */
288
275
  rejectRequest(id, error) {
289
- const callbacks = __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_getCallbacks).call(this, id);
290
- __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_delete).call(this, id);
276
+ const callbacks = this.#getCallbacks(id);
277
+ this.#delete(id);
291
278
  callbacks.reject(error);
292
279
  }
293
280
  /**
@@ -297,10 +284,10 @@ export class ApprovalController extends BaseController {
297
284
  * requests with.
298
285
  */
299
286
  clearRequests(rejectionError) {
300
- for (const id of __classPrivateFieldGet(this, _ApprovalController_approvals, "f").keys()) {
287
+ for (const id of this.#approvals.keys()) {
301
288
  this.rejectRequest(id, rejectionError);
302
289
  }
303
- __classPrivateFieldGet(this, _ApprovalController_origins, "f").clear();
290
+ this.#origins.clear();
304
291
  this.update((draftState) => {
305
292
  draftState.pendingApprovals = {};
306
293
  draftState.pendingApprovalCount = 0;
@@ -339,7 +326,7 @@ export class ApprovalController extends BaseController {
339
326
  });
340
327
  // By default, if nothing else is specified, we always show the approval.
341
328
  if (opts.show !== false) {
342
- __classPrivateFieldGet(this, _ApprovalController_showApprovalRequest, "f").call(this);
329
+ this.#showApprovalRequest();
343
330
  }
344
331
  return { id, loadingText };
345
332
  }
@@ -389,7 +376,7 @@ export class ApprovalController extends BaseController {
389
376
  * @returns Empty object to support future additions.
390
377
  */
391
378
  async showSuccess(opts = {}) {
392
- await __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_result).call(this, APPROVAL_TYPE_RESULT_SUCCESS, opts, {
379
+ await this.#result(APPROVAL_TYPE_RESULT_SUCCESS, opts, {
393
380
  message: opts.message,
394
381
  header: opts.header,
395
382
  title: opts.title,
@@ -409,7 +396,7 @@ export class ApprovalController extends BaseController {
409
396
  * @returns Empty object to support future additions.
410
397
  */
411
398
  async showError(opts = {}) {
412
- await __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_result).call(this, APPROVAL_TYPE_RESULT_ERROR, opts, {
399
+ await this.#result(APPROVAL_TYPE_RESULT_ERROR, opts, {
413
400
  error: opts.error,
414
401
  header: opts.header,
415
402
  title: opts.title,
@@ -417,112 +404,164 @@ export class ApprovalController extends BaseController {
417
404
  });
418
405
  return {};
419
406
  }
420
- }
421
- _ApprovalController_approvals = new WeakMap(), _ApprovalController_origins = new WeakMap(), _ApprovalController_showApprovalRequest = new WeakMap(), _ApprovalController_typesExcludedFromRateLimiting = new WeakMap(), _ApprovalController_instances = new WeakSet(), _ApprovalController_add = function _ApprovalController_add(origin, type, id = nanoid(), requestData, requestState, expectsResult) {
422
- __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_validateAddParams).call(this, id, origin, type, requestData, requestState);
423
- if (!__classPrivateFieldGet(this, _ApprovalController_typesExcludedFromRateLimiting, "f").includes(type) &&
424
- this.hasRequest({ origin, type })) {
425
- throw rpcErrors.resourceUnavailable(getAlreadyPendingMessage(origin, type));
426
- }
427
- // add pending approval
428
- return new Promise((resolve, reject) => {
429
- __classPrivateFieldGet(this, _ApprovalController_approvals, "f").set(id, { resolve, reject });
430
- __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_addPendingApprovalOrigin).call(this, origin, type);
431
- __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_addToStore).call(this, id, origin, type, requestData, requestState, expectsResult);
432
- });
433
- }, _ApprovalController_validateAddParams = function _ApprovalController_validateAddParams(id, origin, type, requestData, requestState) {
434
- let errorMessage = null;
435
- if (!id || typeof id !== 'string') {
436
- errorMessage = 'Must specify non-empty string id.';
437
- }
438
- else if (__classPrivateFieldGet(this, _ApprovalController_approvals, "f").has(id)) {
439
- errorMessage = `Approval request with id '${id}' already exists.`;
440
- }
441
- else if (!origin || typeof origin !== 'string') {
442
- errorMessage = 'Must specify non-empty string origin.';
443
- }
444
- else if (!type || typeof type !== 'string') {
445
- errorMessage = 'Must specify non-empty string type.';
446
- }
447
- else if (requestData &&
448
- (typeof requestData !== 'object' || Array.isArray(requestData))) {
449
- errorMessage = 'Request data must be a plain object if specified.';
450
- }
451
- else if (requestState &&
452
- (typeof requestState !== 'object' || Array.isArray(requestState))) {
453
- errorMessage = 'Request state must be a plain object if specified.';
454
- }
455
- if (errorMessage) {
456
- throw rpcErrors.internal(errorMessage);
457
- }
458
- }, _ApprovalController_addPendingApprovalOrigin = function _ApprovalController_addPendingApprovalOrigin(origin, type) {
459
- let originMap = __classPrivateFieldGet(this, _ApprovalController_origins, "f").get(origin);
460
- if (!originMap) {
461
- originMap = new Map();
462
- __classPrivateFieldGet(this, _ApprovalController_origins, "f").set(origin, originMap);
463
- }
464
- const currentValue = originMap.get(type) || 0;
465
- originMap.set(type, currentValue + 1);
466
- }, _ApprovalController_addToStore = function _ApprovalController_addToStore(id, origin, type, requestData, requestState, expectsResult) {
467
- const approval = {
468
- id,
469
- origin,
470
- type,
471
- time: Date.now(),
472
- requestData: requestData || null,
473
- requestState: requestState || null,
474
- expectsResult: expectsResult || false,
475
- };
476
- this.update((draftState) => {
477
- draftState.pendingApprovals[id] = approval;
478
- draftState.pendingApprovalCount = Object.keys(draftState.pendingApprovals).length;
479
- });
480
- }, _ApprovalController_delete = function _ApprovalController_delete(id) {
481
- if (!__classPrivateFieldGet(this, _ApprovalController_approvals, "f").has(id)) {
482
- throw new ApprovalRequestNotFoundError(id);
483
- }
484
- __classPrivateFieldGet(this, _ApprovalController_approvals, "f").delete(id);
485
- const { origin, type } = this.state.pendingApprovals[id];
486
- const originMap = __classPrivateFieldGet(this, _ApprovalController_origins, "f").get(origin);
487
- const originTotalCount = this.getApprovalCount({ origin });
488
- const originTypeCount = originMap.get(type);
489
- if (originTotalCount === 1) {
490
- __classPrivateFieldGet(this, _ApprovalController_origins, "f").delete(origin);
407
+ /**
408
+ * Implementation of add operation.
409
+ *
410
+ * @param origin - The origin of the approval request.
411
+ * @param type - The type associated with the approval request.
412
+ * @param id - The id of the approval request.
413
+ * @param requestData - The request data associated with the approval request.
414
+ * @param requestState - The request state associated with the approval request.
415
+ * @param expectsResult - Whether the approval request expects a result object to be returned.
416
+ * @returns The approval promise.
417
+ */
418
+ #add(origin, type, id = nanoid(), requestData, requestState, expectsResult) {
419
+ this.#validateAddParams(id, origin, type, requestData, requestState);
420
+ if (!this.#typesExcludedFromRateLimiting.includes(type) &&
421
+ this.hasRequest({ origin, type })) {
422
+ throw rpcErrors.resourceUnavailable(getAlreadyPendingMessage(origin, type));
423
+ }
424
+ // add pending approval
425
+ return new Promise((resolve, reject) => {
426
+ this.#approvals.set(id, { resolve, reject });
427
+ this.#addPendingApprovalOrigin(origin, type);
428
+ this.#addToStore(id, origin, type, requestData, requestState, expectsResult);
429
+ });
491
430
  }
492
- else {
493
- originMap.set(type, originTypeCount - 1);
431
+ /**
432
+ * Validates parameters to the add method.
433
+ *
434
+ * @param id - The id of the approval request.
435
+ * @param origin - The origin of the approval request.
436
+ * @param type - The type associated with the approval request.
437
+ * @param requestData - The request data associated with the approval request.
438
+ * @param requestState - The request state associated with the approval request.
439
+ */
440
+ #validateAddParams(id, origin, type, requestData, requestState) {
441
+ let errorMessage = null;
442
+ if (!id || typeof id !== 'string') {
443
+ errorMessage = 'Must specify non-empty string id.';
444
+ }
445
+ else if (this.#approvals.has(id)) {
446
+ errorMessage = `Approval request with id '${id}' already exists.`;
447
+ }
448
+ else if (!origin || typeof origin !== 'string') {
449
+ errorMessage = 'Must specify non-empty string origin.';
450
+ }
451
+ else if (!type || typeof type !== 'string') {
452
+ errorMessage = 'Must specify non-empty string type.';
453
+ }
454
+ else if (requestData &&
455
+ (typeof requestData !== 'object' || Array.isArray(requestData))) {
456
+ errorMessage = 'Request data must be a plain object if specified.';
457
+ }
458
+ else if (requestState &&
459
+ (typeof requestState !== 'object' || Array.isArray(requestState))) {
460
+ errorMessage = 'Request state must be a plain object if specified.';
461
+ }
462
+ if (errorMessage) {
463
+ throw rpcErrors.internal(errorMessage);
464
+ }
494
465
  }
495
- this.update((draftState) => {
496
- delete draftState.pendingApprovals[id];
497
- draftState.pendingApprovalCount = Object.keys(draftState.pendingApprovals).length;
498
- });
499
- }, _ApprovalController_getCallbacks = function _ApprovalController_getCallbacks(id) {
500
- const callbacks = __classPrivateFieldGet(this, _ApprovalController_approvals, "f").get(id);
501
- if (!callbacks) {
502
- throw new ApprovalRequestNotFoundError(id);
466
+ /**
467
+ * Adds an entry to _origins.
468
+ * Performs no validation.
469
+ *
470
+ * @param origin - The origin of the approval request.
471
+ * @param type - The type associated with the approval request.
472
+ */
473
+ #addPendingApprovalOrigin(origin, type) {
474
+ let originMap = this.#origins.get(origin);
475
+ if (!originMap) {
476
+ originMap = new Map();
477
+ this.#origins.set(origin, originMap);
478
+ }
479
+ const currentValue = originMap.get(type) || 0;
480
+ originMap.set(type, currentValue + 1);
503
481
  }
504
- return callbacks;
505
- }, _ApprovalController_result = async function _ApprovalController_result(type, opts, requestData) {
506
- try {
507
- await this.addAndShowApprovalRequest({
508
- origin: ORIGIN_METAMASK,
482
+ /**
483
+ * Adds an entry to the store.
484
+ * Performs no validation.
485
+ *
486
+ * @param id - The id of the approval request.
487
+ * @param origin - The origin of the approval request.
488
+ * @param type - The type associated with the approval request.
489
+ * @param requestData - The request data associated with the approval request.
490
+ * @param requestState - The request state associated with the approval request.
491
+ * @param expectsResult - Whether the request expects a result object to be returned.
492
+ */
493
+ #addToStore(id, origin, type, requestData, requestState, expectsResult) {
494
+ const approval = {
495
+ id,
496
+ origin,
509
497
  type,
510
- requestData,
498
+ time: Date.now(),
499
+ requestData: requestData || null,
500
+ requestState: requestState || null,
501
+ expectsResult: expectsResult || false,
502
+ };
503
+ this.update((draftState) => {
504
+ draftState.pendingApprovals[id] = approval;
505
+ draftState.pendingApprovalCount = Object.keys(draftState.pendingApprovals).length;
511
506
  });
512
507
  }
513
- catch (error) {
514
- console.info('Failed to display result page', error);
508
+ /**
509
+ * Deletes the approval with the given id.
510
+ *
511
+ * Deletion is an internal operation because approval state is solely
512
+ * managed by this controller.
513
+ *
514
+ * @param id - The id of the approval request to be deleted.
515
+ */
516
+ #delete(id) {
517
+ if (!this.#approvals.has(id)) {
518
+ throw new ApprovalRequestNotFoundError(id);
519
+ }
520
+ this.#approvals.delete(id);
521
+ const { origin, type } = this.state.pendingApprovals[id];
522
+ const originMap = this.#origins.get(origin);
523
+ const originTotalCount = this.getApprovalCount({ origin });
524
+ const originTypeCount = originMap.get(type);
525
+ if (originTotalCount === 1) {
526
+ this.#origins.delete(origin);
527
+ }
528
+ else {
529
+ originMap.set(type, originTypeCount - 1);
530
+ }
531
+ this.update((draftState) => {
532
+ delete draftState.pendingApprovals[id];
533
+ draftState.pendingApprovalCount = Object.keys(draftState.pendingApprovals).length;
534
+ });
515
535
  }
516
- finally {
517
- if (opts.flowToEnd) {
518
- try {
519
- this.endFlow({ id: opts.flowToEnd });
520
- }
521
- catch (error) {
522
- console.info('Failed to end flow', { id: opts.flowToEnd, error });
536
+ #getCallbacks(id) {
537
+ const callbacks = this.#approvals.get(id);
538
+ if (!callbacks) {
539
+ throw new ApprovalRequestNotFoundError(id);
540
+ }
541
+ return callbacks;
542
+ }
543
+ async #result(type, opts, requestData) {
544
+ try {
545
+ await this.addAndShowApprovalRequest({
546
+ origin: ORIGIN_METAMASK,
547
+ type,
548
+ requestData,
549
+ });
550
+ }
551
+ catch (error) {
552
+ console.info('Failed to display result page', error);
553
+ }
554
+ finally {
555
+ if (opts.flowToEnd) {
556
+ try {
557
+ this.endFlow({ id: opts.flowToEnd });
558
+ }
559
+ catch (error) {
560
+ console.info('Failed to end flow', { id: opts.flowToEnd, error });
561
+ }
523
562
  }
524
563
  }
525
564
  }
526
- };
565
+ }
527
566
  export default ApprovalController;
528
- //# sourceMappingURL=ApprovalController.mjs.map
567
+ //# sourceMappingURL=ApprovalController.js.map