@camstack/server 1.2.229 → 1.2.231

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.
@@ -6950,6 +6950,14 @@ function createCapRouter_pipelineOrchestrator(getProvider, _createRemoteProxy) {
6950
6950
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
6951
6951
  return p.setAgentCapabilities(input);
6952
6952
  }),
6953
+ setAgentDecodeLimits: trpc_middleware_js_1.adminProcedure
6954
+ .input(types_87.pipelineOrchestratorCapability.methods.setAgentDecodeLimits.input.loose())
6955
+ .output(types_87.pipelineOrchestratorCapability.methods.setAgentDecodeLimits.output)
6956
+ .mutation(async ({ input, ctx }) => {
6957
+ const p = requireCapProvider('pipeline-orchestrator', () => getProvider(ctx));
6958
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
6959
+ return p.setAgentDecodeLimits(input);
6960
+ }),
6953
6961
  setAgentReachableHost: trpc_middleware_js_1.adminProcedure
6954
6962
  .input(types_87.pipelineOrchestratorCapability.methods.setAgentReachableHost.input.loose())
6955
6963
  .output(types_87.pipelineOrchestratorCapability.methods.setAgentReachableHost.output)
@@ -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
- return { prefix, access: asRouteAccess(Reflect.get(entry, 'access')), baseUrl, secret };
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(['grid-view', 'events-view']),
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. */
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('cst_')) {
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.229",
3
+ "version": "1.2.231",
4
4
  "private": false,
5
5
  "files": [
6
6
  "dist",