@xcitedbs/client 0.3.3 → 0.3.4
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/dist/client.test.js +45 -0
- package/dist/types.d.ts +13 -1
- package/llms.txt +13 -1
- package/package.json +1 -1
package/dist/client.test.js
CHANGED
|
@@ -315,6 +315,51 @@ const types_js_1 = require("./types.js");
|
|
|
315
315
|
}));
|
|
316
316
|
strict_1.default.equal(h.get('X-Test-Auth'), 'preserve');
|
|
317
317
|
});
|
|
318
|
+
(0, node_test_1.it)('forwards bootstrap.triggers and surfaces triggers_created on the client', async () => {
|
|
319
|
+
const captured = { value: null };
|
|
320
|
+
const orig = globalThis.fetch;
|
|
321
|
+
globalThis.fetch = node_test_1.mock.fn(async (_input, init) => {
|
|
322
|
+
captured.value = { body: JSON.parse(String(init?.body ?? '{}')) };
|
|
323
|
+
return new Response(JSON.stringify({
|
|
324
|
+
session_token: 'tok-trig',
|
|
325
|
+
expires_at: Date.now() + 60000,
|
|
326
|
+
session_ttl_seconds: 60,
|
|
327
|
+
bootstrap: {
|
|
328
|
+
user_isolation_applied: false,
|
|
329
|
+
developer_bypass_applied: false,
|
|
330
|
+
policies_created: [],
|
|
331
|
+
triggers_created: ['t-write-meta'],
|
|
332
|
+
},
|
|
333
|
+
}), { status: 201 });
|
|
334
|
+
});
|
|
335
|
+
try {
|
|
336
|
+
const client = await client_js_1.XCiteDBClient.createTestSession({
|
|
337
|
+
baseUrl: 'http://127.0.0.1:9',
|
|
338
|
+
apiKey: 'k',
|
|
339
|
+
bootstrap: {
|
|
340
|
+
triggers: [
|
|
341
|
+
{
|
|
342
|
+
trigger_id: 't-write-meta',
|
|
343
|
+
trigger: {
|
|
344
|
+
event: 'meta_changed',
|
|
345
|
+
match: { identifiers: [{ match_start: '/' }] },
|
|
346
|
+
action: { unquery: { x: '$count' }, target_identifier: '/_audit', meta_path: 'n', mode: 'set' },
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
],
|
|
350
|
+
},
|
|
351
|
+
});
|
|
352
|
+
const body = captured.value.body;
|
|
353
|
+
const boot = body.bootstrap;
|
|
354
|
+
const triggers = boot.triggers;
|
|
355
|
+
strict_1.default.equal(triggers.length, 1);
|
|
356
|
+
strict_1.default.equal(triggers[0].trigger_id, 't-write-meta');
|
|
357
|
+
strict_1.default.deepEqual(client.lastTestSessionBootstrap?.triggers_created, ['t-write-meta']);
|
|
358
|
+
}
|
|
359
|
+
finally {
|
|
360
|
+
globalThis.fetch = orig;
|
|
361
|
+
}
|
|
362
|
+
});
|
|
318
363
|
});
|
|
319
364
|
(0, node_test_1.describe)('enableUserIsolation', () => {
|
|
320
365
|
(0, node_test_1.it)('with explicit config, configures prefixing without any HTTP call', async () => {
|
package/dist/types.d.ts
CHANGED
|
@@ -720,12 +720,24 @@ export interface TestSessionBootstrap {
|
|
|
720
720
|
policy_id: string;
|
|
721
721
|
policy: SecurityPolicy;
|
|
722
722
|
}>;
|
|
723
|
+
/**
|
|
724
|
+
* Per-test trigger set. Installed into the synthetic test tenant only — the project's
|
|
725
|
+
* global trigger registry is untouched. Each entry is `{ trigger_id, trigger }`; the
|
|
726
|
+
* `trigger` shape matches `upsertTrigger`. Validation errors abort the bootstrap with
|
|
727
|
+
* `400 bootstrap_trigger_invalid`; storage failures abort with `500 bootstrap_trigger_failed`.
|
|
728
|
+
*/
|
|
729
|
+
triggers?: Array<{
|
|
730
|
+
trigger_id: string;
|
|
731
|
+
trigger: TriggerDefinition;
|
|
732
|
+
}>;
|
|
723
733
|
}
|
|
724
734
|
/** `bootstrap` summary returned by the server after a bootstrapped test session is created. */
|
|
725
735
|
export interface TestSessionBootstrapSummary {
|
|
726
736
|
user_isolation_applied?: boolean;
|
|
727
737
|
developer_bypass_applied?: boolean;
|
|
728
738
|
policies_created?: string[];
|
|
739
|
+
/** IDs of triggers installed by the bootstrap (in input order). */
|
|
740
|
+
triggers_created?: string[];
|
|
729
741
|
}
|
|
730
742
|
/** One row from `GET /api/v1/test/sessions` (management; no `X-Test-Session` on that route). */
|
|
731
743
|
export interface TestSessionInfo {
|
|
@@ -749,7 +761,7 @@ export interface CreateTestSessionOptions {
|
|
|
749
761
|
* When true, creates an overlay test session: writable ephemeral LMDB with production project data as read-only base.
|
|
750
762
|
*/
|
|
751
763
|
overlay?: boolean;
|
|
752
|
-
/** Optional server-side bootstrap (user isolation, developer_bypass, policies). */
|
|
764
|
+
/** Optional server-side bootstrap (user isolation, developer_bypass, policies, triggers). */
|
|
753
765
|
bootstrap?: TestSessionBootstrap;
|
|
754
766
|
/**
|
|
755
767
|
* Test-session auth fidelity mode (`X-Test-Auth` header on the returned client).
|
package/llms.txt
CHANGED
|
@@ -138,11 +138,23 @@ SDKs surface these fields on typed errors (e.g. `XCiteDBForbiddenError.policyId`
|
|
|
138
138
|
"bootstrap": {
|
|
139
139
|
"user_isolation": { "enabled": true, "namespace_pattern": "/spaces/${user.id}" },
|
|
140
140
|
"developer_bypass": true,
|
|
141
|
-
"policies": []
|
|
141
|
+
"policies": [],
|
|
142
|
+
"triggers": [
|
|
143
|
+
{
|
|
144
|
+
"trigger_id": "audit-writes",
|
|
145
|
+
"trigger": {
|
|
146
|
+
"event": "meta_changed",
|
|
147
|
+
"match": { "identifiers": [{ "match_start": "/" }] },
|
|
148
|
+
"action": { "unquery": { "n": "$count" }, "target_identifier": "/_audit", "meta_path": "n", "mode": "set" }
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
]
|
|
142
152
|
}
|
|
143
153
|
}
|
|
144
154
|
```
|
|
145
155
|
|
|
156
|
+
`bootstrap.triggers` installs per-test triggers into the synthetic test tenant only — the project's global trigger registry (`/_xcitedb/triggers`) is never touched. Each entry is `{ trigger_id, trigger }` (same shape as `upsertTrigger`); validation errors abort with `400 bootstrap_trigger_invalid`. The summary echoes back `triggers_created: string[]`.
|
|
157
|
+
|
|
146
158
|
If you skip the bootstrap, an app-user JWT cannot read or write `/spaces/<userId>/...` — even paths the user "owns" — and you will see 403 with reason `tenant_security_unconfigured`.
|
|
147
159
|
|
|
148
160
|
**SDK one-liners for bootstrap:** **JS:** `XCiteDBClient.createTestSession({ baseUrl, apiKey, testRequireAuth: true, bootstrap: { user_isolation: { enabled: true, namespace_pattern: '/spaces/${user.id}' }, developer_bypass: true } })`. **Python:** `async with XCiteDBClient.test_session(base_url, api_key=sk, test_require_auth=True, bootstrap={...}) as c:`. **C++:** set `options.test_session_bootstrap = nlohmann::json::parse(R"(...)");` then `XCiteDBClient::create_test_session(options)`.
|