@etsoo/appscript 1.1.80 → 1.1.84

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.
@@ -129,6 +129,18 @@ test('Tests for encrypt / decrypt', () => {
129
129
  expect(plain).toEqual(input);
130
130
  });
131
131
 
132
+ test('Tests for encryptEnhanced / decryptEnhanced', () => {
133
+ // Arrange
134
+ const input = 'Hello, world!';
135
+ const passphrase = 'My password';
136
+
137
+ // Act
138
+ const encrypted = app.encryptEnhanced(input, passphrase);
139
+ console.log(encrypted);
140
+ const plain = app.decryptEnhanced(encrypted, passphrase);
141
+ expect(plain).toEqual(input);
142
+ });
143
+
132
144
  test('Tests for initCallUpdateLocal', () => {
133
145
  // Act
134
146
  const passphrase = app.initCallUpdateLocal(
@@ -2,8 +2,10 @@ import { INotifier, NotificationAlign, NotificationCallProps, NotificationConten
2
2
  import { ApiDataError, IApi, IPData } from '@etsoo/restclient';
3
3
  import { DataTypes, DateUtils } from '@etsoo/shared';
4
4
  import { AddressRegion } from '../address/AddressRegion';
5
+ import { IdLabelDto } from '../dto/IdLabelDto';
6
+ import { InitCallDto } from '../dto/InitCallDto';
5
7
  import { IActionResult } from '../result/IActionResult';
6
- import { InitCallResultData } from '../result/InitCallResult';
8
+ import { InitCallResult, InitCallResultData } from '../result/InitCallResult';
7
9
  import { IUserData } from '../state/User';
8
10
  import { IAppSettings } from './AppSettings';
9
11
  import { UserRole } from './UserRole';
@@ -26,7 +28,7 @@ export interface RefreshTokenProps<D extends {}> {
26
28
  /**
27
29
  * Callback
28
30
  */
29
- callback?: (result: RefreshTokenResult) => void;
31
+ callback?: (result: RefreshTokenResult, successData?: string) => void;
30
32
  /**
31
33
  * Data to pass
32
34
  */
@@ -277,6 +279,13 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
277
279
  * @param apiUrl Signout API URL
278
280
  */
279
281
  signout(apiUrl?: string): Promise<void>;
282
+ /**
283
+ * Get organization list
284
+ * @param items Max items
285
+ * @param serviceId Service id
286
+ * @returns Result
287
+ */
288
+ orgList(items?: number, serviceId?: number): Promise<IdLabelDto[] | undefined>;
280
289
  /**
281
290
  * Switch organization
282
291
  * @param apiOrOrg API URL or organization id
@@ -402,6 +411,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
402
411
  * Device id field name
403
412
  */
404
413
  protected deviceIdField: string;
414
+ /**
415
+ * Init call Api URL
416
+ */
417
+ protected initCallApi: string;
405
418
  /**
406
419
  * Passphrase for encryption
407
420
  */
@@ -416,6 +429,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
416
429
  */
417
430
  protected constructor(settings: S, api: IApi, notifier: INotifier<N, C>, name: string);
418
431
  protected setApi(api: IApi): void;
432
+ /**
433
+ * Api init call
434
+ * @param data Data
435
+ * @returns Result
436
+ */
437
+ protected apiInitCall(data: InitCallDto): Promise<InitCallResult | undefined>;
419
438
  /**
420
439
  * Init call
421
440
  * @param callback Callback
@@ -626,11 +645,18 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
626
645
  * @param apiUrl Signout API URL
627
646
  */
628
647
  signout(apiUrl?: string): Promise<void>;
648
+ /**
649
+ * Get organization list
650
+ * @param items Max items
651
+ * @param serviceId Service id
652
+ * @returns Result
653
+ */
654
+ orgList(items?: number, serviceId?: number): Promise<IdLabelDto<number>[] | undefined>;
629
655
  /**
630
656
  * Switch organization
631
- * @param apiOrOrg API URL or organization id
657
+ * @param id Organization id
632
658
  */
633
- switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
659
+ switchOrg(id: number): Promise<boolean | undefined>;
634
660
  /**
635
661
  * Go to the login page
636
662
  */
@@ -39,6 +39,10 @@ class CoreApp {
39
39
  * Device id field name
40
40
  */
41
41
  this.deviceIdField = 'SmartERPDeviceId';
42
+ /**
43
+ * Init call Api URL
44
+ */
45
+ this.initCallApi = 'Auth/WebInitCall';
42
46
  /**
43
47
  * Passphrase for encryption
44
48
  */
@@ -127,6 +131,14 @@ class CoreApp {
127
131
  }
128
132
  };
129
133
  }
134
+ /**
135
+ * Api init call
136
+ * @param data Data
137
+ * @returns Result
138
+ */
139
+ async apiInitCall(data) {
140
+ return await this.api.put(this.initCallApi, data);
141
+ }
130
142
  /**
131
143
  * Init call
132
144
  * @param callback Callback
@@ -138,7 +150,7 @@ class CoreApp {
138
150
  timestamp: new Date().getTime(),
139
151
  deviceId: this.deviceId === '' ? undefined : this.deviceId
140
152
  };
141
- const result = await this.api.put('Auth/WebInitCall', data);
153
+ const result = await this.apiInitCall(data);
142
154
  if (result == null) {
143
155
  if (callback)
144
156
  callback(false);
@@ -569,10 +581,7 @@ class CoreApp {
569
581
  const refreshToken = shared_1.StorageUtils.getLocalData(this.headerTokenField, '');
570
582
  if (refreshToken === '')
571
583
  return null;
572
- const result = this.decrypt(refreshToken);
573
- if (result == undefined)
574
- return null;
575
- return result;
584
+ return refreshToken;
576
585
  }
577
586
  /**
578
587
  * Get all regions
@@ -690,7 +699,7 @@ class CoreApp {
690
699
  */
691
700
  async refreshToken(props) {
692
701
  if (props && props.callback)
693
- props.callback(true);
702
+ props.callback(true, undefined);
694
703
  return true;
695
704
  }
696
705
  /**
@@ -714,14 +723,24 @@ class CoreApp {
714
723
  // Go to login page
715
724
  this.toLoginPage();
716
725
  }
726
+ /**
727
+ * Get organization list
728
+ * @param items Max items
729
+ * @param serviceId Service id
730
+ * @returns Result
731
+ */
732
+ async orgList(items, serviceId) {
733
+ return await this.api.post('Organization/List', {
734
+ items,
735
+ serviceId
736
+ }, { defaultValue: [], showLoading: false });
737
+ }
717
738
  /**
718
739
  * Switch organization
719
- * @param apiOrOrg API URL or organization id
740
+ * @param id Organization id
720
741
  */
721
- async switchOrg(apiOrOrg) {
722
- const api = typeof apiOrOrg === 'number'
723
- ? `Organization/Switch/${apiOrOrg}`
724
- : apiOrOrg;
742
+ async switchOrg(id) {
743
+ const api = `Organization/Switch/${id}`;
725
744
  const result = await this.api.put(api);
726
745
  if (result)
727
746
  return await this.refreshToken();
@@ -2,8 +2,10 @@ import { INotifier, NotificationAlign, NotificationCallProps, NotificationConten
2
2
  import { ApiDataError, IApi, IPData } from '@etsoo/restclient';
3
3
  import { DataTypes, DateUtils } from '@etsoo/shared';
4
4
  import { AddressRegion } from '../address/AddressRegion';
5
+ import { IdLabelDto } from '../dto/IdLabelDto';
6
+ import { InitCallDto } from '../dto/InitCallDto';
5
7
  import { IActionResult } from '../result/IActionResult';
6
- import { InitCallResultData } from '../result/InitCallResult';
8
+ import { InitCallResult, InitCallResultData } from '../result/InitCallResult';
7
9
  import { IUserData } from '../state/User';
8
10
  import { IAppSettings } from './AppSettings';
9
11
  import { UserRole } from './UserRole';
@@ -26,7 +28,7 @@ export interface RefreshTokenProps<D extends {}> {
26
28
  /**
27
29
  * Callback
28
30
  */
29
- callback?: (result: RefreshTokenResult) => void;
31
+ callback?: (result: RefreshTokenResult, successData?: string) => void;
30
32
  /**
31
33
  * Data to pass
32
34
  */
@@ -277,6 +279,13 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
277
279
  * @param apiUrl Signout API URL
278
280
  */
279
281
  signout(apiUrl?: string): Promise<void>;
282
+ /**
283
+ * Get organization list
284
+ * @param items Max items
285
+ * @param serviceId Service id
286
+ * @returns Result
287
+ */
288
+ orgList(items?: number, serviceId?: number): Promise<IdLabelDto[] | undefined>;
280
289
  /**
281
290
  * Switch organization
282
291
  * @param apiOrOrg API URL or organization id
@@ -402,6 +411,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
402
411
  * Device id field name
403
412
  */
404
413
  protected deviceIdField: string;
414
+ /**
415
+ * Init call Api URL
416
+ */
417
+ protected initCallApi: string;
405
418
  /**
406
419
  * Passphrase for encryption
407
420
  */
@@ -416,6 +429,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
416
429
  */
417
430
  protected constructor(settings: S, api: IApi, notifier: INotifier<N, C>, name: string);
418
431
  protected setApi(api: IApi): void;
432
+ /**
433
+ * Api init call
434
+ * @param data Data
435
+ * @returns Result
436
+ */
437
+ protected apiInitCall(data: InitCallDto): Promise<InitCallResult | undefined>;
419
438
  /**
420
439
  * Init call
421
440
  * @param callback Callback
@@ -626,11 +645,18 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
626
645
  * @param apiUrl Signout API URL
627
646
  */
628
647
  signout(apiUrl?: string): Promise<void>;
648
+ /**
649
+ * Get organization list
650
+ * @param items Max items
651
+ * @param serviceId Service id
652
+ * @returns Result
653
+ */
654
+ orgList(items?: number, serviceId?: number): Promise<IdLabelDto<number>[] | undefined>;
629
655
  /**
630
656
  * Switch organization
631
- * @param apiOrOrg API URL or organization id
657
+ * @param id Organization id
632
658
  */
633
- switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
659
+ switchOrg(id: number): Promise<boolean | undefined>;
634
660
  /**
635
661
  * Go to the login page
636
662
  */
@@ -36,6 +36,10 @@ export class CoreApp {
36
36
  * Device id field name
37
37
  */
38
38
  this.deviceIdField = 'SmartERPDeviceId';
39
+ /**
40
+ * Init call Api URL
41
+ */
42
+ this.initCallApi = 'Auth/WebInitCall';
39
43
  /**
40
44
  * Passphrase for encryption
41
45
  */
@@ -124,6 +128,14 @@ export class CoreApp {
124
128
  }
125
129
  };
126
130
  }
131
+ /**
132
+ * Api init call
133
+ * @param data Data
134
+ * @returns Result
135
+ */
136
+ async apiInitCall(data) {
137
+ return await this.api.put(this.initCallApi, data);
138
+ }
127
139
  /**
128
140
  * Init call
129
141
  * @param callback Callback
@@ -135,7 +147,7 @@ export class CoreApp {
135
147
  timestamp: new Date().getTime(),
136
148
  deviceId: this.deviceId === '' ? undefined : this.deviceId
137
149
  };
138
- const result = await this.api.put('Auth/WebInitCall', data);
150
+ const result = await this.apiInitCall(data);
139
151
  if (result == null) {
140
152
  if (callback)
141
153
  callback(false);
@@ -566,10 +578,7 @@ export class CoreApp {
566
578
  const refreshToken = StorageUtils.getLocalData(this.headerTokenField, '');
567
579
  if (refreshToken === '')
568
580
  return null;
569
- const result = this.decrypt(refreshToken);
570
- if (result == undefined)
571
- return null;
572
- return result;
581
+ return refreshToken;
573
582
  }
574
583
  /**
575
584
  * Get all regions
@@ -687,7 +696,7 @@ export class CoreApp {
687
696
  */
688
697
  async refreshToken(props) {
689
698
  if (props && props.callback)
690
- props.callback(true);
699
+ props.callback(true, undefined);
691
700
  return true;
692
701
  }
693
702
  /**
@@ -711,14 +720,24 @@ export class CoreApp {
711
720
  // Go to login page
712
721
  this.toLoginPage();
713
722
  }
723
+ /**
724
+ * Get organization list
725
+ * @param items Max items
726
+ * @param serviceId Service id
727
+ * @returns Result
728
+ */
729
+ async orgList(items, serviceId) {
730
+ return await this.api.post('Organization/List', {
731
+ items,
732
+ serviceId
733
+ }, { defaultValue: [], showLoading: false });
734
+ }
714
735
  /**
715
736
  * Switch organization
716
- * @param apiOrOrg API URL or organization id
737
+ * @param id Organization id
717
738
  */
718
- async switchOrg(apiOrOrg) {
719
- const api = typeof apiOrOrg === 'number'
720
- ? `Organization/Switch/${apiOrOrg}`
721
- : apiOrOrg;
739
+ async switchOrg(id) {
740
+ const api = `Organization/Switch/${id}`;
722
741
  const result = await this.api.put(api);
723
742
  if (result)
724
743
  return await this.refreshToken();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.1.80",
3
+ "version": "1.1.84",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -28,6 +28,7 @@ import {
28
28
  } from 'crypto-js';
29
29
  import { AddressRegion } from '../address/AddressRegion';
30
30
  import { AddressUtils } from '../address/AddressUtils';
31
+ import { IdLabelDto } from '../dto/IdLabelDto';
31
32
  import { InitCallDto } from '../dto/InitCallDto';
32
33
  import { ActionResultError } from '../result/ActionResultError';
33
34
  import { IActionResult } from '../result/IActionResult';
@@ -61,7 +62,7 @@ export interface RefreshTokenProps<D extends {}> {
61
62
  /**
62
63
  * Callback
63
64
  */
64
- callback?: (result: RefreshTokenResult) => void;
65
+ callback?: (result: RefreshTokenResult, successData?: string) => void;
65
66
 
66
67
  /**
67
68
  * Data to pass
@@ -382,6 +383,17 @@ export interface ICoreApp<
382
383
  */
383
384
  signout(apiUrl?: string): Promise<void>;
384
385
 
386
+ /**
387
+ * Get organization list
388
+ * @param items Max items
389
+ * @param serviceId Service id
390
+ * @returns Result
391
+ */
392
+ orgList(
393
+ items?: number,
394
+ serviceId?: number
395
+ ): Promise<IdLabelDto[] | undefined>;
396
+
385
397
  /**
386
398
  * Switch organization
387
399
  * @param apiOrOrg API URL or organization id
@@ -557,6 +569,11 @@ export abstract class CoreApp<
557
569
  */
558
570
  protected deviceIdField: string = 'SmartERPDeviceId';
559
571
 
572
+ /**
573
+ * Init call Api URL
574
+ */
575
+ protected initCallApi: string = 'Auth/WebInitCall';
576
+
560
577
  /**
561
578
  * Passphrase for encryption
562
579
  */
@@ -631,6 +648,15 @@ export abstract class CoreApp<
631
648
  };
632
649
  }
633
650
 
651
+ /**
652
+ * Api init call
653
+ * @param data Data
654
+ * @returns Result
655
+ */
656
+ protected async apiInitCall(data: InitCallDto) {
657
+ return await this.api.put<InitCallResult>(this.initCallApi, data);
658
+ }
659
+
634
660
  /**
635
661
  * Init call
636
662
  * @param callback Callback
@@ -641,10 +667,7 @@ export abstract class CoreApp<
641
667
  timestamp: new Date().getTime(),
642
668
  deviceId: this.deviceId === '' ? undefined : this.deviceId
643
669
  };
644
- const result = await this.api.put<InitCallResult>(
645
- 'Auth/WebInitCall',
646
- data
647
- );
670
+ const result = await this.apiInitCall(data);
648
671
  if (result == null) {
649
672
  if (callback) callback(false);
650
673
  return;
@@ -1180,9 +1203,7 @@ export abstract class CoreApp<
1180
1203
 
1181
1204
  if (refreshToken === '') return null;
1182
1205
 
1183
- const result = this.decrypt(refreshToken);
1184
- if (result == undefined) return null;
1185
- return result;
1206
+ return refreshToken;
1186
1207
  }
1187
1208
 
1188
1209
  /**
@@ -1312,7 +1333,7 @@ export abstract class CoreApp<
1312
1333
  * @param props Props
1313
1334
  */
1314
1335
  async refreshToken<D extends {} = {}>(props?: RefreshTokenProps<D>) {
1315
- if (props && props.callback) props.callback(true);
1336
+ if (props && props.callback) props.callback(true, undefined);
1316
1337
  return true;
1317
1338
  }
1318
1339
 
@@ -1341,15 +1362,29 @@ export abstract class CoreApp<
1341
1362
  this.toLoginPage();
1342
1363
  }
1343
1364
 
1365
+ /**
1366
+ * Get organization list
1367
+ * @param items Max items
1368
+ * @param serviceId Service id
1369
+ * @returns Result
1370
+ */
1371
+ async orgList(items?: number, serviceId?: number) {
1372
+ return await this.api.post<IdLabelDto[]>(
1373
+ 'Organization/List',
1374
+ {
1375
+ items,
1376
+ serviceId
1377
+ },
1378
+ { defaultValue: [], showLoading: false }
1379
+ );
1380
+ }
1381
+
1344
1382
  /**
1345
1383
  * Switch organization
1346
- * @param apiOrOrg API URL or organization id
1384
+ * @param id Organization id
1347
1385
  */
1348
- async switchOrg(apiOrOrg: string | number) {
1349
- const api =
1350
- typeof apiOrOrg === 'number'
1351
- ? `Organization/Switch/${apiOrOrg}`
1352
- : apiOrOrg;
1386
+ async switchOrg(id: number) {
1387
+ const api = `Organization/Switch/${id}`;
1353
1388
  const result = await this.api.put<boolean>(api);
1354
1389
  if (result) return await this.refreshToken();
1355
1390
  return result;