@dontdrinkandroot/ngx-extensions 0.7.0 → 0.21.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/fesm2022/dontdrinkandroot-ngx-extensions.mjs +174 -749
- package/fesm2022/dontdrinkandroot-ngx-extensions.mjs.map +1 -1
- package/package.json +12 -5
- package/types/dontdrinkandroot-ngx-extensions.d.ts +161 -0
- package/LICENSE +0 -201
- package/index.d.ts +0 -5
- package/public-api.d.ts +0 -25
- package/src/cookie/cookie.service.d.ts +0 -41
- package/src/ddr-extensions.module.d.ts +0 -11
- package/src/http/redirect-to-login-interceptor.service.d.ts +0 -15
- package/src/http/url-info.d.ts +0 -13
- package/src/http/with-credentials-interceptor.service.d.ts +0 -11
- package/src/image/lazy-image.directive.d.ts +0 -29
- package/src/jwt/jwt-interceptor.service.d.ts +0 -14
- package/src/jwt/jwt-refresh-token-interceptor.service.d.ts +0 -18
- package/src/jwt/jwt-token-response.d.ts +0 -4
- package/src/jwt/jwt.service.d.ts +0 -48
- package/src/logger/console-logger.service.d.ts +0 -22
- package/src/logger/logger.service.d.ts +0 -10
- package/src/methoddecorator/debounce.d.ts +0 -1
- package/src/methoddecorator/limit.d.ts +0 -1
- package/src/oauth/json-web-token.d.ts +0 -30
- package/src/oauth/oauth2-access-token-interceptor.service.d.ts +0 -14
- package/src/oauth/oauth2-config.d.ts +0 -9
- package/src/oauth/oauth2-error.d.ts +0 -5
- package/src/oauth/oauth2-refresh-token-interceptor.service.d.ts +0 -14
- package/src/oauth/oauth2.module.d.ts +0 -9
- package/src/oauth/oauth2.service.d.ts +0 -35
- package/src/oauth/redirect-to-oauth2-login-interceptor.service.d.ts +0 -18
- package/src/oauth/token-response.d.ts +0 -6
- package/src/scroll/bottom-hit.directive.d.ts +0 -13
- package/src/scroll/scroll.service.d.ts +0 -12
- package/src/storage/local-storage.service.d.ts +0 -23
- package/src/storage/storage.service.d.ts +0 -7
- package/src/typeguard/is-non-null.d.ts +0 -1
- package/src/util/collection-utils.d.ts +0 -10
- package/src/util/number-utils.d.ts +0 -3
- package/src/util/object-utils.d.ts +0 -4
- package/src/util/string-utils.d.ts +0 -6
- package/src/util/type-utils.d.ts +0 -3
- package/src/visibility/visibility.service.d.ts +0 -9
|
@@ -1,278 +1,11 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import {
|
|
2
|
+
import { Injectable, InjectionToken, inject, NgModule, EventEmitter, HostListener, Output, Directive } from '@angular/core';
|
|
3
|
+
import { DOCUMENT, ViewportScroller } from '@angular/common';
|
|
4
|
+
import { Router, NavigationStart } from '@angular/router';
|
|
3
5
|
import { __decorate } from 'tslib';
|
|
4
|
-
import * as i2 from '@angular/common';
|
|
5
|
-
import { DOCUMENT } from '@angular/common';
|
|
6
|
-
import * as i1 from '@angular/router';
|
|
7
|
-
import { NavigationStart } from '@angular/router';
|
|
8
6
|
import { merge, fromEvent, throwError } from 'rxjs';
|
|
9
|
-
import { debounceTime, startWith, map, distinctUntilChanged, shareReplay, catchError
|
|
10
|
-
import
|
|
11
|
-
import { HttpErrorResponse, HttpParams, HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
12
|
-
|
|
13
|
-
class NumberUtils {
|
|
14
|
-
static getNextPowerOfTwo(value) {
|
|
15
|
-
let target = 2;
|
|
16
|
-
while (target < value) {
|
|
17
|
-
target *= 2;
|
|
18
|
-
}
|
|
19
|
-
return target;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
class StringUtils {
|
|
24
|
-
static capitalizeFirstLetter(text) {
|
|
25
|
-
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
26
|
-
}
|
|
27
|
-
static stripTrailingSlash(text) {
|
|
28
|
-
const lastChar = text.charAt(text.length - 1);
|
|
29
|
-
if ('/' === lastChar) {
|
|
30
|
-
return text.slice(0, text.length - 1);
|
|
31
|
-
}
|
|
32
|
-
return text;
|
|
33
|
-
}
|
|
34
|
-
static updateUrlParameter(uri, key, value) {
|
|
35
|
-
// remove the hash part before operating on the uri
|
|
36
|
-
const i = uri.indexOf('#');
|
|
37
|
-
const hash = i === -1 ? '' : uri.substr(i);
|
|
38
|
-
uri = i === -1 ? uri : uri.substr(0, i);
|
|
39
|
-
const re = new RegExp('([?&])' + key + '=.*?(&|$)', 'i');
|
|
40
|
-
const separator = uri.indexOf('?') !== -1 ? '&' : '?';
|
|
41
|
-
if (uri.match(re)) {
|
|
42
|
-
uri = uri.replace(re, '$1' + key + '=' + value + '$2');
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
uri = uri + separator + key + '=' + value;
|
|
46
|
-
}
|
|
47
|
-
return uri + hash; // finally append the hash as well
|
|
48
|
-
}
|
|
49
|
-
static createRandomString(lengthOfCode, possible) {
|
|
50
|
-
let text = '';
|
|
51
|
-
for (let i = 0; i < lengthOfCode; i++) {
|
|
52
|
-
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
53
|
-
}
|
|
54
|
-
return text;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function Debounce(delay = 250) {
|
|
59
|
-
let timeoutReference = null;
|
|
60
|
-
// eslint-disable-next-line
|
|
61
|
-
return (target, propertyKey, descriptor) => {
|
|
62
|
-
const original = descriptor.value;
|
|
63
|
-
descriptor.value = function (...args) {
|
|
64
|
-
if (null != timeoutReference)
|
|
65
|
-
clearTimeout(timeoutReference);
|
|
66
|
-
timeoutReference = setTimeout(() => original.apply(this, args), delay);
|
|
67
|
-
};
|
|
68
|
-
return descriptor;
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function Limit(rate = 250) {
|
|
73
|
-
let timeoutReference = null;
|
|
74
|
-
// eslint-disable-next-line
|
|
75
|
-
return (target, propertyKey, descriptor) => {
|
|
76
|
-
const original = descriptor.value;
|
|
77
|
-
descriptor.value = function (...args) {
|
|
78
|
-
if (null == timeoutReference) {
|
|
79
|
-
timeoutReference = setTimeout(() => {
|
|
80
|
-
original.apply(this, args);
|
|
81
|
-
timeoutReference = null;
|
|
82
|
-
}, rate);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
return descriptor;
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
class LazyImageDirective {
|
|
90
|
-
element;
|
|
91
|
-
changeDetectorRef;
|
|
92
|
-
src;
|
|
93
|
-
objectFit = 'contain';
|
|
94
|
-
offset = 1000;
|
|
95
|
-
hostSrc = 'assets/placeholder.gif';
|
|
96
|
-
hostStyleWidthPx;
|
|
97
|
-
hostStyleHeightPx;
|
|
98
|
-
hostStyleObjectFit = 'contain';
|
|
99
|
-
displayed = false;
|
|
100
|
-
maxLoadedDimension = null;
|
|
101
|
-
constructor(element, changeDetectorRef) {
|
|
102
|
-
this.element = element;
|
|
103
|
-
this.changeDetectorRef = changeDetectorRef;
|
|
104
|
-
}
|
|
105
|
-
windowResized() {
|
|
106
|
-
this.displayed = false;
|
|
107
|
-
this.check();
|
|
108
|
-
}
|
|
109
|
-
windowScroll() {
|
|
110
|
-
this.check();
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* @override
|
|
114
|
-
*/
|
|
115
|
-
ngOnChanges() {
|
|
116
|
-
this.displayed = false;
|
|
117
|
-
this.maxLoadedDimension = null;
|
|
118
|
-
this.check();
|
|
119
|
-
}
|
|
120
|
-
check() {
|
|
121
|
-
if (this.element.nativeElement.parentElement.offsetWidth > 0) {
|
|
122
|
-
this.doCheck();
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
setTimeout(() => this.doCheck(), 1);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
doCheck() {
|
|
129
|
-
if (this.displayed || this.isHidden(this.element.nativeElement)) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
if (this.isInsideViewport(this.element.nativeElement, this.offset)) {
|
|
133
|
-
this.displayed = true;
|
|
134
|
-
const dimension = this.getDimension();
|
|
135
|
-
this.hostStyleWidthPx = dimension.width;
|
|
136
|
-
this.hostStyleHeightPx = dimension.height;
|
|
137
|
-
if (this.maxLoadedDimension != null
|
|
138
|
-
&& this.maxLoadedDimension.width >= dimension.width
|
|
139
|
-
&& this.maxLoadedDimension.height >= dimension.height) {
|
|
140
|
-
// console.log('has smaller dimension');
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
this.maxLoadedDimension = dimension;
|
|
144
|
-
let wantedSize;
|
|
145
|
-
if (this.objectFit === 'cover') {
|
|
146
|
-
wantedSize = NumberUtils.getNextPowerOfTwo(Math.max(dimension.width, dimension.height));
|
|
147
|
-
this.hostStyleObjectFit = 'cover';
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
wantedSize = NumberUtils.getNextPowerOfTwo(Math.min(dimension.width, dimension.height));
|
|
151
|
-
this.hostStyleObjectFit = 'contain';
|
|
152
|
-
}
|
|
153
|
-
this.hostSrc = StringUtils.updateUrlParameter(this.src, 'size', String(wantedSize));
|
|
154
|
-
this.changeDetectorRef.markForCheck();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
isInsideViewport(element, threshold) {
|
|
158
|
-
const ownerDocument = element.ownerDocument;
|
|
159
|
-
const documentTop = window.scrollY || ownerDocument.body.scrollTop;
|
|
160
|
-
const documentLeft = window.scrollX || ownerDocument.body.scrollLeft;
|
|
161
|
-
const documentWidth = window.innerWidth || (ownerDocument.documentElement.clientWidth || document.body.clientWidth);
|
|
162
|
-
const documentHeight = window.innerHeight || (ownerDocument.documentElement.clientHeight || document.body.clientHeight);
|
|
163
|
-
const topOffset = element.getBoundingClientRect().top + documentTop - ownerDocument.documentElement.clientTop;
|
|
164
|
-
const leftOffset = element.getBoundingClientRect().left + documentLeft - ownerDocument.documentElement.clientLeft;
|
|
165
|
-
const isBelowViewport = documentHeight + documentTop <= topOffset - threshold;
|
|
166
|
-
const isAtRightOfViewport = documentWidth + window.scrollX <= leftOffset - threshold;
|
|
167
|
-
const isAboveViewport = documentTop >= topOffset + threshold + element.offsetHeight;
|
|
168
|
-
const isAtLeftOfViewport = documentLeft >= leftOffset + threshold + element.offsetWidth;
|
|
169
|
-
return !isBelowViewport && !isAboveViewport && !isAtRightOfViewport && !isAtLeftOfViewport;
|
|
170
|
-
}
|
|
171
|
-
getDimension() {
|
|
172
|
-
return {
|
|
173
|
-
width: this.element.nativeElement.parentElement.offsetWidth,
|
|
174
|
-
height: this.element.nativeElement.parentElement.offsetHeight,
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
isHidden(element) {
|
|
178
|
-
return window.getComputedStyle(element).display === 'none';
|
|
179
|
-
}
|
|
180
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: LazyImageDirective, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
181
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.0.5", type: LazyImageDirective, isStandalone: false, selector: "[ddrLazyImage]", inputs: { src: ["ddrLazyImage", "src"], objectFit: "objectFit", offset: "offset" }, host: { listeners: { "window:resize": "windowResized($event)", "window:scroll": "windowScroll($event)" }, properties: { "src": "this.hostSrc", "style.width.px": "this.hostStyleWidthPx", "style.height.px": "this.hostStyleHeightPx", "style.object-fit": "this.hostStyleObjectFit" } }, usesOnChanges: true, ngImport: i0 });
|
|
182
|
-
}
|
|
183
|
-
__decorate([
|
|
184
|
-
Debounce()
|
|
185
|
-
], LazyImageDirective.prototype, "windowResized", null);
|
|
186
|
-
__decorate([
|
|
187
|
-
Limit()
|
|
188
|
-
], LazyImageDirective.prototype, "windowScroll", null);
|
|
189
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: LazyImageDirective, decorators: [{
|
|
190
|
-
type: Directive,
|
|
191
|
-
args: [{
|
|
192
|
-
selector: '[ddrLazyImage]',
|
|
193
|
-
standalone: false
|
|
194
|
-
}]
|
|
195
|
-
}], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }], propDecorators: { src: [{
|
|
196
|
-
type: Input,
|
|
197
|
-
args: ['ddrLazyImage']
|
|
198
|
-
}], objectFit: [{
|
|
199
|
-
type: Input
|
|
200
|
-
}], offset: [{
|
|
201
|
-
type: Input
|
|
202
|
-
}], hostSrc: [{
|
|
203
|
-
type: HostBinding,
|
|
204
|
-
args: ['src']
|
|
205
|
-
}], hostStyleWidthPx: [{
|
|
206
|
-
type: HostBinding,
|
|
207
|
-
args: ['style.width.px']
|
|
208
|
-
}], hostStyleHeightPx: [{
|
|
209
|
-
type: HostBinding,
|
|
210
|
-
args: ['style.height.px']
|
|
211
|
-
}], hostStyleObjectFit: [{
|
|
212
|
-
type: HostBinding,
|
|
213
|
-
args: ['style.object-fit']
|
|
214
|
-
}], windowResized: [{
|
|
215
|
-
type: HostListener,
|
|
216
|
-
args: ['window:resize', ['$event']]
|
|
217
|
-
}], windowScroll: [{
|
|
218
|
-
type: HostListener,
|
|
219
|
-
args: ['window:scroll', ['$event']]
|
|
220
|
-
}] } });
|
|
221
|
-
|
|
222
|
-
class BottomHitDirective {
|
|
223
|
-
offset = 1000;
|
|
224
|
-
windowBottomHit = new EventEmitter();
|
|
225
|
-
elementBottomHit = new EventEmitter();
|
|
226
|
-
scrolled($event) {
|
|
227
|
-
this.elementScrollEvent($event);
|
|
228
|
-
}
|
|
229
|
-
windowScrolled() {
|
|
230
|
-
this.windowScrollEvent();
|
|
231
|
-
}
|
|
232
|
-
windowScrollEvent() {
|
|
233
|
-
const pageHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight, document.body.clientHeight, document.documentElement.clientHeight);
|
|
234
|
-
const viewportHeight = document.documentElement.clientHeight;
|
|
235
|
-
const scrollPosition = window.scrollY || document.documentElement.scrollTop || document.body.scrollTop || 0;
|
|
236
|
-
const distanceToBottom = pageHeight - (scrollPosition + viewportHeight);
|
|
237
|
-
if (distanceToBottom < this.offset) {
|
|
238
|
-
this.windowBottomHit.emit();
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
elementScrollEvent($event) {
|
|
242
|
-
const target = $event.target;
|
|
243
|
-
const scrollPosition = target.scrollHeight - target.scrollTop;
|
|
244
|
-
const offsetHeight = target.offsetHeight;
|
|
245
|
-
const isReachingBottom = (scrollPosition - offsetHeight) < this.offset;
|
|
246
|
-
if (isReachingBottom) {
|
|
247
|
-
this.elementBottomHit.emit();
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: BottomHitDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
251
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.0.5", type: BottomHitDirective, isStandalone: false, selector: "[ddrBottomHit]", outputs: { windowBottomHit: "windowBottomHit", elementBottomHit: "elementBottomHit" }, host: { listeners: { "scroll": "scrolled($event)", "window:scroll": "windowScrolled($event)" } }, ngImport: i0 });
|
|
252
|
-
}
|
|
253
|
-
__decorate([
|
|
254
|
-
Limit()
|
|
255
|
-
], BottomHitDirective.prototype, "scrolled", null);
|
|
256
|
-
__decorate([
|
|
257
|
-
Limit()
|
|
258
|
-
], BottomHitDirective.prototype, "windowScrolled", null);
|
|
259
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: BottomHitDirective, decorators: [{
|
|
260
|
-
type: Directive,
|
|
261
|
-
args: [{
|
|
262
|
-
selector: '[ddrBottomHit]',
|
|
263
|
-
standalone: false
|
|
264
|
-
}]
|
|
265
|
-
}], propDecorators: { windowBottomHit: [{
|
|
266
|
-
type: Output
|
|
267
|
-
}], elementBottomHit: [{
|
|
268
|
-
type: Output
|
|
269
|
-
}], scrolled: [{
|
|
270
|
-
type: HostListener,
|
|
271
|
-
args: ['scroll', ['$event']]
|
|
272
|
-
}], windowScrolled: [{
|
|
273
|
-
type: HostListener,
|
|
274
|
-
args: ['window:scroll', ['$event']]
|
|
275
|
-
}] } });
|
|
7
|
+
import { debounceTime, startWith, map, distinctUntilChanged, shareReplay, catchError } from 'rxjs/operators';
|
|
8
|
+
import { HttpErrorResponse } from '@angular/common/http';
|
|
276
9
|
|
|
277
10
|
class Logger {
|
|
278
11
|
debugEnabled = false;
|
|
@@ -314,10 +47,10 @@ class ConsoleLogger extends Logger {
|
|
|
314
47
|
console.error(...data);
|
|
315
48
|
}
|
|
316
49
|
}
|
|
317
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
318
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
50
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: ConsoleLogger, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
51
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: ConsoleLogger });
|
|
319
52
|
}
|
|
320
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
53
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: ConsoleLogger, decorators: [{
|
|
321
54
|
type: Injectable
|
|
322
55
|
}] });
|
|
323
56
|
|
|
@@ -326,13 +59,8 @@ class StorageService {
|
|
|
326
59
|
}
|
|
327
60
|
|
|
328
61
|
class LocalStorageService extends StorageService {
|
|
329
|
-
storagePrefix;
|
|
330
|
-
logger;
|
|
331
|
-
constructor(storagePrefix, logger) {
|
|
332
|
-
super();
|
|
333
|
-
this.storagePrefix = storagePrefix;
|
|
334
|
-
this.logger = logger;
|
|
335
|
-
}
|
|
62
|
+
storagePrefix = inject(DDR_STORAGE_PREFIX);
|
|
63
|
+
logger = inject(Logger);
|
|
336
64
|
/**
|
|
337
65
|
* @override
|
|
338
66
|
*/
|
|
@@ -366,24 +94,18 @@ class LocalStorageService extends StorageService {
|
|
|
366
94
|
getFullKey(key) {
|
|
367
95
|
return this.storagePrefix + '.' + key;
|
|
368
96
|
}
|
|
369
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
370
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
97
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: LocalStorageService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
98
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: LocalStorageService });
|
|
371
99
|
}
|
|
372
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
100
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: LocalStorageService, decorators: [{
|
|
373
101
|
type: Injectable
|
|
374
|
-
}]
|
|
375
|
-
type: Inject,
|
|
376
|
-
args: [DDR_STORAGE_PREFIX]
|
|
377
|
-
}] }, { type: Logger }] });
|
|
102
|
+
}] });
|
|
378
103
|
|
|
379
|
-
const DDR_JWT_REFRESH_TOKEN_URL = new InjectionToken('DDR_JWT_REFRESH_TOKEN_URL');
|
|
380
104
|
const DDR_LOGIN_PATH = new InjectionToken('DDR_LOGIN_PATH');
|
|
381
105
|
class DdrExtensionsModule {
|
|
382
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
383
|
-
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "
|
|
384
|
-
|
|
385
|
-
BottomHitDirective] });
|
|
386
|
-
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: DdrExtensionsModule, providers: [
|
|
106
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: DdrExtensionsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
107
|
+
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.0.6", ngImport: i0, type: DdrExtensionsModule });
|
|
108
|
+
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: DdrExtensionsModule, providers: [
|
|
387
109
|
{
|
|
388
110
|
provide: DDR_LOGIN_PATH,
|
|
389
111
|
useValue: '/login'
|
|
@@ -402,13 +124,9 @@ class DdrExtensionsModule {
|
|
|
402
124
|
},
|
|
403
125
|
] });
|
|
404
126
|
}
|
|
405
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
127
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: DdrExtensionsModule, decorators: [{
|
|
406
128
|
type: NgModule,
|
|
407
129
|
args: [{
|
|
408
|
-
declarations: [
|
|
409
|
-
LazyImageDirective,
|
|
410
|
-
BottomHitDirective
|
|
411
|
-
],
|
|
412
130
|
imports: [],
|
|
413
131
|
providers: [
|
|
414
132
|
{
|
|
@@ -428,10 +146,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImpor
|
|
|
428
146
|
useClass: LocalStorageService
|
|
429
147
|
},
|
|
430
148
|
],
|
|
431
|
-
exports: [
|
|
432
|
-
LazyImageDirective,
|
|
433
|
-
BottomHitDirective
|
|
434
|
-
]
|
|
435
149
|
}]
|
|
436
150
|
}] });
|
|
437
151
|
|
|
@@ -439,13 +153,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImpor
|
|
|
439
153
|
// not use `DOCUMENT` injection and therefore doesn't work well with AoT production builds.
|
|
440
154
|
// Package: https://github.com/BCJTI/ng2-cookies
|
|
441
155
|
class CookieService {
|
|
442
|
-
document;
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
this.document = document;
|
|
446
|
-
// To avoid issues with server side prerendering, check if `document` is defined.
|
|
447
|
-
this.documentIsAccessible = document !== undefined;
|
|
448
|
-
}
|
|
156
|
+
document = inject(DOCUMENT);
|
|
157
|
+
// To avoid issues with server side prerendering, check if `document` is defined.
|
|
158
|
+
documentIsAccessible = this.document !== undefined;
|
|
449
159
|
/**
|
|
450
160
|
* @param name Cookie name
|
|
451
161
|
*/
|
|
@@ -556,18 +266,15 @@ class CookieService {
|
|
|
556
266
|
const escapedName = name.replace(/([[\]{}()|=;+?,.*^$])/ig, '\\$1');
|
|
557
267
|
return new RegExp('(?:^' + escapedName + '|;\\s*' + escapedName + ')=(.*?)(?:;|$)', 'g');
|
|
558
268
|
}
|
|
559
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
560
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
269
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: CookieService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
270
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: CookieService, providedIn: 'root' });
|
|
561
271
|
}
|
|
562
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
272
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: CookieService, decorators: [{
|
|
563
273
|
type: Injectable,
|
|
564
274
|
args: [{
|
|
565
275
|
providedIn: 'root'
|
|
566
276
|
}]
|
|
567
|
-
}]
|
|
568
|
-
type: Inject,
|
|
569
|
-
args: [DOCUMENT]
|
|
570
|
-
}] }] });
|
|
277
|
+
}] });
|
|
571
278
|
|
|
572
279
|
class ObjectUtils {
|
|
573
280
|
static deepCopy(value) {
|
|
@@ -604,6 +311,51 @@ class CollectionUtils {
|
|
|
604
311
|
}
|
|
605
312
|
}
|
|
606
313
|
|
|
314
|
+
class StringUtils {
|
|
315
|
+
static capitalizeFirstLetter(text) {
|
|
316
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
317
|
+
}
|
|
318
|
+
static stripTrailingSlash(text) {
|
|
319
|
+
const lastChar = text.charAt(text.length - 1);
|
|
320
|
+
if ('/' === lastChar) {
|
|
321
|
+
return text.slice(0, text.length - 1);
|
|
322
|
+
}
|
|
323
|
+
return text;
|
|
324
|
+
}
|
|
325
|
+
static updateUrlParameter(uri, key, value) {
|
|
326
|
+
// remove the hash part before operating on the uri
|
|
327
|
+
const i = uri.indexOf('#');
|
|
328
|
+
const hash = i === -1 ? '' : uri.substr(i);
|
|
329
|
+
uri = i === -1 ? uri : uri.substr(0, i);
|
|
330
|
+
const re = new RegExp('([?&])' + key + '=.*?(&|$)', 'i');
|
|
331
|
+
const separator = uri.indexOf('?') !== -1 ? '&' : '?';
|
|
332
|
+
if (uri.match(re)) {
|
|
333
|
+
uri = uri.replace(re, '$1' + key + '=' + value + '$2');
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
uri = uri + separator + key + '=' + value;
|
|
337
|
+
}
|
|
338
|
+
return uri + hash; // finally append the hash as well
|
|
339
|
+
}
|
|
340
|
+
static createRandomString(lengthOfCode, possible) {
|
|
341
|
+
let text = '';
|
|
342
|
+
for (let i = 0; i < lengthOfCode; i++) {
|
|
343
|
+
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
344
|
+
}
|
|
345
|
+
return text;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
class NumberUtils {
|
|
350
|
+
static getNextPowerOfTwo(value) {
|
|
351
|
+
let target = 2;
|
|
352
|
+
while (target < value) {
|
|
353
|
+
target *= 2;
|
|
354
|
+
}
|
|
355
|
+
return target;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
607
359
|
class TypeUtils {
|
|
608
360
|
static notNull(value, message = 'Value must not be null') {
|
|
609
361
|
if (null == value) {
|
|
@@ -614,12 +366,10 @@ class TypeUtils {
|
|
|
614
366
|
}
|
|
615
367
|
|
|
616
368
|
class ScrollService {
|
|
617
|
-
router;
|
|
618
|
-
viewportScroller;
|
|
369
|
+
router = inject(Router);
|
|
370
|
+
viewportScroller = inject(ViewportScroller);
|
|
619
371
|
scrollPositionMap = new Map();
|
|
620
|
-
constructor(
|
|
621
|
-
this.router = router;
|
|
622
|
-
this.viewportScroller = viewportScroller;
|
|
372
|
+
constructor() {
|
|
623
373
|
this.router.events
|
|
624
374
|
.subscribe(e => {
|
|
625
375
|
if (e instanceof NavigationStart) {
|
|
@@ -638,15 +388,100 @@ class ScrollService {
|
|
|
638
388
|
}, 1);
|
|
639
389
|
}
|
|
640
390
|
}
|
|
641
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
642
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
391
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: ScrollService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
392
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: ScrollService, providedIn: 'root' });
|
|
643
393
|
}
|
|
644
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
394
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: ScrollService, decorators: [{
|
|
645
395
|
type: Injectable,
|
|
646
396
|
args: [{
|
|
647
397
|
providedIn: 'root'
|
|
648
398
|
}]
|
|
649
|
-
}], ctorParameters: () => [
|
|
399
|
+
}], ctorParameters: () => [] });
|
|
400
|
+
|
|
401
|
+
function Debounce(delay = 250) {
|
|
402
|
+
let timeoutReference = null;
|
|
403
|
+
// eslint-disable-next-line
|
|
404
|
+
return (target, propertyKey, descriptor) => {
|
|
405
|
+
const original = descriptor.value;
|
|
406
|
+
descriptor.value = function (...args) {
|
|
407
|
+
if (null != timeoutReference)
|
|
408
|
+
clearTimeout(timeoutReference);
|
|
409
|
+
timeoutReference = setTimeout(() => original.apply(this, args), delay);
|
|
410
|
+
};
|
|
411
|
+
return descriptor;
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function Limit(rate = 250) {
|
|
416
|
+
let timeoutReference = null;
|
|
417
|
+
// eslint-disable-next-line
|
|
418
|
+
return (target, propertyKey, descriptor) => {
|
|
419
|
+
const original = descriptor.value;
|
|
420
|
+
descriptor.value = function (...args) {
|
|
421
|
+
if (null == timeoutReference) {
|
|
422
|
+
timeoutReference = setTimeout(() => {
|
|
423
|
+
original.apply(this, args);
|
|
424
|
+
timeoutReference = null;
|
|
425
|
+
}, rate);
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
return descriptor;
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
class BottomHitDirective {
|
|
433
|
+
offset = 1000;
|
|
434
|
+
windowBottomHit = new EventEmitter();
|
|
435
|
+
elementBottomHit = new EventEmitter();
|
|
436
|
+
scrolled($event) {
|
|
437
|
+
this.elementScrollEvent($event);
|
|
438
|
+
}
|
|
439
|
+
windowScrolled() {
|
|
440
|
+
this.windowScrollEvent();
|
|
441
|
+
}
|
|
442
|
+
windowScrollEvent() {
|
|
443
|
+
const pageHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight, document.body.clientHeight, document.documentElement.clientHeight);
|
|
444
|
+
const viewportHeight = document.documentElement.clientHeight;
|
|
445
|
+
const scrollPosition = window.scrollY || document.documentElement.scrollTop || document.body.scrollTop || 0;
|
|
446
|
+
const distanceToBottom = pageHeight - (scrollPosition + viewportHeight);
|
|
447
|
+
if (distanceToBottom < this.offset) {
|
|
448
|
+
this.windowBottomHit.emit();
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
elementScrollEvent($event) {
|
|
452
|
+
const target = $event.target;
|
|
453
|
+
const scrollPosition = target.scrollHeight - target.scrollTop;
|
|
454
|
+
const offsetHeight = target.offsetHeight;
|
|
455
|
+
const isReachingBottom = (scrollPosition - offsetHeight) < this.offset;
|
|
456
|
+
if (isReachingBottom) {
|
|
457
|
+
this.elementBottomHit.emit();
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: BottomHitDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
461
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.0.6", type: BottomHitDirective, isStandalone: true, selector: "[ddrBottomHit]", outputs: { windowBottomHit: "windowBottomHit", elementBottomHit: "elementBottomHit" }, host: { listeners: { "scroll": "scrolled($event)", "window:scroll": "windowScrolled()" } }, ngImport: i0 });
|
|
462
|
+
}
|
|
463
|
+
__decorate([
|
|
464
|
+
Limit()
|
|
465
|
+
], BottomHitDirective.prototype, "scrolled", null);
|
|
466
|
+
__decorate([
|
|
467
|
+
Limit()
|
|
468
|
+
], BottomHitDirective.prototype, "windowScrolled", null);
|
|
469
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: BottomHitDirective, decorators: [{
|
|
470
|
+
type: Directive,
|
|
471
|
+
args: [{
|
|
472
|
+
selector: '[ddrBottomHit]',
|
|
473
|
+
}]
|
|
474
|
+
}], propDecorators: { windowBottomHit: [{
|
|
475
|
+
type: Output
|
|
476
|
+
}], elementBottomHit: [{
|
|
477
|
+
type: Output
|
|
478
|
+
}], scrolled: [{
|
|
479
|
+
type: HostListener,
|
|
480
|
+
args: ['scroll', ['$event']]
|
|
481
|
+
}], windowScrolled: [{
|
|
482
|
+
type: HostListener,
|
|
483
|
+
args: ['window:scroll']
|
|
484
|
+
}] } });
|
|
650
485
|
|
|
651
486
|
class VisibilityService {
|
|
652
487
|
visibility$;
|
|
@@ -656,10 +491,10 @@ class VisibilityService {
|
|
|
656
491
|
getVisibilityObservable() {
|
|
657
492
|
return this.visibility$;
|
|
658
493
|
}
|
|
659
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
660
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
494
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: VisibilityService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
495
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: VisibilityService, providedIn: 'root' });
|
|
661
496
|
}
|
|
662
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
497
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: VisibilityService, decorators: [{
|
|
663
498
|
type: Injectable,
|
|
664
499
|
args: [{ providedIn: 'root' }]
|
|
665
500
|
}], ctorParameters: () => [] });
|
|
@@ -674,10 +509,10 @@ class WithCredentialsInterceptor {
|
|
|
674
509
|
});
|
|
675
510
|
return next.handle(cloned);
|
|
676
511
|
}
|
|
677
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
678
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
512
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: WithCredentialsInterceptor, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
513
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: WithCredentialsInterceptor });
|
|
679
514
|
}
|
|
680
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
515
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: WithCredentialsInterceptor, decorators: [{
|
|
681
516
|
type: Injectable
|
|
682
517
|
}] });
|
|
683
518
|
|
|
@@ -715,12 +550,8 @@ class UrlInfo {
|
|
|
715
550
|
}
|
|
716
551
|
|
|
717
552
|
class RedirectToLoginInterceptor {
|
|
718
|
-
router;
|
|
719
|
-
loginPath;
|
|
720
|
-
constructor(router, loginPath) {
|
|
721
|
-
this.router = router;
|
|
722
|
-
this.loginPath = loginPath;
|
|
723
|
-
}
|
|
553
|
+
router = inject(Router);
|
|
554
|
+
loginPath = inject(DDR_LOGIN_PATH);
|
|
724
555
|
/**
|
|
725
556
|
* @override
|
|
726
557
|
*/
|
|
@@ -734,423 +565,17 @@ class RedirectToLoginInterceptor {
|
|
|
734
565
|
return throwError(err);
|
|
735
566
|
}));
|
|
736
567
|
}
|
|
737
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
738
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
739
|
-
}
|
|
740
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: RedirectToLoginInterceptor, decorators: [{
|
|
741
|
-
type: Injectable
|
|
742
|
-
}], ctorParameters: () => [{ type: i1.Router }, { type: undefined, decorators: [{
|
|
743
|
-
type: Inject,
|
|
744
|
-
args: [DDR_LOGIN_PATH]
|
|
745
|
-
}] }] });
|
|
746
|
-
|
|
747
|
-
const DDR_OAUTH2_CONFIG = new InjectionToken('DDR_OAUTH2_CONFIG');
|
|
748
|
-
class OAuth2Config {
|
|
749
|
-
clientId;
|
|
750
|
-
redirectUri;
|
|
751
|
-
authorizeUri;
|
|
752
|
-
tokenUri;
|
|
753
|
-
constructor(clientId, redirectUri, authorizeUri, tokenUri) {
|
|
754
|
-
this.clientId = clientId;
|
|
755
|
-
this.redirectUri = redirectUri;
|
|
756
|
-
this.authorizeUri = authorizeUri;
|
|
757
|
-
this.tokenUri = tokenUri;
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
class OAuth2Error extends Error {
|
|
762
|
-
static CODE_NOT_FOUND = 'code_not_found';
|
|
763
|
-
static ACCESS_DENIED = 'access_denied';
|
|
764
|
-
constructor(error) {
|
|
765
|
-
super(error);
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
class OAuth2Service {
|
|
770
|
-
route;
|
|
771
|
-
httpClient;
|
|
772
|
-
loggerService;
|
|
773
|
-
config;
|
|
774
|
-
static STORAGE_KEY_CHALLENGE = 'ddr_oauth2_challenge';
|
|
775
|
-
static STORAGE_KEY_REFRESH_TOKEN = 'ddr_oauth2_refresh_token';
|
|
776
|
-
static STORAGE_KEY_RETURN_URL = 'ddr_oauth2_return_url';
|
|
777
|
-
accessTokenString = null;
|
|
778
|
-
accessToken = null;
|
|
779
|
-
REFRESH_MARGIN_SECONDS = 60 * 10;
|
|
780
|
-
refreshTokenRequest$ = null;
|
|
781
|
-
constructor(route, httpClient, loggerService, config) {
|
|
782
|
-
this.route = route;
|
|
783
|
-
this.httpClient = httpClient;
|
|
784
|
-
this.loggerService = loggerService;
|
|
785
|
-
this.config = config;
|
|
786
|
-
}
|
|
787
|
-
redirectToLogin() {
|
|
788
|
-
const challenge = this.createChallenge();
|
|
789
|
-
localStorage.setItem(OAuth2Service.STORAGE_KEY_CHALLENGE, challenge);
|
|
790
|
-
const params = new HttpParams()
|
|
791
|
-
.set('client_id', this.config.clientId)
|
|
792
|
-
.set('response_type', 'code')
|
|
793
|
-
.set('redirect_uri', this.config.redirectUri)
|
|
794
|
-
.set('code_challenge', challenge)
|
|
795
|
-
.set('code_challenge_method', 'plain');
|
|
796
|
-
window.location.href = this.config.authorizeUri + '?' + params.toString();
|
|
797
|
-
}
|
|
798
|
-
handleCode() {
|
|
799
|
-
if (this.route.snapshot.queryParamMap.has('error')) {
|
|
800
|
-
const error = this.route.snapshot.queryParamMap.get('error');
|
|
801
|
-
return throwError(() => new OAuth2Error(error ?? 'Unknown error'));
|
|
802
|
-
}
|
|
803
|
-
if (!this.route.snapshot.queryParamMap.has('code')) {
|
|
804
|
-
return throwError(() => new OAuth2Error(OAuth2Error.CODE_NOT_FOUND));
|
|
805
|
-
}
|
|
806
|
-
const code = TypeUtils.notNull(this.route.snapshot.queryParamMap.get('code'));
|
|
807
|
-
const params = new HttpParams()
|
|
808
|
-
.set('grant_type', 'authorization_code')
|
|
809
|
-
.set('code', code)
|
|
810
|
-
.set('redirect_uri', this.config.redirectUri)
|
|
811
|
-
.set('code_verifier', TypeUtils.notNull(localStorage.getItem(OAuth2Service.STORAGE_KEY_CHALLENGE)))
|
|
812
|
-
.set('client_id', this.config.clientId);
|
|
813
|
-
return this.httpClient.post(this.config.tokenUri, params).pipe(map(tokenResponse => this.processTokenResponse(tokenResponse)));
|
|
814
|
-
}
|
|
815
|
-
createChallenge() {
|
|
816
|
-
return StringUtils.createRandomString(64, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-._~');
|
|
817
|
-
}
|
|
818
|
-
getRefreshToken() {
|
|
819
|
-
return localStorage.getItem(OAuth2Service.STORAGE_KEY_REFRESH_TOKEN);
|
|
820
|
-
}
|
|
821
|
-
getAccessTokenString() {
|
|
822
|
-
return this.accessTokenString;
|
|
823
|
-
}
|
|
824
|
-
isAccessTokenExpired() {
|
|
825
|
-
return (null == this.accessToken
|
|
826
|
-
|| this.accessToken.exp * 1000 < Date.now());
|
|
827
|
-
}
|
|
828
|
-
isRefreshPossibleAndRequired(req = null) {
|
|
829
|
-
return ((null == req || !req.url.endsWith(this.config.tokenUri))
|
|
830
|
-
&& null != this.getRefreshToken()
|
|
831
|
-
&& (null == this.accessToken
|
|
832
|
-
|| (this.accessToken.exp - this.REFRESH_MARGIN_SECONDS) * 1000 < Date.now()));
|
|
833
|
-
}
|
|
834
|
-
performRefresh() {
|
|
835
|
-
if (null == this.refreshTokenRequest$) {
|
|
836
|
-
this.loggerService.info('Performing token refesh');
|
|
837
|
-
const params = new HttpParams()
|
|
838
|
-
.set('grant_type', 'refresh_token')
|
|
839
|
-
.set('refresh_token', TypeUtils.notNull(this.getRefreshToken()))
|
|
840
|
-
.set('client_id', this.config.clientId);
|
|
841
|
-
this.refreshTokenRequest$ = this.httpClient.post(this.config.tokenUri, params).pipe(map(tokenResponse => {
|
|
842
|
-
const token = this.processTokenResponse(tokenResponse);
|
|
843
|
-
this.refreshTokenRequest$ = null;
|
|
844
|
-
return token;
|
|
845
|
-
}), catchError(error => {
|
|
846
|
-
this.accessTokenString = null;
|
|
847
|
-
this.accessToken = null;
|
|
848
|
-
localStorage.removeItem(OAuth2Service.STORAGE_KEY_REFRESH_TOKEN);
|
|
849
|
-
this.refreshTokenRequest$ = null;
|
|
850
|
-
return throwError(error);
|
|
851
|
-
}), shareReplay(1));
|
|
852
|
-
}
|
|
853
|
-
return this.refreshTokenRequest$;
|
|
854
|
-
}
|
|
855
|
-
processTokenResponse(tokenResponse) {
|
|
856
|
-
localStorage.removeItem(OAuth2Service.STORAGE_KEY_CHALLENGE);
|
|
857
|
-
this.accessTokenString = tokenResponse.access_token;
|
|
858
|
-
this.accessToken = JSON.parse(atob(tokenResponse.access_token.split('.')[1]));
|
|
859
|
-
this.loggerService.info('Access Token Expiry', new Date(this.accessToken.exp * 1000));
|
|
860
|
-
localStorage.setItem(OAuth2Service.STORAGE_KEY_REFRESH_TOKEN, tokenResponse.refresh_token);
|
|
861
|
-
return this.accessToken;
|
|
862
|
-
}
|
|
863
|
-
clear() {
|
|
864
|
-
this.accessToken = null;
|
|
865
|
-
this.accessTokenString = null;
|
|
866
|
-
localStorage.removeItem(OAuth2Service.STORAGE_KEY_REFRESH_TOKEN);
|
|
867
|
-
localStorage.removeItem(OAuth2Service.STORAGE_KEY_RETURN_URL);
|
|
868
|
-
}
|
|
869
|
-
setReturnUrl(url) {
|
|
870
|
-
localStorage.setItem(OAuth2Service.STORAGE_KEY_RETURN_URL, url);
|
|
871
|
-
}
|
|
872
|
-
getReturnUrl() {
|
|
873
|
-
return localStorage.getItem(OAuth2Service.STORAGE_KEY_RETURN_URL);
|
|
874
|
-
}
|
|
875
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: OAuth2Service, deps: [{ token: i1.ActivatedRoute }, { token: i2$1.HttpClient }, { token: Logger }, { token: DDR_OAUTH2_CONFIG }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
876
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: OAuth2Service });
|
|
877
|
-
}
|
|
878
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: OAuth2Service, decorators: [{
|
|
879
|
-
type: Injectable
|
|
880
|
-
}], ctorParameters: () => [{ type: i1.ActivatedRoute }, { type: i2$1.HttpClient }, { type: Logger }, { type: OAuth2Config, decorators: [{
|
|
881
|
-
type: Inject,
|
|
882
|
-
args: [DDR_OAUTH2_CONFIG]
|
|
883
|
-
}] }] });
|
|
884
|
-
|
|
885
|
-
class OAuth2RefreshTokenInterceptor {
|
|
886
|
-
oAuth2Service;
|
|
887
|
-
constructor(oAuth2Service) {
|
|
888
|
-
this.oAuth2Service = oAuth2Service;
|
|
889
|
-
}
|
|
890
|
-
/**
|
|
891
|
-
* @override
|
|
892
|
-
*/
|
|
893
|
-
intercept(req, next) {
|
|
894
|
-
if (this.oAuth2Service.isRefreshPossibleAndRequired(req)) {
|
|
895
|
-
return this.oAuth2Service.performRefresh().pipe(switchMap(() => next.handle(req)));
|
|
896
|
-
}
|
|
897
|
-
return next.handle(req);
|
|
898
|
-
}
|
|
899
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: OAuth2RefreshTokenInterceptor, deps: [{ token: OAuth2Service }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
900
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: OAuth2RefreshTokenInterceptor });
|
|
901
|
-
}
|
|
902
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: OAuth2RefreshTokenInterceptor, decorators: [{
|
|
903
|
-
type: Injectable
|
|
904
|
-
}], ctorParameters: () => [{ type: OAuth2Service }] });
|
|
905
|
-
|
|
906
|
-
class RedirectToOAuth2LoginInterceptor {
|
|
907
|
-
oAuth2Service;
|
|
908
|
-
router;
|
|
909
|
-
oAuth2Config;
|
|
910
|
-
constructor(oAuth2Service, router, oAuth2Config) {
|
|
911
|
-
this.oAuth2Service = oAuth2Service;
|
|
912
|
-
this.router = router;
|
|
913
|
-
this.oAuth2Config = oAuth2Config;
|
|
914
|
-
}
|
|
915
|
-
/**
|
|
916
|
-
* @override
|
|
917
|
-
*/
|
|
918
|
-
intercept(req, next) {
|
|
919
|
-
return next.handle(req).pipe(catchError((err) => {
|
|
920
|
-
if (err instanceof HttpErrorResponse) {
|
|
921
|
-
if (err.status === 401) {
|
|
922
|
-
if (!window.location.href.startsWith(this.oAuth2Config.redirectUri)) {
|
|
923
|
-
this.oAuth2Service.setReturnUrl(this.router.routerState.snapshot.url);
|
|
924
|
-
this.oAuth2Service.redirectToLogin();
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
return throwError(err);
|
|
929
|
-
}));
|
|
930
|
-
}
|
|
931
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: RedirectToOAuth2LoginInterceptor, deps: [{ token: OAuth2Service }, { token: i1.Router }, { token: DDR_OAUTH2_CONFIG }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
932
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: RedirectToOAuth2LoginInterceptor });
|
|
933
|
-
}
|
|
934
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: RedirectToOAuth2LoginInterceptor, decorators: [{
|
|
935
|
-
type: Injectable
|
|
936
|
-
}], ctorParameters: () => [{ type: OAuth2Service }, { type: i1.Router }, { type: OAuth2Config, decorators: [{
|
|
937
|
-
type: Inject,
|
|
938
|
-
args: [DDR_OAUTH2_CONFIG]
|
|
939
|
-
}] }] });
|
|
940
|
-
|
|
941
|
-
class OAuth2AccessTokenInterceptor {
|
|
942
|
-
oAuth2Service;
|
|
943
|
-
constructor(oAuth2Service) {
|
|
944
|
-
this.oAuth2Service = oAuth2Service;
|
|
945
|
-
}
|
|
946
|
-
/**
|
|
947
|
-
* @override
|
|
948
|
-
*/
|
|
949
|
-
intercept(req, next) {
|
|
950
|
-
const accessTokenString = this.oAuth2Service.getAccessTokenString();
|
|
951
|
-
if (null !== accessTokenString && !this.oAuth2Service.isAccessTokenExpired()) {
|
|
952
|
-
req = req.clone({
|
|
953
|
-
headers: req.headers.set('Authorization', 'Bearer ' + accessTokenString)
|
|
954
|
-
});
|
|
955
|
-
}
|
|
956
|
-
return next.handle(req);
|
|
957
|
-
}
|
|
958
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: OAuth2AccessTokenInterceptor, deps: [{ token: OAuth2Service }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
959
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: OAuth2AccessTokenInterceptor });
|
|
568
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: RedirectToLoginInterceptor, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
569
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: RedirectToLoginInterceptor });
|
|
960
570
|
}
|
|
961
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
571
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: RedirectToLoginInterceptor, decorators: [{
|
|
962
572
|
type: Injectable
|
|
963
|
-
}], ctorParameters: () => [{ type: OAuth2Service }] });
|
|
964
|
-
|
|
965
|
-
class OAuth2Module {
|
|
966
|
-
static forRoot(config) {
|
|
967
|
-
return {
|
|
968
|
-
ngModule: OAuth2Module,
|
|
969
|
-
providers: [
|
|
970
|
-
OAuth2Service,
|
|
971
|
-
{
|
|
972
|
-
provide: DDR_OAUTH2_CONFIG,
|
|
973
|
-
useValue: config
|
|
974
|
-
},
|
|
975
|
-
{
|
|
976
|
-
provide: HTTP_INTERCEPTORS,
|
|
977
|
-
useClass: OAuth2RefreshTokenInterceptor,
|
|
978
|
-
multi: true
|
|
979
|
-
},
|
|
980
|
-
{
|
|
981
|
-
provide: HTTP_INTERCEPTORS,
|
|
982
|
-
useClass: RedirectToOAuth2LoginInterceptor,
|
|
983
|
-
multi: true
|
|
984
|
-
},
|
|
985
|
-
{
|
|
986
|
-
provide: HTTP_INTERCEPTORS,
|
|
987
|
-
useClass: OAuth2AccessTokenInterceptor,
|
|
988
|
-
multi: true
|
|
989
|
-
}
|
|
990
|
-
],
|
|
991
|
-
};
|
|
992
|
-
}
|
|
993
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: OAuth2Module, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
994
|
-
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.0.5", ngImport: i0, type: OAuth2Module });
|
|
995
|
-
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: OAuth2Module });
|
|
996
|
-
}
|
|
997
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: OAuth2Module, decorators: [{
|
|
998
|
-
type: NgModule
|
|
999
573
|
}] });
|
|
1000
574
|
|
|
1001
575
|
function isNonNull(value) {
|
|
1002
576
|
return value != null;
|
|
1003
577
|
}
|
|
1004
578
|
|
|
1005
|
-
class JwtService {
|
|
1006
|
-
storageService;
|
|
1007
|
-
loggerService;
|
|
1008
|
-
/**
|
|
1009
|
-
* The current token.
|
|
1010
|
-
*/
|
|
1011
|
-
token = null;
|
|
1012
|
-
/**
|
|
1013
|
-
* The expiry of the current token.
|
|
1014
|
-
*/
|
|
1015
|
-
tokenExpiry = null;
|
|
1016
|
-
constructor(storageService, loggerService) {
|
|
1017
|
-
this.storageService = storageService;
|
|
1018
|
-
this.loggerService = loggerService;
|
|
1019
|
-
}
|
|
1020
|
-
/**
|
|
1021
|
-
* Sets the current token and a refresh token.
|
|
1022
|
-
*/
|
|
1023
|
-
setTokens(token, refreshToken) {
|
|
1024
|
-
this.setToken(token);
|
|
1025
|
-
this.storageService.store(this.getRefreshTokenStorageKey(), refreshToken);
|
|
1026
|
-
}
|
|
1027
|
-
/**
|
|
1028
|
-
* Sets the current token.
|
|
1029
|
-
*/
|
|
1030
|
-
setToken(token) {
|
|
1031
|
-
this.token = token;
|
|
1032
|
-
const decodedToken = JSON.parse(atob(token.split('.')[1]));
|
|
1033
|
-
this.tokenExpiry = decodedToken.exp * 1000;
|
|
1034
|
-
this.loggerService.info('New refresh token, expiry', new Date(this.tokenExpiry));
|
|
1035
|
-
}
|
|
1036
|
-
/**
|
|
1037
|
-
* Gets the current token.
|
|
1038
|
-
*/
|
|
1039
|
-
getToken() {
|
|
1040
|
-
return this.token;
|
|
1041
|
-
}
|
|
1042
|
-
/**
|
|
1043
|
-
* Gets the refresh token.
|
|
1044
|
-
*/
|
|
1045
|
-
getRefreshToken() {
|
|
1046
|
-
return this.storageService.retrieve(this.getRefreshTokenStorageKey());
|
|
1047
|
-
}
|
|
1048
|
-
/**
|
|
1049
|
-
* Checks if the current token expired.
|
|
1050
|
-
*/
|
|
1051
|
-
isExpired() {
|
|
1052
|
-
const now = new Date().getTime();
|
|
1053
|
-
return null == this.tokenExpiry || this.tokenExpiry < now;
|
|
1054
|
-
}
|
|
1055
|
-
/**
|
|
1056
|
-
* Checks if the current token is about to expire.
|
|
1057
|
-
* @param expiryMs
|
|
1058
|
-
*/
|
|
1059
|
-
isAboutToExpire(expiryMs = 60000) {
|
|
1060
|
-
const now = new Date().getTime();
|
|
1061
|
-
return null == this.tokenExpiry || this.tokenExpiry - expiryMs < now;
|
|
1062
|
-
}
|
|
1063
|
-
/**
|
|
1064
|
-
* Clears all token information.
|
|
1065
|
-
*/
|
|
1066
|
-
clear() {
|
|
1067
|
-
this.token = null;
|
|
1068
|
-
this.tokenExpiry = null;
|
|
1069
|
-
this.storageService.remove(this.getRefreshTokenStorageKey());
|
|
1070
|
-
}
|
|
1071
|
-
getRefreshTokenStorageKey() {
|
|
1072
|
-
return 'jwt.refresh_token';
|
|
1073
|
-
}
|
|
1074
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: JwtService, deps: [{ token: StorageService }, { token: Logger }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1075
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: JwtService, providedIn: 'root' });
|
|
1076
|
-
}
|
|
1077
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: JwtService, decorators: [{
|
|
1078
|
-
type: Injectable,
|
|
1079
|
-
args: [{
|
|
1080
|
-
providedIn: 'root'
|
|
1081
|
-
}]
|
|
1082
|
-
}], ctorParameters: () => [{ type: StorageService }, { type: Logger }] });
|
|
1083
|
-
|
|
1084
|
-
class JwtInterceptor {
|
|
1085
|
-
jwtService;
|
|
1086
|
-
constructor(jwtService) {
|
|
1087
|
-
this.jwtService = jwtService;
|
|
1088
|
-
}
|
|
1089
|
-
/**
|
|
1090
|
-
* @override
|
|
1091
|
-
*/
|
|
1092
|
-
intercept(req, next) {
|
|
1093
|
-
const token = this.jwtService.getToken();
|
|
1094
|
-
if (null !== token && !this.jwtService.isExpired()) {
|
|
1095
|
-
req = req.clone({
|
|
1096
|
-
headers: req.headers.set('Authorization', 'Bearer ' + token)
|
|
1097
|
-
});
|
|
1098
|
-
}
|
|
1099
|
-
return next.handle(req);
|
|
1100
|
-
}
|
|
1101
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: JwtInterceptor, deps: [{ token: JwtService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1102
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: JwtInterceptor });
|
|
1103
|
-
}
|
|
1104
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: JwtInterceptor, decorators: [{
|
|
1105
|
-
type: Injectable
|
|
1106
|
-
}], ctorParameters: () => [{ type: JwtService }] });
|
|
1107
|
-
|
|
1108
|
-
class JwtRefreshTokenInterceptor {
|
|
1109
|
-
jwtService;
|
|
1110
|
-
httpClient;
|
|
1111
|
-
jwtRefreshTokenUrl;
|
|
1112
|
-
refreshTokenRequest$ = null;
|
|
1113
|
-
constructor(jwtService, httpClient, jwtRefreshTokenUrl) {
|
|
1114
|
-
this.jwtService = jwtService;
|
|
1115
|
-
this.httpClient = httpClient;
|
|
1116
|
-
this.jwtRefreshTokenUrl = jwtRefreshTokenUrl;
|
|
1117
|
-
}
|
|
1118
|
-
/**
|
|
1119
|
-
* @override
|
|
1120
|
-
*/
|
|
1121
|
-
intercept(req, next) {
|
|
1122
|
-
if (this.jwtService.isAboutToExpire() && !(req.url === this.jwtRefreshTokenUrl)) {
|
|
1123
|
-
const refreshToken = this.jwtService.getRefreshToken();
|
|
1124
|
-
if (null != refreshToken) {
|
|
1125
|
-
return this.getRefreshTokenRequest(refreshToken).pipe(switchMap(() => next.handle(req)));
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
return next.handle(req);
|
|
1129
|
-
}
|
|
1130
|
-
getRefreshTokenRequest(refreshToken) {
|
|
1131
|
-
if (null == this.refreshTokenRequest$) {
|
|
1132
|
-
this.refreshTokenRequest$ = this.httpClient.post(this.jwtRefreshTokenUrl, { refresh_token: refreshToken }).pipe(map(response => {
|
|
1133
|
-
this.jwtService.setTokens(response.token, response.refresh_token);
|
|
1134
|
-
this.refreshTokenRequest$ = null;
|
|
1135
|
-
return response;
|
|
1136
|
-
}), catchError(error => {
|
|
1137
|
-
this.jwtService.clear();
|
|
1138
|
-
this.refreshTokenRequest$ = null;
|
|
1139
|
-
return throwError(error);
|
|
1140
|
-
}), shareReplay(1));
|
|
1141
|
-
}
|
|
1142
|
-
return this.refreshTokenRequest$;
|
|
1143
|
-
}
|
|
1144
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: JwtRefreshTokenInterceptor, deps: [{ token: JwtService }, { token: i2$1.HttpClient }, { token: DDR_JWT_REFRESH_TOKEN_URL }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1145
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: JwtRefreshTokenInterceptor });
|
|
1146
|
-
}
|
|
1147
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: JwtRefreshTokenInterceptor, decorators: [{
|
|
1148
|
-
type: Injectable
|
|
1149
|
-
}], ctorParameters: () => [{ type: JwtService }, { type: i2$1.HttpClient }, { type: undefined, decorators: [{
|
|
1150
|
-
type: Inject,
|
|
1151
|
-
args: [DDR_JWT_REFRESH_TOKEN_URL]
|
|
1152
|
-
}] }] });
|
|
1153
|
-
|
|
1154
579
|
/*
|
|
1155
580
|
* Public API Surface of ngx-extensions
|
|
1156
581
|
*/
|
|
@@ -1159,5 +584,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImpor
|
|
|
1159
584
|
* Generated bundle index. Do not edit.
|
|
1160
585
|
*/
|
|
1161
586
|
|
|
1162
|
-
export { BottomHitDirective, CollectionUtils, CookieService,
|
|
587
|
+
export { BottomHitDirective, CollectionUtils, CookieService, DDR_LOGIN_PATH, DDR_STORAGE_PREFIX, DdrExtensionsModule, Debounce, Limit, NumberUtils, ObjectUtils, RedirectToLoginInterceptor, ScrollService, StorageService, StringUtils, TypeUtils, UrlInfo, VisibilityService, WithCredentialsInterceptor, isNonNull };
|
|
1163
588
|
//# sourceMappingURL=dontdrinkandroot-ngx-extensions.mjs.map
|