@payloadcms/plugin-multi-tenant 3.21.0-canary.db74962 → 3.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/TenantSelector/index.js +1 -1
- package/dist/components/TenantSelector/index.js.map +1 -1
- package/dist/providers/TenantSelectionProvider/index.d.ts.map +1 -1
- package/dist/providers/TenantSelectionProvider/index.js +10 -6
- package/dist/providers/TenantSelectionProvider/index.js.map +1 -1
- package/dist/utilities/getTenantFromCookie.d.ts.map +1 -1
- package/dist/utilities/getTenantFromCookie.js +2 -1
- package/dist/utilities/getTenantFromCookie.js.map +1 -1
- package/package.json +5 -5
|
@@ -34,7 +34,7 @@ export const TenantSelector = ({ viewType })=>{
|
|
|
34
34
|
onChange: handleChange,
|
|
35
35
|
options: options,
|
|
36
36
|
path: "setTenant",
|
|
37
|
-
value: selectedTenantID ? selectedTenantID === SELECT_ALL ? undefined :
|
|
37
|
+
value: selectedTenantID ? selectedTenantID === SELECT_ALL ? undefined : selectedTenantID : undefined
|
|
38
38
|
})
|
|
39
39
|
});
|
|
40
40
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/TenantSelector/index.tsx"],"sourcesContent":["'use client'\nimport type { ReactSelectOption } from '@payloadcms/ui'\nimport type { ViewTypes } from 'payload'\n\nimport { SelectInput } from '@payloadcms/ui'\n\nimport './index.scss'\n\nimport React from 'react'\n\nimport { SELECT_ALL } from '../../constants.js'\nimport { useTenantSelection } from '../../providers/TenantSelectionProvider/index.client.js'\n\nexport const TenantSelector = ({ viewType }: { viewType?: ViewTypes }) => {\n const { options, selectedTenantID, setTenant } = useTenantSelection()\n\n const handleChange = React.useCallback(\n (option: ReactSelectOption | ReactSelectOption[]) => {\n if (option && 'value' in option) {\n setTenant({ id: option.value as string, refresh: true })\n } else {\n setTenant({ id: undefined, refresh: true })\n }\n },\n [setTenant],\n )\n\n if (options.length <= 1) {\n return null\n }\n\n return (\n <div className=\"tenant-selector\">\n <SelectInput\n isClearable={viewType === 'list'}\n label=\"Tenant\"\n name=\"setTenant\"\n onChange={handleChange}\n options={options}\n path=\"setTenant\"\n value={\n selectedTenantID\n ? selectedTenantID === SELECT_ALL\n ? undefined\n :
|
|
1
|
+
{"version":3,"sources":["../../../src/components/TenantSelector/index.tsx"],"sourcesContent":["'use client'\nimport type { ReactSelectOption } from '@payloadcms/ui'\nimport type { ViewTypes } from 'payload'\n\nimport { SelectInput } from '@payloadcms/ui'\n\nimport './index.scss'\n\nimport React from 'react'\n\nimport { SELECT_ALL } from '../../constants.js'\nimport { useTenantSelection } from '../../providers/TenantSelectionProvider/index.client.js'\n\nexport const TenantSelector = ({ viewType }: { viewType?: ViewTypes }) => {\n const { options, selectedTenantID, setTenant } = useTenantSelection()\n\n const handleChange = React.useCallback(\n (option: ReactSelectOption | ReactSelectOption[]) => {\n if (option && 'value' in option) {\n setTenant({ id: option.value as string, refresh: true })\n } else {\n setTenant({ id: undefined, refresh: true })\n }\n },\n [setTenant],\n )\n\n if (options.length <= 1) {\n return null\n }\n\n return (\n <div className=\"tenant-selector\">\n <SelectInput\n isClearable={viewType === 'list'}\n label=\"Tenant\"\n name=\"setTenant\"\n onChange={handleChange}\n options={options}\n path=\"setTenant\"\n value={\n selectedTenantID\n ? selectedTenantID === SELECT_ALL\n ? undefined\n : (selectedTenantID as string)\n : undefined\n }\n />\n </div>\n )\n}\n"],"names":["SelectInput","React","SELECT_ALL","useTenantSelection","TenantSelector","viewType","options","selectedTenantID","setTenant","handleChange","useCallback","option","id","value","refresh","undefined","length","div","className","isClearable","label","name","onChange","path"],"mappings":"AAAA;;AAIA,SAASA,WAAW,QAAQ,iBAAgB;AAE5C,OAAO,eAAc;AAErB,OAAOC,WAAW,QAAO;AAEzB,SAASC,UAAU,QAAQ,qBAAoB;AAC/C,SAASC,kBAAkB,QAAQ,0DAAyD;AAE5F,OAAO,MAAMC,iBAAiB,CAAC,EAAEC,QAAQ,EAA4B;IACnE,MAAM,EAAEC,OAAO,EAAEC,gBAAgB,EAAEC,SAAS,EAAE,GAAGL;IAEjD,MAAMM,eAAeR,MAAMS,WAAW,CACpC,CAACC;QACC,IAAIA,UAAU,WAAWA,QAAQ;YAC/BH,UAAU;gBAAEI,IAAID,OAAOE,KAAK;gBAAYC,SAAS;YAAK;QACxD,OAAO;YACLN,UAAU;gBAAEI,IAAIG;gBAAWD,SAAS;YAAK;QAC3C;IACF,GACA;QAACN;KAAU;IAGb,IAAIF,QAAQU,MAAM,IAAI,GAAG;QACvB,OAAO;IACT;IAEA,qBACE,KAACC;QAAIC,WAAU;kBACb,cAAA,KAAClB;YACCmB,aAAad,aAAa;YAC1Be,OAAM;YACNC,MAAK;YACLC,UAAUb;YACVH,SAASA;YACTiB,MAAK;YACLV,OACEN,mBACIA,qBAAqBL,aACnBa,YACCR,mBACHQ;;;AAKd,EAAC"}
|
|
@@ -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;AAQ1D,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;AAQ1D,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,yCA4CN,CAAA"}
|
|
@@ -15,7 +15,7 @@ export const TenantSelectionProvider = async ({ children, payload, tenantsCollec
|
|
|
15
15
|
});
|
|
16
16
|
tenantOptions = docs.map((doc)=>({
|
|
17
17
|
label: String(doc[useAsTitle]),
|
|
18
|
-
value:
|
|
18
|
+
value: doc.id
|
|
19
19
|
}));
|
|
20
20
|
} catch (_) {
|
|
21
21
|
// user likely does not have access
|
|
@@ -23,12 +23,16 @@ export const TenantSelectionProvider = async ({ children, payload, tenantsCollec
|
|
|
23
23
|
const cookies = await getCookies();
|
|
24
24
|
let tenantCookie = cookies.get('payload-tenant')?.value;
|
|
25
25
|
let initialValue = undefined;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
initialValue = tenantCookie;
|
|
26
|
+
if (tenantOptions.length > 1 && tenantCookie === SELECT_ALL) {
|
|
27
|
+
initialValue = SELECT_ALL;
|
|
29
28
|
} else {
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
const matchingOption = tenantOptions.find((option)=>String(option.value) === tenantCookie);
|
|
30
|
+
if (matchingOption) {
|
|
31
|
+
initialValue = matchingOption.value;
|
|
32
|
+
} else {
|
|
33
|
+
tenantCookie = undefined;
|
|
34
|
+
initialValue = tenantOptions.length > 1 ? SELECT_ALL : tenantOptions[0]?.value;
|
|
35
|
+
}
|
|
32
36
|
}
|
|
33
37
|
return /*#__PURE__*/ _jsx(TenantSelectionProviderClient, {
|
|
34
38
|
initialValue: initialValue,
|
|
@@ -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 { SELECT_ALL } from '../../constants.js'\nimport { findTenantOptions } from '../../queries/findTenantOptions.js'\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 } = await findTenantOptions({\n limit: 0,\n payload,\n tenantsCollectionSlug,\n useAsTitle,\n user,\n })\n tenantOptions = docs.map((doc) => ({\n label: String(doc[useAsTitle]),\n value:
|
|
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 { SELECT_ALL } from '../../constants.js'\nimport { findTenantOptions } from '../../queries/findTenantOptions.js'\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 } = await findTenantOptions({\n limit: 0,\n payload,\n tenantsCollectionSlug,\n useAsTitle,\n user,\n })\n tenantOptions = docs.map((doc) => ({\n label: String(doc[useAsTitle]),\n value: doc.id,\n }))\n } catch (_) {\n // user likely does not have access\n }\n\n const cookies = await getCookies()\n let tenantCookie = cookies.get('payload-tenant')?.value\n let initialValue = undefined\n\n if (tenantOptions.length > 1 && tenantCookie === SELECT_ALL) {\n initialValue = SELECT_ALL\n } else {\n const matchingOption = tenantOptions.find((option) => String(option.value) === tenantCookie)\n if (matchingOption) {\n initialValue = matchingOption.value\n } else {\n tenantCookie = undefined\n initialValue = tenantOptions.length > 1 ? SELECT_ALL : tenantOptions[0]?.value\n }\n }\n\n return (\n <TenantSelectionProviderClient\n initialValue={initialValue}\n tenantCookie={tenantCookie}\n tenantOptions={tenantOptions}\n >\n {children}\n </TenantSelectionProviderClient>\n )\n}\n"],"names":["cookies","getCookies","SELECT_ALL","findTenantOptions","TenantSelectionProviderClient","TenantSelectionProvider","children","payload","tenantsCollectionSlug","useAsTitle","user","tenantOptions","docs","limit","map","doc","label","String","value","id","_","tenantCookie","get","initialValue","undefined","length","matchingOption","find","option"],"mappings":";AAEA,SAASA,WAAWC,UAAU,QAAQ,kBAAiB;AAEvD,SAASC,UAAU,QAAQ,qBAAoB;AAC/C,SAASC,iBAAiB,QAAQ,qCAAoC;AACtE,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,IAAI,EAAE,GAAG,MAAMT,kBAAkB;YACvCU,OAAO;YACPN;YACAC;YACAC;YACAC;QACF;QACAC,gBAAgBC,KAAKE,GAAG,CAAC,CAACC,MAAS,CAAA;gBACjCC,OAAOC,OAAOF,GAAG,CAACN,WAAW;gBAC7BS,OAAOH,IAAII,EAAE;YACf,CAAA;IACF,EAAE,OAAOC,GAAG;IACV,mCAAmC;IACrC;IAEA,MAAMpB,UAAU,MAAMC;IACtB,IAAIoB,eAAerB,QAAQsB,GAAG,CAAC,mBAAmBJ;IAClD,IAAIK,eAAeC;IAEnB,IAAIb,cAAcc,MAAM,GAAG,KAAKJ,iBAAiBnB,YAAY;QAC3DqB,eAAerB;IACjB,OAAO;QACL,MAAMwB,iBAAiBf,cAAcgB,IAAI,CAAC,CAACC,SAAWX,OAAOW,OAAOV,KAAK,MAAMG;QAC/E,IAAIK,gBAAgB;YAClBH,eAAeG,eAAeR,KAAK;QACrC,OAAO;YACLG,eAAeG;YACfD,eAAeZ,cAAcc,MAAM,GAAG,IAAIvB,aAAaS,aAAa,CAAC,EAAE,EAAEO;QAC3E;IACF;IAEA,qBACE,KAACd;QACCmB,cAAcA;QACdF,cAAcA;QACdV,eAAeA;kBAEdL;;AAGP,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTenantFromCookie.d.ts","sourceRoot":"","sources":["../../src/utilities/getTenantFromCookie.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getTenantFromCookie.d.ts","sourceRoot":"","sources":["../../src/utilities/getTenantFromCookie.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,QAAQ,GAAG,MAAM,GACxB,IAAI,GAAG,MAAM,GAAG,MAAM,CAQxB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { parseCookies } from 'payload';
|
|
2
|
+
import { isNumber } from 'payload/shared';
|
|
2
3
|
/**
|
|
3
4
|
* A function that takes request headers and an idType and returns the current tenant ID from the cookie
|
|
4
5
|
*
|
|
@@ -8,7 +9,7 @@ import { parseCookies } from 'payload';
|
|
|
8
9
|
*/ export function getTenantFromCookie(headers, idType) {
|
|
9
10
|
const cookies = parseCookies(headers);
|
|
10
11
|
const selectedTenant = cookies.get('payload-tenant') || null;
|
|
11
|
-
return selectedTenant ? idType === 'number' ? parseFloat(selectedTenant) : selectedTenant : null;
|
|
12
|
+
return selectedTenant ? idType === 'number' && isNumber(selectedTenant) ? parseFloat(selectedTenant) : selectedTenant : null;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
//# sourceMappingURL=getTenantFromCookie.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getTenantFromCookie.ts"],"sourcesContent":["import { parseCookies } from 'payload'\n\n/**\n * A function that takes request headers and an idType and returns the current tenant ID from the cookie\n *\n * @param headers Headers, usually derived from req.headers or next/headers\n * @param idType can be 'number' | 'text', usually derived from payload.db.defaultIDType\n * @returns string | number | null\n */\nexport function getTenantFromCookie(\n headers: Headers,\n idType: 'number' | 'text',\n): null | number | string {\n const cookies = parseCookies(headers)\n const selectedTenant = cookies.get('payload-tenant') || null\n return selectedTenant
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getTenantFromCookie.ts"],"sourcesContent":["import { parseCookies } from 'payload'\nimport { isNumber } from 'payload/shared'\n\n/**\n * A function that takes request headers and an idType and returns the current tenant ID from the cookie\n *\n * @param headers Headers, usually derived from req.headers or next/headers\n * @param idType can be 'number' | 'text', usually derived from payload.db.defaultIDType\n * @returns string | number | null\n */\nexport function getTenantFromCookie(\n headers: Headers,\n idType: 'number' | 'text',\n): null | number | string {\n const cookies = parseCookies(headers)\n const selectedTenant = cookies.get('payload-tenant') || null\n return selectedTenant\n ? idType === 'number' && isNumber(selectedTenant)\n ? parseFloat(selectedTenant)\n : selectedTenant\n : null\n}\n"],"names":["parseCookies","isNumber","getTenantFromCookie","headers","idType","cookies","selectedTenant","get","parseFloat"],"mappings":"AAAA,SAASA,YAAY,QAAQ,UAAS;AACtC,SAASC,QAAQ,QAAQ,iBAAgB;AAEzC;;;;;;CAMC,GACD,OAAO,SAASC,oBACdC,OAAgB,EAChBC,MAAyB;IAEzB,MAAMC,UAAUL,aAAaG;IAC7B,MAAMG,iBAAiBD,QAAQE,GAAG,CAAC,qBAAqB;IACxD,OAAOD,iBACHF,WAAW,YAAYH,SAASK,kBAC9BE,WAAWF,kBACXA,iBACF;AACN"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-multi-tenant",
|
|
3
|
-
"version": "3.21.0
|
|
3
|
+
"version": "3.21.0",
|
|
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.21.0
|
|
71
|
-
"payload": "3.21.0
|
|
70
|
+
"@payloadcms/ui": "3.21.0",
|
|
71
|
+
"payload": "3.21.0"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
74
|
"next": "^15.0.3",
|
|
75
|
-
"@payloadcms/ui": "3.21.0
|
|
76
|
-
"payload": "3.21.0
|
|
75
|
+
"@payloadcms/ui": "3.21.0",
|
|
76
|
+
"payload": "3.21.0"
|
|
77
77
|
},
|
|
78
78
|
"homepage:": "https://payloadcms.com",
|
|
79
79
|
"scripts": {
|