@endora-commerce/contracts 0.107.0 → 0.108.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/admin-feedback.d.ts +61 -0
- package/dist/admin-feedback.d.ts.map +1 -0
- package/dist/admin-feedback.js +71 -0
- package/dist/admin-feedback.js.map +1 -0
- package/dist/admin-name.d.ts +21 -0
- package/dist/admin-name.d.ts.map +1 -0
- package/dist/admin-name.js +30 -0
- package/dist/admin-name.js.map +1 -0
- package/dist/carts.d.ts +197 -1
- package/dist/carts.d.ts.map +1 -1
- package/dist/carts.js +29 -0
- package/dist/carts.js.map +1 -1
- package/dist/catalog.d.ts +243 -10
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +107 -4
- package/dist/catalog.js.map +1 -1
- package/dist/common.d.ts +4 -0
- package/dist/common.d.ts.map +1 -1
- package/dist/common.js +14 -0
- package/dist/common.js.map +1 -1
- package/dist/comparisons.d.ts +7 -0
- package/dist/comparisons.d.ts.map +1 -1
- package/dist/comparisons.js +2 -0
- package/dist/comparisons.js.map +1 -1
- package/dist/credit-limits.d.ts.map +1 -1
- package/dist/credit-limits.js +3 -2
- package/dist/credit-limits.js.map +1 -1
- package/dist/crm-rich-text.d.ts +64 -0
- package/dist/crm-rich-text.d.ts.map +1 -0
- package/dist/crm-rich-text.js +303 -0
- package/dist/crm-rich-text.js.map +1 -0
- package/dist/crm.d.ts +91 -1
- package/dist/crm.d.ts.map +1 -1
- package/dist/crm.js +49 -34
- package/dist/crm.js.map +1 -1
- package/dist/custom-fields.d.ts +414 -1
- package/dist/custom-fields.d.ts.map +1 -1
- package/dist/custom-fields.js +319 -10
- package/dist/custom-fields.js.map +1 -1
- package/dist/document-templates.d.ts +184 -8
- package/dist/document-templates.d.ts.map +1 -1
- package/dist/document-templates.js +98 -1
- package/dist/document-templates.js.map +1 -1
- package/dist/document-values.d.ts +4 -1
- package/dist/document-values.d.ts.map +1 -1
- package/dist/document-values.js +18 -6
- package/dist/document-values.js.map +1 -1
- package/dist/errors.d.ts +37 -8
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +66 -8
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -1
- package/dist/invoices.d.ts.map +1 -1
- package/dist/invoices.js +7 -4
- package/dist/invoices.js.map +1 -1
- package/dist/line-groups.d.ts +80 -0
- package/dist/line-groups.d.ts.map +1 -0
- package/dist/line-groups.js +130 -0
- package/dist/line-groups.js.map +1 -0
- package/dist/localized-name.d.ts +20 -0
- package/dist/localized-name.d.ts.map +1 -0
- package/dist/localized-name.js +45 -0
- package/dist/localized-name.js.map +1 -0
- package/dist/money-decimal.d.ts +162 -0
- package/dist/money-decimal.d.ts.map +1 -0
- package/dist/money-decimal.js +365 -0
- package/dist/money-decimal.js.map +1 -0
- package/dist/money-input.d.ts +64 -0
- package/dist/money-input.d.ts.map +1 -0
- package/dist/money-input.js +111 -0
- package/dist/money-input.js.map +1 -0
- package/dist/order-minimums.d.ts +111 -0
- package/dist/order-minimums.d.ts.map +1 -0
- package/dist/order-minimums.js +196 -0
- package/dist/order-minimums.js.map +1 -0
- package/dist/orders.d.ts +181 -2
- package/dist/orders.d.ts.map +1 -1
- package/dist/orders.js +92 -5
- package/dist/orders.js.map +1 -1
- package/dist/payment-methods.d.ts.map +1 -1
- package/dist/payment-methods.js +2 -1
- package/dist/payment-methods.js.map +1 -1
- package/dist/price-book-decimal.d.ts +84 -0
- package/dist/price-book-decimal.d.ts.map +1 -0
- package/dist/price-book-decimal.js +175 -0
- package/dist/price-book-decimal.js.map +1 -0
- package/dist/price-books.d.ts +2206 -0
- package/dist/price-books.d.ts.map +1 -0
- package/dist/price-books.js +777 -0
- package/dist/price-books.js.map +1 -0
- package/dist/price-lists.d.ts +268 -607
- package/dist/price-lists.d.ts.map +1 -1
- package/dist/price-lists.js +92 -455
- package/dist/price-lists.js.map +1 -1
- package/dist/product-feeds.d.ts +89 -8
- package/dist/product-feeds.d.ts.map +1 -1
- package/dist/product-feeds.js +18 -1
- package/dist/product-feeds.js.map +1 -1
- package/dist/product-value-resolver.d.ts +6 -0
- package/dist/product-value-resolver.d.ts.map +1 -1
- package/dist/product-value-resolver.js +6 -1
- package/dist/product-value-resolver.js.map +1 -1
- package/dist/promotions.d.ts +2 -2
- package/dist/promotions.d.ts.map +1 -1
- package/dist/promotions.js +8 -2
- package/dist/promotions.js.map +1 -1
- package/dist/quick-order.d.ts +39 -0
- package/dist/quick-order.d.ts.map +1 -1
- package/dist/quick-order.js +43 -0
- package/dist/quick-order.js.map +1 -1
- package/dist/quote-requests.d.ts +270 -1
- package/dist/quote-requests.d.ts.map +1 -1
- package/dist/quote-requests.js +150 -6
- package/dist/quote-requests.js.map +1 -1
- package/dist/returns.d.ts +55 -2
- package/dist/returns.d.ts.map +1 -1
- package/dist/returns.js +39 -4
- package/dist/returns.js.map +1 -1
- package/dist/sales-channels.d.ts +2 -0
- package/dist/sales-channels.d.ts.map +1 -1
- package/dist/sales-channels.js +2 -0
- package/dist/sales-channels.js.map +1 -1
- package/dist/search.d.ts +60 -0
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +4 -0
- package/dist/search.js.map +1 -1
- package/dist/shipping-methods.d.ts.map +1 -1
- package/dist/shipping-methods.js +2 -1
- package/dist/shipping-methods.js.map +1 -1
- package/dist/shopping-lists.d.ts +24 -0
- package/dist/shopping-lists.d.ts.map +1 -1
- package/dist/shopping-lists.js +20 -1
- package/dist/shopping-lists.js.map +1 -1
- package/dist/storefront-value-overrides.d.ts +67 -0
- package/dist/storefront-value-overrides.d.ts.map +1 -0
- package/dist/storefront-value-overrides.js +93 -0
- package/dist/storefront-value-overrides.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Feature 155 (FR-001, FR-002, FR-006a, FR-028, FR-037; research R6, R6.1, R9, R10) — the
|
|
3
|
+
* one implementation of the minimum-order rule: a pieces minimum per product and a
|
|
4
|
+
* minimum number of units per packaging unit.
|
|
5
|
+
*
|
|
6
|
+
* Pure, synchronous and I/O-free. Consumers (`carts`, `orders`, `quote_requests`,
|
|
7
|
+
* `quick_order`) fetch the records through the ports they already resolve and call
|
|
8
|
+
* {@link evaluateOrderMinimums}; none of them re-implements the rule.
|
|
9
|
+
*
|
|
10
|
+
* This file imports nothing: `catalog.ts` bounds its request schemas with
|
|
11
|
+
* {@link ORDER_MINIMUM_MAX}, so an import back into it would be a cycle evaluated at load.
|
|
12
|
+
*/
|
|
13
|
+
/** Feature 155 (FR-001, FR-002) — the upper bound of both minimums. */
|
|
14
|
+
export declare const ORDER_MINIMUM_MAX = 1000000;
|
|
15
|
+
/** Integer in 1…{@link ORDER_MINIMUM_MAX}. `null` (clear) is the caller's to allow. */
|
|
16
|
+
export declare function isValidOrderMinimum(value: number): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Whether a product of `type` may carry a pieces minimum (D5) — the one predicate the
|
|
19
|
+
* catalogue write path, the storefront projections and the rule below share.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isOrderMinimumEligibleType(type: string): boolean;
|
|
22
|
+
/** One line as the rule sees it. `quantity` is always base pieces. */
|
|
23
|
+
export interface OrderMinimumLine {
|
|
24
|
+
/** Caller's identity for the line: a cart item id, a request line index, a row number. */
|
|
25
|
+
key: string;
|
|
26
|
+
productId: string;
|
|
27
|
+
quantity: number;
|
|
28
|
+
packagingUnitId: string | null;
|
|
29
|
+
/** The line's own base-quantity snapshot; `null` = use the unit's current value. */
|
|
30
|
+
packagingUnitBaseQuantity: number | null;
|
|
31
|
+
/** Counted toward totals, never itself refused (FR-028, FR-031 (b)). */
|
|
32
|
+
exempt: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** The fields of a product record the rule reads. */
|
|
35
|
+
export interface OrderMinimumProduct {
|
|
36
|
+
id: string;
|
|
37
|
+
/** The product type; minimums apply to `simple` and `configurable` only. */
|
|
38
|
+
type: string;
|
|
39
|
+
/** Pieces minimum; `null` or `≤ 1` = none. */
|
|
40
|
+
minOrderQuantity: number | null;
|
|
41
|
+
}
|
|
42
|
+
/** The fields of a packaging-unit record the rule reads. */
|
|
43
|
+
export interface OrderMinimumPackagingUnit {
|
|
44
|
+
id: string;
|
|
45
|
+
productId: string;
|
|
46
|
+
name: string;
|
|
47
|
+
baseQuantity: number;
|
|
48
|
+
/** Minimum units of this unit per order of the product; `null` = none. */
|
|
49
|
+
minOrderUnits: number | null;
|
|
50
|
+
}
|
|
51
|
+
export interface OrderMinimumRules {
|
|
52
|
+
/** Records of the lines' products. A line whose product is absent here is `product_unavailable`. */
|
|
53
|
+
products: ReadonlyArray<OrderMinimumProduct>;
|
|
54
|
+
packagingUnits: ReadonlyArray<OrderMinimumPackagingUnit>;
|
|
55
|
+
}
|
|
56
|
+
export type OrderMinimumViolation =
|
|
57
|
+
/** FR-037 — no record for the product: fail-closed, reported as an unknown product. */
|
|
58
|
+
{
|
|
59
|
+
key: string;
|
|
60
|
+
productId: string;
|
|
61
|
+
kind: 'product_unavailable';
|
|
62
|
+
} | {
|
|
63
|
+
key: string;
|
|
64
|
+
productId: string;
|
|
65
|
+
kind: 'pieces';
|
|
66
|
+
minimum: number;
|
|
67
|
+
total: number;
|
|
68
|
+
} | {
|
|
69
|
+
key: string;
|
|
70
|
+
productId: string;
|
|
71
|
+
kind: 'packaging_unit';
|
|
72
|
+
packagingUnitId: string;
|
|
73
|
+
packagingUnitName: string;
|
|
74
|
+
minimum: number;
|
|
75
|
+
/** Real number: 96 pieces on a 64-piece unit = 1.5. */
|
|
76
|
+
units: number;
|
|
77
|
+
};
|
|
78
|
+
/** A violation of an actual minimum — what {@link minimumRefusal} accepts. */
|
|
79
|
+
export type OrderMinimumBelowViolation = Exclude<OrderMinimumViolation, {
|
|
80
|
+
kind: 'product_unavailable';
|
|
81
|
+
}>;
|
|
82
|
+
/**
|
|
83
|
+
* Pure, O(lines + products + units). Violations in input-line order; for one line,
|
|
84
|
+
* `product_unavailable` alone, else `pieces` before `packaging_unit`.
|
|
85
|
+
*
|
|
86
|
+
* - A line whose product has no record → `product_unavailable`, counted toward nothing.
|
|
87
|
+
* - Minimums apply to `simple` / `configurable` products only; `minOrderQuantity ≤ 1` and
|
|
88
|
+
* `minOrderUnits = null` are "no rule".
|
|
89
|
+
* - Pieces: the product's total over every line (all variants, exempt lines included); below
|
|
90
|
+
* the minimum, every non-exempt line of the product is flagged.
|
|
91
|
+
* - Packaging unit: for a line naming a current unit of its own product, the units over the
|
|
92
|
+
* product's lines in that unit (each line by its own base-quantity snapshot, else the unit's
|
|
93
|
+
* current value); below the minimum, every non-exempt line in that unit is flagged. A unit
|
|
94
|
+
* that no longer exists (or belongs to another product) gives no unit rule.
|
|
95
|
+
*/
|
|
96
|
+
export declare function evaluateOrderMinimums(lines: readonly OrderMinimumLine[], rules: OrderMinimumRules): OrderMinimumViolation[];
|
|
97
|
+
/**
|
|
98
|
+
* Builds the refusal for a single- or multi-line case (R10) from **minimum** violations
|
|
99
|
+
* (`product_unavailable` is the caller's 404, never passed here): the first violation's code; its
|
|
100
|
+
* `productName`, `minimum` and `packagingUnitName` at the top level of `details` (what the bundle
|
|
101
|
+
* sentence interpolates — SC-004); every violation in `details.lines`, each with its `productName`
|
|
102
|
+
* and the caller's key under `keyName` (`cartItemId`, or `index` as a number). Names are resolved
|
|
103
|
+
* by the caller in the request's language; `message` is the English fallback the envelope
|
|
104
|
+
* replaces with the translated bundle sentence. Returns `null` for no violations.
|
|
105
|
+
*/
|
|
106
|
+
export declare function minimumRefusal(violations: readonly OrderMinimumBelowViolation[], productNameById: ReadonlyMap<string, string>, keyName: 'cartItemId' | 'index'): {
|
|
107
|
+
code: 'PRODUCT_BELOW_MINIMUM_QUANTITY' | 'PACKAGING_UNIT_BELOW_MINIMUM_QUANTITY';
|
|
108
|
+
message: string;
|
|
109
|
+
details: Record<string, unknown>;
|
|
110
|
+
} | null;
|
|
111
|
+
//# sourceMappingURL=order-minimums.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-minimums.d.ts","sourceRoot":"","sources":["../src/order-minimums.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,uEAAuE;AACvE,eAAO,MAAM,iBAAiB,UAAY,CAAC;AAE3C,uFAAuF;AACvF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE1D;AAKD;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED,sEAAsE;AACtE,MAAM,WAAW,gBAAgB;IAC/B,0FAA0F;IAC1F,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,oFAAoF;IACpF,yBAAyB,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,wEAAwE;IACxE,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,qDAAqD;AACrD,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,4EAA4E;IAC5E,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAED,4DAA4D;AAC5D,MAAM,WAAW,yBAAyB;IACxC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,0EAA0E;IAC1E,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAChC,oGAAoG;IACpG,QAAQ,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAC;IAC7C,cAAc,EAAE,aAAa,CAAC,yBAAyB,CAAC,C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+
* Feature 155 (FR-001, FR-002, FR-006a, FR-028, FR-037; research R6, R6.1, R9, R10) — the
|
|
3
|
+
* one implementation of the minimum-order rule: a pieces minimum per product and a
|
|
4
|
+
* minimum number of units per packaging unit.
|
|
5
|
+
*
|
|
6
|
+
* Pure, synchronous and I/O-free. Consumers (`carts`, `orders`, `quote_requests`,
|
|
7
|
+
* `quick_order`) fetch the records through the ports they already resolve and call
|
|
8
|
+
* {@link evaluateOrderMinimums}; none of them re-implements the rule.
|
|
9
|
+
*
|
|
10
|
+
* This file imports nothing: `catalog.ts` bounds its request schemas with
|
|
11
|
+
* {@link ORDER_MINIMUM_MAX}, so an import back into it would be a cycle evaluated at load.
|
|
12
|
+
*/
|
|
13
|
+
/** Feature 155 (FR-001, FR-002) — the upper bound of both minimums. */
|
|
14
|
+
export const ORDER_MINIMUM_MAX = 1_000_000;
|
|
15
|
+
/** Integer in 1…{@link ORDER_MINIMUM_MAX}. `null` (clear) is the caller's to allow. */
|
|
16
|
+
export function isValidOrderMinimum(value) {
|
|
17
|
+
return Number.isInteger(value) && value >= 1 && value <= ORDER_MINIMUM_MAX;
|
|
18
|
+
}
|
|
19
|
+
/** Product types the minimums apply to (spec edge case *Product types*). */
|
|
20
|
+
const ELIGIBLE_PRODUCT_TYPES = new Set(['simple', 'configurable']);
|
|
21
|
+
/**
|
|
22
|
+
* Whether a product of `type` may carry a pieces minimum (D5) — the one predicate the
|
|
23
|
+
* catalogue write path, the storefront projections and the rule below share.
|
|
24
|
+
*/
|
|
25
|
+
export function isOrderMinimumEligibleType(type) {
|
|
26
|
+
return ELIGIBLE_PRODUCT_TYPES.has(type);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Pure, O(lines + products + units). Violations in input-line order; for one line,
|
|
30
|
+
* `product_unavailable` alone, else `pieces` before `packaging_unit`.
|
|
31
|
+
*
|
|
32
|
+
* - A line whose product has no record → `product_unavailable`, counted toward nothing.
|
|
33
|
+
* - Minimums apply to `simple` / `configurable` products only; `minOrderQuantity ≤ 1` and
|
|
34
|
+
* `minOrderUnits = null` are "no rule".
|
|
35
|
+
* - Pieces: the product's total over every line (all variants, exempt lines included); below
|
|
36
|
+
* the minimum, every non-exempt line of the product is flagged.
|
|
37
|
+
* - Packaging unit: for a line naming a current unit of its own product, the units over the
|
|
38
|
+
* product's lines in that unit (each line by its own base-quantity snapshot, else the unit's
|
|
39
|
+
* current value); below the minimum, every non-exempt line in that unit is flagged. A unit
|
|
40
|
+
* that no longer exists (or belongs to another product) gives no unit rule.
|
|
41
|
+
*/
|
|
42
|
+
export function evaluateOrderMinimums(lines, rules) {
|
|
43
|
+
// Pass 1 — index the records.
|
|
44
|
+
const productsById = new Map();
|
|
45
|
+
for (const product of rules.products)
|
|
46
|
+
productsById.set(product.id, product);
|
|
47
|
+
const unitsById = new Map();
|
|
48
|
+
for (const unit of rules.packagingUnits)
|
|
49
|
+
unitsById.set(unit.id, unit);
|
|
50
|
+
// The unit rule that applies to a line, or `null`.
|
|
51
|
+
const unitOf = (line) => {
|
|
52
|
+
if (line.packagingUnitId === null)
|
|
53
|
+
return null;
|
|
54
|
+
const unit = unitsById.get(line.packagingUnitId);
|
|
55
|
+
return unit !== undefined && unit.productId === line.productId ? unit : null;
|
|
56
|
+
};
|
|
57
|
+
// Pass 2 — accumulate per-product pieces and per-(product, unit) units.
|
|
58
|
+
// Units are summed as exact fractions (D2): `7/10 + 1/10 + 1/10 + 1/10` is one
|
|
59
|
+
// unit, where the floating-point sum is 0.9999999999999999 and would refuse it.
|
|
60
|
+
const piecesByProduct = new Map();
|
|
61
|
+
const unitsByProductUnit = new Map();
|
|
62
|
+
for (const line of lines) {
|
|
63
|
+
if (!productsById.has(line.productId))
|
|
64
|
+
continue;
|
|
65
|
+
piecesByProduct.set(line.productId, (piecesByProduct.get(line.productId) ?? 0) + line.quantity);
|
|
66
|
+
const unit = unitOf(line);
|
|
67
|
+
if (unit === null)
|
|
68
|
+
continue;
|
|
69
|
+
const baseQuantity = line.packagingUnitBaseQuantity ?? unit.baseQuantity;
|
|
70
|
+
const unitKey = productUnitKey(line.productId, unit.id);
|
|
71
|
+
unitsByProductUnit.set(unitKey, addFractions(unitsByProductUnit.get(unitKey) ?? ZERO_FRACTION, fractionOf(line.quantity, baseQuantity)));
|
|
72
|
+
}
|
|
73
|
+
// Pass 3 — emit, in input order.
|
|
74
|
+
const violations = [];
|
|
75
|
+
for (const line of lines) {
|
|
76
|
+
const product = productsById.get(line.productId);
|
|
77
|
+
if (product === undefined) {
|
|
78
|
+
violations.push({ key: line.key, productId: line.productId, kind: 'product_unavailable' });
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (line.exempt || !isOrderMinimumEligibleType(product.type))
|
|
82
|
+
continue;
|
|
83
|
+
const minimum = product.minOrderQuantity;
|
|
84
|
+
if (minimum !== null && minimum > 1) {
|
|
85
|
+
const total = piecesByProduct.get(product.id) ?? 0;
|
|
86
|
+
if (total < minimum) {
|
|
87
|
+
violations.push({ key: line.key, productId: product.id, kind: 'pieces', minimum, total });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const unit = unitOf(line);
|
|
91
|
+
if (unit !== null && unit.minOrderUnits !== null) {
|
|
92
|
+
const units = unitsByProductUnit.get(productUnitKey(product.id, unit.id)) ?? ZERO_FRACTION;
|
|
93
|
+
if (fractionBelow(units, unit.minOrderUnits)) {
|
|
94
|
+
violations.push({
|
|
95
|
+
key: line.key,
|
|
96
|
+
productId: product.id,
|
|
97
|
+
kind: 'packaging_unit',
|
|
98
|
+
packagingUnitId: unit.id,
|
|
99
|
+
packagingUnitName: unit.name,
|
|
100
|
+
minimum: unit.minOrderUnits,
|
|
101
|
+
units: fractionValue(units),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return violations;
|
|
107
|
+
}
|
|
108
|
+
function productUnitKey(productId, unitId) {
|
|
109
|
+
return `${productId}\u0000${unitId}`;
|
|
110
|
+
}
|
|
111
|
+
const ZERO_FRACTION = { numerator: 0n, denominator: 1n };
|
|
112
|
+
function gcd(a, b) {
|
|
113
|
+
let x = a < 0n ? -a : a;
|
|
114
|
+
let y = b < 0n ? -b : b;
|
|
115
|
+
while (y !== 0n)
|
|
116
|
+
[x, y] = [y, x % y];
|
|
117
|
+
return x;
|
|
118
|
+
}
|
|
119
|
+
function reduce(numerator, denominator) {
|
|
120
|
+
const divisor = gcd(numerator, denominator) || 1n;
|
|
121
|
+
return { numerator: numerator / divisor, denominator: denominator / divisor };
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* `quantity / baseQuantity` as a fraction. Both are integers by contract (pieces and
|
|
125
|
+
* a unit's pieces); a non-integer is scaled to an integer ratio rather than refused,
|
|
126
|
+
* so a malformed snapshot is judged, never thrown.
|
|
127
|
+
*/
|
|
128
|
+
function fractionOf(quantity, baseQuantity) {
|
|
129
|
+
if (Number.isInteger(quantity) && Number.isInteger(baseQuantity) && baseQuantity > 0) {
|
|
130
|
+
return reduce(BigInt(quantity), BigInt(baseQuantity));
|
|
131
|
+
}
|
|
132
|
+
const scale = 1_000_000;
|
|
133
|
+
return reduce(BigInt(Math.round(quantity * scale)), BigInt(Math.max(1, Math.round(baseQuantity * scale))));
|
|
134
|
+
}
|
|
135
|
+
function addFractions(a, b) {
|
|
136
|
+
return reduce(a.numerator * b.denominator + b.numerator * a.denominator, a.denominator * b.denominator);
|
|
137
|
+
}
|
|
138
|
+
/** `value < minimum`, compared exactly. */
|
|
139
|
+
function fractionBelow(value, minimum) {
|
|
140
|
+
return value.numerator < BigInt(minimum) * value.denominator;
|
|
141
|
+
}
|
|
142
|
+
/** The fraction as the real number the violation reports (`units`). */
|
|
143
|
+
function fractionValue(value) {
|
|
144
|
+
return Number(value.numerator) / Number(value.denominator);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Builds the refusal for a single- or multi-line case (R10) from **minimum** violations
|
|
148
|
+
* (`product_unavailable` is the caller's 404, never passed here): the first violation's code; its
|
|
149
|
+
* `productName`, `minimum` and `packagingUnitName` at the top level of `details` (what the bundle
|
|
150
|
+
* sentence interpolates — SC-004); every violation in `details.lines`, each with its `productName`
|
|
151
|
+
* and the caller's key under `keyName` (`cartItemId`, or `index` as a number). Names are resolved
|
|
152
|
+
* by the caller in the request's language; `message` is the English fallback the envelope
|
|
153
|
+
* replaces with the translated bundle sentence. Returns `null` for no violations.
|
|
154
|
+
*/
|
|
155
|
+
export function minimumRefusal(violations, productNameById, keyName) {
|
|
156
|
+
const first = violations[0];
|
|
157
|
+
if (first === undefined)
|
|
158
|
+
return null;
|
|
159
|
+
const nameOf = (productId) => productNameById.get(productId) ?? productId;
|
|
160
|
+
const lines = violations.map((v) => ({
|
|
161
|
+
[keyName]: keyName === 'index' ? Number(v.key) : v.key,
|
|
162
|
+
productId: v.productId,
|
|
163
|
+
productName: nameOf(v.productId),
|
|
164
|
+
kind: v.kind,
|
|
165
|
+
minimum: v.minimum,
|
|
166
|
+
...(v.kind === 'packaging_unit' ? { packagingUnitName: v.packagingUnitName } : {}),
|
|
167
|
+
}));
|
|
168
|
+
const productName = nameOf(first.productId);
|
|
169
|
+
if (first.kind === 'pieces') {
|
|
170
|
+
return {
|
|
171
|
+
code: 'PRODUCT_BELOW_MINIMUM_QUANTITY',
|
|
172
|
+
message: `"${productName}" has a minimum order quantity of ${first.minimum} pcs.`,
|
|
173
|
+
details: {
|
|
174
|
+
productId: first.productId,
|
|
175
|
+
productName,
|
|
176
|
+
minimum: first.minimum,
|
|
177
|
+
total: first.total,
|
|
178
|
+
lines,
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
code: 'PACKAGING_UNIT_BELOW_MINIMUM_QUANTITY',
|
|
184
|
+
message: `"${productName}" must be ordered in at least ${first.minimum} × ${first.packagingUnitName}.`,
|
|
185
|
+
details: {
|
|
186
|
+
productId: first.productId,
|
|
187
|
+
productName,
|
|
188
|
+
packagingUnitId: first.packagingUnitId,
|
|
189
|
+
packagingUnitName: first.packagingUnitName,
|
|
190
|
+
minimum: first.minimum,
|
|
191
|
+
units: first.units,
|
|
192
|
+
lines,
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=order-minimums.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-minimums.js","sourceRoot":"","sources":["../src/order-minimums.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,uEAAuE;AACvE,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAE3C,uFAAuF;AACvF,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,iBAAiB,CAAC;AAC7E,CAAC;AAED,4EAA4E;AAC5E,MAAM,sBAAsB,GAAwB,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC;AAExF;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CAAC,IAAY;IACrD,OAAO,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC1C,CAAC;AA0DD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,qBAAqB,CACnC,KAAkC,EAClC,KAAwB;IAExB,8BAA8B;IAC9B,MAAM,YAAY,GAAG,IAAI,GAAG,EAA+B,CAAC;IAC5D,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,QAAQ;QAAE,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAC5E,MAAM,SAAS,GAAG,IAAI,GAAG,EAAqC,CAAC;IAC/D,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,cAAc;QAAE,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAEtE,mDA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CAAC,OAAO,MAAM,KAAK,CAAC,iBAAiB,GAAG;QACtG,OAAO,EAAE;YACP,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,WAAW;YACX,eAAe,EAAE,KAAK,CAAC,eAAe;YACtC,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;YAC1C,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,KAAK;SACN;KACF,CAAC;AACJ,CAAC"}
|
package/dist/orders.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export declare const orderItemSchema: z.ZodObject<{
|
|
|
28
28
|
unitPrice: z.ZodNumber;
|
|
29
29
|
taxRate: z.ZodNumber;
|
|
30
30
|
lineTotal: z.ZodNumber;
|
|
31
|
+
groupId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
32
|
+
position: z.ZodDefault<z.ZodNumber>;
|
|
31
33
|
}, z.core.$strip>;
|
|
32
34
|
export type OrderItem = z.infer<typeof orderItemSchema>;
|
|
33
35
|
export declare const nextActionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
@@ -134,6 +136,11 @@ export declare const orderSchema: z.ZodObject<{
|
|
|
134
136
|
}>;
|
|
135
137
|
}, z.core.$strip>;
|
|
136
138
|
sourceQuoteRequestId: z.ZodNullable<z.ZodString>;
|
|
139
|
+
itemGroups: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
140
|
+
id: z.ZodString;
|
|
141
|
+
name: z.ZodString;
|
|
142
|
+
position: z.ZodNumber;
|
|
143
|
+
}, z.core.$strip>>>;
|
|
137
144
|
items: z.ZodArray<z.ZodObject<{
|
|
138
145
|
id: z.ZodString;
|
|
139
146
|
productId: z.ZodString;
|
|
@@ -151,6 +158,8 @@ export declare const orderSchema: z.ZodObject<{
|
|
|
151
158
|
unitPrice: z.ZodNumber;
|
|
152
159
|
taxRate: z.ZodNumber;
|
|
153
160
|
lineTotal: z.ZodNumber;
|
|
161
|
+
groupId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
162
|
+
position: z.ZodDefault<z.ZodNumber>;
|
|
154
163
|
}, z.core.$strip>>;
|
|
155
164
|
subtotal: z.ZodNumber;
|
|
156
165
|
taxTotal: z.ZodNumber;
|
|
@@ -268,6 +277,11 @@ export declare const adminOrderDetailSchema: z.ZodObject<{
|
|
|
268
277
|
}>;
|
|
269
278
|
}, z.core.$strip>;
|
|
270
279
|
sourceQuoteRequestId: z.ZodNullable<z.ZodString>;
|
|
280
|
+
itemGroups: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
281
|
+
id: z.ZodString;
|
|
282
|
+
name: z.ZodString;
|
|
283
|
+
position: z.ZodNumber;
|
|
284
|
+
}, z.core.$strip>>>;
|
|
271
285
|
items: z.ZodArray<z.ZodObject<{
|
|
272
286
|
id: z.ZodString;
|
|
273
287
|
productId: z.ZodString;
|
|
@@ -285,6 +299,8 @@ export declare const adminOrderDetailSchema: z.ZodObject<{
|
|
|
285
299
|
unitPrice: z.ZodNumber;
|
|
286
300
|
taxRate: z.ZodNumber;
|
|
287
301
|
lineTotal: z.ZodNumber;
|
|
302
|
+
groupId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
303
|
+
position: z.ZodDefault<z.ZodNumber>;
|
|
288
304
|
}, z.core.$strip>>;
|
|
289
305
|
subtotal: z.ZodNumber;
|
|
290
306
|
taxTotal: z.ZodNumber;
|
|
@@ -436,6 +452,18 @@ export declare const orderPreviewTotalResponseSchema: z.ZodObject<{
|
|
|
436
452
|
discountTotal: z.ZodNumber;
|
|
437
453
|
total: z.ZodNumber;
|
|
438
454
|
currency: z.ZodString;
|
|
455
|
+
belowMinimumLines: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
456
|
+
cartItemId: z.ZodString;
|
|
457
|
+
productId: z.ZodString;
|
|
458
|
+
productName: z.ZodOptional<z.ZodString>;
|
|
459
|
+
kind: z.ZodEnum<{
|
|
460
|
+
pieces: "pieces";
|
|
461
|
+
packaging_unit: "packaging_unit";
|
|
462
|
+
product_unavailable: "product_unavailable";
|
|
463
|
+
}>;
|
|
464
|
+
minimum: z.ZodOptional<z.ZodNumber>;
|
|
465
|
+
packagingUnitName: z.ZodOptional<z.ZodString>;
|
|
466
|
+
}, z.core.$strip>>>;
|
|
439
467
|
}, z.core.$strip>;
|
|
440
468
|
export type OrderPreviewTotalResponse = z.infer<typeof orderPreviewTotalResponseSchema>;
|
|
441
469
|
export declare const adminOrderStatusTransitionSchema: z.ZodObject<{
|
|
@@ -559,6 +587,31 @@ export declare const adminOrdersListQuerySchema: z.ZodObject<{
|
|
|
559
587
|
placedTo: z.ZodOptional<z.ZodString>;
|
|
560
588
|
totalMin: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
561
589
|
totalMax: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
590
|
+
customFieldFilters: z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodUnknown, z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
591
|
+
contains: z.ZodOptional<z.ZodString>;
|
|
592
|
+
in: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
593
|
+
is: z.ZodOptional<z.ZodBoolean>;
|
|
594
|
+
min: z.ZodOptional<z.ZodString>;
|
|
595
|
+
max: z.ZodOptional<z.ZodString>;
|
|
596
|
+
from: z.ZodOptional<z.ZodString>;
|
|
597
|
+
to: z.ZodOptional<z.ZodString>;
|
|
598
|
+
}, z.core.$strict>>>]>>, z.ZodTransform<Record<string, {
|
|
599
|
+
contains?: string | undefined;
|
|
600
|
+
in?: string[] | undefined;
|
|
601
|
+
is?: boolean | undefined;
|
|
602
|
+
min?: string | undefined;
|
|
603
|
+
max?: string | undefined;
|
|
604
|
+
from?: string | undefined;
|
|
605
|
+
to?: string | undefined;
|
|
606
|
+
}> | undefined, string | Record<string, {
|
|
607
|
+
contains?: string | undefined;
|
|
608
|
+
in?: string[] | undefined;
|
|
609
|
+
is?: boolean | undefined;
|
|
610
|
+
min?: string | undefined;
|
|
611
|
+
max?: string | undefined;
|
|
612
|
+
from?: string | undefined;
|
|
613
|
+
to?: string | undefined;
|
|
614
|
+
}> | undefined>>;
|
|
562
615
|
sort: z.ZodOptional<z.ZodString>;
|
|
563
616
|
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
564
617
|
pageSize: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
@@ -723,13 +776,37 @@ export declare const adminCreateOrderInlineAddressSchema: z.ZodObject<{
|
|
|
723
776
|
saveToAddressBook: z.ZodBoolean;
|
|
724
777
|
}, z.core.$strip>;
|
|
725
778
|
export type AdminCreateOrderInlineAddress = z.infer<typeof adminCreateOrderInlineAddressSchema>;
|
|
779
|
+
/**
|
|
780
|
+
* Feature 155 (FR-038, research R20) — the most items admin create-order and the admin
|
|
781
|
+
* preview accept. Enforced by the service / handler as its first step (`422
|
|
782
|
+
* VALIDATION_FAILED`, `details: { code: 'too_many_items', maximum }`), deliberately not by
|
|
783
|
+
* a schema `.max()`, which would answer 400.
|
|
784
|
+
*/
|
|
785
|
+
export declare const ADMIN_ORDER_MAX_ITEMS = 200;
|
|
786
|
+
/**
|
|
787
|
+
* Feature 159 — a line of the admin create request: the preview's item plus the
|
|
788
|
+
* `groups[].key` it belongs to (absent or `null` = ungrouped). The preview keeps
|
|
789
|
+
* `adminCreateOrderItemSchema`, so a `groupKey` sent there is stripped.
|
|
790
|
+
*/
|
|
791
|
+
export declare const adminCreateOrderLineSchema: z.ZodObject<{
|
|
792
|
+
productId: z.ZodString;
|
|
793
|
+
variantId: z.ZodOptional<z.ZodString>;
|
|
794
|
+
quantity: z.ZodNumber;
|
|
795
|
+
groupKey: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
796
|
+
}, z.core.$strip>;
|
|
797
|
+
export type AdminCreateOrderLine = z.infer<typeof adminCreateOrderLineSchema>;
|
|
726
798
|
export declare const adminCreateOrderRequestSchema: z.ZodObject<{
|
|
727
799
|
customerAccountId: z.ZodString;
|
|
728
800
|
salesChannelId: z.ZodString;
|
|
801
|
+
groups: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
802
|
+
key: z.ZodString;
|
|
803
|
+
name: z.ZodString;
|
|
804
|
+
}, z.core.$strict>>>;
|
|
729
805
|
items: z.ZodArray<z.ZodObject<{
|
|
730
806
|
productId: z.ZodString;
|
|
731
807
|
variantId: z.ZodOptional<z.ZodString>;
|
|
732
808
|
quantity: z.ZodNumber;
|
|
809
|
+
groupKey: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
733
810
|
}, z.core.$strip>>;
|
|
734
811
|
deliveryMethodId: z.ZodString;
|
|
735
812
|
paymentMethodId: z.ZodString;
|
|
@@ -845,6 +922,7 @@ export declare const adminOrderPreviewLineSchema: z.ZodObject<{
|
|
|
845
922
|
unitPrice: z.ZodString;
|
|
846
923
|
currency: z.ZodString;
|
|
847
924
|
lineTotal: z.ZodNumber;
|
|
925
|
+
taxRate: z.ZodOptional<z.ZodNumber>;
|
|
848
926
|
unavailable: z.ZodOptional<z.ZodBoolean>;
|
|
849
927
|
}, z.core.$strip>;
|
|
850
928
|
/**
|
|
@@ -853,12 +931,14 @@ export declare const adminOrderPreviewLineSchema: z.ZodObject<{
|
|
|
853
931
|
* `isProductVisibleTo` (catalog.ts) for why the two visibility/assortment codes are distinct here
|
|
854
932
|
* and one answer on every buyer-facing seam.
|
|
855
933
|
*/
|
|
856
|
-
export declare const ADMIN_ORDER_PREVIEW_MESSAGE_PRECEDENCE: readonly ["PRODUCT_NOT_FOUND", "PRODUCT_NOT_VISIBLE_TO_CUSTOMER", "PRODUCT_NOT_IN_SALES_CHANNEL", "QUOTE_ONLY"];
|
|
934
|
+
export declare const ADMIN_ORDER_PREVIEW_MESSAGE_PRECEDENCE: readonly ["PRODUCT_NOT_FOUND", "PRODUCT_NOT_VISIBLE_TO_CUSTOMER", "PRODUCT_NOT_IN_SALES_CHANNEL", "QUOTE_ONLY", "UNPRICED", "BELOW_MINIMUM_QUANTITY"];
|
|
857
935
|
export declare const adminOrderPreviewMessageCodeSchema: z.ZodEnum<{
|
|
858
936
|
PRODUCT_NOT_FOUND: "PRODUCT_NOT_FOUND";
|
|
859
937
|
PRODUCT_NOT_VISIBLE_TO_CUSTOMER: "PRODUCT_NOT_VISIBLE_TO_CUSTOMER";
|
|
860
938
|
PRODUCT_NOT_IN_SALES_CHANNEL: "PRODUCT_NOT_IN_SALES_CHANNEL";
|
|
861
939
|
QUOTE_ONLY: "QUOTE_ONLY";
|
|
940
|
+
UNPRICED: "UNPRICED";
|
|
941
|
+
BELOW_MINIMUM_QUANTITY: "BELOW_MINIMUM_QUANTITY";
|
|
862
942
|
}>;
|
|
863
943
|
export type AdminOrderPreviewMessageCode = z.infer<typeof adminOrderPreviewMessageCodeSchema>;
|
|
864
944
|
export declare const adminOrderPreviewResponseSchema: z.ZodObject<{
|
|
@@ -869,6 +949,7 @@ export declare const adminOrderPreviewResponseSchema: z.ZodObject<{
|
|
|
869
949
|
unitPrice: z.ZodString;
|
|
870
950
|
currency: z.ZodString;
|
|
871
951
|
lineTotal: z.ZodNumber;
|
|
952
|
+
taxRate: z.ZodOptional<z.ZodNumber>;
|
|
872
953
|
unavailable: z.ZodOptional<z.ZodBoolean>;
|
|
873
954
|
}, z.core.$strip>>;
|
|
874
955
|
summary: z.ZodObject<{
|
|
@@ -883,9 +964,42 @@ export declare const adminOrderPreviewResponseSchema: z.ZodObject<{
|
|
|
883
964
|
messages: z.ZodArray<z.ZodObject<{
|
|
884
965
|
productId: z.ZodString;
|
|
885
966
|
code: z.ZodString;
|
|
967
|
+
minimum: z.ZodOptional<z.ZodNumber>;
|
|
886
968
|
}, z.core.$strip>>;
|
|
887
969
|
}, z.core.$strip>;
|
|
888
970
|
export type AdminOrderPreviewResponse = z.infer<typeof adminOrderPreviewResponseSchema>;
|
|
971
|
+
/**
|
|
972
|
+
* Feature 162 — an author-less **system note** the platform writes into an
|
|
973
|
+
* Order's comments: custom-field values that could not be carried into the
|
|
974
|
+
* Order from the record it was created from. Internal, never notifying, and
|
|
975
|
+
* never listed to the buyer. The comment's `body` is an English fallback; a
|
|
976
|
+
* reader renders the note in its own language from this shape.
|
|
977
|
+
*/
|
|
978
|
+
export declare const orderCommentSystemNoteSchema: z.ZodObject<{
|
|
979
|
+
kind: z.ZodLiteral<"custom_field_carry_skipped">;
|
|
980
|
+
source: z.ZodObject<{
|
|
981
|
+
entityType: z.ZodEnum<{
|
|
982
|
+
quote_request: "quote_request";
|
|
983
|
+
opportunity: "opportunity";
|
|
984
|
+
}>;
|
|
985
|
+
recordId: z.ZodString;
|
|
986
|
+
reference: z.ZodString;
|
|
987
|
+
}, z.core.$strip>;
|
|
988
|
+
skipped: z.ZodArray<z.ZodObject<{
|
|
989
|
+
key: z.ZodString;
|
|
990
|
+
reason: z.ZodEnum<{
|
|
991
|
+
target_missing: "target_missing";
|
|
992
|
+
value_type_mismatch: "value_type_mismatch";
|
|
993
|
+
audience_mismatch: "audience_mismatch";
|
|
994
|
+
value_invalid: "value_invalid";
|
|
995
|
+
}>;
|
|
996
|
+
label: z.ZodOptional<z.ZodObject<{
|
|
997
|
+
labelDefault: z.ZodString;
|
|
998
|
+
labels: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
999
|
+
}, z.core.$strip>>;
|
|
1000
|
+
}, z.core.$strip>>;
|
|
1001
|
+
}, z.core.$strip>;
|
|
1002
|
+
export type OrderCommentSystemNote = z.infer<typeof orderCommentSystemNoteSchema>;
|
|
889
1003
|
export declare const orderCommentSchema: z.ZodObject<{
|
|
890
1004
|
id: z.ZodString;
|
|
891
1005
|
orderId: z.ZodString;
|
|
@@ -894,6 +1008,30 @@ export declare const orderCommentSchema: z.ZodObject<{
|
|
|
894
1008
|
body: z.ZodString;
|
|
895
1009
|
isCustomerVisible: z.ZodBoolean;
|
|
896
1010
|
notifyCustomer: z.ZodBoolean;
|
|
1011
|
+
systemNote: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
1012
|
+
kind: z.ZodLiteral<"custom_field_carry_skipped">;
|
|
1013
|
+
source: z.ZodObject<{
|
|
1014
|
+
entityType: z.ZodEnum<{
|
|
1015
|
+
quote_request: "quote_request";
|
|
1016
|
+
opportunity: "opportunity";
|
|
1017
|
+
}>;
|
|
1018
|
+
recordId: z.ZodString;
|
|
1019
|
+
reference: z.ZodString;
|
|
1020
|
+
}, z.core.$strip>;
|
|
1021
|
+
skipped: z.ZodArray<z.ZodObject<{
|
|
1022
|
+
key: z.ZodString;
|
|
1023
|
+
reason: z.ZodEnum<{
|
|
1024
|
+
target_missing: "target_missing";
|
|
1025
|
+
value_type_mismatch: "value_type_mismatch";
|
|
1026
|
+
audience_mismatch: "audience_mismatch";
|
|
1027
|
+
value_invalid: "value_invalid";
|
|
1028
|
+
}>;
|
|
1029
|
+
label: z.ZodOptional<z.ZodObject<{
|
|
1030
|
+
labelDefault: z.ZodString;
|
|
1031
|
+
labels: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
1032
|
+
}, z.core.$strip>>;
|
|
1033
|
+
}, z.core.$strip>>;
|
|
1034
|
+
}, z.core.$strip>>>;
|
|
897
1035
|
createdAt: z.ZodString;
|
|
898
1036
|
}, z.core.$strip>;
|
|
899
1037
|
export type OrderComment = z.infer<typeof orderCommentSchema>;
|
|
@@ -1298,7 +1436,48 @@ export interface PlacedOrderRecord extends OrderRecord {
|
|
|
1298
1436
|
* `nonDeactivatable` never enters one.
|
|
1299
1437
|
*/
|
|
1300
1438
|
export interface OrderPlacementPort {
|
|
1301
|
-
|
|
1439
|
+
/**
|
|
1440
|
+
* `options.language` (feature 155, D3/D4) — the language the caller's response
|
|
1441
|
+
* is answered in, which a minimum refusal names the product in. Absent, the
|
|
1442
|
+
* record's own fallback chain.
|
|
1443
|
+
*/
|
|
1444
|
+
placeOrder(ctx: OrderCustomerContext, req: PlaceOrderRequest, options?: {
|
|
1445
|
+
language?: string;
|
|
1446
|
+
}): Promise<PlacedOrderRecord>;
|
|
1447
|
+
}
|
|
1448
|
+
/** One basket line, as the quote-source confirmation reads it. */
|
|
1449
|
+
export interface QuoteSourceBasketLine {
|
|
1450
|
+
productId: string;
|
|
1451
|
+
variantId: string | null;
|
|
1452
|
+
/** The line's stored unit price — compared with the quote's agreed price. */
|
|
1453
|
+
unitPrice: string;
|
|
1454
|
+
}
|
|
1455
|
+
/**
|
|
1456
|
+
* Container name: `orderQuoteSourcePort`. Owner: `orders`.
|
|
1457
|
+
*
|
|
1458
|
+
* Feature 155 (FR-036, FR-039; `contracts/cart-and-checkout-api.md` §12) —
|
|
1459
|
+
* whether a basket's quote-seeded lines keep their exemption from the
|
|
1460
|
+
* catalogue's order minimums, answered by the **checkout preview's** check: the
|
|
1461
|
+
* Quote Request belongs to `organizationId`, is `Approved`, its validity has not
|
|
1462
|
+
* ended, no Order already carries it, and `basketLines` still hold a line agreed
|
|
1463
|
+
* in it. Lock-free and advisory — placement confirms the source again under its
|
|
1464
|
+
* own lock, so nothing a caller grants on this answer is relied on by placement.
|
|
1465
|
+
*
|
|
1466
|
+
* Published for `carts`' submit-for-approval, which must judge a basket as
|
|
1467
|
+
* placement does rather than take the cart's quote mark at face value. The rule
|
|
1468
|
+
* stays in one place: `orders` already owns it and is the only module that can
|
|
1469
|
+
* answer "no Order carries it yet".
|
|
1470
|
+
*
|
|
1471
|
+
* Fail-closed: `false` whenever the source cannot be confirmed, including while
|
|
1472
|
+
* `quote_requests` is off. **Owner off:** resolving the port throws
|
|
1473
|
+
* `ModuleDisabledError` (503), as for every `orders` port.
|
|
1474
|
+
*/
|
|
1475
|
+
export interface OrderQuoteSourcePort {
|
|
1476
|
+
quoteSourceHonoursExemptions(input: {
|
|
1477
|
+
organizationId: string;
|
|
1478
|
+
quoteRequestId: string;
|
|
1479
|
+
basketLines: readonly QuoteSourceBasketLine[];
|
|
1480
|
+
}): Promise<boolean>;
|
|
1302
1481
|
}
|
|
1303
1482
|
export interface OrderStatusActor {
|
|
1304
1483
|
kind: 'admin' | 'customer' | 'system';
|