import {z} from 'zod' export type UpdatePasswordAuth = {username?: string | undefined, password?: string | undefined}; export type SSHTunnelParams = {ssh_tunnel_host: string, ssh_tunnel_port: number, ssh_tunnel_username: string, ssh_public_key?: ('primary_public_key' | 'secondary_public_key') | undefined}; export type UpdatePostgresSourceOptions = {host?: string | undefined, port?: number | undefined, database?: string | undefined, auth_method?: 'password_auth' | undefined, password_auth?: UpdatePasswordAuth | undefined, use_ssh_tunnel?: boolean | undefined, ssh_tunnel?: SSHTunnelParams | undefined, disable_ssl?: boolean | undefined}; export type UpdateRedshiftAccessKeys = {password: string, access_id: string, secret_key: string}; export type AWSIAMRole = {aws_iam_role_arn: string}; export type UpdateRedshiftSourceOptions = {host?: string | undefined, port?: number | undefined, database?: string | undefined, cluster?: string | undefined, region?: string | undefined, workgroup?: string | undefined, username?: string | undefined, auth_method?: ('aws_iam_role' | 'aws_access_keys') | undefined, aws_access_keys?: UpdateRedshiftAccessKeys | undefined, aws_iam_role?: AWSIAMRole | undefined, use_ssh_tunnel?: boolean | undefined, ssh_tunnel?: SSHTunnelParams | undefined, disable_ssl?: boolean | undefined, connection_timeout_in_seconds?: number | undefined}; export type UpdateRedshiftServerlessSourceOptions = {host?: string | undefined, port?: number | undefined, database?: string | undefined, workgroup?: string | undefined, region?: string | undefined, auth_method?: ('aws_iam_role' | 'aws_access_keys') | undefined, aws_access_keys?: UpdateRedshiftAccessKeys | undefined, aws_iam_role?: AWSIAMRole | undefined, use_ssh_tunnel?: boolean | undefined, ssh_tunnel?: SSHTunnelParams | undefined, disable_ssl?: boolean | undefined, connection_timeout_in_seconds?: number | undefined}; export type CredentialSource = {environment_id: string, region_url: string, url: string, regional_cred_verification_url: string}; export type GcpExternalAccountMetadata = {type: string, audience: string, subject_token_type: string, service_account_impersonation_url: string, token_url: string, credential_source: CredentialSource}; export type UpdateGCPServiceAccountRole = {service_account_email?: string | undefined, workload_identity_federation_metadata?: GcpExternalAccountMetadata | undefined}; export type UpdateFederatedGCPServiceAccountRole = {service_account_email: string, workload_identity_federation_metadata?: GcpExternalAccountMetadata | undefined}; export type UpdateGCPSourceServiceAccountKey = {service_account_email?: string | undefined, service_account_key: unknown}; export type UpdateBigQuerySourceOptions = {project_id?: string | undefined, region?: string | undefined, auth_method?: ('gcp_service_account_role' | 'gcp_service_account_key' | 'federated_gcp_service_account_role') | undefined, gcp_service_account_role?: UpdateGCPServiceAccountRole | undefined, federated_gcp_service_account_role?: UpdateFederatedGCPServiceAccountRole | undefined, gcp_service_account_key?: UpdateGCPSourceServiceAccountKey | undefined}; export type UpdateAWSAccessKeys = {access_id?: string | undefined, secret_key?: string | undefined}; export type UpdateS3SourceOptions = {bucket_name?: string | undefined, region?: string | undefined, auth_method?: ('aws_iam_role' | 'aws_access_keys') | undefined, aws_iam_role?: AWSIAMRole | undefined, aws_access_keys?: UpdateAWSAccessKeys | undefined, bucket_host?: string | undefined, use_ssh_tunnel?: boolean | undefined, ssh_tunnel?: SSHTunnelParams | undefined}; export type UpdateAzureServiceSharedAccessSignature = {shared_access_signature_token?: string | undefined}; export type UpdateABSSourceOptions = {bucket_name?: string | undefined, storage_account_name?: string | undefined, auth_method?: 'azure_service_shared_access_signature' | undefined, azure_service_shared_access_signature?: UpdateAzureServiceSharedAccessSignature | undefined}; export type UpdatePublicKeyAuth = {public_key?: string | undefined}; export type UpdateSFTPSourceOptions = {username?: string | undefined, host?: string | undefined, port?: number | undefined, auth_method?: 'public_key_auth' | undefined, public_key_auth?: UpdatePublicKeyAuth | undefined}; export type UpdateGCSAccessKeys = {access_key?: string | undefined, secret?: string | undefined}; export type UpdateGCSSourceOptions = {bucket_name?: string | undefined, region?: string | undefined, auth_method?: ('gcp_service_account_role' | 'federated_gcp_service_account_role' | 'gcs_hmac_keys' | 'gcp_service_account_key') | undefined, gcp_service_account_role?: UpdateGCPServiceAccountRole | undefined, federated_gcp_service_account_role?: UpdateFederatedGCPServiceAccountRole | undefined, gcs_hmac_keys?: UpdateGCSAccessKeys | undefined, gcp_service_account_key?: UpdateGCPSourceServiceAccountKey | undefined}; export type UpdateS3CompatibleSourceOptions = {host?: string | undefined, port?: number | undefined, bucket_name?: string | undefined, auth_method?: 'access_keys' | undefined, aws_access_keys?: UpdateAWSAccessKeys | undefined, disable_ssl?: boolean | undefined, use_ssh_tunnel?: boolean | undefined, ssh_tunnel?: SSHTunnelParams | undefined}; export type UpdateSnowflakeSourceOptions = {host?: string | undefined, port?: number | undefined, database?: string | undefined, username?: string | undefined, auth_method?: 'public_key_auth' | undefined, public_key_auth?: UpdatePublicKeyAuth | undefined}; export type BearerTokenAuth = {bearer_token: string}; export type OAuthAuth = {client_id: string, client_secret: string}; export type UpdateDeltaSharingSourceOptions = {host?: string | undefined, port?: number | undefined, auth_method?: ('bearer_token' | 'oauth2') | undefined, bearer_token?: BearerTokenAuth | undefined, oauth2?: OAuthAuth | undefined}; export type UpdateSourceOptions = {name?: string | undefined, vendor?: string | undefined, postgres?: UpdatePostgresSourceOptions | undefined, redshift?: UpdateRedshiftSourceOptions | undefined, redshift_serverless?: UpdateRedshiftServerlessSourceOptions | undefined, bigquery?: UpdateBigQuerySourceOptions | undefined, s3?: UpdateS3SourceOptions | undefined, abs?: UpdateABSSourceOptions | undefined, sftp?: UpdateSFTPSourceOptions | undefined, gcs?: UpdateGCSSourceOptions | undefined, s3_compatible?: UpdateS3CompatibleSourceOptions | undefined, snowflake?: UpdateSnowflakeSourceOptions | undefined, delta_sharing?: UpdateDeltaSharingSourceOptions | undefined}; export type TestSourceRequest = {source?: UpdateSourceOptions | undefined}; export type CreateApiImportSourcesIdTestSourceArgs = {id: string, body: TestSourceRequest}; export type CreateApiImportSourcesIdTestSourceOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const testSourceResponse = z.object({code: z.string().optional(), message: z.string().optional()}); export const createApiImportSourcesIdTestSourceResponse = z.object({status: z.literal("success"), data: testSourceResponse, message: z.string()}); 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 }; /** * Test import source * * POST /import/sources/{id}/test-source */ export const createApiImportSourcesIdTestSource = async (args: CreateApiImportSourcesIdTestSourceArgs, options?: CreateApiImportSourcesIdTestSourceOptions) => { const {baseUrl = "https://api.prequel.co", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/import/sources/${encodeURIComponent(String(args.id))}/test-source${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(createApiImportSourcesIdTestSourceResponse, await res.json()) };