@rstreamlabs/tunnels 1.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/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # `@rstreamlabs/tunnels`
2
+
3
+ Data-plane JS/TS SDK for rstream tunnels.
4
+
5
+ Use this package to talk directly to the tunnels engine: list tunnels, inspect
6
+ clients, watch engine events, validate webhooks, and create fine-grained app
7
+ tokens.
8
+
9
+ The package supports both:
10
+
11
+ - direct engine usage, including self-hosted deployments
12
+ - managed rstream projects resolved via the control plane
13
+ - bearer-token authentication and application credentials
14
+
15
+ ## Self-hosted usage
16
+
17
+ ```ts
18
+ import { RstreamTunnelsClient } from "@rstreamlabs/tunnels";
19
+
20
+ const client = new RstreamTunnelsClient({
21
+ credentials: { token: process.env.RSTREAM_AUTHENTICATION_TOKEN! },
22
+ engine: process.env.RSTREAM_ENGINE!,
23
+ });
24
+
25
+ const tunnels = await client.tunnels.list();
26
+ ```
27
+
28
+ ## Managed usage
29
+
30
+ ```ts
31
+ import { RstreamTunnelsClient } from "@rstreamlabs/tunnels";
32
+
33
+ const client = new RstreamTunnelsClient({
34
+ credentials: { token: process.env.RSTREAM_AUTHENTICATION_TOKEN! },
35
+ projectEndpoint: "project-endpoint",
36
+ });
37
+
38
+ const engine = await client.getEngine();
39
+ const turn = await client.turn.createCredentials();
40
+ ```
41
+
42
+ ## Application Credentials
43
+
44
+ `@rstreamlabs/tunnels` can work directly with an app `clientId` and
45
+ `clientSecret`. This is the intended backend flow when you want the server to
46
+ mint short-lived tokens for downstream clients.
47
+
48
+ ```ts
49
+ import { RstreamTunnelsClient } from "@rstreamlabs/tunnels";
50
+
51
+ const client = new RstreamTunnelsClient({
52
+ credentials: {
53
+ clientId: process.env.RSTREAM_CLIENT_ID!,
54
+ clientSecret: process.env.RSTREAM_CLIENT_SECRET!,
55
+ },
56
+ projectEndpoint: "project-endpoint",
57
+ });
58
+
59
+ const { token } = await client.auth.createAuthToken({ expires_in: 60 });
60
+ ```
61
+
62
+ ## Fine-Grained Tokens
63
+
64
+ ```ts
65
+ import { RstreamTunnelsClient } from "@rstreamlabs/tunnels";
66
+
67
+ const admin = new RstreamTunnelsClient({
68
+ credentials: {
69
+ clientId: process.env.RSTREAM_CLIENT_ID!,
70
+ clientSecret: process.env.RSTREAM_CLIENT_SECRET!,
71
+ },
72
+ projectEndpoint: "project-endpoint",
73
+ });
74
+
75
+ const { token } = await admin.auth.createAuthToken({
76
+ expires_in: 60,
77
+ scopes: {
78
+ tunnels: {
79
+ create: { filters: { protocol: { oneof: ["http"] } } },
80
+ connect: { params: { path: { regex: "^/api" } } },
81
+ list: { select: { id: true, name: true, protocol: true } },
82
+ },
83
+ },
84
+ });
85
+ ```
86
+
87
+ ## TURN credentials
88
+
89
+ `@rstreamlabs/tunnels` supports the same three TURN credential paths as the
90
+ platform:
91
+
92
+ - managed API issuance with a short-lived auth token
93
+ - local derivation from a PAT
94
+ - local derivation from an app `clientId` and `clientSecret`
95
+
96
+ ```ts
97
+ import { createTURNCredentials } from "@rstreamlabs/tunnels";
98
+
99
+ const turn = await createTURNCredentials({
100
+ credentials: { token: process.env.RSTREAM_AUTHENTICATION_TOKEN! },
101
+ projectEndpoint: "project-endpoint",
102
+ });
103
+ ```
104
+
105
+ `@rstreamlabs/tunnels` reads `RSTREAM_API_URL`, `RSTREAM_ENGINE`, and
106
+ `RSTREAM_AUTHENTICATION_TOKEN` when they are not provided explicitly.
107
+
108
+ For managed control-plane APIs, use [`@rstreamlabs/rstream`](../rstream/README.md).