@tallyui/core 3.20.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-XF3RD6GX.js +515 -0
- package/dist/index.d.ts +41 -47
- package/dist/index.js +119 -101
- package/dist/server/index.cjs +1923 -0
- package/dist/server/index.d.cts +1039 -0
- package/dist/server/index.d.ts +46 -48
- package/dist/server/index.js +516 -206
- package/dist/{command-result-E_nH57WD.d.ts → tax-rate-DCJhfJbZ.d.ts} +442 -26
- package/package.json +10 -5
- package/src/commands.ts +12 -0
- package/src/context/money-format-context.tsx +50 -0
- package/src/coupons/woocommerce/to-coupon-configs.ts +5 -8
- package/src/fnv1a32.ts +14 -0
- package/src/index.ts +18 -5
- package/src/known-warnings.ts +23 -0
- package/src/money.ts +85 -2
- package/src/server/batch.ts +63 -27
- package/src/server/command-result.ts +28 -1
- package/src/server/display-signalling/contract.ts +203 -78
- package/src/server/display-signalling/memory-server.ts +71 -23
- package/src/server/fiscal-figures.ts +1 -1
- package/src/server/index.ts +5 -1
- package/src/server/money.ts +4 -1
- package/src/server/order-payload-shape.ts +96 -5
- package/src/server/refund-payload-shape.ts +5 -11
- package/src/server/register-payload-shape.ts +6 -12
- package/src/server/rejection-codes.ts +4 -4
- package/src/server/reopen-payload-shape.ts +25 -0
- package/src/server/shape-errors.ts +17 -0
- package/src/server/tax-rate.ts +13 -0
- package/src/server/update-payload-shape.ts +51 -0
- package/src/server/versions.ts +9 -2
- package/src/types/closures.ts +34 -0
- package/src/types/commands.ts +93 -8
- package/src/types/connector.ts +37 -4
- package/src/types/display-signalling.ts +30 -14
- package/src/types/index.ts +6 -3
- package/src/types/orders.ts +25 -3
- package/src/types/payment-methods.ts +17 -0
- package/src/types/stock.ts +2 -0
- package/src/types/store-settings.ts +7 -0
- package/src/types/traits/product.ts +19 -0
- package/dist/chunk-27L7XLTT.js +0 -235
package/dist/chunk-27L7XLTT.js
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
// src/types/display-signalling.ts
|
|
2
|
-
var DISPLAY_PAIR_CAPABILITY = "customer_display.pair";
|
|
3
|
-
var DisplaySignallingError = class extends Error {
|
|
4
|
-
code;
|
|
5
|
-
constructor(code, message = code) {
|
|
6
|
-
super(message);
|
|
7
|
-
this.name = "DisplaySignallingError";
|
|
8
|
-
this.code = code;
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
// src/customer-display/rate-limit-source.ts
|
|
13
|
-
var IPV4 = /^(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}$/;
|
|
14
|
-
var HEXTET = /^[0-9a-f]{1,4}$/;
|
|
15
|
-
function expandIpv6(address) {
|
|
16
|
-
let text = address.toLowerCase();
|
|
17
|
-
const last = text.slice(text.lastIndexOf(":") + 1);
|
|
18
|
-
if (IPV4.test(last)) {
|
|
19
|
-
const [a, b, c, d] = last.split(".").map(Number);
|
|
20
|
-
text = `${text.slice(0, text.length - last.length)}${(a << 8 | b).toString(16)}:${(c << 8 | d).toString(16)}`;
|
|
21
|
-
}
|
|
22
|
-
const halves = text.split("::");
|
|
23
|
-
if (halves.length > 2) return void 0;
|
|
24
|
-
const head = halves[0] ? halves[0].split(":") : [];
|
|
25
|
-
const tail = halves.length === 2 && halves[1] ? halves[1].split(":") : [];
|
|
26
|
-
const missing = 8 - head.length - tail.length;
|
|
27
|
-
if (halves.length === 2 ? missing < 1 : missing !== 0) return void 0;
|
|
28
|
-
const groups = [...head, ...Array(missing).fill("0"), ...tail];
|
|
29
|
-
if (!groups.every((group) => HEXTET.test(group))) return void 0;
|
|
30
|
-
return groups.map((group) => group.padStart(4, "0"));
|
|
31
|
-
}
|
|
32
|
-
function rateLimitSource(address) {
|
|
33
|
-
const input = address.trim();
|
|
34
|
-
if (IPV4.test(input)) return input;
|
|
35
|
-
const zone = input.indexOf("%");
|
|
36
|
-
const hextets = expandIpv6(zone >= 0 ? input.slice(0, zone) : input);
|
|
37
|
-
if (!hextets) return input;
|
|
38
|
-
if (hextets.slice(0, 5).every((group) => group === "0000") && hextets[5] === "ffff") {
|
|
39
|
-
const high = parseInt(hextets[6], 16);
|
|
40
|
-
const low = parseInt(hextets[7], 16);
|
|
41
|
-
return [high >> 8, high & 255, low >> 8, low & 255].join(".");
|
|
42
|
-
}
|
|
43
|
-
return `${hextets.slice(0, 4).join(":")}::/64`;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// src/commands.ts
|
|
47
|
-
var COMMANDS_PATH = "/tally/v1/commands";
|
|
48
|
-
var PROTOCOL_HEADER = "X-Tally-Protocol";
|
|
49
|
-
var PROTOCOL_VERSION = 1;
|
|
50
|
-
var MAX_COMMANDS_PER_BATCH = 50;
|
|
51
|
-
var ORDER_NOTE_MAX = 1e3;
|
|
52
|
-
function isCommandBatchResponse(value) {
|
|
53
|
-
return typeof value === "object" && value !== null && "results" in value && Array.isArray(value.results) && value.results.every(
|
|
54
|
-
(result) => typeof result === "object" && result !== null && "id" in result && typeof result.id === "string" && "status" in result && (result.status === "applied" || result.status === "duplicate" || result.status === "rejected")
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// src/server/command-result.ts
|
|
59
|
-
var CommandResultError = class extends Error {
|
|
60
|
-
constructor(message) {
|
|
61
|
-
super(message);
|
|
62
|
-
this.name = "CommandResultError";
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
function parseCommandResult(value) {
|
|
66
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
67
|
-
throw new CommandResultError("Invalid result: expected object");
|
|
68
|
-
}
|
|
69
|
-
const input = value;
|
|
70
|
-
if (typeof input.id !== "string" || input.id.length === 0) {
|
|
71
|
-
throw new CommandResultError("Invalid id");
|
|
72
|
-
}
|
|
73
|
-
if (input.status !== "applied" && input.status !== "duplicate" && input.status !== "rejected") {
|
|
74
|
-
throw new CommandResultError("Invalid status");
|
|
75
|
-
}
|
|
76
|
-
const result = { id: input.id, status: input.status };
|
|
77
|
-
const object = (value2) => typeof value2 === "object" && value2 !== null && (Object.getPrototypeOf(value2) === Object.prototype || Object.getPrototypeOf(value2) === null);
|
|
78
|
-
if (input.serverRefs !== void 0) {
|
|
79
|
-
if (typeof input.serverRefs !== "object" || input.serverRefs === null || Array.isArray(input.serverRefs)) {
|
|
80
|
-
throw new CommandResultError("Invalid serverRefs");
|
|
81
|
-
}
|
|
82
|
-
const refs = input.serverRefs;
|
|
83
|
-
if (typeof refs.orderId !== "string" || refs.orderId.length === 0) {
|
|
84
|
-
throw new CommandResultError("Invalid serverRefs.orderId");
|
|
85
|
-
}
|
|
86
|
-
if (refs.displayId !== void 0 && typeof refs.displayId !== "string") {
|
|
87
|
-
throw new CommandResultError("Invalid serverRefs.displayId");
|
|
88
|
-
}
|
|
89
|
-
if (!Number.isSafeInteger(refs.totalMinor)) {
|
|
90
|
-
throw new CommandResultError("Invalid serverRefs.totalMinor");
|
|
91
|
-
}
|
|
92
|
-
result.serverRefs = { orderId: refs.orderId, totalMinor: refs.totalMinor };
|
|
93
|
-
if (refs.displayId !== void 0) result.serverRefs.displayId = refs.displayId;
|
|
94
|
-
}
|
|
95
|
-
if (input.register !== void 0) {
|
|
96
|
-
if (!object(input.register)) throw new CommandResultError("Invalid register");
|
|
97
|
-
result.register = input.register;
|
|
98
|
-
}
|
|
99
|
-
if (input.refund !== void 0) {
|
|
100
|
-
if (!object(input.refund)) throw new CommandResultError("Invalid refund");
|
|
101
|
-
const refund = input.refund;
|
|
102
|
-
if (!Number.isSafeInteger(refund.totalMinor) || refund.totalMinor < 0) throw new CommandResultError("Invalid refund.totalMinor");
|
|
103
|
-
if (!object(refund.byMethod)) throw new CommandResultError("Invalid refund.byMethod");
|
|
104
|
-
const byMethod = Object.fromEntries(Object.entries(refund.byMethod).map(([key, amount]) => {
|
|
105
|
-
if (!key.length) throw new CommandResultError("Invalid refund.byMethod");
|
|
106
|
-
if (!Number.isSafeInteger(amount) || amount < 0) throw new CommandResultError(`Invalid refund.byMethod.${key}`);
|
|
107
|
-
return [key, amount];
|
|
108
|
-
}));
|
|
109
|
-
if (Object.values(byMethod).reduce((sum, amount) => sum + amount, 0) !== refund.totalMinor) throw new CommandResultError("Invalid refund.byMethod");
|
|
110
|
-
if (!Array.isArray(refund.refunds) || refund.refunds.length === 0) throw new CommandResultError("Invalid refund.refunds");
|
|
111
|
-
const refunds = refund.refunds.map((value2, index) => {
|
|
112
|
-
const field = `refund.refunds[${index}]`;
|
|
113
|
-
if (!object(value2)) throw new CommandResultError(`Invalid ${field}`);
|
|
114
|
-
const entry = value2;
|
|
115
|
-
for (const key of ["id", "paymentId"]) {
|
|
116
|
-
if (typeof entry[key] !== "string" || entry[key].length === 0) throw new CommandResultError(`Invalid ${field}.${key}`);
|
|
117
|
-
}
|
|
118
|
-
if (!Number.isSafeInteger(entry.totalMinor) || entry.totalMinor < 0) throw new CommandResultError(`Invalid ${field}.totalMinor`);
|
|
119
|
-
if (typeof entry.state !== "string" || entry.state.length === 0) throw new CommandResultError(`Invalid ${field}.state`);
|
|
120
|
-
return { id: entry.id, paymentId: entry.paymentId, totalMinor: entry.totalMinor, state: entry.state };
|
|
121
|
-
});
|
|
122
|
-
if (refunds.reduce((sum, entry) => sum + entry.totalMinor, 0) !== refund.totalMinor) throw new CommandResultError("Invalid refund.refunds");
|
|
123
|
-
result.refund = { totalMinor: refund.totalMinor, byMethod, refunds };
|
|
124
|
-
}
|
|
125
|
-
if (result.status === "applied" && result.serverRefs === void 0 && result.register === void 0 && result.refund === void 0) {
|
|
126
|
-
throw new CommandResultError("Invalid serverRefs: required for applied");
|
|
127
|
-
}
|
|
128
|
-
if (input.warnings !== void 0) {
|
|
129
|
-
if (!Array.isArray(input.warnings)) {
|
|
130
|
-
throw new CommandResultError("Invalid warnings");
|
|
131
|
-
}
|
|
132
|
-
result.warnings = input.warnings.map((warning, index) => {
|
|
133
|
-
const field = `warnings[${index}]`;
|
|
134
|
-
if (typeof warning !== "object" || warning === null || Array.isArray(warning)) {
|
|
135
|
-
throw new CommandResultError(`Invalid ${field}`);
|
|
136
|
-
}
|
|
137
|
-
const item = warning;
|
|
138
|
-
if (item.code === "total_mismatch") {
|
|
139
|
-
for (const key of ["expectedMinor", "serverMinor"]) {
|
|
140
|
-
if (!Number.isInteger(item[key])) {
|
|
141
|
-
throw new CommandResultError(`Invalid ${field}.${key}`);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
if (item.bridgeMinor != null && !Number.isSafeInteger(item.bridgeMinor)) {
|
|
145
|
-
throw new CommandResultError(`Invalid ${field}.bridgeMinor`);
|
|
146
|
-
}
|
|
147
|
-
return item.bridgeMinor != null ? { code: item.code, expectedMinor: item.expectedMinor, serverMinor: item.serverMinor, bridgeMinor: item.bridgeMinor } : { code: item.code, expectedMinor: item.expectedMinor, serverMinor: item.serverMinor };
|
|
148
|
-
}
|
|
149
|
-
if (item.code === "insufficient_stock") {
|
|
150
|
-
if (typeof item.variantId !== "string" || item.variantId.length === 0) {
|
|
151
|
-
throw new CommandResultError(`Invalid ${field}.variantId`);
|
|
152
|
-
}
|
|
153
|
-
if (!Number.isInteger(item.quantity) || item.quantity < 1) {
|
|
154
|
-
throw new CommandResultError(`Invalid ${field}.quantity`);
|
|
155
|
-
}
|
|
156
|
-
return { code: item.code, variantId: item.variantId, quantity: item.quantity };
|
|
157
|
-
}
|
|
158
|
-
if (item.code === "tax_rate_mismatch") {
|
|
159
|
-
if (!Number.isSafeInteger(item.ratePpm) || item.ratePpm < 0) {
|
|
160
|
-
throw new CommandResultError(`Invalid ${field}.ratePpm`);
|
|
161
|
-
}
|
|
162
|
-
for (const key of ["expectedMinor", "serverMinor"]) {
|
|
163
|
-
if (!Number.isSafeInteger(item[key])) {
|
|
164
|
-
throw new CommandResultError(`Invalid ${field}.${key}`);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return { code: item.code, ratePpm: item.ratePpm, expectedMinor: item.expectedMinor, serverMinor: item.serverMinor };
|
|
168
|
-
}
|
|
169
|
-
if (item.code === "customer_ignored") {
|
|
170
|
-
if (typeof item.customerId !== "string" || item.customerId.length === 0 || item.customerId.length > 64) {
|
|
171
|
-
throw new CommandResultError(`Invalid ${field}.customerId`);
|
|
172
|
-
}
|
|
173
|
-
return { code: item.code, customerId: item.customerId };
|
|
174
|
-
}
|
|
175
|
-
if (item.code === "register_session_unknown") {
|
|
176
|
-
if (typeof item.sessionId !== "string" || item.sessionId.length === 0 || item.sessionId.length > 64) {
|
|
177
|
-
throw new CommandResultError(`Invalid ${field}.sessionId`);
|
|
178
|
-
}
|
|
179
|
-
return { code: item.code, sessionId: item.sessionId };
|
|
180
|
-
}
|
|
181
|
-
if (item.code === "figures_mismatch") {
|
|
182
|
-
if (!Array.isArray(item.fields) || item.fields.length === 0) throw new CommandResultError(`Invalid ${field}.fields`);
|
|
183
|
-
const seen = [];
|
|
184
|
-
return { code: item.code, fields: item.fields.map((value2, i) => {
|
|
185
|
-
const path = `${field}.fields[${i}]`;
|
|
186
|
-
if (typeof value2 !== "object" || value2 === null || Array.isArray(value2)) throw new CommandResultError(`Invalid ${path}`);
|
|
187
|
-
const entry = value2;
|
|
188
|
-
if (!["subtotalMinor", "taxMinor", "discountMinor"].includes(entry.field) || seen.includes(entry.field)) {
|
|
189
|
-
throw new CommandResultError(`Invalid ${path}.field`);
|
|
190
|
-
}
|
|
191
|
-
seen.push(entry.field);
|
|
192
|
-
if (!Number.isSafeInteger(entry.tillMinor)) throw new CommandResultError(`Invalid ${path}.tillMinor`);
|
|
193
|
-
if (!Number.isSafeInteger(entry.serverMinor) || entry.serverMinor === entry.tillMinor) throw new CommandResultError(`Invalid ${path}.serverMinor`);
|
|
194
|
-
return { field: entry.field, tillMinor: entry.tillMinor, serverMinor: entry.serverMinor };
|
|
195
|
-
}) };
|
|
196
|
-
}
|
|
197
|
-
throw new CommandResultError(`Invalid ${field}.code`);
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
if (input.error !== void 0) {
|
|
201
|
-
if (typeof input.error !== "object" || input.error === null || Array.isArray(input.error)) {
|
|
202
|
-
throw new CommandResultError("Invalid error");
|
|
203
|
-
}
|
|
204
|
-
const error = input.error;
|
|
205
|
-
if (typeof error.code !== "string" || error.code.length === 0) {
|
|
206
|
-
throw new CommandResultError("Invalid error.code");
|
|
207
|
-
}
|
|
208
|
-
if (typeof error.message !== "string") {
|
|
209
|
-
throw new CommandResultError("Invalid error.message");
|
|
210
|
-
}
|
|
211
|
-
result.error = { code: error.code, message: error.message };
|
|
212
|
-
if (error.data !== void 0) {
|
|
213
|
-
if (!object(error.data)) throw new CommandResultError("Invalid error.data");
|
|
214
|
-
result.error.data = error.data;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
if (result.status === "rejected" && result.error === void 0) {
|
|
218
|
-
throw new CommandResultError("Invalid error: required for rejected");
|
|
219
|
-
}
|
|
220
|
-
return result;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export {
|
|
224
|
-
DISPLAY_PAIR_CAPABILITY,
|
|
225
|
-
DisplaySignallingError,
|
|
226
|
-
rateLimitSource,
|
|
227
|
-
COMMANDS_PATH,
|
|
228
|
-
PROTOCOL_HEADER,
|
|
229
|
-
PROTOCOL_VERSION,
|
|
230
|
-
MAX_COMMANDS_PER_BATCH,
|
|
231
|
-
ORDER_NOTE_MAX,
|
|
232
|
-
isCommandBatchResponse,
|
|
233
|
-
CommandResultError,
|
|
234
|
-
parseCommandResult
|
|
235
|
-
};
|