@tallyui/core 3.12.0 → 3.14.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-UFWXJAMF.js → chunk-CSXNXRBA.js} +2 -0
- package/dist/{command-result-CrM7yjwk.d.ts → command-result-CoCa8PXJ.d.ts} +22 -5
- package/dist/index.d.ts +248 -6
- package/dist/index.js +76 -4
- package/dist/server/index.d.ts +8 -6
- package/dist/server/index.js +11 -3
- package/package.json +1 -1
- package/src/commands.ts +2 -0
- package/src/connectivity.ts +41 -0
- package/src/index.ts +11 -2
- package/src/server/batch.ts +1 -0
- package/src/server/index.ts +1 -1
- package/src/server/order-payload-shape.ts +5 -1
- package/src/server/register-outcome.ts +2 -0
- package/src/server/register-payload-shape.ts +4 -0
- package/src/server/rejection-codes.ts +1 -2
- package/src/server/versions.ts +4 -1
- package/src/types/cashier.ts +32 -0
- package/src/types/commands.ts +17 -4
- package/src/types/connector.ts +61 -4
- package/src/types/customers.ts +32 -3
- package/src/types/index.ts +1 -0
- package/src/types/payment-methods.ts +103 -0
- package/src/types/registers.ts +15 -0
package/dist/server/index.js
CHANGED
|
@@ -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-
|
|
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
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
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { TallyConnector } from './types/connector';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* How well a connector's store answers (v2 parity A6, unit 34). The same three states as WCPOS v2's
|
|
5
|
+
* `EngineConnectivity`: `degraded` means the device is online but the store keeps failing.
|
|
6
|
+
*/
|
|
7
|
+
export type ConnectivityState = 'online' | 'offline' | 'degraded';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A store's deliberate refusal to sync until someone updates software. `fixedBy` as in `SyncNotice`: `'till'` when
|
|
11
|
+
* this app is older than the store accepts, `'store'` when the store's software is older than the app needs.
|
|
12
|
+
* `reason` is the connector's code for it; `software`, `minVersion` and `status` only when the refusal names them.
|
|
13
|
+
*/
|
|
14
|
+
export type UpdateRequired = { reason: string; fixedBy: 'till' | 'store'; software?: string; minVersion?: string; status?: number };
|
|
15
|
+
|
|
16
|
+
/** What one failed request says: about connectivity, an update-required refusal, or nothing (`null`). */
|
|
17
|
+
export type FailureClass = 'offline' | 'degraded' | { updateRequired: UpdateRequired } | null;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The rule for a connector without `classifyFailure`: a timeout or a 5xx is `degraded`, a request that got no
|
|
21
|
+
* response (a fetch's `TypeError`, or a `network` code as `CustomerServiceError` has) is `offline`, anything else is
|
|
22
|
+
* `null`. It never answers update-required: only a connector knows its own refusal.
|
|
23
|
+
*/
|
|
24
|
+
export function neutralFailureClass(error: unknown): FailureClass {
|
|
25
|
+
if (typeof error !== 'object' || error === null) return null;
|
|
26
|
+
const { name, code, status } = error as { name?: unknown; code?: unknown; status?: unknown };
|
|
27
|
+
if (name === 'AbortError' || name === 'TimeoutError' || code === 'timeout') return 'degraded';
|
|
28
|
+
if (typeof status === 'number' && status >= 500) return 'degraded';
|
|
29
|
+
if (name === 'TypeError' || code === 'network') return 'offline';
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The connector's own `classifyFailure` when it has one (its answer is final), else `neutralFailureClass`. A method that throws gives `null`. */
|
|
34
|
+
export function classifyFailure(connector: Pick<TallyConnector, 'classifyFailure'> | undefined, error: unknown): FailureClass {
|
|
35
|
+
if (!connector?.classifyFailure) return neutralFailureClass(error);
|
|
36
|
+
try {
|
|
37
|
+
return connector.classifyFailure(error);
|
|
38
|
+
} catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -33,12 +33,20 @@ export { SignInError } from './sign-in';
|
|
|
33
33
|
export { ConnectorUnauthorizedError } from './unauthorized';
|
|
34
34
|
export { isRxdbRemoteVersionMismatch } from './rxdb-remote-version-mismatch';
|
|
35
35
|
export { errorKind, type ErrorKind, type SyncNotice } from './sync-notice';
|
|
36
|
+
export { classifyFailure, neutralFailureClass, type ConnectivityState, type FailureClass, type UpdateRequired } from './connectivity';
|
|
36
37
|
export type { SignInErrorCode } from './sign-in';
|
|
37
38
|
export { StoreSettingsError } from './store-settings';
|
|
38
|
-
export { customerTraits, CustomerServiceError, type Customer, type CustomerInput } from './types/customers';
|
|
39
|
+
export { customerTraits, CustomerServiceError, type Customer, type CustomerInput, type CustomerAddress, type CustomerTaxId, type CustomerPatch } from './types/customers';
|
|
40
|
+
export { paymentMethodOf, defaultPaymentMethods } from './types/payment-methods';
|
|
41
|
+
export type {
|
|
42
|
+
PaymentMethodDescriptor, PaymentKind, CaptureMode, CaptureModeEntry, PaymentHardware, PaymentTransport,
|
|
43
|
+
PaymentOfflineMode, PaymentTipsMode, PaymentRounding,
|
|
44
|
+
} from './types/payment-methods';
|
|
39
45
|
export type {
|
|
40
46
|
StoreOrder, StoreOrderLine, StoreOrderCharge, StoreOrderPayment, StoreOrderRefund, ListOrdersQuery, StoreOrderPage,
|
|
41
47
|
} from './types/orders';
|
|
48
|
+
export type { RegisterInfo } from './types/registers';
|
|
49
|
+
export { CASHIER_PERMISSIONS, cashierPermissions, isCashierPermission, type Cashier, type CashierPermission } from './types/cashier';
|
|
42
50
|
export type { StoreSettingsErrorCode, StoreSettingsChoices } from './store-settings';
|
|
43
51
|
|
|
44
52
|
export type {
|
|
@@ -52,12 +60,13 @@ export type {
|
|
|
52
60
|
OrderCreateCoupon, OrderCreateCouponInvalidData, OrderCreateTotalMismatchData,
|
|
53
61
|
CommandBatchRequest, CommandBatchResponse, BatchTooLargeBody,
|
|
54
62
|
RegisterCommandResult, RegisterSessionOpenPayload, RegisterSessionAlreadyOpenData, RegisterSessionSupersededData,
|
|
63
|
+
RegisterApprovalRequiredData, RegisterApprovalInvalidData,
|
|
55
64
|
RegisterSessionTransitionPayload,
|
|
56
65
|
RegisterMovementRecordPayload, RegisterMovementVoidPayload, RegisterClosureSubmitPayload,
|
|
57
66
|
} from './types';
|
|
58
67
|
|
|
59
68
|
export {
|
|
60
|
-
COMMANDS_PATH, PROTOCOL_HEADER, PROTOCOL_VERSION, MAX_COMMANDS_PER_BATCH,
|
|
69
|
+
COMMANDS_PATH, PROTOCOL_HEADER, PROTOCOL_VERSION, MAX_COMMANDS_PER_BATCH, ORDER_NOTE_MAX,
|
|
61
70
|
isCommandBatchResponse,
|
|
62
71
|
} from './commands';
|
|
63
72
|
|
package/src/server/batch.ts
CHANGED
|
@@ -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'
|
package/src/server/index.ts
CHANGED
|
@@ -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'
|
package/src/server/versions.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/types/commands.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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. */
|
package/src/types/connector.ts
CHANGED
|
@@ -5,8 +5,12 @@ 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';
|
|
13
|
+
import type { FailureClass } from '../connectivity';
|
|
10
14
|
|
|
11
15
|
/**
|
|
12
16
|
* Authentication configuration for a connector.
|
|
@@ -60,6 +64,12 @@ export interface ServerCapabilities {
|
|
|
60
64
|
* coupon. WooCommerce: true only when the woocommerce-pos plugin reports 1.9.0 or later.
|
|
61
65
|
*/
|
|
62
66
|
coupons?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* The store's register approval threshold (ADR-082 d3), from the top level of `/tally/v1/info`. With
|
|
69
|
+
* `register >= 3`, a close whose absolute cash variance is over `thresholdMinor` needs the store's approval.
|
|
70
|
+
* Absent means the store sets none, and the app's own threshold applies.
|
|
71
|
+
*/
|
|
72
|
+
registerApproval?: { thresholdMinor: number };
|
|
63
73
|
}
|
|
64
74
|
|
|
65
75
|
/** #287, ADR-071. `custom`: the till computes as when absent; that server never emits `figures_mismatch` for subtotal or tax. */
|
|
@@ -115,6 +125,16 @@ export function parseLineTax(value: unknown, warn?: (reason: string) => void): {
|
|
|
115
125
|
return undefined;
|
|
116
126
|
}
|
|
117
127
|
|
|
128
|
+
function parseRegisterApproval(value: unknown, warn?: (reason: string) => void): { thresholdMinor: number } | undefined {
|
|
129
|
+
if (value === undefined) return undefined;
|
|
130
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
131
|
+
const { thresholdMinor } = value as { thresholdMinor?: unknown };
|
|
132
|
+
if (typeof thresholdMinor === 'number' && Number.isSafeInteger(thresholdMinor) && thresholdMinor >= 0) return { thresholdMinor };
|
|
133
|
+
}
|
|
134
|
+
warn?.('ignoring a malformed registerApproval');
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
|
|
118
138
|
const maxVersion = (list: unknown): number | undefined => {
|
|
119
139
|
const valid = Array.isArray(list) ? list.filter((v): v is number => typeof v === 'number' && Number.isSafeInteger(v) && v > 0) : [];
|
|
120
140
|
return valid.length > 0 ? Math.max(...valid) : undefined;
|
|
@@ -124,6 +144,7 @@ const maxVersion = (list: unknown): number | undefined => {
|
|
|
124
144
|
* Reads a 2xx body of `GET /tally/v1/info` (ADR-062): `orderCreate` is the max of
|
|
125
145
|
* `contracts["order.create"]`, or 1 when it's missing or malformed; `register` is the max of
|
|
126
146
|
* `contracts.register` when valid; `taxRounding` is the top-level sibling of `contracts` (#287); malformed `lineTax` is ignored.
|
|
147
|
+
* malformed `registerApproval` is ignored (ADR-082).
|
|
127
148
|
* `orderRefund` is the max of `contracts["order.refund"]` when valid, otherwise absent (ADR-080).
|
|
128
149
|
* Absent `taxRounding` uses the default; a present malformed value is unknown, so settings wait.
|
|
129
150
|
* A non-object body is also unknown, not a statement of the store's defaults.
|
|
@@ -133,7 +154,7 @@ export function parseInfoCapabilities(body: unknown, warn?: (reason: string) =>
|
|
|
133
154
|
warn?.('non-object info body: capabilities unknown');
|
|
134
155
|
return undefined;
|
|
135
156
|
}
|
|
136
|
-
const { contracts, taxRounding, lineTax } = body as { contracts?: Record<string, unknown> | null; taxRounding?: unknown; lineTax?: unknown };
|
|
157
|
+
const { contracts, taxRounding, lineTax, registerApproval } = body as { contracts?: Record<string, unknown> | null; taxRounding?: unknown; lineTax?: unknown; registerApproval?: unknown };
|
|
137
158
|
const register = maxVersion(contracts?.register);
|
|
138
159
|
const orderRefund = maxVersion(contracts?.['order.refund']);
|
|
139
160
|
const rounding = parseTaxRounding(taxRounding);
|
|
@@ -142,10 +163,12 @@ export function parseInfoCapabilities(body: unknown, warn?: (reason: string) =>
|
|
|
142
163
|
return undefined;
|
|
143
164
|
}
|
|
144
165
|
const parsedLineTax = parseLineTax(lineTax, warn);
|
|
166
|
+
const parsed = parseRegisterApproval(registerApproval, warn);
|
|
145
167
|
return { orderCreate: maxVersion(contracts?.['order.create']) ?? 1,
|
|
146
168
|
...(orderRefund !== undefined ? { orderRefund } : {}),
|
|
147
169
|
...(register !== undefined ? { register } : {}), ...(rounding ? { taxRounding: rounding } : {}),
|
|
148
|
-
...(parsedLineTax ? { lineTax: parsedLineTax } : {})
|
|
170
|
+
...(parsedLineTax ? { lineTax: parsedLineTax } : {}),
|
|
171
|
+
...(parsed ? { registerApproval: parsed } : {}) };
|
|
149
172
|
}
|
|
150
173
|
|
|
151
174
|
export interface AuthField {
|
|
@@ -298,10 +321,25 @@ export interface TallyConnector {
|
|
|
298
321
|
* `unauthorized` or `invalid_credentials` means sign in again), never on its class.
|
|
299
322
|
*/
|
|
300
323
|
capabilities?: (context: SyncContext) => Promise<ServerCapabilities | undefined>;
|
|
301
|
-
/**
|
|
324
|
+
/**
|
|
325
|
+
* The payment methods the till may offer, in the order it shows them (v2 parity A2). Read-only, never writes to
|
|
326
|
+
* the store. `undefined` when the connector has none of its own: the till offers `defaultPaymentMethods()`.
|
|
327
|
+
*/
|
|
328
|
+
paymentMethods?: (context: SyncContext) => Promise<PaymentMethodDescriptor[]>;
|
|
329
|
+
/**
|
|
330
|
+
* Customer search: online only. An empty or whitespace query may list a first page of the store's customers
|
|
331
|
+
* (recent ones, or in the store's own picker order); a connector that cannot list them returns `[]`.
|
|
332
|
+
* `undefined` when the connector has no customer support.
|
|
333
|
+
*/
|
|
302
334
|
searchCustomers?: (context: SyncContext, query: string, options?: { limit?: number }) => Promise<Customer[]>;
|
|
303
335
|
/** Customer creation: online only; `undefined` when the connector has no customer support. */
|
|
304
336
|
createCustomer?: (context: SyncContext, input: CustomerInput) => Promise<Customer>;
|
|
337
|
+
/**
|
|
338
|
+
* Customer edit: online only; resolves the customer as the store now has it. Rejects with
|
|
339
|
+
* `ConnectorUnauthorizedError` for credentials and `CustomerServiceError` (`invalid` for a refused patch or an id
|
|
340
|
+
* the store does not have, `server` or `network` otherwise). `undefined` when the connector can't edit customers.
|
|
341
|
+
*/
|
|
342
|
+
updateCustomer?: (context: SyncContext, id: string, patch: CustomerPatch) => Promise<Customer>;
|
|
305
343
|
/** Customer lookup: online only; `undefined` when the connector has no customer support. */
|
|
306
344
|
getCustomer?: (context: SyncContext, id: string) => Promise<Customer | null>;
|
|
307
345
|
/**
|
|
@@ -324,4 +362,23 @@ export interface TallyConnector {
|
|
|
324
362
|
* read-only; rejects as `listOrders`. `undefined` when the connector has no order history.
|
|
325
363
|
*/
|
|
326
364
|
getOrders?: (context: SyncContext, ids: readonly string[]) => Promise<StoreOrder[]>;
|
|
365
|
+
/**
|
|
366
|
+
* The store's register directory (v2 parity A4): online only, read-only. Rejects with `ConnectorUnauthorizedError`
|
|
367
|
+
* for credentials; a connector's own errors otherwise. `undefined` when the connector has no register directory.
|
|
368
|
+
*/
|
|
369
|
+
listRegisters?: (context: SyncContext) => Promise<RegisterInfo[]>;
|
|
370
|
+
/**
|
|
371
|
+
* The signed-in cashier and their neutral POS permissions (v2 parity A12), mapped from the platform's own roles or
|
|
372
|
+
* capabilities. Read-only. `null` when the connector has no cashier to describe; `undefined` (no method) when the
|
|
373
|
+
* connector has no permission model: the till then allows everything, as before (`can` in `@tallyui/pos`).
|
|
374
|
+
* Permission names outside `CashierPermission` are dropped by `useCashier` (`cashierPermissions`).
|
|
375
|
+
*/
|
|
376
|
+
cashier?: (context: SyncContext) => Promise<Cashier | null>;
|
|
377
|
+
/**
|
|
378
|
+
* Maps one of this connector's request failures (pull, push, reconcile, online calls) to a connectivity verdict or
|
|
379
|
+
* its own update-required refusal (v2 parity A6). Synchronous and pure. `null` when the failure says nothing about
|
|
380
|
+
* connectivity (a validation refusal). `undefined` (no method) uses `neutralFailureClass`, which a connector's own
|
|
381
|
+
* method may also call for the failures it does not map.
|
|
382
|
+
*/
|
|
383
|
+
classifyFailure?: (error: unknown) => FailureClass;
|
|
327
384
|
}
|
package/src/types/customers.ts
CHANGED
|
@@ -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
|
-
/**
|
|
13
|
-
|
|
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
|
-
|
|
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
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -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';
|