@rstreamlabs/tunnels 1.0.1 → 1.0.2

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
@@ -46,6 +46,7 @@ __export(index_exports, {
46
46
  authTokenPermissionsSchema: () => authTokenPermissionsSchema,
47
47
  authTokenSchema: () => authTokenSchema,
48
48
  authTokenScopesSchema: () => authTokenScopesSchema,
49
+ authTokenTunnelGrantSchema: () => authTokenTunnelGrantSchema,
49
50
  authTokenTunnelsScopesSchema: () => authTokenTunnelsScopesSchema,
50
51
  clientSchema: () => clientSchema,
51
52
  createAPITURNCredentials: () => createAPITURNCredentials,
@@ -77,41 +78,6 @@ module.exports = __toCommonJS(index_exports);
77
78
 
78
79
  // src/auth-resource.ts
79
80
  var import_rstream = require("@rstreamlabs/rstream");
80
- var import_rstream2 = require("@rstreamlabs/rstream");
81
- var RstreamAuthResource = class {
82
- client;
83
- constructor(client) {
84
- this.client = client;
85
- }
86
- async createAuthToken(params, options) {
87
- const credentials = options?.credentials || this.client.credentials;
88
- if (!(0, import_rstream2.isClientCredentials)(credentials)) {
89
- throw new Error(
90
- "Application credentials (client id, client secret) are required to create an auth token."
91
- );
92
- }
93
- const engine = options?.engine ?? await this.client.getEngine().catch(() => void 0);
94
- return createAuthTokenFromClientCredentials(credentials, params, {
95
- engine
96
- });
97
- }
98
- };
99
- function createAuthTokenFromClientCredentials(credentials, params, options) {
100
- const payload = {
101
- metadata: {
102
- engine: options?.engine,
103
- scopes: params?.scopes
104
- },
105
- permissions: null,
106
- project_id: params?.project_id,
107
- workspace_id: params?.workspace_id
108
- };
109
- const { token } = (0, import_rstream.createClientCredentialsToken)(credentials, {
110
- claims: payload,
111
- expiresInSeconds: params?.expires_in
112
- });
113
- return { token };
114
- }
115
81
 
116
82
  // src/zod.ts
117
83
  var z = __toESM(require("zod"));
@@ -141,9 +107,9 @@ function filters(base) {
141
107
  const shape = Object.fromEntries(entries);
142
108
  const node = z.lazy(
143
109
  () => z.union([
144
- z.object(shape),
145
- z.object({ AND: z.array(node) }),
146
- z.object({ OR: z.array(node) })
110
+ z.object(shape).strict(),
111
+ z.object({ AND: z.array(node) }).strict(),
112
+ z.object({ OR: z.array(node) }).strict()
147
113
  ])
148
114
  );
149
115
  return node;
@@ -206,6 +172,7 @@ var listTunnelsResponseSchema = z2.array(tunnelSchema);
206
172
 
207
173
  // src/auth.ts
208
174
  var z3 = __toESM(require("zod"));
175
+ var nonEmptyStringSchema = z3.string().trim().min(1);
209
176
  var authTokenPermissionsSchema = z3.array(z3.string());
210
177
  var authTokenTunnelsScopesSchema = z3.object({
211
178
  // Scopes for creating tunnels
@@ -254,45 +221,121 @@ var authTokenScopesSchema = z3.object({
254
221
  tunnels: authTokenTunnelsScopesSchema.optional()
255
222
  // Scopes related to tunnels
256
223
  });
224
+ var authTokenTunnelGrantSchema = z3.object({
225
+ workspaces: z3.array(nonEmptyStringSchema).min(1).optional(),
226
+ projects: z3.array(nonEmptyStringSchema).min(1).optional(),
227
+ scopes: authTokenScopesSchema.optional()
228
+ }).strict().superRefine((grant, ctx) => {
229
+ if (grant.workspaces !== void 0 && grant.projects !== void 0) {
230
+ ctx.addIssue({
231
+ code: z3.ZodIssueCode.custom,
232
+ message: "A grant cannot target workspaces and projects at the same time.",
233
+ path: ["projects"]
234
+ });
235
+ }
236
+ });
237
+ var authTokenCommonSchema = {
238
+ aud: z3.union([z3.string(), z3.array(z3.string())]).optional(),
239
+ exp: z3.number().optional(),
240
+ tunnelsGrants: z3.array(authTokenTunnelGrantSchema).optional(),
241
+ iat: z3.number().optional(),
242
+ iss: z3.string().optional(),
243
+ jti: z3.string().optional(),
244
+ metadata: z3.object({
245
+ engine: z3.string().optional()
246
+ }).strict().optional(),
247
+ nbf: z3.number().optional(),
248
+ sub: z3.string().optional()
249
+ };
257
250
  var authTokenSchema = z3.union([
258
251
  z3.object({
259
252
  type: z3.literal("auth"),
260
253
  userId: z3.string(),
261
- permissions: authTokenPermissionsSchema.nullable()
262
- }),
254
+ permissions: authTokenPermissionsSchema.nullable(),
255
+ ...authTokenCommonSchema
256
+ }).strict(),
263
257
  z3.object({
264
258
  type: z3.literal("pat"),
265
- token_endpoint: z3.string().optional()
266
- }),
259
+ token_endpoint: z3.string().optional(),
260
+ ...authTokenCommonSchema
261
+ }).strict(),
267
262
  z3.object({
268
263
  type: z3.literal("app"),
269
264
  clientId: z3.string(),
270
- permissions: authTokenPermissionsSchema.nullable()
271
- })
272
- ]).and(
273
- z3.object({
274
- workspace_id: z3.string().optional(),
275
- project_id: z3.string().optional(),
276
- metadata: z3.object({
277
- engine: z3.string().optional(),
278
- scopes: authTokenScopesSchema.optional()
279
- }).optional()
280
- })
281
- );
265
+ permissions: authTokenPermissionsSchema.nullable(),
266
+ ...authTokenCommonSchema
267
+ }).strict()
268
+ ]);
282
269
  var tokenSchema = authTokenSchema;
283
270
  var createAuthTokenParamsSchema = z3.object({
284
271
  expires_in: z3.number().default(60),
285
272
  // 1 minute
286
- workspace_id: z3.string().optional(),
287
- project_id: z3.string().optional(),
288
273
  scopes: authTokenScopesSchema.optional(),
274
+ tunnelsGrants: z3.array(authTokenTunnelGrantSchema).optional(),
289
275
  metadata: z3.unknown().optional()
290
276
  // Additional metadata
277
+ }).strict().superRefine((params, ctx) => {
278
+ if (params.scopes !== void 0 && params.tunnelsGrants !== void 0) {
279
+ ctx.addIssue({
280
+ code: z3.ZodIssueCode.custom,
281
+ message: "Use either scopes or tunnelsGrants, not both.",
282
+ path: ["tunnelsGrants"]
283
+ });
284
+ }
291
285
  });
292
286
  var createAuthTokenResponseSchema = z3.object({
293
287
  token: z3.string()
294
288
  });
295
289
 
290
+ // src/auth-resource.ts
291
+ var import_rstream2 = require("@rstreamlabs/rstream");
292
+ var RstreamAuthResource = class {
293
+ client;
294
+ constructor(client) {
295
+ this.client = client;
296
+ }
297
+ async createAuthToken(params, options) {
298
+ const credentials = options?.credentials || this.client.credentials;
299
+ if (!(0, import_rstream2.isClientCredentials)(credentials)) {
300
+ throw new Error(
301
+ "Application credentials (client id, client secret) are required to create an auth token."
302
+ );
303
+ }
304
+ const engine = options?.engine ?? await this.client.getEngine().catch(() => void 0);
305
+ return createAuthTokenFromClientCredentials(credentials, params, {
306
+ engine
307
+ });
308
+ }
309
+ };
310
+ function createAuthTokenFromClientCredentials(credentials, params, options) {
311
+ const tokenParams = createAuthTokenParamsSchema.parse(params ?? {});
312
+ const payload = {
313
+ metadata: {
314
+ engine: options?.engine
315
+ },
316
+ tunnelsGrants: normalizeAuthTokenTunnelGrants(tokenParams),
317
+ permissions: null
318
+ };
319
+ const { token } = (0, import_rstream.createClientCredentialsToken)(credentials, {
320
+ claims: payload,
321
+ expiresInSeconds: tokenParams.expires_in
322
+ });
323
+ return { token };
324
+ }
325
+ function normalizeAuthTokenTunnelGrants(params) {
326
+ if (!params) {
327
+ return void 0;
328
+ }
329
+ const tunnelsGrants = params.tunnelsGrants;
330
+ if (tunnelsGrants !== void 0) {
331
+ return [...tunnelsGrants];
332
+ }
333
+ if (params.scopes) {
334
+ return [{ scopes: params.scopes }];
335
+ }
336
+ return void 0;
337
+ }
338
+
296
339
  // src/client.ts
297
340
  var z4 = __toESM(require("zod"));
298
341
  var clientSchema = z4.object({
@@ -344,7 +387,7 @@ var RstreamClientsResource = class {
344
387
 
345
388
  // src/stream.ts
346
389
  var z5 = __toESM(require("zod"));
347
- var nonEmptyStringSchema = z5.string().min(1);
390
+ var nonEmptyStringSchema2 = z5.string().min(1);
348
391
  var isoDateTimeSchema = z5.string().datetime();
349
392
  var ipAddressSchema = z5.string();
350
393
  var intNonNegSchema = z5.number().int().nonnegative();
@@ -363,12 +406,12 @@ var httpHeadersSchema = z5.record(
363
406
  );
364
407
  var httpProtocolSchema = z5.enum(["http/1.1", "h2", "h2c", "h3"]);
365
408
  var httpRequestSchema = z5.object({
366
- method: nonEmptyStringSchema,
409
+ method: nonEmptyStringSchema2,
367
410
  scheme: z5.string().min(1).optional(),
368
- host: nonEmptyStringSchema.optional(),
369
- path: nonEmptyStringSchema.optional(),
411
+ host: nonEmptyStringSchema2.optional(),
412
+ path: nonEmptyStringSchema2.optional(),
370
413
  query: z5.string().optional(),
371
- url: nonEmptyStringSchema.optional(),
414
+ url: nonEmptyStringSchema2.optional(),
372
415
  headers: httpHeadersSchema.optional(),
373
416
  userAgent: z5.string().optional()
374
417
  });
@@ -463,7 +506,7 @@ var firewallSchema = z5.discriminatedUnion("decision", [
463
506
  })
464
507
  ]);
465
508
  var routedTunnelSchema = z5.object({
466
- tunnelId: nonEmptyStringSchema.optional(),
509
+ tunnelId: nonEmptyStringSchema2.optional(),
467
510
  tunnelName: z5.string().optional(),
468
511
  protocol: z5.string().optional(),
469
512
  published: z5.boolean().optional(),
@@ -514,13 +557,13 @@ var responseSchema = z5.discriminatedUnion("outcome", [
514
557
  responseFailedSchema
515
558
  ]);
516
559
  var streamSummarySchema = z5.object({
517
- workspace_id: nonEmptyStringSchema.optional(),
518
- project_id: nonEmptyStringSchema.optional(),
519
- cluster_id: nonEmptyStringSchema.optional(),
520
- user_id: nonEmptyStringSchema.optional(),
521
- client_id: nonEmptyStringSchema.optional(),
522
- tunnel_id: nonEmptyStringSchema.optional(),
523
- stream_id: nonEmptyStringSchema,
560
+ workspace_id: nonEmptyStringSchema2.optional(),
561
+ project_id: nonEmptyStringSchema2.optional(),
562
+ cluster_id: nonEmptyStringSchema2.optional(),
563
+ user_id: nonEmptyStringSchema2.optional(),
564
+ client_id: nonEmptyStringSchema2.optional(),
565
+ tunnel_id: nonEmptyStringSchema2.optional(),
566
+ stream_id: nonEmptyStringSchema2,
524
567
  created_at: isoDateTimeSchema,
525
568
  terminated_at: isoDateTimeSchema,
526
569
  request: z5.object({
@@ -1336,6 +1379,7 @@ function parseWebTTYServers(tunnels) {
1336
1379
  authTokenPermissionsSchema,
1337
1380
  authTokenSchema,
1338
1381
  authTokenScopesSchema,
1382
+ authTokenTunnelGrantSchema,
1339
1383
  authTokenTunnelsScopesSchema,
1340
1384
  clientSchema,
1341
1385
  createAPITURNCredentials,
package/dist/index.mjs CHANGED
@@ -1,40 +1,5 @@
1
1
  // src/auth-resource.ts
2
2
  import { createClientCredentialsToken } from "@rstreamlabs/rstream";
3
- import { isClientCredentials } from "@rstreamlabs/rstream";
4
- var RstreamAuthResource = class {
5
- client;
6
- constructor(client) {
7
- this.client = client;
8
- }
9
- async createAuthToken(params, options) {
10
- const credentials = options?.credentials || this.client.credentials;
11
- if (!isClientCredentials(credentials)) {
12
- throw new Error(
13
- "Application credentials (client id, client secret) are required to create an auth token."
14
- );
15
- }
16
- const engine = options?.engine ?? await this.client.getEngine().catch(() => void 0);
17
- return createAuthTokenFromClientCredentials(credentials, params, {
18
- engine
19
- });
20
- }
21
- };
22
- function createAuthTokenFromClientCredentials(credentials, params, options) {
23
- const payload = {
24
- metadata: {
25
- engine: options?.engine,
26
- scopes: params?.scopes
27
- },
28
- permissions: null,
29
- project_id: params?.project_id,
30
- workspace_id: params?.workspace_id
31
- };
32
- const { token } = createClientCredentialsToken(credentials, {
33
- claims: payload,
34
- expiresInSeconds: params?.expires_in
35
- });
36
- return { token };
37
- }
38
3
 
39
4
  // src/zod.ts
40
5
  import * as z from "zod";
@@ -64,9 +29,9 @@ function filters(base) {
64
29
  const shape = Object.fromEntries(entries);
65
30
  const node = z.lazy(
66
31
  () => z.union([
67
- z.object(shape),
68
- z.object({ AND: z.array(node) }),
69
- z.object({ OR: z.array(node) })
32
+ z.object(shape).strict(),
33
+ z.object({ AND: z.array(node) }).strict(),
34
+ z.object({ OR: z.array(node) }).strict()
70
35
  ])
71
36
  );
72
37
  return node;
@@ -129,6 +94,7 @@ var listTunnelsResponseSchema = z2.array(tunnelSchema);
129
94
 
130
95
  // src/auth.ts
131
96
  import * as z3 from "zod";
97
+ var nonEmptyStringSchema = z3.string().trim().min(1);
132
98
  var authTokenPermissionsSchema = z3.array(z3.string());
133
99
  var authTokenTunnelsScopesSchema = z3.object({
134
100
  // Scopes for creating tunnels
@@ -177,45 +143,121 @@ var authTokenScopesSchema = z3.object({
177
143
  tunnels: authTokenTunnelsScopesSchema.optional()
178
144
  // Scopes related to tunnels
179
145
  });
146
+ var authTokenTunnelGrantSchema = z3.object({
147
+ workspaces: z3.array(nonEmptyStringSchema).min(1).optional(),
148
+ projects: z3.array(nonEmptyStringSchema).min(1).optional(),
149
+ scopes: authTokenScopesSchema.optional()
150
+ }).strict().superRefine((grant, ctx) => {
151
+ if (grant.workspaces !== void 0 && grant.projects !== void 0) {
152
+ ctx.addIssue({
153
+ code: z3.ZodIssueCode.custom,
154
+ message: "A grant cannot target workspaces and projects at the same time.",
155
+ path: ["projects"]
156
+ });
157
+ }
158
+ });
159
+ var authTokenCommonSchema = {
160
+ aud: z3.union([z3.string(), z3.array(z3.string())]).optional(),
161
+ exp: z3.number().optional(),
162
+ tunnelsGrants: z3.array(authTokenTunnelGrantSchema).optional(),
163
+ iat: z3.number().optional(),
164
+ iss: z3.string().optional(),
165
+ jti: z3.string().optional(),
166
+ metadata: z3.object({
167
+ engine: z3.string().optional()
168
+ }).strict().optional(),
169
+ nbf: z3.number().optional(),
170
+ sub: z3.string().optional()
171
+ };
180
172
  var authTokenSchema = z3.union([
181
173
  z3.object({
182
174
  type: z3.literal("auth"),
183
175
  userId: z3.string(),
184
- permissions: authTokenPermissionsSchema.nullable()
185
- }),
176
+ permissions: authTokenPermissionsSchema.nullable(),
177
+ ...authTokenCommonSchema
178
+ }).strict(),
186
179
  z3.object({
187
180
  type: z3.literal("pat"),
188
- token_endpoint: z3.string().optional()
189
- }),
181
+ token_endpoint: z3.string().optional(),
182
+ ...authTokenCommonSchema
183
+ }).strict(),
190
184
  z3.object({
191
185
  type: z3.literal("app"),
192
186
  clientId: z3.string(),
193
- permissions: authTokenPermissionsSchema.nullable()
194
- })
195
- ]).and(
196
- z3.object({
197
- workspace_id: z3.string().optional(),
198
- project_id: z3.string().optional(),
199
- metadata: z3.object({
200
- engine: z3.string().optional(),
201
- scopes: authTokenScopesSchema.optional()
202
- }).optional()
203
- })
204
- );
187
+ permissions: authTokenPermissionsSchema.nullable(),
188
+ ...authTokenCommonSchema
189
+ }).strict()
190
+ ]);
205
191
  var tokenSchema = authTokenSchema;
206
192
  var createAuthTokenParamsSchema = z3.object({
207
193
  expires_in: z3.number().default(60),
208
194
  // 1 minute
209
- workspace_id: z3.string().optional(),
210
- project_id: z3.string().optional(),
211
195
  scopes: authTokenScopesSchema.optional(),
196
+ tunnelsGrants: z3.array(authTokenTunnelGrantSchema).optional(),
212
197
  metadata: z3.unknown().optional()
213
198
  // Additional metadata
199
+ }).strict().superRefine((params, ctx) => {
200
+ if (params.scopes !== void 0 && params.tunnelsGrants !== void 0) {
201
+ ctx.addIssue({
202
+ code: z3.ZodIssueCode.custom,
203
+ message: "Use either scopes or tunnelsGrants, not both.",
204
+ path: ["tunnelsGrants"]
205
+ });
206
+ }
214
207
  });
215
208
  var createAuthTokenResponseSchema = z3.object({
216
209
  token: z3.string()
217
210
  });
218
211
 
212
+ // src/auth-resource.ts
213
+ import { isClientCredentials } from "@rstreamlabs/rstream";
214
+ var RstreamAuthResource = class {
215
+ client;
216
+ constructor(client) {
217
+ this.client = client;
218
+ }
219
+ async createAuthToken(params, options) {
220
+ const credentials = options?.credentials || this.client.credentials;
221
+ if (!isClientCredentials(credentials)) {
222
+ throw new Error(
223
+ "Application credentials (client id, client secret) are required to create an auth token."
224
+ );
225
+ }
226
+ const engine = options?.engine ?? await this.client.getEngine().catch(() => void 0);
227
+ return createAuthTokenFromClientCredentials(credentials, params, {
228
+ engine
229
+ });
230
+ }
231
+ };
232
+ function createAuthTokenFromClientCredentials(credentials, params, options) {
233
+ const tokenParams = createAuthTokenParamsSchema.parse(params ?? {});
234
+ const payload = {
235
+ metadata: {
236
+ engine: options?.engine
237
+ },
238
+ tunnelsGrants: normalizeAuthTokenTunnelGrants(tokenParams),
239
+ permissions: null
240
+ };
241
+ const { token } = createClientCredentialsToken(credentials, {
242
+ claims: payload,
243
+ expiresInSeconds: tokenParams.expires_in
244
+ });
245
+ return { token };
246
+ }
247
+ function normalizeAuthTokenTunnelGrants(params) {
248
+ if (!params) {
249
+ return void 0;
250
+ }
251
+ const tunnelsGrants = params.tunnelsGrants;
252
+ if (tunnelsGrants !== void 0) {
253
+ return [...tunnelsGrants];
254
+ }
255
+ if (params.scopes) {
256
+ return [{ scopes: params.scopes }];
257
+ }
258
+ return void 0;
259
+ }
260
+
219
261
  // src/client.ts
220
262
  import * as z4 from "zod";
221
263
  var clientSchema = z4.object({
@@ -267,7 +309,7 @@ var RstreamClientsResource = class {
267
309
 
268
310
  // src/stream.ts
269
311
  import * as z5 from "zod";
270
- var nonEmptyStringSchema = z5.string().min(1);
312
+ var nonEmptyStringSchema2 = z5.string().min(1);
271
313
  var isoDateTimeSchema = z5.string().datetime();
272
314
  var ipAddressSchema = z5.string();
273
315
  var intNonNegSchema = z5.number().int().nonnegative();
@@ -286,12 +328,12 @@ var httpHeadersSchema = z5.record(
286
328
  );
287
329
  var httpProtocolSchema = z5.enum(["http/1.1", "h2", "h2c", "h3"]);
288
330
  var httpRequestSchema = z5.object({
289
- method: nonEmptyStringSchema,
331
+ method: nonEmptyStringSchema2,
290
332
  scheme: z5.string().min(1).optional(),
291
- host: nonEmptyStringSchema.optional(),
292
- path: nonEmptyStringSchema.optional(),
333
+ host: nonEmptyStringSchema2.optional(),
334
+ path: nonEmptyStringSchema2.optional(),
293
335
  query: z5.string().optional(),
294
- url: nonEmptyStringSchema.optional(),
336
+ url: nonEmptyStringSchema2.optional(),
295
337
  headers: httpHeadersSchema.optional(),
296
338
  userAgent: z5.string().optional()
297
339
  });
@@ -386,7 +428,7 @@ var firewallSchema = z5.discriminatedUnion("decision", [
386
428
  })
387
429
  ]);
388
430
  var routedTunnelSchema = z5.object({
389
- tunnelId: nonEmptyStringSchema.optional(),
431
+ tunnelId: nonEmptyStringSchema2.optional(),
390
432
  tunnelName: z5.string().optional(),
391
433
  protocol: z5.string().optional(),
392
434
  published: z5.boolean().optional(),
@@ -437,13 +479,13 @@ var responseSchema = z5.discriminatedUnion("outcome", [
437
479
  responseFailedSchema
438
480
  ]);
439
481
  var streamSummarySchema = z5.object({
440
- workspace_id: nonEmptyStringSchema.optional(),
441
- project_id: nonEmptyStringSchema.optional(),
442
- cluster_id: nonEmptyStringSchema.optional(),
443
- user_id: nonEmptyStringSchema.optional(),
444
- client_id: nonEmptyStringSchema.optional(),
445
- tunnel_id: nonEmptyStringSchema.optional(),
446
- stream_id: nonEmptyStringSchema,
482
+ workspace_id: nonEmptyStringSchema2.optional(),
483
+ project_id: nonEmptyStringSchema2.optional(),
484
+ cluster_id: nonEmptyStringSchema2.optional(),
485
+ user_id: nonEmptyStringSchema2.optional(),
486
+ client_id: nonEmptyStringSchema2.optional(),
487
+ tunnel_id: nonEmptyStringSchema2.optional(),
488
+ stream_id: nonEmptyStringSchema2,
447
489
  created_at: isoDateTimeSchema,
448
490
  terminated_at: isoDateTimeSchema,
449
491
  request: z5.object({
@@ -1258,6 +1300,7 @@ export {
1258
1300
  authTokenPermissionsSchema,
1259
1301
  authTokenSchema,
1260
1302
  authTokenScopesSchema,
1303
+ authTokenTunnelGrantSchema,
1261
1304
  authTokenTunnelsScopesSchema,
1262
1305
  clientSchema,
1263
1306
  createAPITURNCredentials,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstreamlabs/tunnels",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "JS/TS SDK for the rstream tunnels data plane and engine APIs.",
5
5
  "author": "@uartnet <hello@rstream.io>",
6
6
  "license": "Apache-2.0",