@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.
Files changed (54) hide show
  1. package/dist/action-ledger-drift.d.ts +29 -0
  2. package/dist/action-ledger-drift.d.ts.map +1 -0
  3. package/dist/action-ledger-drift.js +163 -0
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +2 -0
  6. package/dist/routes-action-ledger.d.ts +181 -0
  7. package/dist/routes-action-ledger.d.ts.map +1 -0
  8. package/dist/routes-action-ledger.js +142 -0
  9. package/dist/routes-documents.d.ts +8 -8
  10. package/dist/routes-public.d.ts +48 -48
  11. package/dist/routes-settlement.d.ts +1 -1
  12. package/dist/routes-shared.d.ts +12 -0
  13. package/dist/routes-shared.d.ts.map +1 -1
  14. package/dist/routes.d.ts +288 -217
  15. package/dist/routes.d.ts.map +1 -1
  16. package/dist/routes.js +280 -46
  17. package/dist/schema.d.ts +22 -22
  18. package/dist/service-action-ledger-accounting.d.ts +77 -0
  19. package/dist/service-action-ledger-accounting.d.ts.map +1 -0
  20. package/dist/service-action-ledger-accounting.js +307 -0
  21. package/dist/service-action-ledger-booking-payments.d.ts +48 -0
  22. package/dist/service-action-ledger-booking-payments.d.ts.map +1 -0
  23. package/dist/service-action-ledger-booking-payments.js +178 -0
  24. package/dist/service-action-ledger-payment-authorizations.d.ts +48 -0
  25. package/dist/service-action-ledger-payment-authorizations.d.ts.map +1 -0
  26. package/dist/service-action-ledger-payment-authorizations.js +209 -0
  27. package/dist/service-action-ledger-payment-sessions.d.ts +83 -0
  28. package/dist/service-action-ledger-payment-sessions.d.ts.map +1 -0
  29. package/dist/service-action-ledger-payment-sessions.js +294 -0
  30. package/dist/service-action-ledger-supplier-payments.d.ts +21 -0
  31. package/dist/service-action-ledger-supplier-payments.d.ts.map +1 -0
  32. package/dist/service-action-ledger-supplier-payments.js +70 -0
  33. package/dist/service-action-ledger.d.ts +6 -0
  34. package/dist/service-action-ledger.d.ts.map +1 -0
  35. package/dist/service-action-ledger.js +5 -0
  36. package/dist/service-booking-create.d.ts +50 -8
  37. package/dist/service-booking-create.d.ts.map +1 -1
  38. package/dist/service-booking-create.js +58 -1
  39. package/dist/service-bookings-dual-create.d.ts +50 -8
  40. package/dist/service-bookings-dual-create.d.ts.map +1 -1
  41. package/dist/service-issue.d.ts +42 -12
  42. package/dist/service-issue.d.ts.map +1 -1
  43. package/dist/service-issue.js +141 -4
  44. package/dist/service-public.d.ts +13 -13
  45. package/dist/service-vouchers.d.ts +10 -10
  46. package/dist/service.d.ts +291 -279
  47. package/dist/service.d.ts.map +1 -1
  48. package/dist/service.js +753 -238
  49. package/dist/validation-billing.d.ts +37 -37
  50. package/dist/validation-payments.d.ts +102 -102
  51. package/dist/validation-public.d.ts +45 -45
  52. package/dist/validation-shared.d.ts +32 -32
  53. package/dist/validation-vouchers.d.ts +2 -2
  54. package/package.json +13 -7
@@ -0,0 +1,178 @@
1
+ import { buildIdempotencyFingerprint, } from "@voyantjs/action-ledger";
2
+ export function buildBookingPaymentScheduleCreateActionLedgerInput(context, input, options = {}) {
3
+ const target = getBookingPaymentScheduleLedgerTarget(input.schedule);
4
+ return {
5
+ context,
6
+ actionName: "finance.booking_payment_schedule.create",
7
+ actionVersion: "v1",
8
+ actionKind: "create",
9
+ status: "succeeded",
10
+ evaluatedRisk: "high",
11
+ targetType: target.type,
12
+ targetId: target.id,
13
+ routeOrToolName: "finance.booking_payment_schedule.create",
14
+ authorizationSource: options.authorizationSource ?? "finance.booking_payment_schedule.route",
15
+ idempotencyScope: null,
16
+ idempotencyKey: null,
17
+ idempotencyFingerprint: null,
18
+ mutationDetail: {
19
+ commandInputRef: `booking:${input.schedule.bookingId}:payment_schedule`,
20
+ commandResultRef: `booking_payment_schedule:${input.schedule.id}`,
21
+ summary: `Payment schedule ${input.schedule.id} created for booking ${input.schedule.bookingId}`,
22
+ reversalKind: "none",
23
+ },
24
+ };
25
+ }
26
+ export function buildBookingPaymentScheduleUpdateActionLedgerInput(context, input, options = {}) {
27
+ const target = getBookingPaymentScheduleLedgerTarget(input.schedule);
28
+ const changedFields = Object.keys(input.changes).sort();
29
+ const changeSummary = changedFields.length > 0 ? changedFields.join(", ") : "no fields";
30
+ return {
31
+ context,
32
+ actionName: "finance.booking_payment_schedule.update",
33
+ actionVersion: "v1",
34
+ actionKind: "update",
35
+ status: "succeeded",
36
+ evaluatedRisk: "high",
37
+ targetType: target.type,
38
+ targetId: target.id,
39
+ routeOrToolName: "finance.booking_payment_schedule.update",
40
+ authorizationSource: options.authorizationSource ?? "finance.booking_payment_schedule.route",
41
+ idempotencyScope: null,
42
+ idempotencyKey: null,
43
+ idempotencyFingerprint: null,
44
+ mutationDetail: {
45
+ commandInputRef: `booking_payment_schedule:${input.schedule.id}:update`,
46
+ commandResultRef: `booking_payment_schedule:${input.schedule.id}`,
47
+ summary: `Payment schedule ${input.schedule.id} updated (${changeSummary})`,
48
+ reversalKind: "none",
49
+ },
50
+ };
51
+ }
52
+ export function buildBookingPaymentScheduleDeleteActionLedgerInput(context, input, options = {}) {
53
+ const target = getBookingPaymentScheduleLedgerTarget(input.schedule);
54
+ return {
55
+ context,
56
+ actionName: "finance.booking_payment_schedule.delete",
57
+ actionVersion: "v1",
58
+ actionKind: "delete",
59
+ status: "succeeded",
60
+ evaluatedRisk: "high",
61
+ targetType: target.type,
62
+ targetId: target.id,
63
+ routeOrToolName: "finance.booking_payment_schedule.delete",
64
+ authorizationSource: options.authorizationSource ?? "finance.booking_payment_schedule.route",
65
+ idempotencyScope: null,
66
+ idempotencyKey: null,
67
+ idempotencyFingerprint: null,
68
+ mutationDetail: {
69
+ commandInputRef: `booking_payment_schedule:${input.schedule.id}:delete`,
70
+ commandResultRef: null,
71
+ summary: `Payment schedule ${input.schedule.id} deleted`,
72
+ reversalKind: "none",
73
+ },
74
+ };
75
+ }
76
+ function getBookingPaymentScheduleLedgerTarget(schedule) {
77
+ return { type: "booking", id: schedule.bookingId };
78
+ }
79
+ export async function buildBookingGuaranteeCreateActionLedgerInput(context, input, options = {}) {
80
+ const target = getBookingGuaranteeLedgerTarget(input.guarantee);
81
+ const idempotencyKey = input.guarantee.referenceNumber;
82
+ return {
83
+ context,
84
+ actionName: "finance.booking_guarantee.create",
85
+ actionVersion: "v1",
86
+ actionKind: "create",
87
+ status: "succeeded",
88
+ evaluatedRisk: "high",
89
+ targetType: target.type,
90
+ targetId: target.id,
91
+ routeOrToolName: "finance.booking_guarantee.create",
92
+ authorizationSource: options.authorizationSource ?? "finance.booking_guarantee.route",
93
+ idempotencyScope: idempotencyKey
94
+ ? `finance.booking:${input.guarantee.bookingId}:guarantee`
95
+ : null,
96
+ idempotencyKey,
97
+ idempotencyFingerprint: idempotencyKey
98
+ ? await buildIdempotencyFingerprint({
99
+ actionName: "finance.booking_guarantee.create",
100
+ actionVersion: "v1",
101
+ targetType: target.type,
102
+ targetId: target.id,
103
+ commandInput: {
104
+ bookingGuaranteeId: input.guarantee.id,
105
+ bookingId: input.guarantee.bookingId,
106
+ bookingPaymentScheduleId: input.guarantee.bookingPaymentScheduleId,
107
+ guaranteeType: input.guarantee.guaranteeType,
108
+ status: input.guarantee.status,
109
+ paymentInstrumentId: input.guarantee.paymentInstrumentId,
110
+ paymentAuthorizationId: input.guarantee.paymentAuthorizationId,
111
+ currency: input.guarantee.currency,
112
+ amountCents: input.guarantee.amountCents,
113
+ provider: input.guarantee.provider,
114
+ referenceNumber: input.guarantee.referenceNumber,
115
+ },
116
+ })
117
+ : null,
118
+ mutationDetail: {
119
+ commandInputRef: `booking:${input.guarantee.bookingId}:guarantee`,
120
+ commandResultRef: `booking_guarantee:${input.guarantee.id}`,
121
+ summary: `Booking guarantee ${input.guarantee.id} created for booking ${input.guarantee.bookingId}`,
122
+ reversalKind: "none",
123
+ },
124
+ };
125
+ }
126
+ export function buildBookingGuaranteeUpdateActionLedgerInput(context, input, options = {}) {
127
+ const target = getBookingGuaranteeLedgerTarget(input.guarantee);
128
+ const changedFields = Object.keys(input.changes).sort();
129
+ const changeSummary = changedFields.length > 0 ? changedFields.join(", ") : "no fields";
130
+ return {
131
+ context,
132
+ actionName: "finance.booking_guarantee.update",
133
+ actionVersion: "v1",
134
+ actionKind: "update",
135
+ status: "succeeded",
136
+ evaluatedRisk: "high",
137
+ targetType: target.type,
138
+ targetId: target.id,
139
+ routeOrToolName: "finance.booking_guarantee.update",
140
+ authorizationSource: options.authorizationSource ?? "finance.booking_guarantee.route",
141
+ idempotencyScope: null,
142
+ idempotencyKey: null,
143
+ idempotencyFingerprint: null,
144
+ mutationDetail: {
145
+ commandInputRef: `booking_guarantee:${input.guarantee.id}:update`,
146
+ commandResultRef: `booking_guarantee:${input.guarantee.id}`,
147
+ summary: `Booking guarantee ${input.guarantee.id} updated (${changeSummary})`,
148
+ reversalKind: "none",
149
+ },
150
+ };
151
+ }
152
+ export function buildBookingGuaranteeDeleteActionLedgerInput(context, input, options = {}) {
153
+ const target = getBookingGuaranteeLedgerTarget(input.guarantee);
154
+ return {
155
+ context,
156
+ actionName: "finance.booking_guarantee.delete",
157
+ actionVersion: "v1",
158
+ actionKind: "delete",
159
+ status: "succeeded",
160
+ evaluatedRisk: "high",
161
+ targetType: target.type,
162
+ targetId: target.id,
163
+ routeOrToolName: "finance.booking_guarantee.delete",
164
+ authorizationSource: options.authorizationSource ?? "finance.booking_guarantee.route",
165
+ idempotencyScope: null,
166
+ idempotencyKey: null,
167
+ idempotencyFingerprint: null,
168
+ mutationDetail: {
169
+ commandInputRef: `booking_guarantee:${input.guarantee.id}:delete`,
170
+ commandResultRef: null,
171
+ summary: `Booking guarantee ${input.guarantee.id} deleted`,
172
+ reversalKind: "none",
173
+ },
174
+ };
175
+ }
176
+ function getBookingGuaranteeLedgerTarget(guarantee) {
177
+ return { type: "booking", id: guarantee.bookingId };
178
+ }
@@ -0,0 +1,48 @@
1
+ import { type ActionLedgerRequestContextValues, type BuildActionLedgerMutationInput } from "@voyantjs/action-ledger";
2
+ import type { z } from "zod";
3
+ import type { paymentAuthorizations, paymentCaptures } from "./schema.js";
4
+ import type { updatePaymentAuthorizationSchema, updatePaymentCaptureSchema } from "./validation.js";
5
+ type UpdatePaymentAuthorizationInput = z.infer<typeof updatePaymentAuthorizationSchema>;
6
+ type UpdatePaymentCaptureInput = z.infer<typeof updatePaymentCaptureSchema>;
7
+ type PaymentAuthorizationRecord = typeof paymentAuthorizations.$inferSelect;
8
+ type PaymentCaptureRecord = typeof paymentCaptures.$inferSelect;
9
+ type PaymentAuthorizationCreateLedgerInput = {
10
+ authorization: PaymentAuthorizationRecord;
11
+ };
12
+ type PaymentAuthorizationUpdateLedgerInput = {
13
+ authorization: PaymentAuthorizationRecord;
14
+ changes: UpdatePaymentAuthorizationInput;
15
+ };
16
+ type PaymentAuthorizationDeleteLedgerInput = {
17
+ authorization: PaymentAuthorizationRecord;
18
+ };
19
+ type PaymentCaptureCreateLedgerInput = {
20
+ capture: PaymentCaptureRecord;
21
+ };
22
+ type PaymentCaptureUpdateLedgerInput = {
23
+ capture: PaymentCaptureRecord;
24
+ changes: UpdatePaymentCaptureInput;
25
+ };
26
+ type PaymentCaptureDeleteLedgerInput = {
27
+ capture: PaymentCaptureRecord;
28
+ };
29
+ export declare function buildPaymentAuthorizationCreateActionLedgerInput(context: ActionLedgerRequestContextValues, input: PaymentAuthorizationCreateLedgerInput, options?: {
30
+ authorizationSource?: string | null;
31
+ }): Promise<BuildActionLedgerMutationInput>;
32
+ export declare function buildPaymentAuthorizationUpdateActionLedgerInput(context: ActionLedgerRequestContextValues, input: PaymentAuthorizationUpdateLedgerInput, options?: {
33
+ authorizationSource?: string | null;
34
+ }): BuildActionLedgerMutationInput;
35
+ export declare function buildPaymentAuthorizationDeleteActionLedgerInput(context: ActionLedgerRequestContextValues, input: PaymentAuthorizationDeleteLedgerInput, options?: {
36
+ authorizationSource?: string | null;
37
+ }): BuildActionLedgerMutationInput;
38
+ export declare function buildPaymentCaptureCreateActionLedgerInput(context: ActionLedgerRequestContextValues, input: PaymentCaptureCreateLedgerInput, options?: {
39
+ authorizationSource?: string | null;
40
+ }): Promise<BuildActionLedgerMutationInput>;
41
+ export declare function buildPaymentCaptureUpdateActionLedgerInput(context: ActionLedgerRequestContextValues, input: PaymentCaptureUpdateLedgerInput, options?: {
42
+ authorizationSource?: string | null;
43
+ }): BuildActionLedgerMutationInput;
44
+ export declare function buildPaymentCaptureDeleteActionLedgerInput(context: ActionLedgerRequestContextValues, input: PaymentCaptureDeleteLedgerInput, options?: {
45
+ authorizationSource?: string | null;
46
+ }): BuildActionLedgerMutationInput;
47
+ export {};
48
+ //# sourceMappingURL=service-action-ledger-payment-authorizations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-action-ledger-payment-authorizations.d.ts","sourceRoot":"","sources":["../src/service-action-ledger-payment-authorizations.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gCAAgC,EACrC,KAAK,8BAA8B,EAEpC,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,KAAK,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACzE,OAAO,KAAK,EAAE,gCAAgC,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAA;AAEnG,KAAK,+BAA+B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gCAAgC,CAAC,CAAA;AACvF,KAAK,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAA;AAE3E,KAAK,0BAA0B,GAAG,OAAO,qBAAqB,CAAC,YAAY,CAAA;AAC3E,KAAK,oBAAoB,GAAG,OAAO,eAAe,CAAC,YAAY,CAAA;AAE/D,KAAK,qCAAqC,GAAG;IAC3C,aAAa,EAAE,0BAA0B,CAAA;CAC1C,CAAA;AACD,KAAK,qCAAqC,GAAG;IAC3C,aAAa,EAAE,0BAA0B,CAAA;IACzC,OAAO,EAAE,+BAA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0BhC;AAED,wBAAgB,0CAA0C,CACxD,OAAO,EAAE,gCAAgC,EACzC,KAAK,EAAE,+BAA+B,EACtC,OAAO,GAAE;IACP,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC/B,GACL,8BAA8B,CAwBhC"}
@@ -0,0 +1,209 @@
1
+ import { buildIdempotencyFingerprint, } from "@voyantjs/action-ledger";
2
+ export async function buildPaymentAuthorizationCreateActionLedgerInput(context, input, options = {}) {
3
+ const target = getPaymentAuthorizationLedgerTarget(input.authorization);
4
+ const idempotencyKey = input.authorization.externalAuthorizationId;
5
+ return {
6
+ context,
7
+ actionName: "finance.payment_authorization.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_authorization.create",
15
+ authorizationSource: options.authorizationSource ?? "finance.payment_authorization.route",
16
+ idempotencyScope: idempotencyKey
17
+ ? `finance.${target.type}:${target.id}:payment_authorization`
18
+ : null,
19
+ idempotencyKey,
20
+ idempotencyFingerprint: idempotencyKey
21
+ ? await buildIdempotencyFingerprint({
22
+ actionName: "finance.payment_authorization.create",
23
+ actionVersion: "v1",
24
+ targetType: target.type,
25
+ targetId: target.id,
26
+ commandInput: {
27
+ paymentAuthorizationId: input.authorization.id,
28
+ bookingId: input.authorization.bookingId,
29
+ orderId: input.authorization.orderId,
30
+ invoiceId: input.authorization.invoiceId,
31
+ bookingGuaranteeId: input.authorization.bookingGuaranteeId,
32
+ amountCents: input.authorization.amountCents,
33
+ currency: input.authorization.currency,
34
+ provider: input.authorization.provider,
35
+ externalAuthorizationId: input.authorization.externalAuthorizationId,
36
+ status: input.authorization.status,
37
+ },
38
+ })
39
+ : null,
40
+ mutationDetail: {
41
+ commandInputRef: `${target.type}:${target.id}:payment_authorization`,
42
+ commandResultRef: `payment_authorization:${input.authorization.id}`,
43
+ summary: `Payment authorization ${input.authorization.id} created for ${target.type} ${target.id}`,
44
+ reversalKind: "none",
45
+ },
46
+ };
47
+ }
48
+ export function buildPaymentAuthorizationUpdateActionLedgerInput(context, input, options = {}) {
49
+ const target = getPaymentAuthorizationLedgerTarget(input.authorization);
50
+ const changedFields = Object.keys(input.changes).sort();
51
+ const changeSummary = changedFields.length > 0 ? changedFields.join(", ") : "no fields";
52
+ return {
53
+ context,
54
+ actionName: "finance.payment_authorization.update",
55
+ actionVersion: "v1",
56
+ actionKind: "update",
57
+ status: "succeeded",
58
+ evaluatedRisk: "high",
59
+ targetType: target.type,
60
+ targetId: target.id,
61
+ routeOrToolName: "finance.payment_authorization.update",
62
+ authorizationSource: options.authorizationSource ?? "finance.payment_authorization.route",
63
+ idempotencyScope: null,
64
+ idempotencyKey: null,
65
+ idempotencyFingerprint: null,
66
+ mutationDetail: {
67
+ commandInputRef: `payment_authorization:${input.authorization.id}:update`,
68
+ commandResultRef: `payment_authorization:${input.authorization.id}`,
69
+ summary: `Payment authorization ${input.authorization.id} updated (${changeSummary})`,
70
+ reversalKind: "none",
71
+ },
72
+ };
73
+ }
74
+ export function buildPaymentAuthorizationDeleteActionLedgerInput(context, input, options = {}) {
75
+ const target = getPaymentAuthorizationLedgerTarget(input.authorization);
76
+ return {
77
+ context,
78
+ actionName: "finance.payment_authorization.delete",
79
+ actionVersion: "v1",
80
+ actionKind: "delete",
81
+ status: "succeeded",
82
+ evaluatedRisk: "high",
83
+ targetType: target.type,
84
+ targetId: target.id,
85
+ routeOrToolName: "finance.payment_authorization.delete",
86
+ authorizationSource: options.authorizationSource ?? "finance.payment_authorization.route",
87
+ idempotencyScope: null,
88
+ idempotencyKey: null,
89
+ idempotencyFingerprint: null,
90
+ mutationDetail: {
91
+ commandInputRef: `payment_authorization:${input.authorization.id}:delete`,
92
+ commandResultRef: null,
93
+ summary: `Payment authorization ${input.authorization.id} deleted`,
94
+ reversalKind: "none",
95
+ },
96
+ };
97
+ }
98
+ function getPaymentAuthorizationLedgerTarget(authorization) {
99
+ if (authorization.bookingId)
100
+ return { type: "booking", id: authorization.bookingId };
101
+ if (authorization.invoiceId)
102
+ return { type: "invoice", id: authorization.invoiceId };
103
+ if (authorization.orderId)
104
+ return { type: "order", id: authorization.orderId };
105
+ if (authorization.bookingGuaranteeId) {
106
+ return { type: "booking_guarantee", id: authorization.bookingGuaranteeId };
107
+ }
108
+ return { type: "payment_authorization", id: authorization.id };
109
+ }
110
+ export async function buildPaymentCaptureCreateActionLedgerInput(context, input, options = {}) {
111
+ const target = getPaymentCaptureLedgerTarget(input.capture);
112
+ const idempotencyKey = input.capture.externalCaptureId;
113
+ return {
114
+ context,
115
+ actionName: "finance.payment_capture.create",
116
+ actionVersion: "v1",
117
+ actionKind: "create",
118
+ status: "succeeded",
119
+ evaluatedRisk: "high",
120
+ targetType: target.type,
121
+ targetId: target.id,
122
+ routeOrToolName: "finance.payment_capture.create",
123
+ authorizationSource: options.authorizationSource ?? "finance.payment_capture.route",
124
+ idempotencyScope: idempotencyKey ? `finance.${target.type}:${target.id}:payment_capture` : null,
125
+ idempotencyKey,
126
+ idempotencyFingerprint: idempotencyKey
127
+ ? await buildIdempotencyFingerprint({
128
+ actionName: "finance.payment_capture.create",
129
+ actionVersion: "v1",
130
+ targetType: target.type,
131
+ targetId: target.id,
132
+ commandInput: {
133
+ paymentCaptureId: input.capture.id,
134
+ paymentAuthorizationId: input.capture.paymentAuthorizationId,
135
+ invoiceId: input.capture.invoiceId,
136
+ amountCents: input.capture.amountCents,
137
+ currency: input.capture.currency,
138
+ provider: input.capture.provider,
139
+ externalCaptureId: input.capture.externalCaptureId,
140
+ status: input.capture.status,
141
+ },
142
+ })
143
+ : null,
144
+ mutationDetail: {
145
+ commandInputRef: `${target.type}:${target.id}:payment_capture`,
146
+ commandResultRef: `payment_capture:${input.capture.id}`,
147
+ summary: `Payment capture ${input.capture.id} created for ${target.type} ${target.id}`,
148
+ reversalKind: "none",
149
+ },
150
+ };
151
+ }
152
+ export function buildPaymentCaptureUpdateActionLedgerInput(context, input, options = {}) {
153
+ const target = getPaymentCaptureLedgerTarget(input.capture);
154
+ const changedFields = Object.keys(input.changes).sort();
155
+ const changeSummary = changedFields.length > 0 ? changedFields.join(", ") : "no fields";
156
+ return {
157
+ context,
158
+ actionName: "finance.payment_capture.update",
159
+ actionVersion: "v1",
160
+ actionKind: "update",
161
+ status: "succeeded",
162
+ evaluatedRisk: "high",
163
+ targetType: target.type,
164
+ targetId: target.id,
165
+ routeOrToolName: "finance.payment_capture.update",
166
+ authorizationSource: options.authorizationSource ?? "finance.payment_capture.route",
167
+ idempotencyScope: null,
168
+ idempotencyKey: null,
169
+ idempotencyFingerprint: null,
170
+ mutationDetail: {
171
+ commandInputRef: `payment_capture:${input.capture.id}:update`,
172
+ commandResultRef: `payment_capture:${input.capture.id}`,
173
+ summary: `Payment capture ${input.capture.id} updated (${changeSummary})`,
174
+ reversalKind: "none",
175
+ },
176
+ };
177
+ }
178
+ export function buildPaymentCaptureDeleteActionLedgerInput(context, input, options = {}) {
179
+ const target = getPaymentCaptureLedgerTarget(input.capture);
180
+ return {
181
+ context,
182
+ actionName: "finance.payment_capture.delete",
183
+ actionVersion: "v1",
184
+ actionKind: "delete",
185
+ status: "succeeded",
186
+ evaluatedRisk: "high",
187
+ targetType: target.type,
188
+ targetId: target.id,
189
+ routeOrToolName: "finance.payment_capture.delete",
190
+ authorizationSource: options.authorizationSource ?? "finance.payment_capture.route",
191
+ idempotencyScope: null,
192
+ idempotencyKey: null,
193
+ idempotencyFingerprint: null,
194
+ mutationDetail: {
195
+ commandInputRef: `payment_capture:${input.capture.id}:delete`,
196
+ commandResultRef: null,
197
+ summary: `Payment capture ${input.capture.id} deleted`,
198
+ reversalKind: "none",
199
+ },
200
+ };
201
+ }
202
+ function getPaymentCaptureLedgerTarget(capture) {
203
+ if (capture.invoiceId)
204
+ return { type: "invoice", id: capture.invoiceId };
205
+ if (capture.paymentAuthorizationId) {
206
+ return { type: "payment_authorization", id: capture.paymentAuthorizationId };
207
+ }
208
+ return { type: "payment_capture", id: capture.id };
209
+ }
@@ -0,0 +1,83 @@
1
+ import { type ActionLedgerRequestContextValues, type BuildActionLedgerMutationInput } from "@voyantjs/action-ledger";
2
+ import type { z } from "zod";
3
+ import type { paymentInstruments, paymentSessions } from "./schema.js";
4
+ import type { cancelPaymentSessionSchema, completePaymentSessionSchema, expirePaymentSessionSchema, failPaymentSessionSchema, markPaymentSessionRequiresRedirectSchema, updatePaymentInstrumentSchema, updatePaymentSessionSchema } from "./validation.js";
5
+ type CompletePaymentSessionInput = z.infer<typeof completePaymentSessionSchema>;
6
+ type UpdatePaymentSessionInput = z.infer<typeof updatePaymentSessionSchema>;
7
+ type MarkPaymentSessionRequiresRedirectInput = z.infer<typeof markPaymentSessionRequiresRedirectSchema>;
8
+ type FailPaymentSessionInput = z.infer<typeof failPaymentSessionSchema>;
9
+ type CancelPaymentSessionInput = z.infer<typeof cancelPaymentSessionSchema>;
10
+ type ExpirePaymentSessionInput = z.infer<typeof expirePaymentSessionSchema>;
11
+ type UpdatePaymentInstrumentInput = z.infer<typeof updatePaymentInstrumentSchema>;
12
+ type PaymentSessionRecord = typeof paymentSessions.$inferSelect;
13
+ type PaymentInstrumentRecord = typeof paymentInstruments.$inferSelect;
14
+ type CreatePaymentSessionLedgerInput = {
15
+ session: PaymentSessionRecord;
16
+ };
17
+ type CompletePaymentSessionLedgerInput = {
18
+ session: PaymentSessionRecord;
19
+ status: CompletePaymentSessionInput["status"];
20
+ paymentId: string | null;
21
+ };
22
+ type PaymentSessionUpdateLedgerInput = {
23
+ session: PaymentSessionRecord;
24
+ changes: UpdatePaymentSessionInput;
25
+ };
26
+ type PaymentSessionRedirectLedgerInput = {
27
+ session: PaymentSessionRecord;
28
+ changes: MarkPaymentSessionRequiresRedirectInput;
29
+ };
30
+ type PaymentSessionFailedLedgerInput = {
31
+ session: PaymentSessionRecord;
32
+ changes: FailPaymentSessionInput;
33
+ };
34
+ type PaymentSessionCancelledLedgerInput = {
35
+ session: PaymentSessionRecord;
36
+ changes: CancelPaymentSessionInput;
37
+ };
38
+ type PaymentSessionExpiredLedgerInput = {
39
+ session: PaymentSessionRecord;
40
+ changes: ExpirePaymentSessionInput;
41
+ };
42
+ type PaymentInstrumentCreateLedgerInput = {
43
+ instrument: PaymentInstrumentRecord;
44
+ };
45
+ type PaymentInstrumentUpdateLedgerInput = {
46
+ instrument: PaymentInstrumentRecord;
47
+ changes: UpdatePaymentInstrumentInput;
48
+ };
49
+ type PaymentInstrumentDeleteLedgerInput = {
50
+ instrument: PaymentInstrumentRecord;
51
+ };
52
+ export declare function buildPaymentInstrumentCreateActionLedgerInput(context: ActionLedgerRequestContextValues, input: PaymentInstrumentCreateLedgerInput, options?: {
53
+ authorizationSource?: string | null;
54
+ }): BuildActionLedgerMutationInput;
55
+ export declare function buildPaymentInstrumentUpdateActionLedgerInput(context: ActionLedgerRequestContextValues, input: PaymentInstrumentUpdateLedgerInput, options?: {
56
+ authorizationSource?: string | null;
57
+ }): BuildActionLedgerMutationInput;
58
+ export declare function buildPaymentInstrumentDeleteActionLedgerInput(context: ActionLedgerRequestContextValues, input: PaymentInstrumentDeleteLedgerInput, options?: {
59
+ authorizationSource?: string | null;
60
+ }): BuildActionLedgerMutationInput;
61
+ export declare function buildPaymentSessionCreateActionLedgerInput(context: ActionLedgerRequestContextValues, input: CreatePaymentSessionLedgerInput, options?: {
62
+ authorizationSource?: string | null;
63
+ }): Promise<BuildActionLedgerMutationInput>;
64
+ export declare function buildPaymentSessionCompletionActionLedgerInput(context: ActionLedgerRequestContextValues, input: CompletePaymentSessionLedgerInput, options?: {
65
+ authorizationSource?: string | null;
66
+ }): Promise<BuildActionLedgerMutationInput>;
67
+ export declare function buildPaymentSessionUpdateActionLedgerInput(context: ActionLedgerRequestContextValues, input: PaymentSessionUpdateLedgerInput, options?: {
68
+ authorizationSource?: string | null;
69
+ }): BuildActionLedgerMutationInput;
70
+ export declare function buildPaymentSessionRequiresRedirectActionLedgerInput(context: ActionLedgerRequestContextValues, input: PaymentSessionRedirectLedgerInput, options?: {
71
+ authorizationSource?: string | null;
72
+ }): BuildActionLedgerMutationInput;
73
+ export declare function buildPaymentSessionFailedActionLedgerInput(context: ActionLedgerRequestContextValues, input: PaymentSessionFailedLedgerInput, options?: {
74
+ authorizationSource?: string | null;
75
+ }): BuildActionLedgerMutationInput;
76
+ export declare function buildPaymentSessionCancelledActionLedgerInput(context: ActionLedgerRequestContextValues, input: PaymentSessionCancelledLedgerInput, options?: {
77
+ authorizationSource?: string | null;
78
+ }): BuildActionLedgerMutationInput;
79
+ export declare function buildPaymentSessionExpiredActionLedgerInput(context: ActionLedgerRequestContextValues, input: PaymentSessionExpiredLedgerInput, options?: {
80
+ authorizationSource?: string | null;
81
+ }): BuildActionLedgerMutationInput;
82
+ export {};
83
+ //# sourceMappingURL=service-action-ledger-payment-sessions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-action-ledger-payment-sessions.d.ts","sourceRoot":"","sources":["../src/service-action-ledger-payment-sessions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gCAAgC,EACrC,KAAK,8BAA8B,EAEpC,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACtE,OAAO,KAAK,EACV,0BAA0B,EAC1B,4BAA4B,EAC5B,0BAA0B,EAC1B,wBAAwB,EACxB,wCAAwC,EACxC,6BAA6B,EAC7B,0BAA0B,EAC3B,MAAM,iBAAiB,CAAA;AAExB,KAAK,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAA;AAC/E,KAAK,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAA;AAC3E,KAAK,uCAAuC,GAAG,CAAC,CAAC,KAAK,CACpD,OAAO,wCAAwC,CAChD,CA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