n8n-nodes-didar-crm 0.0.16 → 0.0.18

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.
@@ -13,7 +13,95 @@ async function noteCreate(i, returnData) {
13
13
  const doneDateUi = this.getNodeParameter('DoneDate', i, '');
14
14
  const dealId = this.getNodeParameter('DealId', i, ZERO_GUID);
15
15
  const caseId = this.getNodeParameter('CaseId', i, ZERO_GUID);
16
- const contactIds = this.getNodeParameter('ContactIds', i, []);
16
+ // const contactIds = this.getNodeParameter('ContactIds', i, []) as string[];
17
+ // ContactIds
18
+ const rawContactIds = this.getNodeParameter('ContactIds', i, []);
19
+ const parseIdList = (input) => {
20
+ const out = [];
21
+ const pushFromString = (raw) => {
22
+ if (!raw)
23
+ return;
24
+ const s = raw.trim();
25
+ if (!s)
26
+ return;
27
+ // الگوی نمایشی n8n: [Array: [...]]
28
+ const arrayLabel = s.match(/^\s*\[Array:\s*(\[[\s\S]*\])\s*\]\s*$/i);
29
+ if (arrayLabel) {
30
+ try {
31
+ const arr = JSON.parse(arrayLabel[1]);
32
+ recur(arr);
33
+ return;
34
+ }
35
+ catch { /* ignore and fall through */ }
36
+ }
37
+ // اگر JSON array باشد
38
+ if (/^\s*\[/.test(s)) {
39
+ try {
40
+ const arr = JSON.parse(s);
41
+ recur(arr);
42
+ return;
43
+ }
44
+ catch {
45
+ throw new Error('Invalid JSON in "Contact IDs". Expected a JSON array of strings.');
46
+ }
47
+ }
48
+ // در غیر این صورت: CSV / newline / semicolon
49
+ s.split(/[\n,;]+/)
50
+ .map((t) => t.trim())
51
+ .filter(Boolean)
52
+ .forEach((t) => out.push(t));
53
+ };
54
+ const recur = (val) => {
55
+ var _a, _b;
56
+ if (val == null)
57
+ return;
58
+ if (Array.isArray(val)) {
59
+ val.forEach(recur);
60
+ return;
61
+ }
62
+ switch (typeof val) {
63
+ case 'string':
64
+ pushFromString(val);
65
+ return;
66
+ case 'number':
67
+ case 'boolean':
68
+ out.push(String(val));
69
+ return;
70
+ case 'object': {
71
+ const obj = val;
72
+ // Map/Set
73
+ if (val instanceof Set) {
74
+ recur(Array.from(val));
75
+ return;
76
+ }
77
+ if (val instanceof Map) {
78
+ recur(Array.from(val.values()));
79
+ return;
80
+ }
81
+ // Wrapperهای رایج
82
+ if (obj === null || obj === void 0 ? void 0 : obj.values) {
83
+ recur(obj.values);
84
+ return;
85
+ }
86
+ if (obj === null || obj === void 0 ? void 0 : obj.Value) {
87
+ recur(obj.Value);
88
+ return;
89
+ }
90
+ // Fallback: تلاش با toString()
91
+ const s = ((_b = (_a = obj === null || obj === void 0 ? void 0 : obj.toString) === null || _a === void 0 ? void 0 : _a.call(obj)) !== null && _b !== void 0 ? _b : '').toString();
92
+ if (s)
93
+ pushFromString(s);
94
+ return;
95
+ }
96
+ default:
97
+ return;
98
+ }
99
+ };
100
+ recur(input);
101
+ // نرمال‌سازی و حذف تکراری‌ها
102
+ return Array.from(new Set(out.map((x) => x.trim()).filter(Boolean)));
103
+ };
104
+ const contactIdsArr = parseIdList(rawContactIds);
17
105
  // 2) اعتبارسنجی‌های ضروری
18
106
  if (!(resultNote === null || resultNote === void 0 ? void 0 : resultNote.trim())) {
19
107
  throw new Error('ResultNote is required for Note creation.');
@@ -39,7 +127,7 @@ async function noteCreate(i, returnData) {
39
127
  DueDateType: 'NoTime', // ثابت و نامنمایش
40
128
  DoneDateType: 'Notime', // ثابت و نامنمایش
41
129
  DealId: dealId || ZERO_GUID,
42
- ContactIds: Array.isArray(contactIds) ? contactIds : [],
130
+ ContactIds: contactIdsArr,
43
131
  CaseId: caseId || ZERO_GUID,
44
132
  },
45
133
  };
@@ -14,7 +14,95 @@ async function noteUpdate(i, returnData) {
14
14
  const doneDateUi = this.getNodeParameter('DoneDate', i, '');
15
15
  const dealId = this.getNodeParameter('DealId', i, ZERO_GUID);
16
16
  const caseId = this.getNodeParameter('CaseId', i, ZERO_GUID);
17
- const contactIds = this.getNodeParameter('ContactIds', i, []);
17
+ // const contactIds = this.getNodeParameter('ContactIds', i, []) as string[];
18
+ // ContactIds
19
+ const rawContactIds = this.getNodeParameter('ContactIds', i, []);
20
+ const parseIdList = (input) => {
21
+ const out = [];
22
+ const pushFromString = (raw) => {
23
+ if (!raw)
24
+ return;
25
+ const s = raw.trim();
26
+ if (!s)
27
+ return;
28
+ // الگوی نمایشی n8n: [Array: [...]]
29
+ const arrayLabel = s.match(/^\s*\[Array:\s*(\[[\s\S]*\])\s*\]\s*$/i);
30
+ if (arrayLabel) {
31
+ try {
32
+ const arr = JSON.parse(arrayLabel[1]);
33
+ recur(arr);
34
+ return;
35
+ }
36
+ catch { /* ignore and fall through */ }
37
+ }
38
+ // اگر JSON array باشد
39
+ if (/^\s*\[/.test(s)) {
40
+ try {
41
+ const arr = JSON.parse(s);
42
+ recur(arr);
43
+ return;
44
+ }
45
+ catch {
46
+ throw new Error('Invalid JSON in "Contact IDs". Expected a JSON array of strings.');
47
+ }
48
+ }
49
+ // در غیر این صورت: CSV / newline / semicolon
50
+ s.split(/[\n,;]+/)
51
+ .map((t) => t.trim())
52
+ .filter(Boolean)
53
+ .forEach((t) => out.push(t));
54
+ };
55
+ const recur = (val) => {
56
+ var _a, _b;
57
+ if (val == null)
58
+ return;
59
+ if (Array.isArray(val)) {
60
+ val.forEach(recur);
61
+ return;
62
+ }
63
+ switch (typeof val) {
64
+ case 'string':
65
+ pushFromString(val);
66
+ return;
67
+ case 'number':
68
+ case 'boolean':
69
+ out.push(String(val));
70
+ return;
71
+ case 'object': {
72
+ const obj = val;
73
+ // Map/Set
74
+ if (val instanceof Set) {
75
+ recur(Array.from(val));
76
+ return;
77
+ }
78
+ if (val instanceof Map) {
79
+ recur(Array.from(val.values()));
80
+ return;
81
+ }
82
+ // Wrapperهای رایج
83
+ if (obj === null || obj === void 0 ? void 0 : obj.values) {
84
+ recur(obj.values);
85
+ return;
86
+ }
87
+ if (obj === null || obj === void 0 ? void 0 : obj.Value) {
88
+ recur(obj.Value);
89
+ return;
90
+ }
91
+ // Fallback: تلاش با toString()
92
+ const s = ((_b = (_a = obj === null || obj === void 0 ? void 0 : obj.toString) === null || _a === void 0 ? void 0 : _a.call(obj)) !== null && _b !== void 0 ? _b : '').toString();
93
+ if (s)
94
+ pushFromString(s);
95
+ return;
96
+ }
97
+ default:
98
+ return;
99
+ }
100
+ };
101
+ recur(input);
102
+ // نرمال‌سازی و حذف تکراری‌ها
103
+ return Array.from(new Set(out.map((x) => x.trim()).filter(Boolean)));
104
+ };
105
+ const contactIdsArr = parseIdList(rawContactIds);
18
106
  // 2) Required validations
19
107
  if (!(id === null || id === void 0 ? void 0 : id.trim())) {
20
108
  throw new Error('Note ID is required for Note update.');
@@ -44,7 +132,7 @@ async function noteUpdate(i, returnData) {
44
132
  DueDateType: 'NoTime',
45
133
  DoneDateType: 'Notime',
46
134
  DealId: dealId || ZERO_GUID,
47
- ContactIds: Array.isArray(contactIds) ? contactIds : [],
135
+ ContactIds: contactIdsArr,
48
136
  CaseId: caseId || ZERO_GUID,
49
137
  },
50
138
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-didar-crm",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "Didar CRM nodes for n8n (Trigger + Deal.create)",
5
5
  "author": "You",
6
6
  "license": "MIT",