@etsoo/appscript 1.1.3 → 1.1.7
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/.github/workflows/main.yml +1 -1
- package/README.md +63 -13
- package/lib/cjs/address/AddressUtils.d.ts +1 -1
- package/lib/cjs/address/AddressUtils.js +7 -10
- package/lib/cjs/app/AppSettings.d.ts +1 -1
- package/lib/cjs/app/CoreApp.d.ts +21 -6
- package/lib/cjs/app/CoreApp.js +32 -6
- package/lib/cjs/app/ExternalSettings.d.ts +1 -1
- package/lib/cjs/business/BusinessTax.d.ts +66 -0
- package/lib/cjs/business/BusinessTax.js +61 -0
- package/lib/cjs/business/BusinessUtils.js +2 -3
- package/lib/cjs/dto/IdDto.d.ts +1 -1
- package/lib/cjs/dto/IdLabelDto.d.ts +1 -1
- package/lib/cjs/dto/UpdateDto.d.ts +1 -1
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/mjs/address/AddressUtils.d.ts +1 -1
- package/lib/mjs/address/AddressUtils.js +8 -11
- package/lib/mjs/app/AppSettings.d.ts +1 -1
- package/lib/mjs/app/CoreApp.d.ts +21 -6
- package/lib/mjs/app/CoreApp.js +32 -6
- package/lib/mjs/app/ExternalSettings.d.ts +1 -1
- package/lib/mjs/business/BusinessTax.d.ts +66 -0
- package/lib/mjs/business/BusinessTax.js +57 -0
- package/lib/mjs/business/BusinessUtils.js +3 -4
- package/lib/mjs/dto/IdDto.d.ts +1 -1
- package/lib/mjs/dto/IdLabelDto.d.ts +1 -1
- package/lib/mjs/dto/UpdateDto.d.ts +1 -1
- package/lib/mjs/index.d.ts +1 -0
- package/lib/mjs/index.js +1 -0
- package/package.json +14 -14
- package/src/address/AddressUtils.ts +3 -3
- package/src/app/AppSettings.ts +1 -1
- package/src/app/CoreApp.ts +44 -7
- package/src/app/ExternalSettings.ts +1 -1
- package/src/business/BusinessTax.ts +86 -0
- package/src/business/BusinessUtils.ts +2 -2
- package/src/dto/IdDto.ts +1 -1
- package/src/dto/IdLabelDto.ts +1 -1
- package/src/dto/UpdateDto.ts +1 -1
- package/src/index.ts +1 -0
- package/tsconfig.cjs.json +1 -1
- package/tsconfig.json +1 -1
|
@@ -28,7 +28,7 @@ jobs:
|
|
|
28
28
|
# Setup .npmrc file to publish to npm
|
|
29
29
|
- uses: actions/setup-node@v1
|
|
30
30
|
with:
|
|
31
|
-
node-version: '14.
|
|
31
|
+
node-version: '14.18'
|
|
32
32
|
registry-url: 'https://registry.npmjs.org'
|
|
33
33
|
|
|
34
34
|
# Named after Continuous Integration, installs dependencies directly from package-lock.json
|
package/README.md
CHANGED
|
@@ -17,8 +17,33 @@ $ yarn add @etsoo/appscript
|
|
|
17
17
|
|
|
18
18
|
## Structure
|
|
19
19
|
|
|
20
|
+
### address - Address (region) related
|
|
21
|
+
|
|
22
|
+
#### AddressContinent.ts ####
|
|
23
|
+
- AddressContinent - Continent Enum
|
|
24
|
+
|
|
25
|
+
#### AddressRegion.ts ####
|
|
26
|
+
- IAddressRegion - Country or region interface
|
|
27
|
+
- AddressRegion - Address or region
|
|
28
|
+
|
|
29
|
+
#### AddressUtils.ts ####
|
|
30
|
+
- getContinents - Get all continents
|
|
31
|
+
- getRegion - Get region from regions and detected region and language
|
|
32
|
+
|
|
20
33
|
### app - Application related
|
|
21
34
|
|
|
35
|
+
#### AppSettings.ts ####
|
|
36
|
+
- IAppSettings - App settings interface
|
|
37
|
+
|
|
38
|
+
#### CoreApp.ts ####
|
|
39
|
+
- IDetectIPCallback - Detect IP callback interface
|
|
40
|
+
- ICoreApp - Core application interface
|
|
41
|
+
- CoreApp - Core application
|
|
42
|
+
|
|
43
|
+
#### ExternalSettings.ts ####
|
|
44
|
+
- IExternalSettings - External settings items
|
|
45
|
+
- IExternalSettingsHost - External settings host passed by external script
|
|
46
|
+
|
|
22
47
|
### bridges - Works with Electron
|
|
23
48
|
|
|
24
49
|
#### ElectronBridge.ts ####
|
|
@@ -28,35 +53,60 @@ $ yarn add @etsoo/appscript
|
|
|
28
53
|
- IAppData - App data interface.
|
|
29
54
|
|
|
30
55
|
#### IBridge.ts ####
|
|
31
|
-
- IBridgeUnsubscribe - Bridge unsubscribe interface
|
|
32
|
-
- IBridgeListener - Bridge listener interface
|
|
33
|
-
- IBridge - Bridge interface
|
|
56
|
+
- IBridgeUnsubscribe - Bridge unsubscribe interface
|
|
57
|
+
- IBridgeListener - Bridge listener interface
|
|
58
|
+
- IBridge - Bridge interface
|
|
59
|
+
|
|
60
|
+
### business - Business logics
|
|
61
|
+
|
|
62
|
+
#### BusinessTax.ts ####
|
|
63
|
+
- IBusinessTax - Business tax interface
|
|
64
|
+
- BusinessTax - Business tax
|
|
65
|
+
|
|
66
|
+
#### BusinessUtils.ts ####
|
|
67
|
+
- addIdLabelBlankItem - Add blank item to id/label data array
|
|
68
|
+
- getUnitLabel - Get product unit's label
|
|
69
|
+
- getUnits - Get all product units
|
|
70
|
+
|
|
71
|
+
#### ProductUnit.ts ####
|
|
72
|
+
- ProductUnit - Product units enum
|
|
73
|
+
|
|
74
|
+
### dto - Data transfer object
|
|
75
|
+
|
|
76
|
+
#### IdDto.ts ####
|
|
77
|
+
- IdDto - Dto with id field
|
|
78
|
+
|
|
79
|
+
#### IdLabelDto.ts ####
|
|
80
|
+
- IdLabelDto - Dto with id and label field
|
|
81
|
+
|
|
82
|
+
#### UpdateDto.ts ####
|
|
83
|
+
- UpdateDto - Dto with id and changedFields
|
|
34
84
|
|
|
35
85
|
### result - API action result
|
|
36
86
|
|
|
37
87
|
#### ActionResult.ts ####
|
|
38
|
-
- ActionResult - API call action result extends IActionResult
|
|
88
|
+
- ActionResult - API call action result extends IActionResult
|
|
39
89
|
|
|
40
90
|
#### ActionResultError.ts ####
|
|
41
91
|
- ActionResultError - Action result to error type.
|
|
42
92
|
|
|
43
93
|
#### IActionResult.ts ####
|
|
44
|
-
- IResultData - Result data interface
|
|
45
|
-
- IdResultData - extends IResultData for 'id' included return data
|
|
46
|
-
- IResultErrors - Result errors interface
|
|
47
|
-
- IActionResult - Action result interface
|
|
94
|
+
- IResultData - Result data interface
|
|
95
|
+
- IdResultData - extends IResultData for 'id' included return data
|
|
96
|
+
- IResultErrors - Result errors interface
|
|
97
|
+
- IActionResult - Action result interface
|
|
48
98
|
- ActionResultId - Action result with id data
|
|
49
99
|
|
|
50
100
|
### state - State management
|
|
51
101
|
|
|
52
|
-
####
|
|
53
|
-
-
|
|
54
|
-
-
|
|
102
|
+
#### Culture.ts ####
|
|
103
|
+
- ICulture - Culture resources state, simple i18n solution
|
|
104
|
+
- ICultureGet - Culture get delegate
|
|
55
105
|
|
|
56
106
|
#### State.ts ####
|
|
57
107
|
- IState - state interface.
|
|
58
|
-
- IAction - state action interface
|
|
108
|
+
- IAction - state action interface
|
|
59
109
|
|
|
60
110
|
#### User.ts ####
|
|
61
111
|
- IUserData - User basic data.
|
|
62
|
-
- IUser - extends IState for user state
|
|
112
|
+
- IUser - extends IState for user state
|
|
@@ -13,7 +13,7 @@ export declare namespace AddressUtils {
|
|
|
13
13
|
*/
|
|
14
14
|
function getContinents(func: ICultureGet, isNumberKey?: boolean): IdLabelDto[];
|
|
15
15
|
/**
|
|
16
|
-
* Get region
|
|
16
|
+
* Get region from regions and detected region and language
|
|
17
17
|
* @param regions Supported regions
|
|
18
18
|
* @param detectedRegion Detected region
|
|
19
19
|
* @param detectedLanguage Detected language
|
|
@@ -16,19 +16,16 @@ var AddressUtils;
|
|
|
16
16
|
* @returns Continents
|
|
17
17
|
*/
|
|
18
18
|
function getContinents(func, isNumberKey = false) {
|
|
19
|
-
return shared_1.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
label: (_a = func('continent' + key)) !== null && _a !== void 0 ? _a : key
|
|
26
|
-
});
|
|
27
|
-
});
|
|
19
|
+
return shared_1.DataTypes.getEnumKeys(AddressContinent_1.AddressContinent).map((key) => ({
|
|
20
|
+
id: isNumberKey
|
|
21
|
+
? AddressContinent_1.AddressContinent[key]
|
|
22
|
+
: key,
|
|
23
|
+
label: func('continent' + key) ?? key
|
|
24
|
+
}));
|
|
28
25
|
}
|
|
29
26
|
AddressUtils.getContinents = getContinents;
|
|
30
27
|
/**
|
|
31
|
-
* Get region
|
|
28
|
+
* Get region from regions and detected region and language
|
|
32
29
|
* @param regions Supported regions
|
|
33
30
|
* @param detectedRegion Detected region
|
|
34
31
|
* @param detectedLanguage Detected language
|
|
@@ -3,7 +3,7 @@ import { DataTypes } from '@etsoo/shared';
|
|
|
3
3
|
import { AddressRegion } from '../address/AddressRegion';
|
|
4
4
|
import { IExternalSettings } from './ExternalSettings';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* App settings interface
|
|
7
7
|
*/
|
|
8
8
|
export interface IAppSettings extends IExternalSettings {
|
|
9
9
|
/**
|
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
30
30
|
/**
|
|
31
31
|
* Label delegate
|
|
32
32
|
*/
|
|
33
|
-
readonly labelDelegate: <T
|
|
33
|
+
readonly labelDelegate: <T = string>(key: string) => T | undefined;
|
|
34
34
|
/**
|
|
35
35
|
* Culture, like zh-CN
|
|
36
36
|
*/
|
|
@@ -43,6 +43,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
43
43
|
* Country or region, like CN
|
|
44
44
|
*/
|
|
45
45
|
readonly region: string;
|
|
46
|
+
/**
|
|
47
|
+
* Is current authorized
|
|
48
|
+
*/
|
|
49
|
+
readonly authorized: boolean;
|
|
46
50
|
/**
|
|
47
51
|
* IP data
|
|
48
52
|
*/
|
|
@@ -110,7 +114,7 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
110
114
|
* @param key key
|
|
111
115
|
* @returns Resource
|
|
112
116
|
*/
|
|
113
|
-
get<T
|
|
117
|
+
get<T = string>(key: string): T | undefined;
|
|
114
118
|
/**
|
|
115
119
|
* Get multiple culture labels
|
|
116
120
|
* @param keys Keys
|
|
@@ -149,6 +153,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
149
153
|
* @returns Transformed url
|
|
150
154
|
*/
|
|
151
155
|
transformUrl(url: string): string;
|
|
156
|
+
/**
|
|
157
|
+
* Try login, returning false means is loading
|
|
158
|
+
*/
|
|
159
|
+
tryLogin(): boolean;
|
|
152
160
|
/**
|
|
153
161
|
* User login
|
|
154
162
|
* @param user User data
|
|
@@ -195,7 +203,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
195
203
|
/**
|
|
196
204
|
* Label delegate
|
|
197
205
|
*/
|
|
198
|
-
get labelDelegate(): <T
|
|
206
|
+
get labelDelegate(): <T = string>(key: string) => T | undefined;
|
|
199
207
|
/**
|
|
200
208
|
* IP data
|
|
201
209
|
*/
|
|
@@ -213,6 +221,13 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
213
221
|
* Search input element
|
|
214
222
|
*/
|
|
215
223
|
searchInput?: HTMLInputElement;
|
|
224
|
+
private _authorized;
|
|
225
|
+
/**
|
|
226
|
+
* Is current authorized
|
|
227
|
+
*/
|
|
228
|
+
get authorized(): boolean;
|
|
229
|
+
private set authorized(value);
|
|
230
|
+
private _isTryingLogin;
|
|
216
231
|
/**
|
|
217
232
|
* Protected constructor
|
|
218
233
|
* @param settings Settings
|
|
@@ -282,7 +297,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
282
297
|
* @param key key
|
|
283
298
|
* @returns Resource
|
|
284
299
|
*/
|
|
285
|
-
get<T
|
|
300
|
+
get<T = string>(key: string): T | undefined;
|
|
286
301
|
/**
|
|
287
302
|
* Get multiple culture labels
|
|
288
303
|
* @param keys Keys
|
|
@@ -326,9 +341,9 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
326
341
|
*/
|
|
327
342
|
transformUrl(url: string): string;
|
|
328
343
|
/**
|
|
329
|
-
* Try login
|
|
344
|
+
* Try login, returning false means is loading
|
|
330
345
|
*/
|
|
331
|
-
|
|
346
|
+
tryLogin(): boolean;
|
|
332
347
|
/**
|
|
333
348
|
* User login
|
|
334
349
|
* @param user User data
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -19,6 +19,8 @@ class CoreApp {
|
|
|
19
19
|
* Response token header field name
|
|
20
20
|
*/
|
|
21
21
|
this.headerTokenField = 'SmartERPRefreshToken';
|
|
22
|
+
this._authorized = false;
|
|
23
|
+
this._isTryingLogin = false;
|
|
22
24
|
// onRequest, show loading or not, rewrite the property to override default action
|
|
23
25
|
api.onRequest = (data) => {
|
|
24
26
|
if (data.showLoading == null || data.showLoading) {
|
|
@@ -79,6 +81,15 @@ class CoreApp {
|
|
|
79
81
|
get labelDelegate() {
|
|
80
82
|
return this.get.bind(this);
|
|
81
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Is current authorized
|
|
86
|
+
*/
|
|
87
|
+
get authorized() {
|
|
88
|
+
return this._authorized;
|
|
89
|
+
}
|
|
90
|
+
set authorized(value) {
|
|
91
|
+
this._authorized = value;
|
|
92
|
+
}
|
|
82
93
|
/**
|
|
83
94
|
* Alert action result
|
|
84
95
|
* @param result Action result
|
|
@@ -93,10 +104,15 @@ class CoreApp {
|
|
|
93
104
|
* @param keep Keep in local storage or not
|
|
94
105
|
*/
|
|
95
106
|
authorize(token, refreshToken, keep = false) {
|
|
107
|
+
// State, when token is null, means logout
|
|
108
|
+
this.authorized = token != null;
|
|
109
|
+
// Token
|
|
96
110
|
this.api.authorize(this.settings.authScheme, token);
|
|
97
111
|
// Cover the current value
|
|
98
112
|
shared_1.StorageUtils.setLocalData(this.headerTokenField, keep ? refreshToken : undefined);
|
|
99
113
|
shared_1.StorageUtils.setSessionData(this.headerTokenField, keep ? undefined : refreshToken);
|
|
114
|
+
// Reset tryLogin state
|
|
115
|
+
this._isTryingLogin = false;
|
|
100
116
|
}
|
|
101
117
|
/**
|
|
102
118
|
* Change country or region
|
|
@@ -178,8 +194,7 @@ class CoreApp {
|
|
|
178
194
|
}
|
|
179
195
|
// Detect IP callbacks
|
|
180
196
|
detectIPCallbacks() {
|
|
181
|
-
|
|
182
|
-
(_a = this.ipDetectCallbacks) === null || _a === void 0 ? void 0 : _a.forEach((f) => f());
|
|
197
|
+
this.ipDetectCallbacks?.forEach((f) => f());
|
|
183
198
|
}
|
|
184
199
|
/**
|
|
185
200
|
* Format date to string
|
|
@@ -190,7 +205,7 @@ class CoreApp {
|
|
|
190
205
|
*/
|
|
191
206
|
formatDate(input, options, timeZone) {
|
|
192
207
|
const { currentCulture, timeZone: defaultTimeZone } = this.settings;
|
|
193
|
-
timeZone
|
|
208
|
+
timeZone ?? (timeZone = defaultTimeZone);
|
|
194
209
|
return shared_1.DateUtils.format(input, currentCulture.name, options, timeZone);
|
|
195
210
|
}
|
|
196
211
|
/**
|
|
@@ -229,6 +244,9 @@ class CoreApp {
|
|
|
229
244
|
const value = this.settings.currentCulture.resources[key];
|
|
230
245
|
if (value == null)
|
|
231
246
|
return undefined;
|
|
247
|
+
// No strict type convertion here
|
|
248
|
+
// Make sure the type is strictly match
|
|
249
|
+
// Otherwise even request number, may still return the source string type
|
|
232
250
|
return value;
|
|
233
251
|
}
|
|
234
252
|
/**
|
|
@@ -237,7 +255,7 @@ class CoreApp {
|
|
|
237
255
|
*/
|
|
238
256
|
getLabels(...keys) {
|
|
239
257
|
const init = {};
|
|
240
|
-
return keys.reduce((a, v) =>
|
|
258
|
+
return keys.reduce((a, v) => ({ ...a, [v]: this.get(v) ?? '' }), init);
|
|
241
259
|
}
|
|
242
260
|
/**
|
|
243
261
|
* Get cached token
|
|
@@ -278,9 +296,8 @@ class CoreApp {
|
|
|
278
296
|
* @returns Time zone
|
|
279
297
|
*/
|
|
280
298
|
getTimeZone() {
|
|
281
|
-
var _a, _b;
|
|
282
299
|
// settings.timeZone = Utils.getTimeZone()
|
|
283
|
-
return
|
|
300
|
+
return this.settings.timeZone ?? this.ipData?.timezone;
|
|
284
301
|
}
|
|
285
302
|
/**
|
|
286
303
|
* Callback where exit a page
|
|
@@ -312,6 +329,15 @@ class CoreApp {
|
|
|
312
329
|
// To /a/b/../ => /a
|
|
313
330
|
return pathname.endsWith('/') ? pathname + url : pathname + '/' + url;
|
|
314
331
|
}
|
|
332
|
+
/**
|
|
333
|
+
* Try login, returning false means is loading
|
|
334
|
+
*/
|
|
335
|
+
tryLogin() {
|
|
336
|
+
if (this._isTryingLogin)
|
|
337
|
+
return false;
|
|
338
|
+
this._isTryingLogin = true;
|
|
339
|
+
return true;
|
|
340
|
+
}
|
|
315
341
|
/**
|
|
316
342
|
* User login
|
|
317
343
|
* @param user User data
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Business tax interface
|
|
3
|
+
*/
|
|
4
|
+
export interface IBusinessTax {
|
|
5
|
+
/**
|
|
6
|
+
* Id
|
|
7
|
+
*/
|
|
8
|
+
readonly id: string;
|
|
9
|
+
/**
|
|
10
|
+
* Name
|
|
11
|
+
*/
|
|
12
|
+
readonly name: string;
|
|
13
|
+
/**
|
|
14
|
+
* Mask
|
|
15
|
+
*/
|
|
16
|
+
readonly mask: string;
|
|
17
|
+
/**
|
|
18
|
+
* Get label key
|
|
19
|
+
*/
|
|
20
|
+
readonly labelKey: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Business tax
|
|
24
|
+
* https://imask.js.org/
|
|
25
|
+
*/
|
|
26
|
+
export declare class BusinessTax implements IBusinessTax {
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
mask: string;
|
|
30
|
+
/**
|
|
31
|
+
* CN
|
|
32
|
+
* Unified Social Credit Code (USCC) / 统一信用代码
|
|
33
|
+
* https://zh.wikisource.org/wiki/GB_32100-2015_%E6%B3%95%E4%BA%BA%E5%92%8C%E5%85%B6%E4%BB%96%E7%BB%84%E7%BB%87%E7%BB%9F%E4%B8%80%E7%A4%BE%E4%BC%9A%E4%BF%A1%E7%94%A8%E4%BB%A3%E7%A0%81%E7%BC%96%E7%A0%81%E8%A7%84%E5%88%99
|
|
34
|
+
*/
|
|
35
|
+
static CN: BusinessTax;
|
|
36
|
+
/**
|
|
37
|
+
* NZ, Inland Revenue (IRD)
|
|
38
|
+
*/
|
|
39
|
+
static NZ: BusinessTax;
|
|
40
|
+
/**
|
|
41
|
+
* US, Employer Identification Number (EIN)
|
|
42
|
+
*/
|
|
43
|
+
static US: BusinessTax;
|
|
44
|
+
/**
|
|
45
|
+
* CA, tax ID number (Business Number, BN)
|
|
46
|
+
*/
|
|
47
|
+
static CA: BusinessTax;
|
|
48
|
+
/**
|
|
49
|
+
* HK, Business Registration Number (BRN)
|
|
50
|
+
*/
|
|
51
|
+
static HK: BusinessTax;
|
|
52
|
+
/**
|
|
53
|
+
* All countries and regions
|
|
54
|
+
*/
|
|
55
|
+
static all: BusinessTax[];
|
|
56
|
+
/**
|
|
57
|
+
* Get country or region by id
|
|
58
|
+
* @param id Country id
|
|
59
|
+
*/
|
|
60
|
+
static getById(id: string): BusinessTax | undefined;
|
|
61
|
+
constructor(id: string, name: string, mask: string);
|
|
62
|
+
/**
|
|
63
|
+
* Get label key
|
|
64
|
+
*/
|
|
65
|
+
get labelKey(): string;
|
|
66
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BusinessTax = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Business tax
|
|
6
|
+
* https://imask.js.org/
|
|
7
|
+
*/
|
|
8
|
+
class BusinessTax {
|
|
9
|
+
// Typescript constructor shorthand
|
|
10
|
+
constructor(id, name, mask) {
|
|
11
|
+
this.id = id;
|
|
12
|
+
this.name = name;
|
|
13
|
+
this.mask = mask;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get country or region by id
|
|
17
|
+
* @param id Country id
|
|
18
|
+
*/
|
|
19
|
+
static getById(id) {
|
|
20
|
+
return BusinessTax.all.find((c) => c.id === id);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get label key
|
|
24
|
+
*/
|
|
25
|
+
get labelKey() {
|
|
26
|
+
return 'tax' + this.id + this.name;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.BusinessTax = BusinessTax;
|
|
30
|
+
/**
|
|
31
|
+
* CN
|
|
32
|
+
* Unified Social Credit Code (USCC) / 统一信用代码
|
|
33
|
+
* https://zh.wikisource.org/wiki/GB_32100-2015_%E6%B3%95%E4%BA%BA%E5%92%8C%E5%85%B6%E4%BB%96%E7%BB%84%E7%BB%87%E7%BB%9F%E4%B8%80%E7%A4%BE%E4%BC%9A%E4%BF%A1%E7%94%A8%E4%BB%A3%E7%A0%81%E7%BC%96%E7%A0%81%E8%A7%84%E5%88%99
|
|
34
|
+
*/
|
|
35
|
+
BusinessTax.CN = new BusinessTax('CN', 'USCC', '*0-000000-**********');
|
|
36
|
+
/**
|
|
37
|
+
* NZ, Inland Revenue (IRD)
|
|
38
|
+
*/
|
|
39
|
+
BusinessTax.NZ = new BusinessTax('NZ', 'IRD', '00[0]-000-000');
|
|
40
|
+
/**
|
|
41
|
+
* US, Employer Identification Number (EIN)
|
|
42
|
+
*/
|
|
43
|
+
BusinessTax.US = new BusinessTax('US', 'EIN', '00-0000000');
|
|
44
|
+
/**
|
|
45
|
+
* CA, tax ID number (Business Number, BN)
|
|
46
|
+
*/
|
|
47
|
+
BusinessTax.CA = new BusinessTax('CA', 'BN', '000000000');
|
|
48
|
+
/**
|
|
49
|
+
* HK, Business Registration Number (BRN)
|
|
50
|
+
*/
|
|
51
|
+
BusinessTax.HK = new BusinessTax('HK', 'BRN', '00000000');
|
|
52
|
+
/**
|
|
53
|
+
* All countries and regions
|
|
54
|
+
*/
|
|
55
|
+
BusinessTax.all = [
|
|
56
|
+
BusinessTax.CN,
|
|
57
|
+
BusinessTax.NZ,
|
|
58
|
+
BusinessTax.US,
|
|
59
|
+
BusinessTax.CA,
|
|
60
|
+
BusinessTax.HK
|
|
61
|
+
];
|
|
@@ -24,8 +24,7 @@ var BusinessUtils;
|
|
|
24
24
|
BusinessUtils.addIdLabelBlankItem = addIdLabelBlankItem;
|
|
25
25
|
// Get unit label by key
|
|
26
26
|
function getUnitLabelByKey(func, key) {
|
|
27
|
-
|
|
28
|
-
return (_a = func('unit' + key)) !== null && _a !== void 0 ? _a : key;
|
|
27
|
+
return func('unit' + key) ?? key;
|
|
29
28
|
}
|
|
30
29
|
/**
|
|
31
30
|
* Get product unit's label
|
|
@@ -45,7 +44,7 @@ var BusinessUtils;
|
|
|
45
44
|
* @returns Units
|
|
46
45
|
*/
|
|
47
46
|
function getUnits(func) {
|
|
48
|
-
return shared_1.
|
|
47
|
+
return shared_1.DataTypes.getEnumKeys(ProductUnit_1.ProductUnit).map((key) => ({
|
|
49
48
|
id: ProductUnit_1.ProductUnit[key],
|
|
50
49
|
label: getUnitLabelByKey(func, key)
|
|
51
50
|
}));
|
package/lib/cjs/dto/IdDto.d.ts
CHANGED
package/lib/cjs/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './app/ExternalSettings';
|
|
|
7
7
|
export * from './bridges/ElectronBridge';
|
|
8
8
|
export * from './bridges/IAppData';
|
|
9
9
|
export * from './bridges/IBridge';
|
|
10
|
+
export * from './business/BusinessTax';
|
|
10
11
|
export * from './business/BusinessUtils';
|
|
11
12
|
export * from './business/ProductUnit';
|
|
12
13
|
export * from './dto/IdDto';
|
package/lib/cjs/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __exportStar(require("./bridges/ElectronBridge"), exports);
|
|
|
23
23
|
__exportStar(require("./bridges/IAppData"), exports);
|
|
24
24
|
__exportStar(require("./bridges/IBridge"), exports);
|
|
25
25
|
// business
|
|
26
|
+
__exportStar(require("./business/BusinessTax"), exports);
|
|
26
27
|
__exportStar(require("./business/BusinessUtils"), exports);
|
|
27
28
|
__exportStar(require("./business/ProductUnit"), exports);
|
|
28
29
|
// dto
|
|
@@ -13,7 +13,7 @@ export declare namespace AddressUtils {
|
|
|
13
13
|
*/
|
|
14
14
|
function getContinents(func: ICultureGet, isNumberKey?: boolean): IdLabelDto[];
|
|
15
15
|
/**
|
|
16
|
-
* Get region
|
|
16
|
+
* Get region from regions and detected region and language
|
|
17
17
|
* @param regions Supported regions
|
|
18
18
|
* @param detectedRegion Detected region
|
|
19
19
|
* @param detectedLanguage Detected language
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DataTypes } from '@etsoo/shared';
|
|
2
2
|
import { AddressRegion } from '..';
|
|
3
3
|
import { AddressContinent } from './AddressContinent';
|
|
4
4
|
/**
|
|
@@ -13,19 +13,16 @@ export var AddressUtils;
|
|
|
13
13
|
* @returns Continents
|
|
14
14
|
*/
|
|
15
15
|
function getContinents(func, isNumberKey = false) {
|
|
16
|
-
return
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
label: (_a = func('continent' + key)) !== null && _a !== void 0 ? _a : key
|
|
23
|
-
});
|
|
24
|
-
});
|
|
16
|
+
return DataTypes.getEnumKeys(AddressContinent).map((key) => ({
|
|
17
|
+
id: isNumberKey
|
|
18
|
+
? AddressContinent[key]
|
|
19
|
+
: key,
|
|
20
|
+
label: func('continent' + key) ?? key
|
|
21
|
+
}));
|
|
25
22
|
}
|
|
26
23
|
AddressUtils.getContinents = getContinents;
|
|
27
24
|
/**
|
|
28
|
-
* Get region
|
|
25
|
+
* Get region from regions and detected region and language
|
|
29
26
|
* @param regions Supported regions
|
|
30
27
|
* @param detectedRegion Detected region
|
|
31
28
|
* @param detectedLanguage Detected language
|
|
@@ -3,7 +3,7 @@ import { DataTypes } from '@etsoo/shared';
|
|
|
3
3
|
import { AddressRegion } from '../address/AddressRegion';
|
|
4
4
|
import { IExternalSettings } from './ExternalSettings';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* App settings interface
|
|
7
7
|
*/
|
|
8
8
|
export interface IAppSettings extends IExternalSettings {
|
|
9
9
|
/**
|