@placeos/ts-client 4.7.5 → 4.7.7

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.7.5",
2
+ "version": "4.7.7",
3
3
  "license": "MIT",
4
4
  "name": "@placeos/ts-client",
5
5
  "author": "Alex Sorafumo <alex@place.tech>",
@@ -1,6 +1,6 @@
1
1
  import * as base64 from 'byte-base64';
2
2
  import * as sha256 from 'fast-sha256';
3
- import { BehaviorSubject, Observable } from 'rxjs';
3
+ import { BehaviorSubject, Observable, lastValueFrom, timer } from 'rxjs';
4
4
  import { fromFetch } from 'rxjs/fetch';
5
5
  import { map } from 'rxjs/operators';
6
6
  import { Md5 } from 'ts-md5';
@@ -159,10 +159,12 @@ export function token(return_expired: boolean = true): string {
159
159
  _failed_count += 1;
160
160
  timeout(
161
161
  're-authorise',
162
- () =>
163
- authorise().catch((e) =>
162
+ async () => {
163
+ delete _promises.authorise;
164
+ await authorise().catch((e) =>
164
165
  log('Auth', `Failed to get token: ${e}`),
165
- ),
166
+ );
167
+ },
166
168
  200 * Math.min(20, _failed_count),
167
169
  );
168
170
  }
@@ -259,7 +261,7 @@ export function checkStoreForAuthParam(
259
261
  }
260
262
 
261
263
  /** Initialise authentication for the http and realtime APIs */
262
- export function setup(options: PlaceAuthOptions): Promise<void> {
264
+ export async function setup(options: PlaceAuthOptions): Promise<void> {
263
265
  _options = options || _options;
264
266
  _options.token_header = _options.token_header ?? isNestedFrame();
265
267
  if (!window.AbortController) {
@@ -268,6 +270,9 @@ export function setup(options: PlaceAuthOptions): Promise<void> {
268
270
  // Intialise storage
269
271
  _storage = _options.storage === 'session' ? sessionStorage : localStorage;
270
272
  _client_id = Md5.hashStr(_options.redirect_uri, false);
273
+ if (_options.delay && _options.delay > 0) {
274
+ await lastValueFrom(timer(_options.delay!));
275
+ }
271
276
  return loadAuthority();
272
277
  }
273
278
 
@@ -85,6 +85,8 @@ export interface PlaceAuthOptions {
85
85
  version?: 'ACA Engine' | 'PlaceOS';
86
86
  /** Whether X-API-KEY values should be ignored */
87
87
  ignore_api_key?: boolean;
88
+ /** Delay authentication by X milliseconds */
89
+ delay?: number;
88
90
  }
89
91
 
90
92
  export interface PlaceTokenResponse {