@fuzdev/fuz_app 0.168.1 → 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 +32 -23
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +101 -80
- 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 +18 -18
- 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/account_action_specs.d.ts +11 -11
- package/dist/auth/account_action_specs.js +1 -1
- package/dist/auth/account_route_schema.d.ts +18 -18
- package/dist/auth/account_route_schema.js +1 -1
- package/dist/auth/account_routes.js +1 -1
- package/dist/auth/account_schema.d.ts +38 -40
- package/dist/auth/account_schema.d.ts.map +1 -1
- package/dist/auth/account_schema.js +7 -8
- package/dist/auth/actor_lookup_action_specs.d.ts +7 -7
- package/dist/auth/actor_lookup_action_specs.js +1 -1
- package/dist/auth/actor_search_action_specs.d.ts +6 -6
- package/dist/auth/actor_search_action_specs.js +1 -1
- package/dist/auth/admin_action_specs.d.ts +166 -166
- package/dist/auth/admin_action_specs.js +1 -1
- package/dist/auth/app_settings_schema.d.ts +3 -3
- package/dist/auth/app_settings_schema.d.ts.map +1 -1
- package/dist/auth/app_settings_schema.js +1 -1
- 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_route_schema.d.ts +1 -1
- package/dist/auth/audit_log_route_schema.js +1 -1
- package/dist/auth/audit_log_schema.d.ts +69 -70
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +2 -2
- package/dist/auth/auth_ddl.d.ts +1 -1
- package/dist/auth/auth_ddl.js +1 -1
- package/dist/auth/bootstrap_route_schema.d.ts +4 -4
- package/dist/auth/bootstrap_route_schema.js +1 -1
- package/dist/auth/cell_action_specs.d.ts +466 -466
- package/dist/auth/cell_action_specs.js +1 -1
- package/dist/auth/cell_actions.d.ts +2 -2
- package/dist/auth/cell_actions.js +5 -5
- package/dist/auth/cell_audit_action_specs.d.ts +14 -14
- package/dist/auth/cell_audit_action_specs.js +1 -1
- package/dist/auth/cell_audit_metadata.d.ts +8 -8
- package/dist/auth/cell_audit_metadata.js +1 -1
- package/dist/auth/cell_field_action_specs.d.ts +55 -55
- package/dist/auth/cell_field_action_specs.js +1 -1
- package/dist/auth/cell_field_audit_metadata.d.ts +4 -4
- package/dist/auth/cell_field_audit_metadata.js +1 -1
- package/dist/auth/cell_grant_action_specs.d.ts +61 -61
- package/dist/auth/cell_grant_action_specs.js +1 -1
- package/dist/auth/cell_grant_audit_metadata.d.ts +10 -10
- package/dist/auth/cell_grant_audit_metadata.js +1 -1
- package/dist/auth/cell_item_action_specs.d.ts +76 -76
- package/dist/auth/cell_item_action_specs.js +1 -1
- package/dist/auth/cell_item_audit_metadata.d.ts +5 -5
- package/dist/auth/cell_item_audit_metadata.js +1 -1
- package/dist/auth/invite_schema.d.ts +11 -11
- package/dist/auth/invite_schema.d.ts.map +1 -1
- package/dist/auth/invite_schema.js +1 -1
- package/dist/auth/name_schema.js +1 -1
- package/dist/auth/password.js +1 -1
- package/dist/auth/request_context.js +2 -2
- package/dist/auth/role_grant_offer_action_specs.d.ts +182 -182
- package/dist/auth/role_grant_offer_action_specs.js +1 -1
- 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 +107 -107
- package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_notifications.js +3 -4
- package/dist/auth/role_grant_offer_schema.d.ts +9 -9
- package/dist/auth/role_grant_offer_schema.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_schema.js +1 -1
- package/dist/auth/self_service_role_action_specs.d.ts +2 -2
- package/dist/auth/self_service_role_action_specs.js +1 -1
- package/dist/auth/self_service_role_actions.d.ts +1 -1
- package/dist/auth/self_service_role_actions.js +1 -1
- package/dist/auth/signup_route_schema.d.ts +2 -2
- package/dist/auth/signup_route_schema.js +1 -1
- package/dist/auth/token_scope.d.ts +8 -8
- package/dist/db/file_fact_url.d.ts +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 +30 -32
- package/dist/http/auth_shape.d.ts +17 -52
- package/dist/http/auth_shape.d.ts.map +1 -1
- package/dist/http/auth_shape.js +19 -61
- package/dist/http/db_routes.d.ts +1 -1
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +1 -1
- package/dist/http/error_schemas.d.ts +36 -36
- package/dist/http/jsonrpc.d.ts +11 -11
- 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 -76
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +6 -8
- package/dist/primitive_schemas.d.ts +162 -112
- package/dist/primitive_schemas.d.ts.map +1 -1
- package/dist/primitive_schemas.js +129 -161
- 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 +41 -146
- package/dist/schema_issues.d.ts.map +1 -1
- package/dist/schema_issues.js +39 -322
- 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/server/serve_fact_route.js +1 -1
- package/dist/server/surface_route.js +1 -1
- package/dist/testing/CLAUDE.md +23 -25
- 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_case.d.ts +96 -114
- package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_case.js +0 -256
- 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/fact_serving.js +1 -1
- 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 +26 -4
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +7 -8
- package/dist/testing/cross_backend/sse_round_trip.js +2 -2
- package/dist/testing/cross_backend/testing_origin_check.d.ts +12 -12
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +608 -201
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +46 -55
- 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_outbound_overflow.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_outbound_overflow.js +35 -0
- 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 -11
- 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 +144 -151
- package/dist/testing/schema_introspect.d.ts +438 -78
- package/dist/testing/schema_introspect.d.ts.map +1 -1
- package/dist/testing/schema_introspect.js +26 -26
- 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/testing/transports/bootstrap.d.ts +1 -1
- package/dist/testing/transports/bootstrap.d.ts.map +1 -1
- package/dist/testing/transports/bootstrap.js +1 -1
- package/dist/ui/BootstrapForm.svelte +1 -2
- package/dist/ui/BootstrapForm.svelte.d.ts.map +1 -1
- package/dist/ui/SignupForm.svelte +1 -2
- package/dist/ui/SignupForm.svelte.d.ts.map +1 -1
- package/dist/ui/admin_accounts_state.svelte.d.ts +5 -5
- package/dist/ui/admin_accounts_state.svelte.d.ts.map +1 -1
- package/dist/ui/admin_invites_state.svelte.d.ts +1 -1
- package/dist/ui/admin_invites_state.svelte.d.ts.map +1 -1
- package/dist/ui/admin_sessions_state.svelte.d.ts +2 -2
- package/dist/ui/admin_sessions_state.svelte.d.ts.map +1 -1
- package/dist/ui/form_state.svelte.d.ts +1 -1
- package/dist/ui/form_state.svelte.js +1 -1
- package/dist/ui/role_grant_offers_state.svelte.d.ts +1 -1
- package/package.json +7 -9
- package/dist/primitive_schemas_fuz.d.ts +0 -178
- package/dist/primitive_schemas_fuz.d.ts.map +0 -1
- package/dist/primitive_schemas_fuz.js +0 -149
- package/dist/zod.d.ts +0 -101
- package/dist/zod.d.ts.map +0 -1
- package/dist/zod.js +0 -195
|
@@ -1,96 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Reusable validator-schema primitives
|
|
3
|
-
* `
|
|
4
|
-
*
|
|
5
|
-
* the
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* entity types + client-safe JSON shapes (its real responsibility) and
|
|
12
|
-
* non-auth consumers can import these primitives without dragging the
|
|
13
|
-
* auth domain along. Future cross-domain primitives (phone, slug) land
|
|
14
|
-
* here too; a URL is `Url` from `@fuzdev/fuz_util/url.ts`.
|
|
2
|
+
* Reusable validator-schema primitives, in `@fuzdev/fuz_schema` —
|
|
3
|
+
* `bounded_string`, `Username` with `UsernameCanonical` and
|
|
4
|
+
* `UsernameProvided`, `Email`, the branded `Uuid` with its factory,
|
|
5
|
+
* `Timestamp`, the hash schemas `FactHashSchema` and `Blake3Hash`, and
|
|
6
|
+
* `ActingActor`. Lives at the top level (not inside `auth/` or `http/`)
|
|
7
|
+
* because these shapes don't depend on or imply any domain — accounts hold a
|
|
8
|
+
* username and email, but invites, password resets, cells, and other surfaces
|
|
9
|
+
* all reach for the same primitives without going through auth. A URL is
|
|
10
|
+
* `Url` from `@fuzdev/fuz_util/url.ts`.
|
|
15
11
|
*
|
|
16
12
|
* Client-safe: nothing here imports `@fuzdev/blake3-wasm`, so wire schemas
|
|
17
13
|
* that validate a hash don't pull the WASM binary into a bundle.
|
|
18
14
|
*
|
|
19
15
|
* @module
|
|
20
16
|
*/
|
|
21
|
-
import {
|
|
17
|
+
import { meta } from '@fuzdev/fuz_schema/meta.ts';
|
|
18
|
+
import { brand, check, iso_datetime, max_length, message, min_length, optional, pipe, regex, string, to_lower_case, transform, uuid, with_default_fn } from '@fuzdev/fuz_schema/schema.ts';
|
|
22
19
|
import { FACT_HASH_EXACT } from '@fuzdev/fuz_util/hash_schemas.ts';
|
|
23
20
|
/**
|
|
24
21
|
* A string schema whose length is bounded in UTF-16 code units — what
|
|
25
22
|
* `String.length` measures, and what the Rust spine counts
|
|
26
23
|
* (`encode_utf16().count()`), so an astral-plane character costs two on both.
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* installed Zod they count code units or Unicode code points, and the peer
|
|
32
|
-
* range admits both. The schema still carries them — they are what puts
|
|
33
|
-
* `minLength` / `maxLength` in the generated JSON Schema — and a check beside
|
|
34
|
-
* them settles the verdict on `String.length`: it adds the over-`max` or
|
|
35
|
-
* under-`min` issue when Zod raised none, and withdraws one Zod raised for a
|
|
36
|
-
* string that is within the bound in units. The issue it adds has the fields
|
|
37
|
-
* of Zod's own and, like Zod's, lets the checks chained after it run, so a
|
|
38
|
-
* refusal reads the same whichever count Zod used.
|
|
39
|
-
*
|
|
40
|
-
* Returns a plain `ZodString`, so format checks, `.brand()`, `.nullish()` and
|
|
41
|
-
* `.meta()` chain as usual. Don't chain a further `.min()` / `.max()` — pass
|
|
42
|
-
* the bound here.
|
|
24
|
+
* fuz_schema's `min_length` / `max_length` read `String.length`. Every length
|
|
25
|
+
* bound on a wire string in the package is built here. Its JSON Schema
|
|
26
|
+
* carries `minLength` / `maxLength`; `max_message` replaces fuz_schema's
|
|
27
|
+
* message on the over-`max` issue.
|
|
43
28
|
*
|
|
44
|
-
* @param options - the bounds, in UTF-16 code units
|
|
29
|
+
* @param options - the bounds, in UTF-16 code units, and the max message
|
|
45
30
|
* @returns the bounded string schema
|
|
46
31
|
*/
|
|
47
32
|
export const bounded_string = (options) => {
|
|
48
33
|
const { min, max, max_message } = options;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
schema = schema.min(min);
|
|
52
|
-
schema = max_message === undefined ? schema.max(max) : schema.max(max, max_message);
|
|
53
|
-
return schema.check((ctx) => {
|
|
54
|
-
const { length } = ctx.value;
|
|
55
|
-
const { issues } = ctx;
|
|
56
|
-
const too_big = issues.findIndex((i) => i.code === 'too_big' && i.origin === 'string' && i.maximum === max);
|
|
57
|
-
if (length > max) {
|
|
58
|
-
if (too_big === -1) {
|
|
59
|
-
issues.push({
|
|
60
|
-
origin: 'string',
|
|
61
|
-
code: 'too_big',
|
|
62
|
-
maximum: max,
|
|
63
|
-
inclusive: true,
|
|
64
|
-
input: ctx.value,
|
|
65
|
-
// as on Zod's own length issues: the checks chained after still run
|
|
66
|
-
continue: true,
|
|
67
|
-
// `path` ahead of `message`, the key order of Zod's finalized issue
|
|
68
|
-
...(max_message !== undefined && { path: [], message: max_message })
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
else if (too_big !== -1) {
|
|
73
|
-
issues.splice(too_big, 1);
|
|
74
|
-
}
|
|
75
|
-
if (min === undefined)
|
|
76
|
-
return;
|
|
77
|
-
const too_small = issues.findIndex((i) => i.code === 'too_small' && i.origin === 'string' && i.minimum === min);
|
|
78
|
-
if (length < min) {
|
|
79
|
-
if (too_small === -1) {
|
|
80
|
-
issues.push({
|
|
81
|
-
origin: 'string',
|
|
82
|
-
code: 'too_small',
|
|
83
|
-
minimum: min,
|
|
84
|
-
inclusive: true,
|
|
85
|
-
input: ctx.value,
|
|
86
|
-
continue: true
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else if (too_small !== -1) {
|
|
91
|
-
issues.splice(too_small, 1);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
34
|
+
const max_step = max_message === undefined ? max_length(max) : message(max_length(max), max_message);
|
|
35
|
+
return min === undefined ? pipe(string, max_step) : pipe(string, min_length(min), max_step);
|
|
94
36
|
};
|
|
95
37
|
/** Minimum username length (must have start + middle + end characters). */
|
|
96
38
|
export const USERNAME_LENGTH_MIN = 3;
|
|
@@ -108,15 +50,45 @@ export const USERNAME_PROVIDED_LENGTH_MAX = 255;
|
|
|
108
50
|
* Username for account creation — starts with letter, alphanumeric/dash/underscore middle, ends with alphanumeric. No @ or . allowed.
|
|
109
51
|
*
|
|
110
52
|
* Canonicalized to lowercase at parse time. The regex rejects whitespace
|
|
111
|
-
* outright, so
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
53
|
+
* outright, so no trim is needed. Storage is canonical across every creation
|
|
54
|
+
* site (bootstrap, signup, admin-create, invite acceptance) because the
|
|
55
|
+
* schema is the single source of truth — eliminates the per-caller
|
|
56
|
+
* `trim().toLowerCase()` ritual and keeps the `LOWER(username) = LOWER($1)`
|
|
57
|
+
* lookup contract simple. A string outside the bounds and off the grammar
|
|
58
|
+
* gets the length issue alone.
|
|
59
|
+
*/
|
|
60
|
+
export const Username = pipe(bounded_string({ min: USERNAME_LENGTH_MIN, max: USERNAME_LENGTH_MAX }), regex(USERNAME_REGEX), to_lower_case);
|
|
61
|
+
/**
|
|
62
|
+
* A username's canonical grammar, `USERNAME_REGEX` in lowercase: a lowercase
|
|
63
|
+
* letter, then lowercase letters, digits, `_` or `-`, ending in a lowercase
|
|
64
|
+
* letter or digit. What `Username` outputs, and what an `account` row holds
|
|
65
|
+
* (its `account_username_lowercase` CHECK).
|
|
66
|
+
*/
|
|
67
|
+
export const USERNAME_CANONICAL_REGEX = /^[a-z][0-9a-z_-]*[0-9a-z]$/;
|
|
68
|
+
/**
|
|
69
|
+
* A username as an account row holds it, the `username` of an output: the
|
|
70
|
+
* bounds of `Username` and `USERNAME_CANONICAL_REGEX`, no transform. A
|
|
71
|
+
* username in any other case fails, where `Username` lowercases it.
|
|
72
|
+
*/
|
|
73
|
+
export const UsernameCanonical = pipe(bounded_string({ min: USERNAME_LENGTH_MIN, max: USERNAME_LENGTH_MAX }), regex(USERNAME_CANONICAL_REGEX));
|
|
74
|
+
/**
|
|
75
|
+
* Username submitted for login or lookup — minimal validation, for
|
|
76
|
+
* forward-compatibility if the creation grammar changes: at least one and at
|
|
77
|
+
* most `USERNAME_PROVIDED_LENGTH_MAX` UTF-16 code units, measured before
|
|
78
|
+
* trimming, holding a character that isn't whitespace.
|
|
79
|
+
*
|
|
80
|
+
* Canonicalized to `.trim().toLowerCase()` at parse time, so login's
|
|
81
|
+
* per-account rate-limit key and its lookup see one value whatever the casing
|
|
82
|
+
* or surrounding whitespace, as `Username` canonicalizes what is stored.
|
|
83
|
+
*
|
|
84
|
+
* A whitespace-only identifier is refused, not canonicalized to `""` and left
|
|
85
|
+
* to fall through to a lookup-miss 401: an empty identifier is malformed
|
|
86
|
+
* input, not a wrong credential, and the Rust spine's `account_login` refuses
|
|
87
|
+
* it too. JS `\s` is exactly the set `trim` removes (ECMA-262's WhiteSpace and
|
|
88
|
+
* LineTerminator), so the `regex` ahead of the transform refuses what would
|
|
89
|
+
* trim to nothing.
|
|
116
90
|
*/
|
|
117
|
-
export const
|
|
118
|
-
.regex(USERNAME_REGEX)
|
|
119
|
-
.transform((s) => s.toLowerCase());
|
|
91
|
+
export const UsernameProvided = pipe(bounded_string({ min: 1, max: USERNAME_PROVIDED_LENGTH_MAX }), message(regex(/\S/), 'Username must not be empty after trimming whitespace'), transform((s) => s.trim().toLowerCase()));
|
|
120
92
|
/**
|
|
121
93
|
* Maximum email length in **bytes** — RFC 5321 §4.5.3.1.3 path-length limit
|
|
122
94
|
* (the limit is octets). `Email` bounds the UTF-8 byte length, matching the
|
|
@@ -145,13 +117,13 @@ export const EMAIL_LENGTH_MAX = 254;
|
|
|
145
117
|
* language, is quadratic: it tries every `.` as the split.
|
|
146
118
|
*/
|
|
147
119
|
export const EMAIL_REGEX = /^[^\s\u0085@]+@[^\s\u0085@.]+\.[^\s\u0085@]*[^\s\u0085@.]$/;
|
|
148
|
-
/** The message of an email over `EMAIL_LENGTH_MAX` bytes, on
|
|
120
|
+
/** The message of an email over `EMAIL_LENGTH_MAX` bytes, on `Email`. */
|
|
149
121
|
export const EMAIL_LENGTH_MESSAGE = `Email must be at most ${EMAIL_LENGTH_MAX} bytes`;
|
|
150
122
|
/** UTF-8 encoder for the `EMAIL_LENGTH_MAX` byte (octet) bound. */
|
|
151
123
|
const utf8_encoder = new TextEncoder();
|
|
152
124
|
/**
|
|
153
|
-
* Whether `s` is at most `EMAIL_LENGTH_MAX` bytes in UTF-8, the bound
|
|
154
|
-
*
|
|
125
|
+
* Whether `s` is at most `EMAIL_LENGTH_MAX` bytes in UTF-8, the bound `Email`
|
|
126
|
+
* checks.
|
|
155
127
|
*
|
|
156
128
|
* `s.length` (UTF-16 units) is a cheap upper bound that short-circuits the
|
|
157
129
|
* `encode` on absurd inputs: a valid (<= 254-byte) address is necessarily
|
|
@@ -164,96 +136,92 @@ const utf8_encoder = new TextEncoder();
|
|
|
164
136
|
export const is_email_within_length_max = (s) => s.length <= EMAIL_LENGTH_MAX && utf8_encoder.encode(s).length <= EMAIL_LENGTH_MAX;
|
|
165
137
|
/**
|
|
166
138
|
* Email validation. Every current consumer pairs it with `Username` (signup,
|
|
167
|
-
* invites, audit log), so the two live together with the other
|
|
168
|
-
* primitives.
|
|
139
|
+
* invites, audit log), so the two live together with the other primitives.
|
|
169
140
|
*
|
|
170
141
|
* Deliberately permissive — a structural shape check (`EMAIL_REGEX` plus the
|
|
171
142
|
* `EMAIL_LENGTH_MAX` byte bound), not RFC 5322 conformance or deliverability
|
|
172
|
-
* (real delivery is proven by a confirmation email).
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
143
|
+
* (real delivery is proven by a confirmation email). The rule is one explicit
|
|
144
|
+
* regex the Rust spine's `is_valid_email` mirrors, looser than grammars
|
|
145
|
+
* requiring a 2+ char TLD and no consecutive dots, which reject addresses like
|
|
146
|
+
* `a@b.c`. The length bound is the UTF-8 **byte** count (RFC 5321
|
|
147
|
+
* measures octets), so a multibyte address is bounded identically to the
|
|
148
|
+
* Rust spine's `s.len()`. No transform: case is preserved and surrounding
|
|
149
|
+
* whitespace is rejected (not trimmed), so storage is verbatim and the
|
|
150
|
+
* case-insensitive lookup rides the DB-side `LOWER(email)`.
|
|
151
|
+
*
|
|
152
|
+
* The `max_length` ahead of the grammar refuses a string past the bound in
|
|
153
|
+
* UTF-16 code units, which is past it in bytes too, before the regex reads
|
|
154
|
+
* it, and the `check` after it the multibyte address within the units but
|
|
155
|
+
* past the bytes, both with `EMAIL_LENGTH_MESSAGE`. Its JSON Schema carries
|
|
156
|
+
* the bound as `maxLength`.
|
|
185
157
|
*/
|
|
186
|
-
export const Email =
|
|
187
|
-
.string()
|
|
188
|
-
.refine(is_email_within_length_max, { message: EMAIL_LENGTH_MESSAGE, abort: true })
|
|
189
|
-
.regex(EMAIL_REGEX);
|
|
158
|
+
export const Email = pipe(string, message(max_length(EMAIL_LENGTH_MAX), EMAIL_LENGTH_MESSAGE), regex(EMAIL_REGEX), message(check(is_email_within_length_max), EMAIL_LENGTH_MESSAGE));
|
|
190
159
|
/** Returns a new random (v4) `Uuid`. */
|
|
191
160
|
export const create_uuid = () => crypto.randomUUID();
|
|
192
161
|
/**
|
|
193
162
|
* The UUID grammar of RFC 9562, in either case: five groups of hex digits,
|
|
194
163
|
* 8-4-4-4-12, with a version from 1 to 8 and the RFC's variant, or the nil or
|
|
195
|
-
* the max UUID
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
* which a test holds it to, and the grammar of the Rust spine's
|
|
199
|
-
* `is_valid_uuid`.
|
|
164
|
+
* the max UUID, read case-insensitively as RFC 9562 §4 reads a UUID. The same
|
|
165
|
+
* source as the pattern fuz_schema's `uuid` renders to JSON Schema, which a
|
|
166
|
+
* test holds it to, and the grammar of the Rust spine's `is_valid_uuid`.
|
|
200
167
|
*/
|
|
201
|
-
const UUID_REGEX = /^(?:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|[fF]{8}-[fF]{4}-[fF]{4}-[fF]{4}-[fF]{12})$/;
|
|
168
|
+
export const UUID_REGEX = /^(?:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|[fF]{8}-[fF]{4}-[fF]{4}-[fF]{4}-[fF]{12})$/;
|
|
202
169
|
/**
|
|
203
|
-
* Branded UUID schema
|
|
204
|
-
*
|
|
205
|
-
* compares equal to the same id read back
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* any case. Issues and JSON Schema keep `format: 'uuid'`; only the `pattern`
|
|
209
|
-
* differs from a bare `z.uuid()`'s, rendered or on a Zod issue (the wire
|
|
210
|
-
* issue drops it).
|
|
211
|
-
*
|
|
212
|
-
* `pattern` is a `$ZodUUIDDef` field that `z.uuid()` honors (its default
|
|
213
|
-
* applies only when none is given) but whose public params type omits it,
|
|
214
|
-
* hence the cast on the params.
|
|
215
|
-
*
|
|
216
|
-
* `.toLowerCase()` rather than `.transform()`: an overwrite keeps the output
|
|
217
|
-
* type and stays invisible to `z.toJSONSchema`, where a transform would leave
|
|
218
|
-
* no input schema to render.
|
|
219
|
-
*
|
|
220
|
-
* The output type is fuz_schema's `Branded<string, 'Uuid'>`, the twin's, by a
|
|
221
|
-
* cast as on `FactHashSchema`: Zod's `.brand('Uuid')` would output Zod's own
|
|
222
|
-
* brand, which a fuz_schema `Uuid` isn't assignable to.
|
|
170
|
+
* Branded UUID schema: a UUID of RFC 9562 in either case, fuz_schema's `uuid`
|
|
171
|
+
* (whose grammar is `UUID_REGEX`), output in lowercase — the form Postgres renders a `uuid` in and every id
|
|
172
|
+
* the server mints — so a parsed id compares equal to the same id read back
|
|
173
|
+
* from the database. The Rust spine canonicalizes the same way. The brand
|
|
174
|
+
* goes outside the `to_lower_case`, which outputs a new string.
|
|
223
175
|
*/
|
|
224
|
-
export const Uuid =
|
|
225
|
-
.uuid({ pattern: UUID_REGEX })
|
|
226
|
-
.toLowerCase();
|
|
176
|
+
export const Uuid = brand(pipe(string, uuid, to_lower_case), 'Uuid');
|
|
227
177
|
/** `Uuid` that defaults to a fresh `create_uuid()` when the input is `undefined`. */
|
|
228
|
-
export const UuidWithDefault = Uuid
|
|
178
|
+
export const UuidWithDefault = with_default_fn(Uuid, create_uuid);
|
|
229
179
|
/**
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
* `iso_datetime` is this grammar with the seconds required and the fraction
|
|
235
|
-
* capped at 9 digits.
|
|
180
|
+
* A timestamp on the wire: a date and time of RFC 3339 in UTC, fuz_schema's
|
|
181
|
+
* `iso_datetime`, which both spines' `YYYY-MM-DDTHH:MM:SSZ`
|
|
182
|
+
* (`iso8601_timestamp_column`) and a `toISOString()` stamp satisfy. Not
|
|
183
|
+
* branded.
|
|
236
184
|
*/
|
|
237
|
-
export const
|
|
238
|
-
/** Returns an ISO 8601 datetime string for the current time. */
|
|
239
|
-
export const get_datetime_now = () => new Date().toISOString();
|
|
240
|
-
/** `Datetime` that defaults to `get_datetime_now()` when the input is `undefined`. */
|
|
241
|
-
export const DatetimeNow = Datetime.default(get_datetime_now);
|
|
185
|
+
export const Timestamp = pipe(string, iso_datetime);
|
|
242
186
|
/**
|
|
243
|
-
*
|
|
187
|
+
* A `blake3:`-prefixed fact hash on the wire: `FACT_HASH_EXACT`, its output
|
|
244
188
|
* `FactHash` from `@fuzdev/fuz_util/hash_schemas.ts` — the type
|
|
245
|
-
* `fact_hash_bytes`, `fact_hash_stream`, and `FactStore`
|
|
189
|
+
* `fact_hash_bytes`, `fact_hash_stream`, and `FactStore` take — so a parsed
|
|
246
190
|
* value passes straight to them. Client-side (cell payloads) and server-side
|
|
247
|
-
* (DB-row hashes) consumers reuse this same schema.
|
|
248
|
-
*
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
191
|
+
* (DB-row hashes) consumers reuse this same schema. Its JSON Schema is the
|
|
192
|
+
* `pattern`.
|
|
193
|
+
*/
|
|
194
|
+
export const FactHashSchema = brand(pipe(string, regex(FACT_HASH_EXACT)), 'FactHash');
|
|
195
|
+
/** A BLAKE3 hex hash's grammar: 64 lowercase hex characters (256-bit output). */
|
|
196
|
+
export const BLAKE3_HASH_REGEX = /^[0-9a-f]{64}$/;
|
|
197
|
+
/** The message of a string off `BLAKE3_HASH_REGEX`. */
|
|
198
|
+
export const BLAKE3_HASH_MESSAGE = 'Expected a 64-character lowercase hex blake3 hash';
|
|
199
|
+
/**
|
|
200
|
+
* A BLAKE3 hex hash: `BLAKE3_HASH_REGEX`, whose issue carries
|
|
201
|
+
* `BLAKE3_HASH_MESSAGE`. A value that is no string gets fuz_schema's message.
|
|
202
|
+
*/
|
|
203
|
+
export const Blake3Hash = pipe(string, message(regex(BLAKE3_HASH_REGEX), BLAKE3_HASH_MESSAGE));
|
|
204
|
+
/** The `description` of `ActingActor`. */
|
|
205
|
+
export const ACTING_ACTOR_DESCRIPTION = 'Actor on the authenticated account that this request acts as. Omit on single-actor accounts; required on multi-actor.';
|
|
206
|
+
/**
|
|
207
|
+
* `acting` field shared by every input that needs the caller's acting actor.
|
|
208
|
+
* Declaring `acting: ActingActor` on a route or action input signals to the
|
|
209
|
+
* dispatcher's authorization phase to resolve an actor against the
|
|
210
|
+
* authenticated account: it runs `resolve_acting_actor`, builds the
|
|
211
|
+
* actor-bound `RequestContext`, and loads role_grants before auth guards fire.
|
|
212
|
+
*
|
|
213
|
+
* Resolution rules: omitted + 1 actor → use it; omitted + multiple actors →
|
|
214
|
+
* `actor_required` with the available list; supplied + on the account → use
|
|
215
|
+
* it; supplied + foreign actor → `actor_not_on_account`.
|
|
216
|
+
*
|
|
217
|
+
* Account-grain routes — input doesn't declare `acting` and auth doesn't
|
|
218
|
+
* require role_grants — skip resolution entirely; their `RequestContext.actor`
|
|
219
|
+
* is `null` and the audit envelope's `actor_id` stays null.
|
|
220
|
+
*
|
|
221
|
+
* Paired with `RouteAuth` (`http/auth_shape.ts`) by registry-time invariant
|
|
222
|
+
* 2: `auth.actor !== 'none'` ⟺ input (or query, on REST GETs) declares
|
|
223
|
+
* `acting?: ActingActor`. The dispatcher finds it by reference
|
|
224
|
+
* (`input_schema_declares_acting`), so an input declares this export, not a
|
|
225
|
+
* copy of it.
|
|
256
226
|
*/
|
|
257
|
-
export const
|
|
258
|
-
.string()
|
|
259
|
-
.regex(FACT_HASH_EXACT);
|
|
227
|
+
export const ActingActor = meta(optional(Uuid), { description: ACTING_ACTOR_DESCRIPTION });
|
package/dist/realtime/sse.d.ts
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
*/
|
|
33
33
|
import type { Context } from 'hono';
|
|
34
34
|
import type { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
35
|
-
import { type
|
|
35
|
+
import { type AnySchema } from '@fuzdev/fuz_schema/schema.ts';
|
|
36
36
|
/**
|
|
37
37
|
* Generic SSE stream controller interface.
|
|
38
38
|
*
|
|
@@ -118,8 +118,8 @@ export declare const create_sse_response: <T = unknown>(c: Context, log: Logger,
|
|
|
118
118
|
export interface EventSpec {
|
|
119
119
|
/** Event method name, used as the JSON-RPC notification `method`. */
|
|
120
120
|
method: string;
|
|
121
|
-
/** Schema for the notification `params` payload
|
|
122
|
-
params:
|
|
121
|
+
/** Schema for the notification `params` payload. */
|
|
122
|
+
params: AnySchema;
|
|
123
123
|
/** Human-readable description for surface output and docs. */
|
|
124
124
|
description: string;
|
|
125
125
|
/** Channel this event broadcasts on. Omit for cross-channel events. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/realtime/sse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAGpC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/realtime/sse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAGpC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAS,KAAK,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAYrE;;;;GAIG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,OAAO;IACrC;;;;OAIG;IACH,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;IACxB,wBAAwB;IACxB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB;;;;;OAKG;IACH,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;CACnC;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC/B,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,MAAM,EAAE,OAAO,CAAC;CAChB;AAED,yCAAyC;AACzC,MAAM,WAAW,kBAAkB;IAClC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AA8DD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,GAAG,OAAO,EAC9C,GAAG,OAAO,EACV,KAAK,MAAM,EACX,UAAU,kBAAkB,KAC1B;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAA;CAsG5C,CAAC;AAEF,gFAAgF;AAChF,MAAM,WAAW,SAAS;IACzB,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,MAAM,EAAE,SAAS,CAAC;IAClB,8DAA8D;IAC9D,WAAW,EAAE,MAAM,CAAC;IACpB,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,4BAA4B,GAAI,CAAC,SAAS,eAAe,EACrE,aAAa;IAAE,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAAK,IAAI,CAAA;CAAE,EAC9D,aAAa,KAAK,CAAC,SAAS,CAAC,EAC7B,KAAK,MAAM,KACT;IAAE,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAAK,IAAI,CAAA;CAmBjD,CAAC"}
|
package/dist/realtime/sse.js
CHANGED
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
*/
|
|
33
33
|
import { streamSSE } from 'hono/streaming';
|
|
34
34
|
import { DEV } from 'esm-env';
|
|
35
|
+
import { parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
35
36
|
import { utf8_length } from '../actions/transports.js';
|
|
36
37
|
import { OutboundBudget } from './outbound_budget.js';
|
|
37
|
-
import { parse_any } from '../schema_issues.js';
|
|
38
38
|
import { SSE_CONNECTED_COMMENT, SSE_KEEP_ALIVE_COMMENT, SSE_KEEP_ALIVE_INTERVAL_MS, SSE_OUTBOUND_QUEUE_BYTES, validate_sse_keep_alive_ms } from './sse_constants.js';
|
|
39
39
|
const is_node_connection_stream = (value) => {
|
|
40
40
|
if (typeof value !== 'object' || value === null)
|
|
@@ -249,7 +249,7 @@ export const create_validated_broadcaster = (broadcaster, event_specs, log) => {
|
|
|
249
249
|
log.warn(`Unknown event method: '${data.method}'`);
|
|
250
250
|
}
|
|
251
251
|
else {
|
|
252
|
-
const result =
|
|
252
|
+
const result = parse(spec.params, data.params);
|
|
253
253
|
if (!result.ok) {
|
|
254
254
|
log.warn(`Params mismatch for '${data.method}':`, result.issues);
|
|
255
255
|
}
|