@hisaabo/cli 0.8.6 → 0.10.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 +154 -4
- package/dist/bin/{audit-trail-IJ6SKACR.js → audit-trail-RTPTWZAL.js} +12 -15
- package/dist/bin/{categories-O6TODPAH.js → categories-JJDTOT5T.js} +3 -3
- package/dist/bin/{check-slug-P7RFU6OP.js → check-slug-5L2VDAEN.js} +16 -4
- package/dist/bin/chunk-2DDIXPNI.js +1512 -0
- package/dist/bin/chunk-ALOHN6GR.js +78 -0
- package/dist/bin/{chunk-QUITS2FE.js → chunk-ESX7V56A.js} +95 -20
- package/dist/bin/chunk-M7DVLVD5.js +245 -0
- package/dist/bin/{chunk-WDN7RIE3.js → chunk-VXEEFNIY.js} +133 -47
- package/dist/bin/client-NFYNYEDI.js +17 -0
- package/dist/bin/{collection-efficiency-DA5RWG3V.js → collection-efficiency-UF3AJPQB.js} +12 -56
- package/dist/bin/{config-4LLNT4SH.js → config-7HVBRHL3.js} +2 -2
- package/dist/bin/{create-C5INBPQO.js → create-2BZQLXQA.js} +18 -9
- package/dist/bin/{default-account-2GMQ7ZA4.js → default-account-MR6O5LPT.js} +7 -13
- package/dist/bin/{expenses-S2YVA5UT.js → expenses-CU6JGDVX.js} +12 -11
- package/dist/bin/{export-YOOODNVX.js → export-GFYQIQLT.js} +9 -24
- package/dist/bin/{export-ZA43MLWO.js → export-WS24LYNH.js} +47 -14
- package/dist/bin/{factory-6MUCSXTL.js → factory-JSEQCPY3.js} +51 -57
- package/dist/bin/{get-GMQRROK2.js → get-HGMB7T6Y.js} +5 -4
- package/dist/bin/{get-ZV3SC2VY.js → get-KAOGGRJR.js} +4 -4
- package/dist/bin/hisaabo.js +2024 -837
- package/dist/bin/{import-UUHMLCKX.js → import-6CEMNCTM.js} +30 -33
- package/dist/bin/{invitations-OVORTTMF.js → invitations-LASABD2X.js} +11 -14
- package/dist/bin/{invite-GGHBZY4U.js → invite-VCBXS7VY.js} +13 -15
- package/dist/bin/{invoice-breakdown-32XXAZDP.js → invoice-breakdown-3XXSYA77.js} +12 -37
- package/dist/bin/{items-6NOIMH6B.js → items-PJPN6ZX3.js} +11 -10
- package/dist/bin/{items-toggle-L6W6QKQD.js → items-toggle-53C35MJU.js} +6 -5
- package/dist/bin/{list-RAR56EMQ.js → list-63EKE6DT.js} +13 -16
- package/dist/bin/{list-OXAVDXH7.js → list-7OSZX6C7.js} +5 -5
- package/dist/bin/{list-FC5JHKHD.js → list-OOROCQR2.js} +11 -12
- package/dist/bin/{members-Y6XJVHHR.js → members-SPHU5F4M.js} +7 -7
- package/dist/bin/monthly-comparison-3FFJT63K.js +79 -0
- package/dist/bin/{order-cancel-QRTCNART.js → order-cancel-RW4NYHKN.js} +8 -18
- package/dist/bin/{order-confirm-LGQOMC4O.js → order-confirm-NXFL2EIQ.js} +7 -15
- package/dist/bin/{order-get-4XAQCRYV.js → order-get-QPSOY2RT.js} +11 -11
- package/dist/bin/{order-update-KZY4H2UR.js → order-update-7DWKEROO.js} +4 -4
- package/dist/bin/{output-NUOL7KJW.js → output-XFDIL3A6.js} +5 -1
- package/dist/bin/{payment-modes-DY2ZEMK7.js → payment-modes-Z5WV3E3O.js} +12 -27
- package/dist/bin/{profit-loss-5GJBG3PL.js → profit-loss-AOISAJ56.js} +14 -13
- package/dist/bin/{receivables-aging-6A7XJKDT.js → receivables-aging-5JHFECGB.js} +13 -66
- package/dist/bin/{remove-ZBX34TIQ.js → remove-TC4UWMOL.js} +7 -15
- package/dist/bin/{revoke-ZTAMW2Q2.js → revoke-QHLNPGI5.js} +7 -3
- package/dist/bin/{revoke-XDNOA2GJ.js → revoke-SXVNALYQ.js} +7 -15
- package/dist/bin/{revoke-all-365NRBOA.js → revoke-all-CYW6A5UE.js} +8 -4
- package/dist/bin/{revoke-invitation-PQH7XNYA.js → revoke-invitation-Z33EUJTS.js} +7 -3
- package/dist/bin/safety-TPD2P7I5.js +18 -0
- package/dist/bin/{sales-trend-D6PQ7MHY.js → sales-trend-WCW6X5BI.js} +16 -16
- package/dist/bin/sequence-HOQ4PQRK.js +56 -0
- package/dist/bin/{store-SVRZBUFO.js → store-DDMHTNTO.js} +15 -8
- package/dist/bin/{summary-H6U7O5GJ.js → summary-TYAL2D3Q.js} +7 -5
- package/dist/bin/{top-customers-ATBN6RDI.js → top-customers-GMIS6GC3.js} +13 -11
- package/dist/bin/{top-items-XXU6KYTC.js → top-items-BK54JO3G.js} +16 -14
- package/dist/bin/{top-outstanding-JTQNGGW4.js → top-outstanding-L4NRJ6NE.js} +9 -11
- package/dist/bin/{unpaid-invoices-BTNQFWCH.js → unpaid-invoices-CEUFEYH7.js} +8 -8
- package/dist/bin/{untracked-PAMEDJ6Y.js → untracked-T6DIDMDQ.js} +9 -9
- package/dist/bin/{update-EK4NJWU4.js → update-EPNB2U74.js} +4 -4
- package/dist/bin/{update-EGHPFXLK.js → update-I2DZRVLR.js} +10 -17
- package/dist/bin/{update-6ZMX2OYX.js → update-MFNOVS6D.js} +4 -4
- package/dist/bin/{update-role-24PDTNFK.js → update-role-D2ETEL2Q.js} +7 -4
- package/dist/bin/{update-settings-AASI6WZX.js → update-settings-UGXLQRYI.js} +15 -9
- package/package.json +8 -7
- package/dist/bin/chunk-NO4FIFMS.js +0 -176
- package/dist/bin/chunk-ZPYC767N.js +0 -157
- package/dist/bin/client-36JX5MR3.js +0 -11
- package/dist/bin/monthly-comparison-IAUZ6SBJ.js +0 -176
- package/dist/bin/sequence-KZWADVD7.js +0 -66
|
@@ -0,0 +1,1512 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/output.ts
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
|
|
6
|
+
// ../shared/src/validators.ts
|
|
7
|
+
import { z as z2 } from "zod";
|
|
8
|
+
|
|
9
|
+
// ../shared/src/zod-messages.ts
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
function receivedType(input) {
|
|
12
|
+
switch (typeof input) {
|
|
13
|
+
case "number":
|
|
14
|
+
return Number.isNaN(input) ? "nan" : "number";
|
|
15
|
+
case "object":
|
|
16
|
+
if (input === null) return "null";
|
|
17
|
+
if (Array.isArray(input)) return "array";
|
|
18
|
+
if (input instanceof Date) return "date";
|
|
19
|
+
if (input instanceof Map) return "map";
|
|
20
|
+
if (input instanceof Set) return "set";
|
|
21
|
+
if (input instanceof Promise) return "promise";
|
|
22
|
+
return "object";
|
|
23
|
+
default:
|
|
24
|
+
return typeof input;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
var quoted = (v) => typeof v === "string" ? `'${v}'` : String(v);
|
|
28
|
+
function zod3Message(issue) {
|
|
29
|
+
switch (issue.code) {
|
|
30
|
+
case "invalid_type": {
|
|
31
|
+
if (issue.input === void 0) return "Required";
|
|
32
|
+
if (issue.expected === "int" && typeof issue.input === "number") {
|
|
33
|
+
return "Expected integer, received float";
|
|
34
|
+
}
|
|
35
|
+
const expected = issue.expected === "int" ? "integer" : issue.expected;
|
|
36
|
+
return `Expected ${expected}, received ${receivedType(issue.input)}`;
|
|
37
|
+
}
|
|
38
|
+
case "too_small": {
|
|
39
|
+
const { minimum, inclusive, exact } = issue;
|
|
40
|
+
switch (issue.origin) {
|
|
41
|
+
case "array":
|
|
42
|
+
case "set":
|
|
43
|
+
return `Array must contain ${exact ? "exactly" : inclusive ? "at least" : "more than"} ${minimum} element(s)`;
|
|
44
|
+
case "string":
|
|
45
|
+
return `String must contain ${exact ? "exactly" : inclusive ? "at least" : "over"} ${minimum} character(s)`;
|
|
46
|
+
case "number":
|
|
47
|
+
case "int":
|
|
48
|
+
case "bigint":
|
|
49
|
+
return `Number must be ${exact ? "exactly equal to " : inclusive ? "greater than or equal to " : "greater than "}${minimum}`;
|
|
50
|
+
case "date":
|
|
51
|
+
return `Date must be ${exact ? "exactly equal to " : inclusive ? "greater than or equal to " : "greater than "}${new Date(Number(minimum))}`;
|
|
52
|
+
default:
|
|
53
|
+
return "Invalid input";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
case "too_big": {
|
|
57
|
+
const { maximum, inclusive, exact } = issue;
|
|
58
|
+
switch (issue.origin) {
|
|
59
|
+
case "array":
|
|
60
|
+
case "set":
|
|
61
|
+
return `Array must contain ${exact ? "exactly" : inclusive ? "at most" : "less than"} ${maximum} element(s)`;
|
|
62
|
+
case "string":
|
|
63
|
+
return `String must contain ${exact ? "exactly" : inclusive ? "at most" : "under"} ${maximum} character(s)`;
|
|
64
|
+
case "number":
|
|
65
|
+
case "int":
|
|
66
|
+
return `Number must be ${exact ? "exactly" : inclusive ? "less than or equal to" : "less than"} ${maximum}`;
|
|
67
|
+
case "bigint":
|
|
68
|
+
return `BigInt must be ${exact ? "exactly" : inclusive ? "less than or equal to" : "less than"} ${maximum}`;
|
|
69
|
+
case "date":
|
|
70
|
+
return `Date must be ${exact ? "exactly" : inclusive ? "smaller than or equal to" : "smaller than"} ${new Date(Number(maximum))}`;
|
|
71
|
+
default:
|
|
72
|
+
return "Invalid input";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
case "invalid_format":
|
|
76
|
+
switch (issue.format) {
|
|
77
|
+
case "regex":
|
|
78
|
+
return "Invalid";
|
|
79
|
+
case "starts_with":
|
|
80
|
+
return `Invalid input: must start with "${issue.prefix}"`;
|
|
81
|
+
case "ends_with":
|
|
82
|
+
return `Invalid input: must end with "${issue.suffix}"`;
|
|
83
|
+
case "includes":
|
|
84
|
+
return `Invalid input: must include "${issue.includes}"`;
|
|
85
|
+
case "guid":
|
|
86
|
+
return "Invalid uuid";
|
|
87
|
+
default:
|
|
88
|
+
return `Invalid ${issue.format}`;
|
|
89
|
+
}
|
|
90
|
+
case "not_multiple_of":
|
|
91
|
+
return `Number must be a multiple of ${issue.divisor}`;
|
|
92
|
+
case "unrecognized_keys":
|
|
93
|
+
return `Unrecognized key(s) in object: ${issue.keys.map((k) => `'${k}'`).join(", ")}`;
|
|
94
|
+
case "invalid_value": {
|
|
95
|
+
if (issue.inst?._zod.def?.type === "literal" && issue.values.length === 1) {
|
|
96
|
+
return `Invalid literal value, expected ${JSON.stringify(issue.values[0])}`;
|
|
97
|
+
}
|
|
98
|
+
return `Invalid enum value. Expected ${issue.values.map(quoted).join(" | ")}, received '${String(issue.input)}'`;
|
|
99
|
+
}
|
|
100
|
+
case "invalid_union":
|
|
101
|
+
return "discriminator" in issue ? void 0 : "Invalid input";
|
|
102
|
+
case "invalid_key":
|
|
103
|
+
case "invalid_element":
|
|
104
|
+
case "custom":
|
|
105
|
+
return "Invalid input";
|
|
106
|
+
default:
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
z.config({ customError: zod3Message });
|
|
111
|
+
|
|
112
|
+
// ../shared/src/money.ts
|
|
113
|
+
var SCALE = 100;
|
|
114
|
+
function toPaise(value) {
|
|
115
|
+
const num = typeof value === "string" ? parseFloat(value) : value;
|
|
116
|
+
if (isNaN(num)) return 0;
|
|
117
|
+
return Math.round(num * SCALE);
|
|
118
|
+
}
|
|
119
|
+
function fromPaise(paise) {
|
|
120
|
+
const sign = paise < 0 ? "-" : "";
|
|
121
|
+
const abs = Math.abs(paise);
|
|
122
|
+
const rupees = Math.floor(abs / SCALE);
|
|
123
|
+
const paisePart = abs % SCALE;
|
|
124
|
+
return `${sign}${rupees}.${String(paisePart).padStart(2, "0")}`;
|
|
125
|
+
}
|
|
126
|
+
var money = {
|
|
127
|
+
/** Add two money values */
|
|
128
|
+
add(a, b) {
|
|
129
|
+
return fromPaise(toPaise(a) + toPaise(b));
|
|
130
|
+
},
|
|
131
|
+
/** Subtract b from a */
|
|
132
|
+
sub(a, b) {
|
|
133
|
+
return fromPaise(toPaise(a) - toPaise(b));
|
|
134
|
+
},
|
|
135
|
+
/** Multiply a money value by a factor (e.g., quantity) */
|
|
136
|
+
mul(amount, factor) {
|
|
137
|
+
const a = toPaise(amount);
|
|
138
|
+
const f = typeof factor === "string" ? parseFloat(factor) : factor;
|
|
139
|
+
return fromPaise(Math.round(a * f));
|
|
140
|
+
},
|
|
141
|
+
/** Calculate percentage of a value: amount * (percent / 100) */
|
|
142
|
+
percent(amount, pct) {
|
|
143
|
+
const a = toPaise(amount);
|
|
144
|
+
const p2 = typeof pct === "string" ? parseFloat(pct) : pct;
|
|
145
|
+
return fromPaise(Math.round(a * p2 / 100));
|
|
146
|
+
},
|
|
147
|
+
/** Sum an array of money values */
|
|
148
|
+
sum(values) {
|
|
149
|
+
const total = values.reduce((acc, v) => acc + toPaise(v), 0);
|
|
150
|
+
return fromPaise(total);
|
|
151
|
+
},
|
|
152
|
+
/** Compare: returns -1, 0, or 1 */
|
|
153
|
+
compare(a, b) {
|
|
154
|
+
const diff = toPaise(a) - toPaise(b);
|
|
155
|
+
return diff < 0 ? -1 : diff > 0 ? 1 : 0;
|
|
156
|
+
},
|
|
157
|
+
/** Check if value is zero */
|
|
158
|
+
isZero(value) {
|
|
159
|
+
return toPaise(value) === 0;
|
|
160
|
+
},
|
|
161
|
+
/** Check if value is positive */
|
|
162
|
+
isPositive(value) {
|
|
163
|
+
return toPaise(value) > 0;
|
|
164
|
+
},
|
|
165
|
+
/** Max of 0 and value */
|
|
166
|
+
max0(value) {
|
|
167
|
+
return fromPaise(Math.max(0, toPaise(value)));
|
|
168
|
+
},
|
|
169
|
+
/** Parse to number (for display only — not for further calculation) */
|
|
170
|
+
toNumber(value) {
|
|
171
|
+
return toPaise(value) / SCALE;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
// ../shared/src/calc.ts
|
|
176
|
+
function calcLineItem(item) {
|
|
177
|
+
if (item.taxInclusive) {
|
|
178
|
+
const grossPerUnit = money.toNumber(item.unitPrice);
|
|
179
|
+
const taxRate = money.toNumber(item.taxPercent);
|
|
180
|
+
const basePerUnit = grossPerUnit / (1 + taxRate / 100);
|
|
181
|
+
const basePrice = basePerUnit.toFixed(2);
|
|
182
|
+
const subtotal2 = money.mul(basePrice, item.quantity);
|
|
183
|
+
const discountAmount2 = money.percent(subtotal2, item.discountPercent);
|
|
184
|
+
const afterDiscount2 = money.sub(subtotal2, discountAmount2);
|
|
185
|
+
const taxAmount2 = money.percent(afterDiscount2, item.taxPercent);
|
|
186
|
+
const total2 = money.add(afterDiscount2, taxAmount2);
|
|
187
|
+
return { subtotal: subtotal2, discountAmount: discountAmount2, afterDiscount: afterDiscount2, taxAmount: taxAmount2, total: total2 };
|
|
188
|
+
}
|
|
189
|
+
const subtotal = money.mul(item.unitPrice, item.quantity);
|
|
190
|
+
const discountAmount = money.percent(subtotal, item.discountPercent);
|
|
191
|
+
const afterDiscount = money.sub(subtotal, discountAmount);
|
|
192
|
+
const taxAmount = money.percent(afterDiscount, item.taxPercent);
|
|
193
|
+
const total = money.add(afterDiscount, taxAmount);
|
|
194
|
+
return { subtotal, discountAmount, afterDiscount, taxAmount, total };
|
|
195
|
+
}
|
|
196
|
+
function calcInvoiceTotals(input) {
|
|
197
|
+
const results = input.lineItems.map((li) => calcLineItem(li));
|
|
198
|
+
const subtotal = money.sum(results.map((r) => r.afterDiscount));
|
|
199
|
+
const lineDiscountTotal = money.sum(results.map((r) => r.discountAmount));
|
|
200
|
+
const taxTotal = money.sum(results.map((r) => r.taxAmount));
|
|
201
|
+
const discountInput = input.invoiceDiscount || "0";
|
|
202
|
+
const discountType = input.invoiceDiscountType || "amount";
|
|
203
|
+
const invoiceDiscountAmount = discountType === "percent" ? money.percent(subtotal, discountInput) : discountInput;
|
|
204
|
+
const chargesTotal = input.charges ? money.sum(input.charges.map((c) => c.amount)) : "0.00";
|
|
205
|
+
const roundOff = input.roundOff || "0.00";
|
|
206
|
+
const total = money.add(
|
|
207
|
+
money.sub(money.add(subtotal, taxTotal), invoiceDiscountAmount),
|
|
208
|
+
money.add(chargesTotal, roundOff)
|
|
209
|
+
);
|
|
210
|
+
return { subtotal, lineDiscountTotal, invoiceDiscountAmount, taxTotal, chargesTotal, roundOff, total };
|
|
211
|
+
}
|
|
212
|
+
var MAX_ROUND_OFF = "1.00";
|
|
213
|
+
function isRoundOffWithinBound(roundOff) {
|
|
214
|
+
const value = roundOff ?? "0";
|
|
215
|
+
return money.compare(value, MAX_ROUND_OFF) <= 0 && money.compare(value, `-${MAX_ROUND_OFF}`) >= 0;
|
|
216
|
+
}
|
|
217
|
+
function validateInvoiceTotals(input, opts = {}) {
|
|
218
|
+
const discountInput = input.invoiceDiscount || "0";
|
|
219
|
+
const discountType = input.invoiceDiscountType || "amount";
|
|
220
|
+
if (money.compare(discountInput, 0) < 0) return "Invoice discount cannot be negative";
|
|
221
|
+
if (discountType === "percent" && money.compare(discountInput, 100) > 0) {
|
|
222
|
+
return "Invoice discount cannot exceed 100%";
|
|
223
|
+
}
|
|
224
|
+
if (!opts.skipRoundOffBound && !isRoundOffWithinBound(input.roundOff || "0")) {
|
|
225
|
+
return `Round off cannot exceed ${MAX_ROUND_OFF} in either direction`;
|
|
226
|
+
}
|
|
227
|
+
const totals = calcInvoiceTotals(input);
|
|
228
|
+
if (money.compare(totals.invoiceDiscountAmount, money.add(totals.subtotal, totals.taxTotal)) > 0) {
|
|
229
|
+
return "Invoice discount cannot exceed the invoice subtotal plus tax";
|
|
230
|
+
}
|
|
231
|
+
if (money.compare(totals.total, 0) < 0) return "Invoice total cannot be negative";
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// ../shared/src/validators.ts
|
|
236
|
+
function withoutDefault(schema) {
|
|
237
|
+
const def2 = schema._zod.def;
|
|
238
|
+
return (def2.type === "default" || def2.type === "optional") && def2.innerType ? withoutDefault(def2.innerType) : schema;
|
|
239
|
+
}
|
|
240
|
+
function partialWithoutDefaults(schema) {
|
|
241
|
+
const shape = {};
|
|
242
|
+
for (const [key, field] of Object.entries(schema.shape)) {
|
|
243
|
+
shape[key] = withoutDefault(field).optional();
|
|
244
|
+
}
|
|
245
|
+
return schema.extend(shape);
|
|
246
|
+
}
|
|
247
|
+
var paginationSchema = z2.object({
|
|
248
|
+
page: z2.number().int().min(1).default(1),
|
|
249
|
+
limit: z2.number().int().min(1).max(100).default(20)
|
|
250
|
+
});
|
|
251
|
+
var dateRangeSchema = z2.object({
|
|
252
|
+
from: z2.string().datetime().optional(),
|
|
253
|
+
to: z2.string().datetime().optional()
|
|
254
|
+
});
|
|
255
|
+
var searchSchema = z2.object({
|
|
256
|
+
query: z2.string().min(1).max(200)
|
|
257
|
+
});
|
|
258
|
+
var loginSchema = z2.object({
|
|
259
|
+
email: z2.string().trim().toLowerCase().email().max(255),
|
|
260
|
+
password: z2.string().min(8).max(128)
|
|
261
|
+
});
|
|
262
|
+
var registerSchema = z2.object({
|
|
263
|
+
email: z2.string().trim().toLowerCase().email().max(255),
|
|
264
|
+
name: z2.string().min(2).max(100),
|
|
265
|
+
password: z2.string().min(8).max(128),
|
|
266
|
+
confirmPassword: z2.string(),
|
|
267
|
+
turnstileToken: z2.string().optional()
|
|
268
|
+
}).refine((d) => d.password === d.confirmPassword, {
|
|
269
|
+
message: "Passwords don't match",
|
|
270
|
+
path: ["confirmPassword"]
|
|
271
|
+
});
|
|
272
|
+
var magicLinkRequestSchema = z2.object({
|
|
273
|
+
email: z2.string().trim().toLowerCase().email().max(255),
|
|
274
|
+
turnstileToken: z2.string().optional(),
|
|
275
|
+
source: z2.enum(["web", "desktop", "mobile"]).default("web")
|
|
276
|
+
});
|
|
277
|
+
var magicLinkVerifySchema = z2.object({
|
|
278
|
+
token: z2.string().min(1).max(128)
|
|
279
|
+
});
|
|
280
|
+
var nativeAuthClientSchema = z2.enum(["desktop", "mobile", "cli"]);
|
|
281
|
+
var nativeStartSchema = z2.object({
|
|
282
|
+
client: nativeAuthClientSchema,
|
|
283
|
+
redirectUri: z2.string().max(512),
|
|
284
|
+
codeChallenge: z2.string().regex(/^[A-Za-z0-9_-]{43}$/),
|
|
285
|
+
codeChallengeMethod: z2.literal("S256"),
|
|
286
|
+
state: z2.string().regex(/^[A-Za-z0-9_-]{16,128}$/)
|
|
287
|
+
});
|
|
288
|
+
var nativeExchangeSchema = z2.object({
|
|
289
|
+
requestId: z2.string().uuid(),
|
|
290
|
+
code: z2.string().min(1).max(128),
|
|
291
|
+
codeVerifier: z2.string().regex(/^[A-Za-z0-9\-._~]{43,128}$/)
|
|
292
|
+
});
|
|
293
|
+
var completeProfileSchema = z2.object({
|
|
294
|
+
name: z2.string().min(2).max(100)
|
|
295
|
+
});
|
|
296
|
+
var gstRegistrationTypes = ["regular", "composition", "unregistered"];
|
|
297
|
+
var createBusinessSchema = z2.object({
|
|
298
|
+
name: z2.string().min(1).max(200),
|
|
299
|
+
legalName: z2.string().max(200).optional(),
|
|
300
|
+
gstRegistrationType: z2.enum(gstRegistrationTypes).default("unregistered"),
|
|
301
|
+
gstin: z2.string().regex(/^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$/).optional().or(z2.literal("")),
|
|
302
|
+
pan: z2.string().regex(/^[A-Z]{5}[0-9]{4}[A-Z]{1}$/),
|
|
303
|
+
phone: z2.string().min(1).max(15),
|
|
304
|
+
email: z2.string().trim().toLowerCase().email().optional().or(z2.literal("")),
|
|
305
|
+
address: z2.string().min(1).max(500),
|
|
306
|
+
city: z2.string().max(100).optional(),
|
|
307
|
+
state: z2.string().max(100).optional(),
|
|
308
|
+
stateCode: z2.string().max(2).optional(),
|
|
309
|
+
pincode: z2.string().max(10).optional(),
|
|
310
|
+
invoicePrefix: z2.string().min(1).max(10).regex(/^[A-Za-z0-9_-]+$/, "Prefix may only contain letters, numbers, hyphen and underscore").default("INV"),
|
|
311
|
+
currency: z2.string().length(3).default("INR"),
|
|
312
|
+
paymentPrefix: z2.string().min(1).max(10).default("PAY"),
|
|
313
|
+
quotationPrefix: z2.string().min(1).max(10).default("QTN"),
|
|
314
|
+
creditNotePrefix: z2.string().min(1).max(10).default("CN"),
|
|
315
|
+
deliveryChallanPrefix: z2.string().min(1).max(10).default("DC"),
|
|
316
|
+
proformaPrefix: z2.string().min(1).max(10).default("PI"),
|
|
317
|
+
// Document defaults — applied to new documents but always overridable per-doc.
|
|
318
|
+
defaultRoundOff: z2.boolean().default(true),
|
|
319
|
+
defaultTermsAndConditions: z2.string().max(2e3).nullable().optional()
|
|
320
|
+
});
|
|
321
|
+
var updateBusinessSchema = partialWithoutDefaults(createBusinessSchema);
|
|
322
|
+
var uploadBusinessLogoSchema = z2.object({
|
|
323
|
+
dataUrl: z2.string().regex(/^data:image\/(png|jpeg);base64,[A-Za-z0-9+/=]+$/, "must be a base64 data URL for PNG or JPEG").max(15e5, "logo too large (max ~1MB)"),
|
|
324
|
+
width: z2.number().int().positive().max(4e3),
|
|
325
|
+
height: z2.number().int().positive().max(4e3)
|
|
326
|
+
});
|
|
327
|
+
var updateSequenceNumberSchema = z2.object({
|
|
328
|
+
documentType: z2.enum(["invoice", "payment", "quotation", "credit_note", "delivery_challan", "proforma"]),
|
|
329
|
+
newNumber: z2.number().int().min(1)
|
|
330
|
+
});
|
|
331
|
+
var itemTypes = ["product", "service"];
|
|
332
|
+
var documentTypes = ["invoice", "quotation", "credit_note", "debit_note", "delivery_challan", "proforma", "sales_return", "purchase_return"];
|
|
333
|
+
var bankAccountTypes = ["savings", "current", "cash", "upi", "credit_card", "payment_gateway"];
|
|
334
|
+
var bankTransactionTypes = ["deposit", "withdrawal", "transfer"];
|
|
335
|
+
var partyTypes = ["customer", "supplier"];
|
|
336
|
+
var tanSchema = z2.preprocess(
|
|
337
|
+
(value) => {
|
|
338
|
+
if (typeof value !== "string") return value;
|
|
339
|
+
const normalized = value.trim().toUpperCase();
|
|
340
|
+
return normalized === "" ? null : normalized;
|
|
341
|
+
},
|
|
342
|
+
z2.string().regex(/^[A-Z]{4}[0-9]{5}[A-Z]$/, "Invalid TAN").nullable().optional()
|
|
343
|
+
);
|
|
344
|
+
var createPartySchema = z2.object({
|
|
345
|
+
type: z2.enum(partyTypes),
|
|
346
|
+
name: z2.string().min(1).max(200),
|
|
347
|
+
phone: z2.string().max(15).optional(),
|
|
348
|
+
email: z2.string().trim().toLowerCase().email().optional().or(z2.literal("")),
|
|
349
|
+
gstin: z2.string().regex(/^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$/).optional().or(z2.literal("")),
|
|
350
|
+
pan: z2.string().optional().or(z2.literal("")),
|
|
351
|
+
tan: tanSchema,
|
|
352
|
+
billingAddress: z2.string().max(500).optional(),
|
|
353
|
+
shippingAddress: z2.string().max(500).optional(),
|
|
354
|
+
city: z2.string().max(100).optional(),
|
|
355
|
+
state: z2.string().max(100).optional(),
|
|
356
|
+
stateCode: z2.string().max(2).optional(),
|
|
357
|
+
pincode: z2.string().max(10).optional(),
|
|
358
|
+
openingBalance: z2.string().regex(/^-?\d{1,13}(\.\d{1,2})?$/).default("0"),
|
|
359
|
+
category: z2.string().max(100).optional(),
|
|
360
|
+
creditPeriodDays: z2.number().int().min(0).max(365).optional(),
|
|
361
|
+
creditLimit: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).optional(),
|
|
362
|
+
contactPersonName: z2.string().max(200).optional(),
|
|
363
|
+
contactPersonDob: z2.string().datetime().optional(),
|
|
364
|
+
bankAccountNumber: z2.string().max(34).optional(),
|
|
365
|
+
bankIfsc: z2.string().max(11).optional(),
|
|
366
|
+
bankName: z2.string().max(200).optional()
|
|
367
|
+
});
|
|
368
|
+
var updatePartySchema = partialWithoutDefaults(createPartySchema).omit({ type: true });
|
|
369
|
+
var units = ["pcs", "kg", "g", "l", "ml", "m", "cm", "ft", "in", "box", "dozen", "pair", "set", "pkt", "bun", "pouch", "jar", "btl", "bag", "ton", "pack", "pet", "person", "other"];
|
|
370
|
+
var itemModes = ["simple", "alt_units", "variants"];
|
|
371
|
+
var unitVariantSchema = z2.object({
|
|
372
|
+
unit: z2.string().min(1).max(50),
|
|
373
|
+
conversionFactor: z2.number().positive(),
|
|
374
|
+
salePrice: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/),
|
|
375
|
+
purchasePrice: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).optional()
|
|
376
|
+
});
|
|
377
|
+
var decimalStr = z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/);
|
|
378
|
+
var decimalStr3 = z2.string().regex(/^-?\d+(\.\d{1,3})?$/);
|
|
379
|
+
var itemVariantSchema = z2.object({
|
|
380
|
+
attributeValues: z2.record(z2.string().min(1), z2.string().min(1)),
|
|
381
|
+
sku: z2.string().max(50).optional(),
|
|
382
|
+
salePrice: decimalStr.optional(),
|
|
383
|
+
purchasePrice: decimalStr.optional(),
|
|
384
|
+
stockQuantity: decimalStr3.default("0"),
|
|
385
|
+
lowStockAlert: z2.string().regex(/^\d+(\.\d{1,3})?$/).optional()
|
|
386
|
+
});
|
|
387
|
+
var createItemBaseSchema = z2.object({
|
|
388
|
+
name: z2.string().min(1).max(200),
|
|
389
|
+
hsn: z2.string().max(20).optional(),
|
|
390
|
+
sku: z2.string().max(50).optional(),
|
|
391
|
+
unit: z2.enum(units).default("pcs"),
|
|
392
|
+
itemMode: z2.enum(itemModes).default("simple"),
|
|
393
|
+
salePrice: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).optional(),
|
|
394
|
+
purchasePrice: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).optional(),
|
|
395
|
+
taxPercent: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).default("0"),
|
|
396
|
+
stockQuantity: z2.string().regex(/^-?\d+(\.\d{1,3})?$/).default("0"),
|
|
397
|
+
lowStockAlert: z2.string().regex(/^\d+(\.\d{1,3})?$/).optional(),
|
|
398
|
+
description: z2.string().max(1e3).optional(),
|
|
399
|
+
itemType: z2.enum(itemTypes).default("product"),
|
|
400
|
+
category: z2.string().max(100).optional(),
|
|
401
|
+
taxInclusive: z2.boolean().default(false),
|
|
402
|
+
unitVariants: z2.array(unitVariantSchema).optional(),
|
|
403
|
+
variantAttributes: z2.array(z2.string().min(1).max(50)).max(5).optional(),
|
|
404
|
+
variants: z2.array(itemVariantSchema).optional()
|
|
405
|
+
});
|
|
406
|
+
var createItemSchema = createItemBaseSchema.refine((d) => {
|
|
407
|
+
if (d.itemMode === "variants" && d.unitVariants && d.unitVariants.length > 0) return false;
|
|
408
|
+
if (d.itemMode === "alt_units" && d.variantAttributes && d.variantAttributes.length > 0) return false;
|
|
409
|
+
if (d.itemMode === "alt_units" && d.variants && d.variants.length > 0) return false;
|
|
410
|
+
return true;
|
|
411
|
+
}, { message: "An item cannot have both unit variants and product variants" });
|
|
412
|
+
var updateItemSchema = partialWithoutDefaults(createItemBaseSchema);
|
|
413
|
+
var MAX_IMAGES_PER_ITEM = 12;
|
|
414
|
+
var uploadItemImageSchema = z2.object({
|
|
415
|
+
itemId: z2.string().uuid(),
|
|
416
|
+
// Optional per-image variant tag. null/omitted = shared across variants.
|
|
417
|
+
variantId: z2.string().uuid().nullish(),
|
|
418
|
+
dataUrl: z2.string().regex(
|
|
419
|
+
/^data:image\/(png|jpeg|webp);base64,[A-Za-z0-9+/=]+$/,
|
|
420
|
+
"must be a base64 data URL for PNG, JPEG, or WebP"
|
|
421
|
+
).max(42e5, "image too large (max ~3MB)"),
|
|
422
|
+
width: z2.number().int().positive().max(8e3).optional(),
|
|
423
|
+
height: z2.number().int().positive().max(8e3).optional(),
|
|
424
|
+
alt: z2.string().max(300).optional()
|
|
425
|
+
});
|
|
426
|
+
var updateItemImageSchema = z2.object({
|
|
427
|
+
imageId: z2.string().uuid(),
|
|
428
|
+
// `variantId: null` explicitly clears the tag (makes the image shared);
|
|
429
|
+
// omitting it leaves the tag unchanged.
|
|
430
|
+
variantId: z2.string().uuid().nullish(),
|
|
431
|
+
alt: z2.string().max(300).nullish()
|
|
432
|
+
});
|
|
433
|
+
var reorderItemImagesSchema = z2.object({
|
|
434
|
+
itemId: z2.string().uuid(),
|
|
435
|
+
// Full ordered list of this item's image ids; index becomes sortOrder.
|
|
436
|
+
orderedImageIds: z2.array(z2.string().uuid()).min(1).max(MAX_IMAGES_PER_ITEM)
|
|
437
|
+
});
|
|
438
|
+
var setPrimaryItemImageSchema = z2.object({
|
|
439
|
+
imageId: z2.string().uuid()
|
|
440
|
+
});
|
|
441
|
+
var invoiceTypes = ["sale", "purchase"];
|
|
442
|
+
var invoiceStatuses = ["draft", "unfulfilled", "sent", "paid", "partial", "overdue", "cancelled", "adjusted"];
|
|
443
|
+
var deliveryMethods = ["self_pickup", "hand_delivery", "courier", "bus", "transport", "post"];
|
|
444
|
+
var invoiceChargeSchema = z2.object({
|
|
445
|
+
label: z2.string().min(1).max(100),
|
|
446
|
+
amount: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/),
|
|
447
|
+
shipmentId: z2.string().uuid().optional()
|
|
448
|
+
});
|
|
449
|
+
var invoiceLineItemSchema = z2.object({
|
|
450
|
+
itemId: z2.string().uuid().optional(),
|
|
451
|
+
// Snapshot of the item name at billing time. Required on every line — this
|
|
452
|
+
// is the primary display text on invoices and must be frozen at create
|
|
453
|
+
// time so future renames of the underlying item don't rewrite history.
|
|
454
|
+
itemName: z2.string().min(1).max(200),
|
|
455
|
+
// Optional free-text line notes (e.g. "Keep separate from order #42").
|
|
456
|
+
// Nullable because the DB column is nullable and the client may pass null
|
|
457
|
+
// explicitly to clear notes. Empty string is coerced to null downstream.
|
|
458
|
+
description: z2.string().max(500).optional().nullable(),
|
|
459
|
+
quantity: z2.string().regex(/^\d+(\.\d{1,3})?$/).refine((v) => parseFloat(v) > 0, { message: "Quantity must be greater than 0" }),
|
|
460
|
+
unitPrice: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/),
|
|
461
|
+
taxPercent: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).default("0").refine((v) => parseFloat(v) <= 56, { message: "Tax percent cannot exceed 56%" }),
|
|
462
|
+
discountPercent: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).default("0").refine((v) => parseFloat(v) <= 100, { message: "Discount cannot exceed 100%" }),
|
|
463
|
+
selectedUnit: z2.string().nullish(),
|
|
464
|
+
conversionFactor: z2.string().nullish(),
|
|
465
|
+
// stored as string like all numerics
|
|
466
|
+
variantId: z2.string().uuid().nullish()
|
|
467
|
+
});
|
|
468
|
+
var createInvoiceBaseSchema = z2.object({
|
|
469
|
+
partyId: z2.string().uuid(),
|
|
470
|
+
type: z2.enum(invoiceTypes),
|
|
471
|
+
documentType: z2.enum(documentTypes).default("invoice"),
|
|
472
|
+
invoiceDate: z2.string().datetime().optional(),
|
|
473
|
+
dueDate: z2.string().datetime().optional(),
|
|
474
|
+
notes: z2.string().max(2e3).optional(),
|
|
475
|
+
termsAndConditions: z2.string().max(2e3).optional(),
|
|
476
|
+
additionalCharges: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).default("0"),
|
|
477
|
+
charges: z2.array(invoiceChargeSchema).optional(),
|
|
478
|
+
invoiceDiscount: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).default("0"),
|
|
479
|
+
invoiceDiscountType: z2.enum(["amount", "percent"]).default("amount"),
|
|
480
|
+
roundOff: z2.string().regex(/^-?\d{1,13}(\.\d{1,2})?$/).default("0"),
|
|
481
|
+
referenceDocumentId: z2.string().uuid().optional(),
|
|
482
|
+
lineItems: z2.array(invoiceLineItemSchema).min(1),
|
|
483
|
+
/**
|
|
484
|
+
* When true, skip stock adjustment on create. Used when converting a
|
|
485
|
+
* delivery_challan → invoice to avoid double-decrementing stock (the
|
|
486
|
+
* challan already decremented it).
|
|
487
|
+
*/
|
|
488
|
+
skipStockAdjustment: z2.boolean().optional(),
|
|
489
|
+
isReverseCharge: z2.boolean().default(false),
|
|
490
|
+
deliveryMethod: z2.enum(deliveryMethods).default("self_pickup"),
|
|
491
|
+
/**
|
|
492
|
+
* Origin channel for this invoice. "pos" for the fullscreen register,
|
|
493
|
+
* "online_store" for storefront orders, "webhook" for public-API /
|
|
494
|
+
* carrier-webhook triggered invoices. Null/undefined = manually created
|
|
495
|
+
* from the invoice form. Used by reporting and the invoice list to
|
|
496
|
+
* attribute a sale to its channel.
|
|
497
|
+
*/
|
|
498
|
+
source: z2.enum(["pos", "online_store", "webhook"]).optional()
|
|
499
|
+
});
|
|
500
|
+
var createInvoiceSchema = createInvoiceBaseSchema.superRefine((d, ctx) => {
|
|
501
|
+
const message = validateInvoiceTotals({
|
|
502
|
+
lineItems: d.lineItems,
|
|
503
|
+
charges: d.charges,
|
|
504
|
+
invoiceDiscount: d.invoiceDiscount,
|
|
505
|
+
invoiceDiscountType: d.invoiceDiscountType,
|
|
506
|
+
roundOff: d.roundOff
|
|
507
|
+
});
|
|
508
|
+
if (message) ctx.addIssue({ code: "custom", message });
|
|
509
|
+
});
|
|
510
|
+
var updateInvoiceStatusSchema = z2.object({
|
|
511
|
+
status: z2.enum(invoiceStatuses)
|
|
512
|
+
});
|
|
513
|
+
var paymentModes = ["cash", "bank", "upi", "cheque", "other", "credit_card", "debit_card", "net_banking", "wallet"];
|
|
514
|
+
var moneyStringSchema = z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/);
|
|
515
|
+
var paymentAllocationSchema = z2.object({
|
|
516
|
+
invoiceId: z2.string().uuid(),
|
|
517
|
+
amount: moneyStringSchema.refine((v) => money.compare(v, "0") > 0, { message: "Amount must be greater than zero" }),
|
|
518
|
+
tdsAmount: moneyStringSchema.default("0").refine((v) => money.compare(v, "0") >= 0, { message: "TDS amount cannot be negative" }),
|
|
519
|
+
tdsSectionCode: z2.string().trim().min(1).max(20).optional(),
|
|
520
|
+
tdsRate: z2.string().regex(/^\d{1,3}(\.\d{1,2})?$/).refine((v) => money.compare(v, "0") >= 0 && money.compare(v, "100") <= 0, { message: "TDS rate must be between 0 and 100" }).optional()
|
|
521
|
+
}).superRefine((value, ctx) => {
|
|
522
|
+
const hasPositiveTds = money.compare(value.tdsAmount, "0") > 0;
|
|
523
|
+
if (hasPositiveTds) {
|
|
524
|
+
if (!value.tdsSectionCode || value.tdsSectionCode.trim() === "") {
|
|
525
|
+
ctx.addIssue({
|
|
526
|
+
code: "custom",
|
|
527
|
+
path: ["tdsSectionCode"],
|
|
528
|
+
message: "TDS section code is required when TDS amount is positive"
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
if (!value.tdsRate || money.compare(value.tdsRate, "0") <= 0) {
|
|
532
|
+
ctx.addIssue({
|
|
533
|
+
code: "custom",
|
|
534
|
+
path: ["tdsRate"],
|
|
535
|
+
message: "TDS rate must be greater than zero when TDS amount is positive"
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
if (money.compare(value.tdsAmount, value.amount) > 0) {
|
|
539
|
+
ctx.addIssue({
|
|
540
|
+
code: "custom",
|
|
541
|
+
path: ["tdsAmount"],
|
|
542
|
+
message: "TDS amount cannot exceed gross allocation"
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
} else {
|
|
546
|
+
if (value.tdsSectionCode || value.tdsRate !== void 0) {
|
|
547
|
+
ctx.addIssue({
|
|
548
|
+
code: "custom",
|
|
549
|
+
path: ["tdsSectionCode"],
|
|
550
|
+
message: "TDS section and rate must be omitted when TDS amount is zero"
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
var createPaymentSchema = z2.object({
|
|
556
|
+
invoiceId: z2.string().uuid().optional(),
|
|
557
|
+
partyId: z2.string().uuid(),
|
|
558
|
+
amount: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).refine((v) => money.compare(v, "0") > 0, { message: "Amount must be greater than zero" }),
|
|
559
|
+
discount: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).default("0"),
|
|
560
|
+
mode: z2.enum(paymentModes),
|
|
561
|
+
referenceNumber: z2.string().max(100).optional(),
|
|
562
|
+
paymentDate: z2.string().datetime().optional(),
|
|
563
|
+
notes: z2.string().max(500).optional(),
|
|
564
|
+
bankAccountId: z2.string().uuid().optional(),
|
|
565
|
+
// Multi-invoice allocation: allocate a single payment across multiple invoices
|
|
566
|
+
allocations: z2.array(paymentAllocationSchema).optional()
|
|
567
|
+
});
|
|
568
|
+
var tdsSectionConfigFields = {
|
|
569
|
+
sectionCode: z2.string().trim().min(1).max(20).transform((value) => value.toUpperCase()),
|
|
570
|
+
sectionLabel: z2.string().trim().min(1).max(200),
|
|
571
|
+
effectiveFrom: z2.string().datetime(),
|
|
572
|
+
effectiveTo: z2.string().datetime().optional().nullable(),
|
|
573
|
+
status: z2.enum(["active", "inactive"]).default("active"),
|
|
574
|
+
version: z2.number().int().positive().max(1e3).default(1)
|
|
575
|
+
};
|
|
576
|
+
var createTdsSectionConfigSchema = z2.object(tdsSectionConfigFields).refine(
|
|
577
|
+
(value) => !value.effectiveTo || value.effectiveTo >= value.effectiveFrom,
|
|
578
|
+
{ message: "effectiveTo must be on or after effectiveFrom", path: ["effectiveTo"] }
|
|
579
|
+
);
|
|
580
|
+
var updatePaymentSchema = z2.object({
|
|
581
|
+
id: z2.string().uuid(),
|
|
582
|
+
amount: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).refine((v) => money.compare(v, "0") > 0, { message: "Amount must be greater than zero" }).optional(),
|
|
583
|
+
discount: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).optional(),
|
|
584
|
+
mode: z2.enum(paymentModes).optional(),
|
|
585
|
+
referenceNumber: z2.string().max(100).optional().nullable(),
|
|
586
|
+
paymentDate: z2.string().datetime().optional(),
|
|
587
|
+
notes: z2.string().max(500).optional().nullable(),
|
|
588
|
+
bankAccountId: z2.string().uuid().optional().nullable(),
|
|
589
|
+
// Replace all allocations (reverse old, apply new). Omit the field to keep the
|
|
590
|
+
// existing allocations; an empty array clears them all.
|
|
591
|
+
allocations: z2.array(paymentAllocationSchema).optional()
|
|
592
|
+
});
|
|
593
|
+
var createExpenseSchema = z2.object({
|
|
594
|
+
category: z2.string().min(1).max(100),
|
|
595
|
+
description: z2.string().max(500).optional(),
|
|
596
|
+
amount: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).refine((v) => parseFloat(v) > 0, { message: "Amount must be greater than zero" }),
|
|
597
|
+
mode: z2.enum(paymentModes),
|
|
598
|
+
expenseDate: z2.string().datetime().optional(),
|
|
599
|
+
referenceNumber: z2.string().max(100).optional(),
|
|
600
|
+
bankAccountId: z2.string().uuid().optional()
|
|
601
|
+
});
|
|
602
|
+
var gatewayChargeRateSchema = z2.object({
|
|
603
|
+
type: z2.enum(["percentage", "flat"]),
|
|
604
|
+
value: z2.string().regex(/^\d+(\.\d{1,4})?$/)
|
|
605
|
+
});
|
|
606
|
+
var gatewayChargeConfigSchema = z2.object({
|
|
607
|
+
credit_card: gatewayChargeRateSchema.optional(),
|
|
608
|
+
debit_card: gatewayChargeRateSchema.optional(),
|
|
609
|
+
upi: gatewayChargeRateSchema.optional(),
|
|
610
|
+
net_banking: gatewayChargeRateSchema.optional(),
|
|
611
|
+
wallet: gatewayChargeRateSchema.optional(),
|
|
612
|
+
default: gatewayChargeRateSchema.optional()
|
|
613
|
+
});
|
|
614
|
+
var createPaymentGatewayConfigSchema = z2.object({
|
|
615
|
+
bankAccountId: z2.string().uuid(),
|
|
616
|
+
settlementAccountId: z2.string().uuid(),
|
|
617
|
+
chargeConfig: gatewayChargeConfigSchema,
|
|
618
|
+
expenseCategory: z2.string().min(1).max(100).default("Payment Gateway Charges"),
|
|
619
|
+
autoSettle: z2.boolean().default(true)
|
|
620
|
+
});
|
|
621
|
+
var updatePaymentGatewayConfigSchema = partialWithoutDefaults(createPaymentGatewayConfigSchema).omit({ bankAccountId: true });
|
|
622
|
+
var createBankAccountSchema = z2.object({
|
|
623
|
+
accountName: z2.string().min(1).max(200),
|
|
624
|
+
accountNumber: z2.string().max(34).optional(),
|
|
625
|
+
ifsc: z2.string().max(11).optional(),
|
|
626
|
+
bankName: z2.string().max(200).optional(),
|
|
627
|
+
accountType: z2.enum(bankAccountTypes).default("savings"),
|
|
628
|
+
openingBalance: z2.string().regex(/^-?\d{1,13}(\.\d{1,2})?$/).default("0"),
|
|
629
|
+
isDefault: z2.boolean().default(false)
|
|
630
|
+
});
|
|
631
|
+
var updateBankAccountSchema = partialWithoutDefaults(createBankAccountSchema);
|
|
632
|
+
var createBankTransactionSchema = z2.object({
|
|
633
|
+
bankAccountId: z2.string().uuid(),
|
|
634
|
+
type: z2.enum(bankTransactionTypes),
|
|
635
|
+
amount: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).refine((v) => parseFloat(v) > 0, { message: "Amount must be greater than zero" }),
|
|
636
|
+
description: z2.string().max(500).optional(),
|
|
637
|
+
referenceType: z2.string().max(50).optional(),
|
|
638
|
+
referenceId: z2.string().uuid().optional(),
|
|
639
|
+
transactionDate: z2.string().datetime().optional()
|
|
640
|
+
});
|
|
641
|
+
var bankTransferSchema = z2.object({
|
|
642
|
+
fromAccountId: z2.string().uuid(),
|
|
643
|
+
toAccountId: z2.string().uuid(),
|
|
644
|
+
amount: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).refine((v) => parseFloat(v) > 0, { message: "Amount must be greater than zero" }),
|
|
645
|
+
description: z2.string().max(500).optional(),
|
|
646
|
+
transactionDate: z2.string().datetime().optional()
|
|
647
|
+
});
|
|
648
|
+
var convertDocumentSchema = z2.object({
|
|
649
|
+
sourceDocumentId: z2.string().uuid(),
|
|
650
|
+
targetDocumentType: z2.enum(documentTypes)
|
|
651
|
+
});
|
|
652
|
+
var reportDateTimeBound = z2.string().datetime().optional();
|
|
653
|
+
var reportDateBound = z2.union([z2.string().date(), z2.string().datetime()]).optional();
|
|
654
|
+
var daybookInputSchema = z2.object({
|
|
655
|
+
// Accepts YYYY-MM-DD or a full ISO datetime. Omitted bounds mean "all time".
|
|
656
|
+
fromDate: reportDateBound,
|
|
657
|
+
toDate: reportDateBound,
|
|
658
|
+
typeFilter: z2.enum(["all", "invoices", "payments", "expenses"]).default("all")
|
|
659
|
+
});
|
|
660
|
+
var outstandingInputSchema = z2.object({
|
|
661
|
+
type: z2.enum(["receivable", "payable", "both"]).default("receivable"),
|
|
662
|
+
asOfDate: z2.string().datetime().optional()
|
|
663
|
+
});
|
|
664
|
+
var registerInputSchema = z2.object({
|
|
665
|
+
fromDate: reportDateTimeBound,
|
|
666
|
+
toDate: reportDateTimeBound,
|
|
667
|
+
partyId: z2.string().uuid().optional()
|
|
668
|
+
});
|
|
669
|
+
var taxSummaryInputSchema = z2.object({
|
|
670
|
+
fromDate: reportDateTimeBound,
|
|
671
|
+
toDate: reportDateTimeBound,
|
|
672
|
+
type: z2.enum(["sales", "purchases", "both"]).default("both")
|
|
673
|
+
});
|
|
674
|
+
var cashFlowForecastInputSchema = z2.object({
|
|
675
|
+
businessId: z2.string().uuid().optional()
|
|
676
|
+
});
|
|
677
|
+
var collectionEfficiencyInputSchema = z2.object({
|
|
678
|
+
fromDate: reportDateTimeBound,
|
|
679
|
+
toDate: reportDateTimeBound
|
|
680
|
+
});
|
|
681
|
+
var itemSalesInputSchema = z2.object({
|
|
682
|
+
fromDate: reportDateTimeBound,
|
|
683
|
+
toDate: reportDateTimeBound,
|
|
684
|
+
category: z2.string().optional(),
|
|
685
|
+
itemType: z2.enum(["product", "service"]).optional(),
|
|
686
|
+
sortBy: z2.enum(["revenue", "quantity", "invoices", "margin"]).default("revenue"),
|
|
687
|
+
compareToPrevious: z2.boolean().default(false)
|
|
688
|
+
});
|
|
689
|
+
var cashFlowStatementInputSchema = z2.object({
|
|
690
|
+
fromDate: reportDateTimeBound,
|
|
691
|
+
toDate: reportDateTimeBound
|
|
692
|
+
});
|
|
693
|
+
var stockSummaryInputSchema = z2.object({
|
|
694
|
+
category: z2.string().optional(),
|
|
695
|
+
showZeroStock: z2.boolean().default(false)
|
|
696
|
+
});
|
|
697
|
+
var partyStatementInputSchema = z2.object({
|
|
698
|
+
partyId: z2.string().uuid(),
|
|
699
|
+
fromDate: reportDateTimeBound,
|
|
700
|
+
toDate: reportDateTimeBound
|
|
701
|
+
});
|
|
702
|
+
var paymentSummaryInputSchema = z2.object({
|
|
703
|
+
fromDate: reportDateTimeBound,
|
|
704
|
+
toDate: reportDateTimeBound,
|
|
705
|
+
type: z2.enum(["received", "made", "both"]).default("both"),
|
|
706
|
+
bankAccountId: z2.string().uuid().optional()
|
|
707
|
+
});
|
|
708
|
+
var recurringFrequencies = ["weekly", "biweekly", "monthly", "quarterly", "half_yearly", "yearly", "custom"];
|
|
709
|
+
var recurringLineItemSchema = z2.object({
|
|
710
|
+
itemId: z2.string().uuid().optional(),
|
|
711
|
+
// Mirrors invoiceLineItemSchema — itemName is the required snapshot and
|
|
712
|
+
// description is the optional free-text notes field.
|
|
713
|
+
itemName: z2.string().min(1).max(200),
|
|
714
|
+
description: z2.string().max(500).optional().nullable(),
|
|
715
|
+
quantity: z2.string().regex(/^\d+(\.\d{1,3})?$/).refine((v) => parseFloat(v) > 0, { message: "Quantity must be greater than 0" }),
|
|
716
|
+
unitPrice: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/),
|
|
717
|
+
taxPercent: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).default("0"),
|
|
718
|
+
discountPercent: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).default("0"),
|
|
719
|
+
selectedUnit: z2.string().nullish(),
|
|
720
|
+
conversionFactor: z2.string().nullish(),
|
|
721
|
+
variantId: z2.string().uuid().nullish()
|
|
722
|
+
});
|
|
723
|
+
var createRecurringInvoiceSchema = z2.object({
|
|
724
|
+
partyId: z2.string().uuid(),
|
|
725
|
+
name: z2.string().min(1).max(200),
|
|
726
|
+
type: z2.enum(invoiceTypes),
|
|
727
|
+
frequency: z2.enum(recurringFrequencies),
|
|
728
|
+
customIntervalDays: z2.number().int().min(1).max(365).optional(),
|
|
729
|
+
lineItems: z2.array(recurringLineItemSchema).min(1),
|
|
730
|
+
notes: z2.string().max(2e3).optional(),
|
|
731
|
+
termsAndConditions: z2.string().max(2e3).optional(),
|
|
732
|
+
additionalCharges: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).default("0"),
|
|
733
|
+
charges: z2.array(invoiceChargeSchema).optional(),
|
|
734
|
+
startDate: z2.string().datetime(),
|
|
735
|
+
endDate: z2.string().datetime().optional(),
|
|
736
|
+
maxRuns: z2.number().int().min(1).optional()
|
|
737
|
+
}).refine((d) => {
|
|
738
|
+
if (d.frequency === "custom" && !d.customIntervalDays) return false;
|
|
739
|
+
return true;
|
|
740
|
+
}, { message: "customIntervalDays is required when frequency is 'custom'", path: ["customIntervalDays"] });
|
|
741
|
+
var updateRecurringInvoiceSchema = z2.object({
|
|
742
|
+
name: z2.string().min(1).max(200).optional(),
|
|
743
|
+
partyId: z2.string().uuid().optional(),
|
|
744
|
+
type: z2.enum(invoiceTypes).optional(),
|
|
745
|
+
frequency: z2.enum(recurringFrequencies).optional(),
|
|
746
|
+
customIntervalDays: z2.number().int().min(1).max(365).optional(),
|
|
747
|
+
lineItems: z2.array(recurringLineItemSchema).min(1).optional(),
|
|
748
|
+
notes: z2.string().max(2e3).optional(),
|
|
749
|
+
termsAndConditions: z2.string().max(2e3).optional(),
|
|
750
|
+
additionalCharges: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).optional(),
|
|
751
|
+
charges: z2.array(invoiceChargeSchema).optional(),
|
|
752
|
+
endDate: z2.string().datetime().optional(),
|
|
753
|
+
maxRuns: z2.number().int().min(1).optional().nullable()
|
|
754
|
+
});
|
|
755
|
+
var accountTypes = ["asset", "liability", "equity", "income", "expense"];
|
|
756
|
+
var createAccountSchema = z2.object({
|
|
757
|
+
code: z2.string().min(1).max(10),
|
|
758
|
+
name: z2.string().min(1).max(200),
|
|
759
|
+
accountType: z2.enum(accountTypes),
|
|
760
|
+
parentId: z2.string().uuid().optional()
|
|
761
|
+
});
|
|
762
|
+
var updateAccountSchema = z2.object({
|
|
763
|
+
name: z2.string().min(1).max(200).optional(),
|
|
764
|
+
isActive: z2.boolean().optional()
|
|
765
|
+
});
|
|
766
|
+
var journalEntryLineSchema = z2.object({
|
|
767
|
+
accountId: z2.string().uuid(),
|
|
768
|
+
debit: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).default("0"),
|
|
769
|
+
credit: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).default("0"),
|
|
770
|
+
narration: z2.string().max(500).optional()
|
|
771
|
+
});
|
|
772
|
+
var createJournalEntrySchema = z2.object({
|
|
773
|
+
entryDate: z2.string().datetime(),
|
|
774
|
+
narration: z2.string().max(2e3).optional(),
|
|
775
|
+
lines: z2.array(journalEntryLineSchema).min(2)
|
|
776
|
+
}).refine((data) => {
|
|
777
|
+
const totalDebit = data.lines.reduce((s, l) => s + parseFloat(l.debit), 0);
|
|
778
|
+
const totalCredit = data.lines.reduce((s, l) => s + parseFloat(l.credit), 0);
|
|
779
|
+
return Math.abs(totalDebit - totalCredit) < 0.01;
|
|
780
|
+
}, { message: "Journal entry must be balanced (total debits = total credits)" });
|
|
781
|
+
var updateJournalEntrySchema = z2.object({
|
|
782
|
+
id: z2.string().uuid(),
|
|
783
|
+
entryDate: z2.string().datetime().optional(),
|
|
784
|
+
narration: z2.string().max(2e3).optional(),
|
|
785
|
+
lines: z2.array(journalEntryLineSchema).min(2).optional()
|
|
786
|
+
}).refine((data) => {
|
|
787
|
+
if (!data.lines) return true;
|
|
788
|
+
const totalDebit = data.lines.reduce((s, l) => s + parseFloat(l.debit), 0);
|
|
789
|
+
const totalCredit = data.lines.reduce((s, l) => s + parseFloat(l.credit), 0);
|
|
790
|
+
return Math.abs(totalDebit - totalCredit) < 0.01;
|
|
791
|
+
}, { message: "Journal entry must be balanced (total debits = total credits)" });
|
|
792
|
+
var voidJournalEntrySchema = z2.object({
|
|
793
|
+
id: z2.string().uuid()
|
|
794
|
+
});
|
|
795
|
+
var journalEntryTemplateLineSchema = z2.object({
|
|
796
|
+
accountId: z2.string().uuid(),
|
|
797
|
+
accountCode: z2.string(),
|
|
798
|
+
accountName: z2.string(),
|
|
799
|
+
debit: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).default("0"),
|
|
800
|
+
credit: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).default("0"),
|
|
801
|
+
narration: z2.string().max(500).optional()
|
|
802
|
+
});
|
|
803
|
+
var createJournalEntryTemplateSchema = z2.object({
|
|
804
|
+
name: z2.string().min(1).max(200),
|
|
805
|
+
narration: z2.string().max(2e3).optional(),
|
|
806
|
+
lines: z2.array(journalEntryTemplateLineSchema).min(2)
|
|
807
|
+
});
|
|
808
|
+
var itcBlockReasons = [
|
|
809
|
+
"motor_vehicle",
|
|
810
|
+
"food_beverage",
|
|
811
|
+
"personal",
|
|
812
|
+
"membership",
|
|
813
|
+
"travel_benefits",
|
|
814
|
+
"works_contract",
|
|
815
|
+
"construction",
|
|
816
|
+
"telecom",
|
|
817
|
+
"other"
|
|
818
|
+
];
|
|
819
|
+
var markItcBlockedSchema = z2.object({
|
|
820
|
+
invoiceId: z2.string().uuid(),
|
|
821
|
+
blockReason: z2.enum(itcBlockReasons),
|
|
822
|
+
notes: z2.string().max(500).optional()
|
|
823
|
+
});
|
|
824
|
+
var markItcEligibleSchema = z2.object({
|
|
825
|
+
invoiceId: z2.string().uuid()
|
|
826
|
+
});
|
|
827
|
+
var recordItcUtilizationSchema = z2.object({
|
|
828
|
+
returnPeriod: z2.string().regex(/^\d{4}-\d{2}$/),
|
|
829
|
+
// "2026-04"
|
|
830
|
+
cgstUtilized: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).default("0"),
|
|
831
|
+
sgstUtilized: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).default("0"),
|
|
832
|
+
igstUtilizedAgainstCgst: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).default("0"),
|
|
833
|
+
igstUtilizedAgainstSgst: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).default("0"),
|
|
834
|
+
igstUtilizedAgainstIgst: z2.string().regex(/^\d{1,13}(\.\d{1,2})?$/).default("0"),
|
|
835
|
+
notes: z2.string().max(500).optional()
|
|
836
|
+
});
|
|
837
|
+
var bankReconColumnMappingSchema = z2.object({
|
|
838
|
+
date: z2.number().int().min(0),
|
|
839
|
+
narration: z2.number().int().min(0),
|
|
840
|
+
debit: z2.number().int().min(0).optional(),
|
|
841
|
+
credit: z2.number().int().min(0).optional(),
|
|
842
|
+
amount: z2.number().int().min(0).optional(),
|
|
843
|
+
type: z2.number().int().min(0).optional(),
|
|
844
|
+
reference: z2.number().int().min(0).optional(),
|
|
845
|
+
balance: z2.number().int().min(0).optional(),
|
|
846
|
+
dateFormat: z2.string().default("DD/MM/YYYY"),
|
|
847
|
+
skipRows: z2.number().int().min(0).default(1),
|
|
848
|
+
amountSignConvention: z2.enum(["debit_positive", "credit_positive"]).optional()
|
|
849
|
+
});
|
|
850
|
+
var confirmBankMappingSchema = z2.object({
|
|
851
|
+
importId: z2.string().uuid(),
|
|
852
|
+
columnMapping: bankReconColumnMappingSchema
|
|
853
|
+
});
|
|
854
|
+
var bankCategorizationRuleSchema = z2.object({
|
|
855
|
+
bankAccountId: z2.string().uuid().optional(),
|
|
856
|
+
matchField: z2.enum(["narration", "reference"]),
|
|
857
|
+
matchType: z2.enum(["contains", "starts_with", "exact", "regex"]),
|
|
858
|
+
matchValue: z2.string().min(1).max(500),
|
|
859
|
+
action: z2.enum(["create_expense", "ignore", "tag_party"]),
|
|
860
|
+
expenseCategory: z2.string().max(100).optional(),
|
|
861
|
+
partyId: z2.string().uuid().optional(),
|
|
862
|
+
priority: z2.number().int().min(0).default(0)
|
|
863
|
+
});
|
|
864
|
+
var eInvoiceConfigSchema = z2.object({
|
|
865
|
+
gstin: z2.string().length(15),
|
|
866
|
+
clientId: z2.string().min(1).max(200),
|
|
867
|
+
clientSecret: z2.string().min(1).max(500),
|
|
868
|
+
username: z2.string().min(1).max(100),
|
|
869
|
+
password: z2.string().min(1).max(200),
|
|
870
|
+
isSandbox: z2.boolean().default(true),
|
|
871
|
+
isEnabled: z2.boolean().default(false),
|
|
872
|
+
thresholdCrore: z2.string().regex(/^\d{1,3}(\.\d{1,2})?$/).default("5")
|
|
873
|
+
});
|
|
874
|
+
var eInvoiceCancelReasons = ["1", "2", "3", "4"];
|
|
875
|
+
var cancelEInvoiceSchema = z2.object({
|
|
876
|
+
invoiceId: z2.string().uuid(),
|
|
877
|
+
cancelReason: z2.enum(eInvoiceCancelReasons),
|
|
878
|
+
cancelRemarks: z2.string().max(100).optional()
|
|
879
|
+
});
|
|
880
|
+
var generateEwayBillSchema = z2.object({
|
|
881
|
+
invoiceId: z2.string().uuid(),
|
|
882
|
+
transporterId: z2.string().max(15).optional(),
|
|
883
|
+
transporterName: z2.string().max(200).optional(),
|
|
884
|
+
vehicleNumber: z2.string().max(20),
|
|
885
|
+
vehicleType: z2.enum(["regular", "over_dimensional"]).default("regular"),
|
|
886
|
+
transportMode: z2.enum(["road", "rail", "air", "ship"]).default("road"),
|
|
887
|
+
distance: z2.number().int().min(1).max(4e3),
|
|
888
|
+
fromAddress: z2.string().max(500).optional(),
|
|
889
|
+
fromPincode: z2.string().length(6).optional(),
|
|
890
|
+
toAddress: z2.string().max(500).optional(),
|
|
891
|
+
toPincode: z2.string().length(6).optional()
|
|
892
|
+
});
|
|
893
|
+
var cancelEwayBillSchema = z2.object({
|
|
894
|
+
ewayBillId: z2.string().uuid(),
|
|
895
|
+
cancelReason: z2.string().max(250)
|
|
896
|
+
});
|
|
897
|
+
var updateEwbVehicleSchema = z2.object({
|
|
898
|
+
ewayBillId: z2.string().uuid(),
|
|
899
|
+
vehicleNumber: z2.string().max(20),
|
|
900
|
+
fromPlace: z2.string().max(200).optional(),
|
|
901
|
+
reason: z2.enum(["breakdown", "transshipment", "first_time", "others"]).default("others")
|
|
902
|
+
});
|
|
903
|
+
var hsnSearchSchema = z2.object({
|
|
904
|
+
query: z2.string().min(1).max(50),
|
|
905
|
+
type: z2.enum(["goods", "services"]).optional(),
|
|
906
|
+
limit: z2.number().int().min(1).max(50).default(20)
|
|
907
|
+
});
|
|
908
|
+
var gstr2bUploadSchema = z2.object({
|
|
909
|
+
returnPeriod: z2.string().regex(/^\d{4}-\d{2}$/),
|
|
910
|
+
content: z2.string().min(1).max(5e7),
|
|
911
|
+
fileName: z2.string().min(1).max(255),
|
|
912
|
+
format: z2.enum(["json", "csv"])
|
|
913
|
+
});
|
|
914
|
+
var gstr2bRecordsInputSchema = z2.object({
|
|
915
|
+
uploadId: z2.string().uuid(),
|
|
916
|
+
matchStatus: z2.enum(["matched", "mismatched", "missing_in_books", "pending", "ignored"]).optional(),
|
|
917
|
+
page: z2.number().int().min(1).default(1),
|
|
918
|
+
limit: z2.number().int().min(1).max(100).default(25)
|
|
919
|
+
});
|
|
920
|
+
var gstr2bSummaryInputSchema = z2.object({
|
|
921
|
+
returnPeriod: z2.string().regex(/^\d{4}-\d{2}$/)
|
|
922
|
+
});
|
|
923
|
+
var gstr2bLinkInvoiceSchema = z2.object({
|
|
924
|
+
recordId: z2.string().uuid(),
|
|
925
|
+
invoiceId: z2.string().uuid()
|
|
926
|
+
});
|
|
927
|
+
var gstr2bIgnoreRecordSchema = z2.object({
|
|
928
|
+
recordId: z2.string().uuid()
|
|
929
|
+
});
|
|
930
|
+
var createApiKeySchema = z2.object({
|
|
931
|
+
name: z2.string().min(1).max(100),
|
|
932
|
+
expiresAt: z2.string().datetime().optional()
|
|
933
|
+
});
|
|
934
|
+
var revokeApiKeySchema = z2.object({
|
|
935
|
+
id: z2.string().uuid()
|
|
936
|
+
});
|
|
937
|
+
var maintenanceStatusSchema = z2.object({
|
|
938
|
+
enabled: z2.boolean(),
|
|
939
|
+
message: z2.string(),
|
|
940
|
+
startsAt: z2.string().datetime().nullable(),
|
|
941
|
+
endsAt: z2.string().datetime().nullable()
|
|
942
|
+
});
|
|
943
|
+
|
|
944
|
+
// ../shared/src/quantity.ts
|
|
945
|
+
var quantityFormatter = new Intl.NumberFormat("en-IN", {
|
|
946
|
+
minimumFractionDigits: 0,
|
|
947
|
+
maximumFractionDigits: 3
|
|
948
|
+
});
|
|
949
|
+
|
|
950
|
+
// ../shared/src/permissions.ts
|
|
951
|
+
var INVOICE_DELETE_WINDOW_MS = 2 * 60 * 60 * 1e3;
|
|
952
|
+
|
|
953
|
+
// ../shared/src/sanitize.ts
|
|
954
|
+
var FORMULA_PREFIX = /^[=+\-@\t\r]/;
|
|
955
|
+
function csvCell(value) {
|
|
956
|
+
if (value === null || value === void 0) return '""';
|
|
957
|
+
let s = typeof value === "string" ? value : String(value);
|
|
958
|
+
const isPlainNumber = typeof value === "number" || /^-?\d+(\.\d+)?$/.test(s);
|
|
959
|
+
if (!isPlainNumber && FORMULA_PREFIX.test(s)) s = `'${s}`;
|
|
960
|
+
return `"${s.replace(/"/g, '""')}"`;
|
|
961
|
+
}
|
|
962
|
+
var CONTROL_CHARS = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f--]/g;
|
|
963
|
+
function stripControlChars(value) {
|
|
964
|
+
return value.replace(CONTROL_CHARS, "\uFFFD");
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
// ../shared/src/tax-codes.ts
|
|
968
|
+
var TDS_TAX_CODE_SOURCE = "https://razorpay.com/docs/payroll/tax-verifications/tax-codes";
|
|
969
|
+
var CURRENT_TDS_CODES = [
|
|
970
|
+
["1001", "Payment to government employees other than union government employees", "192"],
|
|
971
|
+
["1002", "Payment of employees other than government employees", "192"],
|
|
972
|
+
["1004", "Payment of accumulated balance due to an employee", "192A"],
|
|
973
|
+
["1005", "Commission or brokerage - insurance", "194D"],
|
|
974
|
+
["1006", "Commission or brokerage - others", "194H"],
|
|
975
|
+
["1008", "Rent on machinery - specified person", "194I(a)"],
|
|
976
|
+
["1009", "Rent other than machinery - specified person", "194I(b)"],
|
|
977
|
+
["1011", "Payment on any consideration (not in kind) under agreement referred to in section 67(14)", "194-IC"],
|
|
978
|
+
["1012", "Payment of compensation on acquisition of certain immovable property", "194LA"],
|
|
979
|
+
["1013", "Income in respect of units of a specified mutual fund or units from administrator of specified undertaking or specified company", "194K"],
|
|
980
|
+
["1014", "Interest from units of a business trust to a resident unit holder", "194LBA"],
|
|
981
|
+
["1015", "Dividend from units of a business trust to a resident unit holder", "194LBA"],
|
|
982
|
+
["1016", "Renting income from units of a business trust (REIT) to a resident unit holder", "194LBA"],
|
|
983
|
+
["1017", "Income in respect of units of an investment fund specified in section 224", "194LBB"],
|
|
984
|
+
["1018", "Income in respect of an investment in a securitisation trust specified in section 221", "194LBC"],
|
|
985
|
+
["1019", "Interest on securities", "193"],
|
|
986
|
+
["1020", "Interest other than on securities - senior citizen", "194A"],
|
|
987
|
+
["1021", "Interest other than on securities - other than senior citizen", "194A"],
|
|
988
|
+
["1022", "Interest other than interest on securities", "194A"],
|
|
989
|
+
["1023", "Contract payment - contractor is individual or HUF", "194C"],
|
|
990
|
+
["1024", "Contract payment - contractor is other than individual or HUF", "194C"],
|
|
991
|
+
["1026", "Fees for technical services (not professional), royalty for cinematographic films or call centre operations - specified person", "194J(a)"],
|
|
992
|
+
["1027", "Fees for professional services or sum referred to in section 26(2)(h) - specified person", "194J(b)"],
|
|
993
|
+
["1028", "Remuneration, fees or commission to a director of a company - specified person", "194J(b)"],
|
|
994
|
+
["1029", "Dividends (including on preference shares) declared", "194"],
|
|
995
|
+
["1030", "Sum under a life insurance policy (including bonus)", "194DA"],
|
|
996
|
+
["1031", "Sum for purchase of any goods", "194Q"],
|
|
997
|
+
["1032", "Payment to specified senior citizen", "194P"],
|
|
998
|
+
["1033", "Benefit or perquisite arising from business or profession of any resident", "194R"],
|
|
999
|
+
["1035", "Sale of goods or provision of services by e-commerce participant facilitated by e-commerce operator", "194-O"],
|
|
1000
|
+
["1037", "Consideration for transfer of a virtual digital asset (other than individual or HUF)", "194S"],
|
|
1001
|
+
["1058", "Winnings from lottery, crossword puzzle, card game, gambling or betting", "194B"],
|
|
1002
|
+
["1060", "Winnings from online game", "194BA"],
|
|
1003
|
+
["1062", "Winnings from horse race", "194BB"],
|
|
1004
|
+
["1063", "Income to person stocking, distributing, purchasing or selling lottery tickets", "194G"],
|
|
1005
|
+
["1064", "Cash payment by bank/post office/co-operative society - deductee is co-operative society", "194N"],
|
|
1006
|
+
["1065", "Cash payment by bank/post office/co-operative society - deductee is other than co-operative society", "194N"],
|
|
1007
|
+
["1066", "Amount referred to in section 80CCA(2)(a) of the Income-tax Act, 1961", "194EE"],
|
|
1008
|
+
["1067", "Salary, remuneration, commission, bonus or interest to a partner of the firm", "194T"]
|
|
1009
|
+
];
|
|
1010
|
+
var legacyCodes = /* @__PURE__ */ new Map();
|
|
1011
|
+
for (const [, , oldCode] of CURRENT_TDS_CODES) {
|
|
1012
|
+
const code = oldCode.toUpperCase();
|
|
1013
|
+
if (!legacyCodes.has(code)) {
|
|
1014
|
+
legacyCodes.set(code, {
|
|
1015
|
+
code,
|
|
1016
|
+
label: `Legacy section ${oldCode}`,
|
|
1017
|
+
status: "legacy",
|
|
1018
|
+
historicalValidity: "unverified",
|
|
1019
|
+
source: TDS_TAX_CODE_SOURCE
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
var legacyCodesByCurrentCode = /* @__PURE__ */ new Map();
|
|
1024
|
+
for (const [code, , oldCode] of CURRENT_TDS_CODES) {
|
|
1025
|
+
const existing = legacyCodesByCurrentCode.get(code) ?? [];
|
|
1026
|
+
existing.push(oldCode);
|
|
1027
|
+
legacyCodesByCurrentCode.set(code, existing);
|
|
1028
|
+
}
|
|
1029
|
+
var TDS_TAX_CODES = [
|
|
1030
|
+
...CURRENT_TDS_CODES.map(([code, label]) => ({
|
|
1031
|
+
code,
|
|
1032
|
+
label,
|
|
1033
|
+
status: "current",
|
|
1034
|
+
historicalValidity: "verified",
|
|
1035
|
+
effectiveFrom: "2026-04-01",
|
|
1036
|
+
legacyCodes: legacyCodesByCurrentCode.get(code),
|
|
1037
|
+
source: TDS_TAX_CODE_SOURCE
|
|
1038
|
+
})),
|
|
1039
|
+
...Array.from(legacyCodes.values())
|
|
1040
|
+
];
|
|
1041
|
+
var taxCodesByCode = new Map(TDS_TAX_CODES.map((entry) => [entry.code, entry]));
|
|
1042
|
+
|
|
1043
|
+
// ../shared/src/notifications/channels.ts
|
|
1044
|
+
var CHANNEL_IDS = [
|
|
1045
|
+
"money_in",
|
|
1046
|
+
"collections",
|
|
1047
|
+
"sales",
|
|
1048
|
+
"store",
|
|
1049
|
+
"payables",
|
|
1050
|
+
"banking",
|
|
1051
|
+
"compliance",
|
|
1052
|
+
"inventory",
|
|
1053
|
+
"targets",
|
|
1054
|
+
"security",
|
|
1055
|
+
"digest",
|
|
1056
|
+
"general",
|
|
1057
|
+
"promotions"
|
|
1058
|
+
];
|
|
1059
|
+
|
|
1060
|
+
// ../shared/src/notifications/events.ts
|
|
1061
|
+
var ADMIN_LIKE = ["superadmin", "admin"];
|
|
1062
|
+
function def(type, d) {
|
|
1063
|
+
return { type, ...d, target: d.target };
|
|
1064
|
+
}
|
|
1065
|
+
var EVENTS = {
|
|
1066
|
+
"payment.received": def("payment.received", {
|
|
1067
|
+
channel: "money_in",
|
|
1068
|
+
audience: "business",
|
|
1069
|
+
requires: [["read", "Payment"]],
|
|
1070
|
+
lockedFor: null,
|
|
1071
|
+
urgent: false,
|
|
1072
|
+
amountField: "amount",
|
|
1073
|
+
target: (p2) => ({ kind: "payment", id: p2.paymentId })
|
|
1074
|
+
}),
|
|
1075
|
+
"payment.made": def("payment.made", {
|
|
1076
|
+
channel: "payables",
|
|
1077
|
+
audience: "business",
|
|
1078
|
+
requires: [["read", "Expense"], ["read", "Payment"]],
|
|
1079
|
+
lockedFor: null,
|
|
1080
|
+
urgent: false,
|
|
1081
|
+
amountField: "amount",
|
|
1082
|
+
target: (p2) => ({ kind: "payment", id: p2.paymentId })
|
|
1083
|
+
}),
|
|
1084
|
+
"invoice.due_today": def("invoice.due_today", {
|
|
1085
|
+
channel: "collections",
|
|
1086
|
+
audience: "business",
|
|
1087
|
+
requires: [["read", "Invoice"], ["read", "Party"]],
|
|
1088
|
+
lockedFor: null,
|
|
1089
|
+
urgent: false,
|
|
1090
|
+
amountField: "amountDue",
|
|
1091
|
+
target: (p2) => ({ kind: "invoice", id: p2.invoiceId })
|
|
1092
|
+
}),
|
|
1093
|
+
"invoice.overdue": def("invoice.overdue", {
|
|
1094
|
+
channel: "collections",
|
|
1095
|
+
audience: "business",
|
|
1096
|
+
requires: [["read", "Invoice"], ["read", "Party"]],
|
|
1097
|
+
lockedFor: null,
|
|
1098
|
+
urgent: false,
|
|
1099
|
+
amountField: "amountDue",
|
|
1100
|
+
target: (p2) => ({ kind: "invoice", id: p2.invoiceId })
|
|
1101
|
+
}),
|
|
1102
|
+
"store.order_placed": def("store.order_placed", {
|
|
1103
|
+
channel: "store",
|
|
1104
|
+
audience: "business",
|
|
1105
|
+
requires: [["read", "Store"]],
|
|
1106
|
+
lockedFor: null,
|
|
1107
|
+
urgent: false,
|
|
1108
|
+
amountField: "totalAmount",
|
|
1109
|
+
target: (p2) => ({ kind: "store_order", id: p2.orderId })
|
|
1110
|
+
}),
|
|
1111
|
+
"einvoice.failed": def("einvoice.failed", {
|
|
1112
|
+
channel: "compliance",
|
|
1113
|
+
audience: "business",
|
|
1114
|
+
requires: [["read", "EInvoice"]],
|
|
1115
|
+
lockedFor: [...ADMIN_LIKE, "accountant"],
|
|
1116
|
+
urgent: true,
|
|
1117
|
+
amountField: null,
|
|
1118
|
+
target: (p2) => ({ kind: "invoice", id: p2.invoiceId })
|
|
1119
|
+
}),
|
|
1120
|
+
"team.member_joined": def("team.member_joined", {
|
|
1121
|
+
channel: "security",
|
|
1122
|
+
audience: "admins",
|
|
1123
|
+
requires: [],
|
|
1124
|
+
lockedFor: "all",
|
|
1125
|
+
urgent: true,
|
|
1126
|
+
amountField: null,
|
|
1127
|
+
target: () => ({ kind: "team" })
|
|
1128
|
+
}),
|
|
1129
|
+
"team.role_changed": def("team.role_changed", {
|
|
1130
|
+
channel: "security",
|
|
1131
|
+
audience: "subject_and_admins",
|
|
1132
|
+
requires: [],
|
|
1133
|
+
lockedFor: "all",
|
|
1134
|
+
urgent: true,
|
|
1135
|
+
amountField: null,
|
|
1136
|
+
target: () => ({ kind: "team" })
|
|
1137
|
+
}),
|
|
1138
|
+
"api_key.created": def("api_key.created", {
|
|
1139
|
+
channel: "security",
|
|
1140
|
+
audience: "subject_and_admins",
|
|
1141
|
+
requires: [],
|
|
1142
|
+
lockedFor: "all",
|
|
1143
|
+
urgent: true,
|
|
1144
|
+
amountField: null,
|
|
1145
|
+
target: () => ({ kind: "api_keys" })
|
|
1146
|
+
}),
|
|
1147
|
+
"general.announcement": def("general.announcement", {
|
|
1148
|
+
channel: "general",
|
|
1149
|
+
audience: "business",
|
|
1150
|
+
requires: [],
|
|
1151
|
+
lockedFor: null,
|
|
1152
|
+
urgent: false,
|
|
1153
|
+
amountField: null,
|
|
1154
|
+
target: () => ({ kind: "inbox" })
|
|
1155
|
+
})
|
|
1156
|
+
};
|
|
1157
|
+
var EVENT_TYPES = Object.keys(EVENTS);
|
|
1158
|
+
|
|
1159
|
+
// ../shared/src/notifications/preferences.ts
|
|
1160
|
+
var p = (delivery, scope = "everyone", email = false) => ({
|
|
1161
|
+
delivery,
|
|
1162
|
+
scope,
|
|
1163
|
+
thresholdPaise: null,
|
|
1164
|
+
email
|
|
1165
|
+
});
|
|
1166
|
+
var OWNER_DEFAULTS = {
|
|
1167
|
+
money_in: p("push"),
|
|
1168
|
+
collections: p("push"),
|
|
1169
|
+
sales: p("digest"),
|
|
1170
|
+
store: p("push"),
|
|
1171
|
+
payables: p("inbox"),
|
|
1172
|
+
banking: p("inbox"),
|
|
1173
|
+
compliance: p("push", "everyone", true),
|
|
1174
|
+
inventory: p("inbox"),
|
|
1175
|
+
targets: p("digest"),
|
|
1176
|
+
security: p("push", "everyone", true),
|
|
1177
|
+
digest: p("push", "everyone", true),
|
|
1178
|
+
general: p("inbox"),
|
|
1179
|
+
promotions: p("inbox")
|
|
1180
|
+
};
|
|
1181
|
+
var ROLE_DEFAULTS = {
|
|
1182
|
+
superadmin: OWNER_DEFAULTS,
|
|
1183
|
+
admin: OWNER_DEFAULTS,
|
|
1184
|
+
seller_manager: {
|
|
1185
|
+
money_in: p("push"),
|
|
1186
|
+
collections: p("push"),
|
|
1187
|
+
sales: p("push"),
|
|
1188
|
+
store: p("push"),
|
|
1189
|
+
payables: p("off"),
|
|
1190
|
+
banking: p("off"),
|
|
1191
|
+
compliance: p("off"),
|
|
1192
|
+
inventory: p("push"),
|
|
1193
|
+
targets: p("push"),
|
|
1194
|
+
security: p("push", "everyone", true),
|
|
1195
|
+
digest: p("push", "everyone", true),
|
|
1196
|
+
general: p("inbox"),
|
|
1197
|
+
promotions: p("inbox")
|
|
1198
|
+
},
|
|
1199
|
+
seller: {
|
|
1200
|
+
money_in: p("push", "mine"),
|
|
1201
|
+
collections: p("push", "mine"),
|
|
1202
|
+
sales: p("inbox", "mine"),
|
|
1203
|
+
store: p("off"),
|
|
1204
|
+
payables: p("off"),
|
|
1205
|
+
banking: p("off"),
|
|
1206
|
+
compliance: p("off"),
|
|
1207
|
+
inventory: p("off"),
|
|
1208
|
+
targets: p("push", "mine"),
|
|
1209
|
+
security: p("push", "everyone", true),
|
|
1210
|
+
digest: p("push", "mine", true),
|
|
1211
|
+
general: p("inbox"),
|
|
1212
|
+
promotions: p("inbox")
|
|
1213
|
+
},
|
|
1214
|
+
accountant: {
|
|
1215
|
+
money_in: p("inbox"),
|
|
1216
|
+
collections: p("push"),
|
|
1217
|
+
sales: p("off"),
|
|
1218
|
+
store: p("off"),
|
|
1219
|
+
payables: p("push"),
|
|
1220
|
+
banking: p("push"),
|
|
1221
|
+
compliance: p("push", "everyone", true),
|
|
1222
|
+
inventory: p("off"),
|
|
1223
|
+
targets: p("off"),
|
|
1224
|
+
security: p("push", "everyone", true),
|
|
1225
|
+
digest: p("inbox", "everyone", true),
|
|
1226
|
+
general: p("inbox"),
|
|
1227
|
+
promotions: p("inbox")
|
|
1228
|
+
}
|
|
1229
|
+
};
|
|
1230
|
+
var NO_ROLE_DEFAULTS = Object.fromEntries(
|
|
1231
|
+
CHANNEL_IDS.map((c) => [c, p("off")])
|
|
1232
|
+
);
|
|
1233
|
+
|
|
1234
|
+
// ../shared/src/store-slug.ts
|
|
1235
|
+
var RESERVED_STORE_SLUGS = [
|
|
1236
|
+
// Platform / brand
|
|
1237
|
+
"hisaabo",
|
|
1238
|
+
"hisaab",
|
|
1239
|
+
"official",
|
|
1240
|
+
"team",
|
|
1241
|
+
"staff",
|
|
1242
|
+
// Auth, account and infrastructure paths
|
|
1243
|
+
"admin",
|
|
1244
|
+
"api",
|
|
1245
|
+
"app",
|
|
1246
|
+
"login",
|
|
1247
|
+
"logout",
|
|
1248
|
+
"signin",
|
|
1249
|
+
"signup",
|
|
1250
|
+
"register",
|
|
1251
|
+
"auth",
|
|
1252
|
+
"account",
|
|
1253
|
+
"oauth",
|
|
1254
|
+
"verify",
|
|
1255
|
+
"otp",
|
|
1256
|
+
"www",
|
|
1257
|
+
"mail",
|
|
1258
|
+
"email",
|
|
1259
|
+
"static",
|
|
1260
|
+
"assets",
|
|
1261
|
+
"cdn",
|
|
1262
|
+
"ops",
|
|
1263
|
+
"dashboard",
|
|
1264
|
+
"settings",
|
|
1265
|
+
"security",
|
|
1266
|
+
"secure",
|
|
1267
|
+
"kyc",
|
|
1268
|
+
"health",
|
|
1269
|
+
"user",
|
|
1270
|
+
"users",
|
|
1271
|
+
"profile",
|
|
1272
|
+
"home",
|
|
1273
|
+
"search",
|
|
1274
|
+
"pricing",
|
|
1275
|
+
"download",
|
|
1276
|
+
"test",
|
|
1277
|
+
"demo",
|
|
1278
|
+
"null",
|
|
1279
|
+
"undefined",
|
|
1280
|
+
// Commerce flow
|
|
1281
|
+
"pay",
|
|
1282
|
+
"checkout",
|
|
1283
|
+
"cart",
|
|
1284
|
+
"order",
|
|
1285
|
+
"orders",
|
|
1286
|
+
"billing",
|
|
1287
|
+
"invoice",
|
|
1288
|
+
"invoices",
|
|
1289
|
+
"payment",
|
|
1290
|
+
"payments",
|
|
1291
|
+
"upi",
|
|
1292
|
+
// Marketing / support / legal pages
|
|
1293
|
+
"store",
|
|
1294
|
+
"stores",
|
|
1295
|
+
"shop",
|
|
1296
|
+
"docs",
|
|
1297
|
+
"help",
|
|
1298
|
+
"support",
|
|
1299
|
+
"status",
|
|
1300
|
+
"blog",
|
|
1301
|
+
"about",
|
|
1302
|
+
"contact",
|
|
1303
|
+
"customer-care",
|
|
1304
|
+
"privacy",
|
|
1305
|
+
"terms",
|
|
1306
|
+
"refund",
|
|
1307
|
+
"refunds",
|
|
1308
|
+
"policy",
|
|
1309
|
+
"legal",
|
|
1310
|
+
// Paths the storefront itself serves at the top level (apps/store):
|
|
1311
|
+
// `/index` (index.html); `/assets` (build output) and `/store/...` (asset
|
|
1312
|
+
// endpoints) are listed above.
|
|
1313
|
+
"index"
|
|
1314
|
+
];
|
|
1315
|
+
var RESERVED_SET = new Set(RESERVED_STORE_SLUGS);
|
|
1316
|
+
|
|
1317
|
+
// src/output.ts
|
|
1318
|
+
function isInteractive() {
|
|
1319
|
+
return process.stdout.isTTY === true;
|
|
1320
|
+
}
|
|
1321
|
+
function hasColor() {
|
|
1322
|
+
if (process.env["NO_COLOR"] !== void 0) return false;
|
|
1323
|
+
if (process.env["FORCE_COLOR"] === "0") return false;
|
|
1324
|
+
return process.stdout.hasColors?.() ?? isInteractive();
|
|
1325
|
+
}
|
|
1326
|
+
function stripAnsi(str) {
|
|
1327
|
+
return str.replace(/\x1b\[[0-9;]*m/g, "");
|
|
1328
|
+
}
|
|
1329
|
+
function sanitizeTerminal(str) {
|
|
1330
|
+
return str.split(/(\x1b\[[0-9;]*m)/).map((part, i) => i % 2 === 1 ? part : stripControlChars(part)).join("");
|
|
1331
|
+
}
|
|
1332
|
+
function installTerminalSanitizer() {
|
|
1333
|
+
for (const stream of [process.stdout, process.stderr]) {
|
|
1334
|
+
const orig = stream.write.bind(stream);
|
|
1335
|
+
stream.write = ((chunk, ...rest) => {
|
|
1336
|
+
if (typeof chunk === "string") {
|
|
1337
|
+
const lead = chunk.startsWith("\r") ? "\r" : "";
|
|
1338
|
+
chunk = lead + sanitizeTerminal(chunk.slice(lead.length));
|
|
1339
|
+
}
|
|
1340
|
+
return orig(chunk, ...rest);
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
function cellText(str) {
|
|
1345
|
+
return sanitizeTerminal(str).replace(/[\r\n\t]+/g, " ");
|
|
1346
|
+
}
|
|
1347
|
+
function getWidthTier() {
|
|
1348
|
+
const w = process.stdout.columns ?? 80;
|
|
1349
|
+
if (w < 80) return "narrow";
|
|
1350
|
+
if (w <= 120) return "standard";
|
|
1351
|
+
return "wide";
|
|
1352
|
+
}
|
|
1353
|
+
function termWidth() {
|
|
1354
|
+
return process.stdout.columns ?? 80;
|
|
1355
|
+
}
|
|
1356
|
+
var EXIT = {
|
|
1357
|
+
SUCCESS: 0,
|
|
1358
|
+
GENERAL: 1,
|
|
1359
|
+
USAGE: 2,
|
|
1360
|
+
AUTH: 3,
|
|
1361
|
+
FORBIDDEN: 4,
|
|
1362
|
+
NOT_FOUND: 5,
|
|
1363
|
+
VALIDATION: 6,
|
|
1364
|
+
NETWORK: 7,
|
|
1365
|
+
CONFLICT: 8,
|
|
1366
|
+
RATE_LIMITED: 9
|
|
1367
|
+
};
|
|
1368
|
+
function fatalError(message, code = 1) {
|
|
1369
|
+
if (hasColor()) {
|
|
1370
|
+
process.stderr.write(chalk.red("Error: ") + sanitizeTerminal(message) + "\n");
|
|
1371
|
+
} else {
|
|
1372
|
+
process.stderr.write("Error: " + sanitizeTerminal(message) + "\n");
|
|
1373
|
+
}
|
|
1374
|
+
process.exit(code);
|
|
1375
|
+
}
|
|
1376
|
+
function success(message) {
|
|
1377
|
+
if (hasColor()) {
|
|
1378
|
+
process.stdout.write(chalk.green("\u2713 ") + sanitizeTerminal(message) + "\n");
|
|
1379
|
+
} else {
|
|
1380
|
+
process.stdout.write("OK: " + sanitizeTerminal(message) + "\n");
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
function warn(message) {
|
|
1384
|
+
if (hasColor()) {
|
|
1385
|
+
process.stderr.write(chalk.yellow("Warning: ") + sanitizeTerminal(message) + "\n");
|
|
1386
|
+
} else {
|
|
1387
|
+
process.stderr.write("Warning: " + sanitizeTerminal(message) + "\n");
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
function outputJSON(data) {
|
|
1391
|
+
process.stdout.write(JSON.stringify(data, null, 2) + "\n");
|
|
1392
|
+
}
|
|
1393
|
+
function getNestedValue(obj, key) {
|
|
1394
|
+
const parts = key.split(".");
|
|
1395
|
+
let cur = obj;
|
|
1396
|
+
for (const part of parts) {
|
|
1397
|
+
if (cur == null || typeof cur !== "object") return void 0;
|
|
1398
|
+
cur = cur[part];
|
|
1399
|
+
}
|
|
1400
|
+
return cur;
|
|
1401
|
+
}
|
|
1402
|
+
function cellValue(col, row) {
|
|
1403
|
+
const raw = col.format ? col.format(getNestedValue(row, col.key), row) : String(getNestedValue(row, col.key) ?? "");
|
|
1404
|
+
return cellText(raw);
|
|
1405
|
+
}
|
|
1406
|
+
function padEnd(str, len) {
|
|
1407
|
+
const visual = stripAnsi(str).length;
|
|
1408
|
+
const pad = Math.max(0, len - visual);
|
|
1409
|
+
return str + " ".repeat(pad);
|
|
1410
|
+
}
|
|
1411
|
+
function padStart(str, len) {
|
|
1412
|
+
const visual = stripAnsi(str).length;
|
|
1413
|
+
const pad = Math.max(0, len - visual);
|
|
1414
|
+
return " ".repeat(pad) + str;
|
|
1415
|
+
}
|
|
1416
|
+
function outputTable(rows, columns) {
|
|
1417
|
+
if (rows.length === 0) {
|
|
1418
|
+
process.stdout.write(" (no results)\n");
|
|
1419
|
+
return;
|
|
1420
|
+
}
|
|
1421
|
+
const widths = columns.map((col) => {
|
|
1422
|
+
let max = stripAnsi(col.header).length;
|
|
1423
|
+
for (const row of rows) {
|
|
1424
|
+
const vis = stripAnsi(cellValue(col, row)).length;
|
|
1425
|
+
if (vis > max) max = vis;
|
|
1426
|
+
}
|
|
1427
|
+
if (col.width) max = Math.min(max, col.width);
|
|
1428
|
+
return max;
|
|
1429
|
+
});
|
|
1430
|
+
const sep = "\u2500".repeat(widths.reduce((s, w) => s + w + 2, 1));
|
|
1431
|
+
let header = " ";
|
|
1432
|
+
for (let i = 0; i < columns.length; i++) {
|
|
1433
|
+
const col = columns[i];
|
|
1434
|
+
const hdr = cellText(col.header);
|
|
1435
|
+
const h = col.align === "right" ? padStart(hdr, widths[i]) : padEnd(hdr, widths[i]);
|
|
1436
|
+
header += (hasColor() ? chalk.dim(h) : h) + " ";
|
|
1437
|
+
}
|
|
1438
|
+
process.stdout.write(" " + (hasColor() ? chalk.dim(sep) : sep) + "\n");
|
|
1439
|
+
process.stdout.write(header.trimEnd() + "\n");
|
|
1440
|
+
process.stdout.write(" " + (hasColor() ? chalk.dim(sep) : sep) + "\n");
|
|
1441
|
+
for (const row of rows) {
|
|
1442
|
+
let line = " ";
|
|
1443
|
+
for (let i = 0; i < columns.length; i++) {
|
|
1444
|
+
const col = columns[i];
|
|
1445
|
+
let val = cellValue(col, row);
|
|
1446
|
+
const vis = stripAnsi(val).length;
|
|
1447
|
+
if (col.width && vis > col.width) {
|
|
1448
|
+
val = val.slice(0, col.width - 1) + "\u2026";
|
|
1449
|
+
}
|
|
1450
|
+
const cell = col.align === "right" ? padStart(val, widths[i]) : padEnd(val, widths[i]);
|
|
1451
|
+
line += cell + " ";
|
|
1452
|
+
}
|
|
1453
|
+
process.stdout.write(line.trimEnd() + "\n");
|
|
1454
|
+
}
|
|
1455
|
+
process.stdout.write(" " + (hasColor() ? chalk.dim(sep) : sep) + "\n");
|
|
1456
|
+
}
|
|
1457
|
+
function outputTSV(rows, columns) {
|
|
1458
|
+
process.stdout.write(columns.map((c) => stripControlChars(c.header).replace(/[\t\r\n]+/g, " ")).join(" ") + "\n");
|
|
1459
|
+
for (const row of rows) {
|
|
1460
|
+
const line = columns.map((col) => stripAnsi(cellValue(col, row)));
|
|
1461
|
+
process.stdout.write(line.join(" ") + "\n");
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
function outputCSV(rows, columns) {
|
|
1465
|
+
process.stdout.write(columns.map((c) => csvCell(stripControlChars(c.header))).join(",") + "\n");
|
|
1466
|
+
for (const row of rows) {
|
|
1467
|
+
const line = columns.map((col) => {
|
|
1468
|
+
const val = stripAnsi(cellValue(col, row));
|
|
1469
|
+
return val === "-" ? '"-"' : csvCell(val);
|
|
1470
|
+
});
|
|
1471
|
+
process.stdout.write(line.join(",") + "\n");
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
function outputIds(ids) {
|
|
1475
|
+
for (const id of ids) {
|
|
1476
|
+
process.stdout.write(sanitizeTerminal(id).replace(/[\r\n]+/g, " ") + "\n");
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
function paginationFooter(page, limit, total) {
|
|
1480
|
+
const from = (page - 1) * limit + 1;
|
|
1481
|
+
const to = Math.min(page * limit, total);
|
|
1482
|
+
const msg = ` Showing ${from}-${to} of ${total}`;
|
|
1483
|
+
process.stdout.write("\n" + (hasColor() ? chalk.dim(msg) : msg) + "\n");
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
export {
|
|
1487
|
+
money,
|
|
1488
|
+
bankAccountTypes,
|
|
1489
|
+
units,
|
|
1490
|
+
deliveryMethods,
|
|
1491
|
+
moneyStringSchema,
|
|
1492
|
+
paymentAllocationSchema,
|
|
1493
|
+
itcBlockReasons,
|
|
1494
|
+
stripControlChars,
|
|
1495
|
+
isInteractive,
|
|
1496
|
+
hasColor,
|
|
1497
|
+
stripAnsi,
|
|
1498
|
+
sanitizeTerminal,
|
|
1499
|
+
installTerminalSanitizer,
|
|
1500
|
+
getWidthTier,
|
|
1501
|
+
termWidth,
|
|
1502
|
+
EXIT,
|
|
1503
|
+
fatalError,
|
|
1504
|
+
success,
|
|
1505
|
+
warn,
|
|
1506
|
+
outputJSON,
|
|
1507
|
+
outputTable,
|
|
1508
|
+
outputTSV,
|
|
1509
|
+
outputCSV,
|
|
1510
|
+
outputIds,
|
|
1511
|
+
paginationFooter
|
|
1512
|
+
};
|