@openlup/platform 0.22.0 → 0.24.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.
Files changed (241) hide show
  1. package/CHANGELOG.md +440 -158
  2. package/README.md +141 -589
  3. package/dist/fulfillment/adapterConformance.js +1 -1
  4. package/dist/fulfillment/bindings.js +1 -1
  5. package/dist/fulfillment/contracts/conformance.d.ts +3 -1
  6. package/dist/fulfillment/contracts/dispatch.d.ts +45 -3
  7. package/dist/fulfillment/contracts/index.d.ts +3 -3
  8. package/dist/fulfillment/contracts/observation.d.ts +21 -1
  9. package/dist/fulfillment/contracts/readback.d.ts +21 -0
  10. package/dist/fulfillment/contracts/store.d.ts +3 -0
  11. package/dist/fulfillment/contracts/sync.d.ts +58 -2
  12. package/dist/fulfillment/dispatchProjection.d.ts +20 -1
  13. package/dist/fulfillment/dispatchProjection.js +97 -6
  14. package/dist/fulfillment/index.d.ts +3 -2
  15. package/dist/fulfillment/index.js +2 -2
  16. package/dist/fulfillment/migrations.d.ts +5 -0
  17. package/dist/fulfillment/migrations.js +1 -0
  18. package/dist/fulfillment/observationProjection.d.ts +24 -3
  19. package/dist/fulfillment/observationProjection.js +65 -12
  20. package/dist/fulfillment/omnipack/client.d.ts +3 -1
  21. package/dist/fulfillment/omnipack/client.js +31 -13
  22. package/dist/fulfillment/omnipack/index.d.ts +4 -1
  23. package/dist/fulfillment/omnipack/index.js +107 -45
  24. package/dist/fulfillment/omnipack/mappers.d.ts +7 -1
  25. package/dist/fulfillment/omnipack/mappers.js +24 -2
  26. package/dist/fulfillment/omnipack/observation.d.ts +11 -4
  27. package/dist/fulfillment/omnipack/observation.js +44 -29
  28. package/dist/fulfillment/omnipack/reconciliation.d.ts +15 -0
  29. package/dist/fulfillment/omnipack/reconciliation.js +55 -0
  30. package/dist/fulfillment/postgresDispatchStore.js +1 -1
  31. package/dist/fulfillment/postgresShipmentSpine.d.ts +8 -1
  32. package/dist/fulfillment/postgresShipmentSpine.js +17 -3
  33. package/dist/fulfillment/postgresStockSyncPort.js +6 -3
  34. package/dist/fulfillment/providerDispatchAcceptance.d.ts +1 -0
  35. package/dist/fulfillment/providerDispatchAcceptance.js +8 -2
  36. package/dist/fulfillment/providerDispatchWorker.d.ts +51 -0
  37. package/dist/fulfillment/providerDispatchWorker.js +65 -20
  38. package/dist/fulfillment/providerReconciliationWorker.d.ts +27 -19
  39. package/dist/fulfillment/providerReconciliationWorker.js +75 -19
  40. package/dist/fulfillment/providerStockSyncWorker.d.ts +5 -1
  41. package/dist/fulfillment/providerStockSyncWorker.js +229 -120
  42. package/dist/fulfillment/providerTrackingReferences.d.ts +3 -2
  43. package/dist/fulfillment/verifiedIngress.d.ts +38 -11
  44. package/dist/fulfillment/verifiedIngress.js +36 -8
  45. package/dist/invoicing/accountingCanonicalProviderLines.d.ts +5 -0
  46. package/dist/invoicing/accountingCanonicalProviderLines.js +104 -0
  47. package/dist/invoicing/accountingLineAllocation.d.ts +2 -0
  48. package/dist/invoicing/accountingLineAllocation.js +69 -0
  49. package/dist/invoicing/adapterConformance.d.ts +42 -0
  50. package/dist/invoicing/adapterConformance.js +296 -0
  51. package/dist/invoicing/artifacts.d.ts +7 -0
  52. package/dist/invoicing/artifacts.js +20 -0
  53. package/dist/invoicing/bindings.d.ts +46 -0
  54. package/dist/invoicing/bindings.js +69 -0
  55. package/dist/invoicing/capabilities.d.ts +11 -0
  56. package/dist/invoicing/capabilities.js +10 -0
  57. package/dist/invoicing/channelPolicy.d.ts +28 -0
  58. package/dist/invoicing/channelPolicy.js +27 -0
  59. package/dist/invoicing/continuity.d.ts +12 -0
  60. package/dist/invoicing/continuity.js +18 -0
  61. package/dist/invoicing/contracts/capabilities.d.ts +40 -0
  62. package/dist/invoicing/contracts/capabilities.js +1 -0
  63. package/dist/invoicing/contracts/companyLookup.d.ts +49 -0
  64. package/dist/invoicing/contracts/companyLookup.js +1 -0
  65. package/dist/invoicing/contracts/delivery.d.ts +74 -0
  66. package/dist/invoicing/contracts/delivery.js +1 -0
  67. package/dist/invoicing/contracts/facts.d.ts +110 -0
  68. package/dist/invoicing/contracts/facts.js +1 -0
  69. package/dist/invoicing/contracts/host.d.ts +245 -0
  70. package/dist/invoicing/contracts/host.js +1 -0
  71. package/dist/invoicing/contracts/index.d.ts +16 -0
  72. package/dist/invoicing/contracts/index.js +1 -0
  73. package/dist/invoicing/contracts/provider.d.ts +126 -0
  74. package/dist/invoicing/contracts/provider.js +1 -0
  75. package/dist/invoicing/contracts/settlement.d.ts +66 -0
  76. package/dist/invoicing/contracts/settlement.js +1 -0
  77. package/dist/invoicing/contracts/store.d.ts +277 -0
  78. package/dist/invoicing/contracts/store.js +1 -0
  79. package/dist/invoicing/contribution.d.ts +21 -0
  80. package/dist/invoicing/contribution.js +19 -0
  81. package/dist/invoicing/correction.d.ts +42 -0
  82. package/dist/invoicing/correction.js +44 -0
  83. package/dist/invoicing/delivery.d.ts +85 -0
  84. package/dist/invoicing/delivery.js +79 -0
  85. package/dist/invoicing/documentHistory.d.ts +50 -0
  86. package/dist/invoicing/documentHistory.js +213 -0
  87. package/dist/invoicing/documentSync.d.ts +24 -0
  88. package/dist/invoicing/documentSync.js +26 -0
  89. package/dist/invoicing/dutyCollector.d.ts +15 -0
  90. package/dist/invoicing/dutyCollector.js +35 -0
  91. package/dist/invoicing/fulfillmentTrigger.d.ts +56 -0
  92. package/dist/invoicing/fulfillmentTrigger.js +90 -0
  93. package/dist/invoicing/handoff.d.ts +37 -0
  94. package/dist/invoicing/handoff.js +62 -0
  95. package/dist/invoicing/index.d.ts +39 -0
  96. package/dist/invoicing/index.js +37 -0
  97. package/dist/invoicing/issue.d.ts +39 -0
  98. package/dist/invoicing/issue.js +55 -0
  99. package/dist/invoicing/migrations.d.ts +48 -0
  100. package/dist/invoicing/migrations.js +25 -0
  101. package/dist/invoicing/nativeUnsupported.d.ts +9 -0
  102. package/dist/invoicing/nativeUnsupported.js +22 -0
  103. package/dist/invoicing/paymentReadback.d.ts +20 -0
  104. package/dist/invoicing/paymentReadback.js +47 -0
  105. package/dist/invoicing/postgresInvoiceStore.d.ts +55 -0
  106. package/dist/invoicing/postgresInvoiceStore.js +344 -0
  107. package/dist/invoicing/readModel.d.ts +74 -0
  108. package/dist/invoicing/readModel.js +90 -0
  109. package/dist/invoicing/readback.d.ts +4 -0
  110. package/dist/invoicing/readback.js +30 -0
  111. package/dist/invoicing/reversal.d.ts +37 -0
  112. package/dist/invoicing/reversal.js +28 -0
  113. package/dist/invoicing/sellerRevision.d.ts +19 -0
  114. package/dist/invoicing/sellerRevision.js +14 -0
  115. package/dist/invoicing/settlementSync.d.ts +18 -0
  116. package/dist/invoicing/settlementSync.js +32 -0
  117. package/dist/invoicing/snapshot.d.ts +52 -0
  118. package/dist/invoicing/snapshot.js +141 -0
  119. package/dist/subscriptions/automaticRenewal.d.ts +44 -0
  120. package/dist/subscriptions/automaticRenewal.js +81 -0
  121. package/dist/subscriptions/automaticRenewalExecution.d.ts +21 -0
  122. package/dist/subscriptions/automaticRenewalExecution.js +44 -0
  123. package/dist/subscriptions/contracts/commands.d.ts +115 -0
  124. package/dist/subscriptions/contracts/commands.js +1 -0
  125. package/dist/subscriptions/contracts/dunning.d.ts +133 -0
  126. package/dist/subscriptions/contracts/dunning.js +1 -0
  127. package/dist/subscriptions/contracts/index.d.ts +6 -0
  128. package/dist/subscriptions/contracts/index.js +1 -0
  129. package/dist/subscriptions/contracts/messages.d.ts +43 -0
  130. package/dist/subscriptions/contracts/messages.js +1 -0
  131. package/dist/subscriptions/contracts/renewal.d.ts +533 -0
  132. package/dist/subscriptions/contracts/renewal.js +1 -0
  133. package/dist/subscriptions/contracts/stockWait.d.ts +73 -0
  134. package/dist/subscriptions/contracts/stockWait.js +1 -0
  135. package/dist/subscriptions/index.d.ts +39 -0
  136. package/dist/subscriptions/index.js +17 -0
  137. package/dist/subscriptions/paymentOutcomes.d.ts +8 -0
  138. package/dist/subscriptions/paymentOutcomes.js +27 -0
  139. package/dist/subscriptions/postgresRenewalStore.d.ts +20 -0
  140. package/dist/subscriptions/postgresRenewalStore.js +61 -0
  141. package/dist/subscriptions/postgresRetryStore.d.ts +78 -0
  142. package/dist/subscriptions/postgresRetryStore.js +142 -0
  143. package/dist/subscriptions/renewalCycleFailureMechanism.d.ts +34 -0
  144. package/dist/subscriptions/renewalCycleFailureMechanism.js +79 -0
  145. package/dist/subscriptions/renewalCycleMechanism.d.ts +46 -0
  146. package/dist/subscriptions/renewalCycleMechanism.js +157 -0
  147. package/dist/subscriptions/renewalCycleRefusalMechanism.d.ts +41 -0
  148. package/dist/subscriptions/renewalCycleRefusalMechanism.js +160 -0
  149. package/dist/subscriptions/renewalIdentity.d.ts +3 -0
  150. package/dist/subscriptions/renewalIdentity.js +4 -0
  151. package/package.json +23 -3
  152. package/release-gates.json +74 -7
  153. package/sql/20260809210000_accounting_document_rail.sql +889 -0
  154. package/sql/20260811150000_accounting_payout_rail.sql +333 -0
  155. package/sql/20260812130000_accounting_document_lifecycle_rail.sql +460 -0
  156. package/sql/20261022160000_subscription_retry_lifecycle.sql +328 -0
  157. package/sql/20261022165000_fulfillment_stock_evidence_replay_reopen.sql +30 -0
  158. package/sql/20261022190000_invoicing_durable_duties.sql +494 -0
  159. package/sql/20261022191000_invoicing_document_effects.sql +249 -0
  160. package/sql/20261022192000_invoicing_payment_decoupling.sql +144 -0
  161. package/sql/20261022195000_invoicing_seller_revision.sql +65 -0
  162. package/src/fulfillment/adapterConformance.ts +1 -1
  163. package/src/fulfillment/bindings.ts +1 -1
  164. package/src/fulfillment/contracts/conformance.ts +3 -1
  165. package/src/fulfillment/contracts/dispatch.ts +24 -5
  166. package/src/fulfillment/contracts/index.ts +3 -3
  167. package/src/fulfillment/contracts/observation.ts +11 -3
  168. package/src/fulfillment/contracts/readback.ts +13 -0
  169. package/src/fulfillment/contracts/store.ts +1 -0
  170. package/src/fulfillment/contracts/sync.ts +13 -2
  171. package/src/fulfillment/dispatchProjection.ts +94 -7
  172. package/src/fulfillment/index.ts +3 -2
  173. package/src/fulfillment/migrations.ts +1 -0
  174. package/src/fulfillment/observationProjection.ts +64 -13
  175. package/src/fulfillment/omnipack/client.ts +32 -13
  176. package/src/fulfillment/omnipack/index.ts +99 -39
  177. package/src/fulfillment/omnipack/mappers.ts +23 -2
  178. package/src/fulfillment/omnipack/observation.ts +45 -27
  179. package/src/fulfillment/omnipack/reconciliation.ts +56 -0
  180. package/src/fulfillment/postgresDispatchStore.ts +1 -1
  181. package/src/fulfillment/postgresShipmentSpine.ts +21 -4
  182. package/src/fulfillment/postgresStockSyncPort.ts +6 -3
  183. package/src/fulfillment/providerDispatchAcceptance.ts +9 -3
  184. package/src/fulfillment/providerDispatchWorker.ts +61 -20
  185. package/src/fulfillment/providerReconciliationWorker.ts +81 -25
  186. package/src/fulfillment/providerStockSyncWorker.ts +222 -126
  187. package/src/fulfillment/providerTrackingReferences.ts +3 -2
  188. package/src/fulfillment/verifiedIngress.ts +44 -11
  189. package/src/invoicing/accountingCanonicalProviderLines.ts +134 -0
  190. package/src/invoicing/accountingLineAllocation.ts +69 -0
  191. package/src/invoicing/adapterConformance.ts +249 -0
  192. package/src/invoicing/artifacts.ts +19 -0
  193. package/src/invoicing/bindings.ts +80 -0
  194. package/src/invoicing/capabilities.ts +9 -0
  195. package/src/invoicing/channelPolicy.ts +50 -0
  196. package/src/invoicing/continuity.ts +15 -0
  197. package/src/invoicing/contracts/capabilities.ts +15 -0
  198. package/src/invoicing/contracts/companyLookup.ts +13 -0
  199. package/src/invoicing/contracts/delivery.ts +24 -0
  200. package/src/invoicing/contracts/facts.ts +71 -0
  201. package/src/invoicing/contracts/host.ts +84 -0
  202. package/src/invoicing/contracts/index.ts +16 -0
  203. package/src/invoicing/contracts/provider.ts +78 -0
  204. package/src/invoicing/contracts/settlement.ts +39 -0
  205. package/src/invoicing/contracts/store.ts +102 -0
  206. package/src/invoicing/contribution.ts +28 -0
  207. package/src/invoicing/correction.ts +56 -0
  208. package/src/invoicing/delivery.ts +122 -0
  209. package/src/invoicing/documentHistory.ts +301 -0
  210. package/src/invoicing/documentSync.ts +51 -0
  211. package/src/invoicing/dutyCollector.ts +31 -0
  212. package/src/invoicing/fulfillmentTrigger.ts +144 -0
  213. package/src/invoicing/handoff.ts +71 -0
  214. package/src/invoicing/index.ts +39 -0
  215. package/src/invoicing/issue.ts +64 -0
  216. package/src/invoicing/migrations.ts +25 -0
  217. package/src/invoicing/nativeUnsupported.ts +24 -0
  218. package/src/invoicing/paymentReadback.ts +70 -0
  219. package/src/invoicing/postgresInvoiceStore.ts +334 -0
  220. package/src/invoicing/readModel.ts +80 -0
  221. package/src/invoicing/readback.ts +26 -0
  222. package/src/invoicing/reversal.ts +34 -0
  223. package/src/invoicing/sellerRevision.ts +20 -0
  224. package/src/invoicing/settlementSync.ts +37 -0
  225. package/src/invoicing/snapshot.ts +192 -0
  226. package/src/subscriptions/automaticRenewal.ts +87 -0
  227. package/src/subscriptions/automaticRenewalExecution.ts +39 -0
  228. package/src/subscriptions/contracts/commands.ts +46 -0
  229. package/src/subscriptions/contracts/dunning.ts +48 -0
  230. package/src/subscriptions/contracts/index.ts +6 -0
  231. package/src/subscriptions/contracts/messages.ts +18 -0
  232. package/src/subscriptions/contracts/renewal.ts +325 -0
  233. package/src/subscriptions/contracts/stockWait.ts +34 -0
  234. package/src/subscriptions/index.ts +24 -0
  235. package/src/subscriptions/paymentOutcomes.ts +23 -0
  236. package/src/subscriptions/postgresRenewalStore.ts +76 -0
  237. package/src/subscriptions/postgresRetryStore.ts +174 -0
  238. package/src/subscriptions/renewalCycleFailureMechanism.ts +119 -0
  239. package/src/subscriptions/renewalCycleMechanism.ts +225 -0
  240. package/src/subscriptions/renewalCycleRefusalMechanism.ts +215 -0
  241. package/src/subscriptions/renewalIdentity.ts +5 -0
@@ -0,0 +1,49 @@
1
+ import type { InvoiceProof, InvoiceUnsupported } from "./provider.js";
2
+ /** Injected registry seam. Host owns identifier validation, freshness and fallback;
3
+ * lookup evidence never overwrites checkout truth or becomes a renewal prerequisite.
4
+ * Carrier: accountingControlContracts lookup fields, generalized per A5 fit probe.
5
+ */
6
+ export interface InvoiceCompanyLookupPort {
7
+ lookup(input: {
8
+ readonly identifier: {
9
+ readonly scheme: string;
10
+ readonly value: string;
11
+ readonly country?: string;
12
+ };
13
+ readonly asOf: string;
14
+ readonly sourceRef: string;
15
+ }): Promise<{
16
+ readonly kind: "found" | "partial";
17
+ readonly identifier: {
18
+ readonly scheme: string;
19
+ readonly value: string;
20
+ readonly country?: string;
21
+ };
22
+ readonly legalName: string | null;
23
+ readonly registrationIds: readonly {
24
+ readonly scheme: string;
25
+ readonly value: string;
26
+ }[];
27
+ readonly address: {
28
+ readonly line1: string;
29
+ readonly postalCode: string;
30
+ readonly city: string;
31
+ readonly country: string;
32
+ } | null;
33
+ readonly taxRegistrations: readonly {
34
+ readonly scheme: string;
35
+ readonly status: "active" | "not_registered" | "exempt" | "unknown";
36
+ }[];
37
+ readonly sourceRef: string;
38
+ readonly proof: InvoiceProof;
39
+ } | {
40
+ readonly kind: "not_found";
41
+ readonly identifier: Parameters<InvoiceCompanyLookupPort["lookup"]>[0]["identifier"];
42
+ readonly sourceRef: string;
43
+ readonly proof: InvoiceProof;
44
+ } | {
45
+ readonly kind: "unknown";
46
+ readonly sourceRef: string;
47
+ readonly code: "unknown";
48
+ } | InvoiceUnsupported>;
49
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,74 @@
1
+ import type { InvoiceDocumentIdentity, InvoiceProof, InvoiceUnsupported } from "./provider.js";
2
+ /** Durable opaque references; signed URLs and downloaded bytes are transient. */
3
+ export type InvoiceArtifactResult = {
4
+ readonly kind: "found";
5
+ readonly identity: InvoiceDocumentIdentity;
6
+ readonly artifact: {
7
+ readonly kind: "pdf" | "structured_document" | "clearance_receipt";
8
+ readonly ref: string;
9
+ readonly owner: "provider" | "host_storage";
10
+ readonly mediaType: string;
11
+ readonly proof: InvoiceProof;
12
+ };
13
+ } | {
14
+ readonly kind: "absent";
15
+ readonly identity: InvoiceDocumentIdentity;
16
+ readonly evidence: InvoiceProof & {
17
+ readonly exact: true;
18
+ readonly complete: true;
19
+ readonly scope: {
20
+ readonly identity: InvoiceDocumentIdentity;
21
+ readonly kind: "pdf" | "structured_document" | "clearance_receipt";
22
+ readonly artifactRef: string | null;
23
+ };
24
+ };
25
+ } | {
26
+ readonly kind: "unknown";
27
+ readonly identity: InvoiceDocumentIdentity;
28
+ readonly code: "unknown";
29
+ } | InvoiceUnsupported;
30
+ /** Observation only; unsupported is never not_required. No clearance submission. */
31
+ export type InvoiceClearanceObservation = {
32
+ readonly proof: InvoiceProof;
33
+ } & ({
34
+ readonly state: "accepted";
35
+ readonly reference: string;
36
+ } | {
37
+ readonly state: "not_submitted" | "pending" | "rejected" | "not_required" | "unsupported";
38
+ readonly reference: string | null;
39
+ });
40
+ export interface InvoiceDeliveryPort {
41
+ /** Host M04 content/transport; provider acceptance is not inbox delivery.
42
+ * Preserve delivery/request keys, recipient, filename and bytes. Validate PDF
43
+ * type, size and signature before send; uncertain send must never repeat sending.
44
+ */
45
+ send(input: {
46
+ readonly deliveryRef: string;
47
+ readonly requestKey: string;
48
+ readonly attemptCount: number;
49
+ readonly documentRef: string;
50
+ readonly orderId: string;
51
+ readonly orderRef: string;
52
+ readonly invoiceRef: string;
53
+ readonly providerDocumentRef: string;
54
+ readonly clientRef: string | null;
55
+ readonly recipient: string;
56
+ readonly source: string | null;
57
+ readonly providerDocumentNumber: string | null;
58
+ readonly filename: string;
59
+ readonly content: Uint8Array;
60
+ readonly contentType: string;
61
+ }): Promise<{
62
+ readonly kind: "provider_accepted";
63
+ readonly receiptRef: string;
64
+ readonly proof: InvoiceProof;
65
+ } | {
66
+ readonly kind: "failed_before_send";
67
+ readonly retryable: boolean;
68
+ readonly code: "retryable" | "invalid_artifact";
69
+ } | {
70
+ readonly kind: "uncertain";
71
+ readonly code: "uncertain_delivery";
72
+ readonly receiptRef: string | null;
73
+ } | InvoiceUnsupported>;
74
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,110 @@
1
+ /** Frozen host facts; no catalogue, registry or country-policy reread on retry.
2
+ * Carrier: donor providerPorts snapshot and invoiceContracts LocalInvoiceSnapshot;
3
+ * native invoicing_install_facts adds dates/refs/policyVersion and explicit totals.
4
+ */
5
+ export interface InvoiceSeller {
6
+ readonly name: string;
7
+ readonly address: {
8
+ readonly line1: string;
9
+ readonly postalCode: string;
10
+ readonly city: string;
11
+ };
12
+ readonly taxIdentifier: {
13
+ readonly scheme: string;
14
+ readonly value: string;
15
+ };
16
+ readonly registrationIds?: readonly {
17
+ readonly scheme: string;
18
+ readonly value: string;
19
+ }[];
20
+ readonly bankAccount: string | null;
21
+ /** Opaque host routing reference, interpreted only by the selected adapter. */
22
+ readonly routingRef: string | null;
23
+ }
24
+ export interface InvoiceBuyer {
25
+ readonly name: string;
26
+ readonly email: string | null;
27
+ readonly taxIdentifier: {
28
+ readonly scheme: string;
29
+ readonly value: string;
30
+ } | null;
31
+ readonly companyName: string | null;
32
+ readonly address: {
33
+ readonly line1: string | null;
34
+ readonly postalCode: string | null;
35
+ readonly city: string | null;
36
+ readonly country: string | null;
37
+ } | null;
38
+ }
39
+ /** Safe integer minor amounts; taxRateBps is a rate, never a fiscal-support claim.
40
+ * Preserve array order and quantityUnit; no inferred shipping residual or FX.
41
+ */
42
+ export interface InvoiceLine {
43
+ readonly description: string;
44
+ readonly quantity: number;
45
+ readonly quantityUnit?: string;
46
+ readonly unitNetMinor: number;
47
+ readonly unitGrossMinor: number;
48
+ readonly totalNetMinor: number;
49
+ readonly totalTaxMinor: number;
50
+ readonly totalGrossMinor: number;
51
+ readonly taxRateBps: number;
52
+ readonly taxRateLabel?: string;
53
+ readonly positionKind: "item" | "delivery" | null;
54
+ readonly catalogTotalGrossMinor: number | null;
55
+ readonly discountAllocatedMinor: number | null;
56
+ readonly shippingGrossMinor: number | null;
57
+ readonly shippingDiscountMinor: number | null;
58
+ }
59
+ export interface InvoiceFacts {
60
+ readonly factRevision: string;
61
+ readonly policyVersion: string;
62
+ readonly refs: {
63
+ readonly orderId: string;
64
+ readonly orderRef: string;
65
+ readonly invoiceRef: string;
66
+ };
67
+ readonly dates: {
68
+ readonly issueDate: string;
69
+ readonly sellDate: string;
70
+ readonly handedOverAt: string | null;
71
+ readonly paymentCompletedAt: string | null;
72
+ };
73
+ /** Host-defined kind selected through the identifier/tax seam, never guessed. */
74
+ readonly documentKind: string;
75
+ readonly clearanceRequired: boolean;
76
+ readonly currency: string;
77
+ readonly buyer: InvoiceBuyer;
78
+ /** Claim projection only: the first durable claim freezes the seller; legacy obligations retain execution-time fallback. */
79
+ readonly seller?: InvoiceSeller;
80
+ readonly payment: {
81
+ readonly intentRef: string;
82
+ readonly providerRef: string | null;
83
+ readonly providerPaymentRef: string | null;
84
+ readonly amountMinor: number;
85
+ readonly currency: string;
86
+ readonly localSettlementState: "matched" | "unavailable";
87
+ };
88
+ readonly orderMoney: {
89
+ readonly subtotalMinor: number;
90
+ readonly discountMinor: number;
91
+ readonly shippingMinor: number;
92
+ readonly shippingDiscountMinor: number;
93
+ readonly totalMinor: number;
94
+ } | null;
95
+ readonly lines: readonly InvoiceLine[];
96
+ readonly totalNetMinor: number;
97
+ readonly totalTaxMinor: number;
98
+ readonly totalGrossMinor: number;
99
+ readonly chargedTotalGrossMinor: number;
100
+ }
101
+ /** Host-selected immutable revision; it contains no provider or country defaults. */
102
+ export interface InvoiceSellerRevision<Seller = InvoiceSeller> {
103
+ readonly seller: Seller;
104
+ readonly revisionRef: string;
105
+ }
106
+ /** Added only to returned claim facts, never to installed historical revisions. */
107
+ export interface InvoiceClaimedFacts extends InvoiceFacts {
108
+ readonly sellerRevision?: string;
109
+ readonly sellerMode?: "frozen" | "legacy_fallback";
110
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,245 @@
1
+ import type { InvoiceFacts, InvoiceSeller } from "./facts.js";
2
+ import type { InvoiceDocumentIdentity, InvoiceProof, InvoiceProviderPort, InvoiceUnsupported } from "./provider.js";
3
+ import type { InvoiceArtifactResult, InvoiceClearanceObservation, InvoiceDeliveryPort } from "./delivery.js";
4
+ import type { InvoiceCompanyLookupPort } from "./companyLookup.js";
5
+ import type { InvoiceSettlementPort } from "./settlement.js";
6
+ import type { InvoiceCapabilities } from "./capabilities.js";
7
+ import type { InvoiceStorePort } from "./store.js";
8
+ /** Host facts, fiscal routing, M07 reads, storage, registry, M04 delivery and M12
9
+ * history are required selections. Every missing native capability refuses before
10
+ * any write; an owed duty remains observable. This interface grants no authority.
11
+ */
12
+ export interface InvoiceHostPorts {
13
+ facts: {
14
+ read(orderId: string): Promise<{
15
+ readonly kind: "found";
16
+ readonly facts: InvoiceFacts;
17
+ } | {
18
+ readonly kind: "unknown";
19
+ readonly code: "missing_facts";
20
+ } | InvoiceUnsupported>;
21
+ };
22
+ /** Read the current host seller for the next claim, never per duty. Null orderId
23
+ * means an unscoped claim (including corrections). The durable wrapper freezes this seller at
24
+ * the first-ever claim; revisionRef feeds the claim wrapper's revision argument.
25
+ */
26
+ seller: {
27
+ read(input: {
28
+ readonly orderId: string | null;
29
+ }): Promise<{
30
+ readonly kind: "found";
31
+ readonly seller: InvoiceSeller;
32
+ readonly revisionRef: string;
33
+ } | {
34
+ readonly kind: "unknown";
35
+ readonly code: "unknown";
36
+ } | InvoiceUnsupported>;
37
+ };
38
+ /** Read-only projection of the final claimed M07 identity, never a refund writer.
39
+ * Missing nullable money is unavailable, never fabricated zero or mismatch.
40
+ */
41
+ money: {
42
+ read(input: {
43
+ readonly intentRef: string;
44
+ readonly providerRef: string;
45
+ readonly providerPaymentRef: string | null;
46
+ readonly expectedMoney: {
47
+ readonly amountMinor: number;
48
+ readonly currency: string;
49
+ };
50
+ }): Promise<{
51
+ readonly kind: "observed";
52
+ readonly status: "succeeded" | "failed" | "pending";
53
+ readonly amountMinor: number | null;
54
+ readonly currency: string | null;
55
+ readonly proof: InvoiceProof;
56
+ } | {
57
+ readonly kind: "absent";
58
+ readonly evidence: InvoiceProof & {
59
+ readonly exact: true;
60
+ readonly complete: true;
61
+ readonly scope: Parameters<InvoiceHostPorts["money"]["read"]>[0];
62
+ };
63
+ } | {
64
+ readonly kind: "unknown" | "unavailable";
65
+ readonly code: "money_unavailable";
66
+ } | InvoiceUnsupported>;
67
+ };
68
+ artifacts: {
69
+ read(input: {
70
+ readonly identity: InvoiceDocumentIdentity;
71
+ readonly kind: "pdf" | "structured_document" | "clearance_receipt";
72
+ }): Promise<InvoiceArtifactResult>;
73
+ /** Ownership must already be authorized; response bytes are not a storage receipt. */
74
+ download(input: {
75
+ readonly identity: InvoiceDocumentIdentity;
76
+ readonly artifactRef: string;
77
+ }): Promise<{
78
+ readonly kind: "downloaded";
79
+ readonly content: Uint8Array;
80
+ readonly contentType: string;
81
+ } | {
82
+ readonly kind: "unknown";
83
+ readonly code: "unknown";
84
+ } | InvoiceUnsupported>;
85
+ persist(input: {
86
+ readonly identity: InvoiceDocumentIdentity;
87
+ readonly kind: "pdf" | "structured_document" | "clearance_receipt";
88
+ readonly content: Uint8Array;
89
+ readonly contentType: string;
90
+ }): Promise<Exclude<InvoiceArtifactResult, {
91
+ kind: "absent";
92
+ }>>;
93
+ };
94
+ /** Host identifier/tax/rounding policy; refs must match the selected descriptor.
95
+ * No jurisdictional default is supplied. Carrier: TaxIdRoutingPort and injected
96
+ * canonical tax safety in accountingProviderSnapshot.
97
+ */
98
+ fiscal: {
99
+ verify(input: {
100
+ readonly facts: InvoiceFacts;
101
+ readonly policies: InvoiceCapabilities["policies"];
102
+ }): Promise<{
103
+ readonly kind: "verified";
104
+ readonly documentKind: string;
105
+ readonly clearanceRequired: boolean;
106
+ readonly proof: InvoiceProof;
107
+ } | {
108
+ readonly kind: "refused";
109
+ readonly code: "blocked" | "money_mismatch";
110
+ } | {
111
+ readonly kind: "unknown";
112
+ readonly code: "unknown";
113
+ } | InvoiceUnsupported>;
114
+ };
115
+ registry: InvoiceCompanyLookupPort;
116
+ delivery: InvoiceDeliveryPort;
117
+ clearance: {
118
+ observe(input: {
119
+ readonly identity: InvoiceDocumentIdentity;
120
+ readonly providerDocumentRef: string;
121
+ }): Promise<{
122
+ readonly kind: "observed";
123
+ readonly observation: InvoiceClearanceObservation;
124
+ } | {
125
+ readonly kind: "unknown";
126
+ readonly code: "unknown";
127
+ } | InvoiceUnsupported>;
128
+ };
129
+ settlement: InvoiceSettlementPort;
130
+ policy: {
131
+ /** Carrier: channelInvoicePolicyGate and the approved explicit operator skip.
132
+ * Suppression receipts have no fabricated document ID. Host persists attribution.
133
+ * Executor decides before installFacts: suppressed orders get no local document.
134
+ * Readback consumers merge recorded receipts with duty readback.
135
+ * Transient read failures return unknown without recording a receipt.
136
+ */
137
+ decide(input: {
138
+ readonly requestKey: string;
139
+ readonly lookup: {
140
+ readonly by: "order";
141
+ readonly orderId: string;
142
+ } | {
143
+ readonly by: "fulfillmentOrder";
144
+ readonly fulfillmentOrderRef: string;
145
+ };
146
+ }): Promise<{
147
+ readonly kind: "issue";
148
+ readonly policyVersion: string;
149
+ } | {
150
+ readonly kind: "policy_suppressed";
151
+ readonly outcome: "channel_issues" | "no_document";
152
+ readonly policyVersion: string;
153
+ readonly requestKey: string;
154
+ } | {
155
+ readonly kind: "operator_skipped";
156
+ readonly outcome: "operator_skip";
157
+ readonly actorRef: string;
158
+ readonly reason: string;
159
+ readonly requestKey: string;
160
+ } | {
161
+ readonly kind: "unknown";
162
+ readonly code: "unknown";
163
+ } | InvoiceUnsupported>;
164
+ receipts(orderId: string): Promise<readonly (Extract<Awaited<ReturnType<InvoiceHostPorts["policy"]["decide"]>>, {
165
+ kind: "policy_suppressed" | "operator_skipped";
166
+ }> & {
167
+ readonly recordedAt: string;
168
+ })[] | {
169
+ readonly kind: "unknown";
170
+ readonly code: "unknown";
171
+ } | InvoiceUnsupported>;
172
+ };
173
+ /** Authenticate and authorize ownership before reading artifacts. Safe projection
174
+ * only: no buyer/seller payload, raw provider errors, signed URL or arbitrary meta.
175
+ * Found is a complete owned projection; incomplete reads return unknown.
176
+ * Carrier: donor document history + customer download ticket owner/lineage.
177
+ */
178
+ accountHistory: {
179
+ read(input: {
180
+ readonly accountRef: string;
181
+ readonly orderId: string;
182
+ }): Promise<{
183
+ readonly kind: "found";
184
+ readonly accountRef: string;
185
+ readonly orderId: string;
186
+ readonly documents: readonly {
187
+ readonly documentRef: string;
188
+ readonly invoiceRef: string;
189
+ readonly parentDocumentRef: string | null;
190
+ readonly role: "original" | "correction" | "replacement";
191
+ readonly status: string;
192
+ readonly issuedAt: string | null;
193
+ readonly clearance: {
194
+ readonly state: InvoiceClearanceObservation["state"];
195
+ readonly reference: string | null;
196
+ } | null;
197
+ readonly documentKind: string | null;
198
+ readonly artifact: "invoice" | "correction";
199
+ readonly providerDocumentNumber: string | null;
200
+ readonly totalGrossMinor: number | null;
201
+ readonly currency: string;
202
+ readonly emailState: "not_requested" | "pending" | "provider_accepted" | "failed";
203
+ readonly isCurrent: boolean;
204
+ readonly createdAt: string;
205
+ readonly downloadAvailable: boolean;
206
+ }[];
207
+ } | {
208
+ readonly kind: "denied";
209
+ } | {
210
+ readonly kind: "unknown";
211
+ readonly code: "unknown";
212
+ } | InvoiceUnsupported>;
213
+ resolveDownload(input: {
214
+ readonly accountRef: string;
215
+ readonly orderId: string;
216
+ readonly documentRef: string;
217
+ }): Promise<{
218
+ readonly kind: "authorized";
219
+ readonly identity: InvoiceDocumentIdentity;
220
+ readonly artifactRef: string;
221
+ readonly fileName: string;
222
+ readonly parentDocumentRef: string | null;
223
+ } | {
224
+ readonly kind: "denied";
225
+ } | {
226
+ readonly kind: "unknown";
227
+ readonly code: "unknown";
228
+ } | InvoiceUnsupported>;
229
+ };
230
+ }
231
+ /** Explicit service composition inputs; the host retains worker and route authority. Closures/credentials must never be serialized with options.
232
+ */
233
+ export interface InvoiceServicesOptions {
234
+ readonly enabled?: boolean;
235
+ readonly selection: {
236
+ readonly providerRef: string;
237
+ } | null;
238
+ readonly capability: InvoiceCapabilities | null;
239
+ readonly provider: InvoiceProviderPort | null;
240
+ readonly store: InvoiceStorePort | null;
241
+ readonly host: InvoiceHostPorts;
242
+ readiness(): Promise<{
243
+ readonly kind: "ready";
244
+ } | InvoiceUnsupported>;
245
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ /** @consumer Frozen fact provider and installed declaration consumer. */
2
+ export type { InvoiceFacts, InvoiceLine, InvoiceSeller, InvoiceBuyer, InvoiceSellerRevision, InvoiceClaimedFacts } from "./facts.js";
3
+ /** @consumer A4 issue/correction bridge, adapters and operator proof readback. */
4
+ export type { InvoiceIdentity, InvoiceDocumentIdentity, InvoiceWriteResult, InvoiceReadbackResult, InvoiceProviderPort, InvoiceUnsupported, InvoiceDiagnosticCode, InvoiceProof } from "./provider.js";
5
+ /** @consumer Host artifact storage/download binding. */
6
+ export type { InvoiceArtifactResult, InvoiceClearanceObservation } from "./delivery.js";
7
+ /** @consumer Host payout item recorder and resolver. */
8
+ export type { InvoiceSettlementResult, InvoiceSettlementPort, InvoiceSettlementItem } from "./settlement.js";
9
+ /** @consumer Explicit host selection and readInvoiceCapabilities. */
10
+ export type { InvoiceCapabilities } from "./capabilities.js";
11
+ /** @consumer Injected registry adapter (A5). */
12
+ export type { InvoiceCompanyLookupPort } from "./companyLookup.js";
13
+ /** @consumer Managed/native persistence adapter and operator duty readback; no implementation supplied. */
14
+ export type { InvoiceStorePort, InvoiceDutyReadback } from "./store.js";
15
+ /** @consumer Host composition and offline port-fit witnesses. */
16
+ export type { InvoiceHostPorts, InvoiceServicesOptions } from "./host.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,126 @@
1
+ import type { InvoiceFacts } from "./facts.js";
2
+ /** Original host key bytes, immutable revision and exact lookup scope travel together.
3
+ * Carrier: providerPorts create options + approved exact-lookup envelope (fit probe).
4
+ */
5
+ export interface InvoiceIdentity {
6
+ readonly providerRef: string;
7
+ readonly requestKey: string;
8
+ /** Persisted create identity from claim, distinct from original host request key. */
9
+ readonly providerCreateIdentity: string;
10
+ readonly factRevision: string;
11
+ readonly orderRef: string;
12
+ readonly invoiceRef: string;
13
+ readonly operation: "issue" | "full_reversal" | "remote_void";
14
+ readonly correctionRef: string | null;
15
+ readonly parentProviderDocumentRef: string | null;
16
+ }
17
+ /** Document rows and donor delivery/history carriers need no issue-duty metadata.
18
+ * @consumer Host artifacts, clearance, delivery and authorized download adapters.
19
+ */
20
+ export interface InvoiceDocumentIdentity {
21
+ readonly providerRef: string;
22
+ readonly documentRef: string;
23
+ readonly providerDocumentRef: string | null;
24
+ readonly orderRef: string;
25
+ readonly invoiceRef: string;
26
+ readonly parentProviderDocumentRef: string | null;
27
+ }
28
+ /** A closed diagnostic allowlist in the neutral contract. Codes only.
29
+ * @consumer A4 bridge and provider/store adapters. */
30
+ export type InvoiceDiagnosticCode = "faulted" | "missing_facts" | "legacy_facts_unproved" | "retryable" | "blocked" | "unsupported" | "unknown" | "absent" | "host_binding_required" | "selection_required" | "disabled" | "identity_mismatch" | "parent_mismatch" | "money_mismatch" | "money_unavailable" | "invalid_artifact" | "uncertain_delivery";
31
+ /** Missing binding or capability: nothing written.
32
+ * @consumer Host and provider adapters. */
33
+ export interface InvoiceUnsupported {
34
+ readonly kind: "unsupported";
35
+ readonly code: "host_binding_required" | "unsupported";
36
+ readonly retryable: false;
37
+ readonly effectMayHaveSucceeded: false;
38
+ }
39
+ /** Evidence references/fingerprints are adapter-filtered; never raw payloads or errors.
40
+ * @consumer Host recorder, operator readback and adapters. */
41
+ export interface InvoiceProof {
42
+ readonly evidenceRef: string;
43
+ readonly fingerprint: string;
44
+ readonly observedAt: string;
45
+ }
46
+ /** Refused proves a definite provider refusal with no effect; post-request adapter
47
+ * or transport faults are unknown, even when no acknowledgement was received.
48
+ */
49
+ export type InvoiceWriteResult = {
50
+ readonly kind: "issued";
51
+ readonly identity: InvoiceIdentity;
52
+ readonly providerDocumentRef: string;
53
+ readonly providerDocumentNumber: string | null;
54
+ readonly proof: InvoiceProof;
55
+ readonly replayed: boolean;
56
+ } | {
57
+ readonly kind: "refused";
58
+ readonly identity: InvoiceIdentity;
59
+ readonly code: Extract<InvoiceDiagnosticCode, "blocked" | "retryable" | "missing_facts" | "identity_mismatch" | "parent_mismatch" | "money_mismatch">;
60
+ readonly retryable: boolean;
61
+ readonly effectMayHaveSucceeded: false;
62
+ } | {
63
+ readonly kind: "unknown";
64
+ readonly identity: InvoiceIdentity;
65
+ readonly code: "unknown";
66
+ readonly effectMayHaveSucceeded: true;
67
+ } | InvoiceUnsupported;
68
+ /** Exact scope is the full identity, including operation, parent and revision.
69
+ * Incomplete/truncated/failed lookup is unknown. Only exact complete absence can
70
+ * authorize another create; found is proof, never a nullable lookup shortcut.
71
+ */
72
+ export type InvoiceReadbackResult = {
73
+ readonly kind: "found";
74
+ readonly identity: InvoiceIdentity;
75
+ readonly providerDocumentRef: string;
76
+ readonly providerDocumentNumber: string | null;
77
+ readonly proof: InvoiceProof;
78
+ } | {
79
+ readonly kind: "absent";
80
+ readonly identity: InvoiceIdentity;
81
+ readonly evidence: InvoiceProof & {
82
+ readonly exact: true;
83
+ readonly complete: true;
84
+ readonly scope: InvoiceIdentity;
85
+ };
86
+ } | {
87
+ readonly kind: "unknown";
88
+ readonly identity: InvoiceIdentity;
89
+ readonly code: "unknown";
90
+ } | InvoiceUnsupported;
91
+ /** Correction bridge: positive immutable BEFORE facts, explicit zero AFTER,
92
+ * stable correctionRef and parent proof. Retry requires exact recovery before I/O.
93
+ * Carrier: donor createFullCorrection options and accountingProviderSnapshot.
94
+ * @consumer A4 conforming correction bridge and issue/readback adapters.
95
+ */
96
+ export interface InvoiceProviderPort {
97
+ issue(input: {
98
+ readonly identity: InvoiceIdentity & {
99
+ readonly operation: "issue";
100
+ readonly correctionRef: null;
101
+ readonly parentProviderDocumentRef: null;
102
+ };
103
+ readonly facts: InvoiceFacts;
104
+ readonly recoveryLookupRequired: boolean;
105
+ }): Promise<InvoiceWriteResult>;
106
+ correct(input: {
107
+ readonly identity: InvoiceIdentity & {
108
+ readonly operation: "full_reversal";
109
+ readonly correctionRef: string;
110
+ readonly parentProviderDocumentRef: string;
111
+ };
112
+ readonly before: InvoiceFacts;
113
+ readonly after: {
114
+ readonly totalNetMinor: 0;
115
+ readonly totalTaxMinor: 0;
116
+ readonly totalGrossMinor: 0;
117
+ };
118
+ readonly reason: string;
119
+ readonly recoveryLookupRequired: boolean;
120
+ }): Promise<InvoiceWriteResult>;
121
+ read(input: InvoiceIdentity): Promise<InvoiceReadbackResult>;
122
+ /** Remote void stays cut; always refuse before I/O, never substitute local void. */
123
+ void(input: InvoiceIdentity & {
124
+ readonly operation: "remote_void";
125
+ }): Promise<InvoiceUnsupported>;
126
+ }
@@ -0,0 +1 @@
1
+ export {};