@rstreamlabs/tunnels 1.0.1 → 1.0.3
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/README.md +14 -6
- package/dist/index.d.mts +2172 -36
- package/dist/index.d.ts +2172 -36
- package/dist/index.js +132 -76
- package/dist/index.mjs +129 -76
- package/package.json +1 -1
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,
|
|
@@ -65,7 +66,9 @@ __export(index_exports, {
|
|
|
65
66
|
resolveTunnelsAPIURL: () => resolveTunnelsAPIURL,
|
|
66
67
|
resolveTunnelsCredentials: () => resolveTunnelsCredentials,
|
|
67
68
|
resolveTunnelsEngine: () => resolveTunnelsEngine,
|
|
69
|
+
streamEndpointSchema: () => streamEndpointSchema,
|
|
68
70
|
streamSummarySchema: () => streamSummarySchema,
|
|
71
|
+
streamTLSInfoSchema: () => streamTLSInfoSchema,
|
|
69
72
|
tokenSchema: () => tokenSchema,
|
|
70
73
|
tunnelSchema: () => tunnelSchema,
|
|
71
74
|
turnCredentialModeSchema: () => turnCredentialModeSchema,
|
|
@@ -77,41 +80,6 @@ module.exports = __toCommonJS(index_exports);
|
|
|
77
80
|
|
|
78
81
|
// src/auth-resource.ts
|
|
79
82
|
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
83
|
|
|
116
84
|
// src/zod.ts
|
|
117
85
|
var z = __toESM(require("zod"));
|
|
@@ -141,9 +109,9 @@ function filters(base) {
|
|
|
141
109
|
const shape = Object.fromEntries(entries);
|
|
142
110
|
const node = z.lazy(
|
|
143
111
|
() => z.union([
|
|
144
|
-
z.object(shape),
|
|
145
|
-
z.object({ AND: z.array(node) }),
|
|
146
|
-
z.object({ OR: z.array(node) })
|
|
112
|
+
z.object(shape).strict(),
|
|
113
|
+
z.object({ AND: z.array(node) }).strict(),
|
|
114
|
+
z.object({ OR: z.array(node) }).strict()
|
|
147
115
|
])
|
|
148
116
|
);
|
|
149
117
|
return node;
|
|
@@ -206,6 +174,7 @@ var listTunnelsResponseSchema = z2.array(tunnelSchema);
|
|
|
206
174
|
|
|
207
175
|
// src/auth.ts
|
|
208
176
|
var z3 = __toESM(require("zod"));
|
|
177
|
+
var nonEmptyStringSchema = z3.string().trim().min(1);
|
|
209
178
|
var authTokenPermissionsSchema = z3.array(z3.string());
|
|
210
179
|
var authTokenTunnelsScopesSchema = z3.object({
|
|
211
180
|
// Scopes for creating tunnels
|
|
@@ -254,45 +223,121 @@ var authTokenScopesSchema = z3.object({
|
|
|
254
223
|
tunnels: authTokenTunnelsScopesSchema.optional()
|
|
255
224
|
// Scopes related to tunnels
|
|
256
225
|
});
|
|
226
|
+
var authTokenTunnelGrantSchema = z3.object({
|
|
227
|
+
workspaces: z3.array(nonEmptyStringSchema).min(1).optional(),
|
|
228
|
+
projects: z3.array(nonEmptyStringSchema).min(1).optional(),
|
|
229
|
+
scopes: authTokenScopesSchema.optional()
|
|
230
|
+
}).strict().superRefine((grant, ctx) => {
|
|
231
|
+
if (grant.workspaces !== void 0 && grant.projects !== void 0) {
|
|
232
|
+
ctx.addIssue({
|
|
233
|
+
code: z3.ZodIssueCode.custom,
|
|
234
|
+
message: "A grant cannot target workspaces and projects at the same time.",
|
|
235
|
+
path: ["projects"]
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
var authTokenCommonSchema = {
|
|
240
|
+
aud: z3.union([z3.string(), z3.array(z3.string())]).optional(),
|
|
241
|
+
exp: z3.number().optional(),
|
|
242
|
+
tunnelsGrants: z3.array(authTokenTunnelGrantSchema).optional(),
|
|
243
|
+
iat: z3.number().optional(),
|
|
244
|
+
iss: z3.string().optional(),
|
|
245
|
+
jti: z3.string().optional(),
|
|
246
|
+
metadata: z3.object({
|
|
247
|
+
engine: z3.string().optional()
|
|
248
|
+
}).strict().optional(),
|
|
249
|
+
nbf: z3.number().optional(),
|
|
250
|
+
sub: z3.string().optional()
|
|
251
|
+
};
|
|
257
252
|
var authTokenSchema = z3.union([
|
|
258
253
|
z3.object({
|
|
259
254
|
type: z3.literal("auth"),
|
|
260
255
|
userId: z3.string(),
|
|
261
|
-
permissions: authTokenPermissionsSchema.nullable()
|
|
262
|
-
|
|
256
|
+
permissions: authTokenPermissionsSchema.nullable(),
|
|
257
|
+
...authTokenCommonSchema
|
|
258
|
+
}).strict(),
|
|
263
259
|
z3.object({
|
|
264
260
|
type: z3.literal("pat"),
|
|
265
|
-
token_endpoint: z3.string().optional()
|
|
266
|
-
|
|
261
|
+
token_endpoint: z3.string().optional(),
|
|
262
|
+
...authTokenCommonSchema
|
|
263
|
+
}).strict(),
|
|
267
264
|
z3.object({
|
|
268
265
|
type: z3.literal("app"),
|
|
269
266
|
clientId: z3.string(),
|
|
270
|
-
permissions: authTokenPermissionsSchema.nullable()
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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
|
-
);
|
|
267
|
+
permissions: authTokenPermissionsSchema.nullable(),
|
|
268
|
+
...authTokenCommonSchema
|
|
269
|
+
}).strict()
|
|
270
|
+
]);
|
|
282
271
|
var tokenSchema = authTokenSchema;
|
|
283
272
|
var createAuthTokenParamsSchema = z3.object({
|
|
284
273
|
expires_in: z3.number().default(60),
|
|
285
274
|
// 1 minute
|
|
286
|
-
workspace_id: z3.string().optional(),
|
|
287
|
-
project_id: z3.string().optional(),
|
|
288
275
|
scopes: authTokenScopesSchema.optional(),
|
|
276
|
+
tunnelsGrants: z3.array(authTokenTunnelGrantSchema).optional(),
|
|
289
277
|
metadata: z3.unknown().optional()
|
|
290
278
|
// Additional metadata
|
|
279
|
+
}).strict().superRefine((params, ctx) => {
|
|
280
|
+
if (params.scopes !== void 0 && params.tunnelsGrants !== void 0) {
|
|
281
|
+
ctx.addIssue({
|
|
282
|
+
code: z3.ZodIssueCode.custom,
|
|
283
|
+
message: "Use either scopes or tunnelsGrants, not both.",
|
|
284
|
+
path: ["tunnelsGrants"]
|
|
285
|
+
});
|
|
286
|
+
}
|
|
291
287
|
});
|
|
292
288
|
var createAuthTokenResponseSchema = z3.object({
|
|
293
289
|
token: z3.string()
|
|
294
290
|
});
|
|
295
291
|
|
|
292
|
+
// src/auth-resource.ts
|
|
293
|
+
var import_rstream2 = require("@rstreamlabs/rstream");
|
|
294
|
+
var RstreamAuthResource = class {
|
|
295
|
+
client;
|
|
296
|
+
constructor(client) {
|
|
297
|
+
this.client = client;
|
|
298
|
+
}
|
|
299
|
+
async createAuthToken(params, options) {
|
|
300
|
+
const credentials = options?.credentials || this.client.credentials;
|
|
301
|
+
if (!(0, import_rstream2.isClientCredentials)(credentials)) {
|
|
302
|
+
throw new Error(
|
|
303
|
+
"Application credentials (client id, client secret) are required to create an auth token."
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
const engine = options?.engine ?? await this.client.getEngine().catch(() => void 0);
|
|
307
|
+
return createAuthTokenFromClientCredentials(credentials, params, {
|
|
308
|
+
engine
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
function createAuthTokenFromClientCredentials(credentials, params, options) {
|
|
313
|
+
const tokenParams = createAuthTokenParamsSchema.parse(params ?? {});
|
|
314
|
+
const payload = {
|
|
315
|
+
metadata: {
|
|
316
|
+
engine: options?.engine
|
|
317
|
+
},
|
|
318
|
+
tunnelsGrants: normalizeAuthTokenTunnelGrants(tokenParams),
|
|
319
|
+
permissions: null
|
|
320
|
+
};
|
|
321
|
+
const { token } = (0, import_rstream.createClientCredentialsToken)(credentials, {
|
|
322
|
+
claims: payload,
|
|
323
|
+
expiresInSeconds: tokenParams.expires_in
|
|
324
|
+
});
|
|
325
|
+
return { token };
|
|
326
|
+
}
|
|
327
|
+
function normalizeAuthTokenTunnelGrants(params) {
|
|
328
|
+
if (!params) {
|
|
329
|
+
return void 0;
|
|
330
|
+
}
|
|
331
|
+
const tunnelsGrants = params.tunnelsGrants;
|
|
332
|
+
if (tunnelsGrants !== void 0) {
|
|
333
|
+
return [...tunnelsGrants];
|
|
334
|
+
}
|
|
335
|
+
if (params.scopes) {
|
|
336
|
+
return [{ scopes: params.scopes }];
|
|
337
|
+
}
|
|
338
|
+
return void 0;
|
|
339
|
+
}
|
|
340
|
+
|
|
296
341
|
// src/client.ts
|
|
297
342
|
var z4 = __toESM(require("zod"));
|
|
298
343
|
var clientSchema = z4.object({
|
|
@@ -344,8 +389,8 @@ var RstreamClientsResource = class {
|
|
|
344
389
|
|
|
345
390
|
// src/stream.ts
|
|
346
391
|
var z5 = __toESM(require("zod"));
|
|
347
|
-
var
|
|
348
|
-
var isoDateTimeSchema = z5.string().datetime();
|
|
392
|
+
var nonEmptyStringSchema2 = z5.string().min(1);
|
|
393
|
+
var isoDateTimeSchema = z5.string().datetime({ offset: true });
|
|
349
394
|
var ipAddressSchema = z5.string();
|
|
350
395
|
var intNonNegSchema = z5.number().int().nonnegative();
|
|
351
396
|
var numNonNegSchema = z5.number().nonnegative();
|
|
@@ -353,9 +398,14 @@ var geolocationSchema = z5.object({
|
|
|
353
398
|
country: z5.string().optional(),
|
|
354
399
|
region: z5.string().optional()
|
|
355
400
|
});
|
|
356
|
-
var
|
|
401
|
+
var streamTLSInfoSchema = z5.object({
|
|
402
|
+
version: z5.string().min(1).optional(),
|
|
403
|
+
cipher: z5.string().min(1).optional()
|
|
404
|
+
});
|
|
405
|
+
var streamEndpointSchema = z5.object({
|
|
357
406
|
ip: ipAddressSchema.optional(),
|
|
358
|
-
geolocation: geolocationSchema.optional()
|
|
407
|
+
geolocation: geolocationSchema.optional(),
|
|
408
|
+
tls: streamTLSInfoSchema.optional()
|
|
359
409
|
});
|
|
360
410
|
var httpHeadersSchema = z5.record(
|
|
361
411
|
z5.string(),
|
|
@@ -363,12 +413,12 @@ var httpHeadersSchema = z5.record(
|
|
|
363
413
|
);
|
|
364
414
|
var httpProtocolSchema = z5.enum(["http/1.1", "h2", "h2c", "h3"]);
|
|
365
415
|
var httpRequestSchema = z5.object({
|
|
366
|
-
method:
|
|
416
|
+
method: nonEmptyStringSchema2,
|
|
367
417
|
scheme: z5.string().min(1).optional(),
|
|
368
|
-
host:
|
|
369
|
-
path:
|
|
418
|
+
host: nonEmptyStringSchema2.optional(),
|
|
419
|
+
path: nonEmptyStringSchema2.optional(),
|
|
370
420
|
query: z5.string().optional(),
|
|
371
|
-
url:
|
|
421
|
+
url: nonEmptyStringSchema2.optional(),
|
|
372
422
|
headers: httpHeadersSchema.optional(),
|
|
373
423
|
userAgent: z5.string().optional()
|
|
374
424
|
});
|
|
@@ -424,6 +474,9 @@ var unauthorizedSchema = z5.discriminatedUnion("reason", [
|
|
|
424
474
|
unauthorizedReasonSchema({
|
|
425
475
|
reason: z5.literal("user_mismatch")
|
|
426
476
|
}),
|
|
477
|
+
unauthorizedReasonSchema({
|
|
478
|
+
reason: z5.literal("insufficient_scope")
|
|
479
|
+
}),
|
|
427
480
|
unauthorizedReasonSchema({
|
|
428
481
|
reason: z5.literal("policy_denied"),
|
|
429
482
|
policy: z5.enum(["ip", "geo", "mtls", "challenge", "other"]),
|
|
@@ -463,7 +516,7 @@ var firewallSchema = z5.discriminatedUnion("decision", [
|
|
|
463
516
|
})
|
|
464
517
|
]);
|
|
465
518
|
var routedTunnelSchema = z5.object({
|
|
466
|
-
tunnelId:
|
|
519
|
+
tunnelId: nonEmptyStringSchema2.optional(),
|
|
467
520
|
tunnelName: z5.string().optional(),
|
|
468
521
|
protocol: z5.string().optional(),
|
|
469
522
|
published: z5.boolean().optional(),
|
|
@@ -496,7 +549,7 @@ var terminationSchema = z5.object({
|
|
|
496
549
|
var responseConnectedSchema = z5.object({
|
|
497
550
|
outcome: z5.literal("connected"),
|
|
498
551
|
established_at: isoDateTimeSchema,
|
|
499
|
-
upstream:
|
|
552
|
+
upstream: streamEndpointSchema.optional(),
|
|
500
553
|
metrics: streamConnectedMetricsSchema,
|
|
501
554
|
termination: terminationSchema.optional(),
|
|
502
555
|
http: httpResponseStageSchema.optional()
|
|
@@ -504,7 +557,7 @@ var responseConnectedSchema = z5.object({
|
|
|
504
557
|
var responseFailedSchema = z5.object({
|
|
505
558
|
outcome: z5.literal("failed"),
|
|
506
559
|
failure: failureSchema,
|
|
507
|
-
upstream:
|
|
560
|
+
upstream: streamEndpointSchema.optional(),
|
|
508
561
|
metrics: streamFailedMetricsSchema.optional(),
|
|
509
562
|
termination: terminationSchema.optional(),
|
|
510
563
|
http: httpResponseStageSchema.optional()
|
|
@@ -514,17 +567,17 @@ var responseSchema = z5.discriminatedUnion("outcome", [
|
|
|
514
567
|
responseFailedSchema
|
|
515
568
|
]);
|
|
516
569
|
var streamSummarySchema = z5.object({
|
|
517
|
-
workspace_id:
|
|
518
|
-
project_id:
|
|
519
|
-
cluster_id:
|
|
520
|
-
user_id:
|
|
521
|
-
client_id:
|
|
522
|
-
tunnel_id:
|
|
523
|
-
stream_id:
|
|
570
|
+
workspace_id: nonEmptyStringSchema2.optional(),
|
|
571
|
+
project_id: nonEmptyStringSchema2.optional(),
|
|
572
|
+
cluster_id: nonEmptyStringSchema2.optional(),
|
|
573
|
+
user_id: nonEmptyStringSchema2.optional(),
|
|
574
|
+
client_id: nonEmptyStringSchema2.optional(),
|
|
575
|
+
tunnel_id: nonEmptyStringSchema2.optional(),
|
|
576
|
+
stream_id: nonEmptyStringSchema2,
|
|
524
577
|
created_at: isoDateTimeSchema,
|
|
525
578
|
terminated_at: isoDateTimeSchema,
|
|
526
579
|
request: z5.object({
|
|
527
|
-
downstream:
|
|
580
|
+
downstream: streamEndpointSchema,
|
|
528
581
|
http: httpRequestStageSchema.optional()
|
|
529
582
|
}),
|
|
530
583
|
firewall: firewallSchema,
|
|
@@ -534,7 +587,7 @@ var streamSummarySchema = z5.object({
|
|
|
534
587
|
|
|
535
588
|
// src/event.ts
|
|
536
589
|
var z6 = __toESM(require("zod"));
|
|
537
|
-
var isoDateTimeSchema2 = z6.string().datetime();
|
|
590
|
+
var isoDateTimeSchema2 = z6.string().datetime({ offset: true });
|
|
538
591
|
var initialStateSchema = z6.object({
|
|
539
592
|
snapshot_at: isoDateTimeSchema2,
|
|
540
593
|
clients: z6.array(clientSchema),
|
|
@@ -1336,6 +1389,7 @@ function parseWebTTYServers(tunnels) {
|
|
|
1336
1389
|
authTokenPermissionsSchema,
|
|
1337
1390
|
authTokenSchema,
|
|
1338
1391
|
authTokenScopesSchema,
|
|
1392
|
+
authTokenTunnelGrantSchema,
|
|
1339
1393
|
authTokenTunnelsScopesSchema,
|
|
1340
1394
|
clientSchema,
|
|
1341
1395
|
createAPITURNCredentials,
|
|
@@ -1355,7 +1409,9 @@ function parseWebTTYServers(tunnels) {
|
|
|
1355
1409
|
resolveTunnelsAPIURL,
|
|
1356
1410
|
resolveTunnelsCredentials,
|
|
1357
1411
|
resolveTunnelsEngine,
|
|
1412
|
+
streamEndpointSchema,
|
|
1358
1413
|
streamSummarySchema,
|
|
1414
|
+
streamTLSInfoSchema,
|
|
1359
1415
|
tokenSchema,
|
|
1360
1416
|
tunnelSchema,
|
|
1361
1417
|
turnCredentialModeSchema,
|
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
|
-
|
|
196
|
-
|
|
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,8 +309,8 @@ var RstreamClientsResource = class {
|
|
|
267
309
|
|
|
268
310
|
// src/stream.ts
|
|
269
311
|
import * as z5 from "zod";
|
|
270
|
-
var
|
|
271
|
-
var isoDateTimeSchema = z5.string().datetime();
|
|
312
|
+
var nonEmptyStringSchema2 = z5.string().min(1);
|
|
313
|
+
var isoDateTimeSchema = z5.string().datetime({ offset: true });
|
|
272
314
|
var ipAddressSchema = z5.string();
|
|
273
315
|
var intNonNegSchema = z5.number().int().nonnegative();
|
|
274
316
|
var numNonNegSchema = z5.number().nonnegative();
|
|
@@ -276,9 +318,14 @@ var geolocationSchema = z5.object({
|
|
|
276
318
|
country: z5.string().optional(),
|
|
277
319
|
region: z5.string().optional()
|
|
278
320
|
});
|
|
279
|
-
var
|
|
321
|
+
var streamTLSInfoSchema = z5.object({
|
|
322
|
+
version: z5.string().min(1).optional(),
|
|
323
|
+
cipher: z5.string().min(1).optional()
|
|
324
|
+
});
|
|
325
|
+
var streamEndpointSchema = z5.object({
|
|
280
326
|
ip: ipAddressSchema.optional(),
|
|
281
|
-
geolocation: geolocationSchema.optional()
|
|
327
|
+
geolocation: geolocationSchema.optional(),
|
|
328
|
+
tls: streamTLSInfoSchema.optional()
|
|
282
329
|
});
|
|
283
330
|
var httpHeadersSchema = z5.record(
|
|
284
331
|
z5.string(),
|
|
@@ -286,12 +333,12 @@ var httpHeadersSchema = z5.record(
|
|
|
286
333
|
);
|
|
287
334
|
var httpProtocolSchema = z5.enum(["http/1.1", "h2", "h2c", "h3"]);
|
|
288
335
|
var httpRequestSchema = z5.object({
|
|
289
|
-
method:
|
|
336
|
+
method: nonEmptyStringSchema2,
|
|
290
337
|
scheme: z5.string().min(1).optional(),
|
|
291
|
-
host:
|
|
292
|
-
path:
|
|
338
|
+
host: nonEmptyStringSchema2.optional(),
|
|
339
|
+
path: nonEmptyStringSchema2.optional(),
|
|
293
340
|
query: z5.string().optional(),
|
|
294
|
-
url:
|
|
341
|
+
url: nonEmptyStringSchema2.optional(),
|
|
295
342
|
headers: httpHeadersSchema.optional(),
|
|
296
343
|
userAgent: z5.string().optional()
|
|
297
344
|
});
|
|
@@ -347,6 +394,9 @@ var unauthorizedSchema = z5.discriminatedUnion("reason", [
|
|
|
347
394
|
unauthorizedReasonSchema({
|
|
348
395
|
reason: z5.literal("user_mismatch")
|
|
349
396
|
}),
|
|
397
|
+
unauthorizedReasonSchema({
|
|
398
|
+
reason: z5.literal("insufficient_scope")
|
|
399
|
+
}),
|
|
350
400
|
unauthorizedReasonSchema({
|
|
351
401
|
reason: z5.literal("policy_denied"),
|
|
352
402
|
policy: z5.enum(["ip", "geo", "mtls", "challenge", "other"]),
|
|
@@ -386,7 +436,7 @@ var firewallSchema = z5.discriminatedUnion("decision", [
|
|
|
386
436
|
})
|
|
387
437
|
]);
|
|
388
438
|
var routedTunnelSchema = z5.object({
|
|
389
|
-
tunnelId:
|
|
439
|
+
tunnelId: nonEmptyStringSchema2.optional(),
|
|
390
440
|
tunnelName: z5.string().optional(),
|
|
391
441
|
protocol: z5.string().optional(),
|
|
392
442
|
published: z5.boolean().optional(),
|
|
@@ -419,7 +469,7 @@ var terminationSchema = z5.object({
|
|
|
419
469
|
var responseConnectedSchema = z5.object({
|
|
420
470
|
outcome: z5.literal("connected"),
|
|
421
471
|
established_at: isoDateTimeSchema,
|
|
422
|
-
upstream:
|
|
472
|
+
upstream: streamEndpointSchema.optional(),
|
|
423
473
|
metrics: streamConnectedMetricsSchema,
|
|
424
474
|
termination: terminationSchema.optional(),
|
|
425
475
|
http: httpResponseStageSchema.optional()
|
|
@@ -427,7 +477,7 @@ var responseConnectedSchema = z5.object({
|
|
|
427
477
|
var responseFailedSchema = z5.object({
|
|
428
478
|
outcome: z5.literal("failed"),
|
|
429
479
|
failure: failureSchema,
|
|
430
|
-
upstream:
|
|
480
|
+
upstream: streamEndpointSchema.optional(),
|
|
431
481
|
metrics: streamFailedMetricsSchema.optional(),
|
|
432
482
|
termination: terminationSchema.optional(),
|
|
433
483
|
http: httpResponseStageSchema.optional()
|
|
@@ -437,17 +487,17 @@ var responseSchema = z5.discriminatedUnion("outcome", [
|
|
|
437
487
|
responseFailedSchema
|
|
438
488
|
]);
|
|
439
489
|
var streamSummarySchema = z5.object({
|
|
440
|
-
workspace_id:
|
|
441
|
-
project_id:
|
|
442
|
-
cluster_id:
|
|
443
|
-
user_id:
|
|
444
|
-
client_id:
|
|
445
|
-
tunnel_id:
|
|
446
|
-
stream_id:
|
|
490
|
+
workspace_id: nonEmptyStringSchema2.optional(),
|
|
491
|
+
project_id: nonEmptyStringSchema2.optional(),
|
|
492
|
+
cluster_id: nonEmptyStringSchema2.optional(),
|
|
493
|
+
user_id: nonEmptyStringSchema2.optional(),
|
|
494
|
+
client_id: nonEmptyStringSchema2.optional(),
|
|
495
|
+
tunnel_id: nonEmptyStringSchema2.optional(),
|
|
496
|
+
stream_id: nonEmptyStringSchema2,
|
|
447
497
|
created_at: isoDateTimeSchema,
|
|
448
498
|
terminated_at: isoDateTimeSchema,
|
|
449
499
|
request: z5.object({
|
|
450
|
-
downstream:
|
|
500
|
+
downstream: streamEndpointSchema,
|
|
451
501
|
http: httpRequestStageSchema.optional()
|
|
452
502
|
}),
|
|
453
503
|
firewall: firewallSchema,
|
|
@@ -457,7 +507,7 @@ var streamSummarySchema = z5.object({
|
|
|
457
507
|
|
|
458
508
|
// src/event.ts
|
|
459
509
|
import * as z6 from "zod";
|
|
460
|
-
var isoDateTimeSchema2 = z6.string().datetime();
|
|
510
|
+
var isoDateTimeSchema2 = z6.string().datetime({ offset: true });
|
|
461
511
|
var initialStateSchema = z6.object({
|
|
462
512
|
snapshot_at: isoDateTimeSchema2,
|
|
463
513
|
clients: z6.array(clientSchema),
|
|
@@ -1258,6 +1308,7 @@ export {
|
|
|
1258
1308
|
authTokenPermissionsSchema,
|
|
1259
1309
|
authTokenSchema,
|
|
1260
1310
|
authTokenScopesSchema,
|
|
1311
|
+
authTokenTunnelGrantSchema,
|
|
1261
1312
|
authTokenTunnelsScopesSchema,
|
|
1262
1313
|
clientSchema,
|
|
1263
1314
|
createAPITURNCredentials,
|
|
@@ -1277,7 +1328,9 @@ export {
|
|
|
1277
1328
|
resolveTunnelsAPIURL,
|
|
1278
1329
|
resolveTunnelsCredentials,
|
|
1279
1330
|
resolveTunnelsEngine,
|
|
1331
|
+
streamEndpointSchema,
|
|
1280
1332
|
streamSummarySchema,
|
|
1333
|
+
streamTLSInfoSchema,
|
|
1281
1334
|
tokenSchema,
|
|
1282
1335
|
tunnelSchema,
|
|
1283
1336
|
turnCredentialModeSchema,
|