@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/dist/auth/interfaces.d.ts +2 -0
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +1211 -1190
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/auth/functions.ts +10 -5
- package/src/auth/interfaces.ts +2 -0
package/package.json
CHANGED
package/src/auth/functions.ts
CHANGED
|
@@ -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
|
|
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
|
|
package/src/auth/interfaces.ts
CHANGED
|
@@ -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 {
|