@payloadcms/next 3.0.0-beta.11 → 3.0.0-beta.13
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/cjs/withPayload.cjs +2 -1
- package/dist/cjs/withPayload.cjs.map +1 -1
- package/dist/exports/routes.d.ts +1 -1
- package/dist/exports/routes.d.ts.map +1 -1
- package/dist/exports/routes.js +1 -1
- package/dist/exports/routes.js.map +1 -1
- package/dist/exports/utilities.d.ts +3 -1
- package/dist/exports/utilities.d.ts.map +1 -1
- package/dist/exports/utilities.js +3 -1
- package/dist/exports/utilities.js.map +1 -1
- package/dist/next-fileupload/handlers.js.map +1 -1
- package/dist/next-fileupload/isEligibleRequest.js +1 -1
- package/dist/next-fileupload/isEligibleRequest.js.map +1 -1
- package/dist/next-fileupload/processMultipart.d.ts.map +1 -1
- package/dist/next-fileupload/processMultipart.js +29 -6
- package/dist/next-fileupload/processMultipart.js.map +1 -1
- package/dist/next-fileupload/utilities.d.ts.map +1 -1
- package/dist/next-fileupload/utilities.js +4 -4
- package/dist/next-fileupload/utilities.js.map +1 -1
- package/dist/routes/graphql/handler.d.ts.map +1 -1
- package/dist/routes/graphql/handler.js +9 -4
- package/dist/routes/graphql/handler.js.map +1 -1
- package/dist/routes/rest/auth/access.d.ts.map +1 -1
- package/dist/routes/rest/auth/access.js +5 -0
- package/dist/routes/rest/auth/access.js.map +1 -1
- package/dist/routes/rest/auth/forgotPassword.d.ts.map +1 -1
- package/dist/routes/rest/auth/forgotPassword.js +7 -2
- package/dist/routes/rest/auth/forgotPassword.js.map +1 -1
- package/dist/routes/rest/auth/init.d.ts.map +1 -1
- package/dist/routes/rest/auth/init.js +6 -0
- package/dist/routes/rest/auth/init.js.map +1 -1
- package/dist/routes/rest/auth/login.d.ts.map +1 -1
- package/dist/routes/rest/auth/login.js +8 -5
- package/dist/routes/rest/auth/login.js.map +1 -1
- package/dist/routes/rest/auth/logout.d.ts.map +1 -1
- package/dist/routes/rest/auth/logout.js +11 -6
- package/dist/routes/rest/auth/logout.js.map +1 -1
- package/dist/routes/rest/auth/me.d.ts.map +1 -1
- package/dist/routes/rest/auth/me.js +5 -0
- package/dist/routes/rest/auth/me.js.map +1 -1
- package/dist/routes/rest/auth/refresh.d.ts.map +1 -1
- package/dist/routes/rest/auth/refresh.js +11 -7
- package/dist/routes/rest/auth/refresh.js.map +1 -1
- package/dist/routes/rest/auth/registerFirstUser.d.ts.map +1 -1
- package/dist/routes/rest/auth/registerFirstUser.js +17 -5
- package/dist/routes/rest/auth/registerFirstUser.js.map +1 -1
- package/dist/routes/rest/auth/resetPassword.d.ts.map +1 -1
- package/dist/routes/rest/auth/resetPassword.js +8 -5
- package/dist/routes/rest/auth/resetPassword.js.map +1 -1
- package/dist/routes/rest/auth/unlock.d.ts.map +1 -1
- package/dist/routes/rest/auth/unlock.js +7 -2
- package/dist/routes/rest/auth/unlock.js.map +1 -1
- package/dist/routes/rest/auth/verifyEmail.d.ts.map +1 -1
- package/dist/routes/rest/auth/verifyEmail.js +7 -2
- package/dist/routes/rest/auth/verifyEmail.js.map +1 -1
- package/dist/routes/rest/buildFormState.d.ts.map +1 -1
- package/dist/routes/rest/buildFormState.js +11 -0
- package/dist/routes/rest/buildFormState.js.map +1 -1
- package/dist/routes/rest/collections/count.d.ts +3 -0
- package/dist/routes/rest/collections/count.d.ts.map +1 -0
- package/dist/routes/rest/collections/count.js +15 -0
- package/dist/routes/rest/collections/count.js.map +1 -0
- package/dist/routes/rest/collections/create.d.ts.map +1 -1
- package/dist/routes/rest/collections/create.js +5 -0
- package/dist/routes/rest/collections/create.js.map +1 -1
- package/dist/routes/rest/collections/delete.d.ts.map +1 -1
- package/dist/routes/rest/collections/delete.js +7 -0
- package/dist/routes/rest/collections/delete.js.map +1 -1
- package/dist/routes/rest/collections/deleteByID.d.ts.map +1 -1
- package/dist/routes/rest/collections/deleteByID.js +7 -0
- package/dist/routes/rest/collections/deleteByID.js.map +1 -1
- package/dist/routes/rest/collections/docAccess.d.ts.map +1 -1
- package/dist/routes/rest/collections/docAccess.js +5 -0
- package/dist/routes/rest/collections/docAccess.js.map +1 -1
- package/dist/routes/rest/collections/duplicate.d.ts.map +1 -1
- package/dist/routes/rest/collections/duplicate.js +5 -0
- package/dist/routes/rest/collections/duplicate.js.map +1 -1
- package/dist/routes/rest/collections/find.d.ts.map +1 -1
- package/dist/routes/rest/collections/find.js +5 -0
- package/dist/routes/rest/collections/find.js.map +1 -1
- package/dist/routes/rest/collections/findByID.d.ts.map +1 -1
- package/dist/routes/rest/collections/findByID.js +5 -0
- package/dist/routes/rest/collections/findByID.js.map +1 -1
- package/dist/routes/rest/collections/findVersionByID.d.ts.map +1 -1
- package/dist/routes/rest/collections/findVersionByID.js +5 -0
- package/dist/routes/rest/collections/findVersionByID.js.map +1 -1
- package/dist/routes/rest/collections/findVersions.d.ts.map +1 -1
- package/dist/routes/rest/collections/findVersions.js +5 -0
- package/dist/routes/rest/collections/findVersions.js.map +1 -1
- package/dist/routes/rest/collections/preview.d.ts.map +1 -1
- package/dist/routes/rest/collections/preview.js +7 -1
- package/dist/routes/rest/collections/preview.js.map +1 -1
- package/dist/routes/rest/collections/restoreVersion.d.ts.map +1 -1
- package/dist/routes/rest/collections/restoreVersion.js +5 -0
- package/dist/routes/rest/collections/restoreVersion.js.map +1 -1
- package/dist/routes/rest/collections/update.d.ts.map +1 -1
- package/dist/routes/rest/collections/update.js +7 -0
- package/dist/routes/rest/collections/update.js.map +1 -1
- package/dist/routes/rest/collections/updateByID.d.ts.map +1 -1
- package/dist/routes/rest/collections/updateByID.js +5 -0
- package/dist/routes/rest/collections/updateByID.js.map +1 -1
- package/dist/routes/rest/files/getFile.d.ts.map +1 -1
- package/dist/routes/rest/files/getFile.js +15 -8
- package/dist/routes/rest/files/getFile.js.map +1 -1
- package/dist/routes/rest/files/getFileTypeFallback.d.ts +7 -0
- package/dist/routes/rest/files/getFileTypeFallback.d.ts.map +1 -0
- package/dist/routes/rest/files/getFileTypeFallback.js +21 -0
- package/dist/routes/rest/files/getFileTypeFallback.js.map +1 -0
- package/dist/routes/rest/globals/docAccess.d.ts.map +1 -1
- package/dist/routes/rest/globals/docAccess.js +5 -0
- package/dist/routes/rest/globals/docAccess.js.map +1 -1
- package/dist/routes/rest/globals/findOne.d.ts.map +1 -1
- package/dist/routes/rest/globals/findOne.js +5 -0
- package/dist/routes/rest/globals/findOne.js.map +1 -1
- package/dist/routes/rest/globals/findVersionByID.d.ts.map +1 -1
- package/dist/routes/rest/globals/findVersionByID.js +5 -0
- package/dist/routes/rest/globals/findVersionByID.js.map +1 -1
- package/dist/routes/rest/globals/findVersions.d.ts.map +1 -1
- package/dist/routes/rest/globals/findVersions.js +5 -0
- package/dist/routes/rest/globals/findVersions.js.map +1 -1
- package/dist/routes/rest/globals/preview.d.ts.map +1 -1
- package/dist/routes/rest/globals/preview.js +7 -1
- package/dist/routes/rest/globals/preview.js.map +1 -1
- package/dist/routes/rest/globals/restoreVersion.d.ts.map +1 -1
- package/dist/routes/rest/globals/restoreVersion.js +5 -0
- package/dist/routes/rest/globals/restoreVersion.js.map +1 -1
- package/dist/routes/rest/globals/update.d.ts.map +1 -1
- package/dist/routes/rest/globals/update.js +5 -0
- package/dist/routes/rest/globals/update.js.map +1 -1
- package/dist/routes/rest/index.d.ts +1 -0
- package/dist/routes/rest/index.d.ts.map +1 -1
- package/dist/routes/rest/index.js +55 -9
- package/dist/routes/rest/index.js.map +1 -1
- package/dist/routes/rest/routeError.d.ts +5 -4
- package/dist/routes/rest/routeError.d.ts.map +1 -1
- package/dist/routes/rest/routeError.js +25 -11
- package/dist/routes/rest/routeError.js.map +1 -1
- package/dist/utilities/getDataAndFile.d.ts.map +1 -1
- package/dist/utilities/getDataAndFile.js +26 -46
- package/dist/utilities/getDataAndFile.js.map +1 -1
- package/dist/utilities/getPayloadHMR.d.ts +2 -1
- package/dist/utilities/getPayloadHMR.d.ts.map +1 -1
- package/dist/utilities/getPayloadHMR.js +22 -19
- package/dist/utilities/getPayloadHMR.js.map +1 -1
- package/dist/utilities/headersWithCors.d.ts +8 -0
- package/dist/utilities/headersWithCors.d.ts.map +1 -0
- package/dist/utilities/headersWithCors.js +17 -0
- package/dist/utilities/headersWithCors.js.map +1 -0
- package/dist/utilities/initPage.d.ts.map +1 -1
- package/dist/utilities/initPage.js +15 -2
- package/dist/utilities/initPage.js.map +1 -1
- package/dist/views/CreateFirstUser/index.client.js +2 -2
- 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 +17 -0
- package/dist/views/CreateFirstUser/index.js.map +1 -1
- package/dist/views/Edit/Default/index.d.ts.map +1 -1
- package/dist/views/Edit/Default/index.js +3 -2
- package/dist/views/Edit/Default/index.js.map +1 -1
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.d.ts +3 -0
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.d.ts.map +1 -0
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.js +55 -0
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.js.map +1 -0
- package/dist/views/ForgotPassword/index.d.ts.map +1 -1
- package/dist/views/ForgotPassword/index.js +3 -39
- package/dist/views/ForgotPassword/index.js.map +1 -1
- package/dist/views/LivePreview/Toolbar/Controls/index.d.ts.map +1 -1
- package/dist/views/LivePreview/Toolbar/Controls/index.js +6 -4
- package/dist/views/LivePreview/Toolbar/Controls/index.js.map +1 -1
- package/dist/views/Login/LoginForm/index.d.ts.map +1 -1
- package/dist/views/Login/LoginForm/index.js +26 -2
- package/dist/views/Login/LoginForm/index.js.map +1 -1
- package/dist/views/Logout/LogoutClient.d.ts.map +1 -1
- package/dist/views/Logout/LogoutClient.js +1 -2
- package/dist/views/Logout/LogoutClient.js.map +1 -1
- package/dist/withPayload.d.ts.map +1 -1
- package/dist/withPayload.js +2 -1
- package/dist/withPayload.js.map +1 -1
- package/package.json +11 -9
- package/src/index.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/collections/updateByID.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { updateByIDOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nimport { sanitizeCollectionID } from '../utilities/sanitizeCollectionID.js'\n\nexport const updateByID: CollectionRouteHandlerWithID = async ({\n id: incomingID,\n collection,\n req,\n}) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n const autosave = searchParams.get('autosave') === 'true'\n const draft = searchParams.get('draft') === 'true'\n\n const id = sanitizeCollectionID({\n id: incomingID,\n collectionSlug: collection.config.slug,\n payload: req.payload,\n })\n\n const doc = await updateByIDOperation({\n id,\n autosave,\n collection,\n data: req.data,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft,\n req,\n })\n\n let message = req.t('general:updatedSuccessfully')\n\n if (draft) message = req.t('version:draftSavedSuccessfully')\n if (autosave) message = req.t('version:autosavedSuccessfully')\n\n return Response.json(\n {\n doc,\n message,\n },\n {\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","updateByIDOperation","isNumber","sanitizeCollectionID","updateByID","id","incomingID","collection","req","searchParams","depth","get","autosave","draft","collectionSlug","config","slug","payload","doc","data","Number","undefined","message","t","Response","json","status","OK"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/collections/updateByID.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { updateByIDOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\nimport { sanitizeCollectionID } from '../utilities/sanitizeCollectionID.js'\n\nexport const updateByID: CollectionRouteHandlerWithID = async ({\n id: incomingID,\n collection,\n req,\n}) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n const autosave = searchParams.get('autosave') === 'true'\n const draft = searchParams.get('draft') === 'true'\n\n const id = sanitizeCollectionID({\n id: incomingID,\n collectionSlug: collection.config.slug,\n payload: req.payload,\n })\n\n const doc = await updateByIDOperation({\n id,\n autosave,\n collection,\n data: req.data,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft,\n req,\n })\n\n let message = req.t('general:updatedSuccessfully')\n\n if (draft) message = req.t('version:draftSavedSuccessfully')\n if (autosave) message = req.t('version:autosavedSuccessfully')\n\n return Response.json(\n {\n doc,\n message,\n },\n {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","updateByIDOperation","isNumber","headersWithCors","sanitizeCollectionID","updateByID","id","incomingID","collection","req","searchParams","depth","get","autosave","draft","collectionSlug","config","slug","payload","doc","data","Number","undefined","message","t","Response","json","headers","Headers","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,mBAAmB,QAAQ,qBAAoB;AACxD,SAASC,QAAQ,QAAQ,oBAAmB;AAI5C,SAASC,eAAe,QAAQ,wCAAuC;AACvE,SAASC,oBAAoB,QAAQ,uCAAsC;AAE3E,OAAO,MAAMC,aAA2C,OAAO,EAC7DC,IAAIC,UAAU,EACdC,UAAU,EACVC,GAAG,EACJ;IACC,MAAM,EAAEC,YAAY,EAAE,GAAGD;IACzB,MAAME,QAAQD,aAAaE,GAAG,CAAC;IAC/B,MAAMC,WAAWH,aAAaE,GAAG,CAAC,gBAAgB;IAClD,MAAME,QAAQJ,aAAaE,GAAG,CAAC,aAAa;IAE5C,MAAMN,KAAKF,qBAAqB;QAC9BE,IAAIC;QACJQ,gBAAgBP,WAAWQ,MAAM,CAACC,IAAI;QACtCC,SAAST,IAAIS,OAAO;IACtB;IAEA,MAAMC,MAAM,MAAMlB,oBAAoB;QACpCK;QACAO;QACAL;QACAY,MAAMX,IAAIW,IAAI;QACdT,OAAOT,SAASS,SAASU,OAAOV,SAASW;QACzCR;QACAL;IACF;IAEA,IAAIc,UAAUd,IAAIe,CAAC,CAAC;IAEpB,IAAIV,OAAOS,UAAUd,IAAIe,CAAC,CAAC;IAC3B,IAAIX,UAAUU,UAAUd,IAAIe,CAAC,CAAC;IAE9B,OAAOC,SAASC,IAAI,CAClB;QACEP;QACAI;IACF,GACA;QACEI,SAASxB,gBAAgB;YACvBwB,SAAS,IAAIC;YACbnB;QACF;QACAoB,QAAQ7B,WAAW8B,EAAE;IACvB;AAEJ,EAAC"}
|
|
@@ -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,cAAc,EAAE,MAAM,eAAe,CAAA;
|
|
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,eAAe,CAAA;AAe/D,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,QAAQ,QAAQ,CA0DnF,CAAA"}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
+
import getFileType from 'file-type';
|
|
1
2
|
import fsPromises from 'fs/promises';
|
|
2
3
|
import httpStatus from 'http-status';
|
|
3
4
|
import path from 'path';
|
|
4
5
|
import { APIError } from 'payload/errors';
|
|
5
6
|
import { streamFile } from '../../../next-stream-file/index.js';
|
|
7
|
+
import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
6
8
|
import { routeError } from '../routeError.js';
|
|
7
9
|
import { checkFileAccess } from './checkFileAccess.js';
|
|
10
|
+
import { getFileTypeFallback } from './getFileTypeFallback.js';
|
|
8
11
|
export const getFile = async ({ collection, filename, req })=>{
|
|
9
12
|
try {
|
|
10
13
|
if (!collection.config.upload) {
|
|
11
14
|
throw new APIError(`This collection is not an upload collection: ${collection.config.slug}`, httpStatus.BAD_REQUEST);
|
|
12
15
|
}
|
|
13
|
-
if (collection.config.upload.disableLocalStorage && !collection.config.upload.handlers) {
|
|
14
|
-
throw new APIError(`This collection has local storage disabled: ${collection.config.slug}`, httpStatus.BAD_REQUEST);
|
|
15
|
-
}
|
|
16
16
|
await checkFileAccess({
|
|
17
17
|
collection,
|
|
18
18
|
filename,
|
|
@@ -28,22 +28,29 @@ export const getFile = async ({ collection, filename, req })=>{
|
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
return response;
|
|
31
|
+
if (response instanceof Response) return response;
|
|
32
32
|
}
|
|
33
33
|
const fileDir = collection.config.upload?.staticDir || collection.config.slug;
|
|
34
34
|
const filePath = path.resolve(`${fileDir}/${filename}`);
|
|
35
35
|
const stats = await fsPromises.stat(filePath);
|
|
36
36
|
const data = streamFile(filePath);
|
|
37
|
+
const headers = new Headers({
|
|
38
|
+
'Content-Length': stats.size + ''
|
|
39
|
+
});
|
|
40
|
+
const fileTypeResult = await getFileType.fromFile(filePath) || getFileTypeFallback(filePath);
|
|
41
|
+
headers.set('Content-Type', fileTypeResult.mime);
|
|
37
42
|
return new Response(data, {
|
|
38
|
-
headers:
|
|
39
|
-
|
|
43
|
+
headers: headersWithCors({
|
|
44
|
+
headers,
|
|
45
|
+
req
|
|
40
46
|
}),
|
|
41
47
|
status: httpStatus.OK
|
|
42
48
|
});
|
|
43
|
-
} catch (
|
|
49
|
+
} catch (err) {
|
|
44
50
|
return routeError({
|
|
45
51
|
collection,
|
|
46
|
-
|
|
52
|
+
config: req.payload.config,
|
|
53
|
+
err,
|
|
47
54
|
req
|
|
48
55
|
});
|
|
49
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/files/getFile.ts"],"sourcesContent":["import type { Collection, PayloadRequest } from 'payload/types'\n\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 { routeError } from '../routeError.js'\nimport { checkFileAccess } from './checkFileAccess.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
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/files/getFile.ts"],"sourcesContent":["import type { Collection, PayloadRequest } 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: 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 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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFileTypeFallback.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/files/getFileTypeFallback.ts"],"names":[],"mappings":"AAAA,KAAK,UAAU,GAAG;IAChB,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAiBD,eAAO,MAAM,mBAAmB,SAAU,MAAM,KAAG,UAOlD,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const extensionMap = {
|
|
2
|
+
css: 'text/css',
|
|
3
|
+
csv: 'text/csv',
|
|
4
|
+
htm: 'text/html',
|
|
5
|
+
html: 'text/html',
|
|
6
|
+
js: 'application/javascript',
|
|
7
|
+
json: 'application/json',
|
|
8
|
+
md: 'text/markdown',
|
|
9
|
+
svg: 'image/svg+xml',
|
|
10
|
+
xml: 'application/xml',
|
|
11
|
+
yml: 'application/x-yaml'
|
|
12
|
+
};
|
|
13
|
+
export const getFileTypeFallback = (path)=>{
|
|
14
|
+
const ext = path.split('.').pop() || 'txt';
|
|
15
|
+
return {
|
|
16
|
+
ext,
|
|
17
|
+
mime: extensionMap[ext] || 'text/plain'
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=getFileTypeFallback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/files/getFileTypeFallback.ts"],"sourcesContent":["type ReturnType = {\n ext: string\n mime: string\n}\n\nconst extensionMap: {\n [ext: string]: string\n} = {\n css: 'text/css',\n csv: 'text/csv',\n htm: 'text/html',\n html: 'text/html',\n js: 'application/javascript',\n json: 'application/json',\n md: 'text/markdown',\n svg: 'image/svg+xml',\n xml: 'application/xml',\n yml: 'application/x-yaml',\n}\n\nexport const getFileTypeFallback = (path: string): ReturnType => {\n const ext = path.split('.').pop() || 'txt'\n\n return {\n ext,\n mime: extensionMap[ext] || 'text/plain',\n }\n}\n"],"names":["extensionMap","css","csv","htm","html","js","json","md","svg","xml","yml","getFileTypeFallback","path","ext","split","pop","mime"],"rangeMappings":";;;;;;;;;;;;;;;;;;","mappings":"AAKA,MAAMA,eAEF;IACFC,KAAK;IACLC,KAAK;IACLC,KAAK;IACLC,MAAM;IACNC,IAAI;IACJC,MAAM;IACNC,IAAI;IACJC,KAAK;IACLC,KAAK;IACLC,KAAK;AACP;AAEA,OAAO,MAAMC,sBAAsB,CAACC;IAClC,MAAMC,MAAMD,KAAKE,KAAK,CAAC,KAAKC,GAAG,MAAM;IAErC,OAAO;QACLF;QACAG,MAAMhB,YAAY,CAACa,IAAI,IAAI;IAC7B;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"docAccess.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/docAccess.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"docAccess.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/docAccess.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAIrD,eAAO,MAAM,SAAS,EAAE,kBAavB,CAAA"}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import httpStatus from 'http-status';
|
|
2
2
|
import { docAccessOperationGlobal } from 'payload/operations';
|
|
3
|
+
import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
3
4
|
export const docAccess = async ({ globalConfig, req })=>{
|
|
4
5
|
const result = await docAccessOperationGlobal({
|
|
5
6
|
globalConfig,
|
|
6
7
|
req
|
|
7
8
|
});
|
|
8
9
|
return Response.json(result, {
|
|
10
|
+
headers: headersWithCors({
|
|
11
|
+
headers: new Headers(),
|
|
12
|
+
req
|
|
13
|
+
}),
|
|
9
14
|
status: httpStatus.OK
|
|
10
15
|
});
|
|
11
16
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/globals/docAccess.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { docAccessOperationGlobal } from 'payload/operations'\n\nimport type { GlobalRouteHandler } from '../types.js'\n\nexport const docAccess: GlobalRouteHandler = async ({ globalConfig, req }) => {\n const result = await docAccessOperationGlobal({\n globalConfig,\n req,\n })\n\n return Response.json(result, {\n status: httpStatus.OK,\n })\n}\n"],"names":["httpStatus","docAccessOperationGlobal","docAccess","globalConfig","req","result","Response","json","status","OK"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/globals/docAccess.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { docAccessOperationGlobal } from 'payload/operations'\n\nimport type { GlobalRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const docAccess: GlobalRouteHandler = async ({ globalConfig, req }) => {\n const result = await docAccessOperationGlobal({\n globalConfig,\n req,\n })\n\n return Response.json(result, {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n })\n}\n"],"names":["httpStatus","docAccessOperationGlobal","headersWithCors","docAccess","globalConfig","req","result","Response","json","headers","Headers","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,wBAAwB,QAAQ,qBAAoB;AAI7D,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,YAAgC,OAAO,EAAEC,YAAY,EAAEC,GAAG,EAAE;IACvE,MAAMC,SAAS,MAAML,yBAAyB;QAC5CG;QACAC;IACF;IAEA,OAAOE,SAASC,IAAI,CAACF,QAAQ;QAC3BG,SAASP,gBAAgB;YACvBO,SAAS,IAAIC;YACbL;QACF;QACAM,QAAQX,WAAWY,EAAE;IACvB;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/findOne.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/findOne.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAIrD,eAAO,MAAM,OAAO,EAAE,kBAmBrB,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import httpStatus from 'http-status';
|
|
2
2
|
import { findOneOperation } from 'payload/operations';
|
|
3
3
|
import { isNumber } from 'payload/utilities';
|
|
4
|
+
import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
4
5
|
export const findOne = async ({ globalConfig, req })=>{
|
|
5
6
|
const { searchParams } = req;
|
|
6
7
|
const depth = searchParams.get('depth');
|
|
@@ -12,6 +13,10 @@ export const findOne = async ({ globalConfig, req })=>{
|
|
|
12
13
|
req
|
|
13
14
|
});
|
|
14
15
|
return Response.json(result, {
|
|
16
|
+
headers: headersWithCors({
|
|
17
|
+
headers: new Headers(),
|
|
18
|
+
req
|
|
19
|
+
}),
|
|
15
20
|
status: httpStatus.OK
|
|
16
21
|
});
|
|
17
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/globals/findOne.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { findOneOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { GlobalRouteHandler } from '../types.js'\n\nexport const findOne: GlobalRouteHandler = async ({ globalConfig, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const result = await findOneOperation({\n slug: globalConfig.slug,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft: searchParams.get('draft') === 'true',\n globalConfig,\n req,\n })\n\n return Response.json(result, {\n status: httpStatus.OK,\n })\n}\n"],"names":["httpStatus","findOneOperation","isNumber","findOne","globalConfig","req","searchParams","depth","get","result","slug","Number","undefined","draft","Response","json","status","OK"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/globals/findOne.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { findOneOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { GlobalRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const findOne: GlobalRouteHandler = async ({ globalConfig, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const result = await findOneOperation({\n slug: globalConfig.slug,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft: searchParams.get('draft') === 'true',\n globalConfig,\n req,\n })\n\n return Response.json(result, {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n })\n}\n"],"names":["httpStatus","findOneOperation","isNumber","headersWithCors","findOne","globalConfig","req","searchParams","depth","get","result","slug","Number","undefined","draft","Response","json","headers","Headers","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,gBAAgB,QAAQ,qBAAoB;AACrD,SAASC,QAAQ,QAAQ,oBAAmB;AAI5C,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,UAA8B,OAAO,EAAEC,YAAY,EAAEC,GAAG,EAAE;IACrE,MAAM,EAAEC,YAAY,EAAE,GAAGD;IACzB,MAAME,QAAQD,aAAaE,GAAG,CAAC;IAE/B,MAAMC,SAAS,MAAMT,iBAAiB;QACpCU,MAAMN,aAAaM,IAAI;QACvBH,OAAON,SAASM,SAASI,OAAOJ,SAASK;QACzCC,OAAOP,aAAaE,GAAG,CAAC,aAAa;QACrCJ;QACAC;IACF;IAEA,OAAOS,SAASC,IAAI,CAACN,QAAQ;QAC3BO,SAASd,gBAAgB;YACvBc,SAAS,IAAIC;YACbZ;QACF;QACAa,QAAQnB,WAAWoB,EAAE;IACvB;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findVersionByID.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/findVersionByID.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"findVersionByID.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/findVersionByID.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAI3D,eAAO,MAAM,eAAe,EAAE,wBAkB7B,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import httpStatus from 'http-status';
|
|
2
2
|
import { findVersionByIDOperationGlobal } from 'payload/operations';
|
|
3
3
|
import { isNumber } from 'payload/utilities';
|
|
4
|
+
import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
4
5
|
export const findVersionByID = async ({ id, globalConfig, req })=>{
|
|
5
6
|
const { searchParams } = req;
|
|
6
7
|
const depth = searchParams.get('depth');
|
|
@@ -11,6 +12,10 @@ export const findVersionByID = async ({ id, globalConfig, req })=>{
|
|
|
11
12
|
req
|
|
12
13
|
});
|
|
13
14
|
return Response.json(result, {
|
|
15
|
+
headers: headersWithCors({
|
|
16
|
+
headers: new Headers(),
|
|
17
|
+
req
|
|
18
|
+
}),
|
|
14
19
|
status: httpStatus.OK
|
|
15
20
|
});
|
|
16
21
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/globals/findVersionByID.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { findVersionByIDOperationGlobal } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { GlobalRouteHandlerWithID } from '../types.js'\n\nexport const findVersionByID: GlobalRouteHandlerWithID = async ({ id, globalConfig, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const result = await findVersionByIDOperationGlobal({\n id,\n depth: isNumber(depth) ? Number(depth) : undefined,\n globalConfig,\n req,\n })\n\n return Response.json(result, {\n status: httpStatus.OK,\n })\n}\n"],"names":["httpStatus","findVersionByIDOperationGlobal","isNumber","findVersionByID","id","globalConfig","req","searchParams","depth","get","result","Number","undefined","Response","json","status","OK"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/globals/findVersionByID.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { findVersionByIDOperationGlobal } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { GlobalRouteHandlerWithID } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const findVersionByID: GlobalRouteHandlerWithID = async ({ id, globalConfig, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const result = await findVersionByIDOperationGlobal({\n id,\n depth: isNumber(depth) ? Number(depth) : undefined,\n globalConfig,\n req,\n })\n\n return Response.json(result, {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n })\n}\n"],"names":["httpStatus","findVersionByIDOperationGlobal","isNumber","headersWithCors","findVersionByID","id","globalConfig","req","searchParams","depth","get","result","Number","undefined","Response","json","headers","Headers","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,8BAA8B,QAAQ,qBAAoB;AACnE,SAASC,QAAQ,QAAQ,oBAAmB;AAI5C,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,kBAA4C,OAAO,EAAEC,EAAE,EAAEC,YAAY,EAAEC,GAAG,EAAE;IACvF,MAAM,EAAEC,YAAY,EAAE,GAAGD;IACzB,MAAME,QAAQD,aAAaE,GAAG,CAAC;IAE/B,MAAMC,SAAS,MAAMV,+BAA+B;QAClDI;QACAI,OAAOP,SAASO,SAASG,OAAOH,SAASI;QACzCP;QACAC;IACF;IAEA,OAAOO,SAASC,IAAI,CAACJ,QAAQ;QAC3BK,SAASb,gBAAgB;YACvBa,SAAS,IAAIC;YACbV;QACF;QACAW,QAAQlB,WAAWmB,EAAE;IACvB;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/findVersions.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/findVersions.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAIrD,eAAO,MAAM,YAAY,EAAE,kBA0B1B,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import httpStatus from 'http-status';
|
|
2
2
|
import { findVersionsOperationGlobal } from 'payload/operations';
|
|
3
3
|
import { isNumber } from 'payload/utilities';
|
|
4
|
+
import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
4
5
|
export const findVersions = async ({ globalConfig, req })=>{
|
|
5
6
|
const { depth, limit, page, sort, where } = req.query;
|
|
6
7
|
const result = await findVersionsOperationGlobal({
|
|
@@ -13,6 +14,10 @@ export const findVersions = async ({ globalConfig, req })=>{
|
|
|
13
14
|
where
|
|
14
15
|
});
|
|
15
16
|
return Response.json(result, {
|
|
17
|
+
headers: headersWithCors({
|
|
18
|
+
headers: new Headers(),
|
|
19
|
+
req
|
|
20
|
+
}),
|
|
16
21
|
status: httpStatus.OK
|
|
17
22
|
});
|
|
18
23
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/globals/findVersions.ts"],"sourcesContent":["import type { Where } from 'payload/types'\n\nimport httpStatus from 'http-status'\nimport { findVersionsOperationGlobal } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { GlobalRouteHandler } from '../types.js'\n\nexport const findVersions: GlobalRouteHandler = async ({ globalConfig, req }) => {\n const { depth, limit, page, sort, where } = req.query as {\n depth?: string\n limit?: string\n page?: string\n sort?: string\n where?: Where\n }\n\n const result = await findVersionsOperationGlobal({\n depth: isNumber(depth) ? Number(depth) : undefined,\n globalConfig,\n limit: isNumber(limit) ? Number(limit) : undefined,\n page: isNumber(page) ? Number(page) : undefined,\n req,\n sort,\n where,\n })\n\n return Response.json(result, {\n status: httpStatus.OK,\n })\n}\n"],"names":["httpStatus","findVersionsOperationGlobal","isNumber","findVersions","globalConfig","req","depth","limit","page","sort","where","query","result","Number","undefined","Response","json","status","OK"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/globals/findVersions.ts"],"sourcesContent":["import type { Where } from 'payload/types'\n\nimport httpStatus from 'http-status'\nimport { findVersionsOperationGlobal } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { GlobalRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const findVersions: GlobalRouteHandler = async ({ globalConfig, req }) => {\n const { depth, limit, page, sort, where } = req.query as {\n depth?: string\n limit?: string\n page?: string\n sort?: string\n where?: Where\n }\n\n const result = await findVersionsOperationGlobal({\n depth: isNumber(depth) ? Number(depth) : undefined,\n globalConfig,\n limit: isNumber(limit) ? Number(limit) : undefined,\n page: isNumber(page) ? Number(page) : undefined,\n req,\n sort,\n where,\n })\n\n return Response.json(result, {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n })\n}\n"],"names":["httpStatus","findVersionsOperationGlobal","isNumber","headersWithCors","findVersions","globalConfig","req","depth","limit","page","sort","where","query","result","Number","undefined","Response","json","headers","Headers","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,2BAA2B,QAAQ,qBAAoB;AAChE,SAASC,QAAQ,QAAQ,oBAAmB;AAI5C,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,eAAmC,OAAO,EAAEC,YAAY,EAAEC,GAAG,EAAE;IAC1E,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAEC,IAAI,EAAEC,IAAI,EAAEC,KAAK,EAAE,GAAGL,IAAIM,KAAK;IAQrD,MAAMC,SAAS,MAAMZ,4BAA4B;QAC/CM,OAAOL,SAASK,SAASO,OAAOP,SAASQ;QACzCV;QACAG,OAAON,SAASM,SAASM,OAAON,SAASO;QACzCN,MAAMP,SAASO,QAAQK,OAAOL,QAAQM;QACtCT;QACAI;QACAC;IACF;IAEA,OAAOK,SAASC,IAAI,CAACJ,QAAQ;QAC3BK,SAASf,gBAAgB;YACvBe,SAAS,IAAIC;YACbb;QACF;QACAc,QAAQpB,WAAWqB,EAAE;IACvB;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/preview.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/preview.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAKrD,eAAO,MAAM,OAAO,EAAE,kBA2CrB,CAAA"}
|
|
@@ -2,6 +2,7 @@ import httpStatus from 'http-status';
|
|
|
2
2
|
import { extractJWT } from 'payload/auth';
|
|
3
3
|
import { findOneOperation } from 'payload/operations';
|
|
4
4
|
import { isNumber } from 'payload/utilities';
|
|
5
|
+
import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
5
6
|
import { routeError } from '../routeError.js';
|
|
6
7
|
export const preview = async ({ globalConfig, req })=>{
|
|
7
8
|
const { searchParams } = req;
|
|
@@ -24,13 +25,18 @@ export const preview = async ({ globalConfig, req })=>{
|
|
|
24
25
|
token
|
|
25
26
|
});
|
|
26
27
|
} catch (err) {
|
|
27
|
-
routeError({
|
|
28
|
+
return routeError({
|
|
29
|
+
config: req.payload.config,
|
|
28
30
|
err,
|
|
29
31
|
req
|
|
30
32
|
});
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
return Response.json(previewURL, {
|
|
36
|
+
headers: headersWithCors({
|
|
37
|
+
headers: new Headers(),
|
|
38
|
+
req
|
|
39
|
+
}),
|
|
34
40
|
status: httpStatus.OK
|
|
35
41
|
});
|
|
36
42
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/globals/preview.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { extractJWT } from 'payload/auth'\nimport { findOneOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { GlobalRouteHandler } from '../types.js'\n\nimport { routeError } from '../routeError.js'\n\nexport const preview: GlobalRouteHandler = async ({ globalConfig, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const result = await findOneOperation({\n slug: globalConfig.slug,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft: searchParams.get('draft') === 'true',\n globalConfig,\n req,\n })\n\n let previewURL: string\n\n const generatePreviewURL = req.payload.config.globals.find(\n (config) => config.slug === globalConfig.slug,\n )?.admin?.preview\n\n const token = extractJWT(req)\n\n if (typeof generatePreviewURL === 'function') {\n try {\n previewURL = await generatePreviewURL(result, {\n locale: req.locale,\n req,\n token,\n })\n } catch (err) {\n routeError({\n err,\n req,\n })\n }\n }\n\n return Response.json(previewURL, {\n status: httpStatus.OK,\n })\n}\n"],"names":["httpStatus","extractJWT","findOneOperation","isNumber","routeError","preview","globalConfig","req","searchParams","depth","get","result","slug","Number","undefined","draft","previewURL","generatePreviewURL","payload","config","globals","find","admin","token","locale","err","Response","json","status","OK"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/globals/preview.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { extractJWT } from 'payload/auth'\nimport { findOneOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { GlobalRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\nimport { routeError } from '../routeError.js'\n\nexport const preview: GlobalRouteHandler = async ({ globalConfig, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const result = await findOneOperation({\n slug: globalConfig.slug,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft: searchParams.get('draft') === 'true',\n globalConfig,\n req,\n })\n\n let previewURL: string\n\n const generatePreviewURL = req.payload.config.globals.find(\n (config) => config.slug === globalConfig.slug,\n )?.admin?.preview\n\n const token = extractJWT(req)\n\n if (typeof generatePreviewURL === 'function') {\n try {\n previewURL = await generatePreviewURL(result, {\n locale: req.locale,\n req,\n token,\n })\n } catch (err) {\n return routeError({\n config: req.payload.config,\n err,\n req,\n })\n }\n }\n\n return Response.json(previewURL, {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n })\n}\n"],"names":["httpStatus","extractJWT","findOneOperation","isNumber","headersWithCors","routeError","preview","globalConfig","req","searchParams","depth","get","result","slug","Number","undefined","draft","previewURL","generatePreviewURL","payload","config","globals","find","admin","token","locale","err","Response","json","headers","Headers","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,UAAU,QAAQ,eAAc;AACzC,SAASC,gBAAgB,QAAQ,qBAAoB;AACrD,SAASC,QAAQ,QAAQ,oBAAmB;AAI5C,SAASC,eAAe,QAAQ,wCAAuC;AACvE,SAASC,UAAU,QAAQ,mBAAkB;AAE7C,OAAO,MAAMC,UAA8B,OAAO,EAAEC,YAAY,EAAEC,GAAG,EAAE;IACrE,MAAM,EAAEC,YAAY,EAAE,GAAGD;IACzB,MAAME,QAAQD,aAAaE,GAAG,CAAC;IAE/B,MAAMC,SAAS,MAAMV,iBAAiB;QACpCW,MAAMN,aAAaM,IAAI;QACvBH,OAAOP,SAASO,SAASI,OAAOJ,SAASK;QACzCC,OAAOP,aAAaE,GAAG,CAAC,aAAa;QACrCJ;QACAC;IACF;IAEA,IAAIS;IAEJ,MAAMC,qBAAqBV,IAAIW,OAAO,CAACC,MAAM,CAACC,OAAO,CAACC,IAAI,CACxD,CAACF,SAAWA,OAAOP,IAAI,KAAKN,aAAaM,IAAI,GAC5CU,OAAOjB;IAEV,MAAMkB,QAAQvB,WAAWO;IAEzB,IAAI,OAAOU,uBAAuB,YAAY;QAC5C,IAAI;YACFD,aAAa,MAAMC,mBAAmBN,QAAQ;gBAC5Ca,QAAQjB,IAAIiB,MAAM;gBAClBjB;gBACAgB;YACF;QACF,EAAE,OAAOE,KAAK;YACZ,OAAOrB,WAAW;gBAChBe,QAAQZ,IAAIW,OAAO,CAACC,MAAM;gBAC1BM;gBACAlB;YACF;QACF;IACF;IAEA,OAAOmB,SAASC,IAAI,CAACX,YAAY;QAC/BY,SAASzB,gBAAgB;YACvByB,SAAS,IAAIC;YACbtB;QACF;QACAuB,QAAQ/B,WAAWgC,EAAE;IACvB;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restoreVersion.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/restoreVersion.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"restoreVersion.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/restoreVersion.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAI3D,eAAO,MAAM,cAAc,EAAE,wBAwB5B,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import httpStatus from 'http-status';
|
|
2
2
|
import { restoreVersionOperationGlobal } from 'payload/operations';
|
|
3
3
|
import { isNumber } from 'payload/utilities';
|
|
4
|
+
import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
4
5
|
export const restoreVersion = async ({ id, globalConfig, req })=>{
|
|
5
6
|
const { searchParams } = req;
|
|
6
7
|
const depth = searchParams.get('depth');
|
|
@@ -14,6 +15,10 @@ export const restoreVersion = async ({ id, globalConfig, req })=>{
|
|
|
14
15
|
doc,
|
|
15
16
|
message: req.t('version:restoredSuccessfully')
|
|
16
17
|
}, {
|
|
18
|
+
headers: headersWithCors({
|
|
19
|
+
headers: new Headers(),
|
|
20
|
+
req
|
|
21
|
+
}),
|
|
17
22
|
status: httpStatus.OK
|
|
18
23
|
});
|
|
19
24
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/globals/restoreVersion.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { restoreVersionOperationGlobal } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { GlobalRouteHandlerWithID } from '../types.js'\n\nexport const restoreVersion: GlobalRouteHandlerWithID = async ({ id, globalConfig, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const doc = await restoreVersionOperationGlobal({\n id,\n depth: isNumber(depth) ? Number(depth) : undefined,\n globalConfig,\n req,\n })\n\n return Response.json(\n {\n doc,\n message: req.t('version:restoredSuccessfully'),\n },\n {\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","restoreVersionOperationGlobal","isNumber","restoreVersion","id","globalConfig","req","searchParams","depth","get","doc","Number","undefined","Response","json","message","t","status","OK"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/globals/restoreVersion.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { restoreVersionOperationGlobal } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { GlobalRouteHandlerWithID } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const restoreVersion: GlobalRouteHandlerWithID = async ({ id, globalConfig, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const doc = await restoreVersionOperationGlobal({\n id,\n depth: isNumber(depth) ? Number(depth) : undefined,\n globalConfig,\n req,\n })\n\n return Response.json(\n {\n doc,\n message: req.t('version:restoredSuccessfully'),\n },\n {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","restoreVersionOperationGlobal","isNumber","headersWithCors","restoreVersion","id","globalConfig","req","searchParams","depth","get","doc","Number","undefined","Response","json","message","t","headers","Headers","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,6BAA6B,QAAQ,qBAAoB;AAClE,SAASC,QAAQ,QAAQ,oBAAmB;AAI5C,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,iBAA2C,OAAO,EAAEC,EAAE,EAAEC,YAAY,EAAEC,GAAG,EAAE;IACtF,MAAM,EAAEC,YAAY,EAAE,GAAGD;IACzB,MAAME,QAAQD,aAAaE,GAAG,CAAC;IAE/B,MAAMC,MAAM,MAAMV,8BAA8B;QAC9CI;QACAI,OAAOP,SAASO,SAASG,OAAOH,SAASI;QACzCP;QACAC;IACF;IAEA,OAAOO,SAASC,IAAI,CAClB;QACEJ;QACAK,SAAST,IAAIU,CAAC,CAAC;IACjB,GACA;QACEC,SAASf,gBAAgB;YACvBe,SAAS,IAAIC;YACbZ;QACF;QACAa,QAAQpB,WAAWqB,EAAE;IACvB;AAEJ,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/update.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/update.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAIrD,eAAO,MAAM,MAAM,EAAE,kBAkCpB,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import httpStatus from 'http-status';
|
|
2
2
|
import { updateOperationGlobal } from 'payload/operations';
|
|
3
3
|
import { isNumber } from 'payload/utilities';
|
|
4
|
+
import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
4
5
|
export const update = async ({ globalConfig, req })=>{
|
|
5
6
|
const { searchParams } = req;
|
|
6
7
|
const depth = searchParams.get('depth');
|
|
@@ -22,6 +23,10 @@ export const update = async ({ globalConfig, req })=>{
|
|
|
22
23
|
message,
|
|
23
24
|
result
|
|
24
25
|
}, {
|
|
26
|
+
headers: headersWithCors({
|
|
27
|
+
headers: new Headers(),
|
|
28
|
+
req
|
|
29
|
+
}),
|
|
25
30
|
status: httpStatus.OK
|
|
26
31
|
});
|
|
27
32
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/globals/update.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { updateOperationGlobal } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { GlobalRouteHandler } from '../types.js'\n\nexport const update: GlobalRouteHandler = async ({ globalConfig, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n const draft = searchParams.get('draft') === 'true'\n const autosave = searchParams.get('autosave') === 'true'\n\n const result = await updateOperationGlobal({\n slug: globalConfig.slug,\n autosave,\n data: req.data,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft,\n globalConfig,\n req,\n })\n\n let message = req.t('general:updatedSuccessfully')\n\n if (draft) message = req.t('version:draftSavedSuccessfully')\n if (autosave) message = req.t('version:autosavedSuccessfully')\n\n return Response.json(\n {\n message,\n result,\n },\n {\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","updateOperationGlobal","isNumber","update","globalConfig","req","searchParams","depth","get","draft","autosave","result","slug","data","Number","undefined","message","t","Response","json","status","OK"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/globals/update.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { updateOperationGlobal } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { GlobalRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const update: GlobalRouteHandler = async ({ globalConfig, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n const draft = searchParams.get('draft') === 'true'\n const autosave = searchParams.get('autosave') === 'true'\n\n const result = await updateOperationGlobal({\n slug: globalConfig.slug,\n autosave,\n data: req.data,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft,\n globalConfig,\n req,\n })\n\n let message = req.t('general:updatedSuccessfully')\n\n if (draft) message = req.t('version:draftSavedSuccessfully')\n if (autosave) message = req.t('version:autosavedSuccessfully')\n\n return Response.json(\n {\n message,\n result,\n },\n {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","updateOperationGlobal","isNumber","headersWithCors","update","globalConfig","req","searchParams","depth","get","draft","autosave","result","slug","data","Number","undefined","message","t","Response","json","headers","Headers","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,qBAAqB,QAAQ,qBAAoB;AAC1D,SAASC,QAAQ,QAAQ,oBAAmB;AAI5C,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,SAA6B,OAAO,EAAEC,YAAY,EAAEC,GAAG,EAAE;IACpE,MAAM,EAAEC,YAAY,EAAE,GAAGD;IACzB,MAAME,QAAQD,aAAaE,GAAG,CAAC;IAC/B,MAAMC,QAAQH,aAAaE,GAAG,CAAC,aAAa;IAC5C,MAAME,WAAWJ,aAAaE,GAAG,CAAC,gBAAgB;IAElD,MAAMG,SAAS,MAAMX,sBAAsB;QACzCY,MAAMR,aAAaQ,IAAI;QACvBF;QACAG,MAAMR,IAAIQ,IAAI;QACdN,OAAON,SAASM,SAASO,OAAOP,SAASQ;QACzCN;QACAL;QACAC;IACF;IAEA,IAAIW,UAAUX,IAAIY,CAAC,CAAC;IAEpB,IAAIR,OAAOO,UAAUX,IAAIY,CAAC,CAAC;IAC3B,IAAIP,UAAUM,UAAUX,IAAIY,CAAC,CAAC;IAE9B,OAAOC,SAASC,IAAI,CAClB;QACEH;QACAL;IACF,GACA;QACES,SAASlB,gBAAgB;YACvBkB,SAAS,IAAIC;YACbhB;QACF;QACAiB,QAAQvB,WAAWwB,EAAE;IACvB;AAEJ,EAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SanitizedConfig } from 'payload/types';
|
|
2
|
+
export declare const OPTIONS: (config: Promise<SanitizedConfig> | SanitizedConfig) => (request: Request) => Promise<Response>;
|
|
2
3
|
export declare const GET: (config: Promise<SanitizedConfig> | SanitizedConfig) => (request: Request, { params: { slug } }: {
|
|
3
4
|
params: {
|
|
4
5
|
slug: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/routes/rest/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA4C,eAAe,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/routes/rest/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA4C,eAAe,EAAE,MAAM,eAAe,CAAA;AAoK9F,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,sBA4J5E,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,sBA8I5E,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,sBAqE5E,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,sBAqE5E,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import httpStatus from 'http-status';
|
|
2
2
|
import { match } from 'path-to-regexp';
|
|
3
3
|
import { createPayloadRequest } from '../../utilities/createPayloadRequest.js';
|
|
4
|
+
import { headersWithCors } from '../../utilities/headersWithCors.js';
|
|
4
5
|
import { access } from './auth/access.js';
|
|
5
6
|
import { forgotPassword } from './auth/forgotPassword.js';
|
|
6
7
|
import { init } from './auth/init.js';
|
|
@@ -14,6 +15,7 @@ import { unlock } from './auth/unlock.js';
|
|
|
14
15
|
import { verifyEmail } from './auth/verifyEmail.js';
|
|
15
16
|
import { buildFormState } from './buildFormState.js';
|
|
16
17
|
import { endpointsAreDisabled } from './checkEndpoints.js';
|
|
18
|
+
import { count } from './collections/count.js';
|
|
17
19
|
import { create } from './collections/create.js';
|
|
18
20
|
import { deleteDoc } from './collections/delete.js';
|
|
19
21
|
import { deleteByID } from './collections/deleteByID.js';
|
|
@@ -43,6 +45,7 @@ const endpoints = {
|
|
|
43
45
|
deleteByID
|
|
44
46
|
},
|
|
45
47
|
GET: {
|
|
48
|
+
count,
|
|
46
49
|
'doc-access-by-id': docAccess,
|
|
47
50
|
'doc-versions-by-id': findVersionByID,
|
|
48
51
|
find,
|
|
@@ -120,11 +123,37 @@ const handleCustomEndpoints = ({ endpoints, entitySlug, payloadRequest })=>{
|
|
|
120
123
|
}
|
|
121
124
|
return null;
|
|
122
125
|
};
|
|
123
|
-
const RouteNotFoundResponse = (slug)=>Response.json({
|
|
126
|
+
const RouteNotFoundResponse = ({ slug, req })=>Response.json({
|
|
124
127
|
message: `Route Not Found: "${slug.join('/')}"`
|
|
125
128
|
}, {
|
|
129
|
+
headers: headersWithCors({
|
|
130
|
+
headers: new Headers(),
|
|
131
|
+
req
|
|
132
|
+
}),
|
|
126
133
|
status: httpStatus.NOT_FOUND
|
|
127
134
|
});
|
|
135
|
+
export const OPTIONS = (config)=>async (request)=>{
|
|
136
|
+
let req;
|
|
137
|
+
try {
|
|
138
|
+
req = await createPayloadRequest({
|
|
139
|
+
config,
|
|
140
|
+
request
|
|
141
|
+
});
|
|
142
|
+
return Response.json({}, {
|
|
143
|
+
headers: headersWithCors({
|
|
144
|
+
headers: new Headers(),
|
|
145
|
+
req
|
|
146
|
+
}),
|
|
147
|
+
status: 200
|
|
148
|
+
});
|
|
149
|
+
} catch (error) {
|
|
150
|
+
return routeError({
|
|
151
|
+
config,
|
|
152
|
+
err: error,
|
|
153
|
+
req: req || request
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
};
|
|
128
157
|
export const GET = (config)=>async (request, { params: { slug } })=>{
|
|
129
158
|
const [slug1, slug2, slug3, slug4] = slug;
|
|
130
159
|
let req;
|
|
@@ -169,6 +198,7 @@ export const GET = (config)=>async (request, { params: { slug } })=>{
|
|
|
169
198
|
// /:collection/init
|
|
170
199
|
// /:collection/me
|
|
171
200
|
// /:collection/versions
|
|
201
|
+
// /:collection/count
|
|
172
202
|
res = await endpoints.collection.GET[slug2]({
|
|
173
203
|
collection,
|
|
174
204
|
req
|
|
@@ -269,12 +299,16 @@ export const GET = (config)=>async (request, { params: { slug } })=>{
|
|
|
269
299
|
payloadRequest: req
|
|
270
300
|
});
|
|
271
301
|
if (customEndpointResponse) return customEndpointResponse;
|
|
272
|
-
return RouteNotFoundResponse(
|
|
302
|
+
return RouteNotFoundResponse({
|
|
303
|
+
slug,
|
|
304
|
+
req
|
|
305
|
+
});
|
|
273
306
|
} catch (error) {
|
|
274
307
|
return routeError({
|
|
275
308
|
collection,
|
|
309
|
+
config,
|
|
276
310
|
err: error,
|
|
277
|
-
req
|
|
311
|
+
req: req || request
|
|
278
312
|
});
|
|
279
313
|
}
|
|
280
314
|
};
|
|
@@ -410,12 +444,16 @@ export const POST = (config)=>async (request, { params: { slug } })=>{
|
|
|
410
444
|
payloadRequest: req
|
|
411
445
|
});
|
|
412
446
|
if (customEndpointResponse) return customEndpointResponse;
|
|
413
|
-
return RouteNotFoundResponse(
|
|
447
|
+
return RouteNotFoundResponse({
|
|
448
|
+
slug,
|
|
449
|
+
req
|
|
450
|
+
});
|
|
414
451
|
} catch (error) {
|
|
415
452
|
return routeError({
|
|
416
453
|
collection,
|
|
454
|
+
config,
|
|
417
455
|
err: error,
|
|
418
|
-
req
|
|
456
|
+
req: req || request
|
|
419
457
|
});
|
|
420
458
|
}
|
|
421
459
|
};
|
|
@@ -475,12 +513,16 @@ export const DELETE = (config)=>async (request, { params: { slug } })=>{
|
|
|
475
513
|
payloadRequest: req
|
|
476
514
|
});
|
|
477
515
|
if (customEndpointResponse) return customEndpointResponse;
|
|
478
|
-
return RouteNotFoundResponse(
|
|
516
|
+
return RouteNotFoundResponse({
|
|
517
|
+
slug,
|
|
518
|
+
req
|
|
519
|
+
});
|
|
479
520
|
} catch (error) {
|
|
480
521
|
return routeError({
|
|
481
522
|
collection,
|
|
523
|
+
config,
|
|
482
524
|
err: error,
|
|
483
|
-
req
|
|
525
|
+
req: req || request
|
|
484
526
|
});
|
|
485
527
|
}
|
|
486
528
|
};
|
|
@@ -540,12 +582,16 @@ export const PATCH = (config)=>async (request, { params: { slug } })=>{
|
|
|
540
582
|
payloadRequest: req
|
|
541
583
|
});
|
|
542
584
|
if (customEndpointResponse) return customEndpointResponse;
|
|
543
|
-
return RouteNotFoundResponse(
|
|
585
|
+
return RouteNotFoundResponse({
|
|
586
|
+
slug,
|
|
587
|
+
req
|
|
588
|
+
});
|
|
544
589
|
} catch (error) {
|
|
545
590
|
return routeError({
|
|
546
591
|
collection,
|
|
592
|
+
config,
|
|
547
593
|
err: error,
|
|
548
|
-
req
|
|
594
|
+
req: req || request
|
|
549
595
|
});
|
|
550
596
|
}
|
|
551
597
|
};
|