@endora-commerce/contracts 0.107.0 → 0.109.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.
Files changed (273) hide show
  1. package/dist/admin-actions.d.ts +12 -3
  2. package/dist/admin-actions.d.ts.map +1 -1
  3. package/dist/admin-actions.js +34 -3
  4. package/dist/admin-actions.js.map +1 -1
  5. package/dist/admin-contributions.d.ts +35 -6
  6. package/dist/admin-contributions.d.ts.map +1 -1
  7. package/dist/admin-contributions.js +46 -0
  8. package/dist/admin-contributions.js.map +1 -1
  9. package/dist/admin-feedback.d.ts +61 -0
  10. package/dist/admin-feedback.d.ts.map +1 -0
  11. package/dist/admin-feedback.js +71 -0
  12. package/dist/admin-feedback.js.map +1 -0
  13. package/dist/admin-name.d.ts +21 -0
  14. package/dist/admin-name.d.ts.map +1 -0
  15. package/dist/admin-name.js +30 -0
  16. package/dist/admin-name.js.map +1 -0
  17. package/dist/admin-notifications.d.ts +17 -1
  18. package/dist/admin-notifications.d.ts.map +1 -1
  19. package/dist/admin-preferences.d.ts +108 -0
  20. package/dist/admin-preferences.d.ts.map +1 -0
  21. package/dist/admin-preferences.js +133 -0
  22. package/dist/admin-preferences.js.map +1 -0
  23. package/dist/admin.d.ts +15 -1
  24. package/dist/admin.d.ts.map +1 -1
  25. package/dist/admin.js +7 -0
  26. package/dist/admin.js.map +1 -1
  27. package/dist/assets-library.d.ts +97 -3
  28. package/dist/assets-library.d.ts.map +1 -1
  29. package/dist/assets-library.js +5 -0
  30. package/dist/assets-library.js.map +1 -1
  31. package/dist/blog.d.ts +57 -0
  32. package/dist/blog.d.ts.map +1 -1
  33. package/dist/blog.js +63 -1
  34. package/dist/blog.js.map +1 -1
  35. package/dist/carts.d.ts +303 -50
  36. package/dist/carts.d.ts.map +1 -1
  37. package/dist/carts.js +95 -13
  38. package/dist/carts.js.map +1 -1
  39. package/dist/catalog.d.ts +512 -40
  40. package/dist/catalog.d.ts.map +1 -1
  41. package/dist/catalog.js +362 -23
  42. package/dist/catalog.js.map +1 -1
  43. package/dist/cms-brand.d.ts +2233 -0
  44. package/dist/cms-brand.d.ts.map +1 -0
  45. package/dist/cms-brand.js +311 -0
  46. package/dist/cms-brand.js.map +1 -0
  47. package/dist/cms-contact-form.d.ts +55 -0
  48. package/dist/cms-contact-form.d.ts.map +1 -0
  49. package/dist/cms-contact-form.js +100 -0
  50. package/dist/cms-contact-form.js.map +1 -0
  51. package/dist/cms.d.ts +537 -3
  52. package/dist/cms.d.ts.map +1 -1
  53. package/dist/cms.js +251 -0
  54. package/dist/cms.js.map +1 -1
  55. package/dist/common.d.ts +4 -0
  56. package/dist/common.d.ts.map +1 -1
  57. package/dist/common.js +14 -0
  58. package/dist/common.js.map +1 -1
  59. package/dist/comparisons.d.ts +7 -0
  60. package/dist/comparisons.d.ts.map +1 -1
  61. package/dist/comparisons.js +2 -0
  62. package/dist/comparisons.js.map +1 -1
  63. package/dist/credit-limits.d.ts.map +1 -1
  64. package/dist/credit-limits.js +3 -2
  65. package/dist/credit-limits.js.map +1 -1
  66. package/dist/crm-rich-text.d.ts +13 -0
  67. package/dist/crm-rich-text.d.ts.map +1 -0
  68. package/dist/crm-rich-text.js +13 -0
  69. package/dist/crm-rich-text.js.map +1 -0
  70. package/dist/crm.d.ts +180 -62
  71. package/dist/crm.d.ts.map +1 -1
  72. package/dist/crm.js +63 -107
  73. package/dist/crm.js.map +1 -1
  74. package/dist/custom-fields.d.ts +436 -5
  75. package/dist/custom-fields.d.ts.map +1 -1
  76. package/dist/custom-fields.js +325 -10
  77. package/dist/custom-fields.js.map +1 -1
  78. package/dist/customer-accounts.d.ts +30 -0
  79. package/dist/customer-accounts.d.ts.map +1 -1
  80. package/dist/customer-accounts.js +31 -0
  81. package/dist/customer-accounts.js.map +1 -1
  82. package/dist/document-templates.d.ts +211 -23
  83. package/dist/document-templates.d.ts.map +1 -1
  84. package/dist/document-templates.js +98 -1
  85. package/dist/document-templates.js.map +1 -1
  86. package/dist/document-values.d.ts +12 -1
  87. package/dist/document-values.d.ts.map +1 -1
  88. package/dist/document-values.js +41 -11
  89. package/dist/document-values.js.map +1 -1
  90. package/dist/email.d.ts +5 -0
  91. package/dist/email.d.ts.map +1 -1
  92. package/dist/errors.d.ts +142 -8
  93. package/dist/errors.d.ts.map +1 -1
  94. package/dist/errors.js +189 -8
  95. package/dist/errors.js.map +1 -1
  96. package/dist/index.d.ts +24 -1
  97. package/dist/index.d.ts.map +1 -1
  98. package/dist/index.js +43 -1
  99. package/dist/index.js.map +1 -1
  100. package/dist/inventory.d.ts +3 -3
  101. package/dist/invoices.d.ts +6 -2
  102. package/dist/invoices.d.ts.map +1 -1
  103. package/dist/invoices.js +10 -4
  104. package/dist/invoices.js.map +1 -1
  105. package/dist/line-groups.d.ts +80 -0
  106. package/dist/line-groups.d.ts.map +1 -0
  107. package/dist/line-groups.js +130 -0
  108. package/dist/line-groups.js.map +1 -0
  109. package/dist/localized-name.d.ts +20 -0
  110. package/dist/localized-name.d.ts.map +1 -0
  111. package/dist/localized-name.js +45 -0
  112. package/dist/localized-name.js.map +1 -0
  113. package/dist/megamenu.d.ts +674 -0
  114. package/dist/megamenu.d.ts.map +1 -1
  115. package/dist/megamenu.js +96 -3
  116. package/dist/megamenu.js.map +1 -1
  117. package/dist/mfa.d.ts +1 -0
  118. package/dist/mfa.d.ts.map +1 -1
  119. package/dist/mfa.js +8 -2
  120. package/dist/mfa.js.map +1 -1
  121. package/dist/modules.d.ts +8 -1
  122. package/dist/modules.d.ts.map +1 -1
  123. package/dist/modules.js +5 -0
  124. package/dist/modules.js.map +1 -1
  125. package/dist/money-decimal.d.ts +162 -0
  126. package/dist/money-decimal.d.ts.map +1 -0
  127. package/dist/money-decimal.js +365 -0
  128. package/dist/money-decimal.js.map +1 -0
  129. package/dist/money-input.d.ts +64 -0
  130. package/dist/money-input.d.ts.map +1 -0
  131. package/dist/money-input.js +111 -0
  132. package/dist/money-input.js.map +1 -0
  133. package/dist/newsletter.d.ts +3 -3
  134. package/dist/order-minimums.d.ts +111 -0
  135. package/dist/order-minimums.d.ts.map +1 -0
  136. package/dist/order-minimums.js +196 -0
  137. package/dist/order-minimums.js.map +1 -0
  138. package/dist/orders.d.ts +206 -2
  139. package/dist/orders.d.ts.map +1 -1
  140. package/dist/orders.js +106 -5
  141. package/dist/orders.js.map +1 -1
  142. package/dist/page-builder-props.d.ts +1401 -0
  143. package/dist/page-builder-props.d.ts.map +1 -0
  144. package/dist/page-builder-props.js +266 -0
  145. package/dist/page-builder-props.js.map +1 -0
  146. package/dist/page-builder-values.d.ts +95 -0
  147. package/dist/page-builder-values.d.ts.map +1 -0
  148. package/dist/page-builder-values.js +164 -0
  149. package/dist/page-builder-values.js.map +1 -0
  150. package/dist/payment-methods.d.ts.map +1 -1
  151. package/dist/payment-methods.js +2 -1
  152. package/dist/payment-methods.js.map +1 -1
  153. package/dist/pim-connector.d.ts +1 -1
  154. package/dist/platform-language.d.ts +9 -0
  155. package/dist/platform-language.d.ts.map +1 -1
  156. package/dist/platform-language.js +14 -0
  157. package/dist/platform-language.js.map +1 -1
  158. package/dist/price-book-decimal.d.ts +84 -0
  159. package/dist/price-book-decimal.d.ts.map +1 -0
  160. package/dist/price-book-decimal.js +175 -0
  161. package/dist/price-book-decimal.js.map +1 -0
  162. package/dist/price-books.d.ts +2206 -0
  163. package/dist/price-books.d.ts.map +1 -0
  164. package/dist/price-books.js +777 -0
  165. package/dist/price-books.js.map +1 -0
  166. package/dist/price-lists.d.ts +309 -614
  167. package/dist/price-lists.d.ts.map +1 -1
  168. package/dist/price-lists.js +113 -453
  169. package/dist/price-lists.js.map +1 -1
  170. package/dist/product-feeds.d.ts +195 -54
  171. package/dist/product-feeds.d.ts.map +1 -1
  172. package/dist/product-feeds.js +36 -1
  173. package/dist/product-feeds.js.map +1 -1
  174. package/dist/product-scopes.d.ts +628 -0
  175. package/dist/product-scopes.d.ts.map +1 -0
  176. package/dist/product-scopes.js +365 -0
  177. package/dist/product-scopes.js.map +1 -0
  178. package/dist/product-summary-text.d.ts +23 -0
  179. package/dist/product-summary-text.d.ts.map +1 -0
  180. package/dist/product-summary-text.js +64 -0
  181. package/dist/product-summary-text.js.map +1 -0
  182. package/dist/product-url-keys.d.ts +204 -0
  183. package/dist/product-url-keys.d.ts.map +1 -0
  184. package/dist/product-url-keys.js +166 -0
  185. package/dist/product-url-keys.js.map +1 -0
  186. package/dist/product-value-resolver.d.ts +6 -0
  187. package/dist/product-value-resolver.d.ts.map +1 -1
  188. package/dist/product-value-resolver.js +6 -1
  189. package/dist/product-value-resolver.js.map +1 -1
  190. package/dist/projects.d.ts +2355 -0
  191. package/dist/projects.d.ts.map +1 -0
  192. package/dist/projects.js +837 -0
  193. package/dist/projects.js.map +1 -0
  194. package/dist/promotions.d.ts +2 -2
  195. package/dist/promotions.d.ts.map +1 -1
  196. package/dist/promotions.js +8 -2
  197. package/dist/promotions.js.map +1 -1
  198. package/dist/prompt-actions.d.ts +19 -1
  199. package/dist/prompt-actions.d.ts.map +1 -1
  200. package/dist/prompt-actions.js +31 -2
  201. package/dist/prompt-actions.js.map +1 -1
  202. package/dist/quick-order.d.ts +39 -1
  203. package/dist/quick-order.d.ts.map +1 -1
  204. package/dist/quick-order.js +44 -1
  205. package/dist/quick-order.js.map +1 -1
  206. package/dist/quote-requests.d.ts +305 -1
  207. package/dist/quote-requests.d.ts.map +1 -1
  208. package/dist/quote-requests.js +173 -5
  209. package/dist/quote-requests.js.map +1 -1
  210. package/dist/record-references.d.ts +252 -0
  211. package/dist/record-references.d.ts.map +1 -0
  212. package/dist/record-references.js +179 -0
  213. package/dist/record-references.js.map +1 -0
  214. package/dist/record-rich-text.d.ts +66 -0
  215. package/dist/record-rich-text.d.ts.map +1 -0
  216. package/dist/record-rich-text.js +303 -0
  217. package/dist/record-rich-text.js.map +1 -0
  218. package/dist/returns.d.ts +81 -2
  219. package/dist/returns.d.ts.map +1 -1
  220. package/dist/returns.js +39 -4
  221. package/dist/returns.js.map +1 -1
  222. package/dist/sales-channels.d.ts +53 -7
  223. package/dist/sales-channels.d.ts.map +1 -1
  224. package/dist/sales-channels.js +40 -4
  225. package/dist/sales-channels.js.map +1 -1
  226. package/dist/saved-list-views.d.ts +28 -0
  227. package/dist/saved-list-views.d.ts.map +1 -1
  228. package/dist/saved-list-views.js +14 -1
  229. package/dist/saved-list-views.js.map +1 -1
  230. package/dist/scoped-translations.d.ts +48 -0
  231. package/dist/scoped-translations.d.ts.map +1 -0
  232. package/dist/scoped-translations.js +78 -0
  233. package/dist/scoped-translations.js.map +1 -0
  234. package/dist/search.d.ts +73 -5
  235. package/dist/search.d.ts.map +1 -1
  236. package/dist/search.js +4 -0
  237. package/dist/search.js.map +1 -1
  238. package/dist/seo.d.ts +64 -5
  239. package/dist/seo.d.ts.map +1 -1
  240. package/dist/seo.js +31 -4
  241. package/dist/seo.js.map +1 -1
  242. package/dist/settings.d.ts +32 -3
  243. package/dist/settings.d.ts.map +1 -1
  244. package/dist/settings.js +37 -3
  245. package/dist/settings.js.map +1 -1
  246. package/dist/shipping-methods.d.ts.map +1 -1
  247. package/dist/shipping-methods.js +2 -1
  248. package/dist/shipping-methods.js.map +1 -1
  249. package/dist/shopping-lists.d.ts +24 -0
  250. package/dist/shopping-lists.d.ts.map +1 -1
  251. package/dist/shopping-lists.js +20 -1
  252. package/dist/shopping-lists.js.map +1 -1
  253. package/dist/storefront-cache-tags.d.ts +29 -0
  254. package/dist/storefront-cache-tags.d.ts.map +1 -1
  255. package/dist/storefront-cache-tags.js +24 -0
  256. package/dist/storefront-cache-tags.js.map +1 -1
  257. package/dist/storefront-language-path.d.ts +77 -0
  258. package/dist/storefront-language-path.d.ts.map +1 -0
  259. package/dist/storefront-language-path.js +123 -0
  260. package/dist/storefront-language-path.js.map +1 -0
  261. package/dist/storefront-value-overrides.d.ts +67 -0
  262. package/dist/storefront-value-overrides.d.ts.map +1 -0
  263. package/dist/storefront-value-overrides.js +93 -0
  264. package/dist/storefront-value-overrides.js.map +1 -0
  265. package/dist/tasks.d.ts +2842 -0
  266. package/dist/tasks.d.ts.map +1 -0
  267. package/dist/tasks.js +901 -0
  268. package/dist/tasks.js.map +1 -0
  269. package/dist/transactional-emails.d.ts +7 -4
  270. package/dist/transactional-emails.d.ts.map +1 -1
  271. package/dist/transactional-emails.js +13 -0
  272. package/dist/transactional-emails.js.map +1 -1
  273. package/package.json +2 -2
@@ -0,0 +1,111 @@
1
+ import { decimalText } from './price-book-decimal.js';
2
+ /**
3
+ * A typed money amount has at most two decimal places — owner ruling of
4
+ * 2026-10-24, issue #417. Every money field a person or an integration enters
5
+ * (a delivery cost, a payment surcharge, a refund, a credit limit, a
6
+ * promotion's fixed amount) refuses more with `400 AMOUNT_PRECISION_EXCEEDED`,
7
+ * and nothing rounds it: an amount the platform stores is the amount that was
8
+ * typed. Price-book prices have their own four-place grammar and do not use this.
9
+ *
10
+ * A typed **unit price** — a quote's desired, agreed or proposed price — keeps
11
+ * up to four places (owner ruling of 2026-10-25): a unit price is carried at
12
+ * four places from the price book to the invoice line and only the line value
13
+ * is rounded (`specs/pricing/worked-examples.md` §10.18). It takes
14
+ * {@link fourDecimalUnitPrice}, and more than four places is refused with its
15
+ * own code, `400 UNIT_PRICE_PRECISION_EXCEEDED`, whose sentence says four.
16
+ *
17
+ * The refusal is a Zod issue tagged with the code, so a schema states it once
18
+ * and the error envelope (`@endora-commerce/platform/http`) turns a request
19
+ * whose only failures are this one into the error code.
20
+ */
21
+ export const AMOUNT_PRECISION_EXCEEDED = 'AMOUNT_PRECISION_EXCEEDED';
22
+ /** The refusal of a typed unit price with more than four decimal places (owner ruling of 2026-10-25). */
23
+ export const UNIT_PRICE_PRECISION_EXCEEDED = 'UNIT_PRICE_PRECISION_EXCEEDED';
24
+ const DECIMAL = /^-?\d+(?:\.(\d+))?$/;
25
+ /** Whether a number (read as its shortest decimal) or a decimal string has at most `places` significant decimal places. */
26
+ function hasAtMostDecimals(value, places) {
27
+ if (typeof value === 'number' && !Number.isFinite(value))
28
+ return false;
29
+ const match = DECIMAL.exec(decimalText(value));
30
+ if (!match)
31
+ return false;
32
+ // Trailing zeros are not significant: `123.4500` is 123.45 (review of PR #423).
33
+ return (match[1] ?? '').replace(/0+$/, '').length <= places;
34
+ }
35
+ /** Whether a number (read as its shortest decimal) or a decimal string has at most two decimal places. */
36
+ export function hasAtMostTwoDecimals(value) {
37
+ return hasAtMostDecimals(value, 2);
38
+ }
39
+ /** Whether a number (read as its shortest decimal) or a decimal string has at most four decimal places. */
40
+ export function hasAtMostFourDecimals(value) {
41
+ return hasAtMostDecimals(value, 4);
42
+ }
43
+ /** A fresh object each time: Zod normalises a refinement's params in place. */
44
+ function precisionIssue(code = AMOUNT_PRECISION_EXCEEDED) {
45
+ return { message: code, params: { code } };
46
+ }
47
+ /** A number schema refusing more than two decimal places with the precision issue. */
48
+ export function twoDecimalAmount(schema) {
49
+ return schema.refine((value) => hasAtMostTwoDecimals(value), precisionIssue());
50
+ }
51
+ /**
52
+ * A number schema refusing more than four decimal places with the unit-price
53
+ * precision issue — a typed unit price (owner ruling of 2026-10-25). Trailing
54
+ * zeros are not significant, as for {@link twoDecimalAmount}.
55
+ */
56
+ export function fourDecimalUnitPrice(schema) {
57
+ return schema.refine((value) => hasAtMostFourDecimals(value), precisionIssue(UNIT_PRICE_PRECISION_EXCEEDED));
58
+ }
59
+ /** A plain decimal string: an optional minus, digits, and optionally a point and digits. */
60
+ const DECIMAL_STRING = /^-?\d+(?:\.\d+)?$/;
61
+ function decimalStringRefinement(schema, options, places, code) {
62
+ const pattern = options.pattern ?? DECIMAL_STRING;
63
+ const message = options.message ?? 'Not a decimal amount';
64
+ return schema.superRefine((value, ctx) => {
65
+ if (!pattern.test(value) || !DECIMAL_STRING.test(value)) {
66
+ ctx.addIssue({ code: 'custom', message });
67
+ return;
68
+ }
69
+ if (!hasAtMostDecimals(value, places))
70
+ ctx.addIssue({ code: 'custom', ...precisionIssue(code) });
71
+ });
72
+ }
73
+ /**
74
+ * A decimal-string schema: a string that is not a decimal is refused with a
75
+ * **format** issue (`options.message`, `Not a decimal amount` by default) and
76
+ * nothing else; a decimal with a significant digit beyond the second place is
77
+ * refused with the precision issue. Trailing zeros are not significant
78
+ * (`"123.4500"` is 123.45). `options.pattern` narrows the format (a
79
+ * non-negative amount, a bounded number of digits).
80
+ */
81
+ export function twoDecimalAmountString(schema, options = {}) {
82
+ return decimalStringRefinement(schema, options, 2, AMOUNT_PRECISION_EXCEEDED);
83
+ }
84
+ /**
85
+ * The unit-price sibling of {@link twoDecimalAmountString}: the same grammar
86
+ * and the same trim behaviour (pass `z.string().trim()` to accept surrounding
87
+ * whitespace; trailing zeros are not significant), refusing a significant
88
+ * digit beyond the **fourth** place with the unit-price precision issue.
89
+ */
90
+ export function fourDecimalUnitPriceString(schema, options = {}) {
91
+ return decimalStringRefinement(schema, options, 4, UNIT_PRICE_PRECISION_EXCEEDED);
92
+ }
93
+ /** The precision issue, for a `superRefine` that decides per field (a promotion's value is money only for `amount_off`). */
94
+ export function addAmountPrecisionIssue(ctx, path) {
95
+ ctx.addIssue({ code: 'custom', path, ...precisionIssue() });
96
+ }
97
+ function hasPrecisionCode(issue, code) {
98
+ if (!issue || typeof issue !== 'object')
99
+ return false;
100
+ const params = issue.params;
101
+ return params?.code === code || params?.params?.code === code;
102
+ }
103
+ /** Whether a Zod issue (or a Fastify-wrapped one, whose `params` carry the issue's) is the precision issue. */
104
+ export function isAmountPrecisionIssue(issue) {
105
+ return hasPrecisionCode(issue, AMOUNT_PRECISION_EXCEEDED);
106
+ }
107
+ /** Whether a Zod issue (or a Fastify-wrapped one) is the unit-price precision issue. */
108
+ export function isUnitPricePrecisionIssue(issue) {
109
+ return hasPrecisionCode(issue, UNIT_PRICE_PRECISION_EXCEEDED);
110
+ }
111
+ //# sourceMappingURL=money-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"money-input.js","sourceRoot":"","sources":["../src/money-input.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAA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,OAAO,uBAAuB,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,6BAA6B,CAAC,CAAC;AACpF,CAAC;AAED,4HAA4H;AAC5H,MAAM,UAAU,uBAAuB,CAAC,GAAoB,EAAE,IAAmB;IAC/E,GAAG,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,cAAc,EAAE,EAAE,CAAC,CAAC;AAC9D,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc,EAAE,IAAmB;IAC3D,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,MAAM,GAAI,KAAsE,CAAC,MAAM,CAAC;IAC9F,OAAO,MAAM,EAAE,IAAI,KAAK,IAAI,IAAI,MAAM,EAAE,MAAM,EAAE,IAAI,KAAK,IAAI,CAAC;AAChE,CAAC;AAED,+GAA+G;AAC/G,MAAM,UAAU,sBAAsB,CAAC,KAAc;IACnD,OAAO,gBAAgB,CAAC,KAAK,EAAE,yBAAyB,CAAC,CAAC;AAC5D,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,yBAAyB,CAAC,KAAc;IACtD,OAAO,gBAAgB,CAAC,KAAK,EAAE,6BAA6B,CAAC,CAAC;AAChE,CAAC"}
@@ -40,8 +40,8 @@ export declare const campaignStatusSchema: z.ZodEnum<{
40
40
  }>;
41
41
  export type CampaignStatus = z.infer<typeof campaignStatusSchema>;
42
42
  export declare const automationStatusSchema: z.ZodEnum<{
43
- draft: "draft";
44
43
  active: "active";
44
+ draft: "draft";
45
45
  paused: "paused";
46
46
  }>;
47
47
  export type AutomationStatus = z.infer<typeof automationStatusSchema>;
@@ -356,8 +356,8 @@ export declare const automationSummarySchema: z.ZodObject<{
356
356
  id: z.ZodString;
357
357
  name: z.ZodString;
358
358
  status: z.ZodEnum<{
359
- draft: "draft";
360
359
  active: "active";
360
+ draft: "draft";
361
361
  paused: "paused";
362
362
  }>;
363
363
  triggerType: z.ZodEnum<{
@@ -373,8 +373,8 @@ export declare const automationDetailSchema: z.ZodObject<{
373
373
  id: z.ZodString;
374
374
  name: z.ZodString;
375
375
  status: z.ZodEnum<{
376
- draft: "draft";
377
376
  active: "active";
377
+ draft: "draft";
378
378
  paused: "paused";
379
379
  }>;
380
380
  triggerType: z.ZodEnum<{
@@ -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,M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EAAE,MAAM,CAAC;IAChB,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEN,8EAA8E;AAC9E,MAAM,MAAM,0BAA0B,GAAG,OAAO,CAAC,qBAAqB,EAAE;IAAE,IAAI,EAAE,qBAAqB,CAAA;CAAE,CAAC,CAAC;AAEzG;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,SAAS,gBAAgB,EAAE,EAClC,KAAK,EAAE,iBAAiB,GACvB,qBAAqB,EAAE,CAmEzB;AAyDD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,SAAS,0BAA0B,EAAE,EACjD,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5C,OAAO,EAAE,YAAY,GAAG,OAAO,GAC9B;IACD,IAAI,EAAE,gCAAgC,GAAG,uCAAuC,CAAC;IACjF,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,GAAG,IAAI,CAyCP"}
@@ -0,0 +1,196 @@
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 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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