@fuzdev/fuz_app 0.155.1 → 0.156.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/dist/actions/CLAUDE.md +27 -14
- package/dist/actions/action_codegen.d.ts +10 -3
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +52 -13
- package/dist/actions/action_event.d.ts.map +1 -1
- package/dist/actions/action_event.js +13 -11
- package/dist/actions/action_rpc.d.ts +4 -3
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +4 -3
- package/dist/actions/action_spec.d.ts +102 -206
- package/dist/actions/action_spec.d.ts.map +1 -1
- package/dist/actions/action_spec.js +18 -96
- package/dist/actions/action_types.d.ts +4 -4
- package/dist/actions/action_types.d.ts.map +1 -1
- package/dist/actions/action_types.js +2 -2
- package/dist/actions/broadcast_api.d.ts.map +1 -1
- package/dist/actions/broadcast_api.js +6 -5
- package/dist/actions/compile_action_registry.d.ts +11 -6
- package/dist/actions/compile_action_registry.d.ts.map +1 -1
- package/dist/actions/compile_action_registry.js +15 -9
- package/dist/actions/perform_action.d.ts +4 -4
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +11 -11
- package/dist/auth/CLAUDE.md +1 -1
- package/dist/auth/account_action_specs.d.ts +50 -23
- package/dist/auth/account_action_specs.d.ts.map +1 -1
- package/dist/auth/account_action_specs.js +18 -8
- package/dist/auth/account_route_schema.d.ts +10 -10
- package/dist/auth/account_schema.d.ts +21 -21
- package/dist/auth/actor_lookup_action_specs.d.ts +7 -7
- package/dist/auth/actor_search_action_specs.d.ts +6 -6
- package/dist/auth/admin_action_specs.d.ts +98 -98
- package/dist/auth/app_settings_schema.d.ts +2 -2
- package/dist/auth/audit_log_route_schema.d.ts +1 -1
- package/dist/auth/audit_log_schema.d.ts +44 -44
- package/dist/auth/auth_guard_resolver.d.ts +2 -2
- package/dist/auth/auth_guard_resolver.js +2 -2
- package/dist/auth/bootstrap_route_schema.d.ts +4 -4
- package/dist/auth/cell_action_specs.d.ts +241 -241
- package/dist/auth/cell_actions.js +3 -3
- package/dist/auth/cell_audit_action_specs.d.ts +14 -14
- package/dist/auth/cell_audit_metadata.d.ts +6 -6
- package/dist/auth/cell_field_action_specs.d.ts +38 -38
- package/dist/auth/cell_field_audit_metadata.d.ts +4 -4
- package/dist/auth/cell_grant_action_specs.d.ts +61 -61
- package/dist/auth/cell_grant_audit_metadata.d.ts +10 -10
- package/dist/auth/cell_item_action_specs.d.ts +50 -50
- package/dist/auth/cell_item_audit_metadata.d.ts +5 -5
- package/dist/auth/invite_schema.d.ts +6 -6
- package/dist/auth/role_grant_offer_action_specs.d.ts +120 -120
- package/dist/auth/role_grant_offer_notifications.d.ts +66 -66
- package/dist/auth/role_grant_offer_schema.d.ts +6 -6
- package/dist/auth/self_service_role_action_specs.d.ts +2 -2
- package/dist/auth/signup_route_schema.d.ts +2 -2
- package/dist/http/CLAUDE.md +9 -8
- package/dist/http/auth_shape.d.ts +54 -17
- package/dist/http/auth_shape.d.ts.map +1 -1
- package/dist/http/auth_shape.js +104 -52
- package/dist/http/error_schemas.d.ts +6 -4
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +4 -9
- package/dist/http/jsonrpc_errors.d.ts +11 -4
- package/dist/http/jsonrpc_errors.d.ts.map +1 -1
- package/dist/http/jsonrpc_errors.js +11 -4
- package/dist/http/jsonrpc_helpers.d.ts.map +1 -1
- package/dist/http/jsonrpc_helpers.js +2 -1
- package/dist/http/route_spec.d.ts +3 -2
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +20 -8
- package/dist/http/schema_helpers.d.ts +24 -20
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +24 -19
- package/dist/primitive_schemas.d.ts +10 -3
- package/dist/primitive_schemas.d.ts.map +1 -1
- package/dist/primitive_schemas.js +10 -2
- package/dist/primitive_schemas_fuz.d.ts +69 -0
- package/dist/primitive_schemas_fuz.d.ts.map +1 -0
- package/dist/primitive_schemas_fuz.js +49 -0
- package/dist/realtime/sse.d.ts +3 -3
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse.js +4 -4
- package/dist/schema_issues.d.ts +91 -4
- package/dist/schema_issues.d.ts.map +1 -1
- package/dist/schema_issues.js +262 -1
- package/dist/schema_meta.d.ts +24 -8
- package/dist/schema_meta.d.ts.map +1 -1
- package/dist/schema_meta.js +31 -10
- package/dist/server/serve_fact_route.d.ts.map +1 -1
- package/dist/server/serve_fact_route.js +2 -1
- package/dist/testing/CLAUDE.md +17 -11
- package/dist/testing/adversarial_input_cases.d.ts +18 -23
- package/dist/testing/adversarial_input_cases.d.ts.map +1 -1
- package/dist/testing/adversarial_input_cases.js +51 -46
- package/dist/testing/cross_backend/action_manifest.d.ts +2 -1
- package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
- package/dist/testing/cross_backend/action_manifest.js +3 -3
- package/dist/testing/cross_backend/cell_crud.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_crud.js +3 -8
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +5 -4
- package/dist/testing/cross_backend/cross_rpc.d.ts +4 -2
- package/dist/testing/cross_backend/cross_rpc.d.ts.map +1 -1
- package/dist/testing/cross_backend/cross_rpc.js +6 -4
- package/dist/testing/cross_backend/rpc_success_fixtures.d.ts.map +1 -1
- package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/sse_round_trip.js +3 -2
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +8 -8
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +4 -3
- package/dist/testing/rpc_envelope_cases.d.ts +3 -3
- package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
- package/dist/testing/rpc_envelope_cases.js +1 -1
- package/dist/testing/rpc_helpers.d.ts +12 -8
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +18 -15
- package/dist/testing/schema_generators.d.ts +75 -40
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +273 -99
- package/dist/testing/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/sse_round_trip.js +4 -3
- package/dist/ui/admin_accounts_state.svelte.d.ts +10 -10
- package/dist/ui/admin_accounts_state.svelte.d.ts.map +1 -1
- package/dist/ui/admin_invites_state.svelte.d.ts +1 -1
- package/dist/ui/admin_invites_state.svelte.d.ts.map +1 -1
- package/dist/ui/admin_sessions_state.svelte.d.ts +2 -2
- package/dist/ui/admin_sessions_state.svelte.d.ts.map +1 -1
- package/dist/ui/role_grant_offers_state.svelte.d.ts +6 -6
- package/dist/zod.d.ts +23 -5
- package/dist/zod.d.ts.map +1 -1
- package/dist/zod.js +2 -2
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth_shape.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/auth_shape.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"auth_shape.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/auth_shape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,WAAW,gNAAkE,CAAC;AAC3F,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,KAAG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f,OAAO,WAAW,EAClB,SAAS,MAAM,KACb,IAmBF,CAAC"}
|
package/dist/http/auth_shape.js
CHANGED
|
@@ -20,19 +20,24 @@
|
|
|
20
20
|
* `actions → http` dependency direction (and `http/error_schemas.ts` /
|
|
21
21
|
* `http/surface.ts` consume the type).
|
|
22
22
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* `
|
|
30
|
-
* `assert_route_auth_acting_biconditional
|
|
23
|
+
* Every registry-time invariant is enforced at registration, inside the
|
|
24
|
+
* dispatcher loops every spec passes (`apply_route_specs` for route specs,
|
|
25
|
+
* `compile_action_registry` for `create_rpc_endpoint` and
|
|
26
|
+
* `register_action_ws`): the cross-axis invariants 1, 3, and 4 by
|
|
27
|
+
* `assert_route_auth_invariants`, which reads the auth shape alone, and
|
|
28
|
+
* invariant 2 (the `actor !== 'none' ⟺ input or query declares
|
|
29
|
+
* acting?: ActingActor` biconditional), which introspects the spec's
|
|
30
|
+
* input/query schemas, by `assert_route_auth_acting_biconditional`. Specs
|
|
31
|
+
* are plain objects that no registration path parses, so neither check
|
|
32
|
+
* can live only on a schema.
|
|
31
33
|
*
|
|
32
34
|
* @module
|
|
33
35
|
*/
|
|
34
36
|
import { z } from 'zod';
|
|
37
|
+
import { is_schema, parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
38
|
+
import { get_schema_entries } from '@fuzdev/fuz_schema/introspect.ts';
|
|
35
39
|
import { Uuid } from '../primitive_schemas.js';
|
|
40
|
+
import { ACTING_ACTOR_DESCRIPTION, ActingActor as ActingActorFuz } from '../primitive_schemas_fuz.js';
|
|
36
41
|
import { zod_unwrap_to_object } from '../zod.js';
|
|
37
42
|
/**
|
|
38
43
|
* `acting` field shared by every input that needs the caller's acting actor.
|
|
@@ -53,10 +58,11 @@ import { zod_unwrap_to_object } from '../zod.js';
|
|
|
53
58
|
* invariant 2: `auth.actor !== 'none'` ⟺ input (or query, on REST GETs)
|
|
54
59
|
* declares `acting?: ActingActor`. Keeping the contract in one module
|
|
55
60
|
* removes the http/ → auth/ import that an earlier split forced.
|
|
61
|
+
*
|
|
62
|
+
* A fuz_schema input declares the twin in `primitive_schemas_fuz.ts`, which
|
|
63
|
+
* the dispatcher finds the same way.
|
|
56
64
|
*/
|
|
57
|
-
export const ActingActor = Uuid.optional().meta({
|
|
58
|
-
description: 'Actor on the authenticated account that this request acts as. Omit on single-actor accounts; required on multi-actor.'
|
|
59
|
-
});
|
|
65
|
+
export const ActingActor = Uuid.optional().meta({ description: ACTING_ACTOR_DESCRIPTION });
|
|
60
66
|
/**
|
|
61
67
|
* Read an `acting` selector out of an unvalidated value.
|
|
62
68
|
*
|
|
@@ -77,12 +83,21 @@ export const ActingActor = Uuid.optional().meta({
|
|
|
77
83
|
* an input schema behind it, so there a malformed selector is final (the
|
|
78
84
|
* status route answers account-only).
|
|
79
85
|
*
|
|
86
|
+
* The grammar is the fuz_schema twin's, so the uppercase max UUID reads as a
|
|
87
|
+
* selector, as on the Rust spine; naming no actor, it is refused by the
|
|
88
|
+
* authorization phase before a Zod input schema would see it. Every other
|
|
89
|
+
* value reads as the Zod `ActingActor` would. The id comes back lowercased.
|
|
90
|
+
* A route declaring `acting` on its Zod `query` schema doesn't read it here:
|
|
91
|
+
* that schema runs ahead of the authorization phase and refuses the uppercase
|
|
92
|
+
* max with a 400, a declared gap against the Rust spine until those query
|
|
93
|
+
* schemas move to the twin.
|
|
94
|
+
*
|
|
80
95
|
* @param value - the raw `acting` field, from params / query / body
|
|
81
96
|
* @returns the actor id, or `undefined` when absent or malformed
|
|
82
97
|
*/
|
|
83
98
|
export const parse_acting = (value) => {
|
|
84
|
-
const parsed =
|
|
85
|
-
return parsed.
|
|
99
|
+
const parsed = parse(ActingActorFuz, value);
|
|
100
|
+
return parsed.ok ? parsed.value : undefined;
|
|
86
101
|
};
|
|
87
102
|
/**
|
|
88
103
|
* Per-axis auth state — names the dispatcher's behavior on `account` and
|
|
@@ -99,11 +114,51 @@ export const parse_acting = (value) => {
|
|
|
99
114
|
* without an actor binding).
|
|
100
115
|
*/
|
|
101
116
|
export const AuthAxisState = z.enum(['none', 'optional', 'required']);
|
|
117
|
+
/**
|
|
118
|
+
* The cross-axis invariants 1, 3, and 4 an auth shape breaks, in that order —
|
|
119
|
+
* the one implementation behind `assert_route_auth_invariants` and the
|
|
120
|
+
* `RouteAuth` schema's `.superRefine`.
|
|
121
|
+
*/
|
|
122
|
+
const route_auth_invariant_violations = (auth) => {
|
|
123
|
+
const violations = [];
|
|
124
|
+
// invariant 1: roles imply actor
|
|
125
|
+
if (auth.roles?.length && auth.actor !== 'required') {
|
|
126
|
+
violations.push({
|
|
127
|
+
path: 'roles',
|
|
128
|
+
message: "auth.roles requires auth.actor === 'required' (role checks read the actor's role_grants)"
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
// invariant 3: no accountless actors yet
|
|
132
|
+
if (auth.account === 'none' && auth.actor !== 'none') {
|
|
133
|
+
violations.push({
|
|
134
|
+
path: 'actor',
|
|
135
|
+
message: "auth.account === 'none' && auth.actor !== 'none' is not yet supported — accountless credentials (agent-token, group-actor) are out of scope for v1"
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
// invariant 4: unrestricted is leaf
|
|
139
|
+
if (auth.account === 'none' && auth.actor === 'none') {
|
|
140
|
+
if (auth.roles?.length) {
|
|
141
|
+
violations.push({
|
|
142
|
+
path: 'roles',
|
|
143
|
+
message: "unrestricted auth (account === 'none' && actor === 'none') cannot declare roles — nothing to gate"
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (auth.credential_types?.length) {
|
|
147
|
+
violations.push({
|
|
148
|
+
path: 'credential_types',
|
|
149
|
+
message: "unrestricted auth (account === 'none' && actor === 'none') cannot declare credential_types — nothing to gate"
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return violations;
|
|
154
|
+
};
|
|
102
155
|
/**
|
|
103
156
|
* The canonical auth shape used by both `ActionSpec.auth` and
|
|
104
157
|
* `RouteSpec.auth`.
|
|
105
158
|
*
|
|
106
|
-
* Cross-axis registry invariants
|
|
159
|
+
* Cross-axis registry invariants, checked at registration by
|
|
160
|
+
* `assert_route_auth_invariants` (and by this schema's `.superRefine`, the
|
|
161
|
+
* same check, when a caller parses an auth shape):
|
|
107
162
|
*
|
|
108
163
|
* 1. **Roles imply actor.** `roles?.length` ⟹ `actor === 'required'`.
|
|
109
164
|
* Role checks read the actor's role_grants, so a role-gated spec without
|
|
@@ -115,8 +170,7 @@ export const AuthAxisState = z.enum(['none', 'optional', 'required']);
|
|
|
115
170
|
* ⟹ no `roles`, no `credential_types` (nothing left to gate). The same
|
|
116
171
|
* rule covers `required_scope`, but enforcing it needs the capability
|
|
117
172
|
* vocabulary from `auth/`, so it lives with the other `required_scope`
|
|
118
|
-
* check in `fuz_auth_guard_resolver
|
|
119
|
-
* route spec traverses, since the route pipeline never parses this schema.
|
|
173
|
+
* check in `fuz_auth_guard_resolver`.
|
|
120
174
|
*
|
|
121
175
|
* Invariant 2 — the `actor !== 'none' ⟺ input or query declares
|
|
122
176
|
* acting?: ActingActor` biconditional — needs introspection of the
|
|
@@ -166,38 +220,8 @@ export const RouteAuth = z
|
|
|
166
220
|
required_scope: z.string().optional()
|
|
167
221
|
})
|
|
168
222
|
.superRefine((value, ctx) => {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
ctx.addIssue({
|
|
172
|
-
code: 'custom',
|
|
173
|
-
message: "auth.roles requires auth.actor === 'required' (role checks read the actor's role_grants)",
|
|
174
|
-
path: ['roles']
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
// invariant 3: no accountless actors yet
|
|
178
|
-
if (value.account === 'none' && value.actor !== 'none') {
|
|
179
|
-
ctx.addIssue({
|
|
180
|
-
code: 'custom',
|
|
181
|
-
message: "auth.account === 'none' && auth.actor !== 'none' is not yet supported — accountless credentials (agent-token, group-actor) are out of scope for v1",
|
|
182
|
-
path: ['actor']
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
// invariant 4: unrestricted is leaf
|
|
186
|
-
if (value.account === 'none' && value.actor === 'none') {
|
|
187
|
-
if (value.roles?.length) {
|
|
188
|
-
ctx.addIssue({
|
|
189
|
-
code: 'custom',
|
|
190
|
-
message: "unrestricted auth (account === 'none' && actor === 'none') cannot declare roles — nothing to gate",
|
|
191
|
-
path: ['roles']
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
if (value.credential_types?.length) {
|
|
195
|
-
ctx.addIssue({
|
|
196
|
-
code: 'custom',
|
|
197
|
-
message: "unrestricted auth (account === 'none' && actor === 'none') cannot declare credential_types — nothing to gate",
|
|
198
|
-
path: ['credential_types']
|
|
199
|
-
});
|
|
200
|
-
}
|
|
223
|
+
for (const { path, message } of route_auth_invariant_violations(value)) {
|
|
224
|
+
ctx.addIssue({ code: 'custom', message, path: [path] });
|
|
201
225
|
}
|
|
202
226
|
});
|
|
203
227
|
// --- Predicates over the flat-record shape ---
|
|
@@ -252,6 +276,24 @@ export const is_keeper_auth = (auth) => auth.credential_types?.includes('daemon_
|
|
|
252
276
|
* `is_credential_gated_auth` instead.
|
|
253
277
|
*/
|
|
254
278
|
export const is_plain_authenticated_auth = (auth) => auth.account === 'required' && !is_role_auth(auth) && !is_credential_gated_auth(auth);
|
|
279
|
+
/**
|
|
280
|
+
* Registry-time check of the cross-axis invariants 1, 3, and 4 (see
|
|
281
|
+
* `RouteAuth`). Throws on violation, naming every invariant the shape breaks.
|
|
282
|
+
*
|
|
283
|
+
* Called by every dispatcher registration loop (`apply_route_specs`,
|
|
284
|
+
* `compile_action_registry`) on every spec it accepts, so a spec that breaks
|
|
285
|
+
* one fails at assembly rather than at its first request.
|
|
286
|
+
*
|
|
287
|
+
* @param auth - the route/action's auth shape
|
|
288
|
+
* @param context - identifier for the throwing message (route key, RPC method, etc.)
|
|
289
|
+
* @throws Error when any cross-axis invariant is violated
|
|
290
|
+
*/
|
|
291
|
+
export const assert_route_auth_invariants = (auth, context) => {
|
|
292
|
+
const violations = route_auth_invariant_violations(auth);
|
|
293
|
+
if (violations.length === 0)
|
|
294
|
+
return;
|
|
295
|
+
throw new Error(`${context}: ${violations.map((v) => v.message).join('; ')} (registry-time invariants)`);
|
|
296
|
+
};
|
|
255
297
|
// --- Registry-time invariant 2 enforcement ---
|
|
256
298
|
//
|
|
257
299
|
// The biconditional `auth.actor !== 'none' ⟺ input (or query, on REST
|
|
@@ -263,16 +305,26 @@ export const is_plain_authenticated_auth = (auth) => auth.account === 'required'
|
|
|
263
305
|
// `create_rpc_endpoint` + `register_action_ws`).
|
|
264
306
|
/**
|
|
265
307
|
* Whether a schema declares the canonical `acting?: ActingActor` field.
|
|
266
|
-
* Reference-equality on the exported `ActingActor` schema
|
|
267
|
-
*
|
|
308
|
+
* Reference-equality on the exported `ActingActor` schema of the input's
|
|
309
|
+
* library — the Zod one here, the fuz_schema twin in
|
|
310
|
+
* `primitive_schemas_fuz.ts` — so consumer schemas with unrelated `acting`
|
|
311
|
+
* fields don't trip this check, nor does either twin in the other library's
|
|
312
|
+
* object.
|
|
268
313
|
*
|
|
269
314
|
* Peels through Zod wrappers (`optional`, `nullable`, `default`,
|
|
270
315
|
* `transform`, `pipe`, `prefault`) via `zod_unwrap_to_object` so a spec
|
|
271
316
|
* authored as `z.optional(z.strictObject({acting: ActingActor}))` or
|
|
272
317
|
* `z.strictObject({acting: ActingActor}).default({})` still trips the
|
|
273
318
|
* predicate.
|
|
319
|
+
*
|
|
320
|
+
* A `@fuzdev/fuz_schema` schema is read by `get_schema_entries`, which sees
|
|
321
|
+
* through its wrappers (`optional`, `nullable`, the defaults) and a `pipe` to
|
|
322
|
+
* the schema it starts with; a schema that isn't an object under them (a void
|
|
323
|
+
* input, say) answers `false`.
|
|
274
324
|
*/
|
|
275
325
|
export const input_schema_declares_acting = (schema) => {
|
|
326
|
+
if (is_schema(schema))
|
|
327
|
+
return get_schema_entries(schema)?.acting === ActingActorFuz;
|
|
276
328
|
const obj = zod_unwrap_to_object(schema);
|
|
277
329
|
if (!obj)
|
|
278
330
|
return false;
|
|
@@ -305,7 +357,7 @@ export const assert_route_auth_acting_biconditional = (auth, slots, context) =>
|
|
|
305
357
|
return;
|
|
306
358
|
const slot_phrase = slots.query !== undefined ? 'input or query schema' : 'input schema';
|
|
307
359
|
if (wants_actor) {
|
|
308
|
-
throw new Error(`${context}: auth.actor === '${auth.actor}' requires the ${slot_phrase} to declare 'acting?: ActingActor' (registry-time invariant 2)`);
|
|
360
|
+
throw new Error(`${context}: auth.actor === '${auth.actor}' requires the ${slot_phrase} to declare 'acting?: ActingActor', the Zod one or its fuz_schema twin (registry-time invariant 2)`);
|
|
309
361
|
}
|
|
310
|
-
throw new Error(`${context}: ${slot_phrase} declares 'acting?: ActingActor' but auth.actor === 'none' (registry-time invariant 2)`);
|
|
362
|
+
throw new Error(`${context}: ${slot_phrase} declares 'acting?: ActingActor' (Zod or fuz_schema) but auth.actor === 'none' (registry-time invariant 2)`);
|
|
311
363
|
};
|
|
@@ -175,8 +175,8 @@ export type ApiError = z.infer<typeof ApiError>;
|
|
|
175
175
|
* parsing, or when the request body is not valid JSON.
|
|
176
176
|
*
|
|
177
177
|
* `error` is one of the four validation codes the framework emits.
|
|
178
|
-
* `issues` carries
|
|
179
|
-
* three schema-failure cases (`invalid_request_body`,
|
|
178
|
+
* `issues` carries the validation issues as `WireIssue`s, whichever schema
|
|
179
|
+
* library refused, for diagnostic display on the three schema-failure cases (`invalid_request_body`,
|
|
180
180
|
* `invalid_route_params`, `invalid_query_params`). The field is optional:
|
|
181
181
|
* the `invalid_json_body` case (request body parse failure or non-object
|
|
182
182
|
* root) emits no `issues`, and the schema-failure cases emit them only in
|
|
@@ -191,9 +191,11 @@ export declare const ValidationError: z.ZodObject<{
|
|
|
191
191
|
invalid_query_params: "invalid_query_params";
|
|
192
192
|
}>;
|
|
193
193
|
issues: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
194
|
-
|
|
195
|
-
message: z.ZodString;
|
|
194
|
+
kind: z.ZodString;
|
|
196
195
|
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
196
|
+
expected: z.ZodString;
|
|
197
|
+
received: z.ZodString;
|
|
198
|
+
message: z.ZodString;
|
|
197
199
|
}, z.core.$loose>>>;
|
|
198
200
|
}, z.core.$loose>;
|
|
199
201
|
export type ValidationError = z.infer<typeof ValidationError>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error_schemas.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/error_schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"error_schemas.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/error_schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAK9D,0CAA0C;AAC1C,eAAO,MAAM,0BAA0B,EAAG,sBAA+B,CAAC;AAE1E,uDAAuD;AACvD,eAAO,MAAM,uBAAuB,EAAG,mBAA4B,CAAC;AAEpE,6CAA6C;AAC7C,eAAO,MAAM,0BAA0B,EAAG,sBAA+B,CAAC;AAE1E,8CAA8C;AAC9C,eAAO,MAAM,0BAA0B,EAAG,sBAA+B,CAAC;AAE1E;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAG,kBAA2B,CAAC;AAIlE,wCAAwC;AACxC,eAAO,MAAM,6BAA6B,EAAG,yBAAkC,CAAC;AAEhF,+CAA+C;AAC/C,eAAO,MAAM,8BAA8B,EAAG,0BAAmC,CAAC;AAEl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AAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEpE,eAAO,MAAM,sBAAsB;;iBAEjC,CAAC;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE5E,eAAO,MAAM,sBAAsB;;iBAEjC,CAAC;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE5E,eAAO,MAAM,oBAAoB;;iBAE/B,CAAC;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAExE;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;AAEnE;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY;;;;EAAoC,CAAC;AAC9D,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,yBAAyB;IACzC,IAAI,EAAE,SAAS,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,eAAO,MAAM,oBAAoB,GAAI,6EAOlC,yBAAyB,KAAG,iBA8C9B,CAAC"}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { z } from 'zod';
|
|
15
15
|
import { needs_actor } from './auth_shape.js';
|
|
16
|
+
import { WireIssue } from '../schema_issues.js';
|
|
16
17
|
// --- Core: Validation (auto-derived by route spec middleware) ---
|
|
17
18
|
/** Request body failed Zod validation. */
|
|
18
19
|
export const ERROR_INVALID_REQUEST_BODY = 'invalid_request_body';
|
|
@@ -186,8 +187,8 @@ export const ApiError = z.looseObject({ error: z.string() });
|
|
|
186
187
|
* parsing, or when the request body is not valid JSON.
|
|
187
188
|
*
|
|
188
189
|
* `error` is one of the four validation codes the framework emits.
|
|
189
|
-
* `issues` carries
|
|
190
|
-
* three schema-failure cases (`invalid_request_body`,
|
|
190
|
+
* `issues` carries the validation issues as `WireIssue`s, whichever schema
|
|
191
|
+
* library refused, for diagnostic display on the three schema-failure cases (`invalid_request_body`,
|
|
191
192
|
* `invalid_route_params`, `invalid_query_params`). The field is optional:
|
|
192
193
|
* the `invalid_json_body` case (request body parse failure or non-object
|
|
193
194
|
* root) emits no `issues`, and the schema-failure cases emit them only in
|
|
@@ -201,13 +202,7 @@ export const ValidationError = z.looseObject({
|
|
|
201
202
|
ERROR_INVALID_ROUTE_PARAMS,
|
|
202
203
|
ERROR_INVALID_QUERY_PARAMS
|
|
203
204
|
]),
|
|
204
|
-
issues: z
|
|
205
|
-
.array(z.looseObject({
|
|
206
|
-
code: z.string(),
|
|
207
|
-
message: z.string(),
|
|
208
|
-
path: z.array(z.union([z.string(), z.number()]))
|
|
209
|
-
}))
|
|
210
|
-
.optional()
|
|
205
|
+
issues: z.array(WireIssue).optional()
|
|
211
206
|
});
|
|
212
207
|
/**
|
|
213
208
|
* Permission error — returned by `require_role()` and the dispatcher's
|
|
@@ -37,13 +37,14 @@ export type JsonrpcErrorName = 'parse_error' | 'invalid_request' | 'method_not_f
|
|
|
37
37
|
*/
|
|
38
38
|
export declare const JSONRPC_ERROR_CODES: Readonly<Record<JsonrpcErrorName, JsonrpcErrorCode>>;
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
41
|
-
* `JSON.stringify` drops the field from the
|
|
40
|
+
* Call `get` and return its value in development, return `undefined` in
|
|
41
|
+
* production without calling it — so `JSON.stringify` drops the field from the
|
|
42
|
+
* response, and production pays nothing to build it.
|
|
42
43
|
*
|
|
43
44
|
* The single gate for keeping internal diagnostic detail out of production
|
|
44
45
|
* error responses. Two classes flow through it:
|
|
45
46
|
*
|
|
46
|
-
* - **
|
|
47
|
+
* - **Validation `issues`** — the issues array exposes field names, types, and
|
|
47
48
|
* constraints, enough to reverse-engineer an input schema (including on
|
|
48
49
|
* public/unauthenticated actions). Gate the whole `data` object on JSON-RPC
|
|
49
50
|
* errors (so `error.data` is absent, matching the Rust spine) and the
|
|
@@ -54,9 +55,15 @@ export declare const JSONRPC_ERROR_CODES: Readonly<Record<JsonrpcErrorName, Json
|
|
|
54
55
|
*
|
|
55
56
|
* A legitimate caller only ever needs the error code and a stable message.
|
|
56
57
|
*
|
|
58
|
+
* A thunk rather than a value because the detail costs work to build — mapping
|
|
59
|
+
* a failed parse's issues walks the input — and a caller must not be able to
|
|
60
|
+
* make production pay for, or trip on, that work.
|
|
61
|
+
*
|
|
62
|
+
* @param get - builds the diagnostic detail, called only in development
|
|
63
|
+
* @returns the detail in development, `undefined` in production
|
|
57
64
|
* @nodocs
|
|
58
65
|
*/
|
|
59
|
-
export declare const dev_only: <T>(
|
|
66
|
+
export declare const dev_only: <T>(get: () => T) => T | undefined;
|
|
60
67
|
/**
|
|
61
68
|
* Named constructors for `JsonrpcErrorObject` values.
|
|
62
69
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonrpc_errors.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/jsonrpc_errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAEnE,OAAO,EASN,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,MAAM,cAAc,CAAC;AAEtB,0CAA0C;AAC1C,eAAO,MAAM,qBAAqB,kBAAkB,CAAC;AAErD,sEAAsE;AACtE,MAAM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,MAAM,KAAG,gBACa,CAAC;AAEjF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,0BAA0B,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAMjF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,GAAI,MAAM,gBAAgB,KAAG,gBACL,CAAC"}
|
|
@@ -79,13 +79,14 @@ export const JSONRPC_ERROR_CODES = Object.freeze({
|
|
|
79
79
|
request_cancelled: -32010
|
|
80
80
|
});
|
|
81
81
|
/**
|
|
82
|
-
*
|
|
83
|
-
* `JSON.stringify` drops the field from the
|
|
82
|
+
* Call `get` and return its value in development, return `undefined` in
|
|
83
|
+
* production without calling it — so `JSON.stringify` drops the field from the
|
|
84
|
+
* response, and production pays nothing to build it.
|
|
84
85
|
*
|
|
85
86
|
* The single gate for keeping internal diagnostic detail out of production
|
|
86
87
|
* error responses. Two classes flow through it:
|
|
87
88
|
*
|
|
88
|
-
* - **
|
|
89
|
+
* - **Validation `issues`** — the issues array exposes field names, types, and
|
|
89
90
|
* constraints, enough to reverse-engineer an input schema (including on
|
|
90
91
|
* public/unauthenticated actions). Gate the whole `data` object on JSON-RPC
|
|
91
92
|
* errors (so `error.data` is absent, matching the Rust spine) and the
|
|
@@ -96,9 +97,15 @@ export const JSONRPC_ERROR_CODES = Object.freeze({
|
|
|
96
97
|
*
|
|
97
98
|
* A legitimate caller only ever needs the error code and a stable message.
|
|
98
99
|
*
|
|
100
|
+
* A thunk rather than a value because the detail costs work to build — mapping
|
|
101
|
+
* a failed parse's issues walks the input — and a caller must not be able to
|
|
102
|
+
* make production pay for, or trip on, that work.
|
|
103
|
+
*
|
|
104
|
+
* @param get - builds the diagnostic detail, called only in development
|
|
105
|
+
* @returns the detail in development, `undefined` in production
|
|
99
106
|
* @nodocs
|
|
100
107
|
*/
|
|
101
|
-
export const dev_only = (
|
|
108
|
+
export const dev_only = (get) => (DEV ? get() : undefined);
|
|
102
109
|
/**
|
|
103
110
|
* Named constructors for `JsonrpcErrorObject` values.
|
|
104
111
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonrpc_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/jsonrpc_helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EACN,cAAc,EACd,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,aAAa,EAElB,eAAe,EACf,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"jsonrpc_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/jsonrpc_helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EACN,cAAc,EACd,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,aAAa,EAElB,eAAe,EACf,MAAM,cAAc,CAAC;AAWtB,0CAA0C;AAC1C,eAAO,MAAM,sBAAsB,GAClC,QAAQ,aAAa,EACrB,QAAQ,oBAAoB,GAAG,SAAS,EACxC,IAAI,gBAAgB,KAClB,cAUF,CAAC;AAEF,mDAAmD;AACnD,eAAO,MAAM,uBAAuB,GACnC,IAAI,gBAAgB,EACpB,QAAQ,aAAa,KACnB,eAID,CAAC;AAEH,6EAA6E;AAC7E,eAAO,MAAM,2BAA2B,GACvC,QAAQ,aAAa,EACrB,QAAQ,yBAAyB,GAAG,SAAS,KAC3C,mBASF,CAAC;AAEF,iDAAiD;AACjD,eAAO,MAAM,6BAA6B,GACzC,IAAI,oBAAoB,CAAC,IAAI,CAAC,EA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AAC,QAAQ,EAAE,eAAe,GAAG,oBAAoB,CAAA;CAAE,GACtE;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,EAAE,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,wBAAwB,GAAI,MAAM,OAAO,KAAG,wBAqCxD,CAAC"}
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import { DEV } from 'esm-env';
|
|
11
11
|
import { JsonrpcRequest, JSONRPC_VERSION } from './jsonrpc.js';
|
|
12
12
|
import { JSONRPC_ERROR_CODES, dev_only, jsonrpc_error_messages, to_thrown_jsonrpc_error } from './jsonrpc_errors.js';
|
|
13
|
+
import { to_wire_issues } from '../schema_issues.js';
|
|
13
14
|
// --- Message builders ---
|
|
14
15
|
/** Creates a JSON-RPC request message. */
|
|
15
16
|
export const create_jsonrpc_request = (method, params, id) => {
|
|
@@ -177,7 +178,7 @@ export const classify_jsonrpc_message = (json) => {
|
|
|
177
178
|
return {
|
|
178
179
|
kind: 'invalid',
|
|
179
180
|
id,
|
|
180
|
-
error: jsonrpc_error_messages.invalid_request(dev_only({ issues: parsed.error.issues }))
|
|
181
|
+
error: jsonrpc_error_messages.invalid_request(dev_only(() => ({ issues: to_wire_issues(parsed.error.issues, frame) })))
|
|
181
182
|
};
|
|
182
183
|
}
|
|
183
184
|
// the frame itself, validated — not Zod's rebuilt copy, which drops an own
|
|
@@ -280,7 +280,8 @@ export declare const apply_middleware_specs: (app: Hono, specs: Array<Middleware
|
|
|
280
280
|
* - `pending_effects`: eager fire-and-forget pool-write queue
|
|
281
281
|
* - `post_commit_effects`: deferred-thunk queue (push via `emit_after_commit`)
|
|
282
282
|
*
|
|
283
|
-
* Also enforces registry-time
|
|
283
|
+
* Also enforces the auth shape's registry-time invariants: the cross-axis
|
|
284
|
+
* invariants 1, 3, and 4 (`assert_route_auth_invariants`), and invariant 2:
|
|
284
285
|
* `auth.actor !== 'none' ⟺ input or query declares acting?: ActingActor`.
|
|
285
286
|
* REST is bi-located (GETs declare `acting` on `query`, mutations on
|
|
286
287
|
* `input`), so the check passes both slots; the action-dispatcher
|
|
@@ -291,7 +292,7 @@ export declare const apply_middleware_specs: (app: Hono, specs: Array<Middleware
|
|
|
291
292
|
* @param authorize - optional authorization phase; runs after the pre-authorization guards and before the post-authorization guards
|
|
292
293
|
* @param db - used for transaction wrapping and `RouteContext`
|
|
293
294
|
* @mutates `app`
|
|
294
|
-
* @throws Error if two specs share the same `method` + `path` (each combination must be unique), or if any spec violates the actor-acting biconditional
|
|
295
|
+
* @throws Error if two specs share the same `method` + `path` (each combination must be unique), or if any spec violates a cross-axis auth invariant or the actor-acting biconditional
|
|
295
296
|
*/
|
|
296
297
|
export declare const apply_route_specs: (app: Hono, specs: Array<RouteSpec>, resolve_auth_guards: AuthGuardResolver, log: Logger, db: Db, authorize?: AuthorizationHandler) => void;
|
|
297
298
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route_spec.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/route_spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAW,IAAI,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AACtE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,EACN,KAAK,iBAAiB,EACtB,KAAK,YAAY,EAOjB,MAAM,oBAAoB,CAAC;AAW5B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,
|
|
1
|
+
{"version":3,"file":"route_spec.d.ts","sourceRoot":"../src/lib/","sources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CAAC,GAAG,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC;AAK5D;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACzF,wBAAgB,gBAAgB,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC;AAK7D;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACxF,wBAAgB,eAAe,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC;AAsM5D;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,KAAK,IAAI,EAAE,OAAO,KAAK,CAAC,cAAc,CAAC,KAAG,IAIhF,CAAC;AAsGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,iBAAiB,GAC7B,KAAK,IAAI,EACT,OAAO,KAAK,CAAC,SAAS,CAAC,EACvB,qBAAqB,iBAAiB,EACtC,KAAK,MAAM,EACX,IAAI,EAAE,EACN,YAAY,oBAAoB,KAC9B,IAuEF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ,MAAM,EAAE,OAAO,KAAK,CAAC,SAAS,CAAC,KAAG,KAAK,CAAC,SAAS,CAK3F,CAAC"}
|
package/dist/http/route_spec.js
CHANGED
|
@@ -19,7 +19,8 @@ import { is_post_content_type_refused } from './simple_request.js';
|
|
|
19
19
|
import { jsonrpc_error_code_to_http_status, jsonrpc_error_code_to_name, dev_only, to_thrown_jsonrpc_error } from './jsonrpc_errors.js';
|
|
20
20
|
import { is_null_schema, merge_error_schemas } from './schema_helpers.js';
|
|
21
21
|
import { dispatch_with_post_commit_rollback } from './pending_effects.js';
|
|
22
|
-
import { assert_route_auth_acting_biconditional } from './auth_shape.js';
|
|
22
|
+
import { assert_route_auth_acting_biconditional, assert_route_auth_invariants } from './auth_shape.js';
|
|
23
|
+
import { to_wire_issues } from '../schema_issues.js';
|
|
23
24
|
export function get_route_input(c, _schema) {
|
|
24
25
|
return c.get('validated_input');
|
|
25
26
|
}
|
|
@@ -84,7 +85,10 @@ const create_input_validation = (input_schema, method) => {
|
|
|
84
85
|
}
|
|
85
86
|
const result = input_schema.safeParse(body);
|
|
86
87
|
if (!result.success) {
|
|
87
|
-
return c.json({
|
|
88
|
+
return c.json({
|
|
89
|
+
error: ERROR_INVALID_REQUEST_BODY,
|
|
90
|
+
issues: dev_only(() => to_wire_issues(result.error.issues, body))
|
|
91
|
+
}, 400);
|
|
88
92
|
}
|
|
89
93
|
c.set('validated_input', result.data);
|
|
90
94
|
await next();
|
|
@@ -107,7 +111,10 @@ const create_params_validation = (params_schema) => {
|
|
|
107
111
|
const raw_params = c.req.param();
|
|
108
112
|
const result = params_schema.safeParse(raw_params);
|
|
109
113
|
if (!result.success) {
|
|
110
|
-
return c.json({
|
|
114
|
+
return c.json({
|
|
115
|
+
error: ERROR_INVALID_ROUTE_PARAMS,
|
|
116
|
+
issues: dev_only(() => to_wire_issues(result.error.issues, raw_params))
|
|
117
|
+
}, 400);
|
|
111
118
|
}
|
|
112
119
|
c.set('validated_params', result.data);
|
|
113
120
|
await next();
|
|
@@ -130,7 +137,10 @@ const create_query_validation = (query_schema) => {
|
|
|
130
137
|
const raw_query = c.req.query();
|
|
131
138
|
const result = query_schema.safeParse(raw_query);
|
|
132
139
|
if (!result.success) {
|
|
133
|
-
return c.json({
|
|
140
|
+
return c.json({
|
|
141
|
+
error: ERROR_INVALID_QUERY_PARAMS,
|
|
142
|
+
issues: dev_only(() => to_wire_issues(result.error.issues, raw_query))
|
|
143
|
+
}, 400);
|
|
134
144
|
}
|
|
135
145
|
c.set('validated_query', result.data);
|
|
136
146
|
await next();
|
|
@@ -260,11 +270,11 @@ const wrap_error_catch = (handler, log) => {
|
|
|
260
270
|
}
|
|
261
271
|
// generic error — internal_error. Raw exception messages can leak
|
|
262
272
|
// internals; surface them only in development (same gate as the
|
|
263
|
-
//
|
|
273
|
+
// validation-issue redaction), production gets the bare error code.
|
|
264
274
|
log.error('Unhandled handler error', err);
|
|
265
275
|
const body = {
|
|
266
276
|
error: 'internal_error',
|
|
267
|
-
message: dev_only(err instanceof Error ? err.message : undefined)
|
|
277
|
+
message: dev_only(() => (err instanceof Error ? err.message : undefined))
|
|
268
278
|
};
|
|
269
279
|
return c.json(body, 500);
|
|
270
280
|
}
|
|
@@ -333,7 +343,8 @@ const build_rest_error_body = (err) => {
|
|
|
333
343
|
* - `pending_effects`: eager fire-and-forget pool-write queue
|
|
334
344
|
* - `post_commit_effects`: deferred-thunk queue (push via `emit_after_commit`)
|
|
335
345
|
*
|
|
336
|
-
* Also enforces registry-time
|
|
346
|
+
* Also enforces the auth shape's registry-time invariants: the cross-axis
|
|
347
|
+
* invariants 1, 3, and 4 (`assert_route_auth_invariants`), and invariant 2:
|
|
337
348
|
* `auth.actor !== 'none' ⟺ input or query declares acting?: ActingActor`.
|
|
338
349
|
* REST is bi-located (GETs declare `acting` on `query`, mutations on
|
|
339
350
|
* `input`), so the check passes both slots; the action-dispatcher
|
|
@@ -344,7 +355,7 @@ const build_rest_error_body = (err) => {
|
|
|
344
355
|
* @param authorize - optional authorization phase; runs after the pre-authorization guards and before the post-authorization guards
|
|
345
356
|
* @param db - used for transaction wrapping and `RouteContext`
|
|
346
357
|
* @mutates `app`
|
|
347
|
-
* @throws Error if two specs share the same `method` + `path` (each combination must be unique), or if any spec violates the actor-acting biconditional
|
|
358
|
+
* @throws Error if two specs share the same `method` + `path` (each combination must be unique), or if any spec violates a cross-axis auth invariant or the actor-acting biconditional
|
|
348
359
|
*/
|
|
349
360
|
export const apply_route_specs = (app, specs, resolve_auth_guards, log, db, authorize) => {
|
|
350
361
|
const registered = new Set();
|
|
@@ -354,6 +365,7 @@ export const apply_route_specs = (app, specs, resolve_auth_guards, log, db, auth
|
|
|
354
365
|
throw new Error(`Duplicate route: ${route_key} — each method+path combination must be unique`);
|
|
355
366
|
}
|
|
356
367
|
registered.add(route_key);
|
|
368
|
+
assert_route_auth_invariants(spec.auth, `Route "${route_key}"`);
|
|
357
369
|
assert_route_auth_acting_biconditional(spec.auth, { input: spec.input, query: spec.query }, `Route "${route_key}"`);
|
|
358
370
|
const { pre_authorization: pre_authorization_guards, post_authorization: post_authorization_guards } = resolve_auth_guards(spec.auth);
|
|
359
371
|
const content_type_check = create_content_type_check(spec);
|