@etsoo/react 1.3.63 → 1.3.67
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/ReactApp.d.ts +2 -1
- package/lib/app/ReactApp.js +18 -18
- package/lib/app/RefreshTokenRQ.d.ts +4 -0
- package/lib/app/ServiceApp.d.ts +7 -1
- package/lib/app/ServiceApp.js +23 -2
- package/package.json +2 -2
- package/src/app/ReactApp.ts +19 -18
- package/src/app/RefreshTokenRQ.ts +5 -0
- package/src/app/ServiceApp.ts +26 -5
package/lib/app/ReactApp.d.ts
CHANGED
|
@@ -144,8 +144,9 @@ export declare class ReactApp<S extends IAppSettings, D extends IUser, P extends
|
|
|
144
144
|
* @param user New user
|
|
145
145
|
* @param refreshToken Refresh token
|
|
146
146
|
* @param keep Keep in local storage or not
|
|
147
|
+
* @param dispatch User state dispatch
|
|
147
148
|
*/
|
|
148
|
-
userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
|
|
149
|
+
userLogin(user: IUserData, refreshToken: string, keep?: boolean, dispatch?: boolean): void;
|
|
149
150
|
/**
|
|
150
151
|
* User logout
|
|
151
152
|
* @param clearToken Clear refresh token or not
|
package/lib/app/ReactApp.js
CHANGED
|
@@ -24,25 +24,24 @@ export function ReactAppStateDetector(props) {
|
|
|
24
24
|
const { state } = globalApp == null
|
|
25
25
|
? { state: {} }
|
|
26
26
|
: React.useContext(globalApp.userState.context);
|
|
27
|
-
// Match fields
|
|
28
|
-
const authorized = state.authorized;
|
|
29
|
-
const changedFields = state.lastChangedFields;
|
|
30
|
-
let matchedFields;
|
|
31
|
-
if (targetFields == null || changedFields == null) {
|
|
32
|
-
matchedFields = changedFields;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
matchedFields = [];
|
|
36
|
-
targetFields.forEach((targetField) => {
|
|
37
|
-
if (changedFields.includes(targetField))
|
|
38
|
-
matchedFields === null || matchedFields === void 0 ? void 0 : matchedFields.push(targetField);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
27
|
// Ready
|
|
42
28
|
React.useEffect(() => {
|
|
29
|
+
// Match fields
|
|
30
|
+
const changedFields = state.lastChangedFields;
|
|
31
|
+
let matchedFields;
|
|
32
|
+
if (targetFields == null || changedFields == null) {
|
|
33
|
+
matchedFields = changedFields;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
matchedFields = [];
|
|
37
|
+
targetFields.forEach((targetField) => {
|
|
38
|
+
if (changedFields.includes(targetField))
|
|
39
|
+
matchedFields === null || matchedFields === void 0 ? void 0 : matchedFields.push(targetField);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
43
42
|
// Callback
|
|
44
|
-
update(authorized, matchedFields);
|
|
45
|
-
}, [
|
|
43
|
+
update(state.authorized, matchedFields);
|
|
44
|
+
}, [state]);
|
|
46
45
|
// return
|
|
47
46
|
return React.createElement(React.Fragment);
|
|
48
47
|
}
|
|
@@ -211,12 +210,13 @@ export class ReactApp extends CoreApp {
|
|
|
211
210
|
* @param user New user
|
|
212
211
|
* @param refreshToken Refresh token
|
|
213
212
|
* @param keep Keep in local storage or not
|
|
213
|
+
* @param dispatch User state dispatch
|
|
214
214
|
*/
|
|
215
|
-
userLogin(user, refreshToken, keep) {
|
|
215
|
+
userLogin(user, refreshToken, keep, dispatch) {
|
|
216
216
|
// Super call, set token
|
|
217
217
|
super.userLogin(user, refreshToken, keep);
|
|
218
218
|
// Dispatch action
|
|
219
|
-
if (this.userStateDispatch != null)
|
|
219
|
+
if (this.userStateDispatch != null && dispatch !== false)
|
|
220
220
|
this.userStateDispatch({
|
|
221
221
|
type: UserActionType.Login,
|
|
222
222
|
user
|
package/lib/app/ServiceApp.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IApi, RefreshTokenProps } from '@etsoo/appscript';
|
|
1
|
+
import { IApi, InitCallDto, InitCallResult, RefreshTokenProps } from '@etsoo/appscript';
|
|
2
2
|
import { IServiceAppSettings } from './IServiceAppSettings';
|
|
3
3
|
import { IServicePageData } from './IServicePage';
|
|
4
4
|
import { IServiceUser } from './IServiceUser';
|
|
@@ -26,6 +26,12 @@ export declare class ServiceApp<P extends IServicePageData = IServicePageData, U
|
|
|
26
26
|
* @param name Application name
|
|
27
27
|
*/
|
|
28
28
|
constructor(settings: S, name: string);
|
|
29
|
+
/**
|
|
30
|
+
* Api init call, connect to the core Api
|
|
31
|
+
* @param data Data
|
|
32
|
+
* @returns Result
|
|
33
|
+
*/
|
|
34
|
+
protected apiInitCall(data: InitCallDto): Promise<InitCallResult | undefined>;
|
|
29
35
|
/**
|
|
30
36
|
* Go to the login page
|
|
31
37
|
*/
|
package/lib/app/ServiceApp.js
CHANGED
|
@@ -26,6 +26,14 @@ export class ServiceApp extends ReactApp {
|
|
|
26
26
|
this.setApi(api);
|
|
27
27
|
this.coreApi = api;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Api init call, connect to the core Api
|
|
31
|
+
* @param data Data
|
|
32
|
+
* @returns Result
|
|
33
|
+
*/
|
|
34
|
+
async apiInitCall(data) {
|
|
35
|
+
return await this.coreApi.put(this.initCallApi, data);
|
|
36
|
+
}
|
|
29
37
|
/**
|
|
30
38
|
* Go to the login page
|
|
31
39
|
*/
|
|
@@ -57,6 +65,7 @@ export class ServiceApp extends ReactApp {
|
|
|
57
65
|
// Reqest data
|
|
58
66
|
// Merge additional data passed
|
|
59
67
|
const rq = {
|
|
68
|
+
deviceId: this.deviceId,
|
|
60
69
|
timezone: this.getTimeZone(),
|
|
61
70
|
...data
|
|
62
71
|
};
|
|
@@ -106,7 +115,11 @@ export class ServiceApp extends ReactApp {
|
|
|
106
115
|
failCallback(this.get('noData'));
|
|
107
116
|
return false;
|
|
108
117
|
}
|
|
118
|
+
// Login
|
|
109
119
|
this.userLoginEx(serviceResult.data, refreshToken, userData);
|
|
120
|
+
// Success callback
|
|
121
|
+
if (failCallback)
|
|
122
|
+
failCallback(true);
|
|
110
123
|
return true;
|
|
111
124
|
};
|
|
112
125
|
// Call API
|
|
@@ -124,13 +137,18 @@ export class ServiceApp extends ReactApp {
|
|
|
124
137
|
return;
|
|
125
138
|
}
|
|
126
139
|
// Set password for the action
|
|
127
|
-
rq.pwd = this.encrypt(
|
|
140
|
+
rq.pwd = this.encrypt(this.hash(pwd));
|
|
128
141
|
// Submit again
|
|
129
|
-
const result = await this.api.put('Auth/RefreshToken',
|
|
142
|
+
const result = await this.api.put('Auth/RefreshToken', rq, payload);
|
|
130
143
|
if (result == null)
|
|
131
144
|
return;
|
|
132
145
|
if (result.ok) {
|
|
133
146
|
await success(result, (loginResult) => {
|
|
147
|
+
if (loginResult === true) {
|
|
148
|
+
if (callback)
|
|
149
|
+
callback(true);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
134
152
|
const message = this.formatRefreshTokenResult(loginResult);
|
|
135
153
|
if (message)
|
|
136
154
|
this.notifier.alert(message);
|
|
@@ -165,6 +183,9 @@ export class ServiceApp extends ReactApp {
|
|
|
165
183
|
// Refresh token
|
|
166
184
|
return await this.refreshToken({
|
|
167
185
|
callback: (result) => {
|
|
186
|
+
// Success
|
|
187
|
+
if (result === true)
|
|
188
|
+
return;
|
|
168
189
|
const message = this.formatRefreshTokenResult(result);
|
|
169
190
|
if (message == null) {
|
|
170
191
|
this.loginFailed();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/react",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.67",
|
|
4
4
|
"description": "TypeScript ReactJs framework",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@emotion/react": "^11.7.1",
|
|
51
51
|
"@emotion/style": "^0.8.0",
|
|
52
52
|
"@emotion/styled": "^11.6.0",
|
|
53
|
-
"@etsoo/appscript": "^1.1.
|
|
53
|
+
"@etsoo/appscript": "^1.1.83",
|
|
54
54
|
"@etsoo/notificationbase": "^1.0.94",
|
|
55
55
|
"@etsoo/shared": "^1.0.78",
|
|
56
56
|
"@mui/icons-material": "^5.2.4",
|
package/src/app/ReactApp.ts
CHANGED
|
@@ -53,25 +53,24 @@ export function ReactAppStateDetector(props: IStateProps) {
|
|
|
53
53
|
(globalApp.userState as UserState<IUser>).context
|
|
54
54
|
);
|
|
55
55
|
|
|
56
|
-
// Match fields
|
|
57
|
-
const authorized = state.authorized;
|
|
58
|
-
const changedFields = state.lastChangedFields;
|
|
59
|
-
let matchedFields: string[] | undefined;
|
|
60
|
-
if (targetFields == null || changedFields == null) {
|
|
61
|
-
matchedFields = changedFields;
|
|
62
|
-
} else {
|
|
63
|
-
matchedFields = [];
|
|
64
|
-
targetFields.forEach((targetField) => {
|
|
65
|
-
if (changedFields.includes(targetField))
|
|
66
|
-
matchedFields?.push(targetField);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
56
|
// Ready
|
|
71
57
|
React.useEffect(() => {
|
|
58
|
+
// Match fields
|
|
59
|
+
const changedFields = state.lastChangedFields;
|
|
60
|
+
let matchedFields: string[] | undefined;
|
|
61
|
+
if (targetFields == null || changedFields == null) {
|
|
62
|
+
matchedFields = changedFields;
|
|
63
|
+
} else {
|
|
64
|
+
matchedFields = [];
|
|
65
|
+
targetFields.forEach((targetField) => {
|
|
66
|
+
if (changedFields.includes(targetField))
|
|
67
|
+
matchedFields?.push(targetField);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
72
71
|
// Callback
|
|
73
|
-
update(authorized, matchedFields);
|
|
74
|
-
}, [
|
|
72
|
+
update(state.authorized, matchedFields);
|
|
73
|
+
}, [state]);
|
|
75
74
|
|
|
76
75
|
// return
|
|
77
76
|
return React.createElement(React.Fragment);
|
|
@@ -354,17 +353,19 @@ export class ReactApp<
|
|
|
354
353
|
* @param user New user
|
|
355
354
|
* @param refreshToken Refresh token
|
|
356
355
|
* @param keep Keep in local storage or not
|
|
356
|
+
* @param dispatch User state dispatch
|
|
357
357
|
*/
|
|
358
358
|
override userLogin(
|
|
359
359
|
user: IUserData,
|
|
360
360
|
refreshToken: string,
|
|
361
|
-
keep?: boolean
|
|
361
|
+
keep?: boolean,
|
|
362
|
+
dispatch?: boolean
|
|
362
363
|
): void {
|
|
363
364
|
// Super call, set token
|
|
364
365
|
super.userLogin(user, refreshToken, keep);
|
|
365
366
|
|
|
366
367
|
// Dispatch action
|
|
367
|
-
if (this.userStateDispatch != null)
|
|
368
|
+
if (this.userStateDispatch != null && dispatch !== false)
|
|
368
369
|
this.userStateDispatch({
|
|
369
370
|
type: UserActionType.Login,
|
|
370
371
|
user
|
package/src/app/ServiceApp.ts
CHANGED
|
@@ -2,6 +2,8 @@ import {
|
|
|
2
2
|
createClient,
|
|
3
3
|
IApi,
|
|
4
4
|
IApiPayload,
|
|
5
|
+
InitCallDto,
|
|
6
|
+
InitCallResult,
|
|
5
7
|
RefreshTokenProps,
|
|
6
8
|
RefreshTokenResult
|
|
7
9
|
} from '@etsoo/appscript';
|
|
@@ -56,6 +58,15 @@ export class ServiceApp<
|
|
|
56
58
|
this.coreApi = api;
|
|
57
59
|
}
|
|
58
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Api init call, connect to the core Api
|
|
63
|
+
* @param data Data
|
|
64
|
+
* @returns Result
|
|
65
|
+
*/
|
|
66
|
+
protected override async apiInitCall(data: InitCallDto) {
|
|
67
|
+
return await this.coreApi.put<InitCallResult>(this.initCallApi, data);
|
|
68
|
+
}
|
|
69
|
+
|
|
59
70
|
/**
|
|
60
71
|
* Go to the login page
|
|
61
72
|
*/
|
|
@@ -96,6 +107,7 @@ export class ServiceApp<
|
|
|
96
107
|
// Reqest data
|
|
97
108
|
// Merge additional data passed
|
|
98
109
|
const rq: RefreshTokenRQ = {
|
|
110
|
+
deviceId: this.deviceId,
|
|
99
111
|
timezone: this.getTimeZone(),
|
|
100
112
|
...data
|
|
101
113
|
};
|
|
@@ -156,8 +168,12 @@ export class ServiceApp<
|
|
|
156
168
|
return false;
|
|
157
169
|
}
|
|
158
170
|
|
|
171
|
+
// Login
|
|
159
172
|
this.userLoginEx(serviceResult.data, refreshToken, userData);
|
|
160
173
|
|
|
174
|
+
// Success callback
|
|
175
|
+
if (failCallback) failCallback(true);
|
|
176
|
+
|
|
161
177
|
return true;
|
|
162
178
|
};
|
|
163
179
|
|
|
@@ -183,15 +199,12 @@ export class ServiceApp<
|
|
|
183
199
|
}
|
|
184
200
|
|
|
185
201
|
// Set password for the action
|
|
186
|
-
rq.pwd = this.encrypt(
|
|
187
|
-
pwd,
|
|
188
|
-
this.settings.serviceId.toString()
|
|
189
|
-
);
|
|
202
|
+
rq.pwd = this.encrypt(this.hash(pwd));
|
|
190
203
|
|
|
191
204
|
// Submit again
|
|
192
205
|
const result = await this.api.put<SmartERPLoginResult>(
|
|
193
206
|
'Auth/RefreshToken',
|
|
194
|
-
|
|
207
|
+
rq,
|
|
195
208
|
payload
|
|
196
209
|
);
|
|
197
210
|
|
|
@@ -201,6 +214,11 @@ export class ServiceApp<
|
|
|
201
214
|
await success(
|
|
202
215
|
result,
|
|
203
216
|
(loginResult: RefreshTokenResult) => {
|
|
217
|
+
if (loginResult === true) {
|
|
218
|
+
if (callback) callback(true);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
204
222
|
const message =
|
|
205
223
|
this.formatRefreshTokenResult(
|
|
206
224
|
loginResult
|
|
@@ -246,6 +264,9 @@ export class ServiceApp<
|
|
|
246
264
|
// Refresh token
|
|
247
265
|
return await this.refreshToken({
|
|
248
266
|
callback: (result) => {
|
|
267
|
+
// Success
|
|
268
|
+
if (result === true) return;
|
|
269
|
+
|
|
249
270
|
const message = this.formatRefreshTokenResult(result);
|
|
250
271
|
if (message == null) {
|
|
251
272
|
this.loginFailed();
|