@fuzdev/fuz_app 0.165.0 → 0.167.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 +3 -3
- package/dist/actions/action_codegen.d.ts +10 -1
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +17 -8
- package/dist/actions/action_event_data.d.ts +1 -1
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +24 -15
- package/dist/actions/action_spec.d.ts +2 -2
- package/dist/actions/perform_action.d.ts +2 -1
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/auth/CLAUDE.md +10 -8
- package/dist/auth/account_action_specs.d.ts +8 -8
- package/dist/auth/account_route_schema.d.ts +197 -164
- package/dist/auth/account_route_schema.d.ts.map +1 -1
- package/dist/auth/account_route_schema.js +19 -17
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +285 -294
- package/dist/auth/admin_action_specs.d.ts +64 -64
- package/dist/auth/audit_log_route_schema.d.ts +16 -8
- package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_route_schema.js +4 -3
- package/dist/auth/audit_log_routes.d.ts +1 -1
- package/dist/auth/audit_log_routes.d.ts.map +1 -1
- package/dist/auth/audit_log_routes.js +112 -111
- package/dist/auth/audit_log_schema.d.ts +22 -22
- package/dist/auth/bootstrap_route_schema.d.ts +46 -69
- package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
- package/dist/auth/bootstrap_route_schema.js +8 -7
- package/dist/auth/bootstrap_routes.d.ts.map +1 -1
- package/dist/auth/bootstrap_routes.js +100 -98
- package/dist/auth/cell_action_specs.d.ts +6092 -1092
- package/dist/auth/cell_action_specs.d.ts.map +1 -1
- package/dist/auth/cell_action_specs.js +96 -97
- package/dist/auth/cell_actions.d.ts.map +1 -1
- package/dist/auth/cell_actions.js +1 -0
- package/dist/auth/cell_audit_action_specs.d.ts +301 -69
- package/dist/auth/cell_audit_action_specs.d.ts.map +1 -1
- package/dist/auth/cell_audit_action_specs.js +21 -16
- package/dist/auth/cell_audit_actions.js +2 -2
- package/dist/auth/cell_audit_events.d.ts +2 -2
- package/dist/auth/cell_audit_events.d.ts.map +1 -1
- package/dist/auth/cell_audit_metadata.d.ts +93 -30
- package/dist/auth/cell_audit_metadata.d.ts.map +1 -1
- package/dist/auth/cell_audit_metadata.js +15 -14
- package/dist/auth/cell_authorize.d.ts +3 -3
- package/dist/auth/cell_authorize.js +3 -3
- package/dist/auth/cell_data_schema.d.ts +17 -9
- package/dist/auth/cell_data_schema.d.ts.map +1 -1
- package/dist/auth/cell_data_schema.js +9 -7
- package/dist/auth/cell_field_action_specs.d.ts +697 -130
- package/dist/auth/cell_field_action_specs.d.ts.map +1 -1
- package/dist/auth/cell_field_action_specs.js +25 -27
- package/dist/auth/cell_field_actions.d.ts.map +1 -1
- package/dist/auth/cell_field_actions.js +2 -0
- package/dist/auth/cell_field_audit_metadata.d.ts +49 -13
- package/dist/auth/cell_field_audit_metadata.d.ts.map +1 -1
- package/dist/auth/cell_field_audit_metadata.js +6 -6
- package/dist/auth/cell_grant_action_specs.d.ts +1044 -208
- package/dist/auth/cell_grant_action_specs.d.ts.map +1 -1
- package/dist/auth/cell_grant_action_specs.js +36 -33
- package/dist/auth/cell_grant_actions.js +2 -2
- package/dist/auth/cell_grant_audit_metadata.d.ts +188 -40
- package/dist/auth/cell_grant_audit_metadata.d.ts.map +1 -1
- package/dist/auth/cell_grant_audit_metadata.js +12 -11
- package/dist/auth/cell_item_action_specs.d.ts +949 -175
- package/dist/auth/cell_item_action_specs.d.ts.map +1 -1
- package/dist/auth/cell_item_action_specs.js +30 -34
- package/dist/auth/cell_item_actions.js +1 -1
- package/dist/auth/cell_item_audit_metadata.d.ts +68 -19
- package/dist/auth/cell_item_audit_metadata.d.ts.map +1 -1
- package/dist/auth/cell_item_audit_metadata.js +9 -9
- package/dist/auth/cell_relation_list_limit.d.ts +1 -2
- package/dist/auth/cell_relation_list_limit.d.ts.map +1 -1
- package/dist/auth/cell_relation_list_limit.js +3 -8
- package/dist/auth/role_grant_offer_action_specs.d.ts +4 -4
- package/dist/auth/signup_route_schema.d.ts +9 -4
- package/dist/auth/signup_route_schema.d.ts.map +1 -1
- package/dist/auth/signup_route_schema.js +5 -3
- package/dist/auth/signup_routes.d.ts.map +1 -1
- package/dist/auth/signup_routes.js +170 -170
- package/dist/db/cell_moderation.d.ts +6 -7
- package/dist/db/cell_moderation.d.ts.map +1 -1
- package/dist/db/cell_moderation.js +6 -7
- package/dist/http/CLAUDE.md +48 -3
- package/dist/http/common_routes.d.ts +1 -1
- package/dist/http/common_routes.d.ts.map +1 -1
- package/dist/http/common_routes.js +13 -11
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +25 -28
- package/dist/http/error_schemas.d.ts +5 -1
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +5 -1
- package/dist/http/route_result.d.ts +101 -0
- package/dist/http/route_result.d.ts.map +1 -0
- package/dist/http/route_result.js +56 -0
- package/dist/http/route_spec.d.ts +110 -6
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +82 -14
- package/dist/rate_limiter.d.ts +0 -9
- package/dist/rate_limiter.d.ts.map +1 -1
- package/dist/rate_limiter.js +0 -15
- package/dist/server/serve_fact_route.d.ts.map +1 -1
- package/dist/server/serve_fact_route.js +23 -21
- package/dist/server/surface_route.d.ts +1 -1
- package/dist/server/surface_route.d.ts.map +1 -1
- package/dist/server/surface_route.js +4 -2
- package/dist/testing/CLAUDE.md +5 -3
- package/dist/testing/adversarial_404.d.ts.map +1 -1
- package/dist/testing/adversarial_404.js +12 -7
- package/dist/testing/cross_backend/cell_crud.js +2 -2
- package/dist/testing/cross_backend/cell_relations.js +2 -2
- package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
- package/dist/testing/cross_backend/login_security.js +3 -2
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.js +2 -6
- package/dist/testing/stubs.d.ts +14 -3
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +21 -6
- package/package.json +1 -1
package/dist/http/route_spec.js
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Routes are defined as data (method, path, auth, input/output schemas, handler),
|
|
5
5
|
* then applied to Hono. The attack surface is generated from the specs —
|
|
6
|
-
* always accurate, always complete.
|
|
6
|
+
* always accurate, always complete. A handler returns a result
|
|
7
|
+
* (`http/route_result.ts`) and `apply_route_specs` builds the response; a spec
|
|
8
|
+
* is made by `define_route` (or `define_route_shape` + `attach_route_handler`),
|
|
9
|
+
* which checks the handler's results against the route.
|
|
7
10
|
*
|
|
8
11
|
* Input/output schemas align with SAES `ActionSpec` conventions, and each is
|
|
9
12
|
* a Zod or `@fuzdev/fuz_schema` schema (`ValidationSchema`):
|
|
@@ -26,6 +29,66 @@ import { is_json_response } from './route_error_check.js';
|
|
|
26
29
|
import { dispatch_with_post_commit_rollback } from './pending_effects.js';
|
|
27
30
|
import { assert_route_auth_acting_biconditional, assert_route_auth_invariants } from './auth_shape.js';
|
|
28
31
|
import { assert_validation_schema, parse_any, to_wire_issues } from '../schema_issues.js';
|
|
32
|
+
/**
|
|
33
|
+
* Define a route: its handler is checked against the route's `output`,
|
|
34
|
+
* `errors`, `auth`, and `rate_limit` (`TypedRouteHandler`), and the spec is
|
|
35
|
+
* returned as it is, typed as a `RouteSpec`.
|
|
36
|
+
*
|
|
37
|
+
* A literal `errors` list is read as given; a list typed
|
|
38
|
+
* `Array<RestErrorDef>` is refused (`KnownRouteErrors`).
|
|
39
|
+
*
|
|
40
|
+
* @param spec - the route, its handler returning `route_ok`, `route_fail`, or `route_raw`
|
|
41
|
+
* @returns `spec`
|
|
42
|
+
*/
|
|
43
|
+
// @__NO_SIDE_EFFECTS__
|
|
44
|
+
export const define_route = (spec) => spec;
|
|
45
|
+
/**
|
|
46
|
+
* Define a route minus its handler, keeping the types `attach_route_handler`
|
|
47
|
+
* checks its handler against.
|
|
48
|
+
*
|
|
49
|
+
* @param shape - the route without `handler`
|
|
50
|
+
* @returns `shape`
|
|
51
|
+
*/
|
|
52
|
+
// @__NO_SIDE_EFFECTS__
|
|
53
|
+
export const define_route_shape = (shape) => shape;
|
|
54
|
+
/**
|
|
55
|
+
* Attach a handler to a route shape (`define_route_shape`), checked as
|
|
56
|
+
* `define_route` checks one.
|
|
57
|
+
*
|
|
58
|
+
* @param shape - the route without `handler`
|
|
59
|
+
* @param handler - the handler, returning `route_ok`, `route_fail`, or `route_raw`
|
|
60
|
+
* @returns a new spec, `shape` with `handler`
|
|
61
|
+
*/
|
|
62
|
+
// @__NO_SIDE_EFFECTS__
|
|
63
|
+
export const attach_route_handler = (shape, handler) => ({ ...shape, handler });
|
|
64
|
+
/**
|
|
65
|
+
* Build the response for a handler's result: a success as JSON at 200, a
|
|
66
|
+
* failure as its body at its definition's status with the headers the
|
|
67
|
+
* definition derives (`Retry-After`), a raw result as it is. Headers and
|
|
68
|
+
* cookies set on `c` before carry over, as Hono builds the response from `c`.
|
|
69
|
+
*
|
|
70
|
+
* @param c - the Hono context
|
|
71
|
+
* @param result - the handler's result
|
|
72
|
+
* @throws TypeError when `result` is not a result `route_ok`, `route_fail`, or `route_raw` made: a `Response`, a success without a value, a failure without its status or definition, a raw result without a response, `undefined` or `null`
|
|
73
|
+
*/
|
|
74
|
+
export const to_route_response = (c, result) => {
|
|
75
|
+
// each branch checks the field it reads, so a malformed or nullish result
|
|
76
|
+
// falls through to the throw — a `Response` has its own `ok` and `status`,
|
|
77
|
+
// but no `value` or `def`
|
|
78
|
+
if (result?.ok === true) {
|
|
79
|
+
if (result.value !== undefined)
|
|
80
|
+
return c.json(result.value);
|
|
81
|
+
}
|
|
82
|
+
else if (result?.ok === 'raw') {
|
|
83
|
+
if (result.response instanceof Response)
|
|
84
|
+
return result.response;
|
|
85
|
+
}
|
|
86
|
+
else if (!result?.ok && result?.def !== undefined && typeof result.status === 'number') {
|
|
87
|
+
const body = result.body;
|
|
88
|
+
return c.json(body, result.status, result.def.headers?.(body));
|
|
89
|
+
}
|
|
90
|
+
throw new TypeError(`${c.req.method} ${c.req.path}: a route handler returned ${result instanceof Response ? 'a Response' : 'a malformed result'} — return \`route_ok\`, \`route_fail\`, or \`route_raw\``);
|
|
91
|
+
};
|
|
29
92
|
export function get_route_input(c, _schema) {
|
|
30
93
|
return c.get('validated_input');
|
|
31
94
|
}
|
|
@@ -213,13 +276,13 @@ export const apply_middleware_specs = (app, specs) => {
|
|
|
213
276
|
* spine's `db_unavailable_response`.
|
|
214
277
|
* Catches anything else, a foreign error class carrying a JSON-RPC `code`
|
|
215
278
|
* included, and maps to `{error: 'internal_error', message?}`
|
|
216
|
-
* at 500 (`message` populated only in DEV).
|
|
217
|
-
*
|
|
218
|
-
* something is thrown.
|
|
279
|
+
* at 500 (`message` populated only in DEV). A handler's returned result is
|
|
280
|
+
* unaffected — the catch layer only activates when something is thrown.
|
|
219
281
|
*
|
|
220
|
-
* The flat shape matches what middleware and
|
|
221
|
-
*
|
|
222
|
-
* `c.json(failure.body, status)` from the dispatcher's authorization
|
|
282
|
+
* The flat shape matches what middleware and handler failures produce
|
|
283
|
+
* (`c.json({error: ERROR_FOO}, status)` in a middleware, `route_fail(def)` in a
|
|
284
|
+
* handler, `c.json(failure.body, status)` from the dispatcher's authorization
|
|
285
|
+
* phase),
|
|
223
286
|
* so REST callers see one error envelope across every emit site. The
|
|
224
287
|
* `<reason>` string comes from `err.data.reason` when set (consumer-supplied
|
|
225
288
|
* canonical reason code) or from `jsonrpc_error_code_to_name(err.code)`
|
|
@@ -305,7 +368,8 @@ const build_rest_error_body = (err) => {
|
|
|
305
368
|
* adds input validation middleware (for routes with non-null input schemas),
|
|
306
369
|
* runs the optional authorization phase to resolve the acting actor + build
|
|
307
370
|
* the request context, wraps handler with DEV-only output
|
|
308
|
-
* validation,
|
|
371
|
+
* validation, builds each response from its handler's result
|
|
372
|
+
* (`to_route_response`), wraps with error catch layer (a thrown JSON-RPC error,
|
|
309
373
|
* recognized via `to_thrown_jsonrpc_error`, maps to its status; any other
|
|
310
374
|
* throw to a 500), and registers the route.
|
|
311
375
|
*
|
|
@@ -380,7 +444,8 @@ export const apply_route_specs = (app, specs, resolve_auth_guards, log, db, auth
|
|
|
380
444
|
}
|
|
381
445
|
]
|
|
382
446
|
: [];
|
|
383
|
-
// Step 1: adapt RouteHandler → Handler (construct RouteContext, call
|
|
447
|
+
// Step 1: adapt RouteHandler → Handler (construct RouteContext, call
|
|
448
|
+
// spec.handler, build the response from its result)
|
|
384
449
|
const use_transaction = spec.transaction ?? spec.method !== 'GET';
|
|
385
450
|
const inner = spec.handler;
|
|
386
451
|
// Discard post-commit effects a handler queued (`emit_after_commit`) if it
|
|
@@ -388,15 +453,18 @@ export const apply_route_specs = (app, specs, resolve_auth_guards, log, db, auth
|
|
|
388
453
|
// those effects would announce state that never committed. The eager
|
|
389
454
|
// `pending_effects` queue (attempt audits, run outside the transaction) is
|
|
390
455
|
// untouched. Shared with the action dispatcher (actions/perform_action.ts)
|
|
391
|
-
// via `dispatch_with_post_commit_rollback`.
|
|
392
|
-
|
|
456
|
+
// via `dispatch_with_post_commit_rollback`. The response is built inside
|
|
457
|
+
// the dispatch, so a result that can't become one (a bare `Response`, a
|
|
458
|
+
// malformed result, a body `JSON.stringify` refuses) throws before the
|
|
459
|
+
// commit and rolls back.
|
|
460
|
+
let handler = async (c) => {
|
|
393
461
|
const route_context = {
|
|
394
462
|
pending_effects: c.var.pending_effects,
|
|
395
463
|
post_commit_effects: c.var.post_commit_effects
|
|
396
464
|
};
|
|
397
|
-
return dispatch_with_post_commit_rollback(c.var.post_commit_effects, () => use_transaction
|
|
398
|
-
? db.transaction(async (tx) => inner(c, { db: tx, ...route_context }))
|
|
399
|
-
: inner(c, { db, ...route_context }));
|
|
465
|
+
return dispatch_with_post_commit_rollback(c.var.post_commit_effects, async () => use_transaction
|
|
466
|
+
? db.transaction(async (tx) => to_route_response(c, await inner(c, { db: tx, ...route_context })))
|
|
467
|
+
: to_route_response(c, await inner(c, { db, ...route_context })));
|
|
400
468
|
};
|
|
401
469
|
// Step 2: error catch layer — a thrown error becomes its REST body here
|
|
402
470
|
handler = wrap_error_catch(handler, log);
|
package/dist/rate_limiter.d.ts
CHANGED
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
*
|
|
24
24
|
* @module
|
|
25
25
|
*/
|
|
26
|
-
import type { Context } from 'hono';
|
|
27
26
|
import { type Infer } from '@fuzdev/fuz_schema/schema.ts';
|
|
28
27
|
/**
|
|
29
28
|
* Rate limit key type — declares what a route or RPC action's rate limiter
|
|
@@ -395,12 +394,4 @@ export declare const reserve_optional: (limiter: RateLimiter | null, key: string
|
|
|
395
394
|
* @param options - override individual options; unset fields use `default_login_ip_rate_limit`
|
|
396
395
|
*/
|
|
397
396
|
export declare const create_rate_limiter: (options?: Partial<RateLimiterOptions>) => RateLimiter;
|
|
398
|
-
/**
|
|
399
|
-
* Build a 429 rate-limit-exceeded JSON response with `Retry-After` header.
|
|
400
|
-
*
|
|
401
|
-
* @param c - Hono context
|
|
402
|
-
* @param retry_after - seconds until the client should retry
|
|
403
|
-
* @returns a 429 Response
|
|
404
|
-
*/
|
|
405
|
-
export declare const rate_limit_exceeded_response: (c: Context, retry_after: number) => Response;
|
|
406
397
|
//# sourceMappingURL=rate_limiter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rate_limiter.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/rate_limiter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;
|
|
1
|
+
{"version":3,"file":"rate_limiter.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/rate_limiter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;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,GACnC,OAAO,CAAC,sBAAsB,CAAC;IA0HlC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAUxB;;;;;;OAMG;IACH,OAAO,CAAC,GAAG,GAAE,MAAmB,GAAG,IAAI;IAcvC;;;;OAIG;IACH,OAAO,IAAI,IAAI;CAMf;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,GAChC,SAAS,WAAW,GAAG,IAAI,EAC3B,KAAK,MAAM,GAAG,IAAI,EAClB,MAAK,MAAmB,KACtB,sBAGF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,GAC5B,SAAS,WAAW,GAAG,IAAI,EAC3B,KAAK,MAAM,GAAG,IAAI,EAClB,UAAU,uBAAuB,KAC/B,OAAO,CAAC,sBAAsB,CAGhC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,UAAU,OAAO,CAAC,kBAAkB,CAAC,KAAG,WAE3E,CAAC"}
|
package/dist/rate_limiter.js
CHANGED
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
*/
|
|
26
26
|
import { LruMap } from '@fuzdev/fuz_util/lru_map.ts';
|
|
27
27
|
import { one_of } from '@fuzdev/fuz_schema/schema.ts';
|
|
28
|
-
import { REST_RATE_LIMIT_EXCEEDED } from './http/error_schemas.js';
|
|
29
28
|
import { PERIODIC_INTERVAL_MS_MAX } from './periodic.js';
|
|
30
29
|
/**
|
|
31
30
|
* Rate limit key type — declares what a route or RPC action's rate limiter
|
|
@@ -598,17 +597,3 @@ export const reserve_optional = async (limiter, key, options) => {
|
|
|
598
597
|
export const create_rate_limiter = (options) => {
|
|
599
598
|
return new RateLimiter({ ...default_login_ip_rate_limit, ...options });
|
|
600
599
|
};
|
|
601
|
-
/**
|
|
602
|
-
* Build a 429 rate-limit-exceeded JSON response with `Retry-After` header.
|
|
603
|
-
*
|
|
604
|
-
* @param c - Hono context
|
|
605
|
-
* @param retry_after - seconds until the client should retry
|
|
606
|
-
* @returns a 429 Response
|
|
607
|
-
*/
|
|
608
|
-
export const rate_limit_exceeded_response = (c, retry_after) => {
|
|
609
|
-
const body = { error: REST_RATE_LIMIT_EXCEEDED.code, retry_after };
|
|
610
|
-
return c.json(body, {
|
|
611
|
-
status: REST_RATE_LIMIT_EXCEEDED.status,
|
|
612
|
-
headers: REST_RATE_LIMIT_EXCEEDED.headers(body)
|
|
613
|
-
});
|
|
614
|
-
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve_fact_route.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/server/serve_fact_route.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmIG;AAMH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AActD,OAAO,
|
|
1
|
+
{"version":3,"file":"serve_fact_route.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/server/serve_fact_route.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmIG;AAMH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AActD,OAAO,EAIN,KAAK,SAAS,EACd,MAAM,uBAAuB,CAAC;AAU/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAkBjD,MAAM,WAAW,+BAA+B;IAC/C,kFAAkF;IAClF,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;CACZ;AAsJD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,iCAAiC,GAC7C,SAAS,+BAA+B,KACtC,SAyDF,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,4BAA4B,GACxC,SAAS,+BAA+B,KACtC,SA8CF,CAAC"}
|
|
@@ -138,7 +138,9 @@ import { literal, object } from '@fuzdev/fuz_schema/schema.ts';
|
|
|
138
138
|
import { build_request_context, get_public_account_id, get_request_context, has_scoped_role } from '../auth/request_context.js';
|
|
139
139
|
import { ROLE_ADMIN } from '../auth/role_schema.js';
|
|
140
140
|
import { query_active_actors_by_account } from '../auth/account_queries.js';
|
|
141
|
-
import { get_route_params } from '../http/route_spec.js';
|
|
141
|
+
import { define_route, get_route_params } from '../http/route_spec.js';
|
|
142
|
+
import { route_fail, route_raw } from '../http/route_result.js';
|
|
143
|
+
import { REST_INTERNAL_ERROR } from '../http/error_schemas.js';
|
|
142
144
|
import { query_get_fact, query_get_fact_meta } from '../db/fact_queries.js';
|
|
143
145
|
import { to_uint8 } from '../db/fact_store.js';
|
|
144
146
|
import { query_cell_get } from '../db/cell_queries.js';
|
|
@@ -179,7 +181,7 @@ const serve_fact_bytes = async (c, route, hash, config) => {
|
|
|
179
181
|
const { facts_dir, x_accel, log } = config;
|
|
180
182
|
const meta = await query_get_fact_meta({ db: route.db }, hash);
|
|
181
183
|
if (!meta) {
|
|
182
|
-
return c.body(null, 404);
|
|
184
|
+
return route_raw(c.body(null, 404));
|
|
183
185
|
}
|
|
184
186
|
const content_type = meta.content_type ?? 'application/octet-stream';
|
|
185
187
|
const size = String(meta.size);
|
|
@@ -189,39 +191,39 @@ const serve_fact_bytes = async (c, route, hash, config) => {
|
|
|
189
191
|
if (!row || row.bytes === null) {
|
|
190
192
|
// Race: meta said embedded but bytes vanished. Treat as not-found.
|
|
191
193
|
log.warn(`serve_fact: embedded bytes missing for ${hash} (meta said embedded, row=${row ? 'present' : 'null'})`);
|
|
192
|
-
return c.body(null, 404);
|
|
194
|
+
return route_raw(c.body(null, 404));
|
|
193
195
|
}
|
|
194
196
|
const bytes = to_uint8(row.bytes);
|
|
195
|
-
return c.body(bytes, 200, {
|
|
197
|
+
return route_raw(c.body(bytes, 200, {
|
|
196
198
|
'Content-Type': content_type,
|
|
197
199
|
'Content-Length': size,
|
|
198
200
|
'Cache-Control': FACT_CACHE_CONTROL,
|
|
199
201
|
...FACT_SECURITY_HEADERS
|
|
200
|
-
});
|
|
202
|
+
}));
|
|
201
203
|
}
|
|
202
204
|
// External — defense-in-depth re-validate the URL before trusting it
|
|
203
205
|
// to address the filesystem: its shape, then that it is this hash's file
|
|
204
206
|
const parsed = parse_file_fact_url(meta.external_url);
|
|
205
207
|
if (!parsed) {
|
|
206
208
|
log.error(`serve_fact: external_url for ${hash} is not a file:<shard>/<rest> URL; answering 404`);
|
|
207
|
-
return c.body(null, 404);
|
|
209
|
+
return route_raw(c.body(null, 404));
|
|
208
210
|
}
|
|
209
211
|
if (!file_fact_url_addresses(parsed, hash)) {
|
|
210
212
|
log.error(`serve_fact: external_url for ${hash} addresses another fact's file; answering 404`);
|
|
211
|
-
return c.body(null, 404);
|
|
213
|
+
return route_raw(c.body(null, 404));
|
|
212
214
|
}
|
|
213
215
|
const { shard, rest } = parsed;
|
|
214
216
|
if (x_accel !== undefined) {
|
|
215
217
|
// Production: hand off to nginx via the validated `internal;` facts location.
|
|
216
218
|
// nginx answers with that location's own `add_header` set, not these
|
|
217
219
|
// headers, which is why the validator requires the fact pair there.
|
|
218
|
-
return c.body(null, 200, {
|
|
220
|
+
return route_raw(c.body(null, 200, {
|
|
219
221
|
'Content-Type': content_type,
|
|
220
222
|
'Content-Length': size,
|
|
221
223
|
'Cache-Control': FACT_CACHE_CONTROL,
|
|
222
224
|
'X-Accel-Redirect': `${x_accel.redirect_prefix}${shard}/${rest}`,
|
|
223
225
|
...FACT_SECURITY_HEADERS
|
|
224
|
-
});
|
|
226
|
+
}));
|
|
225
227
|
}
|
|
226
228
|
// Dev / tests: stream from disk. Open before committing the 200 so a
|
|
227
229
|
// missing file answers 404 and any other open failure a logged 500, as the
|
|
@@ -234,10 +236,10 @@ const serve_fact_bytes = async (c, route, hash, config) => {
|
|
|
234
236
|
catch (err) {
|
|
235
237
|
if (err.code === 'ENOENT') {
|
|
236
238
|
log.warn(`serve_fact: disk file for ${hash} is missing; answering 404`);
|
|
237
|
-
return c.body(null, 404);
|
|
239
|
+
return route_raw(c.body(null, 404));
|
|
238
240
|
}
|
|
239
241
|
log.error(`serve_fact: disk open for ${hash} failed`, err);
|
|
240
|
-
return
|
|
242
|
+
return route_fail(REST_INTERNAL_ERROR);
|
|
241
243
|
}
|
|
242
244
|
const headers = {
|
|
243
245
|
'Content-Type': content_type,
|
|
@@ -249,10 +251,10 @@ const serve_fact_bytes = async (c, route, hash, config) => {
|
|
|
249
251
|
// unread, so a stream built here would hold the handle open until GC
|
|
250
252
|
if (c.req.method === 'HEAD') {
|
|
251
253
|
await handle.close();
|
|
252
|
-
return c.body(null, 200, headers);
|
|
254
|
+
return route_raw(c.body(null, 200, headers));
|
|
253
255
|
}
|
|
254
256
|
const web_stream = Readable.toWeb(handle.createReadStream());
|
|
255
|
-
return c.body(web_stream, 200, headers);
|
|
257
|
+
return route_raw(c.body(web_stream, 200, headers));
|
|
256
258
|
};
|
|
257
259
|
/**
|
|
258
260
|
* Resolve the caller's `RequestContext` on a pure-public route from the
|
|
@@ -297,7 +299,7 @@ const build_public_request_context = async (c, route) => {
|
|
|
297
299
|
export const create_serve_cell_fact_route_spec = (options) => {
|
|
298
300
|
const { facts_dir, x_accel, log } = options;
|
|
299
301
|
const config = { facts_dir, x_accel, log };
|
|
300
|
-
return {
|
|
302
|
+
return define_route({
|
|
301
303
|
method: 'GET',
|
|
302
304
|
path: '/api/cells/:cell_id/facts/:hash',
|
|
303
305
|
auth: { account: 'none', actor: 'none' },
|
|
@@ -312,7 +314,7 @@ export const create_serve_cell_fact_route_spec = (options) => {
|
|
|
312
314
|
// Resolve the named cell. Missing / soft-deleted → 404 (masked).
|
|
313
315
|
const cell = await query_cell_get({ db: route.db }, cell_id);
|
|
314
316
|
if (!cell) {
|
|
315
|
-
return c.body(null, 404);
|
|
317
|
+
return route_raw(c.body(null, 404));
|
|
316
318
|
}
|
|
317
319
|
// Per-reference view check — scoped to *this* cell only. It runs
|
|
318
320
|
// before the edge check, so a cell the caller can't view does the
|
|
@@ -332,18 +334,18 @@ export const create_serve_cell_fact_route_spec = (options) => {
|
|
|
332
334
|
if (!can_view_cell(req_ctx, cell, grants) &&
|
|
333
335
|
!(await cell_steward_admits({ db: route.db }, req_ctx, cell))) {
|
|
334
336
|
// 404 (not 403) so an unviewable cell→fact edge doesn't leak.
|
|
335
|
-
return c.body(null, 404);
|
|
337
|
+
return route_raw(c.body(null, 404));
|
|
336
338
|
}
|
|
337
339
|
// The cell→fact edge: the cell must actually reference the hash.
|
|
338
340
|
// `cell.refs` is auto-derived from `data` on every write, so this is
|
|
339
341
|
// the authoritative "does this cell reference these bytes" check.
|
|
340
342
|
// Missing edge → 404 (masked), never "exists elsewhere".
|
|
341
343
|
if (!cell.refs?.includes(hash)) {
|
|
342
|
-
return c.body(null, 404);
|
|
344
|
+
return route_raw(c.body(null, 404));
|
|
343
345
|
}
|
|
344
346
|
return serve_fact_bytes(c, route, hash, config);
|
|
345
347
|
}
|
|
346
|
-
};
|
|
348
|
+
});
|
|
347
349
|
};
|
|
348
350
|
/**
|
|
349
351
|
* Build the admin-only bare-hash `GET /api/facts/:hash` `RouteSpec`.
|
|
@@ -366,7 +368,7 @@ export const create_serve_cell_fact_route_spec = (options) => {
|
|
|
366
368
|
export const create_serve_fact_route_spec = (options) => {
|
|
367
369
|
const { facts_dir, x_accel, log } = options;
|
|
368
370
|
const config = { facts_dir, x_accel, log };
|
|
369
|
-
return {
|
|
371
|
+
return define_route({
|
|
370
372
|
method: 'GET',
|
|
371
373
|
path: '/api/facts/:hash',
|
|
372
374
|
auth: {
|
|
@@ -399,9 +401,9 @@ export const create_serve_fact_route_spec = (options) => {
|
|
|
399
401
|
// fires only on such a regression, so it fails loud as well.
|
|
400
402
|
if (!has_scoped_role(get_request_context(c), ROLE_ADMIN, null)) {
|
|
401
403
|
log.error('bare-hash fact read reached the handler without a global admin grant — the auth gate did not run');
|
|
402
|
-
return c.body(null, 404);
|
|
404
|
+
return route_raw(c.body(null, 404));
|
|
403
405
|
}
|
|
404
406
|
return serve_fact_bytes(c, route, hash, config);
|
|
405
407
|
}
|
|
406
|
-
};
|
|
408
|
+
});
|
|
407
409
|
};
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
|
-
import type
|
|
10
|
+
import { type RouteSpec } from '../http/route_spec.js';
|
|
11
11
|
import type { AppSurface } from '../http/surface.js';
|
|
12
12
|
/** Options for the surface explorer route. */
|
|
13
13
|
export interface SurfaceRouteOptions {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"surface_route.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/server/surface_route.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"surface_route.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/server/surface_route.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAgB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAErE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIrD,8CAA8C;AAC9C,MAAM,WAAW,mBAAmB;IACnC,2GAA2G;IAC3G,OAAO,EAAE,UAAU,CAAC;CACpB;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,yBAAyB,GAAI,SAAS,mBAAmB,KAAG,SAoBtE,CAAC"}
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
10
|
import { array, literal, loose_object, object } from '@fuzdev/fuz_schema/schema.ts';
|
|
11
|
+
import { define_route } from '../http/route_spec.js';
|
|
12
|
+
import { route_ok } from '../http/route_result.js';
|
|
11
13
|
import { ActingActor } from '../primitive_schemas_fuz.js';
|
|
12
14
|
import { ROLE_ADMIN } from '../auth/role_schema.js';
|
|
13
15
|
/**
|
|
@@ -24,7 +26,7 @@ import { ROLE_ADMIN } from '../auth/role_schema.js';
|
|
|
24
26
|
* @param options - the surface to serve
|
|
25
27
|
* @returns the `GET /api/surface` route spec
|
|
26
28
|
*/
|
|
27
|
-
export const create_surface_route_spec = (options) => ({
|
|
29
|
+
export const create_surface_route_spec = (options) => define_route({
|
|
28
30
|
method: 'GET',
|
|
29
31
|
path: '/api/surface',
|
|
30
32
|
auth: {
|
|
@@ -35,7 +37,7 @@ export const create_surface_route_spec = (options) => ({
|
|
|
35
37
|
// gets none of it
|
|
36
38
|
required_scope: 'surface:app_surface'
|
|
37
39
|
},
|
|
38
|
-
handler: (
|
|
40
|
+
handler: () => route_ok(options.surface),
|
|
39
41
|
description: 'Application surface (routes, middleware, schemas) — admin only',
|
|
40
42
|
query: object({ acting: ActingActor }),
|
|
41
43
|
input: literal(null),
|
package/dist/testing/CLAUDE.md
CHANGED
|
@@ -30,7 +30,8 @@ time (never runtime), where a throwing guard would break `vite build`.
|
|
|
30
30
|
- `create_noop_stub<T>(label, overrides?)` — Proxy whose every method returns `async () => undefined`; `overrides` pins specific props.
|
|
31
31
|
- `stub` — pre-built throwing stub labelled `'stub'`.
|
|
32
32
|
- `create_stub_db()` — real `Db` whose `client.query` yields `{rows: []}` and `transaction(fn)` synchronously calls `fn(inner_stub_db)`. Safe for `apply_route_specs`'s declarative transaction wrapper.
|
|
33
|
-
- `stub_handler()` — fresh `Response('stub')
|
|
33
|
+
- `stub_handler()` — a fresh `Response('stub')` as a `route_raw` result, a handler that fits any route (`attach_route_handler(shape, stub_handler)`).
|
|
34
|
+
- `stub_route_spec(shape)` — a spec for a surface that is described and never served: `shape` with a handler that throws when run (the spine routes of `create_rust_spine_consumer_surface_spec`).
|
|
34
35
|
- `stub_mw` — pass-through middleware (`async (_c, next) => next()`).
|
|
35
36
|
- `create_stub_app_deps()` — factory: fresh `AppDeps` with no-op keyring/password/`delete_file`, a `read_secure_file` that throws ENOENT (the no-token-file state), a `create_noop_stub` DB, silent `Logger`, no-op `audit`, an empty `connection_closer`.
|
|
36
37
|
- `create_test_audit_emitter()` — no-op `AuditEmitter`; `emit` / `emit_role_grant_target` / `emit_pool` resolve immediately, `notify` no-op, `add_listener` throws (use `create_recording_audit_emitter` for a listener-accepting emitter), `listener_count` returns 0, `drain_inflight` resolves immediately, `is_tracking_inflight` returns `false`.
|
|
@@ -2808,8 +2809,9 @@ over real HTTP on both spines:
|
|
|
2808
2809
|
- **per-IP limit fires** — `default_login_ip_rate_limit.max_attempts` (5, the
|
|
2809
2810
|
shared cap on both impls) failed logins from one forwarded IP → 401, the next →
|
|
2810
2811
|
`429` with the canonical `{error: "rate_limit_exceeded", retry_after}` body +
|
|
2811
|
-
`Retry-After: ceil(retry_after)` header (TS
|
|
2812
|
-
|
|
2812
|
+
`Retry-After: ceil(retry_after)` header (TS
|
|
2813
|
+
`route_fail(REST_RATE_LIMIT_EXCEEDED, {retry_after})` ↔ Rust
|
|
2814
|
+
`route_response::rate_limit_exceeded`).
|
|
2813
2815
|
- **XFF keying** — exhaust one forwarded IP to 429, then a _distinct_ forwarded IP
|
|
2814
2816
|
→ 401 (not 429), proving the limiter keys on the resolved `X-Forwarded-For` IP,
|
|
2815
2817
|
not the loopback TCP peer (a backend ignoring XFF would 429 the fresh IP too).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adversarial_404.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/adversarial_404.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"adversarial_404.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/adversarial_404.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAuB7B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAOlE;;;;;;;;;GASG;AACH,eAAO,MAAM,wBAAwB,GAAI,SAAS,sBAAsB,KAAG,IAkF1E,CAAC"}
|
|
@@ -11,6 +11,7 @@ import './assert_dev_env.js';
|
|
|
11
11
|
* @module
|
|
12
12
|
*/
|
|
13
13
|
import { test, assert, describe } from 'vitest';
|
|
14
|
+
import { route_fail } from '../http/route_result.js';
|
|
14
15
|
import { format_route_key } from '../http/surface_query.js';
|
|
15
16
|
import { is_null_schema } from '../http/schema_helpers.js';
|
|
16
17
|
import { assert_error_schema_valid } from './assertions.js';
|
|
@@ -51,27 +52,31 @@ export const describe_adversarial_404 = (options) => {
|
|
|
51
52
|
const not_found = spec.errors?.find((def) => def.status === 404);
|
|
52
53
|
if (!not_found)
|
|
53
54
|
continue;
|
|
54
|
-
testable.push({ key,
|
|
55
|
+
testable.push({ key, not_found, spec });
|
|
55
56
|
}
|
|
56
57
|
if (testable.length === 0)
|
|
57
58
|
return;
|
|
58
59
|
describe('adversarial 404 response validation', () => {
|
|
59
60
|
// Create stub specs: replace handlers for testable routes with 404 stubs
|
|
60
|
-
const
|
|
61
|
+
const not_found_by_key = new Map();
|
|
61
62
|
for (const entry of testable) {
|
|
62
|
-
|
|
63
|
+
not_found_by_key.set(entry.key, entry.not_found);
|
|
63
64
|
}
|
|
64
65
|
const stub_specs = route_specs.map((spec) => {
|
|
65
|
-
const
|
|
66
|
-
if (!
|
|
66
|
+
const not_found = not_found_by_key.get(format_route_key(spec));
|
|
67
|
+
if (!not_found)
|
|
67
68
|
return spec;
|
|
68
69
|
return {
|
|
69
70
|
...spec,
|
|
70
|
-
|
|
71
|
+
// the code alone, `{error}` at 404: a stub has no fields to give
|
|
72
|
+
handler: () =>
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/no-generated-empty-object-type
|
|
74
|
+
route_fail(not_found)
|
|
71
75
|
};
|
|
72
76
|
});
|
|
73
77
|
const apps = create_auth_test_apps(stub_specs, roles);
|
|
74
|
-
for (const { key,
|
|
78
|
+
for (const { key, not_found, spec } of testable) {
|
|
79
|
+
const error_code = not_found.code;
|
|
75
80
|
test(key, async () => {
|
|
76
81
|
const route = surface.routes.find((r) => format_route_key(r) === key);
|
|
77
82
|
const app = select_auth_app(apps, route.auth);
|
|
@@ -14,7 +14,7 @@ import '../assert_dev_env.js';
|
|
|
14
14
|
*
|
|
15
15
|
* Drives the full lifecycle (create → get → update → delete → list, threading
|
|
16
16
|
* the created id) plus the authz matrix the wire contract guarantees. Every
|
|
17
|
-
* success response is parsed against the verb's declared
|
|
17
|
+
* success response is parsed against the verb's declared **output** schema
|
|
18
18
|
* (`CellCreateOutput` / `CellGetOutput` / …), so a TS↔Rust envelope drift —
|
|
19
19
|
* not just a `CellJson` field drift — fails the suite:
|
|
20
20
|
*
|
|
@@ -125,7 +125,7 @@ export const describe_cell_crud_cross_tests = (options) => {
|
|
|
125
125
|
assert.strictEqual(created.cell.created_by, owner.actor.id);
|
|
126
126
|
assert.strictEqual(created.cell.updated_by, null);
|
|
127
127
|
assert.strictEqual(created.cell.grant_count, 0);
|
|
128
|
-
// Byte-shape gate: `CellJson`'s `
|
|
128
|
+
// Byte-shape gate: `CellJson`'s `Timestamp` accepts a millisecond
|
|
129
129
|
// stamp too, so `expect_output` alone can't tell the two spines
|
|
130
130
|
// apart on the timestamp columns.
|
|
131
131
|
assert_iso8601_seconds(created.cell.created_at, 'cell_create.created_at');
|
|
@@ -8,7 +8,7 @@ import '../assert_dev_env.js';
|
|
|
8
8
|
* Like the CRUD suite (and ws / sse), these verbs are live-mounted on the
|
|
9
9
|
* spine RPC path but stay off the standard declared surface, so the generic
|
|
10
10
|
* `describe_rpc_round_trip_tests` never drives them. Every success response
|
|
11
|
-
* is parsed against the verb's declared
|
|
11
|
+
* is parsed against the verb's declared **output** schema, so a TS↔Rust
|
|
12
12
|
* envelope drift fails the suite — not just a payload-field drift.
|
|
13
13
|
*
|
|
14
14
|
* Coverage (gated on `capabilities.cell_relations`):
|
|
@@ -192,7 +192,7 @@ export const describe_cell_relations_cross_tests = (options) => {
|
|
|
192
192
|
});
|
|
193
193
|
test_if(capabilities.cell_relations, "cell_list shared_with other than 'me' → invalid_params", async () => {
|
|
194
194
|
const fixture = await setup_test();
|
|
195
|
-
// TS rejects at the schema (`
|
|
195
|
+
// TS rejects at the schema (`literal('me')`), Rust in the handler
|
|
196
196
|
// guard — both must land on -32602, so a caller can't widen the
|
|
197
197
|
// grant-driven branch to another actor on either spine.
|
|
198
198
|
const bad = await cross_rpc_call(fixture.fresh_transport(), rpc_path, 'cell_list', { shared_with: 'not-me' }, fixture.create_session_headers());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login_security.d.ts","sourceRoot":"../src/lib/","sources":["../../../src/lib/testing/cross_backend/login_security.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"login_security.d.ts","sourceRoot":"../src/lib/","sources":["../../../src/lib/testing/cross_backend/login_security.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAuF9B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAO5C,mDAAmD;AACnD,MAAM,WAAW,6BAA6B;IAC7C,2EAA2E;IAC3E,QAAQ,CAAC,UAAU,EAAE,SAAS,CAAC;IAC/B,kFAAkF;IAClF,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,wEAAwE;IACxE,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC;;;;;;OAMG;IACH,QAAQ,CAAC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAC3C;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAmDD,eAAO,MAAM,mCAAmC,GAC/C,SAAS,6BAA6B,KACpC,IA4VF,CAAC"}
|
|
@@ -16,8 +16,9 @@ import '../assert_dev_env.js';
|
|
|
16
16
|
* failed logins from one forwarded IP each return `401`, and the next
|
|
17
17
|
* returns `429` with the canonical `{error: "rate_limit_exceeded",
|
|
18
18
|
* retry_after}` body **and** a `Retry-After: ceil(retry_after)` header. The
|
|
19
|
-
* 429 wire shape is the cross-impl contract — TS
|
|
20
|
-
*
|
|
19
|
+
* 429 wire shape is the cross-impl contract — TS
|
|
20
|
+
* `route_fail(REST_RATE_LIMIT_EXCEEDED, {retry_after})` and Rust
|
|
21
|
+
* `route_response::rate_limit_exceeded` must agree.
|
|
21
22
|
* - **trusted-proxy / XFF resolution is honored** — distinct
|
|
22
23
|
* `X-Forwarded-For` IPs get independent buckets: after exhausting one
|
|
23
24
|
* forwarded IP to `429`, a *different* forwarded IP is unaffected (`401`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rust_spine_consumer_surface.d.ts","sourceRoot":"../src/lib/","sources":["../../../src/lib/testing/cross_backend/rust_spine_consumer_surface.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,KAAK,EAAE,eAAe,EAA6B,MAAM,8BAA8B,CAAC;AAM/F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAOnE,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAI3E;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,wDAAyD,CAAC;
|
|
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SAAS,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,wCAAwC,GACpD,SAAS,oCAAoC,KAC3C,CAAC,CAAC,GAAG,EAAE,gBAAgB,KAAK,KAAK,CAAC,eAAe,CAAC,CA+BpD,CAAC;AAiCF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uCAAuC,GACnD,SAAS,mCAAmC,KAC1C,cAoBA,CAAC"}
|
|
@@ -6,7 +6,7 @@ import { create_standard_rpc_actions } from '../../auth/standard_rpc_actions.js'
|
|
|
6
6
|
import { create_health_route_spec } from '../../http/common_routes.js';
|
|
7
7
|
import { REST_FORBIDDEN_HOST } from '../../http/error_schemas.js';
|
|
8
8
|
import { prefix_route_specs } from '../../http/route_spec.js';
|
|
9
|
-
import { create_test_app_surface_spec,
|
|
9
|
+
import { create_test_app_surface_spec, stub_mw, stub_route_spec } from '../stubs.js';
|
|
10
10
|
import { SPINE_ACCOUNT_PATH_PREFIX, SPINE_RPC_PATH } from './spine_surface_constants.js';
|
|
11
11
|
/**
|
|
12
12
|
* The routes `fuz_auth::account_router` mounts, relative to `/api/account`. An
|
|
@@ -19,10 +19,6 @@ import { SPINE_ACCOUNT_PATH_PREFIX, SPINE_RPC_PATH } from './spine_surface_const
|
|
|
19
19
|
export const ACCOUNT_ROUTER_PATHS = ['/status', '/login', '/logout', '/password'];
|
|
20
20
|
/** Surface generation never invokes handlers — see the module doc. */
|
|
21
21
|
const noop_action_handler = (async () => undefined);
|
|
22
|
-
const to_route_spec = (shape) => ({
|
|
23
|
-
...shape,
|
|
24
|
-
handler: stub_handler
|
|
25
|
-
});
|
|
26
22
|
/**
|
|
27
23
|
* The RPC endpoints a Rust spine consumer mounts: the standard admin /
|
|
28
24
|
* role-grant-offer / account actions, the extra families, then the domain
|
|
@@ -81,7 +77,7 @@ const create_spine_consumer_route_specs = (ctx) => {
|
|
|
81
77
|
create_signup_route_shape({
|
|
82
78
|
signup_account_rate_limited: ctx.signup_account_rate_limiter !== null
|
|
83
79
|
})
|
|
84
|
-
].map(
|
|
80
|
+
].map((shape) => stub_route_spec(shape)))
|
|
85
81
|
];
|
|
86
82
|
};
|
|
87
83
|
/**
|
package/dist/testing/stubs.d.ts
CHANGED
|
@@ -8,7 +8,8 @@ import type { BootstrapServerOptions } from '../server/app_server.js';
|
|
|
8
8
|
import type { AppServerContext } from '../server/app_server_context.js';
|
|
9
9
|
import type { AppBackend } from '../server/app_backend.js';
|
|
10
10
|
import { Db } from '../db/db.js';
|
|
11
|
-
import { type RouteSpec } from '../http/route_spec.js';
|
|
11
|
+
import { type RouteShape, type RouteSpec } from '../http/route_spec.js';
|
|
12
|
+
import { type RouteRaw } from '../http/route_result.js';
|
|
12
13
|
import { type AppSurfaceSpec, type RpcEndpointSpec } from '../http/surface.js';
|
|
13
14
|
import { type WsEndpointSpec } from '../actions/ws_endpoint_spec.js';
|
|
14
15
|
import type { EventSpec } from '../realtime/sse.js';
|
|
@@ -52,8 +53,18 @@ export declare const stub: any;
|
|
|
52
53
|
* - `transaction(fn)` calls `fn(db)` synchronously (no real transaction)
|
|
53
54
|
*/
|
|
54
55
|
export declare const create_stub_db: () => Db;
|
|
55
|
-
/** Stub handler that
|
|
56
|
-
export declare const stub_handler: () =>
|
|
56
|
+
/** Stub handler that answers a 200 `stub` text response, as a raw result. */
|
|
57
|
+
export declare const stub_handler: () => RouteRaw;
|
|
58
|
+
/**
|
|
59
|
+
* A route spec for a surface that is described and never served — a
|
|
60
|
+
* backend's routes declared from their shapes: `shape` with a handler that
|
|
61
|
+
* throws when it is run. Its handler is checked against nothing, as it
|
|
62
|
+
* returns nothing.
|
|
63
|
+
*
|
|
64
|
+
* @param shape - the route minus its handler (`define_route_shape`)
|
|
65
|
+
* @returns the spec, for surface generation
|
|
66
|
+
*/
|
|
67
|
+
export declare const stub_route_spec: (shape: RouteShape) => RouteSpec;
|
|
57
68
|
/** Stub middleware that passes through. */
|
|
58
69
|
export declare const stub_mw: (_c: any, next: any) => Promise<void>;
|
|
59
70
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stubs.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/stubs.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAa7B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAGrF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,
|
|
1
|
+
{"version":3,"file":"stubs.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/stubs.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAa7B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAGrF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,M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