@lhi/n8m 0.2.4 → 0.3.1

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.
@@ -128,13 +128,56 @@ export class N8nClient {
128
128
  */
129
129
  async updateWorkflow(workflowId, workflowData) {
130
130
  try {
131
- const sanitized = this.sanitizeSettings(workflowData);
132
- const response = await fetch(`${this.apiUrl}/workflows/${workflowId}`, {
133
- body: JSON.stringify(sanitized),
134
- headers: this.headers,
135
- method: 'PUT',
136
- });
137
- await this.assertOk(response, 'update workflow');
131
+ const w = workflowData;
132
+ const settings = { ...(w.settings || {}) };
133
+ delete settings.timezone;
134
+ const SAFE_NODE_PROPS = new Set([
135
+ 'id', 'name', 'type', 'typeVersion', 'position', 'parameters',
136
+ 'credentials', 'disabled', 'webhookId', 'notes', 'notesInFlow',
137
+ 'continueOnFail', 'alwaysOutputData', 'executeOnce', 'retryOnFail',
138
+ 'maxTries', 'waitBetweenTries',
139
+ ]);
140
+ const buildPayload = (sanitizeNodes, includeVersionId) => {
141
+ const nodes = sanitizeNodes
142
+ ? (w.nodes || []).map((node) => {
143
+ const clean = {};
144
+ for (const key of Object.keys(node)) {
145
+ if (SAFE_NODE_PROPS.has(key))
146
+ clean[key] = node[key];
147
+ }
148
+ return clean;
149
+ })
150
+ : w.nodes;
151
+ const payload = {
152
+ name: w.name,
153
+ nodes,
154
+ connections: w.connections,
155
+ settings,
156
+ };
157
+ if (includeVersionId && w.versionId)
158
+ payload.versionId = w.versionId;
159
+ return payload;
160
+ };
161
+ const attempts = [
162
+ buildPayload(false, true), // full nodes + versionId
163
+ buildPayload(true, true), // sanitized nodes + versionId
164
+ buildPayload(true, false), // sanitized nodes, no versionId
165
+ ];
166
+ let response;
167
+ let errorText = '';
168
+ for (const payload of attempts) {
169
+ response = await fetch(`${this.apiUrl}/workflows/${workflowId}`, {
170
+ body: JSON.stringify(payload),
171
+ headers: this.headers,
172
+ method: 'PUT',
173
+ });
174
+ if (response.ok)
175
+ return;
176
+ errorText = await response.text();
177
+ if (response.status !== 400 || !errorText.includes('additional properties'))
178
+ break;
179
+ }
180
+ throw new Error(`update workflow failed: ${response.status} - ${errorText}`);
138
181
  }
139
182
  catch (error) {
140
183
  throw new Error(`Failed to update workflow: ${error.message}`);
@@ -174,10 +217,15 @@ export class N8nClient {
174
217
  */
175
218
  async createWorkflow(name, workflowData) {
176
219
  try {
177
- const payload = this.sanitizeSettings({
220
+ const w = workflowData;
221
+ const settings = { ...(w.settings || {}) };
222
+ delete settings.timezone;
223
+ const payload = {
178
224
  name,
179
- ...workflowData,
180
- });
225
+ nodes: w.nodes ?? [],
226
+ connections: w.connections ?? {},
227
+ settings,
228
+ };
181
229
  const response = await fetch(`${this.apiUrl}/workflows`, {
182
230
  body: JSON.stringify(payload),
183
231
  headers: this.headers,
@@ -257,7 +305,7 @@ export class N8nClient {
257
305
  allWorkflows = [...allWorkflows, ...result.data];
258
306
  cursor = result.nextCursor;
259
307
  } while (cursor);
260
- return allWorkflows;
308
+ return allWorkflows.filter((w) => !w.isArchived);
261
309
  }
262
310
  catch (error) {
263
311
  throw new Error(`Failed to fetch workflows: ${error.message}`);
@@ -503,6 +551,7 @@ export class N8nClient {
503
551
  mode: 'runOnceForAllItems',
504
552
  jsCode: N8nClient.buildNetworkShimCode(node.type),
505
553
  },
554
+ ...(node.onError ? { onError: node.onError } : {}),
506
555
  };
507
556
  });
508
557
  }