@payloadcms/plugin-multi-tenant 3.29.0-internal.2984e42 → 3.29.0-internal.37e46b5
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 +2 -38
- package/dist/components/GlobalViewRedirect/index.d.ts +0 -1
- package/dist/components/GlobalViewRedirect/index.d.ts.map +1 -1
- package/dist/components/GlobalViewRedirect/index.js +0 -1
- package/dist/components/GlobalViewRedirect/index.js.map +1 -1
- package/dist/components/TenantField/index.client.d.ts.map +1 -1
- package/dist/components/TenantField/index.client.js +3 -2
- package/dist/components/TenantField/index.client.js.map +1 -1
- package/dist/components/TenantSelector/index.d.ts +1 -1
- package/dist/components/TenantSelector/index.d.ts.map +1 -1
- package/dist/components/TenantSelector/index.js +5 -5
- package/dist/components/TenantSelector/index.js.map +1 -1
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +4 -0
- package/dist/constants.js.map +1 -0
- package/dist/defaults.d.ts +0 -1
- package/dist/defaults.d.ts.map +1 -1
- package/dist/defaults.js +0 -1
- package/dist/defaults.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -5
- package/dist/index.js.map +1 -1
- package/dist/list-filters/filterDocumentsBySelectedTenant.d.ts.map +1 -1
- package/dist/list-filters/filterDocumentsBySelectedTenant.js +8 -7
- package/dist/list-filters/filterDocumentsBySelectedTenant.js.map +1 -1
- package/dist/list-filters/filterTenantsBySelectedTenant.d.ts.map +1 -1
- package/dist/list-filters/filterTenantsBySelectedTenant.js +8 -7
- package/dist/list-filters/filterTenantsBySelectedTenant.js.map +1 -1
- package/dist/list-filters/filterUsersBySelectedTenant.d.ts.map +1 -1
- package/dist/list-filters/filterUsersBySelectedTenant.js +10 -9
- package/dist/list-filters/filterUsersBySelectedTenant.js.map +1 -1
- package/dist/providers/TenantSelectionProvider/index.client.d.ts.map +1 -1
- package/dist/providers/TenantSelectionProvider/index.client.js +10 -15
- 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 +7 -9
- package/dist/providers/TenantSelectionProvider/index.js.map +1 -1
- package/dist/types.d.ts +1 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/getGlobalViewRedirect.d.ts +1 -2
- package/dist/utilities/getGlobalViewRedirect.d.ts.map +1 -1
- package/dist/utilities/getGlobalViewRedirect.js +9 -17
- package/dist/utilities/getGlobalViewRedirect.js.map +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -86,18 +86,6 @@ type MultiTenantPluginConfig<ConfigTypes = unknown> = {
|
|
|
86
86
|
* Access configuration for the array field
|
|
87
87
|
*/
|
|
88
88
|
arrayFieldAccess?: ArrayField['access']
|
|
89
|
-
/**
|
|
90
|
-
* Name of the array field
|
|
91
|
-
*
|
|
92
|
-
* @default 'tenants'
|
|
93
|
-
*/
|
|
94
|
-
arrayFieldName?: string
|
|
95
|
-
/**
|
|
96
|
-
* Name of the tenant field
|
|
97
|
-
*
|
|
98
|
-
* @default 'tenant'
|
|
99
|
-
*/
|
|
100
|
-
arrayTenantFieldName?: string
|
|
101
89
|
/**
|
|
102
90
|
* When `includeDefaultField` is `true`, the field will be added to the users collection automatically
|
|
103
91
|
*/
|
|
@@ -113,8 +101,6 @@ type MultiTenantPluginConfig<ConfigTypes = unknown> = {
|
|
|
113
101
|
}
|
|
114
102
|
| {
|
|
115
103
|
arrayFieldAccess?: never
|
|
116
|
-
arrayFieldName?: string
|
|
117
|
-
arrayTenantFieldName?: string
|
|
118
104
|
/**
|
|
119
105
|
* When `includeDefaultField` is `false`, you must include the field on your users collection manually
|
|
120
106
|
*/
|
|
@@ -122,16 +108,6 @@ type MultiTenantPluginConfig<ConfigTypes = unknown> = {
|
|
|
122
108
|
rowFields?: never
|
|
123
109
|
tenantFieldAccess?: never
|
|
124
110
|
}
|
|
125
|
-
/**
|
|
126
|
-
* Customize tenant selector label
|
|
127
|
-
*
|
|
128
|
-
* Either a string or an object where the keys are i18n codes and the values are the string labels
|
|
129
|
-
*/
|
|
130
|
-
tenantSelectorLabel?:
|
|
131
|
-
| Partial<{
|
|
132
|
-
[key in AcceptedLanguages]?: string
|
|
133
|
-
}>
|
|
134
|
-
| string
|
|
135
111
|
/**
|
|
136
112
|
* The slug for the tenant collection
|
|
137
113
|
*
|
|
@@ -144,20 +120,8 @@ type MultiTenantPluginConfig<ConfigTypes = unknown> = {
|
|
|
144
120
|
* Useful for super-admin type users
|
|
145
121
|
*/
|
|
146
122
|
userHasAccessToAllTenants?: (
|
|
147
|
-
user: ConfigTypes extends { user
|
|
123
|
+
user: ConfigTypes extends { user } ? ConfigTypes['user'] : User,
|
|
148
124
|
) => boolean
|
|
149
|
-
/**
|
|
150
|
-
* Opt out of adding access constraints to the tenants collection
|
|
151
|
-
*/
|
|
152
|
-
useTenantsCollectionAccess?: boolean
|
|
153
|
-
/**
|
|
154
|
-
* Opt out including the baseListFilter to filter tenants by selected tenant
|
|
155
|
-
*/
|
|
156
|
-
useTenantsListFilter?: boolean
|
|
157
|
-
/**
|
|
158
|
-
* Opt out including the baseListFilter to filter users by selected tenant
|
|
159
|
-
*/
|
|
160
|
-
useUsersTenantFilter?: boolean
|
|
161
125
|
}
|
|
162
126
|
```
|
|
163
127
|
|
|
@@ -195,7 +159,7 @@ import { Config as ConfigTypes } from './payload-types'
|
|
|
195
159
|
// Add the plugin to your payload config
|
|
196
160
|
export default buildConfig({
|
|
197
161
|
plugins: [
|
|
198
|
-
multiTenantPlugin
|
|
162
|
+
multiTenantPlugin({
|
|
199
163
|
collections: {
|
|
200
164
|
media: {
|
|
201
165
|
useTenantAccess: false,
|
|
@@ -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;AAOrE,KAAK,IAAI,GAAG;IACV,
|
|
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,qBAAqB,EAAE,MAAM,CAAA;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,SAAS,CAAA;CACpB,GAAG,WAAW,CAAA;AAEf,eAAO,MAAM,kBAAkB,SAAgB,IAAI,kBAoBlD,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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 tenantsCollectionSlug: string\n useAsTitle: string\n viewType: ViewTypes\n} & ServerProps\n\nexport const GlobalViewRedirect = async (args: Args) => {\n const collectionSlug = args?.collectionSlug\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 tenantsCollectionSlug: args.tenantsCollectionSlug,\n useAsTitle: args.useAsTitle,\n user: args.user,\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","tenantsCollectionSlug","useAsTitle","user","view","viewType"],"mappings":"AAEA,SAASA,WAAWC,UAAU,QAAQ,kBAAiB;AACvD,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,SAASC,qBAAqB,QAAQ,2CAA0C;AAYhF,OAAO,MAAMC,qBAAqB,OAAOC;IACvC,MAAMC,iBAAiBD,MAAMC;IAC7B,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,uBAAuBT,KAAKS,qBAAqB;YACjDC,YAAYV,KAAKU,UAAU;YAC3BC,MAAMX,KAAKW,IAAI;YACfC,MAAMZ,KAAKa,QAAQ;QACrB;QAEA,IAAIT,eAAe;YACjBP,SAASO;QACX;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.client.d.ts","sourceRoot":"","sources":["../../../src/components/TenantField/index.client.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAA;AAG3D,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"index.client.d.ts","sourceRoot":"","sources":["../../../src/components/TenantField/index.client.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAA;AAG3D,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,OAAO,cAAc,CAAA;AAIrB,KAAK,KAAK,GAAG;IACX,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,GAAG,4BAA4B,CAAA;AAEhC,eAAO,MAAM,WAAW,SAAU,KAAK,6BAgDtC,CAAA"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { RelationshipField, useField } from '@payloadcms/ui';
|
|
4
4
|
import React from 'react';
|
|
5
|
+
import { SELECT_ALL } from '../../constants.js';
|
|
5
6
|
import { useTenantSelection } from '../../providers/TenantSelectionProvider/index.client.js';
|
|
6
7
|
import './index.scss';
|
|
7
8
|
const baseClass = 'tenantField';
|
|
@@ -22,14 +23,14 @@ export const TenantField = (args)=>{
|
|
|
22
23
|
});
|
|
23
24
|
} else {
|
|
24
25
|
// in the document view, the tenant field should always have a value
|
|
25
|
-
const defaultValue = selectedTenantID || options[0]?.value;
|
|
26
|
+
const defaultValue = !selectedTenantID || selectedTenantID === SELECT_ALL ? options[0]?.value : selectedTenantID;
|
|
26
27
|
setTenant({
|
|
27
28
|
id: defaultValue,
|
|
28
29
|
refresh: unique
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
hasSetValueRef.current = true;
|
|
32
|
-
} else if (!value || value !== selectedTenantID) {
|
|
33
|
+
} else if ((!value || value !== selectedTenantID) && selectedTenantID !== SELECT_ALL) {
|
|
33
34
|
// Update the field on the document value when the tenant is changed
|
|
34
35
|
setValue(selectedTenantID);
|
|
35
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/TenantField/index.client.tsx"],"sourcesContent":["'use client'\n\nimport type { RelationshipFieldClientProps } from 'payload'\n\nimport { RelationshipField, useField } from '@payloadcms/ui'\nimport React from 'react'\n\nimport { useTenantSelection } from '../../providers/TenantSelectionProvider/index.client.js'\nimport './index.scss'\n\nconst baseClass = 'tenantField'\n\ntype Props = {\n debug?: boolean\n unique?: boolean\n} & RelationshipFieldClientProps\n\nexport const TenantField = (args: Props) => {\n const { debug, path, unique } = args\n const { setValue, value } = useField<number | string>({ path })\n const { options, selectedTenantID, setPreventRefreshOnChange, setTenant } = useTenantSelection()\n\n const hasSetValueRef = React.useRef(false)\n\n React.useEffect(() => {\n if (!hasSetValueRef.current) {\n // set value on load\n if (value && value !== selectedTenantID) {\n setTenant({ id: value, refresh: unique })\n } else {\n // in the document view, the tenant field should always have a value\n const defaultValue
|
|
1
|
+
{"version":3,"sources":["../../../src/components/TenantField/index.client.tsx"],"sourcesContent":["'use client'\n\nimport type { RelationshipFieldClientProps } from 'payload'\n\nimport { RelationshipField, useField } from '@payloadcms/ui'\nimport React from 'react'\n\nimport { SELECT_ALL } from '../../constants.js'\nimport { useTenantSelection } from '../../providers/TenantSelectionProvider/index.client.js'\nimport './index.scss'\n\nconst baseClass = 'tenantField'\n\ntype Props = {\n debug?: boolean\n unique?: boolean\n} & RelationshipFieldClientProps\n\nexport const TenantField = (args: Props) => {\n const { debug, path, unique } = args\n const { setValue, value } = useField<number | string>({ path })\n const { options, selectedTenantID, setPreventRefreshOnChange, setTenant } = useTenantSelection()\n\n const hasSetValueRef = React.useRef(false)\n\n React.useEffect(() => {\n if (!hasSetValueRef.current) {\n // set value on load\n if (value && value !== selectedTenantID) {\n setTenant({ id: value, refresh: unique })\n } else {\n // in the document view, the tenant field should always have a value\n const defaultValue =\n !selectedTenantID || selectedTenantID === SELECT_ALL\n ? options[0]?.value\n : selectedTenantID\n setTenant({ id: defaultValue, refresh: unique })\n }\n hasSetValueRef.current = true\n } else if ((!value || value !== selectedTenantID) && selectedTenantID !== SELECT_ALL) {\n // Update the field on the document value when the tenant is changed\n setValue(selectedTenantID)\n }\n }, [value, selectedTenantID, setTenant, setValue, options, unique])\n\n React.useEffect(() => {\n if (!unique) {\n setPreventRefreshOnChange(true)\n }\n return () => {\n setPreventRefreshOnChange(false)\n }\n }, [unique, setPreventRefreshOnChange])\n\n if (debug) {\n return (\n <div className={baseClass}>\n <div className={`${baseClass}__wrapper`}>\n <RelationshipField {...args} />\n </div>\n <div className={`${baseClass}__hr`} />\n </div>\n )\n }\n\n return null\n}\n"],"names":["RelationshipField","useField","React","SELECT_ALL","useTenantSelection","baseClass","TenantField","args","debug","path","unique","setValue","value","options","selectedTenantID","setPreventRefreshOnChange","setTenant","hasSetValueRef","useRef","useEffect","current","id","refresh","defaultValue","div","className"],"mappings":"AAAA;;AAIA,SAASA,iBAAiB,EAAEC,QAAQ,QAAQ,iBAAgB;AAC5D,OAAOC,WAAW,QAAO;AAEzB,SAASC,UAAU,QAAQ,qBAAoB;AAC/C,SAASC,kBAAkB,QAAQ,0DAAyD;AAC5F,OAAO,eAAc;AAErB,MAAMC,YAAY;AAOlB,OAAO,MAAMC,cAAc,CAACC;IAC1B,MAAM,EAAEC,KAAK,EAAEC,IAAI,EAAEC,MAAM,EAAE,GAAGH;IAChC,MAAM,EAAEI,QAAQ,EAAEC,KAAK,EAAE,GAAGX,SAA0B;QAAEQ;IAAK;IAC7D,MAAM,EAAEI,OAAO,EAAEC,gBAAgB,EAAEC,yBAAyB,EAAEC,SAAS,EAAE,GAAGZ;IAE5E,MAAMa,iBAAiBf,MAAMgB,MAAM,CAAC;IAEpChB,MAAMiB,SAAS,CAAC;QACd,IAAI,CAACF,eAAeG,OAAO,EAAE;YAC3B,oBAAoB;YACpB,IAAIR,SAASA,UAAUE,kBAAkB;gBACvCE,UAAU;oBAAEK,IAAIT;oBAAOU,SAASZ;gBAAO;YACzC,OAAO;gBACL,oEAAoE;gBACpE,MAAMa,eACJ,CAACT,oBAAoBA,qBAAqBX,aACtCU,OAAO,CAAC,EAAE,EAAED,QACZE;gBACNE,UAAU;oBAAEK,IAAIE;oBAAcD,SAASZ;gBAAO;YAChD;YACAO,eAAeG,OAAO,GAAG;QAC3B,OAAO,IAAI,AAAC,CAAA,CAACR,SAASA,UAAUE,gBAAe,KAAMA,qBAAqBX,YAAY;YACpF,oEAAoE;YACpEQ,SAASG;QACX;IACF,GAAG;QAACF;QAAOE;QAAkBE;QAAWL;QAAUE;QAASH;KAAO;IAElER,MAAMiB,SAAS,CAAC;QACd,IAAI,CAACT,QAAQ;YACXK,0BAA0B;QAC5B;QACA,OAAO;YACLA,0BAA0B;QAC5B;IACF,GAAG;QAACL;QAAQK;KAA0B;IAEtC,IAAIP,OAAO;QACT,qBACE,MAACgB;YAAIC,WAAWpB;;8BACd,KAACmB;oBAAIC,WAAW,GAAGpB,UAAU,SAAS,CAAC;8BACrC,cAAA,KAACL;wBAAmB,GAAGO,IAAI;;;8BAE7B,KAACiB;oBAAIC,WAAW,GAAGpB,UAAU,IAAI,CAAC;;;;IAGxC;IAEA,OAAO;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/TenantSelector/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/TenantSelector/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExC,OAAO,cAAc,CAAA;AAGrB,OAAO,KAAK,MAAM,OAAO,CAAA;AAKzB,eAAO,MAAM,cAAc,wBAAyB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,6BAsC1F,CAAA"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import
|
|
3
|
+
import './index.scss';
|
|
4
4
|
import { SelectInput, useTranslation } from '@payloadcms/ui';
|
|
5
5
|
import React from 'react';
|
|
6
|
+
import { SELECT_ALL } from '../../constants.js';
|
|
6
7
|
import { useTenantSelection } from '../../providers/TenantSelectionProvider/index.client.js';
|
|
7
|
-
import './index.scss';
|
|
8
8
|
export const TenantSelector = ({ label, viewType })=>{
|
|
9
9
|
const { options, selectedTenantID, setTenant } = useTenantSelection();
|
|
10
|
-
const {
|
|
10
|
+
const { t } = useTranslation();
|
|
11
11
|
const handleChange = React.useCallback((option)=>{
|
|
12
12
|
if (option && 'value' in option) {
|
|
13
13
|
setTenant({
|
|
@@ -30,12 +30,12 @@ export const TenantSelector = ({ label, viewType })=>{
|
|
|
30
30
|
className: "tenant-selector",
|
|
31
31
|
children: /*#__PURE__*/ _jsx(SelectInput, {
|
|
32
32
|
isClearable: viewType === 'list',
|
|
33
|
-
label:
|
|
33
|
+
label: t(label),
|
|
34
34
|
name: "setTenant",
|
|
35
35
|
onChange: handleChange,
|
|
36
36
|
options: options,
|
|
37
37
|
path: "setTenant",
|
|
38
|
-
value: selectedTenantID
|
|
38
|
+
value: selectedTenantID ? selectedTenantID === SELECT_ALL ? undefined : selectedTenantID : undefined
|
|
39
39
|
})
|
|
40
40
|
});
|
|
41
41
|
};
|
|
@@ -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
|
|
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 './index.scss'\n\nimport { SelectInput, useTranslation } from '@payloadcms/ui'\nimport React from 'react'\n\nimport { SELECT_ALL } from '../../constants.js'\nimport { useTenantSelection } from '../../providers/TenantSelectionProvider/index.client.js'\n\nexport const TenantSelector = ({ label, viewType }: { label: string; viewType?: ViewTypes }) => {\n const { options, selectedTenantID, setTenant } = useTenantSelection()\n const { t } = useTranslation()\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={t(label as any)}\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","useTranslation","React","SELECT_ALL","useTenantSelection","TenantSelector","label","viewType","options","selectedTenantID","setTenant","t","handleChange","useCallback","option","id","value","refresh","undefined","length","div","className","isClearable","name","onChange","path"],"mappings":"AAAA;;AAIA,OAAO,eAAc;AAErB,SAASA,WAAW,EAAEC,cAAc,QAAQ,iBAAgB;AAC5D,OAAOC,WAAW,QAAO;AAEzB,SAASC,UAAU,QAAQ,qBAAoB;AAC/C,SAASC,kBAAkB,QAAQ,0DAAyD;AAE5F,OAAO,MAAMC,iBAAiB,CAAC,EAAEC,KAAK,EAAEC,QAAQ,EAA2C;IACzF,MAAM,EAAEC,OAAO,EAAEC,gBAAgB,EAAEC,SAAS,EAAE,GAAGN;IACjD,MAAM,EAAEO,CAAC,EAAE,GAAGV;IAEd,MAAMW,eAAeV,MAAMW,WAAW,CACpC,CAACC;QACC,IAAIA,UAAU,WAAWA,QAAQ;YAC/BJ,UAAU;gBAAEK,IAAID,OAAOE,KAAK;gBAAYC,SAAS;YAAK;QACxD,OAAO;YACLP,UAAU;gBAAEK,IAAIG;gBAAWD,SAAS;YAAK;QAC3C;IACF,GACA;QAACP;KAAU;IAGb,IAAIF,QAAQW,MAAM,IAAI,GAAG;QACvB,OAAO;IACT;IAEA,qBACE,KAACC;QAAIC,WAAU;kBACb,cAAA,KAACrB;YACCsB,aAAaf,aAAa;YAC1BD,OAAOK,EAAEL;YACTiB,MAAK;YACLC,UAAUZ;YACVJ,SAASA;YACTiB,MAAK;YACLT,OACEP,mBACIA,qBAAqBN,aACnBe,YACCT,mBACHS;;;AAKd,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,UAAU,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts"],"sourcesContent":["// The tenant cookie can be set to _ALL_ to allow users to see all results for tenants they are a member of.\nexport const SELECT_ALL = '_ALL_'\n"],"names":["SELECT_ALL"],"mappings":"AAAA,4GAA4G;AAC5G,OAAO,MAAMA,aAAa,QAAO"}
|
package/dist/defaults.d.ts
CHANGED
package/dist/defaults.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ;;;;;;CAMpB,CAAA"}
|
package/dist/defaults.js
CHANGED
package/dist/defaults.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["export const defaults = {\n
|
|
1
|
+
{"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["export const defaults = {\n tenantCollectionSlug: 'tenants',\n tenantFieldName: 'tenant',\n tenantsArrayFieldName: 'tenants',\n tenantsArrayTenantFieldName: 'tenant',\n tenantSelectorLabel: 'Tenant',\n}\n"],"names":["defaults","tenantCollectionSlug","tenantFieldName","tenantsArrayFieldName","tenantsArrayTenantFieldName","tenantSelectorLabel"],"mappings":"AAAA,OAAO,MAAMA,WAAW;IACtBC,sBAAsB;IACtBC,iBAAiB;IACjBC,uBAAuB;IACvBC,6BAA6B;IAC7BC,qBAAqB;AACvB,EAAC"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAoB,MAAM,EAAE,MAAM,SAAS,CAAA;AAEvD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAazD,eAAO,MAAM,iBAAiB,GAC3B,UAAU,gBAAgB,uBAAuB,CAAC,UAAU,CAAC,sBAC7C,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAoB,MAAM,EAAE,MAAM,SAAS,CAAA;AAEvD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAazD,eAAO,MAAM,iBAAiB,GAC3B,UAAU,gBAAgB,uBAAuB,CAAC,UAAU,CAAC,sBAC7C,MAAM,KAAG,MAoUzB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -19,8 +19,7 @@ export const multiTenantPlugin = (pluginConfig)=>(incomingConfig)=>{
|
|
|
19
19
|
const tenantFieldName = pluginConfig?.tenantField?.name || defaults.tenantFieldName;
|
|
20
20
|
const tenantsArrayFieldName = pluginConfig?.tenantsArrayField?.arrayFieldName || defaults.tenantsArrayFieldName;
|
|
21
21
|
const tenantsArrayTenantFieldName = pluginConfig?.tenantsArrayField?.arrayTenantFieldName || defaults.tenantsArrayTenantFieldName;
|
|
22
|
-
|
|
23
|
-
const basePath = pluginConfig.basePath || defaults.basePath;
|
|
22
|
+
let tenantSelectorLabel = pluginConfig.tenantSelectorLabel || defaults.tenantSelectorLabel;
|
|
24
23
|
/**
|
|
25
24
|
* Add defaults for admin properties
|
|
26
25
|
*/ if (!incomingConfig.admin) {
|
|
@@ -47,11 +46,11 @@ export const multiTenantPlugin = (pluginConfig)=>(incomingConfig)=>{
|
|
|
47
46
|
}
|
|
48
47
|
/**
|
|
49
48
|
* Add tenant selector localized labels
|
|
50
|
-
*/ if (typeof tenantSelectorLabel === 'object') {
|
|
49
|
+
*/ if (pluginConfig.tenantSelectorLabel && typeof pluginConfig.tenantSelectorLabel === 'object') {
|
|
51
50
|
if (!incomingConfig.i18n) {
|
|
52
51
|
incomingConfig.i18n = {};
|
|
53
52
|
}
|
|
54
|
-
Object.entries(tenantSelectorLabel).forEach(([_locale, label])=>{
|
|
53
|
+
Object.entries(pluginConfig.tenantSelectorLabel).forEach(([_locale, label])=>{
|
|
55
54
|
const locale = _locale;
|
|
56
55
|
if (!incomingConfig.i18n) {
|
|
57
56
|
incomingConfig.i18n = {};
|
|
@@ -72,6 +71,7 @@ export const multiTenantPlugin = (pluginConfig)=>(incomingConfig)=>{
|
|
|
72
71
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
73
72
|
// @ts-expect-error
|
|
74
73
|
incomingConfig.i18n.translations[locale].multiTenant.selectorLabel = label;
|
|
74
|
+
tenantSelectorLabel = 'multiTenant:selectorLabel';
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
@@ -255,7 +255,6 @@ export const multiTenantPlugin = (pluginConfig)=>(incomingConfig)=>{
|
|
|
255
255
|
incomingConfig.admin.components.actions.push({
|
|
256
256
|
path: '@payloadcms/plugin-multi-tenant/rsc#GlobalViewRedirect',
|
|
257
257
|
serverProps: {
|
|
258
|
-
basePath,
|
|
259
258
|
globalSlugs: globalCollectionSlugs,
|
|
260
259
|
tenantFieldName,
|
|
261
260
|
tenantsCollectionSlug,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { AcceptedLanguages } from '@payloadcms/translations'\nimport type { CollectionConfig, Config } from 'payload'\n\nimport type { MultiTenantPluginConfig } from './types.js'\n\nimport { defaults } from './defaults.js'\nimport { tenantField } from './fields/tenantField/index.js'\nimport { tenantsArrayField } from './fields/tenantsArrayField/index.js'\nimport { addTenantCleanup } from './hooks/afterTenantDelete.js'\nimport { filterDocumentsBySelectedTenant } from './list-filters/filterDocumentsBySelectedTenant.js'\nimport { filterTenantsBySelectedTenant } from './list-filters/filterTenantsBySelectedTenant.js'\nimport { filterUsersBySelectedTenant } from './list-filters/filterUsersBySelectedTenant.js'\nimport { addCollectionAccess } from './utilities/addCollectionAccess.js'\nimport { addFilterOptionsToFields } from './utilities/addFilterOptionsToFields.js'\nimport { combineListFilters } from './utilities/combineListFilters.js'\n\nexport const multiTenantPlugin =\n <ConfigType>(pluginConfig: MultiTenantPluginConfig<ConfigType>) =>\n (incomingConfig: Config): Config => {\n if (pluginConfig.enabled === false) {\n return incomingConfig\n }\n\n /**\n * Set defaults\n */\n const userHasAccessToAllTenants: Required<\n MultiTenantPluginConfig<ConfigType>\n >['userHasAccessToAllTenants'] =\n typeof pluginConfig.userHasAccessToAllTenants === 'function'\n ? pluginConfig.userHasAccessToAllTenants\n : () => false\n const tenantsCollectionSlug = (pluginConfig.tenantsSlug =\n pluginConfig.tenantsSlug || defaults.tenantCollectionSlug)\n const tenantFieldName = pluginConfig?.tenantField?.name || defaults.tenantFieldName\n const tenantsArrayFieldName =\n pluginConfig?.tenantsArrayField?.arrayFieldName || defaults.tenantsArrayFieldName\n const tenantsArrayTenantFieldName =\n pluginConfig?.tenantsArrayField?.arrayTenantFieldName || defaults.tenantsArrayTenantFieldName\n const tenantSelectorLabel = pluginConfig.tenantSelectorLabel || defaults.tenantSelectorLabel\n const basePath = pluginConfig.basePath || defaults.basePath\n\n /**\n * Add defaults for admin properties\n */\n if (!incomingConfig.admin) {\n incomingConfig.admin = {}\n }\n if (!incomingConfig.admin?.components) {\n incomingConfig.admin.components = {\n actions: [],\n beforeNavLinks: [],\n providers: [],\n }\n }\n if (!incomingConfig.admin.components?.providers) {\n incomingConfig.admin.components.providers = []\n }\n if (!incomingConfig.admin.components?.actions) {\n incomingConfig.admin.components.actions = []\n }\n if (!incomingConfig.admin.components?.beforeNavLinks) {\n incomingConfig.admin.components.beforeNavLinks = []\n }\n if (!incomingConfig.collections) {\n incomingConfig.collections = []\n }\n\n /**\n * Add tenant selector localized labels\n */\n if (typeof tenantSelectorLabel === 'object') {\n if (!incomingConfig.i18n) {\n incomingConfig.i18n = {}\n }\n Object.entries(tenantSelectorLabel).forEach(([_locale, label]) => {\n const locale = _locale as AcceptedLanguages\n if (!incomingConfig.i18n) {\n incomingConfig.i18n = {}\n }\n if (!incomingConfig.i18n.translations) {\n incomingConfig.i18n.translations = {}\n }\n if (!(locale in incomingConfig.i18n.translations)) {\n incomingConfig.i18n.translations[locale] = {}\n }\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n if (!('multiTenant' in incomingConfig.i18n.translations[locale])) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n incomingConfig.i18n.translations[locale].multiTenant = {}\n }\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n incomingConfig.i18n.translations[locale].multiTenant.selectorLabel = label\n })\n }\n\n /**\n * Add tenants array field to users collection\n */\n const adminUsersCollection = incomingConfig.collections.find(({ slug, auth }) => {\n if (incomingConfig.admin?.user) {\n return slug === incomingConfig.admin.user\n } else if (auth) {\n return true\n }\n })\n\n if (!adminUsersCollection) {\n throw Error('An auth enabled collection was not found')\n }\n\n /**\n * Add tenants array field to users collection\n */\n if (pluginConfig?.tenantsArrayField?.includeDefaultField !== false) {\n adminUsersCollection.fields.push(\n tenantsArrayField({\n ...(pluginConfig?.tenantsArrayField || {}),\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n }),\n )\n }\n\n addCollectionAccess({\n adminUsersSlug: adminUsersCollection.slug,\n collection: adminUsersCollection,\n fieldName: `${tenantsArrayFieldName}.${tenantsArrayTenantFieldName}`,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n userHasAccessToAllTenants,\n })\n\n if (pluginConfig.useUsersTenantFilter !== false) {\n if (!adminUsersCollection.admin) {\n adminUsersCollection.admin = {}\n }\n\n adminUsersCollection.admin.baseListFilter = combineListFilters({\n baseListFilter: adminUsersCollection.admin?.baseListFilter,\n customFilter: (args) =>\n filterUsersBySelectedTenant({\n req: args.req,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n }),\n })\n }\n\n let tenantCollection: CollectionConfig | undefined\n\n const [collectionSlugs, globalCollectionSlugs] = Object.keys(pluginConfig.collections).reduce<\n [string[], string[]]\n >(\n (acc, slug) => {\n if (pluginConfig?.collections?.[slug]?.isGlobal) {\n acc[1].push(slug)\n } else {\n acc[0].push(slug)\n }\n\n return acc\n },\n [[], []],\n )\n\n /**\n * Modify collections\n */\n incomingConfig.collections.forEach((collection) => {\n /**\n * Modify tenants collection\n */\n if (collection.slug === tenantsCollectionSlug) {\n tenantCollection = collection\n\n if (pluginConfig.useTenantsCollectionAccess !== false) {\n /**\n * Add access control constraint to tenants collection\n * - constrains access a users assigned tenants\n */\n addCollectionAccess({\n adminUsersSlug: adminUsersCollection.slug,\n collection,\n fieldName: 'id',\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n userHasAccessToAllTenants,\n })\n }\n\n if (pluginConfig.useTenantsListFilter !== false) {\n /**\n * Add list filter to tenants collection\n * - filter by selected tenant\n */\n if (!collection.admin) {\n collection.admin = {}\n }\n\n collection.admin.baseListFilter = combineListFilters({\n baseListFilter: collection.admin?.baseListFilter,\n customFilter: (args) =>\n filterTenantsBySelectedTenant({\n req: args.req,\n tenantsCollectionSlug,\n }),\n })\n }\n\n if (pluginConfig.cleanupAfterTenantDelete !== false) {\n /**\n * Add cleanup logic when tenant is deleted\n * - delete documents related to tenant\n * - remove tenant from users\n */\n addTenantCleanup({\n collection,\n enabledSlugs: [...collectionSlugs, ...globalCollectionSlugs],\n tenantFieldName,\n tenantsCollectionSlug,\n usersSlug: adminUsersCollection.slug,\n usersTenantsArrayFieldName: tenantsArrayFieldName,\n usersTenantsArrayTenantFieldName: tenantsArrayTenantFieldName,\n })\n }\n } else if (pluginConfig.collections?.[collection.slug]) {\n const isGlobal = Boolean(pluginConfig.collections[collection.slug]?.isGlobal)\n\n if (isGlobal) {\n collection.disableDuplicate = true\n }\n\n /**\n * Modify enabled collections\n */\n addFilterOptionsToFields({\n config: incomingConfig,\n fields: collection.fields,\n tenantEnabledCollectionSlugs: collectionSlugs,\n tenantEnabledGlobalSlugs: globalCollectionSlugs,\n tenantFieldName,\n tenantsCollectionSlug,\n })\n\n /**\n * Add tenant field to enabled collections\n */\n collection.fields.splice(\n 0,\n 0,\n tenantField({\n ...(pluginConfig?.tenantField || {}),\n name: tenantFieldName,\n debug: pluginConfig.debug,\n tenantsCollectionSlug,\n unique: isGlobal,\n }),\n )\n\n if (pluginConfig.collections[collection.slug]?.useBaseListFilter !== false) {\n /**\n * Add list filter to enabled collections\n * - filters results by selected tenant\n */\n if (!collection.admin) {\n collection.admin = {}\n }\n\n collection.admin.baseListFilter = combineListFilters({\n baseListFilter: collection.admin?.baseListFilter,\n customFilter: (args) =>\n filterDocumentsBySelectedTenant({\n req: args.req,\n tenantFieldName,\n tenantsCollectionSlug,\n }),\n })\n }\n\n if (pluginConfig.collections[collection.slug]?.useTenantAccess !== false) {\n /**\n * Add access control constraint to tenant enabled collection\n */\n addCollectionAccess({\n adminUsersSlug: adminUsersCollection.slug,\n collection,\n fieldName: tenantFieldName,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n userHasAccessToAllTenants,\n })\n }\n }\n })\n\n if (!tenantCollection) {\n throw new Error(`Tenants collection not found with slug: ${tenantsCollectionSlug}`)\n }\n\n /**\n * Add TenantSelectionProvider to admin providers\n */\n incomingConfig.admin.components.providers.push({\n clientProps: {\n tenantsCollectionSlug: tenantCollection.slug,\n useAsTitle: tenantCollection.admin?.useAsTitle || 'id',\n },\n path: '@payloadcms/plugin-multi-tenant/rsc#TenantSelectionProvider',\n })\n\n /**\n * Add global redirect action\n */\n if (globalCollectionSlugs.length) {\n incomingConfig.admin.components.actions.push({\n path: '@payloadcms/plugin-multi-tenant/rsc#GlobalViewRedirect',\n serverProps: {\n basePath,\n globalSlugs: globalCollectionSlugs,\n tenantFieldName,\n tenantsCollectionSlug,\n useAsTitle: tenantCollection.admin?.useAsTitle || 'id',\n },\n })\n }\n\n /**\n * Add tenant selector to admin UI\n */\n incomingConfig.admin.components.beforeNavLinks.push({\n clientProps: {\n label: tenantSelectorLabel,\n },\n path: '@payloadcms/plugin-multi-tenant/client#TenantSelector',\n })\n\n return incomingConfig\n }\n"],"names":["defaults","tenantField","tenantsArrayField","addTenantCleanup","filterDocumentsBySelectedTenant","filterTenantsBySelectedTenant","filterUsersBySelectedTenant","addCollectionAccess","addFilterOptionsToFields","combineListFilters","multiTenantPlugin","pluginConfig","incomingConfig","enabled","userHasAccessToAllTenants","tenantsCollectionSlug","tenantsSlug","tenantCollectionSlug","tenantFieldName","name","tenantsArrayFieldName","arrayFieldName","tenantsArrayTenantFieldName","arrayTenantFieldName","tenantSelectorLabel","basePath","admin","components","actions","beforeNavLinks","providers","collections","i18n","Object","entries","forEach","_locale","label","locale","translations","multiTenant","selectorLabel","adminUsersCollection","find","slug","auth","user","Error","includeDefaultField","fields","push","adminUsersSlug","collection","fieldName","useUsersTenantFilter","baseListFilter","customFilter","args","req","tenantCollection","collectionSlugs","globalCollectionSlugs","keys","reduce","acc","isGlobal","useTenantsCollectionAccess","useTenantsListFilter","cleanupAfterTenantDelete","enabledSlugs","usersSlug","usersTenantsArrayFieldName","usersTenantsArrayTenantFieldName","Boolean","disableDuplicate","config","tenantEnabledCollectionSlugs","tenantEnabledGlobalSlugs","splice","debug","unique","useBaseListFilter","useTenantAccess","clientProps","useAsTitle","path","length","serverProps","globalSlugs"],"mappings":"AAKA,SAASA,QAAQ,QAAQ,gBAAe;AACxC,SAASC,WAAW,QAAQ,gCAA+B;AAC3D,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,gBAAgB,QAAQ,+BAA8B;AAC/D,SAASC,+BAA+B,QAAQ,oDAAmD;AACnG,SAASC,6BAA6B,QAAQ,kDAAiD;AAC/F,SAASC,2BAA2B,QAAQ,gDAA+C;AAC3F,SAASC,mBAAmB,QAAQ,qCAAoC;AACxE,SAASC,wBAAwB,QAAQ,0CAAyC;AAClF,SAASC,kBAAkB,QAAQ,oCAAmC;AAEtE,OAAO,MAAMC,oBACX,CAAaC,eACb,CAACC;QACC,IAAID,aAAaE,OAAO,KAAK,OAAO;YAClC,OAAOD;QACT;QAEA;;KAEC,GACD,MAAME,4BAGJ,OAAOH,aAAaG,yBAAyB,KAAK,aAC9CH,aAAaG,yBAAyB,GACtC,IAAM;QACZ,MAAMC,wBAAyBJ,aAAaK,WAAW,GACrDL,aAAaK,WAAW,IAAIhB,SAASiB,oBAAoB;QAC3D,MAAMC,kBAAkBP,cAAcV,aAAakB,QAAQnB,SAASkB,eAAe;QACnF,MAAME,wBACJT,cAAcT,mBAAmBmB,kBAAkBrB,SAASoB,qBAAqB;QACnF,MAAME,8BACJX,cAAcT,mBAAmBqB,wBAAwBvB,SAASsB,2BAA2B;QAC/F,MAAME,sBAAsBb,aAAaa,mBAAmB,IAAIxB,SAASwB,mBAAmB;QAC5F,MAAMC,WAAWd,aAAac,QAAQ,IAAIzB,SAASyB,QAAQ;QAE3D;;KAEC,GACD,IAAI,CAACb,eAAec,KAAK,EAAE;YACzBd,eAAec,KAAK,GAAG,CAAC;QAC1B;QACA,IAAI,CAACd,eAAec,KAAK,EAAEC,YAAY;YACrCf,eAAec,KAAK,CAACC,UAAU,GAAG;gBAChCC,SAAS,EAAE;gBACXC,gBAAgB,EAA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B,iBAAiBjC,KAAK,EAAE0D,cAAc;YACpD;YACAC,MAAM;QACR;QAEA;;KAEC,GACD,IAAIxB,sBAAsByB,MAAM,EAAE;YAChC1E,eAAec,KAAK,CAACC,UAAU,CAACC,OAAO,CAACsB,IAAI,CAAC;gBAC3CmC,MAAM;gBACNE,aAAa;oBACX9D;oBACA+D,aAAa3B;oBACb3C;oBACAH;oBACAqE,YAAYzB,iBAAiBjC,KAAK,EAAE0D,cAAc;gBACpD;YACF;QACF;QAEA;;KAEC,GACDxE,eAAec,KAAK,CAACC,UAAU,CAACE,cAAc,CAACqB,IAAI,CAAC;YAClDiC,aAAa;gBACX9C,OAAOb;YACT;YACA6D,MAAM;QACR;QAEA,OAAOzE;IACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { AcceptedLanguages } from '@payloadcms/translations'\nimport type { CollectionConfig, Config } from 'payload'\n\nimport type { MultiTenantPluginConfig } from './types.js'\n\nimport { defaults } from './defaults.js'\nimport { tenantField } from './fields/tenantField/index.js'\nimport { tenantsArrayField } from './fields/tenantsArrayField/index.js'\nimport { addTenantCleanup } from './hooks/afterTenantDelete.js'\nimport { filterDocumentsBySelectedTenant } from './list-filters/filterDocumentsBySelectedTenant.js'\nimport { filterTenantsBySelectedTenant } from './list-filters/filterTenantsBySelectedTenant.js'\nimport { filterUsersBySelectedTenant } from './list-filters/filterUsersBySelectedTenant.js'\nimport { addCollectionAccess } from './utilities/addCollectionAccess.js'\nimport { addFilterOptionsToFields } from './utilities/addFilterOptionsToFields.js'\nimport { combineListFilters } from './utilities/combineListFilters.js'\n\nexport const multiTenantPlugin =\n <ConfigType>(pluginConfig: MultiTenantPluginConfig<ConfigType>) =>\n (incomingConfig: Config): Config => {\n if (pluginConfig.enabled === false) {\n return incomingConfig\n }\n\n /**\n * Set defaults\n */\n const userHasAccessToAllTenants: Required<\n MultiTenantPluginConfig<ConfigType>\n >['userHasAccessToAllTenants'] =\n typeof pluginConfig.userHasAccessToAllTenants === 'function'\n ? pluginConfig.userHasAccessToAllTenants\n : () => false\n const tenantsCollectionSlug = (pluginConfig.tenantsSlug =\n pluginConfig.tenantsSlug || defaults.tenantCollectionSlug)\n const tenantFieldName = pluginConfig?.tenantField?.name || defaults.tenantFieldName\n const tenantsArrayFieldName =\n pluginConfig?.tenantsArrayField?.arrayFieldName || defaults.tenantsArrayFieldName\n const tenantsArrayTenantFieldName =\n pluginConfig?.tenantsArrayField?.arrayTenantFieldName || defaults.tenantsArrayTenantFieldName\n let tenantSelectorLabel = pluginConfig.tenantSelectorLabel || defaults.tenantSelectorLabel\n\n /**\n * Add defaults for admin properties\n */\n if (!incomingConfig.admin) {\n incomingConfig.admin = {}\n }\n if (!incomingConfig.admin?.components) {\n incomingConfig.admin.components = {\n actions: [],\n beforeNavLinks: [],\n providers: [],\n }\n }\n if (!incomingConfig.admin.components?.providers) {\n incomingConfig.admin.components.providers = []\n }\n if (!incomingConfig.admin.components?.actions) {\n incomingConfig.admin.components.actions = []\n }\n if (!incomingConfig.admin.components?.beforeNavLinks) {\n incomingConfig.admin.components.beforeNavLinks = []\n }\n if (!incomingConfig.collections) {\n incomingConfig.collections = []\n }\n\n /**\n * Add tenant selector localized labels\n */\n if (pluginConfig.tenantSelectorLabel && typeof pluginConfig.tenantSelectorLabel === 'object') {\n if (!incomingConfig.i18n) {\n incomingConfig.i18n = {}\n }\n Object.entries(pluginConfig.tenantSelectorLabel).forEach(([_locale, label]) => {\n const locale = _locale as AcceptedLanguages\n if (!incomingConfig.i18n) {\n incomingConfig.i18n = {}\n }\n if (!incomingConfig.i18n.translations) {\n incomingConfig.i18n.translations = {}\n }\n if (!(locale in incomingConfig.i18n.translations)) {\n incomingConfig.i18n.translations[locale] = {}\n }\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n if (!('multiTenant' in incomingConfig.i18n.translations[locale])) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n incomingConfig.i18n.translations[locale].multiTenant = {}\n }\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n incomingConfig.i18n.translations[locale].multiTenant.selectorLabel = label\n tenantSelectorLabel = 'multiTenant:selectorLabel'\n })\n }\n\n /**\n * Add tenants array field to users collection\n */\n const adminUsersCollection = incomingConfig.collections.find(({ slug, auth }) => {\n if (incomingConfig.admin?.user) {\n return slug === incomingConfig.admin.user\n } else if (auth) {\n return true\n }\n })\n\n if (!adminUsersCollection) {\n throw Error('An auth enabled collection was not found')\n }\n\n /**\n * Add tenants array field to users collection\n */\n if (pluginConfig?.tenantsArrayField?.includeDefaultField !== false) {\n adminUsersCollection.fields.push(\n tenantsArrayField({\n ...(pluginConfig?.tenantsArrayField || {}),\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n }),\n )\n }\n\n addCollectionAccess({\n adminUsersSlug: adminUsersCollection.slug,\n collection: adminUsersCollection,\n fieldName: `${tenantsArrayFieldName}.${tenantsArrayTenantFieldName}`,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n userHasAccessToAllTenants,\n })\n\n if (pluginConfig.useUsersTenantFilter !== false) {\n if (!adminUsersCollection.admin) {\n adminUsersCollection.admin = {}\n }\n\n adminUsersCollection.admin.baseListFilter = combineListFilters({\n baseListFilter: adminUsersCollection.admin?.baseListFilter,\n customFilter: (args) =>\n filterUsersBySelectedTenant({\n req: args.req,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n }),\n })\n }\n\n let tenantCollection: CollectionConfig | undefined\n\n const [collectionSlugs, globalCollectionSlugs] = Object.keys(pluginConfig.collections).reduce<\n [string[], string[]]\n >(\n (acc, slug) => {\n if (pluginConfig?.collections?.[slug]?.isGlobal) {\n acc[1].push(slug)\n } else {\n acc[0].push(slug)\n }\n\n return acc\n },\n [[], []],\n )\n\n /**\n * Modify collections\n */\n incomingConfig.collections.forEach((collection) => {\n /**\n * Modify tenants collection\n */\n if (collection.slug === tenantsCollectionSlug) {\n tenantCollection = collection\n\n if (pluginConfig.useTenantsCollectionAccess !== false) {\n /**\n * Add access control constraint to tenants collection\n * - constrains access a users assigned tenants\n */\n addCollectionAccess({\n adminUsersSlug: adminUsersCollection.slug,\n collection,\n fieldName: 'id',\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n userHasAccessToAllTenants,\n })\n }\n\n if (pluginConfig.useTenantsListFilter !== false) {\n /**\n * Add list filter to tenants collection\n * - filter by selected tenant\n */\n if (!collection.admin) {\n collection.admin = {}\n }\n\n collection.admin.baseListFilter = combineListFilters({\n baseListFilter: collection.admin?.baseListFilter,\n customFilter: (args) =>\n filterTenantsBySelectedTenant({\n req: args.req,\n tenantsCollectionSlug,\n }),\n })\n }\n\n if (pluginConfig.cleanupAfterTenantDelete !== false) {\n /**\n * Add cleanup logic when tenant is deleted\n * - delete documents related to tenant\n * - remove tenant from users\n */\n addTenantCleanup({\n collection,\n enabledSlugs: [...collectionSlugs, ...globalCollectionSlugs],\n tenantFieldName,\n tenantsCollectionSlug,\n usersSlug: adminUsersCollection.slug,\n usersTenantsArrayFieldName: tenantsArrayFieldName,\n usersTenantsArrayTenantFieldName: tenantsArrayTenantFieldName,\n })\n }\n } else if (pluginConfig.collections?.[collection.slug]) {\n const isGlobal = Boolean(pluginConfig.collections[collection.slug]?.isGlobal)\n\n if (isGlobal) {\n collection.disableDuplicate = true\n }\n\n /**\n * Modify enabled collections\n */\n addFilterOptionsToFields({\n config: incomingConfig,\n fields: collection.fields,\n tenantEnabledCollectionSlugs: collectionSlugs,\n tenantEnabledGlobalSlugs: globalCollectionSlugs,\n tenantFieldName,\n tenantsCollectionSlug,\n })\n\n /**\n * Add tenant field to enabled collections\n */\n collection.fields.splice(\n 0,\n 0,\n tenantField({\n ...(pluginConfig?.tenantField || {}),\n name: tenantFieldName,\n debug: pluginConfig.debug,\n tenantsCollectionSlug,\n unique: isGlobal,\n }),\n )\n\n if (pluginConfig.collections[collection.slug]?.useBaseListFilter !== false) {\n /**\n * Add list filter to enabled collections\n * - filters results by selected tenant\n */\n if (!collection.admin) {\n collection.admin = {}\n }\n\n collection.admin.baseListFilter = combineListFilters({\n baseListFilter: collection.admin?.baseListFilter,\n customFilter: (args) =>\n filterDocumentsBySelectedTenant({\n req: args.req,\n tenantFieldName,\n tenantsCollectionSlug,\n }),\n })\n }\n\n if (pluginConfig.collections[collection.slug]?.useTenantAccess !== false) {\n /**\n * Add access control constraint to tenant enabled collection\n */\n addCollectionAccess({\n adminUsersSlug: adminUsersCollection.slug,\n collection,\n fieldName: tenantFieldName,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n userHasAccessToAllTenants,\n })\n }\n }\n })\n\n if (!tenantCollection) {\n throw new Error(`Tenants collection not found with slug: ${tenantsCollectionSlug}`)\n }\n\n /**\n * Add TenantSelectionProvider to admin providers\n */\n incomingConfig.admin.components.providers.push({\n clientProps: {\n tenantsCollectionSlug: tenantCollection.slug,\n useAsTitle: tenantCollection.admin?.useAsTitle || 'id',\n },\n path: '@payloadcms/plugin-multi-tenant/rsc#TenantSelectionProvider',\n })\n\n /**\n * Add global redirect action\n */\n if (globalCollectionSlugs.length) {\n incomingConfig.admin.components.actions.push({\n path: '@payloadcms/plugin-multi-tenant/rsc#GlobalViewRedirect',\n serverProps: {\n globalSlugs: globalCollectionSlugs,\n tenantFieldName,\n tenantsCollectionSlug,\n useAsTitle: tenantCollection.admin?.useAsTitle || 'id',\n },\n })\n }\n\n /**\n * Add tenant selector to admin UI\n */\n incomingConfig.admin.components.beforeNavLinks.push({\n clientProps: {\n label: tenantSelectorLabel,\n },\n path: '@payloadcms/plugin-multi-tenant/client#TenantSelector',\n })\n\n return incomingConfig\n }\n"],"names":["defaults","tenantField","tenantsArrayField","addTenantCleanup","filterDocumentsBySelectedTenant","filterTenantsBySelectedTenant","filterUsersBySelectedTenant","addCollectionAccess","addFilterOptionsToFields","combineListFilters","multiTenantPlugin","pluginConfig","incomingConfig","enabled","userHasAccessToAllTenants","tenantsCollectionSlug","tenantsSlug","tenantCollectionSlug","tenantFieldName","name","tenantsArrayFieldName","arrayFieldName","tenantsArrayTenantFieldName","arrayTenantFieldName","tenantSelectorLabel","admin","components","actions","beforeNavLinks","providers","collections","i18n","Object","entries","forEach","_locale","label","locale","translations","multiTenant","selectorLabel","adminUsersCollection","find","slug","auth","user","Error","includeDefaultField","fields","push","adminUsersSlug","collection","fieldName","useUsersTenantFilter","baseListFilter","customFilter","args","req","tenantCollection","collectionSlugs","globalCollectionSlugs","keys","reduce","acc","isGlobal","useTenantsCollectionAccess","useTenantsListFilter","cleanupAfterTenantDelete","enabledSlugs","usersSlug","usersTenantsArrayFieldName","usersTenantsArrayTenantFieldName","Boolean","disableDuplicate","config","tenantEnabledCollectionSlugs","tenantEnabledGlobalSlugs","splice","debug","unique","useBaseListFilter","useTenantAccess","clientProps","useAsTitle","path","length","serverProps","globalSlugs"],"mappings":"AAKA,SAASA,QAAQ,QAAQ,gBAAe;AACxC,SAASC,WAAW,QAAQ,gCAA+B;AAC3D,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,gBAAgB,QAAQ,+BAA8B;AAC/D,SAASC,+BAA+B,QAAQ,oDAAmD;AACnG,SAASC,6BAA6B,QAAQ,kDAAiD;AAC/F,SAASC,2BAA2B,QAAQ,gDAA+C;AAC3F,SAASC,mBAAmB,QAAQ,qCAAoC;AACxE,SAASC,wBAAwB,QAAQ,0CAAyC;AAClF,SAASC,kBAAkB,QAAQ,oCAAmC;AAEtE,OAAO,MAAMC,oBACX,CAAaC,eACb,CAACC;QACC,IAAID,aAAaE,OAAO,KAAK,OAAO;YAClC,OAAOD;QACT;QAEA;;KAEC,GACD,MAAME,4BAGJ,OAAOH,aAAaG,yBAAyB,KAAK,aAC9CH,aAAaG,yBAAyB,GACtC,IAAM;QACZ,MAAMC,wBAAyBJ,aAAaK,WAAW,GACrDL,aAAaK,WAAW,IAAIhB,SAASiB,oBAAoB;QA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qD,KAAKD,KAAKC,GAAG;gCACbvC;gCACAH;4BACF;oBACJ;gBACF;gBAEA,IAAIJ,aAAamB,WAAW,CAACqB,WAAWR,IAAI,CAAC,EAAEsC,oBAAoB,OAAO;oBACxE;;WAEC,GACD1E,oBAAoB;wBAClB2C,gBAAgBT,qBAAqBE,IAAI;wBACzCQ;wBACAC,WAAWlC;wBACXE;wBACAE;wBACAR;oBACF;gBACF;YACF;QACF;QAEA,IAAI,CAAC4C,kBAAkB;YACrB,MAAM,IAAIZ,MAAM,CAAC,wCAAwC,EAAE/B,uBAAuB;QACpF;QAEA;;KAEC,GACDH,eAAea,KAAK,CAACC,UAAU,CAACG,SAAS,CAACoB,IAAI,CAAC;YAC7CiC,aAAa;gBACXnE,uBAAuB2C,iBAAiBf,IAAI;gBAC5CwC,YAAYzB,iBAAiBjC,KAAK,EAAE0D,cAAc;YACpD;YACAC,MAAM;QACR;QAEA;;KAEC,GACD,IAAIxB,sBAAsByB,MAAM,EAAE;YAChCzE,eAAea,KAAK,CAACC,UAAU,CAACC,OAAO,CAACsB,IAAI,CAAC;gBAC3CmC,MAAM;gBACNE,aAAa;oBACXC,aAAa3B;oBACb1C;oBACAH;oBACAoE,YAAYzB,iBAAiBjC,KAAK,EAAE0D,cAAc;gBACpD;YACF;QACF;QAEA;;KAEC,GACDvE,eAAea,KAAK,CAACC,UAAU,CAACE,cAAc,CAACqB,IAAI,CAAC;YAClDiC,aAAa;gBACX9C,OAAOZ;YACT;YACA4D,MAAM;QACR;QAEA,OAAOxE;IACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filterDocumentsBySelectedTenant.d.ts","sourceRoot":"","sources":["../../src/list-filters/filterDocumentsBySelectedTenant.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"filterDocumentsBySelectedTenant.d.ts","sourceRoot":"","sources":["../../src/list-filters/filterDocumentsBySelectedTenant.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAMpD,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,cAAc,CAAA;IACnB,eAAe,EAAE,MAAM,CAAA;IACvB,qBAAqB,EAAE,MAAM,CAAA;CAC9B,CAAA;AACD,eAAO,MAAM,+BAA+B,qDAIzC,IAAI,KAAG,IAAI,GAAG,KAgBhB,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SELECT_ALL } from '../constants.js';
|
|
1
2
|
import { getCollectionIDType } from '../utilities/getCollectionIDType.js';
|
|
2
3
|
import { getTenantFromCookie } from '../utilities/getTenantFromCookie.js';
|
|
3
4
|
export const filterDocumentsBySelectedTenant = ({ req, tenantFieldName, tenantsCollectionSlug })=>{
|
|
@@ -6,14 +7,14 @@ export const filterDocumentsBySelectedTenant = ({ req, tenantFieldName, tenantsC
|
|
|
6
7
|
payload: req.payload
|
|
7
8
|
});
|
|
8
9
|
const selectedTenant = getTenantFromCookie(req.headers, idType);
|
|
9
|
-
if (selectedTenant) {
|
|
10
|
-
return {
|
|
11
|
-
[tenantFieldName]: {
|
|
12
|
-
equals: selectedTenant
|
|
13
|
-
}
|
|
14
|
-
};
|
|
10
|
+
if (selectedTenant === SELECT_ALL) {
|
|
11
|
+
return {};
|
|
15
12
|
}
|
|
16
|
-
return {
|
|
13
|
+
return {
|
|
14
|
+
[tenantFieldName]: {
|
|
15
|
+
equals: selectedTenant
|
|
16
|
+
}
|
|
17
|
+
};
|
|
17
18
|
};
|
|
18
19
|
|
|
19
20
|
//# sourceMappingURL=filterDocumentsBySelectedTenant.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/list-filters/filterDocumentsBySelectedTenant.ts"],"sourcesContent":["import type { PayloadRequest, Where } from 'payload'\n\nimport { getCollectionIDType } from '../utilities/getCollectionIDType.js'\nimport { getTenantFromCookie } from '../utilities/getTenantFromCookie.js'\n\ntype Args = {\n req: PayloadRequest\n tenantFieldName: string\n tenantsCollectionSlug: string\n}\nexport const filterDocumentsBySelectedTenant = ({\n req,\n tenantFieldName,\n tenantsCollectionSlug,\n}: Args): null | Where => {\n const idType = getCollectionIDType({\n collectionSlug: tenantsCollectionSlug,\n payload: req.payload,\n })\n const selectedTenant = getTenantFromCookie(req.headers, idType)\n\n if (selectedTenant) {\n return {\n
|
|
1
|
+
{"version":3,"sources":["../../src/list-filters/filterDocumentsBySelectedTenant.ts"],"sourcesContent":["import type { PayloadRequest, Where } from 'payload'\n\nimport { SELECT_ALL } from '../constants.js'\nimport { getCollectionIDType } from '../utilities/getCollectionIDType.js'\nimport { getTenantFromCookie } from '../utilities/getTenantFromCookie.js'\n\ntype Args = {\n req: PayloadRequest\n tenantFieldName: string\n tenantsCollectionSlug: string\n}\nexport const filterDocumentsBySelectedTenant = ({\n req,\n tenantFieldName,\n tenantsCollectionSlug,\n}: Args): null | Where => {\n const idType = getCollectionIDType({\n collectionSlug: tenantsCollectionSlug,\n payload: req.payload,\n })\n const selectedTenant = getTenantFromCookie(req.headers, idType)\n\n if (selectedTenant === SELECT_ALL) {\n return {}\n }\n\n return {\n [tenantFieldName]: {\n equals: selectedTenant,\n },\n }\n}\n"],"names":["SELECT_ALL","getCollectionIDType","getTenantFromCookie","filterDocumentsBySelectedTenant","req","tenantFieldName","tenantsCollectionSlug","idType","collectionSlug","payload","selectedTenant","headers","equals"],"mappings":"AAEA,SAASA,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,mBAAmB,QAAQ,sCAAqC;AAOzE,OAAO,MAAMC,kCAAkC,CAAC,EAC9CC,GAAG,EACHC,eAAe,EACfC,qBAAqB,EAChB;IACL,MAAMC,SAASN,oBAAoB;QACjCO,gBAAgBF;QAChBG,SAASL,IAAIK,OAAO;IACtB;IACA,MAAMC,iBAAiBR,oBAAoBE,IAAIO,OAAO,EAAEJ;IAExD,IAAIG,mBAAmBV,YAAY;QACjC,OAAO,CAAC;IACV;IAEA,OAAO;QACL,CAACK,gBAAgB,EAAE;YACjBO,QAAQF;QACV;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filterTenantsBySelectedTenant.d.ts","sourceRoot":"","sources":["../../src/list-filters/filterTenantsBySelectedTenant.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"filterTenantsBySelectedTenant.d.ts","sourceRoot":"","sources":["../../src/list-filters/filterTenantsBySelectedTenant.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAMpD,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,cAAc,CAAA;IACnB,qBAAqB,EAAE,MAAM,CAAA;CAC9B,CAAA;AACD,eAAO,MAAM,6BAA6B,oCAGvC,IAAI,KAAG,IAAI,GAAG,KAgBhB,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SELECT_ALL } from '../constants.js';
|
|
1
2
|
import { getCollectionIDType } from '../utilities/getCollectionIDType.js';
|
|
2
3
|
import { getTenantFromCookie } from '../utilities/getTenantFromCookie.js';
|
|
3
4
|
export const filterTenantsBySelectedTenant = ({ req, tenantsCollectionSlug })=>{
|
|
@@ -6,14 +7,14 @@ export const filterTenantsBySelectedTenant = ({ req, tenantsCollectionSlug })=>{
|
|
|
6
7
|
payload: req.payload
|
|
7
8
|
});
|
|
8
9
|
const selectedTenant = getTenantFromCookie(req.headers, idType);
|
|
9
|
-
if (selectedTenant) {
|
|
10
|
-
return {
|
|
11
|
-
id: {
|
|
12
|
-
equals: selectedTenant
|
|
13
|
-
}
|
|
14
|
-
};
|
|
10
|
+
if (selectedTenant === SELECT_ALL) {
|
|
11
|
+
return {};
|
|
15
12
|
}
|
|
16
|
-
return {
|
|
13
|
+
return {
|
|
14
|
+
id: {
|
|
15
|
+
equals: selectedTenant
|
|
16
|
+
}
|
|
17
|
+
};
|
|
17
18
|
};
|
|
18
19
|
|
|
19
20
|
//# sourceMappingURL=filterTenantsBySelectedTenant.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/list-filters/filterTenantsBySelectedTenant.ts"],"sourcesContent":["import type { PayloadRequest, Where } from 'payload'\n\nimport { getCollectionIDType } from '../utilities/getCollectionIDType.js'\nimport { getTenantFromCookie } from '../utilities/getTenantFromCookie.js'\n\ntype Args = {\n req: PayloadRequest\n tenantsCollectionSlug: string\n}\nexport const filterTenantsBySelectedTenant = ({\n req,\n tenantsCollectionSlug,\n}: Args): null | Where => {\n const idType = getCollectionIDType({\n collectionSlug: tenantsCollectionSlug,\n payload: req.payload,\n })\n const selectedTenant = getTenantFromCookie(req.headers, idType)\n\n if (selectedTenant) {\n return {\n
|
|
1
|
+
{"version":3,"sources":["../../src/list-filters/filterTenantsBySelectedTenant.ts"],"sourcesContent":["import type { PayloadRequest, Where } from 'payload'\n\nimport { SELECT_ALL } from '../constants.js'\nimport { getCollectionIDType } from '../utilities/getCollectionIDType.js'\nimport { getTenantFromCookie } from '../utilities/getTenantFromCookie.js'\n\ntype Args = {\n req: PayloadRequest\n tenantsCollectionSlug: string\n}\nexport const filterTenantsBySelectedTenant = ({\n req,\n tenantsCollectionSlug,\n}: Args): null | Where => {\n const idType = getCollectionIDType({\n collectionSlug: tenantsCollectionSlug,\n payload: req.payload,\n })\n const selectedTenant = getTenantFromCookie(req.headers, idType)\n\n if (selectedTenant === SELECT_ALL) {\n return {}\n }\n\n return {\n id: {\n equals: selectedTenant,\n },\n }\n}\n"],"names":["SELECT_ALL","getCollectionIDType","getTenantFromCookie","filterTenantsBySelectedTenant","req","tenantsCollectionSlug","idType","collectionSlug","payload","selectedTenant","headers","id","equals"],"mappings":"AAEA,SAASA,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,mBAAmB,QAAQ,sCAAqC;AAMzE,OAAO,MAAMC,gCAAgC,CAAC,EAC5CC,GAAG,EACHC,qBAAqB,EAChB;IACL,MAAMC,SAASL,oBAAoB;QACjCM,gBAAgBF;QAChBG,SAASJ,IAAII,OAAO;IACtB;IACA,MAAMC,iBAAiBP,oBAAoBE,IAAIM,OAAO,EAAEJ;IAExD,IAAIG,mBAAmBT,YAAY;QACjC,OAAO,CAAC;IACV;IAEA,OAAO;QACLW,IAAI;YACFC,QAAQH;QACV;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filterUsersBySelectedTenant.d.ts","sourceRoot":"","sources":["../../src/list-filters/filterUsersBySelectedTenant.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"filterUsersBySelectedTenant.d.ts","sourceRoot":"","sources":["../../src/list-filters/filterUsersBySelectedTenant.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAMpD,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,cAAc,CAAA;IACnB,qBAAqB,EAAE,MAAM,CAAA;IAC7B,2BAA2B,EAAE,MAAM,CAAA;IACnC,qBAAqB,EAAE,MAAM,CAAA;CAC9B,CAAA;AACD;;GAEG;AACH,eAAO,MAAM,2BAA2B,wFAKrC,IAAI,KAAG,IAAI,GAAG,KAgBhB,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SELECT_ALL } from '../constants.js';
|
|
1
2
|
import { getCollectionIDType } from '../utilities/getCollectionIDType.js';
|
|
2
3
|
import { getTenantFromCookie } from '../utilities/getTenantFromCookie.js';
|
|
3
4
|
/**
|
|
@@ -8,16 +9,16 @@ import { getTenantFromCookie } from '../utilities/getTenantFromCookie.js';
|
|
|
8
9
|
payload: req.payload
|
|
9
10
|
});
|
|
10
11
|
const selectedTenant = getTenantFromCookie(req.headers, idType);
|
|
11
|
-
if (selectedTenant) {
|
|
12
|
-
return {
|
|
13
|
-
[`${tenantsArrayFieldName}.${tenantsArrayTenantFieldName}`]: {
|
|
14
|
-
in: [
|
|
15
|
-
selectedTenant
|
|
16
|
-
]
|
|
17
|
-
}
|
|
18
|
-
};
|
|
12
|
+
if (selectedTenant === SELECT_ALL) {
|
|
13
|
+
return {};
|
|
19
14
|
}
|
|
20
|
-
return {
|
|
15
|
+
return {
|
|
16
|
+
[`${tenantsArrayFieldName}.${tenantsArrayTenantFieldName}`]: {
|
|
17
|
+
in: [
|
|
18
|
+
selectedTenant
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
};
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
//# sourceMappingURL=filterUsersBySelectedTenant.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/list-filters/filterUsersBySelectedTenant.ts"],"sourcesContent":["import type { PayloadRequest, Where } from 'payload'\n\nimport { getCollectionIDType } from '../utilities/getCollectionIDType.js'\nimport { getTenantFromCookie } from '../utilities/getTenantFromCookie.js'\n\ntype Args = {\n req: PayloadRequest\n tenantsArrayFieldName: string\n tenantsArrayTenantFieldName: string\n tenantsCollectionSlug: string\n}\n/**\n * Filter the list of users by the selected tenant\n */\nexport const filterUsersBySelectedTenant = ({\n req,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n}: Args): null | Where => {\n const idType = getCollectionIDType({\n collectionSlug: tenantsCollectionSlug,\n payload: req.payload,\n })\n const selectedTenant = getTenantFromCookie(req.headers, idType)\n\n if (selectedTenant) {\n return {\n
|
|
1
|
+
{"version":3,"sources":["../../src/list-filters/filterUsersBySelectedTenant.ts"],"sourcesContent":["import type { PayloadRequest, Where } from 'payload'\n\nimport { SELECT_ALL } from '../constants.js'\nimport { getCollectionIDType } from '../utilities/getCollectionIDType.js'\nimport { getTenantFromCookie } from '../utilities/getTenantFromCookie.js'\n\ntype Args = {\n req: PayloadRequest\n tenantsArrayFieldName: string\n tenantsArrayTenantFieldName: string\n tenantsCollectionSlug: string\n}\n/**\n * Filter the list of users by the selected tenant\n */\nexport const filterUsersBySelectedTenant = ({\n req,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n}: Args): null | Where => {\n const idType = getCollectionIDType({\n collectionSlug: tenantsCollectionSlug,\n payload: req.payload,\n })\n const selectedTenant = getTenantFromCookie(req.headers, idType)\n\n if (selectedTenant === SELECT_ALL) {\n return {}\n }\n\n return {\n [`${tenantsArrayFieldName}.${tenantsArrayTenantFieldName}`]: {\n in: [selectedTenant],\n },\n }\n}\n"],"names":["SELECT_ALL","getCollectionIDType","getTenantFromCookie","filterUsersBySelectedTenant","req","tenantsArrayFieldName","tenantsArrayTenantFieldName","tenantsCollectionSlug","idType","collectionSlug","payload","selectedTenant","headers","in"],"mappings":"AAEA,SAASA,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,mBAAmB,QAAQ,sCAAqC;AAQzE;;CAEC,GACD,OAAO,MAAMC,8BAA8B,CAAC,EAC1CC,GAAG,EACHC,qBAAqB,EACrBC,2BAA2B,EAC3BC,qBAAqB,EAChB;IACL,MAAMC,SAASP,oBAAoB;QACjCQ,gBAAgBF;QAChBG,SAASN,IAAIM,OAAO;IACtB;IACA,MAAMC,iBAAiBT,oBAAoBE,IAAIQ,OAAO,EAAEJ;IAExD,IAAIG,mBAAmBX,YAAY;QACjC,OAAO,CAAC;IACV;IAEA,OAAO;QACL,CAAC,GAAGK,sBAAsB,CAAC,EAAEC,6BAA6B,CAAC,EAAE;YAC3DO,IAAI;gBAACF;aAAe;QACtB;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;AAI3C,OAAO,KAAwB,MAAM,OAAO,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;;OAEG;IACH,OAAO,EAAE,YAAY,EAAE,CAAA;IACvB;;OAEG;IACH,gBAAgB,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAC7C;;;;OAIG;IACH,yBAAyB,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAA;IACxE;;;;;OAKG;IACH,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,6DAKvC;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,YAAY,EAAE,CAAA;CAC9B,sBA8FA,CAAA;AAED,eAAO,MAAM,kBAAkB,mBAAkC,CAAA"}
|
|
@@ -3,6 +3,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import { useAuth } from '@payloadcms/ui';
|
|
4
4
|
import { useRouter } from 'next/navigation.js';
|
|
5
5
|
import React, { createContext } from 'react';
|
|
6
|
+
import { SELECT_ALL } from '../../constants.js';
|
|
6
7
|
const Context = /*#__PURE__*/ createContext({
|
|
7
8
|
options: [],
|
|
8
9
|
selectedTenantID: undefined,
|
|
@@ -31,8 +32,8 @@ export const TenantSelectionProviderClient = ({ children, initialValue, tenantCo
|
|
|
31
32
|
const setTenant = React.useCallback(({ id, refresh })=>{
|
|
32
33
|
if (id === undefined) {
|
|
33
34
|
if (tenantOptions.length > 1) {
|
|
34
|
-
setSelectedTenantID(
|
|
35
|
-
|
|
35
|
+
setSelectedTenantID(SELECT_ALL);
|
|
36
|
+
setCookie(SELECT_ALL);
|
|
36
37
|
} else {
|
|
37
38
|
setSelectedTenantID(tenantOptions[0]?.value);
|
|
38
39
|
setCookie(String(tenantOptions[0]?.value));
|
|
@@ -45,15 +46,14 @@ export const TenantSelectionProviderClient = ({ children, initialValue, tenantCo
|
|
|
45
46
|
router.refresh();
|
|
46
47
|
}
|
|
47
48
|
}, [
|
|
48
|
-
deleteCookie,
|
|
49
|
-
preventRefreshOnChange,
|
|
50
|
-
router,
|
|
51
|
-
setCookie,
|
|
52
49
|
setSelectedTenantID,
|
|
50
|
+
setCookie,
|
|
51
|
+
router,
|
|
52
|
+
preventRefreshOnChange,
|
|
53
53
|
tenantOptions
|
|
54
54
|
]);
|
|
55
55
|
React.useEffect(()=>{
|
|
56
|
-
if (selectedTenantID && !tenantOptions.find((option)=>option.value === selectedTenantID)) {
|
|
56
|
+
if (selectedTenantID && selectedTenantID !== SELECT_ALL && !tenantOptions.find((option)=>option.value === selectedTenantID)) {
|
|
57
57
|
if (tenantOptions?.[0]?.value) {
|
|
58
58
|
setTenant({
|
|
59
59
|
id: tenantOptions[0].value,
|
|
@@ -78,18 +78,13 @@ export const TenantSelectionProviderClient = ({ children, initialValue, tenantCo
|
|
|
78
78
|
if (userID && !tenantCookie) {
|
|
79
79
|
// User is logged in, but does not have a tenant cookie, set it
|
|
80
80
|
setSelectedTenantID(initialValue);
|
|
81
|
-
|
|
82
|
-
setCookie(String(initialValue));
|
|
83
|
-
} else {
|
|
84
|
-
deleteCookie();
|
|
85
|
-
}
|
|
81
|
+
setCookie(String(initialValue));
|
|
86
82
|
}
|
|
87
83
|
}, [
|
|
88
84
|
userID,
|
|
89
85
|
tenantCookie,
|
|
90
86
|
initialValue,
|
|
91
87
|
setCookie,
|
|
92
|
-
deleteCookie,
|
|
93
88
|
router
|
|
94
89
|
]);
|
|
95
90
|
React.useEffect(()=>{
|
|
@@ -110,7 +105,7 @@ export const TenantSelectionProviderClient = ({ children, initialValue, tenantCo
|
|
|
110
105
|
return /*#__PURE__*/ _jsx("span", {
|
|
111
106
|
"data-selected-tenant-id": selectedTenantID,
|
|
112
107
|
"data-selected-tenant-title": selectedTenantLabel,
|
|
113
|
-
children: /*#__PURE__*/ _jsx(Context, {
|
|
108
|
+
children: /*#__PURE__*/ _jsx(Context.Provider, {
|
|
114
109
|
value: {
|
|
115
110
|
options: tenantOptions,
|
|
116
111
|
selectedTenantID,
|
|
@@ -121,6 +116,6 @@ export const TenantSelectionProviderClient = ({ children, initialValue, tenantCo
|
|
|
121
116
|
})
|
|
122
117
|
});
|
|
123
118
|
};
|
|
124
|
-
export const useTenantSelection = ()=>React.
|
|
119
|
+
export const useTenantSelection = ()=>React.useContext(Context);
|
|
125
120
|
|
|
126
121
|
//# sourceMappingURL=index.client.js.map
|
|
@@ -1 +1 @@
|
|
|
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\ntype ContextType = {\n /**\n * Array of options to select from\n */\n options: OptionObject[]\n /**\n * The currently selected tenant ID\n */\n selectedTenantID: number | string | undefined\n /**\n * Prevents a refresh when the tenant is changed\n *\n * If not switching tenants while viewing a \"global\", set to true\n */\n setPreventRefreshOnChange: React.Dispatch<React.SetStateAction<boolean>>\n /**\n * Sets the selected tenant ID\n *\n * @param args.id - The ID of the tenant to select\n * @param args.refresh - Whether to refresh the page after changing the tenant\n */\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 tenantCookie,\n tenantOptions,\n}: {\n children: React.ReactNode\n initialValue?: number | string\n tenantCookie?: string\n tenantOptions: OptionObject[]\n}) => {\n const [selectedTenantID, setSelectedTenantID] = React.useState<number | string | undefined>(\n initialValue,\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 deleteCookie = React.useCallback(() => {\n document.cookie = 'payload-tenant=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'\n }, [])\n\n const setTenant = React.useCallback<ContextType['setTenant']>(\n ({ id, refresh }) => {\n if (id === undefined) {\n if (tenantOptions.length > 1) {\n setSelectedTenantID(
|
|
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 /**\n * Array of options to select from\n */\n options: OptionObject[]\n /**\n * The currently selected tenant ID\n */\n selectedTenantID: number | string | undefined\n /**\n * Prevents a refresh when the tenant is changed\n *\n * If not switching tenants while viewing a \"global\", set to true\n */\n setPreventRefreshOnChange: React.Dispatch<React.SetStateAction<boolean>>\n /**\n * Sets the selected tenant ID\n *\n * @param args.id - The ID of the tenant to select\n * @param args.refresh - Whether to refresh the page after changing the tenant\n */\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 tenantCookie,\n tenantOptions,\n}: {\n children: React.ReactNode\n initialValue?: number | string\n tenantCookie?: string\n tenantOptions: OptionObject[]\n}) => {\n const [selectedTenantID, setSelectedTenantID] = React.useState<number | string | undefined>(\n initialValue,\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 deleteCookie = React.useCallback(() => {\n document.cookie = 'payload-tenant=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'\n }, [])\n\n const setTenant = React.useCallback<ContextType['setTenant']>(\n ({ id, refresh }) => {\n if (id === undefined) {\n if (tenantOptions.length > 1) {\n setSelectedTenantID(SELECT_ALL)\n setCookie(SELECT_ALL)\n } else {\n setSelectedTenantID(tenantOptions[0]?.value)\n setCookie(String(tenantOptions[0]?.value))\n }\n } else {\n setSelectedTenantID(id)\n setCookie(String(id))\n }\n if (!preventRefreshOnChange && refresh) {\n router.refresh()\n }\n },\n [setSelectedTenantID, setCookie, router, preventRefreshOnChange, tenantOptions],\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 }, [tenantCookie, setTenant, selectedTenantID, tenantOptions, initialValue, setCookie])\n\n React.useEffect(() => {\n if (userID && !tenantCookie) {\n // User is logged in, but does not have a tenant cookie, set it\n setSelectedTenantID(initialValue)\n setCookie(String(initialValue))\n }\n }, [userID, tenantCookie, initialValue, setCookie, router])\n\n React.useEffect(() => {\n if (!userID && tenantCookie) {\n // User is not logged in, but has a tenant cookie, delete it\n deleteCookie()\n setSelectedTenantID(undefined)\n } else if (userID) {\n // User changed, refresh\n router.refresh()\n }\n }, [userID, tenantCookie, deleteCookie, 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","tenantCookie","tenantOptions","setSelectedTenantID","useState","preventRefreshOnChange","user","userID","useMemo","id","selectedTenantLabel","find","option","value","label","router","setCookie","useCallback","expires","document","cookie","deleteCookie","refresh","length","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;AA0B/C,MAAMC,wBAAUF,cAA2B;IACzCG,SAAS,EAAE;IACXC,kBAAkBC;I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;QAAWD;QAAQV;QAAwBH;KAAc;IAGjFb,MAAMoC,SAAS,CAAC;QACd,IACE/B,oBACAA,qBAAqBH,cACrB,CAACW,cAAcS,IAAI,CAAC,CAACC,SAAWA,OAAOC,KAAK,KAAKnB,mBACjD;YACA,IAAIQ,eAAe,CAAC,EAAE,EAAEW,OAAO;gBAC7BhB,UAAU;oBAAEY,IAAIP,aAAa,CAAC,EAAE,CAACW,KAAK;oBAAES,SAAS;gBAAK;YACxD,OAAO;gBACLzB,UAAU;oBAAEY,IAAId;oBAAW2B,SAAS;gBAAK;YAC3C;QACF;IACF,GAAG;QAACrB;QAAcJ;QAAWH;QAAkBQ;QAAeF;QAAcgB;KAAU;IAEtF3B,MAAMoC,SAAS,CAAC;QACd,IAAIlB,UAAU,CAACN,cAAc;YAC3B,+DAA+D;YAC/DE,oBAAoBH;YACpBgB,UAAUQ,OAAOxB;QACnB;IACF,GAAG;QAACO;QAAQN;QAAcD;QAAcgB;QAAWD;KAAO;IAE1D1B,MAAMoC,SAAS,CAAC;QACd,IAAI,CAAClB,UAAUN,cAAc;YAC3B,4DAA4D;YAC5DoB;YACAlB,oBAAoBR;QACtB,OAAO,IAAIY,QAAQ;YACjB,wBAAwB;YACxBQ,OAAOO,OAAO;QAChB;IACF,GAAG;QAACf;QAAQN;QAAcoB;QAAcN;KAAO;IAE/C,qBACE,KAACW;QACCC,2BAAyBjC;QACzBkC,8BAA4BlB;kBAE5B,cAAA,KAAClB,QAAQqC,QAAQ;YACfhB,OAAO;gBACLpB,SAASS;gBACTR;gBACAE;gBACAC;YACF;sBAECE;;;AAIT,EAAC;AAED,OAAO,MAAM+B,qBAAqB,IAAMzC,MAAM0C,UAAU,CAACvC,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;
|
|
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"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { cookies as getCookies } from 'next/headers.js';
|
|
3
|
+
import { SELECT_ALL } from '../../constants.js';
|
|
3
4
|
import { findTenantOptions } from '../../queries/findTenantOptions.js';
|
|
4
5
|
import { TenantSelectionProviderClient } from './index.client.js';
|
|
5
6
|
export const TenantSelectionProvider = async ({ children, payload, tenantsCollectionSlug, useAsTitle, user })=>{
|
|
@@ -22,20 +23,17 @@ export const TenantSelectionProvider = async ({ children, payload, tenantsCollec
|
|
|
22
23
|
const cookies = await getCookies();
|
|
23
24
|
let tenantCookie = cookies.get('payload-tenant')?.value;
|
|
24
25
|
let initialValue = undefined;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
if (tenantOptions.length > 1 && tenantCookie === SELECT_ALL) {
|
|
27
|
+
initialValue = SELECT_ALL;
|
|
28
|
+
} else {
|
|
28
29
|
const matchingOption = tenantOptions.find((option)=>String(option.value) === tenantCookie);
|
|
29
30
|
if (matchingOption) {
|
|
30
31
|
initialValue = matchingOption.value;
|
|
32
|
+
} else {
|
|
33
|
+
tenantCookie = undefined;
|
|
34
|
+
initialValue = tenantOptions.length > 1 ? SELECT_ALL : tenantOptions[0]?.value;
|
|
31
35
|
}
|
|
32
36
|
}
|
|
33
|
-
/**
|
|
34
|
-
* If the there was no cookie or the cookie was an invalid tenantID set intialValue
|
|
35
|
-
*/ if (!initialValue) {
|
|
36
|
-
tenantCookie = undefined;
|
|
37
|
-
initialValue = tenantOptions.length > 1 ? undefined : tenantOptions[0]?.value;
|
|
38
|
-
}
|
|
39
37
|
return /*#__PURE__*/ _jsx(TenantSelectionProviderClient, {
|
|
40
38
|
initialValue: initialValue,
|
|
41
39
|
tenantCookie: 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 { 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
|
|
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"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import type { AcceptedLanguages } from '@payloadcms/translations';
|
|
2
2
|
import type { ArrayField, CollectionSlug, Field, RelationshipField, User } from 'payload';
|
|
3
3
|
export type MultiTenantPluginConfig<ConfigTypes = unknown> = {
|
|
4
|
-
/**
|
|
5
|
-
* Base path for your application
|
|
6
|
-
*
|
|
7
|
-
* https://nextjs.org/docs/app/api-reference/config/next-config-js/basePath
|
|
8
|
-
*
|
|
9
|
-
* @default undefined
|
|
10
|
-
*/
|
|
11
|
-
basePath?: string;
|
|
12
4
|
/**
|
|
13
5
|
* After a tenant is deleted, the plugin will attempt to clean up related documents
|
|
14
6
|
* - removing documents with the tenant ID
|
|
@@ -116,7 +108,7 @@ export type MultiTenantPluginConfig<ConfigTypes = unknown> = {
|
|
|
116
108
|
/**
|
|
117
109
|
* Customize tenant selector label
|
|
118
110
|
*
|
|
119
|
-
* Either a string or an object where the keys are
|
|
111
|
+
* Either a string or an object where the keys are locales and the values are the string labels
|
|
120
112
|
*/
|
|
121
113
|
tenantSelectorLabel?: Partial<{
|
|
122
114
|
[key in AcceptedLanguages]?: 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,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AACjE,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,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AACjE,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;;;;OA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E,OAAO,CAAA;IACpC;;OAEG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B;;OAEG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,CAAA;AAED,MAAM,MAAM,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,CAAC,EACJ;QACE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;KACjC,EAAE,GACH,IAAI,CAAA;CACT,GAAG,IAAI,CAAA"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { AcceptedLanguages } from '@payloadcms/translations'\nimport type { ArrayField, CollectionSlug, Field, RelationshipField, User } from 'payload'\n\nexport type MultiTenantPluginConfig<ConfigTypes = unknown> = {\n /**\n *
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { AcceptedLanguages } from '@payloadcms/translations'\nimport 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 * Name of the array field\n *\n * @default 'tenants'\n */\n arrayFieldName?: string\n /**\n * Name of the tenant field\n *\n * @default 'tenant'\n */\n arrayTenantFieldName?: string\n /**\n * When `includeDefaultField` is `true`, the field will be added to the users collection automatically\n */\n includeDefaultField?: true\n /**\n * Additional fields to include on the tenants array field\n */\n rowFields?: Field[]\n /**\n * Access configuration for the tenant field\n */\n tenantFieldAccess?: RelationshipField['access']\n }\n | {\n arrayFieldAccess?: never\n arrayFieldName?: string\n arrayTenantFieldName?: string\n /**\n * When `includeDefaultField` is `false`, you must include the field on your users collection manually\n */\n includeDefaultField?: false\n rowFields?: never\n tenantFieldAccess?: never\n }\n /**\n * Customize tenant selector label\n *\n * Either a string or an object where the keys are locales and the values are the string labels\n */\n tenantSelectorLabel?:\n | Partial<{\n [key in AcceptedLanguages]?: string\n }>\n | string\n /**\n * The slug for the tenant collection\n *\n * @default 'tenants'\n */\n tenantsSlug?: string\n /**\n * Function that determines if a user has access to _all_ tenants\n *\n * Useful for super-admin type users\n */\n userHasAccessToAllTenants?: (\n user: ConfigTypes extends { user: unknown } ? ConfigTypes['user'] : User,\n ) => boolean\n /**\n * Opt out of adding access constraints to the tenants collection\n */\n useTenantsCollectionAccess?: boolean\n /**\n * Opt out including the baseListFilter to filter tenants by selected tenant\n */\n useTenantsListFilter?: boolean\n /**\n * Opt out including the baseListFilter to filter users by selected tenant\n */\n useUsersTenantFilter?: boolean\n}\n\nexport type Tenant<IDType = number | string> = {\n id: IDType\n name: string\n}\n\nexport type UserWithTenantsField = {\n tenants?:\n | {\n tenant: number | string | Tenant\n }[]\n | null\n} & User\n"],"names":[],"mappings":"AAyJA,WAMQ"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Payload, User, ViewTypes } from 'payload';
|
|
2
2
|
type Args = {
|
|
3
|
-
basePath?: string;
|
|
4
3
|
docID?: number | string;
|
|
5
4
|
headers: Headers;
|
|
6
5
|
payload: Payload;
|
|
@@ -11,6 +10,6 @@ type Args = {
|
|
|
11
10
|
user?: User;
|
|
12
11
|
view: ViewTypes;
|
|
13
12
|
};
|
|
14
|
-
export declare function getGlobalViewRedirect({ slug,
|
|
13
|
+
export declare function getGlobalViewRedirect({ slug, docID, headers, payload, tenantFieldName, tenantsCollectionSlug, useAsTitle, user, view, }: Args): Promise<string | void>;
|
|
15
14
|
export {};
|
|
16
15
|
//# 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,IAAI,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"getGlobalViewRedirect.d.ts","sourceRoot":"","sources":["../../src/utilities/getGlobalViewRedirect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAOvD,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,qBAAqB,EAAE,MAAM,CAAA;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,IAAI,EAAE,SAAS,CAAA;CAChB,CAAA;AACD,wBAAsB,qBAAqB,CAAC,EAC1C,IAAI,EACJ,KAAK,EACL,OAAO,EACP,OAAO,EACP,eAAe,EACf,qBAAqB,EACrB,UAAU,EACV,IAAI,EACJ,IAAI,GACL,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA6D/B"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SELECT_ALL } from '../constants.js';
|
|
2
2
|
import { findTenantOptions } from '../queries/findTenantOptions.js';
|
|
3
3
|
import { getCollectionIDType } from './getCollectionIDType.js';
|
|
4
4
|
import { getTenantFromCookie } from './getTenantFromCookie.js';
|
|
5
|
-
export async function getGlobalViewRedirect({ slug,
|
|
5
|
+
export async function getGlobalViewRedirect({ slug, docID, headers, payload, tenantFieldName, tenantsCollectionSlug, useAsTitle, user, view }) {
|
|
6
6
|
const idType = getCollectionIDType({
|
|
7
7
|
collectionSlug: tenantsCollectionSlug,
|
|
8
8
|
payload
|
|
9
9
|
});
|
|
10
10
|
let tenant = getTenantFromCookie(headers, idType);
|
|
11
|
-
let redirectRoute
|
|
12
|
-
if (!tenant) {
|
|
11
|
+
let redirectRoute;
|
|
12
|
+
if (!tenant || tenant === SELECT_ALL) {
|
|
13
13
|
const tenantsQuery = await findTenantOptions({
|
|
14
14
|
limit: 1,
|
|
15
15
|
payload,
|
|
@@ -37,32 +37,24 @@ export async function getGlobalViewRedirect({ slug, basePath, docID, headers, pa
|
|
|
37
37
|
if (view === 'document') {
|
|
38
38
|
if (docID && !tenantDocID) {
|
|
39
39
|
// viewing a document with an id but does not match the selected tenant, redirect to create route
|
|
40
|
-
redirectRoute =
|
|
40
|
+
redirectRoute = `${payload.config.routes.admin}/collections/${slug}/create`;
|
|
41
41
|
} else if (tenantDocID && docID !== tenantDocID) {
|
|
42
42
|
// tenant document already exists but does not match current route doc ID, redirect to matching tenant doc
|
|
43
|
-
redirectRoute =
|
|
43
|
+
redirectRoute = `${payload.config.routes.admin}/collections/${slug}/${tenantDocID}`;
|
|
44
44
|
}
|
|
45
45
|
} else if (view === 'list') {
|
|
46
46
|
if (tenantDocID) {
|
|
47
47
|
// tenant document exists, redirect to edit view
|
|
48
|
-
redirectRoute =
|
|
48
|
+
redirectRoute = `${payload.config.routes.admin}/collections/${slug}/${tenantDocID}`;
|
|
49
49
|
} else {
|
|
50
50
|
// tenant document does not exist, redirect to create route
|
|
51
|
-
redirectRoute =
|
|
51
|
+
redirectRoute = `${payload.config.routes.admin}/collections/${slug}/create`;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
} catch (e) {
|
|
55
55
|
payload.logger.error(e, `${typeof e === 'object' && e && 'message' in e ? `e?.message - ` : ''}Multi Tenant Redirect Error`);
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
return formatAdminURL({
|
|
59
|
-
adminRoute: payload.config.routes.admin,
|
|
60
|
-
basePath,
|
|
61
|
-
path: redirectRoute,
|
|
62
|
-
serverURL: payload.config.serverURL
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
return undefined;
|
|
57
|
+
return redirectRoute;
|
|
66
58
|
}
|
|
67
59
|
|
|
68
60
|
//# sourceMappingURL=getGlobalViewRedirect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getGlobalViewRedirect.ts"],"sourcesContent":["import type { Payload, User, ViewTypes } from 'payload'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getGlobalViewRedirect.ts"],"sourcesContent":["import type { Payload, User, ViewTypes } from 'payload'\n\nimport { SELECT_ALL } from '../constants.js'\nimport { findTenantOptions } from '../queries/findTenantOptions.js'\nimport { getCollectionIDType } from './getCollectionIDType.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 tenantsCollectionSlug: string\n useAsTitle: string\n user?: User\n view: ViewTypes\n}\nexport async function getGlobalViewRedirect({\n slug,\n docID,\n headers,\n payload,\n tenantFieldName,\n tenantsCollectionSlug,\n useAsTitle,\n user,\n view,\n}: Args): Promise<string | void> {\n const idType = getCollectionIDType({\n collectionSlug: tenantsCollectionSlug,\n payload,\n })\n let tenant = getTenantFromCookie(headers, idType)\n let redirectRoute\n\n if (!tenant || tenant === SELECT_ALL) {\n const tenantsQuery = await findTenantOptions({\n limit: 1,\n payload,\n tenantsCollectionSlug,\n useAsTitle,\n user,\n })\n\n tenant = tenantsQuery.docs[0]?.id || null\n }\n\n try {\n const { docs } = await payload.find({\n collection: slug,\n depth: 0,\n limit: 1,\n overrideAccess: false,\n pagination: false,\n user,\n where: {\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 return redirectRoute\n}\n"],"names":["SELECT_ALL","findTenantOptions","getCollectionIDType","getTenantFromCookie","getGlobalViewRedirect","slug","docID","headers","payload","tenantFieldName","tenantsCollectionSlug","useAsTitle","user","view","idType","collectionSlug","tenant","redirectRoute","tenantsQuery","limit","docs","id","find","collection","depth","overrideAccess","pagination","where","equals","tenantDocID","config","routes","admin","e","logger","error"],"mappings":"AAEA,SAASA,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,iBAAiB,QAAQ,kCAAiC;AACnE,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,mBAAmB,QAAQ,2BAA0B;AAa9D,OAAO,eAAeC,sBAAsB,EAC1CC,IAAI,EACJC,KAAK,EACLC,OAAO,EACPC,OAAO,EACPC,eAAe,EACfC,qBAAqB,EACrBC,UAAU,EACVC,IAAI,EACJC,IAAI,EACC;IACL,MAAMC,SAASZ,oBAAoB;QACjCa,gBAAgBL;QAChBF;IACF;IACA,IAAIQ,SAASb,oBAAoBI,SAASO;IAC1C,IAAIG;IAEJ,IAAI,CAACD,UAAUA,WAAWhB,YAAY;QACpC,MAAMkB,eAAe,MAAMjB,kBAAkB;YAC3CkB,OAAO;YACPX;YACAE;YACAC;YACAC;QACF;QAEAI,SAASE,aAAaE,IAAI,CAAC,EAAE,EAAEC,MAAM;IACvC;IAEA,IAAI;QACF,MAAM,EAAED,IAAI,EAAE,GAAG,MAAMZ,QAAQc,IAAI,CAAC;YAClCC,YAAYlB;YACZmB,OAAO;YACPL,OAAO;YACPM,gBAAgB;YAChBC,YAAY;YACZd;YACAe,OAAO;gBACL,CAAClB,gBAAgB,EAAE;oBACjBmB,QAAQZ;gBACV;YACF;QACF;QAEA,MAAMa,cAAcT,MAAM,CAAC,EAAE,EAAEC;QAE/B,IAAIR,SAAS,YAAY;YACvB,IAAIP,SAAS,CAACuB,aAAa;gBACzB,iGAAiG;gBACjGZ,gBAAgB,GAAGT,QAAQsB,MAAM,CAACC,MAAM,CAACC,KAAK,CAAC,aAAa,EAAE3B,KAAK,OAAO,CAAC;YAC7E,OAAO,IAAIwB,eAAevB,UAAUuB,aAAa;gBAC/C,0GAA0G;gBAC1GZ,gBAAgB,GAAGT,QAAQsB,MAAM,CAACC,MAAM,CAACC,KAAK,CAAC,aAAa,EAAE3B,KAAK,CAAC,EAAEwB,aAAa;YACrF;QACF,OAAO,IAAIhB,SAAS,QAAQ;YAC1B,IAAIgB,aAAa;gBACf,gDAAgD;gBAChDZ,gBAAgB,GAAGT,QAAQsB,MAAM,CAACC,MAAM,CAACC,KAAK,CAAC,aAAa,EAAE3B,KAAK,CAAC,EAAEwB,aAAa;YACrF,OAAO;gBACL,2DAA2D;gBAC3DZ,gBAAgB,GAAGT,QAAQsB,MAAM,CAACC,MAAM,CAACC,KAAK,CAAC,aAAa,EAAE3B,KAAK,OAAO,CAAC;YAC7E;QACF;IACF,EAAE,OAAO4B,GAAY;QACnBzB,QAAQ0B,MAAM,CAACC,KAAK,CAClBF,GACA,GAAG,OAAOA,MAAM,YAAYA,KAAK,aAAaA,IAAI,CAAC,aAAa,CAAC,GAAG,GAAG,2BAA2B,CAAC;IAEvG;IACA,OAAOhB;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-multi-tenant",
|
|
3
|
-
"version": "3.29.0-internal.
|
|
3
|
+
"version": "3.29.0-internal.37e46b5",
|
|
4
4
|
"description": "Multi Tenant plugin for Payload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"payload",
|
|
@@ -67,14 +67,14 @@
|
|
|
67
67
|
],
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@payloadcms/eslint-config": "3.28.0",
|
|
70
|
-
"@payloadcms/ui": "3.29.0-internal.
|
|
71
|
-
"@payloadcms/translations": "3.29.0-internal.
|
|
72
|
-
"payload": "3.29.0-internal.
|
|
70
|
+
"@payloadcms/ui": "3.29.0-internal.37e46b5",
|
|
71
|
+
"@payloadcms/translations": "3.29.0-internal.37e46b5",
|
|
72
|
+
"payload": "3.29.0-internal.37e46b5"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"next": "^15.0.3",
|
|
76
|
-
"@payloadcms/ui": "3.29.0-internal.
|
|
77
|
-
"payload": "3.29.0-internal.
|
|
76
|
+
"@payloadcms/ui": "3.29.0-internal.37e46b5",
|
|
77
|
+
"payload": "3.29.0-internal.37e46b5"
|
|
78
78
|
},
|
|
79
79
|
"homepage:": "https://payloadcms.com",
|
|
80
80
|
"scripts": {
|