@camstack/server 1.2.228 → 1.2.230
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/api/trpc/core-cap-bridge.js +7 -9
- package/dist/api/trpc/server-provided-caps.js +44 -0
- package/dist/auth/addon-route-share-gate.js +33 -0
- package/dist/core/addon/addon-registry.service.js +28 -1
- package/dist/core/auth/share-token.service.js +2 -1
- package/dist/core/moleculer/moleculer.service.js +3 -0
- package/dist/main.js +23 -1
- package/package.json +6 -1
|
@@ -23,13 +23,15 @@ exports.describeMeshOrigin = describeMeshOrigin;
|
|
|
23
23
|
exports.buildCoreCapService = buildCoreCapService;
|
|
24
24
|
const system_1 = require("@camstack/system");
|
|
25
25
|
const http_request_census_singleton_js_1 = require("./http-request-census.singleton.js");
|
|
26
|
+
const server_provided_caps_js_1 = require("./server-provided-caps.js");
|
|
26
27
|
const trpc_context_js_1 = require("./trpc.context.js");
|
|
27
28
|
const trpc_middleware_js_1 = require("./trpc.middleware.js");
|
|
28
29
|
/**
|
|
29
30
|
* appRouter namespaces that back the CORE API surface and must be
|
|
30
|
-
* reachable cross-process
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* reachable cross-process: every server-provided hub-service cap
|
|
32
|
+
* (`HUB_SERVICE_CAP_NAMES`, the single source shared with
|
|
33
|
+
* `buildServerProviders`) plus the hand-written core routers from
|
|
34
|
+
* `trpc.router.ts`, minus the deliberate exclusions below.
|
|
33
35
|
*
|
|
34
36
|
* Excluded on purpose:
|
|
35
37
|
* - `auth` — issuing service / scoped tokens over the trusted mesh
|
|
@@ -40,12 +42,8 @@ const trpc_middleware_js_1 = require("./trpc.middleware.js");
|
|
|
40
42
|
* request/reply, and the worker side fast-fails on them by design.
|
|
41
43
|
*/
|
|
42
44
|
const CORE_NAMESPACES = new Set([
|
|
43
|
-
// Service-backed cap routers (no addon provider).
|
|
44
|
-
|
|
45
|
-
'toast',
|
|
46
|
-
'integrations',
|
|
47
|
-
'nodes',
|
|
48
|
-
'addons',
|
|
45
|
+
// Service-backed cap routers (no addon provider) — derived, never copied.
|
|
46
|
+
...server_provided_caps_js_1.HUB_SERVICE_CAP_NAMES.map(server_provided_caps_js_1.capNameToNamespace),
|
|
49
47
|
// Hand-written single-impl core routers.
|
|
50
48
|
'capabilities',
|
|
51
49
|
'notifications',
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The capabilities the SERVER provides — routers mounted from
|
|
4
|
+
* `buildServerProviders` (`trpc.router.ts`) rather than from an addon.
|
|
5
|
+
*
|
|
6
|
+
* One list, two consumers, so they cannot drift:
|
|
7
|
+
* - `buildServerProviders` is typed over {@link ServerProvidedCapName}: a
|
|
8
|
+
* factory added there without a name here, or a name here without a
|
|
9
|
+
* factory, is a compile error.
|
|
10
|
+
* - the `$core-caps` mesh bridge (`core-cap-bridge.ts`) derives its
|
|
11
|
+
* namespace set from {@link HUB_SERVICE_CAP_NAMES}. Before it did, the
|
|
12
|
+
* inference-timeout guard's first fingerprint failed on all three nodes
|
|
13
|
+
* with "no provider registered for cap server-management" — the server
|
|
14
|
+
* provided the cap, no addon did, and the bridge list had been copied by
|
|
15
|
+
* hand before the cap existed.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.ADDON_BACKED_SERVER_CAP_NAMES = exports.HUB_SERVICE_CAP_NAMES = void 0;
|
|
19
|
+
exports.capNameToNamespace = capNameToNamespace;
|
|
20
|
+
/**
|
|
21
|
+
* Caps served by a hub SERVICE. No addon ever registers a provider for them,
|
|
22
|
+
* so a forked runner can reach them only over the `$core-caps` bridge.
|
|
23
|
+
*/
|
|
24
|
+
exports.HUB_SERVICE_CAP_NAMES = [
|
|
25
|
+
'network-quality',
|
|
26
|
+
'system',
|
|
27
|
+
'toast',
|
|
28
|
+
'integrations',
|
|
29
|
+
'nodes',
|
|
30
|
+
'server-management',
|
|
31
|
+
'addons',
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
* Caps whose server factory only WRAPS an addon singleton per request
|
|
35
|
+
* (`webrtc-session` injects the HTTP User-Agent the forked broker cannot
|
|
36
|
+
* see). A forked caller resolves these through the registry like any addon
|
|
37
|
+
* cap; a resolver miss means the addon is down, not that the bridge should
|
|
38
|
+
* answer — so they are deliberately NOT bridged.
|
|
39
|
+
*/
|
|
40
|
+
exports.ADDON_BACKED_SERVER_CAP_NAMES = ['webrtc-session'];
|
|
41
|
+
/** kebab-case cap name → the camelCase appRouter namespace it is mounted as. */
|
|
42
|
+
function capNameToNamespace(capName) {
|
|
43
|
+
return capName.replace(/-([a-z])/g, (_m, c) => c.toUpperCase());
|
|
44
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SHARE_DEVICES_HEADER = exports.SHARE_KIND_HEADER = void 0;
|
|
4
|
+
exports.gateAddonShareToken = gateAddonShareToken;
|
|
5
|
+
exports.stripShareHeaders = stripShareHeaders;
|
|
6
|
+
exports.SHARE_KIND_HEADER = 'x-camstack-share-kind';
|
|
7
|
+
exports.SHARE_DEVICES_HEADER = 'x-camstack-share-devices';
|
|
8
|
+
function gateAddonShareToken(input) {
|
|
9
|
+
if (input.record === null)
|
|
10
|
+
return { ok: false, status: 401, error: 'Invalid token' };
|
|
11
|
+
const kind = input.record.scope.kind;
|
|
12
|
+
if (!(input.endpoint.share ?? []).includes(kind)) {
|
|
13
|
+
return { ok: false, status: 403, error: 'Share token not accepted here' };
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
ok: true,
|
|
17
|
+
headers: {
|
|
18
|
+
[exports.SHARE_KIND_HEADER]: kind,
|
|
19
|
+
[exports.SHARE_DEVICES_HEADER]: input.record.scope.deviceIds.join(','),
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** The forwarded header set without any share header the client supplied. */
|
|
24
|
+
function stripShareHeaders(headers) {
|
|
25
|
+
const out = {};
|
|
26
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
27
|
+
const lower = key.toLowerCase();
|
|
28
|
+
if (lower === exports.SHARE_KIND_HEADER || lower === exports.SHARE_DEVICES_HEADER)
|
|
29
|
+
continue;
|
|
30
|
+
out[key] = value;
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
@@ -37,6 +37,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
37
37
|
exports.AddonRegistryService = void 0;
|
|
38
38
|
exports.shouldEvictMissingOnDisk = shouldEvictMissingOnDisk;
|
|
39
39
|
exports.addonUpdatePayload = addonUpdatePayload;
|
|
40
|
+
exports.parseDataPlaneEndpoints = parseDataPlaneEndpoints;
|
|
40
41
|
exports.shouldEmitProviderRegisteredReady = shouldEmitProviderRegisteredReady;
|
|
41
42
|
const node_crypto_1 = require("node:crypto");
|
|
42
43
|
const fs = __importStar(require("node:fs"));
|
|
@@ -204,9 +205,35 @@ function parseDataPlaneEndpoints(raw) {
|
|
|
204
205
|
if (typeof prefix !== 'string' || typeof baseUrl !== 'string' || typeof secret !== 'string') {
|
|
205
206
|
throw new Error('data-planes: endpoint descriptor missing prefix/baseUrl/secret');
|
|
206
207
|
}
|
|
207
|
-
|
|
208
|
+
const share = parseDataPlaneShare(Reflect.get(entry, 'share'));
|
|
209
|
+
return {
|
|
210
|
+
prefix,
|
|
211
|
+
access: asRouteAccess(Reflect.get(entry, 'access')),
|
|
212
|
+
baseUrl,
|
|
213
|
+
secret,
|
|
214
|
+
...(share !== undefined ? { share } : {}),
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* The share opt-in, or `undefined` when the plane declared none. An unknown
|
|
220
|
+
* kind is refused loudly: admitting it silently would let a typo open a
|
|
221
|
+
* plane to share tokens nobody scoped.
|
|
222
|
+
*/
|
|
223
|
+
function parseDataPlaneShare(value) {
|
|
224
|
+
if (value === undefined)
|
|
225
|
+
return undefined;
|
|
226
|
+
if (!Array.isArray(value))
|
|
227
|
+
throw new Error('data-planes: `share` is not an array');
|
|
228
|
+
return value.map((kind) => {
|
|
229
|
+
if (!isShareViewKind(kind))
|
|
230
|
+
throw new Error(`data-planes: unknown share kind ${String(kind)}`);
|
|
231
|
+
return kind;
|
|
208
232
|
});
|
|
209
233
|
}
|
|
234
|
+
function isShareViewKind(value) {
|
|
235
|
+
return typeof value === 'string' && types_1.SHARE_VIEW_KINDS.includes(value);
|
|
236
|
+
}
|
|
210
237
|
// Phase 11 (settings redesign): `stripValue` helper and the legacy
|
|
211
238
|
// `getAddonConfigSchema / getAddonConfig / updateAddonConfig` adapter
|
|
212
239
|
// shim that consumed it were deleted. All settings flow through the
|
|
@@ -58,6 +58,7 @@ exports.ShareTokenService = exports.ShareTokenRecordSchema = exports.ShareTokenS
|
|
|
58
58
|
* live in, reached directly instead of over the settings-store cap since
|
|
59
59
|
* this service is hub-resident). Collection: `share_view_tokens`.
|
|
60
60
|
*/
|
|
61
|
+
const types_1 = require("@camstack/types");
|
|
61
62
|
const crypto = __importStar(require("node:crypto"));
|
|
62
63
|
const zod_1 = require("zod");
|
|
63
64
|
/**
|
|
@@ -115,7 +116,7 @@ exports.SHARE_TOKEN_MAX_DEVICES = 64;
|
|
|
115
116
|
* WebRTC session, and a grid link cannot read a track.
|
|
116
117
|
*/
|
|
117
118
|
exports.ShareTokenScopeSchema = zod_1.z.object({
|
|
118
|
-
kind: zod_1.z.enum(
|
|
119
|
+
kind: zod_1.z.enum(types_1.SHARE_VIEW_KINDS),
|
|
119
120
|
deviceIds: zod_1.z.array(zod_1.z.number().int().nonnegative()).min(1).max(exports.SHARE_TOKEN_MAX_DEVICES),
|
|
120
121
|
});
|
|
121
122
|
/** Persisted record — never leaves the server with `tokenHash` attached. */
|
|
@@ -349,6 +349,9 @@ class MoleculerService {
|
|
|
349
349
|
// multi-node addon cap is covered with no change here.
|
|
350
350
|
isCoreServiceCap: (capName) => (0, core_cap_bridge_js_1.isCoreServiceCapName)(capName),
|
|
351
351
|
logger: {
|
|
352
|
+
debug: (msg, meta) => logger.debug(msg, meta !== null && meta !== undefined
|
|
353
|
+
? { meta: meta }
|
|
354
|
+
: undefined),
|
|
352
355
|
warn: (msg, meta) => logger.warn(msg, meta !== null && meta !== undefined
|
|
353
356
|
? { meta: meta }
|
|
354
357
|
: undefined),
|
package/dist/main.js
CHANGED
|
@@ -78,6 +78,7 @@ const trpc_error_principal_1 = require("./api/trpc/trpc-error-principal");
|
|
|
78
78
|
const trpc_error_device_tags_1 = require("./api/trpc/trpc-error-device-tags");
|
|
79
79
|
const ws_request_census_1 = require("./api/trpc/ws-request-census");
|
|
80
80
|
const addon_route_jwt_gate_js_1 = require("./auth/addon-route-jwt-gate.js");
|
|
81
|
+
const addon_route_share_gate_js_1 = require("./auth/addon-route-share-gate.js");
|
|
81
82
|
const session_cookie_js_1 = require("./auth/session-cookie.js");
|
|
82
83
|
const boot_config_1 = require("./boot/boot-config");
|
|
83
84
|
const integration_id_backfill_1 = require("./boot/integration-id-backfill");
|
|
@@ -966,6 +967,7 @@ async function bootstrap() {
|
|
|
966
967
|
const dpMatch = dataPlaneRegistry.match(addonId, subPath);
|
|
967
968
|
if (dpMatch) {
|
|
968
969
|
const access = dpMatch.endpoint.access;
|
|
970
|
+
let shareHeaders = null;
|
|
969
971
|
if (access !== 'public') {
|
|
970
972
|
const authHeader = request.headers.authorization;
|
|
971
973
|
const cookieToken = request.cookies?.[session_cookie_js_1.SESSION_COOKIE];
|
|
@@ -973,7 +975,18 @@ async function bootstrap() {
|
|
|
973
975
|
return reply.status(401).send({ error: 'Unauthorized' });
|
|
974
976
|
}
|
|
975
977
|
const token = authHeader ? authHeader.replace('Bearer ', '') : cookieToken;
|
|
976
|
-
if (token.startsWith('
|
|
978
|
+
if (token.startsWith('csv_')) {
|
|
979
|
+
// A share link (`csv_*`): admitted only by a plane that opted in
|
|
980
|
+
// to its scope kind, and the scope's devices travel in headers the
|
|
981
|
+
// HUB sets — whatever the client sent under those names is dropped
|
|
982
|
+
// (see `addon-route-share-gate.ts`).
|
|
983
|
+
const record = await shareTokenService.validate(token);
|
|
984
|
+
const gate = (0, addon_route_share_gate_js_1.gateAddonShareToken)({ record, endpoint: dpMatch.endpoint });
|
|
985
|
+
if (!gate.ok)
|
|
986
|
+
return reply.status(gate.status).send({ error: gate.error });
|
|
987
|
+
shareHeaders = gate.headers;
|
|
988
|
+
}
|
|
989
|
+
else if (token.startsWith('cst_')) {
|
|
977
990
|
const userMgmt = capabilityRegistry?.getSingleton('user-management');
|
|
978
991
|
if (!userMgmt)
|
|
979
992
|
return reply.status(503).send({ error: 'User management not available' });
|
|
@@ -1003,6 +1016,15 @@ async function bootstrap() {
|
|
|
1003
1016
|
// multiplexes by prefix, so it strips the prefix itself. (`dpMatch.rest`
|
|
1004
1017
|
// is only used to pick the endpoint, not to rewrite the path.)
|
|
1005
1018
|
const upstreamPath = `/${subPath}${queryString}`;
|
|
1019
|
+
// The share headers are the HUB's to write: drop whatever the client
|
|
1020
|
+
// sent under those names, then set the validated scope, if any.
|
|
1021
|
+
for (const name of Object.keys(request.raw.headers)) {
|
|
1022
|
+
if (name.toLowerCase() === addon_route_share_gate_js_1.SHARE_KIND_HEADER ||
|
|
1023
|
+
name.toLowerCase() === addon_route_share_gate_js_1.SHARE_DEVICES_HEADER)
|
|
1024
|
+
delete request.raw.headers[name];
|
|
1025
|
+
}
|
|
1026
|
+
if (shareHeaders !== null)
|
|
1027
|
+
Object.assign(request.raw.headers, shareHeaders);
|
|
1006
1028
|
// Take over the socket — `proxyToUpstream` drives the raw response.
|
|
1007
1029
|
reply.hijack();
|
|
1008
1030
|
const replayBody = request.body === undefined
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@camstack/server",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.230",
|
|
4
4
|
"private": false,
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -78,5 +78,10 @@
|
|
|
78
78
|
"vitest": "*",
|
|
79
79
|
"@camstack/node-root": "*",
|
|
80
80
|
"tsup": "^8.0.0"
|
|
81
|
+
},
|
|
82
|
+
"nx": {
|
|
83
|
+
"implicitDependencies": [
|
|
84
|
+
"@camstack/addon-benchmark"
|
|
85
|
+
]
|
|
81
86
|
}
|
|
82
87
|
}
|