@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.
Files changed (98) hide show
  1. package/README.md +0 -1
  2. package/__tests__/app/CoreApp.ts +54 -16
  3. package/lib/cjs/address/AddressContinent.d.ts +5 -1
  4. package/lib/cjs/address/AddressContinent.js +1 -1
  5. package/lib/cjs/address/AddressRegion.d.ts +31 -15
  6. package/lib/cjs/address/AddressRegion.js +3 -2
  7. package/lib/cjs/address/AddressState.d.ts +17 -0
  8. package/lib/cjs/address/AddressState.js +2 -0
  9. package/lib/cjs/address/AddressUtils.d.ts +1 -17
  10. package/lib/cjs/address/AddressUtils.js +4 -35
  11. package/lib/cjs/app/CoreApp.d.ts +7 -21
  12. package/lib/cjs/app/CoreApp.js +16 -46
  13. package/lib/cjs/app/ExternalSettings.d.ts +1 -0
  14. package/lib/cjs/app/ExternalSettings.js +16 -10
  15. package/lib/cjs/app/IApp.d.ts +7 -21
  16. package/lib/cjs/business/BusinessUtils.d.ts +1 -43
  17. package/lib/cjs/business/BusinessUtils.js +0 -72
  18. package/lib/cjs/business/Currency.d.ts +8 -0
  19. package/lib/cjs/business/Currency.js +18 -0
  20. package/lib/cjs/erp/AddressApi.d.ts +44 -0
  21. package/lib/cjs/erp/AddressApi.js +105 -0
  22. package/lib/cjs/erp/OrgApi.d.ts +26 -0
  23. package/lib/cjs/erp/OrgApi.js +43 -0
  24. package/lib/cjs/erp/PublicApi.d.ts +81 -0
  25. package/lib/cjs/erp/PublicApi.js +124 -0
  26. package/lib/cjs/erp/dto/CurrencyDto.d.ts +6 -0
  27. package/lib/cjs/erp/dto/CurrencyDto.js +2 -0
  28. package/lib/cjs/erp/dto/ExchangeRateDto.d.ts +13 -0
  29. package/lib/cjs/erp/dto/ExchangeRateDto.js +2 -0
  30. package/lib/cjs/erp/dto/ExchangeRateHistoryDto.d.ts +8 -0
  31. package/lib/cjs/erp/dto/ExchangeRateHistoryDto.js +2 -0
  32. package/lib/cjs/erp/dto/PublicProductDto.d.ts +35 -0
  33. package/lib/cjs/erp/dto/PublicProductDto.js +2 -0
  34. package/lib/cjs/i18n/en-US.json +1 -0
  35. package/lib/cjs/i18n/zh-CN.json +1 -0
  36. package/lib/cjs/i18n/zh-HK.json +1 -0
  37. package/lib/cjs/index.d.ts +5 -0
  38. package/lib/cjs/index.js +6 -0
  39. package/lib/mjs/address/AddressContinent.d.ts +5 -1
  40. package/lib/mjs/address/AddressContinent.js +1 -1
  41. package/lib/mjs/address/AddressRegion.d.ts +31 -15
  42. package/lib/mjs/address/AddressRegion.js +3 -2
  43. package/lib/mjs/address/AddressState.d.ts +17 -0
  44. package/lib/mjs/address/AddressState.js +1 -0
  45. package/lib/mjs/address/AddressUtils.d.ts +1 -17
  46. package/lib/mjs/address/AddressUtils.js +1 -32
  47. package/lib/mjs/app/CoreApp.d.ts +7 -21
  48. package/lib/mjs/app/CoreApp.js +16 -46
  49. package/lib/mjs/app/ExternalSettings.d.ts +1 -0
  50. package/lib/mjs/app/ExternalSettings.js +16 -10
  51. package/lib/mjs/app/IApp.d.ts +7 -21
  52. package/lib/mjs/business/BusinessUtils.d.ts +1 -43
  53. package/lib/mjs/business/BusinessUtils.js +0 -72
  54. package/lib/mjs/business/Currency.d.ts +8 -0
  55. package/lib/mjs/business/Currency.js +15 -0
  56. package/lib/mjs/erp/AddressApi.d.ts +44 -0
  57. package/lib/mjs/erp/AddressApi.js +78 -0
  58. package/lib/mjs/erp/OrgApi.d.ts +26 -0
  59. package/lib/mjs/erp/OrgApi.js +39 -0
  60. package/lib/mjs/erp/PublicApi.d.ts +81 -0
  61. package/lib/mjs/erp/PublicApi.js +120 -0
  62. package/lib/mjs/erp/dto/CurrencyDto.d.ts +6 -0
  63. package/lib/mjs/erp/dto/CurrencyDto.js +1 -0
  64. package/lib/mjs/erp/dto/ExchangeRateDto.d.ts +13 -0
  65. package/lib/mjs/erp/dto/ExchangeRateDto.js +1 -0
  66. package/lib/mjs/erp/dto/ExchangeRateHistoryDto.d.ts +8 -0
  67. package/lib/mjs/erp/dto/ExchangeRateHistoryDto.js +1 -0
  68. package/lib/mjs/erp/dto/PublicProductDto.d.ts +35 -0
  69. package/lib/mjs/erp/dto/PublicProductDto.js +1 -0
  70. package/lib/mjs/i18n/en-US.json +1 -0
  71. package/lib/mjs/i18n/zh-CN.json +1 -0
  72. package/lib/mjs/i18n/zh-HK.json +1 -0
  73. package/lib/mjs/index.d.ts +5 -0
  74. package/lib/mjs/index.js +6 -0
  75. package/package.json +8 -8
  76. package/src/address/AddressContinent.ts +6 -1
  77. package/src/address/AddressRegion.ts +36 -16
  78. package/src/address/AddressState.ts +19 -0
  79. package/src/address/AddressUtils.ts +1 -35
  80. package/src/app/CoreApp.ts +21 -56
  81. package/src/app/ExternalSettings.ts +17 -13
  82. package/src/app/IApp.ts +8 -26
  83. package/src/business/BusinessUtils.ts +1 -105
  84. package/src/business/Currency.ts +20 -0
  85. package/src/erp/AddressApi.ts +103 -0
  86. package/src/erp/OrgApi.ts +45 -0
  87. package/src/erp/PublicApi.ts +162 -0
  88. package/src/erp/dto/CurrencyDto.ts +7 -0
  89. package/src/erp/dto/ExchangeRateDto.ts +14 -0
  90. package/src/erp/dto/ExchangeRateHistoryDto.ts +9 -0
  91. package/src/erp/dto/PublicProductDto.ts +41 -0
  92. package/src/i18n/address.en-US.json +21 -0
  93. package/src/i18n/address.zh-CN.json +21 -0
  94. package/src/i18n/address.zh-HK.json +21 -0
  95. package/src/i18n/en-US.json +1 -0
  96. package/src/i18n/zh-CN.json +1 -0
  97. package/src/i18n/zh-HK.json +1 -0
  98. package/src/index.ts +7 -0
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -52,6 +52,7 @@
52
52
  "help": "Help",
53
53
  "id": "Number#",
54
54
  "info": "Info",
55
+ "item": "Item",
55
56
  "itemExists": "'{0}' already exists",
56
57
  "loading": "Loading...",
57
58
  "login": "Login",
@@ -52,6 +52,7 @@
52
52
  "help": "帮助",
53
53
  "id": "编号",
54
54
  "info": "信息",
55
+ "item": "项目",
55
56
  "itemExists": "'{0}'已经存在",
56
57
  "loading": "正在加载...",
57
58
  "login": "登录",
@@ -52,6 +52,7 @@
52
52
  "help": "幫助",
53
53
  "id": "編號",
54
54
  "info": "信息",
55
+ "item": "項目",
55
56
  "itemExists": "'{0}'已经存在",
56
57
  "loading": "正在加載...",
57
58
  "login": "登錄",
@@ -1,5 +1,6 @@
1
1
  export * from './address/AddressContinent';
2
2
  export * from './address/AddressRegion';
3
+ export * from './address/AddressState';
3
4
  export * from './address/AddressUtils';
4
5
  export * from './app/AppSettings';
5
6
  export * from './app/CoreApp';
@@ -10,6 +11,7 @@ export * from './bridges/BridgeUtils';
10
11
  export * from './bridges/IBridgeHost';
11
12
  export * from './business/BusinessTax';
12
13
  export * from './business/BusinessUtils';
14
+ export * from './business/Currency';
13
15
  export * from './business/EntityStatus';
14
16
  export * from './business/ProductUnit';
15
17
  export * from './business/RepeatOption';
@@ -17,6 +19,9 @@ export * from './def/ListItem';
17
19
  export * from './dto/IdLabelDto';
18
20
  export * from './dto/IdLabelPrimaryDto';
19
21
  export * from './dto/InitCallDto';
22
+ export * from './erp/AddressApi';
23
+ export * from './erp/OrgApi';
24
+ export * from './erp/PublicApi';
20
25
  export * from './i18n/enUS';
21
26
  export * from './i18n/zhCN';
22
27
  export * from './i18n/zhHK';
package/lib/cjs/index.js CHANGED
@@ -18,6 +18,7 @@ exports.createClient = exports.ApiAuthorizationScheme = void 0;
18
18
  // address
19
19
  __exportStar(require("./address/AddressContinent"), exports);
20
20
  __exportStar(require("./address/AddressRegion"), exports);
21
+ __exportStar(require("./address/AddressState"), exports);
21
22
  __exportStar(require("./address/AddressUtils"), exports);
22
23
  // app
23
24
  __exportStar(require("./app/AppSettings"), exports);
@@ -31,6 +32,7 @@ __exportStar(require("./bridges/IBridgeHost"), exports);
31
32
  // business
32
33
  __exportStar(require("./business/BusinessTax"), exports);
33
34
  __exportStar(require("./business/BusinessUtils"), exports);
35
+ __exportStar(require("./business/Currency"), exports);
34
36
  __exportStar(require("./business/EntityStatus"), exports);
35
37
  __exportStar(require("./business/ProductUnit"), exports);
36
38
  __exportStar(require("./business/RepeatOption"), exports);
@@ -40,6 +42,10 @@ __exportStar(require("./def/ListItem"), exports);
40
42
  __exportStar(require("./dto/IdLabelDto"), exports);
41
43
  __exportStar(require("./dto/IdLabelPrimaryDto"), exports);
42
44
  __exportStar(require("./dto/InitCallDto"), exports);
45
+ // erp
46
+ __exportStar(require("./erp/AddressApi"), exports);
47
+ __exportStar(require("./erp/OrgApi"), exports);
48
+ __exportStar(require("./erp/PublicApi"), exports);
43
49
  // i18n
44
50
  __exportStar(require("./i18n/enUS"), exports);
45
51
  __exportStar(require("./i18n/zhCN"), exports);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Continent
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,5 +1,5 @@
1
1
  /**
2
- * Continent
2
+ * Address continent
3
3
  */
4
4
  export var AddressContinent;
5
5
  (function (AddressContinent) {
@@ -1,8 +1,9 @@
1
- import { AddressContinent } from './AddressContinent';
1
+ import { Currency } from '../business/Currency';
2
+ import { AddressContinent, AddressContinentId } from './AddressContinent';
2
3
  /**
3
- * Country or region interface
4
+ * Address region in database
4
5
  */
5
- export interface IAddressRegion {
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 continent: AddressContinent;
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: string;
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: string;
74
+ currency: Currency;
64
75
  languages: string[];
65
- name: string;
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
- constructor(id: string, id3: string, nid: string, continent: AddressContinent, exitCode: string, idd: string, currency: string, languages: string[], name?: string);
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
  }
@@ -4,7 +4,7 @@ import { AddressContinent } from './AddressContinent';
4
4
  */
5
5
  export class AddressRegion {
6
6
  // Typescript constructor shorthand
7
- constructor(id, id3, nid, continent, exitCode, idd, currency, languages, name = id) {
7
+ constructor(id, id3, nid, continent, exitCode, idd, currency, languages, label = id) {
8
8
  this.id = id;
9
9
  this.id3 = id3;
10
10
  this.nid = nid;
@@ -13,7 +13,8 @@ export class AddressRegion {
13
13
  this.idd = idd;
14
14
  this.currency = currency;
15
15
  this.languages = languages;
16
- this.name = name;
16
+ this.label = label;
17
+ this.continentId = AddressContinent[continent];
17
18
  }
18
19
  /**
19
20
  * Get country or region by id
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Address state
3
+ */
4
+ export declare type AddressState = {
5
+ /**
6
+ * Id
7
+ */
8
+ id: string;
9
+ /**
10
+ * Abbreviation
11
+ */
12
+ abbr?: string;
13
+ /**
14
+ * Name
15
+ */
16
+ label: string;
17
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -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,29 +1,9 @@
1
- import { DataTypes } from '@etsoo/shared';
2
- import { AddressRegion } from '..';
3
- import { AddressContinent } from './AddressContinent';
1
+ import { AddressRegion } from './AddressRegion';
4
2
  /**
5
3
  * Address utils
6
4
  */
7
5
  export var AddressUtils;
8
6
  (function (AddressUtils) {
9
- /**
10
- * Get all continents
11
- * @param func Label delegate
12
- * @param isNumberKey Is number key or key as id
13
- * @returns Continents
14
- */
15
- function getContinents(func, isNumberKey = false) {
16
- return DataTypes.getEnumKeys(AddressContinent).map((key) => {
17
- var _a;
18
- return ({
19
- id: isNumberKey
20
- ? DataTypes.getEnumByKey(AddressContinent, key)
21
- : key.toString(),
22
- label: (_a = func('continent' + key)) !== null && _a !== void 0 ? _a : key
23
- });
24
- });
25
- }
26
- AddressUtils.getContinents = getContinents;
27
7
  /**
28
8
  * Get region from regions and detected region and language
29
9
  * @param regions Supported regions
@@ -49,15 +29,4 @@ export var AddressUtils;
49
29
  return AddressRegion.getById(regions[0]);
50
30
  }
51
31
  AddressUtils.getRegion = getRegion;
52
- /**
53
- * Get region label
54
- * @param region Region id
55
- * @param func Label delegate
56
- * @returns Label
57
- */
58
- function getRegionLabel(region, func) {
59
- var _a;
60
- return (_a = func('region' + region)) !== null && _a !== void 0 ? _a : region;
61
- }
62
- AddressUtils.getRegionLabel = getRegionLabel;
63
32
  })(AddressUtils || (AddressUtils = {}));
@@ -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,7 +39,7 @@ 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
  /**
@@ -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
@@ -3,9 +3,7 @@ import { ApiDataError } from '@etsoo/restclient';
3
3
  import { DataTypes, DateUtils, DomUtils, NumberUtils, Utils } from '@etsoo/shared';
4
4
  import { AES, algo, enc, HmacSHA512, lib, mode, pad, PBKDF2, SHA3 } from 'crypto-js';
5
5
  import { AddressRegion } from '../address/AddressRegion';
6
- import { AddressUtils } from '../address/AddressUtils';
7
6
  import { BridgeUtils } from '../bridges/BridgeUtils';
8
- import { BusinessUtils } from '../business/BusinessUtils';
9
7
  import { EntityStatus } from '../business/EntityStatus';
10
8
  import { ActionResultError } from '../result/ActionResultError';
11
9
  import { appFields } from './IApp';
@@ -237,6 +235,8 @@ export class CoreApp {
237
235
  * @param api Api
238
236
  */
239
237
  setApi(api) {
238
+ // Base URL of the API
239
+ api.baseUrl = this.settings.endpoint;
240
240
  // onRequest, show loading or not, rewrite the property to override default action
241
241
  api.onRequest = (data) => {
242
242
  if (data.showLoading == null || data.showLoading) {
@@ -504,12 +504,20 @@ export class CoreApp {
504
504
  this._culture = name;
505
505
  // Hold the current resources
506
506
  this.settings.currentCulture = culture;
507
- // Update all supported regions' name
508
- this.settings.regions.forEach((id) => {
509
- const region = AddressRegion.getById(id);
510
- if (region)
511
- region.name = AddressUtils.getRegionLabel(id, this.labelDelegate);
512
- });
507
+ }
508
+ /**
509
+ * Check language is supported or not, return a valid language when supported
510
+ * @param language Language
511
+ * @returns Result
512
+ */
513
+ checkLanguage(language) {
514
+ if (language) {
515
+ 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)); });
516
+ if (item)
517
+ return item.name;
518
+ }
519
+ // Default language
520
+ return this.culture;
513
521
  }
514
522
  /**
515
523
  * Clear cache data
@@ -938,16 +946,6 @@ export class CoreApp {
938
946
  // settings.timeZone = Utils.getTimeZone()
939
947
  return (_a = this.settings.timeZone) !== null && _a !== void 0 ? _a : (_b = this.ipData) === null || _b === void 0 ? void 0 : _b.timezone;
940
948
  }
941
- /**
942
- * Get product unit and repeat option label
943
- * @param unit Product unit or repeat option
944
- * @param isJoined Add the join label like 'per Kg' for Kg
945
- */
946
- getUnitLabel(unit, isJoined) {
947
- if (unit == null)
948
- return '';
949
- return BusinessUtils.getUnitLabel(unit, this.labelDelegate, isJoined);
950
- }
951
949
  /**
952
950
  * Hash message, SHA3 or HmacSHA512, 512 as Base64
953
951
  * https://cryptojs.gitbook.io/docs/
@@ -1086,34 +1084,6 @@ export class CoreApp {
1086
1084
  // Go to login page
1087
1085
  this.toLoginPage();
1088
1086
  }
1089
- /**
1090
- * Get organization list
1091
- * @param items Max items
1092
- * @param serviceId Service id
1093
- * @returns Result
1094
- */
1095
- async orgList(items, serviceId) {
1096
- return await this.api.post('Organization/List', {
1097
- items,
1098
- serviceId
1099
- }, { defaultValue: [], showLoading: false });
1100
- }
1101
- /**
1102
- * Switch organization
1103
- * @param id Organization id
1104
- * @param serviceId Service id
1105
- */
1106
- async switchOrg(id, serviceId) {
1107
- const api = `Organization/Switch`;
1108
- const result = await this.api.put(api, {
1109
- id,
1110
- serviceId,
1111
- deviceId: this.deviceId
1112
- });
1113
- if (result)
1114
- return await this.refreshToken();
1115
- return result;
1116
- }
1117
1087
  /**
1118
1088
  * Go to the login page
1119
1089
  * @param tryLogin Try to login again
@@ -31,4 +31,5 @@ export declare namespace ExternalSettings {
31
31
  * Create instance
32
32
  */
33
33
  function Create(): IExternalSettings | undefined;
34
+ function format(settings: any, hostname?: string): any;
34
35
  }
@@ -12,17 +12,9 @@ export var ExternalSettings;
12
12
  if (typeof settings === 'object') {
13
13
  if (typeof window !== 'undefined') {
14
14
  // Host name
15
- let hostname = window.location.hostname;
16
- // Empty string returned under Electron
17
- if (hostname === '')
18
- hostname = 'localhost';
15
+ const hostname = globalThis.location.hostname;
19
16
  // replace {hostname}
20
- for (const key in settings) {
21
- const value = settings[key];
22
- if (typeof value === 'string') {
23
- settings[key] = value.replace('{hostname}', hostname);
24
- }
25
- }
17
+ format(settings, hostname);
26
18
  }
27
19
  return settings;
28
20
  }
@@ -30,4 +22,18 @@ export var ExternalSettings;
30
22
  return undefined;
31
23
  }
32
24
  ExternalSettings.Create = Create;
25
+ function format(settings, hostname) {
26
+ // Default hostname
27
+ if (!hostname)
28
+ hostname = 'localhost';
29
+ // replace {hostname}
30
+ for (const key in settings) {
31
+ const value = settings[key];
32
+ if (typeof value === 'string') {
33
+ settings[key] = value.replace('{hostname}', hostname);
34
+ }
35
+ }
36
+ return settings;
37
+ }
38
+ ExternalSettings.format = format;
33
39
  })(ExternalSettings || (ExternalSettings = {}));
@@ -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 } 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';
@@ -70,7 +69,7 @@ export interface IApp {
70
69
  */
71
70
  readonly fields: IAppFields;
72
71
  /**
73
- * API
72
+ * API, not recommend to use it directly in code, wrap to separate methods
74
73
  */
75
74
  readonly api: IApi;
76
75
  /**
@@ -163,6 +162,12 @@ export interface IApp {
163
162
  * @returns true means device is invalid
164
163
  */
165
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;
166
171
  /**
167
172
  * Clear cache data
168
173
  */
@@ -310,12 +315,6 @@ export interface IApp {
310
315
  * @returns Time zone
311
316
  */
312
317
  getTimeZone(): string | undefined;
313
- /**
314
- * Get product unit and repeat option label
315
- * @param unit Product unit or repeat option
316
- * @param isJoined Add the join label like 'per Kg' for Kg
317
- */
318
- getUnitLabel(unit?: ProductUnit, isJoined?: boolean): string;
319
318
  /**
320
319
  * Hash message, SHA3 or HmacSHA512, 512 as Base64
321
320
  * https://cryptojs.gitbook.io/docs/
@@ -367,23 +366,10 @@ export interface IApp {
367
366
  * Signout
368
367
  */
369
368
  signout(): Promise<void>;
370
- /**
371
- * Get organization list
372
- * @param items Max items
373
- * @param serviceId Service id
374
- * @returns Result
375
- */
376
- orgList(items?: number, serviceId?: number): Promise<ListType[] | undefined>;
377
369
  /**
378
370
  * Persist settings to source when application exit
379
371
  */
380
372
  persist(): void;
381
- /**
382
- * Switch organization
383
- * @param id Organization id
384
- * @param serviceId Service id
385
- */
386
- switchOrg(id: number, serviceId?: number): Promise<boolean | undefined>;
387
373
  /**
388
374
  * Go to the login page
389
375
  * @param tryLogin Try to login again
@@ -1,6 +1,4 @@
1
- import { DataTypes, ListType, ListType1 } from '@etsoo/shared';
2
- import { ICultureGet } from '../state/Culture';
3
- import { ProductUnit } from './ProductUnit';
1
+ import { DataTypes, ListType } from '@etsoo/shared';
4
2
  /**
5
3
  * Business utils
6
4
  */
@@ -13,13 +11,6 @@ export declare namespace BusinessUtils {
13
11
  * @returns Result
14
12
  */
15
13
  function formatAvatarTitle(title?: string, maxChars?: number, defaultTitle?: string): string;
16
- /**
17
- * Get currency collection
18
- * @param currencyNames Names like CNY, USD
19
- * @param func Label delegate
20
- * @returns Collection
21
- */
22
- function getCurrencies(currencyNames: string[], func: ICultureGet): ListType1[];
23
14
  /**
24
15
  * Get 12-month items
25
16
  * @param monthLabels Month labels
@@ -27,39 +18,6 @@ export declare namespace BusinessUtils {
27
18
  * @returns 12 months
28
19
  */
29
20
  function getMonths(monthLabels: string[], startMonth?: number): ListType[];
30
- /**
31
- * Get product unit's label
32
- * Please define the label in culture with key 'unitPC' for ProductUnit.PC like that
33
- * @param unit Unit
34
- * @param func Label delegate
35
- * @param isJoined Add the join label like 'per Kg' for Kg
36
- * @returns Label
37
- */
38
- function getUnitLabel(unit: ProductUnit, func: ICultureGet, isJoined?: boolean): string;
39
- /**
40
- * Get all product units
41
- * @param func Label delegate
42
- * @returns Units
43
- */
44
- function getUnits(func: ICultureGet): ListType[];
45
- /**
46
- *
47
- * Get all product units
48
- * @param func Label delegate
49
- * @param options Define the order and limit the items
50
- * @param isJoined Add the join label like 'per Kg' for Kg
51
- * @returns Units
52
- */
53
- function getUnits(func: ICultureGet, options?: string[], isJoined?: boolean): ListType[];
54
- /**
55
- *
56
- * Get all repeat options
57
- * @param func Label delegate
58
- * @param options Define the order and limit the items
59
- * @param isJoined Add the join label like 'per Kg' for Kg
60
- * @returns Units
61
- */
62
- function getRepeatOptions(func: ICultureGet, options?: string[], isJoined?: boolean): ListType[];
63
21
  /**
64
22
  * Set id value
65
23
  * @param item QueryRQ or TiplistRQ or similiar item