@bison-lab/payload-core 5.6.0 → 5.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/README.md +1 -1
- package/dist/{capability-CAXtTcSU.mjs → capability-DCwqbZ82.mjs} +63 -11
- package/dist/{capability-CAXtTcSU.mjs.map → capability-DCwqbZ82.mjs.map} +1 -1
- package/dist/index.mjs +1 -1
- package/dist/translate.d.mts +11 -3
- package/dist/translate.d.mts.map +1 -1
- package/dist/translate.mjs +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -910,7 +910,7 @@ the switcher/hreflang filter; `GET /api/translation/locales` serves it to an
|
|
|
910
910
|
edge runtime. `localizeExistingContent` is the one-to-several locale data
|
|
911
911
|
migration: it runs the generated SQL with every `DROP COLUMN` / `DROP TYPE`
|
|
912
912
|
moved last and each moving column copied into `<table>_locales` first.
|
|
913
|
-
It also sets the default locale on the new `locale` column of `_rels` / `_texts` / `_numbers` rows whose `path` is a localized field (`isLocalizedPath` over the migration's `payload.config`), and stops when such rows exist without it. Postgres only. `pnpm --filter @bison-lab/payload-core test:postgres` runs it against a local Postgres with recorded `migrate:create` output (`src/__tests__/fixtures/localize/`); the normal suite skips it.
|
|
913
|
+
It also sets the default locale on the new `locale` column of `_rels` / `_texts` / `_numbers` rows whose `path` is a localized field (`isLocalizedPath` over the migration's `payload.config`), and stops when such rows exist without it. Postgres only. `pnpm --filter @bison-lab/payload-core test:postgres` runs it against a local Postgres with recorded `migrate:create` output (`src/__tests__/fixtures/localize/`); the normal suite skips it. The same command also boots a real Payload on a scratch database (`@payloadcms/db-postgres`, a dev dependency pinned to the Payload version) to hold the Interface text Global's behavior that FakePayload only copies: a never-saved Global reading as a draft, and a version restore writing the live row (`interface-text-postgres.test.ts`, #305 / #309).
|
|
914
914
|
|
|
915
915
|
### Jobs, usage and failures (#295, #296)
|
|
916
916
|
|
|
@@ -3710,6 +3710,25 @@ const refusePublishWithoutGrant = async ({ data, req }) => {
|
|
|
3710
3710
|
if (await Promise.resolve(canPublish({ req }))) return data;
|
|
3711
3711
|
throw new Forbidden();
|
|
3712
3712
|
};
|
|
3713
|
+
/**
|
|
3714
|
+
* Without Publish, an update must be a draft save (`draft: true`;
|
|
3715
|
+
* `?draft=true` over REST, which the admin's Save draft sends), and a
|
|
3716
|
+
* version restore is refused outright. The gate above is not enough on its
|
|
3717
|
+
* own: Payload fills `_status` from the latest version, so once anyone has
|
|
3718
|
+
* saved a draft a plain update reads `'draft'`, passes it, and still writes
|
|
3719
|
+
* the live row that `getMessages` serves (#309). A restore writes that live
|
|
3720
|
+
* row even with `draft: true` (Payload only marks it a draft first), so no
|
|
3721
|
+
* restore is a draft save. Writes with no user or with `overrideAccess` are
|
|
3722
|
+
* the server's own and pass, as on the gate.
|
|
3723
|
+
*/
|
|
3724
|
+
const draftSavesOnlyWithoutPublish = async ({ args, operation, req }) => {
|
|
3725
|
+
if (operation !== "update" && operation !== "restoreVersion") return args;
|
|
3726
|
+
const write = args;
|
|
3727
|
+
if (write.overrideAccess || !req.user) return args;
|
|
3728
|
+
if (operation === "update" && write.draft === true && !write.publishAllLocales && !write.publishSpecificLocale && !write.unpublishAllLocales) return args;
|
|
3729
|
+
if (await Promise.resolve(canPublish({ req }))) return args;
|
|
3730
|
+
throw new Forbidden();
|
|
3731
|
+
};
|
|
3713
3732
|
const clearMessages = ({ doc, req }) => {
|
|
3714
3733
|
invalidateMessages(req.payload);
|
|
3715
3734
|
return doc;
|
|
@@ -3718,7 +3737,9 @@ const clearMessages = ({ doc, req }) => {
|
|
|
3718
3737
|
* The Interface text Global: one row per message, key shared by every
|
|
3719
3738
|
* locale, text localized. Drafts on, so a publish is what re-translates
|
|
3720
3739
|
* changed English (the usual rules). The Content grant saves drafts; the
|
|
3721
|
-
* Publish grant publishes, as on Pages and the Header
|
|
3740
|
+
* Publish grant publishes, as on Pages and the Header, and is the only
|
|
3741
|
+
* grant that writes the live text any other way (a plain update, a version
|
|
3742
|
+
* restore).
|
|
3722
3743
|
*/
|
|
3723
3744
|
function interfaceTextGlobal() {
|
|
3724
3745
|
return {
|
|
@@ -3737,6 +3758,7 @@ function interfaceTextGlobal() {
|
|
|
3737
3758
|
max: 50
|
|
3738
3759
|
},
|
|
3739
3760
|
hooks: {
|
|
3761
|
+
beforeOperation: [draftSavesOnlyWithoutPublish],
|
|
3740
3762
|
beforeChange: [refusePublishWithoutGrant],
|
|
3741
3763
|
afterChange: [clearMessages]
|
|
3742
3764
|
},
|
|
@@ -3771,6 +3793,33 @@ function interfaceTextGlobal() {
|
|
|
3771
3793
|
};
|
|
3772
3794
|
}
|
|
3773
3795
|
/**
|
|
3796
|
+
* Judged from the newest version row, not `findGlobal({ draft: true })`: a
|
|
3797
|
+
* Global that was never saved has no row, and Payload reads it back with the
|
|
3798
|
+
* `_status` default, `'draft'`, so that read refused a first import (#305).
|
|
3799
|
+
* A caller's `payload` without `findGlobalVersions` (a hand-built wrapper
|
|
3800
|
+
* written for the earlier signature) keeps the old read, and with it the old
|
|
3801
|
+
* refusal of a never-saved Global; pass `req` instead of wrapping.
|
|
3802
|
+
*/
|
|
3803
|
+
async function hasUnpublishedDraft(payload, req) {
|
|
3804
|
+
if (typeof payload.findGlobalVersions !== "function") return (await payload.findGlobal({
|
|
3805
|
+
slug: INTERFACE_TEXT_SLUG,
|
|
3806
|
+
depth: 0,
|
|
3807
|
+
overrideAccess: true,
|
|
3808
|
+
draft: true,
|
|
3809
|
+
...req
|
|
3810
|
+
}))?._status === "draft";
|
|
3811
|
+
const { docs } = await payload.findGlobalVersions({
|
|
3812
|
+
slug: INTERFACE_TEXT_SLUG,
|
|
3813
|
+
sort: "-updatedAt",
|
|
3814
|
+
limit: 1,
|
|
3815
|
+
pagination: false,
|
|
3816
|
+
depth: 0,
|
|
3817
|
+
overrideAccess: true,
|
|
3818
|
+
...req
|
|
3819
|
+
});
|
|
3820
|
+
return (docs[0]?.version)?._status === "draft";
|
|
3821
|
+
}
|
|
3822
|
+
/**
|
|
3774
3823
|
* The migration path from `messages/<locale>.json`: the source locale's
|
|
3775
3824
|
* file sets the keys and fills blank English, every other file fills blank
|
|
3776
3825
|
* text in its locale. Anything already in the CMS is kept, so running it
|
|
@@ -3780,13 +3829,19 @@ function interfaceTextGlobal() {
|
|
|
3780
3829
|
* `context: { autoTranslate: false }`, so importing translates nothing;
|
|
3781
3830
|
* blank strings left over fill on the next publish or backfill.
|
|
3782
3831
|
*
|
|
3832
|
+
* In a migration, pass its `req` so every read and write joins the
|
|
3833
|
+
* migration's transaction and sees the tables it just created.
|
|
3834
|
+
*
|
|
3783
3835
|
* ```ts
|
|
3784
3836
|
* import en from "../src/messages/en.json";
|
|
3785
3837
|
* import es from "../src/messages/es.json";
|
|
3786
|
-
*
|
|
3838
|
+
* export async function up({ payload, req }: MigrateUpArgs) {
|
|
3839
|
+
* await importMessages(payload, { en, es }, { req });
|
|
3840
|
+
* }
|
|
3787
3841
|
* ```
|
|
3788
3842
|
*/
|
|
3789
3843
|
async function importMessages(payload, files, options = {}) {
|
|
3844
|
+
const req = options.req ? { req: options.req } : {};
|
|
3790
3845
|
const localization = payload.config.localization;
|
|
3791
3846
|
const source = options.sourceLocale ?? (localization ? localization.defaultLocale : "en");
|
|
3792
3847
|
const sourceFile = files[source];
|
|
@@ -3802,7 +3857,8 @@ async function importMessages(payload, files, options = {}) {
|
|
|
3802
3857
|
fallbackLocale: false,
|
|
3803
3858
|
depth: 0,
|
|
3804
3859
|
overrideAccess: true,
|
|
3805
|
-
draft: true
|
|
3860
|
+
draft: true,
|
|
3861
|
+
...req
|
|
3806
3862
|
})).messages ?? [];
|
|
3807
3863
|
const write = async (locale, rows) => {
|
|
3808
3864
|
await payload.updateGlobal({
|
|
@@ -3814,16 +3870,12 @@ async function importMessages(payload, files, options = {}) {
|
|
|
3814
3870
|
},
|
|
3815
3871
|
depth: 0,
|
|
3816
3872
|
overrideAccess: true,
|
|
3817
|
-
context: { autoTranslate: false }
|
|
3873
|
+
context: { autoTranslate: false },
|
|
3874
|
+
...req
|
|
3818
3875
|
});
|
|
3819
3876
|
};
|
|
3820
3877
|
const blank = (value) => typeof value !== "string" || value.trim() === "";
|
|
3821
|
-
if (
|
|
3822
|
-
slug: "interface-text",
|
|
3823
|
-
depth: 0,
|
|
3824
|
-
overrideAccess: true,
|
|
3825
|
-
draft: true
|
|
3826
|
-
}))?._status === "draft") throw new Error("importMessages: Interface text has an unpublished draft. Publish or discard it in the admin, then import again, so the import does not put that draft live.");
|
|
3878
|
+
if (await hasUnpublishedDraft(payload, req)) throw new Error("importMessages: Interface text has an unpublished draft. Publish or discard it in the admin, then import again, so the import does not put that draft live.");
|
|
3827
3879
|
const flatSource = flattenMessages(sourceFile);
|
|
3828
3880
|
const rows = (await read(source)).map((row) => ({ ...row }));
|
|
3829
3881
|
const byKey = new Map(rows.map((row) => [row.key, row]));
|
|
@@ -4098,4 +4150,4 @@ function withJobsOnSwitch(global) {
|
|
|
4098
4150
|
//#endregion
|
|
4099
4151
|
export { LIBRARY_DEFAULT_LOCALE as $, seedRoleRows as $t, TRANSLATE_NOW as A, isAuthenticated as At, TRANSLATION_STATUS_BAR as B, LAST_USERS_TICK_MESSAGE as Bt, isAutosave as C, PACKAGE_FEATURES as Cn, getRolesMatrix as Ct, shouldSkipUndraftedTranslation as D, isLockedFeature as Dn, hideUnlessDeveloper as Dt, shouldSkipDraftedTranslation as E, isFeatureSlug as En, hasRole as Et, TRANSLATION_ACTIVITY_PANEL as F, DEFAULT_ROLE_MATRIX as Ft, FAILURE_ADVICE as G, applyRoleSlugsFromNames as Gt, readTranslationSettings as H, ROLES_FIELD_DESCRIPTION as Ht, TRANSLATION_GRANT as I, DEVELOPER_DESCRIPTION as It, monthKey as J, normalizeStoredRoles as Jt, RATE_LIMIT_STREAK as K, defaultRolesFieldValue as Kt, TRANSLATION_KEY_PANEL as L, DUPLICATE_ROLE_NAME_MESSAGE as Lt, BISON_TRANSLATION_CONTEXT as M, isDeveloperTab as Mt, readTranslateState as N, isPrivilegedRole as Nt, TRANSACTION_TIMEOUT_MS as O, isPackageFeatureSlug as On, isAdmin as Ot, withTranslator as P, storedRoles as Pt, ACTIVE_LOCALES_CACHE_MS as Q, roleSelectOptions as Qt, TRANSLATION_SETTINGS_SLUG as R, DUPLICATE_ROLE_SLUG_MESSAGE as Rt, startJob as S, FEATURE_GROUP_LABELS as Sn, developerOnlyAccess as St, localizedCopyUnchanged as T, isFeatureGroupId as Tn, hasGrant as Tt, resolveModel as U, ROLES_GLOBAL_DESCRIPTION as Ut, invalidateTranslationSettings as V, MISSING_SEED_ROLES_MESSAGE as Vt, siteFromInstructions as W, ROLES_SLUG as Wt, usageHistory as X, resetRolesMatrix as Xt, recordUsage as Y, parseRolesMatrix as Yt, usageThisMonth as Z, roleDescription as Zt, frozenWordForce as _, roleLabel as _n, hideUnlessFeature as _t, MESSAGES_CACHE_MS as a, parseFeaturesMatrix as an, invalidateActiveLocales as at, runJobSlice as b, FEATURES_SLUG as bn, canManageContent as bt, importMessages as c, CAPABILITIES as cn, encryptApiKey as ct, unflattenMessages as d, ROLES as dn, sameRow as dt, validateRolesMatrix as en, LIBRARY_LOCALES as et, translationSettingsEndpoints as f, ROLE_LABELS as fn, translationJob as ft, estimateJob as g, isRoleSlug as gn, hasFeature as gt, claimJob as h, isRoleName as hn, getFeaturesMatrix as ht, INTERFACE_TEXT_SLUG as i, featureGroupLabel as in, inactiveLocaleRedirect as it, translateDocument as j, isDeveloper as jt, runAfterCommit as k, isAdminOrSelf as kt, interfaceTextGlobal as l, CAPABILITY_FEATURES as ln, resolveApiKey as lt, TRANSLATION_JOBS_SLUG as m, isRole as mn, canUseFeature as mt, hasLocalizedFields as n, defaultFeaturesFieldValue as nn, activeAlternates as nt, flattenMessages as o, stampFeatureCatalogue as on, withLibraryLocales as ot, LEASE_MS as p, THEME_FEATURE_SLUGS as pn, allowedFeaturesForUser as pt, TRANSLATION_USAGE_SLUG as q, grantsFromStoredRole as qt, translation as r, featureCatalogue as rn, activeLocales as rt, getMessages as s, validateFeaturesMatrix as sn, decryptApiKey as st, applyTranslation as t, MISSING_PACKAGE_FEATURES_MESSAGE as tn, LIBRARY_LOCALE_CODES as tt, invalidateMessages as u, DEFAULT_ROLE_GRANTS as un, collectLocalizedStrings as ut, jobView as v, sanitizeRoleNameInput as vn, authenticatedOrPublished as vt, draftedTranslationDecision as w, PACKAGE_FEATURE_SLUGS as wn, hasCapability as wt, startBackfill as x, FEATURE_GROUPS as xn, canPublish as xt, resumeStaleJobs as y, slugifyRoleName as yn, canManageBrand as yt, TRANSLATION_STATE_SLUG as z, INVALID_ROLE_NAME_MESSAGE as zt };
|
|
4100
4152
|
|
|
4101
|
-
//# sourceMappingURL=capability-
|
|
4153
|
+
//# sourceMappingURL=capability-DCwqbZ82.mjs.map
|