@payloadcms/plugin-multi-tenant 4.0.0-internal.8ba6b5b → 4.0.0-internal.934870d

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.
Files changed (78) hide show
  1. package/dist/components/AssignTenantFieldModal/index.client.d.ts +2 -2
  2. package/dist/components/AssignTenantFieldModal/index.client.d.ts.map +1 -1
  3. package/dist/components/AssignTenantFieldModal/index.client.js.map +1 -1
  4. package/dist/components/GlobalViewRedirect/index.d.ts.map +1 -1
  5. package/dist/components/TenantField/index.client.d.ts.map +1 -1
  6. package/dist/components/TenantField/index.client.js +84 -74
  7. package/dist/components/TenantField/index.client.js.map +1 -1
  8. package/dist/components/TenantSelector/index.client.d.ts +1 -1
  9. package/dist/components/TenantSelector/index.client.d.ts.map +1 -1
  10. package/dist/components/TenantSelector/index.css +4 -4
  11. package/dist/components/TenantSelector/index.d.ts.map +1 -1
  12. package/dist/defaults.d.ts.map +1 -1
  13. package/dist/endpoints/getTenantOptionsEndpoint.d.ts +1 -1
  14. package/dist/endpoints/getTenantOptionsEndpoint.d.ts.map +1 -1
  15. package/dist/fields/tenantField/index.d.ts +4 -2
  16. package/dist/fields/tenantField/index.d.ts.map +1 -1
  17. package/dist/fields/tenantField/index.js +36 -9
  18. package/dist/fields/tenantField/index.js.map +1 -1
  19. package/dist/fields/tenantsArrayField/index.d.ts.map +1 -1
  20. package/dist/filters/filterDocumentsByTenants.d.ts.map +1 -1
  21. package/dist/hooks/afterTenantDelete.d.ts +1 -1
  22. package/dist/hooks/afterTenantDelete.d.ts.map +1 -1
  23. package/dist/hooks/afterTenantDelete.js +3 -0
  24. package/dist/hooks/afterTenantDelete.js.map +1 -1
  25. package/dist/hooks/enforceTenantMembership.d.ts +15 -0
  26. package/dist/hooks/enforceTenantMembership.d.ts.map +1 -0
  27. package/dist/hooks/enforceTenantMembership.js +39 -0
  28. package/dist/hooks/enforceTenantMembership.js.map +1 -0
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +26 -4
  31. package/dist/index.js.map +1 -1
  32. package/dist/providers/TenantSelectionProvider/index.client.d.ts.map +1 -1
  33. package/dist/providers/TenantSelectionProvider/index.client.js +22 -24
  34. package/dist/providers/TenantSelectionProvider/index.client.js.map +1 -1
  35. package/dist/providers/TenantSelectionProvider/index.d.ts.map +1 -1
  36. package/dist/translations/languages/en.d.ts.map +1 -1
  37. package/dist/types.d.ts +5 -3
  38. package/dist/types.d.ts.map +1 -1
  39. package/dist/types.js.map +1 -1
  40. package/dist/utilities/addCollectionAccess.d.ts +6 -8
  41. package/dist/utilities/addCollectionAccess.d.ts.map +1 -1
  42. package/dist/utilities/addCollectionAccess.js +99 -21
  43. package/dist/utilities/addCollectionAccess.js.map +1 -1
  44. package/dist/utilities/combineFilters.d.ts.map +1 -1
  45. package/dist/utilities/extractID.d.ts.map +1 -1
  46. package/dist/utilities/generateCookie.d.ts.map +1 -1
  47. package/dist/utilities/getCollectionIDType.d.ts +1 -1
  48. package/dist/utilities/getCollectionIDType.d.ts.map +1 -1
  49. package/dist/utilities/getGlobalViewRedirect.d.ts.map +1 -1
  50. package/dist/utilities/getGlobalViewRedirect.js +2 -0
  51. package/dist/utilities/getGlobalViewRedirect.js.map +1 -1
  52. package/dist/utilities/getTenantIDsFromValue.d.ts +2 -0
  53. package/dist/utilities/getTenantIDsFromValue.d.ts.map +1 -0
  54. package/dist/utilities/getTenantIDsFromValue.js +14 -0
  55. package/dist/utilities/getTenantIDsFromValue.js.map +1 -0
  56. package/dist/utilities/getTenantOptions.d.ts +1 -1
  57. package/dist/utilities/getTenantOptions.d.ts.map +1 -1
  58. package/dist/utilities/getUserTenantIDs.d.ts.map +1 -1
  59. package/dist/utilities/getUserTenantIDs.js +3 -2
  60. package/dist/utilities/getUserTenantIDs.js.map +1 -1
  61. package/dist/utilities/isValidTenantAssignment.d.ts +13 -0
  62. package/dist/utilities/isValidTenantAssignment.d.ts.map +1 -0
  63. package/dist/utilities/isValidTenantAssignment.js +28 -0
  64. package/dist/utilities/isValidTenantAssignment.js.map +1 -0
  65. package/dist/utilities/miniChalk.d.ts.map +1 -1
  66. package/dist/utilities/shouldRefreshTenantSelection.d.ts +5 -0
  67. package/dist/utilities/shouldRefreshTenantSelection.d.ts.map +1 -0
  68. package/dist/utilities/shouldRefreshTenantSelection.js +3 -0
  69. package/dist/utilities/shouldRefreshTenantSelection.js.map +1 -0
  70. package/package.json +7 -8
  71. package/dist/utilities/combineWhereConstraints.d.ts +0 -3
  72. package/dist/utilities/combineWhereConstraints.d.ts.map +0 -1
  73. package/dist/utilities/combineWhereConstraints.js +0 -19
  74. package/dist/utilities/combineWhereConstraints.js.map +0 -1
  75. package/dist/utilities/withTenantAccess.d.ts +0 -16
  76. package/dist/utilities/withTenantAccess.d.ts.map +0 -1
  77. package/dist/utilities/withTenantAccess.js +0 -76
  78. 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 User,\n} from 'payload'\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', or 'unlock'\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', or 'unlock'\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']\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":"AAiRA,WAMuD"}
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,7 +1,7 @@
1
- import type { CollectionConfig } from 'payload';
1
+ import type { CollectionConfig, Config } from 'payload';
2
2
  import type { AllAccessKeys, MultiTenantPluginConfig } from '../types.js';
3
3
  export declare const collectionAccessKeys: AllAccessKeys;
4
- type Args = {
4
+ export type TenantAccessConfig = {
5
5
  accessResultCallback?: MultiTenantPluginConfig['usersAccessResultOverride'];
6
6
  adminUsersSlug: string;
7
7
  collection: CollectionConfig;
@@ -10,10 +10,8 @@ type Args = {
10
10
  tenantsArrayTenantFieldName?: string;
11
11
  userHasAccessToAllTenants: Required<MultiTenantPluginConfig>['userHasAccessToAllTenants'];
12
12
  };
13
- /**
14
- * Adds tenant access constraint to collection
15
- * - constrains access a users assigned tenants
16
- */
17
- export declare const addCollectionAccess: ({ accessResultCallback, adminUsersSlug, collection, fieldName, tenantsArrayFieldName, tenantsArrayTenantFieldName, userHasAccessToAllTenants, }: Args) => void;
18
- export {};
13
+ export declare const addCollectionAccess: ({ config, scopes, }: {
14
+ config: Config;
15
+ scopes: TenantAccessConfig[];
16
+ }) => void;
19
17
  //# 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;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAIzE,eAAO,MAAM,oBAAoB,EAAE,aAOzB,CAAA;AAEV,KAAK,IAAI,GAAG;IACV,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;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAAI,iJAQjC,IAAI,KAAG,IAiBT,CAAA"}
1
+ {"version":3,"file":"addCollectionAccess.d.ts","sourceRoot":"","sources":["../../src/utilities/addCollectionAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA4B,gBAAgB,EAAE,MAAM,EAAe,MAAM,SAAS,CAAA;AAE9F,OAAO,KAAK,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAIzE,eAAO,MAAM,oBAAoB,EAAE,aAQzB,CAAA;AAEV,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;AA2ED,eAAO,MAAM,mBAAmB,wBAG7B;IACD,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,kBAAkB,EAAE,CAAA;CAC7B,KAAG,IAgDH,CAAA"}
@@ -1,32 +1,110 @@
1
- import { withTenantAccess } from './withTenantAccess.js';
1
+ import { getTenantAccess } from './getTenantAccess.js';
2
2
  export const collectionAccessKeys = [
3
3
  'create',
4
4
  'read',
5
5
  'update',
6
6
  'delete',
7
7
  'readVersions',
8
- 'unlock'
8
+ 'unlock',
9
+ 'validate'
9
10
  ];
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 = {};
17
- }
18
- collection.access[key] = withTenantAccess({
19
- accessFunction: collection.access?.[key],
20
- accessKey: key,
21
- accessResultCallback,
22
- adminUsersSlug,
23
- collection,
24
- fieldName: key === 'readVersions' ? `version.${fieldName}` : fieldName,
25
- tenantsArrayFieldName,
26
- tenantsArrayTenantFieldName,
27
- userHasAccessToAllTenants
28
- });
11
+ const getTenantAccessResult = ({ accessKey, accessResult, accessResultCallback, adminUsersSlug, args, collection, fieldName, tenantsArrayFieldName, tenantsArrayTenantFieldName, userHasAccessToAllTenants })=>{
12
+ const finish = (result)=>accessResultCallback ? accessResultCallback({
13
+ accessKey,
14
+ accessResult: result,
15
+ ...args
16
+ }) : result;
17
+ if (!accessResult) {
18
+ return finish(false);
19
+ }
20
+ const user = args.req.user;
21
+ if (!user || user.collection !== adminUsersSlug || userHasAccessToAllTenants(user)) {
22
+ return finish(accessResult);
23
+ }
24
+ const tenantConstraint = getTenantAccess({
25
+ fieldName,
26
+ tenantsArrayFieldName,
27
+ tenantsArrayTenantFieldName,
28
+ user
29
+ });
30
+ if (tenantConstraint[fieldName]?.in.length === 0) {
31
+ return finish(collection.slug === user.collection ? {
32
+ id: {
33
+ equals: user.id
34
+ }
35
+ } : false);
36
+ }
37
+ const tenantResult = collection.slug === user.collection ? {
38
+ or: [
39
+ {
40
+ id: {
41
+ equals: user.id
42
+ }
43
+ },
44
+ tenantConstraint
45
+ ]
46
+ } : tenantConstraint;
47
+ return finish(accessResult === true ? tenantResult : {
48
+ and: [
49
+ accessResult,
50
+ tenantResult
51
+ ]
29
52
  });
30
53
  };
54
+ const wrapCollectionAccess = (scope)=>{
55
+ scope.collection.access ??= {};
56
+ const updateAccessFallback = scope.collection.access.update;
57
+ for (const accessKey of collectionAccessKeys){
58
+ // A collection without its own `validate` access is governed by `update`, matching core's
59
+ // fallback contract, rather than the generic "any authenticated user" default below.
60
+ const accessFunction = scope.collection.access[accessKey] ?? (accessKey === 'validate' ? updateAccessFallback : undefined) ?? (({ req })=>Boolean(req.user));
61
+ scope.collection.access[accessKey] = async (args)=>getTenantAccessResult({
62
+ ...scope,
63
+ accessKey,
64
+ accessResult: await accessFunction(args),
65
+ args,
66
+ fieldName: accessKey === 'readVersions' ? `version.${scope.fieldName}` : scope.fieldName
67
+ });
68
+ }
69
+ };
70
+ export const addCollectionAccess = ({ config, scopes })=>{
71
+ const baseAccessScopes = new Map();
72
+ for (const scope of scopes){
73
+ if (scope.accessResultCallback) {
74
+ wrapCollectionAccess(scope);
75
+ } else {
76
+ baseAccessScopes.set(scope.collection.slug, scope);
77
+ }
78
+ }
79
+ if (!baseAccessScopes.size) {
80
+ return;
81
+ }
82
+ config.baseAccess ??= {};
83
+ config.baseAccess.collections ??= {};
84
+ const originalBaseAccess = {
85
+ ...config.baseAccess.collections
86
+ };
87
+ for (const accessKey of collectionAccessKeys){
88
+ const baseAccessFunction = originalBaseAccess[accessKey] ?? (accessKey === 'validate' ? originalBaseAccess.update : undefined);
89
+ config.baseAccess.collections[accessKey] = async (args)=>{
90
+ const baseResult = baseAccessFunction ? await baseAccessFunction(args) : true;
91
+ const scope = baseAccessScopes.get(args.slug);
92
+ if (!baseResult || !scope) {
93
+ return baseResult;
94
+ }
95
+ if (accessKey === 'create' && typeof baseResult === 'object') {
96
+ return baseResult;
97
+ }
98
+ const tenantResult = await getTenantAccessResult({
99
+ ...scope,
100
+ accessKey,
101
+ accessResult: baseResult,
102
+ args,
103
+ fieldName: accessKey === 'readVersions' ? `version.${scope.fieldName}` : scope.fieldName
104
+ });
105
+ return accessKey === 'create' ? Boolean(tenantResult) : tenantResult;
106
+ };
107
+ }
108
+ };
31
109
 
32
110
  //# sourceMappingURL=addCollectionAccess.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/addCollectionAccess.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\n\nimport type { AllAccessKeys, MultiTenantPluginConfig } from '../types.js'\n\nimport { withTenantAccess } from './withTenantAccess.js'\n\nexport const collectionAccessKeys: AllAccessKeys = [\n 'create',\n 'read',\n 'update',\n 'delete',\n 'readVersions',\n 'unlock',\n] as const\n\ntype Args = {\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\n/**\n * Adds tenant access constraint to collection\n * - constrains access a users assigned tenants\n */\nexport const addCollectionAccess = ({\n accessResultCallback,\n adminUsersSlug,\n collection,\n fieldName,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n userHasAccessToAllTenants,\n}: Args): void => {\n collectionAccessKeys.forEach((key) => {\n if (!collection.access) {\n collection.access = {}\n }\n collection.access[key] = withTenantAccess({\n accessFunction: collection.access?.[key],\n accessKey: key,\n accessResultCallback,\n adminUsersSlug,\n collection,\n fieldName: key === 'readVersions' ? `version.${fieldName}` : fieldName,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n userHasAccessToAllTenants,\n })\n })\n}\n"],"names":["withTenantAccess","collectionAccessKeys","addCollectionAccess","accessResultCallback","adminUsersSlug","collection","fieldName","tenantsArrayFieldName","tenantsArrayTenantFieldName","userHasAccessToAllTenants","forEach","key","access","accessFunction","accessKey"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,wBAAuB;AAExD,OAAO,MAAMC,uBAAsC;IACjD;IACA;IACA;IACA;IACA;IACA;CACD,CAAS;AAYV;;;CAGC,GACD,OAAO,MAAMC,sBAAsB,CAAC,EAClCC,oBAAoB,EACpBC,cAAc,EACdC,UAAU,EACVC,SAAS,EACTC,qBAAqB,EACrBC,2BAA2B,EAC3BC,yBAAyB,EACpB;IACLR,qBAAqBS,OAAO,CAAC,CAACC;QAC5B,IAAI,CAACN,WAAWO,MAAM,EAAE;YACtBP,WAAWO,MAAM,GAAG,CAAC;QACvB;QACAP,WAAWO,MAAM,CAACD,IAAI,GAAGX,iBAAiB;YACxCa,gBAAgBR,WAAWO,MAAM,EAAE,CAACD,IAAI;YACxCG,WAAWH;YACXR;YACAC;YACAC;YACAC,WAAWK,QAAQ,iBAAiB,CAAC,QAAQ,EAAEL,WAAW,GAAGA;YAC7DC;YACAC;YACAC;QACF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/addCollectionAccess.ts"],"sourcesContent":["import type { AccessArgs, AccessResult, CollectionConfig, Config, User, Where } from 'payload'\n\nimport type { AllAccessKeys, MultiTenantPluginConfig } from '../types.js'\n\nimport { getTenantAccess } from './getTenantAccess.js'\n\nexport const collectionAccessKeys: AllAccessKeys = [\n 'create',\n 'read',\n 'update',\n 'delete',\n 'readVersions',\n 'unlock',\n 'validate',\n] as const\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\nconst getTenantAccessResult = ({\n accessKey,\n accessResult,\n accessResultCallback,\n adminUsersSlug,\n args,\n collection,\n fieldName,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n userHasAccessToAllTenants,\n}: {\n accessKey: AllAccessKeys[number]\n accessResult: AccessResult\n args: AccessArgs\n} & TenantAccessConfig): AccessResult | Promise<AccessResult> => {\n const finish = (result: AccessResult): AccessResult | Promise<AccessResult> =>\n accessResultCallback\n ? accessResultCallback({ accessKey, accessResult: result, ...args })\n : result\n\n if (!accessResult) {\n return finish(false)\n }\n\n const user = args.req.user\n\n if (!user || user.collection !== adminUsersSlug || userHasAccessToAllTenants(user as User)) {\n return finish(accessResult)\n }\n\n const tenantConstraint = getTenantAccess({\n fieldName,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n user,\n })\n\n if (tenantConstraint[fieldName]?.in.length === 0) {\n return finish(collection.slug === user.collection ? { id: { equals: user.id } } : false)\n }\n\n const tenantResult: Where =\n collection.slug === user.collection\n ? { or: [{ id: { equals: user.id } }, tenantConstraint] }\n : tenantConstraint\n\n return finish(accessResult === true ? tenantResult : { and: [accessResult, tenantResult] })\n}\n\nconst wrapCollectionAccess = (scope: TenantAccessConfig): void => {\n scope.collection.access ??= {}\n const updateAccessFallback = scope.collection.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 scope.collection.access[accessKey] ??\n (accessKey === 'validate' ? updateAccessFallback : undefined) ??\n (({ req }: AccessArgs) => Boolean(req.user))\n\n scope.collection.access[accessKey] = async (args) =>\n getTenantAccessResult({\n ...scope,\n accessKey,\n accessResult: await accessFunction(args),\n args,\n fieldName: accessKey === 'readVersions' ? `version.${scope.fieldName}` : scope.fieldName,\n })\n }\n}\n\nexport const addCollectionAccess = ({\n config,\n scopes,\n}: {\n config: Config\n scopes: TenantAccessConfig[]\n}): void => {\n const baseAccessScopes = new Map<string, TenantAccessConfig>()\n\n for (const scope of scopes) {\n if (scope.accessResultCallback) {\n wrapCollectionAccess(scope)\n } else {\n baseAccessScopes.set(scope.collection.slug, scope)\n }\n }\n\n if (!baseAccessScopes.size) {\n return\n }\n\n config.baseAccess ??= {}\n config.baseAccess.collections ??= {}\n\n const originalBaseAccess = { ...config.baseAccess.collections }\n\n for (const accessKey of collectionAccessKeys) {\n const baseAccessFunction =\n originalBaseAccess[accessKey] ??\n (accessKey === 'validate' ? originalBaseAccess.update : undefined)\n\n config.baseAccess.collections[accessKey] = async (args) => {\n const baseResult = baseAccessFunction ? await baseAccessFunction(args) : true\n const scope = baseAccessScopes.get(args.slug)\n\n if (!baseResult || !scope) {\n return baseResult\n }\n\n if (accessKey === 'create' && typeof baseResult === 'object') {\n return baseResult\n }\n\n const tenantResult = await getTenantAccessResult({\n ...scope,\n accessKey,\n accessResult: baseResult,\n args,\n fieldName: accessKey === 'readVersions' ? `version.${scope.fieldName}` : scope.fieldName,\n })\n\n return accessKey === 'create' ? Boolean(tenantResult) : tenantResult\n }\n }\n}\n"],"names":["getTenantAccess","collectionAccessKeys","getTenantAccessResult","accessKey","accessResult","accessResultCallback","adminUsersSlug","args","collection","fieldName","tenantsArrayFieldName","tenantsArrayTenantFieldName","userHasAccessToAllTenants","finish","result","user","req","tenantConstraint","in","length","slug","id","equals","tenantResult","or","and","wrapCollectionAccess","scope","access","updateAccessFallback","update","accessFunction","undefined","Boolean","addCollectionAccess","config","scopes","baseAccessScopes","Map","set","size","baseAccess","collections","originalBaseAccess","baseAccessFunction","baseResult","get"],"mappings":"AAIA,SAASA,eAAe,QAAQ,uBAAsB;AAEtD,OAAO,MAAMC,uBAAsC;IACjD;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAS;AAYV,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AI1C,cAAc,YAAY,OAAO0C,eAAe,UAAU;gBAC5D,OAAOA;YACT;YAEA,MAAMtB,eAAe,MAAMrB,sBAAsB;gBAC/C,GAAGyB,KAAK;gBACRxB;gBACAC,cAAcyC;gBACdtC;gBACAE,WAAWN,cAAc,iBAAiB,CAAC,QAAQ,EAAEwB,MAAMlB,SAAS,EAAE,GAAGkB,MAAMlB,SAAS;YAC1F;YAEA,OAAON,cAAc,WAAW8B,QAAQV,gBAAgBA;QAC1D;IACF;AACF,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,GACxB,8BAA8B,IAAI,KAAG,UA8BrC,CAAA"}
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,EACtD,YAAY,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,KAClC,MAMF,CAAA"}
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;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,QAAQ,CAAA;IACpC,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,oBAAoB,GAAG,OAAO,EAC3D,MAAM,aAAa,KAClB,oBAAoB,SAAS,IAAI,GAAG,YAAY,GAAG,MA6ErD,CAAA"}
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;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,QAAQ,CAAA;IACpC,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,MAAM,GAAG,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) => "number" | "text";
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,GAAI,6BAA6B,IAAI,KAAG,QAAQ,GAAG,MAElF,CAAA"}
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 +1 @@
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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AI,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,CAoG/B"}
@@ -30,6 +30,7 @@ export async function getGlobalViewRedirect({ slug: collectionSlug, docID, heade
30
30
  collection: collectionSlug,
31
31
  depth: 0,
32
32
  limit: 1,
33
+ overrideAccess: true,
33
34
  pagination: false,
34
35
  select: {
35
36
  id: true
@@ -113,6 +114,7 @@ export async function getGlobalViewRedirect({ slug: collectionSlug, docID, heade
113
114
  },
114
115
  depth: 0,
115
116
  draft: true,
117
+ overrideAccess: true,
116
118
  select: {
117
119
  id: true
118
120
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/getGlobalViewRedirect.ts"],"sourcesContent":["import type { Payload, ServerAdapter, User, ViewTypes } from 'payload'\n\nimport { formatAdminURL, hasAutosaveEnabled } from 'payload/shared'\n\nimport type { MultiTenantPluginConfig } from '../types.js'\n\nimport { getCollectionIDType } from './getCollectionIDType.js'\nimport { getTenantFromCookie } from './getTenantFromCookie.js'\nimport { getTenantOptions } from './getTenantOptions.js'\n\ntype Args = {\n /**\n * This is no longer needed and is handled internally.\n *\n * @deprecated\n */\n basePath?: string\n docID?: number | string\n headers: Headers\n payload: Payload\n server: ServerAdapter\n slug: string\n tenantFieldName: string\n tenantsArrayFieldName: string\n tenantsArrayTenantFieldName: string\n tenantsCollectionSlug: string\n useAsTitle: string\n user?: User\n userHasAccessToAllTenants: Required<MultiTenantPluginConfig>['userHasAccessToAllTenants']\n view: ViewTypes\n}\nexport async function getGlobalViewRedirect({\n slug: collectionSlug,\n docID,\n headers,\n payload,\n server,\n tenantFieldName,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n useAsTitle,\n user,\n userHasAccessToAllTenants,\n view,\n}: Args): Promise<string | void> {\n const idType = getCollectionIDType({\n collectionSlug: tenantsCollectionSlug,\n payload,\n })\n let tenant = getTenantFromCookie(headers, idType)\n let redirectRoute: `/${string}` | void = undefined\n\n if (!user) {\n return server.unauthorized()\n }\n\n if (!tenant) {\n const tenantOptions = await getTenantOptions({\n payload,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n useAsTitle,\n user,\n userHasAccessToAllTenants,\n })\n\n tenant = tenantOptions[0]?.value || null\n }\n\n if (tenant) {\n try {\n const globalTenantDocQuery = await payload.find({\n collection: collectionSlug,\n depth: 0,\n limit: 1,\n pagination: false,\n select: {\n id: true,\n },\n where: {\n [tenantFieldName]: {\n in: [tenant],\n },\n },\n })\n\n const globalTenantDocID = globalTenantDocQuery?.docs?.[0]?.id\n\n if (view === 'document') {\n // global tenant document edit view\n if (globalTenantDocID && docID !== globalTenantDocID) {\n // tenant document already exists but does not match current route docID\n // redirect to matching tenant docID from query\n redirectRoute = `/collections/${collectionSlug}/${globalTenantDocID}`\n } else if (docID && !globalTenantDocID) {\n // a docID was found in the route but no global document with this tenant exists\n // so we need to generate a redirect to the create route\n redirectRoute = await generateCreateRedirect({\n collectionSlug,\n payload,\n tenantID: tenant,\n })\n }\n } else if (view === 'list') {\n // global tenant document list view\n if (globalTenantDocID) {\n // tenant document exists, redirect from list view to the document edit view\n redirectRoute = `/collections/${collectionSlug}/${globalTenantDocID}`\n } else {\n // no matching document was found for the current tenant\n // so we need to generate a redirect to the create route\n redirectRoute = await generateCreateRedirect({\n collectionSlug,\n payload,\n tenantID: tenant,\n })\n }\n }\n } catch (e: unknown) {\n const prefix = `${e && typeof e === 'object' && 'message' in e && typeof e.message === 'string' ? `${e.message} - ` : ''}`\n payload.logger.error(e, `${prefix}Multi Tenant Redirect Error`)\n }\n } else {\n // no tenants were found, redirect to the admin view\n return formatAdminURL({\n adminRoute: payload.config.routes.admin,\n path: '',\n serverURL: payload.config.serverURL,\n })\n }\n\n if (redirectRoute) {\n return formatAdminURL({\n adminRoute: payload.config.routes.admin,\n path: redirectRoute,\n serverURL: payload.config.serverURL,\n })\n }\n\n // no redirect is needed\n // the current route is valid\n return undefined\n}\n\ntype GenerateCreateArgs = {\n collectionSlug: string\n payload: Payload\n tenantID: number | string\n}\n/**\n * Generate a redirect URL for creating a new document in a multi-tenant collection.\n *\n * If autosave is enabled on the collection, we need to create the document and then redirect to it.\n * Otherwise we can redirect to the default create route.\n */\nasync function generateCreateRedirect({\n collectionSlug,\n payload,\n tenantID,\n}: GenerateCreateArgs): Promise<`/${string}` | undefined> {\n const collectionConfig = payload.collections[collectionSlug]?.config\n if (hasAutosaveEnabled(collectionConfig!)) {\n // Autosave is enabled, create a document first\n try {\n const doc = await payload.create({\n collection: collectionSlug,\n data: {\n tenant: tenantID,\n },\n depth: 0,\n draft: true,\n select: {\n id: true,\n },\n })\n return `/collections/${collectionSlug}/${doc.id}`\n } catch (error) {\n payload.logger.error(\n error,\n `Error creating autosave global multi tenant document for ${collectionSlug}`,\n )\n }\n\n return '/'\n }\n\n // Autosave is not enabled, redirect to default create route\n return `/collections/${collectionSlug}/create`\n}\n"],"names":["formatAdminURL","hasAutosaveEnabled","getCollectionIDType","getTenantFromCookie","getTenantOptions","getGlobalViewRedirect","slug","collectionSlug","docID","headers","payload","server","tenantFieldName","tenantsArrayFieldName","tenantsArrayTenantFieldName","tenantsCollectionSlug","useAsTitle","user","userHasAccessToAllTenants","view","idType","tenant","redirectRoute","undefined","unauthorized","tenantOptions","value","globalTenantDocQuery","find","collection","depth","limit","pagination","select","id","where","in","globalTenantDocID","docs","generateCreateRedirect","tenantID","e","prefix","message","logger","error","adminRoute","config","routes","admin","path","serverURL","collectionConfig","collections","doc","create","data","draft"],"mappings":"AAEA,SAASA,cAAc,EAAEC,kBAAkB,QAAQ,iBAAgB;AAInE,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,gBAAgB,QAAQ,wBAAuB;AAuBxD,OAAO,eAAeC,sBAAsB,EAC1CC,MAAMC,cAAc,EACpBC,KAAK,EACLC,OAAO,EACPC,OAAO,EACPC,MAAM,EACNC,eAAe,EACfC,qBAAqB,EACrBC,2BAA2B,EAC3BC,qBAAqB,EACrBC,UAAU,EACVC,IAAI,EACJC,yBAAyB,EACzBC,IAAI,EACC;IACL,MAAMC,SAASlB,oBAAoB;QACjCK,gBAAgBQ;QAChBL;IACF;IACA,IAAIW,SAASlB,oBAAoBM,SAASW;IAC1C,IAAIE,gBAAqCC;IAEzC,IAAI,CAACN,MAAM;QACT,OAAON,OAAOa,YAAY;IAC5B;IAEA,IAAI,CAACH,QAAQ;QACX,MAAMI,gBAAgB,MAAMrB,iBAAiB;YAC3CM;YACAG;YACAC;YACAC;YACAC;YACAC;YACAC;QACF;QAEAG,SAASI,aAAa,CAAC,EAAE,EAAEC,SAAS;IACtC;IAEA,IAAIL,QAAQ;QACV,IAAI;YACF,MAAMM,uBAAuB,MAAMjB,QAAQkB,IAAI,CAAC;gBAC9CC,YAAYtB;gBACZuB,OAAO;gBACPC,OAAO;gBACPC,YAAY;gBACZC,QAAQ;oBACNC,IAAI;gBACN;gBACAC,OAAO;oBACL,CAACvB,gBAAgB,EAAE;wBACjBwB,IAAI;4BAACf;yBAAO;oBACd;gBACF;YACF;YAEA,MAAMgB,oBAAoBV,sBAAsBW,MAAM,CAAC,EAAE,EAAEJ;YAE3D,IAAIf,SAAS,YAAY;gBACvB,mCAAmC;gBACnC,IAAIkB,qBAAqB7B,UAAU6B,mBAAmB;oBACpD,wEAAwE;oBACxE,+CAA+C;oBAC/Cf,gBAAgB,CAAC,aAAa,EAA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CAAC9C,eAAe,EAAEwC;IAC9D,IAAI9C,mBAAmBmD,mBAAoB;QACzC,+CAA+C;QAC/C,IAAI;YACF,MAAME,MAAM,MAAM5C,QAAQ6C,MAAM,CAAC;gBAC/B1B,YAAYtB;gBACZiD,MAAM;oBACJnC,QAAQmB;gBACV;gBACAV,OAAO;gBACP2B,OAAO;gBACPxB,QAAQ;oBACNC,IAAI;gBACN;YACF;YACA,OAAO,CAAC,aAAa,EAAE3B,eAAe,CAAC,EAAE+C,IAAIpB,EAAE,EAAE;QACnD,EAAE,OAAOW,OAAO;YACdnC,QAAQkC,MAAM,CAACC,KAAK,CAClBA,OACA,CAAC,yDAAyD,EAAEtC,gBAAgB;QAEhF;QAEA,OAAO;IACT;IAEA,4DAA4D;IAC5D,OAAO,CAAC,aAAa,EAAEA,eAAe,OAAO,CAAC;AAChD"}
1
+ {"version":3,"sources":["../../src/utilities/getGlobalViewRedirect.ts"],"sourcesContent":["import type { Payload, ServerAdapter, User, ViewTypes } from 'payload'\n\nimport { formatAdminURL, hasAutosaveEnabled } from 'payload/shared'\n\nimport type { MultiTenantPluginConfig } from '../types.js'\n\nimport { getCollectionIDType } from './getCollectionIDType.js'\nimport { getTenantFromCookie } from './getTenantFromCookie.js'\nimport { getTenantOptions } from './getTenantOptions.js'\n\ntype Args = {\n /**\n * This is no longer needed and is handled internally.\n *\n * @deprecated\n */\n basePath?: string\n docID?: number | string\n headers: Headers\n payload: Payload\n server: ServerAdapter\n slug: string\n tenantFieldName: string\n tenantsArrayFieldName: string\n tenantsArrayTenantFieldName: string\n tenantsCollectionSlug: string\n useAsTitle: string\n user?: User\n userHasAccessToAllTenants: Required<MultiTenantPluginConfig>['userHasAccessToAllTenants']\n view: ViewTypes\n}\nexport async function getGlobalViewRedirect({\n slug: collectionSlug,\n docID,\n headers,\n payload,\n server,\n tenantFieldName,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n useAsTitle,\n user,\n userHasAccessToAllTenants,\n view,\n}: Args): Promise<string | void> {\n const idType = getCollectionIDType({\n collectionSlug: tenantsCollectionSlug,\n payload,\n })\n let tenant = getTenantFromCookie(headers, idType)\n let redirectRoute: `/${string}` | void = undefined\n\n if (!user) {\n return server.unauthorized()\n }\n\n if (!tenant) {\n const tenantOptions = await getTenantOptions({\n payload,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n useAsTitle,\n user,\n userHasAccessToAllTenants,\n })\n\n tenant = tenantOptions[0]?.value || null\n }\n\n if (tenant) {\n try {\n const globalTenantDocQuery = await payload.find({\n collection: collectionSlug,\n depth: 0,\n limit: 1,\n overrideAccess: true,\n pagination: false,\n select: {\n id: true,\n },\n where: {\n [tenantFieldName]: {\n in: [tenant],\n },\n },\n })\n\n const globalTenantDocID = globalTenantDocQuery?.docs?.[0]?.id\n\n if (view === 'document') {\n // global tenant document edit view\n if (globalTenantDocID && docID !== globalTenantDocID) {\n // tenant document already exists but does not match current route docID\n // redirect to matching tenant docID from query\n redirectRoute = `/collections/${collectionSlug}/${globalTenantDocID}`\n } else if (docID && !globalTenantDocID) {\n // a docID was found in the route but no global document with this tenant exists\n // so we need to generate a redirect to the create route\n redirectRoute = await generateCreateRedirect({\n collectionSlug,\n payload,\n tenantID: tenant,\n })\n }\n } else if (view === 'list') {\n // global tenant document list view\n if (globalTenantDocID) {\n // tenant document exists, redirect from list view to the document edit view\n redirectRoute = `/collections/${collectionSlug}/${globalTenantDocID}`\n } else {\n // no matching document was found for the current tenant\n // so we need to generate a redirect to the create route\n redirectRoute = await generateCreateRedirect({\n collectionSlug,\n payload,\n tenantID: tenant,\n })\n }\n }\n } catch (e: unknown) {\n const prefix = `${e && typeof e === 'object' && 'message' in e && typeof e.message === 'string' ? `${e.message} - ` : ''}`\n payload.logger.error(e, `${prefix}Multi Tenant Redirect Error`)\n }\n } else {\n // no tenants were found, redirect to the admin view\n return formatAdminURL({\n adminRoute: payload.config.routes.admin,\n path: '',\n serverURL: payload.config.serverURL,\n })\n }\n\n if (redirectRoute) {\n return formatAdminURL({\n adminRoute: payload.config.routes.admin,\n path: redirectRoute,\n serverURL: payload.config.serverURL,\n })\n }\n\n // no redirect is needed\n // the current route is valid\n return undefined\n}\n\ntype GenerateCreateArgs = {\n collectionSlug: string\n payload: Payload\n tenantID: number | string\n}\n/**\n * Generate a redirect URL for creating a new document in a multi-tenant collection.\n *\n * If autosave is enabled on the collection, we need to create the document and then redirect to it.\n * Otherwise we can redirect to the default create route.\n */\nasync function generateCreateRedirect({\n collectionSlug,\n payload,\n tenantID,\n}: GenerateCreateArgs): Promise<`/${string}` | undefined> {\n const collectionConfig = payload.collections[collectionSlug]?.config\n if (hasAutosaveEnabled(collectionConfig!)) {\n // Autosave is enabled, create a document first\n try {\n const doc = await payload.create({\n collection: collectionSlug,\n data: {\n tenant: tenantID,\n },\n depth: 0,\n draft: true,\n overrideAccess: true,\n select: {\n id: true,\n },\n })\n return `/collections/${collectionSlug}/${doc.id}`\n } catch (error) {\n payload.logger.error(\n error,\n `Error creating autosave global multi tenant document for ${collectionSlug}`,\n )\n }\n\n return '/'\n }\n\n // Autosave is not enabled, redirect to default create route\n return `/collections/${collectionSlug}/create`\n}\n"],"names":["formatAdminURL","hasAutosaveEnabled","getCollectionIDType","getTenantFromCookie","getTenantOptions","getGlobalViewRedirect","slug","collectionSlug","docID","headers","payload","server","tenantFieldName","tenantsArrayFieldName","tenantsArrayTenantFieldName","tenantsCollectionSlug","useAsTitle","user","userHasAccessToAllTenants","view","idType","tenant","redirectRoute","undefined","unauthorized","tenantOptions","value","globalTenantDocQuery","find","collection","depth","limit","overrideAccess","pagination","select","id","where","in","globalTenantDocID","docs","generateCreateRedirect","tenantID","e","prefix","message","logger","error","adminRoute","config","routes","admin","path","serverURL","collectionConfig","collections","doc","create","data","draft"],"mappings":"AAEA,SAASA,cAAc,EAAEC,kBAAkB,QAAQ,iBAAgB;AAInE,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,m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,CAAC;gBAC/B3B,YAAYtB;gBACZkD,MAAM;oBACJpC,QAAQoB;gBACV;gBACAX,OAAO;gBACP4B,OAAO;gBACP1B,gBAAgB;gBAChBE,QAAQ;oBACNC,IAAI;gBACN;YACF;YACA,OAAO,CAAC,aAAa,EAAE5B,eAAe,CAAC,EAAEgD,IAAIpB,EAAE,EAAE;QACnD,EAAE,OAAOW,OAAO;YACdpC,QAAQmC,MAAM,CAACC,KAAK,CAClBA,OACA,CAAC,yDAAyD,EAAEvC,gBAAgB;QAEhF;QAEA,OAAO;IACT;IAEA,4DAA4D;IAC5D,OAAO,CAAC,aAAa,EAAEA,eAAe,OAAO,CAAC;AAChD"}
@@ -0,0 +1,2 @@
1
+ export declare const getTenantIDsFromValue: (value: unknown) => string[];
2
+ //# sourceMappingURL=getTenantIDsFromValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getTenantIDsFromValue.d.ts","sourceRoot":"","sources":["../../src/utilities/getTenantIDsFromValue.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,qBAAqB,UAAW,OAAO,KAAG,MAAM,EAU5D,CAAA"}
@@ -0,0 +1,14 @@
1
+ import { extractID } from './extractID.js';
2
+ export const getTenantIDsFromValue = (value)=>{
3
+ if (value === undefined || value === null) {
4
+ return [];
5
+ }
6
+ return (Array.isArray(value) ? value : [
7
+ value
8
+ ]).map((entry)=>{
9
+ const id = entry === null || entry === undefined ? undefined : extractID(entry);
10
+ return typeof id === 'number' || typeof id === 'string' ? String(id) : '';
11
+ });
12
+ };
13
+
14
+ //# sourceMappingURL=getTenantIDsFromValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/getTenantIDsFromValue.ts"],"sourcesContent":["import type { Tenant } from '../types.js'\n\nimport { extractID } from './extractID.js'\n\nexport const getTenantIDsFromValue = (value: unknown): string[] => {\n if (value === undefined || value === null) {\n return []\n }\n\n return (Array.isArray(value) ? value : [value]).map((entry) => {\n const id = entry === null || entry === undefined ? undefined : extractID(entry as Tenant)\n\n return typeof id === 'number' || typeof id === 'string' ? String(id) : ''\n })\n}\n"],"names":["extractID","getTenantIDsFromValue","value","undefined","Array","isArray","map","entry","id","String"],"mappings":"AAEA,SAASA,SAAS,QAAQ,iBAAgB;AAE1C,OAAO,MAAMC,wBAAwB,CAACC;IACpC,IAAIA,UAAUC,aAAaD,UAAU,MAAM;QACzC,OAAO,EAAE;IACX;IAEA,OAAO,AAACE,CAAAA,MAAMC,OAAO,CAACH,SAASA,QAAQ;QAACA;KAAM,AAAD,EAAGI,GAAG,CAAC,CAACC;QACnD,MAAMC,KAAKD,UAAU,QAAQA,UAAUJ,YAAYA,YAAYH,UAAUO;QAEzE,OAAO,OAAOC,OAAO,YAAY,OAAOA,OAAO,WAAWC,OAAOD,MAAM;IACzE;AACF,EAAC"}
@@ -7,6 +7,6 @@ export declare const getTenantOptions: ({ payload, tenantsArrayFieldName, tenant
7
7
  tenantsCollectionSlug: string;
8
8
  useAsTitle: string;
9
9
  user: User;
10
- userHasAccessToAllTenants: Required<MultiTenantPluginConfig>["userHasAccessToAllTenants"];
10
+ userHasAccessToAllTenants: Required<MultiTenantPluginConfig>['userHasAccessToAllTenants'];
11
11
  }) => Promise<OptionObject[]>;
12
12
  //# sourceMappingURL=getTenantOptions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getTenantOptions.d.ts","sourceRoot":"","sources":["../../src/utilities/getTenantOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAE1D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAE1D,eAAO,MAAM,gBAAgB,GAAU,sIAQpC;IACD,OAAO,EAAE,OAAO,CAAA;IAChB,qBAAqB,EAAE,MAAM,CAAA;IAC7B,2BAA2B,EAAE,MAAM,CAAA;IACnC,qBAAqB,EAAE,MAAM,CAAA;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,IAAI,CAAA;IACV,yBAAyB,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAAC,2BAA2B,CAAC,CAAA;CAC1F,KAAG,OAAO,CAAC,YAAY,EAAE,CAuDzB,CAAA"}
1
+ {"version":3,"file":"getTenantOptions.d.ts","sourceRoot":"","sources":["../../src/utilities/getTenantOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAE1D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAE1D,eAAO,MAAM,gBAAgB,yIAQ1B;IACD,OAAO,EAAE,OAAO,CAAA;IAChB,qBAAqB,EAAE,MAAM,CAAA;IAC7B,2BAA2B,EAAE,MAAM,CAAA;IACnC,qBAAqB,EAAE,MAAM,CAAA;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,IAAI,CAAA;IACV,yBAAyB,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAAC,2BAA2B,CAAC,CAAA;CAC1F,KAAG,OAAO,CAAC,YAAY,EAAE,CAuDzB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"getUserTenantIDs.d.ts","sourceRoot":"","sources":["../../src/utilities/getUserTenantIDs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAK/D;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,SAAS,MAAM,GAAG,MAAM,EAC7D,MAAM,IAAI,GAAG,oBAAoB,EACjC,UAAU;IACR,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,2BAA2B,CAAC,EAAE,MAAM,CAAA;CACrC,KACA,MAAM,EAoBR,CAAA"}
1
+ {"version":3,"file":"getUserTenantIDs.d.ts","sourceRoot":"","sources":["../../src/utilities/getUserTenantIDs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAK/D;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,SAAS,MAAM,GAAG,MAAM,QACvD,IAAI,GAAG,oBAAoB,YACvB;IACR,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,2BAA2B,CAAC,EAAE,MAAM,CAAA;CACrC,KACA,MAAM,EAqBR,CAAA"}
@@ -12,8 +12,9 @@ import { extractID } from './extractID.js';
12
12
  const tenantsArrayTenantFieldName = options?.tenantsArrayTenantFieldName || defaults.tenantsArrayTenantFieldName;
13
13
  const tenantsArray = user[tenantsArrayFieldName];
14
14
  return (Array.isArray(tenantsArray) ? tenantsArray : [])?.reduce((acc, row)=>{
15
- if (row[tenantsArrayTenantFieldName]) {
16
- acc.push(extractID(row[tenantsArrayTenantFieldName]));
15
+ const tenantRow = row[tenantsArrayTenantFieldName];
16
+ if (tenantRow !== undefined && tenantRow !== null) {
17
+ acc.push(extractID(tenantRow));
17
18
  }
18
19
  return acc;
19
20
  }, []) || [];
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/getUserTenantIDs.ts"],"sourcesContent":["import type { Tenant, UserWithTenantsField } from '../types.js'\n\nimport { defaults } from '../defaults.js'\nimport { extractID } from './extractID.js'\n\n/**\n * Returns array of all tenant IDs assigned to a user\n *\n * @param user - User object with tenants field\n */\nexport const getUserTenantIDs = <IDType extends number | string>(\n user: null | UserWithTenantsField,\n options?: {\n tenantsArrayFieldName?: string\n tenantsArrayTenantFieldName?: string\n },\n): IDType[] => {\n if (!user) {\n return []\n }\n\n const tenantsArrayFieldName = options?.tenantsArrayFieldName || defaults.tenantsArrayFieldName\n const tenantsArrayTenantFieldName =\n options?.tenantsArrayTenantFieldName || defaults.tenantsArrayTenantFieldName\n\n const tenantsArray = (user as Record<string, unknown>)[tenantsArrayFieldName]\n\n return (\n (Array.isArray(tenantsArray) ? tenantsArray : [])?.reduce<IDType[]>((acc, row) => {\n if (row[tenantsArrayTenantFieldName]) {\n acc.push(extractID<IDType>(row[tenantsArrayTenantFieldName] as Tenant<IDType>))\n }\n\n return acc\n }, []) || []\n )\n}\n"],"names":["defaults","extractID","getUserTenantIDs","user","options","tenantsArrayFieldName","tenantsArrayTenantFieldName","tenantsArray","Array","isArray","reduce","acc","row","push"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,iBAAgB;AACzC,SAASC,SAAS,QAAQ,iBAAgB;AAE1C;;;;CAIC,GACD,OAAO,MAAMC,mBAAmB,CAC9BC,MACAC;IAKA,IAAI,CAACD,MAAM;QACT,OAAO,EAAE;IACX;IAEA,MAAME,wBAAwBD,SAASC,yBAAyBL,SAASK,qBAAqB;IAC9F,MAAMC,8BACJF,SAASE,+BAA+BN,SAASM,2BAA2B;IAE9E,MAAMC,eAAe,AAACJ,IAAgC,CAACE,sBAAsB;IAE7E,OACE,AAACG,CAAAA,MAAMC,OAAO,CAACF,gBAAgBA,eAAe,EAAE,AAAD,GAAIG,OAAiB,CAACC,KAAKC;QACxE,IAAIA,GAAG,CAACN,4BAA4B,EAAE;YACpCK,IAAIE,IAAI,CAACZ,UAAkBW,GAAG,CAACN,4BAA4B;QAC7D;QAEA,OAAOK;IACT,GAAG,EAAE,KAAK,EAAE;AAEhB,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/getUserTenantIDs.ts"],"sourcesContent":["import type { Tenant, UserWithTenantsField } from '../types.js'\n\nimport { defaults } from '../defaults.js'\nimport { extractID } from './extractID.js'\n\n/**\n * Returns array of all tenant IDs assigned to a user\n *\n * @param user - User object with tenants field\n */\nexport const getUserTenantIDs = <IDType extends number | string>(\n user: null | UserWithTenantsField,\n options?: {\n tenantsArrayFieldName?: string\n tenantsArrayTenantFieldName?: string\n },\n): IDType[] => {\n if (!user) {\n return []\n }\n\n const tenantsArrayFieldName = options?.tenantsArrayFieldName || defaults.tenantsArrayFieldName\n const tenantsArrayTenantFieldName =\n options?.tenantsArrayTenantFieldName || defaults.tenantsArrayTenantFieldName\n\n const tenantsArray = (user as Record<string, unknown>)[tenantsArrayFieldName]\n\n return (\n (Array.isArray(tenantsArray) ? tenantsArray : [])?.reduce<IDType[]>((acc, row) => {\n const tenantRow = row[tenantsArrayTenantFieldName] as Tenant<IDType>\n if (tenantRow !== undefined && tenantRow !== null) {\n acc.push(extractID(tenantRow))\n }\n\n return acc\n }, []) || []\n )\n}\n"],"names":["defaults","extractID","getUserTenantIDs","user","options","tenantsArrayFieldName","tenantsArrayTenantFieldName","tenantsArray","Array","isArray","reduce","acc","row","tenantRow","undefined","push"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,iBAAgB;AACzC,SAASC,SAAS,QAAQ,iBAAgB;AAE1C;;;;CAIC,GACD,OAAO,MAAMC,mBAAmB,CAC9BC,MACAC;IAKA,IAAI,CAACD,MAAM;QACT,OAAO,EAAE;IACX;IAEA,MAAME,wBAAwBD,SAASC,yBAAyBL,SAASK,qBAAqB;IAC9F,MAAMC,8BACJF,SAASE,+BAA+BN,SAASM,2BAA2B;IAE9E,MAAMC,eAAe,AAACJ,IAAgC,CAACE,sBAAsB;IAE7E,OACE,AAACG,CAAAA,MAAMC,OAAO,CAACF,gBAAgBA,eAAe,EAAE,AAAD,GAAIG,OAAiB,CAACC,KAAKC;QACxE,MAAMC,YAAYD,GAAG,CAACN,4BAA4B;QAClD,IAAIO,cAAcC,aAAaD,cAAc,MAAM;YACjDF,IAAII,IAAI,CAACd,UAAUY;QACrB;QAEA,OAAOF;IACT,GAAG,EAAE,KAAK,EAAE;AAEhB,EAAC"}
@@ -0,0 +1,13 @@
1
+ import type { PayloadRequest } from 'payload';
2
+ import type { MultiTenantPluginConfig } from '../types.js';
3
+ type Args = {
4
+ previousValue?: unknown;
5
+ req: PayloadRequest;
6
+ tenantsArrayFieldName: string;
7
+ tenantsArrayTenantFieldName: string;
8
+ userHasAccessToAllTenants?: MultiTenantPluginConfig['userHasAccessToAllTenants'];
9
+ value: unknown;
10
+ };
11
+ export declare const isValidTenantAssignment: ({ previousValue, req, tenantsArrayFieldName, tenantsArrayTenantFieldName, userHasAccessToAllTenants, value, }: Args) => boolean;
12
+ export {};
13
+ //# sourceMappingURL=isValidTenantAssignment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isValidTenantAssignment.d.ts","sourceRoot":"","sources":["../../src/utilities/isValidTenantAssignment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAK1D,KAAK,IAAI,GAAG;IACV,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;IACnB,qBAAqB,EAAE,MAAM,CAAA;IAC7B,2BAA2B,EAAE,MAAM,CAAA;IACnC,yBAAyB,CAAC,EAAE,uBAAuB,CAAC,2BAA2B,CAAC,CAAA;IAChF,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAED,eAAO,MAAM,uBAAuB,kHAOjC,IAAI,KAAG,OAgCT,CAAA"}
@@ -0,0 +1,28 @@
1
+ import { getTenantIDsFromValue } from './getTenantIDsFromValue.js';
2
+ import { getUserTenantIDs } from './getUserTenantIDs.js';
3
+ export const isValidTenantAssignment = ({ previousValue, req, tenantsArrayFieldName, tenantsArrayTenantFieldName, userHasAccessToAllTenants, value })=>{
4
+ const { user } = req;
5
+ if (user) {
6
+ if (userHasAccessToAllTenants?.(user)) {
7
+ return true;
8
+ }
9
+ } else if (req.payloadAPI === 'local') {
10
+ return true;
11
+ }
12
+ const submittedDocumentTenantIDs = getTenantIDsFromValue(value);
13
+ const storedDocumentTenantIDs = getTenantIDsFromValue(previousValue);
14
+ if (!hasTenantValueChanged(submittedDocumentTenantIDs, storedDocumentTenantIDs)) {
15
+ return true;
16
+ }
17
+ if (submittedDocumentTenantIDs.length === 0) {
18
+ return false;
19
+ }
20
+ const userAssignedTenantIDs = getUserTenantIDs(user, {
21
+ tenantsArrayFieldName,
22
+ tenantsArrayTenantFieldName
23
+ });
24
+ return submittedDocumentTenantIDs.every((tenantID)=>userAssignedTenantIDs.some((userAssignedTenantID)=>String(userAssignedTenantID) === String(tenantID)));
25
+ };
26
+ const hasTenantValueChanged = (submittedTenantIDs, storedTenantIDs)=>submittedTenantIDs.length !== storedTenantIDs.length || submittedTenantIDs.some((tenantID)=>!storedTenantIDs.includes(tenantID));
27
+
28
+ //# sourceMappingURL=isValidTenantAssignment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/isValidTenantAssignment.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport type { MultiTenantPluginConfig } from '../types.js'\n\nimport { getTenantIDsFromValue } from './getTenantIDsFromValue.js'\nimport { getUserTenantIDs } from './getUserTenantIDs.js'\n\ntype Args = {\n previousValue?: unknown\n req: PayloadRequest\n tenantsArrayFieldName: string\n tenantsArrayTenantFieldName: string\n userHasAccessToAllTenants?: MultiTenantPluginConfig['userHasAccessToAllTenants']\n value: unknown\n}\n\nexport const isValidTenantAssignment = ({\n previousValue,\n req,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n userHasAccessToAllTenants,\n value,\n}: Args): boolean => {\n const { user } = req\n\n if (user) {\n if (userHasAccessToAllTenants?.(user)) {\n return true\n }\n } else if (req.payloadAPI === 'local') {\n return true\n }\n\n const submittedDocumentTenantIDs = getTenantIDsFromValue(value)\n const storedDocumentTenantIDs = getTenantIDsFromValue(previousValue)\n\n if (!hasTenantValueChanged(submittedDocumentTenantIDs, storedDocumentTenantIDs)) {\n return true\n }\n\n if (submittedDocumentTenantIDs.length === 0) {\n return false\n }\n\n const userAssignedTenantIDs = getUserTenantIDs(user, {\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n })\n\n return submittedDocumentTenantIDs.every((tenantID) =>\n userAssignedTenantIDs.some(\n (userAssignedTenantID) => String(userAssignedTenantID) === String(tenantID),\n ),\n )\n}\n\nconst hasTenantValueChanged = (\n submittedTenantIDs: (number | string)[],\n storedTenantIDs: (number | string)[],\n): boolean =>\n submittedTenantIDs.length !== storedTenantIDs.length ||\n submittedTenantIDs.some((tenantID) => !storedTenantIDs.includes(tenantID))\n"],"names":["getTenantIDsFromValue","getUserTenantIDs","isValidTenantAssignment","previousValue","req","tenantsArrayFieldName","tenantsArrayTenantFieldName","userHasAccessToAllTenants","value","user","payloadAPI","submittedDocumentTenantIDs","storedDocumentTenantIDs","hasTenantValueChanged","length","userAssignedTenantIDs","every","tenantID","some","userAssignedTenantID","String","submittedTenantIDs","storedTenantIDs","includes"],"mappings":"AAIA,SAASA,qBAAqB,QAAQ,6BAA4B;AAClE,SAASC,gBAAgB,QAAQ,wBAAuB;AAWxD,OAAO,MAAMC,0BAA0B,CAAC,EACtCC,aAAa,EACbC,GAAG,EACHC,qBAAqB,EACrBC,2BAA2B,EAC3BC,yBAAyB,EACzBC,KAAK,EACA;IACL,MAAM,EAAEC,IAAI,EAAE,GAAGL;IAEjB,IAAIK,MAAM;QACR,IAAIF,4BAA4BE,OAAO;YACrC,OAAO;QACT;IACF,OAAO,IAAIL,IAAIM,UAAU,KAAK,SAAS;QACrC,OAAO;IACT;IAEA,MAAMC,6BAA6BX,sBAAsBQ;IACzD,MAAMI,0BAA0BZ,sBAAsBG;IAEtD,IAAI,CAACU,sBAAsBF,4BAA4BC,0BAA0B;QAC/E,OAAO;IACT;IAEA,IAAID,2BAA2BG,MAAM,KAAK,GAAG;QAC3C,OAAO;IACT;IAEA,MAAMC,wBAAwBd,iBAAiBQ,MAAM;QACnDJ;QACAC;IACF;IAEA,OAAOK,2BAA2BK,KAAK,CAAC,CAACC,WACvCF,sBAAsBG,IAAI,CACxB,CAACC,uBAAyBC,OAAOD,0BAA0BC,OAAOH;AAGxE,EAAC;AAED,MAAMJ,wBAAwB,CAC5BQ,oBACAC,kBAEAD,mBAAmBP,MAAM,KAAKQ,gBAAgBR,MAAM,IACpDO,mBAAmBH,IAAI,CAAC,CAACD,WAAa,CAACK,gBAAgBC,QAAQ,CAACN"}
@@ -1 +1 @@
1
- {"version":3,"file":"miniChalk.d.ts","sourceRoot":"","sources":["../../src/utilities/miniChalk.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,SAAS;gBACR,MAAM;gBACN,MAAM;gBACN,MAAM;eACP,MAAM;iBACJ,MAAM;mBACJ,MAAM;eACV,MAAM;qBACA,MAAM;iBACV,MAAM;kBACL,MAAM;mBAGL,MAAM;sBACH,MAAM;CACzB,CAAA"}
1
+ {"version":3,"file":"miniChalk.d.ts","sourceRoot":"","sources":["../../src/utilities/miniChalk.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,SAAS;IACpB,IAAI,QAAQ,MAAM;IAClB,IAAI,QAAQ,MAAM;IAClB,IAAI,QAAQ,MAAM;IAClB,GAAG,QAAQ,MAAM;IACjB,KAAK,QAAQ,MAAM;IACnB,OAAO,QAAQ,MAAM;IACrB,GAAG,QAAQ,MAAM;IACjB,SAAS,QAAQ,MAAM;IACvB,KAAK,QAAQ,MAAM;IACnB,MAAM,QAAQ,MAAM;IAGpB,OAAO,QAAQ,MAAM;IACrB,UAAU,QAAQ,MAAM;CACzB,CAAA"}
@@ -0,0 +1,5 @@
1
+ export declare const shouldRefreshTenantSelection: ({ initialValue, tenantCookie, }: {
2
+ initialValue?: number | string;
3
+ tenantCookie?: string;
4
+ }) => boolean;
5
+ //# sourceMappingURL=shouldRefreshTenantSelection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shouldRefreshTenantSelection.d.ts","sourceRoot":"","sources":["../../src/utilities/shouldRefreshTenantSelection.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,4BAA4B,oCAGtC;IACD,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,KAAG,OAAiD,CAAA"}
@@ -0,0 +1,3 @@
1
+ export const shouldRefreshTenantSelection = ({ initialValue, tenantCookie })=>!initialValue && Boolean(tenantCookie);
2
+
3
+ //# sourceMappingURL=shouldRefreshTenantSelection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/shouldRefreshTenantSelection.ts"],"sourcesContent":["export const shouldRefreshTenantSelection = ({\n initialValue,\n tenantCookie,\n}: {\n initialValue?: number | string\n tenantCookie?: string\n}): boolean => !initialValue && Boolean(tenantCookie)\n"],"names":["shouldRefreshTenantSelection","initialValue","tenantCookie","Boolean"],"mappings":"AAAA,OAAO,MAAMA,+BAA+B,CAAC,EAC3CC,YAAY,EACZC,YAAY,EAIb,GAAc,CAACD,gBAAgBE,QAAQD,cAAa"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-multi-tenant",
3
- "version": "4.0.0-internal.8ba6b5b",
3
+ "version": "4.0.0-internal.934870d",
4
4
  "description": "Multi Tenant plugin for Payload",
5
5
  "keywords": [
6
6
  "payload",
@@ -26,7 +26,6 @@
26
26
  }
27
27
  ],
28
28
  "sideEffects": [
29
- "*.scss",
30
29
  "*.css"
31
30
  ],
32
31
  "type": "module",
@@ -81,13 +80,13 @@
81
80
  ],
82
81
  "devDependencies": {
83
82
  "@payloadcms/eslint-config": "3.28.0",
84
- "@payloadcms/translations": "4.0.0-internal.8ba6b5b",
85
- "@payloadcms/ui": "4.0.0-internal.8ba6b5b",
86
- "payload": "4.0.0-internal.8ba6b5b"
83
+ "@payloadcms/translations": "4.0.0-internal.934870d",
84
+ "@payloadcms/ui": "4.0.0-internal.934870d",
85
+ "payload": "4.0.0-internal.934870d"
87
86
  },
88
87
  "peerDependencies": {
89
- "@payloadcms/ui": "4.0.0-internal.8ba6b5b",
90
- "payload": "4.0.0-internal.8ba6b5b"
88
+ "@payloadcms/ui": "4.0.0-internal.934870d",
89
+ "payload": "4.0.0-internal.934870d"
91
90
  },
92
91
  "homepage:": "https://payloadcms.com",
93
92
  "scripts": {
@@ -96,7 +95,7 @@
96
95
  "build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
97
96
  "build:types": "tsc --emitDeclarationOnly --outDir dist",
98
97
  "clean": "rimraf {dist,*.tsbuildinfo}",
99
- "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
98
+ "copyfiles": "copyfiles -u 1 -e \"**/*.spec.*\" \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
100
99
  "lint": "eslint .",
101
100
  "lint:fix": "eslint . --fix",
102
101
  "pack:plugin": "pnpm build && pnpm pack"
@@ -1,3 +0,0 @@
1
- import type { Where } from 'payload';
2
- export declare function combineWhereConstraints(constraints: Array<Where>): Where;
3
- //# sourceMappingURL=combineWhereConstraints.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"combineWhereConstraints.d.ts","sourceRoot":"","sources":["../../src/utilities/combineWhereConstraints.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEpC,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAgBxE"}
@@ -1,19 +0,0 @@
1
- export function combineWhereConstraints(constraints) {
2
- if (constraints.length === 0) {
3
- return {};
4
- }
5
- if (constraints.length === 1 && constraints[0]) {
6
- return constraints[0];
7
- }
8
- const andConstraint = {
9
- and: []
10
- };
11
- constraints.forEach((constraint)=>{
12
- if (andConstraint.and && constraint && typeof constraint === 'object') {
13
- andConstraint.and.push(constraint);
14
- }
15
- });
16
- return andConstraint;
17
- }
18
-
19
- //# sourceMappingURL=combineWhereConstraints.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utilities/combineWhereConstraints.ts"],"sourcesContent":["import type { Where } from 'payload'\n\nexport function combineWhereConstraints(constraints: Array<Where>): Where {\n if (constraints.length === 0) {\n return {}\n }\n if (constraints.length === 1 && constraints[0]) {\n return constraints[0]\n }\n const andConstraint: Where = {\n and: [],\n }\n constraints.forEach((constraint) => {\n if (andConstraint.and && constraint && typeof constraint === 'object') {\n andConstraint.and.push(constraint)\n }\n })\n return andConstraint\n}\n"],"names":["combineWhereConstraints","constraints","length","andConstraint","and","forEach","constraint","push"],"mappings":"AAEA,OAAO,SAASA,wBAAwBC,WAAyB;IAC/D,IAAIA,YAAYC,MAAM,KAAK,GAAG;QAC5B,OAAO,CAAC;IACV;IACA,IAAID,YAAYC,MAAM,KAAK,KAAKD,WAAW,CAAC,EAAE,EAAE;QAC9C,OAAOA,WAAW,CAAC,EAAE;IACvB;IACA,MAAME,gBAAuB;QAC3BC,KAAK,EAAE;IACT;IACAH,YAAYI,OAAO,CAAC,CAACC;QACnB,IAAIH,cAAcC,GAAG,IAAIE,cAAc,OAAOA,eAAe,UAAU;YACrEH,cAAcC,GAAG,CAACG,IAAI,CAACD;QACzB;IACF;IACA,OAAOH;AACT"}