@tallyui/core 4.2.0 → 5.1.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 → chunk-RPBSJ3FB.js} +62 -2
- package/dist/index.d.ts +10 -4
- package/dist/index.js +25 -7
- package/dist/{tax-rate-DCJhfJbZ.d.ts → refund-share-Cv_TgE1p.d.ts} +215 -3
- package/dist/server/index.cjs +323 -224
- package/dist/server/index.d.cts +109 -5
- package/dist/server/index.d.ts +25 -6
- package/dist/server/index.js +267 -225
- package/package.json +4 -1
- package/src/commands.ts +2 -0
- package/src/index.ts +9 -4
- package/src/order-filters.ts +14 -6
- package/src/server/batch-outcome.ts +7 -0
- package/src/server/batch.ts +26 -8
- package/src/server/command-result.ts +3 -1
- package/src/server/fiscal-figures.ts +13 -0
- package/src/server/index.ts +4 -2
- package/src/server/order-payload-shape.ts +12 -0
- package/src/server/refund-share.ts +92 -0
- package/src/server/round-ratio.ts +10 -0
- package/src/server/versions.ts +6 -2
- package/src/types/commands.ts +4 -1
- package/src/types/connector.ts +54 -1
- package/src/types/orders.ts +69 -2
package/dist/server/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
DISPLAY_PAIR_CAPABILITY,
|
|
4
4
|
DisplaySignallingError,
|
|
5
5
|
MAX_COMMANDS_PER_BATCH,
|
|
6
|
+
NEEDS_ADMIN_MESSAGE_MAX,
|
|
6
7
|
ORDER_LINE_SKU_MAX,
|
|
7
8
|
ORDER_META_KEY_MAX,
|
|
8
9
|
ORDER_META_MAX,
|
|
@@ -17,9 +18,12 @@ import {
|
|
|
17
18
|
minorToMajor,
|
|
18
19
|
minorUnitDigits,
|
|
19
20
|
parseCommandResult,
|
|
21
|
+
priceRefund,
|
|
20
22
|
rateLimitSource,
|
|
21
|
-
ratePpmFromPercent
|
|
22
|
-
|
|
23
|
+
ratePpmFromPercent,
|
|
24
|
+
refundableLines,
|
|
25
|
+
roundRatio
|
|
26
|
+
} from "../chunk-RPBSJ3FB.js";
|
|
23
27
|
import "../chunk-MLKGABMK.js";
|
|
24
28
|
|
|
25
29
|
// src/server/fingerprint.ts
|
|
@@ -90,6 +94,17 @@ function payloadShapeErrors(payload) {
|
|
|
90
94
|
const lineDiscounts = (Array.isArray(payload.lines) ? payload.lines : []).reduce((sum, line, index) => sum + (object(line) ? discount(line.discountMinor, `lines[${index}].discountMinor`) : 0n), 0n);
|
|
91
95
|
const orderDiscount = discount(payload.discountMinor, "discountMinor");
|
|
92
96
|
if (errors.length === 0) check2(orderDiscount === lineDiscounts, "discountMinor", "the sum of lines[].discountMinor");
|
|
97
|
+
if (payload.cashRoundings !== void 0) {
|
|
98
|
+
const entries = payload.cashRoundings;
|
|
99
|
+
check2(Array.isArray(entries) && entries.length <= 16, "cashRoundings", "an array of at most 16 entries");
|
|
100
|
+
if (Array.isArray(entries) && entries.length <= 16) for (const [index, entry] of entries.entries()) {
|
|
101
|
+
const path = `cashRoundings[${index}]`;
|
|
102
|
+
check2(object(entry), path, "an object");
|
|
103
|
+
if (!object(entry)) continue;
|
|
104
|
+
check2(typeof entry.paymentId === "string" && entry.paymentId.length > 0, `${path}.paymentId`, "a non-empty string");
|
|
105
|
+
check2(Number.isSafeInteger(entry.minor), `${path}.minor`, "a safe integer");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
93
108
|
if (payload.customer !== void 0 && payload.customer !== null) {
|
|
94
109
|
check2(object(payload.customer), "customer", "an object");
|
|
95
110
|
if (object(payload.customer) && payload.customer.email !== void 0) {
|
|
@@ -439,6 +454,17 @@ function fiscalFiguresErrors(payload) {
|
|
|
439
454
|
check2(!seen.has(line.clientLineId), `display.lines[${index}].clientLineId`, "no duplicate clientLineId");
|
|
440
455
|
seen.add(line.clientLineId);
|
|
441
456
|
});
|
|
457
|
+
if (!errors.length) {
|
|
458
|
+
const sum = (rows) => (rows ?? []).reduce((total, row) => total + BigInt(row.amountMinor), 0n);
|
|
459
|
+
const roundings = (payload.cashRoundings ?? []).reduce((total, entry) => total + BigInt(entry.minor), 0n);
|
|
460
|
+
check2(
|
|
461
|
+
BigInt(display.subtotalMinor) - BigInt(display.discountMinor) + sum(display.fees) + sum(display.shipping) + (display.taxInclusive ? 0n : BigInt(display.taxMinor)) + roundings === BigInt(display.totalMinor),
|
|
462
|
+
"display.totalMinor",
|
|
463
|
+
"subtotalMinor \u2212 discountMinor + fees + shipping (+ taxMinor when exclusive) + cashRoundings"
|
|
464
|
+
);
|
|
465
|
+
check2(sum(display.lines) === BigInt(display.subtotalMinor), "display.subtotalMinor", "the sum of display.lines[].amountMinor");
|
|
466
|
+
check2(BigInt(display.discountMinor) === BigInt(display.orderDiscountMinor) + display.lines.reduce((total, line) => total + sum(line.discounts), 0n) + sum(display.coupons), "display.discountMinor", "orderDiscountMinor + the line discount rows + the coupon rows");
|
|
467
|
+
}
|
|
442
468
|
try {
|
|
443
469
|
check2(display.exponent === currencyDecimals(payload.currency), "display.exponent", "the currency decimals");
|
|
444
470
|
} catch {
|
|
@@ -457,7 +483,7 @@ function fiscalFiguresErrors(payload) {
|
|
|
457
483
|
|
|
458
484
|
// src/server/versions.ts
|
|
459
485
|
var SUPPORTED_ORDER_CREATE_VERSIONS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
|
|
460
|
-
var SUPPORTED_REGISTER_VERSIONS = [1];
|
|
486
|
+
var SUPPORTED_REGISTER_VERSIONS = [1, 2, 3];
|
|
461
487
|
var SUPPORTED_ORDER_REFUND_VERSIONS = [1];
|
|
462
488
|
var SUPPORTED_ORDER_REOPEN_VERSIONS = [1];
|
|
463
489
|
var SUPPORTED_ORDER_UPDATE_VERSIONS = [1];
|
|
@@ -477,6 +503,224 @@ function shapeErrors() {
|
|
|
477
503
|
return { errors, check: check2, noNul };
|
|
478
504
|
}
|
|
479
505
|
|
|
506
|
+
// src/server/refund-payload-shape.ts
|
|
507
|
+
function refundPayloadErrors(payload) {
|
|
508
|
+
const { errors, check: check2, noNul } = shapeErrors();
|
|
509
|
+
if (!isPlainObject(payload)) return ["payload: expected an object"];
|
|
510
|
+
const fields = [
|
|
511
|
+
"clientRefundId",
|
|
512
|
+
"orderId",
|
|
513
|
+
"registerId",
|
|
514
|
+
"sessionId",
|
|
515
|
+
"clientOrderId",
|
|
516
|
+
"cashierRef",
|
|
517
|
+
"lines",
|
|
518
|
+
"shippingMinor",
|
|
519
|
+
"totalMinor",
|
|
520
|
+
"adjustmentMinor",
|
|
521
|
+
"destination",
|
|
522
|
+
"reason",
|
|
523
|
+
"createdAt"
|
|
524
|
+
];
|
|
525
|
+
for (const key of Object.keys(payload)) {
|
|
526
|
+
if (!fields.includes(key) && errors.length < 10) {
|
|
527
|
+
errors.push(`${key.includes("\0") ? JSON.stringify(key) : key}: unknown field for order.refund version 1`);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
for (const field of ["clientRefundId", "orderId", "registerId", "sessionId", "clientOrderId", "cashierRef"]) {
|
|
531
|
+
const value = payload[field];
|
|
532
|
+
if (["clientOrderId", "cashierRef"].includes(field) && value === void 0) continue;
|
|
533
|
+
check2(
|
|
534
|
+
typeof value === "string" && value.length > 0 && value.length <= 64,
|
|
535
|
+
field,
|
|
536
|
+
"a non-empty string of at most 64 characters"
|
|
537
|
+
);
|
|
538
|
+
noNul(value, field);
|
|
539
|
+
}
|
|
540
|
+
check2(Array.isArray(payload.lines) && payload.lines.length <= 500, "lines", "an array of at most 500 lines");
|
|
541
|
+
const seen = /* @__PURE__ */ new Set();
|
|
542
|
+
if (Array.isArray(payload.lines)) payload.lines.forEach((line, index) => {
|
|
543
|
+
const path = `lines[${index}]`;
|
|
544
|
+
if (!isPlainObject(line)) {
|
|
545
|
+
check2(false, path, "an object");
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
for (const key of Object.keys(line)) {
|
|
549
|
+
if (!["orderLineId", "quantity", "restock"].includes(key) && errors.length < 10) {
|
|
550
|
+
errors.push(`${path}.${key.includes("\0") ? JSON.stringify(key) : key}: unknown field for order.refund version 1`);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
check2(
|
|
554
|
+
typeof line.orderLineId === "string" && line.orderLineId.length > 0 && line.orderLineId.length <= 64,
|
|
555
|
+
`${path}.orderLineId`,
|
|
556
|
+
"a non-empty string of at most 64 characters"
|
|
557
|
+
);
|
|
558
|
+
noNul(line.orderLineId, `${path}.orderLineId`);
|
|
559
|
+
if (typeof line.orderLineId === "string") {
|
|
560
|
+
check2(!seen.has(line.orderLineId), `${path}.orderLineId`, "unique in lines");
|
|
561
|
+
seen.add(line.orderLineId);
|
|
562
|
+
}
|
|
563
|
+
check2(Number.isSafeInteger(line.quantity) && line.quantity >= 1, `${path}.quantity`, "a safe integer >= 1");
|
|
564
|
+
check2(typeof line.restock === "boolean", `${path}.restock`, "a boolean");
|
|
565
|
+
});
|
|
566
|
+
for (const field of ["shippingMinor", "totalMinor"]) {
|
|
567
|
+
check2(Number.isSafeInteger(payload[field]) && payload[field] >= 0, field, "a safe integer >= 0");
|
|
568
|
+
}
|
|
569
|
+
check2(Number.isSafeInteger(payload.adjustmentMinor), "adjustmentMinor", "a safe integer");
|
|
570
|
+
check2(payload.destination === "original_method" || payload.destination === "cash", "destination", "original_method or cash");
|
|
571
|
+
noNul(payload.destination, "destination");
|
|
572
|
+
check2(
|
|
573
|
+
typeof payload.reason === "string" && payload.reason.trim().length > 0 && payload.reason.length <= 500,
|
|
574
|
+
"reason",
|
|
575
|
+
"a non-empty string after trim of at most 500 characters"
|
|
576
|
+
);
|
|
577
|
+
noNul(payload.reason, "reason");
|
|
578
|
+
check2(
|
|
579
|
+
typeof payload.createdAt === "string" && payload.createdAt.length > 0 && !Number.isNaN(Date.parse(payload.createdAt)),
|
|
580
|
+
"createdAt",
|
|
581
|
+
"a valid date"
|
|
582
|
+
);
|
|
583
|
+
noNul(payload.createdAt, "createdAt");
|
|
584
|
+
return errors;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// src/server/register-payload-shape.ts
|
|
588
|
+
function registerPayloadErrors(type, payload) {
|
|
589
|
+
const { errors, check: check2, noNul } = shapeErrors();
|
|
590
|
+
if (!isPlainObject(payload)) return ["payload: expected an object"];
|
|
591
|
+
const string = (field, optional = false) => {
|
|
592
|
+
const value = payload[field];
|
|
593
|
+
if (optional && value === void 0) return;
|
|
594
|
+
check2(typeof value === "string" && (optional || value.length > 0), field, optional ? "a string" : "a non-empty string");
|
|
595
|
+
if (typeof value === "string" && (field.endsWith("Id") || field === "voids")) check2(value.length <= 64, field, "at most 64 characters");
|
|
596
|
+
if (typeof value === "string" && ["openedAt", "at", "createdAt", "closedAt"].includes(field)) {
|
|
597
|
+
check2(!Number.isNaN(Date.parse(value)), field, "a valid date");
|
|
598
|
+
}
|
|
599
|
+
noNul(value, field);
|
|
600
|
+
};
|
|
601
|
+
const integer = (field, min = -Infinity) => check2(Number.isSafeInteger(payload[field]) && payload[field] >= min, field, `a safe integer >= ${min}`);
|
|
602
|
+
const record = (field) => {
|
|
603
|
+
const value = payload[field];
|
|
604
|
+
check2(isPlainObject(value), field, "a record of integers");
|
|
605
|
+
if (isPlainObject(value)) for (const [key, amount] of Object.entries(value)) {
|
|
606
|
+
check2(key.length > 0 && Number.isSafeInteger(amount), `${field}.${key}`, "a non-empty key with a safe integer");
|
|
607
|
+
noNul(key, `${field}.${JSON.stringify(key)}`);
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
string("sessionId");
|
|
611
|
+
switch (type) {
|
|
612
|
+
case "register.session.open":
|
|
613
|
+
for (const field of ["registerId", "openedAt"]) string(field);
|
|
614
|
+
for (const field of ["storeKey", "businessDay", "openedBy"]) string(field, true);
|
|
615
|
+
if (payload.deviceName !== void 0) {
|
|
616
|
+
check2(
|
|
617
|
+
typeof payload.deviceName === "string" && payload.deviceName.trim().length >= 1 && payload.deviceName.trim().length <= 64,
|
|
618
|
+
"deviceName",
|
|
619
|
+
"a string of 1 to 64 characters after trim"
|
|
620
|
+
);
|
|
621
|
+
noNul(payload.deviceName, "deviceName");
|
|
622
|
+
}
|
|
623
|
+
if (payload.supersedes !== void 0) {
|
|
624
|
+
check2(
|
|
625
|
+
typeof payload.supersedes === "string" && payload.supersedes.length > 0 && payload.supersedes.length <= 64,
|
|
626
|
+
"supersedes",
|
|
627
|
+
"a non-empty string of at most 64 characters"
|
|
628
|
+
);
|
|
629
|
+
noNul(payload.supersedes, "supersedes");
|
|
630
|
+
}
|
|
631
|
+
integer("countedFloatMinor", 0);
|
|
632
|
+
for (const field of ["expectedFloatMinor", "openingVarianceMinor"]) if (payload[field] !== void 0) integer(field);
|
|
633
|
+
break;
|
|
634
|
+
case "register.session.transition":
|
|
635
|
+
string("at");
|
|
636
|
+
check2(["open", "counting", "closed"].includes(payload.status), "status", "open, counting or closed");
|
|
637
|
+
for (const field of ["counted", "closedBy", "approvedBy"]) if (payload[field] !== void 0) {
|
|
638
|
+
check2(payload.status === "closed", field, "a closing transition");
|
|
639
|
+
if (field === "counted") record(field);
|
|
640
|
+
else string(field, true);
|
|
641
|
+
}
|
|
642
|
+
break;
|
|
643
|
+
case "register.movement.record":
|
|
644
|
+
case "register.movement.void":
|
|
645
|
+
for (const field of ["movementId", "createdAt"]) string(field);
|
|
646
|
+
string("createdBy", true);
|
|
647
|
+
if (type === "register.movement.void") string("voids");
|
|
648
|
+
else {
|
|
649
|
+
check2(
|
|
650
|
+
typeof payload.reason === "string" && payload.reason.trim().length > 0 && payload.reason.length <= 500,
|
|
651
|
+
"reason",
|
|
652
|
+
"a non-empty string after trim of at most 500 characters"
|
|
653
|
+
);
|
|
654
|
+
noNul(payload.reason, "reason");
|
|
655
|
+
check2(["paid_in", "paid_out", "no_sale"].includes(payload.type), "type", "paid_in, paid_out or no_sale");
|
|
656
|
+
integer("amountMinor", payload.type === "no_sale" ? 0 : 1);
|
|
657
|
+
if (payload.type === "no_sale") check2(payload.amountMinor === 0, "amountMinor", "0 for no_sale");
|
|
658
|
+
}
|
|
659
|
+
break;
|
|
660
|
+
case "register.closure.submit":
|
|
661
|
+
for (const field of ["closureId", "registerId", "openedAt", "closedAt", "softwareVersion"]) string(field);
|
|
662
|
+
for (const field of ["businessDay", "closedBy", "approvedBy"]) string(field, true);
|
|
663
|
+
if (payload.approval !== void 0) {
|
|
664
|
+
check2(typeof payload.approval === "string" && payload.approval.length > 0, "approval", "a non-empty string");
|
|
665
|
+
noNul(payload.approval, "approval");
|
|
666
|
+
}
|
|
667
|
+
integer("number", 1);
|
|
668
|
+
for (const field of [
|
|
669
|
+
"periodSalesTotalMinor",
|
|
670
|
+
"periodRefundsTotalMinor",
|
|
671
|
+
"perpetualSalesTotalMinor",
|
|
672
|
+
"perpetualRefundsTotalMinor",
|
|
673
|
+
"unsyncedCount",
|
|
674
|
+
"unsyncedTotalMinor"
|
|
675
|
+
]) integer(field, 0);
|
|
676
|
+
for (const field of ["number", "unsyncedCount"])
|
|
677
|
+
check2(payload[field] <= 2147483647, field, "at most 2147483647");
|
|
678
|
+
for (const field of ["tillExpected", "counted"]) record(field);
|
|
679
|
+
for (const field of ["orderIds", "movementIds"]) {
|
|
680
|
+
const value = payload[field];
|
|
681
|
+
check2(Array.isArray(value), field, "an array of ids");
|
|
682
|
+
if (Array.isArray(value)) value.forEach((id, index) => {
|
|
683
|
+
check2(typeof id === "string" && id.length > 0 && id.length <= 64, `${field}[${index}]`, "a non-empty string of at most 64 characters");
|
|
684
|
+
noNul(id, `${field}[${index}]`);
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
break;
|
|
688
|
+
default:
|
|
689
|
+
check2(false, "type", "a register command type");
|
|
690
|
+
}
|
|
691
|
+
return errors;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
// src/server/reopen-payload-shape.ts
|
|
695
|
+
function reopenPayloadErrors(payload) {
|
|
696
|
+
const { errors, check: check2, noNul } = shapeErrors();
|
|
697
|
+
if (!isPlainObject(payload)) return ["payload: expected an object"];
|
|
698
|
+
const fields = ["orderId", "clientOrderId", "baseRevision", "cashierRef", "registerId", "storeId", "createdAt"];
|
|
699
|
+
for (const key of Object.keys(payload)) {
|
|
700
|
+
if (!fields.includes(key) && errors.length < 10) {
|
|
701
|
+
errors.push(`${key.includes("\0") ? JSON.stringify(key) : key}: unknown field for order.reopen version 1`);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
for (const field of ["orderId", "cashierRef", "registerId", "clientOrderId", "baseRevision", "storeId"]) {
|
|
705
|
+
const value = payload[field];
|
|
706
|
+
if (["clientOrderId", "baseRevision", "storeId"].includes(field) && value === void 0) continue;
|
|
707
|
+
const max = field === "baseRevision" ? 128 : 64;
|
|
708
|
+
check2(
|
|
709
|
+
typeof value === "string" && value.length > 0 && value.length <= max,
|
|
710
|
+
field,
|
|
711
|
+
`a non-empty string of at most ${max} characters`
|
|
712
|
+
);
|
|
713
|
+
noNul(value, field);
|
|
714
|
+
}
|
|
715
|
+
check2(
|
|
716
|
+
typeof payload.createdAt === "string" && payload.createdAt.length > 0 && !Number.isNaN(Date.parse(payload.createdAt)),
|
|
717
|
+
"createdAt",
|
|
718
|
+
"a valid date"
|
|
719
|
+
);
|
|
720
|
+
noNul(payload.createdAt, "createdAt");
|
|
721
|
+
return errors;
|
|
722
|
+
}
|
|
723
|
+
|
|
480
724
|
// src/server/update-payload-shape.ts
|
|
481
725
|
function updateOnlyErrors(payload) {
|
|
482
726
|
const { errors, check: check2 } = shapeErrors();
|
|
@@ -563,6 +807,7 @@ function validateBatch(body) {
|
|
|
563
807
|
}
|
|
564
808
|
var rejected = (id, code, message, data) => ({ id, status: "rejected", error: data === void 0 ? { code, message } : { code, message, data } });
|
|
565
809
|
var firstTen = (errors) => errors.slice(0, 10).join("; ");
|
|
810
|
+
var shapeRefusal = (id, errors) => errors.length ? rejected(id, "invalid_payload", firstTen(errors)) : void 0;
|
|
566
811
|
function unsupportedOptional(envelope, key, versions, noun) {
|
|
567
812
|
if (versions.includes(envelope.version)) return void 0;
|
|
568
813
|
return rejected(
|
|
@@ -576,8 +821,12 @@ function precheckCommand(envelope, supported) {
|
|
|
576
821
|
for (const key of ["orderCreate", "register"]) {
|
|
577
822
|
if (!supported[key]?.length) throw new TypeError(`precheckCommand: supported.${key} must list at least one version`);
|
|
578
823
|
}
|
|
579
|
-
if (envelope.type === "order.refund")
|
|
580
|
-
|
|
824
|
+
if (envelope.type === "order.refund") {
|
|
825
|
+
return unsupportedOptional(envelope, "orderRefund", supported.orderRefund ?? [], "refunds") ?? shapeRefusal(envelope.id, refundPayloadErrors(envelope.payload));
|
|
826
|
+
}
|
|
827
|
+
if (envelope.type === "order.reopen") {
|
|
828
|
+
return unsupportedOptional(envelope, "orderReopen", supported.orderReopen ?? [], "reopens") ?? shapeRefusal(envelope.id, reopenPayloadErrors(envelope.payload));
|
|
829
|
+
}
|
|
581
830
|
if (envelope.type === "order.update") {
|
|
582
831
|
const refusal = unsupportedOptional(envelope, "orderUpdate", supported.orderUpdate ?? [], "updates");
|
|
583
832
|
if (refusal) return refusal;
|
|
@@ -597,7 +846,7 @@ function precheckCommand(envelope, supported) {
|
|
|
597
846
|
{ register: Math.max(...supported.register) }
|
|
598
847
|
);
|
|
599
848
|
}
|
|
600
|
-
return
|
|
849
|
+
return shapeRefusal(envelope.id, registerPayloadErrors(envelope.type, envelope.payload));
|
|
601
850
|
}
|
|
602
851
|
const command = envelope;
|
|
603
852
|
if (!supported.orderCreate.includes(command.version)) {
|
|
@@ -608,6 +857,9 @@ function precheckCommand(envelope, supported) {
|
|
|
608
857
|
{ orderCreate: Math.max(...supported.orderCreate) }
|
|
609
858
|
);
|
|
610
859
|
}
|
|
860
|
+
if (command.payload.cashRoundings !== void 0 && supported.cashRounding !== true) {
|
|
861
|
+
return rejected(command.id, "invalid_payload", "cashRoundings requires the cashRounding capability, which this server does not declare");
|
|
862
|
+
}
|
|
611
863
|
const { lines, discountMinor } = command.payload;
|
|
612
864
|
const discounted = discountMinor !== void 0 || Array.isArray(lines) && lines.some((line) => line?.discountMinor !== void 0);
|
|
613
865
|
const payload = command.payload;
|
|
@@ -651,7 +903,7 @@ function precheckCommand(envelope, supported) {
|
|
|
651
903
|
return rejected(command.id, "invalid_payload", firstTen(bounds));
|
|
652
904
|
}
|
|
653
905
|
const shape = payloadShapeErrors(payload);
|
|
654
|
-
const errors =
|
|
906
|
+
const errors = shape.length ? shape : v3 && display !== void 0 && taxByRate !== void 0 ? fiscalFiguresErrors(payload) : [];
|
|
655
907
|
if (errors.length) {
|
|
656
908
|
return rejected(command.id, "invalid_payload", firstTen(errors));
|
|
657
909
|
}
|
|
@@ -662,6 +914,9 @@ function precheckCommand(envelope, supported) {
|
|
|
662
914
|
function inProgressOutcome(id) {
|
|
663
915
|
return { status: 409, body: { code: "in_progress", id } };
|
|
664
916
|
}
|
|
917
|
+
function needsAdminOutcome(id, reason, message) {
|
|
918
|
+
return { status: 409, body: { code: "needs_admin", id, reason, message: message.slice(0, NEEDS_ADMIN_MESSAGE_MAX) } };
|
|
919
|
+
}
|
|
665
920
|
function transientOutcome(id) {
|
|
666
921
|
return { status: 503, body: { code: "transient", id, message: "Temporary failure, retry later." } };
|
|
667
922
|
}
|
|
@@ -671,224 +926,6 @@ function totalWarnings(expectedMinor, serverMinor) {
|
|
|
671
926
|
return serverMinor === expectedMinor ? [] : [{ code: "total_mismatch", expectedMinor, serverMinor }];
|
|
672
927
|
}
|
|
673
928
|
|
|
674
|
-
// src/server/register-payload-shape.ts
|
|
675
|
-
function registerPayloadErrors(type, payload) {
|
|
676
|
-
const { errors, check: check2, noNul } = shapeErrors();
|
|
677
|
-
if (!isPlainObject(payload)) return ["payload: expected an object"];
|
|
678
|
-
const string = (field, optional = false) => {
|
|
679
|
-
const value = payload[field];
|
|
680
|
-
if (optional && value === void 0) return;
|
|
681
|
-
check2(typeof value === "string" && (optional || value.length > 0), field, optional ? "a string" : "a non-empty string");
|
|
682
|
-
if (typeof value === "string" && (field.endsWith("Id") || field === "voids")) check2(value.length <= 64, field, "at most 64 characters");
|
|
683
|
-
if (typeof value === "string" && ["openedAt", "at", "createdAt", "closedAt"].includes(field)) {
|
|
684
|
-
check2(!Number.isNaN(Date.parse(value)), field, "a valid date");
|
|
685
|
-
}
|
|
686
|
-
noNul(value, field);
|
|
687
|
-
};
|
|
688
|
-
const integer = (field, min = -Infinity) => check2(Number.isSafeInteger(payload[field]) && payload[field] >= min, field, `a safe integer >= ${min}`);
|
|
689
|
-
const record = (field) => {
|
|
690
|
-
const value = payload[field];
|
|
691
|
-
check2(isPlainObject(value), field, "a record of integers");
|
|
692
|
-
if (isPlainObject(value)) for (const [key, amount] of Object.entries(value)) {
|
|
693
|
-
check2(key.length > 0 && Number.isSafeInteger(amount), `${field}.${key}`, "a non-empty key with a safe integer");
|
|
694
|
-
noNul(key, `${field}.${JSON.stringify(key)}`);
|
|
695
|
-
}
|
|
696
|
-
};
|
|
697
|
-
string("sessionId");
|
|
698
|
-
switch (type) {
|
|
699
|
-
case "register.session.open":
|
|
700
|
-
for (const field of ["registerId", "openedAt"]) string(field);
|
|
701
|
-
for (const field of ["storeKey", "businessDay", "openedBy"]) string(field, true);
|
|
702
|
-
if (payload.deviceName !== void 0) {
|
|
703
|
-
check2(
|
|
704
|
-
typeof payload.deviceName === "string" && payload.deviceName.trim().length >= 1 && payload.deviceName.trim().length <= 64,
|
|
705
|
-
"deviceName",
|
|
706
|
-
"a string of 1 to 64 characters after trim"
|
|
707
|
-
);
|
|
708
|
-
noNul(payload.deviceName, "deviceName");
|
|
709
|
-
}
|
|
710
|
-
if (payload.supersedes !== void 0) {
|
|
711
|
-
check2(
|
|
712
|
-
typeof payload.supersedes === "string" && payload.supersedes.length > 0 && payload.supersedes.length <= 64,
|
|
713
|
-
"supersedes",
|
|
714
|
-
"a non-empty string of at most 64 characters"
|
|
715
|
-
);
|
|
716
|
-
noNul(payload.supersedes, "supersedes");
|
|
717
|
-
}
|
|
718
|
-
integer("countedFloatMinor", 0);
|
|
719
|
-
for (const field of ["expectedFloatMinor", "openingVarianceMinor"]) if (payload[field] !== void 0) integer(field);
|
|
720
|
-
break;
|
|
721
|
-
case "register.session.transition":
|
|
722
|
-
string("at");
|
|
723
|
-
check2(["open", "counting", "closed"].includes(payload.status), "status", "open, counting or closed");
|
|
724
|
-
for (const field of ["counted", "closedBy", "approvedBy"]) if (payload[field] !== void 0) {
|
|
725
|
-
check2(payload.status === "closed", field, "a closing transition");
|
|
726
|
-
if (field === "counted") record(field);
|
|
727
|
-
else string(field, true);
|
|
728
|
-
}
|
|
729
|
-
break;
|
|
730
|
-
case "register.movement.record":
|
|
731
|
-
case "register.movement.void":
|
|
732
|
-
for (const field of ["movementId", "createdAt"]) string(field);
|
|
733
|
-
string("createdBy", true);
|
|
734
|
-
if (type === "register.movement.void") string("voids");
|
|
735
|
-
else {
|
|
736
|
-
check2(
|
|
737
|
-
typeof payload.reason === "string" && payload.reason.trim().length > 0 && payload.reason.length <= 500,
|
|
738
|
-
"reason",
|
|
739
|
-
"a non-empty string after trim of at most 500 characters"
|
|
740
|
-
);
|
|
741
|
-
noNul(payload.reason, "reason");
|
|
742
|
-
check2(["paid_in", "paid_out", "no_sale"].includes(payload.type), "type", "paid_in, paid_out or no_sale");
|
|
743
|
-
integer("amountMinor", payload.type === "no_sale" ? 0 : 1);
|
|
744
|
-
if (payload.type === "no_sale") check2(payload.amountMinor === 0, "amountMinor", "0 for no_sale");
|
|
745
|
-
}
|
|
746
|
-
break;
|
|
747
|
-
case "register.closure.submit":
|
|
748
|
-
for (const field of ["closureId", "registerId", "openedAt", "closedAt", "softwareVersion"]) string(field);
|
|
749
|
-
for (const field of ["businessDay", "closedBy", "approvedBy"]) string(field, true);
|
|
750
|
-
if (payload.approval !== void 0) {
|
|
751
|
-
check2(typeof payload.approval === "string" && payload.approval.length > 0, "approval", "a non-empty string");
|
|
752
|
-
noNul(payload.approval, "approval");
|
|
753
|
-
}
|
|
754
|
-
integer("number", 1);
|
|
755
|
-
for (const field of [
|
|
756
|
-
"periodSalesTotalMinor",
|
|
757
|
-
"periodRefundsTotalMinor",
|
|
758
|
-
"perpetualSalesTotalMinor",
|
|
759
|
-
"perpetualRefundsTotalMinor",
|
|
760
|
-
"unsyncedCount",
|
|
761
|
-
"unsyncedTotalMinor"
|
|
762
|
-
]) integer(field, 0);
|
|
763
|
-
for (const field of ["number", "unsyncedCount"])
|
|
764
|
-
check2(payload[field] <= 2147483647, field, "at most 2147483647");
|
|
765
|
-
for (const field of ["tillExpected", "counted"]) record(field);
|
|
766
|
-
for (const field of ["orderIds", "movementIds"]) {
|
|
767
|
-
const value = payload[field];
|
|
768
|
-
check2(Array.isArray(value), field, "an array of ids");
|
|
769
|
-
if (Array.isArray(value)) value.forEach((id, index) => {
|
|
770
|
-
check2(typeof id === "string" && id.length > 0 && id.length <= 64, `${field}[${index}]`, "a non-empty string of at most 64 characters");
|
|
771
|
-
noNul(id, `${field}[${index}]`);
|
|
772
|
-
});
|
|
773
|
-
}
|
|
774
|
-
break;
|
|
775
|
-
default:
|
|
776
|
-
check2(false, "type", "a register command type");
|
|
777
|
-
}
|
|
778
|
-
return errors;
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
// src/server/refund-payload-shape.ts
|
|
782
|
-
function refundPayloadErrors(payload) {
|
|
783
|
-
const { errors, check: check2, noNul } = shapeErrors();
|
|
784
|
-
if (!isPlainObject(payload)) return ["payload: expected an object"];
|
|
785
|
-
const fields = [
|
|
786
|
-
"clientRefundId",
|
|
787
|
-
"orderId",
|
|
788
|
-
"registerId",
|
|
789
|
-
"sessionId",
|
|
790
|
-
"clientOrderId",
|
|
791
|
-
"cashierRef",
|
|
792
|
-
"lines",
|
|
793
|
-
"shippingMinor",
|
|
794
|
-
"totalMinor",
|
|
795
|
-
"adjustmentMinor",
|
|
796
|
-
"destination",
|
|
797
|
-
"reason",
|
|
798
|
-
"createdAt"
|
|
799
|
-
];
|
|
800
|
-
for (const key of Object.keys(payload)) {
|
|
801
|
-
if (!fields.includes(key) && errors.length < 10) {
|
|
802
|
-
errors.push(`${key.includes("\0") ? JSON.stringify(key) : key}: unknown field for order.refund version 1`);
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
for (const field of ["clientRefundId", "orderId", "registerId", "sessionId", "clientOrderId", "cashierRef"]) {
|
|
806
|
-
const value = payload[field];
|
|
807
|
-
if (["clientOrderId", "cashierRef"].includes(field) && value === void 0) continue;
|
|
808
|
-
check2(
|
|
809
|
-
typeof value === "string" && value.length > 0 && value.length <= 64,
|
|
810
|
-
field,
|
|
811
|
-
"a non-empty string of at most 64 characters"
|
|
812
|
-
);
|
|
813
|
-
noNul(value, field);
|
|
814
|
-
}
|
|
815
|
-
check2(Array.isArray(payload.lines) && payload.lines.length <= 500, "lines", "an array of at most 500 lines");
|
|
816
|
-
const seen = /* @__PURE__ */ new Set();
|
|
817
|
-
if (Array.isArray(payload.lines)) payload.lines.forEach((line, index) => {
|
|
818
|
-
const path = `lines[${index}]`;
|
|
819
|
-
if (!isPlainObject(line)) {
|
|
820
|
-
check2(false, path, "an object");
|
|
821
|
-
return;
|
|
822
|
-
}
|
|
823
|
-
for (const key of Object.keys(line)) {
|
|
824
|
-
if (!["orderLineId", "quantity", "restock"].includes(key) && errors.length < 10) {
|
|
825
|
-
errors.push(`${path}.${key.includes("\0") ? JSON.stringify(key) : key}: unknown field for order.refund version 1`);
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
check2(
|
|
829
|
-
typeof line.orderLineId === "string" && line.orderLineId.length > 0 && line.orderLineId.length <= 64,
|
|
830
|
-
`${path}.orderLineId`,
|
|
831
|
-
"a non-empty string of at most 64 characters"
|
|
832
|
-
);
|
|
833
|
-
noNul(line.orderLineId, `${path}.orderLineId`);
|
|
834
|
-
if (typeof line.orderLineId === "string") {
|
|
835
|
-
check2(!seen.has(line.orderLineId), `${path}.orderLineId`, "unique in lines");
|
|
836
|
-
seen.add(line.orderLineId);
|
|
837
|
-
}
|
|
838
|
-
check2(Number.isSafeInteger(line.quantity) && line.quantity >= 1, `${path}.quantity`, "a safe integer >= 1");
|
|
839
|
-
check2(typeof line.restock === "boolean", `${path}.restock`, "a boolean");
|
|
840
|
-
});
|
|
841
|
-
for (const field of ["shippingMinor", "totalMinor"]) {
|
|
842
|
-
check2(Number.isSafeInteger(payload[field]) && payload[field] >= 0, field, "a safe integer >= 0");
|
|
843
|
-
}
|
|
844
|
-
check2(Number.isSafeInteger(payload.adjustmentMinor), "adjustmentMinor", "a safe integer");
|
|
845
|
-
check2(payload.destination === "original_method" || payload.destination === "cash", "destination", "original_method or cash");
|
|
846
|
-
noNul(payload.destination, "destination");
|
|
847
|
-
check2(
|
|
848
|
-
typeof payload.reason === "string" && payload.reason.trim().length > 0 && payload.reason.length <= 500,
|
|
849
|
-
"reason",
|
|
850
|
-
"a non-empty string after trim of at most 500 characters"
|
|
851
|
-
);
|
|
852
|
-
noNul(payload.reason, "reason");
|
|
853
|
-
check2(
|
|
854
|
-
typeof payload.createdAt === "string" && payload.createdAt.length > 0 && !Number.isNaN(Date.parse(payload.createdAt)),
|
|
855
|
-
"createdAt",
|
|
856
|
-
"a valid date"
|
|
857
|
-
);
|
|
858
|
-
noNul(payload.createdAt, "createdAt");
|
|
859
|
-
return errors;
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
// src/server/reopen-payload-shape.ts
|
|
863
|
-
function reopenPayloadErrors(payload) {
|
|
864
|
-
const { errors, check: check2, noNul } = shapeErrors();
|
|
865
|
-
if (!isPlainObject(payload)) return ["payload: expected an object"];
|
|
866
|
-
const fields = ["orderId", "clientOrderId", "baseRevision", "cashierRef", "registerId", "storeId", "createdAt"];
|
|
867
|
-
for (const key of Object.keys(payload)) {
|
|
868
|
-
if (!fields.includes(key) && errors.length < 10) {
|
|
869
|
-
errors.push(`${key.includes("\0") ? JSON.stringify(key) : key}: unknown field for order.reopen version 1`);
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
for (const field of ["orderId", "cashierRef", "registerId", "clientOrderId", "baseRevision", "storeId"]) {
|
|
873
|
-
const value = payload[field];
|
|
874
|
-
if (["clientOrderId", "baseRevision", "storeId"].includes(field) && value === void 0) continue;
|
|
875
|
-
const max = field === "baseRevision" ? 128 : 64;
|
|
876
|
-
check2(
|
|
877
|
-
typeof value === "string" && value.length > 0 && value.length <= max,
|
|
878
|
-
field,
|
|
879
|
-
`a non-empty string of at most ${max} characters`
|
|
880
|
-
);
|
|
881
|
-
noNul(value, field);
|
|
882
|
-
}
|
|
883
|
-
check2(
|
|
884
|
-
typeof payload.createdAt === "string" && payload.createdAt.length > 0 && !Number.isNaN(Date.parse(payload.createdAt)),
|
|
885
|
-
"createdAt",
|
|
886
|
-
"a valid date"
|
|
887
|
-
);
|
|
888
|
-
noNul(payload.createdAt, "createdAt");
|
|
889
|
-
return errors;
|
|
890
|
-
}
|
|
891
|
-
|
|
892
929
|
// src/server/rejection-codes.ts
|
|
893
930
|
function platformErrorResult(id, platformCode, platformMessage) {
|
|
894
931
|
return { id, status: "rejected", error: { code: "platform_error", message: `${platformCode}: ${platformMessage}`, data: { platformCode, platformMessage } } };
|
|
@@ -1509,6 +1546,7 @@ function displaySignallingContract(makeHarness) {
|
|
|
1509
1546
|
export {
|
|
1510
1547
|
CommandResultError,
|
|
1511
1548
|
MAX_COMMANDS_PER_BATCH,
|
|
1549
|
+
NEEDS_ADMIN_MESSAGE_MAX,
|
|
1512
1550
|
ORDER_NOTE_MAX,
|
|
1513
1551
|
SUPPORTED_ORDER_CREATE_VERSIONS,
|
|
1514
1552
|
SUPPORTED_ORDER_REFUND_VERSIONS,
|
|
@@ -1528,15 +1566,19 @@ export {
|
|
|
1528
1566
|
majorToMinor,
|
|
1529
1567
|
minorToMajor,
|
|
1530
1568
|
minorUnitDigits,
|
|
1569
|
+
needsAdminOutcome,
|
|
1531
1570
|
parseCommandResult,
|
|
1532
1571
|
payloadBoundErrors,
|
|
1533
1572
|
payloadShapeErrors,
|
|
1534
1573
|
platformErrorResult,
|
|
1535
1574
|
precheckCommand,
|
|
1575
|
+
priceRefund,
|
|
1536
1576
|
ratePpmFromPercent,
|
|
1537
1577
|
refundPayloadErrors,
|
|
1578
|
+
refundableLines,
|
|
1538
1579
|
registerPayloadErrors,
|
|
1539
1580
|
reopenPayloadErrors,
|
|
1581
|
+
roundRatio,
|
|
1540
1582
|
totalWarnings,
|
|
1541
1583
|
transientOutcome,
|
|
1542
1584
|
updatePayloadErrors,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tallyui/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Core interfaces, traits, and context providers for Tally UI",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -51,6 +51,9 @@
|
|
|
51
51
|
"rxjs": ">=7"
|
|
52
52
|
},
|
|
53
53
|
"peerDependenciesMeta": {
|
|
54
|
+
"react": {
|
|
55
|
+
"optional": true
|
|
56
|
+
},
|
|
54
57
|
"rxdb": {
|
|
55
58
|
"optional": true
|
|
56
59
|
},
|
package/src/commands.ts
CHANGED
|
@@ -10,6 +10,8 @@ export const PROTOCOL_VERSION = 1;
|
|
|
10
10
|
export const MAX_COMMANDS_PER_BATCH = 50;
|
|
11
11
|
/** The longest order.create `note` (version 7, ADR-083), in UTF-16 code units. WCPOS v2's order note has no cap; this bounds the wire. */
|
|
12
12
|
export const ORDER_NOTE_MAX = 1000;
|
|
13
|
+
/** The most UTF-16 units of a `needs_admin` message the till keeps and shows (TallyUI #1280). */
|
|
14
|
+
export const NEEDS_ADMIN_MESSAGE_MAX = 500;
|
|
13
15
|
/** The most tax ids order.create 12 carries in `customer.taxIds` (ADR-092). */
|
|
14
16
|
export const ORDER_TAX_IDS_MAX = 10;
|
|
15
17
|
/** The longest order.create 12 tax id `type` (the connector's scheme id), in UTF-16 code units (ADR-092). */
|
package/src/index.ts
CHANGED
|
@@ -30,7 +30,7 @@ export type {
|
|
|
30
30
|
StoreTaxRate,
|
|
31
31
|
StoreTaxRateLocation,
|
|
32
32
|
} from './types';
|
|
33
|
-
export type { SignInResult, ServerCapabilities, TaxRounding } from './types/connector';
|
|
33
|
+
export type { SignInResult, ServerCapabilities, TaxRounding, SettleOutcome, SettleCancelRequest, SettlePayment, SettlePayRequest, SettlePayResult, RefusedOrderSettlement } from './types/connector';
|
|
34
34
|
export type {
|
|
35
35
|
DisplaySignalling, DisplaySignallingContext, DisplaySignallingErrorCode, DisplayAdvertisement, IceServer,
|
|
36
36
|
PendingPairing, DisplayRecord, SignalMessage, TillDevice,
|
|
@@ -54,9 +54,10 @@ export type {
|
|
|
54
54
|
} from './types/payment-methods';
|
|
55
55
|
export type { ReceiptTemplate, ReceiptTemplateKind } from './types/receipt-templates';
|
|
56
56
|
export type {
|
|
57
|
-
StoreOrder, StoreOrderLine, StoreOrderCharge, StoreOrderPayment, StoreOrderRefund, ListOrdersQuery, StoreOrderPage, OrderFilterField,
|
|
57
|
+
StoreOrder, StoreOrderLine, StoreOrderCharge, StoreOrderPayment, StoreOrderRefund, StoreOrderRefundLine, ListOrdersQuery, StoreOrderPage, OrderFilterField,
|
|
58
|
+
StoreRefund, StoreRefundOrphan, ListRefundsQuery, StoreRefundPage,
|
|
58
59
|
} from './types/orders';
|
|
59
|
-
export { ORDER_FILTER_FIELDS, UnsupportedOrderFilterError, orderFilterFields, assertOrderFiltersSupported, assertOrderDateRange } from './order-filters';
|
|
60
|
+
export { ORDER_FILTER_FIELDS, UnsupportedOrderFilterError, StoreRefundsUnsupportedError, orderFilterFields, assertOrderFiltersSupported, assertOrderDateRange } from './order-filters';
|
|
60
61
|
export type { RegisterInfo } from './types/registers';
|
|
61
62
|
export type { ApproverCredentials, Correction, StoreClosure, ClosureReads } from './types/closures';
|
|
62
63
|
export { CASHIER_PERMISSIONS, cashierPermissions, isCashierPermission, type Cashier, type CashierPermission } from './types/cashier';
|
|
@@ -83,7 +84,7 @@ export type {
|
|
|
83
84
|
export type { OrderAddress, OrderCreateCouponLine } from './types/commands';
|
|
84
85
|
|
|
85
86
|
export {
|
|
86
|
-
COMMANDS_PATH, PROTOCOL_HEADER, PROTOCOL_VERSION, MAX_COMMANDS_PER_BATCH, ORDER_NOTE_MAX,
|
|
87
|
+
COMMANDS_PATH, PROTOCOL_HEADER, PROTOCOL_VERSION, MAX_COMMANDS_PER_BATCH, ORDER_NOTE_MAX, NEEDS_ADMIN_MESSAGE_MAX,
|
|
87
88
|
ORDER_TAX_IDS_MAX, ORDER_TAX_ID_TYPE_MAX, ORDER_TAX_ID_VALUE_MAX, ORDER_META_MAX, ORDER_META_KEY_MAX, ORDER_LINE_SKU_MAX,
|
|
88
89
|
isCommandBatchResponse,
|
|
89
90
|
} from './commands';
|
|
@@ -123,3 +124,7 @@ export { parseCommandResult, CommandResultError } from './server/command-result'
|
|
|
123
124
|
export { deriveSessionFigures, deriveVariance } from './server/register-figures';
|
|
124
125
|
// Browser-safe: tax-rate.ts has no imports. The till and servers convert percentages to the same integer ppm.
|
|
125
126
|
export { ratePpmFromPercent } from './server/tax-rate';
|
|
127
|
+
// Browser-safe: round-ratio.ts has no imports. The till and servers round exact ratios the same way.
|
|
128
|
+
export { roundRatio, type RoundingMode } from './server/round-ratio';
|
|
129
|
+
// Browser-safe: refund-share.ts imports only types and round-ratio. The till and servers share one BigInt refund share (desk, 22 Nov).
|
|
130
|
+
export { refundableLines, priceRefund, type RefundableOrderLine, type EarlierRefund, type RefundableLine, type PricedRefundLine, type PricedRefund } from './server/refund-share';
|