@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
@@ -1,338 +1,72 @@
1
1
  import { z } from 'zod';
2
- import { ADMIN_PRODUCT_SELECTION_MAX } from './catalog.js';
3
- import { isoDateTimeSchema, moneySchema, uuidSchema } from './common.js';
2
+ import { isoDateTimeSchema, uuidSchema } from './common.js';
3
+ import { priceSourceSchema } from './price-books.js';
4
4
  /**
5
- * Pricing contracts (feature 011 engine).
5
+ * Pricing contracts — what every consumer of a price reads.
6
6
  *
7
- * Schemas: `priceListEngineSchema`, `applicationRuleSchema`,
8
- * `priceListBracketSchema`, `displayModeSchema`, etc. Model the B2B
9
- * pricing engine: multi-currency multi-bracket prices per product, an
10
- * Application Rule tree (AND/OR over SC/CG/Org/Cat/Currency criteria),
11
- * Base/Sale split, lifecycle status, and the four-level price-display
12
- * mode chain.
13
- *
14
- * Legacy feature-014 schemas (`priceListItemSchema`,
15
- * `priceListAssignmentSchema`, etc.) were retired by T011 alongside
16
- * their entity files and admin endpoints.
7
+ * Feature 160 (D-287 P1) replaced the feature-011 engine with price books:
8
+ * the book, its rows, its sets and the explanation are in `price-books.ts`;
9
+ * this file keeps what a *price* looks like to its readers — the listing and
10
+ * line answers, the ports that produce them, the display-mode chain, the price
11
+ * ordering, and the price-list read port. The Application-rule tree and its
12
+ * evaluator, the bracket and roster shapes, the matrix-entry v1 shapes and the
13
+ * `priceListAdminPort` were removed with the old model (`priceBookWritePort`, in
14
+ * `price-books.ts`, replaces the last).
17
15
  */
18
16
  const CURRENCY = z.string().regex(/^[A-Z]{3}$/, 'ISO 4217 currency code');
19
17
  const POSITIVE_INT = z.number().int().positive();
20
18
  const DECIMAL_STRING = z
21
19
  .string()
22
20
  .regex(/^\d+(\.\d{1,4})?$/, 'decimal as string with up to 4 fractional digits');
23
- // --- Customer Group ---------------------------------------------------------
24
- //
25
- // The schemas, the record and the read port moved to `customer-accounts.ts`
26
- // with the entity (feature 076, D-79): a customer group describes the customer,
27
- // and a price list merely refers to one by id. Nothing here imports them back —
28
- // `PriceListAssignment` and the rule-target types carry a `customerGroupId`
29
- // string, never the record.
30
- // =============================================================================
31
- // FEATURE 011 — pricing-engine schemas
32
- // =============================================================================
33
- // --- Application Rule AST ---------------------------------------------------
34
- export const ruleCriterionTypeSchema = z.enum([
35
- 'salesChannel',
36
- 'customerGroup',
37
- 'organization',
38
- 'category',
39
- 'currency',
40
- ]);
41
- const ruleCriterionNodeSchema = z.object({
42
- kind: z.literal('criterion'),
43
- type: ruleCriterionTypeSchema,
44
- values: z.array(z.string()).max(1000),
45
- });
46
- const ruleAllNodeSchema = z.object({ kind: z.literal('all') });
47
- const ruleNodeSchema = z.lazy(() => z.discriminatedUnion('kind', [
48
- ruleAllNodeSchema,
49
- ruleCriterionNodeSchema,
50
- z.object({
51
- kind: z.literal('group'),
52
- op: z.enum(['AND', 'OR']),
53
- children: z.array(ruleNodeSchema).min(1).max(20),
54
- }),
55
- ]));
56
- function ruleDepth(node) {
57
- if (node.kind !== 'group')
58
- return 0;
59
- return 1 + Math.max(...node.children.map(ruleDepth));
60
- }
61
- export const applicationRuleSchema = ruleNodeSchema.refine((node) => ruleDepth(node) <= 5, { message: 'rule_depth_exceeds_5' });
62
- // --- Price list (engine shape) ---------------------------------------------
63
- export const priceListTypeSchema = z.enum(['base', 'sale']);
64
- export const priceListStatusSchema = z.enum([
65
- 'draft',
66
- 'active',
67
- 'scheduled',
68
- 'expired',
69
- ]);
70
- export const priceListEngineSchema = z.object({
71
- id: uuidSchema,
72
- name: z.string().min(1).max(200),
73
- type: priceListTypeSchema,
74
- status: priceListStatusSchema,
75
- startsAt: isoDateTimeSchema.nullable(),
76
- endsAt: isoDateTimeSchema.nullable(),
77
- applicationRule: applicationRuleSchema,
78
- isSystem: z.boolean(),
79
- modifiedAt: isoDateTimeSchema,
80
- createdAt: isoDateTimeSchema,
81
- });
82
- export const createPriceListEngineRequestSchema = z.object({
83
- name: z.string().min(1).max(200),
84
- type: priceListTypeSchema,
85
- startsAt: isoDateTimeSchema.nullable().optional(),
86
- endsAt: isoDateTimeSchema.nullable().optional(),
87
- applicationRule: applicationRuleSchema.optional(),
88
- });
89
- export const patchPriceListEngineRequestSchema = z
90
- .object({
91
- name: z.string().min(1).max(200).optional(),
92
- type: priceListTypeSchema.optional(),
93
- startsAt: isoDateTimeSchema.nullable().optional(),
94
- endsAt: isoDateTimeSchema.nullable().optional(),
95
- applicationRule: applicationRuleSchema.optional(),
96
- })
97
- .refine((v) => Object.keys(v).length > 0, { message: 'patch_body_empty' });
98
- // --- Price brackets ---------------------------------------------------------
99
- export const priceListBracketSchema = z.object({
100
- priceListId: uuidSchema,
101
- productId: uuidSchema,
102
- currencyCode: CURRENCY,
103
- minQuantity: POSITIVE_INT,
104
- maxQuantity: POSITIVE_INT.nullable(),
105
- amount: DECIMAL_STRING,
106
- });
107
- export const replaceBracketsRequestSchema = z.object({
108
- bracketsByCurrency: z.record(CURRENCY, z.array(z.object({
109
- minQuantity: POSITIVE_INT,
110
- maxQuantity: POSITIVE_INT.nullable(),
111
- amount: DECIMAL_STRING,
112
- }))),
113
- });
114
- export const productAssignmentSchema = z.object({
115
- priceListId: uuidSchema,
116
- productId: uuidSchema,
117
- bracketsByCurrency: z.record(CURRENCY, z.array(priceListBracketSchema)),
118
- });
119
- export const replaceProductsRequestSchema = z.object({
120
- productIds: z.array(uuidSchema),
121
- });
122
- // --- Price matrix (feature 148) ---------------------------------------------
123
- //
124
- // A matrix entry prices a *selection* of products (one product, a category, an
125
- // attribute value, a category and an attribute value, or every product) for an
126
- // optional organization and a quantity window, at a fixed unit price or a
127
- // percentage off the reference price. It lives inside a price list: the list's
128
- // application rule still decides which buyers the list serves, and the entry
129
- // decides the price within it. Resolution semantics:
130
- // `specs/148-price-list-matrix-rules/contracts/pricing-resolution-matrix.md`.
131
- /** At most this many entries per price list (spec FR-007) — a product decision. */
132
- export const PRICE_MATRIX_MAX_ENTRIES_PER_LIST = 5000;
133
- export const priceMatrixPriceTypeSchema = z.enum(['fixed', 'discount_percent']);
134
- /** Derived from which selection coordinates are set; never stored. */
135
- export const priceMatrixSelectionKindSchema = z.enum([
136
- 'product',
137
- 'category_attribute',
138
- 'attribute',
139
- 'category',
140
- 'all',
141
- ]);
142
- /** A percentage with at most two decimals, greater than 0 and at most 100. */
143
- const PRICE_MATRIX_PERCENT_SHAPE = /^\d{1,3}(\.\d{1,2})?$/;
144
- const PRICE_MATRIX_PERCENT = z.string().superRefine((v, ctx) => {
145
- if (!PRICE_MATRIX_PERCENT_SHAPE.test(v)) {
146
- ctx.addIssue({ code: 'custom', message: 'percentage with up to 2 fractional digits' });
147
- return;
148
- }
149
- const n = Number(v);
150
- if (!(n > 0 && n <= 100)) {
151
- ctx.addIssue({ code: 'custom', message: 'percentage must be greater than 0 and at most 100' });
152
- }
153
- });
154
- export const priceMatrixAttributeSchema = z.object({
155
- key: z.string().min(1).max(64),
156
- value: z.string().min(1).max(255),
157
- });
158
- export const priceMatrixPriceSchema = z.discriminatedUnion('type', [
159
- z.object({ type: z.literal('fixed'), amount: DECIMAL_STRING, currencyCode: CURRENCY }),
160
- z.object({ type: z.literal('discount_percent'), percent: PRICE_MATRIX_PERCENT }),
21
+ // --- Display modes ----------------------------------------------------------
22
+ export const displayModeSchema = z.enum([
23
+ 'gross_only',
24
+ 'net_only',
25
+ 'both',
26
+ 'none',
161
27
  ]);
162
- /** `selectionKind` of an entry, from which selection coordinates are set. */
163
- export function priceMatrixSelectionKind(entry) {
164
- if (entry.productId !== null)
165
- return 'product';
166
- if (entry.categoryId !== null && entry.attribute !== null)
167
- return 'category_attribute';
168
- if (entry.attribute !== null)
169
- return 'attribute';
170
- if (entry.categoryId !== null)
171
- return 'category';
172
- return 'all';
173
- }
174
28
  /**
175
- * The cross-field rules of an entry — the CHECK constraints of
176
- * `price_list_matrix_entries` that a single field cannot express (data-model
177
- * §1). One function so the create schema and the service's merge-then-validate
178
- * of a PATCH apply exactly the same rules.
29
+ * Issue #491 — whether a resolved display mode withholds every amount from the
30
+ * viewer it was resolved for.
31
+ *
32
+ * `none` is "price on request": the shop does not show this viewer a price, and
33
+ * the server does not send one. `price_lists` applies it where it maps a
34
+ * resolution onto the published listing and engine shapes
35
+ * (`ListingPriceDetail`, `ListingPrice`, the resolved-price endpoint), so every
36
+ * catalogue surface gets no amount and `displayMode: 'none'`. A **line** answer
37
+ * ({@link LinePriceResult}) keeps its amount, because it is what a charging
38
+ * consumer refuses as quote-only; a consumer that publishes a line amount to a
39
+ * viewer asks this function first rather than re-stating the rule.
179
40
  */
180
- export function priceMatrixEntryShapeIssues(entry) {
181
- const out = [];
182
- if (entry.productId !== null && (entry.categoryId !== null || entry.attribute !== null)) {
183
- out.push({
184
- path: ['productId'],
185
- message: 'A product selection cannot be combined with a category or an attribute.',
186
- });
187
- }
188
- if (entry.productId !== null && entry.organizationId === null) {
189
- out.push({
190
- path: ['organizationId'],
191
- message: "A product selection needs an organization — without one it is the list's own product price.",
192
- });
193
- }
194
- if (entry.maxQuantity !== null && entry.maxQuantity < entry.minQuantity) {
195
- out.push({ path: ['maxQuantity'], message: 'maxQuantity must be at least minQuantity.' });
196
- }
197
- if (entry.price.type === 'fixed' &&
198
- entry.productId === null &&
199
- entry.categoryId === null &&
200
- entry.attribute === null) {
201
- out.push({
202
- path: ['price', 'type'],
203
- message: 'A fixed price needs a product, category or attribute selection.',
204
- });
205
- }
206
- return out;
41
+ export function displayModeWithholdsAmounts(mode) {
42
+ return mode === 'none';
207
43
  }
208
- const priceMatrixEntryFields = {
209
- productId: uuidSchema.nullable().default(null),
210
- categoryId: uuidSchema.nullable().default(null),
211
- attribute: priceMatrixAttributeSchema.nullable().default(null),
212
- organizationId: uuidSchema.nullable().default(null),
213
- minQuantity: POSITIVE_INT,
214
- maxQuantity: POSITIVE_INT.nullable().default(null),
215
- price: priceMatrixPriceSchema,
216
- };
217
- /** Body of `POST /api/v1/admin/price-lists-engine/:id/matrix`. */
218
- export const priceMatrixEntryInputSchema = z
219
- .object(priceMatrixEntryFields)
220
- .superRefine((value, ctx) => {
221
- for (const issue of priceMatrixEntryShapeIssues(value)) {
222
- ctx.addIssue({ code: 'custom', path: issue.path, message: issue.message });
223
- }
224
- });
225
44
  /**
226
- * Body of `PATCH …/matrix/:entryId` — every field optional, at least one
227
- * present. The cross-field rules run on the merged entry in the service.
45
+ * Feature 160 (FR-029, owner ruling 2026-10-23) — why a price book pinned to a
46
+ * product feed publishes no prices now. A feed is fetched by a provider, which
47
+ * is nobody's buyer, so a pinned book publishes only while it would price an
48
+ * anonymous buyer on the feed's channel: `active` or `scheduled` and inside its
49
+ * schedule window (`outside_schedule`, else `not_active`), bound to that
50
+ * channel with the channel offering its currency (`not_on_channel`; a base book
51
+ * is channel-independent), and for everyone (`audience_restricted`). A book in
52
+ * another currency than the feed's (`currency_mismatch`) or one that does not
53
+ * exist (`not_found`) prices nothing either.
228
54
  */
229
- export const priceMatrixEntryPatchSchema = z
230
- .object({
231
- productId: uuidSchema.nullable().optional(),
232
- categoryId: uuidSchema.nullable().optional(),
233
- attribute: priceMatrixAttributeSchema.nullable().optional(),
234
- organizationId: uuidSchema.nullable().optional(),
235
- minQuantity: POSITIVE_INT.optional(),
236
- maxQuantity: POSITIVE_INT.nullable().optional(),
237
- price: priceMatrixPriceSchema.optional(),
238
- })
239
- .refine((v) => Object.keys(v).length > 0, { message: 'patch_body_empty' });
240
- /** Query of `GET …/matrix`. `organizationId = 'none'` lists not organization-specific entries. */
241
- export const priceMatrixListQuerySchema = z.object({
242
- page: z.coerce.number().int().min(0).default(0),
243
- pageSize: z.coerce.number().int().min(1).max(200).default(50),
244
- selectionKind: priceMatrixSelectionKindSchema.optional(),
245
- organizationId: z.union([uuidSchema, z.literal('none')]).optional(),
246
- productId: uuidSchema.optional(),
247
- categoryId: uuidSchema.optional(),
248
- });
249
- /** Why an attribute entry does not price anything right now (spec FR-010). */
250
- export const priceMatrixInactiveReasonSchema = z.enum([
251
- 'attribute_not_flagged',
252
- 'attribute_not_found',
253
- 'attribute_language_scoped',
254
- 'attribute_channel_scoped',
255
- 'attribute_value_type',
55
+ export const pinnedPriceBookUnpublishableReasonSchema = z.enum([
56
+ 'not_found',
57
+ 'currency_mismatch',
58
+ 'not_active',
59
+ 'outside_schedule',
60
+ 'not_on_channel',
61
+ 'audience_restricted',
256
62
  ]);
257
- export const priceMatrixEntrySchema = z.object({
258
- id: uuidSchema,
259
- priceListId: uuidSchema,
260
- selectionKind: priceMatrixSelectionKindSchema,
261
- productId: uuidSchema.nullable(),
262
- categoryId: uuidSchema.nullable(),
263
- attribute: priceMatrixAttributeSchema.nullable(),
264
- organizationId: uuidSchema.nullable(),
265
- minQuantity: POSITIVE_INT,
266
- maxQuantity: POSITIVE_INT.nullable(),
267
- price: priceMatrixPriceSchema,
268
- /** `false` ⇒ the attribute is no longer eligible; always `true` for non-attribute entries. */
269
- active: z.boolean(),
270
- inactiveReason: priceMatrixInactiveReasonSchema.nullable(),
271
- /**
272
- * `true` when the named product, category or organization no longer resolves
273
- * as live (soft-deleted — the foreign-key cascade only fires on a purge).
274
- */
275
- targetDeleted: z.boolean(),
276
- /** Display labels resolved server-side, so the table needs no request per row. */
277
- labels: z.object({
278
- product: z.object({ sku: z.string(), name: z.string() }).nullable(),
279
- category: z.string().nullable(),
280
- attribute: z.object({ label: z.string(), valueLabel: z.string() }).nullable(),
281
- organization: z.string().nullable(),
282
- }),
283
- createdAt: isoDateTimeSchema,
284
- updatedAt: isoDateTimeSchema,
285
- });
286
- export const priceMatrixListResponseSchema = z.object({
287
- data: z.object({
288
- items: z.array(priceMatrixEntrySchema),
289
- total: z.number().int().min(0),
290
- page: z.number().int().min(0),
291
- pageSize: z.number().int().min(1),
292
- limit: z.number().int().min(1),
293
- }),
294
- });
295
- export const priceMatrixEntryResponseSchema = z.object({ data: priceMatrixEntrySchema });
296
- /** One item of `GET /api/v1/admin/pricing/rule-targets/attributes`. */
297
- export const priceMatrixAttributeTargetSchema = z.object({
298
- key: z.string(),
299
- label: z.string(),
300
- valueType: z.enum(['select', 'enum', 'multiselect', 'boolean']),
301
- options: z.array(z.object({ value: z.string(), label: z.string() })),
302
- });
303
- /** Route params of every `/api/v1/admin/price-lists-engine/:id/...` route. */
304
- export const priceListIdParamsSchema = z.object({ id: uuidSchema });
305
63
  /**
306
- * Body of `POST /api/v1/admin/price-lists-engine/:id/products/bulk-add`: add
307
- * the products to the list's roster in one audited write. Additive — products
308
- * already on the roster keep their brackets. At least one id, at most
309
- * {@link ADMIN_PRODUCT_SELECTION_MAX}.
64
+ * `productResolvedPriceSchema` (in `catalog.ts`, which this file imports and so
65
+ * cannot import back) spells the display modes out; this keeps the two lists
66
+ * identical at compile time.
310
67
  */
311
- export const bulkAddPriceListProductsRequestSchema = z.object({
312
- productIds: z.array(uuidSchema).min(1).max(ADMIN_PRODUCT_SELECTION_MAX),
313
- });
314
- /** Why a product of a bulk add was not added. `product_not_found`: unknown or deleted. */
315
- export const bulkAddPriceListProductFailureReasonSchema = z.enum(['product_not_found']);
316
- /**
317
- * Per-product outcome of a bulk add, over the de-duplicated ids: `added` now
318
- * on the roster, `unchanged` already on it (a retry is safe), `failed` with a
319
- * reason.
320
- */
321
- export const bulkAddPriceListProductsResultSchema = z.object({
322
- added: z.array(uuidSchema),
323
- unchanged: z.array(uuidSchema),
324
- failed: z.array(z.object({ productId: uuidSchema, reason: bulkAddPriceListProductFailureReasonSchema })),
325
- });
326
- export const bulkAddPriceListProductsResponseSchema = z.object({
327
- data: bulkAddPriceListProductsResultSchema,
328
- });
329
- // --- Display modes ----------------------------------------------------------
330
- export const displayModeSchema = z.enum([
331
- 'gross_only',
332
- 'net_only',
333
- 'both',
334
- 'none',
335
- ]);
68
+ const displayModesAgree = true;
69
+ void displayModesAgree;
336
70
  export const displayModeOverrideScopeSchema = z.enum([
337
71
  'organization',
338
72
  'category',
@@ -348,37 +82,72 @@ export const upsertDisplayModeOverrideRequestSchema = z.object({
348
82
  mode: displayModeSchema.or(z.literal('inherit')),
349
83
  });
350
84
  // --- Resolved price (storefront/cart consumer) ------------------------------
351
- export const resolvedPriceEngineSchema = z.object({
352
- baseListId: uuidSchema,
353
- basePrice: moneySchema,
85
+ /** A price as the resolver answers it: the amount as a decimal string, never a float. */
86
+ const RESOLVED_MONEY = z.object({ amount: DECIMAL_STRING, currency: CURRENCY });
87
+ /**
88
+ * `GET /api/v1/storefront/products/:id/resolved-price`. A product no price book
89
+ * prices for the buyer (FR-018) is **unpriced**: `baseListId`, `basePrice` and
90
+ * `quantityBracket` are all `null` together — never an empty-string id.
91
+ *
92
+ * Issue #491 — a product whose display mode resolves to `none` for the viewer
93
+ * answers the same way: no book, no amount, no bracket, no sale, `source` and
94
+ * `compareAt` `null` and no `listPrice`, with `displayMode: 'none'` so the page
95
+ * can tell "price on request" from "no price".
96
+ */
97
+ export const resolvedPriceEngineSchema = z
98
+ .object({
99
+ baseListId: uuidSchema.nullable(),
100
+ basePrice: RESOLVED_MONEY.nullable(),
354
101
  saleListId: uuidSchema.nullable(),
355
- salePrice: moneySchema.nullable(),
102
+ salePrice: RESOLVED_MONEY.nullable(),
356
103
  displayMode: displayModeSchema,
357
104
  currencyCode: CURRENCY,
358
- quantityBracket: z.object({
105
+ quantityBracket: z
106
+ .object({
359
107
  minQuantity: POSITIVE_INT,
360
108
  maxQuantity: POSITIVE_INT.nullable(),
361
- }),
109
+ })
110
+ .nullable(),
111
+ /** Feature 160 — which tier priced the charged line; `null` when nothing did. */
112
+ source: priceSourceSchema.nullable().optional(),
113
+ /** Feature 160 — the buyer price a charged sale undercut. */
114
+ compareAt: z.string().nullable().optional(),
115
+ /** Feature 160 (G9) — the catalogue price beside a lower buyer price, when shown. */
116
+ listPrice: z.object({ amount: z.string(), currency: CURRENCY }).optional(),
117
+ })
118
+ .superRefine((value, ctx) => {
119
+ const priced = [value.baseListId !== null, value.basePrice !== null, value.quantityBracket !== null];
120
+ if (priced.some((p) => p !== priced[0])) {
121
+ ctx.addIssue({
122
+ code: 'custom',
123
+ message: 'baseListId, basePrice and quantityBracket are null together (unpriced) or set together (priced).',
124
+ path: ['baseListId'],
125
+ });
126
+ }
362
127
  });
363
128
  // --- Listing price (catalogue listing / search / compare / links) -----------
364
129
  /**
365
130
  * What a catalogue listing may show as a product's price — issue #132.
366
131
  *
367
- * There is always one default price list, so the first arm is the path a
368
- * listing normally takes. The product ruling names the whole chain and this
369
- * union is that chain, one arm each:
132
+ * Two arms:
370
133
  *
371
- * `price_list` — an applicable list priced this product for this buyer;
372
- * `product` — no list applied, so the price assigned directly to the
373
- * Product stands in (the legacy `defaultPrice` attribute);
374
- * `none` — neither exists, and the listing renders no price.
134
+ * `price_list` — a price book priced this product for this buyer (the base
135
+ * book, an everyone book of the channel, a buyer book or a
136
+ * sale; `priceSource` names the tier);
137
+ * `none` — nothing prices it, or the viewer's display mode is `none`
138
+ * (issue #491: the amount is withheld on the server), and the
139
+ * listing renders no price.
140
+ *
141
+ * Feature 160 removed the third arm, `product` — the price assigned directly
142
+ * to the Product (the legacy `defaultPrice` attribute): a product has no price
143
+ * of its own any more (FR-042).
375
144
  *
376
145
  * The `none` arm carries **no `amount` field**, following the `ResolvedTax`
377
146
  * precedent (issue #124): a listing showing nothing and a listing offering a
378
147
  * free product are different pages, so a caller has to narrow on `source`
379
148
  * before it can read a figure. A product priced at zero comes back as
380
- * `{ source: 'price_list' | 'product', amount: '0.00' }` and renders as zero —
381
- * `amount` is never a falsy sentinel for absence.
149
+ * `{ source: 'price_list', amount: '0.00' }` and renders as zero — `amount` is
150
+ * never a falsy sentinel for absence.
382
151
  *
383
152
  * As with `ResolvedTax`, "the `price_lists` module is absent" is deliberately
384
153
  * not an arm: absence is not a value, and the port gate throws
@@ -391,11 +160,18 @@ export const listingPriceSchema = z.discriminatedUnion('source', [
391
160
  currency: CURRENCY,
392
161
  priceListId: uuidSchema,
393
162
  isSale: z.boolean(),
394
- }),
395
- z.object({
396
- source: z.literal('product'),
397
- amount: DECIMAL_STRING,
398
- currency: CURRENCY,
163
+ /**
164
+ * Feature 160 (D-287 P1) — which tier of the price-book resolution priced
165
+ * the card. Named `priceSource` because `source` is this union's
166
+ * discriminant.
167
+ */
168
+ priceSource: priceSourceSchema.optional(),
169
+ /** Feature 160 — the buyer price, struck through, when a sale is charged (FR-025). */
170
+ compareAtAmount: DECIMAL_STRING.optional(),
171
+ /** Feature 160 — the variants of the product resolve to different prices (FR-024). */
172
+ variesByVariant: z.boolean().optional(),
173
+ /** Feature 160 — the highest variant price; `amount` is the lowest ("from"). */
174
+ maxAmount: DECIMAL_STRING.optional(),
399
175
  }),
400
176
  z.object({ source: z.literal('none') }),
401
177
  ]);
@@ -466,120 +242,4 @@ export const PRICING_SETTING_CODES = {
466
242
  DEFAULT_DISPLAY_MODE: 'pricing.default_display_mode',
467
243
  UNAUTHENTICATED_DISPLAY_MODE: 'pricing.unauthenticated_display_mode',
468
244
  };
469
- const NO_EXPLICIT = new Set();
470
- /**
471
- * Pure rule evaluator (feature 011 / FR-022, FR-023, FR-026, FR-029).
472
- *
473
- * Walks the discriminated-union AST and returns:
474
- * - `matched`: the overall AST truth value against the resolution context.
475
- * - `explicitOn`: the criterion types that contributed to the match AND had
476
- * non-empty value lists. The resolver's priority chain consults this to
477
- * award the per-step boost (FR-026 steps 1..4).
478
- *
479
- * Notes:
480
- * - The `category` criterion is product-driven (FR-029): it matches when the
481
- * product belongs to any category named in the rule's value list.
482
- * - The `currency` criterion never appears in the priority chain even when
483
- * explicit; it is purely a matching criterion.
484
- * - `{ kind: 'all' }` and any criterion with `values: []` are treated as
485
- * always-true and contribute nothing to `explicitOn` (FR-022).
486
- */
487
- export function evaluateApplicationRule(rule, ctx) {
488
- if (rule.kind === 'all') {
489
- return { matched: true, explicitOn: NO_EXPLICIT };
490
- }
491
- if (rule.kind === 'criterion') {
492
- if (rule.values.length === 0) {
493
- return { matched: true, explicitOn: NO_EXPLICIT };
494
- }
495
- if (rule.type === 'organization') {
496
- const rank = organizationMatchRank(rule.values, ctx);
497
- if (rank === undefined)
498
- return { matched: false, explicitOn: NO_EXPLICIT };
499
- return { matched: true, explicitOn: new Set(['organization']), organizationRank: rank };
500
- }
501
- const matched = matchesCriterion(rule.type, rule.values, ctx);
502
- return {
503
- matched,
504
- explicitOn: matched ? new Set([rule.type]) : NO_EXPLICIT,
505
- };
506
- }
507
- // group node
508
- if (rule.children.length === 0) {
509
- // defensive — schema disallows, but evaluate as always-true (empty AND/OR)
510
- return { matched: true, explicitOn: NO_EXPLICIT };
511
- }
512
- const childEvaluations = rule.children.map((c) => evaluateApplicationRule(c, ctx));
513
- if (rule.op === 'AND') {
514
- const allMatch = childEvaluations.every((e) => e.matched);
515
- if (!allMatch)
516
- return { matched: false, explicitOn: NO_EXPLICIT };
517
- return {
518
- matched: true,
519
- explicitOn: unionExplicit(childEvaluations),
520
- ...withRank(minRank(childEvaluations)),
521
- };
522
- }
523
- // OR
524
- const matchingChildren = childEvaluations.filter((e) => e.matched);
525
- if (matchingChildren.length === 0)
526
- return { matched: false, explicitOn: NO_EXPLICIT };
527
- // Only matching children contribute to the explicit set + nearness rank.
528
- return {
529
- matched: true,
530
- explicitOn: unionExplicit(matchingChildren),
531
- ...withRank(minRank(matchingChildren)),
532
- };
533
- }
534
- /**
535
- * The nearness rank of the nearest org (in `ctx.organizationChain`, else
536
- * `[organizationId]`) named by `values`, or `undefined` when none match.
537
- */
538
- function organizationMatchRank(values, ctx) {
539
- const chain = ctx.organizationChain && ctx.organizationChain.length > 0
540
- ? ctx.organizationChain
541
- : ctx.organizationId !== null
542
- ? [ctx.organizationId]
543
- : [];
544
- const valueSet = new Set(values);
545
- for (let i = 0; i < chain.length; i += 1) {
546
- if (valueSet.has(chain[i]))
547
- return i; // nearest-first → first hit is the nearest
548
- }
549
- return undefined;
550
- }
551
- function minRank(evaluations) {
552
- let min;
553
- for (const e of evaluations) {
554
- if (e.organizationRank !== undefined && (min === undefined || e.organizationRank < min)) {
555
- min = e.organizationRank;
556
- }
557
- }
558
- return min;
559
- }
560
- function withRank(rank) {
561
- return rank === undefined ? {} : { organizationRank: rank };
562
- }
563
- function matchesCriterion(type, values, ctx) {
564
- switch (type) {
565
- case 'salesChannel':
566
- return values.includes(ctx.salesChannelId);
567
- case 'organization':
568
- return organizationMatchRank(values, ctx) !== undefined;
569
- case 'customerGroup':
570
- return ctx.customerGroupId !== null && values.includes(ctx.customerGroupId);
571
- case 'category':
572
- return values.some((c) => ctx.productCategoryIds.has(c));
573
- case 'currency':
574
- return values.includes(ctx.currencyCode);
575
- }
576
- }
577
- function unionExplicit(evaluations) {
578
- const out = new Set();
579
- for (const e of evaluations) {
580
- for (const t of e.explicitOn)
581
- out.add(t);
582
- }
583
- return out;
584
- }
585
245
  //# sourceMappingURL=price-lists.js.map