@tallyui/core 3.18.0 → 3.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-CSXNXRBA.js → chunk-27L7XLTT.js} +48 -0
- package/dist/command-result-BZd1YFMP.d.ts +1956 -0
- package/dist/index.d.ts +51 -1117
- package/dist/index.js +145 -9
- package/dist/server/index.d.ts +46 -5
- package/dist/server/index.js +594 -114
- package/package.json +1 -1
- package/src/customer-display/advertisement.ts +57 -0
- package/src/customer-display/index.ts +2 -0
- package/src/customer-display/rate-limit-source.ts +40 -0
- package/src/index.ts +11 -2
- package/src/order-filters.ts +58 -0
- package/src/server/batch.ts +4 -0
- package/src/server/display-signalling/contract.ts +254 -0
- package/src/server/display-signalling/index.ts +3 -0
- package/src/server/display-signalling/memory-server.ts +250 -0
- package/src/server/index.ts +2 -0
- package/src/server/order-payload-shape.ts +25 -1
- package/src/server/versions.ts +2 -2
- package/src/tax/woocommerce/index.ts +2 -0
- package/src/tax/woocommerce/tax-location.ts +59 -0
- package/src/types/commands.ts +27 -4
- package/src/types/connector.ts +41 -7
- package/src/types/customers.ts +9 -0
- package/src/types/display-signalling.ts +123 -0
- package/src/types/index.ts +5 -0
- package/src/types/orders.ts +23 -0
- package/src/types/receipt-templates.ts +26 -0
- package/src/types/store-settings.ts +11 -1
- package/dist/command-result-CoCa8PXJ.d.ts +0 -544
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { SyncContext } from './connector';
|
|
2
|
+
|
|
3
|
+
/** The capability a cashier session needs for every till-side signalling call (ADR-085 d4, d5); each platform maps it onto its own roles. */
|
|
4
|
+
export const DISPLAY_PAIR_CAPABILITY = 'customer_display.pair';
|
|
5
|
+
|
|
6
|
+
/** One ICE server, in the shape `RTCPeerConnection` takes (ADR-085 d7). */
|
|
7
|
+
export interface IceServer { urls: string | string[]; username?: string; credential?: string }
|
|
8
|
+
|
|
9
|
+
/** The store's display advertisement from `GET /tally/v1/info` (`customerDisplay`, ADR-085 d7, d8). */
|
|
10
|
+
export interface DisplayAdvertisement {
|
|
11
|
+
/** The ICE servers both peers use; `[]` is LAN-only. */
|
|
12
|
+
iceServers: IceServer[];
|
|
13
|
+
/** Whether the till posts the snapshot fallback while a display's data channel is not open. */
|
|
14
|
+
snapshot: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type DisplaySignallingErrorCode =
|
|
18
|
+
/** Till side: no session, or the session lacks `customer_display.pair`. */
|
|
19
|
+
| 'forbidden'
|
|
20
|
+
/** Mint: this device already holds 5 unspent codes. */
|
|
21
|
+
| 'limit'
|
|
22
|
+
/** Every claim refusal: unknown, expired or spent code, rate-limited or paused. One code, so a guesser learns nothing (ADR-085 d4). */
|
|
23
|
+
| 'claim_refused'
|
|
24
|
+
/** Collect with an unknown, declined or expired secret, or a token already collected; it does not say which (#705). */
|
|
25
|
+
| 'collect_refused'
|
|
26
|
+
/** Till side: an id this device does not own, or one that is unknown or expired. */
|
|
27
|
+
| 'not_found'
|
|
28
|
+
/** Display side: a token that is unknown, forgotten or pruned. */
|
|
29
|
+
| 'token_refused'
|
|
30
|
+
/** A snapshot whose JSON is over 200 KiB. */
|
|
31
|
+
| 'too_large'
|
|
32
|
+
/** Transport failure: no answer from the server (connectors). */
|
|
33
|
+
| 'network'
|
|
34
|
+
/** Transport failure: the server answered with an error the seam does not name (connectors). */
|
|
35
|
+
| 'server';
|
|
36
|
+
|
|
37
|
+
/** Every refusal of a `DisplaySignalling` method. Branch on `code`. */
|
|
38
|
+
export class DisplaySignallingError extends Error {
|
|
39
|
+
readonly code: DisplaySignallingErrorCode;
|
|
40
|
+
constructor(code: DisplaySignallingErrorCode, message: string = code) {
|
|
41
|
+
super(message);
|
|
42
|
+
this.name = 'DisplaySignallingError';
|
|
43
|
+
this.code = code;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The display side's context: a display has no login, only the store's address. */
|
|
48
|
+
export interface DisplaySignallingContext { baseUrl: string; fetch?: typeof globalThis.fetch }
|
|
49
|
+
|
|
50
|
+
/** A claim waiting for the minting till's cashier. */
|
|
51
|
+
export interface PendingPairing {
|
|
52
|
+
claimId: string;
|
|
53
|
+
displayName: string;
|
|
54
|
+
/** 4 digits, shown on the display and on the till, so the cashier can see which display asks (#705). */
|
|
55
|
+
checkCode: string;
|
|
56
|
+
/** ISO 8601: the code's expiry, when an unconfirmed claim is deleted. */
|
|
57
|
+
expiresAt: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** A paired display in the server's registry (ADR-085 d6). */
|
|
61
|
+
export interface DisplayRecord {
|
|
62
|
+
displayId: string;
|
|
63
|
+
name: string;
|
|
64
|
+
/** The cashier who confirmed the pairing. */
|
|
65
|
+
cashierId: string;
|
|
66
|
+
/** ISO 8601 of the last successful display-side token call, or `null` when never seen. */
|
|
67
|
+
lastSeenAt: string | null;
|
|
68
|
+
/** Whether the display was seen recently (the reference server: within the last 30 s). */
|
|
69
|
+
connected: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** One WebRTC signalling message; `payload` is opaque to the server. */
|
|
73
|
+
export interface SignalMessage { type: 'offer' | 'answer' | 'ice'; payload: string }
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The platform-neutral signalling seam for a second-device customer display (ADR-085 d2). Each backend's plugin
|
|
77
|
+
* implements the routes its own way; every implementation meets this floor (d4–d6, d8, #705), which
|
|
78
|
+
* `displaySignallingContract` in `@tallyui/core/server` tests. A plugin may be stricter.
|
|
79
|
+
* Till side: every call takes a cashier session and the till's device id; a session without `customer_display.pair`
|
|
80
|
+
* gets `forbidden`, and an id this device does not own gets `not_found`. Display side: no login; calls are gated by the
|
|
81
|
+
* display's token (`token_refused`), and each successful token call updates `lastSeenAt`. Every refusal is a
|
|
82
|
+
* `DisplaySignallingError`.
|
|
83
|
+
*/
|
|
84
|
+
export interface DisplaySignalling {
|
|
85
|
+
/** A pairing code: 6+ digits from `crypto.getRandomValues`, single use, live at most 10 minutes; a 6th unspent code per device gives `limit`. */
|
|
86
|
+
mint(ctx: SyncContext, deviceId: string): Promise<{ code: string; expiresAt: string }>;
|
|
87
|
+
/** The live claims on codes this device minted, each with its check code. */
|
|
88
|
+
pending(ctx: SyncContext, deviceId: string): Promise<PendingPairing[]>;
|
|
89
|
+
/**
|
|
90
|
+
* Confirms a claim on a code this device minted, recording the display as owned by this device and cashier. The
|
|
91
|
+
* display then collects its token: 128 bits, base64url, stored only as SHA-256 hex. A claim that carried a valid
|
|
92
|
+
* token moves that display: its old row, token and snapshot go in the same step, and this device owns the same id.
|
|
93
|
+
*/
|
|
94
|
+
confirm(ctx: SyncContext, deviceId: string, claimId: string): Promise<void>;
|
|
95
|
+
/** Declines a claim on a code this device minted: the pending pairing is deleted, and nothing is issued. */
|
|
96
|
+
decline(ctx: SyncContext, deviceId: string, claimId: string): Promise<void>;
|
|
97
|
+
/** The displays this device owns. A display unseen for 30 days is pruned with its token and snapshot. */
|
|
98
|
+
list(ctx: SyncContext, deviceId: string): Promise<DisplayRecord[]>;
|
|
99
|
+
/** Deletes the display's row, token hash and snapshot at once; the token is refused on its next call. */
|
|
100
|
+
forget(ctx: SyncContext, deviceId: string, displayId: string): Promise<void>;
|
|
101
|
+
/** Queues a message in an owned display's inbox. */
|
|
102
|
+
sendSignal(ctx: SyncContext, deviceId: string, displayId: string, message: SignalMessage): Promise<void>;
|
|
103
|
+
/** Drains this device's inbox: each message once, in send order, only from displays it owns. */
|
|
104
|
+
receiveSignals(ctx: SyncContext, deviceId: string): Promise<Array<SignalMessage & { displayId: string }>>;
|
|
105
|
+
/** Keeps `body` as the display's only snapshot for at most 60 s; over 204 800 UTF-8 bytes of JSON gives `too_large` and keeps the old one. */
|
|
106
|
+
postSnapshot(ctx: SyncContext, deviceId: string, displayId: string, body: unknown): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Claims a live code: the first claim spends it and records a pending pairing with `displayName` and a fresh 4-digit
|
|
109
|
+
* check code, unique among live pending pairings, and returns a claim secret (128 bits, base64url, stored only as a
|
|
110
|
+
* hash); no token. `token` is the display's current token, if any, so a confirm moves it. A claim naming no live code
|
|
111
|
+
* fails and spends nothing. Failed claims are limited per source (10 a minute, IPv6 by /64 via `rateLimitSource`) and
|
|
112
|
+
* store-wide (100 per 10 minutes); over either, every claim is refused and spends nothing. Every refusal is `claim_refused`.
|
|
113
|
+
*/
|
|
114
|
+
claim(dctx: DisplaySignallingContext, request: { code: string; displayName: string; token?: string }): Promise<{ claimSecret: string; checkCode: string }>;
|
|
115
|
+
/** Pending: `pending` with the check code. After the confirm the first collect gives `paired` with the token; later, declined, expired or unknown gives `collect_refused`. */
|
|
116
|
+
collect(dctx: DisplaySignallingContext, claimSecret: string): Promise<{ status: 'pending'; checkCode: string } | { status: 'paired'; displayId: string; token: string }>;
|
|
117
|
+
/** Queues a message in the owning till's inbox. */
|
|
118
|
+
displaySendSignal(dctx: DisplaySignallingContext, token: string, message: SignalMessage): Promise<void>;
|
|
119
|
+
/** Drains this display's own inbox: each message once, in send order. */
|
|
120
|
+
displayReceiveSignals(dctx: DisplaySignallingContext, token: string): Promise<SignalMessage[]>;
|
|
121
|
+
/** The display's latest snapshot, or `null` when none is held. */
|
|
122
|
+
readSnapshot(dctx: DisplaySignallingContext, token: string): Promise<unknown | null>;
|
|
123
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -11,6 +11,11 @@ export type {
|
|
|
11
11
|
|
|
12
12
|
export type { ReplicationAdapter } from './replication';
|
|
13
13
|
|
|
14
|
+
export type {
|
|
15
|
+
DisplaySignalling, DisplaySignallingContext, DisplaySignallingErrorCode, DisplayAdvertisement, IceServer,
|
|
16
|
+
PendingPairing, DisplayRecord, SignalMessage,
|
|
17
|
+
} from './display-signalling';
|
|
18
|
+
|
|
14
19
|
export type { FingerprintReconcileAdapter, IdReconcileAdapter, StockReconcileAdapter } from './reconcile';
|
|
15
20
|
|
|
16
21
|
export type { StoreSettings, StoreSettingsChoice, StoreTaxRate, StoreTaxRateLocation } from './store-settings';
|
package/src/types/orders.ts
CHANGED
|
@@ -69,6 +69,15 @@ export interface StoreOrder {
|
|
|
69
69
|
refunds: StoreOrderRefund[];
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
/** The filter fields a connector may support on listOrders. */
|
|
73
|
+
export type OrderFilterField =
|
|
74
|
+
| 'status' | 'customerId' | 'cashierId' | 'registerId' | 'paymentMethod' | 'storeId' | 'createdVia' | 'dateRange';
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* One page of order history, filtered on the server (#721). A connector maps each filter field its own way; a field the
|
|
78
|
+
* connector does not list in `TallyConnector.orderFilters` is refused with `UnsupportedOrderFilterError`
|
|
79
|
+
* (`assertOrderFiltersSupported`), never dropped.
|
|
80
|
+
*/
|
|
72
81
|
export interface ListOrdersQuery {
|
|
73
82
|
/** 1-based; default 1. */
|
|
74
83
|
page?: number;
|
|
@@ -76,6 +85,20 @@ export interface ListOrdersQuery {
|
|
|
76
85
|
perPage?: number;
|
|
77
86
|
/** The platform's own order search. */
|
|
78
87
|
search?: string;
|
|
88
|
+
/** The platform's own status word, as StoreOrder.status carries it. */
|
|
89
|
+
status?: string;
|
|
90
|
+
/** Store ids, as strings like every id in TallyUI. `'0'` is WooCommerce's guest. */
|
|
91
|
+
customerId?: string;
|
|
92
|
+
cashierId?: string;
|
|
93
|
+
registerId?: string;
|
|
94
|
+
/** A payment method or gateway id, as the platform records it. */
|
|
95
|
+
paymentMethod?: string;
|
|
96
|
+
/** The store (outlet) the order was rung at. */
|
|
97
|
+
storeId?: string;
|
|
98
|
+
/** Where the order was created, in the platform's own words (WooCommerce: `woocommerce-pos`, `checkout`, `admin`). */
|
|
99
|
+
createdVia?: string;
|
|
100
|
+
/** Created at or after `after` and before `before`: ISO 8601 instants in UTC with a `Z` (`2026-11-11T00:00:00.000Z`). Either end may be absent. */
|
|
101
|
+
dateRange?: { after?: string; before?: string };
|
|
79
102
|
}
|
|
80
103
|
|
|
81
104
|
export interface StoreOrderPage { orders: StoreOrder[]; hasMore: boolean }
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** What a template prints: a sale's receipt, a report, or a register closure. */
|
|
2
|
+
export type ReceiptTemplateKind = 'receipt' | 'report' | 'closure';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A store's print template, as the till's renderer takes it (`@tallyui/pos` receipt-template).
|
|
6
|
+
* `html` bodies are Mustache HTML (renderLogiclessTemplate); `thermal` bodies are Mustache over `<receipt>` XML
|
|
7
|
+
* (renderThermalPreview).
|
|
8
|
+
*/
|
|
9
|
+
export interface ReceiptTemplate {
|
|
10
|
+
/** The platform's id, as a string (`"64965"`, `"plugin-core"`). */
|
|
11
|
+
id: string;
|
|
12
|
+
kind: ReceiptTemplateKind;
|
|
13
|
+
title: string;
|
|
14
|
+
engine: 'html' | 'thermal';
|
|
15
|
+
/** The Mustache source. Never empty. */
|
|
16
|
+
body: string;
|
|
17
|
+
/** The paper a thermal body is laid out for; absent for html. */
|
|
18
|
+
paper?: '58mm' | '80mm';
|
|
19
|
+
/**
|
|
20
|
+
* The data vocabulary the body's Mustache tags expect.
|
|
21
|
+
* - `'wcpos'`: WCPOS's receipt data (store.address_lines, totals.total_incl_display, …).
|
|
22
|
+
* - `'tallyui'`: @tallyui/pos `receiptTemplateData`.
|
|
23
|
+
* A body renders blank fields over data in the other vocabulary.
|
|
24
|
+
*/
|
|
25
|
+
dataModel: 'wcpos' | 'tallyui';
|
|
26
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { TaxRounding } from './connector';
|
|
2
|
+
import type { TaxAddress, TaxBasedOn } from '../tax/woocommerce/tax-location';
|
|
3
|
+
import type { WooTaxRate } from '../tax/woocommerce/types';
|
|
2
4
|
|
|
3
5
|
/** What the POS needs from the store's own settings (TV4). Read once after sign-in; the app feeds all three consumers from it. */
|
|
4
6
|
export interface StoreSettings {
|
|
@@ -10,8 +12,16 @@ export interface StoreSettings {
|
|
|
10
12
|
taxRatesPpm: { default: number; [taxClass: string]: number };
|
|
11
13
|
/** The backend's tax rate name per tax class (same keys as `taxRatesPpm`, including `default`), for `per_rate_group_items`' grouping (#324). Set by a connector whose rounding groups by rate name; absent otherwise. */
|
|
12
14
|
taxRateCodes?: Record<string, string>;
|
|
13
|
-
/** WooCommerce rates already filtered to the store's tax address; the empty class uses `standard`. */
|
|
15
|
+
/** WooCommerce rates already filtered to the store's tax address; the empty class uses `standard`. `taxSettingsForLocation` (@tallyui/pos) re-derives it, with `taxRatesPpm`, for another address from `taxRateTable`. */
|
|
14
16
|
taxRates?: Record<string, { id: number; code: string; label: string; rate: string; priority: number; compound: boolean; shipping: boolean }[]>;
|
|
17
|
+
/** WooCommerce's "Calculate tax based on" (`tax_based_on`), normalized. Absent: the connector did not read it; the cart taxes by `taxRates` as today. */
|
|
18
|
+
taxBasedOn?: TaxBasedOn;
|
|
19
|
+
/** The shop base address, as WooCommerce resolves it for `base` (store country, state, city, postcode). */
|
|
20
|
+
baseTaxAddress?: TaxAddress;
|
|
21
|
+
/** The store's whole WooCommerce rate table, unfiltered, for re-matching by address. Absent: `taxRates` is final.
|
|
22
|
+
* `saleTaxContexts` (@tallyui/pos) re-matches only when the app passes the connector's `orderCreate` capability and it
|
|
23
|
+
* is 8 or more, since only order.create 8 tells the server which address the sale was taxed on (#722). */
|
|
24
|
+
taxRateTable?: WooTaxRate[];
|
|
15
25
|
/** Every tax rate the store defines, wherever it applies, for an app's "all tax rates" table (#669). Display only: the cart reads `taxRatesPpm` and `taxRates`, never this. Absent when the connector did not read the list. */
|
|
16
26
|
allTaxRates?: StoreTaxRate[];
|
|
17
27
|
taxRoundAtSubtotal?: boolean;
|