@voltro/protocol 0.81.0 → 0.82.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/CHANGELOG.md +1520 -6
- package/dist/apikey.d.ts +2 -2
- package/dist/index.d.ts +607 -65
- package/dist/index.js +881 -644
- package/dist/inspect.d.ts +67 -1
- package/dist/inspect.js +95 -61
- package/dist/jwt.d.ts +1 -1
- package/dist/rest.d.ts +40 -3
- package/dist/rest.js +191 -159
- package/dist/{restFormat-CzdGVkuB.js → restFormat-EZ8k9ZcQ.js} +38 -33
- package/dist/{scopes-CvU5QBQ4.js → scopes-Di756ENh.js} +126 -106
- package/dist/session.d.ts +11 -0
- package/dist/session.js +53 -52
- package/dist/sessionHeader-DriTZhmv.js +7 -0
- package/package.json +3 -3
package/dist/session.js
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { j as e, nt as t, z as n } from "./scopes-Di756ENh.js";
|
|
2
|
+
import { n as r, t as i } from "./sessionHeader-DriTZhmv.js";
|
|
3
|
+
import { Schema as a } from "effect";
|
|
4
|
+
import { createHmac as o, timingSafeEqual as s } from "node:crypto";
|
|
5
|
+
import { createLogger as c } from "@voltro/logger";
|
|
5
6
|
//#region src/session.ts
|
|
6
|
-
var
|
|
7
|
-
v:
|
|
8
|
-
subject:
|
|
9
|
-
exp:
|
|
10
|
-
iat:
|
|
11
|
-
kid:
|
|
12
|
-
}),
|
|
7
|
+
var l = c({ scope: "@voltro/protocol:session" }), u = 2, d = a.Struct({
|
|
8
|
+
v: a.Literal(2),
|
|
9
|
+
subject: n,
|
|
10
|
+
exp: a.Number,
|
|
11
|
+
iat: a.Number,
|
|
12
|
+
kid: a.optional(a.String)
|
|
13
|
+
}), f = "k0", p = "k-previous", m = () => {
|
|
13
14
|
throw Error("VOLTRO_SESSION_SECRET is not set. It signs and verifies session cookies, and the framework refuses to invent one at this point: a fixed fallback would be readable by anyone with the source, making every session forgeable. `voltro dev` mints a project-local value into .env.local on boot; for a deployment, generate one with `voltro secret generate session`.");
|
|
14
|
-
},
|
|
15
|
-
kid:
|
|
16
|
-
secret:
|
|
17
|
-
} },
|
|
15
|
+
}, h = () => process.env.VOLTRO_SESSION_SECRET ?? m(), g = () => v() ?? { current: {
|
|
16
|
+
kid: _(),
|
|
17
|
+
secret: h()
|
|
18
|
+
} }, _ = () => process.env.VOLTRO_SESSION_KID ?? "k0", v = () => {
|
|
18
19
|
let e = process.env.VOLTRO_SESSION_SECRET;
|
|
19
20
|
if (e === void 0 || e === "") return;
|
|
20
21
|
let t = {
|
|
21
|
-
kid:
|
|
22
|
+
kid: _(),
|
|
22
23
|
secret: e
|
|
23
24
|
}, n = process.env.VOLTRO_SESSION_SECRET_PREVIOUS;
|
|
24
25
|
return n ? {
|
|
@@ -28,54 +29,54 @@ var s = o({ scope: "@voltro/protocol:session" }), c = 2, l = r.Struct({
|
|
|
28
29
|
secret: n
|
|
29
30
|
}
|
|
30
31
|
} : { current: t };
|
|
31
|
-
},
|
|
32
|
+
}, y = 32, b = (e = process.env) => {
|
|
32
33
|
let t = e.VOLTRO_SESSION_SECRET;
|
|
33
34
|
if (t === void 0 || t === "") throw Error("VOLTRO_SESSION_SECRET is not set — refusing to serve. It signs session cookies, and there is no fallback: a built-in one would be readable by anyone with the source. Generate one with `voltro secret generate session`. (`voltro dev` mints a project-local value automatically; a deployment needs its own.)");
|
|
34
35
|
if (t.length < 32) throw Error(`VOLTRO_SESSION_SECRET is only ${t.length} chars — too short for a session secret (need >= 32). This looks like a placeholder. Generate a real one with \`voltro secret generate session\`.`);
|
|
35
|
-
},
|
|
36
|
+
}, x = a.encodeSync(d), S = a.decodeUnknownSync(d), C = (e) => (typeof e == "string" ? Buffer.from(e, "utf8") : e).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""), w = (e) => {
|
|
36
37
|
let t = e.replace(/-/g, "+").replace(/_/g, "/") + "=".repeat((4 - e.length % 4) % 4);
|
|
37
38
|
return Buffer.from(t, "base64");
|
|
38
|
-
},
|
|
39
|
+
}, T = 604800, E = .7, D = (e, t) => C(o("sha256", t).update(e).digest()), O = (e) => typeof e == "string" ? {
|
|
39
40
|
kid: "k0",
|
|
40
41
|
secret: e
|
|
41
|
-
} : e,
|
|
42
|
-
let a =
|
|
42
|
+
} : e, k = (n, r, i = {}) => {
|
|
43
|
+
let a = O(r);
|
|
43
44
|
if (!a.secret) throw Error("signSession: secret must be a non-empty string");
|
|
44
|
-
let o = n
|
|
45
|
-
if (o.length > 0) throw Error(`signSession: refusing to mint a session cookie for a ${
|
|
46
|
-
let s = i.ttlSeconds ??
|
|
45
|
+
let o = e(n);
|
|
46
|
+
if (o.length > 0) throw Error(`signSession: refusing to mint a session cookie for a ${n.type} subject carrying ${o.length} scope(s) (${o.slice(0, 5).join(", ")}). A session cookie carries IDENTITY only — authority is resolved per request, so that removing a role takes effect on the session that already exists instead of in up to 7 days. Mint the session from the identity and move the scopes into the auth.resolveScopes resolver, which runs on every request and can be invalidated the moment a role changes.`);
|
|
47
|
+
let s = i.ttlSeconds ?? T, c = Math.floor((i.now ?? Date.now)() / 1e3), l = {
|
|
47
48
|
v: 2,
|
|
48
|
-
subject: t(
|
|
49
|
+
subject: t(n),
|
|
49
50
|
exp: c + s,
|
|
50
51
|
iat: c,
|
|
51
52
|
...typeof r == "string" ? {} : { kid: a.kid }
|
|
52
|
-
}, u =
|
|
53
|
-
return `${u}.${
|
|
54
|
-
},
|
|
55
|
-
let
|
|
56
|
-
if (
|
|
53
|
+
}, u = C(JSON.stringify(x(l)));
|
|
54
|
+
return `${u}.${D(u, a.secret)}`;
|
|
55
|
+
}, A = (e, t, n, r) => {
|
|
56
|
+
let i = o("sha256", n).update(e).digest(), a = w(t);
|
|
57
|
+
if (a.length !== i.length || !s(a, i)) return null;
|
|
57
58
|
try {
|
|
58
|
-
let t =
|
|
59
|
+
let t = w(e).toString("utf8"), n = S(JSON.parse(t));
|
|
59
60
|
return n.exp < Math.floor(r() / 1e3) ? null : n;
|
|
60
61
|
} catch {
|
|
61
62
|
return null;
|
|
62
63
|
}
|
|
63
|
-
},
|
|
64
|
+
}, j = (e, t) => {
|
|
64
65
|
if (!e || !t) return null;
|
|
65
66
|
let n = e.indexOf(".");
|
|
66
67
|
if (n <= 0 || n === e.length - 1) return null;
|
|
67
|
-
let r =
|
|
68
|
+
let r = A(e.slice(0, n), e.slice(n + 1), t, Date.now);
|
|
68
69
|
return r ? r.subject : null;
|
|
69
|
-
},
|
|
70
|
+
}, M = (e, t, n = {}) => {
|
|
70
71
|
if (!e) return null;
|
|
71
72
|
let r = e.indexOf(".");
|
|
72
73
|
if (r <= 0 || r === e.length - 1) return null;
|
|
73
74
|
let i = e.slice(0, r), a = e.slice(r + 1), o = t.previous ? [t.current, t.previous] : [t.current], s = n.now ?? Date.now;
|
|
74
75
|
for (let e of o) {
|
|
75
76
|
if (!e.secret) continue;
|
|
76
|
-
let t =
|
|
77
|
+
let t = A(i, a, e.secret, s);
|
|
77
78
|
if (!t) continue;
|
|
78
|
-
let r = n.renewFraction ??
|
|
79
|
+
let r = n.renewFraction ?? E, o = Math.floor(s() / 1e3), c = t.exp - t.iat, l = t.iat + c * r;
|
|
79
80
|
return {
|
|
80
81
|
subject: t.subject,
|
|
81
82
|
renew: o >= l,
|
|
@@ -85,14 +86,14 @@ var s = o({ scope: "@voltro/protocol:session" }), c = 2, l = r.Struct({
|
|
|
85
86
|
};
|
|
86
87
|
}
|
|
87
88
|
return null;
|
|
88
|
-
},
|
|
89
|
+
}, N = (e, t) => {
|
|
89
90
|
let n = Buffer.from(e, "utf8"), r = Buffer.from(t, "utf8");
|
|
90
|
-
return n.length === r.length &&
|
|
91
|
-
},
|
|
91
|
+
return n.length === r.length && s(n, r);
|
|
92
|
+
}, P = (e, t, n) => {
|
|
92
93
|
if (!t || t.length === 0) return n?.openWhenUnset === !0;
|
|
93
94
|
let r = e.authorization ?? e.Authorization;
|
|
94
|
-
return !r || !r.startsWith("Bearer ") ? !1 :
|
|
95
|
-
},
|
|
95
|
+
return !r || !r.startsWith("Bearer ") ? !1 : N(r.slice(7).trim(), t);
|
|
96
|
+
}, F = (e, t) => {
|
|
96
97
|
if (e) for (let n of e.split(";")) {
|
|
97
98
|
let e = n.indexOf("=");
|
|
98
99
|
if (e < 0 || n.slice(0, e).trim() !== t) continue;
|
|
@@ -104,26 +105,26 @@ var s = o({ scope: "@voltro/protocol:session" }), c = 2, l = r.Struct({
|
|
|
104
105
|
return r;
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
|
-
},
|
|
108
|
+
}, I = (e, t, n = {}) => {
|
|
108
109
|
let r = [`${e}=${encodeURIComponent(t)}`];
|
|
109
110
|
if (r.push(`Path=${n.path ?? "/"}`), n.maxAgeSeconds !== void 0 && r.push(`Max-Age=${n.maxAgeSeconds}`), r.push("HttpOnly"), n.httpOnly === !1) {
|
|
110
111
|
let e = r.indexOf("HttpOnly");
|
|
111
112
|
e >= 0 && r.splice(e, 1);
|
|
112
113
|
}
|
|
113
114
|
return r.push(`SameSite=${n.sameSite ?? "Lax"}`), (n.secure ?? !0) && r.push("Secure"), n.domain && r.push(`Domain=${n.domain}`), r.join("; ");
|
|
114
|
-
},
|
|
115
|
-
let t =
|
|
115
|
+
}, L = process.env.VOLTRO_SESSION_COOKIE ?? "voltro:session", R = (e, t = L) => r(e, t, F), z = (e) => {
|
|
116
|
+
let t = r(e, L, F);
|
|
116
117
|
if (!t) return;
|
|
117
|
-
let n =
|
|
118
|
+
let n = v();
|
|
118
119
|
if (!n) {
|
|
119
|
-
|
|
120
|
+
V();
|
|
120
121
|
return;
|
|
121
122
|
}
|
|
122
|
-
return
|
|
123
|
-
},
|
|
124
|
-
|
|
125
|
-
},
|
|
126
|
-
|
|
123
|
+
return M(t, n)?.exp;
|
|
124
|
+
}, B = !1, V = () => {
|
|
125
|
+
B || (B = !0, l.error("a `voltro:session` cookie was presented but VOLTRO_SESSION_SECRET is not set — the session cannot be verified, so no credential-expiry bound is imposed and realtime subscriptions on this connection will not be cut off when the session expires. Set VOLTRO_SESSION_SECRET (`voltro secret generate session`); `voltro dev` mints one, `voltro serve` refuses to boot without one.", { cookieName: L }));
|
|
126
|
+
}, H = () => {
|
|
127
|
+
B = !1;
|
|
127
128
|
};
|
|
128
129
|
//#endregion
|
|
129
|
-
export {
|
|
130
|
+
export { p as DEFAULT_PREVIOUS_SESSION_KID, f as DEFAULT_SESSION_KID, y as MIN_SESSION_SECRET_LENGTH, L as SESSION_COOKIE_NAME, i as SESSION_HEADER_NAME, u as SESSION_PAYLOAD_VERSION, b as assertProductionSessionSecret, I as buildSetCookie, P as checkBearer, F as readCookie, R as readSessionValue, H as resetSessionSecretWarningLatch, v as resolveOptionalSessionSecrets, h as resolveSessionSecret, g as resolveSessionSecrets, z as sessionExpiryFromHeaders, k as signSession, N as timingSafeStringEqual, j as verifySession, M as verifySessionKeyed };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltro/protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.82.0",
|
|
4
4
|
"description": "The Voltro wire + plugin contract — defineQuery/Mutation/Action/Stream, definePlugin, sessions / JWT / API-keys, and the RPC protocol.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"voltro",
|
|
@@ -65,8 +65,8 @@
|
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@effect/experimental": "^0.61.1",
|
|
67
67
|
"@effect/sql": "^0.52.1",
|
|
68
|
-
"@voltro/database": "0.
|
|
69
|
-
"@voltro/logger": "0.
|
|
68
|
+
"@voltro/database": "0.82.0",
|
|
69
|
+
"@voltro/logger": "0.82.0",
|
|
70
70
|
"jose": "^6.2.12"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|