@payloadcms/plugin-multi-tenant 3.29.0-internal.d2c9ba5 → 3.29.0-internal.e4e913b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +38 -2
  2. package/dist/components/GlobalViewRedirect/index.d.ts +1 -0
  3. package/dist/components/GlobalViewRedirect/index.d.ts.map +1 -1
  4. package/dist/components/GlobalViewRedirect/index.js +1 -0
  5. package/dist/components/GlobalViewRedirect/index.js.map +1 -1
  6. package/dist/components/TenantField/index.client.d.ts.map +1 -1
  7. package/dist/components/TenantField/index.client.js +2 -3
  8. package/dist/components/TenantField/index.client.js.map +1 -1
  9. package/dist/components/TenantSelector/index.d.ts +1 -1
  10. package/dist/components/TenantSelector/index.d.ts.map +1 -1
  11. package/dist/components/TenantSelector/index.js +5 -5
  12. package/dist/components/TenantSelector/index.js.map +1 -1
  13. package/dist/defaults.d.ts +1 -0
  14. package/dist/defaults.d.ts.map +1 -1
  15. package/dist/defaults.js +1 -0
  16. package/dist/defaults.js.map +1 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +5 -4
  19. package/dist/index.js.map +1 -1
  20. package/dist/list-filters/filterDocumentsBySelectedTenant.d.ts.map +1 -1
  21. package/dist/list-filters/filterDocumentsBySelectedTenant.js +7 -8
  22. package/dist/list-filters/filterDocumentsBySelectedTenant.js.map +1 -1
  23. package/dist/list-filters/filterTenantsBySelectedTenant.d.ts.map +1 -1
  24. package/dist/list-filters/filterTenantsBySelectedTenant.js +7 -8
  25. package/dist/list-filters/filterTenantsBySelectedTenant.js.map +1 -1
  26. package/dist/list-filters/filterUsersBySelectedTenant.d.ts.map +1 -1
  27. package/dist/list-filters/filterUsersBySelectedTenant.js +9 -10
  28. package/dist/list-filters/filterUsersBySelectedTenant.js.map +1 -1
  29. package/dist/providers/TenantSelectionProvider/index.client.d.ts.map +1 -1
  30. package/dist/providers/TenantSelectionProvider/index.client.js +15 -10
  31. package/dist/providers/TenantSelectionProvider/index.client.js.map +1 -1
  32. package/dist/providers/TenantSelectionProvider/index.d.ts.map +1 -1
  33. package/dist/providers/TenantSelectionProvider/index.js +9 -7
  34. package/dist/providers/TenantSelectionProvider/index.js.map +1 -1
  35. package/dist/types.d.ts +9 -1
  36. package/dist/types.d.ts.map +1 -1
  37. package/dist/types.js.map +1 -1
  38. package/dist/utilities/getGlobalViewRedirect.d.ts +2 -1
  39. package/dist/utilities/getGlobalViewRedirect.d.ts.map +1 -1
  40. package/dist/utilities/getGlobalViewRedirect.js +17 -9
  41. package/dist/utilities/getGlobalViewRedirect.js.map +1 -1
  42. package/package.json +7 -7
  43. package/dist/constants.d.ts +0 -2
  44. package/dist/constants.d.ts.map +0 -1
  45. package/dist/constants.js +0 -4
  46. package/dist/constants.js.map +0 -1
package/README.md CHANGED
@@ -86,6 +86,18 @@ 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
89
101
  /**
90
102
  * When `includeDefaultField` is `true`, the field will be added to the users collection automatically
91
103
  */
@@ -101,6 +113,8 @@ type MultiTenantPluginConfig<ConfigTypes = unknown> = {
101
113
  }
102
114
  | {
103
115
  arrayFieldAccess?: never
116
+ arrayFieldName?: string
117
+ arrayTenantFieldName?: string
104
118
  /**
105
119
  * When `includeDefaultField` is `false`, you must include the field on your users collection manually
106
120
  */
@@ -108,6 +122,16 @@ type MultiTenantPluginConfig<ConfigTypes = unknown> = {
108
122
  rowFields?: never
109
123
  tenantFieldAccess?: never
110
124
  }
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
111
135
  /**
112
136
  * The slug for the tenant collection
113
137
  *
@@ -120,8 +144,20 @@ type MultiTenantPluginConfig<ConfigTypes = unknown> = {
120
144
  * Useful for super-admin type users
121
145
  */
122
146
  userHasAccessToAllTenants?: (
123
- user: ConfigTypes extends { user } ? ConfigTypes['user'] : User,
147
+ user: ConfigTypes extends { user: unknown } ? ConfigTypes['user'] : User,
124
148
  ) => 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
125
161
  }
126
162
  ```
127
163
 
@@ -159,7 +195,7 @@ import { Config as ConfigTypes } from './payload-types'
159
195
  // Add the plugin to your payload config
160
196
  export default buildConfig({
161
197
  plugins: [
162
- multiTenantPlugin({
198
+ multiTenantPlugin<ConfigTypes>({
163
199
  collections: {
164
200
  media: {
165
201
  useTenantAccess: false,
@@ -1,5 +1,6 @@
1
1
  import type { CollectionSlug, ServerProps, ViewTypes } from 'payload';
2
2
  type Args = {
3
+ basePath?: string;
3
4
  collectionSlug: CollectionSlug;
4
5
  docID?: number | string;
5
6
  globalSlugs: string[];
@@ -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,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
+ {"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,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,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,kBAqBlD,CAAA"}
@@ -7,6 +7,7 @@ export const GlobalViewRedirect = async (args)=>{
7
7
  const headers = await getHeaders();
8
8
  const redirectRoute = await getGlobalViewRedirect({
9
9
  slug: collectionSlug,
10
+ basePath: args.basePath,
10
11
  docID: args.docID,
11
12
  headers,
12
13
  payload: args.payload,
@@ -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 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
+ {"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 basePath?: string\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 basePath: args.basePath,\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","basePath","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;AAahF,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,UAAUN,KAAKM,QAAQ;YACvBC,OAAOP,KAAKO,KAAK;YACjBZ;YACAa,SAASR,KAAKQ,OAAO;YACrBC,iBAAiBT,KAAKS,eAAe;YACrCC,uBAAuBV,KAAKU,qBAAqB;YACjDC,YAAYX,KAAKW,UAAU;YAC3BC,MAAMZ,KAAKY,IAAI;YACfC,MAAMb,KAAKc,QAAQ;QACrB;QAEA,IAAIV,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;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"}
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;AAGzB,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,6BA6CtC,CAAA"}
@@ -2,7 +2,6 @@
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';
6
5
  import { useTenantSelection } from '../../providers/TenantSelectionProvider/index.client.js';
7
6
  import './index.scss';
8
7
  const baseClass = 'tenantField';
@@ -23,14 +22,14 @@ export const TenantField = (args)=>{
23
22
  });
24
23
  } else {
25
24
  // in the document view, the tenant field should always have a value
26
- const defaultValue = !selectedTenantID || selectedTenantID === SELECT_ALL ? options[0]?.value : selectedTenantID;
25
+ const defaultValue = selectedTenantID || options[0]?.value;
27
26
  setTenant({
28
27
  id: defaultValue,
29
28
  refresh: unique
30
29
  });
31
30
  }
32
31
  hasSetValueRef.current = true;
33
- } else if ((!value || value !== selectedTenantID) && selectedTenantID !== SELECT_ALL) {
32
+ } else if (!value || value !== selectedTenantID) {
34
33
  // Update the field on the document value when the tenant is changed
35
34
  setValue(selectedTenantID);
36
35
  }
@@ -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 { 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
+ {"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 = selectedTenantID || options[0]?.value\n setTenant({ id: defaultValue, refresh: unique })\n }\n hasSetValueRef.current = true\n } else if (!value || value !== selectedTenantID) {\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","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,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,GAAGV,SAA0B;QAAEO;IAAK;IAC7D,MAAM,EAAEI,OAAO,EAAEC,gBAAgB,EAAEC,yBAAyB,EAAEC,SAAS,EAAE,GAAGZ;IAE5E,MAAMa,iBAAiBd,MAAMe,MAAM,CAAC;IAEpCf,MAAMgB,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,eAAeT,oBAAoBD,OAAO,CAAC,EAAE,EAAED;gBACrDI,UAAU;oBAAEK,IAAIE;oBAAcD,SAASZ;gBAAO;YAChD;YACAO,eAAeG,OAAO,GAAG;QAC3B,OAAO,IAAI,CAACR,SAASA,UAAUE,kBAAkB;YAC/C,oEAAoE;YACpEH,SAASG;QACX;IACF,GAAG;QAACF;QAAOE;QAAkBE;QAAWL;QAAUE;QAASH;KAAO;IAElEP,MAAMgB,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,KAACJ;wBAAmB,GAAGM,IAAI;;;8BAE7B,KAACiB;oBAAIC,WAAW,GAAGpB,UAAU,IAAI,CAAC;;;;IAGxC;IAEA,OAAO;AACT,EAAC"}
@@ -1,6 +1,6 @@
1
1
  import type { ViewTypes } from 'payload';
2
- import './index.scss';
3
2
  import React from 'react';
3
+ import './index.scss';
4
4
  export declare const TenantSelector: ({ label, viewType }: {
5
5
  label: string;
6
6
  viewType?: ViewTypes;
@@ -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;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
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/TenantSelector/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,cAAc,CAAA;AAErB,eAAO,MAAM,cAAc,wBAAyB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,6BAgC1F,CAAA"}
@@ -1,13 +1,13 @@
1
1
  'use client';
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import './index.scss';
3
+ import { getTranslation } from '@payloadcms/translations';
4
4
  import { SelectInput, useTranslation } from '@payloadcms/ui';
5
5
  import React from 'react';
6
- import { SELECT_ALL } from '../../constants.js';
7
6
  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 { t } = useTranslation();
10
+ const { i18n } = 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: t(label),
33
+ label: getTranslation(label, i18n),
34
34
  name: "setTenant",
35
35
  onChange: handleChange,
36
36
  options: options,
37
37
  path: "setTenant",
38
- value: selectedTenantID ? selectedTenantID === SELECT_ALL ? undefined : selectedTenantID : undefined
38
+ value: selectedTenantID
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 './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"}
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 { getTranslation } from '@payloadcms/translations'\nimport { SelectInput, useTranslation } from '@payloadcms/ui'\nimport React from 'react'\n\nimport { useTenantSelection } from '../../providers/TenantSelectionProvider/index.client.js'\nimport './index.scss'\n\nexport const TenantSelector = ({ label, viewType }: { label: string; viewType?: ViewTypes }) => {\n const { options, selectedTenantID, setTenant } = useTenantSelection()\n const { i18n } = 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={getTranslation(label, i18n)}\n name=\"setTenant\"\n onChange={handleChange}\n options={options}\n path=\"setTenant\"\n value={selectedTenantID as string | undefined}\n />\n </div>\n )\n}\n"],"names":["getTranslation","SelectInput","useTranslation","React","useTenantSelection","TenantSelector","label","viewType","options","selectedTenantID","setTenant","i18n","handleChange","useCallback","option","id","value","refresh","undefined","length","div","className","isClearable","name","onChange","path"],"mappings":"AAAA;;AAIA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SAASC,WAAW,EAAEC,cAAc,QAAQ,iBAAgB;AAC5D,OAAOC,WAAW,QAAO;AAEzB,SAASC,kBAAkB,QAAQ,0DAAyD;AAC5F,OAAO,eAAc;AAErB,OAAO,MAAMC,iBAAiB,CAAC,EAAEC,KAAK,EAAEC,QAAQ,EAA2C;IACzF,MAAM,EAAEC,OAAO,EAAEC,gBAAgB,EAAEC,SAAS,EAAE,GAAGN;IACjD,MAAM,EAAEO,IAAI,EAAE,GAAGT;IAEjB,MAAMU,eAAeT,MAAMU,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,KAACpB;YACCqB,aAAaf,aAAa;YAC1BD,OAAON,eAAeM,OAAOK;YAC7BY,MAAK;YACLC,UAAUZ;YACVJ,SAASA;YACTiB,MAAK;YACLT,OAAOP;;;AAIf,EAAC"}
@@ -1,4 +1,5 @@
1
1
  export declare const defaults: {
2
+ basePath: undefined;
2
3
  tenantCollectionSlug: string;
3
4
  tenantFieldName: string;
4
5
  tenantsArrayFieldName: string;
@@ -1 +1 @@
1
- {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ;;;;;;CAMpB,CAAA"}
1
+ {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ;;;;;;;CAOpB,CAAA"}
package/dist/defaults.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export const defaults = {
2
+ basePath: undefined,
2
3
  tenantCollectionSlug: 'tenants',
3
4
  tenantFieldName: 'tenant',
4
5
  tenantsArrayFieldName: 'tenants',
@@ -1 +1 @@
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"}
1
+ {"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["export const defaults = {\n basePath: undefined,\n tenantCollectionSlug: 'tenants',\n tenantFieldName: 'tenant',\n tenantsArrayFieldName: 'tenants',\n tenantsArrayTenantFieldName: 'tenant',\n tenantSelectorLabel: 'Tenant',\n}\n"],"names":["defaults","basePath","undefined","tenantCollectionSlug","tenantFieldName","tenantsArrayFieldName","tenantsArrayTenantFieldName","tenantSelectorLabel"],"mappings":"AAAA,OAAO,MAAMA,WAAW;IACtBC,UAAUC;IACVC,sBAAsB;IACtBC,iBAAiB;IACjBC,uBAAuB;IACvBC,6BAA6B;IAC7BC,qBAAqB;AACvB,EAAC"}
@@ -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,MAoUzB,CAAA"}
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,MAqUzB,CAAA"}
package/dist/index.js CHANGED
@@ -19,7 +19,8 @@ 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
- let tenantSelectorLabel = pluginConfig.tenantSelectorLabel || defaults.tenantSelectorLabel;
22
+ const tenantSelectorLabel = pluginConfig.tenantSelectorLabel || defaults.tenantSelectorLabel;
23
+ const basePath = pluginConfig.basePath || defaults.basePath;
23
24
  /**
24
25
  * Add defaults for admin properties
25
26
  */ if (!incomingConfig.admin) {
@@ -46,11 +47,11 @@ export const multiTenantPlugin = (pluginConfig)=>(incomingConfig)=>{
46
47
  }
47
48
  /**
48
49
  * Add tenant selector localized labels
49
- */ if (pluginConfig.tenantSelectorLabel && typeof pluginConfig.tenantSelectorLabel === 'object') {
50
+ */ if (typeof tenantSelectorLabel === 'object') {
50
51
  if (!incomingConfig.i18n) {
51
52
  incomingConfig.i18n = {};
52
53
  }
53
- Object.entries(pluginConfig.tenantSelectorLabel).forEach(([_locale, label])=>{
54
+ Object.entries(tenantSelectorLabel).forEach(([_locale, label])=>{
54
55
  const locale = _locale;
55
56
  if (!incomingConfig.i18n) {
56
57
  incomingConfig.i18n = {};
@@ -71,7 +72,6 @@ export const multiTenantPlugin = (pluginConfig)=>(incomingConfig)=>{
71
72
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
72
73
  // @ts-expect-error
73
74
  incomingConfig.i18n.translations[locale].multiTenant.selectorLabel = label;
74
- tenantSelectorLabel = 'multiTenant:selectorLabel';
75
75
  });
76
76
  }
77
77
  /**
@@ -255,6 +255,7 @@ 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,
258
259
  globalSlugs: globalCollectionSlugs,
259
260
  tenantFieldName,
260
261
  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 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;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,IAAIE,sBAAsBb,aAAaa,mBAAmB,IAAIxB,SAASwB,mBAAmB;QAE1F;;KAEC,GACD,IAAI,CAACZ,eAAea,KAAK,EAAE;YACzBb,eAAea,KAAK,GAAG,CAAC;QAC1B;QACA,IAAI,CAACb,eAAea,KAAK,EAAEC,YAAY;YACrCd,eAAea,KAAK,CAACC,UAAU,GAAG;gBAChCC,SAAS,EAAE;gBACXC,gBAAgB,EAAE;gBAClB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AuB2C,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
+ {"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,M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sD,KAAKD,KAAKC,GAAG;gCACbxC;gCACAH;4BACF;oBACJ;gBACF;gBAEA,IAAIJ,aAAaoB,WAAW,CAACqB,WAAWR,IAAI,CAAC,EAAEsC,oBAAoB,OAAO;oBACxE;;WAEC,GACD3E,oBAAoB;wBAClB4C,gBAAgBT,qBAAqBE,IAAI;wBACzCQ;wBACAC,WAAWnC;wBACXE;wBACAE;wBACAR;oBACF;gBACF;YACF;QACF;QAEA,IAAI,CAAC6C,kBAAkB;YACrB,MAAM,IAAIZ,MAAM,CAAC,wCAAwC,EAAEhC,uBAAuB;QACpF;QAEA;;KAEC,GACDH,eAAec,KAAK,CAACC,UAAU,CAACG,SAAS,CAACoB,IAAI,CAAC;YAC7CiC,aAAa;gBACXpE,uBAAuB4C,iBAAiBf,IAAI;gBAC5CwC,YAAYzB,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 +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;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
+ {"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;AAKpD,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,4 +1,3 @@
1
- import { SELECT_ALL } from '../constants.js';
2
1
  import { getCollectionIDType } from '../utilities/getCollectionIDType.js';
3
2
  import { getTenantFromCookie } from '../utilities/getTenantFromCookie.js';
4
3
  export const filterDocumentsBySelectedTenant = ({ req, tenantFieldName, tenantsCollectionSlug })=>{
@@ -7,14 +6,14 @@ export const filterDocumentsBySelectedTenant = ({ req, tenantFieldName, tenantsC
7
6
  payload: req.payload
8
7
  });
9
8
  const selectedTenant = getTenantFromCookie(req.headers, idType);
10
- if (selectedTenant === SELECT_ALL) {
11
- return {};
9
+ if (selectedTenant) {
10
+ return {
11
+ [tenantFieldName]: {
12
+ equals: selectedTenant
13
+ }
14
+ };
12
15
  }
13
- return {
14
- [tenantFieldName]: {
15
- equals: selectedTenant
16
- }
17
- };
16
+ return {};
18
17
  };
19
18
 
20
19
  //# sourceMappingURL=filterDocumentsBySelectedTenant.js.map
@@ -1 +1 @@
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
+ {"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 [tenantFieldName]: {\n equals: selectedTenant,\n },\n }\n }\n\n return {}\n}\n"],"names":["getCollectionIDType","getTenantFromCookie","filterDocumentsBySelectedTenant","req","tenantFieldName","tenantsCollectionSlug","idType","collectionSlug","payload","selectedTenant","headers","equals"],"mappings":"AAEA,SAASA,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,gBAAgB;QAClB,OAAO;YACL,CAACL,gBAAgB,EAAE;gBACjBO,QAAQF;YACV;QACF;IACF;IAEA,OAAO,CAAC;AACV,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;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
+ {"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;AAKpD,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,4 +1,3 @@
1
- import { SELECT_ALL } from '../constants.js';
2
1
  import { getCollectionIDType } from '../utilities/getCollectionIDType.js';
3
2
  import { getTenantFromCookie } from '../utilities/getTenantFromCookie.js';
4
3
  export const filterTenantsBySelectedTenant = ({ req, tenantsCollectionSlug })=>{
@@ -7,14 +6,14 @@ export const filterTenantsBySelectedTenant = ({ req, tenantsCollectionSlug })=>{
7
6
  payload: req.payload
8
7
  });
9
8
  const selectedTenant = getTenantFromCookie(req.headers, idType);
10
- if (selectedTenant === SELECT_ALL) {
11
- return {};
9
+ if (selectedTenant) {
10
+ return {
11
+ id: {
12
+ equals: selectedTenant
13
+ }
14
+ };
12
15
  }
13
- return {
14
- id: {
15
- equals: selectedTenant
16
- }
17
- };
16
+ return {};
18
17
  };
19
18
 
20
19
  //# sourceMappingURL=filterTenantsBySelectedTenant.js.map
@@ -1 +1 @@
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
+ {"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 id: {\n equals: selectedTenant,\n },\n }\n }\n\n return {}\n}\n"],"names":["getCollectionIDType","getTenantFromCookie","filterTenantsBySelectedTenant","req","tenantsCollectionSlug","idType","collectionSlug","payload","selectedTenant","headers","id","equals"],"mappings":"AAEA,SAASA,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,gBAAgB;QAClB,OAAO;YACLE,IAAI;gBACFC,QAAQH;YACV;QACF;IACF;IAEA,OAAO,CAAC;AACV,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;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
+ {"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;AAKpD,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,4 +1,3 @@
1
- import { SELECT_ALL } from '../constants.js';
2
1
  import { getCollectionIDType } from '../utilities/getCollectionIDType.js';
3
2
  import { getTenantFromCookie } from '../utilities/getTenantFromCookie.js';
4
3
  /**
@@ -9,16 +8,16 @@ import { getTenantFromCookie } from '../utilities/getTenantFromCookie.js';
9
8
  payload: req.payload
10
9
  });
11
10
  const selectedTenant = getTenantFromCookie(req.headers, idType);
12
- if (selectedTenant === SELECT_ALL) {
13
- return {};
11
+ if (selectedTenant) {
12
+ return {
13
+ [`${tenantsArrayFieldName}.${tenantsArrayTenantFieldName}`]: {
14
+ in: [
15
+ selectedTenant
16
+ ]
17
+ }
18
+ };
14
19
  }
15
- return {
16
- [`${tenantsArrayFieldName}.${tenantsArrayTenantFieldName}`]: {
17
- in: [
18
- selectedTenant
19
- ]
20
- }
21
- };
20
+ return {};
22
21
  };
23
22
 
24
23
  //# sourceMappingURL=filterUsersBySelectedTenant.js.map
@@ -1 +1 @@
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
+ {"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 [`${tenantsArrayFieldName}.${tenantsArrayTenantFieldName}`]: {\n in: [selectedTenant],\n },\n }\n }\n\n return {}\n}\n"],"names":["getCollectionIDType","getTenantFromCookie","filterUsersBySelectedTenant","req","tenantsArrayFieldName","tenantsArrayTenantFieldName","tenantsCollectionSlug","idType","collectionSlug","payload","selectedTenant","headers","in"],"mappings":"AAEA,SAASA,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,gBAAgB;QAClB,OAAO;YACL,CAAC,GAAGN,sBAAsB,CAAC,EAAEC,6BAA6B,CAAC,EAAE;gBAC3DO,IAAI;oBAACF;iBAAe;YACtB;QACF;IACF;IAEA,OAAO,CAAC;AACV,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;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"}
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;AAE5C,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,mBAA2B,CAAA"}
@@ -3,7 +3,6 @@ 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';
7
6
  const Context = /*#__PURE__*/ createContext({
8
7
  options: [],
9
8
  selectedTenantID: undefined,
@@ -32,8 +31,8 @@ export const TenantSelectionProviderClient = ({ children, initialValue, tenantCo
32
31
  const setTenant = React.useCallback(({ id, refresh })=>{
33
32
  if (id === undefined) {
34
33
  if (tenantOptions.length > 1) {
35
- setSelectedTenantID(SELECT_ALL);
36
- setCookie(SELECT_ALL);
34
+ setSelectedTenantID(undefined);
35
+ deleteCookie();
37
36
  } else {
38
37
  setSelectedTenantID(tenantOptions[0]?.value);
39
38
  setCookie(String(tenantOptions[0]?.value));
@@ -46,14 +45,15 @@ export const TenantSelectionProviderClient = ({ children, initialValue, tenantCo
46
45
  router.refresh();
47
46
  }
48
47
  }, [
49
- setSelectedTenantID,
50
- setCookie,
51
- router,
48
+ deleteCookie,
52
49
  preventRefreshOnChange,
50
+ router,
51
+ setCookie,
52
+ setSelectedTenantID,
53
53
  tenantOptions
54
54
  ]);
55
55
  React.useEffect(()=>{
56
- if (selectedTenantID && selectedTenantID !== SELECT_ALL && !tenantOptions.find((option)=>option.value === selectedTenantID)) {
56
+ if (selectedTenantID && !tenantOptions.find((option)=>option.value === selectedTenantID)) {
57
57
  if (tenantOptions?.[0]?.value) {
58
58
  setTenant({
59
59
  id: tenantOptions[0].value,
@@ -78,13 +78,18 @@ 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
- setCookie(String(initialValue));
81
+ if (initialValue) {
82
+ setCookie(String(initialValue));
83
+ } else {
84
+ deleteCookie();
85
+ }
82
86
  }
83
87
  }, [
84
88
  userID,
85
89
  tenantCookie,
86
90
  initialValue,
87
91
  setCookie,
92
+ deleteCookie,
88
93
  router
89
94
  ]);
90
95
  React.useEffect(()=>{
@@ -105,7 +110,7 @@ export const TenantSelectionProviderClient = ({ children, initialValue, tenantCo
105
110
  return /*#__PURE__*/ _jsx("span", {
106
111
  "data-selected-tenant-id": selectedTenantID,
107
112
  "data-selected-tenant-title": selectedTenantLabel,
108
- children: /*#__PURE__*/ _jsx(Context.Provider, {
113
+ children: /*#__PURE__*/ _jsx(Context, {
109
114
  value: {
110
115
  options: tenantOptions,
111
116
  selectedTenantID,
@@ -116,6 +121,6 @@ export const TenantSelectionProviderClient = ({ children, initialValue, tenantCo
116
121
  })
117
122
  });
118
123
  };
119
- export const useTenantSelection = ()=>React.useContext(Context);
124
+ export const useTenantSelection = ()=>React.use(Context);
120
125
 
121
126
  //# 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\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;IAClBC,2BAA2B,IAAM;IACjCC,WAAW,IAAM;AACnB;AAEA,OAAO,MAAMC,gCAAgC,CAAC,EAC5CC,QAAQ,EACRC,YAAY,EACZC,YAAY,EACZC,aAAa,EAMd;IACC,MAAM,CAACR,kBAAkBS,oBAAoB,GAAGd,MAAMe,QAAQ,CAC5DJ;IAEF,MAAM,CAACK,wBAAwBT,0BAA0B,GAAGP,MAAMe,QAAQ,CAAC;IAC3E,MAAM,EAAEE,IAAI,EAAE,GAAGnB;IACjB,MAAMoB,SAASlB,MAAMmB,OAAO,CAAC,IAAMF,MAAMG,IAAI;QAACH,MAAMG;KAAG;IACvD,MAAMC,sBAAsBrB,MAAMmB,OAAO,CACvC,IAAMN,cAAcS,IAAI,CAAC,CAACC,SAAWA,OAAOC,KAAK,KAAKnB,mBAAmBoB,OACzE;QAACpB;QAAkBQ;KAAc;IAGnC,MAAMa,SAAS3B;IAEf,MAAM4B,YAAY3B,MAAM4B,WAAW,CAAC,CAACJ;QACnC,MAAMK,UAAU;QACh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,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
+ {"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(undefined)\n deleteCookie()\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 [deleteCookie, preventRefreshOnChange, router, setCookie, setSelectedTenantID, tenantOptions],\n )\n\n React.useEffect(() => {\n if (selectedTenantID && !tenantOptions.find((option) => option.value === selectedTenantID)) {\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 if (initialValue) {\n setCookie(String(initialValue))\n } else {\n deleteCookie()\n }\n }\n }, [userID, tenantCookie, initialValue, setCookie, deleteCookie, 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\n value={{\n options: tenantOptions,\n selectedTenantID,\n setPreventRefreshOnChange,\n setTenant,\n }}\n >\n {children}\n </Context>\n </span>\n )\n}\n\nexport const useTenantSelection = () => React.use(Context)\n"],"names":["useAuth","useRouter","React","createContext","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","useTenantSelection","use"],"mappings":"AAAA;;AAIA,SAASA,OAAO,QAAQ,iBAAgB;AACxC,SAASC,SAAS,QAAQ,qBAAoB;AAC9C,OAAOC,SAASC,aAAa,QAAQ,QAAO;AA0B5C,MAAMC,wBAAUD,cAA2B;IACzCE,SAAS,EAAE;IACXC,kBAAkBC;IAClBC,2BAA2B,IAAM;IACjCC,WAAW,IAAM;AACnB;AAEA,OAAO,MAAMC,gCAAgC,CAAC,EAC5CC,QAAQ,EACRC,YAAY,EACZC,YAAY,EACZC,aAAa,EAMd;IACC,MAAM,CAACR,kBAAkBS,oBAAoB,GAAGb,MAAMc,QAAQ,CAC5DJ;IAEF,MAAM,CAACK,wBAAwBT,0BAA0B,GAAGN,MAAMc,QAAQ,CAAC;IAC3E,MAAM,EAAEE,IAAI,EAAE,GAAGlB;IACjB,MAAMmB,SAASjB,MAAMkB,OAAO,CAAC,IAAMF,MAAMG,IAAI;QAACH,MAAMG;KAAG;IACvD,MAAMC,sBAAsBpB,MAAMkB,OAAO,CACvC,IAAMN,cAAcS,IAAI,CAAC,CAACC,SAAWA,OAAOC,KAAK,KAAKnB,mBAAmBoB,OACzE;QAACpB;QAAkBQ;KAAc;IAGnC,MAAMa,SAAS1B;IAEf,MAAM2B,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;gBACLqB;YACF;QACF;IACF,GAAG;QAACd;QAAQN;QAAcD;QAAcgB;QAAWK;QAAcN;KAAO;IAExEzB,MAAMmC,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;YACCqB,OAAO;gBACLpB,SAASS;gBACTR;gBACAE;gBACAC;YACF;sBAECE;;;AAIT,EAAC;AAED,OAAO,MAAM8B,qBAAqB,IAAMvC,MAAMwC,GAAG,CAACtC,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;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
+ {"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;AAO1D,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,yCAkDN,CAAA"}
@@ -1,6 +1,5 @@
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';
4
3
  import { findTenantOptions } from '../../queries/findTenantOptions.js';
5
4
  import { TenantSelectionProviderClient } from './index.client.js';
6
5
  export const TenantSelectionProvider = async ({ children, payload, tenantsCollectionSlug, useAsTitle, user })=>{
@@ -23,17 +22,20 @@ export const TenantSelectionProvider = async ({ children, payload, tenantsCollec
23
22
  const cookies = await getCookies();
24
23
  let tenantCookie = cookies.get('payload-tenant')?.value;
25
24
  let initialValue = undefined;
26
- if (tenantOptions.length > 1 && tenantCookie === SELECT_ALL) {
27
- initialValue = SELECT_ALL;
28
- } else {
25
+ /**
26
+ * Ensure the cookie is a valid tenant
27
+ */ if (tenantCookie) {
29
28
  const matchingOption = tenantOptions.find((option)=>String(option.value) === tenantCookie);
30
29
  if (matchingOption) {
31
30
  initialValue = matchingOption.value;
32
- } else {
33
- tenantCookie = undefined;
34
- initialValue = tenantOptions.length > 1 ? SELECT_ALL : tenantOptions[0]?.value;
35
31
  }
36
32
  }
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
+ }
37
39
  return /*#__PURE__*/ _jsx(TenantSelectionProviderClient, {
38
40
  initialValue: initialValue,
39
41
  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 { SELECT_ALL } from '../../constants.js'\nimport { findTenantOptions } from '../../queries/findTenantOptions.js'\nimport { TenantSelectionProviderClient } from './index.client.js'\n\ntype Args = {\n children: React.ReactNode\n payload: Payload\n tenantsCollectionSlug: string\n useAsTitle: string\n user: User\n}\n\nexport const TenantSelectionProvider = async ({\n children,\n payload,\n tenantsCollectionSlug,\n useAsTitle,\n user,\n}: Args) => {\n let tenantOptions: OptionObject[] = []\n\n try {\n const { docs } = await findTenantOptions({\n limit: 0,\n payload,\n tenantsCollectionSlug,\n useAsTitle,\n user,\n })\n tenantOptions = docs.map((doc) => ({\n label: String(doc[useAsTitle]),\n value: doc.id,\n }))\n } catch (_) {\n // user likely does not have access\n }\n\n const cookies = await getCookies()\n let tenantCookie = cookies.get('payload-tenant')?.value\n let initialValue = undefined\n\n if (tenantOptions.length > 1 && tenantCookie === SELECT_ALL) {\n initialValue = SELECT_ALL\n } else {\n const matchingOption = tenantOptions.find((option) => String(option.value) === tenantCookie)\n if (matchingOption) {\n initialValue = matchingOption.value\n } else {\n tenantCookie = undefined\n initialValue = tenantOptions.length > 1 ? SELECT_ALL : tenantOptions[0]?.value\n }\n }\n\n return (\n <TenantSelectionProviderClient\n initialValue={initialValue}\n tenantCookie={tenantCookie}\n tenantOptions={tenantOptions}\n >\n {children}\n </TenantSelectionProviderClient>\n )\n}\n"],"names":["cookies","getCookies","SELECT_ALL","findTenantOptions","TenantSelectionProviderClient","TenantSelectionProvider","children","payload","tenantsCollectionSlug","useAsTitle","user","tenantOptions","docs","limit","map","doc","label","String","value","id","_","tenantCookie","get","initialValue","undefined","length","matchingOption","find","option"],"mappings":";AAEA,SAASA,WAAWC,UAAU,QAAQ,kBAAiB;AAEvD,SAASC,UAAU,QAAQ,qBAAoB;AAC/C,SAASC,iBAAiB,QAAQ,qCAAoC;AACtE,SAASC,6BAA6B,QAAQ,oBAAmB;AAUjE,OAAO,MAAMC,0BAA0B,OAAO,EAC5CC,QAAQ,EACRC,OAAO,EACPC,qBAAqB,EACrBC,UAAU,EACVC,IAAI,EACC;IACL,IAAIC,gBAAgC,EAAE;IAEtC,IAAI;QACF,MAAM,EAAEC,IAAI,EAAE,GAAG,MAAMT,kBAAkB;YACvCU,OAAO;YACPN;YACAC;YACAC;YACAC;QACF;QACAC,gBAAgBC,KAAKE,GAAG,CAAC,CAACC,MAAS,CAAA;gBACjCC,OAAOC,OAAOF,GAAG,CAACN,WAAW;gBAC7BS,OAAOH,IAAII,EAAE;YACf,CAAA;IACF,EAAE,OAAOC,GAAG;IACV,mCAAmC;IACrC;IAEA,MAAMpB,UAAU,MAAMC;IACtB,IAAIoB,eAAerB,QAAQsB,GAAG,CAAC,mBAAmBJ;IAClD,IAAIK,eAAeC;IAEnB,IAAIb,cAAcc,MAAM,GAAG,KAAKJ,iBAAiBnB,YAAY;QAC3DqB,eAAerB;IACjB,OAAO;QACL,MAAMwB,iBAAiBf,cAAcgB,IAAI,CAAC,CAACC,SAAWX,OAAOW,OAAOV,KAAK,MAAMG;QAC/E,IAAIK,gBAAgB;YAClBH,eAAeG,eAAeR,KAAK;QACrC,OAAO;YACLG,eAAeG;YACfD,eAAeZ,cAAcc,MAAM,GAAG,IAAIvB,aAAaS,aAAa,CAAC,EAAE,EAAEO;QAC3E;IACF;IAEA,qBACE,KAACd;QACCmB,cAAcA;QACdF,cAAcA;QACdV,eAAeA;kBAEdL;;AAGP,EAAC"}
1
+ {"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 /**\n * Ensure the cookie is a valid tenant\n */\n if (tenantCookie) {\n const matchingOption = tenantOptions.find((option) => String(option.value) === tenantCookie)\n if (matchingOption) {\n initialValue = matchingOption.value\n }\n }\n\n /**\n * If the there was no cookie or the cookie was an invalid tenantID set intialValue\n */\n if (!initialValue) {\n tenantCookie = undefined\n initialValue = tenantOptions.length > 1 ? undefined : tenantOptions[0]?.value\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","findTenantOptions","TenantSelectionProviderClient","TenantSelectionProvider","children","payload","tenantsCollectionSlug","useAsTitle","user","tenantOptions","docs","limit","map","doc","label","String","value","id","_","tenantCookie","get","initialValue","undefined","matchingOption","find","option","length"],"mappings":";AAEA,SAASA,WAAWC,UAAU,QAAQ,kBAAiB;AAEvD,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,MAAMnB,UAAU,MAAMC;IACtB,IAAImB,eAAepB,QAAQqB,GAAG,CAAC,mBAAmBJ;IAClD,IAAIK,eAAeC;IAEnB;;GAEC,GACD,IAAIH,cAAc;QAChB,MAAMI,iBAAiBd,cAAce,IAAI,CAAC,CAACC,SAAWV,OAAOU,OAAOT,KAAK,MAAMG;QAC/E,IAAII,gBAAgB;YAClBF,eAAeE,eAAeP,KAAK;QACrC;IACF;IAEA;;GAEC,GACD,IAAI,CAACK,cAAc;QACjBF,eAAeG;QACfD,eAAeZ,cAAciB,MAAM,GAAG,IAAIJ,YAAYb,aAAa,CAAC,EAAE,EAAEO;IAC1E;IAEA,qBACE,KAACd;QACCmB,cAAcA;QACdF,cAAcA;QACdV,eAAeA;kBAEdL;;AAGP,EAAC"}
package/dist/types.d.ts CHANGED
@@ -1,6 +1,14 @@
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;
4
12
  /**
5
13
  * After a tenant is deleted, the plugin will attempt to clean up related documents
6
14
  * - removing documents with the tenant ID
@@ -108,7 +116,7 @@ export type MultiTenantPluginConfig<ConfigTypes = unknown> = {
108
116
  /**
109
117
  * Customize tenant selector label
110
118
  *
111
- * Either a string or an object where the keys are locales and the values are the string labels
119
+ * Either a string or an object where the keys are i18n codes and the values are the string labels
112
120
  */
113
121
  tenantSelectorLabel?: Partial<{
114
122
  [key in AcceptedLanguages]?: string;
@@ -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,KAA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,KAAK,CAAA;KAC1B,CAAA;IACL;;;;OAIG;IACH,mBAAmB,CAAC,EAChB,OAAO,CAAC;SACL,GAAG,IAAI,iBAAiB,CAAC,CAAC,EAAE,MAAM;KACpC,CAAC,GACF,MAAM,CAAA;IACV;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,yBAAyB,CAAC,EAAE,CAC1B,IAAI,EAAE,WAAW,SAAS;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,GAAG,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,KACrE,OAAO,CAAA;IACZ;;OAEG;IACH,0BAA0B,CAAC,EAAE,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 * 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
+ {"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 * Base path for your application\n *\n * https://nextjs.org/docs/app/api-reference/config/next-config-js/basePath\n *\n * @default undefined\n */\n basePath?: string\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 i18n codes 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":"AAiKA,WAMQ"}
@@ -1,5 +1,6 @@
1
1
  import type { Payload, User, ViewTypes } from 'payload';
2
2
  type Args = {
3
+ basePath?: string;
3
4
  docID?: number | string;
4
5
  headers: Headers;
5
6
  payload: Payload;
@@ -10,6 +11,6 @@ type Args = {
10
11
  user?: User;
11
12
  view: ViewTypes;
12
13
  };
13
- export declare function getGlobalViewRedirect({ slug, docID, headers, payload, tenantFieldName, tenantsCollectionSlug, useAsTitle, user, view, }: Args): Promise<string | void>;
14
+ export declare function getGlobalViewRedirect({ slug, basePath, docID, headers, payload, tenantFieldName, tenantsCollectionSlug, useAsTitle, user, view, }: Args): Promise<string | void>;
14
15
  export {};
15
16
  //# 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;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
+ {"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;AAQvD,KAAK,IAAI,GAAG;IACV,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,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,QAAQ,EACR,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,CAuE/B"}
@@ -1,15 +1,15 @@
1
- import { SELECT_ALL } from '../constants.js';
1
+ import { formatAdminURL } from 'payload/shared';
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, docID, headers, payload, tenantFieldName, tenantsCollectionSlug, useAsTitle, user, view }) {
5
+ export async function getGlobalViewRedirect({ slug, basePath, 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 || tenant === SELECT_ALL) {
11
+ let redirectRoute = undefined;
12
+ if (!tenant) {
13
13
  const tenantsQuery = await findTenantOptions({
14
14
  limit: 1,
15
15
  payload,
@@ -37,24 +37,32 @@ export async function getGlobalViewRedirect({ slug, docID, headers, payload, ten
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 = `${payload.config.routes.admin}/collections/${slug}/create`;
40
+ redirectRoute = `/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 = `${payload.config.routes.admin}/collections/${slug}/${tenantDocID}`;
43
+ redirectRoute = `/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 = `${payload.config.routes.admin}/collections/${slug}/${tenantDocID}`;
48
+ redirectRoute = `/collections/${slug}/${tenantDocID}`;
49
49
  } else {
50
50
  // tenant document does not exist, redirect to create route
51
- redirectRoute = `${payload.config.routes.admin}/collections/${slug}/create`;
51
+ redirectRoute = `/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
- return redirectRoute;
57
+ if (redirectRoute) {
58
+ return formatAdminURL({
59
+ adminRoute: payload.config.routes.admin,
60
+ basePath,
61
+ path: redirectRoute,
62
+ serverURL: payload.config.serverURL
63
+ });
64
+ }
65
+ return undefined;
58
66
  }
59
67
 
60
68
  //# sourceMappingURL=getGlobalViewRedirect.js.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"sources":["../../src/utilities/getGlobalViewRedirect.ts"],"sourcesContent":["import type { Payload, User, ViewTypes } from 'payload'\n\nimport { formatAdminURL } from 'payload/shared'\n\nimport { findTenantOptions } from '../queries/findTenantOptions.js'\nimport { getCollectionIDType } from './getCollectionIDType.js'\nimport { getTenantFromCookie } from './getTenantFromCookie.js'\n\ntype Args = {\n basePath?: string\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 basePath,\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: `/${string}` | void = undefined\n\n if (!tenant) {\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 = `/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 = `/collections/${slug}/${tenantDocID}`\n }\n } else if (view === 'list') {\n if (tenantDocID) {\n // tenant document exists, redirect to edit view\n redirectRoute = `/collections/${slug}/${tenantDocID}`\n } else {\n // tenant document does not exist, redirect to create route\n redirectRoute = `/collections/${slug}/create`\n }\n }\n } catch (e: unknown) {\n payload.logger.error(\n e,\n `${typeof e === 'object' && e && 'message' in e ? `e?.message - ` : ''}Multi Tenant Redirect Error`,\n )\n }\n\n if (redirectRoute) {\n return formatAdminURL({\n adminRoute: payload.config.routes.admin,\n basePath,\n path: redirectRoute,\n serverURL: payload.config.serverURL,\n })\n }\n\n return undefined\n}\n"],"names":["formatAdminURL","findTenantOptions","getCollectionIDType","getTenantFromCookie","getGlobalViewRedirect","slug","basePath","docID","headers","payload","tenantFieldName","tenantsCollectionSlug","useAsTitle","user","view","idType","collectionSlug","tenant","redirectRoute","undefined","tenantsQuery","limit","docs","id","find","collection","depth","overrideAccess","pagination","where","equals","tenantDocID","e","logger","error","adminRoute","config","routes","admin","path","serverURL"],"mappings":"AAEA,SAASA,cAAc,QAAQ,iBAAgB;AAE/C,SAASC,iBAAiB,QAAQ,kCAAiC;AACnE,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,mBAAmB,QAAQ,2BAA0B;AAc9D,OAAO,eAAeC,sBAAsB,EAC1CC,IAAI,EACJC,QAAQ,EACRC,KAAK,EACLC,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AI,CAAC,aAAa,CAAC,GAAG,GAAG,2BAA2B,CAAC;IAEvG;IAEA,IAAId,eAAe;QACjB,OAAOlB,eAAe;YACpBmC,YAAY1B,QAAQ2B,MAAM,CAACC,MAAM,CAACC,KAAK;YACvChC;YACAiC,MAAMrB;YACNsB,WAAW/B,QAAQ2B,MAAM,CAACI,SAAS;QACrC;IACF;IAEA,OAAOrB;AACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-multi-tenant",
3
- "version": "3.29.0-internal.d2c9ba5",
3
+ "version": "3.29.0-internal.e4e913b",
4
4
  "description": "Multi Tenant plugin for Payload",
5
5
  "keywords": [
6
6
  "payload",
@@ -66,15 +66,15 @@
66
66
  "types.d.ts"
67
67
  ],
68
68
  "devDependencies": {
69
- "@payloadcms/translations": "3.29.0-internal.d2c9ba5",
70
- "@payloadcms/ui": "3.29.0-internal.d2c9ba5",
71
- "payload": "3.29.0-internal.d2c9ba5",
72
- "@payloadcms/eslint-config": "3.28.0"
69
+ "@payloadcms/eslint-config": "3.28.0",
70
+ "@payloadcms/ui": "3.29.0-internal.e4e913b",
71
+ "@payloadcms/translations": "3.29.0-internal.e4e913b",
72
+ "payload": "3.29.0-internal.e4e913b"
73
73
  },
74
74
  "peerDependencies": {
75
75
  "next": "^15.0.3",
76
- "@payloadcms/ui": "3.29.0-internal.d2c9ba5",
77
- "payload": "3.29.0-internal.d2c9ba5"
76
+ "@payloadcms/ui": "3.29.0-internal.e4e913b",
77
+ "payload": "3.29.0-internal.e4e913b"
78
78
  },
79
79
  "homepage:": "https://payloadcms.com",
80
80
  "scripts": {
@@ -1,2 +0,0 @@
1
- export declare const SELECT_ALL = "_ALL_";
2
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,UAAU,UAAU,CAAA"}
package/dist/constants.js DELETED
@@ -1,4 +0,0 @@
1
- // The tenant cookie can be set to _ALL_ to allow users to see all results for tenants they are a member of.
2
- export const SELECT_ALL = '_ALL_';
3
-
4
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
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"}