@voltro/protocol 0.37.0 → 0.38.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 +92 -0
- package/dist/{auth-B6YZuSBr.js → auth-CKS3UNnf.js} +45 -45
- package/dist/index.d.ts +27 -0
- package/dist/index.js +383 -383
- package/dist/rest.js +1 -1
- package/dist/session.js +6 -6
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -39,6 +39,98 @@ _Changes staged for the next release accumulate here (rolled up from
|
|
|
39
39
|
|
|
40
40
|
---
|
|
41
41
|
|
|
42
|
+
## [0.38.0] — 2026-08-14
|
|
43
|
+
|
|
44
|
+
### ⚠ BREAKING
|
|
45
|
+
|
|
46
|
+
- **@voltro/plugin-audit, @voltro/protocol, @voltro/plugin-auth** — An audit row now says when an action was taken through an IMPERSONATED session, on the default settings, and no redactor can take that away.
|
|
47
|
+
|
|
48
|
+
`AuditEvent` gained `impersonation`, and the datastore sink a nullable json column of the same name. The mark is lifted out of `subject.metadata` BEFORE the redaction chain runs, so `redactSubject` — including a custom function that erases the subject wholesale — never gets a say.
|
|
49
|
+
|
|
50
|
+
**The defect it closes.** `@voltro/plugin-auth` mints the mark into `subject.metadata`, and `auditPlugin`'s default `redactSubject: 'metadata'` replaces that whole bag. That default is right: the bag is where a per-user provider credential lands, and an audit table is the last place a live PAT should be. The consequence was that on defaults an impersonated action was recorded indistinguishably from the user's own — the one distinction an audit trail exists to make. The documented mitigation (`redactSubject: impersonationAuditRedactor()`) worked and was opt-in, and an audit property that depends on somebody wiring it is not a property.
|
|
51
|
+
|
|
52
|
+
The alternative fix — a keep-these-keys option on `redactSubject` — was rejected for the same reason: it leaves the default wrong, and "who really did this" is not the app's metadata to configure away. It is a property of the event, so it is now a field of the event.
|
|
53
|
+
|
|
54
|
+
**BREAKING: `IMPERSONATION_METADATA_KEY` moved from `@voltro/plugin-auth` to `@voltro/protocol`.** It names the one reserved key in `Subject.metadata`, and `Subject` is protocol's type. Two packages need it — plugin-auth writes the mark, plugin-audit reads it — and a plugin must not depend on another plugin, so spelling the string in both would have made it a second definition no guard is watching. Everything else stays: plugin-auth still exports `impersonationOf`, `isImpersonated`, `ImpersonationMark` and `impersonationAuditRedactor`. The codemod repoints the import, preserving an alias and the type-only form.
|
|
55
|
+
|
|
56
|
+
The redactor keeps working and is no longer load-bearing. Set `redactSubject: 'none'` or a custom function for your own reasons; the impersonation mark is recorded either way.
|
|
57
|
+
|
|
58
|
+
No migration is needed for the new column — a `_voltro_*` change rides the declarative differ on `voltro db apply` and on a `voltro dev` boot, on every dialect.
|
|
59
|
+
- **@voltro/cli** — A `*.startup.ts` that fails now refuses the boot. It used to warn and let the server come up.
|
|
60
|
+
|
|
61
|
+
Measured, on a real `voltro dev` against postgres, while building the row-filter integration test in this same release. A startup reached for `ctx.store.select(...)` — a builder that lives on the request-scoped `MutationStore`, not on the `DataStore` a startup receives — and threw on its first line. The boot printed:
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
warn startup: function rejected
|
|
65
|
+
info startup: registered <- next line, same file
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
and then served every request with no row filter registered. Two lines contradicting each other, the second asserting exactly the thing that had just failed, and an app that looked healthy while its access control was absent.
|
|
69
|
+
|
|
70
|
+
**The rule this overturns was right when it was written.** The header of `startupRunner.ts` read "Errors are logged but never fatal — a failing startup MUST NOT block the rest of the app", and for the startups it was written for — an SSE bridge, a sync loop, a metric aggregator — that is the correct call. It stopped being right when a startup became the documented seam for REGISTRATION: `setRowFilter` is installed from one.
|
|
71
|
+
|
|
72
|
+
The runner cannot tell a registration from a background loop, and the two failures are not symmetric. "The app refuses to boot" is fixed in seconds and is visible to everyone; "the app serves without its access control" is visible to nobody. So the default is the recoverable one, and an app that genuinely wants best-effort writes the `try`/`catch` inside its own startup — one line, at the site where somebody decided the failure was acceptable, where a reviewer can see it. Deliberately not a flag: a flag moves that decision away from the startup it applies to and makes it one setting for all of them.
|
|
73
|
+
|
|
74
|
+
**Two sibling silences went with it**, because fixing only the rejection would have left two more ways to reach the identical state — the per-seam shape this repo keeps paying for. A startup file that cannot be imported, and one with no default-exported function, used to warn and skip. Both refuse now. The second matters more than it sounds: the convention is a DEFAULT-exported function, a named export is discovered and never runs, and that is indistinguishable from a startup that ran and did nothing.
|
|
75
|
+
|
|
76
|
+
**And the 2-second race is gone, which is the half that made the rest reliable.** The old code did not wait for a startup to settle — it raced it against 2000 ms and let the boot win. A startup slower than that was reported as fine, so a rejection arriving afterwards had nothing left to refuse. The runner now waits for the startup to SETTLE, so every failure is catchable however slow it is.
|
|
77
|
+
|
|
78
|
+
That race existed to protect one shape: a startup that never returns because it holds a fiber until shutdown. Counted before changing it, that shape appears in ZERO of the four startups this framework ships — `warm.startup.tsx` (twice), `searchBackfill.startup.tsx` and the memory fixture's all return. So the race protected the shape we discourage and penalised the shape we teach, and the penalised one includes `searchBackfill`, our own example, which awaits a full-table query plus an index backfill and is the likeliest thing in the box to exceed two seconds. Slow AND failing put a consumer back in exactly the silent state this release removes.
|
|
79
|
+
|
|
80
|
+
**So a startup that never returns now refuses the boot too**, after `VOLTRO_STARTUP_TIMEOUT_MS` (60s default), with a message naming the file and showing the `onShutdown` shape to use instead. That makes a previously-documented capability illegal — "a fiber that resolves only on shutdown" — and it is the deliberate half of this change rather than a side effect. A startup that is merely SLOW is unaffected: it is waited for and registers when it finishes.
|
|
81
|
+
|
|
82
|
+
`startup: registered` is written only when the function actually returned. The old code printed it for a failed startup and for one still running.
|
|
83
|
+
|
|
84
|
+
Verified against a real process in every direction, not only in units: the reintroduced defect exits 1 and never listens; a never-returning startup exits 1 and never listens; a slow-but-successful one still registers; and the healthy fixture boots and serves all eight row-filter assertions. `startupRunner.test.ts` is new — there were no tests on this runner at all, which is part of why the contradiction survived.
|
|
85
|
+
|
|
86
|
+
**`voltro update` carries you across this** — codemod `0.38.0/02_startup-failure-refuses-boot`.
|
|
87
|
+
|
|
88
|
+
### Fixed
|
|
89
|
+
|
|
90
|
+
- **@voltro/cli** — A table declared through `databaseHandle({ … })` but not exported as a top-level table is now DISCOVERED — so its mixins apply.
|
|
91
|
+
|
|
92
|
+
Discovery kept whatever `isTable()` accepted out of a schema module's `Object.values`, which only ever sees tables the file exports DIRECTLY. A schema that builds its tables programmatically exports the builder's result:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
export const blogEntities = contentTypeToEntities(blogPost) // { draft, published }
|
|
96
|
+
export const database = databaseHandle({ …, blogPostDrafts: blogEntities.draft })
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`isTable({ draft, published })` is false, so those tables never entered the schema registry — while `databaseHandle` had registered them for by-name lookup perfectly well.
|
|
100
|
+
|
|
101
|
+
**Two registries with different populations, read by different things.** `getTable()` found the table, so insert validation knew `tenantId` was NOT NULL. The schema registry is what drives the mixins, so nothing stamped it. Measured against a real `voltro dev` boot of the scaffolded `api-cms` template, over real RPC:
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
TableValidationFailed: { "table": "blogPost_drafts", "summary":
|
|
105
|
+
"missing required column 'tenantId' — NOT NULL with no default and not auto-stamped" }
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Every `content.saveDraft` in that template, since it shipped. Its own unit test could not see it, because the test builds its schema registry by hand — the one step the running app does not perform.
|
|
109
|
+
|
|
110
|
+
**The write failing was the lucky half.** Reads do not announce themselves: `makeQueryFinalizer` AND-merges `tenantId` from this same registry, so a table missing from it is a table nobody scopes. The visible symptom was a broken mutation; the invisible one was tenant isolation quietly not applied to those tables.
|
|
111
|
+
|
|
112
|
+
The fix takes the by-name registry's DELTA across each schema module's import, so a handle-declared table is attributed to the file that declared it — rather than reading the whole global registry, which by then also holds framework tables that this set deliberately excludes. It lives in `loadDiscovered`, which `voltro dev` and `voltro serve` both call, so the two cannot disagree about it.
|
|
113
|
+
|
|
114
|
+
No app change is needed; the idiomatic `databaseHandle` declaration now works as its documentation always said.
|
|
115
|
+
- **@voltro/database, @voltro/cli** — A migration that fails because `DB_SCHEMA` names a schema that does not exist now says so.
|
|
116
|
+
|
|
117
|
+
Postgres answers `3F000 no schema has been selected to create in`, and the only thing that puts a non-default schema on the connection's `search_path` here is `DB_SCHEMA`. The error mentions neither the variable nor the schema, so the FIRST `CREATE TABLE` of the boot fails with a message about SQL and the reader goes looking at the DDL — for a typo in an environment variable.
|
|
118
|
+
|
|
119
|
+
Found while building the row-filter integration test below: the boot aborted, the log named `_voltro_migrations` and a postgres routine, and nothing in it pointed at the one line of configuration that caused it. Same shape as a 403 that says nothing about `VOLTRO_INSPECT_TOKEN`, fixed in the same release.
|
|
120
|
+
|
|
121
|
+
The remedy also states what the framework will NOT do: Voltro creates tables, never the schema itself. That is a namespace decision, and inventing one from a typo puts a migration somewhere nobody is looking.
|
|
122
|
+
|
|
123
|
+
`remedyFor` is deliberately a one-entry map and the test asserts the empty case as well as the full one. A remedy is worth printing only where the mapping from driver code to cause is exact; a list of maybes is how a reader learns to skip the section.
|
|
124
|
+
|
|
125
|
+
**Alongside it: the row filter is now driven under `voltro dev` against a real postgres.** Both defects that reached consumers lived between layers that were each individually covered — a module-local `let` that split per instance, then a query producer that built its context from an unscoped request — and three consumer documents carried "we have not run this against a real database" as an honest caveat. `rowFilterDevPostgres.integration.test.ts` boots the fixture twice: handlers with no predicate of their own, a filter registered from a `*.startup.tsx`, and a NEGATIVE CONTROL run with the registration skipped that asserts the same queries return BOTH owners. Without the control, "the caller saw one owner" is equally consistent with a database that only ever held one.
|
|
126
|
+
- **@voltro/cli** — A shard that cannot be released no longer spins a fiber at full speed. Upstream `@effect/cluster` releases shards through `Effect.eventually` — retry until success, zero delay, logged at DEBUG — so a shard whose storage was unreachable retried as fast as the event loop allowed, in the one place nobody watches.
|
|
127
|
+
|
|
128
|
+
Our patch replaces it with `Effect.retry(Schedule.exponential(100) ∪ Schedule.spaced(5000))`. `union` takes the MINIMUM of the two delays, so the 5s spacing caps the backoff instead of compounding with it, and both schedules recur forever — attempts stay unbounded, which is what the original intended. The persistence was always correct; only the missing delay was the defect.
|
|
129
|
+
|
|
130
|
+
This entry exists because the change would otherwise have shipped undocumented. The patch lives in `packages/cli/templates/patches/`, and the changelog gate requires an entry for `packages/*/src` — so nothing would have demanded one, even though the file is installed into every user project that runs cluster. A rule that cannot see a path is not the same as a path with nothing on it.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
42
134
|
## [0.37.0] — 2026-08-13
|
|
43
135
|
|
|
44
136
|
### ⚠ BREAKING
|
|
@@ -21,9 +21,9 @@ var i = "admin:full", a = "apikeys:issue:self", o = "apikeys:issue:org", s = "ap
|
|
|
21
21
|
}, te = (e, n) => p(e, n) ? t.void : t.fail(new c({
|
|
22
22
|
required: n,
|
|
23
23
|
message: `missing required scope '${n}'`
|
|
24
|
-
})), m = (e) => typeof e.action == "string" && typeof e.resourceType == "string", h = (e) => typeof e.open == "string",
|
|
25
|
-
|
|
26
|
-
},
|
|
24
|
+
})), m = (e) => typeof e.action == "string" && typeof e.resourceType == "string", h = (e) => typeof e.open == "string", ne = (e) => ({ open: e }), g = (e) => typeof e == "string" ? [e] : e, _, v = (e) => {
|
|
25
|
+
_ = e;
|
|
26
|
+
}, y = (e) => _ === void 0 ? e.filter((e) => (e.guards ?? []).some((e) => !m(e) && e.resource !== void 0)).map((e) => e.tag) : [], b = (e) => [
|
|
27
27
|
`${e.length} procedure${e.length === 1 ? "" : "s"} declare a per-resource guard that nothing enforces:`,
|
|
28
28
|
...e.slice(0, 10).map((e) => ` ${e}`),
|
|
29
29
|
...e.length > 10 ? [` … and ${e.length - 10} more`] : [],
|
|
@@ -37,13 +37,13 @@ var i = "admin:full", a = "apikeys:issue:self", o = "apikeys:issue:org", s = "ap
|
|
|
37
37
|
" • setResourceScopeResolver((req) => Effect<boolean>) — answers \"does this",
|
|
38
38
|
" subject hold `req.scope` on `req.resource`\" from your own tables.",
|
|
39
39
|
" • Drop the `resource` extractor if a global scope check is what you meant."
|
|
40
|
-
].join("\n"),
|
|
41
|
-
|
|
42
|
-
},
|
|
40
|
+
].join("\n"), x = () => _, S, re = (e) => {
|
|
41
|
+
S = e;
|
|
42
|
+
}, C = () => S, w = (e) => new c({
|
|
43
43
|
required: "access-decision",
|
|
44
44
|
message: `${e ?? "this procedure"} declares no access decision: it has neither \`guards:\` nor \`openAccess:\`, and the app runs with \`security.defaultDeny\`. Add the scope(s) a caller must hold (\`guards: [{ scope: '…' }]\`), or declare it open on purpose with \`openAccess: '<why anyone may call this>'\`.`
|
|
45
|
-
}),
|
|
46
|
-
if (!t || t.length === 0) return n?.defaultDeny === !0 ?
|
|
45
|
+
}), T = (e, t, n) => {
|
|
46
|
+
if (!t || t.length === 0) return n?.defaultDeny === !0 ? w(n.procedure) : null;
|
|
47
47
|
for (let n of t) {
|
|
48
48
|
if (h(n)) continue;
|
|
49
49
|
if (m(n)) {
|
|
@@ -53,7 +53,7 @@ var i = "admin:full", a = "apikeys:issue:self", o = "apikeys:issue:org", s = "ap
|
|
|
53
53
|
message: `relationship guard '${n.action}' on '${n.resourceType}' cannot be checked synchronously`
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
|
-
let t =
|
|
56
|
+
let t = g(n.scope);
|
|
57
57
|
if (t.length === 0) continue;
|
|
58
58
|
let r = t.filter((t) => p(e, t));
|
|
59
59
|
if (!((n.mode ?? "all") === "any" ? r.length > 0 : r.length === t.length)) {
|
|
@@ -65,13 +65,13 @@ var i = "admin:full", a = "apikeys:issue:self", o = "apikeys:issue:org", s = "ap
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
return null;
|
|
68
|
-
},
|
|
68
|
+
}, E = (e, n, r) => {
|
|
69
69
|
let i = (e) => new c({
|
|
70
70
|
required: `${n.resourceType}:${n.action}`,
|
|
71
71
|
message: e
|
|
72
72
|
});
|
|
73
73
|
if (p(e, "admin:full")) return t.succeed(null);
|
|
74
|
-
let a =
|
|
74
|
+
let a = S;
|
|
75
75
|
if (a === void 0) return t.succeed(i(`no policy resolver registered — cannot authorize '${n.action}' on '${n.resourceType}'`));
|
|
76
76
|
let o = n.resource(r);
|
|
77
77
|
return o === void 0 || o === "" ? t.succeed(i(`input does not identify a '${n.resourceType}' to authorize`)) : t.suspend(() => a({
|
|
@@ -80,18 +80,18 @@ var i = "admin:full", a = "apikeys:issue:self", o = "apikeys:issue:org", s = "ap
|
|
|
80
80
|
resourceType: n.resourceType,
|
|
81
81
|
resourceId: o
|
|
82
82
|
})).pipe(t.catchAllCause(() => t.succeed(!1)), t.map((e) => e ? null : i(`no '${n.action}' relation on ${n.resourceType}:${o}`)));
|
|
83
|
-
},
|
|
84
|
-
if (!n || n.length === 0) return t.succeed(
|
|
85
|
-
let a =
|
|
86
|
-
return !n.some(m) && (!a || !n.some((e) => e.resource !== void 0)) ? t.succeed(
|
|
83
|
+
}, D = (e, n, r, i) => {
|
|
84
|
+
if (!n || n.length === 0) return t.succeed(T(e, n, i));
|
|
85
|
+
let a = _;
|
|
86
|
+
return !n.some(m) && (!a || !n.some((e) => e.resource !== void 0)) ? t.succeed(T(e, n, i)) : t.gen(function* () {
|
|
87
87
|
for (let i of n) {
|
|
88
88
|
if (h(i)) continue;
|
|
89
89
|
if (m(i)) {
|
|
90
|
-
let t = yield*
|
|
90
|
+
let t = yield* E(e, i, r);
|
|
91
91
|
if (t) return t;
|
|
92
92
|
continue;
|
|
93
93
|
}
|
|
94
|
-
let n =
|
|
94
|
+
let n = g(i.scope);
|
|
95
95
|
if (n.length === 0) continue;
|
|
96
96
|
let o = i.resource ? i.resource(r) : void 0, s = [];
|
|
97
97
|
for (let r of n) {
|
|
@@ -119,51 +119,51 @@ var i = "admin:full", a = "apikeys:issue:self", o = "apikeys:issue:org", s = "ap
|
|
|
119
119
|
}
|
|
120
120
|
return null;
|
|
121
121
|
});
|
|
122
|
-
},
|
|
122
|
+
}, O = n.Record({
|
|
123
123
|
key: n.String,
|
|
124
124
|
value: n.Unknown
|
|
125
|
-
}),
|
|
125
|
+
}), k = n.optional(n.Array(n.String)), A = n.Struct({
|
|
126
126
|
type: n.Literal("user"),
|
|
127
127
|
id: n.String,
|
|
128
128
|
tenantId: n.String,
|
|
129
|
-
scopes:
|
|
130
|
-
metadata: n.optional(
|
|
131
|
-
}),
|
|
129
|
+
scopes: k,
|
|
130
|
+
metadata: n.optional(O)
|
|
131
|
+
}), j = n.Struct({
|
|
132
132
|
type: n.Literal("apiKey"),
|
|
133
133
|
id: n.String,
|
|
134
134
|
tenantId: n.String,
|
|
135
|
-
scopes:
|
|
136
|
-
metadata: n.optional(
|
|
137
|
-
}),
|
|
135
|
+
scopes: k,
|
|
136
|
+
metadata: n.optional(O)
|
|
137
|
+
}), M = n.Struct({
|
|
138
138
|
type: n.Literal("serviceAccount"),
|
|
139
139
|
id: n.String,
|
|
140
140
|
tenantId: n.String,
|
|
141
|
-
scopes:
|
|
142
|
-
metadata: n.optional(
|
|
143
|
-
}),
|
|
141
|
+
scopes: k,
|
|
142
|
+
metadata: n.optional(O)
|
|
143
|
+
}), N = n.Struct({
|
|
144
144
|
type: n.Literal("anonymous"),
|
|
145
145
|
id: n.Null,
|
|
146
146
|
tenantId: n.NullOr(n.String)
|
|
147
|
-
}),
|
|
147
|
+
}), P = n.Struct({
|
|
148
148
|
type: n.Literal("system"),
|
|
149
149
|
id: n.String,
|
|
150
150
|
tenantId: n.Null,
|
|
151
|
-
scopes:
|
|
152
|
-
metadata: n.optional(
|
|
153
|
-
}),
|
|
151
|
+
scopes: k,
|
|
152
|
+
metadata: n.optional(O)
|
|
153
|
+
}), F = n.Union(A, j, M, N, P), I = n.Union(A.omit("scopes"), j.omit("scopes"), M.omit("scopes"), N, P.omit("scopes")), L = (e) => {
|
|
154
154
|
if (e.type === "anonymous") return e;
|
|
155
155
|
let { scopes: t, ...n } = e;
|
|
156
156
|
return n;
|
|
157
|
-
},
|
|
157
|
+
}, R = (e) => e.scopes ?? [], z = (e) => ({
|
|
158
158
|
type: "anonymous",
|
|
159
159
|
id: null,
|
|
160
160
|
tenantId: e
|
|
161
|
-
}),
|
|
161
|
+
}), B = (e, t = ["admin:full"]) => ({
|
|
162
162
|
type: "system",
|
|
163
163
|
id: e,
|
|
164
164
|
tenantId: null,
|
|
165
165
|
scopes: t
|
|
166
|
-
}),
|
|
166
|
+
}), V = (e, t) => {
|
|
167
167
|
let n = e;
|
|
168
168
|
return {
|
|
169
169
|
type: "serviceAccount",
|
|
@@ -172,7 +172,7 @@ var i = "admin:full", a = "apikeys:issue:self", o = "apikeys:issue:org", s = "ap
|
|
|
172
172
|
scopes: n.scopes ?? ["admin:full"],
|
|
173
173
|
...n.metadata === void 0 ? {} : { metadata: n.metadata }
|
|
174
174
|
};
|
|
175
|
-
},
|
|
175
|
+
}, H = (e) => e.type === "system", U = "impersonation", W = (e) => e.metadata?.impersonation ?? null, G = class extends e.Tag("@voltro/Subject")() {}, K = class extends e.Tag("@voltro/ConnectionInfo")() {}, q = class extends r.Tag()("@voltro/AuthMiddleware", { provides: G }) {}, J = class extends r.Tag()("@voltro/ConnectionInfoMiddleware", { provides: K }) {}, Y = (e) => typeof e.mountRoutes == "function", ie = (e) => Array.isArray(e) ? {
|
|
176
176
|
kind: "grant",
|
|
177
177
|
scopes: e
|
|
178
178
|
} : e, X = (e, t) => {
|
|
@@ -180,7 +180,7 @@ var i = "admin:full", a = "apikeys:issue:self", o = "apikeys:issue:org", s = "ap
|
|
|
180
180
|
subject: e,
|
|
181
181
|
removed: []
|
|
182
182
|
};
|
|
183
|
-
let n =
|
|
183
|
+
let n = R(e);
|
|
184
184
|
if (t.kind === "grant") {
|
|
185
185
|
if (t.scopes.length === 0) return {
|
|
186
186
|
subject: e,
|
|
@@ -203,14 +203,14 @@ var i = "admin:full", a = "apikeys:issue:self", o = "apikeys:issue:org", s = "ap
|
|
|
203
203
|
},
|
|
204
204
|
removed: i
|
|
205
205
|
};
|
|
206
|
-
},
|
|
206
|
+
}, ae = 3e4, oe = 1e4, Z = (e) => `${e.type}\u0000${e.tenantId ?? ""}\u0000${e.id ?? ""}`, se = () => {
|
|
207
207
|
if (typeof process > "u") return;
|
|
208
208
|
let e = process.env.VOLTRO_AUTH_SCOPE_CACHE_TTL_MS;
|
|
209
209
|
if (e === void 0 || e === "") return;
|
|
210
210
|
let t = Number(e);
|
|
211
211
|
return Number.isFinite(t) && t >= 0 ? t : void 0;
|
|
212
212
|
}, Q = (e = {}) => {
|
|
213
|
-
let t = e.ttlMs ??
|
|
213
|
+
let t = e.ttlMs ?? se() ?? 3e4, n = e.maxEntries ?? 1e4, r = e.now ?? Date.now, i = /* @__PURE__ */ new Map(), a = () => {
|
|
214
214
|
if (i.size <= n) return;
|
|
215
215
|
let e = r();
|
|
216
216
|
for (let [t, n] of i) n.freshUntil <= e && i.delete(t);
|
|
@@ -246,8 +246,8 @@ var i = "admin:full", a = "apikeys:issue:self", o = "apikeys:issue:org", s = "ap
|
|
|
246
246
|
};
|
|
247
247
|
}
|
|
248
248
|
};
|
|
249
|
-
},
|
|
250
|
-
let n = t?.resolveScopes, r = n === void 0 || t?.scopeCache === !1 ? null : t?.scopeCache !== void 0 &&
|
|
249
|
+
}, ce = (e) => typeof e.resolve == "function", le = (e, t) => {
|
|
250
|
+
let n = t?.resolveScopes, r = n === void 0 || t?.scopeCache === !1 ? null : t?.scopeCache !== void 0 && ce(t.scopeCache) ? t.scopeCache : Q(t?.scopeCache ?? {});
|
|
251
251
|
return async (i) => {
|
|
252
252
|
let a = t?.getStore?.(), o = a === void 0 ? i : {
|
|
253
253
|
...i,
|
|
@@ -258,7 +258,7 @@ var i = "admin:full", a = "apikeys:issue:self", o = "apikeys:issue:org", s = "ap
|
|
|
258
258
|
if (e.kind === "matched") {
|
|
259
259
|
let a = e.subject;
|
|
260
260
|
if (n !== void 0) {
|
|
261
|
-
let s = async () =>
|
|
261
|
+
let s = async () => ie(await n(e.subject, o)), { decision: c, fresh: l } = r === null ? {
|
|
262
262
|
decision: await s(),
|
|
263
263
|
fresh: !0
|
|
264
264
|
} : await r.resolve(Z(e.subject), s);
|
|
@@ -294,10 +294,10 @@ var i = "admin:full", a = "apikeys:issue:self", o = "apikeys:issue:org", s = "ap
|
|
|
294
294
|
if (t?.fallback) return { subject: await t.fallback(o) };
|
|
295
295
|
let s = o.headers["x-tenant"] ?? null;
|
|
296
296
|
if (s === null && t?.anonymousTenantRequired === !0) throw new $({ reason: "tenant required (x-tenant header missing)" });
|
|
297
|
-
return { subject:
|
|
297
|
+
return { subject: z(s) };
|
|
298
298
|
};
|
|
299
|
-
}, $ = class extends n.TaggedError()("Unauthenticated", { reason: n.optional(n.String) }) {},
|
|
299
|
+
}, $ = class extends n.TaggedError()("Unauthenticated", { reason: n.optional(n.String) }) {}, ue = (e, t) => {
|
|
300
300
|
if (e.type === "anonymous") throw new $(t === void 0 ? {} : { reason: t });
|
|
301
301
|
};
|
|
302
302
|
//#endregion
|
|
303
|
-
export {
|
|
303
|
+
export { D as A, ne as B, i as C, c as D, a as E, p as F, l as G, d as H, ee as I, h as L, y as M, C as N, b as O, x as P, m as R, V as S, s as T, re as U, te as V, v as W, Q as _, ae as a, L as b, I as c, z as d, X as f, H as g, Y as h, oe as i, f as j, T as k, G as l, le as m, K as n, U as o, ue as p, J as r, F as s, q as t, $ as u, W as v, o as w, B as x, Z as y, w as z };
|
package/dist/index.d.ts
CHANGED
|
@@ -2181,6 +2181,21 @@ export declare interface IdempotencyStore {
|
|
|
2181
2181
|
* corrupt the pointer. */
|
|
2182
2182
|
export declare const idToPath: (id: RowId) => string;
|
|
2183
2183
|
|
|
2184
|
+
/**
|
|
2185
|
+
* `Subject.metadata` is the APP's bag — opaque to the framework, stored
|
|
2186
|
+
* verbatim — with exactly one reserved key: this one. It carries the mark that
|
|
2187
|
+
* says the session is an impersonated one.
|
|
2188
|
+
*
|
|
2189
|
+
* **Why it lives in protocol and not in `@voltro/plugin-auth`, which mints it.**
|
|
2190
|
+
* Two packages need the answer to "is this session impersonated" and they must
|
|
2191
|
+
* not depend on each other: plugin-auth WRITES the mark, and plugin-audit reads
|
|
2192
|
+
* it to stamp `AuditEvent.impersonation` before redaction runs. A key spelled
|
|
2193
|
+
* out in both is a second definition that no guard is watching — the shape this
|
|
2194
|
+
* repo has been bitten by often enough to have a rule about it. `Subject` is
|
|
2195
|
+
* protocol's type, so its reserved key is protocol's too.
|
|
2196
|
+
*/
|
|
2197
|
+
export declare const IMPERSONATION_METADATA_KEY: "impersonation";
|
|
2198
|
+
|
|
2184
2199
|
export declare interface InsertTarget<Input = unknown, Row = unknown, Item = Record<string, unknown>> extends NestedTargetFields<Input> {
|
|
2185
2200
|
readonly table: string;
|
|
2186
2201
|
readonly op: 'insert';
|
|
@@ -3591,6 +3606,18 @@ export declare const queryToRpc: <Name extends string, Input extends Schema.Sche
|
|
|
3591
3606
|
revision: Schema.optional<typeof Schema.Number>;
|
|
3592
3607
|
}>]>, Schema.Schema.All>, typeof Schema.Never, never>;
|
|
3593
3608
|
|
|
3609
|
+
/**
|
|
3610
|
+
* The RAW mark, unvalidated, or `null`.
|
|
3611
|
+
*
|
|
3612
|
+
* Deliberately `unknown`: protocol owns the key, not the payload's shape.
|
|
3613
|
+
* `@voltro/plugin-auth` mints the mark and validates it back into an
|
|
3614
|
+
* `ImpersonationMark`; an auditor only needs to copy it out before a redactor
|
|
3615
|
+
* can reach it, and giving protocol an opinion about the fields would make the
|
|
3616
|
+
* shape need to agree in two places again — the exact thing the key moved here
|
|
3617
|
+
* to avoid.
|
|
3618
|
+
*/
|
|
3619
|
+
export declare const rawImpersonationMark: (subject: Subject) => unknown;
|
|
3620
|
+
|
|
3594
3621
|
/** The `channel:` namespace. Every channel key starts with it. */
|
|
3595
3622
|
export declare const REACTIVITY_CHANNEL_PREFIX = "channel:";
|
|
3596
3623
|
|