@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.
Files changed (89) 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 +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/index.d.ts +5 -0
  35. package/lib/cjs/index.js +6 -0
  36. package/lib/mjs/address/AddressContinent.d.ts +5 -1
  37. package/lib/mjs/address/AddressContinent.js +1 -1
  38. package/lib/mjs/address/AddressRegion.d.ts +31 -15
  39. package/lib/mjs/address/AddressRegion.js +3 -2
  40. package/lib/mjs/address/AddressState.d.ts +17 -0
  41. package/lib/mjs/address/AddressState.js +1 -0
  42. package/lib/mjs/address/AddressUtils.d.ts +1 -17
  43. package/lib/mjs/address/AddressUtils.js +1 -32
  44. package/lib/mjs/app/CoreApp.d.ts +8 -22
  45. package/lib/mjs/app/CoreApp.js +16 -46
  46. package/lib/mjs/app/ExternalSettings.d.ts +1 -0
  47. package/lib/mjs/app/ExternalSettings.js +16 -10
  48. package/lib/mjs/app/IApp.d.ts +11 -21
  49. package/lib/mjs/business/BusinessUtils.d.ts +1 -43
  50. package/lib/mjs/business/BusinessUtils.js +0 -72
  51. package/lib/mjs/business/Currency.d.ts +8 -0
  52. package/lib/mjs/business/Currency.js +15 -0
  53. package/lib/mjs/erp/AddressApi.d.ts +44 -0
  54. package/lib/mjs/erp/AddressApi.js +78 -0
  55. package/lib/mjs/erp/OrgApi.d.ts +26 -0
  56. package/lib/mjs/erp/OrgApi.js +39 -0
  57. package/lib/mjs/erp/PublicApi.d.ts +81 -0
  58. package/lib/mjs/erp/PublicApi.js +120 -0
  59. package/lib/mjs/erp/dto/CurrencyDto.d.ts +6 -0
  60. package/lib/mjs/erp/dto/CurrencyDto.js +1 -0
  61. package/lib/mjs/erp/dto/ExchangeRateDto.d.ts +13 -0
  62. package/lib/mjs/erp/dto/ExchangeRateDto.js +1 -0
  63. package/lib/mjs/erp/dto/ExchangeRateHistoryDto.d.ts +8 -0
  64. package/lib/mjs/erp/dto/ExchangeRateHistoryDto.js +1 -0
  65. package/lib/mjs/erp/dto/PublicProductDto.d.ts +35 -0
  66. package/lib/mjs/erp/dto/PublicProductDto.js +1 -0
  67. package/lib/mjs/index.d.ts +5 -0
  68. package/lib/mjs/index.js +6 -0
  69. package/package.json +2 -2
  70. package/src/address/AddressContinent.ts +6 -1
  71. package/src/address/AddressRegion.ts +36 -16
  72. package/src/address/AddressState.ts +19 -0
  73. package/src/address/AddressUtils.ts +1 -35
  74. package/src/app/CoreApp.ts +22 -57
  75. package/src/app/ExternalSettings.ts +17 -13
  76. package/src/app/IApp.ts +12 -25
  77. package/src/business/BusinessUtils.ts +1 -105
  78. package/src/business/Currency.ts +20 -0
  79. package/src/erp/AddressApi.ts +103 -0
  80. package/src/erp/OrgApi.ts +45 -0
  81. package/src/erp/PublicApi.ts +162 -0
  82. package/src/erp/dto/CurrencyDto.ts +7 -0
  83. package/src/erp/dto/ExchangeRateDto.ts +14 -0
  84. package/src/erp/dto/ExchangeRateHistoryDto.ts +9 -0
  85. package/src/erp/dto/PublicProductDto.ts +41 -0
  86. package/src/i18n/address.en-US.json +21 -0
  87. package/src/i18n/address.zh-CN.json +21 -0
  88. package/src/i18n/address.zh-HK.json +21 -0
  89. package/src/index.ts +7 -0
@@ -0,0 +1,162 @@
1
+ import { DataTypes, ListType, ListType1 } from '@etsoo/shared';
2
+ import { IApp } from '../app/IApp';
3
+ import { Currency } from '../business/Currency';
4
+ import { ProductUnit } from '../business/ProductUnit';
5
+ import { RepeatOption } from '../business/RepeatOption';
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 {
15
+ /**
16
+ * Constructor
17
+ * @param app Application
18
+ */
19
+ constructor(private app: IApp) {}
20
+
21
+ /**
22
+ * Get currencies
23
+ * @param currencyNames Limited currency names for local data, undefined will try to retrive remoately
24
+ * @returns Result
25
+ */
26
+ async currencies<T extends string[] | Currency[] | undefined>(
27
+ currencyNames?: T
28
+ ): Promise<T extends undefined ? CurrencyDto[] | undefined : ListType1[]> {
29
+ if (currencyNames == null)
30
+ return (await this.app.api.get<CurrencyDto[]>(
31
+ 'Public/GetCurrencies'
32
+ )) as any;
33
+ else
34
+ return currencyNames.map((name) => ({
35
+ id: name,
36
+ label: this.app.get(`currency${name}`) ?? name
37
+ })) as any;
38
+ }
39
+
40
+ /**
41
+ * Get exchange rate
42
+ * @param currency Currency
43
+ * @returns Result
44
+ */
45
+ exchangeRate(currency: Currency) {
46
+ return this.app.api.get<ExchangeRateDto>(
47
+ `Public/ExchangeRate/${currency}`
48
+ );
49
+ }
50
+
51
+ /**
52
+ * Get exchange rate history
53
+ * @param currencies Currencies
54
+ * @param months Max months
55
+ * @returns Result
56
+ */
57
+ exchangeRateHistory(currencies: Currency[], months?: number) {
58
+ return this.app.api.post<ExchangeRateHistoryDto[]>(
59
+ 'Public/ExchangeRateHistory',
60
+ { currencies, months },
61
+ { defaultValue: [] }
62
+ );
63
+ }
64
+
65
+ /**
66
+ * Get product unit's label
67
+ * Please define the label in culture with key 'unitPC' for ProductUnit.PC like that
68
+ * @param unit Unit
69
+ * @param isJoined Add the join label like 'per Kg' for Kg
70
+ * @returns Label
71
+ */
72
+ getUnitLabel(unit: ProductUnit, isJoined?: boolean | string) {
73
+ const key = ProductUnit[unit];
74
+ const label = this.app.get('unit' + key) ?? key;
75
+ const join = this.getUnitJoin(isJoined);
76
+ if (join) {
77
+ return join.format(label);
78
+ }
79
+ return label;
80
+ }
81
+
82
+ private getUnitJoin(isJoined: boolean | string | undefined) {
83
+ return typeof isJoined === 'string'
84
+ ? this.app.get(isJoined) ?? isJoined
85
+ : isJoined
86
+ ? this.app.get('unitJoin')
87
+ : undefined;
88
+ }
89
+
90
+ /**
91
+ * Get mobile base64 QRCode
92
+ * @param id User id
93
+ * @param host Host URL
94
+ */
95
+ mobileQRCode(id?: string, host?: string) {
96
+ return this.app.api.post<string>('Public/MobileQRCode', { id, host });
97
+ }
98
+
99
+ /**
100
+ * Get public and valid product data
101
+ * @param id Product/Service Id or Uid
102
+ * @param culture Language
103
+ * @returns Result
104
+ */
105
+ product<T extends number | string>(
106
+ id: T,
107
+ culture?: string
108
+ ): T extends number ? PublicProductDto : PublicOrgProductDto {
109
+ culture = this.app.checkLanguage(culture);
110
+ return this.app.api.post<PublicProductDto>(
111
+ `Public/Product/${id}/${culture}`
112
+ ) as any;
113
+ }
114
+
115
+ /**
116
+ *
117
+ * Get all repeat options
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
+ repeatOptions(options?: string[], isJoined: boolean = true): ListType[] {
123
+ options ??= DataTypes.getEnumKeys(RepeatOption);
124
+ return this.units(options, isJoined);
125
+ }
126
+
127
+ /**
128
+ * Get all product units
129
+ * @returns Units
130
+ */
131
+ units(): ListType[];
132
+
133
+ /**
134
+ *
135
+ * Get all product units
136
+ * @param options Define the order and limit the items
137
+ * @param isJoined Add the join label like 'per Kg' for Kg
138
+ * @returns Units
139
+ */
140
+ units(options?: string[], isJoined?: boolean): ListType[];
141
+
142
+ /**
143
+ *
144
+ * Get all product units
145
+ * @param options Define the order and limit the items
146
+ * @param isJoined Add the join label like 'per Kg' for Kg
147
+ * @returns Units
148
+ */
149
+ units(options?: string[], isJoined?: boolean | string): ListType[] {
150
+ options ??= DataTypes.getEnumKeys(ProductUnit);
151
+ return options.map((key) => {
152
+ const id = DataTypes.getEnumByKey(ProductUnit, key)! as number;
153
+ return {
154
+ id,
155
+ label: this.getUnitLabel(
156
+ id,
157
+ this.getUnitJoin(isJoined)
158
+ ).formatInitial(true)
159
+ };
160
+ });
161
+ }
162
+ }
@@ -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,11 @@ 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/OrgApi';
37
+ export * from './erp/PublicApi';
38
+
32
39
  // i18n
33
40
  export * from './i18n/enUS';
34
41
  export * from './i18n/zhCN';