@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,294 @@
1
+ import { buildIdempotencyFingerprint, } from "@voyant-travel/action-ledger";
2
+ export function buildPaymentInstrumentCreateActionLedgerInput(context, input, options = {}) {
3
+ const target = getPaymentInstrumentLedgerTarget(input.instrument);
4
+ const ownerRef = getPaymentInstrumentOwnerRef(input.instrument);
5
+ return {
6
+ context,
7
+ actionName: "finance.payment_instrument.create",
8
+ actionVersion: "v1",
9
+ actionKind: "create",
10
+ status: "succeeded",
11
+ evaluatedRisk: "high",
12
+ targetType: target.type,
13
+ targetId: target.id,
14
+ routeOrToolName: "finance.payment_instrument.create",
15
+ authorizationSource: options.authorizationSource ?? "finance.payment_instrument.route",
16
+ idempotencyScope: null,
17
+ idempotencyKey: null,
18
+ idempotencyFingerprint: null,
19
+ mutationDetail: {
20
+ commandInputRef: `${ownerRef}:payment_instrument`,
21
+ commandResultRef: `payment_instrument:${input.instrument.id}`,
22
+ summary: `Payment instrument ${input.instrument.id} created for ${ownerRef}`,
23
+ reversalKind: "none",
24
+ },
25
+ };
26
+ }
27
+ export function buildPaymentInstrumentUpdateActionLedgerInput(context, input, options = {}) {
28
+ const target = getPaymentInstrumentLedgerTarget(input.instrument);
29
+ const changedFields = Object.keys(input.changes).sort();
30
+ const changeSummary = changedFields.length > 0 ? changedFields.join(", ") : "no fields";
31
+ return {
32
+ context,
33
+ actionName: "finance.payment_instrument.update",
34
+ actionVersion: "v1",
35
+ actionKind: "update",
36
+ status: "succeeded",
37
+ evaluatedRisk: "high",
38
+ targetType: target.type,
39
+ targetId: target.id,
40
+ routeOrToolName: "finance.payment_instrument.update",
41
+ authorizationSource: options.authorizationSource ?? "finance.payment_instrument.route",
42
+ idempotencyScope: null,
43
+ idempotencyKey: null,
44
+ idempotencyFingerprint: null,
45
+ mutationDetail: {
46
+ commandInputRef: `payment_instrument:${input.instrument.id}:update`,
47
+ commandResultRef: `payment_instrument:${input.instrument.id}`,
48
+ summary: `Payment instrument ${input.instrument.id} updated (${changeSummary})`,
49
+ reversalKind: "none",
50
+ },
51
+ };
52
+ }
53
+ export function buildPaymentInstrumentDeleteActionLedgerInput(context, input, options = {}) {
54
+ const target = getPaymentInstrumentLedgerTarget(input.instrument);
55
+ return {
56
+ context,
57
+ actionName: "finance.payment_instrument.delete",
58
+ actionVersion: "v1",
59
+ actionKind: "delete",
60
+ status: "succeeded",
61
+ evaluatedRisk: "high",
62
+ targetType: target.type,
63
+ targetId: target.id,
64
+ routeOrToolName: "finance.payment_instrument.delete",
65
+ authorizationSource: options.authorizationSource ?? "finance.payment_instrument.route",
66
+ idempotencyScope: null,
67
+ idempotencyKey: null,
68
+ idempotencyFingerprint: null,
69
+ mutationDetail: {
70
+ commandInputRef: `payment_instrument:${input.instrument.id}:delete`,
71
+ commandResultRef: null,
72
+ summary: `Payment instrument ${input.instrument.id} deleted`,
73
+ reversalKind: "none",
74
+ },
75
+ };
76
+ }
77
+ function getPaymentInstrumentLedgerTarget(instrument) {
78
+ if (instrument.personId)
79
+ return { type: "person", id: instrument.personId };
80
+ if (instrument.organizationId)
81
+ return { type: "organization", id: instrument.organizationId };
82
+ if (instrument.supplierId)
83
+ return { type: "supplier", id: instrument.supplierId };
84
+ if (instrument.channelId)
85
+ return { type: "channel", id: instrument.channelId };
86
+ return { type: "payment_instrument", id: instrument.id };
87
+ }
88
+ function getPaymentInstrumentOwnerRef(instrument) {
89
+ const target = getPaymentInstrumentLedgerTarget(instrument);
90
+ return `${target.type}:${target.id}`;
91
+ }
92
+ export async function buildPaymentSessionCreateActionLedgerInput(context, input, options = {}) {
93
+ const target = getPaymentSessionLedgerTarget(input.session);
94
+ const idempotencyKey = input.session.idempotencyKey;
95
+ return {
96
+ context,
97
+ actionName: "finance.payment_session.create",
98
+ actionVersion: "v1",
99
+ actionKind: "create",
100
+ status: "succeeded",
101
+ evaluatedRisk: "high",
102
+ targetType: target.type,
103
+ targetId: target.id,
104
+ routeOrToolName: "finance.payment_session.create",
105
+ authorizationSource: options.authorizationSource ?? "finance.payment_session.route",
106
+ idempotencyScope: idempotencyKey && target.id
107
+ ? `finance.payment_session:${target.type}:${target.id}:create`
108
+ : null,
109
+ idempotencyKey,
110
+ idempotencyFingerprint: idempotencyKey && target.id
111
+ ? await buildIdempotencyFingerprint({
112
+ actionName: "finance.payment_session.create",
113
+ actionVersion: "v1",
114
+ targetType: target.type,
115
+ targetId: target.id,
116
+ commandInput: {
117
+ paymentSessionId: input.session.id,
118
+ targetType: input.session.targetType,
119
+ targetId: input.session.targetId,
120
+ amountCents: input.session.amountCents,
121
+ currency: input.session.currency,
122
+ provider: input.session.provider,
123
+ idempotencyKey: input.session.idempotencyKey,
124
+ },
125
+ })
126
+ : null,
127
+ mutationDetail: {
128
+ commandInputRef: target.id
129
+ ? `${target.type}:${target.id}:payment_session`
130
+ : "payment_session:create",
131
+ commandResultRef: `payment_session:${input.session.id}`,
132
+ summary: `Payment session ${input.session.id} created for ${target.type} ${target.id ?? "unknown"}`,
133
+ reversalKind: "none",
134
+ },
135
+ };
136
+ }
137
+ export async function buildPaymentSessionCompletionActionLedgerInput(context, input, options = {}) {
138
+ const target = getPaymentSessionCompletionLedgerTarget(input.session);
139
+ const idempotencyKey = input.session.providerPaymentId ??
140
+ input.session.externalReference ??
141
+ input.session.idempotencyKey ??
142
+ null;
143
+ const idempotencyFingerprint = idempotencyKey
144
+ ? await buildIdempotencyFingerprint({
145
+ actionName: "finance.payment_session.complete",
146
+ actionVersion: "v1",
147
+ targetType: target.type,
148
+ targetId: target.id,
149
+ commandInput: {
150
+ paymentSessionId: input.session.id,
151
+ status: input.status,
152
+ providerPaymentId: input.session.providerPaymentId,
153
+ externalReference: input.session.externalReference,
154
+ paymentId: input.paymentId,
155
+ },
156
+ })
157
+ : null;
158
+ return {
159
+ context,
160
+ actionName: "finance.payment_session.complete",
161
+ actionVersion: "v1",
162
+ actionKind: "execute",
163
+ status: "succeeded",
164
+ evaluatedRisk: "high",
165
+ targetType: target.type,
166
+ targetId: target.id,
167
+ routeOrToolName: "finance.payment_session.complete",
168
+ authorizationSource: options.authorizationSource ?? "finance.payment_session.route",
169
+ idempotencyScope: idempotencyKey
170
+ ? `finance.payment_session:${input.session.id}:complete`
171
+ : null,
172
+ idempotencyKey,
173
+ idempotencyFingerprint,
174
+ mutationDetail: {
175
+ commandInputRef: `payment_session:${input.session.id}:complete`,
176
+ commandResultRef: input.paymentId ? `payment:${input.paymentId}` : null,
177
+ summary: `Payment session ${input.session.id} completed as ${input.status}`,
178
+ reversalKind: "none",
179
+ },
180
+ };
181
+ }
182
+ function getPaymentSessionCompletionLedgerTarget(session) {
183
+ return getPaymentSessionLedgerTarget(session);
184
+ }
185
+ function getPaymentSessionLedgerTarget(session) {
186
+ if (session.bookingId)
187
+ return { type: "booking", id: session.bookingId };
188
+ if (session.invoiceId)
189
+ return { type: "invoice", id: session.invoiceId };
190
+ if (session.orderId)
191
+ return { type: "order", id: session.orderId };
192
+ if (session.targetId && session.targetType !== "other") {
193
+ return { type: session.targetType, id: session.targetId };
194
+ }
195
+ return { type: "payment_session", id: session.id };
196
+ }
197
+ export function buildPaymentSessionUpdateActionLedgerInput(context, input, options = {}) {
198
+ const target = getPaymentSessionLedgerTarget(input.session);
199
+ const changedFields = Object.keys(input.changes).sort();
200
+ const changeSummary = changedFields.length > 0 ? changedFields.join(", ") : "no fields";
201
+ return {
202
+ context,
203
+ actionName: "finance.payment_session.update",
204
+ actionVersion: "v1",
205
+ actionKind: "update",
206
+ status: "succeeded",
207
+ evaluatedRisk: "high",
208
+ targetType: target.type,
209
+ targetId: target.id,
210
+ routeOrToolName: "finance.payment_session.update",
211
+ authorizationSource: options.authorizationSource ?? "finance.payment_session.route",
212
+ idempotencyScope: null,
213
+ idempotencyKey: null,
214
+ idempotencyFingerprint: null,
215
+ mutationDetail: {
216
+ commandInputRef: `payment_session:${input.session.id}:update`,
217
+ commandResultRef: `payment_session:${input.session.id}`,
218
+ summary: `Payment session ${input.session.id} updated (${changeSummary})`,
219
+ reversalKind: "none",
220
+ },
221
+ };
222
+ }
223
+ export function buildPaymentSessionRequiresRedirectActionLedgerInput(context, input, options = {}) {
224
+ return buildPaymentSessionStatusActionLedgerInput(context, {
225
+ session: input.session,
226
+ actionName: "finance.payment_session.requires_redirect",
227
+ actionKind: "update",
228
+ routeOrToolName: "finance.payment_session.requires_redirect",
229
+ commandInputRef: `payment_session:${input.session.id}:requires_redirect`,
230
+ commandResultRef: `payment_session:${input.session.id}`,
231
+ summary: `Payment session ${input.session.id} marked as requiring redirect`,
232
+ authorizationSource: options.authorizationSource ?? "finance.payment_session.route",
233
+ });
234
+ }
235
+ export function buildPaymentSessionFailedActionLedgerInput(context, input, options = {}) {
236
+ return buildPaymentSessionStatusActionLedgerInput(context, {
237
+ session: input.session,
238
+ actionName: "finance.payment_session.fail",
239
+ actionKind: "update",
240
+ routeOrToolName: "finance.payment_session.fail",
241
+ commandInputRef: `payment_session:${input.session.id}:fail`,
242
+ commandResultRef: `payment_session:${input.session.id}`,
243
+ summary: `Payment session ${input.session.id} marked as failed`,
244
+ authorizationSource: options.authorizationSource ?? "finance.payment_session.route",
245
+ });
246
+ }
247
+ export function buildPaymentSessionCancelledActionLedgerInput(context, input, options = {}) {
248
+ return buildPaymentSessionStatusActionLedgerInput(context, {
249
+ session: input.session,
250
+ actionName: "finance.payment_session.cancel",
251
+ actionKind: "update",
252
+ routeOrToolName: "finance.payment_session.cancel",
253
+ commandInputRef: `payment_session:${input.session.id}:cancel`,
254
+ commandResultRef: `payment_session:${input.session.id}`,
255
+ summary: `Payment session ${input.session.id} marked as cancelled`,
256
+ authorizationSource: options.authorizationSource ?? "finance.payment_session.route",
257
+ });
258
+ }
259
+ export function buildPaymentSessionExpiredActionLedgerInput(context, input, options = {}) {
260
+ return buildPaymentSessionStatusActionLedgerInput(context, {
261
+ session: input.session,
262
+ actionName: "finance.payment_session.expire",
263
+ actionKind: "update",
264
+ routeOrToolName: "finance.payment_session.expire",
265
+ commandInputRef: `payment_session:${input.session.id}:expire`,
266
+ commandResultRef: `payment_session:${input.session.id}`,
267
+ summary: `Payment session ${input.session.id} marked as expired`,
268
+ authorizationSource: options.authorizationSource ?? "finance.payment_session.route",
269
+ });
270
+ }
271
+ function buildPaymentSessionStatusActionLedgerInput(context, input) {
272
+ const target = getPaymentSessionLedgerTarget(input.session);
273
+ return {
274
+ context,
275
+ actionName: input.actionName,
276
+ actionVersion: "v1",
277
+ actionKind: input.actionKind,
278
+ status: "succeeded",
279
+ evaluatedRisk: "high",
280
+ targetType: target.type,
281
+ targetId: target.id,
282
+ routeOrToolName: input.routeOrToolName,
283
+ authorizationSource: input.authorizationSource,
284
+ idempotencyScope: null,
285
+ idempotencyKey: null,
286
+ idempotencyFingerprint: null,
287
+ mutationDetail: {
288
+ commandInputRef: input.commandInputRef,
289
+ commandResultRef: input.commandResultRef,
290
+ summary: input.summary,
291
+ reversalKind: "none",
292
+ },
293
+ };
294
+ }
@@ -0,0 +1,27 @@
1
+ import { type ActionLedgerRequestContextValues, type BuildActionLedgerMutationInput } from "@voyant-travel/action-ledger";
2
+ import type { supplierInvoices } from "./schema.js";
3
+ type SupplierInvoiceRecord = typeof supplierInvoices.$inferSelect;
4
+ export declare function buildSupplierInvoiceCreateActionLedgerInput(context: ActionLedgerRequestContextValues, input: {
5
+ invoice: SupplierInvoiceRecord;
6
+ }, options?: {
7
+ authorizationSource?: string | null;
8
+ }): Promise<BuildActionLedgerMutationInput>;
9
+ export declare function buildSupplierInvoiceUpdateActionLedgerInput(context: ActionLedgerRequestContextValues, input: {
10
+ invoice: SupplierInvoiceRecord;
11
+ changes: Record<string, unknown>;
12
+ }, options?: {
13
+ authorizationSource?: string | null;
14
+ }): BuildActionLedgerMutationInput;
15
+ export declare function buildSupplierInvoiceDeleteActionLedgerInput(context: ActionLedgerRequestContextValues, input: {
16
+ invoice: SupplierInvoiceRecord;
17
+ }, options?: {
18
+ authorizationSource?: string | null;
19
+ }): BuildActionLedgerMutationInput;
20
+ export declare function buildSupplierInvoiceAllocationsActionLedgerInput(context: ActionLedgerRequestContextValues, input: {
21
+ invoice: SupplierInvoiceRecord;
22
+ allocationCount: number;
23
+ }, options?: {
24
+ authorizationSource?: string | null;
25
+ }): BuildActionLedgerMutationInput;
26
+ export {};
27
+ //# sourceMappingURL=service-action-ledger-supplier-invoices.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-action-ledger-supplier-invoices.d.ts","sourceRoot":"","sources":["../src/service-action-ledger-supplier-invoices.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gCAAgC,EACrC,KAAK,8BAA8B,EAEpC,MAAM,8BAA8B,CAAA;AAErC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAEnD,KAAK,qBAAqB,GAAG,OAAO,gBAAgB,CAAC,YAAY,CAAA;AAIjE,wBAAsB,2CAA2C,CAC/D,OAAO,EAAE,gCAAgC,EACzC,KAAK,EAAE;IAAE,OAAO,EAAE,qBAAqB,CAAA;CAAE,EACzC,OAAO,GAAE;IAAE,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAO,GACpD,OAAO,CAAC,8BAA8B,CAAC,CAsCzC;AAED,wBAAgB,2CAA2C,CACzD,OAAO,EAAE,gCAAgC,EACzC,KAAK,EAAE;IAAE,OAAO,EAAE,qBAAqB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,EAC3E,OAAO,GAAE;IAAE,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAO,GACpD,8BAA8B,CAyBhC;AAED,wBAAgB,2CAA2C,CACzD,OAAO,EAAE,gCAAgC,EACzC,KAAK,EAAE;IAAE,OAAO,EAAE,qBAAqB,CAAA;CAAE,EACzC,OAAO,GAAE;IAAE,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAO,GACpD,8BAA8B,CAsBhC;AAED,wBAAgB,gDAAgD,CAC9D,OAAO,EAAE,gCAAgC,EACzC,KAAK,EAAE;IAAE,OAAO,EAAE,qBAAqB,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,EAClE,OAAO,GAAE;IAAE,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAO,GACpD,8BAA8B,CAsBhC"}
@@ -0,0 +1,111 @@
1
+ import { buildIdempotencyFingerprint, } from "@voyant-travel/action-ledger";
2
+ const TARGET_TYPE = "supplier_invoice";
3
+ export async function buildSupplierInvoiceCreateActionLedgerInput(context, input, options = {}) {
4
+ const idempotencyKey = `${input.invoice.supplierId}:${input.invoice.supplierInvoiceNo}`;
5
+ return {
6
+ context,
7
+ actionName: "finance.supplier_invoice.create",
8
+ actionVersion: "v1",
9
+ actionKind: "create",
10
+ status: "succeeded",
11
+ evaluatedRisk: "high",
12
+ targetType: TARGET_TYPE,
13
+ targetId: input.invoice.id,
14
+ routeOrToolName: "finance.supplier_invoice.create",
15
+ authorizationSource: options.authorizationSource ?? "finance.supplier_invoice.route",
16
+ idempotencyScope: `finance.supplier:${input.invoice.supplierId}:supplier_invoice`,
17
+ idempotencyKey,
18
+ idempotencyFingerprint: await buildIdempotencyFingerprint({
19
+ actionName: "finance.supplier_invoice.create",
20
+ actionVersion: "v1",
21
+ targetType: TARGET_TYPE,
22
+ targetId: input.invoice.id,
23
+ commandInput: {
24
+ supplierInvoiceId: input.invoice.id,
25
+ supplierId: input.invoice.supplierId,
26
+ supplierInvoiceNo: input.invoice.supplierInvoiceNo,
27
+ currency: input.invoice.currency,
28
+ totalCents: input.invoice.totalCents,
29
+ issueDate: input.invoice.issueDate,
30
+ status: input.invoice.status,
31
+ },
32
+ }),
33
+ mutationDetail: {
34
+ commandInputRef: `supplier:${input.invoice.supplierId}:supplier_invoice`,
35
+ commandResultRef: `supplier_invoice:${input.invoice.id}`,
36
+ summary: `Supplier invoice ${input.invoice.supplierInvoiceNo} recorded for supplier ${input.invoice.supplierId}`,
37
+ reversalKind: "domain_command",
38
+ },
39
+ };
40
+ }
41
+ export function buildSupplierInvoiceUpdateActionLedgerInput(context, input, options = {}) {
42
+ const changedFields = Object.keys(input.changes).sort();
43
+ const changeSummary = changedFields.length > 0 ? changedFields.join(", ") : "no fields";
44
+ return {
45
+ context,
46
+ actionName: "finance.supplier_invoice.update",
47
+ actionVersion: "v1",
48
+ actionKind: "update",
49
+ status: "succeeded",
50
+ evaluatedRisk: "high",
51
+ targetType: TARGET_TYPE,
52
+ targetId: input.invoice.id,
53
+ routeOrToolName: "finance.supplier_invoice.update",
54
+ authorizationSource: options.authorizationSource ?? "finance.supplier_invoice.route",
55
+ idempotencyScope: null,
56
+ idempotencyKey: null,
57
+ idempotencyFingerprint: null,
58
+ mutationDetail: {
59
+ commandInputRef: `supplier_invoice:${input.invoice.id}:update`,
60
+ commandResultRef: `supplier_invoice:${input.invoice.id}`,
61
+ summary: `Supplier invoice ${input.invoice.id} updated (${changeSummary})`,
62
+ reversalKind: "none",
63
+ },
64
+ };
65
+ }
66
+ export function buildSupplierInvoiceDeleteActionLedgerInput(context, input, options = {}) {
67
+ return {
68
+ context,
69
+ actionName: "finance.supplier_invoice.delete",
70
+ actionVersion: "v1",
71
+ actionKind: "delete",
72
+ status: "succeeded",
73
+ evaluatedRisk: "high",
74
+ targetType: TARGET_TYPE,
75
+ targetId: input.invoice.id,
76
+ routeOrToolName: "finance.supplier_invoice.delete",
77
+ authorizationSource: options.authorizationSource ?? "finance.supplier_invoice.route",
78
+ idempotencyScope: null,
79
+ idempotencyKey: null,
80
+ idempotencyFingerprint: null,
81
+ mutationDetail: {
82
+ commandInputRef: `supplier_invoice:${input.invoice.id}:delete`,
83
+ commandResultRef: `supplier_invoice:${input.invoice.id}`,
84
+ summary: `Supplier invoice ${input.invoice.id} deleted`,
85
+ reversalKind: "none",
86
+ },
87
+ };
88
+ }
89
+ export function buildSupplierInvoiceAllocationsActionLedgerInput(context, input, options = {}) {
90
+ return {
91
+ context,
92
+ actionName: "finance.supplier_invoice.set_allocations",
93
+ actionVersion: "v1",
94
+ actionKind: "update",
95
+ status: "succeeded",
96
+ evaluatedRisk: "high",
97
+ targetType: TARGET_TYPE,
98
+ targetId: input.invoice.id,
99
+ routeOrToolName: "finance.supplier_invoice.set_allocations",
100
+ authorizationSource: options.authorizationSource ?? "finance.supplier_invoice.route",
101
+ idempotencyScope: null,
102
+ idempotencyKey: null,
103
+ idempotencyFingerprint: null,
104
+ mutationDetail: {
105
+ commandInputRef: `supplier_invoice:${input.invoice.id}:allocations`,
106
+ commandResultRef: `supplier_invoice:${input.invoice.id}`,
107
+ summary: `Supplier invoice ${input.invoice.id} allocations set (${input.allocationCount})`,
108
+ reversalKind: "none",
109
+ },
110
+ };
111
+ }
@@ -0,0 +1,21 @@
1
+ import { type ActionLedgerRequestContextValues, type BuildActionLedgerMutationInput } from "@voyant-travel/action-ledger";
2
+ import type { z } from "zod";
3
+ import type { supplierPayments } from "./schema.js";
4
+ import type { updateSupplierPaymentSchema } from "./validation.js";
5
+ type UpdateSupplierPaymentInput = z.infer<typeof updateSupplierPaymentSchema>;
6
+ type SupplierPaymentRecord = typeof supplierPayments.$inferSelect;
7
+ type SupplierPaymentCreateLedgerInput = {
8
+ payment: SupplierPaymentRecord;
9
+ };
10
+ type SupplierPaymentUpdateLedgerInput = {
11
+ payment: SupplierPaymentRecord;
12
+ changes: UpdateSupplierPaymentInput;
13
+ };
14
+ export declare function buildSupplierPaymentCreateActionLedgerInput(context: ActionLedgerRequestContextValues, input: SupplierPaymentCreateLedgerInput, options?: {
15
+ authorizationSource?: string | null;
16
+ }): Promise<BuildActionLedgerMutationInput>;
17
+ export declare function buildSupplierPaymentUpdateActionLedgerInput(context: ActionLedgerRequestContextValues, input: SupplierPaymentUpdateLedgerInput, options?: {
18
+ authorizationSource?: string | null;
19
+ }): BuildActionLedgerMutationInput;
20
+ export {};
21
+ //# sourceMappingURL=service-action-ledger-supplier-payments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-action-ledger-supplier-payments.d.ts","sourceRoot":"","sources":["../src/service-action-ledger-supplier-payments.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gCAAgC,EACrC,KAAK,8BAA8B,EAEpC,MAAM,8BAA8B,CAAA;AACrC,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AACnD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAA;AAElE,KAAK,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAA;AAC7E,KAAK,qBAAqB,GAAG,OAAO,gBAAgB,CAAC,YAAY,CAAA;AAEjE,KAAK,gCAAgC,GAAG;IACtC,OAAO,EAAE,qBAAqB,CAAA;CAC/B,CAAA;AACD,KAAK,gCAAgC,GAAG;IACtC,OAAO,EAAE,qBAAqB,CAAA;IAC9B,OAAO,EAAE,0BAA0B,CAAA;CACpC,CAAA;AAiCD,wBAAsB,2CAA2C,CAC/D,OAAO,EAAE,gCAAgC,EACzC,KAAK,EAAE,gCAAgC,EACvC,OAAO,GAAE;IACP,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC/B,GACL,OAAO,CAAC,8BAA8B,CAAC,CA4CzC;AAED,wBAAgB,2CAA2C,CACzD,OAAO,EAAE,gCAAgC,EACzC,KAAK,EAAE,gCAAgC,EACvC,OAAO,GAAE;IACP,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC/B,GACL,8BAA8B,CA0BhC"}
@@ -0,0 +1,97 @@
1
+ import { buildIdempotencyFingerprint, } from "@voyant-travel/action-ledger";
2
+ /**
3
+ * AP payments may settle a whole supplier invoice (no booking) or a
4
+ * booking-scoped supplier service. The ledger targets the booking when present,
5
+ * otherwise the supplier invoice (§5.4).
6
+ */
7
+ function resolvePaymentTarget(payment) {
8
+ if (payment.bookingId) {
9
+ return {
10
+ targetType: "booking",
11
+ targetId: payment.bookingId,
12
+ scopeRef: `booking:${payment.bookingId}`,
13
+ };
14
+ }
15
+ if (payment.supplierInvoiceId) {
16
+ return {
17
+ targetType: "supplier_invoice",
18
+ targetId: payment.supplierInvoiceId,
19
+ scopeRef: `supplier_invoice:${payment.supplierInvoiceId}`,
20
+ };
21
+ }
22
+ return {
23
+ targetType: "supplier_payment",
24
+ targetId: payment.id,
25
+ scopeRef: `supplier_payment:${payment.id}`,
26
+ };
27
+ }
28
+ export async function buildSupplierPaymentCreateActionLedgerInput(context, input, options = {}) {
29
+ const idempotencyKey = input.payment.referenceNumber;
30
+ const { targetType, targetId, scopeRef } = resolvePaymentTarget(input.payment);
31
+ return {
32
+ context,
33
+ actionName: "finance.supplier_payment.create",
34
+ actionVersion: "v1",
35
+ actionKind: "create",
36
+ status: "succeeded",
37
+ evaluatedRisk: "high",
38
+ targetType,
39
+ targetId,
40
+ routeOrToolName: "finance.supplier_payment.create",
41
+ authorizationSource: options.authorizationSource ?? "finance.supplier_payment.route",
42
+ idempotencyScope: idempotencyKey ? `finance.${scopeRef}:supplier_payment` : null,
43
+ idempotencyKey,
44
+ idempotencyFingerprint: idempotencyKey
45
+ ? await buildIdempotencyFingerprint({
46
+ actionName: "finance.supplier_payment.create",
47
+ actionVersion: "v1",
48
+ targetType,
49
+ targetId,
50
+ commandInput: {
51
+ supplierPaymentId: input.payment.id,
52
+ bookingId: input.payment.bookingId,
53
+ supplierInvoiceId: input.payment.supplierInvoiceId,
54
+ supplierId: input.payment.supplierId,
55
+ amountCents: input.payment.amountCents,
56
+ currency: input.payment.currency,
57
+ paymentMethod: input.payment.paymentMethod,
58
+ paymentDate: input.payment.paymentDate,
59
+ referenceNumber: input.payment.referenceNumber,
60
+ status: input.payment.status,
61
+ },
62
+ })
63
+ : null,
64
+ mutationDetail: {
65
+ commandInputRef: `${scopeRef}:supplier_payment`,
66
+ commandResultRef: `supplier_payment:${input.payment.id}`,
67
+ summary: `Supplier payment ${input.payment.id} recorded against ${scopeRef}`,
68
+ reversalKind: "none",
69
+ },
70
+ };
71
+ }
72
+ export function buildSupplierPaymentUpdateActionLedgerInput(context, input, options = {}) {
73
+ const changedFields = Object.keys(input.changes).sort();
74
+ const changeSummary = changedFields.length > 0 ? changedFields.join(", ") : "no fields";
75
+ const { targetType, targetId } = resolvePaymentTarget(input.payment);
76
+ return {
77
+ context,
78
+ actionName: "finance.supplier_payment.update",
79
+ actionVersion: "v1",
80
+ actionKind: "update",
81
+ status: "succeeded",
82
+ evaluatedRisk: "high",
83
+ targetType,
84
+ targetId,
85
+ routeOrToolName: "finance.supplier_payment.update",
86
+ authorizationSource: options.authorizationSource ?? "finance.supplier_payment.route",
87
+ idempotencyScope: null,
88
+ idempotencyKey: null,
89
+ idempotencyFingerprint: null,
90
+ mutationDetail: {
91
+ commandInputRef: `supplier_payment:${input.payment.id}:update`,
92
+ commandResultRef: `supplier_payment:${input.payment.id}`,
93
+ summary: `Supplier payment ${input.payment.id} updated (${changeSummary})`,
94
+ reversalKind: "none",
95
+ },
96
+ };
97
+ }
@@ -0,0 +1,7 @@
1
+ export * from "./service-action-ledger-accounting.js";
2
+ export * from "./service-action-ledger-booking-payments.js";
3
+ export * from "./service-action-ledger-bookings.js";
4
+ export * from "./service-action-ledger-payment-authorizations.js";
5
+ export * from "./service-action-ledger-payment-sessions.js";
6
+ export * from "./service-action-ledger-supplier-payments.js";
7
+ //# sourceMappingURL=service-action-ledger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-action-ledger.d.ts","sourceRoot":"","sources":["../src/service-action-ledger.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAA;AACrD,cAAc,6CAA6C,CAAA;AAC3D,cAAc,qCAAqC,CAAA;AACnD,cAAc,mDAAmD,CAAA;AACjE,cAAc,6CAA6C,CAAA;AAC3D,cAAc,8CAA8C,CAAA"}
@@ -0,0 +1,6 @@
1
+ export * from "./service-action-ledger-accounting.js";
2
+ export * from "./service-action-ledger-booking-payments.js";
3
+ export * from "./service-action-ledger-bookings.js";
4
+ export * from "./service-action-ledger-payment-authorizations.js";
5
+ export * from "./service-action-ledger-payment-sessions.js";
6
+ export * from "./service-action-ledger-supplier-payments.js";
@@ -0,0 +1,96 @@
1
+ import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
2
+ import { invoices } from "./schema.js";
3
+ type InvoiceStatus = (typeof invoices.$inferSelect)["status"];
4
+ type InvoiceType = Extract<(typeof invoices.$inferSelect)["invoiceType"], "invoice" | "proforma">;
5
+ export interface FinanceAggregateOutstandingInvoice {
6
+ id: string;
7
+ invoiceNumber: string | null;
8
+ bookingId: string | null;
9
+ status: InvoiceStatus;
10
+ currency: string;
11
+ totalCents: number;
12
+ balanceDueCents: number;
13
+ issueDate: string | null;
14
+ dueDate: string | null;
15
+ }
16
+ export interface FinanceAggregates {
17
+ total: number;
18
+ countsByStatus: Array<{
19
+ status: InvoiceStatus;
20
+ count: number;
21
+ }>;
22
+ counts: {
23
+ invoices: {
24
+ issued: number;
25
+ paid: number;
26
+ void: number;
27
+ overdue: number;
28
+ };
29
+ proformas: {
30
+ issued: number;
31
+ converted: number;
32
+ void: number;
33
+ };
34
+ paymentSessions: {
35
+ pending: number;
36
+ paid: number;
37
+ failed: number;
38
+ };
39
+ };
40
+ totals: Array<{
41
+ currency: string;
42
+ invoiced: number;
43
+ collected: number;
44
+ outstanding: number;
45
+ refunded: number;
46
+ }>;
47
+ /** Issued total (total_cents) grouped by UTC yearMonth + currency. Void excluded. */
48
+ monthlyRevenue: Array<{
49
+ yearMonth: string;
50
+ currency: string;
51
+ totalCents: number;
52
+ }>;
53
+ /** Invoice count per UTC yearMonth, all statuses in range. */
54
+ monthlyInvoiceCounts: Array<{
55
+ yearMonth: string;
56
+ count: number;
57
+ }>;
58
+ /**
59
+ * Sum of `balance_due_cents` for invoices still expecting payment — issued /
60
+ * partially_paid / overdue — grouped by currency. Matches the "how much
61
+ * are we owed" dashboard card.
62
+ */
63
+ outstanding: Array<{
64
+ currency: string;
65
+ balanceDueCents: number;
66
+ count: number;
67
+ }>;
68
+ /**
69
+ * Same as outstanding but restricted to invoices whose `due_date` has
70
+ * passed (`due_date < today`). Counts remaining balance, not the original
71
+ * total, so partial payments reduce the number.
72
+ */
73
+ overdue: Array<{
74
+ currency: string;
75
+ balanceDueCents: number;
76
+ count: number;
77
+ }>;
78
+ /**
79
+ * Bounded top-N slice of outstanding invoices ordered by `due_date`
80
+ * (oldest first; nulls last) so the dashboard can render the
81
+ * "needs collection" list without a separate paginated request.
82
+ * Default 5, max 20 — caller bounds via `outstandingTopLimit`.
83
+ */
84
+ outstandingTopN: FinanceAggregateOutstandingInvoice[];
85
+ }
86
+ export declare function getFinanceAggregates(db: PostgresJsDatabase, options?: {
87
+ range?: "this_month" | "last_month" | "year_to_date" | "all_time" | "custom";
88
+ from?: string;
89
+ to?: string;
90
+ currency?: string[];
91
+ invoiceType?: InvoiceType[];
92
+ status?: InvoiceStatus[];
93
+ outstandingTopLimit?: number;
94
+ }): Promise<FinanceAggregates>;
95
+ export {};
96
+ //# sourceMappingURL=service-aggregates.d.ts.map