payload 3.0.0-beta.114 → 3.0.0-beta.116
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/dist/database/migrations/migrationsCollection.d.ts.map +1 -1
- package/dist/database/migrations/migrationsCollection.js +2 -1
- package/dist/database/migrations/migrationsCollection.js.map +1 -1
- package/dist/fields/config/sanitize.d.ts +1 -1
- package/dist/fields/config/sanitize.d.ts.map +1 -1
- package/dist/fields/config/sanitize.js +15 -8
- package/dist/fields/config/sanitize.js.map +1 -1
- package/dist/lockedDocuments/lockedDocumentsCollection.d.ts.map +1 -1
- package/dist/lockedDocuments/lockedDocumentsCollection.js +2 -1
- package/dist/lockedDocuments/lockedDocumentsCollection.js.map +1 -1
- package/dist/preferences/preferencesCollection.d.ts.map +1 -1
- package/dist/preferences/preferencesCollection.js +2 -1
- package/dist/preferences/preferencesCollection.js.map +1 -1
- package/dist/utilities/checkDocumentLockStatus.d.ts.map +1 -1
- package/dist/utilities/checkDocumentLockStatus.js +4 -1
- package/dist/utilities/checkDocumentLockStatus.js.map +1 -1
- package/dist/utilities/getEntityPolicies.d.ts.map +1 -1
- package/dist/utilities/getEntityPolicies.js +6 -11
- package/dist/utilities/getEntityPolicies.js.map +1 -1
- package/dist/versions/drafts/appendVersionToQueryKey.d.ts +1 -1
- package/dist/versions/drafts/appendVersionToQueryKey.d.ts.map +1 -1
- package/dist/versions/drafts/appendVersionToQueryKey.js +1 -1
- package/dist/versions/drafts/appendVersionToQueryKey.js.map +1 -1
- package/dist/versions/getLatestCollectionVersion.d.ts.map +1 -1
- package/dist/versions/getLatestCollectionVersion.js +3 -1
- package/dist/versions/getLatestCollectionVersion.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrationsCollection.d.ts","sourceRoot":"","sources":["../../../src/database/migrations/migrationsCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AAEzE,eAAO,MAAM,oBAAoB,EAAE,
|
|
1
|
+
{"version":3,"file":"migrationsCollection.d.ts","sourceRoot":"","sources":["../../../src/database/migrations/migrationsCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AAEzE,eAAO,MAAM,oBAAoB,EAAE,gBAmBlC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/database/migrations/migrationsCollection.ts"],"sourcesContent":["import type { CollectionConfig } from '../../collections/config/types.js'\n\nexport const migrationsCollection: CollectionConfig = {\n slug: 'payload-migrations',\n admin: {\n hidden: true,\n },\n endpoints: false,\n fields: [\n {\n name: 'name',\n type: 'text',\n },\n {\n name: 'batch',\n type: 'number',\n // NOTE: This value is -1 if it is a \"dev push\"\n },\n ],\n graphQL: false,\n}\n"],"names":["migrationsCollection","slug","admin","hidden","endpoints","fields","name","type","graphQL"],"mappings":"AAEA,OAAO,MAAMA,uBAAyC;IACpDC,MAAM;IACNC,OAAO;QACLC,QAAQ;IACV;IACAC,WAAW;IACXC,QAAQ;QACN;YACEC,MAAM;YACNC,MAAM;QACR;QACA;YACED,MAAM;YACNC,MAAM;QAER;KACD;IACDC,SAAS;
|
|
1
|
+
{"version":3,"sources":["../../../src/database/migrations/migrationsCollection.ts"],"sourcesContent":["import type { CollectionConfig } from '../../collections/config/types.js'\n\nexport const migrationsCollection: CollectionConfig = {\n slug: 'payload-migrations',\n admin: {\n hidden: true,\n },\n endpoints: false,\n fields: [\n {\n name: 'name',\n type: 'text',\n },\n {\n name: 'batch',\n type: 'number',\n // NOTE: This value is -1 if it is a \"dev push\"\n },\n ],\n graphQL: false,\n lockDocuments: false,\n}\n"],"names":["migrationsCollection","slug","admin","hidden","endpoints","fields","name","type","graphQL","lockDocuments"],"mappings":"AAEA,OAAO,MAAMA,uBAAyC;IACpDC,MAAM;IACNC,OAAO;QACLC,QAAQ;IACV;IACAC,WAAW;IACXC,QAAQ;QACN;YACEC,MAAM;YACNC,MAAM;QACR;QACA;YACED,MAAM;YACNC,MAAM;QAER;KACD;IACDC,SAAS;IACTC,eAAe;AACjB,EAAC"}
|
|
@@ -29,6 +29,6 @@ type Args = {
|
|
|
29
29
|
*/
|
|
30
30
|
validRelationships: null | string[];
|
|
31
31
|
};
|
|
32
|
-
export declare const sanitizeFields: ({ config, existingFieldNames, fields, joins, parentIsLocalized, requireFieldLevelRichTextEditor, richTextSanitizationPromises, schemaPath
|
|
32
|
+
export declare const sanitizeFields: ({ config, existingFieldNames, fields, joins, parentIsLocalized, requireFieldLevelRichTextEditor, richTextSanitizationPromises, schemaPath, validRelationships, }: Args) => Promise<Field[]>;
|
|
33
33
|
export {};
|
|
34
34
|
//# sourceMappingURL=sanitize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/fields/config/sanitize.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AACzF,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAiBvC,KAAK,IAAI,GAAG;IACV,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAChC,MAAM,EAAE,KAAK,EAAE,CAAA;IACf;;OAEG;IACH,KAAK,CAAC,EAAE,cAAc,CAAA;IACtB,iBAAiB,EAAE,OAAO,CAAA;IAC1B;;;;OAIG;IACH,+BAA+B,CAAC,EAAE,OAAO,CAAA;IAEzC;;;OAGG;IACH,4BAA4B,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;IAChF,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;OAGG;IACH,kBAAkB,EAAE,IAAI,GAAG,MAAM,EAAE,CAAA;CACpC,CAAA;
|
|
1
|
+
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/fields/config/sanitize.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AACzF,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAiBvC,KAAK,IAAI,GAAG;IACV,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAChC,MAAM,EAAE,KAAK,EAAE,CAAA;IACf;;OAEG;IACH,KAAK,CAAC,EAAE,cAAc,CAAA;IACtB,iBAAiB,EAAE,OAAO,CAAA;IAC1B;;;;OAIG;IACH,+BAA+B,CAAC,EAAE,OAAO,CAAA;IAEzC;;;OAGG;IACH,4BAA4B,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;IAChF,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;OAGG;IACH,kBAAkB,EAAE,IAAI,GAAG,MAAM,EAAE,CAAA;CACpC,CAAA;AASD,eAAO,MAAM,cAAc,qKAUxB,IAAI,KAAG,OAAO,CAAC,KAAK,EAAE,CAkPxB,CAAA"}
|
|
@@ -7,11 +7,16 @@ import { setDefaultBeforeDuplicate } from '../setDefaultBeforeDuplicate.js';
|
|
|
7
7
|
import validations from '../validations.js';
|
|
8
8
|
import { sanitizeJoinField } from './sanitizeJoinField.js';
|
|
9
9
|
import { fieldAffectsData, tabHasName } from './types.js';
|
|
10
|
-
|
|
10
|
+
function generateSchemaPath({ name, path = '' }) {
|
|
11
|
+
if (!name) {
|
|
12
|
+
return path;
|
|
13
|
+
}
|
|
14
|
+
return path ? `${path}.${name}` : name;
|
|
15
|
+
}
|
|
16
|
+
export const sanitizeFields = async ({ config, existingFieldNames = new Set(), fields, joins, parentIsLocalized, requireFieldLevelRichTextEditor = false, richTextSanitizationPromises, schemaPath = '', validRelationships })=>{
|
|
11
17
|
if (!fields) {
|
|
12
18
|
return [];
|
|
13
19
|
}
|
|
14
|
-
let schemaPath = schemaPathArg;
|
|
15
20
|
for(let i = 0; i < fields.length; i++){
|
|
16
21
|
const field = fields[i];
|
|
17
22
|
if ('_sanitized' in field && field._sanitized === true) {
|
|
@@ -165,9 +170,6 @@ export const sanitizeFields = async ({ config, existingFieldNames = new Set(), f
|
|
|
165
170
|
}
|
|
166
171
|
}
|
|
167
172
|
if ('fields' in field && field.fields) {
|
|
168
|
-
if ('name' in field && field.name) {
|
|
169
|
-
schemaPath = `${schemaPath || ''}${schemaPath ? '.' : ''}${field.name}`;
|
|
170
|
-
}
|
|
171
173
|
field.fields = await sanitizeFields({
|
|
172
174
|
config,
|
|
173
175
|
existingFieldNames: fieldAffectsData(field) ? new Set() : existingFieldNames,
|
|
@@ -176,7 +178,10 @@ export const sanitizeFields = async ({ config, existingFieldNames = new Set(), f
|
|
|
176
178
|
parentIsLocalized: parentIsLocalized || field.localized,
|
|
177
179
|
requireFieldLevelRichTextEditor,
|
|
178
180
|
richTextSanitizationPromises,
|
|
179
|
-
schemaPath
|
|
181
|
+
schemaPath: generateSchemaPath({
|
|
182
|
+
name: 'name' in field ? field.name : undefined,
|
|
183
|
+
path: schemaPath
|
|
184
|
+
}),
|
|
180
185
|
validRelationships
|
|
181
186
|
});
|
|
182
187
|
}
|
|
@@ -184,7 +189,6 @@ export const sanitizeFields = async ({ config, existingFieldNames = new Set(), f
|
|
|
184
189
|
for(let j = 0; j < field.tabs.length; j++){
|
|
185
190
|
const tab = field.tabs[j];
|
|
186
191
|
if (tabHasName(tab)) {
|
|
187
|
-
schemaPath = `${schemaPath || ''}${schemaPath ? '.' : ''}${tab.name}`;
|
|
188
192
|
if (typeof tab.label === 'undefined') {
|
|
189
193
|
tab.label = toWords(tab.name);
|
|
190
194
|
}
|
|
@@ -197,7 +201,10 @@ export const sanitizeFields = async ({ config, existingFieldNames = new Set(), f
|
|
|
197
201
|
parentIsLocalized: parentIsLocalized || tabHasName(tab) && tab.localized,
|
|
198
202
|
requireFieldLevelRichTextEditor,
|
|
199
203
|
richTextSanitizationPromises,
|
|
200
|
-
schemaPath
|
|
204
|
+
schemaPath: generateSchemaPath({
|
|
205
|
+
name: 'name' in tab ? tab.name : undefined,
|
|
206
|
+
path: schemaPath
|
|
207
|
+
}),
|
|
201
208
|
validRelationships
|
|
202
209
|
});
|
|
203
210
|
field.tabs[j] = tab;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/config/sanitize.ts"],"sourcesContent":["import { deepMergeSimple } from '@payloadcms/translations/utilities'\n\nimport type { CollectionConfig, SanitizedJoins } from '../../collections/config/types.js'\nimport type { Config, SanitizedConfig } from '../../config/types.js'\nimport type { Field } from './types.js'\n\nimport {\n DuplicateFieldName,\n InvalidFieldName,\n InvalidFieldRelationship,\n MissingEditorProp,\n MissingFieldType,\n} from '../../errors/index.js'\nimport { formatLabels, toWords } from '../../utilities/formatLabels.js'\nimport { baseBlockFields } from '../baseFields/baseBlockFields.js'\nimport { baseIDField } from '../baseFields/baseIDField.js'\nimport { setDefaultBeforeDuplicate } from '../setDefaultBeforeDuplicate.js'\nimport validations from '../validations.js'\nimport { sanitizeJoinField } from './sanitizeJoinField.js'\nimport { fieldAffectsData, tabHasName } from './types.js'\n\ntype Args = {\n collectionConfig?: CollectionConfig\n config: Config\n existingFieldNames?: Set<string>\n fields: Field[]\n /**\n * When not passed in, assume that join are not supported (globals, arrays, blocks)\n */\n joins?: SanitizedJoins\n parentIsLocalized: boolean\n /**\n * If true, a richText field will require an editor property to be set, as the sanitizeFields function will not add it from the payload config if not present.\n *\n * @default false\n */\n requireFieldLevelRichTextEditor?: boolean\n\n /**\n * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises\n * so that you can sanitize them together, after the config has been sanitized.\n */\n richTextSanitizationPromises?: Array<(config: SanitizedConfig) => Promise<void>>\n schemaPath?: string\n /**\n * If not null, will validate that upload and relationship fields do not relate to a collection that is not in this array.\n * This validation will be skipped if validRelationships is null.\n */\n validRelationships: null | string[]\n}\n\nexport const sanitizeFields = async ({\n config,\n existingFieldNames = new Set(),\n fields,\n joins,\n parentIsLocalized,\n requireFieldLevelRichTextEditor = false,\n richTextSanitizationPromises,\n schemaPath: schemaPathArg,\n validRelationships,\n}: Args): Promise<Field[]> => {\n if (!fields) {\n return []\n }\n\n let schemaPath = schemaPathArg\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i]\n\n if ('_sanitized' in field && field._sanitized === true) {\n continue\n }\n\n if (!field.type) {\n throw new MissingFieldType(field)\n }\n\n // assert that field names do not contain forbidden characters\n if (fieldAffectsData(field) && field.name.includes('.')) {\n throw new InvalidFieldName(field, field.name)\n }\n\n // Auto-label\n if (\n 'name' in field &&\n field.name &&\n typeof field.label !== 'object' &&\n typeof field.label !== 'string' &&\n typeof field.label !== 'function' &&\n field.label !== false\n ) {\n field.label = toWords(field.name)\n }\n\n if (\n field.type === 'checkbox' &&\n typeof field.defaultValue === 'undefined' &&\n field.required === true\n ) {\n field.defaultValue = false\n }\n\n if (field.type === 'join') {\n sanitizeJoinField({ config, field, joins, schemaPath })\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n if (validRelationships) {\n const relationships = Array.isArray(field.relationTo)\n ? field.relationTo\n : [field.relationTo]\n relationships.forEach((relationship: string) => {\n if (!validRelationships.includes(relationship)) {\n throw new InvalidFieldRelationship(field, relationship)\n }\n })\n }\n\n if (field.min && !field.minRows) {\n console.warn(\n `(payload): The \"min\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"minRows\" instead.`,\n )\n }\n if (field.max && !field.maxRows) {\n console.warn(\n `(payload): The \"max\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"maxRows\" instead.`,\n )\n }\n field.minRows = field.minRows || field.min\n field.maxRows = field.maxRows || field.max\n }\n\n if (field.type === 'upload') {\n if (!field.admin || !('isSortable' in field.admin)) {\n field.admin = {\n isSortable: true,\n ...field.admin,\n }\n }\n }\n\n if (field.type === 'array' && field.fields) {\n field.fields.push(baseIDField)\n }\n\n if ((field.type === 'blocks' || field.type === 'array') && field.label) {\n field.labels = field.labels || formatLabels(field.name)\n }\n\n if (fieldAffectsData(field)) {\n if (existingFieldNames.has(field.name)) {\n throw new DuplicateFieldName(field.name)\n } else if (!['blockName', 'id'].includes(field.name)) {\n existingFieldNames.add(field.name)\n }\n\n if (typeof field.localized !== 'undefined') {\n let shouldDisableLocalized = !config.localization\n\n if (!config.compatibility?.allowLocalizedWithinLocalized && parentIsLocalized) {\n shouldDisableLocalized = true\n }\n\n if (shouldDisableLocalized) {\n delete field.localized\n }\n }\n\n if (typeof field.validate === 'undefined') {\n const defaultValidate = validations[field.type]\n if (defaultValidate) {\n field.validate = (val, options) => defaultValidate(val, { ...field, ...options })\n } else {\n field.validate = (): true => true\n }\n }\n\n if (typeof field.virtual === 'undefined') {\n field.virtual = false\n }\n\n if (!field.hooks) {\n field.hooks = {}\n }\n if (!field.access) {\n field.access = {}\n }\n\n setDefaultBeforeDuplicate(field)\n }\n\n if (!field.admin) {\n field.admin = {}\n }\n\n // Make sure that the richText field has an editor\n if (field.type === 'richText') {\n const sanitizeRichText = async (_config: SanitizedConfig) => {\n if (!field.editor) {\n if (_config.editor && !requireFieldLevelRichTextEditor) {\n // config.editor should be sanitized at this point\n field.editor = _config.editor\n } else {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n }\n\n if (typeof field.editor === 'function') {\n field.editor = await field.editor({\n config: _config,\n isRoot: requireFieldLevelRichTextEditor,\n parentIsLocalized: parentIsLocalized || field.localized,\n })\n }\n\n if (field.editor.i18n && Object.keys(field.editor.i18n).length >= 0) {\n config.i18n.translations = deepMergeSimple(config.i18n.translations, field.editor.i18n)\n }\n }\n if (richTextSanitizationPromises) {\n richTextSanitizationPromises.push(sanitizeRichText)\n } else {\n await sanitizeRichText(config as unknown as SanitizedConfig)\n }\n }\n\n if (field.type === 'blocks' && field.blocks) {\n for (const block of field.blocks) {\n if (block._sanitized === true) {\n continue\n }\n block._sanitized = true\n block.fields = block.fields.concat(baseBlockFields)\n block.labels = !block.labels ? formatLabels(block.slug) : block.labels\n\n block.fields = await sanitizeFields({\n config,\n existingFieldNames: new Set(),\n fields: block.fields,\n parentIsLocalized: parentIsLocalized || field.localized,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n }\n\n if ('fields' in field && field.fields) {\n if ('name' in field && field.name) {\n schemaPath = `${schemaPath || ''}${schemaPath ? '.' : ''}${field.name}`\n }\n field.fields = await sanitizeFields({\n config,\n existingFieldNames: fieldAffectsData(field) ? new Set() : existingFieldNames,\n fields: field.fields,\n joins,\n parentIsLocalized: parentIsLocalized || field.localized,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n schemaPath,\n validRelationships,\n })\n }\n\n if (field.type === 'tabs') {\n for (let j = 0; j < field.tabs.length; j++) {\n const tab = field.tabs[j]\n if (tabHasName(tab)) {\n schemaPath = `${schemaPath || ''}${schemaPath ? '.' : ''}${tab.name}`\n if (typeof tab.label === 'undefined') {\n tab.label = toWords(tab.name)\n }\n }\n\n tab.fields = await sanitizeFields({\n config,\n existingFieldNames: tabHasName(tab) ? new Set() : existingFieldNames,\n fields: tab.fields,\n joins,\n parentIsLocalized: parentIsLocalized || (tabHasName(tab) && tab.localized),\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n schemaPath,\n validRelationships,\n })\n field.tabs[j] = tab\n }\n }\n\n if (field.type === 'ui' && typeof field.admin.disableBulkEdit === 'undefined') {\n field.admin.disableBulkEdit = true\n }\n\n if ('_sanitized' in field) {\n field._sanitized = true\n }\n\n fields[i] = field\n }\n\n return fields\n}\n"],"names":["deepMergeSimple","DuplicateFieldName","InvalidFieldName","InvalidFieldRelationship","MissingEditorProp","MissingFieldType","formatLabels","toWords","baseBlockFields","baseIDField","setDefaultBeforeDuplicate","validations","sanitizeJoinField","fieldAffectsData","tabHasName","sanitizeFields","config","existingFieldNames","Set","fields","joins","parentIsLocalized","requireFieldLevelRichTextEditor","richTextSanitizationPromises","schemaPath","schemaPathArg","validRelationships","i","length","field","_sanitized","type","name","includes","label","defaultValue","required","relationships","Array","isArray","relationTo","forEach","relationship","min","minRows","console","warn","max","maxRows","admin","isSortable","push","labels","has","add","localized","shouldDisableLocalized","localization","compatibility","allowLocalizedWithinLocalized","validate","defaultValidate","val","options","virtual","hooks","access","sanitizeRichText","_config","editor","isRoot","i18n","Object","keys","translations","blocks","block","concat","slug","j","tabs","tab","disableBulkEdit"],"mappings":"AAAA,SAASA,eAAe,QAAQ,qCAAoC;AAMpE,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,wBAAwB,EACxBC,iBAAiB,EACjBC,gBAAgB,QACX,wBAAuB;AAC9B,SAASC,YAAY,EAAEC,OAAO,QAAQ,kCAAiC;AACvE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,WAAW,QAAQ,+BAA8B;AAC1D,SAASC,yBAAyB,QAAQ,kCAAiC;AAC3E,OAAOC,iBAAiB,oBAAmB;AAC3C,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,aAAY;AAgCzD,OAAO,MAAMC,iBAAiB,OAAO,EACnCC,MAAM,EACNC,qBAAqB,IAAIC,KAAK,EAC9BC,MAAM,EACNC,KAAK,EACLC,iBAAiB,EACjBC,kCAAkC,KAAK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AG;QACrB;QAEAX,MAAM,CAACQ,EAAE,GAAGE;IACd;IAEA,OAAOV;AACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/config/sanitize.ts"],"sourcesContent":["import { deepMergeSimple } from '@payloadcms/translations/utilities'\n\nimport type { CollectionConfig, SanitizedJoins } from '../../collections/config/types.js'\nimport type { Config, SanitizedConfig } from '../../config/types.js'\nimport type { Field } from './types.js'\n\nimport {\n DuplicateFieldName,\n InvalidFieldName,\n InvalidFieldRelationship,\n MissingEditorProp,\n MissingFieldType,\n} from '../../errors/index.js'\nimport { formatLabels, toWords } from '../../utilities/formatLabels.js'\nimport { baseBlockFields } from '../baseFields/baseBlockFields.js'\nimport { baseIDField } from '../baseFields/baseIDField.js'\nimport { setDefaultBeforeDuplicate } from '../setDefaultBeforeDuplicate.js'\nimport validations from '../validations.js'\nimport { sanitizeJoinField } from './sanitizeJoinField.js'\nimport { fieldAffectsData, tabHasName } from './types.js'\n\ntype Args = {\n collectionConfig?: CollectionConfig\n config: Config\n existingFieldNames?: Set<string>\n fields: Field[]\n /**\n * When not passed in, assume that join are not supported (globals, arrays, blocks)\n */\n joins?: SanitizedJoins\n parentIsLocalized: boolean\n /**\n * If true, a richText field will require an editor property to be set, as the sanitizeFields function will not add it from the payload config if not present.\n *\n * @default false\n */\n requireFieldLevelRichTextEditor?: boolean\n\n /**\n * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises\n * so that you can sanitize them together, after the config has been sanitized.\n */\n richTextSanitizationPromises?: Array<(config: SanitizedConfig) => Promise<void>>\n schemaPath?: string\n /**\n * If not null, will validate that upload and relationship fields do not relate to a collection that is not in this array.\n * This validation will be skipped if validRelationships is null.\n */\n validRelationships: null | string[]\n}\n\nfunction generateSchemaPath({ name, path = '' }: { name?: string; path?: string }): string {\n if (!name) {\n return path\n }\n return path ? `${path}.${name}` : name\n}\n\nexport const sanitizeFields = async ({\n config,\n existingFieldNames = new Set(),\n fields,\n joins,\n parentIsLocalized,\n requireFieldLevelRichTextEditor = false,\n richTextSanitizationPromises,\n schemaPath = '',\n validRelationships,\n}: Args): Promise<Field[]> => {\n if (!fields) {\n return []\n }\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i]\n\n if ('_sanitized' in field && field._sanitized === true) {\n continue\n }\n\n if (!field.type) {\n throw new MissingFieldType(field)\n }\n\n // assert that field names do not contain forbidden characters\n if (fieldAffectsData(field) && field.name.includes('.')) {\n throw new InvalidFieldName(field, field.name)\n }\n\n // Auto-label\n if (\n 'name' in field &&\n field.name &&\n typeof field.label !== 'object' &&\n typeof field.label !== 'string' &&\n typeof field.label !== 'function' &&\n field.label !== false\n ) {\n field.label = toWords(field.name)\n }\n\n if (\n field.type === 'checkbox' &&\n typeof field.defaultValue === 'undefined' &&\n field.required === true\n ) {\n field.defaultValue = false\n }\n\n if (field.type === 'join') {\n sanitizeJoinField({ config, field, joins, schemaPath })\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n if (validRelationships) {\n const relationships = Array.isArray(field.relationTo)\n ? field.relationTo\n : [field.relationTo]\n relationships.forEach((relationship: string) => {\n if (!validRelationships.includes(relationship)) {\n throw new InvalidFieldRelationship(field, relationship)\n }\n })\n }\n\n if (field.min && !field.minRows) {\n console.warn(\n `(payload): The \"min\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"minRows\" instead.`,\n )\n }\n if (field.max && !field.maxRows) {\n console.warn(\n `(payload): The \"max\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"maxRows\" instead.`,\n )\n }\n field.minRows = field.minRows || field.min\n field.maxRows = field.maxRows || field.max\n }\n\n if (field.type === 'upload') {\n if (!field.admin || !('isSortable' in field.admin)) {\n field.admin = {\n isSortable: true,\n ...field.admin,\n }\n }\n }\n\n if (field.type === 'array' && field.fields) {\n field.fields.push(baseIDField)\n }\n\n if ((field.type === 'blocks' || field.type === 'array') && field.label) {\n field.labels = field.labels || formatLabels(field.name)\n }\n\n if (fieldAffectsData(field)) {\n if (existingFieldNames.has(field.name)) {\n throw new DuplicateFieldName(field.name)\n } else if (!['blockName', 'id'].includes(field.name)) {\n existingFieldNames.add(field.name)\n }\n\n if (typeof field.localized !== 'undefined') {\n let shouldDisableLocalized = !config.localization\n\n if (!config.compatibility?.allowLocalizedWithinLocalized && parentIsLocalized) {\n shouldDisableLocalized = true\n }\n\n if (shouldDisableLocalized) {\n delete field.localized\n }\n }\n\n if (typeof field.validate === 'undefined') {\n const defaultValidate = validations[field.type]\n if (defaultValidate) {\n field.validate = (val, options) => defaultValidate(val, { ...field, ...options })\n } else {\n field.validate = (): true => true\n }\n }\n\n if (typeof field.virtual === 'undefined') {\n field.virtual = false\n }\n\n if (!field.hooks) {\n field.hooks = {}\n }\n if (!field.access) {\n field.access = {}\n }\n\n setDefaultBeforeDuplicate(field)\n }\n\n if (!field.admin) {\n field.admin = {}\n }\n\n // Make sure that the richText field has an editor\n if (field.type === 'richText') {\n const sanitizeRichText = async (_config: SanitizedConfig) => {\n if (!field.editor) {\n if (_config.editor && !requireFieldLevelRichTextEditor) {\n // config.editor should be sanitized at this point\n field.editor = _config.editor\n } else {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n }\n\n if (typeof field.editor === 'function') {\n field.editor = await field.editor({\n config: _config,\n isRoot: requireFieldLevelRichTextEditor,\n parentIsLocalized: parentIsLocalized || field.localized,\n })\n }\n\n if (field.editor.i18n && Object.keys(field.editor.i18n).length >= 0) {\n config.i18n.translations = deepMergeSimple(config.i18n.translations, field.editor.i18n)\n }\n }\n if (richTextSanitizationPromises) {\n richTextSanitizationPromises.push(sanitizeRichText)\n } else {\n await sanitizeRichText(config as unknown as SanitizedConfig)\n }\n }\n\n if (field.type === 'blocks' && field.blocks) {\n for (const block of field.blocks) {\n if (block._sanitized === true) {\n continue\n }\n block._sanitized = true\n block.fields = block.fields.concat(baseBlockFields)\n block.labels = !block.labels ? formatLabels(block.slug) : block.labels\n\n block.fields = await sanitizeFields({\n config,\n existingFieldNames: new Set(),\n fields: block.fields,\n parentIsLocalized: parentIsLocalized || field.localized,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n }\n\n if ('fields' in field && field.fields) {\n field.fields = await sanitizeFields({\n config,\n existingFieldNames: fieldAffectsData(field) ? new Set() : existingFieldNames,\n fields: field.fields,\n joins,\n parentIsLocalized: parentIsLocalized || field.localized,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n schemaPath: generateSchemaPath({\n name: 'name' in field ? field.name : undefined,\n path: schemaPath,\n }),\n validRelationships,\n })\n }\n\n if (field.type === 'tabs') {\n for (let j = 0; j < field.tabs.length; j++) {\n const tab = field.tabs[j]\n if (tabHasName(tab)) {\n if (typeof tab.label === 'undefined') {\n tab.label = toWords(tab.name)\n }\n }\n\n tab.fields = await sanitizeFields({\n config,\n existingFieldNames: tabHasName(tab) ? new Set() : existingFieldNames,\n fields: tab.fields,\n joins,\n parentIsLocalized: parentIsLocalized || (tabHasName(tab) && tab.localized),\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n schemaPath: generateSchemaPath({\n name: 'name' in tab ? tab.name : undefined,\n path: schemaPath,\n }),\n validRelationships,\n })\n field.tabs[j] = tab\n }\n }\n\n if (field.type === 'ui' && typeof field.admin.disableBulkEdit === 'undefined') {\n field.admin.disableBulkEdit = true\n }\n\n if ('_sanitized' in field) {\n field._sanitized = true\n }\n\n fields[i] = field\n }\n\n return fields\n}\n"],"names":["deepMergeSimple","DuplicateFieldName","InvalidFieldName","InvalidFieldRelationship","MissingEditorProp","MissingFieldType","formatLabels","toWords","baseBlockFields","baseIDField","setDefaultBeforeDuplicate","validations","sanitizeJoinField","fieldAffectsData","tabHasName","generateSchemaPath","name","path","sanitizeFields","config","existingFieldNames","Set","fields","joins","parentIsLocalized","requireFieldLevelRichTextEditor","richTextSanitizationPromises","schemaPath","validRelationships","i","length","field","_sanitized","type","includes","label","defaultValue","required","relationships","Array","isArray","relationTo","forEach","relationship","min","minRows","console","warn","max","maxRows","admin","isSortable","push","labels","has","add","localized","shouldDisableLocalized","localization","compatibility","allowLocalizedWithinLocalized","validate","defaultValidate","val","options","virtual","hooks","access","sanitizeRichText","_config","editor","isRoot","i18n","Object","keys","translations","blocks","block","concat","slug","undefined","j","tabs","tab","disableBulkEdit"],"mappings":"AAAA,SAASA,eAAe,QAAQ,qCAAoC;AAMpE,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,wBAAwB,EACxBC,iBAAiB,EACjBC,gBAAgB,QACX,wBAAuB;AAC9B,SAASC,YAAY,EAAEC,OAAO,QAAQ,kCAAiC;AACvE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,WAAW,QAAQ,+BAA8B;AAC1D,SAASC,yBAAyB,QAAQ,kCAAiC;AAC3E,OAAOC,iBAAiB,oBAAmB;AAC3C,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,aAAY;AAgCzD,SAASC,mBAAmB,EAAEC,IAAI,EAAEC,OAAO,EAAE,EAAoC;IAC/E,IAAI,CAACD,MAAM;QACT,OAAOC;IACT;IACA,OAAOA,OAAO,CAAC,EAAEA,KAAK,CAAC,EAAED,KAAK,CAAC,GAAGA;AACpC;AAEA,OAAO,MAAME,iBAAiB,OAAO,EACnCC,MAAM,EACNC,qBAAqB,IAAIC,KAAK,EAC9BC,MAAM,EACNC,KAAK,EACLC,iBAAiB,EACjBC,kCAAkC,KAAK,EACvCC,4BAA4B,EAC5BC,aAAa,EAAE,EACfC,kBAAkB,EACb;IACL,IAAI,CAACN,QAAQ;QACX,OAAO,EAAE;IACX;IAEA,IAAK,IAAIO,IAAI,GAAGA,IAAIP,OAAOQ,MAAM,EAAED,IAAK;QACtC,MAAME,QAAQT,MAAM,CAACO,EAAE;QAEvB,IAAI,gBAAgBE,SAASA,MAAMC,UAAU,KAAK,MAAM;YACtD;QACF;Q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IAAI,KAAK,QAAQ;YACzB,IAAK,IAAIgD,IAAI,GAAGA,IAAIlD,MAAMmD,IAAI,CAACpD,MAAM,EAAEmD,IAAK;gBAC1C,MAAME,MAAMpD,MAAMmD,IAAI,CAACD,EAAE;gBACzB,IAAInE,WAAWqE,MAAM;oBACnB,IAAI,OAAOA,IAAIhD,KAAK,KAAK,aAAa;wBACpCgD,IAAIhD,KAAK,GAAG5B,QAAQ4E,IAAInE,IAAI;oBAC9B;gBACF;gBAEAmE,IAAI7D,MAAM,GAAG,MAAMJ,eAAe;oBAChCC;oBACAC,oBAAoBN,WAAWqE,OAAO,IAAI9D,QAAQD;oBAClDE,QAAQ6D,IAAI7D,MAAM;oBAClBC;oBACAC,mBAAmBA,qBAAsBV,WAAWqE,QAAQA,IAAI3B,SAAS;oBACzE/B;oBACAC;oBACAC,YAAYZ,mBAAmB;wBAC7BC,MAAM,UAAUmE,MAAMA,IAAInE,IAAI,GAAGgE;wBACjC/D,MAAMU;oBACR;oBACAC;gBACF;gBACAG,MAAMmD,IAAI,CAACD,EAAE,GAAGE;YAClB;QACF;QAEA,IAAIpD,MAAME,IAAI,KAAK,QAAQ,OAAOF,MAAMmB,KAAK,CAACkC,eAAe,KAAK,aAAa;YAC7ErD,MAAMmB,KAAK,CAACkC,eAAe,GAAG;QAChC;QAEA,IAAI,gBAAgBrD,OAAO;YACzBA,MAAMC,UAAU,GAAG;QACrB;QAEAV,MAAM,CAACO,EAAE,GAAGE;IACd;IAEA,OAAOT;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lockedDocumentsCollection.d.ts","sourceRoot":"","sources":["../../src/lockedDocuments/lockedDocumentsCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAEhD,eAAO,MAAM,4BAA4B,WAAY,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"lockedDocumentsCollection.d.ts","sourceRoot":"","sources":["../../src/lockedDocuments/lockedDocumentsCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAEhD,eAAO,MAAM,4BAA4B,WAAY,MAAM,KAAG,gBA6B5D,CAAA"}
|
|
@@ -25,7 +25,8 @@ export const getLockedDocumentsCollection = (config)=>({
|
|
|
25
25
|
relationTo: config.collections.filter((collectionConfig)=>collectionConfig.auth).map((collectionConfig)=>collectionConfig.slug),
|
|
26
26
|
required: true
|
|
27
27
|
}
|
|
28
|
-
]
|
|
28
|
+
],
|
|
29
|
+
lockDocuments: false
|
|
29
30
|
});
|
|
30
31
|
|
|
31
32
|
//# sourceMappingURL=lockedDocumentsCollection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lockedDocuments/lockedDocumentsCollection.ts"],"sourcesContent":["import type { CollectionConfig } from '../collections/config/types.js'\nimport type { Config } from '../config/types.js'\n\nexport const getLockedDocumentsCollection = (config: Config): CollectionConfig => ({\n slug: 'payload-locked-documents',\n admin: {\n hidden: true,\n },\n fields: [\n {\n name: 'document',\n type: 'relationship',\n index: true,\n maxDepth: 0,\n relationTo: [...config.collections.map((collectionConfig) => collectionConfig.slug)],\n },\n {\n name: 'globalSlug',\n type: 'text',\n index: true,\n },\n {\n name: 'user',\n type: 'relationship',\n maxDepth: 1,\n relationTo: config.collections\n .filter((collectionConfig) => collectionConfig.auth)\n .map((collectionConfig) => collectionConfig.slug),\n required: true,\n },\n ],\n})\n"],"names":["getLockedDocumentsCollection","config","slug","admin","hidden","fields","name","type","index","maxDepth","relationTo","collections","map","collectionConfig","filter","auth","required"],"mappings":"AAGA,OAAO,MAAMA,+BAA+B,CAACC,SAAsC,CAAA;QACjFC,MAAM;QACNC,OAAO;YACLC,QAAQ;QACV;QACAC,QAAQ;YACN;gBACEC,MAAM;gBACNC,MAAM;gBACNC,OAAO;gBACPC,UAAU;gBACVC,YAAY;uBAAIT,OAAOU,WAAW,CAACC,GAAG,CAAC,CAACC,mBAAqBA,iBAAiBX,IAAI;iBAAE;YACtF;YACA;gBACEI,MAAM;gBACNC,MAAM;gBACNC,OAAO;YACT;YACA;gBACEF,MAAM;gBACNC,MAAM;gBACNE,UAAU;gBACVC,YAAYT,OAAOU,WAAW,CAC3BG,MAAM,CAAC,CAACD,mBAAqBA,iBAAiBE,IAAI,EAClDH,GAAG,CAAC,CAACC,mBAAqBA,iBAAiBX,IAAI;gBAClDc,UAAU;YACZ;SACD;
|
|
1
|
+
{"version":3,"sources":["../../src/lockedDocuments/lockedDocumentsCollection.ts"],"sourcesContent":["import type { CollectionConfig } from '../collections/config/types.js'\nimport type { Config } from '../config/types.js'\n\nexport const getLockedDocumentsCollection = (config: Config): CollectionConfig => ({\n slug: 'payload-locked-documents',\n admin: {\n hidden: true,\n },\n fields: [\n {\n name: 'document',\n type: 'relationship',\n index: true,\n maxDepth: 0,\n relationTo: [...config.collections.map((collectionConfig) => collectionConfig.slug)],\n },\n {\n name: 'globalSlug',\n type: 'text',\n index: true,\n },\n {\n name: 'user',\n type: 'relationship',\n maxDepth: 1,\n relationTo: config.collections\n .filter((collectionConfig) => collectionConfig.auth)\n .map((collectionConfig) => collectionConfig.slug),\n required: true,\n },\n ],\n lockDocuments: false,\n})\n"],"names":["getLockedDocumentsCollection","config","slug","admin","hidden","fields","name","type","index","maxDepth","relationTo","collections","map","collectionConfig","filter","auth","required","lockDocuments"],"mappings":"AAGA,OAAO,MAAMA,+BAA+B,CAACC,SAAsC,CAAA;QACjFC,MAAM;QACNC,OAAO;YACLC,QAAQ;QACV;QACAC,QAAQ;YACN;gBACEC,MAAM;gBACNC,MAAM;gBACNC,OAAO;gBACPC,UAAU;gBACVC,YAAY;uBAAIT,OAAOU,WAAW,CAACC,GAAG,CAAC,CAACC,mBAAqBA,iBAAiBX,IAAI;iBAAE;YACtF;YACA;gBACEI,MAAM;gBACNC,MAAM;gBACNC,OAAO;YACT;YACA;gBACEF,MAAM;gBACNC,MAAM;gBACNE,UAAU;gBACVC,YAAYT,OAAOU,WAAW,CAC3BG,MAAM,CAAC,CAACD,mBAAqBA,iBAAiBE,IAAI,EAClDH,GAAG,CAAC,CAACC,mBAAqBA,iBAAiBX,IAAI;gBAClDc,UAAU;YACZ;SACD;QACDC,eAAe;IACjB,CAAA,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preferencesCollection.d.ts","sourceRoot":"","sources":["../../src/preferences/preferencesCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACtE,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAYxD,QAAA,MAAM,wBAAwB,WAAY,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"preferencesCollection.d.ts","sourceRoot":"","sources":["../../src/preferences/preferencesCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACtE,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAYxD,QAAA,MAAM,wBAAwB,WAAY,MAAM,KAAG,gBA4DjD,CAAA;AAEF,eAAe,wBAAwB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/preferences/preferencesCollection.ts"],"sourcesContent":["import type { CollectionConfig } from '../collections/config/types.js'\nimport type { Access, Config } from '../config/types.js'\n\nimport { deleteHandler } from './requestHandlers/delete.js'\nimport { findByIDHandler } from './requestHandlers/findOne.js'\nimport { updateHandler } from './requestHandlers/update.js'\n\nconst preferenceAccess: Access = ({ req }) => ({\n 'user.value': {\n equals: req?.user?.id,\n },\n})\n\nconst getPreferencesCollection = (config: Config): CollectionConfig => ({\n slug: 'payload-preferences',\n access: {\n delete: preferenceAccess,\n read: preferenceAccess,\n },\n admin: {\n hidden: true,\n },\n endpoints: [\n {\n handler: findByIDHandler,\n method: 'get',\n path: '/:key',\n },\n {\n handler: deleteHandler,\n method: 'delete',\n path: '/:key',\n },\n {\n handler: updateHandler,\n method: 'post',\n path: '/:key',\n },\n ],\n fields: [\n {\n name: 'user',\n type: 'relationship',\n hooks: {\n beforeValidate: [\n ({ req }) => {\n if (!req?.user) {\n return null\n }\n return {\n relationTo: req?.user.collection,\n value: req?.user.id,\n }\n },\n ],\n },\n index: true,\n relationTo: config.collections\n .filter((collectionConfig) => collectionConfig.auth)\n .map((collectionConfig) => collectionConfig.slug),\n required: true,\n },\n {\n name: 'key',\n type: 'text',\n index: true,\n },\n {\n name: 'value',\n type: 'json',\n },\n ],\n})\n\nexport default getPreferencesCollection\n"],"names":["deleteHandler","findByIDHandler","updateHandler","preferenceAccess","req","equals","user","id","getPreferencesCollection","config","slug","access","delete","read","admin","hidden","endpoints","handler","method","path","fields","name","type","hooks","beforeValidate","relationTo","collection","value","index","collections","filter","collectionConfig","auth","map","required"],"mappings":"AAGA,SAASA,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,eAAe,QAAQ,+BAA8B;AAC9D,SAASC,aAAa,QAAQ,8BAA6B;AAE3D,MAAMC,mBAA2B,CAAC,EAAEC,GAAG,EAAE,GAAM,CAAA;QAC7C,cAAc;YACZC,QAAQD,KAAKE,MAAMC;QACrB;IACF,CAAA;AAEA,MAAMC,2BAA2B,CAACC,SAAsC,CAAA;QACtEC,MAAM;QACNC,QAAQ;YACNC,QAAQT;YACRU,MAAMV;QACR;QACAW,OAAO;YACLC,QAAQ;QACV;QACAC,WAAW;YACT;gBACEC,SAAShB;gBACTiB,QAAQ;gBACRC,MAAM;YACR;YACA;gBACEF,SAASjB;gBACTkB,QAAQ;gBACRC,MAAM;YACR;YACA;gBACEF,SAASf;gBACTgB,QAAQ;gBACRC,MAAM;YACR;SACD;QACDC,QAAQ;YACN;gBACEC,MAAM;gBACNC,MAAM;gBACNC,OAAO;oBACLC,gBAAgB;wBACd,CAAC,EAAEpB,GAAG,EAAE;4BACN,IAAI,CAACA,KAAKE,MAAM;gCACd,OAAO;4BACT;4BACA,OAAO;gCACLmB,YAAYrB,KAAKE,KAAKoB;gCACtBC,OAAOvB,KAAKE,KAAKC;4BACnB;wBACF;qBACD;gBACH;gBACAqB,OAAO;gBACPH,YAAYhB,OAAOoB,WAAW,CAC3BC,MAAM,CAAC,CAACC,mBAAqBA,iBAAiBC,IAAI,EAClDC,GAAG,CAAC,CAACF,mBAAqBA,iBAAiBrB,IAAI;gBAClDwB,UAAU;YACZ;YACA;gBACEb,MAAM;gBACNC,MAAM;gBACNM,OAAO;YACT;YACA;gBACEP,MAAM;gBACNC,MAAM;YACR;SACD;
|
|
1
|
+
{"version":3,"sources":["../../src/preferences/preferencesCollection.ts"],"sourcesContent":["import type { CollectionConfig } from '../collections/config/types.js'\nimport type { Access, Config } from '../config/types.js'\n\nimport { deleteHandler } from './requestHandlers/delete.js'\nimport { findByIDHandler } from './requestHandlers/findOne.js'\nimport { updateHandler } from './requestHandlers/update.js'\n\nconst preferenceAccess: Access = ({ req }) => ({\n 'user.value': {\n equals: req?.user?.id,\n },\n})\n\nconst getPreferencesCollection = (config: Config): CollectionConfig => ({\n slug: 'payload-preferences',\n access: {\n delete: preferenceAccess,\n read: preferenceAccess,\n },\n admin: {\n hidden: true,\n },\n endpoints: [\n {\n handler: findByIDHandler,\n method: 'get',\n path: '/:key',\n },\n {\n handler: deleteHandler,\n method: 'delete',\n path: '/:key',\n },\n {\n handler: updateHandler,\n method: 'post',\n path: '/:key',\n },\n ],\n fields: [\n {\n name: 'user',\n type: 'relationship',\n hooks: {\n beforeValidate: [\n ({ req }) => {\n if (!req?.user) {\n return null\n }\n return {\n relationTo: req?.user.collection,\n value: req?.user.id,\n }\n },\n ],\n },\n index: true,\n relationTo: config.collections\n .filter((collectionConfig) => collectionConfig.auth)\n .map((collectionConfig) => collectionConfig.slug),\n required: true,\n },\n {\n name: 'key',\n type: 'text',\n index: true,\n },\n {\n name: 'value',\n type: 'json',\n },\n ],\n lockDocuments: false,\n})\n\nexport default getPreferencesCollection\n"],"names":["deleteHandler","findByIDHandler","updateHandler","preferenceAccess","req","equals","user","id","getPreferencesCollection","config","slug","access","delete","read","admin","hidden","endpoints","handler","method","path","fields","name","type","hooks","beforeValidate","relationTo","collection","value","index","collections","filter","collectionConfig","auth","map","required","lockDocuments"],"mappings":"AAGA,SAASA,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,eAAe,QAAQ,+BAA8B;AAC9D,SAASC,aAAa,QAAQ,8BAA6B;AAE3D,MAAMC,mBAA2B,CAAC,EAAEC,GAAG,EAAE,GAAM,CAAA;QAC7C,cAAc;YACZC,QAAQD,KAAKE,MAAMC;QACrB;IACF,CAAA;AAEA,MAAMC,2BAA2B,CAACC,SAAsC,CAAA;QACtEC,MAAM;QACNC,QAAQ;YACNC,QAAQT;YACRU,MAAMV;QACR;QACAW,OAAO;YACLC,QAAQ;QACV;QACAC,WAAW;YACT;gBACEC,SAAShB;gBACTiB,QAAQ;gBACRC,MAAM;YACR;YACA;gBACEF,SAASjB;gBACTkB,QAAQ;gBACRC,MAAM;YACR;YACA;gBACEF,SAASf;gBACTgB,QAAQ;gBACRC,MAAM;YACR;SACD;QACDC,QAAQ;YACN;gBACEC,MAAM;gBACNC,MAAM;gBACNC,OAAO;oBACLC,gBAAgB;wBACd,CAAC,EAAEpB,GAAG,EAAE;4BACN,IAAI,CAACA,KAAKE,MAAM;gCACd,OAAO;4BACT;4BACA,OAAO;gCACLmB,YAAYrB,KAAKE,KAAKoB;gCACtBC,OAAOvB,KAAKE,KAAKC;4BACnB;wBACF;qBACD;gBACH;gBACAqB,OAAO;gBACPH,YAAYhB,OAAOoB,WAAW,CAC3BC,MAAM,CAAC,CAACC,mBAAqBA,iBAAiBC,IAAI,EAClDC,GAAG,CAAC,CAACF,mBAAqBA,iBAAiBrB,IAAI;gBAClDwB,UAAU;YACZ;YACA;gBACEb,MAAM;gBACNC,MAAM;gBACNM,OAAO;YACT;YACA;gBACEP,MAAM;gBACNC,MAAM;YACR;SACD;QACDa,eAAe;IACjB,CAAA;AAEA,eAAe3B,yBAAwB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkDocumentLockStatus.d.ts","sourceRoot":"","sources":["../../src/utilities/checkDocumentLockStatus.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAc,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAInE,KAAK,2BAA2B,GAAG;IACjC,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,uBAAuB,kGAQjC,2BAA2B,KAAG,OAAO,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"checkDocumentLockStatus.d.ts","sourceRoot":"","sources":["../../src/utilities/checkDocumentLockStatus.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAc,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAInE,KAAK,2BAA2B,GAAG;IACjC,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,uBAAuB,kGAQjC,2BAA2B,KAAG,OAAO,CAAC,IAAI,CA0E5C,CAAA"}
|
|
@@ -29,8 +29,11 @@ export const checkDocumentLockStatus = async ({ id, collectionSlug, globalSlug,
|
|
|
29
29
|
} else {
|
|
30
30
|
throw new Error('Either collectionSlug or globalSlug must be provided.');
|
|
31
31
|
}
|
|
32
|
+
if (!isLockingEnabled) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
32
35
|
// Only perform lock checks if overrideLock is false and locking is enabled
|
|
33
|
-
if (!overrideLock
|
|
36
|
+
if (!overrideLock) {
|
|
34
37
|
const defaultLockErrorMessage = collectionSlug ? `Document with ID ${id} is currently locked by another user and cannot be modified.` : `Global document with slug "${globalSlug}" is currently locked by another user and cannot be modified.`;
|
|
35
38
|
const finalLockErrorMessage = lockErrorMessage || defaultLockErrorMessage;
|
|
36
39
|
const lockedDocumentResult = await payload.db.find({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/checkDocumentLockStatus.ts"],"sourcesContent":["import type { TypeWithID } from '../collections/config/types.js'\nimport type { PaginatedDocs } from '../database/types.js'\nimport type { JsonObject, PayloadRequest } from '../types/index.js'\n\nimport { Locked } from '../errors/index.js'\n\ntype CheckDocumentLockStatusArgs = {\n collectionSlug?: string\n globalSlug?: string\n id?: number | string\n lockDurationDefault?: number\n lockErrorMessage?: string\n overrideLock?: boolean\n req: PayloadRequest\n}\n\nexport const checkDocumentLockStatus = async ({\n id,\n collectionSlug,\n globalSlug,\n lockDurationDefault = 300, // Default 5 minutes in seconds\n lockErrorMessage,\n overrideLock = true,\n req,\n}: CheckDocumentLockStatusArgs): Promise<void> => {\n const { payload } = req\n\n // Retrieve the lockDocuments property for either collection or global\n const lockDocumentsProp = collectionSlug\n ? payload.config?.collections?.find((c) => c.slug === collectionSlug)?.lockDocuments\n : payload.config?.globals?.find((g) => g.slug === globalSlug)?.lockDocuments\n\n const isLockingEnabled = lockDocumentsProp !== false\n\n let lockedDocumentQuery = {}\n\n if (collectionSlug) {\n lockedDocumentQuery = {\n and: [\n { 'document.relationTo': { equals: collectionSlug } },\n { 'document.value': { equals: id } },\n ],\n }\n } else if (globalSlug) {\n lockedDocumentQuery = { globalSlug: { equals: globalSlug } }\n } else {\n throw new Error('Either collectionSlug or globalSlug must be provided.')\n }\n\n // Only perform lock checks if overrideLock is false and locking is enabled\n if (!overrideLock
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/checkDocumentLockStatus.ts"],"sourcesContent":["import type { TypeWithID } from '../collections/config/types.js'\nimport type { PaginatedDocs } from '../database/types.js'\nimport type { JsonObject, PayloadRequest } from '../types/index.js'\n\nimport { Locked } from '../errors/index.js'\n\ntype CheckDocumentLockStatusArgs = {\n collectionSlug?: string\n globalSlug?: string\n id?: number | string\n lockDurationDefault?: number\n lockErrorMessage?: string\n overrideLock?: boolean\n req: PayloadRequest\n}\n\nexport const checkDocumentLockStatus = async ({\n id,\n collectionSlug,\n globalSlug,\n lockDurationDefault = 300, // Default 5 minutes in seconds\n lockErrorMessage,\n overrideLock = true,\n req,\n}: CheckDocumentLockStatusArgs): Promise<void> => {\n const { payload } = req\n\n // Retrieve the lockDocuments property for either collection or global\n const lockDocumentsProp = collectionSlug\n ? payload.config?.collections?.find((c) => c.slug === collectionSlug)?.lockDocuments\n : payload.config?.globals?.find((g) => g.slug === globalSlug)?.lockDocuments\n\n const isLockingEnabled = lockDocumentsProp !== false\n\n let lockedDocumentQuery = {}\n\n if (collectionSlug) {\n lockedDocumentQuery = {\n and: [\n { 'document.relationTo': { equals: collectionSlug } },\n { 'document.value': { equals: id } },\n ],\n }\n } else if (globalSlug) {\n lockedDocumentQuery = { globalSlug: { equals: globalSlug } }\n } else {\n throw new Error('Either collectionSlug or globalSlug must be provided.')\n }\n\n if (!isLockingEnabled) {\n return\n }\n\n // Only perform lock checks if overrideLock is false and locking is enabled\n if (!overrideLock) {\n const defaultLockErrorMessage = collectionSlug\n ? `Document with ID ${id} is currently locked by another user and cannot be modified.`\n : `Global document with slug \"${globalSlug}\" is currently locked by another user and cannot be modified.`\n\n const finalLockErrorMessage = lockErrorMessage || defaultLockErrorMessage\n\n const lockedDocumentResult: PaginatedDocs<JsonObject & TypeWithID> = await payload.db.find({\n collection: 'payload-locked-documents',\n limit: 1,\n pagination: false,\n req,\n sort: '-updatedAt',\n where: lockedDocumentQuery,\n })\n\n // If there's a locked document, check lock conditions\n const lockedDoc = lockedDocumentResult?.docs[0]\n if (lockedDoc) {\n const lastEditedAt = new Date(lockedDoc?.updatedAt).getTime()\n const now = new Date().getTime()\n\n const lockDuration =\n typeof lockDocumentsProp === 'object' ? lockDocumentsProp.duration : lockDurationDefault\n\n const lockDurationInMilliseconds = lockDuration * 1000\n const currentUserId = req.user?.id\n\n // document is locked by another user and the lock hasn't expired\n if (\n lockedDoc.user?.value !== currentUserId &&\n now - lastEditedAt <= lockDurationInMilliseconds\n ) {\n throw new Locked(finalLockErrorMessage)\n }\n }\n }\n\n // Perform the delete operation regardless of overrideLock status\n await payload.db.deleteMany({\n collection: 'payload-locked-documents',\n req,\n where: lockedDocumentQuery,\n })\n}\n"],"names":["Locked","checkDocumentLockStatus","id","collectionSlug","globalSlug","lockDurationDefault","lockErrorMessage","overrideLock","req","payload","lockDocumentsProp","config","collections","find","c","slug","lockDocuments","globals","g","isLockingEnabled","lockedDocumentQuery","and","equals","Error","defaultLockErrorMessage","finalLockErrorMessage","lockedDocumentResult","db","collection","limit","pagination","sort","where","lockedDoc","docs","lastEditedAt","Date","updatedAt","getTime","now","lockDuration","duration","lockDurationInMilliseconds","currentUserId","user","value","deleteMany"],"mappings":"AAIA,SAASA,MAAM,QAAQ,qBAAoB;AAY3C,OAAO,MAAMC,0BAA0B,OAAO,EAC5CC,EAAE,EACFC,cAAc,EACdC,UAAU,EACVC,sBAAsB,GAAG,EACzBC,gBAAgB,EAChBC,eAAe,IAAI,EACnBC,GAAG,EACyB;IAC5B,MAAM,EAAEC,OAAO,EAAE,GAAGD;IAEpB,sEAAsE;IACtE,MA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,IAAI,EAAE1C;YAEhC,iEAAiE;YACjE,IACE+B,UAAUW,IAAI,EAAEC,UAAUF,iBAC1BJ,MAAMJ,gBAAgBO,4BACtB;gBACA,MAAM,IAAI1C,OAAOyB;YACnB;QACF;IACF;IAEA,iEAAiE;IACjE,MAAMhB,QAAQkB,EAAE,CAACmB,UAAU,CAAC;QAC1BlB,YAAY;QACZpB;QACAwB,OAAOZ;IACT;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEntityPolicies.d.ts","sourceRoot":"","sources":["../../src/utilities/getEntityPolicies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAC9E,OAAO,KAAK,EAAE,yBAAyB,EAAc,MAAM,gCAAgC,CAAA;AAG3F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,aAAa,EAAY,cAAc,EAAS,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"getEntityPolicies.d.ts","sourceRoot":"","sources":["../../src/utilities/getEntityPolicies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAC9E,OAAO,KAAK,EAAE,yBAAyB,EAAc,MAAM,gCAAgC,CAAA;AAG3F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,aAAa,EAAY,cAAc,EAAS,MAAM,mBAAmB,CAAA;AAKvF,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,yBAAyB,GAAG,qBAAqB,CAAA;IACzD,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,UAAU,EAAE,aAAa,EAAE,CAAA;IAC3B,GAAG,EAAE,cAAc,CAAA;IACnB,IAAI,EAAE,YAAY,GAAG,QAAQ,CAAA;CAC9B,CAAA;AAED,KAAK,UAAU,CAAC,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,QAAQ,GACxD,gBAAgB,GAChB,oBAAoB,CAAA;AAYxB,wBAAsB,iBAAiB,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAwOvF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { combineQueries } from '../database/combineQueries.js';
|
|
1
2
|
import { tabHasName } from '../fields/config/types.js';
|
|
2
3
|
export async function getEntityPolicies(args) {
|
|
3
4
|
const { id, type, entity, operations, req } = args;
|
|
@@ -29,17 +30,11 @@ export async function getEntityPolicies(args) {
|
|
|
29
30
|
overrideAccess: true,
|
|
30
31
|
pagination: false,
|
|
31
32
|
req,
|
|
32
|
-
where: {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
id: {
|
|
38
|
-
equals: id
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
]
|
|
42
|
-
}
|
|
33
|
+
where: combineQueries(where, {
|
|
34
|
+
id: {
|
|
35
|
+
equals: id
|
|
36
|
+
}
|
|
37
|
+
})
|
|
43
38
|
});
|
|
44
39
|
return paginatedRes?.docs?.[0] || undefined;
|
|
45
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getEntityPolicies.ts"],"sourcesContent":["import type { CollectionPermission, GlobalPermission } from '../auth/types.js'\nimport type { SanitizedCollectionConfig, TypeWithID } from '../collections/config/types.js'\nimport type { Access } from '../config/types.js'\nimport type { Field, FieldAccess } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\nimport type { AllOperations, Document, PayloadRequest, Where } from '../types/index.js'\n\nimport { tabHasName } from '../fields/config/types.js'\n\ntype Args = {\n entity: SanitizedCollectionConfig | SanitizedGlobalConfig\n id?: number | string\n operations: AllOperations[]\n req: PayloadRequest\n type: 'collection' | 'global'\n}\n\ntype ReturnType<T extends Args> = T['type'] extends 'global'\n ? GlobalPermission\n : CollectionPermission\n\ntype CreateAccessPromise = (args: {\n access: Access | FieldAccess\n accessLevel: 'entity' | 'field'\n disableWhere?: boolean\n operation: AllOperations\n policiesObj: {\n [key: string]: any\n }\n}) => Promise<void>\n\nexport async function getEntityPolicies<T extends Args>(args: T): Promise<ReturnType<T>> {\n const { id, type, entity, operations, req } = args\n const { data, locale, payload, user } = req\n const isLoggedIn = !!user\n\n const policies = {\n fields: {},\n } as ReturnType<T>\n\n let docBeingAccessed\n\n async function getEntityDoc({ where }: { where?: Where } = {}): Promise<Document & TypeWithID> {\n if (entity.slug) {\n if (type === 'global') {\n return payload.findGlobal({\n slug: entity.slug,\n fallbackLocale: null,\n locale,\n overrideAccess: true,\n req,\n })\n }\n\n if (type === 'collection' && id) {\n if (typeof where === 'object') {\n const paginatedRes = await payload.find({\n collection: entity.slug,\n depth: 0,\n fallbackLocale: null,\n limit: 1,\n locale,\n overrideAccess: true,\n pagination: false,\n req,\n where: {\n ...where,\n and: [\n ...(where.and || []),\n {\n id: {\n equals: id,\n },\n },\n ],\n },\n })\n\n return paginatedRes?.docs?.[0] || undefined\n }\n\n return payload.findByID({\n id,\n collection: entity.slug,\n depth: 0,\n fallbackLocale: null,\n locale,\n overrideAccess: true,\n req,\n })\n }\n }\n\n return undefined\n }\n\n const createAccessPromise: CreateAccessPromise = async ({\n access,\n accessLevel,\n disableWhere = false,\n operation,\n policiesObj,\n }) => {\n const mutablePolicies = policiesObj\n\n if (accessLevel === 'field' && docBeingAccessed === undefined) {\n // assign docBeingAccessed first as the promise to avoid multiple calls to getEntityDoc\n docBeingAccessed = getEntityDoc().then((doc) => {\n docBeingAccessed = doc\n })\n }\n // awaiting the promise to ensure docBeingAccessed is assigned before it is used\n await docBeingAccessed\n\n // https://payloadcms.slack.com/archives/C048Z9C2BEX/p1702054928343769\n const accessResult = await access({ id, data, doc: docBeingAccessed, req })\n\n if (typeof accessResult === 'object' && !disableWhere) {\n mutablePolicies[operation] = {\n permission:\n id || type === 'global' ? !!(await getEntityDoc({ where: accessResult })) : true,\n where: accessResult,\n }\n } else if (mutablePolicies[operation]?.permission !== false) {\n mutablePolicies[operation] = {\n permission: !!accessResult,\n }\n }\n }\n\n const executeFieldPolicies = async ({\n entityPermission,\n fields,\n operation,\n policiesObj,\n }: {\n entityPermission\n fields: Field[]\n operation: AllOperations\n policiesObj\n }) => {\n const mutablePolicies = policiesObj.fields\n\n await Promise.all(\n fields.map(async (field) => {\n if ('name' in field && field.name) {\n if (!mutablePolicies[field.name]) {\n mutablePolicies[field.name] = {}\n }\n\n if ('access' in field && field.access && typeof field.access[operation] === 'function') {\n await createAccessPromise({\n access: field.access[operation],\n accessLevel: 'field',\n disableWhere: true,\n operation,\n policiesObj: mutablePolicies[field.name],\n })\n } else {\n mutablePolicies[field.name][operation] = {\n permission: policiesObj[operation]?.permission,\n }\n }\n\n if ('fields' in field && field.fields) {\n if (!mutablePolicies[field.name].fields) {\n mutablePolicies[field.name].fields = {}\n }\n\n await executeFieldPolicies({\n entityPermission,\n fields: field.fields,\n operation,\n policiesObj: mutablePolicies[field.name],\n })\n }\n\n if ('blocks' in field && field?.blocks) {\n if (!mutablePolicies[field.name]?.blocks) {\n mutablePolicies[field.name].blocks = {}\n }\n\n await Promise.all(\n field.blocks.map(async (block) => {\n if (!mutablePolicies[field.name].blocks?.[block.slug]) {\n mutablePolicies[field.name].blocks[block.slug] = {\n fields: {},\n [operation]: { permission: entityPermission },\n }\n } else if (!mutablePolicies[field.name].blocks[block.slug][operation]) {\n mutablePolicies[field.name].blocks[block.slug][operation] = {\n permission: entityPermission,\n }\n }\n\n await executeFieldPolicies({\n entityPermission,\n fields: block.fields,\n operation,\n policiesObj: mutablePolicies[field.name].blocks[block.slug],\n })\n }),\n )\n }\n } else if ('fields' in field && field.fields) {\n await executeFieldPolicies({\n entityPermission,\n fields: field.fields,\n operation,\n policiesObj,\n })\n } else if (field.type === 'tabs') {\n await Promise.all(\n field.tabs.map(async (tab) => {\n if (tabHasName(tab)) {\n if (!mutablePolicies[tab.name]) {\n mutablePolicies[tab.name] = {\n fields: {},\n [operation]: { permission: entityPermission },\n }\n } else if (!mutablePolicies[tab.name][operation]) {\n mutablePolicies[tab.name][operation] = { permission: entityPermission }\n }\n await executeFieldPolicies({\n entityPermission,\n fields: tab.fields,\n operation,\n policiesObj: mutablePolicies[tab.name],\n })\n } else {\n await executeFieldPolicies({\n entityPermission,\n fields: tab.fields,\n operation,\n policiesObj,\n })\n }\n }),\n )\n }\n }),\n )\n }\n\n await operations.reduce(async (priorOperation, operation) => {\n await priorOperation\n\n let entityAccessPromise: Promise<void>\n\n if (typeof entity.access[operation] === 'function') {\n entityAccessPromise = createAccessPromise({\n access: entity.access[operation],\n accessLevel: 'entity',\n operation,\n policiesObj: policies,\n })\n } else {\n policies[operation] = {\n permission: isLoggedIn,\n }\n }\n\n await entityAccessPromise\n\n await executeFieldPolicies({\n entityPermission: policies[operation].permission,\n fields: entity.fields,\n operation,\n policiesObj: policies,\n })\n }, Promise.resolve())\n\n return policies\n}\n"],"names":["tabHasName","getEntityPolicies","args","id","type","entity","operations","req","data","locale","payload","user","isLoggedIn","policies","fields","docBeingAccessed","getEntityDoc","where","slug","findGlobal","fallbackLocale","overrideAccess","paginatedRes","find","collection","depth","limit","pagination","and","equals","docs","undefined","findByID","createAccessPromise","access","accessLevel","disableWhere","operation","policiesObj","mutablePolicies","then","doc","accessResult","permission","executeFieldPolicies","entityPermission","Promise","all","map","field","name","blocks","block","tabs","tab","reduce","priorOperation","entityAccessPromise","resolve"],"mappings":"AAOA,SAASA,UAAU,QAAQ,4BAA2B;AAwBtD,OAAO,eAAeC,kBAAkCC,IAAO;IAC7D,MAAM,EAAEC,EAAE,EAAEC,IAAI,EAAEC,MAAM,EAAEC,UAAU,EAAEC,GAAG,EAAE,GAAGL;IAC9C,M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AAM6C;QAEN,MAAMb,qBAAqB;YACzBC,kBAAkBhC,QAAQ,CAACwB,UAAU,CAACM,UAAU;YAChD7B,QAAQT,OAAOS,MAAM;YACrBuB;YACAC,aAAazB;QACf;IACF,GAAGiC,QAAQY,OAAO;IAElB,OAAO7C;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getEntityPolicies.ts"],"sourcesContent":["import type { CollectionPermission, GlobalPermission } from '../auth/types.js'\nimport type { SanitizedCollectionConfig, TypeWithID } from '../collections/config/types.js'\nimport type { Access } from '../config/types.js'\nimport type { Field, FieldAccess } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\nimport type { AllOperations, Document, PayloadRequest, Where } from '../types/index.js'\n\nimport { combineQueries } from '../database/combineQueries.js'\nimport { tabHasName } from '../fields/config/types.js'\n\ntype Args = {\n entity: SanitizedCollectionConfig | SanitizedGlobalConfig\n id?: number | string\n operations: AllOperations[]\n req: PayloadRequest\n type: 'collection' | 'global'\n}\n\ntype ReturnType<T extends Args> = T['type'] extends 'global'\n ? GlobalPermission\n : CollectionPermission\n\ntype CreateAccessPromise = (args: {\n access: Access | FieldAccess\n accessLevel: 'entity' | 'field'\n disableWhere?: boolean\n operation: AllOperations\n policiesObj: {\n [key: string]: any\n }\n}) => Promise<void>\n\nexport async function getEntityPolicies<T extends Args>(args: T): Promise<ReturnType<T>> {\n const { id, type, entity, operations, req } = args\n const { data, locale, payload, user } = req\n const isLoggedIn = !!user\n\n const policies = {\n fields: {},\n } as ReturnType<T>\n\n let docBeingAccessed\n\n async function getEntityDoc({ where }: { where?: Where } = {}): Promise<Document & TypeWithID> {\n if (entity.slug) {\n if (type === 'global') {\n return payload.findGlobal({\n slug: entity.slug,\n fallbackLocale: null,\n locale,\n overrideAccess: true,\n req,\n })\n }\n\n if (type === 'collection' && id) {\n if (typeof where === 'object') {\n const paginatedRes = await payload.find({\n collection: entity.slug,\n depth: 0,\n fallbackLocale: null,\n limit: 1,\n locale,\n overrideAccess: true,\n pagination: false,\n req,\n where: combineQueries(where, { id: { equals: id } }),\n })\n\n return paginatedRes?.docs?.[0] || undefined\n }\n\n return payload.findByID({\n id,\n collection: entity.slug,\n depth: 0,\n fallbackLocale: null,\n locale,\n overrideAccess: true,\n req,\n })\n }\n }\n\n return undefined\n }\n\n const createAccessPromise: CreateAccessPromise = async ({\n access,\n accessLevel,\n disableWhere = false,\n operation,\n policiesObj,\n }) => {\n const mutablePolicies = policiesObj\n\n if (accessLevel === 'field' && docBeingAccessed === undefined) {\n // assign docBeingAccessed first as the promise to avoid multiple calls to getEntityDoc\n docBeingAccessed = getEntityDoc().then((doc) => {\n docBeingAccessed = doc\n })\n }\n // awaiting the promise to ensure docBeingAccessed is assigned before it is used\n await docBeingAccessed\n\n // https://payloadcms.slack.com/archives/C048Z9C2BEX/p1702054928343769\n const accessResult = await access({ id, data, doc: docBeingAccessed, req })\n\n if (typeof accessResult === 'object' && !disableWhere) {\n mutablePolicies[operation] = {\n permission:\n id || type === 'global' ? !!(await getEntityDoc({ where: accessResult })) : true,\n where: accessResult,\n }\n } else if (mutablePolicies[operation]?.permission !== false) {\n mutablePolicies[operation] = {\n permission: !!accessResult,\n }\n }\n }\n\n const executeFieldPolicies = async ({\n entityPermission,\n fields,\n operation,\n policiesObj,\n }: {\n entityPermission\n fields: Field[]\n operation: AllOperations\n policiesObj\n }) => {\n const mutablePolicies = policiesObj.fields\n\n await Promise.all(\n fields.map(async (field) => {\n if ('name' in field && field.name) {\n if (!mutablePolicies[field.name]) {\n mutablePolicies[field.name] = {}\n }\n\n if ('access' in field && field.access && typeof field.access[operation] === 'function') {\n await createAccessPromise({\n access: field.access[operation],\n accessLevel: 'field',\n disableWhere: true,\n operation,\n policiesObj: mutablePolicies[field.name],\n })\n } else {\n mutablePolicies[field.name][operation] = {\n permission: policiesObj[operation]?.permission,\n }\n }\n\n if ('fields' in field && field.fields) {\n if (!mutablePolicies[field.name].fields) {\n mutablePolicies[field.name].fields = {}\n }\n\n await executeFieldPolicies({\n entityPermission,\n fields: field.fields,\n operation,\n policiesObj: mutablePolicies[field.name],\n })\n }\n\n if ('blocks' in field && field?.blocks) {\n if (!mutablePolicies[field.name]?.blocks) {\n mutablePolicies[field.name].blocks = {}\n }\n\n await Promise.all(\n field.blocks.map(async (block) => {\n if (!mutablePolicies[field.name].blocks?.[block.slug]) {\n mutablePolicies[field.name].blocks[block.slug] = {\n fields: {},\n [operation]: { permission: entityPermission },\n }\n } else if (!mutablePolicies[field.name].blocks[block.slug][operation]) {\n mutablePolicies[field.name].blocks[block.slug][operation] = {\n permission: entityPermission,\n }\n }\n\n await executeFieldPolicies({\n entityPermission,\n fields: block.fields,\n operation,\n policiesObj: mutablePolicies[field.name].blocks[block.slug],\n })\n }),\n )\n }\n } else if ('fields' in field && field.fields) {\n await executeFieldPolicies({\n entityPermission,\n fields: field.fields,\n operation,\n policiesObj,\n })\n } else if (field.type === 'tabs') {\n await Promise.all(\n field.tabs.map(async (tab) => {\n if (tabHasName(tab)) {\n if (!mutablePolicies[tab.name]) {\n mutablePolicies[tab.name] = {\n fields: {},\n [operation]: { permission: entityPermission },\n }\n } else if (!mutablePolicies[tab.name][operation]) {\n mutablePolicies[tab.name][operation] = { permission: entityPermission }\n }\n await executeFieldPolicies({\n entityPermission,\n fields: tab.fields,\n operation,\n policiesObj: mutablePolicies[tab.name],\n })\n } else {\n await executeFieldPolicies({\n entityPermission,\n fields: tab.fields,\n operation,\n policiesObj,\n })\n }\n }),\n )\n }\n }),\n )\n }\n\n await operations.reduce(async (priorOperation, operation) => {\n await priorOperation\n\n let entityAccessPromise: Promise<void>\n\n if (typeof entity.access[operation] === 'function') {\n entityAccessPromise = createAccessPromise({\n access: entity.access[operation],\n accessLevel: 'entity',\n operation,\n policiesObj: policies,\n })\n } else {\n policies[operation] = {\n permission: isLoggedIn,\n }\n }\n\n await entityAccessPromise\n\n await executeFieldPolicies({\n entityPermission: policies[operation].permission,\n fields: entity.fields,\n operation,\n policiesObj: policies,\n })\n }, Promise.resolve())\n\n return policies\n}\n"],"names":["combineQueries","tabHasName","getEntityPolicies","args","id","type","entity","operations","req","data","locale","payload","user","isLoggedIn","policies","fields","docBeingAccessed","getEntityDoc","where","slug","findGlobal","fallbackLocale","overrideAccess","paginatedRes","find","collection","depth","limit","pagination","equals","docs","undefined","findByID","createAccessPromise","access","accessLevel","disableWhere","operation","policiesObj","mutablePolicies","then","doc","accessResult","permission","executeFieldPolicies","entityPermission","Promise","all","map","field","name","blocks","block","tabs","tab","reduce","priorOperation","entityAccessPromise","resolve"],"mappings":"AAOA,SAASA,cAAc,QAAQ,gCAA+B;AAC9D,SAASC,UAAU,QAAQ,4BAA2B;AAwBtD,OAAO,eAAeC,kBAAkCC,IAAO;IAC7D,MAAM,EAAEC,EAAE,EAAEC,IAAI,EAAEC,MAAM,EAAEC,UAAU,EAAEC,GAAG,EAAE,GAAGL;IAC9C,MAAM,EAAEM,IAAI,EAAEC,MAAM,EAAEC,OAAO,EAAEC,IAAI,EAAE,GAAGJ;IACxC,MAAMK,aAAa,CAAC,CAACD;IAErB,MAAME,WAAW;QACfC,QAAQ,CAAC;IACX;IAEA,IAAIC;IAEJ,eAAeC,aAAa,EAAEC,KAAK,EAAqB,GAAG,CAAC,CAAC;QAC3D,IAAIZ,OAAOa,IAAI,EAAE;YACf,IAAId,SAAS,UAAU;gBACrB,OAAOM,QAAQS,UAAU,CAAC;oBACxBD,MAAMb,OAAOa,IAAI;oBACjBE,gBAAgB;oBAChBX;oBACAY,gBAAgB;oBAChBd;gBACF;YACF;YAEA,IAAIH,SAAS,gBAAgBD,IAAI;gBAC/B,IAAI,OAAOc,UAAU,UAAU;oBAC7B,MAAMK,eAAe,MAAMZ,QAAQa,IAAI,CAAC;wBACtCC,YAAYnB,OAAOa,IAAI;wBACvBO,OAAO;wBACPL,gBAAgB;wBAChBM,OAAO;wBACPjB;wBACAY,gBAAgB;wBAChBM,YAAY;wBACZpB;wBACAU,OAAOlB,eAAekB,OAAO;4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AAe,CAACe,IAAIJ,IAAI,CAAC;wBACxC;oBACF,OAAO;wBACL,MAAMN,qBAAqB;4BACzBC;4BACA9B,QAAQuC,IAAIvC,MAAM;4BAClBsB;4BACAC;wBACF;oBACF;gBACF;YAEJ;QACF;IAEJ;IAEA,MAAM/B,WAAWgD,MAAM,CAAC,OAAOC,gBAAgBnB;QAC7C,MAAMmB;QAEN,IAAIC;QAEJ,IAAI,OAAOnD,OAAO4B,MAAM,CAACG,UAAU,KAAK,YAAY;YAClDoB,sBAAsBxB,oBAAoB;gBACxCC,QAAQ5B,OAAO4B,MAAM,CAACG,UAAU;gBAChCF,aAAa;gBACbE;gBACAC,aAAaxB;YACf;QACF,OAAO;YACLA,QAAQ,CAACuB,UAAU,GAAG;gBACpBM,YAAY9B;YACd;QACF;QAEA,MAAM4C;QAEN,MAAMb,qBAAqB;YACzBC,kBAAkB/B,QAAQ,CAACuB,UAAU,CAACM,UAAU;YAChD5B,QAAQT,OAAOS,MAAM;YACrBsB;YACAC,aAAaxB;QACf;IACF,GAAGgC,QAAQY,OAAO;IAElB,OAAO5C;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appendVersionToQueryKey.d.ts","sourceRoot":"","sources":["../../../src/versions/drafts/appendVersionToQueryKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAEjD,eAAO,MAAM,uBAAuB,
|
|
1
|
+
{"version":3,"file":"appendVersionToQueryKey.d.ts","sourceRoot":"","sources":["../../../src/versions/drafts/appendVersionToQueryKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAEjD,eAAO,MAAM,uBAAuB,WAAW,KAAK,KAAQ,KAqB3D,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/versions/drafts/appendVersionToQueryKey.ts"],"sourcesContent":["import type { Where } from '../../types/index.js'\n\nexport const appendVersionToQueryKey = (query: Where): Where => {\n return Object.entries(query).reduce((res, [key, val]) => {\n if (['AND', 'and', 'OR', 'or'].includes(key) && Array.isArray(val)) {\n return {\n ...res,\n [key.toLowerCase()]: val.map((subQuery) => appendVersionToQueryKey(subQuery)),\n }\n }\n\n if (key !== 'id') {\n return {\n ...res,\n [`version.${key}`]: val,\n }\n }\n\n return {\n ...res,\n parent: val,\n }\n }, {})\n}\n"],"names":["appendVersionToQueryKey","query","Object","entries","reduce","res","key","val","includes","Array","isArray","toLowerCase","map","subQuery","parent"],"mappings":"AAEA,OAAO,MAAMA,0BAA0B,CAACC;
|
|
1
|
+
{"version":3,"sources":["../../../src/versions/drafts/appendVersionToQueryKey.ts"],"sourcesContent":["import type { Where } from '../../types/index.js'\n\nexport const appendVersionToQueryKey = (query: Where = {}): Where => {\n return Object.entries(query).reduce((res, [key, val]) => {\n if (['AND', 'and', 'OR', 'or'].includes(key) && Array.isArray(val)) {\n return {\n ...res,\n [key.toLowerCase()]: val.map((subQuery) => appendVersionToQueryKey(subQuery)),\n }\n }\n\n if (key !== 'id') {\n return {\n ...res,\n [`version.${key}`]: val,\n }\n }\n\n return {\n ...res,\n parent: val,\n }\n }, {})\n}\n"],"names":["appendVersionToQueryKey","query","Object","entries","reduce","res","key","val","includes","Array","isArray","toLowerCase","map","subQuery","parent"],"mappings":"AAEA,OAAO,MAAMA,0BAA0B,CAACC,QAAe,CAAC,CAAC;IACvD,OAAOC,OAAOC,OAAO,CAACF,OAAOG,MAAM,CAAC,CAACC,KAAK,CAACC,KAAKC,IAAI;QAClD,IAAI;YAAC;YAAO;YAAO;YAAM;SAAK,CAACC,QAAQ,CAACF,QAAQG,MAAMC,OAAO,CAACH,MAAM;YAClE,OAAO;gBACL,GAAGF,GAAG;gBACN,CAACC,IAAIK,WAAW,GAAG,EAAEJ,IAAIK,GAAG,CAAC,CAACC,WAAab,wBAAwBa;YACrE;QACF;QAEA,IAAIP,QAAQ,MAAM;YAChB,OAAO;gBACL,GAAGD,GAAG;gBACN,CAAC,CAAC,QAAQ,EAAEC,IAAI,CAAC,CAAC,EAAEC;YACtB;QACF;QAEA,OAAO;YACL,GAAGF,GAAG;YACNS,QAAQP;QACV;IACF,GAAG,CAAC;AACN,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLatestCollectionVersion.d.ts","sourceRoot":"","sources":["../../src/versions/getLatestCollectionVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAA;AAC3F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"getLatestCollectionVersion.d.ts","sourceRoot":"","sources":["../../src/versions/getLatestCollectionVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAA;AAC3F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAMhE,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,yBAAyB,CAAA;IACjC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,KAAK,EAAE,WAAW,CAAA;IAClB,GAAG,CAAC,EAAE,cAAc,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,0BAA0B,GAAU,CAAC,SAAS,UAAU,yDAOlE,IAAI,KAAG,OAAO,CAAC,CAAC,CAgClB,CAAA"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { combineQueries } from '../database/combineQueries.js';
|
|
2
|
+
import { appendVersionToQueryKey } from './drafts/appendVersionToQueryKey.js';
|
|
1
3
|
export const getLatestCollectionVersion = async ({ id, config, payload, published, query, req })=>{
|
|
2
4
|
let latestVersion;
|
|
3
5
|
const whereQuery = published ? {
|
|
@@ -34,7 +36,7 @@ export const getLatestCollectionVersion = async ({ id, config, payload, publishe
|
|
|
34
36
|
pagination: false,
|
|
35
37
|
req,
|
|
36
38
|
sort: '-updatedAt',
|
|
37
|
-
where: whereQuery
|
|
39
|
+
where: combineQueries(appendVersionToQueryKey(query.where), whereQuery)
|
|
38
40
|
});
|
|
39
41
|
[latestVersion] = docs;
|
|
40
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/versions/getLatestCollectionVersion.ts"],"sourcesContent":["import type { SanitizedCollectionConfig, TypeWithID } from '../collections/config/types.js'\nimport type { FindOneArgs } from '../database/types.js'\nimport type { Payload, PayloadRequest } from '../types/index.js'\nimport type { TypeWithVersion } from './types.js'\n\ntype Args = {\n config: SanitizedCollectionConfig\n id: number | string\n payload: Payload\n published?: boolean\n query: FindOneArgs\n req?: PayloadRequest\n}\n\nexport const getLatestCollectionVersion = async <T extends TypeWithID = any>({\n id,\n config,\n payload,\n published,\n query,\n req,\n}: Args): Promise<T> => {\n let latestVersion: TypeWithVersion<T>\n\n const whereQuery = published\n ? { and: [{ parent: { equals: id } }, { 'version._status': { equals: 'published' } }] }\n : { and: [{ parent: { equals: id } }, { latest: { equals: true } }] }\n\n if (config.versions?.drafts) {\n const { docs } = await payload.db.findVersions<T>({\n collection: config.slug,\n limit: 1,\n pagination: false,\n req,\n sort: '-updatedAt',\n where: whereQuery,\n })\n ;[latestVersion] = docs\n }\n\n if (!latestVersion) {\n if (!published) {\n const doc = await payload.db.findOne<T>({ ...query, req })\n\n return doc\n }\n\n return undefined\n }\n\n latestVersion.version.id = id\n\n return latestVersion.version\n}\n"],"names":["getLatestCollectionVersion","id","config","payload","published","query","req","latestVersion","whereQuery","and","parent","equals","latest","versions","drafts","docs","db","findVersions","collection","slug","limit","pagination","sort","where","doc","findOne","undefined","version"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/versions/getLatestCollectionVersion.ts"],"sourcesContent":["import type { SanitizedCollectionConfig, TypeWithID } from '../collections/config/types.js'\nimport type { FindOneArgs } from '../database/types.js'\nimport type { Payload, PayloadRequest } from '../types/index.js'\nimport type { TypeWithVersion } from './types.js'\n\nimport { combineQueries } from '../database/combineQueries.js'\nimport { appendVersionToQueryKey } from './drafts/appendVersionToQueryKey.js'\n\ntype Args = {\n config: SanitizedCollectionConfig\n id: number | string\n payload: Payload\n published?: boolean\n query: FindOneArgs\n req?: PayloadRequest\n}\n\nexport const getLatestCollectionVersion = async <T extends TypeWithID = any>({\n id,\n config,\n payload,\n published,\n query,\n req,\n}: Args): Promise<T> => {\n let latestVersion: TypeWithVersion<T>\n\n const whereQuery = published\n ? { and: [{ parent: { equals: id } }, { 'version._status': { equals: 'published' } }] }\n : { and: [{ parent: { equals: id } }, { latest: { equals: true } }] }\n\n if (config.versions?.drafts) {\n const { docs } = await payload.db.findVersions<T>({\n collection: config.slug,\n limit: 1,\n pagination: false,\n req,\n sort: '-updatedAt',\n where: combineQueries(appendVersionToQueryKey(query.where), whereQuery),\n })\n ;[latestVersion] = docs\n }\n\n if (!latestVersion) {\n if (!published) {\n const doc = await payload.db.findOne<T>({ ...query, req })\n\n return doc\n }\n\n return undefined\n }\n\n latestVersion.version.id = id\n\n return latestVersion.version\n}\n"],"names":["combineQueries","appendVersionToQueryKey","getLatestCollectionVersion","id","config","payload","published","query","req","latestVersion","whereQuery","and","parent","equals","latest","versions","drafts","docs","db","findVersions","collection","slug","limit","pagination","sort","where","doc","findOne","undefined","version"],"mappings":"AAKA,SAASA,cAAc,QAAQ,gCAA+B;AAC9D,SAASC,uBAAuB,QAAQ,sCAAqC;AAW7E,OAAO,MAAMC,6BAA6B,OAAmC,EAC3EC,EAAE,EACFC,MAAM,EACNC,OAAO,EACPC,SAAS,EACTC,KAAK,EACLC,GAAG,EACE;IACL,IAAIC;IAEJ,MAAMC,aAAaJ,YACf;QAAEK,KAAK;YAAC;gBAAEC,QAAQ;oBAAEC,QAAQV;gBAAG;YAAE;YAAG;gBAAE,mBAAmB;oBAAEU,QAAQ;gBAAY;YAAE;SAAE;IAAC,IACpF;QAAEF,KAAK;YAAC;gBAAEC,QAAQ;oBAAEC,QAAQV;gBAAG;YAAE;YAAG;gBAAEW,QAAQ;oBAAED,QAAQ;gBAAK;YAAE;SAAE;IAAC;IAEtE,IAAIT,OAAOW,QAAQ,EAAEC,QAAQ;QAC3B,MAAM,EAAEC,IAAI,EAAE,GAAG,MAAMZ,QAAQa,EAAE,CAACC,YAAY,CAAI;YAChDC,YAAYhB,OAAOiB,IAAI;YACvBC,OAAO;YACPC,YAAY;YACZf;YACAgB,MAAM;YACNC,OAAOzB,eAAeC,wBAAwBM,MAAMkB,KAAK,GAAGf;QAC9D;QACC,CAACD,cAAc,GAAGQ;IACrB;IAEA,IAAI,CAACR,eAAe;QAClB,IAAI,CAACH,WAAW;YACd,MAAMoB,MAAM,MAAMrB,QAAQa,EAAE,CAACS,OAAO,CAAI;gBAAE,GAAGpB,KAAK;gBAAEC;YAAI;YAExD,OAAOkB;QACT;QAEA,OAAOE;IACT;IAEAnB,cAAcoB,OAAO,CAAC1B,EAAE,GAAGA;IAE3B,OAAOM,cAAcoB,OAAO;AAC9B,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payload",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.116",
|
|
4
4
|
"description": "Node, React, Headless CMS and Application Framework built on Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"admin panel",
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"ts-essentials": "10.0.2",
|
|
96
96
|
"tsx": "4.19.1",
|
|
97
97
|
"uuid": "10.0.0",
|
|
98
|
-
"@payloadcms/translations": "3.0.0-beta.
|
|
98
|
+
"@payloadcms/translations": "3.0.0-beta.116"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
101
|
"@hyrious/esbuild-plugin-commonjs": "^0.2.4",
|