import {z} from 'zod' export type ScheduledCapture = {id: string, name: string, paused: boolean, comment?: string | undefined, createdAt?: string | undefined, updatedAt?: string | undefined, captureRequest: {apps?: Array | undefined, browser: 'Chrome' | 'Firefox' | 'iPhone' | 'iPhone 12', country: 'USA' | 'Germany' | 'Italy' | 'Netherlands' | 'UK' | 'Australia', cropHeight?: number | undefined, cropLeft?: number | undefined, cropTop?: number | undefined, cropBottom?: number | undefined, emails?: Array | undefined, externalMax?: number | undefined, format: 'png' | 'jpeg', height: number, scrollTo?: ({x?: number | undefined, y?: number | undefined}) | undefined, size?: ('Full Page' | 'Screen') | undefined, steps?: (Array<{command: 'type' | 'click' | 'screenshot' | 'navigate' | 'sleep', selector?: string | undefined, value?: string | undefined}>) | undefined, tags?: Array<{name: string, readOnly: boolean}> | undefined, url?: string | undefined, urlExternal?: string | undefined, urlType?: ('single' | 'multiple' | 'external') | undefined, urls?: Array | undefined, waitSecond?: number | undefined, maxWait?: number | undefined, hidePopups?: number | undefined, dark?: number | undefined, strictSSL?: number | undefined, width?: number | undefined, zoom?: number | undefined}, schedule: {daysOfMonth?: Array | undefined, daysofWeek?: Array | undefined, exactDates?: Array | undefined, timesOfDay?: Array | undefined}, trackers?: Array | undefined}; export type UpdateApiScheduledcaptureIdArgs = {id: string, body: ScheduledCapture}; export type UpdateApiScheduledcaptureIdOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiScheduledcaptureIdResponse = z.array(z.number().int()); 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 an existing scheduled capture * * PUT /scheduledcapture/{id} * * Also accepts auth: key */ export const updateApiScheduledcaptureId = async (args: UpdateApiScheduledcaptureIdArgs, options?: UpdateApiScheduledcaptureIdOptions) => { const {baseUrl = "https://blitapp.com/api", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("Api-key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/scheduledcapture/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiScheduledcaptureIdResponse, await res.json()) };