@voyantjs/finance-contracts 0.95.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/README.md +25 -0
- package/dist/contracts.test.d.ts +2 -0
- package/dist/contracts.test.d.ts.map +1 -0
- package/dist/contracts.test.js +12 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/validation-billing.d.ts +827 -0
- package/dist/validation-billing.d.ts.map +1 -0
- package/dist/validation-billing.js +436 -0
- package/dist/validation-payments.d.ts +933 -0
- package/dist/validation-payments.d.ts.map +1 -0
- package/dist/validation-payments.js +339 -0
- package/dist/validation-public.d.ts +505 -0
- package/dist/validation-public.d.ts.map +1 -0
- package/dist/validation-public.js +216 -0
- package/dist/validation-shared.d.ts +200 -0
- package/dist/validation-shared.d.ts.map +1 -0
- package/dist/validation-shared.js +179 -0
- package/dist/validation-vouchers.d.ts +62 -0
- package/dist/validation-vouchers.d.ts.map +1 -0
- package/dist/validation-vouchers.js +46 -0
- package/dist/validation.d.ts +6 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +5 -0
- package/package.json +52 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-billing.d.ts","sourceRoot":"","sources":["../src/validation-billing.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AA0BvB,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;iBAA+B,CAAA;AAC1E,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;iBAAyC,CAAA;AAepF,eAAO,MAAM,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAkC,CAAA;AAChF,eAAO,MAAM,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAA4C,CAAA;AA4B1F,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAA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AAEF,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;iBAMnC,CAAA;AAEF,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;;;;;;iBAS7C,CAAA;AAEF,eAAO,MAAM,8BAA8B;;;;;;;iBAAkC,CAAA;AAE7E,eAAO,MAAM,oCAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmB/C,CAAA;AAEF,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kCAAkC,CAAC,CAAA;AAC7F,MAAM,MAAM,8BAA8B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oCAAoC,CAAC,CAAA;AACjG,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gCAAgC,CAAC,CAAA;AACzF,MAAM,MAAM,6BAA6B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mCAAmC,CAAC,CAAA"}
|
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
import { booleanQueryParam } from "@voyantjs/schema-kit/query-params";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { commissionModelSchema, commissionRecipientTypeSchema, commissionStatusSchema, creditNoteStatusSchema, invoiceStatusSchema, paginationSchema, paymentMethodSchema, taxScopeSchema, } from "./validation-shared.js";
|
|
4
|
+
const bookingItemTaxLineCoreSchema = z.object({
|
|
5
|
+
code: z.string().max(100).optional().nullable(),
|
|
6
|
+
name: z.string().min(1).max(255),
|
|
7
|
+
jurisdiction: z.string().max(255).optional().nullable(),
|
|
8
|
+
scope: taxScopeSchema.default("excluded"),
|
|
9
|
+
currency: z.string().min(3).max(3),
|
|
10
|
+
amountCents: z.number().int(),
|
|
11
|
+
rateBasisPoints: z.number().int().min(0).optional().nullable(),
|
|
12
|
+
includedInPrice: z.boolean().default(false),
|
|
13
|
+
remittanceParty: z.string().max(255).optional().nullable(),
|
|
14
|
+
sortOrder: z.number().int().min(0).default(0),
|
|
15
|
+
});
|
|
16
|
+
export const insertBookingItemTaxLineSchema = bookingItemTaxLineCoreSchema;
|
|
17
|
+
export const updateBookingItemTaxLineSchema = bookingItemTaxLineCoreSchema.partial();
|
|
18
|
+
const bookingItemCommissionCoreSchema = z.object({
|
|
19
|
+
channelId: z.string().optional().nullable(),
|
|
20
|
+
recipientType: commissionRecipientTypeSchema,
|
|
21
|
+
commissionModel: commissionModelSchema.default("percentage"),
|
|
22
|
+
currency: z.string().min(3).max(3).optional().nullable(),
|
|
23
|
+
amountCents: z.number().int().optional().nullable(),
|
|
24
|
+
rateBasisPoints: z.number().int().min(0).optional().nullable(),
|
|
25
|
+
status: commissionStatusSchema.default("pending"),
|
|
26
|
+
payableAt: z.string().optional().nullable(),
|
|
27
|
+
paidAt: z.string().optional().nullable(),
|
|
28
|
+
notes: z.string().optional().nullable(),
|
|
29
|
+
});
|
|
30
|
+
export const insertBookingItemCommissionSchema = bookingItemCommissionCoreSchema;
|
|
31
|
+
export const updateBookingItemCommissionSchema = bookingItemCommissionCoreSchema.partial();
|
|
32
|
+
const invoiceCoreSchema = z.object({
|
|
33
|
+
invoiceNumber: z.string().min(1).max(50),
|
|
34
|
+
bookingId: z.string().min(1),
|
|
35
|
+
personId: z.string().optional().nullable(),
|
|
36
|
+
organizationId: z.string().optional().nullable(),
|
|
37
|
+
status: invoiceStatusSchema.default("draft"),
|
|
38
|
+
currency: z.string().min(3).max(3),
|
|
39
|
+
baseCurrency: z.string().min(3).max(3).optional().nullable(),
|
|
40
|
+
fxRateSetId: z.string().optional().nullable(),
|
|
41
|
+
subtotalCents: z.number().int().min(0).default(0),
|
|
42
|
+
baseSubtotalCents: z.number().int().min(0).optional().nullable(),
|
|
43
|
+
taxCents: z.number().int().min(0).default(0),
|
|
44
|
+
baseTaxCents: z.number().int().min(0).optional().nullable(),
|
|
45
|
+
totalCents: z.number().int().min(0).default(0),
|
|
46
|
+
baseTotalCents: z.number().int().min(0).optional().nullable(),
|
|
47
|
+
paidCents: z.number().int().min(0).default(0),
|
|
48
|
+
basePaidCents: z.number().int().min(0).optional().nullable(),
|
|
49
|
+
balanceDueCents: z.number().int().min(0).default(0),
|
|
50
|
+
baseBalanceDueCents: z.number().int().min(0).optional().nullable(),
|
|
51
|
+
commissionPercent: z.number().int().min(0).max(100).optional().nullable(),
|
|
52
|
+
commissionAmountCents: z.number().int().min(0).optional().nullable(),
|
|
53
|
+
issueDate: z.string().min(1),
|
|
54
|
+
dueDate: z.string().min(1),
|
|
55
|
+
notes: z.string().optional().nullable(),
|
|
56
|
+
});
|
|
57
|
+
export const insertInvoiceSchema = invoiceCoreSchema;
|
|
58
|
+
export const updateInvoiceSchema = invoiceCoreSchema.partial();
|
|
59
|
+
export const voidInvoiceSchema = z.object({
|
|
60
|
+
reason: z.string().trim().max(1000).optional().nullable(),
|
|
61
|
+
});
|
|
62
|
+
export const invoiceListSortFieldSchema = z.enum([
|
|
63
|
+
"invoiceNumber",
|
|
64
|
+
"status",
|
|
65
|
+
"totalCents",
|
|
66
|
+
"paidCents",
|
|
67
|
+
"balanceDueCents",
|
|
68
|
+
"issueDate",
|
|
69
|
+
"dueDate",
|
|
70
|
+
"createdAt",
|
|
71
|
+
]);
|
|
72
|
+
export const invoiceListSortDirSchema = z.enum(["asc", "desc"]);
|
|
73
|
+
export const invoiceListQuerySchema = z.object({
|
|
74
|
+
status: invoiceStatusSchema.optional(),
|
|
75
|
+
bookingId: z.string().optional(),
|
|
76
|
+
personId: z.string().optional(),
|
|
77
|
+
organizationId: z.string().optional(),
|
|
78
|
+
currency: z.string().optional(),
|
|
79
|
+
dueDateFrom: z.string().optional(),
|
|
80
|
+
dueDateTo: z.string().optional(),
|
|
81
|
+
search: z.string().optional(),
|
|
82
|
+
sortBy: invoiceListSortFieldSchema.default("createdAt"),
|
|
83
|
+
sortDir: invoiceListSortDirSchema.default("desc"),
|
|
84
|
+
limit: z.coerce.number().int().min(1).max(100).default(50),
|
|
85
|
+
offset: z.coerce.number().int().min(0).default(0),
|
|
86
|
+
});
|
|
87
|
+
const invoiceDocumentWaitModeSchema = z.preprocess((value) => {
|
|
88
|
+
if (value === true || value === "true")
|
|
89
|
+
return "pdf";
|
|
90
|
+
if (value === false || value === "false")
|
|
91
|
+
return "none";
|
|
92
|
+
return value;
|
|
93
|
+
}, z.enum(["none", "pdf", "any"]));
|
|
94
|
+
const invoiceDocumentWaitFieldsSchema = z.object({
|
|
95
|
+
wait: invoiceDocumentWaitModeSchema.optional(),
|
|
96
|
+
waitTimeoutMs: z.coerce.number().int().min(0).max(60_000).optional(),
|
|
97
|
+
});
|
|
98
|
+
const currencyCodeSchema = z
|
|
99
|
+
.string()
|
|
100
|
+
.trim()
|
|
101
|
+
.length(3)
|
|
102
|
+
.transform((value) => value.toUpperCase());
|
|
103
|
+
const invoiceFromBookingLineItemSchema = z.object({
|
|
104
|
+
description: z.string().min(1).max(500),
|
|
105
|
+
quantity: z.number().int().min(1),
|
|
106
|
+
unitAmountCents: z.number().int().min(0),
|
|
107
|
+
taxRateBps: z.number().int().min(0).optional().nullable(),
|
|
108
|
+
taxAmountCents: z.number().int().min(0).optional().nullable(),
|
|
109
|
+
});
|
|
110
|
+
const invoiceExternalRefCoreSchema = z.object({
|
|
111
|
+
provider: z.string().min(1).max(100),
|
|
112
|
+
externalId: z.string().max(255).optional().nullable(),
|
|
113
|
+
externalNumber: z.string().max(255).optional().nullable(),
|
|
114
|
+
externalUrl: z.string().max(1000).optional().nullable(),
|
|
115
|
+
status: z.string().max(100).optional().nullable(),
|
|
116
|
+
metadata: z.record(z.string(), z.unknown()).optional().nullable(),
|
|
117
|
+
syncedAt: z.string().optional().nullable(),
|
|
118
|
+
syncError: z.string().optional().nullable(),
|
|
119
|
+
});
|
|
120
|
+
export const invoiceFromBookingSchema = z
|
|
121
|
+
.object({
|
|
122
|
+
bookingId: z.string().min(1),
|
|
123
|
+
bookingPaymentScheduleId: z.string().min(1).optional(),
|
|
124
|
+
invoiceNumber: z.string().min(1).max(50).optional(),
|
|
125
|
+
seriesId: z.string().min(1).optional(),
|
|
126
|
+
issueDate: z.string().min(1),
|
|
127
|
+
dueDate: z.string().min(1),
|
|
128
|
+
notes: z.string().optional().nullable(),
|
|
129
|
+
currency: currencyCodeSchema.optional(),
|
|
130
|
+
baseCurrency: currencyCodeSchema.optional(),
|
|
131
|
+
fxRateSetId: z.string().min(1).optional(),
|
|
132
|
+
subtotalCents: z.number().int().min(0).optional(),
|
|
133
|
+
taxCents: z.number().int().min(0).optional(),
|
|
134
|
+
totalCents: z.number().int().min(0).optional(),
|
|
135
|
+
lineItems: z.array(invoiceFromBookingLineItemSchema).min(1).optional(),
|
|
136
|
+
paymentScheduleLineDescriptionFormat: z
|
|
137
|
+
.enum(["schedule_first", "product_first", "product_only"])
|
|
138
|
+
.optional(),
|
|
139
|
+
externalRefs: z.array(invoiceExternalRefCoreSchema).optional(),
|
|
140
|
+
/**
|
|
141
|
+
* Document kind. Defaults to a regular invoice; bank-transfer
|
|
142
|
+
* checkout flows pass `proforma` to issue a placeholder doc until
|
|
143
|
+
* payment lands and a real invoice replaces it.
|
|
144
|
+
*/
|
|
145
|
+
invoiceType: z.enum(["invoice", "proforma"]).default("invoice"),
|
|
146
|
+
/**
|
|
147
|
+
* When `true`, downstream e-invoicing plugins (e.g. SmartBill) skip
|
|
148
|
+
* the auto-sync triggered by `invoice.issued` / `invoice.proforma.issued`.
|
|
149
|
+
* The event still fires so other subscribers (ledgers, audit, etc.)
|
|
150
|
+
* see it; only the external-provider subscribers honour this flag.
|
|
151
|
+
*/
|
|
152
|
+
skipExternalSync: z.boolean().optional(),
|
|
153
|
+
wait: invoiceDocumentWaitModeSchema.optional(),
|
|
154
|
+
waitTimeoutMs: z.coerce.number().int().min(0).max(60_000).optional(),
|
|
155
|
+
})
|
|
156
|
+
.superRefine((value, ctx) => {
|
|
157
|
+
const providers = new Set();
|
|
158
|
+
for (const [index, ref] of (value.externalRefs ?? []).entries()) {
|
|
159
|
+
if (providers.has(ref.provider)) {
|
|
160
|
+
ctx.addIssue({
|
|
161
|
+
code: z.ZodIssueCode.custom,
|
|
162
|
+
message: "Duplicate invoice external ref provider",
|
|
163
|
+
path: ["externalRefs", index, "provider"],
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
providers.add(ref.provider);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
const lineItemCoreSchema = z.object({
|
|
170
|
+
bookingItemId: z.string().optional().nullable(),
|
|
171
|
+
bookingPaymentScheduleId: z.string().optional().nullable(),
|
|
172
|
+
description: z.string().min(1).max(1000),
|
|
173
|
+
quantity: z.number().int().min(1).default(1),
|
|
174
|
+
unitPriceCents: z.number().int().min(0),
|
|
175
|
+
totalCents: z.number().int().min(0),
|
|
176
|
+
taxRate: z.number().int().min(0).optional().nullable(),
|
|
177
|
+
sortOrder: z.number().int().min(0).default(0),
|
|
178
|
+
});
|
|
179
|
+
export const insertInvoiceLineItemSchema = lineItemCoreSchema;
|
|
180
|
+
export const updateInvoiceLineItemSchema = lineItemCoreSchema.partial();
|
|
181
|
+
const creditNoteCoreSchema = z.object({
|
|
182
|
+
creditNoteNumber: z.string().min(1).max(50),
|
|
183
|
+
status: creditNoteStatusSchema.default("draft"),
|
|
184
|
+
amountCents: z.number().int().min(1),
|
|
185
|
+
currency: z.string().min(3).max(3),
|
|
186
|
+
baseCurrency: z.string().min(3).max(3).optional().nullable(),
|
|
187
|
+
baseAmountCents: z.number().int().min(0).optional().nullable(),
|
|
188
|
+
fxRateSetId: z.string().optional().nullable(),
|
|
189
|
+
reason: z.string().min(1).max(1000),
|
|
190
|
+
notes: z.string().optional().nullable(),
|
|
191
|
+
});
|
|
192
|
+
export const insertCreditNoteSchema = creditNoteCoreSchema;
|
|
193
|
+
export const updateCreditNoteSchema = creditNoteCoreSchema.partial();
|
|
194
|
+
const creditNoteLineItemCoreSchema = z.object({
|
|
195
|
+
description: z.string().min(1).max(1000),
|
|
196
|
+
quantity: z.number().int().min(1).default(1),
|
|
197
|
+
unitPriceCents: z.number().int().min(0),
|
|
198
|
+
totalCents: z.number().int().min(0),
|
|
199
|
+
sortOrder: z.number().int().min(0).default(0),
|
|
200
|
+
});
|
|
201
|
+
export const insertCreditNoteLineItemSchema = creditNoteLineItemCoreSchema;
|
|
202
|
+
export const updateCreditNoteLineItemSchema = creditNoteLineItemCoreSchema.partial();
|
|
203
|
+
export const insertFinanceNoteSchema = z.object({
|
|
204
|
+
content: z.string().min(1).max(10000),
|
|
205
|
+
});
|
|
206
|
+
export const revenueReportQuerySchema = z.object({ from: z.string().min(1), to: z.string().min(1) });
|
|
207
|
+
export const agingReportQuerySchema = z.object({ asOf: z.string().optional() });
|
|
208
|
+
export const profitabilityQuerySchema = z.object({
|
|
209
|
+
from: z.string().optional(),
|
|
210
|
+
to: z.string().optional(),
|
|
211
|
+
});
|
|
212
|
+
const invoiceNumberResetStrategySchema = z.enum(["never", "annual", "monthly"]);
|
|
213
|
+
const invoiceNumberSeriesScopeSchema = z.enum(["invoice", "proforma", "credit_note"]);
|
|
214
|
+
const invoiceNumberSeriesCoreSchema = z.object({
|
|
215
|
+
code: z.string().min(1).max(100),
|
|
216
|
+
name: z.string().min(1).max(255),
|
|
217
|
+
prefix: z.string().max(50).default(""),
|
|
218
|
+
separator: z.string().max(10).default(""),
|
|
219
|
+
padLength: z.number().int().min(0).max(20).default(4),
|
|
220
|
+
currentSequence: z.number().int().min(0).default(0),
|
|
221
|
+
resetStrategy: invoiceNumberResetStrategySchema.default("never"),
|
|
222
|
+
resetAt: z.string().optional().nullable(),
|
|
223
|
+
scope: invoiceNumberSeriesScopeSchema.default("invoice"),
|
|
224
|
+
isDefault: z.boolean().default(false),
|
|
225
|
+
externalProvider: z.string().min(1).max(100).optional().nullable(),
|
|
226
|
+
externalConfigKey: z.string().min(1).max(100).optional().nullable(),
|
|
227
|
+
active: z.boolean().default(true),
|
|
228
|
+
});
|
|
229
|
+
export const insertInvoiceNumberSeriesSchema = invoiceNumberSeriesCoreSchema;
|
|
230
|
+
export const updateInvoiceNumberSeriesSchema = invoiceNumberSeriesCoreSchema.partial();
|
|
231
|
+
export const invoiceNumberSeriesListQuerySchema = paginationSchema.extend({
|
|
232
|
+
scope: invoiceNumberSeriesScopeSchema.optional(),
|
|
233
|
+
active: booleanQueryParam.optional(),
|
|
234
|
+
});
|
|
235
|
+
export const allocateInvoiceNumberInputSchema = z.object({ seriesId: z.string().min(1) });
|
|
236
|
+
const invoiceTemplateBodyFormatSchema = z.enum(["html", "markdown", "lexical_json"]);
|
|
237
|
+
const invoiceTemplateCoreSchema = z.object({
|
|
238
|
+
name: z.string().min(1).max(255),
|
|
239
|
+
slug: z
|
|
240
|
+
.string()
|
|
241
|
+
.min(1)
|
|
242
|
+
.max(100)
|
|
243
|
+
.regex(/^[a-z0-9-]+$/, "slug must be kebab-case"),
|
|
244
|
+
language: z.string().min(2).max(10).default("en"),
|
|
245
|
+
jurisdiction: z.string().max(10).optional().nullable(),
|
|
246
|
+
bodyFormat: invoiceTemplateBodyFormatSchema.default("html"),
|
|
247
|
+
body: z.string().min(1),
|
|
248
|
+
cssStyles: z.string().optional().nullable(),
|
|
249
|
+
isDefault: z.boolean().default(false),
|
|
250
|
+
active: z.boolean().default(true),
|
|
251
|
+
metadata: z.record(z.string(), z.unknown()).optional().nullable(),
|
|
252
|
+
});
|
|
253
|
+
export const insertInvoiceTemplateSchema = invoiceTemplateCoreSchema;
|
|
254
|
+
export const updateInvoiceTemplateSchema = invoiceTemplateCoreSchema.partial();
|
|
255
|
+
export const invoiceTemplateListQuerySchema = paginationSchema.extend({
|
|
256
|
+
language: z.string().optional(),
|
|
257
|
+
jurisdiction: z.string().optional(),
|
|
258
|
+
active: z.coerce.boolean().optional(),
|
|
259
|
+
search: z.string().optional(),
|
|
260
|
+
});
|
|
261
|
+
const invoiceRenditionFormatSchema = z.enum(["html", "pdf", "xml", "json"]);
|
|
262
|
+
const invoiceRenditionStatusSchema = z.enum(["pending", "ready", "failed", "stale"]);
|
|
263
|
+
const invoiceRenditionCoreSchema = z.object({
|
|
264
|
+
templateId: z.string().optional().nullable(),
|
|
265
|
+
format: invoiceRenditionFormatSchema.default("pdf"),
|
|
266
|
+
status: invoiceRenditionStatusSchema.default("pending"),
|
|
267
|
+
storageKey: z.string().optional().nullable(),
|
|
268
|
+
fileSize: z.number().int().min(0).optional().nullable(),
|
|
269
|
+
checksum: z.string().optional().nullable(),
|
|
270
|
+
language: z.string().optional().nullable(),
|
|
271
|
+
errorMessage: z.string().optional().nullable(),
|
|
272
|
+
generatedAt: z.string().optional().nullable(),
|
|
273
|
+
metadata: z.record(z.string(), z.unknown()).optional().nullable(),
|
|
274
|
+
});
|
|
275
|
+
export const insertInvoiceRenditionSchema = invoiceRenditionCoreSchema;
|
|
276
|
+
export const updateInvoiceRenditionSchema = invoiceRenditionCoreSchema.partial();
|
|
277
|
+
const invoiceAttachmentCoreSchema = z.object({
|
|
278
|
+
kind: z.string().min(1).max(50).default("supporting_document"),
|
|
279
|
+
name: z.string().min(1).max(255),
|
|
280
|
+
mimeType: z.string().max(255).optional().nullable(),
|
|
281
|
+
fileSize: z.number().int().min(0).optional().nullable(),
|
|
282
|
+
storageKey: z.string().max(1000).optional().nullable(),
|
|
283
|
+
checksum: z.string().max(255).optional().nullable(),
|
|
284
|
+
metadata: z.record(z.string(), z.unknown()).optional().nullable(),
|
|
285
|
+
});
|
|
286
|
+
export const insertInvoiceAttachmentSchema = invoiceAttachmentCoreSchema;
|
|
287
|
+
export const updateInvoiceAttachmentSchema = invoiceAttachmentCoreSchema.partial();
|
|
288
|
+
const taxRegimeCodeSchema = z.enum([
|
|
289
|
+
"standard",
|
|
290
|
+
"reduced",
|
|
291
|
+
"exempt",
|
|
292
|
+
"reverse_charge",
|
|
293
|
+
"margin_scheme_art311",
|
|
294
|
+
"zero_rated",
|
|
295
|
+
"out_of_scope",
|
|
296
|
+
"other",
|
|
297
|
+
]);
|
|
298
|
+
const taxRegimeCoreSchema = z.object({
|
|
299
|
+
code: taxRegimeCodeSchema,
|
|
300
|
+
name: z.string().min(1).max(255),
|
|
301
|
+
jurisdiction: z.string().max(10).optional().nullable(),
|
|
302
|
+
ratePercent: z.number().int().min(0).max(10000).optional().nullable(),
|
|
303
|
+
description: z.string().max(2000).optional().nullable(),
|
|
304
|
+
legalReference: z.string().max(500).optional().nullable(),
|
|
305
|
+
active: z.boolean().default(true),
|
|
306
|
+
metadata: z.record(z.string(), z.unknown()).optional().nullable(),
|
|
307
|
+
});
|
|
308
|
+
export const insertTaxRegimeSchema = taxRegimeCoreSchema;
|
|
309
|
+
export const updateTaxRegimeSchema = taxRegimeCoreSchema.partial();
|
|
310
|
+
export const taxRegimeListQuerySchema = paginationSchema.extend({
|
|
311
|
+
code: taxRegimeCodeSchema.optional(),
|
|
312
|
+
jurisdiction: z.string().optional(),
|
|
313
|
+
active: z.coerce.boolean().optional(),
|
|
314
|
+
});
|
|
315
|
+
const taxClassLineSchema = z.object({
|
|
316
|
+
regime_id: z.string().min(1),
|
|
317
|
+
applies_to: z.enum(["base", "addon", "accommodation", "all"]),
|
|
318
|
+
});
|
|
319
|
+
const taxClassCoreSchema = z.object({
|
|
320
|
+
code: z.string().min(1).max(100),
|
|
321
|
+
label: z.string().min(1).max(255),
|
|
322
|
+
description: z.string().max(2000).optional().nullable(),
|
|
323
|
+
defaultRegimeId: z.string().optional().nullable(),
|
|
324
|
+
lines: z.array(taxClassLineSchema).optional().nullable(),
|
|
325
|
+
active: z.boolean().default(true),
|
|
326
|
+
});
|
|
327
|
+
export const insertTaxClassSchema = taxClassCoreSchema;
|
|
328
|
+
export const updateTaxClassSchema = taxClassCoreSchema.partial();
|
|
329
|
+
export const taxClassListQuerySchema = paginationSchema.extend({
|
|
330
|
+
code: z.string().optional(),
|
|
331
|
+
active: z.coerce.boolean().optional(),
|
|
332
|
+
});
|
|
333
|
+
const taxPolicySideSchema = z.enum(["sell", "buy"]);
|
|
334
|
+
const taxPolicyAppliesToSchema = z.enum(["base", "addon", "accommodation", "all"]);
|
|
335
|
+
const taxPolicyProfileCoreSchema = z.object({
|
|
336
|
+
code: z.string().min(1).max(100),
|
|
337
|
+
name: z.string().min(1).max(255),
|
|
338
|
+
jurisdiction: z.string().max(10).optional().nullable(),
|
|
339
|
+
description: z.string().max(2000).optional().nullable(),
|
|
340
|
+
active: z.boolean().default(true),
|
|
341
|
+
});
|
|
342
|
+
export const insertTaxPolicyProfileSchema = taxPolicyProfileCoreSchema;
|
|
343
|
+
export const updateTaxPolicyProfileSchema = taxPolicyProfileCoreSchema.partial();
|
|
344
|
+
export const taxPolicyProfileListQuerySchema = paginationSchema.extend({
|
|
345
|
+
code: z.string().optional(),
|
|
346
|
+
jurisdiction: z.string().optional(),
|
|
347
|
+
active: z.coerce.boolean().optional(),
|
|
348
|
+
});
|
|
349
|
+
const taxPolicyConditionSchema = z.record(z.string(), z.unknown()).optional().nullable();
|
|
350
|
+
const taxPolicyRuleCoreSchema = z.object({
|
|
351
|
+
profileId: z.string().min(1),
|
|
352
|
+
side: taxPolicySideSchema.default("sell"),
|
|
353
|
+
priority: z.number().int().min(0).default(100),
|
|
354
|
+
name: z.string().min(1).max(255),
|
|
355
|
+
appliesTo: taxPolicyAppliesToSchema.default("all"),
|
|
356
|
+
condition: taxPolicyConditionSchema,
|
|
357
|
+
taxRegimeId: z.string().min(1),
|
|
358
|
+
active: z.boolean().default(true),
|
|
359
|
+
});
|
|
360
|
+
export const insertTaxPolicyRuleSchema = taxPolicyRuleCoreSchema;
|
|
361
|
+
export const updateTaxPolicyRuleSchema = taxPolicyRuleCoreSchema.partial();
|
|
362
|
+
export const taxPolicyRuleListQuerySchema = paginationSchema.extend({
|
|
363
|
+
profileId: z.string().optional(),
|
|
364
|
+
side: taxPolicySideSchema.optional(),
|
|
365
|
+
active: z.coerce.boolean().optional(),
|
|
366
|
+
});
|
|
367
|
+
export const insertInvoiceExternalRefSchema = invoiceExternalRefCoreSchema;
|
|
368
|
+
export const updateInvoiceExternalRefSchema = invoiceExternalRefCoreSchema.partial();
|
|
369
|
+
export const pollInvoiceSettlementInputSchema = z.object({
|
|
370
|
+
provider: z.string().min(1).max(100).optional().nullable(),
|
|
371
|
+
reconcilePayment: z.boolean().default(true),
|
|
372
|
+
paymentMethod: paymentMethodSchema.default("bank_transfer"),
|
|
373
|
+
paymentDate: z.string().optional().nullable(),
|
|
374
|
+
referenceNumber: z.string().max(255).optional().nullable(),
|
|
375
|
+
notes: z.string().optional().nullable(),
|
|
376
|
+
});
|
|
377
|
+
export const polledInvoiceSettlementProviderResultSchema = z.object({
|
|
378
|
+
provider: z.string(),
|
|
379
|
+
externalRefId: z.string(),
|
|
380
|
+
externalId: z.string().nullable(),
|
|
381
|
+
externalNumber: z.string().nullable(),
|
|
382
|
+
externalUrl: z.string().nullable(),
|
|
383
|
+
status: z.string().nullable(),
|
|
384
|
+
paidAmountCents: z.number().int().nullable(),
|
|
385
|
+
unpaidAmountCents: z.number().int().nullable(),
|
|
386
|
+
syncedAt: z.string().nullable(),
|
|
387
|
+
settledAt: z.string().nullable(),
|
|
388
|
+
createdPaymentId: z.string().nullable(),
|
|
389
|
+
newlyAppliedAmountCents: z.number().int(),
|
|
390
|
+
syncError: z.string().nullable(),
|
|
391
|
+
});
|
|
392
|
+
export const polledInvoiceSettlementResultSchema = z.object({
|
|
393
|
+
invoiceId: z.string(),
|
|
394
|
+
invoiceStatus: invoiceStatusSchema,
|
|
395
|
+
paidCents: z.number().int(),
|
|
396
|
+
balanceDueCents: z.number().int(),
|
|
397
|
+
results: z.array(polledInvoiceSettlementProviderResultSchema),
|
|
398
|
+
});
|
|
399
|
+
export const renderInvoiceInputSchema = z.object({
|
|
400
|
+
templateId: z.string().optional().nullable(),
|
|
401
|
+
format: invoiceRenditionFormatSchema.default("pdf"),
|
|
402
|
+
language: z.string().optional().nullable(),
|
|
403
|
+
wait: invoiceDocumentWaitModeSchema.optional(),
|
|
404
|
+
waitTimeoutMs: z.coerce.number().int().min(0).max(60_000).optional(),
|
|
405
|
+
});
|
|
406
|
+
export const generateInvoiceDocumentInputSchema = renderInvoiceInputSchema.extend({
|
|
407
|
+
replaceExisting: z.boolean().default(true),
|
|
408
|
+
publicDelivery: z.boolean().default(false),
|
|
409
|
+
publicDeliveryTtlSeconds: z
|
|
410
|
+
.number()
|
|
411
|
+
.int()
|
|
412
|
+
.min(1)
|
|
413
|
+
.max(30 * 24 * 60 * 60)
|
|
414
|
+
.optional(),
|
|
415
|
+
});
|
|
416
|
+
export const invoiceDocumentWaitQuerySchema = invoiceDocumentWaitFieldsSchema;
|
|
417
|
+
export const generatedInvoiceDocumentResultSchema = z.object({
|
|
418
|
+
invoiceId: z.string(),
|
|
419
|
+
renderedBodyFormat: invoiceTemplateBodyFormatSchema,
|
|
420
|
+
renderedBody: z.string(),
|
|
421
|
+
rendition: z.object({
|
|
422
|
+
id: z.string(),
|
|
423
|
+
invoiceId: z.string(),
|
|
424
|
+
templateId: z.string().nullable(),
|
|
425
|
+
format: invoiceRenditionFormatSchema,
|
|
426
|
+
status: invoiceRenditionStatusSchema,
|
|
427
|
+
storageKey: z.string().nullable(),
|
|
428
|
+
fileSize: z.number().int().nullable(),
|
|
429
|
+
checksum: z.string().nullable(),
|
|
430
|
+
language: z.string().nullable(),
|
|
431
|
+
errorMessage: z.string().nullable(),
|
|
432
|
+
generatedAt: z.string().nullable(),
|
|
433
|
+
metadata: z.record(z.string(), z.unknown()).nullable(),
|
|
434
|
+
createdAt: z.string(),
|
|
435
|
+
}),
|
|
436
|
+
});
|