@etsoo/react 1.3.65 → 1.3.69

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.
@@ -3,6 +3,10 @@ import { IActionResult, IUser } from '@etsoo/appscript';
3
3
  * Service user interface
4
4
  */
5
5
  export interface IServiceUser extends IUser {
6
+ /**
7
+ * Service device id
8
+ */
9
+ serviceDeviceId: string;
6
10
  }
7
11
  /**
8
12
  * Service user login result
@@ -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
@@ -210,12 +210,13 @@ export class ReactApp extends CoreApp {
210
210
  * @param user New user
211
211
  * @param refreshToken Refresh token
212
212
  * @param keep Keep in local storage or not
213
+ * @param dispatch User state dispatch
213
214
  */
214
- userLogin(user, refreshToken, keep) {
215
+ userLogin(user, refreshToken, keep, dispatch) {
215
216
  // Super call, set token
216
217
  super.userLogin(user, refreshToken, keep);
217
218
  // Dispatch action
218
- if (this.userStateDispatch != null)
219
+ if (this.userStateDispatch != null && dispatch !== false)
219
220
  this.userStateDispatch({
220
221
  type: UserActionType.Login,
221
222
  user
@@ -20,6 +20,10 @@ export declare class ServiceApp<P extends IServicePageData = IServicePageData, U
20
20
  * Core system user
21
21
  */
22
22
  coreUser?: ISmartERPUser;
23
+ /**
24
+ * Service passphrase
25
+ */
26
+ servicePassphrase: string;
23
27
  /**
24
28
  * Constructor
25
29
  * @param settings Settings
@@ -42,6 +46,21 @@ export declare class ServiceApp<P extends IServicePageData = IServicePageData, U
42
46
  */
43
47
  refreshToken<D = RefreshTokenRQ>(props?: RefreshTokenProps<D>): Promise<boolean>;
44
48
  private loginFailed;
49
+ /**
50
+ * Service decrypt message
51
+ * @param messageEncrypted Encrypted message
52
+ * @param passphrase Secret passphrase
53
+ * @returns Pure text
54
+ */
55
+ serviceDecrypt(messageEncrypted: string, passphrase?: string): string | undefined;
56
+ /**
57
+ * Service encrypt message
58
+ * @param message Message
59
+ * @param passphrase Secret passphrase
60
+ * @param iterations Iterations, 1000 times, 1 - 99
61
+ * @returns Result
62
+ */
63
+ serviceEncrypt(message: string, passphrase?: string, iterations?: number): string;
45
64
  /**
46
65
  * Try login
47
66
  */
@@ -16,6 +16,10 @@ export class ServiceApp extends ReactApp {
16
16
  */
17
17
  constructor(settings, name) {
18
18
  super(settings, name);
19
+ /**
20
+ * Service passphrase
21
+ */
22
+ this.servicePassphrase = '';
19
23
  // Check
20
24
  if (settings.serviceId == null || settings.coreApi == null) {
21
25
  throw new Error('No service settings');
@@ -93,7 +97,7 @@ export class ServiceApp extends ReactApp {
93
97
  const userData = result.data;
94
98
  // Use core system access token to service api to exchange service access token
95
99
  const serviceResult = await this.api.put('Auth/ExchangeToken', {
96
- token: userData.token
100
+ token: this.encryptEnhanced(userData.token, this.settings.serviceId.toString())
97
101
  }, {
98
102
  showLoading,
99
103
  onError: (error) => {
@@ -115,7 +119,11 @@ export class ServiceApp extends ReactApp {
115
119
  failCallback(this.get('noData'));
116
120
  return false;
117
121
  }
122
+ // Login
118
123
  this.userLoginEx(serviceResult.data, refreshToken, userData);
124
+ // Success callback
125
+ if (failCallback)
126
+ failCallback(true);
119
127
  return true;
120
128
  };
121
129
  // Call API
@@ -133,13 +141,18 @@ export class ServiceApp extends ReactApp {
133
141
  return;
134
142
  }
135
143
  // Set password for the action
136
- rq.pwd = this.encrypt(pwd, this.settings.serviceId.toString());
144
+ rq.pwd = this.encrypt(this.hash(pwd));
137
145
  // Submit again
138
- const result = await this.api.put('Auth/RefreshToken', data, payload);
146
+ const result = await this.coreApi.put('Auth/RefreshToken', rq, payload);
139
147
  if (result == null)
140
148
  return;
141
149
  if (result.ok) {
142
150
  await success(result, (loginResult) => {
151
+ if (loginResult === true) {
152
+ if (callback)
153
+ callback(true);
154
+ return;
155
+ }
143
156
  const message = this.formatRefreshTokenResult(loginResult);
144
157
  if (message)
145
158
  this.notifier.alert(message);
@@ -163,6 +176,25 @@ export class ServiceApp extends ReactApp {
163
176
  this.userUnauthorized();
164
177
  this.toLoginPage();
165
178
  }
179
+ /**
180
+ * Service decrypt message
181
+ * @param messageEncrypted Encrypted message
182
+ * @param passphrase Secret passphrase
183
+ * @returns Pure text
184
+ */
185
+ serviceDecrypt(messageEncrypted, passphrase) {
186
+ return this.decrypt(messageEncrypted, passphrase !== null && passphrase !== void 0 ? passphrase : this.servicePassphrase);
187
+ }
188
+ /**
189
+ * Service encrypt message
190
+ * @param message Message
191
+ * @param passphrase Secret passphrase
192
+ * @param iterations Iterations, 1000 times, 1 - 99
193
+ * @returns Result
194
+ */
195
+ serviceEncrypt(message, passphrase, iterations) {
196
+ return this.encrypt(message, passphrase !== null && passphrase !== void 0 ? passphrase : this.servicePassphrase, iterations);
197
+ }
166
198
  /**
167
199
  * Try login
168
200
  */
@@ -174,6 +206,9 @@ export class ServiceApp extends ReactApp {
174
206
  // Refresh token
175
207
  return await this.refreshToken({
176
208
  callback: (result) => {
209
+ // Success
210
+ if (result === true)
211
+ return;
177
212
  const message = this.formatRefreshTokenResult(result);
178
213
  if (message == null) {
179
214
  this.loginFailed();
@@ -194,7 +229,10 @@ export class ServiceApp extends ReactApp {
194
229
  * @param coreUser Core system user
195
230
  */
196
231
  userLoginEx(user, refreshToken, coreUser) {
232
+ var _a;
197
233
  // Service user login
234
+ this.servicePassphrase =
235
+ (_a = this.decrypt(user.serviceDeviceId, this.settings.serviceId.toString())) !== null && _a !== void 0 ? _a : '';
198
236
  super.userLogin(user, refreshToken, false);
199
237
  // Core system user
200
238
  this.coreUser = coreUser;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.3.65",
3
+ "version": "1.3.69",
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.82",
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",
@@ -3,7 +3,12 @@ import { IActionResult, IUser } from '@etsoo/appscript';
3
3
  /**
4
4
  * Service user interface
5
5
  */
6
- export interface IServiceUser extends IUser {}
6
+ export interface IServiceUser extends IUser {
7
+ /**
8
+ * Service device id
9
+ */
10
+ serviceDeviceId: string;
11
+ }
7
12
 
8
13
  /**
9
14
  * Service user login result
@@ -353,17 +353,19 @@ export class ReactApp<
353
353
  * @param user New user
354
354
  * @param refreshToken Refresh token
355
355
  * @param keep Keep in local storage or not
356
+ * @param dispatch User state dispatch
356
357
  */
357
358
  override userLogin(
358
359
  user: IUserData,
359
360
  refreshToken: string,
360
- keep?: boolean
361
+ keep?: boolean,
362
+ dispatch?: boolean
361
363
  ): void {
362
364
  // Super call, set token
363
365
  super.userLogin(user, refreshToken, keep);
364
366
 
365
367
  // Dispatch action
366
- if (this.userStateDispatch != null)
368
+ if (this.userStateDispatch != null && dispatch !== false)
367
369
  this.userStateDispatch({
368
370
  type: UserActionType.Login,
369
371
  user
@@ -37,6 +37,11 @@ export class ServiceApp<
37
37
  */
38
38
  coreUser?: ISmartERPUser;
39
39
 
40
+ /**
41
+ * Service passphrase
42
+ */
43
+ servicePassphrase: string = '';
44
+
40
45
  /**
41
46
  * Constructor
42
47
  * @param settings Settings
@@ -143,7 +148,10 @@ export class ServiceApp<
143
148
  const serviceResult = await this.api.put<ServiceLoginResult>(
144
149
  'Auth/ExchangeToken',
145
150
  {
146
- token: userData.token
151
+ token: this.encryptEnhanced(
152
+ userData.token,
153
+ this.settings.serviceId.toString()
154
+ )
147
155
  },
148
156
  {
149
157
  showLoading,
@@ -168,8 +176,12 @@ export class ServiceApp<
168
176
  return false;
169
177
  }
170
178
 
179
+ // Login
171
180
  this.userLoginEx(serviceResult.data, refreshToken, userData);
172
181
 
182
+ // Success callback
183
+ if (failCallback) failCallback(true);
184
+
173
185
  return true;
174
186
  };
175
187
 
@@ -195,17 +207,15 @@ export class ServiceApp<
195
207
  }
196
208
 
197
209
  // Set password for the action
198
- rq.pwd = this.encrypt(
199
- pwd,
200
- this.settings.serviceId.toString()
201
- );
210
+ rq.pwd = this.encrypt(this.hash(pwd));
202
211
 
203
212
  // Submit again
204
- const result = await this.api.put<SmartERPLoginResult>(
205
- 'Auth/RefreshToken',
206
- data,
207
- payload
208
- );
213
+ const result =
214
+ await this.coreApi.put<SmartERPLoginResult>(
215
+ 'Auth/RefreshToken',
216
+ rq,
217
+ payload
218
+ );
209
219
 
210
220
  if (result == null) return;
211
221
 
@@ -213,6 +223,11 @@ export class ServiceApp<
213
223
  await success(
214
224
  result,
215
225
  (loginResult: RefreshTokenResult) => {
226
+ if (loginResult === true) {
227
+ if (callback) callback(true);
228
+ return;
229
+ }
230
+
216
231
  const message =
217
232
  this.formatRefreshTokenResult(
218
233
  loginResult
@@ -247,6 +262,34 @@ export class ServiceApp<
247
262
  this.toLoginPage();
248
263
  }
249
264
 
265
+ /**
266
+ * Service decrypt message
267
+ * @param messageEncrypted Encrypted message
268
+ * @param passphrase Secret passphrase
269
+ * @returns Pure text
270
+ */
271
+ serviceDecrypt(messageEncrypted: string, passphrase?: string) {
272
+ return this.decrypt(
273
+ messageEncrypted,
274
+ passphrase ?? this.servicePassphrase
275
+ );
276
+ }
277
+
278
+ /**
279
+ * Service encrypt message
280
+ * @param message Message
281
+ * @param passphrase Secret passphrase
282
+ * @param iterations Iterations, 1000 times, 1 - 99
283
+ * @returns Result
284
+ */
285
+ serviceEncrypt(message: string, passphrase?: string, iterations?: number) {
286
+ return this.encrypt(
287
+ message,
288
+ passphrase ?? this.servicePassphrase,
289
+ iterations
290
+ );
291
+ }
292
+
250
293
  /**
251
294
  * Try login
252
295
  */
@@ -258,6 +301,9 @@ export class ServiceApp<
258
301
  // Refresh token
259
302
  return await this.refreshToken({
260
303
  callback: (result) => {
304
+ // Success
305
+ if (result === true) return;
306
+
261
307
  const message = this.formatRefreshTokenResult(result);
262
308
  if (message == null) {
263
309
  this.loginFailed();
@@ -285,6 +331,11 @@ export class ServiceApp<
285
331
  coreUser: ISmartERPUser
286
332
  ): void {
287
333
  // Service user login
334
+ this.servicePassphrase =
335
+ this.decrypt(
336
+ user.serviceDeviceId,
337
+ this.settings.serviceId.toString()
338
+ ) ?? '';
288
339
  super.userLogin(user, refreshToken, false);
289
340
 
290
341
  // Core system user