@voyant-travel/finance 0.119.5

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 (294) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +192 -0
  3. package/dist/action-ledger-drift.d.ts +29 -0
  4. package/dist/action-ledger-drift.d.ts.map +1 -0
  5. package/dist/action-ledger-drift.js +166 -0
  6. package/dist/booking-tax.d.ts +124 -0
  7. package/dist/booking-tax.d.ts.map +1 -0
  8. package/dist/booking-tax.js +264 -0
  9. package/dist/checkout-routes.d.ts +1154 -0
  10. package/dist/checkout-routes.d.ts.map +1 -0
  11. package/dist/checkout-routes.js +116 -0
  12. package/dist/checkout-service-plan.d.ts +137 -0
  13. package/dist/checkout-service-plan.d.ts.map +1 -0
  14. package/dist/checkout-service-plan.js +119 -0
  15. package/dist/checkout-service.d.ts +9 -0
  16. package/dist/checkout-service.d.ts.map +1 -0
  17. package/dist/checkout-service.js +324 -0
  18. package/dist/checkout-validation.d.ts +1682 -0
  19. package/dist/checkout-validation.d.ts.map +1 -0
  20. package/dist/checkout-validation.js +228 -0
  21. package/dist/document-download.d.ts +3 -0
  22. package/dist/document-download.d.ts.map +1 -0
  23. package/dist/document-download.js +1 -0
  24. package/dist/fx-money.d.ts +17 -0
  25. package/dist/fx-money.d.ts.map +1 -0
  26. package/dist/fx-money.js +194 -0
  27. package/dist/index.d.ts +65 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +108 -0
  30. package/dist/invoice-fx.d.ts +134 -0
  31. package/dist/invoice-fx.d.ts.map +1 -0
  32. package/dist/invoice-fx.js +240 -0
  33. package/dist/invoice-number-errors.d.ts +2 -0
  34. package/dist/invoice-number-errors.d.ts.map +1 -0
  35. package/dist/invoice-number-errors.js +58 -0
  36. package/dist/markets-ref.d.ts +149 -0
  37. package/dist/markets-ref.d.ts.map +1 -0
  38. package/dist/markets-ref.js +17 -0
  39. package/dist/payment-link.d.ts +23 -0
  40. package/dist/payment-link.d.ts.map +1 -0
  41. package/dist/payment-link.js +30 -0
  42. package/dist/payment-policy.d.ts +113 -0
  43. package/dist/payment-policy.d.ts.map +1 -0
  44. package/dist/payment-policy.js +193 -0
  45. package/dist/route-runtime.d.ts +22 -0
  46. package/dist/route-runtime.d.ts.map +1 -0
  47. package/dist/route-runtime.js +18 -0
  48. package/dist/routes-action-ledger.d.ts +181 -0
  49. package/dist/routes-action-ledger.d.ts.map +1 -0
  50. package/dist/routes-action-ledger.js +142 -0
  51. package/dist/routes-booking-billing.d.ts +852 -0
  52. package/dist/routes-booking-billing.d.ts.map +1 -0
  53. package/dist/routes-booking-billing.js +223 -0
  54. package/dist/routes-booking-create.d.ts +3 -0
  55. package/dist/routes-booking-create.d.ts.map +1 -0
  56. package/dist/routes-booking-create.js +194 -0
  57. package/dist/routes-booking-reads.d.ts +46 -0
  58. package/dist/routes-booking-reads.d.ts.map +1 -0
  59. package/dist/routes-booking-reads.js +20 -0
  60. package/dist/routes-documents.d.ts +195 -0
  61. package/dist/routes-documents.d.ts.map +1 -0
  62. package/dist/routes-documents.js +93 -0
  63. package/dist/routes-invoice-core.d.ts +794 -0
  64. package/dist/routes-invoice-core.d.ts.map +1 -0
  65. package/dist/routes-invoice-core.js +238 -0
  66. package/dist/routes-invoice-documents.d.ts +401 -0
  67. package/dist/routes-invoice-documents.d.ts.map +1 -0
  68. package/dist/routes-invoice-documents.js +91 -0
  69. package/dist/routes-invoice-issue.d.ts +384 -0
  70. package/dist/routes-invoice-issue.d.ts.map +1 -0
  71. package/dist/routes-invoice-issue.js +208 -0
  72. package/dist/routes-payment-processing.d.ts +1193 -0
  73. package/dist/routes-payment-processing.d.ts.map +1 -0
  74. package/dist/routes-payment-processing.js +238 -0
  75. package/dist/routes-payments.d.ts +309 -0
  76. package/dist/routes-payments.d.ts.map +1 -0
  77. package/dist/routes-payments.js +94 -0
  78. package/dist/routes-public.d.ts +1948 -0
  79. package/dist/routes-public.d.ts.map +1 -0
  80. package/dist/routes-public.js +275 -0
  81. package/dist/routes-reference-data.d.ts +977 -0
  82. package/dist/routes-reference-data.d.ts.map +1 -0
  83. package/dist/routes-reference-data.js +191 -0
  84. package/dist/routes-reports.d.ts +344 -0
  85. package/dist/routes-reports.d.ts.map +1 -0
  86. package/dist/routes-reports.js +93 -0
  87. package/dist/routes-runtime.d.ts +71 -0
  88. package/dist/routes-runtime.d.ts.map +1 -0
  89. package/dist/routes-runtime.js +59 -0
  90. package/dist/routes-settlement.d.ts +67 -0
  91. package/dist/routes-settlement.d.ts.map +1 -0
  92. package/dist/routes-settlement.js +23 -0
  93. package/dist/routes-shared.d.ts +35 -0
  94. package/dist/routes-shared.d.ts.map +1 -0
  95. package/dist/routes-shared.js +10 -0
  96. package/dist/routes-supplier-invoices.d.ts +778 -0
  97. package/dist/routes-supplier-invoices.d.ts.map +1 -0
  98. package/dist/routes-supplier-invoices.js +159 -0
  99. package/dist/routes-vouchers.d.ts +228 -0
  100. package/dist/routes-vouchers.d.ts.map +1 -0
  101. package/dist/routes-vouchers.js +54 -0
  102. package/dist/routes.d.ts +5577 -0
  103. package/dist/routes.d.ts.map +1 -0
  104. package/dist/routes.js +44 -0
  105. package/dist/schema/booking-billing.d.ts +1006 -0
  106. package/dist/schema/booking-billing.d.ts.map +1 -0
  107. package/dist/schema/booking-billing.js +106 -0
  108. package/dist/schema/enums.d.ts +48 -0
  109. package/dist/schema/enums.d.ts.map +1 -0
  110. package/dist/schema/enums.js +237 -0
  111. package/dist/schema/invoice-documents.d.ts +1245 -0
  112. package/dist/schema/invoice-documents.d.ts.map +1 -0
  113. package/dist/schema/invoice-documents.js +140 -0
  114. package/dist/schema/payment-instruments.d.ts +418 -0
  115. package/dist/schema/payment-instruments.d.ts.map +1 -0
  116. package/dist/schema/payment-instruments.js +45 -0
  117. package/dist/schema/payment-processing.d.ts +563 -0
  118. package/dist/schema/payment-processing.d.ts.map +1 -0
  119. package/dist/schema/payment-processing.js +65 -0
  120. package/dist/schema/payment-sessions.d.ts +728 -0
  121. package/dist/schema/payment-sessions.d.ts.map +1 -0
  122. package/dist/schema/payment-sessions.js +79 -0
  123. package/dist/schema/receivables.d.ts +1474 -0
  124. package/dist/schema/receivables.d.ts.map +1 -0
  125. package/dist/schema/receivables.js +179 -0
  126. package/dist/schema/relations.d.ts +82 -0
  127. package/dist/schema/relations.d.ts.map +1 -0
  128. package/dist/schema/relations.js +144 -0
  129. package/dist/schema/supplier-invoices.d.ts +1619 -0
  130. package/dist/schema/supplier-invoices.d.ts.map +1 -0
  131. package/dist/schema/supplier-invoices.js +228 -0
  132. package/dist/schema/tax.d.ts +712 -0
  133. package/dist/schema/tax.d.ts.map +1 -0
  134. package/dist/schema/tax.js +98 -0
  135. package/dist/schema/vouchers.d.ts +444 -0
  136. package/dist/schema/vouchers.d.ts.map +1 -0
  137. package/dist/schema/vouchers.js +64 -0
  138. package/dist/schema.d.ts +12 -0
  139. package/dist/schema.d.ts.map +1 -0
  140. package/dist/schema.js +11 -0
  141. package/dist/service-accountant-shares.d.ts +106 -0
  142. package/dist/service-accountant-shares.d.ts.map +1 -0
  143. package/dist/service-accountant-shares.js +331 -0
  144. package/dist/service-action-ledger-accounting.d.ts +104 -0
  145. package/dist/service-action-ledger-accounting.d.ts.map +1 -0
  146. package/dist/service-action-ledger-accounting.js +386 -0
  147. package/dist/service-action-ledger-booking-payments.d.ts +48 -0
  148. package/dist/service-action-ledger-booking-payments.d.ts.map +1 -0
  149. package/dist/service-action-ledger-booking-payments.js +178 -0
  150. package/dist/service-action-ledger-bookings.d.ts +44 -0
  151. package/dist/service-action-ledger-bookings.d.ts.map +1 -0
  152. package/dist/service-action-ledger-bookings.js +81 -0
  153. package/dist/service-action-ledger-payment-authorizations.d.ts +48 -0
  154. package/dist/service-action-ledger-payment-authorizations.d.ts.map +1 -0
  155. package/dist/service-action-ledger-payment-authorizations.js +209 -0
  156. package/dist/service-action-ledger-payment-sessions.d.ts +83 -0
  157. package/dist/service-action-ledger-payment-sessions.d.ts.map +1 -0
  158. package/dist/service-action-ledger-payment-sessions.js +294 -0
  159. package/dist/service-action-ledger-supplier-invoices.d.ts +27 -0
  160. package/dist/service-action-ledger-supplier-invoices.d.ts.map +1 -0
  161. package/dist/service-action-ledger-supplier-invoices.js +111 -0
  162. package/dist/service-action-ledger-supplier-payments.d.ts +21 -0
  163. package/dist/service-action-ledger-supplier-payments.d.ts.map +1 -0
  164. package/dist/service-action-ledger-supplier-payments.js +97 -0
  165. package/dist/service-action-ledger.d.ts +7 -0
  166. package/dist/service-action-ledger.d.ts.map +1 -0
  167. package/dist/service-action-ledger.js +6 -0
  168. package/dist/service-aggregates.d.ts +96 -0
  169. package/dist/service-aggregates.d.ts.map +1 -0
  170. package/dist/service-aggregates.js +294 -0
  171. package/dist/service-booking-billing.d.ts +2322 -0
  172. package/dist/service-booking-billing.d.ts.map +1 -0
  173. package/dist/service-booking-billing.js +8 -0
  174. package/dist/service-booking-create.d.ts +410 -0
  175. package/dist/service-booking-create.d.ts.map +1 -0
  176. package/dist/service-booking-create.js +1256 -0
  177. package/dist/service-booking-guarantees.d.ts +725 -0
  178. package/dist/service-booking-guarantees.d.ts.map +1 -0
  179. package/dist/service-booking-guarantees.js +153 -0
  180. package/dist/service-booking-item-billing.d.ts +1062 -0
  181. package/dist/service-booking-item-billing.d.ts.map +1 -0
  182. package/dist/service-booking-item-billing.js +77 -0
  183. package/dist/service-booking-payment-schedules.d.ts +557 -0
  184. package/dist/service-booking-payment-schedules.d.ts.map +1 -0
  185. package/dist/service-booking-payment-schedules.js +372 -0
  186. package/dist/service-bookings-dual-create.d.ts +308 -0
  187. package/dist/service-bookings-dual-create.d.ts.map +1 -0
  188. package/dist/service-bookings-dual-create.js +131 -0
  189. package/dist/service-boundary-sql.d.ts +6 -0
  190. package/dist/service-boundary-sql.d.ts.map +1 -0
  191. package/dist/service-boundary-sql.js +15 -0
  192. package/dist/service-cost-categories.d.ts +26 -0
  193. package/dist/service-cost-categories.d.ts.map +1 -0
  194. package/dist/service-cost-categories.js +76 -0
  195. package/dist/service-documents.d.ts +80 -0
  196. package/dist/service-documents.d.ts.map +1 -0
  197. package/dist/service-documents.js +228 -0
  198. package/dist/service-invoice-artifacts.d.ts +246 -0
  199. package/dist/service-invoice-artifacts.d.ts.map +1 -0
  200. package/dist/service-invoice-artifacts.js +277 -0
  201. package/dist/service-invoice-core.d.ts +405 -0
  202. package/dist/service-invoice-core.d.ts.map +1 -0
  203. package/dist/service-invoice-core.js +290 -0
  204. package/dist/service-invoice-credit-notes.d.ts +973 -0
  205. package/dist/service-invoice-credit-notes.d.ts.map +1 -0
  206. package/dist/service-invoice-credit-notes.js +142 -0
  207. package/dist/service-invoice-from-booking.d.ts +41 -0
  208. package/dist/service-invoice-from-booking.d.ts.map +1 -0
  209. package/dist/service-invoice-from-booking.js +267 -0
  210. package/dist/service-invoice-line-items.d.ts +432 -0
  211. package/dist/service-invoice-line-items.d.ts.map +1 -0
  212. package/dist/service-invoice-line-items.js +102 -0
  213. package/dist/service-invoice-numbering.d.ts +227 -0
  214. package/dist/service-invoice-numbering.d.ts.map +1 -0
  215. package/dist/service-invoice-numbering.js +260 -0
  216. package/dist/service-invoice-payments.d.ts +673 -0
  217. package/dist/service-invoice-payments.d.ts.map +1 -0
  218. package/dist/service-invoice-payments.js +398 -0
  219. package/dist/service-invoices.d.ts +2501 -0
  220. package/dist/service-invoices.d.ts.map +1 -0
  221. package/dist/service-invoices.js +12 -0
  222. package/dist/service-issue.d.ts +207 -0
  223. package/dist/service-issue.d.ts.map +1 -0
  224. package/dist/service-issue.js +431 -0
  225. package/dist/service-payment-authorizations.d.ts +164 -0
  226. package/dist/service-payment-authorizations.d.ts.map +1 -0
  227. package/dist/service-payment-authorizations.js +227 -0
  228. package/dist/service-payment-instruments.d.ts +116 -0
  229. package/dist/service-payment-instruments.d.ts.map +1 -0
  230. package/dist/service-payment-instruments.js +99 -0
  231. package/dist/service-payment-processing.d.ts +676 -0
  232. package/dist/service-payment-processing.d.ts.map +1 -0
  233. package/dist/service-payment-processing.js +10 -0
  234. package/dist/service-payment-session-completion.d.ts +48 -0
  235. package/dist/service-payment-session-completion.d.ts.map +1 -0
  236. package/dist/service-payment-session-completion.js +238 -0
  237. package/dist/service-payment-sessions.d.ts +361 -0
  238. package/dist/service-payment-sessions.d.ts.map +1 -0
  239. package/dist/service-payment-sessions.js +280 -0
  240. package/dist/service-profitability.d.ts +114 -0
  241. package/dist/service-profitability.d.ts.map +1 -0
  242. package/dist/service-profitability.js +794 -0
  243. package/dist/service-public.d.ts +553 -0
  244. package/dist/service-public.d.ts.map +1 -0
  245. package/dist/service-public.js +583 -0
  246. package/dist/service-reference-data.d.ts +272 -0
  247. package/dist/service-reference-data.d.ts.map +1 -0
  248. package/dist/service-reference-data.js +280 -0
  249. package/dist/service-rendition-wait.d.ts +38 -0
  250. package/dist/service-rendition-wait.d.ts.map +1 -0
  251. package/dist/service-rendition-wait.js +67 -0
  252. package/dist/service-reports.d.ts +37 -0
  253. package/dist/service-reports.d.ts.map +1 -0
  254. package/dist/service-reports.js +62 -0
  255. package/dist/service-settlement.d.ts +46 -0
  256. package/dist/service-settlement.d.ts.map +1 -0
  257. package/dist/service-settlement.js +185 -0
  258. package/dist/service-shared.d.ts +541 -0
  259. package/dist/service-shared.d.ts.map +1 -0
  260. package/dist/service-shared.js +764 -0
  261. package/dist/service-supplier-invoices.d.ts +871 -0
  262. package/dist/service-supplier-invoices.d.ts.map +1 -0
  263. package/dist/service-supplier-invoices.js +744 -0
  264. package/dist/service-supplier-payments.d.ts +69 -0
  265. package/dist/service-supplier-payments.d.ts.map +1 -0
  266. package/dist/service-supplier-payments.js +136 -0
  267. package/dist/service-vouchers-migration.d.ts +44 -0
  268. package/dist/service-vouchers-migration.d.ts.map +1 -0
  269. package/dist/service-vouchers-migration.js +148 -0
  270. package/dist/service-vouchers.d.ts +157 -0
  271. package/dist/service-vouchers.d.ts.map +1 -0
  272. package/dist/service-vouchers.js +191 -0
  273. package/dist/service.d.ts +6490 -0
  274. package/dist/service.d.ts.map +1 -0
  275. package/dist/service.js +29 -0
  276. package/dist/validation-billing.d.ts +2 -0
  277. package/dist/validation-billing.d.ts.map +1 -0
  278. package/dist/validation-billing.js +1 -0
  279. package/dist/validation-payments.d.ts +2 -0
  280. package/dist/validation-payments.d.ts.map +1 -0
  281. package/dist/validation-payments.js +1 -0
  282. package/dist/validation-public.d.ts +2 -0
  283. package/dist/validation-public.d.ts.map +1 -0
  284. package/dist/validation-public.js +1 -0
  285. package/dist/validation-shared.d.ts +2 -0
  286. package/dist/validation-shared.d.ts.map +1 -0
  287. package/dist/validation-shared.js +1 -0
  288. package/dist/validation-vouchers.d.ts +2 -0
  289. package/dist/validation-vouchers.d.ts.map +1 -0
  290. package/dist/validation-vouchers.js +1 -0
  291. package/dist/validation.d.ts +2 -0
  292. package/dist/validation.d.ts.map +1 -0
  293. package/dist/validation.js +1 -0
  294. package/package.json +121 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes-booking-billing.d.ts","sourceRoot":"","sources":["../src/routes-booking-billing.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAA;AAgB7C,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kEAsVpC,CAAA"}
@@ -0,0 +1,223 @@
1
+ import { ActionLedgerIdempotencyConflictError } from "@voyant-travel/action-ledger";
2
+ import { parseJsonBody } from "@voyant-travel/hono";
3
+ import { Hono } from "hono";
4
+ import { getActionLedgerRequestContext, getFinanceRouteRuntime } from "./routes-runtime.js";
5
+ import { financeService, PaymentValidationError } from "./service.js";
6
+ import { applyDefaultBookingPaymentPlanSchema, createPaymentSessionFromGuaranteeSchema, createPaymentSessionFromScheduleSchema, insertBookingGuaranteeSchema, insertBookingItemCommissionSchema, insertBookingItemTaxLineSchema, insertBookingPaymentScheduleSchema, updateBookingGuaranteeSchema, updateBookingItemCommissionSchema, updateBookingItemTaxLineSchema, updateBookingPaymentScheduleSchema, } from "./validation.js";
7
+ export const financeBookingBillingRoutes = new Hono()
8
+ // ========================================================================
9
+ // Booking Payment Schedules
10
+ // ========================================================================
11
+ .get("/bookings/:bookingId/payment-schedules", async (c) => {
12
+ return c.json({
13
+ data: await financeService.listBookingPaymentSchedules(c.get("db"), c.req.param("bookingId")),
14
+ });
15
+ })
16
+ .post("/bookings/:bookingId/payment-schedules", async (c) => {
17
+ try {
18
+ const runtime = getFinanceRouteRuntime(c);
19
+ const row = await financeService.createBookingPaymentSchedule(c.get("db"), c.req.param("bookingId"), await parseJsonBody(c, insertBookingPaymentScheduleSchema), {
20
+ eventBus: runtime?.eventBus,
21
+ actionLedgerContext: getActionLedgerRequestContext(c),
22
+ actionLedgerAuthorizationSource: "finance.booking_payment_schedule.route",
23
+ });
24
+ if (!row) {
25
+ return c.json({ error: "Booking not found" }, 404);
26
+ }
27
+ return c.json({ data: row }, 201);
28
+ }
29
+ catch (error) {
30
+ if (error instanceof PaymentValidationError) {
31
+ return c.json({ error: error.message, code: error.code, details: error.details }, error.status);
32
+ }
33
+ if (error instanceof ActionLedgerIdempotencyConflictError) {
34
+ return c.json({
35
+ error: error.message,
36
+ existingActionId: error.existingActionId,
37
+ }, 409);
38
+ }
39
+ throw error;
40
+ }
41
+ })
42
+ .post("/bookings/:bookingId/payment-schedules/default-plan", async (c) => {
43
+ const runtime = getFinanceRouteRuntime(c);
44
+ const rows = await financeService.applyDefaultBookingPaymentPlan(c.get("db"), c.req.param("bookingId"), await parseJsonBody(c, applyDefaultBookingPaymentPlanSchema), {
45
+ eventBus: runtime?.eventBus,
46
+ actionLedgerContext: getActionLedgerRequestContext(c),
47
+ actionLedgerAuthorizationSource: "finance.booking_payment_schedule.default_plan.route",
48
+ });
49
+ if (!rows) {
50
+ return c.json({ error: "Booking not found" }, 404);
51
+ }
52
+ return c.json({ data: rows }, 201);
53
+ })
54
+ .patch("/bookings/:bookingId/payment-schedules/:scheduleId", async (c) => {
55
+ try {
56
+ const runtime = getFinanceRouteRuntime(c);
57
+ const row = await financeService.updateBookingPaymentSchedule(c.get("db"), c.req.param("scheduleId"), await parseJsonBody(c, updateBookingPaymentScheduleSchema), {
58
+ eventBus: runtime?.eventBus,
59
+ actionLedgerContext: getActionLedgerRequestContext(c),
60
+ actionLedgerAuthorizationSource: "finance.booking_payment_schedule.route",
61
+ });
62
+ if (!row) {
63
+ return c.json({ error: "Payment schedule not found" }, 404);
64
+ }
65
+ return c.json({ data: row });
66
+ }
67
+ catch (error) {
68
+ if (error instanceof PaymentValidationError) {
69
+ return c.json({ error: error.message, code: error.code, details: error.details }, error.status);
70
+ }
71
+ throw error;
72
+ }
73
+ })
74
+ .post("/bookings/:bookingId/payment-schedules/:scheduleId/payment-session", async (c) => {
75
+ try {
76
+ const runtime = getFinanceRouteRuntime(c);
77
+ const row = await financeService.createPaymentSessionFromBookingSchedule(c.get("db"), c.req.param("scheduleId"), await parseJsonBody(c, createPaymentSessionFromScheduleSchema), {
78
+ eventBus: runtime?.eventBus,
79
+ actionLedgerContext: getActionLedgerRequestContext(c),
80
+ actionLedgerAuthorizationSource: "finance.payment_session.route",
81
+ });
82
+ if (!row) {
83
+ return c.json({ error: "Payment schedule not found" }, 404);
84
+ }
85
+ return c.json({ data: row }, 201);
86
+ }
87
+ catch (error) {
88
+ const message = error instanceof Error ? error.message : "Unable to create payment session";
89
+ return c.json({ error: message }, 409);
90
+ }
91
+ })
92
+ .delete("/bookings/:bookingId/payment-schedules/:scheduleId", async (c) => {
93
+ const runtime = getFinanceRouteRuntime(c);
94
+ const row = await financeService.deleteBookingPaymentSchedule(c.get("db"), c.req.param("scheduleId"), {
95
+ eventBus: runtime?.eventBus,
96
+ actionLedgerContext: getActionLedgerRequestContext(c),
97
+ actionLedgerAuthorizationSource: "finance.booking_payment_schedule.route",
98
+ });
99
+ if (!row) {
100
+ return c.json({ error: "Payment schedule not found" }, 404);
101
+ }
102
+ return c.json({ success: true }, 200);
103
+ })
104
+ // ========================================================================
105
+ // Booking Guarantees
106
+ // ========================================================================
107
+ .get("/bookings/:bookingId/guarantees", async (c) => {
108
+ return c.json({
109
+ data: await financeService.listBookingGuarantees(c.get("db"), c.req.param("bookingId")),
110
+ });
111
+ })
112
+ .post("/bookings/:bookingId/guarantees", async (c) => {
113
+ const runtime = getFinanceRouteRuntime(c);
114
+ const row = await financeService.createBookingGuarantee(c.get("db"), c.req.param("bookingId"), await parseJsonBody(c, insertBookingGuaranteeSchema), {
115
+ eventBus: runtime?.eventBus,
116
+ actionLedgerContext: getActionLedgerRequestContext(c),
117
+ actionLedgerAuthorizationSource: "finance.booking_guarantee.route",
118
+ });
119
+ if (!row) {
120
+ return c.json({ error: "Booking not found" }, 404);
121
+ }
122
+ return c.json({ data: row }, 201);
123
+ })
124
+ .post("/bookings/:bookingId/guarantees/:guaranteeId/payment-session", async (c) => {
125
+ try {
126
+ const runtime = getFinanceRouteRuntime(c);
127
+ const row = await financeService.createPaymentSessionFromBookingGuarantee(c.get("db"), c.req.param("guaranteeId"), await parseJsonBody(c, createPaymentSessionFromGuaranteeSchema), {
128
+ eventBus: runtime?.eventBus,
129
+ actionLedgerContext: getActionLedgerRequestContext(c),
130
+ actionLedgerAuthorizationSource: "finance.payment_session.route",
131
+ });
132
+ if (!row) {
133
+ return c.json({ error: "Booking guarantee not found" }, 404);
134
+ }
135
+ return c.json({ data: row }, 201);
136
+ }
137
+ catch (error) {
138
+ const message = error instanceof Error ? error.message : "Unable to create payment session";
139
+ return c.json({ error: message }, 409);
140
+ }
141
+ })
142
+ .patch("/bookings/:bookingId/guarantees/:guaranteeId", async (c) => {
143
+ const runtime = getFinanceRouteRuntime(c);
144
+ const row = await financeService.updateBookingGuarantee(c.get("db"), c.req.param("guaranteeId"), await parseJsonBody(c, updateBookingGuaranteeSchema), {
145
+ eventBus: runtime?.eventBus,
146
+ actionLedgerContext: getActionLedgerRequestContext(c),
147
+ actionLedgerAuthorizationSource: "finance.booking_guarantee.route",
148
+ });
149
+ if (!row) {
150
+ return c.json({ error: "Booking guarantee not found" }, 404);
151
+ }
152
+ return c.json({ data: row });
153
+ })
154
+ .delete("/bookings/:bookingId/guarantees/:guaranteeId", async (c) => {
155
+ const runtime = getFinanceRouteRuntime(c);
156
+ const row = await financeService.deleteBookingGuarantee(c.get("db"), c.req.param("guaranteeId"), {
157
+ eventBus: runtime?.eventBus,
158
+ actionLedgerContext: getActionLedgerRequestContext(c),
159
+ actionLedgerAuthorizationSource: "finance.booking_guarantee.route",
160
+ });
161
+ if (!row) {
162
+ return c.json({ error: "Booking guarantee not found" }, 404);
163
+ }
164
+ return c.json({ success: true }, 200);
165
+ })
166
+ // ========================================================================
167
+ // Booking Item Taxes
168
+ // ========================================================================
169
+ .get("/booking-items/:bookingItemId/tax-lines", async (c) => {
170
+ return c.json({
171
+ data: await financeService.listBookingItemTaxLines(c.get("db"), c.req.param("bookingItemId")),
172
+ });
173
+ })
174
+ .post("/booking-items/:bookingItemId/tax-lines", async (c) => {
175
+ const row = await financeService.createBookingItemTaxLine(c.get("db"), c.req.param("bookingItemId"), await parseJsonBody(c, insertBookingItemTaxLineSchema));
176
+ if (!row) {
177
+ return c.json({ error: "Booking item not found" }, 404);
178
+ }
179
+ return c.json({ data: row }, 201);
180
+ })
181
+ .patch("/booking-items/:bookingItemId/tax-lines/:taxLineId", async (c) => {
182
+ const row = await financeService.updateBookingItemTaxLine(c.get("db"), c.req.param("taxLineId"), await parseJsonBody(c, updateBookingItemTaxLineSchema));
183
+ if (!row) {
184
+ return c.json({ error: "Booking item tax line not found" }, 404);
185
+ }
186
+ return c.json({ data: row });
187
+ })
188
+ .delete("/booking-items/:bookingItemId/tax-lines/:taxLineId", async (c) => {
189
+ const row = await financeService.deleteBookingItemTaxLine(c.get("db"), c.req.param("taxLineId"));
190
+ if (!row) {
191
+ return c.json({ error: "Booking item tax line not found" }, 404);
192
+ }
193
+ return c.json({ success: true }, 200);
194
+ })
195
+ // ========================================================================
196
+ // Booking Item Commissions
197
+ // ========================================================================
198
+ .get("/booking-items/:bookingItemId/commissions", async (c) => {
199
+ return c.json({
200
+ data: await financeService.listBookingItemCommissions(c.get("db"), c.req.param("bookingItemId")),
201
+ });
202
+ })
203
+ .post("/booking-items/:bookingItemId/commissions", async (c) => {
204
+ const row = await financeService.createBookingItemCommission(c.get("db"), c.req.param("bookingItemId"), await parseJsonBody(c, insertBookingItemCommissionSchema));
205
+ if (!row) {
206
+ return c.json({ error: "Booking item not found" }, 404);
207
+ }
208
+ return c.json({ data: row }, 201);
209
+ })
210
+ .patch("/booking-items/:bookingItemId/commissions/:commissionId", async (c) => {
211
+ const row = await financeService.updateBookingItemCommission(c.get("db"), c.req.param("commissionId"), await parseJsonBody(c, updateBookingItemCommissionSchema));
212
+ if (!row) {
213
+ return c.json({ error: "Booking item commission not found" }, 404);
214
+ }
215
+ return c.json({ data: row });
216
+ })
217
+ .delete("/booking-items/:bookingItemId/commissions/:commissionId", async (c) => {
218
+ const row = await financeService.deleteBookingItemCommission(c.get("db"), c.req.param("commissionId"));
219
+ if (!row) {
220
+ return c.json({ error: "Booking item commission not found" }, 404);
221
+ }
222
+ return c.json({ success: true }, 200);
223
+ });
@@ -0,0 +1,3 @@
1
+ import type { HonoExtension } from "@voyant-travel/hono/module";
2
+ export declare const bookingsCreateExtension: HonoExtension;
3
+ //# sourceMappingURL=routes-booking-create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes-booking-create.d.ts","sourceRoot":"","sources":["../src/routes-booking-create.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAwO/D,eAAO,MAAM,uBAAuB,EAAE,aAQrC,CAAA"}
@@ -0,0 +1,194 @@
1
+ import { parseJsonBody } from "@voyant-travel/hono";
2
+ import { Hono } from "hono";
3
+ import { FINANCE_ROUTE_RUNTIME_CONTAINER_KEY } from "./route-runtime.js";
4
+ import { bookingCreateSchema, createBooking } from "./service-booking-create.js";
5
+ import { dualCreateBooking, dualCreateBookingSchema } from "./service-bookings-dual-create.js";
6
+ function resolveRuntime(container) {
7
+ try {
8
+ return container?.resolve(FINANCE_ROUTE_RUNTIME_CONTAINER_KEY);
9
+ }
10
+ catch {
11
+ return undefined;
12
+ }
13
+ }
14
+ function getBookingCreateActionLedgerRequestContext(c) {
15
+ const context = {
16
+ userId: c.get("userId") ?? null,
17
+ agentId: c.get("agentId") ?? null,
18
+ workflowPrincipalId: c.get("workflowPrincipalId") ?? null,
19
+ principalSubtype: c.get("principalSubtype") ?? null,
20
+ sessionId: c.get("sessionId") ?? null,
21
+ apiTokenId: c.get("apiTokenId") ?? c.get("apiKeyId") ?? null,
22
+ callerType: c.get("callerType") ?? null,
23
+ actor: c.get("actor") ?? null,
24
+ isInternalRequest: c.get("isInternalRequest") ?? false,
25
+ organizationId: c.get("organizationId") ?? null,
26
+ workflowRunId: c.get("workflowRunId") ?? null,
27
+ workflowStepId: c.get("workflowStepId") ?? null,
28
+ correlationId: c.req.header("x-correlation-id") ?? c.req.header("x-request-id") ?? null,
29
+ };
30
+ if (context.userId ||
31
+ context.agentId ||
32
+ context.workflowPrincipalId ||
33
+ context.apiTokenId ||
34
+ context.isInternalRequest) {
35
+ return context;
36
+ }
37
+ return undefined;
38
+ }
39
+ /**
40
+ * Mounted under `/v1/admin/bookings/*` via the extension's `module` target, so
41
+ * the endpoint's public-facing path lands at `POST /v1/admin/bookings/create`
42
+ * even though the code lives in `@voyant-travel/finance`. See the header comment in
43
+ * service-booking-create.ts for why finance owns this orchestration.
44
+ */
45
+ const createBookingRoutes = new Hono()
46
+ .post("/create", async (c) => {
47
+ const input = await parseJsonBody(c, bookingCreateSchema);
48
+ const runtime = resolveRuntime(c.var.container);
49
+ const outcome = await createBooking(c.get("db"), input, {
50
+ userId: c.get("userId"),
51
+ runtime: {
52
+ ...(runtime ?? {}),
53
+ actionLedgerContext: getBookingCreateActionLedgerRequestContext(c),
54
+ actionLedgerAuthorizationSource: "booking.create.route",
55
+ },
56
+ });
57
+ switch (outcome.status) {
58
+ case "ok":
59
+ return c.json({ data: outcome.result }, 201);
60
+ case "invalid_payment_schedules":
61
+ return c.json({
62
+ error: "Invalid payment schedules",
63
+ issues: outcome.issues,
64
+ }, 400);
65
+ case "payload_resolver_mismatch":
66
+ return c.json({
67
+ error: "Booking payload does not match the resolved draft",
68
+ code: "payload_resolver_mismatch",
69
+ mismatches: outcome.mismatches,
70
+ }, 400);
71
+ case "room_occupancy_insufficient":
72
+ return c.json({
73
+ error: "Selected rooms cannot seat the booking party",
74
+ code: "room_occupancy_insufficient",
75
+ pax: outcome.pax,
76
+ occupancyMax: outcome.occupancyMax,
77
+ shortfall: outcome.shortfall,
78
+ }, 400);
79
+ case "duplicate_booking":
80
+ return c.json({
81
+ error: "Duplicate booking",
82
+ code: "duplicate_booking",
83
+ existingBookingId: outcome.existingBooking.id,
84
+ existingBookingNumber: outcome.existingBooking.bookingNumber,
85
+ existingBookingStatus: outcome.existingBooking.status,
86
+ }, 409);
87
+ case "product_not_found":
88
+ return c.json({ error: "Product not found or unavailable" }, 404);
89
+ case "voucher_not_found":
90
+ return c.json({ error: "Voucher not found" }, 404);
91
+ case "voucher_inactive":
92
+ return c.json({ error: "Voucher is not active" }, 409);
93
+ case "voucher_not_started":
94
+ return c.json({ error: "Voucher is not yet valid" }, 409);
95
+ case "voucher_expired":
96
+ return c.json({ error: "Voucher has expired" }, 409);
97
+ case "voucher_insufficient_balance":
98
+ return c.json({ error: "Voucher does not have enough balance" }, 409);
99
+ case "group_not_found":
100
+ return c.json({ error: "Booking group not found" }, 404);
101
+ case "booking_already_in_group":
102
+ return c.json({
103
+ error: "Booking is already a member of a group",
104
+ currentGroupId: outcome.currentGroupId,
105
+ }, 409);
106
+ }
107
+ })
108
+ .post("/dual-create", async (c) => {
109
+ const input = await parseJsonBody(c, dualCreateBookingSchema);
110
+ const runtime = resolveRuntime(c.var.container);
111
+ const outcome = await dualCreateBooking(c.get("db"), input, {
112
+ userId: c.get("userId"),
113
+ runtime: {
114
+ ...(runtime ?? {}),
115
+ actionLedgerContext: getBookingCreateActionLedgerRequestContext(c),
116
+ actionLedgerAuthorizationSource: "booking.create.route",
117
+ },
118
+ });
119
+ if (outcome.status === "ok") {
120
+ return c.json({ data: outcome.result }, 201);
121
+ }
122
+ // Both failure branches carry a nested create reason. Map them to
123
+ // the same HTTP codes the single create endpoint uses so callers
124
+ // can treat them uniformly, and surface which sub-booking tripped.
125
+ const which = outcome.status === "primary_failed" ? "primary" : "secondary";
126
+ const reason = outcome.reason;
127
+ const body = { which, reasonStatus: reason.status };
128
+ switch (reason.status) {
129
+ case "invalid_payment_schedules":
130
+ return c.json({
131
+ ...body,
132
+ error: `${which}: invalid payment schedules`,
133
+ issues: reason.issues,
134
+ }, 400);
135
+ case "payload_resolver_mismatch":
136
+ return c.json({
137
+ ...body,
138
+ error: `${which}: booking payload does not match the resolved draft`,
139
+ code: "payload_resolver_mismatch",
140
+ mismatches: reason.mismatches,
141
+ }, 400);
142
+ case "room_occupancy_insufficient":
143
+ return c.json({
144
+ ...body,
145
+ error: `${which}: selected rooms cannot seat the booking party`,
146
+ code: "room_occupancy_insufficient",
147
+ pax: reason.pax,
148
+ occupancyMax: reason.occupancyMax,
149
+ shortfall: reason.shortfall,
150
+ }, 400);
151
+ case "duplicate_booking":
152
+ return c.json({
153
+ ...body,
154
+ error: `${which}: duplicate booking`,
155
+ code: "duplicate_booking",
156
+ existingBookingId: reason.existingBooking.id,
157
+ existingBookingNumber: reason.existingBooking.bookingNumber,
158
+ existingBookingStatus: reason.existingBooking.status,
159
+ }, 409);
160
+ case "product_not_found":
161
+ return c.json({ ...body, error: `${which}: product not found or unavailable` }, 404);
162
+ case "voucher_not_found":
163
+ return c.json({ ...body, error: `${which}: voucher not found` }, 404);
164
+ case "voucher_inactive":
165
+ return c.json({ ...body, error: `${which}: voucher is not active` }, 409);
166
+ case "voucher_not_started":
167
+ return c.json({ ...body, error: `${which}: voucher is not yet valid` }, 409);
168
+ case "voucher_expired":
169
+ return c.json({ ...body, error: `${which}: voucher has expired` }, 409);
170
+ case "voucher_insufficient_balance":
171
+ return c.json({ ...body, error: `${which}: voucher does not have enough balance` }, 409);
172
+ case "group_not_found":
173
+ return c.json({ ...body, error: `${which}: group linking failed` }, 500);
174
+ case "booking_already_in_group":
175
+ return c.json({
176
+ ...body,
177
+ error: `${which}: booking is already in a group`,
178
+ currentGroupId: reason.currentGroupId,
179
+ }, 409);
180
+ }
181
+ });
182
+ const bookingsCreateExtensionDef = {
183
+ name: "bookings-create",
184
+ module: "bookings",
185
+ };
186
+ export const bookingsCreateExtension = {
187
+ extension: bookingsCreateExtensionDef,
188
+ // Mount on both surfaces to mirror bookings' own module routes. The legacy
189
+ // `/v1/bookings/...` path is what existing bookings-react hooks hit; the
190
+ // `/v1/admin/bookings/...` path is staff-guarded and the forward-looking
191
+ // convention. Both serve the same handler.
192
+ adminRoutes: createBookingRoutes,
193
+ routes: createBookingRoutes,
194
+ };
@@ -0,0 +1,46 @@
1
+ import type { Env } from "./routes-shared.js";
2
+ export declare const financeBookingReadRoutes: import("hono/hono-base").HonoBase<Env, {
3
+ "/bookings/:bookingId/payments": {
4
+ $get: {
5
+ input: {
6
+ param: {
7
+ bookingId: string;
8
+ };
9
+ };
10
+ output: {
11
+ error: string;
12
+ };
13
+ outputFormat: "json";
14
+ status: 404;
15
+ } | {
16
+ input: {
17
+ param: {
18
+ bookingId: string;
19
+ };
20
+ };
21
+ output: {
22
+ data: {
23
+ bookingId: string;
24
+ payments: {
25
+ id: string;
26
+ invoiceId: string;
27
+ invoiceNumber: string;
28
+ invoiceType: "invoice" | "proforma" | "credit_note";
29
+ status: "failed" | "pending" | "completed" | "refunded";
30
+ paymentMethod: "other" | "bank_transfer" | "credit_card" | "voucher" | "debit_card" | "cash" | "cheque" | "wallet" | "direct_bill";
31
+ amountCents: number;
32
+ currency: string;
33
+ baseCurrency: string | null;
34
+ baseAmountCents: number | null;
35
+ paymentDate: string;
36
+ referenceNumber: string | null;
37
+ notes: string | null;
38
+ }[];
39
+ };
40
+ };
41
+ outputFormat: "json";
42
+ status: import("hono/utils/http-status").ContentfulStatusCode;
43
+ };
44
+ };
45
+ }, "/", "/bookings/:bookingId/payments">;
46
+ //# sourceMappingURL=routes-booking-reads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes-booking-reads.d.ts","sourceRoot":"","sources":["../src/routes-booking-reads.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAA;AAE7C,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wCAsBjC,CAAA"}
@@ -0,0 +1,20 @@
1
+ import { Hono } from "hono";
2
+ export const financeBookingReadRoutes = new Hono()
3
+ // ========================================================================
4
+ // Booking-scoped reads (admin)
5
+ // ========================================================================
6
+ // Mirror the customer-portal's `/v1/public/finance/bookings/:bookingId/payments`
7
+ // endpoint on the admin surface. The admin actor guard
8
+ // (`requireActor("staff")`) blocks staff sessions from hitting the
9
+ // public path, but operators absolutely need to see the canonical
10
+ // `payments` rows on the booking detail page. This handler reuses
11
+ // the same publicFinanceService helper so the response shape is
12
+ // identical to the customer-portal flow.
13
+ .get("/bookings/:bookingId/payments", async (c) => {
14
+ const { publicFinanceService } = await import("./service-public.js");
15
+ const result = await publicFinanceService.getBookingPayments(c.get("db"), c.req.param("bookingId"));
16
+ if (!result) {
17
+ return c.json({ error: "Booking payments not found" }, 404);
18
+ }
19
+ return c.json({ data: result });
20
+ });