@tetrascience-npm/tetrascience-react-ui 0.2.0 → 0.3.0-beta.2.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
@@ -12,17 +12,17 @@ This library provides:
12
12
  ## Installation
13
13
 
14
14
  ```bash
15
- yarn add tetrascience-react-ui
15
+ yarn add @tetrascience-npm/tetrascience-react-ui
16
16
  ```
17
17
 
18
18
  ## Quick Start
19
19
 
20
20
  ```tsx
21
21
  // 1. Import the CSS (required)
22
- import 'tetrascience-react-ui/index.css';
22
+ import '@tetrascience-npm/tetrascience-react-ui/index.css';
23
23
 
24
24
  // 2. Import components
25
- import { Button, Card, BarGraph } from 'tetrascience-react-ui';
25
+ import { Button, Card, BarGraph } from '@tetrascience-npm/tetrascience-react-ui';
26
26
 
27
27
  function App() {
28
28
  return (
@@ -53,7 +53,7 @@ AppLayout, AreaGraph, BarGraph, Boxplot, Chromatogram, DotPlot, Heatmap, Histogr
53
53
  Customise colours, border radius, and spacing:
54
54
 
55
55
  ```tsx
56
- import { ThemeProvider } from 'tetrascience-react-ui';
56
+ import { ThemeProvider } from '@tetrascience-npm/tetrascience-react-ui';
57
57
 
58
58
  const customTheme = {
59
59
  colors: {
@@ -72,13 +72,140 @@ const customTheme = {
72
72
 
73
73
  See [THEMING.md](./THEMING.md) for the complete theming guide.
74
74
 
75
+ ## Server Utilities
76
+
77
+ Beyond UI components, this library includes server-side helper functions for building TetraScience applications. These are available via the `/server` subpath to avoid pulling Node.js dependencies into browser bundles.
78
+
79
+ ### Authentication (`server/auth`)
80
+
81
+ **JWT Token Manager** - Manages JWT token retrieval for data apps:
82
+
83
+ ```typescript
84
+ import { jwtManager } from '@tetrascience-npm/tetrascience-react-ui/server';
85
+
86
+ // In Express middleware
87
+ app.use(async (req, res, next) => {
88
+ const token = await jwtManager.getTokenFromExpressRequest(req);
89
+ req.tdpAuth = { token, orgSlug: process.env.ORG_SLUG };
90
+ next();
91
+ });
92
+
93
+ // Or with raw cookies
94
+ const token = await jwtManager.getUserToken(req.cookies);
95
+ ```
96
+
97
+ **Environment Variables:**
98
+
99
+ - `ORG_SLUG` - Organization slug (required)
100
+ - `CONNECTOR_ID` - Connector ID for ts-token-ref flow
101
+ - `TDP_ENDPOINT` - API base URL
102
+ - `TS_AUTH_TOKEN` - Service account token (fallback for local dev)
103
+
104
+ > **Note:** The singleton `jwtManager` reads environment variables when the module is imported. Ensure these are set before importing the module.
105
+
106
+ ### Data App Providers (`server/providers`)
107
+
108
+ TypeScript equivalents of the Python helpers from `ts-lib-ui-kit-streamlit` for connecting to database providers (Snowflake, Databricks, Athena).
109
+
110
+ **Getting Provider Configurations:**
111
+
112
+ ```typescript
113
+ import { TDPClient } from '@tetrascience-npm/ts-connectors-sdk';
114
+ import {
115
+ getProviderConfigurations,
116
+ buildProvider,
117
+ jwtManager,
118
+ } from '@tetrascience-npm/tetrascience-react-ui/server';
119
+
120
+ // Get user's auth token from request (e.g., in Express middleware)
121
+ const userToken = await jwtManager.getTokenFromExpressRequest(req);
122
+
123
+ // Create TDPClient with the user's auth token
124
+ const client = new TDPClient({
125
+ authToken: userToken,
126
+ artifactType: 'data-app',
127
+ orgSlug: process.env.ORG_SLUG,
128
+ });
129
+ await client.init();
130
+
131
+ // Get all configured providers for this data app
132
+ const providers = await getProviderConfigurations(client);
133
+
134
+ for (const config of providers) {
135
+ console.log(`Provider: ${config.name} (${config.type})`);
136
+
137
+ // Build a database connection from the config
138
+ const provider = await buildProvider(config);
139
+ const results = await provider.query('SELECT * FROM my_table LIMIT 10');
140
+ await provider.close();
141
+ }
142
+ ```
143
+
144
+ **Using Specific Providers:**
145
+
146
+ ```typescript
147
+ import {
148
+ buildSnowflakeProvider,
149
+ buildDatabricksProvider,
150
+ getTdpAthenaProvider,
151
+ type ProviderConfiguration,
152
+ } from '@tetrascience-npm/tetrascience-react-ui/server';
153
+
154
+ // Snowflake
155
+ const snowflakeProvider = await buildSnowflakeProvider(config);
156
+ const data = await snowflakeProvider.query('SELECT * FROM users');
157
+ await snowflakeProvider.close();
158
+
159
+ // Databricks
160
+ const databricksProvider = await buildDatabricksProvider(config);
161
+ const data = await databricksProvider.query('SELECT * FROM events');
162
+ await databricksProvider.close();
163
+
164
+ // TDP Athena (uses environment configuration)
165
+ const athenaProvider = await getTdpAthenaProvider();
166
+ const data = await athenaProvider.query('SELECT * FROM files');
167
+ await athenaProvider.close();
168
+ ```
169
+
170
+ **Exception Handling:**
171
+
172
+ ```typescript
173
+ import {
174
+ QueryError,
175
+ MissingTableError,
176
+ ProviderConnectionError,
177
+ InvalidProviderConfigurationError,
178
+ } from '@tetrascience-npm/tetrascience-react-ui/server';
179
+
180
+ try {
181
+ const results = await provider.query('SELECT * FROM missing_table');
182
+ } catch (error) {
183
+ if (error instanceof MissingTableError) {
184
+ console.error('Table not found:', error.message);
185
+ } else if (error instanceof QueryError) {
186
+ console.error('Query failed:', error.message);
187
+ }
188
+ }
189
+ ```
190
+
191
+ **Environment Variables:**
192
+
193
+ - `DATA_APP_PROVIDER_CONFIG` - JSON override for local development only
194
+ - `CONNECTOR_ID` - Connector ID for fetching providers from TDP
195
+ - `TDP_ENDPOINT` - TDP API base URL
196
+ - `ORG_SLUG` - Organization slug
197
+ - `ATHENA_S3_OUTPUT_LOCATION` - S3 bucket for Athena query results
198
+ - `AWS_REGION` - AWS region for Athena
199
+
200
+ > **Note:** Authentication tokens are obtained from the user's JWT via `jwtManager`. The `TS_AUTH_TOKEN` environment variable is only for local development fallback.
201
+
75
202
  ## TypeScript Support
76
203
 
77
204
  Full TypeScript support with exported types:
78
205
 
79
206
  ```tsx
80
- import { Button } from 'tetrascience-react-ui';
81
- import type { ButtonProps, BarGraphProps, BarDataSeries } from 'tetrascience-react-ui';
207
+ import { Button } from '@tetrascience-npm/tetrascience-react-ui';
208
+ import type { ButtonProps, BarGraphProps, BarDataSeries } from '@tetrascience-npm/tetrascience-react-ui';
82
209
  ```
83
210
 
84
211
  ## Examples
@@ -87,8 +214,8 @@ The repository includes example applications in the `examples/` directory:
87
214
 
88
215
  ```bash
89
216
  # Clone the repository
90
- git clone https://github.com/tetrascience/ts-lib-ui-kit-react.git
91
- cd ts-lib-ui-kit-react
217
+ git clone https://github.com/tetrascience/ts-lib-ui-kit.git
218
+ cd ts-lib-ui-kit
92
219
 
93
220
  # Install dependencies
94
221
  yarn
@@ -97,13 +224,13 @@ yarn
97
224
  yarn workspace vite-themed-app dev
98
225
  ```
99
226
 
100
- Visit http://localhost:5173 to see the example app with custom theming.
227
+ Visit <http://localhost:5173> to see the example app with custom theming.
101
228
 
102
229
  ## Documentation
103
230
 
104
- - [Getting Started Guide](https://github.com/tetrascience/ts-lib-ui-kit-react/blob/main/get_started_1.md) - Step-by-step tutorial
105
- - [Theming Guide](https://github.com/tetrascience/ts-lib-ui-kit-react/blob/main/THEMING.md) - Customise the design system
106
- - [Storybook](https://github.com/tetrascience/ts-lib-ui-kit-react/blob/main/DEVELOPERS.md#development-setup) - Clone the repo and run `yarn storybook`
231
+ - [Getting Started Guide](./get_started_1.md) - Step-by-step tutorial
232
+ - [Theming Guide](./THEMING.md) - Customise the design system
233
+ - [Contributing](./CONTRIBUTING.md#development-setup) - Clone the repo and run `yarn storybook`
107
234
 
108
235
  ## Tech Stack
109
236