xytara 3.1.13 → 3.1.15

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 (68) hide show
  1. package/.env.example +38 -4
  2. package/BSV_TERANODE_PLATFORM_DISCONTINUITY_RUNBOOK.md +126 -126
  3. package/REAL_PAYMENT_SETUP.md +14 -7
  4. package/RELEASE_NOTES.md +9 -4
  5. package/fixtures/catalog.js +22 -0
  6. package/lib/a2a_rpc.js +287 -280
  7. package/lib/account_auth.js +585 -585
  8. package/lib/agent_identity.js +162 -162
  9. package/lib/asyncapi_contract.js +3 -3
  10. package/lib/bolt_adapter.js +187 -187
  11. package/lib/bolt_payment_front.js +224 -224
  12. package/lib/buyer_event_log.js +215 -0
  13. package/lib/buyer_safety_policy.js +132 -0
  14. package/lib/checkout_processor_adapter.js +217 -217
  15. package/lib/command_flow.js +911 -722
  16. package/lib/commerce_artifacts.js +591 -591
  17. package/lib/commerce_bridge.js +274 -274
  18. package/lib/commerce_cases.js +399 -399
  19. package/lib/commerce_client.js +7694 -7694
  20. package/lib/commerce_quotes.js +29 -0
  21. package/lib/commerce_runtime.js +322 -322
  22. package/lib/execution_dedupe.js +86 -86
  23. package/lib/external_credit_bridge.js +142 -142
  24. package/lib/http_transport.js +99 -81
  25. package/lib/l402_adapter.js +241 -241
  26. package/lib/l402_payment_front.js +265 -265
  27. package/lib/mpp_adapter.js +237 -237
  28. package/lib/openapi_contract.js +4 -0
  29. package/lib/payment_config.js +257 -253
  30. package/lib/payment_verification.js +357 -357
  31. package/lib/provider_payout_execution.js +155 -155
  32. package/lib/provider_registry.js +852 -842
  33. package/lib/rate_limiter.js +81 -81
  34. package/lib/runtime_state_store.js +495 -369
  35. package/lib/settlement_bsv_live.js +600 -600
  36. package/lib/settlement_bsv_teranode.js +117 -117
  37. package/lib/stripe_mpp_payment_front.js +258 -258
  38. package/lib/x402_facilitator.js +198 -191
  39. package/lib/x402_lane_contract.js +5 -3
  40. package/lib/x402_settlement_recovery.js +175 -0
  41. package/package.json +9 -3
  42. package/scripts/buyer_events_daily_report.js +79 -0
  43. package/scripts/state_backup_offsite.js +196 -0
  44. package/scripts/verify_a2a_rpc.js +131 -105
  45. package/scripts/verify_agent_identity.js +153 -153
  46. package/scripts/verify_all.js +1 -1
  47. package/scripts/verify_bolt_adapter.js +128 -128
  48. package/scripts/verify_buyer_event_log.js +123 -0
  49. package/scripts/verify_buyer_safety.js +141 -0
  50. package/scripts/verify_cdp_facilitator.js +110 -110
  51. package/scripts/verify_checkout_processor.js +109 -109
  52. package/scripts/verify_commerce_bridge.js +177 -177
  53. package/scripts/verify_execution_dedupe.js +189 -189
  54. package/scripts/verify_execution_surfacing.js +76 -76
  55. package/scripts/verify_final_activation.js +191 -191
  56. package/scripts/verify_l402_adapter.js +86 -86
  57. package/scripts/verify_lifecycle_spend_binding.js +88 -0
  58. package/scripts/verify_mpp_adapter.js +128 -128
  59. package/scripts/verify_production_readiness.js +268 -268
  60. package/scripts/verify_rate_limiter.js +52 -52
  61. package/scripts/verify_refund_credit.js +106 -106
  62. package/scripts/verify_release_candidate.js +81 -81
  63. package/scripts/verify_runtime_state_guard.js +117 -0
  64. package/scripts/verify_service.js +15421 -15421
  65. package/scripts/verify_verify_execute_settle.js +209 -208
  66. package/scripts/verify_x402_facilitator.js +307 -286
  67. package/scripts/verify_x402_settlement_recovery.js +153 -0
  68. package/server.js +12242 -11974
@@ -175,10 +175,38 @@ function refreshQuoteStatus(state, quoteId, nowMs) {
175
175
  return next;
176
176
  }
177
177
 
178
+ // Expired, never-paid quotes (e.g. from unpaid 402 probes) are pure history: nothing executes or
179
+ // settles against them. Keep them for a retention window, then drop them so durable state does
180
+ // not grow without bound. Executed/accepted quotes are never pruned.
181
+ const DEFAULT_QUOTE_RETENTION_MS = 7 * 24 * 60 * 60 * 1000;
182
+ function quoteRetentionMs() {
183
+ const raw = process.env.XYTARA_QUOTE_RETENTION_MS;
184
+ if (raw === undefined || raw === "") return DEFAULT_QUOTE_RETENTION_MS;
185
+ const n = Number(raw);
186
+ return Number.isFinite(n) && n >= 0 ? n : DEFAULT_QUOTE_RETENTION_MS;
187
+ }
188
+
189
+ function pruneStaleQuotes(state, nowMs) {
190
+ if (!state || !(state.quotes instanceof Map)) return 0;
191
+ const now = typeof nowMs === "number" ? nowMs : Date.now();
192
+ const cutoff = now - quoteRetentionMs();
193
+ let pruned = 0;
194
+ for (const [quoteId, quote] of Array.from(state.quotes.entries())) {
195
+ if (!quote || quote.status !== "expired" || quote.transaction_id) continue;
196
+ const expiresAtMs = Date.parse(quote.expires_at_iso || "");
197
+ if (Number.isFinite(expiresAtMs) && expiresAtMs < cutoff) {
198
+ state.quotes.delete(quoteId);
199
+ pruned += 1;
200
+ }
201
+ }
202
+ return pruned;
203
+ }
204
+
178
205
  function hydrateQuoteStates(state, nowMs) {
179
206
  for (const quoteId of Array.from(state.quotes.keys())) {
180
207
  refreshQuoteStatus(state, quoteId, nowMs);
181
208
  }
209
+ pruneStaleQuotes(state, nowMs);
182
210
  }
183
211
 
184
212
  function markQuoteExecuted(state, quote, result, paymentRecord, options) {
@@ -233,5 +261,6 @@ module.exports = {
233
261
  isQuoteExpired,
234
262
  markQuoteExecuted,
235
263
  normalizeTaskRefs,
264
+ pruneStaleQuotes,
236
265
  refreshQuoteStatus
237
266
  };