import { post } from '../../../../lib/request/request-params-builder.ts'; import { safeUrl } from '../../../../lib/utils.ts'; import { CcApiSimpleCommand } from '../../lib/cc-api-command.ts'; import type { CreateWebhookNotificationCommandInput, CreateWebhookNotificationCommandOutput, } from './create-webhook-notification-command.types.ts'; import { transformWebhookNotification } from './notification-transform.ts'; /** * Creates a webhook, which posts platform events to one or more URLs as they happen. * * @endpoint [POST] /v2/notifications/webhooks/:XXX * @group Notification * @version 2 */ export class CreateWebhookNotificationCommand extends CcApiSimpleCommand< CreateWebhookNotificationCommandInput, CreateWebhookNotificationCommandOutput > { toRequestParams(params: CreateWebhookNotificationCommandInput) { return post(safeUrl`/v2/notifications/webhooks/${params.ownerId}`, { name: params.name, urls: params.urls, events: params.events, scope: params.scopes, }); } transformCommandOutput(response: unknown): CreateWebhookNotificationCommandOutput { return transformWebhookNotification(response); } // the handler inserts a hook under a freshly generated id, so a replay leaves the owner with two identical hooks isIdempotent(): boolean { return false; } }