@payloadcms/plugin-multi-tenant 3.92.1 → 3.94.0-internal.78c6d86

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.
@@ -1 +1 @@
1
- {"version":3,"file":"getGlobalViewRedirect.d.ts","sourceRoot":"","sources":["../../src/utilities/getGlobalViewRedirect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAK5D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAM1D,KAAK,IAAI,GAAG;IACV;;;;OAIG;IACH,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,2BAA2B,EAAE,MAAM,CAAA;IACnC,qBAAqB,EAAE,MAAM,CAAA;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,yBAAyB,EAAE,QAAQ,CAAC,uBAAuB,CAAC,GAAG,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAA;IAC9F,IAAI,EAAE,SAAS,CAAA;CAChB,CAAA;AACD,wBAAsB,qBAAqB,CAAC,EAC1C,IAAI,EAAE,cAAc,EACpB,KAAK,EACL,OAAO,EACP,OAAO,EACP,eAAe,EACf,qBAAqB,EACrB,2BAA2B,EAC3B,qBAAqB,EACrB,UAAU,EACV,IAAI,EACJ,yBAAyB,EACzB,IAAI,GACL,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAmG/B"}
1
+ {"version":3,"file":"getGlobalViewRedirect.d.ts","sourceRoot":"","sources":["../../src/utilities/getGlobalViewRedirect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAK5D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAM1D,KAAK,IAAI,GAAG;IACV;;;;OAIG;IACH,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,2BAA2B,EAAE,MAAM,CAAA;IACnC,qBAAqB,EAAE,MAAM,CAAA;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,yBAAyB,EAAE,QAAQ,CAAC,uBAAuB,CAAC,GAAG,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAA;IAC9F,IAAI,EAAE,SAAS,CAAA;CAChB,CAAA;AACD,wBAAsB,qBAAqB,CAAC,EAC1C,IAAI,EAAE,cAAc,EACpB,KAAK,EACL,OAAO,EACP,OAAO,EACP,eAAe,EACf,qBAAqB,EACrB,2BAA2B,EAC3B,qBAAqB,EACrB,UAAU,EACV,IAAI,EACJ,yBAAyB,EACzB,IAAI,GACL,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAyG/B"}
@@ -8,33 +8,33 @@ export async function getGlobalViewRedirect({ slug: collectionSlug, docID, heade
8
8
  collectionSlug: tenantsCollectionSlug,
9
9
  payload
10
10
  });
11
- let tenant = getTenantFromCookie(headers, idType);
11
+ const selectedTenant = getTenantFromCookie(headers, idType);
12
12
  let redirectRoute = undefined;
13
13
  if (!user) {
14
14
  return unauthorized();
15
15
  }
16
- if (!tenant) {
17
- const tenantOptions = await getTenantOptions({
18
- payload,
19
- tenantsArrayFieldName,
20
- tenantsArrayTenantFieldName,
21
- tenantsCollectionSlug,
22
- useAsTitle,
23
- user,
24
- userHasAccessToAllTenants
25
- });
26
- tenant = tenantOptions[0]?.value || null;
27
- }
16
+ const tenantOptions = await getTenantOptions({
17
+ payload,
18
+ tenantsArrayFieldName,
19
+ tenantsArrayTenantFieldName,
20
+ tenantsCollectionSlug,
21
+ useAsTitle,
22
+ user,
23
+ userHasAccessToAllTenants
24
+ });
25
+ const tenant = tenantOptions.find(({ value })=>String(value) === String(selectedTenant))?.value || tenantOptions[0]?.value || null;
28
26
  if (tenant) {
29
27
  try {
30
28
  const globalTenantDocQuery = await payload.find({
31
29
  collection: collectionSlug,
32
30
  depth: 0,
33
31
  limit: 1,
32
+ overrideAccess: false,
34
33
  pagination: false,
35
34
  select: {
36
35
  id: true
37
36
  },
37
+ user,
38
38
  where: {
39
39
  [tenantFieldName]: {
40
40
  in: [
@@ -56,7 +56,9 @@ export async function getGlobalViewRedirect({ slug: collectionSlug, docID, heade
56
56
  redirectRoute = await generateCreateRedirect({
57
57
  collectionSlug,
58
58
  payload,
59
- tenantID: tenant
59
+ tenantFieldName,
60
+ tenantID: tenant,
61
+ user
60
62
  });
61
63
  }
62
64
  } else if (view === 'list') {
@@ -70,7 +72,9 @@ export async function getGlobalViewRedirect({ slug: collectionSlug, docID, heade
70
72
  redirectRoute = await generateCreateRedirect({
71
73
  collectionSlug,
72
74
  payload,
73
- tenantID: tenant
75
+ tenantFieldName,
76
+ tenantID: tenant,
77
+ user
74
78
  });
75
79
  }
76
80
  }
@@ -102,7 +106,7 @@ export async function getGlobalViewRedirect({ slug: collectionSlug, docID, heade
102
106
  *
103
107
  * If autosave is enabled on the collection, we need to create the document and then redirect to it.
104
108
  * Otherwise we can redirect to the default create route.
105
- */ async function generateCreateRedirect({ collectionSlug, payload, tenantID }) {
109
+ */ async function generateCreateRedirect({ collectionSlug, payload, tenantFieldName, tenantID, user }) {
106
110
  const collectionConfig = payload.collections[collectionSlug]?.config;
107
111
  if (hasAutosaveEnabled(collectionConfig)) {
108
112
  // Autosave is enabled, create a document first
@@ -110,13 +114,15 @@ export async function getGlobalViewRedirect({ slug: collectionSlug, docID, heade
110
114
  const doc = await payload.create({
111
115
  collection: collectionSlug,
112
116
  data: {
113
- tenant: tenantID
117
+ [tenantFieldName]: tenantID
114
118
  },
115
119
  depth: 0,
116
120
  draft: true,
121
+ overrideAccess: false,
117
122
  select: {
118
123
  id: true
119
- }
124
+ },
125
+ user
120
126
  });
121
127
  return `/collections/${collectionSlug}/${doc.id}`;
122
128
  } catch (error) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/getGlobalViewRedirect.ts"],"sourcesContent":["import type { Payload, TypedUser, ViewTypes } from 'payload'\n\nimport { unauthorized } from 'next/navigation.js'\nimport { formatAdminURL, hasAutosaveEnabled } from 'payload/shared'\n\nimport type { MultiTenantPluginConfig } from '../types.js'\n\nimport { getCollectionIDType } from './getCollectionIDType.js'\nimport { getTenantFromCookie } from './getTenantFromCookie.js'\nimport { getTenantOptions } from './getTenantOptions.js'\n\ntype Args = {\n /**\n * This is no longer needed and is handled internally.\n *\n * @deprecated\n */\n basePath?: string\n docID?: number | string\n headers: Headers\n payload: Payload\n slug: string\n tenantFieldName: string\n tenantsArrayFieldName: string\n tenantsArrayTenantFieldName: string\n tenantsCollectionSlug: string\n useAsTitle: string\n user?: TypedUser\n userHasAccessToAllTenants: Required<MultiTenantPluginConfig<any>>['userHasAccessToAllTenants']\n view: ViewTypes\n}\nexport async function getGlobalViewRedirect({\n slug: collectionSlug,\n docID,\n headers,\n payload,\n tenantFieldName,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n useAsTitle,\n user,\n userHasAccessToAllTenants,\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 (!user) {\n return unauthorized()\n }\n\n if (!tenant) {\n const tenantOptions = await getTenantOptions({\n payload,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n useAsTitle,\n user,\n userHasAccessToAllTenants,\n })\n\n tenant = tenantOptions[0]?.value || null\n }\n\n if (tenant) {\n try {\n const globalTenantDocQuery = await payload.find({\n collection: collectionSlug,\n depth: 0,\n limit: 1,\n pagination: false,\n select: {\n id: true,\n },\n where: {\n [tenantFieldName]: {\n in: [tenant],\n },\n },\n })\n\n const globalTenantDocID = globalTenantDocQuery?.docs?.[0]?.id\n\n if (view === 'document') {\n // global tenant document edit view\n if (globalTenantDocID && docID !== globalTenantDocID) {\n // tenant document already exists but does not match current route docID\n // redirect to matching tenant docID from query\n redirectRoute = `/collections/${collectionSlug}/${globalTenantDocID}`\n } else if (docID && !globalTenantDocID) {\n // a docID was found in the route but no global document with this tenant exists\n // so we need to generate a redirect to the create route\n redirectRoute = await generateCreateRedirect({\n collectionSlug,\n payload,\n tenantID: tenant,\n })\n }\n } else if (view === 'list') {\n // global tenant document list view\n if (globalTenantDocID) {\n // tenant document exists, redirect from list view to the document edit view\n redirectRoute = `/collections/${collectionSlug}/${globalTenantDocID}`\n } else {\n // no matching document was found for the current tenant\n // so we need to generate a redirect to the create route\n redirectRoute = await generateCreateRedirect({\n collectionSlug,\n payload,\n tenantID: tenant,\n })\n }\n }\n } catch (e: unknown) {\n const prefix = `${e && typeof e === 'object' && 'message' in e && typeof e.message === 'string' ? `${e.message} - ` : ''}`\n payload.logger.error(e, `${prefix}Multi Tenant Redirect Error`)\n }\n } else {\n // no tenants were found, redirect to the admin view\n return formatAdminURL({\n adminRoute: payload.config.routes.admin,\n path: '',\n serverURL: payload.config.serverURL,\n })\n }\n\n if (redirectRoute) {\n return formatAdminURL({\n adminRoute: payload.config.routes.admin,\n path: redirectRoute,\n serverURL: payload.config.serverURL,\n })\n }\n\n // no redirect is needed\n // the current route is valid\n return undefined\n}\n\ntype GenerateCreateArgs = {\n collectionSlug: string\n payload: Payload\n tenantID: number | string\n}\n/**\n * Generate a redirect URL for creating a new document in a multi-tenant collection.\n *\n * If autosave is enabled on the collection, we need to create the document and then redirect to it.\n * Otherwise we can redirect to the default create route.\n */\nasync function generateCreateRedirect({\n collectionSlug,\n payload,\n tenantID,\n}: GenerateCreateArgs): Promise<`/${string}` | undefined> {\n const collectionConfig = payload.collections[collectionSlug]?.config\n if (hasAutosaveEnabled(collectionConfig!)) {\n // Autosave is enabled, create a document first\n try {\n const doc = await payload.create({\n collection: collectionSlug,\n data: {\n tenant: tenantID,\n },\n depth: 0,\n draft: true,\n select: {\n id: true,\n },\n })\n return `/collections/${collectionSlug}/${doc.id}`\n } catch (error) {\n payload.logger.error(\n error,\n `Error creating autosave global multi tenant document for ${collectionSlug}`,\n )\n }\n\n return '/'\n }\n\n // Autosave is not enabled, redirect to default create route\n return `/collections/${collectionSlug}/create`\n}\n"],"names":["unauthorized","formatAdminURL","hasAutosaveEnabled","getCollectionIDType","getTenantFromCookie","getTenantOptions","getGlobalViewRedirect","slug","collectionSlug","docID","headers","payload","tenantFieldName","tenantsArrayFieldName","tenantsArrayTenantFieldName","tenantsCollectionSlug","useAsTitle","user","userHasAccessToAllTenants","view","idType","tenant","redirectRoute","undefined","tenantOptions","value","globalTenantDocQuery","find","collection","depth","limit","pagination","select","id","where","in","globalTenantDocID","docs","generateCreateRedirect","tenantID","e","prefix","message","logger","error","adminRoute","config","routes","admin","path","serverURL","collectionConfig","collections","doc","create","data","draft"],"mappings":"AAEA,SAASA,YAAY,QAAQ,qBAAoB;AACjD,SAASC,cAAc,EAAEC,kBAAkB,QAAQ,iBAAgB;AAInE,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,gBAAgB,QAAQ,wBAAuB;AAsBxD,OAAO,eAAeC,sBAAsB,EAC1CC,MAAM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Aa,EAAEzB,eAAe,CAAC,EAAE6C,IAAIpB,EAAE,EAAE;QACnD,EAAE,OAAOW,OAAO;YACdjC,QAAQgC,MAAM,CAACC,KAAK,CAClBA,OACA,CAAC,yDAAyD,EAAEpC,gBAAgB;QAEhF;QAEA,OAAO;IACT;IAEA,4DAA4D;IAC5D,OAAO,CAAC,aAAa,EAAEA,eAAe,OAAO,CAAC;AAChD"}
1
+ {"version":3,"sources":["../../src/utilities/getGlobalViewRedirect.ts"],"sourcesContent":["import type { Payload, TypedUser, ViewTypes } from 'payload'\n\nimport { unauthorized } from 'next/navigation.js'\nimport { formatAdminURL, hasAutosaveEnabled } from 'payload/shared'\n\nimport type { MultiTenantPluginConfig } from '../types.js'\n\nimport { getCollectionIDType } from './getCollectionIDType.js'\nimport { getTenantFromCookie } from './getTenantFromCookie.js'\nimport { getTenantOptions } from './getTenantOptions.js'\n\ntype Args = {\n /**\n * This is no longer needed and is handled internally.\n *\n * @deprecated\n */\n basePath?: string\n docID?: number | string\n headers: Headers\n payload: Payload\n slug: string\n tenantFieldName: string\n tenantsArrayFieldName: string\n tenantsArrayTenantFieldName: string\n tenantsCollectionSlug: string\n useAsTitle: string\n user?: TypedUser\n userHasAccessToAllTenants: Required<MultiTenantPluginConfig<any>>['userHasAccessToAllTenants']\n view: ViewTypes\n}\nexport async function getGlobalViewRedirect({\n slug: collectionSlug,\n docID,\n headers,\n payload,\n tenantFieldName,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n useAsTitle,\n user,\n userHasAccessToAllTenants,\n view,\n}: Args): Promise<string | void> {\n const idType = getCollectionIDType({\n collectionSlug: tenantsCollectionSlug,\n payload,\n })\n const selectedTenant = getTenantFromCookie(headers, idType)\n let redirectRoute: `/${string}` | void = undefined\n\n if (!user) {\n return unauthorized()\n }\n\n const tenantOptions = await getTenantOptions({\n payload,\n tenantsArrayFieldName,\n tenantsArrayTenantFieldName,\n tenantsCollectionSlug,\n useAsTitle,\n user,\n userHasAccessToAllTenants,\n })\n const tenant =\n tenantOptions.find(({ value }) => String(value) === String(selectedTenant))?.value ||\n tenantOptions[0]?.value ||\n null\n\n if (tenant) {\n try {\n const globalTenantDocQuery = await payload.find({\n collection: collectionSlug,\n depth: 0,\n limit: 1,\n overrideAccess: false,\n pagination: false,\n select: {\n id: true,\n },\n user,\n where: {\n [tenantFieldName]: {\n in: [tenant],\n },\n },\n })\n\n const globalTenantDocID = globalTenantDocQuery?.docs?.[0]?.id\n\n if (view === 'document') {\n // global tenant document edit view\n if (globalTenantDocID && docID !== globalTenantDocID) {\n // tenant document already exists but does not match current route docID\n // redirect to matching tenant docID from query\n redirectRoute = `/collections/${collectionSlug}/${globalTenantDocID}`\n } else if (docID && !globalTenantDocID) {\n // a docID was found in the route but no global document with this tenant exists\n // so we need to generate a redirect to the create route\n redirectRoute = await generateCreateRedirect({\n collectionSlug,\n payload,\n tenantFieldName,\n tenantID: tenant,\n user,\n })\n }\n } else if (view === 'list') {\n // global tenant document list view\n if (globalTenantDocID) {\n // tenant document exists, redirect from list view to the document edit view\n redirectRoute = `/collections/${collectionSlug}/${globalTenantDocID}`\n } else {\n // no matching document was found for the current tenant\n // so we need to generate a redirect to the create route\n redirectRoute = await generateCreateRedirect({\n collectionSlug,\n payload,\n tenantFieldName,\n tenantID: tenant,\n user,\n })\n }\n }\n } catch (e: unknown) {\n const prefix = `${e && typeof e === 'object' && 'message' in e && typeof e.message === 'string' ? `${e.message} - ` : ''}`\n payload.logger.error(e, `${prefix}Multi Tenant Redirect Error`)\n }\n } else {\n // no tenants were found, redirect to the admin view\n return formatAdminURL({\n adminRoute: payload.config.routes.admin,\n path: '',\n serverURL: payload.config.serverURL,\n })\n }\n\n if (redirectRoute) {\n return formatAdminURL({\n adminRoute: payload.config.routes.admin,\n path: redirectRoute,\n serverURL: payload.config.serverURL,\n })\n }\n\n // no redirect is needed\n // the current route is valid\n return undefined\n}\n\ntype GenerateCreateArgs = {\n collectionSlug: string\n payload: Payload\n tenantFieldName: string\n tenantID: number | string\n user: TypedUser\n}\n/**\n * Generate a redirect URL for creating a new document in a multi-tenant collection.\n *\n * If autosave is enabled on the collection, we need to create the document and then redirect to it.\n * Otherwise we can redirect to the default create route.\n */\nasync function generateCreateRedirect({\n collectionSlug,\n payload,\n tenantFieldName,\n tenantID,\n user,\n}: GenerateCreateArgs): Promise<`/${string}` | undefined> {\n const collectionConfig = payload.collections[collectionSlug]?.config\n if (hasAutosaveEnabled(collectionConfig!)) {\n // Autosave is enabled, create a document first\n try {\n const doc = await payload.create({\n collection: collectionSlug,\n data: {\n [tenantFieldName]: tenantID,\n },\n depth: 0,\n draft: true,\n overrideAccess: false,\n select: {\n id: true,\n },\n user,\n })\n return `/collections/${collectionSlug}/${doc.id}`\n } catch (error) {\n payload.logger.error(\n error,\n `Error creating autosave global multi tenant document for ${collectionSlug}`,\n )\n }\n\n return '/'\n }\n\n // Autosave is not enabled, redirect to default create route\n return `/collections/${collectionSlug}/create`\n}\n"],"names":["unauthorized","formatAdminURL","hasAutosaveEnabled","getCollectionIDType","getTenantFromCookie","getTenantOptions","getGlobalViewRedirect","slug","collectionSlug","docID","headers","payload","tenantFieldName","tenantsArrayFieldName","tenantsArrayTenantFieldName","tenantsCollectionSlug","useAsTitle","user","userHasAccessToAllTenants","view","idType","selectedTenant","redirectRoute","undefined","tenantOptions","tenant","find","value","String","globalTenantDocQuery","collection","depth","limit","overrideAccess","pagination","select","id","where","in","globalTenantDocID","docs","generateCreateRedirect","tenantID","e","prefix","message","logger","error","adminRoute","config","routes","admin","path","serverURL","collectionConfig","collections","doc","create","data","draft"],"mappings":"AAEA,SAASA,YAAY,QAAQ,qBAAoB;AACjD,SAASC,cAAc,EAAEC,kBAAkB,QAAQ,iBAAgB;AAInE,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,gBAAgB,QAAQ,wBAAuB;AAsBxD,OAAO,eAAeC,sBAAsB,EAC1C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8C,MAAM,CAAC;gBAC/B3B,YAAYtB;gBACZkD,MAAM;oBACJ,CAAC9C,gBAAgB,EAAE8B;gBACrB;gBACAX,OAAO;gBACP4B,OAAO;gBACP1B,gBAAgB;gBAChBE,QAAQ;oBACNC,IAAI;gBACN;gBACAnB;YACF;YACA,OAAO,CAAC,aAAa,EAAET,eAAe,CAAC,EAAEgD,IAAIpB,EAAE,EAAE;QACnD,EAAE,OAAOW,OAAO;YACdpC,QAAQmC,MAAM,CAACC,KAAK,CAClBA,OACA,CAAC,yDAAyD,EAAEvC,gBAAgB;QAEhF;QAEA,OAAO;IACT;IAEA,4DAA4D;IAC5D,OAAO,CAAC,aAAa,EAAEA,eAAe,OAAO,CAAC;AAChD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-multi-tenant",
3
- "version": "3.92.1",
3
+ "version": "3.94.0-internal.78c6d86",
4
4
  "description": "Multi Tenant plugin for Payload",
5
5
  "keywords": [
6
6
  "payload",
@@ -81,13 +81,13 @@
81
81
  ],
82
82
  "devDependencies": {
83
83
  "@payloadcms/eslint-config": "3.28.0",
84
- "@payloadcms/translations": "3.92.1",
85
- "@payloadcms/ui": "3.92.1",
86
- "payload": "3.92.1"
84
+ "@payloadcms/translations": "3.94.0-internal.78c6d86",
85
+ "@payloadcms/ui": "3.94.0-internal.78c6d86",
86
+ "payload": "3.94.0-internal.78c6d86"
87
87
  },
88
88
  "peerDependencies": {
89
- "@payloadcms/ui": "3.92.1",
90
- "payload": "3.92.1"
89
+ "@payloadcms/ui": "3.94.0-internal.78c6d86",
90
+ "payload": "3.94.0-internal.78c6d86"
91
91
  },
92
92
  "homepage:": "https://payloadcms.com",
93
93
  "scripts": {