@etsoo/appscript 1.5.20 → 1.5.22

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
@@ -88,7 +89,8 @@ export const appFields = [
88
89
  'serversideDeviceId',
89
90
  'deviceId',
90
91
  'devices',
91
- 'devicePassphrase'
92
+ 'devicePassphrase',
93
+ 'cachedUrl'
92
94
  ] as const;
93
95
 
94
96
  /**
@@ -180,6 +182,11 @@ export interface IApp {
180
182
  */
181
183
  readonly debug: boolean;
182
184
 
185
+ /**
186
+ * Cached URL
187
+ */
188
+ cachedUrl: string | undefined | null;
189
+
183
190
  /**
184
191
  * IP data
185
192
  */
@@ -212,6 +219,13 @@ export interface IApp {
212
219
  */
213
220
  addRootUrl(url: string): string;
214
221
 
222
+ /**
223
+ * Add scheduled task
224
+ * @param task Task, return false to stop
225
+ * @param interval Interval in milliseconds
226
+ */
227
+ addTask(task: () => PromiseLike<void | false>, interval: number): void;
228
+
215
229
  /**
216
230
  * Alert result
217
231
  * @param result Result message
@@ -282,6 +296,21 @@ export interface IApp {
282
296
  */
283
297
  clearDeviceId(): void;
284
298
 
299
+ /**
300
+ * Create API client, override to implement custom client creation by name
301
+ * @param name Client name
302
+ * @param item External endpoint item
303
+ * @returns Result
304
+ */
305
+ createApi(
306
+ name: string,
307
+ item: ExternalEndpoint,
308
+ refresh?: (
309
+ api: IApi,
310
+ token: string
311
+ ) => Promise<[string, number] | undefined>
312
+ ): IApi;
313
+
285
314
  /**
286
315
  * Decrypt message
287
316
  * @param messageEncrypted Encrypted message
@@ -343,6 +372,20 @@ export interface IApp {
343
372
  iterations?: number
344
373
  ): string;
345
374
 
375
+ /**
376
+ * Exchange token data
377
+ * @param api API
378
+ * @param token Core system's refresh token to exchange
379
+ * @returns Result
380
+ */
381
+ exchangeToken(api: IApi, token: string): Promise<void>;
382
+
383
+ /**
384
+ * Exchange intergration tokens for all APIs
385
+ * @param token Core system's refresh token to exchange
386
+ */
387
+ exchangeTokenAll(token: string): void;
388
+
346
389
  /**
347
390
  * Format date to string
348
391
  * @param input Input date
@@ -692,6 +735,14 @@ export interface IApp {
692
735
  */
693
736
  tryLogin(showLoading?: boolean): Promise<boolean>;
694
737
 
738
+ /**
739
+ * Update API token and expires
740
+ * @param name Api name
741
+ * @param token Refresh token
742
+ * @param seconds Access token expires in seconds
743
+ */
744
+ updateApi(name: string, token: string | undefined, seconds: number): void;
745
+
695
746
  /**
696
747
  * User login
697
748
  * @param user User data
@@ -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
+ };