@etsoo/appscript 1.1.52 → 1.1.56

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.
@@ -12,6 +12,29 @@ import { UserRole } from './UserRole';
12
12
  export interface IDetectIPCallback {
13
13
  (): void;
14
14
  }
15
+ /**
16
+ * Refresh token result type
17
+ * true means success, false means failed but no any message
18
+ * other cases means failed with differnet message
19
+ */
20
+ export declare type RefreshTokenResult = boolean | string | ApiDataError | IActionResult;
21
+ /**
22
+ * Refresh token props
23
+ */
24
+ export interface RefreshTokenProps<D extends {}> {
25
+ /**
26
+ * Callback
27
+ */
28
+ callback?: (result: RefreshTokenResult) => void;
29
+ /**
30
+ * Data to pass
31
+ */
32
+ data?: D;
33
+ /**
34
+ * Show loading bar or not
35
+ */
36
+ showLoading?: boolean;
37
+ }
15
38
  /**
16
39
  * Core application interface
17
40
  */
@@ -171,13 +194,19 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
171
194
  pageExit(): void;
172
195
  /**
173
196
  * Refresh token
197
+ * @param props Props
174
198
  */
175
- refreshToken(): Promise<boolean>;
199
+ refreshToken<D extends {} = {}>(props?: RefreshTokenProps<D>): Promise<boolean>;
176
200
  /**
177
201
  * Signout
178
202
  * @param apiUrl Signout API URL
179
203
  */
180
204
  signout(apiUrl?: string): Promise<void>;
205
+ /**
206
+ * Switch organization
207
+ * @param apiOrOrg API URL or organization id
208
+ */
209
+ switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
181
210
  /**
182
211
  * Go to the login page
183
212
  */
@@ -415,8 +444,9 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
415
444
  abstract freshCountdownUI(callback?: () => PromiseLike<unknown>): void;
416
445
  /**
417
446
  * Refresh token
447
+ * @param callback Callback
418
448
  */
419
- refreshToken(): Promise<boolean>;
449
+ refreshToken<D extends {} = {}>(props?: RefreshTokenProps<D>): Promise<boolean>;
420
450
  /**
421
451
  * Setup callback
422
452
  */
@@ -426,6 +456,11 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
426
456
  * @param apiUrl Signout API URL
427
457
  */
428
458
  signout(apiUrl?: string): Promise<void>;
459
+ /**
460
+ * Switch organization
461
+ * @param apiOrOrg API URL or organization id
462
+ */
463
+ switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
429
464
  /**
430
465
  * Go to the login page
431
466
  */
@@ -438,6 +473,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
438
473
  transformUrl(url: string): string;
439
474
  /**
440
475
  * Try login, returning false means is loading
476
+ * UI get involved while refreshToken not intended
441
477
  */
442
478
  tryLogin(): Promise<boolean>;
443
479
  /**
@@ -399,8 +399,11 @@ class CoreApp {
399
399
  }
400
400
  /**
401
401
  * Refresh token
402
+ * @param callback Callback
402
403
  */
403
- async refreshToken() {
404
+ async refreshToken(props) {
405
+ if (props && props.callback)
406
+ props.callback(true);
404
407
  return true;
405
408
  }
406
409
  /**
@@ -424,6 +427,19 @@ class CoreApp {
424
427
  // Go to login page
425
428
  this.toLoginPage();
426
429
  }
430
+ /**
431
+ * Switch organization
432
+ * @param apiOrOrg API URL or organization id
433
+ */
434
+ async switchOrg(apiOrOrg) {
435
+ const api = typeof apiOrOrg === 'number'
436
+ ? `Organization/Switch/${apiOrOrg}`
437
+ : apiOrOrg;
438
+ const result = await this.api.put(api);
439
+ if (result)
440
+ return await this.refreshToken();
441
+ return result;
442
+ }
427
443
  /**
428
444
  * Go to the login page
429
445
  */
@@ -454,6 +470,7 @@ class CoreApp {
454
470
  }
455
471
  /**
456
472
  * Try login, returning false means is loading
473
+ * UI get involved while refreshToken not intended
457
474
  */
458
475
  async tryLogin() {
459
476
  if (this._isTryingLogin)
@@ -12,6 +12,29 @@ import { UserRole } from './UserRole';
12
12
  export interface IDetectIPCallback {
13
13
  (): void;
14
14
  }
15
+ /**
16
+ * Refresh token result type
17
+ * true means success, false means failed but no any message
18
+ * other cases means failed with differnet message
19
+ */
20
+ export declare type RefreshTokenResult = boolean | string | ApiDataError | IActionResult;
21
+ /**
22
+ * Refresh token props
23
+ */
24
+ export interface RefreshTokenProps<D extends {}> {
25
+ /**
26
+ * Callback
27
+ */
28
+ callback?: (result: RefreshTokenResult) => void;
29
+ /**
30
+ * Data to pass
31
+ */
32
+ data?: D;
33
+ /**
34
+ * Show loading bar or not
35
+ */
36
+ showLoading?: boolean;
37
+ }
15
38
  /**
16
39
  * Core application interface
17
40
  */
@@ -171,13 +194,19 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
171
194
  pageExit(): void;
172
195
  /**
173
196
  * Refresh token
197
+ * @param props Props
174
198
  */
175
- refreshToken(): Promise<boolean>;
199
+ refreshToken<D extends {} = {}>(props?: RefreshTokenProps<D>): Promise<boolean>;
176
200
  /**
177
201
  * Signout
178
202
  * @param apiUrl Signout API URL
179
203
  */
180
204
  signout(apiUrl?: string): Promise<void>;
205
+ /**
206
+ * Switch organization
207
+ * @param apiOrOrg API URL or organization id
208
+ */
209
+ switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
181
210
  /**
182
211
  * Go to the login page
183
212
  */
@@ -415,8 +444,9 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
415
444
  abstract freshCountdownUI(callback?: () => PromiseLike<unknown>): void;
416
445
  /**
417
446
  * Refresh token
447
+ * @param callback Callback
418
448
  */
419
- refreshToken(): Promise<boolean>;
449
+ refreshToken<D extends {} = {}>(props?: RefreshTokenProps<D>): Promise<boolean>;
420
450
  /**
421
451
  * Setup callback
422
452
  */
@@ -426,6 +456,11 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
426
456
  * @param apiUrl Signout API URL
427
457
  */
428
458
  signout(apiUrl?: string): Promise<void>;
459
+ /**
460
+ * Switch organization
461
+ * @param apiOrOrg API URL or organization id
462
+ */
463
+ switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
429
464
  /**
430
465
  * Go to the login page
431
466
  */
@@ -438,6 +473,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
438
473
  transformUrl(url: string): string;
439
474
  /**
440
475
  * Try login, returning false means is loading
476
+ * UI get involved while refreshToken not intended
441
477
  */
442
478
  tryLogin(): Promise<boolean>;
443
479
  /**
@@ -396,8 +396,11 @@ export class CoreApp {
396
396
  }
397
397
  /**
398
398
  * Refresh token
399
+ * @param callback Callback
399
400
  */
400
- async refreshToken() {
401
+ async refreshToken(props) {
402
+ if (props && props.callback)
403
+ props.callback(true);
401
404
  return true;
402
405
  }
403
406
  /**
@@ -421,6 +424,19 @@ export class CoreApp {
421
424
  // Go to login page
422
425
  this.toLoginPage();
423
426
  }
427
+ /**
428
+ * Switch organization
429
+ * @param apiOrOrg API URL or organization id
430
+ */
431
+ async switchOrg(apiOrOrg) {
432
+ const api = typeof apiOrOrg === 'number'
433
+ ? `Organization/Switch/${apiOrOrg}`
434
+ : apiOrOrg;
435
+ const result = await this.api.put(api);
436
+ if (result)
437
+ return await this.refreshToken();
438
+ return result;
439
+ }
424
440
  /**
425
441
  * Go to the login page
426
442
  */
@@ -451,6 +467,7 @@ export class CoreApp {
451
467
  }
452
468
  /**
453
469
  * Try login, returning false means is loading
470
+ * UI get involved while refreshToken not intended
454
471
  */
455
472
  async tryLogin() {
456
473
  if (this._isTryingLogin)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.1.52",
3
+ "version": "1.1.56",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -65,7 +65,7 @@
65
65
  "@types/jest": "^27.0.3",
66
66
  "@typescript-eslint/eslint-plugin": "^5.5.0",
67
67
  "@typescript-eslint/parser": "^5.5.0",
68
- "eslint": "^8.3.0",
68
+ "eslint": "^8.4.0",
69
69
  "eslint-config-airbnb-base": "^15.0.0",
70
70
  "eslint-plugin-import": "^2.25.3",
71
71
  "jest": "^27.4.3",
@@ -29,6 +29,37 @@ export interface IDetectIPCallback {
29
29
  (): void;
30
30
  }
31
31
 
32
+ /**
33
+ * Refresh token result type
34
+ * true means success, false means failed but no any message
35
+ * other cases means failed with differnet message
36
+ */
37
+ export type RefreshTokenResult =
38
+ | boolean
39
+ | string
40
+ | ApiDataError
41
+ | IActionResult;
42
+
43
+ /**
44
+ * Refresh token props
45
+ */
46
+ export interface RefreshTokenProps<D extends {}> {
47
+ /**
48
+ * Callback
49
+ */
50
+ callback?: (result: RefreshTokenResult) => void;
51
+
52
+ /**
53
+ * Data to pass
54
+ */
55
+ data?: D;
56
+
57
+ /**
58
+ * Show loading bar or not
59
+ */
60
+ showLoading?: boolean;
61
+ }
62
+
32
63
  /**
33
64
  * Core application interface
34
65
  */
@@ -231,8 +262,11 @@ export interface ICoreApp<
231
262
 
232
263
  /**
233
264
  * Refresh token
265
+ * @param props Props
234
266
  */
235
- refreshToken(): Promise<boolean>;
267
+ refreshToken<D extends {} = {}>(
268
+ props?: RefreshTokenProps<D>
269
+ ): Promise<boolean>;
236
270
 
237
271
  /**
238
272
  * Signout
@@ -240,6 +274,12 @@ export interface ICoreApp<
240
274
  */
241
275
  signout(apiUrl?: string): Promise<void>;
242
276
 
277
+ /**
278
+ * Switch organization
279
+ * @param apiOrOrg API URL or organization id
280
+ */
281
+ switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
282
+
243
283
  /**
244
284
  * Go to the login page
245
285
  */
@@ -817,8 +857,10 @@ export abstract class CoreApp<
817
857
 
818
858
  /**
819
859
  * Refresh token
860
+ * @param callback Callback
820
861
  */
821
- async refreshToken(): Promise<boolean> {
862
+ async refreshToken<D extends {} = {}>(props?: RefreshTokenProps<D>) {
863
+ if (props && props.callback) props.callback(true);
822
864
  return true;
823
865
  }
824
866
 
@@ -847,6 +889,20 @@ export abstract class CoreApp<
847
889
  this.toLoginPage();
848
890
  }
849
891
 
892
+ /**
893
+ * Switch organization
894
+ * @param apiOrOrg API URL or organization id
895
+ */
896
+ async switchOrg(apiOrOrg: string | number) {
897
+ const api =
898
+ typeof apiOrOrg === 'number'
899
+ ? `Organization/Switch/${apiOrOrg}`
900
+ : apiOrOrg;
901
+ const result = await this.api.put<boolean>(api);
902
+ if (result) return await this.refreshToken();
903
+ return result;
904
+ }
905
+
850
906
  /**
851
907
  * Go to the login page
852
908
  */
@@ -881,6 +937,7 @@ export abstract class CoreApp<
881
937
 
882
938
  /**
883
939
  * Try login, returning false means is loading
940
+ * UI get involved while refreshToken not intended
884
941
  */
885
942
  async tryLogin() {
886
943
  if (this._isTryingLogin) return false;