payload 3.0.0-beta.115 → 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/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"}
|
|
@@ -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,MAAME,oBAAoBP,iBACtBM,QAAQE,MAAM,EAAEC,aAAaC,KAAK,CAACC,IAAMA,EAAEC,IAAI,KAAKZ,iBAAiBa,gBACrEP,QAAQE,MAAM,EAAEM,SAASJ,KAAK,CAACK,IAAMA,EAAEH,IAAI,KAAKX,aAAaY;IAEjE,MAAMG,mBAAmBT,sBAAsB;IAE/C,IAAIU,sBAAsB,CAAC;IAE3B,IAAIjB,gBAAgB;QAClBiB,sBAAsB;YACpBC,KAAK;gBACH;oBAAE,uBAAuB;wBAAEC,QAAQnB;oBAAe;gBAAE;gBACpD;oBAAE,kBAAkB;wBAAEmB,QAAQpB;oBAAG;gBAAE;aACpC;QACH;IACF,OAAO,IAAIE,YAAY;QACrBgB,sBAAsB;YAAEhB,YAAY;gBAAEkB,QAAQlB;YAAW;QAAE;IAC7D,OAAO;QACL,MAAM,IAAImB,MAAM;IAClB;IAEA,IAAI,CAACJ,kBAAkB;QACrB;IACF;IAEA,2EAA2E;IAC3E,IAAI,CAACZ,cAAc;QACjB,MAAMiB,0BAA0BrB,iBAC5B,CAAC,iBAAiB,EAAED,GAAG,4DAA4D,CAAC,GACpF,CAAC,2BAA2B,EAAEE,WAAW,6DAA6D,CAAC;QAE3G,MAAMqB,wBAAwBnB,oBAAoBkB;QAElD,MAAME,uBAA+D,MAAMjB,QAAQkB,EAAE,CAACd,IAAI,CAAC;YACzFe,YAAY;YACZC,OAAO;YACPC,YAAY;YACZtB;YACAuB,MAAM;YACNC,OAAOZ;QACT;QAEA,sDAAsD;QACtD,MAAMa,YAAYP,sBAAsBQ,IAAI,CAAC,EAAE;QAC/C,IAAID,WAAW;YACb,MAAME,eAAe,IAAIC,KAAKH,WAAWI,WAAWC,OAAO;YAC3D,MAAMC,MAAM,IAAIH,OAAOE,OAAO;YAE9B,MAAME,eACJ,OAAO9B,sBAAsB,WAAWA,kBAAkB+B,QAAQ,GAAGpC;YAEvE,MAAMqC,6BAA6BF,eAAe;YAClD,MAAMG,gBAAgBnC,IAAIoC,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,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,OAAO;4BACL,GAAGA,KAAK;4BACRW,KAAK;mCACCX,MAAMW,GAAG,IAAI,EAAE;gCACnB;oCACEzB,IAAI;wCACF0B,QAAQ1B;oCACV;gCACF;6BACD;wBACH;oBACF;oBAEA,OAAOmB,cAAcQ,MAAM,CAAC,EAAE,IAAIC;gBACpC;gBAEA,OAAOrB,QAAQsB,QAAQ,CAAC;oBACtB7B;oBACAqB,YAAYnB,OAAOa,IAAI;oBAC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MAAM,CAAC,OAAOC,gBAAgBnB;QAC7C,MAAMmB;QAEN,IAAIC;QAEJ,IAAI,OAAOpD,OAAO6B,MAAM,CAACG,UAAU,KAAK,YAAY;YAClDoB,sBAAsBxB,oBAAoB;gBACxCC,QAAQ7B,OAAO6B,MAAM,CAACG,UAAU;gBAChCF,aAAa;gBACbE;gBACAC,aAAazB;YACf;QACF,OAAO;YACLA,QAAQ,CAACwB,UAAU,GAAG;gBACpBM,YAAY/B;YACd;QACF;QAEA,MAAM6C;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;oBA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gCACT,CAACsB,UAAU,EAAE;oCAAEM,YAAYE;gCAAiB;4BAC9C;wBACF,OAAO,IAAI,CAACN,eAAe,CAACe,IAAIJ,IAAI,CAAC,CAACb,UAAU,EAAE;4BAChDE,eAAe,CAACe,IAAIJ,IAAI,CAAC,CAACb,UAAU,GAAG;gCAAEM,YAAYE;4BAAiB;wBACxE;wBACA,MAAMD,qBAAqB;4BACzBC;4BACA9B,QAAQuC,IAAIvC,MAAM;4BAClBsB;4BACAC,aAAaC,eAAe,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",
|