import {z} from 'zod' export type WebhookAuthRequest = {scheme?: ('none' | 'bearer' | 'basic' | 'header') | undefined, secret?: (string | null) | undefined, headerName?: (string | null) | undefined}; export type UpdateWatchRequest = {isActive?: (boolean | null) | undefined, webhookUrl?: (string | null) | undefined, webhookSecret?: (string | null) | undefined, scope?: ({[key: string]: string} | null) | undefined, emailAddress?: (string | null) | undefined, webhookAuth?: (WebhookAuthRequest | null) | undefined}; export type PatchApiApiV1WatchesWatchIdArgs = {watch_id: string, body: UpdateWatchRequest}; export type PatchApiApiV1WatchesWatchIdOptions = {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 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 watchEnvelope = z.object({data: watchResponse, 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 }; /** * Update a board watch * * PATCH /api/v1/watches/{watch_id} * * Also accepts auth: ApiKeyHeader */ export const patchApiApiV1WatchesWatchId = async (args: PatchApiApiV1WatchesWatchIdArgs, options?: PatchApiApiV1WatchesWatchIdOptions) => { const {baseUrl = "https://api.vaquill.ai", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set('authorization', `Bearer ${ApiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/watches/${encodeURIComponent(String(args.watch_id))}${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(watchEnvelope, await res.json()) };