@adonis-agora/payments 0.2.0 → 0.3.0

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 (319) hide show
  1. package/CHANGELOG.md +2347 -0
  2. package/dist/assets/spa/assets/index-CT5Zon6P.css +1 -0
  3. package/dist/assets/spa/assets/index-CvEbJEnq.js +41 -0
  4. package/dist/assets/spa/assets/index-CvEbJEnq.js.map +1 -0
  5. package/dist/assets/spa/index.html +20 -0
  6. package/dist/commands/main.d.ts +4 -3
  7. package/dist/commands/main.d.ts.map +1 -1
  8. package/dist/commands/main.js +9 -2
  9. package/dist/commands/main.js.map +1 -1
  10. package/dist/commands/payments_health.d.ts +31 -0
  11. package/dist/commands/payments_health.d.ts.map +1 -0
  12. package/dist/commands/payments_health.js +113 -0
  13. package/dist/commands/payments_health.js.map +1 -0
  14. package/dist/commands/payments_sync.d.ts +18 -4
  15. package/dist/commands/payments_sync.d.ts.map +1 -1
  16. package/dist/commands/payments_sync.js +136 -40
  17. package/dist/commands/payments_sync.js.map +1 -1
  18. package/dist/configure.d.ts +12 -5
  19. package/dist/configure.d.ts.map +1 -1
  20. package/dist/configure.js +18 -5
  21. package/dist/configure.js.map +1 -1
  22. package/dist/providers/dashboard_provider.d.ts +97 -0
  23. package/dist/providers/dashboard_provider.d.ts.map +1 -0
  24. package/dist/providers/dashboard_provider.js +430 -0
  25. package/dist/providers/dashboard_provider.js.map +1 -0
  26. package/dist/providers/payments_client_provider.d.ts +41 -0
  27. package/dist/providers/payments_client_provider.d.ts.map +1 -0
  28. package/dist/providers/payments_client_provider.js +95 -0
  29. package/dist/providers/payments_client_provider.js.map +1 -0
  30. package/dist/providers/payments_provider.d.ts +35 -0
  31. package/dist/providers/payments_provider.d.ts.map +1 -1
  32. package/dist/providers/payments_provider.js +250 -36
  33. package/dist/providers/payments_provider.js.map +1 -1
  34. package/dist/src/billing/billing_health.d.ts +85 -0
  35. package/dist/src/billing/billing_health.d.ts.map +1 -0
  36. package/dist/src/billing/billing_health.js +155 -0
  37. package/dist/src/billing/billing_health.js.map +1 -0
  38. package/dist/src/billing/billing_overview.d.ts +4 -3
  39. package/dist/src/billing/billing_overview.d.ts.map +1 -1
  40. package/dist/src/billing/billing_overview.js +14 -5
  41. package/dist/src/billing/billing_overview.js.map +1 -1
  42. package/dist/src/billing/billing_store.d.ts +634 -5
  43. package/dist/src/billing/billing_store.d.ts.map +1 -1
  44. package/dist/src/billing/billing_store.js +18 -1
  45. package/dist/src/billing/billing_store.js.map +1 -1
  46. package/dist/src/billing/index.d.ts +2 -1
  47. package/dist/src/billing/index.d.ts.map +1 -1
  48. package/dist/src/billing/index.js +1 -0
  49. package/dist/src/billing/index.js.map +1 -1
  50. package/dist/src/billing/list_query.d.ts +16 -0
  51. package/dist/src/billing/list_query.d.ts.map +1 -0
  52. package/dist/src/billing/list_query.js +28 -0
  53. package/dist/src/billing/list_query.js.map +1 -0
  54. package/dist/src/billing/lucid_billing_store.d.ts +122 -4
  55. package/dist/src/billing/lucid_billing_store.d.ts.map +1 -1
  56. package/dist/src/billing/lucid_billing_store.js +811 -13
  57. package/dist/src/billing/lucid_billing_store.js.map +1 -1
  58. package/dist/src/billing/mixins/index.d.ts +3 -0
  59. package/dist/src/billing/mixins/index.d.ts.map +1 -1
  60. package/dist/src/billing/mixins/index.js +3 -0
  61. package/dist/src/billing/mixins/index.js.map +1 -1
  62. package/dist/src/billing/mixins/with_audit_event.d.ts +48 -0
  63. package/dist/src/billing/mixins/with_audit_event.d.ts.map +1 -0
  64. package/dist/src/billing/mixins/with_audit_event.js +77 -0
  65. package/dist/src/billing/mixins/with_audit_event.js.map +1 -0
  66. package/dist/src/billing/mixins/with_customer.d.ts +39 -0
  67. package/dist/src/billing/mixins/with_customer.d.ts.map +1 -0
  68. package/dist/src/billing/mixins/with_customer.js +68 -0
  69. package/dist/src/billing/mixins/with_customer.js.map +1 -0
  70. package/dist/src/billing/mixins/with_dispute.d.ts +68 -0
  71. package/dist/src/billing/mixins/with_dispute.d.ts.map +1 -0
  72. package/dist/src/billing/mixins/with_dispute.js +83 -0
  73. package/dist/src/billing/mixins/with_dispute.js.map +1 -0
  74. package/dist/src/billing/mixins/with_payment.d.ts +42 -0
  75. package/dist/src/billing/mixins/with_payment.d.ts.map +1 -1
  76. package/dist/src/billing/mixins/with_payment.js +29 -3
  77. package/dist/src/billing/mixins/with_payment.js.map +1 -1
  78. package/dist/src/billing/mixins/with_subscription.d.ts +7 -0
  79. package/dist/src/billing/mixins/with_subscription.d.ts.map +1 -1
  80. package/dist/src/billing/mixins/with_subscription.js +15 -1
  81. package/dist/src/billing/mixins/with_subscription.js.map +1 -1
  82. package/dist/src/billing/mixins/with_usage_event.d.ts +7 -0
  83. package/dist/src/billing/mixins/with_usage_event.d.ts.map +1 -1
  84. package/dist/src/billing/mixins/with_usage_event.js +15 -1
  85. package/dist/src/billing/mixins/with_usage_event.js.map +1 -1
  86. package/dist/src/billing/mixins/with_webhook_event.d.ts +18 -0
  87. package/dist/src/billing/mixins/with_webhook_event.d.ts.map +1 -1
  88. package/dist/src/billing/mixins/with_webhook_event.js +18 -1
  89. package/dist/src/billing/mixins/with_webhook_event.js.map +1 -1
  90. package/dist/src/billing/resolve_dispatch.d.ts +22 -0
  91. package/dist/src/billing/resolve_dispatch.d.ts.map +1 -0
  92. package/dist/src/billing/resolve_dispatch.js +44 -0
  93. package/dist/src/billing/resolve_dispatch.js.map +1 -0
  94. package/dist/src/billing/resolve_store.d.ts +18 -0
  95. package/dist/src/billing/resolve_store.d.ts.map +1 -0
  96. package/dist/src/billing/resolve_store.js +35 -0
  97. package/dist/src/billing/resolve_store.js.map +1 -0
  98. package/dist/src/billing/schema.d.ts +108 -0
  99. package/dist/src/billing/schema.d.ts.map +1 -0
  100. package/dist/src/billing/schema.js +350 -0
  101. package/dist/src/billing/schema.js.map +1 -0
  102. package/dist/src/billing/webhook_dispatcher.d.ts +95 -16
  103. package/dist/src/billing/webhook_dispatcher.d.ts.map +1 -1
  104. package/dist/src/billing/webhook_dispatcher.js +186 -33
  105. package/dist/src/billing/webhook_dispatcher.js.map +1 -1
  106. package/dist/src/billing/webhook_events.d.ts +67 -1
  107. package/dist/src/billing/webhook_events.d.ts.map +1 -1
  108. package/dist/src/billing/webhook_events.js +15 -0
  109. package/dist/src/billing/webhook_events.js.map +1 -1
  110. package/dist/src/billing/webhook_processor.d.ts.map +1 -1
  111. package/dist/src/billing/webhook_processor.js +325 -5
  112. package/dist/src/billing/webhook_processor.js.map +1 -1
  113. package/dist/src/client/define_config.d.ts +150 -0
  114. package/dist/src/client/define_config.d.ts.map +1 -0
  115. package/dist/src/client/define_config.js +98 -0
  116. package/dist/src/client/define_config.js.map +1 -0
  117. package/dist/src/client/handlers.d.ts +71 -0
  118. package/dist/src/client/handlers.d.ts.map +1 -0
  119. package/dist/src/client/handlers.js +119 -0
  120. package/dist/src/client/handlers.js.map +1 -0
  121. package/dist/src/client/index.d.ts +16 -0
  122. package/dist/src/client/index.d.ts.map +1 -0
  123. package/dist/src/client/index.js +13 -0
  124. package/dist/src/client/index.js.map +1 -0
  125. package/dist/src/client/statuses.d.ts +38 -0
  126. package/dist/src/client/statuses.d.ts.map +1 -0
  127. package/dist/src/client/statuses.js +42 -0
  128. package/dist/src/client/statuses.js.map +1 -0
  129. package/dist/src/dashboard/actions.d.ts +143 -0
  130. package/dist/src/dashboard/actions.d.ts.map +1 -0
  131. package/dist/src/dashboard/actions.js +112 -0
  132. package/dist/src/dashboard/actions.js.map +1 -0
  133. package/dist/src/dashboard/auth.d.ts +136 -0
  134. package/dist/src/dashboard/auth.d.ts.map +1 -0
  135. package/dist/src/dashboard/auth.js +152 -0
  136. package/dist/src/dashboard/auth.js.map +1 -0
  137. package/dist/src/dashboard/define_config.d.ts +80 -0
  138. package/dist/src/dashboard/define_config.d.ts.map +1 -0
  139. package/dist/src/dashboard/define_config.js +83 -0
  140. package/dist/src/dashboard/define_config.js.map +1 -0
  141. package/dist/src/dashboard/handlers.d.ts +281 -0
  142. package/dist/src/dashboard/handlers.d.ts.map +1 -0
  143. package/dist/src/dashboard/handlers.js +960 -0
  144. package/dist/src/dashboard/handlers.js.map +1 -0
  145. package/dist/src/dashboard/index.d.ts +18 -0
  146. package/dist/src/dashboard/index.d.ts.map +1 -0
  147. package/dist/src/dashboard/index.js +14 -0
  148. package/dist/src/dashboard/index.js.map +1 -0
  149. package/dist/src/dashboard/login_page.d.ts +23 -0
  150. package/dist/src/dashboard/login_page.d.ts.map +1 -0
  151. package/dist/src/dashboard/login_page.js +170 -0
  152. package/dist/src/dashboard/login_page.js.map +1 -0
  153. package/dist/src/dashboard/period.d.ts +31 -0
  154. package/dist/src/dashboard/period.d.ts.map +1 -0
  155. package/dist/src/dashboard/period.js +44 -0
  156. package/dist/src/dashboard/period.js.map +1 -0
  157. package/dist/src/dashboard/session_cookie.d.ts +42 -0
  158. package/dist/src/dashboard/session_cookie.d.ts.map +1 -0
  159. package/dist/src/dashboard/session_cookie.js +97 -0
  160. package/dist/src/dashboard/session_cookie.js.map +1 -0
  161. package/dist/src/dashboard/spa.d.ts +24 -0
  162. package/dist/src/dashboard/spa.d.ts.map +1 -0
  163. package/dist/src/dashboard/spa.js +52 -0
  164. package/dist/src/dashboard/spa.js.map +1 -0
  165. package/dist/src/define_config.d.ts +244 -9
  166. package/dist/src/define_config.d.ts.map +1 -1
  167. package/dist/src/define_config.js +97 -1
  168. package/dist/src/define_config.js.map +1 -1
  169. package/dist/src/diagnostics.d.ts +287 -7
  170. package/dist/src/diagnostics.d.ts.map +1 -1
  171. package/dist/src/diagnostics.js +317 -1
  172. package/dist/src/diagnostics.js.map +1 -1
  173. package/dist/src/driver.d.ts +139 -5
  174. package/dist/src/driver.d.ts.map +1 -1
  175. package/dist/src/drivers/abacate.d.ts +12 -2
  176. package/dist/src/drivers/abacate.d.ts.map +1 -1
  177. package/dist/src/drivers/abacate.js +112 -19
  178. package/dist/src/drivers/abacate.js.map +1 -1
  179. package/dist/src/drivers/adyen.d.ts +164 -0
  180. package/dist/src/drivers/adyen.d.ts.map +1 -0
  181. package/dist/src/drivers/adyen.js +678 -0
  182. package/dist/src/drivers/adyen.js.map +1 -0
  183. package/dist/src/drivers/asaas.d.ts +52 -2
  184. package/dist/src/drivers/asaas.d.ts.map +1 -1
  185. package/dist/src/drivers/asaas.js +364 -29
  186. package/dist/src/drivers/asaas.js.map +1 -1
  187. package/dist/src/drivers/dodo.d.ts +135 -0
  188. package/dist/src/drivers/dodo.d.ts.map +1 -0
  189. package/dist/src/drivers/dodo.js +864 -0
  190. package/dist/src/drivers/dodo.js.map +1 -0
  191. package/dist/src/drivers/efi.d.ts +98 -0
  192. package/dist/src/drivers/efi.d.ts.map +1 -0
  193. package/dist/src/drivers/efi.js +628 -0
  194. package/dist/src/drivers/efi.js.map +1 -0
  195. package/dist/src/drivers/infinitepay.d.ts +156 -0
  196. package/dist/src/drivers/infinitepay.d.ts.map +1 -0
  197. package/dist/src/drivers/infinitepay.js +321 -0
  198. package/dist/src/drivers/infinitepay.js.map +1 -0
  199. package/dist/src/drivers/lemonsqueezy.d.ts +125 -0
  200. package/dist/src/drivers/lemonsqueezy.d.ts.map +1 -0
  201. package/dist/src/drivers/lemonsqueezy.js +632 -0
  202. package/dist/src/drivers/lemonsqueezy.js.map +1 -0
  203. package/dist/src/drivers/mercadopago.d.ts +97 -0
  204. package/dist/src/drivers/mercadopago.d.ts.map +1 -0
  205. package/dist/src/drivers/mercadopago.js +844 -0
  206. package/dist/src/drivers/mercadopago.js.map +1 -0
  207. package/dist/src/drivers/mollie.d.ts +125 -0
  208. package/dist/src/drivers/mollie.d.ts.map +1 -0
  209. package/dist/src/drivers/mollie.js +812 -0
  210. package/dist/src/drivers/mollie.js.map +1 -0
  211. package/dist/src/drivers/paddle.d.ts +148 -0
  212. package/dist/src/drivers/paddle.d.ts.map +1 -0
  213. package/dist/src/drivers/paddle.js +738 -0
  214. package/dist/src/drivers/paddle.js.map +1 -0
  215. package/dist/src/drivers/pagarme.d.ts +97 -0
  216. package/dist/src/drivers/pagarme.d.ts.map +1 -0
  217. package/dist/src/drivers/pagarme.js +829 -0
  218. package/dist/src/drivers/pagarme.js.map +1 -0
  219. package/dist/src/drivers/pagbank.d.ts +57 -0
  220. package/dist/src/drivers/pagbank.d.ts.map +1 -0
  221. package/dist/src/drivers/pagbank.js +499 -0
  222. package/dist/src/drivers/pagbank.js.map +1 -0
  223. package/dist/src/drivers/paypal.d.ts +120 -0
  224. package/dist/src/drivers/paypal.d.ts.map +1 -0
  225. package/dist/src/drivers/paypal.js +891 -0
  226. package/dist/src/drivers/paypal.js.map +1 -0
  227. package/dist/src/drivers/polar.d.ts +118 -0
  228. package/dist/src/drivers/polar.d.ts.map +1 -0
  229. package/dist/src/drivers/polar.js +604 -0
  230. package/dist/src/drivers/polar.js.map +1 -0
  231. package/dist/src/drivers/razorpay.d.ts +103 -0
  232. package/dist/src/drivers/razorpay.d.ts.map +1 -0
  233. package/dist/src/drivers/razorpay.js +867 -0
  234. package/dist/src/drivers/razorpay.js.map +1 -0
  235. package/dist/src/drivers/shared.d.ts +33 -0
  236. package/dist/src/drivers/shared.d.ts.map +1 -0
  237. package/dist/src/drivers/shared.js +37 -0
  238. package/dist/src/drivers/shared.js.map +1 -0
  239. package/dist/src/drivers/square.d.ts +133 -0
  240. package/dist/src/drivers/square.d.ts.map +1 -0
  241. package/dist/src/drivers/square.js +905 -0
  242. package/dist/src/drivers/square.js.map +1 -0
  243. package/dist/src/drivers/stripe.d.ts +40 -3
  244. package/dist/src/drivers/stripe.d.ts.map +1 -1
  245. package/dist/src/drivers/stripe.js +806 -25
  246. package/dist/src/drivers/stripe.js.map +1 -1
  247. package/dist/src/drivers/woovi.d.ts +10 -3
  248. package/dist/src/drivers/woovi.d.ts.map +1 -1
  249. package/dist/src/drivers/woovi.js +162 -29
  250. package/dist/src/drivers/woovi.js.map +1 -1
  251. package/dist/src/ensure_customer.d.ts +34 -1
  252. package/dist/src/ensure_customer.d.ts.map +1 -1
  253. package/dist/src/ensure_customer.js +29 -4
  254. package/dist/src/ensure_customer.js.map +1 -1
  255. package/dist/src/http.d.ts +37 -3
  256. package/dist/src/http.d.ts.map +1 -1
  257. package/dist/src/http.js +69 -5
  258. package/dist/src/http.js.map +1 -1
  259. package/dist/src/index.d.ts +40 -10
  260. package/dist/src/index.d.ts.map +1 -1
  261. package/dist/src/index.js +22 -4
  262. package/dist/src/index.js.map +1 -1
  263. package/dist/src/invoice/emit_invoice.d.ts.map +1 -1
  264. package/dist/src/invoice/emit_invoice.js +31 -11
  265. package/dist/src/invoice/emit_invoice.js.map +1 -1
  266. package/dist/src/money.d.ts +23 -5
  267. package/dist/src/money.d.ts.map +1 -1
  268. package/dist/src/money.js +72 -7
  269. package/dist/src/money.js.map +1 -1
  270. package/dist/src/payments_manager.d.ts +8 -1
  271. package/dist/src/payments_manager.d.ts.map +1 -1
  272. package/dist/src/payments_manager.js +168 -6
  273. package/dist/src/payments_manager.js.map +1 -1
  274. package/dist/src/services/main.d.ts +38 -0
  275. package/dist/src/services/main.d.ts.map +1 -1
  276. package/dist/src/services/main.js +130 -0
  277. package/dist/src/services/main.js.map +1 -1
  278. package/dist/src/telescope/index.d.ts +2 -0
  279. package/dist/src/telescope/index.d.ts.map +1 -1
  280. package/dist/src/telescope/index.js +1 -0
  281. package/dist/src/telescope/index.js.map +1 -1
  282. package/dist/src/telescope/payments_watcher.d.ts +10 -4
  283. package/dist/src/telescope/payments_watcher.d.ts.map +1 -1
  284. package/dist/src/telescope/payments_watcher.js +65 -13
  285. package/dist/src/telescope/payments_watcher.js.map +1 -1
  286. package/dist/src/telescope/register.d.ts +62 -0
  287. package/dist/src/telescope/register.d.ts.map +1 -0
  288. package/dist/src/telescope/register.js +48 -0
  289. package/dist/src/telescope/register.js.map +1 -0
  290. package/dist/src/testing/fake_payments.d.ts +62 -0
  291. package/dist/src/testing/fake_payments.d.ts.map +1 -0
  292. package/dist/src/testing/fake_payments.js +82 -0
  293. package/dist/src/testing/fake_payments.js.map +1 -0
  294. package/dist/src/testing/in_memory_billing_store.d.ts +151 -2
  295. package/dist/src/testing/in_memory_billing_store.d.ts.map +1 -1
  296. package/dist/src/testing/in_memory_billing_store.js +517 -4
  297. package/dist/src/testing/in_memory_billing_store.js.map +1 -1
  298. package/dist/src/testing/index.d.ts +2 -1
  299. package/dist/src/testing/index.d.ts.map +1 -1
  300. package/dist/src/testing/index.js +1 -0
  301. package/dist/src/testing/index.js.map +1 -1
  302. package/dist/src/types.d.ts +161 -5
  303. package/dist/src/types.d.ts.map +1 -1
  304. package/dist/src/types.js +30 -1
  305. package/dist/src/types.js.map +1 -1
  306. package/dist/src/webhook_handlers.d.ts +96 -2
  307. package/dist/src/webhook_handlers.d.ts.map +1 -1
  308. package/dist/src/webhook_handlers.js +91 -10
  309. package/dist/src/webhook_handlers.js.map +1 -1
  310. package/dist/src/webhook_security.d.ts +94 -3
  311. package/dist/src/webhook_security.d.ts.map +1 -1
  312. package/dist/src/webhook_security.js +173 -9
  313. package/dist/src/webhook_security.js.map +1 -1
  314. package/dist/stubs/config/payments.stub +13 -0
  315. package/dist/stubs/config/payments_client.stub +42 -0
  316. package/dist/stubs/config/payments_dashboard.stub +38 -0
  317. package/dist/stubs/database/migrations/create_billing_tables.stub +35 -77
  318. package/dist/stubs/make/webhook_handler/main.stub +29 -11
  319. package/package.json +60 -25
@@ -0,0 +1,281 @@
1
+ import { type BillingStore } from '../billing/billing_store.js';
2
+ import { BILLING_LIST_DEFAULT_LIMIT } from '../billing/list_query.js';
3
+ import type { RefundAction, ReplayAction } from './actions.js';
4
+ /**
5
+ * Framework-light JSON handlers over a {@link BillingStore}.
6
+ *
7
+ * Each handler takes a {@link Deps} bundle (the store the app already resolved, the display
8
+ * currency, and — for the two write actions — the ports in `actions.ts`) and a plain
9
+ * {@link ApiRequest} (a thin view of the parts of an HTTP request it needs), and returns a plain
10
+ * {@link ApiResponse} (status + JSON body). No AdonisJS types leak in, so the handlers are
11
+ * unit-testable against the real `InMemoryBillingStore` with no HTTP server. The provider adapts
12
+ * an AdonisJS `HttpContext` to these shapes.
13
+ *
14
+ * Mirrors `@adonis-agora/durable`'s `src/dashboard/handlers.ts` convention exactly (`Deps` /
15
+ * `ApiRequest` / `ApiResponse` / `ok` / `notFound` / `badRequest`, reads as `GET`, actions as
16
+ * `POST`), so the two consoles' server halves read the same.
17
+ *
18
+ * This is a MANAGEMENT console, not a debugger: it answers "what needs my attention, which
19
+ * customer is stuck, can I fix it from here". Raw payloads, verification traces and timings are
20
+ * `@adonis-agora/telescope`'s job and are deliberately absent — nothing here returns a stored
21
+ * gateway payload.
22
+ *
23
+ * MONEY: `amount` and `revenue` cross this boundary as integer MINOR UNITS, exactly as they are
24
+ * stored. Nothing here divides — and the divisor is not always 100 (`src/money.ts`'s
25
+ * `currencyExponent`). The SPA formats at render (`src/app/money.ts`).
26
+ */
27
+ /** What the handlers need to answer a request. */
28
+ export interface Deps {
29
+ store: BillingStore;
30
+ /** ISO 4217 code echoed to the client so it knows how to format the minor units it receives. */
31
+ currency: string;
32
+ /** Injectable clock (for the period presets) — defaults to the wall clock. */
33
+ now?: () => Date;
34
+ /**
35
+ * The write actions. Absent (or partially absent) when the app has no reachable
36
+ * `PaymentsManager` — the read endpoints keep working and the action endpoints answer `503`
37
+ * with a sentence saying so, rather than a button that silently does nothing.
38
+ */
39
+ actions?: Partial<DashboardActions>;
40
+ /**
41
+ * WHO is making this request, as the provider's `enforce()` guard already knew them.
42
+ *
43
+ * Per-request, unlike everything else on `Deps`. The guard has verified a signed session
44
+ * carrying a user before any handler runs, and until now it threw that away — so the only
45
+ * record of a refund issued from this console was a diagnostic naming a gateway id, an amount
46
+ * and no person at all. `undefined` on a console with no `dashboardAuth` configured, which is
47
+ * recorded honestly as "unattributed" rather than invented.
48
+ */
49
+ actor?: string;
50
+ }
51
+ /** The two things this console can CHANGE. See `actions.ts`. */
52
+ export interface DashboardActions {
53
+ refund: RefundAction;
54
+ replayWebhook: ReplayAction;
55
+ }
56
+ /** The subset of an HTTP request the handlers read. */
57
+ export interface ApiRequest {
58
+ /** Route params, e.g. `{ gatewayId: 'pi_123' }`. */
59
+ params: Record<string, string | undefined>;
60
+ /** Parsed query string, e.g. `{ status: 'failed', limit: '20' }`. */
61
+ query: Record<string, string | string[] | undefined>;
62
+ /** Parsed JSON body (for the POST actions). */
63
+ body?: unknown;
64
+ }
65
+ /** A plain JSON response: an HTTP status and a serializable body. */
66
+ export interface ApiResponse {
67
+ status: number;
68
+ body: unknown;
69
+ }
70
+ /** A `200 OK` JSON response. Exported so sibling handlers share one convention. */
71
+ export declare const ok: (body: unknown) => ApiResponse;
72
+ /** The statuses the payments filter offers. `status` is a free string in the store (a gateway may
73
+ * send its own), so this is a UI convenience list, not a validation whitelist. Every member of
74
+ * `BillingStatus` is here: `authorized` money can still evaporate and `disputed` money has already
75
+ * been pulled back, and an operator who cannot filter for either cannot see either. */
76
+ export declare const PAYMENT_STATUSES: readonly ["paid", "authorized", "pending", "failed", "refunded", "disputed", "canceled"];
77
+ /** The statuses the disputes filter offers — `DisputeStatus`, ordered the way an operator reads
78
+ * them: what still needs an answer first. `warning` leads because it is the only one where a
79
+ * refund still stops the chargeback from ever being filed. */
80
+ export declare const DISPUTE_STATUSES: readonly ["warning", "open", "under_review", "lost", "expired", "canceled", "won"];
81
+ /** How far ahead `?dueWithin=` looks when the caller asks for closing windows but names no
82
+ * horizon. Matches `billingHealth`'s default, so the panel and the cron agree about "soon". */
83
+ export declare const DISPUTE_DEFAULT_DUE_WITHIN_HOURS = 72;
84
+ /** The ledger's three statuses. `failed` is the one that means "a handler threw and the dispatcher
85
+ * gave up" — i.e. the event's effect never happened. */
86
+ export declare const WEBHOOK_EVENT_STATUSES: readonly ["received", "processed", "failed"];
87
+ /** `SubscriptionStatus`, ordered the way an operator reads them: what needs attention first.
88
+ * `paused` sits apart from `active` deliberately — a paused subscriber is not paying. */
89
+ export declare const SUBSCRIPTION_STATUSES: readonly ["past_due", "paused", "incomplete", "trialing", "active", "canceled", "ended"];
90
+ /** The one status the subscriptions screen opens on: someone's payment failed and the subscription
91
+ * is about to lapse. Everything else can wait until tomorrow. */
92
+ export declare const SUBSCRIPTION_DEFAULT_STATUS = "past_due";
93
+ /**
94
+ * How many rows a provider-filtered page may scan before it gives up and says so.
95
+ *
96
+ * `BillingListQuery` filters on `status` only, so `?provider=` is applied here, over pages read
97
+ * from the store. That is bounded work by construction — but it has to be bounded VISIBLY: a
98
+ * silent "no Asaas payments" that really means "none in the last thousand rows" is the kind of
99
+ * wrong answer an operator acts on. `page.truncated` says which one they are looking at.
100
+ */
101
+ export declare const PROVIDER_SCAN_CAP = 1000;
102
+ /**
103
+ * `GET <api>/overview` — the `billingOverview()` aggregates for a selectable window.
104
+ *
105
+ * Straight passthrough of the headless function this package already ships: revenue (integer
106
+ * minor units), active subscriptions (which INCLUDES `trialing` — see `countActiveSubscriptions`),
107
+ * and one line per metered meter.
108
+ */
109
+ export declare function overview(deps: Deps, req: ApiRequest): Promise<ApiResponse>;
110
+ /**
111
+ * `GET <api>/health` — the three silent failures of a billing install, from `billingHealth()`.
112
+ *
113
+ * This is the endpoint the console opens on. Every other screen answers a question the operator
114
+ * had to think of; this one answers the question they did not: an install where the worker died,
115
+ * or the webhook endpoint stopped being reachable, keeps returning `200` everywhere while revenue
116
+ * quietly stops landing. `failures` names WHICH provider and event type is failing, so the answer
117
+ * is a place to look rather than a number.
118
+ *
119
+ * Nothing here is windowed by the period selector: `billingHealth` has its own thresholds
120
+ * (15 min stuck, 2 h unconfirmed, 24 h of failures) and they are the thresholds `payments:health`
121
+ * alerts on, so the console and the cron agree.
122
+ */
123
+ export declare function health(deps: Deps): Promise<ApiResponse>;
124
+ /**
125
+ * `GET <api>/disputes` — a page of `billing_disputes`.
126
+ *
127
+ * Two modes, because a dispute list has two questions:
128
+ *
129
+ * - default: newest first, `status`/`provider` filters — the log.
130
+ * - `?dueWithin=<hours>`: only OPEN disputes carrying a deadline, soonest window first — the
131
+ * work. Rows already past their deadline stay in it: they are still open and still
132
+ * unanswered, and dropping them the moment they expire would make the panel go quiet at
133
+ * exactly the moment it became urgent.
134
+ *
135
+ * There is still no "accept" and no "fight" button: whether to submit evidence or refund is a
136
+ * business rule (it turns on the fee, the evidence you actually have, and the chargeback ratio
137
+ * that puts a merchant into a card network's monitoring programme), and it stays in the app's
138
+ * code. The one write this screen does have is {@link resolveDispute}, which records an outcome
139
+ * that has ALREADY happened at the gateway — see the note there for why that is not the same
140
+ * thing.
141
+ */
142
+ export declare function disputes(deps: Deps, req: ApiRequest): Promise<ApiResponse>;
143
+ /**
144
+ * `GET <api>/payments` — a page of `billing_payments`, newest first.
145
+ *
146
+ * Filters: `status`, `provider`, and the three that answer "did this one land?" —
147
+ * `reference` (the app's own `externalReference`), `gatewayId`, and `customerId`. All three are
148
+ * EXACT: they are join keys, and a prefix match on `order-4` returning `order-42` is a wrong
149
+ * answer to a question about money.
150
+ */
151
+ export declare function payments(deps: Deps, req: ApiRequest): Promise<ApiResponse>;
152
+ /**
153
+ * `GET <api>/payments/:gatewayId` — everything this system knows about ONE payment.
154
+ *
155
+ * The screen that did not exist, and the honest name for it is "what IS knowable", not "history".
156
+ * `billing_payments` is a single mutable row upserted in place: it has a current state and no
157
+ * past, so "what changed on this payment, and when?" cannot be answered from it and this endpoint
158
+ * does not pretend otherwise. What it assembles instead:
159
+ *
160
+ * - the row's CURRENT state, including `refundedAmount` and the app's own reference;
161
+ * - the app-side OWNER, through `billing_customers`;
162
+ * - every DISPUTE filed against it — that table does carry a real link (`payment_gateway_id`);
163
+ * - the LEDGER rows whose stored delivery names it, newest first. That is a payload substring
164
+ * scan, with everything that implies: it is unindexed, and it can match a delivery that merely
165
+ * mentions the id. `events.matchedBy` says so on the wire rather than in a comment nobody sees.
166
+ * - the AUDIT rows naming it — who refunded it, from this console, and when.
167
+ *
168
+ * The stored payload is still never returned. The timeline says an event ARRIVED and what type it
169
+ * was; what was inside it is telescope's job.
170
+ */
171
+ export declare function paymentDetail(deps: Deps, req: ApiRequest): Promise<ApiResponse>;
172
+ /**
173
+ * `GET <api>/subscriptions` — a page of `billing_subscriptions`, newest first,
174
+ * `status`/`provider` filters.
175
+ *
176
+ * For a subscription business this is the daily surface: `countActiveSubscriptions()` answers "how
177
+ * many", which is the wrong question on any day something is wrong. The operational questions are
178
+ * WHICH subscriptions are `past_due` (someone's card failed and they are about to lose access) and
179
+ * which are `paused` (a subscriber who is not paying and must not be read as active) — and a count
180
+ * cannot name a customer to email.
181
+ */
182
+ export declare function subscriptions(deps: Deps, req: ApiRequest): Promise<ApiResponse>;
183
+ /**
184
+ * `GET <api>/webhook-events` — a page of the idempotency ledger, newest first,
185
+ * `status`/`provider` filters.
186
+ *
187
+ * The `error` column is carried through verbatim: a `failed` row is the only record that a handler
188
+ * threw, and its message is the only place the reason survives. The stored gateway payload is NOT
189
+ * returned — that is a debugging question, and telescope is where it belongs.
190
+ */
191
+ export declare function webhookEvents(deps: Deps, req: ApiRequest): Promise<ApiResponse>;
192
+ /**
193
+ * `GET <api>/customers` — a page of `billing_customers`, newest first.
194
+ *
195
+ * The endpoint that did not exist. `billing_customers` holds `owner_type`/`owner_id`, written by
196
+ * the app itself through `ensureCustomer`, and that mapping is the ONLY thing tying a payment to
197
+ * a person: a payment row carries `cus_…` and nothing else. Without this the console could show
198
+ * every charge in the system and never answer "which of these is user 4102's".
199
+ *
200
+ * Filters: `provider`, `ownerType`, `ownerId`, `gatewayId` — all exact. Pair `ownerType` with
201
+ * `ownerId`: one owner may legitimately hold a customer at every configured gateway, so an id
202
+ * alone is not a key.
203
+ */
204
+ export declare function customers(deps: Deps, req: ApiRequest): Promise<ApiResponse>;
205
+ /** The audit actions the filter offers. A free string in the column, so this is a UI convenience
206
+ * list, not a validation whitelist — an app that records its own actions still sees them. */
207
+ export declare const AUDIT_ACTION_FILTERS: readonly ["webhook.rejected", "payment.refunded", "dispute.resolved"];
208
+ /**
209
+ * `GET <api>/audit` — the trail of things that happened which no other table records.
210
+ *
211
+ * Three kinds of row, and each of them used to be a diagnostic and nothing else:
212
+ *
213
+ * - `webhook.rejected` — a delivery the endpoint REFUSED. This is the one that matters most,
214
+ * because it is otherwise invisible: a rejected delivery never becomes a ledger row, so a
215
+ * rotated webhook secret looks exactly like a quiet week — zero events, zero failures, every
216
+ * check green — while every refund, chargeback and dispute closure is dropped on the floor.
217
+ * - `payment.refunded` — WHO refunded what, from this console. The payment row moves only when
218
+ * the gateway's webhook lands, and that row names no person.
219
+ * - `dispute.resolved` — who closed a dispute the gateway will never close itself.
220
+ *
221
+ * Filters: `action`, `actor`, `provider`, `subjectType`, `subjectId` — all exact.
222
+ */
223
+ export declare function auditEvents(deps: Deps, req: ApiRequest): Promise<ApiResponse>;
224
+ /**
225
+ * `GET <api>/providers` — the gateways this install actually uses, for the provider filter.
226
+ *
227
+ * Driven by the DATA, never by a hardcoded list: this package ships eighteen drivers and an
228
+ * install runs two or three of them, so a static list would offer fifteen filters that return
229
+ * nothing and hide the one that matters behind them. The ledger side is exact
230
+ * (`webhookEventBreakdown` groups the whole table); the payment/subscription side reads the most
231
+ * recent {@link PROVIDER_DISCOVERY_SCAN} rows, which is enough to notice a gateway that is in use.
232
+ */
233
+ export declare function providers(deps: Deps): Promise<ApiResponse>;
234
+ /** The dispute statuses that mean the matter is FINISHED — `DISPUTE_STATUSES` minus the open
235
+ * ones. Only these can be recorded through {@link resolveDispute}: "resolve" that could put a
236
+ * row back into `open` is not a resolution, it is an edit box over a money table. */
237
+ export declare const DISPUTE_RESOLUTION_STATUSES: ("warning" | "open" | "under_review" | "canceled" | "won" | "lost" | "expired")[];
238
+ /**
239
+ * `POST <api>/disputes/:gatewayId/resolve` — record how a dispute ENDED.
240
+ *
241
+ * The one thing this console could not do, and the reason the dispute alarm was permanently red
242
+ * on a real install: Asaas publishes no lost-dispute event at all, and the driver hardcodes
243
+ * `outcome: 'won'` when it closes one — so a dispute that was LOST stays `open` in
244
+ * `billing_disputes` forever. `listDisputesDueWithin` counts past-deadline rows on purpose, so
245
+ * the check stays red, and a fifteen-minute cron logs the same failure until nobody reads it.
246
+ * A gateway that never closes the loop is the NORMAL case here, not the exception.
247
+ *
248
+ * This does not fight, accept or refund anything — nothing here talks to a gateway. It records
249
+ * an outcome that has already happened somewhere else, with the status, the outcome and WHO said
250
+ * so, which is the difference between a resolution and an edit box.
251
+ *
252
+ * Body: `{ status, outcome?, note? }`. `status` must be a finished one
253
+ * ({@link DISPUTE_RESOLUTION_STATUSES}); `outcome` defaults to it.
254
+ */
255
+ export declare function resolveDispute(deps: Deps, req: ApiRequest): Promise<ApiResponse>;
256
+ /**
257
+ * `POST <api>/payments/:gatewayId/refund` — refund a payment through its own gateway.
258
+ *
259
+ * `POST`, never `GET`: a refund reachable by URL is a refund a crawler can trigger. Body is
260
+ * `{ amount?: number }` in integer minor units; omit it for the full amount.
261
+ *
262
+ * The local row is deliberately NOT rewritten here. The gateway confirms a refund with a
263
+ * `payment.refunded` webhook, and that is what moves the row to `refunded` — writing it optimistically
264
+ * would show the operator a refund that may never have settled.
265
+ */
266
+ export declare function refundPayment(deps: Deps, req: ApiRequest): Promise<ApiResponse>;
267
+ /**
268
+ * `POST <api>/webhook-events/:gatewayEventId/retry` — re-run a failed event's handlers.
269
+ *
270
+ * The single most useful thing an operator can do after fixing a handler bug: a `failed` row means
271
+ * the dispatcher gave up, so whatever that event described — a subscription activated, a payment
272
+ * recorded — never happened, and nothing will retry it. Replaying is safe because the ledger
273
+ * re-claims a `failed` event (`recordWebhookEvent` returns it again) while refusing an in-flight or
274
+ * already-processed one, so this can never double-apply a redelivery.
275
+ *
276
+ * `POST`, never `GET`, for the same reason the refund is.
277
+ */
278
+ export declare function retryWebhookEvent(deps: Deps, req: ApiRequest): Promise<ApiResponse>;
279
+ /** Re-exported so the provider and the SPA agree on the default page size without duplicating it. */
280
+ export { BILLING_LIST_DEFAULT_LIMIT };
281
+ //# sourceMappingURL=handlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.d.ts","sourceRoot":"","s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