@voyantjs/finance 0.4.5 → 0.6.0
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/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -6
- package/dist/route-runtime.d.ts +13 -0
- package/dist/route-runtime.d.ts.map +1 -0
- package/dist/route-runtime.js +8 -0
- package/dist/routes-documents.d.ts +45 -8
- package/dist/routes-documents.d.ts.map +1 -1
- package/dist/routes-documents.js +51 -8
- package/dist/routes-public.d.ts +564 -9
- package/dist/routes-public.d.ts.map +1 -1
- package/dist/routes-public.js +65 -54
- package/dist/routes-settlement.d.ts +3 -2
- package/dist/routes-settlement.d.ts.map +1 -1
- package/dist/routes-settlement.js +9 -8
- package/dist/routes.d.ts +124 -135
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +59 -61
- package/dist/schema.d.ts +9 -9
- package/dist/service-documents.d.ts +0 -1
- package/dist/service-documents.d.ts.map +1 -1
- package/dist/service-documents.js +3 -5
- package/dist/service-public.d.ts +11 -8
- package/dist/service-public.d.ts.map +1 -1
- package/dist/service-public.js +11 -6
- package/dist/service-settlement.d.ts.map +1 -1
- package/dist/service-settlement.js +3 -0
- package/dist/service.d.ts +127 -127
- package/dist/validation-billing.d.ts +6 -6
- package/dist/validation-payments.d.ts +18 -18
- package/dist/validation-public.d.ts +8 -8
- package/dist/validation-shared.d.ts +8 -8
- package/package.json +7 -7
package/dist/routes-public.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parseJsonBody, parseQuery } from "@voyantjs/hono";
|
|
1
2
|
import { Hono } from "hono";
|
|
2
3
|
import { notFound } from "./routes-shared.js";
|
|
3
4
|
import { publicFinanceService } from "./service-public.js";
|
|
@@ -8,57 +9,67 @@ function paymentConflictError(error) {
|
|
|
8
9
|
}
|
|
9
10
|
return "Unable to start payment session";
|
|
10
11
|
}
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
12
|
+
export function createPublicFinanceRoutes(options = {}) {
|
|
13
|
+
const resolveDocumentDownloadUrl = (bindings, storageKey) => options.resolveDocumentDownloadUrl?.(bindings, storageKey) ?? null;
|
|
14
|
+
return new Hono()
|
|
15
|
+
.post("/vouchers/validate", async (c) => {
|
|
16
|
+
const result = await publicFinanceService.validateVoucher(c.get("db"), await parseJsonBody(c, publicValidateVoucherSchema));
|
|
17
|
+
return c.json({ data: result });
|
|
18
|
+
})
|
|
19
|
+
.get("/documents/by-reference", async (c) => {
|
|
20
|
+
const document = await publicFinanceService.getDocumentByReference(c.get("db"), parseQuery(c, publicFinanceDocumentLookupQuerySchema).reference, {
|
|
21
|
+
resolveDocumentDownloadUrl: (storageKey) => resolveDocumentDownloadUrl(c.env, storageKey),
|
|
22
|
+
});
|
|
23
|
+
return document ? c.json({ data: document }) : notFound(c, "Finance document not found");
|
|
24
|
+
})
|
|
25
|
+
.get("/bookings/:bookingId/documents", async (c) => {
|
|
26
|
+
const documents = await publicFinanceService.getBookingDocuments(c.get("db"), c.req.param("bookingId"), {
|
|
27
|
+
resolveDocumentDownloadUrl: (storageKey) => resolveDocumentDownloadUrl(c.env, storageKey),
|
|
28
|
+
});
|
|
29
|
+
return documents ? c.json({ data: documents }) : notFound(c, "Booking documents not found");
|
|
30
|
+
})
|
|
31
|
+
.get("/bookings/:bookingId/payments", async (c) => {
|
|
32
|
+
const payments = await publicFinanceService.getBookingPayments(c.get("db"), c.req.param("bookingId"));
|
|
33
|
+
return payments ? c.json({ data: payments }) : notFound(c, "Booking payments not found");
|
|
34
|
+
})
|
|
35
|
+
.get("/bookings/:bookingId/payment-options", async (c) => {
|
|
36
|
+
const paymentOptions = await publicFinanceService.getBookingPaymentOptions(c.get("db"), c.req.param("bookingId"), parseQuery(c, publicPaymentOptionsQuerySchema));
|
|
37
|
+
return paymentOptions
|
|
38
|
+
? c.json({ data: paymentOptions })
|
|
39
|
+
: notFound(c, "Booking payment options not found");
|
|
40
|
+
})
|
|
41
|
+
.get("/payment-sessions/:sessionId", async (c) => {
|
|
42
|
+
const session = await publicFinanceService.getPaymentSession(c.get("db"), c.req.param("sessionId"));
|
|
43
|
+
return session ? c.json({ data: session }) : notFound(c, "Payment session not found");
|
|
44
|
+
})
|
|
45
|
+
.post("/bookings/:bookingId/payment-schedules/:scheduleId/payment-session", async (c) => {
|
|
46
|
+
try {
|
|
47
|
+
const session = await publicFinanceService.startBookingSchedulePaymentSession(c.get("db"), c.req.param("bookingId"), c.req.param("scheduleId"), await parseJsonBody(c, publicStartPaymentSessionSchema));
|
|
48
|
+
return session
|
|
49
|
+
? c.json({ data: session }, 201)
|
|
50
|
+
: notFound(c, "Booking payment schedule not found");
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
return c.json({ error: paymentConflictError(error) }, 409);
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
.post("/bookings/:bookingId/guarantees/:guaranteeId/payment-session", async (c) => {
|
|
57
|
+
try {
|
|
58
|
+
const session = await publicFinanceService.startBookingGuaranteePaymentSession(c.get("db"), c.req.param("bookingId"), c.req.param("guaranteeId"), await parseJsonBody(c, publicStartPaymentSessionSchema));
|
|
59
|
+
return session ? c.json({ data: session }, 201) : notFound(c, "Booking guarantee not found");
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return c.json({ error: paymentConflictError(error) }, 409);
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
.post("/invoices/:invoiceId/payment-session", async (c) => {
|
|
66
|
+
try {
|
|
67
|
+
const session = await publicFinanceService.startInvoicePaymentSession(c.get("db"), c.req.param("invoiceId"), await parseJsonBody(c, publicStartPaymentSessionSchema));
|
|
68
|
+
return session ? c.json({ data: session }, 201) : notFound(c, "Invoice not found");
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
return c.json({ error: paymentConflictError(error) }, 409);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
export const publicFinanceRoutes = createPublicFinanceRoutes();
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { EventBus } from "@voyantjs/core";
|
|
1
|
+
import type { EventBus, ModuleContainer } from "@voyantjs/core";
|
|
2
2
|
import { type InvoiceSettlementPoller } from "./service-settlement.js";
|
|
3
3
|
type Env = {
|
|
4
4
|
Bindings: Record<string, unknown>;
|
|
5
5
|
Variables: {
|
|
6
|
+
container: ModuleContainer;
|
|
6
7
|
db: import("drizzle-orm/postgres-js").PostgresJsDatabase;
|
|
7
8
|
userId?: string;
|
|
8
9
|
};
|
|
@@ -35,7 +36,7 @@ export declare function createFinanceAdminSettlementRoutes(options?: FinanceSett
|
|
|
35
36
|
output: {
|
|
36
37
|
data: {
|
|
37
38
|
invoiceId: string;
|
|
38
|
-
invoiceStatus: "draft" | "sent" | "partially_paid" | "paid" | "overdue"
|
|
39
|
+
invoiceStatus: "void" | "draft" | "sent" | "partially_paid" | "paid" | "overdue";
|
|
39
40
|
paidCents: number;
|
|
40
41
|
balanceDueCents: number;
|
|
41
42
|
results: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes-settlement.d.ts","sourceRoot":"","sources":["../src/routes-settlement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"routes-settlement.d.ts","sourceRoot":"","sources":["../src/routes-settlement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAS/D,OAAO,EAA4B,KAAK,uBAAuB,EAAE,MAAM,yBAAyB,CAAA;AAGhG,KAAK,GAAG,GAAG;IACT,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACjC,SAAS,EAAE;QACT,SAAS,EAAE,eAAe,CAAA;QAC1B,EAAE,EAAE,OAAO,yBAAyB,EAAE,kBAAkB,CAAA;QACxD,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,CAAA;CACF,CAAA;AAED,MAAM,WAAW,6BAA6B;IAC5C,wBAAwB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAA;IAClE,+BAA+B,CAAC,EAAE,CAChC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC9B,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,GAAG,SAAS,CAAA;IACxD,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,QAAQ,GAAG,SAAS,CAAA;CAC9E;AAaD,wBAAgB,kCAAkC,CAAC,OAAO,GAAE,6BAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yCAqB7F;AAED,YAAY,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAA"}
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
+
import { parseOptionalJsonBody } from "@voyantjs/hono";
|
|
1
2
|
import { Hono } from "hono";
|
|
3
|
+
import { buildFinanceRouteRuntime, FINANCE_ROUTE_RUNTIME_CONTAINER_KEY, } from "./route-runtime.js";
|
|
2
4
|
import { financeSettlementService } from "./service-settlement.js";
|
|
3
5
|
import { pollInvoiceSettlementInputSchema } from "./validation.js";
|
|
4
|
-
function
|
|
5
|
-
return (
|
|
6
|
-
|
|
7
|
-
function resolveEventBus(options, bindings) {
|
|
8
|
-
return options?.resolveEventBus?.(bindings) ?? options?.eventBus;
|
|
6
|
+
function getRuntime(options, bindings, resolveFromContainer) {
|
|
7
|
+
return (resolveFromContainer?.(FINANCE_ROUTE_RUNTIME_CONTAINER_KEY) ??
|
|
8
|
+
buildFinanceRouteRuntime(bindings, options));
|
|
9
9
|
}
|
|
10
10
|
export function createFinanceAdminSettlementRoutes(options = {}) {
|
|
11
11
|
return new Hono().post("/invoices/:id/poll-settlement", async (c) => {
|
|
12
|
-
const
|
|
12
|
+
const runtime = getRuntime(options, c.env, (key) => c.var.container?.resolve(key));
|
|
13
|
+
const result = await financeSettlementService.pollInvoiceSettlement(c.get("db"), c.req.param("id"), await parseOptionalJsonBody(c, pollInvoiceSettlementInputSchema), {
|
|
13
14
|
bindings: c.env,
|
|
14
|
-
invoiceSettlementPollers:
|
|
15
|
-
eventBus:
|
|
15
|
+
invoiceSettlementPollers: runtime.invoiceSettlementPollers,
|
|
16
|
+
eventBus: runtime.eventBus,
|
|
16
17
|
});
|
|
17
18
|
if ("status" in result && result.status === "not_found") {
|
|
18
19
|
return c.json({ error: "Invoice not found" }, 404);
|