@etsoo/appscript 1.6.8 → 1.6.10
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/README.md +0 -2
- package/__tests__/app/CoreApp.ts +12 -0
- package/lib/cjs/app/CoreApp.d.ts +10 -0
- package/lib/cjs/app/CoreApp.js +26 -3
- package/lib/cjs/app/IApp.d.ts +10 -0
- package/lib/mjs/app/CoreApp.d.ts +10 -0
- package/lib/mjs/app/CoreApp.js +26 -3
- package/lib/mjs/app/IApp.d.ts +10 -0
- package/package.json +2 -2
- package/src/app/CoreApp.ts +30 -2
- package/src/app/IApp.ts +14 -0
package/README.md
CHANGED
package/__tests__/app/CoreApp.ts
CHANGED
|
@@ -260,3 +260,15 @@ test("Tests for isValidPassword", () => {
|
|
|
260
260
|
expect(app.isValidPassword("abcd3")).toBeFalsy();
|
|
261
261
|
expect(app.isValidPassword("1234abcd")).toBeTruthy();
|
|
262
262
|
});
|
|
263
|
+
|
|
264
|
+
test("Tests for checkSesession", async () => {
|
|
265
|
+
await app.checkSession((isSame) => {
|
|
266
|
+
expect(isSame).toBeFalsy();
|
|
267
|
+
return Promise.resolve();
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
await app.checkSession((isSame) => {
|
|
271
|
+
expect(isSame).toBeTruthy();
|
|
272
|
+
return Promise.resolve();
|
|
273
|
+
});
|
|
274
|
+
});
|
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -200,6 +200,11 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
200
200
|
* @returns Result
|
|
201
201
|
*/
|
|
202
202
|
addRootUrl(url: string): string;
|
|
203
|
+
/**
|
|
204
|
+
* Check current app is in same session
|
|
205
|
+
* @param callback Callback
|
|
206
|
+
*/
|
|
207
|
+
checkSession(callback: (isSame: boolean) => Promise<void | false>): Promise<void>;
|
|
203
208
|
/**
|
|
204
209
|
* Create Auth API
|
|
205
210
|
* @param api Specify the API to use
|
|
@@ -671,6 +676,11 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
671
676
|
* @returns Result
|
|
672
677
|
*/
|
|
673
678
|
protected apiRefreshToken(api: IApi, rq: ApiRefreshTokenRQ): Promise<[string, number] | undefined>;
|
|
679
|
+
/**
|
|
680
|
+
* Save refresh token to cache
|
|
681
|
+
* @param token Refresh token
|
|
682
|
+
*/
|
|
683
|
+
saveCacheToken(token: string | undefined): void;
|
|
674
684
|
/**
|
|
675
685
|
* Setup tasks
|
|
676
686
|
*/
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -290,6 +290,22 @@ class CoreApp {
|
|
|
290
290
|
? url
|
|
291
291
|
: "/" + url));
|
|
292
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* Check current app is in same session
|
|
295
|
+
* @param callback Callback
|
|
296
|
+
*/
|
|
297
|
+
async checkSession(callback) {
|
|
298
|
+
// Session name
|
|
299
|
+
const sessionName = this.addIdentifier("same-session");
|
|
300
|
+
// Current session
|
|
301
|
+
const isSame = this.storage.getData(sessionName) === true;
|
|
302
|
+
// Callback
|
|
303
|
+
const result = await callback(isSame);
|
|
304
|
+
if (!isSame && result !== false) {
|
|
305
|
+
// Set the session when the callback does not return false
|
|
306
|
+
this.storage.setData(sessionName, true);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
293
309
|
/**
|
|
294
310
|
* Create Auth API
|
|
295
311
|
* @param api Specify the API to use
|
|
@@ -722,9 +738,7 @@ class CoreApp {
|
|
|
722
738
|
this.api.authorize(schema, token);
|
|
723
739
|
// Overwrite the current value
|
|
724
740
|
if (refreshToken !== "") {
|
|
725
|
-
|
|
726
|
-
refreshToken = this.encrypt(refreshToken);
|
|
727
|
-
this.storage.setData(this.fields.headerToken, refreshToken);
|
|
741
|
+
this.saveCacheToken(refreshToken);
|
|
728
742
|
}
|
|
729
743
|
// Reset tryLogin state
|
|
730
744
|
this._isTryingLogin = false;
|
|
@@ -1641,6 +1655,15 @@ class CoreApp {
|
|
|
1641
1655
|
// Return the new refresh token and access token expiration seconds
|
|
1642
1656
|
return [data.refreshToken, data.expiresIn];
|
|
1643
1657
|
}
|
|
1658
|
+
/**
|
|
1659
|
+
* Save refresh token to cache
|
|
1660
|
+
* @param token Refresh token
|
|
1661
|
+
*/
|
|
1662
|
+
saveCacheToken(token) {
|
|
1663
|
+
if (token != null)
|
|
1664
|
+
token = this.encrypt(token);
|
|
1665
|
+
this.storage.setData(this.fields.headerToken, token);
|
|
1666
|
+
}
|
|
1644
1667
|
/**
|
|
1645
1668
|
* Setup tasks
|
|
1646
1669
|
*/
|
package/lib/cjs/app/IApp.d.ts
CHANGED
|
@@ -266,6 +266,11 @@ export interface IApp {
|
|
|
266
266
|
* @returns Result
|
|
267
267
|
*/
|
|
268
268
|
checkLanguage(language?: string): string;
|
|
269
|
+
/**
|
|
270
|
+
* Check current app is in same session
|
|
271
|
+
* @param callback Callback
|
|
272
|
+
*/
|
|
273
|
+
checkSession(callback: (isSame: boolean) => Promise<void | false>): Promise<void>;
|
|
269
274
|
/**
|
|
270
275
|
* Clear cache data
|
|
271
276
|
*/
|
|
@@ -570,6 +575,11 @@ export interface IApp {
|
|
|
570
575
|
* @param callback Callback
|
|
571
576
|
*/
|
|
572
577
|
refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
|
|
578
|
+
/**
|
|
579
|
+
* Save refresh token to cache
|
|
580
|
+
* @param token Refresh token
|
|
581
|
+
*/
|
|
582
|
+
saveCacheToken(token: string | undefined): void;
|
|
573
583
|
/**
|
|
574
584
|
* Setup Api error handler
|
|
575
585
|
* @param api Api
|
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -200,6 +200,11 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
200
200
|
* @returns Result
|
|
201
201
|
*/
|
|
202
202
|
addRootUrl(url: string): string;
|
|
203
|
+
/**
|
|
204
|
+
* Check current app is in same session
|
|
205
|
+
* @param callback Callback
|
|
206
|
+
*/
|
|
207
|
+
checkSession(callback: (isSame: boolean) => Promise<void | false>): Promise<void>;
|
|
203
208
|
/**
|
|
204
209
|
* Create Auth API
|
|
205
210
|
* @param api Specify the API to use
|
|
@@ -671,6 +676,11 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
671
676
|
* @returns Result
|
|
672
677
|
*/
|
|
673
678
|
protected apiRefreshToken(api: IApi, rq: ApiRefreshTokenRQ): Promise<[string, number] | undefined>;
|
|
679
|
+
/**
|
|
680
|
+
* Save refresh token to cache
|
|
681
|
+
* @param token Refresh token
|
|
682
|
+
*/
|
|
683
|
+
saveCacheToken(token: string | undefined): void;
|
|
674
684
|
/**
|
|
675
685
|
* Setup tasks
|
|
676
686
|
*/
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -287,6 +287,22 @@ export class CoreApp {
|
|
|
287
287
|
? url
|
|
288
288
|
: "/" + url));
|
|
289
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* Check current app is in same session
|
|
292
|
+
* @param callback Callback
|
|
293
|
+
*/
|
|
294
|
+
async checkSession(callback) {
|
|
295
|
+
// Session name
|
|
296
|
+
const sessionName = this.addIdentifier("same-session");
|
|
297
|
+
// Current session
|
|
298
|
+
const isSame = this.storage.getData(sessionName) === true;
|
|
299
|
+
// Callback
|
|
300
|
+
const result = await callback(isSame);
|
|
301
|
+
if (!isSame && result !== false) {
|
|
302
|
+
// Set the session when the callback does not return false
|
|
303
|
+
this.storage.setData(sessionName, true);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
290
306
|
/**
|
|
291
307
|
* Create Auth API
|
|
292
308
|
* @param api Specify the API to use
|
|
@@ -719,9 +735,7 @@ export class CoreApp {
|
|
|
719
735
|
this.api.authorize(schema, token);
|
|
720
736
|
// Overwrite the current value
|
|
721
737
|
if (refreshToken !== "") {
|
|
722
|
-
|
|
723
|
-
refreshToken = this.encrypt(refreshToken);
|
|
724
|
-
this.storage.setData(this.fields.headerToken, refreshToken);
|
|
738
|
+
this.saveCacheToken(refreshToken);
|
|
725
739
|
}
|
|
726
740
|
// Reset tryLogin state
|
|
727
741
|
this._isTryingLogin = false;
|
|
@@ -1638,6 +1652,15 @@ export class CoreApp {
|
|
|
1638
1652
|
// Return the new refresh token and access token expiration seconds
|
|
1639
1653
|
return [data.refreshToken, data.expiresIn];
|
|
1640
1654
|
}
|
|
1655
|
+
/**
|
|
1656
|
+
* Save refresh token to cache
|
|
1657
|
+
* @param token Refresh token
|
|
1658
|
+
*/
|
|
1659
|
+
saveCacheToken(token) {
|
|
1660
|
+
if (token != null)
|
|
1661
|
+
token = this.encrypt(token);
|
|
1662
|
+
this.storage.setData(this.fields.headerToken, token);
|
|
1663
|
+
}
|
|
1641
1664
|
/**
|
|
1642
1665
|
* Setup tasks
|
|
1643
1666
|
*/
|
package/lib/mjs/app/IApp.d.ts
CHANGED
|
@@ -266,6 +266,11 @@ export interface IApp {
|
|
|
266
266
|
* @returns Result
|
|
267
267
|
*/
|
|
268
268
|
checkLanguage(language?: string): string;
|
|
269
|
+
/**
|
|
270
|
+
* Check current app is in same session
|
|
271
|
+
* @param callback Callback
|
|
272
|
+
*/
|
|
273
|
+
checkSession(callback: (isSame: boolean) => Promise<void | false>): Promise<void>;
|
|
269
274
|
/**
|
|
270
275
|
* Clear cache data
|
|
271
276
|
*/
|
|
@@ -570,6 +575,11 @@ export interface IApp {
|
|
|
570
575
|
* @param callback Callback
|
|
571
576
|
*/
|
|
572
577
|
refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
|
|
578
|
+
/**
|
|
579
|
+
* Save refresh token to cache
|
|
580
|
+
* @param token Refresh token
|
|
581
|
+
*/
|
|
582
|
+
saveCacheToken(token: string | undefined): void;
|
|
573
583
|
/**
|
|
574
584
|
* Setup Api error handler
|
|
575
585
|
* @param api Api
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/appscript",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.10",
|
|
4
4
|
"description": "Applications shared TypeScript framework",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -50,6 +50,6 @@
|
|
|
50
50
|
"@vitejs/plugin-react": "^4.3.4",
|
|
51
51
|
"jsdom": "^26.0.0",
|
|
52
52
|
"typescript": "^5.7.3",
|
|
53
|
-
"vitest": "^3.0.
|
|
53
|
+
"vitest": "^3.0.6"
|
|
54
54
|
}
|
|
55
55
|
}
|
package/src/app/CoreApp.ts
CHANGED
|
@@ -509,6 +509,26 @@ export abstract class CoreApp<
|
|
|
509
509
|
);
|
|
510
510
|
}
|
|
511
511
|
|
|
512
|
+
/**
|
|
513
|
+
* Check current app is in same session
|
|
514
|
+
* @param callback Callback
|
|
515
|
+
*/
|
|
516
|
+
async checkSession(callback: (isSame: boolean) => Promise<void | false>) {
|
|
517
|
+
// Session name
|
|
518
|
+
const sessionName = this.addIdentifier("same-session");
|
|
519
|
+
|
|
520
|
+
// Current session
|
|
521
|
+
const isSame = this.storage.getData<boolean>(sessionName) === true;
|
|
522
|
+
|
|
523
|
+
// Callback
|
|
524
|
+
const result = await callback(isSame);
|
|
525
|
+
|
|
526
|
+
if (!isSame && result !== false) {
|
|
527
|
+
// Set the session when the callback does not return false
|
|
528
|
+
this.storage.setData(sessionName, true);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
512
532
|
/**
|
|
513
533
|
* Create Auth API
|
|
514
534
|
* @param api Specify the API to use
|
|
@@ -1100,8 +1120,7 @@ export abstract class CoreApp<
|
|
|
1100
1120
|
|
|
1101
1121
|
// Overwrite the current value
|
|
1102
1122
|
if (refreshToken !== "") {
|
|
1103
|
-
|
|
1104
|
-
this.storage.setData(this.fields.headerToken, refreshToken);
|
|
1123
|
+
this.saveCacheToken(refreshToken);
|
|
1105
1124
|
}
|
|
1106
1125
|
|
|
1107
1126
|
// Reset tryLogin state
|
|
@@ -2202,6 +2221,15 @@ export abstract class CoreApp<
|
|
|
2202
2221
|
return [data.refreshToken, data.expiresIn];
|
|
2203
2222
|
}
|
|
2204
2223
|
|
|
2224
|
+
/**
|
|
2225
|
+
* Save refresh token to cache
|
|
2226
|
+
* @param token Refresh token
|
|
2227
|
+
*/
|
|
2228
|
+
saveCacheToken(token: string | undefined) {
|
|
2229
|
+
if (token != null) token = this.encrypt(token);
|
|
2230
|
+
this.storage.setData(this.fields.headerToken, token);
|
|
2231
|
+
}
|
|
2232
|
+
|
|
2205
2233
|
/**
|
|
2206
2234
|
* Setup tasks
|
|
2207
2235
|
*/
|
package/src/app/IApp.ts
CHANGED
|
@@ -347,6 +347,14 @@ export interface IApp {
|
|
|
347
347
|
*/
|
|
348
348
|
checkLanguage(language?: string): string;
|
|
349
349
|
|
|
350
|
+
/**
|
|
351
|
+
* Check current app is in same session
|
|
352
|
+
* @param callback Callback
|
|
353
|
+
*/
|
|
354
|
+
checkSession(
|
|
355
|
+
callback: (isSame: boolean) => Promise<void | false>
|
|
356
|
+
): Promise<void>;
|
|
357
|
+
|
|
350
358
|
/**
|
|
351
359
|
* Clear cache data
|
|
352
360
|
*/
|
|
@@ -757,6 +765,12 @@ export interface IApp {
|
|
|
757
765
|
callback?: (result?: boolean | IActionResult) => boolean | void
|
|
758
766
|
): Promise<void>;
|
|
759
767
|
|
|
768
|
+
/**
|
|
769
|
+
* Save refresh token to cache
|
|
770
|
+
* @param token Refresh token
|
|
771
|
+
*/
|
|
772
|
+
saveCacheToken(token: string | undefined): void;
|
|
773
|
+
|
|
760
774
|
/**
|
|
761
775
|
* Setup Api error handler
|
|
762
776
|
* @param api Api
|