@bison-lab/payload-core 5.9.3 → 5.12.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.
@@ -60,6 +60,8 @@ const PACKAGE_FEATURES = [
60
60
  defaultReleased: true
61
61
  }
62
62
  ];
63
+ /** Settings → Features copy beside a release-only row's switch. */
64
+ const RELEASE_ONLY_NOTE = "Releasing turns this on for everyone.";
63
65
  function isFeatureGroupId(value) {
64
66
  return typeof value === "string" && FEATURE_GROUPS.includes(value);
65
67
  }
@@ -177,23 +179,54 @@ function defaultGrantsForRole(role, extraGrants) {
177
179
  //#endregion
178
180
  //#region src/features/matrix.ts
179
181
  const MISSING_PACKAGE_FEATURES_MESSAGE = "Features must include Content, Publish, Media, Users, and Roles.";
182
+ /** `{ releaseOnly: true }` for a release-only row, nothing otherwise, so other rows keep their shape. */
183
+ function releaseOnlyMark(releaseOnly) {
184
+ return releaseOnly === true ? { releaseOnly: true } : {};
185
+ }
180
186
  function featureCatalogue(extras = []) {
181
187
  return [...PACKAGE_FEATURES.map((feature) => ({ ...feature })), ...extras.map((extra) => ({
182
188
  slug: extra.slug,
183
189
  label: extra.label,
184
190
  group: extra.group ?? "users",
185
- defaultReleased: extra.defaultReleased ?? false
191
+ defaultReleased: extra.defaultReleased ?? false,
192
+ ...releaseOnlyMark(extra.releaseOnly)
186
193
  }))];
187
194
  }
195
+ /** Slugs of the release-only rows among a site's extras. */
196
+ function releaseOnlyFeatureSlugs(extras = []) {
197
+ return featureCatalogue(extras).filter((feature) => feature.releaseOnly).map((feature) => feature.slug);
198
+ }
188
199
  function defaultFeaturesFieldValue(extras = []) {
189
200
  return featureCatalogue(extras).map((feature) => ({
190
201
  id: feature.slug,
191
202
  slug: feature.slug,
192
203
  label: feature.label,
193
204
  group: feature.group,
194
- released: feature.defaultReleased
205
+ released: feature.defaultReleased,
206
+ ...releaseOnlyMark(feature.releaseOnly)
195
207
  }));
196
208
  }
209
+ /**
210
+ * Stamps the release-only mark onto saved rows from the code catalogue
211
+ * (and clears one the catalogue no longer has). Keeps every row, its
212
+ * order and its other values; a value that is not an array comes back
213
+ * as it was.
214
+ */
215
+ function markReleaseOnlyRows(value, releaseOnly) {
216
+ if (!Array.isArray(value)) return value;
217
+ const marked = new Set(releaseOnly);
218
+ return value.map((item) => {
219
+ if (!item || typeof item !== "object") return item;
220
+ const slug = "slug" in item && typeof item.slug === "string" ? item.slug : "";
221
+ if (marked.has(slug)) return {
222
+ ...item,
223
+ releaseOnly: true
224
+ };
225
+ if (!("releaseOnly" in item)) return item;
226
+ const { releaseOnly: _stale, ...rest } = item;
227
+ return rest;
228
+ });
229
+ }
197
230
  function stampFeatureCatalogue(value, extras = []) {
198
231
  const bySlug = new Map(featureCatalogue(extras).map((feature) => [feature.slug, feature]));
199
232
  if (!Array.isArray(value)) return defaultFeaturesFieldValue(extras);
@@ -207,7 +240,8 @@ function stampFeatureCatalogue(value, extras = []) {
207
240
  slug: feature.slug,
208
241
  label: feature.label,
209
242
  group: feature.group,
210
- released: Boolean("released" in item && item.released)
243
+ released: Boolean("released" in item && item.released),
244
+ ...releaseOnlyMark(feature.releaseOnly)
211
245
  }];
212
246
  });
213
247
  }
@@ -231,7 +265,8 @@ function parseFeaturesMatrix(value) {
231
265
  slug,
232
266
  label,
233
267
  group,
234
- released: Boolean("released" in item && item.released)
268
+ released: Boolean("released" in item && item.released),
269
+ ...releaseOnlyMark("releaseOnly" in item && item.releaseOnly === true)
235
270
  });
236
271
  }
237
272
  if (PACKAGE_FEATURES.some((feature) => !seen.has(feature.slug))) return {
@@ -578,13 +613,16 @@ function isAccessArgs(value) {
578
613
  }
579
614
  function grantedOnReleased(user, slug, row, matrix) {
580
615
  if (!row.released) return false;
616
+ if (row.releaseOnly) return true;
581
617
  return hasGrant(user, slug, matrix);
582
618
  }
583
619
  /**
584
620
  * True when the feature is released and a held role is granted it.
585
621
  * Developer is always allowed. An empty Global falls back to catalogue
586
- * defaults. A group slug (`pages`) is true when any child is.
587
- * `theme` is the Roles grant: Features cannot release or withhold it.
622
+ * defaults. A group slug (`pages`) is true when any child is, not
623
+ * counting release-only rows. A released release-only row is true for
624
+ * every login; off, only for a Developer. `theme` is the Roles grant:
625
+ * Features cannot release or withhold it.
588
626
  */
589
627
  function hasFeature(user, slug, features = null, matrix = DEFAULT_ROLE_MATRIX) {
590
628
  if (isDeveloper(user)) return true;
@@ -595,7 +633,40 @@ function hasFeature(user, slug, features = null, matrix = DEFAULT_ROLE_MATRIX) {
595
633
  const leaf = rows.find((entry) => entry.slug === slug);
596
634
  if (leaf) return grantedOnReleased(user, slug, leaf, matrix);
597
635
  if (!isGroupOnlySlug(slug)) return false;
598
- return rows.some((entry) => entry.group === slug && grantedOnReleased(user, entry.slug, entry, matrix));
636
+ return rows.some((entry) => entry.group === slug && !entry.releaseOnly && grantedOnReleased(user, entry.slug, entry, matrix));
637
+ }
638
+ /**
639
+ * Whether the saved Features row for `slug` is released. Matches the slug
640
+ * exactly; a missing row, a non-array, or an empty slug is off.
641
+ */
642
+ function featureReleased(rows, slug) {
643
+ if (!Array.isArray(rows) || typeof slug !== "string" || slug === "") return false;
644
+ const row = rows.find((entry) => !!entry && typeof entry === "object" && "slug" in entry && entry.slug === slug);
645
+ return !!row && typeof row === "object" && "released" in row && row.released === true;
646
+ }
647
+ /**
648
+ * Reads the saved Features Global (override access) and answers whether
649
+ * the row for `slug` is released, for every visitor, not per login. A
650
+ * missing row, an empty or unreadable Global, or a read that fails (no
651
+ * table yet) is off. Pass `req` to read inside that request's transaction.
652
+ *
653
+ * @example const launched = await readFeatureReleased(payload, "find-a-doctor");
654
+ */
655
+ async function readFeatureReleased(payload, slug, req) {
656
+ const findGlobal = payload?.findGlobal;
657
+ if (typeof findGlobal !== "function") return false;
658
+ try {
659
+ const doc = await findGlobal.call(payload, {
660
+ slug: FEATURES_SLUG,
661
+ depth: 0,
662
+ overrideAccess: true,
663
+ ...req ? { req } : {}
664
+ });
665
+ const rows = doc && typeof doc === "object" && "features" in doc ? doc.features : null;
666
+ return featureReleased(Array.isArray(rows) ? rows : null, slug);
667
+ } catch {
668
+ return false;
669
+ }
599
670
  }
600
671
  /**
601
672
  * Reads the saved Features Global. `null` means empty or unreadable — callers
@@ -4162,6 +4233,6 @@ function withJobsOnSwitch(global) {
4162
4233
  };
4163
4234
  }
4164
4235
  //#endregion
4165
- export { LIBRARY_DEFAULT_LOCALE as $, resetRolesMatrix as $t, TRANSLATE_NOW as A, isLockedFeature as An, hideUnlessDeveloper as At, TRANSLATION_STATUS_BAR as B, DUPLICATE_ROLE_NAME_MESSAGE as Bt, isAutosave as C, FEATURES_SLUG as Cn, canManageContent as Ct, shouldSkipUndraftedTranslation as D, PACKAGE_FEATURE_SLUGS as Dn, hasCapability as Dt, shouldSkipDraftedTranslation as E, PACKAGE_FEATURES as En, getRolesMatrix as Et, TRANSLATION_ACTIVITY_PANEL as F, isDeveloperTab as Ft, FAILURE_ADVICE as G, ROLES_FIELD_DESCRIPTION as Gt, readTranslationSettings as H, INVALID_ROLE_NAME_MESSAGE as Ht, TRANSLATION_GRANT as I, isPrivilegedRole as It, monthKey as J, applyRoleSlugsFromNames as Jt, RATE_LIMIT_STREAK as K, ROLES_GLOBAL_DESCRIPTION as Kt, TRANSLATION_KEY_PANEL as L, storedRoles as Lt, BISON_TRANSLATION_CONTEXT as M, isAdminOrSelf as Mt, readTranslateState as N, isAuthenticated as Nt, TRANSACTION_TIMEOUT_MS as O, isFeatureGroupId as On, hasGrant as Ot, withTranslator as P, isDeveloper as Pt, ACTIVE_LOCALES_CACHE_MS as Q, parseRolesMatrix as Qt, TRANSLATION_SETTINGS_SLUG as R, DEFAULT_ROLE_MATRIX as Rt, startJob as S, slugifyRoleName as Sn, canManageBrand as St, localizedCopyUnchanged as T, FEATURE_GROUP_LABELS as Tn, developerOnlyAccess as Tt, resolveModel as U, LAST_USERS_TICK_MESSAGE as Ut, invalidateTranslationSettings as V, DUPLICATE_ROLE_SLUG_MESSAGE as Vt, siteFromInstructions as W, MISSING_SEED_ROLES_MESSAGE as Wt, usageHistory as X, grantsFromStoredRole as Xt, recordUsage as Y, defaultRolesFieldValue as Yt, usageThisMonth as Z, normalizeStoredRoles as Zt, frozenWordForce as _, isRole as _n, canUseFeature as _t, MESSAGES_CACHE_MS as a, defaultFeaturesFieldValue as an, invalidateActiveLocales as at, runJobSlice as b, roleLabel as bn, hideUnlessFeature as bt, importMessages as c, parseFeaturesMatrix as cn, encryptApiKey as ct, unflattenMessages as d, CAPABILITIES as dn, sameRow as dt, roleDescription as en, LIBRARY_LOCALES as et, translationSettingsEndpoints as f, CAPABILITY_FEATURES as fn, translationJob as ft, estimateJob as g, THEME_FEATURE_SLUGS as gn, allowedFeaturesForUser as gt, claimJob as h, ROLE_LABELS as hn, updateUnlessPublishing as ht, INTERFACE_TEXT_SLUG as i, MISSING_PACKAGE_FEATURES_MESSAGE as in, inactiveLocaleRedirect as it, translateDocument as j, isPackageFeatureSlug as jn, isAdmin as jt, runAfterCommit as k, isFeatureSlug as kn, hasRole as kt, interfaceTextGlobal as l, stampFeatureCatalogue as ln, resolveApiKey as lt, TRANSLATION_JOBS_SLUG as m, ROLES as mn, refusePublishWithoutGrant as mt, hasLocalizedFields as n, seedRoleRows as nn, activeAlternates as nt, flattenMessages as o, featureCatalogue as on, withLibraryLocales as ot, LEASE_MS as p, DEFAULT_ROLE_GRANTS as pn, draftSavesOnlyWithoutPublish as pt, TRANSLATION_USAGE_SLUG as q, ROLES_SLUG as qt, translation as r, validateRolesMatrix as rn, activeLocales as rt, getMessages as s, featureGroupLabel as sn, decryptApiKey as st, applyTranslation as t, roleSelectOptions as tn, LIBRARY_LOCALE_CODES as tt, invalidateMessages as u, validateFeaturesMatrix as un, collectLocalizedStrings as ut, jobView as v, isRoleName as vn, getFeaturesMatrix as vt, draftedTranslationDecision as w, FEATURE_GROUPS as wn, canPublish as wt, startBackfill as x, sanitizeRoleNameInput as xn, authenticatedOrPublished as xt, resumeStaleJobs as y, isRoleSlug as yn, hasFeature as yt, TRANSLATION_STATE_SLUG as z, DEVELOPER_DESCRIPTION as zt };
4236
+ export { LIBRARY_DEFAULT_LOCALE as $, normalizeStoredRoles as $t, TRANSLATE_NOW as A, PACKAGE_FEATURES as An, hasGrant as At, TRANSLATION_STATUS_BAR as B, DEFAULT_ROLE_MATRIX as Bt, isAutosave as C, isRoleSlug as Cn, authenticatedOrPublished as Ct, shouldSkipUndraftedTranslation as D, FEATURES_SLUG as Dn, developerOnlyAccess as Dt, shouldSkipDraftedTranslation as E, slugifyRoleName as En, canPublish as Et, TRANSLATION_ACTIVITY_PANEL as F, isLockedFeature as Fn, isAuthenticated as Ft, FAILURE_ADVICE as G, LAST_USERS_TICK_MESSAGE as Gt, readTranslationSettings as H, DUPLICATE_ROLE_NAME_MESSAGE as Ht, TRANSLATION_GRANT as I, isPackageFeatureSlug as In, isDeveloper as It, monthKey as J, ROLES_GLOBAL_DESCRIPTION as Jt, RATE_LIMIT_STREAK as K, MISSING_SEED_ROLES_MESSAGE as Kt, TRANSLATION_KEY_PANEL as L, isDeveloperTab as Lt, BISON_TRANSLATION_CONTEXT as M, RELEASE_ONLY_NOTE as Mn, hideUnlessDeveloper as Mt, readTranslateState as N, isFeatureGroupId as Nn, isAdmin as Nt, TRANSACTION_TIMEOUT_MS as O, FEATURE_GROUPS as On, getRolesMatrix as Ot, withTranslator as P, isFeatureSlug as Pn, isAdminOrSelf as Pt, ACTIVE_LOCALES_CACHE_MS as Q, grantsFromStoredRole as Qt, TRANSLATION_SETTINGS_SLUG as R, isPrivilegedRole as Rt, startJob as S, isRoleName as Sn, readFeatureReleased as St, localizedCopyUnchanged as T, sanitizeRoleNameInput as Tn, canManageContent as Tt, resolveModel as U, DUPLICATE_ROLE_SLUG_MESSAGE as Ut, invalidateTranslationSettings as V, DEVELOPER_DESCRIPTION as Vt, siteFromInstructions as W, INVALID_ROLE_NAME_MESSAGE as Wt, usageHistory as X, applyRoleSlugsFromNames as Xt, recordUsage as Y, ROLES_SLUG as Yt, usageThisMonth as Z, defaultRolesFieldValue as Zt, frozenWordForce as _, DEFAULT_ROLE_GRANTS as _n, canUseFeature as _t, MESSAGES_CACHE_MS as a, validateRolesMatrix as an, invalidateActiveLocales as at, runJobSlice as b, THEME_FEATURE_SLUGS as bn, hasFeature as bt, importMessages as c, featureCatalogue as cn, encryptApiKey as ct, unflattenMessages as d, parseFeaturesMatrix as dn, sameRow as dt, parseRolesMatrix as en, LIBRARY_LOCALES as et, translationSettingsEndpoints as f, releaseOnlyFeatureSlugs as fn, translationJob as ft, estimateJob as g, CAPABILITY_FEATURES as gn, allowedFeaturesForUser as gt, claimJob as h, CAPABILITIES as hn, updateUnlessPublishing as ht, INTERFACE_TEXT_SLUG as i, seedRoleRows as in, inactiveLocaleRedirect as it, translateDocument as j, PACKAGE_FEATURE_SLUGS as jn, hasRole as jt, runAfterCommit as k, FEATURE_GROUP_LABELS as kn, hasCapability as kt, interfaceTextGlobal as l, featureGroupLabel as ln, resolveApiKey as lt, TRANSLATION_JOBS_SLUG as m, validateFeaturesMatrix as mn, refusePublishWithoutGrant as mt, hasLocalizedFields as n, roleDescription as nn, activeAlternates as nt, flattenMessages as o, MISSING_PACKAGE_FEATURES_MESSAGE as on, withLibraryLocales as ot, LEASE_MS as p, stampFeatureCatalogue as pn, draftSavesOnlyWithoutPublish as pt, TRANSLATION_USAGE_SLUG as q, ROLES_FIELD_DESCRIPTION as qt, translation as r, roleSelectOptions as rn, activeLocales as rt, getMessages as s, defaultFeaturesFieldValue as sn, decryptApiKey as st, applyTranslation as t, resetRolesMatrix as tn, LIBRARY_LOCALE_CODES as tt, invalidateMessages as u, markReleaseOnlyRows as un, collectLocalizedStrings as ut, jobView as v, ROLES as vn, featureReleased as vt, draftedTranslationDecision as w, roleLabel as wn, canManageBrand as wt, startBackfill as x, isRole as xn, hideUnlessFeature as xt, resumeStaleJobs as y, ROLE_LABELS as yn, getFeaturesMatrix as yt, TRANSLATION_STATE_SLUG as z, storedRoles as zt };
4166
4237
 
4167
- //# sourceMappingURL=capability-B3Mk0KRh.mjs.map
4238
+ //# sourceMappingURL=capability-Kd5LgQpm.mjs.map