n8n-nodes-atendix 1.3.0 → 1.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.
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  /**
3
3
  * n8n-nodes-atendix — Credenciais Tray Commerce
4
- * v1.3.0CORREÇÃO CRÍTICA:
5
- * URL: {store_id}.commercesuite.com.br/web_api (api.tray.com.br não existe)
6
- * consumer_key/secret agora são campos de credencial (não env vars)
4
+ * v1.3.1Reverte UX para API Address + Auth Code apenas
5
+ * consumer_key/secret são do Atendix (process.env no servidor)
6
+ * URL padrão corrigida: {store}.commercesuite.com.br/web_api
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.TrayApiAuto = void 0;
@@ -19,30 +19,13 @@ class TrayApiAuto {
19
19
  this.documentationUrl = 'https://developers.tray.com.br/docs/';
20
20
  this.properties = [
21
21
  {
22
- displayName: 'Store ID',
23
- name: 'storeId',
22
+ displayName: 'API Address',
23
+ name: 'apiAddress',
24
24
  type: 'string',
25
25
  default: '',
26
26
  required: true,
27
- placeholder: '1225878',
28
- description: 'ID da sua loja Tray. A URL base (https://{storeId}.commercesuite.com.br/web_api) é gerada automaticamente.',
29
- },
30
- {
31
- displayName: 'Consumer Key',
32
- name: 'consumerKey',
33
- type: 'string',
34
- default: '',
35
- required: true,
36
- description: 'Consumer Key fornecida pela Tray no painel de apps',
37
- },
38
- {
39
- displayName: 'Consumer Secret',
40
- name: 'consumerSecret',
41
- type: 'string',
42
- typeOptions: { password: true },
43
- default: '',
44
- required: true,
45
- description: 'Consumer Secret fornecido pela Tray no painel de apps',
27
+ placeholder: 'https://1225878.commercesuite.com.br/web_api',
28
+ description: 'URL base da API da sua loja Tray. Formato: https://{storeId}.commercesuite.com.br/web_api',
46
29
  },
47
30
  {
48
31
  displayName: 'Authorization Code',
@@ -60,33 +43,28 @@ class TrayApiAuto {
60
43
  { displayName: 'Token Expiration',name: 'tokenExpiration',type: 'hidden', default: '' },
61
44
  { displayName: 'API Host', name: 'apiHost', type: 'hidden', default: '' },
62
45
  ];
46
+
63
47
  this.authenticate = {
64
48
  type: 'generic',
65
49
  properties: {
66
50
  qs: { access_token: '={{$credentials.accessToken}}' },
67
51
  },
68
52
  };
53
+
69
54
  this.test = {
70
55
  request: {
71
- baseURL: '={{`https://${$credentials.storeId}.commercesuite.com.br/web_api`}}',
56
+ baseURL: '={{$credentials.apiAddress}}',
72
57
  url: '/auth',
73
58
  method: 'POST',
74
59
  body: {
75
- consumer_key: '={{$credentials.consumerKey}}',
76
- consumer_secret: '={{$credentials.consumerSecret}}',
60
+ consumer_key: process.env.TRAY_CONSUMER_KEY,
61
+ consumer_secret: process.env.TRAY_CONSUMER_SECRET,
77
62
  code: '={{$credentials.authCode}}',
78
63
  },
79
64
  },
80
65
  };
81
66
  }
82
67
 
83
- _buildBaseUrl(credentials) {
84
- const storeId = (credentials.storeId || '').toString().trim();
85
- if (!storeId) throw new Error('[Atendix] Store ID não configurado nas credenciais');
86
- // v1.3.0 FIX: URL correta — api.tray.com.br não existe
87
- return `https://${storeId}.commercesuite.com.br/web_api`;
88
- }
89
-
90
68
  async preAuthentication(credentials) {
91
69
  const now = new Date();
92
70
  const tokenExpiration = credentials.tokenExpiration
@@ -102,16 +80,31 @@ class TrayApiAuto {
102
80
  return await this._authenticateFlow(credentials);
103
81
  }
104
82
 
83
+ _buildBaseUrl(credentials) {
84
+ const addr = (credentials.apiAddress || '').toString().trim().replace(/\/$/, '');
85
+ if (!addr) throw new Error('[Atendix] API Address não configurado nas credenciais');
86
+ return addr;
87
+ }
88
+
105
89
  async _authenticateFlow(credentials) {
106
90
  const baseUrl = this._buildBaseUrl(credentials);
107
- console.log(`[Atendix v1.3.0] Autenticando em: ${baseUrl}/auth`);
91
+
92
+ // consumer_key e consumer_secret são do Atendix — ficam em process.env no servidor N8N
93
+ const consumerKey = process.env.TRAY_CONSUMER_KEY;
94
+ const consumerSecret = process.env.TRAY_CONSUMER_SECRET;
95
+
96
+ if (!consumerKey || !consumerSecret) {
97
+ throw new Error('[Atendix] Variáveis TRAY_CONSUMER_KEY / TRAY_CONSUMER_SECRET não configuradas no servidor N8N. Contate o suporte Atendix.');
98
+ }
99
+
100
+ console.log(`[Atendix v1.3.1] Autenticando em: ${baseUrl}/auth`);
108
101
 
109
102
  const response = await fetch(`${baseUrl}/auth`, {
110
103
  method: 'POST',
111
104
  headers: { 'Content-Type': 'application/json' },
112
105
  body: JSON.stringify({
113
- consumer_key: credentials.consumerKey,
114
- consumer_secret: credentials.consumerSecret,
106
+ consumer_key: consumerKey,
107
+ consumer_secret: consumerSecret,
115
108
  code: credentials.authCode,
116
109
  }),
117
110
  });
@@ -122,7 +115,7 @@ class TrayApiAuto {
122
115
  throw new Error(data.message || `Erro HTTP ${response.status} na autenticação Tray`);
123
116
  }
124
117
 
125
- console.log('[Atendix v1.3.0] Autenticação OK ✓');
118
+ console.log('[Atendix v1.3.1] Autenticação OK ✓');
126
119
  return {
127
120
  ...credentials,
128
121
  accessToken: data.access_token,
@@ -219,19 +219,19 @@ class Atendix {
219
219
 
220
220
  // Credenciais (n8n chama preAuthentication automaticamente)
221
221
  const credentials = await this.getCredentials('trayApiAuto');
222
- const storeId = (credentials.storeId || '').toString().trim();
223
222
 
224
- if (!storeId) {
223
+ // v1.3.1: URL vem do campo apiAddress preenchido pelo usuário
224
+ // Ex: https://1225878.commercesuite.com.br/web_api
225
+ const baseUrl = (credentials.apiAddress || '').toString().trim().replace(/\/$/, '');
226
+ const accessToken = credentials.accessToken;
227
+
228
+ if (!baseUrl) {
225
229
  throw new n8n_workflow_1.NodeOperationError(
226
230
  this.getNode(),
227
- 'Store ID não configurado nas credenciais Atendix. Preencha o campo Store ID.',
231
+ 'API Address não configurado nas credenciais Atendix. Preencha com a URL da sua loja.',
228
232
  );
229
233
  }
230
234
 
231
- // v1.3.0: URL derivada do store_id — nunca mais hardcoded
232
- const baseUrl = `https://${storeId}.commercesuite.com.br/web_api`;
233
- const accessToken = credentials.accessToken;
234
-
235
235
  for (let i = 0; i < items.length; i++) {
236
236
  try {
237
237
  if (i > 0) await wait(500); // Rate-limit seguro: ~120 req/min (limite Tray: 180)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-atendix",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Conector Atendix para integração nativa com a Tray Commerce",
5
5
  "keywords": ["n8n-community-node-package"],
6
6
  "license": "MIT",