import {z} from 'zod' export type GetApiScheduledcaptureIdArgs = {id: string}; export type GetApiScheduledcaptureIdOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const scheduledCapture = z.object({id: z.string(), name: z.string(), paused: z.boolean(), comment: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), captureRequest: z.object({apps: z.array(z.string()).optional(), browser: z.enum(["Chrome", "Firefox", "iPhone", "iPhone 12"]), country: z.enum(["USA", "Germany", "Italy", "Netherlands", "UK", "Australia"]), cropHeight: z.number().int().optional(), cropLeft: z.number().int().optional(), cropTop: z.number().int().optional(), cropBottom: z.number().int().optional(), emails: z.array(z.string()).optional(), externalMax: z.number().int().optional(), format: z.enum(["png", "jpeg"]), height: z.number().int(), scrollTo: z.object({x: z.number().int().optional(), y: z.number().int().optional()}).optional(), size: z.enum(["Full Page", "Screen"]).optional(), steps: z.array(z.object({command: z.enum(["type", "click", "screenshot", "navigate", "sleep"]), selector: z.string().optional(), value: z.string().optional()})).optional(), tags: z.array(z.object({name: z.string(), readOnly: z.boolean()})).optional(), url: z.string().optional(), urlExternal: z.string().optional(), urlType: z.enum(["single", "multiple", "external"]).optional(), urls: z.array(z.string()).optional(), waitSecond: z.number().int().optional(), maxWait: z.number().int().optional(), hidePopups: z.number().int().optional(), dark: z.number().int().optional(), strictSSL: z.number().int().optional(), width: z.number().int().optional(), zoom: z.number().int().optional()}), schedule: z.object({daysOfMonth: z.array(z.number().int()).optional(), daysofWeek: z.array(z.number().int()).optional(), exactDates: z.array(z.string()).optional(), timesOfDay: z.array(z.string()).optional()}), trackers: z.array(z.unknown()).optional()}); 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 }; /** * Retrieve an existing scheduled capture * * GET /scheduledcapture/{id} * * Also accepts auth: key */ export const getApiScheduledcaptureId = async (args: GetApiScheduledcaptureIdArgs, options?: GetApiScheduledcaptureIdOptions) => { const {baseUrl = "https://blitapp.com/api", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(scheduledCapture, await res.json()) };