UNPKG

@metamask/snaps-rpc-methods

Version:
42 lines 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getBackgroundEventsHandler = void 0; const rpc_errors_1 = require("@metamask/rpc-errors"); const endowments_1 = require("../endowments/index.cjs"); const methodName = 'snap_getBackgroundEvents'; const hookNames = { getBackgroundEvents: true, hasPermission: true, }; exports.getBackgroundEventsHandler = { methodNames: [methodName], implementation: getGetBackgroundEventsImplementation, hookNames, }; /** * The `snap_getBackgroundEvents` method implementation. * * @param _req - The JSON-RPC request object. Not used by this function. * @param res - 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.getBackgroundEvents - The function to get the background events. * @param hooks.hasPermission - The function to check if a snap has the `endowment:cronjob` permission. * @returns An array of background events. */ async function getGetBackgroundEventsImplementation(_req, res, _next, end, { getBackgroundEvents, hasPermission }) { if (!hasPermission(endowments_1.SnapEndowments.Cronjob)) { return end(rpc_errors_1.providerErrors.unauthorized()); } try { const events = getBackgroundEvents(); res.result = events; } catch (error) { return end(error); } return end(); } //# sourceMappingURL=getBackgroundEvents.cjs.map