@rstreamlabs/rstream 1.4.0 → 1.5.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.d.mts +2450 -75
- package/dist/index.d.ts +2450 -75
- package/dist/index.js +177 -53
- package/dist/index.mjs +168 -49
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -37,16 +37,21 @@ __export(index_exports, {
|
|
|
37
37
|
RstreamTunnelsRessource: () => RstreamTunnelsRessource,
|
|
38
38
|
RstreamWebHooksRessource: () => RstreamWebHooksRessource,
|
|
39
39
|
Watch: () => Watch,
|
|
40
|
+
authTokenPermissionsSchema: () => authTokenPermissionsSchema,
|
|
41
|
+
authTokenSchema: () => authTokenSchema,
|
|
42
|
+
authTokenScopesSchema: () => authTokenScopesSchema,
|
|
43
|
+
authTokenTunnelsScopesSchema: () => authTokenTunnelsScopesSchema,
|
|
40
44
|
clientSchema: () => clientSchema,
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
createAuthTokenParamsSchema: () => createAuthTokenParamsSchema,
|
|
46
|
+
createAuthTokenResponseSchema: () => createAuthTokenResponseSchema,
|
|
43
47
|
eventSchema: () => eventSchema,
|
|
44
48
|
listClientsParamsSchema: () => listClientsParamsSchema,
|
|
45
49
|
listClientsResponseSchema: () => listClientsResponseSchema,
|
|
46
50
|
listTunnelsParamsSchema: () => listTunnelsParamsSchema,
|
|
47
51
|
listTunnelsResponseSchema: () => listTunnelsResponseSchema,
|
|
48
|
-
|
|
49
|
-
tunnelSchema: () => tunnelSchema
|
|
52
|
+
parseWebTTYServers: () => parseWebTTYServers,
|
|
53
|
+
tunnelSchema: () => tunnelSchema,
|
|
54
|
+
webttyServerSchema: () => webttyServerSchema
|
|
50
55
|
});
|
|
51
56
|
module.exports = __toCommonJS(index_exports);
|
|
52
57
|
|
|
@@ -58,11 +63,11 @@ var RstreamAuthRessource = class {
|
|
|
58
63
|
constructor(client) {
|
|
59
64
|
this.client = client;
|
|
60
65
|
}
|
|
61
|
-
async
|
|
66
|
+
async createAuthToken(params, options) {
|
|
62
67
|
const credentials = options?.credentials || this.client.credentials;
|
|
63
68
|
if (!credentials || !("clientId" in credentials)) {
|
|
64
69
|
throw new Error(
|
|
65
|
-
"Application credentials (client id, client secret) are required to create
|
|
70
|
+
"Application credentials (client id, client secret) are required to create an auth token."
|
|
66
71
|
);
|
|
67
72
|
}
|
|
68
73
|
const now = Math.floor(Date.now() / 1e3);
|
|
@@ -74,9 +79,10 @@ var RstreamAuthRessource = class {
|
|
|
74
79
|
// Expiration time
|
|
75
80
|
type: "app",
|
|
76
81
|
clientId: credentials.clientId,
|
|
82
|
+
permissions: null,
|
|
77
83
|
metadata: {
|
|
78
84
|
engine: this.client.engine,
|
|
79
|
-
|
|
85
|
+
scopes: params?.scopes
|
|
80
86
|
}
|
|
81
87
|
};
|
|
82
88
|
const pk = import_crypto.default.createPrivateKey({
|
|
@@ -184,60 +190,79 @@ var listTunnelsResponseSchema = z2.array(tunnelSchema);
|
|
|
184
190
|
|
|
185
191
|
// src/auth.ts
|
|
186
192
|
var z3 = __toESM(require("zod"));
|
|
187
|
-
var
|
|
188
|
-
|
|
189
|
-
//
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
193
|
+
var authTokenPermissionsSchema = z3.array(z3.string());
|
|
194
|
+
var authTokenTunnelsScopesSchema = z3.object({
|
|
195
|
+
// Scopes for creating tunnels
|
|
196
|
+
create: z3.union([
|
|
197
|
+
z3.boolean(),
|
|
198
|
+
z3.object({
|
|
199
|
+
filters: filters(
|
|
200
|
+
tunnelSchema.omit({
|
|
201
|
+
client_id: true,
|
|
202
|
+
user_id: true,
|
|
203
|
+
status: true,
|
|
204
|
+
creation_date: true
|
|
205
|
+
})
|
|
206
|
+
).optional()
|
|
207
|
+
})
|
|
208
|
+
]).optional(),
|
|
209
|
+
// Scopes for connecting to tunnels
|
|
210
|
+
connect: z3.union([
|
|
211
|
+
z3.boolean(),
|
|
212
|
+
z3.object({
|
|
213
|
+
filters: filters(tunnelSchema).optional(),
|
|
214
|
+
params: filters(
|
|
215
|
+
z3.object({
|
|
216
|
+
path: z3.string().optional()
|
|
217
|
+
})
|
|
218
|
+
).optional()
|
|
219
|
+
})
|
|
220
|
+
]).optional(),
|
|
221
|
+
// Scopes for listing tunnels
|
|
222
|
+
list: z3.union([
|
|
223
|
+
z3.boolean(),
|
|
224
|
+
z3.object({
|
|
225
|
+
filters: filters(tunnelSchema).optional(),
|
|
226
|
+
select: select(tunnelSchema).optional()
|
|
227
|
+
})
|
|
228
|
+
]).optional()
|
|
221
229
|
});
|
|
222
|
-
var
|
|
223
|
-
|
|
230
|
+
var authTokenScopesSchema = z3.object({
|
|
231
|
+
tunnels: authTokenTunnelsScopesSchema.optional()
|
|
232
|
+
// Scopes related to tunnels
|
|
224
233
|
});
|
|
225
|
-
var
|
|
234
|
+
var authTokenSchema = z3.union([
|
|
235
|
+
z3.object({
|
|
236
|
+
type: z3.literal("auth"),
|
|
237
|
+
userId: z3.string(),
|
|
238
|
+
permissions: authTokenPermissionsSchema.nullable()
|
|
239
|
+
}),
|
|
226
240
|
z3.object({
|
|
227
241
|
type: z3.literal("pat")
|
|
228
242
|
}),
|
|
229
243
|
z3.object({
|
|
230
244
|
type: z3.literal("app"),
|
|
231
|
-
clientId: z3.string()
|
|
245
|
+
clientId: z3.string(),
|
|
246
|
+
permissions: authTokenPermissionsSchema.nullable()
|
|
232
247
|
})
|
|
233
248
|
]).and(
|
|
234
249
|
z3.object({
|
|
235
250
|
metadata: z3.object({
|
|
236
251
|
engine: z3.string().optional(),
|
|
237
|
-
|
|
252
|
+
scopes: authTokenScopesSchema.optional()
|
|
238
253
|
}).optional()
|
|
239
254
|
})
|
|
240
255
|
);
|
|
256
|
+
var createAuthTokenParamsSchema = z3.object({
|
|
257
|
+
expires_in: z3.number().default(60),
|
|
258
|
+
// 1 minute
|
|
259
|
+
scopes: authTokenScopesSchema.optional(),
|
|
260
|
+
metadata: z3.unknown().optional()
|
|
261
|
+
// Additional metadata
|
|
262
|
+
});
|
|
263
|
+
var createAuthTokenResponseSchema = z3.object({
|
|
264
|
+
token: z3.string()
|
|
265
|
+
});
|
|
241
266
|
|
|
242
267
|
// src/client.ts
|
|
243
268
|
var z4 = __toESM(require("zod"));
|
|
@@ -450,7 +475,7 @@ var RstreamClient = class {
|
|
|
450
475
|
return credentials.token;
|
|
451
476
|
}
|
|
452
477
|
if (credentials && "clientId" in credentials) {
|
|
453
|
-
return (await this.auth.
|
|
478
|
+
return (await this.auth.createAuthToken(void 0, {
|
|
454
479
|
credentials: {
|
|
455
480
|
clientId: credentials.clientId,
|
|
456
481
|
clientSecret: credentials.clientSecret
|
|
@@ -494,8 +519,8 @@ var Watch = class {
|
|
|
494
519
|
throw new Error("Watch: Connection already started or closed.");
|
|
495
520
|
}
|
|
496
521
|
this.connectionState = "connecting";
|
|
497
|
-
const token = await this.config.auth
|
|
498
|
-
const payload =
|
|
522
|
+
const token = typeof this.config.auth === "function" ? await this.config.auth() : this.config.auth;
|
|
523
|
+
const payload = authTokenSchema.parse(
|
|
499
524
|
import_jsonwebtoken2.default.decode(token, { complete: false })
|
|
500
525
|
);
|
|
501
526
|
const base = `https://${this.config.engine || payload.metadata?.engine || "engine.rstream.io:443"}`;
|
|
@@ -522,6 +547,13 @@ var Watch = class {
|
|
|
522
547
|
this.disconnect();
|
|
523
548
|
}
|
|
524
549
|
};
|
|
550
|
+
if (this.connection instanceof WebSocket) {
|
|
551
|
+
this.connection.onclose = () => {
|
|
552
|
+
if (this.connectionState !== "closed") {
|
|
553
|
+
this.disconnect();
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
}
|
|
525
557
|
}
|
|
526
558
|
disconnect() {
|
|
527
559
|
if (this.connection) {
|
|
@@ -537,6 +569,93 @@ var Watch = class {
|
|
|
537
569
|
}
|
|
538
570
|
}
|
|
539
571
|
};
|
|
572
|
+
|
|
573
|
+
// src/webtty.ts
|
|
574
|
+
var z6 = __toESM(require("zod"));
|
|
575
|
+
var osFamilies = [
|
|
576
|
+
"linux",
|
|
577
|
+
"macos",
|
|
578
|
+
"windows",
|
|
579
|
+
"netbsd",
|
|
580
|
+
"openbsd",
|
|
581
|
+
"freebsd"
|
|
582
|
+
];
|
|
583
|
+
var architectures = [
|
|
584
|
+
"x86_i386",
|
|
585
|
+
"x86_i686",
|
|
586
|
+
"x86_64",
|
|
587
|
+
"x86_64_v2",
|
|
588
|
+
"x86_64_v3",
|
|
589
|
+
"x86_64_v4",
|
|
590
|
+
"armv6",
|
|
591
|
+
"armv6hf",
|
|
592
|
+
"armv7",
|
|
593
|
+
"armv7hf",
|
|
594
|
+
"arm64",
|
|
595
|
+
"mips",
|
|
596
|
+
"mipsle",
|
|
597
|
+
"mips64",
|
|
598
|
+
"mips64le",
|
|
599
|
+
"ppc64",
|
|
600
|
+
"ppc64le",
|
|
601
|
+
"riscv64"
|
|
602
|
+
];
|
|
603
|
+
var webttyServerSchema = z6.object({
|
|
604
|
+
tunnel_id: z6.string(),
|
|
605
|
+
host: z6.string(),
|
|
606
|
+
token_auth: z6.boolean(),
|
|
607
|
+
os_family: z6.enum(osFamilies).optional(),
|
|
608
|
+
arch: z6.enum(architectures).optional(),
|
|
609
|
+
os_id: z6.string().optional(),
|
|
610
|
+
// /etc/os-release::ID (ubuntu, debian, rocky, etc.)
|
|
611
|
+
os_version_id: z6.string().optional(),
|
|
612
|
+
// /etc/os-release::VERSION_ID (24.04, 22.04, 11, 10.0.19045, ...)
|
|
613
|
+
os_version_codename: z6.string().optional(),
|
|
614
|
+
// /etc/os-release::VERSION_CODENAME (jammy, noble...)
|
|
615
|
+
os_pretty_name: z6.string().optional(),
|
|
616
|
+
// /etc/os-release::PRETTY_NAME
|
|
617
|
+
kernel_release: z6.string().optional(),
|
|
618
|
+
// uname -r
|
|
619
|
+
hostname: z6.string().optional(),
|
|
620
|
+
// uname -n
|
|
621
|
+
labels: z6.record(z6.string(), z6.string().optional()).optional()
|
|
622
|
+
});
|
|
623
|
+
function parser(tunnel) {
|
|
624
|
+
if (tunnel.status !== "online") return null;
|
|
625
|
+
if (tunnel.publish !== true) return null;
|
|
626
|
+
if (tunnel.protocol !== "http") return null;
|
|
627
|
+
const tunnelLabels = tunnel.labels ?? {};
|
|
628
|
+
if (tunnelLabels["application-protocol"] !== "rstream.webtty") {
|
|
629
|
+
return null;
|
|
630
|
+
}
|
|
631
|
+
const labels = {};
|
|
632
|
+
for (const [key, value] of Object.entries(tunnelLabels)) {
|
|
633
|
+
if (!key.startsWith("rstream.webtty.label.")) continue;
|
|
634
|
+
const labelKey = key.slice("rstream.webtty.label.".length);
|
|
635
|
+
if (labelKey.length === 0) continue;
|
|
636
|
+
labels[labelKey] = value;
|
|
637
|
+
}
|
|
638
|
+
const candidate = {
|
|
639
|
+
tunnel_id: tunnel.id,
|
|
640
|
+
host: tunnel.host,
|
|
641
|
+
token_auth: tunnel.token_auth === true,
|
|
642
|
+
os_family: tunnelLabels["rstream.webtty.os_family"],
|
|
643
|
+
arch: tunnelLabels["rstream.webtty.arch"],
|
|
644
|
+
os_id: tunnelLabels["rstream.webtty.os_id"],
|
|
645
|
+
os_version_id: tunnelLabels["rstream.webtty.os_version_id"],
|
|
646
|
+
os_version_codename: tunnelLabels["rstream.webtty.os_version_codename"],
|
|
647
|
+
os_pretty_name: tunnelLabels["rstream.webtty.os_pretty_name"],
|
|
648
|
+
kernel_release: tunnelLabels["rstream.webtty.kernel_release"],
|
|
649
|
+
hostname: tunnelLabels["rstream.webtty.hostname"],
|
|
650
|
+
labels: Object.keys(labels).length > 0 ? labels : void 0
|
|
651
|
+
};
|
|
652
|
+
const parsed = webttyServerSchema.safeParse(candidate);
|
|
653
|
+
if (!parsed.success) return null;
|
|
654
|
+
return parsed.data;
|
|
655
|
+
}
|
|
656
|
+
function parseWebTTYServers(tunnels) {
|
|
657
|
+
return tunnels.map((tunnel) => parser(tunnel)).filter((server) => server !== null);
|
|
658
|
+
}
|
|
540
659
|
// Annotate the CommonJS export names for ESM import in node:
|
|
541
660
|
0 && (module.exports = {
|
|
542
661
|
Rstream,
|
|
@@ -546,14 +665,19 @@ var Watch = class {
|
|
|
546
665
|
RstreamTunnelsRessource,
|
|
547
666
|
RstreamWebHooksRessource,
|
|
548
667
|
Watch,
|
|
668
|
+
authTokenPermissionsSchema,
|
|
669
|
+
authTokenSchema,
|
|
670
|
+
authTokenScopesSchema,
|
|
671
|
+
authTokenTunnelsScopesSchema,
|
|
549
672
|
clientSchema,
|
|
550
|
-
|
|
551
|
-
|
|
673
|
+
createAuthTokenParamsSchema,
|
|
674
|
+
createAuthTokenResponseSchema,
|
|
552
675
|
eventSchema,
|
|
553
676
|
listClientsParamsSchema,
|
|
554
677
|
listClientsResponseSchema,
|
|
555
678
|
listTunnelsParamsSchema,
|
|
556
679
|
listTunnelsResponseSchema,
|
|
557
|
-
|
|
558
|
-
tunnelSchema
|
|
680
|
+
parseWebTTYServers,
|
|
681
|
+
tunnelSchema,
|
|
682
|
+
webttyServerSchema
|
|
559
683
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -6,11 +6,11 @@ var RstreamAuthRessource = class {
|
|
|
6
6
|
constructor(client) {
|
|
7
7
|
this.client = client;
|
|
8
8
|
}
|
|
9
|
-
async
|
|
9
|
+
async createAuthToken(params, options) {
|
|
10
10
|
const credentials = options?.credentials || this.client.credentials;
|
|
11
11
|
if (!credentials || !("clientId" in credentials)) {
|
|
12
12
|
throw new Error(
|
|
13
|
-
"Application credentials (client id, client secret) are required to create
|
|
13
|
+
"Application credentials (client id, client secret) are required to create an auth token."
|
|
14
14
|
);
|
|
15
15
|
}
|
|
16
16
|
const now = Math.floor(Date.now() / 1e3);
|
|
@@ -22,9 +22,10 @@ var RstreamAuthRessource = class {
|
|
|
22
22
|
// Expiration time
|
|
23
23
|
type: "app",
|
|
24
24
|
clientId: credentials.clientId,
|
|
25
|
+
permissions: null,
|
|
25
26
|
metadata: {
|
|
26
27
|
engine: this.client.engine,
|
|
27
|
-
|
|
28
|
+
scopes: params?.scopes
|
|
28
29
|
}
|
|
29
30
|
};
|
|
30
31
|
const pk = crypto.createPrivateKey({
|
|
@@ -132,60 +133,79 @@ var listTunnelsResponseSchema = z2.array(tunnelSchema);
|
|
|
132
133
|
|
|
133
134
|
// src/auth.ts
|
|
134
135
|
import * as z3 from "zod";
|
|
135
|
-
var
|
|
136
|
-
|
|
137
|
-
//
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
136
|
+
var authTokenPermissionsSchema = z3.array(z3.string());
|
|
137
|
+
var authTokenTunnelsScopesSchema = z3.object({
|
|
138
|
+
// Scopes for creating tunnels
|
|
139
|
+
create: z3.union([
|
|
140
|
+
z3.boolean(),
|
|
141
|
+
z3.object({
|
|
142
|
+
filters: filters(
|
|
143
|
+
tunnelSchema.omit({
|
|
144
|
+
client_id: true,
|
|
145
|
+
user_id: true,
|
|
146
|
+
status: true,
|
|
147
|
+
creation_date: true
|
|
148
|
+
})
|
|
149
|
+
).optional()
|
|
150
|
+
})
|
|
151
|
+
]).optional(),
|
|
152
|
+
// Scopes for connecting to tunnels
|
|
153
|
+
connect: z3.union([
|
|
154
|
+
z3.boolean(),
|
|
155
|
+
z3.object({
|
|
156
|
+
filters: filters(tunnelSchema).optional(),
|
|
157
|
+
params: filters(
|
|
158
|
+
z3.object({
|
|
159
|
+
path: z3.string().optional()
|
|
160
|
+
})
|
|
161
|
+
).optional()
|
|
162
|
+
})
|
|
163
|
+
]).optional(),
|
|
164
|
+
// Scopes for listing tunnels
|
|
165
|
+
list: z3.union([
|
|
166
|
+
z3.boolean(),
|
|
167
|
+
z3.object({
|
|
168
|
+
filters: filters(tunnelSchema).optional(),
|
|
169
|
+
select: select(tunnelSchema).optional()
|
|
170
|
+
})
|
|
171
|
+
]).optional()
|
|
169
172
|
});
|
|
170
|
-
var
|
|
171
|
-
|
|
173
|
+
var authTokenScopesSchema = z3.object({
|
|
174
|
+
tunnels: authTokenTunnelsScopesSchema.optional()
|
|
175
|
+
// Scopes related to tunnels
|
|
172
176
|
});
|
|
173
|
-
var
|
|
177
|
+
var authTokenSchema = z3.union([
|
|
178
|
+
z3.object({
|
|
179
|
+
type: z3.literal("auth"),
|
|
180
|
+
userId: z3.string(),
|
|
181
|
+
permissions: authTokenPermissionsSchema.nullable()
|
|
182
|
+
}),
|
|
174
183
|
z3.object({
|
|
175
184
|
type: z3.literal("pat")
|
|
176
185
|
}),
|
|
177
186
|
z3.object({
|
|
178
187
|
type: z3.literal("app"),
|
|
179
|
-
clientId: z3.string()
|
|
188
|
+
clientId: z3.string(),
|
|
189
|
+
permissions: authTokenPermissionsSchema.nullable()
|
|
180
190
|
})
|
|
181
191
|
]).and(
|
|
182
192
|
z3.object({
|
|
183
193
|
metadata: z3.object({
|
|
184
194
|
engine: z3.string().optional(),
|
|
185
|
-
|
|
195
|
+
scopes: authTokenScopesSchema.optional()
|
|
186
196
|
}).optional()
|
|
187
197
|
})
|
|
188
198
|
);
|
|
199
|
+
var createAuthTokenParamsSchema = z3.object({
|
|
200
|
+
expires_in: z3.number().default(60),
|
|
201
|
+
// 1 minute
|
|
202
|
+
scopes: authTokenScopesSchema.optional(),
|
|
203
|
+
metadata: z3.unknown().optional()
|
|
204
|
+
// Additional metadata
|
|
205
|
+
});
|
|
206
|
+
var createAuthTokenResponseSchema = z3.object({
|
|
207
|
+
token: z3.string()
|
|
208
|
+
});
|
|
189
209
|
|
|
190
210
|
// src/client.ts
|
|
191
211
|
import * as z4 from "zod";
|
|
@@ -398,7 +418,7 @@ var RstreamClient = class {
|
|
|
398
418
|
return credentials.token;
|
|
399
419
|
}
|
|
400
420
|
if (credentials && "clientId" in credentials) {
|
|
401
|
-
return (await this.auth.
|
|
421
|
+
return (await this.auth.createAuthToken(void 0, {
|
|
402
422
|
credentials: {
|
|
403
423
|
clientId: credentials.clientId,
|
|
404
424
|
clientSecret: credentials.clientSecret
|
|
@@ -442,8 +462,8 @@ var Watch = class {
|
|
|
442
462
|
throw new Error("Watch: Connection already started or closed.");
|
|
443
463
|
}
|
|
444
464
|
this.connectionState = "connecting";
|
|
445
|
-
const token = await this.config.auth
|
|
446
|
-
const payload =
|
|
465
|
+
const token = typeof this.config.auth === "function" ? await this.config.auth() : this.config.auth;
|
|
466
|
+
const payload = authTokenSchema.parse(
|
|
447
467
|
jwt2.decode(token, { complete: false })
|
|
448
468
|
);
|
|
449
469
|
const base = `https://${this.config.engine || payload.metadata?.engine || "engine.rstream.io:443"}`;
|
|
@@ -470,6 +490,13 @@ var Watch = class {
|
|
|
470
490
|
this.disconnect();
|
|
471
491
|
}
|
|
472
492
|
};
|
|
493
|
+
if (this.connection instanceof WebSocket) {
|
|
494
|
+
this.connection.onclose = () => {
|
|
495
|
+
if (this.connectionState !== "closed") {
|
|
496
|
+
this.disconnect();
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
}
|
|
473
500
|
}
|
|
474
501
|
disconnect() {
|
|
475
502
|
if (this.connection) {
|
|
@@ -485,6 +512,93 @@ var Watch = class {
|
|
|
485
512
|
}
|
|
486
513
|
}
|
|
487
514
|
};
|
|
515
|
+
|
|
516
|
+
// src/webtty.ts
|
|
517
|
+
import * as z6 from "zod";
|
|
518
|
+
var osFamilies = [
|
|
519
|
+
"linux",
|
|
520
|
+
"macos",
|
|
521
|
+
"windows",
|
|
522
|
+
"netbsd",
|
|
523
|
+
"openbsd",
|
|
524
|
+
"freebsd"
|
|
525
|
+
];
|
|
526
|
+
var architectures = [
|
|
527
|
+
"x86_i386",
|
|
528
|
+
"x86_i686",
|
|
529
|
+
"x86_64",
|
|
530
|
+
"x86_64_v2",
|
|
531
|
+
"x86_64_v3",
|
|
532
|
+
"x86_64_v4",
|
|
533
|
+
"armv6",
|
|
534
|
+
"armv6hf",
|
|
535
|
+
"armv7",
|
|
536
|
+
"armv7hf",
|
|
537
|
+
"arm64",
|
|
538
|
+
"mips",
|
|
539
|
+
"mipsle",
|
|
540
|
+
"mips64",
|
|
541
|
+
"mips64le",
|
|
542
|
+
"ppc64",
|
|
543
|
+
"ppc64le",
|
|
544
|
+
"riscv64"
|
|
545
|
+
];
|
|
546
|
+
var webttyServerSchema = z6.object({
|
|
547
|
+
tunnel_id: z6.string(),
|
|
548
|
+
host: z6.string(),
|
|
549
|
+
token_auth: z6.boolean(),
|
|
550
|
+
os_family: z6.enum(osFamilies).optional(),
|
|
551
|
+
arch: z6.enum(architectures).optional(),
|
|
552
|
+
os_id: z6.string().optional(),
|
|
553
|
+
// /etc/os-release::ID (ubuntu, debian, rocky, etc.)
|
|
554
|
+
os_version_id: z6.string().optional(),
|
|
555
|
+
// /etc/os-release::VERSION_ID (24.04, 22.04, 11, 10.0.19045, ...)
|
|
556
|
+
os_version_codename: z6.string().optional(),
|
|
557
|
+
// /etc/os-release::VERSION_CODENAME (jammy, noble...)
|
|
558
|
+
os_pretty_name: z6.string().optional(),
|
|
559
|
+
// /etc/os-release::PRETTY_NAME
|
|
560
|
+
kernel_release: z6.string().optional(),
|
|
561
|
+
// uname -r
|
|
562
|
+
hostname: z6.string().optional(),
|
|
563
|
+
// uname -n
|
|
564
|
+
labels: z6.record(z6.string(), z6.string().optional()).optional()
|
|
565
|
+
});
|
|
566
|
+
function parser(tunnel) {
|
|
567
|
+
if (tunnel.status !== "online") return null;
|
|
568
|
+
if (tunnel.publish !== true) return null;
|
|
569
|
+
if (tunnel.protocol !== "http") return null;
|
|
570
|
+
const tunnelLabels = tunnel.labels ?? {};
|
|
571
|
+
if (tunnelLabels["application-protocol"] !== "rstream.webtty") {
|
|
572
|
+
return null;
|
|
573
|
+
}
|
|
574
|
+
const labels = {};
|
|
575
|
+
for (const [key, value] of Object.entries(tunnelLabels)) {
|
|
576
|
+
if (!key.startsWith("rstream.webtty.label.")) continue;
|
|
577
|
+
const labelKey = key.slice("rstream.webtty.label.".length);
|
|
578
|
+
if (labelKey.length === 0) continue;
|
|
579
|
+
labels[labelKey] = value;
|
|
580
|
+
}
|
|
581
|
+
const candidate = {
|
|
582
|
+
tunnel_id: tunnel.id,
|
|
583
|
+
host: tunnel.host,
|
|
584
|
+
token_auth: tunnel.token_auth === true,
|
|
585
|
+
os_family: tunnelLabels["rstream.webtty.os_family"],
|
|
586
|
+
arch: tunnelLabels["rstream.webtty.arch"],
|
|
587
|
+
os_id: tunnelLabels["rstream.webtty.os_id"],
|
|
588
|
+
os_version_id: tunnelLabels["rstream.webtty.os_version_id"],
|
|
589
|
+
os_version_codename: tunnelLabels["rstream.webtty.os_version_codename"],
|
|
590
|
+
os_pretty_name: tunnelLabels["rstream.webtty.os_pretty_name"],
|
|
591
|
+
kernel_release: tunnelLabels["rstream.webtty.kernel_release"],
|
|
592
|
+
hostname: tunnelLabels["rstream.webtty.hostname"],
|
|
593
|
+
labels: Object.keys(labels).length > 0 ? labels : void 0
|
|
594
|
+
};
|
|
595
|
+
const parsed = webttyServerSchema.safeParse(candidate);
|
|
596
|
+
if (!parsed.success) return null;
|
|
597
|
+
return parsed.data;
|
|
598
|
+
}
|
|
599
|
+
function parseWebTTYServers(tunnels) {
|
|
600
|
+
return tunnels.map((tunnel) => parser(tunnel)).filter((server) => server !== null);
|
|
601
|
+
}
|
|
488
602
|
export {
|
|
489
603
|
RstreamClient as Rstream,
|
|
490
604
|
RstreamAuthRessource,
|
|
@@ -493,14 +607,19 @@ export {
|
|
|
493
607
|
RstreamTunnelsRessource,
|
|
494
608
|
RstreamWebHooksRessource,
|
|
495
609
|
Watch,
|
|
610
|
+
authTokenPermissionsSchema,
|
|
611
|
+
authTokenSchema,
|
|
612
|
+
authTokenScopesSchema,
|
|
613
|
+
authTokenTunnelsScopesSchema,
|
|
496
614
|
clientSchema,
|
|
497
|
-
|
|
498
|
-
|
|
615
|
+
createAuthTokenParamsSchema,
|
|
616
|
+
createAuthTokenResponseSchema,
|
|
499
617
|
eventSchema,
|
|
500
618
|
listClientsParamsSchema,
|
|
501
619
|
listClientsResponseSchema,
|
|
502
620
|
listTunnelsParamsSchema,
|
|
503
621
|
listTunnelsResponseSchema,
|
|
504
|
-
|
|
505
|
-
tunnelSchema
|
|
622
|
+
parseWebTTYServers,
|
|
623
|
+
tunnelSchema,
|
|
624
|
+
webttyServerSchema
|
|
506
625
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rstreamlabs/rstream",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "JS SDK for rstream.",
|
|
5
5
|
"author": "@uartnet <hello@rstream.io>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
"type-check": "tsc --noEmit"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@turbo/gen": "^2.
|
|
22
|
+
"@turbo/gen": "^2.6.1",
|
|
23
23
|
"@types/jsonwebtoken": "^9.0.10",
|
|
24
24
|
"@types/node": "^24",
|
|
25
25
|
"eslint-config": "*",
|
|
26
|
-
"eslint": "9.
|
|
27
|
-
"tsup": "^8.5.
|
|
26
|
+
"eslint": "9.39.1",
|
|
27
|
+
"tsup": "^8.5.1",
|
|
28
28
|
"typescript-config": "*",
|
|
29
|
-
"typescript": "5.9.
|
|
29
|
+
"typescript": "5.9.3"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"jsonwebtoken": "^9.0.2",
|