payload-nested-docs-page-tree 1.2.4 → 1.4.0

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.
Files changed (46) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +136 -47
  3. package/dist/components/PageTreeContext.d.ts +13 -1
  4. package/dist/components/PageTreeContext.js +11 -1
  5. package/dist/components/PageTreeContext.js.map +1 -1
  6. package/dist/components/PageTreeListView.client.d.ts +4 -5
  7. package/dist/components/PageTreeListView.client.js +668 -128
  8. package/dist/components/PageTreeListView.client.js.map +1 -1
  9. package/dist/components/PageTreeListView.module.css +90 -67
  10. package/dist/components/PageTreeListView.server.js +18 -28
  11. package/dist/components/PageTreeListView.server.js.map +1 -1
  12. package/dist/components/PageTreeTitleCell.js +80 -18
  13. package/dist/components/PageTreeTitleCell.js.map +1 -1
  14. package/dist/endpoints/createMovePageEndpoint.d.ts +2 -0
  15. package/dist/endpoints/createMovePageEndpoint.js +166 -123
  16. package/dist/endpoints/createMovePageEndpoint.js.map +1 -1
  17. package/dist/endpoints/createReorderPageEndpoint.d.ts +8 -0
  18. package/dist/endpoints/createReorderPageEndpoint.js +703 -0
  19. package/dist/endpoints/createReorderPageEndpoint.js.map +1 -0
  20. package/dist/endpoints/shared.d.ts +40 -0
  21. package/dist/endpoints/shared.js +93 -0
  22. package/dist/endpoints/shared.js.map +1 -0
  23. package/dist/exports/client.js.map +1 -1
  24. package/dist/exports/rsc.js.map +1 -1
  25. package/dist/index.js +105 -26
  26. package/dist/index.js.map +1 -1
  27. package/dist/types.d.ts +9 -2
  28. package/dist/types.js +0 -2
  29. package/dist/types.js.map +1 -1
  30. package/dist/utilities/badgeConfig.js.map +1 -1
  31. package/dist/utilities/diagnostics.d.ts +42 -0
  32. package/dist/utilities/diagnostics.js +83 -0
  33. package/dist/utilities/diagnostics.js.map +1 -0
  34. package/dist/utilities/dropTargets.d.ts +2 -2
  35. package/dist/utilities/dropTargets.js +9 -7
  36. package/dist/utilities/dropTargets.js.map +1 -1
  37. package/dist/utilities/pageTree.js +4 -6
  38. package/dist/utilities/pageTree.js.map +1 -1
  39. package/dist/utilities/pageTreeCollision.d.ts +6 -0
  40. package/dist/utilities/pageTreeCollision.js +39 -4
  41. package/dist/utilities/pageTreeCollision.js.map +1 -1
  42. package/dist/utilities/pageTreeConfig.js.map +1 -1
  43. package/dist/utilities/status.d.ts +1 -1
  44. package/dist/utilities/status.js +7 -3
  45. package/dist/utilities/status.js.map +1 -1
  46. package/package.json +13 -12
@@ -1,23 +1,14 @@
1
+ import { DIAGNOSTICS_FLOW_CONTEXT_KEY, createFlowID, readMainRowSnapshot } from '../utilities/diagnostics.js';
1
2
  import { CANCEL_DRAG_MESSAGE } from '../utilities/moveValidation.js';
2
3
  import { buildChildrenByParentID, collectDescendantIDs, getDocParentID, stringifyDocID } from '../utilities/pageTree.js';
3
4
  import { pageTreeMoveContextKey } from '../types.js';
4
- function respond(status, body) {
5
- return Response.json(body, {
6
- status
7
- });
8
- }
5
+ import { assertUpdateAccess, collectionHasAutosaveDrafts, collectionHasDrafts, getRequestedLocale, normalizeID, respond, toCollectionID } from './shared.js';
6
+ const SNAPSHOT_FIELDS = [
7
+ '_status'
8
+ ];
9
9
  function hasOwnProperty(value, key) {
10
10
  return Object.prototype.hasOwnProperty.call(value, key);
11
11
  }
12
- function normalizeID(value) {
13
- if (value === null || value === undefined || value === '') {
14
- return null;
15
- }
16
- if (typeof value === 'number' || typeof value === 'string') {
17
- return stringifyDocID(value);
18
- }
19
- return null;
20
- }
21
12
  function normalizeMoveDocumentBody(value) {
22
13
  const incomingData = typeof value === 'string' ? (()=>{
23
14
  try {
@@ -41,15 +32,33 @@ function normalizeMoveDocumentBody(value) {
41
32
  };
42
33
  }
43
34
  async function readBodyFromRequest(req) {
44
- const directBody = normalizeMoveDocumentBody(req.data);
45
- if (directBody) {
46
- return directBody;
35
+ let lastAttempt = null;
36
+ if (req.data !== undefined && req.data !== null) {
37
+ lastAttempt = {
38
+ raw: req.data,
39
+ source: 'req.data'
40
+ };
41
+ const directBody = normalizeMoveDocumentBody(req.data);
42
+ if (directBody) {
43
+ return {
44
+ body: directBody,
45
+ lastAttempt
46
+ };
47
+ }
47
48
  }
48
49
  if (typeof req.json === 'function') {
49
50
  try {
50
- const jsonBody = normalizeMoveDocumentBody(await req.json());
51
+ const raw = await req.json();
52
+ lastAttempt = {
53
+ raw,
54
+ source: 'req.json'
55
+ };
56
+ const jsonBody = normalizeMoveDocumentBody(raw);
51
57
  if (jsonBody) {
52
- return jsonBody;
58
+ return {
59
+ body: jsonBody,
60
+ lastAttempt
61
+ };
53
62
  }
54
63
  } catch {
55
64
  // Fall through to the text-based fallback when the runtime does not hydrate req.data.
@@ -57,98 +66,36 @@ async function readBodyFromRequest(req) {
57
66
  }
58
67
  if (typeof req.text === 'function') {
59
68
  try {
60
- return normalizeMoveDocumentBody(await req.text());
61
- } catch {
62
- return null;
63
- }
64
- }
65
- return null;
66
- }
67
- function getPayloadCollection({ collectionSlug, req }) {
68
- return req.payload.collections[collectionSlug];
69
- }
70
- function usesNumericID({ collectionSlug, req }) {
71
- const collection = getPayloadCollection({
72
- collectionSlug,
73
- req
74
- });
75
- if (!collection) {
76
- return false;
77
- }
78
- const idType = collection.customIDType ?? req.payload.db.defaultIDType;
79
- return idType === 'number';
80
- }
81
- function toCollectionID(args) {
82
- const { collectionSlug, id, req } = args;
83
- if (!usesNumericID({
84
- collectionSlug,
85
- req
86
- })) {
87
- return id;
88
- }
89
- return Number(id);
90
- }
91
- function getRequestedLocale(req) {
92
- return req.locale && req.locale !== 'all' ? req.locale : undefined;
93
- }
94
- function collectionHasDrafts(args) {
95
- return Boolean(getPayloadCollection(args)?.config?.versions?.drafts);
96
- }
97
- async function assertUpdateAccess(args) {
98
- const { collectionSlug, movedID, nextParentID, parentFieldSlug, req } = args;
99
- const collection = getPayloadCollection({
100
- collectionSlug,
101
- req
102
- });
103
- const updateAccess = collection?.config?.access?.update;
104
- if (!updateAccess) {
105
- return null;
106
- }
107
- const accessResult = await updateAccess({
108
- data: {
109
- [parentFieldSlug]: nextParentID
110
- },
111
- id: movedID,
112
- req
113
- });
114
- if (accessResult === false) {
115
- return respond(403, {
116
- message: req.i18n.t('error:unauthorized')
117
- });
118
- }
119
- if (accessResult && typeof accessResult === 'object') {
120
- const matchingDocs = await req.payload.find({
121
- collection: collectionSlug,
122
- depth: 0,
123
- draft: collectionHasDrafts({
124
- collectionSlug,
125
- req
126
- }) ? true : undefined,
127
- limit: 1,
128
- locale: getRequestedLocale(req),
129
- overrideAccess: true,
130
- req,
131
- where: {
132
- and: [
133
- {
134
- id: {
135
- equals: movedID
136
- }
137
- },
138
- accessResult
139
- ]
69
+ const raw = await req.text();
70
+ lastAttempt = {
71
+ raw,
72
+ source: 'req.text'
73
+ };
74
+ const textBody = normalizeMoveDocumentBody(raw);
75
+ if (textBody) {
76
+ return {
77
+ body: textBody,
78
+ lastAttempt
79
+ };
140
80
  }
141
- });
142
- if (matchingDocs.docs.length === 0) {
143
- return respond(403, {
144
- message: req.i18n.t('error:unauthorized')
145
- });
81
+ } catch {
82
+ return {
83
+ body: null,
84
+ lastAttempt
85
+ };
146
86
  }
147
87
  }
148
- return null;
88
+ return {
89
+ body: null,
90
+ lastAttempt
91
+ };
149
92
  }
150
93
  export function createMovePageEndpoint(args) {
151
- const { collectionSlug, parentFieldSlug } = args;
94
+ const { collectionSlug, diagnostics, parentFieldSlug } = args;
95
+ const snapshotFields = [
96
+ ...SNAPSHOT_FIELDS,
97
+ parentFieldSlug
98
+ ];
152
99
  return {
153
100
  handler: async (req)=>{
154
101
  const movedIDFromRoute = normalizeID(req.routeParams?.id);
@@ -157,8 +104,22 @@ export function createMovePageEndpoint(args) {
157
104
  message: 'Document ID was not specified.'
158
105
  });
159
106
  }
160
- const body = await readBodyFromRequest(req);
107
+ const { body, lastAttempt } = await readBodyFromRequest(req);
161
108
  if (!body) {
109
+ if (diagnostics.enabled) {
110
+ diagnostics.log({
111
+ collection: collectionSlug,
112
+ data: {
113
+ movedID: movedIDFromRoute,
114
+ rawBody: lastAttempt?.raw ?? null,
115
+ rawBodySource: lastAttempt?.source ?? null
116
+ },
117
+ flow: createFlowID('move-endpoint'),
118
+ level: 'warn',
119
+ message: 'move endpoint rejected request body: parentID was missing or malformed',
120
+ source: 'move-endpoint:body-rejected'
121
+ });
122
+ }
162
123
  return respond(400, {
163
124
  message: 'A valid parentID is required.'
164
125
  });
@@ -175,9 +136,10 @@ export function createMovePageEndpoint(args) {
175
136
  });
176
137
  const accessError = await assertUpdateAccess({
177
138
  collectionSlug,
178
- movedID,
179
- nextParentID,
180
- parentFieldSlug,
139
+ data: {
140
+ [parentFieldSlug]: nextParentID
141
+ },
142
+ id: movedID,
181
143
  req
182
144
  });
183
145
  if (accessError) {
@@ -233,28 +195,109 @@ export function createMovePageEndpoint(args) {
233
195
  message: 'A document cannot be moved under one of its descendants.'
234
196
  });
235
197
  }
236
- await req.payload.update({
198
+ const flow = createFlowID('move-endpoint');
199
+ const moveStart = Date.now();
200
+ const hasDrafts = collectionHasDrafts({
201
+ collectionSlug,
202
+ req
203
+ });
204
+ const hasAutosave = hasDrafts && collectionHasAutosaveDrafts({
205
+ collectionSlug,
206
+ req
207
+ });
208
+ const updateData = {
209
+ [parentFieldSlug]: body.parentID === null ? null : toCollectionID({
210
+ collectionSlug,
211
+ id: body.parentID,
212
+ req
213
+ })
214
+ };
215
+ const updateArgs = {
237
216
  collection: collectionSlug,
238
217
  context: {
239
218
  [pageTreeMoveContextKey]: true
240
219
  },
241
- data: {
242
- [parentFieldSlug]: body.parentID === null ? null : toCollectionID({
243
- collectionSlug,
244
- id: body.parentID,
245
- req
246
- })
247
- },
220
+ autosave: hasAutosave ? true : undefined,
221
+ data: updateData,
248
222
  depth: 0,
249
- draft: collectionHasDrafts({
250
- collectionSlug,
251
- req
252
- }) ? true : undefined,
223
+ draft: hasDrafts ? true : undefined,
253
224
  id: movedID,
254
225
  locale: getRequestedLocale(req),
255
226
  overrideAccess: true,
256
227
  req
257
- });
228
+ };
229
+ if (diagnostics.enabled) {
230
+ if (!req.context) {
231
+ req.context = {};
232
+ }
233
+ ;
234
+ req.context[DIAGNOSTICS_FLOW_CONTEXT_KEY] = flow;
235
+ const beforeSnapshot = await readMainRowSnapshot({
236
+ collectionSlug,
237
+ fields: snapshotFields,
238
+ id: movedID,
239
+ req
240
+ });
241
+ diagnostics.log({
242
+ collection: collectionSlug,
243
+ data: {
244
+ autosave: updateArgs.autosave ?? null,
245
+ currentParentID,
246
+ draft: updateArgs.draft,
247
+ hasTransaction: Boolean(req.transactionID),
248
+ locale: updateArgs.locale ?? null,
249
+ movedID: String(movedID),
250
+ nextParentID: body.parentID,
251
+ publishedMainRowBefore: beforeSnapshot,
252
+ updateData
253
+ },
254
+ flow,
255
+ level: 'info',
256
+ message: 'move endpoint entering: parent move only',
257
+ source: 'move-endpoint:enter'
258
+ });
259
+ }
260
+ try {
261
+ const result = await req.payload.update(updateArgs);
262
+ if (diagnostics.enabled) {
263
+ const afterSnapshot = await readMainRowSnapshot({
264
+ collectionSlug,
265
+ fields: snapshotFields,
266
+ id: movedID,
267
+ req
268
+ });
269
+ diagnostics.log({
270
+ collection: collectionSlug,
271
+ data: {
272
+ durMs: Date.now() - moveStart,
273
+ movedID: String(movedID),
274
+ publishedMainRowAfter: afterSnapshot,
275
+ resultStatus: result?._status ?? null
276
+ },
277
+ flow,
278
+ level: 'info',
279
+ message: 'move endpoint payload.update succeeded',
280
+ source: 'move-endpoint:ok'
281
+ });
282
+ }
283
+ } catch (err) {
284
+ const error = err;
285
+ diagnostics.log({
286
+ collection: collectionSlug,
287
+ data: {
288
+ data: error?.data ?? null,
289
+ durMs: Date.now() - moveStart,
290
+ message: error?.message,
291
+ movedID: String(movedID),
292
+ name: error?.name
293
+ },
294
+ flow,
295
+ level: 'error',
296
+ message: `move endpoint payload.update failed: ${error?.message ?? 'unknown error'}`,
297
+ source: 'move-endpoint:error'
298
+ });
299
+ throw err;
300
+ }
258
301
  return respond(200, {
259
302
  movedID: movedIDFromRoute,
260
303
  ok: true,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/endpoints/createMovePageEndpoint.ts"],"sourcesContent":["import type { Endpoint, PayloadRequest, Where } from 'payload'\r\n\r\nimport { CANCEL_DRAG_MESSAGE } from '../utilities/moveValidation.js'\r\nimport {\r\n buildChildrenByParentID,\r\n collectDescendantIDs,\r\n getDocParentID,\r\n stringifyDocID,\r\n} from '../utilities/pageTree.js'\r\nimport { pageTreeMoveContextKey, type PageTreeSourceDoc } from '../types.js'\r\n\r\ntype MoveDocumentRequestBody = {\r\n parentID: null | string\r\n}\r\n\r\ntype PayloadCollectionLike = {\r\n config?: {\r\n access?: {\r\n update?: ((args: Record<string, unknown>) => Promise<Record<string, unknown> | boolean> | Record<string, unknown> | boolean) | undefined\r\n }\r\n versions?: {\r\n drafts?: unknown\r\n }\r\n }\r\n customIDType?: string\r\n}\r\n\r\nfunction respond(status: number, body: Record<string, unknown>) {\r\n return Response.json(body, { status })\r\n}\r\n\r\nfunction hasOwnProperty(value: object, key: PropertyKey): boolean {\r\n return Object.prototype.hasOwnProperty.call(value, key)\r\n}\r\n\r\nfunction normalizeID(value: unknown): null | string {\r\n if (value === null || value === undefined || value === '') {\r\n return null\r\n }\r\n\r\n if (typeof value === 'number' || typeof value === 'string') {\r\n return stringifyDocID(value)\r\n }\r\n\r\n return null\r\n}\r\n\r\nfunction normalizeMoveDocumentBody(value: unknown): MoveDocumentRequestBody | null {\r\n const incomingData =\r\n typeof value === 'string'\r\n ? (() => {\r\n try {\r\n return JSON.parse(value) as unknown\r\n } catch {\r\n return null\r\n }\r\n })()\r\n : value\r\n\r\n if (!incomingData || typeof incomingData !== 'object' || Array.isArray(incomingData)) {\r\n return null\r\n }\r\n\r\n if (!hasOwnProperty(incomingData, 'parentID')) {\r\n return null\r\n }\r\n\r\n const parentID = normalizeID((incomingData as { parentID?: unknown }).parentID)\r\n\r\n if (\r\n (incomingData as { parentID?: unknown }).parentID !== null &&\r\n (incomingData as { parentID?: unknown }).parentID !== undefined &&\r\n parentID === null\r\n ) {\r\n return null\r\n }\r\n\r\n return {\r\n parentID,\r\n }\r\n}\r\n\r\nasync function readBodyFromRequest(req: PayloadRequest): Promise<MoveDocumentRequestBody | null> {\r\n const directBody = normalizeMoveDocumentBody(req.data)\r\n\r\n if (directBody) {\r\n return directBody\r\n }\r\n\r\n if (typeof req.json === 'function') {\r\n try {\r\n const jsonBody = normalizeMoveDocumentBody(await req.json())\r\n\r\n if (jsonBody) {\r\n return jsonBody\r\n }\r\n } catch {\r\n // Fall through to the text-based fallback when the runtime does not hydrate req.data.\r\n }\r\n }\r\n\r\n if (typeof req.text === 'function') {\r\n try {\r\n return normalizeMoveDocumentBody(await req.text())\r\n } catch {\r\n return null\r\n }\r\n }\r\n\r\n return null\r\n}\r\n\r\nfunction getPayloadCollection({\r\n collectionSlug,\r\n req,\r\n}: {\r\n collectionSlug: string\r\n req: PayloadRequest\r\n}): PayloadCollectionLike | undefined {\r\n return (req.payload.collections as unknown as Record<string, PayloadCollectionLike | undefined>)[\r\n collectionSlug\r\n ]\r\n}\r\n\r\nfunction usesNumericID({\r\n collectionSlug,\r\n req,\r\n}: {\r\n collectionSlug: string\r\n req: PayloadRequest\r\n}): boolean {\r\n const collection = getPayloadCollection({ collectionSlug, req })\r\n\r\n if (!collection) {\r\n return false\r\n }\r\n\r\n const idType = collection.customIDType ?? req.payload.db.defaultIDType\r\n\r\n return idType === 'number'\r\n}\r\n\r\nfunction toCollectionID(args: {\r\n collectionSlug: string\r\n id: string\r\n req: PayloadRequest\r\n}): number | string {\r\n const { collectionSlug, id, req } = args\r\n\r\n if (!usesNumericID({ collectionSlug, req })) {\r\n return id\r\n }\r\n\r\n return Number(id)\r\n}\r\n\r\nfunction getRequestedLocale(req: PayloadRequest): string | undefined {\r\n return req.locale && req.locale !== 'all' ? req.locale : undefined\r\n}\r\n\r\nfunction collectionHasDrafts(args: {\r\n collectionSlug: string\r\n req: PayloadRequest\r\n}): boolean {\r\n return Boolean(getPayloadCollection(args)?.config?.versions?.drafts)\r\n}\r\n\r\nasync function assertUpdateAccess(args: {\r\n collectionSlug: string\r\n movedID: number | string\r\n nextParentID: null | number | string\r\n parentFieldSlug: string\r\n req: PayloadRequest\r\n}): Promise<Response | null> {\r\n const { collectionSlug, movedID, nextParentID, parentFieldSlug, req } = args\r\n const collection = getPayloadCollection({ collectionSlug, req })\r\n const updateAccess = collection?.config?.access?.update\r\n\r\n if (!updateAccess) {\r\n return null\r\n }\r\n\r\n const accessResult = await updateAccess({\r\n data: { [parentFieldSlug]: nextParentID } as never,\r\n id: movedID as never,\r\n req,\r\n })\r\n\r\n if (accessResult === false) {\r\n return respond(403, {\r\n message: req.i18n.t('error:unauthorized'),\r\n })\r\n }\r\n\r\n if (accessResult && typeof accessResult === 'object') {\r\n const matchingDocs = await req.payload.find({\r\n collection: collectionSlug as never,\r\n depth: 0,\r\n draft: collectionHasDrafts({ collectionSlug, req }) ? true : undefined,\r\n limit: 1,\r\n locale: getRequestedLocale(req) as never,\r\n overrideAccess: true,\r\n req,\r\n where: {\r\n and: [\r\n {\r\n id: {\r\n equals: movedID,\r\n },\r\n },\r\n accessResult as Where,\r\n ],\r\n },\r\n } as never)\r\n\r\n if (matchingDocs.docs.length === 0) {\r\n return respond(403, {\r\n message: req.i18n.t('error:unauthorized'),\r\n })\r\n }\r\n }\r\n\r\n return null\r\n}\r\n\r\nexport function createMovePageEndpoint(args: {\r\n collectionSlug: string\r\n parentFieldSlug: string\r\n}): Endpoint {\r\n const { collectionSlug, parentFieldSlug } = args\r\n\r\n return {\r\n handler: async (req) => {\r\n const movedIDFromRoute = normalizeID(req.routeParams?.id)\r\n\r\n if (!movedIDFromRoute) {\r\n return respond(400, {\r\n message: 'Document ID was not specified.',\r\n })\r\n }\r\n\r\n const body = await readBodyFromRequest(req)\r\n\r\n if (!body) {\r\n return respond(400, {\r\n message: 'A valid parentID is required.',\r\n })\r\n }\r\n\r\n const movedID = toCollectionID({\r\n collectionSlug,\r\n id: movedIDFromRoute,\r\n req,\r\n })\r\n const nextParentID =\r\n body.parentID === null\r\n ? null\r\n : toCollectionID({\r\n collectionSlug,\r\n id: body.parentID,\r\n req,\r\n })\r\n const accessError = await assertUpdateAccess({\r\n collectionSlug,\r\n movedID,\r\n nextParentID,\r\n parentFieldSlug,\r\n req,\r\n })\r\n\r\n if (accessError) {\r\n return accessError\r\n }\r\n\r\n const docsResult = await req.payload.find({\r\n collection: collectionSlug as never,\r\n depth: 0,\r\n draft: collectionHasDrafts({ collectionSlug, req }) ? true : undefined,\r\n fallbackLocale: false as never,\r\n limit: 0,\r\n locale: getRequestedLocale(req) as never,\r\n overrideAccess: true,\r\n req,\r\n } as never)\r\n const docs = docsResult.docs as unknown as PageTreeSourceDoc[]\r\n const docsByID = new Map(docs.map((doc) => [stringifyDocID(doc.id), doc]))\r\n const movedDoc = docsByID.get(movedIDFromRoute)\r\n\r\n if (!movedDoc) {\r\n return respond(404, {\r\n message: 'Document not found.',\r\n })\r\n }\r\n\r\n if (body.parentID !== null && !docsByID.has(body.parentID)) {\r\n return respond(400, {\r\n message: 'Parent document not found.',\r\n })\r\n }\r\n\r\n const currentParentID = getDocParentID(movedDoc, parentFieldSlug)\r\n\r\n if (currentParentID === body.parentID) {\r\n return respond(400, {\r\n message: 'Document already has that parent.',\r\n })\r\n }\r\n\r\n if (body.parentID === movedIDFromRoute) {\r\n return respond(400, {\r\n message: CANCEL_DRAG_MESSAGE,\r\n })\r\n }\r\n\r\n const childrenByParentID = buildChildrenByParentID({\r\n docs,\r\n parentFieldSlug,\r\n })\r\n const descendantIDs = collectDescendantIDs(movedIDFromRoute, childrenByParentID)\r\n\r\n if (body.parentID !== null && descendantIDs.includes(body.parentID)) {\r\n return respond(400, {\r\n message: 'A document cannot be moved under one of its descendants.',\r\n })\r\n }\r\n\r\n await req.payload.update({\r\n collection: collectionSlug as never,\r\n context: {\r\n [pageTreeMoveContextKey]: true,\r\n },\r\n data: {\r\n [parentFieldSlug]:\r\n body.parentID === null\r\n ? null\r\n : toCollectionID({\r\n collectionSlug,\r\n id: body.parentID,\r\n req,\r\n }),\r\n } as never,\r\n depth: 0,\r\n draft: collectionHasDrafts({ collectionSlug, req }) ? true : undefined,\r\n id: movedID as never,\r\n locale: getRequestedLocale(req) as never,\r\n overrideAccess: true,\r\n req,\r\n } as never)\r\n\r\n return respond(200, {\r\n movedID: movedIDFromRoute,\r\n ok: true,\r\n parentID: body.parentID,\r\n })\r\n },\r\n method: 'post',\r\n path: '/:id/move',\r\n }\r\n}\r\n"],"names":["CANCEL_DRAG_MESSAGE","buildChildrenByParentID","collectDescendantIDs","getDocParentID","stringifyDocID","pageTreeMoveContextKey","respond","status","body","Response","json","hasOwnProperty","value","key","Object","prototype","call","normalizeID","undefined","normalizeMoveDocumentBody","incomingData","JSON","parse","Array","isArray","parentID","readBodyFromRequest","req","directBody","data","jsonBody","text","getPayloadCollection","collectionSlug","payload","collections","usesNumericID","collection","idType","customIDType","db","defaultIDType","toCollectionID","args","id","Number","getRequestedLocale","locale","collectionHasDrafts","Boolean","config","versions","drafts","assertUpdateAccess","movedID","nextParentID","parentFieldSlug","updateAccess","access","update","accessResult","message","i18n","t","matchingDocs","find","depth","draft","limit","overrideAccess","where","and","equals","docs","length","createMovePageEndpoint","handler","movedIDFromRoute","routeParams","accessError","docsResult","fallbackLocale","docsByID","Map","map","doc","movedDoc","get","has","currentParentID","childrenByParentID","descendantIDs","includes","context","ok","method","path"],"mappings":"AAEA,SAASA,mBAAmB,QAAQ,iCAAgC;AACpE,SACEC,uBAAuB,EACvBC,oBAAoB,EACpBC,cAAc,EACdC,cAAc,QACT,2BAA0B;AACjC,SAASC,sBAAsB,QAAgC,cAAa;AAkB5E,SAASC,QAAQC,MAAc,EAAEC,IAA6B;IAC5D,OAAOC,SAASC,IAAI,CAACF,MAAM;QAAED;IAAO;AACtC;AAEA,SAASI,eAAeC,KAAa,EAAEC,GAAgB;IACrD,O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F,uBAAuB,EAAE;gBAC5B;gBACAwB,MAAM;oBACJ,CAAC2B,gBAAgB,EACfhD,KAAKiB,QAAQ,KAAK,OACd,OACAiB,eAAe;wBACbT;wBACAW,IAAIpC,KAAKiB,QAAQ;wBACjBE;oBACF;gBACR;gBACAuC,OAAO;gBACPC,OAAOnB,oBAAoB;oBAAEf;oBAAgBN;gBAAI,KAAK,OAAOT;gBAC7D0B,IAAIU;gBACJP,QAAQD,mBAAmBnB;gBAC3B0C,gBAAgB;gBAChB1C;YACF;YAEA,OAAOrB,QAAQ,KAAK;gBAClBgD,SAASuB;gBACTiB,IAAI;gBACJrE,UAAUjB,KAAKiB,QAAQ;YACzB;QACF;QACAsE,QAAQ;QACRC,MAAM;IACR;AACF"}
1
+ {"version":3,"sources":["../../src/endpoints/createMovePageEndpoint.ts"],"sourcesContent":["import type { Endpoint, PayloadRequest } from 'payload'\n\nimport {\n DIAGNOSTICS_FLOW_CONTEXT_KEY,\n type Diagnostics,\n createFlowID,\n readMainRowSnapshot,\n} from '../utilities/diagnostics.js'\nimport { CANCEL_DRAG_MESSAGE } from '../utilities/moveValidation.js'\nimport {\n buildChildrenByParentID,\n collectDescendantIDs,\n getDocParentID,\n stringifyDocID,\n} from '../utilities/pageTree.js'\nimport { pageTreeMoveContextKey, type PageTreeSourceDoc } from '../types.js'\nimport {\n assertUpdateAccess,\n collectionHasAutosaveDrafts,\n collectionHasDrafts,\n getRequestedLocale,\n normalizeID,\n respond,\n toCollectionID,\n} from './shared.js'\n\nconst SNAPSHOT_FIELDS = ['_status'] as const\n\ntype MoveDocumentRequestBody = {\n parentID: null | string\n}\n\r\nfunction hasOwnProperty(value: object, key: PropertyKey): boolean {\r\n return Object.prototype.hasOwnProperty.call(value, key)\r\n}\r\n\r\nfunction normalizeMoveDocumentBody(value: unknown): MoveDocumentRequestBody | null {\n const incomingData =\r\n typeof value === 'string'\r\n ? (() => {\r\n try {\r\n return JSON.parse(value) as unknown\r\n } catch {\r\n return null\r\n }\r\n })()\r\n : value\r\n\r\n if (!incomingData || typeof incomingData !== 'object' || Array.isArray(incomingData)) {\r\n return null\r\n }\r\n\r\n if (!hasOwnProperty(incomingData, 'parentID')) {\r\n return null\r\n }\r\n\r\n const parentID = normalizeID((incomingData as { parentID?: unknown }).parentID)\r\n\r\n if (\r\n (incomingData as { parentID?: unknown }).parentID !== null &&\r\n (incomingData as { parentID?: unknown }).parentID !== undefined &&\r\n parentID === null\r\n ) {\r\n return null\r\n }\r\n\r\n return {\r\n parentID,\r\n }\r\n}\r\n\r\ntype RawBodyAttempt = {\n raw: unknown\n source: 'req.data' | 'req.json' | 'req.text'\n}\n\nasync function readBodyFromRequest(\n req: PayloadRequest,\n): Promise<{ body: MoveDocumentRequestBody | null; lastAttempt: null | RawBodyAttempt }> {\n let lastAttempt: null | RawBodyAttempt = null\n\n if (req.data !== undefined && req.data !== null) {\n lastAttempt = { raw: req.data, source: 'req.data' }\n const directBody = normalizeMoveDocumentBody(req.data)\n\n if (directBody) {\n return { body: directBody, lastAttempt }\n }\n }\n\n if (typeof req.json === 'function') {\n try {\n const raw = await req.json()\n lastAttempt = { raw, source: 'req.json' }\n const jsonBody = normalizeMoveDocumentBody(raw)\n\n if (jsonBody) {\n return { body: jsonBody, lastAttempt }\n }\n } catch {\n // Fall through to the text-based fallback when the runtime does not hydrate req.data.\n }\r\n }\r\n\n if (typeof req.text === 'function') {\n try {\n const raw = await req.text()\n lastAttempt = { raw, source: 'req.text' }\n const textBody = normalizeMoveDocumentBody(raw)\n\n if (textBody) {\n return { body: textBody, lastAttempt }\n }\n } catch {\n return { body: null, lastAttempt }\n }\n }\n\n return { body: null, lastAttempt }\n}\n\r\nexport function createMovePageEndpoint(args: {\n collectionSlug: string\n diagnostics: Diagnostics\n parentFieldSlug: string\n}): Endpoint {\n const { collectionSlug, diagnostics, parentFieldSlug } = args\n const snapshotFields = [...SNAPSHOT_FIELDS, parentFieldSlug]\n\n return {\n handler: async (req) => {\n const movedIDFromRoute = normalizeID(req.routeParams?.id)\r\n\r\n if (!movedIDFromRoute) {\r\n return respond(400, {\r\n message: 'Document ID was not specified.',\r\n })\r\n }\r\n\r\n const { body, lastAttempt } = await readBodyFromRequest(req)\n\n if (!body) {\n if (diagnostics.enabled) {\n diagnostics.log({\n collection: collectionSlug,\n data: {\n movedID: movedIDFromRoute,\n rawBody: lastAttempt?.raw ?? null,\n rawBodySource: lastAttempt?.source ?? null,\n },\n flow: createFlowID('move-endpoint'),\n level: 'warn',\n message: 'move endpoint rejected request body: parentID was missing or malformed',\n source: 'move-endpoint:body-rejected',\n })\n }\n\n return respond(400, {\n message: 'A valid parentID is required.',\n })\n }\r\n\r\n const movedID = toCollectionID({\r\n collectionSlug,\r\n id: movedIDFromRoute,\r\n req,\r\n })\r\n const nextParentID =\r\n body.parentID === null\r\n ? null\r\n : toCollectionID({\r\n collectionSlug,\r\n id: body.parentID,\r\n req,\r\n })\r\n const accessError = await assertUpdateAccess({\n collectionSlug,\n data: { [parentFieldSlug]: nextParentID },\n id: movedID,\n req,\n })\n\r\n if (accessError) {\r\n return accessError\r\n }\r\n\r\n const docsResult = await req.payload.find({\r\n collection: collectionSlug as never,\r\n depth: 0,\r\n draft: collectionHasDrafts({ collectionSlug, req }) ? true : undefined,\r\n fallbackLocale: false as never,\r\n limit: 0,\r\n locale: getRequestedLocale(req) as never,\r\n overrideAccess: true,\r\n req,\r\n } as never)\r\n const docs = docsResult.docs as unknown as PageTreeSourceDoc[]\r\n const docsByID = new Map(docs.map((doc) => [stringifyDocID(doc.id), doc]))\r\n const movedDoc = docsByID.get(movedIDFromRoute)\r\n\r\n if (!movedDoc) {\r\n return respond(404, {\r\n message: 'Document not found.',\r\n })\r\n }\r\n\r\n if (body.parentID !== null && !docsByID.has(body.parentID)) {\r\n return respond(400, {\r\n message: 'Parent document not found.',\r\n })\r\n }\r\n\r\n const currentParentID = getDocParentID(movedDoc, parentFieldSlug)\n\n if (currentParentID === body.parentID) {\n return respond(400, {\r\n message: 'Document already has that parent.',\r\n })\r\n }\r\n\r\n if (body.parentID === movedIDFromRoute) {\r\n return respond(400, {\r\n message: CANCEL_DRAG_MESSAGE,\r\n })\r\n }\r\n\r\n const childrenByParentID = buildChildrenByParentID({\r\n docs,\r\n parentFieldSlug,\r\n })\r\n const descendantIDs = collectDescendantIDs(movedIDFromRoute, childrenByParentID)\r\n\r\n if (body.parentID !== null && descendantIDs.includes(body.parentID)) {\n return respond(400, {\n message: 'A document cannot be moved under one of its descendants.',\n })\n }\n\n const flow = createFlowID('move-endpoint')\n const moveStart = Date.now()\n const hasDrafts = collectionHasDrafts({ collectionSlug, req })\n const hasAutosave = hasDrafts && collectionHasAutosaveDrafts({ collectionSlug, req })\n const updateData = {\n [parentFieldSlug]:\n body.parentID === null\n ? null\n : toCollectionID({\n collectionSlug,\n id: body.parentID,\n req,\n }),\n }\n const updateArgs = {\n collection: collectionSlug as never,\n context: {\n [pageTreeMoveContextKey]: true,\n } as Record<string, unknown>,\n autosave: hasAutosave ? true : undefined,\n data: updateData as never,\n depth: 0,\n draft: hasDrafts ? true : undefined,\n id: movedID as never,\n locale: getRequestedLocale(req) as never,\n overrideAccess: true,\n req,\n }\n\n if (diagnostics.enabled) {\n if (!req.context) {\n req.context = {}\n }\n\n ;(req.context as Record<string, unknown>)[DIAGNOSTICS_FLOW_CONTEXT_KEY] = flow\n\n const beforeSnapshot = await readMainRowSnapshot({\n collectionSlug,\n fields: snapshotFields,\n id: movedID,\n req,\n })\n\n diagnostics.log({\n collection: collectionSlug,\n data: {\n autosave: updateArgs.autosave ?? null,\n currentParentID,\n draft: updateArgs.draft,\n hasTransaction: Boolean((req as { transactionID?: unknown }).transactionID),\n locale: updateArgs.locale ?? null,\n movedID: String(movedID),\n nextParentID: body.parentID,\n publishedMainRowBefore: beforeSnapshot,\n updateData,\n },\n flow,\n level: 'info',\n message: 'move endpoint entering: parent move only',\n source: 'move-endpoint:enter',\n })\n }\n\n try {\n const result = (await req.payload.update(updateArgs as never)) as\n | (Record<string, unknown> & { _status?: string })\n | undefined\n\n if (diagnostics.enabled) {\n const afterSnapshot = await readMainRowSnapshot({\n collectionSlug,\n fields: snapshotFields,\n id: movedID,\n req,\n })\n\n diagnostics.log({\n collection: collectionSlug,\n data: {\n durMs: Date.now() - moveStart,\n movedID: String(movedID),\n publishedMainRowAfter: afterSnapshot,\n resultStatus: result?._status ?? null,\n },\n flow,\n level: 'info',\n message: 'move endpoint payload.update succeeded',\n source: 'move-endpoint:ok',\n })\n }\n } catch (err) {\n const error = err as { data?: unknown; message?: string; name?: string } & Error\n\n diagnostics.log({\n collection: collectionSlug,\n data: {\n data: error?.data ?? null,\n durMs: Date.now() - moveStart,\n message: error?.message,\n movedID: String(movedID),\n name: error?.name,\n },\n flow,\n level: 'error',\n message: `move endpoint payload.update failed: ${error?.message ?? 'unknown error'}`,\n source: 'move-endpoint:error',\n })\n\n throw err\n }\n\n return respond(200, {\n movedID: movedIDFromRoute,\n ok: true,\r\n parentID: body.parentID,\r\n })\r\n },\r\n method: 'post',\r\n path: '/:id/move',\r\n }\r\n}\r\n"],"names":["DIAGNOSTICS_FLOW_CONTEXT_KEY","createFlowID","readMainRowSnapshot","CANCEL_DRAG_MESSAGE","buildChildrenByParentID","collectDescendantIDs","getDocParentID","stringifyDocID","pageTreeMoveContextKey","assertUpdateAccess","collectionHasAutosaveDrafts","collectionHasDrafts","getRequestedLocale","normalizeID","respond","toCollectionID","SNAPSHOT_FIELDS","hasOwnProperty","value","key","Object","prototype","call","normalizeMoveDocumentBody","incomingData","JSON","parse","Array","isArray","parentID","undefined","readBodyFromRequest","req","lastAttempt","data","raw","source","directBody","body","json","jsonBody","text","textBody","createMovePageEndpoint","args","collectionSlug","diagnostics","parentFieldSlug","snapshotFields","handler","movedIDFromRoute","routeParams","id","message","enabled","log","collection","movedID","rawBody","rawBodySource","flow","level","nextParentID","accessError","docsResult","payload","find","depth","draft","fallbackLocale","limit","locale","overrideAccess","docs","docsByID","Map","map","doc","movedDoc","get","has","currentParentID","childrenByParentID","descendantIDs","includes","moveStart","Date","now","hasDrafts","hasAutosave","updateData","updateArgs","context","autosave","beforeSnapshot","fields","hasTransaction","Boolean","transactionID","String","publishedMainRowBefore","result","update","afterSnapshot","durMs","publishedMainRowAfter","resultStatus","_status","err","error","name","ok","method","path"],"mappings":"AAEA,SACEA,4BAA4B,EAE5BC,YAAY,EACZC,mBAAmB,QACd,8BAA6B;AACpC,SAASC,mBAAmB,QAAQ,iCAAgC;AACpE,SACEC,uBAAuB,EACvBC,oBAAoB,EACpBC,cAAc,EACdC,cAAc,QACT,2BAA0B;AACjC,SAASC,sBAAsB,QAAgC,cAAa;AAC5E,SACEC,kBAAkB,EAClBC,2BAA2B,EAC3BC,mBAAmB,EACnBC,kBAAkB,EAClBC,WAAW,EACXC,OAAO,EACPC,cAAc,QACT,cAAa;AAEpB,MAAMC,kBAAkB;IAAC;CAAU;AAMnC,SAASC,eAAeC,KAAa,EAAEC,GAAgB;IACrD,OAAOC,OAAOC,SAAS,CAACJ,cAAc,CAACK,IAAI,CAACJ,OAAOC;AACrD;AAEA,SAASI,0BAA0BL,KAAc;IAC/C,MAAMM,eACJ,OAAON,UAAU,WACb,AAAC,CAAA;QACC,IAAI;YACF,OAAOO,KAAKC,KAAK,CAACR;QACpB,EAAE,OAAM;YACN,OAAO;QACT;IACF,CAAA,MACAA;IAEN,IAAI,CAACM,gBAAgB,OAAOA,iBAAiB,YAAYG,MAAMC,OAAO,CAACJ,eAAe;QACpF,OAAO;IACT;IAEA,IAAI,CAACP,eAAeO,cAAc,aAAa;QAC7C,OAAO;IACT;IAEA,MAAMK,WAAWhB,YAAY,AAACW,aAAwCK,QAAQ;IAE9E,IACE,AAACL,aAAwCK,QAAQ,KAAK,QACtD,AAACL,aAAwCK,QAAQ,KAAKC,aACtDD,aAAa,MACb;QACA,OAAO;IACT;IAEA,OAAO;QACLA;IACF;AACF;AAOA,eAAeE,oBACbC,GAAmB;IAEnB,IAAIC,cAAqC;IAEzC,IAAID,IAAIE,IA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pBhC,SAASwD,OAAOxD;wBAChBI,SAAS0C,OAAO1C;wBAChBqD,MAAMD,OAAOC;oBACf;oBACAlD;oBACAC,OAAO;oBACPR,SAAS,CAAC,qCAAqC,EAAEwD,OAAOxD,WAAW,iBAAiB;oBACpFjB,QAAQ;gBACV;gBAEA,MAAMwE;YACR;YAEA,OAAO9F,QAAQ,KAAK;gBAClB2C,SAASP;gBACT6D,IAAI;gBACJlF,UAAUS,KAAKT,QAAQ;YACzB;QACF;QACAmF,QAAQ;QACRC,MAAM;IACR;AACF"}
@@ -0,0 +1,8 @@
1
+ import type { Endpoint } from 'payload';
2
+ import { type Diagnostics } from '../utilities/diagnostics.js';
3
+ export declare function createReorderPageEndpoint(args: {
4
+ collectionSlug: string;
5
+ diagnostics: Diagnostics;
6
+ orderableFieldName: string;
7
+ parentFieldSlug: string;
8
+ }): Endpoint;