@payloadcms/next 3.0.0-beta.56 → 3.0.0-beta.57
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/prod/index.js +2 -2
- package/dist/prod/styles.css +1 -1
- package/dist/routes/graphql/handler.js +8 -12
- package/dist/routes/graphql/handler.js.map +1 -1
- package/dist/routes/rest/auth/forgotPassword.d.ts.map +1 -1
- package/dist/routes/rest/auth/forgotPassword.js +7 -3
- package/dist/routes/rest/auth/forgotPassword.js.map +1 -1
- package/dist/routes/rest/auth/login.d.ts.map +1 -1
- package/dist/routes/rest/auth/login.js +9 -4
- package/dist/routes/rest/auth/login.js.map +1 -1
- package/dist/routes/rest/auth/registerFirstUser.d.ts.map +1 -1
- package/dist/routes/rest/auth/registerFirstUser.js +9 -2
- package/dist/routes/rest/auth/registerFirstUser.js.map +1 -1
- package/dist/routes/rest/auth/verifyEmail.js +1 -1
- package/dist/routes/rest/auth/verifyEmail.js.map +1 -1
- package/dist/routes/rest/buildFormState.d.ts +2 -2
- package/dist/routes/rest/buildFormState.d.ts.map +1 -1
- 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 +59 -91
- package/dist/routes/rest/index.js.map +1 -1
- package/dist/routes/rest/og/index.d.ts +2 -2
- package/dist/routes/rest/og/index.d.ts.map +1 -1
- package/dist/routes/rest/og/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 -6
- package/dist/utilities/addDataAndFileToRequest.d.ts.map +1 -1
- package/dist/utilities/addDataAndFileToRequest.js +15 -18
- package/dist/utilities/addDataAndFileToRequest.js.map +1 -1
- package/dist/utilities/addLocalesToRequest.d.ts +2 -5
- package/dist/utilities/addLocalesToRequest.d.ts.map +1 -1
- package/dist/utilities/addLocalesToRequest.js +8 -9
- package/dist/utilities/addLocalesToRequest.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/index.d.ts.map +1 -1
- package/dist/utilities/initPage/index.js.map +1 -1
- package/dist/views/Document/getDocumentData.d.ts +2 -2
- package/dist/views/Document/getDocumentData.d.ts.map +1 -1
- package/dist/views/Document/getDocumentData.js.map +1 -1
- package/dist/views/Edit/Default/Auth/APIKey.js.map +1 -1
- package/dist/views/Edit/Default/Auth/index.d.ts.map +1 -1
- package/dist/views/Edit/Default/Auth/index.js +10 -3
- package/dist/views/Edit/Default/Auth/index.js.map +1 -1
- package/dist/views/Edit/Default/Auth/types.d.ts +1 -0
- package/dist/views/Edit/Default/Auth/types.d.ts.map +1 -1
- package/dist/views/Edit/Default/Auth/types.js.map +1 -1
- package/dist/views/Edit/Default/index.d.ts.map +1 -1
- package/dist/views/Edit/Default/index.js +1 -0
- package/dist/views/Edit/Default/index.js.map +1 -1
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.d.ts.map +1 -1
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.js +34 -6
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.js.map +1 -1
- package/dist/views/Login/LoginForm/index.d.ts.map +1 -1
- package/dist/views/Login/LoginForm/index.js +38 -8
- package/dist/views/Login/LoginForm/index.js.map +1 -1
- package/package.json +7 -7
|
@@ -68,24 +68,20 @@ export const getGraphql = async (config)=>{
|
|
|
68
68
|
};
|
|
69
69
|
export const POST = (config)=>async (request)=>{
|
|
70
70
|
const originalRequest = request.clone();
|
|
71
|
-
const
|
|
71
|
+
const req = await createPayloadRequest({
|
|
72
72
|
config,
|
|
73
73
|
request
|
|
74
74
|
});
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
});
|
|
78
|
-
const payloadRequest = addLocalesToRequestFromData({
|
|
79
|
-
request: reqWithData
|
|
80
|
-
});
|
|
75
|
+
await addDataAndFileToRequest(req);
|
|
76
|
+
addLocalesToRequestFromData(req);
|
|
81
77
|
const { schema, validationRules } = await getGraphql(config);
|
|
82
|
-
const { payload } =
|
|
78
|
+
const { payload } = req;
|
|
83
79
|
const afterErrorHook = typeof payload.config.hooks.afterError === 'function' ? payload.config.hooks.afterError : null;
|
|
84
80
|
const headers = {};
|
|
85
81
|
const apiResponse = await createHandler({
|
|
86
82
|
context: {
|
|
87
83
|
headers,
|
|
88
|
-
req
|
|
84
|
+
req
|
|
89
85
|
},
|
|
90
86
|
onOperation: async (request, args, result)=>{
|
|
91
87
|
const response = typeof payload.extensions === 'function' ? await payload.extensions({
|
|
@@ -110,13 +106,13 @@ export const POST = (config)=>async (request)=>{
|
|
|
110
106
|
})(originalRequest);
|
|
111
107
|
const resHeaders = headersWithCors({
|
|
112
108
|
headers: new Headers(apiResponse.headers),
|
|
113
|
-
req
|
|
109
|
+
req
|
|
114
110
|
});
|
|
115
111
|
for(const key in headers){
|
|
116
112
|
resHeaders.append(key, headers[key]);
|
|
117
113
|
}
|
|
118
|
-
if (
|
|
119
|
-
mergeHeaders(
|
|
114
|
+
if (req.responseHeaders) {
|
|
115
|
+
mergeHeaders(req.responseHeaders, resHeaders);
|
|
120
116
|
}
|
|
121
117
|
return new Response(apiResponse.body, {
|
|
122
118
|
headers: resHeaders,
|
|
@@ -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'\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'\nimport { mergeHeaders } from '../../utilities/mergeHeaders.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 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
|
|
1
|
+
{"version":3,"sources":["../../../src/routes/graphql/handler.ts"],"sourcesContent":["import type { GraphQLError, GraphQLFormattedError } from 'graphql'\nimport type { CollectionAfterErrorHook, Payload, SanitizedConfig } from 'payload'\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'\nimport { mergeHeaders } from '../../utilities/mergeHeaders.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 const resolvedConfig = await config\n cached.promise = new Promise((resolve) => {\n const schema = configToSchema(resolvedConfig)\n resolve(cached.graphql || schema)\n })\n }\n\n try {\n cached.graphql = await cached.promise\n } catch (e) {\n cached.promise = null\n throw e\n }\n\n return cached.graphql\n}\n\nexport const POST =\n (config: Promise<SanitizedConfig> | SanitizedConfig) => async (request: Request) => {\n const originalRequest = request.clone()\n const req = await createPayloadRequest({\n config,\n request,\n })\n\n await addDataAndFileToRequest(req)\n addLocalesToRequestFromData(req)\n\n const { schema, validationRules } = await getGraphql(config)\n\n const { payload } = req\n\n const 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 },\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: (_, 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 if (req.responseHeaders) {\n mergeHeaders(req.responseHeaders, resHeaders)\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","mergeHeaders","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","resolvedConfig","Promise","resolve","schema","e","POST","request","originalRequest","clone","req","validationRules","hooks","afterError","headers","apiResponse","context","onOperation","args","result","errors","all","map","_","defaultRules","concat","resHeaders","Headers","key","append","responseHeaders","Response","body"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forgotPassword.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/forgotPassword.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD,eAAO,MAAM,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"forgotPassword.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/forgotPassword.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD,eAAO,MAAM,cAAc,EAAE,sBA+B5B,CAAA"}
|
|
@@ -3,11 +3,15 @@ import { forgotPasswordOperation } from 'payload';
|
|
|
3
3
|
import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
4
4
|
export const forgotPassword = async ({ collection, req })=>{
|
|
5
5
|
const { t } = req;
|
|
6
|
+
const authData = collection.config.auth?.loginWithUsername ? {
|
|
7
|
+
email: typeof req.data?.email === 'string' ? req.data.email : '',
|
|
8
|
+
username: typeof req.data?.username === 'string' ? req.data.username : ''
|
|
9
|
+
} : {
|
|
10
|
+
email: typeof req.data?.email === 'string' ? req.data.email : ''
|
|
11
|
+
};
|
|
6
12
|
await forgotPasswordOperation({
|
|
7
13
|
collection,
|
|
8
|
-
data:
|
|
9
|
-
email: req.data.email
|
|
10
|
-
},
|
|
14
|
+
data: authData,
|
|
11
15
|
disableEmail: Boolean(req.data?.disableEmail),
|
|
12
16
|
expiration: typeof req.data.expiration === 'number' ? req.data.expiration : undefined,
|
|
13
17
|
req
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/auth/forgotPassword.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { forgotPasswordOperation } from 'payload'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const forgotPassword: CollectionRouteHandler = async ({ collection, req }) => {\n const { t } = req\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/auth/forgotPassword.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { forgotPasswordOperation } from 'payload'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const forgotPassword: CollectionRouteHandler = async ({ collection, req }) => {\n const { t } = req\n const authData = collection.config.auth?.loginWithUsername\n ? {\n email: typeof req.data?.email === 'string' ? req.data.email : '',\n username: typeof req.data?.username === 'string' ? req.data.username : '',\n }\n : {\n email: typeof req.data?.email === 'string' ? req.data.email : '',\n }\n\n await forgotPasswordOperation({\n collection,\n data: authData,\n disableEmail: Boolean(req.data?.disableEmail),\n expiration: typeof req.data.expiration === 'number' ? req.data.expiration : undefined,\n req,\n })\n\n return Response.json(\n {\n message: t('general:success'),\n },\n {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","forgotPasswordOperation","headersWithCors","forgotPassword","collection","req","t","authData","config","auth","loginWithUsername","email","data","username","disableEmail","Boolean","expiration","undefined","Response","json","message","headers","Headers","status","OK"],"mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,iBAAyC,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IAC9E,MAAM,EAAEC,CAAC,EAAE,GAAGD;IACd,MAAME,WAAWH,WAAWI,MAAM,CAACC,IAAI,EAAEC,oBACrC;QACEC,OAAO,OAAON,IAAIO,IAAI,EAAED,UAAU,WAAWN,IAAIO,IAAI,CAACD,KAAK,GAAG;QAC9DE,UAAU,OAAOR,IAAIO,IAAI,EAAEC,aAAa,WAAWR,IAAIO,IAAI,CAACC,QAAQ,GAAG;IACzE,IACA;QACEF,OAAO,OAAON,IAAIO,IAAI,EAAED,UAAU,WAAWN,IAAIO,IAAI,CAACD,KAAK,GAAG;IAChE;IAEJ,MAAMV,wBAAwB;QAC5BG;QACAQ,MAAML;QACNO,cAAcC,QAAQV,IAAIO,IAAI,EAAEE;QAChCE,YAAY,OAAOX,IAAIO,IAAI,CAACI,UAAU,KAAK,WAAWX,IAAIO,IAAI,CAACI,UAAU,GAAGC;QAC5EZ;IACF;IAEA,OAAOa,SAASC,IAAI,CAClB;QACEC,SAASd,EAAE;IACb,GACA;QACEe,SAASnB,gBAAgB;YACvBmB,SAAS,IAAIC;YACbjB;QACF;QACAkB,QAAQvB,WAAWwB,EAAE;IACvB;AAEJ,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/login.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD,eAAO,MAAM,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/login.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD,eAAO,MAAM,KAAK,EAAE,sBA8CnB,CAAA"}
|
|
@@ -5,12 +5,17 @@ import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
|
5
5
|
export const login = async ({ collection, req })=>{
|
|
6
6
|
const { searchParams, t } = req;
|
|
7
7
|
const depth = searchParams.get('depth');
|
|
8
|
+
const authData = collection.config.auth?.loginWithUsername ? {
|
|
9
|
+
email: typeof req.data?.email === 'string' ? req.data.email : '',
|
|
10
|
+
password: typeof req.data?.password === 'string' ? req.data.password : '',
|
|
11
|
+
username: typeof req.data?.username === 'string' ? req.data.username : ''
|
|
12
|
+
} : {
|
|
13
|
+
email: typeof req.data?.email === 'string' ? req.data.email : '',
|
|
14
|
+
password: typeof req.data?.password === 'string' ? req.data.password : ''
|
|
15
|
+
};
|
|
8
16
|
const result = await loginOperation({
|
|
9
17
|
collection,
|
|
10
|
-
data:
|
|
11
|
-
email: typeof req.data?.email === 'string' ? req.data.email : '',
|
|
12
|
-
password: typeof req.data?.password === 'string' ? req.data.password : ''
|
|
13
|
-
},
|
|
18
|
+
data: authData,
|
|
14
19
|
depth: isNumber(depth) ? Number(depth) : undefined,
|
|
15
20
|
req
|
|
16
21
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/auth/login.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { generatePayloadCookie, loginOperation } from 'payload'\nimport { isNumber } from 'payload/shared'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const login: CollectionRouteHandler = async ({ collection, req }) => {\n const { searchParams, t } = req\n const depth = searchParams.get('depth')\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/auth/login.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { generatePayloadCookie, loginOperation } from 'payload'\nimport { isNumber } from 'payload/shared'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const login: CollectionRouteHandler = async ({ collection, req }) => {\n const { searchParams, t } = req\n const depth = searchParams.get('depth')\n const authData = collection.config.auth?.loginWithUsername\n ? {\n email: typeof req.data?.email === 'string' ? req.data.email : '',\n password: typeof req.data?.password === 'string' ? req.data.password : '',\n username: typeof req.data?.username === 'string' ? req.data.username : '',\n }\n : {\n email: typeof req.data?.email === 'string' ? req.data.email : '',\n password: typeof req.data?.password === 'string' ? req.data.password : '',\n }\n\n const result = await loginOperation({\n collection,\n data: authData,\n depth: isNumber(depth) ? Number(depth) : undefined,\n req,\n })\n\n const cookie = generatePayloadCookie({\n collectionConfig: collection.config,\n payload: req.payload,\n token: result.token,\n })\n\n if (collection.config.auth.removeTokenFromResponses) {\n delete result.token\n }\n\n return Response.json(\n {\n message: t('authentication:passed'),\n ...result,\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","loginOperation","isNumber","headersWithCors","login","collection","req","searchParams","t","depth","get","authData","config","auth","loginWithUsername","email","data","password","username","result","Number","undefined","cookie","collectionConfig","payload","token","removeTokenFromResponses","Response","json","message","headers","Headers","status","OK"],"mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,qBAAqB,EAAEC,cAAc,QAAQ,UAAS;AAC/D,SAASC,QAAQ,QAAQ,iBAAgB;AAIzC,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,QAAgC,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACrE,MAAM,EAAEC,YAAY,EAAEC,CAAC,EAAE,GAAGF;IAC5B,MAAMG,QAAQF,aAAaG,GAAG,CAAC;IAC/B,MAAMC,WAAWN,WAAWO,MAAM,CAACC,IAAI,EAAEC,oBACrC;QACEC,OAAO,OAAOT,IAAIU,IAAI,EAAED,UAAU,WAAWT,IAAIU,IAAI,CAACD,KAAK,GAAG;QAC9DE,UAAU,OAAOX,IAAIU,IAAI,EAAEC,aAAa,WAAWX,IAAIU,IAAI,CAACC,QAAQ,GAAG;QACvEC,UAAU,OAAOZ,IAAIU,IAAI,EAAEE,aAAa,WAAWZ,IAAIU,IAAI,CAACE,QAAQ,GAAG;IACzE,IACA;QACEH,OAAO,OAAOT,IAAIU,IAAI,EAAED,UAAU,WAAWT,IAAIU,IAAI,CAACD,KAAK,GAAG;QAC9DE,UAAU,OAAOX,IAAIU,IAAI,EAAEC,aAAa,WAAWX,IAAIU,IAAI,CAACC,QAAQ,GAAG;IACzE;IAEJ,MAAME,SAAS,MAAMlB,eAAe;QAClCI;QACAW,MAAML;QACNF,OAAOP,SAASO,SAASW,OAAOX,SAASY;QACzCf;IACF;IAEA,MAAMgB,SAAStB,sBAAsB;QACnCuB,kBAAkBlB,WAAWO,MAAM;QACnCY,SAASlB,IAAIkB,OAAO;QACpBC,OAAON,OAAOM,KAAK;IACrB;IAEA,IAAIpB,WAAWO,MAAM,CAACC,IAAI,CAACa,wBAAwB,EAAE;QACnD,OAAOP,OAAOM,KAAK;IACrB;IAEA,OAAOE,SAASC,IAAI,CAClB;QACEC,SAASrB,EAAE;QACX,GAAGW,MAAM;IACX,GACA;QACEW,SAAS3B,gBAAgB;YACvB2B,SAAS,IAAIC,QAAQ;gBACnB,cAAcT;YAChB;YACAhB;QACF;QACA0B,QAAQjC,WAAWkC,EAAE;IACvB;AAEJ,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerFirstUser.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/registerFirstUser.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD,eAAO,MAAM,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"registerFirstUser.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/registerFirstUser.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD,eAAO,MAAM,iBAAiB,EAAE,sBA6C/B,CAAA"}
|
|
@@ -3,12 +3,19 @@ import { generatePayloadCookie, registerFirstUserOperation } from 'payload';
|
|
|
3
3
|
import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
4
4
|
export const registerFirstUser = async ({ collection, req })=>{
|
|
5
5
|
const { data, t } = req;
|
|
6
|
+
const authData = collection.config.auth?.loginWithUsername ? {
|
|
7
|
+
email: typeof req.data?.email === 'string' ? req.data.email : '',
|
|
8
|
+
password: typeof req.data?.password === 'string' ? req.data.password : '',
|
|
9
|
+
username: typeof req.data?.username === 'string' ? req.data.username : ''
|
|
10
|
+
} : {
|
|
11
|
+
email: typeof req.data?.email === 'string' ? req.data.email : '',
|
|
12
|
+
password: typeof req.data?.password === 'string' ? req.data.password : ''
|
|
13
|
+
};
|
|
6
14
|
const result = await registerFirstUserOperation({
|
|
7
15
|
collection,
|
|
8
16
|
data: {
|
|
9
17
|
...data,
|
|
10
|
-
|
|
11
|
-
password: typeof data?.password === 'string' ? data.password : ''
|
|
18
|
+
...authData
|
|
12
19
|
},
|
|
13
20
|
req
|
|
14
21
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/auth/registerFirstUser.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { generatePayloadCookie, registerFirstUserOperation } from 'payload'\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
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/auth/registerFirstUser.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { generatePayloadCookie, registerFirstUserOperation } from 'payload'\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 const authData = collection.config.auth?.loginWithUsername\n ? {\n email: typeof req.data?.email === 'string' ? req.data.email : '',\n password: typeof req.data?.password === 'string' ? req.data.password : '',\n username: typeof req.data?.username === 'string' ? req.data.username : '',\n }\n : {\n email: typeof req.data?.email === 'string' ? req.data.email : '',\n password: typeof req.data?.password === 'string' ? req.data.password : '',\n }\n\n const result = await registerFirstUserOperation({\n collection,\n data: {\n ...data,\n ...authData,\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","authData","config","auth","loginWithUsername","email","password","username","result","cookie","collectionConfig","payload","token","Response","json","exp","message","user","headers","Headers","status","OK"],"mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,qBAAqB,EAAEC,0BAA0B,QAAQ,UAAS;AAI3E,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,oBAA4C,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACjF,MAAM,EAAEC,IAAI,EAAEC,CAAC,EAAE,GAAGF;IACpB,MAAMG,WAAWJ,WAAWK,MAAM,CAACC,IAAI,EAAEC,oBACrC;QACEC,OAAO,OAAOP,IAAIC,IAAI,EAAEM,UAAU,WAAWP,IAAIC,IAAI,CAACM,KAAK,GAAG;QAC9DC,UAAU,OAAOR,IAAIC,IAAI,EAAEO,aAAa,WAAWR,IAAIC,IAAI,CAACO,QAAQ,GAAG;QACvEC,UAAU,OAAOT,IAAIC,IAAI,EAAEQ,aAAa,WAAWT,IAAIC,IAAI,CAACQ,QAAQ,GAAG;IACzE,IACA;QACEF,OAAO,OAAOP,IAAIC,IAAI,EAAEM,UAAU,WAAWP,IAAIC,IAAI,CAACM,KAAK,GAAG;QAC9DC,UAAU,OAAOR,IAAIC,IAAI,EAAEO,aAAa,WAAWR,IAAIC,IAAI,CAACO,QAAQ,GAAG;IACzE;IAEJ,MAAME,SAAS,MAAMd,2BAA2B;QAC9CG;QACAE,MAAM;YACJ,GAAGA,IAAI;YACP,GAAGE,QAAQ;QACb;QACAH;IACF;IAEA,MAAMW,SAAShB,sBAAsB;QACnCiB,kBAAkBb,WAAWK,MAAM;QACnCS,SAASb,IAAIa,OAAO;QACpBC,OAAOJ,OAAOI,KAAK;IACrB;IAEA,OAAOC,SAASC,IAAI,CAClB;QACEC,KAAKP,OAAOO,GAAG;QACfC,SAAShB,EAAE;QACXY,OAAOJ,OAAOI,KAAK;QACnBK,MAAMT,OAAOS,IAAI;IACnB,GACA;QACEC,SAASvB,gBAAgB;YACvBuB,SAAS,IAAIC,QAAQ;gBACnB,cAAcV;YAChB;YACAX;QACF;QACAsB,QAAQ5B,WAAW6B,EAAE;IACvB;AAEJ,EAAC"}
|
|
@@ -9,7 +9,7 @@ export const verifyEmail = async ({ id, collection, req })=>{
|
|
|
9
9
|
token: id
|
|
10
10
|
});
|
|
11
11
|
return Response.json({
|
|
12
|
-
message: t('authentication:
|
|
12
|
+
message: t('authentication:accountVerified')
|
|
13
13
|
}, {
|
|
14
14
|
headers: headersWithCors({
|
|
15
15
|
headers: new Headers(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/auth/verifyEmail.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { verifyEmailOperation } from 'payload'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const verifyEmail: CollectionRouteHandlerWithID = async ({ id, collection, req }) => {\n const { t } = req\n await verifyEmailOperation({\n collection,\n req,\n token: id,\n })\n\n return Response.json(\n {\n message: t('authentication:
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/auth/verifyEmail.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { verifyEmailOperation } from 'payload'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const verifyEmail: CollectionRouteHandlerWithID = async ({ id, collection, req }) => {\n const { t } = req\n await verifyEmailOperation({\n collection,\n req,\n token: id,\n })\n\n return Response.json(\n {\n message: t('authentication:accountVerified'),\n },\n {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","verifyEmailOperation","headersWithCors","verifyEmail","id","collection","req","t","token","Response","json","message","headers","Headers","status","OK"],"mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,oBAAoB,QAAQ,UAAS;AAI9C,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,cAA4C,OAAO,EAAEC,EAAE,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACrF,MAAM,EAAEC,CAAC,EAAE,GAAGD;IACd,MAAML,qBAAqB;QACzBI;QACAC;QACAE,OAAOJ;IACT;IAEA,OAAOK,SAASC,IAAI,CAClB;QACEC,SAASJ,EAAE;IACb,GACA;QACEK,SAASV,gBAAgB;YACvBU,SAAS,IAAIC;YACbP;QACF;QACAQ,QAAQd,WAAWe,EAAE;IACvB;AAEJ,EAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
2
2
|
export declare const buildFormState: ({ req }: {
|
|
3
|
-
req:
|
|
3
|
+
req: PayloadRequest;
|
|
4
4
|
}) => Promise<Response>;
|
|
5
5
|
//# sourceMappingURL=buildFormState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildFormState.d.ts","sourceRoot":"","sources":["../../../src/routes/rest/buildFormState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"buildFormState.d.ts","sourceRoot":"","sources":["../../../src/routes/rest/buildFormState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAQ7C,eAAO,MAAM,cAAc,YAAmB;IAAE,GAAG,EAAE,cAAc,CAAA;CAAE,sBAyCpE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/routes/rest/buildFormState.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../../src/routes/rest/buildFormState.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { buildFormState as buildFormStateFn } from '@payloadcms/ui/utilities/buildFormState'\nimport httpStatus from 'http-status'\n\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\nimport { routeError } from './routeError.js'\n\nexport const buildFormState = async ({ req }: { req: PayloadRequest }) => {\n const headers = headersWithCors({\n headers: new Headers(),\n req,\n })\n\n try {\n const result = await buildFormStateFn({ req })\n\n return Response.json(result, {\n headers,\n status: httpStatus.OK,\n })\n } catch (err) {\n if (err.message === 'Could not find field schema for given path') {\n return Response.json(\n {\n message: err.message,\n },\n {\n headers,\n status: httpStatus.BAD_REQUEST,\n },\n )\n }\n\n if (err.message === 'Unauthorized') {\n return Response.json(null, {\n headers,\n status: httpStatus.UNAUTHORIZED,\n })\n }\n\n req.payload.logger.error({ err, msg: `There was an error building form state` })\n\n return routeError({\n config: req.payload.config,\n err,\n req,\n })\n }\n}\n"],"names":["buildFormState","buildFormStateFn","httpStatus","headersWithCors","routeError","req","headers","Headers","result","Response","json","status","OK","err","message","BAD_REQUEST","UNAUTHORIZED","payload","logger","error","msg","config"],"mappings":"AAEA,SAASA,kBAAkBC,gBAAgB,QAAQ,0CAAyC;AAC5F,OAAOC,gBAAgB,cAAa;AAEpC,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,UAAU,QAAQ,kBAAiB;AAE5C,OAAO,MAAMJ,iBAAiB,OAAO,EAAEK,GAAG,EAA2B;IACnE,MAAMC,UAAUH,gBAAgB;QAC9BG,SAAS,IAAIC;QACbF;IACF;IAEA,IAAI;QACF,MAAMG,SAAS,MAAMP,iBAAiB;YAAEI;QAAI;QAE5C,OAAOI,SAASC,IAAI,CAACF,QAAQ;YAC3BF;YACAK,QAAQT,WAAWU,EAAE;QACvB;IACF,EAAE,OAAOC,KAAK;QACZ,IAAIA,IAAIC,OAAO,KAAK,8CAA8C;YAChE,OAAOL,SAASC,IAAI,CAClB;gBACEI,SAASD,IAAIC,OAAO;YACtB,GACA;gBACER;gBACAK,QAAQT,WAAWa,WAAW;YAChC;QAEJ;QAEA,IAAIF,IAAIC,OAAO,KAAK,gBAAgB;YAClC,OAAOL,SAASC,IAAI,CAAC,MAAM;gBACzBJ;gBACAK,QAAQT,WAAWc,YAAY;YACjC;QACF;QAEAX,IAAIY,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;YAAEN;YAAKO,KAAK,CAAC,sCAAsC,CAAC;QAAC;QAE9E,OAAOhB,WAAW;YAChBiB,QAAQhB,IAAIY,OAAO,CAACI,MAAM;YAC1BR;YACAR;QACF;IACF;AACF,EAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Collection,
|
|
1
|
+
import type { Collection, PayloadRequest, TypeWithID } from 'payload';
|
|
2
2
|
export declare function checkFileAccess({ collection, filename, req, }: {
|
|
3
3
|
collection: Collection;
|
|
4
4
|
filename: string;
|
|
5
|
-
req:
|
|
5
|
+
req: PayloadRequest;
|
|
6
6
|
}): Promise<Response | TypeWithID>;
|
|
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,cAAc,EAAE,UAAU,EAAS,MAAM,SAAS,CAAA;AAM5E,wBAAsB,eAAe,CAAC,EACpC,UAAU,EACV,QAAQ,EACR,GAAG,GACJ,EAAE;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,OAAO,CAAC,QAAQ,GAAG,UAAU,CAAC,CA6CjC"}
|
|
@@ -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, PayloadRequest, TypeWithID, Where } from 'payload'\n\nimport { Forbidden, executeAccess } from 'payload'\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: PayloadRequest\n}): Promise<Response | TypeWithID> {\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 return doc\n }\n}\n"],"names":["Forbidden","executeAccess","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"],"mappings":"AAEA,SAASA,SAAS,EAAEC,aAAa,QAAQ,UAAS;AAElD,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,MAAMV,cAAc;QAAEW,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,IAAIxB,UAAUM,IAAIwB,CAAC;QAC3B;QAEA,OAAON;IACT;AACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Collection,
|
|
1
|
+
import type { Collection, PayloadRequest } from 'payload';
|
|
2
2
|
type Args = {
|
|
3
3
|
collection: Collection;
|
|
4
4
|
filename: string;
|
|
5
|
-
req:
|
|
5
|
+
req: PayloadRequest;
|
|
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,cAAc,EAAE,MAAM,SAAS,CAAA;AAezD,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,UAAU,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AACD,eAAO,MAAM,OAAO,kCAAyC,IAAI,KAAG,OAAO,CAAC,QAAQ,CA4DnF,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, PayloadRequest } from 'payload'\n\nimport { fileTypeFromFile } from 'file-type'\nimport fsPromises from 'fs/promises'\nimport httpStatus from 'http-status'\nimport path from 'path'\nimport { APIError } from 'payload'\n\nimport { streamFile } from '../../../fetchAPI-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: PayloadRequest\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 const accessResult = await checkFileAccess({\n collection,\n filename,\n req,\n })\n\n if (accessResult instanceof Response) return accessResult\n\n if (collection.config.upload.handlers?.length) {\n let customResponse = null\n for (const handler of collection.config.upload.handlers) {\n customResponse = await handler(req, {\n doc: accessResult,\n params: {\n collection: collection.config.slug,\n filename,\n },\n })\n }\n\n if (customResponse instanceof Response) return customResponse\n }\n\n const fileDir = collection.config.upload?.staticDir || collection.config.slug\n const filePath = path.resolve(`${fileDir}/${filename}`)\n const stats = await fsPromises.stat(filePath)\n const data = streamFile(filePath)\n const fileTypeResult = (await fileTypeFromFile(filePath)) || getFileTypeFallback(filePath)\n\n let headers = new Headers()\n headers.set('Content-Type', fileTypeResult.mime)\n headers.set('Content-Length', stats.size + '')\n headers = collection.config.upload?.modifyResponseHeaders\n ? collection.config.upload.modifyResponseHeaders({ headers })\n : headers\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":["fileTypeFromFile","fsPromises","httpStatus","path","APIError","streamFile","headersWithCors","routeError","checkFileAccess","getFileTypeFallback","getFile","collection","filename","req","config","upload","slug","BAD_REQUEST","accessResult","Response","handlers","length","customResponse","handler","doc","params","fileDir","staticDir","filePath","resolve","stats","stat","data","fileTypeResult","headers","Headers","set","mime","size","modifyResponseHeaders","status","OK","err","payload"],"mappings":"AAEA,SAASA,gBAAgB,QAAQ,YAAW;AAC5C,OAAOC,gBAAgB,cAAa;AACpC,OAAOC,gBAAgB,cAAa;AACpC,OAAOC,UAAU,OAAM;AACvB,SAASC,QAAQ,QAAQ,UAAS;AAElC,SAASC,UAAU,QAAQ,yCAAwC;AACnE,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,MAAMC,eAAe,MAAMV,gBAAgB;YACzCG;YACAC;YACAC;QACF;QAEA,IAAIK,wBAAwBC,UAAU,OAAOD;QAE7C,IAAIP,WAAWG,MAAM,CAACC,MAAM,CAACK,QAAQ,EAAEC,QAAQ;YAC7C,IAAIC,iBAAiB;YACrB,KAAK,MAAMC,WAAWZ,WAAWG,MAAM,CAACC,MAAM,CAACK,QAAQ,CAAE;gBACvDE,iBAAiB,MAAMC,QAAQV,KAAK;oBAClCW,KAAKN;oBACLO,QAAQ;wBACNd,YAAYA,WAAWG,MAAM,CAACE,IAAI;wBAClCJ;oBACF;gBACF;YACF;YAEA,IAAIU,0BAA0BH,UAAU,OAAOG;QACjD;QAEA,MAAMI,UAAUf,WAAWG,MAAM,CAACC,MAAM,EAAEY,aAAahB,WAAWG,MAAM,CAACE,IAAI;QAC7E,MAAMY,WAAWzB,KAAK0B,OAAO,CAAC,CAAC,EAAEH,QAAQ,CAAC,EAAEd,SAAS,CAAC;QACtD,MAAMkB,QAAQ,MAAM7B,WAAW8B,IAAI,CAACH;QACpC,MAAMI,OAAO3B,WAAWuB;QACxB,MAAMK,iBAAiB,AAAC,MAAMjC,iBAAiB4B,aAAcnB,oBAAoBmB;QAEjF,IAAIM,UAAU,IAAIC;QAClBD,QAAQE,GAAG,CAAC,gBAAgBH,eAAeI,IAAI;QAC/CH,QAAQE,GAAG,CAAC,kBAAkBN,MAAMQ,IAAI,GAAG;QAC3CJ,UAAUvB,WAAWG,MAAM,CAACC,MAAM,EAAEwB,wBAChC5B,WAAWG,MAAM,CAACC,MAAM,CAACwB,qBAAqB,CAAC;YAAEL;QAAQ,KACzDA;QAEJ,OAAO,IAAIf,SAASa,MAAM;YACxBE,SAAS5B,gBAAgB;gBACvB4B;gBACArB;YACF;YACA2B,QAAQtC,WAAWuC,EAAE;QACvB;IACF,EAAE,OAAOC,KAAK;QACZ,OAAOnC,WAAW;YAChBI;YACAG,QAAQD,IAAI8B,OAAO,CAAC7B,MAAM;YAC1B4B;YACA7B;QACF;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/routes/rest/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/routes/rest/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsD,eAAe,EAAE,MAAM,SAAS,CAAA;AAkMlG,eAAO,MAAM,OAAO,WACT,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,eAAqB,OAAO,sBA0B9E,CAAA;AAEH,eAAO,MAAM,GAAG,WACL,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,eACnC,OAAO,wBAAwB;IAAE,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAA;CAAE,sBAsL5E,CAAA;AAEH,eAAO,MAAM,IAAI,WACN,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,eACnC,OAAO,wBAAwB;IAAE,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAA;CAAE,sBA4K5E,CAAA;AAEH,eAAO,MAAM,MAAM,WACR,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,eACnC,OAAO,wBAAwB;IAAE,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAA;CAAE,sBAoF5E,CAAA;AAEH,eAAO,MAAM,KAAK,WACP,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,eACnC,OAAO,wBAAwB;IAAE,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAA;CAAE,sBAqF5E,CAAA"}
|