@claxedo/workspace-relay-protocol 0.5.0 → 0.5.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/LICENSE +21 -0
- package/README.md +48 -2
- package/dist/index.d.ts +8 -1
- package/dist/index.mjs +16 -1389
- package/dist/token-verifier.d.ts +1 -0
- package/package.json +16 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Claxedo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -5,15 +5,61 @@ traffic. This package intentionally has no Hono, Bun, or server dependency so
|
|
|
5
5
|
workspace hosts and non-Node clients can validate tunnel frames without pulling
|
|
6
6
|
in the relay implementation.
|
|
7
7
|
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm install @claxedo/workspace-relay-protocol
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Quickstart
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { createStaticTokenVerifier, isTunnelMessage, validateTunnelMessage } from "@claxedo/workspace-relay-protocol"
|
|
18
|
+
|
|
19
|
+
// Validate an inbound tunnel frame before acting on it.
|
|
20
|
+
const result = validateTunnelMessage(JSON.parse(rawFrame))
|
|
21
|
+
if (!result.ok) {
|
|
22
|
+
throw new Error(`invalid tunnel frame: ${result.reason}`)
|
|
23
|
+
}
|
|
24
|
+
// result.message is a narrowed TunnelMessage here.
|
|
25
|
+
|
|
26
|
+
// Or use the boolean type guard when you just need a filter.
|
|
27
|
+
const frames = incoming.filter(isTunnelMessage)
|
|
28
|
+
|
|
29
|
+
// A fixed token table for tests and single-tenant self-hosted deployments.
|
|
30
|
+
const verifier = createStaticTokenVerifier({
|
|
31
|
+
tokens: {
|
|
32
|
+
"test-token": {
|
|
33
|
+
subject: "workspace-abc",
|
|
34
|
+
scopes: ["relay:connect"],
|
|
35
|
+
claims: {
|
|
36
|
+
iss: "claxedo-test",
|
|
37
|
+
aud: "workspace-relay",
|
|
38
|
+
sub: "workspace-abc",
|
|
39
|
+
workspace_id: "workspace-abc",
|
|
40
|
+
host_id: "host-1",
|
|
41
|
+
exp: Math.floor(Date.now() / 1000) + 3600,
|
|
42
|
+
iat: Math.floor(Date.now() / 1000),
|
|
43
|
+
jti: "jti-1",
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
const claims = await verifier.verify("test-token")
|
|
49
|
+
```
|
|
50
|
+
|
|
8
51
|
## Public Surface
|
|
9
52
|
|
|
10
53
|
| Export | Stability | Purpose |
|
|
11
54
|
| --- | --- | --- |
|
|
12
55
|
| `TUNNEL_PROTOCOL_VERSION` | Stable | Current tunnel protocol version. |
|
|
13
|
-
| `TunnelMessage` and message subtypes | Stable | Discriminated union for HTTP, WebSocket, heartbeat, flow-control, and error frames. |
|
|
56
|
+
| `TunnelMessage` and message subtypes | Stable | Discriminated union for HTTP, WebSocket, heartbeat, host-registration, flow-control, and error frames. |
|
|
57
|
+
| `TunnelHostRegistrationUpdate` / `"host.registration.update"` | Stable | Frame a host sends to update the set of workspace IDs it serves and its auth token. |
|
|
14
58
|
| `validateTunnelMessage`, `isTunnelMessage` | Stable | Runtime validation for protocol, message type, and per-message payload shape. |
|
|
15
|
-
| `
|
|
59
|
+
| `TunnelMessageValidation` | Stable | Result type returned by `validateTunnelMessage` — `{ ok: true, message }` or a typed failure (`protocol_mismatch` / `invalid`). |
|
|
60
|
+
| `makeTunnelPing`, `makeTunnelPong` | Stable | Helpers for heartbeat requests and replies. |
|
|
16
61
|
| `TokenVerifier` and claim types | Stable | Narrow verifier interface shared by relay/runtime boundaries. |
|
|
62
|
+
| `RelayHostVerifierClaims` (incl. `role`) | Stable | Claims shape for host-side verification: org, `role` (`viewer` \| `editor` \| `admin` \| `owner`), and cloud/user-hosted backing discriminant. |
|
|
17
63
|
| `createClerkTokenVerifier` | Public beta | Verifies Clerk session tokens with issuer, audience, JWKS, and algorithm constraints. |
|
|
18
64
|
| `createHttpTokenVerifier` | Public beta | Calls an operator-controlled verifier endpoint over HTTP. |
|
|
19
65
|
| `createStaticTokenVerifier` | Test/single-tenant only | Fixed token table for tests and isolated self-hosted deployments. |
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,12 @@ export type TunnelPong = {
|
|
|
14
14
|
sent_at: number;
|
|
15
15
|
received_at: number;
|
|
16
16
|
};
|
|
17
|
+
export type TunnelHostRegistrationUpdate = {
|
|
18
|
+
type: "host.registration.update";
|
|
19
|
+
protocol: typeof TUNNEL_PROTOCOL_VERSION;
|
|
20
|
+
workspace_ids: string[];
|
|
21
|
+
token: string;
|
|
22
|
+
};
|
|
17
23
|
export type TunnelHttpRequest = {
|
|
18
24
|
type: "http.request";
|
|
19
25
|
protocol: typeof TUNNEL_PROTOCOL_VERSION;
|
|
@@ -80,7 +86,7 @@ export type TunnelError = {
|
|
|
80
86
|
code: string;
|
|
81
87
|
message: string;
|
|
82
88
|
};
|
|
83
|
-
export type TunnelMessage = TunnelPing | TunnelPong | TunnelHttpRequest | TunnelHttpResponseStart | TunnelHttpResponseChunk | TunnelHttpResponseEnd | TunnelHttpResponseFlow | TunnelWsOpen | TunnelWsFrame | TunnelWsClose | TunnelError;
|
|
89
|
+
export type TunnelMessage = TunnelPing | TunnelPong | TunnelHostRegistrationUpdate | TunnelHttpRequest | TunnelHttpResponseStart | TunnelHttpResponseChunk | TunnelHttpResponseEnd | TunnelHttpResponseFlow | TunnelWsOpen | TunnelWsFrame | TunnelWsClose | TunnelError;
|
|
84
90
|
export type TunnelMessageValidation = {
|
|
85
91
|
ok: true;
|
|
86
92
|
message: TunnelMessage;
|
|
@@ -97,3 +103,4 @@ export type TunnelMessageValidation = {
|
|
|
97
103
|
export declare function validateTunnelMessage(input: unknown): TunnelMessageValidation;
|
|
98
104
|
export declare function isTunnelMessage(input: unknown): input is TunnelMessage;
|
|
99
105
|
export declare function makeTunnelPong(input: TunnelPing, receivedAt?: number): TunnelPong;
|
|
106
|
+
export declare function makeTunnelPing(sentAt?: number, id?: string): TunnelPing;
|