import {z} from 'zod' export type WarehouseConnectInventory = {schemas: Array<{name: string, database: string}>, roles: Array<{isDefault: boolean, name: string}>, warehouses: Array<{state: string | null, size: string | null, name: string}>, databases: Array<{sizeBytes?: (number | null) | undefined, comment: string | null, name: string}>}; export type WarehouseTypesSNOWFLAKE = 'snowflake'; export type SnowflakeAuthenticationType = 'password' | 'private_key' | 'sso' | 'external_browser' | 'oauth_authorization_code' | 'none'; export type WeekDay = number; export type DepositSnowflakeCredentials = {type: WarehouseTypesSNOWFLAKE, user: string, password?: string | undefined, privateKey?: string | undefined, privateKeyPass?: string | undefined, token?: string | undefined, refreshToken?: string | undefined, account: string, requireUserCredentials?: boolean | undefined, authenticationType?: SnowflakeAuthenticationType | undefined, role?: string | undefined, threads?: number | undefined, clientSessionKeepAlive?: boolean | undefined, queryTag?: string | undefined, accessUrl?: string | undefined, startOfWeek?: (WeekDay | null) | undefined, dataTimezone?: string | undefined, quotedIdentifiersIgnoreCase?: boolean | undefined, disableTimestampConversion?: boolean | undefined, timeoutSeconds?: number | undefined, override?: boolean | undefined, organizationWarehouseCredentialsUuid?: string | undefined, database?: string | undefined, warehouse?: string | undefined, schema?: string | undefined}; export type DepositWarehouseConnectionRequest = {inventory: WarehouseConnectInventory | null, credentials: DepositSnowflakeCredentials, code: string}; export type CreateApiApiV1WarehouseConnectDepositArgs = {body: DepositWarehouseConnectionRequest}; export type CreateApiApiV1WarehouseConnectDepositOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const apiDepositWarehouseConnectionResponse = z.object({results: z.unknown(), status: z.literal("ok")}); 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 }; /** * Deposit connection * * POST /api/v1/warehouse-connect/deposit */ export const createApiApiV1WarehouseConnectDeposit = async (args: CreateApiApiV1WarehouseConnectDepositArgs, options: CreateApiApiV1WarehouseConnectDepositOptions) => { 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") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/warehouse-connect/deposit${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(apiDepositWarehouseConnectionResponse, await res.json()) };