@placeos/ts-client 4.7.4 → 4.7.6

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.4",
2
+ "version": "4.7.6",
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';
@@ -259,7 +259,7 @@ export function checkStoreForAuthParam(
259
259
  }
260
260
 
261
261
  /** Initialise authentication for the http and realtime APIs */
262
- export function setup(options: PlaceAuthOptions): Promise<void> {
262
+ export async function setup(options: PlaceAuthOptions): Promise<void> {
263
263
  _options = options || _options;
264
264
  _options.token_header = _options.token_header ?? isNestedFrame();
265
265
  if (!window.AbortController) {
@@ -268,9 +268,16 @@ export function setup(options: PlaceAuthOptions): Promise<void> {
268
268
  // Intialise storage
269
269
  _storage = _options.storage === 'session' ? sessionStorage : localStorage;
270
270
  _client_id = Md5.hashStr(_options.redirect_uri, false);
271
+ if (_options.delay && _options.delay > 0) {
272
+ await lastValueFrom(timer(_options.delay!));
273
+ }
271
274
  return loadAuthority();
272
275
  }
273
276
 
277
+ export function setStorage(type: 'session' | 'local'): void {
278
+ _storage = type === 'session' ? sessionStorage : localStorage;
279
+ }
280
+
274
281
  /**
275
282
  * @private
276
283
  */
@@ -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 {
package/src/auth.ts CHANGED
@@ -23,6 +23,7 @@ export {
23
23
  refreshAuthority,
24
24
  refreshToken,
25
25
  setAPI_Key,
26
+ setStorage,
26
27
  setToken,
27
28
  setup,
28
29
  token,