@phis/ui 0.6.0 → 0.6.2

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 (92) hide show
  1. package/components/controls/phi-form-control.d.ts +6 -0
  2. package/components/controls/phi-form-control.js +23 -7
  3. package/components/controls/phi-media-picker-control.d.ts +3 -1
  4. package/components/controls/phi-media-picker-control.js +2 -2
  5. package/components/forms/form-descriptor-runtime-client.d.ts +3 -1
  6. package/components/forms/form-descriptor-runtime-client.js +2 -2
  7. package/components/forms/form-field-provider-modules.d.ts +23 -0
  8. package/components/forms/form-field-provider-modules.js +28 -0
  9. package/components/forms/form-provider-contract.d.ts +7 -0
  10. package/components/forms/form-provider-contract.js +7 -0
  11. package/components/forms/lazy-form-field-control.d.ts +14 -0
  12. package/components/forms/lazy-form-field-control.js +35 -0
  13. package/components/forms/phi-form-widget.d.ts +3 -2
  14. package/components/forms/phi-form-widget.js +21 -3
  15. package/components/forms/shared-form-provider-registry.js +1 -33
  16. package/components/media/phi-area-upload-widget.js +6 -58
  17. package/components/media/phi-media-picker-binding.d.ts +16 -1
  18. package/components/media/phi-media-picker-binding.js +3 -2
  19. package/components/media/phi-media-upload.d.ts +12 -0
  20. package/components/media/phi-media-upload.js +22 -0
  21. package/components/media/phi-upload-drop-area.d.ts +22 -0
  22. package/components/media/phi-upload-drop-area.js +49 -0
  23. package/components/widgets/helpers/semantic-html-translation.d.ts +4 -1
  24. package/components/widgets/helpers/semantic-html-translation.js +4 -2
  25. package/components/widgets/label-sets/admin-users.d.ts +9 -1
  26. package/components/widgets/label-sets/admin-users.js +14 -2
  27. package/components/widgets/label-sets/slot-upload.js +6 -3
  28. package/components/widgets/label-types/slot-upload.d.ts +7 -1
  29. package/components/widgets/label-types/slot-upload.js +2 -1
  30. package/components/widgets/shared/markdown-render.js +6 -6
  31. package/constants/media-library-provider-keys.d.ts +9 -0
  32. package/constants/media-library-provider-keys.js +9 -0
  33. package/constants/runtime-module-ownership.js +2 -0
  34. package/controls.d.ts +2 -0
  35. package/controls.js +1 -0
  36. package/gateway/signet-route.js +11 -6
  37. package/helpers/phi-signet-head.d.ts +4 -3
  38. package/helpers/phi-signet-head.js +17 -5
  39. package/helpers/phi-signet.d.ts +12 -0
  40. package/helpers/phi-signet.js +11 -0
  41. package/net/phi-next-proxy.d.ts +10 -8
  42. package/net/phi-next-proxy.js +27 -84
  43. package/next/proxy-runtime.js +15 -0
  44. package/next/site-proxy.js +5 -0
  45. package/package.json +1 -1
  46. package/plugins/runtime-modules/asset/definition.d.ts +44 -2
  47. package/plugins/runtime-modules/asset/definition.js +5 -2
  48. package/plugins/runtime-modules/asset/form-providers.d.ts +63 -0
  49. package/plugins/runtime-modules/asset/form-providers.js +54 -0
  50. package/plugins/runtime-modules/asset/form-ui-provider.js +13 -3
  51. package/plugins/runtime-modules/asset/media-asset-field.d.ts +20 -0
  52. package/plugins/runtime-modules/asset/media-asset-field.js +33 -0
  53. package/plugins/runtime-modules/asset/media-asset-form-control.d.ts +21 -0
  54. package/plugins/runtime-modules/asset/media-asset-form-control.js +74 -0
  55. package/plugins/runtime-modules/builder/clients/pages-workspace.js +4 -4
  56. package/plugins/runtime-modules/builder/controller/draft-command-controller.js +2 -2
  57. package/plugins/runtime-modules/builder/controller/page-controller.js +5 -5
  58. package/plugins/runtime-modules/builder/persistence.js +4 -4
  59. package/plugins/runtime-modules/builder/region-keys.d.ts +10 -0
  60. package/plugins/runtime-modules/builder/region-keys.js +10 -0
  61. package/plugins/runtime-modules/core/widgets/html/server.js +1 -1
  62. package/plugins/runtime-modules/core/widgets/slot-upload/client.js +28 -23
  63. package/plugins/runtime-modules/core/widgets/slot-upload/slot.d.ts +19 -0
  64. package/plugins/runtime-modules/core/widgets/slot-upload/slot.js +16 -0
  65. package/plugins/runtime-modules/resolver.js +38 -4
  66. package/plugins/runtime-modules/user-management/addon-roles.d.ts +35 -0
  67. package/plugins/runtime-modules/user-management/addon-roles.js +76 -0
  68. package/plugins/runtime-modules/user-management/cards.js +1 -1
  69. package/plugins/runtime-modules/user-management/client-data-providers.js +6 -0
  70. package/plugins/runtime-modules/user-management/data-providers.d.ts +11 -2
  71. package/plugins/runtime-modules/user-management/data-providers.js +12 -1
  72. package/plugins/runtime-modules/user-management/definition.d.ts +11 -2
  73. package/plugins/runtime-modules/user-management/ids.d.ts +1 -0
  74. package/plugins/runtime-modules/user-management/ids.js +1 -0
  75. package/plugins/runtime-modules/user-management/services/options.d.ts +8 -0
  76. package/plugins/runtime-modules/user-management/services/options.js +25 -0
  77. package/plugins/runtime-modules/user-management/services/table.js +9 -1
  78. package/plugins/runtime-modules/user-management/trees/phi-default-admin-users-page-tree.js +20 -2
  79. package/server-helpers/cms-widget-texts.js +1 -1
  80. package/server-helpers/search-index.js +29 -19
  81. package/server-helpers/search-text.d.ts +3 -2
  82. package/server-helpers/search-text.js +6 -5
  83. package/server-helpers/site-build-id.d.ts +25 -0
  84. package/server-helpers/site-build-id.js +27 -0
  85. package/server-helpers/translate.d.ts +13 -2
  86. package/server-helpers/translate.js +10 -6
  87. package/theme/phi-theme-signet.d.ts +6 -0
  88. package/theme/phi-theme-signet.js +37 -1
  89. package/theme/phi-tokens.d.ts +1 -1
  90. package/theme/phi-tokens.js +5 -1
  91. package/types/cms-plugins.d.ts +10 -1
  92. package/types/site-theme.d.ts +14 -2
@@ -0,0 +1,25 @@
1
+ "use client";
2
+ import { createPhiControlOptionsProviderClient } from "../../../../components/controls/phi-options-provider";
3
+ import { buildPhiAddonRoleFilterOptions, readPhiAddonRoleCatalog } from "../addon-roles";
4
+ import { PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS } from "../ids";
5
+ /**
6
+ * The Add-ons enabled for the Site and their roles, as one filter's options: an Add-on (any role) and each
7
+ * role of it. The Core answers every signed-in caller (`GET /api/site/addon-roles`); who may see the users
8
+ * list at all is settled by the users route itself.
9
+ */
10
+ export const PhiUserManagementAddonRoleOptionsProviderClient = createPhiControlOptionsProviderClient({
11
+ key: PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS.addonRoleOptions,
12
+ load: async () => {
13
+ const response = await fetch("/api/site/addon-roles", {
14
+ cache: "no-store",
15
+ credentials: "include",
16
+ headers: { accept: "application/json" },
17
+ });
18
+ const payload = await response.json().catch(() => null);
19
+ if (!response.ok)
20
+ throw new Error("Failed to load the Add-on roles.");
21
+ return payload;
22
+ },
23
+ resolveLoadKey: () => "user-management-addon-roles",
24
+ resolve: (context) => ({ options: buildPhiAddonRoleFilterOptions(readPhiAddonRoleCatalog(context.asyncData)) }),
25
+ });
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
  import { isPhiRecord } from "../../../../helpers/is-record";
3
3
  import { PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS } from "../ids";
4
+ import { buildPhiAddonRoleTags, parsePhiAddonRoleFilter } from "../addon-roles";
4
5
  import { buildPhiTablePageParams, createPhiTableProviderRequestInit, readPhiPositiveInteger, readPhiTableRows, readPhiTableStringFilter, } from "../../../../components/widgets/client/shared/phi-table-provider-request";
5
6
  import { PhiTableProviderError, } from "../../../../types/table-widget";
6
7
  import { createPhiTableProviderClient } from "../../../../components/widgets/client/shared/phi-table-provider";
@@ -12,11 +13,18 @@ async function loadUsers({ query, signal, }) {
12
13
  const params = buildPhiTablePageParams(query, 20);
13
14
  const search = query.search?.trim() ?? "";
14
15
  const accountType = readPhiTableStringFilter(query, "accountType");
16
+ const addonRole = parsePhiAddonRoleFilter(readPhiTableStringFilter(query, "addonRole"));
15
17
  const enabled = readPhiTableStringFilter(query, "enabled");
16
18
  if (search)
17
19
  params.set("search", search);
18
20
  if (accountType)
19
21
  params.set("accountType", accountType);
22
+ // The Core's two filters: an Add-on, and optionally one of its roles (`addonRole` needs `addonId`).
23
+ if (addonRole) {
24
+ params.set("addonId", addonRole.addonId);
25
+ if (addonRole.addonRole)
26
+ params.set("addonRole", addonRole.addonRole);
27
+ }
20
28
  if (enabled)
21
29
  params.set("enabled", enabled);
22
30
  const primarySort = query.sorts?.[0];
@@ -25,7 +33,7 @@ async function loadUsers({ query, signal, }) {
25
33
  params.set("sortOrder", primarySort.direction === "descending" ? "descend" : "ascend");
26
34
  }
27
35
  const result = await readPhiTableProviderResponse(await fetch(`${API_PATH}?${params.toString()}`, createPhiTableProviderRequestInit(signal)), RESPONSE_OPTIONS);
28
- const rows = readPhiTableRows(result?.rows);
36
+ const rows = readPhiTableRows(result?.rows).map((row) => ({ ...row, addonRoleTags: buildPhiAddonRoleTags(row) }));
29
37
  if (typeof result?.siteTotal !== "number" || !Number.isFinite(result.siteTotal) || result.siteTotal < 0) {
30
38
  throw new PhiTableProviderError("invalid-response", "User Management site total is invalid.");
31
39
  }
@@ -6,6 +6,7 @@ import { buildPhiBasePageContentScaffold, PHI_BASE_PAGE_LAYOUT_NODE_ID } from ".
6
6
  import { getPhiAdminUsersPageLabels } from "./admin-users-label-set";
7
7
  import { getPhiAdminUsersTableWidgetLabels } from "../../../../components/widgets/label-sets/admin-users";
8
8
  import { PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS } from "../ids";
9
+ import { PHI_USER_MANAGEMENT_ADDON_ALL_ROLES_TAG } from "../addon-roles";
9
10
  import { createPhiSignalAddress, createPhiSignalSubcontrolAddress, PHI_SIGNAL_VALUE_SCHEMAS } from "../../../../types/signals";
10
11
  import { createPhiUserManagementControllerAddress, PHI_USER_MANAGEMENT_CONTROLLER_INSTANCE_KEY, PHI_USER_MANAGEMENT_CONTROLLER_TYPE, } from "../controller/address";
11
12
  import { PHI_USER_MANAGEMENT_FORM_IDS } from "../forms";
@@ -267,7 +268,7 @@ export async function buildPhiDefaultAdminUsersPageTree({ page, runtime, }) {
267
268
  renderer: "badge",
268
269
  sizing: { mode: "content" },
269
270
  valueMap: {
270
- customer: widgetLabels.accountTypes.shop,
271
+ customer: widgetLabels.accountTypes.external,
271
272
  roles: widgetLabels.accountTypes.roles,
272
273
  auth: widgetLabels.accountTypes.auth,
273
274
  },
@@ -290,6 +291,16 @@ export async function buildPhiDefaultAdminUsersPageTree({ page, runtime, }) {
290
291
  accountant: "default",
291
292
  },
292
293
  },
294
+ {
295
+ key: "addonRoleTags",
296
+ fieldKey: "addonRoleTags",
297
+ title: widgetLabels.columns.addonRoles,
298
+ renderer: "tags",
299
+ sizing: { mode: "content" },
300
+ // A Site Admin holds every role of every Add-on, which one tag says instead of listing them.
301
+ valueMap: { [PHI_USER_MANAGEMENT_ADDON_ALL_ROLES_TAG]: widgetLabels.addonRoles.all },
302
+ tagColorMap: { [PHI_USER_MANAGEMENT_ADDON_ALL_ROLES_TAG]: "error" },
303
+ },
293
304
  { key: "userFlagTags", fieldKey: "userFlagTags", title: widgetLabels.columns.userFlags, renderer: "tags", sizing: { mode: "content" } },
294
305
  { key: "siteFlagTags", fieldKey: "siteFlagTags", title: widgetLabels.columns.siteFlags, renderer: "tags", sizing: { mode: "content" } },
295
306
  { key: "lastLoginAt", fieldKey: "lastLoginAt", title: widgetLabels.columns.lastLogin, renderer: "datetime", sizing: { mode: "content" }, sortable: true },
@@ -314,11 +325,18 @@ export async function buildPhiDefaultAdminUsersPageTree({ page, runtime, }) {
314
325
  label: widgetLabels.columns.account,
315
326
  defaultValue: "roles",
316
327
  options: [
317
- { value: "customer", label: widgetLabels.accountTypes.shop },
328
+ { value: "customer", label: widgetLabels.accountTypes.external },
318
329
  { value: "roles", label: widgetLabels.accountTypes.roles },
319
330
  { value: "auth", label: widgetLabels.accountTypes.auth },
320
331
  ],
321
332
  },
333
+ {
334
+ key: "addonRole",
335
+ type: "select",
336
+ label: widgetLabels.filters.addonRole,
337
+ description: widgetLabels.filters.addonRoleHint,
338
+ optionsProvider: { providerKey: PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS.addonRoleOptions },
339
+ },
322
340
  {
323
341
  key: "enabled",
324
342
  type: "select",
@@ -82,7 +82,7 @@ export async function translatePhiWidgetConfigTexts(subjects, runtime) {
82
82
  const ctx = CTX_BY_REGISTER[register];
83
83
  const translated = store === "global"
84
84
  ? await trGlobalBulkForLocale(locale, texts, ctx)
85
- : await trBulkForLocale(locale, texts, ctx);
85
+ : await trBulkForLocale(locale, texts, ctx, "text", undefined, runtime);
86
86
  return [key, translated];
87
87
  })));
88
88
  pending.forEach((entry, entryIndex) => {
@@ -18,6 +18,7 @@ import { resolvePhiCmsLookup } from "./cms-lookup";
18
18
  import { resolvePhiAreaRouteScope } from "./cms-request";
19
19
  import { runWithPhiRequestRuntime } from "./request-runtime";
20
20
  import { loadPhiSiteRequestContext } from "./runtime";
21
+ import { getPhiSiteBuildId } from "./site-build-id";
21
22
  import { joinPhiSearchText } from "./search-text";
22
23
  /**
23
24
  * The Site's half of its search (SEARCH.md): the documents phis indexes, built from the published Pages.
@@ -47,11 +48,6 @@ const PHI_SEARCH_RUNTIME_MODULE_ID = createPhiRuntimeModuleId(PHI_SHARED_PACKAGE
47
48
  const PHI_SEARCH_INDEX_RESOLVE_CONCURRENCY = 4;
48
49
  /** How long after the marker moved the run starts, so a burst of publishes is one run. */
49
50
  const PHI_SEARCH_INDEX_DEBOUNCE_MS = 2_000;
50
- /**
51
- * What the extraction is, named in the fingerprint: a change in how documents are built reindexes every
52
- * Site on its next start, which the published revisions alone would not do.
53
- */
54
- const PHI_SEARCH_INDEX_FORMAT = 2;
55
51
  const REGISTRY_KEY = Symbol.for("phis-ui.search-index");
56
52
  function readRegistry() {
57
53
  const holder = globalThis;
@@ -124,6 +120,7 @@ async function indexRegisteredAreas(registry) {
124
120
  internalToken: bridgeRuntime.internalToken,
125
121
  siteKey: bridgeRuntime.siteKey,
126
122
  };
123
+ const failures = new Map();
127
124
  const held = await fetchPhiSiteSearchIndexStates(credentials);
128
125
  const heldFingerprint = (areaMask, locale) => held.find((state) => state.areaMask === areaMask && state.locale === locale)?.fingerprint ?? null;
129
126
  for (const area of PHI_SEARCH_INDEX_AREAS) {
@@ -131,12 +128,15 @@ async function indexRegisteredAreas(registry) {
131
128
  if (!bridge)
132
129
  continue;
133
130
  try {
134
- await indexArea({ area, bridge, credentials, heldFingerprint });
131
+ await indexArea({ area, bridge, credentials, heldFingerprint, failures });
135
132
  }
136
133
  catch (error) {
137
134
  console.error(`[phis-ui] Indexing the ${area} Area for search failed.`, error);
138
135
  }
139
136
  }
137
+ for (const [widgetType, failure] of failures) {
138
+ console.error(`[phis-ui] The search index could not read the Widget "${widgetType}" on ${failure.pages} page(s) in this run; first on ${failure.first}.`, failure.error);
139
+ }
140
140
  }
141
141
  /**
142
142
  * The reader an Area is indexed as: the Public Area's anonymous visitor, the App's signed-in member who
@@ -156,7 +156,7 @@ function asIndexingReader(context, area) {
156
156
  },
157
157
  };
158
158
  }
159
- async function indexArea({ area, bridge, credentials, heldFingerprint, }) {
159
+ async function indexArea({ area, bridge, credentials, heldFingerprint, failures, }) {
160
160
  const { apiBaseUrl, internalToken, siteKey } = credentials;
161
161
  const catalog = resolvePhiCmsDescriptorCatalog(bridge.runtimeModuleCatalog);
162
162
  const shellBinding = resolvePhiCmsAreaShellPresetBinding(catalog, area);
@@ -201,9 +201,14 @@ async function indexArea({ area, bridge, credentials, heldFingerprint, }) {
201
201
  * translated. Publishing content moves the read marker (the Site's publish triggers), correcting a
202
202
  * translation moves a translation marker, and without them here either left the old words in the
203
203
  * index. The price is a run per published change, which is what SEARCH.md promises.
204
+ *
205
+ * The build is in here because what a document contains depends on the code that builds it (phis-ui,
206
+ * the Site package, the Modules), and no list of inputs can name that. A new build of the Site is
207
+ * therefore a reason to write again, and the build's id says exactly that. The consequence is one run
208
+ * per Area and language after every rollout, and none between.
204
209
  */
205
210
  const fingerprint = createHash("sha256").update(JSON.stringify({
206
- format: PHI_SEARCH_INDEX_FORMAT,
211
+ build: getPhiSiteBuildId(),
207
212
  area,
208
213
  publishedPages,
209
214
  areaPreset: areaPreset?.preset ?? null,
@@ -242,7 +247,7 @@ async function indexArea({ area, bridge, credentials, heldFingerprint, }) {
242
247
  if (heldFingerprint(areaMask, locale) === fingerprint)
243
248
  continue;
244
249
  const context = asIndexingReader(await loadPhiSiteRequestContext(siteKey, locale, "", apiBaseUrl, internalToken), area);
245
- const documents = await readDocuments({ bridge, area, locale, context, candidates, loadPlugin, accessRegistry });
250
+ const documents = await readDocuments({ bridge, area, locale, context, candidates, loadPlugin, accessRegistry, failures });
246
251
  const answer = await putPhiSiteSearchIndexSet({
247
252
  ...credentials,
248
253
  area,
@@ -257,7 +262,7 @@ async function indexArea({ area, bridge, credentials, heldFingerprint, }) {
257
262
  console.info(`[phis-ui] Search index ${area}/${locale}: ${answer.accepted ? `${answer.state.documentCount} documents written` : "already held"}.`);
258
263
  }
259
264
  }
260
- async function readDocuments({ bridge, area, locale, context, candidates, loadPlugin, accessRegistry, }) {
265
+ async function readDocuments({ bridge, area, locale, context, candidates, loadPlugin, accessRegistry, failures, }) {
261
266
  const documents = new Array(candidates.length).fill(null);
262
267
  let next = 0;
263
268
  async function work() {
@@ -265,7 +270,7 @@ async function readDocuments({ bridge, area, locale, context, candidates, loadPl
265
270
  const index = next++;
266
271
  const path = candidates[index].path;
267
272
  try {
268
- documents[index] = await readDocument({ bridge, area, locale, context, path, loadPlugin, accessRegistry });
273
+ documents[index] = await readDocument({ bridge, area, locale, context, path, loadPlugin, accessRegistry, failures });
269
274
  }
270
275
  catch (error) {
271
276
  console.error(`[phis-ui] The search index could not read ${area}:${path} (${locale}).`, error);
@@ -284,7 +289,7 @@ async function readDocuments({ bridge, area, locale, context, candidates, loadPl
284
289
  * -- of the Widgets this reader would see: a Layout or Widget with a narrower policy than the Page's is
285
290
  * left out here as the live render leaves it out, so its words never reach a reader it is hidden from.
286
291
  */
287
- async function readDocument({ bridge, area, locale, context, path, loadPlugin, accessRegistry, }) {
292
+ async function readDocument({ bridge, area, locale, context, path, loadPlugin, accessRegistry, failures, }) {
288
293
  const resolved = await resolvePhiCmsLookup({
289
294
  bridge,
290
295
  area,
@@ -303,11 +308,12 @@ async function readDocument({ bridge, area, locale, context, path, loadPlugin, a
303
308
  if (!canPhiViewerAccess(resolved.runtime.viewer, page.accessPolicy))
304
309
  return null;
305
310
  /*
306
- * The Widgets answer inside a request scope of their own. `searchText` is given the runtime, but the
307
- * shared server helpers a Widget reaches for -- the translation of its texts first of all -- read the
308
- * request runtime from the scope, and the indexer runs where no request is: at start-up, or on a
309
- * timer after a publish. Without this scope every Widget that translates fails and a Page is indexed
310
- * by title and description alone, which is what the first production index was.
311
+ * `searchText` is given the runtime and names it to every helper it reaches (the translation of its
312
+ * texts first of all), so a Widget never depends on a request scope. The scope below is kept for the
313
+ * helpers that still read the request's runtime, since the indexer runs where no request is: at
314
+ * start-up, or on a timer after a publish. A built Site showed this scope not carrying into the
315
+ * Widget's code (the first production index was title and description alone), which is why the
316
+ * runtime is passed and not left to be found.
311
317
  */
312
318
  const visible = filterPhiCmsRenderableTreeForViewer({
313
319
  tree: resolved.page,
@@ -333,8 +339,12 @@ async function readDocument({ bridge, area, locale, context, path, loadPlugin, a
333
339
  collected.push(...await plugin.searchText({ widget, config, runtime: resolved.runtime }));
334
340
  }
335
341
  catch (error) {
336
- // One Widget that cannot say its words costs the Page those words, not the Page.
337
- console.error(`[phis-ui] The search index could not read the Widget "${widget.widgetType}" on ${area}:${path}.`, error);
342
+ // One Widget that cannot say its words costs the Page those words, not the Page; the run names the type once.
343
+ const failure = failures.get(widget.widgetType);
344
+ if (failure)
345
+ failure.pages += 1;
346
+ else
347
+ failures.set(widget.widgetType, { pages: 1, first: `${area}:${path} (${locale})`, error });
338
348
  }
339
349
  }
340
350
  return collected;
@@ -13,9 +13,10 @@ import type { PhiBlockRuntime } from "../types";
13
13
  /**
14
14
  * The Widget's own words in the reader's language, the way the Widget's render translates them: a
15
15
  * Preset's sentence through the platform's store, an author's through the Site's. Empty entries stay
16
- * in place so the caller can line answers up with what it asked.
16
+ * in place so the caller can line answers up with what it asked. The runtime is the one `searchText`
17
+ * was given and is named to the translation: the index runs where no request scope may be read.
17
18
  */
18
- export declare function translatePhiSearchTexts(locale: string, texts: readonly (string | undefined | null)[], options: {
19
+ export declare function translatePhiSearchTexts(runtime: Pick<PhiBlockRuntime, "site" | "locale">, texts: readonly (string | undefined | null)[], options: {
19
20
  translate: boolean;
20
21
  textSource?: PhiTextSource;
21
22
  }): Promise<string[]>;
@@ -13,16 +13,17 @@ import { trBulkForLocale, trGlobalBulkForLocale } from "./translate";
13
13
  /**
14
14
  * The Widget's own words in the reader's language, the way the Widget's render translates them: a
15
15
  * Preset's sentence through the platform's store, an author's through the Site's. Empty entries stay
16
- * in place so the caller can line answers up with what it asked.
16
+ * in place so the caller can line answers up with what it asked. The runtime is the one `searchText`
17
+ * was given and is named to the translation: the index runs where no request scope may be read.
17
18
  */
18
- export async function translatePhiSearchTexts(locale, texts, options) {
19
+ export async function translatePhiSearchTexts(runtime, texts, options) {
19
20
  const source = texts.map((text) => (typeof text === "string" ? text.trim() : ""));
20
21
  if (!options.translate || !source.some(Boolean)) {
21
22
  return source;
22
23
  }
23
24
  const translated = options.textSource === PHI_TEXT_SOURCE_PRESET
24
- ? await trGlobalBulkForLocale(locale, source)
25
- : await trBulkForLocale(locale, source);
25
+ ? await trGlobalBulkForLocale(runtime.locale.current, source)
26
+ : await trBulkForLocale(runtime.locale.current, source, 0, "text", undefined, runtime);
26
27
  return translated.map((text, index) => text || source[index] || "");
27
28
  }
28
29
  /**
@@ -35,7 +36,7 @@ export async function translatePhiSearchWidgetTexts(runtime, texts, options) {
35
36
  if (present.length === 0)
36
37
  return [];
37
38
  const masked = present.map((text) => maskPhiTextPlaceholders(text, 0));
38
- const translated = await translatePhiSearchTexts(runtime.locale.current, masked.map((entry) => entry.text), options);
39
+ const translated = await translatePhiSearchTexts(runtime, masked.map((entry) => entry.text), options);
39
40
  return translated
40
41
  .map((text, index) => resolvePhiTextPlaceholders(text, masked[index].names, runtime, []))
41
42
  .filter(Boolean);
@@ -0,0 +1,25 @@
1
+ import "server-only";
2
+ /**
3
+ * The identity of the Site's build: the token Next writes to `BUILD_ID` in its output directory on every
4
+ * `next build`. It is the one thing that says "different code is running" without anyone keeping a number
5
+ * (SEARCH.md, "When the index is written").
6
+ *
7
+ * Next has no public runtime API for it, and phis-ui names no output directory anywhere else, so this
8
+ * assumes the default: `.next` under the working directory, which for a Site's service is the directory of
9
+ * its release. A Site that sets `distDir` gets the fallback below, which re-indexes on every start --
10
+ * correct, only more often than needed. It deliberately does not read the Core's `release.json`: that file
11
+ * exists only for Sites the phis CLI built.
12
+ *
13
+ * Read once per process. Without the file (`next dev`, tests) the id is made once per process, so a
14
+ * development start indexes anew and nothing fails. A read failure other than "no such file" is logged
15
+ * once and treated the same way.
16
+ */
17
+ export type PhiSiteBuildIdOptions = {
18
+ /** The Next output directory; defaults to `.next` under the working directory. */
19
+ directory?: string;
20
+ /** Reads the file's text; defaults to `node:fs`. Throws as `readFileSync` does. */
21
+ readFile?: (filePath: string) => string;
22
+ };
23
+ export declare function readPhiSiteBuildId(options?: PhiSiteBuildIdOptions): string;
24
+ /** The build id of this process, read on first use and kept (also across duplicate module instances). */
25
+ export declare function getPhiSiteBuildId(): string;
@@ -0,0 +1,27 @@
1
+ import "server-only";
2
+ import { randomUUID } from "node:crypto";
3
+ import { readFileSync } from "node:fs";
4
+ import path from "node:path";
5
+ export function readPhiSiteBuildId(options = {}) {
6
+ const directory = options.directory ?? path.join(process.cwd(), ".next");
7
+ const readFile = options.readFile ?? ((filePath) => readFileSync(filePath, "utf8"));
8
+ const filePath = path.join(directory, "BUILD_ID");
9
+ try {
10
+ const id = readFile(filePath).trim();
11
+ if (id)
12
+ return id;
13
+ }
14
+ catch (error) {
15
+ if (error?.code !== "ENOENT") {
16
+ console.error(`[phis-ui] The Site's build id could not be read from ${filePath}.`, error);
17
+ }
18
+ }
19
+ return `process-${randomUUID()}`;
20
+ }
21
+ const BUILD_ID_KEY = Symbol.for("phis-ui.site-build-id");
22
+ /** The build id of this process, read on first use and kept (also across duplicate module instances). */
23
+ export function getPhiSiteBuildId() {
24
+ const holder = globalThis;
25
+ holder[BUILD_ID_KEY] ??= readPhiSiteBuildId();
26
+ return holder[BUILD_ID_KEY];
27
+ }
@@ -2,8 +2,15 @@ import "server-only";
2
2
  import { type PhiTranslationParams } from "../helpers/translation-format";
3
3
  import { PHI_TR_CTX_WEB_UI_LABEL, type PhiTranslationFormat } from "../gateway/tr";
4
4
  import { type PhiTextSource } from "../helpers/text-source";
5
+ import type { PhiBlockRuntime } from "../types";
5
6
  export { PHI_TR_CTX_WEB_UI_LABEL };
6
7
  export type { PhiTranslationParams } from "../helpers/translation-format";
8
+ /**
9
+ * The part of a runtime a Site's translation needs: whose store answers. A caller that holds the
10
+ * runtime hands it over; one that does not is read from the request scope, which a render has and a
11
+ * background run (the search index) may not.
12
+ */
13
+ export type PhiTranslationRuntime = Pick<PhiBlockRuntime, "site">;
7
14
  export declare function tr(msg: string, params?: PhiTranslationParams, ctx?: string | number, format?: PhiTranslationFormat): Promise<string>;
8
15
  export declare function trGlobal(msg: string, params?: PhiTranslationParams, ctx?: string | number, format?: PhiTranslationFormat): Promise<string>;
9
16
  /**
@@ -16,9 +23,13 @@ export declare function trGlobal(msg: string, params?: PhiTranslationParams, ctx
16
23
  export declare function trWidgetText(locale: string | undefined, msg: string, textSource: PhiTextSource | undefined): Promise<string>;
17
24
  export declare function trForLocale(localeInput: string, msg: string, params?: PhiTranslationParams, ctx?: string | number, format?: PhiTranslationFormat,
18
25
  /** The language `msg` is written in, when it is not the Site's own -- a Module's text. */
19
- sourceLocale?: string): Promise<string>;
26
+ sourceLocale?: string,
27
+ /** The runtime the caller holds; without it the request's is read. */
28
+ runtime?: PhiTranslationRuntime): Promise<string>;
20
29
  export declare function trGlobalForLocale(localeInput: string, msg: string, params?: PhiTranslationParams, ctx?: string | number, format?: PhiTranslationFormat): Promise<string>;
21
30
  export declare function trBulk(msgs: string[], ctx?: string | number, format?: PhiTranslationFormat, sourceLocale?: string): Promise<string[]>;
22
- export declare function trBulkForLocale(localeInput: string, msgs: string[], ctx?: string | number, format?: PhiTranslationFormat, sourceLocale?: string): Promise<string[]>;
31
+ export declare function trBulkForLocale(localeInput: string, msgs: string[], ctx?: string | number, format?: PhiTranslationFormat, sourceLocale?: string,
32
+ /** The runtime the caller holds; without it the request's is read. */
33
+ runtime?: PhiTranslationRuntime): Promise<string[]>;
23
34
  export declare function trGlobalBulk(msgs: string[], ctx?: string | number, format?: PhiTranslationFormat): Promise<string[]>;
24
35
  export declare function trGlobalBulkForLocale(localeInput: string, msgs: string[], ctx?: string | number, format?: PhiTranslationFormat): Promise<string[]>;
@@ -8,8 +8,8 @@ import { resolvePhiRequestLocale } from "./request-locale";
8
8
  import { readPhiServerApiCredentials } from "../helpers/phis-server-credentials";
9
9
  import { PHI_TEXT_SOURCE_PRESET } from "../helpers/text-source";
10
10
  export { PHI_TR_CTX_WEB_UI_LABEL };
11
- function buildTranslatorOptions(locale, sourceLocale) {
12
- const requestRuntime = getPhiRequestRuntime();
11
+ function buildTranslatorOptions(locale, sourceLocale, runtime) {
12
+ const requestRuntime = runtime ?? getPhiRequestRuntime();
13
13
  const resolvedRuntime = resolvePhiRuntimeConfig({
14
14
  apiBaseUrl: readPhiServerApiCredentials().apiBaseUrl,
15
15
  internalToken: readPhiServerApiCredentials().internalToken,
@@ -69,13 +69,15 @@ function normalizeMessages(msgs) {
69
69
  }
70
70
  export async function trForLocale(localeInput, msg, params = 0, ctx = 0, format = "text",
71
71
  /** The language `msg` is written in, when it is not the Site's own -- a Module's text. */
72
- sourceLocale) {
72
+ sourceLocale,
73
+ /** The runtime the caller holds; without it the request's is read. */
74
+ runtime) {
73
75
  const normalizedMessage = msg.trim();
74
76
  if (!normalizedMessage) {
75
77
  return "";
76
78
  }
77
79
  const locale = resolvePhiTranslationLocale(localeInput);
78
- const options = buildTranslatorOptions(locale, sourceLocale);
80
+ const options = buildTranslatorOptions(locale, sourceLocale, runtime);
79
81
  const translated = await requestInternalTranslation(options, normalizedMessage, undefined, ctx ? String(ctx) : undefined, format);
80
82
  return formatPhiTranslation(translated, params);
81
83
  }
@@ -96,13 +98,15 @@ export async function trBulk(msgs, ctx = 0, format = "text", sourceLocale) {
96
98
  const locale = await resolvePhiRequestLocale();
97
99
  return trBulkForLocale(locale, msgs, ctx, format, sourceLocale);
98
100
  }
99
- export async function trBulkForLocale(localeInput, msgs, ctx = 0, format = "text", sourceLocale) {
101
+ export async function trBulkForLocale(localeInput, msgs, ctx = 0, format = "text", sourceLocale,
102
+ /** The runtime the caller holds; without it the request's is read. */
103
+ runtime) {
100
104
  const normalizedMessages = normalizeMessages(msgs);
101
105
  if (!normalizedMessages.some(Boolean)) {
102
106
  return normalizedMessages;
103
107
  }
104
108
  const locale = resolvePhiTranslationLocale(localeInput);
105
- const options = buildTranslatorOptions(locale, sourceLocale);
109
+ const options = buildTranslatorOptions(locale, sourceLocale, runtime);
106
110
  return requestInternalTranslationBulk(options, normalizedMessages, ctx ? String(ctx) : undefined, format);
107
111
  }
108
112
  export async function trGlobalBulk(msgs, ctx = 0, format = "text") {
@@ -6,6 +6,12 @@ export type PhiThemeSignetPicture = {
6
6
  } | {
7
7
  kind: "asset";
8
8
  assetId: number;
9
+ /** The Asset's revision, read from the delivered address the Core resolved (`?r=<revision>`). */
10
+ revision?: number;
11
+ /** The picture's media type and size as the Core states them, where it does. */
12
+ contentType?: string;
13
+ width?: number;
14
+ height?: number;
9
15
  };
10
16
  /**
11
17
  * The Signet a Site wears, and whose it is: `site` where the record states it (a save made it the
@@ -1,3 +1,28 @@
1
+ /** A media type the head may state: an image type as the Core writes it, nothing with parameters. */
2
+ const PHI_SIGNET_CONTENT_TYPE = /^image\/[a-z0-9][a-z0-9.+-]*$/u;
3
+ function isPositiveInteger(value) {
4
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
5
+ }
6
+ /**
7
+ * The revision in the address the Core delivers an Asset at, `/api/site/media/<id>/content?r=<revision>`.
8
+ * Only that address for this Asset counts: anything else (a path elsewhere, another id, a missing or
9
+ * non-numeric `r`) states no revision, and the Signet is named as it was before the Core wrote one.
10
+ */
11
+ function readPhiSignetAssetRevision(url, assetId) {
12
+ if (typeof url !== "string")
13
+ return null;
14
+ let parsed;
15
+ try {
16
+ parsed = new URL(url, "http://signet.invalid");
17
+ }
18
+ catch {
19
+ return null;
20
+ }
21
+ if (parsed.origin !== "http://signet.invalid" || parsed.pathname !== `/api/site/media/${assetId}/content`)
22
+ return null;
23
+ const revision = parsed.searchParams.get("r");
24
+ return revision !== null && /^\d{1,15}$/u.test(revision) ? Number(revision) : null;
25
+ }
1
26
  /**
2
27
  * The Signet the record itself states, and nothing else.
3
28
  *
@@ -8,7 +33,18 @@
8
33
  */
9
34
  export function readPhiThemeSiteSignet(authored) {
10
35
  if (authored?.sourceKind === "asset" && Number.isInteger(authored.assetId) && authored.assetId > 0) {
11
- return { kind: "asset", assetId: authored.assetId };
36
+ const revision = readPhiSignetAssetRevision(authored.url, authored.assetId);
37
+ const contentType = typeof authored.contentType === "string" && PHI_SIGNET_CONTENT_TYPE.test(authored.contentType)
38
+ ? authored.contentType
39
+ : null;
40
+ const sized = isPositiveInteger(authored.width) && isPositiveInteger(authored.height);
41
+ return {
42
+ kind: "asset",
43
+ assetId: authored.assetId,
44
+ ...(revision != null ? { revision } : {}),
45
+ ...(contentType ? { contentType } : {}),
46
+ ...(sized ? { width: authored.width, height: authored.height } : {}),
47
+ };
12
48
  }
13
49
  if (authored?.sourceKind === "url" && typeof authored.sourceUrl === "string" && authored.sourceUrl.startsWith("data:image/")) {
14
50
  return { kind: "data", source: authored.sourceUrl };
@@ -61,7 +61,7 @@ export declare const PHI_RADII: {
61
61
  readonly xxl: 89;
62
62
  };
63
63
  export declare const PHI_CONTROL_HEIGHTS: {
64
- readonly sm: 26;
64
+ readonly sm: 21;
65
65
  readonly md: 34;
66
66
  readonly lg: 55;
67
67
  };
@@ -60,8 +60,12 @@ export const PHI_RADII = {
60
60
  xl: 55,
61
61
  xxl: 89,
62
62
  };
63
+ /*
64
+ * The Fibonacci row 21, 34, 55. A single-line field is as high as the Button of its size, so the small 21
65
+ * is the height that carries the small text (13).
66
+ */
63
67
  export const PHI_CONTROL_HEIGHTS = {
64
- sm: 26,
68
+ sm: 21,
65
69
  md: 34,
66
70
  lg: 55,
67
71
  };
@@ -549,7 +549,8 @@ export type PhiCmsWidgetPlugin<TConfig> = {
549
549
  * answers the text as the reader sees it -- translated for `runtime.locale`, with the Page's values
550
550
  * filled in -- and nothing a reader does not see. A Widget without it contributes no text, which is
551
551
  * right for a picture, a form or a navigation; a Widget that draws words a visitor would search for
552
- * says them here, in reading order, one entry per line or paragraph.
552
+ * says them here, in reading order, one entry per line or paragraph. It runs outside a request, so it
553
+ * uses the `runtime` it is given and passes it to what it calls, never the request's scope.
553
554
  */
554
555
  searchText?: PhiBivariantCallback<[
555
556
  PhiCmsWidgetSearchTextArgs<TConfig>
@@ -613,6 +614,13 @@ export type PhiCmsRuntimeRenderRegistry = {
613
614
  ownerModuleIdByLayoutType: ReadonlyMap<string, PhiRuntimeModuleId>;
614
615
  /** The used Modules whose catalog entry says they bring a UI provider through their Client half. */
615
616
  uiProviderModuleIds: ReadonlySet<PhiRuntimeModuleId>;
617
+ /** The Modules active in this Area. */
618
+ activeModuleIds: ReadonlySet<PhiRuntimeModuleId>;
619
+ /**
620
+ * Which installed Module owns each Form field type, active here or not. A Form widget mounts the field
621
+ * Providers of the active owners its Form uses, and marks the fields of the others as unavailable.
622
+ */
623
+ ownerModuleIdByFormFieldTypeKey: ReadonlyMap<PhiFormProviderKey, PhiRuntimeModuleId>;
616
624
  /**
617
625
  * How to ask each active Module for the facts it publishes, by the namespace it publishes them under.
618
626
  *
@@ -1129,6 +1137,7 @@ export type PhiResolvedRuntimeModuleSet = {
1129
1137
  platformModuleId: PhiRuntimeModuleId;
1130
1138
  installedOwnerModuleIdByWidgetType: ReadonlyMap<string, PhiRuntimeModuleId>;
1131
1139
  installedOwnerModuleIdByLayoutType: ReadonlyMap<string, PhiRuntimeModuleId>;
1140
+ installedOwnerModuleIdByFormFieldTypeKey: ReadonlyMap<PhiFormProviderKey, PhiRuntimeModuleId>;
1132
1141
  ownerModuleIdByControllerType: ReadonlyMap<string, PhiRuntimeModuleId>;
1133
1142
  areaControllerSettings: readonly PhiRuntimeControllerSetting[];
1134
1143
  };
@@ -113,8 +113,20 @@ export type PhiSiteThemeBrandLogo = {
113
113
  * Set that has none. `url` is the state before a save takes the picture into the Media library (a data
114
114
  * URL, a Set's own Signet); an `asset` is the state after.
115
115
  */
116
- export type PhiSiteThemeBrandSignet = Exclude<PhiSiteThemeBrandLogo, {
117
- sourceKind: "none";
116
+ export type PhiSiteThemeBrandSignet = (Extract<PhiSiteThemeBrandLogo, {
117
+ sourceKind: "asset";
118
+ }> & {
119
+ /**
120
+ * What the Core states about the Asset when it resolves the Site config (Core 0.4.1): `url` carries the
121
+ * delivered address with the Asset's revision (`?r=<revision>`), and the type and size of the picture
122
+ * are stated beside it. All absent from a record an older Core resolved, or one a draft carries; the
123
+ * head and the route then fall back to what the id alone says.
124
+ */
125
+ contentType?: string | null;
126
+ width?: number | null;
127
+ height?: number | null;
128
+ }) | Extract<PhiSiteThemeBrandLogo, {
129
+ sourceKind: "url";
118
130
  }>;
119
131
  export type PhiSiteThemeBrandLogos = {
120
132
  light?: PhiSiteThemeBrandLogo | null;