@payloadcms/next 3.24.0 → 3.25.0-canary.36940b2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/elements/Nav/getNavPrefs.d.ts +2 -5
  2. package/dist/elements/Nav/getNavPrefs.d.ts.map +1 -1
  3. package/dist/elements/Nav/getNavPrefs.js +23 -24
  4. package/dist/elements/Nav/getNavPrefs.js.map +1 -1
  5. package/dist/elements/Nav/index.js +1 -4
  6. package/dist/elements/Nav/index.js.map +1 -1
  7. package/dist/layouts/Root/index.d.ts.map +1 -1
  8. package/dist/layouts/Root/index.js +19 -27
  9. package/dist/layouts/Root/index.js.map +1 -1
  10. package/dist/prod/styles.css +1 -1
  11. package/dist/utilities/getPreferences.d.ts +5 -2
  12. package/dist/utilities/getPreferences.d.ts.map +1 -1
  13. package/dist/utilities/getPreferences.js +22 -25
  14. package/dist/utilities/getPreferences.js.map +1 -1
  15. package/dist/utilities/getRequestLocale.d.ts.map +1 -1
  16. package/dist/utilities/getRequestLocale.js +1 -1
  17. package/dist/utilities/getRequestLocale.js.map +1 -1
  18. package/dist/utilities/handleServerFunctions.d.ts.map +1 -1
  19. package/dist/utilities/handleServerFunctions.js +5 -1
  20. package/dist/utilities/handleServerFunctions.js.map +1 -1
  21. package/dist/utilities/initPage/index.d.ts +1 -1
  22. package/dist/utilities/initPage/index.d.ts.map +1 -1
  23. package/dist/utilities/initPage/index.js +26 -24
  24. package/dist/utilities/initPage/index.js.map +1 -1
  25. package/dist/utilities/initPage/types.d.ts +11 -0
  26. package/dist/utilities/initPage/types.d.ts.map +1 -1
  27. package/dist/utilities/initPage/types.js.map +1 -1
  28. package/dist/utilities/initReq.d.ts +18 -2
  29. package/dist/utilities/initReq.d.ts.map +1 -1
  30. package/dist/utilities/initReq.js +138 -52
  31. package/dist/utilities/initReq.js.map +1 -1
  32. package/dist/views/NotFound/index.d.ts.map +1 -1
  33. package/dist/views/NotFound/index.js +2 -1
  34. package/dist/views/NotFound/index.js.map +1 -1
  35. package/package.json +7 -7
@@ -1,3 +1,6 @@
1
- import type { Payload, User } from 'payload';
2
- export declare const getPreferences: <T>(key: string, payload: Payload, user: User) => Promise<T>;
1
+ import type { DefaultDocumentIDType, Payload } from 'payload';
2
+ export declare const getPreferences: <T>(key: string, payload: Payload, userID: DefaultDocumentIDType, userSlug: string) => Promise<{
3
+ id: DefaultDocumentIDType;
4
+ value: T;
5
+ }>;
3
6
  //# sourceMappingURL=getPreferences.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getPreferences.d.ts","sourceRoot":"","sources":["../../src/utilities/getPreferences.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAI5C,eAAO,MAAM,cAAc,GAClB,CAAC,OAAO,MAAM,WAAW,OAAO,QAAQ,IAAI,KAAG,OAAO,CAAC,CAAC,CAmChE,CAAA"}
1
+ {"version":3,"file":"getPreferences.d.ts","sourceRoot":"","sources":["../../src/utilities/getPreferences.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAI7D,eAAO,MAAM,cAAc,GAClB,CAAC,OACD,MAAM,WACF,OAAO,UACR,qBAAqB,YACnB,MAAM,KACf,OAAO,CAAC;IAAE,EAAE,EAAE,qBAAqB,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CA+BnD,CAAA"}
@@ -1,29 +1,26 @@
1
1
  import { cache } from 'react';
2
- export const getPreferences = cache(async (key, payload, user) => {
3
- let result = null;
4
- try {
5
- result = await payload.find({
6
- collection: 'payload-preferences',
7
- depth: 0,
8
- limit: 1,
9
- user,
10
- where: {
11
- and: [{
12
- 'user.relationTo': {
13
- equals: payload.config.admin.user
14
- }
15
- }, {
16
- 'user.value': {
17
- equals: user.id
18
- }
19
- }, {
20
- key: {
21
- equals: key
22
- }
23
- }]
24
- }
25
- })?.then(res => res.docs?.[0]?.value);
26
- } catch (_err) {} // eslint-disable-line no-empty
2
+ export const getPreferences = cache(async (key, payload, userID, userSlug) => {
3
+ const result = await payload.find({
4
+ collection: 'payload-preferences',
5
+ depth: 0,
6
+ limit: 1,
7
+ pagination: false,
8
+ where: {
9
+ and: [{
10
+ key: {
11
+ equals: key
12
+ }
13
+ }, {
14
+ 'user.relationTo': {
15
+ equals: userSlug
16
+ }
17
+ }, {
18
+ 'user.value': {
19
+ equals: userID
20
+ }
21
+ }]
22
+ }
23
+ }).then(res => res.docs?.[0]);
27
24
  return result;
28
25
  });
29
26
  //# sourceMappingURL=getPreferences.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getPreferences.js","names":["cache","getPreferences","key","payload","user","result","find","collection","depth","limit","where","and","equals","config","admin","id","then","res","docs","value","_err"],"sources":["../../src/utilities/getPreferences.ts"],"sourcesContent":["import type { Payload, User } from 'payload'\n\nimport { cache } from 'react'\n\nexport const getPreferences = cache(\n async <T>(key: string, payload: Payload, user: User): Promise<T> => {\n let result: T = null\n\n try {\n result = 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: key,\n },\n },\n ],\n },\n })\n ?.then((res) => res.docs?.[0]?.value as T)\n } catch (_err) {} // eslint-disable-line no-empty\n\n return result\n },\n)\n"],"mappings":"AAEA,SAASA,KAAK,QAAQ;AAEtB,OAAO,MAAMC,cAAA,GAAiBD,KAAA,CAC5B,OAAUE,GAAA,EAAaC,OAAA,EAAkBC,IAAA;EACvC,IAAIC,MAAA,GAAY;EAEhB,IAAI;IACFA,MAAA,GAAS,MAAMF,OAAA,CACZG,IAAI,CAAC;MACJC,UAAA,EAAY;MACZC,KAAA,EAAO;MACPC,KAAA,EAAO;MACPL,IAAA;MACAM,KAAA,EAAO;QACLC,GAAA,EAAK,CACH;UACE,mBAAmB;YACjBC,MAAA,EAAQT,OAAA,CAAQU,MAAM,CAACC,KAAK,CAACV;UAC/B;QACF,GACA;UACE,cAAc;YACZQ,MAAA,EAAQR,IAAA,CAAKW;UACf;QACF,GACA;UACEb,GAAA,EAAK;YACHU,MAAA,EAAQV;UACV;QACF;MAEJ;IACF,IACEc,IAAA,CAAMC,GAAA,IAAQA,GAAA,CAAIC,IAAI,GAAG,EAAE,EAAEC,KAAA;EACnC,EAAE,OAAOC,IAAA,EAAM,CAAC,EAAE;EAElB,OAAOf,MAAA;AACT","ignoreList":[]}
1
+ {"version":3,"file":"getPreferences.js","names":["cache","getPreferences","key","payload","userID","userSlug","result","find","collection","depth","limit","pagination","where","and","equals","then","res","docs"],"sources":["../../src/utilities/getPreferences.ts"],"sourcesContent":["import type { DefaultDocumentIDType, Payload } from 'payload'\n\nimport { cache } from 'react'\n\nexport const getPreferences = cache(\n async <T>(\n key: string,\n payload: Payload,\n userID: DefaultDocumentIDType,\n userSlug: string,\n ): Promise<{ id: DefaultDocumentIDType; value: T }> => {\n const result = (await payload\n .find({\n collection: 'payload-preferences',\n depth: 0,\n limit: 1,\n pagination: false,\n where: {\n and: [\n {\n key: {\n equals: key,\n },\n },\n {\n 'user.relationTo': {\n equals: userSlug,\n },\n },\n {\n 'user.value': {\n equals: userID,\n },\n },\n ],\n },\n })\n .then((res) => res.docs?.[0])) as { id: DefaultDocumentIDType; value: T }\n\n return result\n },\n)\n"],"mappings":"AAEA,SAASA,KAAK,QAAQ;AAEtB,OAAO,MAAMC,cAAA,GAAiBD,KAAA,CAC5B,OACEE,GAAA,EACAC,OAAA,EACAC,MAAA,EACAC,QAAA;EAEA,MAAMC,MAAA,GAAU,MAAMH,OAAA,CACnBI,IAAI,CAAC;IACJC,UAAA,EAAY;IACZC,KAAA,EAAO;IACPC,KAAA,EAAO;IACPC,UAAA,EAAY;IACZC,KAAA,EAAO;MACLC,GAAA,EAAK,CACH;QACEX,GAAA,EAAK;UACHY,MAAA,EAAQZ;QACV;MACF,GACA;QACE,mBAAmB;UACjBY,MAAA,EAAQT;QACV;MACF,GACA;QACE,cAAc;UACZS,MAAA,EAAQV;QACV;MACF;IAEJ;EACF,GACCW,IAAI,CAAEC,GAAA,IAAQA,GAAA,CAAIC,IAAI,GAAG,EAAE;EAE9B,OAAOX,MAAA;AACT","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"getRequestLocale.d.ts","sourceRoot":"","sources":["../../src/utilities/getRequestLocale.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAOrD,KAAK,qBAAqB,GAAG;IAC3B,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,wBAAsB,gBAAgB,CAAC,EAAE,GAAG,EAAE,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,CAqBtF"}
1
+ {"version":3,"file":"getRequestLocale.d.ts","sourceRoot":"","sources":["../../src/utilities/getRequestLocale.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAOrD,KAAK,qBAAqB,GAAG;IAC3B,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,wBAAsB,gBAAgB,CAAC,EAAE,GAAG,EAAE,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,CA8BtF"}
@@ -13,7 +13,7 @@ export async function getRequestLocale({
13
13
  value: localeFromParams
14
14
  });
15
15
  }
16
- return findLocaleFromCode(req.payload.config.localization, localeFromParams || (await getPreferences('locale', req.payload, req.user))) || findLocaleFromCode(req.payload.config.localization, req.payload.config.localization.defaultLocale || 'en');
16
+ return req.user && findLocaleFromCode(req.payload.config.localization, localeFromParams || (await getPreferences('locale', req.payload, req.user.id, req.user.collection))?.value) || findLocaleFromCode(req.payload.config.localization, req.payload.config.localization.defaultLocale || 'en');
17
17
  }
18
18
  return undefined;
19
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"getRequestLocale.js","names":["upsertPreferences","findLocaleFromCode","getPreferences","getRequestLocale","req","payload","config","localization","localeFromParams","query","locale","key","value","user","defaultLocale","undefined"],"sources":["../../src/utilities/getRequestLocale.ts"],"sourcesContent":["import type { Locale, PayloadRequest } from 'payload'\n\nimport { upsertPreferences } from '@payloadcms/ui/rsc'\nimport { findLocaleFromCode } from '@payloadcms/ui/shared'\n\nimport { getPreferences } from './getPreferences.js'\n\ntype GetRequestLocalesArgs = {\n req: PayloadRequest\n}\n\nexport async function getRequestLocale({ req }: GetRequestLocalesArgs): Promise<Locale> {\n if (req.payload.config.localization) {\n const localeFromParams = req.query.locale as string | undefined\n\n if (localeFromParams) {\n await upsertPreferences<Locale['code']>({ key: 'locale', req, value: localeFromParams })\n }\n\n return (\n findLocaleFromCode(\n req.payload.config.localization,\n localeFromParams || (await getPreferences<Locale['code']>('locale', req.payload, req.user)),\n ) ||\n findLocaleFromCode(\n req.payload.config.localization,\n req.payload.config.localization.defaultLocale || 'en',\n )\n )\n }\n\n return undefined\n}\n"],"mappings":"AAEA,SAASA,iBAAiB,QAAQ;AAClC,SAASC,kBAAkB,QAAQ;AAEnC,SAASC,cAAc,QAAQ;AAM/B,OAAO,eAAeC,iBAAiB;EAAEC;AAAG,CAAyB;EACnE,IAAIA,GAAA,CAAIC,OAAO,CAACC,MAAM,CAACC,YAAY,EAAE;IACnC,MAAMC,gBAAA,GAAmBJ,GAAA,CAAIK,KAAK,CAACC,MAAM;IAEzC,IAAIF,gBAAA,EAAkB;MACpB,MAAMR,iBAAA,CAAkC;QAAEW,GAAA,EAAK;QAAUP,GAAA;QAAKQ,KAAA,EAAOJ;MAAiB;IACxF;IAEA,OACEP,kBAAA,CACEG,GAAA,CAAIC,OAAO,CAACC,MAAM,CAACC,YAAY,EAC/BC,gBAAA,KAAqB,MAAMN,cAAA,CAA+B,UAAUE,GAAA,CAAIC,OAAO,EAAED,GAAA,CAAIS,IAAI,OAE3FZ,kBAAA,CACEG,GAAA,CAAIC,OAAO,CAACC,MAAM,CAACC,YAAY,EAC/BH,GAAA,CAAIC,OAAO,CAACC,MAAM,CAACC,YAAY,CAACO,aAAa,IAAI;EAGvD;EAEA,OAAOC,SAAA;AACT","ignoreList":[]}
1
+ {"version":3,"file":"getRequestLocale.js","names":["upsertPreferences","findLocaleFromCode","getPreferences","getRequestLocale","req","payload","config","localization","localeFromParams","query","locale","key","value","user","id","collection","defaultLocale","undefined"],"sources":["../../src/utilities/getRequestLocale.ts"],"sourcesContent":["import type { Locale, PayloadRequest } from 'payload'\n\nimport { upsertPreferences } from '@payloadcms/ui/rsc'\nimport { findLocaleFromCode } from '@payloadcms/ui/shared'\n\nimport { getPreferences } from './getPreferences.js'\n\ntype GetRequestLocalesArgs = {\n req: PayloadRequest\n}\n\nexport async function getRequestLocale({ req }: GetRequestLocalesArgs): Promise<Locale> {\n if (req.payload.config.localization) {\n const localeFromParams = req.query.locale as string | undefined\n\n if (localeFromParams) {\n await upsertPreferences<Locale['code']>({ key: 'locale', req, value: localeFromParams })\n }\n\n return (\n (req.user &&\n findLocaleFromCode(\n req.payload.config.localization,\n localeFromParams ||\n (\n await getPreferences<Locale['code']>(\n 'locale',\n req.payload,\n req.user.id,\n req.user.collection,\n )\n )?.value,\n )) ||\n findLocaleFromCode(\n req.payload.config.localization,\n req.payload.config.localization.defaultLocale || 'en',\n )\n )\n }\n\n return undefined\n}\n"],"mappings":"AAEA,SAASA,iBAAiB,QAAQ;AAClC,SAASC,kBAAkB,QAAQ;AAEnC,SAASC,cAAc,QAAQ;AAM/B,OAAO,eAAeC,iBAAiB;EAAEC;AAAG,CAAyB;EACnE,IAAIA,GAAA,CAAIC,OAAO,CAACC,MAAM,CAACC,YAAY,EAAE;IACnC,MAAMC,gBAAA,GAAmBJ,GAAA,CAAIK,KAAK,CAACC,MAAM;IAEzC,IAAIF,gBAAA,EAAkB;MACpB,MAAMR,iBAAA,CAAkC;QAAEW,GAAA,EAAK;QAAUP,GAAA;QAAKQ,KAAA,EAAOJ;MAAiB;IACxF;IAEA,OACEJ,GAAC,CAAIS,IAAI,IACPZ,kBAAA,CACEG,GAAA,CAAIC,OAAO,CAACC,MAAM,CAACC,YAAY,EAC/BC,gBAAA,IAEI,OAAMN,cAAA,CACJ,UACAE,GAAA,CAAIC,OAAO,EACXD,GAAA,CAAIS,IAAI,CAACC,EAAE,EACXV,GAAA,CAAIS,IAAI,CAACE,UAAU,CACrB,GACCH,KAAA,KAETX,kBAAA,CACEG,GAAA,CAAIC,OAAO,CAACC,MAAM,CAACC,YAAY,EAC/BH,GAAA,CAAIC,OAAO,CAACC,MAAM,CAACC,YAAY,CAACS,aAAa,IAAI;EAGvD;EAEA,OAAOC,SAAA;AACT","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"handleServerFunctions.d.ts","sourceRoot":"","sources":["../../src/utilities/handleServerFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAYpE,eAAO,MAAM,qBAAqB,EAAE,qBA4BnC,CAAA"}
1
+ {"version":3,"file":"handleServerFunctions.d.ts","sourceRoot":"","sources":["../../src/utilities/handleServerFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAYpE,eAAO,MAAM,qBAAqB,EAAE,qBAgCnC,CAAA"}
@@ -15,7 +15,11 @@ export const handleServerFunctions = async args => {
15
15
  } = args;
16
16
  const {
17
17
  req
18
- } = await initReq(configPromise);
18
+ } = await initReq({
19
+ configPromise,
20
+ importMap,
21
+ key: 'RootLayout'
22
+ });
19
23
  const augmentedArgs = {
20
24
  ...fnArgs,
21
25
  importMap,
@@ -1 +1 @@
1
- {"version":3,"file":"handleServerFunctions.js","names":["copyDataFromLocaleHandler","buildFormStateHandler","buildTableStateHandler","schedulePublishHandler","renderDocumentHandler","renderDocumentSlotsHandler","renderListHandler","initReq","handleServerFunctions","args","name","fnKey","fnArgs","config","configPromise","importMap","req","augmentedArgs","serverFunctions","fn","Error"],"sources":["../../src/utilities/handleServerFunctions.ts"],"sourcesContent":["import type { ServerFunction, ServerFunctionHandler } from 'payload'\n\nimport { copyDataFromLocaleHandler } from '@payloadcms/ui/rsc'\nimport { buildFormStateHandler } from '@payloadcms/ui/utilities/buildFormState'\nimport { buildTableStateHandler } from '@payloadcms/ui/utilities/buildTableState'\nimport { schedulePublishHandler } from '@payloadcms/ui/utilities/schedulePublishHandler'\n\nimport { renderDocumentHandler } from '../views/Document/handleServerFunction.js'\nimport { renderDocumentSlotsHandler } from '../views/Document/renderDocumentSlots.js'\nimport { renderListHandler } from '../views/List/handleServerFunction.js'\nimport { initReq } from './initReq.js'\n\nexport const handleServerFunctions: ServerFunctionHandler = async (args) => {\n const { name: fnKey, args: fnArgs, config: configPromise, importMap } = args\n\n const { req } = await initReq(configPromise)\n\n const augmentedArgs: Parameters<ServerFunction>[0] = {\n ...fnArgs,\n importMap,\n req,\n }\n\n const serverFunctions = {\n 'copy-data-from-locale': copyDataFromLocaleHandler as any as ServerFunction,\n 'form-state': buildFormStateHandler as any as ServerFunction,\n 'render-document': renderDocumentHandler as any as ServerFunction,\n 'render-document-slots': renderDocumentSlotsHandler as any as ServerFunction,\n 'render-list': renderListHandler as any as ServerFunction,\n 'schedule-publish': schedulePublishHandler as any as ServerFunction,\n 'table-state': buildTableStateHandler as any as ServerFunction,\n }\n\n const fn = serverFunctions[fnKey]\n\n if (!fn) {\n throw new Error(`Unknown Server Function: ${fnKey}`)\n }\n\n return fn(augmentedArgs)\n}\n"],"mappings":"AAEA,SAASA,yBAAyB,QAAQ;AAC1C,SAASC,qBAAqB,QAAQ;AACtC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,sBAAsB,QAAQ;AAEvC,SAASC,qBAAqB,QAAQ;AACtC,SAASC,0BAA0B,QAAQ;AAC3C,SAASC,iBAAiB,QAAQ;AAClC,SAASC,OAAO,QAAQ;AAExB,OAAO,MAAMC,qBAAA,GAA+C,MAAOC,IAAA;EACjE,MAAM;IAAEC,IAAA,EAAMC,KAAK;IAAEF,IAAA,EAAMG,MAAM;IAAEC,MAAA,EAAQC,aAAa;IAAEC;EAAS,CAAE,GAAGN,IAAA;EAExE,MAAM;IAAEO;EAAG,CAAE,GAAG,MAAMT,OAAA,CAAQO,aAAA;EAE9B,MAAMG,aAAA,GAA+C;IACnD,GAAGL,MAAM;IACTG,SAAA;IACAC;EACF;EAEA,MAAME,eAAA,GAAkB;IACtB,yBAAyBlB,yBAAA;IACzB,cAAcC,qBAAA;IACd,mBAAmBG,qBAAA;IACnB,yBAAyBC,0BAAA;IACzB,eAAeC,iBAAA;IACf,oBAAoBH,sBAAA;IACpB,eAAeD;EACjB;EAEA,MAAMiB,EAAA,GAAKD,eAAe,CAACP,KAAA,CAAM;EAEjC,IAAI,CAACQ,EAAA,EAAI;IACP,MAAM,IAAIC,KAAA,CAAM,4BAA4BT,KAAA,EAAO;EACrD;EAEA,OAAOQ,EAAA,CAAGF,aAAA;AACZ","ignoreList":[]}
1
+ {"version":3,"file":"handleServerFunctions.js","names":["copyDataFromLocaleHandler","buildFormStateHandler","buildTableStateHandler","schedulePublishHandler","renderDocumentHandler","renderDocumentSlotsHandler","renderListHandler","initReq","handleServerFunctions","args","name","fnKey","fnArgs","config","configPromise","importMap","req","key","augmentedArgs","serverFunctions","fn","Error"],"sources":["../../src/utilities/handleServerFunctions.ts"],"sourcesContent":["import type { ServerFunction, ServerFunctionHandler } from 'payload'\n\nimport { copyDataFromLocaleHandler } from '@payloadcms/ui/rsc'\nimport { buildFormStateHandler } from '@payloadcms/ui/utilities/buildFormState'\nimport { buildTableStateHandler } from '@payloadcms/ui/utilities/buildTableState'\nimport { schedulePublishHandler } from '@payloadcms/ui/utilities/schedulePublishHandler'\n\nimport { renderDocumentHandler } from '../views/Document/handleServerFunction.js'\nimport { renderDocumentSlotsHandler } from '../views/Document/renderDocumentSlots.js'\nimport { renderListHandler } from '../views/List/handleServerFunction.js'\nimport { initReq } from './initReq.js'\n\nexport const handleServerFunctions: ServerFunctionHandler = async (args) => {\n const { name: fnKey, args: fnArgs, config: configPromise, importMap } = args\n\n const { req } = await initReq({\n configPromise,\n importMap,\n key: 'RootLayout',\n })\n\n const augmentedArgs: Parameters<ServerFunction>[0] = {\n ...fnArgs,\n importMap,\n req,\n }\n\n const serverFunctions = {\n 'copy-data-from-locale': copyDataFromLocaleHandler as any as ServerFunction,\n 'form-state': buildFormStateHandler as any as ServerFunction,\n 'render-document': renderDocumentHandler as any as ServerFunction,\n 'render-document-slots': renderDocumentSlotsHandler as any as ServerFunction,\n 'render-list': renderListHandler as any as ServerFunction,\n 'schedule-publish': schedulePublishHandler as any as ServerFunction,\n 'table-state': buildTableStateHandler as any as ServerFunction,\n }\n\n const fn = serverFunctions[fnKey]\n\n if (!fn) {\n throw new Error(`Unknown Server Function: ${fnKey}`)\n }\n\n return fn(augmentedArgs)\n}\n"],"mappings":"AAEA,SAASA,yBAAyB,QAAQ;AAC1C,SAASC,qBAAqB,QAAQ;AACtC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,sBAAsB,QAAQ;AAEvC,SAASC,qBAAqB,QAAQ;AACtC,SAASC,0BAA0B,QAAQ;AAC3C,SAASC,iBAAiB,QAAQ;AAClC,SAASC,OAAO,QAAQ;AAExB,OAAO,MAAMC,qBAAA,GAA+C,MAAOC,IAAA;EACjE,MAAM;IAAEC,IAAA,EAAMC,KAAK;IAAEF,IAAA,EAAMG,MAAM;IAAEC,MAAA,EAAQC,aAAa;IAAEC;EAAS,CAAE,GAAGN,IAAA;EAExE,MAAM;IAAEO;EAAG,CAAE,GAAG,MAAMT,OAAA,CAAQ;IAC5BO,aAAA;IACAC,SAAA;IACAE,GAAA,EAAK;EACP;EAEA,MAAMC,aAAA,GAA+C;IACnD,GAAGN,MAAM;IACTG,SAAA;IACAC;EACF;EAEA,MAAMG,eAAA,GAAkB;IACtB,yBAAyBnB,yBAAA;IACzB,cAAcC,qBAAA;IACd,mBAAmBG,qBAAA;IACnB,yBAAyBC,0BAAA;IACzB,eAAeC,iBAAA;IACf,oBAAoBH,sBAAA;IACpB,eAAeD;EACjB;EAEA,MAAMkB,EAAA,GAAKD,eAAe,CAACR,KAAA,CAAM;EAEjC,IAAI,CAACS,EAAA,EAAI;IACP,MAAM,IAAIC,KAAA,CAAM,4BAA4BV,KAAA,EAAO;EACrD;EAEA,OAAOS,EAAA,CAAGF,aAAA;AACZ","ignoreList":[]}
@@ -1,4 +1,4 @@
1
1
  import type { InitPageResult } from 'payload';
2
2
  import type { Args } from './types.js';
3
- export declare const initPage: ({ config: configPromise, importMap, route, searchParams, }: Args) => Promise<InitPageResult>;
3
+ export declare const initPage: ({ config: configPromise, importMap, route, searchParams, useLayoutReq, }: Args) => Promise<InitPageResult>;
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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
+ {"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,6EAMlB,IAAI,KAAG,OAAO,CAAC,cAAc,CAkG/B,CAAA"}
@@ -1,6 +1,5 @@
1
- import { headers as getHeaders } from 'next/headers.js';
2
1
  import { notFound } from 'next/navigation.js';
3
- import { getPayload, isEntityHidden, parseCookies } from 'payload';
2
+ import { isEntityHidden } from 'payload';
4
3
  import * as qs from 'qs-esm';
5
4
  import { initReq } from '../initReq.js';
6
5
  import { getRouteInfo } from './handleAdminPage.js';
@@ -11,16 +10,35 @@ export const initPage = async ({
11
10
  config: configPromise,
12
11
  importMap,
13
12
  route,
14
- searchParams
13
+ searchParams,
14
+ useLayoutReq
15
15
  }) => {
16
- const headers = await getHeaders();
17
- const payload = await getPayload({
18
- config: configPromise,
19
- importMap
20
- });
21
16
  const queryString = `${qs.stringify(searchParams ?? {}, {
22
17
  addQueryPrefix: true
23
18
  })}`;
19
+ const {
20
+ cookies,
21
+ locale,
22
+ permissions,
23
+ req,
24
+ req: {
25
+ payload
26
+ }
27
+ } = await initReq({
28
+ configPromise,
29
+ importMap,
30
+ key: useLayoutReq ? 'RootLayout' : 'initPage',
31
+ overrides: {
32
+ fallbackLocale: false,
33
+ req: {
34
+ query: qs.parse(queryString, {
35
+ depth: 10,
36
+ ignoreQueryPrefix: true
37
+ })
38
+ }
39
+ },
40
+ urlSuffix: `${route}${searchParams ? queryString : ''}`
41
+ });
24
42
  const {
25
43
  collections,
26
44
  globals,
@@ -28,22 +46,6 @@ export const initPage = async ({
28
46
  admin: adminRoute
29
47
  }
30
48
  } = payload.config;
31
- const cookies = parseCookies(headers);
32
- const {
33
- locale,
34
- permissions,
35
- req
36
- } = await initReq(payload.config, {
37
- fallbackLocale: false,
38
- req: {
39
- headers,
40
- query: qs.parse(queryString, {
41
- depth: 10,
42
- ignoreQueryPrefix: true
43
- }),
44
- url: `${payload.config.serverURL}${route}${searchParams ? queryString : ''}`
45
- }
46
- });
47
49
  const languageOptions = Object.entries(payload.config.i18n.supportedLanguages || {}).reduce((acc, [language, languageConfig]) => {
48
50
  if (Object.keys(payload.config.i18n.supportedLanguages).includes(language)) {
49
51
  acc.push({
@@ -1 +1 @@
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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AAA;IACA7B,eAAA;IACAV,MAAA;IACAC,WAAA;IACAiC,UAAA;IACAhC,GAAA;IACAqB,YAAA,EAAcrB,GAAA,CAAIW,IAAI,CAACU,YAAY;IACnCI;EACF;AACF","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["notFound","isEntityHidden","qs","initReq","getRouteInfo","handleAuthRedirect","isCustomAdminView","isPublicAdminRoute","initPage","config","configPromise","importMap","route","searchParams","useLayoutReq","queryString","stringify","addQueryPrefix","cookies","locale","permissions","req","payload","key","overrides","fallbackLocale","query","parse","depth","ignoreQueryPrefix","urlSuffix","collections","globals","routes","admin","adminRoute","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 useLayoutReq,\n}: Args): Promise<InitPageResult> => {\n const queryString = `${qs.stringify(searchParams ?? {}, { addQueryPrefix: true })}`\n\n const {\n cookies,\n locale,\n permissions,\n req,\n req: { payload },\n } = await initReq({\n configPromise,\n importMap,\n key: useLayoutReq ? 'RootLayout' : 'initPage',\n overrides: {\n fallbackLocale: false,\n req: {\n query: qs.parse(queryString, {\n depth: 10,\n ignoreQueryPrefix: true,\n }),\n },\n },\n urlSuffix: `${route}${searchParams ? queryString : ''}`,\n })\n\n const {\n collections,\n globals,\n routes: { admin: adminRoute },\n } = payload.config\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":"AAGA,SAASA,QAAQ,QAAQ;AACzB,SAAqBC,cAAc,QAAsB;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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IAC1E,OAAOjE,QAAA;EACT;EAEA,OAAO;IACL8D,gBAAA;IACA5C,OAAA;IACA8C,KAAA;IACAC,YAAA;IACA7B,eAAA;IACAjB,MAAA;IACAC,WAAA;IACAwC,UAAA;IACAvC,GAAA;IACA4B,YAAA,EAAc5B,GAAA,CAAIkB,IAAI,CAACU,YAAY;IACnCI;EACF;AACF","ignoreList":[]}
@@ -21,5 +21,16 @@ export type Args = {
21
21
  searchParams: {
22
22
  [key: string]: string | string[] | undefined;
23
23
  };
24
+ /**
25
+ * If `useLayoutReq` is `true`, this page will use the cached `req` created by the root layout
26
+ * instead of creating a new one.
27
+ *
28
+ * This is improves performance for pages that are able to share the same `req` as the root layout,
29
+ * as permissions do not need to be re-calculated.
30
+ *
31
+ * If the page has unique query and url params that need to be part of the `req` object, or if you
32
+ * need permissions calculation to respect those you should not use this property.
33
+ */
34
+ useLayoutReq?: boolean;
24
35
  };
25
36
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utilities/initPage/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAEzD,MAAM,MAAM,IAAI,GAAG;IACjB;;;OAGG;IACH,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,CAAA;IAClD,SAAS,EAAE,SAAS,CAAA;IACpB;;;OAGG;IACH,2BAA2B,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAC9C;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,YAAY,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAA;KAAE,CAAA;CAC/D,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utilities/initPage/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAEzD,MAAM,MAAM,IAAI,GAAG;IACjB;;;OAGG;IACH,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,CAAA;IAClD,SAAS,EAAE,SAAS,CAAA;IACpB;;;OAGG;IACH,2BAA2B,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAC9C;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,YAAY,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAA;KAAE,CAAA;IAC9D;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../src/utilities/initPage/types.ts"],"sourcesContent":["import type { ImportMap, SanitizedConfig } from 'payload'\n\nexport type Args = {\n /**\n * Your sanitized Payload config.\n * If unresolved, this function will await the promise.\n */\n config: Promise<SanitizedConfig> | SanitizedConfig\n importMap: ImportMap\n /**\n * If true, redirects unauthenticated users to the admin login page.\n * If a string is provided, the user will be redirected to that specific URL.\n */\n redirectUnauthenticatedUser?: boolean | string\n /**\n * The current route, i.e. `/admin/collections/posts`.\n */\n route: string\n /**\n * The search parameters of the current route provided to all pages in Next.js.\n */\n searchParams: { [key: string]: string | string[] | undefined }\n}\n"],"mappings":"AAEA","ignoreList":[]}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../src/utilities/initPage/types.ts"],"sourcesContent":["import type { ImportMap, SanitizedConfig } from 'payload'\n\nexport type Args = {\n /**\n * Your sanitized Payload config.\n * If unresolved, this function will await the promise.\n */\n config: Promise<SanitizedConfig> | SanitizedConfig\n importMap: ImportMap\n /**\n * If true, redirects unauthenticated users to the admin login page.\n * If a string is provided, the user will be redirected to that specific URL.\n */\n redirectUnauthenticatedUser?: boolean | string\n /**\n * The current route, i.e. `/admin/collections/posts`.\n */\n route: string\n /**\n * The search parameters of the current route provided to all pages in Next.js.\n */\n searchParams: { [key: string]: string | string[] | undefined }\n /**\n * If `useLayoutReq` is `true`, this page will use the cached `req` created by the root layout\n * instead of creating a new one.\n *\n * This is improves performance for pages that are able to share the same `req` as the root layout,\n * as permissions do not need to be re-calculated.\n *\n * If the page has unique query and url params that need to be part of the `req` object, or if you\n * need permissions calculation to respect those you should not use this property.\n */\n useLayoutReq?: boolean\n}\n"],"mappings":"AAEA","ignoreList":[]}
@@ -1,10 +1,26 @@
1
- import type { Locale, PayloadRequest, SanitizedConfig, SanitizedPermissions } from 'payload';
1
+ import type { AcceptedLanguages } from '@payloadcms/translations';
2
+ import type { ImportMap, Locale, PayloadRequest, SanitizedConfig, SanitizedPermissions } from 'payload';
3
+ import { headers as getHeaders } from 'next/headers.js';
2
4
  import { createLocalReq } from 'payload';
3
5
  type Result = {
6
+ cookies: Map<string, string>;
7
+ headers: Awaited<ReturnType<typeof getHeaders>>;
8
+ languageCode: AcceptedLanguages;
4
9
  locale?: Locale;
5
10
  permissions: SanitizedPermissions;
6
11
  req: PayloadRequest;
7
12
  };
8
- export declare const initReq: (configPromise: Promise<SanitizedConfig> | SanitizedConfig, overrides?: Parameters<typeof createLocalReq>[0]) => Promise<Result>;
13
+ /**
14
+ * Initializes a full request object, including the `req` object and access control.
15
+ * As access control and getting the request locale is dependent on the current URL and
16
+ * query parameters, this function cannot be cached as often as the partial request object.
17
+ */
18
+ export declare const initReq: ({ configPromise, importMap, key, overrides, urlSuffix, }: {
19
+ configPromise: Promise<SanitizedConfig> | SanitizedConfig;
20
+ importMap: ImportMap;
21
+ key: string;
22
+ overrides?: Parameters<typeof createLocalReq>[0];
23
+ urlSuffix?: string;
24
+ }) => Promise<Result>;
9
25
  export {};
10
26
  //# sourceMappingURL=initReq.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"initReq.d.ts","sourceRoot":"","sources":["../../src/utilities/initReq.ts"],"names":[],"mappings":"A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,EAAE,MAAM,CAAA;IACX,SAAS,CAAC,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAA;IAChD,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,KAAG,OAAO,CAAC,MAAM,CA6DjB,CAAA"}
@@ -3,61 +3,147 @@ import { headers as getHeaders } from 'next/headers.js';
3
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) {
7
- const config = await configPromise;
8
- const payload = await getPayload({
9
- config
10
- });
11
- const headers = await getHeaders();
12
- const cookies = parseCookies(headers);
13
- const languageCode = getRequestLanguage({
14
- config,
15
- cookies,
16
- headers
17
- });
18
- const i18n = await initI18n({
19
- config: config.i18n,
20
- context: 'client',
21
- language: languageCode
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
- */
6
+ /**
7
+ * Stable object to cache the partial request object across all pages
8
+ */
9
+ const getPartialInitReqContainer = cache(function () {
10
+ return {
11
+ reqResult: false
12
+ };
13
+ });
14
+ /**
15
+ * Stable object to cache the request object across all pages with the same key
16
+ */
17
+ const getInitReqContainer = cache(function (
18
+ /**
19
+ * The key is solely used to control caching behavior
20
+ */
21
+ key) {
22
+ return {
23
+ reqResult: false
24
+ };
25
+ });
26
+ /**
27
+ * Initializes a partial request object. This does not construct the `req` object and does
28
+ * not run access control.
29
+ *
30
+ * The output of this function can be cached across all pages, which is why it is
31
+ * separated from `initReq`.
32
+ */
33
+ const initPartialReq = async function ({
34
+ configPromise,
35
+ importMap
36
+ }) {
37
+ const partialReqContainer = getPartialInitReqContainer();
38
+ if (partialReqContainer?.reqResult && 'then' in partialReqContainer.reqResult && typeof partialReqContainer?.reqResult?.then === 'function') {
39
+ return await partialReqContainer.reqResult;
40
+ }
41
+ partialReqContainer.reqResult = (async () => {
42
+ const config = await configPromise;
43
+ const payload = await getPayload({
44
+ config,
45
+ importMap
46
+ });
47
+ const headers = await getHeaders();
48
+ const cookies = parseCookies(headers);
49
+ const languageCode = getRequestLanguage({
50
+ config,
51
+ cookies,
52
+ headers
53
+ });
54
+ const i18n = await initI18n({
55
+ config: config.i18n,
56
+ context: 'client',
57
+ language: languageCode
58
+ });
59
+ /**
60
+ * 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
61
+ * I.e. the `payload.auth` function would call `getAccessResults` without a fully-formed `req` object
62
+ */
63
+ const {
64
+ responseHeaders,
65
+ user
66
+ } = await executeAuthStrategies({
67
+ headers,
68
+ payload
69
+ });
70
+ const result = {
71
+ cookies,
72
+ headers,
73
+ i18n,
74
+ languageCode,
75
+ payload,
76
+ responseHeaders,
77
+ user
78
+ };
79
+ return result;
80
+ })();
81
+ partialReqContainer.reqResult = await partialReqContainer.reqResult;
82
+ return partialReqContainer.reqResult;
83
+ };
84
+ /**
85
+ * Initializes a full request object, including the `req` object and access control.
86
+ * As access control and getting the request locale is dependent on the current URL and
87
+ * query parameters, this function cannot be cached as often as the partial request object.
88
+ */
89
+ export const initReq = async function ({
90
+ configPromise,
91
+ importMap,
92
+ key,
93
+ overrides,
94
+ urlSuffix
95
+ }) {
27
96
  const {
97
+ cookies,
98
+ headers,
99
+ i18n,
100
+ languageCode,
101
+ payload,
28
102
  responseHeaders,
29
103
  user
30
- } = await executeAuthStrategies({
31
- headers,
32
- payload
104
+ } = await initPartialReq({
105
+ configPromise,
106
+ importMap
33
107
  });
34
- const {
35
- req: reqOverrides,
36
- ...optionsOverrides
37
- } = overrides || {};
38
- const req = await createLocalReq({
39
- req: {
108
+ const reqContainer = getInitReqContainer(key);
109
+ if (reqContainer?.reqResult && 'then' in reqContainer.reqResult && typeof reqContainer?.reqResult?.then === 'function') {
110
+ return await reqContainer.reqResult;
111
+ }
112
+ reqContainer.reqResult = (async () => {
113
+ const {
114
+ req: reqOverrides,
115
+ ...optionsOverrides
116
+ } = overrides || {};
117
+ const req = await createLocalReq({
118
+ req: {
119
+ headers,
120
+ host: headers.get('host'),
121
+ i18n: i18n,
122
+ responseHeaders,
123
+ url: `${payload.config.serverURL}${urlSuffix || ''}`,
124
+ user,
125
+ ...(reqOverrides || {})
126
+ },
127
+ ...(optionsOverrides || {})
128
+ }, payload);
129
+ const locale = await getRequestLocale({
130
+ req
131
+ });
132
+ req.locale = locale?.code;
133
+ const permissions = await getAccessResults({
134
+ req
135
+ });
136
+ const result = {
137
+ cookies,
40
138
  headers,
41
- host: headers.get('host'),
42
- i18n: i18n,
43
- responseHeaders,
44
- url: `${payload.config.serverURL}`,
45
- user,
46
- ...(reqOverrides || {})
47
- },
48
- ...(optionsOverrides || {})
49
- }, payload);
50
- const locale = await getRequestLocale({
51
- req
52
- });
53
- req.locale = locale?.code;
54
- const permissions = await getAccessResults({
55
- req
56
- });
57
- return {
58
- locale,
59
- permissions,
60
- req
61
- };
62
- });
139
+ languageCode,
140
+ locale,
141
+ permissions,
142
+ req
143
+ };
144
+ return result;
145
+ })();
146
+ reqContainer.reqResult = await reqContainer.reqResult;
147
+ return reqContainer.reqResult;
148
+ };
63
149
  //# sourceMappingURL=initReq.js.map
@@ -1 +1 @@
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":[]}
1
+ {"version":3,"file":"initReq.js","names":["initI18n","headers","getHeaders","createLocalReq","executeAuthStrategies","getAccessResults","getPayload","getRequestLanguage","parseCookies","cache","getRequestLocale","getPartialInitReqContainer","reqResult","getInitReqContainer","key","initPartialReq","configPromise","importMap","partialReqContainer","then","config","payload","cookies","languageCode","i18n","context","language","responseHeaders","user","result","initReq","overrides","urlSuffix","reqContainer","req","reqOverrides","optionsOverrides","host","get","url","serverURL","locale","code","permissions"],"sources":["../../src/utilities/initReq.ts"],"sourcesContent":["import type { AcceptedLanguages, I18n, I18nClient } from '@payloadcms/translations'\nimport type {\n ImportMap,\n Locale,\n Payload,\n PayloadRequest,\n SanitizedConfig,\n SanitizedPermissions,\n User,\n} 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 cookies: Map<string, string>\n headers: Awaited<ReturnType<typeof getHeaders>>\n languageCode: AcceptedLanguages\n locale?: Locale\n permissions: SanitizedPermissions\n req: PayloadRequest\n}\n\ntype PartialResult = {\n cookies: Map<string, string>\n headers: Awaited<ReturnType<typeof getHeaders>>\n i18n: I18nClient\n languageCode: AcceptedLanguages\n payload: Payload\n responseHeaders: Headers\n user: null | User\n}\n\n/**\n * Stable object to cache the partial request object across all pages\n */\nconst getPartialInitReqContainer = cache(function (): {\n reqResult: false | PartialResult | Promise<PartialResult>\n} {\n return {\n reqResult: false,\n }\n})\n\n/**\n * Stable object to cache the request object across all pages with the same key\n */\nconst getInitReqContainer = cache(function (\n /**\n * The key is solely used to control caching behavior\n */\n key: string,\n): {\n reqResult: false | Promise<Result> | Result\n} {\n return {\n reqResult: false,\n }\n})\n\n/**\n * Initializes a partial request object. This does not construct the `req` object and does\n * not run access control.\n *\n * The output of this function can be cached across all pages, which is why it is\n * separated from `initReq`.\n */\nconst initPartialReq = async function ({\n configPromise,\n importMap,\n}: {\n configPromise: Promise<SanitizedConfig> | SanitizedConfig\n importMap: ImportMap\n}): Promise<PartialResult> {\n const partialReqContainer = getPartialInitReqContainer()\n\n if (\n partialReqContainer?.reqResult &&\n 'then' in partialReqContainer.reqResult &&\n typeof partialReqContainer?.reqResult?.then === 'function'\n ) {\n return await partialReqContainer.reqResult\n }\n\n partialReqContainer.reqResult = (async () => {\n const config = await configPromise\n const payload = await getPayload({ config, importMap })\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 result: PartialResult = {\n cookies,\n headers,\n i18n,\n languageCode,\n payload,\n responseHeaders,\n user,\n }\n\n return result\n })()\n\n partialReqContainer.reqResult = await partialReqContainer.reqResult\n\n return partialReqContainer.reqResult\n}\n\n/**\n * Initializes a full request object, including the `req` object and access control.\n * As access control and getting the request locale is dependent on the current URL and\n * query parameters, this function cannot be cached as often as the partial request object.\n */\nexport const initReq = async function ({\n configPromise,\n importMap,\n key,\n overrides,\n urlSuffix,\n}: {\n configPromise: Promise<SanitizedConfig> | SanitizedConfig\n importMap: ImportMap\n key: string\n overrides?: Parameters<typeof createLocalReq>[0]\n urlSuffix?: string\n}): Promise<Result> {\n const { cookies, headers, i18n, languageCode, payload, responseHeaders, user } =\n await initPartialReq({\n configPromise,\n importMap,\n })\n\n const reqContainer = getInitReqContainer(key)\n\n if (\n reqContainer?.reqResult &&\n 'then' in reqContainer.reqResult &&\n typeof reqContainer?.reqResult?.then === 'function'\n ) {\n return await reqContainer.reqResult\n }\n\n reqContainer.reqResult = (async () => {\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}${urlSuffix || ''}`,\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 const result: Result = {\n cookies,\n headers,\n languageCode,\n locale,\n permissions,\n req,\n }\n\n return result\n })()\n\n reqContainer.reqResult = await reqContainer.reqResult\n\n return reqContainer.reqResult\n}\n"],"mappings":"AAWA,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;AAqBjC;;;AAGA,MAAMC,0BAAA,GAA6BF,KAAA,CAAM;EAGvC,OAAO;IACLG,SAAA,EAAW;EACb;AACF;AAEA;;;AAGA,MAAMC,mBAAA,GAAsBJ,KAAA,CAAM;AAChC;;;AAGAK,GAAW;EAIX,OAAO;IACLF,SAAA,EAAW;EACb;AACF;AAEA;;;;;;;AAOA,MAAMG,cAAA,GAAiB,eAAAA,CAAgB;EACrCC,aAAa;EACbC;AAAS,CAIV;EACC,MAAMC,mBAAA,GAAsBP,0BAAA;EAE5B,IACEO,mBAAA,EAAqBN,SAAA,IACrB,UAAUM,mBAAA,CAAoBN,SAAS,IACvC,OAAOM,mBAAA,EAAqBN,SAAA,EAAWO,IAAA,KAAS,YAChD;IACA,OAAO,MAAMD,mBAAA,CAAoBN,SAAS;EAC5C;EAEAM,mBAAA,CAAoBN,SAAS,GAAG,CAAC;IAC/B,MAAMQ,MAAA,GAAS,MAAMJ,aAAA;IACrB,MAAMK,OAAA,GAAU,MAAMf,UAAA,CAAW;MAAEc,MAAA;MAAQH;IAAU;IAErD,MAA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AE,GAAGC;IAAA,CAAkB,GAAGL,SAAA,IAAa,CAAC;IAEjE,MAAMG,GAAA,GAAM,MAAM/B,cAAA,CAChB;MACE+B,GAAA,EAAK;QACHjC,OAAA;QACAoC,IAAA,EAAMpC,OAAA,CAAQqC,GAAG,CAAC;QAClBd,IAAA,EAAMA,IAAA;QACNG,eAAA;QACAY,GAAA,EAAK,GAAGlB,OAAA,CAAQD,MAAM,CAACoB,SAAS,GAAGR,SAAA,IAAa,IAAI;QACpDJ,IAAA;QACA,IAAIO,YAAA,IAAgB,CAAC,CAAC;MACxB;MACA,IAAIC,gBAAA,IAAoB,CAAC,CAAC;IAC5B,GACAf,OAAA;IAGF,MAAMoB,MAAA,GAAS,MAAM/B,gBAAA,CAAiB;MACpCwB;IACF;IAEAA,GAAA,CAAIO,MAAM,GAAGA,MAAA,EAAQC,IAAA;IAErB,MAAMC,WAAA,GAAc,MAAMtC,gBAAA,CAAiB;MACzC6B;IACF;IAEA,MAAML,MAAA,GAAiB;MACrBP,OAAA;MACArB,OAAA;MACAsB,YAAA;MACAkB,MAAA;MACAE,WAAA;MACAT;IACF;IAEA,OAAOL,MAAA;EACT;EAEAI,YAAA,CAAarB,SAAS,GAAG,MAAMqB,YAAA,CAAarB,SAAS;EAErD,OAAOqB,YAAA,CAAarB,SAAS;AAC/B","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/views/NotFound/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;AACpC,OAAO,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAG/E,OAAO,KAAK,MAAM,OAAO,CAAA;AAOzB,eAAO,MAAM,oBAAoB,+BAE9B;IACD,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,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AAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE,CAAA;CAC9C,KAAG,OAAO,CAAC,QAAQ,CAUnB,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG,CAAC,IAAI,EAAE;IACxC,MAAM,EAAE,eAAe,CAAA;IACvB,IAAI,EAAE,IAAI,CAAA;IACV,MAAM,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE,CAAA;CAC9C,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEvB,eAAO,MAAM,YAAY,oGAKtB;IACD,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,CAAA;IAChC,SAAS,EAAE,SAAS,CAAA;IACpB,MAAM,EAAE,OAAO,CAAC;QACd,QAAQ,EAAE,MAAM,EAAE,CAAA;KACnB,CAAC,CAAA;IACF,YAAY,EAAE,OAAO,CAAC;QACpB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;KACjC,CAAC,CAAA;CACH,+BAkCA,CAAA;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,oBAAoB,qBAEvD"}
@@ -37,7 +37,8 @@ export const NotFoundPage = async ({
37
37
  adminRoute,
38
38
  path: '/not-found'
39
39
  }),
40
- searchParams
40
+ searchParams,
41
+ useLayoutReq: true
41
42
  });
42
43
  const params = await paramsPromise;
43
44
  if (!initPageResult.req.user || !initPageResult.permissions.canAccessAdmin) {