@eventsdk/sdk 0.0.0-stage → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +9 -0
  3. package/dist/compatibility-http/bridge/receive.d.ts +3 -0
  4. package/dist/compatibility-http/bridge/types.d.ts +44 -0
  5. package/dist/compatibility-http/index.d.ts +4 -0
  6. package/dist/compatibility-http/index.js +1 -0
  7. package/dist/compatibility-http/policy/validate-policy.d.ts +3 -0
  8. package/dist/conformance/admission/harness.d.ts +20 -0
  9. package/dist/conformance/admission/run-suite.d.ts +2 -0
  10. package/dist/conformance/consumer/harness.d.ts +24 -0
  11. package/dist/conformance/consumer/run-apply-suite.d.ts +2 -0
  12. package/dist/conformance/consumer/run-worker-suite.d.ts +2 -0
  13. package/dist/conformance/fanout/harness.d.ts +39 -0
  14. package/dist/conformance/fanout/run-suite.d.ts +2 -0
  15. package/dist/conformance/gap/harness.d.ts +19 -0
  16. package/dist/conformance/gap/run-suite.d.ts +2 -0
  17. package/dist/conformance/index.d.ts +20 -0
  18. package/dist/conformance/index.js +1 -0
  19. package/dist/conformance/producer/harness.d.ts +21 -0
  20. package/dist/conformance/producer/run-suite.d.ts +2 -0
  21. package/dist/conformance/receipt/harness.d.ts +12 -0
  22. package/dist/conformance/receipt/projection-harness.d.ts +9 -0
  23. package/dist/conformance/receipt/run-projection-suite.d.ts +2 -0
  24. package/dist/conformance/receipt/run-suite.d.ts +2 -0
  25. package/dist/conformance/reliability/checks.d.ts +4 -0
  26. package/dist/conformance/result/harness.d.ts +15 -0
  27. package/dist/conformance/result/run-suite.d.ts +2 -0
  28. package/dist/conformance/version/compatibility.d.ts +13 -0
  29. package/dist/contracts/canonical/canonical-json.d.ts +1 -0
  30. package/dist/contracts/contract-types.d.ts +34 -0
  31. package/dist/contracts/generated/business-receipt.d.ts +21 -0
  32. package/dist/contracts/generated/cloud-event-context.d.ts +32 -0
  33. package/dist/contracts/generated/cloud-event-fanout.d.ts +33 -0
  34. package/dist/contracts/generated/cloud-event.d.ts +24 -0
  35. package/dist/contracts/generated/event-origin-claims.d.ts +13 -0
  36. package/dist/contracts/generated/exchange-grant.d.ts +11 -0
  37. package/dist/contracts/generated/exchange-registration.d.ts +24 -0
  38. package/dist/contracts/generated/fanout-event-draft.d.ts +28 -0
  39. package/dist/contracts/generated/gap-baseline.d.ts +18 -0
  40. package/dist/contracts/generated/gap-recovery-command.d.ts +7 -0
  41. package/dist/contracts/generated/identity-context.d.ts +15 -0
  42. package/dist/contracts/generated/namespaced-reference.d.ts +4 -0
  43. package/dist/contracts/generated/native-event-catalog.d.ts +19 -0
  44. package/dist/contracts/generated/node-connection-profile.d.ts +217 -0
  45. package/dist/contracts/generated/node-worker-observation.d.ts +7 -0
  46. package/dist/contracts/generated/outbox-recovery-command.d.ts +8 -0
  47. package/dist/contracts/generated/portable-exchange-registration.d.ts +109 -0
  48. package/dist/contracts/generated/portable-gap-baseline.d.ts +93 -0
  49. package/dist/contracts/generated/portable-gap-recovery-command.d.ts +35 -0
  50. package/dist/contracts/generated/portable-outbox-recovery-command.d.ts +37 -0
  51. package/dist/contracts/generated/public-jwks-snapshot.d.ts +141 -0
  52. package/dist/contracts/generated/result-ref.d.ts +8 -0
  53. package/dist/contracts/generated/supported-profiles.d.ts +3 -0
  54. package/dist/contracts/generated/tenant-connection.d.ts +13 -0
  55. package/dist/contracts/generated/tenant-context.d.ts +4 -0
  56. package/dist/contracts/index.d.ts +26 -0
  57. package/dist/contracts/index.js +1 -0
  58. package/dist/contracts/validation/contract-error.d.ts +16 -0
  59. package/dist/contracts/validation/contracts.d.ts +316 -0
  60. package/dist/contracts/validation/decode-cloud-event.d.ts +2 -0
  61. package/dist/contracts/validation/identity-context.d.ts +3 -0
  62. package/dist/contracts/validation/origin-proof-wire.d.ts +3 -0
  63. package/dist/contracts/validation/strict-json.d.ts +1 -0
  64. package/dist/core/inbox/accept-delivery.d.ts +26 -0
  65. package/dist/core/inbox/apply-delivery.d.ts +29 -0
  66. package/dist/core/inbox/domain-apply-result.d.ts +13 -0
  67. package/dist/core/inbox/inbox-worker.d.ts +2 -0
  68. package/dist/core/inbox/read-result.d.ts +12 -0
  69. package/dist/core/inbox/worker-types.d.ts +21 -0
  70. package/dist/core/index.d.ts +50 -0
  71. package/dist/core/index.js +1 -0
  72. package/dist/core/outbox/authorize-recovery.d.ts +75 -0
  73. package/dist/core/outbox/outbox-relay.d.ts +26 -0
  74. package/dist/core/outbox/record-event.d.ts +10 -0
  75. package/dist/core/outbox/record-fanout.d.ts +16 -0
  76. package/dist/core/ports/dead-letter.d.ts +29 -0
  77. package/dist/core/ports/inbox.d.ts +43 -0
  78. package/dist/core/ports/observability.d.ts +21 -0
  79. package/dist/core/ports/origin-refresh.d.ts +5 -0
  80. package/dist/core/ports/outbox.d.ts +46 -0
  81. package/dist/core/ports/result-reader.d.ts +14 -0
  82. package/dist/core/ports/transport.d.ts +13 -0
  83. package/dist/core/receipt/receipt-state.d.ts +3 -0
  84. package/dist/core/recovery/event-log.d.ts +28 -0
  85. package/dist/core/recovery/gap-baseline-binding.d.ts +2 -0
  86. package/dist/core/recovery/gap-recovery.d.ts +15 -0
  87. package/dist/core/recovery/receipt-identity-recovery.d.ts +8 -0
  88. package/dist/core/recovery/receipt-recovery.d.ts +14 -0
  89. package/dist/core/recovery/replay-dead-letter.d.ts +4 -0
  90. package/dist/core/runtime/dependencies.d.ts +19 -0
  91. package/dist/core/runtime/errors.d.ts +6 -0
  92. package/dist/core/runtime/event-identity.d.ts +14 -0
  93. package/dist/core/runtime/exchange-connection.d.ts +7 -0
  94. package/dist/core/runtime/fanout-identity.d.ts +6 -0
  95. package/dist/core/runtime/lease.d.ts +6 -0
  96. package/dist/core/runtime/observe-health.d.ts +3 -0
  97. package/dist/core/runtime/operation.d.ts +2 -0
  98. package/dist/core/runtime/retry.d.ts +14 -0
  99. package/dist/identity-contracts/authorization/authorization-port.d.ts +35 -0
  100. package/dist/identity-contracts/index.d.ts +2 -0
  101. package/dist/identity-contracts/index.js +0 -0
  102. package/dist/identity-contracts/origin/verified-origin.d.ts +28 -0
  103. package/dist/identity-verifier/index.d.ts +6 -0
  104. package/dist/identity-verifier/index.js +1 -0
  105. package/dist/identity-verifier/jwt/service-token-verifier.d.ts +15 -0
  106. package/dist/identity-verifier/origin/event-origin-policy.d.ts +36 -0
  107. package/dist/identity-verifier/origin/event-origin-signer.d.ts +6 -0
  108. package/dist/identity-verifier/origin/event-origin-verifier.d.ts +6 -0
  109. package/dist/index.d.ts +22 -0
  110. package/dist/index.js +20 -0
  111. package/dist/node-config/configuration-error.d.ts +4 -0
  112. package/dist/node-config/diagnostics/check-configuration.d.ts +40 -0
  113. package/dist/node-config/identity/load-identity.d.ts +14 -0
  114. package/dist/node-config/identity/local-recovery-origin.d.ts +3 -0
  115. package/dist/node-config/identity/public-identity.d.ts +87 -0
  116. package/dist/node-config/identity/public-snapshot.d.ts +2 -0
  117. package/dist/node-config/identity/signing-identity.d.ts +5 -0
  118. package/dist/node-config/index.d.ts +12 -0
  119. package/dist/node-config/index.js +1 -0
  120. package/dist/node-config/main.js +3 -0
  121. package/dist/node-config/operations/export-own-public.d.ts +8 -0
  122. package/dist/node-config/operations/refresh-trust.d.ts +10 -0
  123. package/dist/node-config/profile/load-profile.d.ts +6 -0
  124. package/dist/node-config/profile/validate-profile.d.ts +2 -0
  125. package/dist/node-worker/index.d.ts +3 -0
  126. package/dist/node-worker/index.js +1 -0
  127. package/dist/node-worker/lifecycle.d.ts +19 -0
  128. package/dist/node-worker/route-scheduler.d.ts +17 -0
  129. package/dist/node-worker/session.d.ts +15 -0
  130. package/dist/provisioner/application/apply.d.ts +11 -0
  131. package/dist/provisioner/application/ports.d.ts +44 -0
  132. package/dist/provisioner/application/verify.d.ts +7 -0
  133. package/dist/provisioner/cli/arguments.d.ts +9 -0
  134. package/dist/provisioner/cli/live-command.d.ts +7 -0
  135. package/dist/provisioner/cli/main.js +2 -0
  136. package/dist/provisioner/cli/run.d.ts +2 -0
  137. package/dist/provisioner/cli/session-types.d.ts +26 -0
  138. package/dist/provisioner/conformance/policy.d.ts +9 -0
  139. package/dist/provisioner/index.d.ts +17 -0
  140. package/dist/provisioner/index.js +1 -0
  141. package/dist/provisioner/manifest/types.d.ts +55 -0
  142. package/dist/provisioner/manifest/validate.d.ts +3 -0
  143. package/dist/provisioner/nats/inspector.d.ts +13 -0
  144. package/dist/provisioner/nats/types.d.ts +38 -0
  145. package/dist/provisioner/nats/writer-types.d.ts +11 -0
  146. package/dist/provisioner/nats/writer.d.ts +18 -0
  147. package/dist/provisioner/planning/digest.d.ts +1 -0
  148. package/dist/provisioner/planning/plan.d.ts +18 -0
  149. package/dist/transport-nats/connection/delivery-session.d.ts +10 -0
  150. package/dist/transport-nats/connection/verified-connection.d.ts +12 -0
  151. package/dist/transport-nats/consume/delivery-handler.d.ts +34 -0
  152. package/dist/transport-nats/consume/nats-consumer.d.ts +18 -0
  153. package/dist/transport-nats/index.d.ts +12 -0
  154. package/dist/transport-nats/index.js +3 -0
  155. package/dist/transport-nats/publish/nats-publisher.d.ts +24 -0
  156. package/dist/transport-nats/transport-error.d.ts +5 -0
  157. package/licenses/NATS-LICENSE +201 -0
  158. package/package.json +75 -3
  159. package/README.md +0 -3
@@ -0,0 +1,16 @@
1
+ export interface ValidationIssue {
2
+ readonly path: string;
3
+ readonly keyword: string;
4
+ }
5
+ export type ValidationResult<T> = {
6
+ readonly valid: true;
7
+ readonly value: T;
8
+ } | {
9
+ readonly valid: false;
10
+ readonly issues: readonly ValidationIssue[];
11
+ };
12
+ export declare class ContractError extends Error {
13
+ readonly issues: readonly ValidationIssue[];
14
+ readonly code = "INVALID_CONTRACT";
15
+ constructor(issues: readonly ValidationIssue[]);
16
+ }
@@ -0,0 +1,316 @@
1
+ import type { GapBaseline } from '../generated/gap-baseline.js';
2
+ import type { GapRecoveryCommand } from '../generated/gap-recovery-command.js';
3
+ import type { ExchangeRegistration } from '../generated/exchange-registration.js';
4
+ import type { OutboxRecoveryCommand } from '../generated/outbox-recovery-command.js';
5
+ import type { NodeWorkerObservation } from '../generated/node-worker-observation.js';
6
+ import type { NativeEventCatalog } from '../generated/native-event-catalog.js';
7
+ import type { CloudEvent, FanoutEventDraft, NamespacedReference, IdentityContext, BusinessReceipt, ResultRef, TenantContext, TenantConnection, ExchangeGrant, EventOriginClaims, NodeConnectionProfile, PublicJwksSnapshot } from '../contract-types.js';
8
+ export declare const parseNativeEventCatalog: (value: unknown) => NativeEventCatalog;
9
+ export declare const parseNodeWorkerObservation: (value: unknown) => NodeWorkerObservation;
10
+ export declare const validateOutboxRecoveryCommand: (value: unknown) => import("./contract-error.js").ValidationResult<OutboxRecoveryCommand>;
11
+ export declare const parseOutboxRecoveryCommand: (value: unknown) => OutboxRecoveryCommand;
12
+ export declare const validateCloudEvent: (value: unknown) => import("./contract-error.js").ValidationResult<CloudEvent>;
13
+ export declare const validateCloudEventV1: (value: unknown) => import("./contract-error.js").ValidationResult<{
14
+ readonly specversion: "1.0";
15
+ readonly id: string;
16
+ readonly source: string;
17
+ readonly type: string;
18
+ readonly time: string;
19
+ readonly dataschema: string;
20
+ readonly datacontenttype: "application/json";
21
+ readonly profile: "eventsdk/1.0";
22
+ readonly kind: "EVENT" | "HANDOFF" | "RECEIPT";
23
+ readonly serviceorigin: string;
24
+ readonly sourcetenant: string;
25
+ readonly audience: string;
26
+ readonly connectionref: string;
27
+ readonly grantref: string;
28
+ readonly grantversion: number;
29
+ readonly correlationid: string;
30
+ readonly causationid?: string;
31
+ readonly subject?: string;
32
+ readonly data: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | {
33
+ readonly [x: string]: string | number | boolean | any | any | null;
34
+ } | null)[] | {
35
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null;
36
+ } | null)[] | {
37
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null;
38
+ } | null)[] | {
39
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null;
40
+ } | null)[] | {
41
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
42
+ } | null)[] | {
43
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
44
+ } | null)[] | {
45
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
46
+ } | null)[] | {
47
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
48
+ } | null)[] | {
49
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
50
+ } | null)[] | {
51
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
52
+ } | null)[] | {
53
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
54
+ } | null)[] | {
55
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
56
+ } | null;
57
+ }>;
58
+ export declare const validateCloudEventV11: (value: unknown) => import("./contract-error.js").ValidationResult<{
59
+ readonly specversion: "1.0";
60
+ readonly id: string;
61
+ readonly source: string;
62
+ readonly type: string;
63
+ readonly time: string;
64
+ readonly dataschema: string;
65
+ readonly datacontenttype: "application/json";
66
+ readonly profile: "eventsdk/1.1";
67
+ readonly kind: "EVENT" | "HANDOFF" | "RECEIPT";
68
+ readonly serviceorigin: string;
69
+ readonly sourcetenant: string;
70
+ readonly audience: string;
71
+ readonly connectionref: string;
72
+ readonly grantref: string;
73
+ readonly grantversion: number;
74
+ readonly correlationid: string;
75
+ readonly causationid?: string;
76
+ readonly subject?: string;
77
+ readonly data: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | {
78
+ readonly [x: string]: string | number | boolean | any | any | null;
79
+ } | null)[] | {
80
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null;
81
+ } | null)[] | {
82
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null;
83
+ } | null)[] | {
84
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null;
85
+ } | null)[] | {
86
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
87
+ } | null)[] | {
88
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
89
+ } | null)[] | {
90
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
91
+ } | null)[] | {
92
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
93
+ } | null)[] | {
94
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
95
+ } | null)[] | {
96
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
97
+ } | null)[] | {
98
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
99
+ } | null)[] | {
100
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
101
+ } | null;
102
+ readonly orgnamespace?: string;
103
+ readonly orgref?: string;
104
+ readonly projectnamespace?: string;
105
+ readonly projectref?: string;
106
+ readonly principalnamespace?: string;
107
+ readonly principalref?: string;
108
+ readonly resourcenamespace?: string;
109
+ readonly resourceref?: string;
110
+ }>;
111
+ export declare const validateNamespacedReference: (value: unknown) => import("./contract-error.js").ValidationResult<{
112
+ readonly namespace: string;
113
+ readonly ref: string;
114
+ }>;
115
+ export declare const validateIdentityContext: (value: unknown) => import("./contract-error.js").ValidationResult<{
116
+ readonly sourceTenant: {
117
+ readonly serviceRef: string;
118
+ readonly tenantRef: string;
119
+ };
120
+ readonly organization?: {
121
+ readonly namespace: string;
122
+ readonly ref: string;
123
+ };
124
+ readonly project?: {
125
+ readonly namespace: string;
126
+ readonly ref: string;
127
+ };
128
+ readonly actorPrincipal?: {
129
+ readonly namespace: string;
130
+ readonly ref: string;
131
+ };
132
+ readonly resource?: {
133
+ readonly namespace: string;
134
+ readonly ref: string;
135
+ };
136
+ }>;
137
+ export declare const validateBusinessReceipt: (value: unknown) => import("./contract-error.js").ValidationResult<{
138
+ readonly receiptRef: string;
139
+ readonly originSource: string;
140
+ readonly originEventId: string;
141
+ readonly deliveryRef: string;
142
+ readonly consumerRef: string;
143
+ readonly targetScope: string;
144
+ readonly disposition: "RECEIVED" | "APPLIED" | "REJECTED" | "HOLD" | "UNKNOWN";
145
+ readonly recordedAt: string;
146
+ readonly revision: number;
147
+ readonly reasonCode?: string;
148
+ readonly resultRef?: {
149
+ readonly sourceSystem: string;
150
+ readonly resourceType: string;
151
+ readonly resourceId: string;
152
+ readonly revision: string;
153
+ readonly digest: string;
154
+ readonly evidenceRef?: string;
155
+ };
156
+ }>;
157
+ export declare const validateResultRef: (value: unknown) => import("./contract-error.js").ValidationResult<{
158
+ readonly sourceSystem: string;
159
+ readonly resourceType: string;
160
+ readonly resourceId: string;
161
+ readonly revision: string;
162
+ readonly digest: string;
163
+ readonly evidenceRef?: string;
164
+ }>;
165
+ export declare const validateTenantContext: (value: unknown) => import("./contract-error.js").ValidationResult<{
166
+ readonly serviceRef: string;
167
+ readonly tenantRef: string;
168
+ }>;
169
+ export declare const validateTenantConnection: (value: unknown) => import("./contract-error.js").ValidationResult<{
170
+ readonly connectionRef: string;
171
+ readonly version: number;
172
+ readonly local: {
173
+ readonly serviceRef: string;
174
+ readonly tenantRef: string;
175
+ };
176
+ readonly remote: {
177
+ readonly serviceRef: string;
178
+ readonly tenantRef: string;
179
+ };
180
+ readonly status: "ACTIVE" | "SUSPENDED" | "REVOKED";
181
+ readonly updatedAt: string;
182
+ readonly organizationRef?: string;
183
+ }>;
184
+ export declare const validateExchangeGrant: (value: unknown) => import("./contract-error.js").ValidationResult<{
185
+ readonly grantRef: string;
186
+ readonly version: number;
187
+ readonly connectionRef: string;
188
+ readonly direction: "OUTBOUND" | "INBOUND";
189
+ readonly status: "ACTIVE" | "SUSPENDED" | "REVOKED";
190
+ readonly eventTypes: readonly string[];
191
+ readonly audience: string;
192
+ readonly notBefore: string;
193
+ readonly expiresAt: string;
194
+ }>;
195
+ export declare const parseCloudEvent: (value: unknown) => CloudEvent;
196
+ export declare const parseBusinessReceipt: (value: unknown) => BusinessReceipt;
197
+ export declare const parseResultRef: (value: unknown) => ResultRef;
198
+ export declare const parseTenantContext: (value: unknown) => TenantContext;
199
+ export declare const parseTenantConnection: (value: unknown) => TenantConnection;
200
+ export declare const parseExchangeGrant: (value: unknown) => ExchangeGrant;
201
+ export declare const parseNamespacedReference: (value: unknown) => NamespacedReference;
202
+ export declare const parseIdentityContext: (value: unknown) => IdentityContext;
203
+ export declare const validateCloudEventV12: (value: unknown) => import("./contract-error.js").ValidationResult<{
204
+ readonly specversion: "1.0";
205
+ readonly id: string;
206
+ readonly source: string;
207
+ readonly type: string;
208
+ readonly time: string;
209
+ readonly dataschema: string;
210
+ readonly datacontenttype: "application/json";
211
+ readonly profile: "eventsdk/1.2";
212
+ readonly kind: "EVENT";
213
+ readonly serviceorigin: string;
214
+ readonly sourcetenant: string;
215
+ readonly audience: string;
216
+ readonly connectionref: string;
217
+ readonly grantref: string;
218
+ readonly grantversion: number;
219
+ readonly correlationid: string;
220
+ readonly causationid?: string;
221
+ readonly subject?: string;
222
+ readonly data: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | {
223
+ readonly [x: string]: string | number | boolean | any | any | null;
224
+ } | null)[] | {
225
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null;
226
+ } | null)[] | {
227
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null;
228
+ } | null)[] | {
229
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null;
230
+ } | null)[] | {
231
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
232
+ } | null)[] | {
233
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
234
+ } | null)[] | {
235
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
236
+ } | null)[] | {
237
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
238
+ } | null)[] | {
239
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
240
+ } | null)[] | {
241
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
242
+ } | null)[] | {
243
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
244
+ } | null)[] | {
245
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
246
+ } | null;
247
+ readonly orgnamespace?: string;
248
+ readonly orgref?: string;
249
+ readonly projectnamespace?: string;
250
+ readonly projectref?: string;
251
+ readonly principalnamespace?: string;
252
+ readonly principalref?: string;
253
+ readonly resourcenamespace?: string;
254
+ readonly resourceref?: string;
255
+ readonly deliveryid: string;
256
+ }>;
257
+ export declare const validateFanoutEventDraft: (value: unknown) => import("./contract-error.js").ValidationResult<{
258
+ readonly specversion: "1.0";
259
+ readonly id: string;
260
+ readonly source: string;
261
+ readonly type: string;
262
+ readonly time: string;
263
+ readonly dataschema: string;
264
+ readonly datacontenttype: "application/json";
265
+ readonly profile: "eventsdk/1.2";
266
+ readonly kind: "EVENT";
267
+ readonly serviceorigin: string;
268
+ readonly sourcetenant: string;
269
+ readonly correlationid: string;
270
+ readonly causationid?: string;
271
+ readonly subject?: string;
272
+ readonly data: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | {
273
+ readonly [x: string]: string | number | boolean | any | any | null;
274
+ } | null)[] | {
275
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null;
276
+ } | null)[] | {
277
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null;
278
+ } | null)[] | {
279
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null;
280
+ } | null)[] | {
281
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
282
+ } | null)[] | {
283
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
284
+ } | null)[] | {
285
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
286
+ } | null)[] | {
287
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
288
+ } | null)[] | {
289
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
290
+ } | null)[] | {
291
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
292
+ } | null)[] | {
293
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
294
+ } | null)[] | {
295
+ readonly [x: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | any | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null)[] | any | null;
296
+ } | null;
297
+ readonly orgnamespace?: string;
298
+ readonly orgref?: string;
299
+ readonly projectnamespace?: string;
300
+ readonly projectref?: string;
301
+ readonly principalnamespace?: string;
302
+ readonly principalref?: string;
303
+ readonly resourcenamespace?: string;
304
+ readonly resourceref?: string;
305
+ }>;
306
+ export declare const parseFanoutEventDraft: (value: unknown) => FanoutEventDraft;
307
+ export declare const validateEventOriginClaims: (value: unknown) => import("./contract-error.js").ValidationResult<EventOriginClaims>;
308
+ export declare const parseEventOriginClaims: (value: unknown) => EventOriginClaims;
309
+ export declare const validateNodeConnectionProfile: (value: unknown) => import("./contract-error.js").ValidationResult<NodeConnectionProfile>;
310
+ export declare const parseNodeConnectionProfile: (value: unknown) => NodeConnectionProfile;
311
+ export declare const validatePublicJwksSnapshot: (value: unknown) => import("./contract-error.js").ValidationResult<PublicJwksSnapshot>;
312
+ export declare const parsePublicJwksSnapshot: (value: unknown) => PublicJwksSnapshot;
313
+ export declare const validateExchangeRegistration: (value: unknown) => import("./contract-error.js").ValidationResult<ExchangeRegistration>;
314
+ export declare const parseExchangeRegistration: (value: unknown) => ExchangeRegistration;
315
+ export declare const parseGapBaseline: (value: unknown) => GapBaseline;
316
+ export declare const parseGapRecoveryCommand: (value: unknown) => GapRecoveryCommand;
@@ -0,0 +1,2 @@
1
+ import type { CloudEvent } from '../contract-types.js';
2
+ export declare function decodeCloudEvent(input: string | Uint8Array): CloudEvent;
@@ -0,0 +1,3 @@
1
+ import type { IdentityContext } from '../contract-types.js';
2
+ export declare function extractIdentityContext(input: unknown): IdentityContext;
3
+ export declare function assertWireGrantVersion(version: number): void;
@@ -0,0 +1,3 @@
1
+ export declare const EVENTSDK_ORIGIN_PROOF_HEADER = "EventSDK-Origin-Proof";
2
+ export declare const EVENTSDK_ORIGIN_PROOF_TYPE = "eventsdk-origin+jws";
3
+ export declare function isEventOriginProofWireForm(value: unknown): value is string;
@@ -0,0 +1 @@
1
+ export declare function parseJsonStrict(input: string | Uint8Array): unknown;
@@ -0,0 +1,26 @@
1
+ import { type BusinessReceipt } from '@eventsdk/sdk/contracts';
2
+ import type { AuthorizationPort, VerifiedOrigin } from '@eventsdk/sdk/identity-contracts';
3
+ import type { InboxAdmissionPort } from '../ports/inbox.js';
4
+ import type { Clock, Digest, IdGenerator, OperationOptions } from '../runtime/dependencies.js';
5
+ export interface DeliveryInput {
6
+ readonly event: unknown;
7
+ readonly origin: VerifiedOrigin;
8
+ readonly deliveryRef: string;
9
+ readonly consumerRef: string;
10
+ }
11
+ export interface AdmissionDependencies {
12
+ readonly audience: string;
13
+ readonly inbox: InboxAdmissionPort;
14
+ readonly authorization: AuthorizationPort;
15
+ readonly clock: Clock;
16
+ readonly ids: IdGenerator;
17
+ readonly digest: Digest;
18
+ }
19
+ export type DurableAdmission = {
20
+ readonly kind: 'RECEIVED' | 'DUPLICATE';
21
+ readonly receipt: BusinessReceipt;
22
+ } | {
23
+ readonly kind: 'REJECTED';
24
+ readonly reasonCode: string;
25
+ };
26
+ export declare function acceptDelivery(input: DeliveryInput, deps: AdmissionDependencies, options: OperationOptions): Promise<DurableAdmission>;
@@ -0,0 +1,29 @@
1
+ import { type BusinessReceipt, type ResultRef } from '@eventsdk/sdk/contracts';
2
+ import type { AuthorizationDecision, AuthorizationPort, AuthorizationRequest } from '@eventsdk/sdk/identity-contracts';
3
+ import type { ClaimedInbox, InboxApplyPort } from '../ports/inbox.js';
4
+ import type { ResultReadPort, ResultSnapshot } from '../ports/result-reader.js';
5
+ import type { Clock, Digest, OperationOptions } from '../runtime/dependencies.js';
6
+ import type { OriginRefreshPort } from '../ports/origin-refresh.js';
7
+ import type { DomainApplyResult } from './domain-apply-result.js';
8
+ export type { DomainApplyResult } from './domain-apply-result.js';
9
+ export interface ApplyAuthorizationPort<TTransaction> {
10
+ authorizeInTransaction(tx: TTransaction, request: AuthorizationRequest): Promise<AuthorizationDecision>;
11
+ }
12
+ export interface DomainApplyPort<TTransaction> {
13
+ apply(tx: TTransaction, claim: ClaimedInbox, snapshot: ResultSnapshot | undefined, signal: AbortSignal): Promise<void | DomainApplyResult>;
14
+ }
15
+ export interface ApplyDependencies<TTransaction> {
16
+ readonly inbox: InboxApplyPort<TTransaction>;
17
+ readonly authorization: ApplyAuthorizationPort<TTransaction>;
18
+ readonly domain: DomainApplyPort<TTransaction>;
19
+ readonly clock: Clock;
20
+ readonly digest: Digest;
21
+ readonly originRefresh?: OriginRefreshPort;
22
+ }
23
+ export interface ApplyReadback {
24
+ readonly reference: ResultRef;
25
+ readonly reader: ResultReadPort;
26
+ readonly authorization: AuthorizationPort;
27
+ readonly digest: Digest;
28
+ }
29
+ export declare function applyDelivery<T>(claim: ClaimedInbox, deps: ApplyDependencies<T>, options: OperationOptions, readback?: ApplyReadback): Promise<BusinessReceipt>;
@@ -0,0 +1,13 @@
1
+ import { type ResultRef } from '@eventsdk/sdk/contracts';
2
+ export interface LegacyDomainApplyResult {
3
+ readonly resultRef?: ResultRef;
4
+ }
5
+ export type DomainApplyOutcome = {
6
+ readonly disposition: 'APPLIED';
7
+ readonly resultRef?: ResultRef;
8
+ } | {
9
+ readonly disposition: 'REJECTED' | 'HOLD';
10
+ readonly reasonCode: string;
11
+ };
12
+ export type DomainApplyResult = LegacyDomainApplyResult | DomainApplyOutcome;
13
+ export declare function normalizeDomainApplyResult(value: unknown): DomainApplyOutcome;
@@ -0,0 +1,2 @@
1
+ import type { InboxWorkerDependencies, InboxWorkerOptions, InboxWorkerSummary } from './worker-types.js';
2
+ export declare function runInboxWorker<T>(deps: InboxWorkerDependencies<T>, options: InboxWorkerOptions): Promise<InboxWorkerSummary>;
@@ -0,0 +1,12 @@
1
+ import { type CloudEvent, type ResultRef } from '@eventsdk/sdk/contracts';
2
+ import type { AuthorizationPort, VerifiedOrigin } from '@eventsdk/sdk/identity-contracts';
3
+ import type { ResultReadPort, ResultSnapshot } from '../ports/result-reader.js';
4
+ import type { Clock, Digest } from '../runtime/dependencies.js';
5
+ export interface ResultReadRequest {
6
+ readonly reference: ResultRef;
7
+ readonly event: CloudEvent;
8
+ readonly origin: VerifiedOrigin;
9
+ readonly consumerRef: string;
10
+ readonly targetScope: string;
11
+ }
12
+ export declare function readAuthorizedResult(request: ResultReadRequest, reader: ResultReadPort, authorization: AuthorizationPort, digest: Digest, signal: AbortSignal, clock: Clock): Promise<ResultSnapshot>;
@@ -0,0 +1,21 @@
1
+ import type { BusinessReceipt } from '@eventsdk/sdk/contracts';
2
+ import type { DeadLetterPort, InboxWorkClaim, InboxWorkPort } from '../ports/dead-letter.js';
3
+ import type { InboxApplyPort } from '../ports/inbox.js';
4
+ import type { Clock, IdGenerator, OperationOptions, Random } from '../runtime/dependencies.js';
5
+ import type { RetryPolicy } from '../runtime/retry.js';
6
+ export interface InboxWorkerDependencies<TTransaction> {
7
+ readonly work: InboxWorkPort;
8
+ readonly receipts: Pick<InboxApplyPort<TTransaction>, 'readReceipt'>;
9
+ readonly deadLetters: DeadLetterPort<TTransaction>;
10
+ readonly clock: Clock;
11
+ readonly ids: IdGenerator;
12
+ readonly random: Random;
13
+ readonly process: (claim: InboxWorkClaim, options: OperationOptions) => Promise<BusinessReceipt>;
14
+ }
15
+ export interface InboxWorkerOptions extends OperationOptions {
16
+ readonly batchSize: number;
17
+ readonly leaseMs: number;
18
+ readonly retry: RetryPolicy;
19
+ }
20
+ export type InboxWorkOutcome = 'APPLIED' | 'REJECTED' | 'RETRY' | 'QUARANTINED' | 'UNRESOLVED';
21
+ export type InboxWorkerSummary = Readonly<Record<InboxWorkOutcome, number>>;
@@ -0,0 +1,50 @@
1
+ export { CoreError, assertNotAborted } from './runtime/errors.js';
2
+ export type { CoreErrorCode } from './runtime/errors.js';
3
+ export type { Clock, IdGenerator, Digest, Random, OperationOptions, MetricSink, } from './runtime/dependencies.js';
4
+ export { boundedOperation } from './runtime/operation.js';
5
+ export { assertLiveLease } from './runtime/lease.js';
6
+ export type { Lease } from './runtime/lease.js';
7
+ export { decideRetry } from './runtime/retry.js';
8
+ export type { RetryPolicy, RetryDecision } from './runtime/retry.js';
9
+ export { eventMessageId, eventDigest, inboxKey } from './runtime/event-identity.js';
10
+ export type { EventIdentity, InboxKey } from './runtime/event-identity.js';
11
+ export type { PublishPort, PublishAck, PublishContext } from './ports/transport.js';
12
+ export type { OutboxRecordPort, OutboxRelayPort, OutboxPort, OutboxRecord, ClaimedEvent, PublishOutcome, } from './ports/outbox.js';
13
+ export type { InboxAdmissionPort, InboxApplyPort, AcceptedEvent, PersistResult, QuarantineRecord, ClaimedInbox, } from './ports/inbox.js';
14
+ export type { ResultReadPort, ResultSnapshot } from './ports/result-reader.js';
15
+ export { recordEvent } from './outbox/record-event.js';
16
+ export type { RecordDependencies } from './outbox/record-event.js';
17
+ export { relayOutbox } from './outbox/outbox-relay.js';
18
+ export type { RelayDependencies, RelayOptions, RelaySummary } from './outbox/outbox-relay.js';
19
+ export { acceptDelivery } from './inbox/accept-delivery.js';
20
+ export type { DeliveryInput, AdmissionDependencies, DurableAdmission, } from './inbox/accept-delivery.js';
21
+ export { applyDelivery } from './inbox/apply-delivery.js';
22
+ export type { ApplyAuthorizationPort, DomainApplyPort, DomainApplyResult, ApplyDependencies, ApplyReadback, } from './inbox/apply-delivery.js';
23
+ export { readAuthorizedResult } from './inbox/read-result.js';
24
+ export type { ResultReadRequest } from './inbox/read-result.js';
25
+ export { assertReceiptTransition, classifyReceiptCommit } from './receipt/receipt-state.js';
26
+ export { recoverReceipt } from './recovery/receipt-recovery.js';
27
+ export { recoverReceiptByIdentity } from './recovery/receipt-identity-recovery.js';
28
+ export type { ReceiptIdentityLookupPort } from './recovery/receipt-identity-recovery.js';
29
+ export type { ReceiptLookupPort, RecoveryObservation } from './recovery/receipt-recovery.js';
30
+ export { stageEventLogPage } from './recovery/event-log.js';
31
+ export type { EventLogItem, EventLogPage, NativeEventLogPort, EventLogCheckpointPort, } from './recovery/event-log.js';
32
+ export { recoverGap } from './recovery/gap-recovery.js';
33
+ export type { AuthorizedSnapshot, SnapshotRecoveryPort } from './recovery/gap-recovery.js';
34
+ export type { DeadLetterEntry, DeadLetterPort, InboxWorkPort } from './ports/dead-letter.js';
35
+ export { replayDeadLetter } from './recovery/replay-dead-letter.js';
36
+ export type { OriginRefreshPort } from './ports/origin-refresh.js';
37
+ export type { DeliveryHealth, DeliveryHealthPort, HealthMetricSink, } from './ports/observability.js';
38
+ export { observeDeliveryHealth } from './runtime/observe-health.js';
39
+ export type { InboxWorkClaim } from './ports/dead-letter.js';
40
+ export type { InboxWorkerDependencies, InboxWorkerOptions, InboxWorkerSummary, InboxWorkOutcome, } from './inbox/worker-types.js';
41
+ export { runInboxWorker } from './inbox/inbox-worker.js';
42
+ export type { DomainApplyOutcome, LegacyDomainApplyResult } from './inbox/domain-apply-result.js';
43
+ export { deriveDeliveryId, logicalEventDigest, fanoutLogicalEvent, assertDeliveryIdentity, } from './runtime/fanout-identity.js';
44
+ export { recordFanoutEvent, prepareFanoutDelivery } from './outbox/record-fanout.js';
45
+ export type { FanoutRoute, FanoutRecipient } from './outbox/record-fanout.js';
46
+ export type { FanoutOutboxRecord } from './ports/outbox.js';
47
+ export type { FanoutAcceptedEvent } from './ports/inbox.js';
48
+ export { deriveExchangeConnectionRef } from './runtime/exchange-connection.js';
49
+ export { authorizeOutboxRecovery, type HeldOutboxRecord } from './outbox/authorize-recovery.js';
50
+ export { assertGapBaselineBinding } from './recovery/gap-baseline-binding.js';
@@ -0,0 +1 @@
1
+ var CoreError=class extends Error{constructor(code){super(code);this.code=code;this.name="CoreError"}code};function assertNotAborted(signal){if(signal?.aborted)throw new CoreError("ABORTED")}async function boundedOperation(options,operation){assertNotAborted(options.signal);if(!Number.isSafeInteger(options.timeoutMs)||options.timeoutMs<1||options.timeoutMs>2147483647){throw new CoreError("INVALID_CONFIGURATION")}const controller=new AbortController;let rejectAbort;const stopped=new Promise((_resolve,reject)=>{rejectAbort=reject});const stop=code=>{controller.abort();rejectAbort?.(new CoreError(code))};const onAbort=()=>stop("ABORTED");options.signal?.addEventListener("abort",onAbort,{once:true});const timer=setTimeout(()=>stop("TIMEOUT"),options.timeoutMs);try{return await Promise.race([Promise.resolve().then(()=>{assertNotAborted(controller.signal);return operation(controller.signal)}),stopped])}finally{clearTimeout(timer);options.signal?.removeEventListener("abort",onAbort)}}function assertLiveLease(lease,now){if(!Number.isFinite(now)||!lease.token||!Number.isSafeInteger(lease.generation)||lease.generation<1||!Number.isFinite(lease.expiresAt)||lease.expiresAt<=now){throw new CoreError("STALE_LEASE")}}function decideRetry(attempt,now,policy,random){if(!Number.isSafeInteger(attempt)||attempt<1||!Number.isSafeInteger(now)||now<0||!Number.isSafeInteger(policy.maxAttempts)||policy.maxAttempts<1||!Number.isSafeInteger(policy.baseDelayMs)||policy.baseDelayMs<0||!Number.isSafeInteger(policy.maxDelayMs)||policy.maxDelayMs<policy.baseDelayMs||policy.jitterRatio<0||policy.jitterRatio>1||!Number.isFinite(policy.jitterRatio)){throw new CoreError("INVALID_CONFIGURATION")}if(attempt>=policy.maxAttempts)return{kind:"EXHAUSTED"};const sample=random.next();if(!Number.isFinite(sample)||sample<0||sample>=1)throw new CoreError("INVALID_CONFIGURATION");const base=Math.min(policy.maxDelayMs,policy.baseDelayMs*2**Math.min(attempt-1,52));const delay=Math.min(policy.maxDelayMs,base*(1-policy.jitterRatio+sample*policy.jitterRatio));const nextAttemptAt=now+Math.floor(delay);if(!Number.isSafeInteger(nextAttemptAt))throw new CoreError("INVALID_CONFIGURATION");return{kind:"RETRY",nextAttemptAt}}import{canonicalJson}from"@eventsdk/sdk/contracts";function eventMessageId(event,digest){return digest.sha256(event.deliveryid===void 0?`${event.source}\0${event.id}`:canonicalJson(["eventsdk-delivery-message/1",event.source,event.id,event.deliveryid]))}function eventDigest(event,digest){return digest.sha256(canonicalJson(event))}function inboxKey(key){return[key.consumerRef,key.targetScope,key.source,key.id].map(value=>`${value.length}:${value}`).join("")}import{parseCloudEvent}from"@eventsdk/sdk/contracts";function assertOrigin(event,origin,now){if(!Number.isFinite(now)||!origin.issuer||!origin.subject||!Array.isArray(origin.audience)||event.serviceorigin!==origin.serviceRef||!origin.audience.includes(event.audience)||!Number.isFinite(Date.parse(origin.expiresAt))||Date.parse(origin.expiresAt)<=now||!Number.isFinite(Date.parse(origin.verifiedAt))||Date.parse(origin.verifiedAt)>now){throw new CoreError("ORIGIN_MISMATCH")}}function authorizedScope(event,decision){if(decision.decision!=="ALLOW"){throw new CoreError(decision.decision==="DENY"?"AUTHORIZATION_DENIED":"AUTHORIZATION_UNKNOWN")}if(!decision.targetScope||decision.source!==event.source||decision.connectionRef!==event.connectionref||decision.grantRef!==event.grantref||decision.grantVersion!==event.grantversion){throw new CoreError("AUTHORIZATION_DENIED")}return decision.targetScope}import{canonicalJson as canonicalJson2,parseFanoutEventDraft}from"@eventsdk/sdk/contracts";function fanoutLogicalEvent(event){const{audience:_audience,connectionref:_connection,grantref:_grant,grantversion:_version,deliveryid:_delivery,...logical}=event;return parseFanoutEventDraft(logical)}function logicalEventDigest(event,digest){return digest.sha256(canonicalJson2(event.profile==="eventsdk/1.2"?fanoutLogicalEvent(event):event))}function deriveDeliveryId(event,digest){return digest.sha256(canonicalJson2(["eventsdk-delivery/1",event.source,event.id,event.audience,event.connectionref]))}async function assertDeliveryIdentity(event,digest){if(event.profile==="eventsdk/1.2"&&event.deliveryid!==await deriveDeliveryId(event,digest))throw new CoreError("EVENT_ID_CONFLICT")}function immutableSnapshot(value){return freezeDeep(structuredClone(value))}function freezeDeep(value){if(value!==null&&typeof value==="object"&&!Object.isFrozen(value)){Object.freeze(value);for(const nested of Object.values(value))freezeDeep(nested)}return value}async function recordEvent(tx,input,origin,dependencies,options){const event=immutableSnapshot(parseCloudEvent(input));origin=immutableSnapshot(origin);await boundedOperation(options,async signal=>{assertOrigin(event,origin,dependencies.clock.now());await assertDeliveryIdentity(event,dependencies.digest);if(event.profile==="eventsdk/1.2"&&!dependencies.outbox.recordFanoutInTransaction)throw new CoreError("ADAPTER_CAPABILITY_REQUIRED");const decision=await dependencies.authorization.authorize({phase:"OUTBOUND",event,origin,signal});if(authorizedScope(event,decision)!==event.sourcetenant)throw new CoreError("AUTHORIZATION_DENIED");const digest=await eventDigest(event,dependencies.digest);assertOrigin(event,origin,dependencies.clock.now());const record={event,origin,digest};if(event.profile==="eventsdk/1.2"){if(!dependencies.outbox.recordFanoutInTransaction)throw new CoreError("ADAPTER_CAPABILITY_REQUIRED");await dependencies.outbox.recordFanoutInTransaction(tx,{...record,logicalDigest:await logicalEventDigest(event,dependencies.digest),deliveryId:event.deliveryid},signal)}else await dependencies.outbox.recordInTransaction(tx,record,signal)})}async function refreshOrigin(event,previous,clock,signal,port){const verified=port?immutableSnapshot(await port.refresh(event,previous,signal)):previous;assertOrigin(event,verified,clock.now());return verified}async function publishClaim(claim,deps,options){try{return await boundedOperation(options,async signal=>{assertLiveLease(claim.lease,deps.clock.now());await assertDeliveryIdentity(claim.event,deps.digest);if(await eventDigest(claim.event,deps.digest)!==claim.digest)throw new CoreError("EVENT_ID_CONFLICT");const origin=await refreshOrigin(claim.event,claim.origin,deps.clock,signal,deps.originRefresh);const decision=await deps.authorization.authorize({phase:"OUTBOUND",event:claim.event,origin,signal});if(authorizedScope(claim.event,decision)!==claim.event.sourcetenant)throw new CoreError("AUTHORIZATION_DENIED");const messageId=await eventMessageId(claim.event,deps.digest);assertOrigin(claim.event,origin,deps.clock.now());assertLiveLease(claim.lease,deps.clock.now());const ack=await deps.publisher.publish(claim.event,{messageId,signal});return{status:"PUBLISHED",ack}})}catch(error){if(error instanceof CoreError&&["AUTHORIZATION_DENIED","AUTHORIZATION_UNKNOWN","ORIGIN_MISMATCH","EVENT_ID_CONFLICT"].includes(error.code)){return{status:"HOLD",reasonCode:error.code}}const retry=decideRetry(claim.attempt,deps.clock.now(),options.retry,deps.random);return retry.kind==="RETRY"?{status:"UNKNOWN",nextAttemptAt:retry.nextAttemptAt}:{status:"HOLD",reasonCode:"PUBLISH_UNKNOWN_RETRY_EXHAUSTED"}}}async function relayOutbox(deps,options){if(!Number.isSafeInteger(options.batchSize)||options.batchSize<1||options.batchSize>1e3||!Number.isFinite(options.leaseMs)||options.leaseMs<=options.timeoutMs)throw new CoreError("INVALID_CONFIGURATION");const claims=await boundedOperation(options,signal=>deps.outbox.claimReady({limit:options.batchSize,now:deps.clock.now(),leaseMs:options.leaseMs,signal}));if(claims.length>options.batchSize)throw new CoreError("INVALID_CONFIGURATION");const summary={published:0,unknown:0,held:0};const immutableClaims=immutableSnapshot(claims);for(const raw of immutableClaims){const claim=immutableSnapshot(raw);assertNotAborted(options.signal);assertLiveLease(claim.lease,deps.clock.now());if(claim.event.profile==="eventsdk/1.2"&&!deps.outbox.settleFanoutPublish)throw new CoreError("ADAPTER_CAPABILITY_REQUIRED");const outcome=await publishClaim(claim,deps,options);await boundedOperation({timeoutMs:options.timeoutMs},signal=>{assertLiveLease(claim.lease,deps.clock.now());if(claim.event.profile==="eventsdk/1.2"){if(!deps.outbox.settleFanoutPublish)throw new CoreError("ADAPTER_CAPABILITY_REQUIRED");return deps.outbox.settleFanoutPublish(claim.event,claim.lease,outcome,signal)}return deps.outbox.settlePublish(claim.event,claim.lease,outcome,signal)});if(outcome.status==="PUBLISHED")summary.published+=1;else if(outcome.status==="UNKNOWN")summary.unknown+=1;else summary.held+=1}return summary}import{parseCloudEvent as parseCloudEvent2}from"@eventsdk/sdk/contracts";import{parseBusinessReceipt}from"@eventsdk/sdk/contracts";function receivedReceipt(event,deliveryRef,consumerRef,targetScope,clock,ids){return parseBusinessReceipt({receiptRef:ids.next(),originSource:event.source,originEventId:event.id,deliveryRef,consumerRef,targetScope,disposition:"RECEIVED",recordedAt:new Date(clock.now()).toISOString(),revision:1})}async function persistAdmission(record,inbox,digest,signal){if(record.event.profile!=="eventsdk/1.2")return inbox.persistAccepted(record,signal);if(!inbox.persistFanoutAccepted)throw new CoreError("ADAPTER_CAPABILITY_REQUIRED");return inbox.persistFanoutAccepted({...record,logicalDigest:await logicalEventDigest(record.event,digest),deliveryId:record.event.deliveryid},signal)}async function quarantine(input,deps,reasonCode,signal){await deps.inbox.persistQuarantine({deliveryRef:input.deliveryRef,consumerRef:input.consumerRef,reasonCode,recordedAt:new Date(deps.clock.now()).toISOString()},signal);if(reasonCode==="AUTHORIZATION_UNKNOWN")throw new CoreError("AUTHORIZATION_UNKNOWN");return{kind:"REJECTED",reasonCode}}async function admitVerified(event,input,deps,signal){let targetScope;try{if(event.audience!==deps.audience)throw new CoreError("ORIGIN_MISMATCH");assertOrigin(event,input.origin,deps.clock.now());await assertDeliveryIdentity(event,deps.digest);const decision=await deps.authorization.authorize({phase:"RECEIVE",event,origin:input.origin,consumerRef:input.consumerRef,signal});targetScope=authorizedScope(event,decision);assertOrigin(event,input.origin,deps.clock.now())}catch(error){if(!(error instanceof CoreError))throw error;return quarantine(input,deps,error.code,signal)}const receipt=receivedReceipt(event,input.deliveryRef,input.consumerRef,targetScope,deps.clock,deps.ids);const result=await persistAdmission({key:{source:event.source,id:event.id,consumerRef:input.consumerRef,targetScope},event,origin:input.origin,digest:await eventDigest(event,deps.digest),deliveryRef:input.deliveryRef,receipt},deps.inbox,deps.digest,signal);if(result.kind==="CONFLICT")return quarantine(input,deps,"EVENT_ID_CONFLICT",signal);return result}async function acceptDelivery(input,deps,options){input=immutableSnapshot(input);if(!input.consumerRef||!input.deliveryRef)throw new CoreError("INVALID_CONFIGURATION");return boundedOperation(options,async signal=>{let event;try{event=parseCloudEvent2(input.event)}catch{return quarantine(input,deps,"INVALID_CONTRACT",signal)}return admitVerified(event,input,deps,signal)})}import{parseBusinessReceipt as parseBusinessReceipt4}from"@eventsdk/sdk/contracts";import{canonicalJson as canonicalJson3,parseBusinessReceipt as parseBusinessReceipt2}from"@eventsdk/sdk/contracts";var transitions={RECEIVED:["APPLIED","REJECTED","HOLD","UNKNOWN"],HOLD:["APPLIED","REJECTED","HOLD","UNKNOWN"],UNKNOWN:["APPLIED","REJECTED","HOLD"],APPLIED:[],REJECTED:[]};function assertReceiptTransition(previous,next){const identity=["receiptRef","originSource","originEventId","deliveryRef","consumerRef","targetScope"];if(identity.some(field=>previous[field]!==next[field]))throw new CoreError("RECEIPT_MISMATCH");if(next.revision!==previous.revision+1||!transitions[previous.disposition].includes(next.disposition)){throw new CoreError("INVALID_TRANSITION")}}function classifyReceiptCommit(previous,next){parseBusinessReceipt2(previous);parseBusinessReceipt2(next);if(previous.disposition==="HOLD"&&canonicalJson3(previous)===canonicalJson3(next)){return"UNCHANGED"}assertReceiptTransition(previous,next);return"TRANSITION"}import{parseBusinessReceipt as parseBusinessReceipt3,parseCloudEvent as parseCloudEvent3}from"@eventsdk/sdk/contracts";async function validateClaim(claim,digest){parseCloudEvent3(claim.event);await assertDeliveryIdentity(claim.event,digest);parseBusinessReceipt3(claim.receipt);if(claim.key.source!==claim.event.source||claim.key.id!==claim.event.id||claim.receipt.originSource!==claim.event.source||claim.receipt.originEventId!==claim.event.id||claim.receipt.consumerRef!==claim.key.consumerRef||claim.receipt.targetScope!==claim.key.targetScope||claim.receipt.deliveryRef!==claim.deliveryRef)throw new CoreError("RECEIPT_MISMATCH");if(claim.receipt.disposition==="UNKNOWN")throw new CoreError("RECOVERY_REQUIRED");if(claim.receipt.disposition==="APPLIED"||claim.receipt.disposition==="REJECTED"){throw new CoreError("INVALID_TRANSITION")}if(await eventDigest(claim.event,digest)!==claim.digest)throw new CoreError("EVENT_ID_CONFLICT")}import{canonicalJson as canonicalJson4,parseResultRef}from"@eventsdk/sdk/contracts";async function readAuthorizedResult(request,reader,authorization,digest,signal,clock){request=immutableSnapshot(request);assertNotAborted(signal);assertOrigin(request.event,request.origin,clock.now());const reference=parseResultRef(request.reference);if(reference.sourceSystem!==request.event.serviceorigin)throw new CoreError("RESULT_MISMATCH");const decision=await authorization.authorize({phase:"RESULT_READ",event:request.event,origin:request.origin,consumerRef:request.consumerRef,targetScope:request.targetScope,resultRef:reference,signal});if(authorizedScope(request.event,decision)!==request.targetScope)throw new CoreError("TARGET_SCOPE_CHANGED");assertNotAborted(signal);assertOrigin(request.event,request.origin,clock.now());const raw=await reader.read(request.reference,{event:request.event,origin:request.origin,targetScope:request.targetScope,signal});if(!raw)throw new CoreError("RECOVERY_REQUIRED");const snapshot=immutableSnapshot(raw);parseResultRef(snapshot.reference);const fields=["sourceSystem","resourceType","resourceId","revision","digest","evidenceRef"];if(fields.some(field=>snapshot.reference[field]!==request.reference[field])||`sha256:${await digest.sha256(canonicalJson4(snapshot.value))}`!==request.reference.digest){throw new CoreError("RESULT_MISMATCH")}assertNotAborted(signal);assertOrigin(request.event,request.origin,clock.now());return snapshot}import{canonicalJson as canonicalJson6}from"@eventsdk/sdk/contracts";import{canonicalJson as canonicalJson5,parseResultRef as parseResultRef2}from"@eventsdk/sdk/contracts";function resultObject(value){if(value===null||typeof value!=="object"||Array.isArray(value))throw new CoreError("INVALID_DOMAIN_RESULT");const prototype=Object.getPrototypeOf(value);if(prototype!==Object.prototype&&prototype!==null)throw new CoreError("INVALID_DOMAIN_RESULT");for(const key of Reflect.ownKeys(value)){const descriptor=Object.getOwnPropertyDescriptor(value,key);if(typeof key!=="string"||!descriptor?.enumerable||!("value"in descriptor)){throw new CoreError("INVALID_DOMAIN_RESULT")}}return value}function appliedResult(value){if(Object.keys(value).some(key=>key!=="disposition"&&key!=="resultRef"))throw new CoreError("INVALID_DOMAIN_RESULT");if(!Object.hasOwn(value,"resultRef"))return Object.freeze({disposition:"APPLIED"});resultObject(value.resultRef);canonicalJson5(value.resultRef);const reference=parseResultRef2(value.resultRef);return immutableSnapshot({disposition:"APPLIED",resultRef:reference})}function normalizeDomainApplyResult(value){if(value===void 0)return Object.freeze({disposition:"APPLIED"});try{const result=resultObject(value);if(!Object.hasOwn(result,"disposition")||result.disposition==="APPLIED")return appliedResult(result);if(result.disposition!=="REJECTED"&&result.disposition!=="HOLD")throw new CoreError("INVALID_DOMAIN_RESULT");if(Object.keys(result).some(key=>key!=="disposition"&&key!=="reasonCode")||typeof result.reasonCode!=="string"||!/^[A-Z][A-Z0-9_]{0,63}$/.test(result.reasonCode)){throw new CoreError("INVALID_DOMAIN_RESULT")}return Object.freeze({disposition:result.disposition,reasonCode:result.reasonCode})}catch{throw new CoreError("INVALID_DOMAIN_RESULT")}}async function runDomainApply(tx,claim,deps,snapshot,signal){let invoked=false;let observed;const operation=async()=>{if(invoked)throw new CoreError("INVALID_DOMAIN_RESULT");invoked=true;observed=normalizeDomainApplyResult(await deps.domain.apply(tx,claim,snapshot,signal));return observed};if(!deps.inbox.withDomainSavepoint){const outcome2=await operation();if(outcome2.disposition!=="APPLIED")throw new CoreError("ADAPTER_CAPABILITY_REQUIRED");return outcome2}const outcome=normalizeDomainApplyResult(await deps.inbox.withDomainSavepoint(tx,operation,signal));if(!invoked||!observed||canonicalJson6(outcome)!==canonicalJson6(observed))throw new CoreError("INVALID_DOMAIN_RESULT");return outcome}function dispositionReceipt(claim,disposition,clock,reasonCode,resultRef){const{reasonCode:_previousReason,resultRef:_previousResult,...previous}=claim.receipt;const next={...previous,...reasonCode?{reasonCode}:{},...resultRef?{resultRef}:{},disposition,revision:claim.receipt.revision+1,recordedAt:new Date(clock.now()).toISOString()};assertReceiptTransition(claim.receipt,next);return parseBusinessReceipt4(next)}async function applyAuthorizedDomain(tx,claim,deps,snapshot,signal){assertNotAborted(signal);assertOrigin(claim.event,claim.origin,deps.clock.now());assertLiveLease(claim.lease,deps.clock.now());const outcome=await runDomainApply(tx,claim,deps,snapshot,signal);assertNotAborted(signal);assertOrigin(claim.event,claim.origin,deps.clock.now());assertLiveLease(claim.lease,deps.clock.now());if(outcome.disposition==="APPLIED"&&outcome.resultRef&&outcome.resultRef.sourceSystem!==claim.event.audience){throw new CoreError("RESULT_MISMATCH")}if(outcome.disposition==="HOLD"&&claim.receipt.disposition==="HOLD"&&claim.receipt.reasonCode===outcome.reasonCode)return claim.receipt;const receipt=outcome.disposition==="APPLIED"?dispositionReceipt(claim,"APPLIED",deps.clock,void 0,outcome.resultRef):dispositionReceipt(claim,outcome.disposition,deps.clock,outcome.reasonCode);await deps.inbox.completeInTransaction(tx,claim,receipt,signal);return receipt}async function applyTransaction(claim,deps,snapshot,signal){return deps.inbox.transact(claim,async tx=>{assertLiveLease(claim.lease,deps.clock.now());const decision=await deps.authorization.authorizeInTransaction(tx,{phase:"APPLY",event:claim.event,origin:claim.origin,consumerRef:claim.key.consumerRef,targetScope:claim.key.targetScope,signal});if(decision.decision!=="ALLOW"){if(decision.decision==="UNKNOWN"&&claim.receipt.disposition==="HOLD")return claim.receipt;const receipt=dispositionReceipt(claim,decision.decision==="DENY"?"REJECTED":"HOLD",deps.clock,/^[A-Z][A-Z0-9_]{0,63}$/.test(decision.reasonCode)?decision.reasonCode:"AUTHORIZATION_UNAVAILABLE");await deps.inbox.completeInTransaction(tx,claim,receipt,signal);return receipt}if(authorizedScope(claim.event,decision)!==claim.key.targetScope)throw new CoreError("TARGET_SCOPE_CHANGED");return applyAuthorizedDomain(tx,claim,deps,snapshot,signal)},signal)}async function applyDelivery(claim,deps,options,readback){claim=immutableSnapshot(claim);return boundedOperation(options,async signal=>{await validateClaim(claim,deps.digest);assertLiveLease(claim.lease,deps.clock.now());const origin=await refreshOrigin(claim.event,claim.origin,deps.clock,signal,deps.originRefresh);claim=immutableSnapshot({...claim,origin});let snapshot;if(readback)snapshot=await readAuthorizedResult({reference:readback.reference,event:claim.event,origin:claim.origin,consumerRef:claim.key.consumerRef,targetScope:claim.key.targetScope},readback.reader,readback.authorization,readback.digest,signal,deps.clock);return applyTransaction(claim,deps,snapshot,signal)})}import{parseBusinessReceipt as parseBusinessReceipt5}from"@eventsdk/sdk/contracts";async function recoverReceipt(key,deliveryRef,reader,options){key=immutableSnapshot({source:key.source,id:key.id,consumerRef:key.consumerRef,targetScope:key.targetScope});return boundedOperation(options,async signal=>{const raw=await reader.read(key,deliveryRef,signal);assertNotAborted(signal);if(!raw)return{status:"WAIT",receipt:null};const receipt=immutableSnapshot(parseBusinessReceipt5(raw));if(receipt.originSource!==key.source||receipt.originEventId!==key.id||receipt.consumerRef!==key.consumerRef||receipt.targetScope!==key.targetScope||receipt.deliveryRef!==deliveryRef)throw new CoreError("RECEIPT_MISMATCH");return{status:["APPLIED","REJECTED"].includes(receipt.disposition)?"RESOLVED":"WAIT",receipt}})}import{parseBusinessReceipt as parseBusinessReceipt6}from"@eventsdk/sdk/contracts";async function recoverReceiptByIdentity(key,reader,options){key=immutableSnapshot({source:key.source,id:key.id,consumerRef:key.consumerRef,targetScope:key.targetScope});if(Object.values(key).some(part=>typeof part!=="string"||part.length===0)){throw new CoreError("INVALID_CONFIGURATION")}return boundedOperation(options,async signal=>{const raw=await reader.readByIdentity(key,signal);assertNotAborted(signal);if(!raw)return{status:"WAIT",receipt:null};const receipt=immutableSnapshot(parseBusinessReceipt6(raw));if(receipt.originSource!==key.source||receipt.originEventId!==key.id||receipt.consumerRef!==key.consumerRef||receipt.targetScope!==key.targetScope){throw new CoreError("RECEIPT_MISMATCH")}return{status:receipt.disposition==="APPLIED"||receipt.disposition==="REJECTED"?"RESOLVED":"WAIT",receipt}})}async function stageEventLogPage(cursor,limit,source,checkpoint,options){if(!Number.isSafeInteger(limit)||limit<1||limit>1e3)throw new CoreError("INVALID_CONFIGURATION");return boundedOperation(options,async signal=>{const page=immutableSnapshot(await source.readAfter(cursor,limit,signal));if(page.kind==="GAP"){await checkpoint.recordGap(cursor,page.oldestAvailableCursor,signal);return"GAP"}if(page.items.length>limit||page.items.length>0&&page.nextCursor===cursor||page.items.some(item=>!item.revision||!item.commitEvidenceRef||!item.cursor)){throw new CoreError("INVALID_CONFIGURATION")}await checkpoint.stageAndAdvance(cursor,page,signal);return"PAGE"})}import{canonicalJson as canonicalJson7}from"@eventsdk/sdk/contracts";async function recoverGap(source,scope,expectedWatermark,port,options){return boundedOperation(options,async signal=>{const raw=await port.readAuthorized(source,scope,signal);assertNotAborted(signal);const snapshot=immutableSnapshot(raw);if(!snapshot)throw new CoreError("RECOVERY_REQUIRED");if(snapshot.source!==source||snapshot.scope!==scope||[snapshot.source,snapshot.scope,snapshot.revision,snapshot.watermark,snapshot.evidenceRef].some(reference=>typeof reference!=="string"||reference.length===0))throw new CoreError("RESULT_MISMATCH");canonicalJson7(snapshot.value);assertNotAborted(signal);await port.applyAndCheckpoint(expectedWatermark,snapshot,signal);assertNotAborted(signal);return snapshot})}async function replayDeadLetter(entry,port,authorization,options){entry=immutableSnapshot(entry);return boundedOperation(options,signal=>port.transactReplay(entry,async(tx,claim)=>{if(inboxKey(entry.key)!==inboxKey(claim.key)||entry.originalDeliveryRef!==claim.deliveryRef){throw new CoreError("RECEIPT_MISMATCH")}if(claim.receipt.disposition==="UNKNOWN")throw new CoreError("RECOVERY_REQUIRED");if(claim.receipt.disposition==="APPLIED"||claim.receipt.disposition==="REJECTED"){throw new CoreError("INVALID_TRANSITION")}const decision=await authorization.authorizeInTransaction(tx,{phase:"APPLY",event:claim.event,origin:claim.origin,consumerRef:claim.key.consumerRef,targetScope:claim.key.targetScope,signal});if(authorizedScope(claim.event,decision)!==claim.key.targetScope)throw new CoreError("TARGET_SCOPE_CHANGED");await port.requeueInTransaction(tx,claim,signal)},signal))}async function observeDeliveryHealth(port,sink,options){const health=await boundedOperation(options,signal=>port.read(signal));if(!Number.isFinite(health.observedAt)||health.oldestPendingAt!==null&&!Number.isFinite(health.oldestPendingAt)){throw new CoreError("INVALID_CONFIGURATION")}const gauges={outbox_pending:health.outboxPending,outbox_oldest_age_ms:health.oldestPendingAt===null?0:Math.max(0,health.observedAt-health.oldestPendingAt),consumer_lag:health.consumerLag,retry_pending:health.retryPending,quarantined:health.quarantined,unresolved_receipts:health.unresolvedReceipts,gaps:health.gaps,authorization_denials:health.authorizationDenials};if(health.brokerStoredBytes!==void 0)gauges.broker_stored_bytes=health.brokerStoredBytes;if(health.brokerQuotaBytes!==void 0)gauges.broker_quota_bytes=health.brokerQuotaBytes;if(health.bridgeUnconfirmed!==void 0)gauges.bridge_unconfirmed=health.bridgeUnconfirmed;if(Object.values(gauges).some(value=>!Number.isFinite(value)||value<0))throw new CoreError("INVALID_CONFIGURATION");for(const[name,value]of Object.entries(gauges))sink.gauge(`eventsdk_${name}`,value);return health}import{parseBusinessReceipt as parseBusinessReceipt7}from"@eventsdk/sdk/contracts";function assertCorrelated(claim,receipt){if(receipt.receiptRef!==claim.receipt.receiptRef||receipt.revision<claim.receipt.revision||(claim.receipt.disposition==="APPLIED"||claim.receipt.disposition==="REJECTED")&&receipt.disposition!==claim.receipt.disposition||receipt.originSource!==claim.key.source||receipt.originEventId!==claim.key.id||receipt.consumerRef!==claim.key.consumerRef||receipt.targetScope!==claim.key.targetScope||receipt.deliveryRef!==claim.deliveryRef)throw new CoreError("RECEIPT_MISMATCH")}async function quarantineWork(claim,deps,reasonCode,signal){await deps.deadLetters.quarantine(claim,{ref:deps.ids.next(),key:claim.key,originalDeliveryRef:claim.deliveryRef,reasonCode,attempts:claim.attempt,recordedAt:new Date(deps.clock.now()).toISOString()},signal);return"QUARANTINED"}async function reconcileWork(claim,deps,options){return boundedOperation({timeoutMs:options.timeoutMs},async signal=>{const raw=await deps.receipts.readReceipt(claim.key,signal);if(!raw)throw new CoreError("RECOVERY_REQUIRED");const receipt=immutableSnapshot(parseBusinessReceipt7(raw));assertCorrelated(claim,receipt);if(receipt.disposition==="APPLIED"||receipt.disposition==="REJECTED")return receipt.disposition;const current={...claim,receipt};if(receipt.disposition==="UNKNOWN")return quarantineWork(current,deps,"OUTCOME_UNKNOWN_READBACK_REQUIRED",signal);const retry=decideRetry(claim.attempt,deps.clock.now(),options.retry,deps.random);if(retry.kind==="EXHAUSTED")return quarantineWork(current,deps,"RETRY_EXHAUSTED",signal);await deps.work.defer(claim.key,claim.lease,receipt,retry.nextAttemptAt,"APPLY_NOT_TERMINAL",signal);return"RETRY"})}async function runClaim(claim,deps,options){try{assertLiveLease(claim.lease,deps.clock.now());if(claim.receipt.disposition==="RECEIVED"||claim.receipt.disposition==="HOLD"){try{await boundedOperation(options,signal=>deps.process(claim,{timeoutMs:options.timeoutMs,signal}))}catch{}}return await reconcileWork(claim,deps,options)}catch{return"UNRESOLVED"}}async function runInboxWorker(deps,options){if(!Number.isSafeInteger(options.batchSize)||options.batchSize<1||options.batchSize>1e3||!Number.isFinite(options.leaseMs)||options.leaseMs<=options.timeoutMs)throw new CoreError("INVALID_CONFIGURATION");const claims=immutableSnapshot(await boundedOperation(options,signal=>deps.work.claimReady({limit:options.batchSize,now:deps.clock.now(),leaseMs:options.leaseMs,signal})));if(claims.length>options.batchSize)throw new CoreError("INVALID_CONFIGURATION");const summary={APPLIED:0,REJECTED:0,RETRY:0,QUARANTINED:0,UNRESOLVED:0};for(const claim of claims){assertNotAborted(options.signal);if(!Number.isSafeInteger(claim.attempt)||claim.attempt<1)throw new CoreError("INVALID_CONFIGURATION");summary[await runClaim(claim,deps,options)]+=1}return summary}import{parseCloudEvent as parseCloudEvent4,parseFanoutEventDraft as parseFanoutEventDraft2}from"@eventsdk/sdk/contracts";async function prepareFanoutDelivery(input,route,digest){const fact=immutableSnapshot(parseFanoutEventDraft2(input));const keys=Object.keys(route);if(keys.length!==4||keys.some(k=>!["audience","connectionref","grantref","grantversion"].includes(k)))throw new CoreError("INVALID_CONFIGURATION");const draft={...fact,...immutableSnapshot(route)};const event=parseCloudEvent4({...draft,deliveryid:await deriveDeliveryId(draft,digest)});if(event.profile!=="eventsdk/1.2")throw new CoreError("INVALID_CONFIGURATION");return event}async function recordFanoutEvent(tx,draft,recipients,deps,options){const fact=immutableSnapshot(parseFanoutEventDraft2(draft));const targets=immutableSnapshot(recipients);if(targets.length<1||targets.length>1e3)throw new CoreError("INVALID_CONFIGURATION");if(!deps.outbox.recordFanoutInTransaction)throw new CoreError("ADAPTER_CAPABILITY_REQUIRED");return boundedOperation(options,async signal=>{const events=[];const deliveryIds=new Set;for(const target of targets){signal.throwIfAborted();const event=await prepareFanoutDelivery(fact,target.route,deps.digest);if(deliveryIds.has(event.deliveryid))throw new CoreError("INVALID_CONFIGURATION");deliveryIds.add(event.deliveryid);events.push(event)}for(const[index,target]of targets.entries()){const event=events[index];if(!event)throw new CoreError("INVALID_CONFIGURATION");await recordEvent(tx,event,target.origin,deps,{...options,signal})}return events})}import{canonicalJson as canonicalJson8,parseTenantContext}from"@eventsdk/sdk/contracts";async function deriveExchangeConnectionRef(input,digest){const from=parseTenantContext(input.from),to=parseTenantContext(input.to);try{if(new URL(input.source).href.length>2048)throw new Error("source")}catch{throw new CoreError("INVALID_CONFIGURATION")}return`urn:eventsdk:connection:${await digest.sha256(canonicalJson8(["eventsdk-native-connection/1",input.source,from,to]))}`}import{parseOutboxRecoveryCommand}from"@eventsdk/sdk/contracts";async function authorizeOutboxRecovery(command,stored,deps,options){const record=immutableSnapshot(stored),input=immutableSnapshot(parseOutboxRecoveryCommand(command));return boundedOperation(options,async signal=>{const event=record.event;if(event.source!==input.source||event.id!==input.id||event.deliveryid!==input.deliveryid||record.status!=="HOLD"||record.generation!==input.expectedGeneration)throw new CoreError("RECOVERY_REQUIRED");await assertDeliveryIdentity(event,deps.digest);if(await eventDigest(event,deps.digest)!==record.digest)throw new CoreError("EVENT_ID_CONFLICT");const origin=await refreshOrigin(event,record.origin,deps.clock,signal,deps.originRefresh);const scope=authorizedScope(event,await deps.authorization.authorize({phase:"OUTBOUND",event,origin,signal}));if(scope!==event.sourcetenant)throw new CoreError("TARGET_SCOPE_CHANGED");return immutableSnapshot({event,digest:record.digest,generation:record.generation,origin,targetScope:scope})})}import{parseGapBaseline}from"@eventsdk/sdk/contracts";function assertGapBaselineBinding(event,value,targetScope){const baseline=parseGapBaseline(value);if(event.profile!=="eventsdk/1.2"||event.kind!=="EVENT"||baseline.source!==event.source||baseline.sourceTenant!==event.sourcetenant||baseline.targetService!==event.audience||baseline.connectionRef!==event.connectionref||baseline.grantRef!==event.grantref||baseline.grantVersion!==event.grantversion||baseline.createdAt!==event.time||targetScope!==void 0&&baseline.targetTenant!==targetScope)throw new CoreError("RESULT_MISMATCH")}export{CoreError,acceptDelivery,applyDelivery,assertDeliveryIdentity,assertGapBaselineBinding,assertLiveLease,assertNotAborted,assertReceiptTransition,authorizeOutboxRecovery,boundedOperation,classifyReceiptCommit,decideRetry,deriveDeliveryId,deriveExchangeConnectionRef,eventDigest,eventMessageId,fanoutLogicalEvent,inboxKey,logicalEventDigest,observeDeliveryHealth,prepareFanoutDelivery,readAuthorizedResult,recordEvent,recordFanoutEvent,recoverGap,recoverReceipt,recoverReceiptByIdentity,relayOutbox,replayDeadLetter,runInboxWorker,stageEventLogPage};