@payloadcms/next 3.15.1 → 3.15.2-canary.595a742
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exports/utilities.d.ts +65 -5
- package/dist/exports/utilities.d.ts.map +1 -1
- package/dist/exports/utilities.js +49 -5
- package/dist/exports/utilities.js.map +1 -1
- package/dist/layouts/Root/index.d.ts.map +1 -1
- package/dist/layouts/Root/index.js +7 -2
- package/dist/layouts/Root/index.js.map +1 -1
- package/dist/routes/graphql/handler.d.ts.map +1 -1
- package/dist/routes/graphql/handler.js +1 -6
- package/dist/routes/graphql/handler.js.map +1 -1
- package/dist/routes/graphql/playground.d.ts +1 -1
- package/dist/routes/graphql/playground.d.ts.map +1 -1
- package/dist/routes/graphql/playground.js +1 -1
- package/dist/routes/graphql/playground.js.map +1 -1
- package/dist/routes/rest/index.d.ts +6 -26
- package/dist/routes/rest/index.d.ts.map +1 -1
- package/dist/routes/rest/index.js +25 -820
- package/dist/routes/rest/index.js.map +1 -1
- package/dist/routes/rest/og/index.d.ts +2 -8
- package/dist/routes/rest/og/index.d.ts.map +1 -1
- package/dist/routes/rest/og/index.js +3 -6
- package/dist/routes/rest/og/index.js.map +1 -1
- package/dist/utilities/getNextRequestI18n.d.ts +1 -1
- package/dist/utilities/getNextRequestI18n.d.ts.map +1 -1
- package/dist/utilities/getNextRequestI18n.js +1 -1
- package/dist/utilities/getNextRequestI18n.js.map +1 -1
- package/dist/utilities/getPayloadHMR.d.ts +8 -0
- package/dist/utilities/getPayloadHMR.d.ts.map +1 -1
- package/dist/utilities/getPayloadHMR.js +8 -0
- package/dist/utilities/getPayloadHMR.js.map +1 -1
- package/dist/utilities/getPreference.d.ts +3 -0
- package/dist/utilities/getPreference.d.ts.map +1 -0
- package/dist/utilities/getPreference.js +29 -0
- package/dist/utilities/getPreference.js.map +1 -0
- package/dist/utilities/getRequestLocale.d.ts +9 -0
- package/dist/utilities/getRequestLocale.d.ts.map +1 -0
- package/dist/utilities/getRequestLocale.js +13 -0
- package/dist/utilities/getRequestLocale.js.map +1 -0
- package/dist/utilities/initPage/index.d.ts.map +1 -1
- package/dist/utilities/initPage/index.js +7 -38
- package/dist/utilities/initPage/index.js.map +1 -1
- package/dist/utilities/initReq.d.ts.map +1 -1
- package/dist/utilities/initReq.js +1 -2
- package/dist/utilities/initReq.js.map +1 -1
- package/dist/views/List/handleServerFunction.d.ts +1 -2
- package/dist/views/List/handleServerFunction.d.ts.map +1 -1
- package/dist/views/List/handleServerFunction.js.map +1 -1
- package/dist/views/List/index.d.ts.map +1 -1
- package/dist/views/List/index.js.map +1 -1
- package/dist/views/Root/index.d.ts.map +1 -1
- package/dist/views/Root/index.js.map +1 -1
- package/package.json +7 -7
- package/dist/fetchAPI-multipart/fileFactory.d.ts +0 -16
- package/dist/fetchAPI-multipart/fileFactory.d.ts.map +0 -1
- package/dist/fetchAPI-multipart/fileFactory.js +0 -44
- package/dist/fetchAPI-multipart/fileFactory.js.map +0 -1
- package/dist/fetchAPI-multipart/handlers.d.ts +0 -14
- package/dist/fetchAPI-multipart/handlers.d.ts.map +0 -1
- package/dist/fetchAPI-multipart/handlers.js +0 -87
- package/dist/fetchAPI-multipart/handlers.js.map +0 -1
- package/dist/fetchAPI-multipart/index.d.ts +0 -32
- package/dist/fetchAPI-multipart/index.d.ts.map +0 -1
- package/dist/fetchAPI-multipart/index.js +0 -43
- package/dist/fetchAPI-multipart/index.js.map +0 -1
- package/dist/fetchAPI-multipart/isEligibleRequest.d.ts +0 -2
- package/dist/fetchAPI-multipart/isEligibleRequest.d.ts.map +0 -1
- package/dist/fetchAPI-multipart/isEligibleRequest.js +0 -18
- package/dist/fetchAPI-multipart/isEligibleRequest.js.map +0 -1
- package/dist/fetchAPI-multipart/processMultipart.d.ts +0 -9
- package/dist/fetchAPI-multipart/processMultipart.d.ts.map +0 -1
- package/dist/fetchAPI-multipart/processMultipart.js +0 -178
- package/dist/fetchAPI-multipart/processMultipart.js.map +0 -1
- package/dist/fetchAPI-multipart/processNested.d.ts +0 -2
- package/dist/fetchAPI-multipart/processNested.d.ts.map +0 -1
- package/dist/fetchAPI-multipart/processNested.js +0 -31
- package/dist/fetchAPI-multipart/processNested.js.map +0 -1
- package/dist/fetchAPI-multipart/uploadTimer.d.ts +0 -7
- package/dist/fetchAPI-multipart/uploadTimer.d.ts.map +0 -1
- package/dist/fetchAPI-multipart/uploadTimer.js +0 -20
- package/dist/fetchAPI-multipart/uploadTimer.js.map +0 -1
- package/dist/fetchAPI-multipart/utilities.d.ts +0 -65
- package/dist/fetchAPI-multipart/utilities.d.ts.map +0 -1
- package/dist/fetchAPI-multipart/utilities.js +0 -227
- package/dist/fetchAPI-multipart/utilities.js.map +0 -1
- package/dist/fetchAPI-stream-file/index.d.ts +0 -5
- package/dist/fetchAPI-stream-file/index.d.ts.map +0 -1
- package/dist/fetchAPI-stream-file/index.js +0 -27
- package/dist/fetchAPI-stream-file/index.js.map +0 -1
- package/dist/routes/rest/auth/access.d.ts +0 -3
- package/dist/routes/rest/auth/access.d.ts.map +0 -1
- package/dist/routes/rest/auth/access.js +0 -28
- package/dist/routes/rest/auth/access.js.map +0 -1
- package/dist/routes/rest/auth/forgotPassword.d.ts +0 -3
- package/dist/routes/rest/auth/forgotPassword.d.ts.map +0 -1
- package/dist/routes/rest/auth/forgotPassword.js +0 -34
- package/dist/routes/rest/auth/forgotPassword.js.map +0 -1
- package/dist/routes/rest/auth/init.d.ts +0 -3
- package/dist/routes/rest/auth/init.d.ts.map +0 -1
- package/dist/routes/rest/auth/init.js +0 -20
- package/dist/routes/rest/auth/init.js.map +0 -1
- package/dist/routes/rest/auth/login.d.ts +0 -3
- package/dist/routes/rest/auth/login.d.ts.map +0 -1
- package/dist/routes/rest/auth/login.js +0 -49
- package/dist/routes/rest/auth/login.js.map +0 -1
- package/dist/routes/rest/auth/logout.d.ts +0 -3
- package/dist/routes/rest/auth/logout.d.ts.map +0 -1
- package/dist/routes/rest/auth/logout.js +0 -40
- package/dist/routes/rest/auth/logout.js.map +0 -1
- package/dist/routes/rest/auth/me.d.ts +0 -3
- package/dist/routes/rest/auth/me.d.ts.map +0 -1
- package/dist/routes/rest/auth/me.js +0 -28
- package/dist/routes/rest/auth/me.js.map +0 -1
- package/dist/routes/rest/auth/refresh.d.ts +0 -3
- package/dist/routes/rest/auth/refresh.d.ts.map +0 -1
- package/dist/routes/rest/auth/refresh.js +0 -38
- package/dist/routes/rest/auth/refresh.js.map +0 -1
- package/dist/routes/rest/auth/registerFirstUser.d.ts +0 -3
- package/dist/routes/rest/auth/registerFirstUser.d.ts.map +0 -1
- package/dist/routes/rest/auth/registerFirstUser.js +0 -48
- package/dist/routes/rest/auth/registerFirstUser.js.map +0 -1
- package/dist/routes/rest/auth/resetPassword.d.ts +0 -3
- package/dist/routes/rest/auth/resetPassword.d.ts.map +0 -1
- package/dist/routes/rest/auth/resetPassword.js +0 -43
- package/dist/routes/rest/auth/resetPassword.js.map +0 -1
- package/dist/routes/rest/auth/unlock.d.ts +0 -3
- package/dist/routes/rest/auth/unlock.d.ts.map +0 -1
- package/dist/routes/rest/auth/unlock.js +0 -32
- package/dist/routes/rest/auth/unlock.js.map +0 -1
- package/dist/routes/rest/auth/verifyEmail.d.ts +0 -3
- package/dist/routes/rest/auth/verifyEmail.d.ts.map +0 -1
- package/dist/routes/rest/auth/verifyEmail.js +0 -27
- package/dist/routes/rest/auth/verifyEmail.js.map +0 -1
- package/dist/routes/rest/checkEndpoints.d.ts +0 -5
- package/dist/routes/rest/checkEndpoints.d.ts.map +0 -1
- package/dist/routes/rest/checkEndpoints.js +0 -14
- package/dist/routes/rest/checkEndpoints.js.map +0 -1
- package/dist/routes/rest/collections/count.d.ts +0 -3
- package/dist/routes/rest/collections/count.d.ts.map +0 -1
- package/dist/routes/rest/collections/count.js +0 -19
- package/dist/routes/rest/collections/count.js.map +0 -1
- package/dist/routes/rest/collections/create.d.ts +0 -3
- package/dist/routes/rest/collections/create.d.ts.map +0 -1
- package/dist/routes/rest/collections/create.js +0 -39
- package/dist/routes/rest/collections/create.js.map +0 -1
- package/dist/routes/rest/collections/delete.d.ts +0 -3
- package/dist/routes/rest/collections/delete.d.ts.map +0 -1
- package/dist/routes/rest/collections/delete.js +0 -57
- package/dist/routes/rest/collections/delete.js.map +0 -1
- package/dist/routes/rest/collections/deleteByID.d.ts +0 -3
- package/dist/routes/rest/collections/deleteByID.d.ts.map +0 -1
- package/dist/routes/rest/collections/deleteByID.js +0 -50
- package/dist/routes/rest/collections/deleteByID.js.map +0 -1
- package/dist/routes/rest/collections/docAccess.d.ts +0 -3
- package/dist/routes/rest/collections/docAccess.d.ts.map +0 -1
- package/dist/routes/rest/collections/docAccess.js +0 -22
- package/dist/routes/rest/collections/docAccess.js.map +0 -1
- package/dist/routes/rest/collections/duplicate.d.ts +0 -3
- package/dist/routes/rest/collections/duplicate.d.ts.map +0 -1
- package/dist/routes/rest/collections/duplicate.js +0 -47
- package/dist/routes/rest/collections/duplicate.js.map +0 -1
- package/dist/routes/rest/collections/find.d.ts +0 -3
- package/dist/routes/rest/collections/find.d.ts.map +0 -1
- package/dist/routes/rest/collections/find.js +0 -43
- package/dist/routes/rest/collections/find.js.map +0 -1
- package/dist/routes/rest/collections/findByID.d.ts +0 -3
- package/dist/routes/rest/collections/findByID.d.ts.map +0 -1
- package/dist/routes/rest/collections/findByID.js +0 -38
- package/dist/routes/rest/collections/findByID.js.map +0 -1
- package/dist/routes/rest/collections/findVersionByID.d.ts +0 -3
- package/dist/routes/rest/collections/findVersionByID.d.ts.map +0 -1
- package/dist/routes/rest/collections/findVersionByID.js +0 -36
- package/dist/routes/rest/collections/findVersionByID.js.map +0 -1
- package/dist/routes/rest/collections/findVersions.d.ts +0 -3
- package/dist/routes/rest/collections/findVersions.d.ts.map +0 -1
- package/dist/routes/rest/collections/findVersions.js +0 -39
- package/dist/routes/rest/collections/findVersions.js.map +0 -1
- package/dist/routes/rest/collections/preview.d.ts +0 -3
- package/dist/routes/rest/collections/preview.d.ts.map +0 -1
- package/dist/routes/rest/collections/preview.js +0 -49
- package/dist/routes/rest/collections/preview.js.map +0 -1
- package/dist/routes/rest/collections/restoreVersion.d.ts +0 -3
- package/dist/routes/rest/collections/restoreVersion.d.ts.map +0 -1
- package/dist/routes/rest/collections/restoreVersion.js +0 -40
- package/dist/routes/rest/collections/restoreVersion.js.map +0 -1
- package/dist/routes/rest/collections/update.d.ts +0 -3
- package/dist/routes/rest/collections/update.d.ts.map +0 -1
- package/dist/routes/rest/collections/update.js +0 -62
- package/dist/routes/rest/collections/update.js.map +0 -1
- package/dist/routes/rest/collections/updateByID.d.ts +0 -3
- package/dist/routes/rest/collections/updateByID.d.ts.map +0 -1
- package/dist/routes/rest/collections/updateByID.js +0 -55
- package/dist/routes/rest/collections/updateByID.js.map +0 -1
- package/dist/routes/rest/files/checkFileAccess.d.ts +0 -7
- package/dist/routes/rest/files/checkFileAccess.d.ts.map +0 -1
- package/dist/routes/rest/files/checkFileAccess.js +0 -57
- package/dist/routes/rest/files/checkFileAccess.js.map +0 -1
- package/dist/routes/rest/files/getFile.d.ts +0 -9
- package/dist/routes/rest/files/getFile.d.ts.map +0 -1
- package/dist/routes/rest/files/getFile.js +0 -70
- package/dist/routes/rest/files/getFile.js.map +0 -1
- package/dist/routes/rest/files/getFileTypeFallback.d.ts +0 -7
- package/dist/routes/rest/files/getFileTypeFallback.d.ts.map +0 -1
- package/dist/routes/rest/files/getFileTypeFallback.js +0 -20
- package/dist/routes/rest/files/getFileTypeFallback.js.map +0 -1
- package/dist/routes/rest/globals/docAccess.d.ts +0 -3
- package/dist/routes/rest/globals/docAccess.d.ts.map +0 -1
- package/dist/routes/rest/globals/docAccess.js +0 -20
- package/dist/routes/rest/globals/docAccess.js.map +0 -1
- package/dist/routes/rest/globals/findOne.d.ts +0 -3
- package/dist/routes/rest/globals/findOne.d.ts.map +0 -1
- package/dist/routes/rest/globals/findOne.js +0 -30
- package/dist/routes/rest/globals/findOne.js.map +0 -1
- package/dist/routes/rest/globals/findVersionByID.d.ts +0 -3
- package/dist/routes/rest/globals/findVersionByID.d.ts.map +0 -1
- package/dist/routes/rest/globals/findVersionByID.js +0 -30
- package/dist/routes/rest/globals/findVersionByID.js.map +0 -1
- package/dist/routes/rest/globals/findVersions.d.ts +0 -3
- package/dist/routes/rest/globals/findVersions.d.ts.map +0 -1
- package/dist/routes/rest/globals/findVersions.js +0 -39
- package/dist/routes/rest/globals/findVersions.js.map +0 -1
- package/dist/routes/rest/globals/preview.d.ts +0 -3
- package/dist/routes/rest/globals/preview.d.ts.map +0 -1
- package/dist/routes/rest/globals/preview.js +0 -47
- package/dist/routes/rest/globals/preview.js.map +0 -1
- package/dist/routes/rest/globals/restoreVersion.d.ts +0 -3
- package/dist/routes/rest/globals/restoreVersion.d.ts.map +0 -1
- package/dist/routes/rest/globals/restoreVersion.js +0 -34
- package/dist/routes/rest/globals/restoreVersion.js.map +0 -1
- package/dist/routes/rest/globals/update.d.ts +0 -3
- package/dist/routes/rest/globals/update.d.ts.map +0 -1
- package/dist/routes/rest/globals/update.js +0 -46
- package/dist/routes/rest/globals/update.js.map +0 -1
- package/dist/routes/rest/routeError.d.ts +0 -9
- package/dist/routes/rest/routeError.d.ts.map +0 -1
- package/dist/routes/rest/routeError.js +0 -83
- package/dist/routes/rest/routeError.js.map +0 -1
- package/dist/routes/rest/types.d.ts +0 -23
- package/dist/routes/rest/types.d.ts.map +0 -1
- package/dist/routes/rest/types.js +0 -2
- package/dist/routes/rest/types.js.map +0 -1
- package/dist/routes/rest/utilities/sanitizeCollectionID.d.ts +0 -9
- package/dist/routes/rest/utilities/sanitizeCollectionID.d.ts.map +0 -1
- package/dist/routes/rest/utilities/sanitizeCollectionID.js +0 -20
- package/dist/routes/rest/utilities/sanitizeCollectionID.js.map +0 -1
- package/dist/utilities/addDataAndFileToRequest.d.ts +0 -8
- package/dist/utilities/addDataAndFileToRequest.d.ts.map +0 -1
- package/dist/utilities/addDataAndFileToRequest.js +0 -47
- package/dist/utilities/addDataAndFileToRequest.js.map +0 -1
- package/dist/utilities/addLocalesToRequest.d.ts +0 -17
- package/dist/utilities/addLocalesToRequest.d.ts.map +0 -1
- package/dist/utilities/addLocalesToRequest.js +0 -65
- package/dist/utilities/addLocalesToRequest.js.map +0 -1
- package/dist/utilities/createPayloadRequest.d.ts +0 -11
- package/dist/utilities/createPayloadRequest.d.ts.map +0 -1
- package/dist/utilities/createPayloadRequest.js +0 -103
- package/dist/utilities/createPayloadRequest.js.map +0 -1
- package/dist/utilities/getRequestLanguage.d.ts +0 -12
- package/dist/utilities/getRequestLanguage.d.ts.map +0 -1
- package/dist/utilities/getRequestLanguage.js +0 -19
- package/dist/utilities/getRequestLanguage.js.map +0 -1
- package/dist/utilities/getRequestLocales.d.ts +0 -12
- package/dist/utilities/getRequestLocales.d.ts.map +0 -1
- package/dist/utilities/getRequestLocales.js +0 -35
- package/dist/utilities/getRequestLocales.js.map +0 -1
- package/dist/utilities/headersWithCors.d.ts +0 -8
- package/dist/utilities/headersWithCors.d.ts.map +0 -1
- package/dist/utilities/headersWithCors.js +0 -24
- package/dist/utilities/headersWithCors.js.map +0 -1
- package/dist/utilities/mergeHeaders.d.ts +0 -2
- package/dist/utilities/mergeHeaders.d.ts.map +0 -1
- package/dist/utilities/mergeHeaders.js +0 -10
- package/dist/utilities/mergeHeaders.js.map +0 -1
|
@@ -1,822 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { match } from 'path-to-regexp';
|
|
3
|
-
import { addDataAndFileToRequest } from '../../utilities/addDataAndFileToRequest.js';
|
|
4
|
-
import { addLocalesToRequestFromData } from '../../utilities/addLocalesToRequest.js';
|
|
5
|
-
import { createPayloadRequest } from '../../utilities/createPayloadRequest.js';
|
|
6
|
-
import { headersWithCors } from '../../utilities/headersWithCors.js';
|
|
7
|
-
import { mergeHeaders } from '../../utilities/mergeHeaders.js';
|
|
8
|
-
import { access } from './auth/access.js';
|
|
9
|
-
import { forgotPassword } from './auth/forgotPassword.js';
|
|
10
|
-
import { init } from './auth/init.js';
|
|
11
|
-
import { login } from './auth/login.js';
|
|
12
|
-
import { logout } from './auth/logout.js';
|
|
13
|
-
import { me } from './auth/me.js';
|
|
14
|
-
import { refresh } from './auth/refresh.js';
|
|
15
|
-
import { registerFirstUser } from './auth/registerFirstUser.js';
|
|
16
|
-
import { resetPassword } from './auth/resetPassword.js';
|
|
17
|
-
import { unlock } from './auth/unlock.js';
|
|
18
|
-
import { verifyEmail } from './auth/verifyEmail.js';
|
|
19
|
-
import { endpointsAreDisabled } from './checkEndpoints.js';
|
|
20
|
-
import { count } from './collections/count.js';
|
|
21
|
-
import { create } from './collections/create.js';
|
|
22
|
-
import { deleteDoc } from './collections/delete.js';
|
|
23
|
-
import { deleteByID } from './collections/deleteByID.js';
|
|
24
|
-
import { docAccess } from './collections/docAccess.js';
|
|
25
|
-
import { duplicate } from './collections/duplicate.js';
|
|
26
|
-
import { find } from './collections/find.js';
|
|
27
|
-
import { findByID } from './collections/findByID.js';
|
|
28
|
-
import { findVersionByID } from './collections/findVersionByID.js';
|
|
29
|
-
import { findVersions } from './collections/findVersions.js';
|
|
30
|
-
import { preview as previewCollection } from './collections/preview.js';
|
|
31
|
-
import { restoreVersion } from './collections/restoreVersion.js';
|
|
32
|
-
import { update } from './collections/update.js';
|
|
33
|
-
import { updateByID } from './collections/updateByID.js';
|
|
34
|
-
import { getFile } from './files/getFile.js';
|
|
35
|
-
import { docAccess as docAccessGlobal } from './globals/docAccess.js';
|
|
36
|
-
import { findOne } from './globals/findOne.js';
|
|
37
|
-
import { findVersionByID as findVersionByIdGlobal } from './globals/findVersionByID.js';
|
|
38
|
-
import { findVersions as findVersionsGlobal } from './globals/findVersions.js';
|
|
39
|
-
import { preview as previewGlobal } from './globals/preview.js';
|
|
40
|
-
import { restoreVersion as restoreVersionGlobal } from './globals/restoreVersion.js';
|
|
41
|
-
import { update as updateGlobal } from './globals/update.js';
|
|
1
|
+
import { handleEndpoints } from 'payload';
|
|
42
2
|
import { generateOGImage } from './og/index.js';
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
access: docAccess,
|
|
68
|
-
create,
|
|
69
|
-
'doc-access-by-id': docAccess,
|
|
70
|
-
'doc-verify-by-id': verifyEmail,
|
|
71
|
-
'doc-versions-by-id': restoreVersion,
|
|
72
|
-
duplicate,
|
|
73
|
-
'first-register': registerFirstUser,
|
|
74
|
-
'forgot-password': forgotPassword,
|
|
75
|
-
login,
|
|
76
|
-
logout,
|
|
77
|
-
'refresh-token': refresh,
|
|
78
|
-
'reset-password': resetPassword,
|
|
79
|
-
unlock
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
global: {
|
|
83
|
-
GET: {
|
|
84
|
-
'doc-access': docAccessGlobal,
|
|
85
|
-
'doc-versions': findVersionsGlobal,
|
|
86
|
-
'doc-versions-by-id': findVersionByIdGlobal,
|
|
87
|
-
findOne,
|
|
88
|
-
preview: previewGlobal
|
|
89
|
-
},
|
|
90
|
-
POST: {
|
|
91
|
-
'doc-access': docAccessGlobal,
|
|
92
|
-
'doc-versions-by-id': restoreVersionGlobal,
|
|
93
|
-
update: updateGlobal
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
root: {
|
|
97
|
-
GET: {
|
|
98
|
-
access,
|
|
99
|
-
og: generateOGImage
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
const handleCustomEndpoints = async ({
|
|
104
|
-
endpoints,
|
|
105
|
-
entitySlug,
|
|
106
|
-
req
|
|
107
|
-
}) => {
|
|
108
|
-
if (endpoints && endpoints.length > 0) {
|
|
109
|
-
let handlerParams = {};
|
|
110
|
-
const {
|
|
111
|
-
pathname
|
|
112
|
-
} = req;
|
|
113
|
-
/*
|
|
114
|
-
* This makes sure the next.js basePath property is supported. If basePath is used, payload config.routes.api should include it. This makes all outgoing frontend request
|
|
115
|
-
* target the correct API endpoint starting with basePath, which is good!
|
|
116
|
-
*
|
|
117
|
-
* The incoming request (here) will not include the basePath though, as it's automatically stripped by Next.js. Since we are adding the basePath to the pathPrefix below though
|
|
118
|
-
* (from req.payload.config.routes.api) we need to add it to pathname, which does not contain the basePath. Otherwise, no endpoint will be matched if basePath is set.
|
|
119
|
-
*/
|
|
120
|
-
let adjustedPathname = pathname;
|
|
121
|
-
if (process.env.NEXT_BASE_PATH) {
|
|
122
|
-
adjustedPathname = process.env.NEXT_BASE_PATH + pathname;
|
|
123
|
-
}
|
|
124
|
-
const pathPrefix = req.payload.config.routes.api + (entitySlug ? `/${entitySlug}` : '');
|
|
125
|
-
const customEndpoint = endpoints.find(endpoint => {
|
|
126
|
-
if (endpoint.method === req.method.toLowerCase()) {
|
|
127
|
-
const pathMatchFn = match(`${pathPrefix}${endpoint.path}`, {
|
|
128
|
-
decode: decodeURIComponent
|
|
129
|
-
});
|
|
130
|
-
const tempParams = pathMatchFn(adjustedPathname);
|
|
131
|
-
if (tempParams) {
|
|
132
|
-
handlerParams = tempParams.params;
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
if (customEndpoint) {
|
|
138
|
-
req.routeParams = {
|
|
139
|
-
...req.routeParams,
|
|
140
|
-
...handlerParams
|
|
141
|
-
};
|
|
142
|
-
const res = await customEndpoint.handler(req);
|
|
143
|
-
if (res instanceof Response) {
|
|
144
|
-
if (req.responseHeaders) {
|
|
145
|
-
const mergedResponse = new Response(res.body, {
|
|
146
|
-
headers: mergeHeaders(req.responseHeaders, res.headers),
|
|
147
|
-
status: res.status,
|
|
148
|
-
statusText: res.statusText
|
|
149
|
-
});
|
|
150
|
-
return mergedResponse;
|
|
151
|
-
}
|
|
152
|
-
return res;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return null;
|
|
157
|
-
};
|
|
158
|
-
const RouteNotFoundResponse = ({
|
|
159
|
-
slug,
|
|
160
|
-
req
|
|
161
|
-
}) => Response.json({
|
|
162
|
-
message: `Route Not Found: "${slug.join('/')}"`
|
|
163
|
-
}, {
|
|
164
|
-
headers: headersWithCors({
|
|
165
|
-
headers: new Headers(),
|
|
166
|
-
req
|
|
167
|
-
}),
|
|
168
|
-
status: httpStatus.NOT_FOUND
|
|
169
|
-
});
|
|
170
|
-
export const OPTIONS = config => async request => {
|
|
171
|
-
let req;
|
|
172
|
-
try {
|
|
173
|
-
req = await createPayloadRequest({
|
|
174
|
-
config,
|
|
175
|
-
request
|
|
176
|
-
});
|
|
177
|
-
return Response.json({}, {
|
|
178
|
-
headers: headersWithCors({
|
|
179
|
-
headers: new Headers(),
|
|
180
|
-
req
|
|
181
|
-
}),
|
|
182
|
-
status: 200
|
|
183
|
-
});
|
|
184
|
-
} catch (error) {
|
|
185
|
-
return routeError({
|
|
186
|
-
config,
|
|
187
|
-
err: error,
|
|
188
|
-
req: req || request
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
export const GET = config => async (request, {
|
|
193
|
-
params: paramsPromise
|
|
194
|
-
}) => {
|
|
195
|
-
const {
|
|
196
|
-
slug
|
|
197
|
-
} = await paramsPromise;
|
|
198
|
-
const [slug1, slug2, slug3, slug4] = slug;
|
|
199
|
-
let req;
|
|
200
|
-
let res;
|
|
201
|
-
let collection;
|
|
202
|
-
try {
|
|
203
|
-
req = await createPayloadRequest({
|
|
204
|
-
config,
|
|
205
|
-
request
|
|
206
|
-
});
|
|
207
|
-
const disableEndpoints = endpointsAreDisabled({
|
|
208
|
-
endpoints: req.payload.config.endpoints,
|
|
209
|
-
request
|
|
210
|
-
});
|
|
211
|
-
if (disableEndpoints) {
|
|
212
|
-
return disableEndpoints;
|
|
213
|
-
}
|
|
214
|
-
collection = req.payload.collections?.[slug1];
|
|
215
|
-
if (collection) {
|
|
216
|
-
req.routeParams.collection = slug1;
|
|
217
|
-
const disableEndpoints = endpointsAreDisabled({
|
|
218
|
-
endpoints: collection.config.endpoints,
|
|
219
|
-
request
|
|
220
|
-
});
|
|
221
|
-
if (disableEndpoints) {
|
|
222
|
-
return disableEndpoints;
|
|
223
|
-
}
|
|
224
|
-
const customEndpointResponse = await handleCustomEndpoints({
|
|
225
|
-
endpoints: collection.config.endpoints,
|
|
226
|
-
entitySlug: slug1,
|
|
227
|
-
req
|
|
228
|
-
});
|
|
229
|
-
if (customEndpointResponse) {
|
|
230
|
-
return customEndpointResponse;
|
|
231
|
-
} else {
|
|
232
|
-
await addDataAndFileToRequest(req);
|
|
233
|
-
addLocalesToRequestFromData(req);
|
|
234
|
-
switch (slug.length) {
|
|
235
|
-
case 1:
|
|
236
|
-
// /:collection
|
|
237
|
-
res = await endpoints.collection.GET.find({
|
|
238
|
-
collection,
|
|
239
|
-
req
|
|
240
|
-
});
|
|
241
|
-
break;
|
|
242
|
-
case 2:
|
|
243
|
-
if (slug2 in endpoints.collection.GET) {
|
|
244
|
-
// /:collection/init
|
|
245
|
-
// /:collection/me
|
|
246
|
-
// /:collection/versions
|
|
247
|
-
// /:collection/count
|
|
248
|
-
res = await endpoints.collection.GET[slug2]({
|
|
249
|
-
collection,
|
|
250
|
-
req
|
|
251
|
-
});
|
|
252
|
-
} else {
|
|
253
|
-
// /:collection/:id
|
|
254
|
-
res = await endpoints.collection.GET.findByID({
|
|
255
|
-
id: slug2,
|
|
256
|
-
collection,
|
|
257
|
-
req
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
break;
|
|
261
|
-
case 3:
|
|
262
|
-
if (slug2 === 'file') {
|
|
263
|
-
// /:collection/file/:filename
|
|
264
|
-
res = await endpoints.collection.GET.getFile({
|
|
265
|
-
collection,
|
|
266
|
-
filename: slug3,
|
|
267
|
-
req
|
|
268
|
-
});
|
|
269
|
-
} else if (slug3 in endpoints.collection.GET) {
|
|
270
|
-
// /:collection/:id/preview
|
|
271
|
-
res = await endpoints.collection.GET[slug3]({
|
|
272
|
-
id: slug2,
|
|
273
|
-
collection,
|
|
274
|
-
req
|
|
275
|
-
});
|
|
276
|
-
} else if (`doc-${slug2}-by-id` in endpoints.collection.GET) {
|
|
277
|
-
// /:collection/access/:id
|
|
278
|
-
// /:collection/versions/:id
|
|
279
|
-
res = await endpoints.collection.GET[`doc-${slug2}-by-id`]({
|
|
280
|
-
id: slug3,
|
|
281
|
-
collection,
|
|
282
|
-
req
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
break;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
} else if (slug1 === 'globals') {
|
|
289
|
-
const globalConfig = req.payload.config.globals.find(global => global.slug === slug2);
|
|
290
|
-
req.routeParams.global = globalConfig.slug;
|
|
291
|
-
const disableEndpoints = endpointsAreDisabled({
|
|
292
|
-
endpoints: globalConfig.endpoints,
|
|
293
|
-
request
|
|
294
|
-
});
|
|
295
|
-
if (disableEndpoints) {
|
|
296
|
-
return disableEndpoints;
|
|
297
|
-
}
|
|
298
|
-
const customEndpointResponse = await handleCustomEndpoints({
|
|
299
|
-
endpoints: globalConfig.endpoints,
|
|
300
|
-
entitySlug: `${slug1}/${slug2}`,
|
|
301
|
-
req
|
|
302
|
-
});
|
|
303
|
-
if (customEndpointResponse) {
|
|
304
|
-
return customEndpointResponse;
|
|
305
|
-
} else {
|
|
306
|
-
await addDataAndFileToRequest(req);
|
|
307
|
-
addLocalesToRequestFromData(req);
|
|
308
|
-
switch (slug.length) {
|
|
309
|
-
case 2:
|
|
310
|
-
// /globals/:slug
|
|
311
|
-
res = await endpoints.global.GET.findOne({
|
|
312
|
-
globalConfig,
|
|
313
|
-
req
|
|
314
|
-
});
|
|
315
|
-
break;
|
|
316
|
-
case 3:
|
|
317
|
-
if (slug3 in endpoints.global.GET) {
|
|
318
|
-
// /globals/:slug/preview
|
|
319
|
-
res = await endpoints.global.GET[slug3]({
|
|
320
|
-
globalConfig,
|
|
321
|
-
req
|
|
322
|
-
});
|
|
323
|
-
} else if (`doc-${slug3}` in endpoints.global.GET) {
|
|
324
|
-
// /globals/:slug/access
|
|
325
|
-
// /globals/:slug/versions
|
|
326
|
-
// /globals/:slug/preview
|
|
327
|
-
res = await (endpoints.global.GET?.[`doc-${slug3}`])({
|
|
328
|
-
globalConfig,
|
|
329
|
-
req
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
break;
|
|
333
|
-
case 4:
|
|
334
|
-
if (`doc-${slug3}-by-id` in endpoints.global.GET) {
|
|
335
|
-
// /globals/:slug/versions/:id
|
|
336
|
-
res = await (endpoints.global.GET?.[`doc-${slug3}-by-id`])({
|
|
337
|
-
id: slug4,
|
|
338
|
-
globalConfig,
|
|
339
|
-
req
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
break;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
} else if (slug.length === 1 && slug1 in endpoints.root.GET) {
|
|
346
|
-
await addDataAndFileToRequest(req);
|
|
347
|
-
addLocalesToRequestFromData(req);
|
|
348
|
-
res = await endpoints.root.GET[slug1]({
|
|
349
|
-
req
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
if (res instanceof Response) {
|
|
353
|
-
if (req.responseHeaders) {
|
|
354
|
-
const mergedResponse = new Response(res.body, {
|
|
355
|
-
headers: mergeHeaders(req.responseHeaders, res.headers),
|
|
356
|
-
status: res.status,
|
|
357
|
-
statusText: res.statusText
|
|
358
|
-
});
|
|
359
|
-
return mergedResponse;
|
|
360
|
-
}
|
|
361
|
-
return res;
|
|
362
|
-
}
|
|
363
|
-
// root routes
|
|
364
|
-
const customEndpointResponse = await handleCustomEndpoints({
|
|
365
|
-
endpoints: req.payload.config.endpoints,
|
|
366
|
-
req
|
|
367
|
-
});
|
|
368
|
-
if (customEndpointResponse) {
|
|
369
|
-
return customEndpointResponse;
|
|
370
|
-
}
|
|
371
|
-
return RouteNotFoundResponse({
|
|
372
|
-
slug,
|
|
373
|
-
req
|
|
374
|
-
});
|
|
375
|
-
} catch (error) {
|
|
376
|
-
return routeError({
|
|
377
|
-
collection,
|
|
378
|
-
config,
|
|
379
|
-
err: error,
|
|
380
|
-
req: req || request
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
|
-
export const POST = config => async (request, {
|
|
385
|
-
params: paramsPromise
|
|
386
|
-
}) => {
|
|
387
|
-
const {
|
|
388
|
-
slug
|
|
389
|
-
} = await paramsPromise;
|
|
390
|
-
const [slug1, slug2, slug3, slug4] = slug;
|
|
391
|
-
let req;
|
|
392
|
-
let res;
|
|
393
|
-
let collection;
|
|
394
|
-
const overrideHttpMethod = request.headers.get('X-HTTP-Method-Override');
|
|
395
|
-
if (overrideHttpMethod === 'GET') {
|
|
396
|
-
return await GET(config)(request, {
|
|
397
|
-
params: paramsPromise
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
try {
|
|
401
|
-
req = await createPayloadRequest({
|
|
402
|
-
config,
|
|
403
|
-
request
|
|
404
|
-
});
|
|
405
|
-
collection = req.payload.collections?.[slug1];
|
|
406
|
-
const disableEndpoints = endpointsAreDisabled({
|
|
407
|
-
endpoints: req.payload.config.endpoints,
|
|
408
|
-
request
|
|
409
|
-
});
|
|
410
|
-
if (disableEndpoints) {
|
|
411
|
-
return disableEndpoints;
|
|
412
|
-
}
|
|
413
|
-
if (collection) {
|
|
414
|
-
req.routeParams.collection = slug1;
|
|
415
|
-
const disableEndpoints = endpointsAreDisabled({
|
|
416
|
-
endpoints: collection.config.endpoints,
|
|
417
|
-
request
|
|
418
|
-
});
|
|
419
|
-
if (disableEndpoints) {
|
|
420
|
-
return disableEndpoints;
|
|
421
|
-
}
|
|
422
|
-
const customEndpointResponse = await handleCustomEndpoints({
|
|
423
|
-
endpoints: collection.config.endpoints,
|
|
424
|
-
entitySlug: slug1,
|
|
425
|
-
req
|
|
426
|
-
});
|
|
427
|
-
if (customEndpointResponse) {
|
|
428
|
-
return customEndpointResponse;
|
|
429
|
-
} else {
|
|
430
|
-
await addDataAndFileToRequest(req);
|
|
431
|
-
addLocalesToRequestFromData(req);
|
|
432
|
-
switch (slug.length) {
|
|
433
|
-
case 1:
|
|
434
|
-
// /:collection
|
|
435
|
-
res = await endpoints.collection.POST.create({
|
|
436
|
-
collection,
|
|
437
|
-
req
|
|
438
|
-
});
|
|
439
|
-
break;
|
|
440
|
-
case 2:
|
|
441
|
-
if (slug2 in endpoints.collection.POST) {
|
|
442
|
-
// /:collection/login
|
|
443
|
-
// /:collection/logout
|
|
444
|
-
// /:collection/unlock
|
|
445
|
-
// /:collection/access
|
|
446
|
-
// /:collection/first-register
|
|
447
|
-
// /:collection/forgot-password
|
|
448
|
-
// /:collection/reset-password
|
|
449
|
-
// /:collection/refresh-token
|
|
450
|
-
res = await (endpoints.collection.POST?.[slug2])({
|
|
451
|
-
collection,
|
|
452
|
-
req
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
break;
|
|
456
|
-
case 3:
|
|
457
|
-
if (`doc-${slug2}-by-id` in endpoints.collection.POST) {
|
|
458
|
-
// /:collection/access/:id
|
|
459
|
-
// /:collection/versions/:id
|
|
460
|
-
// /:collection/verify/:token ("doc-verify-by-id" uses id as token internally)
|
|
461
|
-
res = await endpoints.collection.POST[`doc-${slug2}-by-id`]({
|
|
462
|
-
id: slug3,
|
|
463
|
-
collection,
|
|
464
|
-
req
|
|
465
|
-
});
|
|
466
|
-
} else if (slug3 === 'duplicate' && collection.config.disableDuplicate !== true) {
|
|
467
|
-
// /:collection/:id/duplicate
|
|
468
|
-
res = await endpoints.collection.POST.duplicate({
|
|
469
|
-
id: slug2,
|
|
470
|
-
collection,
|
|
471
|
-
req
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
break;
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
} else if (slug1 === 'globals' && slug2) {
|
|
478
|
-
const globalConfig = req.payload.config.globals.find(global => global.slug === slug2);
|
|
479
|
-
req.routeParams.global = globalConfig.slug;
|
|
480
|
-
const disableEndpoints = endpointsAreDisabled({
|
|
481
|
-
endpoints: globalConfig.endpoints,
|
|
482
|
-
request
|
|
483
|
-
});
|
|
484
|
-
if (disableEndpoints) {
|
|
485
|
-
return disableEndpoints;
|
|
486
|
-
}
|
|
487
|
-
const customEndpointResponse = await handleCustomEndpoints({
|
|
488
|
-
endpoints: globalConfig.endpoints,
|
|
489
|
-
entitySlug: `${slug1}/${slug2}`,
|
|
490
|
-
req
|
|
491
|
-
});
|
|
492
|
-
if (customEndpointResponse) {
|
|
493
|
-
return customEndpointResponse;
|
|
494
|
-
} else {
|
|
495
|
-
await addDataAndFileToRequest(req);
|
|
496
|
-
addLocalesToRequestFromData(req);
|
|
497
|
-
switch (slug.length) {
|
|
498
|
-
case 2:
|
|
499
|
-
// /globals/:slug
|
|
500
|
-
res = await endpoints.global.POST.update({
|
|
501
|
-
globalConfig,
|
|
502
|
-
req
|
|
503
|
-
});
|
|
504
|
-
break;
|
|
505
|
-
case 3:
|
|
506
|
-
if (`doc-${slug3}` in endpoints.global.POST) {
|
|
507
|
-
// /globals/:slug/access
|
|
508
|
-
res = await (endpoints.global.POST?.[`doc-${slug3}`])({
|
|
509
|
-
globalConfig,
|
|
510
|
-
req
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
break;
|
|
514
|
-
case 4:
|
|
515
|
-
if (`doc-${slug3}-by-id` in endpoints.global.POST) {
|
|
516
|
-
// /globals/:slug/versions/:id
|
|
517
|
-
res = await (endpoints.global.POST?.[`doc-${slug3}-by-id`])({
|
|
518
|
-
id: slug4,
|
|
519
|
-
globalConfig,
|
|
520
|
-
req
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
break;
|
|
524
|
-
default:
|
|
525
|
-
res = new Response('Route Not Found', {
|
|
526
|
-
status: 404
|
|
527
|
-
});
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
if (res instanceof Response) {
|
|
532
|
-
if (req.responseHeaders) {
|
|
533
|
-
const mergedResponse = new Response(res.body, {
|
|
534
|
-
headers: mergeHeaders(req.responseHeaders, res.headers),
|
|
535
|
-
status: res.status,
|
|
536
|
-
statusText: res.statusText
|
|
537
|
-
});
|
|
538
|
-
return mergedResponse;
|
|
539
|
-
}
|
|
540
|
-
return res;
|
|
541
|
-
}
|
|
542
|
-
// root routes
|
|
543
|
-
const customEndpointResponse = await handleCustomEndpoints({
|
|
544
|
-
endpoints: req.payload.config.endpoints,
|
|
545
|
-
req
|
|
546
|
-
});
|
|
547
|
-
if (customEndpointResponse) {
|
|
548
|
-
return customEndpointResponse;
|
|
549
|
-
}
|
|
550
|
-
return RouteNotFoundResponse({
|
|
551
|
-
slug,
|
|
552
|
-
req
|
|
553
|
-
});
|
|
554
|
-
} catch (error) {
|
|
555
|
-
return routeError({
|
|
556
|
-
collection,
|
|
557
|
-
config,
|
|
558
|
-
err: error,
|
|
559
|
-
req: req || request
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
};
|
|
563
|
-
export const DELETE = config => async (request, {
|
|
564
|
-
params: paramsPromise
|
|
565
|
-
}) => {
|
|
566
|
-
const {
|
|
567
|
-
slug
|
|
568
|
-
} = await paramsPromise;
|
|
569
|
-
const [slug1, slug2] = slug;
|
|
570
|
-
let req;
|
|
571
|
-
let res;
|
|
572
|
-
let collection;
|
|
573
|
-
try {
|
|
574
|
-
req = await createPayloadRequest({
|
|
575
|
-
config,
|
|
576
|
-
request
|
|
577
|
-
});
|
|
578
|
-
collection = req.payload.collections?.[slug1];
|
|
579
|
-
const disableEndpoints = endpointsAreDisabled({
|
|
580
|
-
endpoints: req.payload.config.endpoints,
|
|
581
|
-
request
|
|
582
|
-
});
|
|
583
|
-
if (disableEndpoints) {
|
|
584
|
-
return disableEndpoints;
|
|
585
|
-
}
|
|
586
|
-
if (collection) {
|
|
587
|
-
req.routeParams.collection = slug1;
|
|
588
|
-
const disableEndpoints = endpointsAreDisabled({
|
|
589
|
-
endpoints: collection.config.endpoints,
|
|
590
|
-
request
|
|
591
|
-
});
|
|
592
|
-
if (disableEndpoints) {
|
|
593
|
-
return disableEndpoints;
|
|
594
|
-
}
|
|
595
|
-
const customEndpointResponse = await handleCustomEndpoints({
|
|
596
|
-
endpoints: collection.config.endpoints,
|
|
597
|
-
entitySlug: slug1,
|
|
598
|
-
req
|
|
599
|
-
});
|
|
600
|
-
if (customEndpointResponse) {
|
|
601
|
-
return customEndpointResponse;
|
|
602
|
-
} else {
|
|
603
|
-
await addDataAndFileToRequest(req);
|
|
604
|
-
addLocalesToRequestFromData(req);
|
|
605
|
-
switch (slug.length) {
|
|
606
|
-
case 1:
|
|
607
|
-
// /:collection
|
|
608
|
-
res = await endpoints.collection.DELETE.delete({
|
|
609
|
-
collection,
|
|
610
|
-
req
|
|
611
|
-
});
|
|
612
|
-
break;
|
|
613
|
-
case 2:
|
|
614
|
-
// /:collection/:id
|
|
615
|
-
res = await endpoints.collection.DELETE.deleteByID({
|
|
616
|
-
id: slug2,
|
|
617
|
-
collection,
|
|
618
|
-
req
|
|
619
|
-
});
|
|
620
|
-
break;
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
if (res instanceof Response) {
|
|
625
|
-
if (req.responseHeaders) {
|
|
626
|
-
const mergedResponse = new Response(res.body, {
|
|
627
|
-
headers: mergeHeaders(req.responseHeaders, res.headers),
|
|
628
|
-
status: res.status,
|
|
629
|
-
statusText: res.statusText
|
|
630
|
-
});
|
|
631
|
-
return mergedResponse;
|
|
632
|
-
}
|
|
633
|
-
return res;
|
|
634
|
-
}
|
|
635
|
-
// root routes
|
|
636
|
-
const customEndpointResponse = await handleCustomEndpoints({
|
|
637
|
-
endpoints: req.payload.config.endpoints,
|
|
638
|
-
req
|
|
639
|
-
});
|
|
640
|
-
if (customEndpointResponse) {
|
|
641
|
-
return customEndpointResponse;
|
|
642
|
-
}
|
|
643
|
-
return RouteNotFoundResponse({
|
|
644
|
-
slug,
|
|
645
|
-
req
|
|
646
|
-
});
|
|
647
|
-
} catch (error) {
|
|
648
|
-
return routeError({
|
|
649
|
-
collection,
|
|
650
|
-
config,
|
|
651
|
-
err: error,
|
|
652
|
-
req: req || request
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
};
|
|
656
|
-
export const PATCH = config => async (request, {
|
|
657
|
-
params: paramsPromise
|
|
658
|
-
}) => {
|
|
659
|
-
const {
|
|
660
|
-
slug
|
|
661
|
-
} = await paramsPromise;
|
|
662
|
-
const [slug1, slug2] = slug;
|
|
663
|
-
let req;
|
|
664
|
-
let res;
|
|
665
|
-
let collection;
|
|
666
|
-
try {
|
|
667
|
-
req = await createPayloadRequest({
|
|
668
|
-
config,
|
|
669
|
-
request
|
|
670
|
-
});
|
|
671
|
-
collection = req.payload.collections?.[slug1];
|
|
672
|
-
const disableEndpoints = endpointsAreDisabled({
|
|
673
|
-
endpoints: req.payload.config.endpoints,
|
|
674
|
-
request
|
|
675
|
-
});
|
|
676
|
-
if (disableEndpoints) {
|
|
677
|
-
return disableEndpoints;
|
|
678
|
-
}
|
|
679
|
-
if (collection) {
|
|
680
|
-
req.routeParams.collection = slug1;
|
|
681
|
-
const disableEndpoints = endpointsAreDisabled({
|
|
682
|
-
endpoints: collection.config.endpoints,
|
|
683
|
-
request
|
|
684
|
-
});
|
|
685
|
-
if (disableEndpoints) {
|
|
686
|
-
return disableEndpoints;
|
|
687
|
-
}
|
|
688
|
-
const customEndpointResponse = await handleCustomEndpoints({
|
|
689
|
-
endpoints: collection.config.endpoints,
|
|
690
|
-
entitySlug: slug1,
|
|
691
|
-
req
|
|
692
|
-
});
|
|
693
|
-
if (customEndpointResponse) {
|
|
694
|
-
return customEndpointResponse;
|
|
695
|
-
} else {
|
|
696
|
-
await addDataAndFileToRequest(req);
|
|
697
|
-
addLocalesToRequestFromData(req);
|
|
698
|
-
switch (slug.length) {
|
|
699
|
-
case 1:
|
|
700
|
-
// /:collection
|
|
701
|
-
res = await endpoints.collection.PATCH.update({
|
|
702
|
-
collection,
|
|
703
|
-
req
|
|
704
|
-
});
|
|
705
|
-
break;
|
|
706
|
-
case 2:
|
|
707
|
-
// /:collection/:id
|
|
708
|
-
res = await endpoints.collection.PATCH.updateByID({
|
|
709
|
-
id: slug2,
|
|
710
|
-
collection,
|
|
711
|
-
req
|
|
712
|
-
});
|
|
713
|
-
break;
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
if (res instanceof Response) {
|
|
718
|
-
if (req.responseHeaders) {
|
|
719
|
-
const mergedResponse = new Response(res.body, {
|
|
720
|
-
headers: mergeHeaders(req.responseHeaders, res.headers),
|
|
721
|
-
status: res.status,
|
|
722
|
-
statusText: res.statusText
|
|
723
|
-
});
|
|
724
|
-
return mergedResponse;
|
|
725
|
-
}
|
|
726
|
-
return res;
|
|
727
|
-
}
|
|
728
|
-
// root routes
|
|
729
|
-
const customEndpointResponse = await handleCustomEndpoints({
|
|
730
|
-
endpoints: req.payload.config.endpoints,
|
|
731
|
-
req
|
|
732
|
-
});
|
|
733
|
-
if (customEndpointResponse) {
|
|
734
|
-
return customEndpointResponse;
|
|
735
|
-
}
|
|
736
|
-
return RouteNotFoundResponse({
|
|
737
|
-
slug,
|
|
738
|
-
req
|
|
739
|
-
});
|
|
740
|
-
} catch (error) {
|
|
741
|
-
return routeError({
|
|
742
|
-
collection,
|
|
743
|
-
config,
|
|
744
|
-
err: error,
|
|
745
|
-
req: req || request
|
|
746
|
-
});
|
|
747
|
-
}
|
|
748
|
-
};
|
|
749
|
-
export const PUT = config => async (request, {
|
|
750
|
-
params: paramsPromise
|
|
751
|
-
}) => {
|
|
752
|
-
const {
|
|
753
|
-
slug
|
|
754
|
-
} = await paramsPromise;
|
|
755
|
-
const [slug1] = slug;
|
|
756
|
-
let req;
|
|
757
|
-
let res;
|
|
758
|
-
let collection;
|
|
759
|
-
try {
|
|
760
|
-
req = await createPayloadRequest({
|
|
761
|
-
config,
|
|
762
|
-
request
|
|
763
|
-
});
|
|
764
|
-
collection = req.payload.collections?.[slug1];
|
|
765
|
-
const disableEndpoints = endpointsAreDisabled({
|
|
766
|
-
endpoints: req.payload.config.endpoints,
|
|
767
|
-
request
|
|
768
|
-
});
|
|
769
|
-
if (disableEndpoints) {
|
|
770
|
-
return disableEndpoints;
|
|
771
|
-
}
|
|
772
|
-
if (collection) {
|
|
773
|
-
req.routeParams.collection = slug1;
|
|
774
|
-
const disableEndpoints = endpointsAreDisabled({
|
|
775
|
-
endpoints: collection.config.endpoints,
|
|
776
|
-
request
|
|
777
|
-
});
|
|
778
|
-
if (disableEndpoints) {
|
|
779
|
-
return disableEndpoints;
|
|
780
|
-
}
|
|
781
|
-
const customEndpointResponse = await handleCustomEndpoints({
|
|
782
|
-
endpoints: collection.config.endpoints,
|
|
783
|
-
entitySlug: slug1,
|
|
784
|
-
req
|
|
785
|
-
});
|
|
786
|
-
if (customEndpointResponse) {
|
|
787
|
-
return customEndpointResponse;
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
if (res instanceof Response) {
|
|
791
|
-
if (req.responseHeaders) {
|
|
792
|
-
const mergedResponse = new Response(res.body, {
|
|
793
|
-
headers: mergeHeaders(req.responseHeaders, res.headers),
|
|
794
|
-
status: res.status,
|
|
795
|
-
statusText: res.statusText
|
|
796
|
-
});
|
|
797
|
-
return mergedResponse;
|
|
798
|
-
}
|
|
799
|
-
return res;
|
|
800
|
-
}
|
|
801
|
-
// root routes
|
|
802
|
-
const customEndpointResponse = await handleCustomEndpoints({
|
|
803
|
-
endpoints: req.payload.config.endpoints,
|
|
804
|
-
req
|
|
805
|
-
});
|
|
806
|
-
if (customEndpointResponse) {
|
|
807
|
-
return customEndpointResponse;
|
|
808
|
-
}
|
|
809
|
-
return RouteNotFoundResponse({
|
|
810
|
-
slug,
|
|
811
|
-
req
|
|
812
|
-
});
|
|
813
|
-
} catch (error) {
|
|
814
|
-
return routeError({
|
|
815
|
-
collection,
|
|
816
|
-
config,
|
|
817
|
-
err: error,
|
|
818
|
-
req: req || request
|
|
819
|
-
});
|
|
820
|
-
}
|
|
821
|
-
};
|
|
3
|
+
let initedOGEndpoint = false;
|
|
4
|
+
const handlerBuilder = config => async request => {
|
|
5
|
+
const awaitedConfig = await config;
|
|
6
|
+
// Add this endpoint only when using Next.js, still can be overriden.
|
|
7
|
+
if (initedOGEndpoint === false && !awaitedConfig.endpoints.some(endpoint => endpoint.path === '/og' && endpoint.method === 'get')) {
|
|
8
|
+
awaitedConfig.endpoints.push({
|
|
9
|
+
handler: generateOGImage,
|
|
10
|
+
method: 'get',
|
|
11
|
+
path: '/og'
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
initedOGEndpoint = true;
|
|
15
|
+
const response = await handleEndpoints({
|
|
16
|
+
config,
|
|
17
|
+
request
|
|
18
|
+
});
|
|
19
|
+
return response;
|
|
20
|
+
};
|
|
21
|
+
export const OPTIONS = handlerBuilder;
|
|
22
|
+
export const GET = handlerBuilder;
|
|
23
|
+
export const POST = handlerBuilder;
|
|
24
|
+
export const DELETE = handlerBuilder;
|
|
25
|
+
export const PATCH = handlerBuilder;
|
|
26
|
+
export const PUT = handlerBuilder;
|
|
822
27
|
//# sourceMappingURL=index.js.map
|