UNPKG

@metamask/snaps-rpc-methods

Version:
76 lines 2.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.endTraceHandler = void 0; const rpc_errors_1 = require("@metamask/rpc-errors"); const superstruct_1 = require("@metamask/superstruct"); const hookNames = { endTrace: true, }; const EndTraceParametersStruct = (0, superstruct_1.object)({ id: (0, superstruct_1.exactOptional)((0, superstruct_1.string)()), name: (0, superstruct_1.string)(), timestamp: (0, superstruct_1.exactOptional)((0, superstruct_1.number)()), }); /** * End a performance trace in Sentry. This method is only available to * preinstalled Snaps. * * @internal */ exports.endTraceHandler = { implementation: getEndTraceImplementation, hookNames, actionNames: ['SnapController:getSnap'], }; /** * The `snap_endTrace` method implementation. This method is used to end a * performance trace in Sentry. It is only available to preinstalled Snaps. * * @param request - The JSON-RPC request object. * @param response - The JSON-RPC response object. * @param _next - The `json-rpc-engine` "next" callback. Not used by this * function. * @param end - The `json-rpc-engine` "end" callback. * @param hooks - The RPC method hooks. * @param hooks.endTrace - The hook function to end a performance trace. * @param messenger - The messenger used to call controller actions. * @returns Nothing. */ function getEndTraceImplementation(request, response, _next, end, { endTrace }, messenger) { const snap = messenger.call('SnapController:getSnap', request.origin); if (!snap?.preinstalled) { return end(rpc_errors_1.rpcErrors.methodNotFound()); } const { params } = request; try { const validatedParams = getValidatedParams(params); endTrace(validatedParams); response.result = null; } catch (error) { return end(error); } return end(); } /** * Validate the parameters for the `snap_endTrace` method. * * @param params - Parameters to validate. * @returns Validated parameters. * @throws Throws RPC error if validation fails. */ function getValidatedParams(params) { try { return (0, superstruct_1.create)(params, EndTraceParametersStruct); } catch (error) { if (error instanceof superstruct_1.StructError) { throw rpc_errors_1.rpcErrors.invalidParams({ message: `Invalid params: ${error.message}.`, }); } /* istanbul ignore next */ throw rpc_errors_1.rpcErrors.internal(); } } //# sourceMappingURL=endTrace.cjs.map