@payloadcms/plugin-multi-tenant 4.0.0-internal.bc5cf8c → 4.0.0-internal.bd1d413
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/LICENSE.md +1 -1
- package/dist/components/AssignTenantFieldModal/index.client.d.ts +2 -2
- package/dist/components/AssignTenantFieldModal/index.client.d.ts.map +1 -1
- package/dist/components/AssignTenantFieldModal/index.client.js +2 -2
- package/dist/components/AssignTenantFieldModal/index.client.js.map +1 -1
- package/dist/components/GlobalViewRedirect/index.d.ts +3 -3
- package/dist/components/GlobalViewRedirect/index.d.ts.map +1 -1
- package/dist/components/GlobalViewRedirect/index.js +2 -2
- package/dist/components/GlobalViewRedirect/index.js.map +1 -1
- package/dist/components/TenantField/index.client.d.ts.map +1 -1
- package/dist/components/TenantField/index.client.js +91 -77
- package/dist/components/TenantField/index.client.js.map +1 -1
- package/dist/components/TenantSelector/index.client.d.ts +1 -1
- package/dist/components/TenantSelector/index.client.d.ts.map +1 -1
- package/dist/components/TenantSelector/index.client.js +2 -2
- package/dist/components/TenantSelector/index.client.js.map +1 -1
- package/dist/components/TenantSelector/index.css +4 -4
- package/dist/components/TenantSelector/index.d.ts.map +1 -1
- package/dist/defaults.d.ts.map +1 -1
- package/dist/endpoints/getTenantOptionsEndpoint.d.ts +7 -3
- package/dist/endpoints/getTenantOptionsEndpoint.d.ts.map +1 -1
- package/dist/endpoints/getTenantOptionsEndpoint.js +7 -4
- package/dist/endpoints/getTenantOptionsEndpoint.js.map +1 -1
- package/dist/fields/tenantField/index.d.ts +4 -2
- package/dist/fields/tenantField/index.d.ts.map +1 -1
- package/dist/fields/tenantField/index.js +57 -9
- package/dist/fields/tenantField/index.js.map +1 -1
- package/dist/fields/tenantsArrayField/index.d.ts.map +1 -1
- package/dist/filters/filterDocumentsByTenants.d.ts +3 -3
- package/dist/filters/filterDocumentsByTenants.d.ts.map +1 -1
- package/dist/filters/filterDocumentsByTenants.js.map +1 -1
- package/dist/hooks/afterTenantDelete.d.ts +2 -2
- package/dist/hooks/afterTenantDelete.d.ts.map +1 -1
- package/dist/hooks/afterTenantDelete.js +24 -17
- package/dist/hooks/afterTenantDelete.js.map +1 -1
- package/dist/hooks/enforceTenantMembership.d.ts +15 -0
- package/dist/hooks/enforceTenantMembership.d.ts.map +1 -0
- package/dist/hooks/enforceTenantMembership.js +39 -0
- package/dist/hooks/enforceTenantMembership.js.map +1 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +293 -195
- package/dist/index.js.map +1 -1
- package/dist/providers/TenantSelectionProvider/index.client.d.ts +3 -1
- package/dist/providers/TenantSelectionProvider/index.client.d.ts.map +1 -1
- package/dist/providers/TenantSelectionProvider/index.client.js +49 -35
- package/dist/providers/TenantSelectionProvider/index.client.js.map +1 -1
- package/dist/providers/TenantSelectionProvider/index.d.ts +5 -5
- package/dist/providers/TenantSelectionProvider/index.d.ts.map +1 -1
- package/dist/providers/TenantSelectionProvider/index.js +6 -4
- package/dist/providers/TenantSelectionProvider/index.js.map +1 -1
- package/dist/translations/languages/en.d.ts.map +1 -1
- package/dist/types.d.ts +9 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/addCollectionAccess.d.ts +9 -12
- package/dist/utilities/addCollectionAccess.d.ts.map +1 -1
- package/dist/utilities/addCollectionAccess.js +39 -27
- package/dist/utilities/addCollectionAccess.js.map +1 -1
- package/dist/utilities/addFilterOptionsToFields.d.ts +4 -5
- package/dist/utilities/addFilterOptionsToFields.d.ts.map +1 -1
- package/dist/utilities/addFilterOptionsToFields.js +37 -40
- package/dist/utilities/addFilterOptionsToFields.js.map +1 -1
- package/dist/utilities/collectionAccessKeys.d.ts +3 -0
- package/dist/utilities/collectionAccessKeys.d.ts.map +1 -0
- package/dist/utilities/collectionAccessKeys.js +11 -0
- package/dist/utilities/collectionAccessKeys.js.map +1 -0
- package/dist/utilities/combineBaseAccessWithTenantAccess.d.ts +7 -0
- package/dist/utilities/combineBaseAccessWithTenantAccess.d.ts.map +1 -0
- package/dist/utilities/combineBaseAccessWithTenantAccess.js +35 -0
- package/dist/utilities/combineBaseAccessWithTenantAccess.js.map +1 -0
- package/dist/utilities/combineCollectionAccessWithTenantAccess.d.ts +4 -0
- package/dist/utilities/combineCollectionAccessWithTenantAccess.d.ts.map +1 -0
- package/dist/utilities/combineCollectionAccessWithTenantAccess.js +26 -0
- package/dist/utilities/combineCollectionAccessWithTenantAccess.js.map +1 -0
- package/dist/utilities/combineFilters.d.ts.map +1 -1
- package/dist/utilities/extractID.d.ts.map +1 -1
- package/dist/utilities/generateCookie.d.ts.map +1 -1
- package/dist/utilities/getCollectionIDType.d.ts +1 -1
- package/dist/utilities/getCollectionIDType.d.ts.map +1 -1
- package/dist/utilities/getGlobalViewRedirect.d.ts +3 -3
- package/dist/utilities/getGlobalViewRedirect.d.ts.map +1 -1
- package/dist/utilities/getGlobalViewRedirect.js +25 -18
- package/dist/utilities/getGlobalViewRedirect.js.map +1 -1
- package/dist/utilities/getTenantAccessResult.d.ts +9 -0
- package/dist/utilities/getTenantAccessResult.d.ts.map +1 -0
- package/dist/utilities/getTenantAccessResult.js +46 -0
- package/dist/utilities/getTenantAccessResult.js.map +1 -0
- package/dist/utilities/getTenantIDsFromValue.d.ts +2 -0
- package/dist/utilities/getTenantIDsFromValue.d.ts.map +1 -0
- package/dist/utilities/getTenantIDsFromValue.js +14 -0
- package/dist/utilities/getTenantIDsFromValue.js.map +1 -0
- package/dist/utilities/getTenantOptions.d.ts +4 -5
- package/dist/utilities/getTenantOptions.d.ts.map +1 -1
- package/dist/utilities/getTenantOptions.js +2 -2
- package/dist/utilities/getTenantOptions.js.map +1 -1
- package/dist/utilities/getUserTenantIDs.d.ts.map +1 -1
- package/dist/utilities/getUserTenantIDs.js +5 -3
- package/dist/utilities/getUserTenantIDs.js.map +1 -1
- package/dist/utilities/isValidTenantAssignment.d.ts +13 -0
- package/dist/utilities/isValidTenantAssignment.d.ts.map +1 -0
- package/dist/utilities/isValidTenantAssignment.js +28 -0
- package/dist/utilities/isValidTenantAssignment.js.map +1 -0
- package/dist/utilities/miniChalk.d.ts.map +1 -1
- package/dist/utilities/shouldRefreshTenantSelection.d.ts +5 -0
- package/dist/utilities/shouldRefreshTenantSelection.d.ts.map +1 -0
- package/dist/utilities/shouldRefreshTenantSelection.js +3 -0
- package/dist/utilities/shouldRefreshTenantSelection.js.map +1 -0
- package/package.json +24 -28
- package/dist/@types/assets.d.js +0 -2
- package/dist/@types/assets.d.js.map +0 -1
- package/dist/utilities/combineWhereConstraints.d.ts +0 -3
- package/dist/utilities/combineWhereConstraints.d.ts.map +0 -1
- package/dist/utilities/combineWhereConstraints.js +0 -19
- package/dist/utilities/combineWhereConstraints.js.map +0 -1
- package/dist/utilities/withTenantAccess.d.ts +0 -16
- package/dist/utilities/withTenantAccess.d.ts.map +0 -1
- package/dist/utilities/withTenantAccess.js +0 -76
- package/dist/utilities/withTenantAccess.js.map +0 -1
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { AcceptedLanguages } from '@payloadcms/translations'\nimport type {\n AccessArgs,\n AccessResult,\n ArrayField,\n CollectionConfig,\n CollectionSlug,\n Field,\n RelationshipField,\n SingleRelationshipField,\n
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { AcceptedLanguages } from '@payloadcms/translations'\nimport type {\n AccessArgs,\n AccessResult,\n ArrayField,\n CollectionConfig,\n CollectionSlug,\n Field,\n RelationshipField,\n SingleRelationshipField,\n User,\n} from 'payload'\n\nexport type TenantValue = (number | string)[] | (number | string)\n\nexport type MultiTenantPluginConfig = {\n /**\n * After a tenant is deleted, the plugin will attempt to clean up related documents\n * - removing documents with the tenant ID\n * - removing the tenant from users\n *\n * @default true\n */\n cleanupAfterTenantDelete?: boolean\n /**\n * Automatically\n */\n collections: {\n [key in CollectionSlug]?: {\n /**\n * Override the access result from the collection access control functions\n *\n * The function receives:\n * - accessResult: the original result from the access control function\n * - accessKey: 'read', 'create', 'update', 'delete', 'readVersions', 'unlock', or 'validate'\n * - ...restOfAccessArgs: the original arguments passed to the access control function\n */\n accessResultOverride?: CollectionAccessResultOverride\n /**\n * Opt out of adding the tenant field and place\n * it manually using the `tenantField` export from the plugin\n */\n customTenantField?: boolean\n /**\n * Set to `true` if you want the collection to behave as a global\n *\n * @default false\n */\n isGlobal?: boolean\n /**\n * Overrides for the tenant field, will override the entire tenantField configuration\n */\n tenantFieldOverrides?: CollectionTenantFieldConfigOverrides\n /**\n * Set to `false` if you want to manually apply the baseListFilter\n * Set to `false` if you want to manually apply the baseFilter\n *\n * @default true\n */\n useBaseFilter?: boolean\n /**\n * @deprecated Use `useBaseFilter` instead. If both are defined,\n * `useBaseFilter` will take precedence. This property remains only\n * for backward compatibility and may be removed in a future version.\n *\n * Originally, `baseListFilter` was intended to filter only the List View\n * in the admin panel. However, base filtering is often required in other areas\n * such as internal link relationships in the Lexical editor.\n *\n * @default true\n */\n useBaseListFilter?: boolean\n /**\n * Set to `false` if you want to handle collection access manually without the multi-tenant constraints applied\n *\n * @default true\n */\n useTenantAccess?: boolean\n }\n }\n /**\n * Enables debug mode\n * - Makes the tenant field visible in the admin UI within applicable collections\n *\n * @default false\n */\n debug?: boolean\n /**\n * Enables the multi-tenant plugin\n *\n * @default true\n */\n enabled?: boolean\n /**\n * Localization for the plugin\n */\n i18n?: {\n translations: {\n [key in AcceptedLanguages]?: {\n /**\n * Shown inside 3 dot menu on edit document view\n *\n * @default 'Assign Tenant'\n */\n 'assign-tenant-button-label'?: string\n /**\n * Shown as the title of the assign tenant modal\n *\n * @default 'Assign \"{{title}}\"'\n */\n 'assign-tenant-modal-title'?: string\n /**\n * Shown as the label for the assigned tenant field in the assign tenant modal\n *\n * @default 'Assigned Tenant'\n */\n 'field-assignedTenant-label'?: string\n /**\n * Shown as the label for the global tenant selector in the admin UI\n *\n * @default 'Filter by Tenant'\n */\n 'nav-tenantSelector-label'?: string\n }\n }\n }\n /**\n * Field configuration for the field added to all tenant enabled collections\n */\n tenantField?: RootTenantFieldConfigOverrides\n /**\n * Field configuration for the field added to the users collection\n *\n * If `includeDefaultField` is `false`, you must include the field on your users collection manually\n * This is useful if you want to customize the field or place the field in a specific location\n */\n tenantsArrayField?:\n | {\n /**\n * Access configuration for the array field\n */\n arrayFieldAccess?: ArrayField['access']\n /**\n * Name of the array field\n *\n * @default 'tenants'\n */\n arrayFieldName?: string\n /**\n * Name of the tenant field\n *\n * @default 'tenant'\n */\n arrayTenantFieldName?: string\n /**\n * When `includeDefaultField` is `true`, the field will be added to the users collection automatically\n */\n includeDefaultField?: true\n /**\n * Additional fields to include on the tenants array field\n */\n rowFields?: Field[]\n /**\n * Access configuration for the tenant field\n */\n tenantFieldAccess?: RelationshipField['access']\n }\n | {\n arrayFieldAccess?: never\n arrayFieldName?: string\n arrayTenantFieldName?: string\n /**\n * When `includeDefaultField` is `false`, you must include the field on your users collection manually\n */\n includeDefaultField?: false\n rowFields?: never\n tenantFieldAccess?: never\n }\n /**\n * Customize tenant selector label\n *\n * Either a string or an object where the keys are i18n codes and the values are the string labels\n *\n * @deprecated Use `i18n.translations` instead.\n */\n tenantSelectorLabel?:\n | Partial<{\n [key in AcceptedLanguages]?: string\n }>\n | string\n /**\n * The slug for the tenant collection\n *\n * @default 'tenants'\n */\n tenantsSlug?: string\n /**\n * Function that determines if a user has access to _all_ tenants\n *\n * Useful for super-admin type users\n */\n userHasAccessToAllTenants?: (user: User) => boolean\n /**\n * Override the access result on the users collection access control functions\n *\n * The function receives:\n * - accessResult: the original result from the access control function\n * - accessKey: 'read', 'create', 'update', 'delete', 'readVersions', 'unlock', or 'validate'\n * - ...restOfAccessArgs: the original arguments passed to the access control function\n */\n usersAccessResultOverride?: CollectionAccessResultOverride\n /**\n * Opt out of adding access constraints to the tenants collection\n */\n useTenantsCollectionAccess?: boolean\n /**\n * Opt out including the baseListFilter to filter tenants by selected tenant\n */\n useTenantsListFilter?: boolean\n\n /**\n * Opt out including the baseListFilter to filter users by selected tenant\n */\n useUsersTenantFilter?: boolean\n}\n\nexport type RootTenantFieldConfigOverrides = Partial<\n Omit<\n SingleRelationshipField,\n | '_sanitized'\n | 'hidden'\n | 'index'\n | 'localized'\n | 'max'\n | 'maxRows'\n | 'min'\n | 'minRows'\n | 'relationTo'\n | 'required'\n | 'type'\n | 'unique'\n | 'virtual'\n >\n>\n\nexport type CollectionTenantFieldConfigOverrides = Partial<\n Omit<RootTenantFieldConfigOverrides, 'name'>\n>\n\nexport type Tenant<IDType = number | string> = {\n id: IDType\n name: string\n}\n\nexport type UserWithTenantsField = {\n tenants?:\n | {\n tenant: number | string | Tenant\n }[]\n | null\n} & User\n\ntype AllAccessKeysT<T extends readonly string[]> = T[number] extends keyof Omit<\n Required<CollectionConfig>['access'],\n 'admin'\n>\n ? keyof Omit<Required<CollectionConfig>['access'], 'admin'> extends T[number]\n ? T\n : never\n : never\n\nexport type AllAccessKeys = AllAccessKeysT<\n ['create', 'read', 'update', 'delete', 'readVersions', 'unlock', 'validate']\n>\n\nexport type CollectionAccessResultOverride = ({\n accessKey,\n accessResult,\n}: {\n accessKey: AllAccessKeys[number]\n accessResult: AccessResult\n} & AccessArgs) => AccessResult | Promise<AccessResult>\n"],"names":[],"mappings":"AAmRA,WAMuD"}
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import type { CollectionConfig } from 'payload';
|
|
2
|
-
import type {
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
accessResultCallback?: MultiTenantPluginConfig<ConfigType>['usersAccessResultOverride'];
|
|
1
|
+
import type { CollectionConfig, Config } from 'payload';
|
|
2
|
+
import type { MultiTenantPluginConfig } from '../types.js';
|
|
3
|
+
export type TenantAccessConfig = {
|
|
4
|
+
accessResultCallback?: MultiTenantPluginConfig['usersAccessResultOverride'];
|
|
6
5
|
adminUsersSlug: string;
|
|
7
6
|
collection: CollectionConfig;
|
|
8
7
|
fieldName: string;
|
|
9
8
|
tenantsArrayFieldName?: string;
|
|
10
9
|
tenantsArrayTenantFieldName?: string;
|
|
11
|
-
userHasAccessToAllTenants: Required<MultiTenantPluginConfig
|
|
10
|
+
userHasAccessToAllTenants: Required<MultiTenantPluginConfig>['userHasAccessToAllTenants'];
|
|
12
11
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export declare const addCollectionAccess: <ConfigType>({ accessResultCallback, adminUsersSlug, collection, fieldName, tenantsArrayFieldName, tenantsArrayTenantFieldName, userHasAccessToAllTenants, }: Args<ConfigType>) => void;
|
|
18
|
-
export {};
|
|
12
|
+
export declare const addCollectionAccess: ({ collectionAccessConfigs, config, }: {
|
|
13
|
+
collectionAccessConfigs: TenantAccessConfig[];
|
|
14
|
+
config: Config;
|
|
15
|
+
}) => Config;
|
|
19
16
|
//# sourceMappingURL=addCollectionAccess.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addCollectionAccess.d.ts","sourceRoot":"","sources":["../../src/utilities/addCollectionAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"addCollectionAccess.d.ts","sourceRoot":"","sources":["../../src/utilities/addCollectionAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAEvD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAK1D,MAAM,MAAM,kBAAkB,GAAG;IAC/B,oBAAoB,CAAC,EAAE,uBAAuB,CAAC,2BAA2B,CAAC,CAAA;IAC3E,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,gBAAgB,CAAA;IAC5B,SAAS,EAAE,MAAM,CAAA;IACjB,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,2BAA2B,CAAC,EAAE,MAAM,CAAA;IACpC,yBAAyB,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAAC,2BAA2B,CAAC,CAAA;CAC1F,CAAA;AAED,eAAO,MAAM,mBAAmB,yCAG7B;IACD,uBAAuB,EAAE,kBAAkB,EAAE,CAAA;IAC7C,MAAM,EAAE,MAAM,CAAA;CACf,KAAG,MAiDH,CAAA"}
|
|
@@ -1,32 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
];
|
|
10
|
-
/**
|
|
11
|
-
* Adds tenant access constraint to collection
|
|
12
|
-
* - constrains access a users assigned tenants
|
|
13
|
-
*/ export const addCollectionAccess = ({ accessResultCallback, adminUsersSlug, collection, fieldName, tenantsArrayFieldName, tenantsArrayTenantFieldName, userHasAccessToAllTenants })=>{
|
|
14
|
-
collectionAccessKeys.forEach((key)=>{
|
|
15
|
-
if (!collection.access) {
|
|
16
|
-
collection.access = {};
|
|
1
|
+
import { combineBaseAccessWithTenantAccess } from './combineBaseAccessWithTenantAccess.js';
|
|
2
|
+
import { combineCollectionAccessWithTenantAccess } from './combineCollectionAccessWithTenantAccess.js';
|
|
3
|
+
export const addCollectionAccess = ({ collectionAccessConfigs, config })=>{
|
|
4
|
+
const { baseAccessBySlug, collectionAccessBySlug } = collectionAccessConfigs.reduce((acc, accessConfig)=>{
|
|
5
|
+
if (accessConfig.accessResultCallback) {
|
|
6
|
+
acc.collectionAccessBySlug.set(accessConfig.collection.slug, accessConfig);
|
|
7
|
+
} else {
|
|
8
|
+
acc.baseAccessBySlug.set(accessConfig.collection.slug, accessConfig);
|
|
17
9
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
adminUsersSlug,
|
|
23
|
-
collection,
|
|
24
|
-
fieldName: key === 'readVersions' ? `version.${fieldName}` : fieldName,
|
|
25
|
-
tenantsArrayFieldName,
|
|
26
|
-
tenantsArrayTenantFieldName,
|
|
27
|
-
userHasAccessToAllTenants
|
|
28
|
-
});
|
|
10
|
+
return acc;
|
|
11
|
+
}, {
|
|
12
|
+
baseAccessBySlug: new Map(),
|
|
13
|
+
collectionAccessBySlug: new Map()
|
|
29
14
|
});
|
|
15
|
+
let updatedConfig = config;
|
|
16
|
+
// Override callbacks need the collection's own access result.
|
|
17
|
+
if (collectionAccessBySlug.size) {
|
|
18
|
+
updatedConfig = {
|
|
19
|
+
...updatedConfig,
|
|
20
|
+
collections: updatedConfig.collections?.map((collection)=>{
|
|
21
|
+
const accessConfig = collectionAccessBySlug.get(collection.slug);
|
|
22
|
+
if (!accessConfig) {
|
|
23
|
+
return collection;
|
|
24
|
+
}
|
|
25
|
+
return combineCollectionAccessWithTenantAccess({
|
|
26
|
+
...accessConfig,
|
|
27
|
+
collection
|
|
28
|
+
});
|
|
29
|
+
})
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (baseAccessBySlug.size) {
|
|
33
|
+
updatedConfig = {
|
|
34
|
+
...updatedConfig,
|
|
35
|
+
baseAccess: combineBaseAccessWithTenantAccess({
|
|
36
|
+
accessConfigBySlug: baseAccessBySlug,
|
|
37
|
+
baseAccess: config.baseAccess
|
|
38
|
+
})
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return updatedConfig;
|
|
30
42
|
};
|
|
31
43
|
|
|
32
44
|
//# sourceMappingURL=addCollectionAccess.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/addCollectionAccess.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\n\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/addCollectionAccess.ts"],"sourcesContent":["import type { CollectionConfig, Config } from 'payload'\n\nimport type { MultiTenantPluginConfig } from '../types.js'\n\nimport { combineBaseAccessWithTenantAccess } from './combineBaseAccessWithTenantAccess.js'\nimport { combineCollectionAccessWithTenantAccess } from './combineCollectionAccessWithTenantAccess.js'\n\nexport type TenantAccessConfig = {\n accessResultCallback?: MultiTenantPluginConfig['usersAccessResultOverride']\n adminUsersSlug: string\n collection: CollectionConfig\n fieldName: string\n tenantsArrayFieldName?: string\n tenantsArrayTenantFieldName?: string\n userHasAccessToAllTenants: Required<MultiTenantPluginConfig>['userHasAccessToAllTenants']\n}\n\nexport const addCollectionAccess = ({\n collectionAccessConfigs,\n config,\n}: {\n collectionAccessConfigs: TenantAccessConfig[]\n config: Config\n}): Config => {\n const { baseAccessBySlug, collectionAccessBySlug } = collectionAccessConfigs.reduce<{\n baseAccessBySlug: Map<string, TenantAccessConfig>\n collectionAccessBySlug: Map<string, TenantAccessConfig>\n }>(\n (acc, accessConfig) => {\n if (accessConfig.accessResultCallback) {\n acc.collectionAccessBySlug.set(accessConfig.collection.slug, accessConfig)\n } else {\n acc.baseAccessBySlug.set(accessConfig.collection.slug, accessConfig)\n }\n\n return acc\n },\n {\n baseAccessBySlug: new Map(),\n collectionAccessBySlug: new Map(),\n },\n )\n\n let updatedConfig = config\n\n // Override callbacks need the collection's own access result.\n if (collectionAccessBySlug.size) {\n updatedConfig = {\n ...updatedConfig,\n collections: updatedConfig.collections?.map((collection) => {\n const accessConfig = collectionAccessBySlug.get(collection.slug)\n\n if (!accessConfig) {\n return collection\n }\n\n return combineCollectionAccessWithTenantAccess({ ...accessConfig, collection })\n }),\n }\n }\n\n if (baseAccessBySlug.size) {\n updatedConfig = {\n ...updatedConfig,\n baseAccess: combineBaseAccessWithTenantAccess({\n accessConfigBySlug: baseAccessBySlug,\n baseAccess: config.baseAccess,\n }),\n }\n }\n\n return updatedConfig\n}\n"],"names":["combineBaseAccessWithTenantAccess","combineCollectionAccessWithTenantAccess","addCollectionAccess","collectionAccessConfigs","config","baseAccessBySlug","collectionAccessBySlug","reduce","acc","accessConfig","accessResultCallback","set","collection","slug","Map","updatedConfig","size","collections","map","get","baseAccess","accessConfigBySlug"],"mappings":"AAIA,SAASA,iCAAiC,QAAQ,yCAAwC;AAC1F,SAASC,uCAAuC,QAAQ,+CAA8C;AAYtG,OAAO,MAAMC,sBAAsB,CAAC,EAClCC,uBAAuB,EACvBC,MAAM,EAIP;IACC,MAAM,EAAEC,gBAAgB,EAAEC,sBAAsB,EAAE,GAAGH,wBAAwBI,MAAM,CAIjF,CAACC,KAAKC;QACJ,IAAIA,aAAaC,oBAAoB,EAAE;YACrCF,IAAIF,sBAAsB,CAACK,GAAG,CAACF,aAAaG,UAAU,CAACC,IAAI,EAAEJ;QAC/D,OAAO;YACLD,IAAIH,gBAAgB,CAACM,GAAG,CAACF,aAAaG,UAAU,CAACC,IAAI,EAAEJ;QACzD;QAEA,OAAOD;IACT,GACA;QACEH,kBAAkB,IAAIS;QACtBR,wBAAwB,IAAIQ;IAC9B;IAGF,IAAIC,gBAAgBX;IAEpB,8DAA8D;IAC9D,IAAIE,uBAAuBU,IAAI,EAAE;QAC/BD,gBAAgB;YACd,GAAGA,aAAa;YAChBE,aAAaF,cAAcE,WAAW,EAAEC,IAAI,CAACN;gBAC3C,MAAMH,eAAeH,uBAAuBa,GAAG,CAACP,WAAWC,IAAI;gBAE/D,IAAI,CAACJ,cAAc;oBACjB,OAAOG;gBACT;gBAEA,OAAOX,wCAAwC;oBAAE,GAAGQ,YAAY;oBAAEG;gBAAW;YAC/E;QACF;IACF;IAEA,IAAIP,iBAAiBW,IAAI,EAAE;QACzBD,gBAAgB;YACd,GAAGA,aAAa;YAChBK,YAAYpB,kCAAkC;gBAC5CqB,oBAAoBhB;gBACpBe,YAAYhB,OAAOgB,UAAU;YAC/B;QACF;IACF;IAEA,OAAOL;AACT,EAAC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Field } from 'payload';
|
|
2
2
|
import type { MultiTenantPluginConfig } from '../types.js';
|
|
3
|
-
type AddFilterOptionsToFieldsArgs
|
|
3
|
+
type AddFilterOptionsToFieldsArgs = {
|
|
4
4
|
blockReferencesWithFilters: string[];
|
|
5
|
-
config: Config | SanitizedConfig;
|
|
6
5
|
fields: Field[];
|
|
7
6
|
tenantEnabledCollectionSlugs: string[];
|
|
8
7
|
tenantEnabledGlobalSlugs: string[];
|
|
@@ -10,8 +9,8 @@ type AddFilterOptionsToFieldsArgs<ConfigType = unknown> = {
|
|
|
10
9
|
tenantsArrayFieldName: string;
|
|
11
10
|
tenantsArrayTenantFieldName: string;
|
|
12
11
|
tenantsCollectionSlug: string;
|
|
13
|
-
userHasAccessToAllTenants: Required<MultiTenantPluginConfig
|
|
12
|
+
userHasAccessToAllTenants: Required<MultiTenantPluginConfig>['userHasAccessToAllTenants'];
|
|
14
13
|
};
|
|
15
|
-
export declare function addFilterOptionsToFields
|
|
14
|
+
export declare function addFilterOptionsToFields({ blockReferencesWithFilters, fields, tenantEnabledCollectionSlugs, tenantEnabledGlobalSlugs, tenantFieldName, tenantsArrayFieldName, tenantsArrayTenantFieldName, tenantsCollectionSlug, userHasAccessToAllTenants, }: AddFilterOptionsToFieldsArgs): Field[];
|
|
16
15
|
export {};
|
|
17
16
|
//# sourceMappingURL=addFilterOptionsToFields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addFilterOptionsToFields.d.ts","sourceRoot":"","sources":["../../src/utilities/addFilterOptionsToFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,
|
|
1
|
+
{"version":3,"file":"addFilterOptionsToFields.d.ts","sourceRoot":"","sources":["../../src/utilities/addFilterOptionsToFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,KAAK,EAAqB,MAAM,SAAS,CAAA;AAE9D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAK1D,KAAK,4BAA4B,GAAG;IAClC,0BAA0B,EAAE,MAAM,EAAE,CAAA;IACpC,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,4BAA4B,EAAE,MAAM,EAAE,CAAA;IACtC,wBAAwB,EAAE,MAAM,EAAE,CAAA;IAClC,eAAe,EAAE,MAAM,CAAA;IACvB,qBAAqB,EAAE,MAAM,CAAA;IAC7B,2BAA2B,EAAE,MAAM,CAAA;IACnC,qBAAqB,EAAE,MAAM,CAAA;IAC7B,yBAAyB,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAAC,2BAA2B,CAAC,CAAA;CAC1F,CAAA;AAED,wBAAgB,wBAAwB,CAAC,EACvC,0BAA0B,EAC1B,MAAM,EACN,4BAA4B,EAC5B,wBAAwB,EACxB,eAAe,EACf,qBAAsD,EACtD,2BAAkE,EAClE,qBAAqB,EACrB,yBAAyB,GAC1B,EAAE,4BAA4B,GAAG,KAAK,EAAE,CAwHxC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defaults } from '../defaults.js';
|
|
2
2
|
import { filterDocumentsByTenants } from '../filters/filterDocumentsByTenants.js';
|
|
3
|
-
export function addFilterOptionsToFields({ blockReferencesWithFilters,
|
|
3
|
+
export function addFilterOptionsToFields({ blockReferencesWithFilters, fields, tenantEnabledCollectionSlugs, tenantEnabledGlobalSlugs, tenantFieldName, tenantsArrayFieldName = defaults.tenantsArrayFieldName, tenantsArrayTenantFieldName = defaults.tenantsArrayTenantFieldName, tenantsCollectionSlug, userHasAccessToAllTenants }) {
|
|
4
4
|
const newFields = [];
|
|
5
5
|
for (const field of fields){
|
|
6
6
|
let newField = {
|
|
@@ -43,7 +43,6 @@ export function addFilterOptionsToFields({ blockReferencesWithFilters, config, f
|
|
|
43
43
|
if (newField.type === 'row' || newField.type === 'array' || newField.type === 'collapsible' || newField.type === 'group') {
|
|
44
44
|
newField.fields = addFilterOptionsToFields({
|
|
45
45
|
blockReferencesWithFilters,
|
|
46
|
-
config,
|
|
47
46
|
fields: newField.fields,
|
|
48
47
|
tenantEnabledCollectionSlugs,
|
|
49
48
|
tenantEnabledGlobalSlugs,
|
|
@@ -62,11 +61,9 @@ export function addFilterOptionsToFields({ blockReferencesWithFilters, config, f
|
|
|
62
61
|
if (typeof _block === 'string') {
|
|
63
62
|
isReference = true;
|
|
64
63
|
if (!blockReferencesWithFilters.includes(_block)) {
|
|
65
|
-
block = config?.blocks?.find((b)=>b.slug === _block);
|
|
66
64
|
blockReferencesWithFilters.push(_block);
|
|
67
65
|
}
|
|
68
66
|
} else {
|
|
69
|
-
// Create a shallow copy to avoid mutating the original block reference
|
|
70
67
|
block = {
|
|
71
68
|
..._block
|
|
72
69
|
};
|
|
@@ -74,7 +71,6 @@ export function addFilterOptionsToFields({ blockReferencesWithFilters, config, f
|
|
|
74
71
|
if (block?.fields) {
|
|
75
72
|
block.fields = addFilterOptionsToFields({
|
|
76
73
|
blockReferencesWithFilters,
|
|
77
|
-
config,
|
|
78
74
|
fields: block.fields,
|
|
79
75
|
tenantEnabledCollectionSlugs,
|
|
80
76
|
tenantEnabledGlobalSlugs,
|
|
@@ -96,7 +92,6 @@ export function addFilterOptionsToFields({ blockReferencesWithFilters, config, f
|
|
|
96
92
|
};
|
|
97
93
|
newTab.fields = addFilterOptionsToFields({
|
|
98
94
|
blockReferencesWithFilters,
|
|
99
|
-
config,
|
|
100
95
|
fields: tab.fields,
|
|
101
96
|
tenantEnabledCollectionSlugs,
|
|
102
97
|
tenantEnabledGlobalSlugs,
|
|
@@ -116,42 +111,44 @@ export function addFilterOptionsToFields({ blockReferencesWithFilters, config, f
|
|
|
116
111
|
function addRelationshipFilter({ field, tenantEnabledCollectionSlugs, tenantFieldName, tenantsArrayFieldName = defaults.tenantsArrayFieldName, tenantsArrayTenantFieldName = defaults.tenantsArrayTenantFieldName, tenantsCollectionSlug, userHasAccessToAllTenants }) {
|
|
117
112
|
// User specified filter
|
|
118
113
|
const originalFilter = field.filterOptions;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
114
|
+
return {
|
|
115
|
+
...field,
|
|
116
|
+
filterOptions: async (args)=>{
|
|
117
|
+
const originalFilterResult = typeof originalFilter === 'function' ? await originalFilter(args) : originalFilter ?? true;
|
|
118
|
+
// If the relationTo is not a tenant enabled collection, return early
|
|
119
|
+
if (args.relationTo && !tenantEnabledCollectionSlugs.includes(args.relationTo)) {
|
|
120
|
+
return originalFilterResult;
|
|
121
|
+
}
|
|
122
|
+
// If the original filter returns false, return early
|
|
123
|
+
if (originalFilterResult === false) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
// Custom tenant filter
|
|
127
|
+
const tenantFilterResults = filterDocumentsByTenants({
|
|
128
|
+
docTenantID: args.data?.[tenantFieldName],
|
|
129
|
+
filterFieldName: tenantFieldName,
|
|
130
|
+
req: args.req,
|
|
131
|
+
tenantsArrayFieldName,
|
|
132
|
+
tenantsArrayTenantFieldName,
|
|
133
|
+
tenantsCollectionSlug,
|
|
134
|
+
userHasAccessToAllTenants
|
|
135
|
+
});
|
|
136
|
+
// If the tenant filter returns null, meaning no tenant filter, just use the original filter
|
|
137
|
+
if (tenantFilterResults === null) {
|
|
138
|
+
return originalFilterResult;
|
|
139
|
+
}
|
|
140
|
+
// If the original filter returns true, just use the tenant filter
|
|
141
|
+
if (originalFilterResult === true) {
|
|
142
|
+
return tenantFilterResults;
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
and: [
|
|
146
|
+
originalFilterResult,
|
|
147
|
+
tenantFilterResults
|
|
148
|
+
]
|
|
149
|
+
};
|
|
146
150
|
}
|
|
147
|
-
return {
|
|
148
|
-
and: [
|
|
149
|
-
originalFilterResult,
|
|
150
|
-
tenantFilterResults
|
|
151
|
-
]
|
|
152
|
-
};
|
|
153
151
|
};
|
|
154
|
-
return field;
|
|
155
152
|
}
|
|
156
153
|
|
|
157
154
|
//# sourceMappingURL=addFilterOptionsToFields.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/addFilterOptionsToFields.ts"],"sourcesContent":["import type { Block, Config, Field, RelationshipField, SanitizedConfig } from 'payload'\n\nimport type { MultiTenantPluginConfig } from '../types.js'\n\nimport { defaults } from '../defaults.js'\nimport { filterDocumentsByTenants } from '../filters/filterDocumentsByTenants.js'\n\ntype AddFilterOptionsToFieldsArgs<ConfigType = unknown> = {\n blockReferencesWithFilters: string[]\n config: Config | SanitizedConfig\n fields: Field[]\n tenantEnabledCollectionSlugs: string[]\n tenantEnabledGlobalSlugs: string[]\n tenantFieldName: string\n tenantsArrayFieldName: string\n tenantsArrayTenantFieldName: string\n tenantsCollectionSlug: string\n userHasAccessToAllTenants: Required<\n MultiTenantPluginConfig<ConfigType>\n >['userHasAccessToAllTenants']\n}\n\nexport function addFilterOptionsToFields<ConfigType = unknown>({\n blockReferencesWithFilters,\n config,\n fields,\n tenantEnabledCollectionSlugs,\n tenantEnabledGlobalSlugs,\n tenantFieldName,\n tenantsArrayFieldName = defaults.tenantsArrayFieldName,\n tenantsArrayTenantFieldName = defaults.tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n userHasAccessToAllTenants,\n}: AddFilterOptionsToFieldsArgs<ConfigType>): Field[] {\n const newFields = []\n for (const field of fields) {\n let newField: Field = { ...field }\n if (newField.type === 'relationship') {\n let hasTenantRelationsips = false\n /**\n * Adjusts relationship fields to filter by tenant\n * and ensures relationTo cannot be a tenant global collection\n */\n if (typeof newField.relationTo === 'string') {\n if (tenantEnabledGlobalSlugs.includes(newField.relationTo)) {\n throw new Error(\n `The collection ${newField.relationTo} is a global collection and cannot be related to a tenant enabled collection.`,\n )\n }\n if (tenantEnabledCollectionSlugs.includes(newField.relationTo)) {\n hasTenantRelationsips = true\n }\n } else {\n for (const relationTo of newField.relationTo) {\n if (tenantEnabledGlobalSlugs.includes(relationTo)) {\n throw new Error(\n `The collection ${relationTo} is a global collection and cannot be related to a tenant enabled collection.`,\n )\n }\n if (tenantEnabledCollectionSlugs.includes(relationTo)) {\n hasTenantRelationsips = true\n }\n }\n }\n\n if (hasTenantRelationsips) {\n newField = addRelationshipFilter({\n field: newField as RelationshipField,\n tenantEnabledCollectionSlugs,\n tenantFieldName,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n userHasAccessToAllTenants,\n })\n }\n }\n\n if (\n newField.type === 'row' ||\n newField.type === 'array' ||\n newField.type === 'collapsible' ||\n newField.type === 'group'\n ) {\n newField.fields = addFilterOptionsToFields({\n blockReferencesWithFilters,\n config,\n fields: newField.fields,\n tenantEnabledCollectionSlugs,\n tenantEnabledGlobalSlugs,\n tenantFieldName,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n userHasAccessToAllTenants,\n })\n }\n\n if (newField.type === 'blocks') {\n const newBlocks: (Block | string)[] = []\n newField.blocks.forEach((_block) => {\n let block: Block | undefined\n let isReference = false\n\n if (typeof _block === 'string') {\n isReference = true\n if (!blockReferencesWithFilters.includes(_block)) {\n block = config?.blocks?.find((b) => b.slug === _block)\n blockReferencesWithFilters.push(_block)\n }\n } else {\n // Create a shallow copy to avoid mutating the original block reference\n block = { ..._block }\n }\n\n if (block?.fields) {\n block.fields = addFilterOptionsToFields({\n blockReferencesWithFilters,\n config,\n fields: block.fields,\n tenantEnabledCollectionSlugs,\n tenantEnabledGlobalSlugs,\n tenantFieldName,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n userHasAccessToAllTenants,\n })\n }\n\n newBlocks.push(isReference ? _block : block!)\n })\n newField.blocks = newBlocks\n }\n\n if (newField.type === 'tabs') {\n newField.tabs = newField.tabs.map((tab) => {\n const newTab = { ...tab }\n newTab.fields = addFilterOptionsToFields({\n blockReferencesWithFilters,\n config,\n fields: tab.fields,\n tenantEnabledCollectionSlugs,\n tenantEnabledGlobalSlugs,\n tenantFieldName,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n userHasAccessToAllTenants,\n })\n return newTab\n })\n }\n\n newFields.push(newField)\n }\n\n return newFields\n}\n\ntype AddFilterArgs<ConfigType = unknown> = {\n field: RelationshipField\n tenantEnabledCollectionSlugs: string[]\n tenantFieldName: string\n tenantsArrayFieldName: string\n tenantsArrayTenantFieldName: string\n tenantsCollectionSlug: string\n userHasAccessToAllTenants: Required<\n MultiTenantPluginConfig<ConfigType>\n >['userHasAccessToAllTenants']\n}\nfunction addRelationshipFilter<ConfigType = unknown>({\n field,\n tenantEnabledCollectionSlugs,\n tenantFieldName,\n tenantsArrayFieldName = defaults.tenantsArrayFieldName,\n tenantsArrayTenantFieldName = defaults.tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n userHasAccessToAllTenants,\n}: AddFilterArgs<ConfigType>): Field {\n // User specified filter\n const originalFilter = field.filterOptions\n field.filterOptions = async (args) => {\n const originalFilterResult =\n typeof originalFilter === 'function' ? await originalFilter(args) : (originalFilter ?? true)\n\n // If the relationTo is not a tenant enabled collection, return early\n if (args.relationTo && !tenantEnabledCollectionSlugs.includes(args.relationTo)) {\n return originalFilterResult\n }\n\n // If the original filtr returns false, return early\n if (originalFilterResult === false) {\n return false\n }\n\n // Custom tenant filter\n const tenantFilterResults = filterDocumentsByTenants({\n docTenantID: args.data?.[tenantFieldName],\n filterFieldName: tenantFieldName,\n req: args.req,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n userHasAccessToAllTenants,\n })\n\n // If the tenant filter returns null, meaning no tenant filter, just use the original filter\n if (tenantFilterResults === null) {\n return originalFilterResult\n }\n\n // If the original filter returns true, just use the tenant filter\n if (originalFilterResult === true) {\n return tenantFilterResults\n }\n\n return {\n and: [originalFilterResult, tenantFilterResults],\n }\n }\n\n return field\n}\n"],"names":["defaults","filterDocumentsByTenants","addFilterOptionsToFields","blockReferencesWithFilters","config","fields","tenantEnabledCollectionSlugs","tenantEnabledGlobalSlugs","tenantFieldName","tenantsArrayFieldName","tenantsArrayTenantFieldName","tenantsCollectionSlug","userHasAccessToAllTenants","newFields","field","newField","type","hasTenantRelationsips","relationTo","includes","Error","addRelationshipFilter","newBlocks","blocks","forEach","_block","block","isReference","find","b","slug","push","tabs","map","tab","newTab","originalFilter","filterOptions","args","originalFilterResult","tenantFilterResults","docTenantID","data","filterFieldName","req","and"],"mappings":"AAIA,SAASA,QAAQ,QAAQ,iBAAgB;AACzC,SAASC,wBAAwB,QAAQ,yCAAwC;AAiBjF,OAAO,SAASC,yBAA+C,EAC7DC,0BAA0B,EAC1BC,MAAM,EACNC,MAAM,EACNC,4BAA4B,EAC5BC,wBAAwB,EACxBC,eAAe,EACfC,wBAAwBT,SAASS,qBAAqB,EACtDC,8BAA8BV,SAASU,2BAA2B,EAClEC,qBAAqB,EACrBC,yBAAyB,EACgB;IACzC,MAAMC,YAAY,EAAE;IACpB,KAAK,MAAMC,SAAST,OAAQ;QAC1B,IAAIU,WAAkB;YAAE,GAAGD,KAAK;QAAC;QACjC,IAAIC,SAASC,IAAI,KAAK,gBAAgB;YACpC,IAAIC,wBAAwB;YAC5B;;;OAGC,GACD,IAAI,OAAOF,SAASG,UAAU,KAAK,UAAU;gBAC3C,IAAIX,yBAAyBY,QAAQ,CAACJ,SAASG,UAAU,GAAG;oBAC1D,MAAM,IAAIE,MACR,CAAC,eAAe,EAAEL,SAASG,UAAU,CAAC,6EAA6E,CAAC;gBAExH;gBACA,IAAIZ,6BAA6Ba,QAAQ,CAACJ,SAASG,UAAU,GAAG;oBAC9DD,wBAAwB;gBAC1B;YACF,OAAO;gBACL,KAAK,MAAMC,cAAcH,SAASG,UAAU,CAAE;oBAC5C,IAAIX,yBAAyBY,QAAQ,CAACD,aAAa;wBACjD,MAA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T"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/addFilterOptionsToFields.ts"],"sourcesContent":["import type { Block, Field, RelationshipField } from 'payload'\n\nimport type { MultiTenantPluginConfig } from '../types.js'\n\nimport { defaults } from '../defaults.js'\nimport { filterDocumentsByTenants } from '../filters/filterDocumentsByTenants.js'\n\ntype AddFilterOptionsToFieldsArgs = {\n blockReferencesWithFilters: string[]\n fields: Field[]\n tenantEnabledCollectionSlugs: string[]\n tenantEnabledGlobalSlugs: string[]\n tenantFieldName: string\n tenantsArrayFieldName: string\n tenantsArrayTenantFieldName: string\n tenantsCollectionSlug: string\n userHasAccessToAllTenants: Required<MultiTenantPluginConfig>['userHasAccessToAllTenants']\n}\n\nexport function addFilterOptionsToFields({\n blockReferencesWithFilters,\n fields,\n tenantEnabledCollectionSlugs,\n tenantEnabledGlobalSlugs,\n tenantFieldName,\n tenantsArrayFieldName = defaults.tenantsArrayFieldName,\n tenantsArrayTenantFieldName = defaults.tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n userHasAccessToAllTenants,\n}: AddFilterOptionsToFieldsArgs): Field[] {\n const newFields = []\n for (const field of fields) {\n let newField: Field = { ...field }\n if (newField.type === 'relationship') {\n let hasTenantRelationsips = false\n /**\n * Adjusts relationship fields to filter by tenant\n * and ensures relationTo cannot be a tenant global collection\n */\n if (typeof newField.relationTo === 'string') {\n if (tenantEnabledGlobalSlugs.includes(newField.relationTo)) {\n throw new Error(\n `The collection ${newField.relationTo} is a global collection and cannot be related to a tenant enabled collection.`,\n )\n }\n if (tenantEnabledCollectionSlugs.includes(newField.relationTo)) {\n hasTenantRelationsips = true\n }\n } else {\n for (const relationTo of newField.relationTo) {\n if (tenantEnabledGlobalSlugs.includes(relationTo)) {\n throw new Error(\n `The collection ${relationTo} is a global collection and cannot be related to a tenant enabled collection.`,\n )\n }\n if (tenantEnabledCollectionSlugs.includes(relationTo)) {\n hasTenantRelationsips = true\n }\n }\n }\n\n if (hasTenantRelationsips) {\n newField = addRelationshipFilter({\n field: newField,\n tenantEnabledCollectionSlugs,\n tenantFieldName,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n userHasAccessToAllTenants,\n })\n }\n }\n\n if (\n newField.type === 'row' ||\n newField.type === 'array' ||\n newField.type === 'collapsible' ||\n newField.type === 'group'\n ) {\n newField.fields = addFilterOptionsToFields({\n blockReferencesWithFilters,\n fields: newField.fields,\n tenantEnabledCollectionSlugs,\n tenantEnabledGlobalSlugs,\n tenantFieldName,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n userHasAccessToAllTenants,\n })\n }\n\n if (newField.type === 'blocks') {\n const newBlocks: (Block | string)[] = []\n newField.blocks.forEach((_block) => {\n let block: Block | undefined\n let isReference = false\n\n if (typeof _block === 'string') {\n isReference = true\n if (!blockReferencesWithFilters.includes(_block)) {\n blockReferencesWithFilters.push(_block)\n }\n } else {\n block = { ..._block }\n }\n\n if (block?.fields) {\n block.fields = addFilterOptionsToFields({\n blockReferencesWithFilters,\n fields: block.fields,\n tenantEnabledCollectionSlugs,\n tenantEnabledGlobalSlugs,\n tenantFieldName,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n userHasAccessToAllTenants,\n })\n }\n\n newBlocks.push(isReference ? _block : block!)\n })\n newField.blocks = newBlocks\n }\n\n if (newField.type === 'tabs') {\n newField.tabs = newField.tabs.map((tab) => {\n const newTab = { ...tab }\n newTab.fields = addFilterOptionsToFields({\n blockReferencesWithFilters,\n fields: tab.fields,\n tenantEnabledCollectionSlugs,\n tenantEnabledGlobalSlugs,\n tenantFieldName,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n userHasAccessToAllTenants,\n })\n return newTab\n })\n }\n\n newFields.push(newField)\n }\n\n return newFields\n}\n\ntype AddFilterArgs = {\n field: RelationshipField\n tenantEnabledCollectionSlugs: string[]\n tenantFieldName: string\n tenantsArrayFieldName: string\n tenantsArrayTenantFieldName: string\n tenantsCollectionSlug: string\n userHasAccessToAllTenants: Required<MultiTenantPluginConfig>['userHasAccessToAllTenants']\n}\nfunction addRelationshipFilter({\n field,\n tenantEnabledCollectionSlugs,\n tenantFieldName,\n tenantsArrayFieldName = defaults.tenantsArrayFieldName,\n tenantsArrayTenantFieldName = defaults.tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n userHasAccessToAllTenants,\n}: AddFilterArgs): RelationshipField {\n // User specified filter\n const originalFilter = field.filterOptions\n\n return {\n ...field,\n filterOptions: async (args) => {\n const originalFilterResult =\n typeof originalFilter === 'function' ? await originalFilter(args) : (originalFilter ?? true)\n\n // If the relationTo is not a tenant enabled collection, return early\n if (args.relationTo && !tenantEnabledCollectionSlugs.includes(args.relationTo)) {\n return originalFilterResult\n }\n\n // If the original filter returns false, return early\n if (originalFilterResult === false) {\n return false\n }\n\n // Custom tenant filter\n const tenantFilterResults = filterDocumentsByTenants({\n docTenantID: args.data?.[tenantFieldName],\n filterFieldName: tenantFieldName,\n req: args.req,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n userHasAccessToAllTenants,\n })\n\n // If the tenant filter returns null, meaning no tenant filter, just use the original filter\n if (tenantFilterResults === null) {\n return originalFilterResult\n }\n\n // If the original filter returns true, just use the tenant filter\n if (originalFilterResult === true) {\n return tenantFilterResults\n }\n\n return {\n and: [originalFilterResult, tenantFilterResults],\n }\n },\n }\n}\n"],"names":["defaults","filterDocumentsByTenants","addFilterOptionsToFields","blockReferencesWithFilters","fields","tenantEnabledCollectionSlugs","tenantEnabledGlobalSlugs","tenantFieldName","tenantsArrayFieldName","tenantsArrayTenantFieldName","tenantsCollectionSlug","userHasAccessToAllTenants","newFields","field","newField","type","hasTenantRelationsips","relationTo","includes","Error","addRelationshipFilter","newBlocks","blocks","forEach","_block","block","isReference","push","tabs","map","tab","newTab","originalFilter","filterOptions","args","originalFilterResult","tenantFilterResults","docTenantID","data","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ACrBC,yBAAyB,EACX;IACd,wBAAwB;IACxB,MAAMqB,iBAAiBnB,MAAMoB,aAAa;IAE1C,OAAO;QACL,GAAGpB,KAAK;QACRoB,eAAe,OAAOC;YACpB,MAAMC,uBACJ,OAAOH,mBAAmB,aAAa,MAAMA,eAAeE,QAASF,kBAAkB;YAEzF,qEAAqE;YACrE,IAAIE,KAAKjB,UAAU,IAAI,CAACZ,6BAA6Ba,QAAQ,CAACgB,KAAKjB,UAAU,GAAG;gBAC9E,OAAOkB;YACT;YAEA,qDAAqD;YACrD,IAAIA,yBAAyB,OAAO;gBAClC,OAAO;YACT;YAEA,uBAAuB;YACvB,MAAMC,sBAAsBnC,yBAAyB;gBACnDoC,aAAaH,KAAKI,IAAI,EAAE,CAAC/B,gBAAgB;gBACzCgC,iBAAiBhC;gBACjBiC,KAAKN,KAAKM,GAAG;gBACbhC;gBACAC;gBACAC;gBACAC;YACF;YAEA,4FAA4F;YAC5F,IAAIyB,wBAAwB,MAAM;gBAChC,OAAOD;YACT;YAEA,kEAAkE;YAClE,IAAIA,yBAAyB,MAAM;gBACjC,OAAOC;YACT;YAEA,OAAO;gBACLK,KAAK;oBAACN;oBAAsBC;iBAAoB;YAClD;QACF;IACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectionAccessKeys.d.ts","sourceRoot":"","sources":["../../src/utilities/collectionAccessKeys.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD,eAAO,MAAM,oBAAoB,EAAE,aAQzB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/collectionAccessKeys.ts"],"sourcesContent":["import type { AllAccessKeys } from '../types.js'\n\nexport const collectionAccessKeys: AllAccessKeys = [\n 'create',\n 'read',\n 'update',\n 'delete',\n 'readVersions',\n 'unlock',\n 'validate',\n] as const\n"],"names":["collectionAccessKeys"],"mappings":"AAEA,OAAO,MAAMA,uBAAsC;IACjD;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAS"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Config } from 'payload';
|
|
2
|
+
import type { TenantAccessConfig } from './addCollectionAccess.js';
|
|
3
|
+
export declare const combineBaseAccessWithTenantAccess: ({ accessConfigBySlug, baseAccess, }: {
|
|
4
|
+
accessConfigBySlug: Map<string, TenantAccessConfig>;
|
|
5
|
+
baseAccess: Config['baseAccess'];
|
|
6
|
+
}) => Config['baseAccess'];
|
|
7
|
+
//# sourceMappingURL=combineBaseAccessWithTenantAccess.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combineBaseAccessWithTenantAccess.d.ts","sourceRoot":"","sources":["../../src/utilities/combineBaseAccessWithTenantAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAKlE,eAAO,MAAM,iCAAiC,wCAG3C;IACD,kBAAkB,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAA;IACnD,UAAU,EAAE,MAAM,CAAC,YAAY,CAAC,CAAA;CACjC,KAAG,MAAM,CAAC,YAAY,CA0CtB,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { collectionAccessKeys } from './collectionAccessKeys.js';
|
|
2
|
+
import { getTenantAccessResult } from './getTenantAccessResult.js';
|
|
3
|
+
export const combineBaseAccessWithTenantAccess = ({ accessConfigBySlug, baseAccess })=>{
|
|
4
|
+
const originalBaseAccess = baseAccess?.collections || {};
|
|
5
|
+
const collections = {
|
|
6
|
+
...originalBaseAccess
|
|
7
|
+
};
|
|
8
|
+
for (const accessKey of collectionAccessKeys){
|
|
9
|
+
const baseAccessFunction = originalBaseAccess[accessKey] ?? (accessKey === 'validate' ? originalBaseAccess.update : undefined);
|
|
10
|
+
collections[accessKey] = async (args)=>{
|
|
11
|
+
const baseResult = baseAccessFunction ? await baseAccessFunction(args) : true;
|
|
12
|
+
const accessConfig = accessConfigBySlug.get(args.slug);
|
|
13
|
+
if (!baseResult || !accessConfig) {
|
|
14
|
+
return baseResult;
|
|
15
|
+
}
|
|
16
|
+
if (accessKey === 'create' && typeof baseResult === 'object') {
|
|
17
|
+
return baseResult;
|
|
18
|
+
}
|
|
19
|
+
const tenantResult = await getTenantAccessResult({
|
|
20
|
+
...accessConfig,
|
|
21
|
+
accessKey,
|
|
22
|
+
accessResult: baseResult,
|
|
23
|
+
args,
|
|
24
|
+
fieldName: accessKey === 'readVersions' ? `version.${accessConfig.fieldName}` : accessConfig.fieldName
|
|
25
|
+
});
|
|
26
|
+
return accessKey === 'create' ? Boolean(tenantResult) : tenantResult;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
...baseAccess,
|
|
31
|
+
collections
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=combineBaseAccessWithTenantAccess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/combineBaseAccessWithTenantAccess.ts"],"sourcesContent":["import type { Config } from 'payload'\n\nimport type { TenantAccessConfig } from './addCollectionAccess.js'\n\nimport { collectionAccessKeys } from './collectionAccessKeys.js'\nimport { getTenantAccessResult } from './getTenantAccessResult.js'\n\nexport const combineBaseAccessWithTenantAccess = ({\n accessConfigBySlug,\n baseAccess,\n}: {\n accessConfigBySlug: Map<string, TenantAccessConfig>\n baseAccess: Config['baseAccess']\n}): Config['baseAccess'] => {\n const originalBaseAccess = baseAccess?.collections || {}\n const collections: NonNullable<NonNullable<Config['baseAccess']>['collections']> = {\n ...originalBaseAccess,\n }\n\n for (const accessKey of collectionAccessKeys) {\n const baseAccessFunction =\n originalBaseAccess[accessKey] ??\n (accessKey === 'validate' ? originalBaseAccess.update : undefined)\n\n collections[accessKey] = async (args) => {\n const baseResult = baseAccessFunction ? await baseAccessFunction(args) : true\n const accessConfig = accessConfigBySlug.get(args.slug)\n\n if (!baseResult || !accessConfig) {\n return baseResult\n }\n\n if (accessKey === 'create' && typeof baseResult === 'object') {\n return baseResult\n }\n\n const tenantResult = await getTenantAccessResult({\n ...accessConfig,\n accessKey,\n accessResult: baseResult,\n args,\n fieldName:\n accessKey === 'readVersions'\n ? `version.${accessConfig.fieldName}`\n : accessConfig.fieldName,\n })\n\n return accessKey === 'create' ? Boolean(tenantResult) : tenantResult\n }\n }\n\n return {\n ...baseAccess,\n collections,\n }\n}\n"],"names":["collectionAccessKeys","getTenantAccessResult","combineBaseAccessWithTenantAccess","accessConfigBySlug","baseAccess","originalBaseAccess","collections","accessKey","baseAccessFunction","update","undefined","args","baseResult","accessConfig","get","slug","tenantResult","accessResult","fieldName","Boolean"],"mappings":"AAIA,SAASA,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,qBAAqB,QAAQ,6BAA4B;AAElE,OAAO,MAAMC,oCAAoC,CAAC,EAChDC,kBAAkB,EAClBC,UAAU,EAIX;IACC,MAAMC,qBAAqBD,YAAYE,eAAe,CAAC;IACvD,MAAMA,cAA6E;QACjF,GAAGD,kBAAkB;IACvB;IAEA,KAAK,MAAME,aAAaP,qBAAsB;QAC5C,MAAMQ,qBACJH,kBAAkB,CAACE,UAAU,IAC5BA,CAAAA,cAAc,aAAaF,mBAAmBI,MAAM,GAAGC,SAAQ;QAElEJ,WAAW,CAACC,UAAU,GAAG,OAAOI;YAC9B,MAAMC,aAAaJ,qBAAqB,MAAMA,mBAAmBG,QAAQ;YACzE,MAAME,eAAeV,mBAAmBW,GAAG,CAACH,KAAKI,IAAI;YAErD,IAAI,CAACH,cAAc,CAACC,cAAc;gBAChC,OAAOD;YACT;YAEA,IAAIL,cAAc,YAAY,OAAOK,eAAe,UAAU;gBAC5D,OAAOA;YACT;YAEA,MAAMI,eAAe,MAAMf,sBAAsB;gBAC/C,GAAGY,YAAY;gBACfN;gBACAU,cAAcL;gBACdD;gBACAO,WACEX,cAAc,iBACV,CAAC,QAAQ,EAAEM,aAAaK,SAAS,EAAE,GACnCL,aAAaK,SAAS;YAC9B;YAEA,OAAOX,cAAc,WAAWY,QAAQH,gBAAgBA;QAC1D;IACF;IAEA,OAAO;QACL,GAAGZ,UAAU;QACbE;IACF;AACF,EAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CollectionConfig } from 'payload';
|
|
2
|
+
import type { TenantAccessConfig } from './addCollectionAccess.js';
|
|
3
|
+
export declare const combineCollectionAccessWithTenantAccess: (accessConfig: TenantAccessConfig) => CollectionConfig;
|
|
4
|
+
//# sourceMappingURL=combineCollectionAccessWithTenantAccess.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combineCollectionAccessWithTenantAccess.d.ts","sourceRoot":"","sources":["../../src/utilities/combineCollectionAccessWithTenantAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAKlE,eAAO,MAAM,uCAAuC,iBACpC,kBAAkB,KAC/B,gBA0BF,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { collectionAccessKeys } from './collectionAccessKeys.js';
|
|
2
|
+
import { getTenantAccessResult } from './getTenantAccessResult.js';
|
|
3
|
+
export const combineCollectionAccessWithTenantAccess = (accessConfig)=>{
|
|
4
|
+
const access = {
|
|
5
|
+
...accessConfig.collection.access
|
|
6
|
+
};
|
|
7
|
+
const updateAccessFallback = access.update;
|
|
8
|
+
for (const accessKey of collectionAccessKeys){
|
|
9
|
+
// A collection without its own `validate` access is governed by `update`, matching core's
|
|
10
|
+
// fallback contract, rather than the generic "any authenticated user" default below.
|
|
11
|
+
const accessFunction = accessConfig.collection.access?.[accessKey] ?? (accessKey === 'validate' ? updateAccessFallback : undefined) ?? (({ req })=>Boolean(req.user));
|
|
12
|
+
access[accessKey] = async (args)=>getTenantAccessResult({
|
|
13
|
+
...accessConfig,
|
|
14
|
+
accessKey,
|
|
15
|
+
accessResult: await accessFunction(args),
|
|
16
|
+
args,
|
|
17
|
+
fieldName: accessKey === 'readVersions' ? `version.${accessConfig.fieldName}` : accessConfig.fieldName
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
...accessConfig.collection,
|
|
22
|
+
access
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=combineCollectionAccessWithTenantAccess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/combineCollectionAccessWithTenantAccess.ts"],"sourcesContent":["import type { AccessArgs, CollectionConfig } from 'payload'\n\nimport type { TenantAccessConfig } from './addCollectionAccess.js'\n\nimport { collectionAccessKeys } from './collectionAccessKeys.js'\nimport { getTenantAccessResult } from './getTenantAccessResult.js'\n\nexport const combineCollectionAccessWithTenantAccess = (\n accessConfig: TenantAccessConfig,\n): CollectionConfig => {\n const access = { ...accessConfig.collection.access }\n const updateAccessFallback = access.update\n\n for (const accessKey of collectionAccessKeys) {\n // A collection without its own `validate` access is governed by `update`, matching core's\n // fallback contract, rather than the generic \"any authenticated user\" default below.\n const accessFunction =\n accessConfig.collection.access?.[accessKey] ??\n (accessKey === 'validate' ? updateAccessFallback : undefined) ??\n (({ req }: AccessArgs) => Boolean(req.user))\n\n access[accessKey] = async (args) =>\n getTenantAccessResult({\n ...accessConfig,\n accessKey,\n accessResult: await accessFunction(args),\n args,\n fieldName:\n accessKey === 'readVersions'\n ? `version.${accessConfig.fieldName}`\n : accessConfig.fieldName,\n })\n }\n\n return { ...accessConfig.collection, access }\n}\n"],"names":["collectionAccessKeys","getTenantAccessResult","combineCollectionAccessWithTenantAccess","accessConfig","access","collection","updateAccessFallback","update","accessKey","accessFunction","undefined","req","Boolean","user","args","accessResult","fieldName"],"mappings":"AAIA,SAASA,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,qBAAqB,QAAQ,6BAA4B;AAElE,OAAO,MAAMC,0CAA0C,CACrDC;IAEA,MAAMC,SAAS;QAAE,GAAGD,aAAaE,UAAU,CAACD,MAAM;IAAC;IACnD,MAAME,uBAAuBF,OAAOG,MAAM;IAE1C,KAAK,MAAMC,aAAaR,qBAAsB;QAC5C,0FAA0F;QAC1F,qFAAqF;QACrF,MAAMS,iBACJN,aAAaE,UAAU,CAACD,MAAM,EAAE,CAACI,UAAU,IAC1CA,CAAAA,cAAc,aAAaF,uBAAuBI,SAAQ,KAC1D,CAAA,CAAC,EAAEC,GAAG,EAAc,GAAKC,QAAQD,IAAIE,IAAI,CAAA;QAE5CT,MAAM,CAACI,UAAU,GAAG,OAAOM,OACzBb,sBAAsB;gBACpB,GAAGE,YAAY;gBACfK;gBACAO,cAAc,MAAMN,eAAeK;gBACnCA;gBACAE,WACER,cAAc,iBACV,CAAC,QAAQ,EAAEL,aAAaa,SAAS,EAAE,GACnCb,aAAaa,SAAS;YAC9B;IACJ;IAEA,OAAO;QAAE,GAAGb,aAAaE,UAAU;QAAED;IAAO;AAC9C,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combineFilters.d.ts","sourceRoot":"","sources":["../../src/utilities/combineFilters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAS,MAAM,SAAS,CAAA;AAEhD,KAAK,IAAI,GAAG;IACV,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,YAAY,EAAE,UAAU,CAAA;CACzB,CAAA;AACD;;;;GAIG;AACH,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"combineFilters.d.ts","sourceRoot":"","sources":["../../src/utilities/combineFilters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAS,MAAM,SAAS,CAAA;AAEhD,KAAK,IAAI,GAAG;IACV,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,YAAY,EAAE,UAAU,CAAA;CACzB,CAAA;AACD;;;;GAIG;AACH,eAAO,MAAM,cAAc,iCACM,IAAI,KAAG,UA8BrC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractID.d.ts","sourceRoot":"","sources":["../../src/utilities/extractID.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,eAAO,MAAM,SAAS,GAAI,MAAM,SAAS,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"extractID.d.ts","sourceRoot":"","sources":["../../src/utilities/extractID.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,eAAO,MAAM,SAAS,GAAI,MAAM,SAAS,MAAM,GAAG,MAAM,cAC1C,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,KAClC,MAMF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateCookie.d.ts","sourceRoot":"","sources":["../../src/utilities/generateCookie.ts"],"names":[],"mappings":"AAAA,KAAK,aAAa,GAAG;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,IAAI,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,oBAAoB,EAAE,OAAO,CAAA;IAC7B,QAAQ,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,QAAQ,CAAA;IACpC,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,KAAK,YAAY,GAAG;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA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AG,SAAS,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,oBAAoB,GAAG,OAAO,QACrD,aAAa,KAClB,oBAAoB,SAAS,IAAI,GAAG,YAAY,GAAG,MA6ErD,CAAA"}
|
|
@@ -3,6 +3,6 @@ type Args = {
|
|
|
3
3
|
collectionSlug: CollectionSlug;
|
|
4
4
|
payload: Payload;
|
|
5
5
|
};
|
|
6
|
-
export declare const getCollectionIDType: ({ collectionSlug, payload }: Args) =>
|
|
6
|
+
export declare const getCollectionIDType: ({ collectionSlug, payload }: Args) => 'number' | 'text';
|
|
7
7
|
export {};
|
|
8
8
|
//# sourceMappingURL=getCollectionIDType.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCollectionIDType.d.ts","sourceRoot":"","sources":["../../src/utilities/getCollectionIDType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtD,KAAK,IAAI,GAAG;IACV,cAAc,EAAE,cAAc,CAAA;IAC9B,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AACD,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"getCollectionIDType.d.ts","sourceRoot":"","sources":["../../src/utilities/getCollectionIDType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtD,KAAK,IAAI,GAAG;IACV,cAAc,EAAE,cAAc,CAAA;IAC9B,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AACD,eAAO,MAAM,mBAAmB,gCAAiC,IAAI,KAAG,QAAQ,GAAG,MAElF,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Payload, ServerAdapter,
|
|
1
|
+
import type { Payload, ServerAdapter, User, ViewTypes } from 'payload';
|
|
2
2
|
import type { MultiTenantPluginConfig } from '../types.js';
|
|
3
3
|
type Args = {
|
|
4
4
|
/**
|
|
@@ -17,8 +17,8 @@ type Args = {
|
|
|
17
17
|
tenantsArrayTenantFieldName: string;
|
|
18
18
|
tenantsCollectionSlug: string;
|
|
19
19
|
useAsTitle: string;
|
|
20
|
-
user?:
|
|
21
|
-
userHasAccessToAllTenants: Required<MultiTenantPluginConfig
|
|
20
|
+
user?: User;
|
|
21
|
+
userHasAccessToAllTenants: Required<MultiTenantPluginConfig>['userHasAccessToAllTenants'];
|
|
22
22
|
view: ViewTypes;
|
|
23
23
|
};
|
|
24
24
|
export declare function getGlobalViewRedirect({ slug: collectionSlug, docID, headers, payload, server, tenantFieldName, tenantsArrayFieldName, tenantsArrayTenantFieldName, tenantsCollectionSlug, useAsTitle, user, userHasAccessToAllTenants, view, }: Args): Promise<string | void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getGlobalViewRedirect.d.ts","sourceRoot":"","sources":["../../src/utilities/getGlobalViewRedirect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"getGlobalViewRedirect.d.ts","sourceRoot":"","sources":["../../src/utilities/getGlobalViewRedirect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAItE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAM1D,KAAK,IAAI,GAAG;IACV;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,aAAa,CAAA;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,eAAe,EAAE,MAAM,CAAA;IACvB,qBAAqB,EAAE,MAAM,CAAA;IAC7B,2BAA2B,EAAE,MAAM,CAAA;IACnC,qBAAqB,EAAE,MAAM,CAAA;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,yBAAyB,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAAC,2BAA2B,CAAC,CAAA;IACzF,IAAI,EAAE,SAAS,CAAA;CAChB,CAAA;AACD,wBAAsB,qBAAqB,CAAC,EAC1C,IAAI,EAAE,cAAc,EACpB,KAAK,EACL,OAAO,EACP,OAAO,EACP,MAAM,EACN,eAAe,EACf,qBAAqB,EACrB,2BAA2B,EAC3B,qBAAqB,EACrB,UAAU,EACV,IAAI,EACJ,yBAAyB,EACzB,IAAI,GACL,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA0G/B"}
|