@etsoo/react 1.3.62 → 1.3.66
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.js +15 -17
- 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 +15 -18
- package/src/app/RefreshTokenRQ.ts +5 -0
- package/src/app/ServiceApp.ts +26 -5
package/lib/app/ReactApp.js
CHANGED
|
@@ -24,26 +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
|
-
console.log('ReactAppStateDetector', state, authorized, matchedFields);
|
|
42
27
|
// Ready
|
|
43
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
|
+
}
|
|
44
42
|
// Callback
|
|
45
|
-
update(authorized, matchedFields);
|
|
46
|
-
}, [
|
|
43
|
+
update(state.authorized, matchedFields);
|
|
44
|
+
}, [state]);
|
|
47
45
|
// return
|
|
48
46
|
return React.createElement(React.Fragment);
|
|
49
47
|
}
|
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.66",
|
|
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,27 +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
|
-
console.log('ReactAppStateDetector', state, authorized, matchedFields);
|
|
71
|
-
|
|
72
56
|
// Ready
|
|
73
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
|
+
|
|
74
71
|
// Callback
|
|
75
|
-
update(authorized, matchedFields);
|
|
76
|
-
}, [
|
|
72
|
+
update(state.authorized, matchedFields);
|
|
73
|
+
}, [state]);
|
|
77
74
|
|
|
78
75
|
// return
|
|
79
76
|
return React.createElement(React.Fragment);
|
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();
|