@etsoo/appscript 1.4.76 → 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.
- package/__tests__/tsconfig.json +2 -2
- package/lib/cjs/app/CoreApp.js +32 -48
- package/lib/cjs/bridges/FlutterHost.js +5 -9
- package/lib/cjs/business/BusinessUtils.js +1 -2
- package/lib/cjs/business/ShoppingCart.js +7 -9
- package/lib/cjs/erp/AddressApi.js +18 -26
- package/lib/cjs/erp/AuthApi.js +2 -2
- package/lib/cjs/erp/EntityApi.js +1 -1
- package/lib/cjs/erp/OrgApi.js +2 -2
- package/lib/cjs/erp/PublicApi.js +16 -26
- package/lib/mjs/app/CoreApp.js +32 -48
- package/lib/mjs/bridges/FlutterHost.js +5 -9
- package/lib/mjs/business/BusinessUtils.js +1 -2
- package/lib/mjs/business/ShoppingCart.js +7 -9
- package/lib/mjs/erp/AddressApi.js +18 -26
- package/lib/mjs/erp/AuthApi.js +2 -2
- package/lib/mjs/erp/EntityApi.js +1 -1
- package/lib/mjs/erp/OrgApi.js +2 -2
- package/lib/mjs/erp/PublicApi.js +16 -26
- package/package.json +4 -4
- package/src/app/CoreApp.ts +8 -7
- package/tsconfig.cjs.json +1 -1
- package/tsconfig.json +2 -2
package/__tests__/tsconfig.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
3
|
+
"target": "ES2020",
|
|
4
4
|
"module": "ESNext",
|
|
5
5
|
"allowJs": true,
|
|
6
6
|
"skipLibCheck": true,
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"allowSyntheticDefaultImports": true,
|
|
9
9
|
"strict": true,
|
|
10
10
|
"forceConsistentCasingInFileNames": true,
|
|
11
|
-
"moduleResolution": "
|
|
11
|
+
"moduleResolution": "Bundler",
|
|
12
12
|
"resolveJsonModule": true,
|
|
13
13
|
"isolatedModules": true,
|
|
14
14
|
"noEmit": true,
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -35,6 +35,7 @@ const ActionResultError_1 = require("../result/ActionResultError");
|
|
|
35
35
|
const IApp_1 = require("./IApp");
|
|
36
36
|
const UserRole_1 = require("./UserRole");
|
|
37
37
|
let CJ;
|
|
38
|
+
const loadCrypto = () => Promise.resolve().then(() => __importStar(require('crypto-js')));
|
|
38
39
|
/**
|
|
39
40
|
* Core application
|
|
40
41
|
*/
|
|
@@ -125,7 +126,6 @@ class CoreApp {
|
|
|
125
126
|
* @param name Application name
|
|
126
127
|
*/
|
|
127
128
|
constructor(settings, api, notifier, storage, name) {
|
|
128
|
-
var _a;
|
|
129
129
|
/**
|
|
130
130
|
* Pending actions
|
|
131
131
|
*/
|
|
@@ -149,7 +149,7 @@ class CoreApp {
|
|
|
149
149
|
* Passphrase for encryption
|
|
150
150
|
*/
|
|
151
151
|
this.passphrase = '';
|
|
152
|
-
if (
|
|
152
|
+
if (settings?.regions?.length === 0) {
|
|
153
153
|
throw new Error('No regions defined');
|
|
154
154
|
}
|
|
155
155
|
this.settings = settings;
|
|
@@ -169,10 +169,7 @@ class CoreApp {
|
|
|
169
169
|
this.setApi(api);
|
|
170
170
|
const { currentCulture, currentRegion } = settings;
|
|
171
171
|
// Load resources
|
|
172
|
-
Promise.all([
|
|
173
|
-
Promise.resolve().then(() => __importStar(require('crypto-js'))),
|
|
174
|
-
this.changeCulture(currentCulture)
|
|
175
|
-
]).then(([cj, _resources]) => {
|
|
172
|
+
Promise.all([loadCrypto(), this.changeCulture(currentCulture)]).then(([cj, _resources]) => {
|
|
176
173
|
(CJ = cj), this.changeRegion(currentRegion);
|
|
177
174
|
this.setup();
|
|
178
175
|
});
|
|
@@ -356,7 +353,7 @@ class CoreApp {
|
|
|
356
353
|
* @param action Custom action
|
|
357
354
|
*/
|
|
358
355
|
setupLogging(action) {
|
|
359
|
-
action
|
|
356
|
+
action ?? (action = (data) => {
|
|
360
357
|
this.api.post('Auth/LogFrontendError', data, {
|
|
361
358
|
onError: (error) => {
|
|
362
359
|
// Use 'debug' to avoid infinite loop
|
|
@@ -402,7 +399,6 @@ class CoreApp {
|
|
|
402
399
|
* @returns Result
|
|
403
400
|
*/
|
|
404
401
|
async initCall(callback, resetKeys) {
|
|
405
|
-
var _a;
|
|
406
402
|
// Reset keys
|
|
407
403
|
if (resetKeys) {
|
|
408
404
|
this.clearDeviceId();
|
|
@@ -444,7 +440,7 @@ class CoreApp {
|
|
|
444
440
|
if (result.title === 'timeDifferenceInvalid' &&
|
|
445
441
|
seconds != null &&
|
|
446
442
|
validSeconds != null) {
|
|
447
|
-
const title =
|
|
443
|
+
const title = this.get('timeDifferenceInvalid')?.format(seconds.toString(), validSeconds.toString());
|
|
448
444
|
this.notifier.alert(title);
|
|
449
445
|
}
|
|
450
446
|
else {
|
|
@@ -544,7 +540,6 @@ class CoreApp {
|
|
|
544
540
|
* @param refreshToken Refresh token
|
|
545
541
|
*/
|
|
546
542
|
authorize(token, refreshToken) {
|
|
547
|
-
var _a;
|
|
548
543
|
// State, when token is null, means logout
|
|
549
544
|
this.authorized = token != null;
|
|
550
545
|
// Token
|
|
@@ -565,7 +560,7 @@ class CoreApp {
|
|
|
565
560
|
this.refreshCountdownClear();
|
|
566
561
|
}
|
|
567
562
|
// Host notice
|
|
568
|
-
|
|
563
|
+
BridgeUtils_1.BridgeUtils.host?.userAuthorization(this.authorized);
|
|
569
564
|
}
|
|
570
565
|
/**
|
|
571
566
|
* Change country or region
|
|
@@ -678,7 +673,7 @@ class CoreApp {
|
|
|
678
673
|
const salt = enc.Hex.parse(messageEncrypted.substring(2, 34));
|
|
679
674
|
const iv = enc.Hex.parse(messageEncrypted.substring(34, 66));
|
|
680
675
|
const encrypted = messageEncrypted.substring(66);
|
|
681
|
-
const key = PBKDF2(passphrase
|
|
676
|
+
const key = PBKDF2(passphrase ?? this.passphrase, salt, {
|
|
682
677
|
keySize: 8, // 256 / 32
|
|
683
678
|
hasher: algo.SHA256,
|
|
684
679
|
iterations: 1000 * iterations
|
|
@@ -721,7 +716,7 @@ class CoreApp {
|
|
|
721
716
|
return undefined;
|
|
722
717
|
}
|
|
723
718
|
const message = messageEncrypted.substring(pos + 1);
|
|
724
|
-
passphrase = this.encryptionEnhance(passphrase
|
|
719
|
+
passphrase = this.encryptionEnhance(passphrase ?? this.passphrase, timestamp);
|
|
725
720
|
return this.decrypt(message, passphrase);
|
|
726
721
|
}
|
|
727
722
|
catch (e) {
|
|
@@ -759,8 +754,7 @@ class CoreApp {
|
|
|
759
754
|
}
|
|
760
755
|
// Detect IP callbacks
|
|
761
756
|
detectIPCallbacks() {
|
|
762
|
-
|
|
763
|
-
(_a = this.ipDetectCallbacks) === null || _a === void 0 ? void 0 : _a.forEach((f) => f());
|
|
757
|
+
this.ipDetectCallbacks?.forEach((f) => f());
|
|
764
758
|
}
|
|
765
759
|
/**
|
|
766
760
|
* Download file
|
|
@@ -800,11 +794,11 @@ class CoreApp {
|
|
|
800
794
|
*/
|
|
801
795
|
encrypt(message, passphrase, iterations) {
|
|
802
796
|
// Default 1 * 1000
|
|
803
|
-
iterations
|
|
797
|
+
iterations ?? (iterations = 1);
|
|
804
798
|
const { lib, PBKDF2, algo, enc, AES, pad, mode } = CJ;
|
|
805
799
|
const bits = 16; // 128 / 8
|
|
806
800
|
const salt = lib.WordArray.random(bits);
|
|
807
|
-
const key = PBKDF2(passphrase
|
|
801
|
+
const key = PBKDF2(passphrase ?? this.passphrase, salt, {
|
|
808
802
|
keySize: 8, // 256 / 32
|
|
809
803
|
hasher: algo.SHA256,
|
|
810
804
|
iterations: 1000 * iterations
|
|
@@ -830,7 +824,7 @@ class CoreApp {
|
|
|
830
824
|
encryptEnhanced(message, passphrase, iterations) {
|
|
831
825
|
// Timestamp
|
|
832
826
|
const timestamp = shared_1.Utils.numberToChars(new Date().getTime());
|
|
833
|
-
passphrase = this.encryptionEnhance(passphrase
|
|
827
|
+
passphrase = this.encryptionEnhance(passphrase ?? this.passphrase, timestamp);
|
|
834
828
|
const result = this.encrypt(message, passphrase, iterations);
|
|
835
829
|
return timestamp + '!' + result;
|
|
836
830
|
}
|
|
@@ -865,7 +859,7 @@ class CoreApp {
|
|
|
865
859
|
*/
|
|
866
860
|
formatDate(input, options, timeZone) {
|
|
867
861
|
const { currentCulture, timeZone: defaultTimeZone } = this.settings;
|
|
868
|
-
timeZone
|
|
862
|
+
timeZone ?? (timeZone = defaultTimeZone);
|
|
869
863
|
return shared_1.DateUtils.format(input, currentCulture.name, options, timeZone);
|
|
870
864
|
}
|
|
871
865
|
/**
|
|
@@ -914,11 +908,11 @@ class CoreApp {
|
|
|
914
908
|
if (typeof result === 'object' &&
|
|
915
909
|
!(result instanceof restclient_1.ApiDataError) &&
|
|
916
910
|
this.checkDeviceResult(result)) {
|
|
917
|
-
initCallCallback
|
|
918
|
-
var _a;
|
|
911
|
+
initCallCallback ?? (initCallCallback = (result) => {
|
|
919
912
|
if (!result)
|
|
920
913
|
return;
|
|
921
|
-
this.notifier.alert(
|
|
914
|
+
this.notifier.alert(this.get('environmentChanged') ??
|
|
915
|
+
'Environment changed', () => {
|
|
922
916
|
// Reload the page
|
|
923
917
|
history.go(0);
|
|
924
918
|
});
|
|
@@ -942,9 +936,9 @@ class CoreApp {
|
|
|
942
936
|
*/
|
|
943
937
|
formatFullName(familyName, givenName) {
|
|
944
938
|
if (!familyName)
|
|
945
|
-
return givenName
|
|
939
|
+
return givenName ?? '';
|
|
946
940
|
if (!givenName)
|
|
947
|
-
return familyName
|
|
941
|
+
return familyName ?? '';
|
|
948
942
|
const wf = givenName + ' ' + familyName;
|
|
949
943
|
if (wf.containChinese() || wf.containJapanese() || wf.containKorean()) {
|
|
950
944
|
return familyName + givenName;
|
|
@@ -972,7 +966,6 @@ class CoreApp {
|
|
|
972
966
|
* @param forceToLocal Force to local labels
|
|
973
967
|
*/
|
|
974
968
|
formatResult(result, forceToLocal) {
|
|
975
|
-
var _a;
|
|
976
969
|
const title = result.title;
|
|
977
970
|
if (title && /^\w+$/.test(title)) {
|
|
978
971
|
const key = title.formatInitial(false);
|
|
@@ -990,7 +983,7 @@ class CoreApp {
|
|
|
990
983
|
result.title = this.get(key);
|
|
991
984
|
}
|
|
992
985
|
// When title contains {0}, replace with the field label
|
|
993
|
-
if (result.field &&
|
|
986
|
+
if (result.field && result.title?.includes('{0}')) {
|
|
994
987
|
const fieldLabel = this.get(result.field.formatInitial(false));
|
|
995
988
|
if (fieldLabel)
|
|
996
989
|
result.title = result.title.format(fieldLabel);
|
|
@@ -1019,7 +1012,7 @@ class CoreApp {
|
|
|
1019
1012
|
*/
|
|
1020
1013
|
getLabels(...keys) {
|
|
1021
1014
|
const init = {};
|
|
1022
|
-
return keys.reduce((a, v) =>
|
|
1015
|
+
return keys.reduce((a, v) => ({ ...a, [v]: this.get(v) ?? '' }), init);
|
|
1023
1016
|
}
|
|
1024
1017
|
/**
|
|
1025
1018
|
* Get bool items
|
|
@@ -1057,18 +1050,16 @@ class CoreApp {
|
|
|
1057
1050
|
* @returns List
|
|
1058
1051
|
*/
|
|
1059
1052
|
getEnumList(em, prefix, filter) {
|
|
1060
|
-
var _a;
|
|
1061
1053
|
const list = [];
|
|
1062
1054
|
const getKey = typeof prefix === 'function'
|
|
1063
1055
|
? prefix
|
|
1064
1056
|
: (key) => prefix + key;
|
|
1065
1057
|
if (Array.isArray(filter)) {
|
|
1066
1058
|
filter.forEach((id) => {
|
|
1067
|
-
var _a;
|
|
1068
1059
|
if (typeof id !== 'number')
|
|
1069
1060
|
return;
|
|
1070
1061
|
const key = shared_1.DataTypes.getEnumKey(em, id);
|
|
1071
|
-
const label =
|
|
1062
|
+
const label = this.get(getKey(key)) ?? key;
|
|
1072
1063
|
list.push({ id, label });
|
|
1073
1064
|
});
|
|
1074
1065
|
}
|
|
@@ -1084,7 +1075,7 @@ class CoreApp {
|
|
|
1084
1075
|
}
|
|
1085
1076
|
if (typeof id !== 'number')
|
|
1086
1077
|
continue;
|
|
1087
|
-
const label =
|
|
1078
|
+
const label = this.get(getKey(key)) ?? key;
|
|
1088
1079
|
list.push({ id, label });
|
|
1089
1080
|
}
|
|
1090
1081
|
}
|
|
@@ -1098,7 +1089,6 @@ class CoreApp {
|
|
|
1098
1089
|
* @returns List
|
|
1099
1090
|
*/
|
|
1100
1091
|
getEnumStrList(em, prefix, filter) {
|
|
1101
|
-
var _a;
|
|
1102
1092
|
const list = [];
|
|
1103
1093
|
const getKey = typeof prefix === 'function'
|
|
1104
1094
|
? prefix
|
|
@@ -1112,7 +1102,7 @@ class CoreApp {
|
|
|
1112
1102
|
continue;
|
|
1113
1103
|
id = fid;
|
|
1114
1104
|
}
|
|
1115
|
-
var label =
|
|
1105
|
+
var label = this.get(getKey(key)) ?? key;
|
|
1116
1106
|
list.push({ id: id.toString(), label });
|
|
1117
1107
|
}
|
|
1118
1108
|
return list;
|
|
@@ -1123,8 +1113,7 @@ class CoreApp {
|
|
|
1123
1113
|
* @returns Label
|
|
1124
1114
|
*/
|
|
1125
1115
|
getRegionLabel(id) {
|
|
1126
|
-
|
|
1127
|
-
return (_a = this.get('region' + id)) !== null && _a !== void 0 ? _a : id;
|
|
1116
|
+
return this.get('region' + id) ?? id;
|
|
1128
1117
|
}
|
|
1129
1118
|
/**
|
|
1130
1119
|
* Get all regions
|
|
@@ -1158,11 +1147,10 @@ class CoreApp {
|
|
|
1158
1147
|
* @param status Status value
|
|
1159
1148
|
*/
|
|
1160
1149
|
getStatusLabel(status) {
|
|
1161
|
-
var _a;
|
|
1162
1150
|
if (status == null)
|
|
1163
1151
|
return '';
|
|
1164
1152
|
const key = EntityStatus_1.EntityStatus[status];
|
|
1165
|
-
return
|
|
1153
|
+
return this.get('status' + key) ?? key;
|
|
1166
1154
|
}
|
|
1167
1155
|
/**
|
|
1168
1156
|
* Get refresh token from response headers
|
|
@@ -1178,9 +1166,8 @@ class CoreApp {
|
|
|
1178
1166
|
* @returns Time zone
|
|
1179
1167
|
*/
|
|
1180
1168
|
getTimeZone() {
|
|
1181
|
-
var _a, _b;
|
|
1182
1169
|
// settings.timeZone = Utils.getTimeZone()
|
|
1183
|
-
return
|
|
1170
|
+
return this.settings.timeZone ?? this.ipData?.timezone;
|
|
1184
1171
|
}
|
|
1185
1172
|
/**
|
|
1186
1173
|
* Hash message, SHA3 or HmacSHA512, 512 as Base64
|
|
@@ -1214,8 +1201,7 @@ class CoreApp {
|
|
|
1214
1201
|
* @returns Result
|
|
1215
1202
|
*/
|
|
1216
1203
|
hasPermission(roles) {
|
|
1217
|
-
|
|
1218
|
-
const userRole = (_a = this.userData) === null || _a === void 0 ? void 0 : _a.role;
|
|
1204
|
+
const userRole = this.userData?.role;
|
|
1219
1205
|
if (userRole == null)
|
|
1220
1206
|
return false;
|
|
1221
1207
|
if (Array.isArray(roles)) {
|
|
@@ -1257,7 +1243,7 @@ class CoreApp {
|
|
|
1257
1243
|
globalThis.history.go(to);
|
|
1258
1244
|
}
|
|
1259
1245
|
else {
|
|
1260
|
-
const { state, replace = false } = options
|
|
1246
|
+
const { state, replace = false } = options ?? {};
|
|
1261
1247
|
if (replace) {
|
|
1262
1248
|
if (state)
|
|
1263
1249
|
globalThis.history.replaceState(state, '', to);
|
|
@@ -1276,8 +1262,7 @@ class CoreApp {
|
|
|
1276
1262
|
* Callback where exit a page
|
|
1277
1263
|
*/
|
|
1278
1264
|
pageExit() {
|
|
1279
|
-
|
|
1280
|
-
(_a = this.lastWarning) === null || _a === void 0 ? void 0 : _a.dismiss();
|
|
1265
|
+
this.lastWarning?.dismiss();
|
|
1281
1266
|
}
|
|
1282
1267
|
/**
|
|
1283
1268
|
* Refresh countdown
|
|
@@ -1356,7 +1341,7 @@ class CoreApp {
|
|
|
1356
1341
|
* @param removeUrl Remove current URL for reuse
|
|
1357
1342
|
*/
|
|
1358
1343
|
toLoginPage(tryLogin, removeUrl) {
|
|
1359
|
-
const url = `/?tryLogin=${tryLogin
|
|
1344
|
+
const url = `/?tryLogin=${tryLogin ?? false}` +
|
|
1360
1345
|
(removeUrl ? '' : '&url=' + encodeURIComponent(location.href));
|
|
1361
1346
|
this.navigate(url);
|
|
1362
1347
|
}
|
|
@@ -1410,12 +1395,11 @@ class CoreApp {
|
|
|
1410
1395
|
* @param align Align, default as TopRight
|
|
1411
1396
|
*/
|
|
1412
1397
|
warning(message, align) {
|
|
1413
|
-
var _a, _b;
|
|
1414
1398
|
// Same message is open
|
|
1415
|
-
if (
|
|
1399
|
+
if (this.lastWarning?.open && this.lastWarning?.content === message)
|
|
1416
1400
|
return;
|
|
1417
1401
|
this.lastWarning = this.notifier.message(notificationbase_1.NotificationMessageType.Warning, message, undefined, {
|
|
1418
|
-
align: align
|
|
1402
|
+
align: align ?? notificationbase_1.NotificationAlign.TopRight
|
|
1419
1403
|
});
|
|
1420
1404
|
}
|
|
1421
1405
|
}
|
|
@@ -54,7 +54,6 @@ class FlutterHost {
|
|
|
54
54
|
this.cacheCommand('exit');
|
|
55
55
|
}
|
|
56
56
|
async getLabels(...keys) {
|
|
57
|
-
var _a;
|
|
58
57
|
// Try 500 miliseconds
|
|
59
58
|
let count = 5;
|
|
60
59
|
while (this.host.callHandler == null) {
|
|
@@ -66,14 +65,11 @@ class FlutterHost {
|
|
|
66
65
|
const init = {};
|
|
67
66
|
if (this.host.callHandler == null)
|
|
68
67
|
return init;
|
|
69
|
-
const result = (
|
|
70
|
-
return keys.reduce((a, v) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
[v]: (_a = result[v]) !== null && _a !== void 0 ? _a : ''
|
|
75
|
-
});
|
|
76
|
-
}, init);
|
|
68
|
+
const result = (await this.host.callHandler('getLabels')) ?? {};
|
|
69
|
+
return keys.reduce((a, v) => ({
|
|
70
|
+
...a,
|
|
71
|
+
[v]: result[v] ?? ''
|
|
72
|
+
}), init);
|
|
77
73
|
}
|
|
78
74
|
getStartUrl() {
|
|
79
75
|
return this.startUrl;
|
|
@@ -44,9 +44,8 @@ var BusinessUtils;
|
|
|
44
44
|
* @param data Data to format
|
|
45
45
|
*/
|
|
46
46
|
function formatCultues(cultures, data) {
|
|
47
|
-
var _a;
|
|
48
47
|
// Add the lost cultures
|
|
49
|
-
const allCultures =
|
|
48
|
+
const allCultures = data.cultures ?? [];
|
|
50
49
|
cultures.forEach((culture) => {
|
|
51
50
|
if (!allCultures.some((a) => a.id === culture.id)) {
|
|
52
51
|
allCultures.push({ id: culture.id, title: '' });
|
|
@@ -42,9 +42,9 @@ class ShoppingCart {
|
|
|
42
42
|
* @returns Result
|
|
43
43
|
*/
|
|
44
44
|
static getCartData(storage, id) {
|
|
45
|
-
var _a;
|
|
46
45
|
try {
|
|
47
|
-
return (
|
|
46
|
+
return (storage.getPersistedObject(id) ??
|
|
47
|
+
storage.getObject(id));
|
|
48
48
|
}
|
|
49
49
|
catch (error) {
|
|
50
50
|
console.warn(`ShoppingCart getCartData ${id} error`, error);
|
|
@@ -177,11 +177,11 @@ class ShoppingCart {
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
getCartData() {
|
|
180
|
-
|
|
181
|
-
|
|
180
|
+
return (this.storage.getPersistedObject(this.identifier) ??
|
|
181
|
+
this.storage.getObject(this.identifier));
|
|
182
182
|
}
|
|
183
183
|
setCartData(state) {
|
|
184
|
-
const { owner, items = [], promotions = [], formData, cache } = state
|
|
184
|
+
const { owner, items = [], promotions = [], formData, cache } = state ?? {};
|
|
185
185
|
this.owner = owner;
|
|
186
186
|
this.items = items;
|
|
187
187
|
this.promotions = promotions;
|
|
@@ -372,7 +372,6 @@ class ShoppingCart {
|
|
|
372
372
|
* @returns Updated or not
|
|
373
373
|
*/
|
|
374
374
|
updateAssetItem(id, assetQty, itemCreator) {
|
|
375
|
-
var _a;
|
|
376
375
|
if (assetQty == null || assetQty <= 0)
|
|
377
376
|
assetQty = 1;
|
|
378
377
|
const index = this.items.findIndex((item) => item.id === id);
|
|
@@ -399,7 +398,7 @@ class ShoppingCart {
|
|
|
399
398
|
// Update
|
|
400
399
|
const item = this.items[index];
|
|
401
400
|
// Price may be cached first
|
|
402
|
-
const price =
|
|
401
|
+
const price = this.prices[id] ?? item.price;
|
|
403
402
|
const qty = item.qty;
|
|
404
403
|
const newItem = {
|
|
405
404
|
...item,
|
|
@@ -422,7 +421,6 @@ class ShoppingCart {
|
|
|
422
421
|
* @returns Updated or not
|
|
423
422
|
*/
|
|
424
423
|
updateItem(id, qty, itemCreator) {
|
|
425
|
-
var _a;
|
|
426
424
|
const index = this.items.findIndex((item) => item.id === id);
|
|
427
425
|
if (qty == null) {
|
|
428
426
|
// Remove the item
|
|
@@ -452,7 +450,7 @@ class ShoppingCart {
|
|
|
452
450
|
// Update
|
|
453
451
|
const item = this.items[index];
|
|
454
452
|
// Price may be cached first
|
|
455
|
-
const price =
|
|
453
|
+
const price = this.prices[id] ?? item.price;
|
|
456
454
|
const newItem = {
|
|
457
455
|
...item,
|
|
458
456
|
qty,
|
|
@@ -17,10 +17,9 @@ class AddressApi extends BaseApi_1.BaseApi {
|
|
|
17
17
|
* @returns Result
|
|
18
18
|
*/
|
|
19
19
|
autocomplete(rq, payload) {
|
|
20
|
-
var _a;
|
|
21
20
|
if (rq.query === '')
|
|
22
21
|
return Promise.resolve(undefined);
|
|
23
|
-
|
|
22
|
+
rq.language ?? (rq.language = this.app.culture);
|
|
24
23
|
return this.api.post('Address/Autocomplete', rq, payload);
|
|
25
24
|
}
|
|
26
25
|
/**
|
|
@@ -45,8 +44,7 @@ class AddressApi extends BaseApi_1.BaseApi {
|
|
|
45
44
|
* @returns Label
|
|
46
45
|
*/
|
|
47
46
|
getContinentLabel(id) {
|
|
48
|
-
|
|
49
|
-
return (_a = this.app.get('continent' + id)) !== null && _a !== void 0 ? _a : id;
|
|
47
|
+
return this.app.get('continent' + id) ?? id;
|
|
50
48
|
}
|
|
51
49
|
/**
|
|
52
50
|
* Get region by id
|
|
@@ -72,7 +70,7 @@ class AddressApi extends BaseApi_1.BaseApi {
|
|
|
72
70
|
if (label === id) {
|
|
73
71
|
// Cache data, make sure called getRegions first
|
|
74
72
|
const regions = cachedRegions[this.app.culture];
|
|
75
|
-
const region = regions
|
|
73
|
+
const region = regions?.find((region) => region.id === id);
|
|
76
74
|
if (region)
|
|
77
75
|
return region.label;
|
|
78
76
|
}
|
|
@@ -83,8 +81,7 @@ class AddressApi extends BaseApi_1.BaseApi {
|
|
|
83
81
|
* @param rq Rquest data
|
|
84
82
|
*/
|
|
85
83
|
async getRegions(rq) {
|
|
86
|
-
|
|
87
|
-
const culture = (_a = rq === null || rq === void 0 ? void 0 : rq.culture) !== null && _a !== void 0 ? _a : this.app.culture;
|
|
84
|
+
const culture = rq?.culture ?? this.app.culture;
|
|
88
85
|
let regions = cachedRegions[culture];
|
|
89
86
|
if (regions == null) {
|
|
90
87
|
regions = await this.api.get(`Address/RegionList?language=${culture}`, undefined, { defaultValue: [], showLoading: false });
|
|
@@ -92,19 +89,16 @@ class AddressApi extends BaseApi_1.BaseApi {
|
|
|
92
89
|
return undefined;
|
|
93
90
|
cachedRegions[culture] = regions;
|
|
94
91
|
}
|
|
95
|
-
const { id, favoredIds = [], items = 8, keyword } = rq
|
|
92
|
+
const { id, favoredIds = [], items = 8, keyword } = rq ?? {};
|
|
96
93
|
// Id first
|
|
97
94
|
if (id) {
|
|
98
95
|
return regions.filter((region) => region.id === id);
|
|
99
96
|
}
|
|
100
97
|
// Keyword filter
|
|
101
98
|
if (keyword)
|
|
102
|
-
regions = regions.filter((region) =>
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
((_a = region.py) === null || _a === void 0 ? void 0 : _a.includes(keyword.toUpperCase())) ||
|
|
106
|
-
region.id === keyword.toUpperCase();
|
|
107
|
-
});
|
|
99
|
+
regions = regions.filter((region) => region.label.includes(keyword) ||
|
|
100
|
+
region.py?.includes(keyword.toUpperCase()) ||
|
|
101
|
+
region.id === keyword.toUpperCase());
|
|
108
102
|
// Order by favoredIds
|
|
109
103
|
if (favoredIds.length > 0) {
|
|
110
104
|
regions = shared_1.Utils.sortByFieldFavor([...regions], 'id', favoredIds);
|
|
@@ -118,10 +112,9 @@ class AddressApi extends BaseApi_1.BaseApi {
|
|
|
118
112
|
* @returns Result
|
|
119
113
|
*/
|
|
120
114
|
regionCurrency(regionId) {
|
|
121
|
-
|
|
122
|
-
const region = (_a = (regionId
|
|
115
|
+
const region = (regionId
|
|
123
116
|
? this.regions().find((region) => region.id === regionId)
|
|
124
|
-
: null)
|
|
117
|
+
: null) ?? this.app.settings.currentRegion;
|
|
125
118
|
return region.currency;
|
|
126
119
|
}
|
|
127
120
|
/**
|
|
@@ -154,8 +147,8 @@ class AddressApi extends BaseApi_1.BaseApi {
|
|
|
154
147
|
async states(regionId, favoredIds = [], payload, culture) {
|
|
155
148
|
if (regionId === '')
|
|
156
149
|
return Promise.resolve(undefined);
|
|
157
|
-
payload
|
|
158
|
-
culture
|
|
150
|
+
payload ?? (payload = { defaultValue: [], showLoading: false });
|
|
151
|
+
culture ?? (culture = this.app.culture);
|
|
159
152
|
var items = await this.api.get(`Address/StateList?regionId=${regionId}&language=${culture}`, undefined, payload);
|
|
160
153
|
if (items == null || favoredIds.length === 0)
|
|
161
154
|
return items;
|
|
@@ -173,8 +166,8 @@ class AddressApi extends BaseApi_1.BaseApi {
|
|
|
173
166
|
async cities(stateId, favoredIds = [], payload, culture) {
|
|
174
167
|
if (stateId === '')
|
|
175
168
|
return Promise.resolve(undefined);
|
|
176
|
-
payload
|
|
177
|
-
culture
|
|
169
|
+
payload ?? (payload = { defaultValue: [], showLoading: false });
|
|
170
|
+
culture ?? (culture = this.app.culture);
|
|
178
171
|
const items = await this.api.get(`Address/CityList?stateId=${stateId}&language=${culture}`, undefined, payload);
|
|
179
172
|
if (items == null || favoredIds.length === 0)
|
|
180
173
|
return items;
|
|
@@ -191,8 +184,8 @@ class AddressApi extends BaseApi_1.BaseApi {
|
|
|
191
184
|
async districts(cityId, favoredIds = [], payload, culture) {
|
|
192
185
|
if (cityId < 1)
|
|
193
186
|
return Promise.resolve(undefined);
|
|
194
|
-
payload
|
|
195
|
-
culture
|
|
187
|
+
payload ?? (payload = { defaultValue: [], showLoading: false });
|
|
188
|
+
culture ?? (culture = this.app.culture);
|
|
196
189
|
const items = await this.api.get(`Address/DistrictList?cityId=${cityId}&language=${culture}`, undefined, payload);
|
|
197
190
|
if (items == null || favoredIds.length === 0)
|
|
198
191
|
return items;
|
|
@@ -208,7 +201,7 @@ class AddressApi extends BaseApi_1.BaseApi {
|
|
|
208
201
|
GetPlaceDetails(placeId, language, payload) {
|
|
209
202
|
if (placeId === '')
|
|
210
203
|
return Promise.resolve(undefined);
|
|
211
|
-
language
|
|
204
|
+
language ?? (language = this.app.culture);
|
|
212
205
|
const url = `Address/GetPlaceDetails/${placeId}/${language}`;
|
|
213
206
|
return this.api.get(url, undefined, payload);
|
|
214
207
|
}
|
|
@@ -228,10 +221,9 @@ class AddressApi extends BaseApi_1.BaseApi {
|
|
|
228
221
|
* @returns Result
|
|
229
222
|
*/
|
|
230
223
|
searchPlace(rq, payload) {
|
|
231
|
-
var _a;
|
|
232
224
|
if (rq.query === '')
|
|
233
225
|
return Promise.resolve(undefined);
|
|
234
|
-
|
|
226
|
+
rq.language ?? (rq.language = this.app.culture);
|
|
235
227
|
return this.api.post('Address/SearchPlace', rq, payload);
|
|
236
228
|
}
|
|
237
229
|
}
|
package/lib/cjs/erp/AuthApi.js
CHANGED
|
@@ -13,9 +13,9 @@ class AuthApi extends BaseApi_1.BaseApi {
|
|
|
13
13
|
* @returns Result
|
|
14
14
|
*/
|
|
15
15
|
async loginBase(rq, payload) {
|
|
16
|
-
payload
|
|
16
|
+
payload ?? (payload = {});
|
|
17
17
|
const result = await this.api.post('Auth/Login', rq, payload);
|
|
18
|
-
const refreshToken =
|
|
18
|
+
const refreshToken = result?.ok
|
|
19
19
|
? this.app.getResponseToken(payload.response)
|
|
20
20
|
: null;
|
|
21
21
|
return [result, refreshToken];
|
package/lib/cjs/erp/EntityApi.js
CHANGED
|
@@ -73,7 +73,7 @@ class EntityApi extends BaseApi_1.BaseApi {
|
|
|
73
73
|
* @returns Result
|
|
74
74
|
*/
|
|
75
75
|
async queryFavoredCountryIdsBase(api) {
|
|
76
|
-
api
|
|
76
|
+
api ?? (api = `${this.flag}/QueryFavoredCountryIds`);
|
|
77
77
|
const result = await this.api.get(api, undefined, {
|
|
78
78
|
showLoading: false
|
|
79
79
|
});
|
package/lib/cjs/erp/OrgApi.js
CHANGED
|
@@ -21,7 +21,7 @@ class OrgApi extends EntityApi_1.EntityApi {
|
|
|
21
21
|
* @returns Result
|
|
22
22
|
*/
|
|
23
23
|
checkApiService(api, payload) {
|
|
24
|
-
payload
|
|
24
|
+
payload ?? (payload = { showLoading: false });
|
|
25
25
|
return this.api.get(`${this.flag}/CheckApiService`, { api }, payload);
|
|
26
26
|
}
|
|
27
27
|
list(items, serviceId) {
|
|
@@ -69,7 +69,7 @@ class OrgApi extends EntityApi_1.EntityApi {
|
|
|
69
69
|
*/
|
|
70
70
|
sendActionMessage(rq, payload) {
|
|
71
71
|
const appId = 'serviceId' in this.app.settings ? this.app.settings.serviceId : 0;
|
|
72
|
-
payload
|
|
72
|
+
payload ?? (payload = { showLoading: false });
|
|
73
73
|
return this.api.post('System/SendActionMessage', { ...rq, appId }, payload);
|
|
74
74
|
}
|
|
75
75
|
/**
|