@etsoo/materialui 1.4.52 → 1.4.54
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/lib/app/ServiceApp.d.ts +13 -4
- package/lib/app/ServiceApp.js +42 -8
- package/package.json +10 -10
- package/src/app/ServiceApp.ts +65 -10
package/lib/app/ServiceApp.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { ApiRefreshTokenDto, AppLoginParams, AppTryLoginParams, ExternalEndpoint, IApi } from "@etsoo/appscript";
|
|
1
|
+
import { ApiRefreshTokenDto, AppLoginParams, AppTryLoginParams, ExternalEndpoint, IApi, IApiPayload } from "@etsoo/appscript";
|
|
2
2
|
import { IServiceApp } from "./IServiceApp";
|
|
3
3
|
import { IServiceAppSettings } from "./IServiceAppSettings";
|
|
4
4
|
import { IServicePageData } from "./IServicePage";
|
|
5
5
|
import { IServiceUser, ServiceUserToken } from "./IServiceUser";
|
|
6
6
|
import { ReactApp } from "./ReactApp";
|
|
7
|
+
import { IActionResult } from "@etsoo/shared";
|
|
7
8
|
/**
|
|
8
9
|
* Core Service App
|
|
9
10
|
* Service login to core system, get the refesh token and access token
|
|
@@ -23,6 +24,7 @@ export declare class ServiceApp<U extends IServiceUser = IServiceUser, P extends
|
|
|
23
24
|
* Core system origin
|
|
24
25
|
*/
|
|
25
26
|
readonly coreOrigin: string;
|
|
27
|
+
private coreAccessToken;
|
|
26
28
|
/**
|
|
27
29
|
* Constructor
|
|
28
30
|
* @param settings Settings
|
|
@@ -61,10 +63,17 @@ export declare class ServiceApp<U extends IServiceUser = IServiceUser, P extends
|
|
|
61
63
|
*/
|
|
62
64
|
userLoginEx(user: U & ServiceUserToken, core?: ApiRefreshTokenDto, dispatch?: boolean): void;
|
|
63
65
|
/**
|
|
64
|
-
* Save core system
|
|
65
|
-
* @param
|
|
66
|
+
* Save core system data
|
|
67
|
+
* @param data Data
|
|
66
68
|
*/
|
|
67
|
-
protected saveCoreToken(
|
|
69
|
+
protected saveCoreToken(data: ApiRefreshTokenDto): void;
|
|
70
|
+
/**
|
|
71
|
+
* Switch organization
|
|
72
|
+
* @param organizationId Organization ID
|
|
73
|
+
* @param fromOrganizationId From organization ID
|
|
74
|
+
* @param payload Payload
|
|
75
|
+
*/
|
|
76
|
+
switchOrg(organizationId: number, fromOrganizationId?: number, payload?: IApiPayload<IActionResult<U & ServiceUserToken>>): Promise<IActionResult<U & ServiceUserToken> | undefined>;
|
|
68
77
|
/**
|
|
69
78
|
* Try login
|
|
70
79
|
* @param params Login parameters
|
package/lib/app/ServiceApp.js
CHANGED
|
@@ -22,6 +22,7 @@ export class ServiceApp extends ReactApp {
|
|
|
22
22
|
* Core system origin
|
|
23
23
|
*/
|
|
24
24
|
coreOrigin;
|
|
25
|
+
coreAccessToken;
|
|
25
26
|
/**
|
|
26
27
|
* Constructor
|
|
27
28
|
* @param settings Settings
|
|
@@ -141,16 +142,50 @@ export class ServiceApp extends ReactApp {
|
|
|
141
142
|
tokenType: user.tokenScheme ?? "Bearer",
|
|
142
143
|
expiresIn: user.seconds
|
|
143
144
|
};
|
|
145
|
+
// Cache the core system data
|
|
146
|
+
this.saveCoreToken(core);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Save core system data
|
|
150
|
+
* @param data Data
|
|
151
|
+
*/
|
|
152
|
+
saveCoreToken(data) {
|
|
153
|
+
// Hold the core system access token
|
|
154
|
+
this.coreAccessToken = data.accessToken;
|
|
144
155
|
// Cache the core system refresh token
|
|
145
|
-
this.
|
|
146
|
-
|
|
156
|
+
this.storage.setData(coreTokenKey, this.encrypt(data.refreshToken));
|
|
157
|
+
// Exchange tokens
|
|
158
|
+
this.exchangeTokenAll(data, coreName);
|
|
147
159
|
}
|
|
148
160
|
/**
|
|
149
|
-
*
|
|
150
|
-
* @param
|
|
161
|
+
* Switch organization
|
|
162
|
+
* @param organizationId Organization ID
|
|
163
|
+
* @param fromOrganizationId From organization ID
|
|
164
|
+
* @param payload Payload
|
|
151
165
|
*/
|
|
152
|
-
|
|
153
|
-
|
|
166
|
+
async switchOrg(organizationId, fromOrganizationId, payload) {
|
|
167
|
+
if (!this.coreAccessToken) {
|
|
168
|
+
throw new Error("Core access token is required to switch organization.");
|
|
169
|
+
}
|
|
170
|
+
const [result, refreshToken] = await new AuthApi(this, this.coreApi).switchOrg({ organizationId, fromOrganizationId, token: this.coreAccessToken }, payload);
|
|
171
|
+
if (result == null)
|
|
172
|
+
return;
|
|
173
|
+
if (!result.ok) {
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
if (result.data == null) {
|
|
177
|
+
throw new Error("Invalid switch organization result.");
|
|
178
|
+
}
|
|
179
|
+
let core;
|
|
180
|
+
if ("core" in result.data && typeof result.data.core === "string") {
|
|
181
|
+
core = JSON.parse(result.data.core);
|
|
182
|
+
delete result.data.core;
|
|
183
|
+
}
|
|
184
|
+
// Override the user data's refresh token
|
|
185
|
+
const user = refreshToken ? { ...result.data, refreshToken } : result.data;
|
|
186
|
+
// User login
|
|
187
|
+
this.userLoginEx(user, core, true);
|
|
188
|
+
return result;
|
|
154
189
|
}
|
|
155
190
|
/**
|
|
156
191
|
* Try login
|
|
@@ -185,8 +220,7 @@ export class ServiceApp extends ReactApp {
|
|
|
185
220
|
if (data == null)
|
|
186
221
|
return;
|
|
187
222
|
// Cache the core system refresh token
|
|
188
|
-
this.saveCoreToken(data
|
|
189
|
-
this.exchangeTokenAll(data, coreName);
|
|
223
|
+
this.saveCoreToken(data);
|
|
190
224
|
onSuccess?.();
|
|
191
225
|
});
|
|
192
226
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/materialui",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.54",
|
|
4
4
|
"description": "TypeScript Material-UI Implementation",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
"@emotion/css": "^11.13.5",
|
|
36
36
|
"@emotion/react": "^11.14.0",
|
|
37
37
|
"@emotion/styled": "^11.14.0",
|
|
38
|
-
"@etsoo/appscript": "^1.5.
|
|
38
|
+
"@etsoo/appscript": "^1.5.82",
|
|
39
39
|
"@etsoo/notificationbase": "^1.1.54",
|
|
40
|
-
"@etsoo/react": "^1.8.
|
|
40
|
+
"@etsoo/react": "^1.8.15",
|
|
41
41
|
"@etsoo/shared": "^1.2.55",
|
|
42
|
-
"@mui/icons-material": "^6.
|
|
43
|
-
"@mui/material": "^6.
|
|
44
|
-
"@mui/x-data-grid": "^7.23.
|
|
42
|
+
"@mui/icons-material": "^6.3.0",
|
|
43
|
+
"@mui/material": "^6.3.0",
|
|
44
|
+
"@mui/x-data-grid": "^7.23.5",
|
|
45
45
|
"chart.js": "^4.4.7",
|
|
46
46
|
"chartjs-plugin-datalabels": "^2.2.0",
|
|
47
47
|
"eventemitter3": "^5.0.1",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"pulltorefreshjs": "^0.1.22",
|
|
50
50
|
"react": "^18.3.1",
|
|
51
51
|
"react-avatar-editor": "^13.0.2",
|
|
52
|
-
"react-chartjs-2": "^5.
|
|
52
|
+
"react-chartjs-2": "^5.3.0",
|
|
53
53
|
"react-dom": "^18.3.1",
|
|
54
54
|
"react-draggable": "^4.4.6",
|
|
55
55
|
"react-imask": "7.6.1"
|
|
@@ -63,11 +63,11 @@
|
|
|
63
63
|
"@babel/preset-typescript": "^7.26.0",
|
|
64
64
|
"@babel/runtime-corejs3": "^7.26.0",
|
|
65
65
|
"@testing-library/react": "^16.1.0",
|
|
66
|
-
"@types/pica": "^9.0.
|
|
66
|
+
"@types/pica": "^9.0.5",
|
|
67
67
|
"@types/pulltorefreshjs": "^0.1.7",
|
|
68
|
-
"@types/react": "^18.3.
|
|
68
|
+
"@types/react": "^18.3.18",
|
|
69
69
|
"@types/react-avatar-editor": "^13.0.3",
|
|
70
|
-
"@types/react-dom": "^18.3.
|
|
70
|
+
"@types/react-dom": "^18.3.5",
|
|
71
71
|
"@types/react-input-mask": "^3.0.6",
|
|
72
72
|
"@types/react-window": "^1.8.8",
|
|
73
73
|
"@vitejs/plugin-react": "^4.3.4",
|
package/src/app/ServiceApp.ts
CHANGED
|
@@ -5,13 +5,15 @@ import {
|
|
|
5
5
|
AuthApi,
|
|
6
6
|
BridgeUtils,
|
|
7
7
|
ExternalEndpoint,
|
|
8
|
-
IApi
|
|
8
|
+
IApi,
|
|
9
|
+
IApiPayload
|
|
9
10
|
} from "@etsoo/appscript";
|
|
10
11
|
import { IServiceApp } from "./IServiceApp";
|
|
11
12
|
import { IServiceAppSettings } from "./IServiceAppSettings";
|
|
12
13
|
import { IServicePageData } from "./IServicePage";
|
|
13
14
|
import { IServiceUser, ServiceUserToken } from "./IServiceUser";
|
|
14
15
|
import { ReactApp } from "./ReactApp";
|
|
16
|
+
import { IActionResult } from "@etsoo/shared";
|
|
15
17
|
|
|
16
18
|
const coreName = "core";
|
|
17
19
|
const coreTokenKey = "core-refresh-token";
|
|
@@ -46,6 +48,8 @@ export class ServiceApp<
|
|
|
46
48
|
*/
|
|
47
49
|
readonly coreOrigin: string;
|
|
48
50
|
|
|
51
|
+
private coreAccessToken: string | undefined;
|
|
52
|
+
|
|
49
53
|
/**
|
|
50
54
|
* Constructor
|
|
51
55
|
* @param settings Settings
|
|
@@ -182,18 +186,71 @@ export class ServiceApp<
|
|
|
182
186
|
expiresIn: user.seconds
|
|
183
187
|
};
|
|
184
188
|
|
|
189
|
+
// Cache the core system data
|
|
190
|
+
this.saveCoreToken(core);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Save core system data
|
|
195
|
+
* @param data Data
|
|
196
|
+
*/
|
|
197
|
+
protected saveCoreToken(data: ApiRefreshTokenDto) {
|
|
198
|
+
// Hold the core system access token
|
|
199
|
+
this.coreAccessToken = data.accessToken;
|
|
200
|
+
|
|
185
201
|
// Cache the core system refresh token
|
|
186
|
-
this.
|
|
202
|
+
this.storage.setData(coreTokenKey, this.encrypt(data.refreshToken));
|
|
187
203
|
|
|
188
|
-
|
|
204
|
+
// Exchange tokens
|
|
205
|
+
this.exchangeTokenAll(data, coreName);
|
|
189
206
|
}
|
|
190
207
|
|
|
191
208
|
/**
|
|
192
|
-
*
|
|
193
|
-
* @param
|
|
209
|
+
* Switch organization
|
|
210
|
+
* @param organizationId Organization ID
|
|
211
|
+
* @param fromOrganizationId From organization ID
|
|
212
|
+
* @param payload Payload
|
|
194
213
|
*/
|
|
195
|
-
|
|
196
|
-
|
|
214
|
+
async switchOrg(
|
|
215
|
+
organizationId: number,
|
|
216
|
+
fromOrganizationId?: number,
|
|
217
|
+
payload?: IApiPayload<IActionResult<U & ServiceUserToken>>
|
|
218
|
+
) {
|
|
219
|
+
if (!this.coreAccessToken) {
|
|
220
|
+
throw new Error("Core access token is required to switch organization.");
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const [result, refreshToken] = await new AuthApi(
|
|
224
|
+
this,
|
|
225
|
+
this.coreApi
|
|
226
|
+
).switchOrg(
|
|
227
|
+
{ organizationId, fromOrganizationId, token: this.coreAccessToken },
|
|
228
|
+
payload
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
if (result == null) return;
|
|
232
|
+
|
|
233
|
+
if (!result.ok) {
|
|
234
|
+
return result;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (result.data == null) {
|
|
238
|
+
throw new Error("Invalid switch organization result.");
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
let core: ApiRefreshTokenDto | undefined;
|
|
242
|
+
if ("core" in result.data && typeof result.data.core === "string") {
|
|
243
|
+
core = JSON.parse(result.data.core);
|
|
244
|
+
delete result.data.core;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Override the user data's refresh token
|
|
248
|
+
const user = refreshToken ? { ...result.data, refreshToken } : result.data;
|
|
249
|
+
|
|
250
|
+
// User login
|
|
251
|
+
this.userLoginEx(user, core, true);
|
|
252
|
+
|
|
253
|
+
return result;
|
|
197
254
|
}
|
|
198
255
|
|
|
199
256
|
/**
|
|
@@ -233,9 +290,7 @@ export class ServiceApp<
|
|
|
233
290
|
if (data == null) return;
|
|
234
291
|
|
|
235
292
|
// Cache the core system refresh token
|
|
236
|
-
this.saveCoreToken(data
|
|
237
|
-
|
|
238
|
-
this.exchangeTokenAll(data, coreName);
|
|
293
|
+
this.saveCoreToken(data);
|
|
239
294
|
|
|
240
295
|
onSuccess?.();
|
|
241
296
|
});
|