@genesis-tech/genesispay-seller 0.13.2 → 1.5.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 (78) hide show
  1. package/CHANGELOG.md +227 -0
  2. package/README.md +719 -91
  3. package/dist/checkout-documents.d.ts +105 -0
  4. package/dist/checkout-documents.d.ts.map +1 -0
  5. package/dist/checkout-documents.js +171 -0
  6. package/dist/checkout-documents.js.map +1 -0
  7. package/dist/checkout-return.d.ts +5 -5
  8. package/dist/checkout-return.d.ts.map +1 -1
  9. package/dist/checkout-return.js +3 -2
  10. package/dist/checkout-return.js.map +1 -1
  11. package/dist/client.d.ts +57 -7
  12. package/dist/client.d.ts.map +1 -1
  13. package/dist/client.js +100 -10
  14. package/dist/client.js.map +1 -1
  15. package/dist/contract-mandates.d.ts +39 -0
  16. package/dist/contract-mandates.d.ts.map +1 -0
  17. package/dist/contract-mandates.js +98 -0
  18. package/dist/contract-mandates.js.map +1 -0
  19. package/dist/contract-usage.d.ts +29 -0
  20. package/dist/contract-usage.d.ts.map +1 -0
  21. package/dist/contract-usage.js +92 -0
  22. package/dist/contract-usage.js.map +1 -0
  23. package/dist/errors.d.ts +71 -5
  24. package/dist/errors.d.ts.map +1 -1
  25. package/dist/errors.js +124 -13
  26. package/dist/errors.js.map +1 -1
  27. package/dist/fulfillment-attempts.d.ts +29 -0
  28. package/dist/fulfillment-attempts.d.ts.map +1 -0
  29. package/dist/fulfillment-attempts.js +71 -0
  30. package/dist/fulfillment-attempts.js.map +1 -0
  31. package/dist/fulfillment.d.ts +152 -0
  32. package/dist/fulfillment.d.ts.map +1 -0
  33. package/dist/fulfillment.js +810 -0
  34. package/dist/fulfillment.js.map +1 -0
  35. package/dist/genesispay-settlement.d.ts +4 -2
  36. package/dist/genesispay-settlement.d.ts.map +1 -1
  37. package/dist/genesispay-settlement.js +412 -15
  38. package/dist/genesispay-settlement.js.map +1 -1
  39. package/dist/index.d.ts +11 -5
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +7 -4
  42. package/dist/index.js.map +1 -1
  43. package/dist/invoices.d.ts +31 -0
  44. package/dist/invoices.d.ts.map +1 -1
  45. package/dist/invoices.js +61 -2
  46. package/dist/invoices.js.map +1 -1
  47. package/dist/item-tax.d.ts +25 -0
  48. package/dist/item-tax.d.ts.map +1 -0
  49. package/dist/item-tax.js +43 -0
  50. package/dist/item-tax.js.map +1 -0
  51. package/dist/mandate-gate.d.ts +6 -1
  52. package/dist/mandate-gate.d.ts.map +1 -1
  53. package/dist/mandate-gate.js +81 -7
  54. package/dist/mandate-gate.js.map +1 -1
  55. package/dist/mandates.d.ts +21 -4
  56. package/dist/mandates.d.ts.map +1 -1
  57. package/dist/mandates.js +24 -3
  58. package/dist/mandates.js.map +1 -1
  59. package/dist/networks.d.ts.map +1 -1
  60. package/dist/networks.js +5 -4
  61. package/dist/networks.js.map +1 -1
  62. package/dist/payment-gate.d.ts +32 -1
  63. package/dist/payment-gate.d.ts.map +1 -1
  64. package/dist/payment-gate.js +275 -11
  65. package/dist/payment-gate.js.map +1 -1
  66. package/dist/products.d.ts +40 -16
  67. package/dist/products.d.ts.map +1 -1
  68. package/dist/products.js +1078 -56
  69. package/dist/products.js.map +1 -1
  70. package/dist/strict-response.d.ts +21 -0
  71. package/dist/strict-response.d.ts.map +1 -0
  72. package/dist/strict-response.js +68 -0
  73. package/dist/strict-response.js.map +1 -0
  74. package/dist/webhooks.d.ts +77 -2
  75. package/dist/webhooks.d.ts.map +1 -1
  76. package/dist/webhooks.js +20 -0
  77. package/dist/webhooks.js.map +1 -1
  78. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,232 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.5.0 — 2026-09-30 — exact externally calculated WooCommerce order tax
4
+
5
+ Minor release. The first npm release after 1.3.0; it also carries the
6
+ never-published 1.4.0 entry below. Requires protocol `^0.5.0` (unchanged) and
7
+ a GenesisPay deployment that accepts `lineItems` and the version-2 tax
8
+ assertion on `POST /api/v1/links`.
9
+
10
+ - `checkout.create()` accepts a version-2 external WooCommerce tax assertion
11
+ with exact integer-minor-unit subtotal, tax and total on strict idempotent
12
+ single-use requests.
13
+ - Checkout line items accept `kind: "item" | "shipping" | "fee" | "tax"`;
14
+ every line requires it when external tax is used so net, tax and gross can be
15
+ validated without inventing an aggregate rate.
16
+ - Checkout-link and hosted-document readers expose the additive assertion and
17
+ typed external lines while preserving version-1 item tax unchanged.
18
+ - New exported types `ExternalOrderTax` and `PaymentLinkTax`
19
+ (`ItemTax | ExternalOrderTax`). TypeScript note: `CheckoutLink.taxConfig` is
20
+ now `PaymentLinkTax | null`, and `CheckoutDocumentSnapshot` gains the
21
+ `"external_platform"` tax source, `"external_exact"` rounding and a typed
22
+ external line shape. Code that reads version-1 fields from these values
23
+ narrows on `taxConfig.version === 1` first.
24
+ Values for links created without external tax are unchanged at runtime.
25
+
26
+ ## 1.4.0 — hosted checkout line-item snapshots (never published; shipped in 1.5.0)
27
+
28
+ - `checkout.create()` accepts an optional immutable `lineItems` snapshot with
29
+ product or adjustment labels, quantities, exact decimal-string line totals,
30
+ and optional descriptions, SKUs, and safe HTTP(S) image URLs.
31
+ - GenesisPay requires the line totals to add up exactly to the checkout amount;
32
+ settlement authority remains the frozen amount, asset, chain, and destination.
33
+
34
+ ## 1.3.0 — purchase-bound settlement preparation
35
+
36
+ Additive; requires protocol `^0.5.0`.
37
+
38
+ - Product gates (`products.gate(...).protect`) and the generic
39
+ `createPaymentGate(...).wrap` accept settlement-preparation parameters from
40
+ `GENESISPAY-Settlement-Prepare-Params` when `GENESISPAY-Settlement-Prepare: 1`
41
+ is present. The request body is then the purchase body, so a route may parse
42
+ and validate it before calling the gate (ADR-0083).
43
+ - In that mode a product gate recomputes the canonical method, resource URL and
44
+ request fingerprint and requires them to equal the expected gate intent. A
45
+ mismatch answers `422 { code: "contract_mismatch", mismatches }` and nothing
46
+ is forwarded to GenesisPay; a present but malformed params header answers
47
+ `422 { code: "invalid_request" }` and is never replaced by the body.
48
+ - The generic gate binds no request fingerprint; in header mode it treats the
49
+ body as opaque purchase content and never reads it.
50
+ - Without the params header both gates behave exactly as in 1.2.1: the body
51
+ carries the plan parameters (GET resources, hosted links, older engines).
52
+ - The `prepare` action sent to GenesisPay is unchanged.
53
+ - Document the beta lock on new mandate authority. A locked deployment answers
54
+ HTTP `409` `mandate_authority_locked_for_beta` (no `Retry-After`) for
55
+ `mandates.create`, the `contract_mandate_v1` proposal/activation helpers,
56
+ `mandates.proposeContractUsage` and `plans.create`.
57
+ `mandates.submitContractUsage`, revocation, reads and the x402 payment gate
58
+ are unaffected. Documentation only; no SDK source change and no publication.
59
+
60
+ ## 1.2.1 — settlement ambiguity and terminal polling fixes
61
+
62
+ - Preserve a payer-supplied transaction hash when a custom settlement verifier
63
+ throws, returning a non-success reconciliation response instead of losing the
64
+ locator.
65
+ - Map asynchronously polled `failed` and `expired` product settlements to HTTP
66
+ 409 and 410. Terminal status never looks like successful resource delivery,
67
+ never runs the protected handler, and never forwards `PAYMENT-RESPONSE`.
68
+ - Require synchronous facilitator success to carry a full transaction hash,
69
+ exact network, exact integer minor amount, exact known payer and both explicit
70
+ authorization/settlement verification flags before the paid handler runs.
71
+ - Document the already-exported experimental `contract_mandate_v1` helpers:
72
+ `mandates.createContractSubscription`, `createContractPerUse`,
73
+ `proposeContractUsage`, `submitContractUsage`, and `getContractUsage`, plus
74
+ their result/input types. They independently rebuild typed data and fail
75
+ closed on inconsistent authority. Their presence does not enable backend
76
+ admission or grant Mainnet clearance.
77
+
78
+ ## 1.2.0 — hosted checkout documents and asynchronous settlement
79
+
80
+ Built on the strict 1.1.0 SDK and protocol 0.4 contract; no npm publication is
81
+ part of this change. Strict creation still requires an idempotency key and
82
+ versioned responses, and only `fulfillment.verify()` grants payment authority.
83
+
84
+ ### Added
85
+
86
+ - The facilitator settlement adapter accepts versioned HTTP 202 queue
87
+ acceptance, polls the same-origin seller-key status URL, and reports success
88
+ only after GenesisPay verifies the seller transfer and returns its real hash.
89
+ - Strict product gates poll seller-scoped settlement status after 202 and retry
90
+ the gate request only after seller confirmation. `queued` and `submitted`
91
+ never authorize resource delivery; failed, expired, malformed and timed-out
92
+ status remains fail-closed.
93
+ - `settlementPollTimeoutMs` configures the facilitator adapter's bounded poll
94
+ window (120 seconds by default). Legacy synchronous 200 settlement remains
95
+ compatible.
96
+
97
+ - Plan-aware x402 gates advertise a preparation handshake, proxy exact
98
+ pre-sign authority through the GenesisPay facilitator, and submit the returned
99
+ plan id with settlement. Signed-first clients receive an upgrade refusal
100
+ before broadcast; current on-chain transfers are unchanged (MR-1011).
101
+
102
+ - **`genesispay.checkoutDocuments.list()`** lists the seller's immutable formal
103
+ invoices and enhanced receipts created after confirmed, non-simulated hosted
104
+ human checkout payments.
105
+ - **`genesispay.checkoutDocuments.get(publicId)`** retrieves one document; the
106
+ authenticated API also exposes `GET /api/v1/checkout-documents/:publicId/pdf`.
107
+ - Products and checkout requests expose explicit inclusive `taxConfig`; product
108
+ updates and `checkout.updateTax()` use `expectedTaxConfig` conflict detection.
109
+ - New manual invoices use inclusive per-line tax and produce an invoice/receipt
110
+ pair after real payment. Existing finalized documents stay immutable.
111
+
112
+ ### Safety
113
+
114
+ - Checkout documents are read-only snapshots, not the manual
115
+ `genesispay.invoices.*` lifecycle. A missing `invoiceNumber` means an honest
116
+ enhanced receipt rather than a guessed or incomplete formal invoice.
117
+ - New standalone checkout requests are single-use; repeat purchases use products.
118
+ Legacy generic reusable links close after payment, preserving their history.
119
+
120
+ ## 1.1.0 — durable fulfillment notifications (release candidate)
121
+
122
+ - Add typed `payment.fulfilled` notifications with strict envelope/evidence shape
123
+ checks after raw-body HMAC verification. Wire amounts remain strings;
124
+ authenticated `fulfillment.verify` is still required for economic authority.
125
+ - Add `fulfillment.listAttempts` with scoped, versioned keyset discovery for
126
+ missing-notification recovery. Historical candidates never authorize fulfillment.
127
+ - Document stable source event IDs, nine-send retry cycles, explicit replay and
128
+ attempt/intent-keyed atomic credit handling across webhook and reconciliation.
129
+
130
+ ## 1.0.0 — strict fulfilment authority
131
+
132
+ Breaking authority contract. Existing tolerant checkout, product, entitlement,
133
+ and webhook views remain available for display, correlation, and migration, but
134
+ they are not proof that a seller may fulfil an order.
135
+
136
+ ### Added
137
+
138
+ - `genesispay.fulfillment.verify({ locator, expected })`, the only public SDK
139
+ path that returns strict payment authority. It always retrieves evidence from
140
+ the seller-authenticated GenesisPay API; no public method accepts a
141
+ caller-created evidence object.
142
+ - Exact `ExpectedProductContract`, `ExpectedPaymentLinkContract`,
143
+ `FulfillmentLocator`, `FulfillmentVerification`, and `VerifiedPayment` types.
144
+ Money is `bigint` minor units in application code and bounded canonical
145
+ decimal strings on the wire.
146
+ - Explicit `GENESISPAY-Version: 2026-08-26` negotiation plus matching
147
+ `GENESISPAY-Request-Id` and version metadata on successful and negative
148
+ results.
149
+ - Typed `GenesisPayContractMismatchError`,
150
+ `GenesisPayAmbiguousLocatorError`, `GenesisPayEvidenceError`, and
151
+ `GenesisPayVersionError`. Every SDK error now exposes nullable `requestId` and
152
+ `apiVersion` properties; they are null only when no versioned response exists.
153
+ - `products.assertContract(expected)` and idempotent
154
+ `products.createCheckout({ expected, ... }, { idempotencyKey })`. The latter
155
+ returns an explicit `product_checkout_link` with `linkId`, never an ambiguous
156
+ checkout `id`.
157
+ - `createGateRequestFingerprint(request)` and the breaking
158
+ `products.gate(id).protect(request, expected, handler)` signature. A product
159
+ handler now receives only strictly verified payment/product fields.
160
+
161
+ ### Safety
162
+
163
+ - Strict fee validation distinguishes a supported 100%-of-gross record-only
164
+ quote from an authorized deduction: the former preserves the full seller
165
+ payment; the latter must leave a positive seller amount. Quotes above gross
166
+ fail closed in both backend and SDK.
167
+ - The configured `expectedPayTo` pin also guards strict product contract checks,
168
+ checkout creation and gate protection, authenticated checkout retrieval, and
169
+ strict fulfillment verification. Missing/conflicting retrieved destinations
170
+ fail closed; a caller's expected contract cannot override the pin. Historical
171
+ reconciliation after wallet rotation uses a client pinned to the original
172
+ order destination. Clients without a pin retain their existing behavior.
173
+ - Strict `checkout.create` errors preserve request/version correlation from
174
+ response headers or body while retaining validation, rate-limit and other
175
+ typed HTTP errors, including interrupted or non-JSON error responses.
176
+ - MR-102/MR-103: mode, Base network, chain, asset, token address, and six-decimal
177
+ scale are cross-validated against the SDK's audited USDC/EURC deployment
178
+ registry before a result can be verified.
179
+ - MR-202: locator identity, exact gross amount, frozen destination, product/SKU,
180
+ and complete delivery or gate intent must match the expected immutable
181
+ contract. Contract mismatches throw and include the mismatched field paths.
182
+ - MR-804: verified evidence requires the literal `simulated: false` and the
183
+ supported authority provenance version. Historical evidence without that
184
+ provenance fails closed instead of inheriting a default.
185
+ - Known missing/null/wrong-typed fields, noncanonical or oversized money,
186
+ settlement arithmetic contradictions, unsafe/noncanonical URLs, unknown
187
+ payment channels, and unsupported versions fail closed. Unknown additive
188
+ fields remain forward compatible.
189
+ - Direct `checkout.create` now requires `{ idempotencyKey }` and sends both
190
+ `Idempotency-Key` and the strict API version. There is no idempotency-free
191
+ money-creation overload in 1.0.
192
+ - A product gate never defaults asset/chain or fabricates `simulated: false`.
193
+ Its initial challenge sends the complete validated expected contract for an
194
+ atomic pre-attempt comparison against the exact frozen payable link. Evidence
195
+ failure after settlement returns a `503` recovery response that preserves
196
+ a matching `PAYMENT-RESPONSE` and carries the attempt ID when one is known; permanent
197
+ inconsistencies are explicitly `retryable: false`.
198
+ - Signed gate recovery cross-checks attempt IDs in the request URL, payment
199
+ payload, settlement body, and settlement header. A post-commit transport loss
200
+ returns a retryable recovery response using that locator; a settlement that
201
+ names a different attempt than the signed one never reaches verification or
202
+ the paid handler and drops that other attempt's receipt. Both this case and
203
+ body/header contradictions report an unknown, retryable outcome.
204
+ - Interrupted verification response streams remain transient, while completed
205
+ malformed evidence stays permanent. Missing strict settlement metadata or a
206
+ negative `not_found`/`not_confirmed` verification never claims confirmation.
207
+ - Strict backend creation and gate calls reject a seller key whose mode does
208
+ not match the payment chain before exposing or settling that payment,
209
+ including product checkout idempotent replay.
210
+ - Confirmed gate retries can recover after their original authorization expires,
211
+ with signature and on-chain replay verification and no repeat broadcast/fee.
212
+ Failed/expired attempts remain terminal, including on archived links.
213
+ - Verified network contracts no longer expose the mutable shared asset registry.
214
+ URL-delivery examples use entitlement verification to honor revocation/expiry.
215
+ - Successful entitlement lookups must report a valid entitlement; payer-authorized
216
+ fees must leave a positive seller amount. Contradictory evidence is rejected.
217
+ - Conflicting recovery identities discard unrelated receipts on 503, other 5xx
218
+ and contradictory 2xx responses, while retaining the signed attempt locator.
219
+ - Frozen fee terms and the amount actually collected are deliberately separate:
220
+ a non-collecting payment may have nonzero configured fee terms with a zero
221
+ settled fee.
222
+
223
+ ### Migration
224
+
225
+ Use webhook, browser-return, link, or entitlement identifiers only as locators.
226
+ Pass an immutable expected contract to `fulfillment.verify`, fulfil only on
227
+ `verified: true`, and alert on typed mismatch/evidence/version errors using their
228
+ request ID. Pin this major exactly until the matching strict backend is deployed.
229
+
3
230
  ## 0.13.2 — clean recovery package
4
231
 
5
232
  No API or runtime behaviour change from `0.13.0`. This immutable patch release