@tallyui/core 3.11.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;
@@ -338,6 +351,8 @@ interface OrderCreateLine {
338
351
  regularUnitPriceMinor?: number;
339
352
  /** Version 6 recorded: the variant's attribute names and values (#495), each at most 255 characters. */
340
353
  attributes?: Record<string, string>;
354
+ /** Version 6: the names in attributes the cashier picked for the variant's "Any" option groups (#495 c/d). */
355
+ anyAttributes?: string[];
341
356
  /**
342
357
  * This line's own tax mode, when it differs from the order's `pricesIncludeTax`
343
358
  * (a price that carries its own flag, D2c). Absent means the order's flag, so
@@ -482,6 +497,8 @@ interface OrderCreatePayload {
482
497
  locationId?: string;
483
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. */
484
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;
485
502
  }
486
503
  /** Batch of commands submitted to the server. */
487
504
  interface CommandBatchRequest<E extends AnyCommandEnvelope = CommandEnvelope> {
@@ -506,6 +523,8 @@ declare const PROTOCOL_HEADER = "X-Tally-Protocol";
506
523
  declare const PROTOCOL_VERSION = 1;
507
524
  /** The ADR-038 batch limit; a server answers more with 413 and a BatchTooLargeBody. */
508
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;
509
528
  /**
510
529
  * True if `value` has the shape of a CommandBatchResponse: an object with a
511
530
  * `results` array whose every entry has a string `id` and a `status` of
@@ -522,4 +541,4 @@ declare class CommandResultError extends Error {
522
541
  * CommandResultError naming the first bad field. */
523
542
  declare function parseCommandResult(value: unknown): CommandResult;
524
543
 
525
- export { type AnyCommandEnvelope as A, type BatchTooLargeBody as B, type CommandWarning as C, type OrderRefundResult as D, PROTOCOL_VERSION as E, type PaymentMethodKind 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, PROTOCOL_HEADER 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 { C as CommandWarning } from './command-result-DmHIPt6Z.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, P as PROTOCOL_HEADER, E as PROTOCOL_VERSION, F as PaymentMethodKind, 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-DmHIPt6Z.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,22 +434,265 @@ 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
+ });
466
+ }
467
+
468
+ /** A line of an order the store holds (ADR-081). Money in integer minor units of the order's currency, as the store
469
+ * records it: every amount excludes tax, and the tax is beside it.
470
+ * Each tax field is such that net + tax is the gross rounded once. */
471
+ interface StoreOrderLine {
472
+ /** The store's line id: what `OrderRefundLine.orderLineId` names. */
473
+ id: string;
474
+ /** The till's line id when a till created the line (its `clientLineId`); absent otherwise. */
475
+ clientLineId?: string;
476
+ productId?: string;
477
+ /** The sellable the till's `variantId` names (a WooCommerce variation, or the product itself when simple). */
478
+ variantId?: string;
479
+ name: string;
480
+ sku?: string;
481
+ quantity: number;
482
+ /** Before discounts, excluding tax. */
483
+ subtotalMinor: number;
484
+ subtotalTaxMinor: number;
485
+ /** After discounts, excluding tax. */
486
+ totalMinor: number;
487
+ taxMinor: number;
488
+ }
489
+ /** A fee or shipping line: excluding tax, the tax beside it. A fee may be negative.
490
+ * `taxMinor` is such that `totalMinor + taxMinor` is the gross rounded once. */
491
+ interface StoreOrderCharge {
492
+ name: string;
493
+ totalMinor: number;
494
+ taxMinor: number;
495
+ }
496
+ interface StoreOrderPayment {
497
+ /** The store's own method id, e.g. WooCommerce's `pos_cash`. */
498
+ method: string;
499
+ /** The store's name for it, e.g. "Cash". */
500
+ title?: string;
501
+ /** Set only when the method is one the till itself takes. */
502
+ kind?: PaymentMethodKind;
503
+ amountMinor: number;
504
+ }
505
+ /** A refund the store already recorded against the order. */
506
+ interface StoreOrderRefund {
507
+ id: string; /** Positive. */
508
+ amountMinor: number;
509
+ reason?: string;
510
+ }
511
+ /** An order as the store holds it, read online (ADR-081); never stored by the till. */
512
+ interface StoreOrder {
513
+ /** The store's order id: what `OrderRefundPayload.orderId` and `CommandServerRefs.orderId` carry. */
514
+ id: string;
515
+ /** The number the store shows (`CommandServerRefs.displayId`). */
516
+ reference: string;
517
+ /** The till's `PosOrder.id` when a till created the order; absent otherwise. */
518
+ clientOrderId?: string;
519
+ /** The platform's own status word (WooCommerce: `completed`, `refunded`, …); the app labels it. */
520
+ status: string;
521
+ /** ISO 8601, UTC. */
522
+ placedAt: string;
523
+ currency: string;
524
+ pricesIncludeTax: boolean;
525
+ customer: {
526
+ id?: string;
527
+ name?: string;
528
+ email?: string;
529
+ } | null;
530
+ lines: StoreOrderLine[];
531
+ fees: StoreOrderCharge[];
532
+ shipping: StoreOrderCharge[];
533
+ /** `discountMinor + discountTaxMinor` is the coupon's gross discount rounded once. */
534
+ coupons: Array<{
535
+ code: string;
536
+ discountMinor: number;
537
+ discountTaxMinor: number;
538
+ }>;
539
+ /** Tax by rate; `amountMinor` includes the rate's shipping tax. */
540
+ taxLines: Array<{
541
+ label: string;
542
+ code?: string;
543
+ ratePpm: number;
544
+ amountMinor: number;
545
+ }>;
546
+ discountMinor: number;
547
+ discountTaxMinor: number;
548
+ taxMinor: number;
549
+ totalMinor: number;
550
+ payments: StoreOrderPayment[];
551
+ refunds: StoreOrderRefund[];
552
+ }
553
+ interface ListOrdersQuery {
554
+ /** 1-based; default 1. */
555
+ page?: number;
556
+ /** 1..100; default 25. */
557
+ perPage?: number;
558
+ /** The platform's own order search. */
559
+ search?: string;
560
+ }
561
+ interface StoreOrderPage {
562
+ orders: StoreOrder[];
563
+ hasMore: boolean;
427
564
  }
428
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
+
429
696
  /**
430
697
  * Authentication configuration for a connector.
431
698
  * Each API has wildly different auth — JWT, API keys, OAuth, etc.
@@ -485,6 +752,14 @@ interface ServerCapabilities {
485
752
  * coupon. WooCommerce: true only when the woocommerce-pos plugin reports 1.9.0 or later.
486
753
  */
487
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
+ };
488
763
  }
489
764
  /** #287, ADR-071. `custom`: the till computes as when absent; that server never emits `figures_mismatch` for subtotal or tax. */
490
765
  type TaxRounding = {
@@ -519,6 +794,7 @@ declare function parseLineTax(value: unknown, warn?: (reason: string) => void):
519
794
  * Reads a 2xx body of `GET /tally/v1/info` (ADR-062): `orderCreate` is the max of
520
795
  * `contracts["order.create"]`, or 1 when it's missing or malformed; `register` is the max of
521
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).
522
798
  * `orderRefund` is the max of `contracts["order.refund"]` when valid, otherwise absent (ADR-080).
523
799
  * Absent `taxRounding` uses the default; a present malformed value is unknown, so settings wait.
524
800
  * A non-object body is also unknown, not a statement of the store's defaults.
@@ -659,12 +935,23 @@ interface TallyConnector {
659
935
  * `unauthorized` or `invalid_credentials` means sign in again), never on its class.
660
936
  */
661
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[]>;
662
943
  /** Customer search: online only; `undefined` when the connector has no customer support. */
663
944
  searchCustomers?: (context: SyncContext, query: string, options?: {
664
945
  limit?: number;
665
946
  }) => Promise<Customer[]>;
666
947
  /** Customer creation: online only; `undefined` when the connector has no customer support. */
667
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>;
668
955
  /** Customer lookup: online only; `undefined` when the connector has no customer support. */
669
956
  getCustomer?: (context: SyncContext, id: string) => Promise<Customer | null>;
670
957
  /**
@@ -678,6 +965,29 @@ interface TallyConnector {
678
965
  emailReceipt?: (context: SyncContext, orderId: string, email: string, options?: {
679
966
  saveToBilling?: boolean;
680
967
  }) => Promise<void>;
968
+ /**
969
+ * The store's orders, newest first, one page per call (ADR-081): online only, read-only. Rejects as `emailReceipt`
970
+ * does (`ConnectorUnauthorizedError` for credentials; a connector's own errors otherwise, e.g. `CustomerServiceError`).
971
+ * `undefined` when the connector has no order history.
972
+ */
973
+ listOrders?: (context: SyncContext, query?: ListOrdersQuery) => Promise<StoreOrderPage>;
974
+ /**
975
+ * The given orders by store id (ADR-081), in the order asked; an id the store does not have is left out. Online only,
976
+ * read-only; rejects as `listOrders`. `undefined` when the connector has no order history.
977
+ */
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>;
681
991
  }
682
992
 
683
993
  /**
@@ -1544,4 +1854,4 @@ declare namespace index {
1544
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 };
1545
1855
  }
1546
1856
 
1547
- 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 Money, 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 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,