@etsoo/appscript 1.5.48 → 1.5.50
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/cjs/app/CoreApp.d.ts +10 -2
- package/lib/cjs/app/CoreApp.js +24 -6
- package/lib/cjs/app/IApp.d.ts +3 -2
- package/lib/cjs/erp/AuthApi.js +5 -0
- package/lib/mjs/app/CoreApp.d.ts +10 -2
- package/lib/mjs/app/CoreApp.js +24 -6
- package/lib/mjs/app/IApp.d.ts +3 -2
- package/lib/mjs/erp/AuthApi.js +5 -0
- package/package.json +1 -1
- package/src/app/CoreApp.ts +33 -11
- package/src/app/IApp.ts +3 -2
- package/src/erp/AuthApi.ts +8 -0
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -193,8 +193,9 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
193
193
|
isValidPassword(password: string): boolean;
|
|
194
194
|
/**
|
|
195
195
|
* Persist settings to source when application exit
|
|
196
|
+
* @param keepLogin Keep login or not
|
|
196
197
|
*/
|
|
197
|
-
persist(): void;
|
|
198
|
+
persist(keepLogin?: boolean): void;
|
|
198
199
|
/**
|
|
199
200
|
* Add scheduled task
|
|
200
201
|
* @param task Task, return false to stop
|
|
@@ -509,7 +510,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
509
510
|
* @param tokenKey Refresh token key
|
|
510
511
|
* @returns response refresh token
|
|
511
512
|
*/
|
|
512
|
-
getResponseToken(rawResponse: any, tokenKey
|
|
513
|
+
getResponseToken(rawResponse: any, tokenKey: string): string | null;
|
|
513
514
|
/**
|
|
514
515
|
* Get time zone
|
|
515
516
|
* @returns Time zone
|
|
@@ -600,6 +601,13 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
600
601
|
* @param coreName Core system's name, default is 'core'
|
|
601
602
|
*/
|
|
602
603
|
exchangeTokenAll(coreData: ApiRefreshTokenDto, coreName?: string): void;
|
|
604
|
+
/**
|
|
605
|
+
* API refresh token data
|
|
606
|
+
* @param api Current API
|
|
607
|
+
* @param token Refresh token
|
|
608
|
+
* @returns Result
|
|
609
|
+
*/
|
|
610
|
+
protected apiRefreshTokenData(api: IApi, token: string): Promise<ApiRefreshTokenDto | undefined>;
|
|
603
611
|
/**
|
|
604
612
|
* API refresh token
|
|
605
613
|
* @param api Current API
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -303,8 +303,13 @@ class CoreApp {
|
|
|
303
303
|
}
|
|
304
304
|
/**
|
|
305
305
|
* Persist settings to source when application exit
|
|
306
|
+
* @param keepLogin Keep login or not
|
|
306
307
|
*/
|
|
307
|
-
persist() {
|
|
308
|
+
persist(keepLogin) {
|
|
309
|
+
if (!keepLogin) {
|
|
310
|
+
// Unconditional clear the cache for security
|
|
311
|
+
this.clearCacheToken();
|
|
312
|
+
}
|
|
308
313
|
// Devices
|
|
309
314
|
const devices = this.storage.getPersistedData(this.fields.devices);
|
|
310
315
|
if (devices != null) {
|
|
@@ -317,7 +322,10 @@ class CoreApp {
|
|
|
317
322
|
}
|
|
318
323
|
if (!this.authorized)
|
|
319
324
|
return;
|
|
320
|
-
|
|
325
|
+
const fields = keepLogin
|
|
326
|
+
? this.persistedFields
|
|
327
|
+
: this.persistedFields.filter((f) => f !== this.fields.headerToken);
|
|
328
|
+
this.storage.copyTo(fields);
|
|
321
329
|
}
|
|
322
330
|
/**
|
|
323
331
|
* Add scheduled task
|
|
@@ -1236,7 +1244,7 @@ class CoreApp {
|
|
|
1236
1244
|
const response = this.api.transformResponse(rawResponse);
|
|
1237
1245
|
if (!response.ok)
|
|
1238
1246
|
return null;
|
|
1239
|
-
return this.api.getHeaderValue(response.headers, tokenKey
|
|
1247
|
+
return this.api.getHeaderValue(response.headers, tokenKey);
|
|
1240
1248
|
}
|
|
1241
1249
|
/**
|
|
1242
1250
|
* Get time zone
|
|
@@ -1488,14 +1496,14 @@ class CoreApp {
|
|
|
1488
1496
|
}
|
|
1489
1497
|
}
|
|
1490
1498
|
/**
|
|
1491
|
-
* API refresh token
|
|
1499
|
+
* API refresh token data
|
|
1492
1500
|
* @param api Current API
|
|
1493
1501
|
* @param token Refresh token
|
|
1494
1502
|
* @returns Result
|
|
1495
1503
|
*/
|
|
1496
|
-
async
|
|
1504
|
+
async apiRefreshTokenData(api, token) {
|
|
1497
1505
|
// Call the API quietly, no loading bar and no error popup
|
|
1498
|
-
|
|
1506
|
+
return new AuthApi_1.AuthApi(this).apiRefreshToken({ token }, {
|
|
1499
1507
|
showLoading: false,
|
|
1500
1508
|
onError: (error) => {
|
|
1501
1509
|
console.error(`CoreApp.${api.name}.apiRefreshToken error`, error);
|
|
@@ -1503,6 +1511,16 @@ class CoreApp {
|
|
|
1503
1511
|
return false;
|
|
1504
1512
|
}
|
|
1505
1513
|
});
|
|
1514
|
+
}
|
|
1515
|
+
/**
|
|
1516
|
+
* API refresh token
|
|
1517
|
+
* @param api Current API
|
|
1518
|
+
* @param token Refresh token
|
|
1519
|
+
* @returns Result
|
|
1520
|
+
*/
|
|
1521
|
+
async apiRefreshToken(api, token) {
|
|
1522
|
+
// Call the API quietly, no loading bar and no error popup
|
|
1523
|
+
const data = await this.apiRefreshTokenData(api, token);
|
|
1506
1524
|
if (data == null)
|
|
1507
1525
|
return undefined;
|
|
1508
1526
|
// Update the access token
|
package/lib/cjs/app/IApp.d.ts
CHANGED
|
@@ -462,7 +462,7 @@ export interface IApp {
|
|
|
462
462
|
* @param tokenKey Refresh token key
|
|
463
463
|
* @returns response refresh token
|
|
464
464
|
*/
|
|
465
|
-
getResponseToken(rawResponse: any, tokenKey
|
|
465
|
+
getResponseToken(rawResponse: any, tokenKey: string): string | null;
|
|
466
466
|
/**
|
|
467
467
|
* Get time zone
|
|
468
468
|
* @returns Time zone
|
|
@@ -561,8 +561,9 @@ export interface IApp {
|
|
|
561
561
|
signout(): Promise<void>;
|
|
562
562
|
/**
|
|
563
563
|
* Persist settings to source when application exit
|
|
564
|
+
* @param keepLogin Keep login or not
|
|
564
565
|
*/
|
|
565
|
-
persist(): void;
|
|
566
|
+
persist(keepLogin?: boolean): void;
|
|
566
567
|
/**
|
|
567
568
|
* Go to the login page
|
|
568
569
|
* @param params Login parameters
|
package/lib/cjs/erp/AuthApi.js
CHANGED
|
@@ -42,11 +42,16 @@ class AuthApi extends BaseApi_1.BaseApi {
|
|
|
42
42
|
* @returns Result
|
|
43
43
|
*/
|
|
44
44
|
async loginBase(rq, payload, tokenKey) {
|
|
45
|
+
// Default values
|
|
45
46
|
payload ?? (payload = {});
|
|
47
|
+
tokenKey ?? (tokenKey = AuthApi.HeaderTokenField);
|
|
48
|
+
// Call the API
|
|
46
49
|
const result = await this.api.post('Auth/Login', rq, payload);
|
|
50
|
+
// Get the refresh token
|
|
47
51
|
const refreshToken = result?.ok
|
|
48
52
|
? this.app.getResponseToken(payload.response, tokenKey)
|
|
49
53
|
: null;
|
|
54
|
+
// Return the result
|
|
50
55
|
return [result, refreshToken];
|
|
51
56
|
}
|
|
52
57
|
/**
|
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -193,8 +193,9 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
193
193
|
isValidPassword(password: string): boolean;
|
|
194
194
|
/**
|
|
195
195
|
* Persist settings to source when application exit
|
|
196
|
+
* @param keepLogin Keep login or not
|
|
196
197
|
*/
|
|
197
|
-
persist(): void;
|
|
198
|
+
persist(keepLogin?: boolean): void;
|
|
198
199
|
/**
|
|
199
200
|
* Add scheduled task
|
|
200
201
|
* @param task Task, return false to stop
|
|
@@ -509,7 +510,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
509
510
|
* @param tokenKey Refresh token key
|
|
510
511
|
* @returns response refresh token
|
|
511
512
|
*/
|
|
512
|
-
getResponseToken(rawResponse: any, tokenKey
|
|
513
|
+
getResponseToken(rawResponse: any, tokenKey: string): string | null;
|
|
513
514
|
/**
|
|
514
515
|
* Get time zone
|
|
515
516
|
* @returns Time zone
|
|
@@ -600,6 +601,13 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
600
601
|
* @param coreName Core system's name, default is 'core'
|
|
601
602
|
*/
|
|
602
603
|
exchangeTokenAll(coreData: ApiRefreshTokenDto, coreName?: string): void;
|
|
604
|
+
/**
|
|
605
|
+
* API refresh token data
|
|
606
|
+
* @param api Current API
|
|
607
|
+
* @param token Refresh token
|
|
608
|
+
* @returns Result
|
|
609
|
+
*/
|
|
610
|
+
protected apiRefreshTokenData(api: IApi, token: string): Promise<ApiRefreshTokenDto | undefined>;
|
|
603
611
|
/**
|
|
604
612
|
* API refresh token
|
|
605
613
|
* @param api Current API
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -300,8 +300,13 @@ export class CoreApp {
|
|
|
300
300
|
}
|
|
301
301
|
/**
|
|
302
302
|
* Persist settings to source when application exit
|
|
303
|
+
* @param keepLogin Keep login or not
|
|
303
304
|
*/
|
|
304
|
-
persist() {
|
|
305
|
+
persist(keepLogin) {
|
|
306
|
+
if (!keepLogin) {
|
|
307
|
+
// Unconditional clear the cache for security
|
|
308
|
+
this.clearCacheToken();
|
|
309
|
+
}
|
|
305
310
|
// Devices
|
|
306
311
|
const devices = this.storage.getPersistedData(this.fields.devices);
|
|
307
312
|
if (devices != null) {
|
|
@@ -314,7 +319,10 @@ export class CoreApp {
|
|
|
314
319
|
}
|
|
315
320
|
if (!this.authorized)
|
|
316
321
|
return;
|
|
317
|
-
|
|
322
|
+
const fields = keepLogin
|
|
323
|
+
? this.persistedFields
|
|
324
|
+
: this.persistedFields.filter((f) => f !== this.fields.headerToken);
|
|
325
|
+
this.storage.copyTo(fields);
|
|
318
326
|
}
|
|
319
327
|
/**
|
|
320
328
|
* Add scheduled task
|
|
@@ -1233,7 +1241,7 @@ export class CoreApp {
|
|
|
1233
1241
|
const response = this.api.transformResponse(rawResponse);
|
|
1234
1242
|
if (!response.ok)
|
|
1235
1243
|
return null;
|
|
1236
|
-
return this.api.getHeaderValue(response.headers, tokenKey
|
|
1244
|
+
return this.api.getHeaderValue(response.headers, tokenKey);
|
|
1237
1245
|
}
|
|
1238
1246
|
/**
|
|
1239
1247
|
* Get time zone
|
|
@@ -1485,14 +1493,14 @@ export class CoreApp {
|
|
|
1485
1493
|
}
|
|
1486
1494
|
}
|
|
1487
1495
|
/**
|
|
1488
|
-
* API refresh token
|
|
1496
|
+
* API refresh token data
|
|
1489
1497
|
* @param api Current API
|
|
1490
1498
|
* @param token Refresh token
|
|
1491
1499
|
* @returns Result
|
|
1492
1500
|
*/
|
|
1493
|
-
async
|
|
1501
|
+
async apiRefreshTokenData(api, token) {
|
|
1494
1502
|
// Call the API quietly, no loading bar and no error popup
|
|
1495
|
-
|
|
1503
|
+
return new AuthApi(this).apiRefreshToken({ token }, {
|
|
1496
1504
|
showLoading: false,
|
|
1497
1505
|
onError: (error) => {
|
|
1498
1506
|
console.error(`CoreApp.${api.name}.apiRefreshToken error`, error);
|
|
@@ -1500,6 +1508,16 @@ export class CoreApp {
|
|
|
1500
1508
|
return false;
|
|
1501
1509
|
}
|
|
1502
1510
|
});
|
|
1511
|
+
}
|
|
1512
|
+
/**
|
|
1513
|
+
* API refresh token
|
|
1514
|
+
* @param api Current API
|
|
1515
|
+
* @param token Refresh token
|
|
1516
|
+
* @returns Result
|
|
1517
|
+
*/
|
|
1518
|
+
async apiRefreshToken(api, token) {
|
|
1519
|
+
// Call the API quietly, no loading bar and no error popup
|
|
1520
|
+
const data = await this.apiRefreshTokenData(api, token);
|
|
1503
1521
|
if (data == null)
|
|
1504
1522
|
return undefined;
|
|
1505
1523
|
// Update the access token
|
package/lib/mjs/app/IApp.d.ts
CHANGED
|
@@ -462,7 +462,7 @@ export interface IApp {
|
|
|
462
462
|
* @param tokenKey Refresh token key
|
|
463
463
|
* @returns response refresh token
|
|
464
464
|
*/
|
|
465
|
-
getResponseToken(rawResponse: any, tokenKey
|
|
465
|
+
getResponseToken(rawResponse: any, tokenKey: string): string | null;
|
|
466
466
|
/**
|
|
467
467
|
* Get time zone
|
|
468
468
|
* @returns Time zone
|
|
@@ -561,8 +561,9 @@ export interface IApp {
|
|
|
561
561
|
signout(): Promise<void>;
|
|
562
562
|
/**
|
|
563
563
|
* Persist settings to source when application exit
|
|
564
|
+
* @param keepLogin Keep login or not
|
|
564
565
|
*/
|
|
565
|
-
persist(): void;
|
|
566
|
+
persist(keepLogin?: boolean): void;
|
|
566
567
|
/**
|
|
567
568
|
* Go to the login page
|
|
568
569
|
* @param params Login parameters
|
package/lib/mjs/erp/AuthApi.js
CHANGED
|
@@ -39,11 +39,16 @@ export class AuthApi extends BaseApi {
|
|
|
39
39
|
* @returns Result
|
|
40
40
|
*/
|
|
41
41
|
async loginBase(rq, payload, tokenKey) {
|
|
42
|
+
// Default values
|
|
42
43
|
payload ?? (payload = {});
|
|
44
|
+
tokenKey ?? (tokenKey = AuthApi.HeaderTokenField);
|
|
45
|
+
// Call the API
|
|
43
46
|
const result = await this.api.post('Auth/Login', rq, payload);
|
|
47
|
+
// Get the refresh token
|
|
44
48
|
const refreshToken = result?.ok
|
|
45
49
|
? this.app.getResponseToken(payload.response, tokenKey)
|
|
46
50
|
: null;
|
|
51
|
+
// Return the result
|
|
47
52
|
return [result, refreshToken];
|
|
48
53
|
}
|
|
49
54
|
/**
|
package/package.json
CHANGED
package/src/app/CoreApp.ts
CHANGED
|
@@ -525,8 +525,14 @@ export abstract class CoreApp<
|
|
|
525
525
|
|
|
526
526
|
/**
|
|
527
527
|
* Persist settings to source when application exit
|
|
528
|
+
* @param keepLogin Keep login or not
|
|
528
529
|
*/
|
|
529
|
-
persist() {
|
|
530
|
+
persist(keepLogin?: boolean) {
|
|
531
|
+
if (!keepLogin) {
|
|
532
|
+
// Unconditional clear the cache for security
|
|
533
|
+
this.clearCacheToken();
|
|
534
|
+
}
|
|
535
|
+
|
|
530
536
|
// Devices
|
|
531
537
|
const devices = this.storage.getPersistedData<string[]>(
|
|
532
538
|
this.fields.devices
|
|
@@ -541,7 +547,12 @@ export abstract class CoreApp<
|
|
|
541
547
|
}
|
|
542
548
|
|
|
543
549
|
if (!this.authorized) return;
|
|
544
|
-
|
|
550
|
+
|
|
551
|
+
const fields = keepLogin
|
|
552
|
+
? this.persistedFields
|
|
553
|
+
: this.persistedFields.filter((f) => f !== this.fields.headerToken);
|
|
554
|
+
|
|
555
|
+
this.storage.copyTo(fields);
|
|
545
556
|
}
|
|
546
557
|
|
|
547
558
|
/**
|
|
@@ -1748,13 +1759,10 @@ export abstract class CoreApp<
|
|
|
1748
1759
|
* @param tokenKey Refresh token key
|
|
1749
1760
|
* @returns response refresh token
|
|
1750
1761
|
*/
|
|
1751
|
-
getResponseToken(rawResponse: any, tokenKey
|
|
1762
|
+
getResponseToken(rawResponse: any, tokenKey: string): string | null {
|
|
1752
1763
|
const response = this.api.transformResponse(rawResponse);
|
|
1753
1764
|
if (!response.ok) return null;
|
|
1754
|
-
return this.api.getHeaderValue(
|
|
1755
|
-
response.headers,
|
|
1756
|
-
tokenKey ?? 'Smarterp-Refresh-Token'
|
|
1757
|
-
);
|
|
1765
|
+
return this.api.getHeaderValue(response.headers, tokenKey);
|
|
1758
1766
|
}
|
|
1759
1767
|
|
|
1760
1768
|
/**
|
|
@@ -2046,17 +2054,17 @@ export abstract class CoreApp<
|
|
|
2046
2054
|
}
|
|
2047
2055
|
|
|
2048
2056
|
/**
|
|
2049
|
-
* API refresh token
|
|
2057
|
+
* API refresh token data
|
|
2050
2058
|
* @param api Current API
|
|
2051
2059
|
* @param token Refresh token
|
|
2052
2060
|
* @returns Result
|
|
2053
2061
|
*/
|
|
2054
|
-
protected async
|
|
2062
|
+
protected async apiRefreshTokenData(
|
|
2055
2063
|
api: IApi,
|
|
2056
2064
|
token: string
|
|
2057
|
-
): Promise<
|
|
2065
|
+
): Promise<ApiRefreshTokenDto | undefined> {
|
|
2058
2066
|
// Call the API quietly, no loading bar and no error popup
|
|
2059
|
-
|
|
2067
|
+
return new AuthApi(this).apiRefreshToken(
|
|
2060
2068
|
{ token },
|
|
2061
2069
|
{
|
|
2062
2070
|
showLoading: false,
|
|
@@ -2071,6 +2079,20 @@ export abstract class CoreApp<
|
|
|
2071
2079
|
}
|
|
2072
2080
|
}
|
|
2073
2081
|
);
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2084
|
+
/**
|
|
2085
|
+
* API refresh token
|
|
2086
|
+
* @param api Current API
|
|
2087
|
+
* @param token Refresh token
|
|
2088
|
+
* @returns Result
|
|
2089
|
+
*/
|
|
2090
|
+
protected async apiRefreshToken(
|
|
2091
|
+
api: IApi,
|
|
2092
|
+
token: string
|
|
2093
|
+
): Promise<[string, number] | undefined> {
|
|
2094
|
+
// Call the API quietly, no loading bar and no error popup
|
|
2095
|
+
const data = await this.apiRefreshTokenData(api, token);
|
|
2074
2096
|
if (data == null) return undefined;
|
|
2075
2097
|
|
|
2076
2098
|
// Update the access token
|
package/src/app/IApp.ts
CHANGED
|
@@ -623,7 +623,7 @@ export interface IApp {
|
|
|
623
623
|
* @param tokenKey Refresh token key
|
|
624
624
|
* @returns response refresh token
|
|
625
625
|
*/
|
|
626
|
-
getResponseToken(rawResponse: any, tokenKey
|
|
626
|
+
getResponseToken(rawResponse: any, tokenKey: string): string | null;
|
|
627
627
|
|
|
628
628
|
/**
|
|
629
629
|
* Get time zone
|
|
@@ -758,8 +758,9 @@ export interface IApp {
|
|
|
758
758
|
|
|
759
759
|
/**
|
|
760
760
|
* Persist settings to source when application exit
|
|
761
|
+
* @param keepLogin Keep login or not
|
|
761
762
|
*/
|
|
762
|
-
persist(): void;
|
|
763
|
+
persist(keepLogin?: boolean): void;
|
|
763
764
|
|
|
764
765
|
/**
|
|
765
766
|
* Go to the login page
|
package/src/erp/AuthApi.ts
CHANGED
|
@@ -65,11 +65,19 @@ export class AuthApi extends BaseApi {
|
|
|
65
65
|
payload?: IApiPayload<IActionResult<T>>,
|
|
66
66
|
tokenKey?: string
|
|
67
67
|
): Promise<[IActionResult<T> | undefined, string | null]> {
|
|
68
|
+
// Default values
|
|
68
69
|
payload ??= {};
|
|
70
|
+
tokenKey ??= AuthApi.HeaderTokenField;
|
|
71
|
+
|
|
72
|
+
// Call the API
|
|
69
73
|
const result = await this.api.post('Auth/Login', rq, payload);
|
|
74
|
+
|
|
75
|
+
// Get the refresh token
|
|
70
76
|
const refreshToken = result?.ok
|
|
71
77
|
? this.app.getResponseToken(payload.response, tokenKey)
|
|
72
78
|
: null;
|
|
79
|
+
|
|
80
|
+
// Return the result
|
|
73
81
|
return [result, refreshToken];
|
|
74
82
|
}
|
|
75
83
|
|