@etsoo/appscript 1.3.2 → 1.3.4

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 (94) 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 +8 -22
  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 +11 -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 +38 -0
  21. package/lib/cjs/erp/AddressApi.js +102 -0
  22. package/lib/cjs/erp/BaseApi.d.ts +12 -0
  23. package/lib/cjs/erp/BaseApi.js +16 -0
  24. package/lib/cjs/erp/OrgApi.d.ts +20 -0
  25. package/lib/cjs/erp/OrgApi.js +37 -0
  26. package/lib/cjs/erp/PublicApi.d.ts +75 -0
  27. package/lib/cjs/erp/PublicApi.js +118 -0
  28. package/lib/cjs/erp/dto/CurrencyDto.d.ts +6 -0
  29. package/lib/cjs/erp/dto/CurrencyDto.js +2 -0
  30. package/lib/cjs/erp/dto/ExchangeRateDto.d.ts +13 -0
  31. package/lib/cjs/erp/dto/ExchangeRateDto.js +2 -0
  32. package/lib/cjs/erp/dto/ExchangeRateHistoryDto.d.ts +8 -0
  33. package/lib/cjs/erp/dto/ExchangeRateHistoryDto.js +2 -0
  34. package/lib/cjs/erp/dto/PublicProductDto.d.ts +35 -0
  35. package/lib/cjs/erp/dto/PublicProductDto.js +2 -0
  36. package/lib/cjs/index.d.ts +6 -0
  37. package/lib/cjs/index.js +7 -0
  38. package/lib/mjs/address/AddressContinent.d.ts +5 -1
  39. package/lib/mjs/address/AddressContinent.js +1 -1
  40. package/lib/mjs/address/AddressRegion.d.ts +31 -15
  41. package/lib/mjs/address/AddressRegion.js +3 -2
  42. package/lib/mjs/address/AddressState.d.ts +17 -0
  43. package/lib/mjs/address/AddressState.js +1 -0
  44. package/lib/mjs/address/AddressUtils.d.ts +1 -17
  45. package/lib/mjs/address/AddressUtils.js +1 -32
  46. package/lib/mjs/app/CoreApp.d.ts +8 -22
  47. package/lib/mjs/app/CoreApp.js +16 -46
  48. package/lib/mjs/app/ExternalSettings.d.ts +1 -0
  49. package/lib/mjs/app/ExternalSettings.js +16 -10
  50. package/lib/mjs/app/IApp.d.ts +11 -21
  51. package/lib/mjs/business/BusinessUtils.d.ts +1 -43
  52. package/lib/mjs/business/BusinessUtils.js +0 -72
  53. package/lib/mjs/business/Currency.d.ts +8 -0
  54. package/lib/mjs/business/Currency.js +15 -0
  55. package/lib/mjs/erp/AddressApi.d.ts +38 -0
  56. package/lib/mjs/erp/AddressApi.js +75 -0
  57. package/lib/mjs/erp/BaseApi.d.ts +12 -0
  58. package/lib/mjs/erp/BaseApi.js +12 -0
  59. package/lib/mjs/erp/OrgApi.d.ts +20 -0
  60. package/lib/mjs/erp/OrgApi.js +33 -0
  61. package/lib/mjs/erp/PublicApi.d.ts +75 -0
  62. package/lib/mjs/erp/PublicApi.js +114 -0
  63. package/lib/mjs/erp/dto/CurrencyDto.d.ts +6 -0
  64. package/lib/mjs/erp/dto/CurrencyDto.js +1 -0
  65. package/lib/mjs/erp/dto/ExchangeRateDto.d.ts +13 -0
  66. package/lib/mjs/erp/dto/ExchangeRateDto.js +1 -0
  67. package/lib/mjs/erp/dto/ExchangeRateHistoryDto.d.ts +8 -0
  68. package/lib/mjs/erp/dto/ExchangeRateHistoryDto.js +1 -0
  69. package/lib/mjs/erp/dto/PublicProductDto.d.ts +35 -0
  70. package/lib/mjs/erp/dto/PublicProductDto.js +1 -0
  71. package/lib/mjs/index.d.ts +6 -0
  72. package/lib/mjs/index.js +7 -0
  73. package/package.json +2 -2
  74. package/src/address/AddressContinent.ts +6 -1
  75. package/src/address/AddressRegion.ts +36 -16
  76. package/src/address/AddressState.ts +19 -0
  77. package/src/address/AddressUtils.ts +1 -35
  78. package/src/app/CoreApp.ts +22 -57
  79. package/src/app/ExternalSettings.ts +17 -13
  80. package/src/app/IApp.ts +12 -25
  81. package/src/business/BusinessUtils.ts +1 -105
  82. package/src/business/Currency.ts +20 -0
  83. package/src/erp/AddressApi.ts +97 -0
  84. package/src/erp/BaseApi.ts +12 -0
  85. package/src/erp/OrgApi.ts +39 -0
  86. package/src/erp/PublicApi.ts +156 -0
  87. package/src/erp/dto/CurrencyDto.ts +7 -0
  88. package/src/erp/dto/ExchangeRateDto.ts +14 -0
  89. package/src/erp/dto/ExchangeRateHistoryDto.ts +9 -0
  90. package/src/erp/dto/PublicProductDto.ts +41 -0
  91. package/src/i18n/address.en-US.json +21 -0
  92. package/src/i18n/address.zh-CN.json +21 -0
  93. package/src/i18n/address.zh-HK.json +21 -0
  94. package/src/index.ts +8 -0
@@ -0,0 +1,156 @@
1
+ import { DataTypes, ListType, ListType1 } from '@etsoo/shared';
2
+ import { Currency } from '../business/Currency';
3
+ import { ProductUnit } from '../business/ProductUnit';
4
+ import { RepeatOption } from '../business/RepeatOption';
5
+ import { BaseApi } from './BaseApi';
6
+ import { CurrencyDto } from './dto/CurrencyDto';
7
+ import { ExchangeRateDto } from './dto/ExchangeRateDto';
8
+ import { ExchangeRateHistoryDto } from './dto/ExchangeRateHistoryDto';
9
+ import { PublicOrgProductDto, PublicProductDto } from './dto/PublicProductDto';
10
+
11
+ /**
12
+ * Public API
13
+ */
14
+ export class PublicApi extends BaseApi {
15
+ /**
16
+ * Get currencies
17
+ * @param currencyNames Limited currency names for local data, undefined will try to retrive remoately
18
+ * @returns Result
19
+ */
20
+ async currencies<T extends string[] | Currency[] | undefined>(
21
+ currencyNames?: T
22
+ ): Promise<T extends undefined ? CurrencyDto[] | undefined : ListType1[]> {
23
+ if (currencyNames == null)
24
+ return (await this.app.api.get<CurrencyDto[]>(
25
+ 'Public/GetCurrencies'
26
+ )) as any;
27
+ else
28
+ return currencyNames.map((name) => ({
29
+ id: name,
30
+ label: this.app.get(`currency${name}`) ?? name
31
+ })) as any;
32
+ }
33
+
34
+ /**
35
+ * Get exchange rate
36
+ * @param currency Currency
37
+ * @returns Result
38
+ */
39
+ exchangeRate(currency: Currency) {
40
+ return this.app.api.get<ExchangeRateDto>(
41
+ `Public/ExchangeRate/${currency}`
42
+ );
43
+ }
44
+
45
+ /**
46
+ * Get exchange rate history
47
+ * @param currencies Currencies
48
+ * @param months Max months
49
+ * @returns Result
50
+ */
51
+ exchangeRateHistory(currencies: Currency[], months?: number) {
52
+ return this.app.api.post<ExchangeRateHistoryDto[]>(
53
+ 'Public/ExchangeRateHistory',
54
+ { currencies, months },
55
+ { defaultValue: [] }
56
+ );
57
+ }
58
+
59
+ /**
60
+ * Get product unit's label
61
+ * Please define the label in culture with key 'unitPC' for ProductUnit.PC like that
62
+ * @param unit Unit
63
+ * @param isJoined Add the join label like 'per Kg' for Kg
64
+ * @returns Label
65
+ */
66
+ getUnitLabel(unit: ProductUnit, isJoined?: boolean | string) {
67
+ const key = ProductUnit[unit];
68
+ const label = this.app.get('unit' + key) ?? key;
69
+ const join = this.getUnitJoin(isJoined);
70
+ if (join) {
71
+ return join.format(label);
72
+ }
73
+ return label;
74
+ }
75
+
76
+ private getUnitJoin(isJoined: boolean | string | undefined) {
77
+ return typeof isJoined === 'string'
78
+ ? this.app.get(isJoined) ?? isJoined
79
+ : isJoined
80
+ ? this.app.get('unitJoin')
81
+ : undefined;
82
+ }
83
+
84
+ /**
85
+ * Get mobile base64 QRCode
86
+ * @param id User id
87
+ * @param host Host URL
88
+ */
89
+ mobileQRCode(id?: string, host?: string) {
90
+ return this.app.api.post<string>('Public/MobileQRCode', { id, host });
91
+ }
92
+
93
+ /**
94
+ * Get public and valid product data
95
+ * @param id Product/Service Id or Uid
96
+ * @param culture Language
97
+ * @returns Result
98
+ */
99
+ product<T extends number | string>(
100
+ id: T,
101
+ culture?: string
102
+ ): T extends number ? PublicProductDto : PublicOrgProductDto {
103
+ culture = this.app.checkLanguage(culture);
104
+ return this.app.api.post<PublicProductDto>(
105
+ `Public/Product/${id}/${culture}`
106
+ ) as any;
107
+ }
108
+
109
+ /**
110
+ *
111
+ * Get all repeat options
112
+ * @param options Define the order and limit the items
113
+ * @param isJoined Add the join label like 'per Kg' for Kg
114
+ * @returns Units
115
+ */
116
+ repeatOptions(options?: string[], isJoined: boolean = true): ListType[] {
117
+ options ??= DataTypes.getEnumKeys(RepeatOption);
118
+ return this.units(options, isJoined);
119
+ }
120
+
121
+ /**
122
+ * Get all product units
123
+ * @returns Units
124
+ */
125
+ units(): ListType[];
126
+
127
+ /**
128
+ *
129
+ * Get all product units
130
+ * @param options Define the order and limit the items
131
+ * @param isJoined Add the join label like 'per Kg' for Kg
132
+ * @returns Units
133
+ */
134
+ units(options?: string[], isJoined?: boolean): ListType[];
135
+
136
+ /**
137
+ *
138
+ * Get all product units
139
+ * @param options Define the order and limit the items
140
+ * @param isJoined Add the join label like 'per Kg' for Kg
141
+ * @returns Units
142
+ */
143
+ units(options?: string[], isJoined?: boolean | string): ListType[] {
144
+ options ??= DataTypes.getEnumKeys(ProductUnit);
145
+ return options.map((key) => {
146
+ const id = DataTypes.getEnumByKey(ProductUnit, key)! as number;
147
+ return {
148
+ id,
149
+ label: this.getUnitLabel(
150
+ id,
151
+ this.getUnitJoin(isJoined)
152
+ ).formatInitial(true)
153
+ };
154
+ });
155
+ }
156
+ }
@@ -0,0 +1,7 @@
1
+ import { ListType1 } from '@etsoo/shared';
2
+ import { ExchangeRateDto } from './ExchangeRateDto';
3
+
4
+ /**
5
+ * Currency data
6
+ */
7
+ export type CurrencyDto = ListType1 & ExchangeRateDto;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Exchange rate data
3
+ */
4
+ export type ExchangeRateDto = {
5
+ /**
6
+ * Exchange rate
7
+ */
8
+ exchangeRate: number;
9
+
10
+ /**
11
+ * Update time
12
+ */
13
+ updateTime: string | Date;
14
+ };
@@ -0,0 +1,9 @@
1
+ import { Currency } from '../../business/Currency';
2
+ import { ExchangeRateDto } from './ExchangeRateDto';
3
+
4
+ /**
5
+ * Exchange rate history data
6
+ */
7
+ export type ExchangeRateHistoryDto = ExchangeRateDto & {
8
+ id: Currency;
9
+ };
@@ -0,0 +1,41 @@
1
+ import { EntityStatus } from '../../business/EntityStatus';
2
+
3
+ /**
4
+ * Public product data
5
+ */
6
+ export type PublicProductDto = {
7
+ /**
8
+ * Id
9
+ */
10
+ id: number;
11
+
12
+ /**
13
+ * Name
14
+ */
15
+ name: string;
16
+
17
+ /**
18
+ * Logo
19
+ */
20
+ logo?: string;
21
+
22
+ /**
23
+ * Web URL for access
24
+ */
25
+ webUrl: string;
26
+ };
27
+
28
+ /**
29
+ * Public product with organization data
30
+ */
31
+ export type PublicOrgProductDto = PublicProductDto & {
32
+ /**
33
+ * Purchased service status
34
+ */
35
+ serviceEntityStatus?: EntityStatus;
36
+
37
+ /**
38
+ * Purchased service expiry
39
+ */
40
+ serviceExpiry?: string | Date;
41
+ };
@@ -0,0 +1,21 @@
1
+ {
2
+ "continentAF": "Africa",
3
+ "continentAN": "Antarctica",
4
+ "continentAS": "Asia",
5
+ "continentEU": "Europe",
6
+ "continentNA": "North America",
7
+ "continentOC": "Oceania",
8
+ "continentSA": "South America",
9
+ "regionAU": "Australia",
10
+ "regionCA": "Canada",
11
+ "regionCN": "Mainland China",
12
+ "regionDE": "Germany",
13
+ "regionFR": "France",
14
+ "regionGB": "United Kingdom",
15
+ "regionHK": "Hong Kong, China",
16
+ "regionIE": "Ireland",
17
+ "regionJP": "Japan",
18
+ "regionNZ": "New Zealand",
19
+ "regionSG": "Singapore",
20
+ "regionUS": "United States"
21
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "continentAF": "非洲",
3
+ "continentAN": "南极洲",
4
+ "continentAS": "亚洲",
5
+ "continentEU": "欧洲",
6
+ "continentNA": "北美洲",
7
+ "continentOC": "大洋洲",
8
+ "continentSA": "南美洲",
9
+ "regionAU": "澳大利亚",
10
+ "regionCA": "加拿大",
11
+ "regionCN": "中国大陆",
12
+ "regionDE": "德国",
13
+ "regionFR": "法国",
14
+ "regionGB": "英国",
15
+ "regionHK": "中国香港",
16
+ "regionIE": "爱尔兰",
17
+ "regionJP": "日本",
18
+ "regionNZ": "新西兰",
19
+ "regionSG": "新加坡",
20
+ "regionUS": "美国"
21
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "continentAF": "非洲",
3
+ "continentAN": "南極洲",
4
+ "continentAS": "亞洲",
5
+ "continentEU": "歐洲",
6
+ "continentNA": "北美洲",
7
+ "continentOC": "大洋洲",
8
+ "continentSA": "南美洲",
9
+ "regionAU": "澳大利亞",
10
+ "regionCA": "加拿大",
11
+ "regionCN": "中國大陸",
12
+ "regionDE": "德國",
13
+ "regionFR": "法國",
14
+ "regionGB": "英國",
15
+ "regionHK": "中國香港",
16
+ "regionIE": "愛爾蘭",
17
+ "regionJP": "日本",
18
+ "regionNZ": "新西蘭",
19
+ "regionSG": "新加坡",
20
+ "regionUS": "美國"
21
+ }
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  // address
2
2
  export * from './address/AddressContinent';
3
3
  export * from './address/AddressRegion';
4
+ export * from './address/AddressState';
4
5
  export * from './address/AddressUtils';
5
6
 
6
7
  // app
@@ -17,6 +18,7 @@ export * from './bridges/IBridgeHost';
17
18
  // business
18
19
  export * from './business/BusinessTax';
19
20
  export * from './business/BusinessUtils';
21
+ export * from './business/Currency';
20
22
  export * from './business/EntityStatus';
21
23
  export * from './business/ProductUnit';
22
24
  export * from './business/RepeatOption';
@@ -29,6 +31,12 @@ export * from './dto/IdLabelDto';
29
31
  export * from './dto/IdLabelPrimaryDto';
30
32
  export * from './dto/InitCallDto';
31
33
 
34
+ // erp
35
+ export * from './erp/AddressApi';
36
+ export * from './erp/BaseApi';
37
+ export * from './erp/OrgApi';
38
+ export * from './erp/PublicApi';
39
+
32
40
  // i18n
33
41
  export * from './i18n/enUS';
34
42
  export * from './i18n/zhCN';