@etsoo/appscript 1.1.6 → 1.1.7
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/.github/workflows/main.yml +1 -1
- package/README.md +63 -13
- package/lib/cjs/address/AddressUtils.d.ts +1 -1
- package/lib/cjs/address/AddressUtils.js +7 -10
- package/lib/cjs/app/AppSettings.d.ts +1 -1
- package/lib/cjs/app/CoreApp.d.ts +4 -4
- package/lib/cjs/app/CoreApp.js +7 -6
- package/lib/cjs/app/ExternalSettings.d.ts +1 -1
- package/lib/cjs/business/BusinessTax.js +7 -1
- package/lib/cjs/business/BusinessUtils.js +2 -3
- package/lib/cjs/dto/IdDto.d.ts +1 -1
- package/lib/cjs/dto/IdLabelDto.d.ts +1 -1
- package/lib/cjs/dto/UpdateDto.d.ts +1 -1
- package/lib/mjs/address/AddressUtils.d.ts +1 -1
- package/lib/mjs/address/AddressUtils.js +8 -11
- package/lib/mjs/app/AppSettings.d.ts +1 -1
- package/lib/mjs/app/CoreApp.d.ts +4 -4
- package/lib/mjs/app/CoreApp.js +7 -6
- package/lib/mjs/app/ExternalSettings.d.ts +1 -1
- package/lib/mjs/business/BusinessTax.js +7 -1
- package/lib/mjs/business/BusinessUtils.js +3 -4
- package/lib/mjs/dto/IdDto.d.ts +1 -1
- package/lib/mjs/dto/IdLabelDto.d.ts +1 -1
- package/lib/mjs/dto/UpdateDto.d.ts +1 -1
- package/package.json +14 -14
- package/src/address/AddressUtils.ts +3 -3
- package/src/app/AppSettings.ts +1 -1
- package/src/app/CoreApp.ts +7 -5
- package/src/app/ExternalSettings.ts +1 -1
- package/src/business/BusinessTax.ts +7 -1
- package/src/business/BusinessUtils.ts +2 -2
- package/src/dto/IdDto.ts +1 -1
- package/src/dto/IdLabelDto.ts +1 -1
- package/src/dto/UpdateDto.ts +1 -1
- package/tsconfig.cjs.json +1 -1
- package/tsconfig.json +1 -1
|
@@ -28,7 +28,7 @@ jobs:
|
|
|
28
28
|
# Setup .npmrc file to publish to npm
|
|
29
29
|
- uses: actions/setup-node@v1
|
|
30
30
|
with:
|
|
31
|
-
node-version: '14.
|
|
31
|
+
node-version: '14.18'
|
|
32
32
|
registry-url: 'https://registry.npmjs.org'
|
|
33
33
|
|
|
34
34
|
# Named after Continuous Integration, installs dependencies directly from package-lock.json
|
package/README.md
CHANGED
|
@@ -17,8 +17,33 @@ $ yarn add @etsoo/appscript
|
|
|
17
17
|
|
|
18
18
|
## Structure
|
|
19
19
|
|
|
20
|
+
### address - Address (region) related
|
|
21
|
+
|
|
22
|
+
#### AddressContinent.ts ####
|
|
23
|
+
- AddressContinent - Continent Enum
|
|
24
|
+
|
|
25
|
+
#### AddressRegion.ts ####
|
|
26
|
+
- IAddressRegion - Country or region interface
|
|
27
|
+
- AddressRegion - Address or region
|
|
28
|
+
|
|
29
|
+
#### AddressUtils.ts ####
|
|
30
|
+
- getContinents - Get all continents
|
|
31
|
+
- getRegion - Get region from regions and detected region and language
|
|
32
|
+
|
|
20
33
|
### app - Application related
|
|
21
34
|
|
|
35
|
+
#### AppSettings.ts ####
|
|
36
|
+
- IAppSettings - App settings interface
|
|
37
|
+
|
|
38
|
+
#### CoreApp.ts ####
|
|
39
|
+
- IDetectIPCallback - Detect IP callback interface
|
|
40
|
+
- ICoreApp - Core application interface
|
|
41
|
+
- CoreApp - Core application
|
|
42
|
+
|
|
43
|
+
#### ExternalSettings.ts ####
|
|
44
|
+
- IExternalSettings - External settings items
|
|
45
|
+
- IExternalSettingsHost - External settings host passed by external script
|
|
46
|
+
|
|
22
47
|
### bridges - Works with Electron
|
|
23
48
|
|
|
24
49
|
#### ElectronBridge.ts ####
|
|
@@ -28,35 +53,60 @@ $ yarn add @etsoo/appscript
|
|
|
28
53
|
- IAppData - App data interface.
|
|
29
54
|
|
|
30
55
|
#### IBridge.ts ####
|
|
31
|
-
- IBridgeUnsubscribe - Bridge unsubscribe interface
|
|
32
|
-
- IBridgeListener - Bridge listener interface
|
|
33
|
-
- IBridge - Bridge interface
|
|
56
|
+
- IBridgeUnsubscribe - Bridge unsubscribe interface
|
|
57
|
+
- IBridgeListener - Bridge listener interface
|
|
58
|
+
- IBridge - Bridge interface
|
|
59
|
+
|
|
60
|
+
### business - Business logics
|
|
61
|
+
|
|
62
|
+
#### BusinessTax.ts ####
|
|
63
|
+
- IBusinessTax - Business tax interface
|
|
64
|
+
- BusinessTax - Business tax
|
|
65
|
+
|
|
66
|
+
#### BusinessUtils.ts ####
|
|
67
|
+
- addIdLabelBlankItem - Add blank item to id/label data array
|
|
68
|
+
- getUnitLabel - Get product unit's label
|
|
69
|
+
- getUnits - Get all product units
|
|
70
|
+
|
|
71
|
+
#### ProductUnit.ts ####
|
|
72
|
+
- ProductUnit - Product units enum
|
|
73
|
+
|
|
74
|
+
### dto - Data transfer object
|
|
75
|
+
|
|
76
|
+
#### IdDto.ts ####
|
|
77
|
+
- IdDto - Dto with id field
|
|
78
|
+
|
|
79
|
+
#### IdLabelDto.ts ####
|
|
80
|
+
- IdLabelDto - Dto with id and label field
|
|
81
|
+
|
|
82
|
+
#### UpdateDto.ts ####
|
|
83
|
+
- UpdateDto - Dto with id and changedFields
|
|
34
84
|
|
|
35
85
|
### result - API action result
|
|
36
86
|
|
|
37
87
|
#### ActionResult.ts ####
|
|
38
|
-
- ActionResult - API call action result extends IActionResult
|
|
88
|
+
- ActionResult - API call action result extends IActionResult
|
|
39
89
|
|
|
40
90
|
#### ActionResultError.ts ####
|
|
41
91
|
- ActionResultError - Action result to error type.
|
|
42
92
|
|
|
43
93
|
#### IActionResult.ts ####
|
|
44
|
-
- IResultData - Result data interface
|
|
45
|
-
- IdResultData - extends IResultData for 'id' included return data
|
|
46
|
-
- IResultErrors - Result errors interface
|
|
47
|
-
- IActionResult - Action result interface
|
|
94
|
+
- IResultData - Result data interface
|
|
95
|
+
- IdResultData - extends IResultData for 'id' included return data
|
|
96
|
+
- IResultErrors - Result errors interface
|
|
97
|
+
- IActionResult - Action result interface
|
|
48
98
|
- ActionResultId - Action result with id data
|
|
49
99
|
|
|
50
100
|
### state - State management
|
|
51
101
|
|
|
52
|
-
####
|
|
53
|
-
-
|
|
54
|
-
-
|
|
102
|
+
#### Culture.ts ####
|
|
103
|
+
- ICulture - Culture resources state, simple i18n solution
|
|
104
|
+
- ICultureGet - Culture get delegate
|
|
55
105
|
|
|
56
106
|
#### State.ts ####
|
|
57
107
|
- IState - state interface.
|
|
58
|
-
- IAction - state action interface
|
|
108
|
+
- IAction - state action interface
|
|
59
109
|
|
|
60
110
|
#### User.ts ####
|
|
61
111
|
- IUserData - User basic data.
|
|
62
|
-
- IUser - extends IState for user state
|
|
112
|
+
- IUser - extends IState for user state
|
|
@@ -13,7 +13,7 @@ export declare namespace AddressUtils {
|
|
|
13
13
|
*/
|
|
14
14
|
function getContinents(func: ICultureGet, isNumberKey?: boolean): IdLabelDto[];
|
|
15
15
|
/**
|
|
16
|
-
* Get region
|
|
16
|
+
* Get region from regions and detected region and language
|
|
17
17
|
* @param regions Supported regions
|
|
18
18
|
* @param detectedRegion Detected region
|
|
19
19
|
* @param detectedLanguage Detected language
|
|
@@ -16,19 +16,16 @@ var AddressUtils;
|
|
|
16
16
|
* @returns Continents
|
|
17
17
|
*/
|
|
18
18
|
function getContinents(func, isNumberKey = false) {
|
|
19
|
-
return shared_1.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
label: (_a = func('continent' + key)) !== null && _a !== void 0 ? _a : key
|
|
26
|
-
});
|
|
27
|
-
});
|
|
19
|
+
return shared_1.DataTypes.getEnumKeys(AddressContinent_1.AddressContinent).map((key) => ({
|
|
20
|
+
id: isNumberKey
|
|
21
|
+
? AddressContinent_1.AddressContinent[key]
|
|
22
|
+
: key,
|
|
23
|
+
label: func('continent' + key) ?? key
|
|
24
|
+
}));
|
|
28
25
|
}
|
|
29
26
|
AddressUtils.getContinents = getContinents;
|
|
30
27
|
/**
|
|
31
|
-
* Get region
|
|
28
|
+
* Get region from regions and detected region and language
|
|
32
29
|
* @param regions Supported regions
|
|
33
30
|
* @param detectedRegion Detected region
|
|
34
31
|
* @param detectedLanguage Detected language
|
|
@@ -3,7 +3,7 @@ import { DataTypes } from '@etsoo/shared';
|
|
|
3
3
|
import { AddressRegion } from '../address/AddressRegion';
|
|
4
4
|
import { IExternalSettings } from './ExternalSettings';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* App settings interface
|
|
7
7
|
*/
|
|
8
8
|
export interface IAppSettings extends IExternalSettings {
|
|
9
9
|
/**
|
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
30
30
|
/**
|
|
31
31
|
* Label delegate
|
|
32
32
|
*/
|
|
33
|
-
readonly labelDelegate: <T
|
|
33
|
+
readonly labelDelegate: <T = string>(key: string) => T | undefined;
|
|
34
34
|
/**
|
|
35
35
|
* Culture, like zh-CN
|
|
36
36
|
*/
|
|
@@ -114,7 +114,7 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
114
114
|
* @param key key
|
|
115
115
|
* @returns Resource
|
|
116
116
|
*/
|
|
117
|
-
get<T
|
|
117
|
+
get<T = string>(key: string): T | undefined;
|
|
118
118
|
/**
|
|
119
119
|
* Get multiple culture labels
|
|
120
120
|
* @param keys Keys
|
|
@@ -203,7 +203,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
203
203
|
/**
|
|
204
204
|
* Label delegate
|
|
205
205
|
*/
|
|
206
|
-
get labelDelegate(): <T
|
|
206
|
+
get labelDelegate(): <T = string>(key: string) => T | undefined;
|
|
207
207
|
/**
|
|
208
208
|
* IP data
|
|
209
209
|
*/
|
|
@@ -297,7 +297,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
297
297
|
* @param key key
|
|
298
298
|
* @returns Resource
|
|
299
299
|
*/
|
|
300
|
-
get<T
|
|
300
|
+
get<T = string>(key: string): T | undefined;
|
|
301
301
|
/**
|
|
302
302
|
* Get multiple culture labels
|
|
303
303
|
* @param keys Keys
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -194,8 +194,7 @@ class CoreApp {
|
|
|
194
194
|
}
|
|
195
195
|
// Detect IP callbacks
|
|
196
196
|
detectIPCallbacks() {
|
|
197
|
-
|
|
198
|
-
(_a = this.ipDetectCallbacks) === null || _a === void 0 ? void 0 : _a.forEach((f) => f());
|
|
197
|
+
this.ipDetectCallbacks?.forEach((f) => f());
|
|
199
198
|
}
|
|
200
199
|
/**
|
|
201
200
|
* Format date to string
|
|
@@ -206,7 +205,7 @@ class CoreApp {
|
|
|
206
205
|
*/
|
|
207
206
|
formatDate(input, options, timeZone) {
|
|
208
207
|
const { currentCulture, timeZone: defaultTimeZone } = this.settings;
|
|
209
|
-
timeZone
|
|
208
|
+
timeZone ?? (timeZone = defaultTimeZone);
|
|
210
209
|
return shared_1.DateUtils.format(input, currentCulture.name, options, timeZone);
|
|
211
210
|
}
|
|
212
211
|
/**
|
|
@@ -245,6 +244,9 @@ class CoreApp {
|
|
|
245
244
|
const value = this.settings.currentCulture.resources[key];
|
|
246
245
|
if (value == null)
|
|
247
246
|
return undefined;
|
|
247
|
+
// No strict type convertion here
|
|
248
|
+
// Make sure the type is strictly match
|
|
249
|
+
// Otherwise even request number, may still return the source string type
|
|
248
250
|
return value;
|
|
249
251
|
}
|
|
250
252
|
/**
|
|
@@ -253,7 +255,7 @@ class CoreApp {
|
|
|
253
255
|
*/
|
|
254
256
|
getLabels(...keys) {
|
|
255
257
|
const init = {};
|
|
256
|
-
return keys.reduce((a, v) =>
|
|
258
|
+
return keys.reduce((a, v) => ({ ...a, [v]: this.get(v) ?? '' }), init);
|
|
257
259
|
}
|
|
258
260
|
/**
|
|
259
261
|
* Get cached token
|
|
@@ -294,9 +296,8 @@ class CoreApp {
|
|
|
294
296
|
* @returns Time zone
|
|
295
297
|
*/
|
|
296
298
|
getTimeZone() {
|
|
297
|
-
var _a, _b;
|
|
298
299
|
// settings.timeZone = Utils.getTimeZone()
|
|
299
|
-
return
|
|
300
|
+
return this.settings.timeZone ?? this.ipData?.timezone;
|
|
300
301
|
}
|
|
301
302
|
/**
|
|
302
303
|
* Callback where exit a page
|
|
@@ -52,4 +52,10 @@ BusinessTax.HK = new BusinessTax('HK', 'BRN', '00000000');
|
|
|
52
52
|
/**
|
|
53
53
|
* All countries and regions
|
|
54
54
|
*/
|
|
55
|
-
BusinessTax.all = [
|
|
55
|
+
BusinessTax.all = [
|
|
56
|
+
BusinessTax.CN,
|
|
57
|
+
BusinessTax.NZ,
|
|
58
|
+
BusinessTax.US,
|
|
59
|
+
BusinessTax.CA,
|
|
60
|
+
BusinessTax.HK
|
|
61
|
+
];
|
|
@@ -24,8 +24,7 @@ var BusinessUtils;
|
|
|
24
24
|
BusinessUtils.addIdLabelBlankItem = addIdLabelBlankItem;
|
|
25
25
|
// Get unit label by key
|
|
26
26
|
function getUnitLabelByKey(func, key) {
|
|
27
|
-
|
|
28
|
-
return (_a = func('unit' + key)) !== null && _a !== void 0 ? _a : key;
|
|
27
|
+
return func('unit' + key) ?? key;
|
|
29
28
|
}
|
|
30
29
|
/**
|
|
31
30
|
* Get product unit's label
|
|
@@ -45,7 +44,7 @@ var BusinessUtils;
|
|
|
45
44
|
* @returns Units
|
|
46
45
|
*/
|
|
47
46
|
function getUnits(func) {
|
|
48
|
-
return shared_1.
|
|
47
|
+
return shared_1.DataTypes.getEnumKeys(ProductUnit_1.ProductUnit).map((key) => ({
|
|
49
48
|
id: ProductUnit_1.ProductUnit[key],
|
|
50
49
|
label: getUnitLabelByKey(func, key)
|
|
51
50
|
}));
|
package/lib/cjs/dto/IdDto.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare namespace AddressUtils {
|
|
|
13
13
|
*/
|
|
14
14
|
function getContinents(func: ICultureGet, isNumberKey?: boolean): IdLabelDto[];
|
|
15
15
|
/**
|
|
16
|
-
* Get region
|
|
16
|
+
* Get region from regions and detected region and language
|
|
17
17
|
* @param regions Supported regions
|
|
18
18
|
* @param detectedRegion Detected region
|
|
19
19
|
* @param detectedLanguage Detected language
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DataTypes } from '@etsoo/shared';
|
|
2
2
|
import { AddressRegion } from '..';
|
|
3
3
|
import { AddressContinent } from './AddressContinent';
|
|
4
4
|
/**
|
|
@@ -13,19 +13,16 @@ export var AddressUtils;
|
|
|
13
13
|
* @returns Continents
|
|
14
14
|
*/
|
|
15
15
|
function getContinents(func, isNumberKey = false) {
|
|
16
|
-
return
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
label: (_a = func('continent' + key)) !== null && _a !== void 0 ? _a : key
|
|
23
|
-
});
|
|
24
|
-
});
|
|
16
|
+
return DataTypes.getEnumKeys(AddressContinent).map((key) => ({
|
|
17
|
+
id: isNumberKey
|
|
18
|
+
? AddressContinent[key]
|
|
19
|
+
: key,
|
|
20
|
+
label: func('continent' + key) ?? key
|
|
21
|
+
}));
|
|
25
22
|
}
|
|
26
23
|
AddressUtils.getContinents = getContinents;
|
|
27
24
|
/**
|
|
28
|
-
* Get region
|
|
25
|
+
* Get region from regions and detected region and language
|
|
29
26
|
* @param regions Supported regions
|
|
30
27
|
* @param detectedRegion Detected region
|
|
31
28
|
* @param detectedLanguage Detected language
|
|
@@ -3,7 +3,7 @@ import { DataTypes } from '@etsoo/shared';
|
|
|
3
3
|
import { AddressRegion } from '../address/AddressRegion';
|
|
4
4
|
import { IExternalSettings } from './ExternalSettings';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* App settings interface
|
|
7
7
|
*/
|
|
8
8
|
export interface IAppSettings extends IExternalSettings {
|
|
9
9
|
/**
|
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
30
30
|
/**
|
|
31
31
|
* Label delegate
|
|
32
32
|
*/
|
|
33
|
-
readonly labelDelegate: <T
|
|
33
|
+
readonly labelDelegate: <T = string>(key: string) => T | undefined;
|
|
34
34
|
/**
|
|
35
35
|
* Culture, like zh-CN
|
|
36
36
|
*/
|
|
@@ -114,7 +114,7 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
114
114
|
* @param key key
|
|
115
115
|
* @returns Resource
|
|
116
116
|
*/
|
|
117
|
-
get<T
|
|
117
|
+
get<T = string>(key: string): T | undefined;
|
|
118
118
|
/**
|
|
119
119
|
* Get multiple culture labels
|
|
120
120
|
* @param keys Keys
|
|
@@ -203,7 +203,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
203
203
|
/**
|
|
204
204
|
* Label delegate
|
|
205
205
|
*/
|
|
206
|
-
get labelDelegate(): <T
|
|
206
|
+
get labelDelegate(): <T = string>(key: string) => T | undefined;
|
|
207
207
|
/**
|
|
208
208
|
* IP data
|
|
209
209
|
*/
|
|
@@ -297,7 +297,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
297
297
|
* @param key key
|
|
298
298
|
* @returns Resource
|
|
299
299
|
*/
|
|
300
|
-
get<T
|
|
300
|
+
get<T = string>(key: string): T | undefined;
|
|
301
301
|
/**
|
|
302
302
|
* Get multiple culture labels
|
|
303
303
|
* @param keys Keys
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -191,8 +191,7 @@ export class CoreApp {
|
|
|
191
191
|
}
|
|
192
192
|
// Detect IP callbacks
|
|
193
193
|
detectIPCallbacks() {
|
|
194
|
-
|
|
195
|
-
(_a = this.ipDetectCallbacks) === null || _a === void 0 ? void 0 : _a.forEach((f) => f());
|
|
194
|
+
this.ipDetectCallbacks?.forEach((f) => f());
|
|
196
195
|
}
|
|
197
196
|
/**
|
|
198
197
|
* Format date to string
|
|
@@ -203,7 +202,7 @@ export class CoreApp {
|
|
|
203
202
|
*/
|
|
204
203
|
formatDate(input, options, timeZone) {
|
|
205
204
|
const { currentCulture, timeZone: defaultTimeZone } = this.settings;
|
|
206
|
-
timeZone
|
|
205
|
+
timeZone ?? (timeZone = defaultTimeZone);
|
|
207
206
|
return DateUtils.format(input, currentCulture.name, options, timeZone);
|
|
208
207
|
}
|
|
209
208
|
/**
|
|
@@ -242,6 +241,9 @@ export class CoreApp {
|
|
|
242
241
|
const value = this.settings.currentCulture.resources[key];
|
|
243
242
|
if (value == null)
|
|
244
243
|
return undefined;
|
|
244
|
+
// No strict type convertion here
|
|
245
|
+
// Make sure the type is strictly match
|
|
246
|
+
// Otherwise even request number, may still return the source string type
|
|
245
247
|
return value;
|
|
246
248
|
}
|
|
247
249
|
/**
|
|
@@ -250,7 +252,7 @@ export class CoreApp {
|
|
|
250
252
|
*/
|
|
251
253
|
getLabels(...keys) {
|
|
252
254
|
const init = {};
|
|
253
|
-
return keys.reduce((a, v) =>
|
|
255
|
+
return keys.reduce((a, v) => ({ ...a, [v]: this.get(v) ?? '' }), init);
|
|
254
256
|
}
|
|
255
257
|
/**
|
|
256
258
|
* Get cached token
|
|
@@ -291,9 +293,8 @@ export class CoreApp {
|
|
|
291
293
|
* @returns Time zone
|
|
292
294
|
*/
|
|
293
295
|
getTimeZone() {
|
|
294
|
-
var _a, _b;
|
|
295
296
|
// settings.timeZone = Utils.getTimeZone()
|
|
296
|
-
return
|
|
297
|
+
return this.settings.timeZone ?? this.ipData?.timezone;
|
|
297
298
|
}
|
|
298
299
|
/**
|
|
299
300
|
* Callback where exit a page
|
|
@@ -48,4 +48,10 @@ BusinessTax.HK = new BusinessTax('HK', 'BRN', '00000000');
|
|
|
48
48
|
/**
|
|
49
49
|
* All countries and regions
|
|
50
50
|
*/
|
|
51
|
-
BusinessTax.all = [
|
|
51
|
+
BusinessTax.all = [
|
|
52
|
+
BusinessTax.CN,
|
|
53
|
+
BusinessTax.NZ,
|
|
54
|
+
BusinessTax.US,
|
|
55
|
+
BusinessTax.CA,
|
|
56
|
+
BusinessTax.HK
|
|
57
|
+
];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DataTypes } from '@etsoo/shared';
|
|
2
2
|
import { ProductUnit } from './ProductUnit';
|
|
3
3
|
/**
|
|
4
4
|
* Business utils
|
|
@@ -21,8 +21,7 @@ export var BusinessUtils;
|
|
|
21
21
|
BusinessUtils.addIdLabelBlankItem = addIdLabelBlankItem;
|
|
22
22
|
// Get unit label by key
|
|
23
23
|
function getUnitLabelByKey(func, key) {
|
|
24
|
-
|
|
25
|
-
return (_a = func('unit' + key)) !== null && _a !== void 0 ? _a : key;
|
|
24
|
+
return func('unit' + key) ?? key;
|
|
26
25
|
}
|
|
27
26
|
/**
|
|
28
27
|
* Get product unit's label
|
|
@@ -42,7 +41,7 @@ export var BusinessUtils;
|
|
|
42
41
|
* @returns Units
|
|
43
42
|
*/
|
|
44
43
|
function getUnits(func) {
|
|
45
|
-
return
|
|
44
|
+
return DataTypes.getEnumKeys(ProductUnit).map((key) => ({
|
|
46
45
|
id: ProductUnit[key],
|
|
47
46
|
label: getUnitLabelByKey(func, key)
|
|
48
47
|
}));
|
package/lib/mjs/dto/IdDto.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/appscript",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "Applications shared TypeScript framework",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -47,24 +47,24 @@
|
|
|
47
47
|
},
|
|
48
48
|
"homepage": "https://github.com/ETSOO/NotificationBase#readme",
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@etsoo/notificationbase": "^1.0.
|
|
51
|
-
"@etsoo/restclient": "^1.0.
|
|
52
|
-
"@etsoo/shared": "^1.0.
|
|
50
|
+
"@etsoo/notificationbase": "^1.0.82",
|
|
51
|
+
"@etsoo/restclient": "^1.0.52",
|
|
52
|
+
"@etsoo/shared": "^1.0.49"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@babel/cli": "^7.15.7",
|
|
56
|
-
"@babel/core": "^7.15.
|
|
57
|
-
"@babel/plugin-transform-runtime": "^7.15.
|
|
58
|
-
"@babel/preset-env": "^7.15.
|
|
56
|
+
"@babel/core": "^7.15.8",
|
|
57
|
+
"@babel/plugin-transform-runtime": "^7.15.8",
|
|
58
|
+
"@babel/preset-env": "^7.15.8",
|
|
59
59
|
"@babel/runtime-corejs3": "^7.15.4",
|
|
60
60
|
"@types/jest": "^27.0.2",
|
|
61
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
62
|
-
"@typescript-eslint/parser": "^
|
|
63
|
-
"eslint": "^
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
62
|
+
"@typescript-eslint/parser": "^5.0.0",
|
|
63
|
+
"eslint": "^8.0.1",
|
|
64
64
|
"eslint-config-airbnb-base": "^14.2.1",
|
|
65
|
-
"eslint-plugin-import": "^2.
|
|
66
|
-
"jest": "^27.2.
|
|
67
|
-
"ts-jest": "^27.0.
|
|
68
|
-
"typescript": "^4.4.
|
|
65
|
+
"eslint-plugin-import": "^2.25.2",
|
|
66
|
+
"jest": "^27.2.5",
|
|
67
|
+
"ts-jest": "^27.0.6",
|
|
68
|
+
"typescript": "^4.4.4"
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DataTypes } from '@etsoo/shared';
|
|
2
2
|
import { AddressRegion } from '..';
|
|
3
3
|
import { IdLabelDto } from '../dto/IdLabelDto';
|
|
4
4
|
import { ICultureGet } from '../state/Culture';
|
|
@@ -18,7 +18,7 @@ export namespace AddressUtils {
|
|
|
18
18
|
func: ICultureGet,
|
|
19
19
|
isNumberKey: boolean = false
|
|
20
20
|
): IdLabelDto[] {
|
|
21
|
-
return
|
|
21
|
+
return DataTypes.getEnumKeys(AddressContinent).map((key) => ({
|
|
22
22
|
id: isNumberKey
|
|
23
23
|
? AddressContinent[key as keyof typeof AddressContinent]
|
|
24
24
|
: key,
|
|
@@ -27,7 +27,7 @@ export namespace AddressUtils {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* Get region
|
|
30
|
+
* Get region from regions and detected region and language
|
|
31
31
|
* @param regions Supported regions
|
|
32
32
|
* @param detectedRegion Detected region
|
|
33
33
|
* @param detectedLanguage Detected language
|
package/src/app/AppSettings.ts
CHANGED
package/src/app/CoreApp.ts
CHANGED
|
@@ -46,9 +46,7 @@ export interface ICoreApp<
|
|
|
46
46
|
/**
|
|
47
47
|
* Label delegate
|
|
48
48
|
*/
|
|
49
|
-
readonly labelDelegate: <T
|
|
50
|
-
key: string
|
|
51
|
-
) => T | undefined;
|
|
49
|
+
readonly labelDelegate: <T = string>(key: string) => T | undefined;
|
|
52
50
|
|
|
53
51
|
/**
|
|
54
52
|
* Culture, like zh-CN
|
|
@@ -159,7 +157,7 @@ export interface ICoreApp<
|
|
|
159
157
|
* @param key key
|
|
160
158
|
* @returns Resource
|
|
161
159
|
*/
|
|
162
|
-
get<T
|
|
160
|
+
get<T = string>(key: string): T | undefined;
|
|
163
161
|
|
|
164
162
|
/**
|
|
165
163
|
* Get multiple culture labels
|
|
@@ -560,9 +558,13 @@ export abstract class CoreApp<
|
|
|
560
558
|
* @param key key
|
|
561
559
|
* @returns Resource
|
|
562
560
|
*/
|
|
563
|
-
get<T
|
|
561
|
+
get<T = string>(key: string): T | undefined {
|
|
564
562
|
const value = this.settings.currentCulture.resources[key];
|
|
565
563
|
if (value == null) return undefined;
|
|
564
|
+
|
|
565
|
+
// No strict type convertion here
|
|
566
|
+
// Make sure the type is strictly match
|
|
567
|
+
// Otherwise even request number, may still return the source string type
|
|
566
568
|
return value as T;
|
|
567
569
|
}
|
|
568
570
|
|
|
@@ -58,7 +58,13 @@ export class BusinessTax implements IBusinessTax {
|
|
|
58
58
|
/**
|
|
59
59
|
* All countries and regions
|
|
60
60
|
*/
|
|
61
|
-
static all = [
|
|
61
|
+
static all = [
|
|
62
|
+
BusinessTax.CN,
|
|
63
|
+
BusinessTax.NZ,
|
|
64
|
+
BusinessTax.US,
|
|
65
|
+
BusinessTax.CA,
|
|
66
|
+
BusinessTax.HK
|
|
67
|
+
];
|
|
62
68
|
|
|
63
69
|
/**
|
|
64
70
|
* Get country or region by id
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DataTypes } from '@etsoo/shared';
|
|
2
2
|
import { IdLabelDto } from '../dto/IdLabelDto';
|
|
3
3
|
import { ICultureGet } from '../state/Culture';
|
|
4
4
|
import { ProductUnit } from './ProductUnit';
|
|
@@ -47,7 +47,7 @@ export namespace BusinessUtils {
|
|
|
47
47
|
* @returns Units
|
|
48
48
|
*/
|
|
49
49
|
export function getUnits(func: ICultureGet): IdLabelDto[] {
|
|
50
|
-
return
|
|
50
|
+
return DataTypes.getEnumKeys(ProductUnit).map((key) => ({
|
|
51
51
|
id: ProductUnit[key as keyof typeof ProductUnit],
|
|
52
52
|
label: getUnitLabelByKey(func, key)
|
|
53
53
|
}));
|
package/src/dto/IdDto.ts
CHANGED
package/src/dto/IdLabelDto.ts
CHANGED
package/src/dto/UpdateDto.ts
CHANGED
package/tsconfig.cjs.json
CHANGED