import {z} from 'zod' export type UpdateApiBatchBatchIdVideoIdArgs = {body: {data: {id: string, type: 'video', attributes: {category: 'b-roll' | 'briefings' | 'commercials' | 'greetings' | 'interviews' | 'newscasts' | 'package' | 'psa' | 'video productions', title: string, description: string, instructions: string, notes?: string | undefined, tags?: Array | undefined, created_at: string, virin: string, subdiv?: string | undefined, country: string, city?: string | undefined, status?: ('unpublished' | 'published' | 'archived' | 'needs-approval' | 'processing') | undefined, production_id_number?: string | undefined}, relationships: {authors?: {data: Array<{id: string, type: 'author'}>} | undefined, batch?: {data: {id: string, type: 'batch'}} | undefined, batch_upload: {data: {id: string, type: 'batch-upload' | 'batch-multipart-upload'}}, hometowns?: {data: Array<{id: string, type: 'location'}>} | undefined, themes?: {data: Array<{id: string, type: 'theme'}>} | undefined, service_unit: {data: {id: string, type: 'service-unit'}}}}}}; export type UpdateApiBatchBatchIdVideoIdOptions = {baseUrl?: string | undefined, DVIDS?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiBatchBatchIdVideoIdResponse = z.object({data: z.object({id: z.string(), type: z.literal("video"), attributes: z.object({category: z.enum(["b-roll", "briefings", "commercials", "greetings", "interviews", "newscasts", "package", "psa", "video productions"]), title: z.string().max(255), description: z.string().max(65535), instructions: z.string().max(65535), notes: z.string().max(65535).optional(), tags: z.array(z.string().max(100)).optional(), created_at: z.string(), virin: z.string(), subdiv: z.string().max(50).optional(), country: z.string().max(2), city: z.string().max(75).optional(), status: z.enum(["unpublished", "published", "archived", "needs-approval", "processing"]).optional(), production_id_number: z.string().min(6).max(8).optional()}), relationships: z.object({authors: z.object({data: z.array(z.object({id: z.string(), type: z.literal("author")}))}).optional(), batch: z.object({data: z.object({id: z.string(), type: z.literal("batch")})}).optional(), batch_upload: z.object({data: z.object({id: z.string(), type: z.enum(["batch-upload", "batch-multipart-upload"])})}), hometowns: z.object({data: z.array(z.object({id: z.string(), type: z.literal("location")}))}).optional(), themes: z.object({data: z.array(z.object({id: z.string(), type: z.literal("theme")}))}).optional(), service_unit: z.object({data: z.object({id: z.string(), type: z.literal("service-unit")})})})})}); 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 video by id * * PUT /batch/{batch_id}/video/{id} */ export const updateApiBatchBatchIdVideoId = async (args: UpdateApiBatchBatchIdVideoIdArgs, options?: UpdateApiBatchBatchIdVideoIdOptions) => { const {baseUrl = "https://submitapi.dvidshub.net", fetch: fetchFn = fetch, DVIDS} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/vnd.api+json") headers.set('accept', "application/vnd.api+json") if (DVIDS !== undefined) headers.set('authorization', `Bearer ${DVIDS}`) const url = `${baseUrl.replace(/\/+$/, '')}/batch/${encodeURIComponent(String(args.batch_id))}/video/${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(updateApiBatchBatchIdVideoIdResponse, await res.json()) };