@etsoo/appscript 1.2.73 → 1.2.74

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.
@@ -8,7 +8,7 @@ import {
8
8
  } from '@etsoo/notificationbase';
9
9
  import { ApiAuthorizationScheme, createClient } from '@etsoo/restclient';
10
10
  import { DataTypes, DomUtils, Utils, WindowStorage } from '@etsoo/shared';
11
- import { BusinessUtils, IUser } from '../../src';
11
+ import { BusinessUtils, IUser, UserRole } from '../../src';
12
12
  import { AddressUtils } from '../../src/address/AddressUtils';
13
13
  import { IAppSettings } from '../../src/app/AppSettings';
14
14
  import { CoreApp } from '../../src/app/CoreApp';
@@ -161,6 +161,12 @@ test('Tests for initCallUpdateLocal', () => {
161
161
  expect(passphrase).not.toBeNull();
162
162
  });
163
163
 
164
+ test('Tests for getRoles', () => {
165
+ var roles = app.getRoles(UserRole.User | UserRole.Manager | UserRole.Admin);
166
+ expect(roles.length).toBe(3);
167
+ expect(roles.map((r) => r.id)).toEqual([8, 128, 8192]);
168
+ });
169
+
164
170
  test('Tests for getUnitLabel', () => {
165
171
  expect(app.getUnitLabel(12, true)).toBe('每年');
166
172
  });
@@ -262,16 +262,19 @@ export interface ICoreApp<U extends IUser, S extends IAppSettings, N, C extends
262
262
  getCacheToken(): string | undefined;
263
263
  /**
264
264
  * Get entity status label
265
- * @param data Input data
265
+ * @param status Status value
266
266
  */
267
- getEntityStatusLabel<D extends {
268
- entityStatus?: number;
269
- }>(data?: D): string;
267
+ getEntityStatusLabel(status: number | null | undefined): string;
270
268
  /**
271
269
  * Get all regions
272
270
  * @returns Regions
273
271
  */
274
272
  getRegions(): AddressRegion[];
273
+ /**
274
+ * Get roles
275
+ * @param role Combination role value
276
+ */
277
+ getRoles(role: number): IdLabelDto[];
275
278
  /**
276
279
  * Get refresh token from response headers
277
280
  * @param rawResponse Raw response from API call
@@ -707,13 +710,16 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
707
710
  * @returns Regions
708
711
  */
709
712
  getRegions(): AddressRegion[];
713
+ /**
714
+ * Get roles
715
+ * @param role Combination role value
716
+ */
717
+ getRoles(role: number): IdLabelDto<number>[];
710
718
  /**
711
719
  * Get entity status label
712
- * @param data Input data
720
+ * @param status Status value
713
721
  */
714
- getEntityStatusLabel<D extends {
715
- entityStatus?: number;
716
- }>(data?: D): string;
722
+ getEntityStatusLabel(status: number | null | undefined): string;
717
723
  /**
718
724
  * Get refresh token from response headers
719
725
  * @param rawResponse Raw response from API call
@@ -10,6 +10,7 @@ const AddressUtils_1 = require("../address/AddressUtils");
10
10
  const BridgeUtils_1 = require("../bridges/BridgeUtils");
11
11
  const BusinessUtils_1 = require("../business/BusinessUtils");
12
12
  const ActionResultError_1 = require("../result/ActionResultError");
13
+ const UserRole_1 = require("./UserRole");
13
14
  /**
14
15
  * App fields
15
16
  */
@@ -837,14 +838,33 @@ class CoreApp {
837
838
  return AddressRegion_1.AddressRegion.getById(id);
838
839
  });
839
840
  }
841
+ /**
842
+ * Get roles
843
+ * @param role Combination role value
844
+ */
845
+ getRoles(role) {
846
+ var _a;
847
+ var roles = [];
848
+ var keys = shared_1.DataTypes.getEnumKeys(UserRole_1.UserRole);
849
+ for (var key of keys) {
850
+ var id = UserRole_1.UserRole[key];
851
+ if ((id & role) > 0) {
852
+ roles.push({
853
+ id,
854
+ label: (_a = this.get(`role${key}`)) !== null && _a !== void 0 ? _a : key
855
+ });
856
+ }
857
+ }
858
+ return roles;
859
+ }
840
860
  /**
841
861
  * Get entity status label
842
- * @param data Input data
862
+ * @param status Status value
843
863
  */
844
- getEntityStatusLabel(data) {
845
- if (data == null || data.entityStatus == null)
864
+ getEntityStatusLabel(status) {
865
+ if (status == null)
846
866
  return '';
847
- return BusinessUtils_1.BusinessUtils.getEntityStatusLabel(data.entityStatus, this.labelDelegate);
867
+ return BusinessUtils_1.BusinessUtils.getEntityStatusLabel(status, this.labelDelegate);
848
868
  }
849
869
  /**
850
870
  * Get refresh token from response headers
@@ -38,7 +38,7 @@ export declare namespace BusinessUtils {
38
38
  * @param startMonth Start month, 0 as Jan.
39
39
  * @returns 12 months
40
40
  */
41
- function getMonths(monthLabels: string[], startMonth?: number): DataTypes.IdLabelItem[];
41
+ function getMonths(monthLabels: string[], startMonth?: number): DataTypes.IdLabelItem<number>[];
42
42
  /**
43
43
  * Get product unit's label
44
44
  * Please define the label in culture with key 'unitPC' for ProductUnit.PC like that
@@ -1,9 +1,8 @@
1
1
  import { DataTypes } from '@etsoo/shared';
2
- import { IdDto } from './IdDto';
3
2
  /**
4
3
  * Dto with id and label field
5
4
  */
6
- export declare type IdLabelDto<T extends DataTypes.IdType = number> = IdDto<T> & {
5
+ export declare type IdLabelDto<T extends DataTypes.IdType = number> = DataTypes.IdItem<T> & {
7
6
  /**
8
7
  * Label
9
8
  */
@@ -12,4 +11,4 @@ export declare type IdLabelDto<T extends DataTypes.IdType = number> = IdDto<T> &
12
11
  /**
13
12
  * Conditional IdLabel type
14
13
  */
15
- export declare type IdLabelConditional<T extends boolean> = T extends true ? IdLabelDto[] : IdLabelDto<string>[];
14
+ export declare type IdLabelConditional<T extends boolean> = T extends true ? IdLabelDto<number>[] : IdLabelDto<string>[];
@@ -13,7 +13,6 @@ export * from './business/EntityStatus';
13
13
  export * from './business/ProductUnit';
14
14
  export * from './business/RepeatOption';
15
15
  export * from './def/ListItem';
16
- export * from './dto/IdDto';
17
16
  export * from './dto/IdLabelDto';
18
17
  export * from './dto/IdLabelPrimaryDto';
19
18
  export * from './dto/InitCallDto';
package/lib/cjs/index.js CHANGED
@@ -36,7 +36,6 @@ __exportStar(require("./business/RepeatOption"), exports);
36
36
  // def
37
37
  __exportStar(require("./def/ListItem"), exports);
38
38
  // dto
39
- __exportStar(require("./dto/IdDto"), exports);
40
39
  __exportStar(require("./dto/IdLabelDto"), exports);
41
40
  __exportStar(require("./dto/IdLabelPrimaryDto"), exports);
42
41
  __exportStar(require("./dto/InitCallDto"), exports);
@@ -262,16 +262,19 @@ export interface ICoreApp<U extends IUser, S extends IAppSettings, N, C extends
262
262
  getCacheToken(): string | undefined;
263
263
  /**
264
264
  * Get entity status label
265
- * @param data Input data
265
+ * @param status Status value
266
266
  */
267
- getEntityStatusLabel<D extends {
268
- entityStatus?: number;
269
- }>(data?: D): string;
267
+ getEntityStatusLabel(status: number | null | undefined): string;
270
268
  /**
271
269
  * Get all regions
272
270
  * @returns Regions
273
271
  */
274
272
  getRegions(): AddressRegion[];
273
+ /**
274
+ * Get roles
275
+ * @param role Combination role value
276
+ */
277
+ getRoles(role: number): IdLabelDto[];
275
278
  /**
276
279
  * Get refresh token from response headers
277
280
  * @param rawResponse Raw response from API call
@@ -707,13 +710,16 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
707
710
  * @returns Regions
708
711
  */
709
712
  getRegions(): AddressRegion[];
713
+ /**
714
+ * Get roles
715
+ * @param role Combination role value
716
+ */
717
+ getRoles(role: number): IdLabelDto<number>[];
710
718
  /**
711
719
  * Get entity status label
712
- * @param data Input data
720
+ * @param status Status value
713
721
  */
714
- getEntityStatusLabel<D extends {
715
- entityStatus?: number;
716
- }>(data?: D): string;
722
+ getEntityStatusLabel(status: number | null | undefined): string;
717
723
  /**
718
724
  * Get refresh token from response headers
719
725
  * @param rawResponse Raw response from API call
@@ -1,12 +1,13 @@
1
1
  import { NotificationAlign, NotificationMessageType } from '@etsoo/notificationbase';
2
2
  import { ApiDataError } from '@etsoo/restclient';
3
- import { DateUtils, DomUtils, NumberUtils, Utils } from '@etsoo/shared';
3
+ import { DataTypes, DateUtils, DomUtils, NumberUtils, Utils } from '@etsoo/shared';
4
4
  import { AES, algo, enc, HmacSHA512, lib, mode, pad, PBKDF2, SHA3 } from 'crypto-js';
5
5
  import { AddressRegion } from '../address/AddressRegion';
6
6
  import { AddressUtils } from '../address/AddressUtils';
7
7
  import { BridgeUtils } from '../bridges/BridgeUtils';
8
8
  import { BusinessUtils } from '../business/BusinessUtils';
9
9
  import { ActionResultError } from '../result/ActionResultError';
10
+ import { UserRole } from './UserRole';
10
11
  /**
11
12
  * App fields
12
13
  */
@@ -834,14 +835,33 @@ export class CoreApp {
834
835
  return AddressRegion.getById(id);
835
836
  });
836
837
  }
838
+ /**
839
+ * Get roles
840
+ * @param role Combination role value
841
+ */
842
+ getRoles(role) {
843
+ var _a;
844
+ var roles = [];
845
+ var keys = DataTypes.getEnumKeys(UserRole);
846
+ for (var key of keys) {
847
+ var id = UserRole[key];
848
+ if ((id & role) > 0) {
849
+ roles.push({
850
+ id,
851
+ label: (_a = this.get(`role${key}`)) !== null && _a !== void 0 ? _a : key
852
+ });
853
+ }
854
+ }
855
+ return roles;
856
+ }
837
857
  /**
838
858
  * Get entity status label
839
- * @param data Input data
859
+ * @param status Status value
840
860
  */
841
- getEntityStatusLabel(data) {
842
- if (data == null || data.entityStatus == null)
861
+ getEntityStatusLabel(status) {
862
+ if (status == null)
843
863
  return '';
844
- return BusinessUtils.getEntityStatusLabel(data.entityStatus, this.labelDelegate);
864
+ return BusinessUtils.getEntityStatusLabel(status, this.labelDelegate);
845
865
  }
846
866
  /**
847
867
  * Get refresh token from response headers
@@ -38,7 +38,7 @@ export declare namespace BusinessUtils {
38
38
  * @param startMonth Start month, 0 as Jan.
39
39
  * @returns 12 months
40
40
  */
41
- function getMonths(monthLabels: string[], startMonth?: number): DataTypes.IdLabelItem[];
41
+ function getMonths(monthLabels: string[], startMonth?: number): DataTypes.IdLabelItem<number>[];
42
42
  /**
43
43
  * Get product unit's label
44
44
  * Please define the label in culture with key 'unitPC' for ProductUnit.PC like that
@@ -1,9 +1,8 @@
1
1
  import { DataTypes } from '@etsoo/shared';
2
- import { IdDto } from './IdDto';
3
2
  /**
4
3
  * Dto with id and label field
5
4
  */
6
- export declare type IdLabelDto<T extends DataTypes.IdType = number> = IdDto<T> & {
5
+ export declare type IdLabelDto<T extends DataTypes.IdType = number> = DataTypes.IdItem<T> & {
7
6
  /**
8
7
  * Label
9
8
  */
@@ -12,4 +11,4 @@ export declare type IdLabelDto<T extends DataTypes.IdType = number> = IdDto<T> &
12
11
  /**
13
12
  * Conditional IdLabel type
14
13
  */
15
- export declare type IdLabelConditional<T extends boolean> = T extends true ? IdLabelDto[] : IdLabelDto<string>[];
14
+ export declare type IdLabelConditional<T extends boolean> = T extends true ? IdLabelDto<number>[] : IdLabelDto<string>[];
@@ -13,7 +13,6 @@ export * from './business/EntityStatus';
13
13
  export * from './business/ProductUnit';
14
14
  export * from './business/RepeatOption';
15
15
  export * from './def/ListItem';
16
- export * from './dto/IdDto';
17
16
  export * from './dto/IdLabelDto';
18
17
  export * from './dto/IdLabelPrimaryDto';
19
18
  export * from './dto/InitCallDto';
package/lib/mjs/index.js CHANGED
@@ -19,7 +19,6 @@ export * from './business/RepeatOption';
19
19
  // def
20
20
  export * from './def/ListItem';
21
21
  // dto
22
- export * from './dto/IdDto';
23
22
  export * from './dto/IdLabelDto';
24
23
  export * from './dto/IdLabelPrimaryDto';
25
24
  export * from './dto/InitCallDto';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.2.73",
3
+ "version": "1.2.74",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -54,7 +54,7 @@
54
54
  "dependencies": {
55
55
  "@etsoo/notificationbase": "^1.1.5",
56
56
  "@etsoo/restclient": "^1.0.70",
57
- "@etsoo/shared": "^1.1.41",
57
+ "@etsoo/shared": "^1.1.42",
58
58
  "@types/crypto-js": "^4.1.1",
59
59
  "crypto-js": "^4.1.1"
60
60
  },
@@ -65,8 +65,8 @@
65
65
  "@babel/preset-env": "^7.18.10",
66
66
  "@babel/runtime-corejs3": "^7.18.9",
67
67
  "@types/jest": "^28.1.6",
68
- "@typescript-eslint/eslint-plugin": "^5.32.0",
69
- "@typescript-eslint/parser": "^5.32.0",
68
+ "@typescript-eslint/eslint-plugin": "^5.33.0",
69
+ "@typescript-eslint/parser": "^5.33.0",
70
70
  "eslint": "^8.21.0",
71
71
  "eslint-config-airbnb-base": "^15.0.0",
72
72
  "eslint-plugin-import": "^2.26.0",
@@ -37,7 +37,7 @@ import { InitCallDto } from '../dto/InitCallDto';
37
37
  import { ActionResultError } from '../result/ActionResultError';
38
38
  import { IActionResult } from '../result/IActionResult';
39
39
  import { InitCallResult, InitCallResultData } from '../result/InitCallResult';
40
- import { IUser, IUserData } from '../state/User';
40
+ import { IUser } from '../state/User';
41
41
  import { IAppSettings } from './AppSettings';
42
42
  import { UserRole } from './UserRole';
43
43
 
@@ -376,9 +376,9 @@ export interface ICoreApp<
376
376
 
377
377
  /**
378
378
  * Get entity status label
379
- * @param data Input data
379
+ * @param status Status value
380
380
  */
381
- getEntityStatusLabel<D extends { entityStatus?: number }>(data?: D): string;
381
+ getEntityStatusLabel(status: number | null | undefined): string;
382
382
 
383
383
  /**
384
384
  * Get all regions
@@ -386,6 +386,12 @@ export interface ICoreApp<
386
386
  */
387
387
  getRegions(): AddressRegion[];
388
388
 
389
+ /**
390
+ * Get roles
391
+ * @param role Combination role value
392
+ */
393
+ getRoles(role: number): IdLabelDto[];
394
+
389
395
  /**
390
396
  * Get refresh token from response headers
391
397
  * @param rawResponse Raw response from API call
@@ -1602,16 +1608,34 @@ export abstract class CoreApp<
1602
1608
  });
1603
1609
  }
1604
1610
 
1611
+ /**
1612
+ * Get roles
1613
+ * @param role Combination role value
1614
+ */
1615
+ getRoles(role: number) {
1616
+ var roles: IdLabelDto[] = [];
1617
+
1618
+ var keys = DataTypes.getEnumKeys(UserRole);
1619
+ for (var key of keys) {
1620
+ var id = UserRole[key as keyof typeof UserRole];
1621
+ if ((id & role) > 0) {
1622
+ roles.push({
1623
+ id,
1624
+ label: this.get<string>(`role${key}`) ?? key
1625
+ });
1626
+ }
1627
+ }
1628
+
1629
+ return roles;
1630
+ }
1631
+
1605
1632
  /**
1606
1633
  * Get entity status label
1607
- * @param data Input data
1634
+ * @param status Status value
1608
1635
  */
1609
- getEntityStatusLabel<D extends { entityStatus?: number }>(data?: D) {
1610
- if (data == null || data.entityStatus == null) return '';
1611
- return BusinessUtils.getEntityStatusLabel(
1612
- data.entityStatus,
1613
- this.labelDelegate
1614
- );
1636
+ getEntityStatusLabel(status: number | null | undefined) {
1637
+ if (status == null) return '';
1638
+ return BusinessUtils.getEntityStatusLabel(status, this.labelDelegate);
1615
1639
  }
1616
1640
 
1617
1641
  /**
@@ -1,19 +1,19 @@
1
1
  import { DataTypes } from '@etsoo/shared';
2
- import { IdDto } from './IdDto';
3
2
 
4
3
  /**
5
4
  * Dto with id and label field
6
5
  */
7
- export type IdLabelDto<T extends DataTypes.IdType = number> = IdDto<T> & {
8
- /**
9
- * Label
10
- */
11
- label: string;
12
- };
6
+ export type IdLabelDto<T extends DataTypes.IdType = number> =
7
+ DataTypes.IdItem<T> & {
8
+ /**
9
+ * Label
10
+ */
11
+ label: string;
12
+ };
13
13
 
14
14
  /**
15
15
  * Conditional IdLabel type
16
16
  */
17
17
  export type IdLabelConditional<T extends boolean> = T extends true
18
- ? IdLabelDto[]
18
+ ? IdLabelDto<number>[]
19
19
  : IdLabelDto<string>[];
package/src/index.ts CHANGED
@@ -24,7 +24,6 @@ export * from './business/RepeatOption';
24
24
  export * from './def/ListItem';
25
25
 
26
26
  // dto
27
- export * from './dto/IdDto';
28
27
  export * from './dto/IdLabelDto';
29
28
  export * from './dto/IdLabelPrimaryDto';
30
29
  export * from './dto/InitCallDto';
@@ -1,10 +0,0 @@
1
- import { DataTypes } from '@etsoo/shared';
2
- /**
3
- * Dto with id field
4
- */
5
- export declare type IdDto<T extends DataTypes.IdType = number> = {
6
- /**
7
- * Id
8
- */
9
- readonly id: T;
10
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,10 +0,0 @@
1
- import { DataTypes } from '@etsoo/shared';
2
- /**
3
- * Dto with id field
4
- */
5
- export declare type IdDto<T extends DataTypes.IdType = number> = {
6
- /**
7
- * Id
8
- */
9
- readonly id: T;
10
- };
@@ -1 +0,0 @@
1
- export {};
package/src/dto/IdDto.ts DELETED
@@ -1,11 +0,0 @@
1
- import { DataTypes } from '@etsoo/shared';
2
-
3
- /**
4
- * Dto with id field
5
- */
6
- export type IdDto<T extends DataTypes.IdType = number> = {
7
- /**
8
- * Id
9
- */
10
- readonly id: T;
11
- };