@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 +2 -2
- package/templates/mashup/_package.json +2 -2
- package/templates/mashup/src/Authenticator.js +86 -0
- package/templates/mashup/src/connect.js +19 -17
- package/templates/mashup/src/index.js +7 -1
- package/templates/sn/none/_package.json +1 -1
- package/templates/sn/picasso/common/_package.json +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nebula.js/cli-create",
|
|
3
|
-
"version": "3.0.
|
|
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": "
|
|
30
|
+
"gitHead": "06eb9b2d1876ac3abce9a1c749c0b428d3251481"
|
|
31
31
|
}
|
|
@@ -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
|
|
2
|
-
import
|
|
3
|
-
import { Auth, AuthType } from '@qlik/sdk';
|
|
1
|
+
import { AuthType } from '@qlik/sdk';
|
|
2
|
+
import Authenticator from './Authenticator';
|
|
4
3
|
|
|
5
|
-
async function connect({
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
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);
|