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