import {z} from 'zod' export type CreateApiV0WebhooksWebhookIdActionsDeactivateArgs = {'webhook-id': string}; export type CreateApiV0WebhooksWebhookIdActionsDeactivateOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV0WebhooksWebhookIdActionsDeactivateResponse = z.object({"webhook-description": z.string().min(1).optional(), "updated-at": z.string().optional(), "activate-webhook-url": z.string(), "deactivate-webhook-url": z.string(), "created-at": z.string(), "webhook-state": z.enum(["inactive", "active"]), "created-by": z.string().optional(), "organization-url": z.string(), "test-webhook-url": z.string(), "webhook-url": z.string(), "webhook-destination-url": z.string()}); 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 }; /** * Deactivate a webhook * * POST /v0/webhooks/{webhook-id}/actions/deactivate */ export const createApiV0WebhooksWebhookIdActionsDeactivate = async (args: CreateApiV0WebhooksWebhookIdActionsDeactivateArgs, options?: CreateApiV0WebhooksWebhookIdActionsDeactivateOptions) => { const {baseUrl = "https://api.griffin.com", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("Authorization", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v0/webhooks/${encodeURIComponent(String(args['webhook-id']))}/actions/deactivate${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiV0WebhooksWebhookIdActionsDeactivateResponse, await res.json()) };