@tetrascience-npm/tetrascience-react-ui 0.4.0-beta.8.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +58 -4
  2. package/dist/athena.d.ts +167 -0
  3. package/dist/databricks.d.ts +129 -0
  4. package/dist/exceptions-DN25pCDi.cjs +2 -0
  5. package/dist/exceptions-DN25pCDi.cjs.map +1 -0
  6. package/dist/exceptions-jCQ6h5C8.js +33 -0
  7. package/dist/exceptions-jCQ6h5C8.js.map +1 -0
  8. package/dist/index.cjs +2021 -0
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.css +1 -1
  11. package/dist/index.d.ts +2165 -1733
  12. package/dist/index.js +9461 -2
  13. package/dist/index.js.map +1 -0
  14. package/dist/logo.png +0 -0
  15. package/dist/providers/athena.cjs +2 -0
  16. package/dist/providers/athena.cjs.map +1 -0
  17. package/dist/providers/athena.d.ts +7 -77
  18. package/dist/providers/athena.js +160 -0
  19. package/dist/providers/athena.js.map +1 -0
  20. package/dist/providers/databricks.cjs +2 -0
  21. package/dist/providers/databricks.cjs.map +1 -0
  22. package/dist/providers/databricks.d.ts +7 -41
  23. package/dist/providers/databricks.js +85 -0
  24. package/dist/providers/databricks.js.map +1 -0
  25. package/dist/providers/snowflake.cjs +2 -0
  26. package/dist/providers/snowflake.cjs.map +1 -0
  27. package/dist/providers/snowflake.d.ts +7 -38
  28. package/dist/providers/snowflake.js +122 -0
  29. package/dist/providers/snowflake.js.map +1 -0
  30. package/dist/server.cjs +2 -0
  31. package/dist/server.cjs.map +1 -0
  32. package/dist/server.d.ts +537 -522
  33. package/dist/server.js +266 -0
  34. package/dist/server.js.map +1 -0
  35. package/dist/{providers/types-Ck4uFaGp.d.ts → snowflake.d.ts} +125 -82
  36. package/dist/vite.svg +1 -0
  37. package/package.json +32 -52
  38. package/dist/cjs/index.js +0 -2001
  39. package/dist/cjs/index.js.map +0 -1
  40. package/dist/cjs/providers/athena.js +0 -2
  41. package/dist/cjs/providers/athena.js.map +0 -1
  42. package/dist/cjs/providers/databricks.js +0 -2
  43. package/dist/cjs/providers/databricks.js.map +0 -1
  44. package/dist/cjs/providers/exceptions-CYktpdqW.js +0 -2
  45. package/dist/cjs/providers/exceptions-CYktpdqW.js.map +0 -1
  46. package/dist/cjs/providers/snowflake.js +0 -2
  47. package/dist/cjs/providers/snowflake.js.map +0 -1
  48. package/dist/cjs/server.js +0 -2
  49. package/dist/cjs/server.js.map +0 -1
  50. package/dist/esm/index.js +0 -2001
  51. package/dist/esm/index.js.map +0 -1
  52. package/dist/esm/providers/athena.js +0 -2
  53. package/dist/esm/providers/athena.js.map +0 -1
  54. package/dist/esm/providers/databricks.js +0 -2
  55. package/dist/esm/providers/databricks.js.map +0 -1
  56. package/dist/esm/providers/exceptions-C3uFWZB2.js +0 -2
  57. package/dist/esm/providers/exceptions-C3uFWZB2.js.map +0 -1
  58. package/dist/esm/providers/snowflake.js +0 -2
  59. package/dist/esm/providers/snowflake.js.map +0 -1
  60. package/dist/esm/server.js +0 -2
  61. package/dist/esm/server.js.map +0 -1
package/dist/server.d.ts CHANGED
@@ -1,525 +1,540 @@
1
- import { TDPClient } from '@tetrascience-npm/ts-connectors-sdk';
2
- import * as snowflake_sdk from 'snowflake-sdk';
3
- import * as _databricks_sql_dist_contracts_IDBSQLSession from '@databricks/sql/dist/contracts/IDBSQLSession';
4
- import * as _databricks_sql from '@databricks/sql';
5
- import * as _aws_sdk_client_athena from '@aws-sdk/client-athena';
1
+ import { AthenaClient as AthenaClient_2 } from '@aws-sdk/client-athena';
2
+ import { awsSdkClientAthena } from '@aws-sdk/client-athena';
3
+ import { Connection } from 'snowflake-sdk';
4
+ import { DBSQLClient as DBSQLClient_2 } from '@databricks/sql';
5
+ import { default as default_2 } from '@databricks/sql/dist/contracts/IDBSQLSession';
6
+ import { TDPClient } from '@tetrascience-npm/ts-connectors-sdk';
7
+
8
+ /**
9
+ * Athena Data Provider
10
+ *
11
+ * TypeScript equivalent of AthenaProvider from
12
+ * ts-lib-ui-kit-streamlit/tetrascience/data_app_providers/provider.py
13
+ *
14
+ * @remarks
15
+ * This provider requires the `@aws-sdk/client-athena` package to be installed.
16
+ * It is an optional peer dependency - install it only if you need Athena support:
17
+ * ```bash
18
+ * npm install @aws-sdk/client-athena
19
+ * # or
20
+ * yarn add @aws-sdk/client-athena
21
+ * ```
22
+ */
23
+ declare type AthenaClient = AthenaClient_2;
24
+
25
+ /**
26
+ * Athena data provider
27
+ */
28
+ export declare class AthenaProvider {
29
+ private client;
30
+ private sdk;
31
+ private workgroup;
32
+ private database;
33
+ private outputLocation?;
34
+ /**
35
+ * Initialize the Athena data provider
36
+ *
37
+ * @param client - AWS Athena client
38
+ * @param sdk - AWS Athena SDK module (for accessing command classes)
39
+ * @param workgroup - Athena workgroup to use
40
+ * @param database - Default database/schema
41
+ * @param outputLocation - Optional S3 output location
42
+ */
43
+ constructor(client: AthenaClient, sdk: AthenaSDK, workgroup: string, database: string, outputLocation?: string);
44
+ /**
45
+ * Query the Athena database
46
+ *
47
+ * @param sqlQuery - SQL query to execute
48
+ * @param _params - Parameters to pass to the query (currently not used - Athena doesn't support parameterized queries)
49
+ * @returns Promise resolving to array of row objects
50
+ *
51
+ * @remarks
52
+ * **Security Note:** AWS Athena does not support parameterized queries.
53
+ * Unlike traditional databases, there is no native way to use bind parameters
54
+ * with Athena. Callers are responsible for properly sanitizing any user input
55
+ * before constructing the SQL query string. This is a known limitation of the
56
+ * Athena service, not a design flaw in this implementation.
57
+ */
58
+ query(sqlQuery: string, _params?: Record<string, unknown>): Promise<Array<Record<string, unknown>>>;
59
+ /**
60
+ * Wait for query to complete
61
+ */
62
+ private waitForQueryCompletion;
63
+ /**
64
+ * Fetch all results from a completed query
65
+ */
66
+ private fetchAllResults;
67
+ /**
68
+ * Close the Athena client (no-op for AWS SDK clients)
69
+ */
70
+ close(): Promise<void>;
71
+ }
72
+
73
+ declare type AthenaSDK = awsSdkClientAthena;
74
+
75
+ /**
76
+ * Build a Databricks data provider from the configuration
77
+ *
78
+ * @param config - Provider configuration
79
+ * @returns Promise resolving to Databricks data provider
80
+ * @throws {InvalidProviderConfigurationError} If @databricks/sql is not installed or config is invalid
81
+ */
82
+ export declare function buildDatabricksProvider(config: ProviderConfiguration): Promise<DatabricksProvider>;
83
+
84
+ /**
85
+ * Build a data provider from the configuration
86
+ *
87
+ * The return type is a union of specific provider types. More provider types
88
+ * may be added in the future.
89
+ *
90
+ * @param config - Provider configuration
91
+ * @returns Promise resolving to the appropriate data provider
92
+ * @throws {InvalidProviderConfigurationError} If the provider type is not supported
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * import { TDPClient } from '@tetrascience-npm/ts-connectors-sdk';
97
+ * import { buildProvider, getProviderConfigurations } from '@tetrascience-npm/tetrascience-react-ui/server';
98
+ *
99
+ * // Other fields (tdpEndpoint, connectorId, orgSlug) are read from environment variables
100
+ * const client = new TDPClient({
101
+ * authToken: userJwt,
102
+ * artifactType: "data-app",
103
+ * });
104
+ * await client.init();
105
+ * const configs = await getProviderConfigurations(client);
106
+ *
107
+ * const snowflakeConfig = configs.find(c => c.type === 'snowflake');
108
+ * if (snowflakeConfig) {
109
+ * const provider = await buildProvider(snowflakeConfig);
110
+ * const results = await provider.query('SELECT * FROM my_table');
111
+ * }
112
+ * ```
113
+ */
114
+ export declare function buildProvider(config: ProviderConfiguration): Promise<DataProvider>;
115
+
116
+ /**
117
+ * Build a Snowflake data provider from the configuration
118
+ *
119
+ * @param config - Provider configuration
120
+ * @returns Promise resolving to Snowflake data provider
121
+ * @throws {InvalidProviderConfigurationError} If snowflake-sdk is not installed or config is invalid
122
+ */
123
+ export declare function buildSnowflakeProvider(config: ProviderConfiguration): Promise<SnowflakeProvider>;
124
+
125
+ /**
126
+ * Container data app response from /dataapps/apps/container/{connectorId}
127
+ */
128
+ export declare interface ContainerDataApp {
129
+ id: string;
130
+ orgSlug: string;
131
+ connectorId: string;
132
+ serviceNamespace: string;
133
+ serviceDiscoveryName: string;
134
+ createdAt: string;
135
+ updatedAt?: string;
136
+ createdBy: string;
137
+ updatedBy?: string;
138
+ port: string;
139
+ config: Record<string, unknown>;
140
+ providers: MinimalProvider[];
141
+ }
142
+
143
+ /** Cookie dictionary type - matches Express req.cookies */
144
+ export declare interface CookieDict {
145
+ [key: string]: string;
146
+ }
147
+
148
+ /**
149
+ * Databricks data provider
150
+ */
151
+ export declare class DatabricksProvider {
152
+ private client;
153
+ private session;
154
+ /**
155
+ * Initialize the Databricks data provider
156
+ *
157
+ * @param client - Databricks SQL client
158
+ * @param session - Databricks SQL session
159
+ */
160
+ constructor(client: DBSQLClient, session: IDBSQLSession);
161
+ /**
162
+ * Query the Databricks database
163
+ *
164
+ * @param sqlQuery - SQL query to execute
165
+ * @param _params - Parameters to pass to the query (currently not used)
166
+ * @returns Promise resolving to array of row objects
167
+ */
168
+ query(sqlQuery: string, _params?: Record<string, unknown>): Promise<Array<Record<string, unknown>>>;
169
+ /**
170
+ * Close the Databricks connection
171
+ */
172
+ close(): Promise<void>;
173
+ }
174
+
175
+ /**
176
+ * Union type of all supported data providers
177
+ */
178
+ export declare type DataProvider = SnowflakeProvider | DatabricksProvider | AthenaProvider;
179
+
180
+ declare type DBSQLClient = DBSQLClient_2;
181
+
182
+ /** Express-like request interface (works with Express, Koa, etc.) */
183
+ export declare interface ExpressRequestLike {
184
+ cookies?: CookieDict;
185
+ }
186
+
187
+ /**
188
+ * Get the provider configurations.
189
+ *
190
+ * There are two ways to get the provider configurations:
191
+ * 1. If the environment variable `DATA_APP_PROVIDER_CONFIG` is set or
192
+ * providerConfigOverride is provided, the provider configurations are read from it.
193
+ * 2. If the environment variable `CONNECTOR_ID` is set or connectorId is provided,
194
+ * the provider configurations are fetched from TDP. The secrets are read from
195
+ * environment variables.
196
+ * 3. If neither of the above is set, an empty array is returned.
197
+ *
198
+ * Option 1 is used for local development to specify the provider configurations directly.
199
+ * Option 2 is used in production to fetch the provider configurations from TDP.
200
+ *
201
+ * @param client - Initialized TDPClient instance (call client.init() first)
202
+ * @param options - Optional configuration overrides
203
+ * @returns Array of provider configurations
204
+ * @throws {InvalidProviderConfigurationError} If provider config JSON is invalid
205
+ * @throws {Error} If TDPClient is not initialized
206
+ *
207
+ * @example
208
+ * ```typescript
209
+ * import { TDPClient } from '@tetrascience-npm/ts-connectors-sdk';
210
+ * import { getProviderConfigurations } from '@tetrascience-npm/tetrascience-react-ui/server';
211
+ *
212
+ * // Initialize TDPClient with user's JWT token
213
+ * // Other fields (tdpEndpoint, connectorId, orgSlug) are read from environment variables
214
+ * const client = new TDPClient({
215
+ * authToken: userJwtToken, // from jwtManager.getTokenFromExpressRequest(req)
216
+ * artifactType: "data-app",
217
+ * });
218
+ * await client.init();
219
+ *
220
+ * const providers = await getProviderConfigurations(client);
221
+ *
222
+ * for (const provider of providers) {
223
+ * console.log(`Provider: ${provider.name} (${provider.type})`);
224
+ * }
225
+ * ```
226
+ */
227
+ export declare function getProviderConfigurations(client: TDPClient, options?: GetProviderConfigurationsOptions): Promise<ProviderConfiguration[]>;
228
+
229
+ /**
230
+ * Options for getProviderConfigurations function
231
+ */
232
+ export declare interface GetProviderConfigurationsOptions {
233
+ /** Override provider configurations JSON (for local development) */
234
+ providerConfigOverride?: string;
235
+ /** Connector ID (defaults to CONNECTOR_ID env var) */
236
+ connectorId?: string;
237
+ }
238
+
239
+ /**
240
+ * Get the TDP Athena provider
241
+ *
242
+ * Creates an Athena provider using TDP environment configuration
243
+ *
244
+ * @returns Promise resolving to Athena data provider
245
+ * @throws {InvalidProviderConfigurationError} If @aws-sdk/client-athena is not installed
246
+ * @throws {Error} If ATHENA_S3_OUTPUT_LOCATION is not set when using the 'primary' workgroup
247
+ */
248
+ export declare function getTdpAthenaProvider(): Promise<AthenaProvider>;
249
+
250
+ declare type IDBSQLSession = default_2;
251
+
252
+ /**
253
+ * Raised when the provider configuration is invalid
254
+ */
255
+ export declare class InvalidProviderConfigurationError extends ProviderError {
256
+ constructor(message: string);
257
+ }
258
+
259
+ /**
260
+ * Global singleton instance.
261
+ *
262
+ * Note: This instance is created when the module is imported. Configuration
263
+ * that depends on environment variables (CONNECTOR_ID, ORG_SLUG, TDP_ENDPOINT)
264
+ * is read at module load time. Ensure these environment
265
+ * variables are set before importing this module.
266
+ *
267
+ * If you need different configuration at runtime, create a new JwtTokenManager
268
+ * instance instead of using this singleton.
269
+ */
270
+ export declare const jwtManager: JwtTokenManager;
271
+
272
+ /**
273
+ * Manages JWT token retrieval from request cookies.
274
+ * Supports both ts-auth-token (direct JWT) and ts-token-ref (resolved via connector store).
275
+ */
276
+ export declare class JwtTokenManager {
277
+ private baseUrlOverride;
278
+ private connectorId;
279
+ private orgSlug;
280
+ private tokenCache;
281
+ private tokenRefreshThresholdMs;
282
+ private tdpClient;
283
+ constructor(config?: JwtTokenManagerConfig);
284
+ /**
285
+ * Get the base URL for TDP API calls.
286
+ * Throws an error if not configured (either via config.baseUrl or TDP_ENDPOINT env var).
287
+ */
288
+ private getBaseUrl;
289
+ /**
290
+ * Decode JWT payload without verifying signature.
291
+ * Used only for reading expiration times for cache invalidation.
292
+ * Signature verification is NOT performed here.
293
+ */
294
+ private decodeJwtPayload;
295
+ /** Check if payload is expiring within the refresh threshold */
296
+ private isPayloadExpiringSoon;
297
+ /** Get valid cached token if not expiring */
298
+ private getValidUserJwt;
299
+ /** Initialize or get TDP client */
300
+ private getTdpClient;
301
+ /** Retrieve JWT from connector K/V store using getValues (calls getConnectorData internally) */
302
+ private getJwtFromTokenRefInternal;
303
+ /** Resolve ts-token-ref to full JWT token (with caching) */
304
+ getJwtFromTokenRef(tokenRef: string): Promise<string | null>;
305
+ /** Get token from cookies (ts-auth-token or resolved ts-token-ref) */
306
+ getUserToken(cookies: CookieDict): Promise<string | null>;
307
+ /**
308
+ * Get user token from an Express request object.
309
+ * This is the primary method for Express middleware integration.
310
+ *
311
+ * @example
312
+ * ```typescript
313
+ * import { jwtManager } from '@tetrascience-npm/tetrascience-react-ui/server';
314
+ *
315
+ * app.use(async (req, res, next) => {
316
+ * const token = await jwtManager.getTokenFromExpressRequest(req);
317
+ * req.tdpAuth = { token, orgSlug: process.env.ORG_SLUG };
318
+ * next();
319
+ * });
320
+ * ```
321
+ */
322
+ getTokenFromExpressRequest(req: ExpressRequestLike): Promise<string | null>;
323
+ /** Clear the token cache */
324
+ clearCache(): void;
325
+ }
326
+
327
+ /**
328
+ * JWT Token Manager for TetraScience Data Apps
329
+ *
330
+ * Handles authentication token retrieval from Express request cookies,
331
+ * supporting both direct JWT tokens (ts-auth-token) and token references
332
+ * (ts-token-ref) that are resolved via the connector K/V store.
333
+ *
334
+ * Note: This manager does not perform cryptographic verification of JWT signatures.
335
+ * Signature verification is the responsibility of the consuming application or
336
+ * the upstream authentication layer. The JWT payload is decoded only to read
337
+ * expiration times for cache invalidation.
338
+ */
339
+ /** Configuration options for JwtTokenManager */
340
+ export declare interface JwtTokenManagerConfig {
341
+ baseUrl?: string;
342
+ tokenRefreshThresholdMs?: number;
343
+ }
344
+
345
+ /**
346
+ * Minimal provider information as returned by the /dataapps/apps/{appId} endpoint
347
+ */
348
+ export declare interface MinimalProvider {
349
+ id: string;
350
+ orgSlug: string;
351
+ name: string;
352
+ type: string;
353
+ iconUrl: string;
354
+ createdAt: string;
355
+ updatedAt?: string;
356
+ createdBy: string;
357
+ updatedBy?: string;
358
+ }
359
+
360
+ /**
361
+ * Raised when a table is missing in the database
362
+ */
363
+ export declare class MissingTableError extends ProviderError {
364
+ constructor(message: string);
365
+ }
366
+
367
+ /**
368
+ * Organization API response
369
+ */
370
+ export declare interface OrganizationApiResponse {
371
+ id: string;
372
+ orgSlug: string;
373
+ name: string;
374
+ emailDomain: string;
375
+ authType: string;
376
+ features: Record<string, unknown>;
377
+ tenantId: string;
378
+ createdAt: string;
379
+ createdBy: string;
380
+ modifiedAt?: string;
381
+ modifiedBy?: string;
382
+ subdomain: string;
383
+ ssoEnabledOnTenant: boolean;
384
+ }
385
+
386
+ /**
387
+ * Full provider API response including secrets
388
+ */
389
+ export declare interface ProviderApiResponse {
390
+ id: string;
391
+ orgSlug: string;
392
+ name: string;
393
+ type: string;
394
+ iconUrl: string;
395
+ createdAt: string;
396
+ updatedAt?: string;
397
+ createdBy: string;
398
+ updatedBy?: string;
399
+ dataAppCount: string;
400
+ secrets: ProviderSecret[];
401
+ }
402
+
403
+ /**
404
+ * Data App Provider Types
405
+ *
406
+ * TypeScript equivalents of the Python ProviderConfiguration Pydantic models
407
+ * from ts-lib-ui-kit-streamlit/tetrascience/data_app_providers/provider_typing.py
408
+ */
409
+ /**
410
+ * Configuration model for data providers.
411
+ *
412
+ * This interface represents the configuration needed to connect to various
413
+ * database providers (Snowflake, Databricks, Athena, Benchling, etc.)
414
+ * attached to a data app.
415
+ */
416
+ export declare interface ProviderConfiguration {
417
+ /** Human-readable name of the provider */
418
+ name: string;
419
+ /** Provider type (snowflake, databricks, benchling, custom, etc.) */
420
+ type: string;
421
+ /** Optional URL to the provider's icon */
422
+ iconUrl?: string;
423
+ /** Dictionary containing connection details and credentials */
424
+ fields: Record<string, string | undefined>;
425
+ }
426
+
427
+ /**
428
+ * Raised when connecting to a provider fails
429
+ */
430
+ export declare class ProviderConnectionError extends ProviderError {
431
+ constructor(message: string);
432
+ }
433
+
434
+ /**
435
+ * Provider Exceptions
436
+ *
437
+ * TypeScript equivalents of the Python exceptions from
438
+ * ts-lib-ui-kit-streamlit/tetrascience/data_app_providers/exceptions.py
439
+ */
440
+ /**
441
+ * Base class for provider errors
442
+ */
443
+ export declare class ProviderError extends Error {
444
+ constructor(message: string);
445
+ }
446
+
447
+ /**
448
+ * Display-friendly provider information for UI components.
449
+ *
450
+ * A simplified subset of ProviderConfiguration containing only the
451
+ * fields needed for displaying provider information in the UI,
452
+ * including the names of available connection fields without their
453
+ * secret values.
454
+ */
455
+ export declare interface ProviderInfo {
456
+ /** Human-readable name of the provider */
457
+ name: string;
458
+ /** Provider type (snowflake, databricks, athena, etc.) */
459
+ type: string;
460
+ /** Optional URL to the provider's icon */
461
+ iconUrl?: string | null;
462
+ /** Names of available connection fields (without secret values) */
463
+ availableFields: string[];
464
+ }
465
+
466
+ /**
467
+ * Provider secret information from the provider API response
468
+ */
469
+ export declare interface ProviderSecret {
470
+ name: string;
471
+ value?: string;
472
+ type: string;
473
+ required: boolean;
474
+ arn: string;
475
+ envName: string;
476
+ }
477
+
478
+ /**
479
+ * Raised when a query fails
480
+ */
481
+ export declare class QueryError extends ProviderError {
482
+ constructor(message: string);
483
+ }
484
+
485
+ /**
486
+ * Standardized query result from data providers.
487
+ *
488
+ * This interface provides a consistent shape for query results across
489
+ * all provider types (Snowflake, Databricks, Athena), with optional
490
+ * metadata for API responses.
491
+ */
492
+ export declare interface QueryResult {
493
+ /** Array of row objects returned by the query */
494
+ data: Array<Record<string, unknown>>;
495
+ /** Number of rows returned */
496
+ rowCount: number;
497
+ /** Name of the provider that executed the query */
498
+ provider?: string;
499
+ /** Whether this is mock/demo data */
500
+ mock?: boolean;
501
+ /** Optional message (e.g., for errors or warnings) */
502
+ message?: string;
503
+ }
504
+
505
+ declare type SnowflakeConnection = Connection;
506
+
507
+ /**
508
+ * Snowflake data provider
509
+ */
510
+ export declare class SnowflakeProvider {
511
+ private connection;
512
+ /**
513
+ * Initialize the Snowflake data provider
514
+ *
515
+ * @param connection - Snowflake connection
516
+ */
517
+ constructor(connection: SnowflakeConnection);
518
+ /**
519
+ * Query the Snowflake database
520
+ *
521
+ * @param sqlText - SQL query to execute
522
+ * @param params - Parameters to pass to the query. For positional binds, use an array.
523
+ * For named binds, use an object with keys matching the bind variable names.
524
+ * @returns Promise resolving to array of row objects
525
+ */
526
+ query(sqlText: string, params?: Record<string, unknown> | unknown[]): Promise<Array<Record<string, unknown>>>;
527
+ /**
528
+ * Close the Snowflake connection
529
+ */
530
+ close(): Promise<void>;
531
+ }
532
+
533
+ export { }
6
534
 
7
- /**
8
- * JWT Token Manager for TetraScience Data Apps
9
- *
10
- * Handles authentication token retrieval from Express request cookies,
11
- * supporting both direct JWT tokens (ts-auth-token) and token references
12
- * (ts-token-ref) that are resolved via the connector K/V store.
13
- *
14
- * Note: This manager does not perform cryptographic verification of JWT signatures.
15
- * Signature verification is the responsibility of the consuming application or
16
- * the upstream authentication layer. The JWT payload is decoded only to read
17
- * expiration times for cache invalidation.
18
- */
19
- /** Configuration options for JwtTokenManager */
20
- interface JwtTokenManagerConfig {
21
- baseUrl?: string;
22
- tokenRefreshThresholdMs?: number;
23
- }
24
- /** Cookie dictionary type - matches Express req.cookies */
25
- interface CookieDict {
26
- [key: string]: string;
27
- }
28
- /** Express-like request interface (works with Express, Koa, etc.) */
29
- interface ExpressRequestLike {
30
- cookies?: CookieDict;
31
- }
32
- /**
33
- * Manages JWT token retrieval from request cookies.
34
- * Supports both ts-auth-token (direct JWT) and ts-token-ref (resolved via connector store).
35
- */
36
- declare class JwtTokenManager {
37
- private baseUrlOverride;
38
- private connectorId;
39
- private orgSlug;
40
- private tokenCache;
41
- private tokenRefreshThresholdMs;
42
- private tdpClient;
43
- constructor(config?: JwtTokenManagerConfig);
44
- /**
45
- * Get the base URL for TDP API calls.
46
- * Throws an error if not configured (either via config.baseUrl or TDP_ENDPOINT env var).
47
- */
48
- private getBaseUrl;
49
- /**
50
- * Decode JWT payload without verifying signature.
51
- * Used only for reading expiration times for cache invalidation.
52
- * Signature verification is NOT performed here.
53
- */
54
- private decodeJwtPayload;
55
- /** Check if payload is expiring within the refresh threshold */
56
- private isPayloadExpiringSoon;
57
- /** Get valid cached token if not expiring */
58
- private getValidUserJwt;
59
- /** Initialize or get TDP client */
60
- private getTdpClient;
61
- /** Retrieve JWT from connector K/V store using getValues (calls getConnectorData internally) */
62
- private getJwtFromTokenRefInternal;
63
- /** Resolve ts-token-ref to full JWT token (with caching) */
64
- getJwtFromTokenRef(tokenRef: string): Promise<string | null>;
65
- /** Get token from cookies (ts-auth-token or resolved ts-token-ref) */
66
- getUserToken(cookies: CookieDict): Promise<string | null>;
67
- /**
68
- * Get user token from an Express request object.
69
- * This is the primary method for Express middleware integration.
70
- *
71
- * @example
72
- * ```typescript
73
- * import { jwtManager } from '@tetrascience-npm/tetrascience-react-ui/server';
74
- *
75
- * app.use(async (req, res, next) => {
76
- * const token = await jwtManager.getTokenFromExpressRequest(req);
77
- * req.tdpAuth = { token, orgSlug: process.env.ORG_SLUG };
78
- * next();
79
- * });
80
- * ```
81
- */
82
- getTokenFromExpressRequest(req: ExpressRequestLike): Promise<string | null>;
83
- /** Clear the token cache */
84
- clearCache(): void;
85
- }
86
- /**
87
- * Global singleton instance.
88
- *
89
- * Note: This instance is created when the module is imported. Configuration
90
- * that depends on environment variables (CONNECTOR_ID, ORG_SLUG, TDP_ENDPOINT)
91
- * is read at module load time. Ensure these environment
92
- * variables are set before importing this module.
93
- *
94
- * If you need different configuration at runtime, create a new JwtTokenManager
95
- * instance instead of using this singleton.
96
- */
97
- declare const jwtManager: JwtTokenManager;
98
535
 
99
- /**
100
- * Provider Exceptions
101
- *
102
- * TypeScript equivalents of the Python exceptions from
103
- * ts-lib-ui-kit-streamlit/tetrascience/data_app_providers/exceptions.py
104
- */
105
- /**
106
- * Base class for provider errors
107
- */
108
- declare class ProviderError extends Error {
109
- constructor(message: string);
110
- }
111
- /**
112
- * Raised when a table is missing in the database
113
- */
114
- declare class MissingTableError extends ProviderError {
115
- constructor(message: string);
116
- }
117
- /**
118
- * Raised when a query fails
119
- */
120
- declare class QueryError extends ProviderError {
121
- constructor(message: string);
122
- }
123
- /**
124
- * Raised when connecting to a provider fails
125
- */
126
- declare class ProviderConnectionError extends ProviderError {
127
- constructor(message: string);
128
- }
129
- /**
130
- * Raised when the provider configuration is invalid
131
- */
132
- declare class InvalidProviderConfigurationError extends ProviderError {
133
- constructor(message: string);
134
- }
135
-
136
- /**
137
- * Data App Provider Types
138
- *
139
- * TypeScript equivalents of the Python ProviderConfiguration Pydantic models
140
- * from ts-lib-ui-kit-streamlit/tetrascience/data_app_providers/provider_typing.py
141
- */
142
- /**
143
- * Configuration model for data providers.
144
- *
145
- * This interface represents the configuration needed to connect to various
146
- * database providers (Snowflake, Databricks, Athena, Benchling, etc.)
147
- * attached to a data app.
148
- */
149
- interface ProviderConfiguration {
150
- /** Human-readable name of the provider */
151
- name: string;
152
- /** Provider type (snowflake, databricks, benchling, custom, etc.) */
153
- type: string;
154
- /** Optional URL to the provider's icon */
155
- iconUrl?: string;
156
- /** Dictionary containing connection details and credentials */
157
- fields: Record<string, string | undefined>;
158
- }
159
- /**
160
- * Minimal provider information as returned by the /dataapps/apps/{appId} endpoint
161
- */
162
- interface MinimalProvider {
163
- id: string;
164
- orgSlug: string;
165
- name: string;
166
- type: string;
167
- iconUrl: string;
168
- createdAt: string;
169
- updatedAt?: string;
170
- createdBy: string;
171
- updatedBy?: string;
172
- }
173
- /**
174
- * Provider secret information from the provider API response
175
- */
176
- interface ProviderSecret {
177
- name: string;
178
- value?: string;
179
- type: string;
180
- required: boolean;
181
- arn: string;
182
- envName: string;
183
- }
184
- /**
185
- * Full provider API response including secrets
186
- */
187
- interface ProviderApiResponse {
188
- id: string;
189
- orgSlug: string;
190
- name: string;
191
- type: string;
192
- iconUrl: string;
193
- createdAt: string;
194
- updatedAt?: string;
195
- createdBy: string;
196
- updatedBy?: string;
197
- dataAppCount: string;
198
- secrets: ProviderSecret[];
199
- }
200
- /**
201
- * Container data app response from /dataapps/apps/container/{connectorId}
202
- */
203
- interface ContainerDataApp {
204
- id: string;
205
- orgSlug: string;
206
- connectorId: string;
207
- serviceNamespace: string;
208
- serviceDiscoveryName: string;
209
- createdAt: string;
210
- updatedAt?: string;
211
- createdBy: string;
212
- updatedBy?: string;
213
- port: string;
214
- config: Record<string, unknown>;
215
- providers: MinimalProvider[];
216
- }
217
- /**
218
- * Organization API response
219
- */
220
- interface OrganizationApiResponse {
221
- id: string;
222
- orgSlug: string;
223
- name: string;
224
- emailDomain: string;
225
- authType: string;
226
- features: Record<string, unknown>;
227
- tenantId: string;
228
- createdAt: string;
229
- createdBy: string;
230
- modifiedAt?: string;
231
- modifiedBy?: string;
232
- subdomain: string;
233
- ssoEnabledOnTenant: boolean;
536
+ declare module "styled-components" {
537
+ interface DefaultTheme {
538
+ position: ToastPosition;
539
+ }
234
540
  }
235
- /**
236
- * Options for getProviderConfigurations function
237
- */
238
- interface GetProviderConfigurationsOptions {
239
- /** Override provider configurations JSON (for local development) */
240
- providerConfigOverride?: string;
241
- /** Connector ID (defaults to CONNECTOR_ID env var) */
242
- connectorId?: string;
243
- }
244
- /**
245
- * Display-friendly provider information for UI components.
246
- *
247
- * A simplified subset of ProviderConfiguration containing only the
248
- * fields needed for displaying provider information in the UI,
249
- * including the names of available connection fields without their
250
- * secret values.
251
- */
252
- interface ProviderInfo {
253
- /** Human-readable name of the provider */
254
- name: string;
255
- /** Provider type (snowflake, databricks, athena, etc.) */
256
- type: string;
257
- /** Optional URL to the provider's icon */
258
- iconUrl?: string | null;
259
- /** Names of available connection fields (without secret values) */
260
- availableFields: string[];
261
- }
262
- /**
263
- * Standardized query result from data providers.
264
- *
265
- * This interface provides a consistent shape for query results across
266
- * all provider types (Snowflake, Databricks, Athena), with optional
267
- * metadata for API responses.
268
- */
269
- interface QueryResult {
270
- /** Array of row objects returned by the query */
271
- data: Array<Record<string, unknown>>;
272
- /** Number of rows returned */
273
- rowCount: number;
274
- /** Name of the provider that executed the query */
275
- provider?: string;
276
- /** Whether this is mock/demo data */
277
- mock?: boolean;
278
- /** Optional message (e.g., for errors or warnings) */
279
- message?: string;
280
- }
281
-
282
- /**
283
- * Get Provider Configurations
284
- *
285
- * TypeScript equivalent of get_provider_configurations from
286
- * ts-lib-ui-kit-streamlit/tetrascience/data_app_providers/provider.py
287
- *
288
- * Retrieves data app provider configurations either from environment variable
289
- * override or by fetching from the TDP API.
290
- */
291
-
292
- /**
293
- * Get the provider configurations.
294
- *
295
- * There are two ways to get the provider configurations:
296
- * 1. If the environment variable `DATA_APP_PROVIDER_CONFIG` is set or
297
- * providerConfigOverride is provided, the provider configurations are read from it.
298
- * 2. If the environment variable `CONNECTOR_ID` is set or connectorId is provided,
299
- * the provider configurations are fetched from TDP. The secrets are read from
300
- * environment variables.
301
- * 3. If neither of the above is set, an empty array is returned.
302
- *
303
- * Option 1 is used for local development to specify the provider configurations directly.
304
- * Option 2 is used in production to fetch the provider configurations from TDP.
305
- *
306
- * @param client - Initialized TDPClient instance (call client.init() first)
307
- * @param options - Optional configuration overrides
308
- * @returns Array of provider configurations
309
- * @throws {InvalidProviderConfigurationError} If provider config JSON is invalid
310
- * @throws {Error} If TDPClient is not initialized
311
- *
312
- * @example
313
- * ```typescript
314
- * import { TDPClient } from '@tetrascience-npm/ts-connectors-sdk';
315
- * import { getProviderConfigurations } from '@tetrascience-npm/tetrascience-react-ui/server';
316
- *
317
- * // Initialize TDPClient with user's JWT token
318
- * // Other fields (tdpEndpoint, connectorId, orgSlug) are read from environment variables
319
- * const client = new TDPClient({
320
- * authToken: userJwtToken, // from jwtManager.getTokenFromExpressRequest(req)
321
- * artifactType: "data-app",
322
- * });
323
- * await client.init();
324
- *
325
- * const providers = await getProviderConfigurations(client);
326
- *
327
- * for (const provider of providers) {
328
- * console.log(`Provider: ${provider.name} (${provider.type})`);
329
- * }
330
- * ```
331
- */
332
- declare function getProviderConfigurations(client: TDPClient, options?: GetProviderConfigurationsOptions): Promise<ProviderConfiguration[]>;
333
-
334
- type SnowflakeConnection = snowflake_sdk.Connection;
335
- /**
336
- * Snowflake data provider
337
- */
338
- declare class SnowflakeProvider {
339
- private connection;
340
- /**
341
- * Initialize the Snowflake data provider
342
- *
343
- * @param connection - Snowflake connection
344
- */
345
- constructor(connection: SnowflakeConnection);
346
- /**
347
- * Query the Snowflake database
348
- *
349
- * @param sqlText - SQL query to execute
350
- * @param params - Parameters to pass to the query. For positional binds, use an array.
351
- * For named binds, use an object with keys matching the bind variable names.
352
- * @returns Promise resolving to array of row objects
353
- */
354
- query(sqlText: string, params?: Record<string, unknown> | unknown[]): Promise<Array<Record<string, unknown>>>;
355
- /**
356
- * Close the Snowflake connection
357
- */
358
- close(): Promise<void>;
359
- }
360
- /**
361
- * Build a Snowflake data provider from the configuration
362
- *
363
- * @param config - Provider configuration
364
- * @returns Promise resolving to Snowflake data provider
365
- * @throws {InvalidProviderConfigurationError} If snowflake-sdk is not installed or config is invalid
366
- */
367
- declare function buildSnowflakeProvider(config: ProviderConfiguration): Promise<SnowflakeProvider>;
368
-
369
- type DBSQLClient = _databricks_sql.DBSQLClient;
370
- type IDBSQLSession = _databricks_sql_dist_contracts_IDBSQLSession.default;
371
- /**
372
- * Databricks data provider
373
- */
374
- declare class DatabricksProvider {
375
- private client;
376
- private session;
377
- /**
378
- * Initialize the Databricks data provider
379
- *
380
- * @param client - Databricks SQL client
381
- * @param session - Databricks SQL session
382
- */
383
- constructor(client: DBSQLClient, session: IDBSQLSession);
384
- /**
385
- * Query the Databricks database
386
- *
387
- * @param sqlQuery - SQL query to execute
388
- * @param _params - Parameters to pass to the query (currently not used)
389
- * @returns Promise resolving to array of row objects
390
- */
391
- query(sqlQuery: string, _params?: Record<string, unknown>): Promise<Array<Record<string, unknown>>>;
392
- /**
393
- * Close the Databricks connection
394
- */
395
- close(): Promise<void>;
396
- }
397
- /**
398
- * Build a Databricks data provider from the configuration
399
- *
400
- * @param config - Provider configuration
401
- * @returns Promise resolving to Databricks data provider
402
- * @throws {InvalidProviderConfigurationError} If @databricks/sql is not installed or config is invalid
403
- */
404
- declare function buildDatabricksProvider(config: ProviderConfiguration): Promise<DatabricksProvider>;
405
-
406
- /**
407
- * Athena Data Provider
408
- *
409
- * TypeScript equivalent of AthenaProvider from
410
- * ts-lib-ui-kit-streamlit/tetrascience/data_app_providers/provider.py
411
- *
412
- * @remarks
413
- * This provider requires the `@aws-sdk/client-athena` package to be installed.
414
- * It is an optional peer dependency - install it only if you need Athena support:
415
- * ```bash
416
- * npm install @aws-sdk/client-athena
417
- * # or
418
- * yarn add @aws-sdk/client-athena
419
- * ```
420
- */
421
- type AthenaClient = _aws_sdk_client_athena.AthenaClient;
422
- type AthenaSDK = typeof _aws_sdk_client_athena;
423
- /**
424
- * Athena data provider
425
- */
426
- declare class AthenaProvider {
427
- private client;
428
- private sdk;
429
- private workgroup;
430
- private database;
431
- private outputLocation?;
432
- /**
433
- * Initialize the Athena data provider
434
- *
435
- * @param client - AWS Athena client
436
- * @param sdk - AWS Athena SDK module (for accessing command classes)
437
- * @param workgroup - Athena workgroup to use
438
- * @param database - Default database/schema
439
- * @param outputLocation - Optional S3 output location
440
- */
441
- constructor(client: AthenaClient, sdk: AthenaSDK, workgroup: string, database: string, outputLocation?: string);
442
- /**
443
- * Query the Athena database
444
- *
445
- * @param sqlQuery - SQL query to execute
446
- * @param _params - Parameters to pass to the query (currently not used - Athena doesn't support parameterized queries)
447
- * @returns Promise resolving to array of row objects
448
- *
449
- * @remarks
450
- * **Security Note:** AWS Athena does not support parameterized queries.
451
- * Unlike traditional databases, there is no native way to use bind parameters
452
- * with Athena. Callers are responsible for properly sanitizing any user input
453
- * before constructing the SQL query string. This is a known limitation of the
454
- * Athena service, not a design flaw in this implementation.
455
- */
456
- query(sqlQuery: string, _params?: Record<string, unknown>): Promise<Array<Record<string, unknown>>>;
457
- /**
458
- * Wait for query to complete
459
- */
460
- private waitForQueryCompletion;
461
- /**
462
- * Fetch all results from a completed query
463
- */
464
- private fetchAllResults;
465
- /**
466
- * Close the Athena client (no-op for AWS SDK clients)
467
- */
468
- close(): Promise<void>;
469
- }
470
- /**
471
- * Get the TDP Athena provider
472
- *
473
- * Creates an Athena provider using TDP environment configuration
474
- *
475
- * @returns Promise resolving to Athena data provider
476
- * @throws {InvalidProviderConfigurationError} If @aws-sdk/client-athena is not installed
477
- * @throws {Error} If ATHENA_S3_OUTPUT_LOCATION is not set when using the 'primary' workgroup
478
- */
479
- declare function getTdpAthenaProvider(): Promise<AthenaProvider>;
480
-
481
- /**
482
- * Build Provider Factory
483
- *
484
- * TypeScript equivalent of build_provider from
485
- * ts-lib-ui-kit-streamlit/tetrascience/data_app_providers/provider.py
486
- */
487
-
488
- /**
489
- * Union type of all supported data providers
490
- */
491
- type DataProvider = SnowflakeProvider | DatabricksProvider | AthenaProvider;
492
- /**
493
- * Build a data provider from the configuration
494
- *
495
- * The return type is a union of specific provider types. More provider types
496
- * may be added in the future.
497
- *
498
- * @param config - Provider configuration
499
- * @returns Promise resolving to the appropriate data provider
500
- * @throws {InvalidProviderConfigurationError} If the provider type is not supported
501
- *
502
- * @example
503
- * ```typescript
504
- * import { TDPClient } from '@tetrascience-npm/ts-connectors-sdk';
505
- * import { buildProvider, getProviderConfigurations } from '@tetrascience-npm/tetrascience-react-ui/server';
506
- *
507
- * // Other fields (tdpEndpoint, connectorId, orgSlug) are read from environment variables
508
- * const client = new TDPClient({
509
- * authToken: userJwt,
510
- * artifactType: "data-app",
511
- * });
512
- * await client.init();
513
- * const configs = await getProviderConfigurations(client);
514
- *
515
- * const snowflakeConfig = configs.find(c => c.type === 'snowflake');
516
- * if (snowflakeConfig) {
517
- * const provider = await buildProvider(snowflakeConfig);
518
- * const results = await provider.query('SELECT * FROM my_table');
519
- * }
520
- * ```
521
- */
522
- declare function buildProvider(config: ProviderConfiguration): Promise<DataProvider>;
523
-
524
- export { AthenaProvider, DatabricksProvider, InvalidProviderConfigurationError, JwtTokenManager, MissingTableError, ProviderConnectionError, ProviderError, QueryError, SnowflakeProvider, buildDatabricksProvider, buildProvider, buildSnowflakeProvider, getProviderConfigurations, getTdpAthenaProvider, jwtManager };
525
- export type { ContainerDataApp, CookieDict, DataProvider, ExpressRequestLike, GetProviderConfigurationsOptions, JwtTokenManagerConfig, MinimalProvider, OrganizationApiResponse, ProviderApiResponse, ProviderConfiguration, ProviderInfo, ProviderSecret, QueryResult };