@rstreamlabs/tunnels 1.0.10 → 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.js CHANGED
@@ -43,18 +43,11 @@ __export(index_exports, {
43
43
  RstreamWebhookRessource: () => RstreamWebhookResource,
44
44
  Tunnels: () => RstreamTunnelsClient,
45
45
  Watch: () => Watch,
46
- authTokenPermissionsSchema: () => authTokenPermissionsSchema,
47
- authTokenSchema: () => authTokenSchema,
48
- authTokenScopesSchema: () => authTokenScopesSchema,
49
- authTokenTunnelGrantSchema: () => authTokenTunnelGrantSchema,
50
- authTokenTunnelsScopesSchema: () => authTokenTunnelsScopesSchema,
51
46
  clientFilterSchema: () => clientFilterSchema,
52
47
  clientSchema: () => clientSchema,
53
48
  createAPITURNCredentials: () => createAPITURNCredentials,
54
49
  createAPPTURNCredentials: () => createAPPTURNCredentials,
55
50
  createAuthTokenFromClientCredentials: () => createAuthTokenFromClientCredentials,
56
- createAuthTokenParamsSchema: () => createAuthTokenParamsSchema,
57
- createAuthTokenResponseSchema: () => createAuthTokenResponseSchema,
58
51
  createPATTURNCredentials: () => createPATTURNCredentials,
59
52
  createTURNCredentials: () => createTURNCredentials,
60
53
  engineOpenApiDocument: () => engineOpenApiDocument,
@@ -75,9 +68,7 @@ __export(index_exports, {
75
68
  streamEndpointSchema: () => streamEndpointSchema,
76
69
  streamSummarySchema: () => streamSummarySchema,
77
70
  streamTLSInfoSchema: () => streamTLSInfoSchema,
78
- tokenSchema: () => tokenSchema,
79
71
  tunnelFilterSchema: () => tunnelFilterSchema,
80
- tunnelSchema: () => tunnelSchema,
81
72
  turnCredentialModeSchema: () => turnCredentialModeSchema,
82
73
  webhookEventsSchema: () => webhookEventsSchema,
83
74
  webttyServerSchema: () => webttyServerSchema,
@@ -86,270 +77,8 @@ __export(index_exports, {
86
77
  module.exports = __toCommonJS(index_exports);
87
78
 
88
79
  // src/auth-resource.ts
80
+ var import_auth_token = require("@rstreamlabs/rstream/auth-token");
89
81
  var import_rstream = require("@rstreamlabs/rstream");
90
-
91
- // src/zod.ts
92
- var z = __toESM(require("zod"));
93
- var StringFilter = z.union([
94
- z.string(),
95
- z.object({ exact: z.string() }).strict(),
96
- z.object({ oneof: z.array(z.string()) }).strict(),
97
- z.object({ regex: z.string() }).strict()
98
- ]);
99
- function transform(field) {
100
- if (field instanceof z.ZodOptional) {
101
- return z.optional(transform(field.unwrap()));
102
- }
103
- if (field instanceof z.ZodString) {
104
- return z.optional(StringFilter);
105
- }
106
- if (field instanceof z.ZodRecord) {
107
- return z.optional(z.record(field.keyType, transform(field.valueType)));
108
- }
109
- return z.optional(field);
110
- }
111
- function filters(base) {
112
- const entries = Object.entries(base.shape).map(([key, field]) => [
113
- key,
114
- transform(field)
115
- ]);
116
- const shape = Object.fromEntries(entries);
117
- const node = z.lazy(
118
- () => z.union([
119
- z.object(shape).strict(),
120
- z.object({ AND: z.array(node) }).strict(),
121
- z.object({ OR: z.array(node) }).strict()
122
- ])
123
- );
124
- return node;
125
- }
126
- function select(base) {
127
- const entries = Object.entries(base.shape).map(([key]) => {
128
- return [key, z.boolean().optional()];
129
- });
130
- const shape = Object.fromEntries(entries);
131
- return z.object(shape).strict();
132
- }
133
-
134
- // src/tunnel.ts
135
- var z2 = __toESM(require("zod"));
136
- var DEFAULT_PUBLISHED_PORT = 443;
137
- var tunnelSchema = z2.object({
138
- // common properties
139
- client_id: z2.string(),
140
- user_id: z2.string().optional(),
141
- workspace_id: z2.string().optional(),
142
- project_id: z2.string().optional(),
143
- cluster_id: z2.string().optional(),
144
- plan: z2.string().optional(),
145
- provider: z2.string().optional(),
146
- region: z2.string().optional(),
147
- status: z2.enum(["online", "offline"]),
148
- // tunnel properties
149
- id: z2.string(),
150
- creation_date: z2.union([z2.string().datetime(), z2.date()]).optional(),
151
- name: z2.string().optional(),
152
- type: z2.enum(["bytestream", "datagram"]).optional(),
153
- publish: z2.boolean().optional(),
154
- protocol: z2.enum(["tls", "dtls", "quic", "http"]).optional(),
155
- labels: z2.record(z2.string(), z2.string()).optional(),
156
- geo_ip: z2.array(z2.string()).optional(),
157
- trusted_ips: z2.array(z2.string()).optional(),
158
- host: z2.string().optional(),
159
- hostname: z2.string().optional(),
160
- port: z2.number().int().min(1).max(65535).optional(),
161
- tls_mode: z2.enum(["passthrough", "terminated"]).optional(),
162
- tls_alpns: z2.array(z2.string()).optional(),
163
- tls_min_version: z2.string().optional(),
164
- tls_ciphers: z2.array(z2.string()).optional(),
165
- mtls_auth: z2.boolean().optional(),
166
- http_version: z2.enum(["http/1.1", "h2", "h2c", "h3"]).optional(),
167
- http_use_tls: z2.boolean().optional(),
168
- upstream_tls: z2.boolean().optional(),
169
- token_auth: z2.boolean().optional(),
170
- rstream_auth: z2.boolean().optional(),
171
- challenge_mode: z2.boolean().optional()
172
- });
173
- var tunnelFilterSchema = tunnelSchema.pick({
174
- id: true,
175
- name: true,
176
- type: true,
177
- status: true,
178
- client_id: true,
179
- user_id: true,
180
- publish: true,
181
- protocol: true,
182
- hostname: true,
183
- http_version: true,
184
- labels: true
185
- }).partial();
186
- var listTunnelsParamsSchema = z2.object({
187
- limit: z2.number().int().min(1).optional(),
188
- filters: tunnelFilterSchema.optional()
189
- });
190
- var listTunnelsResponseSchema = z2.array(tunnelSchema);
191
- function formatTunnelHost(tunnel) {
192
- if (!tunnel.hostname) return tunnel.host;
193
- if (!tunnel.port || tunnel.port === DEFAULT_PUBLISHED_PORT) {
194
- return tunnel.hostname;
195
- }
196
- return `${tunnel.hostname}:${tunnel.port}`;
197
- }
198
-
199
- // src/auth.ts
200
- var z3 = __toESM(require("zod"));
201
- var nonEmptyStringSchema = z3.string().trim().min(1);
202
- var authTokenPermissionsSchema = z3.array(z3.string());
203
- var authTokenTunnelsScopesSchema = z3.object({
204
- // Scopes for creating tunnels
205
- create: z3.union([
206
- z3.boolean(),
207
- z3.object({
208
- filters: filters(
209
- tunnelSchema.omit({
210
- client_id: true,
211
- user_id: true,
212
- workspace_id: true,
213
- project_id: true,
214
- cluster_id: true,
215
- plan: true,
216
- provider: true,
217
- region: true,
218
- status: true,
219
- id: true,
220
- creation_date: true
221
- })
222
- ).optional()
223
- }).strict()
224
- ]).optional(),
225
- // Scopes for connecting to tunnels
226
- connect: z3.union([
227
- z3.boolean(),
228
- z3.object({
229
- filters: filters(tunnelSchema).optional(),
230
- params: filters(
231
- z3.object({
232
- path: z3.string().optional()
233
- })
234
- ).optional()
235
- }).strict()
236
- ]).optional(),
237
- // Scopes for listing tunnels
238
- list: z3.union([
239
- z3.boolean(),
240
- z3.object({
241
- filters: filters(tunnelSchema).optional(),
242
- select: select(tunnelSchema).optional()
243
- }).strict()
244
- ]).optional()
245
- }).strict().superRefine((scopes, ctx) => {
246
- if (scopes.create === void 0 && scopes.connect === void 0 && scopes.list === void 0) {
247
- ctx.addIssue({
248
- code: z3.ZodIssueCode.custom,
249
- message: "At least one tunnel scope action is required."
250
- });
251
- }
252
- });
253
- var authTokenScopesSchema = z3.object({
254
- tunnels: authTokenTunnelsScopesSchema.optional()
255
- // Scopes related to tunnels
256
- }).strict().superRefine((scopes, ctx) => {
257
- if (scopes.tunnels === void 0) {
258
- ctx.addIssue({
259
- code: z3.ZodIssueCode.custom,
260
- message: "Tunnel scopes are required.",
261
- path: ["tunnels"]
262
- });
263
- }
264
- });
265
- var authTokenTunnelGrantLeafSchema = z3.object({
266
- workspaces: z3.array(nonEmptyStringSchema).min(1).optional(),
267
- projects: z3.array(nonEmptyStringSchema).min(1).optional(),
268
- scopes: authTokenScopesSchema.optional()
269
- }).strict().superRefine((grant, ctx) => {
270
- if (grant.workspaces !== void 0 && grant.projects !== void 0) {
271
- ctx.addIssue({
272
- code: z3.ZodIssueCode.custom,
273
- message: "A grant cannot target workspaces and projects at the same time.",
274
- path: ["projects"]
275
- });
276
- }
277
- if (grant.workspaces === void 0 && grant.projects === void 0 && grant.scopes === void 0) {
278
- ctx.addIssue({
279
- code: z3.ZodIssueCode.custom,
280
- message: "A grant must target workspaces, projects, or scopes.",
281
- path: ["workspaces"]
282
- });
283
- }
284
- });
285
- var authTokenTunnelGrantSchema = z3.lazy(
286
- () => z3.union([
287
- authTokenTunnelGrantLeafSchema,
288
- z3.object({ AND: z3.array(authTokenTunnelGrantSchema).min(1) }).strict(),
289
- z3.object({ OR: z3.array(authTokenTunnelGrantSchema).min(1) }).strict()
290
- ])
291
- );
292
- var authTokenCommonSchema = {
293
- aud: z3.union([z3.string(), z3.array(z3.string())]).optional(),
294
- exp: z3.number().optional(),
295
- tunnelsGrants: authTokenTunnelGrantSchema.optional(),
296
- iat: z3.number().optional(),
297
- iss: z3.string().optional(),
298
- jti: z3.string().optional(),
299
- metadata: z3.object({
300
- engine: z3.string().optional()
301
- }).strict().optional(),
302
- nbf: z3.number().optional(),
303
- sub: z3.string().optional()
304
- };
305
- var authTokenSchema = z3.union([
306
- z3.object({
307
- type: z3.literal("auth"),
308
- userId: z3.string(),
309
- permissions: authTokenPermissionsSchema.nullable(),
310
- ...authTokenCommonSchema
311
- }).strict(),
312
- z3.object({
313
- type: z3.literal("pat"),
314
- tokendpoint: z3.string().optional(),
315
- token_endpoint: z3.string().optional(),
316
- ...authTokenCommonSchema
317
- }).strict(),
318
- z3.object({
319
- type: z3.literal("app"),
320
- clientId: z3.string(),
321
- permissions: authTokenPermissionsSchema.nullable(),
322
- ...authTokenCommonSchema
323
- }).strict()
324
- ]);
325
- var tokenSchema = authTokenSchema;
326
- var createAuthTokenParamsSchema = z3.object({
327
- expires_in: z3.number().int().min(1).max(3600).default(60),
328
- scopes: authTokenScopesSchema.optional(),
329
- tunnelsGrants: authTokenTunnelGrantSchema.optional(),
330
- metadata: z3.unknown().optional()
331
- // Additional metadata
332
- }).strict().superRefine((params, ctx) => {
333
- if (params.scopes !== void 0 && params.tunnelsGrants !== void 0) {
334
- ctx.addIssue({
335
- code: z3.ZodIssueCode.custom,
336
- message: "Use either scopes or tunnelsGrants, not both.",
337
- path: ["tunnelsGrants"]
338
- });
339
- }
340
- if (params.scopes === void 0 && params.tunnelsGrants === void 0) {
341
- ctx.addIssue({
342
- code: z3.ZodIssueCode.custom,
343
- message: "Explicit scopes or tunnelsGrants are required.",
344
- path: ["scopes"]
345
- });
346
- }
347
- });
348
- var createAuthTokenResponseSchema = z3.object({
349
- token: z3.string()
350
- });
351
-
352
- // src/auth-resource.ts
353
82
  var import_rstream2 = require("@rstreamlabs/rstream");
354
83
  var RstreamAuthResource = class {
355
84
  client;
@@ -371,7 +100,7 @@ var RstreamAuthResource = class {
371
100
  });
372
101
  }
373
102
  async resolveScopeOptions(params, options) {
374
- const tokenParams = createAuthTokenParamsSchema.parse(params);
103
+ const tokenParams = import_auth_token.createAuthTokenParamsSchema.parse(params);
375
104
  if (options?.projectScoped === false) {
376
105
  return options ?? {};
377
106
  }
@@ -390,7 +119,7 @@ var RstreamAuthResource = class {
390
119
  }
391
120
  };
392
121
  function createAuthTokenFromClientCredentials(credentials, params, options) {
393
- const tokenParams = createAuthTokenParamsSchema.parse(params);
122
+ const tokenParams = import_auth_token.createAuthTokenParamsSchema.parse(params);
394
123
  const payload = {
395
124
  metadata: {
396
125
  engine: options?.engine
@@ -492,24 +221,24 @@ function normalizeOptionalString(value) {
492
221
  }
493
222
 
494
223
  // src/client.ts
495
- var z4 = __toESM(require("zod"));
496
- var clientSchema = z4.object({
497
- id: z4.string(),
498
- status: z4.enum(["online", "offline"]),
499
- user_id: z4.string().optional(),
500
- workspace_id: z4.string().optional(),
501
- project_id: z4.string().optional(),
502
- cluster_id: z4.string().optional(),
503
- plan: z4.string().optional(),
504
- provider: z4.string().optional(),
505
- region: z4.string().optional(),
506
- agent: z4.string().optional(),
507
- channel: z4.string().optional(),
508
- version: z4.string().optional(),
509
- os: z4.string().optional(),
510
- arch: z4.string().optional(),
511
- protocol_version: z4.string().optional(),
512
- labels: z4.record(z4.string(), z4.string()).optional()
224
+ var z = __toESM(require("zod"));
225
+ var clientSchema = z.object({
226
+ id: z.string(),
227
+ status: z.enum(["online", "offline"]),
228
+ user_id: z.string().optional(),
229
+ workspace_id: z.string().optional(),
230
+ project_id: z.string().optional(),
231
+ cluster_id: z.string().optional(),
232
+ plan: z.string().optional(),
233
+ provider: z.string().optional(),
234
+ region: z.string().optional(),
235
+ agent: z.string().optional(),
236
+ channel: z.string().optional(),
237
+ version: z.string().optional(),
238
+ os: z.string().optional(),
239
+ arch: z.string().optional(),
240
+ protocol_version: z.string().optional(),
241
+ labels: z.record(z.string(), z.string()).optional()
513
242
  });
514
243
  var clientFilterSchema = clientSchema.pick({
515
244
  id: true,
@@ -523,11 +252,11 @@ var clientFilterSchema = clientSchema.pick({
523
252
  protocol_version: true,
524
253
  labels: true
525
254
  }).partial();
526
- var listClientsParamsSchema = z4.object({
527
- limit: z4.number().int().min(1).optional(),
255
+ var listClientsParamsSchema = z.object({
256
+ limit: z.number().int().min(1).optional(),
528
257
  filters: clientFilterSchema.optional()
529
258
  });
530
- var listClientsResponseSchema = z4.array(clientSchema);
259
+ var listClientsResponseSchema = z.array(clientSchema);
531
260
 
532
261
  // src/clients-resource.ts
533
262
  function clientPathId(id) {
@@ -561,200 +290,200 @@ var RstreamClientsResource = class {
561
290
  };
562
291
 
563
292
  // src/stream.ts
564
- var z5 = __toESM(require("zod"));
565
- var nonEmptyStringSchema2 = z5.string().min(1);
566
- var isoDateTimeSchema = z5.string().datetime({ offset: true });
567
- var ipAddressSchema = z5.string();
568
- var intNonNegSchema = z5.number().int().nonnegative();
569
- var numNonNegSchema = z5.number().nonnegative();
570
- var geolocationSchema = z5.object({
571
- country: z5.string().optional(),
572
- region: z5.string().optional()
293
+ var z2 = __toESM(require("zod"));
294
+ var nonEmptyStringSchema = z2.string().min(1);
295
+ var isoDateTimeSchema = z2.string().datetime({ offset: true });
296
+ var ipAddressSchema = z2.string();
297
+ var intNonNegSchema = z2.number().int().nonnegative();
298
+ var numNonNegSchema = z2.number().nonnegative();
299
+ var geolocationSchema = z2.object({
300
+ country: z2.string().optional(),
301
+ region: z2.string().optional()
573
302
  });
574
- var streamTLSInfoSchema = z5.object({
575
- version: z5.string().min(1).optional(),
576
- cipher: z5.string().min(1).optional(),
577
- protocol: z5.string().min(1).optional(),
578
- curve: z5.string().min(1).optional(),
579
- ech: z5.boolean().optional()
303
+ var streamTLSInfoSchema = z2.object({
304
+ version: z2.string().min(1).optional(),
305
+ cipher: z2.string().min(1).optional(),
306
+ protocol: z2.string().min(1).optional(),
307
+ curve: z2.string().min(1).optional(),
308
+ ech: z2.boolean().optional()
580
309
  });
581
- var streamEndpointSchema = z5.object({
310
+ var streamEndpointSchema = z2.object({
582
311
  ip: ipAddressSchema.optional(),
583
312
  geolocation: geolocationSchema.optional(),
584
313
  tls: streamTLSInfoSchema.optional()
585
314
  });
586
- var httpHeadersSchema = z5.record(
587
- z5.string(),
588
- z5.union([z5.string(), z5.array(z5.string())])
315
+ var httpHeadersSchema = z2.record(
316
+ z2.string(),
317
+ z2.union([z2.string(), z2.array(z2.string())])
589
318
  );
590
- var httpProtocolSchema = z5.enum(["http/1.1", "h2", "h2c", "h3"]);
591
- var httpRequestSchema = z5.object({
592
- method: nonEmptyStringSchema2,
593
- scheme: z5.string().min(1).optional(),
594
- host: nonEmptyStringSchema2.optional(),
595
- path: nonEmptyStringSchema2.optional(),
596
- query: z5.string().optional(),
597
- url: nonEmptyStringSchema2.optional(),
319
+ var httpProtocolSchema = z2.enum(["http/1.1", "h2", "h2c", "h3"]);
320
+ var httpRequestSchema = z2.object({
321
+ method: nonEmptyStringSchema,
322
+ scheme: z2.string().min(1).optional(),
323
+ host: nonEmptyStringSchema.optional(),
324
+ path: nonEmptyStringSchema.optional(),
325
+ query: z2.string().optional(),
326
+ url: nonEmptyStringSchema.optional(),
598
327
  headers: httpHeadersSchema.optional(),
599
- userAgent: z5.string().optional()
328
+ userAgent: z2.string().optional()
600
329
  });
601
- var httpResponseSchema = z5.object({
602
- status: z5.number().int().min(100).max(999),
330
+ var httpResponseSchema = z2.object({
331
+ status: z2.number().int().min(100).max(999),
603
332
  headers: httpHeadersSchema.optional()
604
333
  });
605
- var httpRequestStageSchema = z5.object({
334
+ var httpRequestStageSchema = z2.object({
606
335
  protocol: httpProtocolSchema.optional(),
607
336
  request: httpRequestSchema
608
337
  });
609
- var httpResponseStageSchema = z5.object({
338
+ var httpResponseStageSchema = z2.object({
610
339
  protocol: httpProtocolSchema.optional(),
611
340
  response: httpResponseSchema
612
341
  });
613
- var tokenSourceSchema = z5.enum([
342
+ var tokenSourceSchema = z2.enum([
614
343
  "authorization",
615
344
  "query",
616
345
  "client",
617
346
  "unknown"
618
347
  ]);
619
- var tokenTypeSchema = z5.enum(["auth", "pat", "app", "unknown"]);
620
- var firewallRuleSchema = z5.discriminatedUnion("kind", [
621
- z5.object({ kind: z5.literal("none") }),
622
- z5.object({ kind: z5.literal("mtls") }),
623
- z5.object({
624
- kind: z5.literal("rstream_auth"),
625
- source: z5.literal("rstream_auth")
348
+ var tokenTypeSchema = z2.enum(["auth", "pat", "app", "unknown"]);
349
+ var firewallRuleSchema = z2.discriminatedUnion("kind", [
350
+ z2.object({ kind: z2.literal("none") }),
351
+ z2.object({ kind: z2.literal("mtls") }),
352
+ z2.object({
353
+ kind: z2.literal("rstream_auth"),
354
+ source: z2.literal("rstream_auth")
626
355
  }),
627
- z5.object({
628
- kind: z5.literal("token"),
356
+ z2.object({
357
+ kind: z2.literal("token"),
629
358
  source: tokenSourceSchema.optional(),
630
359
  tokenType: tokenTypeSchema.optional()
631
360
  })
632
361
  ]);
633
- var unauthorizedSourceSchema = z5.object({
362
+ var unauthorizedSourceSchema = z2.object({
634
363
  source: tokenSourceSchema
635
364
  });
636
- var unauthorizedReasonSchema = (shape) => z5.object(shape).merge(unauthorizedSourceSchema);
637
- var unauthorizedSchema = z5.discriminatedUnion("reason", [
365
+ var unauthorizedReasonSchema = (shape) => z2.object(shape).merge(unauthorizedSourceSchema);
366
+ var unauthorizedSchema = z2.discriminatedUnion("reason", [
638
367
  unauthorizedReasonSchema({
639
- reason: z5.literal("missing_token")
368
+ reason: z2.literal("missing_token")
640
369
  }),
641
370
  unauthorizedReasonSchema({
642
- reason: z5.literal("invalid_token")
371
+ reason: z2.literal("invalid_token")
643
372
  }),
644
373
  unauthorizedReasonSchema({
645
- reason: z5.literal("expired_token")
374
+ reason: z2.literal("expired_token")
646
375
  }),
647
376
  unauthorizedReasonSchema({
648
- reason: z5.literal("invalid_secret")
377
+ reason: z2.literal("invalid_secret")
649
378
  }),
650
379
  unauthorizedReasonSchema({
651
- reason: z5.literal("user_mismatch")
380
+ reason: z2.literal("user_mismatch")
652
381
  }),
653
382
  unauthorizedReasonSchema({
654
- reason: z5.literal("insufficient_scope")
383
+ reason: z2.literal("insufficient_scope")
655
384
  }),
656
385
  unauthorizedReasonSchema({
657
- reason: z5.literal("policy_denied"),
658
- policy: z5.enum(["ip", "geo", "mtls", "challenge", "other"]),
659
- value: z5.string().optional()
386
+ reason: z2.literal("policy_denied"),
387
+ policy: z2.enum(["ip", "geo", "mtls", "challenge", "other"]),
388
+ value: z2.string().optional()
660
389
  })
661
390
  ]);
662
- var failureSchema = z5.discriminatedUnion("kind", [
663
- z5.object({
664
- kind: z5.literal("timeout"),
391
+ var failureSchema = z2.discriminatedUnion("kind", [
392
+ z2.object({
393
+ kind: z2.literal("timeout"),
665
394
  timeoutMs: intNonNegSchema.optional(),
666
- message: z5.string().optional()
395
+ message: z2.string().optional()
667
396
  }),
668
- z5.object({
669
- kind: z5.literal("unauthorized"),
397
+ z2.object({
398
+ kind: z2.literal("unauthorized"),
670
399
  why: unauthorizedSchema,
671
- message: z5.string().optional()
400
+ message: z2.string().optional()
672
401
  }),
673
- z5.object({
674
- kind: z5.literal("not_found"),
675
- resource: z5.enum(["tunnel", "client", "route"]),
676
- message: z5.string().optional()
402
+ z2.object({
403
+ kind: z2.literal("not_found"),
404
+ resource: z2.enum(["tunnel", "client", "route"]),
405
+ message: z2.string().optional()
677
406
  }),
678
- z5.object({
679
- kind: z5.literal("refused"),
680
- reason: z5.enum(["capacity", "policy", "unsupported", "other"]),
681
- message: z5.string().optional()
407
+ z2.object({
408
+ kind: z2.literal("refused"),
409
+ reason: z2.enum(["capacity", "policy", "unsupported", "other"]),
410
+ message: z2.string().optional()
682
411
  }),
683
- z5.object({ kind: z5.literal("io"), message: z5.string().optional() }),
684
- z5.object({ kind: z5.literal("internal"), message: z5.string().optional() })
412
+ z2.object({ kind: z2.literal("io"), message: z2.string().optional() }),
413
+ z2.object({ kind: z2.literal("internal"), message: z2.string().optional() })
685
414
  ]);
686
- var firewallSchema = z5.discriminatedUnion("decision", [
687
- z5.object({ decision: z5.literal("allowed"), rule: firewallRuleSchema }),
688
- z5.object({
689
- decision: z5.literal("denied"),
415
+ var firewallSchema = z2.discriminatedUnion("decision", [
416
+ z2.object({ decision: z2.literal("allowed"), rule: firewallRuleSchema }),
417
+ z2.object({
418
+ decision: z2.literal("denied"),
690
419
  rule: firewallRuleSchema,
691
420
  failure: failureSchema
692
421
  })
693
422
  ]);
694
- var routedTunnelSchema = z5.object({
695
- tunnelId: nonEmptyStringSchema2.optional(),
696
- tunnelName: z5.string().optional(),
697
- hostname: z5.string().optional(),
698
- protocol: z5.string().optional(),
699
- published: z5.boolean().optional(),
700
- type: z5.string().optional(),
701
- tlsMode: z5.string().optional(),
702
- httpVersion: z5.string().optional(),
703
- httpUseTls: z5.boolean().optional(),
704
- upstreamTls: z5.boolean().optional(),
705
- tokenAuth: z5.boolean().optional(),
706
- mtls_auth: z5.boolean().optional()
423
+ var routedTunnelSchema = z2.object({
424
+ tunnelId: nonEmptyStringSchema.optional(),
425
+ tunnelName: z2.string().optional(),
426
+ hostname: z2.string().optional(),
427
+ protocol: z2.string().optional(),
428
+ published: z2.boolean().optional(),
429
+ type: z2.string().optional(),
430
+ tlsMode: z2.string().optional(),
431
+ httpVersion: z2.string().optional(),
432
+ httpUseTls: z2.boolean().optional(),
433
+ upstreamTls: z2.boolean().optional(),
434
+ tokenAuth: z2.boolean().optional(),
435
+ mtls_auth: z2.boolean().optional()
707
436
  });
708
- var routingSchema = z5.discriminatedUnion("decision", [
709
- z5.object({ decision: z5.literal("routed"), tunnel: routedTunnelSchema }),
710
- z5.object({ decision: z5.literal("not_routed"), failure: failureSchema })
437
+ var routingSchema = z2.discriminatedUnion("decision", [
438
+ z2.object({ decision: z2.literal("routed"), tunnel: routedTunnelSchema }),
439
+ z2.object({ decision: z2.literal("not_routed"), failure: failureSchema })
711
440
  ]);
712
- var streamConnectedMetricsSchema = z5.object({
441
+ var streamConnectedMetricsSchema = z2.object({
713
442
  establish_ms: numNonNegSchema,
714
443
  duration_ms: numNonNegSchema,
715
444
  upstream_bytes: intNonNegSchema,
716
445
  downstream_bytes: intNonNegSchema
717
446
  });
718
- var streamFailedMetricsSchema = z5.object({
447
+ var streamFailedMetricsSchema = z2.object({
719
448
  time_to_fail_ms: numNonNegSchema.optional(),
720
449
  establish_ms: numNonNegSchema.optional()
721
450
  });
722
- var terminationSchema = z5.object({
723
- by: z5.enum(["downstream", "upstream", "server", "unknown"]),
724
- reason: z5.enum(["closed", "reset", "timeout", "error", "unknown"]),
725
- message: z5.string().optional()
451
+ var terminationSchema = z2.object({
452
+ by: z2.enum(["downstream", "upstream", "server", "unknown"]),
453
+ reason: z2.enum(["closed", "reset", "timeout", "error", "unknown"]),
454
+ message: z2.string().optional()
726
455
  });
727
- var responseConnectedSchema = z5.object({
728
- outcome: z5.literal("connected"),
456
+ var responseConnectedSchema = z2.object({
457
+ outcome: z2.literal("connected"),
729
458
  established_at: isoDateTimeSchema,
730
459
  upstream: streamEndpointSchema.optional(),
731
460
  metrics: streamConnectedMetricsSchema,
732
461
  termination: terminationSchema.optional(),
733
462
  http: httpResponseStageSchema.optional()
734
463
  });
735
- var responseFailedSchema = z5.object({
736
- outcome: z5.literal("failed"),
464
+ var responseFailedSchema = z2.object({
465
+ outcome: z2.literal("failed"),
737
466
  failure: failureSchema,
738
467
  upstream: streamEndpointSchema.optional(),
739
468
  metrics: streamFailedMetricsSchema.optional(),
740
469
  termination: terminationSchema.optional(),
741
470
  http: httpResponseStageSchema.optional()
742
471
  });
743
- var responseSchema = z5.discriminatedUnion("outcome", [
472
+ var responseSchema = z2.discriminatedUnion("outcome", [
744
473
  responseConnectedSchema,
745
474
  responseFailedSchema
746
475
  ]);
747
- var streamSummarySchema = z5.object({
748
- workspace_id: nonEmptyStringSchema2.optional(),
749
- project_id: nonEmptyStringSchema2.optional(),
750
- cluster_id: nonEmptyStringSchema2.optional(),
751
- user_id: nonEmptyStringSchema2.optional(),
752
- client_id: nonEmptyStringSchema2.optional(),
753
- tunnel_id: nonEmptyStringSchema2.optional(),
754
- stream_id: nonEmptyStringSchema2,
476
+ var streamSummarySchema = z2.object({
477
+ workspace_id: nonEmptyStringSchema.optional(),
478
+ project_id: nonEmptyStringSchema.optional(),
479
+ cluster_id: nonEmptyStringSchema.optional(),
480
+ user_id: nonEmptyStringSchema.optional(),
481
+ client_id: nonEmptyStringSchema.optional(),
482
+ tunnel_id: nonEmptyStringSchema.optional(),
483
+ stream_id: nonEmptyStringSchema,
755
484
  created_at: isoDateTimeSchema,
756
485
  terminated_at: isoDateTimeSchema,
757
- request: z5.object({
486
+ request: z2.object({
758
487
  downstream: streamEndpointSchema,
759
488
  http: httpRequestStageSchema.optional()
760
489
  }),
@@ -764,68 +493,100 @@ var streamSummarySchema = z5.object({
764
493
  });
765
494
 
766
495
  // src/event.ts
767
- var z6 = __toESM(require("zod"));
768
- var isoDateTimeSchema2 = z6.string().datetime({ offset: true });
769
- var initialStateSchema = z6.object({
496
+ var import_tunnel = require("@rstreamlabs/rstream/tunnel");
497
+ var z3 = __toESM(require("zod"));
498
+ var isoDateTimeSchema2 = z3.string().datetime({ offset: true });
499
+ var initialStateSchema = z3.object({
770
500
  snapshot_at: isoDateTimeSchema2,
771
- clients: z6.array(clientSchema),
772
- tunnels: z6.array(tunnelSchema)
501
+ clients: z3.array(clientSchema),
502
+ tunnels: z3.array(import_tunnel.tunnelSchema)
773
503
  });
774
- var eventBaseSchema = z6.object({
775
- id: z6.string().optional(),
504
+ var eventBaseSchema = z3.object({
505
+ id: z3.string().optional(),
776
506
  created_at: isoDateTimeSchema2.optional(),
777
- user_id: z6.string().optional(),
778
- workspace_id: z6.string().optional(),
779
- project_id: z6.string().optional(),
780
- cluster_id: z6.string().optional()
507
+ user_id: z3.string().optional(),
508
+ workspace_id: z3.string().optional(),
509
+ project_id: z3.string().optional(),
510
+ cluster_id: z3.string().optional()
781
511
  });
782
- var withEventBase = (shape) => z6.object(shape).merge(eventBaseSchema).passthrough();
512
+ var withEventBase = (shape) => z3.object(shape).merge(eventBaseSchema).passthrough();
783
513
  var stateInitialEventSchema = withEventBase({
784
- type: z6.literal("state.initial"),
514
+ type: z3.literal("state.initial"),
785
515
  object: initialStateSchema
786
516
  });
787
517
  var streamSummaryEventSchema = withEventBase({
788
- type: z6.literal("stream.summary"),
518
+ type: z3.literal("stream.summary"),
789
519
  object: streamSummarySchema
790
520
  });
791
521
  var commonEventsSchema = [
792
522
  withEventBase({
793
- type: z6.literal("client.created"),
523
+ type: z3.literal("client.created"),
794
524
  object: clientSchema
795
525
  }),
796
526
  withEventBase({
797
- type: z6.literal("client.updated"),
527
+ type: z3.literal("client.updated"),
798
528
  object: clientSchema
799
529
  }),
800
530
  withEventBase({
801
- type: z6.literal("client.deleted"),
531
+ type: z3.literal("client.deleted"),
802
532
  object: clientSchema
803
533
  }),
804
534
  withEventBase({
805
- type: z6.literal("tunnel.created"),
806
- object: tunnelSchema
535
+ type: z3.literal("tunnel.created"),
536
+ object: import_tunnel.tunnelSchema
807
537
  }),
808
538
  withEventBase({
809
- type: z6.literal("tunnel.updated"),
810
- object: tunnelSchema
539
+ type: z3.literal("tunnel.updated"),
540
+ object: import_tunnel.tunnelSchema
811
541
  }),
812
542
  withEventBase({
813
- type: z6.literal("tunnel.deleted"),
814
- object: tunnelSchema
543
+ type: z3.literal("tunnel.deleted"),
544
+ object: import_tunnel.tunnelSchema
815
545
  })
816
546
  ];
817
- var wsEventsSchema = z6.union([
547
+ var wsEventsSchema = z3.union([
818
548
  stateInitialEventSchema,
819
549
  ...commonEventsSchema
820
550
  ]);
821
- var webhookEventsSchema = z6.union([
551
+ var webhookEventsSchema = z3.union([
822
552
  ...commonEventsSchema,
823
553
  streamSummaryEventSchema
824
554
  ]);
825
- var eventSchema = z6.union([wsEventsSchema, webhookEventsSchema]);
555
+ var eventSchema = z3.union([wsEventsSchema, webhookEventsSchema]);
556
+
557
+ // src/tunnel.ts
558
+ var import_tunnel2 = require("@rstreamlabs/rstream/tunnel");
559
+ var z4 = __toESM(require("zod"));
560
+ var DEFAULT_PUBLISHED_PORT = 443;
561
+ var tunnelFilterSchema = import_tunnel2.tunnelSchema.pick({
562
+ id: true,
563
+ name: true,
564
+ type: true,
565
+ status: true,
566
+ client_id: true,
567
+ user_id: true,
568
+ publish: true,
569
+ protocol: true,
570
+ hostname: true,
571
+ http_version: true,
572
+ labels: true
573
+ }).partial();
574
+ var listTunnelsParamsSchema = z4.object({
575
+ limit: z4.number().int().min(1).optional(),
576
+ filters: tunnelFilterSchema.optional()
577
+ });
578
+ var listTunnelsResponseSchema = z4.array(import_tunnel2.tunnelSchema);
579
+ function formatTunnelHost(tunnel) {
580
+ if (!tunnel.hostname) return tunnel.host;
581
+ if (!tunnel.port || tunnel.port === DEFAULT_PUBLISHED_PORT) {
582
+ return tunnel.hostname;
583
+ }
584
+ return `${tunnel.hostname}:${tunnel.port}`;
585
+ }
826
586
 
827
587
  // src/openapi.ts
828
- var z7 = __toESM(require("zod"));
588
+ var import_tunnel5 = require("@rstreamlabs/rstream/tunnel");
589
+ var z5 = __toESM(require("zod"));
829
590
  var jsonContentType = "application/json";
830
591
  var openApiContentType = "application/vnd.oai.openapi+json;version=3.1";
831
592
  function isRecord(value) {
@@ -839,10 +600,10 @@ function dropSchemaKeyword(value) {
839
600
  }
840
601
  function jsonSchemaFor(schema) {
841
602
  return dropSchemaKeyword(
842
- z7.toJSONSchema(schema, {
603
+ z5.toJSONSchema(schema, {
843
604
  unrepresentable: "any",
844
605
  override: (ctx) => {
845
- if (ctx.zodSchema instanceof z7.ZodDate) {
606
+ if (ctx.zodSchema instanceof z5.ZodDate) {
846
607
  ctx.jsonSchema.type = "string";
847
608
  ctx.jsonSchema.format = "date-time";
848
609
  }
@@ -909,7 +670,7 @@ var readEngineStreamsRules = [
909
670
  action: "read"
910
671
  }
911
672
  ];
912
- var watchParamsSchema = z7.object({
673
+ var watchParamsSchema = z5.object({
913
674
  clients: clientFilterSchema.optional(),
914
675
  tunnels: tunnelFilterSchema.optional()
915
676
  });
@@ -1037,7 +798,7 @@ var engineOpenApiDocument = {
1037
798
  Event: jsonSchemaFor(wsEventsSchema),
1038
799
  ListClientsParams: jsonSchemaFor(listClientsParamsSchema),
1039
800
  ListTunnelsParams: jsonSchemaFor(listTunnelsParamsSchema),
1040
- TunnelListItem: jsonSchemaFor(tunnelSchema),
801
+ TunnelListItem: jsonSchemaFor(import_tunnel5.tunnelSchema),
1041
802
  WatchParams: jsonSchemaFor(watchParamsSchema)
1042
803
  }
1043
804
  },
@@ -1288,6 +1049,7 @@ async function resolveManagedTunnelsProject(config) {
1288
1049
  }
1289
1050
 
1290
1051
  // src/tunnels-resource.ts
1052
+ var import_tunnel7 = require("@rstreamlabs/rstream/tunnel");
1291
1053
  function tunnelPathId(id) {
1292
1054
  const normalized = id.trim();
1293
1055
  if (!normalized) {
@@ -1314,34 +1076,34 @@ var RstreamTunnelsResource = class {
1314
1076
  method: "GET"
1315
1077
  }
1316
1078
  );
1317
- return tunnelSchema.parse(response);
1079
+ return import_tunnel7.tunnelSchema.parse(response);
1318
1080
  }
1319
1081
  };
1320
1082
 
1321
1083
  // src/tunnels.ts
1084
+ var import_rstream11 = require("@rstreamlabs/rstream");
1322
1085
  var import_rstream12 = require("@rstreamlabs/rstream");
1323
1086
  var import_rstream13 = require("@rstreamlabs/rstream");
1324
- var import_rstream14 = require("@rstreamlabs/rstream");
1325
1087
 
1326
1088
  // src/turn.ts
1327
1089
  var import_rstream8 = require("@rstreamlabs/rstream");
1328
1090
  var import_rstream9 = require("@rstreamlabs/rstream");
1329
1091
  var import_rstream10 = require("@rstreamlabs/rstream");
1330
- var import_rstream11 = require("@rstreamlabs/rstream");
1331
- var z8 = __toESM(require("zod"));
1092
+ var import_turn = require("@rstreamlabs/rstream/turn");
1093
+ var z6 = __toESM(require("zod"));
1332
1094
  var import_crypto = __toESM(require("crypto"));
1333
1095
  var defaultTURNPort = 3478;
1334
1096
  var defaultTURNSPort = 5349;
1335
1097
  var defaultTURNCredentialTTLSeconds = 10 * 60;
1336
1098
  var maxTURNCredentialTTLSeconds = 60 * 60;
1337
- var turnTokenClaimsSchema = z8.object({
1338
- exp: z8.number().int().optional(),
1339
- iat: z8.number().int().optional(),
1340
- token_endpoint: z8.string().regex(/^[0-9a-f]{8}$/i).optional(),
1341
- tokendpoint: z8.string().regex(/^[0-9a-f]{8}$/i).optional(),
1342
- type: z8.enum(["app", "auth", "pat"])
1099
+ var turnTokenClaimsSchema = z6.object({
1100
+ exp: z6.number().int().optional(),
1101
+ iat: z6.number().int().optional(),
1102
+ token_endpoint: z6.string().regex(/^[0-9a-f]{8}$/i).optional(),
1103
+ tokendpoint: z6.string().regex(/^[0-9a-f]{8}$/i).optional(),
1104
+ type: z6.enum(["app", "auth", "pat"])
1343
1105
  });
1344
- var turnCredentialModeSchema = z8.enum(["api", "app", "pat"]);
1106
+ var turnCredentialModeSchema = z6.enum(["api", "app", "pat"]);
1345
1107
  function normalizeOptionalString2(value) {
1346
1108
  const normalized = value?.trim();
1347
1109
  return normalized ? normalized : void 0;
@@ -1535,7 +1297,7 @@ function createPATTURNCredentials(options) {
1535
1297
  )
1536
1298
  );
1537
1299
  const credential = import_crypto.default.createHmac("sha256", key).update(username, "utf8").digest("base64");
1538
- return import_rstream11.turnCredentialsSchema.parse({
1300
+ return import_turn.turnCredentialsSchema.parse({
1539
1301
  credential,
1540
1302
  ttl,
1541
1303
  urls: createTURNURLs(clusterDomain, options.turnPort, options.turnsPort),
@@ -1587,7 +1349,7 @@ async function createAPPTURNCredentials(options) {
1587
1349
  )
1588
1350
  );
1589
1351
  const credential = import_crypto.default.createHmac("sha256", key).update(username, "utf8").digest("base64");
1590
- return import_rstream11.turnCredentialsSchema.parse({
1352
+ return import_turn.turnCredentialsSchema.parse({
1591
1353
  credential,
1592
1354
  ttl: ttlSeconds,
1593
1355
  urls: createTURNURLs(clusterDomain, options.turnPort, options.turnsPort),
@@ -1802,10 +1564,10 @@ var RstreamTunnelsClient = class {
1802
1564
  const projectEndpoint = normalizeOptionalString3(
1803
1565
  this.config?.projectEndpoint
1804
1566
  );
1805
- if (projectEndpoint !== void 0 && normalizeOptionalString3(this.config?.engine) === void 0 && (0, import_rstream14.readEnvironment)().engine === void 0) {
1567
+ if (projectEndpoint !== void 0 && normalizeOptionalString3(this.config?.engine) === void 0 && (0, import_rstream13.readEnvironment)().engine === void 0) {
1806
1568
  const project = await this.getManagedProject();
1807
1569
  if (project !== void 0) {
1808
- const engine = (0, import_rstream12.getTunnelsProjectEngine)(project);
1570
+ const engine = (0, import_rstream11.getTunnelsProjectEngine)(project);
1809
1571
  if (engine) {
1810
1572
  return normalizeEngineAddress(engine);
1811
1573
  }
@@ -1891,7 +1653,7 @@ var RstreamTunnelsClient = class {
1891
1653
  if (!credentials) {
1892
1654
  return void 0;
1893
1655
  }
1894
- if (!(0, import_rstream13.isClientCredentials)(credentials)) {
1656
+ if (!(0, import_rstream12.isClientCredentials)(credentials)) {
1895
1657
  return credentials.token;
1896
1658
  }
1897
1659
  const tokenParams = await this.getEngineAuthTokenParams();
@@ -1929,6 +1691,7 @@ function normalizeOptionalString3(value) {
1929
1691
  }
1930
1692
 
1931
1693
  // src/watch.ts
1694
+ var import_auth_token2 = require("@rstreamlabs/rstream/auth-token");
1932
1695
  var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
1933
1696
  var maxWatchTokenLifetimeSeconds = 3600;
1934
1697
  var watchTokenIssuedAtSkewSeconds = 300;
@@ -1942,7 +1705,7 @@ function normalizeTransport(transport) {
1942
1705
  throw new Error("Watch: Unsupported transport.");
1943
1706
  }
1944
1707
  function validateWatchQueryToken(token) {
1945
- const parsed = authTokenSchema.safeParse(import_jsonwebtoken.default.decode(token));
1708
+ const parsed = import_auth_token2.authTokenSchema.safeParse(import_jsonwebtoken.default.decode(token));
1946
1709
  if (!parsed.success || parsed.data.type === "pat") {
1947
1710
  throw new Error(
1948
1711
  "Watch requires a short-lived auth or app token for URL-based authentication."
@@ -2095,7 +1858,7 @@ var Watch = class {
2095
1858
  };
2096
1859
 
2097
1860
  // src/webtty.ts
2098
- var z9 = __toESM(require("zod"));
1861
+ var z7 = __toESM(require("zod"));
2099
1862
  var osFamilies = [
2100
1863
  "linux",
2101
1864
  "macos",
@@ -2104,25 +1867,25 @@ var osFamilies = [
2104
1867
  "openbsd",
2105
1868
  "freebsd"
2106
1869
  ];
2107
- var webttyServerSchema = z9.object({
2108
- tunnel_id: z9.string(),
2109
- host: z9.string(),
2110
- token_auth: z9.boolean(),
2111
- os_family: z9.enum(osFamilies).optional(),
2112
- arch: z9.string().optional(),
2113
- os_id: z9.string().optional(),
1870
+ var webttyServerSchema = z7.object({
1871
+ tunnel_id: z7.string(),
1872
+ host: z7.string(),
1873
+ token_auth: z7.boolean(),
1874
+ os_family: z7.enum(osFamilies).optional(),
1875
+ arch: z7.string().optional(),
1876
+ os_id: z7.string().optional(),
2114
1877
  // /etc/os-release::ID (ubuntu, debian, rocky, etc.)
2115
- os_version_id: z9.string().optional(),
1878
+ os_version_id: z7.string().optional(),
2116
1879
  // /etc/os-release::VERSION_ID (24.04, 22.04, 11, 10.0.19045, ...)
2117
- os_version_codename: z9.string().optional(),
1880
+ os_version_codename: z7.string().optional(),
2118
1881
  // /etc/os-release::VERSION_CODENAME (jammy, noble...)
2119
- os_pretty_name: z9.string().optional(),
1882
+ os_pretty_name: z7.string().optional(),
2120
1883
  // /etc/os-release::PRETTY_NAME
2121
- kernel_release: z9.string().optional(),
1884
+ kernel_release: z7.string().optional(),
2122
1885
  // uname -r
2123
- hostname: z9.string().optional(),
1886
+ hostname: z7.string().optional(),
2124
1887
  // uname -n
2125
- labels: z9.record(z9.string(), z9.string().optional()).optional()
1888
+ labels: z7.record(z7.string(), z7.string().optional()).optional()
2126
1889
  });
2127
1890
  function parser(tunnel) {
2128
1891
  if (tunnel.status !== "online") return null;
@@ -2175,18 +1938,11 @@ function parseWebTTYServers(tunnels) {
2175
1938
  RstreamWebhookRessource,
2176
1939
  Tunnels,
2177
1940
  Watch,
2178
- authTokenPermissionsSchema,
2179
- authTokenSchema,
2180
- authTokenScopesSchema,
2181
- authTokenTunnelGrantSchema,
2182
- authTokenTunnelsScopesSchema,
2183
1941
  clientFilterSchema,
2184
1942
  clientSchema,
2185
1943
  createAPITURNCredentials,
2186
1944
  createAPPTURNCredentials,
2187
1945
  createAuthTokenFromClientCredentials,
2188
- createAuthTokenParamsSchema,
2189
- createAuthTokenResponseSchema,
2190
1946
  createPATTURNCredentials,
2191
1947
  createTURNCredentials,
2192
1948
  engineOpenApiDocument,
@@ -2207,9 +1963,7 @@ function parseWebTTYServers(tunnels) {
2207
1963
  streamEndpointSchema,
2208
1964
  streamSummarySchema,
2209
1965
  streamTLSInfoSchema,
2210
- tokenSchema,
2211
1966
  tunnelFilterSchema,
2212
- tunnelSchema,
2213
1967
  turnCredentialModeSchema,
2214
1968
  webhookEventsSchema,
2215
1969
  webttyServerSchema,