@antelopejs/dms-saas 0.0.1

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 (687) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +658 -0
  3. package/dist/auth/index.d.ts +3 -0
  4. package/dist/auth/index.js +20 -0
  5. package/dist/auth/index.js.map +1 -0
  6. package/dist/auth/oauth-entry.d.ts +5 -0
  7. package/dist/auth/oauth-entry.js +10 -0
  8. package/dist/auth/oauth-entry.js.map +1 -0
  9. package/dist/auth/plan-permissions-resolver.d.ts +1 -0
  10. package/dist/auth/plan-permissions-resolver.js +44 -0
  11. package/dist/auth/plan-permissions-resolver.js.map +1 -0
  12. package/dist/auth/subscription-access-gate.d.ts +8 -0
  13. package/dist/auth/subscription-access-gate.js +38 -0
  14. package/dist/auth/subscription-access-gate.js.map +1 -0
  15. package/dist/automation/index.d.ts +44 -0
  16. package/dist/automation/index.js +209 -0
  17. package/dist/automation/index.js.map +1 -0
  18. package/dist/billing-state/index.d.ts +5 -0
  19. package/dist/billing-state/index.js +58 -0
  20. package/dist/billing-state/index.js.map +1 -0
  21. package/dist/billing-state/recovery.d.ts +22 -0
  22. package/dist/billing-state/recovery.js +81 -0
  23. package/dist/billing-state/recovery.js.map +1 -0
  24. package/dist/config/dev-mode.d.ts +3 -0
  25. package/dist/config/dev-mode.js +27 -0
  26. package/dist/config/dev-mode.js.map +1 -0
  27. package/dist/config/index.d.ts +2 -0
  28. package/dist/config/index.js +19 -0
  29. package/dist/config/index.js.map +1 -0
  30. package/dist/config/runtime.d.ts +6 -0
  31. package/dist/config/runtime.js +54 -0
  32. package/dist/config/runtime.js.map +1 -0
  33. package/dist/crons/auto-suspend-past-due.d.ts +2 -0
  34. package/dist/crons/auto-suspend-past-due.js +43 -0
  35. package/dist/crons/auto-suspend-past-due.js.map +1 -0
  36. package/dist/crons/cleanup-stripe-webhook-events.d.ts +2 -0
  37. package/dist/crons/cleanup-stripe-webhook-events.js +27 -0
  38. package/dist/crons/cleanup-stripe-webhook-events.js.map +1 -0
  39. package/dist/crons/expire-free-workspaces.d.ts +2 -0
  40. package/dist/crons/expire-free-workspaces.js +36 -0
  41. package/dist/crons/expire-free-workspaces.js.map +1 -0
  42. package/dist/crons/hard-delete-cancelled.d.ts +2 -0
  43. package/dist/crons/hard-delete-cancelled.js +55 -0
  44. package/dist/crons/hard-delete-cancelled.js.map +1 -0
  45. package/dist/crons/index.d.ts +8 -0
  46. package/dist/crons/index.js +25 -0
  47. package/dist/crons/index.js.map +1 -0
  48. package/dist/crons/notify-free-workspaces-ending-soon.d.ts +2 -0
  49. package/dist/crons/notify-free-workspaces-ending-soon.js +69 -0
  50. package/dist/crons/notify-free-workspaces-ending-soon.js.map +1 -0
  51. package/dist/crons/recompute-billing-state.d.ts +2 -0
  52. package/dist/crons/recompute-billing-state.js +19 -0
  53. package/dist/crons/recompute-billing-state.js.map +1 -0
  54. package/dist/crons/recompute-segments.d.ts +2 -0
  55. package/dist/crons/recompute-segments.js +19 -0
  56. package/dist/crons/recompute-segments.js.map +1 -0
  57. package/dist/crons/reconcile-workspace-lifecycle.d.ts +2 -0
  58. package/dist/crons/reconcile-workspace-lifecycle.js +19 -0
  59. package/dist/crons/reconcile-workspace-lifecycle.js.map +1 -0
  60. package/dist/crons/register.d.ts +2 -0
  61. package/dist/crons/register.js +24 -0
  62. package/dist/crons/register.js.map +1 -0
  63. package/dist/crons/subscription-notifications.d.ts +2 -0
  64. package/dist/crons/subscription-notifications.js +55 -0
  65. package/dist/crons/subscription-notifications.js.map +1 -0
  66. package/dist/data-api/index.d.ts +2 -0
  67. package/dist/data-api/index.js +19 -0
  68. package/dist/data-api/index.js.map +1 -0
  69. package/dist/data-api/platformOwner/admin-user-invoices.d.ts +27 -0
  70. package/dist/data-api/platformOwner/admin-user-invoices.js +158 -0
  71. package/dist/data-api/platformOwner/admin-user-invoices.js.map +1 -0
  72. package/dist/data-api/platformOwner/admin-user-workspaces.d.ts +22 -0
  73. package/dist/data-api/platformOwner/admin-user-workspaces.js +97 -0
  74. package/dist/data-api/platformOwner/admin-user-workspaces.js.map +1 -0
  75. package/dist/data-api/platformOwner/credit-notes.d.ts +24 -0
  76. package/dist/data-api/platformOwner/credit-notes.js +133 -0
  77. package/dist/data-api/platformOwner/credit-notes.js.map +1 -0
  78. package/dist/data-api/platformOwner/features.d.ts +30 -0
  79. package/dist/data-api/platformOwner/features.js +141 -0
  80. package/dist/data-api/platformOwner/features.js.map +1 -0
  81. package/dist/data-api/platformOwner/hidden-filter.d.ts +1 -0
  82. package/dist/data-api/platformOwner/hidden-filter.js +18 -0
  83. package/dist/data-api/platformOwner/hidden-filter.js.map +1 -0
  84. package/dist/data-api/platformOwner/index.d.ts +12 -0
  85. package/dist/data-api/platformOwner/index.js +29 -0
  86. package/dist/data-api/platformOwner/index.js.map +1 -0
  87. package/dist/data-api/platformOwner/invoice-options.d.ts +7 -0
  88. package/dist/data-api/platformOwner/invoice-options.js +14 -0
  89. package/dist/data-api/platformOwner/invoice-options.js.map +1 -0
  90. package/dist/data-api/platformOwner/invoices.d.ts +26 -0
  91. package/dist/data-api/platformOwner/invoices.js +147 -0
  92. package/dist/data-api/platformOwner/invoices.js.map +1 -0
  93. package/dist/data-api/platformOwner/members.d.ts +24 -0
  94. package/dist/data-api/platformOwner/members.js +125 -0
  95. package/dist/data-api/platformOwner/members.js.map +1 -0
  96. package/dist/data-api/platformOwner/plan-migrations.d.ts +24 -0
  97. package/dist/data-api/platformOwner/plan-migrations.js +138 -0
  98. package/dist/data-api/platformOwner/plan-migrations.js.map +1 -0
  99. package/dist/data-api/platformOwner/plans.d.ts +30 -0
  100. package/dist/data-api/platformOwner/plans.js +228 -0
  101. package/dist/data-api/platformOwner/plans.js.map +1 -0
  102. package/dist/data-api/platformOwner/segments.d.ts +29 -0
  103. package/dist/data-api/platformOwner/segments.js +223 -0
  104. package/dist/data-api/platformOwner/segments.js.map +1 -0
  105. package/dist/data-api/platformOwner/support.d.ts +58 -0
  106. package/dist/data-api/platformOwner/support.js +111 -0
  107. package/dist/data-api/platformOwner/support.js.map +1 -0
  108. package/dist/data-api/platformOwner/users.d.ts +22 -0
  109. package/dist/data-api/platformOwner/users.js +128 -0
  110. package/dist/data-api/platformOwner/users.js.map +1 -0
  111. package/dist/data-api/platformOwner/workspaces.d.ts +22 -0
  112. package/dist/data-api/platformOwner/workspaces.js +153 -0
  113. package/dist/data-api/platformOwner/workspaces.js.map +1 -0
  114. package/dist/data-api/support-fields.d.ts +49 -0
  115. package/dist/data-api/support-fields.js +166 -0
  116. package/dist/data-api/support-fields.js.map +1 -0
  117. package/dist/data-api/support-routes.d.ts +10 -0
  118. package/dist/data-api/support-routes.js +71 -0
  119. package/dist/data-api/support-routes.js.map +1 -0
  120. package/dist/data-api/tenant/index.d.ts +2 -0
  121. package/dist/data-api/tenant/index.js +19 -0
  122. package/dist/data-api/tenant/index.js.map +1 -0
  123. package/dist/data-api/tenant/support.d.ts +39 -0
  124. package/dist/data-api/tenant/support.js +53 -0
  125. package/dist/data-api/tenant/support.js.map +1 -0
  126. package/dist/data-api/tenant/tenant-invoices.d.ts +37 -0
  127. package/dist/data-api/tenant/tenant-invoices.js +242 -0
  128. package/dist/data-api/tenant/tenant-invoices.js.map +1 -0
  129. package/dist/db/index.d.ts +1 -0
  130. package/dist/db/index.js +18 -0
  131. package/dist/db/index.js.map +1 -0
  132. package/dist/hooks/index.d.ts +3 -0
  133. package/dist/hooks/index.js +20 -0
  134. package/dist/hooks/index.js.map +1 -0
  135. package/dist/hooks/register.d.ts +1 -0
  136. package/dist/hooks/register.js +57 -0
  137. package/dist/hooks/register.js.map +1 -0
  138. package/dist/hooks/tenant-export.d.ts +2 -0
  139. package/dist/hooks/tenant-export.js +64 -0
  140. package/dist/hooks/tenant-export.js.map +1 -0
  141. package/dist/hooks/tenant-provisioning.d.ts +3 -0
  142. package/dist/hooks/tenant-provisioning.js +12 -0
  143. package/dist/hooks/tenant-provisioning.js.map +1 -0
  144. package/dist/implementations/dms-saas/billing.d.ts +2 -0
  145. package/dist/implementations/dms-saas/billing.js +49 -0
  146. package/dist/implementations/dms-saas/billing.js.map +1 -0
  147. package/dist/implementations/dms-saas/invoice-line-items.d.ts +11 -0
  148. package/dist/implementations/dms-saas/invoice-line-items.js +24 -0
  149. package/dist/implementations/dms-saas/invoice-line-items.js.map +1 -0
  150. package/dist/implementations/dms-saas/pages.d.ts +3 -0
  151. package/dist/implementations/dms-saas/pages.js +12 -0
  152. package/dist/implementations/dms-saas/pages.js.map +1 -0
  153. package/dist/implementations/dms-saas/workspace-lifecycle.d.ts +2 -0
  154. package/dist/implementations/dms-saas/workspace-lifecycle.js +23 -0
  155. package/dist/implementations/dms-saas/workspace-lifecycle.js.map +1 -0
  156. package/dist/index.d.ts +8 -0
  157. package/dist/index.js +107 -0
  158. package/dist/index.js.map +1 -0
  159. package/dist/invoice-line-items/billing-window.d.ts +3 -0
  160. package/dist/invoice-line-items/billing-window.js +19 -0
  161. package/dist/invoice-line-items/billing-window.js.map +1 -0
  162. package/dist/invoice-line-items/index.d.ts +1 -0
  163. package/dist/invoice-line-items/index.js +18 -0
  164. package/dist/invoice-line-items/index.js.map +1 -0
  165. package/dist/invoice-line-items/injection.d.ts +2 -0
  166. package/dist/invoice-line-items/injection.js +171 -0
  167. package/dist/invoice-line-items/injection.js.map +1 -0
  168. package/dist/notifications/index.d.ts +2 -0
  169. package/dist/notifications/index.js +19 -0
  170. package/dist/notifications/index.js.map +1 -0
  171. package/dist/notifications/recipients.d.ts +14 -0
  172. package/dist/notifications/recipients.js +87 -0
  173. package/dist/notifications/recipients.js.map +1 -0
  174. package/dist/notifications/subjects.d.ts +21 -0
  175. package/dist/notifications/subjects.js +121 -0
  176. package/dist/notifications/subjects.js.map +1 -0
  177. package/dist/operator-actions/commands.d.ts +41 -0
  178. package/dist/operator-actions/commands.js +233 -0
  179. package/dist/operator-actions/commands.js.map +1 -0
  180. package/dist/operator-actions/db/index.d.ts +4 -0
  181. package/dist/operator-actions/db/index.js +21 -0
  182. package/dist/operator-actions/db/index.js.map +1 -0
  183. package/dist/operator-actions/db/lifecycle-delivery.model.d.ts +29 -0
  184. package/dist/operator-actions/db/lifecycle-delivery.model.js +85 -0
  185. package/dist/operator-actions/db/lifecycle-delivery.model.js.map +1 -0
  186. package/dist/operator-actions/db/lifecycle-delivery.table.d.ts +26 -0
  187. package/dist/operator-actions/db/lifecycle-delivery.table.js +107 -0
  188. package/dist/operator-actions/db/lifecycle-delivery.table.js.map +1 -0
  189. package/dist/operator-actions/db/operator-action.model.d.ts +33 -0
  190. package/dist/operator-actions/db/operator-action.model.js +63 -0
  191. package/dist/operator-actions/db/operator-action.model.js.map +1 -0
  192. package/dist/operator-actions/db/operator-action.table.d.ts +21 -0
  193. package/dist/operator-actions/db/operator-action.table.js +95 -0
  194. package/dist/operator-actions/db/operator-action.table.js.map +1 -0
  195. package/dist/operator-actions/index.d.ts +3 -0
  196. package/dist/operator-actions/index.js +20 -0
  197. package/dist/operator-actions/index.js.map +1 -0
  198. package/dist/operator-actions/journal.d.ts +22 -0
  199. package/dist/operator-actions/journal.js +183 -0
  200. package/dist/operator-actions/journal.js.map +1 -0
  201. package/dist/operator-actions/lifecycle-consumers.d.ts +12 -0
  202. package/dist/operator-actions/lifecycle-consumers.js +28 -0
  203. package/dist/operator-actions/lifecycle-consumers.js.map +1 -0
  204. package/dist/operator-actions/lifecycle-outbox.d.ts +19 -0
  205. package/dist/operator-actions/lifecycle-outbox.js +229 -0
  206. package/dist/operator-actions/lifecycle-outbox.js.map +1 -0
  207. package/dist/operator-actions/types.d.ts +11 -0
  208. package/dist/operator-actions/types.js +3 -0
  209. package/dist/operator-actions/types.js.map +1 -0
  210. package/dist/pages/definitions.d.ts +1 -0
  211. package/dist/pages/definitions.js +18 -0
  212. package/dist/pages/definitions.js.map +1 -0
  213. package/dist/pages/index.d.ts +4 -0
  214. package/dist/pages/index.js +21 -0
  215. package/dist/pages/index.js.map +1 -0
  216. package/dist/pages/module.d.ts +5 -0
  217. package/dist/pages/module.js +15 -0
  218. package/dist/pages/module.js.map +1 -0
  219. package/dist/pages/platform/categories.d.ts +6 -0
  220. package/dist/pages/platform/categories.js +48 -0
  221. package/dist/pages/platform/categories.js.map +1 -0
  222. package/dist/pages/platform/credit-notes.d.ts +9 -0
  223. package/dist/pages/platform/credit-notes.js +40 -0
  224. package/dist/pages/platform/credit-notes.js.map +1 -0
  225. package/dist/pages/platform/dashboard.d.ts +10 -0
  226. package/dist/pages/platform/dashboard.js +95 -0
  227. package/dist/pages/platform/dashboard.js.map +1 -0
  228. package/dist/pages/platform/features.d.ts +9 -0
  229. package/dist/pages/platform/features.js +42 -0
  230. package/dist/pages/platform/features.js.map +1 -0
  231. package/dist/pages/platform/index.d.ts +15 -0
  232. package/dist/pages/platform/index.js +32 -0
  233. package/dist/pages/platform/index.js.map +1 -0
  234. package/dist/pages/platform/invoices.d.ts +9 -0
  235. package/dist/pages/platform/invoices.js +63 -0
  236. package/dist/pages/platform/invoices.js.map +1 -0
  237. package/dist/pages/platform/plans/edit.d.ts +17 -0
  238. package/dist/pages/platform/plans/edit.js +213 -0
  239. package/dist/pages/platform/plans/edit.js.map +1 -0
  240. package/dist/pages/platform/plans/index.d.ts +9 -0
  241. package/dist/pages/platform/plans/index.js +99 -0
  242. package/dist/pages/platform/plans/index.js.map +1 -0
  243. package/dist/pages/platform/plans/migrations.d.ts +9 -0
  244. package/dist/pages/platform/plans/migrations.js +38 -0
  245. package/dist/pages/platform/plans/migrations.js.map +1 -0
  246. package/dist/pages/platform/segments/index.d.ts +9 -0
  247. package/dist/pages/platform/segments/index.js +59 -0
  248. package/dist/pages/platform/segments/index.js.map +1 -0
  249. package/dist/pages/platform/settings.d.ts +9 -0
  250. package/dist/pages/platform/settings.js +147 -0
  251. package/dist/pages/platform/settings.js.map +1 -0
  252. package/dist/pages/platform/support.d.ts +9 -0
  253. package/dist/pages/platform/support.js +29 -0
  254. package/dist/pages/platform/support.js.map +1 -0
  255. package/dist/pages/platform/users/detail.d.ts +9 -0
  256. package/dist/pages/platform/users/detail.js +78 -0
  257. package/dist/pages/platform/users/detail.js.map +1 -0
  258. package/dist/pages/platform/users/index.d.ts +9 -0
  259. package/dist/pages/platform/users/index.js +77 -0
  260. package/dist/pages/platform/users/index.js.map +1 -0
  261. package/dist/pages/platform/workspaces/detail.d.ts +9 -0
  262. package/dist/pages/platform/workspaces/detail.js +120 -0
  263. package/dist/pages/platform/workspaces/detail.js.map +1 -0
  264. package/dist/pages/platform/workspaces/index.d.ts +35 -0
  265. package/dist/pages/platform/workspaces/index.js +300 -0
  266. package/dist/pages/platform/workspaces/index.js.map +1 -0
  267. package/dist/pages/public/auth/index.d.ts +1 -0
  268. package/dist/pages/public/auth/index.js +18 -0
  269. package/dist/pages/public/auth/index.js.map +1 -0
  270. package/dist/pages/public/auth/no-workspace.d.ts +9 -0
  271. package/dist/pages/public/auth/no-workspace.js +26 -0
  272. package/dist/pages/public/auth/no-workspace.js.map +1 -0
  273. package/dist/pages/public/index.d.ts +3 -0
  274. package/dist/pages/public/index.js +20 -0
  275. package/dist/pages/public/index.js.map +1 -0
  276. package/dist/pages/public/legal/index.d.ts +3 -0
  277. package/dist/pages/public/legal/index.js +20 -0
  278. package/dist/pages/public/legal/index.js.map +1 -0
  279. package/dist/pages/public/legal/privacy-policy.d.ts +9 -0
  280. package/dist/pages/public/legal/privacy-policy.js +29 -0
  281. package/dist/pages/public/legal/privacy-policy.js.map +1 -0
  282. package/dist/pages/public/legal/terms-and-conditions.d.ts +9 -0
  283. package/dist/pages/public/legal/terms-and-conditions.js +29 -0
  284. package/dist/pages/public/legal/terms-and-conditions.js.map +1 -0
  285. package/dist/pages/public/legal/terms-of-use.d.ts +9 -0
  286. package/dist/pages/public/legal/terms-of-use.js +29 -0
  287. package/dist/pages/public/legal/terms-of-use.js.map +1 -0
  288. package/dist/pages/public/register.d.ts +9 -0
  289. package/dist/pages/public/register.js +29 -0
  290. package/dist/pages/public/register.js.map +1 -0
  291. package/dist/pages/public/screens.d.ts +3 -0
  292. package/dist/pages/public/screens.js +50 -0
  293. package/dist/pages/public/screens.js.map +1 -0
  294. package/dist/pages/tenant/billing.d.ts +15 -0
  295. package/dist/pages/tenant/billing.js +87 -0
  296. package/dist/pages/tenant/billing.js.map +1 -0
  297. package/dist/pages/tenant/data-export.d.ts +10 -0
  298. package/dist/pages/tenant/data-export.js +32 -0
  299. package/dist/pages/tenant/data-export.js.map +1 -0
  300. package/dist/pages/tenant/general.d.ts +10 -0
  301. package/dist/pages/tenant/general.js +33 -0
  302. package/dist/pages/tenant/general.js.map +1 -0
  303. package/dist/pages/tenant/index.d.ts +6 -0
  304. package/dist/pages/tenant/index.js +23 -0
  305. package/dist/pages/tenant/index.js.map +1 -0
  306. package/dist/pages/tenant/members-seat-quota.d.ts +3 -0
  307. package/dist/pages/tenant/members-seat-quota.js +25 -0
  308. package/dist/pages/tenant/members-seat-quota.js.map +1 -0
  309. package/dist/pages/tenant/support.d.ts +9 -0
  310. package/dist/pages/tenant/support.js +27 -0
  311. package/dist/pages/tenant/support.js.map +1 -0
  312. package/dist/pages/tenant/workspace-suspended.d.ts +9 -0
  313. package/dist/pages/tenant/workspace-suspended.js +26 -0
  314. package/dist/pages/tenant/workspace-suspended.js.map +1 -0
  315. package/dist/plan-changes/deferred.d.ts +18 -0
  316. package/dist/plan-changes/deferred.js +225 -0
  317. package/dist/plan-changes/deferred.js.map +1 -0
  318. package/dist/plan-changes/index.d.ts +1 -0
  319. package/dist/plan-changes/index.js +18 -0
  320. package/dist/plan-changes/index.js.map +1 -0
  321. package/dist/plans/index.d.ts +4 -0
  322. package/dist/plans/index.js +21 -0
  323. package/dist/plans/index.js.map +1 -0
  324. package/dist/plans/seat-capacity.d.ts +9 -0
  325. package/dist/plans/seat-capacity.js +38 -0
  326. package/dist/plans/seat-capacity.js.map +1 -0
  327. package/dist/plans/seat-hooks.d.ts +1 -0
  328. package/dist/plans/seat-hooks.js +80 -0
  329. package/dist/plans/seat-hooks.js.map +1 -0
  330. package/dist/plans/seat-sync.d.ts +10 -0
  331. package/dist/plans/seat-sync.js +23 -0
  332. package/dist/plans/seat-sync.js.map +1 -0
  333. package/dist/routes/index.d.ts +3 -0
  334. package/dist/routes/index.js +20 -0
  335. package/dist/routes/index.js.map +1 -0
  336. package/dist/routes/platformOwner/billing-settings.d.ts +20 -0
  337. package/dist/routes/platformOwner/billing-settings.js +98 -0
  338. package/dist/routes/platformOwner/billing-settings.js.map +1 -0
  339. package/dist/routes/platformOwner/credit-notes-issue.d.ts +16 -0
  340. package/dist/routes/platformOwner/credit-notes-issue.js +56 -0
  341. package/dist/routes/platformOwner/credit-notes-issue.js.map +1 -0
  342. package/dist/routes/platformOwner/dashboard.d.ts +62 -0
  343. package/dist/routes/platformOwner/dashboard.js +310 -0
  344. package/dist/routes/platformOwner/dashboard.js.map +1 -0
  345. package/dist/routes/platformOwner/index.d.ts +12 -0
  346. package/dist/routes/platformOwner/index.js +29 -0
  347. package/dist/routes/platformOwner/index.js.map +1 -0
  348. package/dist/routes/platformOwner/plan-deletion.d.ts +30 -0
  349. package/dist/routes/platformOwner/plan-deletion.js +156 -0
  350. package/dist/routes/platformOwner/plan-deletion.js.map +1 -0
  351. package/dist/routes/platformOwner/plans.d.ts +99 -0
  352. package/dist/routes/platformOwner/plans.js +376 -0
  353. package/dist/routes/platformOwner/plans.js.map +1 -0
  354. package/dist/routes/platformOwner/platform-notes.d.ts +36 -0
  355. package/dist/routes/platformOwner/platform-notes.js +149 -0
  356. package/dist/routes/platformOwner/platform-notes.js.map +1 -0
  357. package/dist/routes/platformOwner/platform-owners.d.ts +12 -0
  358. package/dist/routes/platformOwner/platform-owners.js +77 -0
  359. package/dist/routes/platformOwner/platform-owners.js.map +1 -0
  360. package/dist/routes/platformOwner/segments.d.ts +24 -0
  361. package/dist/routes/platformOwner/segments.js +174 -0
  362. package/dist/routes/platformOwner/segments.js.map +1 -0
  363. package/dist/routes/platformOwner/support.d.ts +21 -0
  364. package/dist/routes/platformOwner/support.js +180 -0
  365. package/dist/routes/platformOwner/support.js.map +1 -0
  366. package/dist/routes/platformOwner/users-detail.d.ts +26 -0
  367. package/dist/routes/platformOwner/users-detail.js +82 -0
  368. package/dist/routes/platformOwner/users-detail.js.map +1 -0
  369. package/dist/routes/platformOwner/workspace-operator-actions.d.ts +34 -0
  370. package/dist/routes/platformOwner/workspace-operator-actions.js +183 -0
  371. package/dist/routes/platformOwner/workspace-operator-actions.js.map +1 -0
  372. package/dist/routes/platformOwner/workspaces-admin.d.ts +27 -0
  373. package/dist/routes/platformOwner/workspaces-admin.js +140 -0
  374. package/dist/routes/platformOwner/workspaces-admin.js.map +1 -0
  375. package/dist/routes/public/index.d.ts +3 -0
  376. package/dist/routes/public/index.js +20 -0
  377. package/dist/routes/public/index.js.map +1 -0
  378. package/dist/routes/public/legal-documents.d.ts +15 -0
  379. package/dist/routes/public/legal-documents.js +72 -0
  380. package/dist/routes/public/legal-documents.js.map +1 -0
  381. package/dist/routes/public/register.d.ts +48 -0
  382. package/dist/routes/public/register.js +193 -0
  383. package/dist/routes/public/register.js.map +1 -0
  384. package/dist/routes/public/webhooks/index.d.ts +1 -0
  385. package/dist/routes/public/webhooks/index.js +18 -0
  386. package/dist/routes/public/webhooks/index.js.map +1 -0
  387. package/dist/routes/public/webhooks/stripe.d.ts +7 -0
  388. package/dist/routes/public/webhooks/stripe.js +41 -0
  389. package/dist/routes/public/webhooks/stripe.js.map +1 -0
  390. package/dist/routes/tenant/billing-portal.d.ts +31 -0
  391. package/dist/routes/tenant/billing-portal.js +117 -0
  392. package/dist/routes/tenant/billing-portal.js.map +1 -0
  393. package/dist/routes/tenant/billing-self-refund.d.ts +18 -0
  394. package/dist/routes/tenant/billing-self-refund.js +199 -0
  395. package/dist/routes/tenant/billing-self-refund.js.map +1 -0
  396. package/dist/routes/tenant/data-export.d.ts +16 -0
  397. package/dist/routes/tenant/data-export.js +102 -0
  398. package/dist/routes/tenant/data-export.js.map +1 -0
  399. package/dist/routes/tenant/index.d.ts +9 -0
  400. package/dist/routes/tenant/index.js +26 -0
  401. package/dist/routes/tenant/index.js.map +1 -0
  402. package/dist/routes/tenant/support.d.ts +27 -0
  403. package/dist/routes/tenant/support.js +185 -0
  404. package/dist/routes/tenant/support.js.map +1 -0
  405. package/dist/routes/tenant/tenant-billing.d.ts +26 -0
  406. package/dist/routes/tenant/tenant-billing.js +148 -0
  407. package/dist/routes/tenant/tenant-billing.js.map +1 -0
  408. package/dist/routes/tenant/tenant-plan-ops.d.ts +57 -0
  409. package/dist/routes/tenant/tenant-plan-ops.js +244 -0
  410. package/dist/routes/tenant/tenant-plan-ops.js.map +1 -0
  411. package/dist/routes/tenant/tenant-plan.d.ts +19 -0
  412. package/dist/routes/tenant/tenant-plan.js +172 -0
  413. package/dist/routes/tenant/tenant-plan.js.map +1 -0
  414. package/dist/routes/tenant/tenant-seats.d.ts +17 -0
  415. package/dist/routes/tenant/tenant-seats.js +58 -0
  416. package/dist/routes/tenant/tenant-seats.js.map +1 -0
  417. package/dist/routes/tenant/workspaces.d.ts +78 -0
  418. package/dist/routes/tenant/workspaces.js +301 -0
  419. package/dist/routes/tenant/workspaces.js.map +1 -0
  420. package/dist/stripe/client.d.ts +6 -0
  421. package/dist/stripe/client.js +44 -0
  422. package/dist/stripe/client.js.map +1 -0
  423. package/dist/stripe/customer-balance.d.ts +12 -0
  424. package/dist/stripe/customer-balance.js +16 -0
  425. package/dist/stripe/customer-balance.js.map +1 -0
  426. package/dist/stripe/customer-billing.d.ts +33 -0
  427. package/dist/stripe/customer-billing.js +140 -0
  428. package/dist/stripe/customer-billing.js.map +1 -0
  429. package/dist/stripe/index.d.ts +11 -0
  430. package/dist/stripe/index.js +28 -0
  431. package/dist/stripe/index.js.map +1 -0
  432. package/dist/stripe/plan-schedule.d.ts +9 -0
  433. package/dist/stripe/plan-schedule.js +83 -0
  434. package/dist/stripe/plan-schedule.js.map +1 -0
  435. package/dist/stripe/proration.d.ts +2 -0
  436. package/dist/stripe/proration.js +19 -0
  437. package/dist/stripe/proration.js.map +1 -0
  438. package/dist/stripe/sync-plan.d.ts +2 -0
  439. package/dist/stripe/sync-plan.js +66 -0
  440. package/dist/stripe/sync-plan.js.map +1 -0
  441. package/dist/stripe/webhook-checkout.d.ts +3 -0
  442. package/dist/stripe/webhook-checkout.js +157 -0
  443. package/dist/stripe/webhook-checkout.js.map +1 -0
  444. package/dist/stripe/webhook-credit-notes.d.ts +3 -0
  445. package/dist/stripe/webhook-credit-notes.js +192 -0
  446. package/dist/stripe/webhook-credit-notes.js.map +1 -0
  447. package/dist/stripe/webhook-dispatch.d.ts +2 -0
  448. package/dist/stripe/webhook-dispatch.js +45 -0
  449. package/dist/stripe/webhook-dispatch.js.map +1 -0
  450. package/dist/stripe/webhook-handlers.d.ts +11 -0
  451. package/dist/stripe/webhook-handlers.js +318 -0
  452. package/dist/stripe/webhook-handlers.js.map +1 -0
  453. package/dist/stripe/webhook-shared.d.ts +28 -0
  454. package/dist/stripe/webhook-shared.js +126 -0
  455. package/dist/stripe/webhook-shared.js.map +1 -0
  456. package/dist/stripe/workspace-checkout.d.ts +29 -0
  457. package/dist/stripe/workspace-checkout.js +106 -0
  458. package/dist/stripe/workspace-checkout.js.map +1 -0
  459. package/dist/support/admissions.d.ts +36 -0
  460. package/dist/support/admissions.js +136 -0
  461. package/dist/support/admissions.js.map +1 -0
  462. package/dist/support/attachments.d.ts +12 -0
  463. package/dist/support/attachments.js +56 -0
  464. package/dist/support/attachments.js.map +1 -0
  465. package/dist/support/config.d.ts +19 -0
  466. package/dist/support/config.js +75 -0
  467. package/dist/support/config.js.map +1 -0
  468. package/dist/support/index.d.ts +6 -0
  469. package/dist/support/index.js +23 -0
  470. package/dist/support/index.js.map +1 -0
  471. package/dist/support/operations.d.ts +51 -0
  472. package/dist/support/operations.js +109 -0
  473. package/dist/support/operations.js.map +1 -0
  474. package/dist/support/plans.d.ts +6 -0
  475. package/dist/support/plans.js +130 -0
  476. package/dist/support/plans.js.map +1 -0
  477. package/dist/support/publications.d.ts +8 -0
  478. package/dist/support/publications.js +106 -0
  479. package/dist/support/publications.js.map +1 -0
  480. package/dist/support/recovery.d.ts +7 -0
  481. package/dist/support/recovery.js +43 -0
  482. package/dist/support/recovery.js.map +1 -0
  483. package/dist/support/service.d.ts +51 -0
  484. package/dist/support/service.js +143 -0
  485. package/dist/support/service.js.map +1 -0
  486. package/dist/support/transitions.d.ts +4 -0
  487. package/dist/support/transitions.js +29 -0
  488. package/dist/support/transitions.js.map +1 -0
  489. package/dist/support/uploads.d.ts +39 -0
  490. package/dist/support/uploads.js +115 -0
  491. package/dist/support/uploads.js.map +1 -0
  492. package/dist/support/validation.d.ts +15 -0
  493. package/dist/support/validation.js +54 -0
  494. package/dist/support/validation.js.map +1 -0
  495. package/dist/types/config.d.ts +16 -0
  496. package/dist/types/config.js +3 -0
  497. package/dist/types/config.js.map +1 -0
  498. package/dist/types/index.d.ts +1 -0
  499. package/dist/types/index.js +18 -0
  500. package/dist/types/index.js.map +1 -0
  501. package/dist/utils/billing-document-type.d.ts +3 -0
  502. package/dist/utils/billing-document-type.js +18 -0
  503. package/dist/utils/billing-document-type.js.map +1 -0
  504. package/dist/utils/billing-period-type.d.ts +3 -0
  505. package/dist/utils/billing-period-type.js +18 -0
  506. package/dist/utils/billing-period-type.js.map +1 -0
  507. package/dist/utils/email-hash.d.ts +1 -0
  508. package/dist/utils/email-hash.js +8 -0
  509. package/dist/utils/email-hash.js.map +1 -0
  510. package/dist/utils/export-dataset-stream.d.ts +19 -0
  511. package/dist/utils/export-dataset-stream.js +40 -0
  512. package/dist/utils/export-dataset-stream.js.map +1 -0
  513. package/dist/utils/index.d.ts +15 -0
  514. package/dist/utils/index.js +32 -0
  515. package/dist/utils/index.js.map +1 -0
  516. package/dist/utils/invoice-lines-type.d.ts +27 -0
  517. package/dist/utils/invoice-lines-type.js +34 -0
  518. package/dist/utils/invoice-lines-type.js.map +1 -0
  519. package/dist/utils/money-cents-type.d.ts +3 -0
  520. package/dist/utils/money-cents-type.js +18 -0
  521. package/dist/utils/money-cents-type.js.map +1 -0
  522. package/dist/utils/pagination.d.ts +22 -0
  523. package/dist/utils/pagination.js +35 -0
  524. package/dist/utils/pagination.js.map +1 -0
  525. package/dist/utils/parse-future-date.d.ts +1 -0
  526. package/dist/utils/parse-future-date.js +15 -0
  527. package/dist/utils/parse-future-date.js.map +1 -0
  528. package/dist/utils/row-instance.d.ts +1 -0
  529. package/dist/utils/row-instance.js +8 -0
  530. package/dist/utils/row-instance.js.map +1 -0
  531. package/dist/utils/segment-conditions-type.d.ts +33 -0
  532. package/dist/utils/segment-conditions-type.js +86 -0
  533. package/dist/utils/segment-conditions-type.js.map +1 -0
  534. package/dist/utils/segment-evaluator.d.ts +3 -0
  535. package/dist/utils/segment-evaluator.js +117 -0
  536. package/dist/utils/segment-evaluator.js.map +1 -0
  537. package/dist/utils/segment-fields.d.ts +19 -0
  538. package/dist/utils/segment-fields.js +212 -0
  539. package/dist/utils/segment-fields.js.map +1 -0
  540. package/dist/utils/segment-matching.d.ts +56 -0
  541. package/dist/utils/segment-matching.js +200 -0
  542. package/dist/utils/segment-matching.js.map +1 -0
  543. package/dist/utils/segment-name-cache.d.ts +2 -0
  544. package/dist/utils/segment-name-cache.js +22 -0
  545. package/dist/utils/segment-name-cache.js.map +1 -0
  546. package/dist/utils/time.d.ts +3 -0
  547. package/dist/utils/time.js +10 -0
  548. package/dist/utils/time.js.map +1 -0
  549. package/dist/workers/index.d.ts +1 -0
  550. package/dist/workers/index.js +18 -0
  551. package/dist/workers/index.js.map +1 -0
  552. package/dist/workers/plan-migration.d.ts +4 -0
  553. package/dist/workers/plan-migration.js +206 -0
  554. package/dist/workers/plan-migration.js.map +1 -0
  555. package/dist/workspaces/billing-profile.d.ts +3 -0
  556. package/dist/workspaces/billing-profile.js +55 -0
  557. package/dist/workspaces/billing-profile.js.map +1 -0
  558. package/dist/workspaces/complimentary.d.ts +7 -0
  559. package/dist/workspaces/complimentary.js +47 -0
  560. package/dist/workspaces/complimentary.js.map +1 -0
  561. package/dist/workspaces/db/card-capacity.model.d.ts +30 -0
  562. package/dist/workspaces/db/card-capacity.model.js +98 -0
  563. package/dist/workspaces/db/card-capacity.model.js.map +1 -0
  564. package/dist/workspaces/db/card-capacity.table.d.ts +11 -0
  565. package/dist/workspaces/db/card-capacity.table.js +34 -0
  566. package/dist/workspaces/db/card-capacity.table.js.map +1 -0
  567. package/dist/workspaces/db/provisioning-attempt.model.d.ts +24 -0
  568. package/dist/workspaces/db/provisioning-attempt.model.js +33 -0
  569. package/dist/workspaces/db/provisioning-attempt.model.js.map +1 -0
  570. package/dist/workspaces/db/provisioning-attempt.table.d.ts +18 -0
  571. package/dist/workspaces/db/provisioning-attempt.table.js +77 -0
  572. package/dist/workspaces/db/provisioning-attempt.table.js.map +1 -0
  573. package/dist/workspaces/db/trial-identity.model.d.ts +25 -0
  574. package/dist/workspaces/db/trial-identity.model.js +62 -0
  575. package/dist/workspaces/db/trial-identity.model.js.map +1 -0
  576. package/dist/workspaces/db/trial-identity.table.d.ts +7 -0
  577. package/dist/workspaces/db/trial-identity.table.js +34 -0
  578. package/dist/workspaces/db/trial-identity.table.js.map +1 -0
  579. package/dist/workspaces/deletion.d.ts +8 -0
  580. package/dist/workspaces/deletion.js +75 -0
  581. package/dist/workspaces/deletion.js.map +1 -0
  582. package/dist/workspaces/free-workspace-guard.d.ts +11 -0
  583. package/dist/workspaces/free-workspace-guard.js +96 -0
  584. package/dist/workspaces/free-workspace-guard.js.map +1 -0
  585. package/dist/workspaces/index.d.ts +6 -0
  586. package/dist/workspaces/index.js +23 -0
  587. package/dist/workspaces/index.js.map +1 -0
  588. package/dist/workspaces/provisioning-rollback.d.ts +2 -0
  589. package/dist/workspaces/provisioning-rollback.js +78 -0
  590. package/dist/workspaces/provisioning-rollback.js.map +1 -0
  591. package/dist/workspaces/provisioning-state.d.ts +6 -0
  592. package/dist/workspaces/provisioning-state.js +91 -0
  593. package/dist/workspaces/provisioning-state.js.map +1 -0
  594. package/dist/workspaces/provisioning.d.ts +49 -0
  595. package/dist/workspaces/provisioning.js +263 -0
  596. package/dist/workspaces/provisioning.js.map +1 -0
  597. package/dist/workspaces/registration-extras.d.ts +1 -0
  598. package/dist/workspaces/registration-extras.js +50 -0
  599. package/dist/workspaces/registration-extras.js.map +1 -0
  600. package/dist/workspaces/suspension.d.ts +13 -0
  601. package/dist/workspaces/suspension.js +124 -0
  602. package/dist/workspaces/suspension.js.map +1 -0
  603. package/frontend-vue/.editorconfig +12 -0
  604. package/frontend-vue/.prettierrc +11 -0
  605. package/frontend-vue/app/build/.gitkeep +0 -0
  606. package/frontend-vue/app/components/CardGrid.vue +77 -0
  607. package/frontend-vue/app/components/CustomerPortalButton.vue +45 -0
  608. package/frontend-vue/app/components/DataExport.vue +300 -0
  609. package/frontend-vue/app/components/DeletePlanModal.vue +223 -0
  610. package/frontend-vue/app/components/FreeAccessBanner.vue +70 -0
  611. package/frontend-vue/app/components/InvoiceLines.vue +57 -0
  612. package/frontend-vue/app/components/IssueCreditNoteModal.vue +128 -0
  613. package/frontend-vue/app/components/LegalLayout.vue +63 -0
  614. package/frontend-vue/app/components/LoadFailure.vue +25 -0
  615. package/frontend-vue/app/components/PastDueAlert.vue +96 -0
  616. package/frontend-vue/app/components/PaymentMethodCard.vue +86 -0
  617. package/frontend-vue/app/components/PlanCard.vue +294 -0
  618. package/frontend-vue/app/components/PlanCardPublic.vue +59 -0
  619. package/frontend-vue/app/components/PlanCardsDisplay.vue +127 -0
  620. package/frontend-vue/app/components/PlanComparisonModal.vue +213 -0
  621. package/frontend-vue/app/components/PlanInheritancePicker.vue +329 -0
  622. package/frontend-vue/app/components/PlatformNotes.vue +281 -0
  623. package/frontend-vue/app/components/PlatformSupport.vue +461 -0
  624. package/frontend-vue/app/components/RecentActivity.vue +72 -0
  625. package/frontend-vue/app/components/RefundButton.vue +126 -0
  626. package/frontend-vue/app/components/Register.vue +174 -0
  627. package/frontend-vue/app/components/RegistrationClosed.vue +15 -0
  628. package/frontend-vue/app/components/SeatQuotaBanner.vue +78 -0
  629. package/frontend-vue/app/components/SegmentConditionsBuilder.vue +176 -0
  630. package/frontend-vue/app/components/SegmentConditionsGroup.vue +494 -0
  631. package/frontend-vue/app/components/SupportAttachmentUpload.vue +140 -0
  632. package/frontend-vue/app/components/SupportThreadHistory.vue +139 -0
  633. package/frontend-vue/app/components/TenantBillingForm.vue +208 -0
  634. package/frontend-vue/app/components/TenantPlanCard.vue +223 -0
  635. package/frontend-vue/app/components/TenantSupport.vue +415 -0
  636. package/frontend-vue/app/components/UserSummaryCard.vue +166 -0
  637. package/frontend-vue/app/components/WorkspaceBillingInfo.vue +68 -0
  638. package/frontend-vue/app/components/WorkspaceCompAccessButton.vue +198 -0
  639. package/frontend-vue/app/components/WorkspaceCreateModal.vue +256 -0
  640. package/frontend-vue/app/components/WorkspaceDangerZone.vue +146 -0
  641. package/frontend-vue/app/components/WorkspaceDetailHeader.vue +24 -0
  642. package/frontend-vue/app/components/WorkspaceIdentity.vue +99 -0
  643. package/frontend-vue/app/components/WorkspaceJoinButton.vue +50 -0
  644. package/frontend-vue/app/components/WorkspaceOperatorActions.vue +340 -0
  645. package/frontend-vue/app/components/WorkspaceSummaryCard.vue +161 -0
  646. package/frontend-vue/app/components/WorkspaceSuspendButton.vue +167 -0
  647. package/frontend-vue/app/components/WorkspaceSuspended.vue +164 -0
  648. package/frontend-vue/app/components/WorkspaceSwitcherWidget.vue +247 -0
  649. package/frontend-vue/app/composables/useApiErrorMessage.ts +35 -0
  650. package/frontend-vue/app/composables/useBillingCountries.ts +54 -0
  651. package/frontend-vue/app/composables/useBillingDocumentType.ts +7 -0
  652. package/frontend-vue/app/composables/useBillingStatus.ts +39 -0
  653. package/frontend-vue/app/composables/useCurrentWorkspace.ts +43 -0
  654. package/frontend-vue/app/composables/useDetailRefresh.ts +17 -0
  655. package/frontend-vue/app/composables/useExportHistory.ts +143 -0
  656. package/frontend-vue/app/composables/useInvoiceLines.ts +22 -0
  657. package/frontend-vue/app/composables/useMoneyFormat.ts +49 -0
  658. package/frontend-vue/app/composables/useMyWorkspaces.ts +47 -0
  659. package/frontend-vue/app/composables/usePlanFeatureFormat.ts +60 -0
  660. package/frontend-vue/app/composables/usePlanIntervalLabel.ts +30 -0
  661. package/frontend-vue/app/composables/useSaasRegistration.ts +522 -0
  662. package/frontend-vue/app/composables/useSeatQuota.ts +18 -0
  663. package/frontend-vue/app/composables/useSharedRequest.ts +54 -0
  664. package/frontend-vue/app/composables/useStripePaymentElement.ts +74 -0
  665. package/frontend-vue/app/composables/useSubscriptionAccess.ts +12 -0
  666. package/frontend-vue/app/composables/useSupportRequest.ts +74 -0
  667. package/frontend-vue/app/composables/useTenantPlan.ts +95 -0
  668. package/frontend-vue/app/composables/useTenantSwitch.ts +22 -0
  669. package/frontend-vue/app/composables/useWorkspaceAccessCache.ts +25 -0
  670. package/frontend-vue/app/custom-pages/auth/no-workspace.vue +495 -0
  671. package/frontend-vue/app/middleware/workspace-suspended.global.ts +56 -0
  672. package/frontend-vue/app/plugins/auth-links.ts +24 -0
  673. package/frontend-vue/app/plugins/billing-data-types.ts +62 -0
  674. package/frontend-vue/app/plugins/footer-links.ts +36 -0
  675. package/frontend-vue/app/plugins/plan-cards-display.client.ts +16 -0
  676. package/frontend-vue/app/plugins/segment-conditions-data-type.client.ts +122 -0
  677. package/frontend-vue/app/plugins/sidebar-widgets.ts +13 -0
  678. package/frontend-vue/app/types/support.ts +123 -0
  679. package/frontend-vue/dms.frontend.ts +68 -0
  680. package/frontend-vue/eslint.config.mjs +13 -0
  681. package/frontend-vue/i18n/locales/saas-en-GB.json +1285 -0
  682. package/frontend-vue/i18n/locales/saas-fr-FR.json +1285 -0
  683. package/frontend-vue/package.json +27 -0
  684. package/frontend-vue/pnpm-lock.yaml +4948 -0
  685. package/frontend-vue/pnpm-workspace.yaml +2 -0
  686. package/frontend-vue/server/routes/auth/finalize-workspace.post.ts +61 -0
  687. package/package.json +91 -0
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scheduleSubscriptionDowngrade = scheduleSubscriptionDowngrade;
4
+ exports.releaseSubscriptionSchedule = releaseSubscriptionSchedule;
5
+ exports.setSubscriptionCancelAtPeriodEnd = setSubscriptionCancelAtPeriodEnd;
6
+ exports.resetSubscriptionPendingState = resetSubscriptionPendingState;
7
+ const time_1 = require("../utils/time");
8
+ const client_1 = require("./client");
9
+ const RELEASE_END_BEHAVIOR = "release";
10
+ const NEW_PHASE_ITERATIONS = 1;
11
+ function toPriceId(price) {
12
+ return typeof price === "string" ? price : price.id;
13
+ }
14
+ function toPhaseItemParam(item) {
15
+ return { price: toPriceId(item.price), quantity: item.quantity };
16
+ }
17
+ function toCurrentPhaseParam(phase) {
18
+ return {
19
+ items: phase.items.map(toPhaseItemParam),
20
+ start_date: phase.start_date,
21
+ end_date: phase.end_date,
22
+ automatic_tax: { enabled: true },
23
+ };
24
+ }
25
+ async function scheduleSubscriptionDowngrade(input) {
26
+ const stripe = (0, client_1.getStripeClient)();
27
+ const created = await stripe.subscriptionSchedules.create({
28
+ from_subscription: input.stripeSubscriptionId,
29
+ });
30
+ const currentPhase = created.phases[0];
31
+ if (!currentPhase)
32
+ return null;
33
+ await stripe.subscriptionSchedules.update(created.id, {
34
+ end_behavior: RELEASE_END_BEHAVIOR,
35
+ phases: [
36
+ toCurrentPhaseParam(currentPhase),
37
+ {
38
+ items: [{ price: input.stripePriceId, quantity: input.quantity }],
39
+ iterations: NEW_PHASE_ITERATIONS,
40
+ automatic_tax: { enabled: true },
41
+ },
42
+ ],
43
+ });
44
+ return (0, time_1.stripeSecondsToDate)(currentPhase.end_date);
45
+ }
46
+ const INERT_SCHEDULE_STATUSES = new Set(["released", "canceled", "completed"]);
47
+ async function releaseSubscriptionSchedule(scheduleId) {
48
+ const stripe = (0, client_1.getStripeClient)();
49
+ try {
50
+ await stripe.subscriptionSchedules.release(scheduleId);
51
+ }
52
+ catch (error) {
53
+ const schedule = await stripe.subscriptionSchedules
54
+ .retrieve(scheduleId)
55
+ .catch(() => null);
56
+ if (schedule && INERT_SCHEDULE_STATUSES.has(schedule.status))
57
+ return;
58
+ throw error;
59
+ }
60
+ }
61
+ async function setSubscriptionCancelAtPeriodEnd(stripeSubscriptionId, cancelAtPeriodEnd) {
62
+ const stripe = (0, client_1.getStripeClient)();
63
+ const updated = await stripe.subscriptions.update(stripeSubscriptionId, {
64
+ cancel_at_period_end: cancelAtPeriodEnd,
65
+ });
66
+ return (0, time_1.stripeSecondsToDate)(updated.current_period_end);
67
+ }
68
+ function toScheduleId(schedule) {
69
+ if (typeof schedule === "string")
70
+ return schedule;
71
+ return schedule?.id ?? null;
72
+ }
73
+ async function resetSubscriptionPendingState(stripeSubscriptionId) {
74
+ const stripe = (0, client_1.getStripeClient)();
75
+ const subscription = await stripe.subscriptions.retrieve(stripeSubscriptionId);
76
+ const scheduleId = toScheduleId(subscription.schedule);
77
+ if (scheduleId)
78
+ await releaseSubscriptionSchedule(scheduleId);
79
+ if (subscription.cancel_at_period_end) {
80
+ await setSubscriptionCancelAtPeriodEnd(stripeSubscriptionId, false);
81
+ }
82
+ }
83
+ //# sourceMappingURL=plan-schedule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plan-schedule.js","sourceRoot":"","sources":["../../src/stripe/plan-schedule.ts"],"names":[],"mappings":";;AA0CA,sEAyBC;AAUD,kEAaC;AAED,4EASC;AAgBD,sEAWC;AA/HD,wCAAoD;AACpD,qCAA2C;AAE3C,MAAM,oBAAoB,GAAG,SAAkB,CAAC;AAChD,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAQ/B,SAAS,SAAS,CAChB,KAAkD;IAElD,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;AACtD,CAAC;AAED,SAAS,gBAAgB,CACvB,IAA4C;IAE5C,OAAO,EAAE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I,UAAU;QAAE,MAAM,2BAA2B,CAAC,UAAU,CAAC,CAAC;IAC9D,IAAI,YAAY,CAAC,oBAAoB,EAAE,CAAC;QACtC,MAAM,gCAAgC,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;IACtE,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function nowInStripeSeconds(): number;
2
+ export declare function computeUnusedPortionCents(amountCents: number, periodStartSeconds: number | null | undefined, periodEndSeconds: number | null | undefined, nowSeconds: number): number;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nowInStripeSeconds = nowInStripeSeconds;
4
+ exports.computeUnusedPortionCents = computeUnusedPortionCents;
5
+ const MS_PER_SECOND = 1000;
6
+ function nowInStripeSeconds() {
7
+ return Math.floor(Date.now() / MS_PER_SECOND);
8
+ }
9
+ function computeUnusedPortionCents(amountCents, periodStartSeconds, periodEndSeconds, nowSeconds) {
10
+ if (!periodStartSeconds ||
11
+ !periodEndSeconds ||
12
+ periodEndSeconds <= periodStartSeconds) {
13
+ return 0;
14
+ }
15
+ const remainingSeconds = Math.max(0, periodEndSeconds - nowSeconds);
16
+ const totalSeconds = periodEndSeconds - periodStartSeconds;
17
+ return Math.floor(amountCents * (remainingSeconds / totalSeconds));
18
+ }
19
+ //# sourceMappingURL=proration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proration.js","sourceRoot":"","sources":["../../src/stripe/proration.ts"],"names":[],"mappings":";;AAEA,gDAEC;AAED,8DAgBC;AAtBD,MAAM,aAAa,GAAG,IAAI,CAAC;AAE3B,SAAgB,kBAAkB;IAChC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,aAAa,CAAC,CAAC;AAChD,CAAC;AAED,SAAgB,yBAAyB,CACvC,WAAmB,EACnB,kBAA6C,EAC7C,gBAA2C,EAC3C,UAAkB;IAElB,IACE,CAAC,kBAAkB;QACnB,CAAC,gBAAgB;QACjB,gBAAgB,IAAI,kBAAkB,EACtC,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC;IACD,MAAM,gBAAgB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,gBAAgB,GAAG,UAAU,CAAC,CAAC;IACpE,MAAM,YAAY,GAAG,gBAAgB,GAAG,kBAAkB,CAAC;IAC3D,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,CAAC,gBAAgB,GAAG,YAAY,CAAC,CAAC,CAAC;AACrE,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { Plan } from "../db";
2
+ export declare function syncPlanWithStripe(plan: Plan): Promise<Plan>;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.syncPlanWithStripe = syncPlanWithStripe;
4
+ const interface_database_decorators_1 = require("@antelopejs/interface-database-decorators");
5
+ const db_1 = require("../db");
6
+ const client_1 = require("./client");
7
+ const PRICE_MULTIPLIER = 100;
8
+ const SEAT_USAGE_TYPE = "licensed";
9
+ const PRICE_TAX_BEHAVIOR = "exclusive";
10
+ async function resolveProductTaxCode() {
11
+ const billingSettingsModel = (0, interface_database_decorators_1.GetModel)(db_1.BillingSettingsModel);
12
+ const settings = await billingSettingsModel.get(db_1.BILLING_SETTINGS_SINGLETON_ID);
13
+ return settings?.stripeTaxCode || db_1.DEFAULT_STRIPE_TAX_CODE;
14
+ }
15
+ function buildRecurring(plan) {
16
+ const recurring = {
17
+ interval: plan.interval,
18
+ };
19
+ if (plan.billingMode === "seat") {
20
+ recurring.usage_type = SEAT_USAGE_TYPE;
21
+ }
22
+ return recurring;
23
+ }
24
+ async function ensureProduct(plan, refs, taxCode) {
25
+ const stripe = (0, client_1.getStripeClient)();
26
+ if (!refs.stripeProductId) {
27
+ const product = await stripe.products.create({
28
+ name: plan.name,
29
+ description: plan.description,
30
+ tax_code: taxCode,
31
+ metadata: { planId: plan._id },
32
+ });
33
+ return product.id;
34
+ }
35
+ await stripe.products.update(refs.stripeProductId, {
36
+ name: plan.name,
37
+ description: plan.description,
38
+ tax_code: taxCode,
39
+ });
40
+ return refs.stripeProductId;
41
+ }
42
+ async function archivePreviousPrice(refs) {
43
+ if (!refs.stripePriceId)
44
+ return;
45
+ const stripe = (0, client_1.getStripeClient)();
46
+ await stripe.prices.update(refs.stripePriceId, { active: false });
47
+ }
48
+ async function syncPlanWithStripe(plan) {
49
+ const refs = { ...plan.paymentProviderRefs };
50
+ const taxCode = await resolveProductTaxCode();
51
+ const productId = await ensureProduct(plan, refs, taxCode);
52
+ refs.stripeProductId = productId;
53
+ const stripe = (0, client_1.getStripeClient)();
54
+ const newPrice = await stripe.prices.create({
55
+ product: productId,
56
+ unit_amount: Math.round(plan.price * PRICE_MULTIPLIER),
57
+ currency: plan.currency.toLowerCase(),
58
+ recurring: buildRecurring(plan),
59
+ tax_behavior: PRICE_TAX_BEHAVIOR,
60
+ metadata: { planId: plan._id, billingMode: plan.billingMode },
61
+ });
62
+ await archivePreviousPrice(refs);
63
+ refs.stripePriceId = newPrice.id;
64
+ return { ...plan, paymentProviderRefs: refs };
65
+ }
66
+ //# sourceMappingURL=sync-plan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-plan.js","sourceRoot":"","sources":["../../src/stripe/sync-plan.ts"],"names":[],"mappings":";;AA6DA,gDAwBC;AArFD,6FAAqE;AAGrE,8BAIe;AACf,qCAA2C;AAE3C,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,eAAe,GAAG,UAAmB,CAAC;AAC5C,MAAM,kBAAkB,GAAG,WAAoB,CAAC;AAEhD,KAAK,UAAU,qBAAqB;IAClC,MAAM,oBAAoB,GAAG,IAAA,wCAAQ,EAAC,yBAAoB,CAAC,CAAC;IAC5D,MAAM,QAAQ,GAAG,MAAM,oBAAoB,CAAC,GAAG,CAC7C,kCAA6B,CAC9B,CAAC;IACF,OAAO,QAAQ,EAAE,aAAa,IAAI,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AAK,UAAU,kBAAkB,CAAC,IAAU;IACjD,MAAM,IAAI,GAAqB,EAAE,GAAG,IAAI,CAAC,mBAAmB,EAAE,CAAC;IAC/D,MAAM,OAAO,GAAG,MAAM,qBAAqB,EAAE,CAAC;IAC9C,MAAM,SAAS,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC3D,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;IAEjC,MAAM,MAAM,GAAG,IAAA,wBAAe,GAAE,CAAC;IACjC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;QAC1C,OAAO,EAAE,SAAS;QAClB,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,gBAAgB,CAAC;QACtD,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE;QACrC,SAAS,EAAE,cAAc,CAAC,IAAI,CAAC;QAC/B,YAAY,EAAE,kBAAkB;QAChC,QAAQ,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE;KAC9D,CAAC,CAAC;IAEH,MAAM,oBAAoB,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,CAAC,aAAa,GAAG,QAAQ,CAAC,EAAE,CAAC;IAMjC,OAAO,EAAE,GAAG,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,CAAC;AAChD,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type Stripe from "stripe";
2
+ export declare function handleCheckoutSessionCompleted(event: Stripe.Event): Promise<void>;
3
+ export declare function handleCheckoutSessionExpired(event: Stripe.Event): Promise<void>;
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleCheckoutSessionCompleted = handleCheckoutSessionCompleted;
4
+ exports.handleCheckoutSessionExpired = handleCheckoutSessionExpired;
5
+ const interface_database_decorators_1 = require("@antelopejs/interface-database-decorators");
6
+ const tenant_lifecycle_1 = require("@antelopejs/interface-dms/tenant-lifecycle");
7
+ const automation_1 = require("../automation");
8
+ const billing_state_1 = require("../billing-state");
9
+ const db_1 = require("../db");
10
+ const utils_1 = require("../utils");
11
+ const complimentary_1 = require("../workspaces/complimentary");
12
+ const client_1 = require("./client");
13
+ const webhook_shared_1 = require("./webhook-shared");
14
+ async function promoteSubscriptionPaymentMethod(subscription) {
15
+ const customerId = (0, webhook_shared_1.asCustomerId)(subscription.customer);
16
+ const paymentMethodId = typeof subscription.default_payment_method === "string"
17
+ ? subscription.default_payment_method
18
+ : (subscription.default_payment_method?.id ?? null);
19
+ if (!customerId || !paymentMethodId)
20
+ return;
21
+ const stripe = (0, client_1.getStripeClient)();
22
+ await stripe.customers.update(customerId, {
23
+ invoice_settings: { default_payment_method: paymentMethodId },
24
+ });
25
+ }
26
+ async function admitCheckoutCompletion(context, existing) {
27
+ if (existing.completedCheckoutSessionId === context.session.id)
28
+ return false;
29
+ if (existing.stripeCheckoutSessionId !== context.session.id)
30
+ throw new Error("Checkout session is not current");
31
+ if (existing.deletionStartedAt)
32
+ throw new Error("Workspace deletion has started");
33
+ const pending = existing.domainTransition;
34
+ if (pending &&
35
+ (pending.kind !== "checkout" ||
36
+ pending.operationId !== context.session.metadata?.operationId ||
37
+ pending.targetPlanId !== context.targetPlanId))
38
+ throw new Error("Checkout completion requires reconciliation");
39
+ const intent = {
40
+ operationId: pending?.operationId ?? `checkout-complete:${context.session.id}`,
41
+ kind: "change_plan",
42
+ targetPlanId: context.targetPlanId,
43
+ requestedAt: pending?.requestedAt ?? new Date(),
44
+ };
45
+ const outcome = await (0, interface_database_decorators_1.GetModel)(db_1.TenantSubscriptionModel, context.tenantId).mutateRevision(existing, { domainTransition: intent });
46
+ if (outcome !== "applied")
47
+ throw new Error(`Checkout completion ${outcome}; reconciliation required`);
48
+ existing.domainTransition = intent;
49
+ return true;
50
+ }
51
+ function resolveCheckoutContext(event) {
52
+ const session = event.data.object;
53
+ if (session.mode !== "subscription")
54
+ return null;
55
+ const tenantId = typeof session.metadata?.tenantId === "string"
56
+ ? session.metadata.tenantId
57
+ : null;
58
+ const subscriptionId = typeof session.subscription === "string"
59
+ ? session.subscription
60
+ : (session.subscription?.id ?? null);
61
+ if (!tenantId || !subscriptionId)
62
+ return null;
63
+ const targetPlanId = typeof session.metadata?.planId === "string"
64
+ ? session.metadata.planId
65
+ : null;
66
+ return { session, tenantId, subscriptionId, targetPlanId };
67
+ }
68
+ async function mirrorCheckoutSubscription(context, subscription, existing, status) {
69
+ const patch = {
70
+ ...(0, complimentary_1.activatePaidUsage)(existing, context.subscriptionId, (0, utils_1.stripeSecondsToDate)(subscription.start_date) ?? new Date()),
71
+ status,
72
+ stripeSubscriptionId: context.subscriptionId,
73
+ currentPeriodEnd: (0, utils_1.stripeSecondsToDate)(subscription.current_period_end),
74
+ updatedAt: new Date(),
75
+ };
76
+ if (context.targetPlanId)
77
+ patch.planId = context.targetPlanId;
78
+ const model = (0, interface_database_decorators_1.GetModel)(db_1.TenantSubscriptionModel, context.tenantId);
79
+ await model.updateDuringTransition(existing._id, existing.domainTransition.operationId, patch);
80
+ await (0, billing_state_1.recomputeTenantBillingState)(context.tenantId);
81
+ }
82
+ async function completeCheckout(context) {
83
+ const existing = await (0, interface_database_decorators_1.GetModel)(db_1.TenantSubscriptionModel, context.tenantId).findOne();
84
+ const previousTransition = existing?.domainTransition;
85
+ if (!existing || !(await admitCheckoutCompletion(context, existing)))
86
+ return;
87
+ const subscription = await retrieveActivatedCheckout(context, existing, previousTransition);
88
+ const status = subscription.status === "trialing" ? webhook_shared_1.TRIALING_STATUS : webhook_shared_1.ACTIVE_STATUS;
89
+ await mirrorCheckoutSubscription(context, subscription, existing, status);
90
+ await promoteSubscriptionPaymentMethod(subscription);
91
+ const planId = context.targetPlanId ?? existing.planId;
92
+ const trialConsumptionRecorded = subscription.status === "trialing" &&
93
+ (await recordCheckoutTrialConsumption(context.session, existing.createdBy, planId));
94
+ await (0, interface_database_decorators_1.GetModel)(db_1.TenantSubscriptionModel, context.tenantId).completeTransition(existing._id, existing.domainTransition.operationId, { completedCheckoutSessionId: context.session.id });
95
+ (0, automation_1.emitAutomationEvent)("saas.subscription-started", {
96
+ tenantId: context.tenantId,
97
+ planId,
98
+ status,
99
+ stripeSubscriptionId: context.subscriptionId,
100
+ trialConsumptionRecorded,
101
+ at: new Date().toISOString(),
102
+ });
103
+ }
104
+ async function retrieveActivatedCheckout(context, existing, previousTransition) {
105
+ const subscription = await (0, client_1.getStripeClient)().subscriptions.retrieve(context.subscriptionId);
106
+ if (subscription.status === webhook_shared_1.ACTIVE_STATUS ||
107
+ subscription.status === webhook_shared_1.TRIALING_STATUS)
108
+ return subscription;
109
+ await (0, interface_database_decorators_1.GetModel)(db_1.TenantSubscriptionModel, context.tenantId).updateDuringTransition(existing._id, existing.domainTransition.operationId, { domainTransition: previousTransition ?? null });
110
+ throw new Error("Checkout subscription has not activated");
111
+ }
112
+ async function handleCheckoutSessionCompleted(event) {
113
+ const context = resolveCheckoutContext(event);
114
+ if (!context)
115
+ return;
116
+ await (0, tenant_lifecycle_1.runTenantLifecycleOperation)(context.tenantId, () => completeCheckout(context));
117
+ }
118
+ async function handleCheckoutSessionExpired(event) {
119
+ const session = event.data.object;
120
+ const tenantId = session.metadata?.tenantId;
121
+ if (!tenantId || session.status !== "expired")
122
+ return;
123
+ const model = (0, interface_database_decorators_1.GetModel)(db_1.TenantSubscriptionModel, tenantId);
124
+ const current = await model.findOne();
125
+ if (current?.stripeCheckoutSessionId !== session.id ||
126
+ current.domainTransition?.kind !== "checkout")
127
+ return;
128
+ if (current.domainTransition.operationId !== session.metadata?.operationId)
129
+ throw new Error("Checkout expiration identity mismatch");
130
+ const outcome = await model.mutateRevision(current, {
131
+ domainTransition: null,
132
+ stripeCheckoutSessionId: null,
133
+ });
134
+ if (outcome !== "applied")
135
+ throw new Error(`Checkout expiration ${outcome}; reconciliation required`);
136
+ }
137
+ async function recordCheckoutTrialConsumption(session, createdBy, planId) {
138
+ const email = session.customer_details?.email;
139
+ if (!email || !createdBy || !planId)
140
+ return false;
141
+ const emailHash = (0, utils_1.hashEmail)(email);
142
+ const trialConsumptionModel = (0, interface_database_decorators_1.GetModel)(db_1.TrialConsumptionModel);
143
+ if (await trialConsumptionModel.existsForIdentity(emailHash, null)) {
144
+ return true;
145
+ }
146
+ await trialConsumptionModel.insert([
147
+ {
148
+ userId: createdBy,
149
+ emailHash,
150
+ paymentFingerprint: null,
151
+ planId,
152
+ consumedAt: new Date(),
153
+ },
154
+ ]);
155
+ return true;
156
+ }
157
+ //# sourceMappingURL=webhook-checkout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook-checkout.js","sourceRoot":"","sources":["../../src/stripe/webhook-checkout.ts"],"names":[],"mappings":";;AAmMA,wEAQC;AAGD,oEAqBC;AAhOD,6FAAqE;AACrE,iFAAyF;AAEzF,8CAAoD;AACpD,oDAA+D;AAM/D,8BAAuE;AACvE,oCAAgF;AAChF,+DAAgE;AAChE,qCAA2C;AAC3C,qDAAgF;AAEhF,KAAK,UAAU,gCAAgC,CAC7C,YAAiC;IAEjC,MAAM,UAAU,GAAG,IAAA,6BAAY,EAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IACvD,MAAM,eAAe,GACnB,OAAO,YAAY,CAAC,sBAAsB,KAAK,QAAQ;QACrD,CAAC,CAAC,YAAY,CAAC,sBAAsB;QACrC,CAAC,CAAC,CAAC,YAAY,CAAC,sBAAsB,EAAE,EAAE,IAAI,IAAI,CAAC,CAAC;IACxD,IAAI,CAAC,UAAU,IAAI,CAAC,eAAe;QAAE,OAAO;IAC5C,MAAM,MAAM,GAAG,IAAA,wBAAe,GAAE,CAAC;IAIjC,MAAM,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,EAAE;QACxC,gBAAgB,EAAE,EAAE,sBAAsB,EAAE,eAAe,EAAE;KAC9D,CAAC,CA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;IACnC,MAAM,qBAAqB,GAAG,IAAA,wCAAQ,EAAC,0BAAqB,CAAC,CAAC;IAG9D,IAAI,MAAM,qBAAqB,CAAC,iBAAiB,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC;QACnE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,qBAAqB,CAAC,MAAM,CAAC;QACjC;YACE,MAAM,EAAE,SAAS;YACjB,SAAS;YACT,kBAAkB,EAAE,IAAI;YACxB,MAAM;YACN,UAAU,EAAE,IAAI,IAAI,EAAE;SACvB;KACF,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type Stripe from "stripe";
2
+ export declare function handleCreditNoteCreated(event: Stripe.Event): Promise<void>;
3
+ export declare function handleCreditNoteVoided(event: Stripe.Event): Promise<void>;
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleCreditNoteCreated = handleCreditNoteCreated;
4
+ exports.handleCreditNoteVoided = handleCreditNoteVoided;
5
+ const interface_database_decorators_1 = require("@antelopejs/interface-database-decorators");
6
+ const db_1 = require("../db");
7
+ const notifications_1 = require("../notifications");
8
+ const utils_1 = require("../utils");
9
+ const client_1 = require("./client");
10
+ const webhook_shared_1 = require("./webhook-shared");
11
+ const CREDIT_NOTE_ICON = "i-ph-receipt";
12
+ function resolveCreditNoteInvoiceId(creditNote) {
13
+ if (typeof creditNote.invoice === "string")
14
+ return creditNote.invoice;
15
+ return creditNote.invoice?.id ?? null;
16
+ }
17
+ function resolveCreditNoteRefundId(creditNote) {
18
+ if (typeof creditNote.refund === "string")
19
+ return creditNote.refund;
20
+ return creditNote.refund?.id ?? null;
21
+ }
22
+ function toCreditNoteLine(line, currency) {
23
+ return {
24
+ description: line.description ?? "",
25
+ quantity: line.quantity,
26
+ amount: -line.amount,
27
+ currency,
28
+ periodStart: null,
29
+ periodEnd: null,
30
+ };
31
+ }
32
+ async function resolveCreditNoteLines(creditNote) {
33
+ if (!creditNote.lines.has_more) {
34
+ return creditNote.lines.data.map((line) => toCreditNoteLine(line, creditNote.currency));
35
+ }
36
+ const lines = (0, client_1.getStripeClient)().creditNotes.listLineItems(creditNote.id, {
37
+ limit: webhook_shared_1.INVOICE_LINES_PAGE_SIZE,
38
+ });
39
+ const allLines = [];
40
+ await lines.autoPagingEach((line) => {
41
+ allLines.push(toCreditNoteLine(line, creditNote.currency));
42
+ });
43
+ return allLines;
44
+ }
45
+ function resolveCreditNoteType(creditNote) {
46
+ return creditNote.type;
47
+ }
48
+ function resolveCreditNoteTax(creditNote) {
49
+ const lineTax = creditNote.tax_amounts.reduce((total, taxAmount) => total + taxAmount.amount, 0);
50
+ return lineTax + (creditNote.shipping_cost?.amount_tax ?? 0);
51
+ }
52
+ function buildCreditNotePayload(creditNote, invoiceRowId) {
53
+ const creditNoteStatus = creditNote.status === "void" ? "void" : "issued";
54
+ return {
55
+ invoiceId: invoiceRowId,
56
+ stripeCreditNoteId: creditNote.id,
57
+ number: creditNote.number,
58
+ amount: creditNote.amount,
59
+ currency: creditNote.currency,
60
+ reason: creditNote.reason ?? "",
61
+ memo: creditNote.memo,
62
+ type: resolveCreditNoteType(creditNote),
63
+ refundId: resolveCreditNoteRefundId(creditNote),
64
+ hostedUrl: null,
65
+ pdfUrl: creditNote.pdf ?? null,
66
+ status: creditNoteStatus,
67
+ issuedAt: (0, utils_1.stripeSecondsToDate)(creditNote.effective_at ?? creditNote.created) ??
68
+ new Date(),
69
+ voidedAt: (0, utils_1.stripeSecondsToDate)(creditNote.voided_at),
70
+ metadata: creditNote.metadata ?? {},
71
+ updatedAt: new Date(),
72
+ };
73
+ }
74
+ function buildCreditNoteInvoicePayload(creditNote, invoice, lines) {
75
+ const tax = resolveCreditNoteTax(creditNote);
76
+ return {
77
+ documentType: "credit_note",
78
+ stripeInvoiceId: invoice.stripeInvoiceId,
79
+ stripeCreditNoteId: creditNote.id,
80
+ number: creditNote.number,
81
+ parentInvoiceNumber: invoice.number,
82
+ amount: -creditNote.amount,
83
+ subtotal: -creditNote.subtotal,
84
+ tax: -tax,
85
+ total: -creditNote.total,
86
+ currency: creditNote.currency,
87
+ periodStart: invoice.periodStart,
88
+ periodEnd: invoice.periodEnd,
89
+ lines,
90
+ status: creditNote.status,
91
+ creditNoteReason: creditNote.reason,
92
+ creditNoteType: resolveCreditNoteType(creditNote),
93
+ memo: creditNote.memo,
94
+ hostedInvoiceUrl: null,
95
+ invoicePdfUrl: creditNote.pdf ?? null,
96
+ metadata: creditNote.metadata ?? {},
97
+ paidAt: null,
98
+ voidedAt: (0, utils_1.stripeSecondsToDate)(creditNote.voided_at),
99
+ issuedAt: (0, utils_1.stripeSecondsToDate)(creditNote.effective_at ?? creditNote.created) ??
100
+ new Date(),
101
+ updatedAt: new Date(),
102
+ };
103
+ }
104
+ async function resolveMirroredInvoice(tenantId, stripeInvoiceId) {
105
+ const invoiceModel = (0, interface_database_decorators_1.GetModel)(db_1.InvoiceModel, tenantId);
106
+ const existing = await invoiceModel.findOneByStripeInvoice(stripeInvoiceId);
107
+ if (existing?.number && existing.periodStart && existing.periodEnd) {
108
+ return existing;
109
+ }
110
+ const stripeInvoice = await (0, client_1.getStripeClient)().invoices.retrieve(stripeInvoiceId);
111
+ await (0, webhook_shared_1.upsertInvoice)(stripeInvoice, tenantId);
112
+ return (await invoiceModel.findOneByStripeInvoice(stripeInvoiceId)) ?? null;
113
+ }
114
+ async function upsertCreditNoteMirror(creditNote, tenantId, invoice) {
115
+ const creditNoteModel = (0, interface_database_decorators_1.GetModel)(db_1.CreditNoteModel, tenantId);
116
+ const existing = await creditNoteModel.findOneByStripeCreditNote(creditNote.id);
117
+ const payload = buildCreditNotePayload(creditNote, invoice._id);
118
+ if (existing) {
119
+ if (creditNote.status === "void") {
120
+ await creditNoteModel.update(existing._id, payload);
121
+ return true;
122
+ }
123
+ return creditNoteModel.updateUnlessVoided(existing._id, payload);
124
+ }
125
+ await creditNoteModel.insert({
126
+ ...payload,
127
+ _id: creditNote.id,
128
+ createdAt: new Date(),
129
+ });
130
+ return true;
131
+ }
132
+ async function upsertCreditNoteInvoiceRow(creditNote, tenantId, invoice, lines) {
133
+ const invoiceModel = (0, interface_database_decorators_1.GetModel)(db_1.InvoiceModel, tenantId);
134
+ const existing = await invoiceModel.findOneByStripeCreditNote(creditNote.id);
135
+ const payload = buildCreditNoteInvoicePayload(creditNote, invoice, lines);
136
+ if (existing) {
137
+ if (creditNote.status === "void") {
138
+ await invoiceModel.update(existing._id, payload);
139
+ return true;
140
+ }
141
+ return invoiceModel.updateUnlessVoided(existing._id, payload);
142
+ }
143
+ await invoiceModel.insert({
144
+ ...payload,
145
+ _id: creditNote.id,
146
+ createdAt: new Date(),
147
+ });
148
+ return true;
149
+ }
150
+ async function mirrorCreditNoteFromEvent(event) {
151
+ const eventCreditNote = event.data.object;
152
+ const customerId = (0, webhook_shared_1.asCustomerId)(eventCreditNote.customer);
153
+ if (!customerId)
154
+ return null;
155
+ const tenant = await (0, webhook_shared_1.findTenantByCustomerId)(customerId);
156
+ if (!tenant)
157
+ return null;
158
+ const creditNote = await (0, client_1.getStripeClient)().creditNotes.retrieve(eventCreditNote.id);
159
+ const stripeInvoiceId = resolveCreditNoteInvoiceId(creditNote);
160
+ if (!stripeInvoiceId) {
161
+ throw new Error(`Stripe credit note ${creditNote.id} has no invoice`);
162
+ }
163
+ const invoice = await resolveMirroredInvoice(tenant._id, stripeInvoiceId);
164
+ if (!invoice) {
165
+ throw new Error(`Could not mirror invoice ${stripeInvoiceId}`);
166
+ }
167
+ const lines = await resolveCreditNoteLines(creditNote);
168
+ const canonicalUpdated = await upsertCreditNoteMirror(creditNote, tenant._id, invoice);
169
+ const invoiceUpdated = await upsertCreditNoteInvoiceRow(creditNote, tenant._id, invoice, lines);
170
+ return {
171
+ creditNote,
172
+ tenantId: tenant._id,
173
+ isCurrent: canonicalUpdated && invoiceUpdated,
174
+ };
175
+ }
176
+ async function handleCreditNoteCreated(event) {
177
+ const mirrored = await mirrorCreditNoteFromEvent(event);
178
+ if (!mirrored)
179
+ return;
180
+ const { creditNote, tenantId, isCurrent } = mirrored;
181
+ if (creditNote.status !== "issued" || !isCurrent)
182
+ return;
183
+ await (0, notifications_1.notifyTenantOwners)(tenantId, notifications_1.creditNoteIssuedSubject, {
184
+ icon: CREDIT_NOTE_ICON,
185
+ title: "Credit note issued",
186
+ description: `A credit note of ${(0, webhook_shared_1.formatAmount)(creditNote.amount, creditNote.currency)} was issued.`,
187
+ });
188
+ }
189
+ async function handleCreditNoteVoided(event) {
190
+ await mirrorCreditNoteFromEvent(event);
191
+ }
192
+ //# sourceMappingURL=webhook-credit-notes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook-credit-notes.js","sourceRoot":"","sources":["../../src/stripe/webhook-credit-notes.ts"],"names":[],"mappings":";;AA4PA,0DAYC;AAED,wDAIC;AAzQD,6FAAqE;AAQrE,8BAAsD;AACtD,oDAA+E;AAC/E,oCAAqE;AACrE,qCAA2C;AAC3C,qDAO0B;AAE1B,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAExC,SAAS,0BAA0B,CACjC,UAA6B;IAE7B,IAAI,OAAO,UAAU,CAAC,OAAO,KAAK,QAAQ;QAAE,OAAO,UAAU,CAAC,OAAO,CAAC;IACtE,OAAO,UAAU,CAAC,OAAO,EAAE,EAAE,IAAI,IAAI,CAAC;AACxC,CAAC;AAED,SAAS,yBAAyB,CAChC,UAA6B;IAE7B,IAAI,OAAO,UAAU,CAAC,MAAM,KAAK,QAAQ;QAAE,OAAO,UAAU,CAAC,MAAM,CAAC;IACpE,OAAO,UAAU,CAAC,MAAM,EAAE,EAAE,IAAI,IAAI,CAAC;AACvC,CAAC;AAED,SAAS,gBAAgB,CACvB,IAA+B,EAC/B,QAAgB;IAEhB,OAAO;QACL,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,EAAE;QACnC,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,MA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,eAAe,EAAE,CAAC,CAAC;IACjE,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,sBAAsB,CAAC,UAAU,CAAC,CAAC;IACvD,MAAM,gBAAgB,GAAG,MAAM,sBAAsB,CACnD,UAAU,EACV,MAAM,CAAC,GAAG,EACV,OAAO,CACR,CAAC;IACF,MAAM,cAAc,GAAG,MAAM,0BAA0B,CACrD,UAAU,EACV,MAAM,CAAC,GAAG,EACV,OAAO,EACP,KAAK,CACN,CAAC;IACF,OAAO;QACL,UAAU;QACV,QAAQ,EAAE,MAAM,CAAC,GAAG;QACpB,SAAS,EAAE,gBAAgB,IAAI,cAAc;KAC9C,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,uBAAuB,CAC3C,KAAmB;IAEnB,MAAM,QAAQ,GAAG,MAAM,yBAAyB,CAAC,KAAK,CAAC,CAAC;IACxD,IAAI,CAAC,QAAQ;QAAE,OAAO;IACtB,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC;IACrD,IAAI,UAAU,CAAC,MAAM,KAAK,QAAQ,IAAI,CAAC,SAAS;QAAE,OAAO;IACzD,MAAM,IAAA,kCAAkB,EAAC,QAAQ,EAAE,uCAAuB,EAAE;QAC1D,IAAI,EAAE,gBAAgB;QACtB,KAAK,EAAE,oBAAoB;QAC3B,WAAW,EAAE,oBAAoB,IAAA,6BAAY,EAAC,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,cAAc;KACpG,CAAC,CAAC;AACL,CAAC;AAEM,KAAK,UAAU,sBAAsB,CAC1C,KAAmB;IAEnB,MAAM,yBAAyB,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type Stripe from "stripe";
2
+ export declare function dispatchStripeWebhookEvent(event: Stripe.Event): Promise<void>;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dispatchStripeWebhookEvent = dispatchStripeWebhookEvent;
4
+ const interface_database_decorators_1 = require("@antelopejs/interface-database-decorators");
5
+ const db_1 = require("../db");
6
+ const webhook_handlers_1 = require("./webhook-handlers");
7
+ const webhook_checkout_1 = require("./webhook-checkout");
8
+ const webhook_credit_notes_1 = require("./webhook-credit-notes");
9
+ const HANDLERS = {
10
+ "checkout.session.completed": webhook_checkout_1.handleCheckoutSessionCompleted,
11
+ "checkout.session.expired": webhook_checkout_1.handleCheckoutSessionExpired,
12
+ "invoice.created": webhook_handlers_1.handleInvoiceCreated,
13
+ "invoice.finalized": webhook_handlers_1.handleInvoiceFinalized,
14
+ "invoice.paid": webhook_handlers_1.handleInvoicePaid,
15
+ "invoice.voided": webhook_handlers_1.handleInvoiceVoided,
16
+ "invoice.payment_failed": webhook_handlers_1.handleInvoicePaymentFailed,
17
+ "credit_note.created": webhook_credit_notes_1.handleCreditNoteCreated,
18
+ "credit_note.voided": webhook_credit_notes_1.handleCreditNoteVoided,
19
+ "charge.refund.updated": webhook_handlers_1.handleChargeRefundUpdated,
20
+ "customer.updated": webhook_handlers_1.handleCustomerUpdated,
21
+ "customer.subscription.deleted": webhook_handlers_1.handleSubscriptionDeleted,
22
+ "customer.subscription.trial_will_end": webhook_handlers_1.handleTrialWillEnd,
23
+ "customer.subscription.updated": webhook_handlers_1.handleSubscriptionUpdated,
24
+ };
25
+ async function dispatchStripeWebhookEvent(event) {
26
+ const stripeWebhookEventModel = (0, interface_database_decorators_1.GetModel)(db_1.StripeWebhookEventModel);
27
+ const claimed = await stripeWebhookEventModel.tryClaim(event.id, event.type);
28
+ if (!claimed)
29
+ return;
30
+ const handler = HANDLERS[event.type];
31
+ if (!handler) {
32
+ await stripeWebhookEventModel.markResult(event.id, claimed, "skipped", null);
33
+ return;
34
+ }
35
+ try {
36
+ await handler(event);
37
+ }
38
+ catch (error) {
39
+ const message = error instanceof Error ? error.message : String(error);
40
+ await stripeWebhookEventModel.markResult(event.id, claimed, "reconciliation_required", message);
41
+ throw error;
42
+ }
43
+ await stripeWebhookEventModel.markResult(event.id, claimed, "success", null);
44
+ }
45
+ //# sourceMappingURL=webhook-dispatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook-dispatch.js","sourceRoot":"","sources":["../../src/stripe/webhook-dispatch.ts"],"names":[],"mappings":";;AA2CA,gEA+BC;AA1ED,6FAAqE;AAErE,8BAAgD;AAChD,yDAW4B;AAC5B,yDAG4B;AAC5B,iEAGgC;AAIhC,MAAM,QAAQ,GAAmC;IAC/C,4BAA4B,EAAE,iDAA8B;IAC5D,0BAA0B,EAAE,+CAA4B;IACxD,iBAAiB,EAAE,uCAAoB;IACvC,mBAAmB,EAAE,yCAAsB;IAC3C,cAAc,EAAE,oCAAiB;IACjC,gBAAgB,EAAE,sCAAmB;IACrC,wBAAwB,EAAE,6CAA0B;IACpD,qBAAqB,EAAE,8CAAuB;IAC9C,oBAAoB,EAAE,6CAAsB;IAC5C,uBAAuB,EAAE,4CAAyB;IAClD,kBAAkB,EAAE,wCAAqB;IACzC,+BAA+B,EAAE,4CAAyB;IAC1D,sCAAsC,EAAE,qCAAkB;IAC1D,+BAA+B,EAAE,4CAAyB;CAC3D,CAAC;AAEK,KAAK,UAAU,0BAA0B,CAC9C,KAAmB;IAEnB,MAAM,uBAAuB,GAAG,IAAA,wCAAQ,EAAC,4BAAuB,CAAC,CAAC;IAClE,MAAM,OAAO,GAAG,MAAM,uBAAuB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7E,IAAI,CAAC,OAAO;QAAE,OAAO;IAErB,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,uBAAuB,CAAC,UAAU,CACtC,KAAK,CAAC,EAAE,EACR,OAAO,EACP,SAAS,EACT,IAAI,CACL,CAAC;QACF,OAAO;IACT,CAAC;IAED,I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