@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
package/src/types.ts CHANGED
@@ -1,17 +1,31 @@
1
+ import type Stripe from 'stripe'
1
2
  import type { InitializedService, LazyService } from '@owlmeans/context'
2
3
  import type { ResourceRecord } from '@owlmeans/resource'
3
4
  import type { MongoResource } from '@owlmeans/mongo-resource'
4
5
  import type { PluginConfig } from '@owlmeans/config'
5
6
  import type { PermissionSet } from '@owlmeans/auth'
7
+ import type { AbstractRequest } from '@owlmeans/entrypoint'
8
+ import type { MailMessage } from '@owlmeans/mailer'
6
9
  import type { Config as ApiConfig, Context as ApiContext } from '@owlmeans/server-api'
7
10
  import type {
8
- AmountCheckoutPolicy, CheckoutPricingMode, LimitConfig, PlanDuration, Product, ProductPlan,
9
- ProductType, QuantityCheckoutPolicy, SubscriptionStatus,
11
+ AmountCheckoutPolicy, AmountNarrowing, AmountPolicyView, BillingProfileView, CancellationBody,
12
+ CancellationKind, CancellationReceipt, CancellationStatus, CheckoutPricingMode, ConsentKind, ConsumerRegion,
13
+ ConsumerRightsDeclaration, ConsumerRightsLinks, ConsumerRightsPolicy, DeclarationChannel, DeclarationKind,
14
+ EntitlementView, LimitDeclaration, LimitView, PerformanceConsentBody, PerformanceConsentResponse,
15
+ PerformanceConsentView, PlanCapability, PlanDuration, PlanPriceView, PlanWithdrawalComponent, PortalFlow,
16
+ PriceEstimate, PricingPolicy, Product, ProductPlan, ProductType, PurchaseKind, PurchaseView,
17
+ QuantityCheckoutPolicy, SubscriptionStartBody, SubscriptionStartResponse, SubscriptionStartView,
18
+ SubscriptionStatus, WithdrawalBody, WithdrawalCandidateList, WithdrawalReceipt, WithdrawalStatus,
10
19
  } from '@owlmeans/payment'
11
20
 
21
+
12
22
  export interface Config extends ApiConfig {}
13
23
  export interface Context<C extends Config = Config> extends ApiContext<C> {}
14
24
 
25
+ // ---------------------------------------------------------------------------------------------
26
+ // Catalogue
27
+ // ---------------------------------------------------------------------------------------------
28
+
15
29
  export interface PaymentProduct extends Product {
16
30
  taxCode?: string
17
31
  unitLabel?: string
@@ -25,6 +39,11 @@ export interface PaymentPlan extends ProductPlan {
25
39
  pricingMode?: CheckoutPricingMode
26
40
  amountPolicy?: AmountCheckoutPolicy
27
41
  quantityPolicy?: QuantityCheckoutPolicy
42
+ /**
43
+ * Exact prices in further currencies, major units by lowercase ISO 4217 code (`{ usd: 20 }`).
44
+ * Synced as the reusable Price's `currency_options`, never converted.
45
+ */
46
+ currencyPrices?: Record<string, number>
28
47
  }
29
48
 
30
49
  export interface PaymentProductDef {
@@ -44,14 +63,20 @@ export interface PaymentPlanDef {
44
63
  productSku: string
45
64
  sku: string
46
65
  duration: PlanDuration
66
+ /** Position among the plans of one product; a higher rank is an upgrade. Absent reads as `0`. */
67
+ rank?: number
68
+ /** Held without paying: `price: 0` and no gateway. */
69
+ free?: boolean
70
+ /** Paygates the plan is sold through. Absent: the product's gateways. A free plan has none. */
71
+ gateways?: string[]
47
72
  /** Reference unit price in major units; amount checkout uses it only for fulfillment conversion. */
48
73
  price: number
49
74
  currency?: string
50
75
  recurring?: { interval: 'month' | 'year' }
51
76
  order?: number
52
77
  title?: string
53
- capabilities?: PermissionSet[]
54
- limits?: { [key: string]: LimitConfig }
78
+ capabilities?: PlanCapability[]
79
+ limits?: { [key: string]: LimitDeclaration }
55
80
  pricingMode?: CheckoutPricingMode
56
81
  amountPolicy?: AmountCheckoutPolicy
57
82
  quantityPolicy?: QuantityCheckoutPolicy
@@ -59,9 +84,114 @@ export interface PaymentPlanDef {
59
84
  minQuantity?: number
60
85
  maxQuantity?: number
61
86
  defaultQuantity?: number
87
+ /**
88
+ * Exact prices in further currencies, major units by ISO 4217 code (`{ usd: 20 }`): a recurring
89
+ * or quantity plan's synced Price carries each as a `currency_options` entry at exactly this
90
+ * amount, while its default currency (the settlement currency) is converted as before.
91
+ */
92
+ currencyPrices?: Record<string, number>
93
+ /**
94
+ * The separately priced parts of a subscription for a withdrawal (CJEU C-641/19): their
95
+ * `shareMinor` sum to `round(price × 100)`. Absent: the whole price is one `time` component.
96
+ */
97
+ withdrawal?: { components: PlanWithdrawalComponent[] }
98
+ }
99
+
100
+ /** File paths (or values) of the Stripe secrets. The webhook secret is an optional override. */
101
+ export interface StripeSecretsDef { api: string; webhook?: string }
102
+ export interface StripePluginConfig extends PluginConfig { api: string; webhook?: string }
103
+
104
+ /** Stripe-only pricing settings — never a browser-visible field (see `PricingPolicy` for those). */
105
+ export interface StripePricingDef {
106
+ /** Overrides `STRIPE_FX_QUOTES_API_VERSION`, when Stripe moves or renames the preview. */
107
+ fxApiVersion?: string
108
+ /**
109
+ * Stripe settlement currency used when a catalogue price is declared in another currency.
110
+ * Recurring prices are converted during product sync; amount checkout is converted per session.
111
+ */
112
+ settlementCurrency?: string
113
+ /** Explicit Stripe payment methods for subscription Checkout; absent keeps Stripe's dynamic selection. */
114
+ subscriptionPaymentMethodTypes?: string[]
115
+ /** Payment methods for a specific subscription charge currency; overrides the default list. */
116
+ subscriptionPaymentMethodTypesByCurrency?: Record<string, string[]>
117
+ /**
118
+ * Let a matching `unspecified` price take the declared `tax.behavior` even when the Stripe
119
+ * account's own tax-settings default resolves to the opposite one — which changes what an
120
+ * existing subscriber is charged at their next renewal. Absent/`false`: such a price is left
121
+ * `unspecified` and a `log.error` explains why.
122
+ */
123
+ migrateUnspecifiedPrices?: boolean
124
+ /**
125
+ * The Stripe customer's e-mail is the application's: every checkout must pass
126
+ * `CreateLinkParams.email` (else `PaygateError('customer-email')`), which is written to the
127
+ * customer before the session — Checkout shows a customer's valid e-mail read-only, so no other
128
+ * address can be typed — and the portal configuration never offers to edit it.
129
+ */
130
+ lockCustomerEmail?: boolean
131
+ /**
132
+ * The billing country a checkout knows — the locked profile's, else `CreateLinkParams.country` —
133
+ * is pinned on the Stripe customer (replacing a saved address of another country before any lock)
134
+ * and Checkout never collects another (`customer_update.address: 'never'`, collection `'auto'`):
135
+ * tax is calculated on it whatever the card form's "Country or region" says, the first completed
136
+ * purchase locks it, and the portal never offers to edit the address. Where Stripe Tax needs more
137
+ * than a country (US: a postal code; CA, IN: a postal code or province) and the customer carries
138
+ * none, Checkout still collects the address — Stripe refuses a session otherwise.
139
+ */
140
+ lockCustomerCountry?: boolean
141
+ }
142
+ export interface StripePricingPluginConfig extends PluginConfig, StripePricingDef {}
143
+
144
+ /** `declarePaymentPricing`'s argument: the browser-safe `PricingPolicy` plus Stripe-only settings. */
145
+ export interface PricingDef extends PricingPolicy {
146
+ stripe?: StripePricingDef
147
+ }
148
+
149
+ /**
150
+ * The business the consumer contracts with — backend only, never advertised. `name` is what the
151
+ * express statements say (`{{trader}}` in a consent or start request); the mails' identity line,
152
+ * the withdrawal information and the model form ("To: …") say `legalName`, `address` and `email`.
153
+ */
154
+ // A type alias, not an interface: it is stored inside a plugin config record, whose values must be
155
+ // index-signature compatible.
156
+ // Kept as a type: it is stored in config values that need an implicit index signature.
157
+ export type TraderDef = {
158
+ name: string
159
+ legalName: string
160
+ /** Postal address; without it (or `email`) the mails render without it and the boot warns. */
161
+ address?: string
162
+ email?: string
163
+ website?: string
164
+ }
165
+
166
+ /** The consumer-rights mail options — backend only, never advertised. */
167
+ export interface ConsumerMailDef {
168
+ /** The mailer service alias. Default `MAILER_SERVICE`. */
169
+ alias?: string
170
+ from?: string
171
+ replyTo?: string
172
+ /** Evidence archive addresses: each receives its own copy of every consumer-rights mail. */
173
+ bcc?: string[]
174
+ }
175
+ export interface ConsumerMailPluginConfig extends PluginConfig, ConsumerMailDef {
176
+ trader?: TraderDef
177
+ }
178
+
179
+ /** `declareConsumerRights`'s argument: the advertised policy plus the backend-only trader and mail options. */
180
+ export interface ConsumerRightsDef extends ConsumerRightsDeclaration { trader?: TraderDef, mail?: ConsumerMailDef }
181
+
182
+ /** What the managed customer portal configuration shows. */
183
+ export interface PortalBrandingDef {
184
+ headline?: string
185
+ privacyPolicyUrl?: string
186
+ termsOfServiceUrl?: string
187
+ /** Where the portal's "return" link leads when a session names none. Absolute URL. */
188
+ returnUrl: string
62
189
  }
190
+ export interface PortalBrandingConfig extends PluginConfig, PortalBrandingDef {}
63
191
 
64
- export interface StripePluginConfig extends PluginConfig { api: string; webhook: string }
192
+ // ---------------------------------------------------------------------------------------------
193
+ // Gateway
194
+ // ---------------------------------------------------------------------------------------------
65
195
 
66
196
  export interface CreateLinkParams {
67
197
  productSku: string
@@ -71,21 +201,235 @@ export interface CreateLinkParams {
71
201
  service: string
72
202
  planSku?: string
73
203
  amountMinor?: number
204
+ /** Stripe Checkout and future paid-invoice language. Caller supplies a Stripe-supported locale. */
205
+ locale?: string
206
+ /**
207
+ * Trusted application copy shown beside the Checkout confirmation button — never caller-provided
208
+ * text. A function receives the charge currency and the price the session charges.
209
+ */
210
+ submitText?: string | ((context: CheckoutTextContext) => string)
74
211
  successUrl?: string
75
212
  cancelUrl?: string
213
+ /** The billing country the buyer declared (ISO 3166-1 alpha-2). A locked profile overrides it. */
214
+ country?: string
215
+ /** The subscription start request recorded right before a subscription checkout. */
216
+ startRequestId?: string
217
+ /** The language the buyer is shown legal copy in; default: the billing country's. */
218
+ consumerLanguage?: string
219
+ /** The request's geolocated country (`cf-ipcountry`) — second location evidence, stored at lock. */
220
+ ipCountry?: string
221
+ /**
222
+ * The buyer's e-mail as the application verified it (the signed-in person's account). Read only
223
+ * under `stripe.lockCustomerEmail`, where it is required and pinned on the Stripe customer.
224
+ */
225
+ email?: string
76
226
  }
77
227
 
78
- export interface PaymentPlugin {
79
- createLink: (ctx: ApiContext, params: CreateLinkParams) => Promise<string>
80
- handleWebhook: (request: unknown, ctx: ApiContext) => Promise<void>
81
- initialize?: (ctx: ApiContext) => Promise<void>
82
- manageSubscription: (ctx: ApiContext, entityId: string, returnUrl: string) => Promise<string>
228
+ /** What a submit-text function is told about the session it labels. */
229
+ export interface CheckoutTextContext {
230
+ language: string
231
+ /** The charge currency, lowercase. */
232
+ currency: string
233
+ /** A subscription's unit price in the charge currency; an amount checkout's pre-tax charge. */
234
+ unitAmountMinor?: number
235
+ interval?: 'month' | 'year'
236
+ region: ConsumerRegion | null
237
+ country?: string
238
+ }
239
+
240
+ // ---------------------------------------------------------------------------------------------
241
+ // Checkout plugins
242
+ // ---------------------------------------------------------------------------------------------
243
+
244
+ /** What a plugin narrows: one entity's amount checkout of one plan, at one instant. */
245
+ export interface CheckoutNarrowInput {
246
+ entityId: string
247
+ productSku: string
248
+ planSku?: string
249
+ /** The plan's own amount policy — the same for everyone. */
250
+ base: AmountCheckoutPolicy
251
+ at: Date
252
+ }
253
+
254
+ /** A checkout about to be created — what `admit` may veto. */
255
+ export interface CheckoutAttempt {
256
+ entityId: string
257
+ productSku: string
258
+ planSku?: string
259
+ mode: 'amount' | 'quantity' | 'subscription'
260
+ /** Amount mode: the net value bought, in the amount policy's currency. */
261
+ amountMinor?: number
262
+ /** The amount policy's currency (amount mode), else the charge currency. */
263
+ amountCurrency?: string
264
+ /** Amount mode: the pre-tax charge in `currency`. */
265
+ chargeMinor?: number
266
+ currency: string
267
+ /** The session lifetime the gateway will set; absent: Stripe's default (24 h). */
268
+ sessionTtlSeconds?: number
269
+ expiresAt?: Date
270
+ at: Date
271
+ }
272
+
273
+ /** A plugin's admission: an optional reservation it binds to the session in `created`. */
274
+ export interface CheckoutAdmission {
275
+ reservationId?: string
83
276
  }
277
+
278
+ /** The session a checkout became. */
279
+ export interface CheckoutCreated extends CheckoutAttempt {
280
+ sessionId: string
281
+ url: string
282
+ /** What this plugin's own `admit` answered. */
283
+ reservationId?: string
284
+ }
285
+
286
+ export type CheckoutOutcome = 'paid' | 'expired' | 'failed'
287
+
288
+ /**
289
+ * How a checkout ended: `paid` (completed and paid), `expired`, or `failed` — an asynchronous
290
+ * payment failure, or a session that never became usable (a later plugin vetoed, Stripe refused,
291
+ * a `created` threw; then `sessionId` may be absent and `reservationId` names the hold to release).
292
+ */
293
+ export interface CheckoutSettled {
294
+ entityId: string
295
+ productSku?: string
296
+ planSku?: string
297
+ sessionId?: string
298
+ reservationId?: string
299
+ outcome: CheckoutOutcome
300
+ amountMinor?: number
301
+ at: Date
302
+ }
303
+
304
+ /**
305
+ * A seam around amount and subscription checkout, registered with
306
+ * `paymentAccessOf(ctx).gateway().use(plugin)` (a plugin with an `alias` registered twice replaces
307
+ * the first). Errors from `narrow` and `admit` propagate — a plugin fails closed; `settled` errors
308
+ * are logged, since holds carry their own TTL.
309
+ */
310
+ export interface CheckoutPlugin {
311
+ alias?: string
312
+ /** Lower what this entity may buy now; `null` for no opinion. */
313
+ narrow?: (ctx: ApiContext, input: CheckoutNarrowInput) => Promise<AmountNarrowing | null>
314
+ /** Veto (throw, e.g. `CheckoutLimitExceeded`) or hold a reservation for the session. */
315
+ admit?: (ctx: ApiContext, attempt: CheckoutAttempt) => Promise<CheckoutAdmission | void>
316
+ /** The session exists — bind the reservation. A throw expires the session and rethrows. */
317
+ created?: (ctx: ApiContext, created: CheckoutCreated) => Promise<void>
318
+ /** From the webhook (paid, expired, failed) or from a checkout that never became usable. */
319
+ settled?: (ctx: ApiContext, settled: CheckoutSettled) => Promise<void>
320
+ /** The longest a session may stay open; the gateway uses the smallest, clamped to 30 min–24 h. */
321
+ sessionTtlSeconds?: number
322
+ }
323
+
324
+ export interface PortalLinkOptions {
325
+ flow: PortalFlow
326
+ /** The target plan of `PortalFlow.Change`. */
327
+ planSku?: string
328
+ returnUrl: string
329
+ }
330
+
331
+ export interface PriceEstimateParams {
332
+ productSku: string
333
+ /** Stable database key resolved by the application before this in-process call. */
334
+ entityId: string
335
+ /** Absent: the product's own reference plan (an amount-priced consumable). */
336
+ planSku?: string
337
+ /** ISO 3166-1 alpha-2. Absent: taken from the entity's paygate customer address. */
338
+ country?: string
339
+ }
340
+
341
+ export interface GrantInternalPlanOptions {
342
+ /** Required to grant a plan that is not `free`. */
343
+ force?: boolean
344
+ /** When the grant stops entitling. Absent: never. */
345
+ periodEnd?: Date
346
+ }
347
+
348
+ export interface SubscriptionRef {
349
+ entityId?: string
350
+ /** The paygate subscription id (`sub_…`). */
351
+ subscriptionId?: string
352
+ }
353
+
84
354
  export interface GatewayService extends InitializedService {
85
- createLink: PaymentPlugin['createLink']
86
- manageSubscription: PaymentPlugin['manageSubscription']
355
+ /** `false` when registered with `manage: false`: every Stripe-calling method throws. */
356
+ managed: boolean
357
+ /** Whether the boot-time `bootstrapStripe` runs: the `bootstrap` option, else `managed`. */
358
+ bootstrap: boolean
359
+ /** The alias whose host and base form the webhook URL: the `webhookService` option, else `cfg.service`. */
360
+ readonly webhookService: string
361
+ /** The key of this deployment's Stripe rows: the `owner` option, else `cfg.service`. */
362
+ readonly owner: string
363
+ /** The Stripe client every paygate call of this gateway uses: the `stripe` option, else the configured secret. */
364
+ stripe: StripeFactory
365
+ createLink: (ctx: ApiContext, params: CreateLinkParams) => Promise<string>
366
+ portalLink: (ctx: ApiContext, entityId: string, opts: PortalLinkOptions) => Promise<string>
367
+ /** @throws PaygateError('unmanaged') when `managed` is `false`. */
368
+ estimatePrice: (ctx: ApiContext, params: PriceEstimateParams) => Promise<PriceEstimate>
369
+ grantInternalPlan: (
370
+ ctx: ApiContext, entityId: string, planSku: string, opts?: GrantInternalPlanOptions,
371
+ ) => Promise<PaymentSubscriptionRecord>
372
+ /** @returns how many subscription rows changed */
373
+ resyncSubscription: (ctx: ApiContext, ref: SubscriptionRef) => Promise<number>
374
+ resyncAll: (ctx: ApiContext) => Promise<{ scanned: number; updated: number }>
375
+ /** Register a checkout plugin; one with an `alias` already registered replaces it. */
376
+ use: (plugin: CheckoutPlugin) => void
377
+ /** The registered checkout plugins, in registration order. */
378
+ checkoutPlugins: () => readonly CheckoutPlugin[]
379
+ /**
380
+ * The entity's amount policy of an amount plan as narrowed NOW — the very computation
381
+ * `createLink` enforces. Mongo and plugins only; works unmanaged.
382
+ */
383
+ amountPolicy: (ctx: ApiContext, entityId: string, productSku: string, planSku?: string) => Promise<AmountPolicyView>
384
+ /** The synced prices of a product's plans, per currency — stored rows, no Stripe call. */
385
+ planPrices: (ctx: ApiContext, productSku: string) => Promise<PlanPriceView[]>
87
386
  }
88
- export interface PaymentResourceOptions { dbAlias?: string; serviceAlias?: string }
387
+
388
+ export interface PaymentGatewayOptions {
389
+ dbAlias?: string
390
+ serviceAlias?: string
391
+ /**
392
+ * `false` for a process that must read entitlements but never talk to Stripe: no Stripe
393
+ * bootstrap at init, and `createLink` / `portalLink` / `resync*` / the webhook route throw
394
+ * `PaygateError('unmanaged')`.
395
+ */
396
+ manage?: boolean
397
+ /**
398
+ * Whether this process brings Stripe to the declared state at boot (`bootstrapStripe`: products,
399
+ * portal configuration, webhook endpoint). Default: `manage`. A managed process with `false`
400
+ * still serves checkout, the portal, estimates and the resyncs, and still runs a FORCED
401
+ * bootstrap (`resync`, an application's `stripeBootstrapOf(ctx).bootstrapStripe(stripe, { force: true })`).
402
+ * `true` on an unmanaged gateway is refused at construction.
403
+ */
404
+ bootstrap?: boolean
405
+ /**
406
+ * The alias (in `cfg.services`) whose host and base form the webhook URL (`webhookUrlOf`) — also
407
+ * the portal configuration's deployment key. Default: `cfg.service`. Name the process that
408
+ * RECEIVES the webhook, in every process of the deployment, so every bootstrap computes one URL.
409
+ * A managed, bootstrapping gateway refuses to initialize when the alias is not declared.
410
+ */
411
+ webhookService?: string
412
+ /**
413
+ * The key this deployment's Stripe rows are stored under: the `payment-webhook` rows' `service`,
414
+ * the signing-secret lookup, the endpoint's `owlmeans:<owner>` description and `service`
415
+ * metadata, the `portal:<owner>` fingerprint and the portal configuration's `service` metadata.
416
+ * Default: `cfg.service`. Give every process sharing the database the same value, so they read
417
+ * and replace one another's rows.
418
+ */
419
+ owner?: string
420
+ /** The Stripe client for this gateway's paygate calls. Default: the configured secret (`stripeClient`). */
421
+ stripe?: StripeFactory
422
+ }
423
+
424
+ /** A Stripe client for one context — the default reads the configured secret. */
425
+ export interface StripeFactory { (ctx: ApiContext): Promise<Stripe> }
426
+
427
+ /** @deprecated use `PaymentGatewayOptions` */
428
+ export type PaymentResourceOptions = PaymentGatewayOptions
429
+
430
+ // ---------------------------------------------------------------------------------------------
431
+ // Observer
432
+ // ---------------------------------------------------------------------------------------------
89
433
 
90
434
  interface TopUpBase {
91
435
  entityId: string
@@ -93,6 +437,7 @@ interface TopUpBase {
93
437
  planSku?: string
94
438
  service: string
95
439
  paygate: string
440
+ /** The checkout session id — the consumer's idempotency key (`payment:<externalId>`). */
96
441
  externalId: string
97
442
  }
98
443
  export interface QuantityTopUpCompletion extends TopUpBase {
@@ -101,57 +446,1045 @@ export interface QuantityTopUpCompletion extends TopUpBase {
101
446
  }
102
447
  export interface AmountTopUpCompletion extends TopUpBase {
103
448
  mode: 'amount'
449
+ /** Net value in the amount policy's catalogue currency. */
104
450
  amountMinor: number
451
+ /** Grossed-up value in the amount policy's catalogue currency, before settlement conversion. */
452
+ sourceChargeAmountMinor: number
453
+ /** The amount policy's catalogue currency. */
454
+ amountCurrency: string
455
+ /** Pre-tax subtotal actually charged by Stripe, in `currency`. */
105
456
  chargeAmountMinor: number
457
+ /** Stripe integration/settlement currency. */
106
458
  currency: string
107
459
  }
108
460
  export type TopUpCompletion = QuantityTopUpCompletion | AmountTopUpCompletion
109
461
 
110
- export interface SubscriptionCompletion {
462
+ export type SubscriptionChange = 'created' | 'renewed' | 'upgraded' | 'downgraded' | 'cancel-scheduled'
463
+ | 'cancel-undone' | 'canceled' | 'paused' | 'resumed' | 'past-due' | 'suspended' | 'trial-ending'
464
+
465
+ export interface SubscriptionSnapshot {
111
466
  entityId: string
112
- status: SubscriptionStatus
113
- productSku: string
114
467
  planSku: string
115
- service: string
468
+ productSku: string
469
+ rank: number
470
+ status: SubscriptionStatus
116
471
  paygate: string
472
+ /** The subscription row's `externalId`. */
473
+ subscriptionId: string
474
+ service: string
475
+ periodStart?: Date
476
+ periodEnd?: Date
477
+ cancelAtPeriodEnd?: boolean
478
+ trialEnd?: Date
479
+ pausedAt?: Date
480
+ createdAt?: Date
481
+ capabilities?: PlanCapability[]
482
+ limits?: { [key: string]: LimitDeclaration }
483
+ }
484
+
485
+ export interface SubscriptionEvent {
486
+ change: SubscriptionChange
487
+ /** The state last propagated to observers; `null` for `created`. */
488
+ previous: SubscriptionSnapshot | null
489
+ current: SubscriptionSnapshot
490
+ /** `ENTITLING_STATUSES.includes(current.status)`. */
491
+ active: boolean
492
+ eventKey: string
493
+ invoiceId?: string
494
+ externalEventId?: string
495
+ }
496
+
497
+ export type PaymentTargetKind = 'fulfillment' | 'subscription'
498
+
499
+ export interface RefundEvent {
500
+ entityId: string
501
+ target: PaymentTargetKind
502
+ productSku?: string
503
+ planSku?: string
504
+ /** The target row's `externalId` (checkout session or subscription). */
117
505
  externalId: string
118
- isNew: boolean
119
- capabilities?: PermissionSet[]
120
- limits?: { [key: string]: LimitConfig }
506
+ refundId: string
507
+ paymentIntentId?: string
508
+ invoiceId?: string
509
+ /** This refund. */
510
+ amountMinor: number
511
+ /** Everything refunded on the charge so far, this refund included. */
512
+ refundedTotalMinor: number
513
+ /** What the customer paid on the refunded charge, tax included. */
514
+ paidMinor?: number
515
+ currency: string
516
+ /** Less than the whole charge has been refunded. */
517
+ partial: boolean
518
+ eventKey: string
519
+ /** Fulfillment targets: the net value credited at checkout. */
520
+ netAmountMinor?: number
521
+ /** Fulfillment targets: the pre-tax subtotal charged at checkout. */
522
+ chargeAmountMinor?: number
523
+ /** The refund's own metadata. */
524
+ metadata?: Record<string, string>
525
+ /**
526
+ * Set when the refund executes a withdrawal (`refund.metadata.withdrawalId`): the `onWithdrawal`
527
+ * observer takes back exactly the unused units — an `onRefund` observer must skip its own
528
+ * claw-back for such a refund, or the units are taken back twice.
529
+ */
530
+ withdrawalId?: string
531
+ }
532
+
533
+ export type DisputePhase = 'opened' | 'funds-withdrawn' | 'funds-reinstated' | 'closed'
534
+
535
+ export interface DisputeEvent {
536
+ entityId: string
537
+ target: PaymentTargetKind
538
+ productSku?: string
539
+ planSku?: string
540
+ externalId: string
541
+ disputeId: string
542
+ phase: DisputePhase
543
+ /** The paygate's dispute status (`needs_response`, `won`, `lost`, …). */
544
+ status: string
545
+ amountMinor: number
546
+ currency: string
547
+ eventKey: string
548
+ netAmountMinor?: number
549
+ chargeAmountMinor?: number
550
+ }
551
+
552
+ export interface PaymentFailedEvent {
553
+ entityId: string
554
+ kind: 'checkout' | 'invoice'
555
+ /** The checkout session or invoice id. */
556
+ externalId: string
557
+ subscriptionId?: string
558
+ invoiceId?: string
559
+ attempt?: number
560
+ actionRequired?: boolean
561
+ nextAttemptAt?: Date
562
+ eventKey: string
563
+ }
564
+
565
+ /** A consumer's express request was recorded (performance consent or subscription start). */
566
+ export interface ConsentEvent {
567
+ kind: ConsentKind
568
+ consentId: string
569
+ entityId: string
570
+ profileId?: string
571
+ /** The purchases the consent covers (none for a start request, which precedes its purchase). */
572
+ purchaseIds: string[]
573
+ planSku?: string
574
+ textVersion: string
575
+ language: string
576
+ decidedAt: Date
577
+ expiresAt?: Date
578
+ /** `consent:<consentId>`. */
579
+ eventKey: string
580
+ }
581
+
582
+ /** A withdrawal executed (`refunded`) or left to an operator (`review`). */
583
+ export interface WithdrawalEvent {
584
+ withdrawalId: string
585
+ /** `withdrawal:<withdrawalId>`. */
586
+ eventKey: string
587
+ entityId: string
588
+ channel: DeclarationChannel
589
+ purchase: PurchaseRef
590
+ declaredAt: Date
591
+ status: WithdrawalStatus
592
+ refund: {
593
+ amountMinor: number
594
+ currency: string
595
+ netMinor?: number
596
+ refundId?: string
597
+ creditNoteId?: string
598
+ }
599
+ /**
600
+ * The purchase's units as the usage meter read them: `returned` is what the application takes
601
+ * back (`granted − used`), `null` without a meter.
602
+ */
603
+ units: { granted: number, used: number, returned: number } | null
604
+ subscriptionCanceled: boolean
605
+ }
606
+
607
+ /** A cancellation was declared (matched to a subscription or not). */
608
+ export interface CancellationEvent {
609
+ cancellationId: string
610
+ /** `cancellation:<cancellationId>`. */
611
+ eventKey: string
612
+ entityId?: string
613
+ matched: boolean
614
+ channel: DeclarationChannel
615
+ kind: CancellationKind
616
+ status: CancellationStatus
617
+ subscriptionId?: string
618
+ effectiveAt?: Date
619
+ declaredAt: Date
121
620
  }
621
+
122
622
  export interface TopUpCallback { (completion: TopUpCompletion, ctx: ApiContext): Promise<void> }
123
- export interface SubscriptionCallback { (completion: SubscriptionCompletion, ctx: ApiContext): Promise<void> }
623
+ export interface SubscriptionCallback { (event: SubscriptionEvent, ctx: ApiContext): Promise<void> }
624
+ export interface RefundCallback { (event: RefundEvent, ctx: ApiContext): Promise<void> }
625
+ export interface DisputeCallback { (event: DisputeEvent, ctx: ApiContext): Promise<void> }
626
+ export interface PaymentFailedCallback { (event: PaymentFailedEvent, ctx: ApiContext): Promise<void> }
627
+ export interface ConsentCallback { (event: ConsentEvent, ctx: ApiContext): Promise<void> }
628
+ export interface WithdrawalCallback { (event: WithdrawalEvent, ctx: ApiContext): Promise<void> }
629
+ export interface CancellationCallback { (event: CancellationEvent, ctx: ApiContext): Promise<void> }
630
+
631
+ /**
632
+ * Callbacks run sequentially and are awaited. A paygate callback's throw escapes so the paygate
633
+ * retries; a consumer-rights callback (`onConsent`, `onWithdrawal`, `onCancellation`) runs AFTER
634
+ * the records and the paygate steps, and its throw is recorded and retried by `reconcile()`.
635
+ */
124
636
  export interface CompletionObserver extends LazyService {
125
637
  onTopUp: (cb: TopUpCallback) => void
126
638
  onSubscription: (cb: SubscriptionCallback) => void
639
+ onRefund: (cb: RefundCallback) => void
640
+ onDispute: (cb: DisputeCallback) => void
641
+ onPaymentFailed: (cb: PaymentFailedCallback) => void
642
+ onConsent: (cb: ConsentCallback) => void
643
+ onWithdrawal: (cb: WithdrawalCallback) => void
644
+ onCancellation: (cb: CancellationCallback) => void
127
645
  propagateTopUp: (completion: TopUpCompletion, ctx: ApiContext) => Promise<void>
128
- propagateSubscription: (completion: SubscriptionCompletion, ctx: ApiContext) => Promise<void>
646
+ propagateSubscription: (event: SubscriptionEvent, ctx: ApiContext) => Promise<void>
647
+ propagateRefund: (event: RefundEvent, ctx: ApiContext) => Promise<void>
648
+ propagateDispute: (event: DisputeEvent, ctx: ApiContext) => Promise<void>
649
+ propagatePaymentFailed: (event: PaymentFailedEvent, ctx: ApiContext) => Promise<void>
650
+ propagateConsent: (event: ConsentEvent, ctx: ApiContext) => Promise<void>
651
+ propagateWithdrawal: (event: WithdrawalEvent, ctx: ApiContext) => Promise<void>
652
+ propagateCancellation: (event: CancellationEvent, ctx: ApiContext) => Promise<void>
129
653
  }
130
654
 
655
+ // ---------------------------------------------------------------------------------------------
656
+ // Records
657
+ // ---------------------------------------------------------------------------------------------
658
+
131
659
  export interface PaygateCustomerRecord extends ResourceRecord {
132
- paygate: string; externalId: string; entityId?: string; profileId?: string
133
- email?: string; name?: string; taxId?: string
660
+ paygate: string
661
+ externalId: string
662
+ entityId?: string
663
+ profileId?: string
664
+ email?: string
665
+ name?: string
666
+ taxId?: string
667
+ /** The paygate customer's billing address country, as its last webhook stated it. */
668
+ country?: string
669
+ /** The paygate customer's own currency (set by its first subscription or invoice). */
670
+ currency?: string
671
+ deletedAt?: Date
134
672
  }
135
673
  export interface PaygateCustomerResource extends MongoResource<PaygateCustomerRecord> {
136
674
  loadByPgId: (externalId: string, paygate: string) => Promise<PaygateCustomerRecord | null>
137
675
  byEntity: (entityId: string, paygate: string) => Promise<PaygateCustomerRecord | null>
138
676
  }
677
+
678
+ /** The classification inputs last propagated to observers. */
679
+ export interface PropagatedState {
680
+ planSku: string
681
+ rank: number
682
+ status: SubscriptionStatus
683
+ cancelAtPeriodEnd?: boolean
684
+ pausedAt?: Date
685
+ /** The renewal invoice last reported as `renewed` — a renewal is reported once per invoice. */
686
+ renewedInvoiceId?: string
687
+ }
688
+
689
+ /**
690
+ * What ONE subscription holds instead of its plan's static declaration. Written by an operator,
691
+ * never by the paygate: every sync and re-grant carries it over with the rest of the row.
692
+ */
693
+ export interface SubscriptionOverrides {
694
+ /** By limit key: the ceiling in force for this subscription, whatever the plan or its promo says. */
695
+ limits?: { [key: string]: { limit: number } }
696
+ }
697
+
698
+ /** One row per subscription — paygate (`sub_…`) or internal (`free:<entityId>`, `internal:<planSku>:<entityId>`). */
139
699
  export interface PaymentSubscriptionRecord extends ResourceRecord {
140
- sku: string; productSku: string; entityId: string; service: string; paygate: string
141
- externalId: string; status: SubscriptionStatus; kind: 'consumable' | 'subscription'
142
- capabilities?: PermissionSet[]; limits?: { [key: string]: LimitConfig }
143
- pricingMode?: CheckoutPricingMode; units?: number; amountMinor?: number
144
- chargeAmountMinor?: number; currency?: string
145
- createdAt: Date; endsAt?: Date; trialUntil?: Date; canceledAt?: Date
146
- fulfilledAt?: Date; initialPropagatedAt?: Date
700
+ entityId: string
701
+ planSku: string
702
+ productSku: string
703
+ service: string
704
+ paygate: string
705
+ externalId: string
706
+ itemId?: string
707
+ priceId?: string
708
+ status: SubscriptionStatus
709
+ externalStatus?: string
710
+ rank: number
711
+ periodStart?: Date
712
+ periodEnd?: Date
713
+ cancelAtPeriodEnd?: boolean
714
+ canceledAt?: Date
715
+ endedAt?: Date
716
+ pausedAt?: Date
717
+ trialEnd?: Date
718
+ latestInvoiceId?: string
719
+ customerId?: string
720
+ disputedAt?: Date
721
+ disputeStatus?: string
722
+ createdAt: Date
723
+ updatedAt?: Date
724
+ /** The paygate-side instant of the state stored; an older event payload is not applied. */
725
+ syncedAt?: Date
726
+ lastEventId?: string
727
+ initialPropagatedAt?: Date
728
+ propagated?: PropagatedState
729
+ /** The subscription's currency (lowercase). */
730
+ currency?: string
731
+ // Checkout evidence — written once the checkout that created the subscription completed.
732
+ checkoutSessionId?: string
733
+ purchaseId?: string
734
+ firstInvoiceId?: string
735
+ country?: string
736
+ email?: string
737
+ amountTotalMinor?: number
738
+ amountTaxMinor?: number
739
+ termsAccepted?: boolean
740
+ startRequestId?: string
741
+ withdrawnAt?: Date
742
+ /** This subscription's own plan parameters — `resolveEffectivePlan` answers the plan with them applied. */
743
+ overrides?: SubscriptionOverrides
147
744
  }
148
745
  export interface PaymentSubscriptionResource extends MongoResource<PaymentSubscriptionRecord> {
149
746
  byExternalId: (externalId: string, paygate: string) => Promise<PaymentSubscriptionRecord | null>
747
+ byItemId: (itemId: string, paygate: string) => Promise<PaymentSubscriptionRecord | null>
748
+ }
749
+
750
+ /** A one-time checkout session: pending until observers succeed, then `fulfilledAt`. */
751
+ export interface PaymentFulfillmentRecord extends ResourceRecord {
752
+ entityId: string
753
+ productSku: string
754
+ planSku?: string
755
+ service: string
756
+ paygate: string
757
+ externalId: string
758
+ paymentIntentId?: string
759
+ chargeId?: string
760
+ invoiceId?: string
761
+ mode: CheckoutPricingMode
762
+ units?: number
763
+ amountMinor?: number
764
+ sourceChargeAmountMinor?: number
765
+ amountCurrency?: string
766
+ chargeAmountMinor?: number
767
+ currency?: string
768
+ createdAt: Date
769
+ fulfilledAt?: Date
770
+ failedAt?: Date
771
+ refundedMinor?: number
772
+ refundedAt?: Date
773
+ disputedAt?: Date
774
+ disputeStatus?: string
775
+ // Checkout evidence.
776
+ country?: string
777
+ email?: string
778
+ profileId?: string
779
+ amountTotalMinor?: number
780
+ amountTaxMinor?: number
781
+ termsAccepted?: boolean
782
+ purchaseId?: string
783
+ }
784
+ export interface PaymentFulfillmentResource extends MongoResource<PaymentFulfillmentRecord> {
785
+ byExternalId: (externalId: string, paygate: string) => Promise<PaymentFulfillmentRecord | null>
150
786
  }
787
+
788
+ /** The paygate webhook endpoint this deployment owns, with its signing secret. */
789
+ export interface PaymentWebhookRecord extends ResourceRecord {
790
+ paygate: string
791
+ /** The gateway's `owner` (default `cfg.service`) — the key every process of one owner shares. */
792
+ service: string
793
+ /** The endpoint's URL (`webhookUrlOf`: the `webhookService` alias's host and base). */
794
+ url: string
795
+ externalId: string
796
+ secret: string
797
+ apiVersion: string
798
+ events: string[]
799
+ hash: string
800
+ createdAt: Date
801
+ updatedAt?: Date
802
+ }
803
+ export interface PaymentWebhookResource extends MongoResource<PaymentWebhookRecord> {}
804
+
805
+ /** A usage event — the source of truth of every limit counter. */
806
+ export interface PaymentUsageRecord extends ResourceRecord {
807
+ entityId: string
808
+ limitKey: string
809
+ /** `windowKeyOf` of the limit when the event was written. */
810
+ window: string
811
+ /** `+n` consumed, `-n` released, any sign for a reconciliation adjustment. */
812
+ delta: number
813
+ eventKey: string
814
+ ref?: string
815
+ reason?: string
816
+ planSku?: string
817
+ createdAt: Date
818
+ releasedAt?: Date
819
+ }
820
+ export interface PaymentUsageResource extends MongoResource<PaymentUsageRecord> {}
821
+
822
+ /** The projection of the usage ledger per (entity, limit, window). */
823
+ export interface PaymentUsageCounterRecord extends ResourceRecord {
824
+ entityId: string
825
+ limitKey: string
826
+ window: string
827
+ used: number
828
+ limit: number
829
+ planSku?: string
830
+ overSince?: Date
831
+ updatedAt: Date
832
+ reconciledAt?: Date
833
+ }
834
+ export interface PaymentUsageCounterResource extends MongoResource<PaymentUsageCounterRecord> {}
835
+
836
+ /** One currency option of a synced price. */
837
+ export interface SyncedPriceOption {
838
+ currency: string
839
+ unitAmount: number
840
+ }
841
+
842
+ /** A reusable price as the last sync left it — what `planPrices` and checkout read without Stripe. */
843
+ export interface SyncedPrice {
844
+ planSku: string
845
+ priceId: string
846
+ lookupKey: string
847
+ /** The default currency and its amount. */
848
+ currency: string
849
+ unitAmount: number
850
+ /** `currency_options` besides the default currency. */
851
+ options: SyncedPriceOption[]
852
+ taxBehavior?: string
853
+ interval?: 'month' | 'year'
854
+ sourceUnitAmount: number
855
+ sourceCurrency: string
856
+ syncedAt: Date
857
+ }
858
+
151
859
  export interface FingerprintRecord extends ResourceRecord {
152
- sku: string; hash: string; productId?: string; updatedAt: Date
860
+ sku: string
861
+ hash: string
862
+ productId?: string
863
+ /** The paygate object the fingerprint describes (a portal configuration id). */
864
+ externalId?: string
865
+ /** A product's synced reusable prices. */
866
+ prices?: SyncedPrice[]
867
+ updatedAt: Date
153
868
  }
154
869
  export interface FingerprintResource extends MongoResource<FingerprintRecord> {
155
870
  bySku: (sku: string) => Promise<FingerprintRecord | null>
156
871
  clear: () => Promise<void>
157
872
  }
873
+
874
+ // ---------------------------------------------------------------------------------------------
875
+ // Entitlements
876
+ // ---------------------------------------------------------------------------------------------
877
+
878
+ export interface EffectivePlan {
879
+ plan: PaymentPlan
880
+ /** The entitling row behind the plan; `null` when the entity falls back to the free plan. */
881
+ subscription: PaymentSubscriptionRecord | null
882
+ /** The declared free plan, when one exists. */
883
+ fallback: PaymentPlan | null
884
+ }
885
+
886
+ export interface ConsumeRequest {
887
+ entityId: string
888
+ limitKey: string
889
+ /** Idempotency key — key it by the record the unit pays for. */
890
+ eventKey: string
891
+ /** Positive safe integer; default `1`. */
892
+ amount?: number
893
+ ref?: string
894
+ reason?: string
895
+ }
896
+
897
+ export interface ReleaseRequest {
898
+ entityId: string
899
+ limitKey: string
900
+ /** The event key the unit was consumed under. */
901
+ eventKey: string
902
+ /** Default: the consumed amount. */
903
+ amount?: number
904
+ }
905
+
906
+ export interface LimitOutcome {
907
+ /** A consume: the unit is held. A release: the release is in effect. */
908
+ admitted: boolean
909
+ /** The event key had been seen before; nothing new was written. */
910
+ replayed: boolean
911
+ limitKey: string
912
+ window: string
913
+ used: number
914
+ limit: number
915
+ remaining: number
916
+ resetsAt?: Date
917
+ eventKey: string
918
+ }
919
+
920
+ export interface OccupancyOutcome {
921
+ limitKey: string
922
+ used: number
923
+ limit: number
924
+ /** `max(0, used - limit)`. */
925
+ over: number
926
+ /** When the entity first went over; absent while it is within the limit. */
927
+ overSince?: Date
928
+ }
929
+
930
+ export interface CounterReconciliation {
931
+ counters: number
932
+ repaired: number
933
+ }
934
+
935
+ export interface EntitlementService extends InitializedService {
936
+ effectivePlan: (entityId: string) => Promise<EffectivePlan>
937
+ entitlements: (entityId: string) => Promise<EntitlementView>
938
+ hasCapability: (entityId: string, param: string) => Promise<boolean>
939
+ /** @throws LimitUnknown */
940
+ limitState: (entityId: string, key: string) => Promise<LimitView>
941
+ /** @throws LimitExhausted | LimitUnknown */
942
+ consume: (req: ConsumeRequest) => Promise<LimitOutcome>
943
+ release: (req: ReleaseRequest) => Promise<LimitOutcome>
944
+ /** @throws LimitUnknown | LimitMisdeclared */
945
+ reconcileOccupancy: (entityId: string, limitKey: string, actual: number) => Promise<OccupancyOutcome>
946
+ reconcileCounters: (entityId?: string) => Promise<CounterReconciliation>
947
+ /**
948
+ * The ACTIVE consume event for this key (not released), or null. This is how a consumer asks
949
+ * "was a unit already spent on this record?" — a consumer keys allowances by the record they pay
950
+ * for (`eventKey = <anything>:<recordId>`, `ref = recordId`) instead of writing a marker onto
951
+ * the record, so a retry replays the same event and a resumed run can re-derive that it is free.
952
+ */
953
+ consumption: (entityId: string, limitKey: string, eventKey: string) => Promise<PaymentUsageRecord | null>
954
+ /**
955
+ * The newest ACTIVE consume event (not released) whose `ref` is this record, or null. For a unit
956
+ * consumed under a fresh event key per cycle (`<key>:<recordId>:<timestamp>`, `ref = recordId`):
957
+ * whether the record holds a unit now, and the event key to release it by.
958
+ */
959
+ consumptionByRef: (entityId: string, limitKey: string, ref: string) => Promise<PaymentUsageRecord | null>
960
+ }
961
+
962
+ export interface ReconcileEntityOptions {
963
+ /** Grant this plan (an internal row) when the entity holds no entitling subscription. */
964
+ freePlanSku?: string
965
+ /** Re-read the entity's paygate subscriptions first (managed gateways only). */
966
+ resync?: boolean
967
+ }
968
+
969
+ export interface ReconcileAllOptions extends ReconcileEntityOptions {
970
+ /** Entities to cover besides those the payment store already knows. */
971
+ entities?: Iterable<string> | AsyncIterable<string>
972
+ }
973
+
974
+ export interface ReconcileAllResult {
975
+ entities: number
976
+ granted: number
977
+ counters: number
978
+ repaired: number
979
+ failed: number
980
+ }
981
+
982
+ // ---------------------------------------------------------------------------------------------
983
+ // Consumer rights — records
984
+ // ---------------------------------------------------------------------------------------------
985
+
986
+ /** Where a billing profile's country came from. */
987
+ export type BillingProfileSource = 'checkout' | 'customer' | 'manual'
988
+
989
+ /** One per organization: the billing country fixed at the first purchase (first write wins). */
990
+ export interface BillingProfileRecord extends ResourceRecord {
991
+ entityId: string
992
+ country: string
993
+ region: ConsumerRegion
994
+ /** The charge currency, fixed with the country. */
995
+ currency: string
996
+ /** The language of the legal copy. */
997
+ language: string
998
+ source: BillingProfileSource
999
+ paygate: string
1000
+ customerId?: string
1001
+ sessionId?: string
1002
+ /** The geolocated country of the request that started the locking checkout — VAT evidence. */
1003
+ ipCountry?: string
1004
+ email?: string
1005
+ name?: string
1006
+ /** A business tax id was given at the locking checkout. */
1007
+ business?: boolean
1008
+ lockedAt: Date
1009
+ createdAt: Date
1010
+ updatedAt?: Date
1011
+ }
1012
+ export interface BillingProfileResource extends MongoResource<BillingProfileRecord> {
1013
+ byEntity: (entityId: string) => Promise<BillingProfileRecord | null>
1014
+ }
1015
+
1016
+ /**
1017
+ * One purchase — a contract and its withdrawal window: a paid one-time checkout (`top-up`) or a
1018
+ * subscription's first invoice (`subscription`). Renewals are not purchases.
1019
+ */
1020
+ export interface PurchaseRecord extends ResourceRecord {
1021
+ /** `stripe:<session id>` (one-time) or `stripe:<subscription id>`. */
1022
+ purchaseId: string
1023
+ /** `CR-YYMMDD-XXXXXX` — what a consumer quotes. */
1024
+ contractRef: string
1025
+ entityId: string
1026
+ kind: PurchaseKind
1027
+ paygate: string
1028
+ sessionId?: string
1029
+ subscriptionId?: string
1030
+ paymentIntentId?: string
1031
+ invoiceId?: string
1032
+ invoiceNumber?: string
1033
+ invoiceLineId?: string
1034
+ productSku: string
1035
+ planSku?: string
1036
+ profileId?: string
1037
+ country?: string
1038
+ region?: ConsumerRegion
1039
+ ipCountry?: string
1040
+ inScope: boolean
1041
+ language: string
1042
+ email?: string
1043
+ name?: string
1044
+ business?: boolean
1045
+ /** The charge currency. */
1046
+ currency: string
1047
+ amountSubtotalMinor: number
1048
+ amountTaxMinor: number
1049
+ amountTotalMinor: number
1050
+ presentmentCurrency?: string
1051
+ presentmentAmountMinor?: number
1052
+ /** Amount checkout: the net value credited, in `amountCurrency`. */
1053
+ netAmountMinor?: number
1054
+ amountCurrency?: string
1055
+ /** Quantity checkout: the units bought. */
1056
+ units?: number
1057
+ taxBehavior?: string
1058
+ /**
1059
+ * Stripe's own `consent.terms_of_service` of the checkout — absent when the session did not
1060
+ * collect it (the policy's `checkoutTerms` off, or the fallback of a Dashboard without a terms URL).
1061
+ */
1062
+ termsAccepted?: boolean
1063
+ textVersion?: string
1064
+ copyVersion?: string
1065
+ startRequestId?: string
1066
+ /** When the consumer expressly requested the services (the start request) — time deductions count from here. */
1067
+ servicesStartedAt?: Date
1068
+ /** When the confirmation mail was claimed — one claim per purchase, whatever the outcome of the send. */
1069
+ confirmationMailAt?: Date
1070
+ purchasedAt: Date
1071
+ /** Exclusive end of the withdrawal window; absent outside the consumer-rights territories. */
1072
+ deadline?: Date
1073
+ consentId?: string
1074
+ consentedAt?: Date
1075
+ withdrawalId?: string
1076
+ withdrawnAt?: Date
1077
+ /** Refunded so far on this purchase's payment, tax included. */
1078
+ refundedMinor?: number
1079
+ /** Set once the whole payment is refunded — the window closes. */
1080
+ refundedAt?: Date
1081
+ cancellationId?: string
1082
+ cancelEffectiveAt?: Date
1083
+ createdAt: Date
1084
+ updatedAt?: Date
1085
+ }
1086
+ export interface PurchaseResource extends MongoResource<PurchaseRecord> {
1087
+ byPurchaseId: (purchaseId: string) => Promise<PurchaseRecord | null>
1088
+ }
1089
+
1090
+ /** The request evidence a consumer act is recorded with (`requestOriginOf`). */
1091
+ export interface RequestOrigin {
1092
+ /** `cf-connecting-ip`, else the LAST `x-forwarded-for` entry, else `x-real-ip`, else the socket. */
1093
+ ip?: string
1094
+ /** The raw `x-forwarded-for` header. */
1095
+ forwardedFor?: string
1096
+ /** `user-agent`, at most 512 characters. */
1097
+ userAgent?: string
1098
+ /** `cf-ipcountry`. */
1099
+ ipCountry?: string
1100
+ acceptLanguage?: string
1101
+ /** The channel the request came through (`http`, `mcp`, …), when the application knows. */
1102
+ via?: string
1103
+ }
1104
+
1105
+ /** Append-only: one express request — a performance consent or a subscription start request. */
1106
+ export interface ConsumerConsentRecord extends ResourceRecord, RequestOrigin {
1107
+ kind: ConsentKind
1108
+ entityId: string
1109
+ profileId?: string
1110
+ /** The person who gave it — the confirmation is mailed here. */
1111
+ name?: string
1112
+ email?: string
1113
+ purchaseIds: string[]
1114
+ planSku?: string
1115
+ /** The plan's name as the statement said it (`{{plan}}`). */
1116
+ planName?: string
1117
+ textVersion: string
1118
+ copyVersion: string
1119
+ /** The language the statement was shown in. */
1120
+ language: string
1121
+ uiLanguage?: string
1122
+ trader: string
1123
+ /**
1124
+ * The copy variant the statement was rendered with: the policy's `consentContext` for a
1125
+ * performance consent, `startContextOf(plan)` (`'units'`) for a start request; absent for the base.
1126
+ */
1127
+ context?: string
1128
+ /** The statement exactly as rendered and recorded. */
1129
+ text: { request: string, acknowledgement: string, checkbox: string }
1130
+ links: ConsumerRightsLinks
1131
+ /** The latest deadline among the covered purchases. */
1132
+ deadline?: Date
1133
+ decidedAt: Date
1134
+ /** A start request stops being usable at this instant. */
1135
+ expiresAt?: Date
1136
+ }
1137
+ export interface ConsumerConsentResource extends MongoResource<ConsumerConsentRecord> {}
1138
+
1139
+ /** Append-only: one withdrawal or cancellation declaration, matched to a contract or not. */
1140
+ export interface ConsumerDeclarationRecord extends ResourceRecord, RequestOrigin {
1141
+ kind: DeclarationKind
1142
+ channel: DeclarationChannel
1143
+ entityId?: string
1144
+ purchaseId?: string
1145
+ subscriptionId?: string
1146
+ /** The contract as the consumer named it. */
1147
+ contractRef?: string
1148
+ name: string
1149
+ email: string
1150
+ cancellationKind?: CancellationKind
1151
+ reason?: string
1152
+ effective?: 'earliest' | 'date'
1153
+ requestedDate?: string
1154
+ language: string
1155
+ textVersion?: string
1156
+ copyVersion: string
1157
+ receivedAt: Date
1158
+ matched: boolean
1159
+ profileId?: string
1160
+ /** A repeated declaration of a contract already withdrawn from: the original's id. */
1161
+ duplicateOf?: string
1162
+ /** The status decided on receipt (`WithdrawalStatus` / `CancellationStatus`); execution steps are events. */
1163
+ status: string
1164
+ refundMinor?: number
1165
+ currency?: string
1166
+ effectiveAt?: Date
1167
+ }
1168
+ export interface ConsumerDeclarationResource extends MongoResource<ConsumerDeclarationRecord> {}
1169
+
1170
+ export type ConsumerEventAction =
1171
+ | 'mail' | 'computed' | 'meter' | 'refund' | 'credit-note' | 'subscription-cancel' | 'cancel-scheduled'
1172
+ | 'observers' | 'lock' | 'lock-mismatch' | 'relock' | 'unlock' | 'duplicate' | 'checkout-terms-fallback'
1173
+
1174
+ export type ConsumerRecordKind = 'purchase' | 'consent' | 'declaration' | 'profile' | 'checkout'
1175
+
1176
+ /** Append-only: one execution or audit step. */
1177
+ export interface ConsumerEventRecord extends ResourceRecord {
1178
+ /** The purchase id, consent id, declaration id, or the entity id of a profile or a checkout. */
1179
+ recordId: string
1180
+ recordKind: ConsumerRecordKind
1181
+ entityId?: string
1182
+ action: ConsumerEventAction
1183
+ /** The mail kind of a `mail` event; the observer family of an `observers` one. */
1184
+ step?: string
1185
+ ok: boolean
1186
+ /** A mail deliberately not sent (a reserved domain, a renderer that suppressed it). */
1187
+ skipped?: boolean
1188
+ externalId?: string
1189
+ amountMinor?: number
1190
+ currency?: string
1191
+ /** JSON. */
1192
+ detail?: string
1193
+ error?: string
1194
+ at: Date
1195
+ }
1196
+ export interface ConsumerEventResource extends MongoResource<ConsumerEventRecord> {}
1197
+
1198
+ // ---------------------------------------------------------------------------------------------
1199
+ // Consumer rights — service
1200
+ // ---------------------------------------------------------------------------------------------
1201
+
1202
+ /** What a usage meter is told about the purchase it reads. */
1203
+ export interface PurchaseRef {
1204
+ purchaseId: string
1205
+ kind: PurchaseKind
1206
+ entityId: string
1207
+ contractRef: string
1208
+ productSku: string
1209
+ planSku?: string
1210
+ /** One-time purchases: the checkout session id. */
1211
+ sessionId?: string
1212
+ /** Subscription purchases: the paygate subscription id. */
1213
+ subscriptionId?: string
1214
+ invoiceId?: string
1215
+ purchasedAt: Date
1216
+ }
1217
+
1218
+ export interface UsageQuery {
1219
+ entityId: string
1220
+ purchase: PurchaseRef
1221
+ /** The purchase's consent — before it the consumer bears no cost; absent: nothing is deductible. */
1222
+ after?: Date
1223
+ at: Date
1224
+ }
1225
+
1226
+ export interface UsageReading {
1227
+ /** Units the purchase granted. */
1228
+ granted: number
1229
+ /** Units of it used so far. */
1230
+ used: number
1231
+ /** Units of it used strictly after `after` (0 without `after`). */
1232
+ usedAfter: number
1233
+ /** Units of it that paid off an earlier overdraft when it was granted. */
1234
+ settled?: number
1235
+ /** Units of it already taken back by an earlier (money) refund. */
1236
+ clawed?: number
1237
+ remaining?: number
1238
+ }
1239
+
1240
+ /**
1241
+ * The application's reading of how much of one purchase was used — for a withdrawal's refund.
1242
+ * The deduction is `usedAfter + settled + clawed`.
1243
+ */
1244
+ export interface UsageMeter {
1245
+ used: (ctx: ApiContext, query: UsageQuery) => Promise<UsageReading>
1246
+ }
1247
+
1248
+ /** Who acts: the organization, and the person's prefill. */
1249
+ export interface ConsumerSubject {
1250
+ entityId: string
1251
+ profileId?: string
1252
+ name?: string
1253
+ email?: string
1254
+ /** `public` when an application matched a public declaration to this organization itself. */
1255
+ channel?: DeclarationChannel
1256
+ }
1257
+
1258
+ export type ConsumerMailKind = 'purchase' | 'consent' | 'start' | 'withdrawal' | 'cancellation'
1259
+
1260
+ /** What a consumer-rights mail is rendered from. */
1261
+ export interface ConsumerMailData {
1262
+ kind: ConsumerMailKind
1263
+ /** The purchase id, consent id or declaration id. */
1264
+ recordId: string
1265
+ entityId?: string
1266
+ language: string
1267
+ to: string
1268
+ name?: string
1269
+ trader: TraderDef
1270
+ links: ConsumerRightsLinks
1271
+ purchase?: PurchaseRecord
1272
+ purchases?: PurchaseRecord[]
1273
+ consent?: ConsumerConsentRecord
1274
+ declaration?: ConsumerDeclarationRecord
1275
+ }
1276
+
1277
+ /**
1278
+ * Replace or suppress a consumer-rights mail: answer a message to send it instead, `null` to send
1279
+ * nothing (recorded as skipped), `undefined` to send the rendered one.
1280
+ */
1281
+ export interface ConsumerMailRenderer { (kind: ConsumerMailKind, data: ConsumerMailData, rendered: MailMessage): MailMessage | null | undefined | Promise<MailMessage | null | undefined> }
1282
+
1283
+ export interface LockOptions {
1284
+ customerId?: string
1285
+ sessionId?: string
1286
+ ipCountry?: string
1287
+ email?: string
1288
+ name?: string
1289
+ business?: boolean
1290
+ /** The charge currency; default: an active subscription's, else the region's. */
1291
+ currency?: string
1292
+ language?: string
1293
+ /** `manual` only: replace an existing lock (audited as a `relock` event). */
1294
+ force?: boolean
1295
+ by?: string
1296
+ reason?: string
1297
+ }
1298
+
1299
+ /** Who removes a lock, and why — kept on the `unlock` event. */
1300
+ export interface UnlockOptions {
1301
+ by?: string
1302
+ reason?: string
1303
+ }
1304
+
1305
+ export interface ConsumerReconcileOptions {
1306
+ /** How far back declarations, mails and observers are retried. Default 30 days. */
1307
+ since?: Date
1308
+ /** The most items per step. Default 50. */
1309
+ limit?: number
1310
+ }
1311
+
1312
+ export interface ConsumerReconcileResult {
1313
+ retried: number
1314
+ mailed: number
1315
+ observed: number
1316
+ backfilled: number
1317
+ locked: number
1318
+ failed: number
1319
+ }
1320
+
1321
+ /**
1322
+ * Lazy: reachable while the application is still being wired (`useMeter`, `useMailRenderer` before
1323
+ * the context initializes); the gateway's initialization initializes it at boot.
1324
+ */
1325
+ export interface ConsumerRightsService extends LazyService {
1326
+ /**
1327
+ * `false`: every paygate-calling method (`withdraw`, `cancel`, `reconcile`'s paygate steps) refuses.
1328
+ * An explicit `manage` of `appendConsumerRights` wins over the gateway's, whatever the order.
1329
+ */
1330
+ readonly managed: boolean
1331
+ policy: () => Promise<ConsumerRightsPolicy | null>
1332
+ /** The locked billing profile, or `null`. */
1333
+ profile: (entityId: string) => Promise<BillingProfileView | null>
1334
+ /** Lock the billing country; the first write wins unless a `manual` lock is `force`d. */
1335
+ lock: (entityId: string, country: string, source: BillingProfileSource, opts?: LockOptions) => Promise<BillingProfileView>
1336
+ /**
1337
+ * An operator removes the lock: the profile is deleted and an `unlock` event keeps it. No lazy lock
1338
+ * from the paygate customer follows (checkout, reconcile); the next completed purchase locks again.
1339
+ * @returns the profile as it was, or `null` when nothing was locked
1340
+ */
1341
+ unlock: (entityId: string, opts?: UnlockOptions) => Promise<BillingProfileView | null>
1342
+ purchases: (entityId: string, opts?: { open?: boolean, at?: Date }) => Promise<PurchaseView[]>
1343
+ consentView: (entityId: string, at?: Date) => Promise<PerformanceConsentView>
1344
+ /** @throws PerformanceConsentRequired (428) for a stale text version */
1345
+ recordConsent: (subject: ConsumerSubject, body: PerformanceConsentBody, origin?: RequestOrigin) => Promise<PerformanceConsentResponse>
1346
+ /** @throws PerformanceConsentRequired while an open in-scope window has no consent */
1347
+ assertConsent: (entityId: string, at?: Date) => Promise<void>
1348
+ /** `context` = `startContextOf(plan)`: the statement variant the dialog shows and the request records. */
1349
+ startView: (entityId: string, planSku: string, opts?: { language?: string }) => Promise<SubscriptionStartView>
1350
+ /**
1351
+ * Records the statement in the variant of the plan (`startContextOf`), the one the start view
1352
+ * named. `plan`: the plan's short name the statement says (default: its localized catalogue title).
1353
+ * @throws SubscriptionStartRequired (428) for a stale text version
1354
+ */
1355
+ recordStartRequest: (
1356
+ subject: ConsumerSubject, body: SubscriptionStartBody, origin?: RequestOrigin, opts?: { plan?: string },
1357
+ ) => Promise<SubscriptionStartResponse>
1358
+ /**
1359
+ * The fresh start request bound to this entity and plan, or `null` when none is required.
1360
+ * @throws SubscriptionStartRequired
1361
+ */
1362
+ assertStartRequest: (entityId: string, planSku: string, startRequestId?: string) => Promise<ConsumerConsentRecord | null>
1363
+ withdrawalCandidates: (entityId: string, subject?: Partial<ConsumerSubject>) => Promise<WithdrawalCandidateList>
1364
+ /** `subject: null` — the public function: matched by contract reference and e-mail, never disclosed. */
1365
+ withdraw: (subject: ConsumerSubject | null, body: WithdrawalBody, origin?: RequestOrigin) => Promise<WithdrawalReceipt>
1366
+ cancel: (subject: ConsumerSubject | null, body: CancellationBody, origin?: RequestOrigin) => Promise<CancellationReceipt>
1367
+ useMeter: (meter: UsageMeter | null) => void
1368
+ useMailRenderer: (renderer: ConsumerMailRenderer | null) => void
1369
+ usageMeter: () => UsageMeter | null
1370
+ mailRenderer: () => ConsumerMailRenderer | null
1371
+ /** Retry refunds, credit notes, cancellations, mails and observers; backfill purchases and legacy locks. */
1372
+ reconcile: (opts?: ConsumerReconcileOptions) => Promise<ConsumerReconcileResult>
1373
+ }
1374
+
1375
+ /**
1376
+ * `appendConsumerRights` options. `manage`, `usage` and `stripe` apply to the service whenever the
1377
+ * call comes — before or after the gateway registered it; the resources' `dbAlias` / `serviceAlias`
1378
+ * are those of the first registration.
1379
+ */
1380
+ export interface ConsumerRightsOptions {
1381
+ /**
1382
+ * `false` in a process that never talks to the paygate (reads and consent asserts only). Absent:
1383
+ * the gateway's `manage`, else managed.
1384
+ */
1385
+ manage?: boolean
1386
+ /** The application's usage meter; without one a withdrawal is left to an operator (`review`). */
1387
+ usage?: UsageMeter
1388
+ alias?: string
1389
+ /** The paygate client; default: the configured Stripe secret. */
1390
+ stripe?: StripeFactory
1391
+ dbAlias?: string
1392
+ serviceAlias?: string
1393
+ }
1394
+
1395
+ // ---------------------------------------------------------------------------------------------
1396
+ // Consumer rights — handlers
1397
+ // ---------------------------------------------------------------------------------------------
1398
+
1399
+ /** What a public declaration is throttled by. */
1400
+ export interface ConsumerThrottleKey {
1401
+ action: 'withdrawal' | 'cancellation'
1402
+ email: string
1403
+ ip?: string
1404
+ }
1405
+
1406
+ /**
1407
+ * The hooks of `consumerRightsEntrypoints`. Every hook gets the request's context last, so an
1408
+ * application keeps its counters and lookups on the context, never in module state.
1409
+ */
1410
+ export interface ConsumerRightsHandlerOptions {
1411
+ /** The organization a signed-in request acts for. Default: `req.entity.id`. */
1412
+ resolveEntity?: (req: AbstractRequest, ctx: ApiContext) => string | null | undefined
1413
+ /** The person's profile id and prefill. */
1414
+ subjectOf?: (req: AbstractRequest, ctx: ApiContext) => Partial<ConsumerSubject> | Promise<Partial<ConsumerSubject>>
1415
+ /** Refuse a money-moving act (consent, start, withdraw, cancel) — e.g. an API-key request. */
1416
+ guardMoney?: (req: AbstractRequest, action: string, ctx: ApiContext) => void | Promise<void>
1417
+ /** REQUIRED when the public subtree is bound: throw (e.g. 429) to refuse a public declaration. */
1418
+ throttle?: (req: AbstractRequest, key: ConsumerThrottleKey, ctx: ApiContext) => void | Promise<void>
1419
+ /** The request evidence; default `requestOriginOf`. */
1420
+ metaOf?: (req: AbstractRequest, ctx: ApiContext) => RequestOrigin
1421
+ /** The least time a public declaration takes to answer, matched or not. Default 1000 ms. */
1422
+ publicMinMs?: number
1423
+ /** The plan's short name a start request's statement says (default: its localized catalogue title). */
1424
+ planNameOf?: (
1425
+ planSku: string, language: string, req: AbstractRequest, ctx: ApiContext,
1426
+ ) => string | undefined | Promise<string | undefined>
1427
+ serviceAlias?: string
1428
+ }
1429
+
1430
+ export interface CheckoutReadHandlerOptions {
1431
+ resolveEntity?: (req: AbstractRequest, ctx: ApiContext) => string | null | undefined
1432
+ gatewayAlias?: string
1433
+ }
1434
+
1435
+ export interface PaygateParams { paygate: string }
1436
+
1437
+ export interface ResyncResult { ok: boolean }
1438
+
1439
+ export interface ResyncSubscriptionsResult { scanned: number; updated: number }
1440
+
1441
+ export interface EntityResolverOption {
1442
+ /** The stable organization id a request acts for. Default: `req.entity.id`, else the token's entity. */
1443
+ resolveEntity?: (req: AbstractRequest) => string | null
1444
+ }
1445
+
1446
+ export interface CapabilityGateOptions extends EntityResolverOption {
1447
+ /** Refuse unless the effective plan belongs to one of these products. */
1448
+ productSkus?: string[]
1449
+ /**
1450
+ * Also require the token to grant the permission (IAM `hasPermission`). Off by default: a
1451
+ * platform token carries no permissions, and the subscription is the authority.
1452
+ */
1453
+ requirePermission?: boolean
1454
+ }
1455
+
1456
+ /** @deprecated use `CapabilityGateOptions` */
1457
+ export type EntitlementGateOptions = CapabilityGateOptions
1458
+
1459
+ export interface LimitGateOptions extends EntityResolverOption {}
1460
+
1461
+ export interface StripeBootstrapOptions {
1462
+ /** Re-verify what the stored fingerprints say is in place. */
1463
+ force?: boolean
1464
+ }
1465
+
1466
+ /** The gateway options a service instance takes — the resource aliases belong to the registration. */
1467
+ export interface GatewayServiceOptions extends Omit<PaymentGatewayOptions, 'dbAlias' | 'serviceAlias'> {}
1468
+
1469
+ export interface CommitOptions {
1470
+ /** The paygate event being applied; a repeat of the last applied one is ignored. */
1471
+ eventId?: string
1472
+ /** A paid renewal invoice. */
1473
+ renewal?: boolean
1474
+ invoiceId?: string
1475
+ /** The paygate announced the trial ends soon. */
1476
+ trialEnding?: boolean
1477
+ /**
1478
+ * Runs after the new state is written and BEFORE observers hear the change — what must exist
1479
+ * before an observer grants anything (a subscription's purchase row). A throw propagates: the
1480
+ * observers are not told and the paygate retries.
1481
+ */
1482
+ beforePropagate?: (record: PaymentSubscriptionRecord, change: SubscriptionChange) => Promise<void>
1483
+ }
1484
+
1485
+ export interface CommitResult {
1486
+ record: PaymentSubscriptionRecord | null
1487
+ change: SubscriptionChange | null
1488
+ /** The stored subscription state changed. */
1489
+ updated: boolean
1490
+ }