import {z} from 'zod' export type FileSchema = {asset_id?: string | undefined, checksum?: (string | null) | undefined, date_created?: string | undefined, date_modified?: string | undefined, directory_path: string, file_date_created?: string | undefined, file_date_modified?: string | undefined, file_set_id: string, file_set_status?: (string | null) | undefined, format_id?: string | undefined, format_status?: (string | null) | undefined, id?: string | undefined, multipart_upload_url?: string | undefined, name?: string | undefined, original_name: string, parent_id?: (string | null) | undefined, size?: number | undefined, status?: ('OPEN' | 'GROWING' | 'AWAITED' | 'CLOSED' | 'FAILED' | 'ARCHIVED' | 'MISSING' | 'REDISCOVERED' | 'DELETED') | undefined, storage_id?: string | undefined, storage_method?: string | undefined, system_domain_id?: string | undefined, template?: string | undefined, template_engine?: ('SIMPLE' | 'JINJA2' | 'null' | null) | undefined, type: 'FILE' | 'DIRECTORY' | 'SYMLINK' | 'SEQUENCE', upload_credentials?: {[key: string]: unknown} | undefined, upload_filename?: string | undefined, upload_headers?: {[key: string]: unknown} | undefined, upload_method?: string | undefined, upload_url?: string | undefined, url?: string | undefined, user_id?: (string | null) | undefined, version_id?: string | undefined}; export type UpdateApiV1AssetsAssetIdTemporaryFilesFileIdArgs = {'App-ID': string, 'Auth-Token': string, asset_id: string, file_id: string, body: FileSchema}; export type UpdateApiV1AssetsAssetIdTemporaryFilesFileIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const fileSchema = z.object({asset_id: z.string().optional(), checksum: z.string().nullable().optional(), date_created: z.string().optional(), date_modified: z.string().optional(), directory_path: z.string(), file_date_created: z.string().optional(), file_date_modified: z.string().optional(), file_set_id: z.string(), file_set_status: z.string().nullable().optional(), format_id: z.string().optional(), format_status: z.string().nullable().optional(), id: z.string().optional(), multipart_upload_url: z.string().optional(), name: z.string().optional(), original_name: z.string(), parent_id: z.string().nullable().optional(), size: z.number().int().gte(-9223372036854776000).lte(9223372036854776000).optional(), status: z.enum(["OPEN", "GROWING", "AWAITED", "CLOSED", "FAILED", "ARCHIVED", "MISSING", "REDISCOVERED", "DELETED"]).optional(), storage_id: z.string().optional(), storage_method: z.string().optional(), system_domain_id: z.string().optional(), template: z.string().optional(), template_engine: z.enum(["SIMPLE", "JINJA2", "null"]).nullable().optional(), type: z.enum(["FILE", "DIRECTORY", "SYMLINK", "SEQUENCE"]), upload_credentials: z.record(z.string(), z.unknown()).optional(), upload_filename: z.string().optional(), upload_headers: z.record(z.string(), z.unknown()).optional(), upload_method: z.string().optional(), upload_url: z.string().optional(), url: z.string().optional(), user_id: z.string().nullable().optional(), version_id: z.string().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 }; /** * Update temporary file's info * * PUT /v1/assets/{asset_id}/temporary_files/{file_id}/ */ export const updateApiV1AssetsAssetIdTemporaryFilesFileId = async (args: UpdateApiV1AssetsAssetIdTemporaryFilesFileIdArgs, options: UpdateApiV1AssetsAssetIdTemporaryFilesFileIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['App-ID'] != null) headers.set("App-ID", String(args['App-ID'])) if (args['Auth-Token'] != null) headers.set("Auth-Token", String(args['Auth-Token'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/assets/${encodeURIComponent(String(args.asset_id))}/temporary_files/${encodeURIComponent(String(args.file_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(fileSchema, await res.json()) };