export type ResourceId = string; export type RecordSchema = Array<{name?: string | undefined, type?: string | undefined}>; export type PhysicalField = {kind: 'physical', name?: string | undefined, type?: string | undefined}; export type ComputedField = {kind: 'computed', name?: string | undefined, expression?: string | undefined}; export type MetadataField = {kind: 'metadata', name?: string | undefined, type?: string | undefined, key?: string | undefined}; export type SchemaV2 = {fields?: (Array) | undefined, watermarks?: (Array<{name?: string | undefined, expression?: string | undefined}>) | undefined, constraints?: ({primary_key?: Array | undefined}) | undefined}; export type AutoscaleConfiguration = {pause_conditions?: ({[key: string]: string | null} | null) | undefined, resume_conditions?: ({[key: string]: string | null} | null) | undefined} | null; export type ConnectionCommon = {name?: string | undefined, description?: string | undefined, connector?: ('astra-streaming' | 'clickhouse' | 'confluent-cloud' | 'datadog' | 'datagen' | 'delta-lake' | 'druid' | 'dynamodb-cdc' | 'elasticsearch' | 'gcp-pubsub' | 'hudi' | 'influxdb' | 'kafka' | 'kinesis' | 'mongodb' | 'mongodb-cdc' | 'ms-sql' | 'mysql-cdc' | 'oracle' | 'oracle-cdc' | 'pinot' | 'polaris' | 'postgres' | 'postgres-cdc' | 'pulsar' | 'redis' | 'redpanda' | 'redshift' | 'rest' | 'rockset' | 's3' | 's3-lambda' | 's3-v2' | 'singlestore-db' | 'snowflake' | 'startree' | 'streamnative' | 'timescale') | undefined, type?: ('source' | 'sink') | undefined, stream_mappings?: (Array<{stream_id?: ResourceId | undefined, external_resource_specifier: unknown}>) | undefined, stream_id?: ResourceId | undefined, schema?: RecordSchema | undefined, schema_v2?: SchemaV2 | undefined, properties?: ({[key: string]: string | null}) | undefined, autoscale_configuration?: AutoscaleConfiguration | undefined}; export type CreateApiConnectionsArgs = {stream_name?: string | undefined, stream_description?: string | undefined, enable_experimental?: boolean | undefined, response_schema_v?: ('v1' | 'v2') | undefined, body: ConnectionCommon}; export type CreateApiConnectionsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a connection. * * POST /connections * * Also accepts auth: oauth2 */ export const createApiConnections = async (args: CreateApiConnectionsArgs, options?: CreateApiConnectionsOptions) => { const {baseUrl = "https://replace-with-account.api.decodable.co/v1alpha2", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args.stream_name != null) query.append("stream_name", String(args.stream_name)) if (args.stream_description != null) query.append("stream_description", String(args.stream_description)) if (args.enable_experimental != null) query.append("enable_experimental", String(args.enable_experimental)) if (args.response_schema_v != null) query.append("response_schema_v", String(args.response_schema_v)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/connections${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 undefined };