import {z} from 'zod' export type GetApiV1ExportLocationsArgs = {'App-ID': string, 'Auth-Token': string, query?: string | undefined, ids?: string | undefined, per_page?: number | undefined, last_id?: string | undefined, sort?: string | undefined, page?: number | undefined}; export type GetApiV1ExportLocationsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const exportLocationSchema = z.object({description: z.string().optional(), export_metadata: z.boolean().optional(), export_original: z.boolean().optional(), export_posters: z.boolean().optional(), export_proxy: z.boolean().optional(), export_to_asset_folder: z.boolean().optional(), export_transcriptions: z.boolean().optional(), id: z.string().optional(), include_original_extension: z.boolean().optional(), metadata_format: z.enum(["CSV", "JSON", "XML"]).optional(), metadata_view: z.string().optional(), name: z.string(), path: z.string(), storage_id: z.string(), system_domain_id: z.string().optional(), transcode_profile_ids: z.array(z.string()).optional(), transcription_format: z.enum(["WEBVTT", "SRT"]).optional()}); export const exportLocationsSchema = 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(exportLocationSchema).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 export_locations * * GET /v1/export_locations/ */ export const getApiV1ExportLocations = async (args: GetApiV1ExportLocationsArgs, options: GetApiV1ExportLocationsOptions) => { 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.query != null) query.append("query", String(args.query)) if (args.ids != null) query.append("ids", String(args.ids)) 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.sort != null) query.append("sort", String(args.sort)) if (args.page != null) query.append("page", String(args.page)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/export_locations/${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(exportLocationsSchema, await res.json()) };