@qelos/plugin-play 3.8.0 → 3.8.1
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/dist/endpoints.d.ts +1 -1
- package/dist/sdk.d.ts +11 -1
- package/dist/sdk.js +33 -9
- package/dist/sdk.js.map +1 -1
- package/package.json +6 -6
- package/src/sdk.ts +66 -16
package/dist/endpoints.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export interface QelosRouteParams extends RouteOptions {
|
|
|
4
4
|
verifyToken: boolean;
|
|
5
5
|
}
|
|
6
6
|
export declare const endpoints: Map<string, QelosRouteParams>;
|
|
7
|
-
export declare const internalEndpoints: Map<string, RouteOptions<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify/types/route").RouteGenericInterface, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, import("fastify").
|
|
7
|
+
export declare const internalEndpoints: Map<string, RouteOptions<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify/types/route").RouteGenericInterface, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, import("fastify").FastifyBaseLogger>>;
|
|
8
8
|
export declare function addProxyEndpoint(path: string, options: Partial<QelosRouteParams>): void;
|
|
9
9
|
export declare function addEndpoint(path: string, options: Partial<QelosRouteParams>): void;
|
|
10
10
|
export declare function addInternalEndpoint(path: string, options: Partial<RouteOptions>): void;
|
package/dist/sdk.d.ts
CHANGED
|
@@ -6,7 +6,17 @@ export declare function authenticate(): Promise<{
|
|
|
6
6
|
refreshToken: string;
|
|
7
7
|
};
|
|
8
8
|
}>;
|
|
9
|
-
export declare function getSdkForUrl<T = any>(appUrl
|
|
9
|
+
export declare function getSdkForUrl<T = any>({ appUrl, refreshToken, accessToken, username, password, onRefresh }: {
|
|
10
|
+
appUrl: string;
|
|
11
|
+
refreshToken?: string;
|
|
12
|
+
accessToken?: string;
|
|
13
|
+
username?: string;
|
|
14
|
+
password?: string;
|
|
15
|
+
onRefresh?: ({ refreshToken, token }: {
|
|
16
|
+
refreshToken: string;
|
|
17
|
+
token: string;
|
|
18
|
+
}) => void;
|
|
19
|
+
}): QelosAdministratorSDK;
|
|
10
20
|
export declare function getSdk(): QelosAdministratorSDK;
|
|
11
21
|
export declare function getSdkForTenant(tenantPayload: StandardPayload): Promise<QelosAdministratorSDK | null>;
|
|
12
22
|
export declare function getEncryptedDataForTenant(tenantPayload: StandardPayload, encryptedId?: string): Promise<any>;
|
package/dist/sdk.js
CHANGED
|
@@ -4,11 +4,17 @@ import config from './config';
|
|
|
4
4
|
import logger from './logger';
|
|
5
5
|
let localSdk;
|
|
6
6
|
export function authenticate() {
|
|
7
|
-
return localSdk.authentication.oAuthSignin({
|
|
7
|
+
return localSdk.authentication.oAuthSignin({
|
|
8
|
+
username: config.qelosUsername,
|
|
9
|
+
password: config.qelosPassword,
|
|
10
|
+
});
|
|
8
11
|
}
|
|
9
12
|
async function bootstrapAuthenticate() {
|
|
10
13
|
try {
|
|
11
|
-
await localSdk.authentication.oAuthSignin({
|
|
14
|
+
await localSdk.authentication.oAuthSignin({
|
|
15
|
+
username: config.qelosUsername,
|
|
16
|
+
password: config.qelosPassword,
|
|
17
|
+
});
|
|
12
18
|
console.log('authenticated successfully to ' + config.qelosUrl);
|
|
13
19
|
}
|
|
14
20
|
catch (err) {
|
|
@@ -17,17 +23,19 @@ async function bootstrapAuthenticate() {
|
|
|
17
23
|
process.exit(1);
|
|
18
24
|
}
|
|
19
25
|
}
|
|
20
|
-
export function getSdkForUrl(appUrl, refreshToken, accessToken, username, password) {
|
|
26
|
+
export function getSdkForUrl({ appUrl, refreshToken, accessToken, username, password, onRefresh }) {
|
|
21
27
|
let sdk;
|
|
22
28
|
const options = {
|
|
23
29
|
appUrl,
|
|
24
30
|
forceRefresh: true,
|
|
25
31
|
fetch: globalThis.fetch || undiciFetch,
|
|
26
|
-
...(config.sdkOptions || {}),
|
|
27
32
|
onFailedRefreshToken: async () => {
|
|
28
|
-
await sdk.authentication.oAuthSignin({ username, password });
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
const res = await sdk.authentication.oAuthSignin({ username, password });
|
|
34
|
+
if (onRefresh) {
|
|
35
|
+
onRefresh(res.payload);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
...(config.sdkOptions || {}),
|
|
31
39
|
};
|
|
32
40
|
if (refreshToken) {
|
|
33
41
|
options.refreshToken = refreshToken;
|
|
@@ -42,7 +50,13 @@ export function getSdk() {
|
|
|
42
50
|
if (localSdk) {
|
|
43
51
|
return localSdk;
|
|
44
52
|
}
|
|
45
|
-
localSdk = getSdkForUrl(
|
|
53
|
+
localSdk = getSdkForUrl({
|
|
54
|
+
appUrl: config.qelosUrl,
|
|
55
|
+
refreshToken: null,
|
|
56
|
+
accessToken: null,
|
|
57
|
+
username: config.qelosUsername,
|
|
58
|
+
password: config.qelosPassword,
|
|
59
|
+
});
|
|
46
60
|
bootstrapAuthenticate().catch();
|
|
47
61
|
return localSdk;
|
|
48
62
|
}
|
|
@@ -52,7 +66,17 @@ export async function getSdkForTenant(tenantPayload) {
|
|
|
52
66
|
if (!data.appUrl) {
|
|
53
67
|
return null;
|
|
54
68
|
}
|
|
55
|
-
const sdk = getSdkForUrl(
|
|
69
|
+
const sdk = getSdkForUrl({
|
|
70
|
+
appUrl: data.appUrl,
|
|
71
|
+
refreshToken: data.currentAuthPayload?.refreshToken,
|
|
72
|
+
accessToken: data.currentAuthPayload?.token,
|
|
73
|
+
username: data.username,
|
|
74
|
+
password: data.password,
|
|
75
|
+
onRefresh: (payload) => {
|
|
76
|
+
data.currentAuthPayload = payload;
|
|
77
|
+
setEncryptedDataForTenant(tenantPayload, config.userPayloadSecret, data);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
56
80
|
return sdk;
|
|
57
81
|
}
|
|
58
82
|
catch (e) {
|
package/dist/sdk.js.map
CHANGED
|
@@ -1 +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
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.1",
|
|
4
4
|
"description": "Play a plugin for Qelos!",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,15 +15,15 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@fastify/cookie": "^8.3.0",
|
|
17
17
|
"@fastify/static": "^6.12.0",
|
|
18
|
-
"@qelos/cache-manager": "^3.8.
|
|
19
|
-
"@qelos/sdk": "^3.8.
|
|
20
|
-
"@qelos/web-sdk": "^3.8.
|
|
21
|
-
"fastify": "~4.
|
|
18
|
+
"@qelos/cache-manager": "^3.8.1",
|
|
19
|
+
"@qelos/sdk": "^3.8.1",
|
|
20
|
+
"@qelos/web-sdk": "^3.8.1",
|
|
21
|
+
"fastify": "~4.15.0",
|
|
22
22
|
"jsonwebtoken": "^9.0.2",
|
|
23
23
|
"undici": "^6.20.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"typescript": "^4.9.5"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "870f8846e1cdcc13af9327c6e70844a33a9f9cba"
|
|
29
29
|
}
|
package/src/sdk.ts
CHANGED
|
@@ -8,13 +8,19 @@ import logger from './logger';
|
|
|
8
8
|
let localSdk: QelosAdministratorSDK<{ tokenIdentifier: string }>;
|
|
9
9
|
|
|
10
10
|
export function authenticate() {
|
|
11
|
-
return localSdk.authentication.oAuthSignin({
|
|
11
|
+
return localSdk.authentication.oAuthSignin({
|
|
12
|
+
username: config.qelosUsername,
|
|
13
|
+
password: config.qelosPassword,
|
|
14
|
+
});
|
|
12
15
|
}
|
|
13
16
|
|
|
14
17
|
async function bootstrapAuthenticate() {
|
|
15
18
|
try {
|
|
16
|
-
await localSdk.authentication.oAuthSignin({
|
|
17
|
-
|
|
19
|
+
await localSdk.authentication.oAuthSignin({
|
|
20
|
+
username: config.qelosUsername,
|
|
21
|
+
password: config.qelosPassword,
|
|
22
|
+
});
|
|
23
|
+
console.log('authenticated successfully to ' + config.qelosUrl);
|
|
18
24
|
} catch (err) {
|
|
19
25
|
console.log('could not authenticate to own qelos app');
|
|
20
26
|
logger.error('connect to qelos error: ', err);
|
|
@@ -22,17 +28,33 @@ async function bootstrapAuthenticate() {
|
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
30
|
|
|
25
|
-
export function getSdkForUrl<T = any>(
|
|
31
|
+
export function getSdkForUrl<T = any>({
|
|
32
|
+
appUrl,
|
|
33
|
+
refreshToken,
|
|
34
|
+
accessToken,
|
|
35
|
+
username,
|
|
36
|
+
password,
|
|
37
|
+
onRefresh
|
|
38
|
+
}: {
|
|
39
|
+
appUrl: string;
|
|
40
|
+
refreshToken?: string;
|
|
41
|
+
accessToken?: string;
|
|
42
|
+
username?: string;
|
|
43
|
+
password?: string;
|
|
44
|
+
onRefresh?: ({ refreshToken, token }: { refreshToken: string, token: string }) => void
|
|
45
|
+
}): QelosAdministratorSDK {
|
|
26
46
|
let sdk: QelosAdministratorSDK;
|
|
27
47
|
const options: QelosSDKOptions = {
|
|
28
48
|
appUrl,
|
|
29
49
|
forceRefresh: true,
|
|
30
|
-
fetch: globalThis.fetch || undiciFetch as any as FetchLike,
|
|
31
|
-
...(config.sdkOptions || {}),
|
|
50
|
+
fetch: globalThis.fetch || (undiciFetch as any as FetchLike),
|
|
32
51
|
onFailedRefreshToken: async () => {
|
|
33
|
-
await sdk.authentication.oAuthSignin({ username, password });
|
|
34
|
-
|
|
35
|
-
|
|
52
|
+
const res = await sdk.authentication.oAuthSignin({ username, password });
|
|
53
|
+
if (onRefresh) {
|
|
54
|
+
onRefresh(res.payload)
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
...(config.sdkOptions || {}),
|
|
36
58
|
};
|
|
37
59
|
if (refreshToken) {
|
|
38
60
|
options.refreshToken = refreshToken;
|
|
@@ -48,29 +70,57 @@ export function getSdk(): QelosAdministratorSDK {
|
|
|
48
70
|
if (localSdk) {
|
|
49
71
|
return localSdk;
|
|
50
72
|
}
|
|
51
|
-
localSdk = getSdkForUrl<{ tokenIdentifier: string }>(
|
|
73
|
+
localSdk = getSdkForUrl<{ tokenIdentifier: string }>({
|
|
74
|
+
appUrl: config.qelosUrl,
|
|
75
|
+
refreshToken: null,
|
|
76
|
+
accessToken: null,
|
|
77
|
+
username: config.qelosUsername,
|
|
78
|
+
password: config.qelosPassword,
|
|
79
|
+
});
|
|
52
80
|
bootstrapAuthenticate().catch();
|
|
53
81
|
return localSdk;
|
|
54
82
|
}
|
|
55
83
|
|
|
56
|
-
export async function getSdkForTenant(
|
|
84
|
+
export async function getSdkForTenant(
|
|
85
|
+
tenantPayload: StandardPayload
|
|
86
|
+
): Promise<QelosAdministratorSDK | null> {
|
|
57
87
|
try {
|
|
58
|
-
const data = await getEncryptedDataForTenant(
|
|
88
|
+
const data = await getEncryptedDataForTenant(
|
|
89
|
+
tenantPayload,
|
|
90
|
+
config.userPayloadSecret
|
|
91
|
+
);
|
|
59
92
|
if (!data.appUrl) {
|
|
60
93
|
return null;
|
|
61
94
|
}
|
|
62
|
-
const sdk = getSdkForUrl(
|
|
95
|
+
const sdk = getSdkForUrl({
|
|
96
|
+
appUrl: data.appUrl,
|
|
97
|
+
refreshToken: data.currentAuthPayload?.refreshToken,
|
|
98
|
+
accessToken: data.currentAuthPayload?.token,
|
|
99
|
+
username: data.username,
|
|
100
|
+
password: data.password,
|
|
101
|
+
onRefresh: (payload) => {
|
|
102
|
+
data.currentAuthPayload = payload;
|
|
103
|
+
setEncryptedDataForTenant(tenantPayload, config.userPayloadSecret, data);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
63
106
|
return sdk;
|
|
64
107
|
} catch (e) {
|
|
65
|
-
logger.log(e)
|
|
108
|
+
logger.log(e);
|
|
66
109
|
return null;
|
|
67
110
|
}
|
|
68
111
|
}
|
|
69
112
|
|
|
70
|
-
export function getEncryptedDataForTenant(
|
|
113
|
+
export function getEncryptedDataForTenant(
|
|
114
|
+
tenantPayload: StandardPayload,
|
|
115
|
+
encryptedId: string = ''
|
|
116
|
+
) {
|
|
71
117
|
return getSdk().users.getEncryptedData(tenantPayload.sub, encryptedId);
|
|
72
118
|
}
|
|
73
119
|
|
|
74
|
-
export function setEncryptedDataForTenant(
|
|
120
|
+
export function setEncryptedDataForTenant(
|
|
121
|
+
tenantPayload: StandardPayload,
|
|
122
|
+
encryptedId: string = '',
|
|
123
|
+
data: any
|
|
124
|
+
) {
|
|
75
125
|
return getSdk().users.setEncryptedData(tenantPayload.sub, encryptedId, data);
|
|
76
126
|
}
|