@phis/ui 0.6.11 → 0.7.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 (84) hide show
  1. package/components/cms/phi-cms-area-render-scope.d.ts +2 -0
  2. package/components/cms/phi-cms-area-render-scope.js +1 -1
  3. package/components/cms/phi-cms-error-page.js +1 -1
  4. package/components/cms/phi-cms-page-render-scope.d.ts +0 -1
  5. package/components/cms/phi-cms-page-render-scope.js +1 -1
  6. package/components/cms/phi-cms-root-layout.js +1 -0
  7. package/components/cms/phi-cms-runtime-registry.d.ts +4 -4
  8. package/components/cms/phi-cms-runtime-registry.js +4 -4
  9. package/components/widgets/label-sets/region.js +2 -0
  10. package/components/widgets/label-types/region.d.ts +2 -0
  11. package/components/widgets/label-types/region.js +1 -0
  12. package/components/widgets/label-types/revisions.js +2 -2
  13. package/components/workspace/catalog-state.d.ts +17 -1
  14. package/components/workspace/catalog-store.js +1 -0
  15. package/gateway/dashboard-cards-route.js +4 -9
  16. package/gateway/form-handler-resolution.js +10 -34
  17. package/gateway/navigation-target-route.js +4 -10
  18. package/gateway/page-references-route.js +3 -8
  19. package/gateway/site-area.d.ts +43 -6
  20. package/gateway/site-area.js +70 -17
  21. package/helpers/cms-area-config.d.ts +36 -14
  22. package/helpers/cms-area-config.js +72 -26
  23. package/next/seo-routes.js +24 -28
  24. package/package.json +2 -2
  25. package/plugins/runtime-modules/accounting/presets.d.ts +0 -1
  26. package/plugins/runtime-modules/accounting/trees/phi-default-accounting-area-preset-tree.js +0 -2
  27. package/plugins/runtime-modules/admin/presets.d.ts +0 -1
  28. package/plugins/runtime-modules/admin/trees/phi-default-admin-area-preset-tree.js +0 -2
  29. package/plugins/runtime-modules/app/presets.d.ts +0 -1
  30. package/plugins/runtime-modules/app/trees/phi-default-app-area-preset-tree.js +0 -2
  31. package/plugins/runtime-modules/area-definitions.d.ts +17 -0
  32. package/plugins/runtime-modules/area-definitions.js +6 -0
  33. package/plugins/runtime-modules/builder/area-shell-presets.server.d.ts +21 -5
  34. package/plugins/runtime-modules/builder/area-shell-presets.server.js +171 -63
  35. package/plugins/runtime-modules/builder/clients/shells-workspace.js +12 -1
  36. package/plugins/runtime-modules/builder/controller/client.js +2 -0
  37. package/plugins/runtime-modules/builder/controller/definition.d.ts +1 -0
  38. package/plugins/runtime-modules/builder/controller/draft-command-controller.d.ts +2 -3
  39. package/plugins/runtime-modules/builder/controller/draft-command-controller.js +56 -25
  40. package/plugins/runtime-modules/builder/controller/draft-status-controller.js +13 -7
  41. package/plugins/runtime-modules/builder/controller/server-definition.d.ts +1 -0
  42. package/plugins/runtime-modules/builder/controller/server-definition.js +7 -4
  43. package/plugins/runtime-modules/builder/controller/workspace-controller.d.ts +2 -1
  44. package/plugins/runtime-modules/builder/controller/workspace-controller.js +9 -3
  45. package/plugins/runtime-modules/builder/data-providers.d.ts +1 -1
  46. package/plugins/runtime-modules/builder/definition.d.ts +1 -1
  47. package/plugins/runtime-modules/builder/developer-workspace-store.js +1 -0
  48. package/plugins/runtime-modules/builder/page-preset-catalog.server.d.ts +0 -2
  49. package/plugins/runtime-modules/builder/page-preset-catalog.server.js +0 -16
  50. package/plugins/runtime-modules/builder/persistence.d.ts +20 -25
  51. package/plugins/runtime-modules/builder/persistence.js +67 -75
  52. package/plugins/runtime-modules/builder/services/runtime-modules-table.d.ts +17 -0
  53. package/plugins/runtime-modules/builder/services/runtime-modules-table.js +79 -2
  54. package/plugins/runtime-modules/builder/trees/phi-default-builder-area-preset-tree.d.ts +0 -1
  55. package/plugins/runtime-modules/builder/trees/phi-default-builder-area-preset-tree.js +0 -2
  56. package/plugins/runtime-modules/builder/workspace-catalog-actions.d.ts +2 -1
  57. package/plugins/runtime-modules/builder/workspace-catalog-actions.js +3 -1
  58. package/plugins/runtime-modules/core/widgets/cascader/authoring.d.ts +1 -1
  59. package/plugins/runtime-modules/descriptor-compiler.d.ts +16 -2
  60. package/plugins/runtime-modules/descriptor-compiler.js +69 -13
  61. package/plugins/runtime-modules/editor/services/releases-table.js +26 -14
  62. package/plugins/runtime-modules/editor/trees/phi-default-editor-area-preset-tree.js +0 -2
  63. package/plugins/runtime-modules/groups/definition.d.ts +1 -1
  64. package/plugins/runtime-modules/phi-default-site-area-preset-tree.js +0 -2
  65. package/plugins/runtime-modules/revisions/controller/client.js +13 -7
  66. package/plugins/runtime-modules/revisions/services/table.js +10 -3
  67. package/plugins/runtime-modules/shell-tree-composition.d.ts +0 -2
  68. package/plugins/runtime-modules/shell-tree-composition.js +0 -3
  69. package/server-helpers/area-root-door-warmup.d.ts +5 -2
  70. package/server-helpers/area-root-door-warmup.js +2 -10
  71. package/server-helpers/cms-area.d.ts +9 -1
  72. package/server-helpers/cms-area.js +16 -11
  73. package/server-helpers/cms-lookup.js +1 -1
  74. package/server-helpers/cms-request.d.ts +58 -13
  75. package/server-helpers/cms-request.js +103 -33
  76. package/server-helpers/cms-root.d.ts +4 -0
  77. package/server-helpers/cms-root.js +48 -35
  78. package/server-helpers/cms.d.ts +5 -5
  79. package/server-helpers/public-login-route.js +4 -9
  80. package/server-helpers/search-index.js +9 -14
  81. package/styles/shell.css +12 -0
  82. package/types/cms-module-descriptors.d.ts +26 -1
  83. package/types/cms-plugins.d.ts +3 -0
  84. package/types/cms.d.ts +10 -3
@@ -2,12 +2,53 @@ import { isPhiRecord } from "../helpers/is-record";
2
2
  import { definePhiRequestMemo } from "../server-helpers/request-memo";
3
3
  import "server-only";
4
4
  import { fetchPhiSiteApi } from "./site-api-request";
5
+ function readAreaModulesSelection(value, context) {
6
+ if (value === null || value === undefined) {
7
+ return null;
8
+ }
9
+ if (!isPhiRecord(value) ||
10
+ !Number.isSafeInteger(value.revisionId) ||
11
+ value.revisionId <= 0 ||
12
+ !isPhiRecord(value.config)) {
13
+ throw new Error(`Invalid Area Module selection in ${context}.`);
14
+ }
15
+ return { revisionId: value.revisionId, config: value.config };
16
+ }
17
+ function readAreaStructure(areaMask, sourcePreset, preset, context) {
18
+ if (preset === null || preset === undefined) {
19
+ return null;
20
+ }
21
+ if (!isPhiRecord(preset) || !isPhiRecord(preset.preset) || !isPhiRecord(sourcePreset)) {
22
+ throw new Error(`Missing CMS area structure in ${context}.`);
23
+ }
24
+ return {
25
+ areaMask,
26
+ sourcePreset: sourcePreset,
27
+ preset: preset,
28
+ };
29
+ }
30
+ function readSiteAreaRead(body, context) {
31
+ if (!isPhiRecord(body) || !Number.isSafeInteger(body.areaMask)) {
32
+ throw new Error(`Missing CMS area payload in ${context}.`);
33
+ }
34
+ const areaMask = body.areaMask;
35
+ return {
36
+ areaMask,
37
+ modules: readAreaModulesSelection(body.modules, context),
38
+ structure: readAreaStructure(areaMask, body.sourcePreset, body.preset, context),
39
+ ...(Number.isSafeInteger(body.revisionId) ? { revisionId: body.revisionId } : {}),
40
+ };
41
+ }
42
+ /**
43
+ * The Area read (`GET /api/v1/site/area`). Live it always answers; a revision or review read answers
44
+ * `null` for a revision that is not there -- or, for a structure revision, not under the identity named.
45
+ */
5
46
  export const getExactSiteArea = definePhiRequestMemo(async function getExactSiteArea({ apiBaseUrl, internalToken, siteKey, path, locale, revision, review, cookieHeader, sourcePreset, }) {
6
- const searchParams = new URLSearchParams({
7
- path,
8
- ownerModuleId: sourcePreset.ownerModuleId,
9
- presetKey: sourcePreset.presetKey,
10
- });
47
+ const searchParams = new URLSearchParams({ path });
48
+ if (sourcePreset) {
49
+ searchParams.set("ownerModuleId", sourcePreset.ownerModuleId);
50
+ searchParams.set("presetKey", sourcePreset.presetKey);
51
+ }
11
52
  if (Number.isInteger(revision) && revision > 0) {
12
53
  searchParams.set("revision", String(revision));
13
54
  }
@@ -27,13 +68,7 @@ export const getExactSiteArea = definePhiRequestMemo(async function getExactSite
27
68
  failure: "Failed to fetch exact CMS area",
28
69
  notFoundIsNull: true,
29
70
  });
30
- if (payload === null) {
31
- return null;
32
- }
33
- if (!payload?.preset?.preset) {
34
- throw new Error("Missing CMS area payload.");
35
- }
36
- return payload;
71
+ return payload === null ? null : readSiteAreaRead(payload, "getExactSiteArea");
37
72
  });
38
73
  function readPublishedPage(entry) {
39
74
  if (!isPhiRecord(entry)) {
@@ -65,7 +100,7 @@ function readPublishedPage(entry) {
65
100
  * anonymous only, so no cookie is sent and no draft can be asked for. Core answers it for the Public
66
101
  * and the App Area, the two anything indexes (SEARCH.md).
67
102
  */
68
- export async function getSiteAreaWithPublishedPages({ apiBaseUrl, internalToken, siteKey, locale, sourcePreset, area = "public", }) {
103
+ export async function getSiteAreaWithPublishedPages({ apiBaseUrl, internalToken, siteKey, locale, area = "public", }) {
69
104
  const payload = await fetchPhiSiteApi({
70
105
  context: "getSiteAreaWithPublishedPages",
71
106
  apiBaseUrl,
@@ -75,22 +110,37 @@ export async function getSiteAreaWithPublishedPages({ apiBaseUrl, internalToken,
75
110
  searchParams: {
76
111
  // Core reads the Area off the path's first segment; Public has none.
77
112
  path: area === "public" ? "/" : `/${area}`,
78
- ownerModuleId: sourcePreset.ownerModuleId,
79
- presetKey: sourcePreset.presetKey,
80
113
  include: "publishedPages",
81
114
  },
82
115
  locale,
83
116
  failure: `Failed to fetch the ${area} Area with its Pages`,
84
117
  userAgent: "phis-ui-sitemap/1.0",
85
118
  });
86
- if (!payload || !Array.isArray(payload.publishedPages)) {
119
+ if (!isPhiRecord(payload) || !Array.isArray(payload.publishedPages)) {
87
120
  throw new Error("Missing published Page projection.");
88
121
  }
89
122
  return {
90
- area: payload.preset ? payload : null,
123
+ area: readSiteAreaRead(payload, "getSiteAreaWithPublishedPages"),
91
124
  publishedPages: payload.publishedPages.map(readPublishedPage),
92
125
  };
93
126
  }
127
+ function readAreaModulesStructure(value, area) {
128
+ if (!isPhiRecord(value)) {
129
+ throw new Error(`Missing CMS area Module selection for "${area}".`);
130
+ }
131
+ const context = `the structures read of "${area}"`;
132
+ const draft = readAreaModulesSelection(value.draft ?? null, context);
133
+ const draftRecord = isPhiRecord(value.draft) ? value.draft : null;
134
+ if (draft && (!Number.isSafeInteger(draftRecord?.version) || !Number.isSafeInteger(draftRecord?.nextNodeSequence))) {
135
+ throw new Error(`Invalid Area Module draft in ${context}.`);
136
+ }
137
+ return {
138
+ draft: draft
139
+ ? { ...draft, version: draftRecord.version, nextNodeSequence: draftRecord.nextNodeSequence }
140
+ : null,
141
+ published: draft ? null : readAreaModulesSelection(value.published ?? null, context),
142
+ };
143
+ }
94
144
  function readAreaStructurePayload(value, area, kind) {
95
145
  if (value === null) {
96
146
  return null;
@@ -104,6 +154,8 @@ function readAreaStructurePayload(value, area, kind) {
104
154
  * What several Areas store about their structure, in one request: per Area its open draft, else what is
105
155
  * published, else nothing -- for each the answer of the draft read (`GET /api/site/cms/area/draft`) or of
106
156
  * `getExactSiteArea`, without a request per Area and read (phis-server `POST /api/site/cms/area/structures`).
157
+ * Each entry also carries the Area's Module selection, which names no identity. An Area may be asked more
158
+ * than once, under each shell identity it could stand on: the structure answers only under its own.
107
159
  */
108
160
  export const getSiteAreaStructures = definePhiRequestMemo(async function getSiteAreaStructures({ apiBaseUrl, internalToken, siteKey, locale, cookieHeader, areas, }) {
109
161
  const payload = await fetchPhiSiteApi({
@@ -131,6 +183,7 @@ export const getSiteAreaStructures = definePhiRequestMemo(async function getSite
131
183
  area: request.area,
132
184
  draft: readAreaStructurePayload(answer.draft ?? null, request.area, "draft"),
133
185
  published: readAreaStructurePayload(answer.published ?? null, request.area, "published"),
186
+ modules: readAreaModulesStructure(answer.modules, request.area),
134
187
  };
135
188
  });
136
189
  });
@@ -1,15 +1,15 @@
1
1
  import type { PhiBuilderAreaKey } from "../constants/cms-areas";
2
2
  import type { PhiRuntimeModuleId } from "../types";
3
- import type { PhiResolvedCmsAreaPresetTree } from "../types/cms";
3
+ import type { PhiCmsAreaModulesSelection } from "../types/cms";
4
4
  import type { PhiCmsInstanceId } from "../types/cms-instance-id";
5
5
  import { type PhiPageReference } from "../types/references";
6
6
  /**
7
7
  * The two halves of an Area preset config, expressed as a path rather than as a list of field names.
8
8
  *
9
9
  * An Area is edited from two workspaces that own different things: its structure on `/builder/shells`,
10
- * its Module selection on `/builder/modules`. Which one may write a given value used to be a convention
11
- * kept by the client and a comment in the server's publish merge; naming the halves makes it a path,
12
- * and the write routes reject a payload that carries the other one.
10
+ * its Module selection on `/builder/modules`. The two are stored apart: `config.shell` in the structure
11
+ * revisions, `config.modules` in the Modules revisions, and each write route rejects a payload that
12
+ * carries the other one.
13
13
  *
14
14
  * A Shell Background is not in here, and that is not an oversight: it belongs to a Region and travels
15
15
  * in the structure tree. What lives under `shell` is what the Shell states about itself rather than
@@ -18,19 +18,17 @@ import { type PhiPageReference } from "../types/references";
18
18
  export declare const PHI_AREA_CONFIG_SHELL_NAMESPACE: "shell";
19
19
  export declare const PHI_AREA_CONFIG_MODULES_NAMESPACE: "modules";
20
20
  /**
21
- * The Modules an Area preset actually activates.
21
+ * The Modules an Area's selection activates.
22
22
  *
23
- * Absent and empty are different answers and are read as different answers: nothing stated is an Area
24
- * that was never asked, and it gets the selection its preset ships with; `[]` is a Builder who
25
- * switched everything off, and it gets nothing.
23
+ * The selection is stored apart from the structure (`PhiCmsAreaModulesSelection`, one Modules revision
24
+ * whose config is `{ modules }`), because the shell an Area takes depends on it and so it has to be read
25
+ * before the shell is known. A structure tree never carries it.
26
26
  *
27
- * The distinction is load-bearing rather than pedantic. A stored Area preset need not carry the
28
- * Modules namespace at all -- the structure draft owns `config.shell` and writes only that -- so
29
- * reading an absent selection as an empty one would let the first structure save of an Area whose
30
- * Modules were never published turn every optional Module off, silently, and take the Pages they carry
31
- * with them.
27
+ * Absent and empty are different answers and are read as different answers: no selection stored is an
28
+ * Area that was never asked, and it gets the default list (`createPhiDefaultAreaRuntimeModuleIds`); `[]`
29
+ * is a Builder who switched everything off, and it gets nothing.
32
30
  */
33
- export declare function readPhiAreaPresetRuntimeModuleIds(tree: Pick<PhiResolvedCmsAreaPresetTree, "runtimeModuleIds" | "preset"> | null | undefined, area: PhiBuilderAreaKey): PhiRuntimeModuleId[];
31
+ export declare function readPhiAreaSelectionRuntimeModuleIds(selection: Pick<PhiCmsAreaModulesSelection, "config"> | null | undefined, area: PhiBuilderAreaKey): PhiRuntimeModuleId[];
34
32
  export declare const PHI_AREA_ROOT_ROUTE_KEY: "rootRoute";
35
33
  /**
36
34
  * What an Area's `/` resolves to.
@@ -189,6 +187,30 @@ export declare const PHI_AREA_META_PUBLIC_DEFAULTS: {
189
187
  */
190
188
  export declare const PHI_AREA_TITLE_TEMPLATE_PLACEHOLDER: "%s";
191
189
  export declare function readPhiAreaMeta(config: Record<string, unknown> | null | undefined): PhiAreaMeta | null;
190
+ /**
191
+ * What an Area shell preset may propose for the Area's settings (`PhiCmsAreaShellPresetDescriptor`),
192
+ * under the keys a Builder save stores them under in `config.shell`.
193
+ */
194
+ export type PhiAreaShellSettings = {
195
+ meta?: PhiAreaMeta;
196
+ rootRoute?: PhiAreaRootRoute;
197
+ };
198
+ /**
199
+ * A shell preset's proposal as the Area config it stands for, read by the same readers as a stored one.
200
+ *
201
+ * Empty for a shell that proposes nothing, which is phis-ui's defaults answering. The answer of an Area
202
+ * that stores a structure on its shell, never this, wherever that structure exists: a Site that saved
203
+ * once has answered, even where it answered with what was proposed.
204
+ */
205
+ export declare function buildPhiAreaShellPresetConfig(settings: PhiAreaShellSettings | null | undefined): Record<string, unknown>;
206
+ /**
207
+ * Why a shell preset's proposal cannot be read as it is written, or null when it can.
208
+ *
209
+ * Strict on purpose (a wrong type is an error, never a silent default): what a package declares here is
210
+ * what every Site that switches it on is served until it saves, so a key the readers drop would be a
211
+ * setting the package believes it made.
212
+ */
213
+ export declare function describePhiAreaShellSettingsError(settings: unknown): string | null;
192
214
  export declare const PHI_AREA_PUBLIC_ROUTE_PATHS_KEY: "publicRoutePaths";
193
215
  /**
194
216
  * A Public address a Module route was given instead of the one it declared.
@@ -6,9 +6,9 @@ import { createPhiPresetCmsPageId, readPhiLinkTarget, readPhiPageReference, } fr
6
6
  * The two halves of an Area preset config, expressed as a path rather than as a list of field names.
7
7
  *
8
8
  * An Area is edited from two workspaces that own different things: its structure on `/builder/shells`,
9
- * its Module selection on `/builder/modules`. Which one may write a given value used to be a convention
10
- * kept by the client and a comment in the server's publish merge; naming the halves makes it a path,
11
- * and the write routes reject a payload that carries the other one.
9
+ * its Module selection on `/builder/modules`. The two are stored apart: `config.shell` in the structure
10
+ * revisions, `config.modules` in the Modules revisions, and each write route rejects a payload that
11
+ * carries the other one.
12
12
  *
13
13
  * A Shell Background is not in here, and that is not an oversight: it belongs to a Region and travels
14
14
  * in the structure tree. What lives under `shell` is what the Shell states about itself rather than
@@ -23,32 +23,18 @@ function readPhiAreaConfigNamespace(config, namespace) {
23
23
  : undefined;
24
24
  }
25
25
  /**
26
- * The Module selection an Area preset carries.
26
+ * The Modules an Area's selection activates.
27
27
  *
28
- * `runtimeModuleIds` is the resolved field the payload already carries when it has one; the stored
29
- * config is what a Site that persisted its Area falls back to. Both readings sit here so the namespace
30
- * appears once rather than at every call site that needs the selection.
31
- */
32
- function readPhiAreaPresetRuntimeModules(tree) {
33
- return tree?.runtimeModuleIds
34
- ?? readPhiAreaConfigNamespace(tree?.preset.config, PHI_AREA_CONFIG_MODULES_NAMESPACE)?.runtimeModules;
35
- }
36
- /**
37
- * The Modules an Area preset actually activates.
38
- *
39
- * Absent and empty are different answers and are read as different answers: nothing stated is an Area
40
- * that was never asked, and it gets the selection its preset ships with; `[]` is a Builder who
41
- * switched everything off, and it gets nothing.
28
+ * The selection is stored apart from the structure (`PhiCmsAreaModulesSelection`, one Modules revision
29
+ * whose config is `{ modules }`), because the shell an Area takes depends on it and so it has to be read
30
+ * before the shell is known. A structure tree never carries it.
42
31
  *
43
- * The distinction is load-bearing rather than pedantic. A stored Area preset need not carry the
44
- * Modules namespace at all -- the structure draft owns `config.shell` and writes only that -- so
45
- * reading an absent selection as an empty one would let the first structure save of an Area whose
46
- * Modules were never published turn every optional Module off, silently, and take the Pages they carry
47
- * with them.
32
+ * Absent and empty are different answers and are read as different answers: no selection stored is an
33
+ * Area that was never asked, and it gets the default list (`createPhiDefaultAreaRuntimeModuleIds`); `[]`
34
+ * is a Builder who switched everything off, and it gets nothing.
48
35
  */
49
- export function readPhiAreaPresetRuntimeModuleIds(tree, area) {
50
- return readPhiRuntimeModuleIds(readPhiAreaPresetRuntimeModules(tree))
51
- ?? createPhiDefaultAreaRuntimeModuleIds(area);
36
+ export function readPhiAreaSelectionRuntimeModuleIds(selection, area) {
37
+ return readPhiRuntimeModuleIds(readPhiAreaConfigNamespace(selection?.config, PHI_AREA_CONFIG_MODULES_NAMESPACE)?.runtimeModules) ?? createPhiDefaultAreaRuntimeModuleIds(area);
52
38
  }
53
39
  export const PHI_AREA_ROOT_ROUTE_KEY = "rootRoute";
54
40
  export function readPhiAreaRootRoute(config) {
@@ -179,6 +165,66 @@ export function readPhiAreaMeta(config) {
179
165
  ...(typeof record.defaultTitle === "string" ? { defaultTitle: record.defaultTitle } : {}),
180
166
  };
181
167
  }
168
+ /**
169
+ * A shell preset's proposal as the Area config it stands for, read by the same readers as a stored one.
170
+ *
171
+ * Empty for a shell that proposes nothing, which is phis-ui's defaults answering. The answer of an Area
172
+ * that stores a structure on its shell, never this, wherever that structure exists: a Site that saved
173
+ * once has answered, even where it answered with what was proposed.
174
+ */
175
+ export function buildPhiAreaShellPresetConfig(settings) {
176
+ if (!settings || (settings.meta === undefined && settings.rootRoute === undefined)) {
177
+ return {};
178
+ }
179
+ return {
180
+ [PHI_AREA_CONFIG_SHELL_NAMESPACE]: {
181
+ ...(settings.meta !== undefined ? { [PHI_AREA_META_KEY]: settings.meta } : {}),
182
+ ...(settings.rootRoute !== undefined ? { [PHI_AREA_ROOT_ROUTE_KEY]: settings.rootRoute } : {}),
183
+ },
184
+ };
185
+ }
186
+ /**
187
+ * Why a shell preset's proposal cannot be read as it is written, or null when it can.
188
+ *
189
+ * Strict on purpose (a wrong type is an error, never a silent default): what a package declares here is
190
+ * what every Site that switches it on is served until it saves, so a key the readers drop would be a
191
+ * setting the package believes it made.
192
+ */
193
+ export function describePhiAreaShellSettingsError(settings) {
194
+ if (settings === undefined) {
195
+ return null;
196
+ }
197
+ if (!isPhiRecord(settings)) {
198
+ return "settings must be an object";
199
+ }
200
+ const unknownKey = Object.keys(settings).find((key) => key !== PHI_AREA_META_KEY && key !== PHI_AREA_ROOT_ROUTE_KEY);
201
+ if (unknownKey) {
202
+ return `settings.${unknownKey} is not an Area setting (meta, rootRoute)`;
203
+ }
204
+ const config = buildPhiAreaShellPresetConfig(settings);
205
+ if (settings.meta !== undefined) {
206
+ if (!isPhiRecord(settings.meta)) {
207
+ return "settings.meta must be an object";
208
+ }
209
+ const read = readPhiAreaMeta(config) ?? {};
210
+ const dropped = Object.keys(settings.meta).find((key) => read[key] !== settings.meta[key]);
211
+ if (dropped) {
212
+ return `settings.meta.${dropped} is not a readable Area meta value`;
213
+ }
214
+ if (read.titleTemplate !== undefined && !read.titleTemplate.includes(PHI_AREA_TITLE_TEMPLATE_PLACEHOLDER)) {
215
+ return `settings.meta.titleTemplate must hold "${PHI_AREA_TITLE_TEMPLATE_PLACEHOLDER}"`;
216
+ }
217
+ }
218
+ if (settings.rootRoute !== undefined) {
219
+ const read = readPhiAreaRootRoute(config);
220
+ const written = settings.rootRoute;
221
+ // A landing reads even with an unreadable target (as none), so the target is checked on its own.
222
+ if (!read || read.mode !== written.mode || (read.mode === "landing" && written.target !== undefined && !read.target)) {
223
+ return "settings.rootRoute is not a readable root route";
224
+ }
225
+ }
226
+ return null;
227
+ }
182
228
  export const PHI_AREA_PUBLIC_ROUTE_PATHS_KEY = "publicRoutePaths";
183
229
  const PHI_PUBLIC_ROUTE_PATH_SEGMENT_PATTERN = /^[\p{L}\p{N}][\p{L}\p{N}._~-]*$/u;
184
230
  /**
@@ -2,13 +2,13 @@ import "server-only";
2
2
  import { createHash } from "node:crypto";
3
3
  import { resolvePhiCmsPageRedirect } from "../components/cms/phi-cms-page-redirect";
4
4
  import { getSiteAreaWithPublishedPages } from "../gateway/site-area";
5
- import { PHI_AREA_META_PUBLIC_DEFAULTS, readPhiAreaLandingSelection, readPhiAreaMeta, readPhiAreaPublicRoutePaths, } from "../helpers/cms-area-config";
5
+ import { buildPhiAreaShellPresetConfig, PHI_AREA_META_PUBLIC_DEFAULTS, readPhiAreaMeta, } from "../helpers/cms-area-config";
6
6
  import { collectPhiSitemapCandidates, renderPhiRobotsTxt, renderPhiSitemapDocuments, renderPhiSitemapIndexXml, resolvePhiSitePublicBase, } from "../helpers/phi-seo";
7
7
  import { createPhiFingerprintCache } from "../helpers/phi-sitemap-cache";
8
8
  import { readPhiSiteRuntimeConfigSync } from "../helpers/site-runtime";
9
- import { compilePhiCmsActiveRouteTable, resolvePhiCmsAreaShellPresetBinding, resolvePhiCmsDescriptorCatalog, } from "../plugins/runtime-modules/descriptor-compiler";
9
+ import { resolvePhiCmsAreaBaseShellPresetBinding, resolvePhiCmsDescriptorCatalog, } from "../plugins/runtime-modules/descriptor-compiler";
10
10
  import { getPhiExactSiteArea } from "../server-helpers/cms";
11
- import { resolveActivePresetModuleKeys } from "../server-helpers/cms-request";
11
+ import { resolvePhiAreaRouteScope } from "../server-helpers/cms-request";
12
12
  import { resolvePhiCmsLookup } from "../server-helpers/cms-lookup";
13
13
  import { loadPhiSiteRequestContext } from "../server-helpers/runtime";
14
14
  import { fetchSiteLocaleConfig } from "../server-helpers/site-locale";
@@ -31,16 +31,11 @@ async function loadPhiPublicSeoContext(bridge, { withPublishedPages }) {
31
31
  const locale = localeConfig.defaultLocale;
32
32
  const requestContext = await loadPhiSiteRequestContext(siteKey, locale, "", apiBaseUrl, internalToken);
33
33
  const catalog = resolvePhiCmsDescriptorCatalog(bridge.runtimeModuleCatalog);
34
- const shellBinding = resolvePhiCmsAreaShellPresetBinding(catalog, "public");
35
- if (!shellBinding) {
34
+ if (!resolvePhiCmsAreaBaseShellPresetBinding(catalog, "public")) {
36
35
  return null;
37
36
  }
38
- const sourcePreset = {
39
- ownerModuleId: shellBinding.descriptor.ownerModuleId,
40
- presetKey: shellBinding.descriptor.presetKey,
41
- };
42
- const { area: areaPreset, publishedPages } = withPublishedPages
43
- ? await getSiteAreaWithPublishedPages({ apiBaseUrl, internalToken, siteKey, locale, sourcePreset })
37
+ const { area: storedArea, publishedPages } = withPublishedPages
38
+ ? await getSiteAreaWithPublishedPages({ apiBaseUrl, internalToken, siteKey, locale })
44
39
  : {
45
40
  area: await getPhiExactSiteArea({
46
41
  path: "/",
@@ -49,18 +44,26 @@ async function loadPhiPublicSeoContext(bridge, { withPublishedPages }) {
49
44
  internalToken,
50
45
  locale,
51
46
  cookieHeader: "",
52
- sourcePreset,
53
47
  }),
54
48
  publishedPages: [],
55
49
  };
56
- const meta = readPhiAreaMeta(areaPreset?.preset.preset.config);
50
+ const scope = resolvePhiAreaRouteScope({
51
+ runtimeModuleCatalog: bridge.runtimeModuleCatalog,
52
+ catalog,
53
+ area: "public",
54
+ read: storedArea,
55
+ serverCapabilities: requestContext.serverCapabilities,
56
+ });
57
+ // The stored answer, else what the effective shell proposes (`settings`), as the Page render reads it.
58
+ const meta = readPhiAreaMeta(scope.structure ? scope.structure.preset.preset.config : buildPhiAreaShellPresetConfig(scope.shellBinding.descriptor.settings));
57
59
  const publicBase = resolvePhiSitePublicBase(requestContext.site.publicUrl, readPhiSiteRuntimeConfigSync().site.publicUrl);
58
60
  return {
59
61
  bridgeRuntime,
60
62
  requestContext,
61
63
  locale,
62
64
  publicBase,
63
- areaPreset,
65
+ storedArea,
66
+ scope,
64
67
  publishedPages,
65
68
  sitemapEnabled: Boolean(publicBase)
66
69
  && (meta?.index ?? PHI_AREA_META_PUBLIC_DEFAULTS.index)
@@ -101,15 +104,8 @@ async function filterPhiSitemapCandidates(bridge, context, candidates) {
101
104
  await Promise.all(Array.from({ length: PHI_SITEMAP_RESOLVE_CONCURRENCY }, work));
102
105
  return candidates.filter((_candidate, index) => listed[index]);
103
106
  }
104
- async function buildPhiSitemapDocuments(bridge, context, activeModuleIds) {
105
- const { requestContext, areaPreset, publishedPages } = context;
106
- const routeTable = compilePhiCmsActiveRouteTable({
107
- catalog: resolvePhiCmsDescriptorCatalog(bridge.runtimeModuleCatalog),
108
- area: "public",
109
- activeModuleIds,
110
- publicRoutePaths: readPhiAreaPublicRoutePaths(areaPreset?.preset.preset.config),
111
- landingSelection: readPhiAreaLandingSelection(areaPreset?.preset.preset.config),
112
- });
107
+ async function buildPhiSitemapDocuments(bridge, context) {
108
+ const { requestContext, scope: { routeTable }, publishedPages } = context;
113
109
  const candidates = collectPhiSitemapCandidates({
114
110
  moduleRoutes: [...routeTable.exactByPath].map(([path, descriptor]) => [path, descriptor]),
115
111
  publishedPages,
@@ -130,11 +126,12 @@ async function buildPhiSitemapDocuments(bridge, context, activeModuleIds) {
130
126
  * What it leaves out -- the installed Module catalog -- changes only with a new Site process, and a
131
127
  * new process starts with an empty cache.
132
128
  */
133
- function buildPhiSitemapFingerprint(context, activeModuleIds) {
129
+ function buildPhiSitemapFingerprint(context) {
134
130
  return createHash("sha256").update(JSON.stringify({
135
131
  publishedPages: context.publishedPages,
136
- area: context.areaPreset?.preset ?? null,
137
- activeModuleIds: [...activeModuleIds].sort(),
132
+ area: context.scope.structure?.preset ?? null,
133
+ modules: context.storedArea?.modules ?? null,
134
+ activeModuleIds: [...context.scope.activeModuleIds].sort(),
138
135
  publicBase: context.publicBase,
139
136
  availableLocales: context.requestContext.site.availableLocales.map((option) => option.code),
140
137
  defaultLocale: context.requestContext.site.defaultLocale,
@@ -158,8 +155,7 @@ export function buildPhiSitemapRouteHandler({ bridge }) {
158
155
  if (!context?.sitemapEnabled || !publicBase) {
159
156
  return new Response("Not Found", { status: 404, headers: { "cache-control": "no-store" } });
160
157
  }
161
- const activeModuleIds = resolveActivePresetModuleKeys(bridge.runtimeModuleCatalog, "public", context.areaPreset ? { preset: context.areaPreset.preset } : null, context.requestContext.serverCapabilities);
162
- const documents = await cache.resolve(buildPhiSitemapFingerprint(context, activeModuleIds), () => buildPhiSitemapDocuments(bridge, { ...context, publicBase }, activeModuleIds));
158
+ const documents = await cache.resolve(buildPhiSitemapFingerprint(context), () => buildPhiSitemapDocuments(bridge, { ...context, publicBase }));
163
159
  /*
164
160
  * One file answers on its own address. More than one -- above 50,000 URLs or 45 MB -- turns
165
161
  * `/sitemap.xml` into an index whose parts are the same route with `?part=<n>`, so the Site needs no
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phis/ui",
3
- "version": "0.6.11",
3
+ "version": "0.7.0",
4
4
  "license": "Apache-2.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -521,7 +521,7 @@
521
521
  "@lexical/rich-text": "0.50.0",
522
522
  "@lexical/selection": "0.50.0",
523
523
  "@lexical/utils": "0.50.0",
524
- "@phis/contracts": "^0.7.13",
524
+ "@phis/contracts": "^0.8.0",
525
525
  "dayjs": "^1.11.23",
526
526
  "dom-serializer": "^2.0.0",
527
527
  "htmlparser2": "^10.1.0",
@@ -6,7 +6,6 @@ export declare const PHI_ACCOUNTING_RUNTIME_MODULE_AREA_SHELLS: {
6
6
  area: "accounting";
7
7
  loadTree: ({ page, runtime }: PhiCmsDescriptorBuildContext) => Promise<{
8
8
  pageMeta: import("../../../types").PhiCmsResolvedPageMeta | null | undefined;
9
- runtimeModuleIds: `${string}/${string}`[] | null | undefined;
10
9
  regions: import("../../../types").PhiCmsRegionNode[];
11
10
  overlays: import("../../../types").PhiCmsOverlayNode[];
12
11
  layoutNodes: import("../../../types").PhiCmsLayoutNode[];
@@ -2,7 +2,6 @@ import { createPhiPresetCmsInstanceIdMap } from "../../../../types/cms-instance-
2
2
  import { PHI_ACCOUNTING_RUNTIME_MODULE_ID } from "../ids";
3
3
  import { createPhiCmsPresetNodes } from "../../../../helpers/cms-preset-nodes";
4
4
  import { buildPhiAreaShellHeaderNodes, buildPhiAreaShellSiderLeftNodes, concatPhiAreaShellPresetNodes, } from "../../../../components/regions/presets/phi-area-shell-preset-nodes";
5
- import { createPhiDefaultAreaRuntimeModuleIds } from "../../area-module-defaults";
6
5
  /*
7
6
  * The staff shell, as Admin's: the header bar with the Page title as a caption, the Tour button and the
8
7
  * Account, and the sidebar on `accounting:sidebar`, composed over the Site's shell in `../presets.ts`.
@@ -35,7 +34,6 @@ export async function buildPhiDefaultAccountingAreaPresetTree({ page, runtime, }
35
34
  const nodes = createPhiCmsPresetNodes(page);
36
35
  return {
37
36
  page: nodes.page(),
38
- runtimeModuleIds: createPhiDefaultAreaRuntimeModuleIds("accounting"),
39
37
  overlays: [],
40
38
  ...concatPhiAreaShellPresetNodes(buildPhiAreaShellHeaderNodes({
41
39
  nodes,
@@ -6,7 +6,6 @@ export declare const PHI_ADMIN_RUNTIME_MODULE_AREA_SHELLS: {
6
6
  area: "admin";
7
7
  loadTree: ({ page, runtime }: PhiCmsDescriptorBuildContext) => Promise<{
8
8
  pageMeta: import("../../../types").PhiCmsResolvedPageMeta | null | undefined;
9
- runtimeModuleIds: `${string}/${string}`[] | null | undefined;
10
9
  regions: import("../../../types").PhiCmsRegionNode[];
11
10
  overlays: import("../../../types").PhiCmsOverlayNode[];
12
11
  layoutNodes: import("../../../types").PhiCmsLayoutNode[];
@@ -2,7 +2,6 @@ import { createPhiPresetCmsInstanceIdMap } from "../../../../types/cms-instance-
2
2
  import { PHI_ADMIN_RUNTIME_MODULE_ID } from "../ids";
3
3
  import { createPhiCmsPresetNodes } from "../../../../helpers/cms-preset-nodes";
4
4
  import { buildPhiAreaShellHeaderNodes, buildPhiAreaShellSiderLeftNodes, concatPhiAreaShellPresetNodes, } from "../../../../components/regions/presets/phi-area-shell-preset-nodes";
5
- import { createPhiDefaultAreaRuntimeModuleIds } from "../../area-module-defaults";
6
5
  const SYNTHETIC_ADMIN_REGION_IDS = {
7
6
  regionHeaderTop: -126,
8
7
  regionSiderLeft: -130,
@@ -30,7 +29,6 @@ export async function buildPhiDefaultAdminAreaPresetTree({ page, runtime, }) {
30
29
  const nodes = createPhiCmsPresetNodes(page);
31
30
  return {
32
31
  page: nodes.page(),
33
- runtimeModuleIds: createPhiDefaultAreaRuntimeModuleIds("admin"),
34
32
  overlays: [],
35
33
  ...concatPhiAreaShellPresetNodes(buildPhiAreaShellHeaderNodes({
36
34
  nodes,
@@ -6,7 +6,6 @@ export declare const PHI_APP_RUNTIME_MODULE_AREA_SHELLS: {
6
6
  area: "app";
7
7
  loadTree: ({ page, runtime }: PhiCmsDescriptorBuildContext) => Promise<{
8
8
  pageMeta: import("../../../types").PhiCmsResolvedPageMeta | null | undefined;
9
- runtimeModuleIds: `${string}/${string}`[] | null | undefined;
10
9
  regions: import("../../../types").PhiCmsRegionNode[];
11
10
  overlays: import("../../../types").PhiCmsOverlayNode[];
12
11
  layoutNodes: import("../../../types").PhiCmsLayoutNode[];
@@ -2,7 +2,6 @@ import { createPhiPresetCmsInstanceIdMap } from "../../../../types/cms-instance-
2
2
  import { PHI_APP_RUNTIME_MODULE_ID } from "../ids";
3
3
  import { createPhiCmsPresetNodes } from "../../../../helpers/cms-preset-nodes";
4
4
  import { buildPhiAreaShellSiderLeftNodes } from "../../../../components/regions/presets/phi-area-shell-preset-nodes";
5
- import { createPhiDefaultAreaRuntimeModuleIds } from "../../area-module-defaults";
6
5
  const SYNTHETIC_APP_REGION_IDS = {
7
6
  regionSiderLeft: -160,
8
7
  };
@@ -33,7 +32,6 @@ export async function buildPhiDefaultAppAreaPresetTree({ page, runtime, }) {
33
32
  const nodes = createPhiCmsPresetNodes(page);
34
33
  return {
35
34
  page,
36
- runtimeModuleIds: createPhiDefaultAreaRuntimeModuleIds("app"),
37
35
  overlays: [],
38
36
  ...buildPhiAreaShellSiderLeftNodes({
39
37
  nodes,