@payloadcms/plugin-multi-tenant 3.18.0 → 3.19.0-canary.d942873
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/README.md +1 -1
- package/dist/providers/TenantSelectionProvider/index.client.d.ts.map +1 -1
- package/dist/providers/TenantSelectionProvider/index.client.js +11 -0
- package/dist/providers/TenantSelectionProvider/index.client.js.map +1 -1
- package/dist/providers/TenantSelectionProvider/index.d.ts.map +1 -1
- package/dist/providers/TenantSelectionProvider/index.js +17 -12
- package/dist/providers/TenantSelectionProvider/index.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/withTenantAccess.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.client.d.ts","sourceRoot":"","sources":["../../../src/providers/TenantSelectionProvider/index.client.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.client.d.ts","sourceRoot":"","sources":["../../../src/providers/TenantSelectionProvider/index.client.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAI3C,OAAO,KAAwB,MAAM,OAAO,CAAA;AAI5C,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,YAAY,EAAE,CAAA;IACvB,gBAAgB,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAC7C,yBAAyB,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAA;IACxE,SAAS,EAAE,CAAC,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAA;CAClF,CAAA;AASD,eAAO,MAAM,6BAA6B,+CAIvC;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,YAAY,EAAE,CAAA;CAC9B,sBA6DA,CAAA;AAED,eAAO,MAAM,kBAAkB,mBAAkC,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useAuth } from '@payloadcms/ui';
|
|
3
4
|
import { useRouter } from 'next/navigation.js';
|
|
4
5
|
import React, { createContext } from 'react';
|
|
5
6
|
import { SELECT_ALL } from '../../constants.js';
|
|
@@ -12,6 +13,10 @@ const Context = /*#__PURE__*/ createContext({
|
|
|
12
13
|
export const TenantSelectionProviderClient = ({ children, initialValue, tenantOptions })=>{
|
|
13
14
|
const [selectedTenantID, setSelectedTenantID] = React.useState(initialValue || SELECT_ALL);
|
|
14
15
|
const [preventRefreshOnChange, setPreventRefreshOnChange] = React.useState(false);
|
|
16
|
+
const { user } = useAuth();
|
|
17
|
+
const userID = React.useMemo(()=>user?.id, [
|
|
18
|
+
user?.id
|
|
19
|
+
]);
|
|
15
20
|
const router = useRouter();
|
|
16
21
|
const setCookie = React.useCallback((value)=>{
|
|
17
22
|
const expires = '; expires=Fri, 31 Dec 9999 23:59:59 GMT';
|
|
@@ -54,6 +59,12 @@ export const TenantSelectionProviderClient = ({ children, initialValue, tenantOp
|
|
|
54
59
|
selectedTenantID,
|
|
55
60
|
tenantOptions
|
|
56
61
|
]);
|
|
62
|
+
React.useEffect(()=>{
|
|
63
|
+
router.refresh();
|
|
64
|
+
}, [
|
|
65
|
+
userID,
|
|
66
|
+
router
|
|
67
|
+
]);
|
|
57
68
|
return /*#__PURE__*/ _jsx(Context.Provider, {
|
|
58
69
|
value: {
|
|
59
70
|
options: tenantOptions,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/providers/TenantSelectionProvider/index.client.tsx"],"sourcesContent":["'use client'\n\nimport type { OptionObject } from 'payload'\n\nimport { useRouter } from 'next/navigation.js'\nimport React, { createContext } from 'react'\n\nimport { SELECT_ALL } from '../../constants.js'\n\ntype ContextType = {\n options: OptionObject[]\n selectedTenantID: number | string | undefined\n setPreventRefreshOnChange: React.Dispatch<React.SetStateAction<boolean>>\n setTenant: (args: { id: number | string | undefined; refresh?: boolean }) => void\n}\n\nconst Context = createContext<ContextType>({\n options: [],\n selectedTenantID: undefined,\n setPreventRefreshOnChange: () => null,\n setTenant: () => null,\n})\n\nexport const TenantSelectionProviderClient = ({\n children,\n initialValue,\n tenantOptions,\n}: {\n children: React.ReactNode\n initialValue?: string\n tenantOptions: OptionObject[]\n}) => {\n const [selectedTenantID, setSelectedTenantID] = React.useState<number | string>(\n initialValue || SELECT_ALL,\n )\n const [preventRefreshOnChange, setPreventRefreshOnChange] = React.useState(false)\n\n const router = useRouter()\n\n const setCookie = React.useCallback((value?: string) => {\n const expires = '; expires=Fri, 31 Dec 9999 23:59:59 GMT'\n document.cookie = 'payload-tenant=' + (value || '') + expires + '; path=/'\n }, [])\n\n const setTenant = React.useCallback<ContextType['setTenant']>(\n ({ id, refresh }) => {\n if (id === undefined) {\n setSelectedTenantID(SELECT_ALL)\n setCookie(SELECT_ALL)\n } else {\n setSelectedTenantID(id)\n setCookie(String(id))\n }\n if (!preventRefreshOnChange && refresh) {\n router.refresh()\n }\n },\n [setSelectedTenantID, setCookie, router, preventRefreshOnChange],\n )\n\n React.useEffect(() => {\n if (\n selectedTenantID &&\n selectedTenantID !== SELECT_ALL &&\n !tenantOptions.find((option) => option.value === selectedTenantID)\n ) {\n if (tenantOptions?.[0]?.value) {\n setTenant({ id: tenantOptions[0].value, refresh: true })\n } else {\n setTenant({ id: undefined, refresh: true })\n }\n }\n }, [initialValue, setTenant, selectedTenantID, tenantOptions])\n\n return (\n <Context.Provider\n value={{\n options: tenantOptions,\n selectedTenantID,\n setPreventRefreshOnChange,\n setTenant,\n }}\n >\n {children}\n </Context.Provider>\n )\n}\n\nexport const useTenantSelection = () => React.useContext(Context)\n"],"names":["useRouter","React","createContext","SELECT_ALL","Context","options","selectedTenantID","undefined","setPreventRefreshOnChange","setTenant","TenantSelectionProviderClient","children","initialValue","tenantOptions","setSelectedTenantID","useState","preventRefreshOnChange","router","setCookie","useCallback","value","expires","document","cookie","
|
|
1
|
+
{"version":3,"sources":["../../../src/providers/TenantSelectionProvider/index.client.tsx"],"sourcesContent":["'use client'\n\nimport type { OptionObject } from 'payload'\n\nimport { useAuth } from '@payloadcms/ui'\nimport { useRouter } from 'next/navigation.js'\nimport React, { createContext } from 'react'\n\nimport { SELECT_ALL } from '../../constants.js'\n\ntype ContextType = {\n options: OptionObject[]\n selectedTenantID: number | string | undefined\n setPreventRefreshOnChange: React.Dispatch<React.SetStateAction<boolean>>\n setTenant: (args: { id: number | string | undefined; refresh?: boolean }) => void\n}\n\nconst Context = createContext<ContextType>({\n options: [],\n selectedTenantID: undefined,\n setPreventRefreshOnChange: () => null,\n setTenant: () => null,\n})\n\nexport const TenantSelectionProviderClient = ({\n children,\n initialValue,\n tenantOptions,\n}: {\n children: React.ReactNode\n initialValue?: string\n tenantOptions: OptionObject[]\n}) => {\n const [selectedTenantID, setSelectedTenantID] = React.useState<number | string>(\n initialValue || SELECT_ALL,\n )\n const [preventRefreshOnChange, setPreventRefreshOnChange] = React.useState(false)\n const { user } = useAuth()\n const userID = React.useMemo(() => user?.id, [user?.id])\n\n const router = useRouter()\n\n const setCookie = React.useCallback((value?: string) => {\n const expires = '; expires=Fri, 31 Dec 9999 23:59:59 GMT'\n document.cookie = 'payload-tenant=' + (value || '') + expires + '; path=/'\n }, [])\n\n const setTenant = React.useCallback<ContextType['setTenant']>(\n ({ id, refresh }) => {\n if (id === undefined) {\n setSelectedTenantID(SELECT_ALL)\n setCookie(SELECT_ALL)\n } else {\n setSelectedTenantID(id)\n setCookie(String(id))\n }\n if (!preventRefreshOnChange && refresh) {\n router.refresh()\n }\n },\n [setSelectedTenantID, setCookie, router, preventRefreshOnChange],\n )\n\n React.useEffect(() => {\n if (\n selectedTenantID &&\n selectedTenantID !== SELECT_ALL &&\n !tenantOptions.find((option) => option.value === selectedTenantID)\n ) {\n if (tenantOptions?.[0]?.value) {\n setTenant({ id: tenantOptions[0].value, refresh: true })\n } else {\n setTenant({ id: undefined, refresh: true })\n }\n }\n }, [initialValue, setTenant, selectedTenantID, tenantOptions])\n\n React.useEffect(() => {\n router.refresh()\n }, [userID, router])\n\n return (\n <Context.Provider\n value={{\n options: tenantOptions,\n selectedTenantID,\n setPreventRefreshOnChange,\n setTenant,\n }}\n >\n {children}\n </Context.Provider>\n )\n}\n\nexport const useTenantSelection = () => React.useContext(Context)\n"],"names":["useAuth","useRouter","React","createContext","SELECT_ALL","Context","options","selectedTenantID","undefined","setPreventRefreshOnChange","setTenant","TenantSelectionProviderClient","children","initialValue","tenantOptions","setSelectedTenantID","useState","preventRefreshOnChange","user","userID","useMemo","id","router","setCookie","useCallback","value","expires","document","cookie","refresh","String","useEffect","find","option","Provider","useTenantSelection","useContext"],"mappings":"AAAA;;AAIA,SAASA,OAAO,QAAQ,iBAAgB;AACxC,SAASC,SAAS,QAAQ,qBAAoB;AAC9C,OAAOC,SAASC,aAAa,QAAQ,QAAO;AAE5C,SAASC,UAAU,QAAQ,qBAAoB;AAS/C,MAAMC,wBAAUF,cAA2B;IACzCG,SAAS,EAAE;IACXC,kBAAkBC;IAClBC,2BAA2B,IAAM;IACjCC,WAAW,IAAM;AACnB;AAEA,OAAO,MAAMC,gCAAgC,CAAC,EAC5CC,QAAQ,EACRC,YAAY,EACZC,aAAa,EAKd;IACC,MAAM,CAACP,kBAAkBQ,oBAAoB,GAAGb,MAAMc,QAAQ,CAC5DH,gBAAgBT;IAElB,MAAM,CAACa,wBAAwBR,0BAA0B,GAAGP,MAAMc,QAAQ,CAAC;IAC3E,MAAM,EAAEE,IAAI,EAAE,GA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
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/TenantSelectionProvider/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAM1D,KAAK,IAAI,GAAG;IACV,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,OAAO,EAAE,OAAO,CAAA;IAChB,qBAAqB,EAAE,MAAM,CAAA;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,IAAI,CAAA;CACX,CAAA;AAED,eAAO,MAAM,uBAAuB,oEAMjC,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/TenantSelectionProvider/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAM1D,KAAK,IAAI,GAAG;IACV,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,OAAO,EAAE,OAAO,CAAA;IAChB,qBAAqB,EAAE,MAAM,CAAA;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,IAAI,CAAA;CACX,CAAA;AAED,eAAO,MAAM,uBAAuB,oEAMjC,IAAI,yCAiCN,CAAA"}
|
|
@@ -2,18 +2,23 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { cookies as getCookies } from 'next/headers.js';
|
|
3
3
|
import { TenantSelectionProviderClient } from './index.client.js';
|
|
4
4
|
export const TenantSelectionProvider = async ({ children, payload, tenantsCollectionSlug, useAsTitle, user })=>{
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
let tenantOptions = [];
|
|
6
|
+
try {
|
|
7
|
+
const { docs: userTenants } = await payload.find({
|
|
8
|
+
collection: tenantsCollectionSlug,
|
|
9
|
+
depth: 0,
|
|
10
|
+
limit: 1000,
|
|
11
|
+
overrideAccess: false,
|
|
12
|
+
sort: useAsTitle,
|
|
13
|
+
user
|
|
14
|
+
});
|
|
15
|
+
tenantOptions = userTenants.map((doc)=>({
|
|
16
|
+
label: String(doc[useAsTitle]),
|
|
17
|
+
value: String(doc.id)
|
|
18
|
+
}));
|
|
19
|
+
} catch (_) {
|
|
20
|
+
// user likely does not have access
|
|
21
|
+
}
|
|
17
22
|
const cookies = await getCookies();
|
|
18
23
|
const tenantCookie = cookies.get('payload-tenant')?.value;
|
|
19
24
|
const selectedTenant = tenantOptions.find((option)=>option.value === tenantCookie)?.label || tenantCookie;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/providers/TenantSelectionProvider/index.tsx"],"sourcesContent":["import type { OptionObject, Payload, User } from 'payload'\n\nimport { cookies as getCookies } from 'next/headers.js'\n\nimport { TenantSelectionProviderClient } from './index.client.js'\n\ntype Args = {\n children: React.ReactNode\n payload: Payload\n tenantsCollectionSlug: string\n useAsTitle: string\n user: User\n}\n\nexport const TenantSelectionProvider = async ({\n children,\n payload,\n tenantsCollectionSlug,\n useAsTitle,\n user,\n}: Args) => {\n const { docs: userTenants } = await payload.find({\n
|
|
1
|
+
{"version":3,"sources":["../../../src/providers/TenantSelectionProvider/index.tsx"],"sourcesContent":["import type { OptionObject, Payload, User } from 'payload'\n\nimport { cookies as getCookies } from 'next/headers.js'\n\nimport { TenantSelectionProviderClient } from './index.client.js'\n\ntype Args = {\n children: React.ReactNode\n payload: Payload\n tenantsCollectionSlug: string\n useAsTitle: string\n user: User\n}\n\nexport const TenantSelectionProvider = async ({\n children,\n payload,\n tenantsCollectionSlug,\n useAsTitle,\n user,\n}: Args) => {\n let tenantOptions: OptionObject[] = []\n\n try {\n const { docs: userTenants } = await payload.find({\n collection: tenantsCollectionSlug,\n depth: 0,\n limit: 1000,\n overrideAccess: false,\n sort: useAsTitle,\n user,\n })\n\n tenantOptions = userTenants.map((doc) => ({\n label: String(doc[useAsTitle]),\n value: String(doc.id),\n }))\n } catch (_) {\n // user likely does not have access\n }\n\n const cookies = await getCookies()\n const tenantCookie = cookies.get('payload-tenant')?.value\n const selectedTenant =\n tenantOptions.find((option) => option.value === tenantCookie)?.label || tenantCookie\n\n return (\n <span data-selected-tenant-id={tenantCookie} data-selected-tenant-title={selectedTenant}>\n <TenantSelectionProviderClient initialValue={tenantCookie} tenantOptions={tenantOptions}>\n {children}\n </TenantSelectionProviderClient>\n </span>\n )\n}\n"],"names":["cookies","getCookies","TenantSelectionProviderClient","TenantSelectionProvider","children","payload","tenantsCollectionSlug","useAsTitle","user","tenantOptions","docs","userTenants","find","collection","depth","limit","overrideAccess","sort","map","doc","label","String","value","id","_","tenantCookie","get","selectedTenant","option","span","data-selected-tenant-id","data-selected-tenant-title","initialValue"],"mappings":";AAEA,SAASA,WAAWC,UAAU,QAAQ,kBAAiB;AAEvD,SAASC,6BAA6B,QAAQ,oBAAmB;AAUjE,OAAO,MAAMC,0BAA0B,OAAO,EAC5CC,QAAQ,EACRC,OAAO,EACPC,qBAAqB,EACrBC,UAAU,EACVC,IAAI,EACC;IACL,IAAIC,gBAAgC,EAAE;IAEtC,IAAI;QACF,MAAM,EAAEC,MAAMC,WAAW,EAAE,GAAG,MAAMN,QAAQO,IAAI,CAAC;YAC/CC,YAAYP;YACZQ,OAAO;YACPC,OAAO;YACPC,gBAAgB;YAChBC,MAAMV;YACNC;QACF;QAEAC,gBAAgBE,YAAYO,GAAG,CAAC,CAACC,MAAS,CAAA;gBACxCC,OAAOC,OAAOF,GAAG,CAACZ,WAAW;gBAC7Be,OAAOD,OAAOF,IAAII,EAAE;YACtB,CAAA;IACF,EAAE,OAAOC,GAAG;IACV,mCAAmC;IACrC;IAEA,MAAMxB,UAAU,MAAMC;IACtB,MAAMwB,eAAezB,QAAQ0B,GAAG,CAAC,mBAAmBJ;IACpD,MAAMK,iBACJlB,cAAcG,IAAI,CAAC,CAACgB,SAAWA,OAAON,KAAK,KAAKG,eAAeL,SAASK;IAE1E,qBACE,KAACI;QAAKC,2BAAyBL;QAAcM,8BAA4BJ;kBACvE,cAAA,KAACzB;YAA8B8B,cAAcP;YAAchB,eAAeA;sBACvEL;;;AAIT,EAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -102,7 +102,7 @@ export type MultiTenantPluginConfig<ConfigTypes = unknown> = {
|
|
|
102
102
|
* Useful for super-admin type users
|
|
103
103
|
*/
|
|
104
104
|
userHasAccessToAllTenants?: (user: ConfigTypes extends {
|
|
105
|
-
user:
|
|
105
|
+
user: unknown;
|
|
106
106
|
} ? ConfigTypes['user'] : User) => boolean;
|
|
107
107
|
};
|
|
108
108
|
export type Tenant<IDType = number | string> = {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAEzF,MAAM,MAAM,uBAAuB,CAAC,WAAW,GAAG,OAAO,IAAI;IAC3D;;;;;;OAMG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAA;IAClC;;OAEG;IACH,WAAW,EAAE;SACV,GAAG,IAAI,cAAc,CAAC,CAAC,EAAE;YACxB;;;;eAIG;YACH,QAAQ,CAAC,EAAE,OAAO,CAAA;YAClB;;;;eAIG;YACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;YAC3B;;;;eAIG;YACH,eAAe,CAAC,EAAE,OAAO,CAAA;SAC1B;KACF,CAAA;IACD;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;OAEG;IACH,WAAW,CAAC,EAAE;QACZ,M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,EAAE,CAAA;CACJ,GAAG,IAAI,CAAA"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { ArrayField, CollectionSlug, Field, RelationshipField, User } from 'payload'\n\nexport type MultiTenantPluginConfig<ConfigTypes = unknown> = {\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 * Set to `true` if you want the collection to behave as a global\n *\n * @default false\n */\n isGlobal?: boolean\n /**\n * Set to `false` if you want to manually apply the baseListFilter\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 * Field configuration for the field added to all tenant enabled collections\n */\n tenantField?: {\n access?: RelationshipField['access']\n /**\n * The name of the field added to all tenant enabled collections\n *\n * @default 'tenant'\n */\n name?: string\n }\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 * 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 /**\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 * 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?: (\n user: ConfigTypes extends { user:
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { ArrayField, CollectionSlug, Field, RelationshipField, User } from 'payload'\n\nexport type MultiTenantPluginConfig<ConfigTypes = unknown> = {\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 * Set to `true` if you want the collection to behave as a global\n *\n * @default false\n */\n isGlobal?: boolean\n /**\n * Set to `false` if you want to manually apply the baseListFilter\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 * Field configuration for the field added to all tenant enabled collections\n */\n tenantField?: {\n access?: RelationshipField['access']\n /**\n * The name of the field added to all tenant enabled collections\n *\n * @default 'tenant'\n */\n name?: string\n }\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 * 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 /**\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 * 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?: (\n user: ConfigTypes extends { user: unknown } ? ConfigTypes['user'] : User,\n ) => boolean\n}\n\nexport type Tenant<IDType = number | string> = {\n id: IDType\n name: string\n}\n\nexport type UserWithTenantsField = {\n tenants: {\n tenant: number | string | Tenant\n }[]\n} & User\n"],"names":[],"mappings":"AAoHA,WAIQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/withTenantAccess.ts"],"sourcesContent":["import type { Access, AccessArgs, AccessResult, User } from 'payload'\n\nimport type { MultiTenantPluginConfig, UserWithTenantsField } from '../types.js'\n\nimport { combineWhereConstraints } from './combineWhereConstraints.js'\nimport { getTenantAccess } from './getTenantAccess.js'\n\ntype Args<ConfigType> = {\n accessFunction?: Access\n fieldName: string\n userHasAccessToAllTenants: Required<\n MultiTenantPluginConfig<ConfigType>\n >['userHasAccessToAllTenants']\n}\nexport const withTenantAccess =\n <ConfigType>({ accessFunction, fieldName, userHasAccessToAllTenants }: Args<ConfigType>) =>\n async (args: AccessArgs): Promise<AccessResult> => {\n const constraints = []\n const accessFn =\n typeof accessFunction === 'function'\n ? accessFunction\n : ({ req }: AccessArgs): AccessResult => Boolean(req.user)\n const accessResult: AccessResult = await accessFn(args)\n\n if (accessResult === false) {\n return false\n } else if (accessResult && typeof accessResult === 'object') {\n constraints.push(accessResult)\n }\n\n if (\n args.req.user &&\n !userHasAccessToAllTenants(\n args.req.user as ConfigType extends { user:
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/withTenantAccess.ts"],"sourcesContent":["import type { Access, AccessArgs, AccessResult, User } from 'payload'\n\nimport type { MultiTenantPluginConfig, UserWithTenantsField } from '../types.js'\n\nimport { combineWhereConstraints } from './combineWhereConstraints.js'\nimport { getTenantAccess } from './getTenantAccess.js'\n\ntype Args<ConfigType> = {\n accessFunction?: Access\n fieldName: string\n userHasAccessToAllTenants: Required<\n MultiTenantPluginConfig<ConfigType>\n >['userHasAccessToAllTenants']\n}\nexport const withTenantAccess =\n <ConfigType>({ accessFunction, fieldName, userHasAccessToAllTenants }: Args<ConfigType>) =>\n async (args: AccessArgs): Promise<AccessResult> => {\n const constraints = []\n const accessFn =\n typeof accessFunction === 'function'\n ? accessFunction\n : ({ req }: AccessArgs): AccessResult => Boolean(req.user)\n const accessResult: AccessResult = await accessFn(args)\n\n if (accessResult === false) {\n return false\n } else if (accessResult && typeof accessResult === 'object') {\n constraints.push(accessResult)\n }\n\n if (\n args.req.user &&\n !userHasAccessToAllTenants(\n args.req.user as ConfigType extends { user: unknown } ? ConfigType['user'] : User,\n )\n ) {\n constraints.push(\n getTenantAccess({\n fieldName,\n user: args.req.user as UserWithTenantsField,\n }),\n )\n return combineWhereConstraints(constraints)\n }\n\n return accessResult\n }\n"],"names":["combineWhereConstraints","getTenantAccess","withTenantAccess","accessFunction","fieldName","userHasAccessToAllTenants","args","constraints","accessFn","req","Boolean","user","accessResult","push"],"mappings":"AAIA,SAASA,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,eAAe,QAAQ,uBAAsB;AAStD,OAAO,MAAMC,mBACX,CAAa,EAAEC,cAAc,EAAEC,SAAS,EAAEC,yBAAyB,EAAoB,GACvF,OAAOC;QACL,MAAMC,cAAc,EAAE;QACtB,MAAMC,WACJ,OAAOL,mBAAmB,aACtBA,iBACA,CAAC,EAAEM,GAAG,EAAc,GAAmBC,QAAQD,IAAIE,IAAI;QAC7D,MAAMC,eAA6B,MAAMJ,SAASF;QAElD,IAAIM,iBAAiB,OAAO;YAC1B,OAAO;QACT,OAAO,IAAIA,gBAAgB,OAAOA,iBAAiB,UAAU;YAC3DL,YAAYM,IAAI,CAACD;QACnB;QAEA,IACEN,KAAKG,GAAG,CAACE,IAAI,IACb,CAACN,0BACCC,KAAKG,GAAG,CAACE,IAAI,GAEf;YACAJ,YAAYM,IAAI,CACdZ,gBAAgB;gBACdG;gBACAO,MAAML,KAAKG,GAAG,CAACE,IAAI;YACrB;YAEF,OAAOX,wBAAwBO;QACjC;QAEA,OAAOK;IACT,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-multi-tenant",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.19.0-canary.d942873",
|
|
4
4
|
"description": "Multi Tenant plugin for Payload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"payload",
|
|
@@ -67,13 +67,13 @@
|
|
|
67
67
|
],
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@payloadcms/eslint-config": "3.9.0",
|
|
70
|
-
"@payloadcms/ui": "3.
|
|
71
|
-
"payload": "3.
|
|
70
|
+
"@payloadcms/ui": "3.19.0-canary.d942873",
|
|
71
|
+
"payload": "3.19.0-canary.d942873"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
74
|
"next": "^15.0.3",
|
|
75
|
-
"@payloadcms/ui": "3.
|
|
76
|
-
"payload": "3.
|
|
75
|
+
"@payloadcms/ui": "3.19.0-canary.d942873",
|
|
76
|
+
"payload": "3.19.0-canary.d942873"
|
|
77
77
|
},
|
|
78
78
|
"homepage:": "https://payloadcms.com",
|
|
79
79
|
"scripts": {
|