import {z} from 'zod' export type CreateApiApiV1InstastatsVideosJobIdCancelArgs = {job_id: string, 'x-api-key': string, League: string}; export type CreateApiApiV1InstastatsVideosJobIdCancelOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const jobVideoIssue = z.object({issue_type: z.string(), exact_timestamp: z.string()}); export const jobStatusResponse = z.object({sport_game_type: z.enum(["5v5", "3v3"]).nullable().optional(), job_id: z.string(), state: z.string(), message: z.string().nullable().optional(), start_of_play: z.string().optional(), completed_at: z.string().nullable().optional(), processing_started_at: z.string().nullable().optional(), video_quality: z.record(z.string(), z.unknown()).nullable().optional(), issues: z.array(jobVideoIssue).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 }; /** * Cancel Video * * POST /api/v1/instastats_videos/{job_id}/cancel */ export const createApiApiV1InstastatsVideosJobIdCancel = async (args: CreateApiApiV1InstastatsVideosJobIdCancelArgs, options?: CreateApiApiV1InstastatsVideosJobIdCancelOptions) => { const {baseUrl = "https://developer.preciser.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['x-api-key'] != null) headers.set("x-api-key", String(args['x-api-key'])) if (args.League != null) headers.set("League", String(args.League)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/instastats_videos/${encodeURIComponent(String(args.job_id))}/cancel${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(jobStatusResponse, await res.json()) };