@jini-ai/core 0.7.2 → 0.7.3-next.2
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 +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 +235 -0
- package/dist/contracts/observability.js +28 -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/gated-mutations/gateway.d.ts +2 -0
- package/dist/gated-mutations/gateway.js +4 -1
- 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 +235 -14
- package/plugin-directory.d.ts +2 -2
- package/plugin-directory.js +16 -10
- 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,68 @@
|
|
|
1
|
+
import type { JsonValue, UUID } from "../primitives/index.js";
|
|
2
|
+
import type { SettingScope } from "./types.js";
|
|
3
|
+
import type { SetValueRequired, resolveScopedDefinitionOrThrow } from './write-values.js';
|
|
4
|
+
import { type SettingsWriteServiceDeps } from './write-service.js';
|
|
5
|
+
/**
|
|
6
|
+
* Every non-global write must land in the workspace it was AUTHORIZED against.
|
|
7
|
+
*
|
|
8
|
+
* `authorize()` is called with `authWorkspaceId` while the value row and revision are written with
|
|
9
|
+
* `input.workspaceId`. Nothing forces the two to match unless this guard runs — a caller that
|
|
10
|
+
* constructs the input directly (rather than through a route that validates the body against the
|
|
11
|
+
* ambient workspace) could otherwise pass a mismatched target and have the write land in a
|
|
12
|
+
* workspace neither `authorize()` call was actually evaluated against.
|
|
13
|
+
*
|
|
14
|
+
* A host's HTTP routes should reject a mismatched body id at the route layer (the real fix, closer
|
|
15
|
+
* to the request). This is the backstop: it holds for every internal caller that constructs the
|
|
16
|
+
* input directly, and makes a future caller incapable of reintroducing the gap.
|
|
17
|
+
*
|
|
18
|
+
* `ForbiddenError` rather than a validation error because the condition is exactly "you are not
|
|
19
|
+
* authorized to write to that workspace".
|
|
20
|
+
*
|
|
21
|
+
* `scope: "global"` is exempt: the platform partition has no workspace, and `set`/`clear` already
|
|
22
|
+
* force `workspaceId: null` on that path.
|
|
23
|
+
*/
|
|
24
|
+
export declare function assertTargetWorkspaceMatchesAuth(input: {
|
|
25
|
+
scope: SettingScope;
|
|
26
|
+
workspaceId?: UUID | undefined;
|
|
27
|
+
authWorkspaceId: UUID;
|
|
28
|
+
callerPrincipalId: UUID;
|
|
29
|
+
}): void;
|
|
30
|
+
/** Optional concurrency guard shared by `set` and `clear`. */
|
|
31
|
+
export interface SettingsValueWriteOptions {
|
|
32
|
+
/** Compare the addressed layer's stored seq, including cleared rows; 0 means no stored row.
|
|
33
|
+
* Omission preserves unconditional writes. Defaults, inherited values and definition revisions
|
|
34
|
+
* do not count. A mismatch throws SettingsRevisionConflictError and rolls back the write.
|
|
35
|
+
*/
|
|
36
|
+
readonly expectedRevisionSeq?: number | undefined;
|
|
37
|
+
}
|
|
38
|
+
type ValueWriteInput = Pick<SetValueRequired["input"], "scope" | "workspaceId" | "principalId" | "callerPrincipalId" | "authWorkspaceId">;
|
|
39
|
+
/** The permission a caller needs for this target, derived from scope and who is being written for. */
|
|
40
|
+
export declare function derivePermissionFor({ input }: {
|
|
41
|
+
input: ValueWriteInput;
|
|
42
|
+
}): string;
|
|
43
|
+
/** Authorize the caller in the ambient workspace; the target workspace must match it. Refusal throws. */
|
|
44
|
+
export declare function authorizeValueWrite({ deps, input, permission }: {
|
|
45
|
+
deps: SettingsWriteServiceDeps;
|
|
46
|
+
input: ValueWriteInput;
|
|
47
|
+
permission: string;
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
/** Append the ledger revision, check the concurrency guard, then save the addressed layer's row. */
|
|
50
|
+
export declare function writeValueRevision({ deps, input, definition, optional, change }: {
|
|
51
|
+
deps: SettingsWriteServiceDeps;
|
|
52
|
+
input: ValueWriteInput & {
|
|
53
|
+
namespace: string;
|
|
54
|
+
key: string;
|
|
55
|
+
};
|
|
56
|
+
definition: Awaited<ReturnType<typeof resolveScopedDefinitionOrThrow>>;
|
|
57
|
+
optional: SettingsValueWriteOptions;
|
|
58
|
+
change: {
|
|
59
|
+
op: "set" | "clear";
|
|
60
|
+
afterJson: JsonValue | null;
|
|
61
|
+
valueJson: JsonValue | null;
|
|
62
|
+
state: "set" | "cleared";
|
|
63
|
+
};
|
|
64
|
+
}): Promise<{
|
|
65
|
+
revisionSeq: number;
|
|
66
|
+
}>;
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=write-value-revisions.d.ts.map
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { nowIso as kernelNowIso } from "../primitives/index.js";
|
|
2
|
+
import { ForbiddenError, SettingsRevisionConflictError } from "./errors.js";
|
|
3
|
+
import { deriveRequiredPermission } from './write-service.js';
|
|
4
|
+
/**
|
|
5
|
+
* Every non-global write must land in the workspace it was AUTHORIZED against.
|
|
6
|
+
*
|
|
7
|
+
* `authorize()` is called with `authWorkspaceId` while the value row and revision are written with
|
|
8
|
+
* `input.workspaceId`. Nothing forces the two to match unless this guard runs — a caller that
|
|
9
|
+
* constructs the input directly (rather than through a route that validates the body against the
|
|
10
|
+
* ambient workspace) could otherwise pass a mismatched target and have the write land in a
|
|
11
|
+
* workspace neither `authorize()` call was actually evaluated against.
|
|
12
|
+
*
|
|
13
|
+
* A host's HTTP routes should reject a mismatched body id at the route layer (the real fix, closer
|
|
14
|
+
* to the request). This is the backstop: it holds for every internal caller that constructs the
|
|
15
|
+
* input directly, and makes a future caller incapable of reintroducing the gap.
|
|
16
|
+
*
|
|
17
|
+
* `ForbiddenError` rather than a validation error because the condition is exactly "you are not
|
|
18
|
+
* authorized to write to that workspace".
|
|
19
|
+
*
|
|
20
|
+
* `scope: "global"` is exempt: the platform partition has no workspace, and `set`/`clear` already
|
|
21
|
+
* force `workspaceId: null` on that path.
|
|
22
|
+
*/
|
|
23
|
+
export function assertTargetWorkspaceMatchesAuth(input) {
|
|
24
|
+
if (input.scope === "global")
|
|
25
|
+
return;
|
|
26
|
+
if (input.workspaceId === undefined)
|
|
27
|
+
return;
|
|
28
|
+
if (input.workspaceId === input.authWorkspaceId)
|
|
29
|
+
return;
|
|
30
|
+
throw new ForbiddenError(`principal '${input.callerPrincipalId}' authorized against workspace '${input.authWorkspaceId}' ` +
|
|
31
|
+
`but the write targets workspace '${input.workspaceId}'`);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Check the addressed value after appendRevision has taken the ledger lock. On Postgres, a read
|
|
35
|
+
* before that lock can see the same old seq in two READ COMMITTED transactions and lose an update.
|
|
36
|
+
* The caller's enclosing transaction rolls the appended revision back on conflict.
|
|
37
|
+
* @complexity At most one scoped value read; no reads when the option is omitted.
|
|
38
|
+
*/
|
|
39
|
+
/** The one stored value the write addresses, at its own scope. */
|
|
40
|
+
function readAddressedValue({ repo, settingId, input }) {
|
|
41
|
+
if (input.scope === "global")
|
|
42
|
+
return repo.getGlobalValue(settingId);
|
|
43
|
+
if (input.scope === "workspace")
|
|
44
|
+
return repo.getWorkspaceValue({ workspaceId: input.workspaceId, settingId });
|
|
45
|
+
return repo.getUserValue({ workspaceId: input.workspaceId, principalId: input.principalId ?? input.callerPrincipalId, settingId });
|
|
46
|
+
}
|
|
47
|
+
async function assertExpectedRevision(required, optional = {}) {
|
|
48
|
+
if (optional.expectedRevisionSeq === undefined)
|
|
49
|
+
return;
|
|
50
|
+
const { repo, settingId, input } = required;
|
|
51
|
+
const current = await readAddressedValue({ repo, settingId, input });
|
|
52
|
+
const actualRevisionSeq = current?.seq ?? 0;
|
|
53
|
+
if (actualRevisionSeq !== optional.expectedRevisionSeq) {
|
|
54
|
+
throw new SettingsRevisionConflictError({ expectedRevisionSeq: optional.expectedRevisionSeq, actualRevisionSeq });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** The permission a caller needs for this target, derived from scope and who is being written for. */
|
|
58
|
+
export function derivePermissionFor({ input }) {
|
|
59
|
+
return deriveRequiredPermission({
|
|
60
|
+
scope: input.scope,
|
|
61
|
+
targetPrincipalId: input.principalId,
|
|
62
|
+
callerPrincipalId: input.callerPrincipalId,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** Authorize the caller in the ambient workspace; the target workspace must match it. Refusal throws. */
|
|
66
|
+
export async function authorizeValueWrite({ deps, input, permission }) {
|
|
67
|
+
const authWorkspaceId = input.authWorkspaceId ?? input.workspaceId ?? input.callerPrincipalId;
|
|
68
|
+
assertTargetWorkspaceMatchesAuth({ ...input, authWorkspaceId });
|
|
69
|
+
const authResult = await deps.authorize({
|
|
70
|
+
principalId: input.callerPrincipalId,
|
|
71
|
+
permission,
|
|
72
|
+
workspaceId: authWorkspaceId,
|
|
73
|
+
entityType: "setting-value",
|
|
74
|
+
});
|
|
75
|
+
if (!authResult.allowed) {
|
|
76
|
+
throw new ForbiddenError(`principal '${input.callerPrincipalId}' is not authorized for '${permission}' (${authResult.reason})`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** Append the ledger revision, check the concurrency guard, then save the addressed layer's row. */
|
|
80
|
+
export async function writeValueRevision({ deps, input, definition, optional, change }) {
|
|
81
|
+
const now = kernelNowIso({ clock: deps.clock });
|
|
82
|
+
const revisionSeq = await deps.repo.appendRevision({
|
|
83
|
+
entityKind: "value",
|
|
84
|
+
settingId: definition.settingId,
|
|
85
|
+
scope: input.scope,
|
|
86
|
+
workspaceId: input.scope === "global" ? null : (input.workspaceId ?? null),
|
|
87
|
+
principalId: input.scope === "user" ? (input.principalId ?? input.callerPrincipalId) : null,
|
|
88
|
+
op: change.op,
|
|
89
|
+
beforeJson: null,
|
|
90
|
+
afterJson: change.afterJson,
|
|
91
|
+
defVersion: definition.version,
|
|
92
|
+
actor: input.callerPrincipalId,
|
|
93
|
+
originPluginId: null,
|
|
94
|
+
changeSetId: null,
|
|
95
|
+
createdAt: now,
|
|
96
|
+
});
|
|
97
|
+
await assertExpectedRevision({ repo: deps.repo, settingId: definition.settingId, input }, optional);
|
|
98
|
+
const base = {
|
|
99
|
+
settingId: definition.settingId,
|
|
100
|
+
scope: input.scope,
|
|
101
|
+
valueJson: change.valueJson,
|
|
102
|
+
state: change.state,
|
|
103
|
+
defVersion: definition.version,
|
|
104
|
+
seq: revisionSeq,
|
|
105
|
+
updatedBy: input.callerPrincipalId,
|
|
106
|
+
updatedAt: now,
|
|
107
|
+
originPluginId: null,
|
|
108
|
+
};
|
|
109
|
+
if (input.scope === "global") {
|
|
110
|
+
await deps.repo.saveGlobalValue({ ...base, workspaceId: null, principalId: null });
|
|
111
|
+
}
|
|
112
|
+
else if (input.scope === "workspace") {
|
|
113
|
+
await deps.repo.saveWorkspaceValue({ ...base, workspaceId: input.workspaceId ?? null, principalId: null });
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
await deps.repo.saveUserValue({
|
|
117
|
+
...base,
|
|
118
|
+
workspaceId: input.workspaceId ?? null,
|
|
119
|
+
principalId: input.principalId ?? input.callerPrincipalId,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return { revisionSeq };
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=write-value-revisions.js.map
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { JsonValue, UUID } from "../primitives/index.js";
|
|
2
|
+
import { type SettingScope } from "./types.js";
|
|
3
|
+
import type { SettingsWriteServiceDeps } from './write-service.js';
|
|
4
|
+
import { type SettingsValueWriteOptions } from './write-value-revisions.js';
|
|
5
|
+
export interface SetValueRequired {
|
|
6
|
+
deps: SettingsWriteServiceDeps;
|
|
7
|
+
input: {
|
|
8
|
+
namespace: string;
|
|
9
|
+
key: string;
|
|
10
|
+
scope: SettingScope;
|
|
11
|
+
value: JsonValue;
|
|
12
|
+
workspaceId?: UUID | undefined;
|
|
13
|
+
principalId?: UUID | undefined;
|
|
14
|
+
callerPrincipalId: UUID;
|
|
15
|
+
/**
|
|
16
|
+
* The ambient workspace to authorize the caller's grant in. Optional and
|
|
17
|
+
* additive: when omitted, falls back to `input.workspaceId ??
|
|
18
|
+
* input.callerPrincipalId`. Callers that DO have a real ambient workspace
|
|
19
|
+
* (every HTTP route in a single-workspace host) should pass it
|
|
20
|
+
* explicitly: for `scope=global` (no `workspaceId`), falling back to
|
|
21
|
+
* `callerPrincipalId` as a stand-in "workspace" id is nonsensical against
|
|
22
|
+
* the real `authorize()` (identity's own authorize looks the principal up
|
|
23
|
+
* by `{workspaceId, id}` — a bogus workspaceId means `findById` returns
|
|
24
|
+
* null and every request is denied `principal_disabled`, including the
|
|
25
|
+
* wildcard-owner).
|
|
26
|
+
*/
|
|
27
|
+
authWorkspaceId?: UUID | undefined;
|
|
28
|
+
/** Set by a caller that has ALREADY opened a transaction around this write —
|
|
29
|
+
* see `resetNamespace`. Explicit rather than an ambient depth counter,
|
|
30
|
+
* because an ambient one cannot tell a genuine nesting from a concurrent
|
|
31
|
+
* unrelated transaction and silently merges the two. */
|
|
32
|
+
skipTransaction?: boolean | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* `deriveRequiredPermission` unconditionally derives `settings.workspace.write` for
|
|
35
|
+
* `scope: "workspace"` — a caller that already authorized a narrower, domain-specific
|
|
36
|
+
* permission at its own route layer (e.g. a comments module's `comments.configure`, an SEO
|
|
37
|
+
* module's `admin.seo.manage`) still hits this chokepoint's generic `settings.workspace.write`
|
|
38
|
+
* check and gets a masked 500 if it lacks that broader grant, even though its own domain
|
|
39
|
+
* permission is exactly what the feature's admin UI advertises as sufficient. Optional and
|
|
40
|
+
* additive: omitted, behavior is unchanged (every pre-existing caller still gets the
|
|
41
|
+
* scope-derived permission). When a domain-settings module supplies this, the chokepoint
|
|
42
|
+
* authorizes THIS permission instead of the scope-derived one — still a mandatory
|
|
43
|
+
* `authorize` call before any write ( fail-closed discipline is not relaxed, only
|
|
44
|
+
* which permission string is checked).
|
|
45
|
+
* See docs/decisions/DR-003-settings-ledger-invariants.md.
|
|
46
|
+
*/
|
|
47
|
+
requiredPermissionOverride?: string | undefined;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export declare function resolveScopedDefinitionOrThrow(deps: SettingsWriteServiceDeps, input: {
|
|
51
|
+
namespace: string;
|
|
52
|
+
key: string;
|
|
53
|
+
scope: SettingScope;
|
|
54
|
+
workspaceId?: UUID | undefined;
|
|
55
|
+
}): Promise<import("./types.js").SettingDefinitionRecord>;
|
|
56
|
+
/**
|
|
57
|
+
* Authorize -> validate -> value + revision in one transaction. An optional expectedRevisionSeq
|
|
58
|
+
* refuses a stale scoped value and rolls back its revision; omission keeps unconditional writes.
|
|
59
|
+
* @example await set({ deps, input }, { expectedRevisionSeq: snapshotSeq });
|
|
60
|
+
* See docs/decisions/DR-003-settings-ledger-invariants.md.
|
|
61
|
+
*/
|
|
62
|
+
export declare function set(required: SetValueRequired, optional?: SettingsValueWriteOptions): Promise<{
|
|
63
|
+
value: JsonValue;
|
|
64
|
+
revisionSeq: number;
|
|
65
|
+
}>;
|
|
66
|
+
export interface ClearValueRequired {
|
|
67
|
+
deps: SettingsWriteServiceDeps;
|
|
68
|
+
input: {
|
|
69
|
+
namespace: string;
|
|
70
|
+
key: string;
|
|
71
|
+
scope: SettingScope;
|
|
72
|
+
workspaceId?: UUID | undefined;
|
|
73
|
+
principalId?: UUID | undefined;
|
|
74
|
+
callerPrincipalId: UUID;
|
|
75
|
+
/** Set by `resetNamespace` when looping `clear` in its own reset-authorized context — bypasses the inner authorize re-check, still writes a normal revision. See docs/decisions/DR-003-settings-ledger-invariants.md. */
|
|
76
|
+
skipAuthorize?: boolean | undefined;
|
|
77
|
+
/** Set by a caller that has ALREADY opened a transaction around this write —
|
|
78
|
+
* see `resetNamespace`. Explicit rather than an ambient depth counter,
|
|
79
|
+
* because an ambient one cannot tell a genuine nesting from a concurrent
|
|
80
|
+
* unrelated transaction and silently merges the two. */
|
|
81
|
+
skipTransaction?: boolean | undefined;
|
|
82
|
+
/** See `SetValueRequired.input.authWorkspaceId`'s doc. Optional/additive. */
|
|
83
|
+
authWorkspaceId?: UUID | undefined;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Authorize -> cleared value + revision in one transaction; the optional concurrency guard has
|
|
88
|
+
* the same semantics as `set`. With skipTransaction, the enclosing caller must propagate errors
|
|
89
|
+
* so its transaction rolls back the appended revision on conflict.
|
|
90
|
+
* @example await clear({ deps, input }, { expectedRevisionSeq: snapshotSeq });
|
|
91
|
+
* See docs/decisions/DR-003-settings-ledger-invariants.md.
|
|
92
|
+
*/
|
|
93
|
+
export declare function clear(required: ClearValueRequired, optional?: SettingsValueWriteOptions): Promise<{
|
|
94
|
+
revisionSeq: number;
|
|
95
|
+
}>;
|
|
96
|
+
//# sourceMappingURL=write-values.d.ts.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { DefinitionNotFoundError, DefinitionTombstonedError, PrincipalNotFoundError, ScopeNotAllowedError, ValueValidationFailedError } from "./errors.js";
|
|
2
|
+
import { resolveDefinitionRaw, validateValueAgainstSchema } from "./settings.js";
|
|
3
|
+
import { SCOPE_BIT } from "./types.js";
|
|
4
|
+
import { assertTargetWorkspaceMatchesAuth, authorizeValueWrite, derivePermissionFor, writeValueRevision } from './write-value-revisions.js';
|
|
5
|
+
export async function resolveScopedDefinitionOrThrow(deps, input) {
|
|
6
|
+
const definitionWorkspaceId = input.scope === "global" ? null : (input.workspaceId ?? null);
|
|
7
|
+
const definition = await resolveDefinitionRaw(deps, {
|
|
8
|
+
namespace: input.namespace,
|
|
9
|
+
key: input.key,
|
|
10
|
+
workspaceId: definitionWorkspaceId,
|
|
11
|
+
});
|
|
12
|
+
if (!definition) {
|
|
13
|
+
throw new DefinitionNotFoundError(`setting '${input.namespace}.${input.key}' was not found`);
|
|
14
|
+
}
|
|
15
|
+
if (definition.status === "tombstone") {
|
|
16
|
+
throw new DefinitionTombstonedError(`setting '${input.namespace}.${input.key}' has been tombstoned`);
|
|
17
|
+
}
|
|
18
|
+
if ((definition.scopes & SCOPE_BIT[input.scope]) === 0) {
|
|
19
|
+
throw new ScopeNotAllowedError(`setting '${input.namespace}.${input.key}' does not allow scope '${input.scope}'`);
|
|
20
|
+
}
|
|
21
|
+
return definition;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* — for scope=user writes targeting another principal, verify
|
|
25
|
+
* that principal resolves to an active user whose own `workspace_id` equals
|
|
26
|
+
* the request's `workspaceId` (structural scoping — a principal
|
|
27
|
+
* belongs to exactly one workspace, not a membership join).
|
|
28
|
+
* See docs/decisions/DR-003-settings-ledger-invariants.md.
|
|
29
|
+
*/
|
|
30
|
+
async function assertTargetPrincipalInWorkspace(deps, input) {
|
|
31
|
+
if (input.scope !== "user")
|
|
32
|
+
return;
|
|
33
|
+
if (!input.principalId || input.principalId === input.callerPrincipalId)
|
|
34
|
+
return;
|
|
35
|
+
if (!input.workspaceId)
|
|
36
|
+
return;
|
|
37
|
+
const principal = await deps.principals.findActiveById({ workspaceId: input.workspaceId, id: input.principalId });
|
|
38
|
+
if (!principal) {
|
|
39
|
+
throw new PrincipalNotFoundError(`principal '${input.principalId}' was not found in workspace '${input.workspaceId}'`, input.principalId, input.workspaceId);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Authorize -> validate -> value + revision in one transaction. An optional expectedRevisionSeq
|
|
44
|
+
* refuses a stale scoped value and rolls back its revision; omission keeps unconditional writes.
|
|
45
|
+
* @example await set({ deps, input }, { expectedRevisionSeq: snapshotSeq });
|
|
46
|
+
* See docs/decisions/DR-003-settings-ledger-invariants.md.
|
|
47
|
+
*/
|
|
48
|
+
export async function set(required, optional = {}) {
|
|
49
|
+
const { deps, input } = required;
|
|
50
|
+
await authorizeValueWrite({ deps, input, permission: input.requiredPermissionOverride ?? derivePermissionFor({ input }) });
|
|
51
|
+
const definition = await resolveScopedDefinitionOrThrow(deps, input);
|
|
52
|
+
if (!validateValueAgainstSchema({ schema: definition.schema, value: input.value })) {
|
|
53
|
+
throw new ValueValidationFailedError(`value for '${input.namespace}.${input.key}' does not match the definition schema`);
|
|
54
|
+
}
|
|
55
|
+
await assertTargetPrincipalInWorkspace(deps, input);
|
|
56
|
+
const runSet = () => writeValueRevision({
|
|
57
|
+
deps, input, definition, optional, change: { op: "set", afterJson: input.value, valueJson: input.value, state: "set" },
|
|
58
|
+
}).then(({ revisionSeq }) => ({ value: input.value, revisionSeq }));
|
|
59
|
+
// `skipTransaction` means an enclosing caller already owns the boundary, so
|
|
60
|
+
// this write joins it and a later failure rolls this one back too.
|
|
61
|
+
return input.skipTransaction ? runSet() : deps.repo.transaction(runSet);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Authorize -> cleared value + revision in one transaction; the optional concurrency guard has
|
|
65
|
+
* the same semantics as `set`. With skipTransaction, the enclosing caller must propagate errors
|
|
66
|
+
* so its transaction rolls back the appended revision on conflict.
|
|
67
|
+
* @example await clear({ deps, input }, { expectedRevisionSeq: snapshotSeq });
|
|
68
|
+
* See docs/decisions/DR-003-settings-ledger-invariants.md.
|
|
69
|
+
*/
|
|
70
|
+
export async function clear(required, optional = {}) {
|
|
71
|
+
const { deps, input } = required;
|
|
72
|
+
if (!input.skipAuthorize)
|
|
73
|
+
await authorizeValueWrite({ deps, input, permission: derivePermissionFor({ input }) });
|
|
74
|
+
const definition = await resolveScopedDefinitionOrThrow(deps, input);
|
|
75
|
+
await assertTargetPrincipalInWorkspace(deps, input);
|
|
76
|
+
const runClear = () => writeValueRevision({
|
|
77
|
+
deps, input, definition, optional, change: { op: "clear", afterJson: null, valueJson: null, state: "cleared" },
|
|
78
|
+
});
|
|
79
|
+
// `skipTransaction` means an enclosing caller already owns the boundary, so
|
|
80
|
+
// this write joins it and a later failure rolls this one back too.
|
|
81
|
+
return input.skipTransaction ? runClear() : deps.repo.transaction(runClear);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=write-values.js.map
|
|
@@ -76,7 +76,7 @@ export interface SurfaceExchangeBinding {
|
|
|
76
76
|
/**
|
|
77
77
|
* One inbound message, or the reason there will not be one.
|
|
78
78
|
*
|
|
79
|
-
* The non-`received` cases are part of the contract rather than error handling
|
|
79
|
+
* The non-`received` cases are part of the contract rather than error handling:
|
|
80
80
|
* blocking moves the timeout story, it does not remove it, and a handler must be able to tell the
|
|
81
81
|
* model something true about which happened.
|
|
82
82
|
*/
|
|
@@ -144,7 +144,7 @@ export type SurfaceExchangeConversation = Omit<SurfaceExchange, 'expiresAtMs'> &
|
|
|
144
144
|
* (MCP-UI's behavior is unchanged, byte for byte); when omitted, only `principalId` and the
|
|
145
145
|
* exchange's own unguessable `randomUUID()` id gate the delivery. That pair is still sufficient —
|
|
146
146
|
* the id is not enumerable, and `principalId` is a server-verified session identity, never a value
|
|
147
|
-
* the browser chooses (
|
|
147
|
+
* the browser chooses (a host's daemon-access check) — so relaxing the caller's OBLIGATION does not
|
|
148
148
|
* relax the exchange's own binding, which `open()` still records honestly as whatever tool actually
|
|
149
149
|
* opened it.
|
|
150
150
|
*/
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** A dictionary indexed by caller-defined locale and English source key. */
|
|
2
|
+
export type LocaleDictionary = Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
3
|
+
/** Locale-bound translation injected into a widget or panel hook. */
|
|
4
|
+
export type Translate = (key: string) => string;
|
|
5
|
+
export type DictionaryTranslator = ((required: {
|
|
6
|
+
locale: string;
|
|
7
|
+
key: string;
|
|
8
|
+
}) => string) & {
|
|
9
|
+
/** Expose caller-owned copy so translation audits can detect untranslated locales despite fallback. */
|
|
10
|
+
readonly dictionary: LocaleDictionary;
|
|
11
|
+
};
|
|
12
|
+
/** Feature copy wins over the host's common copy, then falls back to the source key.
|
|
13
|
+
* No locale context or product dictionary is installed by this helper. */
|
|
14
|
+
export declare function createDictionaryTranslator({ featureDictionary }: {
|
|
15
|
+
featureDictionary: LocaleDictionary;
|
|
16
|
+
}, { commonDictionary }?: {
|
|
17
|
+
commonDictionary?: LocaleDictionary | undefined;
|
|
18
|
+
}): DictionaryTranslator;
|
|
19
|
+
//# sourceMappingURL=dictionary-translator.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function lookup(dictionary, locale, key) {
|
|
2
|
+
if (!Object.hasOwn(dictionary, locale))
|
|
3
|
+
return undefined;
|
|
4
|
+
const block = dictionary[locale];
|
|
5
|
+
return block && Object.hasOwn(block, key) ? block[key] : undefined;
|
|
6
|
+
}
|
|
7
|
+
// Centralize fallback once: small feature dictionaries inherit shared Save/Cancel/Delete copy,
|
|
8
|
+
// and misses remain readable English source keys rather than raw dictionary-miss placeholders.
|
|
9
|
+
/** Feature copy wins over the host's common copy, then falls back to the source key.
|
|
10
|
+
* No locale context or product dictionary is installed by this helper. */
|
|
11
|
+
export function createDictionaryTranslator({ featureDictionary }, { commonDictionary = {} } = {}) {
|
|
12
|
+
return Object.assign(({ locale, key }) => lookup(featureDictionary, locale, key) ?? lookup(commonDictionary, locale, key) ?? key, { dictionary: featureDictionary });
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=dictionary-translator.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file A byte count as a short display label. 1024-based so the label agrees with upload limits.
|
|
3
|
+
* Whole B/KB, one decimal from MB up, so two similarly sized files do not collapse to the same
|
|
4
|
+
* whole-number size. Pure: the locale only controls the decimal separator, never a hardcoded dot.
|
|
5
|
+
*/
|
|
6
|
+
/** Optional presentation: the locale of the decimal separator, and the megabyte unit label. */
|
|
7
|
+
export interface FormatByteSizeOptions {
|
|
8
|
+
/** BCP 47 locale for the decimal separator. Defaults to `en-US`. */
|
|
9
|
+
locale?: string | undefined;
|
|
10
|
+
/** Unit label for the megabyte band (a host that prefers `MiB` passes it). Defaults to `MB`. */
|
|
11
|
+
megabyteLabel?: string | undefined;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 1024-based to agree with upload limits. Whole B/KB, one decimal MB/GB distinguishes
|
|
15
|
+
* similarly sized clips; locale controls the decimal separator, never a hardcoded dot.
|
|
16
|
+
* @param required.bytes - Size in bytes; fractions round to the nearest whole B/KB.
|
|
17
|
+
* @param optional.locale - Locale for the decimal separator.
|
|
18
|
+
* @param optional.megabyteLabel - Unit label for the megabyte band.
|
|
19
|
+
* @returns `823 B`, `820 KB`, `9.5 MB` or `1.2 GB`.
|
|
20
|
+
* @complexity O(1).
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatByteSize({ bytes }: {
|
|
23
|
+
bytes: number;
|
|
24
|
+
}, { locale, megabyteLabel }?: FormatByteSizeOptions): string;
|
|
25
|
+
//# sourceMappingURL=format-byte-size.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file A byte count as a short display label. 1024-based so the label agrees with upload limits.
|
|
3
|
+
* Whole B/KB, one decimal from MB up, so two similarly sized files do not collapse to the same
|
|
4
|
+
* whole-number size. Pure: the locale only controls the decimal separator, never a hardcoded dot.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* 1024-based to agree with upload limits. Whole B/KB, one decimal MB/GB distinguishes
|
|
8
|
+
* similarly sized clips; locale controls the decimal separator, never a hardcoded dot.
|
|
9
|
+
* @param required.bytes - Size in bytes; fractions round to the nearest whole B/KB.
|
|
10
|
+
* @param optional.locale - Locale for the decimal separator.
|
|
11
|
+
* @param optional.megabyteLabel - Unit label for the megabyte band.
|
|
12
|
+
* @returns `823 B`, `820 KB`, `9.5 MB` or `1.2 GB`.
|
|
13
|
+
* @complexity O(1).
|
|
14
|
+
*/
|
|
15
|
+
export function formatByteSize({ bytes }, { locale = 'en-US', megabyteLabel = 'MB' } = {}) {
|
|
16
|
+
if (bytes < 1024)
|
|
17
|
+
return `${Math.round(bytes)} B`;
|
|
18
|
+
const kb = bytes / 1024;
|
|
19
|
+
if (kb < 1024)
|
|
20
|
+
return `${Math.round(kb)} KB`;
|
|
21
|
+
const decimal = new Intl.NumberFormat(locale, { minimumFractionDigits: 1, maximumFractionDigits: 1 });
|
|
22
|
+
const mb = kb / 1024;
|
|
23
|
+
return mb < 1024 ? `${decimal.format(mb)} ${megabyteLabel}` : `${decimal.format(mb / 1024)} GB`;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=format-byte-size.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralize the fixed-width display so formatting changes have one owner. The default
|
|
3
|
+
* preserves the stored timestamp's prefix byte for byte, without parsing or timezone conversion.
|
|
4
|
+
* Trailing seconds, milliseconds and zone suffix are intentionally dropped; callers supply ISO text.
|
|
5
|
+
*/
|
|
6
|
+
/** Render YYYY-MM-DD HH:MM; hosts select viewer-local display by passing the viewer's IANA zone.
|
|
7
|
+
* Core stays pure: the host resolves that zone at its own boundary, so equal arguments always render equally.
|
|
8
|
+
* @throws RangeError when `viewerTimeZone` is not a known IANA zone. */
|
|
9
|
+
export declare function formatTimestamp({ iso }: {
|
|
10
|
+
iso: string;
|
|
11
|
+
}, { viewerTimeZone }?: {
|
|
12
|
+
viewerTimeZone?: string | undefined;
|
|
13
|
+
}): string;
|
|
14
|
+
/** Inject 'now' to keep relative-time display deterministic. The fallback wording uses simple
|
|
15
|
+
* English singular/plural templates; hosts can translate them, but this is not full locale pluralization. */
|
|
16
|
+
export declare function formatRelativeMinutesAgo({ iso, nowMs }: {
|
|
17
|
+
iso: string;
|
|
18
|
+
nowMs: number;
|
|
19
|
+
}, { translate }?: {
|
|
20
|
+
translate?: ((key: string) => string) | undefined;
|
|
21
|
+
}): string;
|
|
22
|
+
//# sourceMappingURL=format-timestamp.d.ts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralize the fixed-width display so formatting changes have one owner. The default
|
|
3
|
+
* preserves the stored timestamp's prefix byte for byte, without parsing or timezone conversion.
|
|
4
|
+
* Trailing seconds, milliseconds and zone suffix are intentionally dropped; callers supply ISO text.
|
|
5
|
+
*/
|
|
6
|
+
/** Render YYYY-MM-DD HH:MM; hosts select viewer-local display by passing the viewer's IANA zone.
|
|
7
|
+
* Core stays pure: the host resolves that zone at its own boundary, so equal arguments always render equally.
|
|
8
|
+
* @throws RangeError when `viewerTimeZone` is not a known IANA zone. */
|
|
9
|
+
export function formatTimestamp({ iso }, { viewerTimeZone } = {}) {
|
|
10
|
+
return viewerTimeZone === undefined ? storedPrefix(iso) : formatInZone({ iso, timeZone: viewerTimeZone });
|
|
11
|
+
}
|
|
12
|
+
const ISO_DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
|
|
13
|
+
const ISO_DATE_TIME_PREFIX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?/;
|
|
14
|
+
const ISO_ZONE_SUFFIX = /^(?:Z|[+-]\d{2}:?\d{2})$/i;
|
|
15
|
+
/** "wall" = zone-less ISO date-time (already a wall-clock time); "instant" = ISO date-only (UTC by the
|
|
16
|
+
* ECMAScript spec) or date-time with an explicit Z/offset; "text" = anything Date would parse host-locally. */
|
|
17
|
+
function isoKind(iso) {
|
|
18
|
+
if (ISO_DATE_ONLY.test(iso))
|
|
19
|
+
return "instant";
|
|
20
|
+
const dateTime = ISO_DATE_TIME_PREFIX.exec(iso)?.[0];
|
|
21
|
+
if (dateTime === undefined)
|
|
22
|
+
return "text";
|
|
23
|
+
const zone = iso.slice(dateTime.length);
|
|
24
|
+
if (zone === "")
|
|
25
|
+
return "wall";
|
|
26
|
+
return ISO_ZONE_SUFFIX.test(zone) ? "instant" : "text";
|
|
27
|
+
}
|
|
28
|
+
function storedPrefix(iso) {
|
|
29
|
+
return iso.slice(0, 16).replace("T", " ");
|
|
30
|
+
}
|
|
31
|
+
/** A stored UTC prefix can label server time as viewer time, so absolute instants
|
|
32
|
+
* are converted with Intl into the given zone, which also follows that zone's DST. Zone-less ISO is
|
|
33
|
+
* already local wall time; other text would be parsed in the host's ambient zone, so it stays as given. */
|
|
34
|
+
function formatInZone({ iso, timeZone }, _options = {}) {
|
|
35
|
+
const kind = isoKind(iso);
|
|
36
|
+
if (kind === "wall")
|
|
37
|
+
return storedPrefix(iso);
|
|
38
|
+
const date = new Date(iso);
|
|
39
|
+
if (kind === "text" || Number.isNaN(date.getTime()))
|
|
40
|
+
return iso; // Keep malformed source data visible.
|
|
41
|
+
const parts = new Intl.DateTimeFormat("en-US", {
|
|
42
|
+
timeZone, year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", hourCycle: "h23",
|
|
43
|
+
}).formatToParts(date);
|
|
44
|
+
const part = (type) => parts.find(entry => entry.type === type)?.value ?? "";
|
|
45
|
+
return `${part("year")}-${part("month")}-${part("day")} ${part("hour")}:${part("minute")}`;
|
|
46
|
+
}
|
|
47
|
+
/** Inject 'now' to keep relative-time display deterministic. The fallback wording uses simple
|
|
48
|
+
* English singular/plural templates; hosts can translate them, but this is not full locale pluralization. */
|
|
49
|
+
export function formatRelativeMinutesAgo({ iso, nowMs }, { translate = (key) => key } = {}) {
|
|
50
|
+
const minutes = Math.max(0, Math.round((nowMs - new Date(iso).getTime()) / 60000));
|
|
51
|
+
if (minutes < 1)
|
|
52
|
+
return translate("less than a minute ago");
|
|
53
|
+
if (minutes === 1)
|
|
54
|
+
return translate("1 minute ago");
|
|
55
|
+
return translate("{minutes} minutes ago").replace(/\{minutes\}/g, String(minutes));
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=format-timestamp.js.map
|
package/dist/text/index.d.ts
CHANGED
|
@@ -5,4 +5,16 @@ export { trimChars, trimCharsEnd, trimCharsStart } from "../primitives/trim-char
|
|
|
5
5
|
export { captureLineTail } from "./line-tail.js";
|
|
6
6
|
export { parseDescriptorI18n } from "./descriptor-i18n.js";
|
|
7
7
|
export type { DescriptorI18n } from "./descriptor-i18n.js";
|
|
8
|
+
export { createTaggedTextSuppressor, emitWithTextSuppressor, possibleTagStart, MAX_CANDIDATE_LENGTH } from './tagged-text-suppression.js';
|
|
9
|
+
export type { TaggedTextMatchers, TaggedTextSuppressor, ArtifactTextSuppressor, ArtifactTextSuppressorStats, StreamTextEvent, StreamEventSink } from './tagged-text-suppression.js';
|
|
10
|
+
export { createDictionaryTranslator } from './dictionary-translator.js';
|
|
11
|
+
export type { Translate, DictionaryTranslator, LocaleDictionary } from './dictionary-translator.js';
|
|
12
|
+
export { interpolate, splitOnPlaceholders, pickPlural, localeEntry } from './template-i18n.js';
|
|
13
|
+
export { formatTimestamp, formatRelativeMinutesAgo } from './format-timestamp.js';
|
|
14
|
+
export { resolveActiveTabId } from './resolve-active-tab-id.js';
|
|
15
|
+
export { redactOAuthUrls } from './redact-urls.js';
|
|
16
|
+
export { isAbortError } from './is-abort-error.js';
|
|
17
|
+
export { extensionForMimeType } from './mime.js';
|
|
18
|
+
export { formatByteSize } from './format-byte-size.js';
|
|
19
|
+
export type { FormatByteSizeOptions } from './format-byte-size.js';
|
|
8
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/text/index.js
CHANGED
|
@@ -3,4 +3,13 @@ export { escapeHtml, escapeXml } from "./escape.js";
|
|
|
3
3
|
export { trimChars, trimCharsEnd, trimCharsStart } from "../primitives/trim-chars.js";
|
|
4
4
|
export { captureLineTail } from "./line-tail.js";
|
|
5
5
|
export { parseDescriptorI18n } from "./descriptor-i18n.js";
|
|
6
|
+
export { createTaggedTextSuppressor, emitWithTextSuppressor, possibleTagStart, MAX_CANDIDATE_LENGTH } from './tagged-text-suppression.js';
|
|
7
|
+
export { createDictionaryTranslator } from './dictionary-translator.js';
|
|
8
|
+
export { interpolate, splitOnPlaceholders, pickPlural, localeEntry } from './template-i18n.js';
|
|
9
|
+
export { formatTimestamp, formatRelativeMinutesAgo } from './format-timestamp.js';
|
|
10
|
+
export { resolveActiveTabId } from './resolve-active-tab-id.js';
|
|
11
|
+
export { redactOAuthUrls } from './redact-urls.js';
|
|
12
|
+
export { isAbortError } from './is-abort-error.js';
|
|
13
|
+
export { extensionForMimeType } from './mime.js';
|
|
14
|
+
export { formatByteSize } from './format-byte-size.js';
|
|
6
15
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Duck-type the name: DOMException's instanceof Error result depends on its browser realm. */
|
|
2
|
+
export function isAbortError({ error }, _options = {}) {
|
|
3
|
+
return typeof error === "object" && error !== null && error.name === "AbortError";
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=is-abort-error.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** @file Maps a MIME type to the file extension used when a pasted file arrives without a name. */
|
|
2
|
+
export function extensionForMimeType({ mimeType }, _optional = {}) {
|
|
3
|
+
if (mimeType === 'image/png')
|
|
4
|
+
return '.png';
|
|
5
|
+
if (mimeType === 'image/jpeg')
|
|
6
|
+
return '.jpg';
|
|
7
|
+
if (mimeType === 'image/gif')
|
|
8
|
+
return '.gif';
|
|
9
|
+
if (mimeType === 'image/webp')
|
|
10
|
+
return '.webp';
|
|
11
|
+
if (mimeType === 'image/avif')
|
|
12
|
+
return '.avif';
|
|
13
|
+
if (mimeType === 'image/svg+xml')
|
|
14
|
+
return '.svg';
|
|
15
|
+
if (mimeType === 'text/html')
|
|
16
|
+
return '.html';
|
|
17
|
+
if (mimeType === 'text/plain')
|
|
18
|
+
return '.txt';
|
|
19
|
+
return '';
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=mime.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Redaction policy is provider-owned; the operation keeps every other byte intact. */
|
|
2
|
+
export declare function redactOAuthUrls({ text, pattern, replacement }: {
|
|
3
|
+
text: string;
|
|
4
|
+
pattern: RegExp;
|
|
5
|
+
replacement: string;
|
|
6
|
+
}): string;
|
|
7
|
+
//# sourceMappingURL=redact-urls.d.ts.map
|