import {z} from 'zod' export type DeleteApiV1WebhooksWebhookIdArgs = {'X-Encircle-Attribution'?: string | undefined, 'X-Encircle-Request'?: string | undefined}; export type DeleteApiV1WebhooksWebhookIdOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const webhookResponse = z.object({id: z.number().int(), delivery_url: z.string(), events: z.array(z.enum(["add_property_claim", "delete_property_claim", "update_property_claim", "add_property_inspection", "delete_property_inspection", "update_property_inspection", "add_property_claim_media", "delete_property_claim_media", "add_property_inspection_media", "delete_property_inspection_media", "add_property_claim_note", "delete_property_claim_note", "add_property_claim_room_note", "delete_property_claim_room_note", "add_dehumidifier", "update_dehumidifier", "add_air_mover", "update_air_mover", "add_air_scrubber", "update_air_scrubber", "property_claim_media", "property_inspection_media"])), authentication: z.object({type: z.enum(["jwt", "oauth", "shared_secret"]), header_name: z.enum(["Authorization", "ocp-apim-subscription-key"]), shared_secret: z.string()}).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Delete a webhook * * DELETE /v1/webhooks/{webhook_id} */ export const deleteApiV1WebhooksWebhookId = async (args: DeleteApiV1WebhooksWebhookIdArgs, options: DeleteApiV1WebhooksWebhookIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Encircle-Attribution'] != null) headers.set("X-Encircle-Attribution", String(args['X-Encircle-Attribution'])) if (args['X-Encircle-Request'] != null) headers.set("X-Encircle-Request", String(args['X-Encircle-Request'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/webhooks/${encodeURIComponent(String(args.webhook_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(webhookResponse, await res.json()) };