@endora-commerce/mod-cms 0.103.1 → 0.105.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/admin/editors/BlockEditor.d.ts.map +1 -1
  2. package/dist/admin/editors/BlockEditor.js +10 -4
  3. package/dist/admin/editors/BlockEditor.js.map +1 -1
  4. package/dist/admin/editors/PageEditor.d.ts.map +1 -1
  5. package/dist/admin/editors/PageEditor.js +10 -4
  6. package/dist/admin/editors/PageEditor.js.map +1 -1
  7. package/dist/admin/editors/TemplateEditor.d.ts.map +1 -1
  8. package/dist/admin/editors/TemplateEditor.js +9 -3
  9. package/dist/admin/editors/TemplateEditor.js.map +1 -1
  10. package/dist/admin/index.d.ts +1 -1
  11. package/dist/admin/index.d.ts.map +1 -1
  12. package/dist/admin/index.js +55 -0
  13. package/dist/admin/index.js.map +1 -1
  14. package/dist/admin/zones/CategoryContentEditor.d.ts +28 -0
  15. package/dist/admin/zones/CategoryContentEditor.d.ts.map +1 -0
  16. package/dist/admin/zones/CategoryContentEditor.js +28 -0
  17. package/dist/admin/zones/CategoryContentEditor.js.map +1 -0
  18. package/dist/backend/index.d.ts +10 -1
  19. package/dist/backend/index.d.ts.map +1 -1
  20. package/dist/backend/index.js +53 -2
  21. package/dist/backend/index.js.map +1 -1
  22. package/dist/backend/plugin.d.ts +11 -4
  23. package/dist/backend/plugin.d.ts.map +1 -1
  24. package/dist/backend/plugin.js +9 -4
  25. package/dist/backend/plugin.js.map +1 -1
  26. package/dist/backend/services/cms-block-service.d.ts +37 -8
  27. package/dist/backend/services/cms-block-service.d.ts.map +1 -1
  28. package/dist/backend/services/cms-block-service.js +176 -91
  29. package/dist/backend/services/cms-block-service.js.map +1 -1
  30. package/dist/backend/services/cms-cache.d.ts +9 -2
  31. package/dist/backend/services/cms-cache.d.ts.map +1 -1
  32. package/dist/backend/services/cms-cache.js +11 -2
  33. package/dist/backend/services/cms-cache.js.map +1 -1
  34. package/dist/backend/services/cms-content-invalidator.d.ts +56 -0
  35. package/dist/backend/services/cms-content-invalidator.d.ts.map +1 -0
  36. package/dist/backend/services/cms-content-invalidator.js +78 -0
  37. package/dist/backend/services/cms-content-invalidator.js.map +1 -0
  38. package/dist/backend/services/cms-hook-service.d.ts +33 -3
  39. package/dist/backend/services/cms-hook-service.d.ts.map +1 -1
  40. package/dist/backend/services/cms-hook-service.js +180 -69
  41. package/dist/backend/services/cms-hook-service.js.map +1 -1
  42. package/dist/backend/services/cms-page-service.d.ts +3 -3
  43. package/dist/backend/services/cms-page-service.d.ts.map +1 -1
  44. package/dist/backend/services/cms-page-service.js +5 -9
  45. package/dist/backend/services/cms-page-service.js.map +1 -1
  46. package/dist/backend/services/cms-template-service.d.ts +37 -3
  47. package/dist/backend/services/cms-template-service.d.ts.map +1 -1
  48. package/dist/backend/services/cms-template-service.js +166 -74
  49. package/dist/backend/services/cms-template-service.js.map +1 -1
  50. package/dist/manifest.d.ts +1 -1
  51. package/docs/cms/index.md +28 -1
  52. package/package.json +13 -13
  53. package/dist/admin/components/CmsContentEditorLayout.d.ts +0 -12
  54. package/dist/admin/components/CmsContentEditorLayout.d.ts.map +0 -1
  55. package/dist/admin/components/CmsContentEditorLayout.js +0 -9
  56. package/dist/admin/components/CmsContentEditorLayout.js.map +0 -1
@@ -1,12 +1,15 @@
1
1
  import { z } from 'zod';
2
- import { cmsColorPaletteSchema, } from '@endora-commerce/contracts';
2
+ import { CMS_CONTENT_CHANGED_EVENT, cmsColorPaletteSchema, } from '@endora-commerce/contracts';
3
3
  import { CMS_PAGE_BUILDER_SETTING_CODES, CMS_SETTING_CODES } from '../manifest.js';
4
4
  import { CmsBlockReadService } from './services/cms-block-read-port.js';
5
5
  import { CmsBlockSeedService } from './services/cms-block-seed-port.js';
6
+ import { storefrontTagsFor } from './services/cms-content-invalidator.js';
6
7
  import { CmsPageReadService } from './services/cms-page-read-port.js';
7
8
  import { lazyPort } from '@endora-commerce/platform/kernel';
8
9
  import { effectiveState } from '@endora-commerce/platform/kernel';
9
10
  import { rethrowIfModuleDisabled } from '@endora-commerce/platform/kernel';
11
+ import { StorefrontRevalidator } from '@endora-commerce/platform/http';
12
+ import { randomUUID } from 'crypto';
10
13
  import { cmsModule } from './plugin.js';
11
14
  import { createAssetEmbedResolver } from './services/asset-embed-resolver.js';
12
15
  import { registerCmsAssetReferences } from './services/asset-references.js';
@@ -80,12 +83,40 @@ export function registerModule(ctx) {
80
83
  cmsAssetResolver: ctx
81
84
  .asFunction(() => createAssetEmbedResolver(lazyPort(ctx, 'assetsLibraryPort')))
82
85
  .singleton(),
86
+ /**
87
+ * The storefront keeps every CMS read in its Data Cache for 60 s, tagged
88
+ * with the names in `CMS_STOREFRONT_CACHE_TAGS`. This is what tells it a
89
+ * write made some of them stale, so a saved page is the next request's
90
+ * page rather than the next minute's. A no-op unless STOREFRONT_BASE_URL
91
+ * and REVALIDATE_SECRET are configured, and best-effort when they are: an
92
+ * unreachable storefront is logged and never fails the save.
93
+ *
94
+ * Registered here, like `catalog`'s, because the subscription that drives
95
+ * it belongs in this file (issue #107).
96
+ */
97
+ cmsStorefrontRevalidator: ctx
98
+ .asFunction(() => new StorefrontRevalidator({
99
+ baseUrl: process.env['STOREFRONT_BASE_URL'],
100
+ secret: process.env['REVALIDATE_SECRET'],
101
+ }))
102
+ .singleton(),
83
103
  cms: ctx
84
104
  .asFunction(({ emFactory, commandBus, redis, resolvedModuleRegistry }) => {
85
105
  const result = cmsModule({
86
106
  emFactory,
87
107
  commandBus,
88
108
  redis,
109
+ // Published on the bus rather than answered here, because this module
110
+ // is not the only one caching CMS content: `megamenu` inlines a
111
+ // block's tree into a menu payload and can learn that the block moved
112
+ // from nowhere else. The bus is read per change, never captured.
113
+ publishContentChange: (change) => {
114
+ ctx.cradle().eventBus.emit(CMS_CONTENT_CHANGED_EVENT, {
115
+ eventId: randomUUID(),
116
+ occurredAt: new Date().toISOString(),
117
+ ...change,
118
+ });
119
+ },
89
120
  // Feature 096, T209/T210. The declarations are fixed at composition;
90
121
  // presence is read per `describe()` call, so an operator switching a
91
122
  // block owner off changes the next response with no restart and no
@@ -267,8 +298,28 @@ export function registerModule(ctx) {
267
298
  const { assetReferenceRegistry, emFactory } = ctx.cradle();
268
299
  registerCmsAssetReferences(assetReferenceRegistry, emFactory);
269
300
  });
301
+ /**
302
+ * A committed content change reaches the storefront's Data Cache.
303
+ *
304
+ * By the time the event is dispatched the write has committed and this
305
+ * module's Redis entries are gone (`CmsContentInvalidator` orders it), so the
306
+ * refetch this provokes reads the new content. `ctx.subscribe` stops it with
307
+ * the module — a switched-off `cms` has no write route to publish from, and
308
+ * no storefront surface left to refresh.
309
+ *
310
+ * Not awaited: the save has already answered, and the storefront being slow
311
+ * or absent is not the operator's problem to wait on.
312
+ */
313
+ ctx.subscribe(CMS_CONTENT_CHANGED_EVENT, (payload) => {
314
+ const change = payload;
315
+ void ctx.cradle().cmsStorefrontRevalidator.revalidate(storefrontTagsFor(change));
316
+ });
270
317
  ctx.routes(async (app) => {
271
- await ctx.cradle().cms.plugin(app);
318
+ const cradle = ctx.cradle();
319
+ // The route registrar is where `app.log` exists, so the revalidator picks
320
+ // it up here; until then a failed revalidation has nowhere to be logged.
321
+ cradle.cmsStorefrontRevalidator.setLogger(app.log);
322
+ await cradle.cms.plugin(app);
272
323
  });
273
324
  /**
274
325
  * This module's rows carry a language code, so it answers "who still points at
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/backend/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,qBAAqB,GAOtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,8BAA8B,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,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AAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9F,CAAC,CAAC,CAAC;IAEH,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACvB,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAa,CAAC;QACvC,0EAA0E;QAC1E,yEAAyE;QACzE,MAAM,CAAC,wBAAwB,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACnD,MAAM,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH;;;;;;;;;;OAUG;IACH,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE;QACd,6BAA6B,CAC3B,QAAQ,CAAkC,GAAG,EAAE,2BAA2B,CAAC,EAC3E,GAAG,CAAC,MAAM,EAAa,CAAC,SAAS,CAClC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,QAAQ;IACR,sBAAsB;IACtB,OAAO;IACP,OAAO;IACP,WAAW;CACZ,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAI3B;IACH,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,yBAAyB,EAAE,cAAc,EAAE,aAAa,EAAE;CAC5F,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import type { FastifyInstance } from 'fastify';
2
2
  import type { EntityManager } from '@mikro-orm/postgresql';
3
3
  import type { Redis } from 'ioredis';
4
- import type { CmsColorPaletteEntry, ModuleManifest } from '@endora-commerce/contracts';
4
+ import type { CmsColorPaletteEntry, CmsContentChange, ModuleManifest } from '@endora-commerce/contracts';
5
5
  import { PageBuilderRegistry, type PageBuilderBreakpointsResolver, type ColorPaletteResolver } from './services/page-builder-registry.js';
6
6
  import { CmsPageService, type ReservedSlugSegmentsResolver } from './services/cms-page-service.js';
7
7
  import { CmsBlockService } from './services/cms-block-service.js';
@@ -20,9 +20,10 @@ export type ColorPaletteWriter = (entries: CmsColorPaletteEntry[], expectedVersi
20
20
  export interface CmsModuleOptions {
21
21
  emFactory: () => EntityManager;
22
22
  /**
23
- * The platform's Command Bus (Constitution XIII): every admin write to a Page
24
- * runs through it, so each one is audited in its own transaction. Required —
25
- * an optional bus would be a write path whose absent form records nothing.
23
+ * The platform's Command Bus (Constitution XIII): every admin write to a
24
+ * Page, a Block, a Template or a Hook runs through it, so each one is audited
25
+ * in its own transaction. Required — an optional bus would be a write path
26
+ * whose absent form records nothing.
26
27
  */
27
28
  commandBus: CommandBus;
28
29
  /**
@@ -49,6 +50,12 @@ export interface CmsModuleOptions {
49
50
  }>;
50
51
  /** Effective presence, read by the registry at enumeration (FR-010). */
51
52
  isModulePresent?: (moduleId: string) => boolean;
53
+ /**
54
+ * Told what a content write changed, after it committed and after this
55
+ * module's own Redis entries were dropped. `backend/index.ts` binds it to the
56
+ * EventBus; a composition that passes nothing publishes nothing.
57
+ */
58
+ publishContentChange?: (change: CmsContentChange) => void;
52
59
  }
53
60
  export interface CmsModuleHandle {
54
61
  pageBuilderRegistry: PageBuilderRegistry;
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/backend/plugin.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEvF,OAAO,EAAE,mBAAmB,EAAE,KAAK,8BAA8B,EAAE,KAAK,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAG1I,OAAO,EAAE,cAAc,EAAE,KAAK,4BAA4B,EAAE,MAAM,gCAAg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,GAAG;IACpD,MAAM,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,MAAM,EAAE,eAAe,CAAC;CACzB,CA0FA"}
@@ -16,6 +16,7 @@ import { CmsReferenceRegistry } from './services/cms-reference-registry.js';
16
16
  import { StorefrontResolver } from './services/storefront-resolver.js';
17
17
  import { CmsHookService } from './services/cms-hook-service.js';
18
18
  import { CmsCache } from './services/cms-cache.js';
19
+ import { CmsContentInvalidator } from './services/cms-content-invalidator.js';
19
20
  import { registerCmsAdminRoutes } from './routes.admin.js';
20
21
  import { registerCmsStorefrontRoutes } from './routes.storefront.js';
21
22
  export function cmsModule(options) {
@@ -30,11 +31,15 @@ export function cmsModule(options) {
30
31
  isModulePresent: options.isModulePresent,
31
32
  });
32
33
  const cache = options.redis ? new CmsCache(options.redis, {}) : undefined;
34
+ // The write services hold this and not the cache: a write states what
35
+ // changed once, and the Redis drop and the published change follow from it
36
+ // in the one order that is safe (see `CmsContentInvalidator`).
37
+ const invalidator = new CmsContentInvalidator(cache, options.publishContentChange ?? (() => { }));
33
38
  const referenceRegistry = new CmsReferenceRegistry(options.emFactory);
34
- const pageService = new CmsPageService(options.emFactory, options.commandBus, () => pageBuilderRegistry.knownNames(), cache, referenceRegistry);
35
- const blockService = new CmsBlockService(options.emFactory, () => pageBuilderRegistry.knownNames(), referenceRegistry, cache);
36
- const templateService = new CmsTemplateService(options.emFactory, () => pageBuilderRegistry.knownNames(), referenceRegistry, cache);
37
- const hookService = new CmsHookService(options.emFactory, cache);
39
+ const pageService = new CmsPageService(options.emFactory, options.commandBus, () => pageBuilderRegistry.knownNames(), invalidator, referenceRegistry);
40
+ const blockService = new CmsBlockService(options.emFactory, options.commandBus, () => pageBuilderRegistry.knownNames(), referenceRegistry, invalidator);
41
+ const templateService = new CmsTemplateService(options.emFactory, options.commandBus, () => pageBuilderRegistry.knownNames(), referenceRegistry, invalidator);
42
+ const hookService = new CmsHookService(options.emFactory, options.commandBus, invalidator);
38
43
  const storefrontResolver = new StorefrontResolver(options.emFactory, cache);
39
44
  let colorPaletteWriter = null;
40
45
  const handle = {
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/backend/plugin.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,EAAE;AACF,qEAAqE;AACrE,uEAAuE;AACvE,uEAAuE;AACvE,qEAAqE;AACrE,sEAAsE;AACtE,qEAAqE;AAOrE,OAAO,EAAE,mBAAmB,EAAkE,MAAM,qCAAqC,CAAC;AAC1I,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,oCAAoC,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,cAAc,EAAqC,MAAM,gCAAgC,CAAC;AACnG,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAyB,MAAM,mCAAmC,CAAC;AAC9F,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AA4ErE,MAAM,UAAU,SAAS,CAAC,OAAyB;IAIjD,MAAM,mBAAmB,GAAG,IAAI,mBAAmB,CAAC;QAClD,WAAW,EAAE,oCAAoC,EAAE;QACnD,2EAA2E;QAC3E,2DAA2D;QAC3D,yEAAyE;QACzE,0EAA0E;QAC1E,wDAAwD;QACxD,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,eAAe,EAAE,OAAO,CAAC,eAAe;KACzC,CAAC,CAAC;IAEH,MAAM,KAAK,G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,+BAA+B,EAAE,CAAC,QAAQ,EAAE,EAAE;YAC5C,WAAW,CAAC,2BAA2B,CAAC,QAAQ,CAAC,CAAC;QACpD,CAAC;QACD,qBAAqB,EAAE,GAAG,EAAE,CAAC,kBAAkB;QAC/C,gBAAgB,EAAE,CAAC,QAAQ,EAAE,EAAE;YAC7B,kBAAkB,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QAChD,CAAC;KACF,CAAC;IAEF,MAAM,MAAM,GAAG,KAAK,EAAE,GAAoB,EAAE,EAAE;QAC5C,MAAM,sBAAsB,CAAC,GAAG,EAAE;YAChC,WAAW;YACX,YAAY;YACZ,eAAe;YACf,WAAW;YACX,mBAAmB;YACnB,qBAAqB,EAAE,GAAG,EAAE,CAAC,kBAAkB;YAC/C,YAAY,EAAE,OAAO,CAAC,YAAY;SACnC,CAAC,CAAC;QACH,MAAM,2BAA2B,CAAC,GAAG,EAAE,EAAE,kBAAkB,EAAE,CAAC,CAAC;IACjE,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAC5B,CAAC"}
@@ -1,20 +1,49 @@
1
1
  import type { EntityManager } from '@mikro-orm/postgresql';
2
2
  import { type CmsBlockDetail, type CmsBlockSummary, type CreateCmsBlockRequest, type PatchCmsBlockRequest } from '@endora-commerce/contracts';
3
+ import type { CommandBus } from '@endora-commerce/platform/commands';
3
4
  import type { CmsReferenceRegistry } from './cms-reference-registry.js';
4
- import type { CmsCache } from './cms-cache.js';
5
+ import type { CmsContentInvalidator } from './cms-content-invalidator.js';
6
+ /**
7
+ * Every write below runs as a Command (Constitution XIII), the way
8
+ * `CmsPageService`'s do: `CommandBus.run` opens the transaction, derives the
9
+ * actor from the ambient TenantContext and records exactly one audit entry
10
+ * beside the write, so a rolled-back write leaves no entry and a committed one
11
+ * cannot skip it. The statements are raw SQL and stay so — what changed is the
12
+ * EntityManager they run on, which is the Command's and no longer one this
13
+ * service opened for itself.
14
+ *
15
+ * What stays **outside** the Command is what is not part of the write: the
16
+ * reference refusal on delete (a read through `CmsReferenceRegistry`, which
17
+ * holds its own manager), the content invalidation (Redis and the published
18
+ * change, only meaningful once the row is committed) and the response read.
19
+ */
5
20
  export declare class CmsBlockService {
6
21
  private readonly emFactory;
22
+ /**
23
+ * Required, with no un-audited fallback: an optional bus is a write path
24
+ * whose absent form audits nothing, which is the defect this parameter
25
+ * exists to remove.
26
+ */
27
+ private readonly commandBus;
7
28
  private readonly knownComponentNames;
8
29
  private readonly references;
9
- private readonly cache?;
10
- constructor(emFactory: () => EntityManager, knownComponentNames: () => Iterable<string>, references: CmsReferenceRegistry, cache?: CmsCache | undefined);
30
+ private readonly invalidator?;
31
+ constructor(emFactory: () => EntityManager,
32
+ /**
33
+ * Required, with no un-audited fallback: an optional bus is a write path
34
+ * whose absent form audits nothing, which is the defect this parameter
35
+ * exists to remove.
36
+ */
37
+ commandBus: CommandBus, knownComponentNames: () => Iterable<string>, references: CmsReferenceRegistry, invalidator?: CmsContentInvalidator | undefined);
38
+ /** What a block change reaches is `CmsContentInvalidator.blocksChanged`'s to say. */
39
+ private invalidateForBlockCodes;
11
40
  /**
12
- * Invalidates the block's own cache entries plus the page-level
13
- * namespace, since we don't track which pages embed which block. The
14
- * page invalidation is coarse but safe: at platform scale (low
15
- * hundreds of pages) the next request rebuilds the cache trivially.
41
+ * What an audit entry keeps of a Block: the facts an operator sets, and not
42
+ * the content tree — the same choice, for the same reason, as a Page's entry.
43
+ * A tree is large and saved many times in one editing session; a content save
44
+ * records which language changed and the version it produced.
16
45
  */
17
- private invalidateForBlockCode;
46
+ private auditState;
18
47
  list(filters?: {
19
48
  salesChannelId?: string;
20
49
  }): Promise<{
@@ -1 +1 @@
1
- {"version":3,"file":"cms-block-service.d.ts","sourceRoot":"","sources":["../../../src/backend/services/cms-block-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAEL,KAAK,cAAc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AK,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC;IAsC7D,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAMxC,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,cAAc,CAAC;IA6DvE,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAuCjG,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAyBzB,OAAO;YAOP,mBAAmB;YAoBnB,mBAAmB;YAkBnB,aAAa;IAQ3B,OAAO,CAAC,aAAa;YAMP,SAAS;YAeT,QAAQ;IAStB,OAAO,CAAC,GAAG;CAGZ"}
@@ -3,28 +3,64 @@ import { ERROR_CODES, } from '@endora-commerce/contracts';
3
3
  import { HttpError } from '@endora-commerce/platform/http';
4
4
  import { walkUnknownComponents } from './content-tree-walker.js';
5
5
  const emptyContent = { languages: {} };
6
+ /**
7
+ * The audit `objectType` of every Block write. One value, so the trail of one
8
+ * block is one query whichever of the four actions wrote the row.
9
+ */
10
+ const BLOCK_OBJECT_TYPE = 'cms_block';
11
+ /**
12
+ * Every write below runs as a Command (Constitution XIII), the way
13
+ * `CmsPageService`'s do: `CommandBus.run` opens the transaction, derives the
14
+ * actor from the ambient TenantContext and records exactly one audit entry
15
+ * beside the write, so a rolled-back write leaves no entry and a committed one
16
+ * cannot skip it. The statements are raw SQL and stay so — what changed is the
17
+ * EntityManager they run on, which is the Command's and no longer one this
18
+ * service opened for itself.
19
+ *
20
+ * What stays **outside** the Command is what is not part of the write: the
21
+ * reference refusal on delete (a read through `CmsReferenceRegistry`, which
22
+ * holds its own manager), the content invalidation (Redis and the published
23
+ * change, only meaningful once the row is committed) and the response read.
24
+ */
6
25
  export class CmsBlockService {
7
26
  emFactory;
27
+ commandBus;
8
28
  knownComponentNames;
9
29
  references;
10
- cache;
11
- constructor(emFactory, knownComponentNames, references, cache) {
30
+ invalidator;
31
+ constructor(emFactory,
32
+ /**
33
+ * Required, with no un-audited fallback: an optional bus is a write path
34
+ * whose absent form audits nothing, which is the defect this parameter
35
+ * exists to remove.
36
+ */
37
+ commandBus, knownComponentNames, references, invalidator) {
12
38
  this.emFactory = emFactory;
39
+ this.commandBus = commandBus;
13
40
  this.knownComponentNames = knownComponentNames;
14
41
  this.references = references;
15
- this.cache = cache;
42
+ this.invalidator = invalidator;
43
+ }
44
+ /** What a block change reaches is `CmsContentInvalidator.blocksChanged`'s to say. */
45
+ async invalidateForBlockCodes(codes) {
46
+ await this.invalidator?.blocksChanged(codes);
16
47
  }
17
48
  /**
18
- * Invalidates the block's own cache entries plus the page-level
19
- * namespace, since we don't track which pages embed which block. The
20
- * page invalidation is coarse but safe: at platform scale (low
21
- * hundreds of pages) the next request rebuilds the cache trivially.
49
+ * What an audit entry keeps of a Block: the facts an operator sets, and not
50
+ * the content tree — the same choice, for the same reason, as a Page's entry.
51
+ * A tree is large and saved many times in one editing session; a content save
52
+ * records which language changed and the version it produced.
22
53
  */
23
- async invalidateForBlockCode(code) {
24
- if (!this.cache)
25
- return;
26
- await this.cache.invalidateBlocksByCode([code]);
27
- await this.cache.invalidateAllPages();
54
+ async auditState(em, row) {
55
+ return {
56
+ name: row.name,
57
+ code: row.code,
58
+ active: row.active,
59
+ description: row.description,
60
+ languages: row.languages,
61
+ salesChannelIds: await this.channelIdsFor(row.id, em),
62
+ version: row.version,
63
+ };
28
64
  }
29
65
  async list(filters = {}) {
30
66
  const params = [];
@@ -43,27 +79,37 @@ export class CmsBlockService {
43
79
  return { data: await Promise.all(rows.map((row) => this.toSummary(row))), nextCursor: null };
44
80
  }
45
81
  async create(input) {
46
- const em = this.emFactory();
47
82
  const id = randomUUID();
48
83
  const now = new Date();
49
- await em.transactional(async (tx) => {
50
- await this.assertCodeAvailable(tx, input.code, input.salesChannelIds);
51
- await tx.execute(`insert into cms_blocks
52
- (id, name, code, active, description, content, languages, version, created_at, updated_at)
53
- values (?, ?, ?, ?, ?, ?::jsonb, ?::jsonb, 1, ?, ?)`, [
54
- id,
55
- input.name,
56
- input.code,
57
- input.active ?? true,
58
- input.description ?? null,
59
- JSON.stringify(emptyContent),
60
- JSON.stringify(input.languages),
61
- now,
62
- now,
63
- ]);
64
- await this.replaceChannelScope(tx, id, input.salesChannelIds, input.code);
84
+ await this.commandBus.run({
85
+ action: 'cms_block.create',
86
+ objectType: BLOCK_OBJECT_TYPE,
87
+ objectId: id,
88
+ run: async ({ em: tx }) => {
89
+ await this.assertCodeAvailable(tx, input.code, input.salesChannelIds);
90
+ await tx.execute(`insert into cms_blocks
91
+ (id, name, code, active, description, content, languages, version, created_at, updated_at)
92
+ values (?, ?, ?, ?, ?, ?::jsonb, ?::jsonb, 1, ?, ?)`, [
93
+ id,
94
+ input.name,
95
+ input.code,
96
+ input.active ?? true,
97
+ input.description ?? null,
98
+ JSON.stringify(emptyContent),
99
+ JSON.stringify(input.languages),
100
+ now,
101
+ now,
102
+ ]);
103
+ await this.replaceChannelScope(tx, id, input.salesChannelIds, input.code);
104
+ const created = await this.findRow(id, tx);
105
+ return {
106
+ result: undefined,
107
+ before: null,
108
+ after: created ? await this.auditState(tx, created) : null,
109
+ };
110
+ },
65
111
  });
66
- await this.invalidateForBlockCode(input.code);
112
+ await this.invalidateForBlockCodes([input.code]);
67
113
  return this.get(id);
68
114
  }
69
115
  async get(id) {
@@ -73,73 +119,97 @@ export class CmsBlockService {
73
119
  return this.toDetail(row);
74
120
  }
75
121
  async patch(id, input) {
76
- const em = this.emFactory();
77
122
  const codesToInvalidate = new Set();
78
- await em.transactional(async (tx) => {
79
- const row = await this.findRow(id, tx);
80
- if (!row)
81
- throw new HttpError(404, ERROR_CODES.CMS_BLOCK_NOT_FOUND, 'CMS Block not found.');
82
- this.assertVersion(row, input.version);
83
- codesToInvalidate.add(row.code);
84
- const nextCode = input.code ?? row.code;
85
- const nextChannels = input.salesChannelIds ?? (await this.channelIdsFor(id, tx));
86
- if (input.code || input.salesChannelIds) {
87
- await this.assertCodeAvailable(tx, nextCode, nextChannels, id);
88
- }
89
- const sets = [];
90
- const params = [];
91
- const set = (sql, value) => {
92
- sets.push(sql);
93
- params.push(value);
94
- };
95
- if (input.name !== undefined)
96
- set('name = ?', input.name);
97
- if (input.code !== undefined)
98
- set('code = ?', input.code);
99
- if (input.active !== undefined)
100
- set('active = ?', input.active);
101
- if (input.description !== undefined)
102
- set('description = ?', input.description);
103
- if (input.languages !== undefined)
104
- set('languages = ?::jsonb', JSON.stringify(input.languages));
105
- if (sets.length > 0) {
106
- params.push(id);
107
- await tx.execute(`update cms_blocks
108
- set ${sets.join(', ')}, version = version + 1, updated_at = now()
109
- where id = ?`, params);
110
- }
111
- if (input.salesChannelIds || input.code) {
112
- await this.replaceChannelScope(tx, id, nextChannels, nextCode);
113
- }
114
- codesToInvalidate.add(nextCode);
123
+ await this.commandBus.run({
124
+ action: 'cms_block.update',
125
+ objectType: BLOCK_OBJECT_TYPE,
126
+ objectId: id,
127
+ run: async ({ em: tx }) => {
128
+ const row = await this.findRow(id, tx);
129
+ if (!row)
130
+ throw new HttpError(404, ERROR_CODES.CMS_BLOCK_NOT_FOUND, 'CMS Block not found.');
131
+ this.assertVersion(row, input.version);
132
+ codesToInvalidate.add(row.code);
133
+ const before = await this.auditState(tx, row);
134
+ const nextCode = input.code ?? row.code;
135
+ const nextChannels = input.salesChannelIds ?? (await this.channelIdsFor(id, tx));
136
+ if (input.code || input.salesChannelIds) {
137
+ await this.assertCodeAvailable(tx, nextCode, nextChannels, id);
138
+ }
139
+ const sets = [];
140
+ const params = [];
141
+ const set = (sql, value) => {
142
+ sets.push(sql);
143
+ params.push(value);
144
+ };
145
+ if (input.name !== undefined)
146
+ set('name = ?', input.name);
147
+ if (input.code !== undefined)
148
+ set('code = ?', input.code);
149
+ if (input.active !== undefined)
150
+ set('active = ?', input.active);
151
+ if (input.description !== undefined)
152
+ set('description = ?', input.description);
153
+ if (input.languages !== undefined)
154
+ set('languages = ?::jsonb', JSON.stringify(input.languages));
155
+ if (sets.length > 0) {
156
+ params.push(id);
157
+ await tx.execute(`update cms_blocks
158
+ set ${sets.join(', ')}, version = version + 1, updated_at = now()
159
+ where id = ?`, params);
160
+ }
161
+ const rescoped = Boolean(input.salesChannelIds || input.code);
162
+ if (rescoped) {
163
+ await this.replaceChannelScope(tx, id, nextChannels, nextCode);
164
+ }
165
+ codesToInvalidate.add(nextCode);
166
+ // A patch that named no field wrote no row, so it leaves no entry: "no
167
+ // write, no audit row" is the bus's own rule and `skipAudit` its spelling.
168
+ if (sets.length === 0 && !rescoped)
169
+ return { result: undefined, skipAudit: true };
170
+ const updated = await this.findRow(id, tx);
171
+ return {
172
+ result: undefined,
173
+ before,
174
+ after: updated ? await this.auditState(tx, updated) : null,
175
+ };
176
+ },
115
177
  });
116
- for (const code of codesToInvalidate)
117
- await this.invalidateForBlockCode(code);
178
+ await this.invalidateForBlockCodes(codesToInvalidate);
118
179
  return this.get(id);
119
180
  }
120
181
  async setContent(id, language, data, version) {
121
- const em = this.emFactory();
122
182
  let invalidatedCode = null;
123
- await em.transactional(async (tx) => {
124
- const row = await this.findRow(id, tx);
125
- if (!row)
126
- throw new HttpError(404, ERROR_CODES.CMS_BLOCK_NOT_FOUND, 'CMS Block not found.');
127
- this.assertVersion(row, version);
128
- invalidatedCode = row.code;
129
- const unknown = walkUnknownComponents(data, new Set(this.knownComponentNames()));
130
- if (unknown.size > 0) {
131
- console.warn(`CMS block ${id} saved with unknown components: ${Array.from(unknown).join(', ')}`);
132
- }
133
- const content = {
134
- languages: { ...(row.content.languages ?? {}), [language]: data },
135
- };
136
- const languages = row.languages.includes(language) ? row.languages : [...row.languages, language];
137
- await tx.execute(`update cms_blocks
138
- set content = ?::jsonb, languages = ?::jsonb, version = version + 1, updated_at = now()
139
- where id = ?`, [JSON.stringify(content), JSON.stringify(languages), id]);
183
+ await this.commandBus.run({
184
+ action: 'cms_block.set_content',
185
+ objectType: BLOCK_OBJECT_TYPE,
186
+ objectId: id,
187
+ run: async ({ em: tx }) => {
188
+ const row = await this.findRow(id, tx);
189
+ if (!row)
190
+ throw new HttpError(404, ERROR_CODES.CMS_BLOCK_NOT_FOUND, 'CMS Block not found.');
191
+ this.assertVersion(row, version);
192
+ invalidatedCode = row.code;
193
+ const unknown = walkUnknownComponents(data, new Set(this.knownComponentNames()));
194
+ if (unknown.size > 0) {
195
+ console.warn(`CMS block ${id} saved with unknown components: ${Array.from(unknown).join(', ')}`);
196
+ }
197
+ const content = {
198
+ languages: { ...(row.content.languages ?? {}), [language]: data },
199
+ };
200
+ const languages = row.languages.includes(language) ? row.languages : [...row.languages, language];
201
+ await tx.execute(`update cms_blocks
202
+ set content = ?::jsonb, languages = ?::jsonb, version = version + 1, updated_at = now()
203
+ where id = ?`, [JSON.stringify(content), JSON.stringify(languages), id]);
204
+ return {
205
+ result: undefined,
206
+ before: { language, version: row.version },
207
+ after: { language, version: row.version + 1 },
208
+ };
209
+ },
140
210
  });
141
211
  if (invalidatedCode)
142
- await this.invalidateForBlockCode(invalidatedCode);
212
+ await this.invalidateForBlockCodes([invalidatedCode]);
143
213
  return this.get(id);
144
214
  }
145
215
  async delete(id) {
@@ -150,8 +220,23 @@ export class CmsBlockService {
150
220
  if (refs.length > 0) {
151
221
  throw new HttpError(409, ERROR_CODES.CMS_REFERENCED, 'CMS Block is referenced.');
152
222
  }
153
- await this.emFactory().execute('delete from cms_blocks where id = ?', [id]);
154
- await this.invalidateForBlockCode(row.code);
223
+ await this.commandBus.run({
224
+ action: 'cms_block.delete',
225
+ objectType: BLOCK_OBJECT_TYPE,
226
+ objectId: id,
227
+ run: async ({ em }) => {
228
+ // Read again on the Command's manager: the entry keeps what the row was
229
+ // at the moment it went, and a block deleted since the check above
230
+ // answers what it always answered.
231
+ const current = await this.findRow(id, em);
232
+ if (!current)
233
+ throw new HttpError(404, ERROR_CODES.CMS_BLOCK_NOT_FOUND, 'CMS Block not found.');
234
+ const before = await this.auditState(em, current);
235
+ await em.execute('delete from cms_blocks where id = ?', [id]);
236
+ return { result: undefined, before, after: null };
237
+ },
238
+ });
239
+ await this.invalidateForBlockCodes([row.code]);
155
240
  }
156
241
  async findRow(id, em = this.emFactory()) {
157
242
  const rows = (await em.execute('select * from cms_blocks where id = ?', [