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 CreateApiFoldersArgs = {confidential_data?: number | undefined, body: BaseVirtualFolder}; export type CreateApiFoldersOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const fsProviders = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6)]); export const oSFsConfig = z.object({read_buffer_size: z.number().int().gte(0).lte(10).optional(), write_buffer_size: z.number().int().gte(0).lte(10).optional()}); export const secret = z.object({status: z.enum(["Plain", "AES-256-GCM", "Secretbox", "GCP", "AWS", "VaultTransit", "AzureKeyVault", "Redacted"]).optional(), payload: z.string().optional(), key: z.string().optional(), additional_data: z.string().optional(), mode: z.number().int().optional()}); export const s3Config = z.object({bucket: z.string().min(1).optional(), region: z.string().min(1).optional(), access_key: z.string().optional(), access_secret: secret.optional(), role_arn: z.string().optional(), session_token: z.string().optional(), endpoint: z.string().optional(), storage_class: z.string().optional(), acl: z.string().optional(), upload_part_size: z.number().int().optional(), upload_concurrency: z.number().int().optional(), upload_part_max_time: z.number().int().optional(), download_part_size: z.number().int().optional(), download_concurrency: z.number().int().optional(), download_part_max_time: z.number().int().optional(), force_path_style: z.boolean().optional(), key_prefix: z.string().optional()}); export const gCSConfig = z.object({bucket: z.string().min(1).optional(), credentials: secret.optional(), automatic_credentials: z.union([z.literal(0), z.literal(1)]).optional(), storage_class: z.string().optional(), acl: z.string().optional(), key_prefix: z.string().optional(), upload_part_size: z.number().int().optional(), upload_part_max_time: z.number().int().optional()}); export const azureBlobFsConfig = z.object({container: z.string().optional(), account_name: z.string().optional(), account_key: secret.optional(), sas_url: secret.optional(), endpoint: z.string().optional(), upload_part_size: z.number().int().optional(), upload_concurrency: z.number().int().optional(), download_part_size: z.number().int().optional(), download_concurrency: z.number().int().optional(), access_tier: z.enum(["", "Archive", "Hot", "Cool"]).optional(), key_prefix: z.string().optional(), use_emulator: z.boolean().optional()}); export const cryptFsConfig = z.object({passphrase: secret.optional(), read_buffer_size: z.number().int().gte(0).lte(10).optional(), write_buffer_size: z.number().int().gte(0).lte(10).optional()}); export const sFTPFsConfig = z.object({endpoint: z.string().optional(), username: z.string().optional(), password: secret.optional(), private_key: secret.optional(), key_passphrase: secret.optional(), fingerprints: z.array(z.string()).optional(), prefix: z.string().optional(), disable_concurrent_reads: z.boolean().optional(), buffer_size: z.number().int().gte(0).lte(16).optional(), equality_check_mode: z.union([z.literal(0), z.literal(1)]).optional()}); export const hTTPFsConfig = z.object({endpoint: z.string().optional(), username: z.string().optional(), password: secret.optional(), api_key: secret.optional(), skip_tls_verify: z.boolean().optional(), equality_check_mode: z.union([z.literal(0), z.literal(1)]).optional()}); export const filesystemConfig = z.object({provider: fsProviders.optional(), osconfig: oSFsConfig.optional(), s3config: s3Config.optional(), gcsconfig: gCSConfig.optional(), azblobconfig: azureBlobFsConfig.optional(), cryptconfig: cryptFsConfig.optional(), sftpconfig: sFTPFsConfig.optional(), httpconfig: hTTPFsConfig.optional()}); export const baseVirtualFolder = z.object({id: z.number().int().gte(1).optional(), name: z.string().optional(), mapped_path: z.string().optional(), description: z.string().optional(), used_quota_size: z.number().int().optional(), used_quota_files: z.number().int().optional(), last_quota_update: z.number().int().optional(), users: z.array(z.string()).optional(), filesystem: filesystemConfig.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 }; /** * Add folder * * POST /folders * * Also accepts auth: APIKeyAuth */ export const createApiFolders = async (args: CreateApiFoldersArgs, options: CreateApiFoldersOptions) => { 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 (args.confidential_data != null) query.append("confidential_data", String(args.confidential_data)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/folders${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(baseVirtualFolder, await res.json()) };