import {z} from 'zod' export type AssetHistorySchema = {asset_id?: string | undefined, date_created?: string | undefined, date_modified?: string | undefined, id?: string | undefined, job_id?: (string | null) | undefined, operation_description?: (string | null) | undefined, operation_type: 'EXPORT' | 'TRANSCODE' | 'ANALYZE' | 'ADD_FORMAT' | 'DELETE_FORMAT' | 'RESTORE_FORMAT' | 'DELETE_FILESET' | 'DELETE_FILE' | 'RESTORE_FILESET' | 'MODIFY_FILESET' | 'APPROVE' | 'REJECT' | 'DOWNLOAD' | 'METADATA' | 'CUSTOM' | 'TRANSCRIPTION' | 'VERSION_CREATE' | 'VERSION_DELETE' | 'VERSION_UPDATE' | 'VERSION_PROMOTE' | 'RESTORE' | 'RESTORE_FROM_GLACIER' | 'ARCHIVE' | 'RESTORE_ARCHIVE' | 'DELETE' | 'TRANSFER' | 'UNLINK_SUBCLIP' | 'FACE_RECOGNITION' | 'PUBLISH' | 'PUBLISH_SCHEDULED' | 'PUBLISH_SAVE_DRAFT', share_id?: (string | null) | undefined, share_user_id?: (string | null) | undefined, system_domain_id?: string | undefined, user_id?: string | undefined, version_id?: string | undefined}; export type CreateApiV1AssetsAssetIdHistoryArgs = {'App-ID': string, 'Auth-Token': string, asset_id: string, update_asset_date_modified?: boolean | undefined, body: AssetHistorySchema}; export type CreateApiV1AssetsAssetIdHistoryOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const assetHistorySchema = z.object({asset_id: z.string().optional(), date_created: z.string().optional(), date_modified: z.string().optional(), id: z.string().optional(), job_id: z.string().nullable().optional(), operation_description: z.string().nullable().optional(), operation_type: z.enum(["EXPORT", "TRANSCODE", "ANALYZE", "ADD_FORMAT", "DELETE_FORMAT", "RESTORE_FORMAT", "DELETE_FILESET", "DELETE_FILE", "RESTORE_FILESET", "MODIFY_FILESET", "APPROVE", "REJECT", "DOWNLOAD", "METADATA", "CUSTOM", "TRANSCRIPTION", "VERSION_CREATE", "VERSION_DELETE", "VERSION_UPDATE", "VERSION_PROMOTE", "RESTORE", "RESTORE_FROM_GLACIER", "ARCHIVE", "RESTORE_ARCHIVE", "DELETE", "TRANSFER", "UNLINK_SUBCLIP", "FACE_RECOGNITION", "PUBLISH", "PUBLISH_SCHEDULED", "PUBLISH_SAVE_DRAFT"]), share_id: z.string().nullable().optional(), share_user_id: z.string().nullable().optional(), system_domain_id: z.string().optional(), user_id: z.string().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 }; /** * Create an asset history entity * * POST /v1/assets/{asset_id}/history/ */ export const createApiV1AssetsAssetIdHistory = async (args: CreateApiV1AssetsAssetIdHistoryArgs, options: CreateApiV1AssetsAssetIdHistoryOptions) => { 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'])) if (args.update_asset_date_modified != null) query.append("update_asset_date_modified", String(args.update_asset_date_modified)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/assets/${encodeURIComponent(String(args.asset_id))}/history/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(assetHistorySchema, await res.json()) };