@etsoo/appscript 1.2.45 → 1.2.49
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/lib/cjs/app/CoreApp.d.ts +27 -29
- package/lib/cjs/app/CoreApp.js +49 -58
- package/lib/cjs/business/BusinessUtils.d.ts +8 -0
- package/lib/cjs/business/BusinessUtils.js +17 -0
- package/lib/cjs/i18n/en-US.json +15 -0
- package/lib/cjs/i18n/zh-CN.json +15 -0
- package/lib/cjs/i18n/zh-HK.json +15 -0
- package/lib/mjs/app/CoreApp.d.ts +27 -29
- package/lib/mjs/app/CoreApp.js +49 -58
- package/lib/mjs/business/BusinessUtils.d.ts +8 -0
- package/lib/mjs/business/BusinessUtils.js +17 -0
- package/lib/mjs/i18n/en-US.json +15 -0
- package/lib/mjs/i18n/zh-CN.json +15 -0
- package/lib/mjs/i18n/zh-HK.json +15 -0
- package/package.json +1 -1
- package/src/app/CoreApp.ts +70 -67
- package/src/business/BusinessUtils.ts +20 -0
- package/src/i18n/en-US.json +15 -0
- package/src/i18n/zh-CN.json +15 -0
- package/src/i18n/zh-HK.json +15 -0
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -6,6 +6,16 @@ import { AddressRegion } from '../address/AddressRegion';
|
|
|
6
6
|
import { AddressUtils } from '../address/AddressUtils';
|
|
7
7
|
import { BusinessUtils } from '../business/BusinessUtils';
|
|
8
8
|
import { ActionResultError } from '../result/ActionResultError';
|
|
9
|
+
/**
|
|
10
|
+
* App fields
|
|
11
|
+
*/
|
|
12
|
+
const appFields = [
|
|
13
|
+
'headerToken',
|
|
14
|
+
'serversideDeviceId',
|
|
15
|
+
'deviceId',
|
|
16
|
+
'devices',
|
|
17
|
+
'devicePassphrase'
|
|
18
|
+
];
|
|
9
19
|
/**
|
|
10
20
|
* Core application
|
|
11
21
|
*/
|
|
@@ -42,8 +52,10 @@ export class CoreApp {
|
|
|
42
52
|
this.notifier = notifier;
|
|
43
53
|
this.storage = storage;
|
|
44
54
|
this.name = name;
|
|
55
|
+
// Fields, attach with the name identifier
|
|
56
|
+
this.fields = appFields.reduce((a, v) => ({ ...a, [v]: 'smarterp-' + v + '-' + name }), {});
|
|
45
57
|
// Device id
|
|
46
|
-
this._deviceId = storage.getData(
|
|
58
|
+
this._deviceId = storage.getData(this.fields.deviceId, '');
|
|
47
59
|
// Restore
|
|
48
60
|
this.restore();
|
|
49
61
|
this.setApi(api);
|
|
@@ -115,10 +127,10 @@ export class CoreApp {
|
|
|
115
127
|
*/
|
|
116
128
|
get persistedFields() {
|
|
117
129
|
return [
|
|
118
|
-
|
|
119
|
-
this.
|
|
120
|
-
|
|
121
|
-
|
|
130
|
+
this.fields.deviceId,
|
|
131
|
+
this.fields.devicePassphrase,
|
|
132
|
+
this.fields.serversideDeviceId,
|
|
133
|
+
this.fields.headerToken
|
|
122
134
|
];
|
|
123
135
|
}
|
|
124
136
|
getDeviceId() {
|
|
@@ -126,23 +138,31 @@ export class CoreApp {
|
|
|
126
138
|
}
|
|
127
139
|
resetKeys() {
|
|
128
140
|
this.storage.clear([
|
|
129
|
-
this.
|
|
130
|
-
|
|
131
|
-
|
|
141
|
+
this.fields.devicePassphrase,
|
|
142
|
+
this.fields.headerToken,
|
|
143
|
+
this.fields.serversideDeviceId
|
|
132
144
|
], false);
|
|
133
145
|
this.passphrase = '';
|
|
134
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Add app name as identifier
|
|
149
|
+
* @param field Field
|
|
150
|
+
* @returns Result
|
|
151
|
+
*/
|
|
152
|
+
addIdentifier(field) {
|
|
153
|
+
return field + '-' + this.name;
|
|
154
|
+
}
|
|
135
155
|
/**
|
|
136
156
|
* Restore settings from persisted source
|
|
137
157
|
*/
|
|
138
158
|
restore() {
|
|
139
159
|
// Devices
|
|
140
|
-
const devices = this.storage.getPersistedData(
|
|
160
|
+
const devices = this.storage.getPersistedData(this.fields.devices, []);
|
|
141
161
|
if (this.deviceId === '') {
|
|
142
162
|
// First vist, restore and keep the source
|
|
143
163
|
this.storage.copyFrom(this.persistedFields, false);
|
|
144
164
|
// Reset device id
|
|
145
|
-
this._deviceId = this.storage.getData(
|
|
165
|
+
this._deviceId = this.storage.getData(this.fields.deviceId, '');
|
|
146
166
|
// Totally new, no data restored
|
|
147
167
|
if (this._deviceId === '')
|
|
148
168
|
return false;
|
|
@@ -156,13 +176,13 @@ export class CoreApp {
|
|
|
156
176
|
return false;
|
|
157
177
|
}
|
|
158
178
|
// this.name to identifier different app's secret
|
|
159
|
-
const passphraseEncrypted = this.storage.getData(this.
|
|
179
|
+
const passphraseEncrypted = this.storage.getData(this.fields.devicePassphrase);
|
|
160
180
|
if (passphraseEncrypted) {
|
|
161
181
|
const passphraseDecrypted = this.decrypt(passphraseEncrypted, this.name);
|
|
162
182
|
if (passphraseDecrypted != null) {
|
|
163
183
|
// Add the device to the list
|
|
164
184
|
devices.push(d);
|
|
165
|
-
this.storage.setPersistedData(
|
|
185
|
+
this.storage.setPersistedData(this.fields.devices, devices);
|
|
166
186
|
this.passphrase = passphraseDecrypted;
|
|
167
187
|
return true;
|
|
168
188
|
}
|
|
@@ -176,27 +196,19 @@ export class CoreApp {
|
|
|
176
196
|
*/
|
|
177
197
|
persist() {
|
|
178
198
|
// Devices
|
|
179
|
-
const devices = this.storage.getPersistedData(
|
|
199
|
+
const devices = this.storage.getPersistedData(this.fields.devices);
|
|
180
200
|
if (devices != null) {
|
|
181
201
|
const index = devices.indexOf(this.getDeviceId());
|
|
182
202
|
if (index !== -1) {
|
|
183
203
|
// Remove current device from the list
|
|
184
204
|
devices.splice(index, 1);
|
|
185
|
-
this.storage.setPersistedData(
|
|
205
|
+
this.storage.setPersistedData(this.fields.devices, devices);
|
|
186
206
|
}
|
|
187
207
|
}
|
|
188
208
|
if (!this.authorized)
|
|
189
209
|
return;
|
|
190
210
|
this.storage.copyTo(this.persistedFields);
|
|
191
211
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Add app name as identifier
|
|
194
|
-
* @param field Field
|
|
195
|
-
* @returns Result
|
|
196
|
-
*/
|
|
197
|
-
addIdentifier(field) {
|
|
198
|
-
return field + '-' + this.name;
|
|
199
|
-
}
|
|
200
212
|
/**
|
|
201
213
|
* Setup Api
|
|
202
214
|
* @param api Api
|
|
@@ -253,7 +265,7 @@ export class CoreApp {
|
|
|
253
265
|
return;
|
|
254
266
|
}
|
|
255
267
|
// Serverside encrypted device id
|
|
256
|
-
const identifier = this.storage.getData(
|
|
268
|
+
const identifier = this.storage.getData(this.fields.serversideDeviceId);
|
|
257
269
|
// Timestamp
|
|
258
270
|
const timestamp = new Date().getTime();
|
|
259
271
|
// Request data
|
|
@@ -289,7 +301,7 @@ export class CoreApp {
|
|
|
289
301
|
if (callback)
|
|
290
302
|
callback(false);
|
|
291
303
|
// Clear device id
|
|
292
|
-
this.storage.setData(
|
|
304
|
+
this.storage.setData(this.fields.deviceId, undefined);
|
|
293
305
|
return;
|
|
294
306
|
}
|
|
295
307
|
this.initCallUpdate(result.data, data.timestamp);
|
|
@@ -312,14 +324,14 @@ export class CoreApp {
|
|
|
312
324
|
return;
|
|
313
325
|
// Update device id and cache it
|
|
314
326
|
this._deviceId = data.deviceId;
|
|
315
|
-
this.storage.setData(
|
|
327
|
+
this.storage.setData(this.fields.deviceId, this._deviceId);
|
|
316
328
|
// Devices
|
|
317
|
-
const devices = this.storage.getPersistedData(
|
|
329
|
+
const devices = this.storage.getPersistedData(this.fields.devices, []);
|
|
318
330
|
devices.push(this.getDeviceId());
|
|
319
|
-
this.storage.setPersistedData(
|
|
331
|
+
this.storage.setPersistedData(this.fields.devices, devices);
|
|
320
332
|
// Current passphrase
|
|
321
333
|
this.passphrase = passphrase;
|
|
322
|
-
this.storage.setData(this.
|
|
334
|
+
this.storage.setData(this.fields.devicePassphrase, this.encrypt(passphrase, this.name));
|
|
323
335
|
// Previous passphrase
|
|
324
336
|
if (data.previousPassphrase) {
|
|
325
337
|
const prev = this.decrypt(data.previousPassphrase, timestamp.toString());
|
|
@@ -351,7 +363,7 @@ export class CoreApp {
|
|
|
351
363
|
* @returns Fields
|
|
352
364
|
*/
|
|
353
365
|
initCallEncryptedUpdateFields() {
|
|
354
|
-
return [
|
|
366
|
+
return [this.fields.headerToken];
|
|
355
367
|
}
|
|
356
368
|
/**
|
|
357
369
|
* Alert action result
|
|
@@ -376,7 +388,7 @@ export class CoreApp {
|
|
|
376
388
|
if (refreshToken !== '') {
|
|
377
389
|
if (refreshToken != null)
|
|
378
390
|
refreshToken = this.encrypt(refreshToken);
|
|
379
|
-
this.storage.setData(
|
|
391
|
+
this.storage.setData(this.fields.headerToken, refreshToken);
|
|
380
392
|
}
|
|
381
393
|
// Reset tryLogin state
|
|
382
394
|
this._isTryingLogin = false;
|
|
@@ -449,14 +461,14 @@ export class CoreApp {
|
|
|
449
461
|
*/
|
|
450
462
|
clearCacheData() {
|
|
451
463
|
this.clearCacheToken();
|
|
452
|
-
this.storage.setData(this.
|
|
464
|
+
this.storage.setData(this.fields.devicePassphrase, undefined);
|
|
453
465
|
}
|
|
454
466
|
/**
|
|
455
467
|
* Clear cached token
|
|
456
468
|
*/
|
|
457
469
|
clearCacheToken() {
|
|
458
470
|
this.cachedRefreshToken = undefined;
|
|
459
|
-
this.storage.setPersistedData(
|
|
471
|
+
this.storage.setPersistedData(this.fields.headerToken, undefined);
|
|
460
472
|
}
|
|
461
473
|
/**
|
|
462
474
|
* Decrypt message
|
|
@@ -711,7 +723,7 @@ export class CoreApp {
|
|
|
711
723
|
// Temp refresh token
|
|
712
724
|
if (this.cachedRefreshToken)
|
|
713
725
|
return this.cachedRefreshToken;
|
|
714
|
-
return this.storage.getData(
|
|
726
|
+
return this.storage.getData(this.fields.headerToken);
|
|
715
727
|
}
|
|
716
728
|
/**
|
|
717
729
|
* Get all regions
|
|
@@ -738,7 +750,7 @@ export class CoreApp {
|
|
|
738
750
|
*/
|
|
739
751
|
getResponseToken(rawResponse) {
|
|
740
752
|
const response = this.api.transformResponse(rawResponse);
|
|
741
|
-
return this.api.getHeaderValue(response.headers,
|
|
753
|
+
return this.api.getHeaderValue(response.headers, 'SmartERPRefreshToken');
|
|
742
754
|
}
|
|
743
755
|
/**
|
|
744
756
|
* Get time zone
|
|
@@ -941,8 +953,9 @@ export class CoreApp {
|
|
|
941
953
|
* Try login, returning false means is loading
|
|
942
954
|
* UI get involved while refreshToken not intended
|
|
943
955
|
* @param data Additional request data
|
|
956
|
+
* @param showLoading Show loading bar or not during call
|
|
944
957
|
*/
|
|
945
|
-
async tryLogin(_data) {
|
|
958
|
+
async tryLogin(_data, _showLoading) {
|
|
946
959
|
if (this._isTryingLogin)
|
|
947
960
|
return false;
|
|
948
961
|
this._isTryingLogin = true;
|
|
@@ -957,7 +970,7 @@ export class CoreApp {
|
|
|
957
970
|
userLogin(user, refreshToken, keep) {
|
|
958
971
|
this.userData = user;
|
|
959
972
|
// Cache the encrypted serverside device id
|
|
960
|
-
this.storage.setData(
|
|
973
|
+
this.storage.setData(this.fields.serversideDeviceId, user.deviceId);
|
|
961
974
|
if (keep) {
|
|
962
975
|
this.authorize(user.token, refreshToken);
|
|
963
976
|
}
|
|
@@ -994,25 +1007,3 @@ export class CoreApp {
|
|
|
994
1007
|
});
|
|
995
1008
|
}
|
|
996
1009
|
}
|
|
997
|
-
(function (CoreApp) {
|
|
998
|
-
/**
|
|
999
|
-
* Response token header field name
|
|
1000
|
-
*/
|
|
1001
|
-
CoreApp.headerTokenField = 'SmartERPRefreshToken';
|
|
1002
|
-
/**
|
|
1003
|
-
* Serverside device id encrypted field name
|
|
1004
|
-
*/
|
|
1005
|
-
CoreApp.serversideDeviceIdField = 'SmartERPServersideDeviceId';
|
|
1006
|
-
/**
|
|
1007
|
-
* Device id field name
|
|
1008
|
-
*/
|
|
1009
|
-
CoreApp.deviceIdField = 'SmartERPDeviceId';
|
|
1010
|
-
/**
|
|
1011
|
-
* Devices field name
|
|
1012
|
-
*/
|
|
1013
|
-
CoreApp.devicesField = 'SmartERPDevices';
|
|
1014
|
-
/**
|
|
1015
|
-
* Device passphrase field name
|
|
1016
|
-
*/
|
|
1017
|
-
CoreApp.devicePassphraseField = 'SmartERPDevicePassphrase';
|
|
1018
|
-
})(CoreApp || (CoreApp = {}));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DataTypes } from '@etsoo/shared';
|
|
1
2
|
import { IdLabelDto } from '../dto/IdLabelDto';
|
|
2
3
|
import { ICultureGet } from '../state/Culture';
|
|
3
4
|
import { EntityStatus } from './EntityStatus';
|
|
@@ -31,6 +32,13 @@ export declare namespace BusinessUtils {
|
|
|
31
32
|
id: EntityStatus;
|
|
32
33
|
label: string;
|
|
33
34
|
}[];
|
|
35
|
+
/**
|
|
36
|
+
* Get 12-month items
|
|
37
|
+
* @param monthLabels Month labels
|
|
38
|
+
* @param startMonth Start month, 0 as Jan.
|
|
39
|
+
* @returns 12 months
|
|
40
|
+
*/
|
|
41
|
+
function getMonths(monthLabels: string[], startMonth?: number): DataTypes.IdLabelItem[];
|
|
34
42
|
/**
|
|
35
43
|
* Get product unit's label
|
|
36
44
|
* Please define the label in culture with key 'unitPC' for ProductUnit.PC like that
|
|
@@ -52,6 +52,23 @@ export var BusinessUtils;
|
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
BusinessUtils.getEntityStatus = getEntityStatus;
|
|
55
|
+
/**
|
|
56
|
+
* Get 12-month items
|
|
57
|
+
* @param monthLabels Month labels
|
|
58
|
+
* @param startMonth Start month, 0 as Jan.
|
|
59
|
+
* @returns 12 months
|
|
60
|
+
*/
|
|
61
|
+
function getMonths(monthLabels, startMonth = 0) {
|
|
62
|
+
const months = [];
|
|
63
|
+
for (let i = 0; i < 12; i++) {
|
|
64
|
+
if (startMonth >= 12)
|
|
65
|
+
startMonth = 0;
|
|
66
|
+
months.push({ id: startMonth, label: monthLabels[startMonth] });
|
|
67
|
+
startMonth++;
|
|
68
|
+
}
|
|
69
|
+
return months;
|
|
70
|
+
}
|
|
71
|
+
BusinessUtils.getMonths = getMonths;
|
|
55
72
|
/**
|
|
56
73
|
* Get product unit's label
|
|
57
74
|
* Please define the label in culture with key 'unitPC' for ProductUnit.PC like that
|
package/lib/mjs/i18n/en-US.json
CHANGED
|
@@ -50,6 +50,20 @@
|
|
|
50
50
|
"message": "Message",
|
|
51
51
|
"mobile": "Mobile number",
|
|
52
52
|
"mobilePhones": "Mobile numbers",
|
|
53
|
+
"months": [
|
|
54
|
+
"Jan.",
|
|
55
|
+
"Feb.",
|
|
56
|
+
"Mar.",
|
|
57
|
+
"Apr.",
|
|
58
|
+
"May.",
|
|
59
|
+
"Jun.",
|
|
60
|
+
"Jul.",
|
|
61
|
+
"Aug.",
|
|
62
|
+
"Sep.",
|
|
63
|
+
"Oct.",
|
|
64
|
+
"Nov.",
|
|
65
|
+
"Dec."
|
|
66
|
+
],
|
|
53
67
|
"more": "More",
|
|
54
68
|
"moreTag": "{0} more",
|
|
55
69
|
"name": "Name",
|
|
@@ -67,6 +81,7 @@
|
|
|
67
81
|
"pageNotFound": "Page Not Found",
|
|
68
82
|
"prompt": "Input",
|
|
69
83
|
"pullToRefresh": "Pull down to refresh",
|
|
84
|
+
"quarters": ["Q1", "Q2", "Q3", "Q4"],
|
|
70
85
|
"record": "Record",
|
|
71
86
|
"refresh": "Refresh",
|
|
72
87
|
"refreshing": "Refreshing",
|
package/lib/mjs/i18n/zh-CN.json
CHANGED
|
@@ -50,6 +50,20 @@
|
|
|
50
50
|
"message": "留言",
|
|
51
51
|
"mobile": "手机号码",
|
|
52
52
|
"mobilePhones": "手机号码",
|
|
53
|
+
"months": [
|
|
54
|
+
"1月",
|
|
55
|
+
"2月",
|
|
56
|
+
"3月",
|
|
57
|
+
"4月",
|
|
58
|
+
"5月",
|
|
59
|
+
"6月",
|
|
60
|
+
"7月",
|
|
61
|
+
"8月",
|
|
62
|
+
"9月",
|
|
63
|
+
"10月",
|
|
64
|
+
"11月",
|
|
65
|
+
"12月"
|
|
66
|
+
],
|
|
53
67
|
"more": "更多",
|
|
54
68
|
"moreTag": "({0}+)",
|
|
55
69
|
"name": "姓名",
|
|
@@ -67,6 +81,7 @@
|
|
|
67
81
|
"pageNotFound": "找不到页面",
|
|
68
82
|
"prompt": "输入",
|
|
69
83
|
"pullToRefresh": "下拉刷新",
|
|
84
|
+
"quarters": ["一季度", "二季度", "三季度", "四季度"],
|
|
70
85
|
"record": "记录",
|
|
71
86
|
"refresh": "刷新",
|
|
72
87
|
"refreshing": "正在刷新",
|
package/lib/mjs/i18n/zh-HK.json
CHANGED
|
@@ -50,6 +50,20 @@
|
|
|
50
50
|
"message": "留言",
|
|
51
51
|
"mobilePhone": "手機號碼",
|
|
52
52
|
"mobilePhones": "手機號碼",
|
|
53
|
+
"months": [
|
|
54
|
+
"1月",
|
|
55
|
+
"2月",
|
|
56
|
+
"3月",
|
|
57
|
+
"4月",
|
|
58
|
+
"5月",
|
|
59
|
+
"6月",
|
|
60
|
+
"7月",
|
|
61
|
+
"8月",
|
|
62
|
+
"9月",
|
|
63
|
+
"10月",
|
|
64
|
+
"11月",
|
|
65
|
+
"12月"
|
|
66
|
+
],
|
|
53
67
|
"more": "更多",
|
|
54
68
|
"moreTag": "({0}+)",
|
|
55
69
|
"name": "姓名",
|
|
@@ -67,6 +81,7 @@
|
|
|
67
81
|
"pageNotFound": "找不到頁面",
|
|
68
82
|
"prompt": "輸入",
|
|
69
83
|
"pullToRefresh": "下拉刷新",
|
|
84
|
+
"quarters": ["一季度", "二季度", "三季度", "四季度"],
|
|
70
85
|
"record": "記錄",
|
|
71
86
|
"refresh": "刷新",
|
|
72
87
|
"refreshing": "正在刷新",
|