@tallyui/core 5.0.0 → 5.2.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.
@@ -1,5 +1,5 @@
1
- import { J as CommandError, aA as OrderCreatePayload, H as CommandEnvelope, bn as RegisterCommandEnvelope, A as AnyCommandEnvelope, K as CommandResult, B as BatchTooLargeBody, G as CommandBatchResponse, C as CommandWarning, bo as RegisterCommandResult, aM as OrderRefundRejectionCode, aS as OrderReopenRejectionCode, aZ as OrderUpdateRejectionCode, aa as DisplaySignalling, b as SyncContext, ab as DisplaySignallingContext } from '../refund-share-BZ_Ff9Zk.js';
2
- export { N as CommandResultError, ae as EarlierRefund, aj as MAX_COMMANDS_PER_BATCH, ak as NEEDS_ADMIN_MESSAGE_MAX, ao as ORDER_NOTE_MAX, aw as OrderCreateDisplay, aD as OrderCreateTaxRate, bb as PricedRefund, bc as PricedRefundLine, bi as RefundableLine, bj as RefundableOrderLine, bz as RoundingMode, cs as currencyDecimals, c1 as deriveSessionFigures, c2 as deriveVariance, ct as majorToMinor, c7 as minorToMajor, c8 as minorUnitDigits, cf as parseCommandResult, ck as priceRefund, cl as ratePpmFromPercent, cm as refundableLines, cq as roundRatio } from '../refund-share-BZ_Ff9Zk.js';
1
+ import { J as CommandError, aA as OrderCreatePayload, H as CommandEnvelope, bo as RegisterCommandEnvelope, A as AnyCommandEnvelope, K as CommandResult, B as BatchTooLargeBody, G as CommandBatchResponse, C as CommandWarning, bp as RegisterCommandResult, aM as OrderRefundRejectionCode, aS as OrderReopenRejectionCode, aZ as OrderUpdateRejectionCode, aa as DisplaySignalling, b as SyncContext, ab as DisplaySignallingContext } from '../refund-share-DVf_0clD.js';
2
+ export { N as CommandResultError, ae as EarlierRefund, aj as MAX_COMMANDS_PER_BATCH, ak as NEEDS_ADMIN_MESSAGE_MAX, ao as ORDER_NOTE_MAX, aw as OrderCreateDisplay, aD as OrderCreateTaxRate, bb as PricedRefund, bc as PricedRefundLine, bi as RefundableLine, bj as RefundableOrderLine, bA as RoundingMode, cB as currencyDecimals, ca as deriveSessionFigures, cb as deriveVariance, cC as majorToMinor, cg as minorToMajor, ch as minorUnitDigits, co as parseCommandResult, ct as priceRefund, cu as ratePpmFromPercent, cv as refundableLines, cz as roundRatio } from '../refund-share-DVf_0clD.js';
3
3
  import 'rxdb';
4
4
  import 'rxjs';
5
5
 
@@ -99,8 +99,10 @@ declare function validateBatch(body: unknown): {
99
99
  * claim, in the executor (order.create; register commands follow ADR-068). It pushes any result
100
100
  * one of those steps returns and moves on.
101
101
  *
102
- * For order.update the shape check is updatePayloadErrors (ADR-090): it adds the update's store ids, and below
103
- * createVersion 5 precheckCommand does not repeat it.
102
+ * For order.update the shape check is updatePayloadErrors (ADR-090): it adds the update's store ids; for order.refund
103
+ * refundPayloadErrors, for order.reopen reopenPayloadErrors, for a register command registerPayloadErrors.
104
+ * precheckCommand repeats the shape check for every command type at every version, after the version answer, as a
105
+ * backstop (#1344, #1346): for order.update's create part too.
104
106
  *
105
107
  * The replay lookup goes before precheckCommand so an already-applied command always replays
106
108
  * as `duplicate`, even once a later @tallyui/core tightens what precheckCommand accepts.
@@ -110,6 +112,7 @@ declare function validateBatch(body: unknown): {
110
112
  * `precheckCommand(envelope, { orderCreate: [1, 2, 3], register: [1], orderRefund: [1], orderReopen: [1], orderUpdate: [1] })` (`orderRefund`, `orderReopen` and `orderUpdate` are optional).
111
113
  * `cashRounding` is the server's own word too (ADR-094): without `true`, an order.create (or an order.update's create part)
112
114
  * carrying `cashRoundings` is refused as `invalid_payload`, never sent on with the field dropped, which would be a wrong total.
115
+ * Likewise, a fee or shipping charge carrying `amountIncludesTax` is refused unless the server declares `chargeTaxMode: true`.
113
116
  */
114
117
  declare function precheckCommand(envelope: Pick<AnyCommandEnvelope | ValidatedCommandEnvelope, 'id' | 'type' | 'version' | 'payload'>, supported: {
115
118
  orderCreate: readonly number[];
@@ -118,6 +121,7 @@ declare function precheckCommand(envelope: Pick<AnyCommandEnvelope | ValidatedCo
118
121
  orderReopen?: readonly number[];
119
122
  orderUpdate?: readonly number[];
120
123
  cashRounding?: boolean;
124
+ chargeTaxMode?: boolean;
121
125
  }): CommandResult | undefined;
122
126
 
123
127
  /**
@@ -23,7 +23,7 @@ import {
23
23
  ratePpmFromPercent,
24
24
  refundableLines,
25
25
  roundRatio
26
- } from "../chunk-RPBSJ3FB.js";
26
+ } from "../chunk-PQ3DB6CJ.js";
27
27
  import "../chunk-MLKGABMK.js";
28
28
 
29
29
  // src/server/fingerprint.ts
@@ -156,7 +156,7 @@ function payloadShapeErrors(payload) {
156
156
  if (custom && (!object(entry) || item === void 0)) return;
157
157
  check2(object(item), path, "an object");
158
158
  if (!object(item)) return;
159
- const keys = custom ? ["name", "sku", "taxClass", "taxStatus"] : [id, "name", "amountMinor", "taxMinor", "taxStatus", "taxClass", ...field === "shipping" ? ["methodId"] : []];
159
+ const keys = custom ? ["name", "sku", "taxClass", "taxStatus"] : [id, "name", "amountMinor", "amountIncludesTax", "taxMinor", "taxStatus", "taxClass", ...field === "shipping" ? ["methodId"] : []];
160
160
  for (const key of Object.keys(item)) check2(keys.includes(key), `${path}.${key}`, "no unknown key");
161
161
  check2(typeof item.name === "string" && item.name.length > 0, `${path}.name`, "a non-empty string");
162
162
  check2(item.taxStatus === "taxable" || item.taxStatus === "none", `${path}.taxStatus`, "taxable or none");
@@ -164,6 +164,7 @@ function payloadShapeErrors(payload) {
164
164
  if (item[key] !== void 0) check2(typeof item[key] === "string", `${path}.${key}`, "a string");
165
165
  }
166
166
  if (!custom) {
167
+ if (item.amountIncludesTax !== void 0) check2(typeof item.amountIncludesTax === "boolean", `${path}.amountIncludesTax`, "a boolean");
167
168
  check2(typeof item[id] === "string" && item[id].length > 0, `${path}.${id}`, "a non-empty string");
168
169
  check2(!seen.has(item[id]), `${path}.${id}`, `no duplicate ${id}`);
169
170
  seen.add(item[id]);
@@ -404,9 +405,9 @@ function fiscalFiguresErrors(payload) {
404
405
  if (payload.fees?.length || payload.shipping?.length) check2(display.taxInclusive === payload.pricesIncludeTax, "display.taxInclusive", "payload.pricesIncludeTax");
405
406
  for (const field of ["fees", "shipping"]) {
406
407
  const id = field === "fees" ? "clientFeeId" : "clientShippingId";
407
- const amounts = new Map((payload[field] ?? []).map((entry) => [
408
+ const charges = new Map((payload[field] ?? []).map((entry) => [
408
409
  "clientFeeId" in entry ? entry.clientFeeId : entry.clientShippingId,
409
- entry.amountMinor
410
+ entry
410
411
  ]));
411
412
  const rows = display[field];
412
413
  if (rows !== void 0) check2(Array.isArray(rows), `display.${field}`, "an array");
@@ -416,12 +417,18 @@ function fiscalFiguresErrors(payload) {
416
417
  if (!object(row, path, [id, "amountMinor"])) return;
417
418
  check2(typeof row[id] === "string" && row[id].length > 0, `${path}.${id}`, "a non-empty string");
418
419
  money(row, path, ["amountMinor"]);
419
- check2(amounts.has(row[id]), `${path}.${id}`, `a payload.${field}[].${id}`);
420
+ const entry = charges.get(row[id]);
421
+ check2(entry !== void 0, `${path}.${id}`, `a payload.${field}[].${id}`);
420
422
  check2(!seen3.has(row[id]), `${path}.${id}`, `no duplicate ${id}`);
421
423
  seen3.add(row[id]);
422
- if (amounts.has(row[id])) check2(row.amountMinor === amounts.get(row[id]), `${path}.amountMinor`, `the payload.${field} amountMinor`);
424
+ if (entry) {
425
+ const converted = entry.amountIncludesTax !== void 0 && entry.amountIncludesTax !== payload.pricesIncludeTax;
426
+ const expected = !converted ? entry.amountMinor : entry.amountMinor + (entry.amountIncludesTax ? -entry.taxMinor : entry.taxMinor);
427
+ const matches = converted ? typeof row.amountMinor === "number" && Math.abs(row.amountMinor - expected) <= 1 : row.amountMinor === expected;
428
+ check2(matches, `${path}.amountMinor`, `the payload.${field} amountMinor${converted ? " converted to the display tax mode" : ""}`);
429
+ }
423
430
  });
424
- for (const key of amounts.keys()) check2(seen3.has(key), `display.${field}`, `a row for ${id} ${key}`);
431
+ for (const key of charges.keys()) check2(seen3.has(key), `display.${field}`, `a row for ${id} ${key}`);
425
432
  }
426
433
  const codes = new Set((payload.coupons ?? []).map((coupon) => coupon.code));
427
434
  const seen2 = /* @__PURE__ */ new Set();
@@ -503,6 +510,224 @@ function shapeErrors() {
503
510
  return { errors, check: check2, noNul };
504
511
  }
505
512
 
513
+ // src/server/refund-payload-shape.ts
514
+ function refundPayloadErrors(payload) {
515
+ const { errors, check: check2, noNul } = shapeErrors();
516
+ if (!isPlainObject(payload)) return ["payload: expected an object"];
517
+ const fields = [
518
+ "clientRefundId",
519
+ "orderId",
520
+ "registerId",
521
+ "sessionId",
522
+ "clientOrderId",
523
+ "cashierRef",
524
+ "lines",
525
+ "shippingMinor",
526
+ "totalMinor",
527
+ "adjustmentMinor",
528
+ "destination",
529
+ "reason",
530
+ "createdAt"
531
+ ];
532
+ for (const key of Object.keys(payload)) {
533
+ if (!fields.includes(key) && errors.length < 10) {
534
+ errors.push(`${key.includes("\0") ? JSON.stringify(key) : key}: unknown field for order.refund version 1`);
535
+ }
536
+ }
537
+ for (const field of ["clientRefundId", "orderId", "registerId", "sessionId", "clientOrderId", "cashierRef"]) {
538
+ const value = payload[field];
539
+ if (["clientOrderId", "cashierRef"].includes(field) && value === void 0) continue;
540
+ check2(
541
+ typeof value === "string" && value.length > 0 && value.length <= 64,
542
+ field,
543
+ "a non-empty string of at most 64 characters"
544
+ );
545
+ noNul(value, field);
546
+ }
547
+ check2(Array.isArray(payload.lines) && payload.lines.length <= 500, "lines", "an array of at most 500 lines");
548
+ const seen = /* @__PURE__ */ new Set();
549
+ if (Array.isArray(payload.lines)) payload.lines.forEach((line, index) => {
550
+ const path = `lines[${index}]`;
551
+ if (!isPlainObject(line)) {
552
+ check2(false, path, "an object");
553
+ return;
554
+ }
555
+ for (const key of Object.keys(line)) {
556
+ if (!["orderLineId", "quantity", "restock"].includes(key) && errors.length < 10) {
557
+ errors.push(`${path}.${key.includes("\0") ? JSON.stringify(key) : key}: unknown field for order.refund version 1`);
558
+ }
559
+ }
560
+ check2(
561
+ typeof line.orderLineId === "string" && line.orderLineId.length > 0 && line.orderLineId.length <= 64,
562
+ `${path}.orderLineId`,
563
+ "a non-empty string of at most 64 characters"
564
+ );
565
+ noNul(line.orderLineId, `${path}.orderLineId`);
566
+ if (typeof line.orderLineId === "string") {
567
+ check2(!seen.has(line.orderLineId), `${path}.orderLineId`, "unique in lines");
568
+ seen.add(line.orderLineId);
569
+ }
570
+ check2(Number.isSafeInteger(line.quantity) && line.quantity >= 1, `${path}.quantity`, "a safe integer >= 1");
571
+ check2(typeof line.restock === "boolean", `${path}.restock`, "a boolean");
572
+ });
573
+ for (const field of ["shippingMinor", "totalMinor"]) {
574
+ check2(Number.isSafeInteger(payload[field]) && payload[field] >= 0, field, "a safe integer >= 0");
575
+ }
576
+ check2(Number.isSafeInteger(payload.adjustmentMinor), "adjustmentMinor", "a safe integer");
577
+ check2(payload.destination === "original_method" || payload.destination === "cash", "destination", "original_method or cash");
578
+ noNul(payload.destination, "destination");
579
+ check2(
580
+ typeof payload.reason === "string" && payload.reason.trim().length > 0 && payload.reason.length <= 500,
581
+ "reason",
582
+ "a non-empty string after trim of at most 500 characters"
583
+ );
584
+ noNul(payload.reason, "reason");
585
+ check2(
586
+ typeof payload.createdAt === "string" && payload.createdAt.length > 0 && !Number.isNaN(Date.parse(payload.createdAt)),
587
+ "createdAt",
588
+ "a valid date"
589
+ );
590
+ noNul(payload.createdAt, "createdAt");
591
+ return errors;
592
+ }
593
+
594
+ // src/server/register-payload-shape.ts
595
+ function registerPayloadErrors(type, payload) {
596
+ const { errors, check: check2, noNul } = shapeErrors();
597
+ if (!isPlainObject(payload)) return ["payload: expected an object"];
598
+ const string = (field, optional = false) => {
599
+ const value = payload[field];
600
+ if (optional && value === void 0) return;
601
+ check2(typeof value === "string" && (optional || value.length > 0), field, optional ? "a string" : "a non-empty string");
602
+ if (typeof value === "string" && (field.endsWith("Id") || field === "voids")) check2(value.length <= 64, field, "at most 64 characters");
603
+ if (typeof value === "string" && ["openedAt", "at", "createdAt", "closedAt"].includes(field)) {
604
+ check2(!Number.isNaN(Date.parse(value)), field, "a valid date");
605
+ }
606
+ noNul(value, field);
607
+ };
608
+ const integer = (field, min = -Infinity) => check2(Number.isSafeInteger(payload[field]) && payload[field] >= min, field, `a safe integer >= ${min}`);
609
+ const record = (field) => {
610
+ const value = payload[field];
611
+ check2(isPlainObject(value), field, "a record of integers");
612
+ if (isPlainObject(value)) for (const [key, amount] of Object.entries(value)) {
613
+ check2(key.length > 0 && Number.isSafeInteger(amount), `${field}.${key}`, "a non-empty key with a safe integer");
614
+ noNul(key, `${field}.${JSON.stringify(key)}`);
615
+ }
616
+ };
617
+ string("sessionId");
618
+ switch (type) {
619
+ case "register.session.open":
620
+ for (const field of ["registerId", "openedAt"]) string(field);
621
+ for (const field of ["storeKey", "businessDay", "openedBy"]) string(field, true);
622
+ if (payload.deviceName !== void 0) {
623
+ check2(
624
+ typeof payload.deviceName === "string" && payload.deviceName.trim().length >= 1 && payload.deviceName.trim().length <= 64,
625
+ "deviceName",
626
+ "a string of 1 to 64 characters after trim"
627
+ );
628
+ noNul(payload.deviceName, "deviceName");
629
+ }
630
+ if (payload.supersedes !== void 0) {
631
+ check2(
632
+ typeof payload.supersedes === "string" && payload.supersedes.length > 0 && payload.supersedes.length <= 64,
633
+ "supersedes",
634
+ "a non-empty string of at most 64 characters"
635
+ );
636
+ noNul(payload.supersedes, "supersedes");
637
+ }
638
+ integer("countedFloatMinor", 0);
639
+ for (const field of ["expectedFloatMinor", "openingVarianceMinor"]) if (payload[field] !== void 0) integer(field);
640
+ break;
641
+ case "register.session.transition":
642
+ string("at");
643
+ check2(["open", "counting", "closed"].includes(payload.status), "status", "open, counting or closed");
644
+ for (const field of ["counted", "closedBy", "approvedBy"]) if (payload[field] !== void 0) {
645
+ check2(payload.status === "closed", field, "a closing transition");
646
+ if (field === "counted") record(field);
647
+ else string(field, true);
648
+ }
649
+ break;
650
+ case "register.movement.record":
651
+ case "register.movement.void":
652
+ for (const field of ["movementId", "createdAt"]) string(field);
653
+ string("createdBy", true);
654
+ if (type === "register.movement.void") string("voids");
655
+ else {
656
+ check2(
657
+ typeof payload.reason === "string" && payload.reason.trim().length > 0 && payload.reason.length <= 500,
658
+ "reason",
659
+ "a non-empty string after trim of at most 500 characters"
660
+ );
661
+ noNul(payload.reason, "reason");
662
+ check2(["paid_in", "paid_out", "no_sale"].includes(payload.type), "type", "paid_in, paid_out or no_sale");
663
+ integer("amountMinor", payload.type === "no_sale" ? 0 : 1);
664
+ if (payload.type === "no_sale") check2(payload.amountMinor === 0, "amountMinor", "0 for no_sale");
665
+ }
666
+ break;
667
+ case "register.closure.submit":
668
+ for (const field of ["closureId", "registerId", "openedAt", "closedAt", "softwareVersion"]) string(field);
669
+ for (const field of ["businessDay", "closedBy", "approvedBy"]) string(field, true);
670
+ if (payload.approval !== void 0) {
671
+ check2(typeof payload.approval === "string" && payload.approval.length > 0, "approval", "a non-empty string");
672
+ noNul(payload.approval, "approval");
673
+ }
674
+ integer("number", 1);
675
+ for (const field of [
676
+ "periodSalesTotalMinor",
677
+ "periodRefundsTotalMinor",
678
+ "perpetualSalesTotalMinor",
679
+ "perpetualRefundsTotalMinor",
680
+ "unsyncedCount",
681
+ "unsyncedTotalMinor"
682
+ ]) integer(field, 0);
683
+ for (const field of ["number", "unsyncedCount"])
684
+ check2(payload[field] <= 2147483647, field, "at most 2147483647");
685
+ for (const field of ["tillExpected", "counted"]) record(field);
686
+ for (const field of ["orderIds", "movementIds"]) {
687
+ const value = payload[field];
688
+ check2(Array.isArray(value), field, "an array of ids");
689
+ if (Array.isArray(value)) value.forEach((id, index) => {
690
+ check2(typeof id === "string" && id.length > 0 && id.length <= 64, `${field}[${index}]`, "a non-empty string of at most 64 characters");
691
+ noNul(id, `${field}[${index}]`);
692
+ });
693
+ }
694
+ break;
695
+ default:
696
+ check2(false, "type", "a register command type");
697
+ }
698
+ return errors;
699
+ }
700
+
701
+ // src/server/reopen-payload-shape.ts
702
+ function reopenPayloadErrors(payload) {
703
+ const { errors, check: check2, noNul } = shapeErrors();
704
+ if (!isPlainObject(payload)) return ["payload: expected an object"];
705
+ const fields = ["orderId", "clientOrderId", "baseRevision", "cashierRef", "registerId", "storeId", "createdAt"];
706
+ for (const key of Object.keys(payload)) {
707
+ if (!fields.includes(key) && errors.length < 10) {
708
+ errors.push(`${key.includes("\0") ? JSON.stringify(key) : key}: unknown field for order.reopen version 1`);
709
+ }
710
+ }
711
+ for (const field of ["orderId", "cashierRef", "registerId", "clientOrderId", "baseRevision", "storeId"]) {
712
+ const value = payload[field];
713
+ if (["clientOrderId", "baseRevision", "storeId"].includes(field) && value === void 0) continue;
714
+ const max = field === "baseRevision" ? 128 : 64;
715
+ check2(
716
+ typeof value === "string" && value.length > 0 && value.length <= max,
717
+ field,
718
+ `a non-empty string of at most ${max} characters`
719
+ );
720
+ noNul(value, field);
721
+ }
722
+ check2(
723
+ typeof payload.createdAt === "string" && payload.createdAt.length > 0 && !Number.isNaN(Date.parse(payload.createdAt)),
724
+ "createdAt",
725
+ "a valid date"
726
+ );
727
+ noNul(payload.createdAt, "createdAt");
728
+ return errors;
729
+ }
730
+
506
731
  // src/server/update-payload-shape.ts
507
732
  function updateOnlyErrors(payload) {
508
733
  const { errors, check: check2 } = shapeErrors();
@@ -589,6 +814,7 @@ function validateBatch(body) {
589
814
  }
590
815
  var rejected = (id, code, message, data) => ({ id, status: "rejected", error: data === void 0 ? { code, message } : { code, message, data } });
591
816
  var firstTen = (errors) => errors.slice(0, 10).join("; ");
817
+ var shapeRefusal = (id, errors) => errors.length ? rejected(id, "invalid_payload", firstTen(errors)) : void 0;
592
818
  function unsupportedOptional(envelope, key, versions, noun) {
593
819
  if (versions.includes(envelope.version)) return void 0;
594
820
  return rejected(
@@ -602,8 +828,12 @@ function precheckCommand(envelope, supported) {
602
828
  for (const key of ["orderCreate", "register"]) {
603
829
  if (!supported[key]?.length) throw new TypeError(`precheckCommand: supported.${key} must list at least one version`);
604
830
  }
605
- if (envelope.type === "order.refund") return unsupportedOptional(envelope, "orderRefund", supported.orderRefund ?? [], "refunds");
606
- if (envelope.type === "order.reopen") return unsupportedOptional(envelope, "orderReopen", supported.orderReopen ?? [], "reopens");
831
+ if (envelope.type === "order.refund") {
832
+ return unsupportedOptional(envelope, "orderRefund", supported.orderRefund ?? [], "refunds") ?? shapeRefusal(envelope.id, refundPayloadErrors(envelope.payload));
833
+ }
834
+ if (envelope.type === "order.reopen") {
835
+ return unsupportedOptional(envelope, "orderReopen", supported.orderReopen ?? [], "reopens") ?? shapeRefusal(envelope.id, reopenPayloadErrors(envelope.payload));
836
+ }
607
837
  if (envelope.type === "order.update") {
608
838
  const refusal = unsupportedOptional(envelope, "orderUpdate", supported.orderUpdate ?? [], "updates");
609
839
  if (refusal) return refusal;
@@ -623,7 +853,7 @@ function precheckCommand(envelope, supported) {
623
853
  { register: Math.max(...supported.register) }
624
854
  );
625
855
  }
626
- return void 0;
856
+ return shapeRefusal(envelope.id, registerPayloadErrors(envelope.type, envelope.payload));
627
857
  }
628
858
  const command = envelope;
629
859
  if (!supported.orderCreate.includes(command.version)) {
@@ -637,6 +867,9 @@ function precheckCommand(envelope, supported) {
637
867
  if (command.payload.cashRoundings !== void 0 && supported.cashRounding !== true) {
638
868
  return rejected(command.id, "invalid_payload", "cashRoundings requires the cashRounding capability, which this server does not declare");
639
869
  }
870
+ if (supported.chargeTaxMode !== true && [command.payload.fees, command.payload.shipping].some((items) => Array.isArray(items) && items.some((entry) => entry?.amountIncludesTax !== void 0))) {
871
+ return rejected(command.id, "invalid_payload", "amountIncludesTax requires the chargeTaxMode capability, which this server does not declare");
872
+ }
640
873
  const { lines, discountMinor } = command.payload;
641
874
  const discounted = discountMinor !== void 0 || Array.isArray(lines) && lines.some((line) => line?.discountMinor !== void 0);
642
875
  const payload = command.payload;
@@ -680,7 +913,7 @@ function precheckCommand(envelope, supported) {
680
913
  return rejected(command.id, "invalid_payload", firstTen(bounds));
681
914
  }
682
915
  const shape = payloadShapeErrors(payload);
683
- const errors = command.version >= 5 && shape.length ? shape : v3 && display !== void 0 && taxByRate !== void 0 && shape.length === 0 ? fiscalFiguresErrors(payload) : [];
916
+ const errors = shape.length ? shape : v3 && display !== void 0 && taxByRate !== void 0 ? fiscalFiguresErrors(payload) : [];
684
917
  if (errors.length) {
685
918
  return rejected(command.id, "invalid_payload", firstTen(errors));
686
919
  }
@@ -703,224 +936,6 @@ function totalWarnings(expectedMinor, serverMinor) {
703
936
  return serverMinor === expectedMinor ? [] : [{ code: "total_mismatch", expectedMinor, serverMinor }];
704
937
  }
705
938
 
706
- // src/server/register-payload-shape.ts
707
- function registerPayloadErrors(type, payload) {
708
- const { errors, check: check2, noNul } = shapeErrors();
709
- if (!isPlainObject(payload)) return ["payload: expected an object"];
710
- const string = (field, optional = false) => {
711
- const value = payload[field];
712
- if (optional && value === void 0) return;
713
- check2(typeof value === "string" && (optional || value.length > 0), field, optional ? "a string" : "a non-empty string");
714
- if (typeof value === "string" && (field.endsWith("Id") || field === "voids")) check2(value.length <= 64, field, "at most 64 characters");
715
- if (typeof value === "string" && ["openedAt", "at", "createdAt", "closedAt"].includes(field)) {
716
- check2(!Number.isNaN(Date.parse(value)), field, "a valid date");
717
- }
718
- noNul(value, field);
719
- };
720
- const integer = (field, min = -Infinity) => check2(Number.isSafeInteger(payload[field]) && payload[field] >= min, field, `a safe integer >= ${min}`);
721
- const record = (field) => {
722
- const value = payload[field];
723
- check2(isPlainObject(value), field, "a record of integers");
724
- if (isPlainObject(value)) for (const [key, amount] of Object.entries(value)) {
725
- check2(key.length > 0 && Number.isSafeInteger(amount), `${field}.${key}`, "a non-empty key with a safe integer");
726
- noNul(key, `${field}.${JSON.stringify(key)}`);
727
- }
728
- };
729
- string("sessionId");
730
- switch (type) {
731
- case "register.session.open":
732
- for (const field of ["registerId", "openedAt"]) string(field);
733
- for (const field of ["storeKey", "businessDay", "openedBy"]) string(field, true);
734
- if (payload.deviceName !== void 0) {
735
- check2(
736
- typeof payload.deviceName === "string" && payload.deviceName.trim().length >= 1 && payload.deviceName.trim().length <= 64,
737
- "deviceName",
738
- "a string of 1 to 64 characters after trim"
739
- );
740
- noNul(payload.deviceName, "deviceName");
741
- }
742
- if (payload.supersedes !== void 0) {
743
- check2(
744
- typeof payload.supersedes === "string" && payload.supersedes.length > 0 && payload.supersedes.length <= 64,
745
- "supersedes",
746
- "a non-empty string of at most 64 characters"
747
- );
748
- noNul(payload.supersedes, "supersedes");
749
- }
750
- integer("countedFloatMinor", 0);
751
- for (const field of ["expectedFloatMinor", "openingVarianceMinor"]) if (payload[field] !== void 0) integer(field);
752
- break;
753
- case "register.session.transition":
754
- string("at");
755
- check2(["open", "counting", "closed"].includes(payload.status), "status", "open, counting or closed");
756
- for (const field of ["counted", "closedBy", "approvedBy"]) if (payload[field] !== void 0) {
757
- check2(payload.status === "closed", field, "a closing transition");
758
- if (field === "counted") record(field);
759
- else string(field, true);
760
- }
761
- break;
762
- case "register.movement.record":
763
- case "register.movement.void":
764
- for (const field of ["movementId", "createdAt"]) string(field);
765
- string("createdBy", true);
766
- if (type === "register.movement.void") string("voids");
767
- else {
768
- check2(
769
- typeof payload.reason === "string" && payload.reason.trim().length > 0 && payload.reason.length <= 500,
770
- "reason",
771
- "a non-empty string after trim of at most 500 characters"
772
- );
773
- noNul(payload.reason, "reason");
774
- check2(["paid_in", "paid_out", "no_sale"].includes(payload.type), "type", "paid_in, paid_out or no_sale");
775
- integer("amountMinor", payload.type === "no_sale" ? 0 : 1);
776
- if (payload.type === "no_sale") check2(payload.amountMinor === 0, "amountMinor", "0 for no_sale");
777
- }
778
- break;
779
- case "register.closure.submit":
780
- for (const field of ["closureId", "registerId", "openedAt", "closedAt", "softwareVersion"]) string(field);
781
- for (const field of ["businessDay", "closedBy", "approvedBy"]) string(field, true);
782
- if (payload.approval !== void 0) {
783
- check2(typeof payload.approval === "string" && payload.approval.length > 0, "approval", "a non-empty string");
784
- noNul(payload.approval, "approval");
785
- }
786
- integer("number", 1);
787
- for (const field of [
788
- "periodSalesTotalMinor",
789
- "periodRefundsTotalMinor",
790
- "perpetualSalesTotalMinor",
791
- "perpetualRefundsTotalMinor",
792
- "unsyncedCount",
793
- "unsyncedTotalMinor"
794
- ]) integer(field, 0);
795
- for (const field of ["number", "unsyncedCount"])
796
- check2(payload[field] <= 2147483647, field, "at most 2147483647");
797
- for (const field of ["tillExpected", "counted"]) record(field);
798
- for (const field of ["orderIds", "movementIds"]) {
799
- const value = payload[field];
800
- check2(Array.isArray(value), field, "an array of ids");
801
- if (Array.isArray(value)) value.forEach((id, index) => {
802
- check2(typeof id === "string" && id.length > 0 && id.length <= 64, `${field}[${index}]`, "a non-empty string of at most 64 characters");
803
- noNul(id, `${field}[${index}]`);
804
- });
805
- }
806
- break;
807
- default:
808
- check2(false, "type", "a register command type");
809
- }
810
- return errors;
811
- }
812
-
813
- // src/server/refund-payload-shape.ts
814
- function refundPayloadErrors(payload) {
815
- const { errors, check: check2, noNul } = shapeErrors();
816
- if (!isPlainObject(payload)) return ["payload: expected an object"];
817
- const fields = [
818
- "clientRefundId",
819
- "orderId",
820
- "registerId",
821
- "sessionId",
822
- "clientOrderId",
823
- "cashierRef",
824
- "lines",
825
- "shippingMinor",
826
- "totalMinor",
827
- "adjustmentMinor",
828
- "destination",
829
- "reason",
830
- "createdAt"
831
- ];
832
- for (const key of Object.keys(payload)) {
833
- if (!fields.includes(key) && errors.length < 10) {
834
- errors.push(`${key.includes("\0") ? JSON.stringify(key) : key}: unknown field for order.refund version 1`);
835
- }
836
- }
837
- for (const field of ["clientRefundId", "orderId", "registerId", "sessionId", "clientOrderId", "cashierRef"]) {
838
- const value = payload[field];
839
- if (["clientOrderId", "cashierRef"].includes(field) && value === void 0) continue;
840
- check2(
841
- typeof value === "string" && value.length > 0 && value.length <= 64,
842
- field,
843
- "a non-empty string of at most 64 characters"
844
- );
845
- noNul(value, field);
846
- }
847
- check2(Array.isArray(payload.lines) && payload.lines.length <= 500, "lines", "an array of at most 500 lines");
848
- const seen = /* @__PURE__ */ new Set();
849
- if (Array.isArray(payload.lines)) payload.lines.forEach((line, index) => {
850
- const path = `lines[${index}]`;
851
- if (!isPlainObject(line)) {
852
- check2(false, path, "an object");
853
- return;
854
- }
855
- for (const key of Object.keys(line)) {
856
- if (!["orderLineId", "quantity", "restock"].includes(key) && errors.length < 10) {
857
- errors.push(`${path}.${key.includes("\0") ? JSON.stringify(key) : key}: unknown field for order.refund version 1`);
858
- }
859
- }
860
- check2(
861
- typeof line.orderLineId === "string" && line.orderLineId.length > 0 && line.orderLineId.length <= 64,
862
- `${path}.orderLineId`,
863
- "a non-empty string of at most 64 characters"
864
- );
865
- noNul(line.orderLineId, `${path}.orderLineId`);
866
- if (typeof line.orderLineId === "string") {
867
- check2(!seen.has(line.orderLineId), `${path}.orderLineId`, "unique in lines");
868
- seen.add(line.orderLineId);
869
- }
870
- check2(Number.isSafeInteger(line.quantity) && line.quantity >= 1, `${path}.quantity`, "a safe integer >= 1");
871
- check2(typeof line.restock === "boolean", `${path}.restock`, "a boolean");
872
- });
873
- for (const field of ["shippingMinor", "totalMinor"]) {
874
- check2(Number.isSafeInteger(payload[field]) && payload[field] >= 0, field, "a safe integer >= 0");
875
- }
876
- check2(Number.isSafeInteger(payload.adjustmentMinor), "adjustmentMinor", "a safe integer");
877
- check2(payload.destination === "original_method" || payload.destination === "cash", "destination", "original_method or cash");
878
- noNul(payload.destination, "destination");
879
- check2(
880
- typeof payload.reason === "string" && payload.reason.trim().length > 0 && payload.reason.length <= 500,
881
- "reason",
882
- "a non-empty string after trim of at most 500 characters"
883
- );
884
- noNul(payload.reason, "reason");
885
- check2(
886
- typeof payload.createdAt === "string" && payload.createdAt.length > 0 && !Number.isNaN(Date.parse(payload.createdAt)),
887
- "createdAt",
888
- "a valid date"
889
- );
890
- noNul(payload.createdAt, "createdAt");
891
- return errors;
892
- }
893
-
894
- // src/server/reopen-payload-shape.ts
895
- function reopenPayloadErrors(payload) {
896
- const { errors, check: check2, noNul } = shapeErrors();
897
- if (!isPlainObject(payload)) return ["payload: expected an object"];
898
- const fields = ["orderId", "clientOrderId", "baseRevision", "cashierRef", "registerId", "storeId", "createdAt"];
899
- for (const key of Object.keys(payload)) {
900
- if (!fields.includes(key) && errors.length < 10) {
901
- errors.push(`${key.includes("\0") ? JSON.stringify(key) : key}: unknown field for order.reopen version 1`);
902
- }
903
- }
904
- for (const field of ["orderId", "cashierRef", "registerId", "clientOrderId", "baseRevision", "storeId"]) {
905
- const value = payload[field];
906
- if (["clientOrderId", "baseRevision", "storeId"].includes(field) && value === void 0) continue;
907
- const max = field === "baseRevision" ? 128 : 64;
908
- check2(
909
- typeof value === "string" && value.length > 0 && value.length <= max,
910
- field,
911
- `a non-empty string of at most ${max} characters`
912
- );
913
- noNul(value, field);
914
- }
915
- check2(
916
- typeof payload.createdAt === "string" && payload.createdAt.length > 0 && !Number.isNaN(Date.parse(payload.createdAt)),
917
- "createdAt",
918
- "a valid date"
919
- );
920
- noNul(payload.createdAt, "createdAt");
921
- return errors;
922
- }
923
-
924
939
  // src/server/rejection-codes.ts
925
940
  function platformErrorResult(id, platformCode, platformMessage) {
926
941
  return { id, status: "rejected", error: { code: "platform_error", message: `${platformCode}: ${platformMessage}`, data: { platformCode, platformMessage } } };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tallyui/core",
3
- "version": "5.0.0",
3
+ "version": "5.2.0",
4
4
  "type": "module",
5
5
  "description": "Core interfaces, traits, and context providers for Tally UI",
6
6
  "main": "./dist/index.js",
@@ -59,6 +59,11 @@ export function useConnector(): TallyConnector {
59
59
  return connector;
60
60
  }
61
61
 
62
+ /** Returns the active connector, or null without a provider. */
63
+ export function useOptionalConnector(): TallyConnector | null {
64
+ return useContext(ConnectorContext);
65
+ }
66
+
62
67
  /**
63
68
  * Convenience hook: grab just the product traits from the active connector.
64
69
  */
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, SettleReverseLeg, SettleReverseRequest, SettleReverseResult, RefusedOrderSettlement } from './types/connector';
34
34
  export type {
35
35
  DisplaySignalling, DisplaySignallingContext, DisplaySignallingErrorCode, DisplayAdvertisement, IceServer,
36
36
  PendingPairing, DisplayRecord, SignalMessage, TillDevice,
@@ -105,6 +105,7 @@ export type { ReconcileFeed, ReconcileFeedEntry, ReconcileFetchEntry, KeyedRecon
105
105
  export {
106
106
  ConnectorProvider,
107
107
  useConnector,
108
+ useOptionalConnector,
108
109
  useProductTraits,
109
110
  useCustomerTraits,
110
111
  useTraitContext,