@owlmeans/server-payment 0.1.18-rc.8 → 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,110 @@
1
+ import { ENTITLING_STATUSES, INTERNAL_PAYGATE, PlanRequired, ProductError, promoHelper } from '@owlmeans/payment';
2
+ import { memoHelper } from '@owlmeans/context';
3
+ import { STRIPE_PAYGATE_ALIAS } from './consts.js';
4
+ import { paymentAccessOf } from './access.js';
5
+ import { planHelper } from './plan.js';
6
+ import { log } from './log.js';
7
+ /** The plan skus already reported unknown — process-wide, so each is warned about once. */
8
+ const unknownPlans = new Set();
9
+ /** An internal grant with a period end stops entitling at that instant; a paygate row never does. */
10
+ const stillEntitles = (row, at) => row.paygate !== INTERNAL_PAYGATE || row.periodEnd == null || new Date(row.periodEnd).getTime() > at.getTime();
11
+ export const makeCatalogueHelper = (ctx) => {
12
+ const access = paymentAccessOf(ctx);
13
+ const findPlan = async (planSku) => {
14
+ try {
15
+ return await access.payment().plan(planSku);
16
+ }
17
+ catch {
18
+ return null;
19
+ }
20
+ };
21
+ const findProduct = async (productSku) => {
22
+ try {
23
+ return await access.payment().product(productSku);
24
+ }
25
+ catch {
26
+ return null;
27
+ }
28
+ };
29
+ const catalogPlans = async () => {
30
+ const products = await access.payment().products();
31
+ const plans = [];
32
+ for (const product of products) {
33
+ plans.push(...await access.payment().allPlans(product.sku));
34
+ }
35
+ return plans;
36
+ };
37
+ const freePlanOf = async () => (await catalogPlans())
38
+ .filter(plan => plan.free === true)
39
+ .sort((a, b) => planHelper.planRank(a) - planHelper.planRank(b) || a.sku.localeCompare(b.sku))[0] ?? null;
40
+ const resolveEffectivePlan = async (entityId, at = new Date()) => {
41
+ const fallback = await freePlanOf();
42
+ const { items } = await access.subscriptions().list({ entityId, status: [...ENTITLING_STATUSES] }, { size: 0 });
43
+ const candidates = [];
44
+ for (const row of items.filter(item => stillEntitles(item, at))) {
45
+ const plan = await findPlan(row.planSku);
46
+ if (plan == null) {
47
+ if (!unknownPlans.has(row.planSku)) {
48
+ unknownPlans.add(row.planSku);
49
+ log.warn('Subscription names an unknown plan; ignored', { subscriptionId: row.externalId, planSku: row.planSku });
50
+ }
51
+ continue;
52
+ }
53
+ candidates.push({ plan, row, rank: planHelper.planRank(plan) });
54
+ }
55
+ candidates.sort((a, b) => b.rank - a.rank
56
+ || new Date(b.row.createdAt).getTime() - new Date(a.row.createdAt).getTime());
57
+ const best = candidates[0];
58
+ if (best != null) {
59
+ return { plan: planHelper.overriddenPlan(best.plan, best.row), subscription: best.row, fallback };
60
+ }
61
+ if (fallback != null) {
62
+ return { plan: fallback, subscription: null, fallback };
63
+ }
64
+ throw new PlanRequired(entityId);
65
+ };
66
+ const entitlementsOf = async (entityId, productSkus) => {
67
+ const { plan, subscription } = await resolveEffectivePlan(entityId);
68
+ if (productSkus != null && !productSkus.includes(plan.productSku)) {
69
+ return [];
70
+ }
71
+ const at = new Date();
72
+ return (plan.capabilities ?? [])
73
+ .filter(set => promoHelper.promoActive(set.promo, subscription?.createdAt, at))
74
+ .map(({ promo: _promo, ...set }) => set);
75
+ };
76
+ const stripePlansOf = async () => {
77
+ const products = await access.payment().products();
78
+ const result = [];
79
+ for (const product of products) {
80
+ if (!(product.gateways ?? []).includes(STRIPE_PAYGATE_ALIAS)) {
81
+ continue;
82
+ }
83
+ const plans = (await access.payment().allPlans(product.sku))
84
+ .filter(plan => planHelper.isSoldThrough(product, plan, STRIPE_PAYGATE_ALIAS));
85
+ if (plans.length > 0) {
86
+ result.push({ product, plans });
87
+ }
88
+ }
89
+ return result;
90
+ };
91
+ const consumablePlanOf = async (productSku, planSku) => {
92
+ const product = await access.payment().product(productSku);
93
+ const plans = (await access.payment().allPlans(product.sku))
94
+ .filter(plan => planHelper.isSoldThrough(product, plan, STRIPE_PAYGATE_ALIAS));
95
+ if (planSku != null && !plans.some(plan => plan.sku === planSku)) {
96
+ throw new ProductError(`plan:${planSku}`);
97
+ }
98
+ const plan = plans.find(item => item.sku === planSku) ?? plans[0];
99
+ if (plan == null)
100
+ throw new ProductError('plan');
101
+ return { product, plan };
102
+ };
103
+ return {
104
+ findPlan, findProduct, catalogPlans, freePlanOf, resolveEffectivePlan, entitlementsOf, stripePlansOf,
105
+ consumablePlanOf,
106
+ };
107
+ };
108
+ /** The catalogue of a context — one per context. */
109
+ export const catalogueOf = memoHelper.oncePer(makeCatalogueHelper);
110
+ //# sourceMappingURL=catalogue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalogue.js","sourceRoot":"","sources":["../src/catalogue.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEjH,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAG9B,2FAA2F;AAC3F,MAAM,YAAY,GAAG,IAAI,GAAG,EAAU,CAAA;AAEtC,qGAAqG;AACrG,MAAM,aAAa,GAAG,CAAC,GAA8B,EAAE,EAAQ,EAAW,EAAE,CAC1E,GAAG,CAAC,OAAO,KAAK,gBAAgB,IAAI,GAAG,CAAC,SAAS,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,GAAG,CAAC,SAAS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CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAmB;aAC1E,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,EAAE,oBAAoB,CAAC,CAAC,CAAA;QAChF,IAAI,OAAO,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,KAAK,OAAO,CAAC,EAAE,CAAC;YACjE,MAAM,IAAI,YAAY,CAAC,QAAQ,OAAO,EAAE,CAAC,CAAA;QAC3C,CAAC;QACD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,KAAK,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAA;QACjE,IAAI,IAAI,IAAI,IAAI;YAAE,MAAM,IAAI,YAAY,CAAC,MAAM,CAAC,CAAA;QAEhD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;IAC1B,CAAC,CAAA;IAED,OAAO;QACL,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,oBAAoB,EAAE,cAAc,EAAE,aAAa;QACpG,gBAAgB;KACjB,CAAA;AACH,CAAC,CAAA;AAED,oDAAoD;AACpD,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAA"}
@@ -0,0 +1,22 @@
1
+ import type { CommitOptions, CommitResult, GrantInternalPlanOptions, PaymentSubscriptionRecord, PropagatedState, SubscriptionSnapshot } from '../types.js';
2
+ /** A context's subscription rows: what observers see of them, how a new state is committed, internal grants. */
3
+ export interface SubscriptionCommitHelper {
4
+ /** A subscription as observers see it; `state` overlays what was last propagated. */
5
+ snapshotOf: (record: PaymentSubscriptionRecord, state?: PropagatedState) => Promise<SubscriptionSnapshot>;
6
+ /**
7
+ * Store a subscription's new state, tell observers what changed, then record what was told.
8
+ *
9
+ * The state is written BEFORE observers run, so an observer reading entitlements sees the new plan.
10
+ * What classification compares against is the state last PROPAGATED (`propagated`), stamped only
11
+ * after every observer succeeded — so an observer that throws leaves the change to be classified
12
+ * again, identically, when the paygate retries. `lastEventId` is stamped with it.
13
+ */
14
+ commitSubscription: (previous: PaymentSubscriptionRecord | null, next: PaymentSubscriptionRecord, opts?: CommitOptions) => Promise<CommitResult>;
15
+ /**
16
+ * Grant a plan without a paygate — the free plan every entity holds, or a complimentary one
17
+ * (`force`). One row per grant (`free:<entityId>` / `internal:<planSku>:<entityId>`), upserted: its
18
+ * `createdAt` survives a re-grant, and observers hear `created` once.
19
+ */
20
+ grantInternalPlan: (entityId: string, planSku: string, opts?: GrantInternalPlanOptions) => Promise<PaymentSubscriptionRecord>;
21
+ }
22
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/commit/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAAE,YAAY,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,eAAe,EACjG,oBAAoB,EACrB,MAAM,aAAa,CAAA;AAEpB,gHAAgH;AAChH,MAAM,WAAW,wBAAwB;IACvC,qFAAqF;IACrF,UAAU,EAAE,CAAC,MAAM,EAAE,yBAAyB,EAAE,KAAK,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,oBAAoB,CAAC,CAAA;IACzG;;;;;;;OAOG;IACH,kBAAkB,EAAE,CAClB,QAAQ,EAAE,yBAAyB,GAAG,IAAI,EAAE,IAAI,EAAE,yBAAyB,EAAE,IAAI,CAAC,EAAE,aAAa,KAC9F,OAAO,CAAC,YAAY,CAAC,CAAA;IAC1B;;;;OAIG;IACH,iBAAiB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,wBAAwB,KAAK,OAAO,CAAC,yBAAyB,CAAC,CAAA;CAC9H"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/commit/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import type { Context as ApiContext } from '@owlmeans/server-api';
2
+ import type { SubscriptionCommitHelper } from './commit/types.js';
3
+ export declare const makeSubscriptionCommitHelper: (ctx: ApiContext) => SubscriptionCommitHelper;
4
+ /** The subscription store of a context — one per context. */
5
+ export declare const subscriptionCommitOf: (target: ApiContext<import("@owlmeans/server-api").Config>) => SubscriptionCommitHelper;
6
+ //# sourceMappingURL=commit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit.d.ts","sourceRoot":"","sources":["../src/commit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAajE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAA;AAEjE,eAAO,MAAM,4BAA4B,QAAS,UAAU,KAAG,wBAoI9D,CAAA;AAED,6DAA6D;AAC7D,eAAO,MAAM,oBAAoB,yFAAmD,CAAA"}
@@ -0,0 +1,125 @@
1
+ import { ENTITLING_STATUSES, INTERNAL_PAYGATE, ProductError, SubscriptionStatus, UnknownPlan } from '@owlmeans/payment';
2
+ import { memoHelper } from '@owlmeans/context';
3
+ import { log } from './log.js';
4
+ import { SUBSCRIPTION_LOG_EVENTS } from './consts.local.js';
5
+ import { paymentAccessOf } from './access.js';
6
+ import { paymentUtils } from './utils.js';
7
+ import { catalogueOf } from './catalogue.js';
8
+ import { planHelper } from './plan.js';
9
+ import { subscriptionHelper } from './subscription.js';
10
+ export const makeSubscriptionCommitHelper = (ctx) => {
11
+ const access = paymentAccessOf(ctx);
12
+ const snapshotOf = async (record, state) => {
13
+ const planSku = state?.planSku ?? record.planSku;
14
+ const declared = await catalogueOf(ctx).findPlan(planSku);
15
+ const plan = declared != null ? planHelper.overriddenPlan(declared, record) : null;
16
+ return paymentUtils.compact({
17
+ entityId: record.entityId,
18
+ planSku,
19
+ productSku: plan?.productSku ?? record.productSku,
20
+ rank: state?.rank ?? record.rank,
21
+ status: state?.status ?? record.status,
22
+ paygate: record.paygate,
23
+ subscriptionId: record.externalId,
24
+ service: record.service,
25
+ periodStart: record.periodStart ?? undefined,
26
+ periodEnd: record.periodEnd ?? undefined,
27
+ cancelAtPeriodEnd: state != null ? state.cancelAtPeriodEnd : record.cancelAtPeriodEnd ?? undefined,
28
+ trialEnd: record.trialEnd ?? undefined,
29
+ pausedAt: state != null ? state.pausedAt : record.pausedAt ?? undefined,
30
+ createdAt: record.createdAt ?? undefined,
31
+ capabilities: plan?.capabilities,
32
+ limits: plan?.limits,
33
+ });
34
+ };
35
+ const commitSubscription = async (previous, next, opts = {}) => {
36
+ const resource = access.subscriptions();
37
+ const updated = previous == null || subscriptionHelper.materiallyDiffers(previous, next);
38
+ const prior = previous?.propagated ?? null;
39
+ const change = subscriptionHelper.classifySubscriptionChange(prior, next, opts);
40
+ const at = new Date();
41
+ const finalize = (record) => {
42
+ const tracked = prior != null || change === 'created';
43
+ return {
44
+ ...record,
45
+ ...(opts.eventId != null ? { lastEventId: opts.eventId } : {}),
46
+ ...(tracked ? {
47
+ propagated: subscriptionHelper.propagatedStateOf(record, change === 'renewed' ? opts.invoiceId : prior?.renewedInvoiceId),
48
+ } : {}),
49
+ ...(change === 'created' && record.initialPropagatedAt == null ? { initialPropagatedAt: at } : {}),
50
+ };
51
+ };
52
+ const write = async (record) => {
53
+ if (record.id != null) {
54
+ return await resource.update(record);
55
+ }
56
+ try {
57
+ return await resource.create(record);
58
+ }
59
+ catch (error) {
60
+ if (!paymentUtils.isDuplicateKey(error)) {
61
+ throw error;
62
+ }
63
+ const winner = await resource.byExternalId(record.externalId, record.paygate);
64
+ return await resource.update({ ...record, id: winner?.id });
65
+ }
66
+ };
67
+ if (change == null) {
68
+ const quiet = previous != null && !updated && (opts.eventId == null || previous.lastEventId === opts.eventId)
69
+ && (prior == null || !subscriptionHelper.stateDiffers(prior, next));
70
+ return { record: quiet ? previous : await write(finalize(next)), change: null, updated };
71
+ }
72
+ const stored = await write(next);
73
+ await opts.beforePropagate?.(stored, change);
74
+ await access.observer().propagateSubscription({
75
+ change,
76
+ previous: prior != null && previous != null ? await snapshotOf(previous, prior) : null,
77
+ current: await snapshotOf(stored),
78
+ active: ENTITLING_STATUSES.includes(stored.status),
79
+ eventKey: subscriptionHelper.subscriptionEventKey(stored, change, opts),
80
+ ...(opts.invoiceId != null ? { invoiceId: opts.invoiceId } : {}),
81
+ ...(opts.eventId != null ? { externalEventId: opts.eventId } : {}),
82
+ }, ctx);
83
+ const record = await resource.update(finalize(stored));
84
+ log.info('Subscription changed', paymentUtils.compact({
85
+ entityId: stored.entityId, subscriptionId: stored.externalId, change, planSku: stored.planSku,
86
+ previousPlanSku: prior != null && prior.planSku !== stored.planSku ? prior.planSku : undefined,
87
+ status: stored.status, currency: stored.currency ?? undefined, invoiceId: opts.invoiceId, eventId: opts.eventId,
88
+ }), { event: SUBSCRIPTION_LOG_EVENTS[change] ?? 'subscription.updated' });
89
+ return { record, change, updated };
90
+ };
91
+ const grantInternalPlan = async (entityId, planSku, opts = {}) => {
92
+ const plan = await catalogueOf(ctx).findPlan(planSku);
93
+ if (plan == null) {
94
+ throw new UnknownPlan(planSku);
95
+ }
96
+ if (plan.free !== true && opts.force !== true) {
97
+ throw new ProductError(`internal-grant:${planSku}`);
98
+ }
99
+ const product = await catalogueOf(ctx).findProduct(plan.productSku);
100
+ const externalId = plan.free === true ? `free:${entityId}` : `internal:${planSku}:${entityId}`;
101
+ const previous = await access.subscriptions().byExternalId(externalId, INTERNAL_PAYGATE);
102
+ const now = new Date();
103
+ const { periodEnd: _periodEnd, endedAt: _endedAt, canceledAt: _canceledAt, ...kept } = previous ?? {};
104
+ const next = {
105
+ ...kept,
106
+ entityId,
107
+ planSku,
108
+ productSku: plan.productSku,
109
+ service: previous?.service ?? product?.services?.[0] ?? ctx.cfg.service,
110
+ paygate: INTERNAL_PAYGATE,
111
+ externalId,
112
+ status: SubscriptionStatus.Active,
113
+ rank: planHelper.planRank(plan),
114
+ ...(opts.periodEnd != null ? { periodEnd: opts.periodEnd } : {}),
115
+ createdAt: previous?.createdAt ?? now,
116
+ updatedAt: now,
117
+ };
118
+ const { record } = await commitSubscription(previous, next);
119
+ return record ?? next;
120
+ };
121
+ return { snapshotOf, commitSubscription, grantInternalPlan };
122
+ };
123
+ /** The subscription store of a context — one per context. */
124
+ export const subscriptionCommitOf = memoHelper.oncePer(makeSubscriptionCommitHelper);
125
+ //# sourceMappingURL=commit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit.js","sourceRoot":"","sources":["../src/commit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEvH,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAK9C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAGtD,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,GAAe,EAA4B,EAAE;IACxF,MAAM,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,CAAA;IAEnC,MAAM,UAAU,GAAG,KAAK,EACtB,MAAiC,EAAE,KAAuB,EAC3B,EAAE;QACjC,MAA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EAAE,GAAG,QAAQ,IAAI,EAAE,CAAA;QAErG,MAAM,IAAI,GAAG;YACX,GAAG,IAAI;YACP,QAAQ;YACR,OAAO;YACP,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,OAAO,EAAE,QAAQ,EAAE,OAAO,IAAI,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,OAAO;YACvE,OAAO,EAAE,gBAAgB;YACzB,UAAU;YACV,MAAM,EAAE,kBAAkB,CAAC,MAAM;YACjC,IAAI,EAAE,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC;YAC/B,GAAG,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAChE,SAAS,EAAE,QAAQ,EAAE,SAAS,IAAI,GAAG;YACrC,SAAS,EAAE,GAAG;SACc,CAAA;QAC9B,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,kBAAkB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;QAE3D,OAAO,MAAM,IAAI,IAAI,CAAA;IACvB,CAAC,CAAA;IAED,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,CAAA;AAC9D,CAAC,CAAA;AAED,6DAA6D;AAC7D,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAAA"}
package/build/config.d.ts CHANGED
@@ -1,8 +1,47 @@
1
- import type { Config, PaymentPlanDef, PaymentProductDef } from './types.js';
1
+ import { type ConsumerRightsPolicy } from '@owlmeans/payment';
2
+ import type { Config, ConsumerRightsDef, PaymentPlanDef, PaymentProductDef, PortalBrandingDef, PricingDef, StripeSecretsDef } from './types.js';
2
3
  export declare const declarePaymentProduct: (cfg: Config, def: PaymentProductDef) => void;
4
+ /**
5
+ * Declare a plan into the configuration catalogue.
6
+ *
7
+ * Validated before anything is pushed: `rank` a safe integer `>= 0`; a `free` plan costs nothing
8
+ * and is sold through no gateway; no capability set under the reserved `limit` scope; every limit
9
+ * well-formed (a `window` limit names its window, the others do not, the ceiling is a safe
10
+ * integer, a promo ends at a real `Date`). Amount and quantity policies are asserted as before.
11
+ */
3
12
  export declare const declarePaymentPlan: (cfg: Config, def: PaymentPlanDef) => void;
4
- export declare const stripeSecrets: (cfg: Config, paths: {
5
- api: string;
6
- webhook: string;
7
- }) => void;
13
+ /**
14
+ * Where the Stripe secrets live. A value that looks like a path is read into the configuration at
15
+ * boot. The webhook secret is an optional override of the one the managed endpoint stores.
16
+ */
17
+ export declare const stripeSecrets: (cfg: Config, paths: StripeSecretsDef) => void;
18
+ /** Branding and the default return URL of the managed customer portal configuration. */
19
+ export declare const portalBranding: (cfg: Config, def: PortalBrandingDef) => void;
20
+ /**
21
+ * Declare the pricing policy: whether checkout collects tax and a VAT/GST id, what `tax_behavior`
22
+ * synced prices are given, Adaptive Pricing, and whether the estimate endpoints are served. A
23
+ * config never carries more than one — a second call replaces the first, so re-declaring (a test, a
24
+ * config module re-run) is safe rather than silently ignored (a config resource resolves an id to
25
+ * its FIRST match).
26
+ *
27
+ * `def.stripe` (the FX Quotes preview version, the unspecified-price migration switch) is
28
+ * Stripe-only and goes to a backend plugin, never the advertised `PricingPolicy` record.
29
+ *
30
+ * @throws PaymentError (`assertPricingPolicy`) when an estimate is declared without the tax or
31
+ * currency capability it requires.
32
+ */
33
+ export declare const declarePaymentPricing: (cfg: Config, def: PricingDef) => void;
34
+ /**
35
+ * Declare the consumer-rights policy (EU withdrawal, spend consent, start requests, cancellation,
36
+ * country lock) — a singleton config record like the pricing policy: `DEFAULT_CONSUMER_RIGHTS`
37
+ * filled in, asserted, and replacing any earlier declaration. It is ADVERTISED to the browser; the
38
+ * `mail` options (mailer alias, sender, archive copies) go to a backend-only plugin config.
39
+ *
40
+ * `trader` (who the consumer contracts with: `name` for the statements, `legalName`/`address`/`email`
41
+ * for the mails and the withdrawal information) is backend-only as well.
42
+ *
43
+ * @throws ConsumerRightsError (`policy:<field>`) — see `assertConsumerRightsPolicy`; `policy:trader`
44
+ * when a mechanism is on and no trader `name` and `legalName` are declared.
45
+ */
46
+ export declare const declareConsumerRights: (cfg: Config, def: ConsumerRightsDef) => ConsumerRightsPolicy;
8
47
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAe,cAAc,EAAkB,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAExG,eAAO,MAAM,qBAAqB,QAAS,MAAM,OAAO,iBAAiB,KAAG,IAS3E,CAAA;AAED,eAAO,MAAM,kBAAkB,QAAS,MAAM,OAAO,cAAc,KAAG,IA4BrE,CAAA;AAED,eAAO,MAAM,aAAa,QAAS,MAAM,SAAS;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,KAAG,IAEpF,CAAA"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqX,KAAK,oBAAoB,EAAmG,MAAM,mBAAmB,CAAA;AAKjhB,OAAO,KAAK,EACV,MAAM,EAAE,iBAAiB,EAAe,cAAc,EAAkB,iBAAiB,EAAE,iBAAiB,EAC5G,UAAU,EAAE,gBAAgB,EAC7B,MAAM,YAAY,CAAA;AAGnB,eAAO,MAAM,qBAAqB,QAAS,MAAM,OAAO,iBAAiB,KAAG,IAS3E,CAAA;AA2BD;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,QAAS,MAAM,OAAO,cAAc,KAAG,IA+CrE,CAAA;AA8CD;;;GAGG;AACH,eAAO,MAAM,aAAa,QAAS,MAAM,SAAS,gBAAgB,KAAG,IAIpE,CAAA;AAED,wFAAwF;AACxF,eAAO,MAAM,cAAc,QAAS,MAAM,OAAO,iBAAiB,KAAG,IAOpE,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,qBAAqB,QAAS,MAAM,OAAO,UAAU,KAAG,IAqCpE,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB,QAAS,MAAM,OAAO,iBAAiB,KAAG,oBAsC3E,CAAA"}
package/build/config.js CHANGED
@@ -1,7 +1,7 @@
1
- import { toConfigRecord } from '@owlmeans/server-app';
2
- import { plugin } from '@owlmeans/config';
3
- import { assertAmountCheckoutPolicy, assertQuantityCheckoutPolicy, CheckoutPricingMode, PLAN_RECORD_PREFIX, PLAN_RECORD_TYPE, PlanStatus, PRODUCT_RECORD_PREFIX, PRODUCT_RECORD_TYPE, } from '@owlmeans/payment';
4
- import { STRIPE_PAYGATE_ALIAS, STRIPE_PLUGIN_CONFIG } from './consts.js';
1
+ import { plugin, PLUGIN_RECORD, configHelper } from '@owlmeans/config';
2
+ import { CAPABILITY_LIMIT_SCOPE, CheckoutPricingMode, CONSUMER_RIGHTS_RECORD_ID, CONSUMER_RIGHTS_RECORD_TYPE, ConsumerRightsError, LimitKind, LimitMisdeclared, makeConsumerRightsPolicy, PLAN_RECORD_PREFIX, PLAN_RECORD_TYPE, PaymentError, PlanRankConflict, PlanStatus, PRICING_POLICY_RECORD_ID, PRICING_POLICY_RECORD_TYPE, PRODUCT_RECORD_PREFIX, PRODUCT_RECORD_TYPE, ProductError, checkoutPricingHelper, priceEstimateHelper } from '@owlmeans/payment';
3
+ import { CONSUMER_RIGHTS_MAIL_PLUGIN_CONFIG, STRIPE_PAYGATE_ALIAS, STRIPE_PLUGIN_CONFIG, STRIPE_PORTAL_PLUGIN_CONFIG, STRIPE_PRICING_PLUGIN_CONFIG, } from './consts.js';
4
+ import { CURRENCY, LIMIT_KINDS, LIMIT_WINDOWS } from './consts.local.js';
5
5
  export const declarePaymentProduct = (cfg, def) => {
6
6
  cfg.records = cfg.records ?? [];
7
7
  const product = {
@@ -10,15 +10,57 @@ export const declarePaymentProduct = (cfg, def) => {
10
10
  gateways: def.gateways ?? [STRIPE_PAYGATE_ALIAS], capabilities: def.capabilities,
11
11
  taxCode: def.taxCode, unitLabel: def.unitLabel,
12
12
  };
13
- cfg.records.push({ ...toConfigRecord(product), recordType: PRODUCT_RECORD_TYPE, id: `${PRODUCT_RECORD_PREFIX}:${def.sku}` });
13
+ cfg.records.push({ ...configHelper.toConfigRecord(product), recordType: PRODUCT_RECORD_TYPE, id: `${PRODUCT_RECORD_PREFIX}:${def.sku}` });
14
14
  };
15
+ const isSafeCount = (value) => typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
16
+ const assertLimitDeclaration = (key, limit) => {
17
+ if (!LIMIT_KINDS.includes(limit.kind)) {
18
+ throw new LimitMisdeclared(`${key}:kind`);
19
+ }
20
+ if (limit.kind === LimitKind.Window) {
21
+ if (limit.window == null) {
22
+ throw new LimitMisdeclared(`${key}:window-missing`);
23
+ }
24
+ if (!LIMIT_WINDOWS.includes(limit.window)) {
25
+ throw new LimitMisdeclared(`${key}:window`);
26
+ }
27
+ }
28
+ else if (limit.window != null) {
29
+ throw new LimitMisdeclared(`${key}:window-forbidden`);
30
+ }
31
+ if (!isSafeCount(limit.limit)) {
32
+ throw new LimitMisdeclared(`${key}:limit`);
33
+ }
34
+ if (limit.promo != null && !(limit.promo.until instanceof Date && !Number.isNaN(limit.promo.until.getTime()))) {
35
+ throw new LimitMisdeclared(`${key}:promo-until`);
36
+ }
37
+ };
38
+ /**
39
+ * Declare a plan into the configuration catalogue.
40
+ *
41
+ * Validated before anything is pushed: `rank` a safe integer `>= 0`; a `free` plan costs nothing
42
+ * and is sold through no gateway; no capability set under the reserved `limit` scope; every limit
43
+ * well-formed (a `window` limit names its window, the others do not, the ceiling is a safe
44
+ * integer, a promo ends at a real `Date`). Amount and quantity policies are asserted as before.
45
+ */
15
46
  export const declarePaymentPlan = (cfg, def) => {
16
- cfg.records = cfg.records ?? [];
47
+ if (def.rank != null && !isSafeCount(def.rank)) {
48
+ throw new PlanRankConflict(`rank:${def.sku}`);
49
+ }
50
+ if (def.free === true && (def.price !== 0 || (def.gateways ?? []).length > 0)) {
51
+ throw new PlanRankConflict(`free:${def.sku}`);
52
+ }
53
+ if ((def.capabilities ?? []).some(set => set.scope === CAPABILITY_LIMIT_SCOPE)) {
54
+ throw new LimitMisdeclared(`${def.sku}:reserved-scope`);
55
+ }
56
+ for (const [key, limit] of Object.entries(def.limits ?? {})) {
57
+ assertLimitDeclaration(key, limit);
58
+ }
17
59
  const pricingMode = def.pricingMode;
18
60
  if (pricingMode === CheckoutPricingMode.Amount) {
19
61
  if (def.amountPolicy == null)
20
62
  throw new TypeError(`Amount checkout plan '${def.sku}' requires amountPolicy`);
21
- assertAmountCheckoutPolicy(def.amountPolicy);
63
+ checkoutPricingHelper.assertAmountCheckoutPolicy(def.amountPolicy);
22
64
  }
23
65
  const quantityPolicy = def.quantityPolicy ?? (def.minQuantity != null || def.maxQuantity != null || def.defaultQuantity != null
24
66
  ? {
@@ -28,19 +70,183 @@ export const declarePaymentPlan = (cfg, def) => {
28
70
  }
29
71
  : undefined);
30
72
  if (quantityPolicy != null)
31
- assertQuantityCheckoutPolicy(quantityPolicy);
73
+ checkoutPricingHelper.assertQuantityCheckoutPolicy(quantityPolicy);
74
+ const currencyPrices = currencyPricesOf(def);
75
+ assertWithdrawalComponents(def);
76
+ cfg.records = cfg.records ?? [];
32
77
  const plan = {
33
78
  productSku: def.productSku, sku: def.sku, status: PlanStatus.Active,
79
+ ...(def.rank != null ? { rank: def.rank } : {}),
80
+ ...(def.free === true ? { free: true, gateways: [] } : def.gateways != null ? { gateways: def.gateways } : {}),
34
81
  duration: def.duration, price: def.price, currency: def.currency ?? def.amountPolicy?.currency ?? 'usd',
35
82
  order: def.order ?? 0, title: def.title ?? def.sku, capabilities: def.capabilities,
36
83
  limits: def.limits, recurring: def.recurring, pricingMode, amountPolicy: def.amountPolicy,
37
84
  quantityPolicy,
38
85
  minQuantity: quantityPolicy?.minimum, maxQuantity: quantityPolicy?.maximum,
39
86
  defaultQuantity: quantityPolicy?.default,
87
+ ...(currencyPrices != null ? { currencyPrices } : {}),
88
+ ...(def.withdrawal != null ? { withdrawal: { components: def.withdrawal.components.map(item => ({ ...item })) } } : {}),
40
89
  };
41
- cfg.records.push({ ...toConfigRecord(plan), recordType: PLAN_RECORD_TYPE, id: `${PLAN_RECORD_PREFIX}:${def.sku}` });
90
+ cfg.records.push({ ...configHelper.toConfigRecord(plan), recordType: PLAN_RECORD_TYPE, id: `${PLAN_RECORD_PREFIX}:${def.sku}` });
91
+ };
92
+ /** `currencyPrices` normalized to lowercase codes; each a positive amount of whole minor units. */
93
+ const currencyPricesOf = (def) => {
94
+ if (def.currencyPrices == null) {
95
+ return undefined;
96
+ }
97
+ if (def.pricingMode === CheckoutPricingMode.Amount || def.free === true) {
98
+ throw new ProductError(`currency-prices:${def.sku}:mode`);
99
+ }
100
+ const prices = {};
101
+ for (const [raw, amount] of Object.entries(def.currencyPrices)) {
102
+ const currency = raw.toLowerCase();
103
+ const minor = Math.round(amount * 100);
104
+ if (!CURRENCY.test(currency) || !Number.isFinite(amount) || amount <= 0 || !Number.isSafeInteger(minor)
105
+ || Math.abs(minor - amount * 100) > 1e-6 || prices[currency] != null) {
106
+ throw new ProductError(`currency-prices:${def.sku}:${raw}`);
107
+ }
108
+ prices[currency] = amount;
109
+ }
110
+ return prices;
42
111
  };
112
+ /** The components' shares must add up to the plan's price in minor units. */
113
+ const assertWithdrawalComponents = (def) => {
114
+ const components = def.withdrawal?.components;
115
+ if (components == null) {
116
+ return;
117
+ }
118
+ const keys = new Set();
119
+ let sum = 0;
120
+ for (const component of components) {
121
+ if (typeof component.key !== 'string' || component.key === '' || keys.has(component.key)
122
+ || (component.basis !== 'time' && component.basis !== 'units')
123
+ || !Number.isSafeInteger(component.shareMinor) || component.shareMinor < 0) {
124
+ throw new ProductError(`withdrawal:${def.sku}:component`);
125
+ }
126
+ keys.add(component.key);
127
+ sum += component.shareMinor;
128
+ }
129
+ if (components.length === 0 || sum !== Math.round(def.price * 100)) {
130
+ throw new ProductError(`withdrawal:${def.sku}:shares`);
131
+ }
132
+ };
133
+ /**
134
+ * Where the Stripe secrets live. A value that looks like a path is read into the configuration at
135
+ * boot. The webhook secret is an optional override of the one the managed endpoint stores.
136
+ */
43
137
  export const stripeSecrets = (cfg, paths) => {
44
- plugin(cfg, { api: paths.api, webhook: paths.webhook }, STRIPE_PLUGIN_CONFIG);
138
+ plugin(cfg, {
139
+ api: paths.api, ...(paths.webhook != null && paths.webhook !== '' ? { webhook: paths.webhook } : {}),
140
+ }, STRIPE_PLUGIN_CONFIG);
141
+ };
142
+ /** Branding and the default return URL of the managed customer portal configuration. */
143
+ export const portalBranding = (cfg, def) => {
144
+ plugin(cfg, {
145
+ returnUrl: def.returnUrl,
146
+ ...(def.headline != null ? { headline: def.headline } : {}),
147
+ ...(def.privacyPolicyUrl != null ? { privacyPolicyUrl: def.privacyPolicyUrl } : {}),
148
+ ...(def.termsOfServiceUrl != null ? { termsOfServiceUrl: def.termsOfServiceUrl } : {}),
149
+ }, STRIPE_PORTAL_PLUGIN_CONFIG);
150
+ };
151
+ /**
152
+ * Declare the pricing policy: whether checkout collects tax and a VAT/GST id, what `tax_behavior`
153
+ * synced prices are given, Adaptive Pricing, and whether the estimate endpoints are served. A
154
+ * config never carries more than one — a second call replaces the first, so re-declaring (a test, a
155
+ * config module re-run) is safe rather than silently ignored (a config resource resolves an id to
156
+ * its FIRST match).
157
+ *
158
+ * `def.stripe` (the FX Quotes preview version, the unspecified-price migration switch) is
159
+ * Stripe-only and goes to a backend plugin, never the advertised `PricingPolicy` record.
160
+ *
161
+ * @throws PaymentError (`assertPricingPolicy`) when an estimate is declared without the tax or
162
+ * currency capability it requires.
163
+ */
164
+ export const declarePaymentPricing = (cfg, def) => {
165
+ const { stripe, ...policy } = def;
166
+ priceEstimateHelper.assertPricingPolicy(policy);
167
+ cfg.records = (cfg.records ?? []).filter(record => record.id !== PRICING_POLICY_RECORD_ID);
168
+ cfg.records.push({
169
+ ...configHelper.toConfigRecord(policy), recordType: PRICING_POLICY_RECORD_TYPE, id: PRICING_POLICY_RECORD_ID,
170
+ });
171
+ if (stripe != null) {
172
+ const settlementCurrency = stripe.settlementCurrency?.toLowerCase();
173
+ if (settlementCurrency != null && !/^[a-z]{3}$/.test(settlementCurrency)) {
174
+ throw new PaymentError('pricing-policy:settlement-currency');
175
+ }
176
+ const normalizeMethods = (methods) => {
177
+ const normalized = methods.map(type => type.toLowerCase());
178
+ if (normalized.length === 0 || normalized.some(type => !/^[a-z][a-z0-9_]*$/.test(type))
179
+ || new Set(normalized).size !== normalized.length) {
180
+ throw new PaymentError('pricing-policy:subscription-payment-methods');
181
+ }
182
+ return normalized;
183
+ };
184
+ const subscriptionPaymentMethodTypes = stripe.subscriptionPaymentMethodTypes != null
185
+ ? normalizeMethods(stripe.subscriptionPaymentMethodTypes) : undefined;
186
+ const subscriptionPaymentMethodTypesByCurrency = {};
187
+ for (const [key, methods] of Object.entries(stripe.subscriptionPaymentMethodTypesByCurrency ?? {})) {
188
+ const currency = key.toLowerCase();
189
+ if (!/^[a-z]{3}$/.test(currency) || Object.hasOwn(subscriptionPaymentMethodTypesByCurrency, currency)) {
190
+ throw new PaymentError('pricing-policy:subscription-payment-methods-currency');
191
+ }
192
+ subscriptionPaymentMethodTypesByCurrency[currency] = normalizeMethods(methods);
193
+ }
194
+ plugin(cfg, {
195
+ ...stripe,
196
+ ...(settlementCurrency != null ? { settlementCurrency } : {}),
197
+ ...(subscriptionPaymentMethodTypes != null ? { subscriptionPaymentMethodTypes } : {}),
198
+ ...(stripe.subscriptionPaymentMethodTypesByCurrency != null ? { subscriptionPaymentMethodTypesByCurrency } : {}),
199
+ }, STRIPE_PRICING_PLUGIN_CONFIG);
200
+ }
201
+ };
202
+ /**
203
+ * Declare the consumer-rights policy (EU withdrawal, spend consent, start requests, cancellation,
204
+ * country lock) — a singleton config record like the pricing policy: `DEFAULT_CONSUMER_RIGHTS`
205
+ * filled in, asserted, and replacing any earlier declaration. It is ADVERTISED to the browser; the
206
+ * `mail` options (mailer alias, sender, archive copies) go to a backend-only plugin config.
207
+ *
208
+ * `trader` (who the consumer contracts with: `name` for the statements, `legalName`/`address`/`email`
209
+ * for the mails and the withdrawal information) is backend-only as well.
210
+ *
211
+ * @throws ConsumerRightsError (`policy:<field>`) — see `assertConsumerRightsPolicy`; `policy:trader`
212
+ * when a mechanism is on and no trader `name` and `legalName` are declared.
213
+ */
214
+ export const declareConsumerRights = (cfg, def) => {
215
+ const { mail, trader, ...declaration } = def;
216
+ const policy = makeConsumerRightsPolicy(declaration);
217
+ const anyMechanism = Object.values(policy.mechanisms).some(on => on === true);
218
+ if (anyMechanism && (trader?.name == null || trader.name.trim() === '' || trader.legalName == null
219
+ || trader.legalName.trim() === '')) {
220
+ throw new ConsumerRightsError('policy:trader');
221
+ }
222
+ if (mail?.bcc?.some(address => !/^[^\s@]+@[^\s@]+$/.test(address)) === true) {
223
+ throw new ConsumerRightsError('policy:mail-bcc');
224
+ }
225
+ cfg.records = (cfg.records ?? []).filter(record => record.id !== CONSUMER_RIGHTS_RECORD_ID);
226
+ cfg.records.push({
227
+ ...configHelper.toConfigRecord(policy), recordType: CONSUMER_RIGHTS_RECORD_TYPE, id: CONSUMER_RIGHTS_RECORD_ID,
228
+ });
229
+ const plugins = cfg[PLUGIN_RECORD];
230
+ if (plugins != null) {
231
+ cfg[PLUGIN_RECORD] = plugins
232
+ .filter(record => record.id !== CONSUMER_RIGHTS_MAIL_PLUGIN_CONFIG);
233
+ }
234
+ if (mail != null || trader != null) {
235
+ plugin(cfg, {
236
+ ...(trader != null ? {
237
+ trader: {
238
+ name: trader.name.trim(), legalName: trader.legalName.trim(),
239
+ ...(trader.address != null && trader.address.trim() !== '' ? { address: trader.address.trim() } : {}),
240
+ ...(trader.email != null && trader.email.trim() !== '' ? { email: trader.email.trim() } : {}),
241
+ ...(trader.website != null && trader.website.trim() !== '' ? { website: trader.website.trim() } : {}),
242
+ },
243
+ } : {}),
244
+ ...(mail?.alias != null ? { alias: mail.alias } : {}),
245
+ ...(mail?.from != null ? { from: mail.from } : {}),
246
+ ...(mail?.replyTo != null ? { replyTo: mail.replyTo } : {}),
247
+ ...(mail?.bcc != null && mail.bcc.length > 0 ? { bcc: [...mail.bcc] } : {}),
248
+ }, CONSUMER_RIGHTS_MAIL_PLUGIN_CONFIG);
249
+ }
250
+ return policy;
45
251
  };
46
252
  //# sourceMappingURL=config.js.map