@etsoo/appscript 1.5.19 → 1.5.21

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/src/app/IApp.ts CHANGED
@@ -22,6 +22,7 @@ import { IAppSettings } from './AppSettings';
22
22
  import { UserRole } from './UserRole';
23
23
  import { EntityStatus } from '../business/EntityStatus';
24
24
  import { Currency } from '../business/Currency';
25
+ import { ExternalEndpoint } from './ExternalSettings';
25
26
 
26
27
  /**
27
28
  * Detect IP callback interface
@@ -212,6 +213,13 @@ export interface IApp {
212
213
  */
213
214
  addRootUrl(url: string): string;
214
215
 
216
+ /**
217
+ * Add scheduled task
218
+ * @param task Task, return false to stop
219
+ * @param interval Interval in milliseconds
220
+ */
221
+ addTask(task: () => PromiseLike<void | false>, interval: number): void;
222
+
215
223
  /**
216
224
  * Alert result
217
225
  * @param result Result message
@@ -282,6 +290,21 @@ export interface IApp {
282
290
  */
283
291
  clearDeviceId(): void;
284
292
 
293
+ /**
294
+ * Create API client, override to implement custom client creation by name
295
+ * @param name Client name
296
+ * @param item External endpoint item
297
+ * @returns Result
298
+ */
299
+ createApi(
300
+ name: string,
301
+ item: ExternalEndpoint,
302
+ refresh?: (
303
+ api: IApi,
304
+ token: string
305
+ ) => Promise<[string, number] | undefined>
306
+ ): IApi;
307
+
285
308
  /**
286
309
  * Decrypt message
287
310
  * @param messageEncrypted Encrypted message
@@ -343,6 +366,20 @@ export interface IApp {
343
366
  iterations?: number
344
367
  ): string;
345
368
 
369
+ /**
370
+ * Exchange token data
371
+ * @param api API
372
+ * @param token Core system's refresh token to exchange
373
+ * @returns Result
374
+ */
375
+ exchangeToken(api: IApi, token: string): Promise<void>;
376
+
377
+ /**
378
+ * Exchange intergration tokens for all APIs
379
+ * @param token Core system's refresh token to exchange
380
+ */
381
+ exchangeTokenAll(token: string): void;
382
+
346
383
  /**
347
384
  * Format date to string
348
385
  * @param input Input date
@@ -688,9 +725,17 @@ export interface IApp {
688
725
  /**
689
726
  * Try login, returning false means is loading
690
727
  * UI get involved while refreshToken not intended
691
- * @param data Additional request data
728
+ * @param showLoading Show loading bar or not
729
+ */
730
+ tryLogin(showLoading?: boolean): Promise<boolean>;
731
+
732
+ /**
733
+ * Update API token and expires
734
+ * @param name Api name
735
+ * @param token Refresh token
736
+ * @param seconds Access token expires in seconds
692
737
  */
693
- tryLogin<D extends object = {}>(data?: D): Promise<boolean>;
738
+ updateApi(name: string, token: string | undefined, seconds: number): void;
694
739
 
695
740
  /**
696
741
  * User login
@@ -65,7 +65,7 @@ export class AuthApi extends BaseApi {
65
65
  async redirectToLogInUrl() {
66
66
  const url = await this.getLogInUrl();
67
67
  if (url == null) return;
68
- window.location.replace(url);
68
+ globalThis.location.replace(url);
69
69
  }
70
70
 
71
71
  /**
@@ -0,0 +1,24 @@
1
+ /**
2
+ * API refresh token data
3
+ */
4
+ export type ApiRefreshTokenDto = {
5
+ /**
6
+ * Refresh token
7
+ */
8
+ readonly refreshToken: string;
9
+
10
+ /**
11
+ * Access token
12
+ */
13
+ readonly accessToken: string;
14
+
15
+ /**
16
+ * Token type
17
+ */
18
+ readonly tokenType: string;
19
+
20
+ /**
21
+ * Expires in
22
+ */
23
+ readonly expiresIn: number;
24
+ };