UNPKG

nylas

Version:

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

98 lines (97 loc) 2.98 kB
import { Resource } from './resource.js'; import { makePathParams } from '../utils.js'; /** * Nylas Webhooks API * * The Nylas Webhooks API allows your application to receive notifications in real-time when certain events occur. */ export class Webhooks extends Resource { /** * List all webhook destinations for the application * @returns The list of webhook destinations */ list({ overrides } = {}) { return super._list({ overrides, path: makePathParams('/v3/webhooks', {}), }); } /** * Return a webhook destination * @return The webhook destination */ find({ webhookId, overrides, }) { return super._find({ path: makePathParams('/v3/webhooks/{webhookId}', { webhookId }), overrides, }); } /** * Create a webhook destination * @returns The created webhook destination */ create({ requestBody, overrides, }) { return super._create({ path: makePathParams('/v3/webhooks', {}), requestBody, overrides, }); } /** * Update a webhook destination * @returns The updated webhook destination */ update({ webhookId, requestBody, overrides, }) { return super._update({ path: makePathParams('/v3/webhooks/{webhookId}', { webhookId }), requestBody, overrides, }); } /** * Delete a webhook destination * @returns The deletion response */ destroy({ webhookId, overrides, }) { return super._destroy({ path: 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: 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: 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; } }