n8n-nodes-salvia 0.2.0 → 0.3.0

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.
@@ -6,8 +6,16 @@ const STAGE_TYPE_LABEL = {
6
6
  won: " (ganho)",
7
7
  lost: " (perda)",
8
8
  };
9
+ const FIELD_TYPE_LABEL = {
10
+ text: "texto",
11
+ number: "número",
12
+ date: "data",
13
+ datetime: "data e hora",
14
+ boolean: "sim/não",
15
+ select: "seleção",
16
+ };
9
17
  async function fetchCatalog(ctx) {
10
- var _a, _b;
18
+ var _a, _b, _c, _d;
11
19
  const creds = (await ctx.getCredentials("salviaApi"));
12
20
  const res = (await ctx.helpers.httpRequestWithAuthentication.call(ctx, "salviaApi", {
13
21
  method: "GET",
@@ -15,21 +23,24 @@ async function fetchCatalog(ctx) {
15
23
  url: "/api/v1/catalog",
16
24
  json: true,
17
25
  }));
18
- return (_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.pipelines) !== null && _b !== void 0 ? _b : [];
26
+ return {
27
+ pipelines: (_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.pipelines) !== null && _b !== void 0 ? _b : [],
28
+ customFields: (_d = (_c = res.data) === null || _c === void 0 ? void 0 : _c.customFields) !== null && _d !== void 0 ? _d : [],
29
+ };
19
30
  }
20
31
  class Salvia {
21
32
  constructor() {
22
33
  this.methods = {
23
34
  loadOptions: {
24
35
  async getPipelines() {
25
- const pipelines = await fetchCatalog(this);
36
+ const { pipelines } = await fetchCatalog(this);
26
37
  return [
27
38
  { name: "— Funil padrão do Salvia —", value: "" },
28
39
  ...pipelines.map((p) => ({ name: p.name, value: p.id })),
29
40
  ];
30
41
  },
31
42
  async getStages() {
32
- const pipelines = await fetchCatalog(this);
43
+ const { pipelines } = await fetchCatalog(this);
33
44
  const pipelineId = this.getCurrentNodeParameter("pipelineId") || "";
34
45
  // Sem funil escolhido, lista as etapas de todos com o funil no rótulo —
35
46
  // escolher a etapa já basta (a API deriva o funil dela).
@@ -46,6 +57,20 @@ class Salvia {
46
57
  })),
47
58
  ];
48
59
  },
60
+ async getCustomFields() {
61
+ const { customFields } = await fetchCatalog(this);
62
+ return customFields.map((f) => {
63
+ var _a;
64
+ const opt = {
65
+ name: `${f.label} (${(_a = FIELD_TYPE_LABEL[f.type]) !== null && _a !== void 0 ? _a : f.type})`,
66
+ value: f.key,
67
+ };
68
+ if (f.type === "select" && f.options.length) {
69
+ opt.description = `Opções: ${f.options.join(", ")}`;
70
+ }
71
+ return opt;
72
+ });
73
+ },
49
74
  },
50
75
  };
51
76
  this.description = {
@@ -191,6 +216,45 @@ class Salvia {
191
216
  },
192
217
  },
193
218
  },
219
+ {
220
+ displayName: "Campos personalizados",
221
+ name: "customFieldsUi",
222
+ type: "fixedCollection",
223
+ typeOptions: { multipleValues: true },
224
+ placeholder: "Adicionar campo personalizado",
225
+ default: {},
226
+ description: "Campos criados na sua conta do Salvia. O dropdown carrega direto de lá — crie o campo no Salvia e ele aparece aqui.",
227
+ displayOptions: { show: { resource: ["lead"], operation: ["create"] } },
228
+ options: [
229
+ {
230
+ displayName: "Campo",
231
+ name: "values",
232
+ values: [
233
+ {
234
+ displayName: "Campo",
235
+ name: "key",
236
+ type: "options",
237
+ typeOptions: { loadOptionsMethod: "getCustomFields" },
238
+ default: "",
239
+ },
240
+ {
241
+ displayName: "Valor",
242
+ name: "value",
243
+ type: "string",
244
+ default: "",
245
+ },
246
+ ],
247
+ },
248
+ ],
249
+ routing: {
250
+ send: {
251
+ type: "body",
252
+ property: "customFields",
253
+ // Vira {"chave": "valor"} no corpo; sem linhas preenchidas, nem vai.
254
+ value: "={{ (($value && $value.values) || []).filter(v => v.key).length ? Object.fromEntries($value.values.filter(v => v.key).map(v => [v.key, v.value])) : undefined }}",
255
+ },
256
+ },
257
+ },
194
258
  {
195
259
  displayName: "Opções adicionais",
196
260
  name: "additionalFields",
@@ -207,20 +271,6 @@ class Salvia {
207
271
  description: "Email de um usuário do Salvia que vira dono do lead",
208
272
  routing: { send: { type: "body", property: "ownerEmail" } },
209
273
  },
210
- {
211
- displayName: "Campos personalizados (JSON)",
212
- name: "customFields",
213
- type: "json",
214
- default: "{}",
215
- description: 'Ex.: {"convenio": "Unimed", "procedimento": "Botox"}',
216
- routing: {
217
- send: {
218
- type: "body",
219
- property: "customFields",
220
- value: "={{ typeof $value === 'string' ? JSON.parse($value || '{}') : $value }}",
221
- },
222
- },
223
- },
224
274
  {
225
275
  displayName: "UTM Source",
226
276
  name: "utmSource",
package/package.json CHANGED
@@ -1,41 +1,41 @@
1
- {
2
- "name": "n8n-nodes-salvia",
3
- "version": "0.2.0",
4
- "description": "Nodes do Salvia CRM para n8n — crie leads e integre sua clínica aos seus fluxos.",
5
- "keywords": [
6
- "n8n-community-node-package",
7
- "salvia",
8
- "crm",
9
- "whatsapp"
10
- ],
11
- "license": "MIT",
12
- "author": "MovMed <pedro@grupomovmed.com.br>",
13
- "repository": {
14
- "type": "git",
15
- "url": "https://github.com/Projetos-Mov/n8n-nodes-salvia.git"
16
- },
17
- "main": "index.js",
18
- "scripts": {
19
- "build": "tsc && node scripts/copy-assets.js"
20
- },
21
- "files": [
22
- "dist"
23
- ],
24
- "n8n": {
25
- "n8nNodesApiVersion": 1,
26
- "credentials": [
27
- "dist/credentials/SalviaApi.credentials.js"
28
- ],
29
- "nodes": [
30
- "dist/nodes/Salvia/Salvia.node.js"
31
- ]
32
- },
33
- "devDependencies": {
34
- "@types/node": "^20.14.0",
35
- "n8n-workflow": "^1.70.0",
36
- "typescript": "^5.5.0"
37
- },
38
- "peerDependencies": {
39
- "n8n-workflow": "*"
40
- }
41
- }
1
+ {
2
+ "name": "n8n-nodes-salvia",
3
+ "version": "0.3.0",
4
+ "description": "Nodes do Salvia CRM para n8n — crie leads e integre sua clínica aos seus fluxos.",
5
+ "keywords": [
6
+ "n8n-community-node-package",
7
+ "salvia",
8
+ "crm",
9
+ "whatsapp"
10
+ ],
11
+ "license": "MIT",
12
+ "author": "MovMed <pedro@grupomovmed.com.br>",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/Projetos-Mov/n8n-nodes-salvia.git"
16
+ },
17
+ "main": "index.js",
18
+ "scripts": {
19
+ "build": "tsc && node scripts/copy-assets.js"
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "n8n": {
25
+ "n8nNodesApiVersion": 1,
26
+ "credentials": [
27
+ "dist/credentials/SalviaApi.credentials.js"
28
+ ],
29
+ "nodes": [
30
+ "dist/nodes/Salvia/Salvia.node.js"
31
+ ]
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^20.14.0",
35
+ "n8n-workflow": "^1.70.0",
36
+ "typescript": "^5.5.0"
37
+ },
38
+ "peerDependencies": {
39
+ "n8n-workflow": "*"
40
+ }
41
+ }