@etsoo/appscript 1.6.8 → 1.6.9

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 CHANGED
@@ -140,8 +140,6 @@ $ yarn add @etsoo/appscript
140
140
  - InitCallResultData - Init call result data
141
141
  - InitCallResult - Init call result
142
142
 
143
- ### erp - SmartERP APIs
144
-
145
143
  ### state - State management
146
144
 
147
145
  #### Culture.ts
@@ -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
+ });
@@ -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
@@ -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
@@ -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
  */
@@ -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
@@ -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
@@ -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
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.6.8",
3
+ "version": "1.6.9",
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.5"
53
+ "vitest": "^3.0.6"
54
54
  }
55
55
  }
@@ -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
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
  */