n8n-nodes-hamkar 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,144 @@
1
+ # n8n-nodes-hamkar
2
+
3
+ This is an n8n community node for integrating with the Hamkar.co API. It allows you to manage contacts and records (create, update, delete, and list) through n8n workflows.
4
+
5
+ [n8n](https://n8n.io/) is a [fair-code licensed](https://docs.n8n.io/reference/license/) workflow automation platform.
6
+
7
+ [Installation](#installation)
8
+ [Operations](#operations)
9
+ [Credentials](#credentials)
10
+ [Compatibility](#compatibility)
11
+ [Usage](#usage)
12
+ [Resources](#resources)
13
+
14
+ ## Installation
15
+
16
+ Follow the [installation guide](https://docs.n8n.io/integrations/community-nodes/installation/) in the n8n community nodes documentation.
17
+
18
+ ### Manual Installation
19
+
20
+ To install manually:
21
+
22
+ 1. Go to **Settings > Community Nodes**
23
+ 2. Select **Install**
24
+ 3. Enter `n8n-nodes-hamkar` in **Enter npm package name**
25
+ 4. Agree to the [risks](https://docs.n8n.io/integrations/community-nodes/risks/) of using community nodes
26
+ 5. Select **Install**
27
+
28
+ After installing the node, you can use it like any other node. n8n displays the node in search results in the **Nodes** panel.
29
+
30
+ ## Operations
31
+
32
+ The Hamkar node supports the following operations:
33
+
34
+ ### Contact
35
+ - **Create**: Create a new contact with name, phone numbers, address, and type (legal/natural)
36
+ - **Update**: Update an existing contact by ID
37
+ - **Delete**: Delete a contact by ID (or archive using update)
38
+ - **Get Many**: Retrieve multiple contacts with optional search filtering
39
+
40
+ ### Record
41
+ - **Create**: Create a new record with contact information, products, and custom field answers
42
+ - **Update**: Update an existing record by ID
43
+ - **Delete**: Delete a record by ID
44
+ - **Get Many**: Retrieve multiple records with optional search filtering
45
+
46
+ ## Credentials
47
+
48
+ To use this node, you need a Hamkar API key:
49
+
50
+ 1. Log in to your Hamkar.co account
51
+ 2. Navigate to your project settings
52
+ 3. Go to the "Connection" (اتصال) section
53
+ 4. Copy your API key (X-API-Key)
54
+
55
+ In n8n:
56
+ 1. Go to **Credentials > New**
57
+ 2. Search for **Hamkar API**
58
+ 3. Paste your API key
59
+ 4. Save the credential
60
+
61
+ ## Compatibility
62
+
63
+ - Minimum n8n version: 0.200.0
64
+ - Tested with n8n version: 1.0.0+
65
+
66
+ ## Usage
67
+
68
+ ### Creating a Contact
69
+
70
+ To create a contact, you need to provide:
71
+ - **Name**: Contact name
72
+ - **Phone Number**: Mobile phone number
73
+ - **Telephone Number** (optional): Landline number
74
+ - **Address** (optional): Contact address
75
+ - **Is Legal**: Whether it's a legal entity (true) or natural person (false)
76
+ - **Is Archived**: Whether the contact is archived
77
+
78
+ ### Creating a Record
79
+
80
+ To create a record, you need to provide:
81
+ - **Tag**: Status title/tag
82
+ - **Topic**: Topic title
83
+ - **Due Date**: Date in YYYY-MM-DD format
84
+ - **Contact**: Contact information including name, phone number, and type
85
+ - **Products**: List of products with ID, quantity, and price
86
+ - **Answers**: Custom field answers with field ID and answer text
87
+
88
+ ### Updating a Record
89
+
90
+ Same as creating, but you also need to provide the **Record ID** of the record you want to update.
91
+
92
+ ### Deleting a Record
93
+
94
+ Provide the **Record ID** of the record you want to delete.
95
+
96
+ ### Listing Records
97
+
98
+ You can:
99
+ - Return all records or limit the number
100
+ - Use a search query to filter results
101
+
102
+ ## Example Workflow
103
+
104
+ Here's a simple example workflow:
105
+
106
+ 1. **Trigger**: Webhook or Schedule
107
+ 2. **Hamkar Node**: Create a new record
108
+ - Set credentials
109
+ - Configure record details
110
+ - Add products and answers
111
+ 3. **Process**: Use the returned data in subsequent nodes
112
+
113
+ ## Resources
114
+
115
+ * [n8n community nodes documentation](https://docs.n8n.io/integrations/community-nodes/)
116
+ * [Hamkar.co API Documentation](https://api.hamkar.co/docs)
117
+
118
+ ## Development
119
+
120
+ If you want to contribute or modify this node:
121
+
122
+ ```bash
123
+ # Clone the repository
124
+ git clone https://github.com/yourusername/n8n-nodes-hamkar.git
125
+ cd n8n-nodes-hamkar
126
+
127
+ # Install dependencies
128
+ npm install
129
+
130
+ # Build the node
131
+ npm run build
132
+
133
+ # Watch for changes during development
134
+ npm run dev
135
+ ```
136
+
137
+ ## License
138
+
139
+ [MIT](https://github.com/n8n-io/n8n-nodes-starter/blob/master/LICENSE.md)
140
+
141
+ ## Support
142
+
143
+ For issues, questions, or contributions, please open an issue on [GitHub](https://github.com/yourusername/n8n-nodes-hamkar/issues).
144
+
@@ -0,0 +1,9 @@
1
+ import { IAuthenticateGeneric, ICredentialTestRequest, ICredentialType, INodeProperties } from 'n8n-workflow';
2
+ export declare class HamkarApi implements ICredentialType {
3
+ name: string;
4
+ displayName: string;
5
+ documentationUrl: string;
6
+ properties: INodeProperties[];
7
+ authenticate: IAuthenticateGeneric;
8
+ test: ICredentialTestRequest;
9
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HamkarApi = void 0;
4
+ class HamkarApi {
5
+ constructor() {
6
+ this.name = 'hamkarApi';
7
+ this.displayName = 'Hamkar API';
8
+ this.documentationUrl = 'https://api.hamkar.co/docs';
9
+ this.properties = [
10
+ {
11
+ displayName: 'API Key',
12
+ name: 'apiKey',
13
+ type: 'string',
14
+ typeOptions: {
15
+ password: true,
16
+ },
17
+ default: '',
18
+ required: true,
19
+ description: 'The API key for Hamkar.co. You can find this in your project connection settings.',
20
+ },
21
+ ];
22
+ this.authenticate = {
23
+ type: 'generic',
24
+ properties: {
25
+ headers: {
26
+ 'X-API-Key': '={{$credentials.apiKey}}',
27
+ },
28
+ },
29
+ };
30
+ this.test = {
31
+ request: {
32
+ baseURL: 'https://api.hamkar.co',
33
+ url: '/api/record/',
34
+ method: 'GET',
35
+ },
36
+ };
37
+ }
38
+ }
39
+ exports.HamkarApi = HamkarApi;
@@ -0,0 +1,5 @@
1
+ import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
2
+ export declare class Hamkar implements INodeType {
3
+ description: INodeTypeDescription;
4
+ execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
5
+ }
@@ -0,0 +1,803 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Hamkar = void 0;
4
+ class Hamkar {
5
+ constructor() {
6
+ this.description = {
7
+ displayName: 'Hamkar',
8
+ name: 'hamkar',
9
+ icon: 'file:hamkar.svg',
10
+ group: ['transform'],
11
+ version: 1,
12
+ subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
13
+ description: 'Interact with Hamkar.co API for record and contact management',
14
+ defaults: {
15
+ name: 'Hamkar',
16
+ },
17
+ inputs: ['main'],
18
+ outputs: ['main'],
19
+ credentials: [
20
+ {
21
+ name: 'hamkarApi',
22
+ required: true,
23
+ },
24
+ ],
25
+ properties: [
26
+ {
27
+ displayName: 'Resource',
28
+ name: 'resource',
29
+ type: 'options',
30
+ noDataExpression: true,
31
+ options: [
32
+ {
33
+ name: 'Contact',
34
+ value: 'contact',
35
+ },
36
+ {
37
+ name: 'Record',
38
+ value: 'record',
39
+ },
40
+ ],
41
+ default: 'contact',
42
+ },
43
+ {
44
+ displayName: 'Operation',
45
+ name: 'operation',
46
+ type: 'options',
47
+ noDataExpression: true,
48
+ displayOptions: {
49
+ show: {
50
+ resource: ['contact'],
51
+ },
52
+ },
53
+ options: [
54
+ {
55
+ name: 'Create',
56
+ value: 'create',
57
+ description: 'Create a new contact',
58
+ action: 'Create a contact',
59
+ },
60
+ {
61
+ name: 'Delete',
62
+ value: 'delete',
63
+ description: 'Delete a contact',
64
+ action: 'Delete a contact',
65
+ },
66
+ {
67
+ name: 'Get Many',
68
+ value: 'getMany',
69
+ description: 'Get many contacts',
70
+ action: 'Get many contacts',
71
+ },
72
+ {
73
+ name: 'Update',
74
+ value: 'update',
75
+ description: 'Update a contact',
76
+ action: 'Update a contact',
77
+ },
78
+ ],
79
+ default: 'create',
80
+ },
81
+ {
82
+ displayName: 'Operation',
83
+ name: 'operation',
84
+ type: 'options',
85
+ noDataExpression: true,
86
+ displayOptions: {
87
+ show: {
88
+ resource: ['record'],
89
+ },
90
+ },
91
+ options: [
92
+ {
93
+ name: 'Create',
94
+ value: 'create',
95
+ description: 'Create a new record',
96
+ action: 'Create a record',
97
+ },
98
+ {
99
+ name: 'Delete',
100
+ value: 'delete',
101
+ description: 'Delete a record',
102
+ action: 'Delete a record',
103
+ },
104
+ {
105
+ name: 'Get Many',
106
+ value: 'getMany',
107
+ description: 'Get many records',
108
+ action: 'Get many records',
109
+ },
110
+ {
111
+ name: 'Update',
112
+ value: 'update',
113
+ description: 'Update a record',
114
+ action: 'Update a record',
115
+ },
116
+ ],
117
+ default: 'create',
118
+ },
119
+ // =============================================
120
+ // Contact Fields
121
+ // =============================================
122
+ // Fields for Contact Create/Update operations
123
+ {
124
+ displayName: 'Name',
125
+ name: 'contactName',
126
+ type: 'string',
127
+ required: true,
128
+ displayOptions: {
129
+ show: {
130
+ resource: ['contact'],
131
+ operation: ['create', 'update'],
132
+ },
133
+ },
134
+ default: '',
135
+ description: 'Contact name',
136
+ },
137
+ {
138
+ displayName: 'Phone Number',
139
+ name: 'contactPhoneNumber',
140
+ type: 'string',
141
+ required: true,
142
+ displayOptions: {
143
+ show: {
144
+ resource: ['contact'],
145
+ operation: ['create', 'update'],
146
+ },
147
+ },
148
+ default: '',
149
+ placeholder: '09123456789',
150
+ description: 'Contact mobile phone number',
151
+ },
152
+ {
153
+ displayName: 'Telephone Number',
154
+ name: 'contactTelephoneNumber',
155
+ type: 'string',
156
+ displayOptions: {
157
+ show: {
158
+ resource: ['contact'],
159
+ operation: ['create', 'update'],
160
+ },
161
+ },
162
+ default: '',
163
+ placeholder: '02112345678',
164
+ description: 'Contact landline telephone number',
165
+ },
166
+ {
167
+ displayName: 'Address',
168
+ name: 'contactAddress',
169
+ type: 'string',
170
+ displayOptions: {
171
+ show: {
172
+ resource: ['contact'],
173
+ operation: ['create', 'update'],
174
+ },
175
+ },
176
+ default: '',
177
+ description: 'Contact address',
178
+ },
179
+ {
180
+ displayName: 'Is Legal',
181
+ name: 'contactIsLegal',
182
+ type: 'boolean',
183
+ displayOptions: {
184
+ show: {
185
+ resource: ['contact'],
186
+ operation: ['create', 'update'],
187
+ },
188
+ },
189
+ default: false,
190
+ description: 'Whether contact is legal entity (true) or natural person (false)',
191
+ },
192
+ {
193
+ displayName: 'Is Archived',
194
+ name: 'contactIsArchived',
195
+ type: 'boolean',
196
+ displayOptions: {
197
+ show: {
198
+ resource: ['contact'],
199
+ operation: ['create', 'update'],
200
+ },
201
+ },
202
+ default: false,
203
+ description: 'Whether contact is archived',
204
+ },
205
+ // Fields for Contact Update/Delete operations
206
+ {
207
+ displayName: 'Contact ID',
208
+ name: 'contactId',
209
+ type: 'string',
210
+ required: true,
211
+ displayOptions: {
212
+ show: {
213
+ resource: ['contact'],
214
+ operation: ['update', 'delete'],
215
+ },
216
+ },
217
+ default: '',
218
+ description: 'ID of the contact to update or delete',
219
+ },
220
+ // Fields for Contact Get Many operation
221
+ {
222
+ displayName: 'Return All',
223
+ name: 'returnAll',
224
+ type: 'boolean',
225
+ displayOptions: {
226
+ show: {
227
+ resource: ['contact'],
228
+ operation: ['getMany'],
229
+ },
230
+ },
231
+ default: false,
232
+ description: 'Whether to return all results or only up to a given limit',
233
+ },
234
+ {
235
+ displayName: 'Limit',
236
+ name: 'limit',
237
+ type: 'number',
238
+ displayOptions: {
239
+ show: {
240
+ resource: ['contact'],
241
+ operation: ['getMany'],
242
+ returnAll: [false],
243
+ },
244
+ },
245
+ typeOptions: {
246
+ minValue: 1,
247
+ maxValue: 100,
248
+ },
249
+ default: 50,
250
+ description: 'Max number of results to return',
251
+ },
252
+ {
253
+ displayName: 'Search Query',
254
+ name: 'search',
255
+ type: 'string',
256
+ displayOptions: {
257
+ show: {
258
+ resource: ['contact'],
259
+ operation: ['getMany'],
260
+ },
261
+ },
262
+ default: '',
263
+ description: 'Search query to filter contacts (name, phone_number, telephone_number)',
264
+ },
265
+ // =============================================
266
+ // Record Fields
267
+ // =============================================
268
+ // Fields for Record Create operation
269
+ {
270
+ displayName: 'Tag',
271
+ name: 'tag',
272
+ type: 'string',
273
+ required: true,
274
+ displayOptions: {
275
+ show: {
276
+ resource: ['record'],
277
+ operation: ['create', 'update'],
278
+ },
279
+ },
280
+ default: '',
281
+ description: 'Status title/tag for the record',
282
+ },
283
+ {
284
+ displayName: 'Topic',
285
+ name: 'topic',
286
+ type: 'string',
287
+ required: true,
288
+ displayOptions: {
289
+ show: {
290
+ resource: ['record'],
291
+ operation: ['create', 'update'],
292
+ },
293
+ },
294
+ default: '',
295
+ description: 'Topic title for the record',
296
+ },
297
+ {
298
+ displayName: 'Due Date',
299
+ name: 'dueDate',
300
+ type: 'string',
301
+ required: true,
302
+ displayOptions: {
303
+ show: {
304
+ resource: ['record'],
305
+ operation: ['create', 'update'],
306
+ },
307
+ },
308
+ default: '',
309
+ placeholder: '2025-03-10',
310
+ description: 'Due date in YYYY-MM-DD format',
311
+ },
312
+ {
313
+ displayName: 'Contact',
314
+ name: 'contact',
315
+ type: 'collection',
316
+ required: true,
317
+ placeholder: 'Add Contact Field',
318
+ displayOptions: {
319
+ show: {
320
+ resource: ['record'],
321
+ operation: ['create', 'update'],
322
+ },
323
+ },
324
+ default: {},
325
+ options: [
326
+ {
327
+ displayName: 'Name',
328
+ name: 'name',
329
+ type: 'string',
330
+ default: '',
331
+ required: true,
332
+ description: 'Contact name',
333
+ },
334
+ {
335
+ displayName: 'Phone Number',
336
+ name: 'phone_number',
337
+ type: 'string',
338
+ default: '',
339
+ required: true,
340
+ description: 'Contact phone number',
341
+ },
342
+ {
343
+ displayName: 'Telephone Number',
344
+ name: 'telephone_number',
345
+ type: 'string',
346
+ default: '',
347
+ description: 'Contact landline number',
348
+ },
349
+ {
350
+ displayName: 'Address',
351
+ name: 'address',
352
+ type: 'string',
353
+ default: '',
354
+ description: 'Contact address',
355
+ },
356
+ {
357
+ displayName: 'Is Legal',
358
+ name: 'is_legal',
359
+ type: 'boolean',
360
+ default: false,
361
+ description: 'Whether contact is legal entity (true) or natural person (false)',
362
+ },
363
+ ],
364
+ },
365
+ {
366
+ displayName: 'Linked User',
367
+ name: 'linkedUser',
368
+ type: 'string',
369
+ displayOptions: {
370
+ show: {
371
+ resource: ['record'],
372
+ operation: ['create', 'update'],
373
+ },
374
+ },
375
+ default: '',
376
+ description: 'Phone number of the user responsible for following up on the record',
377
+ },
378
+ {
379
+ displayName: 'Products',
380
+ name: 'products',
381
+ type: 'fixedCollection',
382
+ typeOptions: {
383
+ multipleValues: true,
384
+ },
385
+ required: true,
386
+ displayOptions: {
387
+ show: {
388
+ resource: ['record'],
389
+ operation: ['create', 'update'],
390
+ },
391
+ },
392
+ default: {},
393
+ placeholder: 'Add Product',
394
+ options: [
395
+ {
396
+ name: 'product',
397
+ displayName: 'Product',
398
+ values: [
399
+ {
400
+ displayName: 'Product ID',
401
+ name: 'product',
402
+ type: 'number',
403
+ default: 0,
404
+ required: true,
405
+ description: 'Product identifier',
406
+ },
407
+ {
408
+ displayName: 'Number',
409
+ name: 'number',
410
+ type: 'number',
411
+ default: 0,
412
+ required: true,
413
+ description: 'Quantity of product',
414
+ },
415
+ {
416
+ displayName: 'Purchased Price',
417
+ name: 'purchased_price',
418
+ type: 'number',
419
+ default: 0,
420
+ required: true,
421
+ description: 'Purchase price of the product',
422
+ },
423
+ ],
424
+ },
425
+ ],
426
+ },
427
+ {
428
+ displayName: 'Answers',
429
+ name: 'answers',
430
+ type: 'fixedCollection',
431
+ typeOptions: {
432
+ multipleValues: true,
433
+ },
434
+ required: true,
435
+ displayOptions: {
436
+ show: {
437
+ resource: ['record'],
438
+ operation: ['create', 'update'],
439
+ },
440
+ },
441
+ default: {},
442
+ placeholder: 'Add Answer',
443
+ options: [
444
+ {
445
+ name: 'answer',
446
+ displayName: 'Answer',
447
+ values: [
448
+ {
449
+ displayName: 'Field ID',
450
+ name: 'field',
451
+ type: 'number',
452
+ default: 0,
453
+ required: true,
454
+ description: 'Field identifier',
455
+ },
456
+ {
457
+ displayName: 'Answer',
458
+ name: 'answer',
459
+ type: 'string',
460
+ default: '',
461
+ required: true,
462
+ description: 'Answer for the field',
463
+ },
464
+ ],
465
+ },
466
+ ],
467
+ },
468
+ // Fields for Update operation
469
+ {
470
+ displayName: 'Record ID',
471
+ name: 'recordId',
472
+ type: 'string',
473
+ required: true,
474
+ displayOptions: {
475
+ show: {
476
+ resource: ['record'],
477
+ operation: ['update', 'delete'],
478
+ },
479
+ },
480
+ default: '',
481
+ description: 'ID of the record to update or delete',
482
+ },
483
+ // Fields for Get Many operation
484
+ {
485
+ displayName: 'Return All',
486
+ name: 'returnAll',
487
+ type: 'boolean',
488
+ displayOptions: {
489
+ show: {
490
+ resource: ['record'],
491
+ operation: ['getMany'],
492
+ },
493
+ },
494
+ default: false,
495
+ description: 'Whether to return all results or only up to a given limit',
496
+ },
497
+ {
498
+ displayName: 'Limit',
499
+ name: 'limit',
500
+ type: 'number',
501
+ displayOptions: {
502
+ show: {
503
+ resource: ['record'],
504
+ operation: ['getMany'],
505
+ returnAll: [false],
506
+ },
507
+ },
508
+ typeOptions: {
509
+ minValue: 1,
510
+ maxValue: 100,
511
+ },
512
+ default: 50,
513
+ description: 'Max number of results to return',
514
+ },
515
+ {
516
+ displayName: 'Search Query',
517
+ name: 'search',
518
+ type: 'string',
519
+ displayOptions: {
520
+ show: {
521
+ resource: ['record'],
522
+ operation: ['getMany'],
523
+ },
524
+ },
525
+ default: '',
526
+ description: 'Search query to filter records',
527
+ },
528
+ ],
529
+ };
530
+ }
531
+ async execute() {
532
+ const items = this.getInputData();
533
+ const returnData = [];
534
+ const resource = this.getNodeParameter('resource', 0);
535
+ const operation = this.getNodeParameter('operation', 0);
536
+ for (let i = 0; i < items.length; i++) {
537
+ try {
538
+ if (resource === 'contact') {
539
+ if (operation === 'create') {
540
+ // Get parameters
541
+ const name = this.getNodeParameter('contactName', i);
542
+ const phoneNumber = this.getNodeParameter('contactPhoneNumber', i);
543
+ const telephoneNumber = this.getNodeParameter('contactTelephoneNumber', i, '');
544
+ const address = this.getNodeParameter('contactAddress', i, '');
545
+ const isLegal = this.getNodeParameter('contactIsLegal', i);
546
+ const isArchived = this.getNodeParameter('contactIsArchived', i);
547
+ // Build request body
548
+ const body = {
549
+ name,
550
+ phone_number: phoneNumber,
551
+ is_legal: isLegal,
552
+ is_archived: isArchived,
553
+ };
554
+ if (telephoneNumber) {
555
+ body.telephone_number = telephoneNumber;
556
+ }
557
+ if (address) {
558
+ body.address = address;
559
+ }
560
+ // Make API request
561
+ const response = await this.helpers.httpRequestWithAuthentication.call(this, 'hamkarApi', {
562
+ method: 'POST',
563
+ url: 'https://api.hamkar.co/api/contact/',
564
+ body,
565
+ json: true,
566
+ });
567
+ returnData.push(response);
568
+ }
569
+ if (operation === 'update') {
570
+ // Get parameters
571
+ const contactId = this.getNodeParameter('contactId', i);
572
+ const name = this.getNodeParameter('contactName', i);
573
+ const phoneNumber = this.getNodeParameter('contactPhoneNumber', i);
574
+ const telephoneNumber = this.getNodeParameter('contactTelephoneNumber', i, '');
575
+ const address = this.getNodeParameter('contactAddress', i, '');
576
+ const isLegal = this.getNodeParameter('contactIsLegal', i);
577
+ const isArchived = this.getNodeParameter('contactIsArchived', i);
578
+ // Build request body
579
+ const body = {
580
+ name,
581
+ phone_number: phoneNumber,
582
+ is_legal: isLegal,
583
+ is_archived: isArchived,
584
+ };
585
+ if (telephoneNumber) {
586
+ body.telephone_number = telephoneNumber;
587
+ }
588
+ if (address) {
589
+ body.address = address;
590
+ }
591
+ // Make API request (supports both PUT and PATCH)
592
+ const response = await this.helpers.httpRequestWithAuthentication.call(this, 'hamkarApi', {
593
+ method: 'PUT',
594
+ url: `https://api.hamkar.co/api/contact/${contactId}`,
595
+ body,
596
+ json: true,
597
+ });
598
+ returnData.push(response);
599
+ }
600
+ if (operation === 'delete') {
601
+ const contactId = this.getNodeParameter('contactId', i);
602
+ // Make API request
603
+ await this.helpers.httpRequestWithAuthentication.call(this, 'hamkarApi', {
604
+ method: 'DELETE',
605
+ url: `https://api.hamkar.co/api/contact/${contactId}`,
606
+ json: true,
607
+ });
608
+ returnData.push({ success: true, contact_id: contactId });
609
+ }
610
+ if (operation === 'getMany') {
611
+ const returnAll = this.getNodeParameter('returnAll', i);
612
+ const search = this.getNodeParameter('search', i, '');
613
+ let url = 'https://api.hamkar.co/api/contact/';
614
+ const qs = {};
615
+ if (search) {
616
+ qs.search = search;
617
+ }
618
+ if (returnAll) {
619
+ // Fetch all pages
620
+ let hasMore = true;
621
+ let nextUrl = url;
622
+ while (hasMore) {
623
+ const response = await this.helpers.httpRequestWithAuthentication.call(this, 'hamkarApi', {
624
+ method: 'GET',
625
+ url: nextUrl,
626
+ qs: nextUrl === url ? qs : {},
627
+ json: true,
628
+ });
629
+ const results = response.results;
630
+ returnData.push(...results);
631
+ if (response.next) {
632
+ nextUrl = response.next;
633
+ }
634
+ else {
635
+ hasMore = false;
636
+ }
637
+ }
638
+ }
639
+ else {
640
+ const limit = this.getNodeParameter('limit', i);
641
+ qs.limit = limit;
642
+ const response = await this.helpers.httpRequestWithAuthentication.call(this, 'hamkarApi', {
643
+ method: 'GET',
644
+ url,
645
+ qs,
646
+ json: true,
647
+ });
648
+ const results = response.results;
649
+ returnData.push(...results);
650
+ }
651
+ }
652
+ }
653
+ if (resource === 'record') {
654
+ if (operation === 'create') {
655
+ // Get parameters
656
+ const tag = this.getNodeParameter('tag', i);
657
+ const topic = this.getNodeParameter('topic', i);
658
+ const dueDate = this.getNodeParameter('dueDate', i);
659
+ const contact = this.getNodeParameter('contact', i);
660
+ const linkedUser = this.getNodeParameter('linkedUser', i, '');
661
+ const productsData = this.getNodeParameter('products', i);
662
+ const answersData = this.getNodeParameter('answers', i);
663
+ // Format products
664
+ const products = (productsData.product || []).map((p) => ({
665
+ product: p.product,
666
+ number: p.number,
667
+ purchased_price: p.purchased_price,
668
+ }));
669
+ // Format answers
670
+ const answers = (answersData.answer || []).map((a) => ({
671
+ field: a.field,
672
+ answer: a.answer,
673
+ }));
674
+ // Build request body
675
+ const body = {
676
+ tag,
677
+ topic,
678
+ duo_date: dueDate,
679
+ contact,
680
+ products,
681
+ answers,
682
+ };
683
+ if (linkedUser) {
684
+ body.linked_user = linkedUser;
685
+ }
686
+ // Make API request
687
+ const response = await this.helpers.httpRequestWithAuthentication.call(this, 'hamkarApi', {
688
+ method: 'POST',
689
+ url: 'https://api.hamkar.co/api/record/',
690
+ body,
691
+ json: true,
692
+ });
693
+ returnData.push(response);
694
+ }
695
+ if (operation === 'update') {
696
+ // Get parameters
697
+ const recordId = this.getNodeParameter('recordId', i);
698
+ const tag = this.getNodeParameter('tag', i);
699
+ const topic = this.getNodeParameter('topic', i);
700
+ const dueDate = this.getNodeParameter('dueDate', i);
701
+ const contact = this.getNodeParameter('contact', i);
702
+ const linkedUser = this.getNodeParameter('linkedUser', i, '');
703
+ const productsData = this.getNodeParameter('products', i);
704
+ const answersData = this.getNodeParameter('answers', i);
705
+ // Format products
706
+ const products = (productsData.product || []).map((p) => ({
707
+ product: p.product,
708
+ number: p.number,
709
+ purchased_price: p.purchased_price,
710
+ }));
711
+ // Format answers
712
+ const answers = (answersData.answer || []).map((a) => ({
713
+ field: a.field,
714
+ answer: a.answer,
715
+ }));
716
+ // Build request body
717
+ const body = {
718
+ tag,
719
+ topic,
720
+ duo_date: dueDate,
721
+ contact,
722
+ products,
723
+ answers,
724
+ };
725
+ if (linkedUser) {
726
+ body.linked_user = linkedUser;
727
+ }
728
+ // Make API request
729
+ const response = await this.helpers.httpRequestWithAuthentication.call(this, 'hamkarApi', {
730
+ method: 'PUT',
731
+ url: `https://api.hamkar.co/api/record/${recordId}`,
732
+ body,
733
+ json: true,
734
+ });
735
+ returnData.push(response);
736
+ }
737
+ if (operation === 'delete') {
738
+ const recordId = this.getNodeParameter('recordId', i);
739
+ // Make API request
740
+ await this.helpers.httpRequestWithAuthentication.call(this, 'hamkarApi', {
741
+ method: 'DELETE',
742
+ url: `https://api.hamkar.co/api/record/${recordId}`,
743
+ json: true,
744
+ });
745
+ returnData.push({ success: true, id: recordId });
746
+ }
747
+ if (operation === 'getMany') {
748
+ const returnAll = this.getNodeParameter('returnAll', i);
749
+ const search = this.getNodeParameter('search', i, '');
750
+ let url = 'https://api.hamkar.co/api/record/';
751
+ const qs = {};
752
+ if (search) {
753
+ qs.search = search;
754
+ }
755
+ if (returnAll) {
756
+ // Fetch all pages
757
+ let hasMore = true;
758
+ let nextUrl = url;
759
+ while (hasMore) {
760
+ const response = await this.helpers.httpRequestWithAuthentication.call(this, 'hamkarApi', {
761
+ method: 'GET',
762
+ url: nextUrl,
763
+ qs: nextUrl === url ? qs : {},
764
+ json: true,
765
+ });
766
+ const results = response.results;
767
+ returnData.push(...results);
768
+ if (response.next) {
769
+ nextUrl = response.next;
770
+ }
771
+ else {
772
+ hasMore = false;
773
+ }
774
+ }
775
+ }
776
+ else {
777
+ const limit = this.getNodeParameter('limit', i);
778
+ qs.limit = limit;
779
+ const response = await this.helpers.httpRequestWithAuthentication.call(this, 'hamkarApi', {
780
+ method: 'GET',
781
+ url,
782
+ qs,
783
+ json: true,
784
+ });
785
+ const results = response.results;
786
+ returnData.push(...results);
787
+ }
788
+ }
789
+ }
790
+ }
791
+ catch (error) {
792
+ if (this.continueOnFail()) {
793
+ const errorMessage = error instanceof Error ? error.message : String(error);
794
+ returnData.push({ error: errorMessage });
795
+ continue;
796
+ }
797
+ throw error;
798
+ }
799
+ }
800
+ return [this.helpers.returnJsonArray(returnData)];
801
+ }
802
+ }
803
+ exports.Hamkar = Hamkar;
Binary file
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">
3
+ <rect width="100" height="100" fill="#00aacc" rx="15"/>
4
+ <text x="50" y="70" font-family="Arial, sans-serif" font-size="60" font-weight="bold" fill="white" text-anchor="middle">H</text>
5
+ </svg>
6
+
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ // This file is intentionally empty
2
+ // The actual entry points are defined in package.json under the "n8n" property
3
+
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "n8n-nodes-hamkar",
3
+ "version": "1.0.0",
4
+ "description": "n8n node for Hamkar.co API - Contact and Record management operations",
5
+ "keywords": [
6
+ "n8n-community-node-package",
7
+ "n8n",
8
+ "hamkar",
9
+ "crm",
10
+ "records"
11
+ ],
12
+ "license": "MIT",
13
+ "homepage": "https://github.com/yourusername/n8n-nodes-hamkar",
14
+ "author": {
15
+ "name": "Your Name",
16
+ "email": "your.email@example.com"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/yourusername/n8n-nodes-hamkar.git"
21
+ },
22
+ "main": "index.js",
23
+ "scripts": {
24
+ "build": "tsc && gulp build:icons",
25
+ "dev": "tsc --watch",
26
+ "format": "prettier nodes credentials --write",
27
+ "lint": "eslint nodes/**/*.ts credentials/**/*.ts package.json",
28
+ "lintfix": "eslint nodes/**/*.ts credentials/**/*.ts package.json --fix",
29
+ "prepublishOnly": "npm run build && npm run lint"
30
+ },
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "n8n": {
35
+ "n8nNodesApiVersion": 1,
36
+ "credentials": [
37
+ "dist/credentials/HamkarApi.credentials.js"
38
+ ],
39
+ "nodes": [
40
+ "dist/nodes/Hamkar/Hamkar.node.js"
41
+ ]
42
+ },
43
+ "devDependencies": {
44
+ "@typescript-eslint/parser": "^5.0.0",
45
+ "eslint": "^8.0.0",
46
+ "eslint-plugin-n8n-nodes-base": "^1.11.0",
47
+ "gulp": "^4.0.2",
48
+ "n8n-workflow": "^1.0.0",
49
+ "prettier": "^2.7.1",
50
+ "typescript": "~5.3.0"
51
+ },
52
+ "peerDependencies": {
53
+ "n8n-workflow": "*"
54
+ }
55
+ }
56
+