You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@metamask/approval-controller

Package Overview
Dependencies
Maintainers
4
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metamask/approval-controller - npm Package Compare versions

Comparing version
8.0.0
to
9.0.0
+7
dist/ApprovalController-method-action-types.cjs
"use strict";
/**
* This file is auto generated by `scripts/generate-method-action-types.ts`.
* Do not edit manually.
*/
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ApprovalController-method-action-types.cjs.map
{"version":3,"file":"ApprovalController-method-action-types.cjs","sourceRoot":"","sources":["../src/ApprovalController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { ApprovalController } from './ApprovalController';\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"]}
/**
* This file is auto generated by `scripts/generate-method-action-types.ts`.
* Do not edit manually.
*/
import type { ApprovalController } from "./ApprovalController.cjs";
/**
* Adds an approval request per the given arguments, optionally showing
* the approval request to the user.
*
* @param opts - Options bag.
* @param opts.id - The id of the approval request. A random id will be
* generated if none is provided.
* @param opts.origin - The origin of the approval request.
* @param opts.type - The type associated with the approval request.
* @param opts.requestData - Additional data associated with the request,
* if any.
* @param opts.requestState - Additional state associated with the request,
* if any.
* @param shouldShowRequest - Whether to show the approval request to the user.
* @returns The approval promise.
*/
export type ApprovalControllerAddRequestAction = {
type: `ApprovalController:addRequest`;
handler: ApprovalController['addRequest'];
};
/**
* Adds an approval request per the given arguments, calls the show approval
* request function, and returns the associated approval promise resolving to
* an AddResult object.
*
* There can only be one approval per origin and type. An error is thrown if
* attempting to add an invalid or duplicate request.
*
* @param opts - Options bag.
* @param opts.id - The id of the approval request. A random id will be
* generated if none is provided.
* @param opts.origin - The origin of the approval request.
* @param opts.type - The type associated with the approval request.
* @param opts.requestData - Additional data associated with the request,
* @param opts.requestState - Additional state associated with the request,
* if any.
* @returns The approval promise resolving to an AddResult object.
*/
export type ApprovalControllerAddAndShowApprovalRequestAction = {
type: `ApprovalController:addAndShowApprovalRequest`;
handler: ApprovalController['addAndShowApprovalRequest'];
};
/**
* Adds an approval request per the given arguments and returns the approval
* promise resolving to an AddResult object.
*
* There can only be one approval per origin and type. An error is thrown if
* attempting to add an invalid or duplicate request.
*
* @param opts - Options bag.
* @param opts.id - The id of the approval request. A random id will be
* generated if none is provided.
* @param opts.origin - The origin of the approval request.
* @param opts.type - The type associated with the approval request.
* @param opts.requestData - Additional data associated with the request,
* if any.
* @returns The approval promise resolving to an AddResult object.
*/
export type ApprovalControllerAddAction = {
type: `ApprovalController:add`;
handler: ApprovalController['add'];
};
/**
* Gets the info for the approval request with the given id.
*
* @param id - The id of the approval request.
* @returns The approval request data associated with the id.
*/
export type ApprovalControllerGetAction = {
type: `ApprovalController:get`;
handler: ApprovalController['get'];
};
/**
* Gets the number of pending approvals, by origin and/or type.
*
* If only `origin` is specified, all approvals for that origin will be
* counted, regardless of type.
* If only `type` is specified, all approvals for that type will be counted,
* regardless of origin.
* If both `origin` and `type` are specified, 0 or 1 will be returned.
*
* @param opts - The approval count options.
* @param opts.origin - An approval origin.
* @param opts.type - The type of the approval request.
* @returns The current approval request count for the given origin and/or
* type.
*/
export type ApprovalControllerGetApprovalCountAction = {
type: `ApprovalController:getApprovalCount`;
handler: ApprovalController['getApprovalCount'];
};
/**
* Get the total count of all pending approval requests for all origins.
*
* @returns The total pending approval request count.
*/
export type ApprovalControllerGetTotalApprovalCountAction = {
type: `ApprovalController:getTotalApprovalCount`;
handler: ApprovalController['getTotalApprovalCount'];
};
/**
* Checks if there's a pending approval request per the given parameters.
* At least one parameter must be specified. An error will be thrown if the
* parameters are invalid.
*
* If `id` is specified, all other parameters will be ignored.
* If `id` is not specified, the method will check for requests that match
* all of the specified parameters.
*
* @param opts - Options bag.
* @param opts.id - The ID to check for.
* @param opts.origin - The origin to check for.
* @param opts.type - The type to check for.
* @returns `true` if a matching approval is found, and `false` otherwise.
*/
export type ApprovalControllerHasRequestAction = {
type: `ApprovalController:hasRequest`;
handler: ApprovalController['hasRequest'];
};
/**
* Resolves the promise of the approval with the given id, and deletes the
* approval. Throws an error if no such approval exists.
*
* @param id - The id of the approval request.
* @param value - The value to resolve the approval promise with.
* @param options - Options bag.
* @returns A promise that either resolves once a result is provided by
* the creator of the approval request, or immediately if `options.waitForResult`
* is `false` or `undefined`.
*/
export type ApprovalControllerAcceptRequestAction = {
type: `ApprovalController:acceptRequest`;
handler: ApprovalController['acceptRequest'];
};
/**
* Rejects the promise of the approval with the given id, and deletes the
* approval. Throws an error if no such approval exists.
*
* @param id - The id of the approval request.
* @param error - The error to reject the approval promise with.
*/
export type ApprovalControllerRejectRequestAction = {
type: `ApprovalController:rejectRequest`;
handler: ApprovalController['rejectRequest'];
};
/**
* Rejects and deletes all approval requests.
*
* @param rejectionError - The JsonRpcError to reject the approval
* requests with.
*/
export type ApprovalControllerClearRequestsAction = {
type: `ApprovalController:clearRequests`;
handler: ApprovalController['clearRequests'];
};
/**
* Updates the request state of the approval with the given id.
*
* @param opts - Options bag.
* @param opts.id - The id of the approval request.
* @param opts.requestState - Additional data associated with the request
*/
export type ApprovalControllerUpdateRequestStateAction = {
type: `ApprovalController:updateRequestState`;
handler: ApprovalController['updateRequestState'];
};
/**
* Starts a new approval flow.
*
* @param opts - Options bag.
* @param opts.id - The id of the approval flow.
* @param opts.loadingText - The loading text that will be associated to the approval flow.
* @param opts.show - A flag to determine whether the approval should show to the user.
* @returns The object containing the approval flow id.
*/
export type ApprovalControllerStartFlowAction = {
type: `ApprovalController:startFlow`;
handler: ApprovalController['startFlow'];
};
/**
* Ends the current approval flow.
*
* @param opts - Options bag.
* @param opts.id - The id of the approval flow that will be finished.
*/
export type ApprovalControllerEndFlowAction = {
type: `ApprovalController:endFlow`;
handler: ApprovalController['endFlow'];
};
/**
* Sets the loading text for the approval flow.
*
* @param opts - Options bag.
* @param opts.id - The approval flow loading text that will be displayed.
* @param opts.loadingText - The loading text that will be associated to the approval flow.
*/
export type ApprovalControllerSetFlowLoadingTextAction = {
type: `ApprovalController:setFlowLoadingText`;
handler: ApprovalController['setFlowLoadingText'];
};
/**
* Show a success page.
*
* @param opts - Options bag.
* @param opts.message - The message text or components to display in the page.
* @param opts.header - The text or components to display in the header of the page.
* @param opts.flowToEnd - The ID of the approval flow to end once the success page is approved.
* @param opts.title - The title to display above the message. Shown by default but can be hidden with `null`.
* @param opts.icon - The icon to display in the page. Shown by default but can be hidden with `null`.
* @returns Empty object to support future additions.
*/
export type ApprovalControllerShowSuccessAction = {
type: `ApprovalController:showSuccess`;
handler: ApprovalController['showSuccess'];
};
/**
* Show an error page.
*
* @param opts - Options bag.
* @param opts.message - The message text or components to display in the page.
* @param opts.header - The text or components to display in the header of the page.
* @param opts.flowToEnd - The ID of the approval flow to end once the error page is approved.
* @param opts.title - The title to display above the message. Shown by default but can be hidden with `null`.
* @param opts.icon - The icon to display in the page. Shown by default but can be hidden with `null`.
* @returns Empty object to support future additions.
*/
export type ApprovalControllerShowErrorAction = {
type: `ApprovalController:showError`;
handler: ApprovalController['showError'];
};
/**
* Union of all ApprovalController action types.
*/
export type ApprovalControllerMethodActions = ApprovalControllerAddRequestAction | ApprovalControllerAddAndShowApprovalRequestAction | ApprovalControllerAddAction | ApprovalControllerGetAction | ApprovalControllerGetApprovalCountAction | ApprovalControllerGetTotalApprovalCountAction | ApprovalControllerHasRequestAction | ApprovalControllerAcceptRequestAction | ApprovalControllerRejectRequestAction | ApprovalControllerClearRequestsAction | ApprovalControllerUpdateRequestStateAction | ApprovalControllerStartFlowAction | ApprovalControllerEndFlowAction | ApprovalControllerSetFlowLoadingTextAction | ApprovalControllerShowSuccessAction | ApprovalControllerShowErrorAction;
//# sourceMappingURL=ApprovalController-method-action-types.d.cts.map
{"version":3,"file":"ApprovalController-method-action-types.d.cts","sourceRoot":"","sources":["../src/ApprovalController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,iCAA6B;AAE/D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,kBAAkB,CAAC,YAAY,CAAC,CAAC;CAC3C,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,iDAAiD,GAAG;IAC9D,IAAI,EAAE,8CAA8C,CAAC;IACrD,OAAO,EAAE,kBAAkB,CAAC,2BAA2B,CAAC,CAAC;CAC1D,CAAC;AAEF;;;;;;;;;;;;;;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D,IAAI,EAAE,uCAAuC,CAAC;IAC9C,OAAO,EAAE,kBAAkB,CAAC,oBAAoB,CAAC,CAAC;CACnD,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,kBAAkB,CAAC,WAAW,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,uCAAuC,CAAC;IAC9C,OAAO,EAAE,kBAAkB,CAAC,oBAAoB,CAAC,CAAC;CACnD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,MAAM,mCAAmC,GAAG;IAChD,IAAI,EAAE,gCAAgC,CAAC;IACvC,OAAO,EAAE,kBAAkB,CAAC,aAAa,CAAC,CAAC;CAC5C,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;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"}
/**
* This file is auto generated by `scripts/generate-method-action-types.ts`.
* Do not edit manually.
*/
import type { ApprovalController } from "./ApprovalController.mjs";
/**
* Adds an approval request per the given arguments, optionally showing
* the approval request to the user.
*
* @param opts - Options bag.
* @param opts.id - The id of the approval request. A random id will be
* generated if none is provided.
* @param opts.origin - The origin of the approval request.
* @param opts.type - The type associated with the approval request.
* @param opts.requestData - Additional data associated with the request,
* if any.
* @param opts.requestState - Additional state associated with the request,
* if any.
* @param shouldShowRequest - Whether to show the approval request to the user.
* @returns The approval promise.
*/
export type ApprovalControllerAddRequestAction = {
type: `ApprovalController:addRequest`;
handler: ApprovalController['addRequest'];
};
/**
* Adds an approval request per the given arguments, calls the show approval
* request function, and returns the associated approval promise resolving to
* an AddResult object.
*
* There can only be one approval per origin and type. An error is thrown if
* attempting to add an invalid or duplicate request.
*
* @param opts - Options bag.
* @param opts.id - The id of the approval request. A random id will be
* generated if none is provided.
* @param opts.origin - The origin of the approval request.
* @param opts.type - The type associated with the approval request.
* @param opts.requestData - Additional data associated with the request,
* @param opts.requestState - Additional state associated with the request,
* if any.
* @returns The approval promise resolving to an AddResult object.
*/
export type ApprovalControllerAddAndShowApprovalRequestAction = {
type: `ApprovalController:addAndShowApprovalRequest`;
handler: ApprovalController['addAndShowApprovalRequest'];
};
/**
* Adds an approval request per the given arguments and returns the approval
* promise resolving to an AddResult object.
*
* There can only be one approval per origin and type. An error is thrown if
* attempting to add an invalid or duplicate request.
*
* @param opts - Options bag.
* @param opts.id - The id of the approval request. A random id will be
* generated if none is provided.
* @param opts.origin - The origin of the approval request.
* @param opts.type - The type associated with the approval request.
* @param opts.requestData - Additional data associated with the request,
* if any.
* @returns The approval promise resolving to an AddResult object.
*/
export type ApprovalControllerAddAction = {
type: `ApprovalController:add`;
handler: ApprovalController['add'];
};
/**
* Gets the info for the approval request with the given id.
*
* @param id - The id of the approval request.
* @returns The approval request data associated with the id.
*/
export type ApprovalControllerGetAction = {
type: `ApprovalController:get`;
handler: ApprovalController['get'];
};
/**
* Gets the number of pending approvals, by origin and/or type.
*
* If only `origin` is specified, all approvals for that origin will be
* counted, regardless of type.
* If only `type` is specified, all approvals for that type will be counted,
* regardless of origin.
* If both `origin` and `type` are specified, 0 or 1 will be returned.
*
* @param opts - The approval count options.
* @param opts.origin - An approval origin.
* @param opts.type - The type of the approval request.
* @returns The current approval request count for the given origin and/or
* type.
*/
export type ApprovalControllerGetApprovalCountAction = {
type: `ApprovalController:getApprovalCount`;
handler: ApprovalController['getApprovalCount'];
};
/**
* Get the total count of all pending approval requests for all origins.
*
* @returns The total pending approval request count.
*/
export type ApprovalControllerGetTotalApprovalCountAction = {
type: `ApprovalController:getTotalApprovalCount`;
handler: ApprovalController['getTotalApprovalCount'];
};
/**
* Checks if there's a pending approval request per the given parameters.
* At least one parameter must be specified. An error will be thrown if the
* parameters are invalid.
*
* If `id` is specified, all other parameters will be ignored.
* If `id` is not specified, the method will check for requests that match
* all of the specified parameters.
*
* @param opts - Options bag.
* @param opts.id - The ID to check for.
* @param opts.origin - The origin to check for.
* @param opts.type - The type to check for.
* @returns `true` if a matching approval is found, and `false` otherwise.
*/
export type ApprovalControllerHasRequestAction = {
type: `ApprovalController:hasRequest`;
handler: ApprovalController['hasRequest'];
};
/**
* Resolves the promise of the approval with the given id, and deletes the
* approval. Throws an error if no such approval exists.
*
* @param id - The id of the approval request.
* @param value - The value to resolve the approval promise with.
* @param options - Options bag.
* @returns A promise that either resolves once a result is provided by
* the creator of the approval request, or immediately if `options.waitForResult`
* is `false` or `undefined`.
*/
export type ApprovalControllerAcceptRequestAction = {
type: `ApprovalController:acceptRequest`;
handler: ApprovalController['acceptRequest'];
};
/**
* Rejects the promise of the approval with the given id, and deletes the
* approval. Throws an error if no such approval exists.
*
* @param id - The id of the approval request.
* @param error - The error to reject the approval promise with.
*/
export type ApprovalControllerRejectRequestAction = {
type: `ApprovalController:rejectRequest`;
handler: ApprovalController['rejectRequest'];
};
/**
* Rejects and deletes all approval requests.
*
* @param rejectionError - The JsonRpcError to reject the approval
* requests with.
*/
export type ApprovalControllerClearRequestsAction = {
type: `ApprovalController:clearRequests`;
handler: ApprovalController['clearRequests'];
};
/**
* Updates the request state of the approval with the given id.
*
* @param opts - Options bag.
* @param opts.id - The id of the approval request.
* @param opts.requestState - Additional data associated with the request
*/
export type ApprovalControllerUpdateRequestStateAction = {
type: `ApprovalController:updateRequestState`;
handler: ApprovalController['updateRequestState'];
};
/**
* Starts a new approval flow.
*
* @param opts - Options bag.
* @param opts.id - The id of the approval flow.
* @param opts.loadingText - The loading text that will be associated to the approval flow.
* @param opts.show - A flag to determine whether the approval should show to the user.
* @returns The object containing the approval flow id.
*/
export type ApprovalControllerStartFlowAction = {
type: `ApprovalController:startFlow`;
handler: ApprovalController['startFlow'];
};
/**
* Ends the current approval flow.
*
* @param opts - Options bag.
* @param opts.id - The id of the approval flow that will be finished.
*/
export type ApprovalControllerEndFlowAction = {
type: `ApprovalController:endFlow`;
handler: ApprovalController['endFlow'];
};
/**
* Sets the loading text for the approval flow.
*
* @param opts - Options bag.
* @param opts.id - The approval flow loading text that will be displayed.
* @param opts.loadingText - The loading text that will be associated to the approval flow.
*/
export type ApprovalControllerSetFlowLoadingTextAction = {
type: `ApprovalController:setFlowLoadingText`;
handler: ApprovalController['setFlowLoadingText'];
};
/**
* Show a success page.
*
* @param opts - Options bag.
* @param opts.message - The message text or components to display in the page.
* @param opts.header - The text or components to display in the header of the page.
* @param opts.flowToEnd - The ID of the approval flow to end once the success page is approved.
* @param opts.title - The title to display above the message. Shown by default but can be hidden with `null`.
* @param opts.icon - The icon to display in the page. Shown by default but can be hidden with `null`.
* @returns Empty object to support future additions.
*/
export type ApprovalControllerShowSuccessAction = {
type: `ApprovalController:showSuccess`;
handler: ApprovalController['showSuccess'];
};
/**
* Show an error page.
*
* @param opts - Options bag.
* @param opts.message - The message text or components to display in the page.
* @param opts.header - The text or components to display in the header of the page.
* @param opts.flowToEnd - The ID of the approval flow to end once the error page is approved.
* @param opts.title - The title to display above the message. Shown by default but can be hidden with `null`.
* @param opts.icon - The icon to display in the page. Shown by default but can be hidden with `null`.
* @returns Empty object to support future additions.
*/
export type ApprovalControllerShowErrorAction = {
type: `ApprovalController:showError`;
handler: ApprovalController['showError'];
};
/**
* Union of all ApprovalController action types.
*/
export type ApprovalControllerMethodActions = ApprovalControllerAddRequestAction | ApprovalControllerAddAndShowApprovalRequestAction | ApprovalControllerAddAction | ApprovalControllerGetAction | ApprovalControllerGetApprovalCountAction | ApprovalControllerGetTotalApprovalCountAction | ApprovalControllerHasRequestAction | ApprovalControllerAcceptRequestAction | ApprovalControllerRejectRequestAction | ApprovalControllerClearRequestsAction | ApprovalControllerUpdateRequestStateAction | ApprovalControllerStartFlowAction | ApprovalControllerEndFlowAction | ApprovalControllerSetFlowLoadingTextAction | ApprovalControllerShowSuccessAction | ApprovalControllerShowErrorAction;
//# sourceMappingURL=ApprovalController-method-action-types.d.mts.map
{"version":3,"file":"ApprovalController-method-action-types.d.mts","sourceRoot":"","sources":["../src/ApprovalController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,iCAA6B;AAE/D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,kBAAkB,CAAC,YAAY,CAAC,CAAC;CAC3C,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,iDAAiD,GAAG;IAC9D,IAAI,EAAE,8CAA8C,CAAC;IACrD,OAAO,EAAE,kBAAkB,CAAC,2BAA2B,CAAC,CAAC;CAC1D,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,wBAAwB,CAAC;IAC/B,OAAO,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC;CACpC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,wBAAwB,CAAC;IAC/B,OAAO,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC;CACpC,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AAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,uCAAuC,CAAC;IAC9C,OAAO,EAAE,kBAAkB,CAAC,oBAAoB,CAAC,CAAC;CACnD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,MAAM,mCAAmC,GAAG;IAChD,IAAI,EAAE,gCAAgC,CAAC;IACvC,OAAO,EAAE,kBAAkB,CAAC,aAAa,CAAC,CAAC;CAC5C,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;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"}
/**
* This file is auto generated by `scripts/generate-method-action-types.ts`.
* Do not edit manually.
*/
export {};
//# sourceMappingURL=ApprovalController-method-action-types.mjs.map
{"version":3,"file":"ApprovalController-method-action-types.mjs","sourceRoot":"","sources":["../src/ApprovalController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { ApprovalController } from './ApprovalController';\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"]}
+24
-1

@@ -10,2 +10,24 @@ # Changelog

## [9.0.0]
### Added
- New `addRequest()` public method ([#8183](https://github.com/MetaMask/core/pull/8183))
- Expose missing public `ApprovalController` methods through its messenger ([#8183](https://github.com/MetaMask/core/pull/8183))
- The following actions are now available:
- `ApprovalController:add`
- `ApprovalController:addAndShowApprovalRequest`
- `ApprovalController:get`
- `ApprovalController:getApprovalCount`
- `ApprovalController:getTotalApprovalCount`
- Corresponding action types (e.g. `ApprovalControllerAddAction`) are available as well.
### Changed
- **BREAKING:** Standardize names of `ApprovalController` methods ([#8183](https://github.com/MetaMask/core/pull/8183))
- All existing methods for handling requests have been renamed so they include `Request` (e.g. `clear()` -> `clearRequest()`). You will need to update usage appropriately.
- The error handling method `error()` has been renamed to include `show` (`error()` -> `showError()`). You will need to update usage appropriately.
- **BREAKING:** Rename get-state action type: `GetApprovalsState` → `ApprovalControllerGetStateAction` ([#8183](https://github.com/MetaMask/core/pull/8183))
- Upgrade `@metamask/utils` from `^11.8.1` to `^11.9.0` ([#7511](https://github.com/MetaMask/core/pull/7511))
## [8.0.0]

@@ -298,3 +320,4 @@

[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/approval-controller@8.0.0...HEAD
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/approval-controller@9.0.0...HEAD
[9.0.0]: https://github.com/MetaMask/core/compare/@metamask/approval-controller@8.0.0...@metamask/approval-controller@9.0.0
[8.0.0]: https://github.com/MetaMask/core/compare/@metamask/approval-controller@7.2.1...@metamask/approval-controller@8.0.0

@@ -301,0 +324,0 @@ [7.2.1]: https://github.com/MetaMask/core/compare/@metamask/approval-controller@7.2.0...@metamask/approval-controller@7.2.1

+47
-28

@@ -54,2 +54,21 @@ "use strict";

};
// === MESSENGER ===
const MESSENGER_EXPOSED_METHODS = [
'acceptRequest',
'add',
'addAndShowApprovalRequest',
'addRequest',
'clearRequests',
'endFlow',
'get',
'getApprovalCount',
'getTotalApprovalCount',
'hasRequest',
'rejectRequest',
'setFlowLoadingText',
'showError',
'showSuccess',
'startFlow',
'updateRequestState',
];
/**

@@ -93,25 +112,25 @@ * Controller for managing requests that require user approval.

__classPrivateFieldSet(this, _ApprovalController_typesExcludedFromRateLimiting, typesExcludedFromRateLimiting, "f");
this.registerMessageHandlers();
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
}
/**
* Constructor helper for registering this controller's messaging system
* actions.
* Adds an approval request per the given arguments, optionally showing
* the approval request to the user.
*
* @param opts - Options bag.
* @param opts.id - The id of the approval request. A random id will be
* generated if none is provided.
* @param opts.origin - The origin of the approval request.
* @param opts.type - The type associated with the approval request.
* @param opts.requestData - Additional data associated with the request,
* if any.
* @param opts.requestState - Additional state associated with the request,
* if any.
* @param shouldShowRequest - Whether to show the approval request to the user.
* @returns The approval promise.
*/
registerMessageHandlers() {
this.messenger.registerActionHandler(`${controllerName}:clearRequests`, this.clear.bind(this));
this.messenger.registerActionHandler(`${controllerName}:addRequest`, (opts, shouldShowRequest) => {
if (shouldShowRequest) {
return this.addAndShowApprovalRequest(opts);
}
return this.add(opts);
});
this.messenger.registerActionHandler(`${controllerName}:hasRequest`, this.has.bind(this));
this.messenger.registerActionHandler(`${controllerName}:acceptRequest`, this.accept.bind(this));
this.messenger.registerActionHandler(`${controllerName}:rejectRequest`, this.reject.bind(this));
this.messenger.registerActionHandler(`${controllerName}:updateRequestState`, this.updateRequestState.bind(this));
this.messenger.registerActionHandler(`${controllerName}:startFlow`, this.startFlow.bind(this));
this.messenger.registerActionHandler(`${controllerName}:endFlow`, this.endFlow.bind(this));
this.messenger.registerActionHandler(`${controllerName}:setFlowLoadingText`, this.setFlowLoadingText.bind(this));
this.messenger.registerActionHandler(`${controllerName}:showSuccess`, this.success.bind(this));
this.messenger.registerActionHandler(`${controllerName}:showError`, this.error.bind(this));
addRequest(opts, shouldShowRequest) {
if (shouldShowRequest) {
return this.addAndShowApprovalRequest(opts);
}
return this.add(opts);
}

@@ -193,3 +212,3 @@ addAndShowApprovalRequest(opts) {

*/
has(opts = {}) {
hasRequest(opts = {}) {
const { id, origin, type: _type } = opts;

@@ -236,3 +255,3 @@ if (id) {

*/
accept(id, value, options) {
acceptRequest(id, value, options) {
// Safe to cast as the delete method below will throw if the ID is not found

@@ -276,3 +295,3 @@ const approval = this.get(id);

*/
reject(id, error) {
rejectRequest(id, error) {
const callbacks = __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_getCallbacks).call(this, id);

@@ -288,5 +307,5 @@ __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_delete).call(this, id);

*/
clear(rejectionError) {
clearRequests(rejectionError) {
for (const id of __classPrivateFieldGet(this, _ApprovalController_approvals, "f").keys()) {
this.reject(id, rejectionError);
this.rejectRequest(id, rejectionError);
}

@@ -381,3 +400,3 @@ __classPrivateFieldGet(this, _ApprovalController_origins, "f").clear();

*/
async success(opts = {}) {
async showSuccess(opts = {}) {
await __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_result).call(this, exports.APPROVAL_TYPE_RESULT_SUCCESS, opts, {

@@ -402,3 +421,3 @@ message: opts.message,

*/
async error(opts = {}) {
async showError(opts = {}) {
await __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_result).call(this, exports.APPROVAL_TYPE_RESULT_ERROR, opts, {

@@ -417,3 +436,3 @@ error: opts.error,

if (!__classPrivateFieldGet(this, _ApprovalController_typesExcludedFromRateLimiting, "f").includes(type) &&
this.has({ origin, type })) {
this.hasRequest({ origin, type })) {
throw rpc_errors_1.rpcErrors.resourceUnavailable(getAlreadyPendingMessage(origin, type));

@@ -420,0 +439,0 @@ }

@@ -1,1 +0,1 @@

{"version":3,"file":"ApprovalController.cjs","sourceRoot":"","sources":["../src/ApprovalController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAIA,+DAGmC;AAGnC,qDAAiD;AAEjD,mCAAgC;AAEhC,yCAMkB;AAElB,YAAY;AAEZ,0CAA0C;AAC7B,QAAA,eAAe,GAAG,UAAU,CAAC;AAC7B,QAAA,0BAA0B,GAAG,cAAc,CAAC;AAC5C,QAAA,4BAA4B,GAAG,gBAAgB,CAAC;AAE7D,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAE5C,MAAM,aAAa,GAA2C;IAC5D,gBAAgB,EAAE;QAChB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;IACD,oBAAoB,EAAE;QACpB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;IACD,aAAa,EAAE;QACb,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAA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;KACF;AACH,CAAC;AAGH,kBAAe,kBAAkB,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n StateMetadata,\n} from '@metamask/base-controller';\nimport {\n BaseController,\n type ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { JsonRpcError, DataWithOptionalCause } from '@metamask/rpc-errors';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { Json, OptionalField } from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\nimport {\n ApprovalRequestNotFoundError,\n ApprovalRequestNoResultSupportError,\n EndInvalidFlowError,\n NoApprovalFlowsError,\n MissingApprovalFlowError,\n} from './errors';\n\n// Constants\n\n// Avoiding dependency on controller-utils\nexport const ORIGIN_METAMASK = 'metamask';\nexport const APPROVAL_TYPE_RESULT_ERROR = 'result_error';\nexport const APPROVAL_TYPE_RESULT_SUCCESS = 'result_success';\n\nconst controllerName = 'ApprovalController';\n\nconst stateMetadata: StateMetadata<ApprovalControllerState> = {\n pendingApprovals: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n pendingApprovalCount: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n approvalFlows: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\nconst getAlreadyPendingMessage = (origin: string, type: string) =>\n `Request of type '${type}' already pending for origin ${origin}. Please wait.`;\n\nconst getDefaultState = (): ApprovalControllerState => {\n return {\n pendingApprovals: {},\n pendingApprovalCount: 0,\n approvalFlows: [],\n };\n};\n\n// Internal Types\n\ntype ApprovalPromiseResolve = (value?: unknown | AddResult) => void;\n\ntype ApprovalPromiseReject = (error?: unknown) => void;\n\ntype ApprovalRequestData = Record<string, Json> | null;\n\ntype ApprovalRequestState = Record<string, Json> | null;\n\ntype ApprovalCallbacks = {\n resolve: ApprovalPromiseResolve;\n reject: ApprovalPromiseReject;\n};\n\ntype ApprovalFlow = {\n id: string;\n loadingText: string | null;\n};\n\ntype ResultOptions = {\n flowToEnd?: string;\n header?: (string | ResultComponent)[];\n icon?: string | null;\n title?: string | null;\n};\n\n// Miscellaneous Types\n\nexport type ApprovalRequest<RequestData extends ApprovalRequestData> = {\n /**\n * The ID of the approval request.\n */\n id: string;\n\n /**\n * The origin of the approval request.\n */\n origin: string;\n\n /**\n * The time that the request was received, per Date.now().\n */\n time: number;\n\n /**\n * The type of the approval request.\n * Unfortunately, not all values will match the `ApprovalType` enum, so we are using `string` here.\n * TODO: Replace `string` with `ApprovalType` when all `type` values used by the clients can be encompassed by the `ApprovalType` enum.\n */\n type: string;\n\n /**\n * Additional data associated with the request.\n */\n requestData: RequestData;\n\n /**\n * Additional mutable state associated with the request\n */\n requestState: ApprovalRequestState;\n\n /**\n * Whether the request expects a result object to be returned instead of just the approval value.\n */\n expectsResult: boolean;\n};\n\nexport type ApprovalFlowState = ApprovalFlow;\n\nexport type ApprovalControllerState = {\n pendingApprovals: Record<string, ApprovalRequest<Record<string, Json>>>;\n pendingApprovalCount: number;\n approvalFlows: ApprovalFlowState[];\n};\n\nexport type ApprovalControllerMessenger = Messenger<\n typeof controllerName,\n ApprovalControllerActions,\n ApprovalControllerEvents\n>;\n\n// Option Types\n\nexport type ShowApprovalRequest = () => void | Promise<void>;\n\nexport type ResultComponent = {\n /**\n * A unique identifier for this instance of the component.\n */\n key: string;\n\n /**\n * The name of the component to render.\n */\n name: string;\n\n /**\n * Any properties required by the component.\n */\n properties?: Record<string, unknown>;\n\n /**\n * Any child components to render inside the component.\n */\n children?: string | ResultComponent | (string | ResultComponent)[];\n};\n\nexport type ApprovalControllerOptions = {\n messenger: ApprovalControllerMessenger;\n showApprovalRequest: ShowApprovalRequest;\n state?: Partial<ApprovalControllerState>;\n typesExcludedFromRateLimiting?: string[];\n};\n\nexport type AddApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData?: Record<string, Json>;\n requestState?: Record<string, Json>;\n expectsResult?: boolean;\n};\n\nexport type UpdateRequestStateOptions = {\n id: string;\n requestState: Record<string, Json>;\n};\n\nexport type AcceptOptions = {\n /**\n * Whether to resolve the returned promise only when the request creator indicates the success of the\n * post-approval logic using the result callbacks.\n * If false or unspecified, the promise will resolve immediately.\n */\n waitForResult?: boolean;\n\n /**\n * Whether to delete the approval request after a result callback is called.\n * If false or unspecified, the approval request will be deleted immediately.\n * Ignored if `waitForResult` is false or unspecified.\n */\n deleteAfterResult?: boolean;\n};\n\nexport type StartFlowOptions = OptionalField<\n ApprovalFlow,\n 'id' | 'loadingText'\n> & { show?: boolean };\n\nexport type EndFlowOptions = Pick<ApprovalFlow, 'id'>;\n\nexport type SetFlowLoadingTextOptions = ApprovalFlow;\n\nexport type SuccessOptions = ResultOptions & {\n message?: string | ResultComponent | (string | ResultComponent)[];\n};\n\nexport type ErrorOptions = ResultOptions & {\n error?: string | ResultComponent | (string | ResultComponent)[];\n};\n\n// Result Types\n\nexport type AcceptResultCallbacks = {\n /**\n * Inform the request acceptor that the post-approval logic was successful.\n *\n * @param value - An optional value generated by the post-approval logic.\n */\n success: (value?: unknown) => void;\n\n /**\n * Inform the request acceptor that the post-approval logic failed.\n *\n * @param error - The reason for the failure.\n */\n error: (error: Error) => void;\n};\n\nexport type AddResult = {\n /**\n * An optional value provided by the request acceptor.\n */\n value?: unknown;\n\n /**\n * Callback functions that must be used to indicate to the request acceptor whether the post-approval logic was successful or not.\n * Will be undefined if the request acceptor did not specify that they want to wait for a result.\n */\n resultCallbacks?: AcceptResultCallbacks;\n};\n\nexport type AcceptResult = {\n /**\n * An optional value provided by the request creator when indicating a successful result.\n */\n value?: unknown;\n};\n\nexport type ApprovalFlowStartResult = ApprovalFlow;\n\nexport type SuccessResult = Record<string, never>;\n\nexport type ErrorResult = Record<string, never>;\n\n// Event Types\n\nexport type ApprovalStateChange = ControllerStateChangeEvent<\n typeof controllerName,\n ApprovalControllerState\n>;\n\nexport type ApprovalControllerEvents = ApprovalStateChange;\n\n// Action Types\n\nexport type GetApprovalsState = ControllerGetStateAction<\n typeof controllerName,\n ApprovalControllerState\n>;\n\nexport type ClearApprovalRequests = {\n type: `${typeof controllerName}:clearRequests`;\n handler: (error: JsonRpcError<DataWithOptionalCause>) => void;\n};\n\nexport type AddApprovalRequest = {\n type: `${typeof controllerName}:addRequest`;\n handler: (\n opts: AddApprovalOptions,\n shouldShowRequest: boolean,\n ) => ReturnType<ApprovalController['add']>;\n};\n\nexport type HasApprovalRequest = {\n type: `${typeof controllerName}:hasRequest`;\n handler: ApprovalController['has'];\n};\n\nexport type AcceptRequest = {\n type: `${typeof controllerName}:acceptRequest`;\n handler: ApprovalController['accept'];\n};\n\nexport type RejectRequest = {\n type: `${typeof controllerName}:rejectRequest`;\n handler: ApprovalController['reject'];\n};\n\nexport type UpdateRequestState = {\n type: `${typeof controllerName}:updateRequestState`;\n handler: ApprovalController['updateRequestState'];\n};\n\nexport type StartFlow = {\n type: `${typeof controllerName}:startFlow`;\n handler: ApprovalController['startFlow'];\n};\n\nexport type EndFlow = {\n type: `${typeof controllerName}:endFlow`;\n handler: ApprovalController['endFlow'];\n};\n\nexport type SetFlowLoadingText = {\n type: `${typeof controllerName}:setFlowLoadingText`;\n handler: ApprovalController['setFlowLoadingText'];\n};\n\nexport type ShowSuccess = {\n type: `${typeof controllerName}:showSuccess`;\n handler: ApprovalController['success'];\n};\n\nexport type ShowError = {\n type: `${typeof controllerName}:showError`;\n handler: ApprovalController['error'];\n};\n\nexport type ApprovalControllerActions =\n | GetApprovalsState\n | ClearApprovalRequests\n | AddApprovalRequest\n | HasApprovalRequest\n | AcceptRequest\n | RejectRequest\n | UpdateRequestState\n | StartFlow\n | EndFlow\n | SetFlowLoadingText\n | ShowSuccess\n | ShowError;\n\n/**\n * Controller for managing requests that require user approval.\n *\n * Enables limiting the number of pending requests by origin and type, counting\n * pending requests, and more.\n *\n * Adding a request returns a promise that resolves or rejects when the request\n * is approved or denied, respectively.\n */\nexport class ApprovalController extends BaseController<\n typeof controllerName,\n ApprovalControllerState,\n ApprovalControllerMessenger\n> {\n #approvals: Map<string, ApprovalCallbacks>;\n\n #origins: Map<string, Map<string, number>>;\n\n #showApprovalRequest: () => void;\n\n #typesExcludedFromRateLimiting: string[];\n\n /**\n * Construct an Approval controller.\n *\n * @param options - The controller options.\n * @param options.showApprovalRequest - Function for opening the UI such that\n * the request can be displayed to the user.\n * @param options.messenger - The restricted messenger for the Approval controller.\n * @param options.state - The initial controller state.\n * @param options.typesExcludedFromRateLimiting - Array of approval types which allow multiple pending approval requests from the same origin.\n */\n constructor({\n messenger,\n showApprovalRequest,\n state = {},\n typesExcludedFromRateLimiting = [],\n }: ApprovalControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.#approvals = new Map();\n this.#origins = new Map();\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#showApprovalRequest = showApprovalRequest;\n this.#typesExcludedFromRateLimiting = typesExcludedFromRateLimiting;\n this.registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n private registerMessageHandlers(): void {\n this.messenger.registerActionHandler(\n `${controllerName}:clearRequests` as const,\n this.clear.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:addRequest` as const,\n (opts: AddApprovalOptions, shouldShowRequest: boolean) => {\n if (shouldShowRequest) {\n return this.addAndShowApprovalRequest(opts);\n }\n return this.add(opts);\n },\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:hasRequest` as const,\n this.has.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:acceptRequest` as const,\n this.accept.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:rejectRequest` as const,\n this.reject.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:updateRequestState` as const,\n this.updateRequestState.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:startFlow` as const,\n this.startFlow.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:endFlow` as const,\n this.endFlow.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:setFlowLoadingText` as const,\n this.setFlowLoadingText.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:showSuccess` as const,\n this.success.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:showError` as const,\n this.error.bind(this),\n );\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 */\n addAndShowApprovalRequest(\n opts: AddApprovalOptions & { expectsResult: true },\n ): Promise<AddResult>;\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\n * to a value provided during acceptance.\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 a value provided during acceptance.\n */\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise<unknown>;\n\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise<unknown> {\n const promise = this.#add(\n opts.origin,\n opts.type,\n opts.id,\n opts.requestData,\n opts.requestState,\n opts.expectsResult,\n );\n this.#showApprovalRequest();\n return promise;\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 */\n add(opts: AddApprovalOptions & { expectsResult: true }): Promise<AddResult>;\n\n /**\n * Adds an approval request per the given arguments and returns the approval\n * promise resolving to a value provided during acceptance.\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 a value provided during acceptance.\n */\n add(opts: AddApprovalOptions): Promise<unknown>;\n\n add(opts: AddApprovalOptions): Promise<unknown | AddResult> {\n return this.#add(\n opts.origin,\n opts.type,\n opts.id,\n opts.requestData,\n opts.requestState,\n opts.expectsResult,\n );\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 */\n get(id: string): ApprovalRequest<ApprovalRequestData> | undefined {\n return this.state.pendingApprovals[id];\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 */\n getApprovalCount(opts: { origin?: string; type?: string } = {}): number {\n if (!opts.origin && !opts.type) {\n throw new Error('Must specify origin, type, or both.');\n }\n const { origin, type: _type } = opts;\n\n if (origin && _type) {\n return this.#origins.get(origin)?.get(_type) || 0;\n }\n\n if (origin) {\n return Array.from(\n (this.#origins.get(origin) || new Map()).values(),\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n ).reduce((total, value) => total + value, 0);\n }\n\n // Only \"type\" was specified\n let count = 0;\n for (const approval of Object.values(this.state.pendingApprovals)) {\n if (approval.type === _type) {\n count += 1;\n }\n }\n return count;\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 */\n getTotalApprovalCount(): number {\n return this.state.pendingApprovalCount;\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 */\n has(opts: { id?: string; origin?: string; type?: string } = {}): boolean {\n const { id, origin, type: _type } = opts;\n\n if (id) {\n if (typeof id !== 'string') {\n throw new Error('May not specify non-string id.');\n }\n return this.#approvals.has(id);\n }\n\n if (_type && typeof _type !== 'string') {\n throw new Error('May not specify non-string type.');\n }\n\n if (origin) {\n if (typeof origin !== 'string') {\n throw new Error('May not specify non-string origin.');\n }\n\n // Check origin and type pair if type also specified\n if (_type) {\n return Boolean(this.#origins.get(origin)?.get(_type));\n }\n return this.#origins.has(origin);\n }\n\n if (_type) {\n for (const approval of Object.values(this.state.pendingApprovals)) {\n if (approval.type === _type) {\n return true;\n }\n }\n return false;\n }\n throw new Error(\n 'Must specify a valid combination of id, origin, and type.',\n );\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 */\n accept(\n id: string,\n value?: unknown,\n options?: AcceptOptions,\n ): Promise<AcceptResult> {\n // Safe to cast as the delete method below will throw if the ID is not found\n const approval = this.get(id) as ApprovalRequest<ApprovalRequestData>;\n const requestPromise = this.#getCallbacks(id);\n let requestDeleted = false;\n\n if (!options?.deleteAfterResult || !options.waitForResult) {\n this.#delete(id);\n requestDeleted = true;\n }\n\n return new Promise<AcceptResult>((resolve, reject) => {\n const resultCallbacks: AcceptResultCallbacks = {\n success: (acceptValue?: unknown) => resolve({ value: acceptValue }),\n error: reject,\n };\n\n if (options?.waitForResult && !approval.expectsResult) {\n reject(new ApprovalRequestNoResultSupportError(id));\n return;\n }\n\n const resultValue = options?.waitForResult ? resultCallbacks : undefined;\n\n const resolveValue = approval.expectsResult\n ? { value, resultCallbacks: resultValue }\n : value;\n\n requestPromise.resolve(resolveValue);\n\n if (!options?.waitForResult) {\n resolve({ value: undefined });\n }\n }).finally(() => {\n if (!requestDeleted) {\n this.#delete(id);\n }\n });\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 */\n reject(id: string, error: unknown): void {\n const callbacks = this.#getCallbacks(id);\n this.#delete(id);\n callbacks.reject(error);\n }\n\n /**\n * Rejects and deletes all approval requests.\n *\n * @param rejectionError - The JsonRpcError to reject the approval\n * requests with.\n */\n clear(rejectionError: JsonRpcError<DataWithOptionalCause>): void {\n for (const id of this.#approvals.keys()) {\n this.reject(id, rejectionError);\n }\n this.#origins.clear();\n this.update((draftState) => {\n draftState.pendingApprovals = {};\n draftState.pendingApprovalCount = 0;\n });\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 */\n updateRequestState(opts: UpdateRequestStateOptions): void {\n if (!this.state.pendingApprovals[opts.id]) {\n throw new ApprovalRequestNotFoundError(opts.id);\n }\n\n this.update((draftState) => {\n draftState.pendingApprovals[opts.id].requestState =\n opts.requestState as never;\n });\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 */\n startFlow(opts: StartFlowOptions = {}): ApprovalFlowStartResult {\n const id = opts.id ?? nanoid();\n const loadingText = opts.loadingText ?? null;\n\n this.update((draftState) => {\n draftState.approvalFlows.push({ id, loadingText });\n });\n\n // By default, if nothing else is specified, we always show the approval.\n if (opts.show !== false) {\n this.#showApprovalRequest();\n }\n\n return { id, loadingText };\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 */\n endFlow({ id }: EndFlowOptions) {\n if (!this.state.approvalFlows.length) {\n throw new NoApprovalFlowsError();\n }\n\n const currentFlow = this.state.approvalFlows.slice(-1)[0];\n\n if (id !== currentFlow.id) {\n throw new EndInvalidFlowError(\n id,\n this.state.approvalFlows.map((flow) => flow.id),\n );\n }\n\n this.update((draftState) => {\n draftState.approvalFlows.pop();\n });\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 */\n setFlowLoadingText({ id, loadingText }: SetFlowLoadingTextOptions) {\n const flowIndex = this.state.approvalFlows.findIndex(\n (flow) => flow.id === id,\n );\n\n if (flowIndex === -1) {\n throw new MissingApprovalFlowError(id);\n }\n\n this.update((draftState) => {\n draftState.approvalFlows[flowIndex].loadingText = loadingText;\n });\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 */\n async success(opts: SuccessOptions = {}): Promise<SuccessResult> {\n await this.#result(APPROVAL_TYPE_RESULT_SUCCESS, opts, {\n message: opts.message,\n header: opts.header,\n title: opts.title,\n icon: opts.icon,\n } as Record<string, Json>);\n\n return {};\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 */\n async error(opts: ErrorOptions = {}): Promise<ErrorResult> {\n await this.#result(APPROVAL_TYPE_RESULT_ERROR, opts, {\n error: opts.error,\n header: opts.header,\n title: opts.title,\n icon: opts.icon,\n } as Record<string, Json>);\n\n return {};\n }\n\n /**\n * Implementation of add operation.\n *\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param id - The id of the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n * @param expectsResult - Whether the approval request expects a result object to be returned.\n * @returns The approval promise.\n */\n #add(\n origin: string,\n type: string,\n id: string = nanoid(),\n requestData?: Record<string, Json>,\n requestState?: Record<string, Json>,\n expectsResult?: boolean,\n ): Promise<unknown | AddResult> {\n this.#validateAddParams(id, origin, type, requestData, requestState);\n\n if (\n !this.#typesExcludedFromRateLimiting.includes(type) &&\n this.has({ origin, type })\n ) {\n throw rpcErrors.resourceUnavailable(\n getAlreadyPendingMessage(origin, type),\n );\n }\n\n // add pending approval\n return new Promise((resolve, reject) => {\n this.#approvals.set(id, { resolve, reject });\n this.#addPendingApprovalOrigin(origin, type);\n\n this.#addToStore(\n id,\n origin,\n type,\n requestData,\n requestState,\n expectsResult,\n );\n });\n }\n\n /**\n * Validates parameters to the add method.\n *\n * @param id - The id of the approval request.\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n */\n #validateAddParams(\n id: string,\n origin: string,\n type: string,\n requestData?: Record<string, Json>,\n requestState?: Record<string, Json>,\n ): void {\n let errorMessage = null;\n if (!id || typeof id !== 'string') {\n errorMessage = 'Must specify non-empty string id.';\n } else if (this.#approvals.has(id)) {\n errorMessage = `Approval request with id '${id}' already exists.`;\n } else if (!origin || typeof origin !== 'string') {\n errorMessage = 'Must specify non-empty string origin.';\n } else if (!type || typeof type !== 'string') {\n errorMessage = 'Must specify non-empty string type.';\n } else if (\n requestData &&\n (typeof requestData !== 'object' || Array.isArray(requestData))\n ) {\n errorMessage = 'Request data must be a plain object if specified.';\n } else if (\n requestState &&\n (typeof requestState !== 'object' || Array.isArray(requestState))\n ) {\n errorMessage = 'Request state must be a plain object if specified.';\n }\n\n if (errorMessage) {\n throw rpcErrors.internal(errorMessage);\n }\n }\n\n /**\n * Adds an entry to _origins.\n * Performs no validation.\n *\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n */\n #addPendingApprovalOrigin(origin: string, type: string): void {\n let originMap = this.#origins.get(origin);\n\n if (!originMap) {\n originMap = new Map();\n this.#origins.set(origin, originMap);\n }\n\n const currentValue = originMap.get(type) || 0;\n originMap.set(type, currentValue + 1);\n }\n\n /**\n * Adds an entry to the store.\n * Performs no validation.\n *\n * @param id - The id of the approval request.\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n * @param expectsResult - Whether the request expects a result object to be returned.\n */\n #addToStore(\n id: string,\n origin: string,\n type: string,\n requestData?: Record<string, Json>,\n requestState?: Record<string, Json>,\n expectsResult?: boolean,\n ): void {\n const approval = {\n id,\n origin,\n type,\n time: Date.now(),\n requestData: requestData || null,\n requestState: requestState || null,\n expectsResult: expectsResult || false,\n };\n\n this.update((draftState) => {\n draftState.pendingApprovals[id] = approval as never;\n\n draftState.pendingApprovalCount = Object.keys(\n draftState.pendingApprovals,\n ).length;\n });\n }\n\n /**\n * Deletes the approval with the given id.\n *\n * Deletion is an internal operation because approval state is solely\n * managed by this controller.\n *\n * @param id - The id of the approval request to be deleted.\n */\n #delete(id: string): void {\n if (!this.#approvals.has(id)) {\n throw new ApprovalRequestNotFoundError(id);\n }\n\n this.#approvals.delete(id);\n\n const { origin, type } = this.state.pendingApprovals[id];\n\n const originMap = this.#origins.get(origin) as Map<string, number>;\n const originTotalCount = this.getApprovalCount({ origin });\n const originTypeCount = originMap.get(type) as number;\n\n if (originTotalCount === 1) {\n this.#origins.delete(origin);\n } else {\n originMap.set(type, originTypeCount - 1);\n }\n\n this.update((draftState) => {\n delete draftState.pendingApprovals[id];\n draftState.pendingApprovalCount = Object.keys(\n draftState.pendingApprovals,\n ).length;\n });\n }\n\n #getCallbacks(id: string): ApprovalCallbacks {\n const callbacks = this.#approvals.get(id);\n\n if (!callbacks) {\n throw new ApprovalRequestNotFoundError(id);\n }\n\n return callbacks;\n }\n\n async #result(\n type: string,\n opts: ResultOptions,\n requestData: Record<string, Json>,\n ) {\n try {\n await this.addAndShowApprovalRequest({\n origin: ORIGIN_METAMASK,\n type,\n requestData,\n });\n } catch (error) {\n console.info('Failed to display result page', error);\n } finally {\n if (opts.flowToEnd) {\n try {\n this.endFlow({ id: opts.flowToEnd });\n } catch (error) {\n console.info('Failed to end flow', { id: opts.flowToEnd, error });\n }\n }\n }\n }\n}\n\nexport default ApprovalController;\n"]}
{"version":3,"file":"ApprovalController.cjs","sourceRoot":"","sources":["../src/ApprovalController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+DAA2D;AAQ3D,qDAAiD;AAEjD,mCAAgC;AAG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kB,CAAC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n StateMetadata,\n} from '@metamask/base-controller';\nimport type { ControllerStateChangeEvent } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { JsonRpcError, DataWithOptionalCause } from '@metamask/rpc-errors';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { Json, OptionalField } from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\nimport type { ApprovalControllerMethodActions } from './ApprovalController-method-action-types';\nimport {\n ApprovalRequestNotFoundError,\n ApprovalRequestNoResultSupportError,\n EndInvalidFlowError,\n NoApprovalFlowsError,\n MissingApprovalFlowError,\n} from './errors';\n\n// Constants\n\n// Avoiding dependency on controller-utils\nexport const ORIGIN_METAMASK = 'metamask';\nexport const APPROVAL_TYPE_RESULT_ERROR = 'result_error';\nexport const APPROVAL_TYPE_RESULT_SUCCESS = 'result_success';\n\nconst controllerName = 'ApprovalController';\n\nconst stateMetadata: StateMetadata<ApprovalControllerState> = {\n pendingApprovals: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n pendingApprovalCount: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n approvalFlows: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\nconst getAlreadyPendingMessage = (origin: string, type: string) =>\n `Request of type '${type}' already pending for origin ${origin}. Please wait.`;\n\nconst getDefaultState = (): ApprovalControllerState => {\n return {\n pendingApprovals: {},\n pendingApprovalCount: 0,\n approvalFlows: [],\n };\n};\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'acceptRequest',\n 'add',\n 'addAndShowApprovalRequest',\n 'addRequest',\n 'clearRequests',\n 'endFlow',\n 'get',\n 'getApprovalCount',\n 'getTotalApprovalCount',\n 'hasRequest',\n 'rejectRequest',\n 'setFlowLoadingText',\n 'showError',\n 'showSuccess',\n 'startFlow',\n 'updateRequestState',\n] as const;\n\n// Internal Types\n\ntype ApprovalPromiseResolve = (value?: unknown | AddResult) => void;\n\ntype ApprovalPromiseReject = (error?: unknown) => void;\n\ntype ApprovalRequestData = Record<string, Json> | null;\n\ntype ApprovalRequestState = Record<string, Json> | null;\n\ntype ApprovalCallbacks = {\n resolve: ApprovalPromiseResolve;\n reject: ApprovalPromiseReject;\n};\n\ntype ApprovalFlow = {\n id: string;\n loadingText: string | null;\n};\n\ntype ResultOptions = {\n flowToEnd?: string;\n header?: (string | ResultComponent)[];\n icon?: string | null;\n title?: string | null;\n};\n\n// Miscellaneous Types\n\nexport type ApprovalRequest<RequestData extends ApprovalRequestData> = {\n /**\n * The ID of the approval request.\n */\n id: string;\n\n /**\n * The origin of the approval request.\n */\n origin: string;\n\n /**\n * The time that the request was received, per Date.now().\n */\n time: number;\n\n /**\n * The type of the approval request.\n * Unfortunately, not all values will match the `ApprovalType` enum, so we are using `string` here.\n * TODO: Replace `string` with `ApprovalType` when all `type` values used by the clients can be encompassed by the `ApprovalType` enum.\n */\n type: string;\n\n /**\n * Additional data associated with the request.\n */\n requestData: RequestData;\n\n /**\n * Additional mutable state associated with the request\n */\n requestState: ApprovalRequestState;\n\n /**\n * Whether the request expects a result object to be returned instead of just the approval value.\n */\n expectsResult: boolean;\n};\n\nexport type ApprovalFlowState = ApprovalFlow;\n\nexport type ApprovalControllerState = {\n pendingApprovals: Record<string, ApprovalRequest<Record<string, Json>>>;\n pendingApprovalCount: number;\n approvalFlows: ApprovalFlowState[];\n};\n\nexport type ApprovalControllerMessenger = Messenger<\n typeof controllerName,\n ApprovalControllerActions,\n ApprovalControllerEvents\n>;\n\n// Option Types\n\nexport type ShowApprovalRequest = () => void | Promise<void>;\n\nexport type ResultComponent = {\n /**\n * A unique identifier for this instance of the component.\n */\n key: string;\n\n /**\n * The name of the component to render.\n */\n name: string;\n\n /**\n * Any properties required by the component.\n */\n properties?: Record<string, unknown>;\n\n /**\n * Any child components to render inside the component.\n */\n children?: string | ResultComponent | (string | ResultComponent)[];\n};\n\nexport type ApprovalControllerOptions = {\n messenger: ApprovalControllerMessenger;\n showApprovalRequest: ShowApprovalRequest;\n state?: Partial<ApprovalControllerState>;\n typesExcludedFromRateLimiting?: string[];\n};\n\nexport type AddApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData?: Record<string, Json>;\n requestState?: Record<string, Json>;\n expectsResult?: boolean;\n};\n\nexport type UpdateRequestStateOptions = {\n id: string;\n requestState: Record<string, Json>;\n};\n\nexport type AcceptOptions = {\n /**\n * Whether to resolve the returned promise only when the request creator indicates the success of the\n * post-approval logic using the result callbacks.\n * If false or unspecified, the promise will resolve immediately.\n */\n waitForResult?: boolean;\n\n /**\n * Whether to delete the approval request after a result callback is called.\n * If false or unspecified, the approval request will be deleted immediately.\n * Ignored if `waitForResult` is false or unspecified.\n */\n deleteAfterResult?: boolean;\n};\n\nexport type StartFlowOptions = OptionalField<\n ApprovalFlow,\n 'id' | 'loadingText'\n> & { show?: boolean };\n\nexport type EndFlowOptions = Pick<ApprovalFlow, 'id'>;\n\nexport type SetFlowLoadingTextOptions = ApprovalFlow;\n\nexport type SuccessOptions = ResultOptions & {\n message?: string | ResultComponent | (string | ResultComponent)[];\n};\n\nexport type ErrorOptions = ResultOptions & {\n error?: string | ResultComponent | (string | ResultComponent)[];\n};\n\n// Result Types\n\nexport type AcceptResultCallbacks = {\n /**\n * Inform the request acceptor that the post-approval logic was successful.\n *\n * @param value - An optional value generated by the post-approval logic.\n */\n success: (value?: unknown) => void;\n\n /**\n * Inform the request acceptor that the post-approval logic failed.\n *\n * @param error - The reason for the failure.\n */\n error: (error: Error) => void;\n};\n\nexport type AddResult = {\n /**\n * An optional value provided by the request acceptor.\n */\n value?: unknown;\n\n /**\n * Callback functions that must be used to indicate to the request acceptor whether the post-approval logic was successful or not.\n * Will be undefined if the request acceptor did not specify that they want to wait for a result.\n */\n resultCallbacks?: AcceptResultCallbacks;\n};\n\nexport type AcceptResult = {\n /**\n * An optional value provided by the request creator when indicating a successful result.\n */\n value?: unknown;\n};\n\nexport type ApprovalFlowStartResult = ApprovalFlow;\n\nexport type SuccessResult = Record<string, never>;\n\nexport type ErrorResult = Record<string, never>;\n\n// Event Types\n\nexport type ApprovalStateChange = ControllerStateChangeEvent<\n typeof controllerName,\n ApprovalControllerState\n>;\n\nexport type ApprovalControllerEvents = ApprovalStateChange;\n\n// Action Types\n\nexport type ApprovalControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n ApprovalControllerState\n>;\n\nexport type ApprovalControllerActions =\n | ApprovalControllerGetStateAction\n | ApprovalControllerMethodActions;\n\n/**\n * Controller for managing requests that require user approval.\n *\n * Enables limiting the number of pending requests by origin and type, counting\n * pending requests, and more.\n *\n * Adding a request returns a promise that resolves or rejects when the request\n * is approved or denied, respectively.\n */\nexport class ApprovalController extends BaseController<\n typeof controllerName,\n ApprovalControllerState,\n ApprovalControllerMessenger\n> {\n readonly #approvals: Map<string, ApprovalCallbacks>;\n\n readonly #origins: Map<string, Map<string, number>>;\n\n readonly #showApprovalRequest: () => void;\n\n readonly #typesExcludedFromRateLimiting: string[];\n\n /**\n * Construct an Approval controller.\n *\n * @param options - The controller options.\n * @param options.showApprovalRequest - Function for opening the UI such that\n * the request can be displayed to the user.\n * @param options.messenger - The restricted messenger for the Approval controller.\n * @param options.state - The initial controller state.\n * @param options.typesExcludedFromRateLimiting - Array of approval types which allow multiple pending approval requests from the same origin.\n */\n constructor({\n messenger,\n showApprovalRequest,\n state = {},\n typesExcludedFromRateLimiting = [],\n }: ApprovalControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.#approvals = new Map();\n this.#origins = new Map();\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#showApprovalRequest = showApprovalRequest;\n this.#typesExcludedFromRateLimiting = typesExcludedFromRateLimiting;\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\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 */\n addRequest(\n opts: AddApprovalOptions,\n shouldShowRequest: boolean,\n ): Promise<unknown> {\n if (shouldShowRequest) {\n return this.addAndShowApprovalRequest(opts);\n }\n return this.add(opts);\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 */\n addAndShowApprovalRequest(\n opts: AddApprovalOptions & { expectsResult: true },\n ): Promise<AddResult>;\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\n * to a value provided during acceptance.\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 a value provided during acceptance.\n */\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise<unknown>;\n\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise<unknown> {\n const promise = this.#add(\n opts.origin,\n opts.type,\n opts.id,\n opts.requestData,\n opts.requestState,\n opts.expectsResult,\n );\n this.#showApprovalRequest();\n return promise;\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 */\n add(opts: AddApprovalOptions & { expectsResult: true }): Promise<AddResult>;\n\n /**\n * Adds an approval request per the given arguments and returns the approval\n * promise resolving to a value provided during acceptance.\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 a value provided during acceptance.\n */\n add(opts: AddApprovalOptions): Promise<unknown>;\n\n add(opts: AddApprovalOptions): Promise<unknown | AddResult> {\n return this.#add(\n opts.origin,\n opts.type,\n opts.id,\n opts.requestData,\n opts.requestState,\n opts.expectsResult,\n );\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 */\n get(id: string): ApprovalRequest<ApprovalRequestData> | undefined {\n return this.state.pendingApprovals[id];\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 */\n getApprovalCount(opts: { origin?: string; type?: string } = {}): number {\n if (!opts.origin && !opts.type) {\n throw new Error('Must specify origin, type, or both.');\n }\n const { origin, type: _type } = opts;\n\n if (origin && _type) {\n return this.#origins.get(origin)?.get(_type) || 0;\n }\n\n if (origin) {\n return Array.from(\n (this.#origins.get(origin) || new Map()).values(),\n ).reduce((total, value) => total + value, 0);\n }\n\n // Only \"type\" was specified\n let count = 0;\n for (const approval of Object.values(this.state.pendingApprovals)) {\n if (approval.type === _type) {\n count += 1;\n }\n }\n return count;\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 */\n getTotalApprovalCount(): number {\n return this.state.pendingApprovalCount;\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 */\n hasRequest(\n opts: { id?: string; origin?: string; type?: string } = {},\n ): boolean {\n const { id, origin, type: _type } = opts;\n\n if (id) {\n if (typeof id !== 'string') {\n throw new Error('May not specify non-string id.');\n }\n return this.#approvals.has(id);\n }\n\n if (_type && typeof _type !== 'string') {\n throw new Error('May not specify non-string type.');\n }\n\n if (origin) {\n if (typeof origin !== 'string') {\n throw new Error('May not specify non-string origin.');\n }\n\n // Check origin and type pair if type also specified\n if (_type) {\n return Boolean(this.#origins.get(origin)?.get(_type));\n }\n return this.#origins.has(origin);\n }\n\n if (_type) {\n for (const approval of Object.values(this.state.pendingApprovals)) {\n if (approval.type === _type) {\n return true;\n }\n }\n return false;\n }\n throw new Error(\n 'Must specify a valid combination of id, origin, and type.',\n );\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 */\n acceptRequest(\n id: string,\n value?: unknown,\n options?: AcceptOptions,\n ): Promise<AcceptResult> {\n // Safe to cast as the delete method below will throw if the ID is not found\n const approval = this.get(id) as ApprovalRequest<ApprovalRequestData>;\n const requestPromise = this.#getCallbacks(id);\n let requestDeleted = false;\n\n if (!options?.deleteAfterResult || !options.waitForResult) {\n this.#delete(id);\n requestDeleted = true;\n }\n\n return new Promise<AcceptResult>((resolve, reject) => {\n const resultCallbacks: AcceptResultCallbacks = {\n success: (acceptValue?: unknown) => resolve({ value: acceptValue }),\n error: reject,\n };\n\n if (options?.waitForResult && !approval.expectsResult) {\n reject(new ApprovalRequestNoResultSupportError(id));\n return;\n }\n\n const resultValue = options?.waitForResult ? resultCallbacks : undefined;\n\n const resolveValue = approval.expectsResult\n ? { value, resultCallbacks: resultValue }\n : value;\n\n requestPromise.resolve(resolveValue);\n\n if (!options?.waitForResult) {\n resolve({ value: undefined });\n }\n }).finally(() => {\n if (!requestDeleted) {\n this.#delete(id);\n }\n });\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 */\n rejectRequest(id: string, error: unknown): void {\n const callbacks = this.#getCallbacks(id);\n this.#delete(id);\n callbacks.reject(error);\n }\n\n /**\n * Rejects and deletes all approval requests.\n *\n * @param rejectionError - The JsonRpcError to reject the approval\n * requests with.\n */\n clearRequests(rejectionError: JsonRpcError<DataWithOptionalCause>): void {\n for (const id of this.#approvals.keys()) {\n this.rejectRequest(id, rejectionError);\n }\n this.#origins.clear();\n this.update((draftState) => {\n draftState.pendingApprovals = {};\n draftState.pendingApprovalCount = 0;\n });\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 */\n updateRequestState(opts: UpdateRequestStateOptions): void {\n if (!this.state.pendingApprovals[opts.id]) {\n throw new ApprovalRequestNotFoundError(opts.id);\n }\n\n this.update((draftState) => {\n draftState.pendingApprovals[opts.id].requestState =\n opts.requestState as never;\n });\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 */\n startFlow(opts: StartFlowOptions = {}): ApprovalFlowStartResult {\n const id = opts.id ?? nanoid();\n const loadingText = opts.loadingText ?? null;\n\n this.update((draftState) => {\n draftState.approvalFlows.push({ id, loadingText });\n });\n\n // By default, if nothing else is specified, we always show the approval.\n if (opts.show !== false) {\n this.#showApprovalRequest();\n }\n\n return { id, loadingText };\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 */\n endFlow({ id }: EndFlowOptions) {\n if (!this.state.approvalFlows.length) {\n throw new NoApprovalFlowsError();\n }\n\n const currentFlow = this.state.approvalFlows.slice(-1)[0];\n\n if (id !== currentFlow.id) {\n throw new EndInvalidFlowError(\n id,\n this.state.approvalFlows.map((flow) => flow.id),\n );\n }\n\n this.update((draftState) => {\n draftState.approvalFlows.pop();\n });\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 */\n setFlowLoadingText({ id, loadingText }: SetFlowLoadingTextOptions) {\n const flowIndex = this.state.approvalFlows.findIndex(\n (flow) => flow.id === id,\n );\n\n if (flowIndex === -1) {\n throw new MissingApprovalFlowError(id);\n }\n\n this.update((draftState) => {\n draftState.approvalFlows[flowIndex].loadingText = loadingText;\n });\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 */\n async showSuccess(opts: SuccessOptions = {}): Promise<SuccessResult> {\n await this.#result(APPROVAL_TYPE_RESULT_SUCCESS, opts, {\n message: opts.message,\n header: opts.header,\n title: opts.title,\n icon: opts.icon,\n } as Record<string, Json>);\n\n return {};\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 */\n async showError(opts: ErrorOptions = {}): Promise<ErrorResult> {\n await this.#result(APPROVAL_TYPE_RESULT_ERROR, opts, {\n error: opts.error,\n header: opts.header,\n title: opts.title,\n icon: opts.icon,\n } as Record<string, Json>);\n\n return {};\n }\n\n /**\n * Implementation of add operation.\n *\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param id - The id of the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n * @param expectsResult - Whether the approval request expects a result object to be returned.\n * @returns The approval promise.\n */\n #add(\n origin: string,\n type: string,\n id: string = nanoid(),\n requestData?: Record<string, Json>,\n requestState?: Record<string, Json>,\n expectsResult?: boolean,\n ): Promise<unknown | AddResult> {\n this.#validateAddParams(id, origin, type, requestData, requestState);\n\n if (\n !this.#typesExcludedFromRateLimiting.includes(type) &&\n this.hasRequest({ origin, type })\n ) {\n throw rpcErrors.resourceUnavailable(\n getAlreadyPendingMessage(origin, type),\n );\n }\n\n // add pending approval\n return new Promise((resolve, reject) => {\n this.#approvals.set(id, { resolve, reject });\n this.#addPendingApprovalOrigin(origin, type);\n\n this.#addToStore(\n id,\n origin,\n type,\n requestData,\n requestState,\n expectsResult,\n );\n });\n }\n\n /**\n * Validates parameters to the add method.\n *\n * @param id - The id of the approval request.\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n */\n #validateAddParams(\n id: string,\n origin: string,\n type: string,\n requestData?: Record<string, Json>,\n requestState?: Record<string, Json>,\n ): void {\n let errorMessage = null;\n if (!id || typeof id !== 'string') {\n errorMessage = 'Must specify non-empty string id.';\n } else if (this.#approvals.has(id)) {\n errorMessage = `Approval request with id '${id}' already exists.`;\n } else if (!origin || typeof origin !== 'string') {\n errorMessage = 'Must specify non-empty string origin.';\n } else if (!type || typeof type !== 'string') {\n errorMessage = 'Must specify non-empty string type.';\n } else if (\n requestData &&\n (typeof requestData !== 'object' || Array.isArray(requestData))\n ) {\n errorMessage = 'Request data must be a plain object if specified.';\n } else if (\n requestState &&\n (typeof requestState !== 'object' || Array.isArray(requestState))\n ) {\n errorMessage = 'Request state must be a plain object if specified.';\n }\n\n if (errorMessage) {\n throw rpcErrors.internal(errorMessage);\n }\n }\n\n /**\n * Adds an entry to _origins.\n * Performs no validation.\n *\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n */\n #addPendingApprovalOrigin(origin: string, type: string): void {\n let originMap = this.#origins.get(origin);\n\n if (!originMap) {\n originMap = new Map();\n this.#origins.set(origin, originMap);\n }\n\n const currentValue = originMap.get(type) || 0;\n originMap.set(type, currentValue + 1);\n }\n\n /**\n * Adds an entry to the store.\n * Performs no validation.\n *\n * @param id - The id of the approval request.\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n * @param expectsResult - Whether the request expects a result object to be returned.\n */\n #addToStore(\n id: string,\n origin: string,\n type: string,\n requestData?: Record<string, Json>,\n requestState?: Record<string, Json>,\n expectsResult?: boolean,\n ): void {\n const approval = {\n id,\n origin,\n type,\n time: Date.now(),\n requestData: requestData || null,\n requestState: requestState || null,\n expectsResult: expectsResult || false,\n };\n\n this.update((draftState) => {\n draftState.pendingApprovals[id] = approval as never;\n\n draftState.pendingApprovalCount = Object.keys(\n draftState.pendingApprovals,\n ).length;\n });\n }\n\n /**\n * Deletes the approval with the given id.\n *\n * Deletion is an internal operation because approval state is solely\n * managed by this controller.\n *\n * @param id - The id of the approval request to be deleted.\n */\n #delete(id: string): void {\n if (!this.#approvals.has(id)) {\n throw new ApprovalRequestNotFoundError(id);\n }\n\n this.#approvals.delete(id);\n\n const { origin, type } = this.state.pendingApprovals[id];\n\n const originMap = this.#origins.get(origin) as Map<string, number>;\n const originTotalCount = this.getApprovalCount({ origin });\n const originTypeCount = originMap.get(type) as number;\n\n if (originTotalCount === 1) {\n this.#origins.delete(origin);\n } else {\n originMap.set(type, originTypeCount - 1);\n }\n\n this.update((draftState) => {\n delete draftState.pendingApprovals[id];\n draftState.pendingApprovalCount = Object.keys(\n draftState.pendingApprovals,\n ).length;\n });\n }\n\n #getCallbacks(id: string): ApprovalCallbacks {\n const callbacks = this.#approvals.get(id);\n\n if (!callbacks) {\n throw new ApprovalRequestNotFoundError(id);\n }\n\n return callbacks;\n }\n\n async #result(\n type: string,\n opts: ResultOptions,\n requestData: Record<string, Json>,\n ) {\n try {\n await this.addAndShowApprovalRequest({\n origin: ORIGIN_METAMASK,\n type,\n requestData,\n });\n } catch (error) {\n console.info('Failed to display result page', error);\n } finally {\n if (opts.flowToEnd) {\n try {\n this.endFlow({ id: opts.flowToEnd });\n } catch (error) {\n console.info('Failed to end flow', { id: opts.flowToEnd, error });\n }\n }\n }\n }\n}\n\nexport default ApprovalController;\n"]}

@@ -0,6 +1,8 @@

import { BaseController } from "@metamask/base-controller";
import type { ControllerGetStateAction } from "@metamask/base-controller";
import { BaseController, type ControllerStateChangeEvent } from "@metamask/base-controller";
import type { ControllerStateChangeEvent } from "@metamask/base-controller";
import type { Messenger } from "@metamask/messenger";
import type { JsonRpcError, DataWithOptionalCause } from "@metamask/rpc-errors";
import type { Json, OptionalField } from "@metamask/utils";
import type { ApprovalControllerMethodActions } from "./ApprovalController-method-action-types.cjs";
export declare const ORIGIN_METAMASK = "metamask";

@@ -159,48 +161,4 @@ export declare const APPROVAL_TYPE_RESULT_ERROR = "result_error";

export type ApprovalControllerEvents = ApprovalStateChange;
export type GetApprovalsState = ControllerGetStateAction<typeof controllerName, ApprovalControllerState>;
export type ClearApprovalRequests = {
type: `${typeof controllerName}:clearRequests`;
handler: (error: JsonRpcError<DataWithOptionalCause>) => void;
};
export type AddApprovalRequest = {
type: `${typeof controllerName}:addRequest`;
handler: (opts: AddApprovalOptions, shouldShowRequest: boolean) => ReturnType<ApprovalController['add']>;
};
export type HasApprovalRequest = {
type: `${typeof controllerName}:hasRequest`;
handler: ApprovalController['has'];
};
export type AcceptRequest = {
type: `${typeof controllerName}:acceptRequest`;
handler: ApprovalController['accept'];
};
export type RejectRequest = {
type: `${typeof controllerName}:rejectRequest`;
handler: ApprovalController['reject'];
};
export type UpdateRequestState = {
type: `${typeof controllerName}:updateRequestState`;
handler: ApprovalController['updateRequestState'];
};
export type StartFlow = {
type: `${typeof controllerName}:startFlow`;
handler: ApprovalController['startFlow'];
};
export type EndFlow = {
type: `${typeof controllerName}:endFlow`;
handler: ApprovalController['endFlow'];
};
export type SetFlowLoadingText = {
type: `${typeof controllerName}:setFlowLoadingText`;
handler: ApprovalController['setFlowLoadingText'];
};
export type ShowSuccess = {
type: `${typeof controllerName}:showSuccess`;
handler: ApprovalController['success'];
};
export type ShowError = {
type: `${typeof controllerName}:showError`;
handler: ApprovalController['error'];
};
export type ApprovalControllerActions = GetApprovalsState | ClearApprovalRequests | AddApprovalRequest | HasApprovalRequest | AcceptRequest | RejectRequest | UpdateRequestState | StartFlow | EndFlow | SetFlowLoadingText | ShowSuccess | ShowError;
export type ApprovalControllerGetStateAction = ControllerGetStateAction<typeof controllerName, ApprovalControllerState>;
export type ApprovalControllerActions = ApprovalControllerGetStateAction | ApprovalControllerMethodActions;
/**

@@ -229,6 +187,18 @@ * Controller for managing requests that require user approval.

/**
* Constructor helper for registering this controller's messaging system
* actions.
* Adds an approval request per the given arguments, optionally showing
* the approval request to the user.
*
* @param opts - Options bag.
* @param opts.id - The id of the approval request. A random id will be
* generated if none is provided.
* @param opts.origin - The origin of the approval request.
* @param opts.type - The type associated with the approval request.
* @param opts.requestData - Additional data associated with the request,
* if any.
* @param opts.requestState - Additional state associated with the request,
* if any.
* @param shouldShowRequest - Whether to show the approval request to the user.
* @returns The approval promise.
*/
private registerMessageHandlers;
addRequest(opts: AddApprovalOptions, shouldShowRequest: boolean): Promise<unknown>;
/**

@@ -357,3 +327,3 @@ * Adds an approval request per the given arguments, calls the show approval

*/
has(opts?: {
hasRequest(opts?: {
id?: string;

@@ -374,3 +344,3 @@ origin?: string;

*/
accept(id: string, value?: unknown, options?: AcceptOptions): Promise<AcceptResult>;
acceptRequest(id: string, value?: unknown, options?: AcceptOptions): Promise<AcceptResult>;
/**

@@ -383,3 +353,3 @@ * Rejects the promise of the approval with the given id, and deletes the

*/
reject(id: string, error: unknown): void;
rejectRequest(id: string, error: unknown): void;
/**

@@ -391,3 +361,3 @@ * Rejects and deletes all approval requests.

*/
clear(rejectionError: JsonRpcError<DataWithOptionalCause>): void;
clearRequests(rejectionError: JsonRpcError<DataWithOptionalCause>): void;
/**

@@ -437,3 +407,3 @@ * Updates the request state of the approval with the given id.

*/
success(opts?: SuccessOptions): Promise<SuccessResult>;
showSuccess(opts?: SuccessOptions): Promise<SuccessResult>;
/**

@@ -450,5 +420,5 @@ * Show an error page.

*/
error(opts?: ErrorOptions): Promise<ErrorResult>;
showError(opts?: ErrorOptions): Promise<ErrorResult>;
}
export default ApprovalController;
//# sourceMappingURL=ApprovalController.d.cts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"ApprovalController.d.cts","sourceRoot":"","sources":["../src/ApprovalController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EAEzB,kCAAkC;AACnC,OAAO,EACL,cAAc,EACd,KAAK,0BAA0B,EAChC,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,6BAA6B;AAEhF,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;AAc3D,eAAO,MAAM,eAAe,aAAa,CAAC;AAC1C,eAAO,MAAM,0BAA0B,iBAAiB,CAAC;AACzD,eAAO,MAAM,4BAA4B,mBAAmB,CAAC;AAE7D,QAAA,MAAM,cAAc,uBAAuB,CAAC;AAwC5C,KAAK,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;AAEvD,KAAK,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;AAOxD,KAAK,YAAY,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,CAAC,MAAM,GAAG,eAAe,CAAC,EAAE,CAAC;IACtC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,CAAC;AAIF,MAAM,MAAM,eAAe,CAAC,WAAW,SAAS,mBAAmB,IAAI;IACrE;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;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mB,GAAG,OAAO,CAAC,aAAa,CAAC;IAWpE;;;;;;;;;;OAUG;IACG,SAAS,CAAC,IAAI,GAAE,YAAiB,GAAG,OAAO,CAAC,WAAW,CAAC;CAgO/D;AAED,eAAe,kBAAkB,CAAC"}

@@ -0,6 +1,8 @@

import { BaseController } from "@metamask/base-controller";
import type { ControllerGetStateAction } from "@metamask/base-controller";
import { BaseController, type ControllerStateChangeEvent } from "@metamask/base-controller";
import type { ControllerStateChangeEvent } from "@metamask/base-controller";
import type { Messenger } from "@metamask/messenger";
import type { JsonRpcError, DataWithOptionalCause } from "@metamask/rpc-errors";
import type { Json, OptionalField } from "@metamask/utils";
import type { ApprovalControllerMethodActions } from "./ApprovalController-method-action-types.mjs";
export declare const ORIGIN_METAMASK = "metamask";

@@ -159,48 +161,4 @@ export declare const APPROVAL_TYPE_RESULT_ERROR = "result_error";

export type ApprovalControllerEvents = ApprovalStateChange;
export type GetApprovalsState = ControllerGetStateAction<typeof controllerName, ApprovalControllerState>;
export type ClearApprovalRequests = {
type: `${typeof controllerName}:clearRequests`;
handler: (error: JsonRpcError<DataWithOptionalCause>) => void;
};
export type AddApprovalRequest = {
type: `${typeof controllerName}:addRequest`;
handler: (opts: AddApprovalOptions, shouldShowRequest: boolean) => ReturnType<ApprovalController['add']>;
};
export type HasApprovalRequest = {
type: `${typeof controllerName}:hasRequest`;
handler: ApprovalController['has'];
};
export type AcceptRequest = {
type: `${typeof controllerName}:acceptRequest`;
handler: ApprovalController['accept'];
};
export type RejectRequest = {
type: `${typeof controllerName}:rejectRequest`;
handler: ApprovalController['reject'];
};
export type UpdateRequestState = {
type: `${typeof controllerName}:updateRequestState`;
handler: ApprovalController['updateRequestState'];
};
export type StartFlow = {
type: `${typeof controllerName}:startFlow`;
handler: ApprovalController['startFlow'];
};
export type EndFlow = {
type: `${typeof controllerName}:endFlow`;
handler: ApprovalController['endFlow'];
};
export type SetFlowLoadingText = {
type: `${typeof controllerName}:setFlowLoadingText`;
handler: ApprovalController['setFlowLoadingText'];
};
export type ShowSuccess = {
type: `${typeof controllerName}:showSuccess`;
handler: ApprovalController['success'];
};
export type ShowError = {
type: `${typeof controllerName}:showError`;
handler: ApprovalController['error'];
};
export type ApprovalControllerActions = GetApprovalsState | ClearApprovalRequests | AddApprovalRequest | HasApprovalRequest | AcceptRequest | RejectRequest | UpdateRequestState | StartFlow | EndFlow | SetFlowLoadingText | ShowSuccess | ShowError;
export type ApprovalControllerGetStateAction = ControllerGetStateAction<typeof controllerName, ApprovalControllerState>;
export type ApprovalControllerActions = ApprovalControllerGetStateAction | ApprovalControllerMethodActions;
/**

@@ -229,6 +187,18 @@ * Controller for managing requests that require user approval.

/**
* Constructor helper for registering this controller's messaging system
* actions.
* Adds an approval request per the given arguments, optionally showing
* the approval request to the user.
*
* @param opts - Options bag.
* @param opts.id - The id of the approval request. A random id will be
* generated if none is provided.
* @param opts.origin - The origin of the approval request.
* @param opts.type - The type associated with the approval request.
* @param opts.requestData - Additional data associated with the request,
* if any.
* @param opts.requestState - Additional state associated with the request,
* if any.
* @param shouldShowRequest - Whether to show the approval request to the user.
* @returns The approval promise.
*/
private registerMessageHandlers;
addRequest(opts: AddApprovalOptions, shouldShowRequest: boolean): Promise<unknown>;
/**

@@ -357,3 +327,3 @@ * Adds an approval request per the given arguments, calls the show approval

*/
has(opts?: {
hasRequest(opts?: {
id?: string;

@@ -374,3 +344,3 @@ origin?: string;

*/
accept(id: string, value?: unknown, options?: AcceptOptions): Promise<AcceptResult>;
acceptRequest(id: string, value?: unknown, options?: AcceptOptions): Promise<AcceptResult>;
/**

@@ -383,3 +353,3 @@ * Rejects the promise of the approval with the given id, and deletes the

*/
reject(id: string, error: unknown): void;
rejectRequest(id: string, error: unknown): void;
/**

@@ -391,3 +361,3 @@ * Rejects and deletes all approval requests.

*/
clear(rejectionError: JsonRpcError<DataWithOptionalCause>): void;
clearRequests(rejectionError: JsonRpcError<DataWithOptionalCause>): void;
/**

@@ -437,3 +407,3 @@ * Updates the request state of the approval with the given id.

*/
success(opts?: SuccessOptions): Promise<SuccessResult>;
showSuccess(opts?: SuccessOptions): Promise<SuccessResult>;
/**

@@ -450,5 +420,5 @@ * Show an error page.

*/
error(opts?: ErrorOptions): Promise<ErrorResult>;
showError(opts?: ErrorOptions): Promise<ErrorResult>;
}
export default ApprovalController;
//# sourceMappingURL=ApprovalController.d.mts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"ApprovalController.d.mts","sourceRoot":"","sources":["../src/ApprovalController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EAEzB,kCAAkC;AACnC,OAAO,EACL,cAAc,EACd,KAAK,0BAA0B,EAChC,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,6BAA6B;AAEhF,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;AAc3D,eAAO,MAAM,eAAe,aAAa,CAAC;AAC1C,eAAO,MAAM,0BAA0B,iBAAiB,CAAC;AACzD,eAAO,MAAM,4BAA4B,mBAAmB,CAAC;AAE7D,QAAA,MAAM,cAAc,uBAAuB,CAAC;AAwC5C,KAAK,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;AAEvD,KAAK,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;AAOxD,KAAK,YAAY,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,CAAC,MAAM,GAAG,eAAe,CAAC,EAAE,CAAC;IACtC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,GAAG,IA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AAE,EAAE,EAAE,EAAE,cAAc;IAmB9B;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,yBAAyB;IAcjE;;;;;;;;;;OAUG;IACG,WAAW,CAAC,IAAI,GAAE,cAAmB,GAAG,OAAO,CAAC,aAAa,CAAC;IAWpE;;;;;;;;;;OAUG;IACG,SAAS,CAAC,IAAI,GAAE,YAAiB,GAAG,OAAO,CAAC,WAAW,CAAC;CAgO/D;AAED,eAAe,kBAAkB,CAAC"}

@@ -51,2 +51,21 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {

};
// === MESSENGER ===
const MESSENGER_EXPOSED_METHODS = [
'acceptRequest',
'add',
'addAndShowApprovalRequest',
'addRequest',
'clearRequests',
'endFlow',
'get',
'getApprovalCount',
'getTotalApprovalCount',
'hasRequest',
'rejectRequest',
'setFlowLoadingText',
'showError',
'showSuccess',
'startFlow',
'updateRequestState',
];
/**

@@ -90,25 +109,25 @@ * Controller for managing requests that require user approval.

__classPrivateFieldSet(this, _ApprovalController_typesExcludedFromRateLimiting, typesExcludedFromRateLimiting, "f");
this.registerMessageHandlers();
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
}
/**
* Constructor helper for registering this controller's messaging system
* actions.
* Adds an approval request per the given arguments, optionally showing
* the approval request to the user.
*
* @param opts - Options bag.
* @param opts.id - The id of the approval request. A random id will be
* generated if none is provided.
* @param opts.origin - The origin of the approval request.
* @param opts.type - The type associated with the approval request.
* @param opts.requestData - Additional data associated with the request,
* if any.
* @param opts.requestState - Additional state associated with the request,
* if any.
* @param shouldShowRequest - Whether to show the approval request to the user.
* @returns The approval promise.
*/
registerMessageHandlers() {
this.messenger.registerActionHandler(`${controllerName}:clearRequests`, this.clear.bind(this));
this.messenger.registerActionHandler(`${controllerName}:addRequest`, (opts, shouldShowRequest) => {
if (shouldShowRequest) {
return this.addAndShowApprovalRequest(opts);
}
return this.add(opts);
});
this.messenger.registerActionHandler(`${controllerName}:hasRequest`, this.has.bind(this));
this.messenger.registerActionHandler(`${controllerName}:acceptRequest`, this.accept.bind(this));
this.messenger.registerActionHandler(`${controllerName}:rejectRequest`, this.reject.bind(this));
this.messenger.registerActionHandler(`${controllerName}:updateRequestState`, this.updateRequestState.bind(this));
this.messenger.registerActionHandler(`${controllerName}:startFlow`, this.startFlow.bind(this));
this.messenger.registerActionHandler(`${controllerName}:endFlow`, this.endFlow.bind(this));
this.messenger.registerActionHandler(`${controllerName}:setFlowLoadingText`, this.setFlowLoadingText.bind(this));
this.messenger.registerActionHandler(`${controllerName}:showSuccess`, this.success.bind(this));
this.messenger.registerActionHandler(`${controllerName}:showError`, this.error.bind(this));
addRequest(opts, shouldShowRequest) {
if (shouldShowRequest) {
return this.addAndShowApprovalRequest(opts);
}
return this.add(opts);
}

@@ -190,3 +209,3 @@ addAndShowApprovalRequest(opts) {

*/
has(opts = {}) {
hasRequest(opts = {}) {
const { id, origin, type: _type } = opts;

@@ -233,3 +252,3 @@ if (id) {

*/
accept(id, value, options) {
acceptRequest(id, value, options) {
// Safe to cast as the delete method below will throw if the ID is not found

@@ -273,3 +292,3 @@ const approval = this.get(id);

*/
reject(id, error) {
rejectRequest(id, error) {
const callbacks = __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_getCallbacks).call(this, id);

@@ -285,5 +304,5 @@ __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_delete).call(this, id);

*/
clear(rejectionError) {
clearRequests(rejectionError) {
for (const id of __classPrivateFieldGet(this, _ApprovalController_approvals, "f").keys()) {
this.reject(id, rejectionError);
this.rejectRequest(id, rejectionError);
}

@@ -378,3 +397,3 @@ __classPrivateFieldGet(this, _ApprovalController_origins, "f").clear();

*/
async success(opts = {}) {
async showSuccess(opts = {}) {
await __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_result).call(this, APPROVAL_TYPE_RESULT_SUCCESS, opts, {

@@ -399,3 +418,3 @@ message: opts.message,

*/
async error(opts = {}) {
async showError(opts = {}) {
await __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_result).call(this, APPROVAL_TYPE_RESULT_ERROR, opts, {

@@ -413,3 +432,3 @@ error: opts.error,

if (!__classPrivateFieldGet(this, _ApprovalController_typesExcludedFromRateLimiting, "f").includes(type) &&
this.has({ origin, type })) {
this.hasRequest({ origin, type })) {
throw rpcErrors.resourceUnavailable(getAlreadyPendingMessage(origin, type));

@@ -416,0 +435,0 @@ }

@@ -1,1 +0,1 @@

{"version":3,"file":"ApprovalController.mjs","sourceRoot":"","sources":["../src/ApprovalController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,OAAO,EACL,cAAc,EAEf,kCAAkC;AAGnC,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAEjD,OAAO,EAAE,MAAM,EAAE,eAAe;AAEhC,OAAO,EACL,4BAA4B,EAC5B,mCAAmC,EACnC,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACzB,qBAAiB;AAElB,YAAY;AAEZ,0CAA0C;AAC1C,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAC;AAC1C,MAAM,CAAC,MAAM,0BAA0B,GAAG,cAAc,CAAC;AACzD,MAAM,CAAC,MAAM,4BAA4B,GAAG,gBAAgB,CAAC;AAE7D,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAE5C,MAAM,aAAa,GAA2C;IAC5D,gBAAgB,EAAE;QAChB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;IACD,oBAAoB,EAAE;QACpB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;IACD,aAAa,EAAE;QACb,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,sBAAsB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AAe,kBAAkB,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n StateMetadata,\n} from '@metamask/base-controller';\nimport {\n BaseController,\n type ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { JsonRpcError, DataWithOptionalCause } from '@metamask/rpc-errors';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { Json, OptionalField } from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\nimport {\n ApprovalRequestNotFoundError,\n ApprovalRequestNoResultSupportError,\n EndInvalidFlowError,\n NoApprovalFlowsError,\n MissingApprovalFlowError,\n} from './errors';\n\n// Constants\n\n// Avoiding dependency on controller-utils\nexport const ORIGIN_METAMASK = 'metamask';\nexport const APPROVAL_TYPE_RESULT_ERROR = 'result_error';\nexport const APPROVAL_TYPE_RESULT_SUCCESS = 'result_success';\n\nconst controllerName = 'ApprovalController';\n\nconst stateMetadata: StateMetadata<ApprovalControllerState> = {\n pendingApprovals: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n pendingApprovalCount: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n approvalFlows: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\nconst getAlreadyPendingMessage = (origin: string, type: string) =>\n `Request of type '${type}' already pending for origin ${origin}. Please wait.`;\n\nconst getDefaultState = (): ApprovalControllerState => {\n return {\n pendingApprovals: {},\n pendingApprovalCount: 0,\n approvalFlows: [],\n };\n};\n\n// Internal Types\n\ntype ApprovalPromiseResolve = (value?: unknown | AddResult) => void;\n\ntype ApprovalPromiseReject = (error?: unknown) => void;\n\ntype ApprovalRequestData = Record<string, Json> | null;\n\ntype ApprovalRequestState = Record<string, Json> | null;\n\ntype ApprovalCallbacks = {\n resolve: ApprovalPromiseResolve;\n reject: ApprovalPromiseReject;\n};\n\ntype ApprovalFlow = {\n id: string;\n loadingText: string | null;\n};\n\ntype ResultOptions = {\n flowToEnd?: string;\n header?: (string | ResultComponent)[];\n icon?: string | null;\n title?: string | null;\n};\n\n// Miscellaneous Types\n\nexport type ApprovalRequest<RequestData extends ApprovalRequestData> = {\n /**\n * The ID of the approval request.\n */\n id: string;\n\n /**\n * The origin of the approval request.\n */\n origin: string;\n\n /**\n * The time that the request was received, per Date.now().\n */\n time: number;\n\n /**\n * The type of the approval request.\n * Unfortunately, not all values will match the `ApprovalType` enum, so we are using `string` here.\n * TODO: Replace `string` with `ApprovalType` when all `type` values used by the clients can be encompassed by the `ApprovalType` enum.\n */\n type: string;\n\n /**\n * Additional data associated with the request.\n */\n requestData: RequestData;\n\n /**\n * Additional mutable state associated with the request\n */\n requestState: ApprovalRequestState;\n\n /**\n * Whether the request expects a result object to be returned instead of just the approval value.\n */\n expectsResult: boolean;\n};\n\nexport type ApprovalFlowState = ApprovalFlow;\n\nexport type ApprovalControllerState = {\n pendingApprovals: Record<string, ApprovalRequest<Record<string, Json>>>;\n pendingApprovalCount: number;\n approvalFlows: ApprovalFlowState[];\n};\n\nexport type ApprovalControllerMessenger = Messenger<\n typeof controllerName,\n ApprovalControllerActions,\n ApprovalControllerEvents\n>;\n\n// Option Types\n\nexport type ShowApprovalRequest = () => void | Promise<void>;\n\nexport type ResultComponent = {\n /**\n * A unique identifier for this instance of the component.\n */\n key: string;\n\n /**\n * The name of the component to render.\n */\n name: string;\n\n /**\n * Any properties required by the component.\n */\n properties?: Record<string, unknown>;\n\n /**\n * Any child components to render inside the component.\n */\n children?: string | ResultComponent | (string | ResultComponent)[];\n};\n\nexport type ApprovalControllerOptions = {\n messenger: ApprovalControllerMessenger;\n showApprovalRequest: ShowApprovalRequest;\n state?: Partial<ApprovalControllerState>;\n typesExcludedFromRateLimiting?: string[];\n};\n\nexport type AddApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData?: Record<string, Json>;\n requestState?: Record<string, Json>;\n expectsResult?: boolean;\n};\n\nexport type UpdateRequestStateOptions = {\n id: string;\n requestState: Record<string, Json>;\n};\n\nexport type AcceptOptions = {\n /**\n * Whether to resolve the returned promise only when the request creator indicates the success of the\n * post-approval logic using the result callbacks.\n * If false or unspecified, the promise will resolve immediately.\n */\n waitForResult?: boolean;\n\n /**\n * Whether to delete the approval request after a result callback is called.\n * If false or unspecified, the approval request will be deleted immediately.\n * Ignored if `waitForResult` is false or unspecified.\n */\n deleteAfterResult?: boolean;\n};\n\nexport type StartFlowOptions = OptionalField<\n ApprovalFlow,\n 'id' | 'loadingText'\n> & { show?: boolean };\n\nexport type EndFlowOptions = Pick<ApprovalFlow, 'id'>;\n\nexport type SetFlowLoadingTextOptions = ApprovalFlow;\n\nexport type SuccessOptions = ResultOptions & {\n message?: string | ResultComponent | (string | ResultComponent)[];\n};\n\nexport type ErrorOptions = ResultOptions & {\n error?: string | ResultComponent | (string | ResultComponent)[];\n};\n\n// Result Types\n\nexport type AcceptResultCallbacks = {\n /**\n * Inform the request acceptor that the post-approval logic was successful.\n *\n * @param value - An optional value generated by the post-approval logic.\n */\n success: (value?: unknown) => void;\n\n /**\n * Inform the request acceptor that the post-approval logic failed.\n *\n * @param error - The reason for the failure.\n */\n error: (error: Error) => void;\n};\n\nexport type AddResult = {\n /**\n * An optional value provided by the request acceptor.\n */\n value?: unknown;\n\n /**\n * Callback functions that must be used to indicate to the request acceptor whether the post-approval logic was successful or not.\n * Will be undefined if the request acceptor did not specify that they want to wait for a result.\n */\n resultCallbacks?: AcceptResultCallbacks;\n};\n\nexport type AcceptResult = {\n /**\n * An optional value provided by the request creator when indicating a successful result.\n */\n value?: unknown;\n};\n\nexport type ApprovalFlowStartResult = ApprovalFlow;\n\nexport type SuccessResult = Record<string, never>;\n\nexport type ErrorResult = Record<string, never>;\n\n// Event Types\n\nexport type ApprovalStateChange = ControllerStateChangeEvent<\n typeof controllerName,\n ApprovalControllerState\n>;\n\nexport type ApprovalControllerEvents = ApprovalStateChange;\n\n// Action Types\n\nexport type GetApprovalsState = ControllerGetStateAction<\n typeof controllerName,\n ApprovalControllerState\n>;\n\nexport type ClearApprovalRequests = {\n type: `${typeof controllerName}:clearRequests`;\n handler: (error: JsonRpcError<DataWithOptionalCause>) => void;\n};\n\nexport type AddApprovalRequest = {\n type: `${typeof controllerName}:addRequest`;\n handler: (\n opts: AddApprovalOptions,\n shouldShowRequest: boolean,\n ) => ReturnType<ApprovalController['add']>;\n};\n\nexport type HasApprovalRequest = {\n type: `${typeof controllerName}:hasRequest`;\n handler: ApprovalController['has'];\n};\n\nexport type AcceptRequest = {\n type: `${typeof controllerName}:acceptRequest`;\n handler: ApprovalController['accept'];\n};\n\nexport type RejectRequest = {\n type: `${typeof controllerName}:rejectRequest`;\n handler: ApprovalController['reject'];\n};\n\nexport type UpdateRequestState = {\n type: `${typeof controllerName}:updateRequestState`;\n handler: ApprovalController['updateRequestState'];\n};\n\nexport type StartFlow = {\n type: `${typeof controllerName}:startFlow`;\n handler: ApprovalController['startFlow'];\n};\n\nexport type EndFlow = {\n type: `${typeof controllerName}:endFlow`;\n handler: ApprovalController['endFlow'];\n};\n\nexport type SetFlowLoadingText = {\n type: `${typeof controllerName}:setFlowLoadingText`;\n handler: ApprovalController['setFlowLoadingText'];\n};\n\nexport type ShowSuccess = {\n type: `${typeof controllerName}:showSuccess`;\n handler: ApprovalController['success'];\n};\n\nexport type ShowError = {\n type: `${typeof controllerName}:showError`;\n handler: ApprovalController['error'];\n};\n\nexport type ApprovalControllerActions =\n | GetApprovalsState\n | ClearApprovalRequests\n | AddApprovalRequest\n | HasApprovalRequest\n | AcceptRequest\n | RejectRequest\n | UpdateRequestState\n | StartFlow\n | EndFlow\n | SetFlowLoadingText\n | ShowSuccess\n | ShowError;\n\n/**\n * Controller for managing requests that require user approval.\n *\n * Enables limiting the number of pending requests by origin and type, counting\n * pending requests, and more.\n *\n * Adding a request returns a promise that resolves or rejects when the request\n * is approved or denied, respectively.\n */\nexport class ApprovalController extends BaseController<\n typeof controllerName,\n ApprovalControllerState,\n ApprovalControllerMessenger\n> {\n #approvals: Map<string, ApprovalCallbacks>;\n\n #origins: Map<string, Map<string, number>>;\n\n #showApprovalRequest: () => void;\n\n #typesExcludedFromRateLimiting: string[];\n\n /**\n * Construct an Approval controller.\n *\n * @param options - The controller options.\n * @param options.showApprovalRequest - Function for opening the UI such that\n * the request can be displayed to the user.\n * @param options.messenger - The restricted messenger for the Approval controller.\n * @param options.state - The initial controller state.\n * @param options.typesExcludedFromRateLimiting - Array of approval types which allow multiple pending approval requests from the same origin.\n */\n constructor({\n messenger,\n showApprovalRequest,\n state = {},\n typesExcludedFromRateLimiting = [],\n }: ApprovalControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.#approvals = new Map();\n this.#origins = new Map();\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#showApprovalRequest = showApprovalRequest;\n this.#typesExcludedFromRateLimiting = typesExcludedFromRateLimiting;\n this.registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n private registerMessageHandlers(): void {\n this.messenger.registerActionHandler(\n `${controllerName}:clearRequests` as const,\n this.clear.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:addRequest` as const,\n (opts: AddApprovalOptions, shouldShowRequest: boolean) => {\n if (shouldShowRequest) {\n return this.addAndShowApprovalRequest(opts);\n }\n return this.add(opts);\n },\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:hasRequest` as const,\n this.has.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:acceptRequest` as const,\n this.accept.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:rejectRequest` as const,\n this.reject.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:updateRequestState` as const,\n this.updateRequestState.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:startFlow` as const,\n this.startFlow.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:endFlow` as const,\n this.endFlow.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:setFlowLoadingText` as const,\n this.setFlowLoadingText.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:showSuccess` as const,\n this.success.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:showError` as const,\n this.error.bind(this),\n );\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 */\n addAndShowApprovalRequest(\n opts: AddApprovalOptions & { expectsResult: true },\n ): Promise<AddResult>;\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\n * to a value provided during acceptance.\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 a value provided during acceptance.\n */\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise<unknown>;\n\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise<unknown> {\n const promise = this.#add(\n opts.origin,\n opts.type,\n opts.id,\n opts.requestData,\n opts.requestState,\n opts.expectsResult,\n );\n this.#showApprovalRequest();\n return promise;\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 */\n add(opts: AddApprovalOptions & { expectsResult: true }): Promise<AddResult>;\n\n /**\n * Adds an approval request per the given arguments and returns the approval\n * promise resolving to a value provided during acceptance.\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 a value provided during acceptance.\n */\n add(opts: AddApprovalOptions): Promise<unknown>;\n\n add(opts: AddApprovalOptions): Promise<unknown | AddResult> {\n return this.#add(\n opts.origin,\n opts.type,\n opts.id,\n opts.requestData,\n opts.requestState,\n opts.expectsResult,\n );\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 */\n get(id: string): ApprovalRequest<ApprovalRequestData> | undefined {\n return this.state.pendingApprovals[id];\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 */\n getApprovalCount(opts: { origin?: string; type?: string } = {}): number {\n if (!opts.origin && !opts.type) {\n throw new Error('Must specify origin, type, or both.');\n }\n const { origin, type: _type } = opts;\n\n if (origin && _type) {\n return this.#origins.get(origin)?.get(_type) || 0;\n }\n\n if (origin) {\n return Array.from(\n (this.#origins.get(origin) || new Map()).values(),\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n ).reduce((total, value) => total + value, 0);\n }\n\n // Only \"type\" was specified\n let count = 0;\n for (const approval of Object.values(this.state.pendingApprovals)) {\n if (approval.type === _type) {\n count += 1;\n }\n }\n return count;\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 */\n getTotalApprovalCount(): number {\n return this.state.pendingApprovalCount;\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 */\n has(opts: { id?: string; origin?: string; type?: string } = {}): boolean {\n const { id, origin, type: _type } = opts;\n\n if (id) {\n if (typeof id !== 'string') {\n throw new Error('May not specify non-string id.');\n }\n return this.#approvals.has(id);\n }\n\n if (_type && typeof _type !== 'string') {\n throw new Error('May not specify non-string type.');\n }\n\n if (origin) {\n if (typeof origin !== 'string') {\n throw new Error('May not specify non-string origin.');\n }\n\n // Check origin and type pair if type also specified\n if (_type) {\n return Boolean(this.#origins.get(origin)?.get(_type));\n }\n return this.#origins.has(origin);\n }\n\n if (_type) {\n for (const approval of Object.values(this.state.pendingApprovals)) {\n if (approval.type === _type) {\n return true;\n }\n }\n return false;\n }\n throw new Error(\n 'Must specify a valid combination of id, origin, and type.',\n );\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 */\n accept(\n id: string,\n value?: unknown,\n options?: AcceptOptions,\n ): Promise<AcceptResult> {\n // Safe to cast as the delete method below will throw if the ID is not found\n const approval = this.get(id) as ApprovalRequest<ApprovalRequestData>;\n const requestPromise = this.#getCallbacks(id);\n let requestDeleted = false;\n\n if (!options?.deleteAfterResult || !options.waitForResult) {\n this.#delete(id);\n requestDeleted = true;\n }\n\n return new Promise<AcceptResult>((resolve, reject) => {\n const resultCallbacks: AcceptResultCallbacks = {\n success: (acceptValue?: unknown) => resolve({ value: acceptValue }),\n error: reject,\n };\n\n if (options?.waitForResult && !approval.expectsResult) {\n reject(new ApprovalRequestNoResultSupportError(id));\n return;\n }\n\n const resultValue = options?.waitForResult ? resultCallbacks : undefined;\n\n const resolveValue = approval.expectsResult\n ? { value, resultCallbacks: resultValue }\n : value;\n\n requestPromise.resolve(resolveValue);\n\n if (!options?.waitForResult) {\n resolve({ value: undefined });\n }\n }).finally(() => {\n if (!requestDeleted) {\n this.#delete(id);\n }\n });\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 */\n reject(id: string, error: unknown): void {\n const callbacks = this.#getCallbacks(id);\n this.#delete(id);\n callbacks.reject(error);\n }\n\n /**\n * Rejects and deletes all approval requests.\n *\n * @param rejectionError - The JsonRpcError to reject the approval\n * requests with.\n */\n clear(rejectionError: JsonRpcError<DataWithOptionalCause>): void {\n for (const id of this.#approvals.keys()) {\n this.reject(id, rejectionError);\n }\n this.#origins.clear();\n this.update((draftState) => {\n draftState.pendingApprovals = {};\n draftState.pendingApprovalCount = 0;\n });\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 */\n updateRequestState(opts: UpdateRequestStateOptions): void {\n if (!this.state.pendingApprovals[opts.id]) {\n throw new ApprovalRequestNotFoundError(opts.id);\n }\n\n this.update((draftState) => {\n draftState.pendingApprovals[opts.id].requestState =\n opts.requestState as never;\n });\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 */\n startFlow(opts: StartFlowOptions = {}): ApprovalFlowStartResult {\n const id = opts.id ?? nanoid();\n const loadingText = opts.loadingText ?? null;\n\n this.update((draftState) => {\n draftState.approvalFlows.push({ id, loadingText });\n });\n\n // By default, if nothing else is specified, we always show the approval.\n if (opts.show !== false) {\n this.#showApprovalRequest();\n }\n\n return { id, loadingText };\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 */\n endFlow({ id }: EndFlowOptions) {\n if (!this.state.approvalFlows.length) {\n throw new NoApprovalFlowsError();\n }\n\n const currentFlow = this.state.approvalFlows.slice(-1)[0];\n\n if (id !== currentFlow.id) {\n throw new EndInvalidFlowError(\n id,\n this.state.approvalFlows.map((flow) => flow.id),\n );\n }\n\n this.update((draftState) => {\n draftState.approvalFlows.pop();\n });\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 */\n setFlowLoadingText({ id, loadingText }: SetFlowLoadingTextOptions) {\n const flowIndex = this.state.approvalFlows.findIndex(\n (flow) => flow.id === id,\n );\n\n if (flowIndex === -1) {\n throw new MissingApprovalFlowError(id);\n }\n\n this.update((draftState) => {\n draftState.approvalFlows[flowIndex].loadingText = loadingText;\n });\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 */\n async success(opts: SuccessOptions = {}): Promise<SuccessResult> {\n await this.#result(APPROVAL_TYPE_RESULT_SUCCESS, opts, {\n message: opts.message,\n header: opts.header,\n title: opts.title,\n icon: opts.icon,\n } as Record<string, Json>);\n\n return {};\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 */\n async error(opts: ErrorOptions = {}): Promise<ErrorResult> {\n await this.#result(APPROVAL_TYPE_RESULT_ERROR, opts, {\n error: opts.error,\n header: opts.header,\n title: opts.title,\n icon: opts.icon,\n } as Record<string, Json>);\n\n return {};\n }\n\n /**\n * Implementation of add operation.\n *\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param id - The id of the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n * @param expectsResult - Whether the approval request expects a result object to be returned.\n * @returns The approval promise.\n */\n #add(\n origin: string,\n type: string,\n id: string = nanoid(),\n requestData?: Record<string, Json>,\n requestState?: Record<string, Json>,\n expectsResult?: boolean,\n ): Promise<unknown | AddResult> {\n this.#validateAddParams(id, origin, type, requestData, requestState);\n\n if (\n !this.#typesExcludedFromRateLimiting.includes(type) &&\n this.has({ origin, type })\n ) {\n throw rpcErrors.resourceUnavailable(\n getAlreadyPendingMessage(origin, type),\n );\n }\n\n // add pending approval\n return new Promise((resolve, reject) => {\n this.#approvals.set(id, { resolve, reject });\n this.#addPendingApprovalOrigin(origin, type);\n\n this.#addToStore(\n id,\n origin,\n type,\n requestData,\n requestState,\n expectsResult,\n );\n });\n }\n\n /**\n * Validates parameters to the add method.\n *\n * @param id - The id of the approval request.\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n */\n #validateAddParams(\n id: string,\n origin: string,\n type: string,\n requestData?: Record<string, Json>,\n requestState?: Record<string, Json>,\n ): void {\n let errorMessage = null;\n if (!id || typeof id !== 'string') {\n errorMessage = 'Must specify non-empty string id.';\n } else if (this.#approvals.has(id)) {\n errorMessage = `Approval request with id '${id}' already exists.`;\n } else if (!origin || typeof origin !== 'string') {\n errorMessage = 'Must specify non-empty string origin.';\n } else if (!type || typeof type !== 'string') {\n errorMessage = 'Must specify non-empty string type.';\n } else if (\n requestData &&\n (typeof requestData !== 'object' || Array.isArray(requestData))\n ) {\n errorMessage = 'Request data must be a plain object if specified.';\n } else if (\n requestState &&\n (typeof requestState !== 'object' || Array.isArray(requestState))\n ) {\n errorMessage = 'Request state must be a plain object if specified.';\n }\n\n if (errorMessage) {\n throw rpcErrors.internal(errorMessage);\n }\n }\n\n /**\n * Adds an entry to _origins.\n * Performs no validation.\n *\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n */\n #addPendingApprovalOrigin(origin: string, type: string): void {\n let originMap = this.#origins.get(origin);\n\n if (!originMap) {\n originMap = new Map();\n this.#origins.set(origin, originMap);\n }\n\n const currentValue = originMap.get(type) || 0;\n originMap.set(type, currentValue + 1);\n }\n\n /**\n * Adds an entry to the store.\n * Performs no validation.\n *\n * @param id - The id of the approval request.\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n * @param expectsResult - Whether the request expects a result object to be returned.\n */\n #addToStore(\n id: string,\n origin: string,\n type: string,\n requestData?: Record<string, Json>,\n requestState?: Record<string, Json>,\n expectsResult?: boolean,\n ): void {\n const approval = {\n id,\n origin,\n type,\n time: Date.now(),\n requestData: requestData || null,\n requestState: requestState || null,\n expectsResult: expectsResult || false,\n };\n\n this.update((draftState) => {\n draftState.pendingApprovals[id] = approval as never;\n\n draftState.pendingApprovalCount = Object.keys(\n draftState.pendingApprovals,\n ).length;\n });\n }\n\n /**\n * Deletes the approval with the given id.\n *\n * Deletion is an internal operation because approval state is solely\n * managed by this controller.\n *\n * @param id - The id of the approval request to be deleted.\n */\n #delete(id: string): void {\n if (!this.#approvals.has(id)) {\n throw new ApprovalRequestNotFoundError(id);\n }\n\n this.#approvals.delete(id);\n\n const { origin, type } = this.state.pendingApprovals[id];\n\n const originMap = this.#origins.get(origin) as Map<string, number>;\n const originTotalCount = this.getApprovalCount({ origin });\n const originTypeCount = originMap.get(type) as number;\n\n if (originTotalCount === 1) {\n this.#origins.delete(origin);\n } else {\n originMap.set(type, originTypeCount - 1);\n }\n\n this.update((draftState) => {\n delete draftState.pendingApprovals[id];\n draftState.pendingApprovalCount = Object.keys(\n draftState.pendingApprovals,\n ).length;\n });\n }\n\n #getCallbacks(id: string): ApprovalCallbacks {\n const callbacks = this.#approvals.get(id);\n\n if (!callbacks) {\n throw new ApprovalRequestNotFoundError(id);\n }\n\n return callbacks;\n }\n\n async #result(\n type: string,\n opts: ResultOptions,\n requestData: Record<string, Json>,\n ) {\n try {\n await this.addAndShowApprovalRequest({\n origin: ORIGIN_METAMASK,\n type,\n requestData,\n });\n } catch (error) {\n console.info('Failed to display result page', error);\n } finally {\n if (opts.flowToEnd) {\n try {\n this.endFlow({ id: opts.flowToEnd });\n } catch (error) {\n console.info('Failed to end flow', { id: opts.flowToEnd, error });\n }\n }\n }\n }\n}\n\nexport default ApprovalController;\n"]}
{"version":3,"file":"ApprovalController.mjs","sourceRoot":"","sources":["../src/ApprovalController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAQ3D,OAAO,EAAE,SAAS,EAAE,6BAA6B;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AE,EAAE,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;YACpE,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAGH,eAAe,kBAAkB,CAAC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n StateMetadata,\n} from '@metamask/base-controller';\nimport type { ControllerStateChangeEvent } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { JsonRpcError, DataWithOptionalCause } from '@metamask/rpc-errors';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { Json, OptionalField } from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\nimport type { ApprovalControllerMethodActions } from './ApprovalController-method-action-types';\nimport {\n ApprovalRequestNotFoundError,\n ApprovalRequestNoResultSupportError,\n EndInvalidFlowError,\n NoApprovalFlowsError,\n MissingApprovalFlowError,\n} from './errors';\n\n// Constants\n\n// Avoiding dependency on controller-utils\nexport const ORIGIN_METAMASK = 'metamask';\nexport const APPROVAL_TYPE_RESULT_ERROR = 'result_error';\nexport const APPROVAL_TYPE_RESULT_SUCCESS = 'result_success';\n\nconst controllerName = 'ApprovalController';\n\nconst stateMetadata: StateMetadata<ApprovalControllerState> = {\n pendingApprovals: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n pendingApprovalCount: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n approvalFlows: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\nconst getAlreadyPendingMessage = (origin: string, type: string) =>\n `Request of type '${type}' already pending for origin ${origin}. Please wait.`;\n\nconst getDefaultState = (): ApprovalControllerState => {\n return {\n pendingApprovals: {},\n pendingApprovalCount: 0,\n approvalFlows: [],\n };\n};\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'acceptRequest',\n 'add',\n 'addAndShowApprovalRequest',\n 'addRequest',\n 'clearRequests',\n 'endFlow',\n 'get',\n 'getApprovalCount',\n 'getTotalApprovalCount',\n 'hasRequest',\n 'rejectRequest',\n 'setFlowLoadingText',\n 'showError',\n 'showSuccess',\n 'startFlow',\n 'updateRequestState',\n] as const;\n\n// Internal Types\n\ntype ApprovalPromiseResolve = (value?: unknown | AddResult) => void;\n\ntype ApprovalPromiseReject = (error?: unknown) => void;\n\ntype ApprovalRequestData = Record<string, Json> | null;\n\ntype ApprovalRequestState = Record<string, Json> | null;\n\ntype ApprovalCallbacks = {\n resolve: ApprovalPromiseResolve;\n reject: ApprovalPromiseReject;\n};\n\ntype ApprovalFlow = {\n id: string;\n loadingText: string | null;\n};\n\ntype ResultOptions = {\n flowToEnd?: string;\n header?: (string | ResultComponent)[];\n icon?: string | null;\n title?: string | null;\n};\n\n// Miscellaneous Types\n\nexport type ApprovalRequest<RequestData extends ApprovalRequestData> = {\n /**\n * The ID of the approval request.\n */\n id: string;\n\n /**\n * The origin of the approval request.\n */\n origin: string;\n\n /**\n * The time that the request was received, per Date.now().\n */\n time: number;\n\n /**\n * The type of the approval request.\n * Unfortunately, not all values will match the `ApprovalType` enum, so we are using `string` here.\n * TODO: Replace `string` with `ApprovalType` when all `type` values used by the clients can be encompassed by the `ApprovalType` enum.\n */\n type: string;\n\n /**\n * Additional data associated with the request.\n */\n requestData: RequestData;\n\n /**\n * Additional mutable state associated with the request\n */\n requestState: ApprovalRequestState;\n\n /**\n * Whether the request expects a result object to be returned instead of just the approval value.\n */\n expectsResult: boolean;\n};\n\nexport type ApprovalFlowState = ApprovalFlow;\n\nexport type ApprovalControllerState = {\n pendingApprovals: Record<string, ApprovalRequest<Record<string, Json>>>;\n pendingApprovalCount: number;\n approvalFlows: ApprovalFlowState[];\n};\n\nexport type ApprovalControllerMessenger = Messenger<\n typeof controllerName,\n ApprovalControllerActions,\n ApprovalControllerEvents\n>;\n\n// Option Types\n\nexport type ShowApprovalRequest = () => void | Promise<void>;\n\nexport type ResultComponent = {\n /**\n * A unique identifier for this instance of the component.\n */\n key: string;\n\n /**\n * The name of the component to render.\n */\n name: string;\n\n /**\n * Any properties required by the component.\n */\n properties?: Record<string, unknown>;\n\n /**\n * Any child components to render inside the component.\n */\n children?: string | ResultComponent | (string | ResultComponent)[];\n};\n\nexport type ApprovalControllerOptions = {\n messenger: ApprovalControllerMessenger;\n showApprovalRequest: ShowApprovalRequest;\n state?: Partial<ApprovalControllerState>;\n typesExcludedFromRateLimiting?: string[];\n};\n\nexport type AddApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData?: Record<string, Json>;\n requestState?: Record<string, Json>;\n expectsResult?: boolean;\n};\n\nexport type UpdateRequestStateOptions = {\n id: string;\n requestState: Record<string, Json>;\n};\n\nexport type AcceptOptions = {\n /**\n * Whether to resolve the returned promise only when the request creator indicates the success of the\n * post-approval logic using the result callbacks.\n * If false or unspecified, the promise will resolve immediately.\n */\n waitForResult?: boolean;\n\n /**\n * Whether to delete the approval request after a result callback is called.\n * If false or unspecified, the approval request will be deleted immediately.\n * Ignored if `waitForResult` is false or unspecified.\n */\n deleteAfterResult?: boolean;\n};\n\nexport type StartFlowOptions = OptionalField<\n ApprovalFlow,\n 'id' | 'loadingText'\n> & { show?: boolean };\n\nexport type EndFlowOptions = Pick<ApprovalFlow, 'id'>;\n\nexport type SetFlowLoadingTextOptions = ApprovalFlow;\n\nexport type SuccessOptions = ResultOptions & {\n message?: string | ResultComponent | (string | ResultComponent)[];\n};\n\nexport type ErrorOptions = ResultOptions & {\n error?: string | ResultComponent | (string | ResultComponent)[];\n};\n\n// Result Types\n\nexport type AcceptResultCallbacks = {\n /**\n * Inform the request acceptor that the post-approval logic was successful.\n *\n * @param value - An optional value generated by the post-approval logic.\n */\n success: (value?: unknown) => void;\n\n /**\n * Inform the request acceptor that the post-approval logic failed.\n *\n * @param error - The reason for the failure.\n */\n error: (error: Error) => void;\n};\n\nexport type AddResult = {\n /**\n * An optional value provided by the request acceptor.\n */\n value?: unknown;\n\n /**\n * Callback functions that must be used to indicate to the request acceptor whether the post-approval logic was successful or not.\n * Will be undefined if the request acceptor did not specify that they want to wait for a result.\n */\n resultCallbacks?: AcceptResultCallbacks;\n};\n\nexport type AcceptResult = {\n /**\n * An optional value provided by the request creator when indicating a successful result.\n */\n value?: unknown;\n};\n\nexport type ApprovalFlowStartResult = ApprovalFlow;\n\nexport type SuccessResult = Record<string, never>;\n\nexport type ErrorResult = Record<string, never>;\n\n// Event Types\n\nexport type ApprovalStateChange = ControllerStateChangeEvent<\n typeof controllerName,\n ApprovalControllerState\n>;\n\nexport type ApprovalControllerEvents = ApprovalStateChange;\n\n// Action Types\n\nexport type ApprovalControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n ApprovalControllerState\n>;\n\nexport type ApprovalControllerActions =\n | ApprovalControllerGetStateAction\n | ApprovalControllerMethodActions;\n\n/**\n * Controller for managing requests that require user approval.\n *\n * Enables limiting the number of pending requests by origin and type, counting\n * pending requests, and more.\n *\n * Adding a request returns a promise that resolves or rejects when the request\n * is approved or denied, respectively.\n */\nexport class ApprovalController extends BaseController<\n typeof controllerName,\n ApprovalControllerState,\n ApprovalControllerMessenger\n> {\n readonly #approvals: Map<string, ApprovalCallbacks>;\n\n readonly #origins: Map<string, Map<string, number>>;\n\n readonly #showApprovalRequest: () => void;\n\n readonly #typesExcludedFromRateLimiting: string[];\n\n /**\n * Construct an Approval controller.\n *\n * @param options - The controller options.\n * @param options.showApprovalRequest - Function for opening the UI such that\n * the request can be displayed to the user.\n * @param options.messenger - The restricted messenger for the Approval controller.\n * @param options.state - The initial controller state.\n * @param options.typesExcludedFromRateLimiting - Array of approval types which allow multiple pending approval requests from the same origin.\n */\n constructor({\n messenger,\n showApprovalRequest,\n state = {},\n typesExcludedFromRateLimiting = [],\n }: ApprovalControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.#approvals = new Map();\n this.#origins = new Map();\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#showApprovalRequest = showApprovalRequest;\n this.#typesExcludedFromRateLimiting = typesExcludedFromRateLimiting;\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\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 */\n addRequest(\n opts: AddApprovalOptions,\n shouldShowRequest: boolean,\n ): Promise<unknown> {\n if (shouldShowRequest) {\n return this.addAndShowApprovalRequest(opts);\n }\n return this.add(opts);\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 */\n addAndShowApprovalRequest(\n opts: AddApprovalOptions & { expectsResult: true },\n ): Promise<AddResult>;\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\n * to a value provided during acceptance.\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 a value provided during acceptance.\n */\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise<unknown>;\n\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise<unknown> {\n const promise = this.#add(\n opts.origin,\n opts.type,\n opts.id,\n opts.requestData,\n opts.requestState,\n opts.expectsResult,\n );\n this.#showApprovalRequest();\n return promise;\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 */\n add(opts: AddApprovalOptions & { expectsResult: true }): Promise<AddResult>;\n\n /**\n * Adds an approval request per the given arguments and returns the approval\n * promise resolving to a value provided during acceptance.\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 a value provided during acceptance.\n */\n add(opts: AddApprovalOptions): Promise<unknown>;\n\n add(opts: AddApprovalOptions): Promise<unknown | AddResult> {\n return this.#add(\n opts.origin,\n opts.type,\n opts.id,\n opts.requestData,\n opts.requestState,\n opts.expectsResult,\n );\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 */\n get(id: string): ApprovalRequest<ApprovalRequestData> | undefined {\n return this.state.pendingApprovals[id];\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 */\n getApprovalCount(opts: { origin?: string; type?: string } = {}): number {\n if (!opts.origin && !opts.type) {\n throw new Error('Must specify origin, type, or both.');\n }\n const { origin, type: _type } = opts;\n\n if (origin && _type) {\n return this.#origins.get(origin)?.get(_type) || 0;\n }\n\n if (origin) {\n return Array.from(\n (this.#origins.get(origin) || new Map()).values(),\n ).reduce((total, value) => total + value, 0);\n }\n\n // Only \"type\" was specified\n let count = 0;\n for (const approval of Object.values(this.state.pendingApprovals)) {\n if (approval.type === _type) {\n count += 1;\n }\n }\n return count;\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 */\n getTotalApprovalCount(): number {\n return this.state.pendingApprovalCount;\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 */\n hasRequest(\n opts: { id?: string; origin?: string; type?: string } = {},\n ): boolean {\n const { id, origin, type: _type } = opts;\n\n if (id) {\n if (typeof id !== 'string') {\n throw new Error('May not specify non-string id.');\n }\n return this.#approvals.has(id);\n }\n\n if (_type && typeof _type !== 'string') {\n throw new Error('May not specify non-string type.');\n }\n\n if (origin) {\n if (typeof origin !== 'string') {\n throw new Error('May not specify non-string origin.');\n }\n\n // Check origin and type pair if type also specified\n if (_type) {\n return Boolean(this.#origins.get(origin)?.get(_type));\n }\n return this.#origins.has(origin);\n }\n\n if (_type) {\n for (const approval of Object.values(this.state.pendingApprovals)) {\n if (approval.type === _type) {\n return true;\n }\n }\n return false;\n }\n throw new Error(\n 'Must specify a valid combination of id, origin, and type.',\n );\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 */\n acceptRequest(\n id: string,\n value?: unknown,\n options?: AcceptOptions,\n ): Promise<AcceptResult> {\n // Safe to cast as the delete method below will throw if the ID is not found\n const approval = this.get(id) as ApprovalRequest<ApprovalRequestData>;\n const requestPromise = this.#getCallbacks(id);\n let requestDeleted = false;\n\n if (!options?.deleteAfterResult || !options.waitForResult) {\n this.#delete(id);\n requestDeleted = true;\n }\n\n return new Promise<AcceptResult>((resolve, reject) => {\n const resultCallbacks: AcceptResultCallbacks = {\n success: (acceptValue?: unknown) => resolve({ value: acceptValue }),\n error: reject,\n };\n\n if (options?.waitForResult && !approval.expectsResult) {\n reject(new ApprovalRequestNoResultSupportError(id));\n return;\n }\n\n const resultValue = options?.waitForResult ? resultCallbacks : undefined;\n\n const resolveValue = approval.expectsResult\n ? { value, resultCallbacks: resultValue }\n : value;\n\n requestPromise.resolve(resolveValue);\n\n if (!options?.waitForResult) {\n resolve({ value: undefined });\n }\n }).finally(() => {\n if (!requestDeleted) {\n this.#delete(id);\n }\n });\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 */\n rejectRequest(id: string, error: unknown): void {\n const callbacks = this.#getCallbacks(id);\n this.#delete(id);\n callbacks.reject(error);\n }\n\n /**\n * Rejects and deletes all approval requests.\n *\n * @param rejectionError - The JsonRpcError to reject the approval\n * requests with.\n */\n clearRequests(rejectionError: JsonRpcError<DataWithOptionalCause>): void {\n for (const id of this.#approvals.keys()) {\n this.rejectRequest(id, rejectionError);\n }\n this.#origins.clear();\n this.update((draftState) => {\n draftState.pendingApprovals = {};\n draftState.pendingApprovalCount = 0;\n });\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 */\n updateRequestState(opts: UpdateRequestStateOptions): void {\n if (!this.state.pendingApprovals[opts.id]) {\n throw new ApprovalRequestNotFoundError(opts.id);\n }\n\n this.update((draftState) => {\n draftState.pendingApprovals[opts.id].requestState =\n opts.requestState as never;\n });\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 */\n startFlow(opts: StartFlowOptions = {}): ApprovalFlowStartResult {\n const id = opts.id ?? nanoid();\n const loadingText = opts.loadingText ?? null;\n\n this.update((draftState) => {\n draftState.approvalFlows.push({ id, loadingText });\n });\n\n // By default, if nothing else is specified, we always show the approval.\n if (opts.show !== false) {\n this.#showApprovalRequest();\n }\n\n return { id, loadingText };\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 */\n endFlow({ id }: EndFlowOptions) {\n if (!this.state.approvalFlows.length) {\n throw new NoApprovalFlowsError();\n }\n\n const currentFlow = this.state.approvalFlows.slice(-1)[0];\n\n if (id !== currentFlow.id) {\n throw new EndInvalidFlowError(\n id,\n this.state.approvalFlows.map((flow) => flow.id),\n );\n }\n\n this.update((draftState) => {\n draftState.approvalFlows.pop();\n });\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 */\n setFlowLoadingText({ id, loadingText }: SetFlowLoadingTextOptions) {\n const flowIndex = this.state.approvalFlows.findIndex(\n (flow) => flow.id === id,\n );\n\n if (flowIndex === -1) {\n throw new MissingApprovalFlowError(id);\n }\n\n this.update((draftState) => {\n draftState.approvalFlows[flowIndex].loadingText = loadingText;\n });\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 */\n async showSuccess(opts: SuccessOptions = {}): Promise<SuccessResult> {\n await this.#result(APPROVAL_TYPE_RESULT_SUCCESS, opts, {\n message: opts.message,\n header: opts.header,\n title: opts.title,\n icon: opts.icon,\n } as Record<string, Json>);\n\n return {};\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 */\n async showError(opts: ErrorOptions = {}): Promise<ErrorResult> {\n await this.#result(APPROVAL_TYPE_RESULT_ERROR, opts, {\n error: opts.error,\n header: opts.header,\n title: opts.title,\n icon: opts.icon,\n } as Record<string, Json>);\n\n return {};\n }\n\n /**\n * Implementation of add operation.\n *\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param id - The id of the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n * @param expectsResult - Whether the approval request expects a result object to be returned.\n * @returns The approval promise.\n */\n #add(\n origin: string,\n type: string,\n id: string = nanoid(),\n requestData?: Record<string, Json>,\n requestState?: Record<string, Json>,\n expectsResult?: boolean,\n ): Promise<unknown | AddResult> {\n this.#validateAddParams(id, origin, type, requestData, requestState);\n\n if (\n !this.#typesExcludedFromRateLimiting.includes(type) &&\n this.hasRequest({ origin, type })\n ) {\n throw rpcErrors.resourceUnavailable(\n getAlreadyPendingMessage(origin, type),\n );\n }\n\n // add pending approval\n return new Promise((resolve, reject) => {\n this.#approvals.set(id, { resolve, reject });\n this.#addPendingApprovalOrigin(origin, type);\n\n this.#addToStore(\n id,\n origin,\n type,\n requestData,\n requestState,\n expectsResult,\n );\n });\n }\n\n /**\n * Validates parameters to the add method.\n *\n * @param id - The id of the approval request.\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n */\n #validateAddParams(\n id: string,\n origin: string,\n type: string,\n requestData?: Record<string, Json>,\n requestState?: Record<string, Json>,\n ): void {\n let errorMessage = null;\n if (!id || typeof id !== 'string') {\n errorMessage = 'Must specify non-empty string id.';\n } else if (this.#approvals.has(id)) {\n errorMessage = `Approval request with id '${id}' already exists.`;\n } else if (!origin || typeof origin !== 'string') {\n errorMessage = 'Must specify non-empty string origin.';\n } else if (!type || typeof type !== 'string') {\n errorMessage = 'Must specify non-empty string type.';\n } else if (\n requestData &&\n (typeof requestData !== 'object' || Array.isArray(requestData))\n ) {\n errorMessage = 'Request data must be a plain object if specified.';\n } else if (\n requestState &&\n (typeof requestState !== 'object' || Array.isArray(requestState))\n ) {\n errorMessage = 'Request state must be a plain object if specified.';\n }\n\n if (errorMessage) {\n throw rpcErrors.internal(errorMessage);\n }\n }\n\n /**\n * Adds an entry to _origins.\n * Performs no validation.\n *\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n */\n #addPendingApprovalOrigin(origin: string, type: string): void {\n let originMap = this.#origins.get(origin);\n\n if (!originMap) {\n originMap = new Map();\n this.#origins.set(origin, originMap);\n }\n\n const currentValue = originMap.get(type) || 0;\n originMap.set(type, currentValue + 1);\n }\n\n /**\n * Adds an entry to the store.\n * Performs no validation.\n *\n * @param id - The id of the approval request.\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n * @param expectsResult - Whether the request expects a result object to be returned.\n */\n #addToStore(\n id: string,\n origin: string,\n type: string,\n requestData?: Record<string, Json>,\n requestState?: Record<string, Json>,\n expectsResult?: boolean,\n ): void {\n const approval = {\n id,\n origin,\n type,\n time: Date.now(),\n requestData: requestData || null,\n requestState: requestState || null,\n expectsResult: expectsResult || false,\n };\n\n this.update((draftState) => {\n draftState.pendingApprovals[id] = approval as never;\n\n draftState.pendingApprovalCount = Object.keys(\n draftState.pendingApprovals,\n ).length;\n });\n }\n\n /**\n * Deletes the approval with the given id.\n *\n * Deletion is an internal operation because approval state is solely\n * managed by this controller.\n *\n * @param id - The id of the approval request to be deleted.\n */\n #delete(id: string): void {\n if (!this.#approvals.has(id)) {\n throw new ApprovalRequestNotFoundError(id);\n }\n\n this.#approvals.delete(id);\n\n const { origin, type } = this.state.pendingApprovals[id];\n\n const originMap = this.#origins.get(origin) as Map<string, number>;\n const originTotalCount = this.getApprovalCount({ origin });\n const originTypeCount = originMap.get(type) as number;\n\n if (originTotalCount === 1) {\n this.#origins.delete(origin);\n } else {\n originMap.set(type, originTypeCount - 1);\n }\n\n this.update((draftState) => {\n delete draftState.pendingApprovals[id];\n draftState.pendingApprovalCount = Object.keys(\n draftState.pendingApprovals,\n ).length;\n });\n }\n\n #getCallbacks(id: string): ApprovalCallbacks {\n const callbacks = this.#approvals.get(id);\n\n if (!callbacks) {\n throw new ApprovalRequestNotFoundError(id);\n }\n\n return callbacks;\n }\n\n async #result(\n type: string,\n opts: ResultOptions,\n requestData: Record<string, Json>,\n ) {\n try {\n await this.addAndShowApprovalRequest({\n origin: ORIGIN_METAMASK,\n type,\n requestData,\n });\n } catch (error) {\n console.info('Failed to display result page', error);\n } finally {\n if (opts.flowToEnd) {\n try {\n this.endFlow({ id: opts.flowToEnd });\n } catch (error) {\n console.info('Failed to end flow', { id: opts.flowToEnd, error });\n }\n }\n }\n }\n}\n\nexport default ApprovalController;\n"]}

@@ -1,1 +0,1 @@

{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAqC;AACrC,+CAAyB","sourcesContent":["export * from './ApprovalController';\nexport * from './errors';\n"]}
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAqC;AAmBrC,+CAAyB","sourcesContent":["export * from './ApprovalController';\nexport type {\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} from './ApprovalController-method-action-types';\nexport * from './errors';\n"]}
export * from "./ApprovalController.cjs";
export type { ApprovalControllerAddRequestAction, ApprovalControllerAddAndShowApprovalRequestAction, ApprovalControllerAddAction, ApprovalControllerGetAction, ApprovalControllerGetApprovalCountAction, ApprovalControllerGetTotalApprovalCountAction, ApprovalControllerHasRequestAction, ApprovalControllerAcceptRequestAction, ApprovalControllerRejectRequestAction, ApprovalControllerClearRequestsAction, ApprovalControllerUpdateRequestStateAction, ApprovalControllerStartFlowAction, ApprovalControllerEndFlowAction, ApprovalControllerSetFlowLoadingTextAction, ApprovalControllerShowSuccessAction, ApprovalControllerShowErrorAction, } from "./ApprovalController-method-action-types.cjs";
export * from "./errors.cjs";
//# sourceMappingURL=index.d.cts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yCAAqC;AACrC,6BAAyB"}
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yCAAqC;AACrC,YAAY,EACV,kCAAkC,EAClC,iDAAiD,EACjD,2BAA2B,EAC3B,2BAA2B,EAC3B,wCAAwC,EACxC,6CAA6C,EAC7C,kCAAkC,EAClC,qCAAqC,EACrC,qCAAqC,EACrC,qCAAqC,EACrC,0CAA0C,EAC1C,iCAAiC,EACjC,+BAA+B,EAC/B,0CAA0C,EAC1C,mCAAmC,EACnC,iCAAiC,GAClC,qDAAiD;AAClD,6BAAyB"}
export * from "./ApprovalController.mjs";
export type { ApprovalControllerAddRequestAction, ApprovalControllerAddAndShowApprovalRequestAction, ApprovalControllerAddAction, ApprovalControllerGetAction, ApprovalControllerGetApprovalCountAction, ApprovalControllerGetTotalApprovalCountAction, ApprovalControllerHasRequestAction, ApprovalControllerAcceptRequestAction, ApprovalControllerRejectRequestAction, ApprovalControllerClearRequestsAction, ApprovalControllerUpdateRequestStateAction, ApprovalControllerStartFlowAction, ApprovalControllerEndFlowAction, ApprovalControllerSetFlowLoadingTextAction, ApprovalControllerShowSuccessAction, ApprovalControllerShowErrorAction, } from "./ApprovalController-method-action-types.mjs";
export * from "./errors.mjs";
//# sourceMappingURL=index.d.mts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yCAAqC;AACrC,6BAAyB"}
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yCAAqC;AACrC,YAAY,EACV,kCAAkC,EAClC,iDAAiD,EACjD,2BAA2B,EAC3B,2BAA2B,EAC3B,wCAAwC,EACxC,6CAA6C,EAC7C,kCAAkC,EAClC,qCAAqC,EACrC,qCAAqC,EACrC,qCAAqC,EACrC,0CAA0C,EAC1C,iCAAiC,EACjC,+BAA+B,EAC/B,0CAA0C,EAC1C,mCAAmC,EACnC,iCAAiC,GAClC,qDAAiD;AAClD,6BAAyB"}

@@ -1,1 +0,1 @@

{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yCAAqC;AACrC,6BAAyB","sourcesContent":["export * from './ApprovalController';\nexport * from './errors';\n"]}
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yCAAqC;AAmBrC,6BAAyB","sourcesContent":["export * from './ApprovalController';\nexport type {\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} from './ApprovalController-method-action-types';\nexport * from './errors';\n"]}
{
"name": "@metamask/approval-controller",
"version": "8.0.0",
"version": "9.0.0",
"description": "Manages requests that require user approval",

@@ -39,6 +39,7 @@ "keywords": [

"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
"build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
"build:docs": "typedoc",
"changelog:update": "../../scripts/update-changelog.sh @metamask/approval-controller",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/approval-controller",
"publish:preview": "yarn npm publish --tag preview",
"generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts",
"since-latest-release": "../../scripts/since-latest-release.sh",

@@ -54,3 +55,3 @@ "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",

"@metamask/rpc-errors": "^7.0.2",
"@metamask/utils": "^11.8.1",
"@metamask/utils": "^11.9.0",
"nanoid": "^3.3.8"

@@ -60,10 +61,11 @@ },

"@metamask/auto-changelog": "^3.4.4",
"@types/jest": "^27.4.1",
"@ts-bridge/cli": "^0.6.4",
"@types/jest": "^29.5.14",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
"sinon": "^9.2.4",
"ts-jest": "^27.1.4",
"typedoc": "^0.24.8",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"tsx": "^4.20.5",
"typedoc": "^0.25.13",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.2.2"
"typescript": "~5.3.3"
},

@@ -70,0 +72,0 @@ "engines": {