@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-public.d.ts","sourceRoot":"","sources":["../src/routes-public.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,275 @@
1
+ import { requireCheckoutCapability, } from "@voyant-travel/bookings/checkout-capability";
2
+ import { idempotencyKey, parseJsonBody, parseQuery, UnauthorizedApiError, } from "@voyant-travel/hono";
3
+ import { zipSync } from "fflate";
4
+ import { Hono } from "hono";
5
+ import { resolveStoredDocumentDownload } from "./document-download.js";
6
+ import { getFinanceRouteRuntime } from "./routes-runtime.js";
7
+ import { getRuntimeEnv, notFound } from "./routes-shared.js";
8
+ import { financeService } from "./service.js";
9
+ import { accountantSharesService, buildAccountantInvoicesCsv } from "./service-accountant-shares.js";
10
+ import { buildDepartureProfitabilityCsv, buildProductProfitabilityCsv, } from "./service-profitability.js";
11
+ import { publicFinanceService } from "./service-public.js";
12
+ import { publicFinanceDocumentLookupQuerySchema, publicPaymentOptionsQuerySchema, publicStartPaymentSessionSchema, publicValidateVoucherSchema, } from "./validation-public.js";
13
+ function paymentConflictError(error) {
14
+ if (error instanceof Error) {
15
+ return error.message;
16
+ }
17
+ return "Unable to start payment session";
18
+ }
19
+ async function requireBookingCheckoutCapability(c, bookingId, action) {
20
+ await requireCheckoutCapability(c, bookingId, action, getRuntimeEnv(c));
21
+ }
22
+ function bookingCheckoutCapability(action) {
23
+ return async (c, next) => {
24
+ const bookingId = c.req.param("bookingId");
25
+ if (!bookingId) {
26
+ throw new UnauthorizedApiError("Missing checkout booking id");
27
+ }
28
+ await requireBookingCheckoutCapability(c, bookingId, action);
29
+ await next();
30
+ };
31
+ }
32
+ function invoiceCheckoutCapability(action) {
33
+ return async (c, next) => {
34
+ const invoiceId = c.req.param("invoiceId");
35
+ if (!invoiceId) {
36
+ throw new UnauthorizedApiError("Missing checkout invoice id");
37
+ }
38
+ const bookingId = await publicFinanceService.getInvoiceBookingId(c.get("db"), invoiceId);
39
+ if (!bookingId) {
40
+ return notFound(c, "Invoice not found");
41
+ }
42
+ await requireBookingCheckoutCapability(c, bookingId, action);
43
+ await next();
44
+ };
45
+ }
46
+ export function createPublicFinanceRoutes(options = {}) {
47
+ const resolveDocumentDownloadUrl = (bindings, storageKey) => options.resolveDocumentDownloadUrl?.(bindings, storageKey) ?? null;
48
+ return (new Hono()
49
+ .post("/vouchers/validate", async (c) => {
50
+ const input = await parseJsonBody(c, publicValidateVoucherSchema);
51
+ if (input.bookingId) {
52
+ await requireBookingCheckoutCapability(c, input.bookingId, "payment:read");
53
+ }
54
+ const result = await publicFinanceService.validateVoucher(c.get("db"), input);
55
+ return c.json({ data: result });
56
+ })
57
+ .get("/documents/by-reference", async (c) => {
58
+ const query = parseQuery(c, publicFinanceDocumentLookupQuerySchema);
59
+ const document = await publicFinanceService.getDocumentByReference(c.get("db"), query, {
60
+ resolveDocumentDownloadUrl: (storageKey) => resolveDocumentDownloadUrl(c.env, storageKey),
61
+ });
62
+ if (document?.bookingId) {
63
+ await requireBookingCheckoutCapability(c, document.bookingId, "payment:read");
64
+ }
65
+ return document ? c.json({ data: document }) : notFound(c, "Finance document not found");
66
+ })
67
+ .get("/bookings/:bookingId/documents", async (c) => {
68
+ await requireBookingCheckoutCapability(c, c.req.param("bookingId"), "payment:read");
69
+ const documents = await publicFinanceService.getBookingDocuments(c.get("db"), c.req.param("bookingId"), {
70
+ resolveDocumentDownloadUrl: (storageKey) => resolveDocumentDownloadUrl(c.env, storageKey),
71
+ });
72
+ return documents ? c.json({ data: documents }) : notFound(c, "Booking documents not found");
73
+ })
74
+ .get("/bookings/:bookingId/documents/by-reference", async (c) => {
75
+ await requireBookingCheckoutCapability(c, c.req.param("bookingId"), "payment:read");
76
+ const query = parseQuery(c, publicFinanceDocumentLookupQuerySchema);
77
+ const document = await publicFinanceService.getBookingDocumentByReference(c.get("db"), c.req.param("bookingId"), query, {
78
+ resolveDocumentDownloadUrl: (storageKey) => resolveDocumentDownloadUrl(c.env, storageKey),
79
+ });
80
+ return document ? c.json({ data: document }) : notFound(c, "Finance document not found");
81
+ })
82
+ .get("/bookings/:bookingId/payments", async (c) => {
83
+ await requireBookingCheckoutCapability(c, c.req.param("bookingId"), "payment:read");
84
+ const payments = await publicFinanceService.getBookingPayments(c.get("db"), c.req.param("bookingId"));
85
+ return payments ? c.json({ data: payments }) : notFound(c, "Booking payments not found");
86
+ })
87
+ .get("/bookings/:bookingId/payment-options", async (c) => {
88
+ await requireBookingCheckoutCapability(c, c.req.param("bookingId"), "payment:read");
89
+ const paymentOptions = await publicFinanceService.getBookingPaymentOptions(c.get("db"), c.req.param("bookingId"), parseQuery(c, publicPaymentOptionsQuerySchema));
90
+ return paymentOptions
91
+ ? c.json({ data: paymentOptions })
92
+ : notFound(c, "Booking payment options not found");
93
+ })
94
+ .get("/payment-sessions/:sessionId", async (c) => {
95
+ // No capability check: the session id is itself the bearer
96
+ // credential — anyone the operator shared `/pay/:sessionId` with
97
+ // needs to read it, and the projection is already redacted
98
+ // (no PII beyond payerEmail/payerName which the operator chose
99
+ // to share when issuing the link). Trip-issued sessions already
100
+ // worked this way (no bookingId attached → no check); admin-
101
+ // initiated booking sessions need the same access.
102
+ const session = await publicFinanceService.getPaymentSession(c.get("db"), c.req.param("sessionId"));
103
+ return session ? c.json({ data: session }) : notFound(c, "Payment session not found");
104
+ })
105
+ .post("/bookings/:bookingId/payment-schedules/:scheduleId/payment-session", bookingCheckoutCapability("payment:start"), idempotencyKey(), async (c) => {
106
+ try {
107
+ const session = await publicFinanceService.startBookingSchedulePaymentSession(c.get("db"), c.req.param("bookingId"), c.req.param("scheduleId"), await parseJsonBody(c, publicStartPaymentSessionSchema));
108
+ return session
109
+ ? c.json({ data: session }, 201)
110
+ : notFound(c, "Booking payment schedule not found");
111
+ }
112
+ catch (error) {
113
+ return c.json({ error: paymentConflictError(error) }, 409);
114
+ }
115
+ })
116
+ .post("/bookings/:bookingId/guarantees/:guaranteeId/payment-session", bookingCheckoutCapability("payment:start"), idempotencyKey(), async (c) => {
117
+ try {
118
+ const session = await publicFinanceService.startBookingGuaranteePaymentSession(c.get("db"), c.req.param("bookingId"), c.req.param("guaranteeId"), await parseJsonBody(c, publicStartPaymentSessionSchema));
119
+ return session
120
+ ? c.json({ data: session }, 201)
121
+ : notFound(c, "Booking guarantee not found");
122
+ }
123
+ catch (error) {
124
+ return c.json({ error: paymentConflictError(error) }, 409);
125
+ }
126
+ })
127
+ .post("/invoices/:invoiceId/payment-session", invoiceCheckoutCapability("payment:start"), idempotencyKey(), async (c) => {
128
+ try {
129
+ const session = await publicFinanceService.startInvoicePaymentSession(c.get("db"), c.req.param("invoiceId"), await parseJsonBody(c, publicStartPaymentSessionSchema));
130
+ return session ? c.json({ data: session }, 201) : notFound(c, "Invoice not found");
131
+ }
132
+ catch (error) {
133
+ return c.json({ error: paymentConflictError(error) }, 409);
134
+ }
135
+ })
136
+ // ----- Accountant portal (revocable token link, RFC §13.2) -----
137
+ // Token is the credential; each route resolves the share + its period scope.
138
+ .get("/accountant/:token/summary", async (c) => {
139
+ const resolution = await accountantSharesService.resolve(c.get("db"), c.req.param("token"));
140
+ if (resolution.status === "not_found")
141
+ return notFound(c, "Share not found");
142
+ if (resolution.status === "gone")
143
+ return c.json({ error: "Share expired or revoked" }, 410);
144
+ const { scope, grantId } = resolution;
145
+ await accountantSharesService.recordAccess(c.get("db"), grantId, {
146
+ ip: getClientIp(c.req.raw.headers),
147
+ userAgent: c.req.header("user-agent") ?? null,
148
+ });
149
+ // The base-currency rollup is always computed in the operator accounting
150
+ // base (snapshotted at each invoice's issue-date rate) — no viewer-chosen
151
+ // base, no re-valuation at the latest rate.
152
+ const query = {
153
+ from: scope.from ?? undefined,
154
+ to: scope.to ?? undefined,
155
+ };
156
+ const fx = getFinanceRouteRuntime(c);
157
+ const [departures, products] = await Promise.all([
158
+ financeService.getDepartureProfitability(c.get("db"), query, fx),
159
+ financeService.getProductProfitability(c.get("db"), query, fx),
160
+ ]);
161
+ return c.json({ data: { scope, departures, products } });
162
+ })
163
+ .get("/accountant/:token/invoices", async (c) => {
164
+ const resolution = await accountantSharesService.resolve(c.get("db"), c.req.param("token"));
165
+ if (resolution.status === "not_found")
166
+ return notFound(c, "Share not found");
167
+ if (resolution.status === "gone")
168
+ return c.json({ error: "Share expired or revoked" }, 410);
169
+ const invoices = await accountantSharesService.getInvoicesWithAttachments(c.get("db"), resolution.scope);
170
+ return c.json({ data: invoices });
171
+ })
172
+ .get("/accountant/:token/invoices/:invoiceId/attachments/:attachmentId/download", async (c) => {
173
+ const resolution = await accountantSharesService.resolve(c.get("db"), c.req.param("token"));
174
+ if (resolution.status === "not_found")
175
+ return notFound(c, "Share not found");
176
+ if (resolution.status === "gone")
177
+ return c.json({ error: "Share expired or revoked" }, 410);
178
+ const kind = c.req.query("kind") === "supplier" ? "supplier" : "client";
179
+ const attachment = await accountantSharesService.getAttachmentForDownload(c.get("db"), resolution.scope, kind, c.req.param("invoiceId"), c.req.param("attachmentId"));
180
+ if (!attachment)
181
+ return notFound(c, "Attachment not found");
182
+ const download = await resolveStoredDocumentDownload({ storageKey: attachment.storageKey }, { bindings: c.env, resolveDocumentDownloadUrl });
183
+ if (download.status !== "ready")
184
+ return notFound(c, "Attachment file is not available");
185
+ return c.redirect(download.download.url, 302);
186
+ })
187
+ .get("/accountant/:token/invoices/download-all", async (c) => {
188
+ const resolution = await accountantSharesService.resolve(c.get("db"), c.req.param("token"));
189
+ if (resolution.status === "not_found")
190
+ return notFound(c, "Share not found");
191
+ if (resolution.status === "gone")
192
+ return c.json({ error: "Share expired or revoked" }, 410);
193
+ const attachments = await accountantSharesService.listAttachmentsForZip(c.get("db"), resolution.scope);
194
+ if (attachments.length === 0)
195
+ return notFound(c, "No invoice documents to download");
196
+ const files = {};
197
+ const used = new Set();
198
+ for (const att of attachments) {
199
+ const download = await resolveStoredDocumentDownload({ storageKey: att.storageKey }, { bindings: c.env, resolveDocumentDownloadUrl });
200
+ if (download.status !== "ready")
201
+ continue;
202
+ const res = await fetch(download.download.url);
203
+ if (!res.ok)
204
+ continue;
205
+ const bytes = new Uint8Array(await res.arrayBuffer());
206
+ // Group by client/supplier folder; dedupe collisions.
207
+ let path = `${att.kind}/${sanitizeZipName(att.invoiceNumber)}-${sanitizeZipName(att.name)}`;
208
+ let n = 1;
209
+ while (used.has(path)) {
210
+ path = `${att.kind}/${sanitizeZipName(att.invoiceNumber)}-${n}-${sanitizeZipName(att.name)}`;
211
+ n += 1;
212
+ }
213
+ used.add(path);
214
+ files[path] = bytes;
215
+ }
216
+ if (Object.keys(files).length === 0) {
217
+ return notFound(c, "No invoice documents are available");
218
+ }
219
+ const zipped = zipSync(files);
220
+ return new Response(zipped, {
221
+ headers: {
222
+ "Content-Type": "application/zip",
223
+ "Content-Disposition": 'attachment; filename="invoices.zip"',
224
+ },
225
+ });
226
+ })
227
+ .get("/accountant/:token/export/:report", async (c) => {
228
+ const resolution = await accountantSharesService.resolve(c.get("db"), c.req.param("token"));
229
+ if (resolution.status === "not_found")
230
+ return notFound(c, "Share not found");
231
+ if (resolution.status === "gone")
232
+ return c.json({ error: "Share expired or revoked" }, 410);
233
+ const report = c.req.param("report");
234
+ const query = {
235
+ from: resolution.scope.from ?? undefined,
236
+ to: resolution.scope.to ?? undefined,
237
+ };
238
+ const fx = getFinanceRouteRuntime(c);
239
+ if (report === "departures") {
240
+ const data = await financeService.getDepartureProfitability(c.get("db"), query, fx);
241
+ return csvResponse(buildDepartureProfitabilityCsv(data), "departure-profitability.csv");
242
+ }
243
+ if (report === "products") {
244
+ const data = await financeService.getProductProfitability(c.get("db"), query, fx);
245
+ return csvResponse(buildProductProfitabilityCsv(data), "product-profitability.csv");
246
+ }
247
+ if (report === "invoices") {
248
+ const data = await accountantSharesService.getInvoicesWithAttachments(c.get("db"), resolution.scope);
249
+ return csvResponse(buildAccountantInvoicesCsv(data), "invoices.csv");
250
+ }
251
+ return notFound(c, "Unknown report");
252
+ }));
253
+ }
254
+ function getClientIp(headers) {
255
+ return (headers.get("cf-connecting-ip") ??
256
+ headers.get("x-forwarded-for")?.split(",")[0]?.trim() ??
257
+ headers.get("x-real-ip") ??
258
+ null);
259
+ }
260
+ function sanitizeZipName(value) {
261
+ return (value || "file")
262
+ .replace(/[/\\\r\n"]+/g, "-")
263
+ .replace(/\s+/g, " ")
264
+ .trim()
265
+ .slice(0, 120);
266
+ }
267
+ function csvResponse(csv, filename) {
268
+ return new Response(csv, {
269
+ headers: {
270
+ "Content-Type": "text/csv; charset=utf-8",
271
+ "Content-Disposition": `attachment; filename="${filename}"`,
272
+ },
273
+ });
274
+ }
275
+ export const publicFinanceRoutes = createPublicFinanceRoutes();