@fuzdev/fuz_app 0.169.0 → 0.170.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 +17 -19
- package/dist/actions/action_codegen.d.ts +25 -18
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +83 -67
- package/dist/actions/action_event.d.ts +0 -8
- package/dist/actions/action_event.d.ts.map +1 -1
- package/dist/actions/action_event.js +7 -6
- package/dist/actions/action_event_data.d.ts +4 -4
- package/dist/actions/action_rpc.d.ts +1 -1
- package/dist/actions/action_rpc.js +1 -1
- package/dist/actions/action_spec.d.ts +8 -10
- package/dist/actions/action_spec.d.ts.map +1 -1
- package/dist/actions/action_spec.js +1 -1
- 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 +2 -2
- package/dist/actions/broadcast_api.js +4 -4
- package/dist/actions/compile_action_registry.d.ts +6 -7
- package/dist/actions/compile_action_registry.d.ts.map +1 -1
- package/dist/actions/compile_action_registry.js +8 -9
- package/dist/actions/perform_action.d.ts +6 -6
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +11 -10
- package/dist/actions/socket.svelte.d.ts +1 -1
- package/dist/actions/socket.svelte.js +2 -2
- package/dist/auth/CLAUDE.md +11 -11
- package/dist/auth/admin_action_specs.d.ts +24 -24
- package/dist/auth/audit_emitter.d.ts +6 -7
- package/dist/auth/audit_emitter.d.ts.map +1 -1
- package/dist/auth/audit_emitter.js +11 -22
- package/dist/auth/audit_log_ddl.d.ts +1 -1
- package/dist/auth/audit_log_ddl.js +1 -1
- package/dist/auth/audit_log_queries.d.ts +0 -13
- package/dist/auth/audit_log_queries.d.ts.map +1 -1
- package/dist/auth/audit_log_queries.js +3 -3
- package/dist/auth/audit_log_schema.d.ts +14 -15
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +1 -1
- package/dist/auth/auth_ddl.d.ts +1 -1
- package/dist/auth/auth_ddl.js +1 -1
- package/dist/auth/cell_action_specs.d.ts +54 -54
- package/dist/auth/cell_actions.d.ts +2 -2
- package/dist/auth/cell_actions.js +5 -5
- package/dist/auth/request_context.js +2 -2
- package/dist/auth/role_grant_offer_action_specs.d.ts +6 -6
- package/dist/auth/role_grant_offer_ddl.d.ts +1 -1
- package/dist/auth/role_grant_offer_ddl.js +1 -1
- package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_notifications.js +2 -3
- package/dist/auth/self_service_role_actions.d.ts +1 -1
- package/dist/auth/self_service_role_actions.js +1 -1
- package/dist/env/env_schemas.d.ts +1 -2
- package/dist/env/env_schemas.d.ts.map +1 -1
- package/dist/env/env_schemas.js +3 -4
- package/dist/http/CLAUDE.md +29 -31
- package/dist/http/auth_shape.d.ts +14 -32
- package/dist/http/auth_shape.d.ts.map +1 -1
- package/dist/http/auth_shape.js +14 -49
- package/dist/http/error_schemas.d.ts +18 -18
- package/dist/http/jsonrpc_helpers.js +1 -1
- package/dist/http/route_error_check.d.ts +2 -2
- package/dist/http/route_error_check.d.ts.map +1 -1
- package/dist/http/route_error_check.js +2 -3
- package/dist/http/route_errors.d.ts +4 -4
- package/dist/http/route_errors.d.ts.map +1 -1
- package/dist/http/route_errors.js +0 -13
- package/dist/http/route_spec.d.ts +33 -36
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +21 -22
- package/dist/http/schema_helpers.d.ts +75 -67
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +54 -77
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +6 -8
- package/dist/primitive_schemas.d.ts +9 -17
- package/dist/primitive_schemas.d.ts.map +1 -1
- package/dist/primitive_schemas.js +9 -17
- package/dist/realtime/sse.d.ts +3 -3
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse.js +2 -2
- package/dist/schema_issues.d.ts +39 -147
- package/dist/schema_issues.d.ts.map +1 -1
- package/dist/schema_issues.js +39 -352
- package/dist/schema_meta.d.ts +63 -136
- package/dist/schema_meta.d.ts.map +1 -1
- package/dist/schema_meta.js +37 -184
- package/dist/sensitivity.d.ts +3 -5
- package/dist/sensitivity.d.ts.map +1 -1
- package/dist/sensitivity.js +3 -5
- package/dist/testing/CLAUDE.md +20 -22
- package/dist/testing/adversarial_headers.js +2 -2
- package/dist/testing/adversarial_input_cases.d.ts +19 -18
- package/dist/testing/adversarial_input_cases.d.ts.map +1 -1
- package/dist/testing/adversarial_input_cases.js +29 -42
- package/dist/testing/assertions.d.ts +2 -2
- package/dist/testing/assertions.d.ts.map +1 -1
- package/dist/testing/assertions.js +3 -3
- package/dist/testing/cross_backend/account_lifecycle.js +2 -2
- package/dist/testing/cross_backend/action_manifest.d.ts +10 -9
- package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
- package/dist/testing/cross_backend/action_manifest.js +4 -3
- package/dist/testing/cross_backend/cell_crud.js +1 -1
- package/dist/testing/cross_backend/conformance_rpc_auth.d.ts +0 -62
- package/dist/testing/cross_backend/conformance_rpc_auth.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +3 -3
- package/dist/testing/cross_backend/cross_rpc.d.ts +3 -4
- package/dist/testing/cross_backend/cross_rpc.d.ts.map +1 -1
- package/dist/testing/cross_backend/cross_rpc.js +4 -4
- package/dist/testing/cross_backend/differential.js +2 -2
- package/dist/testing/cross_backend/identity_parity.js +9 -9
- package/dist/testing/cross_backend/origin_conformance.d.ts +9 -9
- package/dist/testing/cross_backend/query_shape.js +1 -1
- package/dist/testing/cross_backend/rpc_success_fixtures.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +1 -1
- package/dist/testing/cross_backend/setup.d.ts +25 -3
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +4 -4
- package/dist/testing/cross_backend/sse_round_trip.js +2 -2
- package/dist/testing/cross_backend/testing_origin_check.d.ts +4 -4
- package/dist/testing/cross_backend/token_lifetime.js +3 -3
- package/dist/testing/cross_backend/wire_shapes.js +1 -1
- package/dist/testing/cross_backend/ws_round_trip.js +1 -1
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +1 -1
- package/dist/testing/integration.js +2 -2
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +2 -2
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +2 -2
- package/dist/testing/rpc_attack_surface.js +1 -1
- 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 -14
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +9 -10
- package/dist/testing/schema_generators.d.ts +67 -60
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +150 -145
- package/dist/testing/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/sse_round_trip.js +2 -2
- package/dist/testing/surface_invariants.d.ts +1 -1
- package/dist/testing/surface_invariants.js +1 -1
- package/dist/ui/form_state.svelte.d.ts +1 -1
- package/dist/ui/form_state.svelte.js +1 -1
- package/package.json +5 -7
- package/dist/zod.d.ts +0 -116
- package/dist/zod.d.ts.map +0 -1
- package/dist/zod.js +0 -218
- package/dist/zod_schemas.d.ts +0 -100
- package/dist/zod_schemas.d.ts.map +0 -1
- package/dist/zod_schemas.js +0 -157
|
@@ -13,13 +13,12 @@ import { ActionExecutor } from './action_event_types.js';
|
|
|
13
13
|
export declare const ActionEventData: import("@fuzdev/fuz_schema/schema.ts").Schema<{
|
|
14
14
|
input: unknown;
|
|
15
15
|
kind: "request_response" | "remote_notification" | "local_call";
|
|
16
|
-
|
|
16
|
+
method: string;
|
|
17
17
|
error: ({
|
|
18
18
|
message: string;
|
|
19
19
|
code: -32700 | -32600 | -32601 | -32602 | -32603 | import("@fuzdev/fuz_schema/schema.ts").Branded<number, "JsonrpcServerErrorCode">;
|
|
20
20
|
data?: unknown;
|
|
21
21
|
} & Record<string, unknown>) | null;
|
|
22
|
-
method: string;
|
|
23
22
|
request: ({
|
|
24
23
|
id: string | number;
|
|
25
24
|
method: string;
|
|
@@ -44,6 +43,7 @@ export declare const ActionEventData: import("@fuzdev/fuz_schema/schema.ts").Sch
|
|
|
44
43
|
} & Record<string, unknown>;
|
|
45
44
|
jsonrpc: "2.0";
|
|
46
45
|
} & Record<string, unknown>) | null;
|
|
46
|
+
output: unknown;
|
|
47
47
|
phase: "send_request" | "receive_request" | "send_response" | "receive_response" | "send_error" | "receive_error" | "send" | "receive" | "execute";
|
|
48
48
|
step: "initial" | "parsed" | "handling" | "handled" | "failed";
|
|
49
49
|
executor: "frontend" | "backend";
|
|
@@ -51,13 +51,12 @@ export declare const ActionEventData: import("@fuzdev/fuz_schema/schema.ts").Sch
|
|
|
51
51
|
}, {
|
|
52
52
|
input: unknown;
|
|
53
53
|
kind: "request_response" | "remote_notification" | "local_call";
|
|
54
|
-
|
|
54
|
+
method: string;
|
|
55
55
|
error: ({
|
|
56
56
|
message: string;
|
|
57
57
|
code: number;
|
|
58
58
|
data?: unknown;
|
|
59
59
|
} & Record<string, unknown>) | null;
|
|
60
|
-
method: string;
|
|
61
60
|
request: ({
|
|
62
61
|
id: string | number;
|
|
63
62
|
method: string;
|
|
@@ -82,6 +81,7 @@ export declare const ActionEventData: import("@fuzdev/fuz_schema/schema.ts").Sch
|
|
|
82
81
|
} & Record<string, unknown>;
|
|
83
82
|
jsonrpc: "2.0";
|
|
84
83
|
} & Record<string, unknown>) | null;
|
|
84
|
+
output: unknown;
|
|
85
85
|
phase: "send_request" | "receive_request" | "send_response" | "receive_response" | "send_error" | "receive_error" | "send" | "receive" | "execute";
|
|
86
86
|
step: "initial" | "parsed" | "handling" | "handled" | "failed";
|
|
87
87
|
executor: "frontend" | "backend";
|
|
@@ -91,7 +91,7 @@ export interface CreateRpcEndpointOptions {
|
|
|
91
91
|
* @returns route specs (GET + POST) ready for `apply_route_specs`
|
|
92
92
|
* @throws Error if two actions share the same `spec.method` (registration-time
|
|
93
93
|
* duplicate detection); also throws if any action's `spec.input` is a null
|
|
94
|
-
* schema (`
|
|
94
|
+
* schema (`literal(null)`; JSON-RPC 2.0 §4.2 forbids
|
|
95
95
|
* `params: null` on the wire — use a void schema for parameterless methods)
|
|
96
96
|
* or its `spec.output` is a void schema.
|
|
97
97
|
*/
|
|
@@ -80,7 +80,7 @@ const envelope_response = (c, envelope, status) => route_raw(c.body(JSON.stringi
|
|
|
80
80
|
* @returns route specs (GET + POST) ready for `apply_route_specs`
|
|
81
81
|
* @throws Error if two actions share the same `spec.method` (registration-time
|
|
82
82
|
* duplicate detection); also throws if any action's `spec.input` is a null
|
|
83
|
-
* schema (`
|
|
83
|
+
* schema (`literal(null)`; JSON-RPC 2.0 §4.2 forbids
|
|
84
84
|
* `params: null` on the wire — use a void schema for parameterless methods)
|
|
85
85
|
* or its `spec.output` is a void schema.
|
|
86
86
|
*/
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* A spec is a plain object typed by these interfaces, written with
|
|
9
9
|
* `satisfies` (`satisfies RequestResponseActionSpec`) so its literal types
|
|
10
10
|
* survive; nothing parses a spec at runtime. Its `input` and `output` are
|
|
11
|
-
*
|
|
11
|
+
* `@fuzdev/fuz_schema` schemas (`AnySchema`).
|
|
12
12
|
* The registration-time checks live in `actions/compile_action_registry.ts`.
|
|
13
13
|
*
|
|
14
14
|
* @see `actions/action_rpc.ts` for the JSON-RPC dispatcher
|
|
@@ -16,11 +16,9 @@
|
|
|
16
16
|
*
|
|
17
17
|
* @module
|
|
18
18
|
*/
|
|
19
|
-
import type
|
|
20
|
-
import { type Infer, type void as fuz_void } from '@fuzdev/fuz_schema/schema.ts';
|
|
19
|
+
import { type Infer, type void as fuz_void, type AnySchema } from '@fuzdev/fuz_schema/schema.ts';
|
|
21
20
|
import type { RateLimitKey } from '../rate_limiter.js';
|
|
22
21
|
import type { RouteAuth } from '../http/auth_shape.js';
|
|
23
|
-
import type { ValidationSchema } from '../schema_issues.js';
|
|
24
22
|
/** The action kinds, in declaration order — what `ActionKind` and `is_action_spec` read. */
|
|
25
23
|
export declare const ACTION_KINDS: readonly ["request_response", "remote_notification", "local_call"];
|
|
26
24
|
export declare const ActionKind: import("@fuzdev/fuz_schema/schema.ts").Schema<"request_response" | "remote_notification" | "local_call", "request_response" | "remote_notification" | "local_call", "one_of", readonly ["request_response", "remote_notification", "local_call"]>;
|
|
@@ -48,10 +46,10 @@ export interface ActionSpec {
|
|
|
48
46
|
*/
|
|
49
47
|
auth: RouteAuth | null;
|
|
50
48
|
side_effects: boolean;
|
|
51
|
-
/** The input schema
|
|
52
|
-
input:
|
|
53
|
-
/** The output schema
|
|
54
|
-
output:
|
|
49
|
+
/** The input schema. */
|
|
50
|
+
input: AnySchema;
|
|
51
|
+
/** The output schema. */
|
|
52
|
+
output: AnySchema;
|
|
55
53
|
async: boolean;
|
|
56
54
|
description: string;
|
|
57
55
|
/**
|
|
@@ -100,12 +98,12 @@ export interface RequestResponseActionSpec extends ActionSpec {
|
|
|
100
98
|
auth: RouteAuth;
|
|
101
99
|
async: true;
|
|
102
100
|
}
|
|
103
|
-
/** A one-way message; its output is
|
|
101
|
+
/** A one-way message; its output is fuz_schema's void schema, `s.void`. */
|
|
104
102
|
export interface RemoteNotificationActionSpec extends ActionSpec {
|
|
105
103
|
kind: 'remote_notification';
|
|
106
104
|
auth: null;
|
|
107
105
|
side_effects: true;
|
|
108
|
-
output:
|
|
106
|
+
output: typeof fuz_void;
|
|
109
107
|
async: true;
|
|
110
108
|
}
|
|
111
109
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action_spec.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/action_spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"action_spec.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/action_spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAEN,KAAK,KAAK,EACV,KAAK,IAAI,IAAI,QAAQ,EACrB,KAAK,SAAS,EACd,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,4FAA4F;AAC5F,eAAO,MAAM,YAAY,oEAAqE,CAAC;AAC/F,eAAO,MAAM,UAAU,mPAAuB,CAAC;AAC/C,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAElD,qEAAqE;AACrE,eAAO,MAAM,iBAAiB,0CAA2C,CAAC;AAC1E,eAAO,MAAM,eAAe,qKAA4B,CAAC;AACzD,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAE5D,4EAA4E;AAC5E,MAAM,WAAW,UAAU;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,CAAC;IACjB,SAAS,EAAE,eAAe,CAAC;IAC3B;;;;;;;;;;;OAWG;IACH,IAAI,EAAE,SAAS,GAAG,IAAI,CAAC;IACvB,YAAY,EAAE,OAAO,CAAC;IACtB,wBAAwB;IACxB,KAAK,EAAE,SAAS,CAAC;IACjB,yBAAyB;IACzB,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;;;OAQG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACtC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,UAAU,CAAC,EAAE,YAAY,CAAC;CAC1B;AAED,iEAAiE;AACjE,MAAM,WAAW,yBAA0B,SAAQ,UAAU;IAC5D,IAAI,EAAE,kBAAkB,CAAC;IACzB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,IAAI,CAAC;CACZ;AAED,2EAA2E;AAC3E,MAAM,WAAW,4BAA6B,SAAQ,UAAU;IAC/D,IAAI,EAAE,qBAAqB,CAAC;IAC5B,IAAI,EAAE,IAAI,CAAC;IACX,YAAY,EAAE,IAAI,CAAC;IACnB,MAAM,EAAE,OAAO,QAAQ,CAAC;IACxB,KAAK,EAAE,IAAI,CAAC;CACZ;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAoB,SAAQ,UAAU;IACtD,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;CACX;AAED,gDAAgD;AAChD,MAAM,MAAM,eAAe,GAC1B,yBAAyB,GAAG,4BAA4B,GAAG,mBAAmB,CAAC;AAEhF,wGAAwG;AACxG,eAAO,MAAM,cAAc,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,eAKK,CAAC;AAE/D,+DAA+D;AAC/D,eAAO,MAAM,mBAAmB,gJAUtB,CAAC;AACX,eAAO,MAAM,gBAAgB,meAA8B,CAAC;AAC5D,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC"}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* A spec is a plain object typed by these interfaces, written with
|
|
9
9
|
* `satisfies` (`satisfies RequestResponseActionSpec`) so its literal types
|
|
10
10
|
* survive; nothing parses a spec at runtime. Its `input` and `output` are
|
|
11
|
-
*
|
|
11
|
+
* `@fuzdev/fuz_schema` schemas (`AnySchema`).
|
|
12
12
|
* The registration-time checks live in `actions/compile_action_registry.ts`.
|
|
13
13
|
*
|
|
14
14
|
* @see `actions/action_rpc.ts` for the JSON-RPC dispatcher
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
* @module
|
|
20
20
|
*/
|
|
21
21
|
import type { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
22
|
+
import type { Infer } from '@fuzdev/fuz_schema/schema.ts';
|
|
22
23
|
import type { ActionSpecUnion, RequestResponseActionSpec } from './action_spec.js';
|
|
23
24
|
import type { Uuid } from '../primitive_schemas.js';
|
|
24
25
|
import type { RequestActorContext, RequestContext } from '../auth/request_context.js';
|
|
@@ -26,7 +27,6 @@ import type { BuiltinCredentialType } from '../auth/credential_type_schema.js';
|
|
|
26
27
|
import type { Db } from '../db/db.js';
|
|
27
28
|
import type { JsonrpcRequestId } from '../http/jsonrpc.js';
|
|
28
29
|
import type { RequestClient } from './peer_request.js';
|
|
29
|
-
import type { ValidationOutput } from '../schema_issues.js';
|
|
30
30
|
/**
|
|
31
31
|
* A spec paired with its optional handler — the composable unit passed to
|
|
32
32
|
* `register_action_ws` and `create_rpc_client`. The server uses both
|
|
@@ -210,16 +210,16 @@ export interface RpcAction {
|
|
|
210
210
|
*/
|
|
211
211
|
export type HandlerForSpec<TSpec extends RequestResponseActionSpec> = [
|
|
212
212
|
TSpec['auth']['actor']
|
|
213
|
-
] extends ['required'] ? ActorActionHandler<
|
|
213
|
+
] extends ['required'] ? ActorActionHandler<Infer<TSpec['input']>, Infer<TSpec['output']>> : [TSpec['auth']['account']] extends ['required'] ? AuthActionHandler<Infer<TSpec['input']>, Infer<TSpec['output']>> : ActionHandler<Infer<TSpec['input']>, Infer<TSpec['output']>>;
|
|
214
214
|
/**
|
|
215
215
|
* Pair a spec with a handler while preserving per-method input/output types
|
|
216
216
|
* and selecting the narrowest `ctx.auth` shape the spec literal admits.
|
|
217
217
|
*
|
|
218
218
|
* Constructing `{spec, handler}` literals widens `handler` to
|
|
219
|
-
* `ActionHandler<any, any>`, so spec/handler drift (renamed
|
|
219
|
+
* `ActionHandler<any, any>`, so spec/handler drift (renamed schema,
|
|
220
220
|
* output field removal, input shape change) slips past the typechecker.
|
|
221
221
|
* `rpc_action(spec, handler)` binds the handler signature to
|
|
222
|
-
* `(input:
|
|
222
|
+
* `(input: Infer<spec.input>, ctx) => Infer<spec.output>` via the
|
|
223
223
|
* generic spec parameter — drift surfaces at the call site.
|
|
224
224
|
*
|
|
225
225
|
* The `ctx.auth` narrowing follows the spec's `auth.account` /
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action_types.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/action_types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"action_types.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/action_types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAE1D,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACtF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD;;;;;;;;;;;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CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,SAAS,yBAAyB,EACjE,MAAM,KAAK,EACX,SAAS,cAAc,CAAC,KAAK,CAAC,KAC5B,SAGD,CAAC"}
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
* and selecting the narrowest `ctx.auth` shape the spec literal admits.
|
|
24
24
|
*
|
|
25
25
|
* Constructing `{spec, handler}` literals widens `handler` to
|
|
26
|
-
* `ActionHandler<any, any>`, so spec/handler drift (renamed
|
|
26
|
+
* `ActionHandler<any, any>`, so spec/handler drift (renamed schema,
|
|
27
27
|
* output field removal, input shape change) slips past the typechecker.
|
|
28
28
|
* `rpc_action(spec, handler)` binds the handler signature to
|
|
29
|
-
* `(input:
|
|
29
|
+
* `(input: Infer<spec.input>, ctx) => Infer<spec.output>` via the
|
|
30
30
|
* generic spec parameter — drift surfaces at the call site.
|
|
31
31
|
*
|
|
32
32
|
* The `ctx.auth` narrowing follows the spec's `auth.account` /
|
|
@@ -79,8 +79,8 @@ export interface CreateBroadcastApiOptions {
|
|
|
79
79
|
*
|
|
80
80
|
* ```ts
|
|
81
81
|
* export interface BackendActionsApi {
|
|
82
|
-
* filer_change: (input:
|
|
83
|
-
* workspace_changed: (input:
|
|
82
|
+
* filer_change: (input: ActionCallInputs['filer_change']) => Promise<void>;
|
|
83
|
+
* workspace_changed: (input: ActionCallInputs['workspace_changed']) => Promise<void>;
|
|
84
84
|
* }
|
|
85
85
|
*
|
|
86
86
|
* const api = create_broadcast_api<BackendActionsApi>({
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
* @module
|
|
19
19
|
*/
|
|
20
20
|
import { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
21
|
+
import { parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
21
22
|
import { create_jsonrpc_notification, to_jsonrpc_params } from '../http/jsonrpc_helpers.js';
|
|
22
|
-
import { parse_any } from '../schema_issues.js';
|
|
23
23
|
/**
|
|
24
24
|
* Builds a typed broadcast API from a set of action specs.
|
|
25
25
|
*
|
|
@@ -38,8 +38,8 @@ import { parse_any } from '../schema_issues.js';
|
|
|
38
38
|
*
|
|
39
39
|
* ```ts
|
|
40
40
|
* export interface BackendActionsApi {
|
|
41
|
-
* filer_change: (input:
|
|
42
|
-
* workspace_changed: (input:
|
|
41
|
+
* filer_change: (input: ActionCallInputs['filer_change']) => Promise<void>;
|
|
42
|
+
* workspace_changed: (input: ActionCallInputs['workspace_changed']) => Promise<void>;
|
|
43
43
|
* }
|
|
44
44
|
*
|
|
45
45
|
* const api = create_broadcast_api<BackendActionsApi>({
|
|
@@ -59,7 +59,7 @@ export const create_broadcast_api = (options) => {
|
|
|
59
59
|
for (const spec of specs) {
|
|
60
60
|
const { method } = spec;
|
|
61
61
|
const send = (input) => {
|
|
62
|
-
const parsed =
|
|
62
|
+
const parsed = parse(spec.input, input);
|
|
63
63
|
if (!parsed.ok) {
|
|
64
64
|
log?.error(`[${method}] input validation failed:`, parsed.issues);
|
|
65
65
|
return;
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
* numbered — "registry-time invariant N" elsewhere in the codebase refers to
|
|
8
8
|
* the `RouteAuth` cross-axis set in `http/auth_shape.ts`, a different list):
|
|
9
9
|
*
|
|
10
|
-
* - **Schema slots** — `input` and `output` each hold a
|
|
11
|
-
* `@fuzdev/fuz_schema` schema (`assert_validation_schema`); a value
|
|
12
|
-
*
|
|
10
|
+
* - **Schema slots** — `input` and `output` each hold a
|
|
11
|
+
* `@fuzdev/fuz_schema` schema (`assert_validation_schema`); a value that
|
|
12
|
+
* is no schema throws naming the action and the slot. Fires for every
|
|
13
13
|
* spec, before the checks that read the schemas.
|
|
14
14
|
* - **Auth-shape cross-axis invariants** — per `assert_route_auth_invariants`
|
|
15
15
|
* in `http/auth_shape.ts`: roles imply a required actor, no accountless
|
|
@@ -33,9 +33,8 @@
|
|
|
33
33
|
* request there is no key for the per-account bucket.
|
|
34
34
|
* - **JSON-RPC §4.2 wire validity** — `request_response` specs whose
|
|
35
35
|
* handler will reach the dispatch map must not use a null schema
|
|
36
|
-
* (`
|
|
37
|
-
*
|
|
38
|
-
* `s.void`, for parameterless methods), nor a void schema for output (a
|
|
36
|
+
* (`literal(null)`) for input (the wire format forbids `"params": null`;
|
|
37
|
+
* use a void schema, `s.void`, for parameterless methods), nor a void schema for output (a
|
|
39
38
|
* response always carries a `result`, which clients validate against
|
|
40
39
|
* `spec.output`; use a null schema for methods with nothing to return).
|
|
41
40
|
* - **Duplicate method names** — JSON-RPC keys on `method`, so every
|
|
@@ -66,7 +65,7 @@ export interface ActionRegistryCompileResult {
|
|
|
66
65
|
*
|
|
67
66
|
* @param actions - polymorphic action array; HTTP RPC passes `RpcAction[]` (narrower), WebSocket passes `Action[]` (kind-polymorphic — handler-less notification specs are accepted)
|
|
68
67
|
* @param ctx_label - per-spec error-message prefix, e.g. `'RPC action'` or `'WS action'`. Combined with the spec method as `${ctx_label} "${method}"`.
|
|
69
|
-
* @throws Error on a schema slot holding a value
|
|
68
|
+
* @throws Error on a schema slot holding a value that is no schema, a cross-axis invariant or biconditional violation, rate-limit/account-axis mismatch, JSON-RPC null-input or void-output, or duplicate method.
|
|
70
69
|
*/
|
|
71
70
|
export declare const compile_action_registry: (actions: ReadonlyArray<Action>, ctx_label: string) => ActionRegistryCompileResult;
|
|
72
71
|
//# sourceMappingURL=compile_action_registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile_action_registry.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/compile_action_registry.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"compile_action_registry.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/compile_action_registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAQ3D,oDAAoD;AACpD,MAAM,WAAW,2BAA2B;IAC3C;;;;;OAKG;IACH,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CACnC;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,GACnC,SAAS,aAAa,CAAC,MAAM,CAAC,EAC9B,WAAW,MAAM,KACf,2BAuDF,CAAC"}
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
* numbered — "registry-time invariant N" elsewhere in the codebase refers to
|
|
8
8
|
* the `RouteAuth` cross-axis set in `http/auth_shape.ts`, a different list):
|
|
9
9
|
*
|
|
10
|
-
* - **Schema slots** — `input` and `output` each hold a
|
|
11
|
-
* `@fuzdev/fuz_schema` schema (`assert_validation_schema`); a value
|
|
12
|
-
*
|
|
10
|
+
* - **Schema slots** — `input` and `output` each hold a
|
|
11
|
+
* `@fuzdev/fuz_schema` schema (`assert_validation_schema`); a value that
|
|
12
|
+
* is no schema throws naming the action and the slot. Fires for every
|
|
13
13
|
* spec, before the checks that read the schemas.
|
|
14
14
|
* - **Auth-shape cross-axis invariants** — per `assert_route_auth_invariants`
|
|
15
15
|
* in `http/auth_shape.ts`: roles imply a required actor, no accountless
|
|
@@ -33,9 +33,8 @@
|
|
|
33
33
|
* request there is no key for the per-account bucket.
|
|
34
34
|
* - **JSON-RPC §4.2 wire validity** — `request_response` specs whose
|
|
35
35
|
* handler will reach the dispatch map must not use a null schema
|
|
36
|
-
* (`
|
|
37
|
-
*
|
|
38
|
-
* `s.void`, for parameterless methods), nor a void schema for output (a
|
|
36
|
+
* (`literal(null)`) for input (the wire format forbids `"params": null`;
|
|
37
|
+
* use a void schema, `s.void`, for parameterless methods), nor a void schema for output (a
|
|
39
38
|
* response always carries a `result`, which clients validate against
|
|
40
39
|
* `spec.output`; use a null schema for methods with nothing to return).
|
|
41
40
|
* - **Duplicate method names** — JSON-RPC keys on `method`, so every
|
|
@@ -58,7 +57,7 @@ import { assert_validation_schema } from '../schema_issues.js';
|
|
|
58
57
|
*
|
|
59
58
|
* @param actions - polymorphic action array; HTTP RPC passes `RpcAction[]` (narrower), WebSocket passes `Action[]` (kind-polymorphic — handler-less notification specs are accepted)
|
|
60
59
|
* @param ctx_label - per-spec error-message prefix, e.g. `'RPC action'` or `'WS action'`. Combined with the spec method as `${ctx_label} "${method}"`.
|
|
61
|
-
* @throws Error on a schema slot holding a value
|
|
60
|
+
* @throws Error on a schema slot holding a value that is no schema, a cross-axis invariant or biconditional violation, rate-limit/account-axis mismatch, JSON-RPC null-input or void-output, or duplicate method.
|
|
62
61
|
*/
|
|
63
62
|
export const compile_action_registry = (actions, ctx_label) => {
|
|
64
63
|
const action_map = new Map();
|
|
@@ -90,10 +89,10 @@ export const compile_action_registry = (actions, ctx_label) => {
|
|
|
90
89
|
// stay registry-only and bypass JSON-RPC wire-validity checks.
|
|
91
90
|
if (spec.kind === 'request_response' && action.handler) {
|
|
92
91
|
if (is_null_schema(spec.input)) {
|
|
93
|
-
throw new Error(`${ctx} uses a null schema for input (
|
|
92
|
+
throw new Error(`${ctx} uses a null schema for input (literal(null)) — JSON-RPC 2.0 §4.2 forbids "params": null on the wire. Use a void schema (s.void) for parameterless methods.`);
|
|
94
93
|
}
|
|
95
94
|
if (is_void_schema(spec.output)) {
|
|
96
|
-
throw new Error(`${ctx} uses a void schema for output (
|
|
95
|
+
throw new Error(`${ctx} uses a void schema for output (s.void) — a JSON-RPC response always carries a result, and clients validate it against spec.output, so no response could match. Use a null schema (literal(null)) for methods with nothing to return.`);
|
|
97
96
|
}
|
|
98
97
|
action_map.set(spec.method, { spec, handler: action.handler });
|
|
99
98
|
}
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* `__proto__` key at any depth (`json_has_own_proto_key`) are refused
|
|
32
32
|
* with `data.reason` `params_proto_key` (`ERROR_PARAMS_PROTO_KEY`), on
|
|
33
33
|
* every input schema, before it runs; then
|
|
34
|
-
* `spec.input` parses the params (`
|
|
34
|
+
* `spec.input` parses the params (`parse`) with
|
|
35
35
|
* void / `?? {}` rules (`to_input_params`). A refusal is the generic
|
|
36
36
|
* `invalid params`, with `data.reason` when the first issue's field
|
|
37
37
|
* declares an `invalid_reason` (`to_invalid_params_error`) and the
|
|
@@ -61,11 +61,11 @@
|
|
|
61
61
|
* @module
|
|
62
62
|
*/
|
|
63
63
|
import type { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
64
|
+
import { type SchemaIssue, type AnySchema } from '@fuzdev/fuz_schema/schema.ts';
|
|
64
65
|
import type { Uuid } from '../primitive_schemas.js';
|
|
65
66
|
import { type RequestContext } from '../auth/request_context.js';
|
|
66
67
|
import { type ResolvedAuth } from '../auth/resolved_auth.js';
|
|
67
68
|
import type { Db } from '../db/db.js';
|
|
68
|
-
import { type AnyIssue, type ValidationSchema } from '../schema_issues.js';
|
|
69
69
|
import { type JsonrpcRequestId, type JsonrpcErrorObject } from '../http/jsonrpc.js';
|
|
70
70
|
import type { RateLimiter } from '../rate_limiter.js';
|
|
71
71
|
import type { RpcAction } from './action_types.js';
|
|
@@ -77,7 +77,7 @@ import type { RequestClient } from './peer_request.js';
|
|
|
77
77
|
export interface PerformActionInput {
|
|
78
78
|
/** The resolved spec + handler (transport does method lookup). */
|
|
79
79
|
action: RpcAction;
|
|
80
|
-
/** Raw params from the wire envelope (validated by `JsonrpcRequest`, pre-`
|
|
80
|
+
/** Raw params from the wire envelope (validated by `JsonrpcRequest`, pre-`parse(spec.input, …)`). */
|
|
81
81
|
raw_params: unknown;
|
|
82
82
|
/** JSON-RPC request id — echoed onto the response. */
|
|
83
83
|
request_id: JsonrpcRequestId;
|
|
@@ -175,12 +175,12 @@ export declare const perform_action: (input: PerformActionInput, deps: PerformAc
|
|
|
175
175
|
* DEV only (`dev_only`). With no declared reason, production sends no `data` at
|
|
176
176
|
* all.
|
|
177
177
|
*
|
|
178
|
-
* @param input - the action's input schema
|
|
179
|
-
* @param issues - the failed parse's issues, in the
|
|
178
|
+
* @param input - the action's input schema
|
|
179
|
+
* @param issues - the failed parse's issues, in the parse's order
|
|
180
180
|
* @param params - the value that was parsed
|
|
181
181
|
* @returns the JSON-RPC error object
|
|
182
182
|
*/
|
|
183
|
-
export declare const to_invalid_params_error: (input:
|
|
183
|
+
export declare const to_invalid_params_error: (input: AnySchema, issues: ReadonlyArray<SchemaIssue>, params: unknown) => JsonrpcErrorObject;
|
|
184
184
|
/**
|
|
185
185
|
* The credential-type 403 — one builder, so the dispatcher's gate below and a
|
|
186
186
|
* handler that gates a credential channel on its input (`account_delete`'s
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perform_action.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/perform_action.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAGN,KAAK,YAAY,EACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"perform_action.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/perform_action.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAS,KAAK,WAAW,E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CAAC"}
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* `__proto__` key at any depth (`json_has_own_proto_key`) are refused
|
|
32
32
|
* with `data.reason` `params_proto_key` (`ERROR_PARAMS_PROTO_KEY`), on
|
|
33
33
|
* every input schema, before it runs; then
|
|
34
|
-
* `spec.input` parses the params (`
|
|
34
|
+
* `spec.input` parses the params (`parse`) with
|
|
35
35
|
* void / `?? {}` rules (`to_input_params`). A refusal is the generic
|
|
36
36
|
* `invalid params`, with `data.reason` when the first issue's field
|
|
37
37
|
* declares an `invalid_reason` (`to_invalid_params_error`) and the
|
|
@@ -61,11 +61,12 @@
|
|
|
61
61
|
* @module
|
|
62
62
|
*/
|
|
63
63
|
import { DEV } from 'esm-env';
|
|
64
|
+
import { parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
64
65
|
import { apply_authorization_phase, has_any_scoped_role } from '../auth/request_context.js';
|
|
65
66
|
import { resolved_auth_scope, resolved_auth_session_hash } from '../auth/resolved_auth.js';
|
|
66
67
|
import { is_db_checkout_error } from '../db/db_checkout_error.js';
|
|
67
68
|
import { resolve_issues_invalid_reason } from '../schema_meta.js';
|
|
68
|
-
import {
|
|
69
|
+
import { to_wire_issues } from '../schema_issues.js';
|
|
69
70
|
import { json_has_own_proto_key, to_input_params } from '../http/schema_helpers.js';
|
|
70
71
|
import { rate_limit_ip_key } from '../http/ip_canonical.js';
|
|
71
72
|
import { dispatch_with_post_commit_rollback } from '../http/pending_effects.js';
|
|
@@ -169,12 +170,12 @@ export const perform_action = async (input, deps) => {
|
|
|
169
170
|
// step 5: validate params. JSON-RPC 2.0 §4.2 forbids `params: null`;
|
|
170
171
|
// registration sites reject null-schema inputs. Empty-body convention
|
|
171
172
|
// (`raw_params ?? {}`) lets all-optional-object methods omit `params`;
|
|
172
|
-
// a void input
|
|
173
|
+
// a void input reads every empty shape as the no-arg call — see
|
|
173
174
|
// `to_input_params`.
|
|
174
175
|
//
|
|
175
176
|
// An own `__proto__` key anywhere in object params is refused first, on
|
|
176
|
-
// every input:
|
|
177
|
-
//
|
|
177
|
+
// every input: a loose schema passes it through, so a schema alone would
|
|
178
|
+
// store it — a sink for
|
|
178
179
|
// any client that copies the value back with plain assignment. Only an
|
|
179
180
|
// object is walked, so a non-object `params` is the schema's refusal, as
|
|
180
181
|
// the Rust twin's shape check answers it ahead of its walk.
|
|
@@ -185,7 +186,7 @@ export const perform_action = async (input, deps) => {
|
|
|
185
186
|
return error_result(jsonrpc_error_messages.invalid_params('invalid params', { reason: ERROR_PARAMS_PROTO_KEY }));
|
|
186
187
|
}
|
|
187
188
|
const params = to_input_params(spec.input, raw_params);
|
|
188
|
-
const parse_result =
|
|
189
|
+
const parse_result = parse(spec.input, params);
|
|
189
190
|
if (!parse_result.ok) {
|
|
190
191
|
return error_result(to_invalid_params_error(spec.input, parse_result.issues, params));
|
|
191
192
|
}
|
|
@@ -211,7 +212,7 @@ export const perform_action = async (input, deps) => {
|
|
|
211
212
|
const output = await handler(validated_input, action_context);
|
|
212
213
|
// DEV-only output validation — logs on mismatch, never throws.
|
|
213
214
|
if (DEV) {
|
|
214
|
-
const output_result =
|
|
215
|
+
const output_result = parse(spec.output, output);
|
|
215
216
|
if (!output_result.ok) {
|
|
216
217
|
log.error(`action output schema mismatch: ${spec.method}`, output_result.issues);
|
|
217
218
|
}
|
|
@@ -263,14 +264,14 @@ const thrown_error_result = (err, context, log) => {
|
|
|
263
264
|
* DEV only (`dev_only`). With no declared reason, production sends no `data` at
|
|
264
265
|
* all.
|
|
265
266
|
*
|
|
266
|
-
* @param input - the action's input schema
|
|
267
|
-
* @param issues - the failed parse's issues, in the
|
|
267
|
+
* @param input - the action's input schema
|
|
268
|
+
* @param issues - the failed parse's issues, in the parse's order
|
|
268
269
|
* @param params - the value that was parsed
|
|
269
270
|
* @returns the JSON-RPC error object
|
|
270
271
|
*/
|
|
271
272
|
export const to_invalid_params_error = (input, issues, params) => {
|
|
272
273
|
const reason = resolve_issues_invalid_reason(input, issues, params);
|
|
273
|
-
const issues_data = dev_only(() => ({ issues: to_wire_issues(issues
|
|
274
|
+
const issues_data = dev_only(() => ({ issues: to_wire_issues(issues) }));
|
|
274
275
|
return jsonrpc_error_messages.invalid_params('invalid params', reason === undefined ? issues_data : { reason, ...issues_data });
|
|
275
276
|
};
|
|
276
277
|
const error_result = (error) => ({
|
|
@@ -327,7 +327,7 @@ export declare class FrontendWebsocketClient implements WebsocketConnection, Dis
|
|
|
327
327
|
*
|
|
328
328
|
* An `undefined` `params` is omitted from the frame rather than sent as
|
|
329
329
|
* `{}` — the absent form is the parameterless call every server admits
|
|
330
|
-
* for a
|
|
330
|
+
* for a void input, including servers that refuse `{}`.
|
|
331
331
|
*
|
|
332
332
|
* Callers supplying an explicit `options.id` are responsible for
|
|
333
333
|
* uniqueness — the pending map is keyed by id, and a duplicate silently
|
|
@@ -411,7 +411,7 @@ export class FrontendWebsocketClient {
|
|
|
411
411
|
*
|
|
412
412
|
* An `undefined` `params` is omitted from the frame rather than sent as
|
|
413
413
|
* `{}` — the absent form is the parameterless call every server admits
|
|
414
|
-
* for a
|
|
414
|
+
* for a void input, including servers that refuse `{}`.
|
|
415
415
|
*
|
|
416
416
|
* Callers supplying an explicit `options.id` are responsible for
|
|
417
417
|
* uniqueness — the pending map is keyed by id, and a duplicate silently
|
|
@@ -462,7 +462,7 @@ export class FrontendWebsocketClient {
|
|
|
462
462
|
const id = options.id ?? ++this.#next_request_id;
|
|
463
463
|
// an `undefined` `params` is omitted, never defaulted to `{}` — the
|
|
464
464
|
// absent form is JSON-RPC 2.0 §4.2's parameterless call and the one
|
|
465
|
-
// shape every server admits for a
|
|
465
|
+
// shape every server admits for a void input, including
|
|
466
466
|
// servers that refuse `{}`
|
|
467
467
|
const frame = params === undefined
|
|
468
468
|
? { jsonrpc: JSONRPC_VERSION, id, method }
|
package/dist/auth/CLAUDE.md
CHANGED
|
@@ -54,18 +54,18 @@ Cross-cutting notes that don't live on any single symbol:
|
|
|
54
54
|
|
|
55
55
|
### Schemas, types, DDL
|
|
56
56
|
|
|
57
|
-
Convention — `*_schema.ts` holds a domain's
|
|
57
|
+
Convention — `*_schema.ts` holds a domain's `@fuzdev/fuz_schema` schemas; `*_ddl.ts` holds DDL strings.
|
|
58
58
|
|
|
59
59
|
- `auth/account_schema.ts` — `Account`, `Actor`, `RoleGrant`, `AuthSession`, `ApiToken` + client-safe JSON shapes, `@fuzdev/fuz_schema` schemas: `SessionId` (`brand(Blake3Hash, 'SessionId')`, minted by `hash_session_token`), `SessionAccountJson` and `AdminAccountJson` (their `username` `UsernameCanonical`, so a username in another case fails), `AuthSessionJson`, `RoleGrantSummaryJson` and `PendingOfferSummaryJson` (`role` a `RoleName`, `scope_kind` a `ScopeKindName` or `null`), `ActorSummaryJson`, `AdminAccountEntryJson`, `ClientApiTokenJson` (`id` an `ApiTokenId`); every timestamp a `Timestamp`. Grant predicates over wire fields: `is_role_grant_active` (not revoked, not expired) and `has_global_role(role_grants, role, now?)` (an active grant of the role with `scope_id === null` — the bare-list form of `has_scoped_role(ctx, role, null)`, used client-side by `AuthState`).
|
|
60
60
|
- `auth/name_schema.ts` — the name grammar the auth vocabularies share: `NAME_REGEX` (runs of lowercase letters joined by single underscores), `NAME_LENGTH_MAX` (64), `is_valid_name`, `create_name_schema(label)` (the `@fuzdev/fuz_schema` schema, `pipe(bounded_string, message(regex))`: a string too long and off the grammar gets the one length issue, a value that is no string fuz_schema's message; its JSON Schema `maxLength` and `pattern`) and the message builders `format_name_length_message` / `format_name_pattern_message`, so each domain keeps its own label in its messages. `RoleName`, `ScopeKindName`, `GrantPathName`, `CredentialTypeName` and a token's `surface:` name (`is_route_scope_capability`) hold it; `AuditEventTypeName` takes its cap over its own grammar. Twin of the Rust `fuz_auth::is_valid_name` / `NAME_LENGTH_MAX`.
|
|
61
|
-
- `auth/role_schema.ts` — `RoleName` (`create_name_schema('Role')`: lowercase letters and underscores, no leading, trailing or consecutive underscores, at most `NAME_LENGTH_MAX` = 64 characters — the grammar every `role` input and every registered role holds, twin of the Rust `is_valid_name`), its messages (`ROLE_NAME_LENGTH_MESSAGE`, `ROLE_NAME_PATTERN_MESSAGE`), `RoleSpec`, `ROLE_KEEPER`, `ROLE_ADMIN`, `BUILTIN_ROLES` and its type `BuiltinRole`, `is_builtin_role`, `create_role_registry` (returns `{role_specs}`), `builtin_role_specs`, `role_has_grant_path`, `list_roles_with_grant_path`. Pinned
|
|
62
|
-
- `auth/scope_kind_schema.ts` — `ScopeKindName`, the constants its messages come from (`SCOPE_KIND_NAME_LENGTH_MESSAGE`, `SCOPE_KIND_NAME_PATTERN_MESSAGE`), `create_scope_kind_registry` (open registry, no builtins; returns `{scope_kinds}`). `ScopeKindName` (`create_name_schema('Scope-kind')`, grammar and cap) checks a registered name and the `scope_kind` on `role_grant_offer_create` / `role_grant_assign`, which is copied into the row and its audit metadata; off the grammar is the partial unique indexes' `'GLOBAL'` token. Pinned
|
|
61
|
+
- `auth/role_schema.ts` — `RoleName` (`create_name_schema('Role')`: lowercase letters and underscores, no leading, trailing or consecutive underscores, at most `NAME_LENGTH_MAX` = 64 characters — the grammar every `role` input and every registered role holds, twin of the Rust `is_valid_name`), its messages (`ROLE_NAME_LENGTH_MESSAGE`, `ROLE_NAME_PATTERN_MESSAGE`), `RoleSpec`, `ROLE_KEEPER`, `ROLE_ADMIN`, `BUILTIN_ROLES` and its type `BuiltinRole`, `is_builtin_role`, `create_role_registry` (returns `{role_specs}`), `builtin_role_specs`, `role_has_grant_path`, `list_roles_with_grant_path`. Pinned by the vector table of `role_schema.name.test.ts`.
|
|
62
|
+
- `auth/scope_kind_schema.ts` — `ScopeKindName`, the constants its messages come from (`SCOPE_KIND_NAME_LENGTH_MESSAGE`, `SCOPE_KIND_NAME_PATTERN_MESSAGE`), `create_scope_kind_registry` (open registry, no builtins; returns `{scope_kinds}`). `ScopeKindName` (`create_name_schema('Scope-kind')`, grammar and cap) checks a registered name and the `scope_kind` on `role_grant_offer_create` / `role_grant_assign`, which is copied into the row and its audit metadata; off the grammar is the partial unique indexes' `'GLOBAL'` token. Pinned by the vector table of `scope_kind_schema.name.test.ts`.
|
|
63
63
|
- `auth/credential_type_schema.ts` — `CredentialTypeName` (`create_name_schema('Credential-type')`), `CREDENTIAL_TYPE_SESSION` / `_API_TOKEN` / `_DAEMON_TOKEN`, `BUILTIN_CREDENTIAL_TYPES` and its type `BuiltinCredentialType`, `create_credential_type_registry` (returns `{credential_types}`).
|
|
64
64
|
- `auth/grant_path_schema.ts` — `GrantPathName` (`create_name_schema('Grant-path')`), `GRANT_PATH_ADMIN` / `_SELF_SERVICE` / `_SYSTEM` / `_BOOTSTRAP`, `BUILTIN_GRANT_PATHS` and its type `BuiltinGrantPath`, `create_grant_path_registry` (returns `{grant_paths}`).
|
|
65
65
|
- `auth/token_lifetime.ts` — the temporal axis of a minted token: `TokenLifetimeInput` (required `variant` on `account_token_create` — `{kind:'eternal'}` or `{kind:'ttl', days}`, a `@fuzdev/fuz_schema` schema), `token_lifetime_to_expires_at`, `TOKEN_TTL_DAYS_MAX`. No default — `expires_at IS NULL` always means "deliberately eternal".
|
|
66
66
|
- `auth/token_scope.ts` — per-credential authority narrowing stored on `api_token.scope`: `TokenScope` / `TokenScopeInput` (`@fuzdev/fuz_schema` `variant`s of strict `object` arms) + constructors, `parse_stored_token_scope` (fail-closed; the `MAX_TOKEN_SCOPE_BYTES` cap counts UTF-8 bytes of the compact document at mint and at read, as the Rust spine does), `token_scope_admits_method` / `_non_rpc`, and the `<section>:<id>` capability vocabulary (`token_scope_method_capability` for the dispatcher's `rpc:<method>`, `is_route_scope_capability` for the `surface:<name>` a `RouteAuth.required_scope` may declare, `token_scope_denied_body`, `TOKEN_SURFACES`). Not an open registry — see ../../../docs/security.md §Token scoping for why the identifier half is deliberately unregistered.
|
|
67
67
|
- `auth/auth_ddl.ts` — `CREATE TABLE` / index / seed strings for the core identity tables.
|
|
68
|
-
- `auth/audit_log_schema.ts` — `@fuzdev/fuz_schema` throughout: `AUDIT_EVENT_TYPES` (the builtin event types) and the type `AuditEventType` (`(typeof AUDIT_EVENT_TYPES)[number]`), `AuditEventTypeName` (`pipe(bounded_string, message(regex))`, `AUDIT_EVENT_TYPE_NAME_REGEX` under `NAME_LENGTH_MAX`, with `AUDIT_EVENT_TYPE_NAME_LENGTH_MESSAGE` / `AUDIT_EVENT_TYPE_NAME_PATTERN_MESSAGE`; a name too long and off the grammar gets the one length issue), `AuditOutcome` (`one_of(['success', 'failure'])`), `audit_metadata_schemas`, `AuditLogEvent`, `AuditLogInput`, `AuditLogConfig
|
|
68
|
+
- `auth/audit_log_schema.ts` — `@fuzdev/fuz_schema` throughout: `AUDIT_EVENT_TYPES` (the builtin event types) and the type `AuditEventType` (`(typeof AUDIT_EVENT_TYPES)[number]`), `AuditEventTypeName` (`pipe(bounded_string, message(regex))`, `AUDIT_EVENT_TYPE_NAME_REGEX` under `NAME_LENGTH_MAX`, with `AUDIT_EVENT_TYPE_NAME_LENGTH_MESSAGE` / `AUDIT_EVENT_TYPE_NAME_PATTERN_MESSAGE`; a name too long and off the grammar gets the one length issue), `AuditOutcome` (`one_of(['success', 'failure'])`), `audit_metadata_schemas`, `AuditLogEvent`, `AuditLogInput`, `AuditLogConfig`, `create_audit_log_config` (refuses an `extra_events` key off `AuditEventTypeName` with its first issue's message), and the wire rows `AuditLogEventJson` (`seq` `pipe(number, safe_integer)`, `created_at` a `Timestamp`), `AuditLogEventWithUsernamesJson`, `RoleGrantHistoryEventJson` and `AdminSessionJson`. `audit_log_list`'s input declares `AuditEventTypeName` and `AuditOutcome`. Pinned by the vector tables of `audit_log_schema.names.test.ts`.
|
|
69
69
|
- `auth/audit_log_ddl.ts` — `audit_log` table DDL with `seq BIGSERIAL` for cursor-based gap fill (BIGSERIAL converges with the Rust spine; `create_db` registers a `pg.types` int8 parser so `seq` still reads as a JS number).
|
|
70
70
|
- `auth/invite_schema.ts` — `Invite`, `CreateInviteInput`, and the `@fuzdev/fuz_schema` rows `InviteJson` (`username` a `UsernameCanonical` or `null`, timestamps `Timestamp`s) and `InviteWithUsernamesJson`, whose resolved names are plain strings.
|
|
71
71
|
- `auth/app_settings_schema.ts` — `AppSettings` (single-row via `CHECK (id = 1)`) and its `@fuzdev/fuz_schema` schemas `AppSettingsJson` and `AppSettingsWithUsernameJson`.
|
|
@@ -549,11 +549,11 @@ TSDoc. The pattern that spans emit sites:
|
|
|
549
549
|
### Audit event extensibility
|
|
550
550
|
|
|
551
551
|
Consumers extend the closed `AUDIT_EVENT_TYPES` enum via
|
|
552
|
-
`create_audit_log_config({extra_events})` — a metadata
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
552
|
+
`create_audit_log_config({extra_events})` — a `@fuzdev/fuz_schema` metadata
|
|
553
|
+
schema or `null` per type; collisions with builtins, name-format failures
|
|
554
|
+
and a value that is no schema throw at construction. `query_audit_log`
|
|
555
|
+
validates through `parse`, and a dropped row's log line masks the
|
|
556
|
+
`sensitivity: 'secret'` fields of an object metadata schema.
|
|
557
557
|
The builtin `audit_metadata_schemas` are fuz_schema `loose_object`s
|
|
558
558
|
(`nullable` where the event may carry none, `literal(null)` for `logout`). The
|
|
559
559
|
DB column is `TEXT NOT NULL` (no enum), so consumer types round-trip through
|
|
@@ -731,8 +731,8 @@ API-removable — auth + daemon-token both pivot on it),
|
|
|
731
731
|
targets the sole remaining active admin (soft-deleted admins don't count; the
|
|
732
732
|
count locks its rows, so concurrent removals can't both pass), `ERROR_INVITE_ACCOUNT_EXISTS_USERNAME` /
|
|
733
733
|
`_EMAIL` / `ERROR_INVITE_DUPLICATE` on invite create, `ERROR_INVITE_NOT_FOUND`
|
|
734
|
-
on invite delete. `invite_create` empty input is rejected at the schema
|
|
735
|
-
|
|
734
|
+
on invite delete. `invite_create` empty input is rejected at the schema by a
|
|
735
|
+
`check` and surfaces as `invalid_params` with `error.data.issues` (DEV-only `WireIssue`s).
|
|
736
736
|
|
|
737
737
|
Closure state:
|
|
738
738
|
|