@qelos/plugin-play 3.0.1 → 3.0.3
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/create-cert.js +1 -1
- package/package.json +2 -2
- package/src/authentication.ts +46 -8
- package/src/endpoints.ts +1 -1
- package/src/micro-frontends.ts +48 -5
package/create-cert.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const {execSync} = require('child_process');
|
|
2
2
|
|
|
3
|
-
execSync(`cd cert && docker run -v $
|
|
3
|
+
execSync(`cd cert && docker run -v ${process.cwd()}:/certs \\
|
|
4
4
|
-e SSL_SUBJECT=${process.env.HOSTNAME || '0.0.0.0'} stakater/ssl-certs-generator:1.0`, {stdio: 'inherit'});
|
|
5
5
|
|
|
6
6
|
console.log('done.');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qelos/plugin-play",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "Play a plugin for Qelos!",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@fastify/cookie": "^8.3.0",
|
|
20
20
|
"@fastify/static": "^6.5.0",
|
|
21
21
|
"@qelos/sdk": "^3.0.1",
|
|
22
|
-
"@qelos/web-sdk": "^3.0.
|
|
22
|
+
"@qelos/web-sdk": "^3.0.3",
|
|
23
23
|
"fastify": "^4.3.0",
|
|
24
24
|
"jsonwebtoken": "^8.5.1",
|
|
25
25
|
"undici": "^5.8.0"
|
package/src/authentication.ts
CHANGED
|
@@ -260,19 +260,53 @@ export function getCallbackRoute(): RouteOptions {
|
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
export function getFrontendAuthorizationRoute(): RouteOptions {
|
|
263
|
+
let standaloneAuthorize: (reply) => Promise<any> = async () => {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
263
266
|
if (config.qelosUrl) {
|
|
264
|
-
onFrontendAuthorization(async ({returnUrl, user, tenant}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
267
|
+
onFrontendAuthorization(async ({returnUrl, user, tenant}) => {
|
|
268
|
+
try {
|
|
269
|
+
const draft = await getSdk().drafts.getDraft(returnUrl, `${tenant.sub}.${user.email}`);
|
|
270
|
+
if (draft && draft.contextData) {
|
|
271
|
+
return {
|
|
272
|
+
code: draft.contextData.code,
|
|
273
|
+
token: jwt.sign({code: draft.contextData, user, tenant}, config.accessTokenSecret, {expiresIn: '30min'}),
|
|
274
|
+
}
|
|
270
275
|
}
|
|
276
|
+
} catch {
|
|
277
|
+
//
|
|
271
278
|
}
|
|
272
279
|
return;
|
|
273
280
|
});
|
|
281
|
+
|
|
282
|
+
if (config.dev) {
|
|
283
|
+
standaloneAuthorize = async (reply) => {
|
|
284
|
+
const [fullUser] = await getSdk().users.getList({exact: true, email: config.qelosUsername});
|
|
285
|
+
const user = {
|
|
286
|
+
_id: fullUser._id,
|
|
287
|
+
email: fullUser.email,
|
|
288
|
+
firstName: fullUser.firstName,
|
|
289
|
+
lastName: fullUser.lastName,
|
|
290
|
+
roles: fullUser.roles
|
|
291
|
+
}
|
|
292
|
+
const tenant = {
|
|
293
|
+
sub: user._id,
|
|
294
|
+
identifier: user.email
|
|
295
|
+
};
|
|
296
|
+
reply.setCookie('token_default', jwt.sign({
|
|
297
|
+
code: 'default',
|
|
298
|
+
user,
|
|
299
|
+
tenant
|
|
300
|
+
}, config.accessTokenSecret, {expiresIn: '30min'}));
|
|
301
|
+
return {
|
|
302
|
+
user,
|
|
303
|
+
tenant
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
}
|
|
274
307
|
}
|
|
275
308
|
|
|
309
|
+
|
|
276
310
|
return {
|
|
277
311
|
method: 'POST',
|
|
278
312
|
url: manifest.authorizeUrl,
|
|
@@ -298,8 +332,12 @@ export function getFrontendAuthorizationRoute(): RouteOptions {
|
|
|
298
332
|
}
|
|
299
333
|
}
|
|
300
334
|
}
|
|
301
|
-
|
|
302
|
-
|
|
335
|
+
const response = await standaloneAuthorize(reply);
|
|
336
|
+
if (!response) {
|
|
337
|
+
reply.statusCode = 401;
|
|
338
|
+
return notAuthorized;
|
|
339
|
+
}
|
|
340
|
+
return response;
|
|
303
341
|
}
|
|
304
342
|
}
|
|
305
343
|
}
|
package/src/endpoints.ts
CHANGED
package/src/micro-frontends.ts
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
import manifest, {NavBarGroup} from './manifest';
|
|
2
|
+
import {addProxyEndpoint, QelosRouteParams} from './endpoints';
|
|
2
3
|
|
|
3
|
-
export interface
|
|
4
|
+
export interface IframeMicroFrontend extends GlobalMicroFrontend {
|
|
5
|
+
url: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface PreDesignedMicroFrontendOptions
|
|
9
|
+
extends Pick<QelosRouteParams, 'verifyToken'>,
|
|
10
|
+
Partial<Pick<QelosRouteParams, 'handler'>>,
|
|
11
|
+
GlobalMicroFrontend {
|
|
12
|
+
use: string;
|
|
13
|
+
fetchUrl?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface PreDesignedMicroFrontend extends Omit<PreDesignedMicroFrontendOptions, 'handler' | 'verifyToken'> {
|
|
17
|
+
fetchUrl: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface GlobalMicroFrontend {
|
|
4
21
|
name: string;
|
|
5
22
|
description: string;
|
|
6
|
-
url: string;
|
|
7
23
|
roles?: string[],
|
|
8
24
|
route?: {
|
|
9
25
|
name: string;
|
|
@@ -24,11 +40,38 @@ export interface MicroFrontend {
|
|
|
24
40
|
}
|
|
25
41
|
}
|
|
26
42
|
|
|
27
|
-
export
|
|
28
|
-
|
|
43
|
+
export type MicroFrontendOptions = IframeMicroFrontend | PreDesignedMicroFrontendOptions
|
|
44
|
+
export type MicroFrontend = IframeMicroFrontend | PreDesignedMicroFrontend
|
|
45
|
+
|
|
46
|
+
export function addMicroFrontend(mfe: MicroFrontendOptions) {
|
|
47
|
+
mfe = {...mfe}
|
|
48
|
+
let manifestMfe: MicroFrontend;
|
|
49
|
+
if ('use' in mfe) {
|
|
50
|
+
const verifyToken = mfe.verifyToken || true;
|
|
51
|
+
delete mfe.verifyToken;
|
|
52
|
+
|
|
53
|
+
if ('handler' in mfe) {
|
|
54
|
+
const fetchUrl = mfe.fetchUrl || btoa(mfe.name);
|
|
55
|
+
const handler = mfe.handler;
|
|
56
|
+
delete mfe.handler;
|
|
57
|
+
addProxyEndpoint(fetchUrl, {
|
|
58
|
+
handler,
|
|
59
|
+
verifyToken,
|
|
60
|
+
});
|
|
61
|
+
manifestMfe = {
|
|
62
|
+
...mfe as PreDesignedMicroFrontend,
|
|
63
|
+
fetchUrl
|
|
64
|
+
}
|
|
65
|
+
} else if ('fetchUrl' in mfe) {
|
|
66
|
+
manifestMfe = mfe as PreDesignedMicroFrontend;
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
manifestMfe = mfe;
|
|
70
|
+
}
|
|
71
|
+
manifest.microFrontends.push(manifestMfe);
|
|
29
72
|
}
|
|
30
73
|
|
|
31
|
-
export function addGroupedMicroFrontends(group: NavBarGroup, mfeArray:
|
|
74
|
+
export function addGroupedMicroFrontends(group: NavBarGroup, mfeArray: MicroFrontendOptions[]) {
|
|
32
75
|
manifest.navBarGroups.push(group);
|
|
33
76
|
mfeArray.forEach(mfe => {
|
|
34
77
|
addMicroFrontend({...mfe, route: {...mfe.route, group: group.key}})
|