UNPKG

nylas

Version:

A NodeJS wrapper for the Nylas REST API for email, contacts, and calendar.

102 lines (101 loc) 3.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Webhooks = void 0; const resource_js_1 = require("./resource.js"); const utils_js_1 = require("../utils.js"); /** * Nylas Webhooks API * * The Nylas Webhooks API allows your application to receive notifications in real-time when certain events occur. */ class Webhooks extends resource_js_1.Resource { /** * List all webhook destinations for the application * @returns The list of webhook destinations */ list({ overrides } = {}) { return super._list({ overrides, path: (0, utils_js_1.makePathParams)('/v3/webhooks', {}), }); } /** * Return a webhook destination * @return The webhook destination */ find({ webhookId, overrides, }) { return super._find({ path: (0, utils_js_1.makePathParams)('/v3/webhooks/{webhookId}', { webhookId }), overrides, }); } /** * Create a webhook destination * @returns The created webhook destination */ create({ requestBody, overrides, }) { return super._create({ path: (0, utils_js_1.makePathParams)('/v3/webhooks', {}), requestBody, overrides, }); } /** * Update a webhook destination * @returns The updated webhook destination */ update({ webhookId, requestBody, overrides, }) { return super._update({ path: (0, utils_js_1.makePathParams)('/v3/webhooks/{webhookId}', { webhookId }), requestBody, overrides, }); } /** * Delete a webhook destination * @returns The deletion response */ destroy({ webhookId, overrides, }) { return super._destroy({ path: (0, utils_js_1.makePathParams)('/v3/webhooks/{webhookId}', { webhookId }), overrides, }); } /** * Update the webhook secret value for a destination * @returns The updated webhook destination with the webhook secret */ rotateSecret({ webhookId, overrides, }) { return super._create({ path: (0, utils_js_1.makePathParams)('/v3/webhooks/rotate-secret/{webhookId}', { webhookId, }), requestBody: {}, overrides, }); } /** * Get the current list of IP addresses that Nylas sends webhooks from * @returns The list of IP addresses that Nylas sends webhooks from */ ipAddresses({ overrides } = {}) { return super._find({ path: (0, utils_js_1.makePathParams)('/v3/webhooks/ip-addresses', {}), overrides, }); } /** * Extract the challenge parameter from a URL * @param url The URL sent by Nylas containing the challenge parameter * @returns The challenge parameter */ extractChallengeParameter(url) { const urlObject = new URL(url); const challengeParameter = urlObject.searchParams.get('challenge'); if (!challengeParameter) { throw new Error('Invalid URL or no challenge parameter found.'); } return challengeParameter; } } exports.Webhooks = Webhooks;