@etsoo/appscript 1.6.7 → 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
+ });
@@ -58,11 +58,12 @@ export declare class AuthApi extends BaseApi {
58
58
  exchangeToken(rq: TokenInputRQ, payload?: IApiPayload<ApiRefreshTokenDto>): Promise<ApiRefreshTokenDto | undefined>;
59
59
  /**
60
60
  * Get log in url
61
+ * @param deviceId Device ID
61
62
  * @param payload Payload
62
63
  * @param apiHost API host
63
64
  * @returns Result
64
65
  */
65
- getLogInUrl(payload?: IApiPayload<string>, apiHost?: string): Promise<string | undefined>;
66
+ getLogInUrl(deviceId?: string, payload?: IApiPayload<string>, apiHost?: string): Promise<string | undefined>;
66
67
  /**
67
68
  * Login
68
69
  * @param rq Request data
@@ -69,14 +69,15 @@ class AuthApi extends BaseApi_1.BaseApi {
69
69
  }
70
70
  /**
71
71
  * Get log in url
72
+ * @param deviceId Device ID
72
73
  * @param payload Payload
73
74
  * @param apiHost API host
74
75
  * @returns Result
75
76
  */
76
- getLogInUrl(payload, apiHost) {
77
+ getLogInUrl(deviceId, payload, apiHost) {
77
78
  const rq = {
78
79
  region: this.app.region,
79
- device: this.app.deviceId
80
+ device: deviceId ?? this.app.deviceId
80
81
  };
81
82
  return this.api.get(`${apiHost ?? ""}Auth/GetLogInUrl`, rq, payload);
82
83
  }
@@ -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
  */
@@ -58,11 +58,12 @@ export declare class AuthApi extends BaseApi {
58
58
  exchangeToken(rq: TokenInputRQ, payload?: IApiPayload<ApiRefreshTokenDto>): Promise<ApiRefreshTokenDto | undefined>;
59
59
  /**
60
60
  * Get log in url
61
+ * @param deviceId Device ID
61
62
  * @param payload Payload
62
63
  * @param apiHost API host
63
64
  * @returns Result
64
65
  */
65
- getLogInUrl(payload?: IApiPayload<string>, apiHost?: string): Promise<string | undefined>;
66
+ getLogInUrl(deviceId?: string, payload?: IApiPayload<string>, apiHost?: string): Promise<string | undefined>;
66
67
  /**
67
68
  * Login
68
69
  * @param rq Request data
@@ -66,14 +66,15 @@ export class AuthApi extends BaseApi {
66
66
  }
67
67
  /**
68
68
  * Get log in url
69
+ * @param deviceId Device ID
69
70
  * @param payload Payload
70
71
  * @param apiHost API host
71
72
  * @returns Result
72
73
  */
73
- getLogInUrl(payload, apiHost) {
74
+ getLogInUrl(deviceId, payload, apiHost) {
74
75
  const rq = {
75
76
  region: this.app.region,
76
- device: this.app.deviceId
77
+ device: deviceId ?? this.app.deviceId
77
78
  };
78
79
  return this.api.get(`${apiHost ?? ""}Auth/GetLogInUrl`, rq, payload);
79
80
  }
@@ -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.7",
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
  }
@@ -101,14 +101,19 @@ export class AuthApi extends BaseApi {
101
101
 
102
102
  /**
103
103
  * Get log in url
104
+ * @param deviceId Device ID
104
105
  * @param payload Payload
105
106
  * @param apiHost API host
106
107
  * @returns Result
107
108
  */
108
- getLogInUrl(payload?: IApiPayload<string>, apiHost?: string) {
109
+ getLogInUrl(
110
+ deviceId?: string,
111
+ payload?: IApiPayload<string>,
112
+ apiHost?: string
113
+ ) {
109
114
  const rq: GetLogInUrlRQ = {
110
115
  region: this.app.region,
111
- device: this.app.deviceId
116
+ device: deviceId ?? this.app.deviceId
112
117
  };
113
118
  return this.api.get(`${apiHost ?? ""}Auth/GetLogInUrl`, rq, payload);
114
119
  }
@@ -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
  */