@nebula.js/cli-create 3.0.3 → 3.1.0-alpha.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nebula.js/cli-create",
3
- "version": "3.0.3",
3
+ "version": "3.1.0-alpha.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "author": "QlikTech International AB",
@@ -27,5 +27,5 @@
27
27
  "fs-extra": "10.1.0",
28
28
  "inquirer": "8.2.4"
29
29
  },
30
- "gitHead": "2beefab5a936527fe5cdd20b98784d72199327fb"
30
+ "gitHead": "06eb9b2d1876ac3abce9a1c749c0b428d3251481"
31
31
  }
@@ -13,8 +13,8 @@
13
13
  "dependencies": {
14
14
  "@nebula.js/stardust": "<%= nebulaVersion %>",
15
15
  "@nebula.js/sn-bar-chart": "^1.x",
16
- "@qlik/sdk": "^0.9.1",
16
+ "@qlik/sdk": "^0.12.0",
17
17
  "enigma.js": "^2.6.3",
18
- "parcel": "^2.3.2"
18
+ "parcel": "^2.7.0"
19
19
  }
20
20
  }
@@ -0,0 +1,86 @@
1
+ import enigma from 'enigma.js';
2
+ import schema from 'enigma.js/schemas/12.936.0.json';
3
+ import { Auth, AuthType } from '@qlik/sdk';
4
+
5
+ export default class Authenticator {
6
+ /**
7
+ *
8
+ * @param {String} appId - application id from sense client
9
+ * @param {Strign} url - tenant url
10
+ */
11
+ constructor({ appId, url }) {
12
+ this.authInstance = null;
13
+ this.appId = appId;
14
+ this.host = url.replace(/^https?:\/\//, '').replace(/\/?/, '');
15
+ }
16
+
17
+ /**
18
+ * gets you the promise of enigma instance for your app
19
+ * based on webIntegrationId
20
+ * @param {Strign} webIntegrationId - your web Integration Id from managment console
21
+ * @returns {Promise<IEnigmaClass>} enigma app promise
22
+ */
23
+ async AuthenticateWithWebIntegrationId({ webIntegrationId }) {
24
+ this.authInstance = new Auth({
25
+ authType: AuthType.WebIntegration,
26
+ autoRedirect: true,
27
+ host: this.host,
28
+ webIntegrationId,
29
+ });
30
+
31
+ if (!this.authInstance.isAuthenticated()) {
32
+ this.authInstance.authenticate();
33
+ } else return this.getEnigmaApp();
34
+
35
+ return null;
36
+ }
37
+
38
+ /**
39
+ * gets you the promise of enigma instance for your app
40
+ * based on clientId
41
+ * @param {Strign} clientId - your client Id from managment console
42
+ * @param {Strign} redirectUri - the redirect url while bringing you the code + state, default is `window.location.origin`
43
+ * @returns {Promise<IEnigmaClass>} enigma app promise
44
+ */
45
+ async AuthenticateWithOAuth({ clientId, redirectUri }) {
46
+ this.authInstance = new Auth({
47
+ authType: AuthType.OAuth2,
48
+ host: this.host,
49
+ redirectUri: redirectUri || window.location.origin,
50
+ clientId,
51
+ });
52
+
53
+ const urlParams = new URLSearchParams(window.location.search);
54
+ if (urlParams.get('code')) {
55
+ try {
56
+ await this.authInstance.authorize(window.location.href);
57
+ const url = new URL(window.location);
58
+ url.searchParams.delete('code');
59
+ url.searchParams.delete('state');
60
+ window.history.replaceState(null, null, url);
61
+ } catch (error) {
62
+ console.error({ error });
63
+ }
64
+
65
+ return this.getEnigmaApp();
66
+ }
67
+
68
+ if (!(await this.authInstance.isAuthorized())) {
69
+ const { url } = await this.authInstance.generateAuthorizationUrl();
70
+ const protocol = url.includes('https://') ? 'https' : 'http';
71
+ window.location = `${protocol}://${url}`;
72
+ }
73
+
74
+ return null;
75
+ }
76
+
77
+ /**
78
+ * returns a promise of enigma instance
79
+ * @returns {Promise<IEnigmaClass>} enigma app instance promise
80
+ */
81
+ async getEnigmaApp() {
82
+ const url = await this.authInstance.generateWebsocketUrl(this.appId);
83
+ const enigmaGlobal = await enigma.create({ schema, url }).open();
84
+ return enigmaGlobal.openDoc(this.appId);
85
+ }
86
+ }
@@ -1,24 +1,26 @@
1
- import enigma from 'enigma.js';
2
- import schema from 'enigma.js/schemas/12.936.0.json';
3
- import { Auth, AuthType } from '@qlik/sdk';
1
+ import { AuthType } from '@qlik/sdk';
2
+ import Authenticator from './Authenticator';
4
3
 
5
- async function connect({ url, webIntegrationId, appId }) {
6
- const authInstance = new Auth({
7
- webIntegrationId,
8
- autoRedirect: true,
9
- authType: AuthType.WebIntegration,
10
- host: url.replace(/^https?:\/\//, '').replace(/\/?/, ''),
4
+ async function connect({ connectionType, url, appId, ...rest }) {
5
+ const AuthenticatorInstance = new Authenticator({
6
+ url,
7
+ appId,
11
8
  });
12
9
 
13
- if (!authInstance.isAuthenticated()) {
14
- authInstance.authenticate();
15
- } else {
16
- const wssUrl = await authInstance.generateWebsocketUrl(appId);
17
- const enigmaGlobal = await enigma.create({ schema, url: wssUrl }).open();
18
- return enigmaGlobal.openDoc(appId);
19
- }
10
+ switch (connectionType) {
11
+ case AuthType.WebIntegration: {
12
+ return AuthenticatorInstance.AuthenticateWithWebIntegrationId({
13
+ ...rest,
14
+ });
15
+ }
16
+
17
+ case AuthType.OAuth2: {
18
+ return AuthenticatorInstance.AuthenticateWithOAuth({ ...rest });
19
+ }
20
20
 
21
- return null;
21
+ default:
22
+ throw new Error('Please Provide a `connectionType` to proceed!');
23
+ }
22
24
  }
23
25
 
24
26
  export default connect;
@@ -1,12 +1,18 @@
1
1
  /* eslint-disable */
2
+ import { AuthType } from '@qlik/sdk';
2
3
  import embed from './configure';
3
4
  import connect from './connect';
4
5
 
5
6
  async function run() {
6
7
  const app = await connect({
8
+ connectionType: '<AuthType.SOME_CONNECTION_TYPE>',
7
9
  url: '<URL>',
8
- webIntegrationId: '<Qlik web integration id>',
9
10
  appId: '<App id>',
11
+
12
+ // you should use only one of below keys
13
+ // based on your `connectionType`
14
+ clientId: '<Qlik OAuth client id>',
15
+ webIntegrationId: '<Qlik web integration id>',
10
16
  });
11
17
 
12
18
  const n = embed(app);
@@ -10,7 +10,7 @@
10
10
  "keywords": ["qlik", "nebula", "stardust"],
11
11
  "files": ["dist"],
12
12
  "engines": {
13
- "node": ">=8"
13
+ "node": ">=18"
14
14
  },
15
15
  "main": "dist/<%= name %>.js",
16
16
  "module": "dist/<%= name %>.esm.js",
@@ -10,7 +10,7 @@
10
10
  "keywords": ["qlik", "nebula", "stardust"],
11
11
  "files": ["dist"],
12
12
  "engines": {
13
- "node": ">=8"
13
+ "node": ">=18"
14
14
  },
15
15
  "main": "dist/<%= name %>.js",
16
16
  "module": "dist/<%= name %>.esm.js",