UNPKG

@marceloclp/monzojs

Version:

Unofficial wrapper for the Monzo API written in TypeScript.

41 lines (40 loc) 1.6 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.deleteWebhook = exports.createWebhook = exports.getWebhooks = void 0; const create_request_1 = __importDefault(require("../utils/create-request")); /** * List the webhooks your application has registered on an account. * * @see https://docs.monzo.com/#list-webhooks */ const getWebhooks = async (accessToken, { accountId }) => (0, create_request_1.default)(accessToken) .withQuery({ account_id: accountId }) .get(`webhooks`) .then(({ webhooks }) => webhooks); exports.getWebhooks = getWebhooks; /** * Register a webhook. * * Each time a matching event occurs, Monzo will make a POST call to the URL you * provide. If the call fails, we will retry up to a maximum of 5 attempts, with * exponential backoff. * * @see https://docs.monzo.com/#registering-a-webhook */ const createWebhook = async (accessToken, { accountId, url }) => (0, create_request_1.default)(accessToken) .withFormData({ account_id: accountId, url: url }) .post(`webhooks`) .then(({ webhook }) => webhook); exports.createWebhook = createWebhook; /** * Delete a webhook. * * This will stop Monzo from sending notifications to the webhook's url. * * @see https://docs.monzo.com/#deleting-a-webhook */ const deleteWebhook = async (accessToken, { webhookId }) => (0, create_request_1.default)(accessToken).post(`webhooks/${webhookId}`); exports.deleteWebhook = deleteWebhook;