@payloadcms/next 3.0.0-beta.120 → 3.0.0-beta.121
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/prod/styles.css +1 -1
- package/dist/routes/rest/collections/create.d.ts.map +1 -1
- package/dist/routes/rest/collections/create.js +3 -1
- package/dist/routes/rest/collections/create.js.map +1 -1
- package/dist/routes/rest/collections/delete.d.ts.map +1 -1
- package/dist/routes/rest/collections/delete.js +3 -0
- package/dist/routes/rest/collections/delete.js.map +1 -1
- package/dist/routes/rest/collections/deleteByID.d.ts.map +1 -1
- package/dist/routes/rest/collections/deleteByID.js +3 -1
- package/dist/routes/rest/collections/deleteByID.js.map +1 -1
- package/dist/routes/rest/collections/duplicate.d.ts.map +1 -1
- package/dist/routes/rest/collections/duplicate.js +3 -1
- package/dist/routes/rest/collections/duplicate.js.map +1 -1
- package/dist/routes/rest/collections/find.d.ts.map +1 -1
- package/dist/routes/rest/collections/find.js +3 -0
- package/dist/routes/rest/collections/find.js.map +1 -1
- package/dist/routes/rest/collections/findByID.d.ts.map +1 -1
- package/dist/routes/rest/collections/findByID.js +3 -1
- package/dist/routes/rest/collections/findByID.js.map +1 -1
- package/dist/routes/rest/collections/findVersionByID.d.ts.map +1 -1
- package/dist/routes/rest/collections/findVersionByID.js +3 -1
- package/dist/routes/rest/collections/findVersionByID.js.map +1 -1
- package/dist/routes/rest/collections/findVersions.d.ts.map +1 -1
- package/dist/routes/rest/collections/findVersions.js +3 -0
- package/dist/routes/rest/collections/findVersions.js.map +1 -1
- package/dist/routes/rest/collections/update.d.ts.map +1 -1
- package/dist/routes/rest/collections/update.js +3 -0
- package/dist/routes/rest/collections/update.js.map +1 -1
- package/dist/routes/rest/collections/updateByID.d.ts.map +1 -1
- package/dist/routes/rest/collections/updateByID.js +3 -1
- package/dist/routes/rest/collections/updateByID.js.map +1 -1
- package/dist/routes/rest/globals/findOne.d.ts.map +1 -1
- package/dist/routes/rest/globals/findOne.js +3 -1
- package/dist/routes/rest/globals/findOne.js.map +1 -1
- package/dist/routes/rest/globals/findVersionByID.d.ts.map +1 -1
- package/dist/routes/rest/globals/findVersionByID.js +3 -1
- package/dist/routes/rest/globals/findVersionByID.js.map +1 -1
- package/dist/routes/rest/globals/findVersions.d.ts.map +1 -1
- package/dist/routes/rest/globals/findVersions.js +3 -0
- package/dist/routes/rest/globals/findVersions.js.map +1 -1
- package/dist/routes/rest/globals/update.d.ts.map +1 -1
- package/dist/routes/rest/globals/update.js +3 -1
- package/dist/routes/rest/globals/update.js.map +1 -1
- package/dist/routes/rest/utilities/sanitizeSelect.d.ts +6 -0
- package/dist/routes/rest/utilities/sanitizeSelect.d.ts.map +1 -0
- package/dist/routes/rest/utilities/sanitizeSelect.js +17 -0
- package/dist/routes/rest/utilities/sanitizeSelect.js.map +1 -0
- package/dist/utilities/initPage/index.d.ts.map +1 -1
- package/dist/utilities/initPage/index.js +5 -0
- package/dist/utilities/initPage/index.js.map +1 -1
- package/dist/utilities/initPage/isCustomAdminView.d.ts +10 -0
- package/dist/utilities/initPage/isCustomAdminView.d.ts.map +1 -0
- package/dist/utilities/initPage/isCustomAdminView.js +31 -0
- package/dist/utilities/initPage/isCustomAdminView.js.map +1 -0
- package/dist/utilities/initPage/shared.d.ts.map +1 -1
- package/dist/utilities/initPage/shared.js +2 -1
- package/dist/utilities/initPage/shared.js.map +1 -1
- package/dist/views/Document/getViewsFromConfig.d.ts.map +1 -1
- package/dist/views/Document/getViewsFromConfig.js +6 -0
- package/dist/views/Document/getViewsFromConfig.js.map +1 -1
- package/dist/views/Edit/Default/Auth/APIKey.d.ts.map +1 -1
- package/dist/views/Edit/Default/Auth/APIKey.js +2 -8
- package/dist/views/Edit/Default/Auth/APIKey.js.map +1 -1
- package/dist/views/Edit/Default/Auth/index.d.ts.map +1 -1
- package/dist/views/Edit/Default/Auth/index.js +37 -26
- package/dist/views/Edit/Default/Auth/index.js.map +1 -1
- package/dist/views/NotFound/index.d.ts.map +1 -1
- package/dist/views/NotFound/index.js +3 -0
- package/dist/views/NotFound/index.js.map +1 -1
- package/dist/views/Root/index.d.ts.map +1 -1
- package/dist/views/Root/index.js +14 -6
- package/dist/views/Root/index.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/update.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/update.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAKrD,eAAO,MAAM,MAAM,EAAE,kBAyCpB,CAAA"}
|
|
@@ -2,6 +2,7 @@ import httpStatus from 'http-status';
|
|
|
2
2
|
import { updateOperationGlobal } from 'payload';
|
|
3
3
|
import { isNumber } from 'payload/shared';
|
|
4
4
|
import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
5
|
+
import { sanitizeSelect } from '../utilities/sanitizeSelect.js';
|
|
5
6
|
export const update = async ({
|
|
6
7
|
globalConfig,
|
|
7
8
|
req
|
|
@@ -21,7 +22,8 @@ export const update = async ({
|
|
|
21
22
|
draft,
|
|
22
23
|
globalConfig,
|
|
23
24
|
publishSpecificLocale,
|
|
24
|
-
req
|
|
25
|
+
req,
|
|
26
|
+
select: sanitizeSelect(req.query.select)
|
|
25
27
|
});
|
|
26
28
|
let message = req.t('general:updatedSuccessfully');
|
|
27
29
|
if (draft) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","names":["httpStatus","updateOperationGlobal","isNumber","headersWithCors","update","globalConfig","req","searchParams","depth","get","draft","autosave","publishSpecificLocale","query","result","slug","data","Number","undefined","message","t","Response","json","headers","Headers","status","OK"],"sources":["../../../../src/routes/rest/globals/update.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { updateOperationGlobal } from 'payload'\nimport { isNumber } from 'payload/shared'\n\nimport type { GlobalRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const update: GlobalRouteHandler = async ({ globalConfig, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n const draft = searchParams.get('draft') === 'true'\n const autosave = searchParams.get('autosave') === 'true'\n const publishSpecificLocale = req.query.publishSpecificLocale as string | undefined\n\n const result = await updateOperationGlobal({\n slug: globalConfig.slug,\n autosave,\n data: req.data,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft,\n globalConfig,\n publishSpecificLocale,\n req,\n })\n\n let message = req.t('general:updatedSuccessfully')\n\n if (draft) {\n message = req.t('version:draftSavedSuccessfully')\n }\n if (autosave) {\n message = req.t('version:autosavedSuccessfully')\n }\n\n return Response.json(\n {\n message,\n result,\n },\n {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"mappings":"AAAA,OAAOA,UAAA,MAAgB;AACvB,SAASC,qBAAqB,QAAQ;AACtC,SAASC,QAAQ,QAAQ;AAIzB,SAASC,eAAe,QAAQ;
|
|
1
|
+
{"version":3,"file":"update.js","names":["httpStatus","updateOperationGlobal","isNumber","headersWithCors","sanitizeSelect","update","globalConfig","req","searchParams","depth","get","draft","autosave","publishSpecificLocale","query","result","slug","data","Number","undefined","select","message","t","Response","json","headers","Headers","status","OK"],"sources":["../../../../src/routes/rest/globals/update.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { updateOperationGlobal } from 'payload'\nimport { isNumber } from 'payload/shared'\n\nimport type { GlobalRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\nimport { sanitizeSelect } from '../utilities/sanitizeSelect.js'\n\nexport const update: GlobalRouteHandler = async ({ globalConfig, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n const draft = searchParams.get('draft') === 'true'\n const autosave = searchParams.get('autosave') === 'true'\n const publishSpecificLocale = req.query.publishSpecificLocale as string | undefined\n\n const result = await updateOperationGlobal({\n slug: globalConfig.slug,\n autosave,\n data: req.data,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft,\n globalConfig,\n publishSpecificLocale,\n req,\n select: sanitizeSelect(req.query.select),\n })\n\n let message = req.t('general:updatedSuccessfully')\n\n if (draft) {\n message = req.t('version:draftSavedSuccessfully')\n }\n if (autosave) {\n message = req.t('version:autosavedSuccessfully')\n }\n\n return Response.json(\n {\n message,\n result,\n },\n {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"mappings":"AAAA,OAAOA,UAAA,MAAgB;AACvB,SAASC,qBAAqB,QAAQ;AACtC,SAASC,QAAQ,QAAQ;AAIzB,SAASC,eAAe,QAAQ;AAChC,SAASC,cAAc,QAAQ;AAE/B,OAAO,MAAMC,MAAA,GAA6B,MAAAA,CAAO;EAAEC,YAAY;EAAEC;AAAG,CAAE;EACpE,MAAM;IAAEC;EAAY,CAAE,GAAGD,GAAA;EACzB,MAAME,KAAA,GAAQD,YAAA,CAAaE,GAAG,CAAC;EAC/B,MAAMC,KAAA,GAAQH,YAAA,CAAaE,GAAG,CAAC,aAAa;EAC5C,MAAME,QAAA,GAAWJ,YAAA,CAAaE,GAAG,CAAC,gBAAgB;EAClD,MAAMG,qBAAA,GAAwBN,GAAA,CAAIO,KAAK,CAACD,qBAAqB;EAE7D,MAAME,MAAA,GAAS,MAAMd,qBAAA,CAAsB;IACzCe,IAAA,EAAMV,YAAA,CAAaU,IAAI;IACvBJ,QAAA;IACAK,IAAA,EAAMV,GAAA,CAAIU,IAAI;IACdR,KAAA,EAAOP,QAAA,CAASO,KAAA,IAASS,MAAA,CAAOT,KAAA,IAASU,SAAA;IACzCR,KAAA;IACAL,YAAA;IACAO,qBAAA;IACAN,GAAA;IACAa,MAAA,EAAQhB,cAAA,CAAeG,GAAA,CAAIO,KAAK,CAACM,MAAM;EACzC;EAEA,IAAIC,OAAA,GAAUd,GAAA,CAAIe,CAAC,CAAC;EAEpB,IAAIX,KAAA,EAAO;IACTU,OAAA,GAAUd,GAAA,CAAIe,CAAC,CAAC;EAClB;EACA,IAAIV,QAAA,EAAU;IACZS,OAAA,GAAUd,GAAA,CAAIe,CAAC,CAAC;EAClB;EAEA,OAAOC,QAAA,CAASC,IAAI,CAClB;IACEH,OAAA;IACAN;EACF,GACA;IACEU,OAAA,EAAStB,eAAA,CAAgB;MACvBsB,OAAA,EAAS,IAAIC,OAAA;MACbnB;IACF;IACAoB,MAAA,EAAQ3B,UAAA,CAAW4B;EACrB;AAEJ","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizeSelect.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/utilities/sanitizeSelect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC;;GAEG;AACH,eAAO,MAAM,cAAc,sBAAuB,OAAO,KAAG,UAAU,GAAG,SAcxE,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sanitizes REST select query to SelectType
|
|
3
|
+
*/export const sanitizeSelect = unsanitizedSelect => {
|
|
4
|
+
if (unsanitizedSelect && typeof unsanitizedSelect === 'object') {
|
|
5
|
+
for (const k in unsanitizedSelect) {
|
|
6
|
+
if (unsanitizedSelect[k] === 'true') {
|
|
7
|
+
unsanitizedSelect[k] = true;
|
|
8
|
+
} else if (unsanitizedSelect[k] === 'false') {
|
|
9
|
+
unsanitizedSelect[k] = false;
|
|
10
|
+
} else if (typeof unsanitizedSelect[k] === 'object') {
|
|
11
|
+
sanitizeSelect(unsanitizedSelect[k]);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return unsanitizedSelect;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=sanitizeSelect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizeSelect.js","names":["sanitizeSelect","unsanitizedSelect","k"],"sources":["../../../../src/routes/rest/utilities/sanitizeSelect.ts"],"sourcesContent":["import type { SelectType } from 'payload'\n\n/**\n * Sanitizes REST select query to SelectType\n */\nexport const sanitizeSelect = (unsanitizedSelect: unknown): SelectType | undefined => {\n if (unsanitizedSelect && typeof unsanitizedSelect === 'object') {\n for (const k in unsanitizedSelect) {\n if (unsanitizedSelect[k] === 'true') {\n unsanitizedSelect[k] = true\n } else if (unsanitizedSelect[k] === 'false') {\n unsanitizedSelect[k] = false\n } else if (typeof unsanitizedSelect[k] === 'object') {\n sanitizeSelect(unsanitizedSelect[k])\n }\n }\n }\n\n return unsanitizedSelect as SelectType\n}\n"],"mappings":"AAEA;;GAGA,OAAO,MAAMA,cAAA,GAAkBC,iBAAA;EAC7B,IAAIA,iBAAA,IAAqB,OAAOA,iBAAA,KAAsB,UAAU;IAC9D,KAAK,MAAMC,CAAA,IAAKD,iBAAA,EAAmB;MACjC,IAAIA,iBAAiB,CAACC,CAAA,CAAE,KAAK,QAAQ;QACnCD,iBAAiB,CAACC,CAAA,CAAE,GAAG;MACzB,OAAO,IAAID,iBAAiB,CAACC,CAAA,CAAE,KAAK,SAAS;QAC3CD,iBAAiB,CAACC,CAAA,CAAE,GAAG;MACzB,OAAO,IAAI,OAAOD,iBAAiB,CAACC,CAAA,CAAE,KAAK,UAAU;QACnDF,cAAA,CAAeC,iBAAiB,CAACC,CAAA,CAAE;MACrC;IACF;EACF;EAEA,OAAOD,iBAAA;AACT","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utilities/initPage/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAA2C,MAAM,SAAS,CAAA;AAQtF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utilities/initPage/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAA2C,MAAM,SAAS,CAAA;AAQtF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAStC,eAAO,MAAM,QAAQ,+DAKlB,IAAI,KAAG,OAAO,CAAC,cAAc,CAqJ/B,CAAA"}
|
|
@@ -7,6 +7,7 @@ import { getPayloadHMR } from '../getPayloadHMR.js';
|
|
|
7
7
|
import { initReq } from '../initReq.js';
|
|
8
8
|
import { getRouteInfo } from './handleAdminPage.js';
|
|
9
9
|
import { handleAuthRedirect } from './handleAuthRedirect.js';
|
|
10
|
+
import { isCustomAdminView } from './isCustomAdminView.js';
|
|
10
11
|
import { isPublicAdminRoute } from './shared.js';
|
|
11
12
|
export const initPage = async ({
|
|
12
13
|
config: configPromise,
|
|
@@ -124,6 +125,10 @@ export const initPage = async ({
|
|
|
124
125
|
adminRoute,
|
|
125
126
|
config: payload.config,
|
|
126
127
|
route
|
|
128
|
+
}) && !isCustomAdminView({
|
|
129
|
+
adminRoute,
|
|
130
|
+
config: payload.config,
|
|
131
|
+
route
|
|
127
132
|
})) {
|
|
128
133
|
redirectTo = handleAuthRedirect({
|
|
129
134
|
config: payload.config,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["findLocaleFromCode","headers","getHeaders","notFound","createLocalReq","isEntityHidden","parseCookies","qs","getPayloadHMR","initReq","getRouteInfo","handleAuthRedirect","isPublicAdminRoute","initPage","config","configPromise","importMap","route","searchParams","payload","queryString","stringify","addQueryPrefix","collections","globals","localization","routes","admin","adminRoute","cookies","i18n","permissions","user","req","fallbackLocale","host","get","query","parse","depth","ignoreQueryPrefix","url","serverURL","languageOptions","Object","entries","supportedLanguages","reduce","acc","language","languageConfig","keys","includes","push","label","translations","general","thisLanguage","value","localeParam","locale","defaultLocaleCode","defaultLocale","localeCode","find","collection","limit","where","and","equals","id","key","then","res","docs","error","code","visibleEntities","map","slug","hidden","filter","Boolean","redirectTo","canAccessAdmin","collectionConfig","collectionSlug","docID","globalConfig","globalSlug","defaultIDType","db"],"sources":["../../../src/utilities/initPage/index.ts"],"sourcesContent":["import type { InitPageResult, Locale, PayloadRequest, VisibleEntities } from 'payload'\n\nimport { findLocaleFromCode } from '@payloadcms/ui/shared'\nimport { headers as getHeaders } from 'next/headers.js'\nimport { notFound } from 'next/navigation.js'\nimport { createLocalReq, isEntityHidden, parseCookies } from 'payload'\nimport * as qs from 'qs-esm'\n\nimport type { Args } from './types.js'\n\nimport { getPayloadHMR } from '../getPayloadHMR.js'\nimport { initReq } from '../initReq.js'\nimport { getRouteInfo } from './handleAdminPage.js'\nimport { handleAuthRedirect } from './handleAuthRedirect.js'\nimport { isPublicAdminRoute } from './shared.js'\n\nexport const initPage = async ({\n config: configPromise,\n importMap,\n route,\n searchParams,\n}: Args): Promise<InitPageResult> => {\n const headers = await getHeaders()\n const payload = await getPayloadHMR({ config: configPromise, importMap })\n const queryString = `${qs.stringify(searchParams ?? {}, { addQueryPrefix: true })}`\n\n const {\n collections,\n globals,\n localization,\n routes: { admin: adminRoute },\n } = payload.config\n\n const cookies = parseCookies(headers)\n\n const { i18n, permissions, user } = await initReq(payload.config)\n\n // Ideally, we should not need to recreate the req, because\n // we can get it from the above initReq.\n\n // We just need to -overwrite- the url and query of the req\n // we get above. Clone the req? We'll look into that eventually.\n const req = await createLocalReq(\n {\n fallbackLocale: null,\n req: {\n headers,\n host: headers.get('host'),\n i18n,\n query: qs.parse(queryString, {\n depth: 10,\n ignoreQueryPrefix: true,\n }),\n url: `${payload.config.serverURL}${route}${searchParams ? queryString : ''}`,\n } as PayloadRequest,\n },\n payload,\n )\n\n const languageOptions = Object.entries(payload.config.i18n.supportedLanguages || {}).reduce(\n (acc, [language, languageConfig]) => {\n if (Object.keys(payload.config.i18n.supportedLanguages).includes(language)) {\n acc.push({\n label: languageConfig.translations.general.thisLanguage,\n value: language,\n })\n }\n\n return acc\n },\n [],\n )\n\n req.user = user\n\n const localeParam = searchParams?.locale as string\n let locale: Locale\n\n if (localization) {\n const defaultLocaleCode = localization.defaultLocale ? localization.defaultLocale : 'en'\n let localeCode: string = localeParam\n\n if (!localeCode) {\n try {\n localeCode = await payload\n .find({\n collection: 'payload-preferences',\n depth: 0,\n limit: 1,\n user,\n where: {\n and: [\n {\n 'user.relationTo': {\n equals: payload.config.admin.user,\n },\n },\n {\n 'user.value': {\n equals: user.id,\n },\n },\n {\n key: {\n equals: 'locale',\n },\n },\n ],\n },\n })\n ?.then((res) => res.docs?.[0]?.value as string)\n } catch (error) {} // eslint-disable-line no-empty\n }\n\n locale = findLocaleFromCode(localization, localeCode)\n\n if (!locale) {\n locale = findLocaleFromCode(localization, defaultLocaleCode)\n }\n req.locale = locale.code\n }\n\n const visibleEntities: VisibleEntities = {\n collections: collections\n .map(({ slug, admin: { hidden } }) => (!isEntityHidden({ hidden, user }) ? slug : null))\n .filter(Boolean),\n globals: globals\n .map(({ slug, admin: { hidden } }) => (!isEntityHidden({ hidden, user }) ? slug : null))\n .filter(Boolean),\n }\n\n let redirectTo = null\n\n if (\n !permissions.canAccessAdmin &&\n !isPublicAdminRoute({ adminRoute, config: payload.config, route })\n ) {\n redirectTo = handleAuthRedirect({\n config: payload.config,\n route,\n searchParams,\n user,\n })\n }\n\n const { collectionConfig, collectionSlug, docID, globalConfig, globalSlug } = getRouteInfo({\n adminRoute,\n config: payload.config,\n defaultIDType: payload.db.defaultIDType,\n route,\n })\n\n if ((collectionSlug && !collectionConfig) || (globalSlug && !globalConfig)) {\n return notFound()\n }\n\n return {\n collectionConfig,\n cookies,\n docID,\n globalConfig,\n languageOptions,\n locale,\n permissions,\n redirectTo,\n req,\n translations: i18n.translations,\n visibleEntities,\n }\n}\n"],"mappings":"AAEA,SAASA,kBAAkB,QAAQ;AACnC,SAASC,OAAA,IAAWC,UAAU,QAAQ;AACtC,SAASC,QAAQ,QAAQ;AACzB,SAASC,cAAc,EAAEC,cAAc,EAAEC,YAAY,QAAQ;AAC7D,YAAYC,EAAA,MAAQ;AAIpB,SAASC,aAAa,QAAQ;AAC9B,SAASC,OAAO,QAAQ;AACxB,SAASC,YAAY,QAAQ;AAC7B,SAASC,kBAAkB,QAAQ;AACnC,SAASC,kBAAkB,QAAQ;AAEnC,OAAO,MAAMC,QAAA,GAAW,MAAAA,CAAO;EAC7BC,MAAA,EAAQC,aAAa;EACrBC,SAAS;EACTC,KAAK;EACLC;AAAY,CACP;EACL,
|
|
1
|
+
{"version":3,"file":"index.js","names":["findLocaleFromCode","headers","getHeaders","notFound","createLocalReq","isEntityHidden","parseCookies","qs","getPayloadHMR","initReq","getRouteInfo","handleAuthRedirect","isCustomAdminView","isPublicAdminRoute","initPage","config","configPromise","importMap","route","searchParams","payload","queryString","stringify","addQueryPrefix","collections","globals","localization","routes","admin","adminRoute","cookies","i18n","permissions","user","req","fallbackLocale","host","get","query","parse","depth","ignoreQueryPrefix","url","serverURL","languageOptions","Object","entries","supportedLanguages","reduce","acc","language","languageConfig","keys","includes","push","label","translations","general","thisLanguage","value","localeParam","locale","defaultLocaleCode","defaultLocale","localeCode","find","collection","limit","where","and","equals","id","key","then","res","docs","error","code","visibleEntities","map","slug","hidden","filter","Boolean","redirectTo","canAccessAdmin","collectionConfig","collectionSlug","docID","globalConfig","globalSlug","defaultIDType","db"],"sources":["../../../src/utilities/initPage/index.ts"],"sourcesContent":["import type { InitPageResult, Locale, PayloadRequest, VisibleEntities } from 'payload'\n\nimport { findLocaleFromCode } from '@payloadcms/ui/shared'\nimport { headers as getHeaders } from 'next/headers.js'\nimport { notFound } from 'next/navigation.js'\nimport { createLocalReq, isEntityHidden, parseCookies } from 'payload'\nimport * as qs from 'qs-esm'\n\nimport type { Args } from './types.js'\n\nimport { getPayloadHMR } from '../getPayloadHMR.js'\nimport { initReq } from '../initReq.js'\nimport { getRouteInfo } from './handleAdminPage.js'\nimport { handleAuthRedirect } from './handleAuthRedirect.js'\nimport { isCustomAdminView } from './isCustomAdminView.js'\nimport { isPublicAdminRoute } from './shared.js'\n\nexport const initPage = async ({\n config: configPromise,\n importMap,\n route,\n searchParams,\n}: Args): Promise<InitPageResult> => {\n const headers = await getHeaders()\n const payload = await getPayloadHMR({ config: configPromise, importMap })\n const queryString = `${qs.stringify(searchParams ?? {}, { addQueryPrefix: true })}`\n\n const {\n collections,\n globals,\n localization,\n routes: { admin: adminRoute },\n } = payload.config\n\n const cookies = parseCookies(headers)\n\n const { i18n, permissions, user } = await initReq(payload.config)\n\n // Ideally, we should not need to recreate the req, because\n // we can get it from the above initReq.\n\n // We just need to -overwrite- the url and query of the req\n // we get above. Clone the req? We'll look into that eventually.\n const req = await createLocalReq(\n {\n fallbackLocale: null,\n req: {\n headers,\n host: headers.get('host'),\n i18n,\n query: qs.parse(queryString, {\n depth: 10,\n ignoreQueryPrefix: true,\n }),\n url: `${payload.config.serverURL}${route}${searchParams ? queryString : ''}`,\n } as PayloadRequest,\n },\n payload,\n )\n\n const languageOptions = Object.entries(payload.config.i18n.supportedLanguages || {}).reduce(\n (acc, [language, languageConfig]) => {\n if (Object.keys(payload.config.i18n.supportedLanguages).includes(language)) {\n acc.push({\n label: languageConfig.translations.general.thisLanguage,\n value: language,\n })\n }\n\n return acc\n },\n [],\n )\n\n req.user = user\n\n const localeParam = searchParams?.locale as string\n let locale: Locale\n\n if (localization) {\n const defaultLocaleCode = localization.defaultLocale ? localization.defaultLocale : 'en'\n let localeCode: string = localeParam\n\n if (!localeCode) {\n try {\n localeCode = await payload\n .find({\n collection: 'payload-preferences',\n depth: 0,\n limit: 1,\n user,\n where: {\n and: [\n {\n 'user.relationTo': {\n equals: payload.config.admin.user,\n },\n },\n {\n 'user.value': {\n equals: user.id,\n },\n },\n {\n key: {\n equals: 'locale',\n },\n },\n ],\n },\n })\n ?.then((res) => res.docs?.[0]?.value as string)\n } catch (error) {} // eslint-disable-line no-empty\n }\n\n locale = findLocaleFromCode(localization, localeCode)\n\n if (!locale) {\n locale = findLocaleFromCode(localization, defaultLocaleCode)\n }\n req.locale = locale.code\n }\n\n const visibleEntities: VisibleEntities = {\n collections: collections\n .map(({ slug, admin: { hidden } }) => (!isEntityHidden({ hidden, user }) ? slug : null))\n .filter(Boolean),\n globals: globals\n .map(({ slug, admin: { hidden } }) => (!isEntityHidden({ hidden, user }) ? slug : null))\n .filter(Boolean),\n }\n\n let redirectTo = null\n\n if (\n !permissions.canAccessAdmin &&\n !isPublicAdminRoute({ adminRoute, config: payload.config, route }) &&\n !isCustomAdminView({ adminRoute, config: payload.config, route })\n ) {\n redirectTo = handleAuthRedirect({\n config: payload.config,\n route,\n searchParams,\n user,\n })\n }\n\n const { collectionConfig, collectionSlug, docID, globalConfig, globalSlug } = getRouteInfo({\n adminRoute,\n config: payload.config,\n defaultIDType: payload.db.defaultIDType,\n route,\n })\n\n if ((collectionSlug && !collectionConfig) || (globalSlug && !globalConfig)) {\n return notFound()\n }\n\n return {\n collectionConfig,\n cookies,\n docID,\n globalConfig,\n languageOptions,\n locale,\n permissions,\n redirectTo,\n req,\n translations: i18n.translations,\n visibleEntities,\n }\n}\n"],"mappings":"AAEA,SAASA,kBAAkB,QAAQ;AACnC,SAASC,OAAA,IAAWC,UAAU,QAAQ;AACtC,SAASC,QAAQ,QAAQ;AACzB,SAASC,cAAc,EAAEC,cAAc,EAAEC,YAAY,QAAQ;AAC7D,YAAYC,EAAA,MAAQ;AAIpB,SAASC,aAAa,QAAQ;AAC9B,SAASC,OAAO,QAAQ;AACxB,SAASC,YAAY,QAAQ;AAC7B,SAASC,kBAAkB,QAAQ;AACnC,SAASC,iBAAiB,QAAQ;AAClC,SAASC,kBAAkB,QAAQ;AAEnC,OAAO,MAAMC,QAAA,GAAW,MAAAA,CAAO;EAC7BC,MAAA,EAAQC,aAAa;EACrBC,SAAS;EACTC,KAAK;EACLC;AAAY,CACP;EACL,MAAMlB,OAAA,GAAU,MAAMC,UAAA;E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ACAlD,GAAA;IACAsB,YAAA,EAAczB,IAAA,CAAKyB,YAAY;IAC/BsB;EACF;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SanitizedConfig } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Returns an array of views marked with 'public: true' in the config
|
|
4
|
+
*/
|
|
5
|
+
export declare const isCustomAdminView: ({ adminRoute, config, route, }: {
|
|
6
|
+
adminRoute: string;
|
|
7
|
+
config: SanitizedConfig;
|
|
8
|
+
route: string;
|
|
9
|
+
}) => boolean;
|
|
10
|
+
//# sourceMappingURL=isCustomAdminView.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isCustomAdminView.d.ts","sourceRoot":"","sources":["../../../src/utilities/initPage/isCustomAdminView.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmC,eAAe,EAAE,MAAM,SAAS,CAAA;AAI/E;;GAEG;AACH,eAAO,MAAM,iBAAiB,mCAI3B;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,eAAe,CAAA;IACvB,KAAK,EAAE,MAAM,CAAA;CACd,KAAG,OAmBH,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getRouteWithoutAdmin } from './shared.js';
|
|
2
|
+
/**
|
|
3
|
+
* Returns an array of views marked with 'public: true' in the config
|
|
4
|
+
*/
|
|
5
|
+
export const isCustomAdminView = ({
|
|
6
|
+
adminRoute,
|
|
7
|
+
config,
|
|
8
|
+
route
|
|
9
|
+
}) => {
|
|
10
|
+
if (config.admin?.components?.views) {
|
|
11
|
+
const isPublicAdminRoute = Object.entries(config.admin.components.views).some(([_, view]) => {
|
|
12
|
+
const routeWithoutAdmin = getRouteWithoutAdmin({
|
|
13
|
+
adminRoute,
|
|
14
|
+
route
|
|
15
|
+
});
|
|
16
|
+
if (view.exact) {
|
|
17
|
+
if (routeWithoutAdmin === view.path) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
} else {
|
|
21
|
+
if (routeWithoutAdmin.startsWith(view.path)) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
});
|
|
27
|
+
return isPublicAdminRoute;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=isCustomAdminView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isCustomAdminView.js","names":["getRouteWithoutAdmin","isCustomAdminView","adminRoute","config","route","admin","components","views","isPublicAdminRoute","Object","entries","some","_","view","routeWithoutAdmin","exact","path","startsWith"],"sources":["../../../src/utilities/initPage/isCustomAdminView.ts"],"sourcesContent":["import type { AdminViewConfig, PayloadRequest, SanitizedConfig } from 'payload'\n\nimport { getRouteWithoutAdmin } from './shared.js'\n\n/**\n * Returns an array of views marked with 'public: true' in the config\n */\nexport const isCustomAdminView = ({\n adminRoute,\n config,\n route,\n}: {\n adminRoute: string\n config: SanitizedConfig\n route: string\n}): boolean => {\n if (config.admin?.components?.views) {\n const isPublicAdminRoute = Object.entries(config.admin.components.views).some(([_, view]) => {\n const routeWithoutAdmin = getRouteWithoutAdmin({ adminRoute, route })\n\n if (view.exact) {\n if (routeWithoutAdmin === view.path) {\n return true\n }\n } else {\n if (routeWithoutAdmin.startsWith(view.path)) {\n return true\n }\n }\n return false\n })\n return isPublicAdminRoute\n }\n return false\n}\n"],"mappings":"AAEA,SAASA,oBAAoB,QAAQ;AAErC;;;AAGA,OAAO,MAAMC,iBAAA,GAAoBA,CAAC;EAChCC,UAAU;EACVC,MAAM;EACNC;AAAK,CAKN;EACC,IAAID,MAAA,CAAOE,KAAK,EAAEC,UAAA,EAAYC,KAAA,EAAO;IACnC,MAAMC,kBAAA,GAAqBC,MAAA,CAAOC,OAAO,CAACP,MAAA,CAAOE,KAAK,CAACC,UAAU,CAACC,KAAK,EAAEI,IAAI,CAAC,CAAC,CAACC,CAAA,EAAGC,IAAA,CAAK;MACtF,MAAMC,iBAAA,GAAoBd,oBAAA,CAAqB;QAAEE,UAAA;QAAYE;MAAM;MAEnE,IAAIS,IAAA,CAAKE,KAAK,EAAE;QACd,IAAID,iBAAA,KAAsBD,IAAA,CAAKG,IAAI,EAAE;UACnC,OAAO;QACT;MACF,OAAO;QACL,IAAIF,iBAAA,CAAkBG,UAAU,CAACJ,IAAA,CAAKG,IAAI,GAAG;UAC3C,OAAO;QACT;MACF;MACA,OAAO;IACT;IACA,OAAOR,kBAAA;EACT;EACA,OAAO;AACT","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/utilities/initPage/shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAiB9C,eAAO,MAAM,YAAY,2BAGtB;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,eAAe,CAAA;IACvB,KAAK,EAAE,MAAM,CAAA;CACd,KAAG,OAEH,CAAA;AAED,eAAO,MAAM,kBAAkB,mCAI5B;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,eAAe,CAAA;IACvB,KAAK,EAAE,MAAM,CAAA;CACd,KAAG,
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/utilities/initPage/shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAiB9C,eAAO,MAAM,YAAY,2BAGtB;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,eAAe,CAAA;IACvB,KAAK,EAAE,MAAM,CAAA;CACd,KAAG,OAEH,CAAA;AAED,eAAO,MAAM,kBAAkB,mCAI5B;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,eAAe,CAAA;IACvB,KAAK,EAAE,MAAM,CAAA;CACd,KAAG,OAeH,CAAA;AAED,eAAO,MAAM,oBAAoB,2BAG9B;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;CACd,KAAG,MAEH,CAAA"}
|
|
@@ -11,7 +11,7 @@ export const isPublicAdminRoute = ({
|
|
|
11
11
|
config,
|
|
12
12
|
route
|
|
13
13
|
}) => {
|
|
14
|
-
|
|
14
|
+
const isPublicAdminRoute = publicAdminRoutes.some(routeSegment => {
|
|
15
15
|
const segment = config.admin?.routes?.[routeSegment] || routeSegment;
|
|
16
16
|
const routeWithoutAdmin = getRouteWithoutAdmin({
|
|
17
17
|
adminRoute,
|
|
@@ -25,6 +25,7 @@ export const isPublicAdminRoute = ({
|
|
|
25
25
|
return false;
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
|
+
return isPublicAdminRoute;
|
|
28
29
|
};
|
|
29
30
|
export const getRouteWithoutAdmin = ({
|
|
30
31
|
adminRoute,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","names":["publicAdminRoutes","isAdminRoute","adminRoute","route","startsWith","isPublicAdminRoute","config","some","routeSegment","segment","admin","routes","routeWithoutAdmin","getRouteWithoutAdmin","includes","replace"],"sources":["../../../src/utilities/initPage/shared.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload'\n\n// Routes that require admin authentication\nconst publicAdminRoutes: (keyof Pick<\n SanitizedConfig['admin']['routes'],\n 'createFirstUser' | 'forgot' | 'inactivity' | 'login' | 'logout' | 'reset' | 'unauthorized'\n>)[] = [\n 'createFirstUser',\n 'forgot',\n 'login',\n 'logout',\n 'forgot',\n 'inactivity',\n 'unauthorized',\n 'reset',\n]\n\nexport const isAdminRoute = ({\n adminRoute,\n route,\n}: {\n adminRoute: string\n config: SanitizedConfig\n route: string\n}): boolean => {\n return route.startsWith(adminRoute)\n}\n\nexport const isPublicAdminRoute = ({\n adminRoute,\n config,\n route,\n}: {\n adminRoute: string\n config: SanitizedConfig\n route: string\n}): boolean => {\n
|
|
1
|
+
{"version":3,"file":"shared.js","names":["publicAdminRoutes","isAdminRoute","adminRoute","route","startsWith","isPublicAdminRoute","config","some","routeSegment","segment","admin","routes","routeWithoutAdmin","getRouteWithoutAdmin","includes","replace"],"sources":["../../../src/utilities/initPage/shared.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload'\n\n// Routes that require admin authentication\nconst publicAdminRoutes: (keyof Pick<\n SanitizedConfig['admin']['routes'],\n 'createFirstUser' | 'forgot' | 'inactivity' | 'login' | 'logout' | 'reset' | 'unauthorized'\n>)[] = [\n 'createFirstUser',\n 'forgot',\n 'login',\n 'logout',\n 'forgot',\n 'inactivity',\n 'unauthorized',\n 'reset',\n]\n\nexport const isAdminRoute = ({\n adminRoute,\n route,\n}: {\n adminRoute: string\n config: SanitizedConfig\n route: string\n}): boolean => {\n return route.startsWith(adminRoute)\n}\n\nexport const isPublicAdminRoute = ({\n adminRoute,\n config,\n route,\n}: {\n adminRoute: string\n config: SanitizedConfig\n route: string\n}): boolean => {\n const isPublicAdminRoute = publicAdminRoutes.some((routeSegment) => {\n const segment = config.admin?.routes?.[routeSegment] || routeSegment\n const routeWithoutAdmin = getRouteWithoutAdmin({ adminRoute, route })\n\n if (routeWithoutAdmin.startsWith(segment)) {\n return true\n } else if (routeWithoutAdmin.includes('/verify/')) {\n return true\n } else {\n return false\n }\n })\n\n return isPublicAdminRoute\n}\n\nexport const getRouteWithoutAdmin = ({\n adminRoute,\n route,\n}: {\n adminRoute: string\n route: string\n}): string => {\n return adminRoute && adminRoute !== '/' ? route.replace(adminRoute, '') : route\n}\n"],"mappings":"AAEA;AACA,MAAMA,iBAAA,GAGC,CACL,mBACA,UACA,SACA,UACA,UACA,cACA,gBACA,QACD;AAED,OAAO,MAAMC,YAAA,GAAeA,CAAC;EAC3BC,UAAU;EACVC;AAAK,CAKN;EACC,OAAOA,KAAA,CAAMC,UAAU,CAACF,UAAA;AAC1B;AAEA,OAAO,MAAMG,kBAAA,GAAqBA,CAAC;EACjCH,UAAU;EACVI,MAAM;EACNH;AAAK,CAKN;EACC,MAAME,kBAAA,GAAqBL,iBAAA,CAAkBO,IAAI,CAAEC,YAAA;IACjD,MAAMC,OAAA,GAAUH,MAAA,CAAOI,KAAK,EAAEC,MAAA,GAASH,YAAA,CAAa,IAAIA,YAAA;IACxD,MAAMI,iBAAA,GAAoBC,oBAAA,CAAqB;MAAEX,UAAA;MAAYC;IAAM;IAEnE,IAAIS,iBAAA,CAAkBR,UAAU,CAACK,OAAA,GAAU;MACzC,OAAO;IACT,OAAO,IAAIG,iBAAA,CAAkBE,QAAQ,CAAC,aAAa;MACjD,OAAO;IACT,OAAO;MACL,OAAO;IACT;EACF;EAEA,OAAOT,kBAAA;AACT;AAEA,OAAO,MAAMQ,oBAAA,GAAuBA,CAAC;EACnCX,UAAU;EACVC;AAAK,CAIN;EACC,OAAOD,UAAA,IAAcA,UAAA,KAAe,MAAMC,KAAA,CAAMY,OAAO,CAACb,UAAA,EAAY,MAAMC,KAAA;AAC5E","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getViewsFromConfig.d.ts","sourceRoot":"","sources":["../../../src/views/Document/getViewsFromConfig.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,yBAAyB,EACzB,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAa9B,MAAM,MAAM,cAAc,CAAC,MAAM,SAAS,MAAM,IAAI;IAClD,SAAS,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,CAAA;IAC5B,gBAAgB,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAA;CAC5C,CAAA;AAED,eAAO,MAAM,kBAAkB,uGAO5B;IACD,gBAAgB,CAAC,EAAE,yBAAyB,CAAA;IAC5C,MAAM,EAAE,eAAe,CAAA;IACvB,YAAY,CAAC,EAAE,qBAAqB,CAAA;IACpC,aAAa,EAAE,MAAM,EAAE,CAAA;CACxB,GAAG,CACA;IACE,cAAc,EAAE,oBAAoB,GAAG,gBAAgB,CAAA;IACvD,sBAAsB,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;CAC3C,GACD;IACE,cAAc,CAAC,EAAE,KAAK,CAAA;IACtB,sBAAsB,EAAE,IAAI,CAAA;CAC7B,CACJ,KAAG;IACF,UAAU,EAAE,cAAc,CAAC,uBAAuB,CAAC,CAAA;IACnD,WAAW,EAAE,cAAc,CAAC,uBAAuB,CAAC,CAAA;IACpD;;OAEG;IACH,SAAS,EAAE,cAAc,CAAC,cAAc,CAAC,CAAA;IACzC,OAAO,EAAE,MAAM,CAAA;CAChB,GAAG,
|
|
1
|
+
{"version":3,"file":"getViewsFromConfig.d.ts","sourceRoot":"","sources":["../../../src/views/Document/getViewsFromConfig.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,yBAAyB,EACzB,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAa9B,MAAM,MAAM,cAAc,CAAC,MAAM,SAAS,MAAM,IAAI;IAClD,SAAS,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,CAAA;IAC5B,gBAAgB,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAA;CAC5C,CAAA;AAED,eAAO,MAAM,kBAAkB,uGAO5B;IACD,gBAAgB,CAAC,EAAE,yBAAyB,CAAA;IAC5C,MAAM,EAAE,eAAe,CAAA;IACvB,YAAY,CAAC,EAAE,qBAAqB,CAAA;IACpC,aAAa,EAAE,MAAM,EAAE,CAAA;CACxB,GAAG,CACA;IACE,cAAc,EAAE,oBAAoB,GAAG,gBAAgB,CAAA;IACvD,sBAAsB,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;CAC3C,GACD;IACE,cAAc,CAAC,EAAE,KAAK,CAAA;IACtB,sBAAsB,EAAE,IAAI,CAAA;CAC7B,CACJ,KAAG;IACF,UAAU,EAAE,cAAc,CAAC,uBAAuB,CAAC,CAAA;IACnD,WAAW,EAAE,cAAc,CAAC,uBAAuB,CAAC,CAAA;IACpD;;OAEG;IACH,SAAS,EAAE,cAAc,CAAC,cAAc,CAAC,CAAA;IACzC,OAAO,EAAE,MAAM,CAAA;CAChB,GAAG,IA0XH,CAAA"}
|
|
@@ -105,6 +105,9 @@ export const getViewsFromConfig = ({
|
|
|
105
105
|
DefaultView = {
|
|
106
106
|
Component: DefaultLivePreviewView
|
|
107
107
|
};
|
|
108
|
+
CustomView = {
|
|
109
|
+
payloadComponent: getCustomViewByKey(views, 'livePreview')
|
|
110
|
+
};
|
|
108
111
|
}
|
|
109
112
|
break;
|
|
110
113
|
}
|
|
@@ -224,6 +227,9 @@ export const getViewsFromConfig = ({
|
|
|
224
227
|
DefaultView = {
|
|
225
228
|
Component: DefaultLivePreviewView
|
|
226
229
|
};
|
|
230
|
+
CustomView = {
|
|
231
|
+
payloadComponent: getCustomViewByKey(views, 'livePreview')
|
|
232
|
+
};
|
|
227
233
|
}
|
|
228
234
|
break;
|
|
229
235
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getViewsFromConfig.js","names":["notFound","APIView","DefaultAPIView","EditView","DefaultEditView","LivePreviewView","DefaultLivePreviewView","UnauthorizedView","VersionView","DefaultVersionView","VersionsView","DefaultVersionsView","getCustomViewByKey","getCustomViewByRoute","getViewsFromConfig","collectionConfig","config","docPermissions","globalConfig","overrideDocPermissions","routeSegments","DefaultView","CustomView","ErrorView","viewKey","routes","admin","adminRoute","views","components","livePreviewEnabled","livePreview","collections","includes","slug","globals","collectionEntity","collectionSlug","segment3","segment4","segment5","remainingSegments","read","permission","length","create","payloadComponent","Component","baseRoute","filter","Boolean","join","currentRoute","CustomViewComponent","customViewKey","hideAPIURL","readVersions","globalEntity","globalSlug"],"sources":["../../../src/views/Document/getViewsFromConfig.tsx"],"sourcesContent":["import type {\n AdminViewProps,\n CollectionPermission,\n GlobalPermission,\n PayloadComponent,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SanitizedGlobalConfig,\n ServerSideEditViewProps,\n} from 'payload'\nimport type React from 'react'\n\nimport { notFound } from 'next/navigation.js'\n\nimport { APIView as DefaultAPIView } from '../API/index.js'\nimport { EditView as DefaultEditView } from '../Edit/index.js'\nimport { LivePreviewView as DefaultLivePreviewView } from '../LivePreview/index.js'\nimport { UnauthorizedView } from '../Unauthorized/index.js'\nimport { VersionView as DefaultVersionView } from '../Version/index.js'\nimport { VersionsView as DefaultVersionsView } from '../Versions/index.js'\nimport { getCustomViewByKey } from './getCustomViewByKey.js'\nimport { getCustomViewByRoute } from './getCustomViewByRoute.js'\n\nexport type ViewFromConfig<TProps extends object> = {\n Component?: React.FC<TProps>\n payloadComponent?: PayloadComponent<TProps>\n}\n\nexport const getViewsFromConfig = ({\n collectionConfig,\n config,\n docPermissions,\n globalConfig,\n overrideDocPermissions,\n routeSegments,\n}: {\n collectionConfig?: SanitizedCollectionConfig\n config: SanitizedConfig\n globalConfig?: SanitizedGlobalConfig\n routeSegments: string[]\n} & (\n | {\n docPermissions: CollectionPermission | GlobalPermission\n overrideDocPermissions?: false | undefined\n }\n | {\n docPermissions?: never\n overrideDocPermissions: true\n }\n)): {\n CustomView: ViewFromConfig<ServerSideEditViewProps>\n DefaultView: ViewFromConfig<ServerSideEditViewProps>\n /**\n * The error view to display if CustomView or DefaultView do not exist (could be either due to not found, or unauthorized). Can be null\n */\n ErrorView: ViewFromConfig<AdminViewProps>\n viewKey: string\n} | null => {\n // Conditionally import and lazy load the default view\n let DefaultView: ViewFromConfig<ServerSideEditViewProps> = null\n let CustomView: ViewFromConfig<ServerSideEditViewProps> = null\n let ErrorView: ViewFromConfig<AdminViewProps> = null\n let viewKey: string\n\n const {\n routes: { admin: adminRoute },\n } = config\n\n const views =\n (collectionConfig && collectionConfig?.admin?.components?.views) ||\n (globalConfig && globalConfig?.admin?.components?.views)\n\n const livePreviewEnabled =\n (collectionConfig && collectionConfig?.admin?.livePreview) ||\n config?.admin?.livePreview?.collections?.includes(collectionConfig?.slug) ||\n (globalConfig && globalConfig?.admin?.livePreview) ||\n config?.admin?.livePreview?.globals?.includes(globalConfig?.slug)\n\n if (collectionConfig) {\n const [collectionEntity, collectionSlug, segment3, segment4, segment5, ...remainingSegments] =\n routeSegments\n\n if (!overrideDocPermissions && !docPermissions?.read?.permission) {\n notFound()\n } else {\n // `../:id`, or `../create`\n switch (routeSegments.length) {\n case 3: {\n switch (segment3) {\n case 'create': {\n if (\n !overrideDocPermissions &&\n 'create' in docPermissions &&\n docPermissions?.create?.permission\n ) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'default'),\n }\n DefaultView = {\n Component: DefaultEditView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n break\n }\n\n default: {\n const baseRoute = [\n adminRoute !== '/' && adminRoute,\n 'collections',\n collectionSlug,\n segment3,\n ]\n .filter(Boolean)\n .join('/')\n\n const currentRoute = [baseRoute, segment4, segment5, ...remainingSegments]\n .filter(Boolean)\n .join('/')\n\n const { Component: CustomViewComponent, viewKey: customViewKey } =\n getCustomViewByRoute({\n baseRoute,\n currentRoute,\n views,\n })\n\n if (customViewKey) {\n viewKey = customViewKey\n\n CustomView = {\n payloadComponent: CustomViewComponent,\n }\n } else {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'default'),\n }\n\n DefaultView = {\n Component: DefaultEditView,\n }\n }\n\n break\n }\n }\n break\n }\n\n // `../:id/api`, `../:id/preview`, `../:id/versions`, etc\n case 4: {\n switch (segment4) {\n case 'api': {\n if (collectionConfig?.admin?.hideAPIURL !== true) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'api'),\n }\n DefaultView = {\n Component: DefaultAPIView,\n }\n }\n break\n }\n\n case 'preview': {\n if (livePreviewEnabled) {\n DefaultView = {\n Component: DefaultLivePreviewView,\n }\n }\n break\n }\n\n case 'versions': {\n if (!overrideDocPermissions && docPermissions?.readVersions?.permission) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'versions'),\n }\n DefaultView = {\n Component: DefaultVersionsView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n break\n }\n\n default: {\n const baseRoute = [\n adminRoute !== '/' && adminRoute,\n 'collections',\n collectionSlug,\n segment3,\n ]\n .filter(Boolean)\n .join('/')\n\n const currentRoute = [baseRoute, segment4, segment5, ...remainingSegments]\n .filter(Boolean)\n .join('/')\n\n const { Component: CustomViewComponent, viewKey: customViewKey } =\n getCustomViewByRoute({\n baseRoute,\n currentRoute,\n views,\n })\n\n if (customViewKey) {\n viewKey = customViewKey\n\n CustomView = {\n payloadComponent: CustomViewComponent,\n }\n }\n\n break\n }\n }\n break\n }\n\n // `../:id/versions/:version`, etc\n default: {\n if (segment4 === 'versions') {\n if (!overrideDocPermissions && docPermissions?.readVersions?.permission) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'version'),\n }\n DefaultView = {\n Component: DefaultVersionView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n } else {\n const baseRoute = [\n adminRoute !== '/' && adminRoute,\n collectionEntity,\n collectionSlug,\n segment3,\n ]\n .filter(Boolean)\n .join('/')\n\n const currentRoute = [baseRoute, segment4, segment5, ...remainingSegments]\n .filter(Boolean)\n .join('/')\n\n const { Component: CustomViewComponent, viewKey: customViewKey } = getCustomViewByRoute(\n {\n baseRoute,\n currentRoute,\n views,\n },\n )\n\n if (customViewKey) {\n viewKey = customViewKey\n\n CustomView = {\n payloadComponent: CustomViewComponent,\n }\n }\n }\n\n break\n }\n }\n }\n }\n\n if (globalConfig) {\n const [globalEntity, globalSlug, segment3, ...remainingSegments] = routeSegments\n\n if (!overrideDocPermissions && !docPermissions?.read?.permission) {\n notFound()\n } else {\n switch (routeSegments.length) {\n case 2: {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'default'),\n }\n DefaultView = {\n Component: DefaultEditView,\n }\n break\n }\n\n case 3: {\n // `../:slug/api`, `../:slug/preview`, `../:slug/versions`, etc\n switch (segment3) {\n case 'api': {\n if (globalConfig?.admin?.hideAPIURL !== true) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'api'),\n }\n DefaultView = {\n Component: DefaultAPIView,\n }\n }\n break\n }\n\n case 'preview': {\n if (livePreviewEnabled) {\n DefaultView = {\n Component: DefaultLivePreviewView,\n }\n }\n break\n }\n\n case 'versions': {\n if (!overrideDocPermissions && docPermissions?.readVersions?.permission) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'versions'),\n }\n\n DefaultView = {\n Component: DefaultVersionsView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n break\n }\n\n default: {\n if (!overrideDocPermissions && docPermissions?.read?.permission) {\n const baseRoute = [adminRoute, globalEntity, globalSlug, segment3]\n .filter(Boolean)\n .join('/')\n\n const currentRoute = [baseRoute, segment3, ...remainingSegments]\n .filter(Boolean)\n .join('/')\n\n const { Component: CustomViewComponent, viewKey: customViewKey } =\n getCustomViewByRoute({\n baseRoute,\n currentRoute,\n views,\n })\n\n if (customViewKey) {\n viewKey = customViewKey\n\n CustomView = {\n payloadComponent: CustomViewComponent,\n }\n } else {\n DefaultView = {\n Component: DefaultEditView,\n }\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n break\n }\n }\n break\n }\n\n default: {\n // `../:slug/versions/:version`, etc\n if (segment3 === 'versions') {\n if (!overrideDocPermissions && docPermissions?.readVersions?.permission) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'version'),\n }\n DefaultView = {\n Component: DefaultVersionView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n } else {\n const baseRoute = [adminRoute !== '/' && adminRoute, 'globals', globalSlug]\n .filter(Boolean)\n .join('/')\n\n const currentRoute = [baseRoute, segment3, ...remainingSegments]\n .filter(Boolean)\n .join('/')\n\n const { Component: CustomViewComponent, viewKey: customViewKey } = getCustomViewByRoute(\n {\n baseRoute,\n currentRoute,\n views,\n },\n )\n\n if (customViewKey) {\n viewKey = customViewKey\n\n CustomView = {\n payloadComponent: CustomViewComponent,\n }\n }\n }\n\n break\n }\n }\n }\n }\n\n return {\n CustomView,\n DefaultView,\n ErrorView,\n viewKey,\n }\n}\n"],"mappings":"AAYA,SAASA,QAAQ,QAAQ;AAEzB,SAASC,OAAA,IAAWC,cAAc,QAAQ;AAC1C,SAASC,QAAA,IAAYC,eAAe,QAAQ;AAC5C,SAASC,eAAA,IAAmBC,sBAAsB,QAAQ;AAC1D,SAASC,gBAAgB,QAAQ;AACjC,SAASC,WAAA,IAAeC,kBAAkB,QAAQ;AAClD,SAASC,YAAA,IAAgBC,mBAAmB,QAAQ;AACpD,SAASC,kBAAkB,QAAQ;AACnC,SAASC,oBAAoB,QAAQ;AAOrC,OAAO,MAAMC,kBAAA,GAAqBA,CAAC;EACjCC,gBAAgB;EAChBC,MAAM;EACNC,cAAc;EACdC,YAAY;EACZC,sBAAsB;EACtBC;AAAa,CAed;EASC;EACA,IAAIC,WAAA,GAAuD;EAC3D,IAAIC,UAAA,GAAsD;EAC1D,IAAIC,SAAA,GAA4C;EAChD,IAAIC,OAAA;EAEJ,MAAM;IACJC,MAAA,EAAQ;MAAEC,KAAA,EAAOC;IAAU;EAAE,CAC9B,GAAGX,MAAA;EAEJ,MAAMY,KAAA,GACJb,gBAAC,IAAoBA,gBAAA,EAAkBW,KAAA,EAAOG,UAAA,EAAYD,KAAA,IACzDV,YAAA,IAAgBA,YAAA,EAAcQ,KAAA,EAAOG,UAAA,EAAYD,KAAA;EAEpD,MAAME,kBAAA,GACJf,gBAAC,IAAoBA,gBAAA,EAAkBW,KAAA,EAAOK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AAWV,QAAA,E,GAAaG,iBAAA,CAAkB,CAC7DQ,MAAM,CAACC,OAAA,EACPC,IAAI,CAAC;cAER,MAAM;gBAAEJ,SAAA,EAAWM,mBAAmB;gBAAE7B,OAAA,EAAS8B;cAAa,CAAE,GAAGzC,oBAAA,CACjE;gBACEmC,SAAA;gBACAI,YAAA;gBACAxB;cACF;cAGF,IAAI0B,aAAA,EAAe;gBACjB9B,OAAA,GAAU8B,aAAA;gBAEVhC,UAAA,GAAa;kBACXwB,gBAAA,EAAkBO;gBACpB;cACF;YACF;YAEA;UACF;MACF;IACF;EACF;EAEA,OAAO;IACL/B,UAAA;IACAD,WAAA;IACAE,SAAA;IACAC;EACF;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"getViewsFromConfig.js","names":["notFound","APIView","DefaultAPIView","EditView","DefaultEditView","LivePreviewView","DefaultLivePreviewView","UnauthorizedView","VersionView","DefaultVersionView","VersionsView","DefaultVersionsView","getCustomViewByKey","getCustomViewByRoute","getViewsFromConfig","collectionConfig","config","docPermissions","globalConfig","overrideDocPermissions","routeSegments","DefaultView","CustomView","ErrorView","viewKey","routes","admin","adminRoute","views","components","livePreviewEnabled","livePreview","collections","includes","slug","globals","collectionEntity","collectionSlug","segment3","segment4","segment5","remainingSegments","read","permission","length","create","payloadComponent","Component","baseRoute","filter","Boolean","join","currentRoute","CustomViewComponent","customViewKey","hideAPIURL","readVersions","globalEntity","globalSlug"],"sources":["../../../src/views/Document/getViewsFromConfig.tsx"],"sourcesContent":["import type {\n AdminViewProps,\n CollectionPermission,\n GlobalPermission,\n PayloadComponent,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SanitizedGlobalConfig,\n ServerSideEditViewProps,\n} from 'payload'\nimport type React from 'react'\n\nimport { notFound } from 'next/navigation.js'\n\nimport { APIView as DefaultAPIView } from '../API/index.js'\nimport { EditView as DefaultEditView } from '../Edit/index.js'\nimport { LivePreviewView as DefaultLivePreviewView } from '../LivePreview/index.js'\nimport { UnauthorizedView } from '../Unauthorized/index.js'\nimport { VersionView as DefaultVersionView } from '../Version/index.js'\nimport { VersionsView as DefaultVersionsView } from '../Versions/index.js'\nimport { getCustomViewByKey } from './getCustomViewByKey.js'\nimport { getCustomViewByRoute } from './getCustomViewByRoute.js'\n\nexport type ViewFromConfig<TProps extends object> = {\n Component?: React.FC<TProps>\n payloadComponent?: PayloadComponent<TProps>\n}\n\nexport const getViewsFromConfig = ({\n collectionConfig,\n config,\n docPermissions,\n globalConfig,\n overrideDocPermissions,\n routeSegments,\n}: {\n collectionConfig?: SanitizedCollectionConfig\n config: SanitizedConfig\n globalConfig?: SanitizedGlobalConfig\n routeSegments: string[]\n} & (\n | {\n docPermissions: CollectionPermission | GlobalPermission\n overrideDocPermissions?: false | undefined\n }\n | {\n docPermissions?: never\n overrideDocPermissions: true\n }\n)): {\n CustomView: ViewFromConfig<ServerSideEditViewProps>\n DefaultView: ViewFromConfig<ServerSideEditViewProps>\n /**\n * The error view to display if CustomView or DefaultView do not exist (could be either due to not found, or unauthorized). Can be null\n */\n ErrorView: ViewFromConfig<AdminViewProps>\n viewKey: string\n} | null => {\n // Conditionally import and lazy load the default view\n let DefaultView: ViewFromConfig<ServerSideEditViewProps> = null\n let CustomView: ViewFromConfig<ServerSideEditViewProps> = null\n let ErrorView: ViewFromConfig<AdminViewProps> = null\n let viewKey: string\n\n const {\n routes: { admin: adminRoute },\n } = config\n\n const views =\n (collectionConfig && collectionConfig?.admin?.components?.views) ||\n (globalConfig && globalConfig?.admin?.components?.views)\n\n const livePreviewEnabled =\n (collectionConfig && collectionConfig?.admin?.livePreview) ||\n config?.admin?.livePreview?.collections?.includes(collectionConfig?.slug) ||\n (globalConfig && globalConfig?.admin?.livePreview) ||\n config?.admin?.livePreview?.globals?.includes(globalConfig?.slug)\n\n if (collectionConfig) {\n const [collectionEntity, collectionSlug, segment3, segment4, segment5, ...remainingSegments] =\n routeSegments\n\n if (!overrideDocPermissions && !docPermissions?.read?.permission) {\n notFound()\n } else {\n // `../:id`, or `../create`\n switch (routeSegments.length) {\n case 3: {\n switch (segment3) {\n case 'create': {\n if (\n !overrideDocPermissions &&\n 'create' in docPermissions &&\n docPermissions?.create?.permission\n ) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'default'),\n }\n DefaultView = {\n Component: DefaultEditView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n break\n }\n\n default: {\n const baseRoute = [\n adminRoute !== '/' && adminRoute,\n 'collections',\n collectionSlug,\n segment3,\n ]\n .filter(Boolean)\n .join('/')\n\n const currentRoute = [baseRoute, segment4, segment5, ...remainingSegments]\n .filter(Boolean)\n .join('/')\n\n const { Component: CustomViewComponent, viewKey: customViewKey } =\n getCustomViewByRoute({\n baseRoute,\n currentRoute,\n views,\n })\n\n if (customViewKey) {\n viewKey = customViewKey\n\n CustomView = {\n payloadComponent: CustomViewComponent,\n }\n } else {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'default'),\n }\n\n DefaultView = {\n Component: DefaultEditView,\n }\n }\n\n break\n }\n }\n break\n }\n\n // `../:id/api`, `../:id/preview`, `../:id/versions`, etc\n case 4: {\n switch (segment4) {\n case 'api': {\n if (collectionConfig?.admin?.hideAPIURL !== true) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'api'),\n }\n DefaultView = {\n Component: DefaultAPIView,\n }\n }\n break\n }\n\n case 'preview': {\n if (livePreviewEnabled) {\n DefaultView = {\n Component: DefaultLivePreviewView,\n }\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'livePreview'),\n }\n }\n break\n }\n\n case 'versions': {\n if (!overrideDocPermissions && docPermissions?.readVersions?.permission) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'versions'),\n }\n DefaultView = {\n Component: DefaultVersionsView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n break\n }\n\n default: {\n const baseRoute = [\n adminRoute !== '/' && adminRoute,\n 'collections',\n collectionSlug,\n segment3,\n ]\n .filter(Boolean)\n .join('/')\n\n const currentRoute = [baseRoute, segment4, segment5, ...remainingSegments]\n .filter(Boolean)\n .join('/')\n\n const { Component: CustomViewComponent, viewKey: customViewKey } =\n getCustomViewByRoute({\n baseRoute,\n currentRoute,\n views,\n })\n\n if (customViewKey) {\n viewKey = customViewKey\n\n CustomView = {\n payloadComponent: CustomViewComponent,\n }\n }\n\n break\n }\n }\n break\n }\n\n // `../:id/versions/:version`, etc\n default: {\n if (segment4 === 'versions') {\n if (!overrideDocPermissions && docPermissions?.readVersions?.permission) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'version'),\n }\n DefaultView = {\n Component: DefaultVersionView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n } else {\n const baseRoute = [\n adminRoute !== '/' && adminRoute,\n collectionEntity,\n collectionSlug,\n segment3,\n ]\n .filter(Boolean)\n .join('/')\n\n const currentRoute = [baseRoute, segment4, segment5, ...remainingSegments]\n .filter(Boolean)\n .join('/')\n\n const { Component: CustomViewComponent, viewKey: customViewKey } = getCustomViewByRoute(\n {\n baseRoute,\n currentRoute,\n views,\n },\n )\n\n if (customViewKey) {\n viewKey = customViewKey\n\n CustomView = {\n payloadComponent: CustomViewComponent,\n }\n }\n }\n\n break\n }\n }\n }\n }\n\n if (globalConfig) {\n const [globalEntity, globalSlug, segment3, ...remainingSegments] = routeSegments\n\n if (!overrideDocPermissions && !docPermissions?.read?.permission) {\n notFound()\n } else {\n switch (routeSegments.length) {\n case 2: {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'default'),\n }\n DefaultView = {\n Component: DefaultEditView,\n }\n break\n }\n\n case 3: {\n // `../:slug/api`, `../:slug/preview`, `../:slug/versions`, etc\n switch (segment3) {\n case 'api': {\n if (globalConfig?.admin?.hideAPIURL !== true) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'api'),\n }\n DefaultView = {\n Component: DefaultAPIView,\n }\n }\n break\n }\n\n case 'preview': {\n if (livePreviewEnabled) {\n DefaultView = {\n Component: DefaultLivePreviewView,\n }\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'livePreview'),\n }\n }\n break\n }\n\n case 'versions': {\n if (!overrideDocPermissions && docPermissions?.readVersions?.permission) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'versions'),\n }\n\n DefaultView = {\n Component: DefaultVersionsView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n break\n }\n\n default: {\n if (!overrideDocPermissions && docPermissions?.read?.permission) {\n const baseRoute = [adminRoute, globalEntity, globalSlug, segment3]\n .filter(Boolean)\n .join('/')\n\n const currentRoute = [baseRoute, segment3, ...remainingSegments]\n .filter(Boolean)\n .join('/')\n\n const { Component: CustomViewComponent, viewKey: customViewKey } =\n getCustomViewByRoute({\n baseRoute,\n currentRoute,\n views,\n })\n\n if (customViewKey) {\n viewKey = customViewKey\n\n CustomView = {\n payloadComponent: CustomViewComponent,\n }\n } else {\n DefaultView = {\n Component: DefaultEditView,\n }\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n break\n }\n }\n break\n }\n\n default: {\n // `../:slug/versions/:version`, etc\n if (segment3 === 'versions') {\n if (!overrideDocPermissions && docPermissions?.readVersions?.permission) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'version'),\n }\n DefaultView = {\n Component: DefaultVersionView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n } else {\n const baseRoute = [adminRoute !== '/' && adminRoute, 'globals', globalSlug]\n .filter(Boolean)\n .join('/')\n\n const currentRoute = [baseRoute, segment3, ...remainingSegments]\n .filter(Boolean)\n .join('/')\n\n const { Component: CustomViewComponent, viewKey: customViewKey } = getCustomViewByRoute(\n {\n baseRoute,\n currentRoute,\n views,\n },\n )\n\n if (customViewKey) {\n viewKey = customViewKey\n\n CustomView = {\n payloadComponent: CustomViewComponent,\n }\n }\n }\n\n break\n }\n }\n }\n }\n\n return {\n CustomView,\n DefaultView,\n Err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AA,CACjE;gBACEmC,SAAA;gBACAI,YAAA;gBACAxB;cACF;cAGF,IAAI0B,aAAA,EAAe;gBACjB9B,OAAA,GAAU8B,aAAA;gBAEVhC,UAAA,GAAa;kBACXwB,gBAAA,EAAkBO;gBACpB;cACF;YACF;YAEA;UACF;MACF;IACF;EACF;EAEA,OAAO;IACL/B,UAAA;IACAD,WAAA;IACAE,SAAA;IACAC;EACF;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"APIKey.d.ts","sourceRoot":"","sources":["../../../../../src/views/Edit/Default/Auth/APIKey.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAuC,MAAM,OAAO,CAAA;AAO3D,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"APIKey.d.ts","sourceRoot":"","sources":["../../../../../src/views/Edit/Default/Auth/APIKey.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAuC,MAAM,OAAO,CAAA;AAO3D,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAyHvF,CAAA"}
|
|
@@ -23,8 +23,7 @@ export const APIKey = ({
|
|
|
23
23
|
config
|
|
24
24
|
} = useConfig();
|
|
25
25
|
const {
|
|
26
|
-
collectionSlug
|
|
27
|
-
docPermissions
|
|
26
|
+
collectionSlug
|
|
28
27
|
} = useDocumentInfo();
|
|
29
28
|
const apiKey = useFormFields(([fields]) => fields && fields[path] || null);
|
|
30
29
|
const apiKeyField = config.collections.find(collection => {
|
|
@@ -63,11 +62,6 @@ export const APIKey = ({
|
|
|
63
62
|
value: apiKeyValue
|
|
64
63
|
})]
|
|
65
64
|
}), [apiKeyLabel, apiKeyValue]);
|
|
66
|
-
const canUpdateAPIKey = useMemo(() => {
|
|
67
|
-
if (docPermissions && docPermissions?.fields?.apiKey) {
|
|
68
|
-
return docPermissions.fields.apiKey.update.permission;
|
|
69
|
-
}
|
|
70
|
-
}, [docPermissions]);
|
|
71
65
|
const fieldType = useField({
|
|
72
66
|
path: 'apiKey',
|
|
73
67
|
validate
|
|
@@ -122,7 +116,7 @@ export const APIKey = ({
|
|
|
122
116
|
type: "text",
|
|
123
117
|
value: value || ''
|
|
124
118
|
})]
|
|
125
|
-
}), !readOnly &&
|
|
119
|
+
}), !readOnly && /*#__PURE__*/_jsx(GenerateConfirmation, {
|
|
126
120
|
highlightField: highlightField,
|
|
127
121
|
setKey: () => setValue(uuidv4())
|
|
128
122
|
})]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"APIKey.js","names":["getTranslation","CopyToClipboard","FieldLabel","GenerateConfirmation","useConfig","useDocumentInfo","useField","useFormFields","useTranslation","text","React","useEffect","useMemo","useState","v4","uuidv4","path","baseClass","fieldBaseClass","APIKey","enabled","readOnly","initialAPIKey","highlightedField","setHighlightedField","i18n","t","config","collectionSlug","
|
|
1
|
+
{"version":3,"file":"APIKey.js","names":["getTranslation","CopyToClipboard","FieldLabel","GenerateConfirmation","useConfig","useDocumentInfo","useField","useFormFields","useTranslation","text","React","useEffect","useMemo","useState","v4","uuidv4","path","baseClass","fieldBaseClass","APIKey","enabled","readOnly","initialAPIKey","highlightedField","setHighlightedField","i18n","t","config","collectionSlug","apiKey","fields","apiKeyField","collections","find","collection","slug","field","name","validate","val","type","data","maxLength","minLength","preferences","req","payload","siblingData","apiKeyValue","value","apiKeyLabel","label","APIKeyLabel","_jsxs","className","_jsx","fieldType","highlightField","setTimeout","setValue","Fragment","filter","Boolean","join","htmlFor","Label","Component","RenderedComponent","undefined","disabled","id","setKey"],"sources":["../../../../../src/views/Edit/Default/Auth/APIKey.tsx"],"sourcesContent":["'use client'\nimport type { PayloadRequest, TextFieldClient } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n CopyToClipboard,\n FieldLabel,\n GenerateConfirmation,\n useConfig,\n useDocumentInfo,\n useField,\n useFormFields,\n useTranslation,\n} from '@payloadcms/ui'\nimport { text } from 'payload/shared'\nimport React, { useEffect, useMemo, useState } from 'react'\nimport { v4 as uuidv4 } from 'uuid'\n\nconst path = 'apiKey'\nconst baseClass = 'api-key'\nconst fieldBaseClass = 'field-type'\n\nexport const APIKey: React.FC<{ readonly enabled: boolean; readonly readOnly?: boolean }> = ({\n enabled,\n readOnly,\n}) => {\n const [initialAPIKey] = useState(uuidv4())\n const [highlightedField, setHighlightedField] = useState(false)\n const { i18n, t } = useTranslation()\n const { config } = useConfig()\n const { collectionSlug } = useDocumentInfo()\n\n const apiKey = useFormFields(([fields]) => (fields && fields[path]) || null)\n\n const apiKeyField: TextFieldClient = config.collections\n .find((collection) => {\n return collection.slug === collectionSlug\n })\n ?.fields?.find((field) => 'name' in field && field.name === 'apiKey') as TextFieldClient\n\n const validate = (val) =>\n text(val, {\n name: 'apiKey',\n type: 'text',\n data: {},\n maxLength: 48,\n minLength: 24,\n preferences: { fields: {} },\n req: {\n payload: {\n config,\n },\n t,\n } as unknown as PayloadRequest,\n siblingData: {},\n })\n\n const apiKeyValue = apiKey?.value\n\n const apiKeyLabel = useMemo(() => {\n let label: Record<string, string> | string = 'API Key'\n\n if (apiKeyField?.label) {\n label = apiKeyField.label\n }\n\n return getTranslation(label, i18n)\n }, [apiKeyField, i18n])\n\n const APIKeyLabel = useMemo(\n () => (\n <div className={`${baseClass}__label`}>\n <span>{apiKeyLabel}</span>\n <CopyToClipboard value={apiKeyValue as string} />\n </div>\n ),\n [apiKeyLabel, apiKeyValue],\n )\n\n const fieldType = useField({\n path: 'apiKey',\n validate,\n })\n\n const highlightField = () => {\n if (highlightedField) {\n setHighlightedField(false)\n }\n setTimeout(() => {\n setHighlightedField(true)\n }, 1)\n }\n\n const { setValue, value } = fieldType\n\n useEffect(() => {\n if (!apiKeyValue && enabled) {\n setValue(initialAPIKey)\n }\n if (!enabled && apiKeyValue) {\n setValue(null)\n }\n }, [apiKeyValue, enabled, setValue, initialAPIKey])\n\n useEffect(() => {\n if (highlightedField) {\n setTimeout(() => {\n setHighlightedField(false)\n }, 10000)\n }\n }, [highlightedField])\n\n if (!enabled) {\n return null\n }\n\n return (\n <React.Fragment>\n <div className={[fieldBaseClass, 'api-key', 'read-only'].filter(Boolean).join(' ')}>\n <FieldLabel\n field={null}\n htmlFor={path}\n Label={{\n type: 'client',\n Component: null,\n RenderedComponent: APIKeyLabel,\n }}\n />\n <input\n aria-label={apiKeyLabel}\n className={highlightedField ? 'highlight' : undefined}\n disabled\n id=\"apiKey\"\n name=\"apiKey\"\n type=\"text\"\n value={(value as string) || ''}\n />\n </div>\n {!readOnly && (\n <GenerateConfirmation highlightField={highlightField} setKey={() => setValue(uuidv4())} />\n )}\n </React.Fragment>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,cAAc,QAAQ;AAC/B,SACEC,eAAe,EACfC,UAAU,EACVC,oBAAoB,EACpBC,SAAS,EACTC,eAAe,EACfC,QAAQ,EACRC,aAAa,EACbC,cAAc,QACT;AACP,SAASC,IAAI,QAAQ;AACrB,OAAOC,KAAA,IAASC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ;AACpD,SAASC,EAAA,IAAMC,MAAM,QAAQ;AAE7B,MAAMC,IAAA,GAAO;AACb,MAAMC,SAAA,GAAY;AAClB,MAAMC,cAAA,GAAiB;AAEvB,OAAO,MAAMC,MAAA,GAA+EA,CAAC;EAC3FC,OAAO;EACPC;AAAQ,CACT;EACC,MAAM,CAACC,aAAA,CAAc,GAAGT,QAAA,CAASE,MAAA;EACjC,MAAM,CAACQ,gBAAA,EAAkBC,mBAAA,CAAoB,GAAGX,QAAA,CAAS;EACzD,MAAM;IAAEY,IAAI;IAAEC;EAAC,CAAE,G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S,KAAA,EAAOA,KAAC,IAAoB;;QAG/B,CAAC5B,QAAA,iBACAkC,IAAA,CAACpD,oBAAA;MAAqBsD,cAAA,EAAgBA,cAAA;MAAgBc,MAAA,EAAQA,CAAA,KAAMZ,QAAA,CAAS5C,MAAA;;;AAIrF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/views/Edit/Default/Auth/index.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAoD,MAAM,OAAO,CAAA;AAGxE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAIvC,OAAO,cAAc,CAAA;AAIrB,eAAO,MAAM,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/views/Edit/Default/Auth/index.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAoD,MAAM,OAAO,CAAA;AAGxE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAIvC,OAAO,cAAc,CAAA;AAIrB,eAAO,MAAM,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA8MhC,CAAA"}
|
|
@@ -9,7 +9,7 @@ import { RenderEmailAndUsernameFields } from '../../../../elements/EmailAndUsern
|
|
|
9
9
|
import { APIKey } from './APIKey.js';
|
|
10
10
|
const baseClass = 'auth-fields';
|
|
11
11
|
export const Auth = props => {
|
|
12
|
-
const $ = _c(
|
|
12
|
+
const $ = _c(55);
|
|
13
13
|
const {
|
|
14
14
|
className,
|
|
15
15
|
collectionSlug,
|
|
@@ -64,6 +64,10 @@ export const Auth = props => {
|
|
|
64
64
|
t2 = false;
|
|
65
65
|
}
|
|
66
66
|
const hasPermissionToUnlock = t2;
|
|
67
|
+
const apiKeyReadOnly = readOnly || !docPermissions?.fields?.apiKey?.update?.permission;
|
|
68
|
+
const enableAPIKeyReadOnly = readOnly || !docPermissions?.fields?.enableAPIKey?.update?.permission;
|
|
69
|
+
const canReadApiKey = docPermissions?.fields?.apiKey?.read?.permission;
|
|
70
|
+
const canReadEnableAPIKey = docPermissions?.fields?.enableAPIKey?.read?.permission;
|
|
67
71
|
let t3;
|
|
68
72
|
if ($[0] !== setValidateBeforeSubmit || $[1] !== setSchemaPath || $[2] !== collectionSlug || $[3] !== dispatchFields || $[4] !== t) {
|
|
69
73
|
t3 = showPasswordFields => {
|
|
@@ -174,36 +178,39 @@ export const Auth = props => {
|
|
|
174
178
|
}
|
|
175
179
|
const t8 = t7.join(" ");
|
|
176
180
|
let t9;
|
|
177
|
-
if ($[20] !== disableLocalStrategy || $[21] !== docPermissions || $[22] !== loginWithUsername || $[23] !== operation || $[24] !== readOnly || $[25] !== showPasswordFields_0 || $[26] !== requirePassword || $[27] !== disabled || $[28] !== t || $[29] !== handleChangePassword || $[30] !== hasPermissionToUnlock || $[31] !== unlock_0 || $[32] !== useAPIKey || $[33] !==
|
|
181
|
+
if ($[20] !== disableLocalStrategy || $[21] !== docPermissions || $[22] !== loginWithUsername || $[23] !== operation || $[24] !== readOnly || $[25] !== showPasswordFields_0 || $[26] !== requirePassword || $[27] !== disabled || $[28] !== t || $[29] !== handleChangePassword || $[30] !== hasPermissionToUnlock || $[31] !== unlock_0 || $[32] !== useAPIKey || $[33] !== canReadEnableAPIKey || $[34] !== enableAPIKeyReadOnly || $[35] !== canReadApiKey || $[36] !== enableAPIKey || $[37] !== apiKeyReadOnly || $[38] !== verify || $[39] !== t8) {
|
|
178
182
|
let t10;
|
|
179
|
-
if ($[
|
|
183
|
+
if ($[41] !== useAPIKey || $[42] !== canReadEnableAPIKey || $[43] !== disabled || $[44] !== enableAPIKeyReadOnly || $[45] !== t || $[46] !== canReadApiKey || $[47] !== enableAPIKey || $[48] !== apiKeyReadOnly) {
|
|
180
184
|
t10 = useAPIKey && _jsxs("div", {
|
|
181
185
|
className: `${baseClass}__api-key`,
|
|
182
|
-
children: [_jsx(CheckboxField, {
|
|
186
|
+
children: [canReadEnableAPIKey && _jsx(CheckboxField, {
|
|
183
187
|
field: {
|
|
184
188
|
name: "enableAPIKey",
|
|
185
189
|
admin: {
|
|
186
190
|
disabled,
|
|
187
|
-
readOnly
|
|
191
|
+
readOnly: enableAPIKeyReadOnly
|
|
188
192
|
},
|
|
189
193
|
label: t("authentication:enableAPIKey")
|
|
190
194
|
}
|
|
191
|
-
}), _jsx(APIKey, {
|
|
195
|
+
}), canReadApiKey && _jsx(APIKey, {
|
|
192
196
|
enabled: !!enableAPIKey?.value,
|
|
193
|
-
readOnly
|
|
197
|
+
readOnly: apiKeyReadOnly
|
|
194
198
|
})]
|
|
195
199
|
});
|
|
196
|
-
$[
|
|
197
|
-
$[
|
|
198
|
-
$[
|
|
199
|
-
$[
|
|
200
|
-
$[
|
|
201
|
-
$[
|
|
200
|
+
$[41] = useAPIKey;
|
|
201
|
+
$[42] = canReadEnableAPIKey;
|
|
202
|
+
$[43] = disabled;
|
|
203
|
+
$[44] = enableAPIKeyReadOnly;
|
|
204
|
+
$[45] = t;
|
|
205
|
+
$[46] = canReadApiKey;
|
|
206
|
+
$[47] = enableAPIKey;
|
|
207
|
+
$[48] = apiKeyReadOnly;
|
|
208
|
+
$[49] = t10;
|
|
202
209
|
} else {
|
|
203
|
-
t10 = $[
|
|
210
|
+
t10 = $[49];
|
|
204
211
|
}
|
|
205
212
|
let t11;
|
|
206
|
-
if ($[
|
|
213
|
+
if ($[50] !== verify || $[51] !== disabled || $[52] !== readOnly || $[53] !== t) {
|
|
207
214
|
t11 = verify && _jsx(CheckboxField, {
|
|
208
215
|
field: {
|
|
209
216
|
name: "_verified",
|
|
@@ -214,13 +221,13 @@ export const Auth = props => {
|
|
|
214
221
|
label: t("authentication:verified")
|
|
215
222
|
}
|
|
216
223
|
});
|
|
217
|
-
$[
|
|
218
|
-
$[
|
|
219
|
-
$[
|
|
220
|
-
$[
|
|
221
|
-
$[
|
|
224
|
+
$[50] = verify;
|
|
225
|
+
$[51] = disabled;
|
|
226
|
+
$[52] = readOnly;
|
|
227
|
+
$[53] = t;
|
|
228
|
+
$[54] = t11;
|
|
222
229
|
} else {
|
|
223
|
-
t11 = $[
|
|
230
|
+
t11 = $[54];
|
|
224
231
|
}
|
|
225
232
|
t9 = _jsxs("div", {
|
|
226
233
|
className: t8,
|
|
@@ -284,12 +291,16 @@ export const Auth = props => {
|
|
|
284
291
|
$[30] = hasPermissionToUnlock;
|
|
285
292
|
$[31] = unlock_0;
|
|
286
293
|
$[32] = useAPIKey;
|
|
287
|
-
$[33] =
|
|
288
|
-
$[34] =
|
|
289
|
-
$[35] =
|
|
290
|
-
$[36] =
|
|
294
|
+
$[33] = canReadEnableAPIKey;
|
|
295
|
+
$[34] = enableAPIKeyReadOnly;
|
|
296
|
+
$[35] = canReadApiKey;
|
|
297
|
+
$[36] = enableAPIKey;
|
|
298
|
+
$[37] = apiKeyReadOnly;
|
|
299
|
+
$[38] = verify;
|
|
300
|
+
$[39] = t8;
|
|
301
|
+
$[40] = t9;
|
|
291
302
|
} else {
|
|
292
|
-
t9 = $[
|
|
303
|
+
t9 = $[40];
|
|
293
304
|
}
|
|
294
305
|
return t9;
|
|
295
306
|
};
|