@tetrascience-npm/tetrascience-react-ui 0.4.0-beta.1.1 → 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 +86 -1
- package/dist/cjs/index.js +188 -173
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +188 -173
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +701 -92
- package/dist/server.d.ts +12 -4
- package/package.json +20 -14
- package/src/styles/README.md +0 -56
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
React component library for building TetraScience applications.
|
|
4
4
|
|
|
5
|
+
[](https://www.npmjs.com/package/@tetrascience-npm/tetrascience-react-ui) [](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
|
|
@@ -121,10 +129,10 @@ import {
|
|
|
121
129
|
const userToken = await jwtManager.getTokenFromExpressRequest(req);
|
|
122
130
|
|
|
123
131
|
// Create TDPClient with the user's auth token
|
|
132
|
+
// Other fields (tdpEndpoint, connectorId, orgSlug) are read from environment variables
|
|
124
133
|
const client = new TDPClient({
|
|
125
134
|
authToken: userToken,
|
|
126
135
|
artifactType: 'data-app',
|
|
127
|
-
orgSlug: process.env.ORG_SLUG,
|
|
128
136
|
});
|
|
129
137
|
await client.init();
|
|
130
138
|
|
|
@@ -199,6 +207,81 @@ try {
|
|
|
199
207
|
|
|
200
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.
|
|
201
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
|
+
|
|
202
285
|
## TypeScript Support
|
|
203
286
|
|
|
204
287
|
Full TypeScript support with exported types:
|
|
@@ -228,6 +311,8 @@ Visit <http://localhost:5173> to see the example app with custom theming.
|
|
|
228
311
|
|
|
229
312
|
## Documentation
|
|
230
313
|
|
|
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
|
|
231
316
|
- [Getting Started Guide](./get_started_1.md) - Step-by-step tutorial
|
|
232
317
|
- [Theming Guide](./THEMING.md) - Customise the design system
|
|
233
318
|
- [Contributing](./CONTRIBUTING.md#development-setup) - Clone the repo and run `yarn storybook`
|