import {z} from 'zod' export type GetApiAccountsIntegrationsIdSubscriptionsArgs = {id: string}; export type GetApiAccountsIntegrationsIdSubscriptionsOptions = {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 getApiAccountsIntegrationsIdSubscriptionsResponse = z.object({data: z.array(taskSubscription)}); 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 }; /** * List webhook subscriptions * * GET /accounts/integrations/{id}/subscriptions * * Also accepts auth: apiKeyAuth */ export const getApiAccountsIntegrationsIdSubscriptions = async (args: GetApiAccountsIntegrationsIdSubscriptionsArgs, options?: GetApiAccountsIntegrationsIdSubscriptionsOptions) => { const {baseUrl = "https://api.quiva.ai", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/integrations/${encodeURIComponent(String(args.id))}/subscriptions${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiAccountsIntegrationsIdSubscriptionsResponse, await res.json()) };