@voyantjs/finance 0.52.2 → 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 +224 -224
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +252 -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 +12 -12
- package/dist/service-bookings-dual-create.d.ts +12 -12
- package/dist/service-issue.d.ts +15 -12
- package/dist/service-issue.d.ts.map +1 -1
- package/dist/service-issue.js +24 -3
- 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 +731 -234
- 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
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AnyDrizzleDb } from "@voyantjs/db";
|
|
2
|
+
import { type SQL } from "drizzle-orm";
|
|
3
|
+
export type FinanceActionLedgerDriftCheck = "invoice" | "payment" | "payment_session";
|
|
4
|
+
export interface CheckFinanceActionLedgerDriftInput {
|
|
5
|
+
createdAtFrom?: Date | string | null;
|
|
6
|
+
sampleLimit?: number | null;
|
|
7
|
+
}
|
|
8
|
+
export interface FinanceActionLedgerDriftRow {
|
|
9
|
+
check: FinanceActionLedgerDriftCheck;
|
|
10
|
+
missingCount: number;
|
|
11
|
+
sampleIds: string[];
|
|
12
|
+
}
|
|
13
|
+
export interface CheckFinanceActionLedgerDriftResult {
|
|
14
|
+
ok: boolean;
|
|
15
|
+
rows: FinanceActionLedgerDriftRow[];
|
|
16
|
+
}
|
|
17
|
+
interface FinanceActionLedgerDriftQueryRow extends Record<string, unknown> {
|
|
18
|
+
check: FinanceActionLedgerDriftCheck;
|
|
19
|
+
missing_count: number | string;
|
|
20
|
+
sample_ids: string[] | null;
|
|
21
|
+
}
|
|
22
|
+
export declare function buildFinanceActionLedgerDriftQueries(input?: CheckFinanceActionLedgerDriftInput): Record<FinanceActionLedgerDriftCheck, SQL<FinanceActionLedgerDriftQueryRow>>;
|
|
23
|
+
export declare function checkFinanceActionLedgerDrift(db: AnyDrizzleDb, input?: CheckFinanceActionLedgerDriftInput): Promise<CheckFinanceActionLedgerDriftResult>;
|
|
24
|
+
declare function normalizeRow(row: FinanceActionLedgerDriftQueryRow): FinanceActionLedgerDriftRow;
|
|
25
|
+
export declare const __test__: {
|
|
26
|
+
normalizeRow: typeof normalizeRow;
|
|
27
|
+
};
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=action-ledger-drift.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action-ledger-drift.d.ts","sourceRoot":"","sources":["../src/action-ledger-drift.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,EAAE,KAAK,GAAG,EAAwB,MAAM,aAAa,CAAA;AAmB5D,MAAM,MAAM,6BAA6B,GAAG,SAAS,GAAG,SAAS,GAAG,iBAAiB,CAAA;AAErF,MAAM,WAAW,kCAAkC;IACjD,aAAa,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAAA;IACpC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC5B;AAED,MAAM,WAAW,2BAA2B;IAC1C,KAAK,EAAE,6BAA6B,CAAA;IACpC,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,EAAE,CAAA;CACpB;AAED,MAAM,WAAW,mCAAmC;IAClD,EAAE,EAAE,OAAO,CAAA;IACX,IAAI,EAAE,2BAA2B,EAAE,CAAA;CACpC;AAED,UAAU,gCAAiC,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACxE,KAAK,EAAE,6BAA6B,CAAA;IACpC,aAAa,EAAE,MAAM,GAAG,MAAM,CAAA;IAC9B,UAAU,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;CAC5B;AAED,wBAAgB,oCAAoC,CAClD,KAAK,GAAE,kCAAuC,GAC7C,MAAM,CAAC,6BAA6B,EAAE,GAAG,CAAC,gCAAgC,CAAC,CAAC,CAyG9E;AAED,wBAAsB,6BAA6B,CACjD,EAAE,EAAE,YAAY,EAChB,KAAK,GAAE,kCAAuC,GAC7C,OAAO,CAAC,mCAAmC,CAAC,CAe9C;AAyBD,iBAAS,YAAY,CAAC,GAAG,EAAE,gCAAgC,GAAG,2BAA2B,CAMxF;AAED,eAAO,MAAM,QAAQ;;CAEpB,CAAA"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { actionLedgerEntries } from "@voyantjs/action-ledger/schema";
|
|
2
|
+
import { sql } from "drizzle-orm";
|
|
3
|
+
import { invoices, paymentSessions, payments } from "./schema.js";
|
|
4
|
+
const DEFAULT_SAMPLE_LIMIT = 20;
|
|
5
|
+
const MAX_SAMPLE_LIMIT = 100;
|
|
6
|
+
const INVOICE_ISSUE_ACTION_NAME = "finance.invoice.issue_from_booking";
|
|
7
|
+
const PAYMENT_RECORD_ACTION_NAME = "finance.payment.record";
|
|
8
|
+
const PAYMENT_SESSION_ACTION_NAMES = [
|
|
9
|
+
"finance.payment_session.create",
|
|
10
|
+
"finance.payment_session.complete",
|
|
11
|
+
"finance.payment_session.update",
|
|
12
|
+
"finance.payment_session.requires_redirect",
|
|
13
|
+
"finance.payment_session.fail",
|
|
14
|
+
"finance.payment_session.cancel",
|
|
15
|
+
"finance.payment_session.expire",
|
|
16
|
+
];
|
|
17
|
+
export function buildFinanceActionLedgerDriftQueries(input = {}) {
|
|
18
|
+
const sampleLimit = normalizeSampleLimit(input.sampleLimit);
|
|
19
|
+
return {
|
|
20
|
+
invoice: sql `
|
|
21
|
+
SELECT
|
|
22
|
+
'invoice' AS check,
|
|
23
|
+
count(*)::int AS missing_count,
|
|
24
|
+
coalesce(
|
|
25
|
+
array_agg(candidate_id ORDER BY created_at DESC, candidate_id DESC)
|
|
26
|
+
FILTER (WHERE sample_ordinal <= ${sampleLimit}),
|
|
27
|
+
ARRAY[]::text[]
|
|
28
|
+
) AS sample_ids
|
|
29
|
+
FROM (
|
|
30
|
+
SELECT
|
|
31
|
+
${invoices.id} AS candidate_id,
|
|
32
|
+
${invoices.createdAt} AS created_at,
|
|
33
|
+
row_number() OVER (ORDER BY ${invoices.createdAt} DESC, ${invoices.id} DESC) AS sample_ordinal
|
|
34
|
+
FROM ${invoices}
|
|
35
|
+
WHERE ${invoices.status} <> ${"draft"}
|
|
36
|
+
${buildCreatedAtCondition(invoices.createdAt, input.createdAtFrom)}
|
|
37
|
+
AND NOT EXISTS (
|
|
38
|
+
SELECT 1
|
|
39
|
+
FROM ${actionLedgerEntries}
|
|
40
|
+
WHERE ${actionLedgerEntries.actionName} = ${INVOICE_ISSUE_ACTION_NAME}
|
|
41
|
+
AND ${actionLedgerEntries.targetType} = ${"booking"}
|
|
42
|
+
AND ${actionLedgerEntries.targetId} = ${invoices.bookingId}
|
|
43
|
+
)
|
|
44
|
+
) missing
|
|
45
|
+
`,
|
|
46
|
+
payment: sql `
|
|
47
|
+
SELECT
|
|
48
|
+
'payment' AS check,
|
|
49
|
+
count(*)::int AS missing_count,
|
|
50
|
+
coalesce(
|
|
51
|
+
array_agg(candidate_id ORDER BY created_at DESC, candidate_id DESC)
|
|
52
|
+
FILTER (WHERE sample_ordinal <= ${sampleLimit}),
|
|
53
|
+
ARRAY[]::text[]
|
|
54
|
+
) AS sample_ids
|
|
55
|
+
FROM (
|
|
56
|
+
SELECT
|
|
57
|
+
${payments.id} AS candidate_id,
|
|
58
|
+
${payments.createdAt} AS created_at,
|
|
59
|
+
row_number() OVER (ORDER BY ${payments.createdAt} DESC, ${payments.id} DESC) AS sample_ordinal
|
|
60
|
+
FROM ${payments}
|
|
61
|
+
INNER JOIN ${invoices} ON ${invoices.id} = ${payments.invoiceId}
|
|
62
|
+
WHERE 1 = 1
|
|
63
|
+
${buildCreatedAtCondition(payments.createdAt, input.createdAtFrom)}
|
|
64
|
+
AND NOT EXISTS (
|
|
65
|
+
SELECT 1
|
|
66
|
+
FROM ${actionLedgerEntries}
|
|
67
|
+
WHERE ${actionLedgerEntries.actionName} = ${PAYMENT_RECORD_ACTION_NAME}
|
|
68
|
+
AND ${actionLedgerEntries.targetType} = ${"booking"}
|
|
69
|
+
AND ${actionLedgerEntries.targetId} = ${invoices.bookingId}
|
|
70
|
+
)
|
|
71
|
+
) missing
|
|
72
|
+
`,
|
|
73
|
+
payment_session: sql `
|
|
74
|
+
SELECT
|
|
75
|
+
'payment_session' AS check,
|
|
76
|
+
count(*)::int AS missing_count,
|
|
77
|
+
coalesce(
|
|
78
|
+
array_agg(candidate_id ORDER BY created_at DESC, candidate_id DESC)
|
|
79
|
+
FILTER (WHERE sample_ordinal <= ${sampleLimit}),
|
|
80
|
+
ARRAY[]::text[]
|
|
81
|
+
) AS sample_ids
|
|
82
|
+
FROM (
|
|
83
|
+
SELECT
|
|
84
|
+
${paymentSessions.id} AS candidate_id,
|
|
85
|
+
${paymentSessions.createdAt} AS created_at,
|
|
86
|
+
row_number() OVER (
|
|
87
|
+
ORDER BY ${paymentSessions.createdAt} DESC, ${paymentSessions.id} DESC
|
|
88
|
+
) AS sample_ordinal
|
|
89
|
+
FROM ${paymentSessions}
|
|
90
|
+
WHERE 1 = 1
|
|
91
|
+
${buildCreatedAtCondition(paymentSessions.createdAt, input.createdAtFrom)}
|
|
92
|
+
AND NOT EXISTS (
|
|
93
|
+
SELECT 1
|
|
94
|
+
FROM ${actionLedgerEntries}
|
|
95
|
+
WHERE ${actionLedgerEntries.actionName} IN (${sql.join(PAYMENT_SESSION_ACTION_NAMES.map((actionName) => sql `${actionName}`), sql `, `)})
|
|
96
|
+
AND ${actionLedgerEntries.targetType} = CASE
|
|
97
|
+
WHEN ${paymentSessions.bookingId} IS NOT NULL THEN ${"booking"}
|
|
98
|
+
WHEN ${paymentSessions.invoiceId} IS NOT NULL THEN ${"invoice"}
|
|
99
|
+
WHEN ${paymentSessions.orderId} IS NOT NULL THEN ${"order"}
|
|
100
|
+
WHEN ${paymentSessions.targetId} IS NOT NULL
|
|
101
|
+
AND ${paymentSessions.targetType} <> ${"other"}
|
|
102
|
+
THEN ${paymentSessions.targetType}
|
|
103
|
+
ELSE ${"payment_session"}
|
|
104
|
+
END
|
|
105
|
+
AND ${actionLedgerEntries.targetId} = CASE
|
|
106
|
+
WHEN ${paymentSessions.bookingId} IS NOT NULL THEN ${paymentSessions.bookingId}
|
|
107
|
+
WHEN ${paymentSessions.invoiceId} IS NOT NULL THEN ${paymentSessions.invoiceId}
|
|
108
|
+
WHEN ${paymentSessions.orderId} IS NOT NULL THEN ${paymentSessions.orderId}
|
|
109
|
+
WHEN ${paymentSessions.targetId} IS NOT NULL
|
|
110
|
+
AND ${paymentSessions.targetType} <> ${"other"}
|
|
111
|
+
THEN ${paymentSessions.targetId}
|
|
112
|
+
ELSE ${paymentSessions.id}
|
|
113
|
+
END
|
|
114
|
+
)
|
|
115
|
+
) missing
|
|
116
|
+
`,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
export async function checkFinanceActionLedgerDrift(db, input = {}) {
|
|
120
|
+
const queries = buildFinanceActionLedgerDriftQueries(input);
|
|
121
|
+
const results = await Promise.all([
|
|
122
|
+
db.execute(queries.invoice),
|
|
123
|
+
db.execute(queries.payment),
|
|
124
|
+
db.execute(queries.payment_session),
|
|
125
|
+
]);
|
|
126
|
+
const rows = results
|
|
127
|
+
.flatMap((result) => extractRows(result))
|
|
128
|
+
.map((row) => normalizeRow(row));
|
|
129
|
+
return {
|
|
130
|
+
ok: rows.every((row) => row.missingCount === 0),
|
|
131
|
+
rows,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function normalizeSampleLimit(limit) {
|
|
135
|
+
if (!limit)
|
|
136
|
+
return DEFAULT_SAMPLE_LIMIT;
|
|
137
|
+
return Math.min(Math.max(Math.trunc(limit), 1), MAX_SAMPLE_LIMIT);
|
|
138
|
+
}
|
|
139
|
+
function buildCreatedAtCondition(column, value) {
|
|
140
|
+
if (!value)
|
|
141
|
+
return sql ``;
|
|
142
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
143
|
+
if (Number.isNaN(date.getTime())) {
|
|
144
|
+
throw new Error("createdAtFrom must be a valid date");
|
|
145
|
+
}
|
|
146
|
+
return sql `AND ${column} >= ${date}`;
|
|
147
|
+
}
|
|
148
|
+
function extractRows(result) {
|
|
149
|
+
if (Array.isArray(result))
|
|
150
|
+
return result;
|
|
151
|
+
const maybeRows = result.rows;
|
|
152
|
+
return Array.isArray(maybeRows) ? maybeRows : [];
|
|
153
|
+
}
|
|
154
|
+
function normalizeRow(row) {
|
|
155
|
+
return {
|
|
156
|
+
check: row.check,
|
|
157
|
+
missingCount: Number(row.missing_count),
|
|
158
|
+
sampleIds: row.sample_ids ?? [],
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
export const __test__ = {
|
|
162
|
+
normalizeRow,
|
|
163
|
+
};
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAGvD,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAGvD,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,oBAAoB,CAAA;AAI3B,OAAO,EAA6B,KAAK,yBAAyB,EAAE,MAAM,oBAAoB,CAAA;AAG9F,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAC7D,OAAO,EACL,yBAAyB,EACzB,KAAK,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ACtB,MAAM,iBAAiB,CAAA;AACxB,YAAY,EACV,6BAA6B,EAC7B,4BAA4B,EAC5B,2BAA2B,EAC3B,4BAA4B,EAC5B,2BAA2B,EAC3B,2BAA2B,EAC3B,gCAAgC,EAChC,yBAAyB,EACzB,oBAAoB,EACpB,8BAA8B,EAC9B,0BAA0B,EAC1B,6BAA6B,GAC9B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,mCAAmC,EACnC,kCAAkC,EAClC,iCAAiC,EACjC,kCAAkC,EAClC,iCAAiC,EACjC,uCAAuC,EACvC,iCAAiC,EACjC,sCAAsC,EACtC,iCAAiC,EACjC,8BAA8B,EAC9B,+BAA+B,EAC/B,0BAA0B,EAC1B,+BAA+B,EAC/B,2BAA2B,EAC3B,6BAA6B,GAC9B,MAAM,wBAAwB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Hono } from "hono";
|
|
2
2
|
import { buildFinanceRouteRuntime, FINANCE_ROUTE_RUNTIME_CONTAINER_KEY, } from "./route-runtime.js";
|
|
3
3
|
import { financeRoutes } from "./routes.js";
|
|
4
|
+
import { financeActionLedgerRoutes } from "./routes-action-ledger.js";
|
|
4
5
|
import { createFinanceAdminDocumentRoutes } from "./routes-documents.js";
|
|
5
6
|
import { createPublicFinanceRoutes } from "./routes-public.js";
|
|
6
7
|
import { createFinanceAdminSettlementRoutes } from "./routes-settlement.js";
|
|
@@ -36,6 +37,7 @@ export const financeModule = {
|
|
|
36
37
|
export function createFinanceHonoModule(options = {}) {
|
|
37
38
|
const adminRoutes = new Hono()
|
|
38
39
|
.route("/", financeRoutes)
|
|
40
|
+
.route("/", financeActionLedgerRoutes)
|
|
39
41
|
.route("/", createFinanceAdminDocumentRoutes(options))
|
|
40
42
|
.route("/", createFinanceAdminSettlementRoutes(options));
|
|
41
43
|
const module = {
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { type ActionLedgerEntry } from "@voyantjs/action-ledger";
|
|
2
|
+
import { type ActionLedgerTargetTimelinePage } from "@voyantjs/action-ledger/timeline";
|
|
3
|
+
import type { z } from "zod";
|
|
4
|
+
import type { Env } from "./routes-shared.js";
|
|
5
|
+
export type FinanceActionLedgerListResponse = ActionLedgerTargetTimelinePage;
|
|
6
|
+
declare function buildFinanceActionLedgerPage({ entries, limit, }: {
|
|
7
|
+
entries: ActionLedgerEntry[];
|
|
8
|
+
limit: number;
|
|
9
|
+
}): ActionLedgerTargetTimelinePage;
|
|
10
|
+
declare function getPaymentSessionLedgerTarget(session: {
|
|
11
|
+
id: string;
|
|
12
|
+
bookingId: string | null;
|
|
13
|
+
invoiceId: string | null;
|
|
14
|
+
orderId: string | null;
|
|
15
|
+
targetType: string;
|
|
16
|
+
targetId: string | null;
|
|
17
|
+
}): {
|
|
18
|
+
type: string;
|
|
19
|
+
id: string;
|
|
20
|
+
};
|
|
21
|
+
export declare const financeActionLedgerRoutes: import("hono/hono-base").HonoBase<Env, {
|
|
22
|
+
"/invoices/:id/action-ledger": {
|
|
23
|
+
$get: {
|
|
24
|
+
input: {
|
|
25
|
+
param: {
|
|
26
|
+
id: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
output: {
|
|
30
|
+
data: {
|
|
31
|
+
id: string;
|
|
32
|
+
actionName: string;
|
|
33
|
+
actionVersion: string;
|
|
34
|
+
actionKind: "execute" | "reverse" | "update" | "delete" | "read" | "create" | "approve" | "reject" | "compensate" | "duplicate";
|
|
35
|
+
status: "requested" | "awaiting_approval" | "approved" | "denied" | "succeeded" | "failed" | "reversed" | "compensated" | "expired" | "cancelled" | "superseded";
|
|
36
|
+
evaluatedRisk: "low" | "medium" | "high" | "critical";
|
|
37
|
+
actorType: string | null;
|
|
38
|
+
principalType: "user" | "api_key" | "agent" | "workflow" | "system";
|
|
39
|
+
principalId: string;
|
|
40
|
+
principalSubtype: string | null;
|
|
41
|
+
sessionId: string | null;
|
|
42
|
+
apiTokenId: string | null;
|
|
43
|
+
internalRequest: boolean;
|
|
44
|
+
delegatedByPrincipalType: "user" | "api_key" | "agent" | "workflow" | "system" | null;
|
|
45
|
+
delegatedByPrincipalId: string | null;
|
|
46
|
+
delegationId: string | null;
|
|
47
|
+
callerType: string | null;
|
|
48
|
+
organizationId: string | null;
|
|
49
|
+
routeOrToolName: string | null;
|
|
50
|
+
workflowRunId: string | null;
|
|
51
|
+
workflowStepId: string | null;
|
|
52
|
+
correlationId: string | null;
|
|
53
|
+
causationActionId: string | null;
|
|
54
|
+
idempotencyScope: string | null;
|
|
55
|
+
idempotencyKey: string | null;
|
|
56
|
+
idempotencyFingerprint: string | null;
|
|
57
|
+
targetType: string;
|
|
58
|
+
targetId: string;
|
|
59
|
+
capabilityId: string | null;
|
|
60
|
+
capabilityVersion: string | null;
|
|
61
|
+
authorizationSource: string | null;
|
|
62
|
+
approvalId: string | null;
|
|
63
|
+
amendsActionId: string | null;
|
|
64
|
+
occurredAt: string;
|
|
65
|
+
createdAt: string;
|
|
66
|
+
mutationSummary: string | null;
|
|
67
|
+
}[];
|
|
68
|
+
pageInfo: {
|
|
69
|
+
nextCursor: {
|
|
70
|
+
occurredAt: string;
|
|
71
|
+
id: string;
|
|
72
|
+
} | null;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
outputFormat: "json";
|
|
76
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
77
|
+
} | {
|
|
78
|
+
input: {
|
|
79
|
+
param: {
|
|
80
|
+
id: string;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
output: {
|
|
84
|
+
error: string;
|
|
85
|
+
};
|
|
86
|
+
outputFormat: "json";
|
|
87
|
+
status: 404;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
} & {
|
|
91
|
+
"/payment-sessions/:id/action-ledger": {
|
|
92
|
+
$get: {
|
|
93
|
+
input: {
|
|
94
|
+
param: {
|
|
95
|
+
id: string;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
output: {
|
|
99
|
+
data: {
|
|
100
|
+
id: string;
|
|
101
|
+
actionName: string;
|
|
102
|
+
actionVersion: string;
|
|
103
|
+
actionKind: "execute" | "reverse" | "update" | "delete" | "read" | "create" | "approve" | "reject" | "compensate" | "duplicate";
|
|
104
|
+
status: "requested" | "awaiting_approval" | "approved" | "denied" | "succeeded" | "failed" | "reversed" | "compensated" | "expired" | "cancelled" | "superseded";
|
|
105
|
+
evaluatedRisk: "low" | "medium" | "high" | "critical";
|
|
106
|
+
actorType: string | null;
|
|
107
|
+
principalType: "user" | "api_key" | "agent" | "workflow" | "system";
|
|
108
|
+
principalId: string;
|
|
109
|
+
principalSubtype: string | null;
|
|
110
|
+
sessionId: string | null;
|
|
111
|
+
apiTokenId: string | null;
|
|
112
|
+
internalRequest: boolean;
|
|
113
|
+
delegatedByPrincipalType: "user" | "api_key" | "agent" | "workflow" | "system" | null;
|
|
114
|
+
delegatedByPrincipalId: string | null;
|
|
115
|
+
delegationId: string | null;
|
|
116
|
+
callerType: string | null;
|
|
117
|
+
organizationId: string | null;
|
|
118
|
+
routeOrToolName: string | null;
|
|
119
|
+
workflowRunId: string | null;
|
|
120
|
+
workflowStepId: string | null;
|
|
121
|
+
correlationId: string | null;
|
|
122
|
+
causationActionId: string | null;
|
|
123
|
+
idempotencyScope: string | null;
|
|
124
|
+
idempotencyKey: string | null;
|
|
125
|
+
idempotencyFingerprint: string | null;
|
|
126
|
+
targetType: string;
|
|
127
|
+
targetId: string;
|
|
128
|
+
capabilityId: string | null;
|
|
129
|
+
capabilityVersion: string | null;
|
|
130
|
+
authorizationSource: string | null;
|
|
131
|
+
approvalId: string | null;
|
|
132
|
+
amendsActionId: string | null;
|
|
133
|
+
occurredAt: string;
|
|
134
|
+
createdAt: string;
|
|
135
|
+
mutationSummary: string | null;
|
|
136
|
+
}[];
|
|
137
|
+
pageInfo: {
|
|
138
|
+
nextCursor: {
|
|
139
|
+
occurredAt: string;
|
|
140
|
+
id: string;
|
|
141
|
+
} | null;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
outputFormat: "json";
|
|
145
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
146
|
+
} | {
|
|
147
|
+
input: {
|
|
148
|
+
param: {
|
|
149
|
+
id: string;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
output: {
|
|
153
|
+
error: string;
|
|
154
|
+
};
|
|
155
|
+
outputFormat: "json";
|
|
156
|
+
status: 404;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
}, "/", "/payment-sessions/:id/action-ledger">;
|
|
160
|
+
export type FinanceActionLedgerRoutes = typeof financeActionLedgerRoutes;
|
|
161
|
+
export declare const __test__: {
|
|
162
|
+
buildFinanceActionLedgerPage: typeof buildFinanceActionLedgerPage;
|
|
163
|
+
financeActionLedgerQuerySchema: z.ZodPipe<z.ZodObject<{
|
|
164
|
+
cursorOccurredAt: z.ZodOptional<z.ZodString>;
|
|
165
|
+
cursorId: z.ZodOptional<z.ZodString>;
|
|
166
|
+
limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
167
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
168
|
+
cursor: {
|
|
169
|
+
occurredAt: string;
|
|
170
|
+
id: string;
|
|
171
|
+
} | undefined;
|
|
172
|
+
limit?: number | undefined;
|
|
173
|
+
}, {
|
|
174
|
+
cursorOccurredAt?: string | undefined;
|
|
175
|
+
cursorId?: string | undefined;
|
|
176
|
+
limit?: number | undefined;
|
|
177
|
+
}>>;
|
|
178
|
+
getPaymentSessionLedgerTarget: typeof getPaymentSessionLedgerTarget;
|
|
179
|
+
};
|
|
180
|
+
export {};
|
|
181
|
+
//# sourceMappingURL=routes-action-ledger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes-action-ledger.d.ts","sourceRoot":"","sources":["../src/routes-action-ledger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAuB,MAAM,yBAAyB,CAAA;AACrF,OAAO,EACL,KAAK,8BAA8B,EAGpC,MAAM,kCAAkC,CAAA;AAIzC,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAA;AA+C7C,MAAM,MAAM,+BAA+B,GAAG,8BAA8B,CAAA;AAE5E,iBAAS,4BAA4B,CAAC,EACpC,OAAO,EACP,KAAK,GACN,EAAE;IACD,OAAO,EAAE,iBAAiB,EAAE,CAAA;IAC5B,KAAK,EAAE,MAAM,CAAA;CACd,kCAEA;AAED,iBAAS,6BAA6B,CAAC,OAAO,EAAE;IAC9C,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CACxB;;;EAQA;AA+GD,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8CAEuC,CAAA;AAE7E,MAAM,MAAM,yBAAyB,GAAG,OAAO,yBAAyB,CAAA;AAExE,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;CAIpB,CAAA"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { actionLedgerService } from "@voyantjs/action-ledger";
|
|
2
|
+
import { actionLedgerTargetTimelineQuerySchema, buildActionLedgerTargetTimelinePage, } from "@voyantjs/action-ledger/timeline";
|
|
3
|
+
import { parseQuery } from "@voyantjs/hono";
|
|
4
|
+
import { Hono } from "hono";
|
|
5
|
+
import { financeService } from "./service.js";
|
|
6
|
+
const FINANCE_INVOICE_LEDGER_ACTION_NAMES = [
|
|
7
|
+
"finance.invoice.issue_from_booking",
|
|
8
|
+
"finance.invoice.update",
|
|
9
|
+
"finance.invoice.delete",
|
|
10
|
+
"finance.invoice_line_item.create",
|
|
11
|
+
"finance.invoice_line_item.update",
|
|
12
|
+
"finance.invoice_line_item.delete",
|
|
13
|
+
"finance.credit_note.create",
|
|
14
|
+
"finance.credit_note.update",
|
|
15
|
+
"finance.credit_note_line_item.create",
|
|
16
|
+
"finance.payment.record",
|
|
17
|
+
"finance.payment_session.create",
|
|
18
|
+
"finance.payment_session.complete",
|
|
19
|
+
"finance.payment_session.update",
|
|
20
|
+
"finance.payment_session.requires_redirect",
|
|
21
|
+
"finance.payment_session.fail",
|
|
22
|
+
"finance.payment_session.cancel",
|
|
23
|
+
"finance.payment_session.expire",
|
|
24
|
+
"finance.payment_authorization.create",
|
|
25
|
+
"finance.payment_authorization.update",
|
|
26
|
+
"finance.payment_authorization.delete",
|
|
27
|
+
"finance.payment_capture.create",
|
|
28
|
+
"finance.payment_capture.update",
|
|
29
|
+
"finance.payment_capture.delete",
|
|
30
|
+
];
|
|
31
|
+
const FINANCE_PAYMENT_SESSION_LEDGER_ACTION_NAMES = [
|
|
32
|
+
"finance.payment_session.create",
|
|
33
|
+
"finance.payment_session.complete",
|
|
34
|
+
"finance.payment_session.update",
|
|
35
|
+
"finance.payment_session.requires_redirect",
|
|
36
|
+
"finance.payment_session.fail",
|
|
37
|
+
"finance.payment_session.cancel",
|
|
38
|
+
"finance.payment_session.expire",
|
|
39
|
+
];
|
|
40
|
+
const financeActionLedgerQuerySchema = actionLedgerTargetTimelineQuerySchema;
|
|
41
|
+
function buildFinanceActionLedgerPage({ entries, limit, }) {
|
|
42
|
+
return buildActionLedgerTargetTimelinePage({ entries, limit });
|
|
43
|
+
}
|
|
44
|
+
function getPaymentSessionLedgerTarget(session) {
|
|
45
|
+
if (session.bookingId)
|
|
46
|
+
return { type: "booking", id: session.bookingId };
|
|
47
|
+
if (session.invoiceId)
|
|
48
|
+
return { type: "invoice", id: session.invoiceId };
|
|
49
|
+
if (session.orderId)
|
|
50
|
+
return { type: "order", id: session.orderId };
|
|
51
|
+
if (session.targetId && session.targetType !== "other") {
|
|
52
|
+
return { type: session.targetType, id: session.targetId };
|
|
53
|
+
}
|
|
54
|
+
return { type: "payment_session", id: session.id };
|
|
55
|
+
}
|
|
56
|
+
function dedupeFinanceActionLedgerSources(sources) {
|
|
57
|
+
const sourcesByKey = new Map();
|
|
58
|
+
for (const source of sources) {
|
|
59
|
+
const key = `${source.targetType}:${source.targetId}:${source.actionNames.join(",")}`;
|
|
60
|
+
sourcesByKey.set(key, source);
|
|
61
|
+
}
|
|
62
|
+
return [...sourcesByKey.values()];
|
|
63
|
+
}
|
|
64
|
+
async function listFinanceActionLedgerPage(c, sources, query) {
|
|
65
|
+
const limit = query.limit ?? 50;
|
|
66
|
+
const queryLimit = limit + 1;
|
|
67
|
+
const sourceQueries = dedupeFinanceActionLedgerSources(sources).flatMap((source) => source.actionNames.map((actionName) => ({
|
|
68
|
+
targetType: source.targetType,
|
|
69
|
+
targetId: source.targetId,
|
|
70
|
+
actionName,
|
|
71
|
+
})));
|
|
72
|
+
const results = await Promise.all(sourceQueries.map((source) => actionLedgerService.listEntries(c.get("db"), {
|
|
73
|
+
...source,
|
|
74
|
+
cursor: query.cursor,
|
|
75
|
+
limit: queryLimit,
|
|
76
|
+
})));
|
|
77
|
+
const page = buildFinanceActionLedgerPage({
|
|
78
|
+
entries: results.flatMap((result) => result.entries),
|
|
79
|
+
limit,
|
|
80
|
+
});
|
|
81
|
+
const details = await Promise.all(page.data.map((entry) => actionLedgerService.getEntry(c.get("db"), entry.id)));
|
|
82
|
+
const summariesByActionId = new Map(details.flatMap((detail) => detail ? [[detail.entry.id, detail.mutationDetail?.summary ?? null]] : []));
|
|
83
|
+
return c.json(buildActionLedgerTargetTimelinePage({
|
|
84
|
+
entries: results.flatMap((result) => result.entries),
|
|
85
|
+
limit,
|
|
86
|
+
mutationSummariesByActionId: summariesByActionId,
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
async function listInvoiceActionLedger(c) {
|
|
90
|
+
const invoiceId = c.req.param("id");
|
|
91
|
+
if (!invoiceId)
|
|
92
|
+
return c.json({ error: "Invoice not found" }, 404);
|
|
93
|
+
const invoice = await financeService.getInvoiceById(c.get("db"), invoiceId);
|
|
94
|
+
if (!invoice)
|
|
95
|
+
return c.json({ error: "Invoice not found" }, 404);
|
|
96
|
+
const query = parseQuery(c, financeActionLedgerQuerySchema);
|
|
97
|
+
const sources = [
|
|
98
|
+
{
|
|
99
|
+
targetType: "invoice",
|
|
100
|
+
targetId: invoice.id,
|
|
101
|
+
actionNames: FINANCE_INVOICE_LEDGER_ACTION_NAMES,
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
if (invoice.bookingId) {
|
|
105
|
+
sources.push({
|
|
106
|
+
targetType: "booking",
|
|
107
|
+
targetId: invoice.bookingId,
|
|
108
|
+
actionNames: FINANCE_INVOICE_LEDGER_ACTION_NAMES,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return listFinanceActionLedgerPage(c, sources, query);
|
|
112
|
+
}
|
|
113
|
+
async function listPaymentSessionActionLedger(c) {
|
|
114
|
+
const paymentSessionId = c.req.param("id");
|
|
115
|
+
if (!paymentSessionId)
|
|
116
|
+
return c.json({ error: "Payment session not found" }, 404);
|
|
117
|
+
const session = await financeService.getPaymentSessionById(c.get("db"), paymentSessionId);
|
|
118
|
+
if (!session)
|
|
119
|
+
return c.json({ error: "Payment session not found" }, 404);
|
|
120
|
+
const target = getPaymentSessionLedgerTarget(session);
|
|
121
|
+
const query = parseQuery(c, financeActionLedgerQuerySchema);
|
|
122
|
+
return listFinanceActionLedgerPage(c, [
|
|
123
|
+
{
|
|
124
|
+
targetType: target.type,
|
|
125
|
+
targetId: target.id,
|
|
126
|
+
actionNames: FINANCE_PAYMENT_SESSION_LEDGER_ACTION_NAMES,
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
targetType: "payment_session",
|
|
130
|
+
targetId: session.id,
|
|
131
|
+
actionNames: FINANCE_PAYMENT_SESSION_LEDGER_ACTION_NAMES,
|
|
132
|
+
},
|
|
133
|
+
], query);
|
|
134
|
+
}
|
|
135
|
+
export const financeActionLedgerRoutes = new Hono()
|
|
136
|
+
.get("/invoices/:id/action-ledger", listInvoiceActionLedger)
|
|
137
|
+
.get("/payment-sessions/:id/action-ledger", listPaymentSessionActionLedger);
|
|
138
|
+
export const __test__ = {
|
|
139
|
+
buildFinanceActionLedgerPage,
|
|
140
|
+
financeActionLedgerQuerySchema,
|
|
141
|
+
getPaymentSessionLedgerTarget,
|
|
142
|
+
};
|
|
@@ -67,19 +67,19 @@ export declare function createFinanceAdminDocumentRoutes(options?: FinanceDocume
|
|
|
67
67
|
renderedBodyFormat: "html" | "markdown" | "lexical_json";
|
|
68
68
|
renderedBody: string;
|
|
69
69
|
rendition: {
|
|
70
|
-
|
|
70
|
+
format: "json" | "html" | "pdf" | "xml";
|
|
71
71
|
id: string;
|
|
72
|
+
status: "failed" | "pending" | "ready" | "stale";
|
|
72
73
|
createdAt: string;
|
|
73
74
|
updatedAt: string;
|
|
74
|
-
|
|
75
|
-
format: "json" | "pdf" | "html" | "xml";
|
|
76
|
-
errorMessage: string | null;
|
|
75
|
+
metadata: import("hono/utils/types").JSONValue;
|
|
77
76
|
templateId: string | null;
|
|
78
77
|
language: string | null;
|
|
79
78
|
invoiceId: string;
|
|
80
79
|
storageKey: string | null;
|
|
81
80
|
fileSize: number | null;
|
|
82
81
|
checksum: string | null;
|
|
82
|
+
errorMessage: string | null;
|
|
83
83
|
generatedAt: string | null;
|
|
84
84
|
};
|
|
85
85
|
};
|
|
@@ -138,19 +138,19 @@ export declare function createFinanceAdminDocumentRoutes(options?: FinanceDocume
|
|
|
138
138
|
renderedBodyFormat: "html" | "markdown" | "lexical_json";
|
|
139
139
|
renderedBody: string;
|
|
140
140
|
rendition: {
|
|
141
|
-
|
|
141
|
+
format: "json" | "html" | "pdf" | "xml";
|
|
142
142
|
id: string;
|
|
143
|
+
status: "failed" | "pending" | "ready" | "stale";
|
|
143
144
|
createdAt: string;
|
|
144
145
|
updatedAt: string;
|
|
145
|
-
|
|
146
|
-
format: "json" | "pdf" | "html" | "xml";
|
|
147
|
-
errorMessage: string | null;
|
|
146
|
+
metadata: import("hono/utils/types").JSONValue;
|
|
148
147
|
templateId: string | null;
|
|
149
148
|
language: string | null;
|
|
150
149
|
invoiceId: string;
|
|
151
150
|
storageKey: string | null;
|
|
152
151
|
fileSize: number | null;
|
|
153
152
|
checksum: string | null;
|
|
153
|
+
errorMessage: string | null;
|
|
154
154
|
generatedAt: string | null;
|
|
155
155
|
};
|
|
156
156
|
};
|