import {z} from 'zod' export type AccountId = string; export type FilePath = string; export type DeleteFileBatchRequest = {files: Array}; export type DeleteApiV2AccountsAccountIdFilesBatchArgs = {accountId: AccountId, body: DeleteFileBatchRequest}; export type DeleteApiV2AccountsAccountIdFilesBatchOptions = {baseUrl?: string | undefined, authorizationHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const accountJobId = z.string().min(26).max(26); export const accountJobType = z.enum(["ProcessImageJob", "ProcessVideoJob", "ProcessAudioJob", "AntivirusJob", "ResetCacheJob", "DeleteFolderBatchJob", "DeleteFileBatchJob", "CopyFolderBatchJob", "CopyFileBatchJob"]); export const jobUrl = z.string().min(1).max(255); export const asyncResponse = z.object({jobDocs: z.literal("https://www.bytescale.com/docs/job-api/GetJob"), jobId: accountJobId, jobType: accountJobType, jobUrl: jobUrl}); 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 }; /** * Deletes multiple files asynchronously. * * Requires a `secret_*` API key. Alternatively, you can use a `public_*` API key and JWT-based auth. * * DELETE /v2/accounts/{accountId}/files/batch */ export const deleteApiV2AccountsAccountIdFilesBatch = async (args: DeleteApiV2AccountsAccountIdFilesBatchArgs, options?: DeleteApiV2AccountsAccountIdFilesBatchOptions) => { const {baseUrl = "https://api.bytescale.com", fetch: fetchFn = fetch, authorizationHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (authorizationHeader !== undefined) headers.set("Authorization", authorizationHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v2/accounts/${encodeURIComponent(String(args.accountId))}/files/batch${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", 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(asyncResponse, await res.json()) };