import {z} from 'zod' export type GetApiApiV1ProjectsProjectUuidUserWarehouseCredentialsArgs = {projectUuid: string}; export type GetApiApiV1ProjectsProjectUuidUserWarehouseCredentialsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const projectType = z.enum(["DEFAULT", "PREVIEW"]); export const userWarehouseCredentialsProject = z.object({type: projectType, name: z.string(), projectUuid: z.string()}); export const warehouseTypesREDSHIFT = z.literal("redshift"); export const redshiftAuthenticationType = z.enum(["password", "iam", "iam_browser"]); export const pickCreateRedshiftCredentialsTypeOrUserOrAuthenticationTypeOrAssumeRoleArn = z.object({type: warehouseTypesREDSHIFT, user: z.string(), authenticationType: redshiftAuthenticationType.optional(), assumeRoleArn: z.string().optional()}); export const warehouseTypesPOSTGRES = z.literal("postgres"); export const warehouseTypesSNOWFLAKE = z.literal("snowflake"); export const warehouseTypesTRINO = z.literal("trino"); export const warehouseTypesCLICKHOUSE = z.literal("clickhouse"); export const pickCreatePostgresCredentialsOrCreateSnowflakeCredentialsOrCreateTrinoCredentialsOrCreateClickhouseCredentialsTypeOrUser = z.object({type: z.union([warehouseTypesPOSTGRES, warehouseTypesSNOWFLAKE, warehouseTypesTRINO, warehouseTypesCLICKHOUSE]), user: z.string()}); export const warehouseTypesBIGQUERY = z.literal("bigquery"); export const pickCreateBigqueryCredentialsType = z.object({type: warehouseTypesBIGQUERY}); export const warehouseTypesDATABRICKS = z.literal("databricks"); export const pickCreateDatabricksCredentialsType = z.object({type: warehouseTypesDATABRICKS}); export const warehouseTypesATHENA = z.literal("athena"); export const pickCreateAthenaCredentialsType = z.object({type: warehouseTypesATHENA}); export const warehouseTypesDUCKDB = z.literal("duckdb"); export const pickCreateDuckdbCredentialsType = z.object({type: warehouseTypesDUCKDB}); export const userWarehouseCredentials = z.object({project: userWarehouseCredentialsProject.nullable(), credentials: z.union([pickCreateRedshiftCredentialsTypeOrUserOrAuthenticationTypeOrAssumeRoleArn, pickCreatePostgresCredentialsOrCreateSnowflakeCredentialsOrCreateTrinoCredentialsOrCreateClickhouseCredentialsTypeOrUser, pickCreateBigqueryCredentialsType, pickCreateDatabricksCredentialsType, pickCreateAthenaCredentialsType, pickCreateDuckdbCredentialsType]), updatedAt: z.string(), createdAt: z.string(), name: z.string(), userUuid: z.string(), uuid: z.string()}); export const getApiApiV1ProjectsProjectUuidUserWarehouseCredentialsResponse = z.object({results: z.array(userWarehouseCredentials), 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 }; /** * List project user warehouse credentials * * GET /api/v1/projects/{projectUuid}/user-warehouse-credentials */ export const getApiApiV1ProjectsProjectUuidUserWarehouseCredentials = async (args: GetApiApiV1ProjectsProjectUuidUserWarehouseCredentialsArgs, options: GetApiApiV1ProjectsProjectUuidUserWarehouseCredentialsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/projects/${encodeURIComponent(String(args.projectUuid))}/user-warehouse-credentials${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiV1ProjectsProjectUuidUserWarehouseCredentialsResponse, await res.json()) };