@connectorx/n8n-nodes-cortex 0.1.24 → 0.1.25

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.
@@ -230,10 +230,8 @@ class Cortex {
230
230
  {
231
231
  displayName: 'Template Variables',
232
232
  name: 'template_variables',
233
- type: 'fixedCollection',
234
- typeOptions: {
235
- multipleValues: true,
236
- },
233
+ type: 'resourceMapper',
234
+ noDataExpression: true,
237
235
  displayOptions: {
238
236
  show: {
239
237
  resource: ['message'],
@@ -241,23 +239,24 @@ class Cortex {
241
239
  msg_type: ['template'],
242
240
  },
243
241
  },
244
- default: {},
245
- options: [
246
- {
247
- name: 'variable',
248
- displayName: 'Variable',
249
- values: [
250
- {
251
- displayName: 'Value',
252
- name: 'value',
253
- type: 'string',
254
- default: '',
255
- description: 'Variable value — fill in the same order as shown in the template dropdown',
256
- },
257
- ],
242
+ default: {
243
+ mappingMode: 'defineBelow',
244
+ value: null,
245
+ },
246
+ typeOptions: {
247
+ loadOptionsDependsOn: ['template_id'],
248
+ resourceMapper: {
249
+ resourceMapperMethod: 'getTemplateVariableFields',
250
+ mode: 'add',
251
+ fieldWords: {
252
+ singular: 'variável',
253
+ plural: 'variáveis',
254
+ },
255
+ addAllFields: true,
256
+ noFieldsError: 'Selecione um template primeiro',
257
+ multiKeyMatch: false,
258
258
  },
259
- ],
260
- description: 'Fill in the template variable values in the same order as shown in the template dropdown (e.g. "Vars: nome, email" → 1st value = nome, 2nd value = email)',
259
+ },
261
260
  },
262
261
  {
263
262
  displayName: 'Sender ID',
@@ -518,6 +517,31 @@ class Cortex {
518
517
  }
519
518
  },
520
519
  },
520
+ resourceMapping: {
521
+ async getTemplateVariableFields() {
522
+ try {
523
+ const templateDataStr = this.getNodeParameter('template_id');
524
+ if (!templateDataStr)
525
+ return { fields: [] };
526
+ const templateData = JSON.parse(templateDataStr);
527
+ const vars = (templateData.variables || []);
528
+ return {
529
+ fields: vars.map((v) => ({
530
+ id: v.name,
531
+ displayName: v.name.toUpperCase(),
532
+ required: true,
533
+ defaultMatch: false,
534
+ display: true,
535
+ type: 'string',
536
+ canBeUsedToMatch: false,
537
+ })),
538
+ };
539
+ }
540
+ catch (e) {
541
+ return { fields: [] };
542
+ }
543
+ },
544
+ },
521
545
  };
522
546
  }
523
547
  async execute() {
@@ -576,22 +600,21 @@ class Cortex {
576
600
  catch (e) {
577
601
  throw new Error('Invalid template selection');
578
602
  }
579
- const varsCollection = (() => { try {
603
+ const varsData = (() => { try {
580
604
  return this.getNodeParameter('template_variables', i, {});
581
605
  }
582
606
  catch (_e) {
583
607
  return {};
584
608
  } })();
585
- const userValues = ((varsCollection === null || varsCollection === void 0 ? void 0 : varsCollection.variable) || []).map((v) => v.value || '');
609
+ const userValues = (varsData === null || varsData === void 0 ? void 0 : varsData.value) || {};
586
610
  const templateVars = templateData.variables || [];
587
611
  const components = [];
588
612
  const headerVars = templateVars.filter((v) => v.component === 'header');
589
613
  const bodyVars = templateVars.filter((v) => v.component === 'body');
590
- let valueIdx = 0;
591
614
  if (headerVars.length > 0) {
592
615
  const params = headerVars.map((tv) => {
593
616
  const isPositional = /^Variável \d+$/.test(tv.name);
594
- const param = { type: 'text', text: userValues[valueIdx++] || '' };
617
+ const param = { type: 'text', text: userValues[tv.name] || '' };
595
618
  if (!isPositional)
596
619
  param.parameter_name = tv.name;
597
620
  return param;
@@ -601,7 +624,7 @@ class Cortex {
601
624
  if (bodyVars.length > 0) {
602
625
  const params = bodyVars.map((tv) => {
603
626
  const isPositional = /^Variável \d+$/.test(tv.name);
604
- const param = { type: 'text', text: userValues[valueIdx++] || '' };
627
+ const param = { type: 'text', text: userValues[tv.name] || '' };
605
628
  if (!isPositional)
606
629
  param.parameter_name = tv.name;
607
630
  return param;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@connectorx/n8n-nodes-cortex",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "description": "n8n nodes for Cortex API",
5
5
  "keywords": [
6
6
  "n8n-community-node-package"