@jini-ai/core 0.7.2 → 0.7.3-next.1
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/CHANGELOG.md +0 -2
- package/README.md +40 -12
- package/dist/admin-runtime/admin-api-error.d.ts +68 -0
- package/dist/admin-runtime/admin-api-error.js +72 -0
- package/dist/admin-runtime/admin-config-error.d.ts +8 -0
- package/dist/admin-runtime/admin-config-error.js +11 -0
- package/dist/admin-runtime/controller-store.d.ts +20 -0
- package/dist/admin-runtime/controller-store.js +32 -0
- package/dist/admin-runtime/index.d.ts +13 -0
- package/dist/admin-runtime/index.js +12 -0
- package/dist/admin-runtime/panel-access.d.ts +88 -0
- package/dist/admin-runtime/panel-access.js +76 -0
- package/dist/admin-runtime/query-suffix.d.ts +5 -0
- package/dist/admin-runtime/query-suffix.js +5 -0
- package/dist/agent-handles/element-handles.d.ts +134 -0
- package/dist/agent-handles/element-handles.js +45 -0
- package/dist/agent-handles/field-descriptor.d.ts +28 -0
- package/dist/agent-handles/field-descriptor.js +3 -0
- package/dist/agent-handles/handle.d.ts +109 -0
- package/dist/agent-handles/handle.js +109 -0
- package/dist/agent-handles/index.d.ts +9 -0
- package/dist/agent-handles/index.js +6 -0
- package/dist/agent-handles/list-handles.d.ts +46 -0
- package/dist/agent-handles/list-handles.js +67 -0
- package/dist/agent-handles/secret-attrs.d.ts +14 -0
- package/dist/agent-handles/secret-attrs.js +13 -0
- package/dist/approval-batch-chain.d.ts +45 -0
- package/dist/approval-batch-chain.js +75 -0
- package/dist/approval.d.ts +33 -14
- package/dist/approval.js +57 -43
- package/dist/batch-tool-inputs.js +24 -20
- package/dist/contracts/admin-module.d.ts +166 -0
- package/dist/contracts/admin-module.js +14 -0
- package/dist/contracts/agents/definition.d.ts +459 -0
- package/dist/contracts/agents/definition.js +2 -0
- package/dist/contracts/agents/index.d.ts +7 -0
- package/dist/contracts/agents/index.js +2 -0
- package/dist/contracts/agents/launch.d.ts +64 -0
- package/dist/contracts/agents/launch.js +2 -0
- package/dist/contracts/agents/model-catalog.d.ts +213 -0
- package/dist/contracts/agents/model-catalog.js +4 -0
- package/dist/contracts/agents/native-tool-policy.d.ts +42 -0
- package/dist/contracts/agents/native-tool-policy.js +2 -0
- package/dist/contracts/ai-trace/capture.d.ts +17 -0
- package/dist/contracts/ai-trace/capture.js +43 -0
- package/dist/contracts/ai-trace/classify.d.ts +12 -0
- package/dist/contracts/ai-trace/classify.js +16 -0
- package/dist/contracts/ai-trace/index.d.ts +13 -0
- package/dist/contracts/ai-trace/index.js +6 -0
- package/dist/contracts/ai-trace/recorder.d.ts +64 -0
- package/dist/contracts/ai-trace/recorder.js +283 -0
- package/dist/contracts/ai-trace/sinks.d.ts +51 -0
- package/dist/contracts/ai-trace/sinks.js +153 -0
- package/dist/contracts/ai-trace/types.d.ts +123 -0
- package/dist/contracts/ai-trace/types.js +17 -0
- package/dist/contracts/ai-trace/usage.d.ts +16 -0
- package/dist/contracts/ai-trace/usage.js +45 -0
- package/dist/contracts/blob.d.ts +31 -0
- package/dist/contracts/blob.js +10 -0
- package/dist/contracts/capabilities.d.ts +95 -0
- package/dist/contracts/capabilities.js +111 -0
- package/dist/contracts/charts.d.ts +75 -0
- package/dist/contracts/charts.js +4 -0
- package/dist/contracts/env.d.ts +96 -0
- package/dist/contracts/env.js +6 -0
- package/dist/contracts/events/change-set.d.ts +106 -0
- package/dist/contracts/events/change-set.js +2 -0
- package/dist/contracts/events/command.d.ts +118 -0
- package/dist/contracts/events/command.js +2 -0
- package/dist/contracts/events/ports.d.ts +172 -0
- package/dist/contracts/events/ports.js +2 -0
- package/dist/contracts/events.d.ts +5 -0
- package/dist/contracts/events.js +2 -0
- package/dist/contracts/forms.d.ts +110 -0
- package/dist/contracts/forms.js +4 -0
- package/dist/contracts/hosted-mcp/config.d.ts +19 -0
- package/dist/contracts/hosted-mcp/record.d.ts +61 -4
- package/dist/contracts/mail/email-sender.d.ts +118 -0
- package/dist/contracts/mail/email-sender.js +20 -0
- package/dist/contracts/mail/smtp-payload.d.ts +32 -0
- package/dist/contracts/mail/smtp-payload.js +2 -0
- package/dist/contracts/mail.d.ts +2 -0
- package/dist/contracts/mail.js +1 -1
- package/dist/contracts/observability.d.ts +232 -0
- package/dist/contracts/observability.js +27 -0
- package/dist/contracts/plugin-sdk.d.ts +186 -0
- package/dist/contracts/plugin-sdk.js +39 -0
- package/dist/contracts/runtime/command.d.ts +41 -0
- package/dist/contracts/runtime/command.js +60 -0
- package/dist/contracts/runtime/environment.d.ts +18 -0
- package/dist/contracts/runtime/environment.js +26 -0
- package/dist/contracts/runtime/file-lock.d.ts +94 -0
- package/dist/contracts/runtime/file-lock.js +25 -0
- package/dist/contracts/runtime/fs.d.ts +33 -0
- package/dist/contracts/runtime/fs.js +2 -0
- package/dist/contracts/runtime/http.d.ts +89 -0
- package/dist/contracts/runtime/http.js +2 -0
- package/dist/contracts/runtime/platform.d.ts +3 -0
- package/dist/contracts/runtime/platform.js +2 -0
- package/dist/contracts/runtime/process.d.ts +40 -0
- package/dist/contracts/runtime/process.js +31 -0
- package/dist/contracts/runtime/reader.d.ts +11 -0
- package/dist/contracts/runtime/reader.js +2 -0
- package/dist/contracts/runtime/terminal.d.ts +99 -0
- package/dist/contracts/runtime/terminal.js +2 -0
- package/dist/contracts/runtime/testing.d.ts +84 -0
- package/dist/contracts/runtime/testing.js +116 -0
- package/dist/contracts/runtime.d.ts +10 -0
- package/dist/contracts/runtime.js +10 -0
- package/dist/contracts/server/api-error.d.ts +43 -0
- package/dist/contracts/server/api-error.js +49 -0
- package/dist/contracts/server/auth.d.ts +20 -0
- package/dist/contracts/server/auth.js +21 -0
- package/dist/contracts/server/conformance.d.ts +25 -0
- package/dist/contracts/server/conformance.js +50 -0
- package/dist/contracts/server/json-route.d.ts +176 -0
- package/dist/contracts/server/json-route.js +155 -0
- package/dist/contracts/server/middleware.d.ts +35 -0
- package/dist/contracts/server/middleware.js +56 -0
- package/dist/contracts/server/origin.d.ts +44 -0
- package/dist/contracts/server/origin.js +32 -0
- package/dist/contracts/server/query.d.ts +16 -0
- package/dist/contracts/server/query.js +69 -0
- package/dist/contracts/server/rate-limit.d.ts +20 -0
- package/dist/contracts/server/rate-limit.js +8 -0
- package/dist/contracts/server/request-body.d.ts +26 -0
- package/dist/contracts/server/request-body.js +82 -0
- package/dist/contracts/server/result.d.ts +17 -0
- package/dist/contracts/server/result.js +5 -0
- package/dist/contracts/server/route-table.d.ts +54 -0
- package/dist/contracts/server/route-table.js +119 -0
- package/dist/contracts/server/same-origin-write.d.ts +18 -0
- package/dist/contracts/server/same-origin-write.js +31 -0
- package/dist/contracts/server/security-headers.d.ts +30 -0
- package/dist/contracts/server/security-headers.js +35 -0
- package/dist/contracts/server/sse.d.ts +82 -0
- package/dist/contracts/server/sse.js +103 -0
- package/dist/contracts/server/testing.d.ts +59 -0
- package/dist/contracts/server/testing.js +68 -0
- package/dist/contracts/server/verified-origin/configured-origin.d.ts +37 -0
- package/dist/contracts/server/verified-origin/configured-origin.js +103 -0
- package/dist/contracts/server/verified-origin/index.d.ts +7 -0
- package/dist/contracts/server/verified-origin/index.js +6 -0
- package/dist/contracts/server/verified-origin/loopback-host.d.ts +9 -0
- package/dist/contracts/server/verified-origin/loopback-host.js +17 -0
- package/dist/contracts/server/verified-origin/origin.d.ts +64 -0
- package/dist/contracts/server/verified-origin/origin.js +162 -0
- package/dist/contracts/server/verified-origin/ports.d.ts +38 -0
- package/dist/contracts/server/verified-origin/ports.js +2 -0
- package/dist/contracts/server/verified-origin/repo.memory.d.ts +32 -0
- package/dist/contracts/server/verified-origin/repo.memory.js +34 -0
- package/dist/contracts/server/verified-origin/site-path.d.ts +113 -0
- package/dist/contracts/server/verified-origin/site-path.js +188 -0
- package/dist/contracts/server/verified-origin/types.d.ts +33 -0
- package/dist/contracts/server/verified-origin/types.js +30 -0
- package/dist/contracts/server.d.ts +46 -2
- package/dist/contracts/server.js +17 -3
- package/dist/contracts/storage/kernel.d.ts +86 -0
- package/dist/contracts/storage/kernel.js +38 -0
- package/dist/contracts/storage/migration.d.ts +32 -0
- package/dist/contracts/storage/migration.js +2 -0
- package/dist/contracts/storage/rows.d.ts +33 -0
- package/dist/contracts/storage/rows.js +42 -0
- package/dist/contracts/storage/sqlite.d.ts +113 -0
- package/dist/contracts/storage/sqlite.js +8 -0
- package/dist/contracts/storage/values.d.ts +25 -0
- package/dist/contracts/storage/values.js +25 -0
- package/dist/contracts/storage.d.ts +8 -0
- package/dist/contracts/storage.js +6 -0
- package/dist/contracts/vault/invariants.d.ts +26 -0
- package/dist/contracts/vault/invariants.js +49 -0
- package/dist/contracts/vault.d.ts +1 -0
- package/dist/contracts/vault.js +1 -1
- package/dist/env/coercers.d.ts +21 -0
- package/dist/env/coercers.js +68 -0
- package/dist/env/describe-env-for-diagnostics.d.ts +16 -0
- package/dist/env/describe-env-for-diagnostics.js +23 -0
- package/dist/env/format-env-issue.d.ts +13 -0
- package/dist/env/format-env-issue.js +22 -0
- package/dist/env/parse-env.d.ts +24 -0
- package/dist/env/parse-env.js +102 -0
- package/dist/env/value-echo.d.ts +17 -0
- package/dist/env/value-echo.js +42 -0
- package/dist/errors/approved-cause.d.ts +36 -0
- package/dist/errors/approved-cause.js +17 -0
- package/dist/errors/bindings.d.ts +61 -0
- package/dist/errors/bindings.js +57 -0
- package/dist/errors/catalog.d.ts +84 -0
- package/dist/errors/catalog.js +151 -0
- package/dist/errors/disclosure.d.ts +48 -0
- package/dist/errors/disclosure.js +27 -0
- package/dist/errors/error-id.d.ts +26 -0
- package/dist/errors/error-id.js +23 -0
- package/dist/errors/idioms.d.ts +73 -0
- package/dist/errors/idioms.js +85 -0
- package/dist/errors/incident-text.d.ts +16 -0
- package/dist/errors/incident-text.js +77 -0
- package/dist/errors/reporter.d.ts +94 -0
- package/dist/errors/reporter.js +152 -0
- package/dist/errors/sentences.d.ts +68 -0
- package/dist/errors/sentences.js +93 -0
- package/dist/errors/testing.d.ts +50 -0
- package/dist/errors/testing.js +44 -0
- package/dist/fetch/cache.d.ts +12 -5
- package/dist/fetch/cache.js +46 -47
- package/dist/fetch/index.d.ts +1 -1
- package/dist/fetch/loader-read.d.ts +6 -2
- package/dist/fetch/loader-read.js +4 -4
- package/dist/format-error-for-log.d.ts +15 -0
- package/dist/format-error-for-log.js +55 -0
- package/dist/host-read-vocabulary.d.ts +47 -0
- package/dist/host-read-vocabulary.js +44 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +4 -0
- package/dist/list-page.d.ts +93 -0
- package/dist/list-page.js +154 -0
- package/dist/model-facing-tool-errors.d.ts +67 -5
- package/dist/model-facing-tool-errors.js +155 -19
- package/dist/net/endpoint-policy.d.ts +39 -0
- package/dist/net/endpoint-policy.js +218 -0
- package/dist/net/fetch-timeouts.d.ts +38 -0
- package/dist/net/fetch-timeouts.js +31 -0
- package/dist/net/index.d.ts +4 -0
- package/dist/net/index.js +4 -0
- package/dist/net/loopback.d.ts +13 -0
- package/dist/net/loopback.js +39 -0
- package/dist/optimistic-concurrency.d.ts +183 -0
- package/dist/optimistic-concurrency.js +222 -0
- package/dist/primitives/errors.d.ts +9 -0
- package/dist/primitives/errors.js +12 -0
- package/dist/primitives/ids.d.ts +0 -2
- package/dist/primitives/ids.js +1 -4
- package/dist/primitives/index.d.ts +3 -0
- package/dist/primitives/index.js +2 -0
- package/dist/primitives/logger.d.ts +36 -1
- package/dist/primitives/logger.js +125 -9
- package/dist/primitives/node-shape.d.ts +24 -0
- package/dist/primitives/node-shape.js +21 -0
- package/dist/primitives/time.d.ts +9 -2
- package/dist/primitives/time.js +4 -3
- package/dist/provider-registry.js +26 -20
- package/dist/records.d.ts +40 -7
- package/dist/records.js +37 -3
- package/dist/redact.d.ts +1 -84
- package/dist/redact.js +2 -826
- package/dist/redaction-collectors.d.ts +7 -0
- package/dist/redaction-collectors.js +152 -0
- package/dist/redaction-exact-secrets.d.ts +14 -0
- package/dist/redaction-exact-secrets.js +115 -0
- package/dist/redaction-labels.d.ts +14 -0
- package/dist/redaction-labels.js +156 -0
- package/dist/redaction-patterns.d.ts +54 -0
- package/dist/redaction-patterns.js +178 -0
- package/dist/redaction-spans.d.ts +31 -0
- package/dist/redaction-spans.js +83 -0
- package/dist/registration-kit.d.ts +1 -1
- package/dist/revision-conflict-error.d.ts +18 -0
- package/dist/revision-conflict-error.js +20 -0
- package/dist/secret-shapes.d.ts +50 -0
- package/dist/secret-shapes.js +105 -0
- package/dist/settings/agent-tools.js +22 -8
- package/dist/settings/agent-value-write-tools.d.ts +4 -1
- package/dist/settings/agent-value-write-tools.js +7 -6
- package/dist/settings/agent-writable-preferences.d.ts +3 -1
- package/dist/settings/agent-writable-preferences.js +1 -1
- package/dist/settings/agent-write-denylist.d.ts +7 -4
- package/dist/settings/agent-write-denylist.js +1 -1
- package/dist/settings/{express/cms-adapter.d.ts → cms-adapter.d.ts} +3 -2
- package/dist/settings/{express/cms-adapter.js → cms-adapter.js} +21 -11
- package/dist/settings/definitions-dispatch.js +3 -1
- package/dist/settings/ensure-definitions.js +3 -1
- package/dist/settings/errors.d.ts +1 -13
- package/dist/settings/errors.js +2 -15
- package/dist/settings/index.d.ts +11 -2
- package/dist/settings/index.js +10 -2
- package/dist/settings/purge-service.js +63 -86
- package/dist/settings/{express/contracts.d.ts → route-policy.d.ts} +53 -47
- package/dist/settings/{express/shared.js → route-policy.js} +1 -16
- package/dist/settings/settings.d.ts +19 -11
- package/dist/settings/settings.js +9 -11
- package/dist/settings/tool-registrations.d.ts +3 -3
- package/dist/settings/tool-registrations.js +130 -125
- package/dist/settings/types.d.ts +1 -1
- package/dist/settings/write-definition-rename.d.ts +37 -0
- package/dist/settings/write-definition-rename.js +119 -0
- package/dist/settings/write-definition-retype.d.ts +61 -0
- package/dist/settings/write-definition-retype.js +109 -0
- package/dist/settings/write-definition-status.d.ts +81 -0
- package/dist/settings/write-definition-status.js +121 -0
- package/dist/settings/write-reset.d.ts +34 -0
- package/dist/settings/write-reset.js +73 -0
- package/dist/settings/write-service.d.ts +16 -287
- package/dist/settings/write-service.js +49 -681
- package/dist/settings/write-value-revisions.d.ts +68 -0
- package/dist/settings/write-value-revisions.js +124 -0
- package/dist/settings/write-values.d.ts +96 -0
- package/dist/settings/write-values.js +83 -0
- package/dist/surface-exchanges.d.ts +2 -2
- package/dist/text/dictionary-translator.d.ts +19 -0
- package/dist/text/dictionary-translator.js +14 -0
- package/dist/text/format-byte-size.d.ts +25 -0
- package/dist/text/format-byte-size.js +25 -0
- package/dist/text/format-timestamp.d.ts +22 -0
- package/dist/text/format-timestamp.js +57 -0
- package/dist/text/index.d.ts +12 -0
- package/dist/text/index.js +9 -0
- package/dist/text/is-abort-error.d.ts +5 -0
- package/dist/text/is-abort-error.js +5 -0
- package/dist/text/mime.d.ts +5 -0
- package/dist/text/mime.js +21 -0
- package/dist/text/redact-urls.d.ts +7 -0
- package/dist/text/redact-urls.js +5 -0
- package/dist/text/resolve-active-tab-id.d.ts +13 -0
- package/dist/text/resolve-active-tab-id.js +15 -0
- package/dist/text/sanitize-untrusted-text.d.ts +1 -1
- package/dist/text/sanitize-untrusted-text.js +2 -1
- package/dist/text/tagged-text-suppression.d.ts +103 -0
- package/dist/text/tagged-text-suppression.js +143 -0
- package/dist/text/template-i18n.d.ts +37 -0
- package/dist/text/template-i18n.js +48 -0
- package/dist/tool-call-text.d.ts +59 -0
- package/dist/tool-call-text.js +62 -0
- package/dist/tool-input-envelope.js +8 -4
- package/dist/tool-input-normalization.js +8 -1
- package/dist/tool-input-repairs.d.ts +58 -0
- package/dist/tool-input-repairs.js +154 -0
- package/dist/tool-tokens.js +1 -1
- package/dist/user-facing-error.d.ts +1 -1
- package/dist/user-facing-error.js +3 -1
- package/package.json +234 -13
- package/dist/settings/express/contracts.js +0 -2
- package/dist/settings/express/http-request.d.ts +0 -33
- package/dist/settings/express/http-request.js +0 -50
- package/dist/settings/express/http.d.ts +0 -10
- package/dist/settings/express/http.js +0 -196
- package/dist/settings/express/index.d.ts +0 -5
- package/dist/settings/express/index.js +0 -4
- package/dist/settings/express/shared.d.ts +0 -68
- package/dist/settings/express/stream.d.ts +0 -24
- package/dist/settings/express/stream.js +0 -171
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marks a promise handled: no unhandled-rejection report for it. Every awaiter of the original
|
|
3
|
+
* promise still gets the rejection. For a promise whose failure its own owner already shows.
|
|
4
|
+
* @complexity O(1).
|
|
5
|
+
*/
|
|
6
|
+
export function observed(required, _optional = {}) {
|
|
7
|
+
required.promise.then(undefined, () => undefined);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Resolves when the promise settles and never rejects. Only for a promise whose rejection another
|
|
11
|
+
* named owner already receives (a queue tail waiting for the previous job).
|
|
12
|
+
* @complexity O(1).
|
|
13
|
+
*/
|
|
14
|
+
export function afterSettled(required, _optional = {}) {
|
|
15
|
+
return Promise.resolve(required.promise).then(() => undefined, () => undefined);
|
|
16
|
+
}
|
|
17
|
+
function notify({ error, step }, optional) {
|
|
18
|
+
try {
|
|
19
|
+
optional.observe?.({ error, step });
|
|
20
|
+
}
|
|
21
|
+
catch { /* An observer cannot turn an optional probe into a failure. */ }
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Runs `work`; on ANY failure returns `fallback`. For an optional probe or a documented fallback,
|
|
25
|
+
* where every failure means "no answer". `step` is a fixed label naming the probe; the gate lists it.
|
|
26
|
+
* Where a real failure must not look like "absent", use {@link absentWhen} instead.
|
|
27
|
+
* @complexity O(1) beyond `work`.
|
|
28
|
+
*/
|
|
29
|
+
export async function orFallback(required, optional = {}) {
|
|
30
|
+
try {
|
|
31
|
+
return await required.work();
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
notify({ error, step: required.step }, optional);
|
|
35
|
+
return required.fallback;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** {@link orFallback} for a synchronous `work` (browser storage that may throw). */
|
|
39
|
+
export function orFallbackSync(required, optional = {}) {
|
|
40
|
+
try {
|
|
41
|
+
return required.work();
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
notify({ error, step: required.step }, optional);
|
|
45
|
+
return required.fallback;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Runs cleanup. A failure is logged with its step (the log line carries the class and listed code,
|
|
50
|
+
* a host sink the original) and is never thrown, so cleanup cannot replace the result it follows.
|
|
51
|
+
* @complexity O(1) beyond `work`.
|
|
52
|
+
*/
|
|
53
|
+
export async function bestEffort(required, _optional = {}) {
|
|
54
|
+
try {
|
|
55
|
+
await required.work();
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
try {
|
|
59
|
+
required.logger.warn({ message: `[cleanup] ${required.step} failed` }, { meta: { step: required.step }, error });
|
|
60
|
+
}
|
|
61
|
+
catch { /* A failing log sink cannot turn cleanup into a failure. */ }
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function isAbsence({ error, codes, kinds }) {
|
|
65
|
+
if (kinds.some(kind => error instanceof kind))
|
|
66
|
+
return true;
|
|
67
|
+
const code = typeof error === 'object' && error !== null ? error.code : undefined;
|
|
68
|
+
return typeof code === 'string' && codes.includes(code);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Runs `work`; returns `undefined` only for the listed codes (`ENOENT`) or classes and RETHROWS
|
|
72
|
+
* everything else, so a storage failure never reads as "not there".
|
|
73
|
+
* @complexity O(codes + kinds) on the failure path.
|
|
74
|
+
*/
|
|
75
|
+
export async function absentWhen(required, _optional = {}) {
|
|
76
|
+
try {
|
|
77
|
+
return await required.work();
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (isAbsence({ error, codes: required.codes, kinds: required.kinds }))
|
|
81
|
+
return undefined;
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=idioms.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Raw text is cut here before redaction so one huge value cannot stall the failure path; the
|
|
2
|
+
* record itself is cut after redaction, well below this, so a secret split by this cut is never printed. */
|
|
3
|
+
export declare const MAX_RAW_INCIDENT_TEXT = 65536;
|
|
4
|
+
/** Options of {@link describeThrownValue}. None yet; named so one can be added without changing the signature. */
|
|
5
|
+
export interface DescribeThrownValueOptions {
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Message and up to 30 stack lines of an `Error`; for any other value, its own data only.
|
|
9
|
+
* Never throws: a revoked Proxy or a hostile prototype becomes `[unreadable]`.
|
|
10
|
+
* @returns Unredacted text, cut at {@link MAX_RAW_INCIDENT_TEXT}. The caller redacts it before storing it.
|
|
11
|
+
* @complexity O(min(size of the value, a fixed bound)).
|
|
12
|
+
*/
|
|
13
|
+
export declare function describeThrownValue(required: {
|
|
14
|
+
value: unknown;
|
|
15
|
+
}, _optional?: DescribeThrownValueOptions): string;
|
|
16
|
+
//# sourceMappingURL=incident-text.d.ts.map
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The text of a thrown value for the operator-only incident record. Not for callers: an error
|
|
3
|
+
* message can quote private text that no redactor recognises, so this text goes to the host record
|
|
4
|
+
* and the tracker only, after secret shapes and the host's exact secrets are blanked.
|
|
5
|
+
*
|
|
6
|
+
* A thrown value is untrusted. For a value that is not an `Error` this reads data properties only:
|
|
7
|
+
* it never runs a getter, `toJSON` or a custom inspector (core cannot use `node:util`, whose
|
|
8
|
+
* `inspect(..., { customInspect: false, getters: false })` the visitor reporter relied on). An
|
|
9
|
+
* `Error` is read through its own `stack` and `message`, inside the same guard.
|
|
10
|
+
*/
|
|
11
|
+
const MAX_STACK_LINES = 30;
|
|
12
|
+
const MAX_DEPTH = 3;
|
|
13
|
+
const MAX_ENTRIES = 20;
|
|
14
|
+
/** Raw text is cut here before redaction so one huge value cannot stall the failure path; the
|
|
15
|
+
* record itself is cut after redaction, well below this, so a secret split by this cut is never printed. */
|
|
16
|
+
export const MAX_RAW_INCIDENT_TEXT = 65_536;
|
|
17
|
+
const UNREADABLE = '[unreadable]';
|
|
18
|
+
const ACCESSOR = Symbol('accessor property');
|
|
19
|
+
/** A data property's value from the object or its prototypes; {@link ACCESSOR} for a getter, which is never called. */
|
|
20
|
+
function dataProperty({ target, key }) {
|
|
21
|
+
for (let holder = target; holder !== null; holder = Object.getPrototypeOf(holder)) {
|
|
22
|
+
const descriptor = Object.getOwnPropertyDescriptor(holder, key);
|
|
23
|
+
if (descriptor !== undefined)
|
|
24
|
+
return 'value' in descriptor ? descriptor.value : ACCESSOR;
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
function scalarText({ value }) {
|
|
29
|
+
if (typeof value === 'string')
|
|
30
|
+
return JSON.stringify(value);
|
|
31
|
+
if (typeof value === 'function')
|
|
32
|
+
return '[function]';
|
|
33
|
+
if (typeof value === 'symbol')
|
|
34
|
+
return '[symbol]';
|
|
35
|
+
return String(value);
|
|
36
|
+
}
|
|
37
|
+
function entryText({ target, key, depth }) {
|
|
38
|
+
const value = dataProperty({ target, key });
|
|
39
|
+
return value === ACCESSOR ? '[getter]' : valueText({ value, depth: depth + 1 });
|
|
40
|
+
}
|
|
41
|
+
function valueText({ value, depth }) {
|
|
42
|
+
if (typeof value !== 'object' || value === null)
|
|
43
|
+
return scalarText({ value });
|
|
44
|
+
if (depth >= MAX_DEPTH)
|
|
45
|
+
return '[nested too deep]';
|
|
46
|
+
const list = Array.isArray(value);
|
|
47
|
+
const keys = Object.keys(value);
|
|
48
|
+
const shown = keys.slice(0, MAX_ENTRIES).map(key => (list ? '' : `${key}: `) + entryText({ target: value, key, depth }));
|
|
49
|
+
if (keys.length > MAX_ENTRIES)
|
|
50
|
+
shown.push('…');
|
|
51
|
+
return list ? `[${shown.join(', ')}]` : `{ ${shown.join(', ')} }`;
|
|
52
|
+
}
|
|
53
|
+
/** An `Error` is read the ordinary way: on current V8 `stack` is an accessor, so a data-only read would lose every native stack. */
|
|
54
|
+
function errorText({ error }) {
|
|
55
|
+
const stack = error.stack;
|
|
56
|
+
if (typeof stack === 'string' && stack.trim())
|
|
57
|
+
return stack.split('\n').slice(0, MAX_STACK_LINES).join('\n');
|
|
58
|
+
const message = error.message;
|
|
59
|
+
return typeof message === 'string' ? `Error: ${message}` : 'Error: [message unavailable]';
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Message and up to 30 stack lines of an `Error`; for any other value, its own data only.
|
|
63
|
+
* Never throws: a revoked Proxy or a hostile prototype becomes `[unreadable]`.
|
|
64
|
+
* @returns Unredacted text, cut at {@link MAX_RAW_INCIDENT_TEXT}. The caller redacts it before storing it.
|
|
65
|
+
* @complexity O(min(size of the value, a fixed bound)).
|
|
66
|
+
*/
|
|
67
|
+
export function describeThrownValue(required, _optional = {}) {
|
|
68
|
+
try {
|
|
69
|
+
const { value } = required;
|
|
70
|
+
const text = value instanceof Error ? errorText({ error: value }) : typeof value === 'string' ? value : valueText({ value, depth: 0 });
|
|
71
|
+
return text.slice(0, MAX_RAW_INCIDENT_TEXT);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return UNREADABLE;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=incident-text.js.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { type ServerApiError } from '../contracts/server/api-error.js';
|
|
2
|
+
import type { IdGenerator } from '../primitives/ids.js';
|
|
3
|
+
import type { Logger } from '../primitives/logger.js';
|
|
4
|
+
import { type Clock } from '../primitives/time.js';
|
|
5
|
+
import { type SecretRedactionOptions } from '../redaction-patterns.js';
|
|
6
|
+
import type { UserFacingError } from '../user-facing-error.js';
|
|
7
|
+
import type { ApprovedCause } from './approved-cause.js';
|
|
8
|
+
import type { ErrorCatalog } from './catalog.js';
|
|
9
|
+
import { type ErrorAudience } from './disclosure.js';
|
|
10
|
+
/** One report to the host's tracker. Structurally what `ObservabilityPort.reportError` takes; core does not import diagnostics. */
|
|
11
|
+
export interface IncidentTrackerReport {
|
|
12
|
+
readonly error: unknown;
|
|
13
|
+
readonly context: {
|
|
14
|
+
readonly operation: string;
|
|
15
|
+
readonly level?: 'warning' | 'error';
|
|
16
|
+
readonly exactSecrets?: readonly string[];
|
|
17
|
+
readonly attributes?: Readonly<Record<string, string | number>>;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface ErrorReporterPorts {
|
|
21
|
+
/** Returns a finished error ID. Hosts mint `ERR-XXXX-XXXX-XXXX-XXXX`, the one shape a reader can recover from plain text. */
|
|
22
|
+
readonly ids: IdGenerator;
|
|
23
|
+
readonly clock: Clock;
|
|
24
|
+
/** Receives the operator-only incident record. */
|
|
25
|
+
readonly logger: Pick<Logger, 'warn' | 'error'>;
|
|
26
|
+
readonly tracker: {
|
|
27
|
+
reportError(report: IncidentTrackerReport): unknown;
|
|
28
|
+
};
|
|
29
|
+
readonly catalog: ErrorCatalog;
|
|
30
|
+
readonly versions: {
|
|
31
|
+
readonly app: string;
|
|
32
|
+
readonly jini: string;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** Options of {@link createErrorReporter}. */
|
|
36
|
+
export interface ErrorReporterOptions {
|
|
37
|
+
/** The host's redaction policy and standing exact secrets, applied to every record. */
|
|
38
|
+
readonly redaction?: SecretRedactionOptions;
|
|
39
|
+
}
|
|
40
|
+
export interface DescribeFailureOptions {
|
|
41
|
+
/** Reuse an ID the boundary already minted, so one failure keeps one ID. */
|
|
42
|
+
readonly errorId?: string;
|
|
43
|
+
/** Defaults to `'anonymous'`. Set it only after authentication (and, for `'authorized'`, this operation's permission check) has passed. */
|
|
44
|
+
readonly audience?: ErrorAudience;
|
|
45
|
+
readonly approvedCause?: ApprovedCause;
|
|
46
|
+
/** Secrets known to this call (a token the request carried), blanked wherever they appear. */
|
|
47
|
+
readonly exactSecrets?: readonly string[];
|
|
48
|
+
}
|
|
49
|
+
export interface RecordFailureOptions {
|
|
50
|
+
readonly errorId?: string;
|
|
51
|
+
readonly level?: 'warning' | 'error';
|
|
52
|
+
readonly exactSecrets?: readonly string[];
|
|
53
|
+
/** `'skip'` is for a failure the caller caused and was told about (a rate-limit refusal on an
|
|
54
|
+
* anonymous surface): without it, unauthenticated requests could drive unbounded third-party
|
|
55
|
+
* reports. The host record is still written. Its callers are a reviewed list in
|
|
56
|
+
* `scripts/check-error-disclosure-callers.ts` (run by `pnpm guard`); a host keeps its own. */
|
|
57
|
+
readonly tracker?: 'report' | 'skip';
|
|
58
|
+
}
|
|
59
|
+
export interface DescribedFailure {
|
|
60
|
+
readonly kind: 'refusal' | 'incident';
|
|
61
|
+
readonly status: number;
|
|
62
|
+
readonly error: ServerApiError;
|
|
63
|
+
/** An incident's Copy-details block, for a signed-in caller only. */
|
|
64
|
+
readonly failure?: UserFacingError;
|
|
65
|
+
}
|
|
66
|
+
export interface ErrorReporter {
|
|
67
|
+
/** Refusal → its code and words. Anything else → an incident: one ID, one host record, one tracker report. Never throws. */
|
|
68
|
+
describe(required: {
|
|
69
|
+
error: unknown;
|
|
70
|
+
step: string;
|
|
71
|
+
scope: string;
|
|
72
|
+
fallback: {
|
|
73
|
+
readonly message: string;
|
|
74
|
+
readonly action: string;
|
|
75
|
+
};
|
|
76
|
+
}, optional?: DescribeFailureOptions): DescribedFailure;
|
|
77
|
+
/** A failure nobody is shown (job, cleanup, IPC handler): host record and tracker only. Never throws. */
|
|
78
|
+
record(required: {
|
|
79
|
+
error: unknown;
|
|
80
|
+
step: string;
|
|
81
|
+
}, optional?: RecordFailureOptions): {
|
|
82
|
+
errorId: string;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** Stands in when the host's ID port itself fails, so the record and the caller still agree on one value. */
|
|
86
|
+
export declare const UNAVAILABLE_ERROR_ID = "ERR-0000-0000-0000-0000";
|
|
87
|
+
/**
|
|
88
|
+
* Builds the host's reporter. `fallback` is required at every `describe` call, so the reporter has
|
|
89
|
+
* no default sentence and cannot emit a generic one.
|
|
90
|
+
* @example reporter.describe({ error, step: 'Export site', scope: 'site-export', fallback: { message: 'The site export could not be completed.', action: 'Try the export again.' } }, { audience: 'signed-in' })
|
|
91
|
+
* @complexity O(bindings in the scope) for a refusal; O(size of the error text) for an incident (redaction).
|
|
92
|
+
*/
|
|
93
|
+
export declare function createErrorReporter(required: ErrorReporterPorts, optional?: ErrorReporterOptions): ErrorReporter;
|
|
94
|
+
//# sourceMappingURL=reporter.d.ts.map
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The one incident path. A boundary (route, tool, job, IPC handler, run) hands a caught value
|
|
3
|
+
* to the reporter. A refusal (an error the scope's catalog bindings name) becomes its code and
|
|
4
|
+
* words, with no incident. Anything else is an incident: one error ID, one host record, one tracker
|
|
5
|
+
* report, and the caller gets the boundary's own fallback words with the ID.
|
|
6
|
+
*
|
|
7
|
+
* Stateless. Every dependency is a port the host passes; there is no optional sink, so an incident
|
|
8
|
+
* cannot be dropped for lack of wiring. Nothing here throws: a failing ID, clock, catalog, logger or
|
|
9
|
+
* tracker port must not replace the failure being reported; its adapter blanks secrets before anything leaves the process.
|
|
10
|
+
*/
|
|
11
|
+
import { ClientFacingError } from '../contracts/server/json-route.js';
|
|
12
|
+
import { statusForError } from '../contracts/server/api-error.js';
|
|
13
|
+
import { createErrorDescriber, describeErrorForLog, describeErrorParts } from '../model-facing-tool-errors.js';
|
|
14
|
+
import { toIsoDateTime } from '../primitives/time.js';
|
|
15
|
+
import { redactSecrets } from '../redact.js';
|
|
16
|
+
import {} from '../redaction-patterns.js';
|
|
17
|
+
import { discloseIncident } from './disclosure.js';
|
|
18
|
+
import { describeThrownValue } from './incident-text.js';
|
|
19
|
+
import { interpolateSentence } from './sentences.js';
|
|
20
|
+
/** Stands in when the host's ID port itself fails, so the record and the caller still agree on one value. */
|
|
21
|
+
export const UNAVAILABLE_ERROR_ID = 'ERR-0000-0000-0000-0000';
|
|
22
|
+
const MAX_RECORD_TEXT = 8192;
|
|
23
|
+
const MAX_PARAM_TEXT = 128;
|
|
24
|
+
const MAX_CAUSES = 3;
|
|
25
|
+
function redactionFor({ context, exactSecrets }) {
|
|
26
|
+
// Whole fields are redacted before they are cut. PII stays readable in the operator record unless the host asks otherwise.
|
|
27
|
+
return { redactPii: false, ...context.redaction, exactSecrets: [...(context.redaction.exactSecrets ?? []), ...(exactSecrets ?? [])] };
|
|
28
|
+
}
|
|
29
|
+
function attempt({ read, fallback }) {
|
|
30
|
+
try {
|
|
31
|
+
return read();
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return fallback;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Labels of up to three causes, nearest first: class and listed code only. */
|
|
38
|
+
function causeLabels({ error, describer }) {
|
|
39
|
+
const labels = [];
|
|
40
|
+
let current = error;
|
|
41
|
+
while (labels.length < MAX_CAUSES && current instanceof Error && current.cause !== undefined) {
|
|
42
|
+
current = current.cause;
|
|
43
|
+
const parts = describer.describeErrorParts({ err: current });
|
|
44
|
+
labels.push(parts.code === undefined ? parts.label : `${parts.label}(${parts.code})`);
|
|
45
|
+
}
|
|
46
|
+
return labels;
|
|
47
|
+
}
|
|
48
|
+
function headLabel({ error, describer }) {
|
|
49
|
+
const parts = describer.describeErrorParts({ err: error });
|
|
50
|
+
return parts.code === undefined ? parts.label : `${parts.label}(${parts.code})`;
|
|
51
|
+
}
|
|
52
|
+
function reportToTracker(required) {
|
|
53
|
+
const { context, incident, step, error, exactSecrets, level } = required;
|
|
54
|
+
const failed = (trackerError) => {
|
|
55
|
+
// The host record above already holds the incident; say that the tracker copy is missing.
|
|
56
|
+
attempt({ fallback: undefined, read: () => context.ports.logger.warn({ message: `[incident] the tracker did not accept the report for error ${incident.errorId}` }, { meta: { errorId: incident.errorId, tracker: describeErrorForLog({ err: trackerError }) } }) });
|
|
57
|
+
};
|
|
58
|
+
try {
|
|
59
|
+
const sent = context.ports.tracker.reportError({
|
|
60
|
+
error,
|
|
61
|
+
context: { operation: step, level, ...(exactSecrets === undefined ? {} : { exactSecrets }), attributes: { errorId: incident.errorId, label: incident.label } },
|
|
62
|
+
});
|
|
63
|
+
if (sent instanceof Promise)
|
|
64
|
+
sent.then(undefined, failed);
|
|
65
|
+
}
|
|
66
|
+
catch (trackerError) {
|
|
67
|
+
failed(trackerError);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Mints the ID, writes the one host record and (unless skipped) the one tracker report. */
|
|
71
|
+
function recordIncident(required, optional = {}) {
|
|
72
|
+
const { context, error } = required;
|
|
73
|
+
const { ports, describer } = context;
|
|
74
|
+
const redaction = redactionFor({ context, exactSecrets: optional.exactSecrets });
|
|
75
|
+
const errorId = optional.errorId ?? attempt({ read: () => ports.ids.newId(), fallback: UNAVAILABLE_ERROR_ID });
|
|
76
|
+
const time = attempt({ read: () => toIsoDateTime({ epochMs: ports.clock.nowMs() }), fallback: undefined });
|
|
77
|
+
const step = redactSecrets({ input: required.step }, redaction).slice(0, 512);
|
|
78
|
+
const label = attempt({ read: () => headLabel({ error, describer }), fallback: 'Error' });
|
|
79
|
+
const diagnostic = redactSecrets({ input: describeThrownValue({ value: error }) }, redaction).slice(0, MAX_RECORD_TEXT);
|
|
80
|
+
const incident = { errorId, label, ...(time === undefined ? {} : { time }) };
|
|
81
|
+
const level = optional.level ?? 'error';
|
|
82
|
+
const meta = {
|
|
83
|
+
errorId, step, label, causes: attempt({ read: () => causeLabels({ error, describer }), fallback: [] }),
|
|
84
|
+
appVersion: ports.versions.app, jiniVersion: ports.versions.jini, ...(time === undefined ? {} : { time }), diagnostic,
|
|
85
|
+
};
|
|
86
|
+
// `diagnostic` is the operator-only record. The tracker gets the original `error` and the call's `exactSecrets`; the tracker adapter blanks secrets before anything leaves the process.
|
|
87
|
+
attempt({ fallback: undefined, read: () => ports.logger[level === 'warning' ? 'warn' : 'error']({ message: `[incident] ${step} failed (error ${errorId})` }, { meta, error }) });
|
|
88
|
+
if (optional.tracker !== 'skip')
|
|
89
|
+
reportToTracker({ context, incident, step, error, exactSecrets: optional.exactSecrets, level });
|
|
90
|
+
return incident;
|
|
91
|
+
}
|
|
92
|
+
function redactedParams({ params, redaction }) {
|
|
93
|
+
return Object.fromEntries(Object.entries(params).map(([name, value]) => [name, typeof value === 'number' ? value : redactSecrets({ input: value }, redaction).slice(0, MAX_PARAM_TEXT)]));
|
|
94
|
+
}
|
|
95
|
+
/** The wire error of a refusal. Words a sentence reserves for authorised callers are replaced by the boundary's fallback words. */
|
|
96
|
+
function refusalError(required) {
|
|
97
|
+
const { match, fallback, audience, redaction } = required;
|
|
98
|
+
const { sentence } = match;
|
|
99
|
+
const base = { code: match.code, ...(sentence === undefined ? {} : { retryable: sentence.retryable }) };
|
|
100
|
+
if (sentence?.audience === 'authorized' && audience !== 'authorized')
|
|
101
|
+
return { ...base, message: fallback.message };
|
|
102
|
+
if (match.mode !== 'sentence')
|
|
103
|
+
return { ...base, message: match.message ?? fallback.message };
|
|
104
|
+
if (sentence === undefined)
|
|
105
|
+
return { ...base, message: fallback.message };
|
|
106
|
+
const params = redactedParams({ params: match.params ?? {}, redaction });
|
|
107
|
+
const message = interpolateSentence({ text: sentence.message }, { params });
|
|
108
|
+
return Object.keys(params).length === 0 ? { ...base, message } : { ...base, message, details: { params } };
|
|
109
|
+
}
|
|
110
|
+
function refusal(required) {
|
|
111
|
+
const { context, error } = required;
|
|
112
|
+
const { catalog } = context.ports;
|
|
113
|
+
// An already-classified carrier: our own code built it, naming the exact error it chose to disclose.
|
|
114
|
+
if (error instanceof ClientFacingError) {
|
|
115
|
+
const carried = error.apiError;
|
|
116
|
+
return { kind: 'refusal', status: catalog.statusFor({ error: carried }) ?? statusForError({ error: carried }), error: carried };
|
|
117
|
+
}
|
|
118
|
+
const match = attempt({ read: () => catalog.match({ error, scope: required.scope }), fallback: undefined });
|
|
119
|
+
if (match === undefined)
|
|
120
|
+
return undefined;
|
|
121
|
+
const wire = refusalError({ match, fallback: required.fallback, audience: required.audience, redaction: redactionFor({ context }) });
|
|
122
|
+
return { kind: 'refusal', status: match.sentence?.status ?? statusForError({ error: wire }), error: wire };
|
|
123
|
+
}
|
|
124
|
+
function describeFailure(required, optional = {}) {
|
|
125
|
+
const { context } = required;
|
|
126
|
+
const audience = optional.audience ?? 'anonymous';
|
|
127
|
+
const refused = attempt({ read: () => refusal({ context, error: required.error, scope: required.scope, fallback: required.fallback, audience }), fallback: undefined });
|
|
128
|
+
if (refused !== undefined)
|
|
129
|
+
return refused;
|
|
130
|
+
const incident = recordIncident({ context, error: required.error, step: required.step }, { ...(optional.errorId === undefined ? {} : { errorId: optional.errorId }), ...(optional.exactSecrets === undefined ? {} : { exactSecrets: optional.exactSecrets }) });
|
|
131
|
+
const failure = attempt({ fallback: undefined, read: () => discloseIncident({ audience, step: required.step, label: incident.label, errorId: incident.errorId, fallback: required.fallback, versions: context.ports.versions }, { redaction: redactionFor({ context, exactSecrets: optional.exactSecrets }), ...(optional.approvedCause === undefined ? {} : { approvedCause: optional.approvedCause }), ...(incident.time === undefined ? {} : { time: incident.time }) }) });
|
|
132
|
+
// The ID is part of the words, so it survives a consumer that keeps only a message string.
|
|
133
|
+
const error = { code: 'INTERNAL_ERROR', message: `${required.fallback.message} (error ${incident.errorId})`, requestId: incident.errorId };
|
|
134
|
+
return { kind: 'incident', status: 500, error, ...(failure === undefined ? {} : { failure }) };
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Builds the host's reporter. `fallback` is required at every `describe` call, so the reporter has
|
|
138
|
+
* no default sentence and cannot emit a generic one.
|
|
139
|
+
* @example reporter.describe({ error, step: 'Export site', scope: 'site-export', fallback: { message: 'The site export could not be completed.', action: 'Try the export again.' } }, { audience: 'signed-in' })
|
|
140
|
+
* @complexity O(bindings in the scope) for a refusal; O(size of the error text) for an incident (redaction).
|
|
141
|
+
*/
|
|
142
|
+
export function createErrorReporter(required, optional = {}) {
|
|
143
|
+
// The catalog's codes and labelled classes extend what a record may name; a catalog whose
|
|
144
|
+
// vocabulary cannot be read still leaves the built-in describer.
|
|
145
|
+
const describer = attempt({ read: () => createErrorDescriber(required.catalog.describerVocabulary()), fallback: { describeErrorParts, describeErrorForLog } });
|
|
146
|
+
const context = { ports: required, redaction: optional.redaction ?? {}, describer };
|
|
147
|
+
return {
|
|
148
|
+
describe: (args, options = {}) => describeFailure({ context, ...args }, options),
|
|
149
|
+
record: (args, options = {}) => ({ errorId: recordIncident({ context, error: args.error, step: args.step }, options).errorId }),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=reporter.js.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Relation 1 of the error catalog: the plain words for one error code (what failed, what to
|
|
3
|
+
* do next) with its HTTP status. One definition per code.
|
|
4
|
+
*
|
|
5
|
+
* This is the only module a feature's `*.sentences.ts` file may import, and the admin bundle
|
|
6
|
+
* imports those files, so this module imports nothing: no error class, no server code.
|
|
7
|
+
* Class-to-code bindings live in `bindings.ts`, which is server-side.
|
|
8
|
+
*/
|
|
9
|
+
/** Who may read a sentence's words: any caller, or only one authorised for the operation. */
|
|
10
|
+
export type SentenceAudience = 'anyone' | 'authorized';
|
|
11
|
+
/** The plain words for one error code. English source text; `{name}` placeholders only. */
|
|
12
|
+
export interface ErrorSentence {
|
|
13
|
+
/** HTTP status at a route boundary. */
|
|
14
|
+
readonly status: number;
|
|
15
|
+
readonly retryable: boolean;
|
|
16
|
+
/** What failed. */
|
|
17
|
+
readonly message: string;
|
|
18
|
+
/** What to do next. */
|
|
19
|
+
readonly action: string;
|
|
20
|
+
readonly audience: SentenceAudience;
|
|
21
|
+
}
|
|
22
|
+
/** One feature's sentences. Every code starts with the set's `domain` prefix. */
|
|
23
|
+
export interface ErrorSentenceSet {
|
|
24
|
+
readonly domain: string;
|
|
25
|
+
readonly codes: Readonly<Record<string, ErrorSentence>>;
|
|
26
|
+
}
|
|
27
|
+
/** Options of {@link defineErrorSentences}. None yet; named so one can be added without changing the signature. */
|
|
28
|
+
export interface ErrorSentenceOptions {
|
|
29
|
+
}
|
|
30
|
+
/** Options of {@link interpolateSentence}. */
|
|
31
|
+
export interface InterpolateSentenceOptions {
|
|
32
|
+
/** Values for the `{name}` placeholders. A placeholder with no value is left as written. */
|
|
33
|
+
readonly params?: Readonly<Record<string, string | number>>;
|
|
34
|
+
}
|
|
35
|
+
/** True for a code the catalog accepts: `[A-Z][A-Z0-9_]*`, at most 64 characters. */
|
|
36
|
+
export declare function isErrorCodeToken(required: {
|
|
37
|
+
code: unknown;
|
|
38
|
+
}, _optional?: ErrorSentenceOptions): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Declares one feature's sentences. A code is a constant token and starts with `<domain>_`, so a
|
|
41
|
+
* feature cannot give words to a shared generic code (`RESOURCE_CONFLICT` means different things in
|
|
42
|
+
* different domains; its words belong to each feature's own namespaced code).
|
|
43
|
+
* @throws TypeError for a code, status or text of the wrong shape (a programming error, found at load).
|
|
44
|
+
* @example defineErrorSentences({ domain: 'MEMBERS', codes: { MEMBERS_NOT_FOUND: { status: 404, retryable: false, message: 'That member does not exist.', action: 'Check the member list and try again.', audience: 'anyone' } } })
|
|
45
|
+
* @complexity O(codes).
|
|
46
|
+
*/
|
|
47
|
+
export declare function defineErrorSentences(required: {
|
|
48
|
+
domain: string;
|
|
49
|
+
codes: Readonly<Record<string, ErrorSentence>>;
|
|
50
|
+
}, _optional?: ErrorSentenceOptions): ErrorSentenceSet;
|
|
51
|
+
/**
|
|
52
|
+
* Core's own set: the generic version codes every domain shares. Built here, without the prefix
|
|
53
|
+
* rule, because no exported function can define an unprefixed code. `CONCURRENT_EDIT` is a legacy
|
|
54
|
+
* generic code with the same sentence as `VERSION_CONFLICT`: two domains answer with it today, so
|
|
55
|
+
* no feature set may define it. The two version literals equal `VERSION_CONFLICT_CODE` and
|
|
56
|
+
* `VERSION_REQUIRED_CODE` in `optimistic-concurrency.ts` (a test holds them together; this file
|
|
57
|
+
* imports nothing).
|
|
58
|
+
*/
|
|
59
|
+
export declare const CORE_ERROR_SENTENCES: ErrorSentenceSet;
|
|
60
|
+
/**
|
|
61
|
+
* Fills a sentence's `{name}` placeholders. Used by the server for the English wire message and by
|
|
62
|
+
* a client after translating the source text. A placeholder with no value stays as written.
|
|
63
|
+
* @complexity O(text length).
|
|
64
|
+
*/
|
|
65
|
+
export declare function interpolateSentence(required: {
|
|
66
|
+
text: string;
|
|
67
|
+
}, optional?: InterpolateSentenceOptions): string;
|
|
68
|
+
//# sourceMappingURL=sentences.d.ts.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Relation 1 of the error catalog: the plain words for one error code (what failed, what to
|
|
3
|
+
* do next) with its HTTP status. One definition per code.
|
|
4
|
+
*
|
|
5
|
+
* This is the only module a feature's `*.sentences.ts` file may import, and the admin bundle
|
|
6
|
+
* imports those files, so this module imports nothing: no error class, no server code.
|
|
7
|
+
* Class-to-code bindings live in `bindings.ts`, which is server-side.
|
|
8
|
+
*/
|
|
9
|
+
/** A constant token: the only shape a catalog code may have (the log describer's own rule). */
|
|
10
|
+
const CONSTANT_TOKEN = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
11
|
+
const PLACEHOLDER = /\{([A-Za-z][A-Za-z0-9_]{0,31})\}/g;
|
|
12
|
+
/** True for a code the catalog accepts: `[A-Z][A-Z0-9_]*`, at most 64 characters. */
|
|
13
|
+
export function isErrorCodeToken(required, _optional = {}) {
|
|
14
|
+
return typeof required.code === 'string' && CONSTANT_TOKEN.test(required.code);
|
|
15
|
+
}
|
|
16
|
+
function wordsProblem({ code, sentence }) {
|
|
17
|
+
if (typeof sentence.message !== 'string' || !sentence.message.trim())
|
|
18
|
+
return `"${code}" needs a message that says what failed`;
|
|
19
|
+
if (typeof sentence.action !== 'string' || !sentence.action.trim())
|
|
20
|
+
return `"${code}" needs an action that says what to do next`;
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
function sentenceProblem({ code, sentence }) {
|
|
24
|
+
if (!Number.isInteger(sentence.status) || sentence.status < 400 || sentence.status > 599)
|
|
25
|
+
return `"${code}" needs an HTTP status from 400 to 599`;
|
|
26
|
+
if (typeof sentence.retryable !== 'boolean')
|
|
27
|
+
return `"${code}" needs retryable to be true or false`;
|
|
28
|
+
if (sentence.audience !== 'anyone' && sentence.audience !== 'authorized')
|
|
29
|
+
return `"${code}" needs audience "anyone" or "authorized"`;
|
|
30
|
+
return wordsProblem({ code, sentence });
|
|
31
|
+
}
|
|
32
|
+
function buildSet({ domain, codes, prefixed }) {
|
|
33
|
+
if (!isErrorCodeToken({ code: domain }))
|
|
34
|
+
throw new TypeError(`Error sentences: the domain "${String(domain)}" must be a constant token like MEMBERS.`);
|
|
35
|
+
const checked = {};
|
|
36
|
+
for (const [code, sentence] of Object.entries(codes)) {
|
|
37
|
+
if (!isErrorCodeToken({ code }))
|
|
38
|
+
throw new TypeError(`Error sentences (${domain}): the code "${code}" must be a constant token like ${domain}_NOT_FOUND.`);
|
|
39
|
+
if (prefixed && !code.startsWith(`${domain}_`))
|
|
40
|
+
throw new TypeError(`Error sentences (${domain}): the code "${code}" must start with "${domain}_". Shared generic codes are defined only by core.`);
|
|
41
|
+
const problem = sentenceProblem({ code, sentence });
|
|
42
|
+
if (problem !== undefined)
|
|
43
|
+
throw new TypeError(`Error sentences (${domain}): ${problem}.`);
|
|
44
|
+
checked[code] = Object.freeze({ ...sentence });
|
|
45
|
+
}
|
|
46
|
+
return Object.freeze({ domain, codes: Object.freeze(checked) });
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Declares one feature's sentences. A code is a constant token and starts with `<domain>_`, so a
|
|
50
|
+
* feature cannot give words to a shared generic code (`RESOURCE_CONFLICT` means different things in
|
|
51
|
+
* different domains; its words belong to each feature's own namespaced code).
|
|
52
|
+
* @throws TypeError for a code, status or text of the wrong shape (a programming error, found at load).
|
|
53
|
+
* @example defineErrorSentences({ domain: 'MEMBERS', codes: { MEMBERS_NOT_FOUND: { status: 404, retryable: false, message: 'That member does not exist.', action: 'Check the member list and try again.', audience: 'anyone' } } })
|
|
54
|
+
* @complexity O(codes).
|
|
55
|
+
*/
|
|
56
|
+
export function defineErrorSentences(required, _optional = {}) {
|
|
57
|
+
return buildSet({ ...required, prefixed: true });
|
|
58
|
+
}
|
|
59
|
+
const VERSION_CONFLICT_SENTENCE = {
|
|
60
|
+
status: 409, retryable: false, audience: 'anyone',
|
|
61
|
+
message: 'This record was changed by someone else after you opened it, so nothing was saved.',
|
|
62
|
+
action: 'Reload it to see the latest version, then make your change again.',
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Core's own set: the generic version codes every domain shares. Built here, without the prefix
|
|
66
|
+
* rule, because no exported function can define an unprefixed code. `CONCURRENT_EDIT` is a legacy
|
|
67
|
+
* generic code with the same sentence as `VERSION_CONFLICT`: two domains answer with it today, so
|
|
68
|
+
* no feature set may define it. The two version literals equal `VERSION_CONFLICT_CODE` and
|
|
69
|
+
* `VERSION_REQUIRED_CODE` in `optimistic-concurrency.ts` (a test holds them together; this file
|
|
70
|
+
* imports nothing).
|
|
71
|
+
*/
|
|
72
|
+
export const CORE_ERROR_SENTENCES = buildSet({
|
|
73
|
+
domain: 'CORE', prefixed: false,
|
|
74
|
+
codes: {
|
|
75
|
+
VERSION_CONFLICT: VERSION_CONFLICT_SENTENCE,
|
|
76
|
+
CONCURRENT_EDIT: VERSION_CONFLICT_SENTENCE,
|
|
77
|
+
VERSION_REQUIRED: {
|
|
78
|
+
status: 428, retryable: false, audience: 'anyone',
|
|
79
|
+
message: "This save did not say which version you were editing, so nothing was saved (it could have overwritten someone else's change).",
|
|
80
|
+
action: 'Reload, make your change again, and save.',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
/**
|
|
85
|
+
* Fills a sentence's `{name}` placeholders. Used by the server for the English wire message and by
|
|
86
|
+
* a client after translating the source text. A placeholder with no value stays as written.
|
|
87
|
+
* @complexity O(text length).
|
|
88
|
+
*/
|
|
89
|
+
export function interpolateSentence(required, optional = {}) {
|
|
90
|
+
const params = optional.params ?? {};
|
|
91
|
+
return required.text.replace(PLACEHOLDER, (whole, name) => (Object.hasOwn(params, name) ? String(params[name]) : whole));
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=sentences.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Recording fakes of the reporter's ports, for tests in any package: a fake of an interface,
|
|
3
|
+
* never a mock of another package's internals.
|
|
4
|
+
*/
|
|
5
|
+
import type { IdGenerator } from '../primitives/ids.js';
|
|
6
|
+
import type { LogDiagnosticRecord, Logger } from '../primitives/logger.js';
|
|
7
|
+
import type { Clock } from '../primitives/time.js';
|
|
8
|
+
import { type ErrorCatalog } from './catalog.js';
|
|
9
|
+
import { type ErrorReporter, type ErrorReporterOptions, type IncidentTrackerReport } from './reporter.js';
|
|
10
|
+
/** A logger that keeps every call exactly as made, original error objects included. */
|
|
11
|
+
export declare function createRecordingLogger(): {
|
|
12
|
+
readonly logger: Logger;
|
|
13
|
+
readonly entries: LogDiagnosticRecord[];
|
|
14
|
+
};
|
|
15
|
+
/** A tracker that keeps every report. */
|
|
16
|
+
export declare function createRecordingTracker(): {
|
|
17
|
+
readonly tracker: {
|
|
18
|
+
reportError(report: IncidentTrackerReport): void;
|
|
19
|
+
};
|
|
20
|
+
readonly reports: IncidentTrackerReport[];
|
|
21
|
+
};
|
|
22
|
+
/** Hands out the given IDs in order; throws when a test asks for more than it listed. */
|
|
23
|
+
export declare function createSequenceIds(required: {
|
|
24
|
+
ids: readonly string[];
|
|
25
|
+
}): IdGenerator;
|
|
26
|
+
/** A clock fixed at one instant. */
|
|
27
|
+
export declare function createFixedClock(required: {
|
|
28
|
+
iso: string;
|
|
29
|
+
}): Clock;
|
|
30
|
+
/** Options of {@link createRecordingReporter}. */
|
|
31
|
+
export interface RecordingReporterOptions extends ErrorReporterOptions {
|
|
32
|
+
readonly catalog?: ErrorCatalog;
|
|
33
|
+
readonly versions?: {
|
|
34
|
+
readonly app: string;
|
|
35
|
+
readonly jini: string;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A real reporter over recording ports, for a test that needs to see what an incident wrote.
|
|
40
|
+
* @example const { reporter, entries, reports } = createRecordingReporter({ ids: ['ERR-0000-0000-0000-0001'], iso: '2026-01-01T00:00:00.000Z' });
|
|
41
|
+
*/
|
|
42
|
+
export declare function createRecordingReporter(required: {
|
|
43
|
+
ids: readonly string[];
|
|
44
|
+
iso: string;
|
|
45
|
+
}, optional?: RecordingReporterOptions): {
|
|
46
|
+
readonly reporter: ErrorReporter;
|
|
47
|
+
readonly entries: LogDiagnosticRecord[];
|
|
48
|
+
readonly reports: IncidentTrackerReport[];
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=testing.d.ts.map
|