@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,174 @@
1
+ ---
2
+ name: reference
3
+ description: The consumer-rights contracts — declaring the policy, the records, the ConsumerRightsService methods and usage meter, withdrawal and cancellation step by step, mails and handler options.
4
+ metadata:
5
+ purposes: payment, consent, server-api
6
+ mentions: declareConsumerRights, ConsumerRightsService, CONSUMER_RIGHTS_SERVICE, consumerRightsOf, recordConsent, assertConsent, recordStartRequest, withdrawalCandidates, PerformanceConsentRequired, SubscriptionStartRequired, UsageMeter, withdrawalRefundHelper
7
+ ---
8
+ <!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
9
+
10
+ # @owlmeans/server-payment — Consumer-rights reference
11
+
12
+ The contracts behind `SKILL.md` § Consumer rights. Types live in `src/types.ts`, schemas in
13
+ `src/schemas.ts`, the service in `src/consumer/service.ts`.
14
+
15
+ ## Declaring
16
+
17
+ ```typescript
18
+ declareConsumerRights(cfg, {
19
+ ...ConsumerRightsDeclaration, // @owlmeans/payment: textVersion, links (per language), mechanisms,
20
+ // currencies { eu, other }, countries, withdrawalDays, deadline, …
21
+ trader: { name, legalName, address?, email?, website? }, // backend only; required when any mechanism is on
22
+ mail: { alias?, from?, replyTo?, bcc?: string[] }, // backend only
23
+ consentContext?: string, // advertised: the performance-consent copy variant (`included`)
24
+ }): ConsumerRightsPolicy
25
+ ```
26
+
27
+ - The policy is a singleton ADVERTISED config record (`CONSUMER_RIGHTS_RECORD_ID`), filled from
28
+ `DEFAULT_CONSUMER_RIGHTS` (14 days, weekend rollover, **margin 5 days**, every mechanism off) and
29
+ asserted; a second declaration replaces the first.
30
+ - `trader` and `mail` go to the plugin config `_external:payment-consumer-mail`
31
+ (`CONSUMER_RIGHTS_MAIL_PLUGIN_CONFIG`), never advertised. `trader.name` fills `{{trader}}` in the
32
+ consent and start statements; `legalName, address, email` (whatever is declared) fill it in the
33
+ mails, the withdrawal information and the model form.
34
+ - Refusals: `ConsumerRightsError('policy:trader')` (a mechanism on, no `name`/`legalName`),
35
+ `'policy:mail-bcc'`, and every `consumerRightsPolicyHelper.assertConsumerRightsPolicy` refusal.
36
+
37
+ ## Records
38
+
39
+ | Record | Fields |
40
+ |---|---|
41
+ | `BillingProfileRecord` | `entityId, country, region, currency, language, source ('checkout'\|'customer'\|'manual'), paygate, customerId?, sessionId?, ipCountry?, email?, name?, business?, lockedAt, createdAt, updatedAt?` |
42
+ | `PurchaseRecord` | `purchaseId, contractRef, entityId, kind, paygate, sessionId?, subscriptionId?, paymentIntentId?, invoiceId?, invoiceNumber?, invoiceLineId?, productSku, planSku?, profileId?, country?, region?, ipCountry?, inScope, language, email?, name?, business?, currency, amountSubtotalMinor, amountTaxMinor, amountTotalMinor, presentmentCurrency?, presentmentAmountMinor?, netAmountMinor?, amountCurrency?, units?, taxBehavior?, termsAccepted?, textVersion?, copyVersion?, startRequestId?, servicesStartedAt?, confirmationMailAt?, purchasedAt, deadline?, consentId?, consentedAt?, withdrawalId?, withdrawnAt?, refundedMinor?, refundedAt?, cancellationId?, cancelEffectiveAt?, createdAt, updatedAt?` |
43
+ | `ConsumerConsentRecord` | `kind ('performance'\|'subscription-start'), entityId, profileId?, name?, email?, purchaseIds[], planSku?, planName?, textVersion, copyVersion, language, uiLanguage?, trader, context? (the copy variant: the policy's `consentContext` / `consumerCopyHelper.startContextOf(plan)`), text {request, acknowledgement, checkbox}, links, deadline?, decidedAt, expiresAt?` + `RequestOrigin` |
44
+ | `ConsumerDeclarationRecord` | `kind ('withdrawal'\|'cancellation'), channel ('in-app'\|'public'), entityId?, purchaseId?, subscriptionId?, contractRef?, name, email, cancellationKind?, reason?, effective?, requestedDate?, language, textVersion?, copyVersion, receivedAt, matched, profileId?, duplicateOf?, status, refundMinor?, currency?, effectiveAt?` + `RequestOrigin` |
45
+ | `ConsumerEventRecord` | `recordId, recordKind ('purchase'\|'consent'\|'declaration'\|'profile'\|'checkout'), entityId?, action, step?, ok, skipped?, externalId?, amountMinor?, currency?, detail? (JSON), error?, at` |
46
+ | `RequestOrigin` | `ip?, forwardedFor?, userAgent?, ipCountry?, acceptLanguage?, via?` |
47
+
48
+ Event actions: `mail` (step = mail kind), `computed` (the meter reading and the refund, JSON),
49
+ `meter`, `refund`, `credit-note` (step `preview` for a failed preview), `subscription-cancel`,
50
+ `cancel-scheduled`, `observers` (step = `consent`/`withdrawal`/`cancellation`), `lock`,
51
+ `lock-mismatch`, `relock`, `unlock` (detail: `from`, `by`, `reason`, the deleted `profile`),
52
+ `duplicate`, `checkout-terms-fallback` (`recordKind: 'checkout'`, `recordId` = the entity,
53
+ `externalId` = the session created without the checkbox, `ok: false`, detail: the Stripe `message`,
54
+ `code`, `param`, `mode`, `productSku`, `planSku`; `error` when the retry failed too).
55
+
56
+ `PurchaseRecord.termsAccepted` is Stripe's `consent.terms_of_service` of the completed session and
57
+ nothing else; `confirmationMailAt` is the one claim of the purchase confirmation.
58
+
59
+ Accessors (`paymentAccessOf(ctx)`, `src/access.ts`): `billingProfiles`, `purchases`, `consumerConsents`,
60
+ `consumerDeclarations`, `consumerEvents`, `consumerRights`, `consumerRightsOf`; `paymentUtils.conditionalSet` (`src/utils.ts`).
61
+
62
+ ## The service (`ConsumerRightsService`, `CONSUMER_RIGHTS_SERVICE = 'payment-consumer-rights'`)
63
+
64
+ | Method | Does |
65
+ |---|---|
66
+ | `managed` | `false`: `withdraw`, `cancel` and reconcile's paygate steps refuse / skip. The application's explicit `manage`, else the gateway's, else `true` — whatever the registration order |
67
+ | `policy()` | the declared policy or `null` |
68
+ | `profile(entityId)` | the locked `BillingProfileView`, or `null` (the handler answers an unlocked view) |
69
+ | `lock(entityId, country, source, { force?, by?, reason?, currency?, … })` | first write wins; `manual` + `force` relocks (event `relock`) |
70
+ | `unlock(entityId, { by?, reason? })` | deletes the profile while it still holds the country read (else `ConsumerRightsError('unlock:changed:<id>')`), event `unlock`; answers the old view or `null`; no lazy lock from the paygate customer follows |
71
+ | `purchases(entityId, { open?, at? })` | `PurchaseView[]`, newest first; `withdrawable` asks the meter for top-ups |
72
+ | `consentView(entityId, at?)` | `PerformanceConsentView`: the open unconsented top-up windows, the billing language, the trader name, links, `context` = the policy's `consentContext` (absent without one) |
73
+ | `recordConsent(subject, body, origin?)` | 428 on a stale version or a view that saw none of the open windows; covers the listed open windows; `text` = `consumerCopyHelper.consentStatementOf(body.language, Performance, { trader, context: policy.consentContext })`, `context` stored |
74
+ | `assertConsent(entityId, at?)` | one indexed query; `PerformanceConsentRequired {pending, deadline}` |
75
+ | `startView(entityId, planSku, { language? })` | `SubscriptionStartView`; `required` unless locked outside the territories; `context` = `consumerCopyHelper.startContextOf(plan)` |
76
+ | `recordStartRequest(subject, body, origin?, { plan? })` | 428 `SubscriptionStartRequired` on a stale version; `UnknownPlan`; `text` = `consumerCopyHelper.consentStatementOf(body.language, SubscriptionStart, { trader, plan, context: consumerCopyHelper.startContextOf(plan) })`, `context` stored; mails the start confirmation |
77
+ | `assertStartRequest(entityId, planSku, id?)` | the fresh request bound to entity, plan and text version, or `null` when none is needed; else 428 |
78
+ | `withdrawalCandidates(entityId, subject?)` | open windows with an estimate (a top-up fully used after consent is left out); `automatic` = refunds on, meter present, managed |
79
+ | `withdraw(subject \| null, body, origin?)` | see below |
80
+ | `cancel(subject \| null, body, origin?)` | see below |
81
+ | `useMeter(meter)` / `usageMeter()` | the application's `UsageMeter` — settable while wiring (a lazy service) |
82
+ | `useMailRenderer(fn)` / `mailRenderer()` | `(kind, data, rendered) => MailMessage \| null \| undefined` |
83
+ | `reconcile({ since?, limit? })` | `{ retried, mailed, observed, backfilled, locked, failed }` |
84
+
85
+ `ConsumerSubject { entityId, profileId?, name?, email?, channel? }` — `channel: 'public'` when the
86
+ application matched a public declaration to an organization itself (the answer stays public).
87
+
88
+ ### The usage meter
89
+
90
+ ```typescript
91
+ interface PurchaseRef { purchaseId; kind; entityId; contractRef; productSku; planSku?; sessionId?; subscriptionId?; invoiceId?; purchasedAt }
92
+ interface UsageMeter {
93
+ used(ctx, q: { entityId; purchase: PurchaseRef; after?: Date; at: Date }):
94
+ Promise<{ granted; used; usedAfter; settled?; clawed?; remaining? }>
95
+ }
96
+ ```
97
+
98
+ `after` is the purchase's `consentedAt` (a subscription: its start request); without it
99
+ `usedAfter` must be 0. Deduction = `usedAfter + settled + clawed`; the units taken back
100
+ (`WithdrawalEvent.units.returned`) = `remaining ?? granted − used − settled − clawed`.
101
+
102
+ ## Withdrawal, step by step
103
+
104
+ 1. Policy and `mechanisms.withdrawal` required; managed required.
105
+ 2. Resolve: in-app `purchaseId` (or a contract) of the subject's organization — unknown,
106
+ out of scope or already refunded refuse (`WithdrawalUnavailable`, 409); public: contract
107
+ reference (normalized) or invoice number, and an e-mail of the purchase / profile / paygate
108
+ customer (case-insensitive).
109
+ 3. Already withdrawn: record the declaration with `duplicateOf`, answer the original receipt.
110
+ 4. Decide: unmatched or no right → `received`; past the deadline → `expired`; meter and automatic
111
+ refunds → compute (`processing`; a top-up with nothing to reimburse is `performed` in-app,
112
+ `review` in public); else `review`.
113
+ 5. Append the declaration (status, refund, currency); for `processing`/`review` set `withdrawnAt`
114
+ and `withdrawalId` conditionally — a loser records a `duplicate` event and answers the winner.
115
+ 6. Record `computed`; mail the receipt (refund / review / expired / unmatched text).
116
+ 7. Paygate (`processing` only), first attempt under `withdrawal:<id>:<step>`:
117
+ - subscription: `subscriptions.cancel(id, { prorate: false, invoice_now: false, cancellation_details: { comment: 'withdrawal:<id>' } })`, row `withdrawnAt`;
118
+ - invoice-backed: `creditNotes.preview({ invoice, lines: [{ type: 'invoice_line_item', invoice_line_item, amount: net }] })`, `refunds.create({ payment_intent, amount: min(open, preview.total), reason: 'requested_by_customer', metadata: { owlmeans, withdrawalId, purchaseId } })`, `creditNotes.create({ invoice, lines, refund, memo, metadata })` — a failed preview or credit note keeps the plain refund (event recorded);
119
+ - no invoice: the plain refund of the gross amount;
120
+ - no payment intent: `review`.
121
+ 8. `onWithdrawal` for `refunded` and `review`; a `failed` one is told after reconcile succeeds.
122
+
123
+ The refund is `withdrawalRefundHelper.oneTimeWithdrawalRefund` (gross on the total, net on the subtotal with the earlier
124
+ refunds' net share) or `.subscriptionWithdrawalRefund` (components of the net, time from the start
125
+ request, units by the meter; gross `ceil(paid × net' / net)`), always capped at what is still
126
+ unrefunded and rounded in the consumer's favour.
127
+
128
+ ## Cancellation, step by step
129
+
130
+ 1. Policy and `mechanisms.cancellation`; managed.
131
+ 2. Resolve the subscription: in-app `subscriptionId`, a contract, else the entitling Stripe
132
+ subscription (none → `CancellationUnavailable('no-subscription')`, ended → `'ended'`); public the
133
+ contract + e-mail, else the only organization whose paygate customer has the e-mail.
134
+ 3. Decide: extraordinary → `review` (paygate untouched); ordinary and live →
135
+ `cancellationEffectiveAt(periodEnd, interval, requested)` → `already-scheduled` when the period
136
+ end is already scheduled, else `scheduled`; otherwise `received`.
137
+ 4. Append the declaration; `scheduled`: `subscriptions.update` (`cancel_at_period_end` or
138
+ `cancel_at` + `proration_behavior: 'none'`, `cancellation_details.comment 'cancellation:<id>'`,
139
+ key `cancellation:<id>:schedule`) — a failure answers `received` and is retried.
140
+ 5. Purchase `cancellationId`/`cancelEffectiveAt`; mail the receipt (effective / review /
141
+ unmatched); `onCancellation`.
142
+
143
+ ## Mails
144
+
145
+ | Kind | When | Content |
146
+ |---|---|---|
147
+ | `purchase` | an in-scope purchase with an e-mail, once (the conditional `confirmationMailAt` claim) | order (contract, date, product, total incl. tax), the start request verbatim, withdrawal information with the function's address, model form, links |
148
+ | `consent` | a consent covering purchases | the statement verbatim (the recorded `text.checkbox` — the `consentContext` variant when declared), date/time UTC, the purchases with their last day, the unused-credits rule, links |
149
+ | `start` | a start request | the statement verbatim, the plan, the rule of the recorded variant (`email.start.rule`, `rule_units` when the record's `context` is `units`), links |
150
+ | `withdrawal` | every declaration (not a repeat) | the declaration, date/time of receipt, refund / review / expired / unmatched |
151
+ | `cancellation` | every declaration | the declaration, the effective date / review / unmatched |
152
+
153
+ Recipient: the purchase e-mail; the consent's person, else the profile / latest purchase /
154
+ paygate customer e-mail; the declaration's e-mail. `ConsumerMailData` carries the records a
155
+ renderer needs (`purchase`, `purchases`, `consent`, `declaration`, `links`, `trader`).
156
+
157
+ ## Handlers
158
+
159
+ Every hook gets the request's context last (`ctx`): reach services through it, keep no module state.
160
+
161
+ | Option | Default | Use |
162
+ |---|---|---|
163
+ | `resolveEntity(req, ctx)` | `req.entity?.id` | the organization the account routes act for |
164
+ | `subjectOf(req, ctx)` | — | profile id, name and e-mail prefill |
165
+ | `guardMoney(req, action, ctx)` | — | `consent`, `start`, `withdraw`, `cancel` — refuse API keys |
166
+ | `throttle(req, { action, email, ip }, ctx)` | **required with `public`** | per-IP / per-e-mail / global counters; throw 429 |
167
+ | `metaOf(req, ctx)` | `originHelper.requestOriginOf` | the evidence recorded |
168
+ | `publicMinMs` | 1000 | the least time a public declaration answers in |
169
+ | `planNameOf(planSku, language, req, ctx)` | — | the plan's short name in a start statement |
170
+ | `serviceAlias` | `CONSUMER_RIGHTS_SERVICE` | — |
171
+
172
+ Bound routes: account `base, profile, purchases, consent, giveConsent, start, requestStart,
173
+ withdrawals, withdraw, cancel`; public `base, policy, withdraw, cancel` (the screens are frontend
174
+ routes). `checkoutReadEntrypoints`: `base, amountPolicy, planPrices`.
@@ -0,0 +1,46 @@
1
+ import type Stripe from 'stripe';
2
+ import type { PaymentService } from '@owlmeans/payment';
3
+ import type { BillingProfileResource, CompletionObserver, ConsumerConsentResource, ConsumerDeclarationResource, ConsumerEventResource, ConsumerMailPluginConfig, ConsumerRightsService, EntitlementService, FingerprintResource, GatewayService, PaygateCustomerResource, PaymentFulfillmentResource, PaymentSubscriptionRecord, PaymentSubscriptionResource, PaymentUsageCounterResource, PaymentUsageResource, PaymentWebhookResource, PortalBrandingConfig, PurchaseResource, StripePluginConfig, StripePricingPluginConfig } from '../types.js';
4
+ /** What one context holds for payments: its services, its resources, its plugin configs and its Stripe client. */
5
+ export interface PaymentAccess {
6
+ payment: () => PaymentService;
7
+ gateway: () => GatewayService;
8
+ /** The gateway, or `null` in a context that registered none. */
9
+ gatewayOf: () => GatewayService | null;
10
+ observer: () => CompletionObserver;
11
+ entitlements: () => EntitlementService;
12
+ paygateCustomers: () => PaygateCustomerResource;
13
+ subscriptions: () => PaymentSubscriptionResource;
14
+ fulfillments: () => PaymentFulfillmentResource;
15
+ paymentWebhooks: () => PaymentWebhookResource;
16
+ usageEvents: () => PaymentUsageResource;
17
+ usageCounters: () => PaymentUsageCounterResource;
18
+ fingerprints: () => FingerprintResource;
19
+ billingProfiles: () => BillingProfileResource;
20
+ purchases: () => PurchaseResource;
21
+ consumerConsents: () => ConsumerConsentResource;
22
+ consumerDeclarations: () => ConsumerDeclarationResource;
23
+ consumerEvents: () => ConsumerEventResource;
24
+ /** The consumer-rights service. @throws when it is not registered */
25
+ consumerRights: (alias?: string) => ConsumerRightsService;
26
+ /** The consumer-rights service, or `null` in a process that registered none. */
27
+ consumerRightsOf: (alias?: string) => ConsumerRightsService | null;
28
+ stripeConfig: () => Promise<StripePluginConfig>;
29
+ /** The portal branding declared with `portalBranding`, or `null`. */
30
+ portalBrandingConfig: () => Promise<PortalBrandingConfig | null>;
31
+ /** The consumer-rights mail options declared with `declareConsumerRights`, or `null`. */
32
+ consumerMailConfig: () => Promise<ConsumerMailPluginConfig | null>;
33
+ /** The Stripe-only pricing settings declared with `declarePaymentPricing`, or `null`. */
34
+ stripePricingConfig: () => Promise<StripePricingPluginConfig | null>;
35
+ /**
36
+ * A Stripe client pinned to {@link STRIPE_PINNED_API_VERSION}: the API version this package's payload
37
+ * readers, the stored webhook endpoints and the test doubles are written for. The installed SDK is typed
38
+ * for a newer one, so a read of a field the newer version moved (a subscription's period, an invoice's
39
+ * subscription) is cast at the seam until the readers are migrated — the pin is what keeps the shapes
40
+ * the code parses and the shapes Stripe sends the same.
41
+ */
42
+ stripeClient: () => Promise<Stripe>;
43
+ /** The entity's highest-ranked entitling subscription of one product. */
44
+ activeSubscription: (entityId: string, productSku: string) => Promise<PaymentSubscriptionRecord | null>;
45
+ }
46
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/access/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EACV,sBAAsB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,2BAA2B,EAChG,qBAAqB,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,mBAAmB,EAC/G,cAAc,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,yBAAyB,EAC9F,2BAA2B,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,sBAAsB,EACtG,oBAAoB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,yBAAyB,EACtF,MAAM,aAAa,CAAA;AAEpB,kHAAkH;AAClH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,cAAc,CAAA;IAC7B,OAAO,EAAE,MAAM,cAAc,CAAA;IAC7B,gEAAgE;IAChE,SAAS,EAAE,MAAM,cAAc,GAAG,IAAI,CAAA;IACtC,QAAQ,EAAE,MAAM,kBAAkB,CAAA;IAClC,YAAY,EAAE,MAAM,kBAAkB,CAAA;IACtC,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;IAC/C,aAAa,EAAE,MAAM,2BAA2B,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],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import type { Context as ApiContext } from '@owlmeans/server-api';
2
+ import type { PaymentAccess } from './access/types.js';
3
+ export declare const makePaymentAccess: (ctx: ApiContext) => PaymentAccess;
4
+ /** The payment access of a context — one per context. */
5
+ export declare const paymentAccessOf: (target: ApiContext<import("@owlmeans/server-api").Config>) => PaymentAccess;
6
+ //# sourceMappingURL=access.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAgBjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEtD,eAAO,MAAM,iBAAiB,QAAS,UAAU,KAAG,aA4DnD,CAAA;AAED,yDAAyD;AACzD,eAAO,MAAM,eAAe,8EAAwC,CAAA"}
@@ -0,0 +1,45 @@
1
+ import Stripe from 'stripe';
2
+ import { PLUGINS } from '@owlmeans/config';
3
+ import { memoHelper } from '@owlmeans/context';
4
+ import { DEFAULT_ALIAS as PAYMENT_SERVICE, ENTITLING_STATUSES } from '@owlmeans/payment';
5
+ import { CONSUMER_RIGHTS_MAIL_PLUGIN_CONFIG, CONSUMER_RIGHTS_SERVICE, ENTITLEMENT_SERVICE, GATEWAY_SERVICE, PAYMENT_OBSERVER, RES_BILLING_PROFILE, RES_CONSUMER_CONSENT, RES_CONSUMER_DECLARATION, RES_CONSUMER_EVENT, RES_PAYGATE_CUSTOMER, RES_PAYMENT_FINGERPRINT, RES_PAYMENT_FULFILLMENT, RES_PAYMENT_PURCHASE, RES_PAYMENT_SUBSCRIPTION, RES_PAYMENT_USAGE, RES_PAYMENT_USAGE_COUNTER, RES_PAYMENT_WEBHOOK, STRIPE_PINNED_API_VERSION, STRIPE_PLUGIN_CONFIG, STRIPE_PORTAL_PLUGIN_CONFIG, STRIPE_PRICING_PLUGIN_CONFIG, } from './consts.js';
6
+ export const makePaymentAccess = (ctx) => {
7
+ const hasService = (alias) => ctx.hasService?.(alias) === true;
8
+ const plugins = () => ctx.getConfigResource(PLUGINS);
9
+ const payment = () => ctx.service(PAYMENT_SERVICE);
10
+ const gateway = () => ctx.service(GATEWAY_SERVICE);
11
+ const gatewayOf = () => hasService(GATEWAY_SERVICE) ? gateway() : null;
12
+ const observer = () => ctx.service(PAYMENT_OBSERVER);
13
+ const entitlements = () => ctx.service(ENTITLEMENT_SERVICE);
14
+ const paygateCustomers = () => ctx.resource(RES_PAYGATE_CUSTOMER);
15
+ const subscriptions = () => ctx.resource(RES_PAYMENT_SUBSCRIPTION);
16
+ const fulfillments = () => ctx.resource(RES_PAYMENT_FULFILLMENT);
17
+ const paymentWebhooks = () => ctx.resource(RES_PAYMENT_WEBHOOK);
18
+ const usageEvents = () => ctx.resource(RES_PAYMENT_USAGE);
19
+ const usageCounters = () => ctx.resource(RES_PAYMENT_USAGE_COUNTER);
20
+ const fingerprints = () => ctx.resource(RES_PAYMENT_FINGERPRINT);
21
+ const billingProfiles = () => ctx.resource(RES_BILLING_PROFILE);
22
+ const purchases = () => ctx.resource(RES_PAYMENT_PURCHASE);
23
+ const consumerConsents = () => ctx.resource(RES_CONSUMER_CONSENT);
24
+ const consumerDeclarations = () => ctx.resource(RES_CONSUMER_DECLARATION);
25
+ const consumerEvents = () => ctx.resource(RES_CONSUMER_EVENT);
26
+ const consumerRights = (alias = CONSUMER_RIGHTS_SERVICE) => ctx.service(alias);
27
+ const consumerRightsOf = (alias = CONSUMER_RIGHTS_SERVICE) => hasService(alias) ? ctx.service(alias) : null;
28
+ const stripeConfig = async () => await plugins().get(STRIPE_PLUGIN_CONFIG);
29
+ const portalBrandingConfig = async () => await plugins().load(STRIPE_PORTAL_PLUGIN_CONFIG);
30
+ const consumerMailConfig = async () => await plugins().load(CONSUMER_RIGHTS_MAIL_PLUGIN_CONFIG);
31
+ const stripePricingConfig = async () => await plugins().load(STRIPE_PRICING_PLUGIN_CONFIG);
32
+ const stripeClient = async () => new Stripe((await stripeConfig()).api, { apiVersion: STRIPE_PINNED_API_VERSION });
33
+ const activeSubscription = async (entityId, productSku) => await subscriptions().load({
34
+ entityId, productSku, status: [...ENTITLING_STATUSES],
35
+ }, { sort: [{ field: 'rank', order: 'desc' }, { field: 'createdAt', order: 'desc' }] });
36
+ return {
37
+ payment, gateway, gatewayOf, observer, entitlements, paygateCustomers, subscriptions, fulfillments,
38
+ paymentWebhooks, usageEvents, usageCounters, fingerprints, billingProfiles, purchases, consumerConsents,
39
+ consumerDeclarations, consumerEvents, consumerRights, consumerRightsOf, stripeConfig, portalBrandingConfig,
40
+ consumerMailConfig, stripePricingConfig, stripeClient, activeSubscription,
41
+ };
42
+ };
43
+ /** The payment access of a context — one per context. */
44
+ export const paymentAccessOf = memoHelper.oncePer(makePaymentAccess);
45
+ //# sourceMappingURL=access.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access.js","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,kBAAkB,EAAuB,MAAM,mBAAmB,CAAA;AAE7G,OAAO,EACL,kCAAkC,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,eAAe,EACjG,gBAAgB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,kBAAkB,EACzG,oBAAoB,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,oBAAoB,EAC5F,wBAAwB,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,mBAAmB,EAC3F,yBAAyB,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,4BAA4B,GAC3G,MAAM,aAAa,CAAA;AAWpB,MAAM,CAAC,MAAM,iBAAi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BAAmB,GAAG,KAAK,IAA+C,EAAE,CAChF,MAAM,OAAO,EAAE,CAAC,IAAI,CAAC,4BAA4B,CAAqC,CAAA;IAExF,MAAM,YAAY,GAAG,KAAK,IAAqB,EAAE,CAC/C,IAAI,MAAM,CAAC,CAAC,MAAM,YAAY,EAAE,CAAC,CAAC,GAAG,EAAE,EAAE,UAAU,EAAE,yBAAkC,EAAE,CAAC,CAAA;IAE5F,MAAM,kBAAkB,GAAG,KAAK,EAC9B,QAAgB,EAAE,UAAkB,EACO,EAAE,CAAC,MAAM,aAAa,EAAE,CAAC,IAAI,CAAC;QACzE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,GAAG,kBAAkB,CAAC;KACtD,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAA;IAEvF,OAAO;QACL,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,YAAY;QAClG,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,gBAAgB;QACvG,oBAAoB,EAAE,cAAc,EAAE,cAAc,EAAE,gBAAgB,EAAE,YAAY,EAAE,oBAAoB;QAC1G,kBAAkB,EAAE,mBAAmB,EAAE,YAAY,EAAE,kBAAkB;KAC1E,CAAA;AACH,CAAC,CAAA;AAED,yDAAyD;AACzD,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAA"}
@@ -1,3 +1,4 @@
1
1
  export * from './webhook.js';
2
2
  export * from './resync.js';
3
+ export * from './resync-subscriptions.js';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,2BAA2B,CAAA"}
@@ -1,3 +1,4 @@
1
1
  export * from './webhook.js';
2
2
  export * from './resync.js';
3
+ export * from './resync-subscriptions.js';
3
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,2BAA2B,CAAA"}
@@ -0,0 +1,3 @@
1
+ /** Re-read every live paygate subscription — the manually or periodically triggered repair. */
2
+ export declare const resyncSubscriptions: import("@owlmeans/server-entrypoint").BoundEntrypointHandler<import("@owlmeans/entrypoint").EntrypointProtocol<{}, import("../types.js").ResyncSubscriptionsResult>>;
3
+ //# sourceMappingURL=resync-subscriptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resync-subscriptions.d.ts","sourceRoot":"","sources":["../../src/actions/resync-subscriptions.ts"],"names":[],"mappings":"AAOA,+FAA+F;AAC/F,eAAO,MAAM,mBAAmB,sKAC8B,CAAA"}
@@ -0,0 +1,7 @@
1
+ import { handlers } from '@owlmeans/server-api';
2
+ import { paymentAccessOf } from '../access.js';
3
+ import { paymentGate } from '../protocol.js';
4
+ const bind = handlers();
5
+ /** Re-read every live paygate subscription — the manually or periodically triggered repair. */
6
+ export const resyncSubscriptions = bind.request(paymentGate.resyncSubscriptions, async (_request, context) => await paymentAccessOf(context).gateway().resyncAll(context));
7
+ //# sourceMappingURL=resync-subscriptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resync-subscriptions.js","sourceRoot":"","sources":["../../src/actions/resync-subscriptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,MAAM,IAAI,GAAG,QAAQ,EAAW,CAAA;AAEhC,+FAA+F;AAC/F,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,mBAAmB,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,CAC3G,MAAM,eAAe,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAA"}
@@ -1,2 +1,7 @@
1
- export declare const resync: import("@owlmeans/server-entrypoint").BoundEntrypointHandler<import("@owlmeans/entrypoint").EntrypointProtocol<{}, import("../consts.js").ResyncResult>>;
1
+ /**
2
+ * Forget every sync fingerprint and bring Stripe back to the declared catalogue, portal and webhook —
3
+ * in any managed process, `bootstrap: false` included: the webhook URL and the rows follow the
4
+ * gateway's `webhookService` and `owner`, so every process of the owner converges on one state.
5
+ */
6
+ export declare const resync: import("@owlmeans/server-entrypoint").BoundEntrypointHandler<import("@owlmeans/entrypoint").EntrypointProtocol<{}, import("../types.js").ResyncResult>>;
2
7
  //# sourceMappingURL=resync.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resync.d.ts","sourceRoot":"","sources":["../../src/actions/resync.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,MAAM,0JAIjB,CAAA"}
1
+ {"version":3,"file":"resync.d.ts","sourceRoot":"","sources":["../../src/actions/resync.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,eAAO,MAAM,MAAM,yJAOjB,CAAA"}
@@ -1,11 +1,21 @@
1
+ import { PaygateError } from '@owlmeans/payment';
1
2
  import { handlers } from '@owlmeans/server-api';
2
- import { paymentGate } from '../consts.js';
3
- import { fingerprints } from '../utils.js';
4
- import { initialize } from '../sync.js';
3
+ import { paymentAccessOf } from '../access.js';
4
+ import { paymentGate } from '../protocol.js';
5
+ import { stripeBootstrapOf } from '../bootstrap.js';
5
6
  const bind = handlers();
7
+ /**
8
+ * Forget every sync fingerprint and bring Stripe back to the declared catalogue, portal and webhook —
9
+ * in any managed process, `bootstrap: false` included: the webhook URL and the rows follow the
10
+ * gateway's `webhookService` and `owner`, so every process of the owner converges on one state.
11
+ */
6
12
  export const resync = bind.request(paymentGate.resync, async (_request, context) => {
7
- await fingerprints(context).clear();
8
- await initialize(context);
13
+ const paymentAccess = paymentAccessOf(context);
14
+ const service = paymentAccess.gateway();
15
+ if (!service.managed)
16
+ throw new PaygateError('unmanaged');
17
+ await paymentAccess.fingerprints().clear();
18
+ await stripeBootstrapOf(context).bootstrapStripe(await service.stripe(context), { force: true });
9
19
  return { ok: true };
10
20
  });
11
21
  //# sourceMappingURL=resync.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resync.js","sourceRoot":"","sources":["../../src/actions/resync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAGvC,MAAM,IAAI,GAAG,QAAQ,EAAW,CAAA;AAEhC,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE;IACjF,MAAM,YAAY,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAA;IACnC,MAAM,UAAU,CAAC,OAAO,CAAC,CAAA;IACzB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAA;AACrB,CAAC,CAAC,CAAA"}
1
+ {"version":3,"file":"resync.js","sourceRoot":"","sources":["../../src/actions/resync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAEnD,MAAM,IAAI,GAAG,QAAQ,EAAW,CAAA;AAEhC;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE;IACjF,MAAM,aAAa,GAAG,eAAe,CAAC,OAAO,CAAC,CAAA;IAC9C,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,EAAE,CAAA;IACvC,IAAI,CAAC,OAAO,CAAC,OAAO;QAAE,MAAM,IAAI,YAAY,CAAC,WAAW,CAAC,CAAA;IACzD,MAAM,aAAa,CAAC,YAAY,EAAE,CAAC,KAAK,EAAE,CAAA;IAC1C,MAAM,iBAAiB,CAAC,OAAO,CAAC,CAAC,eAAe,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IAChG,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAA;AACrB,CAAC,CAAC,CAAA"}
@@ -1,4 +1,5 @@
1
+ /** A Stripe delivery — only a managed gateway receives one; its secret is the `owner`'s stored one. */
1
2
  export declare const webhook: import("@owlmeans/server-entrypoint").BoundEntrypointHandler<import("@owlmeans/entrypoint").EntrypointProtocol<{
2
- params: import("../consts.js").PaygateParams;
3
+ params: import("../types.js").PaygateParams;
3
4
  }, undefined>>;
4
5
  //# sourceMappingURL=webhook.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../src/actions/webhook.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,OAAO;;cAGlB,CAAA"}
1
+ {"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../src/actions/webhook.ts"],"names":[],"mappings":"AAUA,uGAAuG;AACvG,eAAO,MAAM,OAAO;;cAKlB,CAAA"}
@@ -1,11 +1,17 @@
1
- import { UnknownPaygate } from '@owlmeans/payment';
1
+ import { PaygateError, UnknownPaygate } from '@owlmeans/payment';
2
2
  import { handlers } from '@owlmeans/server-api';
3
- import { paymentGate, STRIPE_PAYGATE_ALIAS } from '../consts.js';
4
- import { stripePlugin } from '../plugins/stripe.js';
3
+ import { STRIPE_PAYGATE_ALIAS } from '../consts.js';
4
+ import { paymentAccessOf } from '../access.js';
5
+ import { paymentGate } from '../protocol.js';
6
+ import { webhookOf } from '../plugins/webhook-manager.js';
5
7
  const bind = handlers();
8
+ /** A Stripe delivery — only a managed gateway receives one; its secret is the `owner`'s stored one. */
6
9
  export const webhook = bind.params(paymentGate.webhook, async ({ paygate }, context, request) => {
7
10
  if (paygate !== STRIPE_PAYGATE_ALIAS)
8
11
  throw new UnknownPaygate(paygate);
9
- await stripePlugin.handleWebhook(request, context);
12
+ const service = paymentAccessOf(context).gateway();
13
+ if (!service.managed)
14
+ throw new PaygateError('unmanaged');
15
+ await webhookOf(context).handleStripeWebhook(await service.stripe(context), request);
10
16
  });
11
17
  //# sourceMappingURL=webhook.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"webhook.js","sourceRoot":"","sources":["../../src/actions/webhook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,Q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AC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAA;IAClD,IAAI,CAAC,OAAO,CAAC,OAAO;QAAE,MAAM,IAAI,YAAY,CAAC,WAAW,CAAC,CAAA;IACzD,MAAM,SAAS,CAAC,OAAO,CAAC,CAAC,mBAAmB,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAA;AACtF,CAAC,CAAC,CAAA"}
@@ -0,0 +1,16 @@
1
+ import type Stripe from 'stripe';
2
+ import type { StripeBootstrapOptions } from '../types.js';
3
+ /** What brings Stripe to a deployment's declaration. */
4
+ export interface StripeBootstrapHelper {
5
+ /**
6
+ * Bring Stripe to what this deployment declares, each step on its own so one failing does not block
7
+ * the others: products and prices, the customer-portal configuration, the webhook endpoint.
8
+ *
9
+ * The webhook URL and the owner key come from the context's gateway (`webhookService`, `owner`), so
10
+ * every process of one deployment — the one bootstrapping at boot, a `resync`, an application's
11
+ * forced maintenance run — computes the same URL and rows; each step is fingerprinted, so running it
12
+ * from any of them is idempotent.
13
+ */
14
+ bootstrapStripe: (stripe: Stripe, opts?: StripeBootstrapOptions) => Promise<void>;
15
+ }
16
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/bootstrap/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEzD,wDAAwD;AACxD,MAAM,WAAW,qBAAqB;IACpC;;;;;;;;OAQG;IACH,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,sBAAsB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAClF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/bootstrap/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import type { Context as ApiContext } from '@owlmeans/server-api';
2
+ import type { StripeBootstrapHelper } from './bootstrap/types.js';
3
+ export declare const makeStripeBootstrapHelper: (ctx: ApiContext) => StripeBootstrapHelper;
4
+ /** The Stripe bootstrap of a context — one per context. */
5
+ export declare const stripeBootstrapOf: (target: ApiContext<import("@owlmeans/server-api").Config>) => StripeBootstrapHelper;
6
+ //# sourceMappingURL=bootstrap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAIjE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAKjE,eAAO,MAAM,yBAAyB,QAAS,UAAU,KAAG,qBAiB3D,CAAA;AAED,2DAA2D;AAC3D,eAAO,MAAM,iBAAiB,sFAAgD,CAAA"}
@@ -0,0 +1,26 @@
1
+ import { memoHelper } from '@owlmeans/context';
2
+ import { log } from './log.js';
3
+ import { productSyncOf } from './sync.js';
4
+ import { portalOf } from './plugins/portal.js';
5
+ import { webhookOf } from './plugins/webhook-manager.js';
6
+ export const makeStripeBootstrapHelper = (ctx) => {
7
+ const bootstrapStripe = async (stripe, opts = {}) => {
8
+ const steps = [
9
+ ['products', async () => await productSyncOf(ctx).syncStripeProducts(stripe)],
10
+ ['portal', async () => await portalOf(ctx).ensurePortalConfiguration(stripe, opts)],
11
+ ['webhook', async () => await webhookOf(ctx).ensureWebhookEndpoint(stripe, opts)],
12
+ ];
13
+ for (const [name, step] of steps) {
14
+ try {
15
+ await step();
16
+ }
17
+ catch (error) {
18
+ log.error('Stripe bootstrap step failed', { step: name, error });
19
+ }
20
+ }
21
+ };
22
+ return { bootstrapStripe };
23
+ };
24
+ /** The Stripe bootstrap of a context — one per context. */
25
+ export const stripeBootstrapOf = memoHelper.oncePer(makeStripeBootstrapHelper);
26
+ //# sourceMappingURL=bootstrap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE9B,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAExD,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,GAAe,EAAyB,EAAE;IAClF,MAAM,eAAe,GAAG,KAAK,EAAE,MAAc,EAAE,IAAI,GAA2B,EAAE,EAAiB,EAAE;QACjG,MAAM,KAAK,GAA4C;YACrD,CAAC,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;YAC7E,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC,yBAAyB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACnF,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,SAAS,CAAC,GAAG,CAAC,CAAC,qBAAqB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;SAClF,CAAA;QACD,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC;YACjC,IAAI,CAAC;gBACH,MAAM,IAAI,EAAE,CAAA;YACd,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,GAAG,CAAC,KAAK,CAAC,8BAA8B,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;YAClE,CAAC;QACH,CAAC;IACH,CAAC,CAAA;IAED,OAAO,EAAE,eAAe,EAAE,CAAA;AAC5B,CAAC,CAAA;AAED,2DAA2D;AAC3D,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAA"}
@@ -0,0 +1,38 @@
1
+ import type { PermissionSet } from '@owlmeans/auth';
2
+ import type { EffectivePlan, PaymentPlan, PaymentProduct } from '../types.js';
3
+ /** The catalogue a context declares, and the plan each entity holds in it. */
4
+ export interface CatalogueHelper {
5
+ /** A plan by sku, or `null` when the catalogue no longer declares it. */
6
+ findPlan: (planSku: string) => Promise<PaymentPlan | null>;
7
+ /** A product by sku, or `null`. */
8
+ findProduct: (productSku: string) => Promise<PaymentProduct | null>;
9
+ /** Every plan of every declared product. */
10
+ catalogPlans: () => Promise<PaymentPlan[]>;
11
+ /** The declared free plan an entity falls back to: the lowest rank, then the sku. */
12
+ freePlanOf: () => Promise<PaymentPlan | null>;
13
+ /**
14
+ * The plan an entity holds: its highest-ranked subscription in an entitling status (the catalogue
15
+ * rank, the stored one for a plan the catalogue no longer declares; the newest first on a tie),
16
+ * else the declared free plan. The plan answered carries the winning row's `overrides`
17
+ * (`overriddenPlan`), so every reader — ceilings, the view, the gates — sees one answer.
18
+ *
19
+ * @throws PlanRequired when there is neither.
20
+ */
21
+ resolveEffectivePlan: (entityId: string, at?: Date) => Promise<EffectivePlan>;
22
+ /**
23
+ * The capability sets an entity's effective plan grants now — sets behind a lapsed promo left out.
24
+ * Empty when the plan is not of one of `productSkus`.
25
+ */
26
+ entitlementsOf: (entityId: string, productSkus?: string[]) => Promise<PermissionSet[]>;
27
+ /** Every product sold through Stripe with the plans it sells there. */
28
+ stripePlansOf: () => Promise<Array<{
29
+ product: PaymentProduct;
30
+ plans: PaymentPlan[];
31
+ }>>;
32
+ /** The plan an amount/quantity checkout of a consumable product sells: the named one, else the first. */
33
+ consumablePlanOf: (productSku: string, planSku?: string) => Promise<{
34
+ product: PaymentProduct;
35
+ plan: PaymentPlan;
36
+ }>;
37
+ }
38
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/catalogue/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE7E,8EAA8E;AAC9E,MAAM,WAAW,eAAe;IAC9B,yEAAyE;IACzE,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IAC1D,mCAAmC;IACnC,WAAW,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAA;IACnE,4CAA4C;IAC5C,YAAY,EAAE,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC,CAAA;IAC1C,qFAAqF;IACrF,UAAU,EAAE,MAAM,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IAC7C;;;;;;;OAOG;IACH,oBAAoB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,IAAI,KAAK,OAAO,CAAC,aAAa,CAAC,CAAA;IAC7E;;;OAGG;IACH,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,aAAa,EAAE,CAAC,CAAA;IACtF,uEAAuE;IACvE,aAAa,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,cAAc,CAAC;QAAC,KAAK,EAAE,WAAW,EAAE,CAAA;KAAE,CAAC,CAAC,CAAA;IACtF,yGAAyG;IACzG,gBAAgB,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,cAAc,CAAC;QAAC,IAAI,EAAE,WAAW,CAAA;KAAE,CAAC,CAAA;CACpH"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/catalogue/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import type { Context as ApiContext } from '@owlmeans/server-api';
2
+ import type { CatalogueHelper } from './catalogue/types.js';
3
+ export declare const makeCatalogueHelper: (ctx: ApiContext) => CatalogueHelper;
4
+ /** The catalogue of a context — one per context. */
5
+ export declare const catalogueOf: (target: ApiContext<import("@owlmeans/server-api").Config>) => CatalogueHelper;
6
+ //# sourceMappingURL=catalogue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalogue.d.ts","sourceRoot":"","sources":["../src/catalogue.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAOjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAS3D,eAAO,MAAM,mBAAmB,QAAS,UAAU,KAAG,eAiHrD,CAAA;AAED,oDAAoD;AACpD,eAAO,MAAM,WAAW,gFAA0C,CAAA"}