@claxedo/workspace-relay-protocol 0.1.0 → 0.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/README.md +78 -0
- package/dist/index.d.ts +23 -2
- package/dist/index.mjs +1558 -5
- package/dist/token-verifier.d.ts +52 -10
- package/package.json +19 -6
package/dist/token-verifier.d.ts
CHANGED
|
@@ -12,18 +12,52 @@
|
|
|
12
12
|
*
|
|
13
13
|
* See the boundary READMEs for wiring rules.
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
import { type JWTPayload } from "jose";
|
|
16
|
+
export type TokenVerifierBaseClaims = {
|
|
17
|
+
iss: string;
|
|
18
|
+
aud: string;
|
|
19
|
+
sub: string;
|
|
20
|
+
workspace_id: string;
|
|
21
|
+
host_id: string;
|
|
22
|
+
exp: number;
|
|
23
|
+
iat: number;
|
|
24
|
+
jti: string;
|
|
25
|
+
} & Record<string, unknown>;
|
|
26
|
+
export type RuntimeAccessVerifierClaims = TokenVerifierBaseClaims & {
|
|
27
|
+
org_id: string;
|
|
28
|
+
role: "viewer" | "editor" | "admin" | "owner";
|
|
29
|
+
};
|
|
30
|
+
export type RelayHostVerifierClaims = TokenVerifierBaseClaims & {
|
|
31
|
+
org_id: string;
|
|
32
|
+
} & ({
|
|
33
|
+
access: "cloud";
|
|
34
|
+
backing: "cloud-vm";
|
|
35
|
+
} | {
|
|
36
|
+
access: "user-hosted";
|
|
37
|
+
backing: "local-worktree";
|
|
38
|
+
});
|
|
39
|
+
export type TokenClaims<TClaims extends Record<string, unknown> = Record<string, unknown>> = {
|
|
16
40
|
/** Stable subject id. The boundary is responsible for mapping this
|
|
17
41
|
* to a domain principal (user, workspace, runtime, etc.). */
|
|
18
42
|
subject: string;
|
|
19
43
|
/** Scopes / capabilities asserted by the issuer. May be empty. */
|
|
20
44
|
scopes: string[];
|
|
21
|
-
/** Full claim payload. Carries
|
|
45
|
+
/** Full claim payload. Carries the common verifier token contract plus
|
|
22
46
|
* boundary-specific custom claims. */
|
|
23
|
-
claims:
|
|
47
|
+
claims: TClaims;
|
|
48
|
+
};
|
|
49
|
+
export type TokenVerifier<TClaims extends Record<string, unknown> = Record<string, unknown>> = {
|
|
50
|
+
verify(token: string): Promise<TokenClaims<TClaims>>;
|
|
24
51
|
};
|
|
25
|
-
export type
|
|
26
|
-
|
|
52
|
+
export type ClerkTokenVerifierClaims = JWTPayload & {
|
|
53
|
+
iss: string;
|
|
54
|
+
sub: string;
|
|
55
|
+
exp: number;
|
|
56
|
+
iat?: number;
|
|
57
|
+
jti?: string;
|
|
58
|
+
sid?: string;
|
|
59
|
+
org_id?: string;
|
|
60
|
+
orgId?: string;
|
|
27
61
|
};
|
|
28
62
|
export declare class TokenVerifierError extends Error {
|
|
29
63
|
readonly code: string;
|
|
@@ -37,7 +71,7 @@ export declare class TokenVerifierError extends Error {
|
|
|
37
71
|
}
|
|
38
72
|
export type HttpTokenVerifierOptions = {
|
|
39
73
|
/** Verifier endpoint. Must accept POST with `{ token }` JSON body
|
|
40
|
-
* and return `{ subject: string; scopes?: string[]; claims
|
|
74
|
+
* and return `{ subject: string; scopes?: string[]; claims: TokenVerifierBaseClaims }`
|
|
41
75
|
* on success, or HTTP non-2xx on failure. */
|
|
42
76
|
endpoint: string;
|
|
43
77
|
/** Optional fixed headers (e.g., bearer auth on the verifier itself). */
|
|
@@ -47,9 +81,17 @@ export type HttpTokenVerifierOptions = {
|
|
|
47
81
|
/** Request timeout in ms. Default 5000. */
|
|
48
82
|
timeoutMs?: number;
|
|
49
83
|
};
|
|
50
|
-
export declare function createHttpTokenVerifier(options: HttpTokenVerifierOptions): TokenVerifier
|
|
51
|
-
export type
|
|
84
|
+
export declare function createHttpTokenVerifier(options: HttpTokenVerifierOptions): TokenVerifier<TokenVerifierBaseClaims>;
|
|
85
|
+
export type ClerkTokenVerifierOptions = {
|
|
86
|
+
issuer: string;
|
|
87
|
+
jwksUrl: string;
|
|
88
|
+
audience?: string;
|
|
89
|
+
scopes?: string[];
|
|
90
|
+
algorithms?: Array<"ES256" | "EdDSA" | "RS256">;
|
|
91
|
+
};
|
|
92
|
+
export declare function createClerkTokenVerifier(options: ClerkTokenVerifierOptions): TokenVerifier<ClerkTokenVerifierClaims>;
|
|
93
|
+
export type StaticTokenVerifierOptions<TClaims extends Record<string, unknown> = Record<string, unknown>> = {
|
|
52
94
|
/** Map of token string → claims to return. */
|
|
53
|
-
tokens: Record<string, TokenClaims
|
|
95
|
+
tokens: Record<string, TokenClaims<TClaims>>;
|
|
54
96
|
};
|
|
55
|
-
export declare function createStaticTokenVerifier(options: StaticTokenVerifierOptions): TokenVerifier
|
|
97
|
+
export declare function createStaticTokenVerifier<TClaims extends Record<string, unknown> = Record<string, unknown>>(options: StaticTokenVerifierOptions<TClaims>): TokenVerifier<TClaims>;
|
package/package.json
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@claxedo/workspace-relay-protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"bun": "./dist/index.mjs",
|
|
11
|
+
"development": "./dist/index.mjs",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"default": "./dist/index.mjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
7
16
|
"files": [
|
|
17
|
+
"README.md",
|
|
8
18
|
"dist"
|
|
9
19
|
],
|
|
10
20
|
"publishConfig": {
|
|
11
21
|
"access": "public"
|
|
12
22
|
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"jose": "6.0.11"
|
|
25
|
+
},
|
|
13
26
|
"scripts": {
|
|
14
27
|
"build": "tsx scripts/build.ts",
|
|
15
28
|
"prepublishOnly": "npm run build",
|
|
@@ -17,10 +30,10 @@
|
|
|
17
30
|
"test": "bun test src"
|
|
18
31
|
},
|
|
19
32
|
"devDependencies": {
|
|
20
|
-
"@tsconfig/node-lts": "
|
|
21
|
-
"@types/bun": "
|
|
22
|
-
"esbuild": "
|
|
23
|
-
"tsx": "
|
|
24
|
-
"typescript": "
|
|
33
|
+
"@tsconfig/node-lts": "22.0.4",
|
|
34
|
+
"@types/bun": "1.3.13",
|
|
35
|
+
"esbuild": "0.25.12",
|
|
36
|
+
"tsx": "4.22.3",
|
|
37
|
+
"typescript": "5.8.2"
|
|
25
38
|
}
|
|
26
39
|
}
|