n8n-nodes-syncmate 1.0.21 → 1.0.23

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.
@@ -0,0 +1,7 @@
1
+ import { ICredentialType, INodeProperties } from 'n8n-workflow';
2
+ export declare class AssistroTokenApi implements ICredentialType {
3
+ name: string;
4
+ displayName: string;
5
+ documentationUrl: string;
6
+ properties: INodeProperties[];
7
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AssistroTokenApi = void 0;
4
+ class AssistroTokenApi {
5
+ constructor() {
6
+ this.name = 'assistroTokenApi';
7
+ this.displayName = 'Assistro API Token';
8
+ this.documentationUrl = 'https://docs.assistro.co/api';
9
+ this.properties = [
10
+ {
11
+ displayName: 'Access Token',
12
+ name: 'accessToken',
13
+ type: 'string',
14
+ typeOptions: { password: true },
15
+ default: '',
16
+ description: 'The JWT Access Token provided by Assistro',
17
+ },
18
+ ];
19
+ }
20
+ }
21
+ exports.AssistroTokenApi = AssistroTokenApi;
@@ -19,12 +19,42 @@ class WhatsAuto {
19
19
  outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
20
20
  usableAsTool: true,
21
21
  credentials: [
22
+ {
23
+ name: 'assistroTokenApi',
24
+ required: true,
25
+ displayOptions: {
26
+ show: {
27
+ authentication: ['jwt'],
28
+ },
29
+ },
30
+ },
22
31
  {
23
32
  name: 'assistroOAuth2Api',
24
33
  required: true,
34
+ displayOptions: {
35
+ show: {
36
+ authentication: ['oAuth2'],
37
+ },
38
+ },
25
39
  },
26
40
  ],
27
41
  properties: [
42
+ {
43
+ displayName: 'Authentication',
44
+ name: 'authentication',
45
+ type: 'options',
46
+ options: [
47
+ {
48
+ name: 'API Token (JWT)',
49
+ value: 'jwt',
50
+ },
51
+ {
52
+ name: 'OAuth2',
53
+ value: 'oAuth2',
54
+ },
55
+ ],
56
+ default: 'jwt',
57
+ },
28
58
  {
29
59
  displayName: 'Resource',
30
60
  name: 'resource',
@@ -197,9 +227,10 @@ class WhatsAuto {
197
227
  };
198
228
  }
199
229
  async execute() {
200
- var _a, _b, _c;
230
+ var _a;
201
231
  const items = this.getInputData();
202
232
  const returnData = [];
233
+ const authMethod = this.getNodeParameter('authentication', 0);
203
234
  for (let i = 0; i < items.length; i++) {
204
235
  try {
205
236
  const operation = this.getNodeParameter('operation', i);
@@ -222,7 +253,7 @@ class WhatsAuto {
222
253
  }
223
254
  body = { msgs: [msgObj] };
224
255
  }
225
- if (operation === 'group') {
256
+ else if (operation === 'group') {
226
257
  const groupId = this.getNodeParameter('groupId', i);
227
258
  const message = this.getNodeParameter('message', i);
228
259
  const mediaFiles = this.getNodeParameter('mediaFiles', i);
@@ -243,7 +274,7 @@ class WhatsAuto {
243
274
  }
244
275
  body = { msgs: [msgObj] };
245
276
  }
246
- if (operation === 'newsletter') {
277
+ else if (operation === 'newsletter') {
247
278
  const newsletterId = this.getNodeParameter('newsletterId', i);
248
279
  const message = this.getNodeParameter('newsletterMessage', i);
249
280
  let cleanNewsletterId = newsletterId.trim();
@@ -258,16 +289,32 @@ class WhatsAuto {
258
289
  }],
259
290
  };
260
291
  }
261
- const response = await this.helpers.httpRequestWithAuthentication.call(this, 'assistroOAuth2Api', {
292
+ let endpointUri = '';
293
+ if (authMethod === 'oAuth2') {
294
+ endpointUri = 'https://app.assistro.co/api/v1/wapushplus/singlePass/message';
295
+ }
296
+ else {
297
+ endpointUri = 'https://app.assistro.co/api/v1/wapushplus/single/message';
298
+ }
299
+ const requestOptions = {
262
300
  method: 'POST',
263
- url: 'https://app.assistro.co/api/v1/wapushplus/singlePass/message',
301
+ url: endpointUri,
264
302
  headers: {
265
303
  'Content-Type': 'application/json',
266
304
  'Integration': 'n8n',
267
305
  },
268
306
  body,
269
307
  json: true,
270
- });
308
+ };
309
+ let response;
310
+ if (authMethod === 'oAuth2') {
311
+ response = await this.helpers.httpRequestWithAuthentication.call(this, 'assistroOAuth2Api', requestOptions);
312
+ }
313
+ else {
314
+ const credentials = await this.getCredentials('assistroTokenApi');
315
+ requestOptions.headers['Authorization'] = `Bearer ${credentials.accessToken}`;
316
+ response = await this.helpers.httpRequest(requestOptions);
317
+ }
271
318
  returnData.push({
272
319
  json: response,
273
320
  pairedItem: { item: i },
@@ -278,18 +325,13 @@ class WhatsAuto {
278
325
  returnData.push({
279
326
  json: {
280
327
  error: error.message,
328
+ details: ((_a = error.response) === null || _a === void 0 ? void 0 : _a.body) || undefined,
281
329
  },
282
330
  pairedItem: { item: i },
283
331
  });
284
332
  continue;
285
333
  }
286
- if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401 || ((_b = error.response) === null || _b === void 0 ? void 0 : _b.status) === 403) {
287
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Authentication failed. Please reconnect your OAuth credentials.', { itemIndex: i });
288
- }
289
- if (((_c = error.response) === null || _c === void 0 ? void 0 : _c.status) === 500) {
290
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Server error. Your access token may have expired. Please reconnect OAuth credentials.', { itemIndex: i });
291
- }
292
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Failed to send message: ${error.message}`, { itemIndex: i });
334
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
293
335
  }
294
336
  }
295
337
  return [returnData];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-syncmate",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "description": "Send WhatsApp messages or media using SyncMate Assistro API.",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",