@etsoo/appscript 1.1.2 → 1.1.6

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.
@@ -27,6 +27,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
27
27
  * Notifier
28
28
  */
29
29
  readonly notifier: INotifier<N, C>;
30
+ /**
31
+ * Label delegate
32
+ */
33
+ readonly labelDelegate: <T extends DataTypes.SimpleType = string>(key: string) => T | undefined;
30
34
  /**
31
35
  * Culture, like zh-CN
32
36
  */
@@ -39,6 +43,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
39
43
  * Country or region, like CN
40
44
  */
41
45
  readonly region: string;
46
+ /**
47
+ * Is current authorized
48
+ */
49
+ readonly authorized: boolean;
42
50
  /**
43
51
  * IP data
44
52
  */
@@ -145,6 +153,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
145
153
  * @returns Transformed url
146
154
  */
147
155
  transformUrl(url: string): string;
156
+ /**
157
+ * Try login, returning false means is loading
158
+ */
159
+ tryLogin(): boolean;
148
160
  /**
149
161
  * User login
150
162
  * @param user User data
@@ -188,6 +200,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
188
200
  * Country or region, like CN
189
201
  */
190
202
  get region(): string;
203
+ /**
204
+ * Label delegate
205
+ */
206
+ get labelDelegate(): <T extends DataTypes.SimpleType = string>(key: string) => T | undefined;
191
207
  /**
192
208
  * IP data
193
209
  */
@@ -205,6 +221,13 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
205
221
  * Search input element
206
222
  */
207
223
  searchInput?: HTMLInputElement;
224
+ private _authorized;
225
+ /**
226
+ * Is current authorized
227
+ */
228
+ get authorized(): boolean;
229
+ private set authorized(value);
230
+ private _isTryingLogin;
208
231
  /**
209
232
  * Protected constructor
210
233
  * @param settings Settings
@@ -318,9 +341,9 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
318
341
  */
319
342
  transformUrl(url: string): string;
320
343
  /**
321
- * Try login
344
+ * Try login, returning false means is loading
322
345
  */
323
- abstract tryLogin(): void;
346
+ tryLogin(): boolean;
324
347
  /**
325
348
  * User login
326
349
  * @param user User data
@@ -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) {
@@ -73,6 +75,21 @@ class CoreApp {
73
75
  get region() {
74
76
  return this._region;
75
77
  }
78
+ /**
79
+ * Label delegate
80
+ */
81
+ get labelDelegate() {
82
+ return this.get.bind(this);
83
+ }
84
+ /**
85
+ * Is current authorized
86
+ */
87
+ get authorized() {
88
+ return this._authorized;
89
+ }
90
+ set authorized(value) {
91
+ this._authorized = value;
92
+ }
76
93
  /**
77
94
  * Alert action result
78
95
  * @param result Action result
@@ -87,10 +104,15 @@ class CoreApp {
87
104
  * @param keep Keep in local storage or not
88
105
  */
89
106
  authorize(token, refreshToken, keep = false) {
107
+ // State, when token is null, means logout
108
+ this.authorized = token != null;
109
+ // Token
90
110
  this.api.authorize(this.settings.authScheme, token);
91
111
  // Cover the current value
92
112
  shared_1.StorageUtils.setLocalData(this.headerTokenField, keep ? refreshToken : undefined);
93
113
  shared_1.StorageUtils.setSessionData(this.headerTokenField, keep ? undefined : refreshToken);
114
+ // Reset tryLogin state
115
+ this._isTryingLogin = false;
94
116
  }
95
117
  /**
96
118
  * Change country or region
@@ -306,6 +328,15 @@ class CoreApp {
306
328
  // To /a/b/../ => /a
307
329
  return pathname.endsWith('/') ? pathname + url : pathname + '/' + url;
308
330
  }
331
+ /**
332
+ * Try login, returning false means is loading
333
+ */
334
+ tryLogin() {
335
+ if (this._isTryingLogin)
336
+ return false;
337
+ this._isTryingLogin = true;
338
+ return true;
339
+ }
309
340
  /**
310
341
  * User login
311
342
  * @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,55 @@
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 = [BusinessTax.CN, BusinessTax.NZ, BusinessTax.US];
@@ -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
@@ -27,6 +27,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
27
27
  * Notifier
28
28
  */
29
29
  readonly notifier: INotifier<N, C>;
30
+ /**
31
+ * Label delegate
32
+ */
33
+ readonly labelDelegate: <T extends DataTypes.SimpleType = string>(key: string) => T | undefined;
30
34
  /**
31
35
  * Culture, like zh-CN
32
36
  */
@@ -39,6 +43,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
39
43
  * Country or region, like CN
40
44
  */
41
45
  readonly region: string;
46
+ /**
47
+ * Is current authorized
48
+ */
49
+ readonly authorized: boolean;
42
50
  /**
43
51
  * IP data
44
52
  */
@@ -145,6 +153,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
145
153
  * @returns Transformed url
146
154
  */
147
155
  transformUrl(url: string): string;
156
+ /**
157
+ * Try login, returning false means is loading
158
+ */
159
+ tryLogin(): boolean;
148
160
  /**
149
161
  * User login
150
162
  * @param user User data
@@ -188,6 +200,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
188
200
  * Country or region, like CN
189
201
  */
190
202
  get region(): string;
203
+ /**
204
+ * Label delegate
205
+ */
206
+ get labelDelegate(): <T extends DataTypes.SimpleType = string>(key: string) => T | undefined;
191
207
  /**
192
208
  * IP data
193
209
  */
@@ -205,6 +221,13 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
205
221
  * Search input element
206
222
  */
207
223
  searchInput?: HTMLInputElement;
224
+ private _authorized;
225
+ /**
226
+ * Is current authorized
227
+ */
228
+ get authorized(): boolean;
229
+ private set authorized(value);
230
+ private _isTryingLogin;
208
231
  /**
209
232
  * Protected constructor
210
233
  * @param settings Settings
@@ -318,9 +341,9 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
318
341
  */
319
342
  transformUrl(url: string): string;
320
343
  /**
321
- * Try login
344
+ * Try login, returning false means is loading
322
345
  */
323
- abstract tryLogin(): void;
346
+ tryLogin(): boolean;
324
347
  /**
325
348
  * User login
326
349
  * @param user User data
@@ -16,6 +16,8 @@ export class CoreApp {
16
16
  * Response token header field name
17
17
  */
18
18
  this.headerTokenField = 'SmartERPRefreshToken';
19
+ this._authorized = false;
20
+ this._isTryingLogin = false;
19
21
  // onRequest, show loading or not, rewrite the property to override default action
20
22
  api.onRequest = (data) => {
21
23
  if (data.showLoading == null || data.showLoading) {
@@ -70,6 +72,21 @@ export class CoreApp {
70
72
  get region() {
71
73
  return this._region;
72
74
  }
75
+ /**
76
+ * Label delegate
77
+ */
78
+ get labelDelegate() {
79
+ return this.get.bind(this);
80
+ }
81
+ /**
82
+ * Is current authorized
83
+ */
84
+ get authorized() {
85
+ return this._authorized;
86
+ }
87
+ set authorized(value) {
88
+ this._authorized = value;
89
+ }
73
90
  /**
74
91
  * Alert action result
75
92
  * @param result Action result
@@ -84,10 +101,15 @@ export class CoreApp {
84
101
  * @param keep Keep in local storage or not
85
102
  */
86
103
  authorize(token, refreshToken, keep = false) {
104
+ // State, when token is null, means logout
105
+ this.authorized = token != null;
106
+ // Token
87
107
  this.api.authorize(this.settings.authScheme, token);
88
108
  // Cover the current value
89
109
  StorageUtils.setLocalData(this.headerTokenField, keep ? refreshToken : undefined);
90
110
  StorageUtils.setSessionData(this.headerTokenField, keep ? undefined : refreshToken);
111
+ // Reset tryLogin state
112
+ this._isTryingLogin = false;
91
113
  }
92
114
  /**
93
115
  * Change country or region
@@ -303,6 +325,15 @@ export class CoreApp {
303
325
  // To /a/b/../ => /a
304
326
  return pathname.endsWith('/') ? pathname + url : pathname + '/' + url;
305
327
  }
328
+ /**
329
+ * Try login, returning false means is loading
330
+ */
331
+ tryLogin() {
332
+ if (this._isTryingLogin)
333
+ return false;
334
+ this._isTryingLogin = true;
335
+ return true;
336
+ }
306
337
  /**
307
338
  * User login
308
339
  * @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,51 @@
1
+ /**
2
+ * Business tax
3
+ * https://imask.js.org/
4
+ */
5
+ export class BusinessTax {
6
+ // Typescript constructor shorthand
7
+ constructor(id, name, mask) {
8
+ this.id = id;
9
+ this.name = name;
10
+ this.mask = mask;
11
+ }
12
+ /**
13
+ * Get country or region by id
14
+ * @param id Country id
15
+ */
16
+ static getById(id) {
17
+ return BusinessTax.all.find((c) => c.id === id);
18
+ }
19
+ /**
20
+ * Get label key
21
+ */
22
+ get labelKey() {
23
+ return 'tax' + this.id + this.name;
24
+ }
25
+ }
26
+ /**
27
+ * CN
28
+ * Unified Social Credit Code (USCC) / 统一信用代码
29
+ * 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
30
+ */
31
+ BusinessTax.CN = new BusinessTax('CN', 'USCC', '*0-000000-**********');
32
+ /**
33
+ * NZ, Inland Revenue (IRD)
34
+ */
35
+ BusinessTax.NZ = new BusinessTax('NZ', 'IRD', '00[0]-000-000');
36
+ /**
37
+ * US, Employer Identification Number (EIN)
38
+ */
39
+ BusinessTax.US = new BusinessTax('US', 'EIN', '00-0000000');
40
+ /**
41
+ * CA, tax ID number (Business Number, BN)
42
+ */
43
+ BusinessTax.CA = new BusinessTax('CA', 'BN', '000000000');
44
+ /**
45
+ * HK, Business Registration Number (BRN)
46
+ */
47
+ BusinessTax.HK = new BusinessTax('HK', 'BRN', '00000000');
48
+ /**
49
+ * All countries and regions
50
+ */
51
+ BusinessTax.all = [BusinessTax.CN, BusinessTax.NZ, BusinessTax.US];
@@ -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/mjs/index.js CHANGED
@@ -11,6 +11,7 @@ export * from './bridges/ElectronBridge';
11
11
  export * from './bridges/IAppData';
12
12
  export * from './bridges/IBridge';
13
13
  // business
14
+ export * from './business/BusinessTax';
14
15
  export * from './business/BusinessUtils';
15
16
  export * from './business/ProductUnit';
16
17
  // dto
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.1.2",
3
+ "version": "1.1.6",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -43,6 +43,13 @@ export interface ICoreApp<
43
43
  */
44
44
  readonly notifier: INotifier<N, C>;
45
45
 
46
+ /**
47
+ * Label delegate
48
+ */
49
+ readonly labelDelegate: <T extends DataTypes.SimpleType = string>(
50
+ key: string
51
+ ) => T | undefined;
52
+
46
53
  /**
47
54
  * Culture, like zh-CN
48
55
  */
@@ -58,6 +65,11 @@ export interface ICoreApp<
58
65
  */
59
66
  readonly region: string;
60
67
 
68
+ /**
69
+ * Is current authorized
70
+ */
71
+ readonly authorized: boolean;
72
+
61
73
  /**
62
74
  * IP data
63
75
  */
@@ -192,6 +204,11 @@ export interface ICoreApp<
192
204
  */
193
205
  transformUrl(url: string): string;
194
206
 
207
+ /**
208
+ * Try login, returning false means is loading
209
+ */
210
+ tryLogin(): boolean;
211
+
195
212
  /**
196
213
  * User login
197
214
  * @param user User data
@@ -254,6 +271,13 @@ export abstract class CoreApp<
254
271
  return this._region;
255
272
  }
256
273
 
274
+ /**
275
+ * Label delegate
276
+ */
277
+ get labelDelegate() {
278
+ return this.get.bind(this);
279
+ }
280
+
257
281
  /**
258
282
  * IP data
259
283
  */
@@ -277,6 +301,20 @@ export abstract class CoreApp<
277
301
  */
278
302
  searchInput?: HTMLInputElement;
279
303
 
304
+ private _authorized: boolean = false;
305
+ /**
306
+ * Is current authorized
307
+ */
308
+ get authorized() {
309
+ return this._authorized;
310
+ }
311
+
312
+ private set authorized(value: boolean) {
313
+ this._authorized = value;
314
+ }
315
+
316
+ private _isTryingLogin = false;
317
+
280
318
  /**
281
319
  * Protected constructor
282
320
  * @param settings Settings
@@ -341,6 +379,10 @@ export abstract class CoreApp<
341
379
  * @param keep Keep in local storage or not
342
380
  */
343
381
  authorize(token?: string, refreshToken?: string, keep: boolean = false) {
382
+ // State, when token is null, means logout
383
+ this.authorized = token != null;
384
+
385
+ // Token
344
386
  this.api.authorize(this.settings.authScheme, token);
345
387
 
346
388
  // Cover the current value
@@ -352,6 +394,9 @@ export abstract class CoreApp<
352
394
  this.headerTokenField,
353
395
  keep ? undefined : refreshToken
354
396
  );
397
+
398
+ // Reset tryLogin state
399
+ this._isTryingLogin = false;
355
400
  }
356
401
 
357
402
  /**
@@ -618,9 +663,13 @@ export abstract class CoreApp<
618
663
  }
619
664
 
620
665
  /**
621
- * Try login
666
+ * Try login, returning false means is loading
622
667
  */
623
- abstract tryLogin(): void;
668
+ tryLogin() {
669
+ if (this._isTryingLogin) return false;
670
+ this._isTryingLogin = true;
671
+ return true;
672
+ }
624
673
 
625
674
  /**
626
675
  * User login
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Business tax interface
3
+ */
4
+ export interface IBusinessTax {
5
+ /**
6
+ * Id
7
+ */
8
+ readonly id: string;
9
+
10
+ /**
11
+ * Name
12
+ */
13
+ readonly name: string;
14
+
15
+ /**
16
+ * Mask
17
+ */
18
+ readonly mask: string;
19
+
20
+ /**
21
+ * Get label key
22
+ */
23
+ readonly labelKey: string;
24
+ }
25
+
26
+ /**
27
+ * Business tax
28
+ * https://imask.js.org/
29
+ */
30
+ export class BusinessTax implements IBusinessTax {
31
+ /**
32
+ * CN
33
+ * Unified Social Credit Code (USCC) / 统一信用代码
34
+ * 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
35
+ */
36
+ static CN = new BusinessTax('CN', 'USCC', '*0-000000-**********');
37
+
38
+ /**
39
+ * NZ, Inland Revenue (IRD)
40
+ */
41
+ static NZ = new BusinessTax('NZ', 'IRD', '00[0]-000-000');
42
+
43
+ /**
44
+ * US, Employer Identification Number (EIN)
45
+ */
46
+ static US = new BusinessTax('US', 'EIN', '00-0000000');
47
+
48
+ /**
49
+ * CA, tax ID number (Business Number, BN)
50
+ */
51
+ static CA = new BusinessTax('CA', 'BN', '000000000');
52
+
53
+ /**
54
+ * HK, Business Registration Number (BRN)
55
+ */
56
+ static HK = new BusinessTax('HK', 'BRN', '00000000');
57
+
58
+ /**
59
+ * All countries and regions
60
+ */
61
+ static all = [BusinessTax.CN, BusinessTax.NZ, BusinessTax.US];
62
+
63
+ /**
64
+ * Get country or region by id
65
+ * @param id Country id
66
+ */
67
+ static getById(id: string) {
68
+ return BusinessTax.all.find((c) => c.id === id);
69
+ }
70
+
71
+ // Typescript constructor shorthand
72
+ constructor(public id: string, public name: string, public mask: string) {}
73
+
74
+ /**
75
+ * Get label key
76
+ */
77
+ get labelKey() {
78
+ return 'tax' + this.id + this.name;
79
+ }
80
+ }
package/src/index.ts CHANGED
@@ -14,6 +14,7 @@ export * from './bridges/IAppData';
14
14
  export * from './bridges/IBridge';
15
15
 
16
16
  // business
17
+ export * from './business/BusinessTax';
17
18
  export * from './business/BusinessUtils';
18
19
  export * from './business/ProductUnit';
19
20