@payloadcms/next 3.16.0 → 3.17.0
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/layouts/Root/index.d.ts.map +1 -1
- package/dist/layouts/Root/index.js +8 -11
- package/dist/layouts/Root/index.js.map +1 -1
- package/dist/prod/styles.css +1 -1
- package/dist/routes/rest/index.d.ts.map +1 -1
- package/dist/routes/rest/index.js +1 -0
- package/dist/routes/rest/index.js.map +1 -1
- package/dist/utilities/initPage/index.d.ts.map +1 -1
- package/dist/utilities/initPage/index.js +9 -22
- package/dist/utilities/initPage/index.js.map +1 -1
- package/dist/utilities/initReq.d.ts +4 -5
- package/dist/utilities/initReq.d.ts.map +1 -1
- package/dist/utilities/initReq.js +31 -12
- package/dist/utilities/initReq.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/routes/rest/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/routes/rest/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,SAAS,CAAA;AAoC/D,eAAO,MAAM,OAAO,WA7BT,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,eACnC,OAAO,KAAG,OAAO,CAAC,QAAQ,CA4BP,CAAA;AAErC,eAAO,MAAM,GAAG,WA/BL,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,eACnC,OAAO,KAAG,OAAO,CAAC,QAAQ,CA8BX,CAAA;AAEjC,eAAO,MAAM,IAAI,WAjCN,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,eACnC,OAAO,KAAG,OAAO,CAAC,QAAQ,CAgCV,CAAA;AAElC,eAAO,MAAM,MAAM,WAnCR,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,eACnC,OAAO,KAAG,OAAO,CAAC,QAAQ,CAkCR,CAAA;AAEpC,eAAO,MAAM,KAAK,WArCP,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,eACnC,OAAO,KAAG,OAAO,CAAC,QAAQ,CAoCT,CAAA;AAEnC,eAAO,MAAM,GAAG,WAvCL,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,eACnC,OAAO,KAAG,OAAO,CAAC,QAAQ,CAsCX,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["handleEndpoints","generateOGImage","initedOGEndpoint","handlerBuilder","config","request","awaitedConfig","endpoints","some","endpoint","path","method","push","handler","response","OPTIONS","GET","POST","DELETE","PATCH","PUT"],"sources":["../../../src/routes/rest/index.ts"],"sourcesContent":["import { handleEndpoints, type SanitizedConfig } from 'payload'\n\nimport { generateOGImage } from './og/index.js'\n\nlet initedOGEndpoint = false\n\nconst handlerBuilder =\n (config: Promise<SanitizedConfig> | SanitizedConfig) =>\n async (request: Request): Promise<Response> => {\n const awaitedConfig = await config\n\n // Add this endpoint only when using Next.js, still can be overriden.\n if (\n initedOGEndpoint === false &&\n !awaitedConfig.endpoints.some(\n (endpoint) => endpoint.path === '/og' && endpoint.method === 'get',\n )\n ) {\n awaitedConfig.endpoints.push({\n handler: generateOGImage,\n method: 'get',\n path: '/og',\n })\n }\n\n initedOGEndpoint = true\n\n const response = await handleEndpoints({\n config,\n request,\n })\n\n return response\n }\n\nexport const OPTIONS = handlerBuilder\n\nexport const GET = handlerBuilder\n\nexport const POST = handlerBuilder\n\nexport const DELETE = handlerBuilder\n\nexport const PATCH = handlerBuilder\n\nexport const PUT = handlerBuilder\n"],"mappings":"AAAA,SAASA,eAAe,QAA8B;AAEtD,SAASC,eAAe,QAAQ;AAEhC,IAAIC,gBAAA,GAAmB;AAEvB,MAAMC,cAAA,GACHC,MAAA,IACD,MAAOC,OAAA;EACL,MAAMC,aAAA,GAAgB,MAAMF,MAAA;EAE5B;EACA,IACEF,gBAAA,KAAqB,SACrB,CAACI,aAAA,CAAcC,SAAS,CAACC,IAAI,CAC1BC,QAAA,IAAaA,QAAA,CAASC,IAAI,KAAK,SAASD,QAAA,CAASE,MAAM,KAAK,QAE/D;IACAL,aAAA,CAAcC,SAAS,CAACK,IAAI,CAAC;MAC3BC,OAAA,EAASZ,eAAA;MACTU,MAAA,EAAQ;MACRD,IAAA,EAAM;IACR;EACF;EAEAR,gBAAA,GAAmB;EAEnB,MAAMY,QAAA,GAAW,MAAMd,eAAA,CAAgB;
|
|
1
|
+
{"version":3,"file":"index.js","names":["handleEndpoints","generateOGImage","initedOGEndpoint","handlerBuilder","config","request","awaitedConfig","endpoints","some","endpoint","path","method","push","handler","response","basePath","process","env","NEXT_BASE_PATH","OPTIONS","GET","POST","DELETE","PATCH","PUT"],"sources":["../../../src/routes/rest/index.ts"],"sourcesContent":["import { handleEndpoints, type SanitizedConfig } from 'payload'\n\nimport { generateOGImage } from './og/index.js'\n\nlet initedOGEndpoint = false\n\nconst handlerBuilder =\n (config: Promise<SanitizedConfig> | SanitizedConfig) =>\n async (request: Request): Promise<Response> => {\n const awaitedConfig = await config\n\n // Add this endpoint only when using Next.js, still can be overriden.\n if (\n initedOGEndpoint === false &&\n !awaitedConfig.endpoints.some(\n (endpoint) => endpoint.path === '/og' && endpoint.method === 'get',\n )\n ) {\n awaitedConfig.endpoints.push({\n handler: generateOGImage,\n method: 'get',\n path: '/og',\n })\n }\n\n initedOGEndpoint = true\n\n const response = await handleEndpoints({\n basePath: process.env.NEXT_BASE_PATH,\n config,\n request,\n })\n\n return response\n }\n\nexport const OPTIONS = handlerBuilder\n\nexport const GET = handlerBuilder\n\nexport const POST = handlerBuilder\n\nexport const DELETE = handlerBuilder\n\nexport const PATCH = handlerBuilder\n\nexport const PUT = handlerBuilder\n"],"mappings":"AAAA,SAASA,eAAe,QAA8B;AAEtD,SAASC,eAAe,QAAQ;AAEhC,IAAIC,gBAAA,GAAmB;AAEvB,MAAMC,cAAA,GACHC,MAAA,IACD,MAAOC,OAAA;EACL,MAAMC,aAAA,GAAgB,MAAMF,MAAA;EAE5B;EACA,IACEF,gBAAA,KAAqB,SACrB,CAACI,aAAA,CAAcC,SAAS,CAACC,IAAI,CAC1BC,QAAA,IAAaA,QAAA,CAASC,IAAI,KAAK,SAASD,QAAA,CAASE,MAAM,KAAK,QAE/D;IACAL,aAAA,CAAcC,SAAS,CAACK,IAAI,CAAC;MAC3BC,OAAA,EAASZ,eAAA;MACTU,MAAA,EAAQ;MACRD,IAAA,EAAM;IACR;EACF;EAEAR,gBAAA,GAAmB;EAEnB,MAAMY,QAAA,GAAW,MAAMd,eAAA,CAAgB;IACrCe,QAAA,EAAUC,OAAA,CAAQC,GAAG,CAACC,cAAc;IACpCd,MAAA;IACAC;EACF;EAEA,OAAOS,QAAA;AACT;AAEF,OAAO,MAAMK,OAAA,GAAUhB,cAAA;AAEvB,OAAO,MAAMiB,GAAA,GAAMjB,cAAA;AAEnB,OAAO,MAAMkB,IAAA,GAAOlB,cAAA;AAEpB,OAAO,MAAMmB,MAAA,GAASnB,cAAA;AAEtB,OAAO,MAAMoB,KAAA,GAAQpB,cAAA;AAErB,OAAO,MAAMqB,GAAA,GAAMrB,cAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utilities/initPage/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utilities/initPage/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAmB,MAAM,SAAS,CAAA;AAO9D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAQtC,eAAO,MAAM,QAAQ,+DAKlB,IAAI,KAAG,OAAO,CAAC,cAAc,CA4F/B,CAAA"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { headers as getHeaders } from 'next/headers.js';
|
|
2
2
|
import { notFound } from 'next/navigation.js';
|
|
3
|
-
import {
|
|
3
|
+
import { getPayload, isEntityHidden, parseCookies } from 'payload';
|
|
4
4
|
import * as qs from 'qs-esm';
|
|
5
|
-
import { getRequestLocale } from '../getRequestLocale.js';
|
|
6
5
|
import { initReq } from '../initReq.js';
|
|
7
6
|
import { getRouteInfo } from './handleAdminPage.js';
|
|
8
7
|
import { handleAuthRedirect } from './handleAuthRedirect.js';
|
|
@@ -31,27 +30,20 @@ export const initPage = async ({
|
|
|
31
30
|
} = payload.config;
|
|
32
31
|
const cookies = parseCookies(headers);
|
|
33
32
|
const {
|
|
34
|
-
|
|
33
|
+
locale,
|
|
35
34
|
permissions,
|
|
36
|
-
|
|
37
|
-
} = await initReq(payload.config
|
|
38
|
-
// Ideally, we should not need to recreate the req, because
|
|
39
|
-
// we can get it from the above initReq.
|
|
40
|
-
// We just need to -overwrite- the url and query of the req
|
|
41
|
-
// we get above. Clone the req? We'll look into that eventually.
|
|
42
|
-
const req = await createLocalReq({
|
|
35
|
+
req
|
|
36
|
+
} = await initReq(payload.config, {
|
|
43
37
|
fallbackLocale: false,
|
|
44
38
|
req: {
|
|
45
39
|
headers,
|
|
46
|
-
host: headers.get('host'),
|
|
47
|
-
i18n: i18n,
|
|
48
40
|
query: qs.parse(queryString, {
|
|
49
41
|
depth: 10,
|
|
50
42
|
ignoreQueryPrefix: true
|
|
51
43
|
}),
|
|
52
44
|
url: `${payload.config.serverURL}${route}${searchParams ? queryString : ''}`
|
|
53
45
|
}
|
|
54
|
-
}
|
|
46
|
+
});
|
|
55
47
|
const languageOptions = Object.entries(payload.config.i18n.supportedLanguages || {}).reduce((acc, [language, languageConfig]) => {
|
|
56
48
|
if (Object.keys(payload.config.i18n.supportedLanguages).includes(language)) {
|
|
57
49
|
acc.push({
|
|
@@ -61,11 +53,6 @@ export const initPage = async ({
|
|
|
61
53
|
}
|
|
62
54
|
return acc;
|
|
63
55
|
}, []);
|
|
64
|
-
req.user = user;
|
|
65
|
-
const locale = await getRequestLocale({
|
|
66
|
-
req
|
|
67
|
-
});
|
|
68
|
-
req.locale = locale?.code;
|
|
69
56
|
const visibleEntities = {
|
|
70
57
|
collections: collections.map(({
|
|
71
58
|
slug,
|
|
@@ -74,7 +61,7 @@ export const initPage = async ({
|
|
|
74
61
|
}
|
|
75
62
|
}) => !isEntityHidden({
|
|
76
63
|
hidden,
|
|
77
|
-
user
|
|
64
|
+
user: req.user
|
|
78
65
|
}) ? slug : null).filter(Boolean),
|
|
79
66
|
globals: globals.map(({
|
|
80
67
|
slug,
|
|
@@ -83,7 +70,7 @@ export const initPage = async ({
|
|
|
83
70
|
}
|
|
84
71
|
}) => !isEntityHidden({
|
|
85
72
|
hidden,
|
|
86
|
-
user
|
|
73
|
+
user: req.user
|
|
87
74
|
}) ? slug : null).filter(Boolean)
|
|
88
75
|
};
|
|
89
76
|
let redirectTo = null;
|
|
@@ -100,7 +87,7 @@ export const initPage = async ({
|
|
|
100
87
|
config: payload.config,
|
|
101
88
|
route,
|
|
102
89
|
searchParams,
|
|
103
|
-
user
|
|
90
|
+
user: req.user
|
|
104
91
|
});
|
|
105
92
|
}
|
|
106
93
|
const {
|
|
@@ -129,7 +116,7 @@ export const initPage = async ({
|
|
|
129
116
|
permissions,
|
|
130
117
|
redirectTo,
|
|
131
118
|
req,
|
|
132
|
-
translations: i18n.translations,
|
|
119
|
+
translations: req.i18n.translations,
|
|
133
120
|
visibleEntities
|
|
134
121
|
};
|
|
135
122
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["headers","getHeaders","notFound","
|
|
1
|
+
{"version":3,"file":"index.js","names":["headers","getHeaders","notFound","getPayload","isEntityHidden","parseCookies","qs","initReq","getRouteInfo","handleAuthRedirect","isCustomAdminView","isPublicAdminRoute","initPage","config","configPromise","importMap","route","searchParams","payload","queryString","stringify","addQueryPrefix","collections","globals","routes","admin","adminRoute","cookies","locale","permissions","req","fallbackLocale","query","parse","depth","ignoreQueryPrefix","url","serverURL","languageOptions","Object","entries","i18n","supportedLanguages","reduce","acc","language","languageConfig","keys","includes","push","label","translations","general","thisLanguage","value","visibleEntities","map","slug","hidden","user","filter","Boolean","redirectTo","canAccessAdmin","collectionConfig","collectionSlug","docID","globalConfig","globalSlug","defaultIDType","db"],"sources":["../../../src/utilities/initPage/index.ts"],"sourcesContent":["import type { InitPageResult, VisibleEntities } from 'payload'\n\nimport { headers as getHeaders } from 'next/headers.js'\nimport { notFound } from 'next/navigation.js'\nimport { getPayload, isEntityHidden, parseCookies } from 'payload'\nimport * as qs from 'qs-esm'\n\nimport type { Args } from './types.js'\n\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 getPayload({ config: configPromise, importMap })\n const queryString = `${qs.stringify(searchParams ?? {}, { addQueryPrefix: true })}`\n\n const {\n collections,\n globals,\n routes: { admin: adminRoute },\n } = payload.config\n\n const cookies = parseCookies(headers)\n\n const { locale, permissions, req } = await initReq(payload.config, {\n fallbackLocale: false,\n req: {\n headers,\n query: qs.parse(queryString, {\n depth: 10,\n ignoreQueryPrefix: true,\n }),\n url: `${payload.config.serverURL}${route}${searchParams ? queryString : ''}`,\n },\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 const visibleEntities: VisibleEntities = {\n collections: collections\n .map(({ slug, admin: { hidden } }) =>\n !isEntityHidden({ hidden, user: req.user }) ? slug : null,\n )\n .filter(Boolean),\n globals: globals\n .map(({ slug, admin: { hidden } }) =>\n !isEntityHidden({ hidden, user: req.user }) ? slug : null,\n )\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: req.user,\n })\n }\n\n const { collectionConfig, collectionSlug, docID, globalConfig, globalSlug } = getRouteInfo({\n adminRoute,\n config: payload.config,\n defaultIDType: payload.db.defaultIDType,\n payload,\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: req.i18n.translations,\n visibleEntities,\n }\n}\n"],"mappings":"AAEA,SAASA,OAAA,IAAWC,UAAU,QAAQ;AACtC,SAASC,QAAQ,QAAQ;AACzB,SAASC,UAAU,EAAEC,cAAc,EAAEC,YAAY,QAAQ;AACzD,YAAYC,EAAA,MAAQ;AAIpB,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,MAAMjB,OAAA,GAAU,MAAMC,UAAA;EACtB,MAAMiB,OAAA,GAAU,MAAMf,UAAA,CAAW;IAAEU,MAAA,EAAQC,aAAA;IAAeC;EAAU;EACpE,MAAMI,WAAA,GAAc,GAAGb,EAAA,CAAGc,SAAS,CAACH,YAAA,IAAgB,CAAC,GAAG;IAAEI,cAAA,EAAgB;EAAK,IAAI;EAEnF,MAA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,YAAY;IACnCI;EACF;AACF","ignoreList":[]}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
1
|
+
import type { Locale, PayloadRequest, SanitizedConfig, SanitizedPermissions } from 'payload';
|
|
2
|
+
import { createLocalReq } from 'payload';
|
|
3
3
|
type Result = {
|
|
4
|
-
|
|
4
|
+
locale?: Locale;
|
|
5
5
|
permissions: SanitizedPermissions;
|
|
6
6
|
req: PayloadRequest;
|
|
7
|
-
user: User;
|
|
8
7
|
};
|
|
9
|
-
export declare const initReq: (configPromise: Promise<SanitizedConfig> | SanitizedConfig) => Promise<Result>;
|
|
8
|
+
export declare const initReq: (configPromise: Promise<SanitizedConfig> | SanitizedConfig, overrides?: Parameters<typeof createLocalReq>[0]) => Promise<Result>;
|
|
10
9
|
export {};
|
|
11
10
|
//# sourceMappingURL=initReq.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initReq.d.ts","sourceRoot":"","sources":["../../src/utilities/initReq.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"initReq.d.ts","sourceRoot":"","sources":["../../src/utilities/initReq.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAI5F,OAAO,EACL,cAAc,EAMf,MAAM,SAAS,CAAA;AAKhB,KAAK,MAAM,GAAG;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,oBAAoB,CAAA;IACjC,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,OAAO,kBACH,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,cAC7C,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,KAC/C,OAAO,CAAC,MAAM,CA6Df,CAAA"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { initI18n } from '@payloadcms/translations';
|
|
2
2
|
import { headers as getHeaders } from 'next/headers.js';
|
|
3
|
-
import { createLocalReq, getPayload, getRequestLanguage, parseCookies } from 'payload';
|
|
3
|
+
import { createLocalReq, executeAuthStrategies, getAccessResults, getPayload, getRequestLanguage, parseCookies } from 'payload';
|
|
4
4
|
import { cache } from 'react';
|
|
5
|
-
|
|
5
|
+
import { getRequestLocale } from './getRequestLocale.js';
|
|
6
|
+
export const initReq = cache(async function (configPromise, overrides) {
|
|
6
7
|
const config = await configPromise;
|
|
7
8
|
const payload = await getPayload({
|
|
8
9
|
config
|
|
@@ -19,26 +20,44 @@ export const initReq = cache(async function (configPromise) {
|
|
|
19
20
|
context: 'client',
|
|
20
21
|
language: languageCode
|
|
21
22
|
});
|
|
23
|
+
/**
|
|
24
|
+
* Cannot simply call `payload.auth` here, as we need the user to get the locale, and we need the locale to get the access results
|
|
25
|
+
* I.e. the `payload.auth` function would call `getAccessResults` without a fully-formed `req` object
|
|
26
|
+
*/
|
|
27
|
+
const {
|
|
28
|
+
responseHeaders,
|
|
29
|
+
user
|
|
30
|
+
} = await executeAuthStrategies({
|
|
31
|
+
headers,
|
|
32
|
+
payload
|
|
33
|
+
});
|
|
34
|
+
const {
|
|
35
|
+
req: reqOverrides,
|
|
36
|
+
...optionsOverrides
|
|
37
|
+
} = overrides || {};
|
|
22
38
|
const req = await createLocalReq({
|
|
23
39
|
req: {
|
|
24
40
|
headers,
|
|
25
41
|
host: headers.get('host'),
|
|
26
42
|
i18n: i18n,
|
|
27
|
-
|
|
28
|
-
|
|
43
|
+
responseHeaders,
|
|
44
|
+
url: `${payload.config.serverURL}`,
|
|
45
|
+
user,
|
|
46
|
+
...(reqOverrides || {})
|
|
47
|
+
},
|
|
48
|
+
...(optionsOverrides || {})
|
|
29
49
|
}, payload);
|
|
30
|
-
const {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
50
|
+
const locale = await getRequestLocale({
|
|
51
|
+
req
|
|
52
|
+
});
|
|
53
|
+
req.locale = locale?.code;
|
|
54
|
+
const permissions = await getAccessResults({
|
|
35
55
|
req
|
|
36
56
|
});
|
|
37
57
|
return {
|
|
38
|
-
|
|
58
|
+
locale,
|
|
39
59
|
permissions,
|
|
40
|
-
req
|
|
41
|
-
user
|
|
60
|
+
req
|
|
42
61
|
};
|
|
43
62
|
});
|
|
44
63
|
//# sourceMappingURL=initReq.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initReq.js","names":["initI18n","headers","getHeaders","createLocalReq","getPayload","getRequestLanguage","parseCookies","cache","initReq","configPromise","config","payload","cookies","languageCode","i18n","context","language","req","host","get","url","serverURL","
|
|
1
|
+
{"version":3,"file":"initReq.js","names":["initI18n","headers","getHeaders","createLocalReq","executeAuthStrategies","getAccessResults","getPayload","getRequestLanguage","parseCookies","cache","getRequestLocale","initReq","configPromise","overrides","config","payload","cookies","languageCode","i18n","context","language","responseHeaders","user","req","reqOverrides","optionsOverrides","host","get","url","serverURL","locale","code","permissions"],"sources":["../../src/utilities/initReq.ts"],"sourcesContent":["import type { I18n, I18nClient } from '@payloadcms/translations'\nimport type { Locale, PayloadRequest, SanitizedConfig, SanitizedPermissions } from 'payload'\n\nimport { initI18n } from '@payloadcms/translations'\nimport { headers as getHeaders } from 'next/headers.js'\nimport {\n createLocalReq,\n executeAuthStrategies,\n getAccessResults,\n getPayload,\n getRequestLanguage,\n parseCookies,\n} from 'payload'\nimport { cache } from 'react'\n\nimport { getRequestLocale } from './getRequestLocale.js'\n\ntype Result = {\n locale?: Locale\n permissions: SanitizedPermissions\n req: PayloadRequest\n}\n\nexport const initReq = cache(async function (\n configPromise: Promise<SanitizedConfig> | SanitizedConfig,\n overrides?: Parameters<typeof createLocalReq>[0],\n): Promise<Result> {\n const config = await configPromise\n const payload = await getPayload({ config })\n\n const headers = await getHeaders()\n const cookies = parseCookies(headers)\n\n const languageCode = getRequestLanguage({\n config,\n cookies,\n headers,\n })\n\n const i18n: I18nClient = await initI18n({\n config: config.i18n,\n context: 'client',\n language: languageCode,\n })\n\n /**\n * Cannot simply call `payload.auth` here, as we need the user to get the locale, and we need the locale to get the access results\n * I.e. the `payload.auth` function would call `getAccessResults` without a fully-formed `req` object\n */\n const { responseHeaders, user } = await executeAuthStrategies({\n headers,\n payload,\n })\n\n const { req: reqOverrides, ...optionsOverrides } = overrides || {}\n\n const req = await createLocalReq(\n {\n req: {\n headers,\n host: headers.get('host'),\n i18n: i18n as I18n,\n responseHeaders,\n url: `${payload.config.serverURL}`,\n user,\n ...(reqOverrides || {}),\n },\n ...(optionsOverrides || {}),\n },\n payload,\n )\n\n const locale = await getRequestLocale({\n req,\n })\n\n req.locale = locale?.code\n\n const permissions = await getAccessResults({\n req,\n })\n\n return {\n locale,\n permissions,\n req,\n }\n})\n"],"mappings":"AAGA,SAASA,QAAQ,QAAQ;AACzB,SAASC,OAAA,IAAWC,UAAU,QAAQ;AACtC,SACEC,cAAc,EACdC,qBAAqB,EACrBC,gBAAgB,EAChBC,UAAU,EACVC,kBAAkB,EAClBC,YAAY,QACP;AACP,SAASC,KAAK,QAAQ;AAEtB,SAASC,gBAAgB,QAAQ;AAQjC,OAAO,MAAMC,OAAA,GAAUF,KAAA,CAAM,gBAC3BG,aAAyD,EACzDC,SAAgD;EAEhD,MAAMC,MAAA,GAAS,MAAMF,aAAA;EACrB,MAAMG,OAAA,GAAU,MAAMT,UAAA,CAAW;IAAEQ;EAAO;EAE1C,MAAMb,OAAA,GAAU,MAAMC,UAAA;EACtB,MAAMc,OAAA,GAAUR,YAAA,CAAaP,OAAA;EAE7B,MAAMgB,YAAA,GAAeV,kBAAA,CAAmB;IACtCO,MAAA;IACAE,OAAA;IACAf;EACF;EAEA,MAAMiB,IAAA,GAAmB,MAAMlB,QAAA,CAAS;IACtCc,MAAA,EAAQA,MAAA,CAAOI,IAAI;IACnBC,OAAA,EAAS;IACTC,QAAA,EAAUH;EACZ;EAEA;;;;EAIA,MAAM;IAAEI,eAAe;IAAEC;EAAI,CAAE,GAAG,MAAMlB,qBAAA,CAAsB;IAC5DH,OAAA;IACAc;EACF;EAEA,MAAM;IAAEQ,GAAA,EAAKC,YAAY;IAAE,GAAGC;EAAA,CAAkB,GAAGZ,SAAA,IAAa,CAAC;EAEjE,MAAMU,GAAA,GAAM,MAAMpB,cAAA,CAChB;IACEoB,GAAA,EAAK;MACHtB,OAAA;MACAyB,IAAA,EAAMzB,OAAA,CAAQ0B,GAAG,CAAC;MAClBT,IAAA,EAAMA,IAAA;MACNG,eAAA;MACAO,GAAA,EAAK,GAAGb,OAAA,CAAQD,MAAM,CAACe,SAAS,EAAE;MAClCP,IAAA;MACA,IAAIE,YAAA,IAAgB,CAAC,CAAC;IACxB;IACA,IAAIC,gBAAA,IAAoB,CAAC,CAAC;EAC5B,GACAV,OAAA;EAGF,MAAMe,MAAA,GAAS,MAAMpB,gBAAA,CAAiB;IACpCa;EACF;EAEAA,GAAA,CAAIO,MAAM,GAAGA,MAAA,EAAQC,IAAA;EAErB,MAAMC,WAAA,GAAc,MAAM3B,gBAAA,CAAiB;IACzCkB;EACF;EAEA,OAAO;IACLO,MAAA;IACAE,WAAA;IACAT;EACF;AACF","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/next",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.17.0",
|
|
4
4
|
"homepage": "https://payloadcms.com",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -79,9 +79,9 @@
|
|
|
79
79
|
"sass": "1.77.4",
|
|
80
80
|
"sonner": "^1.7.0",
|
|
81
81
|
"uuid": "10.0.0",
|
|
82
|
-
"@payloadcms/
|
|
83
|
-
"@payloadcms/
|
|
84
|
-
"@payloadcms/
|
|
82
|
+
"@payloadcms/graphql": "3.17.0",
|
|
83
|
+
"@payloadcms/translations": "3.17.0",
|
|
84
|
+
"@payloadcms/ui": "3.17.0"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@babel/cli": "7.25.9",
|
|
@@ -99,13 +99,13 @@
|
|
|
99
99
|
"esbuild-sass-plugin": "3.3.1",
|
|
100
100
|
"eslint-plugin-react-compiler": "19.0.0-beta-df7b47d-20241124",
|
|
101
101
|
"swc-plugin-transform-remove-imports": "2.0.0",
|
|
102
|
-
"payload": "3.
|
|
102
|
+
"payload": "3.17.0",
|
|
103
103
|
"@payloadcms/eslint-config": "3.9.0"
|
|
104
104
|
},
|
|
105
105
|
"peerDependencies": {
|
|
106
106
|
"graphql": "^16.8.1",
|
|
107
107
|
"next": "^15.0.0",
|
|
108
|
-
"payload": "3.
|
|
108
|
+
"payload": "3.17.0"
|
|
109
109
|
},
|
|
110
110
|
"engines": {
|
|
111
111
|
"node": "^18.20.2 || >=20.9.0"
|