n8n-nodes-didar-crm 0.0.8 → 0.0.9

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.
@@ -39,6 +39,8 @@ const Load = __importStar(require("../lib/loadOptions"));
39
39
  const deal_1 = require("./deal");
40
40
  const PersonOps = __importStar(require("./person"));
41
41
  const person_1 = require("./person");
42
+ const CompanyOps = __importStar(require("./company"));
43
+ const company_1 = require("./company");
42
44
  class DidarCrm {
43
45
  constructor() {
44
46
  this.methods = {
@@ -68,6 +70,7 @@ class DidarCrm {
68
70
  options: [
69
71
  { name: 'Deal', value: 'deal' },
70
72
  { name: 'Person', value: 'person' },
73
+ { name: 'Company', value: 'company' },
71
74
  ],
72
75
  default: 'deal',
73
76
  description: 'Choose the entity to act on.',
@@ -98,6 +101,19 @@ class DidarCrm {
98
101
  default: 'create',
99
102
  description: 'Select the action to perform on the selected resource.',
100
103
  },
104
+ {
105
+ displayName: 'Operation',
106
+ name: 'operation',
107
+ type: 'options',
108
+ displayOptions: { show: { resource: ['company'] } },
109
+ options: [
110
+ { name: 'Create', value: 'create', action: 'Create a company' },
111
+ { name: 'Update', value: 'update', action: 'Update a company by Id' }, // NEW
112
+ { name: 'Get', value: 'get', action: 'Get a company by Id' }, // NEW
113
+ ],
114
+ default: 'create',
115
+ description: 'Select the action to perform on the selected resource.',
116
+ },
101
117
  // Deal properties (imported)
102
118
  ...deal_1.dealCreateProperties,
103
119
  ...deal_1.dealUpdateProperties,
@@ -106,6 +122,10 @@ class DidarCrm {
106
122
  ...person_1.personCreateProperties,
107
123
  ...person_1.personUpdateProperties,
108
124
  ...person_1.personGetProperties,
125
+ // Company properties (imported)
126
+ ...company_1.companyCreateProperties,
127
+ ...company_1.companyUpdateProperties,
128
+ ...company_1.companyGetProperties,
109
129
  ],
110
130
  };
111
131
  }
@@ -143,6 +163,20 @@ class DidarCrm {
143
163
  continue;
144
164
  }
145
165
  }
166
+ if (resource === 'company') {
167
+ if (operation === 'create') {
168
+ await CompanyOps.companyCreate.call(this, i, returnData);
169
+ continue;
170
+ }
171
+ if (operation === 'update') {
172
+ await CompanyOps.companyUpdate.call(this, i, returnData);
173
+ continue;
174
+ } // NEW
175
+ if (operation === 'get') {
176
+ await CompanyOps.companyGet.call(this, i, returnData);
177
+ continue;
178
+ } // NEW
179
+ }
146
180
  }
147
181
  return [returnData];
148
182
  }
@@ -0,0 +1,2 @@
1
+ import { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
2
+ export declare function companyCreate(this: IExecuteFunctions, i: number, returnData: INodeExecutionData[]): Promise<void>;
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.companyCreate = companyCreate;
4
+ const http_1 = require("../../lib/http");
5
+ async function companyCreate(i, returnData) {
6
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
7
+ // Name (maps to FirstName) is required
8
+ const name = this.getNodeParameter('FirstName', i, '');
9
+ if (!name)
10
+ throw new Error('Name is required.');
11
+ // Owner selection
12
+ const ownerMode = this.getNodeParameter('OwnerMode', i);
13
+ const ownerId = ownerMode === 'select'
14
+ ? this.getNodeParameter('OwnerIdSelect', i, '')
15
+ : this.getNodeParameter('OwnerIdManual', i, '');
16
+ if (!ownerId)
17
+ throw new Error('OwnerId is required (select from list or enter manually).');
18
+ // Main fields
19
+ const mobile = this.getNodeParameter('MobilePhone', i, '');
20
+ const workPhone = this.getNodeParameter('WorkPhone', i, '');
21
+ // Additional fields
22
+ const add = this.getNodeParameter('additionalFields', i, {}) || {};
23
+ const workPhoneExt = (_a = add.WorkPhoneExtension) !== null && _a !== void 0 ? _a : '';
24
+ const fax = (_b = add.Fax) !== null && _b !== void 0 ? _b : '';
25
+ const email = (_c = add.Email) !== null && _c !== void 0 ? _c : '';
26
+ const isVip = (_d = add.IsVIP) !== null && _d !== void 0 ? _d : false;
27
+ const backgroundInfo = (_e = add.BackgroundInfo) !== null && _e !== void 0 ? _e : '';
28
+ const customerCode = (_f = add.CustomerCode) !== null && _f !== void 0 ? _f : '';
29
+ const economicIssue = (_g = add.EconomicIssue) !== null && _g !== void 0 ? _g : '';
30
+ const registrationNumber = (_h = add.RegistrationNumber) !== null && _h !== void 0 ? _h : '';
31
+ const nationalId = (_j = add.NationalID) !== null && _j !== void 0 ? _j : '';
32
+ const zipCode = (_k = add.ZipCode) !== null && _k !== void 0 ? _k : '';
33
+ const visibilityType = (_l = add.VisibilityType) !== null && _l !== void 0 ? _l : 'Owner';
34
+ // Fields (JSON)
35
+ let fields;
36
+ if (typeof add.Fields === 'string' && add.Fields.trim()) {
37
+ try {
38
+ fields = JSON.parse(add.Fields);
39
+ }
40
+ catch {
41
+ throw new Error('Invalid JSON in "Custom Fields (JSON)".');
42
+ }
43
+ }
44
+ else if (typeof add.Fields === 'object' && add.Fields) {
45
+ fields = add.Fields;
46
+ }
47
+ // Helper: fixedCollection → { KeyValues: [{Key,Value}] }
48
+ const toKeyValues = (obj) => {
49
+ var _a;
50
+ if (!obj || typeof obj !== 'object')
51
+ return undefined;
52
+ const list = (_a = obj.KeyValues) !== null && _a !== void 0 ? _a : [];
53
+ if (!Array.isArray(list) || !list.length)
54
+ return undefined;
55
+ return { KeyValues: list.map(e => { var _a, _b; return ({ Key: (_a = e.Key) !== null && _a !== void 0 ? _a : '', Value: (_b = e.Value) !== null && _b !== void 0 ? _b : '' }); }) };
56
+ };
57
+ const websites = toKeyValues(add.Websites);
58
+ const otherPhones = toKeyValues(add.OtherPhones);
59
+ const otherEmails = toKeyValues(add.OtherEmails);
60
+ const addresses = toKeyValues(add.Addresses);
61
+ // BankAccounts: { Values: [{Value1..Value4}] }
62
+ let bankAccounts;
63
+ if (add.BankAccounts && typeof add.BankAccounts === 'object') {
64
+ const vals = add.BankAccounts.Values;
65
+ if (Array.isArray(vals) && vals.length) {
66
+ bankAccounts = { Values: vals.map(v => {
67
+ var _a, _b, _c, _d;
68
+ return ({
69
+ Value1: (_a = v.Value1) !== null && _a !== void 0 ? _a : '', Value2: (_b = v.Value2) !== null && _b !== void 0 ? _b : '', Value3: (_c = v.Value3) !== null && _c !== void 0 ? _c : '', Value4: (_d = v.Value4) !== null && _d !== void 0 ? _d : '',
70
+ });
71
+ }) };
72
+ }
73
+ }
74
+ // SegmentIds: string[]
75
+ let segmentIds;
76
+ const seg = add.SegmentIds;
77
+ if (Array.isArray(seg))
78
+ segmentIds = seg.filter(Boolean);
79
+ else if (typeof seg === 'string' && seg)
80
+ segmentIds = [seg];
81
+ // Contact body (Type = Company)
82
+ const contact = {
83
+ Type: 'Company',
84
+ FirstName: name, // UI "Name" → API FirstName
85
+ OwnerId: ownerId,
86
+ MobilePhone: mobile,
87
+ WorkPhone: workPhone,
88
+ WorkPhoneExtension: workPhoneExt,
89
+ Fax: fax,
90
+ Email: email,
91
+ IsVIP: isVip,
92
+ BackgroundInfo: backgroundInfo,
93
+ CustomerCode: customerCode,
94
+ EconomicIssue: economicIssue,
95
+ RegistrationNumber: registrationNumber,
96
+ NationalID: nationalId,
97
+ ZipCode: zipCode,
98
+ VisibilityType: visibilityType,
99
+ };
100
+ if (fields)
101
+ contact['Fields'] = fields;
102
+ if (websites)
103
+ contact['Websites'] = websites;
104
+ if (otherPhones)
105
+ contact['OtherPhones'] = otherPhones;
106
+ if (otherEmails)
107
+ contact['OtherEmails'] = otherEmails;
108
+ if (addresses)
109
+ contact['Addresses'] = addresses;
110
+ if (bankAccounts)
111
+ contact['BankAccounts'] = bankAccounts;
112
+ const body = { Contact: contact };
113
+ if (segmentIds && segmentIds.length)
114
+ body['SegmentIds'] = segmentIds;
115
+ const resp = await (0, http_1.didarRequest)(this, i, {
116
+ method: 'POST',
117
+ path: '/api/contact/save',
118
+ body,
119
+ });
120
+ returnData.push({ json: resp });
121
+ }
@@ -0,0 +1,2 @@
1
+ import { INodeProperties } from 'n8n-workflow';
2
+ export declare const companyCreateProperties: INodeProperties[];
@@ -0,0 +1,210 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.companyCreateProperties = void 0;
4
+ const showForCompanyCreate = { show: { resource: ['company'], operation: ['create'] } };
5
+ exports.companyCreateProperties = [
6
+ // --- مین فیلدها (بالا به پایین) ---
7
+ {
8
+ displayName: 'Name',
9
+ name: 'FirstName', // به API به عنوان FirstName ارسال می‌شود
10
+ type: 'string',
11
+ default: '',
12
+ required: true,
13
+ displayOptions: showForCompanyCreate,
14
+ description: 'Company name (required).',
15
+ },
16
+ {
17
+ displayName: 'Mobile Phone',
18
+ name: 'MobilePhone',
19
+ type: 'string',
20
+ default: '',
21
+ displayOptions: showForCompanyCreate,
22
+ description: 'Primary mobile phone number.',
23
+ },
24
+ {
25
+ displayName: 'Work Phone',
26
+ name: 'WorkPhone',
27
+ type: 'string',
28
+ default: '',
29
+ displayOptions: showForCompanyCreate,
30
+ description: 'Work phone number.',
31
+ },
32
+ // --- Owner (Select/Manual) مانند Person/Deal ---
33
+ {
34
+ displayName: 'Owner Input Mode',
35
+ name: 'OwnerMode',
36
+ type: 'options',
37
+ options: [
38
+ { name: 'Select from list', value: 'select' },
39
+ { name: 'Enter ID manually', value: 'manual' },
40
+ ],
41
+ default: 'select',
42
+ displayOptions: showForCompanyCreate,
43
+ description: 'Choose how to set the owner of this company.',
44
+ },
45
+ {
46
+ displayName: 'Owner',
47
+ name: 'OwnerIdSelect',
48
+ type: 'options',
49
+ typeOptions: { loadOptionsMethod: 'getUsers' },
50
+ default: '',
51
+ displayOptions: { show: { ...showForCompanyCreate.show, OwnerMode: ['select'] } },
52
+ description: 'Select the owner user (required if select mode).',
53
+ },
54
+ {
55
+ displayName: 'Owner ID',
56
+ name: 'OwnerIdManual',
57
+ type: 'string',
58
+ default: '',
59
+ displayOptions: { show: { ...showForCompanyCreate.show, OwnerMode: ['manual'] } },
60
+ description: 'Enter owner user ID manually (required if manual mode).',
61
+ },
62
+ // --- Additional Fields ---
63
+ {
64
+ displayName: 'Additional Fields',
65
+ name: 'additionalFields',
66
+ type: 'collection',
67
+ placeholder: 'Add field',
68
+ default: {},
69
+ displayOptions: showForCompanyCreate,
70
+ options: [
71
+ { displayName: 'Work Phone Extension', name: 'WorkPhoneExtension', type: 'string', default: '', description: 'Extension for the work phone.' },
72
+ { displayName: 'Fax', name: 'Fax', type: 'string', default: '', description: 'Fax number.' },
73
+ { displayName: 'Email', name: 'Email', type: 'string', default: '', description: 'Primary email address.' },
74
+ { displayName: 'Is VIP', name: 'IsVIP', type: 'boolean', default: false, description: 'Mark this company as VIP.' },
75
+ { displayName: 'Background Info', name: 'BackgroundInfo', type: 'string', default: '', description: 'Notes or background information.' },
76
+ { displayName: 'Customer Code', name: 'CustomerCode', type: 'string', default: '', description: 'Internal or CRM customer code.' },
77
+ // فیلدهای مخصوص شرکت
78
+ { displayName: 'Economic Issue', name: 'EconomicIssue', type: 'string', default: '', description: 'Economic issue code (company-specific).' },
79
+ { displayName: 'Registration Number', name: 'RegistrationNumber', type: 'string', default: '', description: 'Company registration number.' },
80
+ { displayName: 'National ID', name: 'NationalID', type: 'string', default: '', description: 'Company national ID.' },
81
+ { displayName: 'Zip Code', name: 'ZipCode', type: 'string', default: '', description: 'Postal/ZIP code.' },
82
+ // VisibilityType مانند قبل
83
+ {
84
+ displayName: 'Visibility Type',
85
+ name: 'VisibilityType',
86
+ type: 'options',
87
+ options: [
88
+ { name: 'Owner', value: 'Owner' },
89
+ { name: 'Owner Group', value: 'OwnerGroup' },
90
+ { name: 'Owner SubGroup', value: 'OwnerSubGroup' },
91
+ { name: 'All', value: 'All' },
92
+ ],
93
+ default: 'Owner',
94
+ description: 'Visibility setting for this company.',
95
+ },
96
+ // Fields (JSON)
97
+ {
98
+ displayName: 'Custom Fields (JSON)',
99
+ name: 'Fields',
100
+ type: 'json',
101
+ default: '',
102
+ placeholder: '{ "Field_996_0_7": "value" }',
103
+ description: 'JSON object of custom fields.',
104
+ },
105
+ // Websites / OtherPhones / OtherEmails / Addresses → Key/Value
106
+ {
107
+ displayName: 'Websites',
108
+ name: 'Websites',
109
+ type: 'fixedCollection',
110
+ typeOptions: { multipleValues: true },
111
+ default: {},
112
+ options: [
113
+ {
114
+ name: 'KeyValues',
115
+ displayName: 'Website',
116
+ values: [
117
+ { displayName: 'Key', name: 'Key', type: 'string', default: '' },
118
+ { displayName: 'Value', name: 'Value', type: 'string', default: '' },
119
+ ],
120
+ },
121
+ ],
122
+ description: 'List of websites as key/value pairs.',
123
+ },
124
+ {
125
+ displayName: 'Other Phones',
126
+ name: 'OtherPhones',
127
+ type: 'fixedCollection',
128
+ typeOptions: { multipleValues: true },
129
+ default: {},
130
+ options: [
131
+ {
132
+ name: 'KeyValues',
133
+ displayName: 'Phone',
134
+ values: [
135
+ { displayName: 'Key', name: 'Key', type: 'string', default: '' },
136
+ { displayName: 'Value', name: 'Value', type: 'string', default: '' },
137
+ ],
138
+ },
139
+ ],
140
+ description: 'Additional phone numbers as key/value pairs.',
141
+ },
142
+ {
143
+ displayName: 'Other Emails',
144
+ name: 'OtherEmails',
145
+ type: 'fixedCollection',
146
+ typeOptions: { multipleValues: true },
147
+ default: {},
148
+ options: [
149
+ {
150
+ name: 'KeyValues',
151
+ displayName: 'Email',
152
+ values: [
153
+ { displayName: 'Key', name: 'Key', type: 'string', default: '' },
154
+ { displayName: 'Value', name: 'Value', type: 'string', default: '' },
155
+ ],
156
+ },
157
+ ],
158
+ description: 'Additional emails as key/value pairs.',
159
+ },
160
+ {
161
+ displayName: 'Addresses',
162
+ name: 'Addresses',
163
+ type: 'fixedCollection',
164
+ typeOptions: { multipleValues: true },
165
+ default: {},
166
+ options: [
167
+ {
168
+ name: 'KeyValues',
169
+ displayName: 'Address',
170
+ values: [
171
+ { displayName: 'Key', name: 'Key', type: 'string', default: '' },
172
+ { displayName: 'Value', name: 'Value', type: 'string', default: '' },
173
+ ],
174
+ },
175
+ ],
176
+ description: 'Addresses as key/value pairs (e.g., HQ/Branch/etc.).',
177
+ },
178
+ // BankAccounts: Values[1..4]
179
+ {
180
+ displayName: 'Bank Accounts',
181
+ name: 'BankAccounts',
182
+ type: 'fixedCollection',
183
+ typeOptions: { multipleValues: true },
184
+ default: {},
185
+ options: [
186
+ {
187
+ name: 'Values',
188
+ displayName: 'Bank Account',
189
+ values: [
190
+ { displayName: 'Value1', name: 'Value1', type: 'string', default: '' },
191
+ { displayName: 'Value2', name: 'Value2', type: 'string', default: '' },
192
+ { displayName: 'Value3', name: 'Value3', type: 'string', default: '' },
193
+ { displayName: 'Value4', name: 'Value4', type: 'string', default: '' },
194
+ ],
195
+ },
196
+ ],
197
+ description: 'Bank account details (four flexible fields per entry).',
198
+ },
199
+ // SegmentIds: string[]
200
+ {
201
+ displayName: 'Segment IDs',
202
+ name: 'SegmentIds',
203
+ type: 'string',
204
+ typeOptions: { multipleValues: true },
205
+ default: [],
206
+ description: 'List of segment IDs (GUIDs).',
207
+ },
208
+ ],
209
+ },
210
+ ];
@@ -0,0 +1,2 @@
1
+ import { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
2
+ export declare function companyGet(this: IExecuteFunctions, i: number, returnData: INodeExecutionData[]): Promise<void>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.companyGet = companyGet;
4
+ const http_1 = require("../../lib/http");
5
+ async function companyGet(i, returnData) {
6
+ const companyId = this.getNodeParameter('companyId', i, '');
7
+ if (!companyId)
8
+ throw new Error('Company Id is required.');
9
+ const resp = await (0, http_1.didarRequest)(this, i, {
10
+ method: 'POST',
11
+ path: '/api/contact/GetContactDetail',
12
+ body: { Id: companyId },
13
+ });
14
+ returnData.push({ json: resp });
15
+ }
@@ -0,0 +1,2 @@
1
+ import { INodeProperties } from 'n8n-workflow';
2
+ export declare const companyGetProperties: INodeProperties[];
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.companyGetProperties = void 0;
4
+ exports.companyGetProperties = [
5
+ {
6
+ displayName: 'Company Id',
7
+ name: 'companyId',
8
+ type: 'string',
9
+ default: '',
10
+ required: true,
11
+ displayOptions: { show: { resource: ['company'], operation: ['get'] } },
12
+ description: 'Company Id to fetch (required).',
13
+ },
14
+ ];
@@ -0,0 +1,6 @@
1
+ export { companyCreate } from './create.operation';
2
+ export { companyCreateProperties } from './create.properties';
3
+ export { companyUpdate } from './update.operation';
4
+ export { companyUpdateProperties } from './update.properties';
5
+ export { companyGet } from './get.operation';
6
+ export { companyGetProperties } from './get.properties';
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.companyGetProperties = exports.companyGet = exports.companyUpdateProperties = exports.companyUpdate = exports.companyCreateProperties = exports.companyCreate = void 0;
4
+ var create_operation_1 = require("./create.operation");
5
+ Object.defineProperty(exports, "companyCreate", { enumerable: true, get: function () { return create_operation_1.companyCreate; } });
6
+ var create_properties_1 = require("./create.properties");
7
+ Object.defineProperty(exports, "companyCreateProperties", { enumerable: true, get: function () { return create_properties_1.companyCreateProperties; } });
8
+ var update_operation_1 = require("./update.operation");
9
+ Object.defineProperty(exports, "companyUpdate", { enumerable: true, get: function () { return update_operation_1.companyUpdate; } });
10
+ var update_properties_1 = require("./update.properties");
11
+ Object.defineProperty(exports, "companyUpdateProperties", { enumerable: true, get: function () { return update_properties_1.companyUpdateProperties; } });
12
+ var get_operation_1 = require("./get.operation"); // NEW
13
+ Object.defineProperty(exports, "companyGet", { enumerable: true, get: function () { return get_operation_1.companyGet; } });
14
+ var get_properties_1 = require("./get.properties"); // NEW
15
+ Object.defineProperty(exports, "companyGetProperties", { enumerable: true, get: function () { return get_properties_1.companyGetProperties; } });
@@ -0,0 +1,2 @@
1
+ import { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
2
+ export declare function companyUpdate(this: IExecuteFunctions, i: number, returnData: INodeExecutionData[]): Promise<void>;
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.companyUpdate = companyUpdate;
4
+ const http_1 = require("../../lib/http");
5
+ async function companyUpdate(i, returnData) {
6
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
7
+ // Required
8
+ const id = this.getNodeParameter('Id', i, '');
9
+ if (!id)
10
+ throw new Error('Id is required.');
11
+ const name = this.getNodeParameter('FirstName', i, '');
12
+ if (!name)
13
+ throw new Error('Name is required.');
14
+ // Owner selection
15
+ const ownerMode = this.getNodeParameter('OwnerMode', i);
16
+ const ownerId = ownerMode === 'select'
17
+ ? this.getNodeParameter('OwnerIdSelect', i, '')
18
+ : this.getNodeParameter('OwnerIdManual', i, '');
19
+ if (!ownerId)
20
+ throw new Error('OwnerId is required (select from list or enter manually).');
21
+ // Main fields
22
+ const mobile = this.getNodeParameter('MobilePhone', i, '');
23
+ const workPhone = this.getNodeParameter('WorkPhone', i, '');
24
+ // Additional fields
25
+ const add = this.getNodeParameter('additionalFields', i, {}) || {};
26
+ const workPhoneExt = (_a = add.WorkPhoneExtension) !== null && _a !== void 0 ? _a : '';
27
+ const fax = (_b = add.Fax) !== null && _b !== void 0 ? _b : '';
28
+ const email = (_c = add.Email) !== null && _c !== void 0 ? _c : '';
29
+ const isVip = (_d = add.IsVIP) !== null && _d !== void 0 ? _d : false;
30
+ const backgroundInfo = (_e = add.BackgroundInfo) !== null && _e !== void 0 ? _e : '';
31
+ const customerCode = (_f = add.CustomerCode) !== null && _f !== void 0 ? _f : '';
32
+ const economicIssue = (_g = add.EconomicIssue) !== null && _g !== void 0 ? _g : '';
33
+ const registrationNumber = (_h = add.RegistrationNumber) !== null && _h !== void 0 ? _h : '';
34
+ const nationalId = (_j = add.NationalID) !== null && _j !== void 0 ? _j : '';
35
+ const zipCode = (_k = add.ZipCode) !== null && _k !== void 0 ? _k : '';
36
+ const visibilityType = (_l = add.VisibilityType) !== null && _l !== void 0 ? _l : 'Owner';
37
+ // Fields (JSON or object)
38
+ let fields;
39
+ if (typeof add.Fields === 'string' && add.Fields.trim()) {
40
+ try {
41
+ fields = JSON.parse(add.Fields);
42
+ }
43
+ catch {
44
+ throw new Error('Invalid JSON in "Custom Fields (JSON)".');
45
+ }
46
+ }
47
+ else if (typeof add.Fields === 'object' && add.Fields) {
48
+ fields = add.Fields;
49
+ }
50
+ // Helpers
51
+ const toKeyValues = (obj) => {
52
+ var _a;
53
+ if (!obj || typeof obj !== 'object')
54
+ return undefined;
55
+ const list = (_a = obj.KeyValues) !== null && _a !== void 0 ? _a : [];
56
+ if (!Array.isArray(list) || !list.length)
57
+ return undefined;
58
+ return { KeyValues: list.map(e => { var _a, _b; return ({ Key: (_a = e.Key) !== null && _a !== void 0 ? _a : '', Value: (_b = e.Value) !== null && _b !== void 0 ? _b : '' }); }) };
59
+ };
60
+ const websites = toKeyValues(add.Websites);
61
+ const otherPhones = toKeyValues(add.OtherPhones);
62
+ const otherEmails = toKeyValues(add.OtherEmails);
63
+ const addresses = toKeyValues(add.Addresses);
64
+ let bankAccounts;
65
+ if (add.BankAccounts && typeof add.BankAccounts === 'object') {
66
+ const vals = add.BankAccounts.Values;
67
+ if (Array.isArray(vals) && vals.length) {
68
+ bankAccounts = { Values: vals.map(v => {
69
+ var _a, _b, _c, _d;
70
+ return ({
71
+ Value1: (_a = v.Value1) !== null && _a !== void 0 ? _a : '', Value2: (_b = v.Value2) !== null && _b !== void 0 ? _b : '', Value3: (_c = v.Value3) !== null && _c !== void 0 ? _c : '', Value4: (_d = v.Value4) !== null && _d !== void 0 ? _d : '',
72
+ });
73
+ }) };
74
+ }
75
+ }
76
+ let segmentIds;
77
+ const seg = add.SegmentIds;
78
+ if (Array.isArray(seg))
79
+ segmentIds = seg.filter(Boolean);
80
+ else if (typeof seg === 'string' && seg)
81
+ segmentIds = [seg];
82
+ // Contact body (Type = Company)
83
+ const contact = {
84
+ Id: id,
85
+ Type: 'Company',
86
+ FirstName: name, // UI "Name"
87
+ OwnerId: ownerId,
88
+ MobilePhone: mobile,
89
+ WorkPhone: workPhone,
90
+ WorkPhoneExtension: workPhoneExt,
91
+ Fax: fax,
92
+ Email: email,
93
+ IsVIP: isVip,
94
+ BackgroundInfo: backgroundInfo,
95
+ CustomerCode: customerCode,
96
+ EconomicIssue: economicIssue,
97
+ RegistrationNumber: registrationNumber,
98
+ NationalID: nationalId,
99
+ ZipCode: zipCode,
100
+ VisibilityType: visibilityType,
101
+ };
102
+ if (fields)
103
+ contact['Fields'] = fields;
104
+ if (websites)
105
+ contact['Websites'] = websites;
106
+ if (otherPhones)
107
+ contact['OtherPhones'] = otherPhones;
108
+ if (otherEmails)
109
+ contact['OtherEmails'] = otherEmails;
110
+ if (addresses)
111
+ contact['Addresses'] = addresses;
112
+ if (bankAccounts)
113
+ contact['BankAccounts'] = bankAccounts;
114
+ const body = { Contact: contact };
115
+ if (segmentIds && segmentIds.length)
116
+ body['SegmentIds'] = segmentIds;
117
+ const resp = await (0, http_1.didarRequest)(this, i, {
118
+ method: 'POST',
119
+ path: '/api/contact/save',
120
+ body,
121
+ });
122
+ returnData.push({ json: resp });
123
+ }
@@ -0,0 +1,2 @@
1
+ import { INodeProperties } from 'n8n-workflow';
2
+ export declare const companyUpdateProperties: INodeProperties[];
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.companyUpdateProperties = void 0;
4
+ const showForCompanyUpdate = { show: { resource: ['company'], operation: ['update'] } };
5
+ exports.companyUpdateProperties = [
6
+ // === REQUIRED: Id ===
7
+ {
8
+ displayName: 'Id',
9
+ name: 'Id',
10
+ type: 'string',
11
+ default: '',
12
+ required: true,
13
+ displayOptions: showForCompanyUpdate,
14
+ description: 'Company Id to update (required).',
15
+ },
16
+ // === MAIN fields (same as create) ===
17
+ {
18
+ displayName: 'Name',
19
+ name: 'FirstName', // UI Name → API FirstName
20
+ type: 'string',
21
+ default: '',
22
+ required: true,
23
+ displayOptions: showForCompanyUpdate,
24
+ description: 'Company name (required).',
25
+ },
26
+ {
27
+ displayName: 'Mobile Phone',
28
+ name: 'MobilePhone',
29
+ type: 'string',
30
+ default: '',
31
+ displayOptions: showForCompanyUpdate,
32
+ description: 'Primary mobile phone number.',
33
+ },
34
+ {
35
+ displayName: 'Work Phone',
36
+ name: 'WorkPhone',
37
+ type: 'string',
38
+ default: '',
39
+ displayOptions: showForCompanyUpdate,
40
+ description: 'Work phone number.',
41
+ },
42
+ // Owner (select/manual)
43
+ {
44
+ displayName: 'Owner Input Mode',
45
+ name: 'OwnerMode',
46
+ type: 'options',
47
+ options: [
48
+ { name: 'Select from list', value: 'select' },
49
+ { name: 'Enter ID manually', value: 'manual' },
50
+ ],
51
+ default: 'select',
52
+ displayOptions: showForCompanyUpdate,
53
+ description: 'Choose how to set the owner of this company.',
54
+ },
55
+ {
56
+ displayName: 'Owner',
57
+ name: 'OwnerIdSelect',
58
+ type: 'options',
59
+ typeOptions: { loadOptionsMethod: 'getUsers' },
60
+ default: '',
61
+ displayOptions: { show: { ...showForCompanyUpdate.show, OwnerMode: ['select'] } },
62
+ description: 'Select the owner user (required if select mode).',
63
+ },
64
+ {
65
+ displayName: 'Owner ID',
66
+ name: 'OwnerIdManual',
67
+ type: 'string',
68
+ default: '',
69
+ displayOptions: { show: { ...showForCompanyUpdate.show, OwnerMode: ['manual'] } },
70
+ description: 'Enter owner user ID manually (required if manual mode).',
71
+ },
72
+ // Additional Fields (exact mirror of create)
73
+ {
74
+ displayName: 'Additional Fields',
75
+ name: 'additionalFields',
76
+ type: 'collection',
77
+ placeholder: 'Add field',
78
+ default: {},
79
+ displayOptions: showForCompanyUpdate,
80
+ options: [
81
+ { displayName: 'Work Phone Extension', name: 'WorkPhoneExtension', type: 'string', default: '', description: 'Extension for the work phone.' },
82
+ { displayName: 'Fax', name: 'Fax', type: 'string', default: '', description: 'Fax number.' },
83
+ { displayName: 'Email', name: 'Email', type: 'string', default: '', description: 'Primary email address.' },
84
+ { displayName: 'Is VIP', name: 'IsVIP', type: 'boolean', default: false, description: 'Mark this company as VIP.' },
85
+ { displayName: 'Background Info', name: 'BackgroundInfo', type: 'string', default: '', description: 'Notes or background information.' },
86
+ { displayName: 'Customer Code', name: 'CustomerCode', type: 'string', default: '', description: 'Internal or CRM customer code.' },
87
+ { displayName: 'Economic Issue', name: 'EconomicIssue', type: 'string', default: '', description: 'Economic issue code (company-specific).' },
88
+ { displayName: 'Registration Number', name: 'RegistrationNumber', type: 'string', default: '', description: 'Company registration number.' },
89
+ { displayName: 'National ID', name: 'NationalID', type: 'string', default: '', description: 'Company national ID.' },
90
+ { displayName: 'Zip Code', name: 'ZipCode', type: 'string', default: '', description: 'Postal/ZIP code.' },
91
+ {
92
+ displayName: 'Visibility Type',
93
+ name: 'VisibilityType',
94
+ type: 'options',
95
+ options: [
96
+ { name: 'Owner', value: 'Owner' },
97
+ { name: 'Owner Group', value: 'OwnerGroup' },
98
+ { name: 'Owner SubGroup', value: 'OwnerSubGroup' },
99
+ { name: 'All', value: 'All' },
100
+ ],
101
+ default: 'Owner',
102
+ description: 'Visibility setting for this company.',
103
+ },
104
+ { displayName: 'Custom Fields (JSON)', name: 'Fields', type: 'json', default: '', placeholder: '{ "Field_996_0_7": "value" }', description: 'JSON object of custom fields.' },
105
+ // Key/Value lists
106
+ {
107
+ displayName: 'Websites',
108
+ name: 'Websites',
109
+ type: 'fixedCollection',
110
+ typeOptions: { multipleValues: true },
111
+ default: {},
112
+ options: [{ name: 'KeyValues', displayName: 'Website', values: [
113
+ { displayName: 'Key', name: 'Key', type: 'string', default: '' },
114
+ { displayName: 'Value', name: 'Value', type: 'string', default: '' },
115
+ ] }],
116
+ description: 'List of websites as key/value pairs.',
117
+ },
118
+ {
119
+ displayName: 'Other Phones',
120
+ name: 'OtherPhones',
121
+ type: 'fixedCollection',
122
+ typeOptions: { multipleValues: true },
123
+ default: {},
124
+ options: [{ name: 'KeyValues', displayName: 'Phone', values: [
125
+ { displayName: 'Key', name: 'Key', type: 'string', default: '' },
126
+ { displayName: 'Value', name: 'Value', type: 'string', default: '' },
127
+ ] }],
128
+ description: 'Additional phone numbers as key/value pairs.',
129
+ },
130
+ {
131
+ displayName: 'Other Emails',
132
+ name: 'OtherEmails',
133
+ type: 'fixedCollection',
134
+ typeOptions: { multipleValues: true },
135
+ default: {},
136
+ options: [{ name: 'KeyValues', displayName: 'Email', values: [
137
+ { displayName: 'Key', name: 'Key', type: 'string', default: '' },
138
+ { displayName: 'Value', name: 'Value', type: 'string', default: '' },
139
+ ] }],
140
+ description: 'Additional emails as key/value pairs.',
141
+ },
142
+ {
143
+ displayName: 'Addresses',
144
+ name: 'Addresses',
145
+ type: 'fixedCollection',
146
+ typeOptions: { multipleValues: true },
147
+ default: {},
148
+ options: [{ name: 'KeyValues', displayName: 'Address', values: [
149
+ { displayName: 'Key', name: 'Key', type: 'string', default: '' },
150
+ { displayName: 'Value', name: 'Value', type: 'string', default: '' },
151
+ ] }],
152
+ description: 'Addresses as key/value pairs (e.g., HQ/Branch/etc.).',
153
+ },
154
+ // Bank accounts
155
+ {
156
+ displayName: 'Bank Accounts',
157
+ name: 'BankAccounts',
158
+ type: 'fixedCollection',
159
+ typeOptions: { multipleValues: true },
160
+ default: {},
161
+ options: [{ name: 'Values', displayName: 'Bank Account', values: [
162
+ { displayName: 'Value1', name: 'Value1', type: 'string', default: '' },
163
+ { displayName: 'Value2', name: 'Value2', type: 'string', default: '' },
164
+ { displayName: 'Value3', name: 'Value3', type: 'string', default: '' },
165
+ { displayName: 'Value4', name: 'Value4', type: 'string', default: '' },
166
+ ] }],
167
+ description: 'Bank account details (four flexible fields per entry).',
168
+ },
169
+ // Segments
170
+ {
171
+ displayName: 'Segment IDs',
172
+ name: 'SegmentIds',
173
+ type: 'string',
174
+ typeOptions: { multipleValues: true },
175
+ default: [],
176
+ description: 'List of segment IDs (GUIDs).',
177
+ },
178
+ ],
179
+ },
180
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-didar-crm",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "Didar CRM nodes for n8n (Trigger + Deal.create)",
5
5
  "author": "You",
6
6
  "license": "MIT",