import {z} from 'zod' export type UpdateSubscriptionRequest = {url?: string | undefined, spaces?: Array | undefined, event_kinds?: (Array<'task-created' | 'task-updated' | 'task-status-changed' | 'task-moved' | 'task-deleted' | 'task-action-added' | 'task-action-completed' | 'task-action-deleted' | 'comment-created' | 'comment-updated' | 'comment-deleted'>) | undefined, paused?: false | undefined, rotate_secret?: boolean | undefined}; export type PatchApiAccountsIntegrationsIdSubscriptionsSidArgs = {id: string, sid: string, body: UpdateSubscriptionRequest}; export type PatchApiAccountsIntegrationsIdSubscriptionsSidOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const taskSubscription = z.object({id: z.string(), account_id: z.string(), integration_id: z.string(), spaces: z.array(z.string()), event_kinds: z.array(z.enum(["task-created", "task-updated", "task-status-changed", "task-moved", "task-deleted", "task-action-added", "task-action-completed", "task-action-deleted", "comment-created", "comment-updated", "comment-deleted"])), url: z.string().max(2048), previous_secret_until: z.string().optional(), environment: z.string().optional(), paused: z.boolean(), paused_reason: z.enum(["", "endpoint_gone", "consecutive_failures", "failing_for_24h", "integration_disabled", "scope_removed"]).optional(), paused_at: z.string().optional(), consecutive_failures: z.number().int().optional(), failing_since: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}); export const subscriptionUpdated = z.object({subscription: taskSubscription, secret: z.string().optional()}); export const patchApiAccountsIntegrationsIdSubscriptionsSidResponse = z.object({data: subscriptionUpdated}); 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 }; /** * Update, resume or rotate a subscription * * PATCH /accounts/integrations/{id}/subscriptions/{sid} * * Also accepts auth: apiKeyAuth */ export const patchApiAccountsIntegrationsIdSubscriptionsSid = async (args: PatchApiAccountsIntegrationsIdSubscriptionsSidArgs, options?: PatchApiAccountsIntegrationsIdSubscriptionsSidOptions) => { const {baseUrl = "https://api.quiva.ai", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/integrations/${encodeURIComponent(String(args.id))}/subscriptions/${encodeURIComponent(String(args.sid))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(patchApiAccountsIntegrationsIdSubscriptionsSidResponse, await res.json()) };