@tallyui/core 3.8.0 → 3.9.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/{commands-BvRgJMgX.d.ts → commands-BPNfbeF9.d.ts} +64 -2
- package/dist/index.d.ts +391 -24
- package/dist/index.js +911 -0
- package/dist/server/index.d.ts +23 -9
- package/dist/server/index.js +146 -2
- package/package.json +5 -3
- package/src/coupons/woocommerce/discount.ts +333 -0
- package/src/coupons/woocommerce/helpers.ts +399 -0
- package/src/coupons/woocommerce/index.ts +15 -0
- package/src/coupons/woocommerce/order-totals.ts +360 -0
- package/src/coupons/woocommerce/pos-data.ts +89 -0
- package/src/coupons/woocommerce/recalculate.ts +405 -0
- package/src/coupons/woocommerce/to-coupon-configs.ts +41 -0
- package/src/coupons/woocommerce/types.ts +155 -0
- package/src/coupons/woocommerce/validate.ts +193 -0
- package/src/index.ts +3 -0
- package/src/server/batch.ts +14 -3
- package/src/server/command-result.ts +27 -1
- package/src/server/index.ts +2 -1
- package/src/server/refund-payload-shape.ts +63 -0
- package/src/server/register-figures.ts +18 -3
- package/src/server/rejection-codes.ts +4 -4
- package/src/server/versions.ts +2 -0
- package/src/types/commands.ts +32 -1
- package/src/types/connector.ts +16 -0
- package/src/types/index.ts +2 -0
- package/src/types/store-settings.ts +2 -0
|
@@ -21,7 +21,68 @@ type RegisterCommandEnvelope<P = Record<string, unknown>> = Omit<CommandEnvelope
|
|
|
21
21
|
version: number;
|
|
22
22
|
};
|
|
23
23
|
/** Any command a transport can carry. */
|
|
24
|
-
type AnyCommandEnvelope = CommandEnvelope<unknown> | RegisterCommandEnvelope<unknown>;
|
|
24
|
+
type AnyCommandEnvelope = CommandEnvelope<unknown> | RegisterCommandEnvelope<unknown> | OrderRefundEnvelope<unknown>;
|
|
25
|
+
/** A line's refunded quantity and restock choice (ADR-080). */
|
|
26
|
+
interface OrderRefundLine {
|
|
27
|
+
orderLineId: string;
|
|
28
|
+
quantity: number;
|
|
29
|
+
restock: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** An online refund against an order, attributed to the refunding session (ADR-080). */
|
|
32
|
+
interface OrderRefundPayload {
|
|
33
|
+
clientRefundId: string;
|
|
34
|
+
orderId: string;
|
|
35
|
+
clientOrderId?: string;
|
|
36
|
+
lines: OrderRefundLine[];
|
|
37
|
+
shippingMinor: number;
|
|
38
|
+
adjustmentMinor: number;
|
|
39
|
+
totalMinor: number;
|
|
40
|
+
destination: 'original_method' | 'cash';
|
|
41
|
+
reason: string;
|
|
42
|
+
registerId: string;
|
|
43
|
+
sessionId: string;
|
|
44
|
+
cashierRef?: string;
|
|
45
|
+
createdAt: string;
|
|
46
|
+
}
|
|
47
|
+
/** An order.refund v1 command with the shared idempotency envelope (ADR-080). */
|
|
48
|
+
type OrderRefundEnvelope<P = OrderRefundPayload> = Omit<CommandEnvelope<P>, 'type' | 'version'> & {
|
|
49
|
+
type: 'order.refund';
|
|
50
|
+
version: 1;
|
|
51
|
+
};
|
|
52
|
+
/** The server's refund total, tender attribution and platform refunds (ADR-080). */
|
|
53
|
+
interface OrderRefundResult {
|
|
54
|
+
totalMinor: number;
|
|
55
|
+
byMethod: Record<string, number>;
|
|
56
|
+
refunds: Array<{
|
|
57
|
+
id: string;
|
|
58
|
+
paymentId: string;
|
|
59
|
+
totalMinor: number;
|
|
60
|
+
state: string;
|
|
61
|
+
}>;
|
|
62
|
+
}
|
|
63
|
+
/** Per-command refund refusals (ADR-080 decision 5). */
|
|
64
|
+
type OrderRefundRejectionCode = 'nothing_to_refund' | 'quantity_exceeds' | 'amount_mismatch' | 'order_state' | 'not_till_order' | 'forbidden' | 'no_open_session';
|
|
65
|
+
/** Lines exceeding the server's refundable quantities (ADR-080). */
|
|
66
|
+
interface OrderRefundQuantityExceedsData {
|
|
67
|
+
lines: Array<{
|
|
68
|
+
orderLineId: string;
|
|
69
|
+
quantity: number;
|
|
70
|
+
refundableQuantity: number;
|
|
71
|
+
}>;
|
|
72
|
+
}
|
|
73
|
+
/** The till's expected refund and the server's computed amount (ADR-080). */
|
|
74
|
+
interface OrderRefundAmountMismatchData {
|
|
75
|
+
expectedMinor: number;
|
|
76
|
+
serverMinor: number;
|
|
77
|
+
}
|
|
78
|
+
/** The order state preventing a refund (ADR-080). */
|
|
79
|
+
interface OrderRefundOrderStateData {
|
|
80
|
+
state: string;
|
|
81
|
+
}
|
|
82
|
+
/** The session that is not open on the refunding register (ADR-080). */
|
|
83
|
+
interface OrderRefundNoOpenSessionData {
|
|
84
|
+
sessionId: string;
|
|
85
|
+
}
|
|
25
86
|
/** An order.create envelope: 5 is 4 plus fees, shipping and custom lines (ADR-075), sent only for an order that has one. */
|
|
26
87
|
type OrderCreateEnvelope = CommandEnvelope<OrderCreatePayload> & {
|
|
27
88
|
type: 'order.create';
|
|
@@ -116,6 +177,7 @@ interface CommandResult {
|
|
|
116
177
|
warnings?: CommandWarning[];
|
|
117
178
|
error?: CommandError;
|
|
118
179
|
register?: RegisterCommandResult;
|
|
180
|
+
refund?: OrderRefundResult;
|
|
119
181
|
}
|
|
120
182
|
/** A register command's server figures (registers c2b applies them). */
|
|
121
183
|
interface RegisterCommandResult {
|
|
@@ -408,4 +470,4 @@ declare const MAX_COMMANDS_PER_BATCH = 50;
|
|
|
408
470
|
*/
|
|
409
471
|
declare function isCommandBatchResponse(value: unknown): value is CommandBatchResponse;
|
|
410
472
|
|
|
411
|
-
export { type AnyCommandEnvelope as A, type BatchTooLargeBody as B, type CommandWarning as C, MAX_COMMANDS_PER_BATCH as M, type OrderCreateDisplay as O, PROTOCOL_HEADER as P, type RegisterClosureSubmitPayload as R, COMMANDS_PATH as a, type CommandBatchRequest as b, type CommandBatchResponse as c, type CommandEnvelope as d, type CommandError as e, type CommandResult as f, type CommandServerRefs as g, type CommandStatus as h, type CommandType as i, type OrderCreateEnvelope as j, type OrderCreateLine as k, type OrderCreatePayload as l, type OrderCreatePayment as m, type OrderCreateTaxRate as n,
|
|
473
|
+
export { type AnyCommandEnvelope as A, type BatchTooLargeBody as B, type CommandWarning as C, type RegisterCommandResult as D, type RegisterCommandType as E, type RegisterMovementRecordPayload as F, type RegisterMovementVoidPayload as G, type RegisterSessionAlreadyOpenData as H, type RegisterSessionOpenPayload as I, type RegisterSessionSupersededData as J, type RegisterSessionTransitionPayload as K, isCommandBatchResponse as L, MAX_COMMANDS_PER_BATCH as M, type OrderCreateDisplay as O, PROTOCOL_HEADER as P, type RegisterClosureSubmitPayload as R, COMMANDS_PATH as a, type CommandBatchRequest as b, type CommandBatchResponse as c, type CommandEnvelope as d, type CommandError as e, type CommandResult as f, type CommandServerRefs as g, type CommandStatus as h, type CommandType as i, type OrderCreateEnvelope as j, type OrderCreateLine as k, type OrderCreatePayload as l, type OrderCreatePayment as m, type OrderCreateTaxRate as n, type OrderRefundAmountMismatchData as o, type OrderRefundEnvelope as p, type OrderRefundLine as q, type OrderRefundNoOpenSessionData as r, type OrderRefundOrderStateData as s, type OrderRefundPayload as t, type OrderRefundQuantityExceedsData as u, type OrderRefundRejectionCode as v, type OrderRefundResult as w, PROTOCOL_VERSION as x, type PaymentMethodKind as y, type RegisterCommandEnvelope as z };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RxReplicationPullStreamItem, RxReplicationWriteToMasterRow, RxJsonSchema } from 'rxdb';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
-
import { C as CommandWarning } from './commands-
|
|
4
|
-
export { A as AnyCommandEnvelope, B as BatchTooLargeBody, a as COMMANDS_PATH, b as CommandBatchRequest, c as CommandBatchResponse, d as CommandEnvelope, e as CommandError, f as CommandResult, g as CommandServerRefs, h as CommandStatus, i as CommandType, M as MAX_COMMANDS_PER_BATCH, O as OrderCreateDisplay, j as OrderCreateEnvelope, k as OrderCreateLine, l as OrderCreatePayload, m as OrderCreatePayment, n as OrderCreateTaxRate, P as PROTOCOL_HEADER,
|
|
3
|
+
import { C as CommandWarning } from './commands-BPNfbeF9.js';
|
|
4
|
+
export { A as AnyCommandEnvelope, B as BatchTooLargeBody, a as COMMANDS_PATH, b as CommandBatchRequest, c as CommandBatchResponse, d as CommandEnvelope, e as CommandError, f as CommandResult, g as CommandServerRefs, h as CommandStatus, i as CommandType, M as MAX_COMMANDS_PER_BATCH, O as OrderCreateDisplay, j as OrderCreateEnvelope, k as OrderCreateLine, l as OrderCreatePayload, m as OrderCreatePayment, n as OrderCreateTaxRate, o as OrderRefundAmountMismatchData, p as OrderRefundEnvelope, q as OrderRefundLine, r as OrderRefundNoOpenSessionData, s as OrderRefundOrderStateData, t as OrderRefundPayload, u as OrderRefundQuantityExceedsData, v as OrderRefundRejectionCode, w as OrderRefundResult, P as PROTOCOL_HEADER, x as PROTOCOL_VERSION, y as PaymentMethodKind, R as RegisterClosureSubmitPayload, z as RegisterCommandEnvelope, D as RegisterCommandResult, E as RegisterCommandType, F as RegisterMovementRecordPayload, G as RegisterMovementVoidPayload, H as RegisterSessionAlreadyOpenData, I as RegisterSessionOpenPayload, J as RegisterSessionSupersededData, K as RegisterSessionTransitionPayload, L as isCommandBatchResponse } from './commands-BPNfbeF9.js';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import { ReactNode } from 'react';
|
|
7
7
|
|
|
@@ -376,6 +376,8 @@ interface StoreSettings {
|
|
|
376
376
|
shipping: boolean;
|
|
377
377
|
}[]>;
|
|
378
378
|
taxRoundAtSubtotal?: boolean;
|
|
379
|
+
/** WooCommerce's calculate coupon discounts sequentially setting. */
|
|
380
|
+
calcDiscountsSequentially?: boolean;
|
|
379
381
|
shippingTaxClass?: string;
|
|
380
382
|
taxClassSlugs?: string[];
|
|
381
383
|
/** Connector-specific and opaque to the app: what the connector needs to price documents. The app passes it back to the connector unchanged, and never logs it. */
|
|
@@ -460,6 +462,8 @@ interface ServerCapabilities {
|
|
|
460
462
|
orderCreate: number;
|
|
461
463
|
/** The highest `register` contract version; absent or 0 means no register sync. */
|
|
462
464
|
register?: number;
|
|
465
|
+
/** The highest `order.refund` version; absent or 0 means the store takes no refunds and the app hides the action (ADR-080). */
|
|
466
|
+
orderRefund?: number;
|
|
463
467
|
/** How the store rounds tax (#287). Absent: an older server, per_order + half_away_from_zero. */
|
|
464
468
|
taxRounding?: TaxRounding;
|
|
465
469
|
/** Whether one order may carry several payments. Absent means it may: order.create's `payments` has always been a
|
|
@@ -474,6 +478,11 @@ interface ServerCapabilities {
|
|
|
474
478
|
none: boolean;
|
|
475
479
|
classes: boolean;
|
|
476
480
|
};
|
|
481
|
+
/**
|
|
482
|
+
* Whether the store accepts an order's coupons (ADR-077). Absent means it does not: the till refuses to apply a
|
|
483
|
+
* coupon. WooCommerce: true only when the woocommerce-pos plugin reports 1.9.0 or later.
|
|
484
|
+
*/
|
|
485
|
+
coupons?: boolean;
|
|
477
486
|
}
|
|
478
487
|
/** #287, ADR-071. `custom`: the till computes as when absent; that server never emits `figures_mismatch` for subtotal or tax. */
|
|
479
488
|
type TaxRounding = {
|
|
@@ -508,6 +517,7 @@ declare function parseLineTax(value: unknown, warn?: (reason: string) => void):
|
|
|
508
517
|
* Reads a 2xx body of `GET /tally/v1/info` (ADR-062): `orderCreate` is the max of
|
|
509
518
|
* `contracts["order.create"]`, or 1 when it's missing or malformed; `register` is the max of
|
|
510
519
|
* `contracts.register` when valid; `taxRounding` is the top-level sibling of `contracts` (#287); malformed `lineTax` is ignored.
|
|
520
|
+
* `orderRefund` is the max of `contracts["order.refund"]` when valid, otherwise absent (ADR-080).
|
|
511
521
|
* Absent `taxRounding` uses the default; a present malformed value is unknown, so settings wait.
|
|
512
522
|
* A non-object body is also unknown, not a statement of the store's defaults.
|
|
513
523
|
*/
|
|
@@ -620,6 +630,12 @@ interface TallyConnector {
|
|
|
620
630
|
calculatedPrices?: FingerprintReconcileAdapter;
|
|
621
631
|
/** The daily catalogue check (#248): refetches what differs, deletes only with proof. */
|
|
622
632
|
catalogue?: CatalogueReconcileAdapter;
|
|
633
|
+
/**
|
|
634
|
+
* The coupons' only source (ADR-077 amendment 2): a catalogue reconcile over the coupon listing, whose
|
|
635
|
+
* fingerprint carries the usage that never moves the modified time. Optional: a connector without it has no
|
|
636
|
+
* coupons, and the coupons feature is gated on it.
|
|
637
|
+
*/
|
|
638
|
+
coupons?: CatalogueReconcileAdapter;
|
|
623
639
|
};
|
|
624
640
|
/**
|
|
625
641
|
* Reads the store's own settings (TV4): currency, tax inclusivity, tax
|
|
@@ -1151,28 +1167,379 @@ declare function resolveInheritedShippingTaxClass(activeLineItems: readonly {
|
|
|
1151
1167
|
declare function taxClassFromWire(value?: string | null): string;
|
|
1152
1168
|
declare function taxClassToWire(value?: string | null): string;
|
|
1153
1169
|
|
|
1154
|
-
type
|
|
1155
|
-
type
|
|
1156
|
-
type
|
|
1157
|
-
declare const
|
|
1158
|
-
declare const
|
|
1159
|
-
type
|
|
1160
|
-
declare const
|
|
1161
|
-
declare const
|
|
1162
|
-
declare const
|
|
1163
|
-
declare const
|
|
1164
|
-
declare const
|
|
1165
|
-
declare const
|
|
1166
|
-
declare const
|
|
1167
|
-
declare const
|
|
1168
|
-
declare const
|
|
1169
|
-
declare const
|
|
1170
|
-
declare const
|
|
1171
|
-
declare const
|
|
1172
|
-
declare const
|
|
1173
|
-
declare const
|
|
1170
|
+
type index$1_CalculateTaxesInput = CalculateTaxesInput;
|
|
1171
|
+
type index$1_CalculateTaxesResult = CalculateTaxesResult;
|
|
1172
|
+
type index$1_ItemizedTax = ItemizedTax;
|
|
1173
|
+
declare const index$1_NO_SHIPPING_TAX: typeof NO_SHIPPING_TAX;
|
|
1174
|
+
declare const index$1_STANDARD_TAX_CLASS: typeof STANDARD_TAX_CLASS;
|
|
1175
|
+
type index$1_WooTaxRate = WooTaxRate;
|
|
1176
|
+
declare const index$1_addNumberPrecision: typeof addNumberPrecision;
|
|
1177
|
+
declare const index$1_calculateTaxes: typeof calculateTaxes;
|
|
1178
|
+
declare const index$1_filterTaxRates: typeof filterTaxRates;
|
|
1179
|
+
declare const index$1_getRoundingPrecision: typeof getRoundingPrecision;
|
|
1180
|
+
declare const index$1_normalizeTaxClass: typeof normalizeTaxClass;
|
|
1181
|
+
declare const index$1_removeNumberPrecision: typeof removeNumberPrecision;
|
|
1182
|
+
declare const index$1_resolveInheritedShippingTaxClass: typeof resolveInheritedShippingTaxClass;
|
|
1183
|
+
declare const index$1_roundHalfDown: typeof roundHalfDown;
|
|
1184
|
+
declare const index$1_roundHalfUp: typeof roundHalfUp;
|
|
1185
|
+
declare const index$1_roundTaxTotal: typeof roundTaxTotal;
|
|
1186
|
+
declare const index$1_sumItemizedTaxes: typeof sumItemizedTaxes;
|
|
1187
|
+
declare const index$1_sumTaxes: typeof sumTaxes;
|
|
1188
|
+
declare const index$1_taxClassFromWire: typeof taxClassFromWire;
|
|
1189
|
+
declare const index$1_taxClassToWire: typeof taxClassToWire;
|
|
1190
|
+
declare namespace index$1 {
|
|
1191
|
+
export { type index$1_CalculateTaxesInput as CalculateTaxesInput, type index$1_CalculateTaxesResult as CalculateTaxesResult, type index$1_ItemizedTax as ItemizedTax, index$1_NO_SHIPPING_TAX as NO_SHIPPING_TAX, index$1_STANDARD_TAX_CLASS as STANDARD_TAX_CLASS, type index$1_WooTaxRate as WooTaxRate, index$1_addNumberPrecision as addNumberPrecision, index$1_calculateTaxes as calculateTaxes, index$1_filterTaxRates as filterTaxRates, index$1_getRoundingPrecision as getRoundingPrecision, index$1_normalizeTaxClass as normalizeTaxClass, index$1_removeNumberPrecision as removeNumberPrecision, index$1_resolveInheritedShippingTaxClass as resolveInheritedShippingTaxClass, index$1_roundHalfDown as roundHalfDown, index$1_roundHalfUp as roundHalfUp, index$1_roundTaxTotal as roundTaxTotal, index$1_sumItemizedTaxes as sumItemizedTaxes, index$1_sumTaxes as sumTaxes, index$1_taxClassFromWire as taxClassFromWire, index$1_taxClassToWire as taxClassToWire };
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
interface CouponLineItem {
|
|
1195
|
+
product_id: number;
|
|
1196
|
+
quantity: number;
|
|
1197
|
+
price: number;
|
|
1198
|
+
subtotal: string;
|
|
1199
|
+
total: string;
|
|
1200
|
+
categories: {
|
|
1201
|
+
id: number;
|
|
1202
|
+
}[];
|
|
1203
|
+
on_sale: boolean;
|
|
1204
|
+
/** Stable index into the source line-items array for per-line matching */
|
|
1205
|
+
lineIndex?: number;
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Build a product categories map enriched with ancestor category IDs.
|
|
1209
|
+
*
|
|
1210
|
+
* WooCommerce's wc_get_product_cat_ids() includes ALL ancestor categories
|
|
1211
|
+
* (via get_ancestors()) when checking coupon category restrictions. The POS
|
|
1212
|
+
* REST API only returns directly-assigned categories on product documents.
|
|
1213
|
+
* This function bridges the gap by walking up the category tree.
|
|
1214
|
+
*
|
|
1215
|
+
* @param productCategories - Map of product_id → directly-assigned categories
|
|
1216
|
+
* @param categoryParentMap - Map of category_id → parent_id (from products/categories collection)
|
|
1217
|
+
* @returns Enriched map with ancestor categories included
|
|
1218
|
+
*/
|
|
1219
|
+
declare function enrichCategoriesWithAncestors(productCategories: Map<number, {
|
|
1220
|
+
id: number;
|
|
1221
|
+
}[]>, categoryParentMap: Map<number, number>): Map<number, {
|
|
1222
|
+
id: number;
|
|
1223
|
+
}[]>;
|
|
1224
|
+
|
|
1225
|
+
interface CouponDiscountConfig {
|
|
1226
|
+
discount_type: 'percent' | 'fixed_cart' | 'fixed_product';
|
|
1227
|
+
amount: string;
|
|
1228
|
+
limit_usage_to_x_items: number | null;
|
|
1229
|
+
product_ids: number[];
|
|
1230
|
+
excluded_product_ids: number[];
|
|
1231
|
+
product_categories: number[];
|
|
1232
|
+
excluded_product_categories: number[];
|
|
1233
|
+
exclude_sale_items: boolean;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
interface MetaDataInput {
|
|
1237
|
+
id?: number;
|
|
1238
|
+
key?: string;
|
|
1239
|
+
value?: unknown;
|
|
1240
|
+
display_key?: string;
|
|
1241
|
+
display_value?: string;
|
|
1242
|
+
}
|
|
1243
|
+
interface TaxEntryInput {
|
|
1244
|
+
id?: number;
|
|
1245
|
+
subtotal?: string;
|
|
1246
|
+
total?: string;
|
|
1247
|
+
}
|
|
1248
|
+
interface LineItemInput {
|
|
1249
|
+
product_id?: number | null;
|
|
1250
|
+
variation_id?: number | null;
|
|
1251
|
+
quantity?: number;
|
|
1252
|
+
price?: number;
|
|
1253
|
+
tax_class?: string | null;
|
|
1254
|
+
tax_status?: string | null;
|
|
1255
|
+
subtotal?: string;
|
|
1256
|
+
subtotal_tax?: string;
|
|
1257
|
+
total?: string;
|
|
1258
|
+
total_tax?: string;
|
|
1259
|
+
taxes?: TaxEntryInput[];
|
|
1260
|
+
meta_data?: MetaDataInput[];
|
|
1261
|
+
}
|
|
1262
|
+
interface FeeLineInput {
|
|
1263
|
+
name?: string | null;
|
|
1264
|
+
tax_class?: string | null;
|
|
1265
|
+
tax_status?: string | null;
|
|
1266
|
+
total?: string;
|
|
1267
|
+
total_tax?: string;
|
|
1268
|
+
taxes?: TaxEntryInput[];
|
|
1269
|
+
meta_data?: MetaDataInput[];
|
|
1270
|
+
}
|
|
1271
|
+
interface ShippingLineInput {
|
|
1272
|
+
method_id?: string | null;
|
|
1273
|
+
method_title?: string | null;
|
|
1274
|
+
total?: string;
|
|
1275
|
+
total_tax?: string;
|
|
1276
|
+
taxes?: TaxEntryInput[];
|
|
1277
|
+
meta_data?: MetaDataInput[];
|
|
1278
|
+
}
|
|
1279
|
+
interface CouponLineInput {
|
|
1280
|
+
code?: string | null;
|
|
1281
|
+
discount?: string;
|
|
1282
|
+
discount_tax?: string;
|
|
1283
|
+
meta_data?: MetaDataInput[];
|
|
1284
|
+
}
|
|
1285
|
+
interface TaxRateInput {
|
|
1286
|
+
id?: number;
|
|
1287
|
+
name?: string;
|
|
1288
|
+
rate?: string;
|
|
1289
|
+
compound?: boolean;
|
|
1290
|
+
order?: number;
|
|
1291
|
+
/**
|
|
1292
|
+
* WooCommerce `tax_rate_priority` — THE key WC_Tax sorts compound rates by, and the
|
|
1293
|
+
* one that decides which rate is applied outermost. The app's rate documents carry it
|
|
1294
|
+
* (see the taxRates schema), `calculateTaxes` reads it in preference to `order`, and
|
|
1295
|
+
* `createCartConfig` has always passed it through by spreading. It simply was not
|
|
1296
|
+
* declared here, so a caller assembling rates against this type could not express the
|
|
1297
|
+
* field the engine actually sorts on — which is the shape woocommerce-pos#1548 turned
|
|
1298
|
+
* on: real stores leave `order` at 0 on every rate and differentiate by priority.
|
|
1299
|
+
*/
|
|
1300
|
+
priority?: number;
|
|
1301
|
+
class?: string;
|
|
1302
|
+
shipping?: boolean;
|
|
1303
|
+
country?: string;
|
|
1304
|
+
state?: string;
|
|
1305
|
+
}
|
|
1306
|
+
interface CouponInput {
|
|
1307
|
+
code: string;
|
|
1308
|
+
discount_type: 'percent' | 'fixed_cart' | 'fixed_product';
|
|
1309
|
+
amount: string;
|
|
1310
|
+
limit_usage_to_x_items?: number | null;
|
|
1311
|
+
product_ids?: readonly number[];
|
|
1312
|
+
excluded_product_ids?: readonly number[];
|
|
1313
|
+
product_categories?: readonly number[];
|
|
1314
|
+
excluded_product_categories?: readonly number[];
|
|
1315
|
+
exclude_sale_items?: boolean;
|
|
1316
|
+
individual_use?: boolean;
|
|
1317
|
+
date_expires_gmt?: string | null;
|
|
1318
|
+
usage_limit?: number | null;
|
|
1319
|
+
usage_count?: number;
|
|
1320
|
+
usage_limit_per_user?: number | null;
|
|
1321
|
+
used_by?: readonly (string | number)[];
|
|
1322
|
+
minimum_amount?: string;
|
|
1323
|
+
maximum_amount?: string;
|
|
1324
|
+
email_restrictions?: readonly string[];
|
|
1325
|
+
}
|
|
1326
|
+
interface CouponContext {
|
|
1327
|
+
/** key = LOWERCASE code. Must contain every active coupon_lines code + every validate.codes entry. */
|
|
1328
|
+
readonly coupons: ReadonlyMap<string, CouponInput>;
|
|
1329
|
+
/** Directly-assigned categories per product_id (NOT enriched — enrichment is internal). */
|
|
1330
|
+
readonly productCategories: ReadonlyMap<number, readonly {
|
|
1331
|
+
id: number;
|
|
1332
|
+
}[]>;
|
|
1333
|
+
/** category_id -> parent_id; module walks ancestors itself (wc_get_product_cat_ids parity). */
|
|
1334
|
+
readonly categoryParents?: ReadonlyMap<number, number>;
|
|
1335
|
+
}
|
|
1336
|
+
interface WarningSite {
|
|
1337
|
+
lineType: 'line_item' | 'fee_line' | 'shipping_line' | 'coupon_line';
|
|
1338
|
+
index: number;
|
|
1339
|
+
uuid?: string;
|
|
1340
|
+
}
|
|
1341
|
+
type EngineWarning = {
|
|
1342
|
+
code: 'malformed_pos_data';
|
|
1343
|
+
where: WarningSite;
|
|
1344
|
+
} | {
|
|
1345
|
+
code: 'unknown_tax_rate_id';
|
|
1346
|
+
rateId: number;
|
|
1347
|
+
};
|
|
1348
|
+
type CouponRejectionCode = 'already_applied' | 'expired' | 'usage_limit_reached' | 'usage_limit_reached_for_customer' | 'minimum_spend_not_met' | 'maximum_spend_exceeded' | 'individual_use' | 'individual_use_conflict' | 'email_required' | 'email_not_allowed' | 'not_applicable_to_cart';
|
|
1349
|
+
interface CouponRejection {
|
|
1350
|
+
code: CouponRejectionCode;
|
|
1351
|
+
params?: Readonly<Record<string, string | number>>;
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
interface RecalculateInput {
|
|
1355
|
+
lineItems: LineItemInput[];
|
|
1356
|
+
couponLines: CouponLineInput[];
|
|
1357
|
+
/** Map of coupon code (lowercase) -> coupon config from RxDB */
|
|
1358
|
+
couponConfigs: Map<string, CouponDiscountConfig>;
|
|
1359
|
+
pricesIncludeTax: boolean;
|
|
1360
|
+
calcDiscountsSequentially: boolean;
|
|
1361
|
+
taxRates: {
|
|
1362
|
+
id: number;
|
|
1363
|
+
rate: string;
|
|
1364
|
+
compound: boolean;
|
|
1365
|
+
order: number;
|
|
1366
|
+
/** WooCommerce `tax_rate_priority` — decides compound sequencing (#1548). */
|
|
1367
|
+
priority?: number;
|
|
1368
|
+
class?: string;
|
|
1369
|
+
}[];
|
|
1370
|
+
/** Product categories by product_id for coupon restriction checks */
|
|
1371
|
+
productCategories: Map<number, {
|
|
1372
|
+
id: number;
|
|
1373
|
+
}[]>;
|
|
1374
|
+
/** Whether to round tax at subtotal level (default false = round per-item) */
|
|
1375
|
+
taxRoundAtSubtotal?: boolean;
|
|
1376
|
+
/** Price decimal places (default 2) */
|
|
1377
|
+
dp?: number;
|
|
1378
|
+
}
|
|
1379
|
+
interface RecalculateResult {
|
|
1380
|
+
lineItems: LineItemInput[];
|
|
1381
|
+
couponLines: CouponLineInput[];
|
|
1382
|
+
}
|
|
1383
|
+
/**
|
|
1384
|
+
* Recalculate all coupon discounts from scratch, mirroring WooCommerce's
|
|
1385
|
+
* recalculate_coupons() in abstract-wc-order.php.
|
|
1386
|
+
*
|
|
1387
|
+
* Algorithm:
|
|
1388
|
+
* 1. Reset line item totals to subtotals (pre-coupon state)
|
|
1389
|
+
* 2. Build discount items using POS price as base (mirrors server subtotal filter)
|
|
1390
|
+
* 3. Apply each coupon in order, capping by remaining item value
|
|
1391
|
+
* 4. Update line item totals and coupon line discount amounts
|
|
1392
|
+
*/
|
|
1393
|
+
declare function recalculateCoupons(input: RecalculateInput): RecalculateResult;
|
|
1394
|
+
|
|
1395
|
+
interface Props {
|
|
1396
|
+
lineItems?: LineItemInput[];
|
|
1397
|
+
shippingLines?: ShippingLineInput[];
|
|
1398
|
+
feeLines?: FeeLineInput[];
|
|
1399
|
+
couponLines?: CouponLineInput[];
|
|
1400
|
+
taxRates?: TaxRateInput[];
|
|
1401
|
+
taxRoundAtSubtotal?: boolean;
|
|
1402
|
+
dp?: number;
|
|
1403
|
+
pricesIncludeTax?: boolean;
|
|
1404
|
+
}
|
|
1405
|
+
/**
|
|
1406
|
+
* Calculate order totals from line items, fees, shipping, and coupons.
|
|
1407
|
+
*
|
|
1408
|
+
* When taxRoundAtSubtotal=true, tax values on individual lines are at rounding precision
|
|
1409
|
+
* and the final aggregated tax_total/shipping_tax_total is rounded to dp once.
|
|
1410
|
+
*
|
|
1411
|
+
* When taxRoundAtSubtotal=false (default), taxes were already rounded per-item to dp.
|
|
1412
|
+
*
|
|
1413
|
+
* @param dp - Price decimal places (default 2)
|
|
1414
|
+
* @param pricesIncludeTax - Whether prices include tax (affects rounding mode)
|
|
1415
|
+
* @param onWarning - Optional callback fired when a line references a tax rate id absent
|
|
1416
|
+
* from taxRates (a bucket is lazily created instead of throwing)
|
|
1417
|
+
*/
|
|
1418
|
+
declare function calculateOrderTotals({ lineItems, shippingLines, feeLines, couponLines, taxRates, taxRoundAtSubtotal, dp, pricesIncludeTax, }: Props, onWarning?: (w: {
|
|
1419
|
+
code: 'unknown_tax_rate_id';
|
|
1420
|
+
rateId: number;
|
|
1421
|
+
}) => void): {
|
|
1422
|
+
/**
|
|
1423
|
+
* These properties are stored on the order document
|
|
1424
|
+
*/
|
|
1425
|
+
discount_total: string;
|
|
1426
|
+
discount_tax: string;
|
|
1427
|
+
shipping_total: string;
|
|
1428
|
+
shipping_tax: string;
|
|
1429
|
+
cart_tax: string;
|
|
1430
|
+
total: string;
|
|
1431
|
+
total_tax: string;
|
|
1432
|
+
tax_lines: {
|
|
1433
|
+
tax_total: string;
|
|
1434
|
+
shipping_tax_total: string;
|
|
1435
|
+
rate_id: number;
|
|
1436
|
+
label: string;
|
|
1437
|
+
compound: boolean;
|
|
1438
|
+
rate_percent: number;
|
|
1439
|
+
meta_data: any[];
|
|
1440
|
+
}[];
|
|
1441
|
+
/**
|
|
1442
|
+
* Subtotals are not stored on the order document, but we need them to display in the cart
|
|
1443
|
+
*/
|
|
1444
|
+
subtotal: string;
|
|
1445
|
+
subtotal_tax: string;
|
|
1446
|
+
/**
|
|
1447
|
+
* Need to add fee_total to display in the cart, to match the WC Admin display
|
|
1448
|
+
*/
|
|
1449
|
+
fee_total: string;
|
|
1450
|
+
fee_tax: string;
|
|
1451
|
+
coupon_total: string;
|
|
1452
|
+
coupon_tax: string;
|
|
1453
|
+
};
|
|
1454
|
+
/**
|
|
1455
|
+
* The order-totals read model: the return shape of `calculateOrderTotals`.
|
|
1456
|
+
*
|
|
1457
|
+
* Named here, beside the one function that produces it, so the shape has a
|
|
1458
|
+
* single author. Re-exported as a public type by the package index because
|
|
1459
|
+
* `SettleResult.totals` is typed with it and callers must be able to name it.
|
|
1460
|
+
*/
|
|
1461
|
+
type OrderTotals = ReturnType<typeof calculateOrderTotals>;
|
|
1462
|
+
|
|
1463
|
+
/**
|
|
1464
|
+
* Known gaps (ADR-077 amendment 1), missing upstream too, not regressions:
|
|
1465
|
+
* - `free_shipping` is not applied;
|
|
1466
|
+
* - a coupon's `status` is not checked;
|
|
1467
|
+
* - variation-level product restrictions do not match;
|
|
1468
|
+
* - misc lines do not match category restrictions;
|
|
1469
|
+
* - only `percent`, `fixed_cart` and `fixed_product` are supported;
|
|
1470
|
+
* - usage holds are not modelled.
|
|
1471
|
+
*
|
|
1472
|
+
* Parity unverified (the WooCommerce lane checks each on the dev store):
|
|
1473
|
+
* - the minimum and maximum spend basis on a store whose prices include tax;
|
|
1474
|
+
* - the email restriction (billing email only, not the account email);
|
|
1475
|
+
* - individual use (rejects the new coupon rather than replacing the others);
|
|
1476
|
+
* - `fixed_cart` spreading over excluded items;
|
|
1477
|
+
* - expiry (an instant against the end of day in the site's timezone);
|
|
1478
|
+
* - an inclusive coupon line's `discount + discount_tax`.
|
|
1479
|
+
*/
|
|
1480
|
+
|
|
1481
|
+
interface CouponValidationContext {
|
|
1482
|
+
lineItems: CouponLineItem[];
|
|
1483
|
+
appliedCoupons: string[];
|
|
1484
|
+
appliedCouponsWithIndividualUse?: string[];
|
|
1485
|
+
cartSubtotal: number;
|
|
1486
|
+
customerEmail: string;
|
|
1487
|
+
customerId: number | null;
|
|
1488
|
+
/** Epoch ms — the package's only clock input (SPEC §4: no Date.now() inside the engine). */
|
|
1489
|
+
now: number;
|
|
1490
|
+
}
|
|
1491
|
+
type ValidationResult = {
|
|
1492
|
+
valid: true;
|
|
1493
|
+
} | {
|
|
1494
|
+
valid: false;
|
|
1495
|
+
rejection: CouponRejection;
|
|
1496
|
+
};
|
|
1497
|
+
/**
|
|
1498
|
+
* Client-side coupon validation that mirrors WooCommerce's coupon checks.
|
|
1499
|
+
*
|
|
1500
|
+
* Validates expiry, usage limits, minimum/maximum spend, individual-use rules,
|
|
1501
|
+
* email restrictions, and product/category eligibility.
|
|
1502
|
+
*/
|
|
1503
|
+
declare function validateCoupon(coupon: any, context: CouponValidationContext): ValidationResult;
|
|
1504
|
+
|
|
1505
|
+
/**
|
|
1506
|
+
* Map `CouponInput`s (the adapter-prefetched coupon documents) to the replay's
|
|
1507
|
+
* `CouponDiscountConfig` shape, keyed by the given (lowercase) codes.
|
|
1508
|
+
*
|
|
1509
|
+
* Extracted from `settleCart` so a differential harness can replay the composition
|
|
1510
|
+
* with the EXACT mapping settle uses — the defaults here (`amount || '0'`, `?? null`,
|
|
1511
|
+
* `?? false`, array copies) must never be duplicated. The original caller,
|
|
1512
|
+
* `settle.oracle.test.ts`, is retired; `settle-cart-differential.test.ts` in
|
|
1513
|
+
* packages/core is the harness that relies on this now (via its own
|
|
1514
|
+
* `toLegacyCouponConfigs`, which must stay in step with this function).
|
|
1515
|
+
*
|
|
1516
|
+
* Codes absent from the map are skipped; `settleCart`'s missing_coupon gate
|
|
1517
|
+
* guarantees presence before this runs, and `recalculateCoupons` zeroes the
|
|
1518
|
+
* discount for any coupon line without a config.
|
|
1519
|
+
*/
|
|
1520
|
+
declare function toCouponConfigs(codes: readonly string[], coupons: ReadonlyMap<string, CouponInput>): Map<string, CouponDiscountConfig>;
|
|
1521
|
+
|
|
1522
|
+
type index_CouponContext = CouponContext;
|
|
1523
|
+
type index_CouponDiscountConfig = CouponDiscountConfig;
|
|
1524
|
+
type index_CouponInput = CouponInput;
|
|
1525
|
+
type index_CouponLineInput = CouponLineInput;
|
|
1526
|
+
type index_CouponRejection = CouponRejection;
|
|
1527
|
+
type index_CouponRejectionCode = CouponRejectionCode;
|
|
1528
|
+
type index_CouponValidationContext = CouponValidationContext;
|
|
1529
|
+
type index_EngineWarning = EngineWarning;
|
|
1530
|
+
type index_LineItemInput = LineItemInput;
|
|
1531
|
+
type index_OrderTotals = OrderTotals;
|
|
1532
|
+
type index_RecalculateInput = RecalculateInput;
|
|
1533
|
+
type index_RecalculateResult = RecalculateResult;
|
|
1534
|
+
type index_TaxRateInput = TaxRateInput;
|
|
1535
|
+
type index_ValidationResult = ValidationResult;
|
|
1536
|
+
declare const index_calculateOrderTotals: typeof calculateOrderTotals;
|
|
1537
|
+
declare const index_enrichCategoriesWithAncestors: typeof enrichCategoriesWithAncestors;
|
|
1538
|
+
declare const index_recalculateCoupons: typeof recalculateCoupons;
|
|
1539
|
+
declare const index_toCouponConfigs: typeof toCouponConfigs;
|
|
1540
|
+
declare const index_validateCoupon: typeof validateCoupon;
|
|
1174
1541
|
declare namespace index {
|
|
1175
|
-
export { type
|
|
1542
|
+
export { type index_CouponContext as CouponContext, type index_CouponDiscountConfig as CouponDiscountConfig, type index_CouponInput as CouponInput, type index_CouponLineInput as CouponLineInput, type index_CouponRejection as CouponRejection, type index_CouponRejectionCode as CouponRejectionCode, type index_CouponValidationContext as CouponValidationContext, type index_EngineWarning as EngineWarning, type index_LineItemInput as LineItemInput, type index_OrderTotals as OrderTotals, type index_RecalculateInput as RecalculateInput, type index_RecalculateResult as RecalculateResult, type index_TaxRateInput as TaxRateInput, type index_ValidationResult as ValidationResult, index_calculateOrderTotals as calculateOrderTotals, index_enrichCategoriesWithAncestors as enrichCategoriesWithAncestors, index_recalculateCoupons as recalculateCoupons, index_toCouponConfigs as toCouponConfigs, index_validateCoupon as validateCoupon };
|
|
1176
1543
|
}
|
|
1177
1544
|
|
|
1178
|
-
export { type AuthField, type CatalogueReconcileAdapter, type CatalogueReconcileEntry, type CollectionSync, CommandWarning, type ConnectorAuth, ConnectorProvider, type ConnectorProviderProps, type ConnectorSchemas, type ConnectorTraits, ConnectorUnauthorizedError, type Customer, type CustomerInput, CustomerServiceError, type CustomerTraits, type ErrorKind, type FingerprintReconcileAdapter, type IdReconcileAdapter, type KeyedReconcileFeedOptions, type Money, type ProductCategory, type ProductPrice, type ProductTraits, type ReconcileFeed, type ReconcileFeedEntry, type ReconcileFetchEntry, type RemoteIdEntry, type ReplicationAdapter, type ResolvedPrice, STOCK_LEVELS_LAST_PASS, type ServerCapabilities, SignInError, type SignInErrorCode, type SignInResult, type StockLevel, type StockReconcileAdapter, type StockStatus, type StoreSettings, type StoreSettingsChoice, type StoreSettingsChoices, StoreSettingsError, type StoreSettingsErrorCode, type SyncContext, type SyncNotice, type TallyConnector, type TaxRounding, type TraitContext, type VariantOptionGroup, type VariantSummary, combinePullAdapters, compareIds, createReconcileFeed, currencySymbol, customerTraits, errorKind, findVariantByCode, formatMoney, getProductStock, isRxdbRemoteVersionMismatch, knownWarnings, minorUnitDigits, moneyFromDecimalString, moneyFromMajor, moneyToMajor, parseInfoCapabilities, parseLineTax, parseTaxRounding, resolveCapabilities, resolvePrice, resolvePriceRange, useConnector, useCustomerTraits, useProductStock, useProductTraits, useStockOverlaid, useStockOverlayAsOf, useTraitContext, withStockOverlay, index as woocommerceTax };
|
|
1545
|
+
export { type AuthField, type CatalogueReconcileAdapter, type CatalogueReconcileEntry, type CollectionSync, CommandWarning, type ConnectorAuth, ConnectorProvider, type ConnectorProviderProps, type ConnectorSchemas, type ConnectorTraits, ConnectorUnauthorizedError, type Customer, type CustomerInput, CustomerServiceError, type CustomerTraits, type ErrorKind, type FingerprintReconcileAdapter, type IdReconcileAdapter, type KeyedReconcileFeedOptions, type Money, type ProductCategory, type ProductPrice, type ProductTraits, type ReconcileFeed, type ReconcileFeedEntry, type ReconcileFetchEntry, type RemoteIdEntry, type ReplicationAdapter, type ResolvedPrice, STOCK_LEVELS_LAST_PASS, type ServerCapabilities, SignInError, type SignInErrorCode, type SignInResult, type StockLevel, type StockReconcileAdapter, type StockStatus, type StoreSettings, type StoreSettingsChoice, type StoreSettingsChoices, StoreSettingsError, type StoreSettingsErrorCode, type SyncContext, type SyncNotice, type TallyConnector, type TaxRounding, type TraitContext, type VariantOptionGroup, type VariantSummary, combinePullAdapters, compareIds, createReconcileFeed, currencySymbol, customerTraits, errorKind, findVariantByCode, formatMoney, getProductStock, isRxdbRemoteVersionMismatch, knownWarnings, minorUnitDigits, moneyFromDecimalString, moneyFromMajor, moneyToMajor, parseInfoCapabilities, parseLineTax, parseTaxRounding, resolveCapabilities, resolvePrice, resolvePriceRange, useConnector, useCustomerTraits, useProductStock, useProductTraits, useStockOverlaid, useStockOverlayAsOf, useTraitContext, withStockOverlay, index as woocommerceCoupons, index$1 as woocommerceTax };
|