@open-mercato/core 0.9.1-develop.7473.1.de5b22888f → 0.9.1-develop.7475.1.28ca93ed97

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 (597) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/dist/generated/entities/catalog_price_history_entry/index.js +53 -0
  3. package/dist/generated/entities/catalog_price_history_entry/index.js.map +7 -0
  4. package/dist/generated/entities/customer_group_terms/index.js +2 -0
  5. package/dist/generated/entities/customer_group_terms/index.js.map +2 -2
  6. package/dist/generated/entities/ecommerce_store/index.js +33 -0
  7. package/dist/generated/entities/ecommerce_store/index.js.map +7 -0
  8. package/dist/generated/entities/ecommerce_store_channel_binding/index.js +29 -0
  9. package/dist/generated/entities/ecommerce_store_channel_binding/index.js.map +7 -0
  10. package/dist/generated/entities/ecommerce_store_domain_binding/index.js +23 -0
  11. package/dist/generated/entities/ecommerce_store_domain_binding/index.js.map +7 -0
  12. package/dist/generated/entities.ids.generated.js +8 -1
  13. package/dist/generated/entities.ids.generated.js.map +2 -2
  14. package/dist/generated/entity-fields-registry.js +72 -0
  15. package/dist/generated/entity-fields-registry.js.map +2 -2
  16. package/dist/helpers/integration/customerGroupsFixtures.js.map +2 -2
  17. package/dist/modules/catalog/acl.js +8 -1
  18. package/dist/modules/catalog/acl.js.map +2 -2
  19. package/dist/modules/catalog/api/config/omnibus/route.js +184 -0
  20. package/dist/modules/catalog/api/config/omnibus/route.js.map +7 -0
  21. package/dist/modules/catalog/api/prices/history/route.js +131 -0
  22. package/dist/modules/catalog/api/prices/history/route.js.map +7 -0
  23. package/dist/modules/catalog/api/prices/omnibus-preview/route.js +184 -0
  24. package/dist/modules/catalog/api/prices/omnibus-preview/route.js.map +7 -0
  25. package/dist/modules/catalog/api/products/route.js +54 -245
  26. package/dist/modules/catalog/api/products/route.js.map +3 -3
  27. package/dist/modules/catalog/api/tags/route.js +6 -0
  28. package/dist/modules/catalog/api/tags/route.js.map +2 -2
  29. package/dist/modules/catalog/backend/config/catalog/page.js +3 -1
  30. package/dist/modules/catalog/backend/config/catalog/page.js.map +2 -2
  31. package/dist/modules/catalog/cli.js +80 -2
  32. package/dist/modules/catalog/cli.js.map +2 -2
  33. package/dist/modules/catalog/commands/categories.js +51 -2
  34. package/dist/modules/catalog/commands/categories.js.map +2 -2
  35. package/dist/modules/catalog/commands/prices.js +43 -1
  36. package/dist/modules/catalog/commands/prices.js.map +2 -2
  37. package/dist/modules/catalog/commands/products.js +71 -0
  38. package/dist/modules/catalog/commands/products.js.map +2 -2
  39. package/dist/modules/catalog/commands/variants.js +7 -0
  40. package/dist/modules/catalog/commands/variants.js.map +2 -2
  41. package/dist/modules/catalog/components/OmnibusSettings.js +703 -0
  42. package/dist/modules/catalog/components/OmnibusSettings.js.map +7 -0
  43. package/dist/modules/catalog/components/PriceEditorOmnibusRow.js +152 -0
  44. package/dist/modules/catalog/components/PriceEditorOmnibusRow.js.map +7 -0
  45. package/dist/modules/catalog/components/lookupSources.js +31 -0
  46. package/dist/modules/catalog/components/lookupSources.js.map +7 -0
  47. package/dist/modules/catalog/components/prices/PriceScopeSelectors.js +8 -2
  48. package/dist/modules/catalog/components/prices/PriceScopeSelectors.js.map +2 -2
  49. package/dist/modules/catalog/components/products/VariantBuilder.js +11 -1
  50. package/dist/modules/catalog/components/products/VariantBuilder.js.map +2 -2
  51. package/dist/modules/catalog/data/entities.js +122 -1
  52. package/dist/modules/catalog/data/entities.js.map +2 -2
  53. package/dist/modules/catalog/data/validators.js +78 -0
  54. package/dist/modules/catalog/data/validators.js.map +2 -2
  55. package/dist/modules/catalog/di.js +18 -0
  56. package/dist/modules/catalog/di.js.map +2 -2
  57. package/dist/modules/catalog/lib/omnibus.js +285 -0
  58. package/dist/modules/catalog/lib/omnibus.js.map +7 -0
  59. package/dist/modules/catalog/lib/omnibusBackfill.js +146 -0
  60. package/dist/modules/catalog/lib/omnibusBackfill.js.map +7 -0
  61. package/dist/modules/catalog/lib/omnibusCache.js +89 -0
  62. package/dist/modules/catalog/lib/omnibusCache.js.map +7 -0
  63. package/dist/modules/catalog/lib/omnibusConfig.js +64 -0
  64. package/dist/modules/catalog/lib/omnibusConfig.js.map +7 -0
  65. package/dist/modules/catalog/lib/omnibusHistoryQueries.js +191 -0
  66. package/dist/modules/catalog/lib/omnibusHistoryQueries.js.map +7 -0
  67. package/dist/modules/catalog/lib/omnibusPresentedEntry.js +73 -0
  68. package/dist/modules/catalog/lib/omnibusPresentedEntry.js.map +7 -0
  69. package/dist/modules/catalog/lib/omnibusProductListEnrichment.js +94 -0
  70. package/dist/modules/catalog/lib/omnibusProductListEnrichment.js.map +7 -0
  71. package/dist/modules/catalog/lib/omnibusTypes.js +115 -0
  72. package/dist/modules/catalog/lib/omnibusTypes.js.map +7 -0
  73. package/dist/modules/catalog/lib/optionSchemaTranslations.js +55 -0
  74. package/dist/modules/catalog/lib/optionSchemaTranslations.js.map +7 -0
  75. package/dist/modules/catalog/lib/priceHistoryQuery.js +103 -0
  76. package/dist/modules/catalog/lib/priceHistoryQuery.js.map +7 -0
  77. package/dist/modules/catalog/lib/pricing.js +26 -2
  78. package/dist/modules/catalog/lib/pricing.js.map +2 -2
  79. package/dist/modules/catalog/lib/productFilters.js +273 -0
  80. package/dist/modules/catalog/lib/productFilters.js.map +7 -0
  81. package/dist/modules/catalog/lib/productScopeKeys.js +105 -0
  82. package/dist/modules/catalog/lib/productScopeKeys.js.map +7 -0
  83. package/dist/modules/catalog/lib/productScopeReindex.js +73 -0
  84. package/dist/modules/catalog/lib/productScopeReindex.js.map +7 -0
  85. package/dist/modules/catalog/migrations/Migration20261005105352_catalog.js +39 -0
  86. package/dist/modules/catalog/migrations/Migration20261005105352_catalog.js.map +7 -0
  87. package/dist/modules/catalog/migrations/Migration20261005150824_catalog.js +39 -0
  88. package/dist/modules/catalog/migrations/Migration20261005150824_catalog.js.map +7 -0
  89. package/dist/modules/catalog/services/catalogOmnibusService.js +480 -0
  90. package/dist/modules/catalog/services/catalogOmnibusService.js.map +7 -0
  91. package/dist/modules/catalog/setup.js +3 -1
  92. package/dist/modules/catalog/setup.js.map +2 -2
  93. package/dist/modules/catalog/subscribers/product-scope-keys-category-deleted.js +16 -0
  94. package/dist/modules/catalog/subscribers/product-scope-keys-category-deleted.js.map +7 -0
  95. package/dist/modules/catalog/subscribers/product-scope-keys-category-updated.js +17 -0
  96. package/dist/modules/catalog/subscribers/product-scope-keys-category-updated.js.map +7 -0
  97. package/dist/modules/catalog/translations.js +10 -0
  98. package/dist/modules/catalog/translations.js.map +2 -2
  99. package/dist/modules/configs/lib/upgrade-actions.js +28 -0
  100. package/dist/modules/configs/lib/upgrade-actions.js.map +2 -2
  101. package/dist/modules/customer_groups/api/customer-groups/[id]/terms/route.js +5 -0
  102. package/dist/modules/customer_groups/api/customer-groups/[id]/terms/route.js.map +2 -2
  103. package/dist/modules/customer_groups/components/CustomerGroupTermsSection.js +111 -3
  104. package/dist/modules/customer_groups/components/CustomerGroupTermsSection.js.map +2 -2
  105. package/dist/modules/customer_groups/components/customerGroupAssortmentScope.js +43 -0
  106. package/dist/modules/customer_groups/components/customerGroupAssortmentScope.js.map +7 -0
  107. package/dist/modules/customer_groups/data/entities.js +3 -0
  108. package/dist/modules/customer_groups/data/entities.js.map +2 -2
  109. package/dist/modules/customer_groups/data/validators.js +9 -0
  110. package/dist/modules/customer_groups/data/validators.js.map +2 -2
  111. package/dist/modules/customer_groups/migrations/Migration20261005110250_customer_groups.js +17 -0
  112. package/dist/modules/customer_groups/migrations/Migration20261005110250_customer_groups.js.map +7 -0
  113. package/dist/modules/customer_groups/services/customerGroupsService.js +62 -15
  114. package/dist/modules/customer_groups/services/customerGroupsService.js.map +2 -2
  115. package/dist/modules/ecommerce/acl.js +13 -0
  116. package/dist/modules/ecommerce/acl.js.map +7 -0
  117. package/dist/modules/ecommerce/api/domain-mappings/route.js +72 -0
  118. package/dist/modules/ecommerce/api/domain-mappings/route.js.map +7 -0
  119. package/dist/modules/ecommerce/api/openapi.js +27 -0
  120. package/dist/modules/ecommerce/api/openapi.js.map +7 -0
  121. package/dist/modules/ecommerce/api/store-channel-bindings/[id]/assortment-count/route.js +109 -0
  122. package/dist/modules/ecommerce/api/store-channel-bindings/[id]/assortment-count/route.js.map +7 -0
  123. package/dist/modules/ecommerce/api/store-channel-bindings/crud.js +265 -0
  124. package/dist/modules/ecommerce/api/store-channel-bindings/crud.js.map +7 -0
  125. package/dist/modules/ecommerce/api/store-channel-bindings/route.js +67 -0
  126. package/dist/modules/ecommerce/api/store-channel-bindings/route.js.map +7 -0
  127. package/dist/modules/ecommerce/api/store-domain-bindings/crud.js +296 -0
  128. package/dist/modules/ecommerce/api/store-domain-bindings/crud.js.map +7 -0
  129. package/dist/modules/ecommerce/api/store-domain-bindings/route.js +73 -0
  130. package/dist/modules/ecommerce/api/store-domain-bindings/route.js.map +7 -0
  131. package/dist/modules/ecommerce/api/storefront/categories/[slug]/route.js +87 -0
  132. package/dist/modules/ecommerce/api/storefront/categories/[slug]/route.js.map +7 -0
  133. package/dist/modules/ecommerce/api/storefront/categories/openapiSchemas.js +50 -0
  134. package/dist/modules/ecommerce/api/storefront/categories/openapiSchemas.js.map +7 -0
  135. package/dist/modules/ecommerce/api/storefront/categories/route.js +75 -0
  136. package/dist/modules/ecommerce/api/storefront/categories/route.js.map +7 -0
  137. package/dist/modules/ecommerce/api/storefront/context/route.js +163 -0
  138. package/dist/modules/ecommerce/api/storefront/context/route.js.map +7 -0
  139. package/dist/modules/ecommerce/api/storefront/products/[idOrHandle]/route.js +87 -0
  140. package/dist/modules/ecommerce/api/storefront/products/[idOrHandle]/route.js.map +7 -0
  141. package/dist/modules/ecommerce/api/storefront/products/openapiSchemas.js +177 -0
  142. package/dist/modules/ecommerce/api/storefront/products/openapiSchemas.js.map +7 -0
  143. package/dist/modules/ecommerce/api/storefront/products/route.js +78 -0
  144. package/dist/modules/ecommerce/api/storefront/products/route.js.map +7 -0
  145. package/dist/modules/ecommerce/api/storefront/search/suggest/openapiSchemas.js +25 -0
  146. package/dist/modules/ecommerce/api/storefront/search/suggest/openapiSchemas.js.map +7 -0
  147. package/dist/modules/ecommerce/api/storefront/search/suggest/route.js +75 -0
  148. package/dist/modules/ecommerce/api/storefront/search/suggest/route.js.map +7 -0
  149. package/dist/modules/ecommerce/api/storefront/storefrontRouteSupport.js +58 -0
  150. package/dist/modules/ecommerce/api/storefront/storefrontRouteSupport.js.map +7 -0
  151. package/dist/modules/ecommerce/api/stores/[id]/branding/route.js +183 -0
  152. package/dist/modules/ecommerce/api/stores/[id]/branding/route.js.map +7 -0
  153. package/dist/modules/ecommerce/api/stores/[id]/preview-branding/route.js +92 -0
  154. package/dist/modules/ecommerce/api/stores/[id]/preview-branding/route.js.map +7 -0
  155. package/dist/modules/ecommerce/api/stores/crud.js +401 -0
  156. package/dist/modules/ecommerce/api/stores/crud.js.map +7 -0
  157. package/dist/modules/ecommerce/api/stores/route.js +64 -0
  158. package/dist/modules/ecommerce/api/stores/route.js.map +7 -0
  159. package/dist/modules/ecommerce/backend/config/ecommerce/[id]/page.js +9 -0
  160. package/dist/modules/ecommerce/backend/config/ecommerce/[id]/page.js.map +7 -0
  161. package/dist/modules/ecommerce/backend/config/ecommerce/[id]/page.meta.js +16 -0
  162. package/dist/modules/ecommerce/backend/config/ecommerce/[id]/page.meta.js.map +7 -0
  163. package/dist/modules/ecommerce/backend/config/ecommerce/page.js +9 -0
  164. package/dist/modules/ecommerce/backend/config/ecommerce/page.js.map +7 -0
  165. package/dist/modules/ecommerce/backend/config/ecommerce/page.meta.js +16 -0
  166. package/dist/modules/ecommerce/backend/config/ecommerce/page.meta.js.map +7 -0
  167. package/dist/modules/ecommerce/commands/stores.js +110 -0
  168. package/dist/modules/ecommerce/commands/stores.js.map +7 -0
  169. package/dist/modules/ecommerce/components/ChannelAssortmentCount.js +90 -0
  170. package/dist/modules/ecommerce/components/ChannelAssortmentCount.js.map +7 -0
  171. package/dist/modules/ecommerce/components/ChannelBindingFormSections.js +33 -0
  172. package/dist/modules/ecommerce/components/ChannelBindingFormSections.js.map +7 -0
  173. package/dist/modules/ecommerce/components/ChannelLookupPicker.js +11 -0
  174. package/dist/modules/ecommerce/components/ChannelLookupPicker.js.map +7 -0
  175. package/dist/modules/ecommerce/components/DomainStatusWarning.js +24 -0
  176. package/dist/modules/ecommerce/components/DomainStatusWarning.js.map +7 -0
  177. package/dist/modules/ecommerce/components/StoreAvailabilityDefaultsSection.js +190 -0
  178. package/dist/modules/ecommerce/components/StoreAvailabilityDefaultsSection.js.map +7 -0
  179. package/dist/modules/ecommerce/components/StoreBrandingControls.js +67 -0
  180. package/dist/modules/ecommerce/components/StoreBrandingControls.js.map +7 -0
  181. package/dist/modules/ecommerce/components/StoreBrandingPreview.js +69 -0
  182. package/dist/modules/ecommerce/components/StoreBrandingPreview.js.map +7 -0
  183. package/dist/modules/ecommerce/components/StoreBrandingTab.js +218 -0
  184. package/dist/modules/ecommerce/components/StoreBrandingTab.js.map +7 -0
  185. package/dist/modules/ecommerce/components/StoreChannelBindingDialog.js +270 -0
  186. package/dist/modules/ecommerce/components/StoreChannelBindingDialog.js.map +7 -0
  187. package/dist/modules/ecommerce/components/StoreChannelsTab.js +313 -0
  188. package/dist/modules/ecommerce/components/StoreChannelsTab.js.map +7 -0
  189. package/dist/modules/ecommerce/components/StoreCreateDialog.js +164 -0
  190. package/dist/modules/ecommerce/components/StoreCreateDialog.js.map +7 -0
  191. package/dist/modules/ecommerce/components/StoreDomainBindingDialog.js +162 -0
  192. package/dist/modules/ecommerce/components/StoreDomainBindingDialog.js.map +7 -0
  193. package/dist/modules/ecommerce/components/StoreDomainsTab.js +357 -0
  194. package/dist/modules/ecommerce/components/StoreDomainsTab.js.map +7 -0
  195. package/dist/modules/ecommerce/components/StoreEditPage.js +155 -0
  196. package/dist/modules/ecommerce/components/StoreEditPage.js.map +7 -0
  197. package/dist/modules/ecommerce/components/StoreGeneralTab.js +167 -0
  198. package/dist/modules/ecommerce/components/StoreGeneralTab.js.map +7 -0
  199. package/dist/modules/ecommerce/components/StoreListPage.js +290 -0
  200. package/dist/modules/ecommerce/components/StoreListPage.js.map +7 -0
  201. package/dist/modules/ecommerce/components/StoreSeoTab.js +132 -0
  202. package/dist/modules/ecommerce/components/StoreSeoTab.js.map +7 -0
  203. package/dist/modules/ecommerce/components/StoreStatusBadge.js +20 -0
  204. package/dist/modules/ecommerce/components/StoreStatusBadge.js.map +7 -0
  205. package/dist/modules/ecommerce/components/channelLookups.js +28 -0
  206. package/dist/modules/ecommerce/components/channelLookups.js.map +7 -0
  207. package/dist/modules/ecommerce/components/storeAdmin.js +41 -0
  208. package/dist/modules/ecommerce/components/storeAdmin.js.map +7 -0
  209. package/dist/modules/ecommerce/components/storeBrandingForm.js +197 -0
  210. package/dist/modules/ecommerce/components/storeBrandingForm.js.map +7 -0
  211. package/dist/modules/ecommerce/components/storeChannels.js +140 -0
  212. package/dist/modules/ecommerce/components/storeChannels.js.map +7 -0
  213. package/dist/modules/ecommerce/components/storeDomains.js +167 -0
  214. package/dist/modules/ecommerce/components/storeDomains.js.map +7 -0
  215. package/dist/modules/ecommerce/components/storeEditTabs.js +62 -0
  216. package/dist/modules/ecommerce/components/storeEditTabs.js.map +7 -0
  217. package/dist/modules/ecommerce/components/storeGeneral.js +95 -0
  218. package/dist/modules/ecommerce/components/storeGeneral.js.map +7 -0
  219. package/dist/modules/ecommerce/components/storeSeo.js +69 -0
  220. package/dist/modules/ecommerce/components/storeSeo.js.map +7 -0
  221. package/dist/modules/ecommerce/components/useChannelAssortmentCount.js +45 -0
  222. package/dist/modules/ecommerce/components/useChannelAssortmentCount.js.map +7 -0
  223. package/dist/modules/ecommerce/components/useStoreAccess.js +28 -0
  224. package/dist/modules/ecommerce/components/useStoreAccess.js.map +7 -0
  225. package/dist/modules/ecommerce/data/enrichers.js +157 -0
  226. package/dist/modules/ecommerce/data/enrichers.js.map +7 -0
  227. package/dist/modules/ecommerce/data/entities.js +197 -0
  228. package/dist/modules/ecommerce/data/entities.js.map +7 -0
  229. package/dist/modules/ecommerce/data/validators.js +406 -0
  230. package/dist/modules/ecommerce/data/validators.js.map +7 -0
  231. package/dist/modules/ecommerce/di.js +11 -0
  232. package/dist/modules/ecommerce/di.js.map +7 -0
  233. package/dist/modules/ecommerce/events.js +27 -0
  234. package/dist/modules/ecommerce/events.js.map +7 -0
  235. package/dist/modules/ecommerce/index.js +16 -0
  236. package/dist/modules/ecommerce/index.js.map +7 -0
  237. package/dist/modules/ecommerce/lib/assortmentCount.js +112 -0
  238. package/dist/modules/ecommerce/lib/assortmentCount.js.map +7 -0
  239. package/dist/modules/ecommerce/lib/brandingStyles.js +184 -0
  240. package/dist/modules/ecommerce/lib/brandingStyles.js.map +7 -0
  241. package/dist/modules/ecommerce/lib/buyerContext.js +284 -0
  242. package/dist/modules/ecommerce/lib/buyerContext.js.map +7 -0
  243. package/dist/modules/ecommerce/lib/cacheInvalidation.js +186 -0
  244. package/dist/modules/ecommerce/lib/cacheInvalidation.js.map +7 -0
  245. package/dist/modules/ecommerce/lib/cacheKeys.js +236 -0
  246. package/dist/modules/ecommerce/lib/cacheKeys.js.map +7 -0
  247. package/dist/modules/ecommerce/lib/createConflictRecheck.js +29 -0
  248. package/dist/modules/ecommerce/lib/createConflictRecheck.js.map +7 -0
  249. package/dist/modules/ecommerce/lib/crudEvents.js +94 -0
  250. package/dist/modules/ecommerce/lib/crudEvents.js.map +7 -0
  251. package/dist/modules/ecommerce/lib/crudSupport.js +64 -0
  252. package/dist/modules/ecommerce/lib/crudSupport.js.map +7 -0
  253. package/dist/modules/ecommerce/lib/domainBindingRebind.js +99 -0
  254. package/dist/modules/ecommerce/lib/domainBindingRebind.js.map +7 -0
  255. package/dist/modules/ecommerce/lib/domainMappingSummaries.js +39 -0
  256. package/dist/modules/ecommerce/lib/domainMappingSummaries.js.map +7 -0
  257. package/dist/modules/ecommerce/lib/exclusiveFlag.js +57 -0
  258. package/dist/modules/ecommerce/lib/exclusiveFlag.js.map +7 -0
  259. package/dist/modules/ecommerce/lib/references.js +70 -0
  260. package/dist/modules/ecommerce/lib/references.js.map +7 -0
  261. package/dist/modules/ecommerce/lib/seedDraftStore.js +99 -0
  262. package/dist/modules/ecommerce/lib/seedDraftStore.js.map +7 -0
  263. package/dist/modules/ecommerce/lib/storeBindingCascade.js +109 -0
  264. package/dist/modules/ecommerce/lib/storeBindingCascade.js.map +7 -0
  265. package/dist/modules/ecommerce/lib/storeBranding.js +40 -0
  266. package/dist/modules/ecommerce/lib/storeBranding.js.map +7 -0
  267. package/dist/modules/ecommerce/lib/storeBrandingRoute.js +76 -0
  268. package/dist/modules/ecommerce/lib/storeBrandingRoute.js.map +7 -0
  269. package/dist/modules/ecommerce/lib/storeContext.js +393 -0
  270. package/dist/modules/ecommerce/lib/storeContext.js.map +7 -0
  271. package/dist/modules/ecommerce/lib/storeContextService.js +43 -0
  272. package/dist/modules/ecommerce/lib/storeContextService.js.map +7 -0
  273. package/dist/modules/ecommerce/lib/storeLocale.js +60 -0
  274. package/dist/modules/ecommerce/lib/storeLocale.js.map +7 -0
  275. package/dist/modules/ecommerce/lib/storeNotifications.js +41 -0
  276. package/dist/modules/ecommerce/lib/storeNotifications.js.map +7 -0
  277. package/dist/modules/ecommerce/lib/storefrontCatalogSupport.js +248 -0
  278. package/dist/modules/ecommerce/lib/storefrontCatalogSupport.js.map +7 -0
  279. package/dist/modules/ecommerce/lib/storefrontCategories.js +241 -0
  280. package/dist/modules/ecommerce/lib/storefrontCategories.js.map +7 -0
  281. package/dist/modules/ecommerce/lib/storefrontCategoryCache.js +71 -0
  282. package/dist/modules/ecommerce/lib/storefrontCategoryCache.js.map +7 -0
  283. package/dist/modules/ecommerce/lib/storefrontDetail.js +447 -0
  284. package/dist/modules/ecommerce/lib/storefrontDetail.js.map +7 -0
  285. package/dist/modules/ecommerce/lib/storefrontFacets.js +441 -0
  286. package/dist/modules/ecommerce/lib/storefrontFacets.js.map +7 -0
  287. package/dist/modules/ecommerce/lib/storefrontOptionFilter.js +15 -0
  288. package/dist/modules/ecommerce/lib/storefrontOptionFilter.js.map +7 -0
  289. package/dist/modules/ecommerce/lib/storefrontPricing.js +393 -0
  290. package/dist/modules/ecommerce/lib/storefrontPricing.js.map +7 -0
  291. package/dist/modules/ecommerce/lib/storefrontProductCache.js +90 -0
  292. package/dist/modules/ecommerce/lib/storefrontProductCache.js.map +7 -0
  293. package/dist/modules/ecommerce/lib/storefrontProductScope.js +107 -0
  294. package/dist/modules/ecommerce/lib/storefrontProductScope.js.map +7 -0
  295. package/dist/modules/ecommerce/lib/storefrontProducts.js +670 -0
  296. package/dist/modules/ecommerce/lib/storefrontProducts.js.map +7 -0
  297. package/dist/modules/ecommerce/lib/storefrontQuery.js +156 -0
  298. package/dist/modules/ecommerce/lib/storefrontQuery.js.map +7 -0
  299. package/dist/modules/ecommerce/lib/storefrontRateLimit.js +99 -0
  300. package/dist/modules/ecommerce/lib/storefrontRateLimit.js.map +7 -0
  301. package/dist/modules/ecommerce/lib/storefrontSearch.js +303 -0
  302. package/dist/modules/ecommerce/lib/storefrontSearch.js.map +7 -0
  303. package/dist/modules/ecommerce/lib/storefrontSearchCache.js +35 -0
  304. package/dist/modules/ecommerce/lib/storefrontSearchCache.js.map +7 -0
  305. package/dist/modules/ecommerce/lib/subscriberSupport.js +33 -0
  306. package/dist/modules/ecommerce/lib/subscriberSupport.js.map +7 -0
  307. package/dist/modules/ecommerce/lib/types.js +1 -0
  308. package/dist/modules/ecommerce/lib/types.js.map +7 -0
  309. package/dist/modules/ecommerce/migrations/Migration20261005113233_ecommerce.js +32 -0
  310. package/dist/modules/ecommerce/migrations/Migration20261005113233_ecommerce.js.map +7 -0
  311. package/dist/modules/ecommerce/migrations/Migration20261006112733_ecommerce.js +17 -0
  312. package/dist/modules/ecommerce/migrations/Migration20261006112733_ecommerce.js.map +7 -0
  313. package/dist/modules/ecommerce/notifications.client.js +47 -0
  314. package/dist/modules/ecommerce/notifications.client.js.map +7 -0
  315. package/dist/modules/ecommerce/notifications.js +48 -0
  316. package/dist/modules/ecommerce/notifications.js.map +7 -0
  317. package/dist/modules/ecommerce/search.js +83 -0
  318. package/dist/modules/ecommerce/search.js.map +7 -0
  319. package/dist/modules/ecommerce/setup.js +17 -0
  320. package/dist/modules/ecommerce/setup.js.map +7 -0
  321. package/dist/modules/ecommerce/subscribers/assortment-empty-notifications.js +14 -0
  322. package/dist/modules/ecommerce/subscribers/assortment-empty-notifications.js.map +7 -0
  323. package/dist/modules/ecommerce/subscribers/availability-policy-cache-invalidation.js +14 -0
  324. package/dist/modules/ecommerce/subscribers/availability-policy-cache-invalidation.js.map +7 -0
  325. package/dist/modules/ecommerce/subscribers/catalog-category-cache-invalidation.js +14 -0
  326. package/dist/modules/ecommerce/subscribers/catalog-category-cache-invalidation.js.map +7 -0
  327. package/dist/modules/ecommerce/subscribers/catalog-price-cache-invalidation.js +14 -0
  328. package/dist/modules/ecommerce/subscribers/catalog-price-cache-invalidation.js.map +7 -0
  329. package/dist/modules/ecommerce/subscribers/catalog-product-cache-invalidation.js +14 -0
  330. package/dist/modules/ecommerce/subscribers/catalog-product-cache-invalidation.js.map +7 -0
  331. package/dist/modules/ecommerce/subscribers/catalog-variant-cache-invalidation.js +14 -0
  332. package/dist/modules/ecommerce/subscribers/catalog-variant-cache-invalidation.js.map +7 -0
  333. package/dist/modules/ecommerce/subscribers/customer-group-cache-invalidation.js +14 -0
  334. package/dist/modules/ecommerce/subscribers/customer-group-cache-invalidation.js.map +7 -0
  335. package/dist/modules/ecommerce/subscribers/customer-group-membership-cache-invalidation.js +14 -0
  336. package/dist/modules/ecommerce/subscribers/customer-group-membership-cache-invalidation.js.map +7 -0
  337. package/dist/modules/ecommerce/subscribers/customer-group-terms-cache-invalidation.js +14 -0
  338. package/dist/modules/ecommerce/subscribers/customer-group-terms-cache-invalidation.js.map +7 -0
  339. package/dist/modules/ecommerce/subscribers/customer-user-deleted-cache-invalidation.js +14 -0
  340. package/dist/modules/ecommerce/subscribers/customer-user-deleted-cache-invalidation.js.map +7 -0
  341. package/dist/modules/ecommerce/subscribers/customer-user-updated-cache-invalidation.js +14 -0
  342. package/dist/modules/ecommerce/subscribers/customer-user-updated-cache-invalidation.js.map +7 -0
  343. package/dist/modules/ecommerce/subscribers/domain-binding-rebind.js +16 -0
  344. package/dist/modules/ecommerce/subscribers/domain-binding-rebind.js.map +7 -0
  345. package/dist/modules/ecommerce/subscribers/domain-mapping-cache-invalidation.js +14 -0
  346. package/dist/modules/ecommerce/subscribers/domain-mapping-cache-invalidation.js.map +7 -0
  347. package/dist/modules/ecommerce/subscribers/store-cache-invalidation.js +14 -0
  348. package/dist/modules/ecommerce/subscribers/store-cache-invalidation.js.map +7 -0
  349. package/dist/modules/ecommerce/subscribers/store-channel-binding-cache-invalidation.js +14 -0
  350. package/dist/modules/ecommerce/subscribers/store-channel-binding-cache-invalidation.js.map +7 -0
  351. package/dist/modules/ecommerce/subscribers/store-domain-binding-cache-invalidation.js +14 -0
  352. package/dist/modules/ecommerce/subscribers/store-domain-binding-cache-invalidation.js.map +7 -0
  353. package/dist/modules/ecommerce/subscribers/store-notifications.js +14 -0
  354. package/dist/modules/ecommerce/subscribers/store-notifications.js.map +7 -0
  355. package/dist/modules/query_index/lib/batch.js +23 -9
  356. package/dist/modules/query_index/lib/batch.js.map +2 -2
  357. package/dist/modules/query_index/lib/doc-enrichers.js +212 -0
  358. package/dist/modules/query_index/lib/doc-enrichers.js.map +7 -0
  359. package/dist/modules/query_index/lib/document.js +2 -0
  360. package/dist/modules/query_index/lib/document.js.map +2 -2
  361. package/dist/modules/query_index/lib/engine.js +68 -1
  362. package/dist/modules/query_index/lib/engine.js.map +2 -2
  363. package/dist/modules/query_index/lib/indexer.js +7 -0
  364. package/dist/modules/query_index/lib/indexer.js.map +2 -2
  365. package/dist/modules/query_index/lib/search-tokens.js +2 -0
  366. package/dist/modules/query_index/lib/search-tokens.js.map +2 -2
  367. package/dist/modules/query_index/migrations/Migration20261005201500_query_index.js +17 -0
  368. package/dist/modules/query_index/migrations/Migration20261005201500_query_index.js.map +7 -0
  369. package/dist/modules/translations/components/TranslationManager.js +3 -3
  370. package/dist/modules/translations/components/TranslationManager.js.map +2 -2
  371. package/dist/modules/translations/data/validators.js +1 -1
  372. package/dist/modules/translations/data/validators.js.map +1 -1
  373. package/dist/modules/translations/lib/batch.js +21 -1
  374. package/dist/modules/translations/lib/batch.js.map +2 -2
  375. package/dist/modules/translations/lib/helpers.js +3 -0
  376. package/dist/modules/translations/lib/helpers.js.map +2 -2
  377. package/dist/modules/translations/lib/resolve-field-list.js +14 -2
  378. package/dist/modules/translations/lib/resolve-field-list.js.map +2 -2
  379. package/generated/entities/catalog_price_history_entry/index.ts +25 -0
  380. package/generated/entities/customer_group_terms/index.ts +1 -0
  381. package/generated/entities/ecommerce_store/index.ts +15 -0
  382. package/generated/entities/ecommerce_store_channel_binding/index.ts +13 -0
  383. package/generated/entities/ecommerce_store_domain_binding/index.ts +10 -0
  384. package/generated/entities.ids.generated.ts +8 -1
  385. package/generated/entity-fields-registry.ts +72 -0
  386. package/package.json +7 -7
  387. package/src/helpers/integration/customerGroupsFixtures.ts +2 -0
  388. package/src/modules/auth/i18n/de.json +8 -0
  389. package/src/modules/auth/i18n/en.json +8 -0
  390. package/src/modules/auth/i18n/es.json +8 -0
  391. package/src/modules/auth/i18n/ko.json +8 -0
  392. package/src/modules/auth/i18n/pl.json +8 -0
  393. package/src/modules/catalog/AGENTS.md +5 -2
  394. package/src/modules/catalog/acl.ts +7 -0
  395. package/src/modules/catalog/api/config/omnibus/route.ts +204 -0
  396. package/src/modules/catalog/api/prices/history/route.ts +139 -0
  397. package/src/modules/catalog/api/prices/omnibus-preview/route.ts +202 -0
  398. package/src/modules/catalog/api/products/route.ts +53 -308
  399. package/src/modules/catalog/api/tags/route.ts +6 -0
  400. package/src/modules/catalog/backend/config/catalog/page.tsx +2 -0
  401. package/src/modules/catalog/cli.ts +84 -1
  402. package/src/modules/catalog/commands/categories.ts +54 -2
  403. package/src/modules/catalog/commands/prices.ts +43 -1
  404. package/src/modules/catalog/commands/products.ts +84 -1
  405. package/src/modules/catalog/commands/variants.ts +7 -0
  406. package/src/modules/catalog/components/OmnibusSettings.tsx +832 -0
  407. package/src/modules/catalog/components/PriceEditorOmnibusRow.tsx +219 -0
  408. package/src/modules/catalog/components/lookupSources.ts +29 -0
  409. package/src/modules/catalog/components/prices/PriceScopeSelectors.tsx +9 -0
  410. package/src/modules/catalog/components/products/VariantBuilder.tsx +9 -0
  411. package/src/modules/catalog/data/entities.ts +123 -1
  412. package/src/modules/catalog/data/validators.ts +118 -0
  413. package/src/modules/catalog/di.ts +23 -0
  414. package/src/modules/catalog/i18n/de.json +77 -0
  415. package/src/modules/catalog/i18n/en.json +77 -0
  416. package/src/modules/catalog/i18n/es.json +77 -0
  417. package/src/modules/catalog/i18n/ko.json +77 -0
  418. package/src/modules/catalog/i18n/pl.json +77 -0
  419. package/src/modules/catalog/lib/omnibus.ts +406 -0
  420. package/src/modules/catalog/lib/omnibusBackfill.ts +198 -0
  421. package/src/modules/catalog/lib/omnibusCache.ts +111 -0
  422. package/src/modules/catalog/lib/omnibusConfig.ts +73 -0
  423. package/src/modules/catalog/lib/omnibusHistoryQueries.ts +248 -0
  424. package/src/modules/catalog/lib/omnibusPresentedEntry.ts +76 -0
  425. package/src/modules/catalog/lib/omnibusProductListEnrichment.ts +125 -0
  426. package/src/modules/catalog/lib/omnibusTypes.ts +202 -0
  427. package/src/modules/catalog/lib/optionSchemaTranslations.ts +55 -0
  428. package/src/modules/catalog/lib/priceHistoryQuery.ts +155 -0
  429. package/src/modules/catalog/lib/pricing.ts +42 -4
  430. package/src/modules/catalog/lib/productFilters.ts +349 -0
  431. package/src/modules/catalog/lib/productScopeKeys.ts +162 -0
  432. package/src/modules/catalog/lib/productScopeReindex.ts +139 -0
  433. package/src/modules/catalog/migrations/.snapshot-open-mercato.json +572 -0
  434. package/src/modules/catalog/migrations/Migration20261005105352_catalog.ts +39 -0
  435. package/src/modules/catalog/migrations/Migration20261005150824_catalog.ts +39 -0
  436. package/src/modules/catalog/services/catalogOmnibusService.ts +642 -0
  437. package/src/modules/catalog/setup.ts +2 -0
  438. package/src/modules/catalog/subscribers/product-scope-keys-category-deleted.ts +18 -0
  439. package/src/modules/catalog/subscribers/product-scope-keys-category-updated.ts +19 -0
  440. package/src/modules/catalog/translations.ts +12 -0
  441. package/src/modules/configs/i18n/de.json +5 -1
  442. package/src/modules/configs/i18n/en.json +5 -1
  443. package/src/modules/configs/i18n/es.json +5 -1
  444. package/src/modules/configs/i18n/ko.json +5 -1
  445. package/src/modules/configs/i18n/pl.json +5 -1
  446. package/src/modules/configs/lib/upgrade-actions.ts +35 -0
  447. package/src/modules/customer_groups/api/customer-groups/[id]/terms/route.ts +7 -0
  448. package/src/modules/customer_groups/components/CustomerGroupTermsSection.tsx +124 -2
  449. package/src/modules/customer_groups/components/customerGroupAssortmentScope.ts +46 -0
  450. package/src/modules/customer_groups/data/entities.ts +4 -0
  451. package/src/modules/customer_groups/data/validators.ts +14 -0
  452. package/src/modules/customer_groups/i18n/de.json +12 -0
  453. package/src/modules/customer_groups/i18n/en.json +12 -0
  454. package/src/modules/customer_groups/i18n/es.json +12 -0
  455. package/src/modules/customer_groups/i18n/ko.json +12 -0
  456. package/src/modules/customer_groups/i18n/pl.json +12 -0
  457. package/src/modules/customer_groups/migrations/.snapshot-open-mercato.json +17 -0
  458. package/src/modules/customer_groups/migrations/Migration20261005110250_customer_groups.ts +15 -0
  459. package/src/modules/customer_groups/services/customerGroupsService.ts +74 -23
  460. package/src/modules/ecommerce/acl.ts +9 -0
  461. package/src/modules/ecommerce/api/domain-mappings/route.ts +76 -0
  462. package/src/modules/ecommerce/api/openapi.ts +28 -0
  463. package/src/modules/ecommerce/api/store-channel-bindings/[id]/assortment-count/route.ts +141 -0
  464. package/src/modules/ecommerce/api/store-channel-bindings/crud.ts +283 -0
  465. package/src/modules/ecommerce/api/store-channel-bindings/route.ts +67 -0
  466. package/src/modules/ecommerce/api/store-domain-bindings/crud.ts +324 -0
  467. package/src/modules/ecommerce/api/store-domain-bindings/route.ts +73 -0
  468. package/src/modules/ecommerce/api/storefront/categories/[slug]/route.ts +94 -0
  469. package/src/modules/ecommerce/api/storefront/categories/openapiSchemas.ts +63 -0
  470. package/src/modules/ecommerce/api/storefront/categories/route.ts +78 -0
  471. package/src/modules/ecommerce/api/storefront/context/route.ts +203 -0
  472. package/src/modules/ecommerce/api/storefront/products/[idOrHandle]/route.ts +94 -0
  473. package/src/modules/ecommerce/api/storefront/products/openapiSchemas.ts +193 -0
  474. package/src/modules/ecommerce/api/storefront/products/route.ts +81 -0
  475. package/src/modules/ecommerce/api/storefront/search/suggest/openapiSchemas.ts +25 -0
  476. package/src/modules/ecommerce/api/storefront/search/suggest/route.ts +78 -0
  477. package/src/modules/ecommerce/api/storefront/storefrontRouteSupport.ts +68 -0
  478. package/src/modules/ecommerce/api/stores/[id]/branding/route.ts +205 -0
  479. package/src/modules/ecommerce/api/stores/[id]/preview-branding/route.ts +99 -0
  480. package/src/modules/ecommerce/api/stores/crud.ts +457 -0
  481. package/src/modules/ecommerce/api/stores/route.ts +66 -0
  482. package/src/modules/ecommerce/backend/config/ecommerce/[id]/page.meta.ts +12 -0
  483. package/src/modules/ecommerce/backend/config/ecommerce/[id]/page.tsx +5 -0
  484. package/src/modules/ecommerce/backend/config/ecommerce/page.meta.ts +12 -0
  485. package/src/modules/ecommerce/backend/config/ecommerce/page.tsx +5 -0
  486. package/src/modules/ecommerce/commands/stores.ts +154 -0
  487. package/src/modules/ecommerce/components/ChannelAssortmentCount.tsx +138 -0
  488. package/src/modules/ecommerce/components/ChannelBindingFormSections.tsx +40 -0
  489. package/src/modules/ecommerce/components/ChannelLookupPicker.tsx +5 -0
  490. package/src/modules/ecommerce/components/DomainStatusWarning.tsx +32 -0
  491. package/src/modules/ecommerce/components/StoreAvailabilityDefaultsSection.tsx +219 -0
  492. package/src/modules/ecommerce/components/StoreBrandingControls.tsx +73 -0
  493. package/src/modules/ecommerce/components/StoreBrandingPreview.tsx +77 -0
  494. package/src/modules/ecommerce/components/StoreBrandingTab.tsx +242 -0
  495. package/src/modules/ecommerce/components/StoreChannelBindingDialog.tsx +306 -0
  496. package/src/modules/ecommerce/components/StoreChannelsTab.tsx +375 -0
  497. package/src/modules/ecommerce/components/StoreCreateDialog.tsx +204 -0
  498. package/src/modules/ecommerce/components/StoreDomainBindingDialog.tsx +198 -0
  499. package/src/modules/ecommerce/components/StoreDomainsTab.tsx +426 -0
  500. package/src/modules/ecommerce/components/StoreEditPage.tsx +193 -0
  501. package/src/modules/ecommerce/components/StoreGeneralTab.tsx +189 -0
  502. package/src/modules/ecommerce/components/StoreListPage.tsx +326 -0
  503. package/src/modules/ecommerce/components/StoreSeoTab.tsx +152 -0
  504. package/src/modules/ecommerce/components/StoreStatusBadge.tsx +22 -0
  505. package/src/modules/ecommerce/components/channelLookups.ts +24 -0
  506. package/src/modules/ecommerce/components/storeAdmin.ts +56 -0
  507. package/src/modules/ecommerce/components/storeBrandingForm.ts +230 -0
  508. package/src/modules/ecommerce/components/storeChannels.ts +210 -0
  509. package/src/modules/ecommerce/components/storeDomains.ts +221 -0
  510. package/src/modules/ecommerce/components/storeEditTabs.tsx +76 -0
  511. package/src/modules/ecommerce/components/storeGeneral.ts +155 -0
  512. package/src/modules/ecommerce/components/storeSeo.ts +78 -0
  513. package/src/modules/ecommerce/components/useChannelAssortmentCount.ts +67 -0
  514. package/src/modules/ecommerce/components/useStoreAccess.ts +36 -0
  515. package/src/modules/ecommerce/data/enrichers.ts +213 -0
  516. package/src/modules/ecommerce/data/entities.ts +168 -0
  517. package/src/modules/ecommerce/data/validators.ts +587 -0
  518. package/src/modules/ecommerce/di.ts +9 -0
  519. package/src/modules/ecommerce/events.ts +27 -0
  520. package/src/modules/ecommerce/i18n/de.json +341 -0
  521. package/src/modules/ecommerce/i18n/en.json +341 -0
  522. package/src/modules/ecommerce/i18n/es.json +341 -0
  523. package/src/modules/ecommerce/i18n/ko.json +341 -0
  524. package/src/modules/ecommerce/i18n/pl.json +341 -0
  525. package/src/modules/ecommerce/index.ts +14 -0
  526. package/src/modules/ecommerce/lib/assortmentCount.ts +175 -0
  527. package/src/modules/ecommerce/lib/brandingStyles.ts +215 -0
  528. package/src/modules/ecommerce/lib/buyerContext.ts +401 -0
  529. package/src/modules/ecommerce/lib/cacheInvalidation.ts +302 -0
  530. package/src/modules/ecommerce/lib/cacheKeys.ts +340 -0
  531. package/src/modules/ecommerce/lib/createConflictRecheck.ts +31 -0
  532. package/src/modules/ecommerce/lib/crudEvents.ts +128 -0
  533. package/src/modules/ecommerce/lib/crudSupport.ts +85 -0
  534. package/src/modules/ecommerce/lib/domainBindingRebind.ts +138 -0
  535. package/src/modules/ecommerce/lib/domainMappingSummaries.ts +71 -0
  536. package/src/modules/ecommerce/lib/exclusiveFlag.ts +90 -0
  537. package/src/modules/ecommerce/lib/references.ts +93 -0
  538. package/src/modules/ecommerce/lib/seedDraftStore.ts +125 -0
  539. package/src/modules/ecommerce/lib/storeBindingCascade.ts +138 -0
  540. package/src/modules/ecommerce/lib/storeBranding.ts +48 -0
  541. package/src/modules/ecommerce/lib/storeBrandingRoute.ts +91 -0
  542. package/src/modules/ecommerce/lib/storeContext.ts +669 -0
  543. package/src/modules/ecommerce/lib/storeContextService.ts +71 -0
  544. package/src/modules/ecommerce/lib/storeLocale.ts +88 -0
  545. package/src/modules/ecommerce/lib/storeNotifications.ts +55 -0
  546. package/src/modules/ecommerce/lib/storefrontCatalogSupport.ts +427 -0
  547. package/src/modules/ecommerce/lib/storefrontCategories.ts +419 -0
  548. package/src/modules/ecommerce/lib/storefrontCategoryCache.ts +113 -0
  549. package/src/modules/ecommerce/lib/storefrontDetail.ts +654 -0
  550. package/src/modules/ecommerce/lib/storefrontFacets.ts +697 -0
  551. package/src/modules/ecommerce/lib/storefrontOptionFilter.ts +44 -0
  552. package/src/modules/ecommerce/lib/storefrontPricing.ts +583 -0
  553. package/src/modules/ecommerce/lib/storefrontProductCache.ts +126 -0
  554. package/src/modules/ecommerce/lib/storefrontProductScope.ts +181 -0
  555. package/src/modules/ecommerce/lib/storefrontProducts.ts +963 -0
  556. package/src/modules/ecommerce/lib/storefrontQuery.ts +215 -0
  557. package/src/modules/ecommerce/lib/storefrontRateLimit.ts +126 -0
  558. package/src/modules/ecommerce/lib/storefrontSearch.ts +454 -0
  559. package/src/modules/ecommerce/lib/storefrontSearchCache.ts +49 -0
  560. package/src/modules/ecommerce/lib/subscriberSupport.ts +41 -0
  561. package/src/modules/ecommerce/lib/types.ts +69 -0
  562. package/src/modules/ecommerce/migrations/.snapshot-open-mercato.json +829 -0
  563. package/src/modules/ecommerce/migrations/Migration20261005113233_ecommerce.ts +32 -0
  564. package/src/modules/ecommerce/migrations/Migration20261006112733_ecommerce.ts +15 -0
  565. package/src/modules/ecommerce/notifications.client.ts +46 -0
  566. package/src/modules/ecommerce/notifications.ts +46 -0
  567. package/src/modules/ecommerce/search.ts +93 -0
  568. package/src/modules/ecommerce/setup.ts +15 -0
  569. package/src/modules/ecommerce/subscribers/assortment-empty-notifications.ts +12 -0
  570. package/src/modules/ecommerce/subscribers/availability-policy-cache-invalidation.ts +12 -0
  571. package/src/modules/ecommerce/subscribers/catalog-category-cache-invalidation.ts +12 -0
  572. package/src/modules/ecommerce/subscribers/catalog-price-cache-invalidation.ts +12 -0
  573. package/src/modules/ecommerce/subscribers/catalog-product-cache-invalidation.ts +12 -0
  574. package/src/modules/ecommerce/subscribers/catalog-variant-cache-invalidation.ts +12 -0
  575. package/src/modules/ecommerce/subscribers/customer-group-cache-invalidation.ts +12 -0
  576. package/src/modules/ecommerce/subscribers/customer-group-membership-cache-invalidation.ts +12 -0
  577. package/src/modules/ecommerce/subscribers/customer-group-terms-cache-invalidation.ts +12 -0
  578. package/src/modules/ecommerce/subscribers/customer-user-deleted-cache-invalidation.ts +12 -0
  579. package/src/modules/ecommerce/subscribers/customer-user-updated-cache-invalidation.ts +12 -0
  580. package/src/modules/ecommerce/subscribers/domain-binding-rebind.ts +14 -0
  581. package/src/modules/ecommerce/subscribers/domain-mapping-cache-invalidation.ts +12 -0
  582. package/src/modules/ecommerce/subscribers/store-cache-invalidation.ts +12 -0
  583. package/src/modules/ecommerce/subscribers/store-channel-binding-cache-invalidation.ts +12 -0
  584. package/src/modules/ecommerce/subscribers/store-domain-binding-cache-invalidation.ts +12 -0
  585. package/src/modules/ecommerce/subscribers/store-notifications.ts +12 -0
  586. package/src/modules/query_index/lib/batch.ts +25 -9
  587. package/src/modules/query_index/lib/doc-enrichers.ts +306 -0
  588. package/src/modules/query_index/lib/document.ts +2 -0
  589. package/src/modules/query_index/lib/engine.ts +58 -1
  590. package/src/modules/query_index/lib/indexer.ts +8 -0
  591. package/src/modules/query_index/lib/search-tokens.ts +2 -0
  592. package/src/modules/query_index/migrations/Migration20261005201500_query_index.ts +42 -0
  593. package/src/modules/translations/components/TranslationManager.tsx +3 -3
  594. package/src/modules/translations/data/validators.ts +1 -1
  595. package/src/modules/translations/lib/batch.ts +47 -0
  596. package/src/modules/translations/lib/helpers.ts +4 -0
  597. package/src/modules/translations/lib/resolve-field-list.ts +16 -2
@@ -0,0 +1,349 @@
1
+ import { z } from "zod";
2
+ import type { EntityManager } from "@mikro-orm/postgresql";
3
+ import { raw } from "@mikro-orm/postgresql";
4
+ import { buildCustomFieldFiltersFromQuery } from "@open-mercato/shared/lib/crud/custom-fields";
5
+ import type { CrudCtx } from "@open-mercato/shared/lib/crud/factory";
6
+ import { buildScopedWhere } from "@open-mercato/shared/lib/api/crud";
7
+ import { parseBooleanFlag } from "@open-mercato/shared/lib/boolean";
8
+ import { sanitizeSearchTerm } from "@open-mercato/shared/lib/query/sanitizeSearchTerm";
9
+ import { findWithDecryption } from "@open-mercato/shared/lib/encryption/find";
10
+ import { warnOnEncryptedLikeFilter } from "@open-mercato/shared/lib/encryption/likeFilterWarning";
11
+ import { buildAccentInsensitiveContainsPatternSql } from "@open-mercato/shared/lib/db/accentInsensitiveSearch";
12
+ import { createLogger } from "@open-mercato/shared/lib/logger";
13
+ import { fieldsetCodeRegex } from "@open-mercato/core/modules/entities/data/validators";
14
+ import { E } from "#generated/entities.ids.generated";
15
+ import {
16
+ CatalogOffer,
17
+ CatalogProduct,
18
+ CatalogProductCategory,
19
+ CatalogProductCategoryAssignment,
20
+ CatalogProductTagAssignment,
21
+ } from "../data/entities";
22
+ import { CATALOG_PRODUCT_TYPES } from "../data/types";
23
+ import { PRODUCT_SEARCH_COLUMNS, PRODUCT_SEARCH_EXPRESSION_SQL } from "./productSearch";
24
+
25
+ const logger = createLogger('catalog')
26
+
27
+ const UUID_REGEX =
28
+ /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/;
29
+
30
+ export const catalogProductFilterQuerySchema = z
31
+ .object({
32
+ page: z.coerce.number().min(1).default(1),
33
+ pageSize: z.coerce.number().min(1).max(100).default(50),
34
+ id: z.string().uuid().optional(),
35
+ search: z.string().optional(),
36
+ status: z.string().optional(),
37
+ isActive: z.string().optional(),
38
+ configurable: z.string().optional(),
39
+ productType: z.enum(CATALOG_PRODUCT_TYPES).optional(),
40
+ channelIds: z.string().optional(),
41
+ channelId: z.string().uuid().optional(),
42
+ categoryIds: z.string().optional(),
43
+ tagIds: z.string().optional(),
44
+ offerId: z.string().uuid().optional(),
45
+ userId: z.string().uuid().optional(),
46
+ userGroupId: z.string().uuid().optional(),
47
+ customerId: z.string().uuid().optional(),
48
+ customerGroupId: z.string().uuid().optional(),
49
+ quantity: z.coerce.number().min(1).max(100000).optional(),
50
+ quantityUnit: z.string().trim().max(50).optional(),
51
+ priceDate: z.string().optional(),
52
+ sortField: z.string().optional(),
53
+ sortDir: z.enum(["asc", "desc"]).optional(),
54
+ withDeleted: z.coerce.boolean().optional(),
55
+ customFieldset: z.string().regex(fieldsetCodeRegex).optional(),
56
+ })
57
+ .passthrough();
58
+
59
+ export type CatalogProductFilterQuery = z.infer<typeof catalogProductFilterQuerySchema>;
60
+
61
+ export type BuildProductFiltersOptions = {
62
+ includeCategoryDescendants?: boolean;
63
+ };
64
+
65
+ export function parseIdList(raw?: string): string[] {
66
+ if (!raw) return [];
67
+ return raw
68
+ .split(",")
69
+ .map((value) => value.trim())
70
+ .filter((value) => UUID_REGEX.test(value));
71
+ }
72
+
73
+ export async function buildProductFilters(
74
+ query: CatalogProductFilterQuery,
75
+ ctx: CrudCtx,
76
+ options: BuildProductFiltersOptions = {},
77
+ ): Promise<Record<string, unknown>> {
78
+ const filters: Record<string, unknown> = {};
79
+ const em = (ctx.container.resolve("em") as EntityManager).fork();
80
+ const restrictedProductIds: { value: Set<string> | null } = { value: null };
81
+
82
+ const intersectProductIds = (ids: string[]) => {
83
+ const normalized = ids.filter(
84
+ (id): id is string => typeof id === "string" && id.trim().length > 0,
85
+ );
86
+ const current = new Set(normalized);
87
+ if (!current.size) {
88
+ restrictedProductIds.value = new Set();
89
+ return;
90
+ }
91
+ if (!restrictedProductIds.value) {
92
+ restrictedProductIds.value = current;
93
+ return;
94
+ }
95
+ restrictedProductIds.value = new Set(
96
+ Array.from(restrictedProductIds.value).filter((id) => current.has(id)),
97
+ );
98
+ };
99
+
100
+ const applyRestrictedProducts = () => {
101
+ if (!restrictedProductIds.value) return;
102
+ if (restrictedProductIds.value.size === 0) {
103
+ filters.id = { $eq: "00000000-0000-0000-0000-000000000000" };
104
+ return;
105
+ }
106
+ const ids = Array.from(restrictedProductIds.value);
107
+ const existing = filters.id as Record<string, unknown> | undefined;
108
+ if (existing && typeof existing === "object") {
109
+ if (
110
+ "$eq" in existing &&
111
+ typeof (existing as { $eq?: unknown }).$eq === "string"
112
+ ) {
113
+ const target = (existing as { $eq: string }).$eq;
114
+ if (!restrictedProductIds.value.has(target)) {
115
+ filters.id = { $eq: "00000000-0000-0000-0000-000000000000" };
116
+ }
117
+ return;
118
+ }
119
+ if (
120
+ "$in" in existing &&
121
+ Array.isArray((existing as { $in?: unknown }).$in)
122
+ ) {
123
+ const subset = (existing as { $in: string[] }).$in.filter((id) =>
124
+ restrictedProductIds.value!.has(id),
125
+ );
126
+ filters.id = subset.length
127
+ ? { $in: subset }
128
+ : { $eq: "00000000-0000-0000-0000-000000000000" };
129
+ return;
130
+ }
131
+ }
132
+ filters.id = ids.length === 1 ? { $eq: ids[0] } : { $in: ids };
133
+ };
134
+ if (query.id) {
135
+ filters.id = { $eq: query.id };
136
+ }
137
+ if (query.status && query.status.trim()) {
138
+ filters.status_entry_id = { $eq: query.status.trim() };
139
+ }
140
+ const active = parseBooleanFlag(query.isActive);
141
+ if (active !== undefined) {
142
+ filters.is_active = active;
143
+ }
144
+ const configurable = parseBooleanFlag(query.configurable);
145
+ if (configurable !== undefined) {
146
+ filters.is_configurable = configurable;
147
+ }
148
+ if (query.productType) {
149
+ filters.product_type = { $eq: query.productType };
150
+ }
151
+ const scope = {
152
+ organizationId: ctx.selectedOrganizationId ?? ctx.auth?.orgId ?? null,
153
+ tenantId: ctx.auth?.tenantId ?? null,
154
+ };
155
+ const scopeWhere = buildScopedWhere(
156
+ {},
157
+ {
158
+ organizationId: scope.organizationId,
159
+ organizationIds: ctx.organizationIds ?? undefined,
160
+ tenantId: scope.tenantId,
161
+ orgField: ctx.organizationIds === null ? null : undefined,
162
+ softDeleteField: null,
163
+ },
164
+ );
165
+ const term = sanitizeSearchTerm(query.search);
166
+ const channelFilterIds = parseIdList(query.channelIds);
167
+ const categoryFilterIds = parseIdList(query.categoryIds);
168
+ const tagFilterIds = parseIdList(query.tagIds);
169
+ const customFieldset =
170
+ typeof query.customFieldset === "string" &&
171
+ query.customFieldset.trim().length
172
+ ? query.customFieldset.trim()
173
+ : null;
174
+ const tenantId = ctx.auth?.tenantId ?? null;
175
+
176
+ // These prequeries are independent — each only feeds the final product-id
177
+ // intersection, none depends on another's result — so dispatch them together
178
+ // instead of awaiting one after another (#3179). A task returns null when its
179
+ // filter is inactive (intersection skipped) or the matched product-id list
180
+ // (possibly empty) when active, preserving the "active filter with no matches
181
+ // => empty result" behavior.
182
+ const searchTask = async (): Promise<string[] | null> => {
183
+ if (!term) return null;
184
+ // The predicate hides behind a raw() symbol key, which the filter walker in
185
+ // findWithDecryption cannot see (Object.entries skips symbols), so the
186
+ // encrypted-ILIKE diagnostic is raised here with the field list instead.
187
+ // Without it, a tenant that encrypts one of these columns at rest gets an
188
+ // empty result indistinguishable from a genuine no-match (#5051). It runs
189
+ // alongside the query rather than before it: it is a development-only
190
+ // diagnostic and must not add a round trip to the request path.
191
+ const [searchMatches] = await Promise.all([
192
+ findWithDecryption(
193
+ em,
194
+ CatalogProduct,
195
+ {
196
+ ...scopeWhere,
197
+ ...(query.withDeleted ? {} : { deletedAt: null }),
198
+ [raw(PRODUCT_SEARCH_EXPRESSION_SQL)]: {
199
+ $ilike: raw(buildAccentInsensitiveContainsPatternSql(), [term]),
200
+ },
201
+ },
202
+ { fields: ["id"] },
203
+ scope,
204
+ ),
205
+ warnOnEncryptedLikeFilter({
206
+ em,
207
+ entityName: CatalogProduct,
208
+ likeFields: [...PRODUCT_SEARCH_COLUMNS],
209
+ tenantId: scope.tenantId,
210
+ }),
211
+ ]);
212
+ return searchMatches
213
+ .map((product) => product.id)
214
+ .filter((id): id is string => typeof id === "string" && id.length > 0);
215
+ };
216
+
217
+ const channelTask = async (): Promise<string[] | null> => {
218
+ if (!channelFilterIds.length) return null;
219
+ const offerRows = await findWithDecryption(
220
+ em,
221
+ CatalogOffer,
222
+ {
223
+ channelId: { $in: channelFilterIds },
224
+ deletedAt: null,
225
+ ...scopeWhere,
226
+ },
227
+ { fields: ["id", "product"] },
228
+ scope,
229
+ );
230
+ return offerRows
231
+ .map((offer) =>
232
+ typeof offer.product === "string"
233
+ ? offer.product
234
+ : (offer.product?.id ?? null),
235
+ )
236
+ .filter((id): id is string => !!id);
237
+ };
238
+
239
+ const expandCategoryIds = async (): Promise<string[]> => {
240
+ if (!options.includeCategoryDescendants) return categoryFilterIds;
241
+ const categories = await findWithDecryption(
242
+ em,
243
+ CatalogProductCategory,
244
+ { id: { $in: categoryFilterIds }, deletedAt: null, ...scopeWhere },
245
+ { fields: ["id", "descendantIds"] },
246
+ scope,
247
+ );
248
+ const expanded = new Set(categoryFilterIds);
249
+ for (const category of categories) {
250
+ const descendants = Array.isArray(category.descendantIds) ? category.descendantIds : [];
251
+ for (const descendantId of descendants) {
252
+ if (typeof descendantId === "string" && descendantId.length > 0) {
253
+ expanded.add(descendantId);
254
+ }
255
+ }
256
+ }
257
+ return Array.from(expanded);
258
+ };
259
+
260
+ const categoryTask = async (): Promise<string[] | null> => {
261
+ if (!categoryFilterIds.length) return null;
262
+ const categoryIds = await expandCategoryIds();
263
+ const assignments = await findWithDecryption(
264
+ em,
265
+ CatalogProductCategoryAssignment,
266
+ { category: { $in: categoryIds }, ...scopeWhere },
267
+ { fields: ["id", "product"] },
268
+ scope,
269
+ );
270
+ return assignments
271
+ .map((assignment) =>
272
+ typeof assignment.product === "string"
273
+ ? assignment.product
274
+ : (assignment.product?.id ?? null),
275
+ )
276
+ .filter((id): id is string => !!id);
277
+ };
278
+
279
+ const tagTask = async (): Promise<string[] | null> => {
280
+ if (!tagFilterIds.length) return null;
281
+ const assignments = await findWithDecryption(
282
+ em,
283
+ CatalogProductTagAssignment,
284
+ { tag: { $in: tagFilterIds }, ...scopeWhere },
285
+ { fields: ["id", "product"] },
286
+ scope,
287
+ );
288
+ return assignments
289
+ .map((assignment) =>
290
+ typeof assignment.product === "string"
291
+ ? assignment.product
292
+ : (assignment.product?.id ?? null),
293
+ )
294
+ .filter((id): id is string => !!id);
295
+ };
296
+
297
+ const customFieldTask = async (): Promise<Record<string, unknown>> => {
298
+ try {
299
+ const scopedEm = ctx.container.resolve("em") as EntityManager;
300
+ return await buildCustomFieldFiltersFromQuery({
301
+ entityIds: [E.catalog.catalog_product],
302
+ query,
303
+ em: scopedEm,
304
+ tenantId,
305
+ fieldset: customFieldset ?? undefined,
306
+ });
307
+ } catch (err) {
308
+ // Custom field filter parsing may fail for non-existent or misconfigured fields.
309
+ // Fall back to base filters to avoid blocking the product listing.
310
+ logger.debug('catalog.products custom field filter error', { err });
311
+ return {};
312
+ }
313
+ };
314
+
315
+ const [searchIds, channelIds, categoryIds, tagIds, cfFilters] =
316
+ await Promise.all([
317
+ searchTask(),
318
+ channelTask(),
319
+ categoryTask(),
320
+ tagTask(),
321
+ customFieldTask(),
322
+ ]);
323
+
324
+ // Apply intersections in the original order; intersection is commutative, so
325
+ // the result is identical to the previous sequential pass. An empty array is
326
+ // still intersected (active filter that matched nothing); null is skipped.
327
+ for (const productIds of [searchIds, channelIds, categoryIds, tagIds]) {
328
+ if (productIds) intersectProductIds(productIds);
329
+ }
330
+ Object.assign(filters, cfFilters);
331
+ applyRestrictedProducts();
332
+ return filters;
333
+ }
334
+
335
+ export function scoreProductSearchRelevance(
336
+ needle: string,
337
+ title: string | null | undefined,
338
+ sku: string | null | undefined,
339
+ ): number {
340
+ const t = (title ?? "").toLowerCase();
341
+ const s = (sku ?? "").toLowerCase();
342
+ if (t === needle) return 0;
343
+ if (s === needle) return 1;
344
+ if (t.startsWith(needle)) return 2;
345
+ if (s.startsWith(needle)) return 3;
346
+ if (t.includes(needle)) return 4;
347
+ if (s.includes(needle)) return 5;
348
+ return 6;
349
+ }
@@ -0,0 +1,162 @@
1
+ import { sql, type Kysely, type RawBuilder } from 'kysely'
2
+ import type {
3
+ IndexDocEnricher,
4
+ IndexDocEnricherContext,
5
+ IndexDocEnricherRecord,
6
+ IndexDocEnrichment,
7
+ } from '@open-mercato/core/modules/query_index/lib/doc-enrichers'
8
+
9
+ /**
10
+ * Denormalized assortment keys on the `catalog:catalog_product` index document
11
+ * (Storefront Public API §3.3, decision D9).
12
+ *
13
+ * `scope_keys` is a sorted, de-duplicated jsonb string array:
14
+ * - `cat:<uuid>` for every assigned, non-deleted category AND each of its `ancestor_ids`
15
+ * (so "a category includes its descendants" is a plain overlap test);
16
+ * - `tag:<uuid>` for every assigned tag.
17
+ *
18
+ * Ids only — never encrypted, never translated. A document whose `scope_keys` is `null`
19
+ * (enricher failure) or absent (not reindexed since the enricher shipped) is NOT indexed:
20
+ * consumers MUST fail closed on it, never read it as "no assignments" — see
21
+ * `isProductScopeIndexed`.
22
+ */
23
+ export const PRODUCT_SCOPE_KEYS_ENTITY_TYPE = 'catalog:catalog_product'
24
+ export const PRODUCT_SCOPE_KEYS_DOC_KEY = 'scope_keys'
25
+ export const PRODUCT_SCOPE_KEYS_ENRICHER_ID = 'catalog.product_scope_keys'
26
+ export const PRODUCT_SCOPE_CATEGORY_PREFIX = 'cat:'
27
+ export const PRODUCT_SCOPE_TAG_PREFIX = 'tag:'
28
+
29
+ export function compareCodeUnits(left: string, right: string): number {
30
+ if (left < right) return -1
31
+ if (left > right) return 1
32
+ return 0
33
+ }
34
+
35
+ export function categoryScopeKey(categoryId: string): string {
36
+ return `${PRODUCT_SCOPE_CATEGORY_PREFIX}${categoryId}`
37
+ }
38
+
39
+ export function tagScopeKey(tagId: string): string {
40
+ return `${PRODUCT_SCOPE_TAG_PREFIX}${tagId}`
41
+ }
42
+
43
+ export type ProductScopeKeyInput = {
44
+ categories: ReadonlyArray<{ categoryId: string; ancestorIds: readonly string[] }>
45
+ tagIds: readonly string[]
46
+ }
47
+
48
+ export function buildProductScopeKeys(input: ProductScopeKeyInput): string[] {
49
+ const keys = new Set<string>()
50
+ for (const category of input.categories) {
51
+ if (category.categoryId) keys.add(categoryScopeKey(category.categoryId))
52
+ for (const ancestorId of category.ancestorIds) {
53
+ if (ancestorId) keys.add(categoryScopeKey(ancestorId))
54
+ }
55
+ }
56
+ for (const tagId of input.tagIds) {
57
+ if (tagId) keys.add(tagScopeKey(tagId))
58
+ }
59
+ return Array.from(keys).sort(compareCodeUnits)
60
+ }
61
+
62
+ export function isProductScopeIndexed(doc: Readonly<Record<string, unknown>> | null | undefined): boolean {
63
+ if (!doc) return false
64
+ const keys = doc[PRODUCT_SCOPE_KEYS_DOC_KEY]
65
+ if (!Array.isArray(keys)) return false
66
+ return keys.every((entry) => typeof entry === 'string')
67
+ }
68
+
69
+ export function readJsonIdList(value: unknown): string[] {
70
+ let parsed: unknown = value
71
+ if (typeof value === 'string') {
72
+ try {
73
+ parsed = JSON.parse(value)
74
+ } catch {
75
+ return []
76
+ }
77
+ }
78
+ if (!Array.isArray(parsed)) return []
79
+ return parsed.filter((entry): entry is string => typeof entry === 'string' && entry.length > 0)
80
+ }
81
+
82
+ type ScopeFilter = { tenantId: string | null; organizationId: string | null }
83
+
84
+ function scopeEquals(column: string, value: string | null): RawBuilder<boolean> {
85
+ return value === null
86
+ ? sql<boolean>`${sql.ref(column)} is null`
87
+ : sql<boolean>`${sql.ref(column)} = ${value}`
88
+ }
89
+
90
+ type CategoryAssignmentRow = { product_id: string; category_id: string; ancestor_ids: unknown }
91
+ type TagAssignmentRow = { product_id: string; tag_id: string }
92
+
93
+ /**
94
+ * Computes `scope_keys` for a batch of products in two queries (category assignments joined
95
+ * with their categories, then tag assignments). Every requested product gets an entry — a
96
+ * product without assignments maps to `[]`, which is "indexed, no keys", not "unknown".
97
+ */
98
+ export async function computeProductScopeKeys(
99
+ db: Kysely<any>,
100
+ productIds: readonly string[],
101
+ scope: ScopeFilter,
102
+ ): Promise<Map<string, string[]>> {
103
+ const ids = Array.from(new Set(productIds.filter((id) => typeof id === 'string' && id.length > 0)))
104
+ const result = new Map<string, string[]>()
105
+ if (!ids.length) return result
106
+
107
+ const categoryRows = (await db
108
+ .selectFrom('catalog_product_category_assignments as a')
109
+ .innerJoin('catalog_product_categories as c', 'c.id', 'a.category_id')
110
+ .select(['a.product_id as product_id', 'a.category_id as category_id', 'c.ancestor_ids as ancestor_ids'])
111
+ .where('a.product_id', 'in', ids)
112
+ .where('c.deleted_at', 'is', null)
113
+ .where(scopeEquals('a.tenant_id', scope.tenantId))
114
+ .where(scopeEquals('a.organization_id', scope.organizationId))
115
+ .where(scopeEquals('c.tenant_id', scope.tenantId))
116
+ .where(scopeEquals('c.organization_id', scope.organizationId))
117
+ .execute()) as CategoryAssignmentRow[]
118
+
119
+ const tagRows = (await db
120
+ .selectFrom('catalog_product_tag_assignments as t')
121
+ .select(['t.product_id as product_id', 't.tag_id as tag_id'])
122
+ .where('t.product_id', 'in', ids)
123
+ .where(scopeEquals('t.tenant_id', scope.tenantId))
124
+ .where(scopeEquals('t.organization_id', scope.organizationId))
125
+ .execute()) as TagAssignmentRow[]
126
+
127
+ const inputs = new Map<string, { categories: Array<{ categoryId: string; ancestorIds: string[] }>; tagIds: string[] }>()
128
+ for (const id of ids) inputs.set(id, { categories: [], tagIds: [] })
129
+ for (const row of categoryRows) {
130
+ const entry = inputs.get(String(row.product_id))
131
+ if (!entry) continue
132
+ entry.categories.push({ categoryId: String(row.category_id), ancestorIds: readJsonIdList(row.ancestor_ids) })
133
+ }
134
+ for (const row of tagRows) {
135
+ const entry = inputs.get(String(row.product_id))
136
+ if (!entry) continue
137
+ entry.tagIds.push(String(row.tag_id))
138
+ }
139
+ for (const [id, input] of inputs) result.set(id, buildProductScopeKeys(input))
140
+ return result
141
+ }
142
+
143
+ export const catalogProductScopeKeysEnricher: IndexDocEnricher = {
144
+ id: PRODUCT_SCOPE_KEYS_ENRICHER_ID,
145
+ entityType: PRODUCT_SCOPE_KEYS_ENTITY_TYPE,
146
+ keys: [PRODUCT_SCOPE_KEYS_DOC_KEY],
147
+ async enrich(
148
+ records: readonly IndexDocEnricherRecord[],
149
+ ctx: IndexDocEnricherContext,
150
+ ): Promise<Map<string, IndexDocEnrichment>> {
151
+ const keysByProduct = await computeProductScopeKeys(
152
+ ctx.db,
153
+ records.map((record) => record.recordId),
154
+ { tenantId: ctx.tenantId, organizationId: ctx.organizationId },
155
+ )
156
+ const out = new Map<string, IndexDocEnrichment>()
157
+ for (const [productId, keys] of keysByProduct) {
158
+ out.set(productId, { [PRODUCT_SCOPE_KEYS_DOC_KEY]: keys })
159
+ }
160
+ return out
161
+ },
162
+ }
@@ -0,0 +1,139 @@
1
+ import type { EntityManager } from '@mikro-orm/postgresql'
2
+ import { sql, type Kysely } from 'kysely'
3
+ import { createLogger } from '@open-mercato/shared/lib/logger'
4
+ import { PRODUCT_SCOPE_KEYS_ENTITY_TYPE, readJsonIdList } from './productScopeKeys'
5
+
6
+ const logger = createLogger('catalog').child({ component: 'product-scope-reindex' })
7
+
8
+ /**
9
+ * Above this many affected products a category hierarchy change requests one scoped
10
+ * `query_index.reindex` job for `catalog:catalog_product` instead of per-record upserts.
11
+ */
12
+ export const PRODUCT_SCOPE_REINDEX_UPSERT_LIMIT = 500
13
+
14
+ export type CategoryScopeChangePayload = {
15
+ id?: unknown
16
+ tenantId?: unknown
17
+ organizationId?: unknown
18
+ hierarchyChanged?: unknown
19
+ previousDescendantIds?: unknown
20
+ }
21
+
22
+ export type ProductScopeReindexContext = {
23
+ resolve: <T = unknown>(name: string) => T
24
+ }
25
+
26
+ type EventBusLike = {
27
+ emitEvent: (event: string, payload: unknown, options?: Record<string, unknown>) => Promise<void>
28
+ }
29
+
30
+ type CategoryScopeTarget = {
31
+ categoryId: string
32
+ tenantId: string
33
+ organizationId: string
34
+ extraCategoryIds: string[]
35
+ }
36
+
37
+ export type ProductScopeReindexResult =
38
+ | { mode: 'skipped'; productCount: 0 }
39
+ | { mode: 'upsert'; productCount: number }
40
+ | { mode: 'reindex'; productCount: number }
41
+
42
+ function readNonEmptyString(value: unknown): string | null {
43
+ return typeof value === 'string' && value.length > 0 ? value : null
44
+ }
45
+
46
+ export function parseCategoryScopeTarget(payload: CategoryScopeChangePayload | null | undefined): CategoryScopeTarget | null {
47
+ const categoryId = readNonEmptyString(payload?.id)
48
+ const tenantId = readNonEmptyString(payload?.tenantId)
49
+ const organizationId = readNonEmptyString(payload?.organizationId)
50
+ if (!categoryId || !tenantId || !organizationId) return null
51
+ return {
52
+ categoryId,
53
+ tenantId,
54
+ organizationId,
55
+ extraCategoryIds: readJsonIdList(payload?.previousDescendantIds),
56
+ }
57
+ }
58
+
59
+ export async function collectCategorySubtreeProductIds(
60
+ db: Kysely<any>,
61
+ target: CategoryScopeTarget,
62
+ limit: number,
63
+ ): Promise<string[]> {
64
+ const category = (await db
65
+ .selectFrom('catalog_product_categories')
66
+ .select(['id', 'descendant_ids'])
67
+ .where('id', '=', target.categoryId)
68
+ .where('tenant_id', '=', target.tenantId)
69
+ .where('organization_id', '=', target.organizationId)
70
+ .executeTakeFirst()) as { id: string; descendant_ids: unknown } | undefined
71
+
72
+ const categoryIds = Array.from(new Set([
73
+ target.categoryId,
74
+ ...readJsonIdList(category?.descendant_ids),
75
+ ...target.extraCategoryIds,
76
+ ]))
77
+
78
+ const rows = (await db
79
+ .selectFrom('catalog_product_category_assignments as a')
80
+ .innerJoin('catalog_products as p', 'p.id', 'a.product_id')
81
+ .select('a.product_id as product_id')
82
+ .distinct()
83
+ .where('a.category_id', 'in', categoryIds)
84
+ .where('a.tenant_id', '=', target.tenantId)
85
+ .where('a.organization_id', '=', target.organizationId)
86
+ .where(sql<boolean>`${sql.ref('p.deleted_at')} is null`)
87
+ .limit(limit + 1)
88
+ .execute()) as Array<{ product_id: string }>
89
+
90
+ return rows.map((row) => String(row.product_id))
91
+ }
92
+
93
+ /**
94
+ * Re-projects `scope_keys` for every product assigned anywhere in a category's subtree
95
+ * (Storefront Public API §3.3, R16). Runs from persistent `catalog.category.*` subscribers,
96
+ * i.e. in the events worker, never in the request that changed the hierarchy.
97
+ */
98
+ export async function reindexProductsForCategorySubtree(
99
+ payload: CategoryScopeChangePayload | null | undefined,
100
+ ctx: ProductScopeReindexContext,
101
+ limit: number = PRODUCT_SCOPE_REINDEX_UPSERT_LIMIT,
102
+ ): Promise<ProductScopeReindexResult> {
103
+ const target = parseCategoryScopeTarget(payload)
104
+ if (!target) {
105
+ logger.warn('Category scope change without id/tenant/organization; product scope keys not refreshed', {
106
+ categoryId: readNonEmptyString(payload?.id),
107
+ })
108
+ return { mode: 'skipped', productCount: 0 }
109
+ }
110
+ const em = ctx.resolve<EntityManager>('em')
111
+ const db = em.getKysely() as Kysely<any>
112
+ const bus = ctx.resolve<EventBusLike>('eventBus')
113
+ const productIds = await collectCategorySubtreeProductIds(db, target, limit)
114
+ if (!productIds.length) return { mode: 'skipped', productCount: 0 }
115
+
116
+ if (productIds.length > limit) {
117
+ await bus.emitEvent(
118
+ 'query_index.reindex',
119
+ {
120
+ entityType: PRODUCT_SCOPE_KEYS_ENTITY_TYPE,
121
+ tenantId: target.tenantId,
122
+ organizationId: target.organizationId,
123
+ },
124
+ { persistent: true, deliverInline: false },
125
+ )
126
+ return { mode: 'reindex', productCount: productIds.length }
127
+ }
128
+
129
+ for (const productId of productIds) {
130
+ await bus.emitEvent('query_index.upsert_one', {
131
+ entityType: PRODUCT_SCOPE_KEYS_ENTITY_TYPE,
132
+ recordId: productId,
133
+ tenantId: target.tenantId,
134
+ organizationId: target.organizationId,
135
+ crudAction: 'updated',
136
+ })
137
+ }
138
+ return { mode: 'upsert', productCount: productIds.length }
139
+ }