@owlmeans/server-payment 0.1.18-rc.9 → 0.1.18

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 (537) hide show
  1. package/README.md +157 -26
  2. package/agent-meta/manifest.json +30 -4
  3. package/agent-meta/skills/server-payment/SKILL.md +613 -54
  4. package/agent-meta/skills/server-payment/parts/reference.md +174 -0
  5. package/build/access/types.d.ts +46 -0
  6. package/build/access/types.d.ts.map +1 -0
  7. package/build/access/types.js +2 -0
  8. package/build/access/types.js.map +1 -0
  9. package/build/access.d.ts +6 -0
  10. package/build/access.d.ts.map +1 -0
  11. package/build/access.js +45 -0
  12. package/build/access.js.map +1 -0
  13. package/build/actions/index.d.ts +1 -0
  14. package/build/actions/index.d.ts.map +1 -1
  15. package/build/actions/index.js +1 -0
  16. package/build/actions/index.js.map +1 -1
  17. package/build/actions/resync-subscriptions.d.ts +3 -0
  18. package/build/actions/resync-subscriptions.d.ts.map +1 -0
  19. package/build/actions/resync-subscriptions.js +7 -0
  20. package/build/actions/resync-subscriptions.js.map +1 -0
  21. package/build/actions/resync.d.ts +6 -1
  22. package/build/actions/resync.d.ts.map +1 -1
  23. package/build/actions/resync.js +15 -5
  24. package/build/actions/resync.js.map +1 -1
  25. package/build/actions/webhook.d.ts +2 -1
  26. package/build/actions/webhook.d.ts.map +1 -1
  27. package/build/actions/webhook.js +10 -4
  28. package/build/actions/webhook.js.map +1 -1
  29. package/build/bootstrap/types.d.ts +16 -0
  30. package/build/bootstrap/types.d.ts.map +1 -0
  31. package/build/bootstrap/types.js +2 -0
  32. package/build/bootstrap/types.js.map +1 -0
  33. package/build/bootstrap.d.ts +6 -0
  34. package/build/bootstrap.d.ts.map +1 -0
  35. package/build/bootstrap.js +26 -0
  36. package/build/bootstrap.js.map +1 -0
  37. package/build/catalogue/types.d.ts +38 -0
  38. package/build/catalogue/types.d.ts.map +1 -0
  39. package/build/catalogue/types.js +2 -0
  40. package/build/catalogue/types.js.map +1 -0
  41. package/build/catalogue.d.ts +6 -0
  42. package/build/catalogue.d.ts.map +1 -0
  43. package/build/catalogue.js +110 -0
  44. package/build/catalogue.js.map +1 -0
  45. package/build/commit/types.d.ts +22 -0
  46. package/build/commit/types.d.ts.map +1 -0
  47. package/build/commit/types.js +2 -0
  48. package/build/commit/types.js.map +1 -0
  49. package/build/commit.d.ts +6 -0
  50. package/build/commit.d.ts.map +1 -0
  51. package/build/commit.js +125 -0
  52. package/build/commit.js.map +1 -0
  53. package/build/config.d.ts +44 -5
  54. package/build/config.d.ts.map +1 -1
  55. package/build/config.js +216 -10
  56. package/build/config.js.map +1 -1
  57. package/build/consts.d.ts +74 -16
  58. package/build/consts.d.ts.map +1 -1
  59. package/build/consts.js +86 -23
  60. package/build/consts.js.map +1 -1
  61. package/build/consts.local.d.ts +94 -0
  62. package/build/consts.local.d.ts.map +1 -0
  63. package/build/consts.local.js +44 -0
  64. package/build/consts.local.js.map +1 -0
  65. package/build/consumer/cancellation/types.d.ts +11 -0
  66. package/build/consumer/cancellation/types.d.ts.map +1 -0
  67. package/build/consumer/cancellation/types.js +2 -0
  68. package/build/consumer/cancellation/types.js.map +1 -0
  69. package/build/consumer/cancellation.d.ts +6 -0
  70. package/build/consumer/cancellation.d.ts.map +1 -0
  71. package/build/consumer/cancellation.js +33 -0
  72. package/build/consumer/cancellation.js.map +1 -0
  73. package/build/consumer/capture/types.d.ts +50 -0
  74. package/build/consumer/capture/types.d.ts.map +1 -0
  75. package/build/consumer/capture/types.js +2 -0
  76. package/build/consumer/capture/types.js.map +1 -0
  77. package/build/consumer/capture.d.ts +6 -0
  78. package/build/consumer/capture.d.ts.map +1 -0
  79. package/build/consumer/capture.js +284 -0
  80. package/build/consumer/capture.js.map +1 -0
  81. package/build/consumer/consts.local.d.ts +10 -0
  82. package/build/consumer/consts.local.d.ts.map +1 -0
  83. package/build/consumer/consts.local.js +11 -0
  84. package/build/consumer/consts.local.js.map +1 -0
  85. package/build/consumer/format/types.d.ts +30 -0
  86. package/build/consumer/format/types.d.ts.map +1 -0
  87. package/build/consumer/format/types.js +2 -0
  88. package/build/consumer/format/types.js.map +1 -0
  89. package/build/consumer/format.d.ts +4 -0
  90. package/build/consumer/format.d.ts.map +1 -0
  91. package/build/consumer/format.js +73 -0
  92. package/build/consumer/format.js.map +1 -0
  93. package/build/consumer/handlers.d.ts +21 -0
  94. package/build/consumer/handlers.d.ts.map +1 -0
  95. package/build/consumer/handlers.js +174 -0
  96. package/build/consumer/handlers.js.map +1 -0
  97. package/build/consumer/index.d.ts +10 -0
  98. package/build/consumer/index.d.ts.map +1 -0
  99. package/build/consumer/index.js +6 -0
  100. package/build/consumer/index.js.map +1 -0
  101. package/build/consumer/mail/types.d.ts +29 -0
  102. package/build/consumer/mail/types.d.ts.map +1 -0
  103. package/build/consumer/mail/types.js +2 -0
  104. package/build/consumer/mail/types.js.map +1 -0
  105. package/build/consumer/mail.d.ts +6 -0
  106. package/build/consumer/mail.d.ts.map +1 -0
  107. package/build/consumer/mail.js +313 -0
  108. package/build/consumer/mail.js.map +1 -0
  109. package/build/consumer/observers/types.d.ts +15 -0
  110. package/build/consumer/observers/types.d.ts.map +1 -0
  111. package/build/consumer/observers/types.js +2 -0
  112. package/build/consumer/observers/types.js.map +1 -0
  113. package/build/consumer/observers.d.ts +6 -0
  114. package/build/consumer/observers.d.ts.map +1 -0
  115. package/build/consumer/observers.js +74 -0
  116. package/build/consumer/observers.js.map +1 -0
  117. package/build/consumer/origin/types.d.ts +17 -0
  118. package/build/consumer/origin/types.d.ts.map +1 -0
  119. package/build/consumer/origin/types.js +2 -0
  120. package/build/consumer/origin/types.js.map +1 -0
  121. package/build/consumer/origin.d.ts +8 -0
  122. package/build/consumer/origin.d.ts.map +1 -0
  123. package/build/consumer/origin.js +43 -0
  124. package/build/consumer/origin.js.map +1 -0
  125. package/build/consumer/reconcile/types.d.ts +13 -0
  126. package/build/consumer/reconcile/types.d.ts.map +1 -0
  127. package/build/consumer/reconcile/types.js +2 -0
  128. package/build/consumer/reconcile/types.js.map +1 -0
  129. package/build/consumer/reconcile.d.ts +5 -0
  130. package/build/consumer/reconcile.d.ts.map +1 -0
  131. package/build/consumer/reconcile.js +320 -0
  132. package/build/consumer/reconcile.js.map +1 -0
  133. package/build/consumer/records/types.d.ts +66 -0
  134. package/build/consumer/records/types.d.ts.map +1 -0
  135. package/build/consumer/records/types.js +2 -0
  136. package/build/consumer/records/types.js.map +1 -0
  137. package/build/consumer/records.d.ts +6 -0
  138. package/build/consumer/records.d.ts.map +1 -0
  139. package/build/consumer/records.js +243 -0
  140. package/build/consumer/records.js.map +1 -0
  141. package/build/consumer/service.d.ts +28 -0
  142. package/build/consumer/service.d.ts.map +1 -0
  143. package/build/consumer/service.js +706 -0
  144. package/build/consumer/service.js.map +1 -0
  145. package/build/consumer/types.d.ts +84 -0
  146. package/build/consumer/types.d.ts.map +1 -0
  147. package/build/consumer/types.js +2 -0
  148. package/build/consumer/types.js.map +1 -0
  149. package/build/consumer/types.local.d.ts +26 -0
  150. package/build/consumer/types.local.d.ts.map +1 -0
  151. package/build/consumer/types.local.js +2 -0
  152. package/build/consumer/types.local.js.map +1 -0
  153. package/build/consumer/withdrawal/types.d.ts +36 -0
  154. package/build/consumer/withdrawal/types.d.ts.map +1 -0
  155. package/build/consumer/withdrawal/types.js +2 -0
  156. package/build/consumer/withdrawal/types.js.map +1 -0
  157. package/build/consumer/withdrawal.d.ts +6 -0
  158. package/build/consumer/withdrawal.d.ts.map +1 -0
  159. package/build/consumer/withdrawal.js +237 -0
  160. package/build/consumer/withdrawal.js.map +1 -0
  161. package/build/entitlement.d.ts +4 -0
  162. package/build/entitlement.d.ts.map +1 -0
  163. package/build/entitlement.js +72 -0
  164. package/build/entitlement.js.map +1 -0
  165. package/build/entrypoints.d.ts +19 -2
  166. package/build/entrypoints.d.ts.map +1 -1
  167. package/build/entrypoints.js +16 -4
  168. package/build/entrypoints.js.map +1 -1
  169. package/build/gate/request.d.ts +4 -0
  170. package/build/gate/request.d.ts.map +1 -0
  171. package/build/gate/request.js +17 -0
  172. package/build/gate/request.js.map +1 -0
  173. package/build/gate/types.d.ts +15 -0
  174. package/build/gate/types.d.ts.map +1 -0
  175. package/build/gate/types.js +2 -0
  176. package/build/gate/types.js.map +1 -0
  177. package/build/gate.d.ts +13 -9
  178. package/build/gate.d.ts.map +1 -1
  179. package/build/gate.js +36 -21
  180. package/build/gate.js.map +1 -1
  181. package/build/index.d.ts +50 -3
  182. package/build/index.d.ts.map +1 -1
  183. package/build/index.js +29 -3
  184. package/build/index.js.map +1 -1
  185. package/build/limit.d.ts +11 -0
  186. package/build/limit.d.ts.map +1 -0
  187. package/build/limit.js +48 -0
  188. package/build/limit.js.map +1 -0
  189. package/build/log.d.ts +3 -0
  190. package/build/log.d.ts.map +1 -0
  191. package/build/log.js +4 -0
  192. package/build/log.js.map +1 -0
  193. package/build/models/declarations/types.d.ts +22 -0
  194. package/build/models/declarations/types.d.ts.map +1 -0
  195. package/build/models/declarations/types.js +2 -0
  196. package/build/models/declarations/types.js.map +1 -0
  197. package/build/models/declarations.d.ts +4 -0
  198. package/build/models/declarations.d.ts.map +1 -0
  199. package/build/models/declarations.js +26 -0
  200. package/build/models/declarations.js.map +1 -0
  201. package/build/models/purchase/types.d.ts +13 -0
  202. package/build/models/purchase/types.d.ts.map +1 -0
  203. package/build/models/purchase/types.js +2 -0
  204. package/build/models/purchase/types.js.map +1 -0
  205. package/build/models/purchase.d.ts +4 -0
  206. package/build/models/purchase.d.ts.map +1 -0
  207. package/build/models/purchase.js +37 -0
  208. package/build/models/purchase.js.map +1 -0
  209. package/build/observer.d.ts +9 -0
  210. package/build/observer.d.ts.map +1 -1
  211. package/build/observer.js +38 -12
  212. package/build/observer.js.map +1 -1
  213. package/build/plan/types.d.ts +21 -0
  214. package/build/plan/types.d.ts.map +1 -0
  215. package/build/plan/types.js +2 -0
  216. package/build/plan/types.js.map +1 -0
  217. package/build/plan.d.ts +7 -0
  218. package/build/plan.d.ts.map +1 -0
  219. package/build/plan.js +29 -0
  220. package/build/plan.js.map +1 -0
  221. package/build/plugins/checkout-plugins/types.d.ts +25 -0
  222. package/build/plugins/checkout-plugins/types.d.ts.map +1 -0
  223. package/build/plugins/checkout-plugins/types.js +2 -0
  224. package/build/plugins/checkout-plugins/types.js.map +1 -0
  225. package/build/plugins/checkout-plugins.d.ts +12 -0
  226. package/build/plugins/checkout-plugins.d.ts.map +1 -0
  227. package/build/plugins/checkout-plugins.js +72 -0
  228. package/build/plugins/checkout-plugins.js.map +1 -0
  229. package/build/plugins/checkout-policy/types.d.ts +18 -0
  230. package/build/plugins/checkout-policy/types.d.ts.map +1 -0
  231. package/build/plugins/checkout-policy/types.js +2 -0
  232. package/build/plugins/checkout-policy/types.js.map +1 -0
  233. package/build/plugins/checkout-policy.d.ts +4 -0
  234. package/build/plugins/checkout-policy.d.ts.map +1 -0
  235. package/build/plugins/checkout-policy.js +26 -0
  236. package/build/plugins/checkout-policy.js.map +1 -0
  237. package/build/plugins/checkout-registry/types.d.ts +7 -0
  238. package/build/plugins/checkout-registry/types.d.ts.map +1 -0
  239. package/build/plugins/checkout-registry/types.js +2 -0
  240. package/build/plugins/checkout-registry/types.js.map +1 -0
  241. package/build/plugins/checkout-registry.d.ts +8 -0
  242. package/build/plugins/checkout-registry.d.ts.map +1 -0
  243. package/build/plugins/checkout-registry.js +21 -0
  244. package/build/plugins/checkout-registry.js.map +1 -0
  245. package/build/plugins/consts.local.d.ts +13 -0
  246. package/build/plugins/consts.local.d.ts.map +1 -0
  247. package/build/plugins/consts.local.js +22 -0
  248. package/build/plugins/consts.local.js.map +1 -0
  249. package/build/plugins/customer-lock/types.d.ts +6 -0
  250. package/build/plugins/customer-lock/types.d.ts.map +1 -0
  251. package/build/plugins/customer-lock/types.js +2 -0
  252. package/build/plugins/customer-lock/types.js.map +1 -0
  253. package/build/plugins/customer-lock.d.ts +5 -0
  254. package/build/plugins/customer-lock.d.ts.map +1 -0
  255. package/build/plugins/customer-lock.js +22 -0
  256. package/build/plugins/customer-lock.js.map +1 -0
  257. package/build/plugins/estimate/cache.d.ts +4 -0
  258. package/build/plugins/estimate/cache.d.ts.map +1 -0
  259. package/build/plugins/estimate/cache.js +7 -0
  260. package/build/plugins/estimate/cache.js.map +1 -0
  261. package/build/plugins/estimate/types.d.ts +27 -0
  262. package/build/plugins/estimate/types.d.ts.map +1 -0
  263. package/build/plugins/estimate/types.js +2 -0
  264. package/build/plugins/estimate/types.js.map +1 -0
  265. package/build/plugins/estimate.d.ts +6 -0
  266. package/build/plugins/estimate.d.ts.map +1 -0
  267. package/build/plugins/estimate.js +271 -0
  268. package/build/plugins/estimate.js.map +1 -0
  269. package/build/plugins/events/types.d.ts +12 -0
  270. package/build/plugins/events/types.d.ts.map +1 -0
  271. package/build/plugins/events/types.js +2 -0
  272. package/build/plugins/events/types.js.map +1 -0
  273. package/build/plugins/events.d.ts +6 -13
  274. package/build/plugins/events.d.ts.map +1 -1
  275. package/build/plugins/events.js +441 -144
  276. package/build/plugins/events.js.map +1 -1
  277. package/build/plugins/fx/types.d.ts +33 -0
  278. package/build/plugins/fx/types.d.ts.map +1 -0
  279. package/build/plugins/fx/types.js +2 -0
  280. package/build/plugins/fx/types.js.map +1 -0
  281. package/build/plugins/fx.d.ts +6 -0
  282. package/build/plugins/fx.d.ts.map +1 -0
  283. package/build/plugins/fx.js +83 -0
  284. package/build/plugins/fx.js.map +1 -0
  285. package/build/plugins/portal/types.d.ts +44 -0
  286. package/build/plugins/portal/types.d.ts.map +1 -0
  287. package/build/plugins/portal/types.js +2 -0
  288. package/build/plugins/portal/types.js.map +1 -0
  289. package/build/plugins/portal.d.ts +6 -0
  290. package/build/plugins/portal.d.ts.map +1 -0
  291. package/build/plugins/portal.js +255 -0
  292. package/build/plugins/portal.js.map +1 -0
  293. package/build/plugins/refunds/types.d.ts +35 -0
  294. package/build/plugins/refunds/types.d.ts.map +1 -0
  295. package/build/plugins/refunds/types.js +2 -0
  296. package/build/plugins/refunds/types.js.map +1 -0
  297. package/build/plugins/refunds.d.ts +6 -0
  298. package/build/plugins/refunds.d.ts.map +1 -0
  299. package/build/plugins/refunds.js +81 -0
  300. package/build/plugins/refunds.js.map +1 -0
  301. package/build/plugins/session/types.d.ts +32 -0
  302. package/build/plugins/session/types.d.ts.map +1 -0
  303. package/build/plugins/session/types.js +2 -0
  304. package/build/plugins/session/types.js.map +1 -0
  305. package/build/plugins/session.d.ts +4 -0
  306. package/build/plugins/session.d.ts.map +1 -0
  307. package/build/plugins/session.js +58 -0
  308. package/build/plugins/session.js.map +1 -0
  309. package/build/plugins/status.d.ts +8 -0
  310. package/build/plugins/status.d.ts.map +1 -0
  311. package/build/plugins/status.js +21 -0
  312. package/build/plugins/status.js.map +1 -0
  313. package/build/plugins/stripe/types.d.ts +20 -0
  314. package/build/plugins/stripe/types.d.ts.map +1 -0
  315. package/build/plugins/stripe/types.js +2 -0
  316. package/build/plugins/stripe/types.js.map +1 -0
  317. package/build/plugins/stripe.d.ts +5 -13
  318. package/build/plugins/stripe.d.ts.map +1 -1
  319. package/build/plugins/stripe.js +481 -129
  320. package/build/plugins/stripe.js.map +1 -1
  321. package/build/plugins/subscriptions/types.d.ts +41 -0
  322. package/build/plugins/subscriptions/types.d.ts.map +1 -0
  323. package/build/plugins/subscriptions/types.js +2 -0
  324. package/build/plugins/subscriptions/types.js.map +1 -0
  325. package/build/plugins/subscriptions.d.ts +6 -0
  326. package/build/plugins/subscriptions.d.ts.map +1 -0
  327. package/build/plugins/subscriptions.js +169 -0
  328. package/build/plugins/subscriptions.js.map +1 -0
  329. package/build/plugins/types.d.ts +7 -0
  330. package/build/plugins/types.d.ts.map +1 -0
  331. package/build/plugins/types.js +2 -0
  332. package/build/plugins/types.js.map +1 -0
  333. package/build/plugins/types.local.d.ts +75 -0
  334. package/build/plugins/types.local.d.ts.map +1 -0
  335. package/build/plugins/types.local.js +2 -0
  336. package/build/plugins/types.local.js.map +1 -0
  337. package/build/plugins/webhook-manager/types.d.ts +62 -0
  338. package/build/plugins/webhook-manager/types.d.ts.map +1 -0
  339. package/build/plugins/webhook-manager/types.js +2 -0
  340. package/build/plugins/webhook-manager/types.js.map +1 -0
  341. package/build/plugins/webhook-manager.d.ts +8 -0
  342. package/build/plugins/webhook-manager.d.ts.map +1 -0
  343. package/build/plugins/webhook-manager.js +245 -0
  344. package/build/plugins/webhook-manager.js.map +1 -0
  345. package/build/protocol.d.ts +13 -0
  346. package/build/protocol.d.ts.map +1 -0
  347. package/build/protocol.js +17 -0
  348. package/build/protocol.js.map +1 -0
  349. package/build/reconcile/types.d.ts +17 -0
  350. package/build/reconcile/types.d.ts.map +1 -0
  351. package/build/reconcile/types.js +2 -0
  352. package/build/reconcile/types.js.map +1 -0
  353. package/build/reconcile.d.ts +12 -0
  354. package/build/reconcile.d.ts.map +1 -0
  355. package/build/reconcile.js +91 -0
  356. package/build/reconcile.js.map +1 -0
  357. package/build/resource.d.ts +12 -1
  358. package/build/resource.d.ts.map +1 -1
  359. package/build/resource.js +97 -6
  360. package/build/resource.js.map +1 -1
  361. package/build/schemas.d.ts +19 -0
  362. package/build/schemas.d.ts.map +1 -0
  363. package/build/schemas.js +244 -0
  364. package/build/schemas.js.map +1 -0
  365. package/build/service.d.ts +28 -3
  366. package/build/service.d.ts.map +1 -1
  367. package/build/service.js +140 -19
  368. package/build/service.js.map +1 -1
  369. package/build/subscription/types.d.ts +21 -0
  370. package/build/subscription/types.d.ts.map +1 -0
  371. package/build/subscription/types.js +2 -0
  372. package/build/subscription/types.js.map +1 -0
  373. package/build/subscription.d.ts +4 -0
  374. package/build/subscription.d.ts.map +1 -0
  375. package/build/subscription.js +84 -0
  376. package/build/subscription.js.map +1 -0
  377. package/build/sync/types.d.ts +25 -0
  378. package/build/sync/types.d.ts.map +1 -0
  379. package/build/sync/types.js +2 -0
  380. package/build/sync/types.js.map +1 -0
  381. package/build/sync.d.ts +4 -3
  382. package/build/sync.d.ts.map +1 -1
  383. package/build/sync.js +231 -79
  384. package/build/sync.js.map +1 -1
  385. package/build/types.d.ts +1258 -36
  386. package/build/types.d.ts.map +1 -1
  387. package/build/types.local.d.ts +22 -0
  388. package/build/types.local.d.ts.map +1 -0
  389. package/build/types.local.js +2 -0
  390. package/build/types.local.js.map +1 -0
  391. package/build/usage/types.d.ts +56 -0
  392. package/build/usage/types.d.ts.map +1 -0
  393. package/build/usage/types.js +2 -0
  394. package/build/usage/types.js.map +1 -0
  395. package/build/usage.d.ts +6 -0
  396. package/build/usage.d.ts.map +1 -0
  397. package/build/usage.js +365 -0
  398. package/build/usage.js.map +1 -0
  399. package/build/utils/types.d.ts +31 -0
  400. package/build/utils/types.d.ts.map +1 -0
  401. package/build/utils/types.js +2 -0
  402. package/build/utils/types.js.map +1 -0
  403. package/build/utils.d.ts +21 -7
  404. package/build/utils.d.ts.map +1 -1
  405. package/build/utils.js +56 -17
  406. package/build/utils.js.map +1 -1
  407. package/package.json +22 -17
  408. package/src/access/types.ts +52 -0
  409. package/src/access.ts +86 -0
  410. package/src/actions/index.ts +1 -0
  411. package/src/actions/resync-subscriptions.ts +10 -0
  412. package/src/actions/resync.ts +14 -5
  413. package/src/actions/webhook.ts +9 -4
  414. package/src/bootstrap/types.ts +16 -0
  415. package/src/bootstrap.ts +31 -0
  416. package/src/catalogue/types.ts +32 -0
  417. package/src/catalogue.ts +135 -0
  418. package/src/commit/types.ts +27 -0
  419. package/src/commit.ts +152 -0
  420. package/src/config.ts +234 -14
  421. package/src/consts.local.ts +62 -0
  422. package/src/consts.ts +100 -36
  423. package/src/consumer/cancellation/types.ts +13 -0
  424. package/src/consumer/cancellation.ts +43 -0
  425. package/src/consumer/capture/types.ts +53 -0
  426. package/src/consumer/capture.ts +321 -0
  427. package/src/consumer/consts.local.ts +18 -0
  428. package/src/consumer/format/types.ts +29 -0
  429. package/src/consumer/format.ts +85 -0
  430. package/src/consumer/handlers.ts +204 -0
  431. package/src/consumer/index.ts +9 -0
  432. package/src/consumer/mail/types.ts +31 -0
  433. package/src/consumer/mail.ts +353 -0
  434. package/src/consumer/observers/types.ts +22 -0
  435. package/src/consumer/observers.ts +97 -0
  436. package/src/consumer/origin/types.ts +17 -0
  437. package/src/consumer/origin.ts +61 -0
  438. package/src/consumer/reconcile/types.ts +13 -0
  439. package/src/consumer/reconcile.ts +330 -0
  440. package/src/consumer/records/types.ts +64 -0
  441. package/src/consumer/records.ts +288 -0
  442. package/src/consumer/service.ts +768 -0
  443. package/src/consumer/types.local.ts +22 -0
  444. package/src/consumer/types.ts +96 -0
  445. package/src/consumer/withdrawal/types.ts +37 -0
  446. package/src/consumer/withdrawal.ts +268 -0
  447. package/src/entitlement.ts +85 -0
  448. package/src/entrypoints.ts +17 -4
  449. package/src/gate/request.ts +24 -0
  450. package/src/gate/types.ts +13 -0
  451. package/src/gate.ts +47 -30
  452. package/src/index.ts +55 -3
  453. package/src/limit.ts +54 -0
  454. package/src/log.ts +4 -0
  455. package/src/models/declarations/types.ts +22 -0
  456. package/src/models/declarations.ts +30 -0
  457. package/src/models/purchase/types.ts +13 -0
  458. package/src/models/purchase.ts +43 -0
  459. package/src/observer.ts +44 -11
  460. package/src/plan/types.ts +21 -0
  461. package/src/plan.ts +46 -0
  462. package/src/plugins/checkout-plugins/types.ts +25 -0
  463. package/src/plugins/checkout-plugins.ts +90 -0
  464. package/src/plugins/checkout-policy/types.ts +18 -0
  465. package/src/plugins/checkout-policy.ts +34 -0
  466. package/src/plugins/checkout-registry/types.ts +7 -0
  467. package/src/plugins/checkout-registry.ts +23 -0
  468. package/src/plugins/consts.local.ts +30 -0
  469. package/src/plugins/customer-lock/types.ts +5 -0
  470. package/src/plugins/customer-lock.ts +25 -0
  471. package/src/plugins/estimate/cache.ts +12 -0
  472. package/src/plugins/estimate/types.ts +28 -0
  473. package/src/plugins/estimate.ts +305 -0
  474. package/src/plugins/events/types.ts +11 -0
  475. package/src/plugins/events.ts +466 -132
  476. package/src/plugins/fx/types.ts +40 -0
  477. package/src/plugins/fx.ts +101 -0
  478. package/src/plugins/portal/types.ts +45 -0
  479. package/src/plugins/portal.ts +284 -0
  480. package/src/plugins/refunds/types.ts +31 -0
  481. package/src/plugins/refunds.ts +95 -0
  482. package/src/plugins/session/types.ts +28 -0
  483. package/src/plugins/session.ts +73 -0
  484. package/src/plugins/status.ts +22 -0
  485. package/src/plugins/stripe/types.ts +20 -0
  486. package/src/plugins/stripe.ts +523 -135
  487. package/src/plugins/subscriptions/types.ts +39 -0
  488. package/src/plugins/subscriptions.ts +195 -0
  489. package/src/plugins/types.local.ts +61 -0
  490. package/src/plugins/types.ts +7 -0
  491. package/src/plugins/webhook-manager/types.ts +63 -0
  492. package/src/plugins/webhook-manager.ts +288 -0
  493. package/src/protocol.ts +29 -0
  494. package/src/reconcile/types.ts +17 -0
  495. package/src/reconcile.ts +110 -0
  496. package/src/resource.ts +158 -11
  497. package/src/schemas.ts +271 -0
  498. package/src/service.ts +161 -19
  499. package/src/subscription/types.ts +23 -0
  500. package/src/subscription.ts +104 -0
  501. package/src/sync/types.ts +25 -0
  502. package/src/sync.ts +255 -72
  503. package/src/types.local.ts +18 -0
  504. package/src/types.ts +1365 -32
  505. package/src/usage/types.ts +51 -0
  506. package/src/usage.ts +432 -0
  507. package/src/utils/types.ts +30 -0
  508. package/src/utils.ts +94 -29
  509. package/tests/checkout-consumer.spec.ts +366 -0
  510. package/tests/checkout-locks.spec.ts +161 -0
  511. package/tests/checkout-plugins.spec.ts +164 -0
  512. package/tests/checkout.spec.ts +209 -93
  513. package/tests/consumer-events.spec.ts +215 -0
  514. package/tests/consumer-fixtures.ts +134 -0
  515. package/tests/consumer-ops.spec.ts +350 -0
  516. package/tests/consumer-rights.integration.spec.ts +147 -0
  517. package/tests/consumer-rights.spec.ts +572 -0
  518. package/tests/context.ts +110 -0
  519. package/tests/entitlement.spec.ts +139 -0
  520. package/tests/estimate.spec.ts +350 -0
  521. package/tests/events.spec.ts +357 -0
  522. package/tests/fake-stripe.ts +981 -0
  523. package/tests/gate-handlers.spec.ts +120 -0
  524. package/tests/gate.spec.ts +63 -72
  525. package/tests/gateway-options.spec.ts +180 -0
  526. package/tests/limit-gate.spec.ts +66 -0
  527. package/tests/portal.spec.ts +202 -0
  528. package/tests/protocol.spec.ts +17 -3
  529. package/tests/sync.spec.ts +114 -0
  530. package/tests/usage.integration.spec.ts +133 -0
  531. package/tests/usage.spec.ts +169 -0
  532. package/tests/webhook-manager.spec.ts +149 -0
  533. package/build/model.d.ts +0 -6
  534. package/build/model.d.ts.map +0 -1
  535. package/build/model.js +0 -33
  536. package/build/model.js.map +0 -1
  537. package/src/model.ts +0 -37
@@ -0,0 +1,15 @@
1
+ import type { CancellationStatus, WithdrawalStatus } from '@owlmeans/payment';
2
+ import type { ConsumerConsentRecord, ConsumerDeclarationRecord, PurchaseRecord } from '../../types.js';
3
+ import type { WithdrawalComputation, WithdrawalExecution } from '../types.js';
4
+ /** The consumer-rights observers of a context, told after the records and the paygate steps of an act. */
5
+ export interface ConsumerObserversHelper {
6
+ /** Run the consumer-rights observers of one act; a throw is recorded for `reconcile` to retry. */
7
+ runConsumerObservers: (family: 'consent' | 'withdrawal' | 'cancellation', recordId: string, entityId: string | undefined, run: () => Promise<void>) => Promise<boolean>;
8
+ /** Tell the withdrawal observers — after the records and the paygate steps. */
9
+ notifyWithdrawal: (declaration: ConsumerDeclarationRecord, purchase: PurchaseRecord, status: WithdrawalStatus, computation: Pick<WithdrawalComputation, 'reading' | 'deducted' | 'unitsReturned' | 'netMinor' | 'refundMinor'> | null, execution: WithdrawalExecution | null) => Promise<boolean>;
10
+ /** Tell the cancellation observers. */
11
+ notifyCancellation: (declaration: ConsumerDeclarationRecord, status: CancellationStatus) => Promise<boolean>;
12
+ /** Tell the consent observers. */
13
+ notifyConsent: (consent: ConsumerConsentRecord) => Promise<boolean>;
14
+ }
15
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/consumer/observers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAC7E,OAAO,KAAK,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACtG,OAAO,KAAK,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAE7E,0GAA0G;AAC1G,MAAM,WAAW,uBAAuB;IACtC,kGAAkG;IAClG,oBAAoB,EAAE,CACpB,MAAM,EAAE,SAAS,GAAG,YAAY,GAAG,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,EACjG,GAAG,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KACrB,OAAO,CAAC,OAAO,CAAC,CAAA;IACrB,+EAA+E;IAC/E,gBAAgB,EAAE,CAChB,WAAW,EAAE,yBAAyB,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,gBAAgB,EAC1F,WAAW,EAAE,IAAI,CAAC,qBAAqB,EAAE,SAAS,GAAG,UAAU,GAAG,eAAe,GAAG,UAAU,GAAG,aAAa,CAAC,GAAG,IAAI,EACtH,SAAS,EAAE,mBAAmB,GAAG,IAAI,KAClC,OAAO,CAAC,OAAO,CAAC,CAAA;IACrB,uCAAuC;IACvC,kBAAkB,EAAE,CAAC,WAAW,EAAE,yBAAyB,EAAE,MAAM,EAAE,kBAAkB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5G,kCAAkC;IAClC,aAAa,EAAE,CAAC,OAAO,EAAE,qBAAqB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CACpE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/consumer/observers/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import type { Context as ApiContext } from '@owlmeans/server-api';
2
+ import type { ConsumerObserversHelper } from './observers/types.js';
3
+ export declare const makeConsumerObserversHelper: (ctx: ApiContext) => ConsumerObserversHelper;
4
+ /** The consumer-rights observers of a context — one per context. */
5
+ export declare const consumerObserversOf: (target: ApiContext<import("@owlmeans/server-api").Config>) => ConsumerObserversHelper;
6
+ //# sourceMappingURL=observers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observers.d.ts","sourceRoot":"","sources":["../../src/consumer/observers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAWjE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AAEnE,eAAO,MAAM,2BAA2B,QAAS,UAAU,KAAG,uBA+E7D,CAAA;AAED,oEAAoE;AACpE,eAAO,MAAM,mBAAmB,wFAAkD,CAAA"}
@@ -0,0 +1,74 @@
1
+ import { CancellationKind } from '@owlmeans/payment';
2
+ import { memoHelper } from '@owlmeans/context';
3
+ import { log } from '../log.js';
4
+ import { paymentAccessOf } from '../access.js';
5
+ import { paymentUtils } from '../utils.js';
6
+ import { consumerRecordsOf } from './records.js';
7
+ import { makePurchaseModel } from '../models/purchase.js';
8
+ export const makeConsumerObserversHelper = (ctx) => {
9
+ const access = paymentAccessOf(ctx);
10
+ const records = consumerRecordsOf(ctx);
11
+ const runConsumerObservers = async (family, recordId, entityId, run) => {
12
+ const recordKind = family === 'consent' ? 'consent' : 'declaration';
13
+ try {
14
+ await run();
15
+ await records.recordEvent({ recordId, recordKind, entityId, action: 'observers', step: family, ok: true });
16
+ return true;
17
+ }
18
+ catch (error) {
19
+ log.error('Consumer-rights observers failed; reconcile retries them', { family, recordId, error });
20
+ await records.recordEvent({
21
+ recordId, recordKind, entityId, action: 'observers', step: family, ok: false, error: paymentUtils.errorText(error),
22
+ });
23
+ return false;
24
+ }
25
+ };
26
+ const notifyWithdrawal = async (declaration, purchase, status, computation, execution) => await runConsumerObservers('withdrawal', declaration.id, purchase.entityId, async () => {
27
+ await access.observer().propagateWithdrawal({
28
+ withdrawalId: declaration.id,
29
+ eventKey: `withdrawal:${declaration.id}`,
30
+ entityId: purchase.entityId,
31
+ channel: declaration.channel,
32
+ purchase: makePurchaseModel(purchase).ref(),
33
+ declaredAt: new Date(declaration.receivedAt),
34
+ status,
35
+ refund: paymentUtils.compact({
36
+ amountMinor: execution?.refundedMinor ?? 0,
37
+ currency: purchase.currency,
38
+ netMinor: computation?.netMinor,
39
+ refundId: execution?.refundId,
40
+ creditNoteId: execution?.creditNoteId,
41
+ }),
42
+ units: computation != null
43
+ ? { granted: computation.reading.granted, used: computation.deducted, returned: computation.unitsReturned } : null,
44
+ subscriptionCanceled: execution?.subscriptionCanceled === true,
45
+ }, ctx);
46
+ });
47
+ const notifyCancellation = async (declaration, status) => await runConsumerObservers('cancellation', declaration.id, declaration.entityId ?? undefined, async () => {
48
+ await access.observer().propagateCancellation(paymentUtils.compact({
49
+ cancellationId: declaration.id,
50
+ eventKey: `cancellation:${declaration.id}`,
51
+ entityId: declaration.entityId ?? undefined,
52
+ matched: declaration.matched,
53
+ channel: declaration.channel,
54
+ kind: declaration.cancellationKind ?? CancellationKind.Ordinary,
55
+ status,
56
+ subscriptionId: declaration.subscriptionId ?? undefined,
57
+ effectiveAt: declaration.effectiveAt != null ? new Date(declaration.effectiveAt) : undefined,
58
+ declaredAt: new Date(declaration.receivedAt),
59
+ }), ctx);
60
+ });
61
+ const notifyConsent = async (consent) => await runConsumerObservers('consent', consent.id, consent.entityId, async () => {
62
+ await access.observer().propagateConsent(paymentUtils.compact({
63
+ kind: consent.kind, consentId: consent.id, entityId: consent.entityId, profileId: consent.profileId,
64
+ purchaseIds: [...consent.purchaseIds], planSku: consent.planSku, textVersion: consent.textVersion,
65
+ language: consent.language, decidedAt: new Date(consent.decidedAt),
66
+ expiresAt: consent.expiresAt != null ? new Date(consent.expiresAt) : undefined,
67
+ eventKey: `consent:${consent.id}`,
68
+ }), ctx);
69
+ });
70
+ return { runConsumerObservers, notifyWithdrawal, notifyCancellation, notifyConsent };
71
+ };
72
+ /** The consumer-rights observers of a context — one per context. */
73
+ export const consumerObserversOf = memoHelper.oncePer(makeConsumerObserversHelper);
74
+ //# sourceMappingURL=observers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observers.js","sourceRoot":"","sources":["../../src/consumer/observers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAwC,MAAM,mBAAmB,CAAA;AAE1F,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAK9C,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAGzD,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,GAAe,EAA2B,EAAE;IACtF,MAAM,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,CAAA;IACnC,MAAM,OAAO,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAA;IAEtC,MAAM,oBAAoB,GAAG,KAAK,EAChC,MAAiD,EAAE,QAAgB,EAAE,QAA4B,EACjG,GAAwB,EACN,EAAE;QACpB,MAAM,UAAU,GAAG,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAkB,CAAC,CAAC,CAAC,aAAsB,CAAA;QACrF,IAAI,CAAC;YACH,MAAM,GAAG,EAAE,CAAA;YACX,MAAM,OAAO,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;YAE1G,OAAO,IAAI,CAAA;QAC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AG,KAAK,EAAE,OAA8B,EAAoB,EAAE,CAC/E,MAAM,oBAAoB,CAAC,SAAS,EAAE,OAAO,CAAC,EAAY,EAAE,OAAO,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;QACvF,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAC,gBAAgB,CAAC,YAAY,CAAC,OAAO,CAAC;YAC5D,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,EAAY,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS;YAC7G,WAAW,EAAE,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW;YACjG,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;YAClE,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS;YAC9E,QAAQ,EAAE,WAAW,OAAO,CAAC,EAAY,EAAE;SAC5C,CAAiB,EAAE,GAAG,CAAC,CAAA;IAC1B,CAAC,CAAC,CAAA;IAEJ,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,aAAa,EAAE,CAAA;AACtF,CAAC,CAAA;AAED,oEAAoE;AACpE,MAAM,CAAC,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAA"}
@@ -0,0 +1,17 @@
1
+ import type { AbstractRequest } from '@owlmeans/entrypoint';
2
+ import type { RequestOrigin } from '../../types.js';
3
+ /** The request evidence a consumer act is recorded with. */
4
+ export interface OriginHelper {
5
+ /**
6
+ * The evidence a consumer act is recorded with. `ip` is `cf-connecting-ip` (a Cloudflare edge
7
+ * sets it and strips a client's own), else the LAST `x-forwarded-for` entry (the one the nearest
8
+ * proxy appended — the first is whatever the client claimed), else `x-real-ip`, else the socket
9
+ * peer. The raw `x-forwarded-for`, the `user-agent` (at most 512 characters), `cf-ipcountry`
10
+ * (the geolocated country — second location evidence for VAT) and `accept-language` are kept as
11
+ * they arrived. The default `metaOf` of the consumer-rights handlers.
12
+ */
13
+ requestOriginOf: (req: AbstractRequest) => RequestOrigin;
14
+ /** The origin fields of a record: only those with a value. */
15
+ originFields: (origin: RequestOrigin | undefined) => RequestOrigin;
16
+ }
17
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/consumer/origin/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnD,4DAA4D;AAC5D,MAAM,WAAW,YAAY;IAC3B;;;;;;;OAOG;IACH,eAAe,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,aAAa,CAAA;IACxD,8DAA8D;IAC9D,YAAY,EAAE,CAAC,MAAM,EAAE,aAAa,GAAG,SAAS,KAAK,aAAa,CAAA;CACnE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/consumer/origin/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import type { AbstractRequest } from '@owlmeans/entrypoint';
2
+ import type { RequestOrigin } from '../types.js';
3
+ import type { OriginHelper } from './origin/types.js';
4
+ export declare const createOriginHelper: () => OriginHelper;
5
+ export declare const originHelper: OriginHelper;
6
+ /** @deprecated compat:factory-refactor — use `originHelper.requestOriginOf(…)` */
7
+ export declare const requestOriginOf: (req: AbstractRequest) => RequestOrigin;
8
+ //# sourceMappingURL=origin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"origin.d.ts","sourceRoot":"","sources":["../../src/consumer/origin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAGhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,eAAO,MAAM,kBAAkB,QAAO,YAiDrC,CAAA;AAED,eAAO,MAAM,YAAY,cAAuB,CAAA;AAEhD,kFAAkF;AAClF,eAAO,MAAM,eAAe,QAAS,eAAe,KAAG,aAAkD,CAAA"}
@@ -0,0 +1,43 @@
1
+ import { HEADER_MAX, USER_AGENT_MAX } from './consts.local.js';
2
+ export const createOriginHelper = () => {
3
+ /** A header's first value (Fastify lower-cases names; a repeated header arrives as an array). */
4
+ const headerOf = (headers, name) => {
5
+ const raw = headers?.[name];
6
+ const value = Array.isArray(raw) ? raw[0] : raw;
7
+ if (typeof value !== 'string') {
8
+ return undefined;
9
+ }
10
+ const trimmed = value.trim();
11
+ return trimmed === '' ? undefined : trimmed;
12
+ };
13
+ /** The socket peer of the original server request, when the transport exposes one. */
14
+ const socketOf = (req) => {
15
+ const original = req.original;
16
+ const address = original?.socket?.remoteAddress ?? original?.raw?.socket?.remoteAddress ?? original?.ip;
17
+ return typeof address === 'string' && address !== '' ? address : undefined;
18
+ };
19
+ const requestOriginOf = (req) => {
20
+ const headers = req.headers;
21
+ const forwardedFor = headerOf(headers, 'x-forwarded-for');
22
+ const forwarded = forwardedFor?.split(',').map(entry => entry.trim()).filter(entry => entry !== '');
23
+ const ip = headerOf(headers, 'cf-connecting-ip') ?? forwarded?.[forwarded.length - 1]
24
+ ?? headerOf(headers, 'x-real-ip') ?? socketOf(req);
25
+ const userAgent = headerOf(headers, 'user-agent');
26
+ const ipCountry = headerOf(headers, 'cf-ipcountry');
27
+ const acceptLanguage = headerOf(headers, 'accept-language');
28
+ return {
29
+ ...(ip != null ? { ip: ip.slice(0, HEADER_MAX) } : {}),
30
+ ...(forwardedFor != null ? { forwardedFor: forwardedFor.slice(0, HEADER_MAX) } : {}),
31
+ ...(userAgent != null ? { userAgent: userAgent.slice(0, USER_AGENT_MAX) } : {}),
32
+ ...(ipCountry != null && /^[A-Za-z]{2}$/.test(ipCountry) ? { ipCountry: ipCountry.toUpperCase() } : {}),
33
+ ...(acceptLanguage != null ? { acceptLanguage: acceptLanguage.slice(0, 256) } : {}),
34
+ };
35
+ };
36
+ const originFields = (origin) => Object.fromEntries(Object.entries(origin ?? {}).filter(([key, value]) => ['ip', 'forwardedFor', 'userAgent', 'ipCountry', 'acceptLanguage', 'via'].includes(key)
37
+ && typeof value === 'string' && value !== ''));
38
+ return { requestOriginOf, originFields };
39
+ };
40
+ export const originHelper = createOriginHelper();
41
+ /** @deprecated compat:factory-refactor — use `originHelper.requestOriginOf(…)` */
42
+ export const requestOriginOf = (req) => originHelper.requestOriginOf(req);
43
+ //# sourceMappingURL=origin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"origin.js","sourceRoot":"","sources":["../../src/consumer/origin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAI9D,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAiB,EAAE;IACnD,iGAAiG;IACjG,MAAM,QAAQ,GAAG,CAAC,OAA4B,EAAE,IAAY,EAAsB,EAAE;QAClF,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC,IAAI,CAAC,CAAA;QAC3B,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAA;QAC/C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,SAAS,CAAA;QAClB,CAAC;QACD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,GAAG,CAAC;WACpF,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,CAAC,CAC/B,CAAA;IAElB,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,CAAA;AAC1C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,kBAAkB,EAAE,CAAA;AAEhD,kFAAkF;AAClF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAoB,EAAiB,EAAE,CAAC,YAAY,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA"}
@@ -0,0 +1,13 @@
1
+ import type { ConsumerReconcileOptions, ConsumerReconcileResult } from '../../types.js';
2
+ /** The consumer-rights repair of one service in a context. */
3
+ export interface ConsumerReconcileHelper {
4
+ /**
5
+ * The consumer-rights repair an application runs nightly: retry the paygate steps of withdrawals
6
+ * (refunds, credit notes, subscription cancels) and scheduled cancellations, failed mails and
7
+ * failed observers; backfill purchases of completed checkouts of the last 16 days that have no
8
+ * row; lock organizations that paid before countries were locked. The paygate steps, the
9
+ * backfill and the legacy locks need a managed service. Each step handles at most `limit` items.
10
+ */
11
+ reconcile: (opts?: ConsumerReconcileOptions) => Promise<ConsumerReconcileResult>;
12
+ }
13
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/consumer/reconcile/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAEvF,8DAA8D;AAC9D,MAAM,WAAW,uBAAuB;IACtC;;;;;;OAMG;IACH,SAAS,EAAE,CAAC,IAAI,CAAC,EAAE,wBAAwB,KAAK,OAAO,CAAC,uBAAuB,CAAC,CAAA;CACjF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/consumer/reconcile/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import type { Context as ApiContext } from '@owlmeans/server-api';
2
+ import type { ConsumerRightsInternals } from './types.js';
3
+ import type { ConsumerReconcileHelper } from './reconcile/types.js';
4
+ export declare const makeConsumerReconcileHelper: (ctx: ApiContext, internals: ConsumerRightsInternals) => ConsumerReconcileHelper;
5
+ //# sourceMappingURL=reconcile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconcile.d.ts","sourceRoot":"","sources":["../../src/consumer/reconcile.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEjE,OAAO,KAAK,EAAE,uBAAuB,EAAyB,MAAM,YAAY,CAAA;AAchF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AAEnE,eAAO,MAAM,2BAA2B,QACjC,UAAU,aAAa,uBAAuB,KAClD,uBAgTF,CAAA"}
@@ -0,0 +1,320 @@
1
+ import { MAILER_SERVICE } from '@owlmeans/mailer';
2
+ import { CancellationStatus, DeclarationKind, ENTITLING_STATUSES, PurchaseKind, WithdrawalStatus, } from '@owlmeans/payment';
3
+ import { PURCHASE_BACKFILL_DAYS, STRIPE_PAYGATE_ALIAS } from '../consts.js';
4
+ import { log } from '../log.js';
5
+ import { DAY_MS, MAX_ATTEMPTS } from './consts.local.js';
6
+ import { paymentAccessOf } from '../access.js';
7
+ import { paymentUtils } from '../utils.js';
8
+ import { consumerRecordsOf } from './records.js';
9
+ import { captureOf } from './capture.js';
10
+ import { consumerMailOf } from './mail.js';
11
+ import { consumerObserversOf } from './observers.js';
12
+ import { cancellationOf } from './cancellation.js';
13
+ import { withdrawalOf } from './withdrawal.js';
14
+ export const makeConsumerReconcileHelper = (ctx, internals) => {
15
+ const access = paymentAccessOf(ctx);
16
+ const records = consumerRecordsOf(ctx);
17
+ /** What `withdraw` computed for a declaration, read back from its `computed` event. */
18
+ const computedOf = async (withdrawalId) => {
19
+ const event = await access.consumerEvents().load({ recordId: withdrawalId, action: 'computed', ok: true });
20
+ if (event == null) {
21
+ return null;
22
+ }
23
+ const detail = JSON.parse(event.detail ?? '{}');
24
+ return {
25
+ reading: detail.reading ?? { granted: 0, used: 0, usedAfter: 0 },
26
+ deducted: detail.deducted ?? 0,
27
+ unitsReturned: detail.unitsReturned ?? 0,
28
+ netMinor: detail.netMinor ?? 0,
29
+ refundMinor: event.amountMinor ?? 0,
30
+ };
31
+ };
32
+ const failures = async (recordId, action) => await access.consumerEvents().count({ recordId, action, ok: false });
33
+ /** Every distinct (record, step) with a failed event since `since` and no success after all. */
34
+ const pendingSteps = async (action, since, limit) => {
35
+ const { items } = await access.consumerEvents().list({ action, ok: false, at: { $gte: since } }, {
36
+ size: limit * 4, sort: [{ field: 'at', order: 'desc' }],
37
+ });
38
+ const seen = new Set();
39
+ const pending = [];
40
+ for (const event of items) {
41
+ const key = `${event.recordId}:${event.step ?? ''}`;
42
+ if (seen.has(key))
43
+ continue;
44
+ seen.add(key);
45
+ if (!await records.hasEvent(event.recordId, action, event.step ?? undefined, true)) {
46
+ pending.push(event);
47
+ }
48
+ if (pending.length >= limit)
49
+ break;
50
+ }
51
+ return pending;
52
+ };
53
+ const retryWithdrawals = async (stripe, since, limit, result) => {
54
+ const { items } = await access.consumerDeclarations().list({
55
+ kind: DeclarationKind.Withdrawal, status: WithdrawalStatus.Processing, matched: true, receivedAt: { $gte: since },
56
+ }, { size: limit * 2, sort: [{ field: 'receivedAt', order: 'asc' }] });
57
+ let handled = 0;
58
+ for (const declaration of items) {
59
+ if (handled >= limit)
60
+ break;
61
+ const id = declaration.id;
62
+ const purchase = declaration.purchaseId != null ? await access.purchases().byPurchaseId(declaration.purchaseId) : null;
63
+ // A declaration that lost the race for its purchase is a duplicate — never executed.
64
+ if (purchase == null || purchase.withdrawalId !== id)
65
+ continue;
66
+ const computed = await computedOf(id);
67
+ const refundDone = (declaration.refundMinor ?? 0) <= 0 || await records.hasEvent(id, 'refund', undefined, true);
68
+ const cancelDone = purchase.kind !== PurchaseKind.Subscription
69
+ || await records.hasEvent(id, 'subscription-cancel', undefined, true);
70
+ if (refundDone && cancelDone) {
71
+ const refundEvent = await access.consumerEvents().load({ recordId: id, action: 'refund', ok: true });
72
+ const noteFailed = await access.consumerEvents().load({ recordId: id, action: 'credit-note', ok: false, step: null });
73
+ if (refundEvent?.externalId != null && noteFailed != null && computed != null
74
+ && !await records.hasEvent(id, 'credit-note', undefined, true)) {
75
+ const attempt = await failures(id, 'credit-note');
76
+ if (attempt < MAX_ATTEMPTS) {
77
+ handled++;
78
+ result.retried++;
79
+ if (!await withdrawalOf(ctx).retryCreditNote(stripe, declaration, purchase, computed.netMinor, refundEvent.externalId, attempt)) {
80
+ result.failed++;
81
+ }
82
+ }
83
+ }
84
+ continue;
85
+ }
86
+ const attempt = Math.max(await failures(id, 'refund'), await failures(id, 'subscription-cancel'));
87
+ if (attempt >= MAX_ATTEMPTS)
88
+ continue;
89
+ handled++;
90
+ result.retried++;
91
+ try {
92
+ const execution = await withdrawalOf(ctx).executeWithdrawal(stripe, declaration, purchase, {
93
+ refundMinor: declaration.refundMinor ?? computed?.refundMinor ?? 0, netMinor: computed?.netMinor ?? 0,
94
+ }, { attempt });
95
+ if (!execution.ok) {
96
+ result.failed++;
97
+ continue;
98
+ }
99
+ if (!await records.hasEvent(id, 'observers', 'withdrawal')) {
100
+ await consumerObserversOf(ctx).notifyWithdrawal(declaration, purchase, WithdrawalStatus.Refunded, computed, execution);
101
+ }
102
+ }
103
+ catch (error) {
104
+ result.failed++;
105
+ log.error('Reconcile: withdrawal failed', { id, error });
106
+ }
107
+ }
108
+ };
109
+ const retryCancellations = async (stripe, since, limit, result) => {
110
+ const { items } = await access.consumerDeclarations().list({
111
+ kind: DeclarationKind.Cancellation, status: CancellationStatus.Scheduled, matched: true, receivedAt: { $gte: since },
112
+ }, { size: limit * 2, sort: [{ field: 'receivedAt', order: 'asc' }] });
113
+ let handled = 0;
114
+ for (const declaration of items) {
115
+ if (handled >= limit)
116
+ break;
117
+ const id = declaration.id;
118
+ if (declaration.subscriptionId == null
119
+ || await records.hasEvent(id, 'cancel-scheduled', undefined, true))
120
+ continue;
121
+ const attempt = await failures(id, 'cancel-scheduled');
122
+ const row = await access.subscriptions().byExternalId(declaration.subscriptionId, STRIPE_PAYGATE_ALIAS);
123
+ if (row == null || attempt >= MAX_ATTEMPTS)
124
+ continue;
125
+ handled++;
126
+ result.retried++;
127
+ if (!await cancellationOf(ctx).scheduleCancellation(stripe, declaration, row, attempt)) {
128
+ result.failed++;
129
+ }
130
+ }
131
+ };
132
+ const retryMails = async (since, limit, result) => {
133
+ const policy = await access.payment().consumerRightsPolicy();
134
+ const alias = (await access.consumerMailConfig())?.alias ?? MAILER_SERVICE;
135
+ if (policy == null || ctx.hasService?.(alias) !== true) {
136
+ return;
137
+ }
138
+ for (const event of await pendingSteps('mail', since, limit)) {
139
+ if (event.step == null)
140
+ continue;
141
+ if (await consumerMailOf(ctx).sendConsumerMail(policy, event.step, event.recordId)) {
142
+ result.mailed++;
143
+ }
144
+ else if (!await records.hasEvent(event.recordId, 'mail', event.step, true)) {
145
+ result.failed++;
146
+ }
147
+ }
148
+ };
149
+ const retryObservers = async (since, limit, result) => {
150
+ for (const event of await pendingSteps('observers', since, limit)) {
151
+ let told = false;
152
+ try {
153
+ if (event.step === 'consent') {
154
+ const consent = await access.consumerConsents().load(event.recordId);
155
+ told = consent != null && await consumerObserversOf(ctx).notifyConsent(consent);
156
+ }
157
+ else if (event.step === 'withdrawal') {
158
+ const declaration = await access.consumerDeclarations().load(event.recordId);
159
+ const purchase = declaration?.purchaseId != null ? await access.purchases().byPurchaseId(declaration.purchaseId) : null;
160
+ if (declaration != null && purchase != null) {
161
+ const refunded = await records.hasEvent(event.recordId, 'refund', undefined, true)
162
+ || (declaration.refundMinor ?? 0) <= 0;
163
+ const refund = await access.consumerEvents().load({ recordId: event.recordId, action: 'refund', ok: true });
164
+ const note = await access.consumerEvents().load({ recordId: event.recordId, action: 'credit-note', ok: true });
165
+ told = await consumerObserversOf(ctx).notifyWithdrawal(declaration, purchase, declaration.status === WithdrawalStatus.Processing && refunded ? WithdrawalStatus.Refunded : WithdrawalStatus.Review, await computedOf(event.recordId), refund != null ? {
166
+ ok: true, refundId: refund.externalId ?? undefined, creditNoteId: note?.externalId ?? undefined,
167
+ refundedMinor: refund.amountMinor ?? 0, needsReview: false,
168
+ subscriptionCanceled: await records.hasEvent(event.recordId, 'subscription-cancel', undefined, true),
169
+ } : null);
170
+ }
171
+ }
172
+ else if (event.step === 'cancellation') {
173
+ const declaration = await access.consumerDeclarations().load(event.recordId);
174
+ if (declaration != null) {
175
+ const scheduled = await records.hasEvent(event.recordId, 'cancel-scheduled', undefined, true);
176
+ told = await consumerObserversOf(ctx).notifyCancellation(declaration, declaration.status === CancellationStatus.Scheduled && !scheduled
177
+ ? CancellationStatus.Received : declaration.status);
178
+ }
179
+ }
180
+ }
181
+ catch (error) {
182
+ log.error('Reconcile: observers failed', { recordId: event.recordId, error });
183
+ }
184
+ if (told) {
185
+ result.observed++;
186
+ }
187
+ else {
188
+ result.failed++;
189
+ }
190
+ }
191
+ };
192
+ /** Completed checkouts of the last days that have no purchase row (records only — no mail). */
193
+ const backfillPurchases = async (stripe, limit, result) => {
194
+ const from = Math.floor((Date.now() - PURCHASE_BACKFILL_DAYS * DAY_MS) / 1000);
195
+ let startingAfter;
196
+ let scanned = 0;
197
+ for (;;) {
198
+ const page = await stripe.checkout.sessions.list({
199
+ created: { gte: from }, status: 'complete', limit: 100,
200
+ ...(startingAfter != null ? { starting_after: startingAfter } : {}),
201
+ });
202
+ for (const session of page.data) {
203
+ scanned++;
204
+ if (result.backfilled >= limit)
205
+ return;
206
+ const metadata = session.metadata ?? {};
207
+ if (metadata.entityId == null || metadata.productSku == null)
208
+ continue;
209
+ try {
210
+ if (session.mode === 'payment' && session.payment_status === 'paid') {
211
+ if (await access.purchases().load({ sessionId: session.id }) != null)
212
+ continue;
213
+ const amount = Number(metadata.amountMinor);
214
+ const captured = await captureOf(ctx).capturePaymentPurchase(stripe, session, {
215
+ ...(Number.isSafeInteger(amount) && amount > 0 ? { netAmountMinor: amount } : {}),
216
+ ...(metadata.amountCurrency != null ? { amountCurrency: metadata.amountCurrency } : {}),
217
+ at: new Date(session.created * 1000),
218
+ }, { mail: false });
219
+ if (captured?.created === true)
220
+ result.backfilled++;
221
+ }
222
+ else if (session.mode === 'subscription') {
223
+ const subscriptionId = paymentUtils.idOf(session.subscription);
224
+ if (subscriptionId == null
225
+ || await access.purchases().byPurchaseId(records.purchaseIdOf(subscriptionId)) != null)
226
+ continue;
227
+ const row = await access.subscriptions().byExternalId(subscriptionId, STRIPE_PAYGATE_ALIAS);
228
+ if (row == null || !ENTITLING_STATUSES.includes(row.status))
229
+ continue;
230
+ const subscription = await stripe.subscriptions.retrieve(subscriptionId);
231
+ const captured = await captureOf(ctx).captureSubscriptionPurchase(stripe, subscription, row);
232
+ if (captured != null) {
233
+ await captureOf(ctx).completeSubscriptionPurchase(stripe, session, captured.purchase, { mail: false });
234
+ if (captured.created)
235
+ result.backfilled++;
236
+ }
237
+ }
238
+ }
239
+ catch (error) {
240
+ result.failed++;
241
+ log.error('Reconcile: purchase backfill failed', { sessionId: session.id, error });
242
+ }
243
+ }
244
+ if (!page.has_more || page.data.length === 0 || scanned >= limit * 20)
245
+ return;
246
+ startingAfter = page.data[page.data.length - 1].id;
247
+ }
248
+ };
249
+ /**
250
+ * Organizations that paid before countries were locked: locked from their paygate customer's
251
+ * address — never one an operator unlocked (its next completed purchase locks it).
252
+ */
253
+ const lockLegacy = async (stripe, limit, result) => {
254
+ const policy = await access.payment().consumerRightsPolicy();
255
+ if (policy?.mechanisms.countryLock !== true) {
256
+ return;
257
+ }
258
+ const { items } = await access.paygateCustomers().list({ paygate: STRIPE_PAYGATE_ALIAS, deletedAt: null }, { size: limit * 4 });
259
+ for (const customer of items) {
260
+ if (result.locked >= limit)
261
+ return;
262
+ if (customer.entityId == null || await access.billingProfiles().byEntity(customer.entityId) != null)
263
+ continue;
264
+ if (!await records.hasPaid(customer.entityId) || await records.wasUnlocked(customer.entityId))
265
+ continue;
266
+ try {
267
+ let country = customer.country;
268
+ if (country == null) {
269
+ const retrieved = await stripe.customers.retrieve(customer.externalId);
270
+ country = retrieved.deleted ? undefined : retrieved.address?.country ?? undefined;
271
+ }
272
+ if (country == null)
273
+ continue;
274
+ const { created } = await records.lockProfile(policy, {
275
+ entityId: customer.entityId, country, source: 'customer', customerId: customer.externalId,
276
+ email: customer.email ?? undefined,
277
+ });
278
+ if (created)
279
+ result.locked++;
280
+ }
281
+ catch (error) {
282
+ result.failed++;
283
+ log.error('Reconcile: legacy billing-country lock failed', { entityId: customer.entityId, error });
284
+ }
285
+ }
286
+ };
287
+ const reconcile = async (opts = {}) => {
288
+ const result = { retried: 0, mailed: 0, observed: 0, backfilled: 0, locked: 0, failed: 0 };
289
+ if (await access.payment().consumerRightsPolicy() == null) {
290
+ return result;
291
+ }
292
+ const limit = Math.max(1, opts.limit ?? 50);
293
+ const since = opts.since ?? new Date(Date.now() - 30 * DAY_MS);
294
+ const stripe = internals.managed ? await internals.stripe(ctx) : null;
295
+ const steps = [
296
+ ...(stripe != null ? [
297
+ ['withdrawals', async () => { await retryWithdrawals(stripe, since, limit, result); }],
298
+ ['cancellations', async () => { await retryCancellations(stripe, since, limit, result); }],
299
+ ] : []),
300
+ ['mails', async () => { await retryMails(since, limit, result); }],
301
+ ['observers', async () => { await retryObservers(since, limit, result); }],
302
+ ...(stripe != null ? [
303
+ ['backfill', async () => { await backfillPurchases(stripe, limit, result); }],
304
+ ['legacy locks', async () => { await lockLegacy(stripe, limit, result); }],
305
+ ] : []),
306
+ ];
307
+ for (const [name, step] of steps) {
308
+ try {
309
+ await step();
310
+ }
311
+ catch (error) {
312
+ result.failed++;
313
+ log.error('Consumer-rights reconcile step failed', { step: name, error });
314
+ }
315
+ }
316
+ return result;
317
+ };
318
+ return { reconcile };
319
+ };
320
+ //# sourceMappingURL=reconcile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconcile.js","sourceRoot":"","sources":["../../src/consumer/reconcile.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EACL,kBAAkB,EAAE,eAAe,EAAE,kBAAkB,EAAE,YAAY,EAAE,gBAAgB,GACxF,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAK3E,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAC/B,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAG9C,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,GAAe,EAAE,SAAkC,EAC1B,EAAE;IAC3B,MAAM,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,CAAA;IACnC,MAAM,OAAO,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAA;IAEtC,uFAAuF;IACvF,MAAM,UAAU,GAAG,KAAK,EACtB,YAAoB,EACgG,EAAE;QACtH,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,YAA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