import {z} from 'zod' export type GetApiV1DeleteQueueFileSetsArgs = {'App-ID': string, 'Auth-Token': string, per_page?: number | undefined, page?: number | undefined, sort?: string | undefined, query?: string | undefined, field_name?: string | undefined}; export type GetApiV1DeleteQueueFileSetsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const fileSetElasticSchema = 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 fileSetsElasticSchema = z.object({facets: z.record(z.string(), z.unknown()).optional(), first_url: z.string().optional(), last_url: z.string().optional(), next_url: z.string().optional(), objects: z.array(fileSetElasticSchema).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 deleted file sets * * GET /v1/delete_queue/file_sets/ */ export const getApiV1DeleteQueueFileSets = async (args: GetApiV1DeleteQueueFileSetsArgs, options: GetApiV1DeleteQueueFileSetsOptions) => { 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.query != null) query.append("query", String(args.query)) if (args.field_name != null) query.append("field_name", String(args.field_name)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/delete_queue/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(fileSetsElasticSchema, await res.json()) };