@nitrogenbuilder/connector-payload 0.1.33 → 0.1.34

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.
@@ -103,7 +103,33 @@ export function createCollectionEndpoints(collectionSlug, endpointPrefix) {
103
103
  if (!data?.title) {
104
104
  return Response.json({ error: 'Title is required' }, { status: 400 });
105
105
  }
106
+ let existingDoc = null;
107
+ try {
108
+ existingDoc = (await payload.findByID({
109
+ collection,
110
+ id,
111
+ depth: 0,
112
+ disableErrors: true,
113
+ }));
114
+ }
115
+ catch {
116
+ existingDoc = null;
117
+ }
106
118
  const updateData = { title: data.title };
119
+ if (existingDoc) {
120
+ if ('slug' in existingDoc && existingDoc.slug !== undefined) {
121
+ updateData.slug = existingDoc.slug;
122
+ }
123
+ if ('generateSlug' in existingDoc) {
124
+ updateData.generateSlug = false;
125
+ }
126
+ if ('parent' in existingDoc) {
127
+ updateData.parent = existingDoc.parent;
128
+ }
129
+ if ('breadcrumbs' in existingDoc) {
130
+ updateData.breadcrumbs = [];
131
+ }
132
+ }
107
133
  if (data.author) {
108
134
  updateData.author = data.author;
109
135
  }
@@ -114,11 +140,30 @@ export function createCollectionEndpoints(collectionSlug, endpointPrefix) {
114
140
  if (data.settings !== undefined) {
115
141
  updateData.pageSettings = data.settings;
116
142
  }
117
- await payload.update({
118
- collection,
119
- id,
120
- data: updateData,
121
- });
143
+ try {
144
+ await payload.update({
145
+ collection,
146
+ id,
147
+ data: updateData,
148
+ depth: 0,
149
+ overrideAccess: true,
150
+ req,
151
+ });
152
+ }
153
+ catch (error) {
154
+ payload.logger.error({
155
+ msg: 'Nitrogen page update failed',
156
+ collection,
157
+ id,
158
+ error,
159
+ });
160
+ return Response.json({
161
+ error: error instanceof Error ? error.message : 'Failed to update page',
162
+ details: error && typeof error === 'object' && 'data' in error
163
+ ? error.data
164
+ : undefined,
165
+ }, { status: 400 });
166
+ }
122
167
  return Response.json({ success: true });
123
168
  },
124
169
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitrogenbuilder/connector-payload",
3
- "version": "0.1.33",
3
+ "version": "0.1.34",
4
4
  "description": "Nitrogen page builder connector plugin for Payload CMS 3.x",
5
5
  "author": "Leonardo Dentzien <leo@torchmedia.ca>",
6
6
  "type": "module",