@payloadcms/plugin-multi-tenant 3.18.0 → 3.19.0-canary.9b65c78

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 CHANGED
@@ -9,7 +9,7 @@ A plugin for [Payload](https://github.com/payloadcms/payload) to easily manage m
9
9
  ## Installation
10
10
 
11
11
  ```bash
12
- pnpm add @payloadcms/plugin-multi-tenant@beta
12
+ pnpm add @payloadcms/plugin-multi-tenant
13
13
  ```
14
14
 
15
15
  ## Plugin Types
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/GlobalViewRedirect/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAMrE,KAAK,IAAI,GAAG;IACV,cAAc,EAAE,cAAc,CAAA;IAC9B,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,WAAW,EAAE,MAAM,EAAE,CAAA;IACrB,eAAe,EAAE,MAAM,CAAA;IACvB,QAAQ,EAAE,SAAS,CAAA;CACpB,GAAG,WAAW,CAAA;AAEf,eAAO,MAAM,kBAAkB,SAAgB,IAAI,kBAgBlD,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/GlobalViewRedirect/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAOrE,KAAK,IAAI,GAAG;IACV,cAAc,EAAE,cAAc,CAAA;IAC9B,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,WAAW,EAAE,MAAM,EAAE,CAAA;IACrB,eAAe,EAAE,MAAM,CAAA;IACvB,QAAQ,EAAE,SAAS,CAAA;CACpB,GAAG,WAAW,CAAA;AAEf,eAAO,MAAM,kBAAkB,SAAgB,IAAI,kBAkBlD,CAAA"}
@@ -1,11 +1,14 @@
1
+ import { headers as getHeaders } from 'next/headers.js';
1
2
  import { redirect } from 'next/navigation.js';
2
3
  import { getGlobalViewRedirect } from '../../utilities/getGlobalViewRedirect.js';
3
4
  export const GlobalViewRedirect = async (args)=>{
4
5
  const collectionSlug = args?.collectionSlug;
5
6
  if (collectionSlug && args.globalSlugs?.includes(collectionSlug)) {
7
+ const headers = await getHeaders();
6
8
  const redirectRoute = await getGlobalViewRedirect({
7
9
  slug: collectionSlug,
8
10
  docID: args.docID,
11
+ headers,
9
12
  payload: args.payload,
10
13
  tenantFieldName: args.tenantFieldName,
11
14
  view: args.viewType
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/GlobalViewRedirect/index.ts"],"sourcesContent":["import type { CollectionSlug, ServerProps, ViewTypes } from 'payload'\n\nimport { redirect } from 'next/navigation.js'\n\nimport { getGlobalViewRedirect } from '../../utilities/getGlobalViewRedirect.js'\n\ntype Args = {\n collectionSlug: CollectionSlug\n docID?: number | string\n globalSlugs: string[]\n tenantFieldName: string\n viewType: ViewTypes\n} & ServerProps\n\nexport const GlobalViewRedirect = async (args: Args) => {\n const collectionSlug = args?.collectionSlug\n\n if (collectionSlug && args.globalSlugs?.includes(collectionSlug)) {\n const redirectRoute = await getGlobalViewRedirect({\n slug: collectionSlug,\n docID: args.docID,\n payload: args.payload,\n tenantFieldName: args.tenantFieldName,\n view: args.viewType,\n })\n\n if (redirectRoute) {\n redirect(redirectRoute)\n }\n }\n}\n"],"names":["redirect","getGlobalViewRedirect","GlobalViewRedirect","args","collectionSlug","globalSlugs","includes","redirectRoute","slug","docID","payload","tenantFieldName","view","viewType"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,qBAAoB;AAE7C,SAASC,qBAAqB,QAAQ,2CAA0C;AAUhF,OAAO,MAAMC,qBAAqB,OAAOC;IACvC,MAAMC,iBAAiBD,MAAMC;IAE7B,IAAIA,kBAAkBD,KAAKE,WAAW,EAAEC,SAASF,iBAAiB;QAChE,MAAMG,gBAAgB,MAAMN,sBAAsB;YAChDO,MAAMJ;YACNK,OAAON,KAAKM,KAAK;YACjBC,SAASP,KAAKO,OAAO;YACrBC,iBAAiBR,KAAKQ,eAAe;YACrCC,MAAMT,KAAKU,QAAQ;QACrB;QAEA,IAAIN,eAAe;YACjBP,SAASO;QACX;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/components/GlobalViewRedirect/index.ts"],"sourcesContent":["import type { CollectionSlug, ServerProps, ViewTypes } from 'payload'\n\nimport { headers as getHeaders } from 'next/headers.js'\nimport { redirect } from 'next/navigation.js'\n\nimport { getGlobalViewRedirect } from '../../utilities/getGlobalViewRedirect.js'\n\ntype Args = {\n collectionSlug: CollectionSlug\n docID?: number | string\n globalSlugs: string[]\n tenantFieldName: string\n viewType: ViewTypes\n} & ServerProps\n\nexport const GlobalViewRedirect = async (args: Args) => {\n const collectionSlug = args?.collectionSlug\n\n if (collectionSlug && args.globalSlugs?.includes(collectionSlug)) {\n const headers = await getHeaders()\n const redirectRoute = await getGlobalViewRedirect({\n slug: collectionSlug,\n docID: args.docID,\n headers,\n payload: args.payload,\n tenantFieldName: args.tenantFieldName,\n view: args.viewType,\n })\n\n if (redirectRoute) {\n redirect(redirectRoute)\n }\n }\n}\n"],"names":["headers","getHeaders","redirect","getGlobalViewRedirect","GlobalViewRedirect","args","collectionSlug","globalSlugs","includes","redirectRoute","slug","docID","payload","tenantFieldName","view","viewType"],"mappings":"AAEA,SAASA,WAAWC,UAAU,QAAQ,kBAAiB;AACvD,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,SAASC,qBAAqB,QAAQ,2CAA0C;AAUhF,OAAO,MAAMC,qBAAqB,OAAOC;IACvC,MAAMC,iBAAiBD,MAAMC;IAE7B,IAAIA,kBAAkBD,KAAKE,WAAW,EAAEC,SAASF,iBAAiB;QAChE,MAAMN,UAAU,MAAMC;QACtB,MAAMQ,gBAAgB,MAAMN,sBAAsB;YAChDO,MAAMJ;YACNK,OAAON,KAAKM,KAAK;YACjBX;YACAY,SAASP,KAAKO,OAAO;YACrBC,iBAAiBR,KAAKQ,eAAe;YACrCC,MAAMT,KAAKU,QAAQ;QACrB;QAEA,IAAIN,eAAe;YACjBP,SAASO;QACX;IACF;AACF,EAAC"}
@@ -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;AAG3C,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,sBAuDA,CAAA;AAED,eAAO,MAAM,kBAAkB,mBAAkC,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,sBAsEA,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,14 @@ 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
+ ]);
20
+ const selectedTenantLabel = React.useMemo(()=>tenantOptions.find((option)=>option.value === selectedTenantID)?.label, [
21
+ selectedTenantID,
22
+ tenantOptions
23
+ ]);
15
24
  const router = useRouter();
16
25
  const setCookie = React.useCallback((value)=>{
17
26
  const expires = '; expires=Fri, 31 Dec 9999 23:59:59 GMT';
@@ -54,14 +63,24 @@ export const TenantSelectionProviderClient = ({ children, initialValue, tenantOp
54
63
  selectedTenantID,
55
64
  tenantOptions
56
65
  ]);
57
- return /*#__PURE__*/ _jsx(Context.Provider, {
58
- value: {
59
- options: tenantOptions,
60
- selectedTenantID,
61
- setPreventRefreshOnChange,
62
- setTenant
63
- },
64
- children: children
66
+ React.useEffect(()=>{
67
+ router.refresh();
68
+ }, [
69
+ userID,
70
+ router
71
+ ]);
72
+ return /*#__PURE__*/ _jsx("span", {
73
+ "data-selected-tenant-id": selectedTenantID,
74
+ "data-selected-tenant-title": selectedTenantLabel,
75
+ children: /*#__PURE__*/ _jsx(Context.Provider, {
76
+ value: {
77
+ options: tenantOptions,
78
+ selectedTenantID,
79
+ setPreventRefreshOnChange,
80
+ setTenant
81
+ },
82
+ children: children
83
+ })
65
84
  });
66
85
  };
67
86
  export const useTenantSelection = ()=>React.useContext(Context);
@@ -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","id","refresh","String","useEffect","find","option","Provider","useTenantSelection","useContext"],"mappings":"AAAA;;AAIA,SAASA,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;IAE3E,MAAME,SAASjB;IAEf,MAAMkB,YAAYjB,MAAMkB,WAAW,CAAC,CAACC;QACnC,MAAMC,UAAU;QAChBC,SAASC,MAAM,GAAG,oBAAqBH,CAAAA,SAAS,EAAC,IAAKC,UAAU;IAClE,GAAG,EAAE;IAEL,MAAMZ,YAAYR,MAAMkB,WAAW,CACjC,CAAC,EAAEK,EAAE,EAAEC,OAAO,EAAE;QACd,IAAID,OAAOjB,WAAW;YACpBO,oBAAoBX;YACpBe,UAAUf;QACZ,OAAO;YACLW,oBAAoBU;YACpBN,UAAUQ,OAAOF;QACnB;QACA,IAAI,CAACR,0BAA0BS,SAAS;YACtCR,OAAOQ,OAAO;QAChB;IACF,GACA;QAACX;QAAqBI;QAAWD;QAAQD;KAAuB;IAGlEf,MAAM0B,SAAS,CAAC;QACd,IACErB,oBACAA,qBAAqBH,cACrB,CAACU,cAAce,IAAI,CAAC,CAACC,SAAWA,OAAOT,KAAK,KAAKd,mBACjD;YACA,IAAIO,eAAe,CAAC,EAAE,EAAEO,OAAO;gBAC7BX,UAAU;oBAAEe,IAAIX,aAAa,CAAC,EAAE,CAACO,KAAK;oBAAEK,SAAS;gBAAK;YACxD,OAAO;gBACLhB,UAAU;oBAAEe,IAAIjB;oBAAWkB,SAAS;gBAAK;YAC3C;QACF;IACF,GAAG;QAACb;QAAcH;QAAWH;QAAkBO;KAAc;IAE7D,qBACE,KAACT,QAAQ0B,QAAQ;QACfV,OAAO;YACLf,SAASQ;YACTP;YACAE;YACAC;QACF;kBAECE;;AAGP,EAAC;AAED,OAAO,MAAMoB,qBAAqB,IAAM9B,MAAM+B,UAAU,CAAC5B,SAAQ"}
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 const selectedTenantLabel = React.useMemo(\n () => tenantOptions.find((option) => option.value === selectedTenantID)?.label,\n [selectedTenantID, tenantOptions],\n )\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 <span\n data-selected-tenant-id={selectedTenantID}\n data-selected-tenant-title={selectedTenantLabel}\n >\n <Context.Provider\n value={{\n options: tenantOptions,\n selectedTenantID,\n setPreventRefreshOnChange,\n setTenant,\n }}\n >\n {children}\n </Context.Provider>\n </span>\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","selectedTenantLabel","find","option","value","label","router","setCookie","useCallback","expires","document","cookie","refresh","String","useEffect","span","data-selected-tenant-id","data-selected-tenant-title","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,GAAGlB;IACjB,MAAMmB,SAASjB,MAAMkB,OAAO,CAAC,IAAMF,MAAMG,IAAI;QAACH,MAAMG;KAAG;IACvD,MAAMC,sBAAsBpB,MAAMkB,OAAO,CACvC,IAAMN,cAAcS,IAAI,CAAC,CAACC,SAAWA,OAAOC,KAAK,KAAKlB,mBAAmBmB,OACzE;QAACnB;QAAkBO;KAAc;IAGnC,MAAMa,SAAS1B;IAEf,MAAM2B,YAAY1B,MAAM2B,WAAW,CAAC,CAACJ;QACnC,MAAMK,UAAU;QAChBC,SAASC,MAAM,GAAG,oBAAqBP,CAAAA,SAAS,EAAC,IAAKK,UAAU;IAClE,GAAG,EAAE;IAEL,MAAMpB,YAAYR,MAAM2B,WAAW,CACjC,CAAC,EAAER,EAAE,EAAEY,OAAO,EAAE;QACd,IAAIZ,OAAOb,WAAW;YACpBO,oBAAoBX;YACpBwB,UAAUxB;QACZ,OAAO;YACLW,oBAAoBM;YACpBO,UAAUM,OAAOb;QACnB;QACA,IAAI,CAACJ,0BAA0BgB,SAAS;YACtCN,OAAOM,OAAO;QAChB;IACF,GACA;QAAClB;QAAqBa;QAAWD;QAAQV;KAAuB;IAGlEf,MAAMiC,SAAS,CAAC;QACd,IACE5B,oBACAA,qBAAqBH,cACrB,CAACU,cAAcS,IAAI,CAAC,CAACC,SAAWA,OAAOC,KAAK,KAAKlB,mBACjD;YACA,IAAIO,eAAe,CAAC,EAAE,EAAEW,OAAO;gBAC7Bf,UAAU;oBAAEW,IAAIP,aAAa,CAAC,EAAE,CAACW,KAAK;oBAAEQ,SAAS;gBAAK;YACxD,OAAO;gBACLvB,UAAU;oBAAEW,IAAIb;oBAAWyB,SAAS;gBAAK;YAC3C;QACF;IACF,GAAG;QAACpB;QAAcH;QAAWH;QAAkBO;KAAc;IAE7DZ,MAAMiC,SAAS,CAAC;QACdR,OAAOM,OAAO;IAChB,GAAG;QAACd;QAAQQ;KAAO;IAEnB,qBACE,KAACS;QACCC,2BAAyB9B;QACzB+B,8BAA4BhB;kBAE5B,cAAA,KAACjB,QAAQkC,QAAQ;YACfd,OAAO;gBACLnB,SAASQ;gBACTP;gBACAE;gBACAC;YACF;sBAECE;;;AAIT,EAAC;AAED,OAAO,MAAM4B,qBAAqB,IAAMtC,MAAMuC,UAAU,CAACpC,SAAQ"}
@@ -1 +1 @@
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,yCA0BN,CAAA"}
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,yCA6BN,CAAA"}
@@ -2,29 +2,29 @@ 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
- const { docs: userTenants } = await payload.find({
6
- collection: tenantsCollectionSlug,
7
- depth: 0,
8
- limit: 1000,
9
- overrideAccess: false,
10
- sort: useAsTitle,
11
- user
12
- });
13
- const tenantOptions = userTenants.map((doc)=>({
14
- label: String(doc[useAsTitle]),
15
- value: String(doc.id)
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
- const selectedTenant = tenantOptions.find((option)=>option.value === tenantCookie)?.label || tenantCookie;
20
- return /*#__PURE__*/ _jsx("span", {
21
- "data-selected-tenant-id": tenantCookie,
22
- "data-selected-tenant-title": selectedTenant,
23
- children: /*#__PURE__*/ _jsx(TenantSelectionProviderClient, {
24
- initialValue: tenantCookie,
25
- tenantOptions: tenantOptions,
26
- children: children
27
- })
24
+ return /*#__PURE__*/ _jsx(TenantSelectionProviderClient, {
25
+ initialValue: tenantCookie,
26
+ tenantOptions: tenantOptions,
27
+ children: children
28
28
  });
29
29
  };
30
30
 
@@ -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 collection: tenantsCollectionSlug,\n depth: 0,\n limit: 1000,\n overrideAccess: false,\n sort: useAsTitle,\n user,\n })\n\n const tenantOptions: OptionObject[] = userTenants.map((doc) => ({\n label: String(doc[useAsTitle]),\n value: String(doc.id),\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","docs","userTenants","find","collection","depth","limit","overrideAccess","sort","tenantOptions","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,MAAM,EAAEC,MAAMC,WAAW,EAAE,GAAG,MAAML,QAAQM,IAAI,CAAC;QAC/CC,YAAYN;QACZO,OAAO;QACPC,OAAO;QACPC,gBAAgB;QAChBC,MAAMT;QACNC;IACF;IAEA,MAAMS,gBAAgCP,YAAYQ,GAAG,CAAC,CAACC,MAAS,CAAA;YAC9DC,OAAOC,OAAOF,GAAG,CAACZ,WAAW;YAC7Be,OAAOD,OAAOF,IAAII,EAAE;QACtB,CAAA;IACA,MAAMvB,UAAU,MAAMC;IACtB,MAAMuB,eAAexB,QAAQyB,GAAG,CAAC,mBAAmBH;IACpD,MAAMI,iBACJT,cAAcN,IAAI,CAAC,CAACgB,SAAWA,OAAOL,KAAK,KAAKE,eAAeJ,SAASI;IAE1E,qBACE,KAACI;QAAKC,2BAAyBL;QAAcM,8BAA4BJ;kBACvE,cAAA,KAACxB;YAA8B6B,cAAcP;YAAcP,eAAeA;sBACvEb;;;AAIT,EAAC"}
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\n return (\n <TenantSelectionProviderClient initialValue={tenantCookie} tenantOptions={tenantOptions}>\n {children}\n </TenantSelectionProviderClient>\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","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;IAEpD,qBACE,KAACpB;QAA8ByB,cAAcF;QAAchB,eAAeA;kBACvEL;;AAGP,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: User;
105
+ user: unknown;
106
106
  } ? ConfigTypes['user'] : User) => boolean;
107
107
  };
108
108
  export type Tenant<IDType = number | string> = {
@@ -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,MAAM,CAAC,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAA;QACpC;;;;WAIG;QACH,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,CAAA;IACD;;;;;OAKG;IACH,iB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M,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,IAAI;IAC7C,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE;QACP,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;KACjC,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: User } ? 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
+ {"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,"file":"addFilterOptionsToFields.d.ts","sourceRoot":"","sources":["../../src/utilities/addFilterOptionsToFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAgD,MAAM,SAAS,CAAA;AAIlF,KAAK,4BAA4B,GAAG;IAClC,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,4BAA4B,EAAE,MAAM,EAAE,CAAA;IACtC,wBAAwB,EAAE,MAAM,EAAE,CAAA;CACnC,CAAA;AACD,wBAAgB,wBAAwB,CAAC,EACvC,MAAM,EACN,4BAA4B,EAC5B,wBAAwB,GACzB,EAAE,4BAA4B,QA+D9B"}
1
+ {"version":3,"file":"addFilterOptionsToFields.d.ts","sourceRoot":"","sources":["../../src/utilities/addFilterOptionsToFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAyC,MAAM,SAAS,CAAA;AAI3E,KAAK,4BAA4B,GAAG;IAClC,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,4BAA4B,EAAE,MAAM,EAAE,CAAA;IACtC,wBAAwB,EAAE,MAAM,EAAE,CAAA;CACnC,CAAA;AAED,wBAAgB,wBAAwB,CAAC,EACvC,MAAM,EACN,4BAA4B,EAC5B,wBAAwB,GACzB,EAAE,4BAA4B,QA+D9B"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/addFilterOptionsToFields.ts"],"sourcesContent":["import type { Field, FilterOptionsProps, RelationshipField, Where } from 'payload'\n\nimport { getTenantFromCookie } from './getTenantFromCookie.js'\n\ntype AddFilterOptionsToFieldsArgs = {\n fields: Field[]\n tenantEnabledCollectionSlugs: string[]\n tenantEnabledGlobalSlugs: string[]\n}\nexport function addFilterOptionsToFields({\n fields,\n tenantEnabledCollectionSlugs,\n tenantEnabledGlobalSlugs,\n}: AddFilterOptionsToFieldsArgs) {\n fields.forEach((field) => {\n if (field.type === 'relationship') {\n /**\n * Adjusts relationship fields to filter by tenant\n * and ensures relationTo cannot be a tenant global collection\n */\n if (typeof field.relationTo === 'string') {\n if (tenantEnabledGlobalSlugs.includes(field.relationTo)) {\n throw new Error(\n `The collection ${field.relationTo} is a global collection and cannot be related to a tenant enabled collection.`,\n )\n }\n if (tenantEnabledCollectionSlugs.includes(field.relationTo)) {\n addFilter(field, tenantEnabledCollectionSlugs)\n }\n } else {\n field.relationTo.map((relationTo) => {\n if (tenantEnabledGlobalSlugs.includes(relationTo)) {\n throw new Error(\n `The collection ${relationTo} is a global collection and cannot be related to a tenant enabled collection.`,\n )\n }\n if (tenantEnabledCollectionSlugs.includes(relationTo)) {\n addFilter(field, tenantEnabledCollectionSlugs)\n }\n })\n }\n }\n\n if (\n field.type === 'row' ||\n field.type === 'array' ||\n field.type === 'collapsible' ||\n field.type === 'group'\n ) {\n addFilterOptionsToFields({\n fields: field.fields,\n tenantEnabledCollectionSlugs,\n tenantEnabledGlobalSlugs,\n })\n }\n\n if (field.type === 'blocks') {\n field.blocks.forEach((block) => {\n addFilterOptionsToFields({\n fields: block.fields,\n tenantEnabledCollectionSlugs,\n tenantEnabledGlobalSlugs,\n })\n })\n }\n\n if (field.type === 'tabs') {\n field.tabs.forEach((tab) => {\n addFilterOptionsToFields({\n fields: tab.fields,\n tenantEnabledCollectionSlugs,\n tenantEnabledGlobalSlugs,\n })\n })\n }\n })\n}\n\nfunction addFilter(field: RelationshipField, tenantEnabledCollectionSlugs: string[]) {\n // User specified filter\n const originalFilter = field.filterOptions\n field.filterOptions = async (args) => {\n const originalFilterResult =\n typeof originalFilter === 'function' ? await originalFilter(args) : (originalFilter ?? true)\n\n // If the relationTo is not a tenant enabled collection, return early\n if (args.relationTo && !tenantEnabledCollectionSlugs.includes(args.relationTo)) {\n return originalFilterResult\n }\n\n // If the original filtr returns false, return early\n if (originalFilterResult === false) {\n return false\n }\n\n // Custom tenant filter\n const tenantFilterResults = filterOptionsByTenant(args)\n\n // If the tenant filter returns true, just use the original filter\n if (tenantFilterResults === true) {\n return originalFilterResult\n }\n\n // If the original filter returns true, just use the tenant filter\n if (originalFilterResult === true) {\n return tenantFilterResults\n }\n\n return {\n and: [originalFilterResult, tenantFilterResults],\n }\n }\n}\n\ntype Args = {\n tenantFieldName?: string\n} & FilterOptionsProps\nconst filterOptionsByTenant = ({ req, tenantFieldName = 'tenant' }: Args) => {\n const selectedTenant = getTenantFromCookie(req.headers, req.payload.db.defaultIDType)\n if (!selectedTenant) {\n return true\n }\n\n return {\n or: [\n // ie a related collection that doesn't have a tenant field\n {\n [tenantFieldName]: {\n exists: false,\n },\n },\n // related collections that have a tenant field\n {\n [tenantFieldName]: {\n equals: selectedTenant,\n },\n },\n ],\n }\n}\n"],"names":["getTenantFromCookie","addFilterOptionsToFields","fields","tenantEnabledCollectionSlugs","tenantEnabledGlobalSlugs","forEach","field","type","relationTo","includes","Error","addFilter","map","blocks","block","tabs","tab","originalFilter","filterOptions","args","originalFilterResult","tenantFilterResults","filterOptionsByTenant","and","req","tenantFieldName","selectedTenant","headers","payload","db","defaultIDType","or","exists","equals"],"mappings":"AAEA,SAASA,mBAAmB,QAAQ,2BAA0B;AAO9D,OAAO,SAASC,yBAAyB,EACvCC,MAAM,EACNC,4BAA4B,EAC5BC,wBAAwB,EACK;IAC7BF,OAAOG,OAAO,CAAC,CAACC;QACd,IAAIA,MAAMC,IAAI,KAAK,gBAAgB;YACjC;;;OAGC,GACD,IAAI,OAAOD,MAAME,UAAU,KAAK,UAAU;gBACxC,IAAIJ,yBAAyBK,QAAQ,CAACH,MAAME,UAAU,GAAG;oBACvD,MAAM,IAAIE,MACR,CAAC,eAAe,EAAEJ,MAAME,UAAU,CAAC,6EAA6E,CAAC;gBAErH;gBACA,IAAIL,6BAA6BM,QAAQ,CAACH,MAAME,UAAU,GAAG;oBAC3DG,UAAUL,OAAOH;gBACnB;YACF,OAAO;gBACLG,MAAME,UAAU,CAACI,GAAG,CAAC,CAACJ;oBACpB,IAAIJ,yBAAyBK,QAAQ,CAACD,aAAa;wBACjD,MAAM,IAAIE,MACR,CAAC,eAAe,EAAEF,WAAW,6EAA6E,CAAC;oBAE/G;oBACA,IAAIL,6BAA6BM,QAAQ,CAACD,aAAa;wBACrDG,UAAUL,OAAOH;oBACnB;gBACF;YACF;QACF;QAEA,IACEG,MAAMC,IAAI,KAAK,SACfD,MAAMC,IAAI,KAAK,WACfD,MAAMC,IAAI,KAAK,iBACfD,MAAMC,IAAI,KAAK,SACf;YACAN,yBAAyB;gBACvBC,QAAQI,MAAMJ,MAAM;gBACpBC;gBACAC;YACF;QACF;QAEA,IAAIE,MAAMC,IAAI,KAAK,UAAU;YAC3BD,MAAMO,MAAM,CAACR,OAAO,CAAC,CAACS;gBACpBb,yB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AACF"}
1
+ {"version":3,"sources":["../../src/utilities/addFilterOptionsToFields.ts"],"sourcesContent":["import type { Field, FilterOptionsProps, RelationshipField } from 'payload'\n\nimport { getTenantFromCookie } from './getTenantFromCookie.js'\n\ntype AddFilterOptionsToFieldsArgs = {\n fields: Field[]\n tenantEnabledCollectionSlugs: string[]\n tenantEnabledGlobalSlugs: string[]\n}\n\nexport function addFilterOptionsToFields({\n fields,\n tenantEnabledCollectionSlugs,\n tenantEnabledGlobalSlugs,\n}: AddFilterOptionsToFieldsArgs) {\n fields.forEach((field) => {\n if (field.type === 'relationship') {\n /**\n * Adjusts relationship fields to filter by tenant\n * and ensures relationTo cannot be a tenant global collection\n */\n if (typeof field.relationTo === 'string') {\n if (tenantEnabledGlobalSlugs.includes(field.relationTo)) {\n throw new Error(\n `The collection ${field.relationTo} is a global collection and cannot be related to a tenant enabled collection.`,\n )\n }\n if (tenantEnabledCollectionSlugs.includes(field.relationTo)) {\n addFilter(field, tenantEnabledCollectionSlugs)\n }\n } else {\n field.relationTo.map((relationTo) => {\n if (tenantEnabledGlobalSlugs.includes(relationTo)) {\n throw new Error(\n `The collection ${relationTo} is a global collection and cannot be related to a tenant enabled collection.`,\n )\n }\n if (tenantEnabledCollectionSlugs.includes(relationTo)) {\n addFilter(field, tenantEnabledCollectionSlugs)\n }\n })\n }\n }\n\n if (\n field.type === 'row' ||\n field.type === 'array' ||\n field.type === 'collapsible' ||\n field.type === 'group'\n ) {\n addFilterOptionsToFields({\n fields: field.fields,\n tenantEnabledCollectionSlugs,\n tenantEnabledGlobalSlugs,\n })\n }\n\n if (field.type === 'blocks') {\n field.blocks.forEach((block) => {\n addFilterOptionsToFields({\n fields: block.fields,\n tenantEnabledCollectionSlugs,\n tenantEnabledGlobalSlugs,\n })\n })\n }\n\n if (field.type === 'tabs') {\n field.tabs.forEach((tab) => {\n addFilterOptionsToFields({\n fields: tab.fields,\n tenantEnabledCollectionSlugs,\n tenantEnabledGlobalSlugs,\n })\n })\n }\n })\n}\n\nfunction addFilter(field: RelationshipField, tenantEnabledCollectionSlugs: string[]) {\n // User specified filter\n const originalFilter = field.filterOptions\n field.filterOptions = async (args) => {\n const originalFilterResult =\n typeof originalFilter === 'function' ? await originalFilter(args) : (originalFilter ?? true)\n\n // If the relationTo is not a tenant enabled collection, return early\n if (args.relationTo && !tenantEnabledCollectionSlugs.includes(args.relationTo)) {\n return originalFilterResult\n }\n\n // If the original filtr returns false, return early\n if (originalFilterResult === false) {\n return false\n }\n\n // Custom tenant filter\n const tenantFilterResults = filterOptionsByTenant(args)\n\n // If the tenant filter returns true, just use the original filter\n if (tenantFilterResults === true) {\n return originalFilterResult\n }\n\n // If the original filter returns true, just use the tenant filter\n if (originalFilterResult === true) {\n return tenantFilterResults\n }\n\n return {\n and: [originalFilterResult, tenantFilterResults],\n }\n }\n}\n\ntype Args = {\n tenantFieldName?: string\n} & FilterOptionsProps\nconst filterOptionsByTenant = ({ req, tenantFieldName = 'tenant' }: Args) => {\n const selectedTenant = getTenantFromCookie(req.headers, req.payload.db.defaultIDType)\n if (!selectedTenant) {\n return true\n }\n\n return {\n or: [\n // ie a related collection that doesn't have a tenant field\n {\n [tenantFieldName]: {\n exists: false,\n },\n },\n // related collections that have a tenant field\n {\n [tenantFieldName]: {\n equals: selectedTenant,\n },\n },\n ],\n }\n}\n"],"names":["getTenantFromCookie","addFilterOptionsToFields","fields","tenantEnabledCollectionSlugs","tenantEnabledGlobalSlugs","forEach","field","type","relationTo","includes","Error","addFilter","map","blocks","block","tabs","tab","originalFilter","filterOptions","args","originalFilterResult","tenantFilterResults","filterOptionsByTenant","and","req","tenantFieldName","selectedTenant","headers","payload","db","defaultIDType","or","exists","equals"],"mappings":"AAEA,SAASA,mBAAmB,QAAQ,2BAA0B;AAQ9D,OAAO,SAASC,yBAAyB,EACvCC,MAAM,EACNC,4BAA4B,EAC5BC,wBAAwB,EACK;IAC7BF,OAAOG,OAAO,CAAC,CAACC;QACd,IAAIA,MAAMC,IAAI,KAAK,g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,aAAa,MAAMA,eAAeE,QAASF,kBAAkB;QAEzF,qEAAqE;QACrE,IAAIE,KAAKX,UAAU,IAAI,CAACL,6BAA6BM,QAAQ,CAACU,KAAKX,UAAU,GAAG;YAC9E,OAAOY;QACT;QAEA,oDAAoD;QACpD,IAAIA,yBAAyB,OAAO;YAClC,OAAO;QACT;QAEA,uBAAuB;QACvB,MAAMC,sBAAsBC,sBAAsBH;QAElD,kEAAkE;QAClE,IAAIE,wBAAwB,MAAM;YAChC,OAAOD;QACT;QAEA,kEAAkE;QAClE,IAAIA,yBAAyB,MAAM;YACjC,OAAOC;QACT;QAEA,OAAO;YACLE,KAAK;gBAACH;gBAAsBC;aAAoB;QAClD;IACF;AACF;AAKA,MAAMC,wBAAwB,CAAC,EAAEE,GAAG,EAAEC,kBAAkB,QAAQ,EAAQ;IACtE,MAAMC,iBAAiB1B,oBAAoBwB,IAAIG,OAAO,EAAEH,IAAII,OAAO,CAACC,EAAE,CAACC,aAAa;IACpF,IAAI,CAACJ,gBAAgB;QACnB,OAAO;IACT;IAEA,OAAO;QACLK,IAAI;YACF,2DAA2D;YAC3D;gBACE,CAACN,gBAAgB,EAAE;oBACjBO,QAAQ;gBACV;YACF;YACA,+CAA+C;YAC/C;gBACE,CAACP,gBAAgB,EAAE;oBACjBQ,QAAQP;gBACV;YACF;SACD;IACH;AACF"}
@@ -1,11 +1,12 @@
1
1
  import type { Payload, ViewTypes } from 'payload';
2
2
  type Args = {
3
3
  docID?: number | string;
4
+ headers: Headers;
4
5
  payload: Payload;
5
6
  slug: string;
6
7
  tenantFieldName: string;
7
8
  view: ViewTypes;
8
9
  };
9
- export declare function getGlobalViewRedirect({ slug, docID, payload, tenantFieldName, view, }: Args): Promise<string | void>;
10
+ export declare function getGlobalViewRedirect({ slug, docID, headers, payload, tenantFieldName, view, }: Args): Promise<string | void>;
10
11
  export {};
11
12
  //# sourceMappingURL=getGlobalViewRedirect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getGlobalViewRedirect.d.ts","sourceRoot":"","sources":["../../src/utilities/getGlobalViewRedirect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAOjD,KAAK,IAAI,GAAG;IACV,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,eAAe,EAAE,MAAM,CAAA;IACvB,IAAI,EAAE,SAAS,CAAA;CAChB,CAAA;AACD,wBAAsB,qBAAqB,CAAC,EAC1C,IAAI,EACJ,KAAK,EACL,OAAO,EACP,eAAe,EACf,IAAI,GACL,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAgD/B"}
1
+ {"version":3,"file":"getGlobalViewRedirect.d.ts","sourceRoot":"","sources":["../../src/utilities/getGlobalViewRedirect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAKjD,KAAK,IAAI,GAAG;IACV,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,eAAe,EAAE,MAAM,CAAA;IACvB,IAAI,EAAE,SAAS,CAAA;CAChB,CAAA;AACD,wBAAsB,qBAAqB,CAAC,EAC1C,IAAI,EACJ,KAAK,EACL,OAAO,EACP,OAAO,EACP,eAAe,EACf,IAAI,GACL,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA+C/B"}
@@ -1,8 +1,6 @@
1
- import { headers as getHeaders } from 'next/headers.js';
2
1
  import { SELECT_ALL } from '../constants.js';
3
2
  import { getTenantFromCookie } from './getTenantFromCookie.js';
4
- export async function getGlobalViewRedirect({ slug, docID, payload, tenantFieldName, view }) {
5
- const headers = await getHeaders();
3
+ export async function getGlobalViewRedirect({ slug, docID, headers, payload, tenantFieldName, view }) {
6
4
  const tenant = getTenantFromCookie(headers, payload.db.defaultIDType);
7
5
  let redirectRoute;
8
6
  if (tenant) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/getGlobalViewRedirect.ts"],"sourcesContent":["import type { Payload, ViewTypes } from 'payload'\n\nimport { headers as getHeaders } from 'next/headers.js'\n\nimport { SELECT_ALL } from '../constants.js'\nimport { getTenantFromCookie } from './getTenantFromCookie.js'\n\ntype Args = {\n docID?: number | string\n payload: Payload\n slug: string\n tenantFieldName: string\n view: ViewTypes\n}\nexport async function getGlobalViewRedirect({\n slug,\n docID,\n payload,\n tenantFieldName,\n view,\n}: Args): Promise<string | void> {\n const headers = await getHeaders()\n const tenant = getTenantFromCookie(headers, payload.db.defaultIDType)\n let redirectRoute\n\n if (tenant) {\n try {\n const { docs } = await payload.find({\n collection: slug,\n depth: 0,\n limit: 1,\n where:\n tenant === SELECT_ALL\n ? {}\n : {\n [tenantFieldName]: {\n equals: tenant,\n },\n },\n })\n\n const tenantDocID = docs?.[0]?.id\n\n if (view === 'document') {\n if (docID && !tenantDocID) {\n // viewing a document with an id but does not match the selected tenant, redirect to create route\n redirectRoute = `${payload.config.routes.admin}/collections/${slug}/create`\n } else if (tenantDocID && docID !== tenantDocID) {\n // tenant document already exists but does not match current route doc ID, redirect to matching tenant doc\n redirectRoute = `${payload.config.routes.admin}/collections/${slug}/${tenantDocID}`\n }\n } else if (view === 'list') {\n if (tenantDocID) {\n // tenant document exists, redirect to edit view\n redirectRoute = `${payload.config.routes.admin}/collections/${slug}/${tenantDocID}`\n } else {\n // tenant document does not exist, redirect to create route\n redirectRoute = `${payload.config.routes.admin}/collections/${slug}/create`\n }\n }\n } catch (e: unknown) {\n payload.logger.error(\n e,\n `${typeof e === 'object' && e && 'message' in e ? `e?.message - ` : ''}Multi Tenant Redirect Error`,\n )\n }\n }\n return redirectRoute\n}\n"],"names":["headers","getHeaders","SELECT_ALL","getTenantFromCookie","getGlobalViewRedirect","slug","docID","payload","tenantFieldName","view","tenant","db","defaultIDType","redirectRoute","docs","find","collection","depth","limit","where","equals","tenantDocID","id","config","routes","admin","e","logger","error"],"mappings":"AAEA,SAASA,WAAWC,UAAU,QAAQ,kBAAiB;AAEvD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,mBAAmB,QAAQ,2BAA0B;AAS9D,OAAO,eAAeC,sBAAsB,EAC1CC,IAAI,EACJC,KAAK,EACLC,OAAO,EACPC,eAAe,EACfC,IAAI,EACC;IACL,MAAMT,UAAU,MAAMC;IACtB,MAAMS,SAASP,oBAAoBH,SAASO,QAAQI,EAAE,CAACC,aAAa;IACpE,IAAIC;IAEJ,IAAIH,QAAQ;QACV,IAAI;YACF,MAAM,EAAEI,IAAI,EAAE,GAAG,MAAMP,QAAQQ,IAAI,CAAC;gBAClCC,YAAYX;gBACZY,OAAO;gBACPC,OAAO;gBACPC,OACET,WAAWR,aACP,CAAC,IACD;oBACE,CAACM,gBAAgB,EAAE;wBACjBY,QAAQV;oBACV;gBACF;YACR;YAEA,MAAMW,cAAcP,MAAM,CAAC,EAAE,EAAEQ;YAE/B,IAAIb,SAAS,YAAY;gBACvB,IAAIH,SAAS,CAACe,aAAa;oBACzB,iGAAiG;oBACjGR,gBAAgB,GAAGN,QAAQgB,MAAM,CAACC,MAAM,CAACC,KAAK,CAAC,aAAa,EAAEpB,KAAK,OAAO,CAAC;gBAC7E,OAAO,IAAIgB,eAAef,UAAUe,aAAa;oBAC/C,0GAA0G;oBAC1GR,gBAAgB,GAAGN,QAAQgB,MAAM,CAACC,MAAM,CAACC,KAAK,CAAC,aAAa,EAAEpB,KAAK,CAAC,EAAEgB,aAAa;gBACrF;YACF,OAAO,IAAIZ,SAAS,QAAQ;gBAC1B,IAAIY,aAAa;oBACf,gDAAgD;oBAChDR,gBAAgB,GAAGN,QAAQgB,MAAM,CAACC,MAAM,CAACC,KAAK,CAAC,aAAa,EAAEpB,KAAK,CAAC,EAAEgB,aAAa;gBACrF,OAAO;oBACL,2DAA2D;oBAC3DR,gBAAgB,GAAGN,QAAQgB,MAAM,CAACC,MAAM,CAACC,KAAK,CAAC,aAAa,EAAEpB,KAAK,OAAO,CAAC;gBAC7E;YACF;QACF,EAAE,OAAOqB,GAAY;YACnBnB,QAAQoB,MAAM,CAACC,KAAK,CAClBF,GACA,GAAG,OAAOA,MAAM,YAAYA,KAAK,aAAaA,IAAI,CAAC,aAAa,CAAC,GAAG,GAAG,2BAA2B,CAAC;QAEvG;IACF;IACA,OAAOb;AACT"}
1
+ {"version":3,"sources":["../../src/utilities/getGlobalViewRedirect.ts"],"sourcesContent":["import type { Payload, ViewTypes } from 'payload'\n\nimport { SELECT_ALL } from '../constants.js'\nimport { getTenantFromCookie } from './getTenantFromCookie.js'\n\ntype Args = {\n docID?: number | string\n headers: Headers\n payload: Payload\n slug: string\n tenantFieldName: string\n view: ViewTypes\n}\nexport async function getGlobalViewRedirect({\n slug,\n docID,\n headers,\n payload,\n tenantFieldName,\n view,\n}: Args): Promise<string | void> {\n const tenant = getTenantFromCookie(headers, payload.db.defaultIDType)\n let redirectRoute\n\n if (tenant) {\n try {\n const { docs } = await payload.find({\n collection: slug,\n depth: 0,\n limit: 1,\n where:\n tenant === SELECT_ALL\n ? {}\n : {\n [tenantFieldName]: {\n equals: tenant,\n },\n },\n })\n\n const tenantDocID = docs?.[0]?.id\n\n if (view === 'document') {\n if (docID && !tenantDocID) {\n // viewing a document with an id but does not match the selected tenant, redirect to create route\n redirectRoute = `${payload.config.routes.admin}/collections/${slug}/create`\n } else if (tenantDocID && docID !== tenantDocID) {\n // tenant document already exists but does not match current route doc ID, redirect to matching tenant doc\n redirectRoute = `${payload.config.routes.admin}/collections/${slug}/${tenantDocID}`\n }\n } else if (view === 'list') {\n if (tenantDocID) {\n // tenant document exists, redirect to edit view\n redirectRoute = `${payload.config.routes.admin}/collections/${slug}/${tenantDocID}`\n } else {\n // tenant document does not exist, redirect to create route\n redirectRoute = `${payload.config.routes.admin}/collections/${slug}/create`\n }\n }\n } catch (e: unknown) {\n payload.logger.error(\n e,\n `${typeof e === 'object' && e && 'message' in e ? `e?.message - ` : ''}Multi Tenant Redirect Error`,\n )\n }\n }\n return redirectRoute\n}\n"],"names":["SELECT_ALL","getTenantFromCookie","getGlobalViewRedirect","slug","docID","headers","payload","tenantFieldName","view","tenant","db","defaultIDType","redirectRoute","docs","find","collection","depth","limit","where","equals","tenantDocID","id","config","routes","admin","e","logger","error"],"mappings":"AAEA,SAASA,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,mBAAmB,QAAQ,2BAA0B;AAU9D,OAAO,eAAeC,sBAAsB,EAC1CC,IAAI,EACJC,KAAK,EACLC,OAAO,EACPC,OAAO,EACPC,eAAe,EACfC,IAAI,EACC;IACL,MAAMC,SAASR,oBAAoBI,SAASC,QAAQI,EAAE,CAACC,aAAa;IACpE,IAAIC;IAEJ,IAAIH,QAAQ;QACV,IAAI;YACF,MAAM,EAAEI,IAAI,EAAE,GAAG,MAAMP,QAAQQ,IAAI,CAAC;gBAClCC,YAAYZ;gBACZa,OAAO;gBACPC,OAAO;gBACPC,OACET,WAAWT,aACP,CAAC,IACD;oBACE,CAACO,gBAAgB,EAAE;wBACjBY,QAAQV;oBACV;gBACF;YACR;YAEA,MAAMW,cAAcP,MAAM,CAAC,EAAE,EAAEQ;YAE/B,IAAIb,SAAS,YAAY;gBACvB,IAAIJ,SAAS,CAACgB,aAAa;oBACzB,iGAAiG;oBACjGR,gBAAgB,GAAGN,QAAQgB,MAAM,CAACC,MAAM,CAACC,KAAK,CAAC,aAAa,EAAErB,KAAK,OAAO,CAAC;gBAC7E,OAAO,IAAIiB,eAAehB,UAAUgB,aAAa;oBAC/C,0GAA0G;oBAC1GR,gBAAgB,GAAGN,QAAQgB,MAAM,CAACC,MAAM,CAACC,KAAK,CAAC,aAAa,EAAErB,KAAK,CAAC,EAAEiB,aAAa;gBACrF;YACF,OAAO,IAAIZ,SAAS,QAAQ;gBAC1B,IAAIY,aAAa;oBACf,gDAAgD;oBAChDR,gBAAgB,GAAGN,QAAQgB,MAAM,CAACC,MAAM,CAACC,KAAK,CAAC,aAAa,EAAErB,KAAK,CAAC,EAAEiB,aAAa;gBACrF,OAAO;oBACL,2DAA2D;oBAC3DR,gBAAgB,GAAGN,QAAQgB,MAAM,CAACC,MAAM,CAACC,KAAK,CAAC,aAAa,EAAErB,KAAK,OAAO,CAAC;gBAC7E;YACF;QACF,EAAE,OAAOsB,GAAY;YACnBnB,QAAQoB,MAAM,CAACC,KAAK,CAClBF,GACA,GAAG,OAAOA,MAAM,YAAYA,KAAK,aAAaA,IAAI,CAAC,aAAa,CAAC,GAAG,GAAG,2BAA2B,CAAC;QAEvG;IACF;IACA,OAAOb;AACT"}
@@ -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: User } ? 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"}
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.18.0",
3
+ "version": "3.19.0-canary.9b65c78",
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.18.0",
71
- "payload": "3.18.0"
70
+ "payload": "3.19.0-canary.9b65c78",
71
+ "@payloadcms/ui": "3.19.0-canary.9b65c78"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "next": "^15.0.3",
75
- "@payloadcms/ui": "3.18.0",
76
- "payload": "3.18.0"
75
+ "@payloadcms/ui": "3.19.0-canary.9b65c78",
76
+ "payload": "3.19.0-canary.9b65c78"
77
77
  },
78
78
  "homepage:": "https://payloadcms.com",
79
79
  "scripts": {