@etsoo/appscript 1.1.51 → 1.1.55
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/lib/cjs/app/CoreApp.d.ts +52 -2
- package/lib/cjs/app/CoreApp.js +41 -1
- package/lib/mjs/app/CoreApp.d.ts +52 -2
- package/lib/mjs/app/CoreApp.js +41 -1
- package/package.json +2 -2
- package/src/app/CoreApp.ts +92 -2
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -12,6 +12,25 @@ 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
|
+
* Data to pass
|
|
27
|
+
*/
|
|
28
|
+
data?: D;
|
|
29
|
+
/**
|
|
30
|
+
* Callback
|
|
31
|
+
*/
|
|
32
|
+
callback?: (result: RefreshTokenResult) => void;
|
|
33
|
+
}
|
|
15
34
|
/**
|
|
16
35
|
* Core application interface
|
|
17
36
|
*/
|
|
@@ -171,8 +190,23 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
171
190
|
pageExit(): void;
|
|
172
191
|
/**
|
|
173
192
|
* Refresh token
|
|
193
|
+
* @param props Props
|
|
194
|
+
*/
|
|
195
|
+
refreshToken<D extends {} = {}>(props?: RefreshTokenProps<D>): Promise<boolean>;
|
|
196
|
+
/**
|
|
197
|
+
* Signout
|
|
198
|
+
* @param apiUrl Signout API URL
|
|
174
199
|
*/
|
|
175
|
-
|
|
200
|
+
signout(apiUrl?: string): Promise<void>;
|
|
201
|
+
/**
|
|
202
|
+
* Switch organization
|
|
203
|
+
* @param apiOrOrg API URL or organization id
|
|
204
|
+
*/
|
|
205
|
+
switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
|
|
206
|
+
/**
|
|
207
|
+
* Go to the login page
|
|
208
|
+
*/
|
|
209
|
+
toLoginPage(): void;
|
|
176
210
|
/**
|
|
177
211
|
* Transform URL
|
|
178
212
|
* @param url URL
|
|
@@ -406,12 +440,27 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
406
440
|
abstract freshCountdownUI(callback?: () => PromiseLike<unknown>): void;
|
|
407
441
|
/**
|
|
408
442
|
* Refresh token
|
|
443
|
+
* @param callback Callback
|
|
409
444
|
*/
|
|
410
|
-
refreshToken(): Promise<boolean>;
|
|
445
|
+
refreshToken<D extends {} = {}>(props?: RefreshTokenProps<D>): Promise<boolean>;
|
|
411
446
|
/**
|
|
412
447
|
* Setup callback
|
|
413
448
|
*/
|
|
414
449
|
setup(): void;
|
|
450
|
+
/**
|
|
451
|
+
* Signout
|
|
452
|
+
* @param apiUrl Signout API URL
|
|
453
|
+
*/
|
|
454
|
+
signout(apiUrl?: string): Promise<void>;
|
|
455
|
+
/**
|
|
456
|
+
* Switch organization
|
|
457
|
+
* @param apiOrOrg API URL or organization id
|
|
458
|
+
*/
|
|
459
|
+
switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
|
|
460
|
+
/**
|
|
461
|
+
* Go to the login page
|
|
462
|
+
*/
|
|
463
|
+
toLoginPage(): void;
|
|
415
464
|
/**
|
|
416
465
|
* Transform URL
|
|
417
466
|
* @param url URL
|
|
@@ -420,6 +469,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
420
469
|
transformUrl(url: string): string;
|
|
421
470
|
/**
|
|
422
471
|
* Try login, returning false means is loading
|
|
472
|
+
* UI get involved while refreshToken not intended
|
|
423
473
|
*/
|
|
424
474
|
tryLogin(): Promise<boolean>;
|
|
425
475
|
/**
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -399,14 +399,53 @@ 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
|
/**
|
|
407
410
|
* Setup callback
|
|
408
411
|
*/
|
|
409
412
|
setup() { }
|
|
413
|
+
/**
|
|
414
|
+
* Signout
|
|
415
|
+
* @param apiUrl Signout API URL
|
|
416
|
+
*/
|
|
417
|
+
async signout(apiUrl) {
|
|
418
|
+
await this.api.put(apiUrl !== null && apiUrl !== void 0 ? apiUrl : 'User/Signout', undefined, {
|
|
419
|
+
onError: (error) => {
|
|
420
|
+
console.log(error);
|
|
421
|
+
// Prevent further processing
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
// Clear
|
|
426
|
+
this.userLogout();
|
|
427
|
+
// Go to login page
|
|
428
|
+
this.toLoginPage();
|
|
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
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Go to the login page
|
|
445
|
+
*/
|
|
446
|
+
toLoginPage() {
|
|
447
|
+
window.location.replace(this.transformUrl('/'));
|
|
448
|
+
}
|
|
410
449
|
/**
|
|
411
450
|
* Transform URL
|
|
412
451
|
* @param url URL
|
|
@@ -431,6 +470,7 @@ class CoreApp {
|
|
|
431
470
|
}
|
|
432
471
|
/**
|
|
433
472
|
* Try login, returning false means is loading
|
|
473
|
+
* UI get involved while refreshToken not intended
|
|
434
474
|
*/
|
|
435
475
|
async tryLogin() {
|
|
436
476
|
if (this._isTryingLogin)
|
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -12,6 +12,25 @@ 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
|
+
* Data to pass
|
|
27
|
+
*/
|
|
28
|
+
data?: D;
|
|
29
|
+
/**
|
|
30
|
+
* Callback
|
|
31
|
+
*/
|
|
32
|
+
callback?: (result: RefreshTokenResult) => void;
|
|
33
|
+
}
|
|
15
34
|
/**
|
|
16
35
|
* Core application interface
|
|
17
36
|
*/
|
|
@@ -171,8 +190,23 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
171
190
|
pageExit(): void;
|
|
172
191
|
/**
|
|
173
192
|
* Refresh token
|
|
193
|
+
* @param props Props
|
|
194
|
+
*/
|
|
195
|
+
refreshToken<D extends {} = {}>(props?: RefreshTokenProps<D>): Promise<boolean>;
|
|
196
|
+
/**
|
|
197
|
+
* Signout
|
|
198
|
+
* @param apiUrl Signout API URL
|
|
174
199
|
*/
|
|
175
|
-
|
|
200
|
+
signout(apiUrl?: string): Promise<void>;
|
|
201
|
+
/**
|
|
202
|
+
* Switch organization
|
|
203
|
+
* @param apiOrOrg API URL or organization id
|
|
204
|
+
*/
|
|
205
|
+
switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
|
|
206
|
+
/**
|
|
207
|
+
* Go to the login page
|
|
208
|
+
*/
|
|
209
|
+
toLoginPage(): void;
|
|
176
210
|
/**
|
|
177
211
|
* Transform URL
|
|
178
212
|
* @param url URL
|
|
@@ -406,12 +440,27 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
406
440
|
abstract freshCountdownUI(callback?: () => PromiseLike<unknown>): void;
|
|
407
441
|
/**
|
|
408
442
|
* Refresh token
|
|
443
|
+
* @param callback Callback
|
|
409
444
|
*/
|
|
410
|
-
refreshToken(): Promise<boolean>;
|
|
445
|
+
refreshToken<D extends {} = {}>(props?: RefreshTokenProps<D>): Promise<boolean>;
|
|
411
446
|
/**
|
|
412
447
|
* Setup callback
|
|
413
448
|
*/
|
|
414
449
|
setup(): void;
|
|
450
|
+
/**
|
|
451
|
+
* Signout
|
|
452
|
+
* @param apiUrl Signout API URL
|
|
453
|
+
*/
|
|
454
|
+
signout(apiUrl?: string): Promise<void>;
|
|
455
|
+
/**
|
|
456
|
+
* Switch organization
|
|
457
|
+
* @param apiOrOrg API URL or organization id
|
|
458
|
+
*/
|
|
459
|
+
switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
|
|
460
|
+
/**
|
|
461
|
+
* Go to the login page
|
|
462
|
+
*/
|
|
463
|
+
toLoginPage(): void;
|
|
415
464
|
/**
|
|
416
465
|
* Transform URL
|
|
417
466
|
* @param url URL
|
|
@@ -420,6 +469,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
420
469
|
transformUrl(url: string): string;
|
|
421
470
|
/**
|
|
422
471
|
* Try login, returning false means is loading
|
|
472
|
+
* UI get involved while refreshToken not intended
|
|
423
473
|
*/
|
|
424
474
|
tryLogin(): Promise<boolean>;
|
|
425
475
|
/**
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -396,14 +396,53 @@ 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
|
/**
|
|
404
407
|
* Setup callback
|
|
405
408
|
*/
|
|
406
409
|
setup() { }
|
|
410
|
+
/**
|
|
411
|
+
* Signout
|
|
412
|
+
* @param apiUrl Signout API URL
|
|
413
|
+
*/
|
|
414
|
+
async signout(apiUrl) {
|
|
415
|
+
await this.api.put(apiUrl !== null && apiUrl !== void 0 ? apiUrl : 'User/Signout', undefined, {
|
|
416
|
+
onError: (error) => {
|
|
417
|
+
console.log(error);
|
|
418
|
+
// Prevent further processing
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
// Clear
|
|
423
|
+
this.userLogout();
|
|
424
|
+
// Go to login page
|
|
425
|
+
this.toLoginPage();
|
|
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
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Go to the login page
|
|
442
|
+
*/
|
|
443
|
+
toLoginPage() {
|
|
444
|
+
window.location.replace(this.transformUrl('/'));
|
|
445
|
+
}
|
|
407
446
|
/**
|
|
408
447
|
* Transform URL
|
|
409
448
|
* @param url URL
|
|
@@ -428,6 +467,7 @@ export class CoreApp {
|
|
|
428
467
|
}
|
|
429
468
|
/**
|
|
430
469
|
* Try login, returning false means is loading
|
|
470
|
+
* UI get involved while refreshToken not intended
|
|
431
471
|
*/
|
|
432
472
|
async tryLogin() {
|
|
433
473
|
if (this._isTryingLogin)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/appscript",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.55",
|
|
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.
|
|
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",
|
package/src/app/CoreApp.ts
CHANGED
|
@@ -29,6 +29,32 @@ 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
|
+
* Data to pass
|
|
49
|
+
*/
|
|
50
|
+
data?: D;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Callback
|
|
54
|
+
*/
|
|
55
|
+
callback?: (result: RefreshTokenResult) => void;
|
|
56
|
+
}
|
|
57
|
+
|
|
32
58
|
/**
|
|
33
59
|
* Core application interface
|
|
34
60
|
*/
|
|
@@ -231,8 +257,28 @@ export interface ICoreApp<
|
|
|
231
257
|
|
|
232
258
|
/**
|
|
233
259
|
* Refresh token
|
|
260
|
+
* @param props Props
|
|
261
|
+
*/
|
|
262
|
+
refreshToken<D extends {} = {}>(
|
|
263
|
+
props?: RefreshTokenProps<D>
|
|
264
|
+
): Promise<boolean>;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Signout
|
|
268
|
+
* @param apiUrl Signout API URL
|
|
269
|
+
*/
|
|
270
|
+
signout(apiUrl?: string): Promise<void>;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Switch organization
|
|
274
|
+
* @param apiOrOrg API URL or organization id
|
|
275
|
+
*/
|
|
276
|
+
switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Go to the login page
|
|
234
280
|
*/
|
|
235
|
-
|
|
281
|
+
toLoginPage(): void;
|
|
236
282
|
|
|
237
283
|
/**
|
|
238
284
|
* Transform URL
|
|
@@ -806,8 +852,10 @@ export abstract class CoreApp<
|
|
|
806
852
|
|
|
807
853
|
/**
|
|
808
854
|
* Refresh token
|
|
855
|
+
* @param callback Callback
|
|
809
856
|
*/
|
|
810
|
-
async refreshToken(
|
|
857
|
+
async refreshToken<D extends {} = {}>(props?: RefreshTokenProps<D>) {
|
|
858
|
+
if (props && props.callback) props.callback(true);
|
|
811
859
|
return true;
|
|
812
860
|
}
|
|
813
861
|
|
|
@@ -816,6 +864,47 @@ export abstract class CoreApp<
|
|
|
816
864
|
*/
|
|
817
865
|
setup() {}
|
|
818
866
|
|
|
867
|
+
/**
|
|
868
|
+
* Signout
|
|
869
|
+
* @param apiUrl Signout API URL
|
|
870
|
+
*/
|
|
871
|
+
async signout(apiUrl?: string) {
|
|
872
|
+
await this.api.put<boolean>(apiUrl ?? 'User/Signout', undefined, {
|
|
873
|
+
onError: (error) => {
|
|
874
|
+
console.log(error);
|
|
875
|
+
// Prevent further processing
|
|
876
|
+
return false;
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
|
|
880
|
+
// Clear
|
|
881
|
+
this.userLogout();
|
|
882
|
+
|
|
883
|
+
// Go to login page
|
|
884
|
+
this.toLoginPage();
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Switch organization
|
|
889
|
+
* @param apiOrOrg API URL or organization id
|
|
890
|
+
*/
|
|
891
|
+
async switchOrg(apiOrOrg: string | number) {
|
|
892
|
+
const api =
|
|
893
|
+
typeof apiOrOrg === 'number'
|
|
894
|
+
? `Organization/Switch/${apiOrOrg}`
|
|
895
|
+
: apiOrOrg;
|
|
896
|
+
const result = await this.api.put<boolean>(api);
|
|
897
|
+
if (result) return await this.refreshToken();
|
|
898
|
+
return result;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
/**
|
|
902
|
+
* Go to the login page
|
|
903
|
+
*/
|
|
904
|
+
toLoginPage() {
|
|
905
|
+
window.location.replace(this.transformUrl('/'));
|
|
906
|
+
}
|
|
907
|
+
|
|
819
908
|
/**
|
|
820
909
|
* Transform URL
|
|
821
910
|
* @param url URL
|
|
@@ -843,6 +932,7 @@ export abstract class CoreApp<
|
|
|
843
932
|
|
|
844
933
|
/**
|
|
845
934
|
* Try login, returning false means is loading
|
|
935
|
+
* UI get involved while refreshToken not intended
|
|
846
936
|
*/
|
|
847
937
|
async tryLogin() {
|
|
848
938
|
if (this._isTryingLogin) return false;
|