@loxtep/sdk 0.7.1 → 0.7.7

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.
@@ -1,7 +1,8 @@
1
1
  # SDK Quick Reference Card
2
2
 
3
- Concise cheat sheet for common Loxtep SDK operations. For full walkthroughs,
4
- see the [Getting Started Guide](./getting-started.md).
3
+ Concise cheat sheet for common Loxtep SDK operations (Node.js **v0.7+** MCP
4
+ facades). For full walkthroughs, see the [Getting Started Guide](./getting-started.md)
5
+ (programmatic) or [Code-first CLI guide](./code-first-cli.md) (`loxtep init`).
5
6
 
6
7
  ---
7
8
 
@@ -14,11 +15,15 @@ import { LoxtepClient } from '@loxtep/sdk';
14
15
 
15
16
  const client = new LoxtepClient({
16
17
  api_url: process.env.LOXTEP_API_URL,
18
+ auth: { type: 'jwt', token: process.env.LOXTEP_AUTH_TOKEN! },
17
19
  organization_id: process.env.LOXTEP_ORGANIZATION_ID,
18
20
  project_id: process.env.LOXTEP_PROJECT_ID,
19
21
  instance_id: process.env.LOXTEP_INSTANCE_ID,
20
22
  region: process.env.LOXTEP_REGION,
21
23
  });
24
+
25
+ // Or from workspace files after `loxtep init` + `loxtep login`:
26
+ const wsClient = LoxtepClient.fromWorkspace();
22
27
  ```
23
28
 
24
29
  ### Python
@@ -36,21 +41,17 @@ client = LoxtepClient(
36
41
  )
37
42
  ```
38
43
 
39
- > If you ran `loxtep init`, the SDK reads defaults from
40
- > `~/.loxtep/config.json` — you can use `new LoxtepClient()` with no args.
41
-
42
44
  ---
43
45
 
44
46
  ## Writing Events
45
47
 
46
- **Recommended: use `data_products.get_writer('name')`** — the SDK resolves
47
- queue, bot_id, and stream bus config automatically from deployment metadata.
48
+ **Recommended: `client.get_writer('name')`** — resolves queue, bot_id, and stream
49
+ bus config from deployment metadata.
48
50
 
49
51
  ### Node.js
50
52
 
51
53
  ```typescript
52
- // Resolve by name — no manual queue/bot/stream config needed
53
- const writer = await client.data_products.get_writer('my-data-product');
54
+ const writer = await client.get_writer('my-data-product');
54
55
 
55
56
  writer.write({ id: 'evt-1', payload: { key: 'value' } });
56
57
  writer.write({ id: 'evt-2', payload: { key: 'value' } });
@@ -61,8 +62,7 @@ await writer.close(); // flushes all buffered events
61
62
  ### Python
62
63
 
63
64
  ```python
64
- # Resolve by name — no manual queue/bot/stream config needed
65
- writer = await client.data_products.get_writer("my-data-product")
65
+ writer = await client.get_writer("my-data-product")
66
66
 
67
67
  writer.write({"id": "evt-1", "payload": {"key": "value"}})
68
68
  writer.write({"id": "evt-2", "payload": {"key": "value"}})
@@ -74,13 +74,12 @@ await writer.close() # flushes all buffered events
74
74
 
75
75
  ## Reading Events
76
76
 
77
- **Recommended: use `data_products.get_reader('name')`** — resolves everything
78
- automatically.
77
+ **Recommended: `client.get_reader('name')`**
79
78
 
80
79
  ### Node.js
81
80
 
82
81
  ```typescript
83
- const reader = await client.data_products.get_reader('my-data-product');
82
+ const reader = await client.get_reader('my-data-product');
84
83
 
85
84
  for await (const event of reader) {
86
85
  console.log(event);
@@ -90,16 +89,16 @@ for await (const event of reader) {
90
89
  ### Python
91
90
 
92
91
  ```python
93
- reader = await client.data_products.get_reader("my-data-product")
92
+ reader = await client.get_reader("my-data-product")
94
93
 
95
94
  for event in reader:
96
95
  print(event)
97
96
  ```
98
97
 
99
- ### Advanced: manual queue reader (`queues` namespace)
98
+ ### Advanced: manual queue reader (`client.observe`)
100
99
 
101
100
  ```typescript
102
- const reader = await client.queues.open_reader({
101
+ const reader = await client.observe.open_reader({
103
102
  bot_id: 'my-reader',
104
103
  queue_name: 'raw-events',
105
104
  });
@@ -111,14 +110,17 @@ reader.close();
111
110
 
112
111
  ---
113
112
 
114
- ## Data Products
113
+ ## Data Products (CRUD / stream / replay)
114
+
115
+ Under **`client.build.data_products`** for control-plane APIs; top-level
116
+ `get_writer` / `get_reader` for live I/O.
115
117
 
116
118
  ### Stream Live Events
117
119
 
118
120
  #### Node.js
119
121
 
120
122
  ```typescript
121
- const stream = await client.data_products.stream('<data_product_id>', {
123
+ const stream = await client.build.data_products.stream('<data_product_id>', {
122
124
  bot_id: 'my-stream-bot',
123
125
  });
124
126
 
@@ -127,128 +129,88 @@ for await (const event of stream) {
127
129
  }
128
130
  ```
129
131
 
130
- #### Python
131
-
132
- ```python
133
- stream = client.data_products.stream("<data_product_id>", {
134
- "bot_id": "my-stream-bot",
135
- })
136
-
137
- for event in stream:
138
- print(event)
139
- ```
140
-
141
132
  ### Replay Historical Events
142
133
 
143
- #### Node.js
144
-
145
134
  ```typescript
146
- const events = await client.data_products.replay('<data_product_id>', {
135
+ for await (const event of client.build.data_products.replay('<data_product_id>', {
147
136
  start: '2024-01-01T00:00:00Z',
148
137
  end: '2024-01-02T00:00:00Z',
149
- });
150
- ```
151
-
152
- #### Python
153
-
154
- ```python
155
- events = client.data_products.replay("<data_product_id>", {
156
- "start": "2024-01-01T00:00:00Z",
157
- "end": "2024-01-02T00:00:00Z",
158
- })
138
+ })) {
139
+ console.log(event);
140
+ }
159
141
  ```
160
142
 
161
- ### List and Get Data Products
162
-
163
- #### Node.js
143
+ ### List and Get
164
144
 
165
145
  ```typescript
166
- const products = await client.data_products.list();
167
- const product = await client.data_products.get('<data_product_id>');
168
- ```
169
-
170
- #### Python
171
-
172
- ```python
173
- products = client.data_products.list()
174
- product = client.data_products.get("<data_product_id>")
146
+ const products = await client.build.data_products.list();
147
+ const product = await client.build.data_products.get('<data_product_id>');
175
148
  ```
176
149
 
177
150
  ---
178
151
 
179
152
  ## Workflows and Connectors
180
153
 
181
- ### List Workflows
182
-
183
- #### Node.js
184
-
185
- ```typescript
186
- const workflows = await client.workflows.list({ project_id: '<project_id>' });
187
- ```
188
-
189
- #### Python
190
-
191
- ```python
192
- workflows = client.workflows.list(project_id="<project_id>")
193
- ```
194
-
195
- ### Get Connector
196
-
197
- #### Node.js
198
-
199
154
  ```typescript
200
- const connector = await client.connectors.get('<connector_id>');
201
- ```
202
-
203
- #### Python
204
-
205
- ```python
206
- connector = client.connectors.get("<connector_id>")
155
+ const workflows = await client.build.workflows.list({ project_id: '<project_id>' });
156
+ const connector = await client.connect.connectors.get('<connector_id>');
157
+ const hits = await client.query.catalog.search({ query: 'orders' });
207
158
  ```
208
159
 
209
160
  ---
210
161
 
211
162
  ## Quick Reference Table
212
163
 
213
- | Task | Node.js | Python |
214
- |------|---------|--------|
215
- | **Init client** | `new LoxtepClient(options)` | `LoxtepClient(**options)` |
216
- | **Write events** | `await client.data_products.get_writer('name')` → `writer.write(evt)` → `writer.close()` | Same API |
217
- | **Read events** | `await client.data_products.get_reader('name')` → `for await (const e of reader)` | Same API |
218
- | **Read (low-level)** | `client.queues.open_reader({ bot_id, queue_name })` → `reader.read()` | Same API |
219
- | **Stream live** | `client.data_products.stream(id, opts)` | Same API |
220
- | **Replay history** | `client.data_products.replay(id, opts)` | Same API |
221
- | **List data products** | `client.data_products.list()` | Same API |
222
- | **Get data product** | `client.data_products.get(id)` | Same API |
223
- | **List workflows** | `client.workflows.list({ project_id })` | Same API |
224
- | **Get connector** | `client.connectors.get(id)` | Same API |
225
- | **Invalidate cache** | `client.data_products.invalidate_cache('name')` | Same API |
164
+ | Task | Node.js (v0.7+) |
165
+ |------|-----------------|
166
+ | **Init client** | `new LoxtepClient(options)` or `LoxtepClient.fromWorkspace()` |
167
+ | **Write events** | `await client.get_writer('name')` → `writer.write(evt)` → `writer.close()` |
168
+ | **Read events** | `await client.get_reader('name')` → `for await (const e of reader)` |
169
+ | **Read (low-level)** | `client.observe.open_reader({ bot_id, queue_name })` |
170
+ | **Stream live** | `client.build.data_products.stream(id, opts)` |
171
+ | **Replay history** | `client.build.data_products.replay(id, opts)` |
172
+ | **List data products** | `client.build.data_products.list()` |
173
+ | **List workflows** | `client.build.workflows.list({ project_id })` |
174
+ | **Get connector** | `client.connect.connectors.get(id)` |
175
+ | **Catalog search** | `client.query.catalog.search({ query })` |
176
+ | **Invalidate cache** | `client.build.data_products.invalidate_cache('name')` |
177
+
178
+ See [MCP → SDK mapping](./sdk-mcp-mapping.md) for all 10 facades.
226
179
 
227
180
  ---
228
181
 
229
182
  ## CLI Shortcuts
230
183
 
184
+ Workspace lifecycle (requires `loxtep init` first — see [Code-first CLI guide](./code-first-cli.md)):
185
+
231
186
  ```bash
232
- # Log in
233
- npx loxtep login
187
+ pnpm exec loxtep init [--template shopify-orders]
188
+ pnpm exec loxtep login
189
+ pnpm exec loxtep attach --instance prod
190
+ pnpm exec loxtep generate
191
+ pnpm exec loxtep test my-module --event ./events/sample.json
192
+ pnpm exec loxtep deploy
193
+ ```
234
194
 
235
- # Initialize config
236
- npx loxtep init
195
+ Other commands:
237
196
 
238
- # Export connector config (shell, json, or env format)
239
- npx loxtep config export --from-connector "<connector_id>" --format sh
240
- npx loxtep config export --from-connector "<connector_id>" --format json
241
- npx loxtep config export --from-connector "<connector_id>" --format env
197
+ ```bash
198
+ pnpm exec loxtep login
199
+ pnpm exec loxtep config export --from-connector "<connector_id>" --format json
242
200
  ```
243
201
 
244
202
  ---
245
203
 
246
204
  ## Auth Precedence
247
205
 
248
- The SDK resolves authentication in this order:
206
+ CLI and `fromWorkspace()` resolve tokens in this order:
207
+
208
+ 1. `LOXTEP_AUTH_TOKEN` (CLI) / `LOXTEP_TOKEN` (auto-config env)
209
+ 2. Project-local `.loxtep/credentials.json`
210
+ 3. `~/.loxtep/credentials.json` (from `loxtep login`)
249
211
 
250
- 1. `LOXTEP_AUTH_TOKEN` environment variable
251
- 2. `~/.loxtep/credentials.json` (from `loxtep login`)
212
+ Pass `auth: { type: 'jwt', token }` explicitly when constructing `LoxtepClient`
213
+ in application code.
252
214
 
253
215
  ---
254
216
 
@@ -257,5 +219,5 @@ The SDK resolves authentication in this order:
257
219
  | Resource | Description |
258
220
  |----------|-------------|
259
221
  | [Getting Started Guide](./getting-started.md) | Zero-to-first-event walkthrough |
260
- | [Event Replay Cookbook](./event-replay-cookbook.md) | Patterns for replaying historical events |
222
+ | [Event Replay Cookbook](./event-replay-cookbook.md) | Replay patterns (`build.data_products`, `observe`) |
261
223
  | [MCP → SDK Mapping](./sdk-mcp-mapping.md) | How MCP tools map to SDK methods |
@@ -20,15 +20,15 @@ authenticates via its own OAuth flow in the MCP client, not this file.
20
20
  | Typed REST from Node services, scripts, CI | **`@loxtep/sdk`** (`LoxtepClient`) |
21
21
  | Quick operator commands, token bootstrap | **`loxtep` CLI** (ships with the SDK) |
22
22
  | **Live** queue produce/consume | **SDK** with stream config |
23
- | **Historical** replay / trace-style reads | **SDK** `data_products.replay()` (REST API) |
23
+ | **Historical** replay / trace-style reads | **SDK** `client.build.data_products.replay()` (REST API) |
24
24
 
25
- There is **no** required joint npm install of MCP and SDK; pair them by
25
+ There is **no** required joint package install of MCP and SDK; pair them by
26
26
  **config + docs**, not a metapackage.
27
27
 
28
28
  ## Install
29
29
 
30
30
  ```bash
31
- npm install @loxtep/sdk
31
+ pnpm add @loxtep/sdk
32
32
  # Node.js 22+ recommended (see package engines).
33
33
  ```
34
34
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loxtep/sdk",
3
- "version": "0.7.1",
3
+ "version": "0.7.7",
4
4
  "description": "Loxtep SDK for Node.js — the Enterprise Context Layer: data products, workflows, projects, queues, and machine-usable context for AI",
5
5
  "author": "Loxtep <engineering@loxtep.io>",
6
6
  "homepage": "https://loxtep.io",