@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,31 @@
1
+ import type Stripe from 'stripe';
2
+ /** A resource whose Mongo collection is reached directly — a conditional write's target. */
3
+ export interface CollectionHolder {
4
+ collection: unknown;
5
+ }
6
+ /** The package's pure primitives: paygate payload readers, store guards and audit text. */
7
+ export interface PaymentUtils {
8
+ /**
9
+ * The API version a client was built with — read back from the client, never written as a literal,
10
+ * so a webhook endpoint always receives the payload shapes the client itself parses.
11
+ */
12
+ apiVersionOf: (stripe: Stripe) => string;
13
+ isDuplicateKey: (error: unknown) => boolean;
14
+ /** A paygate answer meaning the object does not exist (deleted, or never did). */
15
+ isMissingObject: (error: unknown) => boolean;
16
+ /** A paygate object reference, expanded or not, as its id. */
17
+ idOf: (value: string | {
18
+ id?: string;
19
+ } | null | undefined) => string | undefined;
20
+ /** Epoch seconds → `Date`. */
21
+ dateOf: (seconds: number | null | undefined) => Date | undefined;
22
+ /** Drop `null` and `undefined` properties — a stored record reads an absent field back as `null`. */
23
+ compact: <T extends object>(value: T) => T;
24
+ /** A conditional single-document `$set` — `true` when the filter matched (the guard held). */
25
+ conditionalSet: (resource: CollectionHolder, filter: Record<string, unknown>, set: Record<string, unknown>) => Promise<boolean>;
26
+ /** A conditional single-document delete — `true` when the filter matched (the guard held). */
27
+ conditionalDelete: (resource: CollectionHolder, filter: Record<string, unknown>) => Promise<boolean>;
28
+ /** An error's message for an audit record, never a stack. */
29
+ errorText: (error: unknown)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;IACpG,6DAA6D;IAC7D,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAA;CACtC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":""}
package/build/utils.d.ts CHANGED
@@ -1,14 +1,28 @@
1
- import Stripe from 'stripe';
2
- import type { PaymentService } from '@owlmeans/payment';
1
+ import type Stripe from 'stripe';
2
+ import { type PaymentService } from '@owlmeans/payment';
3
3
  import type { Context as ApiContext } from '@owlmeans/server-api';
4
- import type { CompletionObserver, FingerprintResource, GatewayService, PaygateCustomerResource, PaymentSubscriptionRecord, PaymentSubscriptionResource, StripePluginConfig } from './types.js';
4
+ import type { CompletionObserver, ConsumerConsentResource, ConsumerRightsService, EntitlementService, GatewayService, PaymentFulfillmentResource, PaymentSubscriptionResource, PurchaseResource } from './types.js';
5
+ import type { PaymentUtils } from './utils/types.js';
6
+ export declare const createPaymentUtils: () => PaymentUtils;
7
+ export declare const paymentUtils: PaymentUtils;
8
+ /** @deprecated compat:factory-refactor — use `paymentAccessOf(ctx).payment()` */
5
9
  export declare const payment: (ctx: ApiContext) => PaymentService;
10
+ /** @deprecated compat:factory-refactor — use `paymentAccessOf(ctx).gateway()` */
6
11
  export declare const gateway: (ctx: ApiContext) => GatewayService;
12
+ /** @deprecated compat:factory-refactor — use `paymentAccessOf(ctx).observer()` */
7
13
  export declare const observer: (ctx: ApiContext) => CompletionObserver;
8
- export declare const paygateCustomers: (ctx: ApiContext) => PaygateCustomerResource;
14
+ /** @deprecated compat:factory-refactor — use `paymentAccessOf(ctx).entitlements()` */
15
+ export declare const entitlements: (ctx: ApiContext) => EntitlementService;
16
+ /** @deprecated compat:factory-refactor — use `paymentAccessOf(ctx).subscriptions()` */
9
17
  export declare const subscriptions: (ctx: ApiContext) => PaymentSubscriptionResource;
10
- export declare const fingerprints: (ctx: ApiContext) => FingerprintResource;
11
- export declare const stripeConfig: (ctx: ApiContext) => Promise<StripePluginConfig>;
18
+ /** @deprecated compat:factory-refactor — use `paymentAccessOf(ctx).fulfillments()` */
19
+ export declare const fulfillments: (ctx: ApiContext) => PaymentFulfillmentResource;
20
+ /** @deprecated compat:factory-refactor — use `paymentAccessOf(ctx).purchases()` */
21
+ export declare const purchases: (ctx: ApiContext) => PurchaseResource;
22
+ /** @deprecated compat:factory-refactor — use `paymentAccessOf(ctx).consumerConsents()` */
23
+ export declare const consumerConsents: (ctx: ApiContext) => ConsumerConsentResource;
24
+ /** @deprecated compat:factory-refactor — use `paymentAccessOf(ctx).consumerRightsOf(…)` */
25
+ export declare const consumerRightsOf: (ctx: ApiContext, alias?: string) => ConsumerRightsService | null;
26
+ /** @deprecated compat:factory-refactor — use `paymentAccessOf(ctx).stripeClient()` */
12
27
  export declare const stripeClient: (ctx: ApiContext) => Promise<Stripe>;
13
- export declare const activeSubscription: (ctx: ApiContext, entityId: string, productSku: string) => Promise<PaymentSubscriptionRecord | null>;
14
28
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAG3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAKjE,OAAO,KAAK,EACV,kBAAkB,EAAE,mBAAmB,EAAE,cAAc,EAAE,uBAAuB,EAChF,yBAAyB,EAAE,2BAA2B,EAAE,kBAAkB,EAC3E,MAAM,YAAY,CAAA;AAEnB,eAAO,MAAM,OAAO,QAAS,UAAU,KAAG,cAA8D,CAAA;AACxG,eAAO,MAAM,OAAO,QAAS,UAAU,KAAG,cAA8D,CAAA;AACxG,eAAO,MAAM,QAAQ,QAAS,UAAU,KAAG,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AM,YAAY,QAAS,UAAU,KAAG,kBAAyD,CAAA;AAExG,uFAAuF;AACvF,eAAO,MAAM,aAAa,QAAS,UAAU,KAAG,2BAAmE,CAAA;AAEnH,sFAAsF;AACtF,eAAO,MAAM,YAAY,QAAS,UAAU,KAAG,0BAAiE,CAAA;AAEhH,mFAAmF;AACnF,eAAO,MAAM,SAAS,QAAS,UAAU,KAAG,gBAAoD,CAAA;AAEhG,0FAA0F;AAC1F,eAAO,MAAM,gBAAgB,QAAS,UAAU,KAAG,uBAAkE,CAAA;AAErH,2FAA2F;AAC3F,eAAO,MAAM,gBAAgB,QACtB,UAAU,UAAS,MAAM,KAC7B,qBAAqB,GAAG,IAAoD,CAAA;AAE/E,sFAAsF;AACtF,eAAO,MAAM,YAAY,QAAe,UAAU,KAAG,OAAO,CAAC,MAAM,CAA8C,CAAA"}
package/build/utils.js CHANGED
@@ -1,18 +1,57 @@
1
- import Stripe from 'stripe';
2
- import { PLUGINS } from '@owlmeans/config';
3
- import { DEFAULT_ALIAS as PAYMENT_SERVICE, SubscriptionStatus } from '@owlmeans/payment';
4
- import { GATEWAY_SERVICE, PAYMENT_OBSERVER, RES_PAYGATE_CUSTOMER, RES_PAYMENT_FINGERPRINT, RES_PAYMENT_SUBSCRIPTION, STRIPE_PLUGIN_CONFIG, } from './consts.js';
5
- export const payment = (ctx) => ctx.service(PAYMENT_SERVICE);
6
- export const gateway = (ctx) => ctx.service(GATEWAY_SERVICE);
7
- export const observer = (ctx) => ctx.service(PAYMENT_OBSERVER);
8
- export const paygateCustomers = (ctx) => ctx.resource(RES_PAYGATE_CUSTOMER);
9
- export const subscriptions = (ctx) => ctx.resource(RES_PAYMENT_SUBSCRIPTION);
10
- export const fingerprints = (ctx) => ctx.resource(RES_PAYMENT_FINGERPRINT);
11
- export const stripeConfig = async (ctx) => await ctx
12
- .getConfigResource(PLUGINS).get(STRIPE_PLUGIN_CONFIG);
13
- export const stripeClient = async (ctx) => new Stripe((await stripeConfig(ctx)).api);
14
- export const activeSubscription = async (ctx, entityId, productSku) => await subscriptions(ctx).load({
15
- entityId, productSku, kind: 'subscription',
16
- status: [SubscriptionStatus.Active, SubscriptionStatus.Trial],
17
- });
1
+ import { MONGO_DUPLICATE_KEY } from '@owlmeans/mongo-resource';
2
+ import { WebhookSetupError } from '@owlmeans/payment';
3
+ import { CONSUMER_RIGHTS_SERVICE } from './consts.js';
4
+ import { paymentAccessOf } from './access.js';
5
+ export const createPaymentUtils = () => {
6
+ const apiVersionOf = (stripe) => {
7
+ const version = stripe.getApiField?.('version');
8
+ if (typeof version !== 'string' || version === '') {
9
+ throw new WebhookSetupError('api-version');
10
+ }
11
+ return version;
12
+ };
13
+ const isDuplicateKey = (error) => error?.code === MONGO_DUPLICATE_KEY;
14
+ const isMissingObject = (error) => {
15
+ const typed = error;
16
+ return typed?.code === 'resource_missing' || typed?.raw?.code === 'resource_missing' || typed?.statusCode === 404;
17
+ };
18
+ const idOf = (value) => value == null ? undefined : typeof value === 'string' ? value : value.id;
19
+ const dateOf = (seconds) => seconds == null ? undefined : new Date(seconds * 1000);
20
+ const compact = (value) => Object.fromEntries(Object.entries(value).filter(([, entry]) => entry != null));
21
+ const conditionalSet = async (resource, filter, set) => {
22
+ const collection = resource.collection;
23
+ const result = await collection.updateOne(filter, { $set: set });
24
+ return (result.matchedCount ?? result.modifiedCount ?? 0) > 0;
25
+ };
26
+ const conditionalDelete = async (resource, filter) => {
27
+ const collection = resource.collection;
28
+ const result = await collection.deleteOne(filter);
29
+ return (result.deletedCount ?? 0) > 0;
30
+ };
31
+ const errorText = (error) => (error instanceof Error ? error.message : String(error)).slice(0, 1000);
32
+ return {
33
+ apiVersionOf, isDuplicateKey, isMissingObject, idOf, dateOf, compact, conditionalSet, conditionalDelete, errorText,
34
+ };
35
+ };
36
+ export const paymentUtils = createPaymentUtils();
37
+ /** @deprecated compat:factory-refactor — use `paymentAccessOf(ctx).payment()` */
38
+ export const payment = (ctx) => paymentAccessOf(ctx).payment();
39
+ /** @deprecated compat:factory-refactor — use `paymentAccessOf(ctx).gateway()` */
40
+ export const gateway = (ctx) => paymentAccessOf(ctx).gateway();
41
+ /** @deprecated compat:factory-refactor — use `paymentAccessOf(ctx).observer()` */
42
+ export const observer = (ctx) => paymentAccessOf(ctx).observer();
43
+ /** @deprecated compat:factory-refactor — use `paymentAccessOf(ctx).entitlements()` */
44
+ export const entitlements = (ctx) => paymentAccessOf(ctx).entitlements();
45
+ /** @deprecated compat:factory-refactor — use `paymentAccessOf(ctx).subscriptions()` */
46
+ export const subscriptions = (ctx) => paymentAccessOf(ctx).subscriptions();
47
+ /** @deprecated compat:factory-refactor — use `paymentAccessOf(ctx).fulfillments()` */
48
+ export const fulfillments = (ctx) => paymentAccessOf(ctx).fulfillments();
49
+ /** @deprecated compat:factory-refactor — use `paymentAccessOf(ctx).purchases()` */
50
+ export const purchases = (ctx) => paymentAccessOf(ctx).purchases();
51
+ /** @deprecated compat:factory-refactor — use `paymentAccessOf(ctx).consumerConsents()` */
52
+ export const consumerConsents = (ctx) => paymentAccessOf(ctx).consumerConsents();
53
+ /** @deprecated compat:factory-refactor — use `paymentAccessOf(ctx).consumerRightsOf(…)` */
54
+ export const consumerRightsOf = (ctx, alias = CONSUMER_RIGHTS_SERVICE) => paymentAccessOf(ctx).consumerRightsOf(alias);
55
+ /** @deprecated compat:factory-refactor — use `paymentAccessOf(ctx).stripeClient()` */
56
+ export const stripeClient = async (ctx) => await paymentAccessOf(ctx).stripeClient();
18
57
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAGxF,OAAO,EACL,eAAe,EAAE,gBAAgB,EAAE,oBAA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F,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAe,EAA2B,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,gBAAgB,EAAE,CAAA;AAErH,2FAA2F;AAC3F,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,GAAe,EAAE,KAAK,GAAW,uBAAuB,EAC1B,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;AAE/E,sFAAsF;AACtF,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,GAAe,EAAmB,EAAE,CAAC,MAAM,eAAe,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owlmeans/server-payment",
3
- "version": "0.1.18-rc.8",
3
+ "version": "0.1.18",
4
4
  "license": "MIT",
5
5
  "description": "Protocol-bound payment resources, entitlement gates, and Stripe checkout for OwlMeans servers.",
6
6
  "type": "module",
@@ -26,25 +26,30 @@
26
26
  "ajv": "*"
27
27
  },
28
28
  "dependencies": {
29
- "@owlmeans/auth": "^0.1.18-rc.20",
30
- "@owlmeans/config": "^0.1.18-rc.23",
31
- "@owlmeans/context": "^0.1.18-rc.19",
32
- "@owlmeans/entrypoint": "^0.1.18-rc.22",
33
- "@owlmeans/mongo-resource": "^0.1.18-rc.23",
34
- "@owlmeans/payment": "^0.1.18-rc.24",
35
- "@owlmeans/resource": "^0.1.18-rc.20",
36
- "@owlmeans/route": "^0.1.18-rc.20",
37
- "@owlmeans/server-api": "^0.1.18-rc.28",
38
- "@owlmeans/server-app": "^0.1.18-rc.30",
39
- "@owlmeans/server-context": "^0.1.18-rc.23",
40
- "@owlmeans/server-entrypoint": "^0.1.18-rc.22",
29
+ "@owlmeans/auth": "^0.1.18",
30
+ "@owlmeans/config": "^0.1.18",
31
+ "@owlmeans/context": "^0.1.18",
32
+ "@owlmeans/entrypoint": "^0.1.18",
33
+ "@owlmeans/iam": "^0.1.18",
34
+ "@owlmeans/mailer": "^0.1.18",
35
+ "@owlmeans/mongo-resource": "^0.1.18",
36
+ "@owlmeans/payment": "^0.1.18",
37
+ "@owlmeans/resource": "^0.1.18",
38
+ "@owlmeans/log": "^0.1.18",
39
+ "@owlmeans/route": "^0.1.18",
40
+ "@owlmeans/server-api": "^0.1.18",
41
+ "@owlmeans/server-app": "^0.1.18",
42
+ "@owlmeans/server-context": "^0.1.18",
43
+ "@owlmeans/server-entrypoint": "^0.1.18",
41
44
  "async-mutex": "^0.5.0",
42
- "stripe": "^17.7.0"
45
+ "stripe": "^23.0.0"
43
46
  },
44
47
  "devDependencies": {
45
- "@owlmeans/dep-config": "workspace:*",
46
- "@types/bun": "^1.4.0",
47
- "@types/node": "^26.1.0",
48
+ "@owlmeans/dep-config": "^0.1.18",
49
+ "@owlmeans/mongo": "^0.1.18",
50
+ "@owlmeans/test-integration": "^0.1.18",
51
+ "@types/bun": "^1.4.2",
52
+ "@types/node": "^26.6.4",
48
53
  "nodemon": "^3.1.14",
49
54
  "typescript": "^7.0.2"
50
55
  },
@@ -0,0 +1,52 @@
1
+ import type Stripe from 'stripe'
2
+ import type { PaymentService } from '@owlmeans/payment'
3
+ import type {
4
+ BillingProfileResource, CompletionObserver, ConsumerConsentResource, ConsumerDeclarationResource,
5
+ ConsumerEventResource, ConsumerMailPluginConfig, ConsumerRightsService, EntitlementService, FingerprintResource,
6
+ GatewayService, PaygateCustomerResource, PaymentFulfillmentResource, PaymentSubscriptionRecord,
7
+ PaymentSubscriptionResource, PaymentUsageCounterResource, PaymentUsageResource, PaymentWebhookResource,
8
+ PortalBrandingConfig, PurchaseResource, StripePluginConfig, StripePricingPluginConfig,
9
+ } from '../types.js'
10
+
11
+ /** What one context holds for payments: its services, its resources, its plugin configs and its Stripe client. */
12
+ export interface PaymentAccess {
13
+ payment: () => PaymentService
14
+ gateway: () => GatewayService
15
+ /** The gateway, or `null` in a context that registered none. */
16
+ gatewayOf: () => GatewayService | null
17
+ observer: () => CompletionObserver
18
+ entitlements: () => EntitlementService
19
+ paygateCustomers: () => PaygateCustomerResource
20
+ subscriptions: () => PaymentSubscriptionResource
21
+ fulfillments: () => PaymentFulfillmentResource
22
+ paymentWebhooks: () => PaymentWebhookResource
23
+ usageEvents: () => PaymentUsageResource
24
+ usageCounters: () => PaymentUsageCounterResource
25
+ fingerprints: () => FingerprintResource
26
+ billingProfiles: () => BillingProfileResource
27
+ purchases: () => PurchaseResource
28
+ consumerConsents: () => ConsumerConsentResource
29
+ consumerDeclarations: () => ConsumerDeclarationResource
30
+ consumerEvents: () => ConsumerEventResource
31
+ /** The consumer-rights service. @throws when it is not registered */
32
+ consumerRights: (alias?: string) => ConsumerRightsService
33
+ /** The consumer-rights service, or `null` in a process that registered none. */
34
+ consumerRightsOf: (alias?: string) => ConsumerRightsService | null
35
+ stripeConfig: () => Promise<StripePluginConfig>
36
+ /** The portal branding declared with `portalBranding`, or `null`. */
37
+ portalBrandingConfig: () => Promise<PortalBrandingConfig | null>
38
+ /** The consumer-rights mail options declared with `declareConsumerRights`, or `null`. */
39
+ consumerMailConfig: () => Promise<ConsumerMailPluginConfig | null>
40
+ /** The Stripe-only pricing settings declared with `declarePaymentPricing`, or `null`. */
41
+ stripePricingConfig: () => Promise<StripePricingPluginConfig | null>
42
+ /**
43
+ * A Stripe client pinned to {@link STRIPE_PINNED_API_VERSION}: the API version this package's payload
44
+ * readers, the stored webhook endpoints and the test doubles are written for. The installed SDK is typed
45
+ * for a newer one, so a read of a field the newer version moved (a subscription's period, an invoice's
46
+ * subscription) is cast at the seam until the readers are migrated — the pin is what keeps the shapes
47
+ * the code parses and the shapes Stripe sends the same.
48
+ */
49
+ stripeClient: () => Promise<Stripe>
50
+ /** The entity's highest-ranked entitling subscription of one product. */
51
+ activeSubscription: (entityId: string, productSku: string) => Promise<PaymentSubscriptionRecord | null>
52
+ }
package/src/access.ts ADDED
@@ -0,0 +1,86 @@
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, type PaymentService } from '@owlmeans/payment'
5
+ import type { Context as ApiContext } from '@owlmeans/server-api'
6
+ import {
7
+ CONSUMER_RIGHTS_MAIL_PLUGIN_CONFIG, CONSUMER_RIGHTS_SERVICE, ENTITLEMENT_SERVICE, GATEWAY_SERVICE,
8
+ PAYMENT_OBSERVER, RES_BILLING_PROFILE, RES_CONSUMER_CONSENT, RES_CONSUMER_DECLARATION, RES_CONSUMER_EVENT,
9
+ RES_PAYGATE_CUSTOMER, RES_PAYMENT_FINGERPRINT, RES_PAYMENT_FULFILLMENT, RES_PAYMENT_PURCHASE,
10
+ RES_PAYMENT_SUBSCRIPTION, RES_PAYMENT_USAGE, RES_PAYMENT_USAGE_COUNTER, RES_PAYMENT_WEBHOOK,
11
+ STRIPE_PINNED_API_VERSION, STRIPE_PLUGIN_CONFIG, STRIPE_PORTAL_PLUGIN_CONFIG, STRIPE_PRICING_PLUGIN_CONFIG,
12
+ } from './consts.js'
13
+ import type {
14
+ BillingProfileResource, CompletionObserver, ConsumerConsentResource, ConsumerDeclarationResource,
15
+ ConsumerEventResource, ConsumerMailPluginConfig, ConsumerRightsService, EntitlementService, FingerprintResource,
16
+ GatewayService, PaygateCustomerResource, PaymentFulfillmentResource, PaymentSubscriptionRecord,
17
+ PaymentSubscriptionResource, PaymentUsageCounterResource, PaymentUsageResource, PaymentWebhookResource,
18
+ PortalBrandingConfig, PurchaseResource, StripePluginConfig, StripePricingPluginConfig,
19
+ } from './types.js'
20
+ import type { PluginReader } from './types.local.js'
21
+ import type { PaymentAccess } from './access/types.js'
22
+
23
+ export const makePaymentAccess = (ctx: ApiContext): PaymentAccess => {
24
+ const hasService = (alias: string): boolean =>
25
+ (ctx as unknown as { hasService?: (alias: string) => boolean }).hasService?.(alias) === true
26
+ const plugins = () => (ctx as never as PluginReader).getConfigResource(PLUGINS)
27
+
28
+ const payment = (): PaymentService => ctx.service<PaymentService>(PAYMENT_SERVICE)
29
+ const gateway = (): GatewayService => ctx.service<GatewayService>(GATEWAY_SERVICE)
30
+ const gatewayOf = (): GatewayService | null => hasService(GATEWAY_SERVICE) ? gateway() : null
31
+ const observer = (): CompletionObserver => ctx.service<CompletionObserver>(PAYMENT_OBSERVER)
32
+ const entitlements = (): EntitlementService => ctx.service<EntitlementService>(ENTITLEMENT_SERVICE)
33
+
34
+ const paygateCustomers = (): PaygateCustomerResource => ctx.resource<PaygateCustomerResource>(RES_PAYGATE_CUSTOMER)
35
+ const subscriptions = (): PaymentSubscriptionResource =>
36
+ ctx.resource<PaymentSubscriptionResource>(RES_PAYMENT_SUBSCRIPTION)
37
+ const fulfillments = (): PaymentFulfillmentResource => ctx.resource<PaymentFulfillmentResource>(RES_PAYMENT_FULFILLMENT)
38
+ const paymentWebhooks = (): PaymentWebhookResource => ctx.resource<PaymentWebhookResource>(RES_PAYMENT_WEBHOOK)
39
+ const usageEvents = (): PaymentUsageResource => ctx.resource<PaymentUsageResource>(RES_PAYMENT_USAGE)
40
+ const usageCounters = (): PaymentUsageCounterResource =>
41
+ ctx.resource<PaymentUsageCounterResource>(RES_PAYMENT_USAGE_COUNTER)
42
+ const fingerprints = (): FingerprintResource => ctx.resource<FingerprintResource>(RES_PAYMENT_FINGERPRINT)
43
+ const billingProfiles = (): BillingProfileResource => ctx.resource<BillingProfileResource>(RES_BILLING_PROFILE)
44
+ const purchases = (): PurchaseResource => ctx.resource<PurchaseResource>(RES_PAYMENT_PURCHASE)
45
+ const consumerConsents = (): ConsumerConsentResource => ctx.resource<ConsumerConsentResource>(RES_CONSUMER_CONSENT)
46
+ const consumerDeclarations = (): ConsumerDeclarationResource =>
47
+ ctx.resource<ConsumerDeclarationResource>(RES_CONSUMER_DECLARATION)
48
+ const consumerEvents = (): ConsumerEventResource => ctx.resource<ConsumerEventResource>(RES_CONSUMER_EVENT)
49
+
50
+ const consumerRights = (alias: string = CONSUMER_RIGHTS_SERVICE): ConsumerRightsService =>
51
+ ctx.service<ConsumerRightsService>(alias)
52
+
53
+ const consumerRightsOf = (alias: string = CONSUMER_RIGHTS_SERVICE): ConsumerRightsService | null =>
54
+ hasService(alias) ? ctx.service<ConsumerRightsService>(alias) : null
55
+
56
+ const stripeConfig = async (): Promise<StripePluginConfig> =>
57
+ await plugins().get(STRIPE_PLUGIN_CONFIG) as StripePluginConfig
58
+
59
+ const portalBrandingConfig = async (): Promise<PortalBrandingConfig | null> =>
60
+ await plugins().load(STRIPE_PORTAL_PLUGIN_CONFIG) as PortalBrandingConfig | null
61
+
62
+ const consumerMailConfig = async (): Promise<ConsumerMailPluginConfig | null> =>
63
+ await plugins().load(CONSUMER_RIGHTS_MAIL_PLUGIN_CONFIG) as ConsumerMailPluginConfig | null
64
+
65
+ const stripePricingConfig = async (): Promise<StripePricingPluginConfig | null> =>
66
+ await plugins().load(STRIPE_PRICING_PLUGIN_CONFIG) as StripePricingPluginConfig | null
67
+
68
+ const stripeClient = async (): Promise<Stripe> =>
69
+ new Stripe((await stripeConfig()).api, { apiVersion: STRIPE_PINNED_API_VERSION as never })
70
+
71
+ const activeSubscription = async (
72
+ entityId: string, productSku: string,
73
+ ): Promise<PaymentSubscriptionRecord | null> => await subscriptions().load({
74
+ entityId, productSku, status: [...ENTITLING_STATUSES],
75
+ }, { sort: [{ field: 'rank', order: 'desc' }, { field: 'createdAt', order: 'desc' }] })
76
+
77
+ return {
78
+ payment, gateway, gatewayOf, observer, entitlements, paygateCustomers, subscriptions, fulfillments,
79
+ paymentWebhooks, usageEvents, usageCounters, fingerprints, billingProfiles, purchases, consumerConsents,
80
+ consumerDeclarations, consumerEvents, consumerRights, consumerRightsOf, stripeConfig, portalBrandingConfig,
81
+ consumerMailConfig, stripePricingConfig, stripeClient, activeSubscription,
82
+ }
83
+ }
84
+
85
+ /** The payment access of a context — one per context. */
86
+ export const paymentAccessOf = memoHelper.oncePer(makePaymentAccess)
@@ -1,2 +1,3 @@
1
1
  export * from './webhook.js'
2
2
  export * from './resync.js'
3
+ export * from './resync-subscriptions.js'
@@ -0,0 +1,10 @@
1
+ import { handlers } from '@owlmeans/server-api'
2
+ import type { Context } from '../types.js'
3
+ import { paymentAccessOf } from '../access.js'
4
+ import { paymentGate } from '../protocol.js'
5
+
6
+ const bind = handlers<Context>()
7
+
8
+ /** Re-read every live paygate subscription — the manually or periodically triggered repair. */
9
+ export const resyncSubscriptions = bind.request(paymentGate.resyncSubscriptions, async (_request, context) =>
10
+ await paymentAccessOf(context).gateway().resyncAll(context))
@@ -1,13 +1,22 @@
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'
5
3
  import type { Context } from '../types.js'
4
+ import { paymentAccessOf } from '../access.js'
5
+ import { paymentGate } from '../protocol.js'
6
+ import { stripeBootstrapOf } from '../bootstrap.js'
6
7
 
7
8
  const bind = handlers<Context>()
8
9
 
10
+ /**
11
+ * Forget every sync fingerprint and bring Stripe back to the declared catalogue, portal and webhook —
12
+ * in any managed process, `bootstrap: false` included: the webhook URL and the rows follow the
13
+ * gateway's `webhookService` and `owner`, so every process of the owner converges on one state.
14
+ */
9
15
  export const resync = bind.request(paymentGate.resync, async (_request, context) => {
10
- await fingerprints(context).clear()
11
- await initialize(context)
16
+ const paymentAccess = paymentAccessOf(context)
17
+ const service = paymentAccess.gateway()
18
+ if (!service.managed) throw new PaygateError('unmanaged')
19
+ await paymentAccess.fingerprints().clear()
20
+ await stripeBootstrapOf(context).bootstrapStripe(await service.stripe(context), { force: true })
12
21
  return { ok: true }
13
22
  })
@@ -1,12 +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'
5
4
  import type { Context } from '../types.js'
5
+ import { paymentAccessOf } from '../access.js'
6
+ import { paymentGate } from '../protocol.js'
7
+ import { webhookOf } from '../plugins/webhook-manager.js'
6
8
 
7
9
  const bind = handlers<Context>()
8
10
 
11
+ /** A Stripe delivery — only a managed gateway receives one; its secret is the `owner`'s stored one. */
9
12
  export const webhook = bind.params(paymentGate.webhook, async ({ paygate }, context, request) => {
10
13
  if (paygate !== STRIPE_PAYGATE_ALIAS) throw new UnknownPaygate(paygate)
11
- await stripePlugin.handleWebhook(request, context)
14
+ const service = paymentAccessOf(context).gateway()
15
+ if (!service.managed) throw new PaygateError('unmanaged')
16
+ await webhookOf(context).handleStripeWebhook(await service.stripe(context), request)
12
17
  })
@@ -0,0 +1,16 @@
1
+ import type Stripe from 'stripe'
2
+ import type { StripeBootstrapOptions } from '../types.js'
3
+
4
+ /** What brings Stripe to a deployment's declaration. */
5
+ export interface StripeBootstrapHelper {
6
+ /**
7
+ * Bring Stripe to what this deployment declares, each step on its own so one failing does not block
8
+ * the others: products and prices, the customer-portal configuration, the webhook endpoint.
9
+ *
10
+ * The webhook URL and the owner key come from the context's gateway (`webhookService`, `owner`), so
11
+ * every process of one deployment — the one bootstrapping at boot, a `resync`, an application's
12
+ * forced maintenance run — computes the same URL and rows; each step is fingerprinted, so running it
13
+ * from any of them is idempotent.
14
+ */
15
+ bootstrapStripe: (stripe: Stripe, opts?: StripeBootstrapOptions) => Promise<void>
16
+ }
@@ -0,0 +1,31 @@
1
+ import type Stripe from 'stripe'
2
+ import type { Context as ApiContext } from '@owlmeans/server-api'
3
+ import { memoHelper } from '@owlmeans/context'
4
+ import type { StripeBootstrapOptions } from './types.js'
5
+ import { log } from './log.js'
6
+ import type { StripeBootstrapHelper } from './bootstrap/types.js'
7
+ import { productSyncOf } from './sync.js'
8
+ import { portalOf } from './plugins/portal.js'
9
+ import { webhookOf } from './plugins/webhook-manager.js'
10
+
11
+ export const makeStripeBootstrapHelper = (ctx: ApiContext): StripeBootstrapHelper => {
12
+ const bootstrapStripe = async (stripe: Stripe, opts: StripeBootstrapOptions = {}): Promise<void> => {
13
+ const steps: Array<[string, () => Promise<unknown>]> = [
14
+ ['products', async () => await productSyncOf(ctx).syncStripeProducts(stripe)],
15
+ ['portal', async () => await portalOf(ctx).ensurePortalConfiguration(stripe, opts)],
16
+ ['webhook', async () => await webhookOf(ctx).ensureWebhookEndpoint(stripe, opts)],
17
+ ]
18
+ for (const [name, step] of steps) {
19
+ try {
20
+ await step()
21
+ } catch (error) {
22
+ log.error('Stripe bootstrap step failed', { step: name, error })
23
+ }
24
+ }
25
+ }
26
+
27
+ return { bootstrapStripe }
28
+ }
29
+
30
+ /** The Stripe bootstrap of a context — one per context. */
31
+ export const stripeBootstrapOf = memoHelper.oncePer(makeStripeBootstrapHelper)
@@ -0,0 +1,32 @@
1
+ import type { PermissionSet } from '@owlmeans/auth'
2
+ import type { EffectivePlan, PaymentPlan, PaymentProduct } from '../types.js'
3
+
4
+ /** The catalogue a context declares, and the plan each entity holds in it. */
5
+ export interface CatalogueHelper {
6
+ /** A plan by sku, or `null` when the catalogue no longer declares it. */
7
+ findPlan: (planSku: string) => Promise<PaymentPlan | null>
8
+ /** A product by sku, or `null`. */
9
+ findProduct: (productSku: string) => Promise<PaymentProduct | null>
10
+ /** Every plan of every declared product. */
11
+ catalogPlans: () => Promise<PaymentPlan[]>
12
+ /** The declared free plan an entity falls back to: the lowest rank, then the sku. */
13
+ freePlanOf: () => Promise<PaymentPlan | null>
14
+ /**
15
+ * The plan an entity holds: its highest-ranked subscription in an entitling status (the catalogue
16
+ * rank, the stored one for a plan the catalogue no longer declares; the newest first on a tie),
17
+ * else the declared free plan. The plan answered carries the winning row's `overrides`
18
+ * (`overriddenPlan`), so every reader — ceilings, the view, the gates — sees one answer.
19
+ *
20
+ * @throws PlanRequired when there is neither.
21
+ */
22
+ resolveEffectivePlan: (entityId: string, at?: Date) => Promise<EffectivePlan>
23
+ /**
24
+ * The capability sets an entity's effective plan grants now — sets behind a lapsed promo left out.
25
+ * Empty when the plan is not of one of `productSkus`.
26
+ */
27
+ entitlementsOf: (entityId: string, productSkus?: string[]) => Promise<PermissionSet[]>
28
+ /** Every product sold through Stripe with the plans it sells there. */
29
+ stripePlansOf: () => Promise<Array<{ product: PaymentProduct, plans: PaymentPlan[] }>>
30
+ /** The plan an amount/quantity checkout of a consumable product sells: the named one, else the first. */
31
+ consumablePlanOf: (productSku: string, planSku?: string) => Promise<{ product: PaymentProduct, plan: PaymentPlan }>
32
+ }