@tallyui/core 3.12.0 → 3.13.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.
@@ -3,6 +3,7 @@ var COMMANDS_PATH = "/tally/v1/commands";
3
3
  var PROTOCOL_HEADER = "X-Tally-Protocol";
4
4
  var PROTOCOL_VERSION = 1;
5
5
  var MAX_COMMANDS_PER_BATCH = 50;
6
+ var ORDER_NOTE_MAX = 1e3;
6
7
  function isCommandBatchResponse(value) {
7
8
  return typeof value === "object" && value !== null && "results" in value && Array.isArray(value.results) && value.results.every(
8
9
  (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")
@@ -179,6 +180,7 @@ export {
179
180
  PROTOCOL_HEADER,
180
181
  PROTOCOL_VERSION,
181
182
  MAX_COMMANDS_PER_BATCH,
183
+ ORDER_NOTE_MAX,
182
184
  isCommandBatchResponse,
183
185
  CommandResultError,
184
186
  parseCommandResult
@@ -6,8 +6,9 @@ interface CommandEnvelope<P = unknown> {
6
6
  type: CommandType;
7
7
  /** 3 when the order carries ADR-065's `display` and `taxByRate` (the store accepts 3), else 2 when discounted, else 1;
8
8
  * 4 is 3 with every `discountMinor` tax-exclusive, built only when capped at 4 or more (#286).
9
- * 5 is 4 plus fees, shipping and custom lines (ADR-075), sent only for an order that has one. */
10
- version: 1 | 2 | 3 | 4 | 5 | 6;
9
+ * 5 is 4 plus fees, shipping and custom lines (ADR-075), sent only for an order that has one.
10
+ * 7 is 6 plus the sale's `note` (ADR-083), sent only for an order that has one. */
11
+ version: 1 | 2 | 3 | 4 | 5 | 6 | 7;
11
12
  payload: P;
12
13
  createdAt: string;
13
14
  deviceId: string;
@@ -83,10 +84,11 @@ interface OrderRefundOrderStateData {
83
84
  interface OrderRefundNoOpenSessionData {
84
85
  sessionId: string;
85
86
  }
86
- /** An order.create envelope: 5 is 4 plus fees, shipping and custom lines (ADR-075), sent only for an order that has one. */
87
+ /** An order.create envelope: 5 is 4 plus fees, shipping and custom lines (ADR-075), sent only for an order that has one.
88
+ * 7 is 6 plus the sale's note (ADR-083). */
87
89
  type OrderCreateEnvelope = CommandEnvelope<OrderCreatePayload> & {
88
90
  type: 'order.create';
89
- version: 1 | 2 | 3 | 4 | 5 | 6;
91
+ version: 1 | 2 | 3 | 4 | 5 | 6 | 7;
90
92
  };
91
93
  /** Outcome of processing a command. */
92
94
  type CommandStatus = 'applied' | 'duplicate' | 'rejected';
@@ -269,6 +271,16 @@ interface RegisterSessionSupersededData {
269
271
  deviceName?: string;
270
272
  newSessionId?: string;
271
273
  }
274
+ /** error.data for register_approval_required (ADR-082 d6): variance is counted − tillExpected for each key of counted. */
275
+ interface RegisterApprovalRequiredData {
276
+ sessionId: string;
277
+ thresholdMinor: number;
278
+ variance: Record<string, number>;
279
+ }
280
+ /** error.data for register_approval_invalid (ADR-082 d6). */
281
+ interface RegisterApprovalInvalidData {
282
+ reason: 'unknown' | 'expired' | 'used' | 'session_mismatch' | 'variance_mismatch';
283
+ }
272
284
  interface RegisterSessionTransitionPayload {
273
285
  sessionId: string;
274
286
  status: 'open' | 'counting' | 'closed';
@@ -303,6 +315,7 @@ interface RegisterClosureSubmitPayload {
303
315
  closedAt: string;
304
316
  closedBy?: string;
305
317
  approvedBy?: string;
318
+ /** Register v3 only (ADR-082): the store's approval proof, opaque; never parsed, logged or stored in the Z. */ approval?: string;
306
319
  tillExpected: Record<string, number>;
307
320
  counted: Record<string, number>;
308
321
  periodSalesTotalMinor: number;
@@ -484,6 +497,8 @@ interface OrderCreatePayload {
484
497
  locationId?: string;
485
498
  /** Version 3+: the register session the sale was taken for, stamped or late (ADR-032). A late sale names the session that refused its stamp; the server tells the two apart by the session's closure `orderIds`. Absent when the sale had no session. */
486
499
  sessionId?: string;
500
+ /** Version 7 (ADR-083): the sale's note, 1 to ORDER_NOTE_MAX UTF-16 units; omitted when the sale has none. */
501
+ note?: string;
487
502
  }
488
503
  /** Batch of commands submitted to the server. */
489
504
  interface CommandBatchRequest<E extends AnyCommandEnvelope = CommandEnvelope> {
@@ -508,6 +523,8 @@ declare const PROTOCOL_HEADER = "X-Tally-Protocol";
508
523
  declare const PROTOCOL_VERSION = 1;
509
524
  /** The ADR-038 batch limit; a server answers more with 413 and a BatchTooLargeBody. */
510
525
  declare const MAX_COMMANDS_PER_BATCH = 50;
526
+ /** 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. */
527
+ declare const ORDER_NOTE_MAX = 1000;
511
528
  /**
512
529
  * True if `value` has the shape of a CommandBatchResponse: an object with a
513
530
  * `results` array whose every entry has a string `id` and a `status` of
@@ -524,4 +541,4 @@ declare class CommandResultError extends Error {
524
541
  * CommandResultError naming the first bad field. */
525
542
  declare function parseCommandResult(value: unknown): CommandResult;
526
543
 
527
- export { type AnyCommandEnvelope as A, type BatchTooLargeBody as B, type CommandWarning as C, type OrderRefundResult as D, PROTOCOL_HEADER as E, PROTOCOL_VERSION as F, type RegisterCommandEnvelope as G, type RegisterCommandResult as H, type RegisterCommandType as I, type RegisterMovementRecordPayload as J, type RegisterMovementVoidPayload as K, type RegisterSessionAlreadyOpenData as L, MAX_COMMANDS_PER_BATCH as M, type RegisterSessionOpenPayload as N, type OrderCreateCoupon as O, type PaymentMethodKind as P, type RegisterSessionSupersededData as Q, type RegisterClosureSubmitPayload as R, type RegisterSessionTransitionPayload as S, isCommandBatchResponse as T, parseCommandResult as U, COMMANDS_PATH as a, type CommandBatchRequest as b, type CommandBatchResponse as c, type CommandEnvelope as d, type CommandError as e, type CommandResult as f, CommandResultError as g, type CommandServerRefs as h, type CommandStatus as i, type CommandType as j, type OrderCreateCouponInvalidData as k, type OrderCreateDisplay as l, type OrderCreateEnvelope as m, type OrderCreateLine as n, type OrderCreatePayload as o, type OrderCreatePayment as p, type OrderCreateTaxRate as q, type OrderCreateTotalMismatchData as r, type OrderRefundAmountMismatchData as s, type OrderRefundEnvelope as t, type OrderRefundLine as u, type OrderRefundNoOpenSessionData as v, type OrderRefundOrderStateData as w, type OrderRefundPayload as x, type OrderRefundQuantityExceedsData as y, type OrderRefundRejectionCode as z };
544
+ export { type AnyCommandEnvelope as A, type BatchTooLargeBody as B, type CommandWarning as C, type OrderRefundRejectionCode as D, type OrderRefundResult as E, PROTOCOL_HEADER as F, PROTOCOL_VERSION as G, type RegisterApprovalRequiredData as H, type RegisterClosureSubmitPayload as I, type RegisterCommandEnvelope as J, type RegisterCommandResult as K, type RegisterCommandType as L, MAX_COMMANDS_PER_BATCH as M, type RegisterMovementRecordPayload as N, ORDER_NOTE_MAX as O, type PaymentMethodKind as P, type RegisterMovementVoidPayload as Q, type RegisterApprovalInvalidData as R, type RegisterSessionAlreadyOpenData as S, type RegisterSessionOpenPayload as T, type RegisterSessionSupersededData as U, type RegisterSessionTransitionPayload as V, isCommandBatchResponse as W, parseCommandResult as X, COMMANDS_PATH as a, type CommandBatchRequest as b, type CommandBatchResponse as c, type CommandEnvelope as d, type CommandError as e, type CommandResult as f, CommandResultError as g, type CommandServerRefs as h, type CommandStatus as i, type CommandType as j, type OrderCreateCoupon as k, type OrderCreateCouponInvalidData as l, type OrderCreateDisplay as m, type OrderCreateEnvelope as n, type OrderCreateLine as o, type OrderCreatePayload as p, type OrderCreatePayment as q, type OrderCreateTaxRate as r, type OrderCreateTotalMismatchData as s, type OrderRefundAmountMismatchData as t, type OrderRefundEnvelope as u, type OrderRefundLine as v, type OrderRefundNoOpenSessionData as w, type OrderRefundOrderStateData as x, type OrderRefundPayload as y, type OrderRefundQuantityExceedsData as z };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { RxReplicationPullStreamItem, RxReplicationWriteToMasterRow, RxJsonSchema } from 'rxdb';
2
2
  import { Observable } from 'rxjs';
3
- import { P as PaymentMethodKind, C as CommandWarning } from './command-result-CrM7yjwk.js';
4
- export { A as AnyCommandEnvelope, B as BatchTooLargeBody, a as COMMANDS_PATH, b as CommandBatchRequest, c as CommandBatchResponse, d as CommandEnvelope, e as CommandError, f as CommandResult, g as CommandResultError, h as CommandServerRefs, i as CommandStatus, j as CommandType, M as MAX_COMMANDS_PER_BATCH, O as OrderCreateCoupon, k as OrderCreateCouponInvalidData, l as OrderCreateDisplay, m as OrderCreateEnvelope, n as OrderCreateLine, o as OrderCreatePayload, p as OrderCreatePayment, q as OrderCreateTaxRate, r as OrderCreateTotalMismatchData, s as OrderRefundAmountMismatchData, t as OrderRefundEnvelope, u as OrderRefundLine, v as OrderRefundNoOpenSessionData, w as OrderRefundOrderStateData, x as OrderRefundPayload, y as OrderRefundQuantityExceedsData, z as OrderRefundRejectionCode, D as OrderRefundResult, E as PROTOCOL_HEADER, F as PROTOCOL_VERSION, R as RegisterClosureSubmitPayload, G as RegisterCommandEnvelope, H as RegisterCommandResult, I as RegisterCommandType, J as RegisterMovementRecordPayload, K as RegisterMovementVoidPayload, L as RegisterSessionAlreadyOpenData, N as RegisterSessionOpenPayload, Q as RegisterSessionSupersededData, S as RegisterSessionTransitionPayload, T as isCommandBatchResponse, U as parseCommandResult } from './command-result-CrM7yjwk.js';
3
+ import { P as PaymentMethodKind, C as CommandWarning } from './command-result-CoCa8PXJ.js';
4
+ export { A as AnyCommandEnvelope, B as BatchTooLargeBody, a as COMMANDS_PATH, b as CommandBatchRequest, c as CommandBatchResponse, d as CommandEnvelope, e as CommandError, f as CommandResult, g as CommandResultError, h as CommandServerRefs, i as CommandStatus, j as CommandType, M as MAX_COMMANDS_PER_BATCH, O as ORDER_NOTE_MAX, k as OrderCreateCoupon, l as OrderCreateCouponInvalidData, m as OrderCreateDisplay, n as OrderCreateEnvelope, o as OrderCreateLine, p as OrderCreatePayload, q as OrderCreatePayment, r as OrderCreateTaxRate, s as OrderCreateTotalMismatchData, t as OrderRefundAmountMismatchData, u as OrderRefundEnvelope, v as OrderRefundLine, w as OrderRefundNoOpenSessionData, x as OrderRefundOrderStateData, y as OrderRefundPayload, z as OrderRefundQuantityExceedsData, D as OrderRefundRejectionCode, E as OrderRefundResult, F as PROTOCOL_HEADER, G as PROTOCOL_VERSION, R as RegisterApprovalInvalidData, H as RegisterApprovalRequiredData, I as RegisterClosureSubmitPayload, J as RegisterCommandEnvelope, K as RegisterCommandResult, L as RegisterCommandType, N as RegisterMovementRecordPayload, Q as RegisterMovementVoidPayload, S as RegisterSessionAlreadyOpenData, T as RegisterSessionOpenPayload, U as RegisterSessionSupersededData, V as RegisterSessionTransitionPayload, W as isCommandBatchResponse, X as parseCommandResult } from './command-result-CoCa8PXJ.js';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import { ReactNode } from 'react';
7
7
 
@@ -399,6 +399,30 @@ interface StoreSettingsChoice {
399
399
  channel?: string;
400
400
  }
401
401
 
402
+ /** A customer's postal address. Platform-neutral; every field optional. `country` is an ISO 3166-1 alpha-2 code. */
403
+ interface CustomerAddress {
404
+ firstName?: string;
405
+ lastName?: string;
406
+ company?: string;
407
+ address1?: string;
408
+ address2?: string;
409
+ city?: string;
410
+ state?: string;
411
+ postcode?: string;
412
+ country?: string;
413
+ phone?: string;
414
+ email?: string;
415
+ }
416
+ /**
417
+ * A tax registration number (VAT, ABN, GST, EIN…). `type` is the connector's own id for the scheme; WCPOS v2's set is
418
+ * eu_vat, gb_vat, au_abn, br_cpf, br_cnpj, in_gst, it_cf, it_piva, es_nif, ar_cuit, sa_vat, ca_gst_hst, us_ein, other.
419
+ */
420
+ interface CustomerTaxId {
421
+ type: string;
422
+ value: string;
423
+ country?: string;
424
+ label?: string;
425
+ }
402
426
  /** A store customer, as the till shows and picks it (programme item 14). Platform-neutral. */
403
427
  interface Customer {
404
428
  /** The platform's id: order.create v3 sends it as `customer.customerId`. */
@@ -410,20 +434,35 @@ interface Customer {
410
434
  email?: string;
411
435
  phone?: string;
412
436
  company?: string;
437
+ billing?: CustomerAddress;
438
+ shipping?: CustomerAddress;
439
+ taxIds?: CustomerTaxId[];
413
440
  }
414
- /** What the till collects to create a customer. v1 requires an email. */
441
+ /** What the till collects to create a customer. v1 requires an email; addresses and tax ids are optional. */
415
442
  interface CustomerInput {
416
443
  email: string;
417
444
  firstName?: string;
418
445
  lastName?: string;
419
446
  phone?: string;
420
447
  company?: string;
448
+ billing?: CustomerAddress;
449
+ shipping?: CustomerAddress;
450
+ taxIds?: CustomerTaxId[];
421
451
  }
452
+ /**
453
+ * A change to an existing customer: any subset of {@link CustomerInput}. A field left out is unchanged; `billing`,
454
+ * `shipping` and `taxIds`, when given, replace the stored value whole (`taxIds: []` removes every tax id).
455
+ */
456
+ type CustomerPatch = Partial<CustomerInput>;
422
457
  declare const customerTraits: CustomerTraits<Customer>;
423
458
  /** A customer call that failed for a reason other than credentials (credentials throw ConnectorUnauthorizedError). */
424
459
  declare class CustomerServiceError extends Error {
425
460
  readonly code: 'network' | 'server' | 'invalid';
426
- constructor(code: 'network' | 'server' | 'invalid', message: string);
461
+ /** The HTTP status the store answered with, when the connector has it; undefined for a network failure (no response). */
462
+ readonly status?: number;
463
+ constructor(code: 'network' | 'server' | 'invalid', message: string, options?: {
464
+ status?: number;
465
+ });
427
466
  }
428
467
 
429
468
  /** A line of an order the store holds (ADR-081). Money in integer minor units of the order's currency, as the store
@@ -524,6 +563,136 @@ interface StoreOrderPage {
524
563
  hasMore: boolean;
525
564
  }
526
565
 
566
+ /**
567
+ * A payment method the till can offer, backend-neutral (a port of WCPOS v2's Payments Contract
568
+ * v1 descriptor, `order-math/src/payments/types.ts`). A connector maps its own model into it:
569
+ * WooCommerce gateways, Medusa payment providers, Vendure payment methods. Amounts are integer
570
+ * minor units of the store currency. Open vocabularies keep values this build has never seen, so
571
+ * the till can show such a method disabled instead of dropping it.
572
+ */
573
+ /** A known value, or any other string this build does not know yet. */
574
+ type OpenEnum<Known extends string> = Known | (string & {});
575
+ /** What kind of money the method takes. Not the order's wire method: that is `PaymentMethodKind`. */
576
+ type PaymentKind = 'cash' | 'card' | 'stored_value' | 'bank_transfer' | 'other';
577
+ /** How the payment is taken. `manual`: the cashier records it (cash, a standalone terminal). */
578
+ type CaptureMode = 'manual' | 'webview' | 'server' | 'device' | 'stored_value' | 'gateway';
579
+ /** The transport a payment terminal is reached over. */
580
+ type PaymentTransport = 'bluetooth' | 'usb' | 'network' | 'tap_to_pay';
581
+ /** Whether a leg can be taken while the till is offline: recorded, queued to settle later, or not at all. */
582
+ type PaymentOfflineMode = 'record' | 'queue' | 'none';
583
+ /** Where a tip is entered, if anywhere. */
584
+ type PaymentTipsMode = 'none' | 'on_reader' | 'at_till';
585
+ /** The terminal hardware behind a method: readers the server lists, or transports an SDK discovers. */
586
+ type PaymentHardware = {
587
+ discovery: OpenEnum<'server'>;
588
+ readers: {
589
+ id: string;
590
+ label: string;
591
+ status: OpenEnum<'online' | 'offline'>;
592
+ default: boolean;
593
+ }[];
594
+ defaultReader: string | null;
595
+ lockToDefault: boolean;
596
+ } | {
597
+ discovery: OpenEnum<'sdk' | 'manual'>;
598
+ transports: {
599
+ transport: OpenEnum<PaymentTransport>;
600
+ offline: OpenEnum<PaymentOfflineMode>;
601
+ tips: OpenEnum<PaymentTipsMode>;
602
+ }[];
603
+ };
604
+ /** One way to capture a method's payments. */
605
+ interface CaptureModeEntry {
606
+ mode: OpenEnum<CaptureMode>;
607
+ /** The payment provider's own name, e.g. a terminal vendor; `null` for none. */
608
+ provider: string | null;
609
+ hardware: PaymentHardware | null;
610
+ }
611
+ /** Cash rounding for the method: the due amount rounds to a multiple of `incrementMinor`; `nearest` rounds half up. */
612
+ type PaymentRounding = {
613
+ incrementMinor: number;
614
+ mode: 'nearest' | 'up' | 'down';
615
+ } | null;
616
+ interface PaymentMethodDescriptor {
617
+ /** The connector's own id for the method, stable across reads. */
618
+ id: string;
619
+ /** The name the till shows. */
620
+ title: string;
621
+ kind: OpenEnum<PaymentKind>;
622
+ capture: CaptureModeEntry & {
623
+ /** Every way the method can be captured, the primary first; absent when `mode` is the only one. */
624
+ modes?: CaptureModeEntry[];
625
+ };
626
+ capabilities: {
627
+ /** `partial`: the method may take less than the balance (a split leg). */
628
+ amount: {
629
+ partial: boolean;
630
+ minMinor?: number;
631
+ maxMinor?: number;
632
+ };
633
+ /** Whether tendering more than is due gives change. */
634
+ change: boolean;
635
+ refunds: {
636
+ via: OpenEnum<'provider' | 'manual' | 'device' | 'none'>;
637
+ partial: boolean;
638
+ };
639
+ tips: OpenEnum<PaymentTipsMode>;
640
+ offline: OpenEnum<PaymentOfflineMode>;
641
+ /** Whether a taken leg can be voided. */
642
+ void: boolean;
643
+ };
644
+ defaults: {
645
+ rounding: PaymentRounding;
646
+ /** Whether taking the payment opens the cash drawer. */
647
+ openDrawer: boolean;
648
+ };
649
+ }
650
+ /** The descriptor of one of today's two wire methods: its `id` is the `PaymentMethodKind`. */
651
+ declare function paymentMethodOf(kind: PaymentMethodKind): PaymentMethodDescriptor;
652
+ /** Today's two methods, cash then the card terminal: what the till offers when the connector has no `paymentMethods`. */
653
+ declare function defaultPaymentMethods(): PaymentMethodDescriptor[];
654
+
655
+ /**
656
+ * A register (till) in the store's register directory (v2 parity A4). Platform-neutral: each connector maps its own
657
+ * register model onto it. Money is integer minor units of the store's currency.
658
+ * The cash variance threshold is not here: it is the store's (ADR-082, `capabilities.registerApproval`).
659
+ */
660
+ interface RegisterInfo {
661
+ /** The platform's register id. */
662
+ id: string;
663
+ /** The register's display name, as the cashier picks it. */
664
+ name: string;
665
+ /** The cash the drawer should open with; absent when the store sets none. */
666
+ defaultFloatMinor?: number;
667
+ /** When the register is due to close: a local store time, `HH:MM` on a 24-hour clock; absent when the store sets none. */
668
+ expectedCloseTime?: string;
669
+ }
670
+
671
+ /**
672
+ * The neutral POS permissions a connector resolves from its own model (v2 parity A12):
673
+ * - `viewReports`: Reports, and a count that shows the expected figures (not blind);
674
+ * - `manageClosures`: recount and close without an approver;
675
+ * - `approveVariance`: approve another cashier's over-threshold count;
676
+ * - `refund`: take refunds;
677
+ * - `discount`: give discounts.
678
+ */
679
+ declare const CASHIER_PERMISSIONS: readonly ["viewReports", "manageClosures", "approveVariance", "refund", "discount"];
680
+ /** One of `CASHIER_PERMISSIONS`. */
681
+ type CashierPermission = (typeof CASHIER_PERMISSIONS)[number];
682
+ /** The signed-in cashier, as the connector maps the platform's user (v2 parity A12). */
683
+ interface Cashier {
684
+ /** The platform's id for the signed-in user. */
685
+ id: string;
686
+ /** The display name, as receipts and the handover show it. */
687
+ name: string;
688
+ /** What this cashier may do; a permission left out is denied. */
689
+ permissions: readonly CashierPermission[];
690
+ }
691
+ /** Whether `value` is one of the five permission names. */
692
+ declare function isCashierPermission(value: unknown): value is CashierPermission;
693
+ /** The known permission names in `values`, first occurrence order, without duplicates; anything else is dropped. */
694
+ declare function cashierPermissions(values: readonly unknown[]): CashierPermission[];
695
+
527
696
  /**
528
697
  * Authentication configuration for a connector.
529
698
  * Each API has wildly different auth — JWT, API keys, OAuth, etc.
@@ -583,6 +752,14 @@ interface ServerCapabilities {
583
752
  * coupon. WooCommerce: true only when the woocommerce-pos plugin reports 1.9.0 or later.
584
753
  */
585
754
  coupons?: boolean;
755
+ /**
756
+ * The store's register approval threshold (ADR-082 d3), from the top level of `/tally/v1/info`. With
757
+ * `register >= 3`, a close whose absolute cash variance is over `thresholdMinor` needs the store's approval.
758
+ * Absent means the store sets none, and the app's own threshold applies.
759
+ */
760
+ registerApproval?: {
761
+ thresholdMinor: number;
762
+ };
586
763
  }
587
764
  /** #287, ADR-071. `custom`: the till computes as when absent; that server never emits `figures_mismatch` for subtotal or tax. */
588
765
  type TaxRounding = {
@@ -617,6 +794,7 @@ declare function parseLineTax(value: unknown, warn?: (reason: string) => void):
617
794
  * Reads a 2xx body of `GET /tally/v1/info` (ADR-062): `orderCreate` is the max of
618
795
  * `contracts["order.create"]`, or 1 when it's missing or malformed; `register` is the max of
619
796
  * `contracts.register` when valid; `taxRounding` is the top-level sibling of `contracts` (#287); malformed `lineTax` is ignored.
797
+ * malformed `registerApproval` is ignored (ADR-082).
620
798
  * `orderRefund` is the max of `contracts["order.refund"]` when valid, otherwise absent (ADR-080).
621
799
  * Absent `taxRounding` uses the default; a present malformed value is unknown, so settings wait.
622
800
  * A non-object body is also unknown, not a statement of the store's defaults.
@@ -757,12 +935,23 @@ interface TallyConnector {
757
935
  * `unauthorized` or `invalid_credentials` means sign in again), never on its class.
758
936
  */
759
937
  capabilities?: (context: SyncContext) => Promise<ServerCapabilities | undefined>;
938
+ /**
939
+ * The payment methods the till may offer, in the order it shows them (v2 parity A2). Read-only, never writes to
940
+ * the store. `undefined` when the connector has none of its own: the till offers `defaultPaymentMethods()`.
941
+ */
942
+ paymentMethods?: (context: SyncContext) => Promise<PaymentMethodDescriptor[]>;
760
943
  /** Customer search: online only; `undefined` when the connector has no customer support. */
761
944
  searchCustomers?: (context: SyncContext, query: string, options?: {
762
945
  limit?: number;
763
946
  }) => Promise<Customer[]>;
764
947
  /** Customer creation: online only; `undefined` when the connector has no customer support. */
765
948
  createCustomer?: (context: SyncContext, input: CustomerInput) => Promise<Customer>;
949
+ /**
950
+ * Customer edit: online only; resolves the customer as the store now has it. Rejects with
951
+ * `ConnectorUnauthorizedError` for credentials and `CustomerServiceError` (`invalid` for a refused patch or an id
952
+ * the store does not have, `server` or `network` otherwise). `undefined` when the connector can't edit customers.
953
+ */
954
+ updateCustomer?: (context: SyncContext, id: string, patch: CustomerPatch) => Promise<Customer>;
766
955
  /** Customer lookup: online only; `undefined` when the connector has no customer support. */
767
956
  getCustomer?: (context: SyncContext, id: string) => Promise<Customer | null>;
768
957
  /**
@@ -787,6 +976,18 @@ interface TallyConnector {
787
976
  * read-only; rejects as `listOrders`. `undefined` when the connector has no order history.
788
977
  */
789
978
  getOrders?: (context: SyncContext, ids: readonly string[]) => Promise<StoreOrder[]>;
979
+ /**
980
+ * The store's register directory (v2 parity A4): online only, read-only. Rejects with `ConnectorUnauthorizedError`
981
+ * for credentials; a connector's own errors otherwise. `undefined` when the connector has no register directory.
982
+ */
983
+ listRegisters?: (context: SyncContext) => Promise<RegisterInfo[]>;
984
+ /**
985
+ * The signed-in cashier and their neutral POS permissions (v2 parity A12), mapped from the platform's own roles or
986
+ * capabilities. Read-only. `null` when the connector has no cashier to describe; `undefined` (no method) when the
987
+ * connector has no permission model: the till then allows everything, as before (`can` in `@tallyui/pos`).
988
+ * Permission names outside `CashierPermission` are dropped by `useCashier` (`cashierPermissions`).
989
+ */
990
+ cashier?: (context: SyncContext) => Promise<Cashier | null>;
790
991
  }
791
992
 
792
993
  /**
@@ -1653,4 +1854,4 @@ declare namespace index {
1653
1854
  export { type index_CouponContext as CouponContext, type index_CouponDiscountConfig as CouponDiscountConfig, type index_CouponInput as CouponInput, type index_CouponLineInput as CouponLineInput, type index_CouponRejection as CouponRejection, type index_CouponRejectionCode as CouponRejectionCode, type index_CouponValidationContext as CouponValidationContext, type index_EngineWarning as EngineWarning, type index_LineItemInput as LineItemInput, type index_OrderTotals as OrderTotals, type index_RecalculateInput as RecalculateInput, type index_RecalculateResult as RecalculateResult, type index_TaxRateInput as TaxRateInput, type index_ValidationResult as ValidationResult, index_calculateOrderTotals as calculateOrderTotals, index_enrichCategoriesWithAncestors as enrichCategoriesWithAncestors, index_recalculateCoupons as recalculateCoupons, index_toCouponConfigs as toCouponConfigs, index_validateCoupon as validateCoupon };
1654
1855
  }
1655
1856
 
1656
- export { type AuthField, type CatalogueReconcileAdapter, type CatalogueReconcileEntry, type CollectionSync, CommandWarning, type ConnectorAuth, ConnectorProvider, type ConnectorProviderProps, type ConnectorSchemas, type ConnectorTraits, ConnectorUnauthorizedError, type Customer, type CustomerInput, CustomerServiceError, type CustomerTraits, type ErrorKind, type FingerprintReconcileAdapter, type IdReconcileAdapter, type KeyedReconcileFeedOptions, type ListOrdersQuery, type Money, PaymentMethodKind, type ProductCategory, type ProductPrice, type ProductTraits, type ReconcileFeed, type ReconcileFeedEntry, type ReconcileFetchEntry, type RemoteIdEntry, type ReplicationAdapter, type ResolvedPrice, STOCK_LEVELS_LAST_PASS, type ServerCapabilities, SignInError, type SignInErrorCode, type SignInResult, type StockLevel, type StockReconcileAdapter, type StockStatus, type StoreOrder, type StoreOrderCharge, type StoreOrderLine, type StoreOrderPage, type StoreOrderPayment, type StoreOrderRefund, type StoreSettings, type StoreSettingsChoice, type StoreSettingsChoices, StoreSettingsError, type StoreSettingsErrorCode, type SyncContext, type SyncNotice, type TallyConnector, type TaxRounding, type TraitContext, type VariantOptionGroup, type VariantSummary, combinePullAdapters, compareIds, createReconcileFeed, currencySymbol, customerTraits, errorKind, findVariantByCode, formatMoney, getProductStock, isRxdbRemoteVersionMismatch, knownWarnings, minorUnitDigits, moneyFromDecimalString, moneyFromMajor, moneyToMajor, parseInfoCapabilities, parseLineTax, parseTaxRounding, resolveCapabilities, resolvePrice, resolvePriceRange, useConnector, useCustomerTraits, useProductStock, useProductTraits, useStockOverlaid, useStockOverlayAsOf, useTraitContext, withStockOverlay, index as woocommerceCoupons, index$1 as woocommerceTax };
1857
+ export { type AuthField, CASHIER_PERMISSIONS, type CaptureMode, type CaptureModeEntry, type Cashier, type CashierPermission, type CatalogueReconcileAdapter, type CatalogueReconcileEntry, type CollectionSync, CommandWarning, type ConnectorAuth, ConnectorProvider, type ConnectorProviderProps, type ConnectorSchemas, type ConnectorTraits, ConnectorUnauthorizedError, type Customer, type CustomerAddress, type CustomerInput, type CustomerPatch, CustomerServiceError, type CustomerTaxId, type CustomerTraits, type ErrorKind, type FingerprintReconcileAdapter, type IdReconcileAdapter, type KeyedReconcileFeedOptions, type ListOrdersQuery, type Money, type PaymentHardware, type PaymentKind, type PaymentMethodDescriptor, PaymentMethodKind, type PaymentOfflineMode, type PaymentRounding, type PaymentTipsMode, type PaymentTransport, type ProductCategory, type ProductPrice, type ProductTraits, type ReconcileFeed, type ReconcileFeedEntry, type ReconcileFetchEntry, type RegisterInfo, type RemoteIdEntry, type ReplicationAdapter, type ResolvedPrice, STOCK_LEVELS_LAST_PASS, type ServerCapabilities, SignInError, type SignInErrorCode, type SignInResult, type StockLevel, type StockReconcileAdapter, type StockStatus, type StoreOrder, type StoreOrderCharge, type StoreOrderLine, type StoreOrderPage, type StoreOrderPayment, type StoreOrderRefund, type StoreSettings, type StoreSettingsChoice, type StoreSettingsChoices, StoreSettingsError, type StoreSettingsErrorCode, type SyncContext, type SyncNotice, type TallyConnector, type TaxRounding, type TraitContext, type VariantOptionGroup, type VariantSummary, cashierPermissions, combinePullAdapters, compareIds, createReconcileFeed, currencySymbol, customerTraits, defaultPaymentMethods, errorKind, findVariantByCode, formatMoney, getProductStock, isCashierPermission, isRxdbRemoteVersionMismatch, knownWarnings, minorUnitDigits, moneyFromDecimalString, moneyFromMajor, moneyToMajor, parseInfoCapabilities, parseLineTax, parseTaxRounding, paymentMethodOf, resolveCapabilities, resolvePrice, resolvePriceRange, useConnector, useCustomerTraits, useProductStock, useProductTraits, useStockOverlaid, useStockOverlayAsOf, useTraitContext, withStockOverlay, index as woocommerceCoupons, index$1 as woocommerceTax };
package/dist/index.js CHANGED
@@ -2,11 +2,12 @@ import {
2
2
  COMMANDS_PATH,
3
3
  CommandResultError,
4
4
  MAX_COMMANDS_PER_BATCH,
5
+ ORDER_NOTE_MAX,
5
6
  PROTOCOL_HEADER,
6
7
  PROTOCOL_VERSION,
7
8
  isCommandBatchResponse,
8
9
  parseCommandResult
9
- } from "./chunk-UFWXJAMF.js";
10
+ } from "./chunk-CSXNXRBA.js";
10
11
  import {
11
12
  __export
12
13
  } from "./chunk-MLKGABMK.js";
@@ -39,6 +40,15 @@ function parseLineTax(value, warn) {
39
40
  warn?.("ignoring a malformed lineTax");
40
41
  return void 0;
41
42
  }
43
+ function parseRegisterApproval(value, warn) {
44
+ if (value === void 0) return void 0;
45
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
46
+ const { thresholdMinor } = value;
47
+ if (typeof thresholdMinor === "number" && Number.isSafeInteger(thresholdMinor) && thresholdMinor >= 0) return { thresholdMinor };
48
+ }
49
+ warn?.("ignoring a malformed registerApproval");
50
+ return void 0;
51
+ }
42
52
  var maxVersion = (list) => {
43
53
  const valid = Array.isArray(list) ? list.filter((v) => typeof v === "number" && Number.isSafeInteger(v) && v > 0) : [];
44
54
  return valid.length > 0 ? Math.max(...valid) : void 0;
@@ -48,7 +58,7 @@ function parseInfoCapabilities(body, warn) {
48
58
  warn?.("non-object info body: capabilities unknown");
49
59
  return void 0;
50
60
  }
51
- const { contracts, taxRounding, lineTax } = body;
61
+ const { contracts, taxRounding, lineTax, registerApproval } = body;
52
62
  const register = maxVersion(contracts?.register);
53
63
  const orderRefund = maxVersion(contracts?.["order.refund"]);
54
64
  const rounding = parseTaxRounding(taxRounding);
@@ -57,12 +67,14 @@ function parseInfoCapabilities(body, warn) {
57
67
  return void 0;
58
68
  }
59
69
  const parsedLineTax = parseLineTax(lineTax, warn);
70
+ const parsed = parseRegisterApproval(registerApproval, warn);
60
71
  return {
61
72
  orderCreate: maxVersion(contracts?.["order.create"]) ?? 1,
62
73
  ...orderRefund !== void 0 ? { orderRefund } : {},
63
74
  ...register !== void 0 ? { register } : {},
64
75
  ...rounding ? { taxRounding: rounding } : {},
65
- ...parsedLineTax ? { lineTax: parsedLineTax } : {}
76
+ ...parsedLineTax ? { lineTax: parsedLineTax } : {},
77
+ ...parsed ? { registerApproval: parsed } : {}
66
78
  };
67
79
  }
68
80
 
@@ -136,13 +148,47 @@ var customerTraits = {
136
148
  getAddressSummary: () => void 0
137
149
  };
138
150
  var CustomerServiceError = class extends Error {
139
- constructor(code, message) {
151
+ constructor(code, message, options) {
140
152
  super(message);
141
153
  this.code = code;
142
154
  this.name = "CustomerServiceError";
155
+ this.status = options?.status;
143
156
  }
157
+ /** The HTTP status the store answered with, when the connector has it; undefined for a network failure (no response). */
158
+ status;
144
159
  };
145
160
 
161
+ // src/types/payment-methods.ts
162
+ function paymentMethodOf(kind) {
163
+ return {
164
+ id: kind,
165
+ title: kind === "cash" ? "Cash" : "Card terminal",
166
+ kind: kind === "cash" ? "cash" : "card",
167
+ capture: { mode: "manual", provider: null, hardware: null },
168
+ capabilities: {
169
+ amount: { partial: true },
170
+ change: kind === "cash",
171
+ refunds: { via: "manual", partial: true },
172
+ tips: "none",
173
+ offline: "record",
174
+ void: true
175
+ },
176
+ defaults: { rounding: null, openDrawer: kind === "cash" }
177
+ };
178
+ }
179
+ function defaultPaymentMethods() {
180
+ return [paymentMethodOf("cash"), paymentMethodOf("external")];
181
+ }
182
+
183
+ // src/types/cashier.ts
184
+ var CASHIER_PERMISSIONS = ["viewReports", "manageClosures", "approveVariance", "refund", "discount"];
185
+ function isCashierPermission(value) {
186
+ return CASHIER_PERMISSIONS.includes(value);
187
+ }
188
+ function cashierPermissions(values) {
189
+ return [...new Set(values.filter(isCashierPermission))];
190
+ }
191
+
146
192
  // src/money.ts
147
193
  var digitsCache = /* @__PURE__ */ new Map();
148
194
  function minorUnitDigits(currency) {
@@ -1751,26 +1797,31 @@ function toCouponConfigs(codes, coupons) {
1751
1797
  return couponConfigs;
1752
1798
  }
1753
1799
  export {
1800
+ CASHIER_PERMISSIONS,
1754
1801
  COMMANDS_PATH,
1755
1802
  CommandResultError,
1756
1803
  ConnectorProvider,
1757
1804
  ConnectorUnauthorizedError,
1758
1805
  CustomerServiceError,
1759
1806
  MAX_COMMANDS_PER_BATCH,
1807
+ ORDER_NOTE_MAX,
1760
1808
  PROTOCOL_HEADER,
1761
1809
  PROTOCOL_VERSION,
1762
1810
  STOCK_LEVELS_LAST_PASS,
1763
1811
  SignInError,
1764
1812
  StoreSettingsError,
1813
+ cashierPermissions,
1765
1814
  combinePullAdapters,
1766
1815
  compareIds,
1767
1816
  createReconcileFeed,
1768
1817
  currencySymbol,
1769
1818
  customerTraits,
1819
+ defaultPaymentMethods,
1770
1820
  errorKind,
1771
1821
  findVariantByCode,
1772
1822
  formatMoney,
1773
1823
  getProductStock,
1824
+ isCashierPermission,
1774
1825
  isCommandBatchResponse,
1775
1826
  isRxdbRemoteVersionMismatch,
1776
1827
  knownWarnings,
@@ -1782,6 +1833,7 @@ export {
1782
1833
  parseInfoCapabilities,
1783
1834
  parseLineTax,
1784
1835
  parseTaxRounding,
1836
+ paymentMethodOf,
1785
1837
  resolveCapabilities,
1786
1838
  resolvePrice,
1787
1839
  resolvePriceRange,
@@ -1,5 +1,5 @@
1
- import { e as CommandError, o as OrderCreatePayload, d as CommandEnvelope, G as RegisterCommandEnvelope, A as AnyCommandEnvelope, f as CommandResult, B as BatchTooLargeBody, c as CommandBatchResponse, C as CommandWarning, H as RegisterCommandResult, z as OrderRefundRejectionCode } from '../command-result-CrM7yjwk.js';
2
- export { g as CommandResultError, M as MAX_COMMANDS_PER_BATCH, l as OrderCreateDisplay, q as OrderCreateTaxRate, U as parseCommandResult } from '../command-result-CrM7yjwk.js';
1
+ import { e as CommandError, p as OrderCreatePayload, d as CommandEnvelope, J as RegisterCommandEnvelope, A as AnyCommandEnvelope, f as CommandResult, B as BatchTooLargeBody, c as CommandBatchResponse, C as CommandWarning, K as RegisterCommandResult, D as OrderRefundRejectionCode } from '../command-result-CoCa8PXJ.js';
2
+ export { g as CommandResultError, M as MAX_COMMANDS_PER_BATCH, O as ORDER_NOTE_MAX, m as OrderCreateDisplay, r as OrderCreateTaxRate, X as parseCommandResult } from '../command-result-CoCa8PXJ.js';
3
3
 
4
4
  /** ISO 4217 minor-unit exponent as resolved by Intl (which rejects malformed codes); depends on the runtime's ICU data. */
5
5
  declare function currencyDecimals(currency: string): number;
@@ -26,7 +26,7 @@ declare function commandFingerprint(envelope: {
26
26
  declare function payloadShapeErrors(payload: unknown): string[];
27
27
  /** Length-bound errors of an order.create payload, e.g. ['lines[0].title: expected at most 255
28
28
  * characters']; [] when every string is within its bound, at most ten. Bounds in UTF-16 code units:
29
- * `customer.email` 254, v5 ids 36 and class/sku/method 64, other strings 255 (`customerId` and `sessionId` keep theirs in
29
+ * `note` ORDER_NOTE_MAX (1000), `customer.email` 254, v5 ids 36 and class/sku/method 64, other strings 255 (`customerId` and `sessionId` keep theirs in
30
30
  * payloadShapeErrors); only strings are checked. A plugin calls it through precheckCommand, after
31
31
  * its replay lookup, so a bound tightened later never turns an applied command's resend into
32
32
  * `invalid_payload`. */
@@ -43,6 +43,9 @@ declare function fiscalFiguresErrors(payload: OrderCreatePayloadV3): string[];
43
43
  * supports (#297). A server passes its own lists to `precheckCommand`, and its /info advertises them, gated by its
44
44
  * own check (Front desk, 2026-09-30): 4 (#286) is 3 with every discountMinor tax-exclusive, and a plugin
45
45
  * advertises it only once it handles it.
46
+ * 5 (ADR-075) adds fees, shipping and custom lines; 6 (ADR-077) adds coupons, regular prices, line
47
+ * attributes and Any picks (#495); a plugin advertises each only once it handles it.
48
+ * 7 (ADR-083) adds the sale note.
46
49
  */
47
50
  declare const SUPPORTED_ORDER_CREATE_VERSIONS: readonly number[];
48
51
  /** The till's capability for the contract versions shared by all five register commands; a server passes its own. */
@@ -165,7 +168,7 @@ declare function deriveSessionFigures(input: {
165
168
  };
166
169
  declare function deriveVariance(counted: Record<string, number>, expected: Record<string, number>): Record<string, number>;
167
170
 
168
- type RegisterConflictCode = 'register_session_already_open' | 'register_session_superseded' | 'register_supersede_forbidden' | 'register_session_closed' | 'register_closure_exists' | 'register_closure_number_invalid';
171
+ type RegisterConflictCode = 'register_session_already_open' | 'register_session_superseded' | 'register_supersede_forbidden' | 'register_session_closed' | 'register_closure_exists' | 'register_closure_number_invalid' | 'register_approval_required' | 'register_approval_invalid';
169
172
  type RegisterOutcome = {
170
173
  kind: 'ok';
171
174
  register: RegisterCommandResult;
@@ -178,8 +181,7 @@ type RegisterOutcome = {
178
181
  message: string;
179
182
  };
180
183
 
181
- /** Every error.code a plugin may put on a rejected result (ADR-038 and its amendments, ADR-068),
182
- * except `register_approval_required`, which arrives with registers c2c. */
184
+ /** Every error.code a plugin may put on a rejected result (ADR-038 and its amendments, ADR-068, ADR-082). */
183
185
  type CommandRejectionCode = 'invalid_payload' | 'unsupported_version' | 'idempotency_mismatch' | 'store_configuration' | 'platform_error' | 'insufficient_stock' | 'unsupported_tax_mode' | 'internal_error' | 'coupon_invalid' | 'total_mismatch' | OrderRejectionCode | RegisterConflictCode | OrderRefundRejectionCode;
184
186
  /**
185
187
  * The rejected result for a platform-native error the plugin has judged permanent (a replay would fail
@@ -1,8 +1,9 @@
1
1
  import {
2
2
  CommandResultError,
3
3
  MAX_COMMANDS_PER_BATCH,
4
+ ORDER_NOTE_MAX,
4
5
  parseCommandResult
5
- } from "../chunk-UFWXJAMF.js";
6
+ } from "../chunk-CSXNXRBA.js";
6
7
  import "../chunk-MLKGABMK.js";
7
8
 
8
9
  // src/server/money.ts
@@ -119,6 +120,7 @@ function payloadShapeErrors(payload) {
119
120
  for (const field of ["registerId", "cashierRef", "locationId"]) {
120
121
  if (payload[field] !== void 0) check(typeof payload[field] === "string", field, "a string");
121
122
  }
123
+ if (payload.note !== void 0) check(typeof payload.note === "string" && payload.note.length > 0, "note", "a non-empty string");
122
124
  for (const field of ["fees", "shipping", "lines"]) {
123
125
  const items = payload[field];
124
126
  if (items === void 0 || field === "lines" && !Array.isArray(items)) continue;
@@ -202,6 +204,7 @@ function payloadStrings(payload) {
202
204
  const found = [];
203
205
  const object = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
204
206
  for (const field of ["clientOrderId", "createdAt", "currency", "registerId", "cashierRef", "locationId"]) found.push([payload[field], field, 255]);
207
+ found.push([payload.note, "note", ORDER_NOTE_MAX]);
205
208
  for (const field of ["lines", "payments"]) {
206
209
  const items = payload[field];
207
210
  if (Array.isArray(items)) items.forEach((item, index) => {
@@ -348,7 +351,7 @@ function fiscalFiguresErrors(payload) {
348
351
  }
349
352
 
350
353
  // src/server/versions.ts
351
- var SUPPORTED_ORDER_CREATE_VERSIONS = [1, 2, 3, 4];
354
+ var SUPPORTED_ORDER_CREATE_VERSIONS = [1, 2, 3, 4, 5, 6, 7];
352
355
  var SUPPORTED_REGISTER_VERSIONS = [1];
353
356
  var SUPPORTED_ORDER_REFUND_VERSIONS = [1];
354
357
 
@@ -438,7 +441,7 @@ function precheckCommand(envelope, supported) {
438
441
  if (line?.[field] !== void 0) v6Fields.push(`lines[${index}].${field}`);
439
442
  }
440
443
  });
441
- let versionError = command.version < 5 && v5Fields.length ? v5Fields.map((field) => `${field} requires version 5`).join("; ") : command.version < 6 && v6Fields.length ? v6Fields.map((field) => `${field} requires version 6`).join("; ") : command.version === 2 && discountMinor === void 0 ? "version 2 requires discountMinor" : command.version === 1 && discounted ? "discountMinor requires version 2" : !v3 && (display !== void 0 || taxByRate !== void 0) ? "display and taxByRate require version 3" : !v3 && sessionId !== void 0 ? "sessionId requires version 3" : !v3 && payload.customer?.customerId !== void 0 ? "customerId requires version 3" : v3 && display !== void 0 !== (taxByRate !== void 0) ? "display and taxByRate must both be present or both absent" : void 0;
444
+ let versionError = command.version < 5 && v5Fields.length ? v5Fields.map((field) => `${field} requires version 5`).join("; ") : command.version < 6 && v6Fields.length ? v6Fields.map((field) => `${field} requires version 6`).join("; ") : command.version < 7 && payload.note !== void 0 ? "note requires version 7" : command.version === 2 && discountMinor === void 0 ? "version 2 requires discountMinor" : command.version === 1 && discounted ? "discountMinor requires version 2" : !v3 && (display !== void 0 || taxByRate !== void 0) ? "display and taxByRate require version 3" : !v3 && sessionId !== void 0 ? "sessionId requires version 3" : !v3 && payload.customer?.customerId !== void 0 ? "customerId requires version 3" : v3 && display !== void 0 !== (taxByRate !== void 0) ? "display and taxByRate must both be present or both absent" : void 0;
442
445
  if (!versionError && Array.isArray(lines)) for (const [index, line] of lines.entries()) {
443
446
  if (line?.custom === void 0 && (typeof line?.variantId !== "string" || !line.variantId.length)) {
444
447
  versionError = `lines[${index}].variantId is required`;
@@ -558,6 +561,10 @@ function registerPayloadErrors(type, payload) {
558
561
  case "register.closure.submit":
559
562
  for (const field of ["closureId", "registerId", "openedAt", "closedAt", "softwareVersion"]) string(field);
560
563
  for (const field of ["businessDay", "closedBy", "approvedBy"]) string(field, true);
564
+ if (payload.approval !== void 0) {
565
+ check(typeof payload.approval === "string" && payload.approval.length > 0, "approval", "a non-empty string");
566
+ noNul(payload.approval, "approval");
567
+ }
561
568
  integer("number", 1);
562
569
  for (const field of [
563
570
  "periodSalesTotalMinor",
@@ -720,6 +727,7 @@ function internalErrorResult(id, correlationId) {
720
727
  export {
721
728
  CommandResultError,
722
729
  MAX_COMMANDS_PER_BATCH,
730
+ ORDER_NOTE_MAX,
723
731
  SUPPORTED_ORDER_CREATE_VERSIONS,
724
732
  SUPPORTED_ORDER_REFUND_VERSIONS,
725
733
  SUPPORTED_REGISTER_VERSIONS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tallyui/core",
3
- "version": "3.12.0",
3
+ "version": "3.13.0",
4
4
  "type": "module",
5
5
  "description": "Core interfaces, traits, and context providers for Tally UI",
6
6
  "main": "./dist/index.js",
package/src/commands.ts CHANGED
@@ -8,6 +8,8 @@ export const PROTOCOL_HEADER = 'X-Tally-Protocol';
8
8
  export const PROTOCOL_VERSION = 1;
9
9
  /** The ADR-038 batch limit; a server answers more with 413 and a BatchTooLargeBody. */
10
10
  export const MAX_COMMANDS_PER_BATCH = 50;
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
+ export const ORDER_NOTE_MAX = 1000;
11
13
 
12
14
  /**
13
15
  * True if `value` has the shape of a CommandBatchResponse: an object with a
package/src/index.ts CHANGED
@@ -35,10 +35,17 @@ export { isRxdbRemoteVersionMismatch } from './rxdb-remote-version-mismatch';
35
35
  export { errorKind, type ErrorKind, type SyncNotice } from './sync-notice';
36
36
  export type { SignInErrorCode } from './sign-in';
37
37
  export { StoreSettingsError } from './store-settings';
38
- export { customerTraits, CustomerServiceError, type Customer, type CustomerInput } from './types/customers';
38
+ export { customerTraits, CustomerServiceError, type Customer, type CustomerInput, type CustomerAddress, type CustomerTaxId, type CustomerPatch } from './types/customers';
39
+ export { paymentMethodOf, defaultPaymentMethods } from './types/payment-methods';
40
+ export type {
41
+ PaymentMethodDescriptor, PaymentKind, CaptureMode, CaptureModeEntry, PaymentHardware, PaymentTransport,
42
+ PaymentOfflineMode, PaymentTipsMode, PaymentRounding,
43
+ } from './types/payment-methods';
39
44
  export type {
40
45
  StoreOrder, StoreOrderLine, StoreOrderCharge, StoreOrderPayment, StoreOrderRefund, ListOrdersQuery, StoreOrderPage,
41
46
  } from './types/orders';
47
+ export type { RegisterInfo } from './types/registers';
48
+ export { CASHIER_PERMISSIONS, cashierPermissions, isCashierPermission, type Cashier, type CashierPermission } from './types/cashier';
42
49
  export type { StoreSettingsErrorCode, StoreSettingsChoices } from './store-settings';
43
50
 
44
51
  export type {
@@ -52,12 +59,13 @@ export type {
52
59
  OrderCreateCoupon, OrderCreateCouponInvalidData, OrderCreateTotalMismatchData,
53
60
  CommandBatchRequest, CommandBatchResponse, BatchTooLargeBody,
54
61
  RegisterCommandResult, RegisterSessionOpenPayload, RegisterSessionAlreadyOpenData, RegisterSessionSupersededData,
62
+ RegisterApprovalRequiredData, RegisterApprovalInvalidData,
55
63
  RegisterSessionTransitionPayload,
56
64
  RegisterMovementRecordPayload, RegisterMovementVoidPayload, RegisterClosureSubmitPayload,
57
65
  } from './types';
58
66
 
59
67
  export {
60
- COMMANDS_PATH, PROTOCOL_HEADER, PROTOCOL_VERSION, MAX_COMMANDS_PER_BATCH,
68
+ COMMANDS_PATH, PROTOCOL_HEADER, PROTOCOL_VERSION, MAX_COMMANDS_PER_BATCH, ORDER_NOTE_MAX,
61
69
  isCommandBatchResponse,
62
70
  } from './commands';
63
71
 
@@ -114,6 +114,7 @@ export function precheckCommand(envelope: Pick<AnyCommandEnvelope | ValidatedCom
114
114
  })
115
115
  let versionError = command.version < 5 && v5Fields.length ? v5Fields.map(field => `${field} requires version 5`).join('; ')
116
116
  : command.version < 6 && v6Fields.length ? v6Fields.map(field => `${field} requires version 6`).join('; ')
117
+ : command.version < 7 && payload.note !== undefined ? 'note requires version 7'
117
118
  : command.version === 2 && discountMinor === undefined ? 'version 2 requires discountMinor'
118
119
  : command.version === 1 && discounted ? 'discountMinor requires version 2'
119
120
  : !v3 && (display !== undefined || taxByRate !== undefined) ? 'display and taxByRate require version 3'
@@ -4,7 +4,7 @@ export { payloadBoundErrors, payloadShapeErrors } from './order-payload-shape'
4
4
  export { fiscalFiguresErrors } from './fiscal-figures'
5
5
  export type { CommandErrorWithData, OrderCreateDisplay, OrderCreateTaxRate, OrderCreatePayloadV3 } from './fiscal-figures'
6
6
  export { SUPPORTED_ORDER_CREATE_VERSIONS, SUPPORTED_REGISTER_VERSIONS, SUPPORTED_ORDER_REFUND_VERSIONS } from './versions'
7
- export { MAX_COMMANDS_PER_BATCH } from '../commands'
7
+ export { MAX_COMMANDS_PER_BATCH, ORDER_NOTE_MAX } from '../commands'
8
8
  export { validateBatch, precheckCommand } from './batch'
9
9
  export type { ValidatedCommandEnvelope } from './batch'
10
10
  export type { BatchTooLargeBody } from '../types'
@@ -1,3 +1,5 @@
1
+ import { ORDER_NOTE_MAX } from '../commands'
2
+
1
3
  /** Shape errors of an order.create payload, e.g. ['lines: expected a non-empty array',
2
4
  * 'payments[0].method: expected a string']; [] when the shape is valid, at most ten. Checks
3
5
  * presence, types, the `customerId` (64) and `sessionId` (36) bounds, and U+0000 in any string;
@@ -74,6 +76,7 @@ export function payloadShapeErrors(payload: unknown): string[] {
74
76
  for (const field of ['registerId', 'cashierRef', 'locationId']) {
75
77
  if (payload[field] !== undefined) check(typeof payload[field] === 'string', field, 'a string')
76
78
  }
79
+ if (payload.note !== undefined) check(typeof payload.note === 'string' && payload.note.length > 0, 'note', 'a non-empty string')
77
80
  for (const field of ['fees', 'shipping', 'lines']) {
78
81
  const items = payload[field]
79
82
  if (items === undefined || field === 'lines' && !Array.isArray(items)) continue
@@ -151,7 +154,7 @@ export function payloadShapeErrors(payload: unknown): string[] {
151
154
 
152
155
  /** Length-bound errors of an order.create payload, e.g. ['lines[0].title: expected at most 255
153
156
  * characters']; [] when every string is within its bound, at most ten. Bounds in UTF-16 code units:
154
- * `customer.email` 254, v5 ids 36 and class/sku/method 64, other strings 255 (`customerId` and `sessionId` keep theirs in
157
+ * `note` ORDER_NOTE_MAX (1000), `customer.email` 254, v5 ids 36 and class/sku/method 64, other strings 255 (`customerId` and `sessionId` keep theirs in
155
158
  * payloadShapeErrors); only strings are checked. A plugin calls it through precheckCommand, after
156
159
  * its replay lookup, so a bound tightened later never turns an applied command's resend into
157
160
  * `invalid_payload`. */
@@ -169,6 +172,7 @@ function payloadStrings(payload: Record<string, unknown>): Array<[string, string
169
172
  const object = (value: unknown): value is Record<string, unknown> =>
170
173
  typeof value === 'object' && value !== null && !Array.isArray(value)
171
174
  for (const field of ['clientOrderId', 'createdAt', 'currency', 'registerId', 'cashierRef', 'locationId']) found.push([payload[field], field, 255])
175
+ found.push([payload.note, 'note', ORDER_NOTE_MAX])
172
176
  for (const field of ['lines', 'payments']) {
173
177
  const items = payload[field]
174
178
  if (Array.isArray(items)) items.forEach((item, index) => {
@@ -7,6 +7,8 @@ export type RegisterConflictCode =
7
7
  | 'register_session_closed'
8
8
  | 'register_closure_exists'
9
9
  | 'register_closure_number_invalid'
10
+ | 'register_approval_required'
11
+ | 'register_approval_invalid'
10
12
 
11
13
  export type RegisterOutcome =
12
14
  | { kind: 'ok'; register: RegisterCommandResult }
@@ -74,6 +74,10 @@ export function registerPayloadErrors(type: string, payload: unknown): string[]
74
74
  case 'register.closure.submit':
75
75
  for (const field of ['closureId', 'registerId', 'openedAt', 'closedAt', 'softwareVersion']) string(field)
76
76
  for (const field of ['businessDay', 'closedBy', 'approvedBy']) string(field, true)
77
+ if (payload.approval !== undefined) {
78
+ check(typeof payload.approval === 'string' && payload.approval.length > 0, 'approval', 'a non-empty string')
79
+ noNul(payload.approval, 'approval')
80
+ }
77
81
  integer('number', 1)
78
82
  for (const field of ['periodSalesTotalMinor', 'periodRefundsTotalMinor', 'perpetualSalesTotalMinor',
79
83
  'perpetualRefundsTotalMinor', 'unsyncedCount', 'unsyncedTotalMinor']) integer(field, 0)
@@ -2,8 +2,7 @@ import type { CommandResult, OrderRefundRejectionCode } from '../types'
2
2
  import type { OrderRejectionCode } from './total-warnings'
3
3
  import type { RegisterConflictCode } from './register-outcome'
4
4
 
5
- /** Every error.code a plugin may put on a rejected result (ADR-038 and its amendments, ADR-068),
6
- * except `register_approval_required`, which arrives with registers c2c. */
5
+ /** Every error.code a plugin may put on a rejected result (ADR-038 and its amendments, ADR-068, ADR-082). */
7
6
  export type CommandRejectionCode =
8
7
  | 'invalid_payload' | 'unsupported_version' | 'idempotency_mismatch' | 'store_configuration' | 'platform_error'
9
8
  | 'insufficient_stock' | 'unsupported_tax_mode' | 'internal_error'
@@ -3,8 +3,11 @@
3
3
  * supports (#297). A server passes its own lists to `precheckCommand`, and its /info advertises them, gated by its
4
4
  * own check (Front desk, 2026-09-30): 4 (#286) is 3 with every discountMinor tax-exclusive, and a plugin
5
5
  * advertises it only once it handles it.
6
+ * 5 (ADR-075) adds fees, shipping and custom lines; 6 (ADR-077) adds coupons, regular prices, line
7
+ * attributes and Any picks (#495); a plugin advertises each only once it handles it.
8
+ * 7 (ADR-083) adds the sale note.
6
9
  */
7
- export const SUPPORTED_ORDER_CREATE_VERSIONS: readonly number[] = [1, 2, 3, 4]
10
+ export const SUPPORTED_ORDER_CREATE_VERSIONS: readonly number[] = [1, 2, 3, 4, 5, 6, 7]
8
11
  /** The till's capability for the contract versions shared by all five register commands; a server passes its own. */
9
12
  export const SUPPORTED_REGISTER_VERSIONS: readonly number[] = [1]
10
13
  /** The till's capability for order.refund versions (ADR-080); a server passes its own. */
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The neutral POS permissions a connector resolves from its own model (v2 parity A12):
3
+ * - `viewReports`: Reports, and a count that shows the expected figures (not blind);
4
+ * - `manageClosures`: recount and close without an approver;
5
+ * - `approveVariance`: approve another cashier's over-threshold count;
6
+ * - `refund`: take refunds;
7
+ * - `discount`: give discounts.
8
+ */
9
+ export const CASHIER_PERMISSIONS = ['viewReports', 'manageClosures', 'approveVariance', 'refund', 'discount'] as const;
10
+
11
+ /** One of `CASHIER_PERMISSIONS`. */
12
+ export type CashierPermission = (typeof CASHIER_PERMISSIONS)[number];
13
+
14
+ /** The signed-in cashier, as the connector maps the platform's user (v2 parity A12). */
15
+ export interface Cashier {
16
+ /** The platform's id for the signed-in user. */
17
+ id: string;
18
+ /** The display name, as receipts and the handover show it. */
19
+ name: string;
20
+ /** What this cashier may do; a permission left out is denied. */
21
+ permissions: readonly CashierPermission[];
22
+ }
23
+
24
+ /** Whether `value` is one of the five permission names. */
25
+ export function isCashierPermission(value: unknown): value is CashierPermission {
26
+ return (CASHIER_PERMISSIONS as readonly unknown[]).includes(value);
27
+ }
28
+
29
+ /** The known permission names in `values`, first occurrence order, without duplicates; anything else is dropped. */
30
+ export function cashierPermissions(values: readonly unknown[]): CashierPermission[] {
31
+ return [...new Set(values.filter(isCashierPermission))];
32
+ }
@@ -7,8 +7,9 @@ export interface CommandEnvelope<P = unknown> {
7
7
  type: CommandType;
8
8
  /** 3 when the order carries ADR-065's `display` and `taxByRate` (the store accepts 3), else 2 when discounted, else 1;
9
9
  * 4 is 3 with every `discountMinor` tax-exclusive, built only when capped at 4 or more (#286).
10
- * 5 is 4 plus fees, shipping and custom lines (ADR-075), sent only for an order that has one. */
11
- version: 1 | 2 | 3 | 4 | 5 | 6;
10
+ * 5 is 4 plus fees, shipping and custom lines (ADR-075), sent only for an order that has one.
11
+ * 7 is 6 plus the sale's `note` (ADR-083), sent only for an order that has one. */
12
+ version: 1 | 2 | 3 | 4 | 5 | 6 | 7;
12
13
  payload: P;
13
14
  createdAt: string; // ISO 8601, client clock
14
15
  deviceId: string;
@@ -54,8 +55,9 @@ export interface OrderRefundOrderStateData { state: string }
54
55
  /** The session that is not open on the refunding register (ADR-080). */
55
56
  export interface OrderRefundNoOpenSessionData { sessionId: string }
56
57
 
57
- /** An order.create envelope: 5 is 4 plus fees, shipping and custom lines (ADR-075), sent only for an order that has one. */
58
- export type OrderCreateEnvelope = CommandEnvelope<OrderCreatePayload> & { type: 'order.create'; version: 1 | 2 | 3 | 4 | 5 | 6 };
58
+ /** An order.create envelope: 5 is 4 plus fees, shipping and custom lines (ADR-075), sent only for an order that has one.
59
+ * 7 is 6 plus the sale's note (ADR-083). */
60
+ export type OrderCreateEnvelope = CommandEnvelope<OrderCreatePayload> & { type: 'order.create'; version: 1 | 2 | 3 | 4 | 5 | 6 | 7 };
59
61
 
60
62
  /** Outcome of processing a command. */
61
63
  export type CommandStatus = 'applied' | 'duplicate' | 'rejected';
@@ -192,6 +194,14 @@ export interface RegisterSessionSupersededData {
192
194
  sessionId: string; supersededAt?: string; supersededBy?: string;
193
195
  deviceId?: string; deviceName?: string; newSessionId?: string;
194
196
  }
197
+ /** error.data for register_approval_required (ADR-082 d6): variance is counted − tillExpected for each key of counted. */
198
+ export interface RegisterApprovalRequiredData {
199
+ sessionId: string; thresholdMinor: number; variance: Record<string, number>;
200
+ }
201
+ /** error.data for register_approval_invalid (ADR-082 d6). */
202
+ export interface RegisterApprovalInvalidData {
203
+ reason: 'unknown' | 'expired' | 'used' | 'session_mismatch' | 'variance_mismatch';
204
+ }
195
205
  export interface RegisterSessionTransitionPayload {
196
206
  sessionId: string; status: 'open' | 'counting' | 'closed'; at: string;
197
207
  /** Closing only. */ counted?: Record<string, number>; closedBy?: string; approvedBy?: string;
@@ -206,6 +216,7 @@ export interface RegisterMovementVoidPayload {
206
216
  export interface RegisterClosureSubmitPayload {
207
217
  closureId: string; sessionId: string; registerId: string; number: number; businessDay?: string;
208
218
  openedAt: string; closedAt: string; closedBy?: string; approvedBy?: string;
219
+ /** Register v3 only (ADR-082): the store's approval proof, opaque; never parsed, logged or stored in the Z. */ approval?: string;
209
220
  tillExpected: Record<string, number>; counted: Record<string, number>;
210
221
  periodSalesTotalMinor: number; periodRefundsTotalMinor: number;
211
222
  perpetualSalesTotalMinor: number; perpetualRefundsTotalMinor: number;
@@ -383,6 +394,8 @@ export interface OrderCreatePayload {
383
394
  locationId?: string;
384
395
  /** Version 3+: the register session the sale was taken for, stamped or late (ADR-032). A late sale names the session that refused its stamp; the server tells the two apart by the session's closure `orderIds`. Absent when the sale had no session. */
385
396
  sessionId?: string;
397
+ /** Version 7 (ADR-083): the sale's note, 1 to ORDER_NOTE_MAX UTF-16 units; omitted when the sale has none. */
398
+ note?: string;
386
399
  }
387
400
 
388
401
  /** Batch of commands submitted to the server. */
@@ -5,8 +5,11 @@ import type { CustomerTraits } from './traits/customer';
5
5
  import type { ReplicationAdapter } from './replication';
6
6
  import type { CatalogueReconcileAdapter, FingerprintReconcileAdapter, IdReconcileAdapter, StockReconcileAdapter } from './reconcile';
7
7
  import type { StoreSettings, StoreSettingsChoice } from './store-settings';
8
- import type { Customer, CustomerInput } from './customers';
8
+ import type { Customer, CustomerInput, CustomerPatch } from './customers';
9
9
  import type { ListOrdersQuery, StoreOrder, StoreOrderPage } from './orders';
10
+ import type { PaymentMethodDescriptor } from './payment-methods';
11
+ import type { RegisterInfo } from './registers';
12
+ import type { Cashier } from './cashier';
10
13
 
11
14
  /**
12
15
  * Authentication configuration for a connector.
@@ -60,6 +63,12 @@ export interface ServerCapabilities {
60
63
  * coupon. WooCommerce: true only when the woocommerce-pos plugin reports 1.9.0 or later.
61
64
  */
62
65
  coupons?: boolean;
66
+ /**
67
+ * The store's register approval threshold (ADR-082 d3), from the top level of `/tally/v1/info`. With
68
+ * `register >= 3`, a close whose absolute cash variance is over `thresholdMinor` needs the store's approval.
69
+ * Absent means the store sets none, and the app's own threshold applies.
70
+ */
71
+ registerApproval?: { thresholdMinor: number };
63
72
  }
64
73
 
65
74
  /** #287, ADR-071. `custom`: the till computes as when absent; that server never emits `figures_mismatch` for subtotal or tax. */
@@ -115,6 +124,16 @@ export function parseLineTax(value: unknown, warn?: (reason: string) => void): {
115
124
  return undefined;
116
125
  }
117
126
 
127
+ function parseRegisterApproval(value: unknown, warn?: (reason: string) => void): { thresholdMinor: number } | undefined {
128
+ if (value === undefined) return undefined;
129
+ if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
130
+ const { thresholdMinor } = value as { thresholdMinor?: unknown };
131
+ if (typeof thresholdMinor === 'number' && Number.isSafeInteger(thresholdMinor) && thresholdMinor >= 0) return { thresholdMinor };
132
+ }
133
+ warn?.('ignoring a malformed registerApproval');
134
+ return undefined;
135
+ }
136
+
118
137
  const maxVersion = (list: unknown): number | undefined => {
119
138
  const valid = Array.isArray(list) ? list.filter((v): v is number => typeof v === 'number' && Number.isSafeInteger(v) && v > 0) : [];
120
139
  return valid.length > 0 ? Math.max(...valid) : undefined;
@@ -124,6 +143,7 @@ const maxVersion = (list: unknown): number | undefined => {
124
143
  * Reads a 2xx body of `GET /tally/v1/info` (ADR-062): `orderCreate` is the max of
125
144
  * `contracts["order.create"]`, or 1 when it's missing or malformed; `register` is the max of
126
145
  * `contracts.register` when valid; `taxRounding` is the top-level sibling of `contracts` (#287); malformed `lineTax` is ignored.
146
+ * malformed `registerApproval` is ignored (ADR-082).
127
147
  * `orderRefund` is the max of `contracts["order.refund"]` when valid, otherwise absent (ADR-080).
128
148
  * Absent `taxRounding` uses the default; a present malformed value is unknown, so settings wait.
129
149
  * A non-object body is also unknown, not a statement of the store's defaults.
@@ -133,7 +153,7 @@ export function parseInfoCapabilities(body: unknown, warn?: (reason: string) =>
133
153
  warn?.('non-object info body: capabilities unknown');
134
154
  return undefined;
135
155
  }
136
- const { contracts, taxRounding, lineTax } = body as { contracts?: Record<string, unknown> | null; taxRounding?: unknown; lineTax?: unknown };
156
+ const { contracts, taxRounding, lineTax, registerApproval } = body as { contracts?: Record<string, unknown> | null; taxRounding?: unknown; lineTax?: unknown; registerApproval?: unknown };
137
157
  const register = maxVersion(contracts?.register);
138
158
  const orderRefund = maxVersion(contracts?.['order.refund']);
139
159
  const rounding = parseTaxRounding(taxRounding);
@@ -142,10 +162,12 @@ export function parseInfoCapabilities(body: unknown, warn?: (reason: string) =>
142
162
  return undefined;
143
163
  }
144
164
  const parsedLineTax = parseLineTax(lineTax, warn);
165
+ const parsed = parseRegisterApproval(registerApproval, warn);
145
166
  return { orderCreate: maxVersion(contracts?.['order.create']) ?? 1,
146
167
  ...(orderRefund !== undefined ? { orderRefund } : {}),
147
168
  ...(register !== undefined ? { register } : {}), ...(rounding ? { taxRounding: rounding } : {}),
148
- ...(parsedLineTax ? { lineTax: parsedLineTax } : {}) };
169
+ ...(parsedLineTax ? { lineTax: parsedLineTax } : {}),
170
+ ...(parsed ? { registerApproval: parsed } : {}) };
149
171
  }
150
172
 
151
173
  export interface AuthField {
@@ -298,10 +320,21 @@ export interface TallyConnector {
298
320
  * `unauthorized` or `invalid_credentials` means sign in again), never on its class.
299
321
  */
300
322
  capabilities?: (context: SyncContext) => Promise<ServerCapabilities | undefined>;
323
+ /**
324
+ * The payment methods the till may offer, in the order it shows them (v2 parity A2). Read-only, never writes to
325
+ * the store. `undefined` when the connector has none of its own: the till offers `defaultPaymentMethods()`.
326
+ */
327
+ paymentMethods?: (context: SyncContext) => Promise<PaymentMethodDescriptor[]>;
301
328
  /** Customer search: online only; `undefined` when the connector has no customer support. */
302
329
  searchCustomers?: (context: SyncContext, query: string, options?: { limit?: number }) => Promise<Customer[]>;
303
330
  /** Customer creation: online only; `undefined` when the connector has no customer support. */
304
331
  createCustomer?: (context: SyncContext, input: CustomerInput) => Promise<Customer>;
332
+ /**
333
+ * Customer edit: online only; resolves the customer as the store now has it. Rejects with
334
+ * `ConnectorUnauthorizedError` for credentials and `CustomerServiceError` (`invalid` for a refused patch or an id
335
+ * the store does not have, `server` or `network` otherwise). `undefined` when the connector can't edit customers.
336
+ */
337
+ updateCustomer?: (context: SyncContext, id: string, patch: CustomerPatch) => Promise<Customer>;
305
338
  /** Customer lookup: online only; `undefined` when the connector has no customer support. */
306
339
  getCustomer?: (context: SyncContext, id: string) => Promise<Customer | null>;
307
340
  /**
@@ -324,4 +357,16 @@ export interface TallyConnector {
324
357
  * read-only; rejects as `listOrders`. `undefined` when the connector has no order history.
325
358
  */
326
359
  getOrders?: (context: SyncContext, ids: readonly string[]) => Promise<StoreOrder[]>;
360
+ /**
361
+ * The store's register directory (v2 parity A4): online only, read-only. Rejects with `ConnectorUnauthorizedError`
362
+ * for credentials; a connector's own errors otherwise. `undefined` when the connector has no register directory.
363
+ */
364
+ listRegisters?: (context: SyncContext) => Promise<RegisterInfo[]>;
365
+ /**
366
+ * The signed-in cashier and their neutral POS permissions (v2 parity A12), mapped from the platform's own roles or
367
+ * capabilities. Read-only. `null` when the connector has no cashier to describe; `undefined` (no method) when the
368
+ * connector has no permission model: the till then allows everything, as before (`can` in `@tallyui/pos`).
369
+ * Permission names outside `CashierPermission` are dropped by `useCashier` (`cashierPermissions`).
370
+ */
371
+ cashier?: (context: SyncContext) => Promise<Cashier | null>;
327
372
  }
@@ -1,5 +1,18 @@
1
1
  import type { CustomerTraits } from './traits/customer';
2
2
 
3
+ /** A customer's postal address. Platform-neutral; every field optional. `country` is an ISO 3166-1 alpha-2 code. */
4
+ export interface CustomerAddress {
5
+ firstName?: string; lastName?: string; company?: string;
6
+ address1?: string; address2?: string; city?: string; state?: string; postcode?: string; country?: string;
7
+ phone?: string; email?: string;
8
+ }
9
+
10
+ /**
11
+ * A tax registration number (VAT, ABN, GST, EIN…). `type` is the connector's own id for the scheme; WCPOS v2's set is
12
+ * eu_vat, gb_vat, au_abn, br_cpf, br_cnpj, in_gst, it_cf, it_piva, es_nif, ar_cuit, sa_vat, ca_gst_hst, us_ein, other.
13
+ */
14
+ export interface CustomerTaxId { type: string; value: string; country?: string; label?: string }
15
+
3
16
  /** A store customer, as the till shows and picks it (programme item 14). Platform-neutral. */
4
17
  export interface Customer {
5
18
  /** The platform's id: order.create v3 sends it as `customer.customerId`. */
@@ -7,10 +20,20 @@ export interface Customer {
7
20
  /** Display name: first + last, else company, else email, else id. Never empty. */
8
21
  name: string;
9
22
  firstName?: string; lastName?: string; email?: string; phone?: string; company?: string;
23
+ billing?: CustomerAddress; shipping?: CustomerAddress; taxIds?: CustomerTaxId[];
24
+ }
25
+
26
+ /** What the till collects to create a customer. v1 requires an email; addresses and tax ids are optional. */
27
+ export interface CustomerInput {
28
+ email: string; firstName?: string; lastName?: string; phone?: string; company?: string;
29
+ billing?: CustomerAddress; shipping?: CustomerAddress; taxIds?: CustomerTaxId[];
10
30
  }
11
31
 
12
- /** What the till collects to create a customer. v1 requires an email. */
13
- export interface CustomerInput { email: string; firstName?: string; lastName?: string; phone?: string; company?: string }
32
+ /**
33
+ * A change to an existing customer: any subset of {@link CustomerInput}. A field left out is unchanged; `billing`,
34
+ * `shipping` and `taxIds`, when given, replace the stored value whole (`taxIds: []` removes every tax id).
35
+ */
36
+ export type CustomerPatch = Partial<CustomerInput>;
14
37
 
15
38
  export const customerTraits: CustomerTraits<Customer> = {
16
39
  getId: (customer) => customer.id,
@@ -22,5 +45,11 @@ export const customerTraits: CustomerTraits<Customer> = {
22
45
 
23
46
  /** A customer call that failed for a reason other than credentials (credentials throw ConnectorUnauthorizedError). */
24
47
  export class CustomerServiceError extends Error {
25
- constructor(readonly code: 'network' | 'server' | 'invalid', message: string) { super(message); this.name = 'CustomerServiceError'; }
48
+ /** The HTTP status the store answered with, when the connector has it; undefined for a network failure (no response). */
49
+ readonly status?: number;
50
+ constructor(readonly code: 'network' | 'server' | 'invalid', message: string, options?: { status?: number }) {
51
+ super(message);
52
+ this.name = 'CustomerServiceError';
53
+ this.status = options?.status;
54
+ }
26
55
  }
@@ -34,6 +34,7 @@ export type {
34
34
  OrderCreateCoupon, OrderCreateCouponInvalidData, OrderCreateTotalMismatchData,
35
35
  CommandBatchRequest, CommandBatchResponse, BatchTooLargeBody,
36
36
  RegisterCommandResult, RegisterSessionOpenPayload, RegisterSessionAlreadyOpenData, RegisterSessionSupersededData,
37
+ RegisterApprovalRequiredData, RegisterApprovalInvalidData,
37
38
  RegisterSessionTransitionPayload,
38
39
  RegisterMovementRecordPayload, RegisterMovementVoidPayload, RegisterClosureSubmitPayload,
39
40
  } from './commands';
@@ -0,0 +1,103 @@
1
+ import type { PaymentMethodKind } from './commands';
2
+
3
+ /**
4
+ * A payment method the till can offer, backend-neutral (a port of WCPOS v2's Payments Contract
5
+ * v1 descriptor, `order-math/src/payments/types.ts`). A connector maps its own model into it:
6
+ * WooCommerce gateways, Medusa payment providers, Vendure payment methods. Amounts are integer
7
+ * minor units of the store currency. Open vocabularies keep values this build has never seen, so
8
+ * the till can show such a method disabled instead of dropping it.
9
+ */
10
+
11
+ /** A known value, or any other string this build does not know yet. */
12
+ type OpenEnum<Known extends string> = Known | (string & {});
13
+
14
+ /** What kind of money the method takes. Not the order's wire method: that is `PaymentMethodKind`. */
15
+ export type PaymentKind = 'cash' | 'card' | 'stored_value' | 'bank_transfer' | 'other';
16
+
17
+ /** How the payment is taken. `manual`: the cashier records it (cash, a standalone terminal). */
18
+ export type CaptureMode = 'manual' | 'webview' | 'server' | 'device' | 'stored_value' | 'gateway';
19
+
20
+ /** The transport a payment terminal is reached over. */
21
+ export type PaymentTransport = 'bluetooth' | 'usb' | 'network' | 'tap_to_pay';
22
+
23
+ /** Whether a leg can be taken while the till is offline: recorded, queued to settle later, or not at all. */
24
+ export type PaymentOfflineMode = 'record' | 'queue' | 'none';
25
+
26
+ /** Where a tip is entered, if anywhere. */
27
+ export type PaymentTipsMode = 'none' | 'on_reader' | 'at_till';
28
+
29
+ /** The terminal hardware behind a method: readers the server lists, or transports an SDK discovers. */
30
+ export type PaymentHardware =
31
+ | {
32
+ discovery: OpenEnum<'server'>;
33
+ readers: { id: string; label: string; status: OpenEnum<'online' | 'offline'>; default: boolean }[];
34
+ defaultReader: string | null;
35
+ lockToDefault: boolean;
36
+ }
37
+ | {
38
+ discovery: OpenEnum<'sdk' | 'manual'>;
39
+ transports: { transport: OpenEnum<PaymentTransport>; offline: OpenEnum<PaymentOfflineMode>; tips: OpenEnum<PaymentTipsMode> }[];
40
+ };
41
+
42
+ /** One way to capture a method's payments. */
43
+ export interface CaptureModeEntry {
44
+ mode: OpenEnum<CaptureMode>;
45
+ /** The payment provider's own name, e.g. a terminal vendor; `null` for none. */
46
+ provider: string | null;
47
+ hardware: PaymentHardware | null;
48
+ }
49
+
50
+ /** Cash rounding for the method: the due amount rounds to a multiple of `incrementMinor`; `nearest` rounds half up. */
51
+ export type PaymentRounding = { incrementMinor: number; mode: 'nearest' | 'up' | 'down' } | null;
52
+
53
+ export interface PaymentMethodDescriptor {
54
+ /** The connector's own id for the method, stable across reads. */
55
+ id: string;
56
+ /** The name the till shows. */
57
+ title: string;
58
+ kind: OpenEnum<PaymentKind>;
59
+ capture: CaptureModeEntry & {
60
+ /** Every way the method can be captured, the primary first; absent when `mode` is the only one. */
61
+ modes?: CaptureModeEntry[];
62
+ };
63
+ capabilities: {
64
+ /** `partial`: the method may take less than the balance (a split leg). */
65
+ amount: { partial: boolean; minMinor?: number; maxMinor?: number };
66
+ /** Whether tendering more than is due gives change. */
67
+ change: boolean;
68
+ refunds: { via: OpenEnum<'provider' | 'manual' | 'device' | 'none'>; partial: boolean };
69
+ tips: OpenEnum<PaymentTipsMode>;
70
+ offline: OpenEnum<PaymentOfflineMode>;
71
+ /** Whether a taken leg can be voided. */
72
+ void: boolean;
73
+ };
74
+ defaults: {
75
+ rounding: PaymentRounding;
76
+ /** Whether taking the payment opens the cash drawer. */
77
+ openDrawer: boolean;
78
+ };
79
+ }
80
+
81
+ /** The descriptor of one of today's two wire methods: its `id` is the `PaymentMethodKind`. */
82
+ export function paymentMethodOf(kind: PaymentMethodKind): PaymentMethodDescriptor {
83
+ return {
84
+ id: kind,
85
+ title: kind === 'cash' ? 'Cash' : 'Card terminal',
86
+ kind: kind === 'cash' ? 'cash' : 'card',
87
+ capture: { mode: 'manual', provider: null, hardware: null },
88
+ capabilities: {
89
+ amount: { partial: true },
90
+ change: kind === 'cash',
91
+ refunds: { via: 'manual', partial: true },
92
+ tips: 'none',
93
+ offline: 'record',
94
+ void: true,
95
+ },
96
+ defaults: { rounding: null, openDrawer: kind === 'cash' },
97
+ };
98
+ }
99
+
100
+ /** Today's two methods, cash then the card terminal: what the till offers when the connector has no `paymentMethods`. */
101
+ export function defaultPaymentMethods(): PaymentMethodDescriptor[] {
102
+ return [paymentMethodOf('cash'), paymentMethodOf('external')];
103
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * A register (till) in the store's register directory (v2 parity A4). Platform-neutral: each connector maps its own
3
+ * register model onto it. Money is integer minor units of the store's currency.
4
+ * The cash variance threshold is not here: it is the store's (ADR-082, `capabilities.registerApproval`).
5
+ */
6
+ export interface RegisterInfo {
7
+ /** The platform's register id. */
8
+ id: string;
9
+ /** The register's display name, as the cashier picks it. */
10
+ name: string;
11
+ /** The cash the drawer should open with; absent when the store sets none. */
12
+ defaultFloatMinor?: number;
13
+ /** When the register is due to close: a local store time, `HH:MM` on a 24-hour clock; absent when the store sets none. */
14
+ expectedCloseTime?: string;
15
+ }