@tetrascience-npm/tetrascience-react-ui 0.2.0 → 0.3.0-beta.1.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 +134 -7
- package/dist/cjs/index.js +264 -261
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/providers/athena.js +2 -0
- package/dist/cjs/providers/athena.js.map +1 -0
- package/dist/cjs/providers/databricks.js +2 -0
- package/dist/cjs/providers/databricks.js.map +1 -0
- package/dist/cjs/providers/exceptions-CYktpdqW.js +2 -0
- package/dist/cjs/providers/exceptions-CYktpdqW.js.map +1 -0
- package/dist/cjs/providers/snowflake.js +2 -0
- package/dist/cjs/providers/snowflake.js.map +1 -0
- package/dist/cjs/server.js +2 -0
- package/dist/cjs/server.js.map +1 -0
- package/dist/esm/index.js +294 -291
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/providers/athena.js +2 -0
- package/dist/esm/providers/athena.js.map +1 -0
- package/dist/esm/providers/databricks.js +2 -0
- package/dist/esm/providers/databricks.js.map +1 -0
- package/dist/esm/providers/exceptions-C3uFWZB2.js +2 -0
- package/dist/esm/providers/exceptions-C3uFWZB2.js.map +1 -0
- package/dist/esm/providers/snowflake.js +2 -0
- package/dist/esm/providers/snowflake.js.map +1 -0
- package/dist/esm/server.js +2 -0
- package/dist/esm/server.js.map +1 -0
- package/dist/index.d.ts +1281 -113
- package/dist/providers/athena.d.ts +79 -0
- package/dist/providers/databricks.d.ts +43 -0
- package/dist/providers/snowflake.d.ts +40 -0
- package/dist/providers/types-Ck4uFaGp.d.ts +82 -0
- package/dist/server.d.ts +517 -0
- package/package.json +112 -16
- package/src/styles/README.md +56 -0
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
|
|
@@ -97,7 +224,7 @@ 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
|
|