@bison-lab/payload-core 4.39.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -33
- package/dist/admin.d.mts +19 -7
- package/dist/admin.d.mts.map +1 -1
- package/dist/admin.mjs +229 -16
- package/dist/admin.mjs.map +1 -1
- package/dist/block-library.d.mts +1 -1
- package/dist/block-library.mjs +1 -1
- package/dist/{block-thumbnails-DXOUzGjY.mjs → block-thumbnails-DC34uFtE.mjs} +1 -1
- package/dist/{block-thumbnails-DXOUzGjY.mjs.map → block-thumbnails-DC34uFtE.mjs.map} +1 -1
- package/dist/block-thumbnails-cli.mjs +1 -1
- package/dist/block-thumbnails.mjs +1 -1
- package/dist/capability-CqdYCzG1.d.mts +434 -0
- package/dist/capability-CqdYCzG1.d.mts.map +1 -0
- package/dist/capability-DHPE2kon.mjs +2685 -0
- package/dist/capability-DHPE2kon.mjs.map +1 -0
- package/dist/{catalogue-FxH10X3v.d.mts → catalogue-DWqHWVE5.d.mts} +1 -1
- package/dist/{catalogue-FxH10X3v.d.mts.map → catalogue-DWqHWVE5.d.mts.map} +1 -1
- package/dist/{facet-field-DjaZ0C7D.d.mts → facet-field-2K22iuWA.d.mts} +1 -1
- package/dist/{facet-field-DjaZ0C7D.d.mts.map → facet-field-2K22iuWA.d.mts.map} +1 -1
- package/dist/{facet-field-Uf8S4yL1.mjs → facet-field-DO3VT_Cz.mjs} +1 -1
- package/dist/{facet-field-Uf8S4yL1.mjs.map → facet-field-DO3VT_Cz.mjs.map} +1 -1
- package/dist/index.d.mts +13 -7
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +25 -667
- package/dist/index.mjs.map +1 -1
- package/dist/{locale-CFWfB4wP.mjs → locale-B6rUVwpg.mjs} +1 -1
- package/dist/locale-B6rUVwpg.mjs.map +1 -0
- package/dist/{locale-CWiIcGuU.d.mts → locale-CTT3nn6T.d.mts} +5 -4
- package/dist/locale-CTT3nn6T.d.mts.map +1 -0
- package/dist/messages-dZV_aAnR.mjs +93 -0
- package/dist/messages-dZV_aAnR.mjs.map +1 -0
- package/dist/metadata.d.mts +1 -1
- package/dist/navigation.d.mts +2 -2
- package/dist/navigation.mjs +1 -1
- package/dist/og.d.mts +2 -2
- package/dist/og.mjs +1 -1
- package/dist/{preview-CNBVfmM7.d.mts → preview-1vwxBgm5.d.mts} +2 -2
- package/dist/{preview-CNBVfmM7.d.mts.map → preview-1vwxBgm5.d.mts.map} +1 -1
- package/dist/{published-_1rrTj_B.d.mts → published-B3etM6X5.d.mts} +3 -3
- package/dist/{published-_1rrTj_B.d.mts.map → published-B3etM6X5.d.mts.map} +1 -1
- package/dist/{published-D3yVnbxs.mjs → published-BMt7Z5CF.mjs} +2 -2
- package/dist/{published-D3yVnbxs.mjs.map → published-BMt7Z5CF.mjs.map} +1 -1
- package/dist/{published-DefZv9na.mjs → published-CkqqY08H.mjs} +2 -2
- package/dist/{published-DefZv9na.mjs.map → published-CkqqY08H.mjs.map} +1 -1
- package/dist/{published-DXjnElZn.d.mts → published-QDNmDi02.d.mts} +2 -2
- package/dist/{published-DXjnElZn.d.mts.map → published-QDNmDi02.d.mts.map} +1 -1
- package/dist/{published-QyTcDznE.mjs → published-hqtvmVUD.mjs} +1 -1
- package/dist/{published-QyTcDznE.mjs.map → published-hqtvmVUD.mjs.map} +1 -1
- package/dist/{root-page-key-B86JwL8Z.mjs → root-page-key-kx3C1eyp.mjs} +1 -1
- package/dist/{root-page-key-B86JwL8Z.mjs.map → root-page-key-kx3C1eyp.mjs.map} +1 -1
- package/dist/seo.mjs +1 -1
- package/dist/{messages-Fl1spIwN.mjs → strings-Fd7kUCT7.mjs} +156 -118
- package/dist/strings-Fd7kUCT7.mjs.map +1 -0
- package/dist/taxonomy.d.mts +1 -1
- package/dist/taxonomy.mjs +1 -1
- package/dist/theme.d.mts +4 -4
- package/dist/theme.mjs +1 -1
- package/dist/{title-D_jixG36.d.mts → title-trhUexxM.d.mts} +1 -1
- package/dist/{title-D_jixG36.d.mts.map → title-trhUexxM.d.mts.map} +1 -1
- package/dist/translate-messages-cli.mjs +3 -2
- package/dist/translate-messages-cli.mjs.map +1 -1
- package/dist/translate.d.mts +300 -206
- package/dist/translate.d.mts.map +1 -1
- package/dist/translate.mjs +225 -1027
- package/dist/translate.mjs.map +1 -1
- package/dist/{types-Db6Iy3hJ.d.mts → types-DLBlHZUd.d.mts} +1 -1
- package/dist/{types-Db6Iy3hJ.d.mts.map → types-DLBlHZUd.d.mts.map} +1 -1
- package/dist/{wireframe-xcJNJzBf.mjs → wireframe-CXorKFU_.mjs} +1 -1
- package/dist/{wireframe-xcJNJzBf.mjs.map → wireframe-CXorKFU_.mjs.map} +1 -1
- package/dist/wireframe-cli.mjs +1 -1
- package/dist/wireframe.mjs +1 -1
- package/package.json +6 -8
- package/dist/locale-CFWfB4wP.mjs.map +0 -1
- package/dist/locale-CWiIcGuU.d.mts.map +0 -1
- package/dist/messages-Fl1spIwN.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -2,11 +2,13 @@ import { n as titleTemplate, t as documentTitle } from "./title-DJ7C48gq.mjs";
|
|
|
2
2
|
import { t as SHARE_IMAGE_SIZE } from "./share-image-C8ZtIcU8.mjs";
|
|
3
3
|
import { C as THEME_PAIRING_FIELD, D as headingSelectValue, E as THEME_SECTION_HEADING, S as THEME_LIBRARY_FIELD, T as THEME_SAVE_BUTTON, _ as THEME_CONTRAST_REPORT, a as THEME_IDENTITY_SLUG, b as THEME_GREY_SCALE_FIELD, c as docFromConfig, d as validateSourceIncluded, f as validateThemeHex, g as THEME_COLOR_SCALE_FIELD, h as THEME_COLOR_FIELD, i as THEME_COLORS_SLUG, m as THEME_APPEARANCE_FIELD, n as SYSTEM_COLOR_KEYS, o as THEME_SLUG, p as LOOK_FIELD, r as THEME_APPEARANCE_SLUG, s as THEME_TYPOGRAPHY_SLUG, t as resolveThemeIdentity, u as themeConfigFromDoc, v as THEME_DOCUMENT_CONTROLS, w as THEME_PUBLISH_FIELD, x as THEME_IDENTITY_FALLBACK, y as THEME_FONT_FIELD } from "./identity-CN6EOeDM.mjs";
|
|
4
4
|
import { a as pageEditorLooks, c as themeLibraryFromDoc, d as deleteLibraryColor, f as rewriteColorToken, i as PAGE_EDITOR_SYSTEM_KEYS, l as findColorTokens, n as colorTokenField, o as pageEditorSwatches, p as themeColorKeys, r as lookField, s as pageEditorTokens, t as THEME_PREVIEW_BREAKPOINTS, u as rewriteColorTokens } from "./preview-Br1SQCKn.mjs";
|
|
5
|
-
import { _ as
|
|
6
|
-
import {
|
|
7
|
-
import { a as
|
|
8
|
-
import { t as
|
|
9
|
-
import {
|
|
5
|
+
import { $ as hasRole, $t as isFeatureSlug, At as featureCatalogue, B as allowedFeaturesForUser, Bt as THEME_FEATURE_SLUGS, Ct as resetRolesMatrix, Dt as validateRolesMatrix, Et as seedRoleRows, Ft as CAPABILITIES, G as authenticatedOrPublished, Gt as sanitizeRoleNameInput, H as getFeaturesMatrix, Ht as isRoleName, It as CAPABILITY_FEATURES, J as canPublish, Jt as FEATURE_GROUPS, K as canManageBrand, Kt as slugifyRoleName, Lt as DEFAULT_ROLE_GRANTS, Mt as parseFeaturesMatrix, Nt as stampFeatureCatalogue, Ot as MISSING_PACKAGE_FEATURES_MESSAGE, Pt as validateFeaturesMatrix, Q as hasGrant, Qt as isFeatureGroupId, Rt as ROLES, St as parseRolesMatrix, Tt as roleSelectOptions, U as hasFeature, Ut as isRoleSlug, V as canUseFeature, Vt as isRole, W as hideUnlessFeature, Wt as roleLabel, X as getRolesMatrix, Xt as PACKAGE_FEATURES, Y as developerOnlyAccess, Yt as FEATURE_GROUP_LABELS, Z as hasCapability, Zt as PACKAGE_FEATURE_SLUGS, _ as TRANSLATION_GRANT, _t as ROLES_SLUG, at as isDeveloperTab, bt as grantsFromStoredRole, ct as DEFAULT_ROLE_MATRIX, dt as DUPLICATE_ROLE_SLUG_MESSAGE, en as isLockedFeature, et as hideUnlessDeveloper, ft as INVALID_ROLE_NAME_MESSAGE, gt as ROLES_GLOBAL_DESCRIPTION, ht as ROLES_FIELD_DESCRIPTION, it as isDeveloper, jt as featureGroupLabel, kt as defaultFeaturesFieldValue, lt as DEVELOPER_DESCRIPTION, mt as MISSING_SEED_ROLES_MESSAGE, nt as isAdminOrSelf, ot as isPrivilegedRole, pt as LAST_USERS_TICK_MESSAGE, q as canManageContent, qt as FEATURES_SLUG, r as translation, rt as isAuthenticated, st as storedRoles, t as applyTranslation, tn as isPackageFeatureSlug, tt as isAdmin, ut as DUPLICATE_ROLE_NAME_MESSAGE, v as TRANSLATION_KEY_PANEL, vt as applyRoleSlugsFromNames, wt as roleDescription, xt as normalizeStoredRoles, y as TRANSLATION_SETTINGS_SLUG, yt as defaultRolesFieldValue, zt as ROLE_LABELS } from "./capability-DHPE2kon.mjs";
|
|
6
|
+
import { _ as sectionControlsOf, a as sectionControlsFromLibrary, c as BLOCK_LIBRARY_CATEGORIES, d as DEFAULT_SECTION_CONTROLS, f as HERO_SECTION_CONTROLS, g as defaultSectionControls, h as SECTION_CONTROL_LABELS, i as defaultBlockLibraryValue, l as BLOCK_LIBRARY_SLUG, m as SECTION_CONTROL_KEYS, n as getSectionControls, o as stampBlockLibrary, p as NO_SECTION_CONTROLS, r as blockLibraryCatalogue, s as validateBlockLibrary, t as blockLibraryEntriesFromConfig, u as PACKAGE_BLOCK_SLUGS } from "./published-hqtvmVUD.mjs";
|
|
7
|
+
import { C as NAVIGATION_SLUG, S as NAVIGATION_FOOTER_SLUG, _ as validateExternalHref, a as FOOTER_MAX_LINK_COLUMNS, b as NAVIGATION_FEATURE, c as footerDesktopTracks, d as validateFooterColumns, f as validateFooterSocialUrl, g as linkField, h as isValidExternalHref, i as FOOTER_MAX_COLUMNS, l as footerFields, m as headerCtaEnabled, n as FOOTER_COLUMNS_FIELD, o as FOOTER_SOCIALS, p as EXTERNAL_HREF_MESSAGE, r as FOOTER_COLUMN_WIDTHS, s as FOOTER_TWELFTHS, t as getNavigation, u as normalizeFooterDesktop, v as validateHeaderCta, x as NAVIGATION_FOOTER_DB_NAME, y as NAVIGATION_DB_NAME } from "./published-BMt7Z5CF.mjs";
|
|
8
|
+
import { a as REQUIRED_PAGE_UNPUBLISH_MESSAGE, c as isRequiredPageKey, i as REQUIRED_PAGE_FIELD, l as isRootPageKey, n as REQUIRED_PAGE_CELL, o as ROOT_PAGE_KEY, r as REQUIRED_PAGE_DELETE_MESSAGE, s as ROOT_PAGE_SLUG, t as PAGE_SLUG_CELL, u as requiredPageKeys } from "./root-page-key-kx3C1eyp.mjs";
|
|
9
|
+
import { t as facetField } from "./facet-field-DO3VT_Cz.mjs";
|
|
10
|
+
import "./strings-Fd7kUCT7.mjs";
|
|
11
|
+
import { l as thumbnailVersion } from "./block-thumbnails-DC34uFtE.mjs";
|
|
10
12
|
import { seoPlugin as seoPlugin$1 } from "@payloadcms/plugin-seo";
|
|
11
13
|
import { catalog } from "@bison-lab/fonts";
|
|
12
14
|
import { DESTRUCTIVE_SCALE_HEX, SHADE_STEPS, SUCCESS_SCALE_HEX, presetHints } from "@bison-lab/tokens";
|
|
@@ -338,658 +340,6 @@ async function readJson(req) {
|
|
|
338
340
|
return null;
|
|
339
341
|
}
|
|
340
342
|
//#endregion
|
|
341
|
-
//#region src/features/types.ts
|
|
342
|
-
const FEATURES_SLUG = "features";
|
|
343
|
-
const FEATURE_GROUPS = [
|
|
344
|
-
"pages",
|
|
345
|
-
"media",
|
|
346
|
-
"theme",
|
|
347
|
-
"users"
|
|
348
|
-
];
|
|
349
|
-
const FEATURE_GROUP_LABELS = {
|
|
350
|
-
pages: "Pages",
|
|
351
|
-
media: "Media",
|
|
352
|
-
theme: "Theme",
|
|
353
|
-
users: "Users"
|
|
354
|
-
};
|
|
355
|
-
const PACKAGE_FEATURE_SLUGS = [
|
|
356
|
-
"content",
|
|
357
|
-
"publish",
|
|
358
|
-
"media",
|
|
359
|
-
"users",
|
|
360
|
-
"roles"
|
|
361
|
-
];
|
|
362
|
-
/**
|
|
363
|
-
* Package catalogue. Features itself is not a row — that screen is
|
|
364
|
-
* Developer-only in code. Theme is not a row either: every site has the
|
|
365
|
-
* Theme Global, and who may edit it is the Roles grant `theme`. Empty
|
|
366
|
-
* Global falls back to these defaults.
|
|
367
|
-
*/
|
|
368
|
-
const PACKAGE_FEATURES = [
|
|
369
|
-
{
|
|
370
|
-
slug: "content",
|
|
371
|
-
label: "Content",
|
|
372
|
-
group: "pages",
|
|
373
|
-
defaultReleased: true
|
|
374
|
-
},
|
|
375
|
-
{
|
|
376
|
-
slug: "publish",
|
|
377
|
-
label: "Publish",
|
|
378
|
-
group: "pages",
|
|
379
|
-
defaultReleased: true
|
|
380
|
-
},
|
|
381
|
-
{
|
|
382
|
-
slug: "media",
|
|
383
|
-
label: "Media",
|
|
384
|
-
group: "media",
|
|
385
|
-
defaultReleased: true
|
|
386
|
-
},
|
|
387
|
-
{
|
|
388
|
-
slug: "users",
|
|
389
|
-
label: "Users",
|
|
390
|
-
group: "users",
|
|
391
|
-
defaultReleased: true
|
|
392
|
-
},
|
|
393
|
-
{
|
|
394
|
-
slug: "roles",
|
|
395
|
-
label: "Roles",
|
|
396
|
-
group: "users",
|
|
397
|
-
defaultReleased: true
|
|
398
|
-
}
|
|
399
|
-
];
|
|
400
|
-
function isFeatureGroupId(value) {
|
|
401
|
-
return typeof value === "string" && FEATURE_GROUPS.includes(value);
|
|
402
|
-
}
|
|
403
|
-
function isPackageFeatureSlug(value) {
|
|
404
|
-
return typeof value === "string" && PACKAGE_FEATURE_SLUGS.includes(value);
|
|
405
|
-
}
|
|
406
|
-
function isFeatureSlug(value) {
|
|
407
|
-
return typeof value === "string" && /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(value);
|
|
408
|
-
}
|
|
409
|
-
/** @deprecated Locks are gone; the release switch is the valve. */
|
|
410
|
-
function isLockedFeature(_slug, _locked) {
|
|
411
|
-
return false;
|
|
412
|
-
}
|
|
413
|
-
//#endregion
|
|
414
|
-
//#region src/roles/types.ts
|
|
415
|
-
/**
|
|
416
|
-
* The Roles Global a site's generated types will describe. Optional and
|
|
417
|
-
* nullable, no index signature: a generated Global is assignable to this,
|
|
418
|
-
* never the reverse.
|
|
419
|
-
*/
|
|
420
|
-
const ROLES = [
|
|
421
|
-
"developer",
|
|
422
|
-
"admin",
|
|
423
|
-
"designer",
|
|
424
|
-
"author"
|
|
425
|
-
];
|
|
426
|
-
const ROLE_LABELS = {
|
|
427
|
-
developer: "Developer",
|
|
428
|
-
admin: "Admin",
|
|
429
|
-
designer: "Designer",
|
|
430
|
-
author: "Author"
|
|
431
|
-
};
|
|
432
|
-
/** Capability aliases over feature grants. Brand is the Theme grant. */
|
|
433
|
-
const CAPABILITIES = [
|
|
434
|
-
"content",
|
|
435
|
-
"brand",
|
|
436
|
-
"publish",
|
|
437
|
-
"users"
|
|
438
|
-
];
|
|
439
|
-
/** One Roles grant. Opens the Theme document and brand-assets. Not a Features row. */
|
|
440
|
-
const THEME_FEATURE_SLUGS = ["theme"];
|
|
441
|
-
/**
|
|
442
|
-
* Grants stored before Theme was one row. Reading any of them is the
|
|
443
|
-
* Theme grant, so a Designer who already had Colors keeps Theme.
|
|
444
|
-
*/
|
|
445
|
-
const LEGACY_THEME_FEATURE_SLUGS = [
|
|
446
|
-
"theme-colors",
|
|
447
|
-
"theme-typography",
|
|
448
|
-
"theme-appearance",
|
|
449
|
-
"theme-identity",
|
|
450
|
-
"brand-assets"
|
|
451
|
-
];
|
|
452
|
-
const CAPABILITY_FEATURES = {
|
|
453
|
-
content: ["content"],
|
|
454
|
-
publish: ["publish"],
|
|
455
|
-
users: ["users"],
|
|
456
|
-
brand: THEME_FEATURE_SLUGS
|
|
457
|
-
};
|
|
458
|
-
const DEFAULT_ROLE_GRANTS = {
|
|
459
|
-
developer: [],
|
|
460
|
-
admin: [
|
|
461
|
-
"content",
|
|
462
|
-
"publish",
|
|
463
|
-
"media",
|
|
464
|
-
"users",
|
|
465
|
-
"roles"
|
|
466
|
-
],
|
|
467
|
-
designer: [
|
|
468
|
-
"content",
|
|
469
|
-
"media",
|
|
470
|
-
...THEME_FEATURE_SLUGS,
|
|
471
|
-
"users",
|
|
472
|
-
"roles"
|
|
473
|
-
],
|
|
474
|
-
author: ["content", "media"]
|
|
475
|
-
};
|
|
476
|
-
function isRole(value) {
|
|
477
|
-
return typeof value === "string" && ROLES.includes(value);
|
|
478
|
-
}
|
|
479
|
-
/** Lowercase slug from a letters-and-spaces name: `designer`, `the-designer`. */
|
|
480
|
-
function isRoleSlug(value) {
|
|
481
|
-
return typeof value === "string" && /^[a-z]+(-[a-z]+)*$/.test(value);
|
|
482
|
-
}
|
|
483
|
-
/** Display name: letters and single spaces only. `The Greatest Designer`. */
|
|
484
|
-
function isRoleName(value) {
|
|
485
|
-
return typeof value === "string" && /^[A-Za-z]+(?: [A-Za-z]+)*$/.test(value.trim());
|
|
486
|
-
}
|
|
487
|
-
/** Strip digits and punctuation as the name is typed. Trailing space stays. */
|
|
488
|
-
function sanitizeRoleNameInput(value) {
|
|
489
|
-
return value.replace(/[^A-Za-z ]/g, "").replace(/ {2,}/g, " ");
|
|
490
|
-
}
|
|
491
|
-
/** Name → stored key. `The Greatest Designer` → `the-greatest-designer`. */
|
|
492
|
-
function slugifyRoleName(value) {
|
|
493
|
-
if (typeof value !== "string") return "";
|
|
494
|
-
return value.trim().toLowerCase().replace(/[^a-z]+/g, "-").replace(/^-|-$/g, "");
|
|
495
|
-
}
|
|
496
|
-
function roleLabel(role, label) {
|
|
497
|
-
const trimmed = typeof label === "string" ? label.trim() : "";
|
|
498
|
-
if (trimmed) return trimmed;
|
|
499
|
-
return isRole(role) ? ROLE_LABELS[role] : role;
|
|
500
|
-
}
|
|
501
|
-
function defaultGrantsForRole(role, extraGrants) {
|
|
502
|
-
if (isRole(role)) return [...DEFAULT_ROLE_GRANTS[role]];
|
|
503
|
-
return extraGrants ? [...extraGrants] : [];
|
|
504
|
-
}
|
|
505
|
-
//#endregion
|
|
506
|
-
//#region src/features/matrix.ts
|
|
507
|
-
const MISSING_PACKAGE_FEATURES_MESSAGE = "Features must include Content, Publish, Media, Users, and Roles.";
|
|
508
|
-
function featureCatalogue(extras = []) {
|
|
509
|
-
return [...PACKAGE_FEATURES.map((feature) => ({ ...feature })), ...extras.map((extra) => ({
|
|
510
|
-
slug: extra.slug,
|
|
511
|
-
label: extra.label,
|
|
512
|
-
group: extra.group ?? "users",
|
|
513
|
-
defaultReleased: extra.defaultReleased ?? false
|
|
514
|
-
}))];
|
|
515
|
-
}
|
|
516
|
-
function defaultFeaturesFieldValue(extras = []) {
|
|
517
|
-
return featureCatalogue(extras).map((feature) => ({
|
|
518
|
-
id: feature.slug,
|
|
519
|
-
slug: feature.slug,
|
|
520
|
-
label: feature.label,
|
|
521
|
-
group: feature.group,
|
|
522
|
-
released: feature.defaultReleased
|
|
523
|
-
}));
|
|
524
|
-
}
|
|
525
|
-
function stampFeatureCatalogue(value, extras = []) {
|
|
526
|
-
const bySlug = new Map(featureCatalogue(extras).map((feature) => [feature.slug, feature]));
|
|
527
|
-
if (!Array.isArray(value)) return defaultFeaturesFieldValue(extras);
|
|
528
|
-
return value.flatMap((item) => {
|
|
529
|
-
if (!item || typeof item !== "object") return [];
|
|
530
|
-
const slug = "slug" in item && typeof item.slug === "string" ? item.slug : "";
|
|
531
|
-
const feature = bySlug.get(slug);
|
|
532
|
-
if (!feature) return [];
|
|
533
|
-
return [{
|
|
534
|
-
id: feature.slug,
|
|
535
|
-
slug: feature.slug,
|
|
536
|
-
label: feature.label,
|
|
537
|
-
group: feature.group,
|
|
538
|
-
released: Boolean("released" in item && item.released)
|
|
539
|
-
}];
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
function parseFeaturesMatrix(value) {
|
|
543
|
-
if (!Array.isArray(value) || value.length === 0) return {
|
|
544
|
-
ok: false,
|
|
545
|
-
message: MISSING_PACKAGE_FEATURES_MESSAGE
|
|
546
|
-
};
|
|
547
|
-
const rows = [];
|
|
548
|
-
const seen = /* @__PURE__ */ new Set();
|
|
549
|
-
for (const item of value) {
|
|
550
|
-
if (!item || typeof item !== "object") continue;
|
|
551
|
-
const slug = "slug" in item ? item.slug : void 0;
|
|
552
|
-
if (!isFeatureSlug(slug) || seen.has(slug)) continue;
|
|
553
|
-
seen.add(slug);
|
|
554
|
-
const pack = PACKAGE_FEATURES.find((feature) => feature.slug === slug);
|
|
555
|
-
const label = "label" in item && typeof item.label === "string" ? item.label : pack?.label ?? slug;
|
|
556
|
-
const group = "group" in item && isFeatureGroupId(item.group) ? item.group : pack?.group ?? "users";
|
|
557
|
-
rows.push({
|
|
558
|
-
id: slug,
|
|
559
|
-
slug,
|
|
560
|
-
label,
|
|
561
|
-
group,
|
|
562
|
-
released: Boolean("released" in item && item.released)
|
|
563
|
-
});
|
|
564
|
-
}
|
|
565
|
-
if (PACKAGE_FEATURES.some((feature) => !seen.has(feature.slug))) return {
|
|
566
|
-
ok: false,
|
|
567
|
-
message: MISSING_PACKAGE_FEATURES_MESSAGE
|
|
568
|
-
};
|
|
569
|
-
return {
|
|
570
|
-
ok: true,
|
|
571
|
-
rows
|
|
572
|
-
};
|
|
573
|
-
}
|
|
574
|
-
function validateFeaturesMatrix(value, extras = []) {
|
|
575
|
-
const parsed = parseFeaturesMatrix(value);
|
|
576
|
-
if (!parsed.ok) return parsed.message;
|
|
577
|
-
const allowed = new Set(featureCatalogue(extras).map((feature) => feature.slug));
|
|
578
|
-
const legacy = new Set(LEGACY_THEME_FEATURE_SLUGS);
|
|
579
|
-
if (parsed.rows.some((row) => !allowed.has(row.slug) && !legacy.has(row.slug))) return MISSING_PACKAGE_FEATURES_MESSAGE;
|
|
580
|
-
return true;
|
|
581
|
-
}
|
|
582
|
-
function featureGroupLabel(group) {
|
|
583
|
-
return isFeatureGroupId(group) ? FEATURE_GROUP_LABELS[group] : group;
|
|
584
|
-
}
|
|
585
|
-
function packageFeatureLabel(slug, extras = []) {
|
|
586
|
-
if (slug === "theme") return "Theme";
|
|
587
|
-
const pack = PACKAGE_FEATURES.find((feature) => feature.slug === slug);
|
|
588
|
-
if (pack) return pack.label;
|
|
589
|
-
return extras.find((feature) => feature.slug === slug)?.label ?? slug;
|
|
590
|
-
}
|
|
591
|
-
function isGroupOnlySlug(slug) {
|
|
592
|
-
return isFeatureGroupId(slug) && !PACKAGE_FEATURES.some((feature) => feature.slug === slug);
|
|
593
|
-
}
|
|
594
|
-
//#endregion
|
|
595
|
-
//#region src/roles/matrix.ts
|
|
596
|
-
const ROLES_SLUG = "roles";
|
|
597
|
-
const ROLES_GLOBAL_DESCRIPTION = "Who may do what. Drag to change rank.";
|
|
598
|
-
const ROLES_FIELD_DESCRIPTION = "Drag to change rank. Ticks are features released on Features, plus Theme. Developer has the whole catalogue.";
|
|
599
|
-
/**
|
|
600
|
-
* Default rank and grants. Developer is implicit (empty grants). The
|
|
601
|
-
* Theme grant defaults to Designer.
|
|
602
|
-
*/
|
|
603
|
-
const DEFAULT_ROLE_MATRIX = ROLES.map((role) => ({
|
|
604
|
-
role,
|
|
605
|
-
grants: defaultGrantsForRole(role)
|
|
606
|
-
}));
|
|
607
|
-
const DEVELOPER_DESCRIPTION = "Everything, including features not released for assignment.";
|
|
608
|
-
const LAST_USERS_TICK_MESSAGE = "Keep Users granted on at least one of Admin or Developer.";
|
|
609
|
-
const MISSING_SEED_ROLES_MESSAGE = "Roles must include Developer.";
|
|
610
|
-
const DUPLICATE_ROLE_SLUG_MESSAGE = "Each role needs a unique slug.";
|
|
611
|
-
const DUPLICATE_ROLE_NAME_MESSAGE = "Each role needs a unique name.";
|
|
612
|
-
const INVALID_ROLE_NAME_MESSAGE = "Use letters and spaces only.";
|
|
613
|
-
const LEGACY_THEME_GRANTS = new Set(LEGACY_THEME_FEATURE_SLUGS);
|
|
614
|
-
function uniqueSlugs(values) {
|
|
615
|
-
const slugs = [];
|
|
616
|
-
for (const value of values) if (typeof value === "string" && isFeatureSlug(value) && !slugs.includes(value)) slugs.push(value);
|
|
617
|
-
return slugs;
|
|
618
|
-
}
|
|
619
|
-
/** One Theme grant. A stored Colors or brand-assets tick is that grant. */
|
|
620
|
-
function collapseThemeGrant(slugs) {
|
|
621
|
-
let theme = false;
|
|
622
|
-
const next = [];
|
|
623
|
-
for (const slug of slugs) {
|
|
624
|
-
if (slug === "theme" || LEGACY_THEME_GRANTS.has(slug)) {
|
|
625
|
-
theme = true;
|
|
626
|
-
continue;
|
|
627
|
-
}
|
|
628
|
-
next.push(slug);
|
|
629
|
-
}
|
|
630
|
-
if (theme) next.push("theme");
|
|
631
|
-
return next;
|
|
632
|
-
}
|
|
633
|
-
/** Read stored grants, or rebuild them from the old capability ticks. */
|
|
634
|
-
function grantsFromStoredRole(item) {
|
|
635
|
-
if ("grants" in item && Array.isArray(item.grants)) return collapseThemeGrant(uniqueSlugs(item.grants));
|
|
636
|
-
const grants = [];
|
|
637
|
-
if ("content" in item && item.content) grants.push("content", "media");
|
|
638
|
-
if ("publish" in item && item.publish) grants.push("publish");
|
|
639
|
-
if ("users" in item && item.users) grants.push("users", "roles");
|
|
640
|
-
if ("brand" in item && item.brand) grants.push("theme");
|
|
641
|
-
return collapseThemeGrant(uniqueSlugs(grants));
|
|
642
|
-
}
|
|
643
|
-
function seedRoleRows(extras = []) {
|
|
644
|
-
return [...DEFAULT_ROLE_MATRIX.map((row) => ({
|
|
645
|
-
...row,
|
|
646
|
-
grants: [...row.grants],
|
|
647
|
-
label: isRole(row.role) ? ROLE_LABELS[row.role] : row.role
|
|
648
|
-
})), ...extras.map((extra) => ({
|
|
649
|
-
role: extra.role,
|
|
650
|
-
label: extra.label,
|
|
651
|
-
grants: extra.grants ? [...extra.grants] : []
|
|
652
|
-
}))];
|
|
653
|
-
}
|
|
654
|
-
function defaultRolesFieldValue(extras = []) {
|
|
655
|
-
return seedRoleRows(extras).map((row) => ({
|
|
656
|
-
id: row.role,
|
|
657
|
-
...row
|
|
658
|
-
}));
|
|
659
|
-
}
|
|
660
|
-
function readRoleRow(item) {
|
|
661
|
-
const role = "role" in item ? item.role : void 0;
|
|
662
|
-
if (typeof role !== "string" || role.trim() === "") return { error: DUPLICATE_ROLE_SLUG_MESSAGE };
|
|
663
|
-
if (!isRoleSlug(role)) return { error: DUPLICATE_ROLE_SLUG_MESSAGE };
|
|
664
|
-
return {
|
|
665
|
-
id: role,
|
|
666
|
-
role,
|
|
667
|
-
label: roleLabel(role, "label" in item && typeof item.label === "string" ? item.label : void 0),
|
|
668
|
-
grants: grantsFromStoredRole(item)
|
|
669
|
-
};
|
|
670
|
-
}
|
|
671
|
-
function parseRolesMatrix(value) {
|
|
672
|
-
if (!Array.isArray(value)) return {
|
|
673
|
-
ok: false,
|
|
674
|
-
message: MISSING_SEED_ROLES_MESSAGE
|
|
675
|
-
};
|
|
676
|
-
const rows = [];
|
|
677
|
-
const seen = /* @__PURE__ */ new Set();
|
|
678
|
-
for (const item of value) {
|
|
679
|
-
if (!item || typeof item !== "object") continue;
|
|
680
|
-
const role = "role" in item ? item.role : void 0;
|
|
681
|
-
if (typeof role !== "string" || role.trim() === "") continue;
|
|
682
|
-
const parsed = readRoleRow(item);
|
|
683
|
-
if ("error" in parsed) return {
|
|
684
|
-
ok: false,
|
|
685
|
-
message: parsed.error
|
|
686
|
-
};
|
|
687
|
-
if (seen.has(parsed.role)) return {
|
|
688
|
-
ok: false,
|
|
689
|
-
message: DUPLICATE_ROLE_SLUG_MESSAGE
|
|
690
|
-
};
|
|
691
|
-
seen.add(parsed.role);
|
|
692
|
-
rows.push(parsed);
|
|
693
|
-
}
|
|
694
|
-
if (!seen.has("developer")) return {
|
|
695
|
-
ok: false,
|
|
696
|
-
message: MISSING_SEED_ROLES_MESSAGE
|
|
697
|
-
};
|
|
698
|
-
return {
|
|
699
|
-
ok: true,
|
|
700
|
-
rows
|
|
701
|
-
};
|
|
702
|
-
}
|
|
703
|
-
function roleHasGrant(row, slug) {
|
|
704
|
-
if (row.role === "developer") return true;
|
|
705
|
-
return row.grants.includes(slug);
|
|
706
|
-
}
|
|
707
|
-
function roleHasCapability(row, capability) {
|
|
708
|
-
if (row.role === "developer") return true;
|
|
709
|
-
return CAPABILITY_FEATURES[capability].some((slug) => row.grants.includes(slug));
|
|
710
|
-
}
|
|
711
|
-
/**
|
|
712
|
-
* Mint a slug from the name only when the row has none yet. An existing
|
|
713
|
-
* key — seed or custom — stays put so a rename cannot orphan users.
|
|
714
|
-
*/
|
|
715
|
-
function applyRoleSlugsFromNames(value) {
|
|
716
|
-
if (!Array.isArray(value)) return value;
|
|
717
|
-
return value.map((item) => {
|
|
718
|
-
if (!item || typeof item !== "object") return item;
|
|
719
|
-
const row = item;
|
|
720
|
-
if (isRoleSlug(row.role)) return item;
|
|
721
|
-
const slug = slugifyRoleName(row.label);
|
|
722
|
-
return isRoleSlug(slug) ? {
|
|
723
|
-
...row,
|
|
724
|
-
role: slug
|
|
725
|
-
} : item;
|
|
726
|
-
});
|
|
727
|
-
}
|
|
728
|
-
function hasDuplicateRoleNames(value) {
|
|
729
|
-
if (!Array.isArray(value)) return false;
|
|
730
|
-
const seen = /* @__PURE__ */ new Set();
|
|
731
|
-
for (const item of value) {
|
|
732
|
-
if (!item || typeof item !== "object") continue;
|
|
733
|
-
const role = "role" in item && typeof item.role === "string" ? item.role : "";
|
|
734
|
-
const name = ("label" in item && typeof item.label === "string" ? item.label : "").trim() || (isRole(role) ? ROLE_LABELS[role] : "");
|
|
735
|
-
if (!name) continue;
|
|
736
|
-
const key = name.toLowerCase();
|
|
737
|
-
if (seen.has(key)) return true;
|
|
738
|
-
seen.add(key);
|
|
739
|
-
}
|
|
740
|
-
return false;
|
|
741
|
-
}
|
|
742
|
-
function hasInvalidRoleName(value) {
|
|
743
|
-
if (!Array.isArray(value)) return false;
|
|
744
|
-
for (const item of value) {
|
|
745
|
-
if (!item || typeof item !== "object") continue;
|
|
746
|
-
const label = "label" in item && typeof item.label === "string" ? item.label.trim() : "";
|
|
747
|
-
if (!label) continue;
|
|
748
|
-
if (!isRoleName(label)) return true;
|
|
749
|
-
}
|
|
750
|
-
return false;
|
|
751
|
-
}
|
|
752
|
-
function validateRolesMatrix(value) {
|
|
753
|
-
if (hasDuplicateRoleNames(value)) return DUPLICATE_ROLE_NAME_MESSAGE;
|
|
754
|
-
if (hasInvalidRoleName(value)) return INVALID_ROLE_NAME_MESSAGE;
|
|
755
|
-
const parsed = parseRolesMatrix(applyRoleSlugsFromNames(value));
|
|
756
|
-
if (!parsed.ok) return parsed.message;
|
|
757
|
-
return true;
|
|
758
|
-
}
|
|
759
|
-
/**
|
|
760
|
-
* Developer is exclusive. Admin does not swallow Designer: both store.
|
|
761
|
-
* Unknown slugs (dropped catalogue keys such as `approver`) fall away unless
|
|
762
|
-
* they appear on the matrix.
|
|
763
|
-
*/
|
|
764
|
-
function normalizeStoredRoles(value, matrix = DEFAULT_ROLE_MATRIX) {
|
|
765
|
-
if (!Array.isArray(value)) return [];
|
|
766
|
-
const allowed = new Set(matrix.map((row) => row.role));
|
|
767
|
-
const roles = [...new Set(value.filter((entry) => typeof entry === "string" && allowed.has(entry)))];
|
|
768
|
-
if (roles.includes("developer")) return ["developer"];
|
|
769
|
-
return roles;
|
|
770
|
-
}
|
|
771
|
-
function roleSelectOptions(matrix = DEFAULT_ROLE_MATRIX) {
|
|
772
|
-
return matrix.map((row) => ({
|
|
773
|
-
label: roleLabel(row.role, row.label),
|
|
774
|
-
value: row.role
|
|
775
|
-
}));
|
|
776
|
-
}
|
|
777
|
-
/** Grant copy only. Developer names the unreleased catalogue; nothing about MCP or seed. */
|
|
778
|
-
function roleDescription(role, matrix = DEFAULT_ROLE_MATRIX) {
|
|
779
|
-
if (role === "developer") return DEVELOPER_DESCRIPTION;
|
|
780
|
-
const row = matrix.find((entry) => entry.role === role);
|
|
781
|
-
if (!row) return "No capabilities";
|
|
782
|
-
return row.grants.map((slug) => packageFeatureLabel(slug)).join(", ") || "No capabilities";
|
|
783
|
-
}
|
|
784
|
-
/**
|
|
785
|
-
* Seed grants and package labels come back; extra rows stay as they are.
|
|
786
|
-
*/
|
|
787
|
-
function resetRolesMatrix(current) {
|
|
788
|
-
const extras = [];
|
|
789
|
-
if (Array.isArray(current)) for (const item of current) {
|
|
790
|
-
if (!item || typeof item !== "object") continue;
|
|
791
|
-
const parsed = readRoleRow(item);
|
|
792
|
-
if ("error" in parsed || isRole(parsed.role)) continue;
|
|
793
|
-
extras.push(parsed);
|
|
794
|
-
}
|
|
795
|
-
return [...defaultRolesFieldValue(), ...extras];
|
|
796
|
-
}
|
|
797
|
-
//#endregion
|
|
798
|
-
//#region src/roles/access.ts
|
|
799
|
-
function isAccessArgs$1(value) {
|
|
800
|
-
return typeof value === "object" && value !== null && "req" in value;
|
|
801
|
-
}
|
|
802
|
-
function storedRoles(user) {
|
|
803
|
-
return Array.isArray(user?.roles) ? user.roles : [];
|
|
804
|
-
}
|
|
805
|
-
function hasRole(user, role) {
|
|
806
|
-
return storedRoles(user).includes(role);
|
|
807
|
-
}
|
|
808
|
-
/** Not a tick. True only when `developer` is stored on the row. */
|
|
809
|
-
function isDeveloper(user) {
|
|
810
|
-
return hasRole(user, "developer");
|
|
811
|
-
}
|
|
812
|
-
function hasCapability(user, capability, matrix = DEFAULT_ROLE_MATRIX) {
|
|
813
|
-
if (isDeveloper(user)) return true;
|
|
814
|
-
return storedRoles(user).some((role) => {
|
|
815
|
-
const row = matrix.find((entry) => entry.role === role);
|
|
816
|
-
return row ? roleHasCapability(row, capability) : false;
|
|
817
|
-
});
|
|
818
|
-
}
|
|
819
|
-
function hasGrant(user, slug, matrix = DEFAULT_ROLE_MATRIX) {
|
|
820
|
-
if (isDeveloper(user)) return true;
|
|
821
|
-
return storedRoles(user).some((role) => {
|
|
822
|
-
const row = matrix.find((entry) => entry.role === role);
|
|
823
|
-
return row ? roleHasGrant(row, slug) : false;
|
|
824
|
-
});
|
|
825
|
-
}
|
|
826
|
-
/**
|
|
827
|
-
* Reads the saved Roles Global, falling back to the seed when the row is
|
|
828
|
-
* empty, missing, or unreadable. Always override-access so a Designer
|
|
829
|
-
* evaluating Theme does not have to read Settings → Roles.
|
|
830
|
-
*/
|
|
831
|
-
async function getRolesMatrix(req = {}, extras = []) {
|
|
832
|
-
const fallback = seedRoleRows(extras);
|
|
833
|
-
const findGlobal = req.payload?.findGlobal;
|
|
834
|
-
if (typeof findGlobal !== "function") return fallback;
|
|
835
|
-
try {
|
|
836
|
-
const doc = await findGlobal({
|
|
837
|
-
slug: ROLES_SLUG,
|
|
838
|
-
overrideAccess: true,
|
|
839
|
-
req
|
|
840
|
-
});
|
|
841
|
-
const parsed = parseRolesMatrix(doc && typeof doc === "object" && "roles" in doc ? doc.roles : void 0);
|
|
842
|
-
return parsed.ok ? parsed.rows : fallback;
|
|
843
|
-
} catch {
|
|
844
|
-
return fallback;
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
function capabilityPredicate(capability) {
|
|
848
|
-
function predicate(userOrArgs, matrix) {
|
|
849
|
-
if (isAccessArgs$1(userOrArgs)) {
|
|
850
|
-
const user = userOrArgs.req.user;
|
|
851
|
-
if (matrix) return hasCapability(user, capability, matrix);
|
|
852
|
-
return getRolesMatrix(userOrArgs.req).then((rows) => hasCapability(user, capability, rows));
|
|
853
|
-
}
|
|
854
|
-
return hasCapability(userOrArgs, capability, matrix ?? DEFAULT_ROLE_MATRIX);
|
|
855
|
-
}
|
|
856
|
-
return predicate;
|
|
857
|
-
}
|
|
858
|
-
const canManageContent = capabilityPredicate("content");
|
|
859
|
-
const canManageBrand = capabilityPredicate("brand");
|
|
860
|
-
const canPublish = capabilityPredicate("publish");
|
|
861
|
-
/** Users grant on any held role (Developer is implicit). */
|
|
862
|
-
const isAdmin = capabilityPredicate("users");
|
|
863
|
-
/** This role id currently has the Users grant, or is Developer. */
|
|
864
|
-
function isPrivilegedRole(role, matrix = DEFAULT_ROLE_MATRIX) {
|
|
865
|
-
if (typeof role !== "string") return false;
|
|
866
|
-
if (role === "developer") return true;
|
|
867
|
-
const row = matrix.find((entry) => entry.role === role);
|
|
868
|
-
return row ? roleHasGrant(row, "users") : false;
|
|
869
|
-
}
|
|
870
|
-
function isAuthenticated(userOrArgs) {
|
|
871
|
-
if (isAccessArgs$1(userOrArgs)) return Boolean(userOrArgs.req.user);
|
|
872
|
-
return Boolean(userOrArgs);
|
|
873
|
-
}
|
|
874
|
-
const isAdminOrSelf = async ({ req }) => {
|
|
875
|
-
if (!req.user) return false;
|
|
876
|
-
if (await isAdmin({ req })) return true;
|
|
877
|
-
return { id: { equals: req.user.id } };
|
|
878
|
-
};
|
|
879
|
-
const authenticatedOrPublished = ({ req: { user } }) => {
|
|
880
|
-
if (isAuthenticated(user)) return true;
|
|
881
|
-
return { _status: { equals: "published" } };
|
|
882
|
-
};
|
|
883
|
-
/**
|
|
884
|
-
* API tab condition. Code-locked to the `developer` slug — not a Features
|
|
885
|
-
* row and not a Role tick a client can grant.
|
|
886
|
-
*/
|
|
887
|
-
function isDeveloperTab({ req }) {
|
|
888
|
-
return isDeveloper(req.user);
|
|
889
|
-
}
|
|
890
|
-
/** Access for chrome globals (Features, Better Editor settings). */
|
|
891
|
-
function developerOnlyAccess() {
|
|
892
|
-
return {
|
|
893
|
-
read: ({ req }) => isDeveloper(req.user),
|
|
894
|
-
update: ({ req }) => isDeveloper(req.user)
|
|
895
|
-
};
|
|
896
|
-
}
|
|
897
|
-
/** `admin.hidden`: hide unless the login is Developer. */
|
|
898
|
-
function hideUnlessDeveloper({ user }) {
|
|
899
|
-
return !isDeveloper(user);
|
|
900
|
-
}
|
|
901
|
-
//#endregion
|
|
902
|
-
//#region src/features/access.ts
|
|
903
|
-
function isAccessArgs(value) {
|
|
904
|
-
return typeof value === "object" && value !== null && "req" in value;
|
|
905
|
-
}
|
|
906
|
-
function grantedOnReleased(user, slug, row, matrix) {
|
|
907
|
-
if (!row.released) return false;
|
|
908
|
-
return hasGrant(user, slug, matrix);
|
|
909
|
-
}
|
|
910
|
-
/**
|
|
911
|
-
* True when the feature is released and a held role is granted it.
|
|
912
|
-
* Developer is always allowed. An empty Global falls back to catalogue
|
|
913
|
-
* defaults. A group slug (`pages`) is true when any child is.
|
|
914
|
-
* `theme` is the Roles grant: Features cannot release or withhold it.
|
|
915
|
-
*/
|
|
916
|
-
function hasFeature(user, slug, features = null, matrix = DEFAULT_ROLE_MATRIX) {
|
|
917
|
-
if (isDeveloper(user)) return true;
|
|
918
|
-
if (!user) return false;
|
|
919
|
-
if (slug === "theme" || LEGACY_THEME_FEATURE_SLUGS.includes(slug)) return hasGrant(user, "theme", matrix);
|
|
920
|
-
const rows = features && features.length > 0 ? features : defaultFeaturesFieldValue();
|
|
921
|
-
const leaf = rows.find((entry) => entry.slug === slug);
|
|
922
|
-
if (leaf) return grantedOnReleased(user, slug, leaf, matrix);
|
|
923
|
-
if (!isGroupOnlySlug(slug)) return false;
|
|
924
|
-
return rows.some((entry) => entry.group === slug && grantedOnReleased(user, entry.slug, entry, matrix));
|
|
925
|
-
}
|
|
926
|
-
/**
|
|
927
|
-
* Reads the saved Features Global. `null` means empty or unreadable — callers
|
|
928
|
-
* fall back to catalogue defaults. Always override-access.
|
|
929
|
-
*/
|
|
930
|
-
async function getFeaturesMatrix(req = {}) {
|
|
931
|
-
const findGlobal = req.payload?.findGlobal;
|
|
932
|
-
if (typeof findGlobal !== "function") return null;
|
|
933
|
-
try {
|
|
934
|
-
const doc = await findGlobal({
|
|
935
|
-
slug: FEATURES_SLUG,
|
|
936
|
-
overrideAccess: true,
|
|
937
|
-
req
|
|
938
|
-
});
|
|
939
|
-
const parsed = parseFeaturesMatrix(doc && typeof doc === "object" && "features" in doc ? doc.features : void 0);
|
|
940
|
-
return parsed.ok ? parsed.rows : null;
|
|
941
|
-
} catch {
|
|
942
|
-
return null;
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
/**
|
|
946
|
-
* Access / nav helper for one catalogue slug. Sync against a passed grid;
|
|
947
|
-
* async when given `req` so it can read both Globals.
|
|
948
|
-
*/
|
|
949
|
-
function canUseFeature(slug) {
|
|
950
|
-
function predicate(userOrArgs, features, roles) {
|
|
951
|
-
if (isAccessArgs(userOrArgs)) {
|
|
952
|
-
const user = userOrArgs.req.user;
|
|
953
|
-
if (features !== void 0) return hasFeature(user, slug, features, roles ?? DEFAULT_ROLE_MATRIX);
|
|
954
|
-
return Promise.all([getFeaturesMatrix(userOrArgs.req), getRolesMatrix(userOrArgs.req)]).then(([grid, matrix]) => hasFeature(user, slug, grid, matrix));
|
|
955
|
-
}
|
|
956
|
-
return hasFeature(userOrArgs, slug, features ?? null, roles ?? DEFAULT_ROLE_MATRIX);
|
|
957
|
-
}
|
|
958
|
-
return predicate;
|
|
959
|
-
}
|
|
960
|
-
/**
|
|
961
|
-
* Feature slugs (and group slugs) this login may use. Written onto the
|
|
962
|
-
* user at afterRead so `admin.hidden({ user })` can follow the saved
|
|
963
|
-
* Features and Roles Globals without a `req`.
|
|
964
|
-
*/
|
|
965
|
-
async function allowedFeaturesForUser(user, req = {}) {
|
|
966
|
-
const [features, roles] = await Promise.all([getFeaturesMatrix(req), getRolesMatrix(req)]);
|
|
967
|
-
return [...(features && features.length > 0 ? features : defaultFeaturesFieldValue()).map((row) => row.slug), ...FEATURE_GROUPS].filter((slug) => hasFeature(user, slug, features, roles));
|
|
968
|
-
}
|
|
969
|
-
function userHasAllowedFeature(user, slug) {
|
|
970
|
-
if (isDeveloper(user)) return true;
|
|
971
|
-
const allowed = user?.allowedFeatures;
|
|
972
|
-
if (!Array.isArray(allowed)) return false;
|
|
973
|
-
return allowed.includes(slug);
|
|
974
|
-
}
|
|
975
|
-
/** `admin.hidden`: hide when the login cannot use the feature. */
|
|
976
|
-
function hideUnlessFeature(slug) {
|
|
977
|
-
return (args) => {
|
|
978
|
-
const user = args.user ?? null;
|
|
979
|
-
if (isDeveloper(user)) return false;
|
|
980
|
-
if (user && Array.isArray(user.allowedFeatures)) return !userHasAllowedFeature(user, slug);
|
|
981
|
-
if (args.req) {
|
|
982
|
-
const result = canUseFeature(slug)({ req: {
|
|
983
|
-
...args.req,
|
|
984
|
-
user
|
|
985
|
-
} });
|
|
986
|
-
if (result instanceof Promise) return result.then((ok) => !ok);
|
|
987
|
-
return !result;
|
|
988
|
-
}
|
|
989
|
-
return !canUseFeature(slug)(user);
|
|
990
|
-
};
|
|
991
|
-
}
|
|
992
|
-
//#endregion
|
|
993
343
|
//#region src/theme/global.ts
|
|
994
344
|
const publicThemeRead = () => true;
|
|
995
345
|
function resolveAccess$1(options) {
|
|
@@ -3643,20 +2993,28 @@ function createAdminNav() {
|
|
|
3643
2993
|
* Sets `admin.components.Nav` to the package Nav. A consuming site must
|
|
3644
2994
|
* not write its own Nav — SPI-10 is the later skin, and it reads
|
|
3645
2995
|
* `resolveAdminNav` rather than a second layout source.
|
|
2996
|
+
*
|
|
2997
|
+
* It also applies the translation capability (`applyTranslation`):
|
|
2998
|
+
* Settings → Translation, its endpoints, and the save hook on every
|
|
2999
|
+
* collection and global with localized fields. Running late (order 1000)
|
|
3000
|
+
* is what lets it see every entity the other plugins registered.
|
|
3646
3001
|
*/
|
|
3647
3002
|
const adminNav = definePlugin({
|
|
3648
3003
|
slug: "admin-nav",
|
|
3649
3004
|
order: 1e3,
|
|
3650
|
-
plugin: ({ config }) =>
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
...
|
|
3654
|
-
|
|
3655
|
-
...
|
|
3656
|
-
|
|
3005
|
+
plugin: ({ config }) => {
|
|
3006
|
+
const translated = applyTranslation(config);
|
|
3007
|
+
return {
|
|
3008
|
+
...translated,
|
|
3009
|
+
admin: {
|
|
3010
|
+
...translated.admin,
|
|
3011
|
+
components: {
|
|
3012
|
+
...translated.admin?.components,
|
|
3013
|
+
Nav: ADMIN_NAV
|
|
3014
|
+
}
|
|
3657
3015
|
}
|
|
3658
|
-
}
|
|
3659
|
-
}
|
|
3016
|
+
};
|
|
3017
|
+
}
|
|
3660
3018
|
});
|
|
3661
3019
|
//#endregion
|
|
3662
3020
|
//#region src/admin-nav/resolve.ts
|
|
@@ -4510,6 +3868,6 @@ const richTextEditorFonts = definePlugin({
|
|
|
4510
3868
|
}
|
|
4511
3869
|
});
|
|
4512
3870
|
//#endregion
|
|
4513
|
-
export { ADMIN_NAV, ADMIN_NAV_ENTITY_FIELD, ADMIN_NAV_ITEM_ROW_LABEL, ADMIN_NAV_ROW_LABEL, ADMIN_NAV_SLUG, BLOCK_DRAWER_CSS, BLOCK_DRAWER_STYLES, BLOCK_LIBRARY_CATEGORIES, BLOCK_LIBRARY_FIELD, BLOCK_LIBRARY_SLUG, BLOCK_THUMBNAIL_PATH, BRAND_ASSETS_MIME_TYPES, BRAND_ASSETS_SLUG, CAPABILITIES, CAPABILITY_FEATURES, DEFAULT_ROLE_GRANTS, DEFAULT_ROLE_MATRIX, DEFAULT_SECTION_CONTROLS, DESCRIPTION_LENGTH, DEVELOPER_DESCRIPTION, DOCUMENT_CREATE_NEW, DOCUMENT_TITLE_ACTIONS, DUPLICATE_ROLE_NAME_MESSAGE, DUPLICATE_ROLE_SLUG_MESSAGE, EXISTING_PARENT_MESSAGE, EXTERNAL_HREF_MESSAGE, FEATURES_MATRIX_FIELD, FEATURES_SLUG, FEATURE_GROUPS, FEATURE_GROUP_LABELS, FOOTER_COLUMNS_FIELD, FOOTER_COLUMN_WIDTHS, FOOTER_MAX_COLUMNS, FOOTER_MAX_LINK_COLUMNS, FOOTER_SOCIALS, FOOTER_TWELFTHS, FORM_SUBMISSIONS_SLUG, HERO_SECTION_CONTROLS, INVALID_ROLE_NAME_MESSAGE, LAST_ADMIN_DELETE_MESSAGE, LAST_ADMIN_DEMOTE_MESSAGE, LAST_USERS_TICK_MESSAGE, LAYOUT_DESCRIPTION, LAYOUT_REQUIRED_LABEL, LAYOUT_REQUIRED_MESSAGE, LIST_ALIGN, LOOK_FIELD, MEDIA_ALT_AUTOFILL, MEDIA_IN_USE_PATH, MEDIA_LIST, MISSING_PACKAGE_FEATURES_MESSAGE, MISSING_SEED_ROLES_MESSAGE, NAVIGATION_DB_NAME, NAVIGATION_FEATURE, NAVIGATION_FOOTER_DB_NAME, NAVIGATION_FOOTER_SLUG, NAVIGATION_SLUG, NEW_FOLDER_PARENT, NO_SECTION_CONTROLS, PACKAGE_BLOCK_SLUGS, PACKAGE_FEATURES, PACKAGE_FEATURE_SLUGS, PAGE_EDITOR_SYSTEM_KEYS, PAGE_SLUG_CELL, PAGE_TITLE_CELL, QUESTIONS_FEATURE, QUESTIONS_LIST, QUESTIONS_SLUG, REDIRECTS_SLUG, REQUIRED_PAGE_CELL, REQUIRED_PAGE_DELETE_MESSAGE, REQUIRED_PAGE_FIELD, REQUIRED_PAGE_UNPUBLISH_MESSAGE, RICH_TEXT_EDITOR_FONTS, RICH_TEXT_EDITOR_FONTS_CSS, ROLES, ROLES_CELL, ROLES_FIELD, ROLES_FIELD_DESCRIPTION, ROLES_GLOBAL_DESCRIPTION, ROLES_GRANTS_FIELD, ROLES_LOCKOUT_MESSAGE, ROLES_MATRIX_FIELD, ROLES_ROW_LABEL, ROLES_SLUG, ROLE_LABELS, ROLE_NAME_FIELD, ROLE_SLUG_FIELD, ROOT_PAGE_KEY, ROOT_PAGE_SLUG, SECTION_CONTROL_KEYS, SECTION_CONTROL_LABELS, SHARE_IMAGE_SIZE, SLUG_FIELD, SLUG_UNLOCK_WARNING, SYSTEM_COLOR_KEYS, THEME_APPEARANCE_FIELD, THEME_APPEARANCE_SLUG, THEME_COLORS_SLUG, THEME_COLOR_FIELD, THEME_COLOR_SCALE_FIELD, THEME_CONTRAST_REPORT, THEME_DOCUMENT_CONTROLS, THEME_FEATURE_SLUGS, THEME_FONT_FIELD, THEME_GREY_SCALE_FIELD, THEME_IDENTITY_FALLBACK, THEME_IDENTITY_SLUG, THEME_LIBRARY_FIELD, THEME_PAIRING_FIELD, THEME_PREVIEW_BREAKPOINTS, THEME_PUBLISH_FIELD, THEME_SAVE_BUTTON, THEME_SECTION_HEADING, THEME_SLUG, THEME_TYPOGRAPHY_SLUG, adminNav, adminOnlyApiTab, allowedFeaturesForUser, altFromFilename, applyRoleSlugsFromNames, authenticatedOrPublished, blockDrawer, blockLibraryCatalogue, blockLibraryEntriesFromConfig, blockThumbnailEndpoint, blockUsage, canManageBrand, canManageContent, canPublish, canUseFeature, colorTokenField, composeSlug, createAdminNav, createBlockLibrary, createBrandAssets, createFeatures, createFormSubmissions, createMedia, createNavigation, createPages, createQuestions, createRedirects, createRoles, createTaxonomy, createTheme, createUsers, defaultBlockLibraryValue, defaultFeaturesFieldValue, defaultRolesFieldValue, defaultSectionControls, deleteLibraryColor, developerOnlyAccess, documentCreateNew, documentTitle, documentTitleActions, ensureRootPage, facetField, featureCatalogue, featureGroupLabel, fillBlankAltFromFilename, findColorTokens, findColorUsages, firstImageIn, footerDesktopTracks, getFeaturesMatrix, getNavigation, getRolesMatrix, getSectionControls, groupBlocksByCategory, hasCapability, hasFeature, hasGrant, hasRole, headerCtaEnabled, hideUnlessDeveloper, hideUnlessFeature, inferredFolders, isAdmin, isAdminOrSelf, isAuthenticated, isDeveloper, isDeveloperTab, isFeatureGroupId, isFeatureSlug, isLockedFeature, isPackageFeatureSlug, isPrivilegedRole, isRole, isRoleName, isRoleSlug, isRootPageKey, isValidExternalHref, lexicalPlainText, listAlign, listAlignColumns, listAlignCss, lockSlugOnPublish, lookField, noIndexField, normalizeFooterDesktop, normalizeSlug, normalizeStoredRoles, packageThumbnailURL, pageEditorLooks, pageEditorSwatches, pageEditorTokens, parentPrefix, parseFeaturesMatrix, parseRolesMatrix, persistThemeChild, pruneUserRoles, publishThemeChild, recordPublishedSlugRedirect, redirectPath, replaceClientOriginalWithResizedFile, requireLayoutOnPublish, resetRolesMatrix, resolveAdminNav, resolveThemeIdentity, rewriteColorToken, rewriteColorTokens, rewriteColorUsages, richTextEditorFonts, roleDescription, roleLabel, roleSelectOptions, sanitizeRoleNameInput, sanitizeSvg, sectionControlsFromLibrary, sectionControlsOf, seedFeatures, seedRoleRows, seedRoles, seedTheme, seoPlugin, slugDepth, slugField, slugLeaf, slugifyRoleName, stampBlockLibrary, stampFeatureCatalogue, storedRoles, stripDrafts, syncAnswerText, themeColorKeys, themeLibraryFromDoc, titleTemplate, truncateAtWord, validateBlockLibrary, validateExternalHref, validateFeaturesMatrix, validateFooterColumns, validateFooterSocialUrl, validateHeaderCta, validateRolesMatrix, withThumbnail, writePublishedSlugRedirect };
|
|
3871
|
+
export { ADMIN_NAV, ADMIN_NAV_ENTITY_FIELD, ADMIN_NAV_ITEM_ROW_LABEL, ADMIN_NAV_ROW_LABEL, ADMIN_NAV_SLUG, BLOCK_DRAWER_CSS, BLOCK_DRAWER_STYLES, BLOCK_LIBRARY_CATEGORIES, BLOCK_LIBRARY_FIELD, BLOCK_LIBRARY_SLUG, BLOCK_THUMBNAIL_PATH, BRAND_ASSETS_MIME_TYPES, BRAND_ASSETS_SLUG, CAPABILITIES, CAPABILITY_FEATURES, DEFAULT_ROLE_GRANTS, DEFAULT_ROLE_MATRIX, DEFAULT_SECTION_CONTROLS, DESCRIPTION_LENGTH, DEVELOPER_DESCRIPTION, DOCUMENT_CREATE_NEW, DOCUMENT_TITLE_ACTIONS, DUPLICATE_ROLE_NAME_MESSAGE, DUPLICATE_ROLE_SLUG_MESSAGE, EXISTING_PARENT_MESSAGE, EXTERNAL_HREF_MESSAGE, FEATURES_MATRIX_FIELD, FEATURES_SLUG, FEATURE_GROUPS, FEATURE_GROUP_LABELS, FOOTER_COLUMNS_FIELD, FOOTER_COLUMN_WIDTHS, FOOTER_MAX_COLUMNS, FOOTER_MAX_LINK_COLUMNS, FOOTER_SOCIALS, FOOTER_TWELFTHS, FORM_SUBMISSIONS_SLUG, HERO_SECTION_CONTROLS, INVALID_ROLE_NAME_MESSAGE, LAST_ADMIN_DELETE_MESSAGE, LAST_ADMIN_DEMOTE_MESSAGE, LAST_USERS_TICK_MESSAGE, LAYOUT_DESCRIPTION, LAYOUT_REQUIRED_LABEL, LAYOUT_REQUIRED_MESSAGE, LIST_ALIGN, LOOK_FIELD, MEDIA_ALT_AUTOFILL, MEDIA_IN_USE_PATH, MEDIA_LIST, MISSING_PACKAGE_FEATURES_MESSAGE, MISSING_SEED_ROLES_MESSAGE, NAVIGATION_DB_NAME, NAVIGATION_FEATURE, NAVIGATION_FOOTER_DB_NAME, NAVIGATION_FOOTER_SLUG, NAVIGATION_SLUG, NEW_FOLDER_PARENT, NO_SECTION_CONTROLS, PACKAGE_BLOCK_SLUGS, PACKAGE_FEATURES, PACKAGE_FEATURE_SLUGS, PAGE_EDITOR_SYSTEM_KEYS, PAGE_SLUG_CELL, PAGE_TITLE_CELL, QUESTIONS_FEATURE, QUESTIONS_LIST, QUESTIONS_SLUG, REDIRECTS_SLUG, REQUIRED_PAGE_CELL, REQUIRED_PAGE_DELETE_MESSAGE, REQUIRED_PAGE_FIELD, REQUIRED_PAGE_UNPUBLISH_MESSAGE, RICH_TEXT_EDITOR_FONTS, RICH_TEXT_EDITOR_FONTS_CSS, ROLES, ROLES_CELL, ROLES_FIELD, ROLES_FIELD_DESCRIPTION, ROLES_GLOBAL_DESCRIPTION, ROLES_GRANTS_FIELD, ROLES_LOCKOUT_MESSAGE, ROLES_MATRIX_FIELD, ROLES_ROW_LABEL, ROLES_SLUG, ROLE_LABELS, ROLE_NAME_FIELD, ROLE_SLUG_FIELD, ROOT_PAGE_KEY, ROOT_PAGE_SLUG, SECTION_CONTROL_KEYS, SECTION_CONTROL_LABELS, SHARE_IMAGE_SIZE, SLUG_FIELD, SLUG_UNLOCK_WARNING, SYSTEM_COLOR_KEYS, THEME_APPEARANCE_FIELD, THEME_APPEARANCE_SLUG, THEME_COLORS_SLUG, THEME_COLOR_FIELD, THEME_COLOR_SCALE_FIELD, THEME_CONTRAST_REPORT, THEME_DOCUMENT_CONTROLS, THEME_FEATURE_SLUGS, THEME_FONT_FIELD, THEME_GREY_SCALE_FIELD, THEME_IDENTITY_FALLBACK, THEME_IDENTITY_SLUG, THEME_LIBRARY_FIELD, THEME_PAIRING_FIELD, THEME_PREVIEW_BREAKPOINTS, THEME_PUBLISH_FIELD, THEME_SAVE_BUTTON, THEME_SECTION_HEADING, THEME_SLUG, THEME_TYPOGRAPHY_SLUG, TRANSLATION_GRANT, TRANSLATION_KEY_PANEL, TRANSLATION_SETTINGS_SLUG, adminNav, adminOnlyApiTab, allowedFeaturesForUser, altFromFilename, applyRoleSlugsFromNames, authenticatedOrPublished, blockDrawer, blockLibraryCatalogue, blockLibraryEntriesFromConfig, blockThumbnailEndpoint, blockUsage, canManageBrand, canManageContent, canPublish, canUseFeature, colorTokenField, composeSlug, createAdminNav, createBlockLibrary, createBrandAssets, createFeatures, createFormSubmissions, createMedia, createNavigation, createPages, createQuestions, createRedirects, createRoles, createTaxonomy, createTheme, createUsers, defaultBlockLibraryValue, defaultFeaturesFieldValue, defaultRolesFieldValue, defaultSectionControls, deleteLibraryColor, developerOnlyAccess, documentCreateNew, documentTitle, documentTitleActions, ensureRootPage, facetField, featureCatalogue, featureGroupLabel, fillBlankAltFromFilename, findColorTokens, findColorUsages, firstImageIn, footerDesktopTracks, getFeaturesMatrix, getNavigation, getRolesMatrix, getSectionControls, groupBlocksByCategory, hasCapability, hasFeature, hasGrant, hasRole, headerCtaEnabled, hideUnlessDeveloper, hideUnlessFeature, inferredFolders, isAdmin, isAdminOrSelf, isAuthenticated, isDeveloper, isDeveloperTab, isFeatureGroupId, isFeatureSlug, isLockedFeature, isPackageFeatureSlug, isPrivilegedRole, isRole, isRoleName, isRoleSlug, isRootPageKey, isValidExternalHref, lexicalPlainText, listAlign, listAlignColumns, listAlignCss, lockSlugOnPublish, lookField, noIndexField, normalizeFooterDesktop, normalizeSlug, normalizeStoredRoles, packageThumbnailURL, pageEditorLooks, pageEditorSwatches, pageEditorTokens, parentPrefix, parseFeaturesMatrix, parseRolesMatrix, persistThemeChild, pruneUserRoles, publishThemeChild, recordPublishedSlugRedirect, redirectPath, replaceClientOriginalWithResizedFile, requireLayoutOnPublish, resetRolesMatrix, resolveAdminNav, resolveThemeIdentity, rewriteColorToken, rewriteColorTokens, rewriteColorUsages, richTextEditorFonts, roleDescription, roleLabel, roleSelectOptions, sanitizeRoleNameInput, sanitizeSvg, sectionControlsFromLibrary, sectionControlsOf, seedFeatures, seedRoleRows, seedRoles, seedTheme, seoPlugin, slugDepth, slugField, slugLeaf, slugifyRoleName, stampBlockLibrary, stampFeatureCatalogue, storedRoles, stripDrafts, syncAnswerText, themeColorKeys, themeLibraryFromDoc, titleTemplate, translation, truncateAtWord, validateBlockLibrary, validateExternalHref, validateFeaturesMatrix, validateFooterColumns, validateFooterSocialUrl, validateHeaderCta, validateRolesMatrix, withThumbnail, writePublishedSlugRedirect };
|
|
4514
3872
|
|
|
4515
3873
|
//# sourceMappingURL=index.mjs.map
|