import { DB_SQL_INITIAL_TEXT, EditorLanguage, FormComponentType, FormItem, InputDataType, Plugin, PluginResponseType, PluginType } from '../../types/index.js'; import { PARAMETERIZED_SQL_DESCRIPTION, PUBLIC_INTEGRATIONS_LOGO_URL, DOCS_BASE_URL } from './constants.js'; import { CONNECTION_METHODS_AND_DISPLAY_NAMES, makeDropdownItem } from './shared/db.js'; export const SnowflakePostgresPluginVersions = { V1: '0.0.1' }; const BASE_HOST = { label: 'Host', name: 'connection.host', componentType: FormComponentType.INPUT_TEXT, placeholder: 'xxxx.us-west-2.aws.postgres.snowflake.app', rules: [{ required: true, message: 'Host is required' }] }; const BASE_PORT = { label: 'Port', name: 'connection.port', componentType: FormComponentType.INPUT_TEXT, dataType: InputDataType.NUMBER, initialValue: 5432, rules: [{ required: true, message: 'Port is required' }] }; const BASE_DATABASE_NAME = { label: 'Database name', name: 'connection.databaseName', componentType: FormComponentType.INPUT_TEXT, rules: [{ required: true, message: 'Database name is required' }] }; const BASE_DATABASE_USERNAME = { label: 'Database username', name: 'connection.username', componentType: FormComponentType.INPUT_TEXT }; const BASE_DATABASE_PASSWORD = { label: 'Database password', name: 'connection.password', componentType: FormComponentType.INPUT_TEXT, dataType: InputDataType.PASSWORD }; const BASE_SELFSIGNED_SSL = { label: 'Use a self-signed SSL certificate', name: 'connection.useSelfSignedSsl', componentType: FormComponentType.CHECKBOX, tooltip: { markdownText: 'Use a self-signed SSL certificate' } }; const BASE_SERVER_CA = { label: 'Server CA', name: 'connection.ca', componentType: FormComponentType.CODE_EDITOR, language: EditorLanguage.TEXT, placeholder: '-----BEGIN CERTIFICATE-----\n' + 'MIIC/jCCAeYCCQDLwS4pIwJC3zANBgkqhkiG9w0BAQsFADBBMQswCQYDVQQGEwJV\n' + '...\n' + '-----END CERTIFICATE-----' }; const BASE_CLIENT_KEY = { label: 'Client key', name: 'connection.key', componentType: FormComponentType.CODE_EDITOR, language: EditorLanguage.TEXT, placeholder: '-----BEGIN RSA PRIVATE KEY-----\n' + 'BAoMBFRlc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCpvozN05Ou\n' + '...\n' + '-----END RSA PRIVATE KEY-----' }; const BASE_CLIENT_CERT = { label: 'Client cert', name: 'connection.cert', componentType: FormComponentType.CODE_EDITOR, language: EditorLanguage.TEXT, placeholder: '-----BEGIN CERTIFICATE-----\n' + 'Ur2LYWdrVjqlS/wJyVIze15FMf7sgl+RINsLbQDLwS4pIwJC3zANBgkqhkiG9w0B\n' + '...\n' + '-----END CERTIFICATE-----' }; export const SnowflakePostgresPlugin: Plugin = { id: 'snowflakepostgres', name: 'Snowflake Postgres', moduleName: 'SnowflakePostgresPlugin', modulePath: 'plugins/snowflakepostgres/SnowflakePostgresPlugin', iconLocation: `${PUBLIC_INTEGRATIONS_LOGO_URL}/snowflake.png`, docsUrl: `${DOCS_BASE_URL}/snowflake-postgres`, type: PluginType.DB, responseType: PluginResponseType.TABLE, hasRawRequest: true, hasMetadata: true, rawRequestName: 'Executed SQL', datasourceTemplate: { sections: [ { name: 'main', items: [ { label: 'Display name', name: 'name', startVersion: SnowflakePostgresPluginVersions.V1, componentType: FormComponentType.INPUT_TEXT, placeholder: 'Snowflake Postgres Production', rules: [{ required: true, message: 'Display name is required' }] }, { label: 'Connection method', name: 'connectionType', startVersion: SnowflakePostgresPluginVersions.V1, componentType: FormComponentType.DROPDOWN, initialValue: 'fields', rules: [{ required: true }], options: Object.entries(CONNECTION_METHODS_AND_DISPLAY_NAMES).map(([value, displayName]) => makeDropdownItem(value, displayName) ) }, { label: 'URI', name: 'connectionUrl', startVersion: SnowflakePostgresPluginVersions.V1, componentType: FormComponentType.DYNAMIC_INPUT_TEXT, placeholder: `postgres://[:user]:[:password]@[:host]:[:port]/[:database]`, tooltip: { markdownText: 'PostgreSQL-compatible connection URI for your Snowflake Postgres instance' }, rules: [{ required: true, message: 'URI is required' }], display: { show: { connectionType: ['url'] } } }, // HOST { ...BASE_HOST, startVersion: SnowflakePostgresPluginVersions.V1, display: { show: { connectionType: ['fields'] } } } as FormItem, // PORT { ...BASE_PORT, startVersion: SnowflakePostgresPluginVersions.V1, display: { show: { connectionType: ['fields'] } } } as FormItem, // DATABASE NAME { ...BASE_DATABASE_NAME, startVersion: SnowflakePostgresPluginVersions.V1, display: { show: { connectionType: ['fields'] } } } as FormItem, // DATABASE USERNAME { ...BASE_DATABASE_USERNAME, startVersion: SnowflakePostgresPluginVersions.V1, display: { show: { connectionType: ['fields'] } } } as FormItem, // DATABASE PASSWORD { ...BASE_DATABASE_PASSWORD, startVersion: SnowflakePostgresPluginVersions.V1, display: { show: { connectionType: ['fields'] } } } as FormItem, // SSL is always enabled for Snowflake - no checkbox shown. // Self-signed SSL certificate option { ...BASE_SELFSIGNED_SSL, startVersion: SnowflakePostgresPluginVersions.V1, display: { show: { connectionType: ['fields'] } } } as FormItem, // SERVER CA { ...BASE_SERVER_CA, startVersion: SnowflakePostgresPluginVersions.V1, display: { show: { 'connection.useSelfSignedSsl': ['true'], connectionType: ['fields'] } } } as FormItem, // CLIENT KEY { ...BASE_CLIENT_KEY, startVersion: SnowflakePostgresPluginVersions.V1, display: { show: { 'connection.useSelfSignedSsl': ['true'], connectionType: ['fields'] } } } as FormItem, // CLIENT CERT { ...BASE_CLIENT_CERT, startVersion: SnowflakePostgresPluginVersions.V1, display: { show: { 'connection.useSelfSignedSsl': ['true'], connectionType: ['fields'] } } } as FormItem ] } ] }, actionTemplate: { sections: [ { name: 'main', items: [ { label: 'Parameters ($1, $2, ...)', name: 'parameters', startVersion: SnowflakePostgresPluginVersions.V1, ldFlag: 'clark.parameterized-apis.v2.enabled', componentType: FormComponentType.DYNAMIC_INPUT_TEXT, placeholder: '[param1, param2, ...]', tooltip: { markdownText: 'JavaScript expression that evaluates to an array of parameter values. Use `$1`, `$2`, etc. in your SQL query to reference these parameters.' } }, { label: '', // Query name: 'body', startVersion: SnowflakePostgresPluginVersions.V1, componentType: FormComponentType.CODE_EDITOR, language: EditorLanguage.SQL, initialValue: DB_SQL_INITIAL_TEXT } ] }, { name: 'advanced:main', items: [ { label: 'Use parameterized SQL', name: 'usePreparedSql', startVersion: SnowflakePostgresPluginVersions.V1, componentType: FormComponentType.SWITCH, initialValue: true, tooltip: { markdownText: PARAMETERIZED_SQL_DESCRIPTION }, display: { show: { parameters: ['undefined'] } } } ] } ] } };