trucontext 0.4.1 → 0.5.0
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/package.json +1 -1
- package/src/client.js +8 -6
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
// client.js — HTTP client for both API planes
|
|
2
|
-
// Auto-refreshes JWT,
|
|
2
|
+
// Auto-refreshes JWT, auto-prefixes appId in data plane paths.
|
|
3
3
|
|
|
4
4
|
import { ensureFreshToken } from './auth.js';
|
|
5
5
|
import { getActiveApp, DATA_PLANE_URL, CONTROL_PLANE_URL } from './config.js';
|
|
6
6
|
|
|
7
7
|
async function request(baseUrl, method, path, body, retry = true) {
|
|
8
8
|
const token = await ensureFreshToken();
|
|
9
|
-
const activeApp = getActiveApp();
|
|
10
9
|
|
|
11
10
|
const headers = {
|
|
12
11
|
'Authorization': `Bearer ${token}`,
|
|
13
12
|
'Content-Type': 'application/json',
|
|
14
13
|
};
|
|
15
|
-
if (activeApp) {
|
|
16
|
-
headers['X-TruContext-App'] = activeApp;
|
|
17
|
-
}
|
|
18
14
|
|
|
19
15
|
const ac = new AbortController();
|
|
20
16
|
const timeout = setTimeout(() => ac.abort(), 15000);
|
|
@@ -69,7 +65,13 @@ async function handleResponse(res) {
|
|
|
69
65
|
// --- Public API ---
|
|
70
66
|
|
|
71
67
|
export function dataPlane(method, path, body) {
|
|
72
|
-
|
|
68
|
+
const appId = getActiveApp();
|
|
69
|
+
if (!appId) {
|
|
70
|
+
throw new Error('No active app. Run: trucontext use <app-id>');
|
|
71
|
+
}
|
|
72
|
+
// Auto-prefix: /v1/entities → /v1/apps/{appId}/entities
|
|
73
|
+
const appPath = path.replace(/^\/v1\//, `/v1/apps/${appId}/`);
|
|
74
|
+
return request(DATA_PLANE_URL, method, appPath, body);
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
export function controlPlane(method, path, body) {
|