import {z} from 'zod' export type GetApiConnectorsConnectionConnectionIdArgs = {connectionId: string}; export type GetApiConnectorsConnectionConnectionIdOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const nexusJobStatus = z.enum(["syncing", "synced", "failed", "loading", "ready"]); export const nexusConnectionSchedulingStatus = z.enum(["oneoff", "todo", "scheduling", "scheduled", "failed_to_schedule", "inactive", "paused", "source_unavailable", "active"]); export const nexusSourceType = z.enum(["snowflake", "snowflakeSSO", "snowflakeLiveQuery", "snowflakeSSOLiveQuery", "google-analytics-data-api", "hubspot", "mysql", "postgres", "salesforce", "salesforceReport", "freshsales", "databricks", "databricksDeltaShare", "databricksLiveQuery", "bigquery", "awsathena", "awsredshift", "mssql", "clickhouse", "clickhouseLiveQuery"]); export const nexusUserFacingConnectionInfo = z.object({connectorParams: z.object({}).optional(), created: z.string().optional(), headers: z.record(z.string(), z.array(z.string())).optional(), id: z.string().optional(), jobParams: z.object({}).optional(), latestCompletedAt: z.string().optional(), latestJobStatus: nexusJobStatus.optional(), name: z.string().optional(), nextRun: z.string().optional(), schedule: z.object({}).optional(), schedulingStatus: nexusConnectionSchedulingStatus.optional(), skipNotification: z.boolean().optional(), sourceFolder: z.string().optional(), sourceType: nexusSourceType.optional(), updated: 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 }; /** * Get connection. * * GET /connectors/connection/{connectionId} */ export const getApiConnectorsConnectionConnectionId = async (args: GetApiConnectorsConnectionConnectionIdArgs, options: GetApiConnectorsConnectionConnectionIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-GIGASHEET-TOKEN", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/connectors/connection/${encodeURIComponent(String(args.connectionId))}${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(nexusUserFacingConnectionInfo, await res.json()) };