import {z} from 'zod' export type GetApiApiV1WatchesArgs = {limit?: number | undefined, offset?: number | undefined}; export type GetApiApiV1WatchesOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const webhookAuthResponse = z.object({scheme: z.string(), headerName: z.string().nullable().optional(), hasSecret: z.boolean().optional()}); export const watchResponse = z.object({id: z.string(), corpusType: z.string(), state: z.string().nullable().optional(), channel: z.string(), webhookUrl: z.string().nullable().optional(), emailAddress: z.string().nullable().optional(), scope: z.record(z.string(), z.string()).nullable().optional(), isActive: z.boolean(), createdAt: z.string(), updatedAt: z.string().nullable().optional(), lastNotifiedAt: z.string().nullable().optional(), lastStatus: z.number().int().nullable().optional(), webhookAuth: webhookAuthResponse.nullable().optional(), cadence: z.string().nullable().optional(), lastRetrievedAt: z.string().nullable().optional(), changeSignal: z.string().optional()}); export const watchesPage = z.object({watches: z.array(watchResponse)}); export const responseMeta = z.object({processingTimeMs: z.number(), creditsConsumed: z.number(), cursor: z.number().int().nullable().optional(), nextBeforeId: z.number().int().nullable().optional(), hasMore: z.boolean().nullable().optional()}); export const watchesEnvelope = z.object({data: watchesPage, meta: responseMeta}); 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 your board watches * * GET /api/v1/watches * * Also accepts auth: ApiKeyHeader */ export const getApiApiV1Watches = async (args: GetApiApiV1WatchesArgs, options?: GetApiApiV1WatchesOptions) => { const {baseUrl = "https://api.vaquill.ai", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (ApiKeyAuth !== undefined) headers.set('authorization', `Bearer ${ApiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/watches${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(watchesEnvelope, await res.json()) };