@phis/ui 0.5.7 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/controls/phi-amount-list-control.d.ts +69 -0
- package/components/controls/phi-amount-list-control.js +15 -0
- package/components/controls/phi-button-control.js +16 -2
- package/components/controls/phi-form-control.d.ts +6 -0
- package/components/controls/phi-form-control.js +23 -7
- package/components/controls/phi-media-picker-control.d.ts +3 -1
- package/components/controls/phi-media-picker-control.js +2 -2
- package/components/forms/form-descriptor-runtime-client.d.ts +3 -1
- package/components/forms/form-descriptor-runtime-client.js +2 -2
- package/components/forms/form-field-provider-modules.d.ts +23 -0
- package/components/forms/form-field-provider-modules.js +28 -0
- package/components/forms/form-provider-contract.d.ts +7 -0
- package/components/forms/form-provider-contract.js +7 -0
- package/components/forms/lazy-form-field-control.d.ts +14 -0
- package/components/forms/lazy-form-field-control.js +35 -0
- package/components/forms/phi-form-widget.d.ts +3 -2
- package/components/forms/phi-form-widget.js +21 -3
- package/components/forms/shared-form-provider-registry.js +1 -33
- package/components/media/phi-area-upload-widget.js +6 -58
- package/components/media/phi-media-picker-binding.d.ts +16 -1
- package/components/media/phi-media-picker-binding.js +3 -2
- package/components/media/phi-media-upload.d.ts +12 -0
- package/components/media/phi-media-upload.js +22 -0
- package/components/media/phi-upload-drop-area.d.ts +22 -0
- package/components/media/phi-upload-drop-area.js +49 -0
- package/components/root/phi-root-layout.d.ts +1 -0
- package/components/root/phi-root-layout.js +1 -0
- package/components/widgets/helpers/semantic-html-translation.d.ts +4 -1
- package/components/widgets/helpers/semantic-html-translation.js +4 -2
- package/components/widgets/label-sets/admin-users.d.ts +9 -1
- package/components/widgets/label-sets/admin-users.js +14 -2
- package/components/widgets/label-sets/slot-upload.js +6 -3
- package/components/widgets/label-types/slot-upload.d.ts +7 -1
- package/components/widgets/label-types/slot-upload.js +2 -1
- package/components/widgets/shared/markdown-render.js +6 -6
- package/constants/media-library-provider-keys.d.ts +9 -0
- package/constants/media-library-provider-keys.js +9 -0
- package/constants/media.d.ts +2 -0
- package/constants/media.js +2 -0
- package/constants/runtime-module-ownership.js +2 -0
- package/controls.d.ts +4 -0
- package/controls.js +2 -0
- package/gateway/signet-route.d.ts +24 -0
- package/gateway/signet-route.js +107 -0
- package/gateway/site-proxy.js +14 -7
- package/helpers/phi-metadata.d.ts +8 -6
- package/helpers/phi-metadata.js +9 -2
- package/helpers/phi-signet-head.d.ts +26 -0
- package/helpers/phi-signet-head.js +53 -0
- package/helpers/phi-signet-paths.d.ts +16 -0
- package/helpers/phi-signet-paths.js +19 -0
- package/helpers/phi-signet.d.ts +40 -0
- package/helpers/phi-signet.js +70 -0
- package/net/phi-next-proxy.d.ts +10 -8
- package/net/phi-next-proxy.js +27 -84
- package/next/proxy-runtime.js +15 -0
- package/next/root-route.js +7 -4
- package/next/site-proxy.js +21 -0
- package/package.json +3 -3
- package/plugins/runtime-modules/area-definitions.d.ts +24 -3
- package/plugins/runtime-modules/area-definitions.js +11 -3
- package/plugins/runtime-modules/asset/definition.d.ts +44 -2
- package/plugins/runtime-modules/asset/definition.js +5 -2
- package/plugins/runtime-modules/asset/form-providers.d.ts +63 -0
- package/plugins/runtime-modules/asset/form-providers.js +54 -0
- package/plugins/runtime-modules/asset/form-ui-provider.js +13 -3
- package/plugins/runtime-modules/asset/media-asset-field.d.ts +20 -0
- package/plugins/runtime-modules/asset/media-asset-field.js +33 -0
- package/plugins/runtime-modules/asset/media-asset-form-control.d.ts +21 -0
- package/plugins/runtime-modules/asset/media-asset-form-control.js +74 -0
- package/plugins/runtime-modules/core/widgets/html/server.js +1 -1
- package/plugins/runtime-modules/core/widgets/slot-upload/client.js +28 -23
- package/plugins/runtime-modules/core/widgets/slot-upload/slot.d.ts +19 -0
- package/plugins/runtime-modules/core/widgets/slot-upload/slot.js +16 -0
- package/plugins/runtime-modules/public/presets.d.ts +12 -0
- package/plugins/runtime-modules/public/presets.js +10 -0
- package/plugins/runtime-modules/public/server.js +1 -1
- package/plugins/runtime-modules/public/trees/phi-default-pub-privacy-page-tree.d.ts +4 -0
- package/plugins/runtime-modules/public/trees/phi-default-pub-privacy-page-tree.js +66 -0
- package/plugins/runtime-modules/public-base-page-references.d.ts +2 -1
- package/plugins/runtime-modules/public-base-page-references.js +2 -1
- package/plugins/runtime-modules/resolver.js +38 -4
- package/plugins/runtime-modules/theme/controller/runtime.js +7 -2
- package/plugins/runtime-modules/theme/materialize-images.d.ts +16 -0
- package/plugins/runtime-modules/theme/materialize-images.js +37 -0
- package/plugins/runtime-modules/user-management/addon-roles.d.ts +35 -0
- package/plugins/runtime-modules/user-management/addon-roles.js +76 -0
- package/plugins/runtime-modules/user-management/cards.js +1 -1
- package/plugins/runtime-modules/user-management/client-data-providers.js +6 -0
- package/plugins/runtime-modules/user-management/data-providers.d.ts +11 -2
- package/plugins/runtime-modules/user-management/data-providers.js +12 -1
- package/plugins/runtime-modules/user-management/definition.d.ts +11 -2
- package/plugins/runtime-modules/user-management/ids.d.ts +1 -0
- package/plugins/runtime-modules/user-management/ids.js +1 -0
- package/plugins/runtime-modules/user-management/services/options.d.ts +8 -0
- package/plugins/runtime-modules/user-management/services/options.js +25 -0
- package/plugins/runtime-modules/user-management/services/table.js +9 -1
- package/plugins/runtime-modules/user-management/trees/phi-default-admin-users-page-tree.js +20 -2
- package/server-helpers/cms-widget-texts.js +1 -1
- package/server-helpers/search-index.js +22 -13
- package/server-helpers/search-text.d.ts +3 -2
- package/server-helpers/search-text.js +6 -5
- package/server-helpers/translate.d.ts +13 -2
- package/server-helpers/translate.js +10 -6
- package/styles/amount-list.css +142 -0
- package/styles/controls.css +156 -7
- package/styles/gradients.css +21 -20
- package/theme/phi-theme-blocks.d.ts +7 -6
- package/theme/phi-theme-composition.d.ts +19 -1
- package/theme/phi-theme-composition.js +15 -0
- package/theme/phi-theme-signet.d.ts +31 -0
- package/theme/phi-theme-signet.js +53 -0
- package/theme/phi-tokens.d.ts +1 -1
- package/theme/phi-tokens.js +5 -1
- package/types/cms-plugins.d.ts +10 -1
- package/types/site-theme.d.ts +29 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type PhiAddonRole = {
|
|
2
|
+
name: string;
|
|
3
|
+
};
|
|
4
|
+
export type PhiAddonRoleCatalogEntry = {
|
|
5
|
+
addonId: string;
|
|
6
|
+
/** The Add-on's `title`: its id until its manifest carries a display name; shown as stated. */
|
|
7
|
+
title: string;
|
|
8
|
+
roles: readonly PhiAddonRole[];
|
|
9
|
+
};
|
|
10
|
+
export type PhiAddonRoleAssignment = {
|
|
11
|
+
addonId: string;
|
|
12
|
+
role: string;
|
|
13
|
+
};
|
|
14
|
+
/** The catalog of an `GET /api/site/addon-roles` answer; entries and roles that do not read are left out. */
|
|
15
|
+
export declare function readPhiAddonRoleCatalog(payload: unknown): PhiAddonRoleCatalogEntry[];
|
|
16
|
+
/** The stored assignments in a user row's `addonRoles` or an answer's `held`. */
|
|
17
|
+
export declare function readPhiAddonRoleAssignments(value: unknown): PhiAddonRoleAssignment[];
|
|
18
|
+
/** The tag a Site Admin's row carries in place of single roles; the Table maps it to its label. */
|
|
19
|
+
export declare const PHI_USER_MANAGEMENT_ADDON_ALL_ROLES_TAG = "all";
|
|
20
|
+
/**
|
|
21
|
+
* The tags of a row's Add-on roles column: one tag per Add-on with its stored roles, so the column stays
|
|
22
|
+
* narrow, and for a Site Admin the one tag that says every role is held. Stored assignments for a Site Admin
|
|
23
|
+
* are not listed (they apply when the person is no longer one; the dialog shows them).
|
|
24
|
+
*/
|
|
25
|
+
export declare function buildPhiAddonRoleTags(row: Record<string, unknown>): string[];
|
|
26
|
+
/** The filter's options: each Add-on (any role), then each of its roles. Values are `<addonId>` and `<addonId>:<role>`. */
|
|
27
|
+
export declare function buildPhiAddonRoleFilterOptions(catalog: readonly PhiAddonRoleCatalogEntry[]): {
|
|
28
|
+
value: string;
|
|
29
|
+
label: string;
|
|
30
|
+
}[];
|
|
31
|
+
/** The Core's `addonId` and optional `addonRole` filters from the one value the Table filter holds. */
|
|
32
|
+
export declare function parsePhiAddonRoleFilter(value: string): {
|
|
33
|
+
addonId: string;
|
|
34
|
+
addonRole: string | null;
|
|
35
|
+
} | null;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { isPhiRecord } from "../../../helpers/is-record";
|
|
2
|
+
const ROLE_NAME = /^[a-z][a-z0-9-]{0,63}$/u;
|
|
3
|
+
function readString(value) {
|
|
4
|
+
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
5
|
+
}
|
|
6
|
+
/** The catalog of an `GET /api/site/addon-roles` answer; entries and roles that do not read are left out. */
|
|
7
|
+
export function readPhiAddonRoleCatalog(payload) {
|
|
8
|
+
const addons = isPhiRecord(payload) && Array.isArray(payload.addons) ? payload.addons : [];
|
|
9
|
+
return addons.flatMap((addon) => {
|
|
10
|
+
if (!isPhiRecord(addon))
|
|
11
|
+
return [];
|
|
12
|
+
const addonId = readString(addon.addonId);
|
|
13
|
+
if (!addonId)
|
|
14
|
+
return [];
|
|
15
|
+
const roles = (Array.isArray(addon.roles) ? addon.roles : []).flatMap((role) => {
|
|
16
|
+
if (!isPhiRecord(role))
|
|
17
|
+
return [];
|
|
18
|
+
const name = readString(role.name);
|
|
19
|
+
if (!name || !ROLE_NAME.test(name))
|
|
20
|
+
return [];
|
|
21
|
+
return [{ name }];
|
|
22
|
+
});
|
|
23
|
+
return roles.length > 0 ? [{ addonId, title: readString(addon.title) ?? addonId, roles }] : [];
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** The stored assignments in a user row's `addonRoles` or an answer's `held`. */
|
|
27
|
+
export function readPhiAddonRoleAssignments(value) {
|
|
28
|
+
return (Array.isArray(value) ? value : []).flatMap((entry) => {
|
|
29
|
+
if (!isPhiRecord(entry))
|
|
30
|
+
return [];
|
|
31
|
+
const addonId = readString(entry.addonId);
|
|
32
|
+
const role = readString(entry.role);
|
|
33
|
+
return addonId && role ? [{ addonId, role }] : [];
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/** The tag a Site Admin's row carries in place of single roles; the Table maps it to its label. */
|
|
37
|
+
export const PHI_USER_MANAGEMENT_ADDON_ALL_ROLES_TAG = "all";
|
|
38
|
+
/**
|
|
39
|
+
* Whether a list row is a Site Admin, who holds every declared role of every enabled Add-on without a stored
|
|
40
|
+
* assignment: an enabled account whose `roleTags` hold `admin` (the Core states no flag of its own).
|
|
41
|
+
*/
|
|
42
|
+
function isPhiAddonRoleHolderOfAll(row) {
|
|
43
|
+
return row.enabled === true && Array.isArray(row.roleTags) && row.roleTags.includes("admin");
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The tags of a row's Add-on roles column: one tag per Add-on with its stored roles, so the column stays
|
|
47
|
+
* narrow, and for a Site Admin the one tag that says every role is held. Stored assignments for a Site Admin
|
|
48
|
+
* are not listed (they apply when the person is no longer one; the dialog shows them).
|
|
49
|
+
*/
|
|
50
|
+
export function buildPhiAddonRoleTags(row) {
|
|
51
|
+
if (isPhiAddonRoleHolderOfAll(row))
|
|
52
|
+
return [PHI_USER_MANAGEMENT_ADDON_ALL_ROLES_TAG];
|
|
53
|
+
const byAddon = new Map();
|
|
54
|
+
for (const { addonId, role } of readPhiAddonRoleAssignments(row.addonRoles)) {
|
|
55
|
+
byAddon.set(addonId, [...(byAddon.get(addonId) ?? []), role]);
|
|
56
|
+
}
|
|
57
|
+
return [...byAddon].map(([addonId, roles]) => `${addonId}: ${roles.join(", ")}`);
|
|
58
|
+
}
|
|
59
|
+
/** The filter's options: each Add-on (any role), then each of its roles. Values are `<addonId>` and `<addonId>:<role>`. */
|
|
60
|
+
export function buildPhiAddonRoleFilterOptions(catalog) {
|
|
61
|
+
return catalog.flatMap((entry) => [
|
|
62
|
+
{ value: entry.addonId, label: entry.title },
|
|
63
|
+
...entry.roles.map((role) => ({ value: `${entry.addonId}:${role.name}`, label: `${entry.title}: ${role.name}` })),
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
/** The Core's `addonId` and optional `addonRole` filters from the one value the Table filter holds. */
|
|
67
|
+
export function parsePhiAddonRoleFilter(value) {
|
|
68
|
+
const trimmed = value.trim();
|
|
69
|
+
if (!trimmed)
|
|
70
|
+
return null;
|
|
71
|
+
const cut = trimmed.lastIndexOf(":");
|
|
72
|
+
const role = cut > 0 ? trimmed.slice(cut + 1) : null;
|
|
73
|
+
if (role !== null && ROLE_NAME.test(role))
|
|
74
|
+
return { addonId: trimmed.slice(0, cut), addonRole: role };
|
|
75
|
+
return { addonId: trimmed, addonRole: null };
|
|
76
|
+
}
|
|
@@ -20,7 +20,7 @@ const PHI_USER_MANAGEMENT_DASHBOARD_CARD_LABEL_SET = definePhiRuntimeModuleLabel
|
|
|
20
20
|
accounts_eyebrow: "Accounts",
|
|
21
21
|
accounts_title: "Site users",
|
|
22
22
|
accounts_description: "User accounts on this site",
|
|
23
|
-
accounts_meta: "Admin, editor, accounting, auth, and
|
|
23
|
+
accounts_meta: "Admin, editor, accounting, auth, and external accounts",
|
|
24
24
|
},
|
|
25
25
|
});
|
|
26
26
|
const PHI_USER_MANAGEMENT_ACCOUNTS_CARD_ID = createPhiDashboardCardId(PHI_USER_MANAGEMENT_RUNTIME_MODULE_ID, "accounts");
|
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
import { PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS } from "./ids";
|
|
3
3
|
import { PHI_USER_MANAGEMENT_RUNTIME_MODULE_ID } from "./ids";
|
|
4
4
|
export const PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_CLIENT_DEFINITIONS = [
|
|
5
|
+
{
|
|
6
|
+
key: PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS.addonRoleOptions,
|
|
7
|
+
ownerModuleId: PHI_USER_MANAGEMENT_RUNTIME_MODULE_ID,
|
|
8
|
+
loadLive: async () => (await import("../../../plugins/runtime-modules/user-management/services/options"))
|
|
9
|
+
.PhiUserManagementAddonRoleOptionsProviderClient,
|
|
10
|
+
},
|
|
5
11
|
{
|
|
6
12
|
key: PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS.table,
|
|
7
13
|
ownerModuleId: PHI_USER_MANAGEMENT_RUNTIME_MODULE_ID,
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
export declare const PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_DESCRIPTORS: {
|
|
1
|
+
export declare const PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_DESCRIPTORS: ({
|
|
2
|
+
key: `${string}/${string}`;
|
|
3
|
+
ownerModuleId: "@phis/ui/modules/user-management";
|
|
4
|
+
kind: "options";
|
|
5
|
+
executionMode: "live";
|
|
6
|
+
authoringMode: "none";
|
|
7
|
+
title: string;
|
|
8
|
+
description: string;
|
|
9
|
+
resources?: undefined;
|
|
10
|
+
} | {
|
|
2
11
|
key: `${string}/${string}`;
|
|
3
12
|
ownerModuleId: "@phis/ui/modules/user-management";
|
|
4
13
|
kind: "table";
|
|
@@ -156,4 +165,4 @@ export declare const PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_DESCRIPTORS: {
|
|
|
156
165
|
summaryFields?: undefined;
|
|
157
166
|
actions?: undefined;
|
|
158
167
|
})[];
|
|
159
|
-
}[];
|
|
168
|
+
})[];
|
|
@@ -2,6 +2,15 @@ import { PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS } from "./ids";
|
|
|
2
2
|
import { PHI_USER_MANAGEMENT_RUNTIME_MODULE_ID } from "./ids";
|
|
3
3
|
import { createPhiUserManagementControllerAddress } from "../../../plugins/runtime-modules/user-management/controller/address";
|
|
4
4
|
export const PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_DESCRIPTORS = [
|
|
5
|
+
{
|
|
6
|
+
key: PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS.addonRoleOptions,
|
|
7
|
+
ownerModuleId: PHI_USER_MANAGEMENT_RUNTIME_MODULE_ID,
|
|
8
|
+
kind: "options",
|
|
9
|
+
executionMode: "live",
|
|
10
|
+
authoringMode: "none",
|
|
11
|
+
title: "Add-on roles",
|
|
12
|
+
description: "The Add-ons enabled for the Site and their declared roles, for filtering users by them.",
|
|
13
|
+
},
|
|
5
14
|
{
|
|
6
15
|
key: PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS.table,
|
|
7
16
|
ownerModuleId: PHI_USER_MANAGEMENT_RUNTIME_MODULE_ID,
|
|
@@ -35,6 +44,8 @@ export const PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_DESCRIPTORS = [
|
|
|
35
44
|
{ key: "email", title: "Email", type: "string" },
|
|
36
45
|
{ key: "accountType", title: "Account type", type: "string" },
|
|
37
46
|
{ key: "roleTags", title: "Roles", type: "json" },
|
|
47
|
+
{ key: "addonRoles", title: "Add-on role assignments", type: "json" },
|
|
48
|
+
{ key: "addonRoleTags", title: "Add-on roles", type: "json" },
|
|
38
49
|
{ key: "userFlagTags", title: "User flags", type: "json" },
|
|
39
50
|
{ key: "siteFlagTags", title: "Site flags", type: "json" },
|
|
40
51
|
{ key: "lastLoginAt", title: "Last login", type: "datetime" },
|
|
@@ -44,7 +55,7 @@ export const PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_DESCRIPTORS = [
|
|
|
44
55
|
],
|
|
45
56
|
query: {
|
|
46
57
|
search: true,
|
|
47
|
-
filterFields: ["accountType", "enabled"],
|
|
58
|
+
filterFields: ["accountType", "addonRole", "enabled"],
|
|
48
59
|
sorting: "single",
|
|
49
60
|
pagination: "offset",
|
|
50
61
|
total: true,
|
|
@@ -26,7 +26,16 @@ export declare const PHI_USER_MANAGEMENT_RUNTIME_MODULE_DEFINITION: {
|
|
|
26
26
|
credentialPolicy: "site-session";
|
|
27
27
|
}[];
|
|
28
28
|
};
|
|
29
|
-
dataProviders: {
|
|
29
|
+
dataProviders: ({
|
|
30
|
+
key: `${string}/${string}`;
|
|
31
|
+
ownerModuleId: "@phis/ui/modules/user-management";
|
|
32
|
+
kind: "options";
|
|
33
|
+
executionMode: "live";
|
|
34
|
+
authoringMode: "none";
|
|
35
|
+
title: string;
|
|
36
|
+
description: string;
|
|
37
|
+
resources?: undefined;
|
|
38
|
+
} | {
|
|
30
39
|
key: `${string}/${string}`;
|
|
31
40
|
ownerModuleId: "@phis/ui/modules/user-management";
|
|
32
41
|
kind: "table";
|
|
@@ -184,6 +193,6 @@ export declare const PHI_USER_MANAGEMENT_RUNTIME_MODULE_DEFINITION: {
|
|
|
184
193
|
summaryFields?: undefined;
|
|
185
194
|
actions?: undefined;
|
|
186
195
|
})[];
|
|
187
|
-
}[];
|
|
196
|
+
})[];
|
|
188
197
|
moduleId: "@phis/ui/modules/user-management";
|
|
189
198
|
};
|
|
@@ -12,4 +12,5 @@ export const PHI_USER_MANAGEMENT_RUNTIME_MODULE_IDENTITY = {
|
|
|
12
12
|
};
|
|
13
13
|
export const PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS = {
|
|
14
14
|
table: createPhiSharedRuntimeDataProviderKey("tables", "user-management"),
|
|
15
|
+
addonRoleOptions: createPhiSharedRuntimeDataProviderKey("options", "user-management-addon-roles"),
|
|
15
16
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Add-ons enabled for the Site and their roles, as one filter's options: an Add-on (any role) and each
|
|
3
|
+
* role of it. The Core answers every signed-in caller (`GET /api/site/addon-roles`); who may see the users
|
|
4
|
+
* list at all is settled by the users route itself.
|
|
5
|
+
*/
|
|
6
|
+
export declare const PhiUserManagementAddonRoleOptionsProviderClient: import("react").ComponentType<{
|
|
7
|
+
children: import("react").ReactNode;
|
|
8
|
+
}>;
|
|
@@ -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.
|
|
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.
|
|
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) => {
|
|
@@ -124,6 +124,7 @@ async function indexRegisteredAreas(registry) {
|
|
|
124
124
|
internalToken: bridgeRuntime.internalToken,
|
|
125
125
|
siteKey: bridgeRuntime.siteKey,
|
|
126
126
|
};
|
|
127
|
+
const failures = new Map();
|
|
127
128
|
const held = await fetchPhiSiteSearchIndexStates(credentials);
|
|
128
129
|
const heldFingerprint = (areaMask, locale) => held.find((state) => state.areaMask === areaMask && state.locale === locale)?.fingerprint ?? null;
|
|
129
130
|
for (const area of PHI_SEARCH_INDEX_AREAS) {
|
|
@@ -131,12 +132,15 @@ async function indexRegisteredAreas(registry) {
|
|
|
131
132
|
if (!bridge)
|
|
132
133
|
continue;
|
|
133
134
|
try {
|
|
134
|
-
await indexArea({ area, bridge, credentials, heldFingerprint });
|
|
135
|
+
await indexArea({ area, bridge, credentials, heldFingerprint, failures });
|
|
135
136
|
}
|
|
136
137
|
catch (error) {
|
|
137
138
|
console.error(`[phis-ui] Indexing the ${area} Area for search failed.`, error);
|
|
138
139
|
}
|
|
139
140
|
}
|
|
141
|
+
for (const [widgetType, failure] of failures) {
|
|
142
|
+
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);
|
|
143
|
+
}
|
|
140
144
|
}
|
|
141
145
|
/**
|
|
142
146
|
* The reader an Area is indexed as: the Public Area's anonymous visitor, the App's signed-in member who
|
|
@@ -156,7 +160,7 @@ function asIndexingReader(context, area) {
|
|
|
156
160
|
},
|
|
157
161
|
};
|
|
158
162
|
}
|
|
159
|
-
async function indexArea({ area, bridge, credentials, heldFingerprint, }) {
|
|
163
|
+
async function indexArea({ area, bridge, credentials, heldFingerprint, failures, }) {
|
|
160
164
|
const { apiBaseUrl, internalToken, siteKey } = credentials;
|
|
161
165
|
const catalog = resolvePhiCmsDescriptorCatalog(bridge.runtimeModuleCatalog);
|
|
162
166
|
const shellBinding = resolvePhiCmsAreaShellPresetBinding(catalog, area);
|
|
@@ -242,7 +246,7 @@ async function indexArea({ area, bridge, credentials, heldFingerprint, }) {
|
|
|
242
246
|
if (heldFingerprint(areaMask, locale) === fingerprint)
|
|
243
247
|
continue;
|
|
244
248
|
const context = asIndexingReader(await loadPhiSiteRequestContext(siteKey, locale, "", apiBaseUrl, internalToken), area);
|
|
245
|
-
const documents = await readDocuments({ bridge, area, locale, context, candidates, loadPlugin, accessRegistry });
|
|
249
|
+
const documents = await readDocuments({ bridge, area, locale, context, candidates, loadPlugin, accessRegistry, failures });
|
|
246
250
|
const answer = await putPhiSiteSearchIndexSet({
|
|
247
251
|
...credentials,
|
|
248
252
|
area,
|
|
@@ -257,7 +261,7 @@ async function indexArea({ area, bridge, credentials, heldFingerprint, }) {
|
|
|
257
261
|
console.info(`[phis-ui] Search index ${area}/${locale}: ${answer.accepted ? `${answer.state.documentCount} documents written` : "already held"}.`);
|
|
258
262
|
}
|
|
259
263
|
}
|
|
260
|
-
async function readDocuments({ bridge, area, locale, context, candidates, loadPlugin, accessRegistry, }) {
|
|
264
|
+
async function readDocuments({ bridge, area, locale, context, candidates, loadPlugin, accessRegistry, failures, }) {
|
|
261
265
|
const documents = new Array(candidates.length).fill(null);
|
|
262
266
|
let next = 0;
|
|
263
267
|
async function work() {
|
|
@@ -265,7 +269,7 @@ async function readDocuments({ bridge, area, locale, context, candidates, loadPl
|
|
|
265
269
|
const index = next++;
|
|
266
270
|
const path = candidates[index].path;
|
|
267
271
|
try {
|
|
268
|
-
documents[index] = await readDocument({ bridge, area, locale, context, path, loadPlugin, accessRegistry });
|
|
272
|
+
documents[index] = await readDocument({ bridge, area, locale, context, path, loadPlugin, accessRegistry, failures });
|
|
269
273
|
}
|
|
270
274
|
catch (error) {
|
|
271
275
|
console.error(`[phis-ui] The search index could not read ${area}:${path} (${locale}).`, error);
|
|
@@ -284,7 +288,7 @@ async function readDocuments({ bridge, area, locale, context, candidates, loadPl
|
|
|
284
288
|
* -- of the Widgets this reader would see: a Layout or Widget with a narrower policy than the Page's is
|
|
285
289
|
* left out here as the live render leaves it out, so its words never reach a reader it is hidden from.
|
|
286
290
|
*/
|
|
287
|
-
async function readDocument({ bridge, area, locale, context, path, loadPlugin, accessRegistry, }) {
|
|
291
|
+
async function readDocument({ bridge, area, locale, context, path, loadPlugin, accessRegistry, failures, }) {
|
|
288
292
|
const resolved = await resolvePhiCmsLookup({
|
|
289
293
|
bridge,
|
|
290
294
|
area,
|
|
@@ -303,11 +307,12 @@ async function readDocument({ bridge, area, locale, context, path, loadPlugin, a
|
|
|
303
307
|
if (!canPhiViewerAccess(resolved.runtime.viewer, page.accessPolicy))
|
|
304
308
|
return null;
|
|
305
309
|
/*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
* timer after a publish.
|
|
310
|
-
*
|
|
310
|
+
* `searchText` is given the runtime and names it to every helper it reaches (the translation of its
|
|
311
|
+
* texts first of all), so a Widget never depends on a request scope. The scope below is kept for the
|
|
312
|
+
* helpers that still read the request's runtime, since the indexer runs where no request is: at
|
|
313
|
+
* start-up, or on a timer after a publish. A built Site showed this scope not carrying into the
|
|
314
|
+
* Widget's code (the first production index was title and description alone), which is why the
|
|
315
|
+
* runtime is passed and not left to be found.
|
|
311
316
|
*/
|
|
312
317
|
const visible = filterPhiCmsRenderableTreeForViewer({
|
|
313
318
|
tree: resolved.page,
|
|
@@ -333,8 +338,12 @@ async function readDocument({ bridge, area, locale, context, path, loadPlugin, a
|
|
|
333
338
|
collected.push(...await plugin.searchText({ widget, config, runtime: resolved.runtime }));
|
|
334
339
|
}
|
|
335
340
|
catch (error) {
|
|
336
|
-
// One Widget that cannot say its words costs the Page those words, not the Page.
|
|
337
|
-
|
|
341
|
+
// One Widget that cannot say its words costs the Page those words, not the Page; the run names the type once.
|
|
342
|
+
const failure = failures.get(widget.widgetType);
|
|
343
|
+
if (failure)
|
|
344
|
+
failure.pages += 1;
|
|
345
|
+
else
|
|
346
|
+
failures.set(widget.widgetType, { pages: 1, first: `${area}:${path} (${locale})`, error });
|
|
338
347
|
}
|
|
339
348
|
}
|
|
340
349
|
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(
|
|
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(
|
|
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
|
|
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);
|
|
@@ -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
|
|
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
|
|
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") {
|