@ethlete/query 0.1.0-next.14 → 0.1.0-next.16
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/esm2020/lib/auth/auth-provider.types.mjs +1 -1
- package/esm2020/lib/auth/bearer-auth-provider.mjs +36 -5
- package/esm2020/lib/directives/infinity-query-trigger.directive.mjs +3 -3
- package/esm2020/lib/directives/infinity-query.directive.mjs +3 -3
- package/esm2020/lib/directives/query.directive.mjs +3 -3
- package/esm2020/lib/query/query.mjs +5 -1
- package/esm2020/lib/query-client/query-client.mjs +10 -7
- package/fesm2015/ethlete-query.mjs +60 -22
- package/fesm2015/ethlete-query.mjs.map +1 -1
- package/fesm2020/ethlete-query.mjs +57 -20
- package/fesm2020/ethlete-query.mjs.map +1 -1
- package/lib/auth/auth-provider.types.d.ts +10 -6
- package/lib/auth/auth-provider.utils.d.ts +1 -1
- package/lib/auth/bearer-auth-provider.d.ts +6 -3
- package/lib/query-client/query-client.d.ts +2 -1
- package/package.json +4 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { getCookie, deleteCookie, setCookie, DestroyService } from '@ethlete/core';
|
|
1
2
|
import { Subject, timer, filter, takeWhile, switchMap, of, BehaviorSubject, interval, takeUntil, tap, fromEvent, startWith, concat, take, debounceTime, combineLatest, map, distinctUntilChanged } from 'rxjs';
|
|
2
3
|
import * as i0 from '@angular/core';
|
|
3
4
|
import { Directive, Input, InjectionToken, inject, ChangeDetectorRef, ViewContainerRef, TemplateRef, ErrorHandler, ElementRef } from '@angular/core';
|
|
4
|
-
import { DestroyService } from '@ethlete/core';
|
|
5
5
|
import { FormGroup } from '@angular/forms';
|
|
6
6
|
import { Router, ActivatedRoute } from '@angular/router';
|
|
7
7
|
|
|
@@ -318,6 +318,7 @@ class BearerAuthProvider {
|
|
|
318
318
|
}
|
|
319
319
|
constructor(_config) {
|
|
320
320
|
this._config = _config;
|
|
321
|
+
this._token = null;
|
|
321
322
|
this._refreshToken = null;
|
|
322
323
|
this._refreshTimerSubscription = null;
|
|
323
324
|
this._failureCount = 0;
|
|
@@ -325,18 +326,41 @@ class BearerAuthProvider {
|
|
|
325
326
|
this.onRefreshInitiation$ = new Subject();
|
|
326
327
|
this.onRefreshSuccess$ = new Subject();
|
|
327
328
|
this.onRefreshFailure$ = new Subject();
|
|
328
|
-
this._token = _config.token;
|
|
329
|
+
this._token = _config.token || null;
|
|
329
330
|
this._refreshToken = _config.refreshConfig?.token ?? null;
|
|
330
|
-
if (this._config.refreshConfig) {
|
|
331
|
+
if (this._config.refreshConfig && this._token) {
|
|
331
332
|
this._setupRefresh(this._config.refreshConfig);
|
|
332
333
|
}
|
|
334
|
+
else if (this._config.refreshConfig?.cookieName) {
|
|
335
|
+
const cookie = getCookie(this._config.refreshConfig.cookieName);
|
|
336
|
+
if (!cookie) {
|
|
337
|
+
this._autoDestruct();
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
this._refreshToken = cookie;
|
|
341
|
+
this._refresh(this._config.refreshConfig);
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
this._autoDestruct();
|
|
345
|
+
console.error('A BearerAuthProvider was created without token or refresh token. You should provide at least a cookieName where the refresh token might be stored.');
|
|
346
|
+
}
|
|
333
347
|
}
|
|
334
|
-
cleanUp() {
|
|
348
|
+
cleanUp(config) {
|
|
335
349
|
this._refreshTimerSubscription?.unsubscribe();
|
|
336
350
|
this._refreshTimerSubscription = null;
|
|
351
|
+
if (this._config.refreshConfig?.cookieName && !config?.keepCookie) {
|
|
352
|
+
deleteCookie(this._config.refreshConfig.cookieName, '/');
|
|
353
|
+
}
|
|
337
354
|
}
|
|
338
|
-
|
|
355
|
+
_autoDestruct() {
|
|
339
356
|
this.cleanUp();
|
|
357
|
+
this.queryClient?.clearAuthProvider();
|
|
358
|
+
}
|
|
359
|
+
_setupRefresh(config) {
|
|
360
|
+
this.cleanUp({ keepCookie: true });
|
|
361
|
+
if (!this._token) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
340
364
|
const bearer = decryptBearer(this._token);
|
|
341
365
|
if (!bearer) {
|
|
342
366
|
return;
|
|
@@ -387,6 +411,9 @@ class BearerAuthProvider {
|
|
|
387
411
|
this._token = tokens.token;
|
|
388
412
|
this._refreshToken = tokens.refreshToken;
|
|
389
413
|
this.onRefreshSuccess$.next(tokens);
|
|
414
|
+
if (config.cookieName) {
|
|
415
|
+
setCookie(config.cookieName, tokens.refreshToken);
|
|
416
|
+
}
|
|
390
417
|
this._setupRefresh(config);
|
|
391
418
|
this._failureCount = 0;
|
|
392
419
|
}
|
|
@@ -401,6 +428,9 @@ class BearerAuthProvider {
|
|
|
401
428
|
if (this._failureCount <= (config.maxRefreshAttempts ?? 3)) {
|
|
402
429
|
this._setupRefresh(config);
|
|
403
430
|
}
|
|
431
|
+
else {
|
|
432
|
+
this._autoDestruct();
|
|
433
|
+
}
|
|
404
434
|
}
|
|
405
435
|
}
|
|
406
436
|
}
|
|
@@ -586,6 +616,10 @@ class Query {
|
|
|
586
616
|
};
|
|
587
617
|
}
|
|
588
618
|
}
|
|
619
|
+
// For form data we need to remove content type header because browser will set it automatically including boundary
|
|
620
|
+
if (headers && 'Content-Type' in headers && headers['Content-Type'] === 'multipart/form-data') {
|
|
621
|
+
delete headers['Content-Type'];
|
|
622
|
+
}
|
|
589
623
|
request({
|
|
590
624
|
route: this._route,
|
|
591
625
|
init: {
|
|
@@ -765,9 +799,9 @@ class QueryDirective {
|
|
|
765
799
|
}
|
|
766
800
|
}
|
|
767
801
|
}
|
|
768
|
-
QueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.
|
|
769
|
-
QueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.1.
|
|
770
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.
|
|
802
|
+
QueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.2", ngImport: i0, type: QueryDirective, deps: [{ token: i0.TemplateRef }, { token: i0.ViewContainerRef }, { token: i0.ErrorHandler }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
803
|
+
QueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.1.2", type: QueryDirective, isStandalone: true, selector: "[query]", inputs: { query: "query", cache: ["queryCache", "cache"] }, ngImport: i0 });
|
|
804
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.2", ngImport: i0, type: QueryDirective, decorators: [{
|
|
771
805
|
type: Directive,
|
|
772
806
|
args: [{
|
|
773
807
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -1076,9 +1110,9 @@ class InfinityQueryDirective {
|
|
|
1076
1110
|
this._data$.next([]);
|
|
1077
1111
|
}
|
|
1078
1112
|
}
|
|
1079
|
-
InfinityQueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.
|
|
1080
|
-
InfinityQueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.1.
|
|
1081
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.
|
|
1113
|
+
InfinityQueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.2", ngImport: i0, type: InfinityQueryDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1114
|
+
InfinityQueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.1.2", type: InfinityQueryDirective, isStandalone: true, selector: "[infinityQuery]", inputs: { infinityQuery: "infinityQuery" }, providers: [{ provide: INFINITY_QUERY_TOKEN, useExisting: InfinityQueryDirective }, DestroyService], exportAs: ["infinityQuery"], ngImport: i0 });
|
|
1115
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.2", ngImport: i0, type: InfinityQueryDirective, decorators: [{
|
|
1082
1116
|
type: Directive,
|
|
1083
1117
|
args: [{
|
|
1084
1118
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -1128,9 +1162,9 @@ class InfinityQueryTriggerDirective {
|
|
|
1128
1162
|
this._observer.observe(this._elementRef.nativeElement);
|
|
1129
1163
|
}
|
|
1130
1164
|
}
|
|
1131
|
-
InfinityQueryTriggerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.
|
|
1132
|
-
InfinityQueryTriggerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.1.
|
|
1133
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.
|
|
1165
|
+
InfinityQueryTriggerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.2", ngImport: i0, type: InfinityQueryTriggerDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1166
|
+
InfinityQueryTriggerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.1.2", type: InfinityQueryTriggerDirective, isStandalone: true, selector: "[infinityQueryTrigger], infinity-query-trigger", inputs: { scrollContainerSelector: "scrollContainerSelector" }, ngImport: i0 });
|
|
1167
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.2", ngImport: i0, type: InfinityQueryTriggerDirective, decorators: [{
|
|
1134
1168
|
type: Directive,
|
|
1135
1169
|
args: [{
|
|
1136
1170
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -1226,11 +1260,14 @@ class QueryClient {
|
|
|
1226
1260
|
return this._clientConfig;
|
|
1227
1261
|
}
|
|
1228
1262
|
get authProvider() {
|
|
1229
|
-
return this._authProvider;
|
|
1263
|
+
return this._authProvider$.getValue();
|
|
1264
|
+
}
|
|
1265
|
+
get authProvider$() {
|
|
1266
|
+
return this._authProvider$.asObservable();
|
|
1230
1267
|
}
|
|
1231
1268
|
constructor(_clientConfig) {
|
|
1232
1269
|
this._clientConfig = _clientConfig;
|
|
1233
|
-
this._authProvider = null;
|
|
1270
|
+
this._authProvider$ = new BehaviorSubject(null);
|
|
1234
1271
|
this.get = (queryConfig) => this.fetch({
|
|
1235
1272
|
...queryConfig,
|
|
1236
1273
|
method: 'GET',
|
|
@@ -1287,15 +1324,15 @@ class QueryClient {
|
|
|
1287
1324
|
};
|
|
1288
1325
|
};
|
|
1289
1326
|
this.setAuthProvider = (authProvider) => {
|
|
1290
|
-
if (this.
|
|
1327
|
+
if (this.authProvider) {
|
|
1291
1328
|
throw new Error('The auth provider is already set. Please call clearAuthProvider() first.');
|
|
1292
1329
|
}
|
|
1293
|
-
this._authProvider
|
|
1330
|
+
this._authProvider$.next(authProvider);
|
|
1294
1331
|
authProvider.queryClient = this;
|
|
1295
1332
|
};
|
|
1296
1333
|
this.clearAuthProvider = () => {
|
|
1297
|
-
this.
|
|
1298
|
-
this._authProvider
|
|
1334
|
+
this.authProvider?.cleanUp();
|
|
1335
|
+
this._authProvider$.next(null);
|
|
1299
1336
|
};
|
|
1300
1337
|
this._store = new QueryStore({
|
|
1301
1338
|
enableChangeLogging: _clientConfig.logging?.queryStateChanges,
|