@endora-commerce/mod-catalog 0.108.0 → 0.110.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 (571) hide show
  1. package/dist/admin/components/CopyToChannelsDialog.d.ts +37 -0
  2. package/dist/admin/components/CopyToChannelsDialog.d.ts.map +1 -0
  3. package/dist/admin/components/CopyToChannelsDialog.js +83 -0
  4. package/dist/admin/components/CopyToChannelsDialog.js.map +1 -0
  5. package/dist/admin/components/PackagingUnitsEditor.d.ts +16 -1
  6. package/dist/admin/components/PackagingUnitsEditor.d.ts.map +1 -1
  7. package/dist/admin/components/PackagingUnitsEditor.js +20 -14
  8. package/dist/admin/components/PackagingUnitsEditor.js.map +1 -1
  9. package/dist/admin/components/ProductAttachmentsSection.d.ts +3 -0
  10. package/dist/admin/components/ProductAttachmentsSection.d.ts.map +1 -0
  11. package/dist/admin/components/ProductAttachmentsSection.js +98 -0
  12. package/dist/admin/components/ProductAttachmentsSection.js.map +1 -0
  13. package/dist/admin/components/ProductAttributesTab.d.ts +1 -11
  14. package/dist/admin/components/ProductAttributesTab.d.ts.map +1 -1
  15. package/dist/admin/components/ProductAttributesTab.js +128 -119
  16. package/dist/admin/components/ProductAttributesTab.js.map +1 -1
  17. package/dist/admin/components/ProductContentCard.d.ts +41 -0
  18. package/dist/admin/components/ProductContentCard.d.ts.map +1 -0
  19. package/dist/admin/components/ProductContentCard.js +28 -0
  20. package/dist/admin/components/ProductContentCard.js.map +1 -0
  21. package/dist/admin/components/ProductGallerySection.d.ts +3 -0
  22. package/dist/admin/components/ProductGallerySection.d.ts.map +1 -0
  23. package/dist/admin/components/ProductGallerySection.js +129 -0
  24. package/dist/admin/components/ProductGallerySection.js.map +1 -0
  25. package/dist/admin/components/ProductOrderRulesCard.d.ts +11 -15
  26. package/dist/admin/components/ProductOrderRulesCard.d.ts.map +1 -1
  27. package/dist/admin/components/ProductOrderRulesCard.js +15 -140
  28. package/dist/admin/components/ProductOrderRulesCard.js.map +1 -1
  29. package/dist/admin/components/ProductScopeBar.d.ts +28 -0
  30. package/dist/admin/components/ProductScopeBar.d.ts.map +1 -0
  31. package/dist/admin/components/ProductScopeBar.js +70 -0
  32. package/dist/admin/components/ProductScopeBar.js.map +1 -0
  33. package/dist/admin/components/ProductScopeOverview.d.ts +38 -0
  34. package/dist/admin/components/ProductScopeOverview.d.ts.map +1 -0
  35. package/dist/admin/components/ProductScopeOverview.js +222 -0
  36. package/dist/admin/components/ProductScopeOverview.js.map +1 -0
  37. package/dist/admin/components/ProductStatusPills.d.ts +17 -0
  38. package/dist/admin/components/ProductStatusPills.d.ts.map +1 -0
  39. package/dist/admin/components/ProductStatusPills.js +23 -0
  40. package/dist/admin/components/ProductStatusPills.js.map +1 -0
  41. package/dist/admin/components/ProductUrlRedirects.d.ts +15 -0
  42. package/dist/admin/components/ProductUrlRedirects.d.ts.map +1 -0
  43. package/dist/admin/components/ProductUrlRedirects.js +70 -0
  44. package/dist/admin/components/ProductUrlRedirects.js.map +1 -0
  45. package/dist/admin/components/ProductsBulkEditDialog.d.ts +30 -0
  46. package/dist/admin/components/ProductsBulkEditDialog.d.ts.map +1 -1
  47. package/dist/admin/components/ProductsBulkEditDialog.js +288 -133
  48. package/dist/admin/components/ProductsBulkEditDialog.js.map +1 -1
  49. package/dist/admin/components/editor/DetailsTab.d.ts +30 -0
  50. package/dist/admin/components/editor/DetailsTab.d.ts.map +1 -0
  51. package/dist/admin/components/editor/DetailsTab.js +59 -0
  52. package/dist/admin/components/editor/DetailsTab.js.map +1 -0
  53. package/dist/admin/components/editor/ImmediateBadge.d.ts +21 -0
  54. package/dist/admin/components/editor/ImmediateBadge.d.ts.map +1 -0
  55. package/dist/admin/components/editor/ImmediateBadge.js +21 -0
  56. package/dist/admin/components/editor/ImmediateBadge.js.map +1 -0
  57. package/dist/admin/components/editor/confirm-removal.d.ts +13 -0
  58. package/dist/admin/components/editor/confirm-removal.d.ts.map +1 -0
  59. package/dist/admin/components/editor/confirm-removal.js +33 -0
  60. package/dist/admin/components/editor/confirm-removal.js.map +1 -0
  61. package/dist/admin/components/editor/editor-context.d.ts +53 -0
  62. package/dist/admin/components/editor/editor-context.d.ts.map +1 -0
  63. package/dist/admin/components/editor/editor-context.js +88 -0
  64. package/dist/admin/components/editor/editor-context.js.map +1 -0
  65. package/dist/admin/components/editor/scoped-controls.d.ts +46 -0
  66. package/dist/admin/components/editor/scoped-controls.d.ts.map +1 -0
  67. package/dist/admin/components/editor/scoped-controls.js +64 -0
  68. package/dist/admin/components/editor/scoped-controls.js.map +1 -0
  69. package/dist/admin/index.d.ts +2 -2
  70. package/dist/admin/index.d.ts.map +1 -1
  71. package/dist/admin/index.js +20 -0
  72. package/dist/admin/index.js.map +1 -1
  73. package/dist/admin/lib/attribute-scope.d.ts +23 -0
  74. package/dist/admin/lib/attribute-scope.d.ts.map +1 -0
  75. package/dist/admin/lib/attribute-scope.js +21 -0
  76. package/dist/admin/lib/attribute-scope.js.map +1 -0
  77. package/dist/admin/lib/bulk-operation-log-text.d.ts +9 -0
  78. package/dist/admin/lib/bulk-operation-log-text.d.ts.map +1 -0
  79. package/dist/admin/lib/bulk-operation-log-text.js +13 -0
  80. package/dist/admin/lib/bulk-operation-log-text.js.map +1 -0
  81. package/dist/admin/lib/editor-scope.d.ts +35 -0
  82. package/dist/admin/lib/editor-scope.d.ts.map +1 -0
  83. package/dist/admin/lib/editor-scope.js +114 -0
  84. package/dist/admin/lib/editor-scope.js.map +1 -0
  85. package/dist/admin/lib/order-minimum-input.d.ts +13 -0
  86. package/dist/admin/lib/order-minimum-input.d.ts.map +1 -0
  87. package/dist/admin/lib/order-minimum-input.js +16 -0
  88. package/dist/admin/lib/order-minimum-input.js.map +1 -0
  89. package/dist/admin/lib/product-labels.d.ts +12 -0
  90. package/dist/admin/lib/product-labels.d.ts.map +1 -0
  91. package/dist/admin/lib/product-labels.js +23 -0
  92. package/dist/admin/lib/product-labels.js.map +1 -0
  93. package/dist/admin/lib/product-scopes-api.d.ts +23 -0
  94. package/dist/admin/lib/product-scopes-api.d.ts.map +1 -0
  95. package/dist/admin/lib/product-scopes-api.js +57 -0
  96. package/dist/admin/lib/product-scopes-api.js.map +1 -0
  97. package/dist/admin/lib/product-url-keys-api.d.ts +23 -0
  98. package/dist/admin/lib/product-url-keys-api.d.ts.map +1 -0
  99. package/dist/admin/lib/product-url-keys-api.js +61 -0
  100. package/dist/admin/lib/product-url-keys-api.js.map +1 -0
  101. package/dist/admin/lib/resolve-product-selection.d.ts +29 -1
  102. package/dist/admin/lib/resolve-product-selection.d.ts.map +1 -1
  103. package/dist/admin/lib/resolve-product-selection.js +42 -6
  104. package/dist/admin/lib/resolve-product-selection.js.map +1 -1
  105. package/dist/admin/lib/scope-overview.d.ts +73 -0
  106. package/dist/admin/lib/scope-overview.d.ts.map +1 -0
  107. package/dist/admin/lib/scope-overview.js +178 -0
  108. package/dist/admin/lib/scope-overview.js.map +1 -0
  109. package/dist/admin/lib/scoped-editor-store.d.ts +81 -0
  110. package/dist/admin/lib/scoped-editor-store.d.ts.map +1 -0
  111. package/dist/admin/lib/scoped-editor-store.js +198 -0
  112. package/dist/admin/lib/scoped-editor-store.js.map +1 -0
  113. package/dist/admin/lib/scoped-values-api.d.ts +14 -0
  114. package/dist/admin/lib/scoped-values-api.d.ts.map +1 -0
  115. package/dist/admin/lib/scoped-values-api.js +55 -0
  116. package/dist/admin/lib/scoped-values-api.js.map +1 -0
  117. package/dist/admin/pages/AttributesManager.d.ts.map +1 -1
  118. package/dist/admin/pages/AttributesManager.js +186 -28
  119. package/dist/admin/pages/AttributesManager.js.map +1 -1
  120. package/dist/admin/pages/BulkOperationDetailPage.d.ts.map +1 -1
  121. package/dist/admin/pages/BulkOperationDetailPage.js +4 -19
  122. package/dist/admin/pages/BulkOperationDetailPage.js.map +1 -1
  123. package/dist/admin/pages/ProductContentPage.d.ts +27 -0
  124. package/dist/admin/pages/ProductContentPage.d.ts.map +1 -0
  125. package/dist/admin/pages/ProductContentPage.js +161 -0
  126. package/dist/admin/pages/ProductContentPage.js.map +1 -0
  127. package/dist/admin/pages/ProductCreateForm.d.ts +3 -0
  128. package/dist/admin/pages/ProductCreateForm.d.ts.map +1 -0
  129. package/dist/admin/pages/ProductCreateForm.js +87 -0
  130. package/dist/admin/pages/ProductCreateForm.js.map +1 -0
  131. package/dist/admin/pages/ProductEditor.d.ts +0 -4
  132. package/dist/admin/pages/ProductEditor.d.ts.map +1 -1
  133. package/dist/admin/pages/ProductEditor.js +878 -627
  134. package/dist/admin/pages/ProductEditor.js.map +1 -1
  135. package/dist/admin/pages/ProductsList.d.ts +12 -0
  136. package/dist/admin/pages/ProductsList.d.ts.map +1 -1
  137. package/dist/admin/pages/ProductsList.js +111 -54
  138. package/dist/admin/pages/ProductsList.js.map +1 -1
  139. package/dist/backend/admin-search-provider.d.ts +3 -2
  140. package/dist/backend/admin-search-provider.d.ts.map +1 -1
  141. package/dist/backend/admin-search-provider.js +2 -3
  142. package/dist/backend/admin-search-provider.js.map +1 -1
  143. package/dist/backend/commands/attribute-commands.d.ts +4 -3
  144. package/dist/backend/commands/attribute-commands.d.ts.map +1 -1
  145. package/dist/backend/commands/attribute-commands.js +82 -21
  146. package/dist/backend/commands/attribute-commands.js.map +1 -1
  147. package/dist/backend/commands/product-content-commands.d.ts +31 -0
  148. package/dist/backend/commands/product-content-commands.d.ts.map +1 -0
  149. package/dist/backend/commands/product-content-commands.js +70 -0
  150. package/dist/backend/commands/product-content-commands.js.map +1 -0
  151. package/dist/backend/commands/scoped-values.commands.d.ts +95 -0
  152. package/dist/backend/commands/scoped-values.commands.d.ts.map +1 -0
  153. package/dist/backend/commands/scoped-values.commands.js +235 -0
  154. package/dist/backend/commands/scoped-values.commands.js.map +1 -0
  155. package/dist/backend/demo/reset.d.ts.map +1 -1
  156. package/dist/backend/demo/reset.js +2 -1
  157. package/dist/backend/demo/reset.js.map +1 -1
  158. package/dist/backend/demo/rows.d.ts +25 -0
  159. package/dist/backend/demo/rows.d.ts.map +1 -1
  160. package/dist/backend/demo/rows.js +35 -12
  161. package/dist/backend/demo/rows.js.map +1 -1
  162. package/dist/backend/demo/seed.d.ts +2 -1
  163. package/dist/backend/demo/seed.d.ts.map +1 -1
  164. package/dist/backend/demo/seed.js +22 -8
  165. package/dist/backend/demo/seed.js.map +1 -1
  166. package/dist/backend/entities/bulk-operation.entity.d.ts +10 -0
  167. package/dist/backend/entities/bulk-operation.entity.d.ts.map +1 -1
  168. package/dist/backend/entities/bulk-operation.entity.js.map +1 -1
  169. package/dist/backend/entities/gallery-item-scope-override.entity.d.ts +30 -0
  170. package/dist/backend/entities/gallery-item-scope-override.entity.d.ts.map +1 -0
  171. package/dist/backend/entities/gallery-item-scope-override.entity.js +80 -0
  172. package/dist/backend/entities/gallery-item-scope-override.entity.js.map +1 -0
  173. package/dist/backend/entities/gallery-item.entity.d.ts +9 -1
  174. package/dist/backend/entities/gallery-item.entity.d.ts.map +1 -1
  175. package/dist/backend/entities/gallery-item.entity.js +16 -0
  176. package/dist/backend/entities/gallery-item.entity.js.map +1 -1
  177. package/dist/backend/entities/gallery-role-scope-override.entity.d.ts +28 -0
  178. package/dist/backend/entities/gallery-role-scope-override.entity.d.ts.map +1 -0
  179. package/dist/backend/entities/gallery-role-scope-override.entity.js +75 -0
  180. package/dist/backend/entities/gallery-role-scope-override.entity.js.map +1 -0
  181. package/dist/backend/entities/product-attachment-scope-override.entity.d.ts +30 -0
  182. package/dist/backend/entities/product-attachment-scope-override.entity.d.ts.map +1 -0
  183. package/dist/backend/entities/product-attachment-scope-override.entity.js +80 -0
  184. package/dist/backend/entities/product-attachment-scope-override.entity.js.map +1 -0
  185. package/dist/backend/entities/product-attachment.entity.d.ts +6 -1
  186. package/dist/backend/entities/product-attachment.entity.d.ts.map +1 -1
  187. package/dist/backend/entities/product-attachment.entity.js +9 -0
  188. package/dist/backend/entities/product-attachment.entity.js.map +1 -1
  189. package/dist/backend/entities/product-attribute.entity.d.ts +5 -9
  190. package/dist/backend/entities/product-attribute.entity.d.ts.map +1 -1
  191. package/dist/backend/entities/product-attribute.entity.js +5 -13
  192. package/dist/backend/entities/product-attribute.entity.js.map +1 -1
  193. package/dist/backend/entities/product-channel-language-scope.entity.d.ts +23 -0
  194. package/dist/backend/entities/product-channel-language-scope.entity.d.ts.map +1 -0
  195. package/dist/backend/entities/product-channel-language-scope.entity.js +61 -0
  196. package/dist/backend/entities/product-channel-language-scope.entity.js.map +1 -0
  197. package/dist/backend/entities/product-channel-scope.entity.d.ts +47 -0
  198. package/dist/backend/entities/product-channel-scope.entity.d.ts.map +1 -0
  199. package/dist/backend/entities/product-channel-scope.entity.js +113 -0
  200. package/dist/backend/entities/product-channel-scope.entity.js.map +1 -0
  201. package/dist/backend/entities/product-content-value.entity.d.ts +39 -0
  202. package/dist/backend/entities/product-content-value.entity.d.ts.map +1 -0
  203. package/dist/backend/entities/product-content-value.entity.js +81 -0
  204. package/dist/backend/entities/product-content-value.entity.js.map +1 -0
  205. package/dist/backend/entities/product-packaging-unit-scope-override.entity.d.ts +30 -0
  206. package/dist/backend/entities/product-packaging-unit-scope-override.entity.d.ts.map +1 -0
  207. package/dist/backend/entities/product-packaging-unit-scope-override.entity.js +80 -0
  208. package/dist/backend/entities/product-packaging-unit-scope-override.entity.js.map +1 -0
  209. package/dist/backend/entities/product-url-key.entity.d.ts +27 -0
  210. package/dist/backend/entities/product-url-key.entity.d.ts.map +1 -0
  211. package/dist/backend/entities/product-url-key.entity.js +70 -0
  212. package/dist/backend/entities/product-url-key.entity.js.map +1 -0
  213. package/dist/backend/entities/product-url-redirect.entity.d.ts +18 -0
  214. package/dist/backend/entities/product-url-redirect.entity.d.ts.map +1 -0
  215. package/dist/backend/entities/product-url-redirect.entity.js +57 -0
  216. package/dist/backend/entities/product-url-redirect.entity.js.map +1 -0
  217. package/dist/backend/entities/product-variant.entity.d.ts +8 -1
  218. package/dist/backend/entities/product-variant.entity.d.ts.map +1 -1
  219. package/dist/backend/entities/product-variant.entity.js +13 -2
  220. package/dist/backend/entities/product-variant.entity.js.map +1 -1
  221. package/dist/backend/entities/product.entity.d.ts +48 -16
  222. package/dist/backend/entities/product.entity.d.ts.map +1 -1
  223. package/dist/backend/entities/product.entity.js +65 -35
  224. package/dist/backend/entities/product.entity.js.map +1 -1
  225. package/dist/backend/index.d.ts +29 -2
  226. package/dist/backend/index.d.ts.map +1 -1
  227. package/dist/backend/index.js +311 -29
  228. package/dist/backend/index.js.map +1 -1
  229. package/dist/backend/plugin.d.ts +79 -8
  230. package/dist/backend/plugin.d.ts.map +1 -1
  231. package/dist/backend/plugin.js +98 -17
  232. package/dist/backend/plugin.js.map +1 -1
  233. package/dist/backend/prompt-tools.d.ts +11 -0
  234. package/dist/backend/prompt-tools.d.ts.map +1 -1
  235. package/dist/backend/prompt-tools.js +124 -9
  236. package/dist/backend/prompt-tools.js.map +1 -1
  237. package/dist/backend/routes.admin.d.ts +42 -14
  238. package/dist/backend/routes.admin.d.ts.map +1 -1
  239. package/dist/backend/routes.admin.js +214 -134
  240. package/dist/backend/routes.admin.js.map +1 -1
  241. package/dist/backend/routes.admin.url-keys.d.ts +23 -0
  242. package/dist/backend/routes.admin.url-keys.d.ts.map +1 -0
  243. package/dist/backend/routes.admin.url-keys.js +14 -0
  244. package/dist/backend/routes.admin.url-keys.js.map +1 -0
  245. package/dist/backend/routes.api-key.d.ts.map +1 -1
  246. package/dist/backend/routes.api-key.js +18 -3
  247. package/dist/backend/routes.api-key.js.map +1 -1
  248. package/dist/backend/routes.external.d.ts.map +1 -1
  249. package/dist/backend/routes.external.js +6 -1
  250. package/dist/backend/routes.external.js.map +1 -1
  251. package/dist/backend/routes.public.d.ts +31 -7
  252. package/dist/backend/routes.public.d.ts.map +1 -1
  253. package/dist/backend/routes.public.js +114 -33
  254. package/dist/backend/routes.public.js.map +1 -1
  255. package/dist/backend/routes.public.url-keys.d.ts +26 -0
  256. package/dist/backend/routes.public.url-keys.d.ts.map +1 -0
  257. package/dist/backend/routes.public.url-keys.js +17 -0
  258. package/dist/backend/routes.public.url-keys.js.map +1 -0
  259. package/dist/backend/services/asset-references.d.ts +12 -1
  260. package/dist/backend/services/asset-references.d.ts.map +1 -1
  261. package/dist/backend/services/asset-references.js +85 -32
  262. package/dist/backend/services/asset-references.js.map +1 -1
  263. package/dist/backend/services/attachment-packaging-scopes.d.ts +61 -0
  264. package/dist/backend/services/attachment-packaging-scopes.d.ts.map +1 -0
  265. package/dist/backend/services/attachment-packaging-scopes.js +98 -0
  266. package/dist/backend/services/attachment-packaging-scopes.js.map +1 -0
  267. package/dist/backend/services/attachment.service.d.ts +8 -1
  268. package/dist/backend/services/attachment.service.d.ts.map +1 -1
  269. package/dist/backend/services/attachment.service.js +105 -21
  270. package/dist/backend/services/attachment.service.js.map +1 -1
  271. package/dist/backend/services/attribute-filter-match.d.ts +14 -0
  272. package/dist/backend/services/attribute-filter-match.d.ts.map +1 -0
  273. package/dist/backend/services/attribute-filter-match.js +19 -0
  274. package/dist/backend/services/attribute-filter-match.js.map +1 -0
  275. package/dist/backend/services/attribute-scope-preview.d.ts +48 -0
  276. package/dist/backend/services/attribute-scope-preview.d.ts.map +1 -0
  277. package/dist/backend/services/attribute-scope-preview.js +76 -0
  278. package/dist/backend/services/attribute-scope-preview.js.map +1 -0
  279. package/dist/backend/services/attribute-set.service.d.ts +10 -1
  280. package/dist/backend/services/attribute-set.service.d.ts.map +1 -1
  281. package/dist/backend/services/attribute-set.service.js +30 -4
  282. package/dist/backend/services/attribute-set.service.js.map +1 -1
  283. package/dist/backend/services/attribute-type-mapping.d.ts +2 -2
  284. package/dist/backend/services/attribute-type-mapping.d.ts.map +1 -1
  285. package/dist/backend/services/attribute-type-mapping.js +6 -0
  286. package/dist/backend/services/attribute-type-mapping.js.map +1 -1
  287. package/dist/backend/services/attribute-usage.d.ts +31 -0
  288. package/dist/backend/services/attribute-usage.d.ts.map +1 -0
  289. package/dist/backend/services/attribute-usage.js +29 -0
  290. package/dist/backend/services/attribute-usage.js.map +1 -0
  291. package/dist/backend/services/bulk-operation.service.d.ts +36 -0
  292. package/dist/backend/services/bulk-operation.service.d.ts.map +1 -1
  293. package/dist/backend/services/bulk-operation.service.js +210 -37
  294. package/dist/backend/services/bulk-operation.service.js.map +1 -1
  295. package/dist/backend/services/bundle.service.d.ts +9 -1
  296. package/dist/backend/services/bundle.service.d.ts.map +1 -1
  297. package/dist/backend/services/bundle.service.js +31 -3
  298. package/dist/backend/services/bundle.service.js.map +1 -1
  299. package/dist/backend/services/catalog-admin-search.service.d.ts +4 -3
  300. package/dist/backend/services/catalog-admin-search.service.d.ts.map +1 -1
  301. package/dist/backend/services/catalog-admin-search.service.js +7 -7
  302. package/dist/backend/services/catalog-admin-search.service.js.map +1 -1
  303. package/dist/backend/services/catalog-admin.service.d.ts +171 -27
  304. package/dist/backend/services/catalog-admin.service.d.ts.map +1 -1
  305. package/dist/backend/services/catalog-admin.service.js +634 -315
  306. package/dist/backend/services/catalog-admin.service.js.map +1 -1
  307. package/dist/backend/services/catalog-attribute-read.service.d.ts +14 -0
  308. package/dist/backend/services/catalog-attribute-read.service.d.ts.map +1 -1
  309. package/dist/backend/services/catalog-attribute-read.service.js +7 -19
  310. package/dist/backend/services/catalog-attribute-read.service.js.map +1 -1
  311. package/dist/backend/services/catalog-bulk-import.service.d.ts +72 -3
  312. package/dist/backend/services/catalog-bulk-import.service.d.ts.map +1 -1
  313. package/dist/backend/services/catalog-bulk-import.service.js +212 -38
  314. package/dist/backend/services/catalog-bulk-import.service.js.map +1 -1
  315. package/dist/backend/services/catalog-bulk-update.service.d.ts +35 -5
  316. package/dist/backend/services/catalog-bulk-update.service.d.ts.map +1 -1
  317. package/dist/backend/services/catalog-bulk-update.service.js +123 -14
  318. package/dist/backend/services/catalog-bulk-update.service.js.map +1 -1
  319. package/dist/backend/services/catalog-org-price-decorator.d.ts +12 -25
  320. package/dist/backend/services/catalog-org-price-decorator.d.ts.map +1 -1
  321. package/dist/backend/services/catalog-org-price-decorator.js +48 -13
  322. package/dist/backend/services/catalog-org-price-decorator.js.map +1 -1
  323. package/dist/backend/services/catalog-product-filter.service.d.ts +16 -2
  324. package/dist/backend/services/catalog-product-filter.service.d.ts.map +1 -1
  325. package/dist/backend/services/catalog-product-filter.service.js +80 -3
  326. package/dist/backend/services/catalog-product-filter.service.js.map +1 -1
  327. package/dist/backend/services/catalog-product-read.service.d.ts +11 -1
  328. package/dist/backend/services/catalog-product-read.service.d.ts.map +1 -1
  329. package/dist/backend/services/catalog-product-read.service.js +40 -23
  330. package/dist/backend/services/catalog-product-read.service.js.map +1 -1
  331. package/dist/backend/services/catalog-query.service.d.ts +170 -42
  332. package/dist/backend/services/catalog-query.service.d.ts.map +1 -1
  333. package/dist/backend/services/catalog-query.service.js +797 -430
  334. package/dist/backend/services/catalog-query.service.js.map +1 -1
  335. package/dist/backend/services/catalog-quick-search.service.d.ts +18 -2
  336. package/dist/backend/services/catalog-quick-search.service.d.ts.map +1 -1
  337. package/dist/backend/services/catalog-quick-search.service.js +53 -21
  338. package/dist/backend/services/catalog-quick-search.service.js.map +1 -1
  339. package/dist/backend/services/catalog-write-ports.d.ts +16 -1
  340. package/dist/backend/services/catalog-write-ports.d.ts.map +1 -1
  341. package/dist/backend/services/catalog-write-ports.js +18 -0
  342. package/dist/backend/services/catalog-write-ports.js.map +1 -1
  343. package/dist/backend/services/category-admin.service.d.ts +12 -1
  344. package/dist/backend/services/category-admin.service.d.ts.map +1 -1
  345. package/dist/backend/services/category-admin.service.js +32 -3
  346. package/dist/backend/services/category-admin.service.js.map +1 -1
  347. package/dist/backend/services/channel-url-facts.d.ts +17 -0
  348. package/dist/backend/services/channel-url-facts.d.ts.map +1 -0
  349. package/dist/backend/services/channel-url-facts.js +20 -0
  350. package/dist/backend/services/channel-url-facts.js.map +1 -0
  351. package/dist/backend/services/content-attribute-rules.d.ts +49 -0
  352. package/dist/backend/services/content-attribute-rules.d.ts.map +1 -0
  353. package/dist/backend/services/content-attribute-rules.js +89 -0
  354. package/dist/backend/services/content-attribute-rules.js.map +1 -0
  355. package/dist/backend/services/effective-value.sql.d.ts +42 -0
  356. package/dist/backend/services/effective-value.sql.d.ts.map +1 -0
  357. package/dist/backend/services/effective-value.sql.js +61 -0
  358. package/dist/backend/services/effective-value.sql.js.map +1 -0
  359. package/dist/backend/services/gallery-scopes.d.ts +63 -0
  360. package/dist/backend/services/gallery-scopes.d.ts.map +1 -0
  361. package/dist/backend/services/gallery-scopes.js +158 -0
  362. package/dist/backend/services/gallery-scopes.js.map +1 -0
  363. package/dist/backend/services/gallery.service.d.ts +32 -4
  364. package/dist/backend/services/gallery.service.d.ts.map +1 -1
  365. package/dist/backend/services/gallery.service.js +182 -44
  366. package/dist/backend/services/gallery.service.js.map +1 -1
  367. package/dist/backend/services/grouped.service.d.ts.map +1 -1
  368. package/dist/backend/services/grouped.service.js +13 -1
  369. package/dist/backend/services/grouped.service.js.map +1 -1
  370. package/dist/backend/services/linkable-asset.d.ts +21 -0
  371. package/dist/backend/services/linkable-asset.d.ts.map +1 -0
  372. package/dist/backend/services/linkable-asset.js +31 -0
  373. package/dist/backend/services/linkable-asset.js.map +1 -0
  374. package/dist/backend/services/packaging-unit.service.d.ts.map +1 -1
  375. package/dist/backend/services/packaging-unit.service.js +73 -47
  376. package/dist/backend/services/packaging-unit.service.js.map +1 -1
  377. package/dist/backend/services/page-builder-content.d.ts +64 -0
  378. package/dist/backend/services/page-builder-content.d.ts.map +1 -0
  379. package/dist/backend/services/page-builder-content.js +113 -0
  380. package/dist/backend/services/page-builder-content.js.map +1 -0
  381. package/dist/backend/services/primary-asset-url.d.ts +12 -1
  382. package/dist/backend/services/primary-asset-url.d.ts.map +1 -1
  383. package/dist/backend/services/primary-asset-url.js +50 -14
  384. package/dist/backend/services/primary-asset-url.js.map +1 -1
  385. package/dist/backend/services/product-availability.service.d.ts +92 -0
  386. package/dist/backend/services/product-availability.service.d.ts.map +1 -0
  387. package/dist/backend/services/product-availability.service.js +260 -0
  388. package/dist/backend/services/product-availability.service.js.map +1 -0
  389. package/dist/backend/services/product-availability.sql.d.ts +71 -0
  390. package/dist/backend/services/product-availability.sql.d.ts.map +1 -0
  391. package/dist/backend/services/product-availability.sql.js +77 -0
  392. package/dist/backend/services/product-availability.sql.js.map +1 -0
  393. package/dist/backend/services/product-content.service.d.ts +62 -0
  394. package/dist/backend/services/product-content.service.d.ts.map +1 -0
  395. package/dist/backend/services/product-content.service.js +122 -0
  396. package/dist/backend/services/product-content.service.js.map +1 -0
  397. package/dist/backend/services/product-editor-preferences.service.d.ts +6 -0
  398. package/dist/backend/services/product-editor-preferences.service.d.ts.map +1 -1
  399. package/dist/backend/services/product-editor-preferences.service.js +12 -0
  400. package/dist/backend/services/product-editor-preferences.service.js.map +1 -1
  401. package/dist/backend/services/product-global-field-rules.d.ts +39 -0
  402. package/dist/backend/services/product-global-field-rules.d.ts.map +1 -0
  403. package/dist/backend/services/product-global-field-rules.js +84 -0
  404. package/dist/backend/services/product-global-field-rules.js.map +1 -0
  405. package/dist/backend/services/product-link.service.d.ts +10 -9
  406. package/dist/backend/services/product-link.service.d.ts.map +1 -1
  407. package/dist/backend/services/product-link.service.js +44 -36
  408. package/dist/backend/services/product-link.service.js.map +1 -1
  409. package/dist/backend/services/product-list-view-service.d.ts.map +1 -1
  410. package/dist/backend/services/product-list-view-service.js +5 -8
  411. package/dist/backend/services/product-list-view-service.js.map +1 -1
  412. package/dist/backend/services/product-page-revalidation.d.ts +60 -0
  413. package/dist/backend/services/product-page-revalidation.d.ts.map +1 -0
  414. package/dist/backend/services/product-page-revalidation.js +165 -0
  415. package/dist/backend/services/product-page-revalidation.js.map +1 -0
  416. package/dist/backend/services/product-scopes.service.d.ts +221 -0
  417. package/dist/backend/services/product-scopes.service.d.ts.map +1 -0
  418. package/dist/backend/services/product-scopes.service.js +692 -0
  419. package/dist/backend/services/product-scopes.service.js.map +1 -0
  420. package/dist/backend/services/product-summary-text.d.ts +8 -0
  421. package/dist/backend/services/product-summary-text.d.ts.map +1 -0
  422. package/dist/backend/services/product-summary-text.js +8 -0
  423. package/dist/backend/services/product-summary-text.js.map +1 -0
  424. package/dist/backend/services/product-value-resolver.service.d.ts +2 -2
  425. package/dist/backend/services/product-value-resolver.service.d.ts.map +1 -1
  426. package/dist/backend/services/product-value-resolver.service.js +4 -7
  427. package/dist/backend/services/product-value-resolver.service.js.map +1 -1
  428. package/dist/backend/services/publication-window-sweep.d.ts +131 -0
  429. package/dist/backend/services/publication-window-sweep.d.ts.map +1 -0
  430. package/dist/backend/services/publication-window-sweep.js +204 -0
  431. package/dist/backend/services/publication-window-sweep.js.map +1 -0
  432. package/dist/backend/services/scheduled-work-probe.d.ts +34 -0
  433. package/dist/backend/services/scheduled-work-probe.d.ts.map +1 -0
  434. package/dist/backend/services/scheduled-work-probe.js +30 -0
  435. package/dist/backend/services/scheduled-work-probe.js.map +1 -0
  436. package/dist/backend/services/scope-completeness.d.ts +107 -0
  437. package/dist/backend/services/scope-completeness.d.ts.map +1 -0
  438. package/dist/backend/services/scope-completeness.js +173 -0
  439. package/dist/backend/services/scope-completeness.js.map +1 -0
  440. package/dist/backend/services/scope-overview.service.d.ts +112 -0
  441. package/dist/backend/services/scope-overview.service.d.ts.map +1 -0
  442. package/dist/backend/services/scope-overview.service.js +329 -0
  443. package/dist/backend/services/scope-overview.service.js.map +1 -0
  444. package/dist/backend/services/scoped-store-adapters.d.ts +58 -0
  445. package/dist/backend/services/scoped-store-adapters.d.ts.map +1 -0
  446. package/dist/backend/services/scoped-store-adapters.js +92 -0
  447. package/dist/backend/services/scoped-store-adapters.js.map +1 -0
  448. package/dist/backend/services/scoped-values-global-only.d.ts +36 -0
  449. package/dist/backend/services/scoped-values-global-only.d.ts.map +1 -0
  450. package/dist/backend/services/scoped-values-global-only.js +92 -0
  451. package/dist/backend/services/scoped-values-global-only.js.map +1 -0
  452. package/dist/backend/services/scoped-values-import.d.ts +86 -0
  453. package/dist/backend/services/scoped-values-import.d.ts.map +1 -0
  454. package/dist/backend/services/scoped-values-import.js +320 -0
  455. package/dist/backend/services/scoped-values-import.js.map +1 -0
  456. package/dist/backend/services/scoped-values-read.service.d.ts +56 -0
  457. package/dist/backend/services/scoped-values-read.service.d.ts.map +1 -0
  458. package/dist/backend/services/scoped-values-read.service.js +289 -0
  459. package/dist/backend/services/scoped-values-read.service.js.map +1 -0
  460. package/dist/backend/services/scoped-values-save.service.d.ts +79 -0
  461. package/dist/backend/services/scoped-values-save.service.d.ts.map +1 -0
  462. package/dist/backend/services/scoped-values-save.service.js +675 -0
  463. package/dist/backend/services/scoped-values-save.service.js.map +1 -0
  464. package/dist/backend/services/scoped-values-state.d.ts +94 -0
  465. package/dist/backend/services/scoped-values-state.d.ts.map +1 -0
  466. package/dist/backend/services/scoped-values-state.js +159 -0
  467. package/dist/backend/services/scoped-values-state.js.map +1 -0
  468. package/dist/backend/services/scoped-values.service.d.ts +36 -0
  469. package/dist/backend/services/scoped-values.service.d.ts.map +1 -0
  470. package/dist/backend/services/scoped-values.service.js +92 -0
  471. package/dist/backend/services/scoped-values.service.js.map +1 -0
  472. package/dist/backend/services/sql-id-arrays.d.ts +16 -0
  473. package/dist/backend/services/sql-id-arrays.d.ts.map +1 -0
  474. package/dist/backend/services/sql-id-arrays.js +24 -0
  475. package/dist/backend/services/sql-id-arrays.js.map +1 -0
  476. package/dist/backend/services/storefront-value-overrides.d.ts +7 -8
  477. package/dist/backend/services/storefront-value-overrides.d.ts.map +1 -1
  478. package/dist/backend/services/storefront-value-overrides.js +11 -14
  479. package/dist/backend/services/storefront-value-overrides.js.map +1 -1
  480. package/dist/backend/services/url-key-resolution.service.d.ts +70 -0
  481. package/dist/backend/services/url-key-resolution.service.d.ts.map +1 -0
  482. package/dist/backend/services/url-key-resolution.service.js +179 -0
  483. package/dist/backend/services/url-key-resolution.service.js.map +1 -0
  484. package/dist/backend/services/url-key.service.d.ts +123 -0
  485. package/dist/backend/services/url-key.service.d.ts.map +1 -0
  486. package/dist/backend/services/url-key.service.js +566 -0
  487. package/dist/backend/services/url-key.service.js.map +1 -0
  488. package/dist/manifest.d.ts +9 -1
  489. package/dist/manifest.d.ts.map +1 -1
  490. package/dist/manifest.js +204 -10
  491. package/dist/manifest.js.map +1 -1
  492. package/dist/migrations/20261022T035133_catalog_product_scopes.d.ts +28 -0
  493. package/dist/migrations/20261022T035133_catalog_product_scopes.d.ts.map +1 -0
  494. package/dist/migrations/20261022T035133_catalog_product_scopes.js +92 -0
  495. package/dist/migrations/20261022T035133_catalog_product_scopes.js.map +1 -0
  496. package/dist/migrations/20261022T054223_catalog_product_url_keys.d.ts +32 -0
  497. package/dist/migrations/20261022T054223_catalog_product_url_keys.d.ts.map +1 -0
  498. package/dist/migrations/20261022T054223_catalog_product_url_keys.js +81 -0
  499. package/dist/migrations/20261022T054223_catalog_product_url_keys.js.map +1 -0
  500. package/dist/migrations/20261025T222634_catalog_product_status_drop_draft.d.ts +34 -0
  501. package/dist/migrations/20261025T222634_catalog_product_status_drop_draft.d.ts.map +1 -0
  502. package/dist/migrations/20261025T222634_catalog_product_status_drop_draft.js +57 -0
  503. package/dist/migrations/20261025T222634_catalog_product_status_drop_draft.js.map +1 -0
  504. package/dist/migrations/20261026T033453_catalog_product_media_scopes.d.ts +26 -0
  505. package/dist/migrations/20261026T033453_catalog_product_media_scopes.d.ts.map +1 -0
  506. package/dist/migrations/20261026T033453_catalog_product_media_scopes.js +54 -0
  507. package/dist/migrations/20261026T033453_catalog_product_media_scopes.js.map +1 -0
  508. package/dist/migrations/20261026T084533_catalog_attachment_packaging_translations.d.ts +27 -0
  509. package/dist/migrations/20261026T084533_catalog_attachment_packaging_translations.d.ts.map +1 -0
  510. package/dist/migrations/20261026T084533_catalog_attachment_packaging_translations.js +45 -0
  511. package/dist/migrations/20261026T084533_catalog_attachment_packaging_translations.js.map +1 -0
  512. package/dist/migrations/20261030T113855_catalog_scope_model_texts.d.ts +36 -0
  513. package/dist/migrations/20261030T113855_catalog_scope_model_texts.d.ts.map +1 -0
  514. package/dist/migrations/20261030T113855_catalog_scope_model_texts.js +225 -0
  515. package/dist/migrations/20261030T113855_catalog_scope_model_texts.js.map +1 -0
  516. package/dist/migrations/20261030T113859_catalog_scope_model_order_rules.d.ts +18 -0
  517. package/dist/migrations/20261030T113859_catalog_scope_model_order_rules.d.ts.map +1 -0
  518. package/dist/migrations/20261030T113859_catalog_scope_model_order_rules.js +39 -0
  519. package/dist/migrations/20261030T113859_catalog_scope_model_order_rules.js.map +1 -0
  520. package/dist/migrations/20261030T113904_catalog_scope_model_url_keys.d.ts +6 -0
  521. package/dist/migrations/20261030T113904_catalog_scope_model_url_keys.d.ts.map +1 -0
  522. package/dist/migrations/20261030T113904_catalog_scope_model_url_keys.js +119 -0
  523. package/dist/migrations/20261030T113904_catalog_scope_model_url_keys.js.map +1 -0
  524. package/dist/migrations/20261030T113908_catalog_scope_model_media.d.ts +6 -0
  525. package/dist/migrations/20261030T113908_catalog_scope_model_media.d.ts.map +1 -0
  526. package/dist/migrations/20261030T113908_catalog_scope_model_media.js +185 -0
  527. package/dist/migrations/20261030T113908_catalog_scope_model_media.js.map +1 -0
  528. package/dist/migrations/20261104T121504_catalog_product_content_values.d.ts +36 -0
  529. package/dist/migrations/20261104T121504_catalog_product_content_values.d.ts.map +1 -0
  530. package/dist/migrations/20261104T121504_catalog_product_content_values.js +53 -0
  531. package/dist/migrations/20261104T121504_catalog_product_content_values.js.map +1 -0
  532. package/dist/migrations/20261107T093126_catalog_sku_unique_among_live.d.ts +33 -0
  533. package/dist/migrations/20261107T093126_catalog_sku_unique_among_live.d.ts.map +1 -0
  534. package/dist/migrations/20261107T093126_catalog_sku_unique_among_live.js +58 -0
  535. package/dist/migrations/20261107T093126_catalog_sku_unique_among_live.js.map +1 -0
  536. package/dist/migrations/20261107T120008_catalog_product_created_at_milliseconds.d.ts +36 -0
  537. package/dist/migrations/20261107T120008_catalog_product_created_at_milliseconds.d.ts.map +1 -0
  538. package/dist/migrations/20261107T120008_catalog_product_created_at_milliseconds.js +40 -0
  539. package/dist/migrations/20261107T120008_catalog_product_created_at_milliseconds.js.map +1 -0
  540. package/dist/migrations/index.d.ts +13 -1
  541. package/dist/migrations/index.d.ts.map +1 -1
  542. package/dist/migrations/index.js +25 -1
  543. package/dist/migrations/index.js.map +1 -1
  544. package/docs/catalog/attachments.md +60 -8
  545. package/docs/catalog/attribute-sets.md +2 -2
  546. package/docs/catalog/attributes.md +68 -8
  547. package/docs/catalog/category-content.md +3 -0
  548. package/docs/catalog/composite-products.md +2 -2
  549. package/docs/catalog/editing-a-product-at-a-scope.md +95 -0
  550. package/docs/catalog/gallery-and-labels.md +68 -8
  551. package/docs/catalog/packaging-units.md +56 -10
  552. package/docs/catalog/per-channel-per-language-overrides.md +68 -237
  553. package/docs/catalog/product-content.md +180 -0
  554. package/docs/catalog/product-links.md +2 -2
  555. package/docs/catalog/url-keys-and-redirects.md +142 -0
  556. package/docs/catalog.md +241 -20
  557. package/i18n/en.json +977 -123
  558. package/i18n/pl.json +976 -122
  559. package/package.json +12 -12
  560. package/dist/admin/components/ProductScopeEditor.d.ts +0 -94
  561. package/dist/admin/components/ProductScopeEditor.d.ts.map +0 -1
  562. package/dist/admin/components/ProductScopeEditor.js +0 -395
  563. package/dist/admin/components/ProductScopeEditor.js.map +0 -1
  564. package/dist/backend/services/product-overrides.service.d.ts +0 -77
  565. package/dist/backend/services/product-overrides.service.d.ts.map +0 -1
  566. package/dist/backend/services/product-overrides.service.js +0 -204
  567. package/dist/backend/services/product-overrides.service.js.map +0 -1
  568. package/dist/backend/services/product-scope-context.service.d.ts +0 -36
  569. package/dist/backend/services/product-scope-context.service.d.ts.map +0 -1
  570. package/dist/backend/services/product-scope-context.service.js +0 -106
  571. package/dist/backend/services/product-scope-context.service.js.map +0 -1
@@ -12,31 +12,31 @@ import { ProductPackagingUnit } from '../entities/product-packaging-unit.entity.
12
12
  import { BundleSlot } from '../entities/bundle-slot.entity.js';
13
13
  import { BundleSlotOption } from '../entities/bundle-slot-option.entity.js';
14
14
  import { resolvePrimaryAssetUrls } from './primary-asset-url.js';
15
+ import { effectiveGallery, loadGalleryScopes } from './gallery-scopes.js';
16
+ import { loadAttachmentsAtScope, loadPackagingUnitNamesAtScope } from './attachment-packaging-scopes.js';
15
17
  import { viewerOrganizationFor } from './viewer-organization.js';
16
- import { effectiveAttributeValues, effectiveSystemText, loadChannelOverridesByProduct, overrideLanguages, } from './storefront-value-overrides.js';
17
- import { ERROR_CODES, compareDecimal, decimalText, formatUnits, isOrderMinimumEligibleType, normaliseAmount, isPriceSort, isProductVisibleTo, listingPriceChannelContext, listingPriceMoney, } from '@endora-commerce/contracts';
18
+ import { channelUrlFactsOf } from './channel-url-facts.js';
19
+ import { effectiveAttributeValues, effectiveSystemText, loadChannelOverridesByProduct, } from './storefront-value-overrides.js';
20
+ import { availabilityCondition, } from './product-availability.sql.js';
21
+ import { effectiveAttributeSql, effectiveTextSql, } from './effective-value.sql.js';
22
+ import { availableAmong, globalScopeFields, isAvailableWith, loadChannelScopeRows, toScopeChannel, } from './product-availability.service.js';
23
+ import { uuidArrayLiteral } from './sql-id-arrays.js';
24
+ import { findCurrentKeyHolder, loadEffectiveKeys } from './url-key-resolution.service.js';
25
+ import { ANONYMOUS_PRODUCT_AUDIENCE, ERROR_CODES, compareDecimal, productDefaultPath, productPath, decimalText, formatUnits, isOrderMinimumEligibleType, effectiveOrderRules, normaliseAmount, effectiveAudience, isPriceSort, isProductVisibleTo, listingPriceChannelContext, resolveScopeLanguage, listingPriceMoney, scopeLanguageOf, isUuidShape, } from '@endora-commerce/contracts';
18
26
  import { HttpError } from '@endora-commerce/platform/http';
19
27
  import { encodeCursor, decodeCursor } from '@endora-commerce/platform/http';
20
- /** A uuid as the database spells one — anything else is a 404 or a discarded cursor, not a query. */
21
- const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
22
- /** A category id as the database spells one — anything else is a 404, not a query. */
23
- const CATEGORY_ID_RE = UUID_RE;
28
+ import { attributeFilterMatches } from './attribute-filter-match.js';
29
+ import { productSummaryText } from './product-summary-text.js';
30
+ import { resolvePageBuilderLanguage } from './page-builder-content.js';
31
+ import { contentAttributeMembers } from './product-content.service.js';
24
32
  /** The deepest ancestor chain {@link CatalogQueryService.getCategoryPageContent} walks. */
25
33
  const MAX_CATEGORY_DEPTH = 64;
26
34
  /**
27
- * Whether a Page Builder document would render anything: a block at the top
28
- * level, or in a legacy `zones` bucket. An editor that was opened and saved
29
- * untouched stores a document with neither.
35
+ * Moved to `page-builder-content.ts` by feature 172, with the rest of the Page
36
+ * Builder helpers category and product content share; re-exported here for
37
+ * its existing importers.
30
38
  */
31
- export function hasPageBuilderBlocks(tree) {
32
- if (Array.isArray(tree['content']) && tree['content'].length > 0)
33
- return true;
34
- const zones = tree['zones'];
35
- if (zones && typeof zones === 'object') {
36
- return Object.values(zones).some((zone) => Array.isArray(zone) && zone.length > 0);
37
- }
38
- return false;
39
- }
39
+ export { hasPageBuilderBlocks } from './page-builder-content.js';
40
40
  function encodeObjectCursor(value) {
41
41
  return encodeCursor(JSON.stringify(value));
42
42
  }
@@ -55,7 +55,7 @@ function isRecord(value) {
55
55
  return typeof value === 'object' && value !== null;
56
56
  }
57
57
  function isUuidText(value) {
58
- return typeof value === 'string' && UUID_RE.test(value);
58
+ return typeof value === 'string' && isUuidShape(value);
59
59
  }
60
60
  /**
61
61
  * A price a cursor carries, normalised to four places, or `null` when it is not
@@ -94,6 +94,15 @@ function cursorAmount(value) {
94
94
  * is additive.
95
95
  */
96
96
  export const PRICE_PAGE_SCAN_BUDGET_MULTIPLE = 8;
97
+ /** The seal purpose of every cursor a price-sorted listing issues (issue #497). */
98
+ export const PRICE_WALK_CURSOR_PURPOSE = 'catalog.listing.price-walk';
99
+ /**
100
+ * The seal purpose of every cursor a price-filtered listing under another sort
101
+ * issues (issue #497): its budget can stop it on a hidden product too, and that
102
+ * position names the product's id. A purpose of its own, so neither walk reads
103
+ * the other's cursor.
104
+ */
105
+ export const PRICE_RANGE_WALK_CURSOR_PURPOSE = 'catalog.listing.price-range-walk';
97
106
  function amountBound(value, side) {
98
107
  const [whole = '0', fraction = ''] = decimalText(value).split('.');
99
108
  let units = BigInt(whole) * 10000n + BigInt(fraction.slice(0, 4).padEnd(4, '0'));
@@ -125,10 +134,8 @@ function withinAmountRange(amount, range) {
125
134
  * ordering came apart in the first place.
126
135
  */
127
136
  function afterKeysetCursor(cursor, op) {
128
- if ('slug' in cursor) {
129
- return {
130
- $or: [{ slug: { [op]: cursor.slug } }, { slug: cursor.slug, id: { [op]: cursor.id } }],
131
- };
137
+ if (!('createdAt' in cursor)) {
138
+ throw new Error('afterKeysetCursor: a name cursor is the name keyset\'s own (`#keysetFor`).');
132
139
  }
133
140
  const at = new Date(cursor.createdAt);
134
141
  return { $or: [{ createdAt: { [op]: at } }, { createdAt: at, id: { [op]: cursor.id } }] };
@@ -167,31 +174,25 @@ function jsStringOfNumeric(n) {
167
174
  `else (${n})::float8::text end)`);
168
175
  }
169
176
  /**
170
- * JavaScript's `String(value)` for a `jsonb` SQL expression, as the attribute
171
- * filter needs it.
177
+ * JavaScript's `String(value)` for a **non-array** `jsonb` SQL expression, as
178
+ * the attribute filter needs it — the text one option is compared as.
172
179
  *
173
180
  * A string or a boolean is its own text, a number is
174
181
  * {@link jsStringOfNumeric}, a JSON `null` reads `'null'` and an object reads
175
- * `[object Object]`. An **array** — a multiselect — joins its elements with a
176
- * comma, each rendered the same way except that a `null` element is empty,
177
- * which is `Array.prototype.join`'s rule.
182
+ * `[object Object]`. An array is not this function's: `#attributeCondition`
183
+ * walks a multiselect's elements and renders each one here (issue #684).
178
184
  *
179
- * One kind is not reproduced: an array **nested inside** an array. JavaScript
180
- * flattens it into the join (`[[1, 2], 3]` reads `1,2,3`); here the inner array
181
- * contributes its JSON text. No attribute type stores one.
185
+ * One kind is not reproduced: an array **nested inside** a multiselect.
186
+ * JavaScript renders it as its comma-joined elements (`[1, 2]` reads `1,2`);
187
+ * here it contributes its JSON text. No attribute type stores one.
182
188
  */
183
189
  function jsStringOfJsonb(value) {
184
- const scalar = (v, nullText) => `(case jsonb_typeof(${v}) ` +
185
- `when 'null' then '${nullText}' ` +
190
+ return (`(case jsonb_typeof(${value}) ` +
191
+ `when 'null' then 'null' ` +
186
192
  `when 'object' then '[object Object]' ` +
187
193
  `when 'number' then (select ${jsStringOfNumeric('num.n')} ` +
188
- `from (select (${v} #>> '{}')::numeric as n) num) ` +
189
- `else ${v} #>> '{}' end)`;
190
- return (`(case jsonb_typeof(${value}) ` +
191
- `when 'array' then (` +
192
- `select coalesce(string_agg(${scalar('el.value', '')}, ',' order by el.position), '') ` +
193
- `from jsonb_array_elements(${value}) with ordinality as el(value, position)) ` +
194
- `else ${scalar(value, 'null')} end)`);
194
+ `from (select (${value} #>> '{}')::numeric as n) num) ` +
195
+ `else ${value} #>> '{}' end)`);
195
196
  }
196
197
  export class CatalogQueryService {
197
198
  emFactory;
@@ -204,6 +205,9 @@ export class CatalogQueryService {
204
205
  organizationDetails;
205
206
  listingPriceOrder;
206
207
  log;
208
+ cursorSeal;
209
+ seoProductMeta;
210
+ isPageBuilderPresent;
207
211
  constructor(emFactory,
208
212
  /**
209
213
  * Feature 002 US4 — optional link provider so the PDP `productDetail`
@@ -303,7 +307,26 @@ export class CatalogQueryService {
303
307
  * without changing anything else. Optional, because a fixture that never
304
308
  * binds never reaches it.
305
309
  */
306
- log) {
310
+ log,
311
+ /**
312
+ * Issue #497 — what every cursor of a price walk is sealed with. Optional
313
+ * only in the signature, like the ordering port: a price walk asked for
314
+ * without it fails loudly rather than issue a cursor a client can read.
315
+ */
316
+ cursorSeal,
317
+ /**
318
+ * Feature 163 — the product page's metadata through `seo` (R13). Optional: a
319
+ * composition without it, like `seo` off, serves the derived metadata.
320
+ */
321
+ seoProductMeta,
322
+ /**
323
+ * Feature 172 (FR-051, research R-13, owner ruling OR-8) — whether the Page
324
+ * Builder's owner is effectively present. It gates one projection only: the
325
+ * product page's `contentAttributes`. Optional only in the signature, and an
326
+ * unwired probe answers "absent", so a composition that forgets it serves no
327
+ * content rather than content the operator may have switched off.
328
+ */
329
+ isPageBuilderPresent) {
307
330
  this.emFactory = emFactory;
308
331
  this.productLinkService = productLinkService;
309
332
  this.customFieldDefinitions = customFieldDefinitions;
@@ -314,6 +337,32 @@ export class CatalogQueryService {
314
337
  this.organizationDetails = organizationDetails;
315
338
  this.listingPriceOrder = listingPriceOrder;
316
339
  this.log = log;
340
+ this.cursorSeal = cursorSeal;
341
+ this.seoProductMeta = seoProductMeta;
342
+ this.isPageBuilderPresent = isPageBuilderPresent;
343
+ }
344
+ #requireCursorSeal() {
345
+ if (!this.cursorSeal) {
346
+ throw new Error('CatalogQueryService: the cursor seal is not wired — a price walk cannot issue a cursor ' +
347
+ 'without handing the client the position its scan stopped at.');
348
+ }
349
+ return this.cursorSeal;
350
+ }
351
+ /** A price walk's cursor, sealed for `purpose`. */
352
+ #sealCursor(purpose, value) {
353
+ return this.#requireCursorSeal().seal(purpose, JSON.stringify(value));
354
+ }
355
+ /** What a cursor sealed for `purpose` holds, or `null` when it does not open or parse. */
356
+ #openCursor(purpose, cursor) {
357
+ const opened = this.#requireCursorSeal().open(purpose, cursor);
358
+ if (opened === null)
359
+ return null;
360
+ try {
361
+ return JSON.parse(opened);
362
+ }
363
+ catch {
364
+ return null;
365
+ }
317
366
  }
318
367
  #requireChannelMembership() {
319
368
  if (!this.channelMembership) {
@@ -322,6 +371,53 @@ export class CatalogQueryService {
322
371
  }
323
372
  return this.channelMembership;
324
373
  }
374
+ /**
375
+ * Feature 163 — where a read asks availability (FR-001): the request's
376
+ * resolved channel (Constitution XII), its scope language L, the audience the
377
+ * route took from the session, and one `now` for every statement and every
378
+ * page-side check of the read, so a window edge cannot fall between two of
379
+ * them.
380
+ */
381
+ #availabilityScope(ctx, now = new Date()) {
382
+ const channel = toScopeChannel(ctx.resolvedChannel);
383
+ return {
384
+ channel,
385
+ languageCode: resolveScopeLanguage(channel, ctx.preferredLanguage),
386
+ audience: ctx.audience,
387
+ now,
388
+ };
389
+ }
390
+ /** {@link availabilityCondition} for this scope — a description; the caller makes the `raw()` key. */
391
+ #availabilityNarrowing(scope) {
392
+ return availabilityCondition({
393
+ channelId: scope.channel.id,
394
+ languageCode: scope.languageCode,
395
+ channelLanguages: scope.channel.languages,
396
+ audience: scope.audience,
397
+ now: scope.now,
398
+ }, this.#requireChannelMembership());
399
+ }
400
+ /**
401
+ * The pure rule over rows already held — the defence in depth behind every
402
+ * statement that carried {@link availabilityCondition}, and the whole check
403
+ * where a read could not carry it. `membersKnown` when the statement already
404
+ * held the kernel's membership subquery.
405
+ */
406
+ #availableAmong(em, products, scope, membersKnown) {
407
+ return availableAmong(em, this.#requireChannelMembership(), products, scope, { membersKnown });
408
+ }
409
+ /**
410
+ * Feature 163 — the ids of `productIds` available to this request at (C, L),
411
+ * for a seam that holds ids and answers its own single not-found (bundle
412
+ * configuration options, FR-004).
413
+ */
414
+ async filterAvailableForRequest(productIds, ctx) {
415
+ if (productIds.length === 0)
416
+ return new Set();
417
+ const em = this.emFactory();
418
+ const products = await em.find(Product, { id: { $in: [...new Set(productIds)] } });
419
+ return this.#availableAmong(em, products, this.#availabilityScope(ctx), false);
420
+ }
325
421
  #requireAssets() {
326
422
  if (!this.assets) {
327
423
  throw new Error('CatalogQueryService: the asset read port is not wired — product images are unavailable.');
@@ -358,9 +454,11 @@ export class CatalogQueryService {
358
454
  * The chain's answer for a batch of products, keyed by product id, **for the
359
455
  * viewer in front of the page**.
360
456
  *
361
- * A non-public sales channel withholds prices (R-18), and it withholds them
362
- * *before* the resolution rather than after: the catalogue has nothing to ask
363
- * about on a channel whose prices it may not show.
457
+ * Whether the viewer is shown a price is the display-mode chain's answer,
458
+ * applied inside the resolution: a viewer whose mode is `none` gets the
459
+ * withheld arm (issue #491). The channel has no say of its own any more
460
+ * (issue #492) — a channel that hides prices until sign-in does so through
461
+ * its `pricing.unauthenticated_display_mode`.
364
462
  *
365
463
  * The organisation is the whole of this method's share of the owner's ruling
366
464
  * — an anonymous visitor sees the channel price, a signed-in buyer sees their
@@ -374,8 +472,6 @@ export class CatalogQueryService {
374
472
  context) {
375
473
  if (products.length === 0)
376
474
  return new Map();
377
- if (!(ctx.resolvedChannel.isPublic ?? true))
378
- return new Map();
379
475
  // D-287 P0 — the details call: one resolution answers both `price` and
380
476
  // `resolvedPrice` (base / sale / display mode), so the product page and the
381
477
  // home page's cards need no second, per-product resolution.
@@ -412,9 +508,9 @@ export class CatalogQueryService {
412
508
  };
413
509
  }
414
510
  /**
415
- * `ProductSummary.price` for one resolved chain answer. A product the channel
416
- * withholds prices for is absent from the map and renders `null`, and so does
417
- * the chain's `none` arm — the wire field has one spelling for "no price".
511
+ * `ProductSummary.price` for one resolved chain answer. A product absent from
512
+ * the map renders `null`, and so does the chain's `none` arm — the wire field
513
+ * has one spelling for "no price".
418
514
  */
419
515
  #summaryPrice(resolved, productId) {
420
516
  const detail = resolved.get(productId);
@@ -423,8 +519,8 @@ export class CatalogQueryService {
423
519
  /**
424
520
  * `ProductSummary.resolvedPrice` — base, sale and display mode from the same
425
521
  * resolution as `price` (D-287 P0), and the list price beside a lower buyer
426
- * price when the engine answered one (161 G14). `null` where the channel
427
- * withholds prices. One mapping for the listing cards and the product detail.
522
+ * price when the engine answered one (161 G14). `null` where the product was
523
+ * not resolved. One mapping for the listing cards and the product detail.
428
524
  */
429
525
  #summaryResolvedPrice(resolved, productId) {
430
526
  const detail = resolved.get(productId);
@@ -452,17 +548,32 @@ export class CatalogQueryService {
452
548
  * that index in that order. Writing it down is what keeps the array the same
453
549
  * array now that a page-wide `in (…)` may reach the rows by another plan.
454
550
  */
455
- async #listingCardReadsFor(em, productIds,
456
- /** The request's resolved sales channel — the override rows are read for it alone. */
457
- channelId) {
551
+ async #listingCardReadsFor(em, products,
552
+ /** The request: its resolved sales channel (override rows and keys are read for it alone) and language. */
553
+ ctx,
554
+ /**
555
+ * What a single-product caller (the product page) has already read for its one
556
+ * product: its scope rows in the channel and its keys per channel language — not
557
+ * read again (checkpoint C code review, N1).
558
+ */
559
+ preloaded) {
560
+ const channelId = ctx.resolvedChannel.id;
561
+ const productIds = products.map((p) => p.id);
458
562
  const categorySlugsByProduct = new Map();
459
563
  if (productIds.length === 0) {
460
- return { assetUrlByProduct: new Map(), categorySlugsByProduct, overridesByProduct: new Map() };
564
+ return {
565
+ assetUrlByProduct: new Map(),
566
+ categorySlugsByProduct,
567
+ overridesByProduct: new Map(),
568
+ effectiveKeyByProduct: new Map(),
569
+ minOrderQuantityByProduct: new Map(),
570
+ };
461
571
  }
462
572
  // Primary asset — for listings prefer the gallery's Thumbnail (US3),
463
573
  // then Base Image, then any first gallery item, finally the legacy
464
- // product_assets row. Resolution chain pinned by T096.
465
- const assetUrlByProduct = await resolvePrimaryAssetUrls(em, this.#requireAssets(), productIds);
574
+ // product_assets row. Resolution chain pinned by T096; run over the gallery as
575
+ // the request's (channel, language) shows it (feature 163 FR-076, feature 174).
576
+ const assetUrlByProduct = await resolvePrimaryAssetUrls(em, this.#requireAssets(), productIds, channelId, this.#availabilityScope(ctx).languageCode);
466
577
  const ids = [...productIds];
467
578
  const catRows = await em.execute(`select pc.product_id::text as product_id, c.slug
468
579
  from product_categories pc
@@ -475,7 +586,39 @@ export class CatalogQueryService {
475
586
  categorySlugsByProduct.set(row.product_id, slugs);
476
587
  }
477
588
  const overridesByProduct = await loadChannelOverridesByProduct(em, ids, channelId);
478
- return { assetUrlByProduct, categorySlugsByProduct, overridesByProduct };
589
+ const effectiveKeyByProduct = preloaded
590
+ ? this.#keysAtScopeLanguage(products, preloaded.keysByLanguage, ctx)
591
+ : await this.#effectiveKeysAt(em, products, ctx);
592
+ // Feature 163 (FR-100) — the channel's minimum, read page-wide with its scope rows.
593
+ const scopeRows = preloaded?.scopeRows ?? (await loadChannelScopeRows(em, ids, channelId));
594
+ const minOrderQuantityByProduct = new Map(products.map((product) => [
595
+ product.id,
596
+ effectiveOrderRules({ minOrderQuantity: product.minOrderQuantity ?? null, returnable: product.returnable }, scopeRows.channelRows.get(product.id)).minOrderQuantity,
597
+ ]));
598
+ return {
599
+ assetUrlByProduct,
600
+ categorySlugsByProduct,
601
+ overridesByProduct,
602
+ effectiveKeyByProduct,
603
+ minOrderQuantityByProduct,
604
+ };
605
+ }
606
+ /** The one product's key at the request's language, from keys already read (N1). */
607
+ #keysAtScopeLanguage(products, keysByLanguage, ctx) {
608
+ const { languageCode } = this.#availabilityScope(ctx);
609
+ return new Map(products.map((product) => [product.id, keysByLanguage.get(languageCode) ?? product.slug]));
610
+ }
611
+ /**
612
+ * Feature 163 (R28) — each product's effective URL key at the request's
613
+ * (channel, language), in one statement for the set.
614
+ */
615
+ async #effectiveKeysAt(em, products, ctx) {
616
+ const { channel, languageCode } = this.#availabilityScope(ctx);
617
+ const keys = await loadEffectiveKeys(em, products, { id: channel.id, languages: [languageCode] });
618
+ const out = new Map();
619
+ for (const product of products)
620
+ out.set(product.id, keys.get(product.id)?.get(languageCode) ?? product.slug);
621
+ return out;
479
622
  }
480
623
  // ------------------------------------------------------------------
481
624
  // Products
@@ -484,17 +627,19 @@ export class CatalogQueryService {
484
627
  // A price walk that began in the default order, for want of a price order,
485
628
  // continues in it to its end — the default listing's page, so nothing the
486
629
  // price path would read first is read (review 2, finding 7).
487
- const priceCursor = isPriceSort(params.sort) && params.cursor ? this.#priceCursor(params.cursor) : null;
630
+ const priceCursor = isPriceSort(params.sort) && params.cursor ? this.#priceCursor(params.cursor, ctx) : null;
488
631
  if (priceCursor?.stream === 'unordered')
489
632
  return this.#listUnordered(params, ctx, priceCursor.cursor);
490
633
  const em = this.emFactory();
491
634
  const channel = ctx.resolvedChannel;
492
635
  // --- Filter validation: any filter[attr.<key>] where the attribute is
493
636
  // not filterable must return 400 FILTER_NOT_ALLOWED (FR-005, T043).
637
+ let attributeViews = [];
494
638
  if (params.attributeFilters) {
495
639
  const keys = Object.keys(params.attributeFilters);
496
640
  if (keys.length > 0) {
497
641
  const views = await this.#requireAttributeRead().listAll();
642
+ attributeViews = views;
498
643
  const byKey = new Map(views.map((a) => [a.key, a]));
499
644
  for (const k of keys) {
500
645
  const a = byKey.get(k);
@@ -504,32 +649,17 @@ export class CatalogQueryService {
504
649
  }
505
650
  }
506
651
  }
652
+ // Feature 163 — status, window, membership and audience are one condition,
653
+ // `availabilityCondition`, applied in every statement below; no status
654
+ // value is tested here (FR-002).
507
655
  const where = {
508
- status: 'active',
509
656
  deletedAt: null,
510
657
  };
511
- if (params.q) {
512
- // MVP: DB-only search. Production target uses Meilisearch behind this
513
- // same query method (T067/T068 — Phase 10 polish); for now we match:
514
- // 1. SKU ILIKE (covers the seeded EXAMPLE-… ids)
515
- // 2. attributeValues at any key flagged isSearchable=true
516
- // The attribute-values match uses Postgres ILIKE on the JSONB cast to
517
- // text, which is fine for the test corpus and good enough until Meili.
518
- const searchableKeys = await this.searchableAttributeKeys(em);
519
- const orClauses = [
520
- { sku: { $ilike: `%${params.q}%` } },
521
- ];
522
- for (const key of searchableKeys) {
523
- // MikroORM's `expr()` would be cleaner; raw cast keeps the dependency
524
- // surface minimal here.
525
- orClauses.push({
526
- // Match any product whose attributeValues[key] (case-insensitive)
527
- // contains the query.
528
- attributeValues: this.searchableJsonbClause(key, params.q),
529
- });
530
- }
531
- where['$or'] = orClauses;
532
- }
658
+ const scope = this.#availabilityScope(ctx);
659
+ // Feature 163 (FR-017 b) — free text and attribute filters over the
660
+ // effective values a card shows at (channel, language), as conditions of
661
+ // every statement below (issue #151), with their page-side twin.
662
+ const filters = await this.#listingFilters(params, ctx, attributeViews);
533
663
  if (params.changedSince) {
534
664
  where['updatedAt'] = { $gt: new Date(params.changedSince) };
535
665
  }
@@ -537,23 +667,22 @@ export class CatalogQueryService {
537
667
  // chunked and both are bounded; everything else takes the single fetch it
538
668
  // always took.
539
669
  if (isPriceSort(params.sort)) {
540
- return this.#listByViewerPrice(em, params, ctx, where, params.sort, priceCursor);
670
+ return this.#listByViewerPrice(em, params, ctx, where, params.sort, priceCursor, scope, filters);
541
671
  }
542
672
  if (params.minPrice !== undefined || params.maxPrice !== undefined) {
543
- return this.#listWithPriceRange(em, params, ctx, where);
673
+ return this.#listWithPriceRange(em, params, ctx, where, scope, filters);
544
674
  }
545
675
  // Cursor decoding — over the keyset this ordering pages by, which is
546
- // `{ createdAt, id }` for the default sort and `{ slug, id }` for `name`.
547
- const keyset = this.keysetFor(params.sort);
548
- let cursorClause = null;
549
- if (params.cursor) {
550
- const decoded = keyset.parse(decodeObjectCursor(params.cursor));
551
- if (decoded)
552
- cursorClause = keyset.after(decoded);
553
- }
676
+ // `{ createdAt, id }` for the default sort and `{ name, id }` (the effective
677
+ // name, feature 163 D6) for `name`. Decoded here; its `where` fragment is
678
+ // made in the statement below, because under `name` it is a `raw()` key.
679
+ const keyset = this.#keysetFor(params.sort, ctx);
680
+ const decodedCursor = params.cursor
681
+ ? keyset.parse(decodeObjectCursor(params.cursor))
682
+ : null;
554
683
  // Issue #151 — everything that decides whether a row is on the listing is
555
684
  // part of the statement the page is cut from. See `#listingNarrowing`.
556
- const narrowing = await this.#listingNarrowing(em, params, ctx);
685
+ const narrowing = await this.#listingNarrowing(em, params, scope);
557
686
  if (narrowing === null) {
558
687
  // The category names nothing a storefront may browse, so no row matches
559
688
  // and there is no statement worth issuing.
@@ -573,23 +702,29 @@ export class CatalogQueryService {
573
702
  const products = await em.find(Product, {
574
703
  $and: [
575
704
  where,
576
- ...(cursorClause ? [cursorClause] : []),
577
- ...narrowing.map((c) => ({ [raw(c.sql, c.params)]: [] })),
705
+ ...(decodedCursor ? [keyset.after(decodedCursor)] : []),
706
+ ...[...narrowing, ...filters.conditions].map((c) => ({ [raw(c.sql, c.params)]: [] })),
578
707
  ],
579
- }, { limit: params.limit + 1, orderBy: this.orderForSort(params.sort) });
708
+ }, { limit: params.limit + 1, orderBy: keyset.orderBy() });
580
709
  const hasMore = products.length > params.limit;
581
710
  const page = hasMore ? products.slice(0, params.limit) : products;
582
- const nextCursor = hasMore && page.length > 0 ? encodeObjectCursor(keyset.of(page[page.length - 1])) : null;
583
- // The audience and attribute predicates once more, over the rows the
711
+ const lastOfPage = page[page.length - 1];
712
+ const nextCursor = hasMore && lastOfPage
713
+ ? encodeObjectCursor(keyset.of(lastOfPage, await this.#cursorNames(em, keyset, [lastOfPage], ctx)))
714
+ : null;
715
+ // The availability and attribute predicates once more, over the rows the
584
716
  // statement returned — kept deliberately, as defence in depth.
585
- // `isProductVisibleTo` is the platform's one answer to "may this caller see
586
- // this product" and the SQL above is a restatement of it; a restatement that
587
- // admits a row the predicate refuses must not be what decides a disclosure.
588
- // The case that exists today is a stored allow-list that is not an array:
589
- // the statement reads it as "no allow-list", the predicate does not. It
590
- // costs no statement, and while the two agree it removes nothing — which is
591
- // what the contract test holds them to, rule by rule, with full pages.
592
- const priceable = page.filter((p) => this.#passesPageFilters(p, params, ctx));
717
+ // `isProductEffectivelyAvailable` is the platform's one answer to "may this
718
+ // caller see this product here, now" and the SQL above is a restatement of
719
+ // it; a restatement that admits a row the rule refuses must not be what
720
+ // decides a disclosure. The case that exists today is a stored allow-list
721
+ // that is not an array: the statement reads it as "no allow-list", the
722
+ // predicate does not. It costs the page's two scope-row reads, and while the
723
+ // two agree it removes nothing — which is what the parity test holds them
724
+ // to (`availability-parity.test.ts`).
725
+ const available = await this.#availableAmong(em, page, scope, true);
726
+ const passing = await filters.passes(em, page);
727
+ const priceable = page.filter((p) => available.has(p.id) && passing.has(p.id));
593
728
  // Build the summaries. The page is resolved **once** — `toSummary` used to
594
729
  // ask `price_lists` for a batch of one, so a 50-card page made 50 calls and
595
730
  // paid the resolution's fixed cost (the active lists, the settings pair, the
@@ -601,7 +736,7 @@ export class CatalogQueryService {
601
736
  // same reason (issue #263): both helpers took an id list already, and both
602
737
  // were being handed one id at a time from inside the loop.
603
738
  const resolvedPrices = await this.#listingPricesFor(priceable, ctx);
604
- const cardReads = await this.#listingCardReadsFor(em, priceable.map((p) => p.id), channel.id);
739
+ const cardReads = await this.#listingCardReadsFor(em, priceable, ctx);
605
740
  const summaries = priceable.map((p) => this.toSummary(p, channel, ctx.preferredLanguage, resolvedPrices, cardReads));
606
741
  return {
607
742
  data: summaries,
@@ -619,16 +754,18 @@ export class CatalogQueryService {
619
754
  * were was short. With two sales channels and the newest hundred products on
620
755
  * one of them, the other's first page of a hundred was empty.
621
756
  *
622
- * - **channel membership** comes from the kernel's accessor as a fragment
623
- * ({@link SalesChannelMembershipPort.entityIdsInChannelSubquery}); the bridge
624
- * is still not named here (Constitution XII);
625
- * - **the audience** is `isProductVisibleTo` restated — see
626
- * `#audienceCondition`;
757
+ * - **availability** (feature 163) is `availabilityCondition`: channel
758
+ * membership through the kernel's accessor
759
+ * ({@link SalesChannelMembershipPort.entityIdsInChannelSubquery} — the
760
+ * bridge is still not named here, Constitution XII), the effective status
761
+ * at (C, L), the effective window at `now` and the effective audience rule
762
+ * (`isProductVisibleTo` restated over the channel's rule);
627
763
  * - **the category** is an `exists` over this module's own
628
764
  * `product_categories`, against the tree's ids rather than against every
629
765
  * product id the tree holds, which is what the page-side test loaded;
630
- * - **each attribute filter** is `#passesPageFilters`' string comparison
631
- * restated — see `#attributeCondition`.
766
+ * - **each attribute filter** is not built here but in `#listingFilters`,
767
+ * as `#attributeCondition` — {@link attributeFilterMatches}, the page-side
768
+ * predicate, restated in SQL.
632
769
  *
633
770
  * **No `raw()` fragment is created here** — these are descriptions, and the
634
771
  * caller turns them into keys in the expression that executes them. A
@@ -636,7 +773,7 @@ export class CatalogQueryService {
636
773
  * only by the statement that consumes it, so this method, which can answer
637
774
  * `null` and awaits a read that can fail, is the wrong place to make one.
638
775
  */
639
- async #listingNarrowing(em, params, ctx) {
776
+ async #listingNarrowing(em, params, scope) {
640
777
  // First, because it is the one part that can end the request: an unknown,
641
778
  // inactive or deleted category means no row matches.
642
779
  let categoryIds = null;
@@ -645,11 +782,7 @@ export class CatalogQueryService {
645
782
  if (categoryIds.length === 0)
646
783
  return null;
647
784
  }
648
- const inChannel = this.#requireChannelMembership().entityIdsInChannelSubquery(ctx.resolvedChannel.id, 'product');
649
- const conditions = [
650
- { sql: (alias) => `${alias}.id in (${inChannel.sql})`, params: inChannel.params },
651
- this.#audienceCondition(ctx.audience),
652
- ];
785
+ const conditions = [this.#availabilityNarrowing(scope)];
653
786
  if (categoryIds !== null) {
654
787
  const ids = categoryIds;
655
788
  conditions.push({
@@ -659,96 +792,104 @@ export class CatalogQueryService {
659
792
  params: ids,
660
793
  });
661
794
  }
662
- for (const [key, values] of Object.entries(params.attributeFilters ?? {})) {
663
- conditions.push(this.#attributeCondition(key, values));
664
- }
665
795
  return conditions;
666
796
  }
667
797
  /**
668
- * `isProductVisibleTo`, as SQL, for the audience in front of the listing.
798
+ * One `filter[attr.<key>]`, as SQL: {@link attributeFilterMatches} restated —
799
+ * the product's value for `key`, rendered as `String` renders it, is one of
800
+ * the requested values, and a multiselect matches when **any** of its options
801
+ * is (issue #684). `#listingFilters`' `passes` calls that function, so the
802
+ * statement and the page agree.
669
803
  *
670
- * The third restatement of that predicate in this module, and the only one
671
- * that takes the audience as an argument: `catalog-quick-search.service.ts`
672
- * answers for a signed-in buyer and `ANONYMOUS_AUDIENCE_CLAUSE` for nobody,
673
- * so neither could be reused for a surface both kinds of caller read. The
674
- * `case` follows the predicate branch for branch — a non-empty allow-list
675
- * decides on its own, then `organization_restricted`, then `logged_in_only` —
676
- * so a fourth visibility value falls to `else true` exactly as it falls to
677
- * the predicate's last `return`.
678
- *
679
- * `@>` containment over the JSONB array, so the organisation has to be one of
680
- * its elements rather than a substring of the serialised bag.
804
+ * A scalar is walked as a one-element array, each element rendered by
805
+ * {@link jsStringOfJsonb}. A key the product does not carry is SQL `NULL`,
806
+ * walked as no element, and matches nothing — the function's `undefined`
807
+ * arm; an empty multiselect matches nothing for the same reason.
681
808
  */
682
- #audienceCondition(audience) {
683
- const onAllowList = audience.organizationId !== null;
809
+ #attributeCondition(value, values) {
810
+ const wanted = values.map((v) => String(v));
811
+ if (wanted.length === 0)
812
+ return { sql: () => 'false', params: [] };
684
813
  return {
685
- sql: (alias) => `(case ` +
686
- `when (case when jsonb_typeof(${alias}.allowed_organization_ids) = 'array' ` +
687
- `then jsonb_array_length(${alias}.allowed_organization_ids) else 0 end) > 0 ` +
688
- `then ${onAllowList ? `${alias}.allowed_organization_ids @> ?::jsonb` : 'false'} ` +
689
- `when ${alias}.visibility = 'organization_restricted' then false ` +
690
- `when ${alias}.visibility = 'logged_in_only' then ${audience.authenticated ? 'true' : 'false'} ` +
691
- `else true end)`,
692
- params: onAllowList ? [JSON.stringify([audience.organizationId])] : [],
814
+ sql: (alias) => `exists (select 1 from (select ${value.sql(alias)} as v) val ` +
815
+ `cross join lateral jsonb_array_elements(case ` +
816
+ `when val.v is null then '[]'::jsonb ` +
817
+ `when jsonb_typeof(val.v) = 'array' then val.v ` +
818
+ `else jsonb_build_array(val.v) end) as el(value) ` +
819
+ `where ${jsStringOfJsonb('el.value')} in (${wanted.map(() => '?').join(',')}))`,
820
+ params: [...value.params, ...wanted],
693
821
  };
694
822
  }
695
823
  /**
696
- * One `filter[attr.<key>]`, as SQL: the product's value for `key`, rendered
697
- * the way `#passesPageFilters` renders it, is one of the requested values.
698
- *
699
- * That method compares `String(value)`, so this is `String` restated for the
700
- * JSON kinds a stored value can take — see {@link jsStringOfJsonb}. A key the
701
- * product does not carry is SQL `NULL` throughout and matches nothing, which
702
- * is the method's `undefined` arm.
703
- *
704
- * The comparison is deliberately not improved here. A multiselect holding two
705
- * options matches neither of them alone, on either side of this change; that
706
- * is a question about what the filter means, and answering it in the
707
- * statement only would make the page-side predicate disagree with it.
824
+ * Feature 163 (FR-017 b) — what narrows a listing beside availability and the
825
+ * category: the free-text match and each `filter[attr.<key>]`, over the
826
+ * **effective** values a card shows at the request's (channel, language)
827
+ * (#384's walk, `effective-value.sql.ts`). `conditions` go into every
828
+ * statement a page is cut from; `passes` is their page-side twin over the
829
+ * same walk in TypeScript (`effectiveAttributeValues`), kept as defence in
830
+ * depth like the availability one.
708
831
  */
709
- #attributeCondition(key, values) {
710
- const wanted = values.map((v) => String(v));
711
- if (wanted.length === 0)
712
- return { sql: () => 'false', params: [] };
832
+ async #listingFilters(params, ctx, attributeViews) {
833
+ const channel = ctx.resolvedChannel;
834
+ const effective = this.#overrideContext(channel, ctx.preferredLanguage);
835
+ const conditions = [];
836
+ // Issue #590 — a read by id is one more condition of every statement a
837
+ // page is cut from, so the price orderings and the range walk honour it as
838
+ // the default order does; its page-side twin is in `passes` below.
839
+ const ids = params.ids && params.ids.length > 0 ? [...params.ids] : null;
840
+ if (ids) {
841
+ conditions.push({
842
+ sql: (alias) => `${alias}.id in (${ids.map(() => '?').join(',')})`,
843
+ params: ids,
844
+ });
845
+ }
846
+ if (params.q)
847
+ conditions.push(await this.#textSearchCondition(params.q, ctx, effective));
848
+ const scopeOf = new Map(attributeViews.map((a) => [a.key, a.scopeLevels]));
849
+ const notScoped = ['G'];
850
+ const attributeFilters = Object.entries(params.attributeFilters ?? {});
851
+ for (const [key, values] of attributeFilters) {
852
+ conditions.push(this.#attributeCondition(effectiveAttributeSql(key, scopeOf.get(key) ?? notScoped, effective), values));
853
+ }
713
854
  return {
714
- sql: (alias) => `(select ${jsStringOfJsonb('val.v')} ` +
715
- `from (select ${alias}.attribute_values -> ?::text as v) val) ` +
716
- `in (${wanted.map(() => '?').join(',')})`,
717
- params: [key, ...wanted],
855
+ conditions,
856
+ passes: async (em, all) => {
857
+ const out = new Set();
858
+ const named = ids ? new Set(ids) : null;
859
+ const products = named ? all.filter((p) => named.has(p.id)) : all;
860
+ if (attributeFilters.length === 0) {
861
+ for (const p of products)
862
+ out.add(p.id);
863
+ return out;
864
+ }
865
+ if (products.length === 0)
866
+ return out;
867
+ const overrides = await loadChannelOverridesByProduct(em, products.map((p) => p.id), channel.id);
868
+ for (const product of products) {
869
+ const values = await effectiveAttributeValues(product.attributeValues ?? {}, overrides.get(product.id), effective, async () => scopeOf);
870
+ const ok = attributeFilters.every(([key, wanted]) => attributeFilterMatches(values[key], wanted.map((w) => String(w))));
871
+ if (ok)
872
+ out.add(product.id);
873
+ }
874
+ return out;
875
+ },
718
876
  };
719
877
  }
720
878
  /**
721
- * The channel/audience/attribute predicates a fetched page is narrowed by,
722
- * for one product.
723
- *
724
- * The channel test is the caller's, because it is one `in (…)` for the whole
725
- * chunk; the other two are per row and were already written inline. They are
726
- * collected here so the price paths below apply **exactly** the same
727
- * narrowing as the default path — a price ordering that filtered differently
728
- * would make a hidden row observable through a position or a page boundary,
729
- * which is the disclosure FR-014 forbids and which neither the relevance sort
730
- * nor the name sort could have had.
879
+ * The free-text match (FR-017 b): the SKU, the effective Name, and the
880
+ * effective value of every searchable attribute, case-insensitive substring.
731
881
  */
732
- #passesPageFilters(product, params, ctx) {
733
- // Issue #227 — the second scoping axis, alongside the channel one. The two
734
- // price paths apply it here, to each chunk they collect before cutting a
735
- // page, and their known cost is the scan budget binding where an operator
736
- // restricts most of a catalogue. The default path no longer relies on it
737
- // (issue #151): `#audienceCondition` puts the same answer in the statement
738
- // its page is cut from, and this runs afterwards only as the predicate's
739
- // own word on each row.
740
- if (!isProductVisibleTo(product, ctx.audience))
741
- return false;
742
- if (!params.attributeFilters)
743
- return true;
744
- for (const [k, values] of Object.entries(params.attributeFilters)) {
745
- const av = product.attributeValues[k];
746
- if (av === undefined)
747
- return false;
748
- if (!values.map((v) => String(v)).includes(String(av)))
749
- return false;
750
- }
751
- return true;
882
+ async #textSearchCondition(q, ctx, effective) {
883
+ const searchable = await this.#requireAttributeRead().listByFlag('isSearchable');
884
+ const like = `%${q}%`;
885
+ const name = this.#effectiveNameExpr(ctx);
886
+ const attributes = searchable.map((a) => effectiveAttributeSql(a.key, a.scopeLevels, effective));
887
+ return {
888
+ sql: (alias) => `(${alias}.sku ilike ? or ${name.sql(alias)} ilike ?` +
889
+ attributes.map((e) => ` or (${e.sql(alias)} #>> '{}') ilike ?`).join('') +
890
+ `)`,
891
+ params: [like, ...name.params, like, ...attributes.flatMap((e) => [...e.params, like])],
892
+ };
752
893
  }
753
894
  /** The two range bounds as four-place decimal strings ({@link amountBound}), for every price path. */
754
895
  #amountRange(params) {
@@ -790,14 +931,14 @@ export class CatalogQueryService {
790
931
  */
791
932
  async #listByViewerPrice(em, params, ctx, where, sort,
792
933
  /** The request's cursor as `#priceCursor` read it: `null` starts the walk. */
793
- decoded) {
934
+ decoded, availability, filters) {
794
935
  const channel = ctx.resolvedChannel;
795
936
  const direction = sort === 'price' ? 'asc' : 'desc';
796
937
  // The viewer's pricing context and the category tree, read once for the
797
938
  // page and handed to whichever walk serves it — every chunk of it (review
798
939
  // 3, A5). An `unordered` walk is decided earlier, in `listProducts`, and
799
940
  // reads neither (review 2, finding 7).
800
- const scope = await this.#priceWalkScope(em, params, ctx);
941
+ const scope = await this.#priceWalkScope(em, params, ctx, availability, filters);
801
942
  const { context } = scope;
802
943
  // A walk whose price order went missing carries on in the default order
803
944
  // from the last price it served, to its end.
@@ -805,7 +946,7 @@ export class CatalogQueryService {
805
946
  return this.#listRemainder(em, params, ctx, where, direction, scope, decoded, decoded.after);
806
947
  }
807
948
  const amountRange = this.#amountRange(params);
808
- const restrictToProductIds = scope.categoryIds ? [...scope.categoryIds] : undefined;
949
+ const { restrictToProductIds } = scope;
809
950
  // A cursor issued under another sort is discarded rather than
810
951
  // reinterpreted: the existing behaviour for a cursor that does not parse.
811
952
  const startInTail = decoded?.stream === 'tail';
@@ -868,7 +1009,7 @@ export class CatalogQueryService {
868
1009
  }
869
1010
  const last = chunk.rows[chunk.rows.length - 1];
870
1011
  priceCursor = { amount: last.amount, productId: last.productId };
871
- const byId = await this.#visibleProductsInOrder(em, chunk.rows.map((row) => row.productId), where, params, ctx);
1012
+ const byId = await this.#visibleProductsInOrder(em, chunk.rows.map((row) => row.productId), where, scope.availability, scope.filters);
872
1013
  for (const row of chunk.rows) {
873
1014
  const product = byId.get(row.productId);
874
1015
  if (!product)
@@ -891,20 +1032,26 @@ export class CatalogQueryService {
891
1032
  bound = true;
892
1033
  break;
893
1034
  }
894
- const chunkWhere = tailCursor
895
- ? {
896
- $and: [
897
- where,
898
- {
899
- $or: [
900
- { createdAt: { $lt: new Date(tailCursor.createdAt) } },
901
- { createdAt: new Date(tailCursor.createdAt), id: { $lt: tailCursor.id } },
902
- ],
903
- },
904
- ],
905
- }
906
- : where;
907
- const rows = await em.find(Product, chunkWhere, {
1035
+ const tailAfter = tailCursor
1036
+ ? [
1037
+ {
1038
+ $or: [
1039
+ { createdAt: { $lt: new Date(tailCursor.createdAt) } },
1040
+ { createdAt: new Date(tailCursor.createdAt), id: { $lt: tailCursor.id } },
1041
+ ],
1042
+ },
1043
+ ]
1044
+ : [];
1045
+ // Feature 163 — availability in the chunk's own statement (issue #151);
1046
+ // the `raw()` key is made in the expression that executes it.
1047
+ const narrowing = this.#availabilityNarrowing(scope.availability);
1048
+ const rows = await em.find(Product, {
1049
+ $and: [
1050
+ where,
1051
+ ...tailAfter,
1052
+ ...[narrowing, ...filters.conditions].map((c) => ({ [raw(c.sql, c.params)]: [] })),
1053
+ ],
1054
+ }, {
908
1055
  limit: chunkSize,
909
1056
  // The listing's own default ordering, in both directions: the tail is
910
1057
  // not ordered by a price it does not have.
@@ -920,11 +1067,12 @@ export class CatalogQueryService {
920
1067
  productIds: rows.map((r) => r.id),
921
1068
  });
922
1069
  const candidates = rows.filter((r) => !priced.has(r.id) && (categoryIds === null || categoryIds.has(r.id)));
923
- const visibleIds = await this.filterByChannel(candidates.map((r) => r.id), channel);
1070
+ const visibleIds = await this.#availableAmong(em, candidates, scope.availability, true);
1071
+ const passing = await scope.filters.passes(em, candidates);
924
1072
  for (const product of candidates) {
925
1073
  if (!visibleIds.has(product.id))
926
1074
  continue;
927
- if (!this.#passesPageFilters(product, params, ctx))
1075
+ if (!passing.has(product.id))
928
1076
  continue;
929
1077
  collected.push(product);
930
1078
  cursors.push({
@@ -946,7 +1094,8 @@ export class CatalogQueryService {
946
1094
  // in the tail once the tail has been read, else in the priced stream,
947
1095
  // whose exhaustion the next page then finds and goes on into the tail —
948
1096
  // never from its last card, and never ends the walk (review 3 of release
949
- // 0.108.0, A1).
1097
+ // 0.108.0, A1). That row may be one the viewer may not see, and its price
1098
+ // is in the position, so the cursor is sealed (issue #497).
950
1099
  const page = collected.slice(0, params.limit);
951
1100
  let resumeAt = null;
952
1101
  if (collected.length > params.limit || orderLost)
@@ -956,9 +1105,9 @@ export class CatalogQueryService {
956
1105
  else if (bound && priceCursor)
957
1106
  resumeAt = { stream: 'priced', ...priceCursor };
958
1107
  const hasMore = resumeAt !== null;
959
- const nextCursor = resumeAt === null ? null : encodeObjectCursor(resumeAt);
1108
+ const nextCursor = resumeAt === null ? null : this.#sealCursor(PRICE_WALK_CURSOR_PURPOSE, resumeAt);
960
1109
  const resolvedPrices = await this.#listingPricesFor(page, ctx, context);
961
- const cardReads = await this.#listingCardReadsFor(em, page.map((p) => p.id), channel.id);
1110
+ const cardReads = await this.#listingCardReadsFor(em, page, ctx);
962
1111
  return {
963
1112
  data: page.map((p) => this.toSummary(p, channel, ctx.preferredLanguage, resolvedPrices, cardReads)),
964
1113
  // No total count, no rank, no "showing 51–100 of 4 213" (FR-015): an
@@ -973,10 +1122,20 @@ export class CatalogQueryService {
973
1122
  * page reads up to eight chunks, and each used to look the organization up
974
1123
  * again and, on the remainder, re-read the category tree).
975
1124
  */
976
- async #priceWalkScope(em, params, ctx) {
1125
+ async #priceWalkScope(em, params, ctx, availability, filters) {
1126
+ const categoryIds = params.categorySlug ? await this.productIdsInCategoryTree(em, params.categorySlug) : null;
1127
+ const named = params.ids && params.ids.length > 0 ? params.ids : null;
1128
+ const restrictToProductIds = named
1129
+ ? named.filter((id) => categoryIds === null || categoryIds.has(id))
1130
+ : categoryIds
1131
+ ? [...categoryIds]
1132
+ : undefined;
977
1133
  return {
978
1134
  context: await this.#viewerPricingContext(ctx),
979
- categoryIds: params.categorySlug ? await this.productIdsInCategoryTree(em, params.categorySlug) : null,
1135
+ categoryIds,
1136
+ restrictToProductIds,
1137
+ availability,
1138
+ filters,
980
1139
  };
981
1140
  }
982
1141
  /**
@@ -987,11 +1146,11 @@ export class CatalogQueryService {
987
1146
  * the default listing's keyset; an `unordered` cursor wraps the default
988
1147
  * listing's own, which that listing checks.
989
1148
  */
990
- #priceCursor(cursor) {
991
- const decoded = decodeObjectCursor(cursor);
1149
+ #priceCursor(cursor, ctx) {
1150
+ const decoded = this.#openCursor(PRICE_WALK_CURSOR_PURPOSE, cursor);
992
1151
  if (!isRecord(decoded))
993
1152
  return null;
994
- const keyset = this.keysetFor(undefined);
1153
+ const keyset = this.#keysetFor(undefined, ctx);
995
1154
  switch (decoded['stream']) {
996
1155
  case 'priced': {
997
1156
  const amount = cursorAmount(decoded['amount']);
@@ -1031,7 +1190,9 @@ export class CatalogQueryService {
1031
1190
  ...page,
1032
1191
  pagination: {
1033
1192
  ...page.pagination,
1034
- cursor: next ? encodeObjectCursor({ stream: 'unordered', cursor: next }) : null,
1193
+ cursor: next
1194
+ ? this.#sealCursor(PRICE_WALK_CURSOR_PURPOSE, { stream: 'unordered', cursor: next })
1195
+ : null,
1035
1196
  },
1036
1197
  };
1037
1198
  }
@@ -1051,16 +1212,18 @@ export class CatalogQueryService {
1051
1212
  * price ordering: the chain's `none` and `product` arms are both absences of
1052
1213
  * a price-list figure, and a range is a claim about one.
1053
1214
  */
1054
- async #listWithPriceRange(em, params, ctx, where) {
1215
+ async #listWithPriceRange(em, params, ctx, where, scope, filters) {
1055
1216
  const range = this.#amountRange(params);
1056
1217
  // The chunk walk and the page it hands back page by the same keyset, and
1057
1218
  // that keyset is the one this ordering sorts on — `keysetFor`.
1058
- const keyset = this.keysetFor(params.sort);
1059
- return this.#walkKeepingByPrice(em, params, ctx, where, await this.#priceWalkScope(em, params, ctx), {
1219
+ const keyset = this.#keysetFor(params.sort, ctx);
1220
+ return this.#walkKeepingByPrice(em, params, ctx, where, await this.#priceWalkScope(em, params, ctx, scope, filters), {
1060
1221
  sort: params.sort,
1061
- start: params.cursor ? keyset.parse(decodeObjectCursor(params.cursor)) : null,
1222
+ start: params.cursor ? keyset.parse(this.#openCursor(PRICE_RANGE_WALK_CURSOR_PURPOSE, params.cursor)) : null,
1062
1223
  keep: (price) => price !== null && withinAmountRange(price.amount, range),
1063
- cursorOf: (after) => encodeObjectCursor(after),
1224
+ // Sealed (issue #497): a page cut by the budget names the row its scan
1225
+ // stopped at, which may be a product the viewer may not see.
1226
+ cursorOf: (after) => this.#sealCursor(PRICE_RANGE_WALK_CURSOR_PURPOSE, after),
1064
1227
  what: 'price-filtered',
1065
1228
  });
1066
1229
  }
@@ -1112,7 +1275,7 @@ export class CatalogQueryService {
1112
1275
  return range === undefined;
1113
1276
  return withinAmountRange(price.amount, range) && afterBoundary(price.amount, product.id);
1114
1277
  },
1115
- cursorOf: (next) => encodeObjectCursor({
1278
+ cursorOf: (next) => this.#sealCursor(PRICE_WALK_CURSOR_PURPOSE, {
1116
1279
  stream: 'rest',
1117
1280
  amount: boundary.amount,
1118
1281
  productId: boundary.productId,
@@ -1126,12 +1289,14 @@ export class CatalogQueryService {
1126
1289
  * by everything a page is narrowed by and then by the live listing price its
1127
1290
  * cards are rendered with — `keep` decides on that price. Bounded by the scan
1128
1291
  * budget; a bound answers a short, possibly empty, page whose cursor
1129
- * continues from the scan position.
1292
+ * continues from the scan position. `cursorOf` seals it: that position may
1293
+ * be a product the viewer may not see (issue #497).
1130
1294
  */
1131
1295
  async #walkKeepingByPrice(em, params, ctx, where, scope, walk) {
1132
1296
  const channel = ctx.resolvedChannel;
1133
1297
  const categoryFilteredIds = scope.categoryIds;
1134
- const keyset = this.keysetFor(walk.sort);
1298
+ const filters = scope.filters;
1299
+ const keyset = this.#keysetFor(walk.sort, ctx);
1135
1300
  let cursor = walk.start;
1136
1301
  const budget = PRICE_PAGE_SCAN_BUDGET_MULTIPLE * params.limit;
1137
1302
  const target = params.limit + 1;
@@ -1147,26 +1312,34 @@ export class CatalogQueryService {
1147
1312
  bound = true;
1148
1313
  break;
1149
1314
  }
1150
- const chunkWhere = cursor ? { $and: [where, keyset.after(cursor)] } : where;
1151
- const rows = await em.find(Product, chunkWhere, {
1315
+ // Feature 163 — availability in the chunk's own statement (issue #151);
1316
+ // the `raw()` key is made in the expression that executes it.
1317
+ const narrowing = this.#availabilityNarrowing(scope.availability);
1318
+ const rows = await em.find(Product, {
1319
+ $and: [
1320
+ where,
1321
+ ...(cursor ? [keyset.after(cursor)] : []),
1322
+ ...[narrowing, ...filters.conditions].map((c) => ({ [raw(c.sql, c.params)]: [] })),
1323
+ ],
1324
+ }, {
1152
1325
  limit: chunkSize,
1153
- orderBy: this.orderForSort(walk.sort),
1326
+ orderBy: keyset.orderBy(),
1154
1327
  });
1155
1328
  spent += rows.length;
1156
1329
  if (rows.length === 0)
1157
1330
  break;
1158
1331
  const lastRow = rows[rows.length - 1];
1159
- cursor = keyset.of(lastRow);
1160
- const visibleIds = await this.filterByChannel(rows.map((r) => r.id), channel);
1332
+ cursor = keyset.of(lastRow, await this.#cursorNames(em, keyset, [lastRow], ctx));
1333
+ const visibleIds = await this.#availableAmong(em, rows, scope.availability, true);
1334
+ const passing = await filters.passes(em, rows);
1161
1335
  const candidates = rows.filter((r) => visibleIds.has(r.id) &&
1162
- this.#passesPageFilters(r, params, ctx) &&
1336
+ passing.has(r.id) &&
1163
1337
  (categoryFilteredIds === null || categoryFilteredIds.has(r.id)));
1164
1338
  // The walk decides on the viewer's own price — the figure the price
1165
- // order is made of — whether or not the channel publishes it; the cards
1166
- // below withhold it where the channel does. `#listingPricesFor` answers
1167
- // no price at all on a non-public channel, which read here as "no
1168
- // detail" and dropped every product, priced and unpriced alike (review 3
1169
- // of release 0.108.0, A3).
1339
+ // order is made of. It asks the resolution directly, not through
1340
+ // `#listingPricesFor`, which once answered no price at all on a channel
1341
+ // that withheld prices; that read here as "no detail" and dropped every
1342
+ // product, priced and unpriced alike (review 3 of release 0.108.0, A3).
1170
1343
  const chunkPrices = candidates.length === 0
1171
1344
  ? new Map()
1172
1345
  : await this.#requireListingPrices().resolveListingPriceDetails({
@@ -1198,14 +1371,12 @@ export class CatalogQueryService {
1198
1371
  const full = collected.length > params.limit;
1199
1372
  const page = collected.slice(0, params.limit);
1200
1373
  const last = page[page.length - 1];
1201
- const resumeAt = full && last ? keyset.of(last) : bound ? cursor : null;
1374
+ const resumeAt = full && last ? keyset.of(last, await this.#cursorNames(em, keyset, [last], ctx)) : bound ? cursor : null;
1202
1375
  const hasMore = resumeAt !== null;
1203
1376
  const nextCursor = resumeAt === null ? null : walk.cursorOf(resumeAt);
1204
- const cardReads = await this.#listingCardReadsFor(em, page.map((p) => p.id), channel.id);
1205
- // A channel that publishes no prices renders none, as `#listingPricesFor` would.
1206
- const shown = (channel.isPublic ?? true) ? prices : new Map();
1377
+ const cardReads = await this.#listingCardReadsFor(em, page, ctx);
1207
1378
  return {
1208
- data: page.map((p) => this.toSummary(p, channel, ctx.preferredLanguage, shown, cardReads)),
1379
+ data: page.map((p) => this.toSummary(p, channel, ctx.preferredLanguage, prices, cardReads)),
1209
1380
  pagination: { cursor: nextCursor, hasMore, limit: params.limit },
1210
1381
  };
1211
1382
  }
@@ -1217,47 +1388,148 @@ export class CatalogQueryService {
1217
1388
  * answers in whatever order it likes, and the ordering being reproduced is the
1218
1389
  * price one.
1219
1390
  */
1220
- async #visibleProductsInOrder(em, productIds, where, params, ctx) {
1391
+ async #visibleProductsInOrder(em, productIds, where, scope, filters) {
1221
1392
  const out = new Map();
1222
1393
  if (productIds.length === 0)
1223
1394
  return out;
1224
- const rows = await em.find(Product, { $and: [where, { id: { $in: [...productIds] } }] });
1225
- const visibleIds = await this.filterByChannel(rows.map((r) => r.id), ctx.resolvedChannel);
1395
+ // Feature 163 — the `raw()` key is made in the expression that executes it.
1396
+ const narrowing = this.#availabilityNarrowing(scope);
1397
+ const rows = await em.find(Product, {
1398
+ $and: [
1399
+ where,
1400
+ { id: { $in: [...productIds] } },
1401
+ ...[narrowing, ...filters.conditions].map((c) => ({ [raw(c.sql, c.params)]: [] })),
1402
+ ],
1403
+ });
1404
+ const visibleIds = await this.#availableAmong(em, rows, scope, true);
1405
+ const passing = await filters.passes(em, rows);
1226
1406
  for (const product of rows) {
1227
1407
  if (!visibleIds.has(product.id))
1228
1408
  continue;
1229
- if (!this.#passesPageFilters(product, params, ctx))
1409
+ if (!passing.has(product.id))
1230
1410
  continue;
1231
1411
  out.set(product.id, product);
1232
1412
  }
1233
1413
  return out;
1234
1414
  }
1235
- async getProductByIdOrSlug(idOrSlug, ctx) {
1415
+ /**
1416
+ * Whether `product` may be shown to this request at (C, L), as the product page
1417
+ * answers it — the one decision both the page and the key resolution
1418
+ * (`UrlKeyResolutionService`) ask, so a key can never resolve to a product the
1419
+ * page would refuse. Throws `404 PRODUCT_NOT_FOUND` or `410 PRODUCT_ARCHIVED`;
1420
+ * answers the product's scope rows on the channel for a caller that reads on.
1421
+ */
1422
+ async assertReachable(product, ctx) {
1236
1423
  const em = this.emFactory();
1237
1424
  const channel = ctx.resolvedChannel;
1238
- const isUuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(idOrSlug);
1239
- const product = await em.findOne(Product, isUuid ? { id: idOrSlug } : { slug: idOrSlug });
1240
- if (!product || product.deletedAt) {
1241
- throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
1242
- }
1243
- if (product.status === 'inactive') {
1244
- throw new HttpError(410, ERROR_CODES.PRODUCT_ARCHIVED, 'Product is inactive.');
1425
+ const notFound = () => new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
1426
+ if (product.deletedAt)
1427
+ throw notFound();
1428
+ // Membership and the audience come first, for every product including an
1429
+ // archived one: a caller outside the channel, or outside the product's
1430
+ // effective audience there, may not learn the row exists — not even that
1431
+ // it existed (feature 163, one answer for "unavailable" and "absent").
1432
+ // Through the kernel's accessor (Constitution XII).
1433
+ const scope = this.#availabilityScope(ctx);
1434
+ const scopeRows = await loadChannelScopeRows(em, [product.id], channel.id);
1435
+ const isMember = (await this.filterByChannel([product.id], channel)).has(product.id);
1436
+ if (!isMember)
1437
+ throw notFound();
1438
+ if (!isProductVisibleTo(effectiveAudience(globalScopeFields(product), scopeRows.channelRows.get(product.id)), ctx.audience)) {
1439
+ throw notFound();
1245
1440
  }
1246
- // Visibility — if the product is not associated with the requested channel,
1247
- // behave like it doesn't exist. Avoids exposing non-public catalogue.
1248
- const visibleIds = await this.filterByChannel([product.id], channel);
1249
- if (!visibleIds.has(product.id)) {
1250
- throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
1441
+ // FR-005, O-3 (T156t) — 410 iff archived: `archived_at` alone says "gone"
1442
+ // (archiving is its own action, owner decision Q1); the status never does.
1443
+ // Otherwise 404 unless effectively available at (C, L) — a product switched
1444
+ // off globally, in the channel or in the language is not reachable by its URL.
1445
+ //
1446
+ // The 410 says "this was here and is gone", so it is answered only where
1447
+ // the product would be available to this buyer with the archive taken away —
1448
+ // `archived_at` cleared and the global status read as `active`, while every
1449
+ // channel and channel × language status, membership, the channel's languages,
1450
+ // the window and the audience still apply (security review, checkpoint B). An archived
1451
+ // product that is also switched off in this channel or language, or
1452
+ // outside its window, answers the absent product's 404: its existence
1453
+ // here is not this caller's to learn.
1454
+ if (product.archivedAt) {
1455
+ const asIfLive = {
1456
+ id: product.id,
1457
+ status: 'active',
1458
+ deletedAt: null,
1459
+ archivedAt: null,
1460
+ publishFrom: product.publishFrom ?? null,
1461
+ publishUntil: product.publishUntil ?? null,
1462
+ visibility: product.visibility,
1463
+ allowedOrganizationIds: product.allowedOrganizationIds,
1464
+ minOrderQuantity: product.minOrderQuantity ?? null,
1465
+ returnable: product.returnable,
1466
+ };
1467
+ if (!isAvailableWith(asIfLive, scopeRows, true, scope))
1468
+ throw notFound();
1469
+ throw new HttpError(410, ERROR_CODES.PRODUCT_ARCHIVED, 'Product is archived.');
1251
1470
  }
1252
- // Issue #227 — and the same answer for the audience axis. 404 rather than
1253
- // 403: a caller who may not see the row may not learn it exists either,
1254
- // and a 403 on a slug tells them it does. This is also the gate the
1255
- // `/links` and `/bundle-configuration/validate` routes stand behind, since
1256
- // both resolve their subject through here first.
1257
- if (!isProductVisibleTo(product, ctx.audience)) {
1471
+ const available = await availableAmong(em, this.#requireChannelMembership(), [product], scope, {
1472
+ membersKnown: true,
1473
+ rows: scopeRows,
1474
+ });
1475
+ if (!available.has(product.id))
1476
+ throw notFound();
1477
+ return scopeRows;
1478
+ }
1479
+ /**
1480
+ * Feature 163 (FR-074, `contracts/url-keys-and-redirects.md` §6) — the page's
1481
+ * canonical at the request's (C, L) and its alternate-language paths, built with
1482
+ * `productPath()` here because only catalog knows the channel's URL languages
1483
+ * and where the product is available. An alternate is listed only for a channel
1484
+ * language where the product is available to the **anonymous** audience,
1485
+ * whoever is asking: `hreflang` tells a crawler what it may open.
1486
+ */
1487
+ #pagePaths(product, scopeRows, ctx,
1488
+ /** The product's effective key per channel language, already read by the page. */
1489
+ keys) {
1490
+ const scope = this.#availabilityScope(ctx);
1491
+ const channel = scope.channel;
1492
+ const urlFacts = channelUrlFactsOf(ctx.resolvedChannel);
1493
+ const pathAt = (languageCode) => productPath({
1494
+ key: keys.get(languageCode) ?? product.slug,
1495
+ languageCode,
1496
+ channel: urlFacts,
1497
+ });
1498
+ const alternates = channel.languages
1499
+ .filter((languageCode) => isAvailableWith(product, scopeRows, true, {
1500
+ ...scope,
1501
+ languageCode,
1502
+ audience: ANONYMOUS_PRODUCT_AUDIENCE,
1503
+ }))
1504
+ .map((languageCode) => ({ languageCode, path: pathAt(languageCode) }));
1505
+ // Feature 167 (url-shape §8) — `x-default` is the unprefixed URL of the key at the
1506
+ // channel's default language, in both setting states.
1507
+ const xDefault = productDefaultPath(keys.get(channel.defaultLanguage) ?? product.slug);
1508
+ return { canonical: pathAt(scope.languageCode), alternates, xDefault };
1509
+ }
1510
+ /**
1511
+ * The product page's read (R28): an id; else the product whose effective key at the
1512
+ * request's (C, L) it is (`findCurrentKeyHolder`, feature 174); else a
1513
+ * product's global key, the stable handle CMS product blocks store. Never a
1514
+ * redirect: the storefront resolves a URL through `resolve` and reads by id.
1515
+ */
1516
+ async getProductByIdOrSlug(idOrSlug, ctx) {
1517
+ const em = this.emFactory();
1518
+ const channel = ctx.resolvedChannel;
1519
+ const isUuid = isUuidShape(idOrSlug);
1520
+ const product = isUuid
1521
+ ? await em.findOne(Product, { id: idOrSlug })
1522
+ : ((await findCurrentKeyHolder(em, idOrSlug, channel.id, this.#availabilityScope(ctx).languageCode)) ??
1523
+ (await em.findOne(Product, { slug: idOrSlug })));
1524
+ if (!product || product.deletedAt) {
1258
1525
  throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
1259
1526
  }
1260
- const cardReads = await this.#listingCardReadsFor(em, [product.id], channel.id);
1527
+ const scopeRows = await this.assertReachable(product, ctx);
1528
+ // The product's keys in every channel language, read once for the card's link and
1529
+ // the page's canonical and alternates (checkpoint C code review, N1).
1530
+ const keysByLanguage = (await loadEffectiveKeys(em, [product], this.#availabilityScope(ctx).channel)).get(product.id) ??
1531
+ new Map();
1532
+ const cardReads = await this.#listingCardReadsFor(em, [product], ctx, { scopeRows, keysByLanguage });
1261
1533
  const summary = this.toSummary(product, channel, ctx.preferredLanguage, await this.#listingPricesFor([product], ctx), cardReads);
1262
1534
  // Issue #384 — the product's override rows, already read for the summary.
1263
1535
  const overrides = cardReads.overridesByProduct.get(product.id);
@@ -1275,7 +1547,7 @@ export class CatalogQueryService {
1275
1547
  // Assets
1276
1548
  const assetRows = await em.execute(`select asset_id, position from product_assets where product_id = ? order by position asc`, [product.id]);
1277
1549
  const assetIds = assetRows.map((r) => r.asset_id);
1278
- const assets = await this.#requireAssets().findByIds(assetIds);
1550
+ const allAssets = await this.#requireAssets().findByIds(assetIds);
1279
1551
  // Variants
1280
1552
  const variants = product.type === 'configurable' ? await em.find(ProductVariant, { parentProductId: product.id }) : [];
1281
1553
  // Feature 002 — Attribute Set wired to this Product. Pulled in a
@@ -1287,25 +1559,55 @@ export class CatalogQueryService {
1287
1559
  // Feature 002 US3 — eager-load gallery + attachments for the PDP.
1288
1560
  // Gallery: items + label bridge zipped per item; Asset urls
1289
1561
  // resolved into a flat shape the storefront can render directly.
1290
- const galleryItems = await em.find(GalleryItem, { productId: product.id }, { orderBy: { position: 'asc', id: 'asc' } });
1291
- const galleryAssetIds = galleryItems.map((g) => g.assetId);
1562
+ // Feature 163 (FR-076, R14), feature 174 (data-model §6) — the gallery as the request's
1563
+ // (channel, language) shows it: hidden items dropped, each role at its scope holder
1564
+ // (`effectiveGallery`), each alt text at the scope.
1565
+ const scopeLanguage = this.#availabilityScope(ctx).languageCode;
1566
+ const readScope = { channelId: channel.id, languageCode: scopeLanguage };
1567
+ const storedGalleryItems = await em.find(GalleryItem, { productId: product.id }, { orderBy: { position: 'asc', id: 'asc' } });
1568
+ const galleryLabels = storedGalleryItems.length > 0
1569
+ ? await em.find(GalleryItemLabel, { productId: product.id })
1570
+ : [];
1571
+ const globalLabelsByItem = new Map();
1572
+ for (const l of galleryLabels) {
1573
+ const existing = globalLabelsByItem.get(l.galleryItemId) ?? [];
1574
+ existing.push(l.label);
1575
+ globalLabelsByItem.set(l.galleryItemId, existing);
1576
+ }
1577
+ const galleryOverrides = storedGalleryItems.length > 0
1578
+ ? (await loadGalleryScopes(em, [product.id], readScope)).get(product.id)
1579
+ : undefined;
1580
+ const galleryItems = effectiveGallery(storedGalleryItems.map((item) => ({ id: item.id, item, labels: globalLabelsByItem.get(item.id) ?? [] })), galleryOverrides);
1581
+ const labelsByItem = new Map(galleryItems.map((g) => [g.id, g.labels]));
1582
+ const galleryAssetIds = galleryItems.map((g) => g.item.assetId);
1292
1583
  const galleryAssetsById = new Map();
1293
1584
  if (galleryAssetIds.length > 0) {
1294
1585
  const galleryAssets = await this.#requireAssets().findByIds(galleryAssetIds);
1295
1586
  for (const a of galleryAssets)
1296
1587
  galleryAssetsById.set(a.id, a);
1297
1588
  }
1298
- const galleryLabels = galleryItems.length > 0
1299
- ? await em.find(GalleryItemLabel, { productId: product.id })
1300
- : [];
1301
- const labelsByItem = new Map();
1302
- for (const l of galleryLabels) {
1303
- const existing = labelsByItem.get(l.galleryItemId) ?? [];
1304
- existing.push(l.label);
1305
- labelsByItem.set(l.galleryItemId, existing);
1306
- }
1589
+ // An image hidden in the channel stays hidden when a legacy `product_assets` row
1590
+ // names the same asset.
1591
+ const hiddenAssetIds = new Set(storedGalleryItems.filter((item) => galleryOverrides?.hidden.has(item.id)).map((item) => item.assetId));
1592
+ const assets = allAssets.filter((asset) => !hiddenAssetIds.has(asset.id));
1593
+ // FR-077 (R15), feature 174 (T035) — the image's alt text at (C, L): its override there
1594
+ // (`''` for an empty one: a decorative image, rendered `alt=""`), else its Global alt
1595
+ // text, else the asset's alt text through the existing pick; `null` = none.
1596
+ const altTextOf = (item, asset) => galleryOverrides?.altText.get(item.id) ??
1597
+ item.altText ??
1598
+ (asset.altText ? this.pickLang(asset.altText, ctx.preferredLanguage, channel) : null);
1307
1599
  // Attachments + their types, eager-loaded in two queries.
1308
- const attachmentRows = await em.find(ProductAttachment, { productId: product.id }, { orderBy: { position: 'asc', id: 'asc' } });
1600
+ // Feature 163 (FR-078, R16), feature 174 (data-model §7) — each attachment's name,
1601
+ // description and hidden flag at (C, L); a hidden one is neither listed nor named
1602
+ // here (its asset is not even read).
1603
+ const storedAttachmentRows = await em.find(ProductAttachment, { productId: product.id }, { orderBy: { position: 'asc', id: 'asc' } });
1604
+ const attachmentsAtScope = await loadAttachmentsAtScope(em, product.id, storedAttachmentRows.map((row) => ({
1605
+ id: row.id,
1606
+ name: row.name,
1607
+ description: row.description ?? null,
1608
+ hidden: row.hidden === true,
1609
+ })), readScope);
1610
+ const attachmentRows = storedAttachmentRows.filter((row) => attachmentsAtScope.get(row.id)?.hidden !== true);
1309
1611
  const attachmentTypeIds = [...new Set(attachmentRows.map((a) => a.attachmentTypeId))];
1310
1612
  const attachmentTypesById = new Map();
1311
1613
  if (attachmentTypeIds.length > 0) {
@@ -1320,7 +1622,7 @@ export class CatalogQueryService {
1320
1622
  for (const a of aAssets)
1321
1623
  attachmentAssetsById.set(a.id, a);
1322
1624
  }
1323
- const descriptionText = effectiveSystemText(overrides, 'description', overrideCtx, product.description, this.pickLang(product.description, ctx.preferredLanguage, channel));
1625
+ const descriptionText = effectiveSystemText(overrides, 'description', overrideCtx, product.description) ?? '';
1324
1626
  // The summary's name went through the same resolution.
1325
1627
  const nameText = summary.name;
1326
1628
  // Issue #384 — channel-scoped user attributes carry their override for
@@ -1329,10 +1631,7 @@ export class CatalogQueryService {
1329
1631
  // at most once for this page, and only by whichever step needs them first.
1330
1632
  let attributeViews;
1331
1633
  const listAttributeViews = () => (attributeViews ??= this.#requireAttributeRead().listAll());
1332
- const attributeValues = await effectiveAttributeValues(product.attributeValues ?? {}, overrides, overrideCtx, async () => new Map((await listAttributeViews()).map((a) => [
1333
- a.key,
1334
- { channelScoped: a.channelScoped, languageScoped: a.languageScoped },
1335
- ])));
1634
+ const attributeValues = await effectiveAttributeValues(product.attributeValues ?? {}, overrides, overrideCtx, async () => new Map((await listAttributeViews()).map((a) => [a.key, a.scopeLevels])));
1336
1635
  // Feature 012 / FR-030 — "Parametry produktu" tab projection.
1337
1636
  // Resolve every attribute that is flagged isVisibleOnProductPage
1338
1637
  // AND has a non-empty value on this product. Render the value per
@@ -1340,6 +1639,27 @@ export class CatalogQueryService {
1340
1639
  // formatted scalar otherwise). Sorted by AttributeSetAttribute
1341
1640
  // position when assigned, by attribute key otherwise.
1342
1641
  const visibleAttributes = await this.buildVisibleAttributesProjection(em, product, attributeValues, ctx.preferredLanguage, channel, listAttributeViews);
1642
+ // T097 — OG image prefers gallery Base Image (then Thumbnail, then
1643
+ // primaryAssetUrl). Base Image is the marketer's hero shot, so social
1644
+ // shares should land on it.
1645
+ const labelled = (label) => galleryItems
1646
+ .map((g) => ({ asset: galleryAssetsById.get(g.item.assetId) ?? null, labels: labelsByItem.get(g.id) ?? [] }))
1647
+ .find((g) => g.asset && g.labels.includes(label))?.asset ?? null;
1648
+ const derivedSeo = {
1649
+ title: nameText,
1650
+ description: descriptionText.slice(0, 160),
1651
+ ogTitle: nameText,
1652
+ ogDescription: descriptionText.slice(0, 240),
1653
+ ogImageUrl: labelled('base_image')?.storageUrl ?? labelled('thumbnail')?.storageUrl ?? summary.primaryAssetUrl,
1654
+ };
1655
+ // Feature 163 (R13, Q-A) — the operator's overrides at (C, L), field by
1656
+ // field, over the derived values; the derived ones alone while `seo` is off.
1657
+ const seoMeta = (await this.seoProductMeta?.({
1658
+ productId: product.id,
1659
+ channelId: channel.id,
1660
+ languageCode: this.#availabilityScope(ctx).languageCode,
1661
+ fallback: derivedSeo,
1662
+ })) ?? derivedSeo;
1343
1663
  const detail = {
1344
1664
  ...summary,
1345
1665
  description: descriptionText,
@@ -1361,34 +1681,14 @@ export class CatalogQueryService {
1361
1681
  name: this.pickLang(c.name, ctx.preferredLanguage, channel),
1362
1682
  slug: c.slug,
1363
1683
  })),
1684
+ paths: this.#pagePaths(product, scopeRows, ctx, keysByLanguage),
1364
1685
  seo: {
1365
- metaTitle: nameText,
1366
- metaDescription: descriptionText.slice(0, 160),
1686
+ metaTitle: seoMeta.title,
1687
+ metaDescription: seoMeta.description,
1367
1688
  openGraph: {
1368
- title: nameText,
1369
- description: descriptionText.slice(0, 240),
1370
- // T097 — OG image prefers gallery Base Image (then Thumbnail,
1371
- // then primaryAssetUrl). Base Image is the marketer's hero
1372
- // shot, so social shares should land on it.
1373
- imageUrl: (() => {
1374
- const base = galleryItems
1375
- .map((g) => ({
1376
- asset: galleryAssetsById.get(g.assetId) ?? null,
1377
- labels: labelsByItem.get(g.id) ?? [],
1378
- }))
1379
- .find((g) => g.asset && g.labels.includes('base_image'));
1380
- if (base?.asset)
1381
- return base.asset.storageUrl;
1382
- const thumb = galleryItems
1383
- .map((g) => ({
1384
- asset: galleryAssetsById.get(g.assetId) ?? null,
1385
- labels: labelsByItem.get(g.id) ?? [],
1386
- }))
1387
- .find((g) => g.asset && g.labels.includes('thumbnail'));
1388
- if (thumb?.asset)
1389
- return thumb.asset.storageUrl;
1390
- return summary.primaryAssetUrl;
1391
- })(),
1689
+ title: seoMeta.ogTitle,
1690
+ description: seoMeta.ogDescription,
1691
+ imageUrl: seoMeta.ogImageUrl,
1392
1692
  },
1393
1693
  },
1394
1694
  structuredDataJsonLd: {
@@ -1420,15 +1720,16 @@ export class CatalogQueryService {
1420
1720
  }
1421
1721
  : {}),
1422
1722
  gallery: galleryItems.flatMap((g) => {
1423
- const a = galleryAssetsById.get(g.assetId);
1723
+ const a = galleryAssetsById.get(g.item.assetId);
1424
1724
  if (!a)
1425
1725
  return [];
1426
1726
  return [
1427
1727
  {
1428
1728
  id: g.id,
1429
- position: g.position,
1430
- labels: [...(labelsByItem.get(g.id) ?? [])].sort(),
1729
+ position: g.item.position,
1730
+ labels: [...g.labels].sort(),
1431
1731
  asset: { id: a.id, kind: a.kind, url: a.storageUrl },
1732
+ altText: altTextOf(g.item, a),
1432
1733
  },
1433
1734
  ];
1434
1735
  }),
@@ -1441,8 +1742,10 @@ export class CatalogQueryService {
1441
1742
  {
1442
1743
  id: row.id,
1443
1744
  position: row.position,
1444
- name: row.name,
1445
- description: row.description ?? null,
1745
+ name: attachmentsAtScope.get(row.id)?.name ?? row.name,
1746
+ description: attachmentsAtScope.has(row.id)
1747
+ ? attachmentsAtScope.get(row.id).description
1748
+ : (row.description ?? null),
1446
1749
  type: { id: t.id, code: t.code, name: t.name },
1447
1750
  asset: {
1448
1751
  id: a.id,
@@ -1535,9 +1838,11 @@ export class CatalogQueryService {
1535
1838
  if (product.type === 'simple' || product.type === 'configurable') {
1536
1839
  const packagingUnits = await em.find(ProductPackagingUnit, { productId: product.id }, { orderBy: { position: 'asc', name: 'asc' } });
1537
1840
  if (packagingUnits.length > 0) {
1841
+ // Feature 174 (data-model §7) — each unit's name at (C, L); `''` for an empty override.
1842
+ const unitNames = await loadPackagingUnitNamesAtScope(em, product.id, packagingUnits, readScope);
1538
1843
  detail.packagingUnits = packagingUnits.map((u) => ({
1539
1844
  id: u.id,
1540
- name: u.name,
1845
+ name: unitNames.get(u.id) ?? u.name,
1541
1846
  baseQuantity: u.baseQuantity,
1542
1847
  position: u.position,
1543
1848
  isDefault: u.isDefault,
@@ -1559,22 +1864,29 @@ export class CatalogQueryService {
1559
1864
  const result = new Map();
1560
1865
  if (ids.length === 0)
1561
1866
  return result;
1562
- const products = await em.find(Product, { id: { $in: ids } });
1867
+ // Feature 163 — a child or option off at (C, L), outside its window or
1868
+ // outside the audience is not offered through its parent (edge case
1869
+ // *child off*): it is left out of the composite, as an absent one is.
1870
+ const candidates = await em.find(Product, { id: { $in: ids } });
1871
+ const available = await this.#availableAmong(em, candidates, this.#availabilityScope(ctx), false);
1872
+ const products = candidates.filter((p) => available.has(p.id));
1563
1873
  // Primary asset url via gallery thumb chain -> base_image -> first item
1564
1874
  // -> legacy product_assets first row. One helper, shared with `toSummary`
1565
1875
  // and `ProductLinkService`, so the chain and the port call have one home.
1566
- const assetUrlByProduct = await resolvePrimaryAssetUrls(em, this.#requireAssets(), ids);
1876
+ const assetUrlByProduct = await resolvePrimaryAssetUrls(em, this.#requireAssets(), ids, channel.id, this.#availabilityScope(ctx).languageCode);
1567
1877
  const resolvedPrices = await this.#listingPricesFor(products, ctx);
1568
1878
  // Issue #384 — one statement for every child's override rows on this channel.
1569
1879
  const overridesByProduct = await loadChannelOverridesByProduct(em, ids, channel.id);
1570
1880
  const overrideCtx = this.#overrideContext(channel, ctx.preferredLanguage);
1881
+ // Feature 163 (R28) — a child's link is its effective key at (C, L).
1882
+ const effectiveKeys = await this.#effectiveKeysAt(em, products, ctx);
1571
1883
  for (const p of products) {
1572
1884
  const price = this.#summaryPrice(resolvedPrices, p.id);
1573
1885
  result.set(p.id, {
1574
1886
  id: p.id,
1575
1887
  sku: p.sku,
1576
- slug: p.slug,
1577
- name: effectiveSystemText(overridesByProduct.get(p.id), 'name', overrideCtx, p.name, this.pickLang(p.name, ctx.preferredLanguage, channel)),
1888
+ slug: effectiveKeys.get(p.id) ?? p.slug,
1889
+ name: effectiveSystemText(overridesByProduct.get(p.id), 'name', overrideCtx, p.name) ?? '',
1578
1890
  primaryAssetUrl: assetUrlByProduct.get(p.id) ?? null,
1579
1891
  price,
1580
1892
  });
@@ -1592,7 +1904,7 @@ export class CatalogQueryService {
1592
1904
  // roots seed the walk.
1593
1905
  const rows = await em.find(Category, { deletedAt: null, isActive: true }, { orderBy: { sortOrder: 'asc' } });
1594
1906
  // Directly-assigned products per category that this caller may see.
1595
- const directSets = await this.directProductSetsByCategory(em, channel, ctx.audience);
1907
+ const directSets = await this.directProductSetsByCategory(em, channel, this.#availabilityScope(ctx));
1596
1908
  const byParent = new Map();
1597
1909
  for (const row of rows) {
1598
1910
  const key = row.parentCategoryId ?? null;
@@ -1649,7 +1961,8 @@ export class CatalogQueryService {
1649
1961
  */
1650
1962
  async getCategoryPageContent(categoryId, ctx) {
1651
1963
  const notFound = () => new HttpError(404, ERROR_CODES.NOT_FOUND, 'Category not found.');
1652
- if (!CATEGORY_ID_RE.test(categoryId))
1964
+ // A category id as the database spells one — anything else is a 404, not a query.
1965
+ if (!isUuidShape(categoryId))
1653
1966
  throw notFound();
1654
1967
  const em = this.emFactory();
1655
1968
  const category = await em.findOne(Category, { id: categoryId, deletedAt: null, isActive: true }, { populate: ['content'] });
@@ -1672,21 +1985,59 @@ export class CatalogQueryService {
1672
1985
  throw notFound();
1673
1986
  parentId = parent.parentCategoryId ?? null;
1674
1987
  }
1675
- const languages = category.content?.languages ?? {};
1676
- const candidates = [
1677
- ctx.preferredLanguage,
1678
- ctx.resolvedChannel.defaultLanguage,
1679
- 'en-US',
1680
- 'en',
1681
- ...Object.keys(languages),
1682
- ].filter((v) => typeof v === 'string');
1683
- for (const language of candidates) {
1684
- const tree = languages[language];
1685
- if (tree !== undefined && hasPageBuilderBlocks(tree)) {
1686
- return { categoryId: category.id, language, content: tree };
1687
- }
1988
+ // Feature 172 (research R-12) — the one language walk product content shares.
1989
+ const resolved = resolvePageBuilderLanguage(category.content?.languages ?? {}, ctx);
1990
+ return resolved
1991
+ ? { categoryId: category.id, language: resolved.language, content: resolved.document }
1992
+ : { categoryId: category.id, language: null, content: null };
1993
+ }
1994
+ /**
1995
+ * Feature 172 (`specs/172-product-content-attributes/`, FR-030, FR-033,
1996
+ * FR-061, research R-11) — the product page's Page Builder content
1997
+ * attributes, each resolved to one language.
1998
+ *
1999
+ * Called by the public product route **after** `getProductByIdOrSlug` has
2000
+ * decided the product is visible to this request (channel, audience,
2001
+ * organisation): it adds no read path of its own around those rules
2002
+ * (Principles XI, XII), and the external API and every port never call it
2003
+ * (FR-042). Candidates are the `page_builder` members of the product's
2004
+ * **current** set, by position then key; a document is resolved by the
2005
+ * language walk category content uses, and an attribute with no language
2006
+ * holding a block is left out. No label is carried (FR-037).
2007
+ */
2008
+ async getProductPageContent(productId, attributeSetId, ctx) {
2009
+ // FR-051 — with the CMS off the page carries no content; the rows stay
2010
+ // untouched (FR-050, SC-004) and come back with it (FR-052).
2011
+ if (!this.isPageBuilderPresent?.())
2012
+ return [];
2013
+ if (!attributeSetId)
2014
+ return [];
2015
+ const em = this.emFactory();
2016
+ const rows = (await em.execute(`select custom_field_definition_id, position from attribute_set_attributes where attribute_set_id = ?`, [attributeSetId]));
2017
+ if (rows.length === 0)
2018
+ return [];
2019
+ const members = contentAttributeMembers(rows, await this.#requireAttributeRead().listAll());
2020
+ if (members.length === 0)
2021
+ return [];
2022
+ const values = (await em.execute(`select pcv.product_attribute_id, pcv.content
2023
+ from product_content_values pcv
2024
+ join products p on p.id = pcv.product_id
2025
+ where pcv.product_id = ? and p.deleted_at is null
2026
+ and pcv.product_attribute_id in (${members.map(() => '?').join(', ')})`, [productId, ...members.map((member) => member.attributeId)]));
2027
+ const contentByAttribute = new Map(values.map((row) => [
2028
+ row.product_attribute_id,
2029
+ (typeof row.content === 'string' ? JSON.parse(row.content) : row.content),
2030
+ ]));
2031
+ const resolved = [];
2032
+ for (const member of members) {
2033
+ const envelope = contentByAttribute.get(member.attributeId);
2034
+ if (!envelope)
2035
+ continue;
2036
+ const chosen = resolvePageBuilderLanguage(envelope.languages ?? {}, ctx);
2037
+ if (chosen)
2038
+ resolved.push({ key: member.key, language: chosen.language, content: chosen.document });
1688
2039
  }
1689
- return { categoryId: category.id, language: null, content: null };
2040
+ return resolved;
1690
2041
  }
1691
2042
  // ------------------------------------------------------------------
1692
2043
  // Filters
@@ -1695,13 +2046,29 @@ export class CatalogQueryService {
1695
2046
  const em = this.emFactory();
1696
2047
  const channel = ctx.resolvedChannel;
1697
2048
  const attrs = await this.#requireAttributeRead().listByFlag('isFilterable');
1698
- // Build option / range facets by scanning Products in the channel.
1699
- const products = await em.find(Product, { status: 'active', deletedAt: null });
1700
- const visibleIds = await this.filterByChannel(products.map((p) => p.id), channel);
1701
- // Issue #227 — a facet count is a disclosure too. "Brass (3)" on a
2049
+ // Build option / range facets by scanning Products available in the
2050
+ // channel. Issue #227 — a facet count is a disclosure too. "Brass (3)" on a
1702
2051
  // catalogue holding two brass products the caller may see is the third
1703
- // one, named by arithmetic.
1704
- const visible = products.filter((p) => visibleIds.has(p.id) && isProductVisibleTo(p, ctx.audience));
2052
+ // one, named by arithmetic; feature 163 extends that to a product off at
2053
+ // (C, L) or outside its window. Availability is in the statement and then
2054
+ // the rule's own word on each row; the `raw()` key is made in the
2055
+ // expression that executes it.
2056
+ const scope = this.#availabilityScope(ctx);
2057
+ const narrowing = this.#availabilityNarrowing(scope);
2058
+ const products = await em.find(Product, {
2059
+ $and: [{ deletedAt: null }, { [raw(narrowing.sql, narrowing.params)]: [] }],
2060
+ });
2061
+ const visibleIds = await this.#availableAmong(em, products, scope, true);
2062
+ const visible = products.filter((p) => visibleIds.has(p.id));
2063
+ // Feature 163 (FR-017 b) — counts over the effective values a card shows at
2064
+ // (channel, language): #384's walk over this channel's override rows.
2065
+ const effective = this.#overrideContext(channel, ctx.preferredLanguage);
2066
+ const scopeOf = new Map(attrs.map((a) => [a.key, a.scopeLevels]));
2067
+ const overrides = await loadChannelOverridesByProduct(em, visible.map((p) => p.id), channel.id);
2068
+ const valuesOf = new Map();
2069
+ for (const p of visible) {
2070
+ valuesOf.set(p.id, await effectiveAttributeValues(p.attributeValues ?? {}, overrides.get(p.id), effective, async () => scopeOf));
2071
+ }
1705
2072
  const definitions = attrs.map((a) => {
1706
2073
  const label = this.pickLang(a.label, ctx.preferredLanguage, channel);
1707
2074
  const def = {
@@ -1717,7 +2084,7 @@ export class CatalogQueryService {
1717
2084
  a.valueType === 'string') {
1718
2085
  const optionCounts = new Map();
1719
2086
  for (const p of visible) {
1720
- const v = p.attributeValues[a.key];
2087
+ const v = valuesOf.get(p.id)?.[a.key];
1721
2088
  if (v === undefined || v === null)
1722
2089
  continue;
1723
2090
  // multiselect carries an array of selected option values.
@@ -1742,7 +2109,7 @@ export class CatalogQueryService {
1742
2109
  let min;
1743
2110
  let max;
1744
2111
  for (const p of visible) {
1745
- const raw = p.attributeValues[a.key];
2112
+ const raw = valuesOf.get(p.id)?.[a.key];
1746
2113
  const n = typeof raw === 'number' ? raw : Number(raw);
1747
2114
  if (!Number.isFinite(n))
1748
2115
  continue;
@@ -1919,11 +2286,6 @@ export class CatalogQueryService {
1919
2286
  });
1920
2287
  return items;
1921
2288
  }
1922
- /** Cached per-call list of attribute keys that should match free-text search. */
1923
- async searchableAttributeKeys(_em) {
1924
- const attrs = await this.#requireAttributeRead().listByFlag('isSearchable');
1925
- return attrs.map((a) => a.key);
1926
- }
1927
2289
  /**
1928
2290
  * Feature 007 — list of attribute keys flagged `is_comparable=true`,
1929
2291
  * sorted alphabetically. Consumed by the comparisons module's
@@ -1979,68 +2341,42 @@ export class CatalogQueryService {
1979
2341
  options,
1980
2342
  };
1981
2343
  }
1982
- /**
1983
- * Build a MikroORM where-clause for "attributeValues[key] contains query
1984
- * (case-insensitive)". MikroORM doesn't have a first-class JSONB query
1985
- * helper for the `->>` operator, so we use `$jsonb` style by selecting the
1986
- * value via the operators object.
1987
- */
1988
- searchableJsonbClause(key, query) {
1989
- // expr` returns the property at `key` cast to text; ILIKE handles
1990
- // case-insensitivity. We rely on MikroORM's `raw()` operator-form passed
1991
- // through to Knex.
1992
- return { [key]: { $ilike: `%${query}%` } };
1993
- }
1994
- orderForSort(sort) {
1995
- switch (sort) {
1996
- case 'name':
1997
- return { slug: 'asc', id: 'asc' };
1998
- case '-name':
1999
- return { slug: 'desc', id: 'desc' };
2000
- case '-createdAt':
2001
- case 'relevance':
2002
- default:
2003
- return { createdAt: 'desc', id: 'desc' };
2004
- }
2005
- }
2006
2344
  /**
2007
2345
  * The keyset a listing pages by — **derived from the ordering it serves**,
2008
- * never assumed.
2009
- *
2010
- * A chunk is fetched with `orderForSort(sort)` and the walk then asks for
2011
- * "everything after the last row of it". Those are one decision, and they had
2012
- * come apart: the `after` predicate was written over `created_at` whatever the
2013
- * ordering, so under `sort=name` — which orders by `slug` — it excluded the
2014
- * rows *newer* than the last one served instead of the rows already served.
2015
- * That set has no relation to the page, so the walk both repeats products and
2016
- * never reaches the ones between the repeats:
2017
- * `?q=…&sort=name&minPrice=0&maxPrice=100000&limit=3` served
2018
- * `[A, B, A]` on one page and then re-issued a cursor pointing at `B`.
2346
+ * never assumed. The ordering and the "everything after this row" predicate
2347
+ * are one decision, and they had come apart once: the `after` predicate was
2348
+ * written over `created_at` whatever the ordering, so under `sort=name` the
2349
+ * walk both repeated products and skipped the ones between the repeats.
2019
2350
  *
2020
- * Deriving it here is what keeps the two in step for the next ordering
2021
- * somebody adds: `orderForSort` is the only place that says what a sort orders
2022
- * by, and this is the only place that says how to page it.
2351
+ * Feature 163 (D6) — the name ordering is the **effective** name a card shows
2352
+ * at the request's (channel, language), `effectiveTextSql`, with `id` as the
2353
+ * tie-break (the name is not unique). It replaced an ordering by `slug`.
2023
2354
  */
2024
- keysetFor(sort) {
2025
- const order = this.orderForSort(sort);
2026
- const slugDirection = order['slug'];
2027
- if (slugDirection !== undefined) {
2028
- // `slug` is unique, so the `id` tie-break can never fire. It is written
2029
- // anyway because the ordering names it, and a keyset that drops a column
2030
- // its ordering carries is the defect above in miniature.
2031
- const op = slugDirection === 'asc' ? '$gt' : '$lt';
2355
+ #keysetFor(sort, ctx) {
2356
+ if (sort === 'name' || sort === '-name') {
2357
+ const direction = sort === 'name' ? 'asc' : 'desc';
2358
+ const cmp = direction === 'asc' ? '>' : '<';
2359
+ const name = this.#effectiveNameExpr(ctx);
2032
2360
  return {
2033
- of: (product) => ({ slug: product.slug, id: product.id }),
2034
- parse: (decoded) => isRecord(decoded) && typeof decoded['slug'] === 'string' && isUuidText(decoded['id'])
2035
- ? { slug: decoded['slug'], id: decoded['id'] }
2361
+ byName: true,
2362
+ of: (product, nameOf) => ({ name: nameOf(product.id) ?? '', id: product.id }),
2363
+ parse: (decoded) => isRecord(decoded) && typeof decoded['name'] === 'string' && isUuidText(decoded['id'])
2364
+ ? { name: decoded['name'], id: decoded['id'] }
2036
2365
  : null,
2037
- after: (cursor) => afterKeysetCursor(cursor, op),
2366
+ after: (cursor) => {
2367
+ if (!('name' in cursor))
2368
+ return {};
2369
+ return {
2370
+ [raw((alias) => `(${name.sql(alias)} ${cmp} ? or (${name.sql(alias)} = ? and ${alias}.id ${cmp} ?))`, [...name.params, cursor.name, ...name.params, cursor.name, cursor.id])]: [],
2371
+ };
2372
+ },
2373
+ orderBy: () => ({ [raw((alias) => name.sql(alias), name.params)]: direction, id: direction }),
2038
2374
  };
2039
2375
  }
2040
2376
  // The default ordering is `createdAt desc, id desc`, in every sort that
2041
- // reaches here, so the direction is not read off the map the way the slug
2042
- // one is — it has nothing to read.
2377
+ // reaches here.
2043
2378
  return {
2379
+ byName: false,
2044
2380
  of: (product) => ({ createdAt: product.createdAt.toISOString(), id: product.id }),
2045
2381
  // The id is compared with a uuid column: a cursor naming anything else is
2046
2382
  // discarded here rather than refused by the database as a 500.
@@ -2051,8 +2387,37 @@ export class CatalogQueryService {
2051
2387
  ? { createdAt: decoded['createdAt'], id: decoded['id'] }
2052
2388
  : null,
2053
2389
  after: (cursor) => afterKeysetCursor(cursor, '$lt'),
2390
+ orderBy: () => ({ createdAt: 'desc', id: 'desc' }),
2054
2391
  };
2055
2392
  }
2393
+ /**
2394
+ * Feature 163 (FR-017 b) — the effective Name a card shows at the request's
2395
+ * (channel, language), as SQL: the value the listing searches and sorts on.
2396
+ * The same two language chains `toSummary` uses (`#overrideContext` and
2397
+ * `pickLang`).
2398
+ */
2399
+ #effectiveNameExpr(ctx) {
2400
+ const channel = ctx.resolvedChannel;
2401
+ return effectiveTextSql('name', this.#overrideContext(channel, ctx.preferredLanguage));
2402
+ }
2403
+ /**
2404
+ * The names a name cursor carries — **the statement's own sort key**, read by
2405
+ * the same `effectiveTextSql` expression the ordering and the `after`
2406
+ * predicate use (`#keysetFor`), so the cursor can never disagree with the
2407
+ * order it continues (code review W4). It used to be recomputed by the
2408
+ * TypeScript walk, which is held equal to the SQL by a parity test but is a
2409
+ * second implementation: when the two diverged, a walk repeated and skipped
2410
+ * rows. One keyed statement over the page's last row — the read it replaces
2411
+ * cost the same — and nothing when the keyset does not need it.
2412
+ */
2413
+ async #cursorNames(em, keyset, products, ctx) {
2414
+ if (!keyset.byName || products.length === 0)
2415
+ return () => undefined;
2416
+ const name = this.#effectiveNameExpr(ctx);
2417
+ const rows = await em.execute(`select p.id::text as id, ${name.sql('p')} as name from products p where p.id = any(?::uuid[])`, [...name.params, uuidArrayLiteral(products.map((p) => p.id))]);
2418
+ const names = new Map(rows.map((row) => [row.id, row.name ?? '']));
2419
+ return (productId) => names.get(productId);
2420
+ }
2056
2421
  async filterByChannel(productIds, channel) {
2057
2422
  if (productIds.length === 0)
2058
2423
  return new Set();
@@ -2106,26 +2471,24 @@ export class CatalogQueryService {
2106
2471
  * (i.e. via a `product_categories` row). Subtree roll-up to ancestors is
2107
2472
  * done by the caller, which has the parent map to walk.
2108
2473
  */
2109
- async directProductSetsByCategory(em, channel, audience) {
2474
+ async directProductSetsByCategory(em, channel, scope) {
2110
2475
  const base = await em.execute(`select category_id, product_id from product_categories`);
2111
2476
  if (base.length === 0)
2112
2477
  return new Map();
2113
2478
  // Channel membership.
2114
- const visibleIds = await this.filterByChannel(base.map((r) => r.product_id), channel);
2115
- // Issue #227 — and the audience axis, which needs the two columns this
2116
- // path never loaded: `product_categories` carries ids and nothing else, so
2117
- // the rows come back here rather than the predicate going down there. The
2118
- // category tree publishes a `productCount` per node, and a count is the
2119
- // one field a restricted product can still move.
2120
- const restricted = new Set((await em.find(Product, { id: { $in: [...visibleIds] } }, { fields: ['id', 'visibility', 'allowedOrganizationIds'] }))
2121
- .filter((p) => !isProductVisibleTo(p, audience))
2122
- .map((p) => p.id));
2479
+ const memberIds = await this.filterByChannel(base.map((r) => r.product_id), channel);
2480
+ // Issue #227 / feature 163 — and availability, which needs the columns
2481
+ // this path never loaded: `product_categories` carries ids and nothing
2482
+ // else, so the rows come back here rather than the predicate going down
2483
+ // there. The category tree publishes a `productCount` per node, and a count
2484
+ // is the one field a restricted, switched-off or out-of-window product can
2485
+ // still move.
2486
+ const members = await em.find(Product, { id: { $in: [...memberIds] } });
2487
+ const visibleIds = await this.#availableAmong(em, members, scope, true);
2123
2488
  const sets = new Map();
2124
2489
  for (const row of base) {
2125
2490
  if (!visibleIds.has(row.product_id))
2126
2491
  continue;
2127
- if (restricted.has(row.product_id))
2128
- continue;
2129
2492
  let set = sets.get(row.category_id);
2130
2493
  if (!set) {
2131
2494
  set = new Set();
@@ -2152,28 +2515,34 @@ export class CatalogQueryService {
2152
2515
  */
2153
2516
  toSummary(product, channel, preferredLanguage, resolvedPrices, cardReads) {
2154
2517
  // Price — the pricing engine's answer for this product on this channel
2155
- // (issue #132), read out of the page's resolution. Sales Channel visibility
2156
- // still strips it on a non-public channel; what changed is that the figure
2157
- // underneath is one a price list stands behind rather than the catalogue's
2158
- // own legacy attribute.
2518
+ // (issue #132), read out of the page's resolution — a figure a price book
2519
+ // stands behind, or nothing where the viewer's display mode withholds it.
2159
2520
  const price = this.#summaryPrice(resolvedPrices, product.id);
2160
2521
  // Issue #384 — the channel's override when one applies, else the baseline
2161
2522
  // language pick, out of the page's pre-read override rows.
2162
- const nameText = effectiveSystemText(cardReads.overridesByProduct.get(product.id), 'name', this.#overrideContext(channel, preferredLanguage), product.name, this.pickLang(product.name, preferredLanguage, channel));
2523
+ const nameText = effectiveSystemText(cardReads.overridesByProduct.get(product.id), 'name', this.#overrideContext(channel, preferredLanguage), product.name) ?? '';
2524
+ // Feature 163 (R-16) — the card's summary, from the description this row
2525
+ // already holds, through the same override and language pick as the PDP's.
2526
+ const descriptionText = effectiveSystemText(cardReads.overridesByProduct.get(product.id), 'description', this.#overrideContext(channel, preferredLanguage), product.description) ?? '';
2163
2527
  return {
2164
2528
  id: product.id,
2165
2529
  sku: product.sku,
2166
2530
  type: product.type,
2167
2531
  name: nameText,
2168
- slug: product.slug,
2532
+ // Feature 163 (R28) — the effective key at the request's (channel, language).
2533
+ slug: cardReads.effectiveKeyByProduct.get(product.id) ?? product.slug,
2534
+ summary: productSummaryText(descriptionText),
2169
2535
  categorySlugs: cardReads.categorySlugsByProduct.get(product.id) ?? [],
2170
2536
  primaryAssetUrl: cardReads.assetUrlByProduct.get(product.id) ?? null,
2171
2537
  price,
2172
2538
  stockIndicator: null,
2173
2539
  stockLevel: null,
2174
2540
  // Feature 155 (FR-014) — emitted for the types the minimum applies to only.
2541
+ // Feature 163 (FR-100) — the request channel's minimum.
2175
2542
  minOrderQuantity: isOrderMinimumEligibleType(product.type)
2176
- ? (product.minOrderQuantity ?? null)
2543
+ ? (cardReads.minOrderQuantityByProduct.has(product.id)
2544
+ ? (cardReads.minOrderQuantityByProduct.get(product.id) ?? null)
2545
+ : (product.minOrderQuantity ?? null))
2177
2546
  : null,
2178
2547
  resolvedPrice: this.#summaryResolvedPrice(resolvedPrices, product.id),
2179
2548
  ...this.#summaryPriceBookFields(resolvedPrices, product.id),
@@ -2204,10 +2573,8 @@ export class CatalogQueryService {
2204
2573
  * a later one.
2205
2574
  */
2206
2575
  #overrideContext(channel, preferredLanguage) {
2207
- return {
2208
- channelId: channel.id,
2209
- languages: overrideLanguages(preferredLanguage, channel.defaultLanguage),
2210
- };
2576
+ // Feature 174 — the chain runs at the request's resolved (C, L): C×L → C → Global.
2577
+ return { channelId: channel.id, languageCode: scopeLanguageOf(channel, preferredLanguage) };
2211
2578
  }
2212
2579
  pickLang(blob, preferred, channel) {
2213
2580
  const preferredLangs = [preferred, channel?.defaultLanguage, 'en-US', 'en'].filter((v) => typeof v === 'string');