@fuzdev/fuz_app 0.163.0 → 0.164.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/README.md +2 -1
- 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 +4 -0
- package/dist/actions/action_spec.d.ts +3 -3
- package/dist/actions/action_spec.d.ts.map +1 -1
- package/dist/auth/CLAUDE.md +1 -1
- package/dist/auth/account_route_schema.d.ts +3 -27
- package/dist/auth/account_route_schema.d.ts.map +1 -1
- package/dist/auth/account_route_schema.js +6 -20
- package/dist/auth/admin_action_specs.d.ts +56 -56
- package/dist/auth/audit_log_route_schema.d.ts +1 -1
- package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_route_schema.js +4 -5
- package/dist/auth/audit_log_schema.d.ts +18 -18
- package/dist/auth/bootstrap_route_schema.d.ts +1 -30
- package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
- package/dist/auth/bootstrap_route_schema.js +3 -8
- package/dist/auth/daemon_token.d.ts +4 -4
- package/dist/auth/daemon_token.d.ts.map +1 -1
- package/dist/auth/daemon_token.js +3 -3
- package/dist/auth/daemon_token_middleware.d.ts +1 -1
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +5 -5
- package/dist/auth/middleware.js +4 -4
- package/dist/auth/role_grant_offer_action_specs.d.ts +2 -2
- package/dist/auth/signup_route_schema.d.ts.map +1 -1
- package/dist/auth/signup_route_schema.js +3 -7
- package/dist/db/CLAUDE.md +2 -1
- package/dist/db/file_fact_url.d.ts +11 -6
- package/dist/db/file_fact_url.d.ts.map +1 -1
- package/dist/db/file_fact_url.js +5 -5
- package/dist/db/schema_ready.d.ts +0 -5
- package/dist/db/schema_ready.d.ts.map +1 -1
- package/dist/db/schema_ready.js +0 -5
- package/dist/http/CLAUDE.md +104 -71
- package/dist/http/auth_shape.d.ts +48 -29
- package/dist/http/auth_shape.d.ts.map +1 -1
- package/dist/http/auth_shape.js +12 -85
- package/dist/http/body_limit.d.ts +12 -0
- package/dist/http/body_limit.d.ts.map +1 -1
- package/dist/http/body_limit.js +15 -0
- package/dist/http/body_limit_schema.d.ts +20 -0
- package/dist/http/body_limit_schema.d.ts.map +1 -0
- package/dist/http/body_limit_schema.js +20 -0
- 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 +11 -14
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +59 -69
- package/dist/http/dev_route_error_check.d.ts +70 -0
- package/dist/http/dev_route_error_check.d.ts.map +1 -0
- package/dist/http/dev_route_error_check.js +119 -0
- package/dist/http/error_schemas.d.ts +365 -189
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +256 -149
- package/dist/http/health_schema.d.ts +10 -6
- package/dist/http/health_schema.d.ts.map +1 -1
- package/dist/http/health_schema.js +3 -3
- package/dist/http/middleware_spec.d.ts +8 -3
- package/dist/http/middleware_spec.d.ts.map +1 -1
- package/dist/http/origin.d.ts +12 -43
- package/dist/http/origin.d.ts.map +1 -1
- package/dist/http/origin.js +10 -6
- package/dist/http/route_error_check.d.ts +158 -0
- package/dist/http/route_error_check.d.ts.map +1 -0
- package/dist/http/route_error_check.js +247 -0
- package/dist/http/route_errors.d.ts +80 -0
- package/dist/http/route_errors.d.ts.map +1 -0
- package/dist/http/route_errors.js +83 -0
- package/dist/http/route_spec.d.ts +33 -17
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +48 -62
- package/dist/http/schema_helpers.d.ts +0 -33
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +0 -45
- package/dist/http/surface.d.ts +19 -12
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +25 -38
- package/dist/http/surface_query.d.ts +11 -2
- package/dist/http/surface_query.d.ts.map +1 -1
- package/dist/http/surface_query.js +7 -1
- package/dist/primitive_schemas_fuz.d.ts +17 -3
- package/dist/primitive_schemas_fuz.d.ts.map +1 -1
- package/dist/primitive_schemas_fuz.js +13 -3
- package/dist/rate_limiter.d.ts +13 -0
- package/dist/rate_limiter.d.ts.map +1 -1
- package/dist/rate_limiter.js +20 -2
- package/dist/schema_issues.d.ts +29 -11
- package/dist/schema_issues.d.ts.map +1 -1
- package/dist/schema_issues.js +11 -10
- package/dist/schema_meta.d.ts +8 -1
- package/dist/schema_meta.d.ts.map +1 -1
- package/dist/schema_meta.js +2 -1
- package/dist/server/app_server.d.ts +3 -1
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +24 -10
- package/dist/server/serve_fact_route.d.ts.map +1 -1
- package/dist/server/serve_fact_route.js +8 -31
- package/dist/server/surface_route.d.ts.map +1 -1
- package/dist/server/surface_route.js +5 -6
- package/dist/server/x_accel.d.ts +12 -7
- package/dist/server/x_accel.d.ts.map +1 -1
- package/dist/server/x_accel.js +7 -9
- package/dist/testing/CLAUDE.md +33 -39
- package/dist/testing/admin_integration.js +1 -1
- package/dist/testing/adversarial_404.d.ts +4 -18
- package/dist/testing/adversarial_404.d.ts.map +1 -1
- package/dist/testing/adversarial_404.js +19 -51
- package/dist/testing/adversarial_headers.d.ts +3 -4
- package/dist/testing/adversarial_headers.d.ts.map +1 -1
- package/dist/testing/adversarial_headers.js +8 -6
- package/dist/testing/adversarial_input.d.ts.map +1 -1
- package/dist/testing/adversarial_input.js +18 -17
- package/dist/testing/assertions.d.ts +33 -11
- package/dist/testing/assertions.d.ts.map +1 -1
- package/dist/testing/assertions.js +52 -12
- package/dist/testing/attack_surface.d.ts +5 -35
- package/dist/testing/attack_surface.d.ts.map +1 -1
- package/dist/testing/attack_surface.js +29 -91
- package/dist/testing/auth_apps.d.ts.map +1 -1
- package/dist/testing/auth_apps.js +2 -1
- package/dist/testing/cross_backend/action_manifest.d.ts +126 -56
- package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
- package/dist/testing/cross_backend/action_manifest.js +11 -11
- package/dist/testing/cross_backend/action_manifest_parity.d.ts +1 -1
- package/dist/testing/cross_backend/action_manifest_parity.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_crud.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_crud.js +2 -1
- package/dist/testing/cross_backend/conformance_table.js +1 -1
- package/dist/testing/cross_backend/fact_serving.js +3 -3
- package/dist/testing/cross_backend/origin_conformance.d.ts +278 -102
- package/dist/testing/cross_backend/origin_conformance.d.ts.map +1 -1
- package/dist/testing/cross_backend/origin_conformance.js +21 -21
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.js +7 -1
- package/dist/testing/cross_backend/setup.d.ts +13 -0
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +24 -7
- package/dist/testing/cross_backend/testing_origin_check.d.ts +147 -71
- package/dist/testing/cross_backend/testing_origin_check.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_origin_check.js +16 -13
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +70 -27
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +5 -4
- package/dist/testing/error_coverage.d.ts +24 -34
- package/dist/testing/error_coverage.d.ts.map +1 -1
- package/dist/testing/error_coverage.js +46 -89
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +5 -13
- package/dist/testing/integration_helpers.d.ts +37 -9
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +86 -40
- package/dist/testing/middleware.d.ts +3 -5
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +5 -4
- package/dist/testing/rate_limiting.d.ts +1 -1
- package/dist/testing/rate_limiting.d.ts.map +1 -1
- package/dist/testing/rate_limiting.js +5 -4
- package/dist/testing/round_trip.d.ts.map +1 -1
- package/dist/testing/round_trip.js +5 -3
- package/dist/testing/schema_generators.d.ts +10 -3
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +23 -11
- package/dist/testing/stubs.d.ts +10 -1
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +15 -5
- package/dist/testing/surface_invariants.d.ts +36 -115
- package/dist/testing/surface_invariants.d.ts.map +1 -1
- package/dist/testing/surface_invariants.js +106 -269
- package/dist/ui/CLAUDE.md +4 -2
- package/dist/ui/auth_state.svelte.d.ts.map +1 -1
- package/dist/ui/auth_state.svelte.js +2 -8
- package/dist/ui/backend_probe.svelte.js +3 -3
- package/dist/ui/table_state.svelte.d.ts.map +1 -1
- package/dist/ui/table_state.svelte.js +1 -8
- package/dist/ui/ui_fetch.d.ts +12 -2
- package/dist/ui/ui_fetch.d.ts.map +1 -1
- package/dist/ui/ui_fetch.js +22 -4
- package/package.json +1 -1
|
@@ -2,25 +2,30 @@
|
|
|
2
2
|
* Standard error response schemas and error code constants for fuz_app routes.
|
|
3
3
|
*
|
|
4
4
|
* Defines `ERROR_*` constants (single source of truth for machine-parseable
|
|
5
|
-
* error codes
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* error codes, which double as JSON-RPC `data.reason`s), the per-code REST
|
|
6
|
+
* error definitions (`rest_error`, one `REST_*` per code a route or middleware
|
|
7
|
+
* answers, each with its HTTP status and its body as a `@fuzdev/fuz_schema`
|
|
8
|
+
* schema), a type for error schema maps, and `derive_route_errors`, the
|
|
9
|
+
* definitions the framework answers a route with from its method, auth
|
|
10
|
+
* requirement, and input slots.
|
|
8
11
|
*
|
|
9
|
-
* Used in `RouteSpec.errors` and `MiddlewareSpec.errors
|
|
10
|
-
*
|
|
12
|
+
* Used in `RouteSpec.errors` and `MiddlewareSpec.errors`, which each route's
|
|
13
|
+
* error map (`http/route_errors.ts`) unions with the derived definitions for
|
|
14
|
+
* the surface, the DEV error check, and the test helpers.
|
|
11
15
|
*
|
|
12
16
|
* @module
|
|
13
17
|
*/
|
|
14
|
-
import {
|
|
18
|
+
import { type AnySchema, type Infer, type Schema, type SchemaEntries, type SchemaObjectInput, type SchemaObjectOutput } from '@fuzdev/fuz_schema/schema.ts';
|
|
15
19
|
import { type RouteAuth } from './auth_shape.js';
|
|
16
|
-
import {
|
|
17
|
-
|
|
20
|
+
import type { RateLimitKey } from '../rate_limiter.js';
|
|
21
|
+
import type { RouteMethod } from './route_spec.js';
|
|
22
|
+
/** Request body failed its input schema. */
|
|
18
23
|
export declare const ERROR_INVALID_REQUEST_BODY: "invalid_request_body";
|
|
19
24
|
/** Request body is not valid JSON or not an object. */
|
|
20
25
|
export declare const ERROR_INVALID_JSON_BODY: "invalid_json_body";
|
|
21
|
-
/** URL path params failed
|
|
26
|
+
/** URL path params failed their schema. */
|
|
22
27
|
export declare const ERROR_INVALID_ROUTE_PARAMS: "invalid_route_params";
|
|
23
|
-
/** URL query params failed
|
|
28
|
+
/** URL query params failed their schema. */
|
|
24
29
|
export declare const ERROR_INVALID_QUERY_PARAMS: "invalid_query_params";
|
|
25
30
|
/**
|
|
26
31
|
* An RPC call's `params` hold an own `__proto__` key, at any depth — refused
|
|
@@ -35,7 +40,7 @@ export declare const ERROR_INSUFFICIENT_PERMISSIONS: "insufficient_permissions";
|
|
|
35
40
|
/**
|
|
36
41
|
* Route requires a credential type the request didn't arrive on.
|
|
37
42
|
* Symmetric with `ERROR_INSUFFICIENT_PERMISSIONS` + `required_roles`:
|
|
38
|
-
* the body carries `required_credential_types:
|
|
43
|
+
* the body carries `required_credential_types: Array<string>`
|
|
39
44
|
* — what the route demanded, not what arrived. Today the only
|
|
40
45
|
* credential gate is keeper (`['daemon_token']`); future gates
|
|
41
46
|
* (`agent_token`, `group_actor_token`) reuse the same literal and
|
|
@@ -70,6 +75,13 @@ export declare const ERROR_SERVICE_UNAVAILABLE: "service_unavailable";
|
|
|
70
75
|
export declare const ERROR_INVALID_CONTENT_LENGTH: "invalid_content_length";
|
|
71
76
|
/** Request origin not in allowlist. */
|
|
72
77
|
export declare const ERROR_FORBIDDEN_ORIGIN: "forbidden_origin";
|
|
78
|
+
/**
|
|
79
|
+
* The request's `Host` names a host the server doesn't answer to — the Rust
|
|
80
|
+
* spine's DNS-rebinding gate (`host_gate`), its `FORBIDDEN_HOST_REASON`. The
|
|
81
|
+
* TS spine has no host gate; a surface describing a Rust server that mounts
|
|
82
|
+
* one declares it.
|
|
83
|
+
*/
|
|
84
|
+
export declare const ERROR_FORBIDDEN_HOST: "forbidden_host";
|
|
73
85
|
/**
|
|
74
86
|
* A `POST` whose `Content-Type` the route refuses: anything but
|
|
75
87
|
* `application/json` on a JSON route, a CORS-safelisted type or none on a
|
|
@@ -166,213 +178,377 @@ export declare const ERROR_TABLE_NOT_DELETABLE: "table_not_deletable";
|
|
|
166
178
|
export declare const ERROR_ROW_NOT_FOUND: "row_not_found";
|
|
167
179
|
/** Database health-check query failed (connectivity or query error). */
|
|
168
180
|
export declare const ERROR_DATABASE_CONNECTION_FAILED: "database_connection_failed";
|
|
169
|
-
/**
|
|
170
|
-
export declare const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
export type ApiError = z.infer<typeof ApiError>;
|
|
181
|
+
/** The live database lacks a table or column the deploy expects (`db/schema_ready.ts`). */
|
|
182
|
+
export declare const ERROR_SCHEMA_DRIFT: "schema_drift";
|
|
183
|
+
/** The readiness check could not query the database. */
|
|
184
|
+
export declare const ERROR_DB_UNREACHABLE: "db_unreachable";
|
|
174
185
|
/**
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
* `error` is one of the four validation codes the framework emits.
|
|
179
|
-
* `issues` carries the validation issues as `WireIssue`s, whichever schema
|
|
180
|
-
* library refused, for diagnostic display on the three schema-failure cases (`invalid_request_body`,
|
|
181
|
-
* `invalid_route_params`, `invalid_query_params`). The field is optional:
|
|
182
|
-
* the `invalid_json_body` case (request body parse failure or non-object
|
|
183
|
-
* root) emits no `issues`, and the schema-failure cases emit them only in
|
|
184
|
-
* development — production omits them (via `dev_only`) so error responses
|
|
185
|
-
* don't leak input-schema structure to callers.
|
|
186
|
+
* An unexpected failure — the catch layer's answer to an error no route
|
|
187
|
+
* declares (`{error: 'internal_error', message?}`, the message DEV-only).
|
|
186
188
|
*/
|
|
187
|
-
export declare const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
197
|
-
expected: z.ZodString;
|
|
198
|
-
received: z.ZodString;
|
|
199
|
-
message: z.ZodString;
|
|
200
|
-
}, z.core.$loose>>>;
|
|
201
|
-
}, z.core.$loose>;
|
|
202
|
-
export type ValidationError = z.infer<typeof ValidationError>;
|
|
189
|
+
export declare const ERROR_INTERNAL_ERROR: "internal_error";
|
|
190
|
+
/** The entries of a definition's body schema: `error`, its code, beside its fields. */
|
|
191
|
+
export type RestErrorEntries<TCode extends string, TFields extends SchemaEntries> = {
|
|
192
|
+
error: Schema<TCode, TCode, 'literal', TCode>;
|
|
193
|
+
} & TFields;
|
|
194
|
+
/** The body schema of a definition, `loose_object({error: literal(code), ...fields})`. */
|
|
195
|
+
export type RestErrorSchema<TCode extends string, TFields extends SchemaEntries> = Schema<SchemaObjectOutput<RestErrorEntries<TCode, TFields>> & Record<string, unknown>, SchemaObjectInput<RestErrorEntries<TCode, TFields>> & Record<string, unknown>, 'loose_object', RestErrorEntries<TCode, TFields>>;
|
|
196
|
+
/** The body a definition puts on the wire. */
|
|
197
|
+
export type RestErrorBody<TCode extends string, TFields extends SchemaEntries> = Infer<RestErrorSchema<TCode, TFields>>;
|
|
203
198
|
/**
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
199
|
+
* A REST error definition: one code at one HTTP status, with the fields its
|
|
200
|
+
* body carries beside `error`. The status lives here and not on the `ERROR_*`
|
|
201
|
+
* constant, which is also a JSON-RPC `data.reason` with no fixed status.
|
|
207
202
|
*
|
|
208
|
-
*
|
|
209
|
-
* (`
|
|
210
|
-
* as a one-element array; multi-role disjunctions show every admittable
|
|
211
|
-
* role so clients can render targeted copy ("requires admin or steward").
|
|
203
|
+
* The same code may have more than one definition, each a shape of its own
|
|
204
|
+
* (`REST_AUTHENTICATION_REQUIRED` and `REST_AUTHENTICATION_REQUIRED_BOOTSTRAP`).
|
|
212
205
|
*/
|
|
213
|
-
export
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
206
|
+
export interface RestErrorDef<TStatus extends number = number, TCode extends string = string, TFields extends SchemaEntries = SchemaEntries> {
|
|
207
|
+
readonly status: TStatus;
|
|
208
|
+
readonly code: TCode;
|
|
209
|
+
/** The body's entries beside `error`. */
|
|
210
|
+
readonly fields: TFields;
|
|
211
|
+
/** `loose_object({error: literal(code), ...fields})`, what the surface and the DEV check read. */
|
|
212
|
+
readonly schema: RestErrorSchema<TCode, TFields>;
|
|
213
|
+
/** Response headers a definition derives from its body (`Retry-After`). */
|
|
214
|
+
headers?(body: RestErrorBody<TCode, TFields>): Record<string, string>;
|
|
215
|
+
}
|
|
216
|
+
/** Refuses a widened `number` or `string`, so a definition names one status and one code. */
|
|
217
|
+
type Exact<T, TWide> = TWide extends T ? never : T;
|
|
218
218
|
/**
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
* the request's credential type isn't in the route's
|
|
222
|
-
* `auth.credential_types` allowlist.
|
|
223
|
-
*
|
|
224
|
-
* `required_credential_types` carries what the route declared
|
|
225
|
-
* (`['daemon_token']` for keeper; future gates carry their own labels).
|
|
226
|
-
* Symmetric with `PermissionError`'s `required_roles`: clients see what
|
|
227
|
-
* the route demanded, not what their credential is.
|
|
219
|
+
* The grammar of an `error` code: a lowercase ASCII letter, then lowercase
|
|
220
|
+
* letters, digits, and `_` — a code, never prose. Prose goes in `message`.
|
|
228
221
|
*/
|
|
229
|
-
export declare const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
222
|
+
export declare const REST_ERROR_CODE_PATTERN: RegExp;
|
|
223
|
+
/** The characters a code can't start with, beside an uppercase letter. */
|
|
224
|
+
type CodeHeadRefused = '_' | '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
|
|
225
|
+
/** Characters prose has and a code doesn't, beside an uppercase letter. */
|
|
226
|
+
type CodeCharRefused = ' ' | '-' | '.' | ',' | ':' | '/' | "'" | '!' | '?';
|
|
234
227
|
/**
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
* `
|
|
228
|
+
* Refuses, at the type level, only the forms plainly off
|
|
229
|
+
* `REST_ERROR_CODE_PATTERN`: empty, holding an uppercase letter, starting with
|
|
230
|
+
* a digit or `_`, or holding a space or one of a few punctuation marks. Other
|
|
231
|
+
* characters (`@`, `#`, `(`, non-ASCII), and a code typed as a union, pass
|
|
232
|
+
* it. The runtime check in `rest_error` is the authority on the grammar.
|
|
233
|
+
*/
|
|
234
|
+
type RestErrorCode<T extends string> = T extends '' ? never : T extends Lowercase<T> ? T extends `${CodeHeadRefused}${string}` ? never : T extends `${string}${CodeCharRefused}${string}` ? never : T : never;
|
|
235
|
+
/**
|
|
236
|
+
* Whether a value is an `error` code, by `REST_ERROR_CODE_PATTERN`.
|
|
239
237
|
*
|
|
240
|
-
*
|
|
241
|
-
* from its `auth.required_scope` (`surface:audit_stream`, …) — matching the Rust
|
|
242
|
-
* `token_scope_surface_denied_response` and the dispatcher's own per-method
|
|
243
|
-
* denial. Third in the family with `PermissionError` and
|
|
244
|
-
* `CredentialTypeRequiredError` — each names what the route demanded rather
|
|
245
|
-
* than what the caller holds.
|
|
238
|
+
* @param value - the value to test
|
|
246
239
|
*/
|
|
247
|
-
export declare const
|
|
248
|
-
error: z.ZodLiteral<"token_scope_required">;
|
|
249
|
-
required_scope: z.ZodString;
|
|
250
|
-
}, z.core.$loose>;
|
|
251
|
-
export type TokenScopeRequiredError = z.infer<typeof TokenScopeRequiredError>;
|
|
252
|
-
/** Rate limit error — returned when a rate limiter rejects the request. */
|
|
253
|
-
export declare const RateLimitError: z.ZodObject<{
|
|
254
|
-
error: z.ZodLiteral<"rate_limit_exceeded">;
|
|
255
|
-
retry_after: z.ZodNumber;
|
|
256
|
-
}, z.core.$loose>;
|
|
257
|
-
export type RateLimitError = z.infer<typeof RateLimitError>;
|
|
258
|
-
/** Payload too large error — returned when the request body exceeds the size limit. */
|
|
259
|
-
export declare const PayloadTooLargeError: z.ZodObject<{
|
|
260
|
-
error: z.ZodLiteral<"payload_too_large">;
|
|
261
|
-
}, z.core.$loose>;
|
|
262
|
-
export type PayloadTooLargeError = z.infer<typeof PayloadTooLargeError>;
|
|
263
|
-
/** Unsupported content type error — returned when a `POST` route refuses the request's `Content-Type`. */
|
|
264
|
-
export declare const UnsupportedContentTypeError: z.ZodObject<{
|
|
265
|
-
error: z.ZodLiteral<"unsupported_content_type">;
|
|
266
|
-
}, z.core.$loose>;
|
|
267
|
-
export type UnsupportedContentTypeError = z.infer<typeof UnsupportedContentTypeError>;
|
|
268
|
-
/** Foreign key violation error — returned when a delete is blocked by references. */
|
|
269
|
-
export declare const ForeignKeyError: z.ZodObject<{
|
|
270
|
-
error: z.ZodLiteral<"foreign_key_violation">;
|
|
271
|
-
}, z.core.$loose>;
|
|
272
|
-
export type ForeignKeyError = z.infer<typeof ForeignKeyError>;
|
|
240
|
+
export declare const is_rest_error_code: (value: unknown) => value is string;
|
|
273
241
|
/**
|
|
274
|
-
*
|
|
275
|
-
* `
|
|
276
|
-
* the route is acting-aware (input declares `acting?: ActingActor` or
|
|
277
|
-
* auth requires role_grants), but actor resolution failed.
|
|
242
|
+
* Define a REST error: its status, its code, and the fields its body carries
|
|
243
|
+
* beside `error`.
|
|
278
244
|
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
245
|
+
* @param status - the HTTP status it answers at, a literal
|
|
246
|
+
* @param code - the `error` code, a literal matching `REST_ERROR_CODE_PATTERN`, usually an `ERROR_*` constant
|
|
247
|
+
* @param fields - the body's other entries
|
|
248
|
+
* @param headers - the response headers to derive from a body
|
|
249
|
+
* @returns the definition, its body schema a `loose_object`
|
|
250
|
+
* @throws Error when `code` is not an error code (`REST_ERROR_CODE_PATTERN`), or
|
|
251
|
+
* when `fields` has an own `error` entry, which would replace the code
|
|
252
|
+
*/
|
|
253
|
+
export declare const rest_error: <const TStatus extends number, const TCode extends string, const TFields extends SchemaEntries = Record<never, never>>(status: Exact<TStatus, number>, code: Exact<RestErrorCode<TCode>, string>, fields?: TFields, headers?: (body: RestErrorBody<TCode, TFields>) => Record<string, string>) => RestErrorDef<TStatus, TCode, TFields>;
|
|
254
|
+
/**
|
|
255
|
+
* Whether two definitions are the same: one object, or the same status, code,
|
|
256
|
+
* and `headers`, with the same schema at every field.
|
|
282
257
|
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
|
|
286
|
-
|
|
258
|
+
* @param a - one definition
|
|
259
|
+
* @param b - the other
|
|
260
|
+
*/
|
|
261
|
+
export declare const same_rest_error: (a: RestErrorDef, b: RestErrorDef) => boolean;
|
|
262
|
+
/**
|
|
263
|
+
* A list of definitions with each repeat after its first left out
|
|
264
|
+
* (`same_rest_error`), in list order.
|
|
287
265
|
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
266
|
+
* @param defs - the definitions
|
|
267
|
+
* @returns the distinct definitions
|
|
290
268
|
*/
|
|
291
|
-
export declare const
|
|
292
|
-
error: z.ZodLiteral<"actor_required">;
|
|
293
|
-
available: z.ZodArray<z.ZodObject<{
|
|
294
|
-
id: z.ZodString;
|
|
295
|
-
name: z.ZodString;
|
|
296
|
-
}, z.core.$loose>>;
|
|
297
|
-
}, z.core.$loose>;
|
|
298
|
-
export type ActorRequiredError = z.infer<typeof ActorRequiredError>;
|
|
299
|
-
export declare const ActorNotOnAccountError: z.ZodObject<{
|
|
300
|
-
error: z.ZodLiteral<"actor_not_on_account">;
|
|
301
|
-
}, z.core.$loose>;
|
|
302
|
-
export type ActorNotOnAccountError = z.infer<typeof ActorNotOnAccountError>;
|
|
303
|
-
export declare const NoActorsOnAccountError: z.ZodObject<{
|
|
304
|
-
error: z.ZodLiteral<"no_actors_on_account">;
|
|
305
|
-
}, z.core.$loose>;
|
|
306
|
-
export type NoActorsOnAccountError = z.infer<typeof NoActorsOnAccountError>;
|
|
307
|
-
export declare const AccountVanishedError: z.ZodObject<{
|
|
308
|
-
error: z.ZodLiteral<"account_vanished">;
|
|
309
|
-
}, z.core.$loose>;
|
|
310
|
-
export type AccountVanishedError = z.infer<typeof AccountVanishedError>;
|
|
269
|
+
export declare const dedupe_rest_errors: (defs: Iterable<RestErrorDef>) => Array<RestErrorDef>;
|
|
311
270
|
/**
|
|
312
|
-
*
|
|
313
|
-
*
|
|
271
|
+
* Build an error-schema map from a list of definitions, grouped by status.
|
|
272
|
+
* A status with one definition maps to its schema, and one with more to a
|
|
273
|
+
* `union` of their schemas in list order — two shapes of one code included,
|
|
274
|
+
* each a branch; a definition listed twice counts once (`dedupe_rest_errors`).
|
|
314
275
|
*
|
|
315
|
-
*
|
|
316
|
-
* returns
|
|
276
|
+
* @param defs - the definitions
|
|
277
|
+
* @returns the error schemas, keyed by status
|
|
317
278
|
*/
|
|
318
|
-
export
|
|
279
|
+
export declare const to_error_schemas: (defs: Iterable<RestErrorDef>) => ErrorSchemas;
|
|
280
|
+
export declare const REST_INVALID_REQUEST_BODY: RestErrorDef<400, "invalid_request_body", {
|
|
281
|
+
readonly issues: Schema<({
|
|
282
|
+
message: string;
|
|
283
|
+
path: (string | number)[];
|
|
284
|
+
expected: string;
|
|
285
|
+
kind: string;
|
|
286
|
+
received: string;
|
|
287
|
+
} & Record<string, unknown>)[] | undefined, ({
|
|
288
|
+
message: string;
|
|
289
|
+
path: (string | number)[];
|
|
290
|
+
expected: string;
|
|
291
|
+
kind: string;
|
|
292
|
+
received: string;
|
|
293
|
+
} & Record<string, unknown>)[] | undefined, "optional", import("@fuzdev/fuz_schema/schema.ts").SchemaWrapperDef<Schema<({
|
|
294
|
+
message: string;
|
|
295
|
+
path: (string | number)[];
|
|
296
|
+
expected: string;
|
|
297
|
+
kind: string;
|
|
298
|
+
received: string;
|
|
299
|
+
} & Record<string, unknown>)[], ({
|
|
300
|
+
message: string;
|
|
301
|
+
path: (string | number)[];
|
|
302
|
+
expected: string;
|
|
303
|
+
kind: string;
|
|
304
|
+
received: string;
|
|
305
|
+
} & Record<string, unknown>)[], "array", Schema<{
|
|
306
|
+
message: string;
|
|
307
|
+
path: (string | number)[];
|
|
308
|
+
expected: string;
|
|
309
|
+
kind: string;
|
|
310
|
+
received: string;
|
|
311
|
+
} & Record<string, unknown>, {
|
|
312
|
+
message: string;
|
|
313
|
+
path: (string | number)[];
|
|
314
|
+
expected: string;
|
|
315
|
+
kind: string;
|
|
316
|
+
received: string;
|
|
317
|
+
} & Record<string, unknown>, "loose_object", {
|
|
318
|
+
kind: Schema<string, string, "string", undefined>;
|
|
319
|
+
path: Schema<(string | number)[], (string | number)[], "array", Schema<string | number, string | number, "union", readonly [Schema<string, string, "string", undefined>, Schema<number, number, "number", undefined>]>>;
|
|
320
|
+
expected: Schema<string, string, "string", undefined>;
|
|
321
|
+
received: Schema<string, string, "string", undefined>;
|
|
322
|
+
message: Schema<string, string, "string", undefined>;
|
|
323
|
+
}>>>>;
|
|
324
|
+
}>;
|
|
325
|
+
export declare const REST_INVALID_JSON_BODY: RestErrorDef<400, "invalid_json_body", Record<never, never>>;
|
|
326
|
+
export declare const REST_INVALID_ROUTE_PARAMS: RestErrorDef<400, "invalid_route_params", {
|
|
327
|
+
readonly issues: Schema<({
|
|
328
|
+
message: string;
|
|
329
|
+
path: (string | number)[];
|
|
330
|
+
expected: string;
|
|
331
|
+
kind: string;
|
|
332
|
+
received: string;
|
|
333
|
+
} & Record<string, unknown>)[] | undefined, ({
|
|
334
|
+
message: string;
|
|
335
|
+
path: (string | number)[];
|
|
336
|
+
expected: string;
|
|
337
|
+
kind: string;
|
|
338
|
+
received: string;
|
|
339
|
+
} & Record<string, unknown>)[] | undefined, "optional", import("@fuzdev/fuz_schema/schema.ts").SchemaWrapperDef<Schema<({
|
|
340
|
+
message: string;
|
|
341
|
+
path: (string | number)[];
|
|
342
|
+
expected: string;
|
|
343
|
+
kind: string;
|
|
344
|
+
received: string;
|
|
345
|
+
} & Record<string, unknown>)[], ({
|
|
346
|
+
message: string;
|
|
347
|
+
path: (string | number)[];
|
|
348
|
+
expected: string;
|
|
349
|
+
kind: string;
|
|
350
|
+
received: string;
|
|
351
|
+
} & Record<string, unknown>)[], "array", Schema<{
|
|
352
|
+
message: string;
|
|
353
|
+
path: (string | number)[];
|
|
354
|
+
expected: string;
|
|
355
|
+
kind: string;
|
|
356
|
+
received: string;
|
|
357
|
+
} & Record<string, unknown>, {
|
|
358
|
+
message: string;
|
|
359
|
+
path: (string | number)[];
|
|
360
|
+
expected: string;
|
|
361
|
+
kind: string;
|
|
362
|
+
received: string;
|
|
363
|
+
} & Record<string, unknown>, "loose_object", {
|
|
364
|
+
kind: Schema<string, string, "string", undefined>;
|
|
365
|
+
path: Schema<(string | number)[], (string | number)[], "array", Schema<string | number, string | number, "union", readonly [Schema<string, string, "string", undefined>, Schema<number, number, "number", undefined>]>>;
|
|
366
|
+
expected: Schema<string, string, "string", undefined>;
|
|
367
|
+
received: Schema<string, string, "string", undefined>;
|
|
368
|
+
message: Schema<string, string, "string", undefined>;
|
|
369
|
+
}>>>>;
|
|
370
|
+
}>;
|
|
371
|
+
export declare const REST_INVALID_QUERY_PARAMS: RestErrorDef<400, "invalid_query_params", {
|
|
372
|
+
readonly issues: Schema<({
|
|
373
|
+
message: string;
|
|
374
|
+
path: (string | number)[];
|
|
375
|
+
expected: string;
|
|
376
|
+
kind: string;
|
|
377
|
+
received: string;
|
|
378
|
+
} & Record<string, unknown>)[] | undefined, ({
|
|
379
|
+
message: string;
|
|
380
|
+
path: (string | number)[];
|
|
381
|
+
expected: string;
|
|
382
|
+
kind: string;
|
|
383
|
+
received: string;
|
|
384
|
+
} & Record<string, unknown>)[] | undefined, "optional", import("@fuzdev/fuz_schema/schema.ts").SchemaWrapperDef<Schema<({
|
|
385
|
+
message: string;
|
|
386
|
+
path: (string | number)[];
|
|
387
|
+
expected: string;
|
|
388
|
+
kind: string;
|
|
389
|
+
received: string;
|
|
390
|
+
} & Record<string, unknown>)[], ({
|
|
391
|
+
message: string;
|
|
392
|
+
path: (string | number)[];
|
|
393
|
+
expected: string;
|
|
394
|
+
kind: string;
|
|
395
|
+
received: string;
|
|
396
|
+
} & Record<string, unknown>)[], "array", Schema<{
|
|
397
|
+
message: string;
|
|
398
|
+
path: (string | number)[];
|
|
399
|
+
expected: string;
|
|
400
|
+
kind: string;
|
|
401
|
+
received: string;
|
|
402
|
+
} & Record<string, unknown>, {
|
|
403
|
+
message: string;
|
|
404
|
+
path: (string | number)[];
|
|
405
|
+
expected: string;
|
|
406
|
+
kind: string;
|
|
407
|
+
received: string;
|
|
408
|
+
} & Record<string, unknown>, "loose_object", {
|
|
409
|
+
kind: Schema<string, string, "string", undefined>;
|
|
410
|
+
path: Schema<(string | number)[], (string | number)[], "array", Schema<string | number, string | number, "union", readonly [Schema<string, string, "string", undefined>, Schema<number, number, "number", undefined>]>>;
|
|
411
|
+
expected: Schema<string, string, "string", undefined>;
|
|
412
|
+
received: Schema<string, string, "string", undefined>;
|
|
413
|
+
message: Schema<string, string, "string", undefined>;
|
|
414
|
+
}>>>>;
|
|
415
|
+
}>;
|
|
416
|
+
export declare const REST_INVALID_CONTENT_LENGTH: RestErrorDef<400, "invalid_content_length", Record<never, never>>;
|
|
417
|
+
/** No `acting` selector on a multi-actor account; `available` lists the account's actors. */
|
|
418
|
+
export declare const REST_ACTOR_REQUIRED: RestErrorDef<400, "actor_required", {
|
|
419
|
+
readonly available: Schema<({
|
|
420
|
+
name: string;
|
|
421
|
+
id: string;
|
|
422
|
+
} & Record<string, unknown>)[], ({
|
|
423
|
+
name: string;
|
|
424
|
+
id: string;
|
|
425
|
+
} & Record<string, unknown>)[], "array", Schema<{
|
|
426
|
+
name: string;
|
|
427
|
+
id: string;
|
|
428
|
+
} & Record<string, unknown>, {
|
|
429
|
+
name: string;
|
|
430
|
+
id: string;
|
|
431
|
+
} & Record<string, unknown>, "loose_object", {
|
|
432
|
+
id: Schema<string, string, "string", undefined>;
|
|
433
|
+
name: Schema<string, string, "string", undefined>;
|
|
434
|
+
}>>;
|
|
435
|
+
}>;
|
|
436
|
+
/** The `acting` selector names an actor that isn't the account's. */
|
|
437
|
+
export declare const REST_ACTOR_NOT_ON_ACCOUNT: RestErrorDef<400, "actor_not_on_account", Record<never, never>>;
|
|
438
|
+
export declare const REST_TABLE_NOT_DELETABLE: RestErrorDef<400, "table_not_deletable", Record<never, never>>;
|
|
439
|
+
export declare const REST_TABLE_NO_PRIMARY_KEY: RestErrorDef<400, "table_no_primary_key", Record<never, never>>;
|
|
440
|
+
export declare const REST_AUTHENTICATION_REQUIRED: RestErrorDef<401, "authentication_required", Record<never, never>>;
|
|
441
|
+
/** `GET /api/account/status`'s anonymous answer: the same code, with the bootstrap status. */
|
|
442
|
+
export declare const REST_AUTHENTICATION_REQUIRED_BOOTSTRAP: RestErrorDef<401, "authentication_required", {
|
|
443
|
+
readonly bootstrap_available: Schema<boolean | undefined, boolean | undefined, "optional", import("@fuzdev/fuz_schema/schema.ts").SchemaWrapperDef<Schema<boolean, boolean, "boolean", undefined>>>;
|
|
444
|
+
}>;
|
|
445
|
+
export declare const REST_INVALID_CREDENTIALS: RestErrorDef<401, "invalid_credentials", Record<never, never>>;
|
|
446
|
+
/** The bootstrap token didn't match. */
|
|
447
|
+
export declare const REST_INVALID_TOKEN: RestErrorDef<401, "invalid_token", Record<never, never>>;
|
|
319
448
|
/**
|
|
320
|
-
* The
|
|
321
|
-
*
|
|
449
|
+
* The role gate's refusal (`require_role`, and the dispatcher's): the actor
|
|
450
|
+
* holds none of the route's `auth.roles`. `required_roles` is the whole
|
|
451
|
+
* disjunction, so a client can say "requires admin or steward".
|
|
322
452
|
*/
|
|
323
|
-
export
|
|
453
|
+
export declare const REST_INSUFFICIENT_PERMISSIONS: RestErrorDef<403, "insufficient_permissions", {
|
|
454
|
+
readonly required_roles: Schema<string[], string[], "array", Schema<string, string, "string", undefined>>;
|
|
455
|
+
}>;
|
|
324
456
|
/**
|
|
325
|
-
*
|
|
326
|
-
* is
|
|
327
|
-
*
|
|
328
|
-
* - `'ip'` — per-IP rate limiting (login, bootstrap, password change, signup)
|
|
329
|
-
* - `'account'` — per-account rate limiting. On REST auth routes the key is
|
|
330
|
-
* the submitted identifier (login). On RPC actions (post-auth) the key is
|
|
331
|
-
* the resolved actor id (`request_context.actor.id`) — separate namespace.
|
|
332
|
-
* - `'both'` — both keys.
|
|
457
|
+
* The credential-type gate's refusal (`require_credential_types`, and the
|
|
458
|
+
* dispatcher's): the request's credential type is not in the route's
|
|
459
|
+
* `auth.credential_types`, which `required_credential_types` carries.
|
|
333
460
|
*/
|
|
334
|
-
export declare const
|
|
335
|
-
|
|
336
|
-
ip: "ip";
|
|
337
|
-
both: "both";
|
|
461
|
+
export declare const REST_CREDENTIAL_TYPE_REQUIRED: RestErrorDef<403, "credential_type_required", {
|
|
462
|
+
readonly required_credential_types: Schema<string[], string[], "array", Schema<string, string, "string", undefined>>;
|
|
338
463
|
}>;
|
|
339
|
-
export type RateLimitKey = z.infer<typeof RateLimitKey>;
|
|
340
464
|
/**
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
465
|
+
* The token-scope gate's refusal (`require_token_scope`, and
|
|
466
|
+
* `token_scope_surface_denial`): a narrowed api token reaches a capability its
|
|
467
|
+
* scope does not admit. `required_scope` is the route's `auth.required_scope`,
|
|
468
|
+
* verbatim. See `docs/security.md` §Token scoping.
|
|
469
|
+
*/
|
|
470
|
+
export declare const REST_TOKEN_SCOPE_REQUIRED: RestErrorDef<403, "token_scope_required", {
|
|
471
|
+
readonly required_scope: Schema<string, string, "string", undefined>;
|
|
472
|
+
}>;
|
|
473
|
+
export declare const REST_FORBIDDEN_ORIGIN: RestErrorDef<403, "forbidden_origin", Record<never, never>>;
|
|
474
|
+
export declare const REST_FORBIDDEN_HOST: RestErrorDef<403, "forbidden_host", Record<never, never>>;
|
|
475
|
+
export declare const REST_ALREADY_BOOTSTRAPPED: RestErrorDef<403, "already_bootstrapped", Record<never, never>>;
|
|
476
|
+
export declare const REST_NO_MATCHING_INVITE: RestErrorDef<403, "no_matching_invite", Record<never, never>>;
|
|
477
|
+
export declare const REST_TOKEN_FILE_MISSING: RestErrorDef<404, "token_file_missing", Record<never, never>>;
|
|
478
|
+
export declare const REST_TABLE_NOT_FOUND: RestErrorDef<404, "table_not_found", Record<never, never>>;
|
|
479
|
+
export declare const REST_ROW_NOT_FOUND: RestErrorDef<404, "row_not_found", Record<never, never>>;
|
|
480
|
+
/** A delete blocked by rows that reference the row. */
|
|
481
|
+
export declare const REST_FOREIGN_KEY_VIOLATION: RestErrorDef<409, "foreign_key_violation", Record<never, never>>;
|
|
482
|
+
export declare const REST_SIGNUP_CONFLICT: RestErrorDef<409, "signup_conflict", Record<never, never>>;
|
|
483
|
+
/** The body limit's refusal: the request body exceeds the size limit. */
|
|
484
|
+
export declare const REST_PAYLOAD_TOO_LARGE: RestErrorDef<413, "payload_too_large", Record<never, never>>;
|
|
485
|
+
/** A `POST` route refuses the request's `Content-Type`. */
|
|
486
|
+
export declare const REST_UNSUPPORTED_CONTENT_TYPE: RestErrorDef<415, "unsupported_content_type", Record<never, never>>;
|
|
487
|
+
/** The rate limiter's refusal; `retry_after` is in seconds, `Retry-After` its ceiling. */
|
|
488
|
+
export declare const REST_RATE_LIMIT_EXCEEDED: RestErrorDef<429, "rate_limit_exceeded", {
|
|
489
|
+
readonly retry_after: import("@fuzdev/fuz_schema/schema.ts").PipeSchema<number, Schema<number, number, "number", undefined>>;
|
|
490
|
+
}>;
|
|
491
|
+
/** The account's actors enumerated empty, a signup invariant broken. */
|
|
492
|
+
export declare const REST_NO_ACTORS_ON_ACCOUNT: RestErrorDef<500, "no_actors_on_account", Record<never, never>>;
|
|
493
|
+
/** The account or actor row was deleted between credential validation and the actor read. */
|
|
494
|
+
export declare const REST_ACCOUNT_VANISHED: RestErrorDef<500, "account_vanished", Record<never, never>>;
|
|
495
|
+
export declare const REST_INTERNAL_ERROR: RestErrorDef<500, "internal_error", Record<never, never>>;
|
|
496
|
+
export declare const REST_SERVICE_UNAVAILABLE: RestErrorDef<503, "service_unavailable", Record<never, never>>;
|
|
497
|
+
export declare const REST_DATABASE_CONNECTION_FAILED: RestErrorDef<503, "database_connection_failed", Record<never, never>>;
|
|
498
|
+
export declare const REST_SCHEMA_DRIFT: RestErrorDef<503, "schema_drift", Record<never, never>>;
|
|
499
|
+
export declare const REST_DB_UNREACHABLE: RestErrorDef<503, "db_unreachable", Record<never, never>>;
|
|
500
|
+
/**
|
|
501
|
+
* Error schema map — an HTTP status to the schema of every body a route
|
|
502
|
+
* answers at it, built from definitions by `to_error_schemas`.
|
|
368
503
|
*/
|
|
369
|
-
export
|
|
504
|
+
export type ErrorSchemas = Record<number, AnySchema>;
|
|
505
|
+
/**
|
|
506
|
+
* What `derive_route_errors` reads of a route: its method, auth requirement,
|
|
507
|
+
* which input slots it has, and its rate limit key.
|
|
508
|
+
*/
|
|
509
|
+
export interface DeriveRouteErrorsOptions {
|
|
510
|
+
method: RouteMethod;
|
|
370
511
|
auth: RouteAuth;
|
|
512
|
+
/** Whether the route has a body schema, an `input` other than `null`. */
|
|
371
513
|
has_input?: boolean;
|
|
372
514
|
has_params?: boolean;
|
|
373
515
|
has_query?: boolean;
|
|
374
516
|
rate_limit?: RateLimitKey;
|
|
375
|
-
checks_content_type?: boolean;
|
|
376
517
|
}
|
|
377
|
-
|
|
518
|
+
/**
|
|
519
|
+
* Derive the error definitions the framework answers a route with, from its
|
|
520
|
+
* method, auth requirement, input slots, and rate limit — each narrowed to
|
|
521
|
+
* what the route's own middleware can emit.
|
|
522
|
+
*
|
|
523
|
+
* Route handlers declare additional definitions via `RouteSpec.errors`; the
|
|
524
|
+
* route's error map (`resolve_route_error_map`) is the union of these, the
|
|
525
|
+
* applying middleware's, and the route's own.
|
|
526
|
+
*
|
|
527
|
+
* Derivation rules:
|
|
528
|
+
* - **A body**, an `input` other than `null` on a method other than `GET`:
|
|
529
|
+
* 400 `invalid_request_body` and `invalid_json_body`. A `GET` reads no body.
|
|
530
|
+
* - **`params`**: 400 `invalid_route_params`. **`query`**: 400
|
|
531
|
+
* `invalid_query_params`.
|
|
532
|
+
* - **`auth.account === 'required'`** or **`auth.actor === 'required'`**: 401
|
|
533
|
+
* `authentication_required` — the pre-authorization gate's refusal when the
|
|
534
|
+
* credential isn't there. `'optional'` does not derive 401.
|
|
535
|
+
* - **`auth.required_scope`**: 403 `token_scope_required` (carrying
|
|
536
|
+
* `required_scope`). **`auth.credential_types?.length`**: 403
|
|
537
|
+
* `credential_type_required` (carrying `required_credential_types`).
|
|
538
|
+
* **`auth.roles?.length`**: 403 `insufficient_permissions` (carrying
|
|
539
|
+
* `required_roles`). In the order the gates fire; a route with more than
|
|
540
|
+
* one has each.
|
|
541
|
+
* - **`auth.actor !== 'none'`**: 400 `actor_required` and
|
|
542
|
+
* `actor_not_on_account`, and 500 `no_actors_on_account` and
|
|
543
|
+
* `account_vanished` — what the dispatcher's authorization phase emits
|
|
544
|
+
* when it resolves an actor.
|
|
545
|
+
* - **`rate_limit`**: 429 `rate_limit_exceeded` (with `retry_after`).
|
|
546
|
+
* - **`POST`**: 415 `unsupported_content_type` (see
|
|
547
|
+
* `is_post_content_type_refused` in `http/simple_request.ts`).
|
|
548
|
+
*
|
|
549
|
+
* @param options - what the derivation reads of the route
|
|
550
|
+
* @returns the definitions, in the order above
|
|
551
|
+
*/
|
|
552
|
+
export declare const derive_route_errors: ({ method, auth, has_input, has_params, has_query, rate_limit }: DeriveRouteErrorsOptions) => Array<RestErrorDef>;
|
|
553
|
+
export {};
|
|
378
554
|
//# sourceMappingURL=error_schemas.d.ts.map
|