import {z} from 'zod' export type GetApiV1AssetsAssetIdHistoryArgs = {'App-ID': string, 'Auth-Token': string, asset_id: string, per_page?: number | undefined, page?: number | undefined, sort?: string | undefined, filter?: string | undefined, query?: string | undefined, ids?: string | undefined}; export type GetApiV1AssetsAssetIdHistoryOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const assetHistoryElasticSchema = 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 assetHistoryEntitiesSchema = z.object({first_url: z.string().optional(), last_url: z.string().optional(), next_url: z.string().optional(), objects: z.array(assetHistoryElasticSchema).optional(), page: z.number().int().gte(-2147483648).lte(2147483647).optional(), pages: z.number().int().gte(-2147483648).lte(2147483647).optional(), per_page: z.number().int().gte(-2147483648).lte(2147483647).optional(), prev_url: z.string().optional(), scroll_id: z.string().optional(), search_after: z.array(z.unknown()).optional(), total: z.number().int().gte(-9223372036854776000).lte(9223372036854776000).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 }; /** * Get list of history entities for asset * * GET /v1/assets/{asset_id}/history/ */ export const getApiV1AssetsAssetIdHistory = async (args: GetApiV1AssetsAssetIdHistoryArgs, options: GetApiV1AssetsAssetIdHistoryOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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.per_page != null) query.append("per_page", String(args.per_page)) if (args.page != null) query.append("page", String(args.page)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.filter != null) query.append("filter", String(args.filter)) if (args.query != null) query.append("query", String(args.query)) if (args.ids != null) query.append("ids", String(args.ids)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/assets/${encodeURIComponent(String(args.asset_id))}/history/${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(assetHistoryEntitiesSchema, await res.json()) };