import {z} from 'zod' export type RedshiftAuthenticationType = 'password' | 'iam' | 'iam_browser'; export type WeekDay = number; export type WarehouseTypesREDSHIFT = 'redshift'; export type CreateRedshiftCredentials = {sshTunnelPrivateKey?: string | undefined, sshTunnelPublicKey?: string | undefined, sshTunnelUser?: string | undefined, sshTunnelPort?: number | undefined, sshTunnelHost?: string | undefined, useSshTunnel?: boolean | undefined, awsSsoRoleName?: string | undefined, awsSsoAccountId?: string | undefined, awsSsoRegion?: string | undefined, awsSsoStartUrl?: string | undefined, assumeRoleExternalId?: string | undefined, assumeRoleArn?: string | undefined, sessionToken?: string | undefined, secretAccessKey?: string | undefined, accessKeyId?: string | undefined, dbGroups?: Array | undefined, autoCreate?: boolean | undefined, workgroupName?: string | undefined, clusterIdentifier?: string | undefined, isServerless?: boolean | undefined, region?: string | undefined, authenticationType?: RedshiftAuthenticationType | undefined, timeoutSeconds?: number | undefined, dataTimezone?: string | undefined, startOfWeek?: (WeekDay | null) | undefined, ra3Node?: boolean | undefined, sslmode?: string | undefined, keepalivesIdle?: number | undefined, threads?: number | undefined, schema: string, dbname: string, port: number, requireUserCredentials?: boolean | undefined, password?: string | undefined, user: string, host: string, type: WarehouseTypesREDSHIFT}; export type BigqueryAuthenticationType = 'sso' | 'private_key' | 'adc'; export type WarehouseTypesBIGQUERY = 'bigquery'; export type CreateBigqueryCredentials = {accessUrl?: string | undefined, executionProject?: string | undefined, dataTimezone?: string | undefined, startOfWeek?: (WeekDay | null) | undefined, maximumBytesBilled?: number | undefined, location?: string | undefined, retries?: number | undefined, requireUserCredentials?: boolean | undefined, keyfileContents: {[key: string]: string}, authenticationType?: BigqueryAuthenticationType | undefined, priority?: ('interactive' | 'batch') | undefined, timeoutSeconds?: number | undefined, threads?: number | undefined, dataset: string, project: string, type: WarehouseTypesBIGQUERY}; export type WarehouseTypesPOSTGRES = 'postgres'; export type CreatePostgresCredentials = {sshTunnelPrivateKey?: string | undefined, sshTunnelPublicKey?: string | undefined, sshTunnelUser?: string | undefined, sshTunnelPort?: number | undefined, sshTunnelHost?: string | undefined, useSshTunnel?: boolean | undefined, sslrootcert?: (string | null) | undefined, sslrootcertFileName?: string | undefined, sslkey?: (string | null) | undefined, sslkeyFileName?: string | undefined, sslcert?: (string | null) | undefined, sslcertFileName?: string | undefined, sslmode?: string | undefined, timeoutSeconds?: number | undefined, dataTimezone?: string | undefined, startOfWeek?: (WeekDay | null) | undefined, role?: string | undefined, searchPath?: string | undefined, keepalivesIdle?: number | undefined, threads?: number | undefined, schema: string, dbname: string, port: number, requireUserCredentials?: boolean | undefined, password: string, user: string, host: string, type: WarehouseTypesPOSTGRES}; export type SnowflakeAuthenticationType = 'password' | 'private_key' | 'sso' | 'external_browser' | 'oauth_authorization_code' | 'none'; export type WarehouseTypesSNOWFLAKE = 'snowflake'; export type CreateSnowflakeCredentials = {organizationWarehouseCredentialsUuid?: string | undefined, override?: boolean | undefined, timeoutSeconds?: number | undefined, disableTimestampConversion?: boolean | undefined, quotedIdentifiersIgnoreCase?: boolean | undefined, dataTimezone?: string | undefined, startOfWeek?: (WeekDay | null) | undefined, accessUrl?: string | undefined, queryTag?: string | undefined, clientSessionKeepAlive?: boolean | undefined, threads?: number | undefined, schema: string, warehouse: string, database: string, role?: string | undefined, token?: string | undefined, refreshToken?: string | undefined, authenticationType?: SnowflakeAuthenticationType | undefined, privateKeyPass?: string | undefined, privateKey?: string | undefined, requireUserCredentials?: boolean | undefined, password?: string | undefined, user: string, account: string, type: WarehouseTypesSNOWFLAKE}; export type DatabricksAuthenticationType = 'personal_access_token' | 'oauth_m2m' | 'oauth_u2m'; export type WarehouseTypesDATABRICKS = 'databricks'; export type CreateDatabricksCredentials = {compute?: Array<{httpPath: string, name: string}> | undefined, dataTimezone?: string | undefined, startOfWeek?: (WeekDay | null) | undefined, requireUserCredentials?: boolean | undefined, oauthClientSecret?: string | undefined, oauthClientId?: string | undefined, token?: string | undefined, refreshToken?: string | undefined, personalAccessToken?: string | undefined, authenticationType?: DatabricksAuthenticationType | undefined, httpPath: string, serverHostName: string, database: string, catalog?: string | undefined, type: WarehouseTypesDATABRICKS}; export type WarehouseTypesTRINO = 'trino'; export type CreateTrinoCredentials = {dataTimezone?: string | undefined, startOfWeek?: (WeekDay | null) | undefined, source?: string | undefined, http_scheme: string, schema: string, dbname: string, port: number, requireUserCredentials?: boolean | undefined, password: string, user: string, host: string, type: WarehouseTypesTRINO}; export type WarehouseTypesCLICKHOUSE = 'clickhouse'; export type CreateClickhouseCredentials = {timeoutSeconds?: number | undefined, dataTimezone?: string | undefined, startOfWeek?: (WeekDay | null) | undefined, secure?: boolean | undefined, schema: string, port: number, requireUserCredentials?: boolean | undefined, password: string, user: string, host: string, type: WarehouseTypesCLICKHOUSE}; export type AthenaAuthenticationType = 'access_key' | 'iam_role'; export type WarehouseTypesATHENA = 'athena'; export type CreateAthenaCredentials = {dataTimezone?: string | undefined, startOfWeek?: (WeekDay | null) | undefined, requireUserCredentials?: boolean | undefined, numRetries?: number | undefined, threads?: number | undefined, workGroup?: string | undefined, assumeRoleExternalId?: string | undefined, assumeRoleArn?: string | undefined, sessionToken?: string | undefined, secretAccessKey?: string | undefined, accessKeyId?: string | undefined, authenticationType?: AthenaAuthenticationType | undefined, s3DataDir?: string | undefined, s3StagingDir: string, schema: string, database: string, region: string, type: WarehouseTypesATHENA}; export type DuckdbConnectionTypeMOTHERDUCK = 'motherduck'; export type WarehouseTypesDUCKDB = 'duckdb'; export type CreateDuckdbMotherduckCredentials = {dataTimezone?: string | undefined, startOfWeek?: (WeekDay | null) | undefined, requireUserCredentials?: boolean | undefined, threads?: number | undefined, token: string, schema: string, database: string, connectionType: DuckdbConnectionTypeMOTHERDUCK, type: WarehouseTypesDUCKDB}; export type DucklakeDataPathTypeS3 = 's3'; export type CreateDucklakeDataPathS3 = {useSsl?: boolean | undefined, forcePathStyle?: boolean | undefined, secretAccessKey?: string | undefined, accessKeyId?: string | undefined, region?: string | undefined, endpoint?: string | undefined, url: string, type: DucklakeDataPathTypeS3}; export type DucklakeDataPathTypeGCS = 'gcs'; export type CreateDucklakeDataPathGcs = {hmacSecret?: string | undefined, hmacKeyId?: string | undefined, url: string, type: DucklakeDataPathTypeGCS}; export type DucklakeDataPathTypeAZURE = 'azure'; export type CreateDucklakeDataPathAzure = {accountKey?: string | undefined, accountName?: string | undefined, connectionString?: string | undefined, url: string, type: DucklakeDataPathTypeAZURE}; export type DucklakeDataPathTypeLOCAL = 'local'; export type CreateDucklakeDataPathLocal = {path: string, type: DucklakeDataPathTypeLOCAL}; export type CreateDucklakeDataPath = CreateDucklakeDataPathS3 | CreateDucklakeDataPathGcs | CreateDucklakeDataPathAzure | CreateDucklakeDataPathLocal; export type DucklakeCatalogTypePOSTGRES = 'postgres'; export type CreateDucklakeCatalogPostgres = {password: string, user: string, database: string, port: number, host: string, type: DucklakeCatalogTypePOSTGRES}; export type DucklakeCatalogTypeSQLITE = 'sqlite'; export type CreateDucklakeCatalogSqlite = {path: string, type: DucklakeCatalogTypeSQLITE}; export type DucklakeCatalogTypeDUCKDB = 'duckdb'; export type CreateDucklakeCatalogDuckdb = {path: string, type: DucklakeCatalogTypeDUCKDB}; export type CreateDucklakeCatalog = CreateDucklakeCatalogPostgres | CreateDucklakeCatalogSqlite | CreateDucklakeCatalogDuckdb; export type DuckdbConnectionTypeDUCKLAKE = 'ducklake'; export type CreateDuckdbDucklakeCredentials = {dataTimezone?: string | undefined, startOfWeek?: (WeekDay | null) | undefined, requireUserCredentials?: boolean | undefined, threads?: number | undefined, catalogAlias?: string | undefined, schema: string, dataPath: CreateDucklakeDataPath, catalog: CreateDucklakeCatalog, connectionType: DuckdbConnectionTypeDUCKLAKE, type: WarehouseTypesDUCKDB}; export type DuckdbConnectionTypeEMBEDDED = 'embedded'; export type CreateDuckdbEmbeddedCredentials = {schema?: string | undefined, startOfWeek?: number | undefined, dataTimezone?: string | undefined, requireUserCredentials?: boolean | undefined, dataset: string, connectionType: DuckdbConnectionTypeEMBEDDED, type: WarehouseTypesDUCKDB}; export type CreateDuckdbCredentials = CreateDuckdbMotherduckCredentials | CreateDuckdbDucklakeCredentials | CreateDuckdbEmbeddedCredentials; export type CreateWarehouseCredentials = CreateRedshiftCredentials | CreateBigqueryCredentials | CreatePostgresCredentials | CreateSnowflakeCredentials | CreateDatabricksCredentials | CreateTrinoCredentials | CreateClickhouseCredentials | CreateAthenaCredentials | CreateDuckdbCredentials; export type WarehouseTypes = 'bigquery' | 'postgres' | 'redshift' | 'snowflake' | 'databricks' | 'trino' | 'clickhouse' | 'athena' | 'duckdb'; export type DataTimezonePreviewRequest = {credentials: CreateWarehouseCredentials, mode: 'create'} | {dataTimezone: string | null, warehouseType: WarehouseTypes, projectUuid: string, mode: 'edit'}; export type CreateApiApiV1ProjectsPreviewDataTimezoneArgs = {body: DataTimezonePreviewRequest}; export type CreateApiApiV1ProjectsPreviewDataTimezoneOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const dataTimezonePreviewAware = z.object({rendered: z.string(), raw: z.string()}); export const dataTimezonePreviewNaive = z.object({rendered: z.string(), readAs: z.string(), raw: z.string(), interpretedAs: z.string()}); export const apiDataTimezonePreviewResults = z.object({aware: dataTimezonePreviewAware, naive: dataTimezonePreviewNaive, dataTimezoneApplies: z.boolean(), projectTimezone: z.string()}); export const apiDataTimezonePreview = z.object({results: apiDataTimezonePreviewResults, 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 }; /** * Preview data timezone * * POST /api/v1/projects/preview-data-timezone */ export const createApiApiV1ProjectsPreviewDataTimezone = async (args: CreateApiApiV1ProjectsPreviewDataTimezoneArgs, options: CreateApiApiV1ProjectsPreviewDataTimezoneOptions) => { 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/projects/preview-data-timezone${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(apiDataTimezonePreview, await res.json()) };