payload 3.65.0-internal.5b33fe0 → 3.65.0-internal.cebb1a8
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/auth/getAccessResults.d.ts.map +1 -1
- package/dist/auth/getAccessResults.js +12 -10
- package/dist/auth/getAccessResults.js.map +1 -1
- package/dist/auth/types.d.ts +12 -10
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/collections/operations/countVersions.d.ts.map +1 -1
- package/dist/collections/operations/countVersions.js +2 -1
- package/dist/collections/operations/countVersions.js.map +1 -1
- package/dist/collections/operations/docAccess.d.ts +9 -2
- package/dist/collections/operations/docAccess.d.ts.map +1 -1
- package/dist/collections/operations/docAccess.js +8 -6
- package/dist/collections/operations/docAccess.js.map +1 -1
- package/dist/collections/operations/restoreVersion.d.ts.map +1 -1
- package/dist/collections/operations/restoreVersion.js +9 -7
- package/dist/collections/operations/restoreVersion.js.map +1 -1
- package/dist/config/types.d.ts +2 -2
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/database/queryValidation/types.d.ts.map +1 -1
- package/dist/database/queryValidation/types.js.map +1 -1
- package/dist/database/queryValidation/validateQueryPaths.d.ts.map +1 -1
- package/dist/database/queryValidation/validateQueryPaths.js.map +1 -1
- package/dist/database/queryValidation/validateSearchParams.d.ts.map +1 -1
- package/dist/database/queryValidation/validateSearchParams.js +10 -8
- package/dist/database/queryValidation/validateSearchParams.js.map +1 -1
- package/dist/exports/internal.d.ts +6 -0
- package/dist/exports/internal.d.ts.map +1 -0
- package/dist/exports/internal.js +6 -0
- package/dist/exports/internal.js.map +1 -0
- package/dist/globals/operations/docAccess.d.ts +5 -1
- package/dist/globals/operations/docAccess.d.ts.map +1 -1
- package/dist/globals/operations/docAccess.js +8 -11
- package/dist/globals/operations/docAccess.js.map +1 -1
- package/dist/index.bundled.d.ts +27 -12
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utilities/getEntityPermissions/entityDocExists.d.ts +14 -0
- package/dist/utilities/getEntityPermissions/entityDocExists.d.ts.map +1 -0
- package/dist/utilities/getEntityPermissions/entityDocExists.js +45 -0
- package/dist/utilities/getEntityPermissions/entityDocExists.js.map +1 -0
- package/dist/utilities/getEntityPermissions/getEntityPermissions.d.ts +52 -0
- package/dist/utilities/getEntityPermissions/getEntityPermissions.d.ts.map +1 -0
- package/dist/utilities/getEntityPermissions/getEntityPermissions.js +193 -0
- package/dist/utilities/getEntityPermissions/getEntityPermissions.js.map +1 -0
- package/dist/utilities/getEntityPermissions/populateFieldPermissions.d.ts +24 -0
- package/dist/utilities/getEntityPermissions/populateFieldPermissions.d.ts.map +1 -0
- package/dist/utilities/getEntityPermissions/populateFieldPermissions.js +236 -0
- package/dist/utilities/getEntityPermissions/populateFieldPermissions.js.map +1 -0
- package/dist/utilities/sanitizePermissions.d.ts +2 -0
- package/dist/utilities/sanitizePermissions.d.ts.map +1 -1
- package/dist/utilities/sanitizePermissions.js +4 -0
- package/dist/utilities/sanitizePermissions.js.map +1 -1
- package/package.json +7 -2
- package/dist/utilities/getEntityPolicies.d.ts +0 -21
- package/dist/utilities/getEntityPolicies.d.ts.map +0 -1
- package/dist/utilities/getEntityPolicies.js +0 -306
- package/dist/utilities/getEntityPolicies.js.map +0 -1
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getEntityPolicies } from '../../utilities/getEntityPolicies.js';
|
|
3
|
-
import { initTransaction } from '../../utilities/initTransaction.js';
|
|
1
|
+
import { getEntityPermissions } from '../../utilities/getEntityPermissions/getEntityPermissions.js';
|
|
4
2
|
import { killTransaction } from '../../utilities/killTransaction.js';
|
|
5
3
|
import { sanitizePermissions } from '../../utilities/sanitizePermissions.js';
|
|
6
4
|
export const docAccessOperation = async (args)=>{
|
|
7
|
-
const { globalConfig, req } = args;
|
|
5
|
+
const { data, globalConfig, req } = args;
|
|
8
6
|
const globalOperations = [
|
|
9
7
|
'read',
|
|
10
8
|
'update'
|
|
@@ -13,17 +11,16 @@ export const docAccessOperation = async (args)=>{
|
|
|
13
11
|
globalOperations.push('readVersions');
|
|
14
12
|
}
|
|
15
13
|
try {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const result = await getEntityPermissions({
|
|
15
|
+
id: undefined,
|
|
16
|
+
blockReferencesPermissions: {},
|
|
17
|
+
data,
|
|
20
18
|
entity: globalConfig,
|
|
19
|
+
entityType: 'global',
|
|
20
|
+
fetchData: true,
|
|
21
21
|
operations: globalOperations,
|
|
22
22
|
req
|
|
23
23
|
});
|
|
24
|
-
if (shouldCommit) {
|
|
25
|
-
await commitTransaction(req);
|
|
26
|
-
}
|
|
27
24
|
const sanitizedPermissions = sanitizePermissions({
|
|
28
25
|
globals: {
|
|
29
26
|
[globalConfig.slug]: result
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/globals/operations/docAccess.ts"],"sourcesContent":["import type { SanitizedGlobalPermission } from '../../auth/index.js'\nimport type { AllOperations, PayloadRequest } from '../../types/index.js'\nimport type { SanitizedGlobalConfig } from '../config/types.js'\n\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/globals/operations/docAccess.ts"],"sourcesContent":["import type { SanitizedGlobalPermission } from '../../auth/index.js'\nimport type { AllOperations, JsonObject, PayloadRequest } from '../../types/index.js'\nimport type { SanitizedGlobalConfig } from '../config/types.js'\n\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { getEntityPermissions } from '../../utilities/getEntityPermissions/getEntityPermissions.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizePermissions } from '../../utilities/sanitizePermissions.js'\n\ntype Arguments = {\n /**\n * If the document data is passed, it will be used to check access instead of fetching the document from the database.\n */\n data?: JsonObject\n globalConfig: SanitizedGlobalConfig\n req: PayloadRequest\n}\n\nexport const docAccessOperation = async (args: Arguments): Promise<SanitizedGlobalPermission> => {\n const { data, globalConfig, req } = args\n\n const globalOperations: AllOperations[] = ['read', 'update']\n\n if (globalConfig.versions) {\n globalOperations.push('readVersions')\n }\n\n try {\n const result = await getEntityPermissions({\n id: undefined,\n blockReferencesPermissions: {},\n data,\n entity: globalConfig,\n entityType: 'global',\n fetchData: true,\n operations: globalOperations,\n req,\n })\n\n const sanitizedPermissions = sanitizePermissions({\n globals: {\n [globalConfig.slug]: result,\n },\n })\n\n const globalPermissions = sanitizedPermissions?.globals?.[globalConfig.slug]\n return globalPermissions ?? { fields: {} }\n } catch (e: unknown) {\n await killTransaction(req)\n throw e\n }\n}\n"],"names":["getEntityPermissions","killTransaction","sanitizePermissions","docAccessOperation","args","data","globalConfig","req","globalOperations","versions","push","result","id","undefined","blockReferencesPermissions","entity","entityType","fetchData","operations","sanitizedPermissions","globals","slug","globalPermissions","fields","e"],"mappings":"AAKA,SAASA,oBAAoB,QAAQ,+DAA8D;AAEnG,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,mBAAmB,QAAQ,yCAAwC;AAW5E,OAAO,MAAMC,qBAAqB,OAAOC;IACvC,MAAM,EAAEC,IAAI,EAAEC,YAAY,EAAEC,GAAG,EAAE,GAAGH;IAEpC,MAAMI,mBAAoC;QAAC;QAAQ;KAAS;IAE5D,IAAIF,aAAaG,QAAQ,EAAE;QACzBD,iBAAiBE,IAAI,CAAC;IACxB;IAEA,IAAI;QACF,MAAMC,SAAS,MAAMX,qBAAqB;YACxCY,IAAIC;YACJC,4BAA4B,CAAC;YAC7BT;YACAU,QAAQT;YACRU,YAAY;YACZC,WAAW;YACXC,YAAYV;YACZD;QACF;QAEA,MAAMY,uBAAuBjB,oBAAoB;YAC/CkB,SAAS;gBACP,CAACd,aAAae,IAAI,CAAC,EAAEV;YACvB;QACF;QAEA,MAAMW,oBAAoBH,sBAAsBC,SAAS,CAACd,aAAae,IAAI,CAAC;QAC5E,OAAOC,qBAAqB;YAAEC,QAAQ,CAAC;QAAE;IAC3C,EAAE,OAAOC,GAAY;QACnB,MAAMvB,gBAAgBM;QACtB,MAAMiB;IACR;AACF,EAAC"}
|
package/dist/index.bundled.d.ts
CHANGED
|
@@ -769,16 +769,16 @@ type SanitizedBlockPermissions = {
|
|
|
769
769
|
} | true;
|
|
770
770
|
type BlocksPermissions = {
|
|
771
771
|
[blockSlug: string]: BlockPermissions;
|
|
772
|
-
}
|
|
772
|
+
};
|
|
773
773
|
type SanitizedBlocksPermissions = {
|
|
774
774
|
[blockSlug: string]: SanitizedBlockPermissions;
|
|
775
775
|
} | true;
|
|
776
776
|
type FieldPermissions = {
|
|
777
777
|
blocks?: BlocksPermissions;
|
|
778
|
-
create
|
|
778
|
+
create?: Permission;
|
|
779
779
|
fields?: FieldsPermissions;
|
|
780
|
-
read
|
|
781
|
-
update
|
|
780
|
+
read?: Permission;
|
|
781
|
+
update?: Permission;
|
|
782
782
|
};
|
|
783
783
|
type SanitizedFieldPermissions = {
|
|
784
784
|
blocks?: SanitizedBlocksPermissions;
|
|
@@ -791,12 +791,13 @@ type SanitizedFieldsPermissions = {
|
|
|
791
791
|
[fieldName: string]: SanitizedFieldPermissions;
|
|
792
792
|
} | true;
|
|
793
793
|
type CollectionPermission = {
|
|
794
|
-
create
|
|
795
|
-
delete
|
|
794
|
+
create?: Permission;
|
|
795
|
+
delete?: Permission;
|
|
796
796
|
fields: FieldsPermissions;
|
|
797
|
-
read
|
|
797
|
+
read?: Permission;
|
|
798
798
|
readVersions?: Permission;
|
|
799
|
-
|
|
799
|
+
unlock?: Permission;
|
|
800
|
+
update?: Permission;
|
|
800
801
|
};
|
|
801
802
|
type SanitizedCollectionPermission = {
|
|
802
803
|
create?: true;
|
|
@@ -804,13 +805,14 @@ type SanitizedCollectionPermission = {
|
|
|
804
805
|
fields: SanitizedFieldsPermissions;
|
|
805
806
|
read?: true;
|
|
806
807
|
readVersions?: true;
|
|
808
|
+
unlock?: true;
|
|
807
809
|
update?: true;
|
|
808
810
|
};
|
|
809
811
|
type GlobalPermission = {
|
|
810
812
|
fields: FieldsPermissions;
|
|
811
|
-
read
|
|
813
|
+
read?: Permission;
|
|
812
814
|
readVersions?: Permission;
|
|
813
|
-
update
|
|
815
|
+
update?: Permission;
|
|
814
816
|
};
|
|
815
817
|
type SanitizedGlobalPermission = {
|
|
816
818
|
fields: SanitizedFieldsPermissions;
|
|
@@ -5191,7 +5193,7 @@ type AccessArgs<TData = any> = {
|
|
|
5191
5193
|
*/
|
|
5192
5194
|
data?: TData;
|
|
5193
5195
|
/** ID of the resource being accessed */
|
|
5194
|
-
id?:
|
|
5196
|
+
id?: DefaultDocumentIDType;
|
|
5195
5197
|
/** If true, the request is for a static file */
|
|
5196
5198
|
isReadingStaticFile?: boolean;
|
|
5197
5199
|
/** The original request that requires an access check */
|
|
@@ -8825,6 +8827,8 @@ type PayloadRequestData = {
|
|
|
8825
8827
|
*
|
|
8826
8828
|
* 2. import { addDataAndFileToRequest } from 'payload'
|
|
8827
8829
|
* `await addDataAndFileToRequest(req)`
|
|
8830
|
+
*
|
|
8831
|
+
* You should not expect this object to be the document data. It is the request data.
|
|
8828
8832
|
* */
|
|
8829
8833
|
data?: JsonObject;
|
|
8830
8834
|
/** The file on the request, same rules apply as the `data` property */
|
|
@@ -11070,7 +11074,14 @@ declare const createDataloaderCacheKey: ({ collectionSlug, currentDepth, depth,
|
|
|
11070
11074
|
|
|
11071
11075
|
type Arguments$8 = {
|
|
11072
11076
|
collection: Collection;
|
|
11073
|
-
|
|
11077
|
+
/**
|
|
11078
|
+
* If the document data is passed, it will be used to check access instead of fetching the document from the database.
|
|
11079
|
+
*/
|
|
11080
|
+
data?: JsonObject;
|
|
11081
|
+
/**
|
|
11082
|
+
* When called for creating a new document, id is not provided.
|
|
11083
|
+
*/
|
|
11084
|
+
id?: number | string;
|
|
11074
11085
|
req: PayloadRequest;
|
|
11075
11086
|
};
|
|
11076
11087
|
declare function docAccessOperation$1(args: Arguments$8): Promise<SanitizedCollectionPermission>;
|
|
@@ -11662,6 +11673,10 @@ type Args$8 = {
|
|
|
11662
11673
|
declare const getFolderData: ({ collectionSlug, documentWhere, folderID: _folderID, folderWhere, req, sort, }: Args$8) => Promise<GetFolderDataResult>;
|
|
11663
11674
|
|
|
11664
11675
|
type Arguments$3 = {
|
|
11676
|
+
/**
|
|
11677
|
+
* If the document data is passed, it will be used to check access instead of fetching the document from the database.
|
|
11678
|
+
*/
|
|
11679
|
+
data?: JsonObject;
|
|
11665
11680
|
globalConfig: SanitizedGlobalConfig;
|
|
11666
11681
|
req: PayloadRequest;
|
|
11667
11682
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -79,6 +79,8 @@ type PayloadRequestData = {
|
|
|
79
79
|
*
|
|
80
80
|
* 2. import { addDataAndFileToRequest } from 'payload'
|
|
81
81
|
* `await addDataAndFileToRequest(req)`
|
|
82
|
+
*
|
|
83
|
+
* You should not expect this object to be the document data. It is the request data.
|
|
82
84
|
* */
|
|
83
85
|
data?: JsonObject;
|
|
84
86
|
/** The file on the request, same rules apply as the `data` property */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,KAAK,UAAU,MAAM,YAAY,CAAA;AACxC,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC/D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAE9B,OAAO,KAAK,EACV,sBAAsB,EACtB,UAAU,EACV,kBAAkB,EACnB,MAAM,gCAAgC,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EACV,cA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CAAC,sBAAsB,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,GAC/D,sBAAsB,CAAC,KAAK,CAAC,CAAA;AAEjC,MAAM,MAAM,yBAAyB,CACnC,KAAK,SAAS,UAAU,EACxB,OAAO,SAAS,UAAU,IACxB,OAAO,SAAS,UAAU,GAC1B,uBAAuB,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,GAC3D,kBAAkB,CAAC,KAAK,CAAC,CAAA;AAE7B,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAA;AAEzD,MAAM,MAAM,qBAAqB,GAAG;IAAE,CAAC,UAAU,EAAE,MAAM,GAAG,KAAK,CAAA;CAAE,CAAA;AAEnE,MAAM,MAAM,oBAAoB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,OAAO,CAC9D,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CACrC,GACC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA"}
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["import type { I18n, TFunction } from '@payloadcms/translations'\nimport type DataLoader from 'dataloader'\nimport type { OptionalKeys, RequiredKeys } from 'ts-essentials'\nimport type { URL } from 'url'\n\nimport type {\n DataFromCollectionSlug,\n TypeWithID,\n TypeWithTimestamps,\n} from '../collections/config/types.js'\nimport type payload from '../index.js'\nimport type {\n CollectionSlug,\n DataFromGlobalSlug,\n GlobalSlug,\n Payload,\n RequestContext,\n TypedCollectionJoins,\n TypedCollectionSelect,\n TypedFallbackLocale,\n TypedLocale,\n TypedUser,\n} from '../index.js'\nimport type { Operator } from './constants.js'\nexport type { Payload } from '../index.js'\n\nexport type CustomPayloadRequestProperties = {\n context: RequestContext\n /** The locale that should be used for a field when it is not translated to the requested locale */\n fallbackLocale?: TypedFallbackLocale\n i18n: I18n\n /**\n * The requested locale if specified\n * Only available for localized collections\n *\n * Suppressing warning below as it is a valid use case - won't be an issue if generated types exist\n */\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n locale?: 'all' | TypedLocale\n /**\n * The payload object\n */\n payload: typeof payload\n /**\n * The context in which the request is being made\n */\n payloadAPI: 'GraphQL' | 'local' | 'REST'\n /** Optimized document loader */\n payloadDataLoader: {\n /**\n * Wraps `payload.find` with a cache to deduplicate requests\n * @experimental This is may be replaced by a more robust cache strategy in future versions\n * By calling this method with the same arguments many times in one request, it will only be handled one time\n * const result = await req.payloadDataLoader.find({\n * collection,\n * req,\n * where: findWhere,\n * })\n */\n find: Payload['find']\n } & DataLoader<string, TypeWithID>\n /** Resized versions of the image that was uploaded during this request */\n payloadUploadSizes?: Record<string, Buffer>\n /** Query params on the request */\n query: Record<string, unknown>\n /** Any response headers that are required to be set when a response is sent */\n responseHeaders?: Headers\n /** The route parameters\n * @example\n * /:collection/:id -> /posts/123\n * { collection: 'posts', id: '123' }\n */\n routeParams?: Record<string, unknown>\n /** Translate function - duplicate of i18n.t */\n t: TFunction\n /**\n * Identifier for the database transaction for interactions in a single, all-or-nothing operation.\n * Can also be used to ensure consistency when multiple operations try to create a transaction concurrently on the same request.\n */\n transactionID?: number | Promise<number | string> | string\n /**\n * Used to ensure consistency when multiple operations try to create a transaction concurrently on the same request\n * @deprecated This is not used anywhere, instead `transactionID` is used for the above. Will be removed in next major version.\n */\n transactionIDPromise?: Promise<void>\n /** The signed-in user */\n user: null | TypedUser\n} & Pick<\n URL,\n 'hash' | 'host' | 'href' | 'origin' | 'pathname' | 'port' | 'protocol' | 'search' | 'searchParams'\n>\ntype PayloadRequestData = {\n /**\n * Data from the request body\n *\n * Within Payload operations, i.e. hooks, data will be there\n * BUT in custom endpoints it will not be, you will need to\n * use either:\n * 1. `const data = await req.json()`\n *\n * 2. import { addDataAndFileToRequest } from 'payload'\n * `await addDataAndFileToRequest(req)`\n * */\n data?: JsonObject\n /** The file on the request, same rules apply as the `data` property */\n file?: {\n /**\n * Context of the file when it was uploaded via client side.\n */\n clientUploadContext?: unknown\n data: Buffer\n mimetype: string\n name: string\n size: number\n tempFilePath?: string\n }\n}\nexport interface PayloadRequest\n extends CustomPayloadRequestProperties,\n Partial<Request>,\n PayloadRequestData {\n headers: Request['headers']\n}\n\nexport type { Operator }\n\n// Makes it so things like passing new Date() will error\nexport type JsonValue = JsonArray | JsonObject | unknown //Date | JsonArray | JsonObject | boolean | null | number | string // TODO: Evaluate proper, strong type for this\n\nexport type JsonArray = Array<JsonValue>\n\nexport interface JsonObject {\n [key: string]: any\n}\n\nexport type WhereField = {\n // any json-serializable value\n [key in Operator]?: JsonValue\n}\n\nexport type Where = {\n [key: string]: Where[] | WhereField\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n and?: Where[]\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n or?: Where[]\n}\n\nexport type Sort = Array<string> | string\n\ntype SerializableValue = boolean | number | object | string\nexport type DefaultValue =\n | ((args: {\n locale?: TypedLocale\n req: PayloadRequest\n user: PayloadRequest['user']\n }) => SerializableValue)\n | SerializableValue\n\n/**\n * Applies pagination for join fields for including collection relationships\n */\nexport type JoinQuery<TSlug extends CollectionSlug = string> =\n TypedCollectionJoins[TSlug] extends Record<string, string>\n ?\n | false\n | Partial<{\n [K in keyof TypedCollectionJoins[TSlug]]:\n | {\n count?: boolean\n limit?: number\n page?: number\n sort?: string\n where?: Where\n }\n | false\n }>\n : never\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Document = any\n\nexport type Operation = 'create' | 'delete' | 'read' | 'update'\nexport type VersionOperations = 'readVersions'\nexport type AuthOperations = 'unlock'\nexport type AllOperations = AuthOperations | Operation | VersionOperations\n\nexport function docHasTimestamps(doc: any): doc is TypeWithTimestamps {\n return doc?.createdAt && doc?.updatedAt\n}\n\nexport type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N // This is a commonly used trick to detect 'any'\nexport type IsAny<T> = IfAny<T, true, false>\nexport type ReplaceAny<T, DefaultType> = IsAny<T> extends true ? DefaultType : T\n\nexport type SelectIncludeType = {\n [k: string]: SelectIncludeType | true\n}\n\nexport type SelectExcludeType = {\n [k: string]: false | SelectExcludeType\n}\n\nexport type SelectMode = 'exclude' | 'include'\n\nexport type SelectType = SelectExcludeType | SelectIncludeType\n\nexport type ApplyDisableErrors<T, DisableErrors = false> = false extends DisableErrors\n ? T\n : null | T\n\nexport type TransformDataWithSelect<\n Data extends Record<string, any>,\n Select extends SelectType,\n> = Select extends never\n ? Data\n : string extends keyof Select\n ? Data\n : // START Handle types when they aren't generated\n // For example in any package in this repository outside of tests / plugins\n // This stil gives us autocomplete when using include select mode, i.e select: {title :true} returns type {title: any, id: string | number}\n string extends keyof Omit<Data, 'id'>\n ? Select extends SelectIncludeType\n ? {\n [K in Data extends TypeWithID ? 'id' | keyof Select : keyof Select]: K extends 'id'\n ? number | string\n : unknown\n }\n : Data\n : // END Handle types when they aren't generated\n // Handle include mode\n Select extends SelectIncludeType\n ? {\n [K in keyof Data as K extends keyof Select\n ? Select[K] extends object | true\n ? K\n : never\n : // select 'id' always\n K extends 'id'\n ? K\n : never]: Data[K]\n }\n : // Handle exclude mode\n {\n [K in keyof Data as K extends keyof Select\n ? Select[K] extends object | undefined\n ? K\n : never\n : K]: Data[K]\n }\n\nexport type TransformCollectionWithSelect<\n TSlug extends CollectionSlug,\n TSelect extends SelectType,\n> = TSelect extends SelectType\n ? TransformDataWithSelect<DataFromCollectionSlug<TSlug>, TSelect>\n : DataFromCollectionSlug<TSlug>\n\nexport type TransformGlobalWithSelect<\n TSlug extends GlobalSlug,\n TSelect extends SelectType,\n> = TSelect extends SelectType\n ? TransformDataWithSelect<DataFromGlobalSlug<TSlug>, TSelect>\n : DataFromGlobalSlug<TSlug>\n\nexport type PopulateType = Partial<TypedCollectionSelect>\n\nexport type ResolvedFilterOptions = { [collection: string]: Where }\n\nexport type PickPreserveOptional<T, K extends keyof T> = Partial<\n Pick<T, Extract<K, OptionalKeys<T>>>\n> &\n Pick<T, Extract<K, RequiredKeys<T>>>\n"],"names":["docHasTimestamps","doc","createdAt","updatedAt"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["import type { I18n, TFunction } from '@payloadcms/translations'\nimport type DataLoader from 'dataloader'\nimport type { OptionalKeys, RequiredKeys } from 'ts-essentials'\nimport type { URL } from 'url'\n\nimport type {\n DataFromCollectionSlug,\n TypeWithID,\n TypeWithTimestamps,\n} from '../collections/config/types.js'\nimport type payload from '../index.js'\nimport type {\n CollectionSlug,\n DataFromGlobalSlug,\n GlobalSlug,\n Payload,\n RequestContext,\n TypedCollectionJoins,\n TypedCollectionSelect,\n TypedFallbackLocale,\n TypedLocale,\n TypedUser,\n} from '../index.js'\nimport type { Operator } from './constants.js'\nexport type { Payload } from '../index.js'\n\nexport type CustomPayloadRequestProperties = {\n context: RequestContext\n /** The locale that should be used for a field when it is not translated to the requested locale */\n fallbackLocale?: TypedFallbackLocale\n i18n: I18n\n /**\n * The requested locale if specified\n * Only available for localized collections\n *\n * Suppressing warning below as it is a valid use case - won't be an issue if generated types exist\n */\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n locale?: 'all' | TypedLocale\n /**\n * The payload object\n */\n payload: typeof payload\n /**\n * The context in which the request is being made\n */\n payloadAPI: 'GraphQL' | 'local' | 'REST'\n /** Optimized document loader */\n payloadDataLoader: {\n /**\n * Wraps `payload.find` with a cache to deduplicate requests\n * @experimental This is may be replaced by a more robust cache strategy in future versions\n * By calling this method with the same arguments many times in one request, it will only be handled one time\n * const result = await req.payloadDataLoader.find({\n * collection,\n * req,\n * where: findWhere,\n * })\n */\n find: Payload['find']\n } & DataLoader<string, TypeWithID>\n /** Resized versions of the image that was uploaded during this request */\n payloadUploadSizes?: Record<string, Buffer>\n /** Query params on the request */\n query: Record<string, unknown>\n /** Any response headers that are required to be set when a response is sent */\n responseHeaders?: Headers\n /** The route parameters\n * @example\n * /:collection/:id -> /posts/123\n * { collection: 'posts', id: '123' }\n */\n routeParams?: Record<string, unknown>\n /** Translate function - duplicate of i18n.t */\n t: TFunction\n /**\n * Identifier for the database transaction for interactions in a single, all-or-nothing operation.\n * Can also be used to ensure consistency when multiple operations try to create a transaction concurrently on the same request.\n */\n transactionID?: number | Promise<number | string> | string\n /**\n * Used to ensure consistency when multiple operations try to create a transaction concurrently on the same request\n * @deprecated This is not used anywhere, instead `transactionID` is used for the above. Will be removed in next major version.\n */\n transactionIDPromise?: Promise<void>\n /** The signed-in user */\n user: null | TypedUser\n} & Pick<\n URL,\n 'hash' | 'host' | 'href' | 'origin' | 'pathname' | 'port' | 'protocol' | 'search' | 'searchParams'\n>\ntype PayloadRequestData = {\n /**\n * Data from the request body\n *\n * Within Payload operations, i.e. hooks, data will be there\n * BUT in custom endpoints it will not be, you will need to\n * use either:\n * 1. `const data = await req.json()`\n *\n * 2. import { addDataAndFileToRequest } from 'payload'\n * `await addDataAndFileToRequest(req)`\n *\n * You should not expect this object to be the document data. It is the request data.\n * */\n data?: JsonObject\n /** The file on the request, same rules apply as the `data` property */\n file?: {\n /**\n * Context of the file when it was uploaded via client side.\n */\n clientUploadContext?: unknown\n data: Buffer\n mimetype: string\n name: string\n size: number\n tempFilePath?: string\n }\n}\nexport interface PayloadRequest\n extends CustomPayloadRequestProperties,\n Partial<Request>,\n PayloadRequestData {\n headers: Request['headers']\n}\n\nexport type { Operator }\n\n// Makes it so things like passing new Date() will error\nexport type JsonValue = JsonArray | JsonObject | unknown //Date | JsonArray | JsonObject | boolean | null | number | string // TODO: Evaluate proper, strong type for this\n\nexport type JsonArray = Array<JsonValue>\n\nexport interface JsonObject {\n [key: string]: any\n}\n\nexport type WhereField = {\n // any json-serializable value\n [key in Operator]?: JsonValue\n}\n\nexport type Where = {\n [key: string]: Where[] | WhereField\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n and?: Where[]\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n or?: Where[]\n}\n\nexport type Sort = Array<string> | string\n\ntype SerializableValue = boolean | number | object | string\nexport type DefaultValue =\n | ((args: {\n locale?: TypedLocale\n req: PayloadRequest\n user: PayloadRequest['user']\n }) => SerializableValue)\n | SerializableValue\n\n/**\n * Applies pagination for join fields for including collection relationships\n */\nexport type JoinQuery<TSlug extends CollectionSlug = string> =\n TypedCollectionJoins[TSlug] extends Record<string, string>\n ?\n | false\n | Partial<{\n [K in keyof TypedCollectionJoins[TSlug]]:\n | {\n count?: boolean\n limit?: number\n page?: number\n sort?: string\n where?: Where\n }\n | false\n }>\n : never\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Document = any\n\nexport type Operation = 'create' | 'delete' | 'read' | 'update'\nexport type VersionOperations = 'readVersions'\nexport type AuthOperations = 'unlock'\nexport type AllOperations = AuthOperations | Operation | VersionOperations\n\nexport function docHasTimestamps(doc: any): doc is TypeWithTimestamps {\n return doc?.createdAt && doc?.updatedAt\n}\n\nexport type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N // This is a commonly used trick to detect 'any'\nexport type IsAny<T> = IfAny<T, true, false>\nexport type ReplaceAny<T, DefaultType> = IsAny<T> extends true ? DefaultType : T\n\nexport type SelectIncludeType = {\n [k: string]: SelectIncludeType | true\n}\n\nexport type SelectExcludeType = {\n [k: string]: false | SelectExcludeType\n}\n\nexport type SelectMode = 'exclude' | 'include'\n\nexport type SelectType = SelectExcludeType | SelectIncludeType\n\nexport type ApplyDisableErrors<T, DisableErrors = false> = false extends DisableErrors\n ? T\n : null | T\n\nexport type TransformDataWithSelect<\n Data extends Record<string, any>,\n Select extends SelectType,\n> = Select extends never\n ? Data\n : string extends keyof Select\n ? Data\n : // START Handle types when they aren't generated\n // For example in any package in this repository outside of tests / plugins\n // This stil gives us autocomplete when using include select mode, i.e select: {title :true} returns type {title: any, id: string | number}\n string extends keyof Omit<Data, 'id'>\n ? Select extends SelectIncludeType\n ? {\n [K in Data extends TypeWithID ? 'id' | keyof Select : keyof Select]: K extends 'id'\n ? number | string\n : unknown\n }\n : Data\n : // END Handle types when they aren't generated\n // Handle include mode\n Select extends SelectIncludeType\n ? {\n [K in keyof Data as K extends keyof Select\n ? Select[K] extends object | true\n ? K\n : never\n : // select 'id' always\n K extends 'id'\n ? K\n : never]: Data[K]\n }\n : // Handle exclude mode\n {\n [K in keyof Data as K extends keyof Select\n ? Select[K] extends object | undefined\n ? K\n : never\n : K]: Data[K]\n }\n\nexport type TransformCollectionWithSelect<\n TSlug extends CollectionSlug,\n TSelect extends SelectType,\n> = TSelect extends SelectType\n ? TransformDataWithSelect<DataFromCollectionSlug<TSlug>, TSelect>\n : DataFromCollectionSlug<TSlug>\n\nexport type TransformGlobalWithSelect<\n TSlug extends GlobalSlug,\n TSelect extends SelectType,\n> = TSelect extends SelectType\n ? TransformDataWithSelect<DataFromGlobalSlug<TSlug>, TSelect>\n : DataFromGlobalSlug<TSlug>\n\nexport type PopulateType = Partial<TypedCollectionSelect>\n\nexport type ResolvedFilterOptions = { [collection: string]: Where }\n\nexport type PickPreserveOptional<T, K extends keyof T> = Partial<\n Pick<T, Extract<K, OptionalKeys<T>>>\n> &\n Pick<T, Extract<K, RequiredKeys<T>>>\n"],"names":["docHasTimestamps","doc","createdAt","updatedAt"],"mappings":"AA6LA,OAAO,SAASA,iBAAiBC,GAAQ;IACvC,OAAOA,KAAKC,aAAaD,KAAKE;AAChC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type AllOperations, type DefaultDocumentIDType, type PayloadRequest, type Where } from '../../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Returns whether or not the entity doc exists based on the where query.
|
|
4
|
+
*/
|
|
5
|
+
export declare function entityDocExists({ id, slug, entityType, locale, operation, req, where, }: {
|
|
6
|
+
entityType: 'collection' | 'global';
|
|
7
|
+
id?: DefaultDocumentIDType;
|
|
8
|
+
locale?: string;
|
|
9
|
+
operation?: AllOperations;
|
|
10
|
+
req: PayloadRequest;
|
|
11
|
+
slug: string;
|
|
12
|
+
where: Where;
|
|
13
|
+
}): Promise<boolean>;
|
|
14
|
+
//# sourceMappingURL=entityDocExists.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entityDocExists.d.ts","sourceRoot":"","sources":["../../../src/utilities/getEntityPermissions/entityDocExists.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACnB,KAAK,KAAK,EACX,MAAM,gBAAgB,CAAA;AAEvB;;GAEG;AACH,wBAAsB,eAAe,CAAC,EACpC,EAAE,EACF,IAAI,EACJ,UAAU,EACV,MAAM,EACN,SAAS,EACT,GAAG,EACH,KAAK,GACN,EAAE;IACD,UAAU,EAAE,YAAY,GAAG,QAAQ,CAAA;IACnC,EAAE,CAAC,EAAE,qBAAqB,CAAA;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,aAAa,CAAA;IACzB,GAAG,EAAE,cAAc,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,KAAK,CAAA;CACb,GAAG,OAAO,CAAC,OAAO,CAAC,CAqCnB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { combineQueries } from '../../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Returns whether or not the entity doc exists based on the where query.
|
|
4
|
+
*/ export async function entityDocExists({ id, slug, entityType, locale, operation, req, where }) {
|
|
5
|
+
if (entityType === 'global') {
|
|
6
|
+
const global = await req.payload.db.findGlobal({
|
|
7
|
+
slug,
|
|
8
|
+
locale,
|
|
9
|
+
req,
|
|
10
|
+
select: {},
|
|
11
|
+
where
|
|
12
|
+
});
|
|
13
|
+
const hasGlobalDoc = Boolean(global && Object.keys(global).length > 0);
|
|
14
|
+
return hasGlobalDoc;
|
|
15
|
+
}
|
|
16
|
+
if (entityType === 'collection' && id) {
|
|
17
|
+
if (operation === 'readVersions') {
|
|
18
|
+
const count = await req.payload.db.countVersions({
|
|
19
|
+
collection: slug,
|
|
20
|
+
locale,
|
|
21
|
+
req,
|
|
22
|
+
where: combineQueries(where, {
|
|
23
|
+
parent: {
|
|
24
|
+
equals: id
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
});
|
|
28
|
+
return count.totalDocs > 0;
|
|
29
|
+
}
|
|
30
|
+
const count = await req.payload.db.count({
|
|
31
|
+
collection: slug,
|
|
32
|
+
locale,
|
|
33
|
+
req,
|
|
34
|
+
where: combineQueries(where, {
|
|
35
|
+
id: {
|
|
36
|
+
equals: id
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
return count.totalDocs > 0;
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=entityDocExists.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utilities/getEntityPermissions/entityDocExists.ts"],"sourcesContent":["import {\n type AllOperations,\n combineQueries,\n type DefaultDocumentIDType,\n type PayloadRequest,\n type Where,\n} from '../../index.js'\n\n/**\n * Returns whether or not the entity doc exists based on the where query.\n */\nexport async function entityDocExists({\n id,\n slug,\n entityType,\n locale,\n operation,\n req,\n where,\n}: {\n entityType: 'collection' | 'global'\n id?: DefaultDocumentIDType\n locale?: string\n operation?: AllOperations\n req: PayloadRequest\n slug: string\n where: Where\n}): Promise<boolean> {\n if (entityType === 'global') {\n const global = await req.payload.db.findGlobal({\n slug,\n locale,\n req,\n select: {},\n where,\n })\n\n const hasGlobalDoc = Boolean(global && Object.keys(global).length > 0)\n\n return hasGlobalDoc\n }\n\n if (entityType === 'collection' && id) {\n if (operation === 'readVersions') {\n const count = await req.payload.db.countVersions({\n collection: slug,\n locale,\n req,\n where: combineQueries(where, { parent: { equals: id } }),\n })\n return count.totalDocs > 0\n }\n\n const count = await req.payload.db.count({\n collection: slug,\n locale,\n req,\n where: combineQueries(where, { id: { equals: id } }),\n })\n\n return count.totalDocs > 0\n }\n\n return false\n}\n"],"names":["combineQueries","entityDocExists","id","slug","entityType","locale","operation","req","where","global","payload","db","findGlobal","select","hasGlobalDoc","Boolean","Object","keys","length","count","countVersions","collection","parent","equals","totalDocs"],"mappings":"AAAA,SAEEA,cAAc,QAIT,iBAAgB;AAEvB;;CAEC,GACD,OAAO,eAAeC,gBAAgB,EACpCC,EAAE,EACFC,IAAI,EACJC,UAAU,EACVC,MAAM,EACNC,SAAS,EACTC,GAAG,EACHC,KAAK,EASN;IACC,IAAIJ,eAAe,UAAU;QAC3B,MAAMK,SAAS,MAAMF,IAAIG,OAAO,CAACC,EAAE,CAACC,UAAU,CAAC;YAC7CT;YACAE;YACAE;YACAM,QAAQ,CAAC;YACTL;QACF;QAEA,MAAMM,eAAeC,QAAQN,UAAUO,OAAOC,IAAI,CAACR,QAAQS,MAAM,GAAG;QAEpE,OAAOJ;IACT;IAEA,IAAIV,eAAe,gBAAgBF,IAAI;QACrC,IAAII,cAAc,gBAAgB;YAChC,MAAMa,QAAQ,MAAMZ,IAAIG,OAAO,CAACC,EAAE,CAACS,aAAa,CAAC;gBAC/CC,YAAYlB;gBACZE;gBACAE;gBACAC,OAAOR,eAAeQ,OAAO;oBAAEc,QAAQ;wBAAEC,QAAQrB;oBAAG;gBAAE;YACxD;YACA,OAAOiB,MAAMK,SAAS,GAAG;QAC3B;QAEA,MAAML,QAAQ,MAAMZ,IAAIG,OAAO,CAACC,EAAE,CAACQ,KAAK,CAAC;YACvCE,YAAYlB;YACZE;YACAE;YACAC,OAAOR,eAAeQ,OAAO;gBAAEN,IAAI;oBAAEqB,QAAQrB;gBAAG;YAAE;QACpD;QAEA,OAAOiB,MAAMK,SAAS,GAAG;IAC3B;IAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { BlockPermissions, CollectionPermission, GlobalPermission } from '../../auth/types.js';
|
|
2
|
+
import type { SanitizedCollectionConfig, TypeWithID } from '../../collections/config/types.js';
|
|
3
|
+
import type { SanitizedGlobalConfig } from '../../globals/config/types.js';
|
|
4
|
+
import type { BlockSlug, DefaultDocumentIDType } from '../../index.js';
|
|
5
|
+
import type { AllOperations, JsonObject, PayloadRequest } from '../../types/index.js';
|
|
6
|
+
export type BlockReferencesPermissions = Record<BlockSlug, BlockPermissions | Promise<BlockPermissions>>;
|
|
7
|
+
export type EntityDoc = JsonObject | TypeWithID;
|
|
8
|
+
type ReturnType<TEntityType extends 'collection' | 'global'> = TEntityType extends 'global' ? GlobalPermission : CollectionPermission;
|
|
9
|
+
type Args<TEntityType extends 'collection' | 'global'> = {
|
|
10
|
+
blockReferencesPermissions: BlockReferencesPermissions;
|
|
11
|
+
/**
|
|
12
|
+
* If the document data is passed, it will be used to check access instead of fetching the document from the database.
|
|
13
|
+
*/
|
|
14
|
+
data?: JsonObject;
|
|
15
|
+
entity: TEntityType extends 'collection' ? SanitizedCollectionConfig : SanitizedGlobalConfig;
|
|
16
|
+
entityType: TEntityType;
|
|
17
|
+
/**
|
|
18
|
+
* Operations to check access for
|
|
19
|
+
*/
|
|
20
|
+
operations: AllOperations[];
|
|
21
|
+
req: PayloadRequest;
|
|
22
|
+
} & ({
|
|
23
|
+
fetchData: false;
|
|
24
|
+
id?: never;
|
|
25
|
+
} | {
|
|
26
|
+
fetchData: true;
|
|
27
|
+
id: TEntityType extends 'collection' ? DefaultDocumentIDType : undefined;
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Build up permissions object for an entity (collection or global).
|
|
31
|
+
* This is not run during any update and reflects the current state of the entity data => doc and data is the same.
|
|
32
|
+
*
|
|
33
|
+
* When `fetchData` is false:
|
|
34
|
+
* - returned `Where` are not run and evaluated as "does not have permission".
|
|
35
|
+
* - If req.data is passed: `data` and `doc` is passed to access functions.
|
|
36
|
+
* - If req.data is not passed: `data` and `doc` is not passed to access functions.
|
|
37
|
+
*
|
|
38
|
+
* When `fetchData` is true:
|
|
39
|
+
* - `Where` are run and evaluated as "has permission" or "does not have permission".
|
|
40
|
+
* - `data` and `doc` are always passed to access functions.
|
|
41
|
+
* - Error is thrown if `entityType` is 'collection' and `id` is not passed.
|
|
42
|
+
*
|
|
43
|
+
* In both cases:
|
|
44
|
+
* We cannot include siblingData or blockData here, as we do not have siblingData available once we reach block or array
|
|
45
|
+
* rows, as we're calculating schema permissions, which do not include individual rows.
|
|
46
|
+
* For consistency, it's thus better to never include the siblingData and blockData
|
|
47
|
+
*
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
export declare function getEntityPermissions<TEntityType extends 'collection' | 'global'>(args: Args<TEntityType>): Promise<ReturnType<TEntityType>>;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=getEntityPermissions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getEntityPermissions.d.ts","sourceRoot":"","sources":["../../../src/utilities/getEntityPermissions/getEntityPermissions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,oBAAoB,EAEpB,gBAAgB,EAEjB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,yBAAyB,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAC9F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AAC1E,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,cAAc,EAAS,MAAM,sBAAsB,CAAA;AAO5F,MAAM,MAAM,0BAA0B,GAAG,MAAM,CAC7C,SAAS,EACT,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAC7C,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,UAAU,CAAA;AAE/C,KAAK,UAAU,CAAC,WAAW,SAAS,YAAY,GAAG,QAAQ,IAAI,WAAW,SAAS,QAAQ,GACvF,gBAAgB,GAChB,oBAAoB,CAAA;AAExB,KAAK,IAAI,CAAC,WAAW,SAAS,YAAY,GAAG,QAAQ,IAAI;IACvD,0BAA0B,EAAE,0BAA0B,CAAA;IACtD;;OAEG;IACH,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB,MAAM,EAAE,WAAW,SAAS,YAAY,GAAG,yBAAyB,GAAG,qBAAqB,CAAA;IAC5F,UAAU,EAAE,WAAW,CAAA;IACvB;;OAEG;IACH,UAAU,EAAE,aAAa,EAAE,CAAA;IAC3B,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,CACA;IACE,SAAS,EAAE,KAAK,CAAA;IAChB,EAAE,CAAC,EAAE,KAAK,CAAA;CACX,GACD;IACE,SAAS,EAAE,IAAI,CAAA;IACf,EAAE,EAAE,WAAW,SAAS,YAAY,GAAG,qBAAqB,GAAG,SAAS,CAAA;CACzE,CACJ,CAAA;AAYD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,oBAAoB,CAAC,WAAW,SAAS,YAAY,GAAG,QAAQ,EACpF,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,GACtB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAwJlC"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'util';
|
|
2
|
+
import { entityDocExists } from './entityDocExists.js';
|
|
3
|
+
import { populateFieldPermissions } from './populateFieldPermissions.js';
|
|
4
|
+
const topLevelCollectionPermissions = [
|
|
5
|
+
'create',
|
|
6
|
+
'delete',
|
|
7
|
+
'read',
|
|
8
|
+
'readVersions',
|
|
9
|
+
'update',
|
|
10
|
+
'unlock'
|
|
11
|
+
];
|
|
12
|
+
const topLevelGlobalPermissions = [
|
|
13
|
+
'read',
|
|
14
|
+
'readVersions',
|
|
15
|
+
'update'
|
|
16
|
+
];
|
|
17
|
+
/**
|
|
18
|
+
* Build up permissions object for an entity (collection or global).
|
|
19
|
+
* This is not run during any update and reflects the current state of the entity data => doc and data is the same.
|
|
20
|
+
*
|
|
21
|
+
* When `fetchData` is false:
|
|
22
|
+
* - returned `Where` are not run and evaluated as "does not have permission".
|
|
23
|
+
* - If req.data is passed: `data` and `doc` is passed to access functions.
|
|
24
|
+
* - If req.data is not passed: `data` and `doc` is not passed to access functions.
|
|
25
|
+
*
|
|
26
|
+
* When `fetchData` is true:
|
|
27
|
+
* - `Where` are run and evaluated as "has permission" or "does not have permission".
|
|
28
|
+
* - `data` and `doc` are always passed to access functions.
|
|
29
|
+
* - Error is thrown if `entityType` is 'collection' and `id` is not passed.
|
|
30
|
+
*
|
|
31
|
+
* In both cases:
|
|
32
|
+
* We cannot include siblingData or blockData here, as we do not have siblingData available once we reach block or array
|
|
33
|
+
* rows, as we're calculating schema permissions, which do not include individual rows.
|
|
34
|
+
* For consistency, it's thus better to never include the siblingData and blockData
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/ export async function getEntityPermissions(args) {
|
|
38
|
+
const { id, blockReferencesPermissions, data: _data, entity, entityType, fetchData, operations, req } = args;
|
|
39
|
+
const { locale: _locale, user } = req;
|
|
40
|
+
const locale = _locale ? _locale : undefined;
|
|
41
|
+
if (fetchData && entityType === 'collection' && !id) {
|
|
42
|
+
throw new Error('ID is required when fetching data for a collection');
|
|
43
|
+
}
|
|
44
|
+
const hasData = _data && Object.keys(_data).length > 0;
|
|
45
|
+
const data = hasData ? _data : fetchData ? await (async ()=>{
|
|
46
|
+
if (entityType === 'global') {
|
|
47
|
+
return req.payload.findGlobal({
|
|
48
|
+
slug: entity.slug,
|
|
49
|
+
depth: 0,
|
|
50
|
+
fallbackLocale: null,
|
|
51
|
+
locale,
|
|
52
|
+
overrideAccess: true,
|
|
53
|
+
req
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (entityType === 'collection') {
|
|
57
|
+
return req.payload.findByID({
|
|
58
|
+
id: id,
|
|
59
|
+
collection: entity.slug,
|
|
60
|
+
depth: 0,
|
|
61
|
+
fallbackLocale: null,
|
|
62
|
+
locale,
|
|
63
|
+
overrideAccess: true,
|
|
64
|
+
req,
|
|
65
|
+
trash: true
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
})() : undefined;
|
|
69
|
+
const isLoggedIn = !!user;
|
|
70
|
+
const fieldsPermissions = {};
|
|
71
|
+
const entityPermissions = {
|
|
72
|
+
fields: fieldsPermissions
|
|
73
|
+
};
|
|
74
|
+
const promises = [];
|
|
75
|
+
// Phase 1: Resolve all access functions to get where queries
|
|
76
|
+
const accessResults = [];
|
|
77
|
+
for (const _operation of operations){
|
|
78
|
+
const operation = _operation;
|
|
79
|
+
const accessFunction = entity.access[operation];
|
|
80
|
+
if (entityType === 'collection' && topLevelCollectionPermissions.includes(operation) || entityType === 'global' && topLevelGlobalPermissions.includes(operation)) {
|
|
81
|
+
if (typeof accessFunction === 'function') {
|
|
82
|
+
accessResults.push({
|
|
83
|
+
operation,
|
|
84
|
+
result: Promise.resolve(accessFunction({
|
|
85
|
+
id,
|
|
86
|
+
data,
|
|
87
|
+
req
|
|
88
|
+
}))
|
|
89
|
+
});
|
|
90
|
+
} else {
|
|
91
|
+
entityPermissions[operation] = {
|
|
92
|
+
permission: isLoggedIn
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// Await all access functions in parallel
|
|
98
|
+
const resolvedAccessResults = await Promise.all(accessResults.map(async (item)=>({
|
|
99
|
+
operation: item.operation,
|
|
100
|
+
result: await item.result
|
|
101
|
+
})));
|
|
102
|
+
// Phase 2: Process where queries with cache and resolve in parallel
|
|
103
|
+
const whereQueryCache = [];
|
|
104
|
+
const wherePromises = [];
|
|
105
|
+
for (const { operation, result: accessResult } of resolvedAccessResults){
|
|
106
|
+
if (typeof accessResult === 'object') {
|
|
107
|
+
processWhereQuery({
|
|
108
|
+
id,
|
|
109
|
+
slug: entity.slug,
|
|
110
|
+
accessResult,
|
|
111
|
+
entityPermissions,
|
|
112
|
+
entityType,
|
|
113
|
+
fetchData,
|
|
114
|
+
locale,
|
|
115
|
+
operation,
|
|
116
|
+
req,
|
|
117
|
+
wherePromises,
|
|
118
|
+
whereQueryCache
|
|
119
|
+
});
|
|
120
|
+
} else if (entityPermissions[operation]?.permission !== false) {
|
|
121
|
+
entityPermissions[operation] = {
|
|
122
|
+
permission: !!accessResult
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// Await all where query DB calls in parallel
|
|
127
|
+
await Promise.all(wherePromises);
|
|
128
|
+
populateFieldPermissions({
|
|
129
|
+
blockReferencesPermissions,
|
|
130
|
+
data,
|
|
131
|
+
fields: entity.fields,
|
|
132
|
+
operations,
|
|
133
|
+
parentPermissionsObject: entityPermissions,
|
|
134
|
+
permissionsObject: fieldsPermissions,
|
|
135
|
+
promises,
|
|
136
|
+
req
|
|
137
|
+
});
|
|
138
|
+
/**
|
|
139
|
+
* Await all promises in parallel.
|
|
140
|
+
* A promise can add more promises to the promises array (group of fields calls populateFieldPermissions again in their own promise), which will not be
|
|
141
|
+
* awaited in the first run.
|
|
142
|
+
* This is why we need to loop again to process the new promises, until there are no more promises left.
|
|
143
|
+
*/ let iterations = 0;
|
|
144
|
+
while(promises.length > 0){
|
|
145
|
+
const currentPromises = promises.splice(0, promises.length);
|
|
146
|
+
await Promise.all(currentPromises);
|
|
147
|
+
iterations++;
|
|
148
|
+
if (iterations >= 100) {
|
|
149
|
+
throw new Error('Infinite getEntityPermissions promise loop detected.');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return entityPermissions;
|
|
153
|
+
}
|
|
154
|
+
const processWhereQuery = ({ id, slug, accessResult, entityPermissions, entityType, fetchData, locale, operation, req, wherePromises, whereQueryCache })=>{
|
|
155
|
+
if (fetchData) {
|
|
156
|
+
// Check cache for identical where query using deep comparison
|
|
157
|
+
let cached = whereQueryCache.find((entry)=>isDeepStrictEqual(entry.where, accessResult));
|
|
158
|
+
if (!cached) {
|
|
159
|
+
// Cache miss - start DB query (don't await)
|
|
160
|
+
cached = {
|
|
161
|
+
result: entityDocExists({
|
|
162
|
+
id,
|
|
163
|
+
slug,
|
|
164
|
+
entityType,
|
|
165
|
+
locale,
|
|
166
|
+
operation,
|
|
167
|
+
req,
|
|
168
|
+
where: accessResult
|
|
169
|
+
}),
|
|
170
|
+
where: accessResult
|
|
171
|
+
};
|
|
172
|
+
whereQueryCache.push(cached);
|
|
173
|
+
}
|
|
174
|
+
// Defer resolution to Promise.all (cache hits reuse same promise)
|
|
175
|
+
wherePromises.push(cached.result.then((hasPermission)=>{
|
|
176
|
+
entityPermissions[operation] = {
|
|
177
|
+
permission: hasPermission,
|
|
178
|
+
where: accessResult
|
|
179
|
+
};
|
|
180
|
+
}));
|
|
181
|
+
} else {
|
|
182
|
+
// TODO: 4.0: Investigate defaulting to `false` here, if where query is returned but ignored as we don't
|
|
183
|
+
// have the document data available. This seems more secure.
|
|
184
|
+
// Alternatively, we could set permission to a third state, like 'unknown'.
|
|
185
|
+
// Even after calling sanitizePermissions, the permissions will still be true if the where query is returned but ignored as we don't have the document data available.
|
|
186
|
+
entityPermissions[operation] = {
|
|
187
|
+
permission: true,
|
|
188
|
+
where: accessResult
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
//# sourceMappingURL=getEntityPermissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utilities/getEntityPermissions/getEntityPermissions.ts"],"sourcesContent":["import { isDeepStrictEqual } from 'util'\n\nimport type {\n BlockPermissions,\n CollectionPermission,\n FieldsPermissions,\n GlobalPermission,\n Permission,\n} from '../../auth/types.js'\nimport type { SanitizedCollectionConfig, TypeWithID } from '../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../globals/config/types.js'\nimport type { BlockSlug, DefaultDocumentIDType } from '../../index.js'\nimport type { AllOperations, JsonObject, PayloadRequest, Where } from '../../types/index.js'\n\nimport { entityDocExists } from './entityDocExists.js'\nimport { populateFieldPermissions } from './populateFieldPermissions.js'\n\ntype WhereQueryCache = { result: Promise<boolean>; where: Where }[]\n\nexport type BlockReferencesPermissions = Record<\n BlockSlug,\n BlockPermissions | Promise<BlockPermissions>\n>\n\nexport type EntityDoc = JsonObject | TypeWithID\n\ntype ReturnType<TEntityType extends 'collection' | 'global'> = TEntityType extends 'global'\n ? GlobalPermission\n : CollectionPermission\n\ntype Args<TEntityType extends 'collection' | 'global'> = {\n blockReferencesPermissions: BlockReferencesPermissions\n /**\n * If the document data is passed, it will be used to check access instead of fetching the document from the database.\n */\n data?: JsonObject\n entity: TEntityType extends 'collection' ? SanitizedCollectionConfig : SanitizedGlobalConfig\n entityType: TEntityType\n /**\n * Operations to check access for\n */\n operations: AllOperations[]\n req: PayloadRequest\n} & (\n | {\n fetchData: false\n id?: never\n }\n | {\n fetchData: true\n id: TEntityType extends 'collection' ? DefaultDocumentIDType : undefined\n }\n)\n\nconst topLevelCollectionPermissions = [\n 'create',\n 'delete',\n 'read',\n 'readVersions',\n 'update',\n 'unlock',\n]\nconst topLevelGlobalPermissions = ['read', 'readVersions', 'update']\n\n/**\n * Build up permissions object for an entity (collection or global).\n * This is not run during any update and reflects the current state of the entity data => doc and data is the same.\n *\n * When `fetchData` is false:\n * - returned `Where` are not run and evaluated as \"does not have permission\".\n * - If req.data is passed: `data` and `doc` is passed to access functions.\n * - If req.data is not passed: `data` and `doc` is not passed to access functions.\n *\n * When `fetchData` is true:\n * - `Where` are run and evaluated as \"has permission\" or \"does not have permission\".\n * - `data` and `doc` are always passed to access functions.\n * - Error is thrown if `entityType` is 'collection' and `id` is not passed.\n *\n * In both cases:\n * We cannot include siblingData or blockData here, as we do not have siblingData available once we reach block or array\n * rows, as we're calculating schema permissions, which do not include individual rows.\n * For consistency, it's thus better to never include the siblingData and blockData\n *\n * @internal\n */\nexport async function getEntityPermissions<TEntityType extends 'collection' | 'global'>(\n args: Args<TEntityType>,\n): Promise<ReturnType<TEntityType>> {\n const {\n id,\n blockReferencesPermissions,\n data: _data,\n entity,\n entityType,\n fetchData,\n operations,\n req,\n } = args\n const { locale: _locale, user } = req\n\n const locale = _locale ? _locale : undefined\n\n if (fetchData && entityType === 'collection' && !id) {\n throw new Error('ID is required when fetching data for a collection')\n }\n\n const hasData = _data && Object.keys(_data).length > 0\n const data: JsonObject | undefined = hasData\n ? _data\n : fetchData\n ? await (async () => {\n if (entityType === 'global') {\n return req.payload.findGlobal({\n slug: entity.slug,\n depth: 0,\n fallbackLocale: null,\n locale,\n overrideAccess: true,\n req,\n })\n }\n\n if (entityType === 'collection') {\n return req.payload.findByID({\n id: id!,\n collection: entity.slug,\n depth: 0,\n fallbackLocale: null,\n locale,\n overrideAccess: true,\n req,\n trash: true,\n })\n }\n })()\n : undefined\n\n const isLoggedIn = !!user\n\n const fieldsPermissions: FieldsPermissions = {}\n\n const entityPermissions: ReturnType<TEntityType> = {\n fields: fieldsPermissions,\n } as ReturnType<TEntityType>\n\n const promises: Promise<void>[] = []\n\n // Phase 1: Resolve all access functions to get where queries\n const accessResults: {\n operation: keyof typeof entity.access\n result: Promise<boolean | Where>\n }[] = []\n\n for (const _operation of operations) {\n const operation = _operation as keyof typeof entity.access\n const accessFunction = entity.access[operation]\n\n if (\n (entityType === 'collection' && topLevelCollectionPermissions.includes(operation)) ||\n (entityType === 'global' && topLevelGlobalPermissions.includes(operation))\n ) {\n if (typeof accessFunction === 'function') {\n accessResults.push({\n operation,\n result: Promise.resolve(accessFunction({ id, data, req })) as Promise<boolean | Where>,\n })\n } else {\n entityPermissions[operation] = {\n permission: isLoggedIn,\n }\n }\n }\n }\n\n // Await all access functions in parallel\n const resolvedAccessResults = await Promise.all(\n accessResults.map(async (item) => ({\n operation: item.operation,\n result: await item.result,\n })),\n )\n\n // Phase 2: Process where queries with cache and resolve in parallel\n const whereQueryCache: WhereQueryCache = []\n const wherePromises: Promise<void>[] = []\n\n for (const { operation, result: accessResult } of resolvedAccessResults) {\n if (typeof accessResult === 'object') {\n processWhereQuery({\n id,\n slug: entity.slug,\n accessResult,\n entityPermissions,\n entityType,\n fetchData,\n locale,\n operation,\n req,\n wherePromises,\n whereQueryCache,\n })\n } else if (entityPermissions[operation]?.permission !== false) {\n entityPermissions[operation] = { permission: !!accessResult }\n }\n }\n\n // Await all where query DB calls in parallel\n await Promise.all(wherePromises)\n\n populateFieldPermissions({\n blockReferencesPermissions,\n data,\n fields: entity.fields,\n operations,\n parentPermissionsObject: entityPermissions,\n permissionsObject: fieldsPermissions,\n promises,\n req,\n })\n\n /**\n * Await all promises in parallel.\n * A promise can add more promises to the promises array (group of fields calls populateFieldPermissions again in their own promise), which will not be\n * awaited in the first run.\n * This is why we need to loop again to process the new promises, until there are no more promises left.\n */\n let iterations = 0\n while (promises.length > 0) {\n const currentPromises = promises.splice(0, promises.length)\n\n await Promise.all(currentPromises)\n\n iterations++\n if (iterations >= 100) {\n throw new Error('Infinite getEntityPermissions promise loop detected.')\n }\n }\n\n return entityPermissions\n}\n\nconst processWhereQuery = ({\n id,\n slug,\n accessResult,\n entityPermissions,\n entityType,\n fetchData,\n locale,\n operation,\n req,\n wherePromises,\n whereQueryCache,\n}: {\n accessResult: Where\n entityPermissions: CollectionPermission | GlobalPermission\n entityType: 'collection' | 'global'\n fetchData: boolean\n id?: DefaultDocumentIDType\n locale?: string\n operation: Extract<keyof (CollectionPermission | GlobalPermission), AllOperations>\n req: PayloadRequest\n slug: string\n wherePromises: Promise<void>[]\n whereQueryCache: WhereQueryCache\n}): void => {\n if (fetchData) {\n // Check cache for identical where query using deep comparison\n let cached = whereQueryCache.find((entry) => isDeepStrictEqual(entry.where, accessResult))\n\n if (!cached) {\n // Cache miss - start DB query (don't await)\n cached = {\n result: entityDocExists({\n id,\n slug,\n entityType,\n locale,\n operation,\n req,\n where: accessResult,\n }),\n where: accessResult,\n }\n whereQueryCache.push(cached)\n }\n\n // Defer resolution to Promise.all (cache hits reuse same promise)\n wherePromises.push(\n cached.result.then((hasPermission) => {\n entityPermissions[operation] = {\n permission: hasPermission,\n where: accessResult,\n } as Permission\n }),\n )\n } else {\n // TODO: 4.0: Investigate defaulting to `false` here, if where query is returned but ignored as we don't\n // have the document data available. This seems more secure.\n // Alternatively, we could set permission to a third state, like 'unknown'.\n // Even after calling sanitizePermissions, the permissions will still be true if the where query is returned but ignored as we don't have the document data available.\n entityPermissions[operation] = { permission: true, where: accessResult } as Permission\n }\n}\n"],"names":["isDeepStrictEqual","entityDocExists","populateFieldPermissions","topLevelCollectionPermissions","topLevelGlobalPermissions","getEntityPermissions","args","id","blockReferencesPermissions","data","_data","entity","entityType","fetchData","operations","req","locale","_locale","user","undefined","Error","hasData","Object","keys","length","payload","findGlobal","slug","depth","fallbackLocale","overrideAccess","findByID","collection","trash","isLoggedIn","fieldsPermissions","entityPermissions","fields","promises","accessResults","_operation","operation","accessFunction","access","includes","push","result","Promise","resolve","permission","resolvedAccessResults","all","map","item","whereQueryCache","wherePromises","accessResult","processWhereQuery","parentPermissionsObject","permissionsObject","iterations","currentPromises","splice","cached","find","entry","where","then","hasPermission"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,OAAM;AAcxC,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,wBAAwB,QAAQ,gCAA+B;AAuCxE,MAAMC,gCAAgC;IACpC;IACA;IACA;IACA;IACA;IACA;CACD;AACD,MAAMC,4BAA4B;IAAC;IAAQ;IAAgB;CAAS;AAEpE;;;;;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,eAAeC,qBACpBC,IAAuB;IAEvB,MAAM,EACJC,EAAE,EACFC,0BAA0B,EAC1BC,MAAMC,KAAK,EACXC,MAAM,EACNC,UAAU,EACVC,SAAS,EACTC,UAAU,EACVC,GAAG,EACJ,GAAGT;IACJ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B,iBAAiB,EACjBxB,UAAU,EACVC,SAAS,EACTG,MAAM,EACNyB,SAAS,EACT1B,GAAG,EACHwC,aAAa,EACbD,eAAe,EAahB;IACC,IAAIzC,WAAW;QACb,8DAA8D;QAC9D,IAAIkD,SAAST,gBAAgBU,IAAI,CAAC,CAACC,QAAUjE,kBAAkBiE,MAAMC,KAAK,EAAEV;QAE5E,IAAI,CAACO,QAAQ;YACX,4CAA4C;YAC5CA,SAAS;gBACPjB,QAAQ7C,gBAAgB;oBACtBM;oBACAoB;oBACAf;oBACAI;oBACAyB;oBACA1B;oBACAmD,OAAOV;gBACT;gBACAU,OAAOV;YACT;YACAF,gBAAgBT,IAAI,CAACkB;QACvB;QAEA,kEAAkE;QAClER,cAAcV,IAAI,CAChBkB,OAAOjB,MAAM,CAACqB,IAAI,CAAC,CAACC;YAClBhC,iBAAiB,CAACK,UAAU,GAAG;gBAC7BQ,YAAYmB;gBACZF,OAAOV;YACT;QACF;IAEJ,OAAO;QACL,wGAAwG;QACxG,4DAA4D;QAC5D,2EAA2E;QAC3E,sKAAsK;QACtKpB,iBAAiB,CAACK,UAAU,GAAG;YAAEQ,YAAY;YAAMiB,OAAOV;QAAa;IACzE;AACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CollectionPermission, FieldPermissions, FieldsPermissions, GlobalPermission } from '../../auth/types.js';
|
|
2
|
+
import type { DefaultDocumentIDType } from '../../index.js';
|
|
3
|
+
import type { AllOperations, JsonObject, PayloadRequest } from '../../types/index.js';
|
|
4
|
+
import type { BlockReferencesPermissions } from './getEntityPermissions.js';
|
|
5
|
+
import { type Field } from '../../fields/config/types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Build up permissions object and run access functions for each field of an entity
|
|
8
|
+
* This function is synchronous and collects all async work into the promises array
|
|
9
|
+
*/
|
|
10
|
+
export declare const populateFieldPermissions: ({ id, blockReferencesPermissions, data, fields, operations, parentPermissionsObject, permissionsObject, promises, req, }: {
|
|
11
|
+
blockReferencesPermissions: BlockReferencesPermissions;
|
|
12
|
+
data: JsonObject | undefined;
|
|
13
|
+
fields: Field[];
|
|
14
|
+
id?: DefaultDocumentIDType;
|
|
15
|
+
/**
|
|
16
|
+
* Operations to check access for
|
|
17
|
+
*/
|
|
18
|
+
operations: AllOperations[];
|
|
19
|
+
parentPermissionsObject: CollectionPermission | FieldPermissions | GlobalPermission;
|
|
20
|
+
permissionsObject: FieldsPermissions;
|
|
21
|
+
promises: Promise<void>[];
|
|
22
|
+
req: PayloadRequest;
|
|
23
|
+
}) => void;
|
|
24
|
+
//# sourceMappingURL=populateFieldPermissions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"populateFieldPermissions.d.ts","sourceRoot":"","sources":["../../../src/utilities/getEntityPermissions/populateFieldPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAEjB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrF,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAA;AAE3E,OAAO,EAAE,KAAK,KAAK,EAAc,MAAM,8BAA8B,CAAA;AAkCrE;;;GAGG;AACH,eAAO,MAAM,wBAAwB,6HAUlC;IACD,0BAA0B,EAAE,0BAA0B,CAAA;IACtD,IAAI,EAAE,UAAU,GAAG,SAAS,CAAA;IAC5B,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,EAAE,CAAC,EAAE,qBAAqB,CAAA;IAC1B;;OAEG;IACH,UAAU,EAAE,aAAa,EAAE,CAAA;IAC3B,uBAAuB,EAAE,oBAAoB,GAAG,gBAAgB,GAAG,gBAAgB,CAAA;IACnF,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAA;IACzB,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,IAsPH,CAAA"}
|