@segmentstream/ontology 0.168.1 → 0.170.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.170.0
4
+
5
+ An `hmac` webhook signature can sign the body as `{ body: "sorted-json" }`: the body parsed as a
6
+ JSON object and written again compactly with the keys of every object sorted, as `JSON.stringify`
7
+ writes it, for providers that sign such a re-serialization rather than the bytes they sent, such
8
+ as NOWPayments' IPN (`x-nowpayments-sig`, hex HMAC-SHA512). A delivery whose body is not a JSON
9
+ object fails the check. `{ body: true }` still signs the raw bytes. Adding a signature to a token
10
+ webhook changes its URL, since a signed webhook has no token: declare the signed one beside the
11
+ old one while objects created before still carry the old URL.
12
+
13
+ ## 0.169.0
14
+
15
+ An entity can declare `eraseFromWarehouseOnDelete: true`: deleting one of its records then erases
16
+ the record's replicated history from the workspace warehouse, in every copy the platform keeps,
17
+ leaving only the content-free fact of its deletion. Every deletion counts, whether by an action, a
18
+ cascade or a retention purge, and so do the deletions recorded before the setting was turned on.
19
+ Erasure runs daily; the record is gone from everything the workspace can query within about two
20
+ days. It is off by default. The built-in `agent_draft` turns it on, so drafts the chat retention
21
+ deletes no longer remain readable in the warehouse.
22
+
3
23
  ## 0.168.1
4
24
 
5
25
  The replication schema adds a content-free erasure journal, `_ontology_replication_erasures`.
@@ -162,6 +162,8 @@ export const AgentDraft = entity("agent_draft", {
162
162
  id: "ent_agent_review",
163
163
  // @legacy ontology.agent-review-entity-name
164
164
  renamedFrom: "agent_review",
165
+ // A draft the chat retention deletes takes its text, notes and reasons out of the warehouse too.
166
+ eraseFromWarehouseOnDelete: true,
165
167
  label: "Agent draft",
166
168
  plural: "Agent drafts",
167
169
  title: "draft",
package/dist/analyze.js CHANGED
@@ -2298,6 +2298,7 @@ function resolveEntity(candidate, scope, resolvedProperties) {
2298
2298
  report("invalid-guide", `${name}.guide`, "must be a relative path to a Markdown file, such as ./lead.md.");
2299
2299
  }
2300
2300
  checkWrites(name, definition, report);
2301
+ checkErasure(name, definition, report);
2301
2302
  const properties = resolvedProperties ?? resolveProperties(candidate, scope);
2302
2303
  const relationships = resolveRelationships(candidate, scope);
2303
2304
  if (isBlank(definition.title)) {
@@ -2337,6 +2338,18 @@ function writesOf(candidate) {
2337
2338
  ? "actions"
2338
2339
  : "generated";
2339
2340
  }
2341
+ function checkErasure(name, definition, report) {
2342
+ const erase = definition.eraseFromWarehouseOnDelete;
2343
+ if (erase === undefined) {
2344
+ return;
2345
+ }
2346
+ if (typeof erase !== "boolean") {
2347
+ report("invalid-erasure", `${name}.eraseFromWarehouseOnDelete`, "eraseFromWarehouseOnDelete is true or false.");
2348
+ }
2349
+ else if (erase && definition.source !== undefined) {
2350
+ report("invalid-erasure", `${name}.eraseFromWarehouseOnDelete`, "a warehouse-backed entity's records are the warehouse's own; remove eraseFromWarehouseOnDelete.");
2351
+ }
2352
+ }
2340
2353
  function checkWrites(name, definition, report) {
2341
2354
  const writes = definition.writes;
2342
2355
  if (writes === undefined) {
@@ -1,10 +1,10 @@
1
1
  import { Schema } from "effect";
2
- export declare const DIAGNOSTIC_CODES: readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-chat", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "feedback-unreportable", "agent-tools-implicit", "named-secret-deprecated", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"];
2
+ export declare const DIAGNOSTIC_CODES: readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "invalid-erasure", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-chat", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "feedback-unreportable", "agent-tools-implicit", "named-secret-deprecated", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"];
3
3
  export type DiagnosticCode = (typeof DIAGNOSTIC_CODES)[number];
4
4
  /** A problem `check` found in an ontology definition. */
5
5
  export declare const Diagnostic: Schema.Struct<{
6
6
  readonly severity: Schema.Literals<readonly ["error", "warning", "info"]>;
7
- readonly code: Schema.Literals<readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-chat", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "feedback-unreportable", "agent-tools-implicit", "named-secret-deprecated", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"]>;
7
+ readonly code: Schema.Literals<readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "invalid-erasure", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-chat", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "feedback-unreportable", "agent-tools-implicit", "named-secret-deprecated", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"]>;
8
8
  /** Where the problem is, for example `lead.properties.status.options[1]`. */
9
9
  readonly path: Schema.String;
10
10
  readonly message: Schema.String;
@@ -14,7 +14,7 @@ declare const InvalidOntology_base: Schema.Class<InvalidOntology, Schema.TaggedS
14
14
  readonly message: Schema.String;
15
15
  readonly diagnostics: Schema.$Array<Schema.Struct<{
16
16
  readonly severity: Schema.Literals<readonly ["error", "warning", "info"]>;
17
- readonly code: Schema.Literals<readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-chat", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "feedback-unreportable", "agent-tools-implicit", "named-secret-deprecated", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"]>;
17
+ readonly code: Schema.Literals<readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "invalid-erasure", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-chat", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "feedback-unreportable", "agent-tools-implicit", "named-secret-deprecated", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"]>;
18
18
  /** Where the problem is, for example `lead.properties.status.options[1]`. */
19
19
  readonly path: Schema.String;
20
20
  readonly message: Schema.String;
@@ -43,6 +43,7 @@ export const DIAGNOSTIC_CODES = [
43
43
  "earlier-name",
44
44
  "invalid-guide",
45
45
  "invalid-writes",
46
+ "invalid-erasure",
46
47
  "generated-update-empty",
47
48
  "managed-without-effect",
48
49
  "missing-permissions",
package/dist/entity.d.ts CHANGED
@@ -179,6 +179,15 @@ export interface EntityDefinition<P extends Properties, R extends Relationships,
179
179
  * Reads stay the same. Stored entities only.
180
180
  */
181
181
  readonly writes?: EntityWrites;
182
+ /**
183
+ * Whether deleting a record also erases its replicated history from the workspace warehouse:
184
+ * every earlier value the warehouse holds for it, in each copy the platform keeps. The record's
185
+ * deletion itself stays, with no content. Erasure runs daily; see the replication docs for its
186
+ * timing. Every deletion counts, by an action, a cascade or a retention purge, as do the
187
+ * deletions recorded before it was turned on. Off by default: the warehouse keeps a deleted
188
+ * record's history for queries over the past. Stored entities only.
189
+ */
190
+ readonly eraseFromWarehouseOnDelete?: boolean;
182
191
  }
183
192
  /** Who writes an entity's records; see {@link EntityDefinition.writes}. */
184
193
  export type EntityWrites = "generated" | "actions";
@@ -110,6 +110,9 @@ import { type ResolvedGuest, type ResolvedSignInOptions, type SignInPolicy } fro
110
110
  * `private` without members. Older readers ignore it and register no chat without members.
111
111
  * Within version 16, a mailbox in `chat` may carry `signature: true`, written only when declared:
112
112
  * the ontology's replies to mail end with the mailbox's own signature. Older readers ignore it.
113
+ * Within version 16, an entity may carry `erase_from_warehouse_on_delete: true`, written only when
114
+ * declared: deleting a record erases its replicated history from the warehouse. The SDK's own
115
+ * replication capture acts on it; readers ignore it.
113
116
  */
114
117
  export declare const MANIFEST_VERSION = 16;
115
118
  /** The phrase used for a direction the author did not phrase. */
@@ -418,6 +421,11 @@ export declare const EntityManifest: Schema.Struct<{
418
421
  * writes and its `permissions` hold only `read`. Absent means the generated writes exist.
419
422
  */
420
423
  readonly writes: Schema.optionalKey<Schema.Literal<"actions">>;
424
+ /**
425
+ * `true` when deleting a record erases its replicated history from the warehouse; written only
426
+ * then. The SDK's replication capture acts on it; the platform does not read it.
427
+ */
428
+ readonly eraseFromWarehouseOnDelete: Schema.optionalKey<Schema.Literal<true>>;
421
429
  }>;
422
430
  export type EntityManifest = typeof EntityManifest.Type;
423
431
  /**
@@ -523,7 +531,7 @@ export declare const WebhookTriggerManifest: Schema.Struct<{
523
531
  readonly tolerance: Schema.optionalKey<Schema.Number>;
524
532
  }>>;
525
533
  readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
526
- readonly body: Schema.Literal<true>;
534
+ readonly body: Schema.Literals<readonly [true, "sorted-json"]>;
527
535
  }>, Schema.Struct<{
528
536
  readonly header: Schema.String;
529
537
  }>, Schema.Struct<{
@@ -599,7 +607,7 @@ export declare const WorkflowTriggerManifest: Schema.Union<readonly [Schema.Stru
599
607
  readonly tolerance: Schema.optionalKey<Schema.Number>;
600
608
  }>>;
601
609
  readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
602
- readonly body: Schema.Literal<true>;
610
+ readonly body: Schema.Literals<readonly [true, "sorted-json"]>;
603
611
  }>, Schema.Struct<{
604
612
  readonly header: Schema.String;
605
613
  }>, Schema.Struct<{
@@ -682,7 +690,7 @@ export declare const WorkflowManifest: Schema.Struct<{
682
690
  readonly tolerance: Schema.optionalKey<Schema.Number>;
683
691
  }>>;
684
692
  readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
685
- readonly body: Schema.Literal<true>;
693
+ readonly body: Schema.Literals<readonly [true, "sorted-json"]>;
686
694
  }>, Schema.Struct<{
687
695
  readonly header: Schema.String;
688
696
  }>, Schema.Struct<{
@@ -1151,9 +1159,15 @@ export declare const OntologyManifestWire: Schema.encodeKeys<Schema.Struct<{
1151
1159
  * writes and its `permissions` hold only `read`. Absent means the generated writes exist.
1152
1160
  */
1153
1161
  readonly writes: Schema.optionalKey<Schema.Literal<"actions">>;
1162
+ /**
1163
+ * `true` when deleting a record erases its replicated history from the warehouse; written only
1164
+ * then. The SDK's replication capture acts on it; the platform does not read it.
1165
+ */
1166
+ readonly eraseFromWarehouseOnDelete: Schema.optionalKey<Schema.Literal<true>>;
1154
1167
  }>, {
1155
1168
  readonly builtIn: "built_in";
1156
1169
  readonly renamedFrom: "renamed_from";
1170
+ readonly eraseFromWarehouseOnDelete: "erase_from_warehouse_on_delete";
1157
1171
  }>>;
1158
1172
  readonly roles: Schema.$Array<Schema.encodeKeys<Schema.Struct<{
1159
1173
  readonly name: Schema.String;
@@ -1445,7 +1459,7 @@ export declare const OntologyManifestWire: Schema.encodeKeys<Schema.Struct<{
1445
1459
  readonly tolerance: Schema.optionalKey<Schema.Number>;
1446
1460
  }>>;
1447
1461
  readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
1448
- readonly body: Schema.Literal<true>;
1462
+ readonly body: Schema.Literals<readonly [true, "sorted-json"]>;
1449
1463
  }>, Schema.Struct<{
1450
1464
  readonly header: Schema.String;
1451
1465
  }>, Schema.Struct<{
@@ -1650,6 +1664,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
1650
1664
  readonly balanceOver?: string | undefined;
1651
1665
  }[] | undefined;
1652
1666
  readonly guide?: string | undefined;
1667
+ readonly eraseFromWarehouseOnDelete?: true | undefined;
1653
1668
  }[];
1654
1669
  readonly chat?: {
1655
1670
  readonly telegram?: {
@@ -1724,7 +1739,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
1724
1739
  readonly signature?: {
1725
1740
  readonly scheme: string;
1726
1741
  readonly message?: readonly (string | {
1727
- readonly body: true;
1742
+ readonly body: true | "sorted-json";
1728
1743
  } | {
1729
1744
  readonly header: string;
1730
1745
  } | {
@@ -2027,6 +2042,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2027
2042
  readonly balanceOver?: string | undefined;
2028
2043
  }[] | undefined;
2029
2044
  readonly guide?: string | undefined;
2045
+ readonly eraseFromWarehouseOnDelete?: true | undefined;
2030
2046
  }[];
2031
2047
  readonly chat?: {
2032
2048
  readonly telegram?: {
@@ -2101,7 +2117,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2101
2117
  readonly signature?: {
2102
2118
  readonly scheme: string;
2103
2119
  readonly message?: readonly (string | {
2104
- readonly body: true;
2120
+ readonly body: true | "sorted-json";
2105
2121
  } | {
2106
2122
  readonly header: string;
2107
2123
  } | {
@@ -2404,6 +2420,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2404
2420
  }[] | undefined;
2405
2421
  readonly guide?: string | undefined;
2406
2422
  readonly renamed_from?: string | undefined;
2423
+ readonly erase_from_warehouse_on_delete?: true | undefined;
2407
2424
  }[];
2408
2425
  readonly chat?: {
2409
2426
  readonly telegram?: {
@@ -2480,7 +2497,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2480
2497
  readonly signature?: {
2481
2498
  readonly scheme: string;
2482
2499
  readonly message?: readonly (string | {
2483
- readonly body: true;
2500
+ readonly body: true | "sorted-json";
2484
2501
  } | {
2485
2502
  readonly header: string;
2486
2503
  } | {
@@ -2781,6 +2798,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2781
2798
  readonly balanceOver?: string | undefined;
2782
2799
  }[] | undefined;
2783
2800
  readonly guide?: string | undefined;
2801
+ readonly eraseFromWarehouseOnDelete?: true | undefined;
2784
2802
  }[];
2785
2803
  readonly chat?: {
2786
2804
  readonly telegram?: {
@@ -2857,7 +2875,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2857
2875
  readonly signature?: {
2858
2876
  readonly scheme: string;
2859
2877
  readonly message?: readonly (string | {
2860
- readonly body: true;
2878
+ readonly body: true | "sorted-json";
2861
2879
  } | {
2862
2880
  readonly header: string;
2863
2881
  } | {
@@ -3185,9 +3203,15 @@ export declare const OntologyManifest: Schema.declareConstructor<{
3185
3203
  * writes and its `permissions` hold only `read`. Absent means the generated writes exist.
3186
3204
  */
3187
3205
  readonly writes: Schema.optionalKey<Schema.Literal<"actions">>;
3206
+ /**
3207
+ * `true` when deleting a record erases its replicated history from the warehouse; written only
3208
+ * then. The SDK's replication capture acts on it; the platform does not read it.
3209
+ */
3210
+ readonly eraseFromWarehouseOnDelete: Schema.optionalKey<Schema.Literal<true>>;
3188
3211
  }>, {
3189
3212
  readonly builtIn: "built_in";
3190
3213
  readonly renamedFrom: "renamed_from";
3214
+ readonly eraseFromWarehouseOnDelete: "erase_from_warehouse_on_delete";
3191
3215
  }>>;
3192
3216
  readonly roles: Schema.$Array<Schema.encodeKeys<Schema.Struct<{
3193
3217
  readonly name: Schema.String;
@@ -3479,7 +3503,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
3479
3503
  readonly tolerance: Schema.optionalKey<Schema.Number>;
3480
3504
  }>>;
3481
3505
  readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
3482
- readonly body: Schema.Literal<true>;
3506
+ readonly body: Schema.Literals<readonly [true, "sorted-json"]>;
3483
3507
  }>, Schema.Struct<{
3484
3508
  readonly header: Schema.String;
3485
3509
  }>, Schema.Struct<{
@@ -3718,6 +3742,11 @@ export declare const OntologyManifest: Schema.declareConstructor<{
3718
3742
  * writes and its `permissions` hold only `read`. Absent means the generated writes exist.
3719
3743
  */
3720
3744
  readonly writes: Schema.optionalKey<Schema.Literal<"actions">>;
3745
+ /**
3746
+ * `true` when deleting a record erases its replicated history from the warehouse; written only
3747
+ * then. The SDK's replication capture acts on it; the platform does not read it.
3748
+ */
3749
+ readonly eraseFromWarehouseOnDelete: Schema.optionalKey<Schema.Literal<true>>;
3721
3750
  }>>;
3722
3751
  readonly roles: Schema.$Array<Schema.Struct<{
3723
3752
  readonly name: Schema.String;
@@ -3991,7 +4020,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
3991
4020
  readonly tolerance: Schema.optionalKey<Schema.Number>;
3992
4021
  }>>;
3993
4022
  readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
3994
- readonly body: Schema.Literal<true>;
4023
+ readonly body: Schema.Literals<readonly [true, "sorted-json"]>;
3995
4024
  }>, Schema.Struct<{
3996
4025
  readonly header: Schema.String;
3997
4026
  }>, Schema.Struct<{
@@ -4188,6 +4217,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
4188
4217
  readonly balanceOver?: string | undefined;
4189
4218
  }[] | undefined;
4190
4219
  readonly guide?: string | undefined;
4220
+ readonly eraseFromWarehouseOnDelete?: true | undefined;
4191
4221
  }[];
4192
4222
  readonly chat?: {
4193
4223
  readonly telegram?: {
@@ -4262,7 +4292,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
4262
4292
  readonly signature?: {
4263
4293
  readonly scheme: string;
4264
4294
  readonly message?: readonly (string | {
4265
- readonly body: true;
4295
+ readonly body: true | "sorted-json";
4266
4296
  } | {
4267
4297
  readonly header: string;
4268
4298
  } | {
@@ -4565,6 +4595,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
4565
4595
  readonly balanceOver?: string | undefined;
4566
4596
  }[] | undefined;
4567
4597
  readonly guide?: string | undefined;
4598
+ readonly eraseFromWarehouseOnDelete?: true | undefined;
4568
4599
  }[];
4569
4600
  readonly chat?: {
4570
4601
  readonly telegram?: {
@@ -4639,7 +4670,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
4639
4670
  readonly signature?: {
4640
4671
  readonly scheme: string;
4641
4672
  readonly message?: readonly (string | {
4642
- readonly body: true;
4673
+ readonly body: true | "sorted-json";
4643
4674
  } | {
4644
4675
  readonly header: string;
4645
4676
  } | {
@@ -4948,6 +4979,7 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
4948
4979
  readonly balanceOver?: string | undefined;
4949
4980
  }[] | undefined;
4950
4981
  readonly guide?: string | undefined;
4982
+ readonly eraseFromWarehouseOnDelete?: true | undefined;
4951
4983
  }[];
4952
4984
  readonly chat?: {
4953
4985
  readonly telegram?: {
@@ -5022,7 +5054,7 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
5022
5054
  readonly signature?: {
5023
5055
  readonly scheme: string;
5024
5056
  readonly message?: readonly (string | {
5025
- readonly body: true;
5057
+ readonly body: true | "sorted-json";
5026
5058
  } | {
5027
5059
  readonly header: string;
5028
5060
  } | {
@@ -5325,6 +5357,7 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
5325
5357
  readonly balanceOver?: string | undefined;
5326
5358
  }[] | undefined;
5327
5359
  readonly guide?: string | undefined;
5360
+ readonly eraseFromWarehouseOnDelete?: true | undefined;
5328
5361
  }[];
5329
5362
  readonly chat?: {
5330
5363
  readonly telegram?: {
@@ -5399,7 +5432,7 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
5399
5432
  readonly signature?: {
5400
5433
  readonly scheme: string;
5401
5434
  readonly message?: readonly (string | {
5402
- readonly body: true;
5435
+ readonly body: true | "sorted-json";
5403
5436
  } | {
5404
5437
  readonly header: string;
5405
5438
  } | {
package/dist/manifest.js CHANGED
@@ -111,6 +111,9 @@ import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isGuestBotCheckScheme, isGue
111
111
  * `private` without members. Older readers ignore it and register no chat without members.
112
112
  * Within version 16, a mailbox in `chat` may carry `signature: true`, written only when declared:
113
113
  * the ontology's replies to mail end with the mailbox's own signature. Older readers ignore it.
114
+ * Within version 16, an entity may carry `erase_from_warehouse_on_delete: true`, written only when
115
+ * declared: deleting a record erases its replicated history from the warehouse. The SDK's own
116
+ * replication capture acts on it; readers ignore it.
114
117
  */
115
118
  export const MANIFEST_VERSION = 16;
116
119
  /** The first version whose documents use snake_case names on the wire. */
@@ -296,6 +299,11 @@ export const EntityManifest = Schema.Struct({
296
299
  * writes and its `permissions` hold only `read`. Absent means the generated writes exist.
297
300
  */
298
301
  writes: Schema.optionalKey(Schema.Literal("actions")),
302
+ /**
303
+ * `true` when deleting a record erases its replicated history from the warehouse; written only
304
+ * then. The SDK's replication capture acts on it; the platform does not read it.
305
+ */
306
+ eraseFromWarehouseOnDelete: Schema.optionalKey(Schema.Literal(true)),
299
307
  });
300
308
  /**
301
309
  * A scoped permission of a role: `<entity>:<verb>` and the `where` of the records it covers, in the
@@ -387,7 +395,7 @@ export const WebhookTriggerManifest = Schema.Struct({
387
395
  })),
388
396
  message: Schema.optionalKey(Schema.Array(Schema.Union([
389
397
  Schema.String,
390
- Schema.Struct({ body: Schema.Literal(true) }),
398
+ Schema.Struct({ body: Schema.Literals([true, "sorted-json"]) }),
391
399
  Schema.Struct({ header: Schema.String }),
392
400
  Schema.Struct({ timestamp: Schema.Literal(true) }),
393
401
  ]))),
@@ -696,7 +704,11 @@ const EntityManifestWire = Schema.Struct({
696
704
  metrics: Schema.optionalKey(Schema.Array(MetricManifestWire)),
697
705
  properties: Schema.Array(PropertyManifestWire),
698
706
  relationships: Schema.Array(RelationshipManifestWire),
699
- }).pipe(Schema.encodeKeys({ builtIn: "built_in", renamedFrom: "renamed_from" }));
707
+ }).pipe(Schema.encodeKeys({
708
+ builtIn: "built_in",
709
+ renamedFrom: "renamed_from",
710
+ eraseFromWarehouseOnDelete: "erase_from_warehouse_on_delete",
711
+ }));
700
712
  const RoleManifestWire = RoleManifest.pipe(Schema.encodeKeys({ builtIn: "built_in" }));
701
713
  /** The JSON contract written since version 4; decoded SDK models remain camelCase. */
702
714
  export const OntologyManifestWire = Schema.Struct({
@@ -1100,6 +1112,9 @@ function entityManifest(input) {
1100
1112
  })),
1101
1113
  permissions: { ...resolved.permissions },
1102
1114
  ...(resolved.writes === "actions" ? { writes: "actions" } : {}),
1115
+ ...(definition.eraseFromWarehouseOnDelete === true && definition.source === undefined
1116
+ ? { eraseFromWarehouseOnDelete: true }
1117
+ : {}),
1103
1118
  };
1104
1119
  }
1105
1120
  /** Builds the manifest of a resolved ontology that passed `check`. */
@@ -404,6 +404,7 @@ export declare const MigrationPlan: Schema.Struct<{
404
404
  readonly balanceOver?: string | undefined;
405
405
  }[] | undefined;
406
406
  readonly guide?: string | undefined;
407
+ readonly eraseFromWarehouseOnDelete?: true | undefined;
407
408
  }[];
408
409
  readonly chat?: {
409
410
  readonly telegram?: {
@@ -478,7 +479,7 @@ export declare const MigrationPlan: Schema.Struct<{
478
479
  readonly signature?: {
479
480
  readonly scheme: string;
480
481
  readonly message?: readonly (string | {
481
- readonly body: true;
482
+ readonly body: true | "sorted-json";
482
483
  } | {
483
484
  readonly header: string;
484
485
  } | {
@@ -781,6 +782,7 @@ export declare const MigrationPlan: Schema.Struct<{
781
782
  readonly balanceOver?: string | undefined;
782
783
  }[] | undefined;
783
784
  readonly guide?: string | undefined;
785
+ readonly eraseFromWarehouseOnDelete?: true | undefined;
784
786
  }[];
785
787
  readonly chat?: {
786
788
  readonly telegram?: {
@@ -855,7 +857,7 @@ export declare const MigrationPlan: Schema.Struct<{
855
857
  readonly signature?: {
856
858
  readonly scheme: string;
857
859
  readonly message?: readonly (string | {
858
- readonly body: true;
860
+ readonly body: true | "sorted-json";
859
861
  } | {
860
862
  readonly header: string;
861
863
  } | {
@@ -1158,6 +1160,7 @@ export declare const MigrationPlan: Schema.Struct<{
1158
1160
  }[] | undefined;
1159
1161
  readonly guide?: string | undefined;
1160
1162
  readonly renamed_from?: string | undefined;
1163
+ readonly erase_from_warehouse_on_delete?: true | undefined;
1161
1164
  }[];
1162
1165
  readonly chat?: {
1163
1166
  readonly telegram?: {
@@ -1234,7 +1237,7 @@ export declare const MigrationPlan: Schema.Struct<{
1234
1237
  readonly signature?: {
1235
1238
  readonly scheme: string;
1236
1239
  readonly message?: readonly (string | {
1237
- readonly body: true;
1240
+ readonly body: true | "sorted-json";
1238
1241
  } | {
1239
1242
  readonly header: string;
1240
1243
  } | {
@@ -1535,6 +1538,7 @@ export declare const MigrationPlan: Schema.Struct<{
1535
1538
  readonly balanceOver?: string | undefined;
1536
1539
  }[] | undefined;
1537
1540
  readonly guide?: string | undefined;
1541
+ readonly eraseFromWarehouseOnDelete?: true | undefined;
1538
1542
  }[];
1539
1543
  readonly chat?: {
1540
1544
  readonly telegram?: {
@@ -1611,7 +1615,7 @@ export declare const MigrationPlan: Schema.Struct<{
1611
1615
  readonly signature?: {
1612
1616
  readonly scheme: string;
1613
1617
  readonly message?: readonly (string | {
1614
- readonly body: true;
1618
+ readonly body: true | "sorted-json";
1615
1619
  } | {
1616
1620
  readonly header: string;
1617
1621
  } | {
@@ -1907,9 +1911,11 @@ export declare const MigrationPlan: Schema.Struct<{
1907
1911
  readonly unlink: Schema.optionalKey<Schema.String>;
1908
1912
  }>>;
1909
1913
  readonly writes: Schema.optionalKey<Schema.Literal<"actions">>;
1914
+ readonly eraseFromWarehouseOnDelete: Schema.optionalKey<Schema.Literal<true>>;
1910
1915
  }>, {
1911
1916
  readonly builtIn: "built_in";
1912
1917
  readonly renamedFrom: "renamed_from";
1918
+ readonly eraseFromWarehouseOnDelete: "erase_from_warehouse_on_delete";
1913
1919
  }>>;
1914
1920
  readonly roles: Schema.$Array<Schema.encodeKeys<Schema.Struct<{
1915
1921
  readonly name: Schema.String;
@@ -2135,7 +2141,7 @@ export declare const MigrationPlan: Schema.Struct<{
2135
2141
  readonly tolerance: Schema.optionalKey<Schema.Number>;
2136
2142
  }>>;
2137
2143
  readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
2138
- readonly body: Schema.Literal<true>;
2144
+ readonly body: Schema.Literals<readonly [true, "sorted-json"]>;
2139
2145
  }>, Schema.Struct<{
2140
2146
  readonly header: Schema.String;
2141
2147
  }>, Schema.Struct<{
@@ -2300,6 +2306,7 @@ export declare const MigrationPlan: Schema.Struct<{
2300
2306
  readonly unlink: Schema.optionalKey<Schema.String>;
2301
2307
  }>>;
2302
2308
  readonly writes: Schema.optionalKey<Schema.Literal<"actions">>;
2309
+ readonly eraseFromWarehouseOnDelete: Schema.optionalKey<Schema.Literal<true>>;
2303
2310
  }>>;
2304
2311
  readonly roles: Schema.$Array<Schema.Struct<{
2305
2312
  readonly name: Schema.String;
@@ -2510,7 +2517,7 @@ export declare const MigrationPlan: Schema.Struct<{
2510
2517
  readonly tolerance: Schema.optionalKey<Schema.Number>;
2511
2518
  }>>;
2512
2519
  readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
2513
- readonly body: Schema.Literal<true>;
2520
+ readonly body: Schema.Literals<readonly [true, "sorted-json"]>;
2514
2521
  }>, Schema.Struct<{
2515
2522
  readonly header: Schema.String;
2516
2523
  }>, Schema.Struct<{
@@ -2676,6 +2683,7 @@ export declare const MigrationPlan: Schema.Struct<{
2676
2683
  readonly balanceOver?: string | undefined;
2677
2684
  }[] | undefined;
2678
2685
  readonly guide?: string | undefined;
2686
+ readonly eraseFromWarehouseOnDelete?: true | undefined;
2679
2687
  }[];
2680
2688
  readonly chat?: {
2681
2689
  readonly telegram?: {
@@ -2750,7 +2758,7 @@ export declare const MigrationPlan: Schema.Struct<{
2750
2758
  readonly signature?: {
2751
2759
  readonly scheme: string;
2752
2760
  readonly message?: readonly (string | {
2753
- readonly body: true;
2761
+ readonly body: true | "sorted-json";
2754
2762
  } | {
2755
2763
  readonly header: string;
2756
2764
  } | {
@@ -3053,6 +3061,7 @@ export declare const MigrationPlan: Schema.Struct<{
3053
3061
  readonly balanceOver?: string | undefined;
3054
3062
  }[] | undefined;
3055
3063
  readonly guide?: string | undefined;
3064
+ readonly eraseFromWarehouseOnDelete?: true | undefined;
3056
3065
  }[];
3057
3066
  readonly chat?: {
3058
3067
  readonly telegram?: {
@@ -3127,7 +3136,7 @@ export declare const MigrationPlan: Schema.Struct<{
3127
3136
  readonly signature?: {
3128
3137
  readonly scheme: string;
3129
3138
  readonly message?: readonly (string | {
3130
- readonly body: true;
3139
+ readonly body: true | "sorted-json";
3131
3140
  } | {
3132
3141
  readonly header: string;
3133
3142
  } | {
@@ -158,6 +158,15 @@ export function replicationEntityDdl(manifest, previous) {
158
158
  const declared = entity.relationships
159
159
  .filter((r) => r.cardinality === "many")
160
160
  .map((r) => r.name);
161
+ // A deletion of an entity that erases its history is journaled whatever replication's state,
162
+ // in the deleting transaction, so no path of deletion escapes it.
163
+ const erases = entity.eraseFromWarehouseOnDelete === true;
164
+ const journal = erases
165
+ ? `IF NEW.kind = 'delete' THEN
166
+ INSERT INTO _ontology_replication_erasures (entity_id, record_id)
167
+ VALUES (${ql(entity.id)}, NEW.record_id) ON CONFLICT DO NOTHING;
168
+ END IF;`
169
+ : "";
161
170
  return [
162
171
  `ALTER TABLE ${history} ADD COLUMN IF NOT EXISTS replication jsonb`,
163
172
  `CREATE INDEX IF NOT EXISTS ${qi(`_replication_${key}_idx`)} ON ${history}
@@ -167,6 +176,7 @@ export function replicationEntityDdl(manifest, previous) {
167
176
  event_revision bigint; record_key text; record_kind text := 'entity';
168
177
  is_deleted boolean := NEW.kind = 'delete';
169
178
  BEGIN
179
+ ${journal}
170
180
  SELECT * INTO state FROM _ontology_replication WHERE id;
171
181
  policy := state.selection->${ql(entity.id)};
172
182
  IF NOT state.enabled OR policy IS NULL THEN RETURN NEW; END IF;
@@ -209,6 +219,15 @@ export function replicationEntityDdl(manifest, previous) {
209
219
  END IF;
210
220
  RETURN NEW;
211
221
  END $$`,
222
+ // Deletions recorded before the entity erased its history, such as drafts a retention purge
223
+ // already deleted, are erased as well: due at once, requested when they were deleted.
224
+ ...(erases
225
+ ? [
226
+ `INSERT INTO _ontology_replication_erasures (entity_id, record_id, requested_at, due_at)
227
+ SELECT ${ql(entity.id)}, record_id, min(at), now() FROM ${history}
228
+ WHERE kind = 'delete' GROUP BY record_id ON CONFLICT DO NOTHING`,
229
+ ]
230
+ : []),
212
231
  `DROP TRIGGER IF EXISTS _ontology_capture ON ${history}`,
213
232
  `CREATE TRIGGER _ontology_capture BEFORE INSERT ON ${history} FOR EACH ROW EXECUTE FUNCTION ${fn}()`,
214
233
  `DROP TRIGGER IF EXISTS _ontology_writer_guard ON ${table}`,
@@ -411,9 +411,11 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
411
411
  readonly unlink: Schema.optionalKey<Schema.String>;
412
412
  }>>;
413
413
  readonly writes: Schema.optionalKey<Schema.Literal<"actions">>;
414
+ readonly eraseFromWarehouseOnDelete: Schema.optionalKey<Schema.Literal<true>>;
414
415
  }>, {
415
416
  readonly builtIn: "built_in";
416
417
  readonly renamedFrom: "renamed_from";
418
+ readonly eraseFromWarehouseOnDelete: "erase_from_warehouse_on_delete";
417
419
  }>>;
418
420
  readonly roles: Schema.$Array<Schema.encodeKeys<Schema.Struct<{
419
421
  readonly name: Schema.String;
@@ -639,7 +641,7 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
639
641
  readonly tolerance: Schema.optionalKey<Schema.Number>;
640
642
  }>>;
641
643
  readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
642
- readonly body: Schema.Literal<true>;
644
+ readonly body: Schema.Literals<readonly [true, "sorted-json"]>;
643
645
  }>, Schema.Struct<{
644
646
  readonly header: Schema.String;
645
647
  }>, Schema.Struct<{
@@ -800,9 +802,11 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
800
802
  readonly unlink: Schema.optionalKey<Schema.String>;
801
803
  }>>;
802
804
  readonly writes: Schema.optionalKey<Schema.Literal<"actions">>;
805
+ readonly eraseFromWarehouseOnDelete: Schema.optionalKey<Schema.Literal<true>>;
803
806
  }>, {
804
807
  readonly builtIn: "built_in";
805
808
  readonly renamedFrom: "renamed_from";
809
+ readonly eraseFromWarehouseOnDelete: "erase_from_warehouse_on_delete";
806
810
  }>>>;
807
811
  readonly roles: Schema.toEncoded<Schema.$Array<Schema.encodeKeys<Schema.Struct<{
808
812
  readonly name: Schema.String;
@@ -1028,7 +1032,7 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
1028
1032
  readonly tolerance: Schema.optionalKey<Schema.Number>;
1029
1033
  }>>;
1030
1034
  readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
1031
- readonly body: Schema.Literal<true>;
1035
+ readonly body: Schema.Literals<readonly [true, "sorted-json"]>;
1032
1036
  }>, Schema.Struct<{
1033
1037
  readonly header: Schema.String;
1034
1038
  }>, Schema.Struct<{
@@ -107,6 +107,13 @@ export declare const STRIPE_TOLERANCE_SECONDS = 300;
107
107
  * is SegmentStream's, which holds the secret.
108
108
  */
109
109
  export declare function hmacSignature(format: WebhookHmacFormat): SignatureScheme;
110
+ /**
111
+ * The body re-serialized as a provider signs it with `{ body: "sorted-json" }`: parsed as a JSON
112
+ * object and written compactly with every object's keys sorted, exactly as
113
+ * `JSON.stringify(sortObject(JSON.parse(body)))` writes it in Node; arrays keep their order.
114
+ * `undefined` when the body is not UTF-8 JSON whose top level is an object.
115
+ */
116
+ export declare function sortedJson(body: Uint8Array): string | undefined;
110
117
  /**
111
118
  * Stripe's `Stripe-Signature`: `t=<unix seconds>` and one or more `v1=<hex>`. The signed bytes are
112
119
  * `<t>.` followed by the raw body; the HMAC is SHA-256 keyed with the whole `whsec_…` string.
@@ -197,7 +197,16 @@ export function hmacSignature(format) {
197
197
  parts.push(encoder.encode(part));
198
198
  }
199
199
  else if ("body" in part) {
200
- parts.push(body);
200
+ if (part.body === true) {
201
+ parts.push(body);
202
+ }
203
+ else {
204
+ const sorted = sortedJson(body);
205
+ if (sorted === undefined) {
206
+ return { ok: false, reason: "signature_malformed" };
207
+ }
208
+ parts.push(encoder.encode(sorted));
209
+ }
201
210
  }
202
211
  else if ("timestamp" in part) {
203
212
  parts.push(encoder.encode(timestamp ?? ""));
@@ -222,6 +231,35 @@ export function hmacSignature(format) {
222
231
  return { ok: true, message, signatures };
223
232
  };
224
233
  }
234
+ /**
235
+ * The body re-serialized as a provider signs it with `{ body: "sorted-json" }`: parsed as a JSON
236
+ * object and written compactly with every object's keys sorted, exactly as
237
+ * `JSON.stringify(sortObject(JSON.parse(body)))` writes it in Node; arrays keep their order.
238
+ * `undefined` when the body is not UTF-8 JSON whose top level is an object.
239
+ */
240
+ export function sortedJson(body) {
241
+ const text = utf8Text(body);
242
+ let parsed;
243
+ if (text === undefined) {
244
+ return undefined;
245
+ }
246
+ try {
247
+ parsed = JSON.parse(text);
248
+ }
249
+ catch {
250
+ return undefined;
251
+ }
252
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
253
+ return undefined;
254
+ }
255
+ // Object.fromEntries defines each key as an own property, `__proto__` included, and
256
+ // JSON.stringify writes integer keys first, as it does for the provider's own sorted object.
257
+ return JSON.stringify(parsed, (_key, value) => typeof value === "object" && value !== null && !Array.isArray(value)
258
+ ? Object.fromEntries(Object.keys(value)
259
+ .sort()
260
+ .map((key) => [key, value[key]]))
261
+ : value);
262
+ }
225
263
  /**
226
264
  * Stripe's `Stripe-Signature`: `t=<unix seconds>` and one or more `v1=<hex>`. The signed bytes are
227
265
  * `<t>.` followed by the raw body; the HMAC is SHA-256 keyed with the whole `whsec_…` string.
@@ -18,9 +18,16 @@ export declare const WEBHOOK_SIGNATURE_ENCODINGS: readonly ["hex", "base64"];
18
18
  export type WebhookSignatureEncoding = (typeof WEBHOOK_SIGNATURE_ENCODINGS)[number];
19
19
  /** The bytes of each algorithm's digest, which a signature must decode to. */
20
20
  export declare const WEBHOOK_HMAC_DIGEST_BYTES: Readonly<Record<WebhookHmacAlgorithm, number>>;
21
- /** One piece of the signed bytes: text, the raw body, a header's value or the timestamp. */
21
+ /**
22
+ * How a signed message includes the delivery's body: `true` its raw bytes, `"sorted-json"` the
23
+ * body parsed as a JSON object and written again compactly with the keys of every object sorted,
24
+ * as `JSON.stringify` writes it, for providers that sign such a re-serialization.
25
+ */
26
+ export declare const WEBHOOK_SIGNED_BODIES: readonly [true, "sorted-json"];
27
+ export type WebhookSignedBody = (typeof WEBHOOK_SIGNED_BODIES)[number];
28
+ /** One piece of the signed bytes: text, the body, a header's value or the timestamp. */
22
29
  export type WebhookSignedPart = string | {
23
- readonly body: true;
30
+ readonly body: WebhookSignedBody;
24
31
  } | {
25
32
  readonly header: string;
26
33
  } | {
package/dist/webhooks.js CHANGED
@@ -20,6 +20,12 @@ export const WEBHOOK_HMAC_DIGEST_BYTES = {
20
20
  sha256: 32,
21
21
  sha512: 64,
22
22
  };
23
+ /**
24
+ * How a signed message includes the delivery's body: `true` its raw bytes, `"sorted-json"` the
25
+ * body parsed as a JSON object and written again compactly with the keys of every object sorted,
26
+ * as `JSON.stringify` writes it, for providers that sign such a re-serialization.
27
+ */
28
+ export const WEBHOOK_SIGNED_BODIES = [true, "sorted-json"];
23
29
  /** How far a signed timestamp may be from a delivery's arrival by default, in seconds. */
24
30
  export const WEBHOOK_TIMESTAMP_TOLERANCE_SECONDS = 300;
25
31
  /** The widest tolerance a format may declare, in seconds. */
@@ -241,8 +247,11 @@ export function webhookSignatureProblems(signature) {
241
247
  report(at, `A text part has 1 to ${MAX_WEBHOOK_MESSAGE_TEXT} characters.`);
242
248
  }
243
249
  }
244
- else if (isRecord(part) && Object.keys(part).length === 1 && part.body === true) {
250
+ else if (isRecord(part) && Object.keys(part).length === 1 && "body" in part) {
245
251
  bodies += 1;
252
+ if (!WEBHOOK_SIGNED_BODIES.includes(part.body)) {
253
+ report(at, 'The body is signed as { body: true } or { body: "sorted-json" }.');
254
+ }
246
255
  }
247
256
  else if (isRecord(part) && Object.keys(part).length === 1 && part.timestamp === true) {
248
257
  if (!timed) {
@@ -256,11 +265,11 @@ export function webhookSignatureProblems(signature) {
256
265
  }
257
266
  }
258
267
  else {
259
- report(at, "A part is text, { body: true }, { header } or { timestamp: true }.");
268
+ report(at, 'A part is text, { body: true }, { body: "sorted-json" }, { header } or { timestamp: true }.');
260
269
  }
261
270
  }
262
271
  if (bodies !== 1) {
263
- report("message", "message includes { body: true } exactly once.");
272
+ report("message", "message includes the body, as { body }, exactly once.");
264
273
  }
265
274
  }
266
275
  }
@@ -336,7 +345,7 @@ export function webhookSignatureManifest(signature) {
336
345
  message: message.map((part) => typeof part === "string"
337
346
  ? part
338
347
  : "body" in part
339
- ? { body: true }
348
+ ? { body: part.body }
340
349
  : "timestamp" in part
341
350
  ? { timestamp: true }
342
351
  : { header: part.header }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/ontology",
3
- "version": "0.168.1",
3
+ "version": "0.170.0",
4
4
  "description": "Define a SegmentStream workspace app's ontology: entities, relationships, roles and actions, written with Effect.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "SegmentStream",