@payloadcms/next 3.0.0-beta.15 → 3.0.0-beta.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exports/utilities.d.ts +2 -2
- package/dist/exports/utilities.d.ts.map +1 -1
- package/dist/exports/utilities.js +2 -2
- package/dist/exports/utilities.js.map +1 -1
- package/dist/prod/styles.css +1 -1
- package/dist/routes/graphql/handler.d.ts.map +1 -1
- package/dist/routes/graphql/handler.js +11 -7
- 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 +0 -4
- package/dist/routes/graphql/playground.js.map +1 -1
- package/dist/routes/rest/auth/registerFirstUser.d.ts.map +1 -1
- package/dist/routes/rest/auth/registerFirstUser.js +0 -9
- package/dist/routes/rest/auth/registerFirstUser.js.map +1 -1
- package/dist/routes/rest/buildFormState.d.ts +3 -3
- package/dist/routes/rest/buildFormState.d.ts.map +1 -1
- package/dist/routes/rest/buildFormState.js +21 -6
- package/dist/routes/rest/buildFormState.js.map +1 -1
- package/dist/routes/rest/files/checkFileAccess.d.ts +2 -2
- package/dist/routes/rest/files/checkFileAccess.d.ts.map +1 -1
- package/dist/routes/rest/files/checkFileAccess.js.map +1 -1
- package/dist/routes/rest/files/getFile.d.ts +2 -2
- package/dist/routes/rest/files/getFile.d.ts.map +1 -1
- package/dist/routes/rest/files/getFile.js.map +1 -1
- package/dist/routes/rest/index.d.ts.map +1 -1
- package/dist/routes/rest/index.js +217 -217
- package/dist/routes/rest/index.js.map +1 -1
- package/dist/routes/rest/routeError.d.ts +2 -2
- package/dist/routes/rest/routeError.d.ts.map +1 -1
- package/dist/routes/rest/routeError.js.map +1 -1
- package/dist/routes/rest/types.d.ts +7 -7
- package/dist/routes/rest/types.d.ts.map +1 -1
- package/dist/routes/rest/types.js.map +1 -1
- package/dist/utilities/addDataAndFileToRequest.d.ts +3 -2
- package/dist/utilities/addDataAndFileToRequest.d.ts.map +1 -1
- package/dist/utilities/addDataAndFileToRequest.js +10 -10
- package/dist/utilities/addDataAndFileToRequest.js.map +1 -1
- package/dist/utilities/addLocalesToRequest.d.ts +15 -5
- package/dist/utilities/addLocalesToRequest.d.ts.map +1 -1
- package/dist/utilities/addLocalesToRequest.js +24 -15
- package/dist/utilities/addLocalesToRequest.js.map +1 -1
- package/dist/utilities/buildFieldSchemaMap/index.d.ts +2 -2
- package/dist/utilities/buildFieldSchemaMap/index.d.ts.map +1 -1
- package/dist/utilities/buildFieldSchemaMap/index.js.map +1 -1
- package/dist/utilities/createPayloadRequest.d.ts.map +1 -1
- package/dist/utilities/createPayloadRequest.js +16 -6
- package/dist/utilities/createPayloadRequest.js.map +1 -1
- package/dist/utilities/getDataAndFile.d.ts +2 -2
- package/dist/utilities/getDataAndFile.d.ts.map +1 -1
- package/dist/utilities/getDataAndFile.js.map +1 -1
- package/dist/utilities/headersWithCors.d.ts +2 -2
- package/dist/utilities/headersWithCors.d.ts.map +1 -1
- package/dist/utilities/headersWithCors.js.map +1 -1
- package/dist/utilities/initPage.js.map +1 -1
- package/dist/views/CreateFirstUser/index.client.d.ts +3 -3
- package/dist/views/CreateFirstUser/index.client.d.ts.map +1 -1
- package/dist/views/CreateFirstUser/index.client.js +48 -6
- package/dist/views/CreateFirstUser/index.client.js.map +1 -1
- package/dist/views/CreateFirstUser/index.d.ts.map +1 -1
- package/dist/views/CreateFirstUser/index.js +9 -52
- package/dist/views/CreateFirstUser/index.js.map +1 -1
- package/dist/views/CreateFirstUser/index.scss +2 -12
- package/dist/views/Edit/Default/Auth/APIKey.d.ts +1 -0
- package/dist/views/Edit/Default/Auth/APIKey.d.ts.map +1 -1
- package/dist/views/Edit/Default/Auth/APIKey.js +10 -6
- package/dist/views/Edit/Default/Auth/APIKey.js.map +1 -1
- package/dist/views/Edit/Default/Auth/index.js +3 -3
- package/dist/views/Edit/Default/Auth/index.js.map +1 -1
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.js.map +1 -1
- package/dist/views/Login/LoginForm/index.js.map +1 -1
- package/dist/views/ResetPassword/index.js +1 -3
- package/dist/views/ResetPassword/index.js.map +1 -1
- package/package.json +7 -7
|
@@ -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,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/routes/graphql/handler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAqC,eAAe,EAAE,MAAM,eAAe,CAAA;AAsDvF,eAAO,MAAM,UAAU,WAAkB,QAAQ,eAAe,CAAC,GAAG,eAAe,iBA0BlF,CAAA;AAED,eAAO,MAAM,IAAI,WACN,QAAQ,eAAe,CAAC,GAAG,eAAe,eAAqB,OAAO,sBAyD9E,CAAA"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { configToSchema } from '@payloadcms/graphql';
|
|
2
2
|
import { createHandler } from 'graphql-http/lib/use/fetch';
|
|
3
3
|
import httpStatus from 'http-status';
|
|
4
|
-
import {
|
|
4
|
+
import { addDataAndFileToRequest } from '../../utilities/addDataAndFileToRequest.js';
|
|
5
|
+
import { addLocalesToRequestFromData } from '../../utilities/addLocalesToRequest.js';
|
|
5
6
|
import { createPayloadRequest } from '../../utilities/createPayloadRequest.js';
|
|
6
7
|
import { headersWithCors } from '../../utilities/headersWithCors.js';
|
|
7
8
|
const handleError = async (payload, err, debug, afterErrorHook)=>{
|
|
@@ -67,21 +68,24 @@ export const getGraphql = async (config)=>{
|
|
|
67
68
|
};
|
|
68
69
|
export const POST = (config)=>async (request)=>{
|
|
69
70
|
const originalRequest = request.clone();
|
|
70
|
-
const
|
|
71
|
+
const basePayloadRequest = await createPayloadRequest({
|
|
71
72
|
config,
|
|
72
73
|
request
|
|
73
74
|
});
|
|
74
|
-
|
|
75
|
-
request:
|
|
75
|
+
const reqWithData = await addDataAndFileToRequest({
|
|
76
|
+
request: basePayloadRequest
|
|
77
|
+
});
|
|
78
|
+
const payloadRequest = addLocalesToRequestFromData({
|
|
79
|
+
request: reqWithData
|
|
76
80
|
});
|
|
77
81
|
const { schema, validationRules } = await getGraphql(config);
|
|
78
|
-
const { payload } =
|
|
82
|
+
const { payload } = payloadRequest;
|
|
79
83
|
const afterErrorHook = typeof payload.config.hooks.afterError === 'function' ? payload.config.hooks.afterError : null;
|
|
80
84
|
const headers = {};
|
|
81
85
|
const apiResponse = await createHandler({
|
|
82
86
|
context: {
|
|
83
87
|
headers,
|
|
84
|
-
req
|
|
88
|
+
req: payloadRequest
|
|
85
89
|
},
|
|
86
90
|
onOperation: async (request, args, result)=>{
|
|
87
91
|
const response = typeof payload.extensions === 'function' ? await payload.extensions({
|
|
@@ -106,7 +110,7 @@ export const POST = (config)=>async (request)=>{
|
|
|
106
110
|
})(originalRequest);
|
|
107
111
|
const resHeaders = headersWithCors({
|
|
108
112
|
headers: new Headers(apiResponse.headers),
|
|
109
|
-
req
|
|
113
|
+
req: payloadRequest
|
|
110
114
|
});
|
|
111
115
|
for(const key in headers){
|
|
112
116
|
resHeaders.append(key, headers[key]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/routes/graphql/handler.ts"],"sourcesContent":["import type { GraphQLError, GraphQLFormattedError } from 'graphql'\nimport type { CollectionAfterErrorHook, Payload, SanitizedConfig } from 'payload/types'\n\nimport { configToSchema } from '@payloadcms/graphql'\nimport { createHandler } from 'graphql-http/lib/use/fetch'\nimport httpStatus from 'http-status'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/routes/graphql/handler.ts"],"sourcesContent":["import type { GraphQLError, GraphQLFormattedError } from 'graphql'\nimport type { CollectionAfterErrorHook, Payload, SanitizedConfig } from 'payload/types'\n\nimport { configToSchema } from '@payloadcms/graphql'\nimport { createHandler } from 'graphql-http/lib/use/fetch'\nimport httpStatus from 'http-status'\n\nimport { addDataAndFileToRequest } from '../../utilities/addDataAndFileToRequest.js'\nimport { addLocalesToRequestFromData } from '../../utilities/addLocalesToRequest.js'\nimport { createPayloadRequest } from '../../utilities/createPayloadRequest.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\n\nconst handleError = async (\n payload: Payload,\n err: any,\n debug: boolean,\n afterErrorHook: CollectionAfterErrorHook,\n // eslint-disable-next-line @typescript-eslint/require-await\n): Promise<GraphQLFormattedError> => {\n const status = err.originalError.status || httpStatus.INTERNAL_SERVER_ERROR\n let errorMessage = err.message\n payload.logger.error(err.stack)\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 (!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.data) || undefined,\n stack: debug ? err.stack : undefined,\n statusCode: status,\n },\n locations: err.locations,\n message: errorMessage,\n path: err.path,\n }\n\n if (afterErrorHook) {\n ;({ response } = afterErrorHook(err, response, null, null) || { response })\n }\n\n return response\n}\n\nlet cached = global._payload_graphql\n\nif (!cached) {\n // eslint-disable-next-line no-multi-assign\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 // eslint-disable-next-line no-async-promise-executor\n cached.promise = new Promise(async (resolve) => {\n const resolvedConfig = await config\n const schema = configToSchema(resolvedConfig)\n resolve(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 basePayloadRequest = await createPayloadRequest({\n config,\n request,\n })\n\n const reqWithData = await addDataAndFileToRequest({ request: basePayloadRequest })\n const payloadRequest = addLocalesToRequestFromData({ request: reqWithData })\n\n const { schema, validationRules } = await getGraphql(config)\n\n const { payload } = payloadRequest\n\n const afterErrorHook =\n typeof payload.config.hooks.afterError === 'function' ? payload.config.hooks.afterError : null\n\n const headers = {}\n const apiResponse = await createHandler({\n context: { headers, req: payloadRequest },\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(payload, error, payload.config.debug, afterErrorHook)\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: (request, args, defaultRules) => defaultRules.concat(validationRules(args)),\n })(originalRequest)\n\n const resHeaders = headersWithCors({\n headers: new Headers(apiResponse.headers),\n req: payloadRequest,\n })\n\n for (const key in headers) {\n resHeaders.append(key, headers[key])\n }\n\n return new Response(apiResponse.body, {\n headers: resHeaders,\n status: apiResponse.status,\n })\n }\n"],"names":["configToSchema","createHandler","httpStatus","addDataAndFileToRequest","addLocalesToRequestFromData","createPayloadRequest","headersWithCors","handleError","payload","err","debug","afterErrorHook","status","originalError","INTERNAL_SERVER_ERROR","errorMessage","message","logger","error","stack","response","extensions","name","undefined","data","statusCode","locations","path","cached","global","_payload_graphql","graphql","promise","getGraphql","config","process","env","NODE_ENV","Promise","resolve","resolvedConfig","schema","e","POST","request","originalRequest","clone","basePayloadRequest","reqWithData","payloadRequest","validationRules","hooks","afterError","headers","apiResponse","context","req","onOperation","args","result","errors","all","map","defaultRules","concat","resHeaders","Headers","key","append","Response","body"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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Qa,UAAU,KAAK,aAC1B,MAAMb,QAAQa,UAAU,CAAC;oBACvBqC;oBACAF,KAAKZ;oBACLe;gBACF,KACAA;gBACN,IAAIvC,SAASwC,MAAM,EAAE;oBACnB,MAAMA,SAAU,MAAMtB,QAAQuB,GAAG,CAC/BF,OAAOC,MAAM,CAACE,GAAG,CAAC,CAAC5C;wBACjB,OAAOX,YAAYC,SAASU,OAAOV,QAAQ0B,MAAM,CAACxB,KAAK,EAAEC;oBAC3D;oBAEF,yIAAyI;oBACzI,OAAO;wBAAE,GAAGS,QAAQ;wBAAEwC;oBAAO;gBAC/B;gBACA,OAAOxC;YACT;YACAqB;YACAS,iBAAiB,CAACN,SAASc,MAAMK,eAAiBA,aAAaC,MAAM,CAACd,gBAAgBQ;QACxF,GAAGb;QAEH,MAAMoB,aAAa3D,gBAAgB;YACjC+C,SAAS,IAAIa,QAAQZ,YAAYD,OAAO;YACxCG,KAAKP;QACP;QAEA,IAAK,MAAMkB,OAAOd,QAAS;YACzBY,WAAWG,MAAM,CAACD,KAAKd,OAAO,CAACc,IAAI;QACrC;QAEA,OAAO,IAAIE,SAASf,YAAYgB,IAAI,EAAE;YACpCjB,SAASY;YACTrD,QAAQ0C,YAAY1C,MAAM;QAC5B;IACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"playground.d.ts","sourceRoot":"","sources":["../../../src/routes/graphql/playground.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"playground.d.ts","sourceRoot":"","sources":["../../../src/routes/graphql/playground.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAMpD,eAAO,MAAM,GAAG,WAAY,QAAQ,eAAe,CAAC,eAAqB,OAAO,sBA6B/E,CAAA"}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { renderPlaygroundPage } from 'graphql-playground-html';
|
|
2
|
-
import { addLocalesToRequest } from '../../utilities/addLocalesToRequest.js';
|
|
3
2
|
import { createPayloadRequest } from '../../utilities/createPayloadRequest.js';
|
|
4
3
|
export const GET = (config)=>async (request)=>{
|
|
5
4
|
const req = await createPayloadRequest({
|
|
6
5
|
config,
|
|
7
6
|
request
|
|
8
7
|
});
|
|
9
|
-
addLocalesToRequest({
|
|
10
|
-
request: req
|
|
11
|
-
});
|
|
12
8
|
if (!req.payload.config.graphQL.disable && !req.payload.config.graphQL.disablePlaygroundInProduction && process.env.NODE_ENV === 'production' || process.env.NODE_ENV !== 'production') {
|
|
13
9
|
return new Response(renderPlaygroundPage({
|
|
14
10
|
endpoint: `${req.payload.config.routes.api}${req.payload.config.routes.graphQL}`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/routes/graphql/playground.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload/types'\n\nimport { renderPlaygroundPage } from 'graphql-playground-html'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/routes/graphql/playground.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload/types'\n\nimport { renderPlaygroundPage } from 'graphql-playground-html'\n\nimport { createPayloadRequest } from '../../utilities/createPayloadRequest.js'\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 return new Response(\n renderPlaygroundPage({\n endpoint: `${req.payload.config.routes.api}${req.payload.config.routes.graphQL}`,\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"],"names":["renderPlaygroundPage","createPayloadRequest","GET","config","request","req","payload","graphQL","disable","disablePlaygroundInProduction","process","env","NODE_ENV","Response","endpoint","routes","api","settings","headers","status"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,oBAAoB,QAAQ,0BAAyB;AAE9D,SAASC,oBAAoB,QAAQ,0CAAyC;AAE9E,OAAO,MAAMC,MAAM,CAACC,SAAqC,OAAOC;QAC9D,MAAMC,MAAM,MAAMJ,qBAAqB;YACrCE;YACAC;QACF;QAEA,IACE,AAAC,CAACC,IAAIC,OAAO,CAACH,MAAM,CAACI,OAAO,CAACC,OAAO,IAClC,CAACH,IAAIC,OAAO,CAACH,MAAM,CAACI,OAAO,CAACE,6BAA6B,IACzDC,QAAQC,GAAG,CAACC,QAAQ,KAAK,gBAC3BF,QAAQC,GAAG,CAACC,QAAQ,KAAK,cACzB;YACA,OAAO,IAAIC,SACTb,qBAAqB;gBACnBc,UAAU,CAAC,EAAET,IAAIC,OAAO,CAACH,MAAM,CAACY,MAAM,CAACC,GAAG,CAAC,EAAEX,IAAIC,OAAO,CAACH,MAAM,CAACY,MAAM,CAACR,OAAO,CAAC,CAAC;gBAChFU,UAAU;oBACR,uBAAuB;gBACzB;YACF,IACA;gBACEC,SAAS;oBACP,gBAAgB;gBAClB;gBACAC,QAAQ;YACV;QAEJ,OAAO;YACL,OAAO,IAAIN,SAAS,mBAAmB;gBAAEM,QAAQ;YAAI;QACvD;IACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerFirstUser.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/registerFirstUser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"registerFirstUser.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/registerFirstUser.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD,eAAO,MAAM,iBAAiB,EAAE,sBAoC/B,CAAA"}
|
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
import httpStatus from 'http-status';
|
|
2
2
|
import { generatePayloadCookie } from 'payload/auth';
|
|
3
|
-
import { ValidationError } from 'payload/errors';
|
|
4
3
|
import { registerFirstUserOperation } from 'payload/operations';
|
|
5
4
|
import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
6
5
|
export const registerFirstUser = async ({ collection, req })=>{
|
|
7
6
|
const { data, t } = req;
|
|
8
|
-
if (data?.password !== data['confirm-password']) {
|
|
9
|
-
throw new ValidationError([
|
|
10
|
-
{
|
|
11
|
-
field: 'confirm-password',
|
|
12
|
-
message: req.t('Password and confirm password fields do not match.')
|
|
13
|
-
}
|
|
14
|
-
]);
|
|
15
|
-
}
|
|
16
7
|
const result = await registerFirstUserOperation({
|
|
17
8
|
collection,
|
|
18
9
|
data: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/auth/registerFirstUser.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { generatePayloadCookie } from 'payload/auth'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/auth/registerFirstUser.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { generatePayloadCookie } from 'payload/auth'\nimport { registerFirstUserOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const registerFirstUser: CollectionRouteHandler = async ({ collection, req }) => {\n const { data, t } = req\n\n const result = await registerFirstUserOperation({\n collection,\n data: {\n ...data,\n email: typeof data?.email === 'string' ? data.email : '',\n password: typeof data?.password === 'string' ? data.password : '',\n },\n req,\n })\n\n const cookie = generatePayloadCookie({\n collectionConfig: collection.config,\n payload: req.payload,\n token: result.token,\n })\n\n return Response.json(\n {\n exp: result.exp,\n message: t('authentication:successfullyRegisteredFirstUser'),\n token: result.token,\n user: result.user,\n },\n {\n headers: headersWithCors({\n headers: new Headers({\n 'Set-Cookie': cookie,\n }),\n req,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","generatePayloadCookie","registerFirstUserOperation","headersWithCors","registerFirstUser","collection","req","data","t","result","email","password","cookie","collectionConfig","config","payload","token","Response","json","exp","message","user","headers","Headers","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,0BAA0B,QAAQ,qBAAoB;AAI/D,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,oBAA4C,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACjF,MAAM,EAAEC,IAAI,EAAEC,CAAC,EAAE,GAAGF;IAEpB,MAAMG,SAAS,MAAMP,2BAA2B;QAC9CG;QACAE,MAAM;YACJ,GAAGA,IAAI;YACPG,OAAO,OAAOH,MAAMG,UAAU,WAAWH,KAAKG,KAAK,GAAG;YACtDC,UAAU,OAAOJ,MAAMI,aAAa,WAAWJ,KAAKI,QAAQ,GAAG;QACjE;QACAL;IACF;IAEA,MAAMM,SAASX,sBAAsB;QACnCY,kBAAkBR,WAAWS,MAAM;QACnCC,SAAST,IAAIS,OAAO;QACpBC,OAAOP,OAAOO,KAAK;IACrB;IAEA,OAAOC,SAASC,IAAI,CAClB;QACEC,KAAKV,OAAOU,GAAG;QACfC,SAASZ,EAAE;QACXQ,OAAOP,OAAOO,KAAK;QACnBK,MAAMZ,OAAOY,IAAI;IACnB,GACA;QACEC,SAASnB,gBAAgB;YACvBmB,SAAS,IAAIC,QAAQ;gBACnB,cAAcX;YAChB;YACAN;QACF;QACAkB,QAAQxB,WAAWyB,EAAE;IACvB;AAEJ,EAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PayloadRequestWithData } from 'payload/types';
|
|
2
2
|
import type { FieldSchemaMap } from '../../utilities/buildFieldSchemaMap/types.js';
|
|
3
|
-
export declare const getFieldSchemaMap: (req:
|
|
3
|
+
export declare const getFieldSchemaMap: (req: PayloadRequestWithData) => FieldSchemaMap;
|
|
4
4
|
export declare const buildFormState: ({ req }: {
|
|
5
|
-
req:
|
|
5
|
+
req: PayloadRequestWithData;
|
|
6
6
|
}) => Promise<Response>;
|
|
7
7
|
//# sourceMappingURL=buildFormState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildFormState.d.ts","sourceRoot":"","sources":["../../../src/routes/rest/buildFormState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA8B,
|
|
1
|
+
{"version":3,"file":"buildFormState.d.ts","sourceRoot":"","sources":["../../../src/routes/rest/buildFormState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA8B,sBAAsB,EAAc,MAAM,eAAe,CAAA;AAMnG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAA;AAYlF,eAAO,MAAM,iBAAiB,QAAS,sBAAsB,mBAQ5D,CAAA;AAED,eAAO,MAAM,cAAc,YAAmB;IAAE,GAAG,EAAE,sBAAsB,CAAA;CAAE,sBAiN5E,CAAA"}
|
|
@@ -47,10 +47,19 @@ export const buildFormState = async ({ req })=>{
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
} else {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
const hasUsers = await req.payload.find({
|
|
51
|
+
collection: adminUserSlug,
|
|
52
|
+
depth: 0,
|
|
53
|
+
limit: 1,
|
|
54
|
+
pagination: false
|
|
53
55
|
});
|
|
56
|
+
// If there are users, we should not allow access because of /create-first-user
|
|
57
|
+
if (hasUsers.docs.length) {
|
|
58
|
+
return Response.json(null, {
|
|
59
|
+
headers,
|
|
60
|
+
status: httpStatus.UNAUTHORIZED
|
|
61
|
+
});
|
|
62
|
+
}
|
|
54
63
|
}
|
|
55
64
|
const fieldSchemaMap = getFieldSchemaMap(req);
|
|
56
65
|
const id = collectionSlug ? reqData.id : undefined;
|
|
@@ -154,9 +163,15 @@ export const buildFormState = async ({ req })=>{
|
|
|
154
163
|
},
|
|
155
164
|
req
|
|
156
165
|
});
|
|
157
|
-
// Maintain form state of
|
|
158
|
-
if (collectionSlug &&
|
|
159
|
-
|
|
166
|
+
// Maintain form state of auth / upload fields
|
|
167
|
+
if (collectionSlug && formState) {
|
|
168
|
+
if (req.payload.collections[collectionSlug]?.config?.upload && formState.file) {
|
|
169
|
+
result.file = formState.file;
|
|
170
|
+
}
|
|
171
|
+
if (req.payload.collections[collectionSlug]?.config?.auth && !req.payload.collections[collectionSlug].config.auth.disableLocalStrategy) {
|
|
172
|
+
if (formState.password) result.password = formState.password;
|
|
173
|
+
if (formState.email) result.email = formState.email;
|
|
174
|
+
}
|
|
160
175
|
}
|
|
161
176
|
return Response.json(result, {
|
|
162
177
|
headers,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/routes/rest/buildFormState.ts"],"sourcesContent":["import type { BuildFormStateArgs } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport type { DocumentPreferences, Field, PayloadRequest, TypeWithID } from 'payload/types'\n\nimport { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues'\nimport httpStatus from 'http-status'\n\nimport type { FieldSchemaMap } from '../../utilities/buildFieldSchemaMap/types.js'\n\nimport { buildFieldSchemaMap } from '../../utilities/buildFieldSchemaMap/index.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\n\nlet cached = global._payload_fieldSchemaMap\n\nif (!cached) {\n // eslint-disable-next-line no-multi-assign\n cached = global._payload_fieldSchemaMap = null\n}\n\nexport const getFieldSchemaMap = (req: PayloadRequest): FieldSchemaMap => {\n if (cached && process.env.NODE_ENV !== 'development') {\n return cached\n }\n\n cached = buildFieldSchemaMap(req)\n\n return cached\n}\n\nexport const buildFormState = async ({ req }: { req: PayloadRequest }) => {\n const headers = headersWithCors({\n headers: new Headers(),\n req,\n })\n\n try {\n const reqData: BuildFormStateArgs = req.data as BuildFormStateArgs\n const { collectionSlug, formState, globalSlug, locale, operation, schemaPath } = reqData\n\n const incomingUserSlug = req.user?.collection\n const adminUserSlug = req.payload.config.admin.user\n\n // If we have a user slug, test it against the functions\n if (incomingUserSlug) {\n const adminAccessFunction = req.payload.collections[incomingUserSlug].config.access?.admin\n\n // Run the admin access function from the config if it exists\n if (adminAccessFunction) {\n const canAccessAdmin = await adminAccessFunction({ req })\n\n if (!canAccessAdmin) {\n return Response.json(null, {\n headers,\n status: httpStatus.UNAUTHORIZED,\n })\n }\n // Match the user collection to the global admin config\n } else if (adminUserSlug !== incomingUserSlug) {\n return Response.json(null, {\n headers,\n status: httpStatus.UNAUTHORIZED,\n })\n }\n } else {\n return Response.json(null, {\n headers,\n status: httpStatus.UNAUTHORIZED,\n })\n }\n\n const fieldSchemaMap = getFieldSchemaMap(req)\n\n const id = collectionSlug ? reqData.id : undefined\n const schemaPathSegments = schemaPath.split('.')\n\n let fieldSchema: Field[]\n\n if (schemaPathSegments.length === 1) {\n if (req.payload.collections[schemaPath]) {\n fieldSchema = req.payload.collections[schemaPath].config.fields\n } else {\n fieldSchema = req.payload.config.globals.find(\n (global) => global.slug === schemaPath,\n )?.fields\n }\n } else if (fieldSchemaMap.has(schemaPath)) {\n fieldSchema = fieldSchemaMap.get(schemaPath)\n }\n\n if (!fieldSchema) {\n return Response.json(\n {\n message: 'Could not find field schema for given path',\n },\n {\n headers,\n status: httpStatus.BAD_REQUEST,\n },\n )\n }\n\n let docPreferences = reqData.docPreferences\n let data = reqData.data\n\n const promises: {\n data?: Promise<void>\n preferences?: Promise<void>\n } = {}\n\n // If the request does not include doc preferences,\n // we should fetch them. This is useful for DocumentInfoProvider\n // as it reduces the amount of client-side fetches necessary\n // when we fetch data for the Edit view\n if (!docPreferences) {\n let preferencesKey\n\n if (collectionSlug && id) {\n preferencesKey = `collection-${collectionSlug}-${id}`\n }\n\n if (globalSlug) {\n preferencesKey = `global-${globalSlug}`\n }\n\n if (preferencesKey) {\n const fetchPreferences = async () => {\n const preferencesResult = (await req.payload.find({\n collection: 'payload-preferences',\n depth: 0,\n limit: 1,\n where: {\n key: {\n equals: preferencesKey,\n },\n },\n })) as unknown as { docs: { value: DocumentPreferences }[] }\n\n if (preferencesResult?.docs?.[0]?.value) docPreferences = preferencesResult.docs[0].value\n }\n\n promises.preferences = fetchPreferences()\n }\n }\n\n // If there is a form state,\n // then we can deduce data from that form state\n if (formState) data = reduceFieldsToValues(formState, true)\n\n // If we do not have data at this point,\n // we can fetch it. This is useful for DocumentInfoProvider\n // to reduce the amount of fetches required\n if (!data) {\n const fetchData = async () => {\n let resolvedData: TypeWithID\n\n if (collectionSlug && id) {\n resolvedData = await req.payload.findByID({\n id,\n collection: collectionSlug,\n depth: 0,\n draft: true,\n fallbackLocale: null,\n locale,\n overrideAccess: false,\n user: req.user,\n })\n }\n\n if (globalSlug && schemaPath === globalSlug) {\n resolvedData = await req.payload.findGlobal({\n slug: globalSlug,\n depth: 0,\n draft: true,\n fallbackLocale: null,\n locale,\n overrideAccess: false,\n user: req.user,\n })\n }\n\n data = resolvedData\n }\n\n promises.data = fetchData()\n }\n\n if (Object.keys(promises).length > 0) {\n await Promise.all(Object.values(promises))\n }\n\n const result = await buildStateFromSchema({\n id,\n data,\n fieldSchema,\n operation,\n preferences: docPreferences || { fields: {} },\n req,\n })\n\n // Maintain form state of file\n if (\n collectionSlug &&\n req.payload.collections[collectionSlug]?.config?.upload &&\n formState &&\n formState.file\n ) {\n result.file = formState.file\n }\n\n return Response.json(result, {\n headers,\n status: httpStatus.OK,\n })\n } catch (err) {\n return Response.json(\n {\n message: 'There was an error building form state',\n },\n {\n headers,\n status: httpStatus.BAD_REQUEST,\n },\n )\n }\n}\n"],"names":["buildStateFromSchema","reduceFieldsToValues","httpStatus","buildFieldSchemaMap","headersWithCors","cached","global","_payload_fieldSchemaMap","getFieldSchemaMap","req","process","env","NODE_ENV","buildFormState","headers","Headers","reqData","data","collectionSlug","formState","globalSlug","locale","operation","schemaPath","incomingUserSlug","user","collection","adminUserSlug","payload","config","admin","adminAccessFunction","collections","access","canAccessAdmin","Response","json","status","UNAUTHORIZED","fieldSchemaMap","id","undefined","schemaPathSegments","split","fieldSchema","length","fields","globals","find","slug","has","get","message","BAD_REQUEST","docPreferences","promises","preferencesKey","fetchPreferences","preferencesResult","depth","limit","where","key","equals","docs","value","preferences","fetchData","resolvedData","findByID","draft","fallbackLocale","overrideAccess","findGlobal","Object","keys","Promise","all","values","result","upload","file","OK","err"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,oBAAoB,QAAQ,4CAA2C;AAChF,SAASC,oBAAoB,QAAQ,gDAA+C;AACpF,OAAOC,gBAAgB,cAAa;AAIpC,SAASC,mBAAmB,QAAQ,+CAA8C;AAClF,SAASC,eAAe,QAAQ,qCAAoC;AAEpE,IAAIC,SAASC,OAAOC,uBAAuB;AAE3C,IAAI,CAACF,QAAQ;IACX,2CAA2C;IAC3CA,SAASC,OAAOC,uBAAuB,GAAG;AAC5C;AAEA,OAAO,MAAMC,oBAAoB,CAACC;IAChC,IAAIJ,UAAUK,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;QACpD,OAAOP;IACT;IAEAA,SAASF,oBAAoBM;IAE7B,OAAOJ;AACT,EAAC;AAED,OAAO,MAAMQ,iBAAiB,OAAO,EAAEJ,GAAG,EAA2B;IACnE,MAAMK,UAAUV,gBAAgB;QAC9BU,SAAS,IAAIC;QACbN;IACF;IAEA,IAAI;QACF,MAAMO,UAA8BP,IAAIQ,IAAI;QAC5C,MAAM,EAAEC,cAAc,EAA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AAImB,OAAO,CAACyC,QAAQ,CAAC;wBACxC7B;wBACAd,YAAYR;wBACZyC,OAAO;wBACPW,OAAO;wBACPC,gBAAgB;wBAChBlD;wBACAmD,gBAAgB;wBAChB/C,MAAMhB,IAAIgB,IAAI;oBAChB;gBACF;gBAEA,IAAIL,cAAcG,eAAeH,YAAY;oBAC3CgD,eAAe,MAAM3D,IAAImB,OAAO,CAAC6C,UAAU,CAAC;wBAC1CxB,MAAM7B;wBACNuC,OAAO;wBACPW,OAAO;wBACPC,gBAAgB;wBAChBlD;wBACAmD,gBAAgB;wBAChB/C,MAAMhB,IAAIgB,IAAI;oBAChB;gBACF;gBAEAR,OAAOmD;YACT;YAEAb,SAAStC,IAAI,GAAGkD;QAClB;QAEA,IAAIO,OAAOC,IAAI,CAACpB,UAAUV,MAAM,GAAG,GAAG;YACpC,MAAM+B,QAAQC,GAAG,CAACH,OAAOI,MAAM,CAACvB;QAClC;QAEA,MAAMwB,SAAS,MAAM/E,qBAAqB;YACxCwC;YACAvB;YACA2B;YACAtB;YACA4C,aAAaZ,kBAAkB;gBAAER,QAAQ,CAAC;YAAE;YAC5CrC;QACF;QAEA,8BAA8B;QAC9B,IACES,kBACAT,IAAImB,OAAO,CAACI,WAAW,CAACd,eAAe,EAAEW,QAAQmD,UACjD7D,aACAA,UAAU8D,IAAI,EACd;YACAF,OAAOE,IAAI,GAAG9D,UAAU8D,IAAI;QAC9B;QAEA,OAAO9C,SAASC,IAAI,CAAC2C,QAAQ;YAC3BjE;YACAuB,QAAQnC,WAAWgF,EAAE;QACvB;IACF,EAAE,OAAOC,KAAK;QACZ,OAAOhD,SAASC,IAAI,CAClB;YACEgB,SAAS;QACX,GACA;YACEtC;YACAuB,QAAQnC,WAAWmD,WAAW;QAChC;IAEJ;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/routes/rest/buildFormState.ts"],"sourcesContent":["import type { BuildFormStateArgs } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport type { DocumentPreferences, Field, PayloadRequestWithData, TypeWithID } from 'payload/types'\n\nimport { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues'\nimport httpStatus from 'http-status'\n\nimport type { FieldSchemaMap } from '../../utilities/buildFieldSchemaMap/types.js'\n\nimport { buildFieldSchemaMap } from '../../utilities/buildFieldSchemaMap/index.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\n\nlet cached = global._payload_fieldSchemaMap\n\nif (!cached) {\n // eslint-disable-next-line no-multi-assign\n cached = global._payload_fieldSchemaMap = null\n}\n\nexport const getFieldSchemaMap = (req: PayloadRequestWithData): FieldSchemaMap => {\n if (cached && process.env.NODE_ENV !== 'development') {\n return cached\n }\n\n cached = buildFieldSchemaMap(req)\n\n return cached\n}\n\nexport const buildFormState = async ({ req }: { req: PayloadRequestWithData }) => {\n const headers = headersWithCors({\n headers: new Headers(),\n req,\n })\n\n try {\n const reqData: BuildFormStateArgs = req.data as BuildFormStateArgs\n const { collectionSlug, formState, globalSlug, locale, operation, schemaPath } = reqData\n\n const incomingUserSlug = req.user?.collection\n const adminUserSlug = req.payload.config.admin.user\n\n // If we have a user slug, test it against the functions\n if (incomingUserSlug) {\n const adminAccessFunction = req.payload.collections[incomingUserSlug].config.access?.admin\n\n // Run the admin access function from the config if it exists\n if (adminAccessFunction) {\n const canAccessAdmin = await adminAccessFunction({ req })\n\n if (!canAccessAdmin) {\n return Response.json(null, {\n headers,\n status: httpStatus.UNAUTHORIZED,\n })\n }\n // Match the user collection to the global admin config\n } else if (adminUserSlug !== incomingUserSlug) {\n return Response.json(null, {\n headers,\n status: httpStatus.UNAUTHORIZED,\n })\n }\n } else {\n const hasUsers = await req.payload.find({\n collection: adminUserSlug,\n depth: 0,\n limit: 1,\n pagination: false,\n })\n // If there are users, we should not allow access because of /create-first-user\n if (hasUsers.docs.length) {\n return Response.json(null, {\n headers,\n status: httpStatus.UNAUTHORIZED,\n })\n }\n }\n\n const fieldSchemaMap = getFieldSchemaMap(req)\n\n const id = collectionSlug ? reqData.id : undefined\n const schemaPathSegments = schemaPath.split('.')\n\n let fieldSchema: Field[]\n\n if (schemaPathSegments.length === 1) {\n if (req.payload.collections[schemaPath]) {\n fieldSchema = req.payload.collections[schemaPath].config.fields\n } else {\n fieldSchema = req.payload.config.globals.find(\n (global) => global.slug === schemaPath,\n )?.fields\n }\n } else if (fieldSchemaMap.has(schemaPath)) {\n fieldSchema = fieldSchemaMap.get(schemaPath)\n }\n\n if (!fieldSchema) {\n return Response.json(\n {\n message: 'Could not find field schema for given path',\n },\n {\n headers,\n status: httpStatus.BAD_REQUEST,\n },\n )\n }\n\n let docPreferences = reqData.docPreferences\n let data = reqData.data\n\n const promises: {\n data?: Promise<void>\n preferences?: Promise<void>\n } = {}\n\n // If the request does not include doc preferences,\n // we should fetch them. This is useful for DocumentInfoProvider\n // as it reduces the amount of client-side fetches necessary\n // when we fetch data for the Edit view\n if (!docPreferences) {\n let preferencesKey\n\n if (collectionSlug && id) {\n preferencesKey = `collection-${collectionSlug}-${id}`\n }\n\n if (globalSlug) {\n preferencesKey = `global-${globalSlug}`\n }\n\n if (preferencesKey) {\n const fetchPreferences = async () => {\n const preferencesResult = (await req.payload.find({\n collection: 'payload-preferences',\n depth: 0,\n limit: 1,\n where: {\n key: {\n equals: preferencesKey,\n },\n },\n })) as unknown as { docs: { value: DocumentPreferences }[] }\n\n if (preferencesResult?.docs?.[0]?.value) docPreferences = preferencesResult.docs[0].value\n }\n\n promises.preferences = fetchPreferences()\n }\n }\n\n // If there is a form state,\n // then we can deduce data from that form state\n if (formState) data = reduceFieldsToValues(formState, true)\n\n // If we do not have data at this point,\n // we can fetch it. This is useful for DocumentInfoProvider\n // to reduce the amount of fetches required\n if (!data) {\n const fetchData = async () => {\n let resolvedData: TypeWithID\n\n if (collectionSlug && id) {\n resolvedData = await req.payload.findByID({\n id,\n collection: collectionSlug,\n depth: 0,\n draft: true,\n fallbackLocale: null,\n locale,\n overrideAccess: false,\n user: req.user,\n })\n }\n\n if (globalSlug && schemaPath === globalSlug) {\n resolvedData = await req.payload.findGlobal({\n slug: globalSlug,\n depth: 0,\n draft: true,\n fallbackLocale: null,\n locale,\n overrideAccess: false,\n user: req.user,\n })\n }\n\n data = resolvedData\n }\n\n promises.data = fetchData()\n }\n\n if (Object.keys(promises).length > 0) {\n await Promise.all(Object.values(promises))\n }\n\n const result = await buildStateFromSchema({\n id,\n data,\n fieldSchema,\n operation,\n preferences: docPreferences || { fields: {} },\n req,\n })\n\n // Maintain form state of auth / upload fields\n if (collectionSlug && formState) {\n if (req.payload.collections[collectionSlug]?.config?.upload && formState.file) {\n result.file = formState.file\n }\n\n if (\n req.payload.collections[collectionSlug]?.config?.auth &&\n !req.payload.collections[collectionSlug].config.auth.disableLocalStrategy\n ) {\n if (formState.password) result.password = formState.password\n if (formState.email) result.email = formState.email\n }\n }\n\n return Response.json(result, {\n headers,\n status: httpStatus.OK,\n })\n } catch (err) {\n return Response.json(\n {\n message: 'There was an error building form state',\n },\n {\n headers,\n status: httpStatus.BAD_REQUEST,\n },\n )\n }\n}\n"],"names":["buildStateFromSchema","reduceFieldsToValues","httpStatus","buildFieldSchemaMap","headersWithCors","cached","global","_payload_fieldSchemaMap","getFieldSchemaMap","req","process","env","NODE_ENV","buildFormState","headers","Headers","reqData","data","collectionSlug","formState","globalSlug","locale","operation","schemaPath","incomingUserSlug","user","collection","adminUserSlug","payload","config","admin","adminAccessFunction","collections","access","canAccessAdmin","Response","json","status","UNAUTHORIZED","hasUsers","find","depth","limit","pagination","docs","length","fieldSchemaMap","id","undefined","schemaPathSegments","split","fieldSchema","fields","globals","slug","has","get","message","BAD_REQUEST","docPreferences","promises","preferencesKey","fetchPreferences","preferencesResult","where","key","equals","value","preferences","fetchData","resolvedData","findByID","draft","fallbackLocale","overrideAccess","findGlobal","Object","keys","Promise","all","values","result","upload","file","auth","disableLocalStrategy","password","email","OK","err"],"rangeMappings":";;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ACA;YACE3C;YACAuB,QAAQnC,WAAWwD,WAAW;QAChC;IAEJ;AACF,EAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Collection,
|
|
1
|
+
import type { Collection, PayloadRequestWithData } from 'payload/types';
|
|
2
2
|
export declare function checkFileAccess({ collection, filename, req, }: {
|
|
3
3
|
collection: Collection;
|
|
4
4
|
filename: string;
|
|
5
|
-
req:
|
|
5
|
+
req: PayloadRequestWithData;
|
|
6
6
|
}): Promise<Response>;
|
|
7
7
|
//# sourceMappingURL=checkFileAccess.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkFileAccess.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/files/checkFileAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"checkFileAccess.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/files/checkFileAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,sBAAsB,EAAS,MAAM,eAAe,CAAA;AAO9E,wBAAsB,eAAe,CAAC,EACpC,UAAU,EACV,QAAQ,EACR,GAAG,GACJ,EAAE;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,sBAAsB,CAAA;CAC5B,qBA2CA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/files/checkFileAccess.ts"],"sourcesContent":["import type { Collection,
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/files/checkFileAccess.ts"],"sourcesContent":["import type { Collection, PayloadRequestWithData, Where } from 'payload/types'\n\nimport { executeAccess } from 'payload/auth'\nimport { Forbidden } from 'payload/errors'\n\nimport { endpointsAreDisabled } from '../checkEndpoints.js'\n\nexport async function checkFileAccess({\n collection,\n filename,\n req,\n}: {\n collection: Collection\n filename: string\n req: PayloadRequestWithData\n}) {\n const { config } = collection\n const disableEndpoints = endpointsAreDisabled({ endpoints: config.endpoints, request: req })\n if (disableEndpoints) return disableEndpoints\n\n const accessResult = await executeAccess({ isReadingStaticFile: true, req }, config.access.read)\n\n if (typeof accessResult === 'object') {\n const queryToBuild: Where = {\n and: [\n {\n or: [\n {\n filename: {\n equals: filename,\n },\n },\n ],\n },\n accessResult,\n ],\n }\n\n if (config.upload.imageSizes) {\n config.upload.imageSizes.forEach(({ name }) => {\n queryToBuild.and[0].or.push({\n [`sizes.${name}.filename`]: {\n equals: filename,\n },\n })\n })\n }\n\n const doc = await req.payload.db.findOne({\n collection: config.slug,\n req,\n where: queryToBuild,\n })\n\n if (!doc) {\n throw new Forbidden(req.t)\n }\n }\n}\n"],"names":["executeAccess","Forbidden","endpointsAreDisabled","checkFileAccess","collection","filename","req","config","disableEndpoints","endpoints","request","accessResult","isReadingStaticFile","access","read","queryToBuild","and","or","equals","upload","imageSizes","forEach","name","push","doc","payload","db","findOne","slug","where","t"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,aAAa,QAAQ,eAAc;AAC5C,SAASC,SAAS,QAAQ,iBAAgB;AAE1C,SAASC,oBAAoB,QAAQ,uBAAsB;AAE3D,OAAO,eAAeC,gBAAgB,EACpCC,UAAU,EACVC,QAAQ,EACRC,GAAG,EAKJ;IACC,MAAM,EAAEC,MAAM,EAAE,GAAGH;IACnB,MAAMI,mBAAmBN,qBAAqB;QAAEO,WAAWF,OAAOE,SAAS;QAAEC,SAASJ;IAAI;IAC1F,IAAIE,kBAAkB,OAAOA;IAE7B,MAAMG,eAAe,MAAMX,cAAc;QAAEY,qBAAqB;QAAMN;IAAI,GAAGC,OAAOM,MAAM,CAACC,IAAI;IAE/F,IAAI,OAAOH,iBAAiB,UAAU;QACpC,MAAMI,eAAsB;YAC1BC,KAAK;gBACH;oBACEC,IAAI;wBACF;4BACEZ,UAAU;gCACRa,QAAQb;4BACV;wBACF;qBACD;gBACH;gBACAM;aACD;QACH;QAEA,IAAIJ,OAAOY,MAAM,CAACC,UAAU,EAAE;YAC5Bb,OAAOY,MAAM,CAACC,UAAU,CAACC,OAAO,CAAC,CAAC,EAAEC,IAAI,EAAE;gBACxCP,aAAaC,GAAG,CAAC,EAAE,CAACC,EAAE,CAACM,IAAI,CAAC;oBAC1B,CAAC,CAAC,MAAM,EAAED,KAAK,SAAS,CAAC,CAAC,EAAE;wBAC1BJ,QAAQb;oBACV;gBACF;YACF;QACF;QAEA,MAAMmB,MAAM,MAAMlB,IAAImB,OAAO,CAACC,EAAE,CAACC,OAAO,CAAC;YACvCvB,YAAYG,OAAOqB,IAAI;YACvBtB;YACAuB,OAAOd;QACT;QAEA,IAAI,CAACS,KAAK;YACR,MAAM,IAAIvB,UAAUK,IAAIwB,CAAC;QAC3B;IACF;AACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Collection,
|
|
1
|
+
import type { Collection, PayloadRequestWithData } from 'payload/types';
|
|
2
2
|
type Args = {
|
|
3
3
|
collection: Collection;
|
|
4
4
|
filename: string;
|
|
5
|
-
req:
|
|
5
|
+
req: PayloadRequestWithData;
|
|
6
6
|
};
|
|
7
7
|
export declare const getFile: ({ collection, filename, req }: Args) => Promise<Response>;
|
|
8
8
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFile.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/files/getFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"getFile.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/files/getFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAevE,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,UAAU,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,sBAAsB,CAAA;CAC5B,CAAA;AACD,eAAO,MAAM,OAAO,kCAAyC,IAAI,KAAG,QAAQ,QAAQ,CA0DnF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/files/getFile.ts"],"sourcesContent":["import type { Collection,
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/files/getFile.ts"],"sourcesContent":["import type { Collection, PayloadRequestWithData } from 'payload/types'\n\nimport getFileType from 'file-type'\nimport fsPromises from 'fs/promises'\nimport httpStatus from 'http-status'\nimport path from 'path'\nimport { APIError } from 'payload/errors'\n\nimport { streamFile } from '../../../next-stream-file/index.js'\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\nimport { routeError } from '../routeError.js'\nimport { checkFileAccess } from './checkFileAccess.js'\nimport { getFileTypeFallback } from './getFileTypeFallback.js'\n\n// /:collectionSlug/file/:filename\ntype Args = {\n collection: Collection\n filename: string\n req: PayloadRequestWithData\n}\nexport const getFile = async ({ collection, filename, req }: Args): Promise<Response> => {\n try {\n if (!collection.config.upload) {\n throw new APIError(\n `This collection is not an upload collection: ${collection.config.slug}`,\n httpStatus.BAD_REQUEST,\n )\n }\n\n await checkFileAccess({\n collection,\n filename,\n req,\n })\n\n let response: Response = null\n if (collection.config.upload.handlers?.length) {\n for (const handler of collection.config.upload.handlers) {\n response = await handler(req, {\n params: {\n collection: collection.config.slug,\n filename,\n },\n })\n }\n\n if (response instanceof Response) return response\n }\n\n const fileDir = collection.config.upload?.staticDir || collection.config.slug\n const filePath = path.resolve(`${fileDir}/${filename}`)\n\n const stats = await fsPromises.stat(filePath)\n\n const data = streamFile(filePath)\n\n const headers = new Headers({\n 'Content-Length': stats.size + '',\n })\n\n const fileTypeResult = (await getFileType.fromFile(filePath)) || getFileTypeFallback(filePath)\n headers.set('Content-Type', fileTypeResult.mime)\n\n return new Response(data, {\n headers: headersWithCors({\n headers,\n req,\n }),\n status: httpStatus.OK,\n })\n } catch (err) {\n return routeError({\n collection,\n config: req.payload.config,\n err,\n req,\n })\n }\n}\n"],"names":["getFileType","fsPromises","httpStatus","path","APIError","streamFile","headersWithCors","routeError","checkFileAccess","getFileTypeFallback","getFile","collection","filename","req","config","upload","slug","BAD_REQUEST","response","handlers","length","handler","params","Response","fileDir","staticDir","filePath","resolve","stats","stat","data","headers","Headers","size","fileTypeResult","fromFile","set","mime","status","OK","err","payload"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAOA,iBAAiB,YAAW;AACnC,OAAOC,gBAAgB,cAAa;AACpC,OAAOC,gBAAgB,cAAa;AACpC,OAAOC,UAAU,OAAM;AACvB,SAASC,QAAQ,QAAQ,iBAAgB;AAEzC,SAASC,UAAU,QAAQ,qCAAoC;AAC/D,SAASC,eAAe,QAAQ,wCAAuC;AACvE,SAASC,UAAU,QAAQ,mBAAkB;AAC7C,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,mBAAmB,QAAQ,2BAA0B;AAQ9D,OAAO,MAAMC,UAAU,OAAO,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,GAAG,EAAQ;IAC/D,IAAI;QACF,IAAI,CAACF,WAAWG,MAAM,CAACC,MAAM,EAAE;YAC7B,MAAM,IAAIX,SACR,CAAC,6CAA6C,EAAEO,WAAWG,MAAM,CAACE,IAAI,CAAC,CAAC,EACxEd,WAAWe,WAAW;QAE1B;QAEA,MAAMT,gBAAgB;YACpBG;YACAC;YACAC;QACF;QAEA,IAAIK,WAAqB;QACzB,IAAIP,WAAWG,MAAM,CAACC,MAAM,CAACI,QAAQ,EAAEC,QAAQ;YAC7C,KAAK,MAAMC,WAAWV,WAAWG,MAAM,CAACC,MAAM,CAACI,QAAQ,CAAE;gBACvDD,WAAW,MAAMG,QAAQR,KAAK;oBAC5BS,QAAQ;wBACNX,YAAYA,WAAWG,MAAM,CAACE,IAAI;wBAClCJ;oBACF;gBACF;YACF;YAEA,IAAIM,oBAAoBK,UAAU,OAAOL;QAC3C;QAEA,MAAMM,UAAUb,WAAWG,MAAM,CAACC,MAAM,EAAEU,aAAad,WAAWG,MAAM,CAACE,IAAI;QAC7E,MAAMU,WAAWvB,KAAKwB,OAAO,CAAC,CAAC,EAAEH,QAAQ,CAAC,EAAEZ,SAAS,CAAC;QAEtD,MAAMgB,QAAQ,MAAM3B,WAAW4B,IAAI,CAACH;QAEpC,MAAMI,OAAOzB,WAAWqB;QAExB,MAAMK,UAAU,IAAIC,QAAQ;YAC1B,kBAAkBJ,MAAMK,IAAI,GAAG;QACjC;QAEA,MAAMC,iBAAiB,AAAC,MAAMlC,YAAYmC,QAAQ,CAACT,aAAcjB,oBAAoBiB;QACrFK,QAAQK,GAAG,CAAC,gBAAgBF,eAAeG,IAAI;QAE/C,OAAO,IAAId,SAASO,MAAM;YACxBC,SAASzB,gBAAgB;gBACvByB;gBACAlB;YACF;YACAyB,QAAQpC,WAAWqC,EAAE;QACvB;IACF,EAAE,OAAOC,KAAK;QACZ,OAAOjC,WAAW;YAChBI;YACAG,QAAQD,IAAI4B,OAAO,CAAC3B,MAAM;YAC1B0B;YACA3B;QACF;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/routes/rest/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/routes/rest/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAKV,eAAe,EAChB,MAAM,eAAe,CAAA;AAsKtB,eAAO,MAAM,OAAO,WACT,QAAQ,eAAe,CAAC,GAAG,eAAe,eAAqB,OAAO,sBA0B9E,CAAA;AAEH,eAAO,MAAM,GAAG,WACL,QAAQ,eAAe,CAAC,GAAG,eAAe,eACnC,OAAO,wBAAwB;IAAE,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAA;CAAE,sBAgL5E,CAAA;AAEH,eAAO,MAAM,IAAI,WACN,QAAQ,eAAe,CAAC,GAAG,eAAe,eACnC,OAAO,wBAAwB;IAAE,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAA;CAAE,sBA8J5E,CAAA;AAEH,eAAO,MAAM,MAAM,WACR,QAAQ,eAAe,CAAC,GAAG,eAAe,eACnC,OAAO,wBAAwB;IAAE,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAA;CAAE,sBA8E5E,CAAA;AAEH,eAAO,MAAM,KAAK,WACP,QAAQ,eAAe,CAAC,GAAG,eAAe,eACnC,OAAO,wBAAwB;IAAE,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAA;CAAE,sBA+E5E,CAAA"}
|