@rstreamlabs/tunnels 3.10.2 → 4.0.1

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/index.mjs CHANGED
@@ -18,6 +18,8 @@ import {
18
18
  listWebTTYKeyGrantDecryptMaterialParamsSchema,
19
19
  listWebTTYSessionGroupsParamsSchema,
20
20
  listWebTTYSessionsParamsSchema,
21
+ listedClientSchema,
22
+ listedTunnelSchema,
21
23
  projectLogEventsSchema,
22
24
  readWebTTYSessionEventsParamsSchema,
23
25
  resolveWebTTYControlRequestParamsSchema,
@@ -48,7 +50,7 @@ import {
48
50
  webTTYTransportSchema,
49
51
  webhookEventsSchema,
50
52
  wsEventsSchema
51
- } from "./chunk-DQN5T7CI.mjs";
53
+ } from "./chunk-TJNLK4CU.mjs";
52
54
 
53
55
  // src/auth-resource.ts
54
56
  import { createAuthTokenParamsSchema } from "@rstreamlabs/rstream/auth-token";
@@ -1843,7 +1845,7 @@ function validateWatchQueryToken(token) {
1843
1845
  }
1844
1846
  if (!hasWatchOnlyTunnelResources(parsed.data)) {
1845
1847
  throw new Error(
1846
- "Watch requires a fine-grained token limited to tunnel list resources for URL-based authentication."
1848
+ "Watch requires a fine-grained token limited to client or tunnel list resources for URL-based authentication."
1847
1849
  );
1848
1850
  }
1849
1851
  }
@@ -1859,38 +1861,38 @@ function hasWatchOnlyTunnelResources(token) {
1859
1861
  }
1860
1862
  function hasWatchOnlyTunnelResource(resource) {
1861
1863
  return watchResourceBranches(resource).every(
1862
- (branch) => branch.hasList && !branch.hasMutationOrConnect
1864
+ (branch) => (branch.clients || branch.tunnels) && !branch.create && !branch.connect
1863
1865
  );
1864
1866
  }
1865
1867
  function watchResourceBranches(resource) {
1866
1868
  if ("AND" in resource) {
1867
1869
  return resource.AND.reduce(
1868
- (branches, child) => combineWatchResourceBranches(branches, child),
1869
- [{ hasList: false, hasMutationOrConnect: false }]
1870
+ (branches, child) => branches.flatMap(
1871
+ (branch) => watchResourceBranches(child).map((other) => ({
1872
+ clients: branch.clients && other.clients,
1873
+ tunnels: branch.tunnels && other.tunnels,
1874
+ create: branch.create && other.create,
1875
+ connect: branch.connect && other.connect
1876
+ }))
1877
+ ),
1878
+ [{ clients: true, tunnels: true, create: true, connect: true }]
1870
1879
  );
1871
1880
  }
1872
- if ("OR" in resource) {
1873
- return resource.OR.flatMap(watchResourceBranches);
1874
- }
1875
- const tunnels = resource.scopes?.tunnels;
1876
- if (tunnels === void 0) {
1877
- return [{ hasList: false, hasMutationOrConnect: false }];
1881
+ if ("OR" in resource) return resource.OR.flatMap(watchResourceBranches);
1882
+ if (resource.scopes === void 0) {
1883
+ return [{ clients: true, tunnels: true, create: true, connect: true }];
1878
1884
  }
1885
+ const { clients, tunnels } = resource.scopes;
1886
+ const allows = (scope) => scope !== void 0 && scope !== false;
1879
1887
  return [
1880
1888
  {
1881
- hasList: tunnels.list !== void 0,
1882
- hasMutationOrConnect: tunnels.create !== void 0 || tunnels.connect !== void 0
1889
+ clients: clients === void 0 || allows(clients.list),
1890
+ tunnels: allows(tunnels?.list),
1891
+ create: allows(tunnels?.create),
1892
+ connect: allows(tunnels?.connect)
1883
1893
  }
1884
1894
  ];
1885
1895
  }
1886
- function combineWatchResourceBranches(branches, child) {
1887
- return branches.flatMap(
1888
- (branch) => watchResourceBranches(child).map((childBranch) => ({
1889
- hasList: branch.hasList || childBranch.hasList,
1890
- hasMutationOrConnect: branch.hasMutationOrConnect || childBranch.hasMutationOrConnect
1891
- }))
1892
- );
1893
- }
1894
1896
  function hasWatchOnlyPermissions(permissions) {
1895
1897
  if (!Array.isArray(permissions)) {
1896
1898
  return true;
@@ -2116,7 +2118,7 @@ function webTTYHasCapability(capabilities, capability) {
2116
2118
  return capabilities.includes(capability);
2117
2119
  }
2118
2120
  function parser(tunnel, includePrivate) {
2119
- if (tunnel.status !== "online") return null;
2121
+ if (!tunnel.id || tunnel.status !== "online") return null;
2120
2122
  if (tunnel.publish !== true && !includePrivate) return null;
2121
2123
  const managedProtocol = tunnel.protocol === "webtty";
2122
2124
  if (tunnel.protocol !== void 0 && tunnel.protocol !== "http" && !managedProtocol)
@@ -2273,6 +2275,8 @@ export {
2273
2275
  listWebTTYKeyGrantDecryptMaterialParamsSchema,
2274
2276
  listWebTTYSessionGroupsParamsSchema,
2275
2277
  listWebTTYSessionsParamsSchema,
2278
+ listedClientSchema,
2279
+ listedTunnelSchema,
2276
2280
  normalizeEngineAddress,
2277
2281
  parseWebTTYServers,
2278
2282
  projectLogEventsSchema,
@@ -380,6 +380,7 @@ declare const engineOpenApiDocument: {
380
380
  get: {
381
381
  tags: string[];
382
382
  summary: string;
383
+ "x-rstream-token-scope": string;
383
384
  operationId: string;
384
385
  parameters: {
385
386
  $ref: string;
@@ -458,7 +459,7 @@ declare const engineOpenApiDocument: {
458
459
  };
459
460
  };
460
461
  "x-rstream-required-rules": readonly OpenApiRule[];
461
- "x-rstream-token-metadata-scope": string;
462
+ "x-rstream-token-scope": string;
462
463
  };
463
464
  };
464
465
  "/api/sse": {
package/dist/openapi.d.ts CHANGED
@@ -380,6 +380,7 @@ declare const engineOpenApiDocument: {
380
380
  get: {
381
381
  tags: string[];
382
382
  summary: string;
383
+ "x-rstream-token-scope": string;
383
384
  operationId: string;
384
385
  parameters: {
385
386
  $ref: string;
@@ -458,7 +459,7 @@ declare const engineOpenApiDocument: {
458
459
  };
459
460
  };
460
461
  "x-rstream-required-rules": readonly OpenApiRule[];
461
- "x-rstream-token-metadata-scope": string;
462
+ "x-rstream-token-scope": string;
462
463
  };
463
464
  };
464
465
  "/api/sse": {