@etsoo/appscript 1.1.50 → 1.1.54
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 +45 -2
- package/lib/cjs/app/CoreApp.js +41 -1
- package/lib/mjs/app/CoreApp.d.ts +45 -2
- package/lib/mjs/app/CoreApp.js +41 -1
- package/package.json +4 -4
- package/src/app/CoreApp.ts +82 -2
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -12,6 +12,18 @@ 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 callback
|
|
23
|
+
*/
|
|
24
|
+
export interface RefreshTokenCallback {
|
|
25
|
+
(result: RefreshTokenResult): void;
|
|
26
|
+
}
|
|
15
27
|
/**
|
|
16
28
|
* Core application interface
|
|
17
29
|
*/
|
|
@@ -171,8 +183,23 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
171
183
|
pageExit(): void;
|
|
172
184
|
/**
|
|
173
185
|
* Refresh token
|
|
186
|
+
* @param callback Callback
|
|
187
|
+
*/
|
|
188
|
+
refreshToken(callback?: RefreshTokenCallback): Promise<boolean>;
|
|
189
|
+
/**
|
|
190
|
+
* Signout
|
|
191
|
+
* @param apiUrl Signout API URL
|
|
192
|
+
*/
|
|
193
|
+
signout(apiUrl?: string): Promise<void>;
|
|
194
|
+
/**
|
|
195
|
+
* Switch organization
|
|
196
|
+
* @param apiOrOrg API URL or organization id
|
|
174
197
|
*/
|
|
175
|
-
|
|
198
|
+
switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
|
|
199
|
+
/**
|
|
200
|
+
* Go to the login page
|
|
201
|
+
*/
|
|
202
|
+
toLoginPage(): void;
|
|
176
203
|
/**
|
|
177
204
|
* Transform URL
|
|
178
205
|
* @param url URL
|
|
@@ -406,12 +433,27 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
406
433
|
abstract freshCountdownUI(callback?: () => PromiseLike<unknown>): void;
|
|
407
434
|
/**
|
|
408
435
|
* Refresh token
|
|
436
|
+
* @param callback Callback
|
|
409
437
|
*/
|
|
410
|
-
refreshToken(): Promise<boolean>;
|
|
438
|
+
refreshToken(callback?: RefreshTokenCallback): Promise<boolean>;
|
|
411
439
|
/**
|
|
412
440
|
* Setup callback
|
|
413
441
|
*/
|
|
414
442
|
setup(): void;
|
|
443
|
+
/**
|
|
444
|
+
* Signout
|
|
445
|
+
* @param apiUrl Signout API URL
|
|
446
|
+
*/
|
|
447
|
+
signout(apiUrl?: string): Promise<void>;
|
|
448
|
+
/**
|
|
449
|
+
* Switch organization
|
|
450
|
+
* @param apiOrOrg API URL or organization id
|
|
451
|
+
*/
|
|
452
|
+
switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
|
|
453
|
+
/**
|
|
454
|
+
* Go to the login page
|
|
455
|
+
*/
|
|
456
|
+
toLoginPage(): void;
|
|
415
457
|
/**
|
|
416
458
|
* Transform URL
|
|
417
459
|
* @param url URL
|
|
@@ -420,6 +462,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
420
462
|
transformUrl(url: string): string;
|
|
421
463
|
/**
|
|
422
464
|
* Try login, returning false means is loading
|
|
465
|
+
* UI get involved while refreshToken not intended
|
|
423
466
|
*/
|
|
424
467
|
tryLogin(): Promise<boolean>;
|
|
425
468
|
/**
|
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(callback) {
|
|
405
|
+
if (callback)
|
|
406
|
+
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,18 @@ 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 callback
|
|
23
|
+
*/
|
|
24
|
+
export interface RefreshTokenCallback {
|
|
25
|
+
(result: RefreshTokenResult): void;
|
|
26
|
+
}
|
|
15
27
|
/**
|
|
16
28
|
* Core application interface
|
|
17
29
|
*/
|
|
@@ -171,8 +183,23 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
171
183
|
pageExit(): void;
|
|
172
184
|
/**
|
|
173
185
|
* Refresh token
|
|
186
|
+
* @param callback Callback
|
|
187
|
+
*/
|
|
188
|
+
refreshToken(callback?: RefreshTokenCallback): Promise<boolean>;
|
|
189
|
+
/**
|
|
190
|
+
* Signout
|
|
191
|
+
* @param apiUrl Signout API URL
|
|
192
|
+
*/
|
|
193
|
+
signout(apiUrl?: string): Promise<void>;
|
|
194
|
+
/**
|
|
195
|
+
* Switch organization
|
|
196
|
+
* @param apiOrOrg API URL or organization id
|
|
174
197
|
*/
|
|
175
|
-
|
|
198
|
+
switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
|
|
199
|
+
/**
|
|
200
|
+
* Go to the login page
|
|
201
|
+
*/
|
|
202
|
+
toLoginPage(): void;
|
|
176
203
|
/**
|
|
177
204
|
* Transform URL
|
|
178
205
|
* @param url URL
|
|
@@ -406,12 +433,27 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
406
433
|
abstract freshCountdownUI(callback?: () => PromiseLike<unknown>): void;
|
|
407
434
|
/**
|
|
408
435
|
* Refresh token
|
|
436
|
+
* @param callback Callback
|
|
409
437
|
*/
|
|
410
|
-
refreshToken(): Promise<boolean>;
|
|
438
|
+
refreshToken(callback?: RefreshTokenCallback): Promise<boolean>;
|
|
411
439
|
/**
|
|
412
440
|
* Setup callback
|
|
413
441
|
*/
|
|
414
442
|
setup(): void;
|
|
443
|
+
/**
|
|
444
|
+
* Signout
|
|
445
|
+
* @param apiUrl Signout API URL
|
|
446
|
+
*/
|
|
447
|
+
signout(apiUrl?: string): Promise<void>;
|
|
448
|
+
/**
|
|
449
|
+
* Switch organization
|
|
450
|
+
* @param apiOrOrg API URL or organization id
|
|
451
|
+
*/
|
|
452
|
+
switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
|
|
453
|
+
/**
|
|
454
|
+
* Go to the login page
|
|
455
|
+
*/
|
|
456
|
+
toLoginPage(): void;
|
|
415
457
|
/**
|
|
416
458
|
* Transform URL
|
|
417
459
|
* @param url URL
|
|
@@ -420,6 +462,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
420
462
|
transformUrl(url: string): string;
|
|
421
463
|
/**
|
|
422
464
|
* Try login, returning false means is loading
|
|
465
|
+
* UI get involved while refreshToken not intended
|
|
423
466
|
*/
|
|
424
467
|
tryLogin(): Promise<boolean>;
|
|
425
468
|
/**
|
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(callback) {
|
|
402
|
+
if (callback)
|
|
403
|
+
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.54",
|
|
4
4
|
"description": "Applications shared TypeScript framework",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"homepage": "https://github.com/ETSOO/AppScript#readme",
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@etsoo/notificationbase": "^1.0.
|
|
55
|
+
"@etsoo/notificationbase": "^1.0.94",
|
|
56
56
|
"@etsoo/restclient": "^1.0.62",
|
|
57
57
|
"@etsoo/shared": "^1.0.75"
|
|
58
58
|
},
|
|
@@ -65,10 +65,10 @@
|
|
|
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
|
-
"jest": "^27.4.
|
|
71
|
+
"jest": "^27.4.3",
|
|
72
72
|
"ts-jest": "^27.0.7",
|
|
73
73
|
"typescript": "^4.5.2"
|
|
74
74
|
}
|
package/src/app/CoreApp.ts
CHANGED
|
@@ -29,6 +29,24 @@ 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 callback
|
|
45
|
+
*/
|
|
46
|
+
export interface RefreshTokenCallback {
|
|
47
|
+
(result: RefreshTokenResult): void;
|
|
48
|
+
}
|
|
49
|
+
|
|
32
50
|
/**
|
|
33
51
|
* Core application interface
|
|
34
52
|
*/
|
|
@@ -231,8 +249,26 @@ export interface ICoreApp<
|
|
|
231
249
|
|
|
232
250
|
/**
|
|
233
251
|
* Refresh token
|
|
252
|
+
* @param callback Callback
|
|
253
|
+
*/
|
|
254
|
+
refreshToken(callback?: RefreshTokenCallback): Promise<boolean>;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Signout
|
|
258
|
+
* @param apiUrl Signout API URL
|
|
259
|
+
*/
|
|
260
|
+
signout(apiUrl?: string): Promise<void>;
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Switch organization
|
|
264
|
+
* @param apiOrOrg API URL or organization id
|
|
265
|
+
*/
|
|
266
|
+
switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Go to the login page
|
|
234
270
|
*/
|
|
235
|
-
|
|
271
|
+
toLoginPage(): void;
|
|
236
272
|
|
|
237
273
|
/**
|
|
238
274
|
* Transform URL
|
|
@@ -806,8 +842,10 @@ export abstract class CoreApp<
|
|
|
806
842
|
|
|
807
843
|
/**
|
|
808
844
|
* Refresh token
|
|
845
|
+
* @param callback Callback
|
|
809
846
|
*/
|
|
810
|
-
async refreshToken()
|
|
847
|
+
async refreshToken(callback?: RefreshTokenCallback) {
|
|
848
|
+
if (callback) callback(true);
|
|
811
849
|
return true;
|
|
812
850
|
}
|
|
813
851
|
|
|
@@ -816,6 +854,47 @@ export abstract class CoreApp<
|
|
|
816
854
|
*/
|
|
817
855
|
setup() {}
|
|
818
856
|
|
|
857
|
+
/**
|
|
858
|
+
* Signout
|
|
859
|
+
* @param apiUrl Signout API URL
|
|
860
|
+
*/
|
|
861
|
+
async signout(apiUrl?: string) {
|
|
862
|
+
await this.api.put<boolean>(apiUrl ?? 'User/Signout', undefined, {
|
|
863
|
+
onError: (error) => {
|
|
864
|
+
console.log(error);
|
|
865
|
+
// Prevent further processing
|
|
866
|
+
return false;
|
|
867
|
+
}
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
// Clear
|
|
871
|
+
this.userLogout();
|
|
872
|
+
|
|
873
|
+
// Go to login page
|
|
874
|
+
this.toLoginPage();
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* Switch organization
|
|
879
|
+
* @param apiOrOrg API URL or organization id
|
|
880
|
+
*/
|
|
881
|
+
async switchOrg(apiOrOrg: string | number) {
|
|
882
|
+
const api =
|
|
883
|
+
typeof apiOrOrg === 'number'
|
|
884
|
+
? `Organization/Switch/${apiOrOrg}`
|
|
885
|
+
: apiOrOrg;
|
|
886
|
+
const result = await this.api.put<boolean>(api);
|
|
887
|
+
if (result) return await this.refreshToken();
|
|
888
|
+
return result;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/**
|
|
892
|
+
* Go to the login page
|
|
893
|
+
*/
|
|
894
|
+
toLoginPage() {
|
|
895
|
+
window.location.replace(this.transformUrl('/'));
|
|
896
|
+
}
|
|
897
|
+
|
|
819
898
|
/**
|
|
820
899
|
* Transform URL
|
|
821
900
|
* @param url URL
|
|
@@ -843,6 +922,7 @@ export abstract class CoreApp<
|
|
|
843
922
|
|
|
844
923
|
/**
|
|
845
924
|
* Try login, returning false means is loading
|
|
925
|
+
* UI get involved while refreshToken not intended
|
|
846
926
|
*/
|
|
847
927
|
async tryLogin() {
|
|
848
928
|
if (this._isTryingLogin) return false;
|