import {z} from 'zod' export type AccountId = string; export type FolderPath = string; export type DeleteFolderRequest = {deleteFiles?: boolean | undefined, deleteVirtualFolders?: boolean | undefined, folderPath: FolderPath, recursive?: boolean | undefined}; export type DeleteFolderBatchRequest = {folders: Array}; export type DeleteApiV2AccountsAccountIdFoldersBatchArgs = {accountId: AccountId, body: DeleteFolderBatchRequest}; export type DeleteApiV2AccountsAccountIdFoldersBatchOptions = {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 folders asynchronously. * * You can use ListFolder to preview the operation using the `dryRun` parameter. * * *External storage:* external files are only deleted when you directly delete a file or subfolder of a folder that has external storage configured. If you delete the folder itself, only the mapping is removed. * * Requires a `secret_*` API key. Alternatively, you can use a `public_*` API key and JWT-based auth. * * DELETE /v2/accounts/{accountId}/folders/batch */ export const deleteApiV2AccountsAccountIdFoldersBatch = async (args: DeleteApiV2AccountsAccountIdFoldersBatchArgs, options?: DeleteApiV2AccountsAccountIdFoldersBatchOptions) => { 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))}/folders/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()) };