@etsoo/appscript 1.4.77 → 1.4.78

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.
@@ -14,10 +14,9 @@ export class AddressApi extends BaseApi {
14
14
  * @returns Result
15
15
  */
16
16
  autocomplete(rq, payload) {
17
- var _a;
18
17
  if (rq.query === '')
19
18
  return Promise.resolve(undefined);
20
- (_a = rq.language) !== null && _a !== void 0 ? _a : (rq.language = this.app.culture);
19
+ rq.language ?? (rq.language = this.app.culture);
21
20
  return this.api.post('Address/Autocomplete', rq, payload);
22
21
  }
23
22
  /**
@@ -42,8 +41,7 @@ export class AddressApi extends BaseApi {
42
41
  * @returns Label
43
42
  */
44
43
  getContinentLabel(id) {
45
- var _a;
46
- return (_a = this.app.get('continent' + id)) !== null && _a !== void 0 ? _a : id;
44
+ return this.app.get('continent' + id) ?? id;
47
45
  }
48
46
  /**
49
47
  * Get region by id
@@ -69,7 +67,7 @@ export class AddressApi extends BaseApi {
69
67
  if (label === id) {
70
68
  // Cache data, make sure called getRegions first
71
69
  const regions = cachedRegions[this.app.culture];
72
- const region = regions === null || regions === void 0 ? void 0 : regions.find((region) => region.id === id);
70
+ const region = regions?.find((region) => region.id === id);
73
71
  if (region)
74
72
  return region.label;
75
73
  }
@@ -80,8 +78,7 @@ export class AddressApi extends BaseApi {
80
78
  * @param rq Rquest data
81
79
  */
82
80
  async getRegions(rq) {
83
- var _a;
84
- const culture = (_a = rq === null || rq === void 0 ? void 0 : rq.culture) !== null && _a !== void 0 ? _a : this.app.culture;
81
+ const culture = rq?.culture ?? this.app.culture;
85
82
  let regions = cachedRegions[culture];
86
83
  if (regions == null) {
87
84
  regions = await this.api.get(`Address/RegionList?language=${culture}`, undefined, { defaultValue: [], showLoading: false });
@@ -89,19 +86,16 @@ export class AddressApi extends BaseApi {
89
86
  return undefined;
90
87
  cachedRegions[culture] = regions;
91
88
  }
92
- const { id, favoredIds = [], items = 8, keyword } = rq !== null && rq !== void 0 ? rq : {};
89
+ const { id, favoredIds = [], items = 8, keyword } = rq ?? {};
93
90
  // Id first
94
91
  if (id) {
95
92
  return regions.filter((region) => region.id === id);
96
93
  }
97
94
  // Keyword filter
98
95
  if (keyword)
99
- regions = regions.filter((region) => {
100
- var _a;
101
- return region.label.includes(keyword) ||
102
- ((_a = region.py) === null || _a === void 0 ? void 0 : _a.includes(keyword.toUpperCase())) ||
103
- region.id === keyword.toUpperCase();
104
- });
96
+ regions = regions.filter((region) => region.label.includes(keyword) ||
97
+ region.py?.includes(keyword.toUpperCase()) ||
98
+ region.id === keyword.toUpperCase());
105
99
  // Order by favoredIds
106
100
  if (favoredIds.length > 0) {
107
101
  regions = Utils.sortByFieldFavor([...regions], 'id', favoredIds);
@@ -115,10 +109,9 @@ export class AddressApi extends BaseApi {
115
109
  * @returns Result
116
110
  */
117
111
  regionCurrency(regionId) {
118
- var _a;
119
- const region = (_a = (regionId
112
+ const region = (regionId
120
113
  ? this.regions().find((region) => region.id === regionId)
121
- : null)) !== null && _a !== void 0 ? _a : this.app.settings.currentRegion;
114
+ : null) ?? this.app.settings.currentRegion;
122
115
  return region.currency;
123
116
  }
124
117
  /**
@@ -151,8 +144,8 @@ export class AddressApi extends BaseApi {
151
144
  async states(regionId, favoredIds = [], payload, culture) {
152
145
  if (regionId === '')
153
146
  return Promise.resolve(undefined);
154
- payload !== null && payload !== void 0 ? payload : (payload = { defaultValue: [], showLoading: false });
155
- culture !== null && culture !== void 0 ? culture : (culture = this.app.culture);
147
+ payload ?? (payload = { defaultValue: [], showLoading: false });
148
+ culture ?? (culture = this.app.culture);
156
149
  var items = await this.api.get(`Address/StateList?regionId=${regionId}&language=${culture}`, undefined, payload);
157
150
  if (items == null || favoredIds.length === 0)
158
151
  return items;
@@ -170,8 +163,8 @@ export class AddressApi extends BaseApi {
170
163
  async cities(stateId, favoredIds = [], payload, culture) {
171
164
  if (stateId === '')
172
165
  return Promise.resolve(undefined);
173
- payload !== null && payload !== void 0 ? payload : (payload = { defaultValue: [], showLoading: false });
174
- culture !== null && culture !== void 0 ? culture : (culture = this.app.culture);
166
+ payload ?? (payload = { defaultValue: [], showLoading: false });
167
+ culture ?? (culture = this.app.culture);
175
168
  const items = await this.api.get(`Address/CityList?stateId=${stateId}&language=${culture}`, undefined, payload);
176
169
  if (items == null || favoredIds.length === 0)
177
170
  return items;
@@ -188,8 +181,8 @@ export class AddressApi extends BaseApi {
188
181
  async districts(cityId, favoredIds = [], payload, culture) {
189
182
  if (cityId < 1)
190
183
  return Promise.resolve(undefined);
191
- payload !== null && payload !== void 0 ? payload : (payload = { defaultValue: [], showLoading: false });
192
- culture !== null && culture !== void 0 ? culture : (culture = this.app.culture);
184
+ payload ?? (payload = { defaultValue: [], showLoading: false });
185
+ culture ?? (culture = this.app.culture);
193
186
  const items = await this.api.get(`Address/DistrictList?cityId=${cityId}&language=${culture}`, undefined, payload);
194
187
  if (items == null || favoredIds.length === 0)
195
188
  return items;
@@ -205,7 +198,7 @@ export class AddressApi extends BaseApi {
205
198
  GetPlaceDetails(placeId, language, payload) {
206
199
  if (placeId === '')
207
200
  return Promise.resolve(undefined);
208
- language !== null && language !== void 0 ? language : (language = this.app.culture);
201
+ language ?? (language = this.app.culture);
209
202
  const url = `Address/GetPlaceDetails/${placeId}/${language}`;
210
203
  return this.api.get(url, undefined, payload);
211
204
  }
@@ -225,10 +218,9 @@ export class AddressApi extends BaseApi {
225
218
  * @returns Result
226
219
  */
227
220
  searchPlace(rq, payload) {
228
- var _a;
229
221
  if (rq.query === '')
230
222
  return Promise.resolve(undefined);
231
- (_a = rq.language) !== null && _a !== void 0 ? _a : (rq.language = this.app.culture);
223
+ rq.language ?? (rq.language = this.app.culture);
232
224
  return this.api.post('Address/SearchPlace', rq, payload);
233
225
  }
234
226
  }
@@ -10,9 +10,9 @@ export class AuthApi extends BaseApi {
10
10
  * @returns Result
11
11
  */
12
12
  async loginBase(rq, payload) {
13
- payload !== null && payload !== void 0 ? payload : (payload = {});
13
+ payload ?? (payload = {});
14
14
  const result = await this.api.post('Auth/Login', rq, payload);
15
- const refreshToken = (result === null || result === void 0 ? void 0 : result.ok)
15
+ const refreshToken = result?.ok
16
16
  ? this.app.getResponseToken(payload.response)
17
17
  : null;
18
18
  return [result, refreshToken];
@@ -70,7 +70,7 @@ export class EntityApi extends BaseApi {
70
70
  * @returns Result
71
71
  */
72
72
  async queryFavoredCountryIdsBase(api) {
73
- api !== null && api !== void 0 ? api : (api = `${this.flag}/QueryFavoredCountryIds`);
73
+ api ?? (api = `${this.flag}/QueryFavoredCountryIds`);
74
74
  const result = await this.api.get(api, undefined, {
75
75
  showLoading: false
76
76
  });
@@ -18,7 +18,7 @@ export class OrgApi extends EntityApi {
18
18
  * @returns Result
19
19
  */
20
20
  checkApiService(api, payload) {
21
- payload !== null && payload !== void 0 ? payload : (payload = { showLoading: false });
21
+ payload ?? (payload = { showLoading: false });
22
22
  return this.api.get(`${this.flag}/CheckApiService`, { api }, payload);
23
23
  }
24
24
  list(items, serviceId) {
@@ -66,7 +66,7 @@ export class OrgApi extends EntityApi {
66
66
  */
67
67
  sendActionMessage(rq, payload) {
68
68
  const appId = 'serviceId' in this.app.settings ? this.app.settings.serviceId : 0;
69
- payload !== null && payload !== void 0 ? payload : (payload = { showLoading: false });
69
+ payload ?? (payload = { showLoading: false });
70
70
  return this.api.post('System/SendActionMessage', { ...rq, appId }, payload);
71
71
  }
72
72
  /**
@@ -39,22 +39,16 @@ export class PublicApi extends BaseApi {
39
39
  }
40
40
  currencies(names) {
41
41
  if (typeof names === 'boolean' && names) {
42
- return Currencies.map((name) => {
43
- var _a;
44
- return ({
45
- id: name,
46
- label: (_a = this.app.get(`currency${name}`)) !== null && _a !== void 0 ? _a : name
47
- });
48
- });
42
+ return Currencies.map((name) => ({
43
+ id: name,
44
+ label: this.app.get(`currency${name}`) ?? name
45
+ }));
49
46
  }
50
47
  if (Array.isArray(names)) {
51
- return names.map((name) => {
52
- var _a;
53
- return ({
54
- id: name,
55
- label: (_a = this.app.get(`currency${name}`)) !== null && _a !== void 0 ? _a : name
56
- });
57
- });
48
+ return names.map((name) => ({
49
+ id: name,
50
+ label: this.app.get(`currency${name}`) ?? name
51
+ }));
58
52
  }
59
53
  return this.api.get('Public/GetCurrencies', undefined, {
60
54
  defaultValue: [],
@@ -69,7 +63,7 @@ export class PublicApi extends BaseApi {
69
63
  * @returns Result
70
64
  */
71
65
  async exchangeAmount(amount, sourceCurrency, targetCurrency) {
72
- targetCurrency !== null && targetCurrency !== void 0 ? targetCurrency : (targetCurrency = this.app.defaultRegion.currency);
66
+ targetCurrency ?? (targetCurrency = this.app.defaultRegion.currency);
73
67
  const [sourceRate, targetRate] = await Promise.all([
74
68
  this.exchangeRate(sourceCurrency, {
75
69
  showLoading: false
@@ -112,7 +106,7 @@ export class PublicApi extends BaseApi {
112
106
  * @returns Result
113
107
  */
114
108
  exchangeRateHistory(currencies, months, payload) {
115
- payload !== null && payload !== void 0 ? payload : (payload = { defaultValue: [] });
109
+ payload ?? (payload = { defaultValue: [] });
116
110
  return this.api.post('Public/ExchangeRateHistory', { currencies, months }, payload);
117
111
  }
118
112
  /**
@@ -129,9 +123,8 @@ export class PublicApi extends BaseApi {
129
123
  * @returns Label
130
124
  */
131
125
  getCurrencyLabel(currency) {
132
- var _a;
133
126
  const c = `currency${currency}`;
134
- return (_a = this.app.get(c)) !== null && _a !== void 0 ? _a : c;
127
+ return this.app.get(c) ?? c;
135
128
  }
136
129
  /**
137
130
  * Get product unit's label
@@ -141,9 +134,8 @@ export class PublicApi extends BaseApi {
141
134
  * @returns Label
142
135
  */
143
136
  getUnitLabel(unit, isJoined) {
144
- var _a;
145
137
  const key = ProductUnit[unit];
146
- const label = (_a = this.app.get(unitPrefix + key)) !== null && _a !== void 0 ? _a : key;
138
+ const label = this.app.get(unitPrefix + key) ?? key;
147
139
  const join = this.getUnitJoin(isJoined);
148
140
  if (join) {
149
141
  return join.format(label);
@@ -151,9 +143,8 @@ export class PublicApi extends BaseApi {
151
143
  return label;
152
144
  }
153
145
  getUnitJoin(isJoined) {
154
- var _a;
155
146
  return typeof isJoined === 'string'
156
- ? (_a = this.app.get(isJoined)) !== null && _a !== void 0 ? _a : isJoined
147
+ ? this.app.get(isJoined) ?? isJoined
157
148
  : isJoined
158
149
  ? this.app.get('unitJoin')
159
150
  : undefined;
@@ -174,9 +165,8 @@ export class PublicApi extends BaseApi {
174
165
  * @returns Result
175
166
  */
176
167
  parsePin(input, payload) {
177
- var _a;
178
168
  const rq = typeof input === 'string' ? { pin: input } : input;
179
- (_a = rq.language) !== null && _a !== void 0 ? _a : (rq.language = this.app.culture);
169
+ rq.language ?? (rq.language = this.app.culture);
180
170
  return this.api.post('Public/ParsePin', rq, payload);
181
171
  }
182
172
  /**
@@ -198,7 +188,7 @@ export class PublicApi extends BaseApi {
198
188
  * @returns Units
199
189
  */
200
190
  repeatOptions(options, isJoined = true) {
201
- options !== null && options !== void 0 ? options : (options = DataTypes.getEnumKeys(RepeatOption));
191
+ options ?? (options = DataTypes.getEnumKeys(RepeatOption));
202
192
  return this.units(options, isJoined);
203
193
  }
204
194
  /**
@@ -217,7 +207,7 @@ export class PublicApi extends BaseApi {
217
207
  * @returns Units
218
208
  */
219
209
  units(options, isJoined) {
220
- options !== null && options !== void 0 ? options : (options = DataTypes.getEnumKeys(ProductUnit));
210
+ options ?? (options = DataTypes.getEnumKeys(ProductUnit));
221
211
  return options.map((key) => {
222
212
  const id = DataTypes.getEnumByKey(ProductUnit, key);
223
213
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.4.77",
3
+ "version": "1.4.78",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -52,9 +52,9 @@
52
52
  },
53
53
  "homepage": "https://github.com/ETSOO/AppScript#readme",
54
54
  "dependencies": {
55
- "@etsoo/notificationbase": "^1.1.35",
56
- "@etsoo/restclient": "^1.0.98",
57
- "@etsoo/shared": "^1.2.26",
55
+ "@etsoo/notificationbase": "^1.1.39",
56
+ "@etsoo/restclient": "^1.0.99",
57
+ "@etsoo/shared": "^1.2.28",
58
58
  "crypto-js": "^4.2.0"
59
59
  },
60
60
  "devDependencies": {
@@ -43,6 +43,9 @@ import type CryptoJS from 'crypto-js';
43
43
  import { Currency } from '../business/Currency';
44
44
 
45
45
  type CJType = typeof CryptoJS;
46
+ let CJ: CJType;
47
+
48
+ const loadCrypto = () => import('crypto-js');
46
49
 
47
50
  /**
48
51
  * Core application interface
@@ -214,8 +217,6 @@ export abstract class CoreApp<
214
217
 
215
218
  private _isTryingLogin = false;
216
219
 
217
- private CJ: CJType | null = null;
218
-
219
220
  /**
220
221
  * Last called with token refresh
221
222
  */
@@ -295,13 +296,12 @@ export abstract class CoreApp<
295
296
  const { currentCulture, currentRegion } = settings;
296
297
 
297
298
  // Load resources
298
- Promise.all([
299
- import('crypto-js'),
300
- this.changeCulture(currentCulture)
301
- ]).then(([cj, _resources]) => {
302
- (this.CJ = cj), this.changeRegion(currentRegion);
303
- this.setup();
304
- });
299
+ Promise.all([loadCrypto(), this.changeCulture(currentCulture)]).then(
300
+ ([cj, _resources]) => {
301
+ (CJ = cj), this.changeRegion(currentRegion);
302
+ this.setup();
303
+ }
304
+ );
305
305
  }
306
306
 
307
307
  private getDeviceId() {
@@ -919,7 +919,7 @@ export abstract class CoreApp<
919
919
  const iterations = parseInt(messageEncrypted.substring(0, 2), 10);
920
920
  if (isNaN(iterations)) return undefined;
921
921
 
922
- const { PBKDF2, algo, enc, AES, pad, mode } = this.CJ!;
922
+ const { PBKDF2, algo, enc, AES, pad, mode } = CJ;
923
923
 
924
924
  try {
925
925
  const salt = enc.Hex.parse(messageEncrypted.substring(2, 34));
@@ -1087,7 +1087,7 @@ export abstract class CoreApp<
1087
1087
  // Default 1 * 1000
1088
1088
  iterations ??= 1;
1089
1089
 
1090
- const { lib, PBKDF2, algo, enc, AES, pad, mode } = this.CJ!;
1090
+ const { lib, PBKDF2, algo, enc, AES, pad, mode } = CJ;
1091
1091
 
1092
1092
  const bits = 16; // 128 / 8
1093
1093
  const salt = lib.WordArray.random(bits);
@@ -1553,7 +1553,7 @@ export abstract class CoreApp<
1553
1553
  * @param passphrase Secret passphrase
1554
1554
  */
1555
1555
  hash(message: string, passphrase?: string) {
1556
- const { SHA3, enc, HmacSHA512 } = this.CJ!;
1556
+ const { SHA3, enc, HmacSHA512 } = CJ;
1557
1557
  if (passphrase == null)
1558
1558
  return SHA3(message, { outputLength: 512 }).toString(enc.Base64);
1559
1559
  else return HmacSHA512(message, passphrase).toString(enc.Base64);
@@ -1566,7 +1566,7 @@ export abstract class CoreApp<
1566
1566
  * @param passphrase Secret passphrase
1567
1567
  */
1568
1568
  hashHex(message: string, passphrase?: string) {
1569
- const { SHA3, enc, HmacSHA512 } = this.CJ!;
1569
+ const { SHA3, enc, HmacSHA512 } = CJ;
1570
1570
  if (passphrase == null)
1571
1571
  return SHA3(message, { outputLength: 512 }).toString(enc.Hex);
1572
1572
  else return HmacSHA512(message, passphrase).toString(enc.Hex);
package/tsconfig.cjs.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
- "target": "ES2019",
4
+ "target": "ES2020",
5
5
  "allowJs": false,
6
6
  "module": "commonjs",
7
7
  "moduleResolution": "node",
package/tsconfig.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
- "target": "ES2019",
4
+ "target": "ES2020",
5
5
  "allowJs": false,
6
6
  "module": "ESNext",
7
- "moduleResolution": "node",
7
+ "moduleResolution": "Bundler",
8
8
  "resolveJsonModule": true,
9
9
  "isolatedModules": true,
10
10
  "outDir": "./lib/mjs",