@ixiam/n8n-nodes-civicrm 1.0.7 → 1.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.
@@ -1,40 +1,16 @@
1
1
  import type {
2
- ICredentialType,
2
+ ICredentialDataDecryptedObject,
3
+ ICredentialTestFunctions,
4
+ ICredentialsDecrypted,
3
5
  INodeProperties,
4
- IHttpRequestMethods,
5
6
  } from 'n8n-workflow';
6
7
 
7
- export class CiviCrmApi implements ICredentialType {
8
+ export class CiviCrmApi {
9
+
8
10
  name = 'civiCrmApi';
9
11
  displayName = 'CiviCRM API';
10
12
  documentationUrl = 'https://docs.civicrm.org/dev/en/latest/api/';
11
13
 
12
- // ✔ NECESARIO PARA QUE N8N ACEPTE EL TEST
13
- extends = ['genericApi' as const];
14
-
15
- authenticate = {
16
- type: 'generic' as const,
17
- properties: {
18
- headers: {
19
- 'X-Civi-Auth': '={{"Bearer " + $credentials.apiToken}}',
20
- },
21
- },
22
- };
23
-
24
- test = {
25
- request: {
26
- method: 'POST' as IHttpRequestMethods,
27
- url: '={{$credentials.baseUrl.replace(/\\/$/, "")}}/civicrm/ajax/api4/Contact/get',
28
- headers: {
29
- 'X-Civi-Auth': '={{"Bearer " + $credentials.apiToken}}',
30
- 'Content-Type': 'application/json',
31
- },
32
- body: {
33
- limit: 1,
34
- },
35
- },
36
- };
37
-
38
14
  properties: INodeProperties[] = [
39
15
  {
40
16
  displayName: 'Base URL',
@@ -52,4 +28,54 @@ export class CiviCrmApi implements ICredentialType {
52
28
  required: true,
53
29
  },
54
30
  ];
31
+
32
+ // ✔ Autenticación genérica (esto sí es válido)
33
+ authenticate = {
34
+ type: 'generic',
35
+ properties: {
36
+ headers: {
37
+ 'X-Civi-Auth': '={{"Bearer " + $credentials.apiToken}}',
38
+ },
39
+ },
40
+ };
41
+
42
+ async test(
43
+ this: ICredentialTestFunctions,
44
+ credentials: ICredentialsDecrypted<ICredentialDataDecryptedObject>,
45
+ ) {
46
+ const data = credentials.data as { baseUrl: string; apiToken: string };
47
+
48
+ const baseUrl = data.baseUrl.replace(/\/$/, '');
49
+ const token = data.apiToken;
50
+
51
+ try {
52
+ const response = await this.helpers.request({
53
+ method: 'POST',
54
+ url: `${baseUrl}/civicrm/ajax/api4/Contact/get`,
55
+ json: true,
56
+ body: { limit: 1 },
57
+ headers: {
58
+ 'X-Civi-Auth': `Bearer ${token}`,
59
+ 'Content-Type': 'application/json',
60
+ },
61
+ });
62
+
63
+ if (response?.values !== undefined) {
64
+ return {
65
+ status: 'OK',
66
+ message: 'Connection successful.',
67
+ };
68
+ }
69
+
70
+ return {
71
+ status: 'Error',
72
+ message: 'Unexpected API response.',
73
+ };
74
+ } catch (error: any) {
75
+ return {
76
+ status: 'Error',
77
+ message: error.message,
78
+ };
79
+ }
80
+ }
55
81
  }
@@ -1,29 +1,19 @@
1
- import type { ICredentialType, INodeProperties, IHttpRequestMethods } from 'n8n-workflow';
2
- export declare class CiviCrmApi implements ICredentialType {
1
+ import type { ICredentialDataDecryptedObject, ICredentialTestFunctions, ICredentialsDecrypted, INodeProperties } from 'n8n-workflow';
2
+ export declare class CiviCrmApi {
3
3
  name: string;
4
4
  displayName: string;
5
5
  documentationUrl: string;
6
- extends: "genericApi"[];
6
+ properties: INodeProperties[];
7
7
  authenticate: {
8
- type: "generic";
8
+ type: string;
9
9
  properties: {
10
10
  headers: {
11
11
  'X-Civi-Auth': string;
12
12
  };
13
13
  };
14
14
  };
15
- test: {
16
- request: {
17
- method: IHttpRequestMethods;
18
- url: string;
19
- headers: {
20
- 'X-Civi-Auth': string;
21
- 'Content-Type': string;
22
- };
23
- body: {
24
- limit: number;
25
- };
26
- };
27
- };
28
- properties: INodeProperties[];
15
+ test(this: ICredentialTestFunctions, credentials: ICredentialsDecrypted<ICredentialDataDecryptedObject>): Promise<{
16
+ status: string;
17
+ message: any;
18
+ }>;
29
19
  }
@@ -6,29 +6,6 @@ class CiviCrmApi {
6
6
  this.name = 'civiCrmApi';
7
7
  this.displayName = 'CiviCRM API';
8
8
  this.documentationUrl = 'https://docs.civicrm.org/dev/en/latest/api/';
9
- // ✔ NECESARIO PARA QUE N8N ACEPTE EL TEST
10
- this.extends = ['genericApi'];
11
- this.authenticate = {
12
- type: 'generic',
13
- properties: {
14
- headers: {
15
- 'X-Civi-Auth': '={{"Bearer " + $credentials.apiToken}}',
16
- },
17
- },
18
- };
19
- this.test = {
20
- request: {
21
- method: 'POST',
22
- url: '={{$credentials.baseUrl.replace(/\\/$/, "")}}/civicrm/ajax/api4/Contact/get',
23
- headers: {
24
- 'X-Civi-Auth': '={{"Bearer " + $credentials.apiToken}}',
25
- 'Content-Type': 'application/json',
26
- },
27
- body: {
28
- limit: 1,
29
- },
30
- },
31
- };
32
9
  this.properties = [
33
10
  {
34
11
  displayName: 'Base URL',
@@ -46,6 +23,48 @@ class CiviCrmApi {
46
23
  required: true,
47
24
  },
48
25
  ];
26
+ // ✔ Autenticación genérica (esto sí es válido)
27
+ this.authenticate = {
28
+ type: 'generic',
29
+ properties: {
30
+ headers: {
31
+ 'X-Civi-Auth': '={{"Bearer " + $credentials.apiToken}}',
32
+ },
33
+ },
34
+ };
35
+ }
36
+ async test(credentials) {
37
+ const data = credentials.data;
38
+ const baseUrl = data.baseUrl.replace(/\/$/, '');
39
+ const token = data.apiToken;
40
+ try {
41
+ const response = await this.helpers.request({
42
+ method: 'POST',
43
+ url: `${baseUrl}/civicrm/ajax/api4/Contact/get`,
44
+ json: true,
45
+ body: { limit: 1 },
46
+ headers: {
47
+ 'X-Civi-Auth': `Bearer ${token}`,
48
+ 'Content-Type': 'application/json',
49
+ },
50
+ });
51
+ if (response?.values !== undefined) {
52
+ return {
53
+ status: 'OK',
54
+ message: 'Connection successful.',
55
+ };
56
+ }
57
+ return {
58
+ status: 'Error',
59
+ message: 'Unexpected API response.',
60
+ };
61
+ }
62
+ catch (error) {
63
+ return {
64
+ status: 'Error',
65
+ message: error.message,
66
+ };
67
+ }
49
68
  }
50
69
  }
51
70
  exports.CiviCrmApi = CiviCrmApi;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ixiam/n8n-nodes-civicrm",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Full-featured CiviCRM API v4 integration for n8n with support for Contacts, Memberships, Groups, Relationships, Activities and structured sub-entities like Email, Phone, and Address.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "repository": {
23
23
  "type": "git",
24
- "url": "git+https://github.com/ixiam/n8n-nodes-civicrm.git"
24
+ "url": "https://github.com/ixiam/n8n-nodes-civicrm"
25
25
  },
26
26
  "homepage": "https://ixiam.com",
27
27
  "bugs": {