@rstreamlabs/tunnels 1.0.11 → 2.0.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/dist/index.mjs CHANGED
@@ -13,211 +13,13 @@ import {
13
13
  streamSummarySchema,
14
14
  streamTLSInfoSchema,
15
15
  tunnelFilterSchema,
16
- tunnelSchema,
17
16
  webhookEventsSchema,
18
17
  wsEventsSchema
19
- } from "./chunk-NHUJ3FYM.mjs";
18
+ } from "./chunk-UUZYVELQ.mjs";
20
19
 
21
20
  // src/auth-resource.ts
21
+ import { createAuthTokenParamsSchema } from "@rstreamlabs/rstream/auth-token";
22
22
  import { createClientCredentialsToken } from "@rstreamlabs/rstream";
23
-
24
- // src/zod.ts
25
- import * as z from "zod";
26
- var StringFilter = z.union([
27
- z.string(),
28
- z.object({ exact: z.string() }).strict(),
29
- z.object({ oneof: z.array(z.string()) }).strict(),
30
- z.object({ regex: z.string() }).strict()
31
- ]);
32
- function transform(field) {
33
- if (field instanceof z.ZodOptional) {
34
- return z.optional(transform(field.unwrap()));
35
- }
36
- if (field instanceof z.ZodString) {
37
- return z.optional(StringFilter);
38
- }
39
- if (field instanceof z.ZodRecord) {
40
- return z.optional(z.record(field.keyType, transform(field.valueType)));
41
- }
42
- return z.optional(field);
43
- }
44
- function filters(base) {
45
- const entries = Object.entries(base.shape).map(([key, field]) => [
46
- key,
47
- transform(field)
48
- ]);
49
- const shape = Object.fromEntries(entries);
50
- const node = z.lazy(
51
- () => z.union([
52
- z.object(shape).strict(),
53
- z.object({ AND: z.array(node) }).strict(),
54
- z.object({ OR: z.array(node) }).strict()
55
- ])
56
- );
57
- return node;
58
- }
59
- function select(base) {
60
- const entries = Object.entries(base.shape).map(([key]) => {
61
- return [key, z.boolean().optional()];
62
- });
63
- const shape = Object.fromEntries(entries);
64
- return z.object(shape).strict();
65
- }
66
-
67
- // src/auth.ts
68
- import * as z2 from "zod";
69
- var nonEmptyStringSchema = z2.string().trim().min(1);
70
- var authTokenPermissionsSchema = z2.array(z2.string());
71
- var authTokenTunnelsScopesSchema = z2.object({
72
- // Scopes for creating tunnels
73
- create: z2.union([
74
- z2.boolean(),
75
- z2.object({
76
- filters: filters(
77
- tunnelSchema.omit({
78
- client_id: true,
79
- user_id: true,
80
- workspace_id: true,
81
- project_id: true,
82
- cluster_id: true,
83
- plan: true,
84
- provider: true,
85
- region: true,
86
- status: true,
87
- id: true,
88
- creation_date: true
89
- })
90
- ).optional()
91
- }).strict()
92
- ]).optional(),
93
- // Scopes for connecting to tunnels
94
- connect: z2.union([
95
- z2.boolean(),
96
- z2.object({
97
- filters: filters(tunnelSchema).optional(),
98
- params: filters(
99
- z2.object({
100
- path: z2.string().optional()
101
- })
102
- ).optional()
103
- }).strict()
104
- ]).optional(),
105
- // Scopes for listing tunnels
106
- list: z2.union([
107
- z2.boolean(),
108
- z2.object({
109
- filters: filters(tunnelSchema).optional(),
110
- select: select(tunnelSchema).optional()
111
- }).strict()
112
- ]).optional()
113
- }).strict().superRefine((scopes, ctx) => {
114
- if (scopes.create === void 0 && scopes.connect === void 0 && scopes.list === void 0) {
115
- ctx.addIssue({
116
- code: z2.ZodIssueCode.custom,
117
- message: "At least one tunnel scope action is required."
118
- });
119
- }
120
- });
121
- var authTokenScopesSchema = z2.object({
122
- tunnels: authTokenTunnelsScopesSchema.optional()
123
- // Scopes related to tunnels
124
- }).strict().superRefine((scopes, ctx) => {
125
- if (scopes.tunnels === void 0) {
126
- ctx.addIssue({
127
- code: z2.ZodIssueCode.custom,
128
- message: "Tunnel scopes are required.",
129
- path: ["tunnels"]
130
- });
131
- }
132
- });
133
- var authTokenTunnelGrantLeafSchema = z2.object({
134
- workspaces: z2.array(nonEmptyStringSchema).min(1).optional(),
135
- projects: z2.array(nonEmptyStringSchema).min(1).optional(),
136
- scopes: authTokenScopesSchema.optional()
137
- }).strict().superRefine((grant, ctx) => {
138
- if (grant.workspaces !== void 0 && grant.projects !== void 0) {
139
- ctx.addIssue({
140
- code: z2.ZodIssueCode.custom,
141
- message: "A grant cannot target workspaces and projects at the same time.",
142
- path: ["projects"]
143
- });
144
- }
145
- if (grant.workspaces === void 0 && grant.projects === void 0 && grant.scopes === void 0) {
146
- ctx.addIssue({
147
- code: z2.ZodIssueCode.custom,
148
- message: "A grant must target workspaces, projects, or scopes.",
149
- path: ["workspaces"]
150
- });
151
- }
152
- });
153
- var authTokenTunnelGrantSchema = z2.lazy(
154
- () => z2.union([
155
- authTokenTunnelGrantLeafSchema,
156
- z2.object({ AND: z2.array(authTokenTunnelGrantSchema).min(1) }).strict(),
157
- z2.object({ OR: z2.array(authTokenTunnelGrantSchema).min(1) }).strict()
158
- ])
159
- );
160
- var authTokenCommonSchema = {
161
- aud: z2.union([z2.string(), z2.array(z2.string())]).optional(),
162
- exp: z2.number().optional(),
163
- tunnelsGrants: authTokenTunnelGrantSchema.optional(),
164
- iat: z2.number().optional(),
165
- iss: z2.string().optional(),
166
- jti: z2.string().optional(),
167
- metadata: z2.object({
168
- engine: z2.string().optional()
169
- }).strict().optional(),
170
- nbf: z2.number().optional(),
171
- sub: z2.string().optional()
172
- };
173
- var authTokenSchema = z2.union([
174
- z2.object({
175
- type: z2.literal("auth"),
176
- userId: z2.string(),
177
- permissions: authTokenPermissionsSchema.nullable(),
178
- ...authTokenCommonSchema
179
- }).strict(),
180
- z2.object({
181
- type: z2.literal("pat"),
182
- tokendpoint: z2.string().optional(),
183
- token_endpoint: z2.string().optional(),
184
- ...authTokenCommonSchema
185
- }).strict(),
186
- z2.object({
187
- type: z2.literal("app"),
188
- clientId: z2.string(),
189
- permissions: authTokenPermissionsSchema.nullable(),
190
- ...authTokenCommonSchema
191
- }).strict()
192
- ]);
193
- var tokenSchema = authTokenSchema;
194
- var createAuthTokenParamsSchema = z2.object({
195
- expires_in: z2.number().int().min(1).max(3600).default(60),
196
- scopes: authTokenScopesSchema.optional(),
197
- tunnelsGrants: authTokenTunnelGrantSchema.optional(),
198
- metadata: z2.unknown().optional()
199
- // Additional metadata
200
- }).strict().superRefine((params, ctx) => {
201
- if (params.scopes !== void 0 && params.tunnelsGrants !== void 0) {
202
- ctx.addIssue({
203
- code: z2.ZodIssueCode.custom,
204
- message: "Use either scopes or tunnelsGrants, not both.",
205
- path: ["tunnelsGrants"]
206
- });
207
- }
208
- if (params.scopes === void 0 && params.tunnelsGrants === void 0) {
209
- ctx.addIssue({
210
- code: z2.ZodIssueCode.custom,
211
- message: "Explicit scopes or tunnelsGrants are required.",
212
- path: ["scopes"]
213
- });
214
- }
215
- });
216
- var createAuthTokenResponseSchema = z2.object({
217
- token: z2.string()
218
- });
219
-
220
- // src/auth-resource.ts
221
23
  import { isClientCredentials } from "@rstreamlabs/rstream";
222
24
  var RstreamAuthResource = class {
223
25
  client;
@@ -508,6 +310,7 @@ async function resolveManagedTunnelsProject(config) {
508
310
  }
509
311
 
510
312
  // src/tunnels-resource.ts
313
+ import { tunnelSchema } from "@rstreamlabs/rstream/tunnel";
511
314
  function tunnelPathId(id) {
512
315
  const normalized = id.trim();
513
316
  if (!normalized) {
@@ -547,21 +350,21 @@ import { readEnvironment as readEnvironment2 } from "@rstreamlabs/rstream";
547
350
  import { isClientCredentials as isClientCredentials2 } from "@rstreamlabs/rstream";
548
351
  import { isTokenCredentials as isTokenCredentials2 } from "@rstreamlabs/rstream";
549
352
  import { RstreamClient as RstreamClient2 } from "@rstreamlabs/rstream";
550
- import { turnCredentialsSchema } from "@rstreamlabs/rstream";
551
- import * as z3 from "zod";
353
+ import { turnCredentialsSchema } from "@rstreamlabs/rstream/turn";
354
+ import * as z from "zod";
552
355
  import crypto from "crypto";
553
356
  var defaultTURNPort = 3478;
554
357
  var defaultTURNSPort = 5349;
555
358
  var defaultTURNCredentialTTLSeconds = 10 * 60;
556
359
  var maxTURNCredentialTTLSeconds = 60 * 60;
557
- var turnTokenClaimsSchema = z3.object({
558
- exp: z3.number().int().optional(),
559
- iat: z3.number().int().optional(),
560
- token_endpoint: z3.string().regex(/^[0-9a-f]{8}$/i).optional(),
561
- tokendpoint: z3.string().regex(/^[0-9a-f]{8}$/i).optional(),
562
- type: z3.enum(["app", "auth", "pat"])
360
+ var turnTokenClaimsSchema = z.object({
361
+ exp: z.number().int().optional(),
362
+ iat: z.number().int().optional(),
363
+ token_endpoint: z.string().regex(/^[0-9a-f]{8}$/i).optional(),
364
+ tokendpoint: z.string().regex(/^[0-9a-f]{8}$/i).optional(),
365
+ type: z.enum(["app", "auth", "pat"])
563
366
  });
564
- var turnCredentialModeSchema = z3.enum(["api", "app", "pat"]);
367
+ var turnCredentialModeSchema = z.enum(["api", "app", "pat"]);
565
368
  function normalizeOptionalString2(value) {
566
369
  const normalized = value?.trim();
567
370
  return normalized ? normalized : void 0;
@@ -1149,6 +952,7 @@ function normalizeOptionalString3(value) {
1149
952
  }
1150
953
 
1151
954
  // src/watch.ts
955
+ import { authTokenSchema } from "@rstreamlabs/rstream/auth-token";
1152
956
  import jwt from "jsonwebtoken";
1153
957
  var maxWatchTokenLifetimeSeconds = 3600;
1154
958
  var watchTokenIssuedAtSkewSeconds = 300;
@@ -1315,7 +1119,7 @@ var Watch = class {
1315
1119
  };
1316
1120
 
1317
1121
  // src/webtty.ts
1318
- import * as z4 from "zod";
1122
+ import * as z2 from "zod";
1319
1123
  var osFamilies = [
1320
1124
  "linux",
1321
1125
  "macos",
@@ -1324,25 +1128,25 @@ var osFamilies = [
1324
1128
  "openbsd",
1325
1129
  "freebsd"
1326
1130
  ];
1327
- var webttyServerSchema = z4.object({
1328
- tunnel_id: z4.string(),
1329
- host: z4.string(),
1330
- token_auth: z4.boolean(),
1331
- os_family: z4.enum(osFamilies).optional(),
1332
- arch: z4.string().optional(),
1333
- os_id: z4.string().optional(),
1131
+ var webttyServerSchema = z2.object({
1132
+ tunnel_id: z2.string(),
1133
+ host: z2.string(),
1134
+ token_auth: z2.boolean(),
1135
+ os_family: z2.enum(osFamilies).optional(),
1136
+ arch: z2.string().optional(),
1137
+ os_id: z2.string().optional(),
1334
1138
  // /etc/os-release::ID (ubuntu, debian, rocky, etc.)
1335
- os_version_id: z4.string().optional(),
1139
+ os_version_id: z2.string().optional(),
1336
1140
  // /etc/os-release::VERSION_ID (24.04, 22.04, 11, 10.0.19045, ...)
1337
- os_version_codename: z4.string().optional(),
1141
+ os_version_codename: z2.string().optional(),
1338
1142
  // /etc/os-release::VERSION_CODENAME (jammy, noble...)
1339
- os_pretty_name: z4.string().optional(),
1143
+ os_pretty_name: z2.string().optional(),
1340
1144
  // /etc/os-release::PRETTY_NAME
1341
- kernel_release: z4.string().optional(),
1145
+ kernel_release: z2.string().optional(),
1342
1146
  // uname -r
1343
- hostname: z4.string().optional(),
1147
+ hostname: z2.string().optional(),
1344
1148
  // uname -n
1345
- labels: z4.record(z4.string(), z4.string().optional()).optional()
1149
+ labels: z2.record(z2.string(), z2.string().optional()).optional()
1346
1150
  });
1347
1151
  function parser(tunnel) {
1348
1152
  if (tunnel.status !== "online") return null;
@@ -1394,18 +1198,11 @@ export {
1394
1198
  RstreamWebhookResource as RstreamWebhookRessource,
1395
1199
  RstreamTunnelsClient as Tunnels,
1396
1200
  Watch,
1397
- authTokenPermissionsSchema,
1398
- authTokenSchema,
1399
- authTokenScopesSchema,
1400
- authTokenTunnelGrantSchema,
1401
- authTokenTunnelsScopesSchema,
1402
1201
  clientFilterSchema,
1403
1202
  clientSchema,
1404
1203
  createAPITURNCredentials,
1405
1204
  createAPPTURNCredentials,
1406
1205
  createAuthTokenFromClientCredentials,
1407
- createAuthTokenParamsSchema,
1408
- createAuthTokenResponseSchema,
1409
1206
  createPATTURNCredentials,
1410
1207
  createTURNCredentials,
1411
1208
  engineOpenApiDocument,
@@ -1426,9 +1223,7 @@ export {
1426
1223
  streamEndpointSchema,
1427
1224
  streamSummarySchema,
1428
1225
  streamTLSInfoSchema,
1429
- tokenSchema,
1430
1226
  tunnelFilterSchema,
1431
- tunnelSchema,
1432
1227
  turnCredentialModeSchema,
1433
1228
  webhookEventsSchema,
1434
1229
  webttyServerSchema,
package/dist/openapi.js CHANGED
@@ -74,44 +74,9 @@ var listClientsParamsSchema = z.object({
74
74
  var listClientsResponseSchema = z.array(clientSchema);
75
75
 
76
76
  // src/tunnel.ts
77
+ var import_tunnel = require("@rstreamlabs/rstream/tunnel");
77
78
  var z2 = __toESM(require("zod"));
78
- var tunnelSchema = z2.object({
79
- // common properties
80
- client_id: z2.string(),
81
- user_id: z2.string().optional(),
82
- workspace_id: z2.string().optional(),
83
- project_id: z2.string().optional(),
84
- cluster_id: z2.string().optional(),
85
- plan: z2.string().optional(),
86
- provider: z2.string().optional(),
87
- region: z2.string().optional(),
88
- status: z2.enum(["online", "offline"]),
89
- // tunnel properties
90
- id: z2.string(),
91
- creation_date: z2.union([z2.string().datetime(), z2.date()]).optional(),
92
- name: z2.string().optional(),
93
- type: z2.enum(["bytestream", "datagram"]).optional(),
94
- publish: z2.boolean().optional(),
95
- protocol: z2.enum(["tls", "dtls", "quic", "http"]).optional(),
96
- labels: z2.record(z2.string(), z2.string()).optional(),
97
- geo_ip: z2.array(z2.string()).optional(),
98
- trusted_ips: z2.array(z2.string()).optional(),
99
- host: z2.string().optional(),
100
- hostname: z2.string().optional(),
101
- port: z2.number().int().min(1).max(65535).optional(),
102
- tls_mode: z2.enum(["passthrough", "terminated"]).optional(),
103
- tls_alpns: z2.array(z2.string()).optional(),
104
- tls_min_version: z2.string().optional(),
105
- tls_ciphers: z2.array(z2.string()).optional(),
106
- mtls_auth: z2.boolean().optional(),
107
- http_version: z2.enum(["http/1.1", "h2", "h2c", "h3"]).optional(),
108
- http_use_tls: z2.boolean().optional(),
109
- upstream_tls: z2.boolean().optional(),
110
- token_auth: z2.boolean().optional(),
111
- rstream_auth: z2.boolean().optional(),
112
- challenge_mode: z2.boolean().optional()
113
- });
114
- var tunnelFilterSchema = tunnelSchema.pick({
79
+ var tunnelFilterSchema = import_tunnel.tunnelSchema.pick({
115
80
  id: true,
116
81
  name: true,
117
82
  type: true,
@@ -128,7 +93,10 @@ var listTunnelsParamsSchema = z2.object({
128
93
  limit: z2.number().int().min(1).optional(),
129
94
  filters: tunnelFilterSchema.optional()
130
95
  });
131
- var listTunnelsResponseSchema = z2.array(tunnelSchema);
96
+ var listTunnelsResponseSchema = z2.array(import_tunnel.tunnelSchema);
97
+
98
+ // src/openapi.ts
99
+ var import_tunnel5 = require("@rstreamlabs/rstream/tunnel");
132
100
 
133
101
  // src/stream.ts
134
102
  var z3 = __toESM(require("zod"));
@@ -334,12 +302,13 @@ var streamSummarySchema = z3.object({
334
302
  });
335
303
 
336
304
  // src/event.ts
305
+ var import_tunnel2 = require("@rstreamlabs/rstream/tunnel");
337
306
  var z4 = __toESM(require("zod"));
338
307
  var isoDateTimeSchema2 = z4.string().datetime({ offset: true });
339
308
  var initialStateSchema = z4.object({
340
309
  snapshot_at: isoDateTimeSchema2,
341
310
  clients: z4.array(clientSchema),
342
- tunnels: z4.array(tunnelSchema)
311
+ tunnels: z4.array(import_tunnel2.tunnelSchema)
343
312
  });
344
313
  var eventBaseSchema = z4.object({
345
314
  id: z4.string().optional(),
@@ -373,15 +342,15 @@ var commonEventsSchema = [
373
342
  }),
374
343
  withEventBase({
375
344
  type: z4.literal("tunnel.created"),
376
- object: tunnelSchema
345
+ object: import_tunnel2.tunnelSchema
377
346
  }),
378
347
  withEventBase({
379
348
  type: z4.literal("tunnel.updated"),
380
- object: tunnelSchema
349
+ object: import_tunnel2.tunnelSchema
381
350
  }),
382
351
  withEventBase({
383
352
  type: z4.literal("tunnel.deleted"),
384
- object: tunnelSchema
353
+ object: import_tunnel2.tunnelSchema
385
354
  })
386
355
  ];
387
356
  var wsEventsSchema = z4.union([
@@ -607,7 +576,7 @@ var engineOpenApiDocument = {
607
576
  Event: jsonSchemaFor(wsEventsSchema),
608
577
  ListClientsParams: jsonSchemaFor(listClientsParamsSchema),
609
578
  ListTunnelsParams: jsonSchemaFor(listTunnelsParamsSchema),
610
- TunnelListItem: jsonSchemaFor(tunnelSchema),
579
+ TunnelListItem: jsonSchemaFor(import_tunnel5.tunnelSchema),
611
580
  WatchParams: jsonSchemaFor(watchParamsSchema)
612
581
  }
613
582
  },
package/dist/openapi.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  engineOpenApiDocument,
3
3
  engineOpenApiJson
4
- } from "./chunk-NHUJ3FYM.mjs";
4
+ } from "./chunk-UUZYVELQ.mjs";
5
5
  export {
6
6
  engineOpenApiDocument,
7
7
  engineOpenApiJson
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstreamlabs/tunnels",
3
- "version": "1.0.11",
3
+ "version": "2.0.0",
4
4
  "description": "JS/TS SDK for the rstream Engine API and tunnel runtime APIs.",
5
5
  "author": "@uartnet <hello@rstream.io>",
6
6
  "repository": {
@@ -47,7 +47,7 @@
47
47
  "typescript-config": "*"
48
48
  },
49
49
  "dependencies": {
50
- "@rstreamlabs/rstream": "2.1.4",
50
+ "@rstreamlabs/rstream": "2.1.5",
51
51
  "@types/jsonwebtoken": "^9.0.10",
52
52
  "jsonwebtoken": "^9.0.3",
53
53
  "zod": "^4.3.6"