@endora-commerce/mod-catalog 0.108.0 → 0.110.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/components/CopyToChannelsDialog.d.ts +37 -0
- package/dist/admin/components/CopyToChannelsDialog.d.ts.map +1 -0
- package/dist/admin/components/CopyToChannelsDialog.js +83 -0
- package/dist/admin/components/CopyToChannelsDialog.js.map +1 -0
- package/dist/admin/components/PackagingUnitsEditor.d.ts +16 -1
- package/dist/admin/components/PackagingUnitsEditor.d.ts.map +1 -1
- package/dist/admin/components/PackagingUnitsEditor.js +20 -14
- package/dist/admin/components/PackagingUnitsEditor.js.map +1 -1
- package/dist/admin/components/ProductAttachmentsSection.d.ts +3 -0
- package/dist/admin/components/ProductAttachmentsSection.d.ts.map +1 -0
- package/dist/admin/components/ProductAttachmentsSection.js +98 -0
- package/dist/admin/components/ProductAttachmentsSection.js.map +1 -0
- package/dist/admin/components/ProductAttributesTab.d.ts +1 -11
- package/dist/admin/components/ProductAttributesTab.d.ts.map +1 -1
- package/dist/admin/components/ProductAttributesTab.js +128 -119
- package/dist/admin/components/ProductAttributesTab.js.map +1 -1
- package/dist/admin/components/ProductContentCard.d.ts +41 -0
- package/dist/admin/components/ProductContentCard.d.ts.map +1 -0
- package/dist/admin/components/ProductContentCard.js +28 -0
- package/dist/admin/components/ProductContentCard.js.map +1 -0
- package/dist/admin/components/ProductGallerySection.d.ts +3 -0
- package/dist/admin/components/ProductGallerySection.d.ts.map +1 -0
- package/dist/admin/components/ProductGallerySection.js +129 -0
- package/dist/admin/components/ProductGallerySection.js.map +1 -0
- package/dist/admin/components/ProductOrderRulesCard.d.ts +11 -15
- package/dist/admin/components/ProductOrderRulesCard.d.ts.map +1 -1
- package/dist/admin/components/ProductOrderRulesCard.js +15 -140
- package/dist/admin/components/ProductOrderRulesCard.js.map +1 -1
- package/dist/admin/components/ProductScopeBar.d.ts +28 -0
- package/dist/admin/components/ProductScopeBar.d.ts.map +1 -0
- package/dist/admin/components/ProductScopeBar.js +70 -0
- package/dist/admin/components/ProductScopeBar.js.map +1 -0
- package/dist/admin/components/ProductScopeOverview.d.ts +38 -0
- package/dist/admin/components/ProductScopeOverview.d.ts.map +1 -0
- package/dist/admin/components/ProductScopeOverview.js +222 -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/ProductUrlRedirects.d.ts +15 -0
- package/dist/admin/components/ProductUrlRedirects.d.ts.map +1 -0
- package/dist/admin/components/ProductUrlRedirects.js +70 -0
- package/dist/admin/components/ProductUrlRedirects.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 +288 -133
- package/dist/admin/components/ProductsBulkEditDialog.js.map +1 -1
- package/dist/admin/components/editor/DetailsTab.d.ts +30 -0
- package/dist/admin/components/editor/DetailsTab.d.ts.map +1 -0
- package/dist/admin/components/editor/DetailsTab.js +59 -0
- package/dist/admin/components/editor/DetailsTab.js.map +1 -0
- package/dist/admin/components/editor/ImmediateBadge.d.ts +21 -0
- package/dist/admin/components/editor/ImmediateBadge.d.ts.map +1 -0
- package/dist/admin/components/editor/ImmediateBadge.js +21 -0
- package/dist/admin/components/editor/ImmediateBadge.js.map +1 -0
- package/dist/admin/components/editor/confirm-removal.d.ts +13 -0
- package/dist/admin/components/editor/confirm-removal.d.ts.map +1 -0
- package/dist/admin/components/editor/confirm-removal.js +33 -0
- package/dist/admin/components/editor/confirm-removal.js.map +1 -0
- package/dist/admin/components/editor/editor-context.d.ts +53 -0
- package/dist/admin/components/editor/editor-context.d.ts.map +1 -0
- package/dist/admin/components/editor/editor-context.js +88 -0
- package/dist/admin/components/editor/editor-context.js.map +1 -0
- package/dist/admin/components/editor/scoped-controls.d.ts +46 -0
- package/dist/admin/components/editor/scoped-controls.d.ts.map +1 -0
- package/dist/admin/components/editor/scoped-controls.js +64 -0
- package/dist/admin/components/editor/scoped-controls.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 +20 -0
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/lib/attribute-scope.d.ts +23 -0
- package/dist/admin/lib/attribute-scope.d.ts.map +1 -0
- package/dist/admin/lib/attribute-scope.js +21 -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/editor-scope.d.ts +35 -0
- package/dist/admin/lib/editor-scope.d.ts.map +1 -0
- package/dist/admin/lib/editor-scope.js +114 -0
- package/dist/admin/lib/editor-scope.js.map +1 -0
- package/dist/admin/lib/order-minimum-input.d.ts +13 -0
- package/dist/admin/lib/order-minimum-input.d.ts.map +1 -0
- package/dist/admin/lib/order-minimum-input.js +16 -0
- package/dist/admin/lib/order-minimum-input.js.map +1 -0
- package/dist/admin/lib/product-labels.d.ts +12 -0
- package/dist/admin/lib/product-labels.d.ts.map +1 -0
- package/dist/admin/lib/product-labels.js +23 -0
- package/dist/admin/lib/product-labels.js.map +1 -0
- package/dist/admin/lib/product-scopes-api.d.ts +23 -0
- package/dist/admin/lib/product-scopes-api.d.ts.map +1 -0
- package/dist/admin/lib/product-scopes-api.js +57 -0
- package/dist/admin/lib/product-scopes-api.js.map +1 -0
- package/dist/admin/lib/product-url-keys-api.d.ts +23 -0
- package/dist/admin/lib/product-url-keys-api.d.ts.map +1 -0
- package/dist/admin/lib/product-url-keys-api.js +61 -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 +73 -0
- package/dist/admin/lib/scope-overview.d.ts.map +1 -0
- package/dist/admin/lib/scope-overview.js +178 -0
- package/dist/admin/lib/scope-overview.js.map +1 -0
- package/dist/admin/lib/scoped-editor-store.d.ts +81 -0
- package/dist/admin/lib/scoped-editor-store.d.ts.map +1 -0
- package/dist/admin/lib/scoped-editor-store.js +198 -0
- package/dist/admin/lib/scoped-editor-store.js.map +1 -0
- package/dist/admin/lib/scoped-values-api.d.ts +14 -0
- package/dist/admin/lib/scoped-values-api.d.ts.map +1 -0
- package/dist/admin/lib/scoped-values-api.js +55 -0
- package/dist/admin/lib/scoped-values-api.js.map +1 -0
- package/dist/admin/pages/AttributesManager.d.ts.map +1 -1
- package/dist/admin/pages/AttributesManager.js +186 -28
- 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/ProductContentPage.d.ts +27 -0
- package/dist/admin/pages/ProductContentPage.d.ts.map +1 -0
- package/dist/admin/pages/ProductContentPage.js +161 -0
- package/dist/admin/pages/ProductContentPage.js.map +1 -0
- package/dist/admin/pages/ProductCreateForm.d.ts +3 -0
- package/dist/admin/pages/ProductCreateForm.d.ts.map +1 -0
- package/dist/admin/pages/ProductCreateForm.js +87 -0
- package/dist/admin/pages/ProductCreateForm.js.map +1 -0
- 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 +878 -627
- 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 +111 -54
- package/dist/admin/pages/ProductsList.js.map +1 -1
- package/dist/backend/admin-search-provider.d.ts +3 -2
- package/dist/backend/admin-search-provider.d.ts.map +1 -1
- package/dist/backend/admin-search-provider.js +2 -3
- package/dist/backend/admin-search-provider.js.map +1 -1
- package/dist/backend/commands/attribute-commands.d.ts +4 -3
- package/dist/backend/commands/attribute-commands.d.ts.map +1 -1
- package/dist/backend/commands/attribute-commands.js +82 -21
- package/dist/backend/commands/attribute-commands.js.map +1 -1
- package/dist/backend/commands/product-content-commands.d.ts +31 -0
- package/dist/backend/commands/product-content-commands.d.ts.map +1 -0
- package/dist/backend/commands/product-content-commands.js +70 -0
- package/dist/backend/commands/product-content-commands.js.map +1 -0
- package/dist/backend/commands/scoped-values.commands.d.ts +95 -0
- package/dist/backend/commands/scoped-values.commands.d.ts.map +1 -0
- package/dist/backend/commands/scoped-values.commands.js +235 -0
- package/dist/backend/commands/scoped-values.commands.js.map +1 -0
- package/dist/backend/demo/reset.d.ts.map +1 -1
- package/dist/backend/demo/reset.js +2 -1
- package/dist/backend/demo/reset.js.map +1 -1
- package/dist/backend/demo/rows.d.ts +25 -0
- package/dist/backend/demo/rows.d.ts.map +1 -1
- package/dist/backend/demo/rows.js +35 -12
- package/dist/backend/demo/rows.js.map +1 -1
- package/dist/backend/demo/seed.d.ts +2 -1
- package/dist/backend/demo/seed.d.ts.map +1 -1
- package/dist/backend/demo/seed.js +22 -8
- 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-scope-override.entity.d.ts +30 -0
- package/dist/backend/entities/gallery-item-scope-override.entity.d.ts.map +1 -0
- package/dist/backend/entities/gallery-item-scope-override.entity.js +80 -0
- package/dist/backend/entities/gallery-item-scope-override.entity.js.map +1 -0
- package/dist/backend/entities/gallery-item.entity.d.ts +9 -1
- package/dist/backend/entities/gallery-item.entity.d.ts.map +1 -1
- package/dist/backend/entities/gallery-item.entity.js +16 -0
- package/dist/backend/entities/gallery-item.entity.js.map +1 -1
- package/dist/backend/entities/gallery-role-scope-override.entity.d.ts +28 -0
- package/dist/backend/entities/gallery-role-scope-override.entity.d.ts.map +1 -0
- package/dist/backend/entities/gallery-role-scope-override.entity.js +75 -0
- package/dist/backend/entities/gallery-role-scope-override.entity.js.map +1 -0
- package/dist/backend/entities/product-attachment-scope-override.entity.d.ts +30 -0
- package/dist/backend/entities/product-attachment-scope-override.entity.d.ts.map +1 -0
- package/dist/backend/entities/product-attachment-scope-override.entity.js +80 -0
- package/dist/backend/entities/product-attachment-scope-override.entity.js.map +1 -0
- package/dist/backend/entities/product-attachment.entity.d.ts +6 -1
- package/dist/backend/entities/product-attachment.entity.d.ts.map +1 -1
- package/dist/backend/entities/product-attachment.entity.js +9 -0
- package/dist/backend/entities/product-attachment.entity.js.map +1 -1
- package/dist/backend/entities/product-attribute.entity.d.ts +5 -9
- package/dist/backend/entities/product-attribute.entity.d.ts.map +1 -1
- package/dist/backend/entities/product-attribute.entity.js +5 -13
- package/dist/backend/entities/product-attribute.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 +47 -0
- package/dist/backend/entities/product-channel-scope.entity.d.ts.map +1 -0
- package/dist/backend/entities/product-channel-scope.entity.js +113 -0
- package/dist/backend/entities/product-channel-scope.entity.js.map +1 -0
- package/dist/backend/entities/product-content-value.entity.d.ts +39 -0
- package/dist/backend/entities/product-content-value.entity.d.ts.map +1 -0
- package/dist/backend/entities/product-content-value.entity.js +81 -0
- package/dist/backend/entities/product-content-value.entity.js.map +1 -0
- package/dist/backend/entities/product-packaging-unit-scope-override.entity.d.ts +30 -0
- package/dist/backend/entities/product-packaging-unit-scope-override.entity.d.ts.map +1 -0
- package/dist/backend/entities/product-packaging-unit-scope-override.entity.js +80 -0
- package/dist/backend/entities/product-packaging-unit-scope-override.entity.js.map +1 -0
- package/dist/backend/entities/product-url-key.entity.d.ts +27 -0
- package/dist/backend/entities/product-url-key.entity.d.ts.map +1 -0
- package/dist/backend/entities/product-url-key.entity.js +70 -0
- package/dist/backend/entities/product-url-key.entity.js.map +1 -0
- package/dist/backend/entities/product-url-redirect.entity.d.ts +18 -0
- package/dist/backend/entities/product-url-redirect.entity.d.ts.map +1 -0
- package/dist/backend/entities/product-url-redirect.entity.js +57 -0
- package/dist/backend/entities/product-url-redirect.entity.js.map +1 -0
- package/dist/backend/entities/product-variant.entity.d.ts +8 -1
- package/dist/backend/entities/product-variant.entity.d.ts.map +1 -1
- package/dist/backend/entities/product-variant.entity.js +13 -2
- package/dist/backend/entities/product-variant.entity.js.map +1 -1
- package/dist/backend/entities/product.entity.d.ts +48 -16
- package/dist/backend/entities/product.entity.d.ts.map +1 -1
- package/dist/backend/entities/product.entity.js +65 -35
- package/dist/backend/entities/product.entity.js.map +1 -1
- package/dist/backend/index.d.ts +29 -2
- package/dist/backend/index.d.ts.map +1 -1
- package/dist/backend/index.js +311 -29
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/plugin.d.ts +79 -8
- package/dist/backend/plugin.d.ts.map +1 -1
- package/dist/backend/plugin.js +98 -17
- package/dist/backend/plugin.js.map +1 -1
- package/dist/backend/prompt-tools.d.ts +11 -0
- package/dist/backend/prompt-tools.d.ts.map +1 -1
- package/dist/backend/prompt-tools.js +124 -9
- package/dist/backend/prompt-tools.js.map +1 -1
- package/dist/backend/routes.admin.d.ts +42 -14
- package/dist/backend/routes.admin.d.ts.map +1 -1
- package/dist/backend/routes.admin.js +214 -134
- 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 +18 -3
- 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 +31 -7
- package/dist/backend/routes.public.d.ts.map +1 -1
- package/dist/backend/routes.public.js +114 -33
- 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.d.ts +12 -1
- package/dist/backend/services/asset-references.d.ts.map +1 -1
- package/dist/backend/services/asset-references.js +85 -32
- package/dist/backend/services/asset-references.js.map +1 -1
- package/dist/backend/services/attachment-packaging-scopes.d.ts +61 -0
- package/dist/backend/services/attachment-packaging-scopes.d.ts.map +1 -0
- package/dist/backend/services/attachment-packaging-scopes.js +98 -0
- package/dist/backend/services/attachment-packaging-scopes.js.map +1 -0
- package/dist/backend/services/attachment.service.d.ts +8 -1
- package/dist/backend/services/attachment.service.d.ts.map +1 -1
- package/dist/backend/services/attachment.service.js +105 -21
- package/dist/backend/services/attachment.service.js.map +1 -1
- package/dist/backend/services/attribute-filter-match.d.ts +14 -0
- package/dist/backend/services/attribute-filter-match.d.ts.map +1 -0
- package/dist/backend/services/attribute-filter-match.js +19 -0
- package/dist/backend/services/attribute-filter-match.js.map +1 -0
- package/dist/backend/services/attribute-scope-preview.d.ts +48 -0
- package/dist/backend/services/attribute-scope-preview.d.ts.map +1 -0
- package/dist/backend/services/attribute-scope-preview.js +76 -0
- package/dist/backend/services/attribute-scope-preview.js.map +1 -0
- package/dist/backend/services/attribute-set.service.d.ts +10 -1
- package/dist/backend/services/attribute-set.service.d.ts.map +1 -1
- package/dist/backend/services/attribute-set.service.js +30 -4
- package/dist/backend/services/attribute-set.service.js.map +1 -1
- package/dist/backend/services/attribute-type-mapping.d.ts +2 -2
- package/dist/backend/services/attribute-type-mapping.d.ts.map +1 -1
- package/dist/backend/services/attribute-type-mapping.js +6 -0
- package/dist/backend/services/attribute-type-mapping.js.map +1 -1
- package/dist/backend/services/attribute-usage.d.ts +31 -0
- package/dist/backend/services/attribute-usage.d.ts.map +1 -0
- package/dist/backend/services/attribute-usage.js +29 -0
- package/dist/backend/services/attribute-usage.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 +210 -37
- 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 +31 -3
- package/dist/backend/services/bundle.service.js.map +1 -1
- package/dist/backend/services/catalog-admin-search.service.d.ts +4 -3
- package/dist/backend/services/catalog-admin-search.service.d.ts.map +1 -1
- package/dist/backend/services/catalog-admin-search.service.js +7 -7
- package/dist/backend/services/catalog-admin-search.service.js.map +1 -1
- package/dist/backend/services/catalog-admin.service.d.ts +171 -27
- package/dist/backend/services/catalog-admin.service.d.ts.map +1 -1
- package/dist/backend/services/catalog-admin.service.js +634 -315
- package/dist/backend/services/catalog-admin.service.js.map +1 -1
- package/dist/backend/services/catalog-attribute-read.service.d.ts +14 -0
- package/dist/backend/services/catalog-attribute-read.service.d.ts.map +1 -1
- package/dist/backend/services/catalog-attribute-read.service.js +7 -19
- package/dist/backend/services/catalog-attribute-read.service.js.map +1 -1
- package/dist/backend/services/catalog-bulk-import.service.d.ts +72 -3
- package/dist/backend/services/catalog-bulk-import.service.d.ts.map +1 -1
- package/dist/backend/services/catalog-bulk-import.service.js +212 -38
- package/dist/backend/services/catalog-bulk-import.service.js.map +1 -1
- package/dist/backend/services/catalog-bulk-update.service.d.ts +35 -5
- package/dist/backend/services/catalog-bulk-update.service.d.ts.map +1 -1
- package/dist/backend/services/catalog-bulk-update.service.js +123 -14
- package/dist/backend/services/catalog-bulk-update.service.js.map +1 -1
- package/dist/backend/services/catalog-org-price-decorator.d.ts +12 -25
- package/dist/backend/services/catalog-org-price-decorator.d.ts.map +1 -1
- package/dist/backend/services/catalog-org-price-decorator.js +48 -13
- 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 +11 -1
- package/dist/backend/services/catalog-product-read.service.d.ts.map +1 -1
- package/dist/backend/services/catalog-product-read.service.js +40 -23
- package/dist/backend/services/catalog-product-read.service.js.map +1 -1
- package/dist/backend/services/catalog-query.service.d.ts +170 -42
- package/dist/backend/services/catalog-query.service.d.ts.map +1 -1
- package/dist/backend/services/catalog-query.service.js +797 -430
- 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 +53 -21
- package/dist/backend/services/catalog-quick-search.service.js.map +1 -1
- package/dist/backend/services/catalog-write-ports.d.ts +16 -1
- package/dist/backend/services/catalog-write-ports.d.ts.map +1 -1
- package/dist/backend/services/catalog-write-ports.js +18 -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 +32 -3
- 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/content-attribute-rules.d.ts +49 -0
- package/dist/backend/services/content-attribute-rules.d.ts.map +1 -0
- package/dist/backend/services/content-attribute-rules.js +89 -0
- package/dist/backend/services/content-attribute-rules.js.map +1 -0
- package/dist/backend/services/effective-value.sql.d.ts +42 -0
- package/dist/backend/services/effective-value.sql.d.ts.map +1 -0
- package/dist/backend/services/effective-value.sql.js +61 -0
- package/dist/backend/services/effective-value.sql.js.map +1 -0
- package/dist/backend/services/gallery-scopes.d.ts +63 -0
- package/dist/backend/services/gallery-scopes.d.ts.map +1 -0
- package/dist/backend/services/gallery-scopes.js +158 -0
- package/dist/backend/services/gallery-scopes.js.map +1 -0
- package/dist/backend/services/gallery.service.d.ts +32 -4
- package/dist/backend/services/gallery.service.d.ts.map +1 -1
- package/dist/backend/services/gallery.service.js +182 -44
- package/dist/backend/services/gallery.service.js.map +1 -1
- package/dist/backend/services/grouped.service.d.ts.map +1 -1
- package/dist/backend/services/grouped.service.js +13 -1
- package/dist/backend/services/grouped.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 +73 -47
- package/dist/backend/services/packaging-unit.service.js.map +1 -1
- package/dist/backend/services/page-builder-content.d.ts +64 -0
- package/dist/backend/services/page-builder-content.d.ts.map +1 -0
- package/dist/backend/services/page-builder-content.js +113 -0
- package/dist/backend/services/page-builder-content.js.map +1 -0
- package/dist/backend/services/primary-asset-url.d.ts +12 -1
- package/dist/backend/services/primary-asset-url.d.ts.map +1 -1
- package/dist/backend/services/primary-asset-url.js +50 -14
- package/dist/backend/services/primary-asset-url.js.map +1 -1
- package/dist/backend/services/product-availability.service.d.ts +92 -0
- package/dist/backend/services/product-availability.service.d.ts.map +1 -0
- package/dist/backend/services/product-availability.service.js +260 -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-content.service.d.ts +62 -0
- package/dist/backend/services/product-content.service.d.ts.map +1 -0
- package/dist/backend/services/product-content.service.js +122 -0
- package/dist/backend/services/product-content.service.js.map +1 -0
- package/dist/backend/services/product-editor-preferences.service.d.ts +6 -0
- package/dist/backend/services/product-editor-preferences.service.d.ts.map +1 -1
- package/dist/backend/services/product-editor-preferences.service.js +12 -0
- package/dist/backend/services/product-editor-preferences.service.js.map +1 -1
- package/dist/backend/services/product-global-field-rules.d.ts +39 -0
- package/dist/backend/services/product-global-field-rules.d.ts.map +1 -0
- package/dist/backend/services/product-global-field-rules.js +84 -0
- package/dist/backend/services/product-global-field-rules.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 +44 -36
- package/dist/backend/services/product-link.service.js.map +1 -1
- package/dist/backend/services/product-list-view-service.d.ts.map +1 -1
- package/dist/backend/services/product-list-view-service.js +5 -8
- package/dist/backend/services/product-list-view-service.js.map +1 -1
- package/dist/backend/services/product-page-revalidation.d.ts +60 -0
- package/dist/backend/services/product-page-revalidation.d.ts.map +1 -0
- package/dist/backend/services/product-page-revalidation.js +165 -0
- package/dist/backend/services/product-page-revalidation.js.map +1 -0
- package/dist/backend/services/product-scopes.service.d.ts +221 -0
- package/dist/backend/services/product-scopes.service.d.ts.map +1 -0
- package/dist/backend/services/product-scopes.service.js +692 -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 +2 -2
- package/dist/backend/services/product-value-resolver.service.d.ts.map +1 -1
- package/dist/backend/services/product-value-resolver.service.js +4 -7
- package/dist/backend/services/product-value-resolver.service.js.map +1 -1
- package/dist/backend/services/publication-window-sweep.d.ts +131 -0
- package/dist/backend/services/publication-window-sweep.d.ts.map +1 -0
- package/dist/backend/services/publication-window-sweep.js +204 -0
- package/dist/backend/services/publication-window-sweep.js.map +1 -0
- package/dist/backend/services/scheduled-work-probe.d.ts +34 -0
- package/dist/backend/services/scheduled-work-probe.d.ts.map +1 -0
- package/dist/backend/services/scheduled-work-probe.js +30 -0
- package/dist/backend/services/scheduled-work-probe.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 +173 -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 +329 -0
- package/dist/backend/services/scope-overview.service.js.map +1 -0
- package/dist/backend/services/scoped-store-adapters.d.ts +58 -0
- package/dist/backend/services/scoped-store-adapters.d.ts.map +1 -0
- package/dist/backend/services/scoped-store-adapters.js +92 -0
- package/dist/backend/services/scoped-store-adapters.js.map +1 -0
- package/dist/backend/services/scoped-values-global-only.d.ts +36 -0
- package/dist/backend/services/scoped-values-global-only.d.ts.map +1 -0
- package/dist/backend/services/scoped-values-global-only.js +92 -0
- package/dist/backend/services/scoped-values-global-only.js.map +1 -0
- package/dist/backend/services/scoped-values-import.d.ts +86 -0
- package/dist/backend/services/scoped-values-import.d.ts.map +1 -0
- package/dist/backend/services/scoped-values-import.js +320 -0
- package/dist/backend/services/scoped-values-import.js.map +1 -0
- package/dist/backend/services/scoped-values-read.service.d.ts +56 -0
- package/dist/backend/services/scoped-values-read.service.d.ts.map +1 -0
- package/dist/backend/services/scoped-values-read.service.js +289 -0
- package/dist/backend/services/scoped-values-read.service.js.map +1 -0
- package/dist/backend/services/scoped-values-save.service.d.ts +79 -0
- package/dist/backend/services/scoped-values-save.service.d.ts.map +1 -0
- package/dist/backend/services/scoped-values-save.service.js +675 -0
- package/dist/backend/services/scoped-values-save.service.js.map +1 -0
- package/dist/backend/services/scoped-values-state.d.ts +94 -0
- package/dist/backend/services/scoped-values-state.d.ts.map +1 -0
- package/dist/backend/services/scoped-values-state.js +159 -0
- package/dist/backend/services/scoped-values-state.js.map +1 -0
- package/dist/backend/services/scoped-values.service.d.ts +36 -0
- package/dist/backend/services/scoped-values.service.d.ts.map +1 -0
- package/dist/backend/services/scoped-values.service.js +92 -0
- package/dist/backend/services/scoped-values.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 +7 -8
- package/dist/backend/services/storefront-value-overrides.d.ts.map +1 -1
- package/dist/backend/services/storefront-value-overrides.js +11 -14
- package/dist/backend/services/storefront-value-overrides.js.map +1 -1
- package/dist/backend/services/url-key-resolution.service.d.ts +70 -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 +123 -0
- package/dist/backend/services/url-key.service.d.ts.map +1 -0
- package/dist/backend/services/url-key.service.js +566 -0
- package/dist/backend/services/url-key.service.js.map +1 -0
- package/dist/manifest.d.ts +9 -1
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +204 -10
- package/dist/manifest.js.map +1 -1
- 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/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/20261030T113855_catalog_scope_model_texts.d.ts +36 -0
- package/dist/migrations/20261030T113855_catalog_scope_model_texts.d.ts.map +1 -0
- package/dist/migrations/20261030T113855_catalog_scope_model_texts.js +225 -0
- package/dist/migrations/20261030T113855_catalog_scope_model_texts.js.map +1 -0
- package/dist/migrations/20261030T113859_catalog_scope_model_order_rules.d.ts +18 -0
- package/dist/migrations/20261030T113859_catalog_scope_model_order_rules.d.ts.map +1 -0
- package/dist/migrations/20261030T113859_catalog_scope_model_order_rules.js +39 -0
- package/dist/migrations/20261030T113859_catalog_scope_model_order_rules.js.map +1 -0
- package/dist/migrations/20261030T113904_catalog_scope_model_url_keys.d.ts +6 -0
- package/dist/migrations/20261030T113904_catalog_scope_model_url_keys.d.ts.map +1 -0
- package/dist/migrations/20261030T113904_catalog_scope_model_url_keys.js +119 -0
- package/dist/migrations/20261030T113904_catalog_scope_model_url_keys.js.map +1 -0
- package/dist/migrations/20261030T113908_catalog_scope_model_media.d.ts +6 -0
- package/dist/migrations/20261030T113908_catalog_scope_model_media.d.ts.map +1 -0
- package/dist/migrations/20261030T113908_catalog_scope_model_media.js +185 -0
- package/dist/migrations/20261030T113908_catalog_scope_model_media.js.map +1 -0
- package/dist/migrations/20261104T121504_catalog_product_content_values.d.ts +36 -0
- package/dist/migrations/20261104T121504_catalog_product_content_values.d.ts.map +1 -0
- package/dist/migrations/20261104T121504_catalog_product_content_values.js +53 -0
- package/dist/migrations/20261104T121504_catalog_product_content_values.js.map +1 -0
- package/dist/migrations/20261107T093126_catalog_sku_unique_among_live.d.ts +33 -0
- package/dist/migrations/20261107T093126_catalog_sku_unique_among_live.d.ts.map +1 -0
- package/dist/migrations/20261107T093126_catalog_sku_unique_among_live.js +58 -0
- package/dist/migrations/20261107T093126_catalog_sku_unique_among_live.js.map +1 -0
- package/dist/migrations/20261107T120008_catalog_product_created_at_milliseconds.d.ts +36 -0
- package/dist/migrations/20261107T120008_catalog_product_created_at_milliseconds.d.ts.map +1 -0
- package/dist/migrations/20261107T120008_catalog_product_created_at_milliseconds.js +40 -0
- package/dist/migrations/20261107T120008_catalog_product_created_at_milliseconds.js.map +1 -0
- package/dist/migrations/index.d.ts +13 -1
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +25 -1
- package/dist/migrations/index.js.map +1 -1
- package/docs/catalog/attachments.md +60 -8
- package/docs/catalog/attribute-sets.md +2 -2
- package/docs/catalog/attributes.md +68 -8
- package/docs/catalog/category-content.md +3 -0
- package/docs/catalog/composite-products.md +2 -2
- package/docs/catalog/editing-a-product-at-a-scope.md +95 -0
- package/docs/catalog/gallery-and-labels.md +68 -8
- package/docs/catalog/packaging-units.md +56 -10
- package/docs/catalog/per-channel-per-language-overrides.md +68 -237
- package/docs/catalog/product-content.md +180 -0
- package/docs/catalog/product-links.md +2 -2
- package/docs/catalog/url-keys-and-redirects.md +142 -0
- package/docs/catalog.md +241 -20
- package/i18n/en.json +977 -123
- package/i18n/pl.json +976 -122
- package/package.json +12 -12
- package/dist/admin/components/ProductScopeEditor.d.ts +0 -94
- package/dist/admin/components/ProductScopeEditor.d.ts.map +0 -1
- package/dist/admin/components/ProductScopeEditor.js +0 -395
- package/dist/admin/components/ProductScopeEditor.js.map +0 -1
- package/dist/backend/services/product-overrides.service.d.ts +0 -77
- package/dist/backend/services/product-overrides.service.d.ts.map +0 -1
- package/dist/backend/services/product-overrides.service.js +0 -204
- package/dist/backend/services/product-overrides.service.js.map +0 -1
- package/dist/backend/services/product-scope-context.service.d.ts +0 -36
- package/dist/backend/services/product-scope-context.service.d.ts.map +0 -1
- package/dist/backend/services/product-scope-context.service.js +0 -106
- package/dist/backend/services/product-scope-context.service.js.map +0 -1
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
import { randomUUID } from 'crypto';
|
|
2
|
-
import { UniqueConstraintViolationException } from '@mikro-orm/core';
|
|
2
|
+
import { LockMode, UniqueConstraintViolationException } from '@mikro-orm/core';
|
|
3
3
|
import { ERROR_CODES, isOrderMinimumEligibleType, isValidOrderMinimum, PRICE_FIELDS_REFUSED_ON_PRODUCTS,
|
|
4
4
|
// Aliased: the private method below keeps the name, so the shared function
|
|
5
5
|
// needs one the class body cannot shadow.
|
|
6
|
-
slugify as slugifyText, } from '@endora-commerce/contracts';
|
|
6
|
+
slugify as slugifyText, uuidSchema, isUuidShape, } from '@endora-commerce/contracts';
|
|
7
7
|
import { HttpError } from '@endora-commerce/platform/http';
|
|
8
8
|
import { Category } from '../entities/category.entity.js';
|
|
9
9
|
import { Product } from '../entities/product.entity.js';
|
|
10
|
+
import { ProductUrlRedirect } from '../entities/product-url-redirect.entity.js';
|
|
11
|
+
import { allocateFreeSlug } from './url-key.service.js';
|
|
12
|
+
import { bumpScopeVersion } from './scoped-values-state.js';
|
|
10
13
|
import { ProductVariant } from '../entities/product-variant.entity.js';
|
|
14
|
+
import { ProductChannelScope } from '../entities/product-channel-scope.entity.js';
|
|
15
|
+
import { ProductChannelLanguageScope } from '../entities/product-channel-language-scope.entity.js';
|
|
16
|
+
import { globalScopeFields } from './product-availability.service.js';
|
|
17
|
+
import { toChannelRecord, toLanguageRecord } from './product-scopes.service.js';
|
|
11
18
|
import { assertVirtualDownloadFields, ProductTypeValidationError, } from './product-type-validations.js';
|
|
12
19
|
import { createAttributeCommand, createAttributeOptionCommand, deleteAttributeCommand, deleteAttributeOptionCommand, updateAttributeCommand, updateAttributeOptionCommand, } from '../commands/attribute-commands.js';
|
|
20
|
+
import { requireLinkableAsset } from './linkable-asset.js';
|
|
21
|
+
import { attributeSetExists, findSkuHolder, missingCategoryIds, missingRequiredAttributeKeys, PRODUCT_SKU_MAX, reconcileProductCategories, } from './product-global-field-rules.js';
|
|
22
|
+
import { assertNoContentAttributeValues } from './content-attribute-rules.js';
|
|
23
|
+
import { readAttributeUsage } from './attribute-usage.js';
|
|
13
24
|
// Feature 061 — the API-form mapping helpers moved next to the R7 map; the
|
|
14
25
|
// re-exports keep the long-standing import site (routes, tests) stable.
|
|
15
26
|
export { dbToApiAttributeType, resolveAttributeApiType } from './attribute-type-mapping.js';
|
|
27
|
+
/**
|
|
28
|
+
* How many free-looking slug candidates `allocateUniqueSlug` locks at once (Phase 16
|
|
29
|
+
* review): enough that a concurrent writer winning one does not fail the allocation.
|
|
30
|
+
*/
|
|
31
|
+
const SLUG_CANDIDATE_LOCKS = 3;
|
|
16
32
|
/**
|
|
17
33
|
* Feature 160 (FR-043) — a product has no price of its own: a price is a row of
|
|
18
34
|
* a price book (D-287 §5.8). The old *default price* keys of `attributeValues`
|
|
@@ -34,21 +50,28 @@ export function refusePriceFields(fields, pathPrefix = '') {
|
|
|
34
50
|
* identifier, derived or otherwise.
|
|
35
51
|
*/
|
|
36
52
|
const SKU_MAX_LENGTH = 255;
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
*/
|
|
53
|
+
/** Issue #241 — value equality for a product field the update compares before it writes. */
|
|
54
|
+
function sameValue(a, b) {
|
|
55
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
56
|
+
}
|
|
42
57
|
export class CatalogAdminService {
|
|
43
58
|
emFactory;
|
|
44
59
|
events;
|
|
45
|
-
auditLog;
|
|
46
60
|
salesChannelMembership;
|
|
47
61
|
commandBus;
|
|
48
62
|
attributeRead;
|
|
49
63
|
customFields;
|
|
50
64
|
copyWarehouseThresholds;
|
|
51
|
-
|
|
65
|
+
completenessGate;
|
|
66
|
+
assets;
|
|
67
|
+
copySeoProductMeta;
|
|
68
|
+
constructor(emFactory, events,
|
|
69
|
+
/**
|
|
70
|
+
* Unread since issue #241: the last write it recorded by hand, the bulk edit's
|
|
71
|
+
* `product.update`, now runs the Command. Kept so the positional signature the
|
|
72
|
+
* composition and the fixtures construct this service with does not move.
|
|
73
|
+
*/
|
|
74
|
+
_auditLog,
|
|
52
75
|
/**
|
|
53
76
|
* Feature 005 / T027 — when injected, every newly-created Product
|
|
54
77
|
* that does not declare explicit channel membership lands in the
|
|
@@ -81,15 +104,53 @@ export class CatalogAdminService {
|
|
|
81
104
|
* keep constructing this service, and a duplicate with no thresholds copied
|
|
82
105
|
* is the module's declared degrade rather than a failure.
|
|
83
106
|
*/
|
|
84
|
-
copyWarehouseThresholds
|
|
107
|
+
copyWarehouseThresholds,
|
|
108
|
+
/**
|
|
109
|
+
* Feature 163 (FR-060, FR-061) — the completeness gate for an operator's change of
|
|
110
|
+
* the global status. Composed into the admin routes' instance only; it runs only
|
|
111
|
+
* when a call passes a mode ({@link ProductUpdateGate}), so the integration ports
|
|
112
|
+
* and the API-key upsert, which never do, are never gated (A-6).
|
|
113
|
+
*/
|
|
114
|
+
completenessGate,
|
|
115
|
+
/**
|
|
116
|
+
* Feature 166 (FR-006) — `assets_library`'s read port, asked before a
|
|
117
|
+
* download file is linked. Optional so fixtures without the library keep
|
|
118
|
+
* constructing the service; a create that names a file without it fails
|
|
119
|
+
* closed ({@link CatalogAdminService.#requireAssets}).
|
|
120
|
+
*/
|
|
121
|
+
assets,
|
|
122
|
+
/** Feature 174 (FR-119) — `seo`'s metadata copy for a duplicate, presence-decided by the wiring. */
|
|
123
|
+
copySeoProductMeta) {
|
|
85
124
|
this.emFactory = emFactory;
|
|
86
125
|
this.events = events;
|
|
87
|
-
this.auditLog = auditLog;
|
|
88
126
|
this.salesChannelMembership = salesChannelMembership;
|
|
89
127
|
this.commandBus = commandBus;
|
|
90
128
|
this.attributeRead = attributeRead;
|
|
91
129
|
this.customFields = customFields;
|
|
92
130
|
this.copyWarehouseThresholds = copyWarehouseThresholds;
|
|
131
|
+
this.completenessGate = completenessGate;
|
|
132
|
+
this.assets = assets;
|
|
133
|
+
this.copySeoProductMeta = copySeoProductMeta;
|
|
134
|
+
}
|
|
135
|
+
#requireAssets() {
|
|
136
|
+
if (!this.assets) {
|
|
137
|
+
throw new Error('CatalogAdminService: the asset read port is not wired — a download file cannot be linked.');
|
|
138
|
+
}
|
|
139
|
+
return this.assets;
|
|
140
|
+
}
|
|
141
|
+
/** The gate's mode for an operator's write, read once per request; `undefined` where no gate is composed. */
|
|
142
|
+
async completenessMode() {
|
|
143
|
+
return this.completenessGate?.mode();
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Feature 172 (FR-014) — the early refusal of a content attribute's key on a
|
|
147
|
+
* product write, before any row is read or a transaction opened. Reads the
|
|
148
|
+
* attribute model only when the write carries attribute values at all.
|
|
149
|
+
*/
|
|
150
|
+
async #refuseContentAttributeValues(attributeValues) {
|
|
151
|
+
if (!attributeValues || Object.keys(attributeValues).length === 0)
|
|
152
|
+
return;
|
|
153
|
+
assertNoContentAttributeValues(attributeValues, await this.#requireAttributeRead().listAll());
|
|
93
154
|
}
|
|
94
155
|
#requireAttributeRead() {
|
|
95
156
|
if (!this.attributeRead) {
|
|
@@ -161,6 +222,9 @@ export class CatalogAdminService {
|
|
|
161
222
|
*/
|
|
162
223
|
async createProduct(req, _auditCtx) {
|
|
163
224
|
refusePriceFields(req.attributeValues, 'attributeValues.');
|
|
225
|
+
// Feature 172 (FR-014) — refused before the Command opens a transaction;
|
|
226
|
+
// the set guard inside it refuses the same keys again for every other path.
|
|
227
|
+
await this.#refuseContentAttributeValues(req.attributeValues);
|
|
164
228
|
// Feature 002 (T047): cross-field validation for virtual download
|
|
165
229
|
// fields. Zod's .refine() catches most cases at the boundary; the
|
|
166
230
|
// service-level guard is the belt-and-braces backstop for any
|
|
@@ -181,6 +245,10 @@ export class CatalogAdminService {
|
|
|
181
245
|
// Feature 155 (FR-001, D5) — the range and the type rule hold for every
|
|
182
246
|
// caller, not only for the ones a route schema stands in front of.
|
|
183
247
|
assertOrderMinimumAllowed(req.type, req.minOrderQuantity);
|
|
248
|
+
// Feature 166 (FR-006) — a download file the caller may not see answers
|
|
249
|
+
// as a missing one, and is never linked.
|
|
250
|
+
if (req.downloadAssetId)
|
|
251
|
+
await requireLinkableAsset(this.#requireAssets(), req.downloadAssetId);
|
|
184
252
|
// The id is allocated up front so the Command can name its audit target
|
|
185
253
|
// before the row exists (same shape as `duplicateProduct`).
|
|
186
254
|
const productId = randomUUID();
|
|
@@ -213,13 +281,14 @@ export class CatalogAdminService {
|
|
|
213
281
|
// to be allocated against the live table. Without this, two products
|
|
214
282
|
// sharing a name collided on the slug index and the catch above
|
|
215
283
|
// mislabelled the failure `SKU_ALREADY_EXISTS`.
|
|
216
|
-
const slug = await this.allocateUniqueSlug(em,
|
|
284
|
+
const slug = await this.allocateUniqueSlug(em, req.name || req.sku);
|
|
217
285
|
const product = em.create(Product, {
|
|
218
286
|
id: productId,
|
|
219
287
|
sku: req.sku,
|
|
220
288
|
slug,
|
|
221
289
|
type: req.type,
|
|
222
|
-
|
|
290
|
+
// Feature 163 (Q1-d) — a product starts switched off.
|
|
291
|
+
status: req.status ?? 'inactive',
|
|
223
292
|
name: req.name,
|
|
224
293
|
description: req.description,
|
|
225
294
|
stockMode: req.stockMode ?? null,
|
|
@@ -260,7 +329,7 @@ export class CatalogAdminService {
|
|
|
260
329
|
result: product,
|
|
261
330
|
after: {
|
|
262
331
|
sku: product.sku,
|
|
263
|
-
name:
|
|
332
|
+
name: product.name,
|
|
264
333
|
status: product.status,
|
|
265
334
|
visibility: product.visibility,
|
|
266
335
|
stockMode: product.stockMode,
|
|
@@ -281,64 +350,51 @@ export class CatalogAdminService {
|
|
|
281
350
|
}),
|
|
282
351
|
};
|
|
283
352
|
}
|
|
284
|
-
|
|
353
|
+
/**
|
|
354
|
+
* The unaudited product update: the write, its flush and `product.updated.v1`,
|
|
355
|
+
* with no Command and no audit entry. Only the bus-less fallback of
|
|
356
|
+
* {@link updateProductAudited} and fixtures reach it; every operator, API-key and
|
|
357
|
+
* bulk write runs the `product.update` Command (issue #241, Principle XIII).
|
|
358
|
+
*/
|
|
359
|
+
async updateProduct(id, req, gate) {
|
|
285
360
|
const em = this.emFactory();
|
|
286
|
-
const r = await this.#applyProductUpdate(em, id, req);
|
|
361
|
+
const r = await this.#applyProductUpdate(em, id, req, gate);
|
|
287
362
|
await em.flush();
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
action: 'product.update',
|
|
295
|
-
objectType: 'product',
|
|
296
|
-
objectId: r.product.id,
|
|
297
|
-
stateBefore: r.stateBefore,
|
|
298
|
-
stateAfter: { ...r.stateAfter, changedFields: r.changedFields },
|
|
299
|
-
...(auditCtx.ipAddress !== undefined ? { ipAddress: auditCtx.ipAddress } : {}),
|
|
300
|
-
...(auditCtx.userAgent !== undefined ? { userAgent: auditCtx.userAgent } : {}),
|
|
301
|
-
...(auditCtx.requestId !== undefined ? { requestId: auditCtx.requestId } : {}),
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
const announceUpdated = () => this.events.emit('product.updated.v1', {
|
|
363
|
+
// Issue #241 — a write that changed nothing announces nothing.
|
|
364
|
+
if (r.changedFields.length === 0)
|
|
365
|
+
return r.product;
|
|
366
|
+
// Feature 163 (FR-010) — a status write never archives, so this write has
|
|
367
|
+
// one announcement; `product.archived.v1` belongs to the Archive action.
|
|
368
|
+
this.events.emit('product.updated.v1', {
|
|
305
369
|
eventId: randomUUID(),
|
|
306
370
|
occurredAt: new Date().toISOString(),
|
|
307
371
|
productId: r.product.id,
|
|
308
372
|
changedFields: r.changedFields,
|
|
309
373
|
});
|
|
310
|
-
if (r.archived) {
|
|
311
|
-
// Two announcements of one write, in one event scope: outside a scope the
|
|
312
|
-
// bus starts each emit's subscribers at once and waits for none, so the
|
|
313
|
-
// two ran side by side and a subscriber could be handed
|
|
314
|
-
// `product.archived.v1` first. A scope dispatches in order and waits, so
|
|
315
|
-
// every subscriber sees "updated, then archived" — the order the audited
|
|
316
|
-
// path already had — and the search indexer's removal has finished
|
|
317
|
-
// before this returns, which is what keeps a reactivation that follows
|
|
318
|
-
// from being undone by a removal still on its way.
|
|
319
|
-
await this.events.run(async () => {
|
|
320
|
-
announceUpdated();
|
|
321
|
-
this.#emitArchived(r.product.id);
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
else {
|
|
325
|
-
announceUpdated();
|
|
326
|
-
}
|
|
327
374
|
return r.product;
|
|
328
375
|
}
|
|
376
|
+
/** The completeness gate for `product`'s global status going to `status` (FR-060). */
|
|
377
|
+
async #gateGlobalStatus(em, product, status, mode) {
|
|
378
|
+
const gate = this.completenessGate;
|
|
379
|
+
const [channelRows, languageRows, channels] = await Promise.all([
|
|
380
|
+
em.find(ProductChannelScope, { productId: product.id }),
|
|
381
|
+
em.find(ProductChannelLanguageScope, { productId: product.id }),
|
|
382
|
+
gate.memberChannels(product.id),
|
|
383
|
+
]);
|
|
384
|
+
const before = {
|
|
385
|
+
global: globalScopeFields(product),
|
|
386
|
+
channelRows: channelRows.map(toChannelRecord),
|
|
387
|
+
languageRows: languageRows.map(toLanguageRecord),
|
|
388
|
+
};
|
|
389
|
+
const after = { ...before, global: { ...before.global, status } };
|
|
390
|
+
return gate.enforce(em, product, before, after, channels, mode);
|
|
391
|
+
}
|
|
329
392
|
/**
|
|
330
|
-
* `product.archived.v1` — the product
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
* only by `archiveProduct`, which nothing calls: archiving has been "update
|
|
336
|
-
* with `status: 'inactive'`" since feature 022, so the event the search
|
|
337
|
-
* indexer subscribes to and outbound webhooks are offered was announced by
|
|
338
|
-
* no path an operator, an importer or a PIM sync can take.
|
|
339
|
-
*
|
|
340
|
-
* Once per transition: a product that is already inactive is not archived
|
|
341
|
-
* again by a further edit, nor by a write naming the same status.
|
|
393
|
+
* `product.archived.v1` — the product was archived by the Archive action
|
|
394
|
+
* (feature 163, FR-019). Emitted by {@link archiveProduct} alone, after the
|
|
395
|
+
* write has committed and after its `product.updated.v1` `['archivedAt']`,
|
|
396
|
+
* inside the event scope that method opens. Once per transition: archiving an
|
|
397
|
+
* archived product announces nothing.
|
|
342
398
|
*/
|
|
343
399
|
#emitArchived(productId) {
|
|
344
400
|
this.events.emit('product.archived.v1', {
|
|
@@ -349,74 +405,94 @@ export class CatalogAdminService {
|
|
|
349
405
|
}
|
|
350
406
|
/**
|
|
351
407
|
* Feature 054 — admin single-update path, audited co-transactionally via the
|
|
352
|
-
* Command Bus (one audit row + the event on commit, none on rollback
|
|
353
|
-
* back to the
|
|
408
|
+
* Command Bus (one audit row + the event on commit, none on rollback; none either
|
|
409
|
+
* when nothing changed, issue #241). Falls back to the unaudited `updateProduct`
|
|
410
|
+
* when no bus is injected (bus-less tests).
|
|
411
|
+
*/
|
|
412
|
+
/**
|
|
413
|
+
* Whether product writes run through the Command Bus, and so are audited. A bulk
|
|
414
|
+
* edit refuses to run when they do not (issue #241): its per-product writes would
|
|
415
|
+
* fall back to the unaudited `updateProduct`.
|
|
354
416
|
*/
|
|
355
|
-
|
|
417
|
+
hasCommandBus() {
|
|
418
|
+
return this.commandBus !== undefined;
|
|
419
|
+
}
|
|
420
|
+
async updateProductAudited(id, req, gate) {
|
|
421
|
+
// Feature 172 (FR-014) — before the transaction, as on create.
|
|
422
|
+
await this.#refuseContentAttributeValues(req.attributeValues);
|
|
356
423
|
if (!this.commandBus)
|
|
357
|
-
return this.updateProduct(id, req);
|
|
358
|
-
|
|
359
|
-
const outcome = { archived: false };
|
|
360
|
-
// A Command declares one event, and archiving is a second announcement of
|
|
361
|
-
// the same write. The Command Bus opens its own event scope, which ends —
|
|
362
|
-
// dispatching `product.updated.v1` and waiting for its subscribers — once
|
|
363
|
-
// the write has committed; `product.archived.v1` is emitted after that,
|
|
364
|
-
// into the scope opened here, so it is dispatched second and waited for as
|
|
365
|
-
// well. Emitted outside any scope it was started and not waited for: this
|
|
366
|
-
// method returned while the search indexer's removal was still on its way,
|
|
367
|
-
// and a reactivation that followed could be undone by it.
|
|
368
|
-
return this.events.run(async () => {
|
|
369
|
-
const product = await commandBus.run(this.#updateProductCommand(id, req, outcome));
|
|
370
|
-
if (outcome.archived)
|
|
371
|
-
this.#emitArchived(product.id);
|
|
372
|
-
return product;
|
|
373
|
-
});
|
|
424
|
+
return this.updateProduct(id, req, gate);
|
|
425
|
+
return this.commandBus.run(this.#updateProductCommand(id, req, gate));
|
|
374
426
|
}
|
|
375
|
-
#updateProductCommand(id, req,
|
|
376
|
-
/** Written by `run`: whether this write moved the product to `inactive`. */
|
|
377
|
-
outcome) {
|
|
427
|
+
#updateProductCommand(id, req, gate) {
|
|
378
428
|
let changedFields = [];
|
|
379
429
|
return {
|
|
380
430
|
action: 'product.update',
|
|
381
431
|
objectType: 'product',
|
|
382
432
|
objectId: id,
|
|
383
433
|
run: async ({ em }) => {
|
|
384
|
-
const r = await this.#applyProductUpdate(em, id, req);
|
|
434
|
+
const r = await this.#applyProductUpdate(em, id, req, gate);
|
|
385
435
|
changedFields = r.changedFields;
|
|
386
|
-
|
|
436
|
+
// Issue #241 — a write that changed nothing records no entry and announces
|
|
437
|
+
// nothing. The editor's version bump still commits, as on a no-op scope write.
|
|
438
|
+
if (changedFields.length === 0)
|
|
439
|
+
return { result: r.product, skipAudit: true };
|
|
387
440
|
return {
|
|
388
441
|
result: r.product,
|
|
389
442
|
before: r.stateBefore,
|
|
390
|
-
after: { ...r.stateAfter, changedFields },
|
|
443
|
+
after: { ...r.stateAfter, changedFields, ...(gate?.apiKeyId ? { apiKeyId: gate.apiKeyId } : {}) },
|
|
391
444
|
};
|
|
392
445
|
},
|
|
393
|
-
event: (product) =>
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
446
|
+
event: (product) => changedFields.length === 0
|
|
447
|
+
? undefined
|
|
448
|
+
: {
|
|
449
|
+
eventName: 'product.updated.v1',
|
|
450
|
+
payload: {
|
|
451
|
+
eventId: randomUUID(),
|
|
452
|
+
occurredAt: new Date().toISOString(),
|
|
453
|
+
productId: product.id,
|
|
454
|
+
changedFields,
|
|
455
|
+
},
|
|
400
456
|
},
|
|
401
|
-
}),
|
|
402
457
|
};
|
|
403
458
|
}
|
|
404
459
|
/**
|
|
405
460
|
* Pure product-update write on the given em — no flush, no audit, no event.
|
|
406
461
|
* Shared by the legacy `updateProduct` and the audited Command path.
|
|
407
462
|
*/
|
|
408
|
-
async #applyProductUpdate(em, id, req) {
|
|
463
|
+
async #applyProductUpdate(em, id, req, gate) {
|
|
409
464
|
refusePriceFields(req.attributeValues, 'attributeValues.');
|
|
465
|
+
if (!isUuidShape(id)) {
|
|
466
|
+
throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
|
|
467
|
+
}
|
|
410
468
|
const product = await em.findOne(Product, { id });
|
|
411
469
|
if (!product) {
|
|
412
470
|
throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
|
|
413
471
|
}
|
|
414
472
|
// Feature 155 (FR-001, D5) — refused before anything on the row changes.
|
|
415
473
|
assertOrderMinimumAllowed(product.type, req.minOrderQuantity);
|
|
474
|
+
// Feature 174 (C2/C3 code review 1) — the existence rules the scoped save holds for the same
|
|
475
|
+
// Global-only fields (`product-global-field-rules.ts`), checked before anything is written:
|
|
476
|
+
// an unknown attribute set or an unknown or deleted category used to reach the foreign key
|
|
477
|
+
// (a 500), and a deleted category was linked silently.
|
|
478
|
+
if (req.attributeSetId !== undefined &&
|
|
479
|
+
req.attributeSetId !== product.attributeSetId &&
|
|
480
|
+
!(await attributeSetExists(em, req.attributeSetId))) {
|
|
481
|
+
throw new HttpError(400, ERROR_CODES.VALIDATION_FAILED, 'unknown_attribute_set');
|
|
482
|
+
}
|
|
483
|
+
if (req.categoryIds !== undefined) {
|
|
484
|
+
const missing = await missingCategoryIds(em, req.categoryIds);
|
|
485
|
+
if (missing.length > 0) {
|
|
486
|
+
throw new HttpError(400, ERROR_CODES.VALIDATION_FAILED, `unknown_category_ids: ${missing.join(', ')}`);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
// Feature 174 (R7, contract §6) — a product-row write is Save-overwritable: it moves the
|
|
490
|
+
// editor's version, and a `version` the caller sends is compared first (stale → 409).
|
|
491
|
+
await bumpScopeVersion(em, id, req.version);
|
|
416
492
|
const stateBefore = {
|
|
417
493
|
sku: product.sku,
|
|
418
|
-
name:
|
|
419
|
-
description:
|
|
494
|
+
name: product.name,
|
|
495
|
+
description: product.description,
|
|
420
496
|
stockMode: product.stockMode,
|
|
421
497
|
visibility: product.visibility,
|
|
422
498
|
status: product.status,
|
|
@@ -427,9 +503,11 @@ export class CatalogAdminService {
|
|
|
427
503
|
// whether or not this write touched it.
|
|
428
504
|
minOrderQuantity: product.minOrderQuantity ?? null,
|
|
429
505
|
returnable: product.returnable,
|
|
506
|
+
// Feature 163 (FR-023) — the global publication window.
|
|
507
|
+
publishFrom: product.publishFrom?.toISOString() ?? null,
|
|
508
|
+
publishUntil: product.publishUntil?.toISOString() ?? null,
|
|
430
509
|
};
|
|
431
510
|
const changedFields = [];
|
|
432
|
-
let archived = false;
|
|
433
511
|
// Feature 012 / FR-016 — SKU is mutable. Refused with 400 sku_in_use
|
|
434
512
|
// when the new SKU collides with another product. The internal UUID
|
|
435
513
|
// (product.id) is the canonical reference; snapshot tables keep the
|
|
@@ -441,48 +519,50 @@ export class CatalogAdminService {
|
|
|
441
519
|
// create contract enforces. This guard used to read 160 while the
|
|
442
520
|
// column held 64, so a 100-character rename passed validation and then
|
|
443
521
|
// failed at the database; all three now agree.
|
|
444
|
-
if (trimmed.length === 0 || trimmed.length >
|
|
522
|
+
if (trimmed.length === 0 || trimmed.length > PRODUCT_SKU_MAX) {
|
|
445
523
|
throw new HttpError(400, ERROR_CODES.VALIDATION_FAILED, 'invalid_sku');
|
|
446
524
|
}
|
|
447
|
-
const conflict = await em.findOne(Product, { sku: trimmed });
|
|
448
|
-
if (conflict && conflict.id !== product.id) {
|
|
449
|
-
throw new HttpError(400, ERROR_CODES.VALIDATION_FAILED, `sku_in_use { conflictingProductId: ${conflict.id}, conflictingSku: ${trimmed} }`);
|
|
450
|
-
}
|
|
451
525
|
// Feature 025 — SKUs share a global namespace with variants (see createVariant).
|
|
452
|
-
const
|
|
453
|
-
if (
|
|
454
|
-
throw new HttpError(400, ERROR_CODES.VALIDATION_FAILED,
|
|
526
|
+
const holder = await findSkuHolder(em, product.id, trimmed);
|
|
527
|
+
if (holder) {
|
|
528
|
+
throw new HttpError(400, ERROR_CODES.VALIDATION_FAILED, 'productId' in holder
|
|
529
|
+
? `sku_in_use { conflictingProductId: ${holder.productId}, conflictingSku: ${trimmed} }`
|
|
530
|
+
: `sku_in_use { conflictingVariantId: ${holder.variantId}, conflictingSku: ${trimmed} }`);
|
|
455
531
|
}
|
|
456
532
|
product.sku = trimmed;
|
|
457
533
|
changedFields.push('sku');
|
|
458
534
|
}
|
|
459
|
-
|
|
535
|
+
// Issue #241 — a field is changed only when its value moves: a write that
|
|
536
|
+
// restates what is stored records no audit entry and announces nothing.
|
|
537
|
+
if (req.name && req.name !== product.name) {
|
|
460
538
|
product.name = req.name;
|
|
461
539
|
changedFields.push('name');
|
|
462
540
|
}
|
|
463
|
-
if (req.description) {
|
|
541
|
+
if (req.description && req.description !== product.description) {
|
|
464
542
|
product.description = req.description;
|
|
465
543
|
changedFields.push('description');
|
|
466
544
|
}
|
|
467
|
-
if (req.stockMode !== undefined) {
|
|
545
|
+
if (req.stockMode !== undefined && req.stockMode !== (product.stockMode ?? null)) {
|
|
468
546
|
product.stockMode = req.stockMode;
|
|
469
547
|
changedFields.push('stockMode');
|
|
470
548
|
}
|
|
471
|
-
if (req.visibility) {
|
|
549
|
+
if (req.visibility && req.visibility !== product.visibility) {
|
|
472
550
|
product.visibility = req.visibility;
|
|
473
551
|
changedFields.push('visibility');
|
|
474
552
|
}
|
|
475
|
-
// Feature 022
|
|
476
|
-
//
|
|
553
|
+
// Feature 022 — status field. Feature 163 (FR-010, FR-019, O-5): a status
|
|
554
|
+
// write never sets or clears `archivedAt` — `inactive` is plain off and
|
|
555
|
+
// `active` does not restore. Archiving is the Archive / Restore action.
|
|
477
556
|
if (req.status !== undefined && req.status !== product.status) {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
557
|
+
// Feature 163 (FR-060, US6 #3) — a change of the global switch runs the
|
|
558
|
+
// completeness gate over every pair it turns on, before the row changes: in
|
|
559
|
+
// `refuse` one failing pair refuses the whole write (N3). It reads status
|
|
560
|
+
// only, so an archived product set `active` is gated too.
|
|
561
|
+
if (gate?.completeness && this.completenessGate) {
|
|
562
|
+
const warnings = await this.#gateGlobalStatus(em, product, req.status, gate.completeness);
|
|
563
|
+
gate.warnings?.push(...warnings);
|
|
485
564
|
}
|
|
565
|
+
product.status = req.status;
|
|
486
566
|
changedFields.push('status');
|
|
487
567
|
}
|
|
488
568
|
// Feature 002 (T034) — attribute_set_id swap. Persist BEFORE
|
|
@@ -498,8 +578,12 @@ export class CatalogAdminService {
|
|
|
498
578
|
// the set; we validate the incoming patch only since the existing
|
|
499
579
|
// values were already validated at their time of write.
|
|
500
580
|
await this.assertAttributeValueKeysAllowed(em, product.attributeSetId, req.attributeValues, new Set(Object.keys(product.attributeValues ?? {})));
|
|
501
|
-
|
|
502
|
-
|
|
581
|
+
const current = product.attributeValues ?? {};
|
|
582
|
+
const patch = req.attributeValues;
|
|
583
|
+
if (Object.keys(patch).some((key) => !sameValue(current[key], patch[key]))) {
|
|
584
|
+
product.attributeValues = { ...current, ...patch };
|
|
585
|
+
changedFields.push('attributeValues');
|
|
586
|
+
}
|
|
503
587
|
}
|
|
504
588
|
// Feature 012 / FR-013 — refuse the save if any required attribute
|
|
505
589
|
// in the assigned set is left without a value. The merged map is
|
|
@@ -510,7 +594,7 @@ export class CatalogAdminService {
|
|
|
510
594
|
req.attributeSetId !== undefined)) {
|
|
511
595
|
await this.assertRequiredAttributesPresent(em, product.attributeSetId, product.attributeValues ?? {});
|
|
512
596
|
}
|
|
513
|
-
if (req.allowedOrganizationIds) {
|
|
597
|
+
if (req.allowedOrganizationIds && !sameValue(req.allowedOrganizationIds, product.allowedOrganizationIds)) {
|
|
514
598
|
product.allowedOrganizationIds = req.allowedOrganizationIds;
|
|
515
599
|
changedFields.push('allowedOrganizationIds');
|
|
516
600
|
}
|
|
@@ -526,42 +610,67 @@ export class CatalogAdminService {
|
|
|
526
610
|
}
|
|
527
611
|
}
|
|
528
612
|
// Feature 010 — per-product stock-management flags.
|
|
529
|
-
if (req.manageStock !== undefined) {
|
|
613
|
+
if (req.manageStock !== undefined && req.manageStock !== product.manageStock) {
|
|
530
614
|
product.manageStock = req.manageStock;
|
|
531
615
|
changedFields.push('manageStock');
|
|
532
616
|
}
|
|
533
|
-
if (req.backorderEnabled !== undefined) {
|
|
617
|
+
if (req.backorderEnabled !== undefined && req.backorderEnabled !== product.backorderEnabled) {
|
|
534
618
|
product.backorderEnabled = req.backorderEnabled;
|
|
535
619
|
changedFields.push('backorderEnabled');
|
|
536
620
|
}
|
|
537
|
-
if (req.lowStockThreshold !== undefined) {
|
|
621
|
+
if (req.lowStockThreshold !== undefined && req.lowStockThreshold !== (product.lowStockThreshold ?? null)) {
|
|
538
622
|
product.lowStockThreshold = req.lowStockThreshold;
|
|
539
623
|
changedFields.push('lowStockThreshold');
|
|
540
624
|
}
|
|
541
|
-
if (req.lowStockThresholdMode !== undefined) {
|
|
625
|
+
if (req.lowStockThresholdMode !== undefined && req.lowStockThresholdMode !== product.lowStockThresholdMode) {
|
|
542
626
|
product.lowStockThresholdMode = req.lowStockThresholdMode;
|
|
543
627
|
changedFields.push('lowStockThresholdMode');
|
|
544
628
|
}
|
|
545
|
-
if (req.fulfilmentStrategy !== undefined) {
|
|
629
|
+
if (req.fulfilmentStrategy !== undefined && req.fulfilmentStrategy !== (product.fulfilmentStrategy ?? null)) {
|
|
546
630
|
product.fulfilmentStrategy = req.fulfilmentStrategy;
|
|
547
631
|
changedFields.push('fulfilmentStrategy');
|
|
548
632
|
}
|
|
549
|
-
if (req.fulfilmentStrategyWarehouseOrder !== undefined
|
|
633
|
+
if (req.fulfilmentStrategyWarehouseOrder !== undefined &&
|
|
634
|
+
!sameValue(req.fulfilmentStrategyWarehouseOrder, product.fulfilmentStrategyWarehouseOrder ?? null)) {
|
|
550
635
|
product.fulfilmentStrategyWarehouseOrder = req.fulfilmentStrategyWarehouseOrder;
|
|
551
636
|
changedFields.push('fulfilmentStrategyWarehouseOrder');
|
|
552
637
|
}
|
|
553
638
|
// Feature 155 (FR-001, FR-003, D5) — the pieces minimum and the returnable flag.
|
|
554
|
-
if (req.minOrderQuantity !== undefined) {
|
|
639
|
+
if (req.minOrderQuantity !== undefined && req.minOrderQuantity !== (product.minOrderQuantity ?? null)) {
|
|
555
640
|
product.minOrderQuantity = req.minOrderQuantity;
|
|
556
641
|
changedFields.push('minOrderQuantity');
|
|
557
642
|
}
|
|
558
|
-
if (req.returnable !== undefined) {
|
|
643
|
+
if (req.returnable !== undefined && req.returnable !== product.returnable) {
|
|
559
644
|
product.returnable = req.returnable;
|
|
560
645
|
changedFields.push('returnable');
|
|
561
646
|
}
|
|
647
|
+
// Feature 163 (FR-023) — the global publication window, written as a pair:
|
|
648
|
+
// an omitted bound keeps its stored value, and the pair that results must
|
|
649
|
+
// start before it ends. It never touches a channel's window (FR-013).
|
|
650
|
+
if (req.publishFrom !== undefined || req.publishUntil !== undefined) {
|
|
651
|
+
const from = req.publishFrom === undefined
|
|
652
|
+
? (product.publishFrom ?? null)
|
|
653
|
+
: req.publishFrom === null
|
|
654
|
+
? null
|
|
655
|
+
: new Date(req.publishFrom);
|
|
656
|
+
const until = req.publishUntil === undefined
|
|
657
|
+
? (product.publishUntil ?? null)
|
|
658
|
+
: req.publishUntil === null
|
|
659
|
+
? null
|
|
660
|
+
: new Date(req.publishUntil);
|
|
661
|
+
if (from !== null && until !== null && from.getTime() >= until.getTime()) {
|
|
662
|
+
throw new HttpError(422, ERROR_CODES.VALIDATION_FAILED, 'The publication window must start before it ends.', { field: 'window' });
|
|
663
|
+
}
|
|
664
|
+
if ((from?.getTime() ?? null) !== (product.publishFrom?.getTime() ?? null) ||
|
|
665
|
+
(until?.getTime() ?? null) !== (product.publishUntil?.getTime() ?? null)) {
|
|
666
|
+
product.publishFrom = from;
|
|
667
|
+
product.publishUntil = until;
|
|
668
|
+
changedFields.push('publicationWindow');
|
|
669
|
+
}
|
|
670
|
+
}
|
|
562
671
|
const stateAfter = {
|
|
563
|
-
name:
|
|
564
|
-
description:
|
|
672
|
+
name: product.name,
|
|
673
|
+
description: product.description,
|
|
565
674
|
stockMode: product.stockMode,
|
|
566
675
|
visibility: product.visibility,
|
|
567
676
|
status: product.status,
|
|
@@ -570,8 +679,10 @@ export class CatalogAdminService {
|
|
|
570
679
|
allowedOrganizationIds: [...product.allowedOrganizationIds],
|
|
571
680
|
minOrderQuantity: product.minOrderQuantity ?? null,
|
|
572
681
|
returnable: product.returnable,
|
|
682
|
+
publishFrom: product.publishFrom?.toISOString() ?? null,
|
|
683
|
+
publishUntil: product.publishUntil?.toISOString() ?? null,
|
|
573
684
|
};
|
|
574
|
-
return { product, stateBefore, stateAfter, changedFields
|
|
685
|
+
return { product, stateBefore, stateAfter, changedFields };
|
|
575
686
|
}
|
|
576
687
|
/**
|
|
577
688
|
* Makes `product_categories` hold exactly `categoryIds` for one product, on
|
|
@@ -586,37 +697,20 @@ export class CatalogAdminService {
|
|
|
586
697
|
* in the request into a constraint violation.
|
|
587
698
|
*/
|
|
588
699
|
async #reconcileProductCategories(em, productId, categoryIds) {
|
|
589
|
-
|
|
590
|
-
const txCtx = em.getTransactionContext();
|
|
591
|
-
const currentRows = (await conn.execute(`select category_id from product_categories where product_id = ?`, [productId], 'all', txCtx));
|
|
592
|
-
const current = new Set(currentRows.map((r) => r.category_id));
|
|
593
|
-
const target = new Set(categoryIds);
|
|
594
|
-
const toAdd = [...target].filter((id) => !current.has(id));
|
|
595
|
-
const toRemove = [...current].filter((id) => !target.has(id));
|
|
596
|
-
if (toRemove.length > 0) {
|
|
597
|
-
const placeholders = toRemove.map(() => '?').join(',');
|
|
598
|
-
await conn.execute(`delete from product_categories where product_id = ? and category_id in (${placeholders})`, [productId, ...toRemove], 'run', txCtx);
|
|
599
|
-
}
|
|
600
|
-
if (toAdd.length > 0) {
|
|
601
|
-
const placeholders = toAdd.map(() => '(?,?)').join(',');
|
|
602
|
-
const params = [];
|
|
603
|
-
for (const cid of toAdd) {
|
|
604
|
-
params.push(productId, cid);
|
|
605
|
-
}
|
|
606
|
-
await conn.execute(`insert into product_categories (product_id, category_id) values ${placeholders}`, params, 'run', txCtx);
|
|
607
|
-
}
|
|
608
|
-
return toAdd.length > 0 || toRemove.length > 0;
|
|
700
|
+
return reconcileProductCategories(em, productId, categoryIds);
|
|
609
701
|
}
|
|
610
702
|
/**
|
|
611
703
|
* Duplicate an existing Product: copies the core row plus bridge tables
|
|
612
704
|
* (categories, sales-channel memberships, gallery items + labels,
|
|
613
|
-
* attachments, related/up-sell/cross-sell links, grouped
|
|
614
|
-
* bundle slots + options, variants)
|
|
705
|
+
* attachments, packaging units, related/up-sell/cross-sell links, grouped
|
|
706
|
+
* children, bundle slots + options, variants) and, since feature 174
|
|
707
|
+
* (FR-119), every scoped value at Global, Channel and Channel × language.
|
|
615
708
|
*
|
|
616
709
|
* The duplicated row gets a fresh UUID; the SKU is derived from the
|
|
617
710
|
* source by appending `-copy`, then `-copy-2`, `-copy-3`, … until a
|
|
618
|
-
* free slot is found. Status is reset to `'
|
|
619
|
-
* is cleared so the operator can review before
|
|
711
|
+
* free slot is found. Status is reset to `'inactive'` and `archivedAt`
|
|
712
|
+
* is cleared (feature 163, Q1-d) so the operator can review before
|
|
713
|
+
* switching it on — also when the source is archived and `active`.
|
|
620
714
|
*
|
|
621
715
|
* Variants have their own globally-unique SKUs; each is suffixed in
|
|
622
716
|
* the same way against the variant SKU space.
|
|
@@ -630,32 +724,44 @@ export class CatalogAdminService {
|
|
|
630
724
|
if (this.commandBus) {
|
|
631
725
|
return this.commandBus.run({ action, objectType, objectId, run: ({ em }) => write(em) });
|
|
632
726
|
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
727
|
+
// Unaudited without a Command Bus, but still one transaction: the URL-key
|
|
728
|
+
// advisory locks a write takes (`allocateUniqueSlug`) hold only inside one.
|
|
729
|
+
return this.emFactory().transactional(async (em) => {
|
|
730
|
+
const w = await write(em);
|
|
731
|
+
await em.flush();
|
|
732
|
+
return w.result;
|
|
733
|
+
});
|
|
637
734
|
}
|
|
638
735
|
async duplicateProduct(id) {
|
|
639
736
|
const em = this.emFactory();
|
|
737
|
+
if (!isUuidShape(id)) {
|
|
738
|
+
throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
|
|
739
|
+
}
|
|
640
740
|
const source = await em.findOne(Product, { id });
|
|
641
741
|
if (!source) {
|
|
642
742
|
throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
|
|
643
743
|
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
//
|
|
647
|
-
//
|
|
648
|
-
//
|
|
744
|
+
// Feature 174 (FR-119, T151) — the copy is ONE Command: the product row, every catalog-owned
|
|
745
|
+
// bridge and every scoped value at Global, Channel and Channel × language, empty overrides and
|
|
746
|
+
// inherit states included, commit or roll back together with the one audit entry. What other
|
|
747
|
+
// modules own runs through their own audited Commands after it (the channel memberships, the
|
|
748
|
+
// warehouse thresholds): a Command cannot nest inside another's transaction. URL keys are never
|
|
749
|
+
// copied beyond the fresh Global key, and status is reset at every scope (163 Q1-d).
|
|
649
750
|
const dupId = randomUUID();
|
|
650
751
|
const dup = await this.#auditedWrite('product.duplicate', 'product', dupId, async (cem) => {
|
|
752
|
+
// Inside the Command's transaction (Phase 16 review): the slug's URL-key lock is
|
|
753
|
+
// a transaction lock, so on a bare em it was released before the insert.
|
|
754
|
+
const newSku = await this.allocateCopySku(cem, source.sku);
|
|
755
|
+
const newSlug = await this.allocateCopySlug(cem, source.slug);
|
|
651
756
|
const created = cem.create(Product, {
|
|
652
757
|
id: dupId,
|
|
653
758
|
sku: newSku,
|
|
654
759
|
slug: newSlug,
|
|
655
760
|
type: source.type,
|
|
656
|
-
status: '
|
|
657
|
-
|
|
658
|
-
|
|
761
|
+
status: 'inactive',
|
|
762
|
+
archivedAt: null,
|
|
763
|
+
name: this.suffixCopyName(source.name),
|
|
764
|
+
description: source.description,
|
|
659
765
|
stockMode: source.stockMode ?? null,
|
|
660
766
|
visibility: source.visibility,
|
|
661
767
|
attributeValues: { ...source.attributeValues },
|
|
@@ -684,17 +790,37 @@ export class CatalogAdminService {
|
|
|
684
790
|
],
|
|
685
791
|
}
|
|
686
792
|
: {}),
|
|
793
|
+
// Feature 174 (FR-119) — the Global order rules and publication window.
|
|
794
|
+
minOrderQuantity: source.minOrderQuantity ?? null,
|
|
795
|
+
returnable: source.returnable,
|
|
796
|
+
publishFrom: source.publishFrom ?? null,
|
|
797
|
+
publishUntil: source.publishUntil ?? null,
|
|
687
798
|
});
|
|
688
799
|
await cem.flush();
|
|
800
|
+
const copied = await this.#copyCatalogRows(cem, source, dupId);
|
|
801
|
+
const seo = this.copySeoProductMeta
|
|
802
|
+
? await this.copySeoProductMeta(cem, { sourceProductId: source.id, targetProductId: dupId })
|
|
803
|
+
: 'not-present';
|
|
804
|
+
// Feature 172 (FR-060, research R-16) — the product's Page Builder content
|
|
805
|
+
// is copied in this transaction, atomic with the row it belongs to. The
|
|
806
|
+
// audit row counts the attributes, never the documents.
|
|
807
|
+
const copiedContent = (await cem.execute(`insert into product_content_values
|
|
808
|
+
(id, product_id, product_attribute_id, content, summary, created_at, updated_at)
|
|
809
|
+
select gen_random_uuid(), ?, product_attribute_id, content, summary, now(), now()
|
|
810
|
+
from product_content_values where product_id = ?
|
|
811
|
+
returning id`, [dupId, source.id]));
|
|
689
812
|
return {
|
|
690
813
|
result: created,
|
|
691
814
|
before: null,
|
|
692
|
-
after: {
|
|
815
|
+
after: {
|
|
816
|
+
sku: newSku,
|
|
817
|
+
slug: newSlug,
|
|
818
|
+
sourceProductId: id,
|
|
819
|
+
copied: { ...copied, seoScopes: seo === 'not-present' ? null : seo.copied },
|
|
820
|
+
contentAttributeCount: copiedContent.length,
|
|
821
|
+
},
|
|
693
822
|
};
|
|
694
823
|
});
|
|
695
|
-
// product_categories (bridge)
|
|
696
|
-
await em.execute(`insert into "product_categories" ("product_id", "category_id")
|
|
697
|
-
select ?, "category_id" from "product_categories" where "product_id" = ?`, [dup.id, source.id]);
|
|
698
824
|
// The channel assortment, through the kernel's membership service (issue
|
|
699
825
|
// #185). This was an `insert … select` against the bridge table, which is
|
|
700
826
|
// Principle XII's accessor clause and Principle XIII in one statement: the
|
|
@@ -704,46 +830,124 @@ export class CatalogAdminService {
|
|
|
704
830
|
if (this.salesChannelMembership) {
|
|
705
831
|
await this.salesChannelMembership.copyMemberships('product', source.id, dup.id);
|
|
706
832
|
}
|
|
707
|
-
//
|
|
708
|
-
//
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
values (?, ?, ?, ?, now(), now())`, [newId, dup.id, row.asset_id, row.position]);
|
|
719
|
-
}
|
|
720
|
-
const labelRows = (await em.execute(`select "gallery_item_id", "label" from "gallery_item_labels"
|
|
721
|
-
where "product_id" = ?`, [source.id]));
|
|
722
|
-
for (const lbl of labelRows) {
|
|
723
|
-
const mapped = idMap.get(lbl.gallery_item_id);
|
|
724
|
-
if (!mapped)
|
|
725
|
-
continue;
|
|
726
|
-
await em.execute(`insert into "gallery_item_labels"
|
|
727
|
-
("gallery_item_id", "product_id", "label") values (?, ?, ?)`, [mapped, dup.id, lbl.label]);
|
|
728
|
-
}
|
|
833
|
+
// Per-(product, warehouse) low-stock thresholds, so the duplicate inherits
|
|
834
|
+
// the source's alerting profile. `inventory`'s rows and `inventory`'s
|
|
835
|
+
// Command since issue #185 — this used to be an `insert … select` into that
|
|
836
|
+
// module's table from here, which kept writing while an operator had the
|
|
837
|
+
// module switched off. No `catch` around it: the wiring decides presence in
|
|
838
|
+
// front of the gate and the degrade arrives as `'not-present'`.
|
|
839
|
+
if (this.copyWarehouseThresholds) {
|
|
840
|
+
await this.copyWarehouseThresholds({
|
|
841
|
+
sourceProductId: source.id,
|
|
842
|
+
targetProductId: dup.id,
|
|
843
|
+
});
|
|
729
844
|
}
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
845
|
+
this.events.emit('product.created.v1', {
|
|
846
|
+
eventId: randomUUID(),
|
|
847
|
+
occurredAt: new Date().toISOString(),
|
|
848
|
+
productId: dup.id,
|
|
849
|
+
sku: dup.sku,
|
|
850
|
+
});
|
|
851
|
+
return dup;
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* Feature 174 (FR-119, T151) — every catalog-owned row of `source` copied onto `targetId`, on the
|
|
855
|
+
* Command's em: the bridges (categories, gallery with its Global roles, attachments, packaging
|
|
856
|
+
* units, links, grouped children, bundle slots, variants) and every scoped value at Channel and
|
|
857
|
+
* Channel × language — value overrides (texts and attributes), channel scope rows, gallery item,
|
|
858
|
+
* gallery role, attachment and packaging-unit overrides — verbatim, so a deliberately empty
|
|
859
|
+
* override stays empty and a scope holding nothing still inherits. Child-row overrides are
|
|
860
|
+
* re-pointed through an old → new id map passed as one JSON parameter.
|
|
861
|
+
*
|
|
862
|
+
* Not copied: URL keys and redirects (unique per channel; the copy has its fresh Global key),
|
|
863
|
+
* status at Channel and Channel × language (the copy starts `inactive` everywhere, 163 Q1-d).
|
|
864
|
+
* Orphaned rows (a scope the source no longer sells on) are copied like the rest: they keep
|
|
865
|
+
* what the source keeps, and come back to life in the same way when the scope does.
|
|
866
|
+
*/
|
|
867
|
+
async #copyCatalogRows(em, source, targetId) {
|
|
868
|
+
const count = async (sql, params) => (await em.execute(sql, params)).length;
|
|
869
|
+
const idMap = async (table) => {
|
|
870
|
+
const rows = (await em.execute(`select "id" from "${table}" where "product_id" = ?`, [source.id]));
|
|
871
|
+
return Object.fromEntries(rows.map((row) => [row.id, randomUUID()]));
|
|
872
|
+
};
|
|
873
|
+
const remap = (column) => `(?::jsonb ->> o."${column}"::text)::uuid`;
|
|
874
|
+
// product_categories (bridge)
|
|
875
|
+
await em.execute(`insert into "product_categories" ("product_id", "category_id")
|
|
876
|
+
select ?, "category_id" from "product_categories" where "product_id" = ?`, [targetId, source.id]);
|
|
877
|
+
// Texts and attributes at C and C×L.
|
|
878
|
+
const valueOverrides = await count(`insert into "product_value_overrides"
|
|
879
|
+
("id", "product_id", "attribute_key", "channel_id", "language_code", "value", "created_at", "updated_at")
|
|
880
|
+
select gen_random_uuid(), ?, o."attribute_key", o."channel_id", o."language_code", o."value", now(), now()
|
|
881
|
+
from "product_value_overrides" o where o."product_id" = ?
|
|
882
|
+
returning "id"`, [targetId, source.id]);
|
|
883
|
+
// Window, audience, MOQ and returnable at C; status inherits (the copy is reviewed first).
|
|
884
|
+
const channelScopes = await count(`insert into "product_channel_scopes"
|
|
885
|
+
("product_id", "sales_channel_id", "status", "window_overridden", "publish_from", "publish_until",
|
|
886
|
+
"visibility", "allowed_organization_ids", "min_order_quantity_overridden", "min_order_quantity",
|
|
887
|
+
"returnable", "created_at", "updated_at")
|
|
888
|
+
select ?, o."sales_channel_id", null, o."window_overridden", o."publish_from", o."publish_until",
|
|
889
|
+
o."visibility", o."allowed_organization_ids", o."min_order_quantity_overridden",
|
|
890
|
+
o."min_order_quantity", o."returnable", now(), now()
|
|
891
|
+
from "product_channel_scopes" o where o."product_id" = ?
|
|
892
|
+
returning "product_id"`, [targetId, source.id]);
|
|
893
|
+
// Gallery: the items with their Global alt text and hidden flag, the Global roles, the overrides.
|
|
894
|
+
const items = await idMap('gallery_items');
|
|
895
|
+
const itemsJson = JSON.stringify(items);
|
|
896
|
+
const galleryItems = await count(`insert into "gallery_items" ("id", "product_id", "asset_id", "position", "alt_text", "hidden", "created_at", "updated_at")
|
|
897
|
+
select ${remap('id')}, ?, o."asset_id", o."position", o."alt_text", o."hidden", now(), now()
|
|
898
|
+
from "gallery_items" o where o."product_id" = ?
|
|
899
|
+
returning "id"`, [itemsJson, targetId, source.id]);
|
|
900
|
+
const galleryRoles = await count(`insert into "gallery_item_labels" ("gallery_item_id", "product_id", "label")
|
|
901
|
+
select ${remap('gallery_item_id')}, ?, o."label"
|
|
902
|
+
from "gallery_item_labels" o where o."product_id" = ?
|
|
903
|
+
returning "label"`, [itemsJson, targetId, source.id]);
|
|
904
|
+
const galleryItemOverrides = await count(`insert into "gallery_item_scope_overrides"
|
|
905
|
+
("id", "gallery_item_id", "product_id", "sales_channel_id", "language_code", "field", "value", "created_at", "updated_at")
|
|
906
|
+
select gen_random_uuid(), ${remap('gallery_item_id')}, ?, o."sales_channel_id", o."language_code", o."field", o."value", now(), now()
|
|
907
|
+
from "gallery_item_scope_overrides" o where o."product_id" = ?
|
|
908
|
+
returning "id"`, [itemsJson, targetId, source.id]);
|
|
909
|
+
// An empty role (no holder) keeps its `null`: `->>` of a null key is null.
|
|
910
|
+
const galleryRoleOverrides = await count(`insert into "gallery_role_scope_overrides"
|
|
911
|
+
("id", "product_id", "sales_channel_id", "language_code", "label", "gallery_item_id", "created_at", "updated_at")
|
|
912
|
+
select gen_random_uuid(), ?, o."sales_channel_id", o."language_code", o."label", ${remap('gallery_item_id')}, now(), now()
|
|
913
|
+
from "gallery_role_scope_overrides" o where o."product_id" = ?
|
|
914
|
+
returning "id"`, [targetId, itemsJson, source.id]);
|
|
915
|
+
// Attachments with their Global hidden flag, then their overrides.
|
|
916
|
+
const attachmentIds = JSON.stringify(await idMap('product_attachments'));
|
|
917
|
+
const attachments = await count(`insert into "product_attachments"
|
|
918
|
+
("id", "product_id", "asset_id", "attachment_type_id", "name", "description", "position", "hidden", "created_at", "updated_at")
|
|
919
|
+
select ${remap('id')}, ?, o."asset_id", o."attachment_type_id", o."name", o."description", o."position", o."hidden", now(), now()
|
|
920
|
+
from "product_attachments" o where o."product_id" = ?
|
|
921
|
+
returning "id"`, [attachmentIds, targetId, source.id]);
|
|
922
|
+
const attachmentOverrides = await count(`insert into "product_attachment_scope_overrides"
|
|
923
|
+
("id", "attachment_id", "product_id", "sales_channel_id", "language_code", "field", "value", "created_at", "updated_at")
|
|
924
|
+
select gen_random_uuid(), ${remap('attachment_id')}, ?, o."sales_channel_id", o."language_code", o."field", o."value", now(), now()
|
|
925
|
+
from "product_attachment_scope_overrides" o where o."product_id" = ?
|
|
926
|
+
returning "id"`, [attachmentIds, targetId, source.id]);
|
|
927
|
+
// Packaging units, then their name overrides.
|
|
928
|
+
const unitIds = JSON.stringify(await idMap('product_packaging_units'));
|
|
929
|
+
const packagingUnits = await count(`insert into "product_packaging_units"
|
|
930
|
+
("id", "product_id", "name", "base_quantity", "position", "is_default", "min_order_units", "created_at", "updated_at")
|
|
931
|
+
select ${remap('id')}, ?, o."name", o."base_quantity", o."position", o."is_default", o."min_order_units", now(), now()
|
|
932
|
+
from "product_packaging_units" o where o."product_id" = ?
|
|
933
|
+
returning "id"`, [unitIds, targetId, source.id]);
|
|
934
|
+
const packagingUnitOverrides = await count(`insert into "product_packaging_unit_scope_overrides"
|
|
935
|
+
("id", "packaging_unit_id", "product_id", "sales_channel_id", "language_code", "field", "value", "created_at", "updated_at")
|
|
936
|
+
select gen_random_uuid(), ${remap('packaging_unit_id')}, ?, o."sales_channel_id", o."language_code", o."field", o."value", now(), now()
|
|
937
|
+
from "product_packaging_unit_scope_overrides" o where o."product_id" = ?
|
|
938
|
+
returning "id"`, [unitIds, targetId, source.id]);
|
|
735
939
|
// product_links (only outgoing links are copied — incoming links from
|
|
736
940
|
// other products toward the source product stay attached to the source)
|
|
737
941
|
await em.execute(`insert into "product_links"
|
|
738
942
|
("id", "source_product_id", "target_product_id", "kind", "position", "created_at", "updated_at")
|
|
739
943
|
select gen_random_uuid(), ?, "target_product_id", "kind", "position", now(), now()
|
|
740
|
-
from "product_links" where "source_product_id" = ?`, [
|
|
944
|
+
from "product_links" where "source_product_id" = ?`, [targetId, source.id]);
|
|
741
945
|
// grouped_items (children of a grouped product)
|
|
742
946
|
if (source.type === 'grouped') {
|
|
743
947
|
await em.execute(`insert into "grouped_items"
|
|
744
948
|
("id", "parent_product_id", "child_product_id", "quantity", "position", "created_at", "updated_at")
|
|
745
949
|
select gen_random_uuid(), ?, "child_product_id", "quantity", "position", now(), now()
|
|
746
|
-
from "grouped_items" where "parent_product_id" = ?`, [
|
|
950
|
+
from "grouped_items" where "parent_product_id" = ?`, [targetId, source.id]);
|
|
747
951
|
}
|
|
748
952
|
// bundle_slots + bundle_slot_options
|
|
749
953
|
if (source.type === 'bundle') {
|
|
@@ -755,7 +959,7 @@ export class CatalogAdminService {
|
|
|
755
959
|
("id", "parent_product_id", "name", "min_quantity", "max_quantity", "position", "created_at", "updated_at")
|
|
756
960
|
values (?, ?, ?::jsonb, ?, ?, ?, now(), now())`, [
|
|
757
961
|
newSlotId,
|
|
758
|
-
|
|
962
|
+
targetId,
|
|
759
963
|
JSON.stringify(slot.name),
|
|
760
964
|
slot.min_quantity,
|
|
761
965
|
slot.max_quantity,
|
|
@@ -767,18 +971,6 @@ export class CatalogAdminService {
|
|
|
767
971
|
from "bundle_slot_options" where "slot_id" = ?`, [newSlotId, slot.id]);
|
|
768
972
|
}
|
|
769
973
|
}
|
|
770
|
-
// Per-(product, warehouse) low-stock thresholds, so the duplicate inherits
|
|
771
|
-
// the source's alerting profile. `inventory`'s rows and `inventory`'s
|
|
772
|
-
// Command since issue #185 — this used to be an `insert … select` into that
|
|
773
|
-
// module's table from here, which kept writing while an operator had the
|
|
774
|
-
// module switched off. No `catch` around it: the wiring decides presence in
|
|
775
|
-
// front of the gate and the degrade arrives as `'not-present'`.
|
|
776
|
-
if (this.copyWarehouseThresholds) {
|
|
777
|
-
await this.copyWarehouseThresholds({
|
|
778
|
-
sourceProductId: source.id,
|
|
779
|
-
targetProductId: dup.id,
|
|
780
|
-
});
|
|
781
|
-
}
|
|
782
974
|
// product_variants (configurable products) — each variant has its own
|
|
783
975
|
// unique SKU; we allocate copies the same way as the parent SKU.
|
|
784
976
|
if (source.type === 'configurable') {
|
|
@@ -786,7 +978,7 @@ export class CatalogAdminService {
|
|
|
786
978
|
for (const v of variants) {
|
|
787
979
|
const variantSku = await this.allocateCopySku(em, v.sku);
|
|
788
980
|
const newVariant = em.create(ProductVariant, {
|
|
789
|
-
parentProductId:
|
|
981
|
+
parentProductId: targetId,
|
|
790
982
|
sku: variantSku,
|
|
791
983
|
variantAttributeValues: { ...v.variantAttributeValues },
|
|
792
984
|
...(v.stockLevel != null ? { stockLevel: v.stockLevel } : {}),
|
|
@@ -795,13 +987,18 @@ export class CatalogAdminService {
|
|
|
795
987
|
}
|
|
796
988
|
await em.flush();
|
|
797
989
|
}
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
990
|
+
return {
|
|
991
|
+
valueOverrides,
|
|
992
|
+
channelScopes,
|
|
993
|
+
galleryItems,
|
|
994
|
+
galleryItemOverrides,
|
|
995
|
+
galleryRoles,
|
|
996
|
+
galleryRoleOverrides,
|
|
997
|
+
attachments,
|
|
998
|
+
attachmentOverrides,
|
|
999
|
+
packagingUnits,
|
|
1000
|
+
packagingUnitOverrides,
|
|
1001
|
+
};
|
|
805
1002
|
}
|
|
806
1003
|
/**
|
|
807
1004
|
* Find a free SKU derived from `baseSku` by appending `-copy`,
|
|
@@ -819,10 +1016,11 @@ export class CatalogAdminService {
|
|
|
819
1016
|
const suffix = i === 0 ? '-copy' : `-copy-${i + 1}`;
|
|
820
1017
|
const base = baseSku.slice(0, SKU_MAX_LENGTH - suffix.length);
|
|
821
1018
|
const candidate = `${base}${suffix}`;
|
|
822
|
-
|
|
1019
|
+
// Issue #693 — a deleted product or variant does not hold its SKU.
|
|
1020
|
+
const productHit = await em.findOne(Product, { sku: candidate, deletedAt: null });
|
|
823
1021
|
if (productHit)
|
|
824
1022
|
continue;
|
|
825
|
-
const variantHit = await em.findOne(ProductVariant, { sku: candidate });
|
|
1023
|
+
const variantHit = await em.findOne(ProductVariant, { sku: candidate, deletedAt: null });
|
|
826
1024
|
if (variantHit)
|
|
827
1025
|
continue;
|
|
828
1026
|
return candidate;
|
|
@@ -840,41 +1038,119 @@ export class CatalogAdminService {
|
|
|
840
1038
|
* Feature 068 — used by the create path as well as the duplication path; a
|
|
841
1039
|
* name collision on create used to reach the database and be reported as a
|
|
842
1040
|
* SKU conflict.
|
|
1041
|
+
*
|
|
1042
|
+
* Feature 163 (A-11) — a new product's slug is its key in every language, so
|
|
1043
|
+
* "free" means free as a URL key: no product's global key, and no live
|
|
1044
|
+
* product's current or redirecting key in any language.
|
|
1045
|
+
*
|
|
1046
|
+
* Must run inside the caller's transaction (the Command's): the decisive check is
|
|
1047
|
+
* made under the candidates' URL-key locks, which are transaction locks. The first
|
|
1048
|
+
* {@link SLUG_CANDIDATE_LOCKS} candidates that look free without a lock are locked
|
|
1049
|
+
* together, **once and in sorted order** — the order every key writer locks in, so
|
|
1050
|
+
* the two cannot deadlock — and re-checked under the locks in index order; the first
|
|
1051
|
+
* still free wins. A held lock is never released before the transaction ends, so
|
|
1052
|
+
* locking candidates one at a time after a lost race would acquire them out of
|
|
1053
|
+
* sorted order (`root-10` sorts before `root-9`). Losing every candidate of the set
|
|
1054
|
+
* to concurrent writers is refused like an exhausted search.
|
|
843
1055
|
*/
|
|
844
1056
|
async allocateUniqueSlug(em, source) {
|
|
845
1057
|
const root = this.slugify(source);
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
}
|
|
1058
|
+
const candidates = Array.from({ length: 1000 }, (_, i) => (i === 0 ? root : this.slugify(`${root}-${i + 1}`)));
|
|
1059
|
+
// Feature 174 (T039) — the URL-key service's allocation: probe, lock in sorted order, re-check.
|
|
1060
|
+
const slug = await allocateFreeSlug(em, candidates, SLUG_CANDIDATE_LOCKS);
|
|
1061
|
+
if (slug !== null)
|
|
1062
|
+
return slug;
|
|
852
1063
|
throw new HttpError(409, ERROR_CODES.VALIDATION_FAILED, `Could not allocate a unique slug derived from "${source}".`);
|
|
853
1064
|
}
|
|
854
1065
|
/**
|
|
855
|
-
*
|
|
856
|
-
*
|
|
857
|
-
* left untouched.
|
|
1066
|
+
* Feature 174 — the copy's Global name with a "(copy)" suffix, so the duplicate is obviously a
|
|
1067
|
+
* clone in lists. Its Channel and Channel × language names are copied verbatim (FR-119).
|
|
858
1068
|
*/
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
1069
|
+
suffixCopyName(name) {
|
|
1070
|
+
return name.trim() === '' ? name : `${name} (copy)`.slice(0, 255);
|
|
1071
|
+
}
|
|
1072
|
+
/**
|
|
1073
|
+
* Feature 163 (FR-019, research R30.3) — Archive one product: the `product.archive`
|
|
1074
|
+
* Command sets `archivedAt` and touches no status at any scope, and no
|
|
1075
|
+
* completeness gate runs. Announces `product.updated.v1` `['archivedAt']`, then
|
|
1076
|
+
* `product.archived.v1`, both after commit and in that order (one event scope,
|
|
1077
|
+
* dispatched in order and waited for — the search indexer's removal has finished
|
|
1078
|
+
* before this returns). Archiving an archived product is a no-op: no audit row,
|
|
1079
|
+
* no event, `changed: false`.
|
|
1080
|
+
*
|
|
1081
|
+
* 404 `PRODUCT_NOT_FOUND` for an unknown, soft-deleted or non-UUID id.
|
|
1082
|
+
*/
|
|
1083
|
+
async archiveProduct(id) {
|
|
1084
|
+
return this.#setArchived(id, true);
|
|
870
1085
|
}
|
|
871
1086
|
/**
|
|
872
|
-
*
|
|
873
|
-
*
|
|
874
|
-
* `product.
|
|
1087
|
+
* Feature 163 (FR-019) — Restore one product: the `product.restore` Command clears
|
|
1088
|
+
* `archivedAt`, announces `product.updated.v1` `['archivedAt']`, and leaves the
|
|
1089
|
+
* status where it is (an `inactive` product stays off). No-op on a product that is
|
|
1090
|
+
* not archived.
|
|
875
1091
|
*/
|
|
876
|
-
async
|
|
877
|
-
|
|
1092
|
+
async restoreProduct(id) {
|
|
1093
|
+
return this.#setArchived(id, false);
|
|
1094
|
+
}
|
|
1095
|
+
async #setArchived(id, archive) {
|
|
1096
|
+
// A non-UUID id would reach PostgreSQL as an invalid `uuid` literal.
|
|
1097
|
+
if (!uuidSchema.safeParse(id).success) {
|
|
1098
|
+
throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
|
|
1099
|
+
}
|
|
1100
|
+
const outcome = { changed: false };
|
|
1101
|
+
// The Command declares `product.updated.v1`; the Command Bus dispatches it
|
|
1102
|
+
// when its own scope ends, after commit. `product.archived.v1` is emitted
|
|
1103
|
+
// after that, into the scope opened here, so it is dispatched second.
|
|
1104
|
+
return this.events.run(async () => {
|
|
1105
|
+
const product = await this.#runCommand(this.#archiveCommand(id, archive, outcome));
|
|
1106
|
+
if (outcome.changed && archive)
|
|
1107
|
+
this.#emitArchived(product.id);
|
|
1108
|
+
return { product, changed: outcome.changed };
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
#archiveCommand(id, archive, outcome) {
|
|
1112
|
+
return {
|
|
1113
|
+
action: archive ? 'product.archive' : 'product.restore',
|
|
1114
|
+
objectType: 'product',
|
|
1115
|
+
objectId: id,
|
|
1116
|
+
run: async ({ em }) => {
|
|
1117
|
+
// Checkpoint C code review (C-W1) — the row lock serialises a single and a bulk
|
|
1118
|
+
// Archive of one product: the second reads the first's `archivedAt` and is the
|
|
1119
|
+
// no-op, so the transition is audited and announced once.
|
|
1120
|
+
if (!isUuidShape(id)) {
|
|
1121
|
+
throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
|
|
1122
|
+
}
|
|
1123
|
+
const product = await em.findOne(Product, { id, deletedAt: null }, { lockMode: LockMode.PESSIMISTIC_WRITE });
|
|
1124
|
+
if (!product) {
|
|
1125
|
+
throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
|
|
1126
|
+
}
|
|
1127
|
+
const before = product.archivedAt ?? null;
|
|
1128
|
+
if ((before !== null) === archive) {
|
|
1129
|
+
outcome.changed = false;
|
|
1130
|
+
return { result: product, skipAudit: true };
|
|
1131
|
+
}
|
|
1132
|
+
product.archivedAt = archive ? new Date() : null;
|
|
1133
|
+
em.persist(product);
|
|
1134
|
+
await em.flush();
|
|
1135
|
+
outcome.changed = true;
|
|
1136
|
+
return {
|
|
1137
|
+
result: product,
|
|
1138
|
+
before: { archivedAt: before?.toISOString() ?? null },
|
|
1139
|
+
after: { archivedAt: product.archivedAt?.toISOString() ?? null },
|
|
1140
|
+
};
|
|
1141
|
+
},
|
|
1142
|
+
event: (product) => outcome.changed
|
|
1143
|
+
? {
|
|
1144
|
+
eventName: 'product.updated.v1',
|
|
1145
|
+
payload: {
|
|
1146
|
+
eventId: randomUUID(),
|
|
1147
|
+
occurredAt: new Date().toISOString(),
|
|
1148
|
+
productId: product.id,
|
|
1149
|
+
changedFields: ['archivedAt'],
|
|
1150
|
+
},
|
|
1151
|
+
}
|
|
1152
|
+
: undefined,
|
|
1153
|
+
};
|
|
878
1154
|
}
|
|
879
1155
|
async assertProductDeletable(em, productId) {
|
|
880
1156
|
// `em.execute`, not `em.getKnex()`: the caller is `product.delete`'s Command
|
|
@@ -906,6 +1182,9 @@ export class CatalogAdminService {
|
|
|
906
1182
|
objectType: 'product',
|
|
907
1183
|
objectId: id,
|
|
908
1184
|
run: async ({ em }) => {
|
|
1185
|
+
if (!isUuidShape(id)) {
|
|
1186
|
+
throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
|
|
1187
|
+
}
|
|
909
1188
|
const product = await em.findOne(Product, { id, deletedAt: null });
|
|
910
1189
|
if (!product) {
|
|
911
1190
|
throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
|
|
@@ -914,14 +1193,25 @@ export class CatalogAdminService {
|
|
|
914
1193
|
const stateBefore = {
|
|
915
1194
|
status: product.status,
|
|
916
1195
|
sku: product.sku,
|
|
917
|
-
name:
|
|
1196
|
+
name: product.name,
|
|
918
1197
|
deletedAt: product.deletedAt ?? null,
|
|
919
1198
|
};
|
|
1199
|
+
// Feature 163 (FR-072) — a deleted product's old URL keys stop redirecting.
|
|
1200
|
+
const urlRedirects = (await em.find(ProductUrlRedirect, { productId: id })).map((row) => ({
|
|
1201
|
+
id: row.id,
|
|
1202
|
+
languageCode: row.languageCode ?? null,
|
|
1203
|
+
key: row.key,
|
|
1204
|
+
}));
|
|
1205
|
+
if (urlRedirects.length > 0)
|
|
1206
|
+
await em.nativeDelete(ProductUrlRedirect, { productId: id });
|
|
920
1207
|
product.deletedAt = new Date();
|
|
1208
|
+
// Issue #693 — the variants are deleted with their product, at the same instant, so
|
|
1209
|
+
// their SKUs are freed with the product's: uniqueness holds among live rows only.
|
|
1210
|
+
await em.nativeUpdate(ProductVariant, { parentProductId: id, deletedAt: null }, { deletedAt: product.deletedAt });
|
|
921
1211
|
await em.flush();
|
|
922
1212
|
return {
|
|
923
|
-
result: { id: product.id },
|
|
924
|
-
before: stateBefore,
|
|
1213
|
+
result: { id: product.id, formerUrlKeys: urlRedirects.map((row) => row.key) },
|
|
1214
|
+
before: { ...stateBefore, urlRedirects },
|
|
925
1215
|
after: {
|
|
926
1216
|
...stateBefore,
|
|
927
1217
|
deletedAt: product.deletedAt?.toISOString() ?? null,
|
|
@@ -934,6 +1224,7 @@ export class CatalogAdminService {
|
|
|
934
1224
|
eventId: randomUUID(),
|
|
935
1225
|
occurredAt: new Date().toISOString(),
|
|
936
1226
|
productId: result.id,
|
|
1227
|
+
formerUrlKeys: result.formerUrlKeys,
|
|
937
1228
|
},
|
|
938
1229
|
}),
|
|
939
1230
|
};
|
|
@@ -1004,16 +1295,16 @@ export class CatalogAdminService {
|
|
|
1004
1295
|
const em = this.emFactory();
|
|
1005
1296
|
const page = Math.max(0, options.page ?? 0);
|
|
1006
1297
|
const pageSize = Math.min(Math.max(1, options.pageSize ?? 20), 500);
|
|
1007
|
-
|
|
1008
|
-
//
|
|
1009
|
-
//
|
|
1298
|
+
const archivedMode = options.archived ?? 'exclude';
|
|
1299
|
+
// Feature 163 (R30.4) — the status and the archived mode are two independent
|
|
1300
|
+
// filters: `status` reads the status column, `archived` reads `archived_at`.
|
|
1010
1301
|
const where = { deletedAt: null };
|
|
1011
|
-
if (options.status)
|
|
1302
|
+
if (options.status)
|
|
1012
1303
|
where['status'] = options.status;
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1304
|
+
if (archivedMode === 'exclude')
|
|
1305
|
+
where['archivedAt'] = null;
|
|
1306
|
+
else if (archivedMode === 'only')
|
|
1307
|
+
where['archivedAt'] = { $ne: null };
|
|
1017
1308
|
if (options.type) {
|
|
1018
1309
|
where['type'] = options.type;
|
|
1019
1310
|
}
|
|
@@ -1021,23 +1312,7 @@ export class CatalogAdminService {
|
|
|
1021
1312
|
? await this.productIdsInCategoryTree(em, options.categorySlug.trim())
|
|
1022
1313
|
: null;
|
|
1023
1314
|
if (categoryProductIds && categoryProductIds.size === 0) {
|
|
1024
|
-
|
|
1025
|
-
// connection, so the status badges would be counted from outside a
|
|
1026
|
-
// transaction the caller holds open while `em.find` above answers from
|
|
1027
|
-
// inside it — one screen, two views of `products` (issue #207).
|
|
1028
|
-
const countRowsEmpty = (await em.execute(`select status, count(*) as count from products where deleted_at is null group by status`));
|
|
1029
|
-
const countsEmpty = { all: 0, active: 0, draft: 0, inactive: 0 };
|
|
1030
|
-
for (const row of countRowsEmpty) {
|
|
1031
|
-
const n = Number(row.count) || 0;
|
|
1032
|
-
countsEmpty.all += n;
|
|
1033
|
-
if (row.status === 'active')
|
|
1034
|
-
countsEmpty.active = n;
|
|
1035
|
-
else if (row.status === 'draft')
|
|
1036
|
-
countsEmpty.draft = n;
|
|
1037
|
-
else if (row.status === 'inactive')
|
|
1038
|
-
countsEmpty.inactive = n;
|
|
1039
|
-
}
|
|
1040
|
-
return { items: [], page, pageSize, total: 0, counts: countsEmpty };
|
|
1315
|
+
return { items: [], page, pageSize, total: 0, counts: await this.#productListCounts(em) };
|
|
1041
1316
|
}
|
|
1042
1317
|
if (categoryProductIds) {
|
|
1043
1318
|
where['id'] = { $in: [...categoryProductIds] };
|
|
@@ -1052,8 +1327,10 @@ export class CatalogAdminService {
|
|
|
1052
1327
|
qb.whereNull('deleted_at');
|
|
1053
1328
|
if (options.status)
|
|
1054
1329
|
qb.where('status', options.status);
|
|
1055
|
-
|
|
1056
|
-
qb.
|
|
1330
|
+
if (archivedMode === 'exclude')
|
|
1331
|
+
qb.whereNull('archived_at');
|
|
1332
|
+
else if (archivedMode === 'only')
|
|
1333
|
+
qb.whereNotNull('archived_at');
|
|
1057
1334
|
if (options.type)
|
|
1058
1335
|
qb.where('type', options.type);
|
|
1059
1336
|
if (categoryProductIds)
|
|
@@ -1098,24 +1375,37 @@ export class CatalogAdminService {
|
|
|
1098
1375
|
limit: pageSize,
|
|
1099
1376
|
});
|
|
1100
1377
|
}
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1378
|
+
return { items, page, pageSize, total, counts: await this.#productListCounts(em) };
|
|
1379
|
+
}
|
|
1380
|
+
/**
|
|
1381
|
+
* The admin list's tab badges, across the *full* product set whatever tab is
|
|
1382
|
+
* active, so they stay honest (feature 163, R30.4): `all`, `active` and
|
|
1383
|
+
* `inactive` over non-archived, non-deleted rows; `archived` over archived,
|
|
1384
|
+
* non-deleted rows of either status.
|
|
1385
|
+
*
|
|
1386
|
+
* `em.execute`, not `em.getKnex()`: a knex handle takes its own pooled
|
|
1387
|
+
* connection, so the badges would be counted from outside a transaction the
|
|
1388
|
+
* caller holds open while the page above answers from inside it — one screen,
|
|
1389
|
+
* two views of `products` (issue #207).
|
|
1390
|
+
*/
|
|
1391
|
+
async #productListCounts(em) {
|
|
1392
|
+
const rows = (await em.execute(`select status, (archived_at is not null) as archived, count(*) as count
|
|
1393
|
+
from products where deleted_at is null
|
|
1394
|
+
group by status, (archived_at is not null)`));
|
|
1395
|
+
const counts = { all: 0, active: 0, inactive: 0, archived: 0 };
|
|
1396
|
+
for (const row of rows) {
|
|
1109
1397
|
const n = Number(row.count) || 0;
|
|
1398
|
+
if (row.archived) {
|
|
1399
|
+
counts.archived += n;
|
|
1400
|
+
continue;
|
|
1401
|
+
}
|
|
1110
1402
|
counts.all += n;
|
|
1111
1403
|
if (row.status === 'active')
|
|
1112
|
-
counts.active
|
|
1113
|
-
else if (row.status === 'draft')
|
|
1114
|
-
counts.draft = n;
|
|
1404
|
+
counts.active += n;
|
|
1115
1405
|
else if (row.status === 'inactive')
|
|
1116
|
-
counts.inactive
|
|
1406
|
+
counts.inactive += n;
|
|
1117
1407
|
}
|
|
1118
|
-
return
|
|
1408
|
+
return counts;
|
|
1119
1409
|
}
|
|
1120
1410
|
/**
|
|
1121
1411
|
* Feature 033 — return all product ids matching list filters (no pagination).
|
|
@@ -1126,16 +1416,18 @@ export class CatalogAdminService {
|
|
|
1126
1416
|
const em = this.emFactory();
|
|
1127
1417
|
const trimmedQ = options.q?.trim();
|
|
1128
1418
|
const knex = em.getKnex();
|
|
1419
|
+
const archivedMode = options.archived ?? 'exclude';
|
|
1129
1420
|
const applyListFilters = (qb) => {
|
|
1130
|
-
// Mirror listProducts: soft-deleted rows are never selectable
|
|
1131
|
-
//
|
|
1421
|
+
// Mirror listProducts: soft-deleted rows are never selectable; the status
|
|
1422
|
+
// and the archived mode are independent filters (feature 163, R30.4).
|
|
1132
1423
|
qb.whereNull('deleted_at');
|
|
1133
1424
|
if (options.status) {
|
|
1134
1425
|
qb.where('status', options.status);
|
|
1135
1426
|
}
|
|
1136
|
-
|
|
1137
|
-
qb.
|
|
1138
|
-
|
|
1427
|
+
if (archivedMode === 'exclude')
|
|
1428
|
+
qb.whereNull('archived_at');
|
|
1429
|
+
else if (archivedMode === 'only')
|
|
1430
|
+
qb.whereNotNull('archived_at');
|
|
1139
1431
|
if (options.type) {
|
|
1140
1432
|
qb.where('type', options.type);
|
|
1141
1433
|
}
|
|
@@ -1164,6 +1456,9 @@ export class CatalogAdminService {
|
|
|
1164
1456
|
}
|
|
1165
1457
|
async getProductById(id) {
|
|
1166
1458
|
const em = this.emFactory();
|
|
1459
|
+
if (!isUuidShape(id)) {
|
|
1460
|
+
throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
|
|
1461
|
+
}
|
|
1167
1462
|
const product = await em.findOne(Product, { id, deletedAt: null });
|
|
1168
1463
|
if (!product) {
|
|
1169
1464
|
throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
|
|
@@ -1340,6 +1635,19 @@ export class CatalogAdminService {
|
|
|
1340
1635
|
}
|
|
1341
1636
|
return view;
|
|
1342
1637
|
}
|
|
1638
|
+
/**
|
|
1639
|
+
* Feature 172 (FR-007 – FR-009, research R-21) — what deleting the attribute
|
|
1640
|
+
* would meet, for the attributes screen's confirmation dialog. The same query
|
|
1641
|
+
* the delete Command's guard runs, so the dialog and the refusal agree.
|
|
1642
|
+
*/
|
|
1643
|
+
async getAttributeUsage(idOrKey) {
|
|
1644
|
+
const attr = await this.getAttributeByIdOrKey(idOrKey);
|
|
1645
|
+
return readAttributeUsage(this.emFactory(), {
|
|
1646
|
+
definitionId: attr.customFieldDefinitionId,
|
|
1647
|
+
extensionId: attr.id,
|
|
1648
|
+
key: attr.key,
|
|
1649
|
+
});
|
|
1650
|
+
}
|
|
1343
1651
|
/**
|
|
1344
1652
|
* Feature 012 — delete an attribute. Refused while any Attribute Set or
|
|
1345
1653
|
* product still references it (FR-006). The structured error names the
|
|
@@ -1371,15 +1679,20 @@ export class CatalogAdminService {
|
|
|
1371
1679
|
}
|
|
1372
1680
|
async createVariant(parentProductId, req) {
|
|
1373
1681
|
const em = this.emFactory();
|
|
1374
|
-
|
|
1682
|
+
if (!isUuidShape(parentProductId)) {
|
|
1683
|
+
throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, `Product ${parentProductId} not found.`);
|
|
1684
|
+
}
|
|
1685
|
+
// A deleted parent answers as an unknown one (#869).
|
|
1686
|
+
const parent = await em.findOne(Product, { id: parentProductId, deletedAt: null });
|
|
1375
1687
|
if (!parent) {
|
|
1376
1688
|
throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, `Product ${parentProductId} not found.`);
|
|
1377
1689
|
}
|
|
1378
1690
|
if (parent.type !== 'configurable') {
|
|
1379
1691
|
throw new HttpError(400, ERROR_CODES.VALIDATION_FAILED, `Variants can only be added to configurable Products; this Product is ${parent.type}.`);
|
|
1380
1692
|
}
|
|
1381
|
-
// SKU uniqueness MUST hold across both products and variants
|
|
1382
|
-
|
|
1693
|
+
// SKU uniqueness MUST hold across both products and variants — among live
|
|
1694
|
+
// rows: a deleted product does not hold its SKU (issue #693).
|
|
1695
|
+
const existingProduct = await em.findOne(Product, { sku: req.sku, deletedAt: null });
|
|
1383
1696
|
if (existingProduct) {
|
|
1384
1697
|
throw new HttpError(409, ERROR_CODES.SKU_ALREADY_EXISTS, `SKU "${req.sku}" already taken by an existing Product.`);
|
|
1385
1698
|
}
|
|
@@ -1413,6 +1726,9 @@ export class CatalogAdminService {
|
|
|
1413
1726
|
}
|
|
1414
1727
|
async updateVariant(parentProductId, variantId, req) {
|
|
1415
1728
|
const variant = await this.#auditedWrite('product_variant.update', 'product_variant', variantId, async (em) => {
|
|
1729
|
+
if (!isUuidShape(variantId) || !isUuidShape(parentProductId)) {
|
|
1730
|
+
throw new HttpError(404, ERROR_CODES.NOT_FOUND, `Variant ${variantId} not found under Product ${parentProductId}.`);
|
|
1731
|
+
}
|
|
1416
1732
|
const v = await em.findOne(ProductVariant, { id: variantId, parentProductId });
|
|
1417
1733
|
if (!v) {
|
|
1418
1734
|
throw new HttpError(404, ERROR_CODES.NOT_FOUND, `Variant ${variantId} not found under Product ${parentProductId}.`);
|
|
@@ -1444,6 +1760,9 @@ export class CatalogAdminService {
|
|
|
1444
1760
|
}
|
|
1445
1761
|
async deleteVariant(parentProductId, variantId) {
|
|
1446
1762
|
await this.#auditedWrite('product_variant.delete', 'product_variant', variantId, async (em) => {
|
|
1763
|
+
if (!isUuidShape(variantId) || !isUuidShape(parentProductId)) {
|
|
1764
|
+
throw new HttpError(404, ERROR_CODES.NOT_FOUND, `Variant ${variantId} not found under Product ${parentProductId}.`);
|
|
1765
|
+
}
|
|
1447
1766
|
const variant = await em.findOne(ProductVariant, { id: variantId, parentProductId });
|
|
1448
1767
|
if (!variant) {
|
|
1449
1768
|
// DELETE is idempotent — but we still 404 here so admins notice
|
|
@@ -1482,6 +1801,13 @@ export class CatalogAdminService {
|
|
|
1482
1801
|
const keys = Object.keys(attributeValues);
|
|
1483
1802
|
if (keys.length === 0)
|
|
1484
1803
|
return;
|
|
1804
|
+
const views = await this.#requireAttributeRead().listAll();
|
|
1805
|
+
// Feature 172 (FR-014, research R-7) — a Page Builder content attribute's
|
|
1806
|
+
// key is refused **before** the `existingKeys` exemption below: whether it
|
|
1807
|
+
// is new to this save or resent as "already stored", its value is a
|
|
1808
|
+
// document authored on the product content screen, never an attribute
|
|
1809
|
+
// value. This is the one guard every product write crosses.
|
|
1810
|
+
assertNoContentAttributeValues(attributeValues, views);
|
|
1485
1811
|
// Feature 061 — set membership is keyed by definition id; the key lives on
|
|
1486
1812
|
// the definition, resolved through the composed view (Principle I).
|
|
1487
1813
|
//
|
|
@@ -1492,7 +1818,6 @@ export class CatalogAdminService {
|
|
|
1492
1818
|
const rows = (await em.execute(`select custom_field_definition_id
|
|
1493
1819
|
from attribute_set_attributes
|
|
1494
1820
|
where attribute_set_id = ?`, [attributeSetId]));
|
|
1495
|
-
const views = await this.#requireAttributeRead().listAll();
|
|
1496
1821
|
const keyByDefinitionId = new Map(views.map((v) => [v.customFieldDefinitionId, v.key]));
|
|
1497
1822
|
const allowed = new Set(rows
|
|
1498
1823
|
.map((r) => keyByDefinitionId.get(r.custom_field_definition_id))
|
|
@@ -1520,14 +1845,9 @@ export class CatalogAdminService {
|
|
|
1520
1845
|
where attribute_set_id = ?`, [attributeSetId]));
|
|
1521
1846
|
const views = await this.#requireAttributeRead().listAll();
|
|
1522
1847
|
const viewByDefinitionId = new Map(views.map((v) => [v.customFieldDefinitionId, v]));
|
|
1523
|
-
const missing = rows
|
|
1848
|
+
const missing = missingRequiredAttributeKeys(rows
|
|
1524
1849
|
.map((r) => viewByDefinitionId.get(r.custom_field_definition_id))
|
|
1525
|
-
.filter((v) => v !== undefined
|
|
1526
|
-
.map((v) => v.key)
|
|
1527
|
-
.filter((k) => {
|
|
1528
|
-
const v = mergedAttributeValues[k];
|
|
1529
|
-
return v === undefined || v === null || v === '';
|
|
1530
|
-
});
|
|
1850
|
+
.filter((v) => v !== undefined), mergedAttributeValues);
|
|
1531
1851
|
if (missing.length > 0) {
|
|
1532
1852
|
throw new HttpError(400, ERROR_CODES.VALIDATION_FAILED, `missing_required_attribute_values: ${missing.join(', ')}`);
|
|
1533
1853
|
}
|
|
@@ -1540,6 +1860,9 @@ export class CatalogAdminService {
|
|
|
1540
1860
|
*/
|
|
1541
1861
|
async previewAttributeSetSwap(productId, targetSetId) {
|
|
1542
1862
|
const em = this.emFactory();
|
|
1863
|
+
if (!isUuidShape(productId)) {
|
|
1864
|
+
throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
|
|
1865
|
+
}
|
|
1543
1866
|
const product = await em.findOne(Product, { id: productId });
|
|
1544
1867
|
if (!product) {
|
|
1545
1868
|
throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
|
|
@@ -1621,10 +1944,6 @@ export class CatalogAdminService {
|
|
|
1621
1944
|
slugify(value) {
|
|
1622
1945
|
return slugifyText(value, { maxLength: 160 });
|
|
1623
1946
|
}
|
|
1624
|
-
anyValue(blob) {
|
|
1625
|
-
const key = Object.keys(blob)[0];
|
|
1626
|
-
return key ? (blob[key] ?? '') : '';
|
|
1627
|
-
}
|
|
1628
1947
|
}
|
|
1629
1948
|
/**
|
|
1630
1949
|
* Feature 155 (FR-001, threat F5, D5) — a pieces minimum is an integer in
|