n8n-nodes-qlik-cloud 1.2.2 → 1.2.4

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.
@@ -887,13 +887,44 @@ class QlikCloud {
887
887
  {
888
888
  name: 'qlikCloudApi',
889
889
  required: true,
890
+ displayOptions: {
891
+ show: {
892
+ authentication: [
893
+ 'apiToken',
894
+ ],
895
+ },
896
+ },
890
897
  },
891
898
  {
892
899
  name: 'qlikCloudOAuth2Api',
893
900
  required: true,
901
+ displayOptions: {
902
+ show: {
903
+ authentication: [
904
+ 'oAuth2',
905
+ ],
906
+ },
907
+ },
894
908
  },
895
909
  ],
896
910
  properties: [
911
+ {
912
+ displayName: 'Authentication',
913
+ name: 'authentication',
914
+ type: 'options',
915
+ options: [
916
+ {
917
+ name: 'API Token',
918
+ value: 'apiToken',
919
+ },
920
+ {
921
+ name: 'OAuth2',
922
+ value: 'oAuth2',
923
+ },
924
+ ],
925
+ default: 'apiToken',
926
+ description: 'Choose how to authenticate to Qlik Cloud',
927
+ },
897
928
  {
898
929
  displayName: 'Resource',
899
930
  name: 'resource',
@@ -3,17 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.qlikApiRequest = qlikApiRequest;
4
4
  const n8n_workflow_1 = require("n8n-workflow");
5
5
  async function qlikApiRequest(method, endpoint, body, qs, returnFullResponse = false, extraOptions = {}) {
6
- const credentials = await this.getCredentials('qlikCloudApi');
6
+ const authenticationMethod = this.getNodeParameter('authentication', 0);
7
+ const credentialType = authenticationMethod === 'oAuth2' ? 'qlikCloudOAuth2Api' : 'qlikCloudApi';
8
+ const credentials = await this.getCredentials(credentialType);
7
9
  if (!credentials) {
8
10
  throw new n8n_workflow_1.NodeApiError(this.getNode(), {
9
- message: 'No credentials found for Qlik Cloud API',
11
+ message: `No credentials found for Qlik Cloud API (${authenticationMethod === 'oAuth2' ? 'OAuth2' : 'API Token'})`,
10
12
  });
11
13
  }
12
14
  const baseUrl = credentials.baseUrl.replace(/\/+$/, '');
13
- const accessToken = credentials.accessToken;
14
15
  const url = `${baseUrl}${endpoint.startsWith('/') ? endpoint : `/${endpoint}`}`;
15
- const headers = {
16
- Authorization: `Bearer ${accessToken}`,
16
+ const baseHeaders = {
17
17
  'Content-Type': 'application/json',
18
18
  ...(extraOptions.headers || {}),
19
19
  };
@@ -21,15 +21,25 @@ async function qlikApiRequest(method, endpoint, body, qs, returnFullResponse = f
21
21
  method,
22
22
  url,
23
23
  qs,
24
- json: extraOptions.json ?? true,
25
24
  returnFullResponse,
26
25
  ...extraOptions,
27
- headers,
26
+ json: extraOptions.json ?? true,
27
+ headers: baseHeaders,
28
28
  };
29
+ if (authenticationMethod === 'apiToken') {
30
+ const accessToken = credentials.accessToken;
31
+ options.headers = {
32
+ Authorization: `Bearer ${accessToken}`,
33
+ ...baseHeaders,
34
+ };
35
+ }
29
36
  if (body !== undefined) {
30
37
  options.body = body;
31
38
  }
32
39
  try {
40
+ if (authenticationMethod === 'oAuth2') {
41
+ return await this.helpers.httpRequestWithAuthentication.call(this, credentialType, options);
42
+ }
33
43
  return await this.helpers.httpRequest(options);
34
44
  }
35
45
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-qlik-cloud",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "n8n node for Qlik Cloud REST APIs integration",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1240,13 +1240,44 @@ export class QlikCloud implements INodeType {
1240
1240
  {
1241
1241
  name: 'qlikCloudApi',
1242
1242
  required: true,
1243
+ displayOptions: {
1244
+ show: {
1245
+ authentication: [
1246
+ 'apiToken',
1247
+ ],
1248
+ },
1249
+ },
1243
1250
  },
1244
1251
  {
1245
1252
  name: 'qlikCloudOAuth2Api',
1246
1253
  required: true,
1254
+ displayOptions: {
1255
+ show: {
1256
+ authentication: [
1257
+ 'oAuth2',
1258
+ ],
1259
+ },
1260
+ },
1247
1261
  },
1248
1262
  ],
1249
1263
  properties: [
1264
+ {
1265
+ displayName: 'Authentication',
1266
+ name: 'authentication',
1267
+ type: 'options',
1268
+ options: [
1269
+ {
1270
+ name: 'API Token',
1271
+ value: 'apiToken',
1272
+ },
1273
+ {
1274
+ name: 'OAuth2',
1275
+ value: 'oAuth2',
1276
+ },
1277
+ ],
1278
+ default: 'apiToken',
1279
+ description: 'Choose how to authenticate to Qlik Cloud',
1280
+ },
1250
1281
  {
1251
1282
  displayName: 'Resource',
1252
1283
  name: 'resource',
@@ -14,20 +14,20 @@ export async function qlikApiRequest(
14
14
  returnFullResponse: boolean = false,
15
15
  extraOptions: Partial<IHttpRequestOptions> = {},
16
16
  ): Promise<any> {
17
- const credentials = await this.getCredentials('qlikCloudApi');
17
+ const authenticationMethod = this.getNodeParameter('authentication', 0) as 'apiToken' | 'oAuth2';
18
+ const credentialType = authenticationMethod === 'oAuth2' ? 'qlikCloudOAuth2Api' : 'qlikCloudApi';
19
+ const credentials = await this.getCredentials(credentialType);
18
20
 
19
21
  if (!credentials) {
20
22
  throw new NodeApiError(this.getNode(), {
21
- message: 'No credentials found for Qlik Cloud API',
23
+ message: `No credentials found for Qlik Cloud API (${authenticationMethod === 'oAuth2' ? 'OAuth2' : 'API Token'})`,
22
24
  } as any);
23
25
  }
24
26
 
25
27
  const baseUrl = (credentials.baseUrl as string).replace(/\/+$/, '');
26
- const accessToken = credentials.accessToken as string;
27
28
  const url = `${baseUrl}${endpoint.startsWith('/') ? endpoint : `/${endpoint}`}`;
28
29
 
29
- const headers = {
30
- Authorization: `Bearer ${accessToken}`,
30
+ const baseHeaders = {
31
31
  'Content-Type': 'application/json',
32
32
  ...(extraOptions.headers || {}),
33
33
  };
@@ -36,17 +36,29 @@ export async function qlikApiRequest(
36
36
  method,
37
37
  url,
38
38
  qs,
39
- json: extraOptions.json ?? true,
40
39
  returnFullResponse,
41
40
  ...extraOptions,
42
- headers,
41
+ json: extraOptions.json ?? true,
42
+ headers: baseHeaders,
43
43
  };
44
44
 
45
+ if (authenticationMethod === 'apiToken') {
46
+ const accessToken = credentials.accessToken as string;
47
+ options.headers = {
48
+ Authorization: `Bearer ${accessToken}`,
49
+ ...baseHeaders,
50
+ };
51
+ }
52
+
45
53
  if (body !== undefined) {
46
54
  options.body = body;
47
55
  }
48
56
 
49
57
  try {
58
+ if (authenticationMethod === 'oAuth2') {
59
+ return await this.helpers.httpRequestWithAuthentication.call(this, credentialType, options);
60
+ }
61
+
50
62
  return await this.helpers.httpRequest(options);
51
63
  } catch (error) {
52
64
  const errMessage = error instanceof Error ? error.message : typeof error === 'string' ? error : JSON.stringify(error);