import {z} from 'zod' export type FsProviders = 0 | 1 | 2 | 3 | 4 | 5 | 6; export type OSFsConfig = {read_buffer_size?: number | undefined, write_buffer_size?: number | undefined}; export type Secret = {status?: ('Plain' | 'AES-256-GCM' | 'Secretbox' | 'GCP' | 'AWS' | 'VaultTransit' | 'AzureKeyVault' | 'Redacted') | undefined, payload?: string | undefined, key?: string | undefined, additional_data?: string | undefined, mode?: number | undefined}; export type S3Config = {bucket?: string | undefined, region?: string | undefined, access_key?: string | undefined, access_secret?: Secret | undefined, role_arn?: string | undefined, session_token?: string | undefined, endpoint?: string | undefined, storage_class?: string | undefined, acl?: string | undefined, upload_part_size?: number | undefined, upload_concurrency?: number | undefined, upload_part_max_time?: number | undefined, download_part_size?: number | undefined, download_concurrency?: number | undefined, download_part_max_time?: number | undefined, force_path_style?: boolean | undefined, key_prefix?: string | undefined}; export type GCSConfig = {bucket?: string | undefined, credentials?: Secret | undefined, automatic_credentials?: (0 | 1) | undefined, storage_class?: string | undefined, acl?: string | undefined, key_prefix?: string | undefined, upload_part_size?: number | undefined, upload_part_max_time?: number | undefined}; export type AzureBlobFsConfig = {container?: string | undefined, account_name?: string | undefined, account_key?: Secret | undefined, sas_url?: Secret | undefined, endpoint?: string | undefined, upload_part_size?: number | undefined, upload_concurrency?: number | undefined, download_part_size?: number | undefined, download_concurrency?: number | undefined, access_tier?: ('' | 'Archive' | 'Hot' | 'Cool') | undefined, key_prefix?: string | undefined, use_emulator?: boolean | undefined}; export type CryptFsConfig = {passphrase?: Secret | undefined, read_buffer_size?: number | undefined, write_buffer_size?: number | undefined}; export type SFTPFsConfig = {endpoint?: string | undefined, username?: string | undefined, password?: Secret | undefined, private_key?: Secret | undefined, key_passphrase?: Secret | undefined, fingerprints?: Array | undefined, prefix?: string | undefined, disable_concurrent_reads?: boolean | undefined, buffer_size?: number | undefined, equality_check_mode?: (0 | 1) | undefined}; export type HTTPFsConfig = {endpoint?: string | undefined, username?: string | undefined, password?: Secret | undefined, api_key?: Secret | undefined, skip_tls_verify?: boolean | undefined, equality_check_mode?: (0 | 1) | undefined}; export type FilesystemConfig = {provider?: FsProviders | undefined, osconfig?: OSFsConfig | undefined, s3config?: S3Config | undefined, gcsconfig?: GCSConfig | undefined, azblobconfig?: AzureBlobFsConfig | undefined, cryptconfig?: CryptFsConfig | undefined, sftpconfig?: SFTPFsConfig | undefined, httpconfig?: HTTPFsConfig | undefined}; export type BaseVirtualFolder = {id?: number | undefined, name?: string | undefined, mapped_path?: string | undefined, description?: string | undefined, used_quota_size?: number | undefined, used_quota_files?: number | undefined, last_quota_update?: number | undefined, users?: Array | undefined, filesystem?: FilesystemConfig | undefined}; export type UpdateApiFoldersNameArgs = {body: BaseVirtualFolder}; export type UpdateApiFoldersNameOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const apiResponse = z.object({message: z.string().optional(), error: 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 folder * * PUT /folders/{name} * * Also accepts auth: APIKeyAuth */ export const updateApiFoldersName = async (args: UpdateApiFoldersNameArgs, options: UpdateApiFoldersNameOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/folders/${encodeURIComponent(String(args.name))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(apiResponse, await res.json()) };