import {z} from 'zod' export type GetApiV1AssetsAssetIdVersionsVersionIdFileSetsArgs = {'App-ID': string, 'Auth-Token': string, asset_id: string, version_id: string, per_page?: number | undefined, last_id?: string | undefined, file_count?: boolean | undefined, skip_archived?: boolean | undefined}; export type GetApiV1AssetsAssetIdVersionsVersionIdFileSetsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const fileSetSchema = z.object({archive_file_set_id: z.string().optional(), asset_id: z.string().optional(), base_dir: z.string(), component_ids: z.array(z.string()), date_created: z.string().optional(), date_deleted: z.string().optional(), date_modified: z.string().optional(), deleted_by_user: z.string().optional(), file_count: z.number().int().gte(-2147483648).lte(2147483647).optional(), format_id: z.string(), id: z.string().optional(), is_archive: z.boolean().optional(), name: z.string(), original_storage_id: z.string().optional(), status: z.enum(["ACTIVE", "ARCHIVED", "DELETED"]).optional(), storage_id: z.string().optional(), type: z.enum(["REGULAR", "MANY_FILES"]).optional(), version_id: z.string().optional()}); export const fileSetsSchema = z.object({first_url: z.string().optional(), last_url: z.string().optional(), next_url: z.string().optional(), objects: z.array(fileSetSchema).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(), 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 all asset's file sets by version * * GET /v1/assets/{asset_id}/versions/{version_id}/file_sets/ */ export const getApiV1AssetsAssetIdVersionsVersionIdFileSets = async (args: GetApiV1AssetsAssetIdVersionsVersionIdFileSetsArgs, options: GetApiV1AssetsAssetIdVersionsVersionIdFileSetsOptions) => { 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.last_id != null) query.append("last_id", String(args.last_id)) if (args.file_count != null) query.append("file_count", String(args.file_count)) if (args.skip_archived != null) query.append("skip_archived", String(args.skip_archived)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/assets/${encodeURIComponent(String(args.asset_id))}/versions/${encodeURIComponent(String(args.version_id))}/file_sets/${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(fileSetsSchema, await res.json()) };