@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.
- package/dist/{chunk-UFWXJAMF.js → chunk-CSXNXRBA.js} +2 -0
- package/dist/{command-result-DmHIPt6Z.d.ts → command-result-CoCa8PXJ.d.ts} +24 -5
- package/dist/index.d.ts +315 -5
- package/dist/index.js +56 -4
- package/dist/server/index.d.ts +8 -6
- package/dist/server/index.js +26 -4
- package/package.json +1 -1
- package/src/commands.ts +2 -0
- package/src/index.ts +13 -2
- package/src/server/batch.ts +2 -1
- package/src/server/index.ts +1 -1
- package/src/server/order-payload-shape.ts +16 -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 +19 -4
- package/src/types/connector.ts +60 -3
- package/src/types/customers.ts +32 -3
- package/src/types/index.ts +1 -0
- package/src/types/orders.ts +81 -0
- package/src/types/payment-methods.ts +103 -0
- package/src/types/registers.ts +15 -0
package/dist/server/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { e as CommandError,
|
|
2
|
-
export { g as CommandResultError, M as MAX_COMMANDS_PER_BATCH,
|
|
1
|
+
import { e as CommandError, p as OrderCreatePayload, d as CommandEnvelope, J as RegisterCommandEnvelope, A as AnyCommandEnvelope, f as CommandResult, B as BatchTooLargeBody, c as CommandBatchResponse, C as CommandWarning, K as RegisterCommandResult, D as OrderRefundRejectionCode } from '../command-result-CoCa8PXJ.js';
|
|
2
|
+
export { g as CommandResultError, M as MAX_COMMANDS_PER_BATCH, O as ORDER_NOTE_MAX, m as OrderCreateDisplay, r as OrderCreateTaxRate, X as parseCommandResult } from '../command-result-CoCa8PXJ.js';
|
|
3
3
|
|
|
4
4
|
/** ISO 4217 minor-unit exponent as resolved by Intl (which rejects malformed codes); depends on the runtime's ICU data. */
|
|
5
5
|
declare function currencyDecimals(currency: string): number;
|
|
@@ -26,7 +26,7 @@ declare function commandFingerprint(envelope: {
|
|
|
26
26
|
declare function payloadShapeErrors(payload: unknown): string[];
|
|
27
27
|
/** Length-bound errors of an order.create payload, e.g. ['lines[0].title: expected at most 255
|
|
28
28
|
* characters']; [] when every string is within its bound, at most ten. Bounds in UTF-16 code units:
|
|
29
|
-
* `customer.email` 254, v5 ids 36 and class/sku/method 64, other strings 255 (`customerId` and `sessionId` keep theirs in
|
|
29
|
+
* `note` ORDER_NOTE_MAX (1000), `customer.email` 254, v5 ids 36 and class/sku/method 64, other strings 255 (`customerId` and `sessionId` keep theirs in
|
|
30
30
|
* payloadShapeErrors); only strings are checked. A plugin calls it through precheckCommand, after
|
|
31
31
|
* its replay lookup, so a bound tightened later never turns an applied command's resend into
|
|
32
32
|
* `invalid_payload`. */
|
|
@@ -43,6 +43,9 @@ declare function fiscalFiguresErrors(payload: OrderCreatePayloadV3): string[];
|
|
|
43
43
|
* supports (#297). A server passes its own lists to `precheckCommand`, and its /info advertises them, gated by its
|
|
44
44
|
* own check (Front desk, 2026-09-30): 4 (#286) is 3 with every discountMinor tax-exclusive, and a plugin
|
|
45
45
|
* advertises it only once it handles it.
|
|
46
|
+
* 5 (ADR-075) adds fees, shipping and custom lines; 6 (ADR-077) adds coupons, regular prices, line
|
|
47
|
+
* attributes and Any picks (#495); a plugin advertises each only once it handles it.
|
|
48
|
+
* 7 (ADR-083) adds the sale note.
|
|
46
49
|
*/
|
|
47
50
|
declare const SUPPORTED_ORDER_CREATE_VERSIONS: readonly number[];
|
|
48
51
|
/** The till's capability for the contract versions shared by all five register commands; a server passes its own. */
|
|
@@ -165,7 +168,7 @@ declare function deriveSessionFigures(input: {
|
|
|
165
168
|
};
|
|
166
169
|
declare function deriveVariance(counted: Record<string, number>, expected: Record<string, number>): Record<string, number>;
|
|
167
170
|
|
|
168
|
-
type RegisterConflictCode = 'register_session_already_open' | 'register_session_superseded' | 'register_supersede_forbidden' | 'register_session_closed' | 'register_closure_exists' | 'register_closure_number_invalid';
|
|
171
|
+
type RegisterConflictCode = 'register_session_already_open' | 'register_session_superseded' | 'register_supersede_forbidden' | 'register_session_closed' | 'register_closure_exists' | 'register_closure_number_invalid' | 'register_approval_required' | 'register_approval_invalid';
|
|
169
172
|
type RegisterOutcome = {
|
|
170
173
|
kind: 'ok';
|
|
171
174
|
register: RegisterCommandResult;
|
|
@@ -178,8 +181,7 @@ type RegisterOutcome = {
|
|
|
178
181
|
message: string;
|
|
179
182
|
};
|
|
180
183
|
|
|
181
|
-
/** Every error.code a plugin may put on a rejected result (ADR-038 and its amendments, ADR-068)
|
|
182
|
-
* except `register_approval_required`, which arrives with registers c2c. */
|
|
184
|
+
/** Every error.code a plugin may put on a rejected result (ADR-038 and its amendments, ADR-068, ADR-082). */
|
|
183
185
|
type CommandRejectionCode = 'invalid_payload' | 'unsupported_version' | 'idempotency_mismatch' | 'store_configuration' | 'platform_error' | 'insufficient_stock' | 'unsupported_tax_mode' | 'internal_error' | 'coupon_invalid' | 'total_mismatch' | OrderRejectionCode | RegisterConflictCode | OrderRefundRejectionCode;
|
|
184
186
|
/**
|
|
185
187
|
* The rejected result for a platform-native error the plugin has judged permanent (a replay would fail
|
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;
|
|
@@ -177,6 +179,19 @@ function payloadShapeErrors(payload) {
|
|
|
177
179
|
check(object(line.attributes), `${path}.attributes`, "an object");
|
|
178
180
|
if (object(line.attributes)) for (const [key, value] of Object.entries(line.attributes)) check(typeof value === "string", `${path}.attributes.${key}`, "a string");
|
|
179
181
|
}
|
|
182
|
+
const { anyAttributes: names, attributes } = line;
|
|
183
|
+
if (names !== void 0) check(Array.isArray(names), `${path}.anyAttributes`, "an array");
|
|
184
|
+
if (Array.isArray(names)) names.forEach((name, index2) => {
|
|
185
|
+
const at = `${path}.anyAttributes[${index2}]`;
|
|
186
|
+
check(typeof name === "string" && name.length > 0, at, "a non-empty string");
|
|
187
|
+
if (typeof name !== "string" || !name) return;
|
|
188
|
+
check(names.indexOf(name) === index2, at, "no duplicate name");
|
|
189
|
+
check(
|
|
190
|
+
object(attributes) && Object.hasOwn(attributes, name) && typeof attributes[name] === "string" && attributes[name].length > 0,
|
|
191
|
+
at,
|
|
192
|
+
`a key of ${path}.attributes with a non-empty value`
|
|
193
|
+
);
|
|
194
|
+
});
|
|
180
195
|
});
|
|
181
196
|
for (const [value, path] of payloadStrings(payload)) check(!value.includes("\0"), path, "no NUL character");
|
|
182
197
|
return errors;
|
|
@@ -189,6 +204,7 @@ function payloadStrings(payload) {
|
|
|
189
204
|
const found = [];
|
|
190
205
|
const object = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
191
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]);
|
|
192
208
|
for (const field of ["lines", "payments"]) {
|
|
193
209
|
const items = payload[field];
|
|
194
210
|
if (Array.isArray(items)) items.forEach((item, index) => {
|
|
@@ -222,6 +238,7 @@ function payloadStrings(payload) {
|
|
|
222
238
|
if (object(line) && object(line.attributes)) for (const [key, value] of Object.entries(line.attributes)) {
|
|
223
239
|
found.push([key, `lines[${index}].attributes`, 255], [value, `lines[${index}].attributes.${key}`, 255]);
|
|
224
240
|
}
|
|
241
|
+
if (object(line) && Array.isArray(line.anyAttributes)) line.anyAttributes.forEach((name, i) => found.push([name, `lines[${index}].anyAttributes[${i}]`, 255]));
|
|
225
242
|
});
|
|
226
243
|
if (object(payload.customer)) found.push([payload.customer.email, "customer.email", 254], [payload.customer.customerId, "customer.customerId", void 0]);
|
|
227
244
|
found.push([payload.sessionId, "sessionId", void 0]);
|
|
@@ -334,7 +351,7 @@ function fiscalFiguresErrors(payload) {
|
|
|
334
351
|
}
|
|
335
352
|
|
|
336
353
|
// src/server/versions.ts
|
|
337
|
-
var SUPPORTED_ORDER_CREATE_VERSIONS = [1, 2, 3, 4];
|
|
354
|
+
var SUPPORTED_ORDER_CREATE_VERSIONS = [1, 2, 3, 4, 5, 6, 7];
|
|
338
355
|
var SUPPORTED_REGISTER_VERSIONS = [1];
|
|
339
356
|
var SUPPORTED_ORDER_REFUND_VERSIONS = [1];
|
|
340
357
|
|
|
@@ -420,11 +437,11 @@ function precheckCommand(envelope, supported) {
|
|
|
420
437
|
const v6Fields = payload.coupons !== void 0 ? ["coupons"] : [];
|
|
421
438
|
if (display?.coupons !== void 0) v6Fields.push("display.coupons");
|
|
422
439
|
if (Array.isArray(lines)) lines.forEach((line, index) => {
|
|
423
|
-
for (const field of ["regularUnitPriceMinor", "attributes"]) {
|
|
440
|
+
for (const field of ["regularUnitPriceMinor", "attributes", "anyAttributes"]) {
|
|
424
441
|
if (line?.[field] !== void 0) v6Fields.push(`lines[${index}].${field}`);
|
|
425
442
|
}
|
|
426
443
|
});
|
|
427
|
-
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;
|
|
428
445
|
if (!versionError && Array.isArray(lines)) for (const [index, line] of lines.entries()) {
|
|
429
446
|
if (line?.custom === void 0 && (typeof line?.variantId !== "string" || !line.variantId.length)) {
|
|
430
447
|
versionError = `lines[${index}].variantId is required`;
|
|
@@ -544,6 +561,10 @@ function registerPayloadErrors(type, payload) {
|
|
|
544
561
|
case "register.closure.submit":
|
|
545
562
|
for (const field of ["closureId", "registerId", "openedAt", "closedAt", "softwareVersion"]) string(field);
|
|
546
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
|
+
}
|
|
547
568
|
integer("number", 1);
|
|
548
569
|
for (const field of [
|
|
549
570
|
"periodSalesTotalMinor",
|
|
@@ -706,6 +727,7 @@ function internalErrorResult(id, correlationId) {
|
|
|
706
727
|
export {
|
|
707
728
|
CommandResultError,
|
|
708
729
|
MAX_COMMANDS_PER_BATCH,
|
|
730
|
+
ORDER_NOTE_MAX,
|
|
709
731
|
SUPPORTED_ORDER_CREATE_VERSIONS,
|
|
710
732
|
SUPPORTED_ORDER_REFUND_VERSIONS,
|
|
711
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
|
package/src/index.ts
CHANGED
|
@@ -35,7 +35,17 @@ export { isRxdbRemoteVersionMismatch } from './rxdb-remote-version-mismatch';
|
|
|
35
35
|
export { errorKind, type ErrorKind, type SyncNotice } from './sync-notice';
|
|
36
36
|
export type { SignInErrorCode } from './sign-in';
|
|
37
37
|
export { StoreSettingsError } from './store-settings';
|
|
38
|
-
export { customerTraits, CustomerServiceError, type Customer, type CustomerInput } from './types/customers';
|
|
38
|
+
export { customerTraits, CustomerServiceError, type Customer, type CustomerInput, type CustomerAddress, type CustomerTaxId, type CustomerPatch } from './types/customers';
|
|
39
|
+
export { paymentMethodOf, defaultPaymentMethods } from './types/payment-methods';
|
|
40
|
+
export type {
|
|
41
|
+
PaymentMethodDescriptor, PaymentKind, CaptureMode, CaptureModeEntry, PaymentHardware, PaymentTransport,
|
|
42
|
+
PaymentOfflineMode, PaymentTipsMode, PaymentRounding,
|
|
43
|
+
} from './types/payment-methods';
|
|
44
|
+
export type {
|
|
45
|
+
StoreOrder, StoreOrderLine, StoreOrderCharge, StoreOrderPayment, StoreOrderRefund, ListOrdersQuery, StoreOrderPage,
|
|
46
|
+
} from './types/orders';
|
|
47
|
+
export type { RegisterInfo } from './types/registers';
|
|
48
|
+
export { CASHIER_PERMISSIONS, cashierPermissions, isCashierPermission, type Cashier, type CashierPermission } from './types/cashier';
|
|
39
49
|
export type { StoreSettingsErrorCode, StoreSettingsChoices } from './store-settings';
|
|
40
50
|
|
|
41
51
|
export type {
|
|
@@ -49,12 +59,13 @@ export type {
|
|
|
49
59
|
OrderCreateCoupon, OrderCreateCouponInvalidData, OrderCreateTotalMismatchData,
|
|
50
60
|
CommandBatchRequest, CommandBatchResponse, BatchTooLargeBody,
|
|
51
61
|
RegisterCommandResult, RegisterSessionOpenPayload, RegisterSessionAlreadyOpenData, RegisterSessionSupersededData,
|
|
62
|
+
RegisterApprovalRequiredData, RegisterApprovalInvalidData,
|
|
52
63
|
RegisterSessionTransitionPayload,
|
|
53
64
|
RegisterMovementRecordPayload, RegisterMovementVoidPayload, RegisterClosureSubmitPayload,
|
|
54
65
|
} from './types';
|
|
55
66
|
|
|
56
67
|
export {
|
|
57
|
-
COMMANDS_PATH, PROTOCOL_HEADER, PROTOCOL_VERSION, MAX_COMMANDS_PER_BATCH,
|
|
68
|
+
COMMANDS_PATH, PROTOCOL_HEADER, PROTOCOL_VERSION, MAX_COMMANDS_PER_BATCH, ORDER_NOTE_MAX,
|
|
58
69
|
isCommandBatchResponse,
|
|
59
70
|
} from './commands';
|
|
60
71
|
|
package/src/server/batch.ts
CHANGED
|
@@ -108,12 +108,13 @@ export function precheckCommand(envelope: Pick<AnyCommandEnvelope | ValidatedCom
|
|
|
108
108
|
const v6Fields = payload.coupons !== undefined ? ['coupons'] : []
|
|
109
109
|
if (display?.coupons !== undefined) v6Fields.push('display.coupons')
|
|
110
110
|
if (Array.isArray(lines)) lines.forEach((line, index) => {
|
|
111
|
-
for (const field of ['regularUnitPriceMinor', 'attributes'] as const) {
|
|
111
|
+
for (const field of ['regularUnitPriceMinor', 'attributes', 'anyAttributes'] as const) {
|
|
112
112
|
if (line?.[field] !== undefined) v6Fields.push(`lines[${index}].${field}`)
|
|
113
113
|
}
|
|
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
|
|
@@ -133,6 +136,16 @@ export function payloadShapeErrors(payload: unknown): string[] {
|
|
|
133
136
|
check(object(line.attributes), `${path}.attributes`, 'an object')
|
|
134
137
|
if (object(line.attributes)) for (const [key, value] of Object.entries(line.attributes)) check(typeof value === 'string', `${path}.attributes.${key}`, 'a string')
|
|
135
138
|
}
|
|
139
|
+
const { anyAttributes: names, attributes } = line
|
|
140
|
+
if (names !== undefined) check(Array.isArray(names), `${path}.anyAttributes`, 'an array')
|
|
141
|
+
if (Array.isArray(names)) names.forEach((name, index) => {
|
|
142
|
+
const at = `${path}.anyAttributes[${index}]`
|
|
143
|
+
check(typeof name === 'string' && name.length > 0, at, 'a non-empty string')
|
|
144
|
+
if (typeof name !== 'string' || !name) return
|
|
145
|
+
check(names.indexOf(name) === index, at, 'no duplicate name')
|
|
146
|
+
check(object(attributes) && Object.hasOwn(attributes, name) && typeof attributes[name] === 'string' && attributes[name].length > 0,
|
|
147
|
+
at, `a key of ${path}.attributes with a non-empty value`)
|
|
148
|
+
})
|
|
136
149
|
})
|
|
137
150
|
// NUL, only on strings (the checks above name any other type): Postgres text can't hold it, and the lookup keys must be clean.
|
|
138
151
|
for (const [value, path] of payloadStrings(payload)) check(!value.includes('\u0000'), path, 'no NUL character')
|
|
@@ -141,7 +154,7 @@ export function payloadShapeErrors(payload: unknown): string[] {
|
|
|
141
154
|
|
|
142
155
|
/** Length-bound errors of an order.create payload, e.g. ['lines[0].title: expected at most 255
|
|
143
156
|
* characters']; [] when every string is within its bound, at most ten. Bounds in UTF-16 code units:
|
|
144
|
-
* `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
|
|
145
158
|
* payloadShapeErrors); only strings are checked. A plugin calls it through precheckCommand, after
|
|
146
159
|
* its replay lookup, so a bound tightened later never turns an applied command's resend into
|
|
147
160
|
* `invalid_payload`. */
|
|
@@ -159,6 +172,7 @@ function payloadStrings(payload: Record<string, unknown>): Array<[string, string
|
|
|
159
172
|
const object = (value: unknown): value is Record<string, unknown> =>
|
|
160
173
|
typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
161
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])
|
|
162
176
|
for (const field of ['lines', 'payments']) {
|
|
163
177
|
const items = payload[field]
|
|
164
178
|
if (Array.isArray(items)) items.forEach((item, index) => {
|
|
@@ -193,6 +207,7 @@ function payloadStrings(payload: Record<string, unknown>): Array<[string, string
|
|
|
193
207
|
if (object(line) && object(line.attributes)) for (const [key, value] of Object.entries(line.attributes)) {
|
|
194
208
|
found.push([key, `lines[${index}].attributes`, 255], [value, `lines[${index}].attributes.${key}`, 255])
|
|
195
209
|
}
|
|
210
|
+
if (object(line) && Array.isArray(line.anyAttributes)) line.anyAttributes.forEach((name, i) => found.push([name, `lines[${index}].anyAttributes[${i}]`, 255]))
|
|
196
211
|
})
|
|
197
212
|
if (object(payload.customer)) found.push([payload.customer.email, 'customer.email', 254], [payload.customer.customerId, 'customer.customerId', undefined])
|
|
198
213
|
found.push([payload.sessionId, 'sessionId', undefined])
|
|
@@ -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;
|
|
@@ -236,6 +247,8 @@ export interface OrderCreateLine {
|
|
|
236
247
|
regularUnitPriceMinor?: number;
|
|
237
248
|
/** Version 6 recorded: the variant's attribute names and values (#495), each at most 255 characters. */
|
|
238
249
|
attributes?: Record<string, string>;
|
|
250
|
+
/** Version 6: the names in attributes the cashier picked for the variant's "Any" option groups (#495 c/d). */
|
|
251
|
+
anyAttributes?: string[];
|
|
239
252
|
/**
|
|
240
253
|
* This line's own tax mode, when it differs from the order's `pricesIncludeTax`
|
|
241
254
|
* (a price that carries its own flag, D2c). Absent means the order's flag, so
|
|
@@ -381,6 +394,8 @@ export interface OrderCreatePayload {
|
|
|
381
394
|
locationId?: string;
|
|
382
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. */
|
|
383
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;
|
|
384
399
|
}
|
|
385
400
|
|
|
386
401
|
/** Batch of commands submitted to the server. */
|
package/src/types/connector.ts
CHANGED
|
@@ -5,7 +5,11 @@ import type { CustomerTraits } from './traits/customer';
|
|
|
5
5
|
import type { ReplicationAdapter } from './replication';
|
|
6
6
|
import type { CatalogueReconcileAdapter, FingerprintReconcileAdapter, IdReconcileAdapter, StockReconcileAdapter } from './reconcile';
|
|
7
7
|
import type { StoreSettings, StoreSettingsChoice } from './store-settings';
|
|
8
|
-
import type { Customer, CustomerInput } from './customers';
|
|
8
|
+
import type { Customer, CustomerInput, CustomerPatch } from './customers';
|
|
9
|
+
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';
|
|
9
13
|
|
|
10
14
|
/**
|
|
11
15
|
* Authentication configuration for a connector.
|
|
@@ -59,6 +63,12 @@ export interface ServerCapabilities {
|
|
|
59
63
|
* coupon. WooCommerce: true only when the woocommerce-pos plugin reports 1.9.0 or later.
|
|
60
64
|
*/
|
|
61
65
|
coupons?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* The store's register approval threshold (ADR-082 d3), from the top level of `/tally/v1/info`. With
|
|
68
|
+
* `register >= 3`, a close whose absolute cash variance is over `thresholdMinor` needs the store's approval.
|
|
69
|
+
* Absent means the store sets none, and the app's own threshold applies.
|
|
70
|
+
*/
|
|
71
|
+
registerApproval?: { thresholdMinor: number };
|
|
62
72
|
}
|
|
63
73
|
|
|
64
74
|
/** #287, ADR-071. `custom`: the till computes as when absent; that server never emits `figures_mismatch` for subtotal or tax. */
|
|
@@ -114,6 +124,16 @@ export function parseLineTax(value: unknown, warn?: (reason: string) => void): {
|
|
|
114
124
|
return undefined;
|
|
115
125
|
}
|
|
116
126
|
|
|
127
|
+
function parseRegisterApproval(value: unknown, warn?: (reason: string) => void): { thresholdMinor: number } | undefined {
|
|
128
|
+
if (value === undefined) return undefined;
|
|
129
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
130
|
+
const { thresholdMinor } = value as { thresholdMinor?: unknown };
|
|
131
|
+
if (typeof thresholdMinor === 'number' && Number.isSafeInteger(thresholdMinor) && thresholdMinor >= 0) return { thresholdMinor };
|
|
132
|
+
}
|
|
133
|
+
warn?.('ignoring a malformed registerApproval');
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
|
|
117
137
|
const maxVersion = (list: unknown): number | undefined => {
|
|
118
138
|
const valid = Array.isArray(list) ? list.filter((v): v is number => typeof v === 'number' && Number.isSafeInteger(v) && v > 0) : [];
|
|
119
139
|
return valid.length > 0 ? Math.max(...valid) : undefined;
|
|
@@ -123,6 +143,7 @@ const maxVersion = (list: unknown): number | undefined => {
|
|
|
123
143
|
* Reads a 2xx body of `GET /tally/v1/info` (ADR-062): `orderCreate` is the max of
|
|
124
144
|
* `contracts["order.create"]`, or 1 when it's missing or malformed; `register` is the max of
|
|
125
145
|
* `contracts.register` when valid; `taxRounding` is the top-level sibling of `contracts` (#287); malformed `lineTax` is ignored.
|
|
146
|
+
* malformed `registerApproval` is ignored (ADR-082).
|
|
126
147
|
* `orderRefund` is the max of `contracts["order.refund"]` when valid, otherwise absent (ADR-080).
|
|
127
148
|
* Absent `taxRounding` uses the default; a present malformed value is unknown, so settings wait.
|
|
128
149
|
* A non-object body is also unknown, not a statement of the store's defaults.
|
|
@@ -132,7 +153,7 @@ export function parseInfoCapabilities(body: unknown, warn?: (reason: string) =>
|
|
|
132
153
|
warn?.('non-object info body: capabilities unknown');
|
|
133
154
|
return undefined;
|
|
134
155
|
}
|
|
135
|
-
const { contracts, taxRounding, lineTax } = body as { contracts?: Record<string, unknown> | null; taxRounding?: unknown; lineTax?: unknown };
|
|
156
|
+
const { contracts, taxRounding, lineTax, registerApproval } = body as { contracts?: Record<string, unknown> | null; taxRounding?: unknown; lineTax?: unknown; registerApproval?: unknown };
|
|
136
157
|
const register = maxVersion(contracts?.register);
|
|
137
158
|
const orderRefund = maxVersion(contracts?.['order.refund']);
|
|
138
159
|
const rounding = parseTaxRounding(taxRounding);
|
|
@@ -141,10 +162,12 @@ export function parseInfoCapabilities(body: unknown, warn?: (reason: string) =>
|
|
|
141
162
|
return undefined;
|
|
142
163
|
}
|
|
143
164
|
const parsedLineTax = parseLineTax(lineTax, warn);
|
|
165
|
+
const parsed = parseRegisterApproval(registerApproval, warn);
|
|
144
166
|
return { orderCreate: maxVersion(contracts?.['order.create']) ?? 1,
|
|
145
167
|
...(orderRefund !== undefined ? { orderRefund } : {}),
|
|
146
168
|
...(register !== undefined ? { register } : {}), ...(rounding ? { taxRounding: rounding } : {}),
|
|
147
|
-
...(parsedLineTax ? { lineTax: parsedLineTax } : {})
|
|
169
|
+
...(parsedLineTax ? { lineTax: parsedLineTax } : {}),
|
|
170
|
+
...(parsed ? { registerApproval: parsed } : {}) };
|
|
148
171
|
}
|
|
149
172
|
|
|
150
173
|
export interface AuthField {
|
|
@@ -297,10 +320,21 @@ export interface TallyConnector {
|
|
|
297
320
|
* `unauthorized` or `invalid_credentials` means sign in again), never on its class.
|
|
298
321
|
*/
|
|
299
322
|
capabilities?: (context: SyncContext) => Promise<ServerCapabilities | undefined>;
|
|
323
|
+
/**
|
|
324
|
+
* The payment methods the till may offer, in the order it shows them (v2 parity A2). Read-only, never writes to
|
|
325
|
+
* the store. `undefined` when the connector has none of its own: the till offers `defaultPaymentMethods()`.
|
|
326
|
+
*/
|
|
327
|
+
paymentMethods?: (context: SyncContext) => Promise<PaymentMethodDescriptor[]>;
|
|
300
328
|
/** Customer search: online only; `undefined` when the connector has no customer support. */
|
|
301
329
|
searchCustomers?: (context: SyncContext, query: string, options?: { limit?: number }) => Promise<Customer[]>;
|
|
302
330
|
/** Customer creation: online only; `undefined` when the connector has no customer support. */
|
|
303
331
|
createCustomer?: (context: SyncContext, input: CustomerInput) => Promise<Customer>;
|
|
332
|
+
/**
|
|
333
|
+
* Customer edit: online only; resolves the customer as the store now has it. Rejects with
|
|
334
|
+
* `ConnectorUnauthorizedError` for credentials and `CustomerServiceError` (`invalid` for a refused patch or an id
|
|
335
|
+
* the store does not have, `server` or `network` otherwise). `undefined` when the connector can't edit customers.
|
|
336
|
+
*/
|
|
337
|
+
updateCustomer?: (context: SyncContext, id: string, patch: CustomerPatch) => Promise<Customer>;
|
|
304
338
|
/** Customer lookup: online only; `undefined` when the connector has no customer support. */
|
|
305
339
|
getCustomer?: (context: SyncContext, id: string) => Promise<Customer | null>;
|
|
306
340
|
/**
|
|
@@ -312,4 +346,27 @@ export interface TallyConnector {
|
|
|
312
346
|
* email receipts.
|
|
313
347
|
*/
|
|
314
348
|
emailReceipt?: (context: SyncContext, orderId: string, email: string, options?: { saveToBilling?: boolean }) => Promise<void>;
|
|
349
|
+
/**
|
|
350
|
+
* The store's orders, newest first, one page per call (ADR-081): online only, read-only. Rejects as `emailReceipt`
|
|
351
|
+
* does (`ConnectorUnauthorizedError` for credentials; a connector's own errors otherwise, e.g. `CustomerServiceError`).
|
|
352
|
+
* `undefined` when the connector has no order history.
|
|
353
|
+
*/
|
|
354
|
+
listOrders?: (context: SyncContext, query?: ListOrdersQuery) => Promise<StoreOrderPage>;
|
|
355
|
+
/**
|
|
356
|
+
* The given orders by store id (ADR-081), in the order asked; an id the store does not have is left out. Online only,
|
|
357
|
+
* read-only; rejects as `listOrders`. `undefined` when the connector has no order history.
|
|
358
|
+
*/
|
|
359
|
+
getOrders?: (context: SyncContext, ids: readonly string[]) => Promise<StoreOrder[]>;
|
|
360
|
+
/**
|
|
361
|
+
* The store's register directory (v2 parity A4): online only, read-only. Rejects with `ConnectorUnauthorizedError`
|
|
362
|
+
* for credentials; a connector's own errors otherwise. `undefined` when the connector has no register directory.
|
|
363
|
+
*/
|
|
364
|
+
listRegisters?: (context: SyncContext) => Promise<RegisterInfo[]>;
|
|
365
|
+
/**
|
|
366
|
+
* The signed-in cashier and their neutral POS permissions (v2 parity A12), mapped from the platform's own roles or
|
|
367
|
+
* capabilities. Read-only. `null` when the connector has no cashier to describe; `undefined` (no method) when the
|
|
368
|
+
* connector has no permission model: the till then allows everything, as before (`can` in `@tallyui/pos`).
|
|
369
|
+
* Permission names outside `CashierPermission` are dropped by `useCashier` (`cashierPermissions`).
|
|
370
|
+
*/
|
|
371
|
+
cashier?: (context: SyncContext) => Promise<Cashier | null>;
|
|
315
372
|
}
|
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';
|