@etsoo/appscript 1.5.49 → 1.5.51
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/__tests__/app/Culture.ts +20 -1
- package/lib/cjs/app/CoreApp.d.ts +3 -2
- package/lib/cjs/app/CoreApp.js +11 -3
- package/lib/cjs/app/IApp.d.ts +3 -2
- package/lib/cjs/erp/AuthApi.js +5 -0
- package/lib/cjs/i18n/CultureUtils.d.ts +3 -2
- package/lib/cjs/i18n/CultureUtils.js +3 -3
- package/lib/cjs/i18n/en.js +2 -1
- package/lib/cjs/i18n/zhHans.js +2 -1
- package/lib/cjs/i18n/zhHant.js +2 -1
- package/lib/mjs/app/CoreApp.d.ts +3 -2
- package/lib/mjs/app/CoreApp.js +11 -3
- package/lib/mjs/app/IApp.d.ts +3 -2
- package/lib/mjs/erp/AuthApi.js +5 -0
- package/lib/mjs/i18n/CultureUtils.d.ts +3 -2
- package/lib/mjs/i18n/CultureUtils.js +3 -3
- package/lib/mjs/i18n/en.js +2 -1
- package/lib/mjs/i18n/zhHans.js +2 -1
- package/lib/mjs/i18n/zhHant.js +2 -1
- package/package.json +4 -4
- package/src/app/CoreApp.ts +15 -7
- package/src/app/IApp.ts +3 -2
- package/src/erp/AuthApi.ts +8 -0
- package/src/i18n/CultureUtils.ts +6 -2
- package/src/i18n/en.ts +2 -1
- package/src/i18n/zhHans.ts +2 -1
- package/src/i18n/zhHant.ts +2 -1
package/__tests__/app/Culture.ts
CHANGED
|
@@ -1,10 +1,29 @@
|
|
|
1
|
-
import { zhHans } from '../../src';
|
|
1
|
+
import { en, zhHans } from '../../src';
|
|
2
|
+
|
|
3
|
+
test('Tests for en', async () => {
|
|
4
|
+
const e = en(
|
|
5
|
+
{ nameB: 'Name for Business' },
|
|
6
|
+
new Promise((resolve) => resolve({ no: 'No override' }))
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
expect(e.name).toBe('en');
|
|
10
|
+
|
|
11
|
+
const resources =
|
|
12
|
+
typeof e.resources === 'object' ? e.resources : await e.resources();
|
|
13
|
+
|
|
14
|
+
expect(resources.name).toBe('Name');
|
|
15
|
+
expect(resources.nameB).toBe('Name for Business');
|
|
16
|
+
expect(resources.no).toBe('No override');
|
|
17
|
+
});
|
|
2
18
|
|
|
3
19
|
test('Tests for zhHans', async () => {
|
|
4
20
|
const zh = zhHans(
|
|
5
21
|
{ nameB: '名称覆盖' },
|
|
6
22
|
new Promise((resolve) => resolve({ no: 'No override' }))
|
|
7
23
|
);
|
|
24
|
+
|
|
25
|
+
expect(zh.name).toBe('zh-Hans');
|
|
26
|
+
|
|
8
27
|
const resources =
|
|
9
28
|
typeof zh.resources === 'object' ? zh.resources : await zh.resources();
|
|
10
29
|
|
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
|
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
|
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
|
/**
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { DataTypes } from '@etsoo/shared';
|
|
1
|
+
import { DataTypes, DomUtils } from '@etsoo/shared';
|
|
2
2
|
/**
|
|
3
3
|
* Culture utilities
|
|
4
4
|
*/
|
|
5
5
|
export declare namespace CultureUtils {
|
|
6
6
|
/**
|
|
7
7
|
* Make culture
|
|
8
|
+
* @param cultureMaker Culture maker
|
|
8
9
|
* @param resources Resources
|
|
9
10
|
* @returns Culture
|
|
10
11
|
*/
|
|
11
|
-
function make(...resources: (object | (() => Promise<object>))[]): DataTypes.CultureDefinition<DataTypes.StringRecord>;
|
|
12
|
+
function make(cultureMaker: typeof DomUtils.zhHans, ...resources: (object | (() => Promise<object>))[]): DataTypes.CultureDefinition<DataTypes.StringRecord>;
|
|
12
13
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CultureUtils = void 0;
|
|
4
|
-
const shared_1 = require("@etsoo/shared");
|
|
5
4
|
/**
|
|
6
5
|
* Culture utilities
|
|
7
6
|
*/
|
|
@@ -9,11 +8,12 @@ var CultureUtils;
|
|
|
9
8
|
(function (CultureUtils) {
|
|
10
9
|
/**
|
|
11
10
|
* Make culture
|
|
11
|
+
* @param cultureMaker Culture maker
|
|
12
12
|
* @param resources Resources
|
|
13
13
|
* @returns Culture
|
|
14
14
|
*/
|
|
15
|
-
function make(...resources) {
|
|
16
|
-
return
|
|
15
|
+
function make(cultureMaker, ...resources) {
|
|
16
|
+
return cultureMaker(async () => {
|
|
17
17
|
const rs = await Promise.all(resources.map((resource) => new Promise((resolve) => {
|
|
18
18
|
if (typeof resource === 'object') {
|
|
19
19
|
resolve(resource);
|
package/lib/cjs/i18n/en.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.en = void 0;
|
|
4
|
+
const shared_1 = require("@etsoo/shared");
|
|
4
5
|
const CultureUtils_1 = require("./CultureUtils");
|
|
5
6
|
/**
|
|
6
7
|
* Get en neutral culture
|
|
7
8
|
* @param localResources Local resources
|
|
8
9
|
* @returns Full culture
|
|
9
10
|
*/
|
|
10
|
-
const en = (...resources) => CultureUtils_1.CultureUtils.make(import('./en.json'), ...resources);
|
|
11
|
+
const en = (...resources) => CultureUtils_1.CultureUtils.make(shared_1.DomUtils.en, import('./en.json'), ...resources);
|
|
11
12
|
exports.en = en;
|
package/lib/cjs/i18n/zhHans.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.zhHans = void 0;
|
|
4
|
+
const shared_1 = require("@etsoo/shared");
|
|
4
5
|
const CultureUtils_1 = require("./CultureUtils");
|
|
5
6
|
/**
|
|
6
7
|
* Get zh-Hans neutral cultrue
|
|
7
8
|
* @param localResources Local resources
|
|
8
9
|
* @returns Full culture
|
|
9
10
|
*/
|
|
10
|
-
const zhHans = (...resources) => CultureUtils_1.CultureUtils.make(import('./zh-Hans.json'), ...resources);
|
|
11
|
+
const zhHans = (...resources) => CultureUtils_1.CultureUtils.make(shared_1.DomUtils.zhHans, import('./zh-Hans.json'), ...resources);
|
|
11
12
|
exports.zhHans = zhHans;
|
package/lib/cjs/i18n/zhHant.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.zhHant = void 0;
|
|
4
|
+
const shared_1 = require("@etsoo/shared");
|
|
4
5
|
const CultureUtils_1 = require("./CultureUtils");
|
|
5
6
|
/**
|
|
6
7
|
* Get zh-Hant neutral cultrue
|
|
7
8
|
* @param localResources Local resources
|
|
8
9
|
* @returns Full culture
|
|
9
10
|
*/
|
|
10
|
-
const zhHant = (...resources) => CultureUtils_1.CultureUtils.make(import('./zh-Hant.json'), ...resources);
|
|
11
|
+
const zhHant = (...resources) => CultureUtils_1.CultureUtils.make(shared_1.DomUtils.zhHant, import('./zh-Hant.json'), ...resources);
|
|
11
12
|
exports.zhHant = zhHant;
|
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
|
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
|
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
|
/**
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { DataTypes } from '@etsoo/shared';
|
|
1
|
+
import { DataTypes, DomUtils } from '@etsoo/shared';
|
|
2
2
|
/**
|
|
3
3
|
* Culture utilities
|
|
4
4
|
*/
|
|
5
5
|
export declare namespace CultureUtils {
|
|
6
6
|
/**
|
|
7
7
|
* Make culture
|
|
8
|
+
* @param cultureMaker Culture maker
|
|
8
9
|
* @param resources Resources
|
|
9
10
|
* @returns Culture
|
|
10
11
|
*/
|
|
11
|
-
function make(...resources: (object | (() => Promise<object>))[]): DataTypes.CultureDefinition<DataTypes.StringRecord>;
|
|
12
|
+
function make(cultureMaker: typeof DomUtils.zhHans, ...resources: (object | (() => Promise<object>))[]): DataTypes.CultureDefinition<DataTypes.StringRecord>;
|
|
12
13
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DomUtils } from '@etsoo/shared';
|
|
2
1
|
/**
|
|
3
2
|
* Culture utilities
|
|
4
3
|
*/
|
|
@@ -6,11 +5,12 @@ export var CultureUtils;
|
|
|
6
5
|
(function (CultureUtils) {
|
|
7
6
|
/**
|
|
8
7
|
* Make culture
|
|
8
|
+
* @param cultureMaker Culture maker
|
|
9
9
|
* @param resources Resources
|
|
10
10
|
* @returns Culture
|
|
11
11
|
*/
|
|
12
|
-
function make(...resources) {
|
|
13
|
-
return
|
|
12
|
+
function make(cultureMaker, ...resources) {
|
|
13
|
+
return cultureMaker(async () => {
|
|
14
14
|
const rs = await Promise.all(resources.map((resource) => new Promise((resolve) => {
|
|
15
15
|
if (typeof resource === 'object') {
|
|
16
16
|
resolve(resource);
|
package/lib/mjs/i18n/en.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { DomUtils } from '@etsoo/shared';
|
|
1
2
|
import { CultureUtils } from './CultureUtils';
|
|
2
3
|
/**
|
|
3
4
|
* Get en neutral culture
|
|
4
5
|
* @param localResources Local resources
|
|
5
6
|
* @returns Full culture
|
|
6
7
|
*/
|
|
7
|
-
export const en = (...resources) => CultureUtils.make(import('./en.json'), ...resources);
|
|
8
|
+
export const en = (...resources) => CultureUtils.make(DomUtils.en, import('./en.json'), ...resources);
|
package/lib/mjs/i18n/zhHans.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { DomUtils } from '@etsoo/shared';
|
|
1
2
|
import { CultureUtils } from './CultureUtils';
|
|
2
3
|
/**
|
|
3
4
|
* Get zh-Hans neutral cultrue
|
|
4
5
|
* @param localResources Local resources
|
|
5
6
|
* @returns Full culture
|
|
6
7
|
*/
|
|
7
|
-
export const zhHans = (...resources) => CultureUtils.make(import('./zh-Hans.json'), ...resources);
|
|
8
|
+
export const zhHans = (...resources) => CultureUtils.make(DomUtils.zhHans, import('./zh-Hans.json'), ...resources);
|
package/lib/mjs/i18n/zhHant.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { DomUtils } from '@etsoo/shared';
|
|
1
2
|
import { CultureUtils } from './CultureUtils';
|
|
2
3
|
/**
|
|
3
4
|
* Get zh-Hant neutral cultrue
|
|
4
5
|
* @param localResources Local resources
|
|
5
6
|
* @returns Full culture
|
|
6
7
|
*/
|
|
7
|
-
export const zhHant = (...resources) => CultureUtils.make(import('./zh-Hant.json'), ...resources);
|
|
8
|
+
export const zhHant = (...resources) => CultureUtils.make(DomUtils.zhHant, import('./zh-Hant.json'), ...resources);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/appscript",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.51",
|
|
4
4
|
"description": "Applications shared TypeScript framework",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
},
|
|
53
53
|
"homepage": "https://github.com/ETSOO/AppScript#readme",
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@etsoo/notificationbase": "^1.1.
|
|
56
|
-
"@etsoo/restclient": "^1.1.
|
|
57
|
-
"@etsoo/shared": "^1.2.
|
|
55
|
+
"@etsoo/notificationbase": "^1.1.50",
|
|
56
|
+
"@etsoo/restclient": "^1.1.12",
|
|
57
|
+
"@etsoo/shared": "^1.2.49",
|
|
58
58
|
"crypto-js": "^4.2.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
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
|
/**
|
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
|
|
package/src/i18n/CultureUtils.ts
CHANGED
|
@@ -6,11 +6,15 @@ import { DataTypes, DomUtils } from '@etsoo/shared';
|
|
|
6
6
|
export namespace CultureUtils {
|
|
7
7
|
/**
|
|
8
8
|
* Make culture
|
|
9
|
+
* @param cultureMaker Culture maker
|
|
9
10
|
* @param resources Resources
|
|
10
11
|
* @returns Culture
|
|
11
12
|
*/
|
|
12
|
-
export function make(
|
|
13
|
-
|
|
13
|
+
export function make(
|
|
14
|
+
cultureMaker: typeof DomUtils.zhHans,
|
|
15
|
+
...resources: (object | (() => Promise<object>))[]
|
|
16
|
+
) {
|
|
17
|
+
return cultureMaker(async () => {
|
|
14
18
|
const rs = await Promise.all(
|
|
15
19
|
resources.map(
|
|
16
20
|
(resource) =>
|
package/src/i18n/en.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DomUtils } from '@etsoo/shared';
|
|
1
2
|
import { CultureUtils } from './CultureUtils';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -6,4 +7,4 @@ import { CultureUtils } from './CultureUtils';
|
|
|
6
7
|
* @returns Full culture
|
|
7
8
|
*/
|
|
8
9
|
export const en = (...resources: (object | (() => Promise<object>))[]) =>
|
|
9
|
-
CultureUtils.make(import('./en.json'), ...resources);
|
|
10
|
+
CultureUtils.make(DomUtils.en, import('./en.json'), ...resources);
|
package/src/i18n/zhHans.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DomUtils } from '@etsoo/shared';
|
|
1
2
|
import { CultureUtils } from './CultureUtils';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -6,4 +7,4 @@ import { CultureUtils } from './CultureUtils';
|
|
|
6
7
|
* @returns Full culture
|
|
7
8
|
*/
|
|
8
9
|
export const zhHans = (...resources: (object | (() => Promise<object>))[]) =>
|
|
9
|
-
CultureUtils.make(import('./zh-Hans.json'), ...resources);
|
|
10
|
+
CultureUtils.make(DomUtils.zhHans, import('./zh-Hans.json'), ...resources);
|
package/src/i18n/zhHant.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DomUtils } from '@etsoo/shared';
|
|
1
2
|
import { CultureUtils } from './CultureUtils';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -6,4 +7,4 @@ import { CultureUtils } from './CultureUtils';
|
|
|
6
7
|
* @returns Full culture
|
|
7
8
|
*/
|
|
8
9
|
export const zhHant = (...resources: (object | (() => Promise<object>))[]) =>
|
|
9
|
-
CultureUtils.make(import('./zh-Hant.json'), ...resources);
|
|
10
|
+
CultureUtils.make(DomUtils.zhHant, import('./zh-Hant.json'), ...resources);
|