@endora-commerce/mod-cms 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/README.md +1 -0
- package/dist/admin/api/cms-client.d.ts +19 -3
- package/dist/admin/api/cms-client.d.ts.map +1 -1
- package/dist/admin/api/cms-client.js +23 -2
- package/dist/admin/api/cms-client.js.map +1 -1
- package/dist/admin/components/AdminCatalogPreviewProvider.d.ts +9 -0
- package/dist/admin/components/AdminCatalogPreviewProvider.d.ts.map +1 -1
- package/dist/admin/components/AdminCatalogPreviewProvider.js +88 -3
- package/dist/admin/components/AdminCatalogPreviewProvider.js.map +1 -1
- package/dist/admin/components/BackgroundFields.d.ts +16 -0
- package/dist/admin/components/BackgroundFields.d.ts.map +1 -1
- package/dist/admin/components/BackgroundFields.js +58 -11
- package/dist/admin/components/BackgroundFields.js.map +1 -1
- package/dist/admin/components/BrandFontFields.d.ts +17 -0
- package/dist/admin/components/BrandFontFields.d.ts.map +1 -0
- package/dist/admin/components/BrandFontFields.js +39 -0
- package/dist/admin/components/BrandFontFields.js.map +1 -0
- package/dist/admin/components/BrandPreview.d.ts +29 -0
- package/dist/admin/components/BrandPreview.d.ts.map +1 -0
- package/dist/admin/components/BrandPreview.js +130 -0
- package/dist/admin/components/BrandPreview.js.map +1 -0
- package/dist/admin/components/CarouselAddSlideMenu.d.ts +5 -0
- package/dist/admin/components/CarouselAddSlideMenu.d.ts.map +1 -0
- package/dist/admin/components/CarouselAddSlideMenu.js +84 -0
- package/dist/admin/components/CarouselAddSlideMenu.js.map +1 -0
- package/dist/admin/components/CarouselFields.d.ts +6 -0
- package/dist/admin/components/CarouselFields.d.ts.map +1 -0
- package/dist/admin/components/CarouselFields.js +55 -0
- package/dist/admin/components/CarouselFields.js.map +1 -0
- package/dist/admin/components/ContentSliderActionBarExtras.d.ts.map +1 -1
- package/dist/admin/components/ContentSliderActionBarExtras.js +13 -6
- package/dist/admin/components/ContentSliderActionBarExtras.js.map +1 -1
- package/dist/admin/components/FormBlockFields.d.ts +15 -0
- package/dist/admin/components/FormBlockFields.d.ts.map +1 -0
- package/dist/admin/components/FormBlockFields.js +23 -0
- package/dist/admin/components/FormBlockFields.js.map +1 -0
- package/dist/admin/components/HeroFields.d.ts +47 -0
- package/dist/admin/components/HeroFields.d.ts.map +1 -0
- package/dist/admin/components/HeroFields.js +92 -0
- package/dist/admin/components/HeroFields.js.map +1 -0
- package/dist/admin/components/ListingFields.d.ts +6 -0
- package/dist/admin/components/ListingFields.d.ts.map +1 -0
- package/dist/admin/components/ListingFields.js +54 -0
- package/dist/admin/components/ListingFields.js.map +1 -0
- package/dist/admin/components/NewsletterSignupFields.d.ts +18 -0
- package/dist/admin/components/NewsletterSignupFields.d.ts.map +1 -0
- package/dist/admin/components/NewsletterSignupFields.js +38 -0
- package/dist/admin/components/NewsletterSignupFields.js.map +1 -0
- package/dist/admin/components/PageBuilderActionBar.d.ts.map +1 -1
- package/dist/admin/components/PageBuilderActionBar.js +1 -6
- package/dist/admin/components/PageBuilderActionBar.js.map +1 -1
- package/dist/admin/components/PageBuilderEditor.d.ts +43 -2
- package/dist/admin/components/PageBuilderEditor.d.ts.map +1 -1
- package/dist/admin/components/PageBuilderEditor.js +218 -123
- package/dist/admin/components/PageBuilderEditor.js.map +1 -1
- package/dist/admin/components/PageNavigationFields.d.ts +6 -0
- package/dist/admin/components/PageNavigationFields.d.ts.map +1 -0
- package/dist/admin/components/PageNavigationFields.js +29 -0
- package/dist/admin/components/PageNavigationFields.js.map +1 -0
- package/dist/admin/components/PreviewBrandTokens.d.ts +25 -0
- package/dist/admin/components/PreviewBrandTokens.d.ts.map +1 -0
- package/dist/admin/components/PreviewBrandTokens.js +68 -0
- package/dist/admin/components/PreviewBrandTokens.js.map +1 -0
- package/dist/admin/components/SectionBlockFields.d.ts +44 -0
- package/dist/admin/components/SectionBlockFields.d.ts.map +1 -0
- package/dist/admin/components/SectionBlockFields.js +114 -0
- package/dist/admin/components/SectionBlockFields.js.map +1 -0
- package/dist/admin/components/SectionPresetsPanel.d.ts +11 -0
- package/dist/admin/components/SectionPresetsPanel.d.ts.map +1 -0
- package/dist/admin/components/SectionPresetsPanel.js +82 -0
- package/dist/admin/components/SectionPresetsPanel.js.map +1 -0
- package/dist/admin/components/SliderPreviewActionBarExtras.d.ts +1 -1
- package/dist/admin/components/SliderPreviewActionBarExtras.d.ts.map +1 -1
- package/dist/admin/components/SliderPreviewActionBarExtras.js +1 -5
- package/dist/admin/components/SliderPreviewActionBarExtras.js.map +1 -1
- package/dist/admin/components/admin-catalog-preview-map.d.ts +10 -1
- package/dist/admin/components/admin-catalog-preview-map.d.ts.map +1 -1
- package/dist/admin/components/admin-catalog-preview-map.js +11 -1
- package/dist/admin/components/admin-catalog-preview-map.js.map +1 -1
- package/dist/admin/components/block-contributions.d.ts +15 -0
- package/dist/admin/components/block-contributions.d.ts.map +1 -1
- package/dist/admin/components/block-contributions.js +22 -0
- package/dist/admin/components/block-contributions.js.map +1 -1
- package/dist/admin/components/page-builder-i18n.d.ts +24 -2
- package/dist/admin/components/page-builder-i18n.d.ts.map +1 -1
- package/dist/admin/components/page-builder-i18n.js +102 -9
- package/dist/admin/components/page-builder-i18n.js.map +1 -1
- package/dist/admin/editors/PageEditor.d.ts.map +1 -1
- package/dist/admin/editors/PageEditor.js +270 -38
- package/dist/admin/editors/PageEditor.js.map +1 -1
- package/dist/admin/index.d.ts +1 -1
- package/dist/admin/index.d.ts.map +1 -1
- package/dist/admin/index.js +28 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/pages/BrandPage.d.ts +19 -0
- package/dist/admin/pages/BrandPage.d.ts.map +1 -0
- package/dist/admin/pages/BrandPage.js +316 -0
- package/dist/admin/pages/BrandPage.js.map +1 -0
- package/dist/admin/pages/PagesListPage.d.ts.map +1 -1
- package/dist/admin/pages/PagesListPage.js +4 -1
- package/dist/admin/pages/PagesListPage.js.map +1 -1
- package/dist/admin/zones/ProductContentEditor.d.ts +27 -0
- package/dist/admin/zones/ProductContentEditor.d.ts.map +1 -0
- package/dist/admin/zones/ProductContentEditor.js +28 -0
- package/dist/admin/zones/ProductContentEditor.js.map +1 -0
- package/dist/backend/cli/block-names.d.ts +2 -1
- package/dist/backend/cli/block-names.d.ts.map +1 -1
- package/dist/backend/cli/block-names.js.map +1 -1
- package/dist/backend/entities/cms-brand-tokens.entity.d.ts +20 -0
- package/dist/backend/entities/cms-brand-tokens.entity.d.ts.map +1 -0
- package/dist/backend/entities/cms-brand-tokens.entity.js +57 -0
- package/dist/backend/entities/cms-brand-tokens.entity.js.map +1 -0
- package/dist/backend/entities/cms-page.entity.d.ts +32 -1
- package/dist/backend/entities/cms-page.entity.d.ts.map +1 -1
- package/dist/backend/entities/cms-page.entity.js +63 -0
- package/dist/backend/entities/cms-page.entity.js.map +1 -1
- package/dist/backend/index.d.ts +8 -1
- package/dist/backend/index.d.ts.map +1 -1
- package/dist/backend/index.js +90 -10
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/plugin.d.ts +18 -2
- package/dist/backend/plugin.d.ts.map +1 -1
- package/dist/backend/plugin.js +23 -1
- package/dist/backend/plugin.js.map +1 -1
- package/dist/backend/routes.admin.d.ts +2 -0
- package/dist/backend/routes.admin.d.ts.map +1 -1
- package/dist/backend/routes.admin.js +42 -8
- package/dist/backend/routes.admin.js.map +1 -1
- package/dist/backend/routes.storefront.d.ts +24 -1
- package/dist/backend/routes.storefront.d.ts.map +1 -1
- package/dist/backend/routes.storefront.js +55 -2
- package/dist/backend/routes.storefront.js.map +1 -1
- package/dist/backend/services/anchor-guard.d.ts +10 -0
- package/dist/backend/services/anchor-guard.d.ts.map +1 -0
- package/dist/backend/services/anchor-guard.js +132 -0
- package/dist/backend/services/anchor-guard.js.map +1 -0
- package/dist/backend/services/asset-embed-resolver.d.ts +18 -10
- package/dist/backend/services/asset-embed-resolver.d.ts.map +1 -1
- package/dist/backend/services/asset-embed-resolver.js +35 -30
- package/dist/backend/services/asset-embed-resolver.js.map +1 -1
- package/dist/backend/services/asset-references.d.ts.map +1 -1
- package/dist/backend/services/asset-references.js +46 -30
- package/dist/backend/services/asset-references.js.map +1 -1
- package/dist/backend/services/brand-tokens-service.d.ts +84 -0
- package/dist/backend/services/brand-tokens-service.d.ts.map +1 -0
- package/dist/backend/services/brand-tokens-service.js +159 -0
- package/dist/backend/services/brand-tokens-service.js.map +1 -0
- package/dist/backend/services/channel-language-prefixes.d.ts +11 -0
- package/dist/backend/services/channel-language-prefixes.d.ts.map +1 -0
- package/dist/backend/services/channel-language-prefixes.js +24 -0
- package/dist/backend/services/channel-language-prefixes.js.map +1 -0
- package/dist/backend/services/cms-block-read-port.d.ts.map +1 -1
- package/dist/backend/services/cms-block-read-port.js +3 -0
- package/dist/backend/services/cms-block-read-port.js.map +1 -1
- package/dist/backend/services/cms-block-service.d.ts.map +1 -1
- package/dist/backend/services/cms-block-service.js +7 -1
- package/dist/backend/services/cms-block-service.js.map +1 -1
- package/dist/backend/services/cms-cache.d.ts +10 -0
- package/dist/backend/services/cms-cache.d.ts.map +1 -1
- package/dist/backend/services/cms-cache.js +9 -0
- package/dist/backend/services/cms-cache.js.map +1 -1
- package/dist/backend/services/cms-content-invalidator.d.ts +13 -4
- package/dist/backend/services/cms-content-invalidator.d.ts.map +1 -1
- package/dist/backend/services/cms-content-invalidator.js +13 -6
- package/dist/backend/services/cms-content-invalidator.js.map +1 -1
- package/dist/backend/services/cms-hook-service.d.ts.map +1 -1
- package/dist/backend/services/cms-hook-service.js +6 -1
- package/dist/backend/services/cms-hook-service.js.map +1 -1
- package/dist/backend/services/cms-page-read-port.d.ts +12 -1
- package/dist/backend/services/cms-page-read-port.d.ts.map +1 -1
- package/dist/backend/services/cms-page-read-port.js +49 -0
- package/dist/backend/services/cms-page-read-port.js.map +1 -1
- package/dist/backend/services/cms-page-service.d.ts +79 -1
- package/dist/backend/services/cms-page-service.d.ts.map +1 -1
- package/dist/backend/services/cms-page-service.js +344 -19
- package/dist/backend/services/cms-page-service.js.map +1 -1
- package/dist/backend/services/cms-template-service.d.ts.map +1 -1
- package/dist/backend/services/cms-template-service.js +7 -1
- package/dist/backend/services/cms-template-service.js.map +1 -1
- package/dist/backend/services/contact-form/contact-form-mail.d.ts +22 -0
- package/dist/backend/services/contact-form/contact-form-mail.d.ts.map +1 -0
- package/dist/backend/services/contact-form/contact-form-mail.js +64 -0
- package/dist/backend/services/contact-form/contact-form-mail.js.map +1 -0
- package/dist/backend/services/contact-form/contact-form.service.d.ts +35 -0
- package/dist/backend/services/contact-form/contact-form.service.d.ts.map +1 -0
- package/dist/backend/services/contact-form/contact-form.service.js +75 -0
- package/dist/backend/services/contact-form/contact-form.service.js.map +1 -0
- package/dist/backend/services/contact-form/recipients-validator.d.ts +8 -0
- package/dist/backend/services/contact-form/recipients-validator.d.ts.map +1 -0
- package/dist/backend/services/contact-form/recipients-validator.js +23 -0
- package/dist/backend/services/contact-form/recipients-validator.js.map +1 -0
- package/dist/backend/services/content-tree-walker.d.ts +12 -0
- package/dist/backend/services/content-tree-walker.d.ts.map +1 -1
- package/dist/backend/services/content-tree-walker.js +40 -0
- package/dist/backend/services/content-tree-walker.js.map +1 -1
- package/dist/backend/services/page-builder-registry.d.ts +11 -2
- package/dist/backend/services/page-builder-registry.d.ts.map +1 -1
- package/dist/backend/services/page-builder-registry.js +10 -1
- package/dist/backend/services/page-builder-registry.js.map +1 -1
- package/dist/backend/services/page-paths.d.ts +87 -0
- package/dist/backend/services/page-paths.d.ts.map +1 -0
- package/dist/backend/services/page-paths.js +177 -0
- package/dist/backend/services/page-paths.js.map +1 -0
- package/dist/backend/services/reserved-segment-registry.d.ts +16 -0
- package/dist/backend/services/reserved-segment-registry.d.ts.map +1 -0
- package/dist/backend/services/reserved-segment-registry.js +31 -0
- package/dist/backend/services/reserved-segment-registry.js.map +1 -0
- package/dist/backend/services/storefront-resolver.d.ts +58 -3
- package/dist/backend/services/storefront-resolver.d.ts.map +1 -1
- package/dist/backend/services/storefront-resolver.js +314 -29
- package/dist/backend/services/storefront-resolver.js.map +1 -1
- package/dist/backend/services/translation/extract.d.ts.map +1 -1
- package/dist/backend/services/translation/extract.js +9 -1
- package/dist/backend/services/translation/extract.js.map +1 -1
- package/dist/manifest.d.ts +19 -1
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +592 -73
- package/dist/manifest.js.map +1 -1
- package/dist/migrations/20261022T163218_cms_brand_tokens.d.ts +24 -0
- package/dist/migrations/20261022T163218_cms_brand_tokens.d.ts.map +1 -0
- package/dist/migrations/20261022T163218_cms_brand_tokens.js +38 -0
- package/dist/migrations/20261022T163218_cms_brand_tokens.js.map +1 -0
- package/dist/migrations/20261023T052237_cms_page_tree_and_share.d.ts +24 -0
- package/dist/migrations/20261023T052237_cms_page_tree_and_share.d.ts.map +1 -0
- package/dist/migrations/20261023T052237_cms_page_tree_and_share.js +51 -0
- package/dist/migrations/20261023T052237_cms_page_tree_and_share.js.map +1 -0
- package/dist/migrations/20261027T165458_cms_page_parent_path_in_url.d.ts +16 -0
- package/dist/migrations/20261027T165458_cms_page_parent_path_in_url.d.ts.map +1 -0
- package/dist/migrations/20261027T165458_cms_page_parent_path_in_url.js +20 -0
- package/dist/migrations/20261027T165458_cms_page_parent_path_in_url.js.map +1 -0
- package/dist/migrations/20261028T090524_cms_page_breadcrumbs_overlay.d.ts +14 -0
- package/dist/migrations/20261028T090524_cms_page_breadcrumbs_overlay.d.ts.map +1 -0
- package/dist/migrations/20261028T090524_cms_page_breadcrumbs_overlay.js +18 -0
- package/dist/migrations/20261028T090524_cms_page_breadcrumbs_overlay.js.map +1 -0
- package/dist/migrations/20261029T131218_cms_page_translations.d.ts +15 -0
- package/dist/migrations/20261029T131218_cms_page_translations.d.ts.map +1 -0
- package/dist/migrations/20261029T131218_cms_page_translations.js +19 -0
- package/dist/migrations/20261029T131218_cms_page_translations.js.map +1 -0
- package/dist/migrations/index.d.ts +6 -1
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +11 -1
- package/dist/migrations/index.js.map +1 -1
- package/docs/cms/brand.md +310 -0
- package/docs/cms/contact-form.md +161 -0
- package/docs/cms/extending-page-builder.md +210 -15
- package/docs/cms/index.md +1232 -39
- package/docs/cms/page-navigation.md +83 -0
- package/i18n/en.json +2787 -45
- package/i18n/pl.json +2765 -23
- package/package.json +20 -18
- package/dist/admin/components/ButtonLinkFields.d.ts +0 -6
- package/dist/admin/components/ButtonLinkFields.d.ts.map +0 -1
- package/dist/admin/components/ButtonLinkFields.js +0 -127
- package/dist/admin/components/ButtonLinkFields.js.map +0 -1
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { randomUUID } from 'crypto';
|
|
2
|
-
import { ERROR_CODES, firstSlugSegment, } from '@endora-commerce/contracts';
|
|
2
|
+
import { ERROR_CODES, firstSlugSegment, isUuidShape, } from '@endora-commerce/contracts';
|
|
3
3
|
import { HttpError } from '@endora-commerce/platform/http';
|
|
4
4
|
import { SalesChannel } from '@endora-commerce/platform/kernel';
|
|
5
5
|
import { walkBlockEmbeds, walkUnknownComponents } from './content-tree-walker.js';
|
|
6
|
+
import { assertAnchors } from './anchor-guard.js';
|
|
7
|
+
import { addressesOf, anyNested, duplicatePath, loadChannelPageNodes } from './page-paths.js';
|
|
6
8
|
const emptyContent = { languages: {} };
|
|
9
|
+
/**
|
|
10
|
+
* The deepest page tree a parent write may produce, counted in levels with the
|
|
11
|
+
* root as level one (feature 163, research R-18). The storefront trail of a
|
|
12
|
+
* level-eight page therefore names at most seven ancestors, and the resolver's
|
|
13
|
+
* own walk stays bounded by the same number.
|
|
14
|
+
*/
|
|
15
|
+
export const CMS_PAGE_TREE_MAX_DEPTH = 8;
|
|
7
16
|
/**
|
|
8
17
|
* The reserved set as the refusal reads it, from the value an operator typed.
|
|
9
18
|
*
|
|
@@ -27,6 +36,27 @@ export function normalizeReservedSegments(value) {
|
|
|
27
36
|
}
|
|
28
37
|
return [...out];
|
|
29
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* The per-language overrides as they are stored (R24): a blank field is an
|
|
41
|
+
* inherited one, so it is not written, and a language left with no field is
|
|
42
|
+
* not written either. One spelling of "inherits" — absent — keeps the stored
|
|
43
|
+
* map comparable across saves and its audit entries free of noise.
|
|
44
|
+
*/
|
|
45
|
+
export function normalizeTranslations(translations) {
|
|
46
|
+
const out = {};
|
|
47
|
+
for (const [language, entry] of Object.entries(translations)) {
|
|
48
|
+
const kept = {};
|
|
49
|
+
if (entry.name !== undefined && entry.name.trim().length > 0)
|
|
50
|
+
kept.name = entry.name.trim();
|
|
51
|
+
if (entry.slug !== undefined && entry.slug.trim().length > 0)
|
|
52
|
+
kept.slug = entry.slug.trim();
|
|
53
|
+
if (entry.description !== undefined && entry.description.trim().length > 0)
|
|
54
|
+
kept.description = entry.description;
|
|
55
|
+
if (Object.keys(kept).length > 0)
|
|
56
|
+
out[language] = kept;
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
30
60
|
/**
|
|
31
61
|
* The audit `objectType` of every Page write. One value, so the trail of one
|
|
32
62
|
* page is one query whichever of the seven actions wrote the row.
|
|
@@ -78,6 +108,29 @@ export class CmsPageService {
|
|
|
78
108
|
setReservedSegmentsResolver(resolver) {
|
|
79
109
|
this.reservedSegmentsResolver = resolver;
|
|
80
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Feature 167 (FR-040, FR-041) — every sales channel's storefront language
|
|
113
|
+
* prefixes and split aliases, each with the codes of the channels using it. Read
|
|
114
|
+
* through the kernel's channel port (`sales_channels` is non-deactivatable); absent
|
|
115
|
+
* until `registerModule` installs it, which reserves nothing.
|
|
116
|
+
*/
|
|
117
|
+
languagePrefixesResolver = null;
|
|
118
|
+
setLanguagePrefixesResolver(resolver) {
|
|
119
|
+
this.languagePrefixesResolver = resolver;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Feature 171 (research R5) — first segments other modules serve in the given
|
|
123
|
+
* channels (the blog's prefixes), each with the module that claims it. Absent
|
|
124
|
+
* until `registerModule` installs it, which claims nothing.
|
|
125
|
+
*/
|
|
126
|
+
claimedSegmentsResolver = null;
|
|
127
|
+
setClaimedSegmentsResolver(resolver) {
|
|
128
|
+
this.claimedSegmentsResolver = resolver;
|
|
129
|
+
}
|
|
130
|
+
/** The channels' language prefixes → channel codes (feature 167). */
|
|
131
|
+
async languagePrefixes() {
|
|
132
|
+
return this.languagePrefixesResolver ? this.languagePrefixesResolver() : new Map();
|
|
133
|
+
}
|
|
81
134
|
/**
|
|
82
135
|
* The deployment's reserved first path segments — the **one** value the
|
|
83
136
|
* save-time refusal below and the editor's inline warning both read
|
|
@@ -103,19 +156,61 @@ export class CmsPageService {
|
|
|
103
156
|
* `{segment}` placeholder in the operator's own language (§5.4): the code for
|
|
104
157
|
* a consumer to branch on, the sentence for the operator to read.
|
|
105
158
|
*/
|
|
106
|
-
async assertSlugNotReserved(slug) {
|
|
159
|
+
async assertSlugNotReserved(slug, salesChannelIds) {
|
|
107
160
|
const segment = firstSlugSegment(slug);
|
|
108
161
|
if (segment.length === 0)
|
|
109
162
|
return;
|
|
163
|
+
// Feature 171 — a segment another module serves in one of the page's channels
|
|
164
|
+
// (the blog's prefix) is that module's address there, never the page's.
|
|
165
|
+
const claimedBy = this.claimedSegmentsResolver
|
|
166
|
+
? (await this.claimedSegmentsResolver(salesChannelIds)).get(segment)
|
|
167
|
+
: undefined;
|
|
168
|
+
if (claimedBy !== undefined) {
|
|
169
|
+
throw new HttpError(409, ERROR_CODES.CMS_SLUG_RESERVED, `The first path segment "${segment}" is served by the ${claimedBy} module in this sales channel.`, { segment, claimedBy });
|
|
170
|
+
}
|
|
110
171
|
const reserved = await this.reservedSegments();
|
|
111
|
-
|
|
172
|
+
// Feature 167 (FR-040, OR-5, OR-12) — a language prefix of any channel is the
|
|
173
|
+
// storefront's too: the URL `/<prefix>/…` is that language's page, never the
|
|
174
|
+
// CMS page. A prefix of a language no channel serves is an ordinary segment.
|
|
175
|
+
const languagePrefix = (await this.languagePrefixes()).has(segment.toLowerCase());
|
|
176
|
+
if (!reserved.includes(segment) && !languagePrefix)
|
|
112
177
|
return;
|
|
113
178
|
throw new HttpError(409, ERROR_CODES.CMS_SLUG_RESERVED, `The first path segment "${segment}" is reserved by this storefront.`, { segment });
|
|
114
179
|
}
|
|
115
|
-
|
|
180
|
+
/**
|
|
181
|
+
* R24: an override is written only for a language the page declares. A
|
|
182
|
+
* stored one whose language was removed stays, and stops counting
|
|
183
|
+
* (`cmsLocalizedPage`); a *request* naming such a language is a mistake the
|
|
184
|
+
* operator should hear about.
|
|
185
|
+
*/
|
|
186
|
+
assertTranslationsInLanguages(translations, languages) {
|
|
187
|
+
const undeclared = Object.keys(translations).find((language) => !languages.includes(language));
|
|
188
|
+
if (undeclared) {
|
|
189
|
+
throw new HttpError(400, ERROR_CODES.CMS_LANGUAGE_NOT_IN_CHANNEL_SCOPE, `CMS Page language "${undeclared}" is not assigned to this page.`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/** The page's slug and every language slug the request writes (R24) — what the reserved-segment refusal reads. */
|
|
193
|
+
requestedSlugs(slug, translations) {
|
|
194
|
+
const slugs = slug !== undefined ? [slug] : [];
|
|
195
|
+
for (const entry of Object.values(translations ?? {}))
|
|
196
|
+
if (entry.slug)
|
|
197
|
+
slugs.push(entry.slug);
|
|
198
|
+
return slugs;
|
|
199
|
+
}
|
|
200
|
+
async invalidateForPageId(pageId, options = {}) {
|
|
116
201
|
if (!this.invalidator)
|
|
117
202
|
return;
|
|
118
|
-
|
|
203
|
+
const em = this.emFactory();
|
|
204
|
+
const slugs = await this.slugsOf(pageId, em);
|
|
205
|
+
const ids = new Set([pageId]);
|
|
206
|
+
if (options.withDescendants) {
|
|
207
|
+
slugs.push(...(await this.descendantSlugs(pageId, em)));
|
|
208
|
+
for (const descendant of await this.descendantIds(pageId, em))
|
|
209
|
+
ids.add(descendant);
|
|
210
|
+
}
|
|
211
|
+
// R19D: the computed paths too — a nested page is cached under its path.
|
|
212
|
+
const { addresses } = await this.addressSnapshot(em, ids);
|
|
213
|
+
await this.invalidateForSlugs([...slugs, ...addresses]);
|
|
119
214
|
}
|
|
120
215
|
/** Every slug a page is served under — its own and each channel's. */
|
|
121
216
|
async slugsOf(pageId, em = this.emFactory()) {
|
|
@@ -139,13 +234,136 @@ export class CmsPageService {
|
|
|
139
234
|
active: row.active,
|
|
140
235
|
description: row.description,
|
|
141
236
|
languages: row.languages,
|
|
237
|
+
translations: row.translations ?? {},
|
|
142
238
|
salesChannelIds: await this.channelIdsFor(row.id, em),
|
|
143
239
|
meta: this.combineMeta(row),
|
|
240
|
+
parentPageId: row.parent_page_id,
|
|
241
|
+
breadcrumbsVisible: row.breadcrumbs_visible,
|
|
242
|
+
breadcrumbsScheme: row.breadcrumbs_scheme,
|
|
243
|
+
breadcrumbsOverlay: row.breadcrumbs_overlay === true,
|
|
244
|
+
shareImageAssetId: row.share_image_asset_id,
|
|
245
|
+
parentPathInUrl: row.parent_path_in_url === true,
|
|
144
246
|
version: row.version,
|
|
145
247
|
};
|
|
146
248
|
}
|
|
147
|
-
|
|
148
|
-
|
|
249
|
+
/**
|
|
250
|
+
* Feature 163 (FR-030, FR-032; data-model §6): refuse a parent that would make
|
|
251
|
+
* the page its own ancestor, or a tree deeper than `CMS_PAGE_TREE_MAX_DEPTH`.
|
|
252
|
+
*
|
|
253
|
+
* Runs inside the `cms_page.update` Command, so a refusal rolls back before
|
|
254
|
+
* anything is written and the bus records no entry. The transaction-scoped
|
|
255
|
+
* advisory lock serialises parent writes: two concurrent patches (A under B,
|
|
256
|
+
* B under A) would otherwise each pass against the other's pre-image.
|
|
257
|
+
*
|
|
258
|
+
* Depth counts both directions: the levels above the new parent, plus the
|
|
259
|
+
* height of the subtree this page brings with it.
|
|
260
|
+
*/
|
|
261
|
+
async assertParentAllowed(em, pageId, parentPageId) {
|
|
262
|
+
const refuse = (message) => {
|
|
263
|
+
throw new HttpError(422, ERROR_CODES.CMS_PAGE_PARENT_CYCLE, message);
|
|
264
|
+
};
|
|
265
|
+
if (parentPageId === pageId)
|
|
266
|
+
refuse('A CMS Page cannot be its own parent.');
|
|
267
|
+
await em.execute("select pg_advisory_xact_lock(hashtext('cms_pages.parent_page_id'))");
|
|
268
|
+
const parent = await this.findRow(parentPageId, em);
|
|
269
|
+
if (!parent)
|
|
270
|
+
throw new HttpError(404, ERROR_CODES.CMS_PAGE_NOT_FOUND, 'Parent CMS Page not found.');
|
|
271
|
+
// The parent and its ancestors, bounded one level past the limit so a
|
|
272
|
+
// chain that is already too deep (or a stored loop) still terminates.
|
|
273
|
+
const chain = (await em.execute(`with recursive chain(id, parent_page_id, depth) as (
|
|
274
|
+
select id, parent_page_id, 1 from cms_pages where id = ?
|
|
275
|
+
union all
|
|
276
|
+
select p.id, p.parent_page_id, c.depth + 1
|
|
277
|
+
from cms_pages p join chain c on p.id = c.parent_page_id
|
|
278
|
+
where c.depth <= ?
|
|
279
|
+
)
|
|
280
|
+
select id::text as id from chain`, [parentPageId, CMS_PAGE_TREE_MAX_DEPTH]));
|
|
281
|
+
if (chain.some((row) => row.id === pageId)) {
|
|
282
|
+
refuse('This parent would make the CMS Page its own ancestor.');
|
|
283
|
+
}
|
|
284
|
+
const below = (await em.execute(`with recursive subtree(id, depth) as (
|
|
285
|
+
select id, 1 from cms_pages where id = ?
|
|
286
|
+
union all
|
|
287
|
+
select p.id, s.depth + 1
|
|
288
|
+
from cms_pages p join subtree s on p.parent_page_id = s.id
|
|
289
|
+
where s.depth <= ?
|
|
290
|
+
)
|
|
291
|
+
select max(depth)::int as height from subtree`, [pageId, CMS_PAGE_TREE_MAX_DEPTH]));
|
|
292
|
+
const height = below[0]?.height ?? 1;
|
|
293
|
+
if (chain.length + height > CMS_PAGE_TREE_MAX_DEPTH) {
|
|
294
|
+
refuse(`A CMS Page tree may be at most ${CMS_PAGE_TREE_MAX_DEPTH} levels deep.`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* The slugs of every page below this one. A page's name, status
|
|
299
|
+
* and channel scope appear in its descendants' breadcrumb trails, so a write
|
|
300
|
+
* to it must drop their cached answers as well as its own.
|
|
301
|
+
*/
|
|
302
|
+
async descendantSlugs(pageId, em = this.emFactory()) {
|
|
303
|
+
const rows = (await em.execute(`with recursive subtree(id, depth) as (
|
|
304
|
+
select id, 0 from cms_pages where parent_page_id = ?
|
|
305
|
+
union all
|
|
306
|
+
select p.id, s.depth + 1
|
|
307
|
+
from cms_pages p join subtree s on p.parent_page_id = s.id
|
|
308
|
+
where s.depth < ?
|
|
309
|
+
)
|
|
310
|
+
select cpsc.slug from cms_page_sales_channels cpsc
|
|
311
|
+
where cpsc.page_id in (select id from subtree)
|
|
312
|
+
union
|
|
313
|
+
select p.slug from cms_pages p where p.id in (select id from subtree)`, [pageId, CMS_PAGE_TREE_MAX_DEPTH]));
|
|
314
|
+
return rows.map((row) => row.slug);
|
|
315
|
+
}
|
|
316
|
+
async invalidateForSlugs(slugs, options = {}) {
|
|
317
|
+
await this.invalidator?.pagesChanged(slugs, options);
|
|
318
|
+
}
|
|
319
|
+
/** The ids of every page below this one, bounded like every tree walk here. */
|
|
320
|
+
async descendantIds(pageId, em) {
|
|
321
|
+
const rows = (await em.execute(`with recursive subtree(id, depth) as (
|
|
322
|
+
select id, 0 from cms_pages where parent_page_id = ?
|
|
323
|
+
union all
|
|
324
|
+
select p.id, s.depth + 1
|
|
325
|
+
from cms_pages p join subtree s on p.parent_page_id = s.id
|
|
326
|
+
where s.depth < ?
|
|
327
|
+
)
|
|
328
|
+
select distinct id::text as id from subtree`, [pageId, CMS_PAGE_TREE_MAX_DEPTH]));
|
|
329
|
+
return rows.map((row) => row.id).filter((id) => id !== pageId);
|
|
330
|
+
}
|
|
331
|
+
/** The channels any of the given pages is served in. */
|
|
332
|
+
async channelsOfPages(em, pageIds) {
|
|
333
|
+
if (pageIds.size === 0)
|
|
334
|
+
return [];
|
|
335
|
+
const placeholders = [...pageIds].map(() => '?').join(', ');
|
|
336
|
+
const rows = (await em.execute(`select distinct sales_channel_id::text as id from cms_page_sales_channels where page_id in (${placeholders})`, [...pageIds]));
|
|
337
|
+
return rows.map((row) => row.id);
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* The public addresses of a page and its descendants in every channel they
|
|
341
|
+
* are served in (R19D, T282) — each channel slug and each computed path — and
|
|
342
|
+
* whether any of them is nested. Read before and after a write, so the
|
|
343
|
+
* invalidation names the addresses a page had as well as the ones it has.
|
|
344
|
+
*/
|
|
345
|
+
async addressSnapshot(em, pageIds) {
|
|
346
|
+
if (pageIds.size === 0)
|
|
347
|
+
return { addresses: new Set(), nested: false };
|
|
348
|
+
const nodes = await loadChannelPageNodes(em, await this.channelsOfPages(em, pageIds));
|
|
349
|
+
return { addresses: addressesOf(nodes, pageIds), nested: anyNested(nodes, pageIds) };
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* R19D (T282): refuse a write after which two pages of one channel share a
|
|
353
|
+
* public path, where one of them is the page written or one of its
|
|
354
|
+
* descendants. Runs inside the Command after the write, so a refusal rolls
|
|
355
|
+
* the write back and the bus records no entry; the advisory lock serialises
|
|
356
|
+
* the writes that can move a path, as the parent lock does for the tree.
|
|
357
|
+
*/
|
|
358
|
+
async assertPathsUnique(em, pageIds) {
|
|
359
|
+
await em.execute("select pg_advisory_xact_lock(hashtext('cms_pages.public_path'))");
|
|
360
|
+
const nodes = await loadChannelPageNodes(em, await this.channelsOfPages(em, pageIds));
|
|
361
|
+
const duplicate = duplicatePath(nodes, pageIds);
|
|
362
|
+
if (duplicate) {
|
|
363
|
+
throw new HttpError(409, ERROR_CODES.CMS_SLUG_CONFLICT, `Another CMS Page is already served at "/${duplicate.path}".`,
|
|
364
|
+
// R24: the language whose address is taken, when it is a language's.
|
|
365
|
+
{ path: duplicate.path, ...(duplicate.language ? { language: duplicate.language } : {}) });
|
|
366
|
+
}
|
|
149
367
|
}
|
|
150
368
|
async list(filters = {}) {
|
|
151
369
|
const em = this.emFactory();
|
|
@@ -164,14 +382,30 @@ export class CmsPageService {
|
|
|
164
382
|
}
|
|
165
383
|
if (filters.q) {
|
|
166
384
|
params.push(`%${filters.q.toLowerCase()}%`);
|
|
167
|
-
|
|
385
|
+
// R24: a page is found by its name or slug in any language too.
|
|
386
|
+
where.push('(lower(p.name) like ? or lower(p.slug) like ? or lower(p.translations::text) like ?)');
|
|
387
|
+
params.push(`%${filters.q.toLowerCase()}%`);
|
|
168
388
|
params.push(`%${filters.q.toLowerCase()}%`);
|
|
169
389
|
}
|
|
170
390
|
const rows = (await em.execute(`select p.* from cms_pages p
|
|
171
391
|
${where.length > 0 ? `where ${where.join(' and ')}` : ''}
|
|
172
392
|
order by p.updated_at desc
|
|
173
393
|
limit 50`, params));
|
|
174
|
-
const
|
|
394
|
+
const summaries = await Promise.all(rows.map((row) => this.toSummary(row)));
|
|
395
|
+
// Feature 167 (FR-041) — mark a page shadowed by a channel language prefix.
|
|
396
|
+
const prefixes = await this.languagePrefixes();
|
|
397
|
+
const data = summaries.map((page) => {
|
|
398
|
+
// The page's own slug and every per-language slug (R24): any of them may be the
|
|
399
|
+
// one a language prefix hides.
|
|
400
|
+
const slugs = [page.slug, ...Object.values(page.translations ?? {}).map((t) => t.slug ?? '')];
|
|
401
|
+
for (const slug of slugs) {
|
|
402
|
+
const segment = firstSlugSegment(slug).toLowerCase();
|
|
403
|
+
const channelCodes = segment === '' ? undefined : prefixes.get(segment);
|
|
404
|
+
if (channelCodes)
|
|
405
|
+
return { ...page, shadowedByLanguagePrefix: { prefix: segment, channelCodes: [...channelCodes] } };
|
|
406
|
+
}
|
|
407
|
+
return page;
|
|
408
|
+
});
|
|
175
409
|
return { data, nextCursor: null };
|
|
176
410
|
}
|
|
177
411
|
async create(input) {
|
|
@@ -179,7 +413,11 @@ export class CmsPageService {
|
|
|
179
413
|
// against the deployment's configuration and touches no row, so opening a
|
|
180
414
|
// transaction to refuse it would hold a connection for the length of a
|
|
181
415
|
// settings read.
|
|
182
|
-
|
|
416
|
+
for (const slug of this.requestedSlugs(input.slug, input.translations)) {
|
|
417
|
+
await this.assertSlugNotReserved(slug, input.salesChannelIds);
|
|
418
|
+
}
|
|
419
|
+
const translations = normalizeTranslations(input.translations ?? {});
|
|
420
|
+
this.assertTranslationsInLanguages(translations, input.languages);
|
|
183
421
|
const id = randomUUID();
|
|
184
422
|
const now = new Date();
|
|
185
423
|
const meta = this.splitMeta(input.meta ?? null);
|
|
@@ -188,6 +426,7 @@ export class CmsPageService {
|
|
|
188
426
|
input.meta?.[language]?.title?.trim() || input.name,
|
|
189
427
|
]));
|
|
190
428
|
const body = Object.fromEntries(input.languages.map((language) => [language, '']));
|
|
429
|
+
const createdAddresses = new Set([input.slug]);
|
|
191
430
|
await this.commandBus.run({
|
|
192
431
|
action: 'cms_page.create',
|
|
193
432
|
objectType: PAGE_OBJECT_TYPE,
|
|
@@ -195,12 +434,17 @@ export class CmsPageService {
|
|
|
195
434
|
run: async ({ em: tx }) => {
|
|
196
435
|
await this.assertLanguagesInChannelScope(tx, input.languages, input.salesChannelIds);
|
|
197
436
|
await this.assertSlugAvailable(tx, input.slug, input.salesChannelIds);
|
|
437
|
+
if (input.parentPageId)
|
|
438
|
+
await this.assertParentAllowed(tx, id, input.parentPageId);
|
|
198
439
|
await tx.execute(`insert into cms_pages
|
|
199
440
|
(id, path, status, title, body, published_at, archived_at, created_at, updated_at,
|
|
200
441
|
name, slug, active, description, meta_title, meta_description, meta_keywords,
|
|
201
|
-
content, languages, version
|
|
442
|
+
content, languages, version,
|
|
443
|
+
parent_page_id, breadcrumbs_visible, breadcrumbs_scheme, share_image_asset_id,
|
|
444
|
+
parent_path_in_url, breadcrumbs_overlay, translations)
|
|
202
445
|
values (?, ?, 'draft', ?::jsonb, ?::jsonb, null, null, ?, ?,
|
|
203
|
-
?, ?, ?, ?, ?::jsonb, ?::jsonb, ?::jsonb, ?::jsonb, ?::jsonb, 1
|
|
446
|
+
?, ?, ?, ?, ?::jsonb, ?::jsonb, ?::jsonb, ?::jsonb, ?::jsonb, 1,
|
|
447
|
+
?, ?, ?, ?, ?, ?, ?::jsonb)`, [
|
|
204
448
|
id,
|
|
205
449
|
this.legacyPath(input.slug, id),
|
|
206
450
|
JSON.stringify(title),
|
|
@@ -216,8 +460,19 @@ export class CmsPageService {
|
|
|
216
460
|
JSON.stringify(meta.metaKeywords),
|
|
217
461
|
JSON.stringify(emptyContent),
|
|
218
462
|
JSON.stringify(input.languages),
|
|
463
|
+
input.parentPageId ?? null,
|
|
464
|
+
input.breadcrumbsVisible ?? true,
|
|
465
|
+
input.breadcrumbsScheme ?? 'light',
|
|
466
|
+
input.shareImageAssetId ?? null,
|
|
467
|
+
input.parentPathInUrl ?? false,
|
|
468
|
+
input.breadcrumbsOverlay ?? false,
|
|
469
|
+
JSON.stringify(translations),
|
|
219
470
|
]);
|
|
220
471
|
await this.replaceChannelScope(tx, id, input.salesChannelIds, input.slug);
|
|
472
|
+
await this.assertPathsUnique(tx, new Set([id]));
|
|
473
|
+
for (const address of (await this.addressSnapshot(tx, new Set([id]))).addresses) {
|
|
474
|
+
createdAddresses.add(address);
|
|
475
|
+
}
|
|
221
476
|
const created = await this.findRow(id, tx);
|
|
222
477
|
return {
|
|
223
478
|
result: undefined,
|
|
@@ -226,7 +481,7 @@ export class CmsPageService {
|
|
|
226
481
|
};
|
|
227
482
|
},
|
|
228
483
|
});
|
|
229
|
-
await this.invalidateForSlugs(
|
|
484
|
+
await this.invalidateForSlugs(createdAddresses);
|
|
230
485
|
return this.get(id);
|
|
231
486
|
}
|
|
232
487
|
async get(id) {
|
|
@@ -241,9 +496,15 @@ export class CmsPageService {
|
|
|
241
496
|
// would make every page whose slug predates the deployment's reserved set
|
|
242
497
|
// uneditable — a rule that punishes the operator for a decision somebody
|
|
243
498
|
// else made later.
|
|
244
|
-
|
|
245
|
-
|
|
499
|
+
const requested = this.requestedSlugs(input.slug, input.translations);
|
|
500
|
+
if (requested.length > 0) {
|
|
501
|
+
const channelIds = input.salesChannelIds ?? (await this.channelIdsFor(id));
|
|
502
|
+
for (const slug of requested)
|
|
503
|
+
await this.assertSlugNotReserved(slug, channelIds);
|
|
504
|
+
}
|
|
505
|
+
const translations = input.translations !== undefined ? normalizeTranslations(input.translations) : undefined;
|
|
246
506
|
const slugsToInvalidate = new Set();
|
|
507
|
+
let addressesMoved = false;
|
|
247
508
|
await this.commandBus.run({
|
|
248
509
|
action: 'cms_page.update',
|
|
249
510
|
objectType: PAGE_OBJECT_TYPE,
|
|
@@ -259,9 +520,31 @@ export class CmsPageService {
|
|
|
259
520
|
const nextChannels = input.salesChannelIds ?? (await this.channelIdsFor(id, tx));
|
|
260
521
|
const nextLanguages = input.languages ?? row.languages;
|
|
261
522
|
await this.assertLanguagesInChannelScope(tx, nextLanguages, nextChannels);
|
|
523
|
+
if (translations)
|
|
524
|
+
this.assertTranslationsInLanguages(translations, nextLanguages);
|
|
262
525
|
if (input.slug || input.salesChannelIds) {
|
|
263
526
|
await this.assertSlugAvailable(tx, nextSlug, nextChannels, id);
|
|
264
527
|
}
|
|
528
|
+
if (input.parentPageId && input.parentPageId !== row.parent_page_id) {
|
|
529
|
+
await this.assertParentAllowed(tx, id, input.parentPageId);
|
|
530
|
+
}
|
|
531
|
+
// R19D: a write that can move a public path — its own and its nested
|
|
532
|
+
// descendants' — is checked for a duplicate after it is made, and both
|
|
533
|
+
// sets of addresses are invalidated.
|
|
534
|
+
// R24: a language slug moves an address, and so does a language
|
|
535
|
+
// added or removed, since an override counts only while its language
|
|
536
|
+
// is declared.
|
|
537
|
+
const movesPaths = input.slug !== undefined ||
|
|
538
|
+
input.salesChannelIds !== undefined ||
|
|
539
|
+
input.parentPageId !== undefined ||
|
|
540
|
+
input.parentPathInUrl !== undefined ||
|
|
541
|
+
input.languages !== undefined ||
|
|
542
|
+
translations !== undefined;
|
|
543
|
+
// Every write snapshots the subtree's addresses (R24): a name — the
|
|
544
|
+
// page's or a language's — is in the descendants' trails, and they are
|
|
545
|
+
// cached under their language addresses as well as their slugs.
|
|
546
|
+
const subtree = new Set([id, ...(await this.descendantIds(id, tx))]);
|
|
547
|
+
const pathsBefore = await this.addressSnapshot(tx, subtree);
|
|
265
548
|
const meta = input.meta !== undefined ? this.splitMeta(input.meta ?? null) : null;
|
|
266
549
|
const sets = [];
|
|
267
550
|
const params = [];
|
|
@@ -279,6 +562,20 @@ export class CmsPageService {
|
|
|
279
562
|
set('description = ?', input.description);
|
|
280
563
|
if (input.languages !== undefined)
|
|
281
564
|
set('languages = ?::jsonb', JSON.stringify(input.languages));
|
|
565
|
+
if (input.parentPageId !== undefined)
|
|
566
|
+
set('parent_page_id = ?', input.parentPageId);
|
|
567
|
+
if (input.breadcrumbsVisible !== undefined)
|
|
568
|
+
set('breadcrumbs_visible = ?', input.breadcrumbsVisible);
|
|
569
|
+
if (input.breadcrumbsScheme !== undefined)
|
|
570
|
+
set('breadcrumbs_scheme = ?', input.breadcrumbsScheme);
|
|
571
|
+
if (input.breadcrumbsOverlay !== undefined)
|
|
572
|
+
set('breadcrumbs_overlay = ?', input.breadcrumbsOverlay);
|
|
573
|
+
if (input.shareImageAssetId !== undefined)
|
|
574
|
+
set('share_image_asset_id = ?', input.shareImageAssetId);
|
|
575
|
+
if (input.parentPathInUrl !== undefined)
|
|
576
|
+
set('parent_path_in_url = ?', input.parentPathInUrl);
|
|
577
|
+
if (translations !== undefined)
|
|
578
|
+
set('translations = ?::jsonb', JSON.stringify(translations));
|
|
282
579
|
if (meta) {
|
|
283
580
|
set('meta_title = ?::jsonb', JSON.stringify(meta.metaTitle));
|
|
284
581
|
set('meta_description = ?::jsonb', JSON.stringify(meta.metaDescription));
|
|
@@ -295,6 +592,15 @@ export class CmsPageService {
|
|
|
295
592
|
await this.replaceChannelScope(tx, id, nextChannels, nextSlug);
|
|
296
593
|
}
|
|
297
594
|
slugsToInvalidate.add(nextSlug);
|
|
595
|
+
for (const slug of await this.descendantSlugs(id, tx))
|
|
596
|
+
slugsToInvalidate.add(slug);
|
|
597
|
+
if (movesPaths)
|
|
598
|
+
await this.assertPathsUnique(tx, subtree);
|
|
599
|
+
const pathsAfter = await this.addressSnapshot(tx, subtree);
|
|
600
|
+
for (const address of [...pathsBefore.addresses, ...pathsAfter.addresses])
|
|
601
|
+
slugsToInvalidate.add(address);
|
|
602
|
+
if (movesPaths)
|
|
603
|
+
addressesMoved = pathsBefore.nested || pathsAfter.nested;
|
|
298
604
|
// A patch that named no field wrote no row, so it leaves no entry: "no
|
|
299
605
|
// write, no audit row" is the bus's own rule and `skipAudit` its spelling.
|
|
300
606
|
if (sets.length === 0 && !rescoped)
|
|
@@ -307,7 +613,7 @@ export class CmsPageService {
|
|
|
307
613
|
};
|
|
308
614
|
},
|
|
309
615
|
});
|
|
310
|
-
await this.invalidateForSlugs(slugsToInvalidate);
|
|
616
|
+
await this.invalidateForSlugs(slugsToInvalidate, { addressesMoved });
|
|
311
617
|
return this.get(id);
|
|
312
618
|
}
|
|
313
619
|
async setContent(id, language, data, version) {
|
|
@@ -320,6 +626,8 @@ export class CmsPageService {
|
|
|
320
626
|
if (!row)
|
|
321
627
|
throw new HttpError(404, ERROR_CODES.CMS_PAGE_NOT_FOUND, 'CMS Page not found.');
|
|
322
628
|
this.assertVersion(row, version);
|
|
629
|
+
// One anchor names one place in this language's tree (feature 163, R-8).
|
|
630
|
+
assertAnchors({ [language]: data });
|
|
323
631
|
const unknown = walkUnknownComponents(data, new Set(this.knownComponentNames()));
|
|
324
632
|
if (unknown.size > 0) {
|
|
325
633
|
console.warn(`CMS page ${id} saved with unknown components: ${Array.from(unknown).join(', ')}`);
|
|
@@ -367,6 +675,7 @@ export class CmsPageService {
|
|
|
367
675
|
// the slugs cascade with it. Invalidated after the commit, so a storefront
|
|
368
676
|
// read racing the delete cannot re-cache a page that is about to be gone.
|
|
369
677
|
let slugs = [];
|
|
678
|
+
let movedOnDelete = false;
|
|
370
679
|
await this.commandBus.run({
|
|
371
680
|
action: 'cms_page.delete',
|
|
372
681
|
objectType: PAGE_OBJECT_TYPE,
|
|
@@ -378,12 +687,18 @@ export class CmsPageService {
|
|
|
378
687
|
if (!row)
|
|
379
688
|
return { result: undefined, skipAudit: true };
|
|
380
689
|
const before = await this.auditState(em, row);
|
|
381
|
-
|
|
690
|
+
// The children lose this page as their parent (`on delete set null`),
|
|
691
|
+
// so their trails change with it.
|
|
692
|
+
slugs = [...(await this.slugsOf(id, em)), ...(await this.descendantSlugs(id, em))];
|
|
693
|
+
// R19D: and the paths, which move for every nested descendant.
|
|
694
|
+
const snapshot = await this.addressSnapshot(em, new Set([id, ...(await this.descendantIds(id, em))]));
|
|
695
|
+
slugs.push(...snapshot.addresses);
|
|
696
|
+
movedOnDelete = snapshot.nested;
|
|
382
697
|
await em.execute('delete from cms_pages where id = ?', [id]);
|
|
383
698
|
return { result: undefined, before, after: null };
|
|
384
699
|
},
|
|
385
700
|
});
|
|
386
|
-
await this.invalidateForSlugs(slugs);
|
|
701
|
+
await this.invalidateForSlugs(slugs, { addressesMoved: movedOnDelete });
|
|
387
702
|
}
|
|
388
703
|
async transition(id, status) {
|
|
389
704
|
await this.commandBus.run({
|
|
@@ -408,10 +723,13 @@ export class CmsPageService {
|
|
|
408
723
|
};
|
|
409
724
|
},
|
|
410
725
|
});
|
|
411
|
-
await this.invalidateForPageId(id);
|
|
726
|
+
await this.invalidateForPageId(id, { withDescendants: true });
|
|
412
727
|
return this.get(id);
|
|
413
728
|
}
|
|
414
729
|
async findRow(id, em = this.emFactory()) {
|
|
730
|
+
// A malformed id names no row; PostgreSQL would answer it with a 500 (issue #781).
|
|
731
|
+
if (!isUuidShape(id))
|
|
732
|
+
return null;
|
|
415
733
|
const rows = (await em.execute('select * from cms_pages where id = ?', [
|
|
416
734
|
id,
|
|
417
735
|
]));
|
|
@@ -535,6 +853,9 @@ export class CmsPageService {
|
|
|
535
853
|
version: row.version,
|
|
536
854
|
createdAt: this.iso(row.created_at),
|
|
537
855
|
updatedAt: this.iso(row.updated_at),
|
|
856
|
+
parentPageId: row.parent_page_id,
|
|
857
|
+
parentPathInUrl: row.parent_path_in_url === true,
|
|
858
|
+
translations: row.translations ?? {},
|
|
538
859
|
};
|
|
539
860
|
}
|
|
540
861
|
async toDetail(row) {
|
|
@@ -544,6 +865,10 @@ export class CmsPageService {
|
|
|
544
865
|
content: {
|
|
545
866
|
languages: row.content.languages ?? {},
|
|
546
867
|
},
|
|
868
|
+
breadcrumbsVisible: row.breadcrumbs_visible,
|
|
869
|
+
breadcrumbsScheme: row.breadcrumbs_scheme,
|
|
870
|
+
breadcrumbsOverlay: row.breadcrumbs_overlay === true,
|
|
871
|
+
shareImageAssetId: row.share_image_asset_id,
|
|
547
872
|
};
|
|
548
873
|
}
|
|
549
874
|
combineMeta(row) {
|