@payloadcms/next 4.0.0-internal.fa345ef → 4.0.0-internal.ff27d6e

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 (87) hide show
  1. package/dist/adapters/UnmountWhenHidden/index.d.ts +18 -0
  2. package/dist/adapters/UnmountWhenHidden/index.d.ts.map +1 -0
  3. package/dist/adapters/UnmountWhenHidden/index.js +64 -0
  4. package/dist/adapters/UnmountWhenHidden/index.js.map +1 -0
  5. package/dist/adapters/handleServerFunctions.d.ts.map +1 -1
  6. package/dist/adapters/handleServerFunctions.js +11 -2
  7. package/dist/adapters/handleServerFunctions.js.map +1 -1
  8. package/dist/adapters/layout.d.ts +2 -2
  9. package/dist/adapters/layout.d.ts.map +1 -1
  10. package/dist/adapters/layout.js +3 -3
  11. package/dist/adapters/layout.js.map +1 -1
  12. package/dist/adapters/metadata.d.ts.map +1 -1
  13. package/dist/adapters/metadata.js.map +1 -1
  14. package/dist/adapters/router.d.ts.map +1 -1
  15. package/dist/adapters/router.js +58 -20
  16. package/dist/adapters/router.js.map +1 -1
  17. package/dist/adapters/viewport.d.ts +4 -0
  18. package/dist/adapters/viewport.d.ts.map +1 -0
  19. package/dist/adapters/viewport.js +14 -0
  20. package/dist/adapters/viewport.js.map +1 -0
  21. package/dist/adapters/views.d.ts +3 -2
  22. package/dist/adapters/views.d.ts.map +1 -1
  23. package/dist/adapters/views.js +27 -17
  24. package/dist/adapters/views.js.map +1 -1
  25. package/dist/auth/login.d.ts +3 -18
  26. package/dist/auth/login.d.ts.map +1 -1
  27. package/dist/auth/login.js +6 -62
  28. package/dist/auth/login.js.map +1 -1
  29. package/dist/auth/logout.d.ts +2 -5
  30. package/dist/auth/logout.d.ts.map +1 -1
  31. package/dist/auth/logout.js +6 -47
  32. package/dist/auth/logout.js.map +1 -1
  33. package/dist/auth/refresh.d.ts +2 -4
  34. package/dist/auth/refresh.d.ts.map +1 -1
  35. package/dist/auth/refresh.js +6 -51
  36. package/dist/auth/refresh.js.map +1 -1
  37. package/dist/cjs/withPayload.cjs +95 -66
  38. package/dist/cjs/withPayload.cjs.map +4 -4
  39. package/dist/config.d.ts.map +1 -1
  40. package/dist/exports/css.d.ts.map +1 -1
  41. package/dist/exports/layouts.d.ts +1 -0
  42. package/dist/exports/layouts.d.ts.map +1 -1
  43. package/dist/exports/layouts.js +1 -0
  44. package/dist/exports/layouts.js.map +1 -1
  45. package/dist/index.d.ts +1 -1
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/prod/styles.css +1 -1
  48. package/dist/routes/graphql/handler.d.ts.map +1 -1
  49. package/dist/routes/graphql/handler.js +30 -6
  50. package/dist/routes/graphql/handler.js.map +1 -1
  51. package/dist/routes/graphql/playground.d.ts.map +1 -1
  52. package/dist/routes/graphql/playground.js +2 -2
  53. package/dist/routes/graphql/playground.js.map +1 -1
  54. package/dist/routes/rest/index.d.ts +8 -26
  55. package/dist/routes/rest/index.d.ts.map +1 -1
  56. package/dist/routes/rest/og/index.d.ts.map +1 -1
  57. package/dist/routes/rest/og/index.js.map +1 -1
  58. package/dist/utilities/getNextRequestI18n.d.ts.map +1 -1
  59. package/dist/utilities/initAdminContext.d.ts +8 -0
  60. package/dist/utilities/initAdminContext.d.ts.map +1 -0
  61. package/dist/utilities/initAdminContext.js +35 -0
  62. package/dist/utilities/initAdminContext.js.map +1 -0
  63. package/dist/utilities/selectiveCache.d.ts +18 -0
  64. package/dist/utilities/selectiveCache.d.ts.map +1 -0
  65. package/dist/utilities/selectiveCache.js +36 -0
  66. package/dist/utilities/selectiveCache.js.map +1 -0
  67. package/dist/withPayload/instantLoader.d.ts +16 -0
  68. package/dist/withPayload/instantLoader.d.ts.map +1 -0
  69. package/dist/withPayload/instantLoader.js +27 -0
  70. package/dist/withPayload/instantLoader.js.map +1 -0
  71. package/dist/withPayload/withPayload.d.ts +13 -2
  72. package/dist/withPayload/withPayload.d.ts.map +1 -1
  73. package/dist/withPayload/withPayload.js +50 -59
  74. package/dist/withPayload/withPayload.js.map +1 -1
  75. package/dist/withPayload/withPayload.utils.d.ts +34 -12
  76. package/dist/withPayload/withPayload.utils.d.ts.map +1 -1
  77. package/package.json +41 -42
  78. package/dist/utilities/getExistingAuthToken.d.ts +0 -7
  79. package/dist/utilities/getExistingAuthToken.d.ts.map +0 -1
  80. package/dist/utilities/getExistingAuthToken.js +0 -6
  81. package/dist/utilities/getExistingAuthToken.js.map +0 -1
  82. package/dist/utilities/setPayloadAuthCookie.d.ts +0 -9
  83. package/dist/utilities/setPayloadAuthCookie.d.ts.map +0 -1
  84. package/dist/utilities/setPayloadAuthCookie.js +0 -27
  85. package/dist/utilities/setPayloadAuthCookie.js.map +0 -1
  86. package/dist/withPayload/withPayload.spec.js +0 -54
  87. package/dist/withPayload/withPayload.spec.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/routes/graphql/handler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAqC,eAAe,EAAE,MAAM,SAAS,CAAA;AAqEjF,eAAO,MAAM,UAAU,GAAU,QAAQ,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,iBAyBlF,CAAA;AAED,eAAO,MAAM,IAAI,GACd,QAAQ,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,MAAY,SAAS,OAAO,sBAuD9E,CAAA"}
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/routes/graphql/handler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAqC,eAAe,EAAE,MAAM,SAAS,CAAA;AAsEjF,eAAO,MAAM,UAAU,WAAkB,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,iBAyBlF,CAAA;AAED,eAAO,MAAM,IAAI,WACN,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,eAAqB,OAAO,sBA6E9E,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import { configToSchema } from '@payloadcms/graphql';
2
2
  import { createHandler } from 'graphql-http/lib/use/fetch';
3
- import { status as httpStatus } from 'http-status';
4
- import { addDataAndFileToRequest, addLocalesToRequestFromData, createPayloadRequest, headersWithCors, logError, mergeHeaders } from 'payload';
3
+ import { addDataAndFileToRequest, addLocalesToRequestFromData, assertBranchReadable, createPayloadRequestFromWebRequest, headersWithCors, logError, mergeHeaders } from 'payload';
4
+ import { httpStatus } from 'payload/internal';
5
5
  const handleError = async ({
6
6
  err,
7
7
  payload,
@@ -77,20 +77,44 @@ export const getGraphql = async config => {
77
77
  };
78
78
  export const POST = config => async request => {
79
79
  const originalRequest = request.clone();
80
- const req = await createPayloadRequest({
80
+ const req = await createPayloadRequestFromWebRequest({
81
81
  canSetHeaders: true,
82
82
  config,
83
83
  request
84
84
  });
85
+ const {
86
+ payload
87
+ } = req;
88
+ if (payload.config.graphQL?.disable) {
89
+ return new Response(null, {
90
+ status: 404
91
+ });
92
+ }
93
+ // GraphQL takes its branch the same way REST does — a query param on the request —
94
+ // so it needs the same gate (§12.5). Answered as a bare 403 rather than a GraphQL
95
+ // error body: the request is refused before any operation is parsed.
96
+ try {
97
+ await assertBranchReadable({
98
+ req
99
+ });
100
+ } catch (error) {
101
+ if (!(error && typeof error === 'object' && 'status' in error && error.status === 403)) {
102
+ throw error;
103
+ }
104
+ return new Response(null, {
105
+ headers: headersWithCors({
106
+ headers: new Headers(),
107
+ req
108
+ }),
109
+ status: 403
110
+ });
111
+ }
85
112
  await addDataAndFileToRequest(req);
86
113
  addLocalesToRequestFromData(req);
87
114
  const {
88
115
  schema,
89
116
  validationRules
90
117
  } = await getGraphql(config);
91
- const {
92
- payload
93
- } = req;
94
118
  const headers = {};
95
119
  const apiResponse = await createHandler({
96
120
  context: {
@@ -1 +1 @@
1
- {"version":3,"file":"handler.js","names":["configToSchema","createHandler","status","httpStatus","addDataAndFileToRequest","addLocalesToRequestFromData","createPayloadRequest","headersWithCors","logError","mergeHeaders","handleError","err","payload","req","originalError","INTERNAL_SERVER_ERROR","errorMessage","message","config","debug","response","extensions","name","undefined","data","stack","statusCode","locations","path","hooks","afterError","reduce","promise","hook","result","context","error","graphqlResult","Promise","resolve","cached","global","_payload_graphql","graphql","getGraphql","process","env","NODE_ENV","resolvedConfig","schema","e","POST","request","originalRequest","clone","canSetHeaders","validationRules","headers","apiResponse","onOperation","args","errors","all","map","_","defaultRules","concat","resHeaders","Headers","key","append","Response","body","responseHeaders"],"sources":["../../../src/routes/graphql/handler.ts"],"sourcesContent":["import type { GraphQLError, GraphQLFormattedError } from 'graphql'\nimport type { APIError, Payload, PayloadRequest, SanitizedConfig } from 'payload'\n\nimport { configToSchema } from '@payloadcms/graphql'\nimport { createHandler } from 'graphql-http/lib/use/fetch'\nimport { status as httpStatus } from 'http-status'\nimport {\n addDataAndFileToRequest,\n addLocalesToRequestFromData,\n createPayloadRequest,\n headersWithCors,\n logError,\n mergeHeaders,\n} from 'payload'\n\nconst handleError = async ({\n err,\n payload,\n req,\n}: {\n err: GraphQLError\n payload: Payload\n req: PayloadRequest\n}): Promise<GraphQLFormattedError> => {\n const status = (err.originalError as APIError).status || httpStatus.INTERNAL_SERVER_ERROR\n let errorMessage = err.message\n logError({ err, payload })\n\n // Internal server errors can contain anything, including potentially sensitive data.\n // Therefore, error details will be hidden from the response unless `config.debug` is `true`\n if (!payload.config.debug && status === httpStatus.INTERNAL_SERVER_ERROR) {\n errorMessage = 'Something went wrong.'\n }\n\n let response: GraphQLFormattedError = {\n extensions: {\n name: err?.originalError?.name || undefined,\n data: (err && err.originalError && (err.originalError as APIError).data) || undefined,\n stack: payload.config.debug ? err.stack : undefined,\n statusCode: status,\n },\n locations: err.locations,\n message: errorMessage,\n path: err.path,\n }\n\n await payload.config.hooks.afterError?.reduce(async (promise, hook) => {\n await promise\n\n const result = await hook({\n context: req.context,\n error: err,\n graphqlResult: response,\n req,\n })\n\n if (result) {\n response = result.graphqlResult || response\n }\n }, Promise.resolve())\n\n return response\n}\n\nlet cached = global._payload_graphql\n\nif (!cached) {\n cached = global._payload_graphql = { graphql: null, promise: null }\n}\n\nexport const getGraphql = async (config: Promise<SanitizedConfig> | SanitizedConfig) => {\n if (process.env.NODE_ENV === 'development') {\n cached = global._payload_graphql = { graphql: null, promise: null }\n }\n\n if (cached.graphql) {\n return cached.graphql\n }\n\n if (!cached.promise) {\n const resolvedConfig = await config\n cached.promise = new Promise((resolve) => {\n const schema = configToSchema(resolvedConfig)\n resolve(cached.graphql || schema)\n })\n }\n\n try {\n cached.graphql = await cached.promise\n } catch (e) {\n cached.promise = null\n throw e\n }\n\n return cached.graphql\n}\n\nexport const POST =\n (config: Promise<SanitizedConfig> | SanitizedConfig) => async (request: Request) => {\n const originalRequest = request.clone()\n const req = await createPayloadRequest({\n canSetHeaders: true,\n config,\n request,\n })\n\n await addDataAndFileToRequest(req)\n addLocalesToRequestFromData(req)\n\n const { schema, validationRules } = await getGraphql(config)\n\n const { payload } = req\n\n const headers = {}\n const apiResponse = await createHandler({\n context: { headers, req },\n onOperation: async (request, args, result) => {\n const response =\n typeof payload.extensions === 'function'\n ? await payload.extensions({\n args,\n req: request,\n result,\n })\n : result\n if (response.errors) {\n const errors = (await Promise.all(\n result.errors.map((error) => {\n return handleError({ err: error, payload, req })\n }),\n )) as GraphQLError[]\n // errors type should be FormattedGraphQLError[] but onOperation has a return type of ExecutionResult instead of FormattedExecutionResult\n return { ...response, errors }\n }\n return response\n },\n schema,\n validationRules: (_, args, defaultRules) => defaultRules.concat(validationRules(args)),\n })(originalRequest)\n\n const resHeaders = headersWithCors({\n headers: new Headers(apiResponse.headers),\n req,\n })\n\n for (const key in headers) {\n resHeaders.append(key, headers[key])\n }\n\n return new Response(apiResponse.body, {\n headers: req.responseHeaders ? mergeHeaders(req.responseHeaders, resHeaders) : resHeaders,\n status: apiResponse.status,\n })\n }\n"],"mappings":"AAGA,SAASA,cAAc,QAAQ;AAC/B,SAASC,aAAa,QAAQ;AAC9B,SAASC,MAAA,IAAUC,UAAU,QAAQ;AACrC,SACEC,uBAAuB,EACvBC,2BA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rC;EAEA,OAAO,IAAIE,QAAA,CAASb,WAAA,CAAYc,IAAI,EAAE;IACpCf,OAAA,EAAS5C,GAAA,CAAI4D,eAAe,GAAGhE,YAAA,CAAaI,GAAA,CAAI4D,eAAe,EAAEN,UAAA,IAAcA,UAAA;IAC/EjE,MAAA,EAAQwD,WAAA,CAAYxD;EACtB;AACF","ignoreList":[]}
1
+ {"version":3,"file":"handler.js","names":["configToSchema","createHandler","addDataAndFileToRequest","addLocalesToRequestFromData","assertBranchReadable","createPayloadRequestFromWebRequest","headersWithCors","logError","mergeHeaders","httpStatus","handleError","err","payload","req","status","originalError","INTERNAL_SERVER_ERROR","errorMessage","message","config","debug","response","extensions","name","undefined","data","stack","statusCode","locations","path","hooks","afterError","reduce","promise","hook","result","context","error","graphqlResult","Promise","resolve","cached","global","_payload_graphql","graphql","getGraphql","process","env","NODE_ENV","resolvedConfig","schema","e","POST","request","originalRequest","clone","canSetHeaders","graphQL","disable","Response","headers","Headers","validationRules","apiResponse","onOperation","args","errors","all","map","_","defaultRules","concat","resHeaders","key","append","body","responseHeaders"],"sources":["../../../src/routes/graphql/handler.ts"],"sourcesContent":["import type { GraphQLError, GraphQLFormattedError } from 'graphql'\nimport type { APIError, Payload, PayloadRequest, SanitizedConfig } from 'payload'\n\nimport { configToSchema } from '@payloadcms/graphql'\nimport { createHandler } from 'graphql-http/lib/use/fetch'\nimport {\n addDataAndFileToRequest,\n addLocalesToRequestFromData,\n assertBranchReadable,\n createPayloadRequestFromWebRequest,\n headersWithCors,\n logError,\n mergeHeaders,\n} from 'payload'\nimport { httpStatus } from 'payload/internal'\n\nconst handleError = async ({\n err,\n payload,\n req,\n}: {\n err: GraphQLError\n payload: Payload\n req: PayloadRequest\n}): Promise<GraphQLFormattedError> => {\n const status = (err.originalError as APIError).status || httpStatus.INTERNAL_SERVER_ERROR\n let errorMessage = err.message\n logError({ err, payload })\n\n // Internal server errors can contain anything, including potentially sensitive data.\n // Therefore, error details will be hidden from the response unless `config.debug` is `true`\n if (!payload.config.debug && status === httpStatus.INTERNAL_SERVER_ERROR) {\n errorMessage = 'Something went wrong.'\n }\n\n let response: GraphQLFormattedError = {\n extensions: {\n name: err?.originalError?.name || undefined,\n data: (err && err.originalError && (err.originalError as APIError).data) || undefined,\n stack: payload.config.debug ? err.stack : undefined,\n statusCode: status,\n },\n locations: err.locations,\n message: errorMessage,\n path: err.path,\n }\n\n await payload.config.hooks.afterError?.reduce(async (promise, hook) => {\n await promise\n\n const result = await hook({\n context: req.context,\n error: err,\n graphqlResult: response,\n req,\n })\n\n if (result) {\n response = result.graphqlResult || response\n }\n }, Promise.resolve())\n\n return response\n}\n\nlet cached = global._payload_graphql\n\nif (!cached) {\n cached = global._payload_graphql = { graphql: null, promise: null }\n}\n\nexport const getGraphql = async (config: Promise<SanitizedConfig> | SanitizedConfig) => {\n if (process.env.NODE_ENV === 'development') {\n cached = global._payload_graphql = { graphql: null, promise: null }\n }\n\n if (cached.graphql) {\n return cached.graphql\n }\n\n if (!cached.promise) {\n const resolvedConfig = await config\n cached.promise = new Promise((resolve) => {\n const schema = configToSchema(resolvedConfig)\n resolve(cached.graphql || schema)\n })\n }\n\n try {\n cached.graphql = await cached.promise\n } catch (e) {\n cached.promise = null\n throw e\n }\n\n return cached.graphql\n}\n\nexport const POST =\n (config: Promise<SanitizedConfig> | SanitizedConfig) => async (request: Request) => {\n const originalRequest = request.clone()\n const req = await createPayloadRequestFromWebRequest({\n canSetHeaders: true,\n config,\n request,\n })\n\n const { payload } = req\n\n if (payload.config.graphQL?.disable) {\n return new Response(null, {\n status: 404,\n })\n }\n\n // GraphQL takes its branch the same way REST does — a query param on the request —\n // so it needs the same gate (§12.5). Answered as a bare 403 rather than a GraphQL\n // error body: the request is refused before any operation is parsed.\n try {\n await assertBranchReadable({ req })\n } catch (error) {\n if (!(error && typeof error === 'object' && 'status' in error && error.status === 403)) {\n throw error\n }\n\n return new Response(null, {\n headers: headersWithCors({ headers: new Headers(), req }),\n status: 403,\n })\n }\n\n await addDataAndFileToRequest(req)\n addLocalesToRequestFromData(req)\n\n const { schema, validationRules } = await getGraphql(config)\n\n const headers = {}\n const apiResponse = await createHandler({\n context: { headers, req },\n onOperation: async (request, args, result) => {\n const response =\n typeof payload.extensions === 'function'\n ? await payload.extensions({\n args,\n req: request,\n result,\n })\n : result\n if (response.errors) {\n const errors = (await Promise.all(\n result.errors.map((error) => {\n return handleError({ err: error, payload, req })\n }),\n )) as GraphQLError[]\n // errors type should be FormattedGraphQLError[] but onOperation has a return type of ExecutionResult instead of FormattedExecutionResult\n return { ...response, errors }\n }\n return response\n },\n schema,\n validationRules: (_, args, defaultRules) => defaultRules.concat(validationRules(args)),\n })(originalRequest)\n\n const resHeaders = headersWithCors({\n headers: new Headers(apiResponse.headers),\n req,\n })\n\n for (const key in headers) {\n resHeaders.append(key, headers[key])\n }\n\n return new Response(apiResponse.body, {\n headers: req.responseHeaders ? mergeHeaders(req.responseHeaders, resHeaders) : resHeaders,\n status: apiResponse.status,\n })\n }\n"],"mappings":"AAGA,SAASA,cAAc,QAAQ;AAC/B,SAASC,aAAa,QAAQ;AAC9B,SACEC,uBAAuB,EACvBC,2BAA2B,EAC3BC,oBAAoB,EACpBC,kCAAkC,EAClCC,eAAe,EACfC,QAAQ,EACRC,YAAY,QACP;AACP,SAASC,UAAU,QAAQ;AAE3B,MAAMC,WAAA,GAAc,MAAAA,CAAO;EACzBC,GAAG;EACHC,OAAO;EACPC;AAAG,CAKJ;EACC,MAAMC,MAAA,GAASH,GAAC,CAAII,aAAa,CAAcD,MAAM,IAAIL,UAAA,CAAWO,qBAAqB;EACzF,IAAIC,YAAA,GAAeN,GAAA,CAAIO,OAAO;EAC9BX,QAAA,CAAS;IAAEI,GAAA;IAAKC;EAAQ;EAExB;EACA;EACA,IAAI,CAACA,OAAA,CAAQO,MAAM,CAACC,KAAK,IAAIN,MAAA,KAAWL,UAAA,CAAWO,qBAAqB,EAAE;IACxEC,YAAA,GAAe;EACjB;EAEA,IAAII,QAAA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A,EAAKb,OAAO,CAACa,GAAA,CAAI;EACrC;EAEA,OAAO,IAAId,QAAA,CAASI,WAAA,CAAYY,IAAI,EAAE;IACpCf,OAAA,EAAS/C,GAAA,CAAI+D,eAAe,GAAGpE,YAAA,CAAaK,GAAA,CAAI+D,eAAe,EAAEJ,UAAA,IAAcA,UAAA;IAC/E1D,MAAA,EAAQiD,WAAA,CAAYjD;EACtB;AACF","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"playground.d.ts","sourceRoot":"","sources":["../../../src/routes/graphql/playground.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,KAAK,eAAe,EAAE,MAAM,SAAS,CAAA;AAGpE,eAAO,MAAM,GAAG,GAAI,QAAQ,OAAO,CAAC,eAAe,CAAC,MAAY,SAAS,OAAO,sBAiC/E,CAAA"}
1
+ {"version":3,"file":"playground.d.ts","sourceRoot":"","sources":["../../../src/routes/graphql/playground.ts"],"names":[],"mappings":"AACA,OAAO,EAAsC,KAAK,eAAe,EAAE,MAAM,SAAS,CAAA;AAGlF,eAAO,MAAM,GAAG,WAAY,OAAO,CAAC,eAAe,CAAC,eAAqB,OAAO,sBAiC/E,CAAA"}
@@ -1,8 +1,8 @@
1
1
  import { renderPlaygroundPage } from 'graphql-playground-html';
2
- import { createPayloadRequest } from 'payload';
2
+ import { createPayloadRequestFromWebRequest } from 'payload';
3
3
  import { formatAdminURL } from 'payload/shared';
4
4
  export const GET = config => async request => {
5
- const req = await createPayloadRequest({
5
+ const req = await createPayloadRequestFromWebRequest({
6
6
  config,
7
7
  request
8
8
  });
@@ -1 +1 @@
1
- {"version":3,"file":"playground.js","names":["renderPlaygroundPage","createPayloadRequest","formatAdminURL","GET","config","request","req","payload","graphQL","disable","disablePlaygroundInProduction","process","env","NODE_ENV","endpoint","apiRoute","routes","api","path","Response","settings","headers","status"],"sources":["../../../src/routes/graphql/playground.ts"],"sourcesContent":["import { renderPlaygroundPage } from 'graphql-playground-html'\nimport { createPayloadRequest, type SanitizedConfig } from 'payload'\nimport { formatAdminURL } from 'payload/shared'\n\nexport const GET = (config: Promise<SanitizedConfig>) => async (request: Request) => {\n const req = await createPayloadRequest({\n config,\n request,\n })\n\n if (\n (!req.payload.config.graphQL.disable &&\n !req.payload.config.graphQL.disablePlaygroundInProduction &&\n process.env.NODE_ENV === 'production') ||\n process.env.NODE_ENV !== 'production'\n ) {\n const endpoint = formatAdminURL({\n apiRoute: req.payload.config.routes.api,\n path: req.payload.config.routes.graphQL as `/${string}`,\n })\n return new Response(\n renderPlaygroundPage({\n endpoint,\n settings: {\n 'request.credentials': 'include',\n },\n }),\n {\n headers: {\n 'Content-Type': 'text/html',\n },\n status: 200,\n },\n )\n } else {\n return new Response('Route Not Found', { status: 404 })\n }\n}\n"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ;AACrC,SAASC,oBAAoB,QAA8B;AAC3D,SAASC,cAAc,QAAQ;AAE/B,OAAO,MAAMC,GAAA,GAAOC,MAAA,IAAqC,MAAOC,OAAA;EAC9D,MAAMC,GAAA,GAAM,MAAML,oBAAA,CAAqB;IACrCG,MAAA;IACAC;EACF;EAEA,IACE,CAAEC,GAAA,CAAIC,OAAO,CAACH,MAAM,CAACI,OAAO,CAACC,OAAO,IAClC,CAACH,GAAA,CAAIC,OAAO,CAACH,MAAM,CAACI,OAAO,CAACE,6BAA6B,IACzDC,OAAA,CAAQC,GAAG,CAACC,QAAQ,KAAK,gBAC3BF,OAAA,CAAQC,GAAG,CAACC,QAAQ,KAAK,cACzB;IACA,MAAMC,QAAA,GAAWZ,cAAA,CAAe;MAC9Ba,QAAA,EAAUT,GAAA,CAAIC,OAAO,CAACH,MAAM,CAACY,MAAM,CAACC,GAAG;MACvCC,IAAA,EAAMZ,GAAA,CAAIC,OAAO,CAACH,MAAM,CAACY,MAAM,CAACR;IAClC;IACA,OAAO,IAAIW,QAAA,CACTnB,oBAAA,CAAqB;MACnBc,QAAA;MACAM,QAAA,EAAU;QACR,uBAAuB;MACzB;IACF,IACA;MACEC,OAAA,EAAS;QACP,gBAAgB;MAClB;MACAC,MAAA,EAAQ;IACV;EAEJ,OAAO;IACL,OAAO,IAAIH,QAAA,CAAS,mBAAmB;MAAEG,MAAA,EAAQ;IAAI;EACvD;AACF","ignoreList":[]}
1
+ {"version":3,"file":"playground.js","names":["renderPlaygroundPage","createPayloadRequestFromWebRequest","formatAdminURL","GET","config","request","req","payload","graphQL","disable","disablePlaygroundInProduction","process","env","NODE_ENV","endpoint","apiRoute","routes","api","path","Response","settings","headers","status"],"sources":["../../../src/routes/graphql/playground.ts"],"sourcesContent":["import { renderPlaygroundPage } from 'graphql-playground-html'\nimport { createPayloadRequestFromWebRequest, type SanitizedConfig } from 'payload'\nimport { formatAdminURL } from 'payload/shared'\n\nexport const GET = (config: Promise<SanitizedConfig>) => async (request: Request) => {\n const req = await createPayloadRequestFromWebRequest({\n config,\n request,\n })\n\n if (\n (!req.payload.config.graphQL.disable &&\n !req.payload.config.graphQL.disablePlaygroundInProduction &&\n process.env.NODE_ENV === 'production') ||\n process.env.NODE_ENV !== 'production'\n ) {\n const endpoint = formatAdminURL({\n apiRoute: req.payload.config.routes.api,\n path: req.payload.config.routes.graphQL as `/${string}`,\n })\n return new Response(\n renderPlaygroundPage({\n endpoint,\n settings: {\n 'request.credentials': 'include',\n },\n }),\n {\n headers: {\n 'Content-Type': 'text/html',\n },\n status: 200,\n },\n )\n } else {\n return new Response('Route Not Found', { status: 404 })\n }\n}\n"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ;AACrC,SAASC,kCAAkC,QAA8B;AACzE,SAASC,cAAc,QAAQ;AAE/B,OAAO,MAAMC,GAAA,GAAOC,MAAA,IAAqC,MAAOC,OAAA;EAC9D,MAAMC,GAAA,GAAM,MAAML,kCAAA,CAAmC;IACnDG,MAAA;IACAC;EACF;EAEA,IACE,CAAEC,GAAA,CAAIC,OAAO,CAACH,MAAM,CAACI,OAAO,CAACC,OAAO,IAClC,CAACH,GAAA,CAAIC,OAAO,CAACH,MAAM,CAACI,OAAO,CAACE,6BAA6B,IACzDC,OAAA,CAAQC,GAAG,CAACC,QAAQ,KAAK,gBAC3BF,OAAA,CAAQC,GAAG,CAACC,QAAQ,KAAK,cACzB;IACA,MAAMC,QAAA,GAAWZ,cAAA,CAAe;MAC9Ba,QAAA,EAAUT,GAAA,CAAIC,OAAO,CAACH,MAAM,CAACY,MAAM,CAACC,GAAG;MACvCC,IAAA,EAAMZ,GAAA,CAAIC,OAAO,CAACH,MAAM,CAACY,MAAM,CAACR;IAClC;IACA,OAAO,IAAIW,QAAA,CACTnB,oBAAA,CAAqB;MACnBc,QAAA;MACAM,QAAA,EAAU;QACR,uBAAuB;MACzB;IACF,IACA;MACEC,OAAA,EAAS;QACP,gBAAgB;MAClB;MACAC,MAAA,EAAQ;IACV;EAEJ,OAAO;IACL,OAAO,IAAIH,QAAA,CAAS,mBAAmB;MAAEG,MAAA,EAAQ;IAAI;EACvD;AACF","ignoreList":[]}
@@ -1,32 +1,14 @@
1
1
  import { type SanitizedConfig } from 'payload';
2
- export declare const OPTIONS: (config: Promise<SanitizedConfig> | SanitizedConfig) => (request: Request, args: {
3
- params: Promise<{
4
- slug?: string[];
5
- }>;
6
- }) => Promise<Response>;
7
- export declare const GET: (config: Promise<SanitizedConfig> | SanitizedConfig) => (request: Request, args: {
8
- params: Promise<{
9
- slug?: string[];
10
- }>;
11
- }) => Promise<Response>;
12
- export declare const POST: (config: Promise<SanitizedConfig> | SanitizedConfig) => (request: Request, args: {
13
- params: Promise<{
14
- slug?: string[];
15
- }>;
16
- }) => Promise<Response>;
17
- export declare const DELETE: (config: Promise<SanitizedConfig> | SanitizedConfig) => (request: Request, args: {
18
- params: Promise<{
19
- slug?: string[];
20
- }>;
21
- }) => Promise<Response>;
22
- export declare const PATCH: (config: Promise<SanitizedConfig> | SanitizedConfig) => (request: Request, args: {
23
- params: Promise<{
24
- slug?: string[];
25
- }>;
26
- }) => Promise<Response>;
27
- export declare const PUT: (config: Promise<SanitizedConfig> | SanitizedConfig) => (request: Request, args: {
2
+ declare const handlerBuilder: (config: Promise<SanitizedConfig> | SanitizedConfig) => (request: Request, args: {
28
3
  params: Promise<{
29
4
  slug?: string[];
30
5
  }>;
31
6
  }) => Promise<Response>;
7
+ export declare const OPTIONS: typeof handlerBuilder;
8
+ export declare const GET: typeof handlerBuilder;
9
+ export declare const POST: typeof handlerBuilder;
10
+ export declare const DELETE: typeof handlerBuilder;
11
+ export declare const PATCH: typeof handlerBuilder;
12
+ export declare const PUT: typeof handlerBuilder;
13
+ export {};
32
14
  //# sourceMappingURL=index.d.ts.map
@@ -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;AAiD/D,eAAO,MAAM,OAAO,WAzCT,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,MAEjD,SAAS,OAAO,EAChB,MAAM;IACJ,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;CACrC,KACA,OAAO,CAAC,QAAQ,CAmCgB,CAAA;AAErC,eAAO,MAAM,GAAG,WA3CL,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,MAEjD,SAAS,OAAO,EAChB,MAAM;IACJ,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;CACrC,KACA,OAAO,CAAC,QAAQ,CAqCY,CAAA;AAEjC,eAAO,MAAM,IAAI,WA7CN,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,MAEjD,SAAS,OAAO,EAChB,MAAM;IACJ,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;CACrC,KACA,OAAO,CAAC,QAAQ,CAuCa,CAAA;AAElC,eAAO,MAAM,MA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AAO,MAAM,GAAG,uBAAiB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/og/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAc7C,eAAO,MAAM,OAAO,WAAW,CAAA;AAE/B,eAAO,MAAM,WAAW,cAAc,CAAA;AAEtC,eAAO,MAAM,eAAe,EAAE,cA8D7B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/og/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAc7C,eAAO,MAAM,OAAO,WAAW,CAAA;AAE/B,eAAO,MAAM,WAAW,cAAc,CAAA;AAEtC,eAAO,MAAM,eAAe,EAAE,cA4D7B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["PayloadIcon","fs","ImageResponse","path","React","fileURLToPath","OGImage","filename","import","meta","url","dirname","runtime","contentType","generateOGImage","req","config","payload","admin","defaultOGImageType","Response","json","error","status","searchParams","URL","hasTitle","has","title","get","slice","hasLeader","leader","replace","description","fontData","readFile","join","e","logger","message","fontFamily","_jsx","Fallback","Icon","components","graphics","importMap","fonts","name","data","style","weight","height","width"],"sources":["../../../../src/routes/rest/og/index.tsx"],"sourcesContent":["import type { PayloadHandler } from 'payload'\n\nimport { PayloadIcon } from '@payloadcms/ui/shared'\nimport fs from 'fs/promises'\nimport { ImageResponse } from 'next/og.js'\nimport path from 'path'\nimport React from 'react'\nimport { fileURLToPath } from 'url'\n\nimport { OGImage } from './image.js'\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nexport const runtime = 'nodejs'\n\nexport const contentType = 'image/png'\n\nexport const generateOGImage: PayloadHandler = async (req) => {\n const config = req.payload.config\n\n if (config.admin.meta.defaultOGImageType === 'off') {\n return Response.json({ error: `Open Graph images are disabled` }, { status: 400 })\n }\n\n try {\n const { searchParams } = new URL(req.url)\n\n const hasTitle = searchParams.has('title')\n const title = hasTitle ? searchParams.get('title')?.slice(0, 100) : ''\n const hasLeader = searchParams.has('leader')\n const leader = hasLeader ? searchParams.get('leader')?.slice(0, 100).replace('-', ' ') : ''\n const description = searchParams.has('description') ? searchParams.get('description') : ''\n\n let fontData\n\n try {\n // TODO: replace with `.woff2` file when supported\n // See https://github.com/vercel/next.js/issues/63935\n // Or better yet, use a CDN like Google Fonts if ever supported\n fontData = fs.readFile(path.join(dirname, 'roboto-regular.woff'))\n } catch (e) {\n req.payload.logger.error(`Error reading font file or not readable: ${e.message}`)\n }\n\n const fontFamily = 'Roboto, sans-serif'\n\n return new ImageResponse(\n (\n <OGImage\n description={description}\n Fallback={PayloadIcon}\n fontFamily={fontFamily}\n Icon={config.admin?.components?.graphics?.Icon}\n importMap={req.payload.importMap}\n leader={leader}\n title={title}\n />\n ),\n {\n ...(fontData\n ? {\n fonts: [\n {\n name: 'Roboto',\n data: await fontData,\n style: 'normal',\n weight: 400,\n },\n ],\n }\n : {}),\n height: 630,\n width: 1200,\n },\n )\n } catch (e: any) {\n req.payload.logger.error(`Error generating Open Graph image: ${e.message}`)\n return Response.json({ error: `Internal Server Error: ${e.message}` }, { status: 500 })\n }\n}\n"],"mappings":";AAEA,SAASA,WAAW,QAAQ;AAC5B,OAAOC,EAAA,MAAQ;AACf,SAASC,aAAa,QAAQ;AAC9B,OAAOC,IAAA,MAAU;AACjB,OAAOC,KAAA,MAAW;AAClB,SAASC,aAAa,QAAQ;AAE9B,SAASC,OAAO,QAAQ;AAExB,MAAMC,QAAA,GAAWF,aAAA,CAAcG,MAAA,CAAAC,IAAA,CAAYC,GAAG;AAC9C,MAAMC,OAAA,GAAUR,IAAA,CAAKQ,OAAO,CAACJ,QAAA;AAE7B,OAAO,MAAMK,OAAA,GAAU;AAEvB,OAAO,MAAMC,WAAA,GAAc;AAE3B,OAAO,MAAMC,eAAA,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E2B,UAAA,EAAYC,QAAA,EAAUF,IAAA;MAC1CG,SAAA,EAAWhC,GAAA,CAAIE,OAAO,CAAC8B,SAAS;MAChCf,MAAA,EAAQA,MAAA;MACRJ,KAAA,EAAOA;QAGX;MACE,IAAIO,QAAA,GACA;QACEa,KAAA,EAAO,CACL;UACEC,IAAA,EAAM;UACNC,IAAA,EAAM,MAAMf,QAAA;UACZgB,KAAA,EAAO;UACPC,MAAA,EAAQ;QACV;MAEJ,IACA,CAAC,CAAC;MACNC,MAAA,EAAQ;MACRC,KAAA,EAAO;IACT;EAEJ,EAAE,OAAOhB,CAAA,EAAQ;IACfvB,GAAA,CAAIE,OAAO,CAACsB,MAAM,CAACjB,KAAK,CAAC,sCAAsCgB,CAAA,CAAEE,OAAO,EAAE;IAC1E,OAAOpB,QAAA,CAASC,IAAI,CAAC;MAAEC,KAAA,EAAO,0BAA0BgB,CAAA,CAAEE,OAAO;IAAG,GAAG;MAAEjB,MAAA,EAAQ;IAAI;EACvF;AACF","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["PayloadIcon","fs","ImageResponse","path","React","fileURLToPath","OGImage","filename","import","meta","url","dirname","runtime","contentType","generateOGImage","req","config","payload","admin","defaultOGImageType","Response","json","error","status","searchParams","URL","hasTitle","has","title","get","slice","hasLeader","leader","replace","description","fontData","readFile","join","e","logger","message","fontFamily","_jsx","Fallback","Icon","components","graphics","importMap","fonts","name","data","style","weight","height","width"],"sources":["../../../../src/routes/rest/og/index.tsx"],"sourcesContent":["import type { PayloadHandler } from 'payload'\n\nimport { PayloadIcon } from '@payloadcms/ui/shared'\nimport fs from 'fs/promises'\nimport { ImageResponse } from 'next/og.js'\nimport path from 'path'\nimport React from 'react'\nimport { fileURLToPath } from 'url'\n\nimport { OGImage } from './image.js'\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nexport const runtime = 'nodejs'\n\nexport const contentType = 'image/png'\n\nexport const generateOGImage: PayloadHandler = async (req) => {\n const config = req.payload.config\n\n if (config.admin.meta.defaultOGImageType === 'off') {\n return Response.json({ error: `Open Graph images are disabled` }, { status: 400 })\n }\n\n try {\n const { searchParams } = new URL(req.url)\n\n const hasTitle = searchParams.has('title')\n const title = hasTitle ? searchParams.get('title')?.slice(0, 100) : ''\n const hasLeader = searchParams.has('leader')\n const leader = hasLeader ? searchParams.get('leader')?.slice(0, 100).replace('-', ' ') : ''\n const description = searchParams.has('description') ? searchParams.get('description') : ''\n\n let fontData\n\n try {\n // TODO: replace with `.woff2` file when supported\n // See https://github.com/vercel/next.js/issues/63935\n // Or better yet, use a CDN like Google Fonts if ever supported\n fontData = fs.readFile(path.join(dirname, 'roboto-regular.woff'))\n } catch (e) {\n req.payload.logger.error(`Error reading font file or not readable: ${e.message}`)\n }\n\n const fontFamily = 'Roboto, sans-serif'\n\n return new ImageResponse(\n <OGImage\n description={description}\n Fallback={PayloadIcon}\n fontFamily={fontFamily}\n Icon={config.admin?.components?.graphics?.Icon}\n importMap={req.payload.importMap}\n leader={leader}\n title={title}\n />,\n {\n ...(fontData\n ? {\n fonts: [\n {\n name: 'Roboto',\n data: await fontData,\n style: 'normal',\n weight: 400,\n },\n ],\n }\n : {}),\n height: 630,\n width: 1200,\n },\n )\n } catch (e: any) {\n req.payload.logger.error(`Error generating Open Graph image: ${e.message}`)\n return Response.json({ error: `Internal Server Error: ${e.message}` }, { status: 500 })\n }\n}\n"],"mappings":";AAEA,SAASA,WAAW,QAAQ;AAC5B,OAAOC,EAAA,MAAQ;AACf,SAASC,aAAa,QAAQ;AAC9B,OAAOC,IAAA,MAAU;AACjB,OAAOC,KAAA,MAAW;AAClB,SAASC,aAAa,QAAQ;AAE9B,SAASC,OAAO,QAAQ;AAExB,MAAMC,QAAA,GAAWF,aAAA,CAAcG,MAAA,CAAAC,IAAA,CAAYC,GAAG;AAC9C,MAAMC,OAAA,GAAUR,IAAA,CAAKQ,OAAO,CAACJ,QAAA;AAE7B,OAAO,MAAMK,OAAA,GAAU;AAEvB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A,UAAA;MACZG,IAAA,EAAM5B,MAAA,CAAOE,KAAK,EAAE2B,UAAA,EAAYC,QAAA,EAAUF,IAAA;MAC1CG,SAAA,EAAWhC,GAAA,CAAIE,OAAO,CAAC8B,SAAS;MAChCf,MAAA,EAAQA,MAAA;MACRJ,KAAA,EAAOA;QAET;MACE,IAAIO,QAAA,GACA;QACEa,KAAA,EAAO,CACL;UACEC,IAAA,EAAM;UACNC,IAAA,EAAM,MAAMf,QAAA;UACZgB,KAAA,EAAO;UACPC,MAAA,EAAQ;QACV;MAEJ,IACA,CAAC,CAAC;MACNC,MAAA,EAAQ;MACRC,KAAA,EAAO;IACT;EAEJ,EAAE,OAAOhB,CAAA,EAAQ;IACfvB,GAAA,CAAIE,OAAO,CAACsB,MAAM,CAACjB,KAAK,CAAC,sCAAsCgB,CAAA,CAAEE,OAAO,EAAE;IAC1E,OAAOpB,QAAA,CAASC,IAAI,CAAC;MAAEC,KAAA,EAAO,0BAA0BgB,CAAA,CAAEE,OAAO;IAAG,GAAG;MAAEjB,MAAA,EAAQ;IAAI;EACvF;AACF","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"getNextRequestI18n.d.ts","sourceRoot":"","sources":["../../src/utilities/getNextRequestI18n.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAIpF,OAAO,EAAsB,KAAK,eAAe,EAAE,MAAM,SAAS,CAAA;AAElE;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAE7B,uBAAuB,GAAG,EAAE,EAC5B,gCAAgC,SAAS,MAAM,GAAG,KAAK,EACvD,aAEC;IACD,MAAM,EAAE,eAAe,CAAA;CACxB,KAAG,OAAO,CACT,CAAC,gCAAgC,CAAC,SAAS,CAAC,KAAK,CAAC,GAC9C,UAAU,GACV,uBAAuB,SAAS,MAAM,GACpC,UAAU,CAAC,uBAAuB,EAAE,gCAAgC,CAAC,GACrE,UAAU,CAAC,wBAAwB,EAAE,gCAAgC,CAAC,CAO7E,CAAA"}
1
+ {"version":3,"file":"getNextRequestI18n.d.ts","sourceRoot":"","sources":["../../src/utilities/getNextRequestI18n.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAIpF,OAAO,EAAsB,KAAK,eAAe,EAAE,MAAM,SAAS,CAAA;AAElE;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAE7B,uBAAuB,GAAG,EAAE,EAC5B,gCAAgC,SAAS,MAAM,GAAG,KAAK,eAGtD;IACD,MAAM,EAAE,eAAe,CAAA;CACxB,KAAG,OAAO,CACT,CAAC,gCAAgC,CAAC,SAAS,CAAC,KAAK,CAAC,GAC9C,UAAU,GACV,uBAAuB,SAAS,MAAM,GACpC,UAAU,CAAC,uBAAuB,EAAE,gCAAgC,CAAC,GACrE,UAAU,CAAC,wBAAwB,EAAE,gCAAgC,CAAC,CAO7E,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { AdminContext } from 'payload';
2
+ import type { InitAdminContextArgs } from 'payload/internal';
3
+ type NextInitAdminContextArgs = {
4
+ key: string;
5
+ } & Omit<InitAdminContextArgs, 'cache' | 'key' | 'serverAdapter'>;
6
+ export declare const initAdminContext: (args: NextInitAdminContextArgs) => Promise<AdminContext>;
7
+ export {};
8
+ //# sourceMappingURL=initAdminContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initAdminContext.d.ts","sourceRoot":"","sources":["../../src/utilities/initAdminContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,KAAK,EAAqB,oBAAoB,EAAuB,MAAM,kBAAkB,CAAA;AAuBpG,KAAK,wBAAwB,GAAG;IAC9B,GAAG,EAAE,MAAM,CAAA;CACZ,GAAG,IAAI,CAAC,oBAAoB,EAAE,OAAO,GAAG,KAAK,GAAG,eAAe,CAAC,CAAA;AAEjE,eAAO,MAAM,gBAAgB,SAAgB,wBAAwB,0BAapE,CAAA"}
@@ -0,0 +1,35 @@
1
+ import { connection } from 'next/server.js';
2
+ import { initAdminContext as initPayloadAdminContext } from 'payload/internal';
3
+ import { nextServerAdapter } from '../adapters/server.js';
4
+ import { selectiveCache } from './selectiveCache.js';
5
+ const partialContextCache = selectiveCache('partialContext');
6
+ const localeCache = selectiveCache('locale');
7
+ const adminContextCache = selectiveCache('adminContext');
8
+ const cache = {
9
+ getLocale: (resolveLocale, ...key) => localeCache.get({
10
+ create: resolveLocale,
11
+ key
12
+ }),
13
+ getPartial: createPartialContext => partialContextCache.get({
14
+ create: createPartialContext,
15
+ key: ['global']
16
+ }),
17
+ getRequest: (createContext, key, ...cacheArgs) => adminContextCache.get({
18
+ create: createContext,
19
+ key: [key, ...cacheArgs]
20
+ })
21
+ };
22
+ export const initAdminContext = async args => {
23
+ // Without this, enabling `cacheComponents` throws as soon as the admin panel calls `new Date()`
24
+ // (e.g. inside the database adapter): "Next.js encountered the unstable value `new Date()` while
25
+ // prerendering". `connection()` tells Next.js to wait for the incoming request, so everything
26
+ // after it renders per request and can use `new Date()`, `Math.random()`, etc.
27
+ // https://nextjs.org/docs/app/api-reference/functions/connection
28
+ await connection();
29
+ return initPayloadAdminContext({
30
+ ...args,
31
+ cache,
32
+ serverAdapter: nextServerAdapter
33
+ });
34
+ };
35
+ //# sourceMappingURL=initAdminContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initAdminContext.js","names":["connection","initAdminContext","initPayloadAdminContext","nextServerAdapter","selectiveCache","partialContextCache","localeCache","adminContextCache","cache","getLocale","resolveLocale","key","get","create","getPartial","createPartialContext","getRequest","createContext","cacheArgs","args","serverAdapter"],"sources":["../../src/utilities/initAdminContext.ts"],"sourcesContent":["import type { AdminContext } from 'payload'\nimport type { AdminContextCache, InitAdminContextArgs, PartialAdminContext } from 'payload/internal'\n\nimport { connection } from 'next/server.js'\nimport { initAdminContext as initPayloadAdminContext } from 'payload/internal'\n\nimport { nextServerAdapter } from '../adapters/server.js'\nimport { selectiveCache } from './selectiveCache.js'\n\nconst partialContextCache = selectiveCache<PartialAdminContext>('partialContext')\nconst localeCache = selectiveCache<Pick<AdminContext, 'locale'>>('locale')\nconst adminContextCache = selectiveCache<AdminContext>('adminContext')\n\nconst cache: AdminContextCache = {\n getLocale: (resolveLocale, ...key) => localeCache.get({ create: resolveLocale, key }),\n getPartial: (createPartialContext) =>\n partialContextCache.get({ create: createPartialContext, key: ['global'] }),\n getRequest: (createContext, key, ...cacheArgs) =>\n adminContextCache.get({\n create: createContext,\n key: [key, ...cacheArgs],\n }),\n}\n\ntype NextInitAdminContextArgs = {\n key: string\n} & Omit<InitAdminContextArgs, 'cache' | 'key' | 'serverAdapter'>\n\nexport const initAdminContext = async (args: NextInitAdminContextArgs) => {\n // Without this, enabling `cacheComponents` throws as soon as the admin panel calls `new Date()`\n // (e.g. inside the database adapter): \"Next.js encountered the unstable value `new Date()` while\n // prerendering\". `connection()` tells Next.js to wait for the incoming request, so everything\n // after it renders per request and can use `new Date()`, `Math.random()`, etc.\n // https://nextjs.org/docs/app/api-reference/functions/connection\n await connection()\n\n return initPayloadAdminContext({\n ...args,\n cache,\n serverAdapter: nextServerAdapter,\n })\n}\n"],"mappings":"AAGA,SAASA,UAAU,QAAQ;AAC3B,SAASC,gBAAA,IAAoBC,uBAAuB,QAAQ;AAE5D,SAASC,iBAAiB,QAAQ;AAClC,SAASC,cAAc,QAAQ;AAE/B,MAAMC,mBAAA,GAAsBD,cAAA,CAAoC;AAChE,MAAME,WAAA,GAAcF,cAAA,CAA6C;AACjE,MAAMG,iBAAA,GAAoBH,cAAA,CAA6B;AAEvD,MAAMI,KAAA,GAA2B;EAC/BC,SAAA,EAAWA,CAACC,aAAA,EAAe,GAAGC,GAAA,KAAQL,WAAA,CAAYM,GAAG,CAAC;IAAEC,MAAA,EAAQH,aAAA;IAAeC;EAAI;EACnFG,UAAA,EAAaC,oBAAA,IACXV,mBAAA,CAAoBO,GAAG,CAAC;IAAEC,MAAA,EAAQE,oBAAA;IAAsBJ,GAAA,EAAK,CAAC;EAAU;EAC1EK,UAAA,EAAYA,CAACC,aAAA,EAAeN,GAAA,EAAK,GAAGO,SAAA,KAClCX,iBAAA,CAAkBK,GAAG,CAAC;IACpBC,MAAA,EAAQI,aAAA;IACRN,GAAA,EAAK,CAACA,GAAA,E,GAAQO,SAAA;EAChB;AACJ;AAMA,OAAO,MAAMjB,gBAAA,GAAmB,MAAOkB,IAAA;EACrC;EACA;EACA;EACA;EACA;EACA,MAAMnB,UAAA;EAEN,OAAOE,uBAAA,CAAwB;IAC7B,GAAGiB,IAAI;IACPX,KAAA;IACAY,aAAA,EAAejB;EACjB;AACF","ignoreList":[]}
@@ -0,0 +1,18 @@
1
+ type CachedValue = object;
2
+ type GetCachedArgs<TValue extends object> = {
3
+ /** Creates the value when it is not cached. */
4
+ create: () => Promise<TValue>;
5
+ /** Values that identify the cached value. */
6
+ key: unknown[];
7
+ };
8
+ /**
9
+ * Creates a selective cache function that provides more control over React's request-level caching behavior.
10
+ *
11
+ * @param namespace - A namespace to group related cached values
12
+ * @returns A function that manages cached values within the specified namespace
13
+ */
14
+ export declare function selectiveCache<TValue extends object = CachedValue>(namespace: string): {
15
+ get: ({ create, key }: GetCachedArgs<TValue>) => Promise<TValue>;
16
+ };
17
+ export {};
18
+ //# sourceMappingURL=selectiveCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectiveCache.d.ts","sourceRoot":"","sources":["../../src/utilities/selectiveCache.ts"],"names":[],"mappings":"AAEA,KAAK,WAAW,GAAG,MAAM,CAAA;AAEzB,KAAK,aAAa,CAAC,MAAM,SAAS,MAAM,IAAI;IAC1C,+CAA+C;IAC/C,MAAM,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAA;IAC7B,6CAA6C;IAC7C,GAAG,EAAE,OAAO,EAAE,CAAA;CACf,CAAA;AAaD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,SAAS,MAAM,GAAG,WAAW,EAAE,SAAS,EAAE,MAAM;IA4BjF,GAAG,oBAlBqC,aAAa,CAAC,MAAM,CAAC,KAAG,OAAO,CAAC,MAAM,CAAC;EAoBlF"}
@@ -0,0 +1,36 @@
1
+ import { cache } from 'react';
2
+ // Module-scoped cache container that holds all cached, stable containers
3
+ // - these may hold the stable value, or a promise to the stable value
4
+ const globalCacheContainer = {};
5
+ /**
6
+ * Creates a selective cache function that provides more control over React's request-level caching behavior.
7
+ *
8
+ * @param namespace - A namespace to group related cached values
9
+ * @returns A function that manages cached values within the specified namespace
10
+ */
11
+ export function selectiveCache(namespace) {
12
+ if (!globalCacheContainer[namespace]) {
13
+ globalCacheContainer[namespace] = cache((..._args) => ({
14
+ value: null
15
+ }));
16
+ }
17
+ /**
18
+ * Gets or creates a cached value for a specific key within the namespace
19
+ */
20
+ const getCached = async ({
21
+ create,
22
+ key
23
+ }) => {
24
+ const stableObjectFn = globalCacheContainer[namespace];
25
+ const stableObject = stableObjectFn(...key);
26
+ if (stableObject?.value && 'then' in stableObject.value && typeof stableObject.value?.then === 'function') {
27
+ return await stableObject.value;
28
+ }
29
+ stableObject.value = create();
30
+ return await stableObject.value;
31
+ };
32
+ return {
33
+ get: getCached
34
+ };
35
+ }
36
+ //# sourceMappingURL=selectiveCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectiveCache.js","names":["cache","globalCacheContainer","selectiveCache","namespace","_args","value","getCached","create","key","stableObjectFn","stableObject","then","get"],"sources":["../../src/utilities/selectiveCache.ts"],"sourcesContent":["import { cache } from 'react'\n\ntype CachedValue = object\n\ntype GetCachedArgs<TValue extends object> = {\n /** Creates the value when it is not cached. */\n create: () => Promise<TValue>\n /** Values that identify the cached value. */\n key: unknown[]\n}\n\n// Module-scoped cache container that holds all cached, stable containers\n// - these may hold the stable value, or a promise to the stable value\nconst globalCacheContainer: Record<\n string,\n <TValue extends object = CachedValue>(\n ...args: unknown[]\n ) => {\n value: null | Promise<TValue> | TValue\n }\n> = {}\n\n/**\n * Creates a selective cache function that provides more control over React's request-level caching behavior.\n *\n * @param namespace - A namespace to group related cached values\n * @returns A function that manages cached values within the specified namespace\n */\nexport function selectiveCache<TValue extends object = CachedValue>(namespace: string) {\n if (!globalCacheContainer[namespace]) {\n globalCacheContainer[namespace] = cache((..._args) => ({\n value: null,\n }))\n }\n\n /**\n * Gets or creates a cached value for a specific key within the namespace\n */\n const getCached = async ({ create, key }: GetCachedArgs<TValue>): Promise<TValue> => {\n const stableObjectFn = globalCacheContainer[namespace]\n const stableObject = stableObjectFn<TValue>(...key)\n\n if (\n stableObject?.value &&\n 'then' in stableObject.value &&\n typeof stableObject.value?.then === 'function'\n ) {\n return await stableObject.value\n }\n\n stableObject.value = create()\n\n return await stableObject.value\n }\n\n return {\n get: getCached,\n }\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ;AAWtB;AACA;AACA,MAAMC,oBAAA,GAOF,CAAC;AAEL;;;;;;AAMA,OAAO,SAASC,eAAoDC,SAAiB;EACnF,IAAI,CAACF,oBAAoB,CAACE,SAAA,CAAU,EAAE;IACpCF,oBAAoB,CAACE,SAAA,CAAU,GAAGH,KAAA,CAAM,CAAC,GAAGI,KAAA,MAAW;MACrDC,KAAA,EAAO;IACT;EACF;EAEA;;;EAGA,MAAMC,SAAA,GAAY,MAAAA,CAAO;IAAEC,MAAM;IAAEC;EAAG,CAAyB;IAC7D,MAAMC,cAAA,GAAiBR,oBAAoB,CAACE,SAAA,CAAU;IACtD,MAAMO,YAAA,GAAeD,cAAA,IAA0BD,GAAA;IAE/C,IACEE,YAAA,EAAcL,KAAA,IACd,UAAUK,YAAA,CAAaL,KAAK,IAC5B,OAAOK,YAAA,CAAaL,KAAK,EAAEM,IAAA,KAAS,YACpC;MACA,OAAO,MAAMD,YAAA,CAAaL,KAAK;IACjC;IAEAK,YAAA,CAAaL,KAAK,GAAGE,MAAA;IAErB,OAAO,MAAMG,YAAA,CAAaL,KAAK;EACjC;EAEA,OAAO;IACLO,GAAA,EAAKN;EACP;AACF","ignoreList":[]}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Webpack / Turbopack loader that appends `export const instant = false` to the route modules
3
+ * rendering the Payload admin panel (`RootLayout` and `RootPage`).
4
+ *
5
+ * With Next.js `cacheComponents`, every route must either produce a static shell or opt out with
6
+ * `instant = false`. The admin panel reads cookies, headers and the database above any Suspense
7
+ * boundary, so it has to opt out. Next.js reads `instant` from the route module itself and rejects
8
+ * it when `cacheComponents` is disabled, which is why it cannot live in the generated admin files.
9
+ * Instead, `withPayload` registers this loader only when `cacheComponents` is enabled.
10
+ */
11
+ /**
12
+ * @param {string} source
13
+ * @returns {string}
14
+ */
15
+ export default function instantLoader(source: string): string;
16
+ //# sourceMappingURL=instantLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instantLoader.d.ts","sourceRoot":"","sources":["../../src/withPayload/instantLoader.js"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAaH;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,MAAM,EAHjC,MAGiC,GAF/B,MAAM,CAQlB"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Webpack / Turbopack loader that appends `export const instant = false` to the route modules
3
+ * rendering the Payload admin panel (`RootLayout` and `RootPage`).
4
+ *
5
+ * With Next.js `cacheComponents`, every route must either produce a static shell or opt out with
6
+ * `instant = false`. The admin panel reads cookies, headers and the database above any Suspense
7
+ * boundary, so it has to opt out. Next.js reads `instant` from the route module itself and rejects
8
+ * it when `cacheComponents` is disabled, which is why it cannot live in the generated admin files.
9
+ * Instead, `withPayload` registers this loader only when `cacheComponents` is enabled.
10
+ */ // Matches e.g. `import { RootLayout } from '@payloadcms/next/layouts'`, including aliased and
11
+ // multi-line imports. Matching the import instead of the JSX/call site avoids touching files that
12
+ // define their own `RootLayout` component.
13
+ const importsPayloadRootComponentRegex = /\bimport\s*\{[^}]*\bRoot(?:Layout|Page)\b[^}]*\}\s*from\s*['"]@payloadcms\/next\/(?:layouts|views)['"]/;
14
+ // Skip files that already declare `instant` (exported or not), so a user's own value wins and we
15
+ // never produce a duplicate declaration.
16
+ const declaresInstantRegex = /\b(?:const|let|var|function|class)\s+instant\b|\bexport\s*\{[^}]*\binstant\b[^}]*\}/;
17
+ /**
18
+ * @param {string} source
19
+ * @returns {string}
20
+ */
21
+ export default function instantLoader(source) {
22
+ if (!importsPayloadRootComponentRegex.test(source) || declaresInstantRegex.test(source)) {
23
+ return source;
24
+ }
25
+ return `${source}\nexport const instant = false\n`;
26
+ }
27
+ //# sourceMappingURL=instantLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instantLoader.js","names":["importsPayloadRootComponentRegex","declaresInstantRegex","instantLoader","source","test"],"sources":["../../src/withPayload/instantLoader.js"],"sourcesContent":["/**\n * Webpack / Turbopack loader that appends `export const instant = false` to the route modules\n * rendering the Payload admin panel (`RootLayout` and `RootPage`).\n *\n * With Next.js `cacheComponents`, every route must either produce a static shell or opt out with\n * `instant = false`. The admin panel reads cookies, headers and the database above any Suspense\n * boundary, so it has to opt out. Next.js reads `instant` from the route module itself and rejects\n * it when `cacheComponents` is disabled, which is why it cannot live in the generated admin files.\n * Instead, `withPayload` registers this loader only when `cacheComponents` is enabled.\n */\n\n// Matches e.g. `import { RootLayout } from '@payloadcms/next/layouts'`, including aliased and\n// multi-line imports. Matching the import instead of the JSX/call site avoids touching files that\n// define their own `RootLayout` component.\nconst importsPayloadRootComponentRegex =\n /\\bimport\\s*\\{[^}]*\\bRoot(?:Layout|Page)\\b[^}]*\\}\\s*from\\s*['\"]@payloadcms\\/next\\/(?:layouts|views)['\"]/\n\n// Skip files that already declare `instant` (exported or not), so a user's own value wins and we\n// never produce a duplicate declaration.\nconst declaresInstantRegex =\n /\\b(?:const|let|var|function|class)\\s+instant\\b|\\bexport\\s*\\{[^}]*\\binstant\\b[^}]*\\}/\n\n/**\n * @param {string} source\n * @returns {string}\n */\nexport default function instantLoader(source) {\n if (!importsPayloadRootComponentRegex.test(source) || declaresInstantRegex.test(source)) {\n return source\n }\n\n return `${source}\\nexport const instant = false\\n`\n}\n"],"mappings":"AAAA;;;;;;;;;GAAA,CAWA;AACA;AACA;AACA,MAAMA,gCAAA,GACJ;AAEF;AACA;AACA,MAAMC,oBAAA,GACJ;AAEF;;;;AAIA,eAAe,SAASC,cAAcC,MAAM;EAC1C,IAAI,CAACH,gCAAA,CAAiCI,IAAI,CAACD,MAAA,KAAWF,oBAAA,CAAqBG,IAAI,CAACD,MAAA,GAAS;IACvF,OAAOA,MAAA;EACT;EAEA,OAAO,GAAGA,MAAA,kCAAwC;AACpD","ignoreList":[]}
@@ -1,5 +1,16 @@
1
- export function withPayload(nextConfig?: import("next").NextConfig, options?: {
1
+ /**
2
+ * These files must remain as plain JavaScript (.js) rather than TypeScript (.ts) because they are
3
+ * imported directly in next.config.mjs files. Since next.config files run before the build process,
4
+ * TypeScript compilation is not available. This ensures compatibility with all templates and
5
+ * user projects regardless of their TypeScript setup.
6
+ */
7
+ /**
8
+ * @param {import('next').NextConfig} nextConfig
9
+ * @param {Object} [options] - Optional configuration options
10
+ * @param {boolean} [options.devBundleServerPackages] - Whether to bundle server packages in development mode. @default false
11
+ * */
12
+ export declare const withPayload: (nextConfig?: import('next').NextConfig, options?: {
2
13
  devBundleServerPackages?: boolean;
3
- }): import("next").NextConfig;
14
+ }) => import("next").NextConfig;
4
15
  export default withPayload;
5
16
  //# sourceMappingURL=withPayload.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"withPayload.d.ts","sourceRoot":"","sources":["../../src/withPayload/withPayload.js"],"names":[],"mappings":"AAiBO,yCAJI,OAAO,MAAM,EAAE,UAAU,YAEjC;IAA0B,uBAAuB,GAAzC,OAAO;CAA6F,6BA6P9G"}
1
+ {"version":3,"file":"withPayload.d.ts","sourceRoot":"","sources":["../../src/withPayload/withPayload.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH;;;;KAIK;AACL,eAAO,MAAM,WAAW,gBAJb,OAAO,MAAM,EAAE,UAAU,YAEjC;IAA0B,uBAAuB,AAAjD,CAA4G,EAApG,OAAO,CAA6F;CAAA,8BAoO9G,CAAA;eAEc,WAAW"}