@nitrogenbuilder/connector-payload 0.1.30 → 0.1.31

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.
@@ -81,6 +81,16 @@ export const NitrogenTemplates = {
81
81
  },
82
82
  },
83
83
  },
84
+ {
85
+ name: 'templateConditions',
86
+ type: 'json',
87
+ admin: {
88
+ description: 'Template conditions used by the Nitrogen editor',
89
+ components: {
90
+ Field: '@nitrogenbuilder/connector-payload/components/NitrogenDataViewer',
91
+ },
92
+ },
93
+ },
84
94
  ],
85
95
  },
86
96
  ],
@@ -3,6 +3,9 @@ import { buildPermalink, buildRelativePermalink } from '../collection-registry';
3
3
  function isContentTemplateCollection(collection) {
4
4
  return !!collection && collection !== 'header' && collection !== 'footer';
5
5
  }
6
+ function getTemplateConditions(doc) {
7
+ return doc.templateConditions ?? { conditionGroups: [] };
8
+ }
6
9
  function getTemplatePreviewTarget(doc, settings, associatedCollection, associatedDoc) {
7
10
  const previewCollection = associatedDoc && isContentTemplateCollection(associatedCollection)
8
11
  ? associatedCollection
@@ -65,6 +68,7 @@ export const templatesEndpoints = [
65
68
  permalink: previewTarget.permalink,
66
69
  relative_permalink: previewTarget.relative_permalink,
67
70
  postType: associatedCollection || '',
71
+ templateConditions: getTemplateConditions(doc),
68
72
  headerTemplate: isContentTemplateCollection(associatedCollection) ? headerTemplate : null,
69
73
  footerTemplate: isContentTemplateCollection(associatedCollection) ? footerTemplate : null,
70
74
  });
@@ -151,6 +155,7 @@ export const templatesEndpoints = [
151
155
  permalink: previewTarget.permalink,
152
156
  relative_permalink: previewTarget.relative_permalink,
153
157
  postType: associatedCollection || '',
158
+ templateConditions: getTemplateConditions(doc),
154
159
  headerTemplate: isContentTemplateCollection(associatedCollection) ? headerTemplate : null,
155
160
  footerTemplate: isContentTemplateCollection(associatedCollection) ? footerTemplate : null,
156
161
  });
@@ -172,10 +177,13 @@ export const templatesEndpoints = [
172
177
  const id = routeParams?.id;
173
178
  const body = (await req.json?.());
174
179
  const data = (body?.data && typeof body.data === 'object') ? body.data : body;
175
- if (!data?.title) {
176
- return Response.json({ error: 'Title is required' }, { status: 400 });
180
+ if (!data) {
181
+ return Response.json({ error: 'No update data provided' }, { status: 400 });
182
+ }
183
+ const updateData = {};
184
+ if (data.title !== undefined) {
185
+ updateData.title = data.title;
177
186
  }
178
- const updateData = { title: data.title };
179
187
  if (data.author) {
180
188
  updateData.author = data.author;
181
189
  }
@@ -189,6 +197,12 @@ export const templatesEndpoints = [
189
197
  if (data.settings !== undefined) {
190
198
  updateData.templateSettings = data.settings;
191
199
  }
200
+ if (data.conditions !== undefined) {
201
+ updateData.templateConditions = data.conditions;
202
+ }
203
+ if (Object.keys(updateData).length === 0) {
204
+ return Response.json({ error: 'No update data provided' }, { status: 400 });
205
+ }
192
206
  await payload.update({
193
207
  collection: 'nitrogen-templates',
194
208
  id,
package/dist/types.d.ts CHANGED
@@ -28,6 +28,7 @@ export interface NitrogenTemplateDoc extends NitrogenDocBase {
28
28
  templateType?: string;
29
29
  associatedCollection?: string;
30
30
  templateSettings?: JsonObject;
31
+ templateConditions?: JsonObject;
31
32
  }
32
33
  export interface NitrogenSettingsGlobal {
33
34
  licenseKey?: string;
@@ -99,6 +100,7 @@ export interface TemplateUpdateRequestBody {
99
100
  data_content?: string | JsonObject[];
100
101
  templateType?: string;
101
102
  settings?: JsonObject;
103
+ conditions?: JsonObject;
102
104
  }
103
105
  interface TemplateUpdateData {
104
106
  title?: string;
@@ -106,6 +108,7 @@ interface TemplateUpdateData {
106
108
  data?: string | JsonObject[];
107
109
  templateType?: string;
108
110
  settings?: JsonObject;
111
+ conditions?: JsonObject;
109
112
  }
110
113
  export interface SlugLookupRequestBody {
111
114
  slug?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitrogenbuilder/connector-payload",
3
- "version": "0.1.30",
3
+ "version": "0.1.31",
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",