@payloadcms/next 3.0.0-beta.2 → 3.0.0-beta.20
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/cjs/withPayload.cjs +2 -1
- package/dist/cjs/withPayload.cjs.map +1 -1
- package/dist/exports/routes.d.ts +1 -1
- package/dist/exports/routes.d.ts.map +1 -1
- package/dist/exports/routes.js +1 -1
- package/dist/exports/routes.js.map +1 -1
- package/dist/exports/utilities.d.ts +6 -1
- package/dist/exports/utilities.d.ts.map +1 -1
- package/dist/exports/utilities.js +6 -1
- package/dist/exports/utilities.js.map +1 -1
- package/dist/{next-fileupload → fetchAPI-multipart}/fileFactory.d.ts +2 -2
- package/dist/fetchAPI-multipart/fileFactory.d.ts.map +1 -0
- package/dist/fetchAPI-multipart/fileFactory.js.map +1 -0
- package/dist/{next-fileupload → fetchAPI-multipart}/handlers.d.ts +2 -2
- package/dist/fetchAPI-multipart/handlers.d.ts.map +1 -0
- package/dist/fetchAPI-multipart/handlers.js.map +1 -0
- package/dist/{next-fileupload → fetchAPI-multipart}/index.d.ts +8 -8
- package/dist/fetchAPI-multipart/index.d.ts.map +1 -0
- package/dist/{next-fileupload → fetchAPI-multipart}/index.js +1 -1
- package/dist/fetchAPI-multipart/index.js.map +1 -0
- package/dist/fetchAPI-multipart/isEligibleRequest.d.ts.map +1 -0
- package/dist/{next-fileupload → fetchAPI-multipart}/isEligibleRequest.js +1 -1
- package/dist/fetchAPI-multipart/isEligibleRequest.js.map +1 -0
- package/dist/fetchAPI-multipart/processMultipart.d.ts +8 -0
- package/dist/fetchAPI-multipart/processMultipart.d.ts.map +1 -0
- package/dist/{next-fileupload → fetchAPI-multipart}/processMultipart.js +29 -6
- package/dist/fetchAPI-multipart/processMultipart.js.map +1 -0
- package/dist/fetchAPI-multipart/processNested.d.ts.map +1 -0
- package/dist/{next-fileupload → fetchAPI-multipart}/processNested.js +2 -1
- package/dist/fetchAPI-multipart/processNested.js.map +1 -0
- package/dist/fetchAPI-multipart/uploadTimer.d.ts.map +1 -0
- package/dist/fetchAPI-multipart/uploadTimer.js.map +1 -0
- package/dist/{next-fileupload → fetchAPI-multipart}/utilities.d.ts +4 -4
- package/dist/fetchAPI-multipart/utilities.d.ts.map +1 -0
- package/dist/{next-fileupload → fetchAPI-multipart}/utilities.js +4 -4
- package/dist/fetchAPI-multipart/utilities.js.map +1 -0
- package/dist/fetchAPI-stream-file/index.d.ts.map +1 -0
- package/dist/fetchAPI-stream-file/index.js.map +1 -0
- package/dist/layouts/Root/index.d.ts.map +1 -1
- package/dist/layouts/Root/index.js +23 -1
- package/dist/layouts/Root/index.js.map +1 -1
- package/dist/prod/styles.css +1 -1
- package/dist/routes/graphql/handler.d.ts.map +1 -1
- package/dist/routes/graphql/handler.js +20 -7
- package/dist/routes/graphql/handler.js.map +1 -1
- package/dist/routes/rest/auth/access.d.ts.map +1 -1
- package/dist/routes/rest/auth/access.js +5 -0
- package/dist/routes/rest/auth/access.js.map +1 -1
- package/dist/routes/rest/auth/forgotPassword.d.ts.map +1 -1
- package/dist/routes/rest/auth/forgotPassword.js +7 -2
- package/dist/routes/rest/auth/forgotPassword.js.map +1 -1
- package/dist/routes/rest/auth/init.d.ts.map +1 -1
- package/dist/routes/rest/auth/init.js +6 -0
- package/dist/routes/rest/auth/init.js.map +1 -1
- package/dist/routes/rest/auth/login.d.ts.map +1 -1
- package/dist/routes/rest/auth/login.js +8 -5
- package/dist/routes/rest/auth/login.js.map +1 -1
- package/dist/routes/rest/auth/logout.d.ts.map +1 -1
- package/dist/routes/rest/auth/logout.js +12 -7
- package/dist/routes/rest/auth/logout.js.map +1 -1
- package/dist/routes/rest/auth/me.d.ts.map +1 -1
- package/dist/routes/rest/auth/me.js +5 -0
- package/dist/routes/rest/auth/me.js.map +1 -1
- package/dist/routes/rest/auth/refresh.d.ts.map +1 -1
- package/dist/routes/rest/auth/refresh.js +11 -7
- package/dist/routes/rest/auth/refresh.js.map +1 -1
- package/dist/routes/rest/auth/registerFirstUser.d.ts.map +1 -1
- package/dist/routes/rest/auth/registerFirstUser.js +8 -5
- package/dist/routes/rest/auth/registerFirstUser.js.map +1 -1
- package/dist/routes/rest/auth/resetPassword.d.ts.map +1 -1
- package/dist/routes/rest/auth/resetPassword.js +8 -5
- package/dist/routes/rest/auth/resetPassword.js.map +1 -1
- package/dist/routes/rest/auth/unlock.d.ts.map +1 -1
- package/dist/routes/rest/auth/unlock.js +7 -2
- package/dist/routes/rest/auth/unlock.js.map +1 -1
- package/dist/routes/rest/auth/verifyEmail.d.ts.map +1 -1
- package/dist/routes/rest/auth/verifyEmail.js +7 -2
- package/dist/routes/rest/auth/verifyEmail.js.map +1 -1
- package/dist/routes/rest/buildFormState.d.ts +3 -3
- package/dist/routes/rest/buildFormState.d.ts.map +1 -1
- package/dist/routes/rest/buildFormState.js +37 -7
- package/dist/routes/rest/buildFormState.js.map +1 -1
- package/dist/routes/rest/collections/count.d.ts +3 -0
- package/dist/routes/rest/collections/count.d.ts.map +1 -0
- package/dist/routes/rest/collections/count.js +15 -0
- package/dist/routes/rest/collections/count.js.map +1 -0
- package/dist/routes/rest/collections/create.d.ts.map +1 -1
- package/dist/routes/rest/collections/create.js +5 -0
- 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 +7 -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 +14 -1
- package/dist/routes/rest/collections/deleteByID.js.map +1 -1
- package/dist/routes/rest/collections/docAccess.d.ts.map +1 -1
- package/dist/routes/rest/collections/docAccess.js +5 -0
- package/dist/routes/rest/collections/docAccess.js.map +1 -1
- package/dist/routes/rest/collections/duplicate.d.ts.map +1 -1
- package/dist/routes/rest/collections/duplicate.js +12 -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 +5 -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 +12 -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 +12 -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 +5 -0
- package/dist/routes/rest/collections/findVersions.js.map +1 -1
- package/dist/routes/rest/collections/preview.d.ts.map +1 -1
- package/dist/routes/rest/collections/preview.js +11 -2
- package/dist/routes/rest/collections/preview.js.map +1 -1
- package/dist/routes/rest/collections/restoreVersion.d.ts.map +1 -1
- package/dist/routes/rest/collections/restoreVersion.js +12 -1
- package/dist/routes/rest/collections/restoreVersion.js.map +1 -1
- package/dist/routes/rest/collections/update.d.ts.map +1 -1
- package/dist/routes/rest/collections/update.js +7 -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 +12 -1
- package/dist/routes/rest/collections/updateByID.js.map +1 -1
- package/dist/routes/rest/files/checkFileAccess.d.ts +2 -2
- package/dist/routes/rest/files/checkFileAccess.d.ts.map +1 -1
- package/dist/routes/rest/files/checkFileAccess.js.map +1 -1
- package/dist/routes/rest/files/getFile.d.ts +2 -2
- package/dist/routes/rest/files/getFile.d.ts.map +1 -1
- package/dist/routes/rest/files/getFile.js +16 -9
- package/dist/routes/rest/files/getFile.js.map +1 -1
- package/dist/routes/rest/files/getFileTypeFallback.d.ts +7 -0
- package/dist/routes/rest/files/getFileTypeFallback.d.ts.map +1 -0
- package/dist/routes/rest/files/getFileTypeFallback.js +21 -0
- package/dist/routes/rest/files/getFileTypeFallback.js.map +1 -0
- package/dist/routes/rest/globals/docAccess.d.ts.map +1 -1
- package/dist/routes/rest/globals/docAccess.js +5 -0
- package/dist/routes/rest/globals/docAccess.js.map +1 -1
- package/dist/routes/rest/globals/findOne.d.ts.map +1 -1
- package/dist/routes/rest/globals/findOne.js +5 -0
- 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 +5 -0
- 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 +5 -0
- package/dist/routes/rest/globals/findVersions.js.map +1 -1
- package/dist/routes/rest/globals/preview.d.ts.map +1 -1
- package/dist/routes/rest/globals/preview.js +11 -2
- package/dist/routes/rest/globals/preview.js.map +1 -1
- package/dist/routes/rest/globals/restoreVersion.d.ts.map +1 -1
- package/dist/routes/rest/globals/restoreVersion.js +5 -0
- package/dist/routes/rest/globals/restoreVersion.js.map +1 -1
- package/dist/routes/rest/globals/update.d.ts.map +1 -1
- package/dist/routes/rest/globals/update.js +5 -0
- package/dist/routes/rest/globals/update.js.map +1 -1
- package/dist/routes/rest/index.d.ts +1 -0
- package/dist/routes/rest/index.d.ts.map +1 -1
- package/dist/routes/rest/index.js +324 -213
- package/dist/routes/rest/index.js.map +1 -1
- package/dist/routes/rest/routeError.d.ts +5 -4
- package/dist/routes/rest/routeError.d.ts.map +1 -1
- package/dist/routes/rest/routeError.js +25 -11
- package/dist/routes/rest/routeError.js.map +1 -1
- package/dist/routes/rest/types.d.ts +7 -7
- package/dist/routes/rest/types.d.ts.map +1 -1
- package/dist/routes/rest/types.js.map +1 -1
- package/dist/routes/rest/utilities/sanitizeCollectionID.d.ts +9 -0
- package/dist/routes/rest/utilities/sanitizeCollectionID.d.ts.map +1 -0
- package/dist/routes/rest/utilities/sanitizeCollectionID.js +13 -0
- package/dist/routes/rest/utilities/sanitizeCollectionID.js.map +1 -0
- package/dist/scss/app.scss +2 -3
- package/dist/scss/vars.scss +0 -7
- package/dist/utilities/addDataAndFileToRequest.d.ts +11 -0
- package/dist/utilities/addDataAndFileToRequest.d.ts.map +1 -0
- package/dist/utilities/addDataAndFileToRequest.js +74 -0
- package/dist/utilities/addDataAndFileToRequest.js.map +1 -0
- package/dist/utilities/addLocalesToRequest.d.ts +20 -0
- package/dist/utilities/addLocalesToRequest.d.ts.map +1 -0
- package/dist/utilities/addLocalesToRequest.js +41 -0
- package/dist/utilities/addLocalesToRequest.js.map +1 -0
- package/dist/utilities/buildFieldSchemaMap/index.d.ts +2 -2
- package/dist/utilities/buildFieldSchemaMap/index.d.ts.map +1 -1
- package/dist/utilities/buildFieldSchemaMap/index.js.map +1 -1
- package/dist/utilities/createPayloadRequest.d.ts.map +1 -1
- package/dist/utilities/createPayloadRequest.js +15 -28
- package/dist/utilities/createPayloadRequest.js.map +1 -1
- package/dist/utilities/getDataAndFile.d.ts +2 -2
- package/dist/utilities/getDataAndFile.d.ts.map +1 -1
- package/dist/utilities/getDataAndFile.js +27 -43
- package/dist/utilities/getDataAndFile.js.map +1 -1
- package/dist/utilities/getPayloadHMR.d.ts +2 -1
- package/dist/utilities/getPayloadHMR.d.ts.map +1 -1
- package/dist/utilities/getPayloadHMR.js +22 -18
- package/dist/utilities/getPayloadHMR.js.map +1 -1
- package/dist/utilities/headersWithCors.d.ts +8 -0
- package/dist/utilities/headersWithCors.d.ts.map +1 -0
- package/dist/utilities/headersWithCors.js +17 -0
- package/dist/utilities/headersWithCors.js.map +1 -0
- package/dist/utilities/initPage.d.ts.map +1 -1
- package/dist/utilities/initPage.js +16 -2
- package/dist/utilities/initPage.js.map +1 -1
- package/dist/views/API/index.client.js +2 -2
- package/dist/views/API/index.client.js.map +1 -1
- package/dist/views/Account/index.d.ts.map +1 -1
- package/dist/views/Account/index.js +2 -1
- package/dist/views/Account/index.js.map +1 -1
- package/dist/views/CreateFirstUser/index.client.d.ts +3 -3
- package/dist/views/CreateFirstUser/index.client.d.ts.map +1 -1
- package/dist/views/CreateFirstUser/index.client.js +48 -6
- package/dist/views/CreateFirstUser/index.client.js.map +1 -1
- package/dist/views/CreateFirstUser/index.d.ts.map +1 -1
- package/dist/views/CreateFirstUser/index.js +9 -20
- package/dist/views/CreateFirstUser/index.js.map +1 -1
- package/dist/views/CreateFirstUser/index.scss +2 -12
- package/dist/views/Document/index.d.ts.map +1 -1
- package/dist/views/Document/index.js +2 -1
- package/dist/views/Document/index.js.map +1 -1
- package/dist/views/Edit/Default/Auth/APIKey.d.ts +1 -0
- package/dist/views/Edit/Default/Auth/APIKey.d.ts.map +1 -1
- package/dist/views/Edit/Default/Auth/APIKey.js +13 -6
- package/dist/views/Edit/Default/Auth/APIKey.js.map +1 -1
- package/dist/views/Edit/Default/Auth/index.js +2 -1
- package/dist/views/Edit/Default/Auth/index.js.map +1 -1
- package/dist/views/Edit/Default/{SetStepNav → SetDocumentStepNav}/index.d.ts +1 -1
- package/dist/views/Edit/Default/SetDocumentStepNav/index.d.ts.map +1 -0
- package/dist/views/Edit/Default/{SetStepNav → SetDocumentStepNav}/index.js +12 -5
- package/dist/views/Edit/Default/SetDocumentStepNav/index.js.map +1 -0
- package/dist/views/Edit/Default/index.d.ts.map +1 -1
- package/dist/views/Edit/Default/index.js +6 -5
- package/dist/views/Edit/Default/index.js.map +1 -1
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.d.ts +3 -0
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.d.ts.map +1 -0
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.js +58 -0
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.js.map +1 -0
- package/dist/views/ForgotPassword/index.d.ts.map +1 -1
- package/dist/views/ForgotPassword/index.js +3 -39
- package/dist/views/ForgotPassword/index.js.map +1 -1
- package/dist/views/List/index.js +2 -2
- package/dist/views/List/index.js.map +1 -1
- package/dist/views/LivePreview/Toolbar/Controls/index.d.ts.map +1 -1
- package/dist/views/LivePreview/Toolbar/Controls/index.js +6 -4
- package/dist/views/LivePreview/Toolbar/Controls/index.js.map +1 -1
- package/dist/views/LivePreview/index.client.js +2 -2
- package/dist/views/LivePreview/index.client.js.map +1 -1
- package/dist/views/Login/LoginForm/index.d.ts.map +1 -1
- package/dist/views/Login/LoginForm/index.js +32 -2
- package/dist/views/Login/LoginForm/index.js.map +1 -1
- package/dist/views/Logout/LogoutClient.d.ts.map +1 -1
- package/dist/views/Logout/LogoutClient.js +1 -2
- package/dist/views/Logout/LogoutClient.js.map +1 -1
- package/dist/views/Version/Restore/index.d.ts.map +1 -1
- package/dist/views/Version/Restore/index.js +11 -8
- package/dist/views/Version/Restore/index.js.map +1 -1
- package/dist/views/Version/Restore/index.scss +4 -2
- package/dist/views/Versions/index.js +2 -2
- package/dist/views/Versions/index.js.map +1 -1
- package/dist/withPayload.d.ts.map +1 -1
- package/dist/withPayload.js +2 -1
- package/dist/withPayload.js.map +1 -1
- package/package.json +34 -32
- package/dist/next-fileupload/fileFactory.d.ts.map +0 -1
- package/dist/next-fileupload/fileFactory.js.map +0 -1
- package/dist/next-fileupload/handlers.d.ts.map +0 -1
- package/dist/next-fileupload/handlers.js.map +0 -1
- package/dist/next-fileupload/index.d.ts.map +0 -1
- package/dist/next-fileupload/index.js.map +0 -1
- package/dist/next-fileupload/isEligibleRequest.d.ts.map +0 -1
- package/dist/next-fileupload/isEligibleRequest.js.map +0 -1
- package/dist/next-fileupload/processMultipart.d.ts +0 -8
- package/dist/next-fileupload/processMultipart.d.ts.map +0 -1
- package/dist/next-fileupload/processMultipart.js.map +0 -1
- package/dist/next-fileupload/processNested.d.ts.map +0 -1
- package/dist/next-fileupload/processNested.js.map +0 -1
- package/dist/next-fileupload/uploadTimer.d.ts.map +0 -1
- package/dist/next-fileupload/uploadTimer.js.map +0 -1
- package/dist/next-fileupload/utilities.d.ts.map +0 -1
- package/dist/next-fileupload/utilities.js.map +0 -1
- package/dist/next-stream-file/index.d.ts.map +0 -1
- package/dist/next-stream-file/index.js.map +0 -1
- package/dist/prod/payload/SuisseIntl-Bold.woff +0 -0
- package/dist/prod/payload/SuisseIntl-Bold.woff2 +0 -0
- package/dist/prod/payload/SuisseIntl-Medium.woff +0 -0
- package/dist/prod/payload/SuisseIntl-Medium.woff2 +0 -0
- package/dist/prod/payload/SuisseIntl-SemiBold.woff +0 -0
- package/dist/prod/payload/SuisseIntl-SemiBold.woff2 +0 -0
- package/dist/prod/payload/SuisseIntl.woff +0 -0
- package/dist/prod/payload/SuisseIntl.woff2 +0 -0
- package/dist/prod/payload/merriweather-v30-latin-900.woff +0 -0
- package/dist/prod/payload/merriweather-v30-latin-900.woff2 +0 -0
- package/dist/prod/payload/merriweather-v30-latin-900italic.woff +0 -0
- package/dist/prod/payload/merriweather-v30-latin-900italic.woff2 +0 -0
- package/dist/prod/payload/merriweather-v30-latin-italic.woff +0 -0
- package/dist/prod/payload/merriweather-v30-latin-italic.woff2 +0 -0
- package/dist/prod/payload/merriweather-v30-latin-regular.woff +0 -0
- package/dist/prod/payload/merriweather-v30-latin-regular.woff2 +0 -0
- package/dist/scss/fonts.scss +0 -75
- package/dist/views/Edit/Default/SetStepNav/index.d.ts.map +0 -1
- package/dist/views/Edit/Default/SetStepNav/index.js.map +0 -1
- package/src/index.js +0 -1
- /package/dist/{next-fileupload → fetchAPI-multipart}/fileFactory.js +0 -0
- /package/dist/{next-fileupload → fetchAPI-multipart}/handlers.js +0 -0
- /package/dist/{next-fileupload → fetchAPI-multipart}/isEligibleRequest.d.ts +0 -0
- /package/dist/{next-fileupload → fetchAPI-multipart}/processNested.d.ts +0 -0
- /package/dist/{next-fileupload → fetchAPI-multipart}/uploadTimer.d.ts +0 -0
- /package/dist/{next-fileupload → fetchAPI-multipart}/uploadTimer.js +0 -0
- /package/dist/{next-stream-file → fetchAPI-stream-file}/index.d.ts +0 -0
- /package/dist/{next-stream-file → fetchAPI-stream-file}/index.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/addLocalesToRequest.ts"],"sourcesContent":["import type {\n PayloadRequest,\n PayloadRequestData,\n PayloadRequestWithData,\n SanitizedConfig,\n} from 'payload/types'\n\n/**\n * Mutates the Request to contain 'locale' and 'fallbackLocale' based on data or searchParams\n */\ntype Args = {\n request: PayloadRequest & PayloadRequestData\n}\nexport function addLocalesToRequestFromData({ request }: Args): PayloadRequestWithData {\n const {\n data,\n payload: { config },\n } = request\n\n if (data) {\n let localeOnReq = request.locale\n let fallbackLocaleOnReq = request.fallbackLocale\n\n if (!localeOnReq && data?.locale && typeof data.locale === 'string') {\n localeOnReq = data.locale\n }\n\n if (\n !fallbackLocaleOnReq &&\n data?.['fallback-locale'] &&\n typeof data?.['fallback-locale'] === 'string'\n ) {\n fallbackLocaleOnReq = data['fallback-locale']\n }\n\n const { fallbackLocale, locale } = sanitizeLocales({\n fallbackLocale: fallbackLocaleOnReq,\n locale: localeOnReq,\n localization: config.localization,\n })\n\n const mutableRequest = request\n if (locale) mutableRequest.locale = locale\n if (fallbackLocale) mutableRequest.fallbackLocale = fallbackLocale\n return mutableRequest\n }\n\n return request\n}\n\ntype SanitizeLocalesArgs = {\n fallbackLocale: string\n locale: string\n localization: SanitizedConfig['localization']\n}\ntype SanitizeLocalesReturn = {\n fallbackLocale?: string\n locale?: string\n}\nexport const sanitizeLocales = ({\n fallbackLocale,\n locale,\n localization,\n}: SanitizeLocalesArgs): SanitizeLocalesReturn => {\n if (fallbackLocale === 'none') {\n fallbackLocale = 'null'\n } else if (localization && !localization.localeCodes.includes(fallbackLocale)) {\n fallbackLocale = localization.defaultLocale\n }\n\n if (locale === '*') {\n locale = 'all'\n } else if (localization && !localization.localeCodes.includes(locale)) {\n locale = localization.defaultLocale\n }\n\n return {\n fallbackLocale,\n locale,\n }\n}\n"],"names":["addLocalesToRequestFromData","request","data","payload","config","localeOnReq","locale","fallbackLocaleOnReq","fallbackLocale","sanitizeLocales","localization","mutableRequest","localeCodes","includes","defaultLocale"],"rangeMappings":";;;;;;;;;;;;;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PayloadRequestWithData } from 'payload/types';
|
|
2
2
|
import type { FieldSchemaMap } from './types.js';
|
|
3
|
-
export declare const buildFieldSchemaMap: ({ i18n, payload: { config }, }:
|
|
3
|
+
export declare const buildFieldSchemaMap: ({ i18n, payload: { config }, }: PayloadRequestWithData) => FieldSchemaMap;
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utilities/buildFieldSchemaMap/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utilities/buildFieldSchemaMap/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAE3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAIhD,eAAO,MAAM,mBAAmB,mCAG7B,sBAAsB,mBA4BxB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utilities/buildFieldSchemaMap/index.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../../src/utilities/buildFieldSchemaMap/index.ts"],"sourcesContent":["import type { PayloadRequestWithData } from 'payload/types'\n\nimport type { FieldSchemaMap } from './types.js'\n\nimport { traverseFields } from './traverseFields.js'\n\nexport const buildFieldSchemaMap = ({\n i18n,\n payload: { config },\n}: PayloadRequestWithData): FieldSchemaMap => {\n const result: FieldSchemaMap = new Map()\n\n const validRelationships = config.collections.map((c) => c.slug) || []\n\n config.collections.forEach((collection) => {\n traverseFields({\n config,\n fields: collection.fields,\n i18n,\n schemaMap: result,\n schemaPath: collection.slug,\n validRelationships,\n })\n })\n\n config.globals.forEach((global) => {\n traverseFields({\n config,\n fields: global.fields,\n i18n,\n schemaMap: result,\n schemaPath: global.slug,\n validRelationships,\n })\n })\n\n return result\n}\n"],"names":["traverseFields","buildFieldSchemaMap","i18n","payload","config","result","Map","validRelationships","collections","map","c","slug","forEach","collection","fields","schemaMap","schemaPath","globals","global"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,cAAc,QAAQ,sBAAqB;AAEpD,OAAO,MAAMC,sBAAsB,CAAC,EAClCC,IAAI,EACJC,SAAS,EAAEC,MAAM,EAAE,EACI;IACvB,MAAMC,SAAyB,IAAIC;IAEnC,MAAMC,qBAAqBH,OAAOI,WAAW,CAACC,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAK,EAAE;IAEtEP,OAAOI,WAAW,CAACI,OAAO,CAAC,CAACC;QAC1Bb,eAAe;YACbI;YACAU,QAAQD,WAAWC,MAAM;YACzBZ;YACAa,WAAWV;YACXW,YAAYH,WAAWF,IAAI;YAC3BJ;QACF;IACF;IAEAH,OAAOa,OAAO,CAACL,OAAO,CAAC,CAACM;QACtBlB,eAAe;YACbI;YACAU,QAAQI,OAAOJ,MAAM;YACrBZ;YACAa,WAAWV;YACXW,YAAYE,OAAOP,IAAI;YACvBJ;QACF;IACF;IAEA,OAAOF;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPayloadRequest.d.ts","sourceRoot":"","sources":["../../src/utilities/createPayloadRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"createPayloadRequest.d.ts","sourceRoot":"","sources":["../../src/utilities/createPayloadRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkC,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAapG,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,CAAA;IAClD,MAAM,CAAC,EAAE;QACP,UAAU,EAAE,MAAM,CAAA;KACnB,CAAA;IACD,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,oBAAoB,gDAI9B,IAAI,KAAG,QAAQ,cAAc,CA+E/B,CAAA"}
|
|
@@ -4,39 +4,18 @@ import { parseCookies } from 'payload/auth';
|
|
|
4
4
|
import { getDataLoader } from 'payload/utilities';
|
|
5
5
|
import qs from 'qs';
|
|
6
6
|
import { URL } from 'url';
|
|
7
|
-
import {
|
|
7
|
+
import { sanitizeLocales } from './addLocalesToRequest.js';
|
|
8
8
|
import { getPayloadHMR } from './getPayloadHMR.js';
|
|
9
9
|
import { getRequestLanguage } from './getRequestLanguage.js';
|
|
10
|
-
import { getRequestLocales } from './getRequestLocales.js';
|
|
11
10
|
export const createPayloadRequest = async ({ config: configPromise, params, request })=>{
|
|
12
11
|
const cookies = parseCookies(request.headers);
|
|
13
12
|
const payload = await getPayloadHMR({
|
|
14
13
|
config: configPromise
|
|
15
14
|
});
|
|
16
|
-
const {
|
|
17
|
-
let collection = undefined;
|
|
18
|
-
if (params?.collection && collections?.[params.collection]) {
|
|
19
|
-
collection = collections[params.collection];
|
|
20
|
-
}
|
|
15
|
+
const { config } = payload;
|
|
21
16
|
const urlProperties = new URL(request.url);
|
|
22
17
|
const { pathname, searchParams } = urlProperties;
|
|
23
18
|
const isGraphQL = !config.graphQL.disable && pathname === `${config.routes.api}${config.routes.graphQL}`;
|
|
24
|
-
const { data, file } = await getDataAndFile({
|
|
25
|
-
collection,
|
|
26
|
-
config,
|
|
27
|
-
request
|
|
28
|
-
});
|
|
29
|
-
let requestFallbackLocale;
|
|
30
|
-
let requestLocale;
|
|
31
|
-
if (config.localization) {
|
|
32
|
-
const locales = getRequestLocales({
|
|
33
|
-
data,
|
|
34
|
-
localization: config.localization,
|
|
35
|
-
searchParams
|
|
36
|
-
});
|
|
37
|
-
requestLocale = locales.locale;
|
|
38
|
-
requestFallbackLocale = locales.fallbackLocale;
|
|
39
|
-
}
|
|
40
19
|
const language = getRequestLanguage({
|
|
41
20
|
config,
|
|
42
21
|
cookies,
|
|
@@ -47,16 +26,25 @@ export const createPayloadRequest = async ({ config: configPromise, params, requ
|
|
|
47
26
|
context: 'api',
|
|
48
27
|
language
|
|
49
28
|
});
|
|
29
|
+
let locale;
|
|
30
|
+
let fallbackLocale;
|
|
31
|
+
if (config.localization) {
|
|
32
|
+
const locales = sanitizeLocales({
|
|
33
|
+
fallbackLocale: searchParams.get('fallback-locale'),
|
|
34
|
+
locale: searchParams.get('locale'),
|
|
35
|
+
localization: payload.config.localization
|
|
36
|
+
});
|
|
37
|
+
locale = locales.locale;
|
|
38
|
+
fallbackLocale = locales.fallbackLocale;
|
|
39
|
+
}
|
|
50
40
|
const customRequest = {
|
|
51
41
|
context: {},
|
|
52
|
-
|
|
53
|
-
fallbackLocale: requestFallbackLocale,
|
|
54
|
-
file,
|
|
42
|
+
fallbackLocale,
|
|
55
43
|
hash: urlProperties.hash,
|
|
56
44
|
host: urlProperties.host,
|
|
57
45
|
href: urlProperties.href,
|
|
58
46
|
i18n,
|
|
59
|
-
locale
|
|
47
|
+
locale,
|
|
60
48
|
origin: urlProperties.origin,
|
|
61
49
|
pathname: urlProperties.pathname,
|
|
62
50
|
payload,
|
|
@@ -78,7 +66,6 @@ export const createPayloadRequest = async ({ config: configPromise, params, requ
|
|
|
78
66
|
user: null
|
|
79
67
|
};
|
|
80
68
|
const req = Object.assign(request, customRequest);
|
|
81
|
-
if (data) req.json = ()=>Promise.resolve(data);
|
|
82
69
|
req.payloadDataLoader = getDataLoader(req);
|
|
83
70
|
req.user = await executeAuthStrategies({
|
|
84
71
|
cookies,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/createPayloadRequest.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/createPayloadRequest.ts"],"sourcesContent":["import type { CustomPayloadRequestProperties, PayloadRequest, SanitizedConfig } from 'payload/types'\n\nimport { initI18n } from '@payloadcms/translations'\nimport { executeAuthStrategies } from 'payload/auth'\nimport { parseCookies } from 'payload/auth'\nimport { getDataLoader } from 'payload/utilities'\nimport qs from 'qs'\nimport { URL } from 'url'\n\nimport { sanitizeLocales } from './addLocalesToRequest.js'\nimport { getPayloadHMR } from './getPayloadHMR.js'\nimport { getRequestLanguage } from './getRequestLanguage.js'\n\ntype Args = {\n config: Promise<SanitizedConfig> | SanitizedConfig\n params?: {\n collection: string\n }\n request: Request\n}\n\nexport const createPayloadRequest = async ({\n config: configPromise,\n params,\n request,\n}: Args): Promise<PayloadRequest> => {\n const cookies = parseCookies(request.headers)\n const payload = await getPayloadHMR({ config: configPromise })\n\n const { config } = payload\n\n const urlProperties = new URL(request.url)\n const { pathname, searchParams } = urlProperties\n\n const isGraphQL =\n !config.graphQL.disable && pathname === `${config.routes.api}${config.routes.graphQL}`\n\n const language = getRequestLanguage({\n config,\n cookies,\n headers: request.headers,\n })\n\n const i18n = await initI18n({\n config: config.i18n,\n context: 'api',\n language,\n })\n\n let locale\n let fallbackLocale\n if (config.localization) {\n const locales = sanitizeLocales({\n fallbackLocale: searchParams.get('fallback-locale'),\n locale: searchParams.get('locale'),\n localization: payload.config.localization,\n })\n locale = locales.locale\n fallbackLocale = locales.fallbackLocale\n }\n\n const customRequest: CustomPayloadRequestProperties = {\n context: {},\n fallbackLocale,\n hash: urlProperties.hash,\n host: urlProperties.host,\n href: urlProperties.href,\n i18n,\n locale,\n origin: urlProperties.origin,\n pathname: urlProperties.pathname,\n payload,\n payloadAPI: isGraphQL ? 'GraphQL' : 'REST',\n payloadDataLoader: undefined,\n payloadUploadSizes: {},\n port: urlProperties.port,\n protocol: urlProperties.protocol,\n query: urlProperties.search\n ? qs.parse(urlProperties.search, {\n arrayLimit: 1000,\n depth: 10,\n ignoreQueryPrefix: true,\n })\n : {},\n routeParams: params || {},\n search: urlProperties.search,\n searchParams: urlProperties.searchParams,\n t: i18n.t,\n transactionID: undefined,\n user: null,\n }\n\n const req: PayloadRequest = Object.assign(request, customRequest)\n\n req.payloadDataLoader = getDataLoader(req)\n\n req.user = await executeAuthStrategies({\n cookies,\n headers: req.headers,\n isGraphQL,\n payload,\n })\n\n return req\n}\n"],"names":["initI18n","executeAuthStrategies","parseCookies","getDataLoader","qs","URL","sanitizeLocales","getPayloadHMR","getRequestLanguage","createPayloadRequest","config","configPromise","params","request","cookies","headers","payload","urlProperties","url","pathname","searchParams","isGraphQL","graphQL","disable","routes","api","language","i18n","context","locale","fallbackLocale","localization","locales","get","customRequest","hash","host","href","origin","payloadAPI","payloadDataLoader","undefined","payloadUploadSizes","port","protocol","query","search","parse","arrayLimit","depth","ignoreQueryPrefix","routeParams","t","transactionID","user","req","Object","assign"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,YAAY,QAAQ,eAAc;AAC3C,SAASC,aAAa,QAAQ,oBAAmB;AACjD,OAAOC,QAAQ,KAAI;AACnB,SAASC,GAAG,QAAQ,MAAK;AAEzB,SAASC,eAAe,QAAQ,2BAA0B;AAC1D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,kBAAkB,QAAQ,0BAAyB;AAU5D,OAAO,MAAMC,uBAAuB,OAAO,EACzCC,QAAQC,aAAa,EACrBC,MAAM,EACNC,OAAO,EACF;IACL,MAAMC,UAAUZ,aAAaW,QAAQE,OAAO;IAC5C,MAAMC,UAAU,MAAMT,cAAc;QAAEG,QAAQC;IAAc;IAE5D,MAAM,EAAED,MAAM,EAAE,GAAGM;IAEnB,MAAMC,gBAAgB,IAAIZ,IAAIQ,QAAQK,GAAG;IACzC,MAAM,EAAEC,QAAQ,EAAEC,YAAY,EAAE,GAAGH;IAEnC,MAAMI,YACJ,CAACX,OAAOY,OAAO,CAACC,OAAO,IAAIJ,aAAa,CAAC,EAAET,OAAOc,MAAM,CAACC,GAAG,CAAC,EAAEf,OAAOc,MAAM,CAACF,OAAO,C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SAASwC,IAAIxC,OAAO;QACpBM;QACAL;IACF;IAEA,OAAOuC;AACT,EAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { Collection,
|
|
1
|
+
import type { Collection, PayloadRequestWithData, SanitizedConfig } from 'payload/types';
|
|
2
2
|
type GetDataAndFile = (args: {
|
|
3
3
|
collection: Collection;
|
|
4
4
|
config: SanitizedConfig;
|
|
5
5
|
request: Request;
|
|
6
6
|
}) => Promise<{
|
|
7
7
|
data: Record<string, any>;
|
|
8
|
-
file:
|
|
8
|
+
file: PayloadRequestWithData['file'];
|
|
9
9
|
}>;
|
|
10
10
|
export declare const getDataAndFile: GetDataAndFile;
|
|
11
11
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDataAndFile.d.ts","sourceRoot":"","sources":["../../src/utilities/getDataAndFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"getDataAndFile.d.ts","sourceRoot":"","sources":["../../src/utilities/getDataAndFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAMxF,KAAK,cAAc,GAAG,CAAC,IAAI,EAAE;IAC3B,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE,eAAe,CAAA;IACvB,OAAO,EAAE,OAAO,CAAA;CACjB,KAAK,OAAO,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACzB,IAAI,EAAE,sBAAsB,CAAC,MAAM,CAAC,CAAA;CACrC,CAAC,CAAA;AACF,eAAO,MAAM,cAAc,EAAE,cAwD5B,CAAA"}
|
|
@@ -1,56 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export const getDataAndFile = async ({ collection, config, request })=>{
|
|
1
|
+
import { fetchAPIFileUpload } from '../fetchAPI-multipart/index.js';
|
|
2
|
+
export const getDataAndFile = async ({ collection, config, request: incomingRequest })=>{
|
|
3
3
|
let data = undefined;
|
|
4
4
|
let file = undefined;
|
|
5
5
|
if ([
|
|
6
6
|
'PATCH',
|
|
7
7
|
'POST',
|
|
8
8
|
'PUT'
|
|
9
|
-
].includes(
|
|
9
|
+
].includes(incomingRequest.method.toUpperCase()) && incomingRequest.body) {
|
|
10
|
+
const request = new Request(incomingRequest);
|
|
10
11
|
const [contentType] = (request.headers.get('Content-Type') || '').split(';');
|
|
11
12
|
if (contentType === 'application/json') {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const formFile = formData.get('file');
|
|
20
|
-
if (formFile instanceof Blob) {
|
|
21
|
-
const bytes = await formFile.arrayBuffer();
|
|
22
|
-
const buffer = Buffer.from(bytes);
|
|
23
|
-
file = {
|
|
24
|
-
name: formFile.name,
|
|
25
|
-
data: buffer,
|
|
26
|
-
mimetype: formFile.type,
|
|
27
|
-
size: formFile.size
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
const payloadData = formData.get('_payload');
|
|
31
|
-
if (typeof payloadData === 'string') {
|
|
32
|
-
data = JSON.parse(payloadData);
|
|
33
|
-
}
|
|
34
|
-
} else {
|
|
35
|
-
// store temp file on disk
|
|
36
|
-
const { error, fields, files } = await nextFileUpload({
|
|
37
|
-
options: config.upload,
|
|
38
|
-
request
|
|
39
|
-
});
|
|
40
|
-
if (error) {
|
|
41
|
-
throw new Error(error.message);
|
|
42
|
-
}
|
|
43
|
-
if (files?.file) file = files.file;
|
|
44
|
-
if (fields?._payload && typeof fields._payload === 'string') {
|
|
45
|
-
data = JSON.parse(fields._payload);
|
|
46
|
-
}
|
|
13
|
+
const bodyByteSize = parseInt(request.headers.get('Content-Length') || '0', 10);
|
|
14
|
+
const upperByteLimit = typeof config.upload?.limits?.fieldSize === 'number' ? config.upload.limits.fields : undefined;
|
|
15
|
+
if (bodyByteSize <= upperByteLimit || upperByteLimit === undefined) {
|
|
16
|
+
try {
|
|
17
|
+
data = await request.json();
|
|
18
|
+
} catch (error) {
|
|
19
|
+
data = {};
|
|
47
20
|
}
|
|
48
21
|
} else {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
22
|
+
throw new Error('Request body size exceeds the limit');
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
if (request.headers.has('Content-Length') && request.headers.get('Content-Length') !== '0') {
|
|
26
|
+
const { error, fields, files } = await fetchAPIFileUpload({
|
|
27
|
+
options: config.upload,
|
|
28
|
+
request
|
|
29
|
+
});
|
|
30
|
+
if (error) {
|
|
31
|
+
throw new Error(error.message);
|
|
32
|
+
}
|
|
33
|
+
if (collection?.config?.upload && files?.file) {
|
|
34
|
+
file = files.file;
|
|
35
|
+
}
|
|
36
|
+
if (fields?._payload && typeof fields._payload === 'string') {
|
|
37
|
+
data = JSON.parse(fields._payload);
|
|
54
38
|
}
|
|
55
39
|
}
|
|
56
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getDataAndFile.ts"],"sourcesContent":["import type { Collection,
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getDataAndFile.ts"],"sourcesContent":["import type { Collection, PayloadRequestWithData, SanitizedConfig } from 'payload/types'\n\nimport type { FetchAPIFileUploadOptions } from '../fetchAPI-multipart/index.js'\n\nimport { fetchAPIFileUpload } from '../fetchAPI-multipart/index.js'\n\ntype GetDataAndFile = (args: {\n collection: Collection\n config: SanitizedConfig\n request: Request\n}) => Promise<{\n data: Record<string, any>\n file: PayloadRequestWithData['file']\n}>\nexport const getDataAndFile: GetDataAndFile = async ({\n collection,\n config,\n request: incomingRequest,\n}) => {\n let data: Record<string, any> = undefined\n let file: PayloadRequestWithData['file'] = undefined\n\n if (\n ['PATCH', 'POST', 'PUT'].includes(incomingRequest.method.toUpperCase()) &&\n incomingRequest.body\n ) {\n const request = new Request(incomingRequest)\n const [contentType] = (request.headers.get('Content-Type') || '').split(';')\n\n if (contentType === 'application/json') {\n const bodyByteSize = parseInt(request.headers.get('Content-Length') || '0', 10)\n const upperByteLimit =\n typeof config.upload?.limits?.fieldSize === 'number'\n ? config.upload.limits.fields\n : undefined\n if (bodyByteSize <= upperByteLimit || upperByteLimit === undefined) {\n try {\n data = await request.json()\n } catch (error) {\n data = {}\n }\n } else {\n throw new Error('Request body size exceeds the limit')\n }\n } else {\n if (request.headers.has('Content-Length') && request.headers.get('Content-Length') !== '0') {\n const { error, fields, files } = await fetchAPIFileUpload({\n options: config.upload as FetchAPIFileUploadOptions,\n request,\n })\n\n if (error) {\n throw new Error(error.message)\n }\n\n if (collection?.config?.upload && files?.file) {\n file = files.file\n }\n\n if (fields?._payload && typeof fields._payload === 'string') {\n data = JSON.parse(fields._payload)\n }\n }\n }\n }\n\n return {\n data,\n file,\n }\n}\n"],"names":["fetchAPIFileUpload","getDataAndFile","collection","config","request","incomingRequest","data","undefined","file","includes","method","toUpperCase","body","Request","contentType","headers","get","split","bodyByteSize","parseInt","upperByteLimit","upload","limits","fieldSize","fields","json","error","Error","has","files","options","message","_payload","JSON","parse"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,kBAAkB,QAAQ,iCAAgC;AAUnE,OAAO,MAAMC,iBAAiC,OAAO,EACnDC,UAAU,EACVC,MAAM,EACNC,SAASC,eAAe,EACzB;IACC,IAAIC,OAA4BC;IAChC,IAAIC,OAAuCD;IAE3C,IACE;QAAC;QAAS;QAAQ;KAAM,CAACE,QAAQ,CAACJ,gBAAgBK,MAAM,CAACC,WAAW,OACpEN,gBAAgBO,IAAI,EACpB;QACA,MAAMR,UAAU,IAAIS,QAAQR;QAC5B,MAAM,CAACS,YAAY,GAAG,AAACV,CAAAA,QAAQW,OAAO,CAACC,GAAG,CAAC,mBAAmB,EAAC,EAAGC,KAAK,CAAC;QAExE,IAAIH,gBAAgB,oBAAoB;YACtC,MAAMI,eAAeC,SAASf,QAAQW,OAAO,CAACC,GAAG,CAAC,qBAAqB,KAAK;YAC5E,MAAMI,iBACJ,OAAOjB,OAAOkB,MAAM,EAAEC,QAAQC,cAAc,WACxCpB,OAAOkB,MAAM,CAACC,MAAM,CAACE,MAAM,GAC3BjB;YACN,IAAIW,gBAAgBE,kBAAkBA,mBAAmBb,WAAW;gBAClE,IAAI;oBACFD,OAAO,MAAMF,QAAQqB,IAAI;gBAC3B,EAAE,OAAOC,OAAO;oBACdpB,OAAO,CAAC;gBACV;YACF,OAAO;gBACL,MAAM,IAAIqB,MAAM;YAClB;QACF,OAAO;YACL,IAAIvB,QAAQW,OAAO,CAACa,GAAG,CAAC,qBAAqBxB,QAAQW,OAAO,CAACC,GAAG,CAAC,sBAAsB,KAAK;gBAC1F,MAAM,EAAEU,KAAK,EAAEF,MAAM,EAAEK,KAAK,EAAE,GAAG,MAAM7B,mBAAmB;oBACxD8B,SAAS3B,OAAOkB,MAAM;oBACtBjB;gBACF;gBAEA,IAAIsB,OAAO;oBACT,MAAM,IAAIC,MAAMD,MAAMK,OAAO;gBAC/B;gBAEA,IAAI7B,YAAYC,QAAQkB,UAAUQ,OAAOrB,MAAM;oBAC7CA,OAAOqB,MAAMrB,IAAI;gBACnB;gBAEA,IAAIgB,QAAQQ,YAAY,OAAOR,OAAOQ,QAAQ,KAAK,UAAU;oBAC3D1B,OAAO2B,KAAKC,KAAK,CAACV,OAAOQ,QAAQ;gBACnC;YACF;QACF;IACF;IAEA,OAAO;QACL1B;QACAE;IACF;AACF,EAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Payload } from 'payload';
|
|
2
|
-
import type { InitOptions } from 'payload/config';
|
|
2
|
+
import type { InitOptions, SanitizedConfig } from 'payload/config';
|
|
3
|
+
export declare const reload: (config: SanitizedConfig, payload: Payload) => Promise<void>;
|
|
3
4
|
export declare const getPayloadHMR: (options: InitOptions) => Promise<Payload>;
|
|
4
5
|
//# sourceMappingURL=getPayloadHMR.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPayloadHMR.d.ts","sourceRoot":"","sources":["../../src/utilities/getPayloadHMR.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,OAAO,EAAE,MAAM,SAAS,CAAA;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"getPayloadHMR.d.ts","sourceRoot":"","sources":["../../src/utilities/getPayloadHMR.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,OAAO,EAAE,MAAM,SAAS,CAAA;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAgBlE,eAAO,MAAM,MAAM,WAAkB,eAAe,uBAAqB,QAAQ,IAAI,CAuBpF,CAAA;AAED,eAAO,MAAM,aAAa,YAAmB,WAAW,KAAG,QAAQ,OAAO,CA4DzE,CAAA"}
|
|
@@ -9,6 +9,27 @@ if (!cached) {
|
|
|
9
9
|
reload: false
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
+
export const reload = async (config, payload)=>{
|
|
13
|
+
if (typeof payload.db.destroy === 'function') {
|
|
14
|
+
await payload.db.destroy();
|
|
15
|
+
}
|
|
16
|
+
payload.config = config;
|
|
17
|
+
payload.collections = config.collections.reduce((collections, collection)=>{
|
|
18
|
+
collections[collection.slug] = {
|
|
19
|
+
config: collection,
|
|
20
|
+
customIDType: payload.collections[collection.slug]?.customIDType
|
|
21
|
+
};
|
|
22
|
+
return collections;
|
|
23
|
+
}, {});
|
|
24
|
+
payload.globals = {
|
|
25
|
+
config: config.globals
|
|
26
|
+
};
|
|
27
|
+
// TODO: support HMR for other props in the future (see payload/src/index init()) hat may change on Payload singleton
|
|
28
|
+
await payload.db.init();
|
|
29
|
+
await payload.db.connect({
|
|
30
|
+
hotReload: true
|
|
31
|
+
});
|
|
32
|
+
};
|
|
12
33
|
export const getPayloadHMR = async (options)=>{
|
|
13
34
|
if (!options?.config) {
|
|
14
35
|
throw new Error('Error: the payload config is required for getPayload to work.');
|
|
@@ -19,24 +40,7 @@ export const getPayloadHMR = async (options)=>{
|
|
|
19
40
|
if (cached.reload === true) {
|
|
20
41
|
let resolve;
|
|
21
42
|
cached.reload = new Promise((res)=>resolve = res);
|
|
22
|
-
|
|
23
|
-
await cached.payload.db.destroy();
|
|
24
|
-
}
|
|
25
|
-
cached.payload.config = config;
|
|
26
|
-
cached.payload.collections = config.collections.reduce((collections, collection)=>{
|
|
27
|
-
collections[collection.slug] = {
|
|
28
|
-
config: collection
|
|
29
|
-
};
|
|
30
|
-
return collections;
|
|
31
|
-
}, {});
|
|
32
|
-
cached.payload.globals = {
|
|
33
|
-
config: config.globals
|
|
34
|
-
};
|
|
35
|
-
// TODO: support HMR for other props in the future (see payload/src/index init()) hat may change on Payload singleton
|
|
36
|
-
await cached.payload.db.init();
|
|
37
|
-
await cached.payload.db.connect({
|
|
38
|
-
hotReload: true
|
|
39
|
-
});
|
|
43
|
+
await reload(config, cached.payload);
|
|
40
44
|
resolve();
|
|
41
45
|
}
|
|
42
46
|
if (cached.reload instanceof Promise) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getPayloadHMR.ts"],"sourcesContent":["import type { GeneratedTypes, Payload } from 'payload'\nimport type { InitOptions } from 'payload/config'\n\nimport { BasePayload } from 'payload'\nimport WebSocket from 'ws'\n\nlet cached: {\n payload: Payload | null\n promise: Promise<Payload> | null\n reload: Promise<boolean> | boolean\n} = global._payload\n\nif (!cached) {\n // eslint-disable-next-line no-multi-assign\n cached = global._payload = { payload: null, promise: null, reload: false }\n}\n\nexport const
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getPayloadHMR.ts"],"sourcesContent":["import type { GeneratedTypes, Payload } from 'payload'\nimport type { InitOptions, SanitizedConfig } from 'payload/config'\n\nimport { BasePayload } from 'payload'\nimport WebSocket from 'ws'\n\nlet cached: {\n payload: Payload | null\n promise: Promise<Payload> | null\n reload: Promise<boolean> | boolean\n} = global._payload\n\nif (!cached) {\n // eslint-disable-next-line no-multi-assign\n cached = global._payload = { payload: null, promise: null, reload: false }\n}\n\nexport const reload = async (config: SanitizedConfig, payload: Payload): Promise<void> => {\n if (typeof payload.db.destroy === 'function') {\n await payload.db.destroy()\n }\n\n payload.config = config\n\n payload.collections = config.collections.reduce((collections, collection) => {\n collections[collection.slug] = {\n config: collection,\n customIDType: payload.collections[collection.slug]?.customIDType,\n }\n return collections\n }, {})\n\n payload.globals = {\n config: config.globals,\n }\n\n // TODO: support HMR for other props in the future (see payload/src/index init()) hat may change on Payload singleton\n\n await payload.db.init()\n await payload.db.connect({ hotReload: true })\n}\n\nexport const getPayloadHMR = async (options: InitOptions): Promise<Payload> => {\n if (!options?.config) {\n throw new Error('Error: the payload config is required for getPayload to work.')\n }\n\n if (cached.payload) {\n const config = await options.config // TODO: check if we can move this inside the cached.reload === true condition\n\n if (cached.reload === true) {\n let resolve\n\n cached.reload = new Promise((res) => (resolve = res))\n\n await reload(config, cached.payload)\n\n resolve()\n }\n\n if (cached.reload instanceof Promise) {\n await cached.reload\n }\n\n return cached.payload\n }\n\n if (!cached.promise) {\n cached.promise = new BasePayload<GeneratedTypes>().init(options)\n }\n\n try {\n cached.payload = await cached.promise\n\n if (\n process.env.NODE_ENV !== 'production' &&\n process.env.NODE_ENV !== 'test' &&\n process.env.DISABLE_PAYLOAD_HMR !== 'true'\n ) {\n try {\n const port = process.env.PORT || '3000'\n const ws = new WebSocket(`ws://localhost:${port}/_next/webpack-hmr`)\n\n ws.onmessage = (event) => {\n if (typeof event.data === 'string') {\n const data = JSON.parse(event.data)\n\n if ('action' in data && data.action === 'serverComponentChanges') {\n cached.reload = true\n }\n }\n }\n } catch (_) {\n // swallow e\n }\n }\n } catch (e) {\n cached.promise = null\n throw e\n }\n\n return cached.payload\n}\n"],"names":["BasePayload","WebSocket","cached","global","_payload","payload","promise","reload","config","db","destroy","collections","reduce","collection","slug","customIDType","globals","init","connect","hotReload","getPayloadHMR","options","Error","resolve","Promise","res","process","env","NODE_ENV","DISABLE_PAYLOAD_HMR","port","PORT","ws","onmessage","event","data","JSON","parse","action","_","e"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,WAAW,QAAQ,UAAS;AACrC,OAAOC,eAAe,KAAI;AAE1B,IAAIC,SAIAC,OAAOC,QAAQ;AAEnB,IAAI,CAACF,QAAQ;IACX,2CAA2C;IAC3CA,SAASC,OAAOC,QAAQ,GAAG;QAAEC,SAAS;QAAMC,SAAS;QAAMC,QAAQ;IAAM;AAC3E;AAEA,OAAO,MAAMA,SAAS,OAAOC,QAAyBH;IACpD,IAAI,OAAOA,QAAQI,EAAE,CAACC,OAAO,KAAK,YAAY;QAC5C,MAAML,QAAQI,EAAE,CAACC,OAAO;IAC1B;IAEAL,QAAQG,MAAM,GAAGA;IAEjBH,QAAQM,WAAW,GAAGH,OAAOG,WAAW,CAACC,MAAM,CAAC,CAACD,aAAaE;QAC5DF,WAAW,CAACE,WAAWC,IAAI,CAAC,GAAG;YAC7BN,QAAQK;YACRE,cAAcV,QAAQM,WAAW,CAACE,WAAWC,IAAI,CAAC,EAAEC;QACtD;QACA,OAAOJ;IACT,GAAG,CAAC;IAEJN,QAAQW,OAAO,GAAG;QAChBR,QAAQA,OAAOQ,OAAO;IACxB;IAEA,qHAAqH;IAErH,MAAMX,QAAQI,EAAE,CAACQ,IAAI;IACrB,MAAMZ,QAAQI,EAAE,CAACS,OAAO,CAAC;QAAEC,WAAW;IAAK;AAC7C,EAAC;AAED,OAAO,MAAMC,gBAAgB,OAAOC;IAClC,IAAI,CAACA,SAASb,QAAQ;QACpB,MAAM,IAAIc,MAAM;IAClB;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
|
+
import type { PayloadRequestWithData } from 'payload/types';
|
|
2
|
+
type CorsArgs = {
|
|
3
|
+
headers: Headers;
|
|
4
|
+
req: Partial<PayloadRequestWithData>;
|
|
5
|
+
};
|
|
6
|
+
export declare const headersWithCors: ({ headers, req }: CorsArgs) => Headers;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=headersWithCors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headersWithCors.d.ts","sourceRoot":"","sources":["../../src/utilities/headersWithCors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAE3D,KAAK,QAAQ,GAAG;IACd,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAA;CACrC,CAAA;AACD,eAAO,MAAM,eAAe,qBAAsB,QAAQ,KAAG,OAoB5D,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const headersWithCors = ({ headers, req })=>{
|
|
2
|
+
const cors = req?.payload.config.cors;
|
|
3
|
+
const requestOrigin = req?.headers.get('Origin');
|
|
4
|
+
if (cors) {
|
|
5
|
+
headers.set('Access-Control-Allow-Methods', 'PUT, PATCH, POST, GET, DELETE, OPTIONS');
|
|
6
|
+
headers.set('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization, Content-Encoding, x-apollo-tracing');
|
|
7
|
+
if (cors === '*') {
|
|
8
|
+
headers.set('Access-Control-Allow-Origin', '*');
|
|
9
|
+
} else if (Array.isArray(cors) && cors.indexOf(requestOrigin) > -1) {
|
|
10
|
+
headers.set('Access-Control-Allow-Credentials', 'true');
|
|
11
|
+
headers.set('Access-Control-Allow-Origin', requestOrigin);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return headers;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=headersWithCors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/headersWithCors.ts"],"sourcesContent":["import type { PayloadRequestWithData } from 'payload/types'\n\ntype CorsArgs = {\n headers: Headers\n req: Partial<PayloadRequestWithData>\n}\nexport const headersWithCors = ({ headers, req }: CorsArgs): Headers => {\n const cors = req?.payload.config.cors\n const requestOrigin = req?.headers.get('Origin')\n\n if (cors) {\n headers.set('Access-Control-Allow-Methods', 'PUT, PATCH, POST, GET, DELETE, OPTIONS')\n headers.set(\n 'Access-Control-Allow-Headers',\n 'Origin, X-Requested-With, Content-Type, Accept, Authorization, Content-Encoding, x-apollo-tracing',\n )\n\n if (cors === '*') {\n headers.set('Access-Control-Allow-Origin', '*')\n } else if (Array.isArray(cors) && cors.indexOf(requestOrigin) > -1) {\n headers.set('Access-Control-Allow-Credentials', 'true')\n headers.set('Access-Control-Allow-Origin', requestOrigin)\n }\n }\n\n return headers\n}\n"],"names":["headersWithCors","headers","req","cors","payload","config","requestOrigin","get","set","Array","isArray","indexOf"],"rangeMappings":";;;;;;;;;;;;;;","mappings":"AAMA,OAAO,MAAMA,kBAAkB,CAAC,EAAEC,OAAO,EAAEC,GAAG,EAAY;IACxD,MAAMC,OAAOD,KAAKE,QAAQC,OAAOF;IACjC,MAAMG,gBAAgBJ,KAAKD,QAAQM,IAAI;IAEvC,IAAIJ,MAAM;QACRF,QAAQO,GAAG,CAAC,gCAAgC;QAC5CP,QAAQO,GAAG,CACT,gCACA;QAGF,IAAIL,SAAS,KAAK;YAChBF,QAAQO,GAAG,CAAC,+BAA+B;QAC7C,OAAO,IAAIC,MAAMC,OAAO,CAACP,SAASA,KAAKQ,OAAO,CAACL,iBAAiB,CAAC,GAAG;YAClEL,QAAQO,GAAG,CAAC,oCAAoC;YAChDP,QAAQO,GAAG,CAAC,+BAA+BF;QAC7C;IACF;IAEA,OAAOL;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initPage.d.ts","sourceRoot":"","sources":["../../src/utilities/initPage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAGd,eAAe,EAGhB,MAAM,eAAe,CAAA;AAatB,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,CAAA;IAClD,2BAA2B,CAAC,EAAE,OAAO,CAAA;IACrC,KAAK,EAAE,MAAM,CAAA;IACb,YAAY,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAA;KAAE,CAAA;CAC/D,CAAA;
|
|
1
|
+
{"version":3,"file":"initPage.d.ts","sourceRoot":"","sources":["../../src/utilities/initPage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAGd,eAAe,EAGhB,MAAM,eAAe,CAAA;AAatB,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,CAAA;IAClD,2BAA2B,CAAC,EAAE,OAAO,CAAA;IACrC,KAAK,EAAE,MAAM,CAAA;IACb,YAAY,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAA;KAAE,CAAA;CAC/D,CAAA;AAYD,eAAO,MAAM,QAAQ,iFAKlB,IAAI,KAAG,QAAQ,cAAc,CAyG/B,CAAA"}
|
|
@@ -7,6 +7,15 @@ import { createLocalReq, isEntityHidden } from 'payload/utilities';
|
|
|
7
7
|
import qs from 'qs';
|
|
8
8
|
import { getPayloadHMR } from '../utilities/getPayloadHMR.js';
|
|
9
9
|
import { getRequestLanguage } from './getRequestLanguage.js';
|
|
10
|
+
const authRoutes = [
|
|
11
|
+
'/login',
|
|
12
|
+
'/logout',
|
|
13
|
+
'/create-first-user',
|
|
14
|
+
'/forgot',
|
|
15
|
+
'/reset',
|
|
16
|
+
'/verify',
|
|
17
|
+
'/logout-inactivity'
|
|
18
|
+
];
|
|
10
19
|
export const initPage = async ({ config: configPromise, redirectUnauthenticatedUser = false, route, searchParams })=>{
|
|
11
20
|
const headers = getHeaders();
|
|
12
21
|
const localeParam = searchParams?.locale;
|
|
@@ -58,16 +67,21 @@ export const initPage = async ({ config: configPromise, redirectUnauthenticatedU
|
|
|
58
67
|
user
|
|
59
68
|
}) ? slug : null).filter(Boolean)
|
|
60
69
|
};
|
|
61
|
-
const
|
|
70
|
+
const { routes: { admin: adminRoute } } = payload.config;
|
|
71
|
+
const routeSegments = route.replace(adminRoute, '').split('/').filter(Boolean);
|
|
62
72
|
const [entityType, entitySlug, createOrID] = routeSegments;
|
|
63
73
|
const collectionSlug = entityType === 'collections' ? entitySlug : undefined;
|
|
64
74
|
const globalSlug = entityType === 'globals' ? entitySlug : undefined;
|
|
65
75
|
const docID = collectionSlug && createOrID !== 'create' ? createOrID : undefined;
|
|
66
|
-
|
|
76
|
+
const isAuthRoute = authRoutes.some((r)=>r === route.replace(adminRoute, ''));
|
|
77
|
+
if (redirectUnauthenticatedUser && !user && !isAuthRoute) {
|
|
67
78
|
if (searchParams && 'redirect' in searchParams) delete searchParams.redirect;
|
|
68
79
|
const stringifiedSearchParams = Object.keys(searchParams ?? {}).length ? `?${qs.stringify(searchParams)}` : '';
|
|
69
80
|
redirect(`${routes.admin}/login?redirect=${route + stringifiedSearchParams}`);
|
|
70
81
|
}
|
|
82
|
+
if (!permissions.canAccessAdmin && !isAuthRoute) {
|
|
83
|
+
notFound();
|
|
84
|
+
}
|
|
71
85
|
let collectionConfig;
|
|
72
86
|
let globalConfig;
|
|
73
87
|
if (collectionSlug) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/initPage.ts"],"sourcesContent":["import type {\n InitPageResult,\n
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/initPage.ts"],"sourcesContent":["import type {\n InitPageResult,\n PayloadRequestWithData,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SanitizedGlobalConfig,\n VisibleEntities,\n} from 'payload/types'\n\nimport { initI18n } from '@payloadcms/translations'\nimport { findLocaleFromCode } from '@payloadcms/ui/utilities/findLocaleFromCode'\nimport { headers as getHeaders } from 'next/headers.js'\nimport { notFound, redirect } from 'next/navigation.js'\nimport { parseCookies } from 'payload/auth'\nimport { createLocalReq, isEntityHidden } from 'payload/utilities'\nimport qs from 'qs'\n\nimport { getPayloadHMR } from '../utilities/getPayloadHMR.js'\nimport { getRequestLanguage } from './getRequestLanguage.js'\n\ntype Args = {\n config: Promise<SanitizedConfig> | SanitizedConfig\n redirectUnauthenticatedUser?: boolean\n route: string\n searchParams: { [key: string]: string | string[] | undefined }\n}\n\nconst authRoutes = [\n '/login',\n '/logout',\n '/create-first-user',\n '/forgot',\n '/reset',\n '/verify',\n '/logout-inactivity',\n]\n\nexport const initPage = async ({\n config: configPromise,\n redirectUnauthenticatedUser = false,\n route,\n searchParams,\n}: Args): Promise<InitPageResult> => {\n const headers = getHeaders()\n const localeParam = searchParams?.locale as string\n const payload = await getPayloadHMR({ config: configPromise })\n const { collections, globals, localization, routes } = payload.config\n\n const queryString = `${qs.stringify(searchParams ?? {}, { addQueryPrefix: true })}`\n const defaultLocale =\n localization && localization.defaultLocale ? localization.defaultLocale : 'en'\n const localeCode = localeParam || defaultLocale\n const locale = localization && findLocaleFromCode(localization, localeCode)\n const cookies = parseCookies(headers)\n const language = getRequestLanguage({ config: payload.config, cookies, headers })\n\n const i18n = await initI18n({\n config: payload.config.i18n,\n context: 'client',\n language,\n })\n\n const req = await createLocalReq(\n {\n fallbackLocale: null,\n locale: locale.code,\n req: {\n i18n,\n query: qs.parse(queryString, {\n depth: 10,\n ignoreQueryPrefix: true,\n }),\n url: `${payload.config.serverURL}${route}${searchParams ? queryString : ''}`,\n } as PayloadRequestWithData,\n },\n payload,\n )\n\n const { permissions, user } = await payload.auth({ headers, req })\n\n req.user = user\n\n const visibleEntities: VisibleEntities = {\n collections: payload.config.collections\n .map(({ slug, admin: { hidden } }) => (!isEntityHidden({ hidden, user }) ? slug : null))\n .filter(Boolean),\n globals: payload.config.globals\n .map(({ slug, admin: { hidden } }) => (!isEntityHidden({ hidden, user }) ? slug : null))\n .filter(Boolean),\n }\n\n const {\n routes: { admin: adminRoute },\n } = payload.config\n\n const routeSegments = route.replace(adminRoute, '').split('/').filter(Boolean)\n const [entityType, entitySlug, createOrID] = routeSegments\n const collectionSlug = entityType === 'collections' ? entitySlug : undefined\n const globalSlug = entityType === 'globals' ? entitySlug : undefined\n const docID = collectionSlug && createOrID !== 'create' ? createOrID : undefined\n\n const isAuthRoute = authRoutes.some((r) => r === route.replace(adminRoute, ''))\n\n if (redirectUnauthenticatedUser && !user && !isAuthRoute) {\n if (searchParams && 'redirect' in searchParams) delete searchParams.redirect\n\n const stringifiedSearchParams = Object.keys(searchParams ?? {}).length\n ? `?${qs.stringify(searchParams)}`\n : ''\n\n redirect(`${routes.admin}/login?redirect=${route + stringifiedSearchParams}`)\n }\n\n if (!permissions.canAccessAdmin && !isAuthRoute) {\n notFound()\n }\n\n let collectionConfig: SanitizedCollectionConfig\n let globalConfig: SanitizedGlobalConfig\n\n if (collectionSlug) {\n collectionConfig = collections.find((collection) => collection.slug === collectionSlug)\n\n if (!collectionConfig) {\n notFound()\n }\n }\n\n if (globalSlug) {\n globalConfig = globals.find((global) => global.slug === globalSlug)\n\n if (!globalConfig) {\n notFound()\n }\n }\n\n return {\n collectionConfig,\n cookies,\n docID,\n globalConfig,\n locale,\n permissions,\n req,\n translations: i18n.translations,\n visibleEntities,\n }\n}\n"],"names":["initI18n","findLocaleFromCode","headers","getHeaders","notFound","redirect","parseCookies","createLocalReq","isEntityHidden","qs","getPayloadHMR","getRequestLanguage","authRoutes","initPage","config","configPromise","redirectUnauthenticatedUser","route","searchParams","localeParam","locale","payload","collections","globals","localization","routes","queryString","stringify","addQueryPrefix","defaultLocale","localeCode","cookies","language","i18n","context","req","fallbackLocale","code","query","parse","depth","ignoreQueryPrefix","url","serverURL","permissions","user","auth","visibleEntities","map","slug","admin","hidden","filter","Boolean","adminRoute","routeSegments","replace","split","entityType","entitySlug","createOrID","collectionSlug","undefined","globalSlug","docID","isAuthRoute","some","r","stringifiedSearchParams","Object","keys","length","canAccessAdmin","collectionConfig","globalConfig","find","collection","global","translations"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AASA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,kBAAkB,QAAQ,8CAA6C;AAChF,SAASC,WAAWC,UAAU,QAAQ,kBAAiB;AACvD,SAASC,QAAQ,EAAEC,QAAQ,QAAQ,qBAAoB;AACvD,SAASC,YAAY,QAAQ,eAAc;AAC3C,SAASC,cAAc,EAAEC,cAAc,QAAQ,oBAAmB;AAClE,OAAOC,QAAQ,KAAI;AAEnB,SAASC,aAAa,QAAQ,gCAA+B;AAC7D,SAASC,kBAAkB,QAAQ,0BAAyB;AAS5D,MAAMC,aAAa;IACjB;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,OAAO,MAAMC,WAAW,OAAO,EAC7BC,QAAQC,aAAa,EACrBC,8BAA8B,KAAK,EACnCC,KAAK,EACLC,YAAY,EACP;IACL,MAAMhB,UAAUC;IAChB,MAAMgB,cAAcD,cAAcE;IAClC,MAAMC,UAAU,MAAMX,cAAc;QAAEI,QAAQC;IAAc;IAC5D,MAAM,EAAEO,WAAW,EAAEC,OAAO,EAAEC,YAAY,EAAEC,MAAM,EAAE,GAAGJ,QAAQP,MAAM;IAErE,MAAMY,cAAc,CAAC,EAAEjB,GAAGkB,SAAS,CAACT,gBAAgB,CAAC,GAAG;QAAEU,gBAAgB;IAAK,GAAG,CAAC;IACnF,MAAMC,gBACJL,gBAAgBA,aAAaK,aAAa,GAAGL,aAAaK,aAAa,GAAG;IAC5E,MAAMC,aAAaX,eAAeU;IACl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qs';
|
|
17
17
|
import * as React from 'react';
|
|
18
18
|
import { toast } from 'react-toastify';
|
|
19
|
-
import {
|
|
19
|
+
import { SetDocumentStepNav } from '../Edit/Default/SetDocumentStepNav/index.js';
|
|
20
20
|
import { RenderJSON } from './RenderJSON/index.js';
|
|
21
21
|
const baseClass = 'query-inspector';
|
|
22
22
|
export const APIViewClient = ()=>{
|
|
@@ -93,7 +93,7 @@ export const APIViewClient = ()=>{
|
|
|
93
93
|
fullscreen && `${baseClass}--fullscreen`
|
|
94
94
|
].filter(Boolean).join(' '),
|
|
95
95
|
right: false
|
|
96
|
-
}, /*#__PURE__*/ React.createElement(
|
|
96
|
+
}, /*#__PURE__*/ React.createElement(SetDocumentStepNav, {
|
|
97
97
|
collectionSlug: collectionSlug,
|
|
98
98
|
globalLabel: globalConfig?.label,
|
|
99
99
|
globalSlug: globalSlug,
|