@endora-commerce/mod-catalog 0.107.0 → 0.109.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/components/AttachmentScopesDialog.d.ts +22 -0
- package/dist/admin/components/AttachmentScopesDialog.d.ts.map +1 -0
- package/dist/admin/components/AttachmentScopesDialog.js +70 -0
- package/dist/admin/components/AttachmentScopesDialog.js.map +1 -0
- package/dist/admin/components/PackagingUnitsEditor.d.ts +10 -1
- package/dist/admin/components/PackagingUnitsEditor.d.ts.map +1 -1
- package/dist/admin/components/PackagingUnitsEditor.js +127 -10
- package/dist/admin/components/PackagingUnitsEditor.js.map +1 -1
- package/dist/admin/components/ProductAttachmentsSection.d.ts +5 -0
- package/dist/admin/components/ProductAttachmentsSection.d.ts.map +1 -0
- package/dist/admin/components/ProductAttachmentsSection.js +137 -0
- package/dist/admin/components/ProductAttachmentsSection.js.map +1 -0
- package/dist/admin/components/ProductGallerySection.d.ts +14 -0
- package/dist/admin/components/ProductGallerySection.d.ts.map +1 -0
- package/dist/admin/components/ProductGallerySection.js +385 -0
- package/dist/admin/components/ProductGallerySection.js.map +1 -0
- package/dist/admin/components/ProductOrderRulesCard.d.ts +19 -0
- package/dist/admin/components/ProductOrderRulesCard.d.ts.map +1 -0
- package/dist/admin/components/ProductOrderRulesCard.js +275 -0
- package/dist/admin/components/ProductOrderRulesCard.js.map +1 -0
- package/dist/admin/components/ProductScopeControls.d.ts +31 -0
- package/dist/admin/components/ProductScopeControls.d.ts.map +1 -0
- package/dist/admin/components/ProductScopeControls.js +243 -0
- package/dist/admin/components/ProductScopeControls.js.map +1 -0
- package/dist/admin/components/ProductScopeEditor.d.ts +12 -18
- package/dist/admin/components/ProductScopeEditor.d.ts.map +1 -1
- package/dist/admin/components/ProductScopeEditor.js +5 -4
- package/dist/admin/components/ProductScopeEditor.js.map +1 -1
- package/dist/admin/components/ProductScopeOverview.d.ts +26 -0
- package/dist/admin/components/ProductScopeOverview.d.ts.map +1 -0
- package/dist/admin/components/ProductScopeOverview.js +207 -0
- package/dist/admin/components/ProductScopeOverview.js.map +1 -0
- package/dist/admin/components/ProductStatusPills.d.ts +17 -0
- package/dist/admin/components/ProductStatusPills.d.ts.map +1 -0
- package/dist/admin/components/ProductStatusPills.js +23 -0
- package/dist/admin/components/ProductStatusPills.js.map +1 -0
- package/dist/admin/components/ProductUrlKeysPanel.d.ts +17 -0
- package/dist/admin/components/ProductUrlKeysPanel.d.ts.map +1 -0
- package/dist/admin/components/ProductUrlKeysPanel.js +215 -0
- package/dist/admin/components/ProductUrlKeysPanel.js.map +1 -0
- package/dist/admin/components/ProductsBulkEditDialog.d.ts +30 -0
- package/dist/admin/components/ProductsBulkEditDialog.d.ts.map +1 -1
- package/dist/admin/components/ProductsBulkEditDialog.js +308 -125
- package/dist/admin/components/ProductsBulkEditDialog.js.map +1 -1
- package/dist/admin/components/ScopedDialogParts.d.ts +23 -0
- package/dist/admin/components/ScopedDialogParts.d.ts.map +1 -0
- package/dist/admin/components/ScopedDialogParts.js +16 -0
- package/dist/admin/components/ScopedDialogParts.js.map +1 -0
- package/dist/admin/index.d.ts +2 -2
- package/dist/admin/index.d.ts.map +1 -1
- package/dist/admin/index.js +9 -0
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/lib/attribute-scope.d.ts +20 -0
- package/dist/admin/lib/attribute-scope.d.ts.map +1 -0
- package/dist/admin/lib/attribute-scope.js +18 -0
- package/dist/admin/lib/attribute-scope.js.map +1 -0
- package/dist/admin/lib/bulk-operation-log-text.d.ts +9 -0
- package/dist/admin/lib/bulk-operation-log-text.d.ts.map +1 -0
- package/dist/admin/lib/bulk-operation-log-text.js +13 -0
- package/dist/admin/lib/bulk-operation-log-text.js.map +1 -0
- package/dist/admin/lib/media-scopes.d.ts +41 -0
- package/dist/admin/lib/media-scopes.d.ts.map +1 -0
- package/dist/admin/lib/media-scopes.js +66 -0
- package/dist/admin/lib/media-scopes.js.map +1 -0
- package/dist/admin/lib/product-labels.d.ts +14 -0
- package/dist/admin/lib/product-labels.d.ts.map +1 -0
- package/dist/admin/lib/product-labels.js +27 -0
- package/dist/admin/lib/product-labels.js.map +1 -0
- package/dist/admin/lib/product-scope-drafts.d.ts +77 -0
- package/dist/admin/lib/product-scope-drafts.d.ts.map +1 -0
- package/dist/admin/lib/product-scope-drafts.js +133 -0
- package/dist/admin/lib/product-scope-drafts.js.map +1 -0
- package/dist/admin/lib/product-scopes-api.d.ts +40 -0
- package/dist/admin/lib/product-scopes-api.d.ts.map +1 -0
- package/dist/admin/lib/product-scopes-api.js +101 -0
- package/dist/admin/lib/product-scopes-api.js.map +1 -0
- package/dist/admin/lib/product-url-keys-api.d.ts +46 -0
- package/dist/admin/lib/product-url-keys-api.d.ts.map +1 -0
- package/dist/admin/lib/product-url-keys-api.js +110 -0
- package/dist/admin/lib/product-url-keys-api.js.map +1 -0
- package/dist/admin/lib/resolve-product-selection.d.ts +29 -1
- package/dist/admin/lib/resolve-product-selection.d.ts.map +1 -1
- package/dist/admin/lib/resolve-product-selection.js +42 -6
- package/dist/admin/lib/resolve-product-selection.js.map +1 -1
- package/dist/admin/lib/scope-overview.d.ts +74 -0
- package/dist/admin/lib/scope-overview.d.ts.map +1 -0
- package/dist/admin/lib/scope-overview.js +173 -0
- package/dist/admin/lib/scope-overview.js.map +1 -0
- package/dist/admin/pages/AttributesManager.d.ts.map +1 -1
- package/dist/admin/pages/AttributesManager.js +84 -7
- package/dist/admin/pages/AttributesManager.js.map +1 -1
- package/dist/admin/pages/BulkOperationDetailPage.d.ts.map +1 -1
- package/dist/admin/pages/BulkOperationDetailPage.js +4 -19
- package/dist/admin/pages/BulkOperationDetailPage.js.map +1 -1
- package/dist/admin/pages/ProductEditor.d.ts +0 -4
- package/dist/admin/pages/ProductEditor.d.ts.map +1 -1
- package/dist/admin/pages/ProductEditor.js +221 -374
- package/dist/admin/pages/ProductEditor.js.map +1 -1
- package/dist/admin/pages/ProductsList.d.ts +12 -0
- package/dist/admin/pages/ProductsList.d.ts.map +1 -1
- package/dist/admin/pages/ProductsList.js +105 -38
- package/dist/admin/pages/ProductsList.js.map +1 -1
- package/dist/backend/admin-search-provider.d.ts +1 -1
- package/dist/backend/admin-search-provider.d.ts.map +1 -1
- package/dist/backend/admin-search-provider.js +1 -2
- package/dist/backend/admin-search-provider.js.map +1 -1
- package/dist/backend/demo/reset.d.ts +1 -1
- package/dist/backend/demo/rows.d.ts +14 -3
- package/dist/backend/demo/rows.d.ts.map +1 -1
- package/dist/backend/demo/rows.js +24 -17
- package/dist/backend/demo/rows.js.map +1 -1
- package/dist/backend/demo/seed.d.ts.map +1 -1
- package/dist/backend/demo/seed.js +3 -6
- package/dist/backend/demo/seed.js.map +1 -1
- package/dist/backend/entities/bulk-operation.entity.d.ts +10 -0
- package/dist/backend/entities/bulk-operation.entity.d.ts.map +1 -1
- package/dist/backend/entities/bulk-operation.entity.js.map +1 -1
- package/dist/backend/entities/gallery-item-channel-hidden.entity.d.ts +14 -0
- package/dist/backend/entities/gallery-item-channel-hidden.entity.d.ts.map +1 -0
- package/dist/backend/entities/gallery-item-channel-hidden.entity.js +42 -0
- package/dist/backend/entities/gallery-item-channel-hidden.entity.js.map +1 -0
- package/dist/backend/entities/gallery-item-channel-label.entity.d.ts +18 -0
- package/dist/backend/entities/gallery-item-channel-label.entity.d.ts.map +1 -0
- package/dist/backend/entities/gallery-item-channel-label.entity.js +49 -0
- package/dist/backend/entities/gallery-item-channel-label.entity.js.map +1 -0
- package/dist/backend/entities/gallery-item.entity.d.ts +8 -1
- package/dist/backend/entities/gallery-item.entity.d.ts.map +1 -1
- package/dist/backend/entities/gallery-item.entity.js +11 -0
- package/dist/backend/entities/gallery-item.entity.js.map +1 -1
- package/dist/backend/entities/product-attachment-channel-hidden.entity.d.ts +13 -0
- package/dist/backend/entities/product-attachment-channel-hidden.entity.d.ts.map +1 -0
- package/dist/backend/entities/product-attachment-channel-hidden.entity.js +41 -0
- package/dist/backend/entities/product-attachment-channel-hidden.entity.js.map +1 -0
- package/dist/backend/entities/product-attachment.entity.d.ts +8 -1
- package/dist/backend/entities/product-attachment.entity.d.ts.map +1 -1
- package/dist/backend/entities/product-attachment.entity.js +15 -0
- package/dist/backend/entities/product-attachment.entity.js.map +1 -1
- package/dist/backend/entities/product-channel-language-scope.entity.d.ts +23 -0
- package/dist/backend/entities/product-channel-language-scope.entity.d.ts.map +1 -0
- package/dist/backend/entities/product-channel-language-scope.entity.js +61 -0
- package/dist/backend/entities/product-channel-language-scope.entity.js.map +1 -0
- package/dist/backend/entities/product-channel-scope.entity.d.ts +42 -0
- package/dist/backend/entities/product-channel-scope.entity.d.ts.map +1 -0
- package/dist/backend/entities/product-channel-scope.entity.js +104 -0
- package/dist/backend/entities/product-channel-scope.entity.js.map +1 -0
- package/dist/backend/entities/product-packaging-unit.entity.d.ts +13 -1
- package/dist/backend/entities/product-packaging-unit.entity.d.ts.map +1 -1
- package/dist/backend/entities/product-packaging-unit.entity.js +20 -0
- package/dist/backend/entities/product-packaging-unit.entity.js.map +1 -1
- package/dist/backend/entities/product-url-key.entity.d.ts +32 -0
- package/dist/backend/entities/product-url-key.entity.d.ts.map +1 -0
- package/dist/backend/entities/product-url-key.entity.js +75 -0
- package/dist/backend/entities/product-url-key.entity.js.map +1 -0
- package/dist/backend/entities/product-url-redirect.entity.d.ts +23 -0
- package/dist/backend/entities/product-url-redirect.entity.d.ts.map +1 -0
- package/dist/backend/entities/product-url-redirect.entity.js +58 -0
- package/dist/backend/entities/product-url-redirect.entity.js.map +1 -0
- package/dist/backend/entities/product-variant.entity.d.ts +1 -2
- package/dist/backend/entities/product-variant.entity.d.ts.map +1 -1
- package/dist/backend/entities/product-variant.entity.js +0 -5
- package/dist/backend/entities/product-variant.entity.js.map +1 -1
- package/dist/backend/entities/product.entity.d.ts +41 -2
- package/dist/backend/entities/product.entity.d.ts.map +1 -1
- package/dist/backend/entities/product.entity.js +84 -1
- package/dist/backend/entities/product.entity.js.map +1 -1
- package/dist/backend/index.d.ts +27 -6
- package/dist/backend/index.d.ts.map +1 -1
- package/dist/backend/index.js +209 -15
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/plugin.d.ts +45 -4
- package/dist/backend/plugin.d.ts.map +1 -1
- package/dist/backend/plugin.js +67 -9
- package/dist/backend/plugin.js.map +1 -1
- package/dist/backend/prompt-tools.d.ts +10 -0
- package/dist/backend/prompt-tools.d.ts.map +1 -1
- package/dist/backend/prompt-tools.js +108 -4
- package/dist/backend/prompt-tools.js.map +1 -1
- package/dist/backend/routes.admin.d.ts +29 -0
- package/dist/backend/routes.admin.d.ts.map +1 -1
- package/dist/backend/routes.admin.js +161 -55
- package/dist/backend/routes.admin.js.map +1 -1
- package/dist/backend/routes.admin.url-keys.d.ts +23 -0
- package/dist/backend/routes.admin.url-keys.d.ts.map +1 -0
- package/dist/backend/routes.admin.url-keys.js +14 -0
- package/dist/backend/routes.admin.url-keys.js.map +1 -0
- package/dist/backend/routes.api-key.d.ts.map +1 -1
- package/dist/backend/routes.api-key.js +14 -1
- package/dist/backend/routes.api-key.js.map +1 -1
- package/dist/backend/routes.external.d.ts.map +1 -1
- package/dist/backend/routes.external.js +6 -1
- package/dist/backend/routes.external.js.map +1 -1
- package/dist/backend/routes.public.d.ts +24 -7
- package/dist/backend/routes.public.d.ts.map +1 -1
- package/dist/backend/routes.public.js +58 -29
- package/dist/backend/routes.public.js.map +1 -1
- package/dist/backend/routes.public.url-keys.d.ts +26 -0
- package/dist/backend/routes.public.url-keys.d.ts.map +1 -0
- package/dist/backend/routes.public.url-keys.js +17 -0
- package/dist/backend/routes.public.url-keys.js.map +1 -0
- package/dist/backend/services/asset-references.js +43 -30
- package/dist/backend/services/asset-references.js.map +1 -1
- package/dist/backend/services/attachment-packaging-scopes.d.ts +43 -0
- package/dist/backend/services/attachment-packaging-scopes.d.ts.map +1 -0
- package/dist/backend/services/attachment-packaging-scopes.js +115 -0
- package/dist/backend/services/attachment-packaging-scopes.js.map +1 -0
- package/dist/backend/services/attachment.service.d.ts +12 -1
- package/dist/backend/services/attachment.service.d.ts.map +1 -1
- package/dist/backend/services/attachment.service.js +119 -21
- package/dist/backend/services/attachment.service.js.map +1 -1
- package/dist/backend/services/attribute-scope-preview.d.ts +38 -0
- package/dist/backend/services/attribute-scope-preview.d.ts.map +1 -0
- package/dist/backend/services/attribute-scope-preview.js +66 -0
- package/dist/backend/services/attribute-scope-preview.js.map +1 -0
- package/dist/backend/services/bulk-operation.service.d.ts +36 -0
- package/dist/backend/services/bulk-operation.service.d.ts.map +1 -1
- package/dist/backend/services/bulk-operation.service.js +203 -36
- package/dist/backend/services/bulk-operation.service.js.map +1 -1
- package/dist/backend/services/bundle.service.d.ts +9 -1
- package/dist/backend/services/bundle.service.d.ts.map +1 -1
- package/dist/backend/services/bundle.service.js +12 -2
- package/dist/backend/services/bundle.service.js.map +1 -1
- package/dist/backend/services/catalog-admin-search.service.d.ts +1 -1
- package/dist/backend/services/catalog-admin-search.service.js +1 -1
- package/dist/backend/services/catalog-admin.service.d.ts +125 -18
- package/dist/backend/services/catalog-admin.service.d.ts.map +1 -1
- package/dist/backend/services/catalog-admin.service.js +367 -164
- package/dist/backend/services/catalog-admin.service.js.map +1 -1
- package/dist/backend/services/catalog-bulk-import.service.d.ts +24 -2
- package/dist/backend/services/catalog-bulk-import.service.d.ts.map +1 -1
- package/dist/backend/services/catalog-bulk-import.service.js +132 -6
- package/dist/backend/services/catalog-bulk-import.service.js.map +1 -1
- package/dist/backend/services/catalog-bulk-update.service.d.ts +32 -4
- package/dist/backend/services/catalog-bulk-update.service.d.ts.map +1 -1
- package/dist/backend/services/catalog-bulk-update.service.js +115 -12
- package/dist/backend/services/catalog-bulk-update.service.js.map +1 -1
- package/dist/backend/services/catalog-org-price-decorator.d.ts +18 -27
- package/dist/backend/services/catalog-org-price-decorator.d.ts.map +1 -1
- package/dist/backend/services/catalog-org-price-decorator.js +77 -33
- package/dist/backend/services/catalog-org-price-decorator.js.map +1 -1
- package/dist/backend/services/catalog-product-filter.service.d.ts +16 -2
- package/dist/backend/services/catalog-product-filter.service.d.ts.map +1 -1
- package/dist/backend/services/catalog-product-filter.service.js +80 -3
- package/dist/backend/services/catalog-product-filter.service.js.map +1 -1
- package/dist/backend/services/catalog-product-read.service.d.ts +45 -3
- package/dist/backend/services/catalog-product-read.service.d.ts.map +1 -1
- package/dist/backend/services/catalog-product-read.service.js +130 -3
- package/dist/backend/services/catalog-product-read.service.js.map +1 -1
- package/dist/backend/services/catalog-query.service.d.ts +145 -40
- package/dist/backend/services/catalog-query.service.d.ts.map +1 -1
- package/dist/backend/services/catalog-query.service.js +1048 -391
- package/dist/backend/services/catalog-query.service.js.map +1 -1
- package/dist/backend/services/catalog-quick-search.service.d.ts +18 -2
- package/dist/backend/services/catalog-quick-search.service.d.ts.map +1 -1
- package/dist/backend/services/catalog-quick-search.service.js +52 -20
- package/dist/backend/services/catalog-quick-search.service.js.map +1 -1
- package/dist/backend/services/catalog-write-ports.d.ts +18 -1
- package/dist/backend/services/catalog-write-ports.d.ts.map +1 -1
- package/dist/backend/services/catalog-write-ports.js +77 -0
- package/dist/backend/services/catalog-write-ports.js.map +1 -1
- package/dist/backend/services/category-admin.service.d.ts +12 -1
- package/dist/backend/services/category-admin.service.d.ts.map +1 -1
- package/dist/backend/services/category-admin.service.js +23 -2
- package/dist/backend/services/category-admin.service.js.map +1 -1
- package/dist/backend/services/channel-url-facts.d.ts +17 -0
- package/dist/backend/services/channel-url-facts.d.ts.map +1 -0
- package/dist/backend/services/channel-url-facts.js +20 -0
- package/dist/backend/services/channel-url-facts.js.map +1 -0
- package/dist/backend/services/effective-value.sql.d.ts +56 -0
- package/dist/backend/services/effective-value.sql.d.ts.map +1 -0
- package/dist/backend/services/effective-value.sql.js +111 -0
- package/dist/backend/services/effective-value.sql.js.map +1 -0
- package/dist/backend/services/gallery-scopes.d.ts +40 -0
- package/dist/backend/services/gallery-scopes.d.ts.map +1 -0
- package/dist/backend/services/gallery-scopes.js +151 -0
- package/dist/backend/services/gallery-scopes.js.map +1 -0
- package/dist/backend/services/gallery.service.d.ts +46 -4
- package/dist/backend/services/gallery.service.d.ts.map +1 -1
- package/dist/backend/services/gallery.service.js +308 -46
- package/dist/backend/services/gallery.service.js.map +1 -1
- package/dist/backend/services/linkable-asset.d.ts +21 -0
- package/dist/backend/services/linkable-asset.d.ts.map +1 -0
- package/dist/backend/services/linkable-asset.js +31 -0
- package/dist/backend/services/linkable-asset.js.map +1 -0
- package/dist/backend/services/packaging-unit.service.d.ts.map +1 -1
- package/dist/backend/services/packaging-unit.service.js +95 -29
- package/dist/backend/services/packaging-unit.service.js.map +1 -1
- package/dist/backend/services/primary-asset-url.d.ts +7 -1
- package/dist/backend/services/primary-asset-url.d.ts.map +1 -1
- package/dist/backend/services/primary-asset-url.js +45 -14
- package/dist/backend/services/primary-asset-url.js.map +1 -1
- package/dist/backend/services/product-availability.service.d.ts +79 -0
- package/dist/backend/services/product-availability.service.d.ts.map +1 -0
- package/dist/backend/services/product-availability.service.js +223 -0
- package/dist/backend/services/product-availability.service.js.map +1 -0
- package/dist/backend/services/product-availability.sql.d.ts +71 -0
- package/dist/backend/services/product-availability.sql.d.ts.map +1 -0
- package/dist/backend/services/product-availability.sql.js +77 -0
- package/dist/backend/services/product-availability.sql.js.map +1 -0
- package/dist/backend/services/product-link.service.d.ts +10 -9
- package/dist/backend/services/product-link.service.d.ts.map +1 -1
- package/dist/backend/services/product-link.service.js +48 -23
- package/dist/backend/services/product-link.service.js.map +1 -1
- package/dist/backend/services/product-overrides.service.d.ts +9 -2
- package/dist/backend/services/product-overrides.service.d.ts.map +1 -1
- package/dist/backend/services/product-overrides.service.js +13 -6
- package/dist/backend/services/product-overrides.service.js.map +1 -1
- package/dist/backend/services/product-page-revalidation.d.ts +51 -0
- package/dist/backend/services/product-page-revalidation.d.ts.map +1 -0
- package/dist/backend/services/product-page-revalidation.js +146 -0
- package/dist/backend/services/product-page-revalidation.js.map +1 -0
- package/dist/backend/services/product-scope-context.service.d.ts.map +1 -1
- package/dist/backend/services/product-scope-context.service.js +3 -2
- package/dist/backend/services/product-scope-context.service.js.map +1 -1
- package/dist/backend/services/product-scopes.service.d.ts +212 -0
- package/dist/backend/services/product-scopes.service.d.ts.map +1 -0
- package/dist/backend/services/product-scopes.service.js +638 -0
- package/dist/backend/services/product-scopes.service.js.map +1 -0
- package/dist/backend/services/product-summary-text.d.ts +8 -0
- package/dist/backend/services/product-summary-text.d.ts.map +1 -0
- package/dist/backend/services/product-summary-text.js +8 -0
- package/dist/backend/services/product-summary-text.js.map +1 -0
- package/dist/backend/services/product-value-resolver.service.d.ts +11 -1
- package/dist/backend/services/product-value-resolver.service.d.ts.map +1 -1
- package/dist/backend/services/product-value-resolver.service.js +29 -9
- package/dist/backend/services/product-value-resolver.service.js.map +1 -1
- package/dist/backend/services/publication-window-sweep.d.ts +77 -0
- package/dist/backend/services/publication-window-sweep.d.ts.map +1 -0
- package/dist/backend/services/publication-window-sweep.js +117 -0
- package/dist/backend/services/publication-window-sweep.js.map +1 -0
- package/dist/backend/services/scope-completeness.d.ts +107 -0
- package/dist/backend/services/scope-completeness.d.ts.map +1 -0
- package/dist/backend/services/scope-completeness.js +180 -0
- package/dist/backend/services/scope-completeness.js.map +1 -0
- package/dist/backend/services/scope-overview.service.d.ts +112 -0
- package/dist/backend/services/scope-overview.service.d.ts.map +1 -0
- package/dist/backend/services/scope-overview.service.js +372 -0
- package/dist/backend/services/scope-overview.service.js.map +1 -0
- package/dist/backend/services/sql-id-arrays.d.ts +16 -0
- package/dist/backend/services/sql-id-arrays.d.ts.map +1 -0
- package/dist/backend/services/sql-id-arrays.js +24 -0
- package/dist/backend/services/sql-id-arrays.js.map +1 -0
- package/dist/backend/services/storefront-value-overrides.d.ts +31 -0
- package/dist/backend/services/storefront-value-overrides.d.ts.map +1 -0
- package/dist/backend/services/storefront-value-overrides.js +48 -0
- package/dist/backend/services/storefront-value-overrides.js.map +1 -0
- package/dist/backend/services/url-key-resolution.service.d.ts +76 -0
- package/dist/backend/services/url-key-resolution.service.d.ts.map +1 -0
- package/dist/backend/services/url-key-resolution.service.js +179 -0
- package/dist/backend/services/url-key-resolution.service.js.map +1 -0
- package/dist/backend/services/url-key.service.d.ts +171 -0
- package/dist/backend/services/url-key.service.d.ts.map +1 -0
- package/dist/backend/services/url-key.service.js +738 -0
- package/dist/backend/services/url-key.service.js.map +1 -0
- package/dist/manifest.d.ts +3 -1
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +188 -13
- package/dist/manifest.js.map +1 -1
- package/dist/migrations/20261016T082008_catalog_order_rules.d.ts +22 -0
- package/dist/migrations/20261016T082008_catalog_order_rules.d.ts.map +1 -0
- package/dist/migrations/20261016T082008_catalog_order_rules.js +48 -0
- package/dist/migrations/20261016T082008_catalog_order_rules.js.map +1 -0
- package/dist/migrations/20261022T035133_catalog_product_scopes.d.ts +28 -0
- package/dist/migrations/20261022T035133_catalog_product_scopes.d.ts.map +1 -0
- package/dist/migrations/20261022T035133_catalog_product_scopes.js +92 -0
- package/dist/migrations/20261022T035133_catalog_product_scopes.js.map +1 -0
- package/dist/migrations/20261022T054223_catalog_product_url_keys.d.ts +32 -0
- package/dist/migrations/20261022T054223_catalog_product_url_keys.d.ts.map +1 -0
- package/dist/migrations/20261022T054223_catalog_product_url_keys.js +81 -0
- package/dist/migrations/20261022T054223_catalog_product_url_keys.js.map +1 -0
- package/dist/migrations/20261022T111811_catalog_price_fields_removed.d.ts +26 -0
- package/dist/migrations/20261022T111811_catalog_price_fields_removed.d.ts.map +1 -0
- package/dist/migrations/20261022T111811_catalog_price_fields_removed.js +32 -0
- package/dist/migrations/20261022T111811_catalog_price_fields_removed.js.map +1 -0
- package/dist/migrations/20261022T182523_catalog_admin_name_keys.d.ts +38 -0
- package/dist/migrations/20261022T182523_catalog_admin_name_keys.d.ts.map +1 -0
- package/dist/migrations/20261022T182523_catalog_admin_name_keys.js +89 -0
- package/dist/migrations/20261022T182523_catalog_admin_name_keys.js.map +1 -0
- package/dist/migrations/20261025T222634_catalog_product_status_drop_draft.d.ts +34 -0
- package/dist/migrations/20261025T222634_catalog_product_status_drop_draft.d.ts.map +1 -0
- package/dist/migrations/20261025T222634_catalog_product_status_drop_draft.js +57 -0
- package/dist/migrations/20261025T222634_catalog_product_status_drop_draft.js.map +1 -0
- package/dist/migrations/20261026T033453_catalog_product_media_scopes.d.ts +26 -0
- package/dist/migrations/20261026T033453_catalog_product_media_scopes.d.ts.map +1 -0
- package/dist/migrations/20261026T033453_catalog_product_media_scopes.js +54 -0
- package/dist/migrations/20261026T033453_catalog_product_media_scopes.js.map +1 -0
- package/dist/migrations/20261026T084533_catalog_attachment_packaging_translations.d.ts +27 -0
- package/dist/migrations/20261026T084533_catalog_attachment_packaging_translations.d.ts.map +1 -0
- package/dist/migrations/20261026T084533_catalog_attachment_packaging_translations.js +45 -0
- package/dist/migrations/20261026T084533_catalog_attachment_packaging_translations.js.map +1 -0
- package/dist/migrations/index.d.ts +9 -1
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +17 -1
- package/dist/migrations/index.js.map +1 -1
- package/docs/catalog/attachments.md +46 -4
- package/docs/catalog/attributes.md +11 -6
- package/docs/catalog/gallery-and-labels.md +63 -4
- package/docs/catalog/packaging-units.md +82 -8
- package/docs/catalog/per-channel-per-language-overrides.md +195 -10
- package/docs/catalog/url-keys-and-redirects.md +142 -0
- package/docs/catalog.md +326 -17
- package/i18n/en.json +931 -53
- package/i18n/pl.json +930 -52
- package/package.json +10 -10
|
@@ -12,12 +12,24 @@ 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';
|
|
16
|
-
import {
|
|
18
|
+
import { channelUrlFactsOf } from './channel-url-facts.js';
|
|
19
|
+
import { effectiveAttributeValues, effectiveSystemText, loadChannelOverridesByProduct, overrideLanguages, } from './storefront-value-overrides.js';
|
|
20
|
+
import { availabilityCondition, } from './product-availability.sql.js';
|
|
21
|
+
import { effectiveAttributeSql, effectiveTextSql, } from './effective-value.sql.js';
|
|
22
|
+
import { availableAmong, globalScopeFields, isAvailableWith, loadChannelScopeRows, toScopeChannel, } from './product-availability.service.js';
|
|
23
|
+
import { uuidArrayLiteral } from './sql-id-arrays.js';
|
|
24
|
+
import { findCurrentKeyHolder, loadEffectiveKeys } from './url-key-resolution.service.js';
|
|
25
|
+
import { ANONYMOUS_PRODUCT_AUDIENCE, ERROR_CODES, compareDecimal, productDefaultPath, productPath, decimalText, formatUnits, isOrderMinimumEligibleType, effectiveOrderRules, normaliseAmount, effectiveAudience, isPriceSort, isProductVisibleTo, listingPriceChannelContext, resolveScopeLanguage, listingPriceMoney, translationAt, effectivePackagingUnitName, } from '@endora-commerce/contracts';
|
|
17
26
|
import { HttpError } from '@endora-commerce/platform/http';
|
|
18
27
|
import { encodeCursor, decodeCursor } from '@endora-commerce/platform/http';
|
|
28
|
+
import { productSummaryText } from './product-summary-text.js';
|
|
29
|
+
/** A uuid as the database spells one — anything else is a 404 or a discarded cursor, not a query. */
|
|
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;
|
|
19
31
|
/** A category id as the database spells one — anything else is a 404, not a query. */
|
|
20
|
-
const CATEGORY_ID_RE =
|
|
32
|
+
const CATEGORY_ID_RE = UUID_RE;
|
|
21
33
|
/** The deepest ancestor chain {@link CatalogQueryService.getCategoryPageContent} walks. */
|
|
22
34
|
const MAX_CATEGORY_DEPTH = 64;
|
|
23
35
|
/**
|
|
@@ -51,6 +63,25 @@ function decodeObjectCursor(cursor) {
|
|
|
51
63
|
function isRecord(value) {
|
|
52
64
|
return typeof value === 'object' && value !== null;
|
|
53
65
|
}
|
|
66
|
+
function isUuidText(value) {
|
|
67
|
+
return typeof value === 'string' && UUID_RE.test(value);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A price a cursor carries, normalised to four places, or `null` when it is not
|
|
71
|
+
* one. Read with the contracts' own decimal parser — the grammar
|
|
72
|
+
* `compareDecimal` reads and the price order writes — rather than with a
|
|
73
|
+
* second pattern that can drift from it (review 3 of release 0.108.0, A4).
|
|
74
|
+
*/
|
|
75
|
+
function cursorAmount(value) {
|
|
76
|
+
if (typeof value !== 'string')
|
|
77
|
+
return null;
|
|
78
|
+
try {
|
|
79
|
+
return normaliseAmount(value);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
54
85
|
/**
|
|
55
86
|
* How many source rows a price-ordered or price-filtered page may read before it
|
|
56
87
|
* returns short — FR-019, stated as the specification requires and **not** as a
|
|
@@ -61,7 +92,9 @@ function isRecord(value) {
|
|
|
61
92
|
* an operator restricts most of a catalogue from most viewers, and the answer
|
|
62
93
|
* there is a short page — the two price paths narrow each chunk they fetch by
|
|
63
94
|
* channel and audience, where the default path has those in its statement
|
|
64
|
-
* (issue #151) — rather than an unbounded scan.
|
|
95
|
+
* (issue #151) — rather than an unbounded scan. A short page, even an empty
|
|
96
|
+
* one, has `hasMore: true` and a cursor at the position its scan reached, so
|
|
97
|
+
* the budget shortens pages and never ends a walk.
|
|
65
98
|
*
|
|
66
99
|
* A setting was rejected because nobody has the number yet: the value it should
|
|
67
100
|
* take is a function of how much of a catalogue a deployment hides, and shipping
|
|
@@ -70,6 +103,37 @@ function isRecord(value) {
|
|
|
70
103
|
* is additive.
|
|
71
104
|
*/
|
|
72
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';
|
|
115
|
+
function amountBound(value, side) {
|
|
116
|
+
const [whole = '0', fraction = ''] = decimalText(value).split('.');
|
|
117
|
+
let units = BigInt(whole) * 10000n + BigInt(fraction.slice(0, 4).padEnd(4, '0'));
|
|
118
|
+
if (side === 'min' && /[1-9]/.test(fraction.slice(4)))
|
|
119
|
+
units += 1n;
|
|
120
|
+
return formatUnits(units);
|
|
121
|
+
}
|
|
122
|
+
/** Whether a resolved amount lies in the range, compared as decimals; an amount that does not parse does not. */
|
|
123
|
+
function withinAmountRange(amount, range) {
|
|
124
|
+
if (range === undefined)
|
|
125
|
+
return true;
|
|
126
|
+
try {
|
|
127
|
+
if (range.min !== undefined && compareDecimal(amount, range.min) < 0)
|
|
128
|
+
return false;
|
|
129
|
+
if (range.max !== undefined && compareDecimal(amount, range.max) > 0)
|
|
130
|
+
return false;
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
73
137
|
/**
|
|
74
138
|
* The "everything strictly after this row" predicate, over whichever column the
|
|
75
139
|
* cursor names and in the direction that column is ordered in.
|
|
@@ -79,10 +143,8 @@ export const PRICE_PAGE_SCAN_BUDGET_MULTIPLE = 8;
|
|
|
79
143
|
* ordering came apart in the first place.
|
|
80
144
|
*/
|
|
81
145
|
function afterKeysetCursor(cursor, op) {
|
|
82
|
-
if ('
|
|
83
|
-
|
|
84
|
-
$or: [{ slug: { [op]: cursor.slug } }, { slug: cursor.slug, id: { [op]: cursor.id } }],
|
|
85
|
-
};
|
|
146
|
+
if (!('createdAt' in cursor)) {
|
|
147
|
+
throw new Error('afterKeysetCursor: a name cursor is the name keyset\'s own (`#keysetFor`).');
|
|
86
148
|
}
|
|
87
149
|
const at = new Date(cursor.createdAt);
|
|
88
150
|
return { $or: [{ createdAt: { [op]: at } }, { createdAt: at, id: { [op]: cursor.id } }] };
|
|
@@ -158,6 +220,8 @@ export class CatalogQueryService {
|
|
|
158
220
|
organizationDetails;
|
|
159
221
|
listingPriceOrder;
|
|
160
222
|
log;
|
|
223
|
+
cursorSeal;
|
|
224
|
+
seoProductMeta;
|
|
161
225
|
constructor(emFactory,
|
|
162
226
|
/**
|
|
163
227
|
* Feature 002 US4 — optional link provider so the PDP `productDetail`
|
|
@@ -257,7 +321,18 @@ export class CatalogQueryService {
|
|
|
257
321
|
* without changing anything else. Optional, because a fixture that never
|
|
258
322
|
* binds never reaches it.
|
|
259
323
|
*/
|
|
260
|
-
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) {
|
|
261
336
|
this.emFactory = emFactory;
|
|
262
337
|
this.productLinkService = productLinkService;
|
|
263
338
|
this.customFieldDefinitions = customFieldDefinitions;
|
|
@@ -268,6 +343,31 @@ export class CatalogQueryService {
|
|
|
268
343
|
this.organizationDetails = organizationDetails;
|
|
269
344
|
this.listingPriceOrder = listingPriceOrder;
|
|
270
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
|
+
}
|
|
271
371
|
}
|
|
272
372
|
#requireChannelMembership() {
|
|
273
373
|
if (!this.channelMembership) {
|
|
@@ -276,6 +376,53 @@ export class CatalogQueryService {
|
|
|
276
376
|
}
|
|
277
377
|
return this.channelMembership;
|
|
278
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
|
+
}
|
|
279
426
|
#requireAssets() {
|
|
280
427
|
if (!this.assets) {
|
|
281
428
|
throw new Error('CatalogQueryService: the asset read port is not wired — product images are unavailable.');
|
|
@@ -312,9 +459,11 @@ export class CatalogQueryService {
|
|
|
312
459
|
* The chain's answer for a batch of products, keyed by product id, **for the
|
|
313
460
|
* viewer in front of the page**.
|
|
314
461
|
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
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`.
|
|
318
467
|
*
|
|
319
468
|
* The organisation is the whole of this method's share of the owner's ruling
|
|
320
469
|
* — an anonymous visitor sees the channel price, a signed-in buyer sees their
|
|
@@ -323,14 +472,17 @@ export class CatalogQueryService {
|
|
|
323
472
|
* for, so the anonymous request issues exactly the resolution it issued
|
|
324
473
|
* before and lands on exactly the cache entry it landed on before.
|
|
325
474
|
*/
|
|
326
|
-
async #listingPricesFor(products, ctx
|
|
475
|
+
async #listingPricesFor(products, ctx,
|
|
476
|
+
/** The viewer's pricing context, when the caller has built it already for this request. */
|
|
477
|
+
context) {
|
|
327
478
|
if (products.length === 0)
|
|
328
479
|
return new Map();
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
480
|
+
// D-287 P0 — the details call: one resolution answers both `price` and
|
|
481
|
+
// `resolvedPrice` (base / sale / display mode), so the product page and the
|
|
482
|
+
// home page's cards need no second, per-product resolution.
|
|
483
|
+
return this.#requireListingPrices().resolveListingPriceDetails({
|
|
332
484
|
products,
|
|
333
|
-
context: await this.#viewerPricingContext(ctx),
|
|
485
|
+
context: context ?? (await this.#viewerPricingContext(ctx)),
|
|
334
486
|
});
|
|
335
487
|
}
|
|
336
488
|
/**
|
|
@@ -352,16 +504,39 @@ export class CatalogQueryService {
|
|
|
352
504
|
// Issue #249 — the currency the route resolved, or the channel default.
|
|
353
505
|
...listingPriceChannelContext(ctx.resolvedChannel, ctx.currency),
|
|
354
506
|
organization,
|
|
507
|
+
// D-287 P0 — the customer's own group overrides the organisation's; the
|
|
508
|
+
// engine resolves it from the account. Named only beside the account's
|
|
509
|
+
// organisation, so an anonymous page asks exactly what it asked before.
|
|
510
|
+
...(organization && audience.customerAccountId
|
|
511
|
+
? { customerAccountId: audience.customerAccountId }
|
|
512
|
+
: {}),
|
|
355
513
|
};
|
|
356
514
|
}
|
|
357
515
|
/**
|
|
358
|
-
* `ProductSummary.price` for one resolved chain answer. A product
|
|
359
|
-
*
|
|
360
|
-
*
|
|
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".
|
|
361
519
|
*/
|
|
362
520
|
#summaryPrice(resolved, productId) {
|
|
363
|
-
const
|
|
364
|
-
return
|
|
521
|
+
const detail = resolved.get(productId);
|
|
522
|
+
return detail === undefined ? null : listingPriceMoney(detail.price);
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* `ProductSummary.resolvedPrice` — base, sale and display mode from the same
|
|
526
|
+
* resolution as `price` (D-287 P0), and the list price beside a lower buyer
|
|
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.
|
|
529
|
+
*/
|
|
530
|
+
#summaryResolvedPrice(resolved, productId) {
|
|
531
|
+
const detail = resolved.get(productId);
|
|
532
|
+
if (detail === undefined)
|
|
533
|
+
return null;
|
|
534
|
+
return {
|
|
535
|
+
basePrice: detail.basePrice,
|
|
536
|
+
salePrice: detail.salePrice,
|
|
537
|
+
displayMode: detail.displayMode,
|
|
538
|
+
...(detail.listPrice ? { listPrice: { amount: detail.listPrice.amount, currency: detail.listPrice.currency } } : {}),
|
|
539
|
+
};
|
|
365
540
|
}
|
|
366
541
|
/**
|
|
367
542
|
* {@link ListingCardReads} for a page, in a fixed number of statements
|
|
@@ -378,15 +553,32 @@ export class CatalogQueryService {
|
|
|
378
553
|
* that index in that order. Writing it down is what keeps the array the same
|
|
379
554
|
* array now that a page-wide `in (…)` may reach the rows by another plan.
|
|
380
555
|
*/
|
|
381
|
-
async #listingCardReadsFor(em,
|
|
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);
|
|
382
567
|
const categorySlugsByProduct = new Map();
|
|
383
568
|
if (productIds.length === 0) {
|
|
384
|
-
return {
|
|
569
|
+
return {
|
|
570
|
+
assetUrlByProduct: new Map(),
|
|
571
|
+
categorySlugsByProduct,
|
|
572
|
+
overridesByProduct: new Map(),
|
|
573
|
+
effectiveKeyByProduct: new Map(),
|
|
574
|
+
minOrderQuantityByProduct: new Map(),
|
|
575
|
+
};
|
|
385
576
|
}
|
|
386
577
|
// Primary asset — for listings prefer the gallery's Thumbnail (US3),
|
|
387
578
|
// then Base Image, then any first gallery item, finally the legacy
|
|
388
|
-
// product_assets row. Resolution chain pinned by T096
|
|
389
|
-
|
|
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);
|
|
390
582
|
const ids = [...productIds];
|
|
391
583
|
const catRows = await em.execute(`select pc.product_id::text as product_id, c.slug
|
|
392
584
|
from product_categories pc
|
|
@@ -398,20 +590,61 @@ export class CatalogQueryService {
|
|
|
398
590
|
slugs.push(row.slug);
|
|
399
591
|
categorySlugsByProduct.set(row.product_id, slugs);
|
|
400
592
|
}
|
|
401
|
-
|
|
593
|
+
const overridesByProduct = await loadChannelOverridesByProduct(em, ids, channelId);
|
|
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;
|
|
402
627
|
}
|
|
403
628
|
// ------------------------------------------------------------------
|
|
404
629
|
// Products
|
|
405
630
|
// ------------------------------------------------------------------
|
|
406
631
|
async listProducts(params, ctx) {
|
|
632
|
+
// A price walk that began in the default order, for want of a price order,
|
|
633
|
+
// continues in it to its end — the default listing's page, so nothing the
|
|
634
|
+
// price path would read first is read (review 2, finding 7).
|
|
635
|
+
const priceCursor = isPriceSort(params.sort) && params.cursor ? this.#priceCursor(params.cursor, ctx) : null;
|
|
636
|
+
if (priceCursor?.stream === 'unordered')
|
|
637
|
+
return this.#listUnordered(params, ctx, priceCursor.cursor);
|
|
407
638
|
const em = this.emFactory();
|
|
408
639
|
const channel = ctx.resolvedChannel;
|
|
409
640
|
// --- Filter validation: any filter[attr.<key>] where the attribute is
|
|
410
641
|
// not filterable must return 400 FILTER_NOT_ALLOWED (FR-005, T043).
|
|
642
|
+
let attributeViews = [];
|
|
411
643
|
if (params.attributeFilters) {
|
|
412
644
|
const keys = Object.keys(params.attributeFilters);
|
|
413
645
|
if (keys.length > 0) {
|
|
414
646
|
const views = await this.#requireAttributeRead().listAll();
|
|
647
|
+
attributeViews = views;
|
|
415
648
|
const byKey = new Map(views.map((a) => [a.key, a]));
|
|
416
649
|
for (const k of keys) {
|
|
417
650
|
const a = byKey.get(k);
|
|
@@ -421,32 +654,17 @@ export class CatalogQueryService {
|
|
|
421
654
|
}
|
|
422
655
|
}
|
|
423
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).
|
|
424
660
|
const where = {
|
|
425
|
-
status: 'active',
|
|
426
661
|
deletedAt: null,
|
|
427
662
|
};
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
// The attribute-values match uses Postgres ILIKE on the JSONB cast to
|
|
434
|
-
// text, which is fine for the test corpus and good enough until Meili.
|
|
435
|
-
const searchableKeys = await this.searchableAttributeKeys(em);
|
|
436
|
-
const orClauses = [
|
|
437
|
-
{ sku: { $ilike: `%${params.q}%` } },
|
|
438
|
-
];
|
|
439
|
-
for (const key of searchableKeys) {
|
|
440
|
-
// MikroORM's `expr()` would be cleaner; raw cast keeps the dependency
|
|
441
|
-
// surface minimal here.
|
|
442
|
-
orClauses.push({
|
|
443
|
-
// Match any product whose attributeValues[key] (case-insensitive)
|
|
444
|
-
// contains the query.
|
|
445
|
-
attributeValues: this.searchableJsonbClause(key, params.q),
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
where['$or'] = orClauses;
|
|
449
|
-
}
|
|
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);
|
|
450
668
|
if (params.changedSince) {
|
|
451
669
|
where['updatedAt'] = { $gt: new Date(params.changedSince) };
|
|
452
670
|
}
|
|
@@ -454,23 +672,22 @@ export class CatalogQueryService {
|
|
|
454
672
|
// chunked and both are bounded; everything else takes the single fetch it
|
|
455
673
|
// always took.
|
|
456
674
|
if (isPriceSort(params.sort)) {
|
|
457
|
-
return this.#listByViewerPrice(em, params, ctx, where, params.sort);
|
|
675
|
+
return this.#listByViewerPrice(em, params, ctx, where, params.sort, priceCursor, scope, filters);
|
|
458
676
|
}
|
|
459
677
|
if (params.minPrice !== undefined || params.maxPrice !== undefined) {
|
|
460
|
-
return this.#listWithPriceRange(em, params, ctx, where);
|
|
678
|
+
return this.#listWithPriceRange(em, params, ctx, where, scope, filters);
|
|
461
679
|
}
|
|
462
680
|
// Cursor decoding — over the keyset this ordering pages by, which is
|
|
463
|
-
// `{ createdAt, id }` for the default sort and `{
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
}
|
|
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;
|
|
471
688
|
// Issue #151 — everything that decides whether a row is on the listing is
|
|
472
689
|
// part of the statement the page is cut from. See `#listingNarrowing`.
|
|
473
|
-
const narrowing = await this.#listingNarrowing(em, params,
|
|
690
|
+
const narrowing = await this.#listingNarrowing(em, params, scope);
|
|
474
691
|
if (narrowing === null) {
|
|
475
692
|
// The category names nothing a storefront may browse, so no row matches
|
|
476
693
|
// and there is no statement worth issuing.
|
|
@@ -490,23 +707,29 @@ export class CatalogQueryService {
|
|
|
490
707
|
const products = await em.find(Product, {
|
|
491
708
|
$and: [
|
|
492
709
|
where,
|
|
493
|
-
...(
|
|
494
|
-
...narrowing.map((c) => ({ [raw(c.sql, c.params)]: [] })),
|
|
710
|
+
...(decodedCursor ? [keyset.after(decodedCursor)] : []),
|
|
711
|
+
...[...narrowing, ...filters.conditions].map((c) => ({ [raw(c.sql, c.params)]: [] })),
|
|
495
712
|
],
|
|
496
|
-
}, { limit: params.limit + 1, orderBy:
|
|
713
|
+
}, { limit: params.limit + 1, orderBy: keyset.orderBy() });
|
|
497
714
|
const hasMore = products.length > params.limit;
|
|
498
715
|
const page = hasMore ? products.slice(0, params.limit) : products;
|
|
499
|
-
const
|
|
500
|
-
|
|
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
|
|
501
721
|
// statement returned — kept deliberately, as defence in depth.
|
|
502
|
-
// `
|
|
503
|
-
// this product" and the SQL above is a restatement of
|
|
504
|
-
// admits a row the
|
|
505
|
-
// The case that exists today is a stored allow-list
|
|
506
|
-
// the statement reads it as "no allow-list", the
|
|
507
|
-
//
|
|
508
|
-
//
|
|
509
|
-
|
|
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));
|
|
510
733
|
// Build the summaries. The page is resolved **once** — `toSummary` used to
|
|
511
734
|
// ask `price_lists` for a batch of one, so a 50-card page made 50 calls and
|
|
512
735
|
// paid the resolution's fixed cost (the active lists, the settings pair, the
|
|
@@ -518,7 +741,7 @@ export class CatalogQueryService {
|
|
|
518
741
|
// same reason (issue #263): both helpers took an id list already, and both
|
|
519
742
|
// were being handed one id at a time from inside the loop.
|
|
520
743
|
const resolvedPrices = await this.#listingPricesFor(priceable, ctx);
|
|
521
|
-
const cardReads = await this.#listingCardReadsFor(em, priceable
|
|
744
|
+
const cardReads = await this.#listingCardReadsFor(em, priceable, ctx);
|
|
522
745
|
const summaries = priceable.map((p) => this.toSummary(p, channel, ctx.preferredLanguage, resolvedPrices, cardReads));
|
|
523
746
|
return {
|
|
524
747
|
data: summaries,
|
|
@@ -536,11 +759,12 @@ export class CatalogQueryService {
|
|
|
536
759
|
* were was short. With two sales channels and the newest hundred products on
|
|
537
760
|
* one of them, the other's first page of a hundred was empty.
|
|
538
761
|
*
|
|
539
|
-
* - **
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
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);
|
|
544
768
|
* - **the category** is an `exists` over this module's own
|
|
545
769
|
* `product_categories`, against the tree's ids rather than against every
|
|
546
770
|
* product id the tree holds, which is what the page-side test loaded;
|
|
@@ -553,7 +777,7 @@ export class CatalogQueryService {
|
|
|
553
777
|
* only by the statement that consumes it, so this method, which can answer
|
|
554
778
|
* `null` and awaits a read that can fail, is the wrong place to make one.
|
|
555
779
|
*/
|
|
556
|
-
async #listingNarrowing(em, params,
|
|
780
|
+
async #listingNarrowing(em, params, scope) {
|
|
557
781
|
// First, because it is the one part that can end the request: an unknown,
|
|
558
782
|
// inactive or deleted category means no row matches.
|
|
559
783
|
let categoryIds = null;
|
|
@@ -562,11 +786,7 @@ export class CatalogQueryService {
|
|
|
562
786
|
if (categoryIds.length === 0)
|
|
563
787
|
return null;
|
|
564
788
|
}
|
|
565
|
-
const
|
|
566
|
-
const conditions = [
|
|
567
|
-
{ sql: (alias) => `${alias}.id in (${inChannel.sql})`, params: inChannel.params },
|
|
568
|
-
this.#audienceCondition(ctx.audience),
|
|
569
|
-
];
|
|
789
|
+
const conditions = [this.#availabilityNarrowing(scope)];
|
|
570
790
|
if (categoryIds !== null) {
|
|
571
791
|
const ids = categoryIds;
|
|
572
792
|
conditions.push({
|
|
@@ -576,39 +796,8 @@ export class CatalogQueryService {
|
|
|
576
796
|
params: ids,
|
|
577
797
|
});
|
|
578
798
|
}
|
|
579
|
-
for (const [key, values] of Object.entries(params.attributeFilters ?? {})) {
|
|
580
|
-
conditions.push(this.#attributeCondition(key, values));
|
|
581
|
-
}
|
|
582
799
|
return conditions;
|
|
583
800
|
}
|
|
584
|
-
/**
|
|
585
|
-
* `isProductVisibleTo`, as SQL, for the audience in front of the listing.
|
|
586
|
-
*
|
|
587
|
-
* The third restatement of that predicate in this module, and the only one
|
|
588
|
-
* that takes the audience as an argument: `catalog-quick-search.service.ts`
|
|
589
|
-
* answers for a signed-in buyer and `ANONYMOUS_AUDIENCE_CLAUSE` for nobody,
|
|
590
|
-
* so neither could be reused for a surface both kinds of caller read. The
|
|
591
|
-
* `case` follows the predicate branch for branch — a non-empty allow-list
|
|
592
|
-
* decides on its own, then `organization_restricted`, then `logged_in_only` —
|
|
593
|
-
* so a fourth visibility value falls to `else true` exactly as it falls to
|
|
594
|
-
* the predicate's last `return`.
|
|
595
|
-
*
|
|
596
|
-
* `@>` containment over the JSONB array, so the organisation has to be one of
|
|
597
|
-
* its elements rather than a substring of the serialised bag.
|
|
598
|
-
*/
|
|
599
|
-
#audienceCondition(audience) {
|
|
600
|
-
const onAllowList = audience.organizationId !== null;
|
|
601
|
-
return {
|
|
602
|
-
sql: (alias) => `(case ` +
|
|
603
|
-
`when (case when jsonb_typeof(${alias}.allowed_organization_ids) = 'array' ` +
|
|
604
|
-
`then jsonb_array_length(${alias}.allowed_organization_ids) else 0 end) > 0 ` +
|
|
605
|
-
`then ${onAllowList ? `${alias}.allowed_organization_ids @> ?::jsonb` : 'false'} ` +
|
|
606
|
-
`when ${alias}.visibility = 'organization_restricted' then false ` +
|
|
607
|
-
`when ${alias}.visibility = 'logged_in_only' then ${audience.authenticated ? 'true' : 'false'} ` +
|
|
608
|
-
`else true end)`,
|
|
609
|
-
params: onAllowList ? [JSON.stringify([audience.organizationId])] : [],
|
|
610
|
-
};
|
|
611
|
-
}
|
|
612
801
|
/**
|
|
613
802
|
* One `filter[attr.<key>]`, as SQL: the product's value for `key`, rendered
|
|
614
803
|
* the way `#passesPageFilters` renders it, is one of the requested values.
|
|
@@ -623,57 +812,98 @@ export class CatalogQueryService {
|
|
|
623
812
|
* is a question about what the filter means, and answering it in the
|
|
624
813
|
* statement only would make the page-side predicate disagree with it.
|
|
625
814
|
*/
|
|
626
|
-
#attributeCondition(
|
|
815
|
+
#attributeCondition(value, values) {
|
|
627
816
|
const wanted = values.map((v) => String(v));
|
|
628
817
|
if (wanted.length === 0)
|
|
629
818
|
return { sql: () => 'false', params: [] };
|
|
630
819
|
return {
|
|
631
820
|
sql: (alias) => `(select ${jsStringOfJsonb('val.v')} ` +
|
|
632
|
-
`from (select ${alias}
|
|
821
|
+
`from (select ${value.sql(alias)} as v) val) ` +
|
|
633
822
|
`in (${wanted.map(() => '?').join(',')})`,
|
|
634
|
-
params: [
|
|
823
|
+
params: [...value.params, ...wanted],
|
|
635
824
|
};
|
|
636
825
|
}
|
|
637
826
|
/**
|
|
638
|
-
*
|
|
639
|
-
*
|
|
640
|
-
*
|
|
641
|
-
*
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
*
|
|
645
|
-
* would make a hidden row observable through a position or a page boundary,
|
|
646
|
-
* which is the disclosure FR-014 forbids and which neither the relevance sort
|
|
647
|
-
* 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.
|
|
648
834
|
*/
|
|
649
|
-
#
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
//
|
|
654
|
-
//
|
|
655
|
-
//
|
|
656
|
-
|
|
657
|
-
if (
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
const av = product.attributeValues[k];
|
|
663
|
-
if (av === undefined)
|
|
664
|
-
return false;
|
|
665
|
-
if (!values.map((v) => String(v)).includes(String(av)))
|
|
666
|
-
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
|
+
});
|
|
667
848
|
}
|
|
668
|
-
|
|
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
|
+
};
|
|
669
883
|
}
|
|
670
|
-
/**
|
|
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
|
+
};
|
|
899
|
+
}
|
|
900
|
+
/** The two range bounds as four-place decimal strings ({@link amountBound}), for every price path. */
|
|
671
901
|
#amountRange(params) {
|
|
672
902
|
if (params.minPrice === undefined && params.maxPrice === undefined)
|
|
673
903
|
return undefined;
|
|
674
904
|
return {
|
|
675
|
-
...(params.minPrice !== undefined ? { min: params.minPrice
|
|
676
|
-
...(params.maxPrice !== undefined ? { max: params.maxPrice
|
|
905
|
+
...(params.minPrice !== undefined ? { min: amountBound(params.minPrice, 'min') } : {}),
|
|
906
|
+
...(params.maxPrice !== undefined ? { max: amountBound(params.maxPrice, 'max') } : {}),
|
|
677
907
|
};
|
|
678
908
|
}
|
|
679
909
|
/**
|
|
@@ -701,27 +931,28 @@ export class CatalogQueryService {
|
|
|
701
931
|
* place the answer is exclusion, and it is exclusion from a filter the buyer
|
|
702
932
|
* typed rather than from the catalogue.
|
|
703
933
|
*
|
|
704
|
-
* **
|
|
705
|
-
*
|
|
706
|
-
*
|
|
707
|
-
* the priced stream is the price-list relation, and everything else is the
|
|
708
|
-
* tail. Measured incidence of a product carrying that attribute *and* priced
|
|
709
|
-
* by no active list: zero. Interleaving it would mean ordering across
|
|
710
|
-
* `price_list_price_brackets` and `products.attribute_values` in one
|
|
711
|
-
* statement — two modules' tables, which `check:module-boundary` refuses — and
|
|
712
|
-
* the operator's remedy is one action: price the product on the default list.
|
|
713
|
-
* The decision is expressed here, in which set feeds which stream, and
|
|
714
|
-
* nowhere else.
|
|
934
|
+
* **A product has no price of its own** (feature 160, FR-042): the priced
|
|
935
|
+
* stream is the price surface — every price a book gives this viewer — and
|
|
936
|
+
* everything else is the tail.
|
|
715
937
|
*/
|
|
716
|
-
async #listByViewerPrice(em, params, ctx, where, sort
|
|
938
|
+
async #listByViewerPrice(em, params, ctx, where, sort,
|
|
939
|
+
/** The request's cursor as `#priceCursor` read it: `null` starts the walk. */
|
|
940
|
+
decoded, availability, filters) {
|
|
717
941
|
const channel = ctx.resolvedChannel;
|
|
718
942
|
const direction = sort === 'price' ? 'asc' : 'desc';
|
|
719
|
-
|
|
943
|
+
// The viewer's pricing context and the category tree, read once for the
|
|
944
|
+
// page and handed to whichever walk serves it — every chunk of it (review
|
|
945
|
+
// 3, A5). An `unordered` walk is decided earlier, in `listProducts`, and
|
|
946
|
+
// reads neither (review 2, finding 7).
|
|
947
|
+
const scope = await this.#priceWalkScope(em, params, ctx, availability, filters);
|
|
948
|
+
const { context } = scope;
|
|
949
|
+
// A walk whose price order went missing carries on in the default order
|
|
950
|
+
// from the last price it served, to its end.
|
|
951
|
+
if (decoded?.stream === 'rest') {
|
|
952
|
+
return this.#listRemainder(em, params, ctx, where, direction, scope, decoded, decoded.after);
|
|
953
|
+
}
|
|
720
954
|
const amountRange = this.#amountRange(params);
|
|
721
|
-
const restrictToProductIds =
|
|
722
|
-
? [...(await this.productIdsInCategoryTree(em, params.categorySlug))]
|
|
723
|
-
: undefined;
|
|
724
|
-
const decoded = params.cursor ? decodeObjectCursor(params.cursor) : null;
|
|
955
|
+
const { restrictToProductIds } = scope;
|
|
725
956
|
// A cursor issued under another sort is discarded rather than
|
|
726
957
|
// reinterpreted: the existing behaviour for a cursor that does not parse.
|
|
727
958
|
const startInTail = decoded?.stream === 'tail';
|
|
@@ -739,6 +970,8 @@ export class CatalogQueryService {
|
|
|
739
970
|
const collected = [];
|
|
740
971
|
const cursors = [];
|
|
741
972
|
let pricedExhausted = startInTail;
|
|
973
|
+
// The price order went missing after this page had collected from it.
|
|
974
|
+
let orderLost = false;
|
|
742
975
|
// --- the priced stream -------------------------------------------------
|
|
743
976
|
while (!pricedExhausted && collected.length < target) {
|
|
744
977
|
if (spent >= budget) {
|
|
@@ -753,6 +986,26 @@ export class CatalogQueryService {
|
|
|
753
986
|
...(restrictToProductIds !== undefined ? { restrictToProductIds } : {}),
|
|
754
987
|
...(amountRange ? { amountRange } : {}),
|
|
755
988
|
});
|
|
989
|
+
// Feature 160 (`specs/160-pricing-model-v2/contracts/price-surface.md` §3)
|
|
990
|
+
// — no price order exists yet for this channel and currency, and none is
|
|
991
|
+
// built for a request: the page is served in the default order, cards
|
|
992
|
+
// priced live, until the worker has built one. Its cursor is the default
|
|
993
|
+
// listing's, wrapped so the next page continues that walk.
|
|
994
|
+
//
|
|
995
|
+
// Review 2, finding 6 — a walk that is already **on** the price order
|
|
996
|
+
// (a `priced` cursor, or a chunk of this page) and finds it gone does not
|
|
997
|
+
// start again: page 1 of the default order would repeat what it served.
|
|
998
|
+
// It carries on from the last price read (`#listRemainder`); a page that
|
|
999
|
+
// has collected some rows ends with them, its cursor naming the last.
|
|
1000
|
+
if (chunk.unordered) {
|
|
1001
|
+
if (collected.length > 0) {
|
|
1002
|
+
orderLost = true;
|
|
1003
|
+
break;
|
|
1004
|
+
}
|
|
1005
|
+
if (priceCursor === null)
|
|
1006
|
+
return this.#listUnordered(params, ctx, null);
|
|
1007
|
+
return this.#listRemainder(em, params, ctx, where, direction, scope, priceCursor, null);
|
|
1008
|
+
}
|
|
756
1009
|
spent += Math.max(chunk.sourceRowsRead, chunk.rows.length);
|
|
757
1010
|
pricedExhausted = chunk.exhausted;
|
|
758
1011
|
if (chunk.rows.length === 0) {
|
|
@@ -762,7 +1015,7 @@ export class CatalogQueryService {
|
|
|
762
1015
|
}
|
|
763
1016
|
const last = chunk.rows[chunk.rows.length - 1];
|
|
764
1017
|
priceCursor = { amount: last.amount, productId: last.productId };
|
|
765
|
-
const byId = await this.#visibleProductsInOrder(em, chunk.rows.map((row) => row.productId), where,
|
|
1018
|
+
const byId = await this.#visibleProductsInOrder(em, chunk.rows.map((row) => row.productId), where, scope.availability, scope.filters);
|
|
766
1019
|
for (const row of chunk.rows) {
|
|
767
1020
|
const product = byId.get(row.productId);
|
|
768
1021
|
if (!product)
|
|
@@ -779,28 +1032,32 @@ export class CatalogQueryService {
|
|
|
779
1032
|
// not imply, because the provider may have stopped on its own bound.
|
|
780
1033
|
const wantsTail = amountRange === undefined && pricedExhausted && !bound;
|
|
781
1034
|
if (wantsTail) {
|
|
782
|
-
const categoryIds =
|
|
783
|
-
? new Set(restrictToProductIds ?? [])
|
|
784
|
-
: null;
|
|
1035
|
+
const categoryIds = scope.categoryIds;
|
|
785
1036
|
while (collected.length < target) {
|
|
786
1037
|
if (spent >= budget) {
|
|
787
1038
|
bound = true;
|
|
788
1039
|
break;
|
|
789
1040
|
}
|
|
790
|
-
const
|
|
791
|
-
?
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
$
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
const rows = await em.find(Product,
|
|
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
|
+
}, {
|
|
804
1061
|
limit: chunkSize,
|
|
805
1062
|
// The listing's own default ordering, in both directions: the tail is
|
|
806
1063
|
// not ordered by a price it does not have.
|
|
@@ -816,11 +1073,12 @@ export class CatalogQueryService {
|
|
|
816
1073
|
productIds: rows.map((r) => r.id),
|
|
817
1074
|
});
|
|
818
1075
|
const candidates = rows.filter((r) => !priced.has(r.id) && (categoryIds === null || categoryIds.has(r.id)));
|
|
819
|
-
const visibleIds = await this
|
|
1076
|
+
const visibleIds = await this.#availableAmong(em, candidates, scope.availability, true);
|
|
1077
|
+
const passing = await scope.filters.passes(em, candidates);
|
|
820
1078
|
for (const product of candidates) {
|
|
821
1079
|
if (!visibleIds.has(product.id))
|
|
822
1080
|
continue;
|
|
823
|
-
if (!
|
|
1081
|
+
if (!passing.has(product.id))
|
|
824
1082
|
continue;
|
|
825
1083
|
collected.push(product);
|
|
826
1084
|
cursors.push({
|
|
@@ -838,11 +1096,24 @@ export class CatalogQueryService {
|
|
|
838
1096
|
if (bound) {
|
|
839
1097
|
this.log?.warn({ budget, spent, limit: params.limit, sort }, 'catalog: price-ordered page hit its scan budget and is returning short');
|
|
840
1098
|
}
|
|
841
|
-
|
|
1099
|
+
// A page cut by the scan budget continues from where its scan stopped —
|
|
1100
|
+
// in the tail once the tail has been read, else in the priced stream,
|
|
1101
|
+
// whose exhaustion the next page then finds and goes on into the tail —
|
|
1102
|
+
// never from its last card, and never ends the walk (review 3 of release
|
|
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).
|
|
842
1105
|
const page = collected.slice(0, params.limit);
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
1106
|
+
let resumeAt = null;
|
|
1107
|
+
if (collected.length > params.limit || orderLost)
|
|
1108
|
+
resumeAt = cursors[page.length - 1] ?? null;
|
|
1109
|
+
else if (bound && tailCursor)
|
|
1110
|
+
resumeAt = { stream: 'tail', ...tailCursor };
|
|
1111
|
+
else if (bound && priceCursor)
|
|
1112
|
+
resumeAt = { stream: 'priced', ...priceCursor };
|
|
1113
|
+
const hasMore = resumeAt !== null;
|
|
1114
|
+
const nextCursor = resumeAt === null ? null : this.#sealCursor(PRICE_WALK_CURSOR_PURPOSE, resumeAt);
|
|
1115
|
+
const resolvedPrices = await this.#listingPricesFor(page, ctx, context);
|
|
1116
|
+
const cardReads = await this.#listingCardReadsFor(em, page, ctx);
|
|
846
1117
|
return {
|
|
847
1118
|
data: page.map((p) => this.toSummary(p, channel, ctx.preferredLanguage, resolvedPrices, cardReads)),
|
|
848
1119
|
// No total count, no rank, no "showing 51–100 of 4 213" (FR-015): an
|
|
@@ -851,6 +1122,86 @@ export class CatalogQueryService {
|
|
|
851
1122
|
pagination: { cursor: nextCursor, hasMore, limit: params.limit },
|
|
852
1123
|
};
|
|
853
1124
|
}
|
|
1125
|
+
/**
|
|
1126
|
+
* What every chunk of a price walk reads for the same viewer: built once per
|
|
1127
|
+
* page and passed down, never per chunk (review 3 of release 0.108.0, A5 — a
|
|
1128
|
+
* page reads up to eight chunks, and each used to look the organization up
|
|
1129
|
+
* again and, on the remainder, re-read the category tree).
|
|
1130
|
+
*/
|
|
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;
|
|
1139
|
+
return {
|
|
1140
|
+
context: await this.#viewerPricingContext(ctx),
|
|
1141
|
+
categoryIds,
|
|
1142
|
+
restrictToProductIds,
|
|
1143
|
+
availability,
|
|
1144
|
+
filters,
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* The cursor of a price-sorted page, every field checked, or `null` — which
|
|
1149
|
+
* starts the walk at its first page, as the default listing does with a
|
|
1150
|
+
* cursor it cannot read (review 3 of release 0.108.0, A4). A price is read
|
|
1151
|
+
* with the contracts' decimal parser, an id must be a uuid and a position
|
|
1152
|
+
* the default listing's keyset; an `unordered` cursor wraps the default
|
|
1153
|
+
* listing's own, which that listing checks.
|
|
1154
|
+
*/
|
|
1155
|
+
#priceCursor(cursor, ctx) {
|
|
1156
|
+
const decoded = this.#openCursor(PRICE_WALK_CURSOR_PURPOSE, cursor);
|
|
1157
|
+
if (!isRecord(decoded))
|
|
1158
|
+
return null;
|
|
1159
|
+
const keyset = this.#keysetFor(undefined, ctx);
|
|
1160
|
+
switch (decoded['stream']) {
|
|
1161
|
+
case 'priced': {
|
|
1162
|
+
const amount = cursorAmount(decoded['amount']);
|
|
1163
|
+
const productId = decoded['productId'];
|
|
1164
|
+
return amount !== null && isUuidText(productId) ? { stream: 'priced', amount, productId } : null;
|
|
1165
|
+
}
|
|
1166
|
+
case 'tail': {
|
|
1167
|
+
const at = keyset.parse(decoded);
|
|
1168
|
+
return at !== null && 'createdAt' in at ? { stream: 'tail', createdAt: at.createdAt, id: at.id } : null;
|
|
1169
|
+
}
|
|
1170
|
+
case 'rest': {
|
|
1171
|
+
const amount = cursorAmount(decoded['amount']);
|
|
1172
|
+
const productId = decoded['productId'];
|
|
1173
|
+
const after = keyset.parse(decoded['after']);
|
|
1174
|
+
return amount !== null && isUuidText(productId) && after !== null
|
|
1175
|
+
? { stream: 'rest', amount, productId, after }
|
|
1176
|
+
: null;
|
|
1177
|
+
}
|
|
1178
|
+
case 'unordered':
|
|
1179
|
+
return typeof decoded['cursor'] === 'string' ? { stream: 'unordered', cursor: decoded['cursor'] } : null;
|
|
1180
|
+
default:
|
|
1181
|
+
return null;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
/**
|
|
1185
|
+
* A price-sorted page served in the default order, because no price order
|
|
1186
|
+
* exists for the viewer yet (`contracts/price-surface.md` §3): the default
|
|
1187
|
+
* listing's page, with its cursor wrapped as an `unordered` price cursor so
|
|
1188
|
+
* the walk pages through every product once and ends (review finding 3 of
|
|
1189
|
+
* release 0.108.0 — dropping the cursor served page 1 forever).
|
|
1190
|
+
*/
|
|
1191
|
+
async #listUnordered(params, ctx, cursor) {
|
|
1192
|
+
const { sort: _sort, cursor: _cursor, ...rest } = params;
|
|
1193
|
+
const page = await this.listProducts(cursor ? { ...rest, cursor } : rest, ctx);
|
|
1194
|
+
const next = page.pagination.cursor;
|
|
1195
|
+
return {
|
|
1196
|
+
...page,
|
|
1197
|
+
pagination: {
|
|
1198
|
+
...page.pagination,
|
|
1199
|
+
cursor: next
|
|
1200
|
+
? this.#sealCursor(PRICE_WALK_CURSOR_PURPOSE, { stream: 'unordered', cursor: next })
|
|
1201
|
+
: null,
|
|
1202
|
+
},
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
854
1205
|
/**
|
|
855
1206
|
* A price **range** under an ordering that is not a price ordering (research
|
|
856
1207
|
* §R12).
|
|
@@ -867,19 +1218,92 @@ export class CatalogQueryService {
|
|
|
867
1218
|
* price ordering: the chain's `none` and `product` arms are both absences of
|
|
868
1219
|
* a price-list figure, and a range is a claim about one.
|
|
869
1220
|
*/
|
|
870
|
-
async #listWithPriceRange(em, params, ctx, where) {
|
|
871
|
-
const
|
|
872
|
-
const min = params.minPrice;
|
|
873
|
-
const max = params.maxPrice;
|
|
874
|
-
const categoryFilteredIds = params.categorySlug
|
|
875
|
-
? await this.productIdsInCategoryTree(em, params.categorySlug)
|
|
876
|
-
: null;
|
|
1221
|
+
async #listWithPriceRange(em, params, ctx, where, scope, filters) {
|
|
1222
|
+
const range = this.#amountRange(params);
|
|
877
1223
|
// The chunk walk and the page it hands back page by the same keyset, and
|
|
878
1224
|
// that keyset is the one this ordering sorts on — `keysetFor`.
|
|
879
|
-
const keyset = this
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
: null
|
|
1225
|
+
const keyset = this.#keysetFor(params.sort, ctx);
|
|
1226
|
+
return this.#walkKeepingByPrice(em, params, ctx, where, await this.#priceWalkScope(em, params, ctx, scope, filters), {
|
|
1227
|
+
sort: params.sort,
|
|
1228
|
+
start: params.cursor ? keyset.parse(this.#openCursor(PRICE_RANGE_WALK_CURSOR_PURPOSE, params.cursor)) : null,
|
|
1229
|
+
keep: (price) => price !== null && withinAmountRange(price.amount, range),
|
|
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),
|
|
1233
|
+
what: 'price-filtered',
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
/**
|
|
1237
|
+
* The rest of a price-ordered walk whose price order went missing midway
|
|
1238
|
+
* (review 2, finding 6 of release 0.108.0): the surface was retired or is
|
|
1239
|
+
* being rebuilt, and nothing on this request can rebuild it
|
|
1240
|
+
* (`contracts/price-surface.md` §3).
|
|
1241
|
+
*
|
|
1242
|
+
* What the walk has served is, by price, every priced product up to the last
|
|
1243
|
+
* price it served, `boundary`, in the walk's direction and `(amount,
|
|
1244
|
+
* productId)` keyset — the price order's own — and none of the unpriced
|
|
1245
|
+
* tail, which comes after every priced product. So the rest is every product
|
|
1246
|
+
* the listing shows whose live price (the figure its card is rendered with,
|
|
1247
|
+
* and the one the order is built from) sorts **after** `boundary`, and every
|
|
1248
|
+
* unpriced one unless a price range excludes them (FR-012), walked in the
|
|
1249
|
+
* default order — the order of the rest is the one thing there is no
|
|
1250
|
+
* surface to give.
|
|
1251
|
+
*
|
|
1252
|
+
* **The guarantee, stated honestly** (review 3 of release 0.108.0, A2): the
|
|
1253
|
+
* boundary is a price the order held, compared with a price resolved now.
|
|
1254
|
+
* A product whose price changed while the walk was under way — and an order
|
|
1255
|
+
* usually goes missing *because* pricing changed — can sort onto the other
|
|
1256
|
+
* side of the boundary, so it may be met twice or not at all. That is true
|
|
1257
|
+
* of any keyset walk over a live price, the surface walk included: the
|
|
1258
|
+
* surface follows a repricing too. Every product whose price did not change
|
|
1259
|
+
* is met exactly once, scan budget or not (`#walkKeepingByPrice`).
|
|
1260
|
+
*
|
|
1261
|
+
* Chosen over answering "the order changed, start again" because neither the
|
|
1262
|
+
* listing contract nor the storefront can carry that signal: `pagination` is
|
|
1263
|
+
* `{ cursor, hasMore, limit }`, the storefront's pages are server-rendered
|
|
1264
|
+
* links that hold only the cursor, and a restart is a repeat by definition.
|
|
1265
|
+
* Continuing from the last served position needs no wire change, and a walk
|
|
1266
|
+
* started this way stays on it to its end, like an `unordered` one.
|
|
1267
|
+
*/
|
|
1268
|
+
async #listRemainder(em, params, ctx, where, direction, scope, boundary, after) {
|
|
1269
|
+
const range = this.#amountRange(params);
|
|
1270
|
+
const sign = direction === 'asc' ? 1 : -1;
|
|
1271
|
+
const afterBoundary = (amount, productId) => {
|
|
1272
|
+
const byAmount = compareDecimal(amount, boundary.amount);
|
|
1273
|
+
const byId = productId < boundary.productId ? -1 : productId > boundary.productId ? 1 : 0;
|
|
1274
|
+
return sign * (byAmount || byId) > 0;
|
|
1275
|
+
};
|
|
1276
|
+
return this.#walkKeepingByPrice(em, params, ctx, where, scope, {
|
|
1277
|
+
sort: undefined,
|
|
1278
|
+
start: after,
|
|
1279
|
+
keep: (price, product) => {
|
|
1280
|
+
if (price === null)
|
|
1281
|
+
return range === undefined;
|
|
1282
|
+
return withinAmountRange(price.amount, range) && afterBoundary(price.amount, product.id);
|
|
1283
|
+
},
|
|
1284
|
+
cursorOf: (next) => this.#sealCursor(PRICE_WALK_CURSOR_PURPOSE, {
|
|
1285
|
+
stream: 'rest',
|
|
1286
|
+
amount: boundary.amount,
|
|
1287
|
+
productId: boundary.productId,
|
|
1288
|
+
after: next,
|
|
1289
|
+
}),
|
|
1290
|
+
what: 'price-ordered (order lost)',
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
/**
|
|
1294
|
+
* A listing walked in a keyset ordering, chunk by chunk, each chunk narrowed
|
|
1295
|
+
* by everything a page is narrowed by and then by the live listing price its
|
|
1296
|
+
* cards are rendered with — `keep` decides on that price. Bounded by the scan
|
|
1297
|
+
* budget; a bound answers a short, possibly empty, page whose cursor
|
|
1298
|
+
* continues from the scan position. `cursorOf` seals it: that position may
|
|
1299
|
+
* be a product the viewer may not see (issue #497).
|
|
1300
|
+
*/
|
|
1301
|
+
async #walkKeepingByPrice(em, params, ctx, where, scope, walk) {
|
|
1302
|
+
const channel = ctx.resolvedChannel;
|
|
1303
|
+
const categoryFilteredIds = scope.categoryIds;
|
|
1304
|
+
const filters = scope.filters;
|
|
1305
|
+
const keyset = this.#keysetFor(walk.sort, ctx);
|
|
1306
|
+
let cursor = walk.start;
|
|
883
1307
|
const budget = PRICE_PAGE_SCAN_BUDGET_MULTIPLE * params.limit;
|
|
884
1308
|
const target = params.limit + 1;
|
|
885
1309
|
// Over-fetch by one, for the same reason the price path does: a full page
|
|
@@ -894,34 +1318,48 @@ export class CatalogQueryService {
|
|
|
894
1318
|
bound = true;
|
|
895
1319
|
break;
|
|
896
1320
|
}
|
|
897
|
-
|
|
898
|
-
|
|
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
|
+
}, {
|
|
899
1331
|
limit: chunkSize,
|
|
900
|
-
orderBy:
|
|
1332
|
+
orderBy: keyset.orderBy(),
|
|
901
1333
|
});
|
|
902
1334
|
spent += rows.length;
|
|
903
1335
|
if (rows.length === 0)
|
|
904
1336
|
break;
|
|
905
1337
|
const lastRow = rows[rows.length - 1];
|
|
906
|
-
cursor = keyset.of(lastRow);
|
|
907
|
-
const visibleIds = await this
|
|
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);
|
|
908
1341
|
const candidates = rows.filter((r) => visibleIds.has(r.id) &&
|
|
909
|
-
|
|
1342
|
+
passing.has(r.id) &&
|
|
910
1343
|
(categoryFilteredIds === null || categoryFilteredIds.has(r.id)));
|
|
911
|
-
|
|
1344
|
+
// The walk decides on the viewer's own price — the figure the price
|
|
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).
|
|
1349
|
+
const chunkPrices = candidates.length === 0
|
|
1350
|
+
? new Map()
|
|
1351
|
+
: await this.#requireListingPrices().resolveListingPriceDetails({
|
|
1352
|
+
products: candidates,
|
|
1353
|
+
context: scope.context,
|
|
1354
|
+
});
|
|
912
1355
|
for (const product of candidates) {
|
|
913
|
-
const
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
const amount = Number(price.amount);
|
|
917
|
-
if (!Number.isFinite(amount))
|
|
918
|
-
continue;
|
|
919
|
-
if (min !== undefined && amount < min)
|
|
920
|
-
continue;
|
|
921
|
-
if (max !== undefined && amount > max)
|
|
1356
|
+
const detail = chunkPrices.get(product.id);
|
|
1357
|
+
const price = detail?.price.source === 'price_list' ? detail.price : null;
|
|
1358
|
+
if (!walk.keep(price, product))
|
|
922
1359
|
continue;
|
|
923
1360
|
collected.push(product);
|
|
924
|
-
|
|
1361
|
+
if (detail !== undefined)
|
|
1362
|
+
prices.set(product.id, detail);
|
|
925
1363
|
if (collected.length >= target)
|
|
926
1364
|
break;
|
|
927
1365
|
}
|
|
@@ -929,13 +1367,20 @@ export class CatalogQueryService {
|
|
|
929
1367
|
break;
|
|
930
1368
|
}
|
|
931
1369
|
if (bound) {
|
|
932
|
-
this.log?.warn({ budget, spent, limit: params.limit, sort: params.sort ?? 'relevance' },
|
|
1370
|
+
this.log?.warn({ budget, spent, limit: params.limit, sort: params.sort ?? 'relevance' }, `catalog: ${walk.what} page hit its scan budget and is returning short`);
|
|
933
1371
|
}
|
|
934
|
-
|
|
1372
|
+
// A page cut by the scan budget has more after it, and continues from
|
|
1373
|
+
// where its scan stopped — not from its last card, which would read the
|
|
1374
|
+
// same rows again — so a budget makes a page short, or empty, but never
|
|
1375
|
+
// ends the walk (review 3 of release 0.108.0, A1). The scan moves forward
|
|
1376
|
+
// by at least one chunk a page, so the walk still ends.
|
|
1377
|
+
const full = collected.length > params.limit;
|
|
935
1378
|
const page = collected.slice(0, params.limit);
|
|
936
1379
|
const last = page[page.length - 1];
|
|
937
|
-
const
|
|
938
|
-
const
|
|
1380
|
+
const resumeAt = full && last ? keyset.of(last, await this.#cursorNames(em, keyset, [last], ctx)) : bound ? cursor : null;
|
|
1381
|
+
const hasMore = resumeAt !== null;
|
|
1382
|
+
const nextCursor = resumeAt === null ? null : walk.cursorOf(resumeAt);
|
|
1383
|
+
const cardReads = await this.#listingCardReadsFor(em, page, ctx);
|
|
939
1384
|
return {
|
|
940
1385
|
data: page.map((p) => this.toSummary(p, channel, ctx.preferredLanguage, prices, cardReads)),
|
|
941
1386
|
pagination: { cursor: nextCursor, hasMore, limit: params.limit },
|
|
@@ -949,47 +1394,152 @@ export class CatalogQueryService {
|
|
|
949
1394
|
* answers in whatever order it likes, and the ordering being reproduced is the
|
|
950
1395
|
* price one.
|
|
951
1396
|
*/
|
|
952
|
-
async #visibleProductsInOrder(em, productIds, where,
|
|
1397
|
+
async #visibleProductsInOrder(em, productIds, where, scope, filters) {
|
|
953
1398
|
const out = new Map();
|
|
954
1399
|
if (productIds.length === 0)
|
|
955
1400
|
return out;
|
|
956
|
-
|
|
957
|
-
const
|
|
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);
|
|
958
1412
|
for (const product of rows) {
|
|
959
1413
|
if (!visibleIds.has(product.id))
|
|
960
1414
|
continue;
|
|
961
|
-
if (!
|
|
1415
|
+
if (!passing.has(product.id))
|
|
962
1416
|
continue;
|
|
963
1417
|
out.set(product.id, product);
|
|
964
1418
|
}
|
|
965
1419
|
return out;
|
|
966
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
|
+
*/
|
|
967
1522
|
async getProductByIdOrSlug(idOrSlug, ctx) {
|
|
968
1523
|
const em = this.emFactory();
|
|
969
1524
|
const channel = ctx.resolvedChannel;
|
|
970
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);
|
|
971
|
-
const product =
|
|
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 })));
|
|
972
1530
|
if (!product || product.deletedAt) {
|
|
973
1531
|
throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
|
|
974
1532
|
}
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
const
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
// 403: a caller who may not see the row may not learn it exists either,
|
|
986
|
-
// and a 403 on a slug tells them it does. This is also the gate the
|
|
987
|
-
// `/links` and `/bundle-configuration/validate` routes stand behind, since
|
|
988
|
-
// both resolve their subject through here first.
|
|
989
|
-
if (!isProductVisibleTo(product, ctx.audience)) {
|
|
990
|
-
throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
|
|
991
|
-
}
|
|
992
|
-
const summary = this.toSummary(product, channel, ctx.preferredLanguage, await this.#listingPricesFor([product], ctx), await this.#listingCardReadsFor(em, [product.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 });
|
|
1539
|
+
const summary = this.toSummary(product, channel, ctx.preferredLanguage, await this.#listingPricesFor([product], ctx), cardReads);
|
|
1540
|
+
// Issue #384 — the product's override rows, already read for the summary.
|
|
1541
|
+
const overrides = cardReads.overridesByProduct.get(product.id);
|
|
1542
|
+
const overrideCtx = this.#overrideContext(channel, ctx.preferredLanguage);
|
|
993
1543
|
// Categories
|
|
994
1544
|
const categoryRows = await em.execute(`select category_id from product_categories where product_id = ?`, [product.id]);
|
|
995
1545
|
const categoryIds = categoryRows.map((r) => r.category_id);
|
|
@@ -1003,7 +1553,7 @@ export class CatalogQueryService {
|
|
|
1003
1553
|
// Assets
|
|
1004
1554
|
const assetRows = await em.execute(`select asset_id, position from product_assets where product_id = ? order by position asc`, [product.id]);
|
|
1005
1555
|
const assetIds = assetRows.map((r) => r.asset_id);
|
|
1006
|
-
const
|
|
1556
|
+
const allAssets = await this.#requireAssets().findByIds(assetIds);
|
|
1007
1557
|
// Variants
|
|
1008
1558
|
const variants = product.type === 'configurable' ? await em.find(ProductVariant, { parentProductId: product.id }) : [];
|
|
1009
1559
|
// Feature 002 — Attribute Set wired to this Product. Pulled in a
|
|
@@ -1015,25 +1565,47 @@ export class CatalogQueryService {
|
|
|
1015
1565
|
// Feature 002 US3 — eager-load gallery + attachments for the PDP.
|
|
1016
1566
|
// Gallery: items + label bridge zipped per item; Asset urls
|
|
1017
1567
|
// resolved into a flat shape the storefront can render directly.
|
|
1018
|
-
|
|
1019
|
-
|
|
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);
|
|
1020
1586
|
const galleryAssetsById = new Map();
|
|
1021
1587
|
if (galleryAssetIds.length > 0) {
|
|
1022
1588
|
const galleryAssets = await this.#requireAssets().findByIds(galleryAssetIds);
|
|
1023
1589
|
for (const a of galleryAssets)
|
|
1024
1590
|
galleryAssetsById.set(a.id, a);
|
|
1025
1591
|
}
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
const
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
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);
|
|
1035
1601
|
// Attachments + their types, eager-loaded in two queries.
|
|
1036
|
-
|
|
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));
|
|
1037
1609
|
const attachmentTypeIds = [...new Set(attachmentRows.map((a) => a.attachmentTypeId))];
|
|
1038
1610
|
const attachmentTypesById = new Map();
|
|
1039
1611
|
if (attachmentTypeIds.length > 0) {
|
|
@@ -1048,19 +1620,51 @@ export class CatalogQueryService {
|
|
|
1048
1620
|
for (const a of aAssets)
|
|
1049
1621
|
attachmentAssetsById.set(a.id, a);
|
|
1050
1622
|
}
|
|
1051
|
-
const descriptionText = this.pickLang(product.description, ctx.preferredLanguage, channel);
|
|
1052
|
-
|
|
1623
|
+
const descriptionText = effectiveSystemText(overrides, 'description', overrideCtx, product.description, this.pickLang(product.description, ctx.preferredLanguage, channel));
|
|
1624
|
+
// The summary's name went through the same resolution.
|
|
1625
|
+
const nameText = summary.name;
|
|
1626
|
+
// Issue #384 — channel-scoped user attributes carry their override for
|
|
1627
|
+
// this (channel, language); the scope lookup runs only when the product
|
|
1628
|
+
// has a user-attribute override row at all. The attribute views are read
|
|
1629
|
+
// at most once for this page, and only by whichever step needs them first.
|
|
1630
|
+
let attributeViews;
|
|
1631
|
+
const listAttributeViews = () => (attributeViews ??= this.#requireAttributeRead().listAll());
|
|
1632
|
+
const attributeValues = await effectiveAttributeValues(product.attributeValues ?? {}, overrides, overrideCtx, async () => new Map((await listAttributeViews()).map((a) => [
|
|
1633
|
+
a.key,
|
|
1634
|
+
{ channelScoped: a.channelScoped, languageScoped: a.languageScoped },
|
|
1635
|
+
])));
|
|
1053
1636
|
// Feature 012 / FR-030 — "Parametry produktu" tab projection.
|
|
1054
1637
|
// Resolve every attribute that is flagged isVisibleOnProductPage
|
|
1055
1638
|
// AND has a non-empty value on this product. Render the value per
|
|
1056
1639
|
// the active locale (option label for select / enum / multiselect,
|
|
1057
1640
|
// formatted scalar otherwise). Sorted by AttributeSetAttribute
|
|
1058
1641
|
// position when assigned, by attribute key otherwise.
|
|
1059
|
-
const visibleAttributes = await this.buildVisibleAttributesProjection(em, product, ctx.preferredLanguage, channel);
|
|
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;
|
|
1060
1664
|
const detail = {
|
|
1061
1665
|
...summary,
|
|
1062
1666
|
description: descriptionText,
|
|
1063
|
-
attributeValues: this.coerceAttributeValues(
|
|
1667
|
+
attributeValues: this.coerceAttributeValues(attributeValues),
|
|
1064
1668
|
assets: assets.map((a) => ({
|
|
1065
1669
|
id: a.id,
|
|
1066
1670
|
kind: a.kind,
|
|
@@ -1071,7 +1675,6 @@ export class CatalogQueryService {
|
|
|
1071
1675
|
id: v.id,
|
|
1072
1676
|
sku: v.sku,
|
|
1073
1677
|
variantAttributeValues: v.variantAttributeValues,
|
|
1074
|
-
priceOverride: v.priceOverride != null ? Number(v.priceOverride) : null,
|
|
1075
1678
|
stockLevel: v.stockLevel ?? null,
|
|
1076
1679
|
})),
|
|
1077
1680
|
categories: categories.map((c) => ({
|
|
@@ -1079,34 +1682,14 @@ export class CatalogQueryService {
|
|
|
1079
1682
|
name: this.pickLang(c.name, ctx.preferredLanguage, channel),
|
|
1080
1683
|
slug: c.slug,
|
|
1081
1684
|
})),
|
|
1685
|
+
paths: this.#pagePaths(product, scopeRows, ctx, keysByLanguage),
|
|
1082
1686
|
seo: {
|
|
1083
|
-
metaTitle:
|
|
1084
|
-
metaDescription:
|
|
1687
|
+
metaTitle: seoMeta.title,
|
|
1688
|
+
metaDescription: seoMeta.description,
|
|
1085
1689
|
openGraph: {
|
|
1086
|
-
title:
|
|
1087
|
-
description:
|
|
1088
|
-
|
|
1089
|
-
// then primaryAssetUrl). Base Image is the marketer's hero
|
|
1090
|
-
// shot, so social shares should land on it.
|
|
1091
|
-
imageUrl: (() => {
|
|
1092
|
-
const base = galleryItems
|
|
1093
|
-
.map((g) => ({
|
|
1094
|
-
asset: galleryAssetsById.get(g.assetId) ?? null,
|
|
1095
|
-
labels: labelsByItem.get(g.id) ?? [],
|
|
1096
|
-
}))
|
|
1097
|
-
.find((g) => g.asset && g.labels.includes('base_image'));
|
|
1098
|
-
if (base?.asset)
|
|
1099
|
-
return base.asset.storageUrl;
|
|
1100
|
-
const thumb = galleryItems
|
|
1101
|
-
.map((g) => ({
|
|
1102
|
-
asset: galleryAssetsById.get(g.assetId) ?? null,
|
|
1103
|
-
labels: labelsByItem.get(g.id) ?? [],
|
|
1104
|
-
}))
|
|
1105
|
-
.find((g) => g.asset && g.labels.includes('thumbnail'));
|
|
1106
|
-
if (thumb?.asset)
|
|
1107
|
-
return thumb.asset.storageUrl;
|
|
1108
|
-
return summary.primaryAssetUrl;
|
|
1109
|
-
})(),
|
|
1690
|
+
title: seoMeta.ogTitle,
|
|
1691
|
+
description: seoMeta.ogDescription,
|
|
1692
|
+
imageUrl: seoMeta.ogImageUrl,
|
|
1110
1693
|
},
|
|
1111
1694
|
},
|
|
1112
1695
|
structuredDataJsonLd: {
|
|
@@ -1138,15 +1721,16 @@ export class CatalogQueryService {
|
|
|
1138
1721
|
}
|
|
1139
1722
|
: {}),
|
|
1140
1723
|
gallery: galleryItems.flatMap((g) => {
|
|
1141
|
-
const a = galleryAssetsById.get(g.assetId);
|
|
1724
|
+
const a = galleryAssetsById.get(g.item.assetId);
|
|
1142
1725
|
if (!a)
|
|
1143
1726
|
return [];
|
|
1144
1727
|
return [
|
|
1145
1728
|
{
|
|
1146
1729
|
id: g.id,
|
|
1147
|
-
position: g.position,
|
|
1148
|
-
labels: [...
|
|
1730
|
+
position: g.item.position,
|
|
1731
|
+
labels: [...g.labels].sort(),
|
|
1149
1732
|
asset: { id: a.id, kind: a.kind, url: a.storageUrl },
|
|
1733
|
+
altText: altTextOf(g.item, a),
|
|
1150
1734
|
},
|
|
1151
1735
|
];
|
|
1152
1736
|
}),
|
|
@@ -1159,8 +1743,9 @@ export class CatalogQueryService {
|
|
|
1159
1743
|
{
|
|
1160
1744
|
id: row.id,
|
|
1161
1745
|
position: row.position,
|
|
1162
|
-
|
|
1163
|
-
|
|
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,
|
|
1164
1749
|
type: { id: t.id, code: t.code, name: t.name },
|
|
1165
1750
|
asset: {
|
|
1166
1751
|
id: a.id,
|
|
@@ -1255,10 +1840,13 @@ export class CatalogQueryService {
|
|
|
1255
1840
|
if (packagingUnits.length > 0) {
|
|
1256
1841
|
detail.packagingUnits = packagingUnits.map((u) => ({
|
|
1257
1842
|
id: u.id,
|
|
1258
|
-
name
|
|
1843
|
+
// Feature 163 (FR-079) — the name at the scope language, else the global name.
|
|
1844
|
+
name: effectivePackagingUnitName(u, scopeLanguage),
|
|
1259
1845
|
baseQuantity: u.baseQuantity,
|
|
1260
1846
|
position: u.position,
|
|
1261
1847
|
isDefault: u.isDefault,
|
|
1848
|
+
// Feature 155 (FR-016) — the unit's own minimum; `null` = none.
|
|
1849
|
+
minOrderUnits: u.minOrderUnits ?? null,
|
|
1262
1850
|
}));
|
|
1263
1851
|
}
|
|
1264
1852
|
}
|
|
@@ -1275,19 +1863,29 @@ export class CatalogQueryService {
|
|
|
1275
1863
|
const result = new Map();
|
|
1276
1864
|
if (ids.length === 0)
|
|
1277
1865
|
return result;
|
|
1278
|
-
|
|
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));
|
|
1279
1872
|
// Primary asset url via gallery thumb chain -> base_image -> first item
|
|
1280
1873
|
// -> legacy product_assets first row. One helper, shared with `toSummary`
|
|
1281
1874
|
// and `ProductLinkService`, so the chain and the port call have one home.
|
|
1282
|
-
const assetUrlByProduct = await resolvePrimaryAssetUrls(em, this.#requireAssets(), ids);
|
|
1875
|
+
const assetUrlByProduct = await resolvePrimaryAssetUrls(em, this.#requireAssets(), ids, channel.id);
|
|
1283
1876
|
const resolvedPrices = await this.#listingPricesFor(products, ctx);
|
|
1877
|
+
// Issue #384 — one statement for every child's override rows on this channel.
|
|
1878
|
+
const overridesByProduct = await loadChannelOverridesByProduct(em, ids, channel.id);
|
|
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);
|
|
1284
1882
|
for (const p of products) {
|
|
1285
1883
|
const price = this.#summaryPrice(resolvedPrices, p.id);
|
|
1286
1884
|
result.set(p.id, {
|
|
1287
1885
|
id: p.id,
|
|
1288
1886
|
sku: p.sku,
|
|
1289
|
-
slug: p.slug,
|
|
1290
|
-
name: this.pickLang(p.name, ctx.preferredLanguage, channel),
|
|
1887
|
+
slug: effectiveKeys.get(p.id) ?? p.slug,
|
|
1888
|
+
name: effectiveSystemText(overridesByProduct.get(p.id), 'name', overrideCtx, p.name, this.pickLang(p.name, ctx.preferredLanguage, channel)),
|
|
1291
1889
|
primaryAssetUrl: assetUrlByProduct.get(p.id) ?? null,
|
|
1292
1890
|
price,
|
|
1293
1891
|
});
|
|
@@ -1305,7 +1903,7 @@ export class CatalogQueryService {
|
|
|
1305
1903
|
// roots seed the walk.
|
|
1306
1904
|
const rows = await em.find(Category, { deletedAt: null, isActive: true }, { orderBy: { sortOrder: 'asc' } });
|
|
1307
1905
|
// Directly-assigned products per category that this caller may see.
|
|
1308
|
-
const directSets = await this.directProductSetsByCategory(em, channel, ctx
|
|
1906
|
+
const directSets = await this.directProductSetsByCategory(em, channel, this.#availabilityScope(ctx));
|
|
1309
1907
|
const byParent = new Map();
|
|
1310
1908
|
for (const row of rows) {
|
|
1311
1909
|
const key = row.parentCategoryId ?? null;
|
|
@@ -1408,13 +2006,29 @@ export class CatalogQueryService {
|
|
|
1408
2006
|
const em = this.emFactory();
|
|
1409
2007
|
const channel = ctx.resolvedChannel;
|
|
1410
2008
|
const attrs = await this.#requireAttributeRead().listByFlag('isFilterable');
|
|
1411
|
-
// Build option / range facets by scanning Products in the
|
|
1412
|
-
|
|
1413
|
-
const visibleIds = await this.filterByChannel(products.map((p) => p.id), channel);
|
|
1414
|
-
// 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
|
|
1415
2011
|
// catalogue holding two brass products the caller may see is the third
|
|
1416
|
-
// one, named by arithmetic
|
|
1417
|
-
|
|
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
|
+
}
|
|
1418
2032
|
const definitions = attrs.map((a) => {
|
|
1419
2033
|
const label = this.pickLang(a.label, ctx.preferredLanguage, channel);
|
|
1420
2034
|
const def = {
|
|
@@ -1430,7 +2044,7 @@ export class CatalogQueryService {
|
|
|
1430
2044
|
a.valueType === 'string') {
|
|
1431
2045
|
const optionCounts = new Map();
|
|
1432
2046
|
for (const p of visible) {
|
|
1433
|
-
const v = p.
|
|
2047
|
+
const v = valuesOf.get(p.id)?.[a.key];
|
|
1434
2048
|
if (v === undefined || v === null)
|
|
1435
2049
|
continue;
|
|
1436
2050
|
// multiselect carries an array of selected option values.
|
|
@@ -1455,7 +2069,7 @@ export class CatalogQueryService {
|
|
|
1455
2069
|
let min;
|
|
1456
2070
|
let max;
|
|
1457
2071
|
for (const p of visible) {
|
|
1458
|
-
const raw = p.
|
|
2072
|
+
const raw = valuesOf.get(p.id)?.[a.key];
|
|
1459
2073
|
const n = typeof raw === 'number' ? raw : Number(raw);
|
|
1460
2074
|
if (!Number.isFinite(n))
|
|
1461
2075
|
continue;
|
|
@@ -1550,8 +2164,11 @@ export class CatalogQueryService {
|
|
|
1550
2164
|
* Sorted by AttributeSetAttribute.position when the product has an
|
|
1551
2165
|
* Attribute Set, else by attribute key ASC for determinism.
|
|
1552
2166
|
*/
|
|
1553
|
-
async buildVisibleAttributesProjection(em, product,
|
|
1554
|
-
|
|
2167
|
+
async buildVisibleAttributesProjection(em, product,
|
|
2168
|
+
/** The product's effective attribute values for the request (issue #384). */
|
|
2169
|
+
values, preferredLanguage, channel,
|
|
2170
|
+
/** The page's attribute-view read, shared with the override step (issue #384). */
|
|
2171
|
+
listAttributeViews) {
|
|
1555
2172
|
const valueKeys = Object.keys(values).filter((k) => {
|
|
1556
2173
|
const v = values[k];
|
|
1557
2174
|
return v !== undefined && v !== null && v !== '';
|
|
@@ -1560,7 +2177,7 @@ export class CatalogQueryService {
|
|
|
1560
2177
|
return [];
|
|
1561
2178
|
// Feature 061 — attribute metadata + options come from the composed view.
|
|
1562
2179
|
const valueKeySet = new Set(valueKeys);
|
|
1563
|
-
const allViews = await
|
|
2180
|
+
const allViews = await listAttributeViews();
|
|
1564
2181
|
const attrs = allViews.filter((a) => valueKeySet.has(a.key) && a.isVisibleOnProductPage);
|
|
1565
2182
|
if (attrs.length === 0)
|
|
1566
2183
|
return [];
|
|
@@ -1629,11 +2246,6 @@ export class CatalogQueryService {
|
|
|
1629
2246
|
});
|
|
1630
2247
|
return items;
|
|
1631
2248
|
}
|
|
1632
|
-
/** Cached per-call list of attribute keys that should match free-text search. */
|
|
1633
|
-
async searchableAttributeKeys(_em) {
|
|
1634
|
-
const attrs = await this.#requireAttributeRead().listByFlag('isSearchable');
|
|
1635
|
-
return attrs.map((a) => a.key);
|
|
1636
|
-
}
|
|
1637
2249
|
/**
|
|
1638
2250
|
* Feature 007 — list of attribute keys flagged `is_comparable=true`,
|
|
1639
2251
|
* sorted alphabetically. Consumed by the comparisons module's
|
|
@@ -1689,80 +2301,83 @@ export class CatalogQueryService {
|
|
|
1689
2301
|
options,
|
|
1690
2302
|
};
|
|
1691
2303
|
}
|
|
1692
|
-
/**
|
|
1693
|
-
* Build a MikroORM where-clause for "attributeValues[key] contains query
|
|
1694
|
-
* (case-insensitive)". MikroORM doesn't have a first-class JSONB query
|
|
1695
|
-
* helper for the `->>` operator, so we use `$jsonb` style by selecting the
|
|
1696
|
-
* value via the operators object.
|
|
1697
|
-
*/
|
|
1698
|
-
searchableJsonbClause(key, query) {
|
|
1699
|
-
// expr` returns the property at `key` cast to text; ILIKE handles
|
|
1700
|
-
// case-insensitivity. We rely on MikroORM's `raw()` operator-form passed
|
|
1701
|
-
// through to Knex.
|
|
1702
|
-
return { [key]: { $ilike: `%${query}%` } };
|
|
1703
|
-
}
|
|
1704
|
-
orderForSort(sort) {
|
|
1705
|
-
switch (sort) {
|
|
1706
|
-
case 'name':
|
|
1707
|
-
return { slug: 'asc', id: 'asc' };
|
|
1708
|
-
case '-name':
|
|
1709
|
-
return { slug: 'desc', id: 'desc' };
|
|
1710
|
-
case '-createdAt':
|
|
1711
|
-
case 'relevance':
|
|
1712
|
-
default:
|
|
1713
|
-
return { createdAt: 'desc', id: 'desc' };
|
|
1714
|
-
}
|
|
1715
|
-
}
|
|
1716
2304
|
/**
|
|
1717
2305
|
* The keyset a listing pages by — **derived from the ordering it serves**,
|
|
1718
|
-
* never assumed.
|
|
1719
|
-
*
|
|
1720
|
-
*
|
|
1721
|
-
*
|
|
1722
|
-
* come apart: the `after` predicate was written over `created_at` whatever the
|
|
1723
|
-
* ordering, so under `sort=name` — which orders by `slug` — it excluded the
|
|
1724
|
-
* rows *newer* than the last one served instead of the rows already served.
|
|
1725
|
-
* That set has no relation to the page, so the walk both repeats products and
|
|
1726
|
-
* never reaches the ones between the repeats:
|
|
1727
|
-
* `?q=…&sort=name&minPrice=0&maxPrice=100000&limit=3` served
|
|
1728
|
-
* `[A, B, A]` on one page and then re-issued a cursor pointing at `B`.
|
|
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.
|
|
1729
2310
|
*
|
|
1730
|
-
*
|
|
1731
|
-
*
|
|
1732
|
-
*
|
|
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`.
|
|
1733
2314
|
*/
|
|
1734
|
-
keysetFor(sort) {
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
// anyway because the ordering names it, and a keyset that drops a column
|
|
1740
|
-
// its ordering carries is the defect above in miniature.
|
|
1741
|
-
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);
|
|
1742
2320
|
return {
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
? { 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'] }
|
|
1748
2325
|
: null,
|
|
1749
|
-
after: (cursor) =>
|
|
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 }),
|
|
1750
2334
|
};
|
|
1751
2335
|
}
|
|
1752
2336
|
// The default ordering is `createdAt desc, id desc`, in every sort that
|
|
1753
|
-
// reaches here
|
|
1754
|
-
// one is — it has nothing to read.
|
|
2337
|
+
// reaches here.
|
|
1755
2338
|
return {
|
|
2339
|
+
byName: false,
|
|
1756
2340
|
of: (product) => ({ createdAt: product.createdAt.toISOString(), id: product.id }),
|
|
2341
|
+
// The id is compared with a uuid column: a cursor naming anything else is
|
|
2342
|
+
// discarded here rather than refused by the database as a 500.
|
|
1757
2343
|
parse: (decoded) => isRecord(decoded) &&
|
|
1758
2344
|
typeof decoded['createdAt'] === 'string' &&
|
|
1759
|
-
|
|
2345
|
+
isUuidText(decoded['id']) &&
|
|
1760
2346
|
!Number.isNaN(new Date(decoded['createdAt']).getTime())
|
|
1761
2347
|
? { createdAt: decoded['createdAt'], id: decoded['id'] }
|
|
1762
2348
|
: null,
|
|
1763
2349
|
after: (cursor) => afterKeysetCursor(cursor, '$lt'),
|
|
2350
|
+
orderBy: () => ({ createdAt: 'desc', id: 'desc' }),
|
|
1764
2351
|
};
|
|
1765
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
|
+
}
|
|
1766
2381
|
async filterByChannel(productIds, channel) {
|
|
1767
2382
|
if (productIds.length === 0)
|
|
1768
2383
|
return new Set();
|
|
@@ -1816,26 +2431,24 @@ export class CatalogQueryService {
|
|
|
1816
2431
|
* (i.e. via a `product_categories` row). Subtree roll-up to ancestors is
|
|
1817
2432
|
* done by the caller, which has the parent map to walk.
|
|
1818
2433
|
*/
|
|
1819
|
-
async directProductSetsByCategory(em, channel,
|
|
2434
|
+
async directProductSetsByCategory(em, channel, scope) {
|
|
1820
2435
|
const base = await em.execute(`select category_id, product_id from product_categories`);
|
|
1821
2436
|
if (base.length === 0)
|
|
1822
2437
|
return new Map();
|
|
1823
2438
|
// Channel membership.
|
|
1824
|
-
const
|
|
1825
|
-
// Issue #227 — and
|
|
1826
|
-
// path never loaded: `product_categories` carries ids and nothing
|
|
1827
|
-
// the rows come back here rather than the predicate going down
|
|
1828
|
-
// category tree publishes a `productCount` per node, and a count
|
|
1829
|
-
// one field a restricted product can
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
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);
|
|
1833
2448
|
const sets = new Map();
|
|
1834
2449
|
for (const row of base) {
|
|
1835
2450
|
if (!visibleIds.has(row.product_id))
|
|
1836
2451
|
continue;
|
|
1837
|
-
if (restricted.has(row.product_id))
|
|
1838
|
-
continue;
|
|
1839
2452
|
let set = sets.get(row.category_id);
|
|
1840
2453
|
if (!set) {
|
|
1841
2454
|
set = new Set();
|
|
@@ -1862,23 +2475,67 @@ export class CatalogQueryService {
|
|
|
1862
2475
|
*/
|
|
1863
2476
|
toSummary(product, channel, preferredLanguage, resolvedPrices, cardReads) {
|
|
1864
2477
|
// Price — the pricing engine's answer for this product on this channel
|
|
1865
|
-
// (issue #132), read out of the page's resolution
|
|
1866
|
-
//
|
|
1867
|
-
// underneath is one a price list stands behind rather than the catalogue's
|
|
1868
|
-
// 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.
|
|
1869
2480
|
const price = this.#summaryPrice(resolvedPrices, product.id);
|
|
1870
|
-
|
|
2481
|
+
// Issue #384 — the channel's override when one applies, else the baseline
|
|
2482
|
+
// language pick, out of the page's pre-read override rows.
|
|
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));
|
|
1871
2487
|
return {
|
|
1872
2488
|
id: product.id,
|
|
1873
2489
|
sku: product.sku,
|
|
1874
2490
|
type: product.type,
|
|
1875
2491
|
name: nameText,
|
|
1876
|
-
|
|
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),
|
|
1877
2495
|
categorySlugs: cardReads.categorySlugsByProduct.get(product.id) ?? [],
|
|
1878
2496
|
primaryAssetUrl: cardReads.assetUrlByProduct.get(product.id) ?? null,
|
|
1879
2497
|
price,
|
|
1880
2498
|
stockIndicator: null,
|
|
1881
2499
|
stockLevel: null,
|
|
2500
|
+
// Feature 155 (FR-014) — emitted for the types the minimum applies to only.
|
|
2501
|
+
// Feature 163 (FR-100) — the request channel's minimum.
|
|
2502
|
+
minOrderQuantity: isOrderMinimumEligibleType(product.type)
|
|
2503
|
+
? (cardReads.minOrderQuantityByProduct.has(product.id)
|
|
2504
|
+
? (cardReads.minOrderQuantityByProduct.get(product.id) ?? null)
|
|
2505
|
+
: (product.minOrderQuantity ?? null))
|
|
2506
|
+
: null,
|
|
2507
|
+
resolvedPrice: this.#summaryResolvedPrice(resolvedPrices, product.id),
|
|
2508
|
+
...this.#summaryPriceBookFields(resolvedPrices, product.id),
|
|
2509
|
+
};
|
|
2510
|
+
}
|
|
2511
|
+
/**
|
|
2512
|
+
* Feature 160 (FR-024, FR-025) — the compare-at price of a charged sale and
|
|
2513
|
+
* the "from" flag of a product whose variants differ, from the same
|
|
2514
|
+
* resolution as `price`. Present only when the price books answered them.
|
|
2515
|
+
*/
|
|
2516
|
+
#summaryPriceBookFields(resolved, productId) {
|
|
2517
|
+
const price = resolved.get(productId)?.price;
|
|
2518
|
+
if (!price || price.source !== 'price_list')
|
|
2519
|
+
return {};
|
|
2520
|
+
const compareAt = price.compareAtAmount !== undefined ? Number(price.compareAtAmount) : null;
|
|
2521
|
+
return {
|
|
2522
|
+
...(compareAt !== null && Number.isFinite(compareAt)
|
|
2523
|
+
? { compareAtPrice: { amount: compareAt, currency: price.currency } }
|
|
2524
|
+
: {}),
|
|
2525
|
+
...(price.variesByVariant ? { priceVariesByVariant: true } : {}),
|
|
2526
|
+
};
|
|
2527
|
+
}
|
|
2528
|
+
/**
|
|
2529
|
+
* Issue #384 — the language chain an override is walked over: exactly the
|
|
2530
|
+
* legs `pickLang` walks over the baseline (request language, channel
|
|
2531
|
+
* default, `en-US`, `en`), so a (channel, language) override answers for
|
|
2532
|
+
* whichever language the baseline text would have come from and never for
|
|
2533
|
+
* a later one.
|
|
2534
|
+
*/
|
|
2535
|
+
#overrideContext(channel, preferredLanguage) {
|
|
2536
|
+
return {
|
|
2537
|
+
channelId: channel.id,
|
|
2538
|
+
languages: overrideLanguages(preferredLanguage, channel.defaultLanguage),
|
|
1882
2539
|
};
|
|
1883
2540
|
}
|
|
1884
2541
|
pickLang(blob, preferred, channel) {
|