import {z} from 'zod' export type StorageSchema = {default?: boolean | undefined, description?: (string | null) | undefined, id?: string | undefined, last_scanned?: (string | null) | undefined, method: 'FILE' | 'HTTP' | 'FTP' | 'SFTP' | 'S3' | 'B2' | 'GCS' | 'PORTAL' | 'CUSTOM' | 'AZURE' | 'DROPBOX', name: string, purpose: 'KEYFRAMES' | 'FILES' | 'PROXIES' | 'EXPORTS' | 'ARCHIVE' | 'FACES', scanner_status?: (string | null) | undefined, settings: {[key: string]: unknown}, status?: ('ACTIVE' | 'INACTIVE' | 'FAILING') | undefined, status_message?: (string | null) | undefined, version?: string | undefined}; export type PatchApiV1StoragesStorageIdArgs = {'App-ID': string, 'Auth-Token': string, storage_id: string, send_storage_gateway_event?: boolean | undefined, body: StorageSchema}; export type PatchApiV1StoragesStorageIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const storageSchema = z.object({default: z.boolean().optional(), description: z.string().nullable().optional(), id: z.string().optional(), last_scanned: z.string().nullable().optional(), method: z.enum(["FILE", "HTTP", "FTP", "SFTP", "S3", "B2", "GCS", "PORTAL", "CUSTOM", "AZURE", "DROPBOX"]), name: z.string(), purpose: z.enum(["KEYFRAMES", "FILES", "PROXIES", "EXPORTS", "ARCHIVE", "FACES"]), scanner_status: z.string().nullable().optional(), settings: z.record(z.string(), z.unknown()), status: z.enum(["ACTIVE", "INACTIVE", "FAILING"]).optional(), status_message: z.string().nullable().optional(), version: 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 }; /** * Update storage * * PATCH /v1/storages/{storage_id}/ */ export const patchApiV1StoragesStorageId = async (args: PatchApiV1StoragesStorageIdArgs, options: PatchApiV1StoragesStorageIdOptions) => { 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.send_storage_gateway_event != null) query.append("send_storage_gateway_event", String(args.send_storage_gateway_event)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/storages/${encodeURIComponent(String(args.storage_id))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(storageSchema, await res.json()) };