@etsoo/appscript 1.3.2 → 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 +8 -22
- 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 +11 -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/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 +8 -22
- 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 +11 -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/index.d.ts +5 -0
- package/lib/mjs/index.js +6 -0
- package/package.json +2 -2
- 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 +22 -57
- package/src/app/ExternalSettings.ts +17 -13
- package/src/app/IApp.ts +12 -25
- 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/index.ts +7 -0
package/README.md
CHANGED
package/__tests__/app/CoreApp.ts
CHANGED
|
@@ -8,7 +8,14 @@ import {
|
|
|
8
8
|
} from '@etsoo/notificationbase';
|
|
9
9
|
import { ApiAuthorizationScheme, createClient } from '@etsoo/restclient';
|
|
10
10
|
import { DataTypes, DomUtils, Utils, WindowStorage } from '@etsoo/shared';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
AddressApi,
|
|
13
|
+
enUS,
|
|
14
|
+
ExternalSettings,
|
|
15
|
+
IUser,
|
|
16
|
+
PublicApi,
|
|
17
|
+
UserRole
|
|
18
|
+
} from '../../src';
|
|
12
19
|
import { AddressUtils } from '../../src/address/AddressUtils';
|
|
13
20
|
import { IAppSettings } from '../../src/app/AppSettings';
|
|
14
21
|
import { CoreApp } from '../../src/app/CoreApp';
|
|
@@ -22,7 +29,7 @@ const { detectedCountry } = DomUtils;
|
|
|
22
29
|
const { detectedCulture } = DomUtils;
|
|
23
30
|
|
|
24
31
|
// Supported cultures
|
|
25
|
-
const supportedCultures: DataTypes.CultureDefinition[] = [zhCN({})];
|
|
32
|
+
const supportedCultures: DataTypes.CultureDefinition[] = [zhCN({}), enUS({})];
|
|
26
33
|
|
|
27
34
|
// Supported regions
|
|
28
35
|
const supportedRegions = ['CN'];
|
|
@@ -41,7 +48,7 @@ class NotificationContainerTest extends NotificationContainer<
|
|
|
41
48
|
protected addRaw(
|
|
42
49
|
data: INotificaseBase<any, NotificationCallProps>
|
|
43
50
|
): INotification<any, NotificationCallProps> {
|
|
44
|
-
|
|
51
|
+
return new NotificationTest(data.type, data.content);
|
|
45
52
|
}
|
|
46
53
|
}
|
|
47
54
|
|
|
@@ -62,7 +69,7 @@ class CoreAppTest extends CoreApp<
|
|
|
62
69
|
*/
|
|
63
70
|
constructor() {
|
|
64
71
|
super(
|
|
65
|
-
{
|
|
72
|
+
ExternalSettings.format({
|
|
66
73
|
/**
|
|
67
74
|
* Endpoint of the API service
|
|
68
75
|
*/
|
|
@@ -105,7 +112,7 @@ class CoreAppTest extends CoreApp<
|
|
|
105
112
|
supportedCultures,
|
|
106
113
|
detectedCulture
|
|
107
114
|
)!
|
|
108
|
-
},
|
|
115
|
+
}),
|
|
109
116
|
createClient(),
|
|
110
117
|
container,
|
|
111
118
|
new WindowStorage(),
|
|
@@ -123,7 +130,18 @@ class CoreAppTest extends CoreApp<
|
|
|
123
130
|
}
|
|
124
131
|
}
|
|
125
132
|
|
|
126
|
-
|
|
133
|
+
function EnhanceApp<TBase extends DataTypes.MConstructor<CoreAppTest>>(
|
|
134
|
+
Base: TBase
|
|
135
|
+
) {
|
|
136
|
+
return class extends Base {
|
|
137
|
+
readonly addressApi = new AddressApi(this);
|
|
138
|
+
readonly publicApi = new PublicApi(this);
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const appClass = EnhanceApp(CoreAppTest);
|
|
143
|
+
const app = new appClass();
|
|
144
|
+
app.changeCulture(app.settings.cultures[0]);
|
|
127
145
|
|
|
128
146
|
test('Tests for addRootUrl', () => {
|
|
129
147
|
expect(app.addRootUrl('/home')).toBe('/cms/home');
|
|
@@ -173,22 +191,42 @@ test('Tests for getRoles', () => {
|
|
|
173
191
|
expect(roles.map((r) => r.id)).toEqual([8, 128, 8192]);
|
|
174
192
|
});
|
|
175
193
|
|
|
176
|
-
test('Tests for getUnitLabel', () => {
|
|
177
|
-
expect(app.getUnitLabel(12, true)).toBe('每年');
|
|
178
|
-
});
|
|
179
|
-
|
|
180
194
|
test('Tests for isValidPassword', () => {
|
|
181
195
|
expect(app.isValidPassword('12345678')).toBeFalsy();
|
|
182
196
|
expect(app.isValidPassword('abcd3')).toBeFalsy();
|
|
183
197
|
expect(app.isValidPassword('1234abcd')).toBeTruthy();
|
|
184
198
|
});
|
|
185
199
|
|
|
186
|
-
test('Tests for
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
]);
|
|
200
|
+
test('Tests for addressApi', async () => {
|
|
201
|
+
const continents = await app.addressApi.continents();
|
|
202
|
+
expect(continents.length).toBe(7);
|
|
203
|
+
|
|
204
|
+
const labels = await app.addressApi.getLabels('en-NZ');
|
|
205
|
+
expect(labels['regionHK']).toBe('Hong Kong, China');
|
|
206
|
+
|
|
207
|
+
const regions = await app.addressApi.regions('zh-CN');
|
|
208
|
+
const cn = regions.find((r) => r.id === 'CN');
|
|
209
|
+
expect(cn?.label).toBe('中国大陆');
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test('Tests for publicApi', async () => {
|
|
213
|
+
expect(app.publicApi.getUnitLabel(12, true)).toBe('每年');
|
|
192
214
|
|
|
215
|
+
const options = app.publicApi.repeatOptions(['MONTH', 'QUATER', 'YEAR']);
|
|
193
216
|
expect(options[2]).toStrictEqual({ id: 12, label: '每年' });
|
|
217
|
+
|
|
218
|
+
const currencies = await app.publicApi.currencies(['NZD', 'AUD', 'USD']);
|
|
219
|
+
expect(currencies[1].id).toBe('AUD');
|
|
220
|
+
|
|
221
|
+
//const currenciesRemote = await app.publicApi.currencies();
|
|
222
|
+
//console.log(currenciesRemote);
|
|
223
|
+
|
|
224
|
+
//const history = await app.publicApi.exchangeRateHistory(['NZD', 'AUD'], 24);
|
|
225
|
+
//console.log(history);
|
|
226
|
+
|
|
227
|
+
//const qrcode = await app.publicApi.mobileQRCode('xz@etsoo.com');
|
|
228
|
+
//console.log(qrcode);
|
|
229
|
+
|
|
230
|
+
//const exchangeRate = await app.publicApi.exchangeRate('USD');
|
|
231
|
+
//console.log(exchangeRate);
|
|
194
232
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Address continent
|
|
3
3
|
*/
|
|
4
4
|
export declare enum AddressContinent {
|
|
5
5
|
AF = 1,
|
|
@@ -10,3 +10,7 @@ export declare enum AddressContinent {
|
|
|
10
10
|
OC = 6,
|
|
11
11
|
SA = 7
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Address continent ids
|
|
15
|
+
*/
|
|
16
|
+
export declare type AddressContinentId = keyof typeof AddressContinent;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Currency } from '../business/Currency';
|
|
2
|
+
import { AddressContinent, AddressContinentId } from './AddressContinent';
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
+
* Address region in database
|
|
4
5
|
*/
|
|
5
|
-
export interface
|
|
6
|
+
export interface AddressRegionDb {
|
|
6
7
|
/**
|
|
7
8
|
* Id, like CN for China
|
|
8
9
|
* https://www.iban.com/country-codes
|
|
@@ -20,10 +21,10 @@ export interface IAddressRegion {
|
|
|
20
21
|
*/
|
|
21
22
|
readonly nid: string;
|
|
22
23
|
/**
|
|
23
|
-
* Continent
|
|
24
|
-
*
|
|
24
|
+
* Continent id
|
|
25
|
+
* 洲编号
|
|
25
26
|
*/
|
|
26
|
-
readonly
|
|
27
|
+
readonly continentId: AddressContinentId;
|
|
27
28
|
/**
|
|
28
29
|
* Phone exit code for international dial, like 00 in China
|
|
29
30
|
* 国际拨号的电话退出代码
|
|
@@ -38,17 +39,27 @@ export interface IAddressRegion {
|
|
|
38
39
|
* Currency, like CNY for China's currency
|
|
39
40
|
* 币种
|
|
40
41
|
*/
|
|
41
|
-
readonly currency:
|
|
42
|
+
readonly currency: Currency;
|
|
43
|
+
/**
|
|
44
|
+
* Name
|
|
45
|
+
* 名称
|
|
46
|
+
*/
|
|
47
|
+
label: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Country or region interface
|
|
51
|
+
*/
|
|
52
|
+
export interface IAddressRegion extends AddressRegionDb {
|
|
53
|
+
/**
|
|
54
|
+
* Continent
|
|
55
|
+
* 洲
|
|
56
|
+
*/
|
|
57
|
+
readonly continent: AddressContinent;
|
|
42
58
|
/**
|
|
43
59
|
* Languages
|
|
44
60
|
* 语言
|
|
45
61
|
*/
|
|
46
62
|
readonly languages: string[];
|
|
47
|
-
/**
|
|
48
|
-
* Name
|
|
49
|
-
* 名称
|
|
50
|
-
*/
|
|
51
|
-
name: string;
|
|
52
63
|
}
|
|
53
64
|
/**
|
|
54
65
|
* Address or region
|
|
@@ -60,9 +71,9 @@ export declare class AddressRegion implements IAddressRegion {
|
|
|
60
71
|
continent: AddressContinent;
|
|
61
72
|
exitCode: string;
|
|
62
73
|
idd: string;
|
|
63
|
-
currency:
|
|
74
|
+
currency: Currency;
|
|
64
75
|
languages: string[];
|
|
65
|
-
|
|
76
|
+
label: string;
|
|
66
77
|
/**
|
|
67
78
|
* CN - China
|
|
68
79
|
*/
|
|
@@ -131,5 +142,10 @@ export declare class AddressRegion implements IAddressRegion {
|
|
|
131
142
|
* @param id Country id
|
|
132
143
|
*/
|
|
133
144
|
static getById(id: string): AddressRegion | undefined;
|
|
134
|
-
|
|
145
|
+
/**
|
|
146
|
+
* Continent id
|
|
147
|
+
* 洲编号
|
|
148
|
+
*/
|
|
149
|
+
readonly continentId: AddressContinentId;
|
|
150
|
+
constructor(id: string, id3: string, nid: string, continent: AddressContinent, exitCode: string, idd: string, currency: Currency, languages: string[], label?: string);
|
|
135
151
|
}
|
|
@@ -7,7 +7,7 @@ const AddressContinent_1 = require("./AddressContinent");
|
|
|
7
7
|
*/
|
|
8
8
|
class AddressRegion {
|
|
9
9
|
// Typescript constructor shorthand
|
|
10
|
-
constructor(id, id3, nid, continent, exitCode, idd, currency, languages,
|
|
10
|
+
constructor(id, id3, nid, continent, exitCode, idd, currency, languages, label = id) {
|
|
11
11
|
this.id = id;
|
|
12
12
|
this.id3 = id3;
|
|
13
13
|
this.nid = nid;
|
|
@@ -16,7 +16,8 @@ class AddressRegion {
|
|
|
16
16
|
this.idd = idd;
|
|
17
17
|
this.currency = currency;
|
|
18
18
|
this.languages = languages;
|
|
19
|
-
this.
|
|
19
|
+
this.label = label;
|
|
20
|
+
this.continentId = AddressContinent_1.AddressContinent[continent];
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
22
23
|
* Get country or region by id
|
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
import { AddressRegion } from '
|
|
2
|
-
import { IdLabelConditional } from '../dto/IdLabelDto';
|
|
3
|
-
import { ICultureGet } from '../state/Culture';
|
|
1
|
+
import { AddressRegion } from './AddressRegion';
|
|
4
2
|
/**
|
|
5
3
|
* Address utils
|
|
6
4
|
*/
|
|
7
5
|
export declare namespace AddressUtils {
|
|
8
|
-
/**
|
|
9
|
-
* Get all continents
|
|
10
|
-
* @param func Label delegate
|
|
11
|
-
* @param isNumberKey Is number key or key as id
|
|
12
|
-
* @returns Continents
|
|
13
|
-
*/
|
|
14
|
-
function getContinents<T extends boolean>(func: ICultureGet, isNumberKey?: T): IdLabelConditional<T>;
|
|
15
6
|
/**
|
|
16
7
|
* Get region from regions and detected region and language
|
|
17
8
|
* @param regions Supported regions
|
|
@@ -19,11 +10,4 @@ export declare namespace AddressUtils {
|
|
|
19
10
|
* @param detectedLanguage Detected language
|
|
20
11
|
*/
|
|
21
12
|
function getRegion(regions: string[], detectedRegion?: string | null, detectedLanguage?: string | null): AddressRegion;
|
|
22
|
-
/**
|
|
23
|
-
* Get region label
|
|
24
|
-
* @param region Region id
|
|
25
|
-
* @param func Label delegate
|
|
26
|
-
* @returns Label
|
|
27
|
-
*/
|
|
28
|
-
function getRegionLabel(region: string, func: ICultureGet): string;
|
|
29
13
|
}
|
|
@@ -1,32 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AddressUtils = void 0;
|
|
4
|
-
const
|
|
5
|
-
const __1 = require("..");
|
|
6
|
-
const AddressContinent_1 = require("./AddressContinent");
|
|
4
|
+
const AddressRegion_1 = require("./AddressRegion");
|
|
7
5
|
/**
|
|
8
6
|
* Address utils
|
|
9
7
|
*/
|
|
10
8
|
var AddressUtils;
|
|
11
9
|
(function (AddressUtils) {
|
|
12
|
-
/**
|
|
13
|
-
* Get all continents
|
|
14
|
-
* @param func Label delegate
|
|
15
|
-
* @param isNumberKey Is number key or key as id
|
|
16
|
-
* @returns Continents
|
|
17
|
-
*/
|
|
18
|
-
function getContinents(func, isNumberKey = false) {
|
|
19
|
-
return shared_1.DataTypes.getEnumKeys(AddressContinent_1.AddressContinent).map((key) => {
|
|
20
|
-
var _a;
|
|
21
|
-
return ({
|
|
22
|
-
id: isNumberKey
|
|
23
|
-
? shared_1.DataTypes.getEnumByKey(AddressContinent_1.AddressContinent, key)
|
|
24
|
-
: key.toString(),
|
|
25
|
-
label: (_a = func('continent' + key)) !== null && _a !== void 0 ? _a : key
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
AddressUtils.getContinents = getContinents;
|
|
30
10
|
/**
|
|
31
11
|
* Get region from regions and detected region and language
|
|
32
12
|
* @param regions Supported regions
|
|
@@ -36,31 +16,20 @@ var AddressUtils;
|
|
|
36
16
|
function getRegion(regions, detectedRegion, detectedLanguage) {
|
|
37
17
|
// Exactly match
|
|
38
18
|
if (detectedRegion && regions.includes(detectedRegion)) {
|
|
39
|
-
const region =
|
|
19
|
+
const region = AddressRegion_1.AddressRegion.getById(detectedRegion);
|
|
40
20
|
if (region)
|
|
41
21
|
return region;
|
|
42
22
|
}
|
|
43
23
|
// Match with language
|
|
44
24
|
if (detectedLanguage) {
|
|
45
25
|
const region = regions
|
|
46
|
-
.map((id) =>
|
|
26
|
+
.map((id) => AddressRegion_1.AddressRegion.getById(id))
|
|
47
27
|
.find((item) => item.languages.includes(detectedLanguage));
|
|
48
28
|
if (region)
|
|
49
29
|
region;
|
|
50
30
|
}
|
|
51
31
|
// Default
|
|
52
|
-
return
|
|
32
|
+
return AddressRegion_1.AddressRegion.getById(regions[0]);
|
|
53
33
|
}
|
|
54
34
|
AddressUtils.getRegion = getRegion;
|
|
55
|
-
/**
|
|
56
|
-
* Get region label
|
|
57
|
-
* @param region Region id
|
|
58
|
-
* @param func Label delegate
|
|
59
|
-
* @returns Label
|
|
60
|
-
*/
|
|
61
|
-
function getRegionLabel(region, func) {
|
|
62
|
-
var _a;
|
|
63
|
-
return (_a = func('region' + region)) !== null && _a !== void 0 ? _a : region;
|
|
64
|
-
}
|
|
65
|
-
AddressUtils.getRegionLabel = getRegionLabel;
|
|
66
35
|
})(AddressUtils = exports.AddressUtils || (exports.AddressUtils = {}));
|
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { INotifier, NotificationAlign, NotificationCallProps, NotificationConten
|
|
|
2
2
|
import { ApiDataError, IApi, IPData } from '@etsoo/restclient';
|
|
3
3
|
import { DataTypes, DateUtils, IStorage, ListType, ListType1 } from '@etsoo/shared';
|
|
4
4
|
import { AddressRegion } from '../address/AddressRegion';
|
|
5
|
-
import { ProductUnit } from '../business/ProductUnit';
|
|
6
5
|
import { InitCallDto } from '../dto/InitCallDto';
|
|
7
6
|
import { IActionResult } from '../result/IActionResult';
|
|
8
7
|
import { InitCallResult, InitCallResultData } from '../result/InitCallResult';
|
|
@@ -40,9 +39,9 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
40
39
|
*/
|
|
41
40
|
readonly fields: IAppFields;
|
|
42
41
|
/**
|
|
43
|
-
* API
|
|
42
|
+
* API, not recommend to use it directly in code, wrap to separate methods
|
|
44
43
|
*/
|
|
45
|
-
|
|
44
|
+
readonly api: IApi;
|
|
46
45
|
/**
|
|
47
46
|
* Application name
|
|
48
47
|
*/
|
|
@@ -217,6 +216,12 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
217
216
|
* @param culture New culture definition
|
|
218
217
|
*/
|
|
219
218
|
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
219
|
+
/**
|
|
220
|
+
* Check language is supported or not, return a valid language when supported
|
|
221
|
+
* @param language Language
|
|
222
|
+
* @returns Result
|
|
223
|
+
*/
|
|
224
|
+
checkLanguage(language?: string): string;
|
|
220
225
|
/**
|
|
221
226
|
* Clear cache data
|
|
222
227
|
*/
|
|
@@ -386,12 +391,6 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
386
391
|
* @returns Time zone
|
|
387
392
|
*/
|
|
388
393
|
getTimeZone(): string | undefined;
|
|
389
|
-
/**
|
|
390
|
-
* Get product unit and repeat option label
|
|
391
|
-
* @param unit Product unit or repeat option
|
|
392
|
-
* @param isJoined Add the join label like 'per Kg' for Kg
|
|
393
|
-
*/
|
|
394
|
-
getUnitLabel(unit?: ProductUnit, isJoined?: boolean): string;
|
|
395
394
|
/**
|
|
396
395
|
* Hash message, SHA3 or HmacSHA512, 512 as Base64
|
|
397
396
|
* https://cryptojs.gitbook.io/docs/
|
|
@@ -447,19 +446,6 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
447
446
|
* @param apiUrl Signout API URL
|
|
448
447
|
*/
|
|
449
448
|
signout(): Promise<void>;
|
|
450
|
-
/**
|
|
451
|
-
* Get organization list
|
|
452
|
-
* @param items Max items
|
|
453
|
-
* @param serviceId Service id
|
|
454
|
-
* @returns Result
|
|
455
|
-
*/
|
|
456
|
-
orgList(items?: number, serviceId?: number): Promise<ListType[] | undefined>;
|
|
457
|
-
/**
|
|
458
|
-
* Switch organization
|
|
459
|
-
* @param id Organization id
|
|
460
|
-
* @param serviceId Service id
|
|
461
|
-
*/
|
|
462
|
-
switchOrg(id: number, serviceId?: number): Promise<boolean | undefined>;
|
|
463
449
|
/**
|
|
464
450
|
* Go to the login page
|
|
465
451
|
* @param tryLogin Try to login again
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -6,9 +6,7 @@ const restclient_1 = require("@etsoo/restclient");
|
|
|
6
6
|
const shared_1 = require("@etsoo/shared");
|
|
7
7
|
const crypto_js_1 = require("crypto-js");
|
|
8
8
|
const AddressRegion_1 = require("../address/AddressRegion");
|
|
9
|
-
const AddressUtils_1 = require("../address/AddressUtils");
|
|
10
9
|
const BridgeUtils_1 = require("../bridges/BridgeUtils");
|
|
11
|
-
const BusinessUtils_1 = require("../business/BusinessUtils");
|
|
12
10
|
const EntityStatus_1 = require("../business/EntityStatus");
|
|
13
11
|
const ActionResultError_1 = require("../result/ActionResultError");
|
|
14
12
|
const IApp_1 = require("./IApp");
|
|
@@ -240,6 +238,8 @@ class CoreApp {
|
|
|
240
238
|
* @param api Api
|
|
241
239
|
*/
|
|
242
240
|
setApi(api) {
|
|
241
|
+
// Base URL of the API
|
|
242
|
+
api.baseUrl = this.settings.endpoint;
|
|
243
243
|
// onRequest, show loading or not, rewrite the property to override default action
|
|
244
244
|
api.onRequest = (data) => {
|
|
245
245
|
if (data.showLoading == null || data.showLoading) {
|
|
@@ -507,12 +507,20 @@ class CoreApp {
|
|
|
507
507
|
this._culture = name;
|
|
508
508
|
// Hold the current resources
|
|
509
509
|
this.settings.currentCulture = culture;
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Check language is supported or not, return a valid language when supported
|
|
513
|
+
* @param language Language
|
|
514
|
+
* @returns Result
|
|
515
|
+
*/
|
|
516
|
+
checkLanguage(language) {
|
|
517
|
+
if (language) {
|
|
518
|
+
const item = this.settings.cultures.find((c) => { var _a; return c.name === language || ((_a = c.compatibleName) === null || _a === void 0 ? void 0 : _a.includes(language)); });
|
|
519
|
+
if (item)
|
|
520
|
+
return item.name;
|
|
521
|
+
}
|
|
522
|
+
// Default language
|
|
523
|
+
return this.culture;
|
|
516
524
|
}
|
|
517
525
|
/**
|
|
518
526
|
* Clear cache data
|
|
@@ -941,16 +949,6 @@ class CoreApp {
|
|
|
941
949
|
// settings.timeZone = Utils.getTimeZone()
|
|
942
950
|
return (_a = this.settings.timeZone) !== null && _a !== void 0 ? _a : (_b = this.ipData) === null || _b === void 0 ? void 0 : _b.timezone;
|
|
943
951
|
}
|
|
944
|
-
/**
|
|
945
|
-
* Get product unit and repeat option label
|
|
946
|
-
* @param unit Product unit or repeat option
|
|
947
|
-
* @param isJoined Add the join label like 'per Kg' for Kg
|
|
948
|
-
*/
|
|
949
|
-
getUnitLabel(unit, isJoined) {
|
|
950
|
-
if (unit == null)
|
|
951
|
-
return '';
|
|
952
|
-
return BusinessUtils_1.BusinessUtils.getUnitLabel(unit, this.labelDelegate, isJoined);
|
|
953
|
-
}
|
|
954
952
|
/**
|
|
955
953
|
* Hash message, SHA3 or HmacSHA512, 512 as Base64
|
|
956
954
|
* https://cryptojs.gitbook.io/docs/
|
|
@@ -1089,34 +1087,6 @@ class CoreApp {
|
|
|
1089
1087
|
// Go to login page
|
|
1090
1088
|
this.toLoginPage();
|
|
1091
1089
|
}
|
|
1092
|
-
/**
|
|
1093
|
-
* Get organization list
|
|
1094
|
-
* @param items Max items
|
|
1095
|
-
* @param serviceId Service id
|
|
1096
|
-
* @returns Result
|
|
1097
|
-
*/
|
|
1098
|
-
async orgList(items, serviceId) {
|
|
1099
|
-
return await this.api.post('Organization/List', {
|
|
1100
|
-
items,
|
|
1101
|
-
serviceId
|
|
1102
|
-
}, { defaultValue: [], showLoading: false });
|
|
1103
|
-
}
|
|
1104
|
-
/**
|
|
1105
|
-
* Switch organization
|
|
1106
|
-
* @param id Organization id
|
|
1107
|
-
* @param serviceId Service id
|
|
1108
|
-
*/
|
|
1109
|
-
async switchOrg(id, serviceId) {
|
|
1110
|
-
const api = `Organization/Switch`;
|
|
1111
|
-
const result = await this.api.put(api, {
|
|
1112
|
-
id,
|
|
1113
|
-
serviceId,
|
|
1114
|
-
deviceId: this.deviceId
|
|
1115
|
-
});
|
|
1116
|
-
if (result)
|
|
1117
|
-
return await this.refreshToken();
|
|
1118
|
-
return result;
|
|
1119
|
-
}
|
|
1120
1090
|
/**
|
|
1121
1091
|
* Go to the login page
|
|
1122
1092
|
* @param tryLogin Try to login again
|
|
@@ -15,17 +15,9 @@ var ExternalSettings;
|
|
|
15
15
|
if (typeof settings === 'object') {
|
|
16
16
|
if (typeof window !== 'undefined') {
|
|
17
17
|
// Host name
|
|
18
|
-
|
|
19
|
-
// Empty string returned under Electron
|
|
20
|
-
if (hostname === '')
|
|
21
|
-
hostname = 'localhost';
|
|
18
|
+
const hostname = globalThis.location.hostname;
|
|
22
19
|
// replace {hostname}
|
|
23
|
-
|
|
24
|
-
const value = settings[key];
|
|
25
|
-
if (typeof value === 'string') {
|
|
26
|
-
settings[key] = value.replace('{hostname}', hostname);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
20
|
+
format(settings, hostname);
|
|
29
21
|
}
|
|
30
22
|
return settings;
|
|
31
23
|
}
|
|
@@ -33,4 +25,18 @@ var ExternalSettings;
|
|
|
33
25
|
return undefined;
|
|
34
26
|
}
|
|
35
27
|
ExternalSettings.Create = Create;
|
|
28
|
+
function format(settings, hostname) {
|
|
29
|
+
// Default hostname
|
|
30
|
+
if (!hostname)
|
|
31
|
+
hostname = 'localhost';
|
|
32
|
+
// replace {hostname}
|
|
33
|
+
for (const key in settings) {
|
|
34
|
+
const value = settings[key];
|
|
35
|
+
if (typeof value === 'string') {
|
|
36
|
+
settings[key] = value.replace('{hostname}', hostname);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return settings;
|
|
40
|
+
}
|
|
41
|
+
ExternalSettings.format = format;
|
|
36
42
|
})(ExternalSettings = exports.ExternalSettings || (exports.ExternalSettings = {}));
|
package/lib/cjs/app/IApp.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { INotifier, NotificationAlign, NotificationCallProps, NotificationContent, NotificationReturn } from '@etsoo/notificationbase';
|
|
2
|
-
import { ApiDataError, IPData } from '@etsoo/restclient';
|
|
2
|
+
import { ApiDataError, IApi, IPData } from '@etsoo/restclient';
|
|
3
3
|
import { DataTypes, DateUtils, IStorage, ListType } from '@etsoo/shared';
|
|
4
4
|
import { AddressRegion } from '../address/AddressRegion';
|
|
5
|
-
import { ProductUnit } from '../business/ProductUnit';
|
|
6
5
|
import { IActionResult } from '../result/IActionResult';
|
|
7
6
|
import { IUser } from '../state/User';
|
|
8
7
|
import { IAppSettings } from './AppSettings';
|
|
@@ -69,6 +68,10 @@ export interface IApp {
|
|
|
69
68
|
* Fields
|
|
70
69
|
*/
|
|
71
70
|
readonly fields: IAppFields;
|
|
71
|
+
/**
|
|
72
|
+
* API, not recommend to use it directly in code, wrap to separate methods
|
|
73
|
+
*/
|
|
74
|
+
readonly api: IApi;
|
|
72
75
|
/**
|
|
73
76
|
* Notifier
|
|
74
77
|
*/
|
|
@@ -159,6 +162,12 @@ export interface IApp {
|
|
|
159
162
|
* @returns true means device is invalid
|
|
160
163
|
*/
|
|
161
164
|
checkDeviceResult(result: IActionResult): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Check language is supported or not
|
|
167
|
+
* @param language Language
|
|
168
|
+
* @returns Result
|
|
169
|
+
*/
|
|
170
|
+
checkLanguage(language?: string): string;
|
|
162
171
|
/**
|
|
163
172
|
* Clear cache data
|
|
164
173
|
*/
|
|
@@ -306,12 +315,6 @@ export interface IApp {
|
|
|
306
315
|
* @returns Time zone
|
|
307
316
|
*/
|
|
308
317
|
getTimeZone(): string | undefined;
|
|
309
|
-
/**
|
|
310
|
-
* Get product unit and repeat option label
|
|
311
|
-
* @param unit Product unit or repeat option
|
|
312
|
-
* @param isJoined Add the join label like 'per Kg' for Kg
|
|
313
|
-
*/
|
|
314
|
-
getUnitLabel(unit?: ProductUnit, isJoined?: boolean): string;
|
|
315
318
|
/**
|
|
316
319
|
* Hash message, SHA3 or HmacSHA512, 512 as Base64
|
|
317
320
|
* https://cryptojs.gitbook.io/docs/
|
|
@@ -363,23 +366,10 @@ export interface IApp {
|
|
|
363
366
|
* Signout
|
|
364
367
|
*/
|
|
365
368
|
signout(): Promise<void>;
|
|
366
|
-
/**
|
|
367
|
-
* Get organization list
|
|
368
|
-
* @param items Max items
|
|
369
|
-
* @param serviceId Service id
|
|
370
|
-
* @returns Result
|
|
371
|
-
*/
|
|
372
|
-
orgList(items?: number, serviceId?: number): Promise<ListType[] | undefined>;
|
|
373
369
|
/**
|
|
374
370
|
* Persist settings to source when application exit
|
|
375
371
|
*/
|
|
376
372
|
persist(): void;
|
|
377
|
-
/**
|
|
378
|
-
* Switch organization
|
|
379
|
-
* @param id Organization id
|
|
380
|
-
* @param serviceId Service id
|
|
381
|
-
*/
|
|
382
|
-
switchOrg(id: number, serviceId?: number): Promise<boolean | undefined>;
|
|
383
373
|
/**
|
|
384
374
|
* Go to the login page
|
|
385
375
|
* @param tryLogin Try to login again
|