@endora-commerce/mod-catalog 0.108.0 → 0.109.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (374) hide show
  1. package/dist/admin/components/AttachmentScopesDialog.d.ts +22 -0
  2. package/dist/admin/components/AttachmentScopesDialog.d.ts.map +1 -0
  3. package/dist/admin/components/AttachmentScopesDialog.js +70 -0
  4. package/dist/admin/components/AttachmentScopesDialog.js.map +1 -0
  5. package/dist/admin/components/PackagingUnitsEditor.d.ts +7 -1
  6. package/dist/admin/components/PackagingUnitsEditor.d.ts.map +1 -1
  7. package/dist/admin/components/PackagingUnitsEditor.js +82 -11
  8. package/dist/admin/components/PackagingUnitsEditor.js.map +1 -1
  9. package/dist/admin/components/ProductAttachmentsSection.d.ts +5 -0
  10. package/dist/admin/components/ProductAttachmentsSection.d.ts.map +1 -0
  11. package/dist/admin/components/ProductAttachmentsSection.js +137 -0
  12. package/dist/admin/components/ProductAttachmentsSection.js.map +1 -0
  13. package/dist/admin/components/ProductGallerySection.d.ts +14 -0
  14. package/dist/admin/components/ProductGallerySection.d.ts.map +1 -0
  15. package/dist/admin/components/ProductGallerySection.js +385 -0
  16. package/dist/admin/components/ProductGallerySection.js.map +1 -0
  17. package/dist/admin/components/ProductOrderRulesCard.d.ts.map +1 -1
  18. package/dist/admin/components/ProductOrderRulesCard.js +134 -6
  19. package/dist/admin/components/ProductOrderRulesCard.js.map +1 -1
  20. package/dist/admin/components/ProductScopeControls.d.ts +31 -0
  21. package/dist/admin/components/ProductScopeControls.d.ts.map +1 -0
  22. package/dist/admin/components/ProductScopeControls.js +243 -0
  23. package/dist/admin/components/ProductScopeControls.js.map +1 -0
  24. package/dist/admin/components/ProductScopeEditor.d.ts +12 -18
  25. package/dist/admin/components/ProductScopeEditor.d.ts.map +1 -1
  26. package/dist/admin/components/ProductScopeEditor.js +5 -4
  27. package/dist/admin/components/ProductScopeEditor.js.map +1 -1
  28. package/dist/admin/components/ProductScopeOverview.d.ts +26 -0
  29. package/dist/admin/components/ProductScopeOverview.d.ts.map +1 -0
  30. package/dist/admin/components/ProductScopeOverview.js +207 -0
  31. package/dist/admin/components/ProductScopeOverview.js.map +1 -0
  32. package/dist/admin/components/ProductStatusPills.d.ts +17 -0
  33. package/dist/admin/components/ProductStatusPills.d.ts.map +1 -0
  34. package/dist/admin/components/ProductStatusPills.js +23 -0
  35. package/dist/admin/components/ProductStatusPills.js.map +1 -0
  36. package/dist/admin/components/ProductUrlKeysPanel.d.ts +17 -0
  37. package/dist/admin/components/ProductUrlKeysPanel.d.ts.map +1 -0
  38. package/dist/admin/components/ProductUrlKeysPanel.js +215 -0
  39. package/dist/admin/components/ProductUrlKeysPanel.js.map +1 -0
  40. package/dist/admin/components/ProductsBulkEditDialog.d.ts +30 -0
  41. package/dist/admin/components/ProductsBulkEditDialog.d.ts.map +1 -1
  42. package/dist/admin/components/ProductsBulkEditDialog.js +288 -133
  43. package/dist/admin/components/ProductsBulkEditDialog.js.map +1 -1
  44. package/dist/admin/components/ScopedDialogParts.d.ts +23 -0
  45. package/dist/admin/components/ScopedDialogParts.d.ts.map +1 -0
  46. package/dist/admin/components/ScopedDialogParts.js +16 -0
  47. package/dist/admin/components/ScopedDialogParts.js.map +1 -0
  48. package/dist/admin/index.d.ts +2 -2
  49. package/dist/admin/index.d.ts.map +1 -1
  50. package/dist/admin/index.js +9 -0
  51. package/dist/admin/index.js.map +1 -1
  52. package/dist/admin/lib/attribute-scope.d.ts +20 -0
  53. package/dist/admin/lib/attribute-scope.d.ts.map +1 -0
  54. package/dist/admin/lib/attribute-scope.js +18 -0
  55. package/dist/admin/lib/attribute-scope.js.map +1 -0
  56. package/dist/admin/lib/bulk-operation-log-text.d.ts +9 -0
  57. package/dist/admin/lib/bulk-operation-log-text.d.ts.map +1 -0
  58. package/dist/admin/lib/bulk-operation-log-text.js +13 -0
  59. package/dist/admin/lib/bulk-operation-log-text.js.map +1 -0
  60. package/dist/admin/lib/media-scopes.d.ts +41 -0
  61. package/dist/admin/lib/media-scopes.d.ts.map +1 -0
  62. package/dist/admin/lib/media-scopes.js +66 -0
  63. package/dist/admin/lib/media-scopes.js.map +1 -0
  64. package/dist/admin/lib/product-labels.d.ts +14 -0
  65. package/dist/admin/lib/product-labels.d.ts.map +1 -0
  66. package/dist/admin/lib/product-labels.js +27 -0
  67. package/dist/admin/lib/product-labels.js.map +1 -0
  68. package/dist/admin/lib/product-scope-drafts.d.ts +77 -0
  69. package/dist/admin/lib/product-scope-drafts.d.ts.map +1 -0
  70. package/dist/admin/lib/product-scope-drafts.js +133 -0
  71. package/dist/admin/lib/product-scope-drafts.js.map +1 -0
  72. package/dist/admin/lib/product-scopes-api.d.ts +40 -0
  73. package/dist/admin/lib/product-scopes-api.d.ts.map +1 -0
  74. package/dist/admin/lib/product-scopes-api.js +101 -0
  75. package/dist/admin/lib/product-scopes-api.js.map +1 -0
  76. package/dist/admin/lib/product-url-keys-api.d.ts +46 -0
  77. package/dist/admin/lib/product-url-keys-api.d.ts.map +1 -0
  78. package/dist/admin/lib/product-url-keys-api.js +110 -0
  79. package/dist/admin/lib/product-url-keys-api.js.map +1 -0
  80. package/dist/admin/lib/resolve-product-selection.d.ts +29 -1
  81. package/dist/admin/lib/resolve-product-selection.d.ts.map +1 -1
  82. package/dist/admin/lib/resolve-product-selection.js +42 -6
  83. package/dist/admin/lib/resolve-product-selection.js.map +1 -1
  84. package/dist/admin/lib/scope-overview.d.ts +74 -0
  85. package/dist/admin/lib/scope-overview.d.ts.map +1 -0
  86. package/dist/admin/lib/scope-overview.js +173 -0
  87. package/dist/admin/lib/scope-overview.js.map +1 -0
  88. package/dist/admin/pages/AttributesManager.d.ts.map +1 -1
  89. package/dist/admin/pages/AttributesManager.js +84 -7
  90. package/dist/admin/pages/AttributesManager.js.map +1 -1
  91. package/dist/admin/pages/BulkOperationDetailPage.d.ts.map +1 -1
  92. package/dist/admin/pages/BulkOperationDetailPage.js +4 -19
  93. package/dist/admin/pages/BulkOperationDetailPage.js.map +1 -1
  94. package/dist/admin/pages/ProductEditor.d.ts +0 -4
  95. package/dist/admin/pages/ProductEditor.d.ts.map +1 -1
  96. package/dist/admin/pages/ProductEditor.js +214 -346
  97. package/dist/admin/pages/ProductEditor.js.map +1 -1
  98. package/dist/admin/pages/ProductsList.d.ts +12 -0
  99. package/dist/admin/pages/ProductsList.d.ts.map +1 -1
  100. package/dist/admin/pages/ProductsList.js +105 -38
  101. package/dist/admin/pages/ProductsList.js.map +1 -1
  102. package/dist/backend/admin-search-provider.d.ts +1 -1
  103. package/dist/backend/admin-search-provider.d.ts.map +1 -1
  104. package/dist/backend/admin-search-provider.js +1 -2
  105. package/dist/backend/admin-search-provider.js.map +1 -1
  106. package/dist/backend/demo/rows.d.ts +7 -0
  107. package/dist/backend/demo/rows.d.ts.map +1 -1
  108. package/dist/backend/demo/rows.js +17 -12
  109. package/dist/backend/demo/rows.js.map +1 -1
  110. package/dist/backend/demo/seed.js +2 -2
  111. package/dist/backend/demo/seed.js.map +1 -1
  112. package/dist/backend/entities/bulk-operation.entity.d.ts +10 -0
  113. package/dist/backend/entities/bulk-operation.entity.d.ts.map +1 -1
  114. package/dist/backend/entities/bulk-operation.entity.js.map +1 -1
  115. package/dist/backend/entities/gallery-item-channel-hidden.entity.d.ts +14 -0
  116. package/dist/backend/entities/gallery-item-channel-hidden.entity.d.ts.map +1 -0
  117. package/dist/backend/entities/gallery-item-channel-hidden.entity.js +42 -0
  118. package/dist/backend/entities/gallery-item-channel-hidden.entity.js.map +1 -0
  119. package/dist/backend/entities/gallery-item-channel-label.entity.d.ts +18 -0
  120. package/dist/backend/entities/gallery-item-channel-label.entity.d.ts.map +1 -0
  121. package/dist/backend/entities/gallery-item-channel-label.entity.js +49 -0
  122. package/dist/backend/entities/gallery-item-channel-label.entity.js.map +1 -0
  123. package/dist/backend/entities/gallery-item.entity.d.ts +8 -1
  124. package/dist/backend/entities/gallery-item.entity.d.ts.map +1 -1
  125. package/dist/backend/entities/gallery-item.entity.js +11 -0
  126. package/dist/backend/entities/gallery-item.entity.js.map +1 -1
  127. package/dist/backend/entities/product-attachment-channel-hidden.entity.d.ts +13 -0
  128. package/dist/backend/entities/product-attachment-channel-hidden.entity.d.ts.map +1 -0
  129. package/dist/backend/entities/product-attachment-channel-hidden.entity.js +41 -0
  130. package/dist/backend/entities/product-attachment-channel-hidden.entity.js.map +1 -0
  131. package/dist/backend/entities/product-attachment.entity.d.ts +8 -1
  132. package/dist/backend/entities/product-attachment.entity.d.ts.map +1 -1
  133. package/dist/backend/entities/product-attachment.entity.js +15 -0
  134. package/dist/backend/entities/product-attachment.entity.js.map +1 -1
  135. package/dist/backend/entities/product-channel-language-scope.entity.d.ts +23 -0
  136. package/dist/backend/entities/product-channel-language-scope.entity.d.ts.map +1 -0
  137. package/dist/backend/entities/product-channel-language-scope.entity.js +61 -0
  138. package/dist/backend/entities/product-channel-language-scope.entity.js.map +1 -0
  139. package/dist/backend/entities/product-channel-scope.entity.d.ts +42 -0
  140. package/dist/backend/entities/product-channel-scope.entity.d.ts.map +1 -0
  141. package/dist/backend/entities/product-channel-scope.entity.js +104 -0
  142. package/dist/backend/entities/product-channel-scope.entity.js.map +1 -0
  143. package/dist/backend/entities/product-packaging-unit.entity.d.ts +7 -1
  144. package/dist/backend/entities/product-packaging-unit.entity.d.ts.map +1 -1
  145. package/dist/backend/entities/product-packaging-unit.entity.js +10 -0
  146. package/dist/backend/entities/product-packaging-unit.entity.js.map +1 -1
  147. package/dist/backend/entities/product-url-key.entity.d.ts +32 -0
  148. package/dist/backend/entities/product-url-key.entity.d.ts.map +1 -0
  149. package/dist/backend/entities/product-url-key.entity.js +75 -0
  150. package/dist/backend/entities/product-url-key.entity.js.map +1 -0
  151. package/dist/backend/entities/product-url-redirect.entity.d.ts +23 -0
  152. package/dist/backend/entities/product-url-redirect.entity.d.ts.map +1 -0
  153. package/dist/backend/entities/product-url-redirect.entity.js +58 -0
  154. package/dist/backend/entities/product-url-redirect.entity.js.map +1 -0
  155. package/dist/backend/entities/product.entity.d.ts +17 -2
  156. package/dist/backend/entities/product.entity.d.ts.map +1 -1
  157. package/dist/backend/entities/product.entity.js +24 -1
  158. package/dist/backend/entities/product.entity.js.map +1 -1
  159. package/dist/backend/index.d.ts +24 -2
  160. package/dist/backend/index.d.ts.map +1 -1
  161. package/dist/backend/index.js +206 -11
  162. package/dist/backend/index.js.map +1 -1
  163. package/dist/backend/plugin.d.ts +44 -3
  164. package/dist/backend/plugin.d.ts.map +1 -1
  165. package/dist/backend/plugin.js +67 -9
  166. package/dist/backend/plugin.js.map +1 -1
  167. package/dist/backend/prompt-tools.d.ts +10 -0
  168. package/dist/backend/prompt-tools.d.ts.map +1 -1
  169. package/dist/backend/prompt-tools.js +108 -4
  170. package/dist/backend/prompt-tools.js.map +1 -1
  171. package/dist/backend/routes.admin.d.ts +29 -0
  172. package/dist/backend/routes.admin.d.ts.map +1 -1
  173. package/dist/backend/routes.admin.js +123 -54
  174. package/dist/backend/routes.admin.js.map +1 -1
  175. package/dist/backend/routes.admin.url-keys.d.ts +23 -0
  176. package/dist/backend/routes.admin.url-keys.d.ts.map +1 -0
  177. package/dist/backend/routes.admin.url-keys.js +14 -0
  178. package/dist/backend/routes.admin.url-keys.js.map +1 -0
  179. package/dist/backend/routes.api-key.d.ts.map +1 -1
  180. package/dist/backend/routes.api-key.js +14 -1
  181. package/dist/backend/routes.api-key.js.map +1 -1
  182. package/dist/backend/routes.external.d.ts.map +1 -1
  183. package/dist/backend/routes.external.js +6 -1
  184. package/dist/backend/routes.external.js.map +1 -1
  185. package/dist/backend/routes.public.d.ts +24 -7
  186. package/dist/backend/routes.public.d.ts.map +1 -1
  187. package/dist/backend/routes.public.js +55 -26
  188. package/dist/backend/routes.public.js.map +1 -1
  189. package/dist/backend/routes.public.url-keys.d.ts +26 -0
  190. package/dist/backend/routes.public.url-keys.d.ts.map +1 -0
  191. package/dist/backend/routes.public.url-keys.js +17 -0
  192. package/dist/backend/routes.public.url-keys.js.map +1 -0
  193. package/dist/backend/services/asset-references.js +43 -30
  194. package/dist/backend/services/asset-references.js.map +1 -1
  195. package/dist/backend/services/attachment-packaging-scopes.d.ts +43 -0
  196. package/dist/backend/services/attachment-packaging-scopes.d.ts.map +1 -0
  197. package/dist/backend/services/attachment-packaging-scopes.js +115 -0
  198. package/dist/backend/services/attachment-packaging-scopes.js.map +1 -0
  199. package/dist/backend/services/attachment.service.d.ts +12 -1
  200. package/dist/backend/services/attachment.service.d.ts.map +1 -1
  201. package/dist/backend/services/attachment.service.js +119 -21
  202. package/dist/backend/services/attachment.service.js.map +1 -1
  203. package/dist/backend/services/attribute-scope-preview.d.ts +38 -0
  204. package/dist/backend/services/attribute-scope-preview.d.ts.map +1 -0
  205. package/dist/backend/services/attribute-scope-preview.js +66 -0
  206. package/dist/backend/services/attribute-scope-preview.js.map +1 -0
  207. package/dist/backend/services/bulk-operation.service.d.ts +36 -0
  208. package/dist/backend/services/bulk-operation.service.d.ts.map +1 -1
  209. package/dist/backend/services/bulk-operation.service.js +203 -36
  210. package/dist/backend/services/bulk-operation.service.js.map +1 -1
  211. package/dist/backend/services/bundle.service.d.ts +9 -1
  212. package/dist/backend/services/bundle.service.d.ts.map +1 -1
  213. package/dist/backend/services/bundle.service.js +12 -2
  214. package/dist/backend/services/bundle.service.js.map +1 -1
  215. package/dist/backend/services/catalog-admin-search.service.d.ts +1 -1
  216. package/dist/backend/services/catalog-admin-search.service.js +1 -1
  217. package/dist/backend/services/catalog-admin.service.d.ts +111 -18
  218. package/dist/backend/services/catalog-admin.service.d.ts.map +1 -1
  219. package/dist/backend/services/catalog-admin.service.js +298 -142
  220. package/dist/backend/services/catalog-admin.service.js.map +1 -1
  221. package/dist/backend/services/catalog-bulk-import.service.d.ts +24 -2
  222. package/dist/backend/services/catalog-bulk-import.service.d.ts.map +1 -1
  223. package/dist/backend/services/catalog-bulk-import.service.js +132 -6
  224. package/dist/backend/services/catalog-bulk-import.service.js.map +1 -1
  225. package/dist/backend/services/catalog-bulk-update.service.d.ts +32 -4
  226. package/dist/backend/services/catalog-bulk-update.service.d.ts.map +1 -1
  227. package/dist/backend/services/catalog-bulk-update.service.js +107 -11
  228. package/dist/backend/services/catalog-bulk-update.service.js.map +1 -1
  229. package/dist/backend/services/catalog-org-price-decorator.d.ts +12 -25
  230. package/dist/backend/services/catalog-org-price-decorator.d.ts.map +1 -1
  231. package/dist/backend/services/catalog-org-price-decorator.js +48 -13
  232. package/dist/backend/services/catalog-org-price-decorator.js.map +1 -1
  233. package/dist/backend/services/catalog-product-filter.service.d.ts +16 -2
  234. package/dist/backend/services/catalog-product-filter.service.d.ts.map +1 -1
  235. package/dist/backend/services/catalog-product-filter.service.js +80 -3
  236. package/dist/backend/services/catalog-product-filter.service.js.map +1 -1
  237. package/dist/backend/services/catalog-product-read.service.d.ts.map +1 -1
  238. package/dist/backend/services/catalog-product-read.service.js +5 -8
  239. package/dist/backend/services/catalog-product-read.service.js.map +1 -1
  240. package/dist/backend/services/catalog-query.service.d.ts +135 -38
  241. package/dist/backend/services/catalog-query.service.d.ts.map +1 -1
  242. package/dist/backend/services/catalog-query.service.js +683 -354
  243. package/dist/backend/services/catalog-query.service.js.map +1 -1
  244. package/dist/backend/services/catalog-quick-search.service.d.ts +18 -2
  245. package/dist/backend/services/catalog-quick-search.service.d.ts.map +1 -1
  246. package/dist/backend/services/catalog-quick-search.service.js +52 -20
  247. package/dist/backend/services/catalog-quick-search.service.js.map +1 -1
  248. package/dist/backend/services/catalog-write-ports.d.ts +18 -1
  249. package/dist/backend/services/catalog-write-ports.d.ts.map +1 -1
  250. package/dist/backend/services/catalog-write-ports.js +77 -0
  251. package/dist/backend/services/catalog-write-ports.js.map +1 -1
  252. package/dist/backend/services/category-admin.service.d.ts +12 -1
  253. package/dist/backend/services/category-admin.service.d.ts.map +1 -1
  254. package/dist/backend/services/category-admin.service.js +23 -2
  255. package/dist/backend/services/category-admin.service.js.map +1 -1
  256. package/dist/backend/services/channel-url-facts.d.ts +17 -0
  257. package/dist/backend/services/channel-url-facts.d.ts.map +1 -0
  258. package/dist/backend/services/channel-url-facts.js +20 -0
  259. package/dist/backend/services/channel-url-facts.js.map +1 -0
  260. package/dist/backend/services/effective-value.sql.d.ts +56 -0
  261. package/dist/backend/services/effective-value.sql.d.ts.map +1 -0
  262. package/dist/backend/services/effective-value.sql.js +111 -0
  263. package/dist/backend/services/effective-value.sql.js.map +1 -0
  264. package/dist/backend/services/gallery-scopes.d.ts +40 -0
  265. package/dist/backend/services/gallery-scopes.d.ts.map +1 -0
  266. package/dist/backend/services/gallery-scopes.js +151 -0
  267. package/dist/backend/services/gallery-scopes.js.map +1 -0
  268. package/dist/backend/services/gallery.service.d.ts +46 -4
  269. package/dist/backend/services/gallery.service.d.ts.map +1 -1
  270. package/dist/backend/services/gallery.service.js +308 -46
  271. package/dist/backend/services/gallery.service.js.map +1 -1
  272. package/dist/backend/services/linkable-asset.d.ts +21 -0
  273. package/dist/backend/services/linkable-asset.d.ts.map +1 -0
  274. package/dist/backend/services/linkable-asset.js +31 -0
  275. package/dist/backend/services/linkable-asset.js.map +1 -0
  276. package/dist/backend/services/packaging-unit.service.d.ts.map +1 -1
  277. package/dist/backend/services/packaging-unit.service.js +76 -45
  278. package/dist/backend/services/packaging-unit.service.js.map +1 -1
  279. package/dist/backend/services/primary-asset-url.d.ts +7 -1
  280. package/dist/backend/services/primary-asset-url.d.ts.map +1 -1
  281. package/dist/backend/services/primary-asset-url.js +45 -14
  282. package/dist/backend/services/primary-asset-url.js.map +1 -1
  283. package/dist/backend/services/product-availability.service.d.ts +79 -0
  284. package/dist/backend/services/product-availability.service.d.ts.map +1 -0
  285. package/dist/backend/services/product-availability.service.js +223 -0
  286. package/dist/backend/services/product-availability.service.js.map +1 -0
  287. package/dist/backend/services/product-availability.sql.d.ts +71 -0
  288. package/dist/backend/services/product-availability.sql.d.ts.map +1 -0
  289. package/dist/backend/services/product-availability.sql.js +77 -0
  290. package/dist/backend/services/product-availability.sql.js.map +1 -0
  291. package/dist/backend/services/product-link.service.d.ts +10 -9
  292. package/dist/backend/services/product-link.service.d.ts.map +1 -1
  293. package/dist/backend/services/product-link.service.js +32 -22
  294. package/dist/backend/services/product-link.service.js.map +1 -1
  295. package/dist/backend/services/product-overrides.service.d.ts +9 -2
  296. package/dist/backend/services/product-overrides.service.d.ts.map +1 -1
  297. package/dist/backend/services/product-overrides.service.js +13 -6
  298. package/dist/backend/services/product-overrides.service.js.map +1 -1
  299. package/dist/backend/services/product-page-revalidation.d.ts +51 -0
  300. package/dist/backend/services/product-page-revalidation.d.ts.map +1 -0
  301. package/dist/backend/services/product-page-revalidation.js +146 -0
  302. package/dist/backend/services/product-page-revalidation.js.map +1 -0
  303. package/dist/backend/services/product-scope-context.service.d.ts.map +1 -1
  304. package/dist/backend/services/product-scope-context.service.js +3 -2
  305. package/dist/backend/services/product-scope-context.service.js.map +1 -1
  306. package/dist/backend/services/product-scopes.service.d.ts +212 -0
  307. package/dist/backend/services/product-scopes.service.d.ts.map +1 -0
  308. package/dist/backend/services/product-scopes.service.js +638 -0
  309. package/dist/backend/services/product-scopes.service.js.map +1 -0
  310. package/dist/backend/services/product-summary-text.d.ts +8 -0
  311. package/dist/backend/services/product-summary-text.d.ts.map +1 -0
  312. package/dist/backend/services/product-summary-text.js +8 -0
  313. package/dist/backend/services/product-summary-text.js.map +1 -0
  314. package/dist/backend/services/publication-window-sweep.d.ts +77 -0
  315. package/dist/backend/services/publication-window-sweep.d.ts.map +1 -0
  316. package/dist/backend/services/publication-window-sweep.js +117 -0
  317. package/dist/backend/services/publication-window-sweep.js.map +1 -0
  318. package/dist/backend/services/scope-completeness.d.ts +107 -0
  319. package/dist/backend/services/scope-completeness.d.ts.map +1 -0
  320. package/dist/backend/services/scope-completeness.js +180 -0
  321. package/dist/backend/services/scope-completeness.js.map +1 -0
  322. package/dist/backend/services/scope-overview.service.d.ts +112 -0
  323. package/dist/backend/services/scope-overview.service.d.ts.map +1 -0
  324. package/dist/backend/services/scope-overview.service.js +372 -0
  325. package/dist/backend/services/scope-overview.service.js.map +1 -0
  326. package/dist/backend/services/sql-id-arrays.d.ts +16 -0
  327. package/dist/backend/services/sql-id-arrays.d.ts.map +1 -0
  328. package/dist/backend/services/sql-id-arrays.js +24 -0
  329. package/dist/backend/services/sql-id-arrays.js.map +1 -0
  330. package/dist/backend/services/url-key-resolution.service.d.ts +76 -0
  331. package/dist/backend/services/url-key-resolution.service.d.ts.map +1 -0
  332. package/dist/backend/services/url-key-resolution.service.js +179 -0
  333. package/dist/backend/services/url-key-resolution.service.js.map +1 -0
  334. package/dist/backend/services/url-key.service.d.ts +171 -0
  335. package/dist/backend/services/url-key.service.d.ts.map +1 -0
  336. package/dist/backend/services/url-key.service.js +738 -0
  337. package/dist/backend/services/url-key.service.js.map +1 -0
  338. package/dist/manifest.d.ts +3 -1
  339. package/dist/manifest.d.ts.map +1 -1
  340. package/dist/manifest.js +170 -10
  341. package/dist/manifest.js.map +1 -1
  342. package/dist/migrations/20261022T035133_catalog_product_scopes.d.ts +28 -0
  343. package/dist/migrations/20261022T035133_catalog_product_scopes.d.ts.map +1 -0
  344. package/dist/migrations/20261022T035133_catalog_product_scopes.js +92 -0
  345. package/dist/migrations/20261022T035133_catalog_product_scopes.js.map +1 -0
  346. package/dist/migrations/20261022T054223_catalog_product_url_keys.d.ts +32 -0
  347. package/dist/migrations/20261022T054223_catalog_product_url_keys.d.ts.map +1 -0
  348. package/dist/migrations/20261022T054223_catalog_product_url_keys.js +81 -0
  349. package/dist/migrations/20261022T054223_catalog_product_url_keys.js.map +1 -0
  350. package/dist/migrations/20261025T222634_catalog_product_status_drop_draft.d.ts +34 -0
  351. package/dist/migrations/20261025T222634_catalog_product_status_drop_draft.d.ts.map +1 -0
  352. package/dist/migrations/20261025T222634_catalog_product_status_drop_draft.js +57 -0
  353. package/dist/migrations/20261025T222634_catalog_product_status_drop_draft.js.map +1 -0
  354. package/dist/migrations/20261026T033453_catalog_product_media_scopes.d.ts +26 -0
  355. package/dist/migrations/20261026T033453_catalog_product_media_scopes.d.ts.map +1 -0
  356. package/dist/migrations/20261026T033453_catalog_product_media_scopes.js +54 -0
  357. package/dist/migrations/20261026T033453_catalog_product_media_scopes.js.map +1 -0
  358. package/dist/migrations/20261026T084533_catalog_attachment_packaging_translations.d.ts +27 -0
  359. package/dist/migrations/20261026T084533_catalog_attachment_packaging_translations.d.ts.map +1 -0
  360. package/dist/migrations/20261026T084533_catalog_attachment_packaging_translations.js +45 -0
  361. package/dist/migrations/20261026T084533_catalog_attachment_packaging_translations.js.map +1 -0
  362. package/dist/migrations/index.d.ts +6 -1
  363. package/dist/migrations/index.d.ts.map +1 -1
  364. package/dist/migrations/index.js +11 -1
  365. package/dist/migrations/index.js.map +1 -1
  366. package/docs/catalog/attachments.md +46 -4
  367. package/docs/catalog/gallery-and-labels.md +63 -4
  368. package/docs/catalog/packaging-units.md +42 -5
  369. package/docs/catalog/per-channel-per-language-overrides.md +166 -8
  370. package/docs/catalog/url-keys-and-redirects.md +142 -0
  371. package/docs/catalog.md +182 -15
  372. package/i18n/en.json +903 -49
  373. package/i18n/pl.json +902 -48
  374. package/package.json +10 -10
@@ -12,11 +12,20 @@ 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, loadGalleryChannelOverrides } from './gallery-scopes.js';
16
+ import { loadAttachmentsHiddenInChannel } from './attachment-packaging-scopes.js';
15
17
  import { viewerOrganizationFor } from './viewer-organization.js';
18
+ import { channelUrlFactsOf } from './channel-url-facts.js';
16
19
  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';
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, translationAt, effectivePackagingUnitName, } from '@endora-commerce/contracts';
18
26
  import { HttpError } from '@endora-commerce/platform/http';
19
27
  import { encodeCursor, decodeCursor } from '@endora-commerce/platform/http';
28
+ import { productSummaryText } from './product-summary-text.js';
20
29
  /** A uuid as the database spells one — anything else is a 404 or a discarded cursor, not a query. */
21
30
  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
31
  /** A category id as the database spells one — anything else is a 404, not a query. */
@@ -94,6 +103,15 @@ function cursorAmount(value) {
94
103
  * is additive.
95
104
  */
96
105
  export const PRICE_PAGE_SCAN_BUDGET_MULTIPLE = 8;
106
+ /** The seal purpose of every cursor a price-sorted listing issues (issue #497). */
107
+ export const PRICE_WALK_CURSOR_PURPOSE = 'catalog.listing.price-walk';
108
+ /**
109
+ * The seal purpose of every cursor a price-filtered listing under another sort
110
+ * issues (issue #497): its budget can stop it on a hidden product too, and that
111
+ * position names the product's id. A purpose of its own, so neither walk reads
112
+ * the other's cursor.
113
+ */
114
+ export const PRICE_RANGE_WALK_CURSOR_PURPOSE = 'catalog.listing.price-range-walk';
97
115
  function amountBound(value, side) {
98
116
  const [whole = '0', fraction = ''] = decimalText(value).split('.');
99
117
  let units = BigInt(whole) * 10000n + BigInt(fraction.slice(0, 4).padEnd(4, '0'));
@@ -125,10 +143,8 @@ function withinAmountRange(amount, range) {
125
143
  * ordering came apart in the first place.
126
144
  */
127
145
  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
- };
146
+ if (!('createdAt' in cursor)) {
147
+ throw new Error('afterKeysetCursor: a name cursor is the name keyset\'s own (`#keysetFor`).');
132
148
  }
133
149
  const at = new Date(cursor.createdAt);
134
150
  return { $or: [{ createdAt: { [op]: at } }, { createdAt: at, id: { [op]: cursor.id } }] };
@@ -204,6 +220,8 @@ export class CatalogQueryService {
204
220
  organizationDetails;
205
221
  listingPriceOrder;
206
222
  log;
223
+ cursorSeal;
224
+ seoProductMeta;
207
225
  constructor(emFactory,
208
226
  /**
209
227
  * Feature 002 US4 — optional link provider so the PDP `productDetail`
@@ -303,7 +321,18 @@ export class CatalogQueryService {
303
321
  * without changing anything else. Optional, because a fixture that never
304
322
  * binds never reaches it.
305
323
  */
306
- log) {
324
+ log,
325
+ /**
326
+ * Issue #497 — what every cursor of a price walk is sealed with. Optional
327
+ * only in the signature, like the ordering port: a price walk asked for
328
+ * without it fails loudly rather than issue a cursor a client can read.
329
+ */
330
+ cursorSeal,
331
+ /**
332
+ * Feature 163 — the product page's metadata through `seo` (R13). Optional: a
333
+ * composition without it, like `seo` off, serves the derived metadata.
334
+ */
335
+ seoProductMeta) {
307
336
  this.emFactory = emFactory;
308
337
  this.productLinkService = productLinkService;
309
338
  this.customFieldDefinitions = customFieldDefinitions;
@@ -314,6 +343,31 @@ export class CatalogQueryService {
314
343
  this.organizationDetails = organizationDetails;
315
344
  this.listingPriceOrder = listingPriceOrder;
316
345
  this.log = log;
346
+ this.cursorSeal = cursorSeal;
347
+ this.seoProductMeta = seoProductMeta;
348
+ }
349
+ #requireCursorSeal() {
350
+ if (!this.cursorSeal) {
351
+ throw new Error('CatalogQueryService: the cursor seal is not wired — a price walk cannot issue a cursor ' +
352
+ 'without handing the client the position its scan stopped at.');
353
+ }
354
+ return this.cursorSeal;
355
+ }
356
+ /** A price walk's cursor, sealed for `purpose`. */
357
+ #sealCursor(purpose, value) {
358
+ return this.#requireCursorSeal().seal(purpose, JSON.stringify(value));
359
+ }
360
+ /** What a cursor sealed for `purpose` holds, or `null` when it does not open or parse. */
361
+ #openCursor(purpose, cursor) {
362
+ const opened = this.#requireCursorSeal().open(purpose, cursor);
363
+ if (opened === null)
364
+ return null;
365
+ try {
366
+ return JSON.parse(opened);
367
+ }
368
+ catch {
369
+ return null;
370
+ }
317
371
  }
318
372
  #requireChannelMembership() {
319
373
  if (!this.channelMembership) {
@@ -322,6 +376,53 @@ export class CatalogQueryService {
322
376
  }
323
377
  return this.channelMembership;
324
378
  }
379
+ /**
380
+ * Feature 163 — where a read asks availability (FR-001): the request's
381
+ * resolved channel (Constitution XII), its scope language L, the audience the
382
+ * route took from the session, and one `now` for every statement and every
383
+ * page-side check of the read, so a window edge cannot fall between two of
384
+ * them.
385
+ */
386
+ #availabilityScope(ctx, now = new Date()) {
387
+ const channel = toScopeChannel(ctx.resolvedChannel);
388
+ return {
389
+ channel,
390
+ languageCode: resolveScopeLanguage(channel, ctx.preferredLanguage),
391
+ audience: ctx.audience,
392
+ now,
393
+ };
394
+ }
395
+ /** {@link availabilityCondition} for this scope — a description; the caller makes the `raw()` key. */
396
+ #availabilityNarrowing(scope) {
397
+ return availabilityCondition({
398
+ channelId: scope.channel.id,
399
+ languageCode: scope.languageCode,
400
+ channelLanguages: scope.channel.languages,
401
+ audience: scope.audience,
402
+ now: scope.now,
403
+ }, this.#requireChannelMembership());
404
+ }
405
+ /**
406
+ * The pure rule over rows already held — the defence in depth behind every
407
+ * statement that carried {@link availabilityCondition}, and the whole check
408
+ * where a read could not carry it. `membersKnown` when the statement already
409
+ * held the kernel's membership subquery.
410
+ */
411
+ #availableAmong(em, products, scope, membersKnown) {
412
+ return availableAmong(em, this.#requireChannelMembership(), products, scope, { membersKnown });
413
+ }
414
+ /**
415
+ * Feature 163 — the ids of `productIds` available to this request at (C, L),
416
+ * for a seam that holds ids and answers its own single not-found (bundle
417
+ * configuration options, FR-004).
418
+ */
419
+ async filterAvailableForRequest(productIds, ctx) {
420
+ if (productIds.length === 0)
421
+ return new Set();
422
+ const em = this.emFactory();
423
+ const products = await em.find(Product, { id: { $in: [...new Set(productIds)] } });
424
+ return this.#availableAmong(em, products, this.#availabilityScope(ctx), false);
425
+ }
325
426
  #requireAssets() {
326
427
  if (!this.assets) {
327
428
  throw new Error('CatalogQueryService: the asset read port is not wired — product images are unavailable.');
@@ -358,9 +459,11 @@ export class CatalogQueryService {
358
459
  * The chain's answer for a batch of products, keyed by product id, **for the
359
460
  * viewer in front of the page**.
360
461
  *
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.
462
+ * Whether the viewer is shown a price is the display-mode chain's answer,
463
+ * applied inside the resolution: a viewer whose mode is `none` gets the
464
+ * withheld arm (issue #491). The channel has no say of its own any more
465
+ * (issue #492) — a channel that hides prices until sign-in does so through
466
+ * its `pricing.unauthenticated_display_mode`.
364
467
  *
365
468
  * The organisation is the whole of this method's share of the owner's ruling
366
469
  * — an anonymous visitor sees the channel price, a signed-in buyer sees their
@@ -374,8 +477,6 @@ export class CatalogQueryService {
374
477
  context) {
375
478
  if (products.length === 0)
376
479
  return new Map();
377
- if (!(ctx.resolvedChannel.isPublic ?? true))
378
- return new Map();
379
480
  // D-287 P0 — the details call: one resolution answers both `price` and
380
481
  // `resolvedPrice` (base / sale / display mode), so the product page and the
381
482
  // home page's cards need no second, per-product resolution.
@@ -412,9 +513,9 @@ export class CatalogQueryService {
412
513
  };
413
514
  }
414
515
  /**
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".
516
+ * `ProductSummary.price` for one resolved chain answer. A product absent from
517
+ * the map renders `null`, and so does the chain's `none` arm — the wire field
518
+ * has one spelling for "no price".
418
519
  */
419
520
  #summaryPrice(resolved, productId) {
420
521
  const detail = resolved.get(productId);
@@ -423,8 +524,8 @@ export class CatalogQueryService {
423
524
  /**
424
525
  * `ProductSummary.resolvedPrice` — base, sale and display mode from the same
425
526
  * 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.
527
+ * price when the engine answered one (161 G14). `null` where the product was
528
+ * not resolved. One mapping for the listing cards and the product detail.
428
529
  */
429
530
  #summaryResolvedPrice(resolved, productId) {
430
531
  const detail = resolved.get(productId);
@@ -452,17 +553,32 @@ export class CatalogQueryService {
452
553
  * that index in that order. Writing it down is what keeps the array the same
453
554
  * array now that a page-wide `in (…)` may reach the rows by another plan.
454
555
  */
455
- async #listingCardReadsFor(em, productIds,
456
- /** The request's resolved sales channel — the override rows are read for it alone. */
457
- channelId) {
556
+ async #listingCardReadsFor(em, products,
557
+ /** The request: its resolved sales channel (override rows and keys are read for it alone) and language. */
558
+ ctx,
559
+ /**
560
+ * What a single-product caller (the product page) has already read for its one
561
+ * product: its scope rows in the channel and its keys per channel language — not
562
+ * read again (checkpoint C code review, N1).
563
+ */
564
+ preloaded) {
565
+ const channelId = ctx.resolvedChannel.id;
566
+ const productIds = products.map((p) => p.id);
458
567
  const categorySlugsByProduct = new Map();
459
568
  if (productIds.length === 0) {
460
- return { assetUrlByProduct: new Map(), categorySlugsByProduct, overridesByProduct: new Map() };
569
+ return {
570
+ assetUrlByProduct: new Map(),
571
+ categorySlugsByProduct,
572
+ overridesByProduct: new Map(),
573
+ effectiveKeyByProduct: new Map(),
574
+ minOrderQuantityByProduct: new Map(),
575
+ };
461
576
  }
462
577
  // Primary asset — for listings prefer the gallery's Thumbnail (US3),
463
578
  // 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);
579
+ // product_assets row. Resolution chain pinned by T096; run over the gallery as
580
+ // the request's channel shows it (feature 163, FR-076).
581
+ const assetUrlByProduct = await resolvePrimaryAssetUrls(em, this.#requireAssets(), productIds, channelId);
466
582
  const ids = [...productIds];
467
583
  const catRows = await em.execute(`select pc.product_id::text as product_id, c.slug
468
584
  from product_categories pc
@@ -475,7 +591,39 @@ export class CatalogQueryService {
475
591
  categorySlugsByProduct.set(row.product_id, slugs);
476
592
  }
477
593
  const overridesByProduct = await loadChannelOverridesByProduct(em, ids, channelId);
478
- return { assetUrlByProduct, categorySlugsByProduct, overridesByProduct };
594
+ const effectiveKeyByProduct = preloaded
595
+ ? this.#keysAtScopeLanguage(products, preloaded.keysByLanguage, ctx)
596
+ : await this.#effectiveKeysAt(em, products, ctx);
597
+ // Feature 163 (FR-100) — the channel's minimum, read page-wide with its scope rows.
598
+ const scopeRows = preloaded?.scopeRows ?? (await loadChannelScopeRows(em, ids, channelId));
599
+ const minOrderQuantityByProduct = new Map(products.map((product) => [
600
+ product.id,
601
+ effectiveOrderRules({ minOrderQuantity: product.minOrderQuantity ?? null, returnable: product.returnable }, scopeRows.channelRows.get(product.id)).minOrderQuantity,
602
+ ]));
603
+ return {
604
+ assetUrlByProduct,
605
+ categorySlugsByProduct,
606
+ overridesByProduct,
607
+ effectiveKeyByProduct,
608
+ minOrderQuantityByProduct,
609
+ };
610
+ }
611
+ /** The one product's key at the request's language, from keys already read (N1). */
612
+ #keysAtScopeLanguage(products, keysByLanguage, ctx) {
613
+ const { languageCode } = this.#availabilityScope(ctx);
614
+ return new Map(products.map((product) => [product.id, keysByLanguage.get(languageCode) ?? product.slug]));
615
+ }
616
+ /**
617
+ * Feature 163 (R28) — each product's effective URL key at the request's
618
+ * (channel, language), in one statement for the set.
619
+ */
620
+ async #effectiveKeysAt(em, products, ctx) {
621
+ const { channel, languageCode } = this.#availabilityScope(ctx);
622
+ const keys = await loadEffectiveKeys(em, products, { id: channel.id, languages: [languageCode] });
623
+ const out = new Map();
624
+ for (const product of products)
625
+ out.set(product.id, keys.get(product.id)?.get(languageCode) ?? product.slug);
626
+ return out;
479
627
  }
480
628
  // ------------------------------------------------------------------
481
629
  // Products
@@ -484,17 +632,19 @@ export class CatalogQueryService {
484
632
  // A price walk that began in the default order, for want of a price order,
485
633
  // continues in it to its end — the default listing's page, so nothing the
486
634
  // price path would read first is read (review 2, finding 7).
487
- const priceCursor = isPriceSort(params.sort) && params.cursor ? this.#priceCursor(params.cursor) : null;
635
+ const priceCursor = isPriceSort(params.sort) && params.cursor ? this.#priceCursor(params.cursor, ctx) : null;
488
636
  if (priceCursor?.stream === 'unordered')
489
637
  return this.#listUnordered(params, ctx, priceCursor.cursor);
490
638
  const em = this.emFactory();
491
639
  const channel = ctx.resolvedChannel;
492
640
  // --- Filter validation: any filter[attr.<key>] where the attribute is
493
641
  // not filterable must return 400 FILTER_NOT_ALLOWED (FR-005, T043).
642
+ let attributeViews = [];
494
643
  if (params.attributeFilters) {
495
644
  const keys = Object.keys(params.attributeFilters);
496
645
  if (keys.length > 0) {
497
646
  const views = await this.#requireAttributeRead().listAll();
647
+ attributeViews = views;
498
648
  const byKey = new Map(views.map((a) => [a.key, a]));
499
649
  for (const k of keys) {
500
650
  const a = byKey.get(k);
@@ -504,32 +654,17 @@ export class CatalogQueryService {
504
654
  }
505
655
  }
506
656
  }
657
+ // Feature 163 — status, window, membership and audience are one condition,
658
+ // `availabilityCondition`, applied in every statement below; no status
659
+ // value is tested here (FR-002).
507
660
  const where = {
508
- status: 'active',
509
661
  deletedAt: null,
510
662
  };
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
- }
663
+ const scope = this.#availabilityScope(ctx);
664
+ // Feature 163 (FR-017 b) — free text and attribute filters over the
665
+ // effective values a card shows at (channel, language), as conditions of
666
+ // every statement below (issue #151), with their page-side twin.
667
+ const filters = await this.#listingFilters(params, ctx, attributeViews);
533
668
  if (params.changedSince) {
534
669
  where['updatedAt'] = { $gt: new Date(params.changedSince) };
535
670
  }
@@ -537,23 +672,22 @@ export class CatalogQueryService {
537
672
  // chunked and both are bounded; everything else takes the single fetch it
538
673
  // always took.
539
674
  if (isPriceSort(params.sort)) {
540
- return this.#listByViewerPrice(em, params, ctx, where, params.sort, priceCursor);
675
+ return this.#listByViewerPrice(em, params, ctx, where, params.sort, priceCursor, scope, filters);
541
676
  }
542
677
  if (params.minPrice !== undefined || params.maxPrice !== undefined) {
543
- return this.#listWithPriceRange(em, params, ctx, where);
678
+ return this.#listWithPriceRange(em, params, ctx, where, scope, filters);
544
679
  }
545
680
  // 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
- }
681
+ // `{ createdAt, id }` for the default sort and `{ name, id }` (the effective
682
+ // name, feature 163 D6) for `name`. Decoded here; its `where` fragment is
683
+ // made in the statement below, because under `name` it is a `raw()` key.
684
+ const keyset = this.#keysetFor(params.sort, ctx);
685
+ const decodedCursor = params.cursor
686
+ ? keyset.parse(decodeObjectCursor(params.cursor))
687
+ : null;
554
688
  // Issue #151 — everything that decides whether a row is on the listing is
555
689
  // part of the statement the page is cut from. See `#listingNarrowing`.
556
- const narrowing = await this.#listingNarrowing(em, params, ctx);
690
+ const narrowing = await this.#listingNarrowing(em, params, scope);
557
691
  if (narrowing === null) {
558
692
  // The category names nothing a storefront may browse, so no row matches
559
693
  // and there is no statement worth issuing.
@@ -573,23 +707,29 @@ export class CatalogQueryService {
573
707
  const products = await em.find(Product, {
574
708
  $and: [
575
709
  where,
576
- ...(cursorClause ? [cursorClause] : []),
577
- ...narrowing.map((c) => ({ [raw(c.sql, c.params)]: [] })),
710
+ ...(decodedCursor ? [keyset.after(decodedCursor)] : []),
711
+ ...[...narrowing, ...filters.conditions].map((c) => ({ [raw(c.sql, c.params)]: [] })),
578
712
  ],
579
- }, { limit: params.limit + 1, orderBy: this.orderForSort(params.sort) });
713
+ }, { limit: params.limit + 1, orderBy: keyset.orderBy() });
580
714
  const hasMore = products.length > params.limit;
581
715
  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
716
+ const lastOfPage = page[page.length - 1];
717
+ const nextCursor = hasMore && lastOfPage
718
+ ? encodeObjectCursor(keyset.of(lastOfPage, await this.#cursorNames(em, keyset, [lastOfPage], ctx)))
719
+ : null;
720
+ // The availability and attribute predicates once more, over the rows the
584
721
  // 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));
722
+ // `isProductEffectivelyAvailable` is the platform's one answer to "may this
723
+ // caller see this product here, now" and the SQL above is a restatement of
724
+ // it; a restatement that admits a row the rule refuses must not be what
725
+ // decides a disclosure. The case that exists today is a stored allow-list
726
+ // that is not an array: the statement reads it as "no allow-list", the
727
+ // predicate does not. It costs the page's two scope-row reads, and while the
728
+ // two agree it removes nothing — which is what the parity test holds them
729
+ // to (`availability-parity.test.ts`).
730
+ const available = await this.#availableAmong(em, page, scope, true);
731
+ const passing = await filters.passes(em, page);
732
+ const priceable = page.filter((p) => available.has(p.id) && passing.has(p.id));
593
733
  // Build the summaries. The page is resolved **once** — `toSummary` used to
594
734
  // ask `price_lists` for a batch of one, so a 50-card page made 50 calls and
595
735
  // paid the resolution's fixed cost (the active lists, the settings pair, the
@@ -601,7 +741,7 @@ export class CatalogQueryService {
601
741
  // same reason (issue #263): both helpers took an id list already, and both
602
742
  // were being handed one id at a time from inside the loop.
603
743
  const resolvedPrices = await this.#listingPricesFor(priceable, ctx);
604
- const cardReads = await this.#listingCardReadsFor(em, priceable.map((p) => p.id), channel.id);
744
+ const cardReads = await this.#listingCardReadsFor(em, priceable, ctx);
605
745
  const summaries = priceable.map((p) => this.toSummary(p, channel, ctx.preferredLanguage, resolvedPrices, cardReads));
606
746
  return {
607
747
  data: summaries,
@@ -619,11 +759,12 @@ export class CatalogQueryService {
619
759
  * were was short. With two sales channels and the newest hundred products on
620
760
  * one of them, the other's first page of a hundred was empty.
621
761
  *
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`;
762
+ * - **availability** (feature 163) is `availabilityCondition`: channel
763
+ * membership through the kernel's accessor
764
+ * ({@link SalesChannelMembershipPort.entityIdsInChannelSubquery} — the
765
+ * bridge is still not named here, Constitution XII), the effective status
766
+ * at (C, L), the effective window at `now` and the effective audience rule
767
+ * (`isProductVisibleTo` restated over the channel's rule);
627
768
  * - **the category** is an `exists` over this module's own
628
769
  * `product_categories`, against the tree's ids rather than against every
629
770
  * product id the tree holds, which is what the page-side test loaded;
@@ -636,7 +777,7 @@ export class CatalogQueryService {
636
777
  * only by the statement that consumes it, so this method, which can answer
637
778
  * `null` and awaits a read that can fail, is the wrong place to make one.
638
779
  */
639
- async #listingNarrowing(em, params, ctx) {
780
+ async #listingNarrowing(em, params, scope) {
640
781
  // First, because it is the one part that can end the request: an unknown,
641
782
  // inactive or deleted category means no row matches.
642
783
  let categoryIds = null;
@@ -645,11 +786,7 @@ export class CatalogQueryService {
645
786
  if (categoryIds.length === 0)
646
787
  return null;
647
788
  }
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
- ];
789
+ const conditions = [this.#availabilityNarrowing(scope)];
653
790
  if (categoryIds !== null) {
654
791
  const ids = categoryIds;
655
792
  conditions.push({
@@ -659,39 +796,8 @@ export class CatalogQueryService {
659
796
  params: ids,
660
797
  });
661
798
  }
662
- for (const [key, values] of Object.entries(params.attributeFilters ?? {})) {
663
- conditions.push(this.#attributeCondition(key, values));
664
- }
665
799
  return conditions;
666
800
  }
667
- /**
668
- * `isProductVisibleTo`, as SQL, for the audience in front of the listing.
669
- *
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.
681
- */
682
- #audienceCondition(audience) {
683
- const onAllowList = audience.organizationId !== null;
684
- 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])] : [],
693
- };
694
- }
695
801
  /**
696
802
  * One `filter[attr.<key>]`, as SQL: the product's value for `key`, rendered
697
803
  * the way `#passesPageFilters` renders it, is one of the requested values.
@@ -706,49 +812,90 @@ export class CatalogQueryService {
706
812
  * is a question about what the filter means, and answering it in the
707
813
  * statement only would make the page-side predicate disagree with it.
708
814
  */
709
- #attributeCondition(key, values) {
815
+ #attributeCondition(value, values) {
710
816
  const wanted = values.map((v) => String(v));
711
817
  if (wanted.length === 0)
712
818
  return { sql: () => 'false', params: [] };
713
819
  return {
714
820
  sql: (alias) => `(select ${jsStringOfJsonb('val.v')} ` +
715
- `from (select ${alias}.attribute_values -> ?::text as v) val) ` +
821
+ `from (select ${value.sql(alias)} as v) val) ` +
716
822
  `in (${wanted.map(() => '?').join(',')})`,
717
- params: [key, ...wanted],
823
+ params: [...value.params, ...wanted],
718
824
  };
719
825
  }
720
826
  /**
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.
827
+ * Feature 163 (FR-017 b) — what narrows a listing beside availability and the
828
+ * category: the free-text match and each `filter[attr.<key>]`, over the
829
+ * **effective** values a card shows at the request's (channel, language)
830
+ * (#384's walk, `effective-value.sql.ts`). `conditions` go into every
831
+ * statement a page is cut from; `passes` is their page-side twin over the
832
+ * same walk in TypeScript (`effectiveAttributeValues`), kept as defence in
833
+ * depth like the availability one.
731
834
  */
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;
835
+ async #listingFilters(params, ctx, attributeViews) {
836
+ const channel = ctx.resolvedChannel;
837
+ const effective = this.#overrideContext(channel, ctx.preferredLanguage);
838
+ const conditions = [];
839
+ // Issue #590 — a read by id is one more condition of every statement a
840
+ // page is cut from, so the price orderings and the range walk honour it as
841
+ // the default order does; its page-side twin is in `passes` below.
842
+ const ids = params.ids && params.ids.length > 0 ? [...params.ids] : null;
843
+ if (ids) {
844
+ conditions.push({
845
+ sql: (alias) => `${alias}.id in (${ids.map(() => '?').join(',')})`,
846
+ params: ids,
847
+ });
750
848
  }
751
- return true;
849
+ if (params.q)
850
+ conditions.push(await this.#textSearchCondition(params.q, ctx, effective));
851
+ const scopeOf = new Map(attributeViews.map((a) => [a.key, { channelScoped: a.channelScoped, languageScoped: a.languageScoped }]));
852
+ const notScoped = { channelScoped: false, languageScoped: false };
853
+ const attributeFilters = Object.entries(params.attributeFilters ?? {});
854
+ for (const [key, values] of attributeFilters) {
855
+ conditions.push(this.#attributeCondition(effectiveAttributeSql(key, scopeOf.get(key) ?? notScoped, effective), values));
856
+ }
857
+ return {
858
+ conditions,
859
+ passes: async (em, all) => {
860
+ const out = new Set();
861
+ const named = ids ? new Set(ids) : null;
862
+ const products = named ? all.filter((p) => named.has(p.id)) : all;
863
+ if (attributeFilters.length === 0) {
864
+ for (const p of products)
865
+ out.add(p.id);
866
+ return out;
867
+ }
868
+ if (products.length === 0)
869
+ return out;
870
+ const overrides = await loadChannelOverridesByProduct(em, products.map((p) => p.id), channel.id);
871
+ for (const product of products) {
872
+ const values = await effectiveAttributeValues(product.attributeValues ?? {}, overrides.get(product.id), effective, async () => scopeOf);
873
+ const ok = attributeFilters.every(([key, wanted]) => {
874
+ const v = values[key];
875
+ return v !== undefined && wanted.map((w) => String(w)).includes(String(v));
876
+ });
877
+ if (ok)
878
+ out.add(product.id);
879
+ }
880
+ return out;
881
+ },
882
+ };
883
+ }
884
+ /**
885
+ * The free-text match (FR-017 b): the SKU, the effective Name, and the
886
+ * effective value of every searchable attribute, case-insensitive substring.
887
+ */
888
+ async #textSearchCondition(q, ctx, effective) {
889
+ const searchable = await this.#requireAttributeRead().listByFlag('isSearchable');
890
+ const like = `%${q}%`;
891
+ const name = this.#effectiveNameExpr(ctx);
892
+ const attributes = searchable.map((a) => effectiveAttributeSql(a.key, { channelScoped: a.channelScoped, languageScoped: a.languageScoped }, effective));
893
+ return {
894
+ sql: (alias) => `(${alias}.sku ilike ? or ${name.sql(alias)} ilike ?` +
895
+ attributes.map((e) => ` or (${e.sql(alias)} #>> '{}') ilike ?`).join('') +
896
+ `)`,
897
+ params: [like, ...name.params, like, ...attributes.flatMap((e) => [...e.params, like])],
898
+ };
752
899
  }
753
900
  /** The two range bounds as four-place decimal strings ({@link amountBound}), for every price path. */
754
901
  #amountRange(params) {
@@ -790,14 +937,14 @@ export class CatalogQueryService {
790
937
  */
791
938
  async #listByViewerPrice(em, params, ctx, where, sort,
792
939
  /** The request's cursor as `#priceCursor` read it: `null` starts the walk. */
793
- decoded) {
940
+ decoded, availability, filters) {
794
941
  const channel = ctx.resolvedChannel;
795
942
  const direction = sort === 'price' ? 'asc' : 'desc';
796
943
  // The viewer's pricing context and the category tree, read once for the
797
944
  // page and handed to whichever walk serves it — every chunk of it (review
798
945
  // 3, A5). An `unordered` walk is decided earlier, in `listProducts`, and
799
946
  // reads neither (review 2, finding 7).
800
- const scope = await this.#priceWalkScope(em, params, ctx);
947
+ const scope = await this.#priceWalkScope(em, params, ctx, availability, filters);
801
948
  const { context } = scope;
802
949
  // A walk whose price order went missing carries on in the default order
803
950
  // from the last price it served, to its end.
@@ -805,7 +952,7 @@ export class CatalogQueryService {
805
952
  return this.#listRemainder(em, params, ctx, where, direction, scope, decoded, decoded.after);
806
953
  }
807
954
  const amountRange = this.#amountRange(params);
808
- const restrictToProductIds = scope.categoryIds ? [...scope.categoryIds] : undefined;
955
+ const { restrictToProductIds } = scope;
809
956
  // A cursor issued under another sort is discarded rather than
810
957
  // reinterpreted: the existing behaviour for a cursor that does not parse.
811
958
  const startInTail = decoded?.stream === 'tail';
@@ -868,7 +1015,7 @@ export class CatalogQueryService {
868
1015
  }
869
1016
  const last = chunk.rows[chunk.rows.length - 1];
870
1017
  priceCursor = { amount: last.amount, productId: last.productId };
871
- const byId = await this.#visibleProductsInOrder(em, chunk.rows.map((row) => row.productId), where, params, ctx);
1018
+ const byId = await this.#visibleProductsInOrder(em, chunk.rows.map((row) => row.productId), where, scope.availability, scope.filters);
872
1019
  for (const row of chunk.rows) {
873
1020
  const product = byId.get(row.productId);
874
1021
  if (!product)
@@ -891,20 +1038,26 @@ export class CatalogQueryService {
891
1038
  bound = true;
892
1039
  break;
893
1040
  }
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, {
1041
+ const tailAfter = tailCursor
1042
+ ? [
1043
+ {
1044
+ $or: [
1045
+ { createdAt: { $lt: new Date(tailCursor.createdAt) } },
1046
+ { createdAt: new Date(tailCursor.createdAt), id: { $lt: tailCursor.id } },
1047
+ ],
1048
+ },
1049
+ ]
1050
+ : [];
1051
+ // Feature 163 — availability in the chunk's own statement (issue #151);
1052
+ // the `raw()` key is made in the expression that executes it.
1053
+ const narrowing = this.#availabilityNarrowing(scope.availability);
1054
+ const rows = await em.find(Product, {
1055
+ $and: [
1056
+ where,
1057
+ ...tailAfter,
1058
+ ...[narrowing, ...filters.conditions].map((c) => ({ [raw(c.sql, c.params)]: [] })),
1059
+ ],
1060
+ }, {
908
1061
  limit: chunkSize,
909
1062
  // The listing's own default ordering, in both directions: the tail is
910
1063
  // not ordered by a price it does not have.
@@ -920,11 +1073,12 @@ export class CatalogQueryService {
920
1073
  productIds: rows.map((r) => r.id),
921
1074
  });
922
1075
  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);
1076
+ const visibleIds = await this.#availableAmong(em, candidates, scope.availability, true);
1077
+ const passing = await scope.filters.passes(em, candidates);
924
1078
  for (const product of candidates) {
925
1079
  if (!visibleIds.has(product.id))
926
1080
  continue;
927
- if (!this.#passesPageFilters(product, params, ctx))
1081
+ if (!passing.has(product.id))
928
1082
  continue;
929
1083
  collected.push(product);
930
1084
  cursors.push({
@@ -946,7 +1100,8 @@ export class CatalogQueryService {
946
1100
  // in the tail once the tail has been read, else in the priced stream,
947
1101
  // whose exhaustion the next page then finds and goes on into the tail —
948
1102
  // never from its last card, and never ends the walk (review 3 of release
949
- // 0.108.0, A1).
1103
+ // 0.108.0, A1). That row may be one the viewer may not see, and its price
1104
+ // is in the position, so the cursor is sealed (issue #497).
950
1105
  const page = collected.slice(0, params.limit);
951
1106
  let resumeAt = null;
952
1107
  if (collected.length > params.limit || orderLost)
@@ -956,9 +1111,9 @@ export class CatalogQueryService {
956
1111
  else if (bound && priceCursor)
957
1112
  resumeAt = { stream: 'priced', ...priceCursor };
958
1113
  const hasMore = resumeAt !== null;
959
- const nextCursor = resumeAt === null ? null : encodeObjectCursor(resumeAt);
1114
+ const nextCursor = resumeAt === null ? null : this.#sealCursor(PRICE_WALK_CURSOR_PURPOSE, resumeAt);
960
1115
  const resolvedPrices = await this.#listingPricesFor(page, ctx, context);
961
- const cardReads = await this.#listingCardReadsFor(em, page.map((p) => p.id), channel.id);
1116
+ const cardReads = await this.#listingCardReadsFor(em, page, ctx);
962
1117
  return {
963
1118
  data: page.map((p) => this.toSummary(p, channel, ctx.preferredLanguage, resolvedPrices, cardReads)),
964
1119
  // No total count, no rank, no "showing 51–100 of 4 213" (FR-015): an
@@ -973,10 +1128,20 @@ export class CatalogQueryService {
973
1128
  * page reads up to eight chunks, and each used to look the organization up
974
1129
  * again and, on the remainder, re-read the category tree).
975
1130
  */
976
- async #priceWalkScope(em, params, ctx) {
1131
+ async #priceWalkScope(em, params, ctx, availability, filters) {
1132
+ const categoryIds = params.categorySlug ? await this.productIdsInCategoryTree(em, params.categorySlug) : null;
1133
+ const named = params.ids && params.ids.length > 0 ? params.ids : null;
1134
+ const restrictToProductIds = named
1135
+ ? named.filter((id) => categoryIds === null || categoryIds.has(id))
1136
+ : categoryIds
1137
+ ? [...categoryIds]
1138
+ : undefined;
977
1139
  return {
978
1140
  context: await this.#viewerPricingContext(ctx),
979
- categoryIds: params.categorySlug ? await this.productIdsInCategoryTree(em, params.categorySlug) : null,
1141
+ categoryIds,
1142
+ restrictToProductIds,
1143
+ availability,
1144
+ filters,
980
1145
  };
981
1146
  }
982
1147
  /**
@@ -987,11 +1152,11 @@ export class CatalogQueryService {
987
1152
  * the default listing's keyset; an `unordered` cursor wraps the default
988
1153
  * listing's own, which that listing checks.
989
1154
  */
990
- #priceCursor(cursor) {
991
- const decoded = decodeObjectCursor(cursor);
1155
+ #priceCursor(cursor, ctx) {
1156
+ const decoded = this.#openCursor(PRICE_WALK_CURSOR_PURPOSE, cursor);
992
1157
  if (!isRecord(decoded))
993
1158
  return null;
994
- const keyset = this.keysetFor(undefined);
1159
+ const keyset = this.#keysetFor(undefined, ctx);
995
1160
  switch (decoded['stream']) {
996
1161
  case 'priced': {
997
1162
  const amount = cursorAmount(decoded['amount']);
@@ -1031,7 +1196,9 @@ export class CatalogQueryService {
1031
1196
  ...page,
1032
1197
  pagination: {
1033
1198
  ...page.pagination,
1034
- cursor: next ? encodeObjectCursor({ stream: 'unordered', cursor: next }) : null,
1199
+ cursor: next
1200
+ ? this.#sealCursor(PRICE_WALK_CURSOR_PURPOSE, { stream: 'unordered', cursor: next })
1201
+ : null,
1035
1202
  },
1036
1203
  };
1037
1204
  }
@@ -1051,16 +1218,18 @@ export class CatalogQueryService {
1051
1218
  * price ordering: the chain's `none` and `product` arms are both absences of
1052
1219
  * a price-list figure, and a range is a claim about one.
1053
1220
  */
1054
- async #listWithPriceRange(em, params, ctx, where) {
1221
+ async #listWithPriceRange(em, params, ctx, where, scope, filters) {
1055
1222
  const range = this.#amountRange(params);
1056
1223
  // The chunk walk and the page it hands back page by the same keyset, and
1057
1224
  // 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), {
1225
+ const keyset = this.#keysetFor(params.sort, ctx);
1226
+ return this.#walkKeepingByPrice(em, params, ctx, where, await this.#priceWalkScope(em, params, ctx, scope, filters), {
1060
1227
  sort: params.sort,
1061
- start: params.cursor ? keyset.parse(decodeObjectCursor(params.cursor)) : null,
1228
+ start: params.cursor ? keyset.parse(this.#openCursor(PRICE_RANGE_WALK_CURSOR_PURPOSE, params.cursor)) : null,
1062
1229
  keep: (price) => price !== null && withinAmountRange(price.amount, range),
1063
- cursorOf: (after) => encodeObjectCursor(after),
1230
+ // Sealed (issue #497): a page cut by the budget names the row its scan
1231
+ // stopped at, which may be a product the viewer may not see.
1232
+ cursorOf: (after) => this.#sealCursor(PRICE_RANGE_WALK_CURSOR_PURPOSE, after),
1064
1233
  what: 'price-filtered',
1065
1234
  });
1066
1235
  }
@@ -1112,7 +1281,7 @@ export class CatalogQueryService {
1112
1281
  return range === undefined;
1113
1282
  return withinAmountRange(price.amount, range) && afterBoundary(price.amount, product.id);
1114
1283
  },
1115
- cursorOf: (next) => encodeObjectCursor({
1284
+ cursorOf: (next) => this.#sealCursor(PRICE_WALK_CURSOR_PURPOSE, {
1116
1285
  stream: 'rest',
1117
1286
  amount: boundary.amount,
1118
1287
  productId: boundary.productId,
@@ -1126,12 +1295,14 @@ export class CatalogQueryService {
1126
1295
  * by everything a page is narrowed by and then by the live listing price its
1127
1296
  * cards are rendered with — `keep` decides on that price. Bounded by the scan
1128
1297
  * budget; a bound answers a short, possibly empty, page whose cursor
1129
- * continues from the scan position.
1298
+ * continues from the scan position. `cursorOf` seals it: that position may
1299
+ * be a product the viewer may not see (issue #497).
1130
1300
  */
1131
1301
  async #walkKeepingByPrice(em, params, ctx, where, scope, walk) {
1132
1302
  const channel = ctx.resolvedChannel;
1133
1303
  const categoryFilteredIds = scope.categoryIds;
1134
- const keyset = this.keysetFor(walk.sort);
1304
+ const filters = scope.filters;
1305
+ const keyset = this.#keysetFor(walk.sort, ctx);
1135
1306
  let cursor = walk.start;
1136
1307
  const budget = PRICE_PAGE_SCAN_BUDGET_MULTIPLE * params.limit;
1137
1308
  const target = params.limit + 1;
@@ -1147,26 +1318,34 @@ export class CatalogQueryService {
1147
1318
  bound = true;
1148
1319
  break;
1149
1320
  }
1150
- const chunkWhere = cursor ? { $and: [where, keyset.after(cursor)] } : where;
1151
- const rows = await em.find(Product, chunkWhere, {
1321
+ // Feature 163 — availability in the chunk's own statement (issue #151);
1322
+ // the `raw()` key is made in the expression that executes it.
1323
+ const narrowing = this.#availabilityNarrowing(scope.availability);
1324
+ const rows = await em.find(Product, {
1325
+ $and: [
1326
+ where,
1327
+ ...(cursor ? [keyset.after(cursor)] : []),
1328
+ ...[narrowing, ...filters.conditions].map((c) => ({ [raw(c.sql, c.params)]: [] })),
1329
+ ],
1330
+ }, {
1152
1331
  limit: chunkSize,
1153
- orderBy: this.orderForSort(walk.sort),
1332
+ orderBy: keyset.orderBy(),
1154
1333
  });
1155
1334
  spent += rows.length;
1156
1335
  if (rows.length === 0)
1157
1336
  break;
1158
1337
  const lastRow = rows[rows.length - 1];
1159
- cursor = keyset.of(lastRow);
1160
- const visibleIds = await this.filterByChannel(rows.map((r) => r.id), channel);
1338
+ cursor = keyset.of(lastRow, await this.#cursorNames(em, keyset, [lastRow], ctx));
1339
+ const visibleIds = await this.#availableAmong(em, rows, scope.availability, true);
1340
+ const passing = await filters.passes(em, rows);
1161
1341
  const candidates = rows.filter((r) => visibleIds.has(r.id) &&
1162
- this.#passesPageFilters(r, params, ctx) &&
1342
+ passing.has(r.id) &&
1163
1343
  (categoryFilteredIds === null || categoryFilteredIds.has(r.id)));
1164
1344
  // 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).
1345
+ // order is made of. It asks the resolution directly, not through
1346
+ // `#listingPricesFor`, which once answered no price at all on a channel
1347
+ // that withheld prices; that read here as "no detail" and dropped every
1348
+ // product, priced and unpriced alike (review 3 of release 0.108.0, A3).
1170
1349
  const chunkPrices = candidates.length === 0
1171
1350
  ? new Map()
1172
1351
  : await this.#requireListingPrices().resolveListingPriceDetails({
@@ -1198,14 +1377,12 @@ export class CatalogQueryService {
1198
1377
  const full = collected.length > params.limit;
1199
1378
  const page = collected.slice(0, params.limit);
1200
1379
  const last = page[page.length - 1];
1201
- const resumeAt = full && last ? keyset.of(last) : bound ? cursor : null;
1380
+ const resumeAt = full && last ? keyset.of(last, await this.#cursorNames(em, keyset, [last], ctx)) : bound ? cursor : null;
1202
1381
  const hasMore = resumeAt !== null;
1203
1382
  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();
1383
+ const cardReads = await this.#listingCardReadsFor(em, page, ctx);
1207
1384
  return {
1208
- data: page.map((p) => this.toSummary(p, channel, ctx.preferredLanguage, shown, cardReads)),
1385
+ data: page.map((p) => this.toSummary(p, channel, ctx.preferredLanguage, prices, cardReads)),
1209
1386
  pagination: { cursor: nextCursor, hasMore, limit: params.limit },
1210
1387
  };
1211
1388
  }
@@ -1217,47 +1394,148 @@ export class CatalogQueryService {
1217
1394
  * answers in whatever order it likes, and the ordering being reproduced is the
1218
1395
  * price one.
1219
1396
  */
1220
- async #visibleProductsInOrder(em, productIds, where, params, ctx) {
1397
+ async #visibleProductsInOrder(em, productIds, where, scope, filters) {
1221
1398
  const out = new Map();
1222
1399
  if (productIds.length === 0)
1223
1400
  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);
1401
+ // Feature 163 — the `raw()` key is made in the expression that executes it.
1402
+ const narrowing = this.#availabilityNarrowing(scope);
1403
+ const rows = await em.find(Product, {
1404
+ $and: [
1405
+ where,
1406
+ { id: { $in: [...productIds] } },
1407
+ ...[narrowing, ...filters.conditions].map((c) => ({ [raw(c.sql, c.params)]: [] })),
1408
+ ],
1409
+ });
1410
+ const visibleIds = await this.#availableAmong(em, rows, scope, true);
1411
+ const passing = await filters.passes(em, rows);
1226
1412
  for (const product of rows) {
1227
1413
  if (!visibleIds.has(product.id))
1228
1414
  continue;
1229
- if (!this.#passesPageFilters(product, params, ctx))
1415
+ if (!passing.has(product.id))
1230
1416
  continue;
1231
1417
  out.set(product.id, product);
1232
1418
  }
1233
1419
  return out;
1234
1420
  }
1421
+ /**
1422
+ * Whether `product` may be shown to this request at (C, L), as the product page
1423
+ * answers it — the one decision both the page and the key resolution
1424
+ * (`UrlKeyResolutionService`) ask, so a key can never resolve to a product the
1425
+ * page would refuse. Throws `404 PRODUCT_NOT_FOUND` or `410 PRODUCT_ARCHIVED`;
1426
+ * answers the product's scope rows on the channel for a caller that reads on.
1427
+ */
1428
+ async assertReachable(product, ctx) {
1429
+ const em = this.emFactory();
1430
+ const channel = ctx.resolvedChannel;
1431
+ const notFound = () => new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
1432
+ if (product.deletedAt)
1433
+ throw notFound();
1434
+ // Membership and the audience come first, for every product including an
1435
+ // archived one: a caller outside the channel, or outside the product's
1436
+ // effective audience there, may not learn the row exists — not even that
1437
+ // it existed (feature 163, one answer for "unavailable" and "absent").
1438
+ // Through the kernel's accessor (Constitution XII).
1439
+ const scope = this.#availabilityScope(ctx);
1440
+ const scopeRows = await loadChannelScopeRows(em, [product.id], channel.id);
1441
+ const isMember = (await this.filterByChannel([product.id], channel)).has(product.id);
1442
+ if (!isMember)
1443
+ throw notFound();
1444
+ if (!isProductVisibleTo(effectiveAudience(globalScopeFields(product), scopeRows.channelRows.get(product.id)), ctx.audience)) {
1445
+ throw notFound();
1446
+ }
1447
+ // FR-005, O-3 (T156t) — 410 iff archived: `archived_at` alone says "gone"
1448
+ // (archiving is its own action, owner decision Q1); the status never does.
1449
+ // Otherwise 404 unless effectively available at (C, L) — a product switched
1450
+ // off globally, in the channel or in the language is not reachable by its URL.
1451
+ //
1452
+ // The 410 says "this was here and is gone", so it is answered only where
1453
+ // the product would be available to this buyer with the archive taken away —
1454
+ // `archived_at` cleared and the global status read as `active`, while every
1455
+ // channel and channel × language status, membership, the channel's languages,
1456
+ // the window and the audience still apply (security review, checkpoint B). An archived
1457
+ // product that is also switched off in this channel or language, or
1458
+ // outside its window, answers the absent product's 404: its existence
1459
+ // here is not this caller's to learn.
1460
+ if (product.archivedAt) {
1461
+ const asIfLive = {
1462
+ id: product.id,
1463
+ status: 'active',
1464
+ deletedAt: null,
1465
+ archivedAt: null,
1466
+ publishFrom: product.publishFrom ?? null,
1467
+ publishUntil: product.publishUntil ?? null,
1468
+ visibility: product.visibility,
1469
+ allowedOrganizationIds: product.allowedOrganizationIds,
1470
+ minOrderQuantity: product.minOrderQuantity ?? null,
1471
+ returnable: product.returnable,
1472
+ };
1473
+ if (!isAvailableWith(asIfLive, scopeRows, true, scope))
1474
+ throw notFound();
1475
+ throw new HttpError(410, ERROR_CODES.PRODUCT_ARCHIVED, 'Product is archived.');
1476
+ }
1477
+ const available = await availableAmong(em, this.#requireChannelMembership(), [product], scope, {
1478
+ membersKnown: true,
1479
+ rows: scopeRows,
1480
+ });
1481
+ if (!available.has(product.id))
1482
+ throw notFound();
1483
+ return scopeRows;
1484
+ }
1485
+ /**
1486
+ * Feature 163 (FR-074, `contracts/url-keys-and-redirects.md` §6) — the page's
1487
+ * canonical at the request's (C, L) and its alternate-language paths, built with
1488
+ * `productPath()` here because only catalog knows the channel's URL languages
1489
+ * and where the product is available. An alternate is listed only for a channel
1490
+ * language where the product is available to the **anonymous** audience,
1491
+ * whoever is asking: `hreflang` tells a crawler what it may open.
1492
+ */
1493
+ #pagePaths(product, scopeRows, ctx,
1494
+ /** The product's effective key per channel language, already read by the page. */
1495
+ keys) {
1496
+ const scope = this.#availabilityScope(ctx);
1497
+ const channel = scope.channel;
1498
+ const urlFacts = channelUrlFactsOf(ctx.resolvedChannel);
1499
+ const pathAt = (languageCode) => productPath({
1500
+ key: keys.get(languageCode) ?? product.slug,
1501
+ languageCode,
1502
+ channel: urlFacts,
1503
+ });
1504
+ const alternates = channel.languages
1505
+ .filter((languageCode) => isAvailableWith(product, scopeRows, true, {
1506
+ ...scope,
1507
+ languageCode,
1508
+ audience: ANONYMOUS_PRODUCT_AUDIENCE,
1509
+ }))
1510
+ .map((languageCode) => ({ languageCode, path: pathAt(languageCode) }));
1511
+ // Feature 167 (url-shape §8) — `x-default` is the unprefixed URL of the key at the
1512
+ // channel's default language, in both setting states.
1513
+ const xDefault = productDefaultPath(keys.get(channel.defaultLanguage) ?? product.slug);
1514
+ return { canonical: pathAt(scope.languageCode), alternates, xDefault };
1515
+ }
1516
+ /**
1517
+ * The product page's read (R28): an id; else a **current** key of the request's
1518
+ * language L (any channel's key of L counts — `findCurrentKeyHolder`); else a
1519
+ * product's global key, the stable handle CMS product blocks store. Never a
1520
+ * redirect: the storefront resolves a URL through `resolve` and reads by id.
1521
+ */
1235
1522
  async getProductByIdOrSlug(idOrSlug, ctx) {
1236
1523
  const em = this.emFactory();
1237
1524
  const channel = ctx.resolvedChannel;
1238
1525
  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 });
1526
+ const product = isUuid
1527
+ ? await em.findOne(Product, { id: idOrSlug })
1528
+ : ((await findCurrentKeyHolder(em, idOrSlug, this.#availabilityScope(ctx).languageCode)) ??
1529
+ (await em.findOne(Product, { slug: idOrSlug })));
1240
1530
  if (!product || product.deletedAt) {
1241
1531
  throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
1242
1532
  }
1243
- if (product.status === 'inactive') {
1244
- throw new HttpError(410, ERROR_CODES.PRODUCT_ARCHIVED, 'Product is inactive.');
1245
- }
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.');
1251
- }
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)) {
1258
- throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
1259
- }
1260
- const cardReads = await this.#listingCardReadsFor(em, [product.id], channel.id);
1533
+ const scopeRows = await this.assertReachable(product, ctx);
1534
+ // The product's keys in every channel language, read once for the card's link and
1535
+ // the page's canonical and alternates (checkpoint C code review, N1).
1536
+ const keysByLanguage = (await loadEffectiveKeys(em, [product], this.#availabilityScope(ctx).channel)).get(product.id) ??
1537
+ new Map();
1538
+ const cardReads = await this.#listingCardReadsFor(em, [product], ctx, { scopeRows, keysByLanguage });
1261
1539
  const summary = this.toSummary(product, channel, ctx.preferredLanguage, await this.#listingPricesFor([product], ctx), cardReads);
1262
1540
  // Issue #384 — the product's override rows, already read for the summary.
1263
1541
  const overrides = cardReads.overridesByProduct.get(product.id);
@@ -1275,7 +1553,7 @@ export class CatalogQueryService {
1275
1553
  // Assets
1276
1554
  const assetRows = await em.execute(`select asset_id, position from product_assets where product_id = ? order by position asc`, [product.id]);
1277
1555
  const assetIds = assetRows.map((r) => r.asset_id);
1278
- const assets = await this.#requireAssets().findByIds(assetIds);
1556
+ const allAssets = await this.#requireAssets().findByIds(assetIds);
1279
1557
  // Variants
1280
1558
  const variants = product.type === 'configurable' ? await em.find(ProductVariant, { parentProductId: product.id }) : [];
1281
1559
  // Feature 002 — Attribute Set wired to this Product. Pulled in a
@@ -1287,25 +1565,47 @@ export class CatalogQueryService {
1287
1565
  // Feature 002 US3 — eager-load gallery + attachments for the PDP.
1288
1566
  // Gallery: items + label bridge zipped per item; Asset urls
1289
1567
  // 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);
1568
+ // Feature 163 (FR-076, R14) — the gallery as the request's channel shows it:
1569
+ // hidden items dropped, each role at its channel holder (`effectiveGallery`).
1570
+ const storedGalleryItems = await em.find(GalleryItem, { productId: product.id }, { orderBy: { position: 'asc', id: 'asc' } });
1571
+ const galleryLabels = storedGalleryItems.length > 0
1572
+ ? await em.find(GalleryItemLabel, { productId: product.id })
1573
+ : [];
1574
+ const globalLabelsByItem = new Map();
1575
+ for (const l of galleryLabels) {
1576
+ const existing = globalLabelsByItem.get(l.galleryItemId) ?? [];
1577
+ existing.push(l.label);
1578
+ globalLabelsByItem.set(l.galleryItemId, existing);
1579
+ }
1580
+ const galleryOverrides = storedGalleryItems.length > 0
1581
+ ? (await loadGalleryChannelOverrides(em, [product.id], channel.id)).get(product.id)
1582
+ : undefined;
1583
+ const galleryItems = effectiveGallery(storedGalleryItems.map((item) => ({ id: item.id, item, labels: globalLabelsByItem.get(item.id) ?? [] })), galleryOverrides);
1584
+ const labelsByItem = new Map(galleryItems.map((g) => [g.id, g.labels]));
1585
+ const galleryAssetIds = galleryItems.map((g) => g.item.assetId);
1292
1586
  const galleryAssetsById = new Map();
1293
1587
  if (galleryAssetIds.length > 0) {
1294
1588
  const galleryAssets = await this.#requireAssets().findByIds(galleryAssetIds);
1295
1589
  for (const a of galleryAssets)
1296
1590
  galleryAssetsById.set(a.id, a);
1297
1591
  }
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
- }
1592
+ // An image hidden in the channel stays hidden when a legacy `product_assets` row
1593
+ // names the same asset.
1594
+ const hiddenAssetIds = new Set(storedGalleryItems.filter((item) => galleryOverrides?.hidden.has(item.id)).map((item) => item.assetId));
1595
+ const assets = allAssets.filter((asset) => !hiddenAssetIds.has(asset.id));
1596
+ // FR-077 (R15) — the product's own alt text at the scope language, else the
1597
+ // asset's alt text through the existing pick.
1598
+ const scopeLanguage = this.#availabilityScope(ctx).languageCode;
1599
+ const altTextOf = (item, asset) => translationAt(item.altText, scopeLanguage) ??
1600
+ (asset.altText ? this.pickLang(asset.altText, ctx.preferredLanguage, channel) : null);
1307
1601
  // Attachments + their types, eager-loaded in two queries.
1308
- const attachmentRows = await em.find(ProductAttachment, { productId: product.id }, { orderBy: { position: 'asc', id: 'asc' } });
1602
+ // Feature 163 (FR-078, R16) — an attachment hidden in the request's channel is
1603
+ // neither listed nor named here (its asset is not even read).
1604
+ const storedAttachmentRows = await em.find(ProductAttachment, { productId: product.id }, { orderBy: { position: 'asc', id: 'asc' } });
1605
+ const hiddenAttachments = storedAttachmentRows.length > 0
1606
+ ? await loadAttachmentsHiddenInChannel(em, product.id, channel.id)
1607
+ : new Set();
1608
+ const attachmentRows = storedAttachmentRows.filter((row) => !hiddenAttachments.has(row.id));
1309
1609
  const attachmentTypeIds = [...new Set(attachmentRows.map((a) => a.attachmentTypeId))];
1310
1610
  const attachmentTypesById = new Map();
1311
1611
  if (attachmentTypeIds.length > 0) {
@@ -1340,6 +1640,27 @@ export class CatalogQueryService {
1340
1640
  // formatted scalar otherwise). Sorted by AttributeSetAttribute
1341
1641
  // position when assigned, by attribute key otherwise.
1342
1642
  const visibleAttributes = await this.buildVisibleAttributesProjection(em, product, attributeValues, ctx.preferredLanguage, channel, listAttributeViews);
1643
+ // T097 — OG image prefers gallery Base Image (then Thumbnail, then
1644
+ // primaryAssetUrl). Base Image is the marketer's hero shot, so social
1645
+ // shares should land on it.
1646
+ const labelled = (label) => galleryItems
1647
+ .map((g) => ({ asset: galleryAssetsById.get(g.item.assetId) ?? null, labels: labelsByItem.get(g.id) ?? [] }))
1648
+ .find((g) => g.asset && g.labels.includes(label))?.asset ?? null;
1649
+ const derivedSeo = {
1650
+ title: nameText,
1651
+ description: descriptionText.slice(0, 160),
1652
+ ogTitle: nameText,
1653
+ ogDescription: descriptionText.slice(0, 240),
1654
+ ogImageUrl: labelled('base_image')?.storageUrl ?? labelled('thumbnail')?.storageUrl ?? summary.primaryAssetUrl,
1655
+ };
1656
+ // Feature 163 (R13, Q-A) — the operator's overrides at (C, L), field by
1657
+ // field, over the derived values; the derived ones alone while `seo` is off.
1658
+ const seoMeta = (await this.seoProductMeta?.({
1659
+ productId: product.id,
1660
+ channelId: channel.id,
1661
+ languageCode: this.#availabilityScope(ctx).languageCode,
1662
+ fallback: derivedSeo,
1663
+ })) ?? derivedSeo;
1343
1664
  const detail = {
1344
1665
  ...summary,
1345
1666
  description: descriptionText,
@@ -1361,34 +1682,14 @@ export class CatalogQueryService {
1361
1682
  name: this.pickLang(c.name, ctx.preferredLanguage, channel),
1362
1683
  slug: c.slug,
1363
1684
  })),
1685
+ paths: this.#pagePaths(product, scopeRows, ctx, keysByLanguage),
1364
1686
  seo: {
1365
- metaTitle: nameText,
1366
- metaDescription: descriptionText.slice(0, 160),
1687
+ metaTitle: seoMeta.title,
1688
+ metaDescription: seoMeta.description,
1367
1689
  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
- })(),
1690
+ title: seoMeta.ogTitle,
1691
+ description: seoMeta.ogDescription,
1692
+ imageUrl: seoMeta.ogImageUrl,
1392
1693
  },
1393
1694
  },
1394
1695
  structuredDataJsonLd: {
@@ -1420,15 +1721,16 @@ export class CatalogQueryService {
1420
1721
  }
1421
1722
  : {}),
1422
1723
  gallery: galleryItems.flatMap((g) => {
1423
- const a = galleryAssetsById.get(g.assetId);
1724
+ const a = galleryAssetsById.get(g.item.assetId);
1424
1725
  if (!a)
1425
1726
  return [];
1426
1727
  return [
1427
1728
  {
1428
1729
  id: g.id,
1429
- position: g.position,
1430
- labels: [...(labelsByItem.get(g.id) ?? [])].sort(),
1730
+ position: g.item.position,
1731
+ labels: [...g.labels].sort(),
1431
1732
  asset: { id: a.id, kind: a.kind, url: a.storageUrl },
1733
+ altText: altTextOf(g.item, a),
1432
1734
  },
1433
1735
  ];
1434
1736
  }),
@@ -1441,8 +1743,9 @@ export class CatalogQueryService {
1441
1743
  {
1442
1744
  id: row.id,
1443
1745
  position: row.position,
1444
- name: row.name,
1445
- description: row.description ?? null,
1746
+ // Feature 163 (FR-078) — the text at the scope language, else the global one.
1747
+ name: translationAt(row.nameTranslations, scopeLanguage) ?? row.name,
1748
+ description: translationAt(row.descriptionTranslations, scopeLanguage) ?? row.description ?? null,
1446
1749
  type: { id: t.id, code: t.code, name: t.name },
1447
1750
  asset: {
1448
1751
  id: a.id,
@@ -1537,7 +1840,8 @@ export class CatalogQueryService {
1537
1840
  if (packagingUnits.length > 0) {
1538
1841
  detail.packagingUnits = packagingUnits.map((u) => ({
1539
1842
  id: u.id,
1540
- name: u.name,
1843
+ // Feature 163 (FR-079) — the name at the scope language, else the global name.
1844
+ name: effectivePackagingUnitName(u, scopeLanguage),
1541
1845
  baseQuantity: u.baseQuantity,
1542
1846
  position: u.position,
1543
1847
  isDefault: u.isDefault,
@@ -1559,21 +1863,28 @@ export class CatalogQueryService {
1559
1863
  const result = new Map();
1560
1864
  if (ids.length === 0)
1561
1865
  return result;
1562
- const products = await em.find(Product, { id: { $in: ids } });
1866
+ // Feature 163 — a child or option off at (C, L), outside its window or
1867
+ // outside the audience is not offered through its parent (edge case
1868
+ // *child off*): it is left out of the composite, as an absent one is.
1869
+ const candidates = await em.find(Product, { id: { $in: ids } });
1870
+ const available = await this.#availableAmong(em, candidates, this.#availabilityScope(ctx), false);
1871
+ const products = candidates.filter((p) => available.has(p.id));
1563
1872
  // Primary asset url via gallery thumb chain -> base_image -> first item
1564
1873
  // -> legacy product_assets first row. One helper, shared with `toSummary`
1565
1874
  // and `ProductLinkService`, so the chain and the port call have one home.
1566
- const assetUrlByProduct = await resolvePrimaryAssetUrls(em, this.#requireAssets(), ids);
1875
+ const assetUrlByProduct = await resolvePrimaryAssetUrls(em, this.#requireAssets(), ids, channel.id);
1567
1876
  const resolvedPrices = await this.#listingPricesFor(products, ctx);
1568
1877
  // Issue #384 — one statement for every child's override rows on this channel.
1569
1878
  const overridesByProduct = await loadChannelOverridesByProduct(em, ids, channel.id);
1570
1879
  const overrideCtx = this.#overrideContext(channel, ctx.preferredLanguage);
1880
+ // Feature 163 (R28) — a child's link is its effective key at (C, L).
1881
+ const effectiveKeys = await this.#effectiveKeysAt(em, products, ctx);
1571
1882
  for (const p of products) {
1572
1883
  const price = this.#summaryPrice(resolvedPrices, p.id);
1573
1884
  result.set(p.id, {
1574
1885
  id: p.id,
1575
1886
  sku: p.sku,
1576
- slug: p.slug,
1887
+ slug: effectiveKeys.get(p.id) ?? p.slug,
1577
1888
  name: effectiveSystemText(overridesByProduct.get(p.id), 'name', overrideCtx, p.name, this.pickLang(p.name, ctx.preferredLanguage, channel)),
1578
1889
  primaryAssetUrl: assetUrlByProduct.get(p.id) ?? null,
1579
1890
  price,
@@ -1592,7 +1903,7 @@ export class CatalogQueryService {
1592
1903
  // roots seed the walk.
1593
1904
  const rows = await em.find(Category, { deletedAt: null, isActive: true }, { orderBy: { sortOrder: 'asc' } });
1594
1905
  // Directly-assigned products per category that this caller may see.
1595
- const directSets = await this.directProductSetsByCategory(em, channel, ctx.audience);
1906
+ const directSets = await this.directProductSetsByCategory(em, channel, this.#availabilityScope(ctx));
1596
1907
  const byParent = new Map();
1597
1908
  for (const row of rows) {
1598
1909
  const key = row.parentCategoryId ?? null;
@@ -1695,13 +2006,29 @@ export class CatalogQueryService {
1695
2006
  const em = this.emFactory();
1696
2007
  const channel = ctx.resolvedChannel;
1697
2008
  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
2009
+ // Build option / range facets by scanning Products available in the
2010
+ // channel. Issue #227 — a facet count is a disclosure too. "Brass (3)" on a
1702
2011
  // 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));
2012
+ // one, named by arithmetic; feature 163 extends that to a product off at
2013
+ // (C, L) or outside its window. Availability is in the statement and then
2014
+ // the rule's own word on each row; the `raw()` key is made in the
2015
+ // expression that executes it.
2016
+ const scope = this.#availabilityScope(ctx);
2017
+ const narrowing = this.#availabilityNarrowing(scope);
2018
+ const products = await em.find(Product, {
2019
+ $and: [{ deletedAt: null }, { [raw(narrowing.sql, narrowing.params)]: [] }],
2020
+ });
2021
+ const visibleIds = await this.#availableAmong(em, products, scope, true);
2022
+ const visible = products.filter((p) => visibleIds.has(p.id));
2023
+ // Feature 163 (FR-017 b) — counts over the effective values a card shows at
2024
+ // (channel, language): #384's walk over this channel's override rows.
2025
+ const effective = this.#overrideContext(channel, ctx.preferredLanguage);
2026
+ const scopeOf = new Map(attrs.map((a) => [a.key, { channelScoped: a.channelScoped, languageScoped: a.languageScoped }]));
2027
+ const overrides = await loadChannelOverridesByProduct(em, visible.map((p) => p.id), channel.id);
2028
+ const valuesOf = new Map();
2029
+ for (const p of visible) {
2030
+ valuesOf.set(p.id, await effectiveAttributeValues(p.attributeValues ?? {}, overrides.get(p.id), effective, async () => scopeOf));
2031
+ }
1705
2032
  const definitions = attrs.map((a) => {
1706
2033
  const label = this.pickLang(a.label, ctx.preferredLanguage, channel);
1707
2034
  const def = {
@@ -1717,7 +2044,7 @@ export class CatalogQueryService {
1717
2044
  a.valueType === 'string') {
1718
2045
  const optionCounts = new Map();
1719
2046
  for (const p of visible) {
1720
- const v = p.attributeValues[a.key];
2047
+ const v = valuesOf.get(p.id)?.[a.key];
1721
2048
  if (v === undefined || v === null)
1722
2049
  continue;
1723
2050
  // multiselect carries an array of selected option values.
@@ -1742,7 +2069,7 @@ export class CatalogQueryService {
1742
2069
  let min;
1743
2070
  let max;
1744
2071
  for (const p of visible) {
1745
- const raw = p.attributeValues[a.key];
2072
+ const raw = valuesOf.get(p.id)?.[a.key];
1746
2073
  const n = typeof raw === 'number' ? raw : Number(raw);
1747
2074
  if (!Number.isFinite(n))
1748
2075
  continue;
@@ -1919,11 +2246,6 @@ export class CatalogQueryService {
1919
2246
  });
1920
2247
  return items;
1921
2248
  }
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
2249
  /**
1928
2250
  * Feature 007 — list of attribute keys flagged `is_comparable=true`,
1929
2251
  * sorted alphabetically. Consumed by the comparisons module's
@@ -1979,68 +2301,42 @@ export class CatalogQueryService {
1979
2301
  options,
1980
2302
  };
1981
2303
  }
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
2304
  /**
2007
2305
  * The keyset a listing pages by — **derived from the ordering it serves**,
2008
- * never assumed.
2306
+ * never assumed. The ordering and the "everything after this row" predicate
2307
+ * are one decision, and they had come apart once: the `after` predicate was
2308
+ * written over `created_at` whatever the ordering, so under `sort=name` the
2309
+ * walk both repeated products and skipped the ones between the repeats.
2009
2310
  *
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`.
2019
- *
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.
2311
+ * Feature 163 (D6) — the name ordering is the **effective** name a card shows
2312
+ * at the request's (channel, language), `effectiveTextSql`, with `id` as the
2313
+ * tie-break (the name is not unique). It replaced an ordering by `slug`.
2023
2314
  */
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';
2315
+ #keysetFor(sort, ctx) {
2316
+ if (sort === 'name' || sort === '-name') {
2317
+ const direction = sort === 'name' ? 'asc' : 'desc';
2318
+ const cmp = direction === 'asc' ? '>' : '<';
2319
+ const name = this.#effectiveNameExpr(ctx);
2032
2320
  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'] }
2321
+ byName: true,
2322
+ of: (product, nameOf) => ({ name: nameOf(product.id) ?? '', id: product.id }),
2323
+ parse: (decoded) => isRecord(decoded) && typeof decoded['name'] === 'string' && isUuidText(decoded['id'])
2324
+ ? { name: decoded['name'], id: decoded['id'] }
2036
2325
  : null,
2037
- after: (cursor) => afterKeysetCursor(cursor, op),
2326
+ after: (cursor) => {
2327
+ if (!('name' in cursor))
2328
+ return {};
2329
+ return {
2330
+ [raw((alias) => `(${name.sql(alias)} ${cmp} ? or (${name.sql(alias)} = ? and ${alias}.id ${cmp} ?))`, [...name.params, cursor.name, ...name.params, cursor.name, cursor.id])]: [],
2331
+ };
2332
+ },
2333
+ orderBy: () => ({ [raw((alias) => name.sql(alias), name.params)]: direction, id: direction }),
2038
2334
  };
2039
2335
  }
2040
2336
  // 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.
2337
+ // reaches here.
2043
2338
  return {
2339
+ byName: false,
2044
2340
  of: (product) => ({ createdAt: product.createdAt.toISOString(), id: product.id }),
2045
2341
  // The id is compared with a uuid column: a cursor naming anything else is
2046
2342
  // discarded here rather than refused by the database as a 500.
@@ -2051,8 +2347,37 @@ export class CatalogQueryService {
2051
2347
  ? { createdAt: decoded['createdAt'], id: decoded['id'] }
2052
2348
  : null,
2053
2349
  after: (cursor) => afterKeysetCursor(cursor, '$lt'),
2350
+ orderBy: () => ({ createdAt: 'desc', id: 'desc' }),
2054
2351
  };
2055
2352
  }
2353
+ /**
2354
+ * Feature 163 (FR-017 b) — the effective Name a card shows at the request's
2355
+ * (channel, language), as SQL: the value the listing searches and sorts on.
2356
+ * The same two language chains `toSummary` uses (`#overrideContext` and
2357
+ * `pickLang`).
2358
+ */
2359
+ #effectiveNameExpr(ctx) {
2360
+ const channel = ctx.resolvedChannel;
2361
+ return effectiveTextSql('name', this.#overrideContext(channel, ctx.preferredLanguage), [ctx.preferredLanguage, channel.defaultLanguage, 'en-US', 'en'].filter((v) => typeof v === 'string'));
2362
+ }
2363
+ /**
2364
+ * The names a name cursor carries — **the statement's own sort key**, read by
2365
+ * the same `effectiveTextSql` expression the ordering and the `after`
2366
+ * predicate use (`#keysetFor`), so the cursor can never disagree with the
2367
+ * order it continues (code review W4). It used to be recomputed by the
2368
+ * TypeScript walk, which is held equal to the SQL by a parity test but is a
2369
+ * second implementation: when the two diverged, a walk repeated and skipped
2370
+ * rows. One keyed statement over the page's last row — the read it replaces
2371
+ * cost the same — and nothing when the keyset does not need it.
2372
+ */
2373
+ async #cursorNames(em, keyset, products, ctx) {
2374
+ if (!keyset.byName || products.length === 0)
2375
+ return () => undefined;
2376
+ const name = this.#effectiveNameExpr(ctx);
2377
+ 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))]);
2378
+ const names = new Map(rows.map((row) => [row.id, row.name ?? '']));
2379
+ return (productId) => names.get(productId);
2380
+ }
2056
2381
  async filterByChannel(productIds, channel) {
2057
2382
  if (productIds.length === 0)
2058
2383
  return new Set();
@@ -2106,26 +2431,24 @@ export class CatalogQueryService {
2106
2431
  * (i.e. via a `product_categories` row). Subtree roll-up to ancestors is
2107
2432
  * done by the caller, which has the parent map to walk.
2108
2433
  */
2109
- async directProductSetsByCategory(em, channel, audience) {
2434
+ async directProductSetsByCategory(em, channel, scope) {
2110
2435
  const base = await em.execute(`select category_id, product_id from product_categories`);
2111
2436
  if (base.length === 0)
2112
2437
  return new Map();
2113
2438
  // 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));
2439
+ const memberIds = await this.filterByChannel(base.map((r) => r.product_id), channel);
2440
+ // Issue #227 / feature 163 — and availability, which needs the columns
2441
+ // this path never loaded: `product_categories` carries ids and nothing
2442
+ // else, so the rows come back here rather than the predicate going down
2443
+ // there. The category tree publishes a `productCount` per node, and a count
2444
+ // is the one field a restricted, switched-off or out-of-window product can
2445
+ // still move.
2446
+ const members = await em.find(Product, { id: { $in: [...memberIds] } });
2447
+ const visibleIds = await this.#availableAmong(em, members, scope, true);
2123
2448
  const sets = new Map();
2124
2449
  for (const row of base) {
2125
2450
  if (!visibleIds.has(row.product_id))
2126
2451
  continue;
2127
- if (restricted.has(row.product_id))
2128
- continue;
2129
2452
  let set = sets.get(row.category_id);
2130
2453
  if (!set) {
2131
2454
  set = new Set();
@@ -2152,28 +2475,34 @@ export class CatalogQueryService {
2152
2475
  */
2153
2476
  toSummary(product, channel, preferredLanguage, resolvedPrices, cardReads) {
2154
2477
  // 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.
2478
+ // (issue #132), read out of the page's resolution — a figure a price book
2479
+ // stands behind, or nothing where the viewer's display mode withholds it.
2159
2480
  const price = this.#summaryPrice(resolvedPrices, product.id);
2160
2481
  // Issue #384 — the channel's override when one applies, else the baseline
2161
2482
  // language pick, out of the page's pre-read override rows.
2162
2483
  const nameText = effectiveSystemText(cardReads.overridesByProduct.get(product.id), 'name', this.#overrideContext(channel, preferredLanguage), product.name, this.pickLang(product.name, preferredLanguage, channel));
2484
+ // Feature 163 (R-16) — the card's summary, from the description this row
2485
+ // already holds, through the same override and language pick as the PDP's.
2486
+ const descriptionText = effectiveSystemText(cardReads.overridesByProduct.get(product.id), 'description', this.#overrideContext(channel, preferredLanguage), product.description, this.pickLang(product.description, preferredLanguage, channel));
2163
2487
  return {
2164
2488
  id: product.id,
2165
2489
  sku: product.sku,
2166
2490
  type: product.type,
2167
2491
  name: nameText,
2168
- slug: product.slug,
2492
+ // Feature 163 (R28) — the effective key at the request's (channel, language).
2493
+ slug: cardReads.effectiveKeyByProduct.get(product.id) ?? product.slug,
2494
+ summary: productSummaryText(descriptionText),
2169
2495
  categorySlugs: cardReads.categorySlugsByProduct.get(product.id) ?? [],
2170
2496
  primaryAssetUrl: cardReads.assetUrlByProduct.get(product.id) ?? null,
2171
2497
  price,
2172
2498
  stockIndicator: null,
2173
2499
  stockLevel: null,
2174
2500
  // Feature 155 (FR-014) — emitted for the types the minimum applies to only.
2501
+ // Feature 163 (FR-100) — the request channel's minimum.
2175
2502
  minOrderQuantity: isOrderMinimumEligibleType(product.type)
2176
- ? (product.minOrderQuantity ?? null)
2503
+ ? (cardReads.minOrderQuantityByProduct.has(product.id)
2504
+ ? (cardReads.minOrderQuantityByProduct.get(product.id) ?? null)
2505
+ : (product.minOrderQuantity ?? null))
2177
2506
  : null,
2178
2507
  resolvedPrice: this.#summaryResolvedPrice(resolvedPrices, product.id),
2179
2508
  ...this.#summaryPriceBookFields(resolvedPrices, product.id),