@voyantjs/finance 0.52.1 → 0.52.3
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.
- package/dist/action-ledger-drift.d.ts +29 -0
- package/dist/action-ledger-drift.d.ts.map +1 -0
- package/dist/action-ledger-drift.js +163 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/routes-action-ledger.d.ts +181 -0
- package/dist/routes-action-ledger.d.ts.map +1 -0
- package/dist/routes-action-ledger.js +142 -0
- package/dist/routes-documents.d.ts +8 -8
- package/dist/routes-public.d.ts +48 -48
- package/dist/routes-settlement.d.ts +1 -1
- package/dist/routes-shared.d.ts +12 -0
- package/dist/routes-shared.d.ts.map +1 -1
- package/dist/routes.d.ts +288 -217
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +280 -46
- package/dist/schema.d.ts +22 -22
- package/dist/service-action-ledger-accounting.d.ts +77 -0
- package/dist/service-action-ledger-accounting.d.ts.map +1 -0
- package/dist/service-action-ledger-accounting.js +307 -0
- package/dist/service-action-ledger-booking-payments.d.ts +48 -0
- package/dist/service-action-ledger-booking-payments.d.ts.map +1 -0
- package/dist/service-action-ledger-booking-payments.js +178 -0
- package/dist/service-action-ledger-payment-authorizations.d.ts +48 -0
- package/dist/service-action-ledger-payment-authorizations.d.ts.map +1 -0
- package/dist/service-action-ledger-payment-authorizations.js +209 -0
- package/dist/service-action-ledger-payment-sessions.d.ts +83 -0
- package/dist/service-action-ledger-payment-sessions.d.ts.map +1 -0
- package/dist/service-action-ledger-payment-sessions.js +294 -0
- package/dist/service-action-ledger-supplier-payments.d.ts +21 -0
- package/dist/service-action-ledger-supplier-payments.d.ts.map +1 -0
- package/dist/service-action-ledger-supplier-payments.js +70 -0
- package/dist/service-action-ledger.d.ts +6 -0
- package/dist/service-action-ledger.d.ts.map +1 -0
- package/dist/service-action-ledger.js +5 -0
- package/dist/service-booking-create.d.ts +50 -8
- package/dist/service-booking-create.d.ts.map +1 -1
- package/dist/service-booking-create.js +58 -1
- package/dist/service-bookings-dual-create.d.ts +50 -8
- package/dist/service-bookings-dual-create.d.ts.map +1 -1
- package/dist/service-issue.d.ts +42 -12
- package/dist/service-issue.d.ts.map +1 -1
- package/dist/service-issue.js +141 -4
- package/dist/service-public.d.ts +13 -13
- package/dist/service-vouchers.d.ts +10 -10
- package/dist/service.d.ts +291 -279
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +753 -238
- package/dist/validation-billing.d.ts +37 -37
- package/dist/validation-payments.d.ts +102 -102
- package/dist/validation-public.d.ts +45 -45
- package/dist/validation-shared.d.ts +32 -32
- package/dist/validation-vouchers.d.ts +2 -2
- package/package.json +13 -7
package/dist/routes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAC7D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAA;AA+I7C,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wCAmiDtB,CAAA;AAEJ,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAA;AAChD,MAAM,MAAM,mBAAmB,GAAG,OAAO,mBAAmB,CAAA"}
|
package/dist/routes.js
CHANGED
|
@@ -31,6 +31,31 @@ function getFinanceRouteRuntime(c) {
|
|
|
31
31
|
return undefined;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
+
function getActionLedgerRequestContext(c) {
|
|
35
|
+
const context = {
|
|
36
|
+
userId: c.get("userId") ?? null,
|
|
37
|
+
agentId: c.get("agentId") ?? null,
|
|
38
|
+
workflowPrincipalId: c.get("workflowPrincipalId") ?? null,
|
|
39
|
+
principalSubtype: c.get("principalSubtype") ?? null,
|
|
40
|
+
sessionId: c.get("sessionId") ?? null,
|
|
41
|
+
apiTokenId: c.get("apiTokenId") ?? c.get("apiKeyId") ?? null,
|
|
42
|
+
callerType: c.get("callerType") ?? null,
|
|
43
|
+
actor: c.get("actor") ?? null,
|
|
44
|
+
isInternalRequest: c.get("isInternalRequest") ?? false,
|
|
45
|
+
organizationId: c.get("organizationId") ?? null,
|
|
46
|
+
workflowRunId: c.get("workflowRunId") ?? null,
|
|
47
|
+
workflowStepId: c.get("workflowStepId") ?? null,
|
|
48
|
+
correlationId: c.req.header("x-correlation-id") ?? c.req.header("x-request-id") ?? null,
|
|
49
|
+
};
|
|
50
|
+
if (context.userId ||
|
|
51
|
+
context.agentId ||
|
|
52
|
+
context.workflowPrincipalId ||
|
|
53
|
+
context.apiTokenId ||
|
|
54
|
+
context.isInternalRequest) {
|
|
55
|
+
return context;
|
|
56
|
+
}
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
34
59
|
export const financeRoutes = new Hono()
|
|
35
60
|
// ========================================================================
|
|
36
61
|
// Dashboard aggregates
|
|
@@ -47,8 +72,13 @@ export const financeRoutes = new Hono()
|
|
|
47
72
|
return c.json(await financeService.listPaymentSessions(c.get("db"), query));
|
|
48
73
|
})
|
|
49
74
|
.post("/payment-sessions", async (c) => {
|
|
75
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
50
76
|
return c.json({
|
|
51
|
-
data: await financeService.createPaymentSession(c.get("db"), await parseJsonBody(c, insertPaymentSessionSchema)
|
|
77
|
+
data: await financeService.createPaymentSession(c.get("db"), await parseJsonBody(c, insertPaymentSessionSchema), {
|
|
78
|
+
eventBus: runtime?.eventBus,
|
|
79
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
80
|
+
actionLedgerAuthorizationSource: "finance.payment_session.route",
|
|
81
|
+
}),
|
|
52
82
|
}, 201);
|
|
53
83
|
})
|
|
54
84
|
.get("/payment-sessions/:id", async (c) => {
|
|
@@ -58,45 +88,67 @@ export const financeRoutes = new Hono()
|
|
|
58
88
|
return c.json({ data: row });
|
|
59
89
|
})
|
|
60
90
|
.patch("/payment-sessions/:id", async (c) => {
|
|
61
|
-
const
|
|
91
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
92
|
+
const row = await financeService.updatePaymentSession(c.get("db"), c.req.param("id"), await parseJsonBody(c, updatePaymentSessionSchema), {
|
|
93
|
+
eventBus: runtime?.eventBus,
|
|
94
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
95
|
+
actionLedgerAuthorizationSource: "finance.payment_session.route",
|
|
96
|
+
});
|
|
62
97
|
if (!row)
|
|
63
98
|
return c.json({ error: "Payment session not found" }, 404);
|
|
64
99
|
return c.json({ data: row });
|
|
65
100
|
})
|
|
66
101
|
.post("/payment-sessions/:id/requires-redirect", async (c) => {
|
|
67
|
-
const
|
|
102
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
103
|
+
const row = await financeService.markPaymentSessionRequiresRedirect(c.get("db"), c.req.param("id"), await parseJsonBody(c, markPaymentSessionRequiresRedirectSchema), {
|
|
104
|
+
eventBus: runtime?.eventBus,
|
|
105
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
106
|
+
actionLedgerAuthorizationSource: "finance.payment_session.route",
|
|
107
|
+
});
|
|
68
108
|
if (!row)
|
|
69
109
|
return c.json({ error: "Payment session not found" }, 404);
|
|
70
110
|
return c.json({ data: row });
|
|
71
111
|
})
|
|
72
112
|
.post("/payment-sessions/:id/complete", async (c) => {
|
|
73
|
-
const runtime = (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
})();
|
|
81
|
-
const row = await financeService.completePaymentSession(c.get("db"), c.req.param("id"), await parseJsonBody(c, completePaymentSessionSchema), { eventBus: runtime?.eventBus });
|
|
113
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
114
|
+
const row = await financeService.completePaymentSession(c.get("db"), c.req.param("id"), await parseJsonBody(c, completePaymentSessionSchema), {
|
|
115
|
+
eventBus: runtime?.eventBus,
|
|
116
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
117
|
+
actionLedgerAuthorizationSource: "finance.payment_session.route",
|
|
118
|
+
});
|
|
82
119
|
if (!row)
|
|
83
120
|
return c.json({ error: "Payment session not found" }, 404);
|
|
84
121
|
return c.json({ data: row });
|
|
85
122
|
})
|
|
86
123
|
.post("/payment-sessions/:id/fail", async (c) => {
|
|
87
|
-
const
|
|
124
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
125
|
+
const row = await financeService.failPaymentSession(c.get("db"), c.req.param("id"), await parseJsonBody(c, failPaymentSessionSchema), {
|
|
126
|
+
eventBus: runtime?.eventBus,
|
|
127
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
128
|
+
actionLedgerAuthorizationSource: "finance.payment_session.route",
|
|
129
|
+
});
|
|
88
130
|
if (!row)
|
|
89
131
|
return c.json({ error: "Payment session not found" }, 404);
|
|
90
132
|
return c.json({ data: row });
|
|
91
133
|
})
|
|
92
134
|
.post("/payment-sessions/:id/cancel", async (c) => {
|
|
93
|
-
const
|
|
135
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
136
|
+
const row = await financeService.cancelPaymentSession(c.get("db"), c.req.param("id"), await parseJsonBody(c, cancelPaymentSessionSchema), {
|
|
137
|
+
eventBus: runtime?.eventBus,
|
|
138
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
139
|
+
actionLedgerAuthorizationSource: "finance.payment_session.route",
|
|
140
|
+
});
|
|
94
141
|
if (!row)
|
|
95
142
|
return c.json({ error: "Payment session not found" }, 404);
|
|
96
143
|
return c.json({ data: row });
|
|
97
144
|
})
|
|
98
145
|
.post("/payment-sessions/:id/expire", async (c) => {
|
|
99
|
-
const
|
|
146
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
147
|
+
const row = await financeService.expirePaymentSession(c.get("db"), c.req.param("id"), await parseJsonBody(c, expirePaymentSessionSchema), {
|
|
148
|
+
eventBus: runtime?.eventBus,
|
|
149
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
150
|
+
actionLedgerAuthorizationSource: "finance.payment_session.route",
|
|
151
|
+
});
|
|
100
152
|
if (!row)
|
|
101
153
|
return c.json({ error: "Payment session not found" }, 404);
|
|
102
154
|
return c.json({ data: row });
|
|
@@ -109,8 +161,13 @@ export const financeRoutes = new Hono()
|
|
|
109
161
|
return c.json(await financeService.listPaymentInstruments(c.get("db"), query));
|
|
110
162
|
})
|
|
111
163
|
.post("/payment-instruments", async (c) => {
|
|
164
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
112
165
|
return c.json({
|
|
113
|
-
data: await financeService.createPaymentInstrument(c.get("db"), await parseJsonBody(c, insertPaymentInstrumentSchema)
|
|
166
|
+
data: await financeService.createPaymentInstrument(c.get("db"), await parseJsonBody(c, insertPaymentInstrumentSchema), {
|
|
167
|
+
eventBus: runtime?.eventBus,
|
|
168
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
169
|
+
actionLedgerAuthorizationSource: "finance.payment_instrument.route",
|
|
170
|
+
}),
|
|
114
171
|
}, 201);
|
|
115
172
|
})
|
|
116
173
|
.get("/payment-instruments/:id", async (c) => {
|
|
@@ -120,13 +177,23 @@ export const financeRoutes = new Hono()
|
|
|
120
177
|
return c.json({ data: row });
|
|
121
178
|
})
|
|
122
179
|
.patch("/payment-instruments/:id", async (c) => {
|
|
123
|
-
const
|
|
180
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
181
|
+
const row = await financeService.updatePaymentInstrument(c.get("db"), c.req.param("id"), await parseJsonBody(c, updatePaymentInstrumentSchema), {
|
|
182
|
+
eventBus: runtime?.eventBus,
|
|
183
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
184
|
+
actionLedgerAuthorizationSource: "finance.payment_instrument.route",
|
|
185
|
+
});
|
|
124
186
|
if (!row)
|
|
125
187
|
return c.json({ error: "Payment instrument not found" }, 404);
|
|
126
188
|
return c.json({ data: row });
|
|
127
189
|
})
|
|
128
190
|
.delete("/payment-instruments/:id", async (c) => {
|
|
129
|
-
const
|
|
191
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
192
|
+
const row = await financeService.deletePaymentInstrument(c.get("db"), c.req.param("id"), {
|
|
193
|
+
eventBus: runtime?.eventBus,
|
|
194
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
195
|
+
actionLedgerAuthorizationSource: "finance.payment_instrument.route",
|
|
196
|
+
});
|
|
130
197
|
if (!row)
|
|
131
198
|
return c.json({ error: "Payment instrument not found" }, 404);
|
|
132
199
|
return c.json({ success: true });
|
|
@@ -139,8 +206,13 @@ export const financeRoutes = new Hono()
|
|
|
139
206
|
return c.json(await financeService.listPaymentAuthorizations(c.get("db"), query));
|
|
140
207
|
})
|
|
141
208
|
.post("/payment-authorizations", async (c) => {
|
|
209
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
142
210
|
return c.json({
|
|
143
|
-
data: await financeService.createPaymentAuthorization(c.get("db"), await parseJsonBody(c, insertPaymentAuthorizationSchema)
|
|
211
|
+
data: await financeService.createPaymentAuthorization(c.get("db"), await parseJsonBody(c, insertPaymentAuthorizationSchema), {
|
|
212
|
+
eventBus: runtime?.eventBus,
|
|
213
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
214
|
+
actionLedgerAuthorizationSource: "finance.payment_authorization.route",
|
|
215
|
+
}),
|
|
144
216
|
}, 201);
|
|
145
217
|
})
|
|
146
218
|
.get("/payment-authorizations/:id", async (c) => {
|
|
@@ -150,13 +222,23 @@ export const financeRoutes = new Hono()
|
|
|
150
222
|
return c.json({ data: row });
|
|
151
223
|
})
|
|
152
224
|
.patch("/payment-authorizations/:id", async (c) => {
|
|
153
|
-
const
|
|
225
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
226
|
+
const row = await financeService.updatePaymentAuthorization(c.get("db"), c.req.param("id"), await parseJsonBody(c, updatePaymentAuthorizationSchema), {
|
|
227
|
+
eventBus: runtime?.eventBus,
|
|
228
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
229
|
+
actionLedgerAuthorizationSource: "finance.payment_authorization.route",
|
|
230
|
+
});
|
|
154
231
|
if (!row)
|
|
155
232
|
return c.json({ error: "Payment authorization not found" }, 404);
|
|
156
233
|
return c.json({ data: row });
|
|
157
234
|
})
|
|
158
235
|
.delete("/payment-authorizations/:id", async (c) => {
|
|
159
|
-
const
|
|
236
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
237
|
+
const row = await financeService.deletePaymentAuthorization(c.get("db"), c.req.param("id"), {
|
|
238
|
+
eventBus: runtime?.eventBus,
|
|
239
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
240
|
+
actionLedgerAuthorizationSource: "finance.payment_authorization.route",
|
|
241
|
+
});
|
|
160
242
|
if (!row)
|
|
161
243
|
return c.json({ error: "Payment authorization not found" }, 404);
|
|
162
244
|
return c.json({ success: true });
|
|
@@ -169,8 +251,13 @@ export const financeRoutes = new Hono()
|
|
|
169
251
|
return c.json(await financeService.listPaymentCaptures(c.get("db"), query));
|
|
170
252
|
})
|
|
171
253
|
.post("/payment-captures", async (c) => {
|
|
254
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
172
255
|
return c.json({
|
|
173
|
-
data: await financeService.createPaymentCapture(c.get("db"), await parseJsonBody(c, insertPaymentCaptureSchema)
|
|
256
|
+
data: await financeService.createPaymentCapture(c.get("db"), await parseJsonBody(c, insertPaymentCaptureSchema), {
|
|
257
|
+
eventBus: runtime?.eventBus,
|
|
258
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
259
|
+
actionLedgerAuthorizationSource: "finance.payment_capture.route",
|
|
260
|
+
}),
|
|
174
261
|
}, 201);
|
|
175
262
|
})
|
|
176
263
|
.get("/payment-captures/:id", async (c) => {
|
|
@@ -180,13 +267,23 @@ export const financeRoutes = new Hono()
|
|
|
180
267
|
return c.json({ data: row });
|
|
181
268
|
})
|
|
182
269
|
.patch("/payment-captures/:id", async (c) => {
|
|
183
|
-
const
|
|
270
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
271
|
+
const row = await financeService.updatePaymentCapture(c.get("db"), c.req.param("id"), await parseJsonBody(c, updatePaymentCaptureSchema), {
|
|
272
|
+
eventBus: runtime?.eventBus,
|
|
273
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
274
|
+
actionLedgerAuthorizationSource: "finance.payment_capture.route",
|
|
275
|
+
});
|
|
184
276
|
if (!row)
|
|
185
277
|
return c.json({ error: "Payment capture not found" }, 404);
|
|
186
278
|
return c.json({ data: row });
|
|
187
279
|
})
|
|
188
280
|
.delete("/payment-captures/:id", async (c) => {
|
|
189
|
-
const
|
|
281
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
282
|
+
const row = await financeService.deletePaymentCapture(c.get("db"), c.req.param("id"), {
|
|
283
|
+
eventBus: runtime?.eventBus,
|
|
284
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
285
|
+
actionLedgerAuthorizationSource: "finance.payment_capture.route",
|
|
286
|
+
});
|
|
190
287
|
if (!row)
|
|
191
288
|
return c.json({ error: "Payment capture not found" }, 404);
|
|
192
289
|
return c.json({ success: true });
|
|
@@ -218,21 +315,36 @@ export const financeRoutes = new Hono()
|
|
|
218
315
|
});
|
|
219
316
|
})
|
|
220
317
|
.post("/bookings/:bookingId/payment-schedules", async (c) => {
|
|
221
|
-
const
|
|
318
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
319
|
+
const row = await financeService.createBookingPaymentSchedule(c.get("db"), c.req.param("bookingId"), await parseJsonBody(c, insertBookingPaymentScheduleSchema), {
|
|
320
|
+
eventBus: runtime?.eventBus,
|
|
321
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
322
|
+
actionLedgerAuthorizationSource: "finance.booking_payment_schedule.route",
|
|
323
|
+
});
|
|
222
324
|
if (!row) {
|
|
223
325
|
return c.json({ error: "Booking not found" }, 404);
|
|
224
326
|
}
|
|
225
327
|
return c.json({ data: row }, 201);
|
|
226
328
|
})
|
|
227
329
|
.post("/bookings/:bookingId/payment-schedules/default-plan", async (c) => {
|
|
228
|
-
const
|
|
330
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
331
|
+
const rows = await financeService.applyDefaultBookingPaymentPlan(c.get("db"), c.req.param("bookingId"), await parseJsonBody(c, applyDefaultBookingPaymentPlanSchema), {
|
|
332
|
+
eventBus: runtime?.eventBus,
|
|
333
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
334
|
+
actionLedgerAuthorizationSource: "finance.booking_payment_schedule.default_plan.route",
|
|
335
|
+
});
|
|
229
336
|
if (!rows) {
|
|
230
337
|
return c.json({ error: "Booking not found" }, 404);
|
|
231
338
|
}
|
|
232
339
|
return c.json({ data: rows }, 201);
|
|
233
340
|
})
|
|
234
341
|
.patch("/bookings/:bookingId/payment-schedules/:scheduleId", async (c) => {
|
|
235
|
-
const
|
|
342
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
343
|
+
const row = await financeService.updateBookingPaymentSchedule(c.get("db"), c.req.param("scheduleId"), await parseJsonBody(c, updateBookingPaymentScheduleSchema), {
|
|
344
|
+
eventBus: runtime?.eventBus,
|
|
345
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
346
|
+
actionLedgerAuthorizationSource: "finance.booking_payment_schedule.route",
|
|
347
|
+
});
|
|
236
348
|
if (!row) {
|
|
237
349
|
return c.json({ error: "Payment schedule not found" }, 404);
|
|
238
350
|
}
|
|
@@ -240,7 +352,12 @@ export const financeRoutes = new Hono()
|
|
|
240
352
|
})
|
|
241
353
|
.post("/bookings/:bookingId/payment-schedules/:scheduleId/payment-session", async (c) => {
|
|
242
354
|
try {
|
|
243
|
-
const
|
|
355
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
356
|
+
const row = await financeService.createPaymentSessionFromBookingSchedule(c.get("db"), c.req.param("scheduleId"), await parseJsonBody(c, createPaymentSessionFromScheduleSchema), {
|
|
357
|
+
eventBus: runtime?.eventBus,
|
|
358
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
359
|
+
actionLedgerAuthorizationSource: "finance.payment_session.route",
|
|
360
|
+
});
|
|
244
361
|
if (!row) {
|
|
245
362
|
return c.json({ error: "Payment schedule not found" }, 404);
|
|
246
363
|
}
|
|
@@ -252,7 +369,12 @@ export const financeRoutes = new Hono()
|
|
|
252
369
|
}
|
|
253
370
|
})
|
|
254
371
|
.delete("/bookings/:bookingId/payment-schedules/:scheduleId", async (c) => {
|
|
255
|
-
const
|
|
372
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
373
|
+
const row = await financeService.deleteBookingPaymentSchedule(c.get("db"), c.req.param("scheduleId"), {
|
|
374
|
+
eventBus: runtime?.eventBus,
|
|
375
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
376
|
+
actionLedgerAuthorizationSource: "finance.booking_payment_schedule.route",
|
|
377
|
+
});
|
|
256
378
|
if (!row) {
|
|
257
379
|
return c.json({ error: "Payment schedule not found" }, 404);
|
|
258
380
|
}
|
|
@@ -267,7 +389,12 @@ export const financeRoutes = new Hono()
|
|
|
267
389
|
});
|
|
268
390
|
})
|
|
269
391
|
.post("/bookings/:bookingId/guarantees", async (c) => {
|
|
270
|
-
const
|
|
392
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
393
|
+
const row = await financeService.createBookingGuarantee(c.get("db"), c.req.param("bookingId"), await parseJsonBody(c, insertBookingGuaranteeSchema), {
|
|
394
|
+
eventBus: runtime?.eventBus,
|
|
395
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
396
|
+
actionLedgerAuthorizationSource: "finance.booking_guarantee.route",
|
|
397
|
+
});
|
|
271
398
|
if (!row) {
|
|
272
399
|
return c.json({ error: "Booking not found" }, 404);
|
|
273
400
|
}
|
|
@@ -275,7 +402,12 @@ export const financeRoutes = new Hono()
|
|
|
275
402
|
})
|
|
276
403
|
.post("/bookings/:bookingId/guarantees/:guaranteeId/payment-session", async (c) => {
|
|
277
404
|
try {
|
|
278
|
-
const
|
|
405
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
406
|
+
const row = await financeService.createPaymentSessionFromBookingGuarantee(c.get("db"), c.req.param("guaranteeId"), await parseJsonBody(c, createPaymentSessionFromGuaranteeSchema), {
|
|
407
|
+
eventBus: runtime?.eventBus,
|
|
408
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
409
|
+
actionLedgerAuthorizationSource: "finance.payment_session.route",
|
|
410
|
+
});
|
|
279
411
|
if (!row) {
|
|
280
412
|
return c.json({ error: "Booking guarantee not found" }, 404);
|
|
281
413
|
}
|
|
@@ -287,14 +419,24 @@ export const financeRoutes = new Hono()
|
|
|
287
419
|
}
|
|
288
420
|
})
|
|
289
421
|
.patch("/bookings/:bookingId/guarantees/:guaranteeId", async (c) => {
|
|
290
|
-
const
|
|
422
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
423
|
+
const row = await financeService.updateBookingGuarantee(c.get("db"), c.req.param("guaranteeId"), await parseJsonBody(c, updateBookingGuaranteeSchema), {
|
|
424
|
+
eventBus: runtime?.eventBus,
|
|
425
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
426
|
+
actionLedgerAuthorizationSource: "finance.booking_guarantee.route",
|
|
427
|
+
});
|
|
291
428
|
if (!row) {
|
|
292
429
|
return c.json({ error: "Booking guarantee not found" }, 404);
|
|
293
430
|
}
|
|
294
431
|
return c.json({ data: row });
|
|
295
432
|
})
|
|
296
433
|
.delete("/bookings/:bookingId/guarantees/:guaranteeId", async (c) => {
|
|
297
|
-
const
|
|
434
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
435
|
+
const row = await financeService.deleteBookingGuarantee(c.get("db"), c.req.param("guaranteeId"), {
|
|
436
|
+
eventBus: runtime?.eventBus,
|
|
437
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
438
|
+
actionLedgerAuthorizationSource: "finance.booking_guarantee.route",
|
|
439
|
+
});
|
|
298
440
|
if (!row) {
|
|
299
441
|
return c.json({ error: "Booking guarantee not found" }, 404);
|
|
300
442
|
}
|
|
@@ -385,13 +527,23 @@ export const financeRoutes = new Hono()
|
|
|
385
527
|
})
|
|
386
528
|
// POST /supplier-payments — Record supplier payment
|
|
387
529
|
.post("/supplier-payments", async (c) => {
|
|
530
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
388
531
|
return c.json({
|
|
389
|
-
data: await financeService.createSupplierPayment(c.get("db"), await parseJsonBody(c, insertSupplierPaymentSchema)
|
|
532
|
+
data: await financeService.createSupplierPayment(c.get("db"), await parseJsonBody(c, insertSupplierPaymentSchema), {
|
|
533
|
+
eventBus: runtime?.eventBus,
|
|
534
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
535
|
+
actionLedgerAuthorizationSource: "finance.supplier_payment.route",
|
|
536
|
+
}),
|
|
390
537
|
}, 201);
|
|
391
538
|
})
|
|
392
539
|
// PATCH /supplier-payments/:id — Update supplier payment
|
|
393
540
|
.patch("/supplier-payments/:id", async (c) => {
|
|
394
|
-
const
|
|
541
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
542
|
+
const row = await financeService.updateSupplierPayment(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateSupplierPaymentSchema), {
|
|
543
|
+
eventBus: runtime?.eventBus,
|
|
544
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
545
|
+
actionLedgerAuthorizationSource: "finance.supplier_payment.route",
|
|
546
|
+
});
|
|
395
547
|
if (!row) {
|
|
396
548
|
return c.json({ error: "Supplier payment not found" }, 404);
|
|
397
549
|
}
|
|
@@ -457,8 +609,40 @@ export const financeRoutes = new Hono()
|
|
|
457
609
|
unitSellAmountCents: item.unitSellAmountCents,
|
|
458
610
|
totalSellAmountCents: item.totalSellAmountCents,
|
|
459
611
|
})),
|
|
460
|
-
}, {
|
|
612
|
+
}, {
|
|
613
|
+
eventBus: runtime?.eventBus,
|
|
614
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
615
|
+
actionLedgerAuthorizationSource: "finance.invoice.from_booking.route",
|
|
616
|
+
});
|
|
461
617
|
return c.json({ data: row }, 201);
|
|
618
|
+
})
|
|
619
|
+
// POST /invoices/:id/convert-to-invoice — Convert a proforma into a final invoice
|
|
620
|
+
.post("/invoices/:id/convert-to-invoice", async (c) => {
|
|
621
|
+
const { convertProformaToInvoice } = await import("./service-issue.js");
|
|
622
|
+
const input = await c.req
|
|
623
|
+
.json()
|
|
624
|
+
.catch(() => ({}));
|
|
625
|
+
const runtime = (() => {
|
|
626
|
+
try {
|
|
627
|
+
return c.var.container?.resolve(FINANCE_ROUTE_RUNTIME_CONTAINER_KEY);
|
|
628
|
+
}
|
|
629
|
+
catch {
|
|
630
|
+
return undefined;
|
|
631
|
+
}
|
|
632
|
+
})();
|
|
633
|
+
const result = await convertProformaToInvoice(c.get("db"), c.req.param("id"), input, {
|
|
634
|
+
eventBus: runtime?.eventBus,
|
|
635
|
+
});
|
|
636
|
+
if (result.status === "not_found") {
|
|
637
|
+
return c.json({ error: "Invoice not found" }, 404);
|
|
638
|
+
}
|
|
639
|
+
if (result.status === "not_proforma") {
|
|
640
|
+
return c.json({ error: "Only proforma invoices can be converted" }, 409);
|
|
641
|
+
}
|
|
642
|
+
if (result.status === "already_converted") {
|
|
643
|
+
return c.json({ error: "This proforma has already been converted" }, 409);
|
|
644
|
+
}
|
|
645
|
+
return c.json({ data: result.invoice }, 201);
|
|
462
646
|
})
|
|
463
647
|
// GET /invoices/:id — Get single invoice
|
|
464
648
|
.get("/invoices/:id", async (c) => {
|
|
@@ -470,7 +654,12 @@ export const financeRoutes = new Hono()
|
|
|
470
654
|
})
|
|
471
655
|
// PATCH /invoices/:id — Update invoice
|
|
472
656
|
.patch("/invoices/:id", async (c) => {
|
|
473
|
-
const
|
|
657
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
658
|
+
const row = await financeService.updateInvoice(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateInvoiceSchema), {
|
|
659
|
+
eventBus: runtime?.eventBus,
|
|
660
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
661
|
+
actionLedgerAuthorizationSource: "finance.invoice.route",
|
|
662
|
+
});
|
|
474
663
|
if (!row) {
|
|
475
664
|
return c.json({ error: "Invoice not found" }, 404);
|
|
476
665
|
}
|
|
@@ -478,7 +667,12 @@ export const financeRoutes = new Hono()
|
|
|
478
667
|
})
|
|
479
668
|
// DELETE /invoices/:id — Delete invoice (draft only)
|
|
480
669
|
.delete("/invoices/:id", async (c) => {
|
|
481
|
-
const
|
|
670
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
671
|
+
const result = await financeService.deleteInvoice(c.get("db"), c.req.param("id"), {
|
|
672
|
+
eventBus: runtime?.eventBus,
|
|
673
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
674
|
+
actionLedgerAuthorizationSource: "finance.invoice.route",
|
|
675
|
+
});
|
|
482
676
|
if (result.status === "not_found") {
|
|
483
677
|
return c.json({ error: "Invoice not found" }, 404);
|
|
484
678
|
}
|
|
@@ -489,7 +683,12 @@ export const financeRoutes = new Hono()
|
|
|
489
683
|
})
|
|
490
684
|
.post("/invoices/:id/payment-session", async (c) => {
|
|
491
685
|
try {
|
|
492
|
-
const
|
|
686
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
687
|
+
const row = await financeService.createPaymentSessionFromInvoice(c.get("db"), c.req.param("id"), await parseJsonBody(c, createPaymentSessionFromInvoiceSchema), {
|
|
688
|
+
eventBus: runtime?.eventBus,
|
|
689
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
690
|
+
actionLedgerAuthorizationSource: "finance.payment_session.route",
|
|
691
|
+
});
|
|
493
692
|
if (!row) {
|
|
494
693
|
return c.json({ error: "Invoice not found" }, 404);
|
|
495
694
|
}
|
|
@@ -511,7 +710,12 @@ export const financeRoutes = new Hono()
|
|
|
511
710
|
})
|
|
512
711
|
// POST /invoices/:id/line-items — Add line item
|
|
513
712
|
.post("/invoices/:id/line-items", async (c) => {
|
|
514
|
-
const
|
|
713
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
714
|
+
const row = await financeService.createInvoiceLineItem(c.get("db"), c.req.param("id"), await parseJsonBody(c, insertInvoiceLineItemSchema), {
|
|
715
|
+
eventBus: runtime?.eventBus,
|
|
716
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
717
|
+
actionLedgerAuthorizationSource: "finance.invoice_line_item.route",
|
|
718
|
+
});
|
|
515
719
|
if (!row) {
|
|
516
720
|
return c.json({ error: "Invoice not found" }, 404);
|
|
517
721
|
}
|
|
@@ -519,7 +723,12 @@ export const financeRoutes = new Hono()
|
|
|
519
723
|
})
|
|
520
724
|
// PATCH /invoices/:id/line-items/:lineId — Update line item
|
|
521
725
|
.patch("/invoices/:id/line-items/:lineId", async (c) => {
|
|
522
|
-
const
|
|
726
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
727
|
+
const row = await financeService.updateInvoiceLineItem(c.get("db"), c.req.param("lineId"), await parseJsonBody(c, updateInvoiceLineItemSchema), {
|
|
728
|
+
eventBus: runtime?.eventBus,
|
|
729
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
730
|
+
actionLedgerAuthorizationSource: "finance.invoice_line_item.route",
|
|
731
|
+
});
|
|
523
732
|
if (!row) {
|
|
524
733
|
return c.json({ error: "Line item not found" }, 404);
|
|
525
734
|
}
|
|
@@ -527,7 +736,12 @@ export const financeRoutes = new Hono()
|
|
|
527
736
|
})
|
|
528
737
|
// DELETE /invoices/:id/line-items/:lineId — Delete line item
|
|
529
738
|
.delete("/invoices/:id/line-items/:lineId", async (c) => {
|
|
530
|
-
const
|
|
739
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
740
|
+
const row = await financeService.deleteInvoiceLineItem(c.get("db"), c.req.param("lineId"), {
|
|
741
|
+
eventBus: runtime?.eventBus,
|
|
742
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
743
|
+
actionLedgerAuthorizationSource: "finance.invoice_line_item.route",
|
|
744
|
+
});
|
|
531
745
|
if (!row) {
|
|
532
746
|
return c.json({ error: "Line item not found" }, 404);
|
|
533
747
|
}
|
|
@@ -543,7 +757,12 @@ export const financeRoutes = new Hono()
|
|
|
543
757
|
// POST /invoices/:id/payments — Record payment (transaction)
|
|
544
758
|
.post("/invoices/:id/payments", async (c) => {
|
|
545
759
|
try {
|
|
546
|
-
const
|
|
760
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
761
|
+
const row = await financeService.createPayment(c.get("db"), c.req.param("id"), await parseJsonBody(c, insertPaymentSchema), {
|
|
762
|
+
eventBus: runtime?.eventBus,
|
|
763
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
764
|
+
actionLedgerAuthorizationSource: "finance.payment.route",
|
|
765
|
+
});
|
|
547
766
|
if (!row) {
|
|
548
767
|
return c.json({ error: "Invoice not found" }, 404);
|
|
549
768
|
}
|
|
@@ -567,7 +786,12 @@ export const financeRoutes = new Hono()
|
|
|
567
786
|
})
|
|
568
787
|
// POST /invoices/:id/credit-notes — Create credit note
|
|
569
788
|
.post("/invoices/:id/credit-notes", async (c) => {
|
|
570
|
-
const
|
|
789
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
790
|
+
const row = await financeService.createCreditNote(c.get("db"), c.req.param("id"), await parseJsonBody(c, insertCreditNoteSchema), {
|
|
791
|
+
eventBus: runtime?.eventBus,
|
|
792
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
793
|
+
actionLedgerAuthorizationSource: "finance.credit_note.route",
|
|
794
|
+
});
|
|
571
795
|
if (!row) {
|
|
572
796
|
return c.json({ error: "Invoice not found" }, 404);
|
|
573
797
|
}
|
|
@@ -575,7 +799,12 @@ export const financeRoutes = new Hono()
|
|
|
575
799
|
})
|
|
576
800
|
// PATCH /invoices/:id/credit-notes/:creditNoteId — Update credit note
|
|
577
801
|
.patch("/invoices/:id/credit-notes/:creditNoteId", async (c) => {
|
|
578
|
-
const
|
|
802
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
803
|
+
const row = await financeService.updateCreditNote(c.get("db"), c.req.param("creditNoteId"), await parseJsonBody(c, updateCreditNoteSchema), {
|
|
804
|
+
eventBus: runtime?.eventBus,
|
|
805
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
806
|
+
actionLedgerAuthorizationSource: "finance.credit_note.route",
|
|
807
|
+
});
|
|
579
808
|
if (!row) {
|
|
580
809
|
return c.json({ error: "Credit note not found" }, 404);
|
|
581
810
|
}
|
|
@@ -592,7 +821,12 @@ export const financeRoutes = new Hono()
|
|
|
592
821
|
})
|
|
593
822
|
// POST /invoices/:id/credit-notes/:creditNoteId/line-items — Add credit note line item
|
|
594
823
|
.post("/invoices/:id/credit-notes/:creditNoteId/line-items", async (c) => {
|
|
595
|
-
const
|
|
824
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
825
|
+
const row = await financeService.createCreditNoteLineItem(c.get("db"), c.req.param("creditNoteId"), await parseJsonBody(c, insertCreditNoteLineItemSchema), {
|
|
826
|
+
eventBus: runtime?.eventBus,
|
|
827
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
828
|
+
actionLedgerAuthorizationSource: "finance.credit_note_line_item.route",
|
|
829
|
+
});
|
|
596
830
|
if (!row) {
|
|
597
831
|
return c.json({ error: "Credit note not found" }, 404);
|
|
598
832
|
}
|