@payloadcms/next 4.0.0-internal.a0ef1b8 → 4.0.0-internal.a2d053c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/dist/adapters/UnmountWhenHidden/index.d.ts +18 -0
- package/dist/adapters/UnmountWhenHidden/index.d.ts.map +1 -0
- package/dist/adapters/UnmountWhenHidden/index.js +64 -0
- package/dist/adapters/UnmountWhenHidden/index.js.map +1 -0
- package/dist/adapters/handleServerFunctions.d.ts.map +1 -1
- package/dist/adapters/handleServerFunctions.js +9 -2
- package/dist/adapters/handleServerFunctions.js.map +1 -1
- package/dist/adapters/layout.d.ts +2 -2
- package/dist/adapters/layout.d.ts.map +1 -1
- package/dist/adapters/layout.js +3 -3
- package/dist/adapters/layout.js.map +1 -1
- package/dist/adapters/metadata.d.ts.map +1 -1
- package/dist/adapters/metadata.js.map +1 -1
- package/dist/adapters/router.d.ts.map +1 -1
- package/dist/adapters/router.js +58 -20
- package/dist/adapters/router.js.map +1 -1
- package/dist/adapters/viewport.d.ts +4 -0
- package/dist/adapters/viewport.d.ts.map +1 -0
- package/dist/adapters/viewport.js +14 -0
- package/dist/adapters/viewport.js.map +1 -0
- package/dist/adapters/views.d.ts +3 -2
- package/dist/adapters/views.d.ts.map +1 -1
- package/dist/adapters/views.js +27 -17
- package/dist/adapters/views.js.map +1 -1
- package/dist/auth/login.d.ts +3 -18
- package/dist/auth/login.d.ts.map +1 -1
- package/dist/auth/login.js +6 -62
- package/dist/auth/login.js.map +1 -1
- package/dist/auth/logout.d.ts +2 -5
- package/dist/auth/logout.d.ts.map +1 -1
- package/dist/auth/logout.js +6 -47
- package/dist/auth/logout.js.map +1 -1
- package/dist/auth/refresh.d.ts +2 -4
- package/dist/auth/refresh.d.ts.map +1 -1
- package/dist/auth/refresh.js +6 -51
- package/dist/auth/refresh.js.map +1 -1
- package/dist/cjs/withPayload.cjs +96 -66
- package/dist/cjs/withPayload.cjs.map +4 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/exports/css.d.ts.map +1 -1
- package/dist/exports/layouts.d.ts +1 -0
- package/dist/exports/layouts.d.ts.map +1 -1
- package/dist/exports/layouts.js +1 -0
- package/dist/exports/layouts.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/prod/styles.css +1 -1
- package/dist/routes/graphql/handler.d.ts.map +1 -1
- package/dist/routes/graphql/handler.js +11 -6
- package/dist/routes/graphql/handler.js.map +1 -1
- package/dist/routes/graphql/playground.d.ts.map +1 -1
- package/dist/routes/graphql/playground.js +2 -2
- package/dist/routes/graphql/playground.js.map +1 -1
- package/dist/routes/rest/index.d.ts +8 -26
- package/dist/routes/rest/index.d.ts.map +1 -1
- package/dist/routes/rest/og/index.d.ts.map +1 -1
- package/dist/routes/rest/og/index.js.map +1 -1
- package/dist/utilities/getNextRequestI18n.d.ts.map +1 -1
- package/dist/utilities/initAdminContext.d.ts +8 -0
- package/dist/utilities/initAdminContext.d.ts.map +1 -0
- package/dist/utilities/initAdminContext.js +35 -0
- package/dist/utilities/initAdminContext.js.map +1 -0
- package/dist/utilities/selectiveCache.d.ts +18 -0
- package/dist/utilities/selectiveCache.d.ts.map +1 -0
- package/dist/utilities/selectiveCache.js +36 -0
- package/dist/utilities/selectiveCache.js.map +1 -0
- package/dist/withPayload/instantLoader.d.ts +16 -0
- package/dist/withPayload/instantLoader.d.ts.map +1 -0
- package/dist/withPayload/instantLoader.js +27 -0
- package/dist/withPayload/instantLoader.js.map +1 -0
- package/dist/withPayload/withPayload.d.ts +13 -2
- package/dist/withPayload/withPayload.d.ts.map +1 -1
- package/dist/withPayload/withPayload.js +51 -59
- package/dist/withPayload/withPayload.js.map +1 -1
- package/dist/withPayload/withPayload.utils.d.ts +34 -12
- package/dist/withPayload/withPayload.utils.d.ts.map +1 -1
- package/package.json +41 -42
- package/dist/@types/assets.d.js +0 -2
- package/dist/@types/assets.d.js.map +0 -1
- package/dist/utilities/getExistingAuthToken.d.ts +0 -7
- package/dist/utilities/getExistingAuthToken.d.ts.map +0 -1
- package/dist/utilities/getExistingAuthToken.js +0 -6
- package/dist/utilities/getExistingAuthToken.js.map +0 -1
- package/dist/utilities/setPayloadAuthCookie.d.ts +0 -9
- package/dist/utilities/setPayloadAuthCookie.d.ts.map +0 -1
- package/dist/utilities/setPayloadAuthCookie.js +0 -27
- package/dist/utilities/setPayloadAuthCookie.js.map +0 -1
- package/dist/withPayload/withPayload.spec.js +0 -40
- 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,
|
|
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,WAAkB,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,iBAyBlF,CAAA;AAED,eAAO,MAAM,IAAI,WACN,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,eAAqB,OAAO,sBA6D9E,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { configToSchema } from '@payloadcms/graphql';
|
|
2
2
|
import { createHandler } from 'graphql-http/lib/use/fetch';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { addDataAndFileToRequest, addLocalesToRequestFromData, 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,25 @@ 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
|
|
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
|
+
}
|
|
85
93
|
await addDataAndFileToRequest(req);
|
|
86
94
|
addLocalesToRequestFromData(req);
|
|
87
95
|
const {
|
|
88
96
|
schema,
|
|
89
97
|
validationRules
|
|
90
98
|
} = await getGraphql(config);
|
|
91
|
-
const {
|
|
92
|
-
payload
|
|
93
|
-
} = req;
|
|
94
99
|
const headers = {};
|
|
95
100
|
const apiResponse = await createHandler({
|
|
96
101
|
context: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","names":["configToSchema","createHandler","
|
|
1
|
+
{"version":3,"file":"handler.js","names":["configToSchema","createHandler","addDataAndFileToRequest","addLocalesToRequestFromData","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","validationRules","headers","apiResponse","onOperation","args","errors","all","map","_","defaultRules","concat","resHeaders","Headers","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 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 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,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;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AA,CAAYhD;EACtB;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"playground.d.ts","sourceRoot":"","sources":["../../../src/routes/graphql/playground.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
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 {
|
|
2
|
+
import { createPayloadRequestFromWebRequest } from 'payload';
|
|
3
3
|
import { formatAdminURL } from 'payload/shared';
|
|
4
4
|
export const GET = config => async request => {
|
|
5
|
-
const req = await
|
|
5
|
+
const req = await createPayloadRequestFromWebRequest({
|
|
6
6
|
config,
|
|
7
7
|
request
|
|
8
8
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"playground.js","names":["renderPlaygroundPage","
|
|
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
|
-
|
|
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;
|
|
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;AAO/D,QAAA,MAAM,cAAc,WACT,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,eAExC,OAAO,QACV;IACJ,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;CACrC,KACA,OAAO,CAAC,QAAQ,CAiClB,CAAA;AAEH,eAAO,MAAM,OAAO,uBAAiB,CAAA;AAErC,eAAO,MAAM,GAAG,uBAAiB,CAAA;AAEjC,eAAO,MAAM,IAAI,uBAAiB,CAAA;AAElC,eAAO,MAAM,MAAM,uBAAiB,CAAA;AAEpC,eAAO,MAAM,KAAK,uBAAiB,CAAA;AAEnC,eAAO,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,
|
|
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
|
|
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,OAAO,MAAMC,WAAA,GAAc;AAE3B,OAAO,MAAMC,eAAA,GAAkC,MAAOC,GAAA;EACpD,MAAMC,MAAA,GAASD,GAAA,CAAIE,OAAO,CAACD,MAAM;EAEjC,IAAIA,MAAA,CAAOE,KAAK,CAACT,IAAI,CAACU,kBAAkB,KAAK,OAAO;IAClD,OAAOC,QAAA,CAASC,IAAI,CAAC;MAAEC,KAAA,EAAO;IAAiC,GAAG;MAAEC,MAAA,EAAQ;IAAI;EAClF;EAEA,IAAI;IACF,MAAM;MAAEC;IAAY,CAAE,GAAG,IAAIC,GAAA,CAAIV,GAAA,CAAIL,GAAG;IAExC,MAAMgB,QAAA,GAAWF,YAAA,CAAaG,GAAG,CAAC;IAClC,MAAMC,KAAA,GAAQF,QAAA,GAAWF,YAAA,CAAaK,GAAG,CAAC,UAAUC,KAAA,CAAM,GAAG,OAAO;IACpE,MAAMC,SAAA,GAAYP,YAAA,CAAaG,GAAG,CAAC;IACnC,MAAMK,MAAA,GAASD,SAAA,GAAYP,YAAA,CAAaK,GAAG,CAAC,WAAWC,KAA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ACF","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,
|
|
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
|
-
|
|
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
|
-
})
|
|
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":"
|
|
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"}
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
* imported directly in next.config.mjs files. Since next.config files run before the build process,
|
|
4
4
|
* TypeScript compilation is not available. This ensures compatibility with all templates and
|
|
5
5
|
* user projects regardless of their TypeScript setup.
|
|
6
|
-
*/
|
|
6
|
+
*/import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { devServerExternalPackages as devServerExternalPayloadPackages, serverExternalPackages as serverExternalPayloadPackages } from 'payload/build-config';
|
|
8
|
+
const poweredByHeader = {
|
|
7
9
|
key: 'X-Powered-By',
|
|
8
10
|
value: 'Next.js, Payload'
|
|
9
11
|
};
|
|
@@ -13,7 +15,13 @@
|
|
|
13
15
|
* @param {boolean} [options.devBundleServerPackages] - Whether to bundle server packages in development mode. @default false
|
|
14
16
|
* */
|
|
15
17
|
export const withPayload = (nextConfig = {}, options = {}) => {
|
|
16
|
-
const env =
|
|
18
|
+
const env = {
|
|
19
|
+
...nextConfig.env
|
|
20
|
+
};
|
|
21
|
+
// Adds `export const instant = false` to the admin layout and page. See `instantLoader.js` for
|
|
22
|
+
// why this cannot live in the generated admin files.
|
|
23
|
+
const instantLoader = nextConfig.cacheComponents ? typeof import.meta?.resolve === 'function' ? fileURLToPath(new URL('./instantLoader.js', import.meta.url)) : require.resolve('@payloadcms/next/withPayload/instantLoader') : undefined;
|
|
24
|
+
const instantLoaderRule = '**/{layout,page}.{js,jsx,ts,tsx,mjs,mts,cjs,cts}';
|
|
17
25
|
if (nextConfig.experimental?.staleTimes?.dynamic) {
|
|
18
26
|
console.warn('Payload: detected a non-zero value for the `staleTimes.dynamic` option in your Next.js config. This will slow down page transitions and may cause stale data to load within the Admin panel. To clear this warning, remove the `staleTimes.dynamic` option from your Next.js config or set it to 0. In the future, Next.js may support scoping this option to specific routes.');
|
|
19
27
|
env.NEXT_PUBLIC_ENABLE_ROUTER_CACHE_REFRESH = 'true';
|
|
@@ -36,30 +44,24 @@ export const withPayload = (nextConfig = {}, options = {}) => {
|
|
|
36
44
|
/** @type {import('next').NextConfig} */
|
|
37
45
|
const baseConfig = {
|
|
38
46
|
...nextConfig,
|
|
47
|
+
devIndicators: nextConfig.devIndicators !== undefined ? nextConfig.devIndicators : false,
|
|
39
48
|
env,
|
|
40
49
|
experimental: {
|
|
41
|
-
...(nextConfig.experimental || {})
|
|
42
|
-
// Server fast refresh breaks HMR
|
|
43
|
-
turbopackServerFastRefresh: false
|
|
50
|
+
...(nextConfig.experimental || {})
|
|
44
51
|
},
|
|
45
52
|
sassOptions: {
|
|
46
53
|
...(nextConfig.sassOptions || {}),
|
|
47
54
|
/**
|
|
48
55
|
* This prevents scss warning spam during pnpm dev that looks like this:
|
|
49
|
-
* ⚠ ./
|
|
56
|
+
* ⚠ ./path/to/some/index.scss
|
|
50
57
|
* Issue while running loader
|
|
51
|
-
* SassWarning: Deprecation Warning
|
|
52
|
-
*
|
|
58
|
+
* SassWarning: Deprecation Warning: Sass @import rules are deprecated and
|
|
59
|
+
* will be removed in Dart Sass 3.0.0.
|
|
53
60
|
*
|
|
54
61
|
* More info and automated migrator: https://sass-lang.com/d/import
|
|
55
62
|
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* packages/ui/src/scss/styles.scss 9:9 @import
|
|
60
|
-
* test/admin/components/views/CustomMinimal/index.scss 1:9 root stylesheet
|
|
61
|
-
*
|
|
62
|
-
* @todo: update all outdated scss imports to use @use instead of @import. Then, we can remove this.
|
|
63
|
+
* This can be triggered by any `.scss` file in a consumer's project that
|
|
64
|
+
* still uses `@import`.
|
|
63
65
|
*/
|
|
64
66
|
silenceDeprecations: [...(nextConfig.sassOptions?.silenceDeprecations || []), 'import']
|
|
65
67
|
},
|
|
@@ -67,12 +69,25 @@ export const withPayload = (nextConfig = {}, options = {}) => {
|
|
|
67
69
|
...(nextConfig.outputFileTracingExcludes || {}),
|
|
68
70
|
'**/*': [...(nextConfig.outputFileTracingExcludes?.['**/*'] || []), 'drizzle-kit', 'drizzle-kit/api']
|
|
69
71
|
},
|
|
70
|
-
outputFileTracingIncludes: {
|
|
71
|
-
...(nextConfig.outputFileTracingIncludes || {}),
|
|
72
|
-
'**/*': [...(nextConfig.outputFileTracingIncludes?.['**/*'] || []), '@libsql/client']
|
|
73
|
-
},
|
|
74
72
|
turbopack: {
|
|
75
|
-
...(nextConfig.turbopack || {})
|
|
73
|
+
...(nextConfig.turbopack || {}),
|
|
74
|
+
...(instantLoader ? {
|
|
75
|
+
rules: {
|
|
76
|
+
...nextConfig.turbopack?.rules,
|
|
77
|
+
[instantLoaderRule]: [...[].concat(nextConfig.turbopack?.rules?.[instantLoaderRule] ?? []), {
|
|
78
|
+
// Only send files that import the admin root components to the loader, so
|
|
79
|
+
// Turbopack does not run a JavaScript loader for every other layout and page.
|
|
80
|
+
condition: {
|
|
81
|
+
all: [{
|
|
82
|
+
not: 'foreign'
|
|
83
|
+
}, {
|
|
84
|
+
content: /['"]@payloadcms\/next\/(?:layouts|views)['"]/
|
|
85
|
+
}]
|
|
86
|
+
},
|
|
87
|
+
loaders: [instantLoader]
|
|
88
|
+
}]
|
|
89
|
+
}
|
|
90
|
+
} : {})
|
|
76
91
|
},
|
|
77
92
|
// We disable the poweredByHeader here because we add it manually in the headers function below
|
|
78
93
|
...(nextConfig.poweredByHeader !== false ? {
|
|
@@ -94,53 +109,27 @@ export const withPayload = (nextConfig = {}, options = {}) => {
|
|
|
94
109
|
source: '/:path*'
|
|
95
110
|
}];
|
|
96
111
|
},
|
|
97
|
-
serverExternalPackages: [...(nextConfig.serverExternalPackages || []),
|
|
98
|
-
// WHY: without externalizing graphql, a graphql version error will be thrown
|
|
99
|
-
// during runtime ("Ensure that there is only one instance of \"graphql\" in the node_modules\ndirectory.")
|
|
100
|
-
'graphql', 'drizzle-kit', 'drizzle-kit/api', 'sharp', 'libsql', 'require-in-the-middle', 'json-schema-to-typescript',
|
|
101
|
-
// Prevents turbopack build errors by the thread-stream package which is installed by pino
|
|
102
|
-
'pino',
|
|
112
|
+
serverExternalPackages: [...new Set([...(nextConfig.serverExternalPackages || []), ...serverExternalPayloadPackages,
|
|
103
113
|
// file-type v22 uses `import(specifier)` with a non-literal specifier, which Turbopack rejects
|
|
104
114
|
// with "Cannot find module as expression is too dynamic"
|
|
105
|
-
'file-type', ...(process.env.NODE_ENV === 'development' && options.devBundleServerPackages !== true ?
|
|
106
|
-
/**
|
|
107
|
-
* Unless explicitly disabled by the user, by passing `devBundleServerPackages: true` to withPayload, we
|
|
108
|
-
* do not bundle server-only packages during dev for two reasons:
|
|
109
|
-
*
|
|
110
|
-
* 1. Performance: Fewer files to compile means faster compilation speeds.
|
|
111
|
-
* 2. Turbopack support: Webpack's externals are not supported by Turbopack.
|
|
112
|
-
*
|
|
113
|
-
* Regarding Turbopack support: Unlike webpack.externals, we cannot use serverExternalPackages to
|
|
114
|
-
* externalized packages that are not resolvable from the project root. So including a package like
|
|
115
|
-
* "drizzle-kit" in here would do nothing - Next.js will ignore the rule and still bundle the package -
|
|
116
|
-
* because it detects that the package is not resolvable from the project root (= not directly installed
|
|
117
|
-
* by the user in their own package.json).
|
|
118
|
-
*
|
|
119
|
-
* Instead, we can use serverExternalPackages for the entry-point packages that *are* installed directly
|
|
120
|
-
* by the user (e.g. db-postgres, which then installs drizzle-kit as a dependency).
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* We should only do this during development, not build, because externalizing these packages can hurt
|
|
125
|
-
* the bundle size. Not only does it disable tree-shaking, it also risks installing duplicate copies of the
|
|
126
|
-
* same package.
|
|
127
|
-
*
|
|
128
|
-
* Example:
|
|
129
|
-
* - @payloadcms/richtext-lexical (in bundle) -> installs qs-esm (bundled because of importer)
|
|
130
|
-
* - payload (not in bundle, external) -> installs qs-esm (external because of importer)
|
|
131
|
-
* Result: we have two copies of qs-esm installed - one in the bundle, and one in node_modules.
|
|
132
|
-
*
|
|
133
|
-
* During development, these bundle size difference do not matter much, and development speed /
|
|
134
|
-
* turbopack support are more important.
|
|
135
|
-
*/
|
|
136
|
-
['payload', '@payloadcms/db-mongodb', '@payloadcms/db-postgres', '@payloadcms/db-sqlite', '@payloadcms/db-vercel-postgres', '@payloadcms/db-d1-sqlite', '@payloadcms/drizzle', '@payloadcms/email-nodemailer', '@payloadcms/email-resend', '@payloadcms/graphql', '@payloadcms/payload-cloud', '@payloadcms/plugin-redirects'] : [])],
|
|
115
|
+
'file-type', ...(process.env.NODE_ENV === 'development' && options.devBundleServerPackages !== true ? devServerExternalPayloadPackages : [])])],
|
|
137
116
|
webpack: (webpackConfig, webpackOptions) => {
|
|
138
117
|
const incomingWebpackConfig = typeof nextConfig.webpack === 'function' ? nextConfig.webpack(webpackConfig, webpackOptions) : webpackConfig;
|
|
139
118
|
return {
|
|
140
119
|
...incomingWebpackConfig,
|
|
120
|
+
...(instantLoader ? {
|
|
121
|
+
module: {
|
|
122
|
+
...incomingWebpackConfig.module,
|
|
123
|
+
rules: [...(incomingWebpackConfig.module?.rules || []), {
|
|
124
|
+
enforce: 'pre',
|
|
125
|
+
exclude: /node_modules/,
|
|
126
|
+
test: /[/\\](layout|page)\.(?:[cm]?[jt]s|[jt]sx)$/,
|
|
127
|
+
use: [instantLoader]
|
|
128
|
+
}]
|
|
129
|
+
}
|
|
130
|
+
} : {}),
|
|
141
131
|
externals: [...(incomingWebpackConfig?.externals || []),
|
|
142
132
|
/**
|
|
143
|
-
* See the explanation in the serverExternalPackages section above.
|
|
144
133
|
* We need to force Webpack to emit require() calls for these packages, even though they are not
|
|
145
134
|
* resolvable from the project root. You would expect this to error during runtime, but Next.js seems to be able to require these just fine.
|
|
146
135
|
*
|
|
@@ -189,6 +178,9 @@ export const withPayload = (nextConfig = {}, options = {}) => {
|
|
|
189
178
|
process.env.NEXT_BASE_PATH = nextConfig.basePath;
|
|
190
179
|
baseConfig.env.NEXT_BASE_PATH = nextConfig.basePath;
|
|
191
180
|
}
|
|
181
|
+
const trailingSlash = nextConfig.trailingSlash === true ? 'true' : 'false';
|
|
182
|
+
process.env.NEXT_TRAILING_SLASH = trailingSlash;
|
|
183
|
+
baseConfig.env.NEXT_TRAILING_SLASH = trailingSlash;
|
|
192
184
|
return baseConfig;
|
|
193
185
|
};
|
|
194
186
|
export default withPayload;
|