@etsoo/appscript 1.3.1 → 1.3.3
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/README.md +0 -1
- package/__tests__/app/CoreApp.ts +54 -16
- package/lib/cjs/address/AddressContinent.d.ts +5 -1
- package/lib/cjs/address/AddressContinent.js +1 -1
- package/lib/cjs/address/AddressRegion.d.ts +31 -15
- package/lib/cjs/address/AddressRegion.js +3 -2
- package/lib/cjs/address/AddressState.d.ts +17 -0
- package/lib/cjs/address/AddressState.js +2 -0
- package/lib/cjs/address/AddressUtils.d.ts +1 -17
- package/lib/cjs/address/AddressUtils.js +4 -35
- package/lib/cjs/app/CoreApp.d.ts +7 -21
- package/lib/cjs/app/CoreApp.js +16 -46
- package/lib/cjs/app/ExternalSettings.d.ts +1 -0
- package/lib/cjs/app/ExternalSettings.js +16 -10
- package/lib/cjs/app/IApp.d.ts +7 -21
- package/lib/cjs/business/BusinessUtils.d.ts +1 -43
- package/lib/cjs/business/BusinessUtils.js +0 -72
- package/lib/cjs/business/Currency.d.ts +8 -0
- package/lib/cjs/business/Currency.js +18 -0
- package/lib/cjs/erp/AddressApi.d.ts +44 -0
- package/lib/cjs/erp/AddressApi.js +105 -0
- package/lib/cjs/erp/OrgApi.d.ts +26 -0
- package/lib/cjs/erp/OrgApi.js +43 -0
- package/lib/cjs/erp/PublicApi.d.ts +81 -0
- package/lib/cjs/erp/PublicApi.js +124 -0
- package/lib/cjs/erp/dto/CurrencyDto.d.ts +6 -0
- package/lib/cjs/erp/dto/CurrencyDto.js +2 -0
- package/lib/cjs/erp/dto/ExchangeRateDto.d.ts +13 -0
- package/lib/cjs/erp/dto/ExchangeRateDto.js +2 -0
- package/lib/cjs/erp/dto/ExchangeRateHistoryDto.d.ts +8 -0
- package/lib/cjs/erp/dto/ExchangeRateHistoryDto.js +2 -0
- package/lib/cjs/erp/dto/PublicProductDto.d.ts +35 -0
- package/lib/cjs/erp/dto/PublicProductDto.js +2 -0
- package/lib/cjs/i18n/en-US.json +1 -0
- package/lib/cjs/i18n/zh-CN.json +1 -0
- package/lib/cjs/i18n/zh-HK.json +1 -0
- package/lib/cjs/index.d.ts +5 -0
- package/lib/cjs/index.js +6 -0
- package/lib/mjs/address/AddressContinent.d.ts +5 -1
- package/lib/mjs/address/AddressContinent.js +1 -1
- package/lib/mjs/address/AddressRegion.d.ts +31 -15
- package/lib/mjs/address/AddressRegion.js +3 -2
- package/lib/mjs/address/AddressState.d.ts +17 -0
- package/lib/mjs/address/AddressState.js +1 -0
- package/lib/mjs/address/AddressUtils.d.ts +1 -17
- package/lib/mjs/address/AddressUtils.js +1 -32
- package/lib/mjs/app/CoreApp.d.ts +7 -21
- package/lib/mjs/app/CoreApp.js +16 -46
- package/lib/mjs/app/ExternalSettings.d.ts +1 -0
- package/lib/mjs/app/ExternalSettings.js +16 -10
- package/lib/mjs/app/IApp.d.ts +7 -21
- package/lib/mjs/business/BusinessUtils.d.ts +1 -43
- package/lib/mjs/business/BusinessUtils.js +0 -72
- package/lib/mjs/business/Currency.d.ts +8 -0
- package/lib/mjs/business/Currency.js +15 -0
- package/lib/mjs/erp/AddressApi.d.ts +44 -0
- package/lib/mjs/erp/AddressApi.js +78 -0
- package/lib/mjs/erp/OrgApi.d.ts +26 -0
- package/lib/mjs/erp/OrgApi.js +39 -0
- package/lib/mjs/erp/PublicApi.d.ts +81 -0
- package/lib/mjs/erp/PublicApi.js +120 -0
- package/lib/mjs/erp/dto/CurrencyDto.d.ts +6 -0
- package/lib/mjs/erp/dto/CurrencyDto.js +1 -0
- package/lib/mjs/erp/dto/ExchangeRateDto.d.ts +13 -0
- package/lib/mjs/erp/dto/ExchangeRateDto.js +1 -0
- package/lib/mjs/erp/dto/ExchangeRateHistoryDto.d.ts +8 -0
- package/lib/mjs/erp/dto/ExchangeRateHistoryDto.js +1 -0
- package/lib/mjs/erp/dto/PublicProductDto.d.ts +35 -0
- package/lib/mjs/erp/dto/PublicProductDto.js +1 -0
- package/lib/mjs/i18n/en-US.json +1 -0
- package/lib/mjs/i18n/zh-CN.json +1 -0
- package/lib/mjs/i18n/zh-HK.json +1 -0
- package/lib/mjs/index.d.ts +5 -0
- package/lib/mjs/index.js +6 -0
- package/package.json +8 -8
- package/src/address/AddressContinent.ts +6 -1
- package/src/address/AddressRegion.ts +36 -16
- package/src/address/AddressState.ts +19 -0
- package/src/address/AddressUtils.ts +1 -35
- package/src/app/CoreApp.ts +21 -56
- package/src/app/ExternalSettings.ts +17 -13
- package/src/app/IApp.ts +8 -26
- package/src/business/BusinessUtils.ts +1 -105
- package/src/business/Currency.ts +20 -0
- package/src/erp/AddressApi.ts +103 -0
- package/src/erp/OrgApi.ts +45 -0
- package/src/erp/PublicApi.ts +162 -0
- package/src/erp/dto/CurrencyDto.ts +7 -0
- package/src/erp/dto/ExchangeRateDto.ts +14 -0
- package/src/erp/dto/ExchangeRateHistoryDto.ts +9 -0
- package/src/erp/dto/PublicProductDto.ts +41 -0
- package/src/i18n/address.en-US.json +21 -0
- package/src/i18n/address.zh-CN.json +21 -0
- package/src/i18n/address.zh-HK.json +21 -0
- package/src/i18n/en-US.json +1 -0
- package/src/i18n/zh-CN.json +1 -0
- package/src/i18n/zh-HK.json +1 -0
- package/src/index.ts +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/appscript",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"description": "Applications shared TypeScript framework",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@etsoo/notificationbase": "^1.1.12",
|
|
56
56
|
"@etsoo/restclient": "^1.0.74",
|
|
57
|
-
"@etsoo/shared": "^1.1.
|
|
57
|
+
"@etsoo/shared": "^1.1.60",
|
|
58
58
|
"@types/crypto-js": "^4.1.1",
|
|
59
59
|
"crypto-js": "^4.1.1"
|
|
60
60
|
},
|
|
@@ -62,12 +62,12 @@
|
|
|
62
62
|
"@babel/cli": "^7.19.3",
|
|
63
63
|
"@babel/core": "^7.19.3",
|
|
64
64
|
"@babel/plugin-transform-runtime": "^7.19.1",
|
|
65
|
-
"@babel/preset-env": "^7.19.
|
|
66
|
-
"@babel/runtime-corejs3": "^7.19.
|
|
67
|
-
"@types/jest": "^29.1.
|
|
68
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
69
|
-
"@typescript-eslint/parser": "^5.
|
|
70
|
-
"eslint": "^8.
|
|
65
|
+
"@babel/preset-env": "^7.19.4",
|
|
66
|
+
"@babel/runtime-corejs3": "^7.19.4",
|
|
67
|
+
"@types/jest": "^29.1.2",
|
|
68
|
+
"@typescript-eslint/eslint-plugin": "^5.40.0",
|
|
69
|
+
"@typescript-eslint/parser": "^5.40.0",
|
|
70
|
+
"eslint": "^8.25.0",
|
|
71
71
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
72
72
|
"eslint-plugin-import": "^2.26.0",
|
|
73
73
|
"jest": "^29.1.2",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Address continent
|
|
3
3
|
*/
|
|
4
4
|
export enum AddressContinent {
|
|
5
5
|
/// <summary>
|
|
@@ -44,3 +44,8 @@ export enum AddressContinent {
|
|
|
44
44
|
/// </summary>
|
|
45
45
|
SA = 7
|
|
46
46
|
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Address continent ids
|
|
50
|
+
*/
|
|
51
|
+
export type AddressContinentId = keyof typeof AddressContinent;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Currency } from '../business/Currency';
|
|
2
|
+
import { AddressContinent, AddressContinentId } from './AddressContinent';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
+
* Address region in database
|
|
5
6
|
*/
|
|
6
|
-
export interface
|
|
7
|
+
export interface AddressRegionDb {
|
|
7
8
|
/**
|
|
8
9
|
* Id, like CN for China
|
|
9
10
|
* https://www.iban.com/country-codes
|
|
@@ -24,10 +25,10 @@ export interface IAddressRegion {
|
|
|
24
25
|
readonly nid: string;
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
|
-
* Continent
|
|
28
|
-
*
|
|
28
|
+
* Continent id
|
|
29
|
+
* 洲编号
|
|
29
30
|
*/
|
|
30
|
-
readonly
|
|
31
|
+
readonly continentId: AddressContinentId;
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* Phone exit code for international dial, like 00 in China
|
|
@@ -45,19 +46,30 @@ export interface IAddressRegion {
|
|
|
45
46
|
* Currency, like CNY for China's currency
|
|
46
47
|
* 币种
|
|
47
48
|
*/
|
|
48
|
-
readonly currency:
|
|
49
|
+
readonly currency: Currency;
|
|
49
50
|
|
|
50
51
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
52
|
+
* Name
|
|
53
|
+
* 名称
|
|
53
54
|
*/
|
|
54
|
-
|
|
55
|
+
label: string;
|
|
56
|
+
}
|
|
55
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Country or region interface
|
|
60
|
+
*/
|
|
61
|
+
export interface IAddressRegion extends AddressRegionDb {
|
|
56
62
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
63
|
+
* Continent
|
|
64
|
+
* 洲
|
|
65
|
+
*/
|
|
66
|
+
readonly continent: AddressContinent;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Languages
|
|
70
|
+
* 语言
|
|
59
71
|
*/
|
|
60
|
-
|
|
72
|
+
readonly languages: string[];
|
|
61
73
|
}
|
|
62
74
|
|
|
63
75
|
/**
|
|
@@ -269,6 +281,12 @@ export class AddressRegion implements IAddressRegion {
|
|
|
269
281
|
return AddressRegion.all.find((c) => c.id === id);
|
|
270
282
|
}
|
|
271
283
|
|
|
284
|
+
/**
|
|
285
|
+
* Continent id
|
|
286
|
+
* 洲编号
|
|
287
|
+
*/
|
|
288
|
+
readonly continentId: AddressContinentId;
|
|
289
|
+
|
|
272
290
|
// Typescript constructor shorthand
|
|
273
291
|
constructor(
|
|
274
292
|
public id: string,
|
|
@@ -277,8 +295,10 @@ export class AddressRegion implements IAddressRegion {
|
|
|
277
295
|
public continent: AddressContinent,
|
|
278
296
|
public exitCode: string,
|
|
279
297
|
public idd: string,
|
|
280
|
-
public currency:
|
|
298
|
+
public currency: Currency,
|
|
281
299
|
public languages: string[],
|
|
282
|
-
public
|
|
283
|
-
) {
|
|
300
|
+
public label: string = id
|
|
301
|
+
) {
|
|
302
|
+
this.continentId = AddressContinent[continent] as AddressContinentId;
|
|
303
|
+
}
|
|
284
304
|
}
|
|
@@ -1,33 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AddressRegion } from '..';
|
|
3
|
-
import { IdLabelConditional } from '../dto/IdLabelDto';
|
|
4
|
-
import { ICultureGet } from '../state/Culture';
|
|
5
|
-
import { AddressContinent } from './AddressContinent';
|
|
1
|
+
import { AddressRegion } from './AddressRegion';
|
|
6
2
|
|
|
7
3
|
/**
|
|
8
4
|
* Address utils
|
|
9
5
|
*/
|
|
10
6
|
export namespace AddressUtils {
|
|
11
|
-
/**
|
|
12
|
-
* Get all continents
|
|
13
|
-
* @param func Label delegate
|
|
14
|
-
* @param isNumberKey Is number key or key as id
|
|
15
|
-
* @returns Continents
|
|
16
|
-
*/
|
|
17
|
-
export function getContinents<T extends boolean>(
|
|
18
|
-
func: ICultureGet,
|
|
19
|
-
isNumberKey = <T>false
|
|
20
|
-
): IdLabelConditional<T> {
|
|
21
|
-
return <IdLabelConditional<T>>DataTypes.getEnumKeys(
|
|
22
|
-
AddressContinent
|
|
23
|
-
).map((key) => ({
|
|
24
|
-
id: isNumberKey
|
|
25
|
-
? <number>DataTypes.getEnumByKey(AddressContinent, key)!
|
|
26
|
-
: key.toString(),
|
|
27
|
-
label: func('continent' + key) ?? key
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
7
|
/**
|
|
32
8
|
* Get region from regions and detected region and language
|
|
33
9
|
* @param regions Supported regions
|
|
@@ -56,14 +32,4 @@ export namespace AddressUtils {
|
|
|
56
32
|
// Default
|
|
57
33
|
return AddressRegion.getById(regions[0])!;
|
|
58
34
|
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Get region label
|
|
62
|
-
* @param region Region id
|
|
63
|
-
* @param func Label delegate
|
|
64
|
-
* @returns Label
|
|
65
|
-
*/
|
|
66
|
-
export function getRegionLabel(region: string, func: ICultureGet) {
|
|
67
|
-
return func('region' + region) ?? region;
|
|
68
|
-
}
|
|
69
35
|
}
|
package/src/app/CoreApp.ts
CHANGED
|
@@ -30,11 +30,8 @@ import {
|
|
|
30
30
|
SHA3
|
|
31
31
|
} from 'crypto-js';
|
|
32
32
|
import { AddressRegion } from '../address/AddressRegion';
|
|
33
|
-
import { AddressUtils } from '../address/AddressUtils';
|
|
34
33
|
import { BridgeUtils } from '../bridges/BridgeUtils';
|
|
35
|
-
import { BusinessUtils } from '../business/BusinessUtils';
|
|
36
34
|
import { EntityStatus } from '../business/EntityStatus';
|
|
37
|
-
import { ProductUnit } from '../business/ProductUnit';
|
|
38
35
|
import { InitCallDto } from '../dto/InitCallDto';
|
|
39
36
|
import { ActionResultError } from '../result/ActionResultError';
|
|
40
37
|
import { IActionResult } from '../result/IActionResult';
|
|
@@ -98,7 +95,7 @@ export abstract class CoreApp<
|
|
|
98
95
|
readonly fields: IAppFields;
|
|
99
96
|
|
|
100
97
|
/**
|
|
101
|
-
* API
|
|
98
|
+
* API, not recommend to use it directly in code, wrap to separate methods
|
|
102
99
|
*/
|
|
103
100
|
readonly api: IApi;
|
|
104
101
|
|
|
@@ -419,6 +416,9 @@ export abstract class CoreApp<
|
|
|
419
416
|
* @param api Api
|
|
420
417
|
*/
|
|
421
418
|
protected setApi(api: IApi) {
|
|
419
|
+
// Base URL of the API
|
|
420
|
+
api.baseUrl = this.settings.endpoint;
|
|
421
|
+
|
|
422
422
|
// onRequest, show loading or not, rewrite the property to override default action
|
|
423
423
|
api.onRequest = (data) => {
|
|
424
424
|
if (data.showLoading == null || data.showLoading) {
|
|
@@ -743,16 +743,24 @@ export abstract class CoreApp<
|
|
|
743
743
|
|
|
744
744
|
// Hold the current resources
|
|
745
745
|
this.settings.currentCulture = culture;
|
|
746
|
+
}
|
|
746
747
|
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
748
|
+
/**
|
|
749
|
+
* Check language is supported or not, return a valid language when supported
|
|
750
|
+
* @param language Language
|
|
751
|
+
* @returns Result
|
|
752
|
+
*/
|
|
753
|
+
checkLanguage(language?: string) {
|
|
754
|
+
if (language) {
|
|
755
|
+
const item = this.settings.cultures.find(
|
|
756
|
+
(c) =>
|
|
757
|
+
c.name === language || c.compatibleName?.includes(language)
|
|
758
|
+
);
|
|
759
|
+
if (item) return item.name;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
// Default language
|
|
763
|
+
return this.culture;
|
|
756
764
|
}
|
|
757
765
|
|
|
758
766
|
/**
|
|
@@ -1269,16 +1277,6 @@ export abstract class CoreApp<
|
|
|
1269
1277
|
return this.settings.timeZone ?? this.ipData?.timezone;
|
|
1270
1278
|
}
|
|
1271
1279
|
|
|
1272
|
-
/**
|
|
1273
|
-
* Get product unit and repeat option label
|
|
1274
|
-
* @param unit Product unit or repeat option
|
|
1275
|
-
* @param isJoined Add the join label like 'per Kg' for Kg
|
|
1276
|
-
*/
|
|
1277
|
-
getUnitLabel(unit?: ProductUnit, isJoined?: boolean): string {
|
|
1278
|
-
if (unit == null) return '';
|
|
1279
|
-
return BusinessUtils.getUnitLabel(unit, this.labelDelegate, isJoined);
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
1280
|
/**
|
|
1283
1281
|
* Hash message, SHA3 or HmacSHA512, 512 as Base64
|
|
1284
1282
|
* https://cryptojs.gitbook.io/docs/
|
|
@@ -1434,39 +1432,6 @@ export abstract class CoreApp<
|
|
|
1434
1432
|
this.toLoginPage();
|
|
1435
1433
|
}
|
|
1436
1434
|
|
|
1437
|
-
/**
|
|
1438
|
-
* Get organization list
|
|
1439
|
-
* @param items Max items
|
|
1440
|
-
* @param serviceId Service id
|
|
1441
|
-
* @returns Result
|
|
1442
|
-
*/
|
|
1443
|
-
async orgList(items?: number, serviceId?: number) {
|
|
1444
|
-
return await this.api.post<ListType[]>(
|
|
1445
|
-
'Organization/List',
|
|
1446
|
-
{
|
|
1447
|
-
items,
|
|
1448
|
-
serviceId
|
|
1449
|
-
},
|
|
1450
|
-
{ defaultValue: [], showLoading: false }
|
|
1451
|
-
);
|
|
1452
|
-
}
|
|
1453
|
-
|
|
1454
|
-
/**
|
|
1455
|
-
* Switch organization
|
|
1456
|
-
* @param id Organization id
|
|
1457
|
-
* @param serviceId Service id
|
|
1458
|
-
*/
|
|
1459
|
-
async switchOrg(id: number, serviceId?: number) {
|
|
1460
|
-
const api = `Organization/Switch`;
|
|
1461
|
-
const result = await this.api.put<boolean>(api, {
|
|
1462
|
-
id,
|
|
1463
|
-
serviceId,
|
|
1464
|
-
deviceId: this.deviceId
|
|
1465
|
-
});
|
|
1466
|
-
if (result) return await this.refreshToken();
|
|
1467
|
-
return result;
|
|
1468
|
-
}
|
|
1469
|
-
|
|
1470
1435
|
/**
|
|
1471
1436
|
* Go to the login page
|
|
1472
1437
|
* @param tryLogin Try to login again
|
|
@@ -41,21 +41,10 @@ export namespace ExternalSettings {
|
|
|
41
41
|
if (typeof settings === 'object') {
|
|
42
42
|
if (typeof window !== 'undefined') {
|
|
43
43
|
// Host name
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// Empty string returned under Electron
|
|
47
|
-
if (hostname === '') hostname = 'localhost';
|
|
44
|
+
const hostname = globalThis.location.hostname;
|
|
48
45
|
|
|
49
46
|
// replace {hostname}
|
|
50
|
-
|
|
51
|
-
const value = settings[key];
|
|
52
|
-
if (typeof value === 'string') {
|
|
53
|
-
settings[key] = value.replace(
|
|
54
|
-
'{hostname}',
|
|
55
|
-
hostname
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
47
|
+
format(settings, hostname);
|
|
59
48
|
}
|
|
60
49
|
|
|
61
50
|
return settings as IExternalSettings;
|
|
@@ -63,4 +52,19 @@ export namespace ExternalSettings {
|
|
|
63
52
|
}
|
|
64
53
|
return undefined;
|
|
65
54
|
}
|
|
55
|
+
|
|
56
|
+
export function format(settings: any, hostname?: string) {
|
|
57
|
+
// Default hostname
|
|
58
|
+
if (!hostname) hostname = 'localhost';
|
|
59
|
+
|
|
60
|
+
// replace {hostname}
|
|
61
|
+
for (const key in settings) {
|
|
62
|
+
const value = settings[key];
|
|
63
|
+
if (typeof value === 'string') {
|
|
64
|
+
settings[key] = value.replace('{hostname}', hostname);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return settings;
|
|
69
|
+
}
|
|
66
70
|
}
|
package/src/app/IApp.ts
CHANGED
|
@@ -96,7 +96,7 @@ export interface IApp {
|
|
|
96
96
|
readonly fields: IAppFields;
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
|
-
* API
|
|
99
|
+
* API, not recommend to use it directly in code, wrap to separate methods
|
|
100
100
|
*/
|
|
101
101
|
readonly api: IApi;
|
|
102
102
|
|
|
@@ -213,6 +213,13 @@ export interface IApp {
|
|
|
213
213
|
*/
|
|
214
214
|
checkDeviceResult(result: IActionResult): boolean;
|
|
215
215
|
|
|
216
|
+
/**
|
|
217
|
+
* Check language is supported or not
|
|
218
|
+
* @param language Language
|
|
219
|
+
* @returns Result
|
|
220
|
+
*/
|
|
221
|
+
checkLanguage(language?: string): string;
|
|
222
|
+
|
|
216
223
|
/**
|
|
217
224
|
* Clear cache data
|
|
218
225
|
*/
|
|
@@ -405,13 +412,6 @@ export interface IApp {
|
|
|
405
412
|
*/
|
|
406
413
|
getTimeZone(): string | undefined;
|
|
407
414
|
|
|
408
|
-
/**
|
|
409
|
-
* Get product unit and repeat option label
|
|
410
|
-
* @param unit Product unit or repeat option
|
|
411
|
-
* @param isJoined Add the join label like 'per Kg' for Kg
|
|
412
|
-
*/
|
|
413
|
-
getUnitLabel(unit?: ProductUnit, isJoined?: boolean): string;
|
|
414
|
-
|
|
415
415
|
/**
|
|
416
416
|
* Hash message, SHA3 or HmacSHA512, 512 as Base64
|
|
417
417
|
* https://cryptojs.gitbook.io/docs/
|
|
@@ -480,29 +480,11 @@ export interface IApp {
|
|
|
480
480
|
*/
|
|
481
481
|
signout(): Promise<void>;
|
|
482
482
|
|
|
483
|
-
/**
|
|
484
|
-
* Get organization list
|
|
485
|
-
* @param items Max items
|
|
486
|
-
* @param serviceId Service id
|
|
487
|
-
* @returns Result
|
|
488
|
-
*/
|
|
489
|
-
orgList(
|
|
490
|
-
items?: number,
|
|
491
|
-
serviceId?: number
|
|
492
|
-
): Promise<ListType[] | undefined>;
|
|
493
|
-
|
|
494
483
|
/**
|
|
495
484
|
* Persist settings to source when application exit
|
|
496
485
|
*/
|
|
497
486
|
persist(): void;
|
|
498
487
|
|
|
499
|
-
/**
|
|
500
|
-
* Switch organization
|
|
501
|
-
* @param id Organization id
|
|
502
|
-
* @param serviceId Service id
|
|
503
|
-
*/
|
|
504
|
-
switchOrg(id: number, serviceId?: number): Promise<boolean | undefined>;
|
|
505
|
-
|
|
506
488
|
/**
|
|
507
489
|
* Go to the login page
|
|
508
490
|
* @param tryLogin Try to login again
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { DataTypes, ListType
|
|
2
|
-
import { ICultureGet } from '../state/Culture';
|
|
3
|
-
import { ProductUnit } from './ProductUnit';
|
|
4
|
-
import { RepeatOption } from './RepeatOption';
|
|
1
|
+
import { DataTypes, ListType } from '@etsoo/shared';
|
|
5
2
|
|
|
6
3
|
/**
|
|
7
4
|
* Business utils
|
|
@@ -46,22 +43,6 @@ export namespace BusinessUtils {
|
|
|
46
43
|
return defaultTitle;
|
|
47
44
|
}
|
|
48
45
|
|
|
49
|
-
/**
|
|
50
|
-
* Get currency collection
|
|
51
|
-
* @param currencyNames Names like CNY, USD
|
|
52
|
-
* @param func Label delegate
|
|
53
|
-
* @returns Collection
|
|
54
|
-
*/
|
|
55
|
-
export function getCurrencies(
|
|
56
|
-
currencyNames: string[],
|
|
57
|
-
func: ICultureGet
|
|
58
|
-
): ListType1[] {
|
|
59
|
-
return currencyNames.map((name) => ({
|
|
60
|
-
id: name,
|
|
61
|
-
label: func(`currency${name}`) ?? name
|
|
62
|
-
}));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
46
|
/**
|
|
66
47
|
* Get 12-month items
|
|
67
48
|
* @param monthLabels Month labels
|
|
@@ -82,91 +63,6 @@ export namespace BusinessUtils {
|
|
|
82
63
|
return months;
|
|
83
64
|
}
|
|
84
65
|
|
|
85
|
-
/**
|
|
86
|
-
* Get product unit's label
|
|
87
|
-
* Please define the label in culture with key 'unitPC' for ProductUnit.PC like that
|
|
88
|
-
* @param unit Unit
|
|
89
|
-
* @param func Label delegate
|
|
90
|
-
* @param isJoined Add the join label like 'per Kg' for Kg
|
|
91
|
-
* @returns Label
|
|
92
|
-
*/
|
|
93
|
-
export function getUnitLabel(
|
|
94
|
-
unit: ProductUnit,
|
|
95
|
-
func: ICultureGet,
|
|
96
|
-
isJoined?: boolean
|
|
97
|
-
) {
|
|
98
|
-
const key = ProductUnit[unit];
|
|
99
|
-
const label = func('unit' + key) ?? key;
|
|
100
|
-
if (isJoined) {
|
|
101
|
-
const jLabel = func('unitJoin');
|
|
102
|
-
if (jLabel) return jLabel.format(label);
|
|
103
|
-
}
|
|
104
|
-
return label;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Get all product units
|
|
109
|
-
* @param func Label delegate
|
|
110
|
-
* @returns Units
|
|
111
|
-
*/
|
|
112
|
-
export function getUnits(func: ICultureGet): ListType[];
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
*
|
|
116
|
-
* Get all product units
|
|
117
|
-
* @param func Label delegate
|
|
118
|
-
* @param options Define the order and limit the items
|
|
119
|
-
* @param isJoined Add the join label like 'per Kg' for Kg
|
|
120
|
-
* @returns Units
|
|
121
|
-
*/
|
|
122
|
-
export function getUnits(
|
|
123
|
-
func: ICultureGet,
|
|
124
|
-
options?: string[],
|
|
125
|
-
isJoined?: boolean
|
|
126
|
-
): ListType[];
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
*
|
|
130
|
-
* Get all product units
|
|
131
|
-
* @param func Label delegate
|
|
132
|
-
* @param options Define the order and limit the items
|
|
133
|
-
* @param isJoined Add the join label like 'per Kg' for Kg
|
|
134
|
-
* @returns Units
|
|
135
|
-
*/
|
|
136
|
-
export function getUnits(
|
|
137
|
-
func: ICultureGet,
|
|
138
|
-
options?: string[],
|
|
139
|
-
isJoined?: boolean
|
|
140
|
-
): ListType[] {
|
|
141
|
-
options ??= DataTypes.getEnumKeys(ProductUnit);
|
|
142
|
-
return options.map((key) => {
|
|
143
|
-
const id = DataTypes.getEnumByKey(ProductUnit, key)! as number;
|
|
144
|
-
return {
|
|
145
|
-
id,
|
|
146
|
-
label: getUnitLabel(id, func, isJoined).formatInitial(true)
|
|
147
|
-
};
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
*
|
|
153
|
-
* Get all repeat options
|
|
154
|
-
* @param func Label delegate
|
|
155
|
-
* @param options Define the order and limit the items
|
|
156
|
-
* @param isJoined Add the join label like 'per Kg' for Kg
|
|
157
|
-
* @returns Units
|
|
158
|
-
*/
|
|
159
|
-
export function getRepeatOptions(
|
|
160
|
-
func: ICultureGet,
|
|
161
|
-
options?: string[],
|
|
162
|
-
isJoined: boolean = true
|
|
163
|
-
): ListType[] {
|
|
164
|
-
options ??= DataTypes.getEnumKeys(RepeatOption);
|
|
165
|
-
isJoined ??= true;
|
|
166
|
-
|
|
167
|
-
return getUnits(func, options, isJoined);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
66
|
/**
|
|
171
67
|
* Set id value
|
|
172
68
|
* @param item QueryRQ or TiplistRQ or similiar item
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Currency array
|
|
3
|
+
*/
|
|
4
|
+
export const Currencies = [
|
|
5
|
+
'AUD',
|
|
6
|
+
'CAD',
|
|
7
|
+
'CNY',
|
|
8
|
+
'EUR',
|
|
9
|
+
'GBP',
|
|
10
|
+
'HKD',
|
|
11
|
+
'JPY',
|
|
12
|
+
'NZD',
|
|
13
|
+
'SGD',
|
|
14
|
+
'USD'
|
|
15
|
+
] as const;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Currency type
|
|
19
|
+
*/
|
|
20
|
+
export type Currency = typeof Currencies[number];
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { DataTypes } from '@etsoo/shared';
|
|
2
|
+
import { AddressContinent } from '../address/AddressContinent';
|
|
3
|
+
import { AddressRegion, AddressRegionDb } from '../address/AddressRegion';
|
|
4
|
+
import { AddressState } from '../address/AddressState';
|
|
5
|
+
import { IApp } from '../app/IApp';
|
|
6
|
+
import { IdLabelConditional } from '../dto/IdLabelDto';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Address Api
|
|
10
|
+
*/
|
|
11
|
+
export class AddressApi {
|
|
12
|
+
private languageLabels: Record<string, DataTypes.StringRecord | undefined> =
|
|
13
|
+
{};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Constructor
|
|
17
|
+
* @param app Application
|
|
18
|
+
*/
|
|
19
|
+
constructor(private app: IApp) {}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get address labels
|
|
23
|
+
* @param language Language
|
|
24
|
+
* @returns Result
|
|
25
|
+
*/
|
|
26
|
+
async getLabels(language?: string) {
|
|
27
|
+
const l = this.app.checkLanguage(language);
|
|
28
|
+
let labels = this.languageLabels[l];
|
|
29
|
+
if (labels == null) {
|
|
30
|
+
labels = await import(`./../i18n/address.${l}.json`);
|
|
31
|
+
|
|
32
|
+
// Cache
|
|
33
|
+
this.languageLabels[l] = labels;
|
|
34
|
+
}
|
|
35
|
+
return labels!;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Get all continents
|
|
40
|
+
* @param language Language
|
|
41
|
+
* @param isNumberKey Is number key or key as id
|
|
42
|
+
* @returns Continents
|
|
43
|
+
*/
|
|
44
|
+
async continents<T extends boolean>(
|
|
45
|
+
language?: string,
|
|
46
|
+
isNumberKey = <T>false
|
|
47
|
+
): Promise<IdLabelConditional<T>> {
|
|
48
|
+
const labels = await this.getLabels(language);
|
|
49
|
+
return <IdLabelConditional<T>>DataTypes.getEnumKeys(
|
|
50
|
+
AddressContinent
|
|
51
|
+
).map((key) => ({
|
|
52
|
+
id: isNumberKey
|
|
53
|
+
? <number>DataTypes.getEnumByKey(AddressContinent, key)!
|
|
54
|
+
: key.toString(),
|
|
55
|
+
label: labels['continent' + key] ?? key
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Get region list from database
|
|
61
|
+
* @param language Language
|
|
62
|
+
* @param isLocal Is local version
|
|
63
|
+
* @returns Result
|
|
64
|
+
*/
|
|
65
|
+
async regions<T extends boolean = true>(
|
|
66
|
+
language?: string,
|
|
67
|
+
isLocal?: T
|
|
68
|
+
): Promise<
|
|
69
|
+
T extends true | undefined
|
|
70
|
+
? AddressRegion[]
|
|
71
|
+
: AddressRegionDb[] | undefined
|
|
72
|
+
> {
|
|
73
|
+
language = this.app.checkLanguage(language);
|
|
74
|
+
if (isLocal == null || isLocal) {
|
|
75
|
+
const labels = await this.getLabels(language);
|
|
76
|
+
return AddressRegion.all.map((region) => {
|
|
77
|
+
region.label = labels['region' + region.id] as string;
|
|
78
|
+
return { ...region };
|
|
79
|
+
});
|
|
80
|
+
} else {
|
|
81
|
+
return (await this.app.api.get<AddressRegionDb[]>(
|
|
82
|
+
`Address/RegionList?language=${language}`,
|
|
83
|
+
undefined,
|
|
84
|
+
{ defaultValue: [] }
|
|
85
|
+
)) as any;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Get state list from database
|
|
91
|
+
* @param regionId Region id
|
|
92
|
+
* @param language Language
|
|
93
|
+
* @returns Result
|
|
94
|
+
*/
|
|
95
|
+
states(regionId: string, language?: string) {
|
|
96
|
+
language = this.app.checkLanguage(language);
|
|
97
|
+
return this.app.api.get<AddressState[]>(
|
|
98
|
+
`Address/StateList?regionId=${regionId}&language=${language}`,
|
|
99
|
+
undefined,
|
|
100
|
+
{ defaultValue: [] }
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
}
|