@ethlete/query 2.8.0 → 2.9.0
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 +14 -2
- package/esm2020/lib/query/query.mjs +38 -7
- package/esm2020/lib/query/query.types.mjs +1 -1
- package/fesm2015/ethlete-query.mjs +51 -9
- package/fesm2015/ethlete-query.mjs.map +1 -1
- package/fesm2020/ethlete-query.mjs +48 -6
- package/fesm2020/ethlete-query.mjs.map +1 -1
- package/lib/auth/auth-provider.types.d.ts +5 -0
- package/lib/auth/bearer-auth-provider.d.ts +5 -1
- package/lib/query/query.d.ts +1 -0
- package/lib/query/query.types.d.ts +5 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as i1 from '@ethlete/core';
|
|
2
2
|
import { BehaviorSubjectWithSubscriberCount, getCookie, setCookie, deleteCookie, DestroyService, DelayableDirective, equal, clone } from '@ethlete/core';
|
|
3
|
-
import { Observable, filter, takeWhile, switchMap, of, BehaviorSubject, Subject, takeUntil, interval, startWith, finalize,
|
|
3
|
+
import { Observable, filter, takeWhile, switchMap, of, BehaviorSubject, Subject, takeUntil, tap, interval, startWith, finalize, timer, map, combineLatest, fromEvent, debounceTime, take, concat, distinctUntilChanged } from 'rxjs';
|
|
4
4
|
import * as i0 from '@angular/core';
|
|
5
5
|
import { Directive, Input, InjectionToken, inject, ChangeDetectorRef, ViewContainerRef, TemplateRef, ErrorHandler, ElementRef } from '@angular/core';
|
|
6
6
|
import { FormGroup } from '@angular/forms';
|
|
@@ -909,11 +909,34 @@ class Query {
|
|
|
909
909
|
});
|
|
910
910
|
}
|
|
911
911
|
else if (state.type === 'failure') {
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
912
|
+
const failure = () => {
|
|
913
|
+
this._state$.next({
|
|
914
|
+
type: "FAILURE" /* QueryStateType.Failure */,
|
|
915
|
+
error: state.error,
|
|
916
|
+
meta,
|
|
917
|
+
});
|
|
918
|
+
};
|
|
919
|
+
const bearerAuthProvider = this._getBearerAuthProvider();
|
|
920
|
+
if (!bearerAuthProvider || options?._isUnauthorizedRetry) {
|
|
921
|
+
return failure();
|
|
922
|
+
}
|
|
923
|
+
else if (state.error.status === 401 /* HttpStatusCode.Unauthorized */ &&
|
|
924
|
+
bearerAuthProvider.shouldRefreshOnUnauthorizedResponse) {
|
|
925
|
+
const query = bearerAuthProvider._refreshQuery();
|
|
926
|
+
if (!query) {
|
|
927
|
+
return failure();
|
|
928
|
+
}
|
|
929
|
+
query.state$
|
|
930
|
+
.pipe(takeUntilResponse(), takeUntil(this._onAbort$), tap((state) => {
|
|
931
|
+
if (isQueryStateSuccess(state)) {
|
|
932
|
+
this.execute({ ...options, _isUnauthorizedRetry: true });
|
|
933
|
+
}
|
|
934
|
+
else if (isQueryStateFailure(state)) {
|
|
935
|
+
failure();
|
|
936
|
+
}
|
|
937
|
+
}))
|
|
938
|
+
.subscribe();
|
|
939
|
+
}
|
|
917
940
|
}
|
|
918
941
|
else if (state.type === 'cancel') {
|
|
919
942
|
this._state$.next({
|
|
@@ -995,6 +1018,13 @@ class Query {
|
|
|
995
1018
|
this._pollingSubscription?.unsubscribe();
|
|
996
1019
|
this._entitySubscription?.unsubscribe();
|
|
997
1020
|
}
|
|
1021
|
+
_getBearerAuthProvider() {
|
|
1022
|
+
const authProvider = this._client.authProvider;
|
|
1023
|
+
if (authProvider && isBearerAuthProvider(authProvider)) {
|
|
1024
|
+
return authProvider;
|
|
1025
|
+
}
|
|
1026
|
+
return null;
|
|
1027
|
+
}
|
|
998
1028
|
}
|
|
999
1029
|
|
|
1000
1030
|
const isBasicAuthProvider = (authProvider) => authProvider instanceof BasicAuthProvider;
|
|
@@ -1032,6 +1062,11 @@ class BearerAuthProvider {
|
|
|
1032
1062
|
get currentRefreshQuery() {
|
|
1033
1063
|
return this._currentRefreshQuery$.getValue();
|
|
1034
1064
|
}
|
|
1065
|
+
get shouldRefreshOnUnauthorizedResponse() {
|
|
1066
|
+
return (!!this._config.refreshConfig &&
|
|
1067
|
+
(this._config.refreshConfig.refreshOnUnauthorizedResponse === undefined ||
|
|
1068
|
+
this._config.refreshConfig.refreshOnUnauthorizedResponse));
|
|
1069
|
+
}
|
|
1035
1070
|
constructor(_config) {
|
|
1036
1071
|
this._config = _config;
|
|
1037
1072
|
this._destroy$ = new Subject();
|
|
@@ -1112,7 +1147,13 @@ class BearerAuthProvider {
|
|
|
1112
1147
|
break;
|
|
1113
1148
|
}
|
|
1114
1149
|
}
|
|
1150
|
+
/**
|
|
1151
|
+
* @internal
|
|
1152
|
+
*/
|
|
1115
1153
|
_refreshQuery() {
|
|
1154
|
+
if (isQueryStateLoading(this._currentRefreshQuery$.getValue()?.state)) {
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1116
1157
|
const currentRefreshToken = this.tokens.refreshToken;
|
|
1117
1158
|
if (!currentRefreshToken || !this._config.refreshConfig) {
|
|
1118
1159
|
return;
|
|
@@ -1152,6 +1193,7 @@ class BearerAuthProvider {
|
|
|
1152
1193
|
}
|
|
1153
1194
|
}), takeUntilResponse(), takeUntil(this._destroy$))
|
|
1154
1195
|
.subscribe();
|
|
1196
|
+
return query;
|
|
1155
1197
|
}
|
|
1156
1198
|
}
|
|
1157
1199
|
|