@tetrascience-npm/tetrascience-react-ui 0.3.0 → 0.4.0-beta.10.1

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.
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  React component library for building TetraScience applications.
4
4
 
5
+ [![npm version](https://img.shields.io/npm/v/@tetrascience-npm/tetrascience-react-ui)](https://www.npmjs.com/package/@tetrascience-npm/tetrascience-react-ui) [![CI](https://github.com/tetrascience/ts-lib-ui-kit/actions/workflows/ci.yml/badge.svg)](https://github.com/tetrascience/ts-lib-ui-kit/actions/workflows/ci.yml) 📖 **[Storybook – Live Component Demos](https://ts-lib-ui-kit-storybook.vercel.app/)** | 🛠️ **[Contributing Guide](./CONTRIBUTING.md)**
6
+
5
7
  This library provides:
6
8
 
7
9
  - **UI Components**: Reusable React components following atomic design principles
@@ -9,6 +11,12 @@ This library provides:
9
11
  - **Theming**: Customisable design system with ThemeProvider
10
12
  - **TypeScript**: Full type support with exported prop types
11
13
 
14
+ ## Requirements
15
+
16
+ - **React 19+**
17
+ - **Node.js 18+**
18
+ - **TypeScript 5.5+** (optional, but recommended)
19
+
12
20
  ## Installation
13
21
 
14
22
  ```bash
@@ -103,6 +111,177 @@ const token = await jwtManager.getUserToken(req.cookies);
103
111
 
104
112
  > **Note:** The singleton `jwtManager` reads environment variables when the module is imported. Ensure these are set before importing the module.
105
113
 
114
+ ### Data App Providers (`server/providers`)
115
+
116
+ TypeScript equivalents of the Python helpers from `ts-lib-ui-kit-streamlit` for connecting to database providers (Snowflake, Databricks, Athena).
117
+
118
+ **Getting Provider Configurations:**
119
+
120
+ ```typescript
121
+ import { TDPClient } from '@tetrascience-npm/ts-connectors-sdk';
122
+ import {
123
+ getProviderConfigurations,
124
+ buildProvider,
125
+ jwtManager,
126
+ } from '@tetrascience-npm/tetrascience-react-ui/server';
127
+
128
+ // Get user's auth token from request (e.g., in Express middleware)
129
+ const userToken = await jwtManager.getTokenFromExpressRequest(req);
130
+
131
+ // Create TDPClient with the user's auth token
132
+ // Other fields (tdpEndpoint, connectorId, orgSlug) are read from environment variables
133
+ const client = new TDPClient({
134
+ authToken: userToken,
135
+ artifactType: 'data-app',
136
+ });
137
+ await client.init();
138
+
139
+ // Get all configured providers for this data app
140
+ const providers = await getProviderConfigurations(client);
141
+
142
+ for (const config of providers) {
143
+ console.log(`Provider: ${config.name} (${config.type})`);
144
+
145
+ // Build a database connection from the config
146
+ const provider = await buildProvider(config);
147
+ const results = await provider.query('SELECT * FROM my_table LIMIT 10');
148
+ await provider.close();
149
+ }
150
+ ```
151
+
152
+ **Using Specific Providers:**
153
+
154
+ ```typescript
155
+ import {
156
+ buildSnowflakeProvider,
157
+ buildDatabricksProvider,
158
+ getTdpAthenaProvider,
159
+ type ProviderConfiguration,
160
+ } from '@tetrascience-npm/tetrascience-react-ui/server';
161
+
162
+ // Snowflake
163
+ const snowflakeProvider = await buildSnowflakeProvider(config);
164
+ const data = await snowflakeProvider.query('SELECT * FROM users');
165
+ await snowflakeProvider.close();
166
+
167
+ // Databricks
168
+ const databricksProvider = await buildDatabricksProvider(config);
169
+ const data = await databricksProvider.query('SELECT * FROM events');
170
+ await databricksProvider.close();
171
+
172
+ // TDP Athena (uses environment configuration)
173
+ const athenaProvider = await getTdpAthenaProvider();
174
+ const data = await athenaProvider.query('SELECT * FROM files');
175
+ await athenaProvider.close();
176
+ ```
177
+
178
+ **Exception Handling:**
179
+
180
+ ```typescript
181
+ import {
182
+ QueryError,
183
+ MissingTableError,
184
+ ProviderConnectionError,
185
+ InvalidProviderConfigurationError,
186
+ } from '@tetrascience-npm/tetrascience-react-ui/server';
187
+
188
+ try {
189
+ const results = await provider.query('SELECT * FROM missing_table');
190
+ } catch (error) {
191
+ if (error instanceof MissingTableError) {
192
+ console.error('Table not found:', error.message);
193
+ } else if (error instanceof QueryError) {
194
+ console.error('Query failed:', error.message);
195
+ }
196
+ }
197
+ ```
198
+
199
+ **Environment Variables:**
200
+
201
+ - `DATA_APP_PROVIDER_CONFIG` - JSON override for local development only
202
+ - `CONNECTOR_ID` - Connector ID for fetching providers from TDP
203
+ - `TDP_ENDPOINT` - TDP API base URL
204
+ - `ORG_SLUG` - Organization slug
205
+ - `ATHENA_S3_OUTPUT_LOCATION` - S3 bucket for Athena query results
206
+ - `AWS_REGION` - AWS region for Athena
207
+
208
+ > **Note:** Authentication tokens are obtained from the user's JWT via `jwtManager`. The `TS_AUTH_TOKEN` environment variable is only for local development fallback.
209
+
210
+ ### Connector Key/Value Store
211
+
212
+ The TDP connector key/value store lets data apps persist small pieces of state (user preferences, cached results, last-run timestamps, etc.) without an external database. The `TDPClient` from `@tetrascience-npm/ts-connectors-sdk` provides `getValue`, `getValues`, `saveValue`, and `saveValues` methods.
213
+
214
+ **Reading and writing values with the user's JWT token:**
215
+
216
+ ```typescript
217
+ import { TDPClient } from '@tetrascience-npm/ts-connectors-sdk';
218
+ import { jwtManager } from '@tetrascience-npm/tetrascience-react-ui/server';
219
+
220
+ // In an Express route handler:
221
+ app.get('/api/kv/:key', async (req, res) => {
222
+ // 1. Get the user's JWT from request cookies
223
+ const userToken = await jwtManager.getTokenFromExpressRequest(req);
224
+ if (!userToken) return res.status(401).json({ error: 'Not authenticated' });
225
+
226
+ // 2. Create a TDPClient authenticated as the user
227
+ // (CONNECTOR_ID, TDP_ENDPOINT, ORG_SLUG are read from env vars)
228
+ const client = new TDPClient({
229
+ authToken: userToken,
230
+ artifactType: 'data-app',
231
+ });
232
+ await client.init();
233
+
234
+ // 3. Read a value
235
+ const value = await client.getValue(req.params.key);
236
+ res.json({ key: req.params.key, value });
237
+ });
238
+
239
+ app.put('/api/kv/:key', async (req, res) => {
240
+ const userToken = await jwtManager.getTokenFromExpressRequest(req);
241
+ if (!userToken) return res.status(401).json({ error: 'Not authenticated' });
242
+
243
+ const client = new TDPClient({
244
+ authToken: userToken,
245
+ artifactType: 'data-app',
246
+ });
247
+ await client.init();
248
+
249
+ // Write a value (any JSON-serialisable type)
250
+ await client.saveValue(req.params.key, req.body.value, { secure: false });
251
+ res.json({ key: req.params.key, saved: true });
252
+ });
253
+ ```
254
+
255
+ **Reading multiple values at once:**
256
+
257
+ ```typescript
258
+ const values = await client.getValues(['theme', 'locale', 'last-run']);
259
+ // values[0] → theme, values[1] → locale, values[2] → last-run
260
+ ```
261
+
262
+ > See the [example app](./examples/vite-themed-app/) for a complete working server with KV store endpoints.
263
+
264
+ ### TDP Search (`server`)
265
+
266
+ **TdpSearchManager** - Server-side handler for the TdpSearch component. Resolves auth from request cookies (via `jwtManager`), calls TDP `searchEql`, and returns the response so the frontend hook works with minimal wiring.
267
+
268
+ ```typescript
269
+ import { tdpSearchManager } from "@tetrascience-npm/tetrascience-react-ui/server";
270
+
271
+ // Express: mount a POST route (e.g. /api/search)
272
+ app.post("/api/search", express.json(), async (req, res) => {
273
+ try {
274
+ const body = req.body; // SearchEqlRequest (searchTerm, from, size, sort, order, ...)
275
+ const response = await tdpSearchManager.handleSearchRequest(req, body);
276
+ res.json(response);
277
+ } catch (err) {
278
+ res.status(401).json({ error: err instanceof Error ? err.message : "Search failed" });
279
+ }
280
+ });
281
+ ```
282
+
283
+ Frontend: use `<TdpSearch columns={...} />` with default `apiEndpoint="/api/search"`, or pass `apiEndpoint` if you use a different path. Auth is taken from cookies (`ts-auth-token` or `ts-token-ref` via `jwtManager`).
284
+
106
285
  ## TypeScript Support
107
286
 
108
287
  Full TypeScript support with exported types:
@@ -118,8 +297,8 @@ The repository includes example applications in the `examples/` directory:
118
297
 
119
298
  ```bash
120
299
  # Clone the repository
121
- git clone https://github.com/tetrascience/ts-lib-ui-kit-react.git
122
- cd ts-lib-ui-kit-react
300
+ git clone https://github.com/tetrascience/ts-lib-ui-kit.git
301
+ cd ts-lib-ui-kit
123
302
 
124
303
  # Install dependencies
125
304
  yarn
@@ -128,13 +307,15 @@ yarn
128
307
  yarn workspace vite-themed-app dev
129
308
  ```
130
309
 
131
- Visit http://localhost:5173 to see the example app with custom theming.
310
+ Visit <http://localhost:5173> to see the example app with custom theming.
132
311
 
133
312
  ## Documentation
134
313
 
135
- - [Getting Started Guide](https://github.com/tetrascience/ts-lib-ui-kit-react/blob/main/get_started_1.md) - Step-by-step tutorial
136
- - [Theming Guide](https://github.com/tetrascience/ts-lib-ui-kit-react/blob/main/THEMING.md) - Customise the design system
137
- - [Storybook](https://github.com/tetrascience/ts-lib-ui-kit-react/blob/main/DEVELOPERS.md#development-setup) - Clone the repo and run `yarn storybook`
314
+ - [Storybook Live Component Demos](https://ts-lib-ui-kit-storybook.vercel.app/) - Browse all components with interactive examples
315
+ - [NPM Package](https://www.npmjs.com/package/@tetrascience-npm/tetrascience-react-ui) - Installation and version info
316
+ - [Getting Started Guide](./get_started_1.md) - Step-by-step tutorial
317
+ - [Theming Guide](./THEMING.md) - Customise the design system
318
+ - [Contributing](./CONTRIBUTING.md#development-setup) - Clone the repo and run `yarn storybook`
138
319
 
139
320
  ## Tech Stack
140
321