@dontdrinkandroot/ngx-extensions 0.2.0 → 0.2.2

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 (46) hide show
  1. package/esm2020/public-api.mjs +5 -1
  2. package/esm2020/src/cookie/cookie.service.mjs +4 -4
  3. package/esm2020/src/ddr-extensions.module.mjs +35 -8
  4. package/esm2020/src/http/redirect-to-login-interceptor.service.mjs +4 -4
  5. package/esm2020/src/http/with-credentials-interceptor.service.mjs +4 -4
  6. package/esm2020/src/image/lazy-image.directive.mjs +4 -4
  7. package/esm2020/src/jwt/jwt-interceptor.service.mjs +4 -4
  8. package/esm2020/src/jwt/jwt-refresh-token-interceptor.service.mjs +4 -4
  9. package/esm2020/src/jwt/jwt.service.mjs +13 -16
  10. package/esm2020/src/logger/console-logger.service.mjs +43 -0
  11. package/esm2020/src/logger/logger.service.mjs +9 -0
  12. package/esm2020/src/oauth/json-web-token.mjs +2 -0
  13. package/esm2020/src/oauth/oauth2-access-token-interceptor.service.mjs +26 -0
  14. package/esm2020/src/oauth/oauth2-config.mjs +11 -0
  15. package/esm2020/src/oauth/oauth2-error.mjs +8 -0
  16. package/esm2020/src/oauth/oauth2-refresh-token-interceptor.service.mjs +24 -0
  17. package/esm2020/src/oauth/oauth2.module.mjs +44 -0
  18. package/esm2020/src/oauth/oauth2.service.mjs +119 -0
  19. package/esm2020/src/oauth/redirect-to-oauth2-login-interceptor.service.mjs +41 -0
  20. package/esm2020/src/oauth/token-response.mjs +2 -0
  21. package/esm2020/src/scroll/bottom-hit.directive.mjs +4 -4
  22. package/esm2020/src/scroll/scroll.service.mjs +4 -4
  23. package/esm2020/src/storage/local-storage.service.mjs +53 -0
  24. package/esm2020/src/storage/storage.service.mjs +5 -0
  25. package/esm2020/src/visibility/visibility.service.mjs +4 -4
  26. package/fesm2015/dontdrinkandroot-ngx-extensions.mjs +414 -52
  27. package/fesm2015/dontdrinkandroot-ngx-extensions.mjs.map +1 -1
  28. package/fesm2020/dontdrinkandroot-ngx-extensions.mjs +408 -50
  29. package/fesm2020/dontdrinkandroot-ngx-extensions.mjs.map +1 -1
  30. package/package.json +1 -1
  31. package/public-api.d.ts +4 -0
  32. package/src/ddr-extensions.module.d.ts +0 -1
  33. package/src/jwt/jwt.service.d.ts +3 -2
  34. package/src/logger/console-logger.service.d.ts +22 -0
  35. package/src/logger/logger.service.d.ts +10 -0
  36. package/src/oauth/json-web-token.d.ts +30 -0
  37. package/src/oauth/oauth2-access-token-interceptor.service.d.ts +14 -0
  38. package/src/oauth/oauth2-config.d.ts +9 -0
  39. package/src/oauth/oauth2-error.d.ts +5 -0
  40. package/src/oauth/oauth2-refresh-token-interceptor.service.d.ts +14 -0
  41. package/src/oauth/oauth2.module.d.ts +9 -0
  42. package/src/oauth/oauth2.service.d.ts +33 -0
  43. package/src/oauth/redirect-to-oauth2-login-interceptor.service.d.ts +18 -0
  44. package/src/oauth/token-response.d.ts +6 -0
  45. package/src/storage/local-storage.service.d.ts +23 -0
  46. package/src/storage/storage.service.d.ts +7 -0
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Directive, Input, HostBinding, HostListener, EventEmitter, Output, InjectionToken, NgModule, Injectable, Inject } from '@angular/core';
2
+ import { Directive, Input, HostBinding, HostListener, EventEmitter, Output, Injectable, InjectionToken, Inject, NgModule } from '@angular/core';
3
3
  import { __decorate } from 'tslib';
4
4
  import * as i2 from '@angular/common';
5
5
  import { DOCUMENT } from '@angular/common';
@@ -8,7 +8,7 @@ import { NavigationStart } from '@angular/router';
8
8
  import { merge, fromEvent, throwError } from 'rxjs';
9
9
  import { debounceTime, startWith, map, distinctUntilChanged, shareReplay, catchError, switchMap } from 'rxjs/operators';
10
10
  import * as i2$1 from '@angular/common/http';
11
- import { HttpErrorResponse } from '@angular/common/http';
11
+ import { HttpErrorResponse, HttpParams, HTTP_INTERCEPTORS } from '@angular/common/http';
12
12
 
13
13
  class NumberUtils {
14
14
  static getNextPowerOfTwo(value) {
@@ -171,15 +171,15 @@ class LazyImageDirective {
171
171
  return window.getComputedStyle(element).display === 'none';
172
172
  }
173
173
  }
174
- LazyImageDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: LazyImageDirective, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
175
- LazyImageDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.2", 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 });
174
+ LazyImageDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: LazyImageDirective, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
175
+ LazyImageDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.12", 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 });
176
176
  __decorate([
177
177
  Debounce()
178
178
  ], LazyImageDirective.prototype, "windowResized", null);
179
179
  __decorate([
180
180
  Limit()
181
181
  ], LazyImageDirective.prototype, "windowScroll", null);
182
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: LazyImageDirective, decorators: [{
182
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: LazyImageDirective, decorators: [{
183
183
  type: Directive,
184
184
  args: [{ selector: '[ddrLazyImage]' }]
185
185
  }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { src: [{
@@ -240,15 +240,15 @@ class BottomHitDirective {
240
240
  }
241
241
  }
242
242
  }
243
- BottomHitDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: BottomHitDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
244
- BottomHitDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.2", type: BottomHitDirective, selector: "[ddrBottomHit]", outputs: { onWindowBottomHit: "onWindowBottomHit", onElementBottomHit: "onElementBottomHit" }, host: { listeners: { "scroll": "scrolled($event)", "window:scroll": "windowScrolled($event)" } }, ngImport: i0 });
243
+ BottomHitDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: BottomHitDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
244
+ BottomHitDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.12", type: BottomHitDirective, selector: "[ddrBottomHit]", outputs: { onWindowBottomHit: "onWindowBottomHit", onElementBottomHit: "onElementBottomHit" }, host: { listeners: { "scroll": "scrolled($event)", "window:scroll": "windowScrolled($event)" } }, ngImport: i0 });
245
245
  __decorate([
246
246
  Limit()
247
247
  ], BottomHitDirective.prototype, "scrolled", null);
248
248
  __decorate([
249
249
  Limit()
250
250
  ], BottomHitDirective.prototype, "windowScrolled", null);
251
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: BottomHitDirective, decorators: [{
251
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: BottomHitDirective, decorators: [{
252
252
  type: Directive,
253
253
  args: [{
254
254
  selector: '[ddrBottomHit]'
@@ -265,22 +265,135 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImpor
265
265
  args: ['window:scroll', ['$event']]
266
266
  }] } });
267
267
 
268
- const DDR_STORAGE_PREFIX = new InjectionToken('DDR_STORAGE_PREFIX');
268
+ class LoggerService {
269
+ constructor() {
270
+ this.debugEnabled = false;
271
+ this.infoEnabled = true;
272
+ this.warnEnabled = true;
273
+ this.errorEnabled = true;
274
+ }
275
+ }
276
+
277
+ class ConsoleLoggerService extends LoggerService {
278
+ /**
279
+ * @override
280
+ */
281
+ debug(message, ...optionalParams) {
282
+ if (this.debugEnabled) {
283
+ console.debug(message, optionalParams);
284
+ }
285
+ }
286
+ /**
287
+ * @override
288
+ */
289
+ info(message, ...optionalParams) {
290
+ if (this.infoEnabled) {
291
+ console.info(message, optionalParams);
292
+ }
293
+ }
294
+ /**
295
+ * @override
296
+ */
297
+ warn(message, ...optionalParams) {
298
+ if (this.warnEnabled) {
299
+ console.warn(message, optionalParams);
300
+ }
301
+ }
302
+ /**
303
+ * @override
304
+ */
305
+ error(message, ...optionalParams) {
306
+ if (this.errorEnabled) {
307
+ console.error(message, optionalParams);
308
+ }
309
+ }
310
+ }
311
+ ConsoleLoggerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: ConsoleLoggerService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
312
+ ConsoleLoggerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: ConsoleLoggerService });
313
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: ConsoleLoggerService, decorators: [{
314
+ type: Injectable
315
+ }] });
316
+
317
+ const DDR_STORAGE_PREFIX = new InjectionToken('storage-prefix');
318
+ class StorageService {
319
+ }
320
+
321
+ class LocalStorageService extends StorageService {
322
+ constructor(storagePrefix, logger) {
323
+ super();
324
+ this.storagePrefix = storagePrefix;
325
+ this.logger = logger;
326
+ }
327
+ /**
328
+ * @override
329
+ */
330
+ retrieve(key, defaultValue = null) {
331
+ let fullKey = this.getFullKey(key);
332
+ let valueJson = localStorage.getItem(fullKey);
333
+ if (null == valueJson) {
334
+ return defaultValue;
335
+ }
336
+ try {
337
+ return JSON.parse(valueJson);
338
+ }
339
+ catch (e) {
340
+ this.logger.warn('Could not parse json value', valueJson, e);
341
+ localStorage.removeItem(fullKey);
342
+ return null;
343
+ }
344
+ }
345
+ /**
346
+ * @override
347
+ */
348
+ store(key, value) {
349
+ localStorage.setItem(this.getFullKey(key), JSON.stringify(value));
350
+ }
351
+ /**
352
+ * @override
353
+ */
354
+ remove(key) {
355
+ localStorage.removeItem(this.getFullKey(key));
356
+ }
357
+ getFullKey(key) {
358
+ return this.storagePrefix + '.' + key;
359
+ }
360
+ }
361
+ LocalStorageService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: LocalStorageService, deps: [{ token: DDR_STORAGE_PREFIX }, { token: LoggerService }], target: i0.ɵɵFactoryTarget.Injectable });
362
+ LocalStorageService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: LocalStorageService });
363
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: LocalStorageService, decorators: [{
364
+ type: Injectable
365
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
366
+ type: Inject,
367
+ args: [DDR_STORAGE_PREFIX]
368
+ }] }, { type: LoggerService }]; } });
369
+
269
370
  const DDR_JWT_REFRESH_TOKEN_URL = new InjectionToken('DDR_JWT_REFRESH_TOKEN_URL');
270
371
  const DDR_LOGIN_PATH = new InjectionToken('DDR_LOGIN_PATH');
271
372
  class DdrExtensionsModule {
272
373
  }
273
- DdrExtensionsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: DdrExtensionsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
274
- DdrExtensionsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.2", ngImport: i0, type: DdrExtensionsModule, declarations: [LazyImageDirective,
374
+ DdrExtensionsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: DdrExtensionsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
375
+ DdrExtensionsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.12", ngImport: i0, type: DdrExtensionsModule, declarations: [LazyImageDirective,
275
376
  BottomHitDirective], exports: [LazyImageDirective,
276
377
  BottomHitDirective] });
277
- DdrExtensionsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: DdrExtensionsModule, providers: [
378
+ DdrExtensionsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: DdrExtensionsModule, providers: [
278
379
  {
279
380
  provide: DDR_LOGIN_PATH,
280
381
  useValue: '/login'
281
- }
382
+ },
383
+ {
384
+ provide: LoggerService,
385
+ useClass: ConsoleLoggerService
386
+ },
387
+ {
388
+ provide: DDR_STORAGE_PREFIX,
389
+ useValue: 'ddr'
390
+ },
391
+ {
392
+ provide: StorageService,
393
+ useClass: LocalStorageService
394
+ },
282
395
  ] });
283
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: DdrExtensionsModule, decorators: [{
396
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: DdrExtensionsModule, decorators: [{
284
397
  type: NgModule,
285
398
  args: [{
286
399
  declarations: [
@@ -292,7 +405,19 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImpor
292
405
  {
293
406
  provide: DDR_LOGIN_PATH,
294
407
  useValue: '/login'
295
- }
408
+ },
409
+ {
410
+ provide: LoggerService,
411
+ useClass: ConsoleLoggerService
412
+ },
413
+ {
414
+ provide: DDR_STORAGE_PREFIX,
415
+ useValue: 'ddr'
416
+ },
417
+ {
418
+ provide: StorageService,
419
+ useClass: LocalStorageService
420
+ },
296
421
  ],
297
422
  exports: [
298
423
  LazyImageDirective,
@@ -419,9 +544,9 @@ class CookieService {
419
544
  return new RegExp('(?:^' + escapedName + '|;\\s*' + escapedName + ')=(.*?)(?:;|$)', 'g');
420
545
  }
421
546
  }
422
- CookieService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: CookieService, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
423
- CookieService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: CookieService, providedIn: 'root' });
424
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: CookieService, decorators: [{
547
+ CookieService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: CookieService, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
548
+ CookieService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: CookieService, providedIn: 'root' });
549
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: CookieService, decorators: [{
425
550
  type: Injectable,
426
551
  args: [{
427
552
  providedIn: 'root'
@@ -499,9 +624,9 @@ class ScrollService {
499
624
  }
500
625
  }
501
626
  }
502
- ScrollService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: ScrollService, deps: [{ token: i1.Router }, { token: i2.ViewportScroller }], target: i0.ɵɵFactoryTarget.Injectable });
503
- ScrollService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: ScrollService, providedIn: 'root' });
504
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: ScrollService, decorators: [{
627
+ ScrollService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: ScrollService, deps: [{ token: i1.Router }, { token: i2.ViewportScroller }], target: i0.ɵɵFactoryTarget.Injectable });
628
+ ScrollService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: ScrollService, providedIn: 'root' });
629
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: ScrollService, decorators: [{
505
630
  type: Injectable,
506
631
  args: [{
507
632
  providedIn: 'root'
@@ -516,9 +641,9 @@ class VisibilityService {
516
641
  return this.visibility$;
517
642
  }
518
643
  }
519
- VisibilityService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: VisibilityService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
520
- VisibilityService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: VisibilityService, providedIn: 'root' });
521
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: VisibilityService, decorators: [{
644
+ VisibilityService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: VisibilityService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
645
+ VisibilityService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: VisibilityService, providedIn: 'root' });
646
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: VisibilityService, decorators: [{
522
647
  type: Injectable,
523
648
  args: [{ providedIn: 'root' }]
524
649
  }], ctorParameters: function () { return []; } });
@@ -534,9 +659,9 @@ class WithCredentialsInterceptor {
534
659
  return next.handle(cloned);
535
660
  }
536
661
  }
537
- WithCredentialsInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: WithCredentialsInterceptor, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
538
- WithCredentialsInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: WithCredentialsInterceptor });
539
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: WithCredentialsInterceptor, decorators: [{
662
+ WithCredentialsInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WithCredentialsInterceptor, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
663
+ WithCredentialsInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WithCredentialsInterceptor });
664
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WithCredentialsInterceptor, decorators: [{
540
665
  type: Injectable
541
666
  }] });
542
667
 
@@ -585,18 +710,254 @@ class RedirectToLoginInterceptor {
585
710
  }));
586
711
  }
587
712
  }
588
- RedirectToLoginInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: RedirectToLoginInterceptor, deps: [{ token: i1.Router }, { token: DDR_LOGIN_PATH }], target: i0.ɵɵFactoryTarget.Injectable });
589
- RedirectToLoginInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: RedirectToLoginInterceptor });
590
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: RedirectToLoginInterceptor, decorators: [{
713
+ RedirectToLoginInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: RedirectToLoginInterceptor, deps: [{ token: i1.Router }, { token: DDR_LOGIN_PATH }], target: i0.ɵɵFactoryTarget.Injectable });
714
+ RedirectToLoginInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: RedirectToLoginInterceptor });
715
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: RedirectToLoginInterceptor, decorators: [{
591
716
  type: Injectable
592
717
  }], ctorParameters: function () { return [{ type: i1.Router }, { type: undefined, decorators: [{
593
718
  type: Inject,
594
719
  args: [DDR_LOGIN_PATH]
595
720
  }] }]; } });
596
721
 
722
+ const DDR_OAUTH2_CONFIG = new InjectionToken('DDR_OAUTH2_CONFIG');
723
+ class OAuth2Config {
724
+ constructor(clientId, redirectUri, authorizeUri, tokenUri) {
725
+ this.clientId = clientId;
726
+ this.redirectUri = redirectUri;
727
+ this.authorizeUri = authorizeUri;
728
+ this.tokenUri = tokenUri;
729
+ }
730
+ }
731
+
732
+ class OAuth2Error extends Error {
733
+ constructor(error) {
734
+ super(error);
735
+ }
736
+ }
737
+ OAuth2Error.CODE_NOT_FOUND = 'code_not_found';
738
+ OAuth2Error.ACCESS_DENIED = 'access_denied';
739
+
740
+ class OAuth2Service {
741
+ constructor(route, httpClient, config) {
742
+ this.route = route;
743
+ this.httpClient = httpClient;
744
+ this.config = config;
745
+ this.accessTokenString = null;
746
+ this.accessToken = null;
747
+ this.REFRESH_MARGIN_SECONDS = 60 * 10;
748
+ this.refreshTokenRequest$ = null;
749
+ }
750
+ redirectToLogin() {
751
+ const challenge = this.createChallenge();
752
+ localStorage.setItem(OAuth2Service.STORAGE_KEY_CHALLENGE, challenge);
753
+ const params = new HttpParams()
754
+ .set('client_id', this.config.clientId)
755
+ .set('response_type', 'code')
756
+ .set('redirect_uri', this.config.redirectUri)
757
+ .set('code_challenge', challenge)
758
+ .set('code_challenge_method', 'plain');
759
+ window.location.href = this.config.authorizeUri + '?' + params.toString();
760
+ }
761
+ handleCode() {
762
+ if (this.route.snapshot.queryParamMap.has('error')) {
763
+ const error = this.route.snapshot.queryParamMap.get('error');
764
+ return throwError(() => new OAuth2Error(error ?? 'Unknown error'));
765
+ }
766
+ if (!this.route.snapshot.queryParamMap.has('code')) {
767
+ return throwError(() => new OAuth2Error(OAuth2Error.CODE_NOT_FOUND));
768
+ }
769
+ const code = TypeUtils.notNull(this.route.snapshot.queryParamMap.get('code'));
770
+ const params = new HttpParams()
771
+ .set('grant_type', 'authorization_code')
772
+ .set('code', code)
773
+ .set('redirect_uri', this.config.redirectUri)
774
+ .set('code_verifier', TypeUtils.notNull(localStorage.getItem(OAuth2Service.STORAGE_KEY_CHALLENGE)))
775
+ .set('client_id', this.config.clientId);
776
+ return this.httpClient.post(this.config.tokenUri, params).pipe(map(tokenResponse => this.processTokenResponse(tokenResponse)));
777
+ }
778
+ createChallenge() {
779
+ return StringUtils.createRandomString(64, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-._~');
780
+ }
781
+ getRefreshToken() {
782
+ return localStorage.getItem(OAuth2Service.STORAGE_KEY_REFRESH_TOKEN);
783
+ }
784
+ getAccessTokenString() {
785
+ return this.accessTokenString;
786
+ }
787
+ isAccessTokenExpired() {
788
+ return (null == this.accessToken
789
+ || this.accessToken.exp * 1000 < Date.now());
790
+ }
791
+ isRefreshPossibleAndRequired(req = null) {
792
+ return ((null == req || !req.url.endsWith(this.config.tokenUri))
793
+ && null != this.getRefreshToken()
794
+ && (null == this.accessToken
795
+ || (this.accessToken.exp - this.REFRESH_MARGIN_SECONDS) * 1000 < Date.now()));
796
+ }
797
+ performRefresh() {
798
+ if (null == this.refreshTokenRequest$) {
799
+ console.log('Performing token refesh');
800
+ const params = new HttpParams()
801
+ .set('grant_type', 'refresh_token')
802
+ .set('refresh_token', TypeUtils.notNull(this.getRefreshToken()))
803
+ .set('client_id', this.config.clientId);
804
+ this.refreshTokenRequest$ = this.httpClient.post(this.config.tokenUri, params).pipe(map(tokenResponse => this.processTokenResponse(tokenResponse)), catchError(error => {
805
+ this.accessTokenString = null;
806
+ this.accessToken = null;
807
+ localStorage.removeItem(OAuth2Service.STORAGE_KEY_REFRESH_TOKEN);
808
+ this.refreshTokenRequest$ = null;
809
+ return throwError(error);
810
+ }), shareReplay(1));
811
+ }
812
+ return this.refreshTokenRequest$;
813
+ }
814
+ processTokenResponse(tokenResponse) {
815
+ localStorage.removeItem(OAuth2Service.STORAGE_KEY_CHALLENGE);
816
+ this.accessTokenString = tokenResponse.access_token;
817
+ this.accessToken = JSON.parse(atob(tokenResponse.access_token.split('.')[1]));
818
+ console.log('Access Token Expiry', new Date(this.accessToken.exp * 1000));
819
+ localStorage.setItem(OAuth2Service.STORAGE_KEY_REFRESH_TOKEN, tokenResponse.refresh_token);
820
+ return this.accessToken;
821
+ }
822
+ clear() {
823
+ this.accessToken = null;
824
+ this.accessTokenString = null;
825
+ localStorage.removeItem(OAuth2Service.STORAGE_KEY_REFRESH_TOKEN);
826
+ localStorage.removeItem(OAuth2Service.STORAGE_KEY_RETURN_URL);
827
+ }
828
+ setReturnUrl(url) {
829
+ localStorage.setItem(OAuth2Service.STORAGE_KEY_RETURN_URL, url);
830
+ }
831
+ getReturnUrl() {
832
+ return localStorage.getItem(OAuth2Service.STORAGE_KEY_RETURN_URL);
833
+ }
834
+ }
835
+ OAuth2Service.STORAGE_KEY_CHALLENGE = 'ddr_oauth2_challenge';
836
+ OAuth2Service.STORAGE_KEY_REFRESH_TOKEN = 'ddr_oauth2_refresh_token';
837
+ OAuth2Service.STORAGE_KEY_RETURN_URL = 'ddr_oauth2_return_url';
838
+ OAuth2Service.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2Service, deps: [{ token: i1.ActivatedRoute }, { token: i2$1.HttpClient }, { token: DDR_OAUTH2_CONFIG }], target: i0.ɵɵFactoryTarget.Injectable });
839
+ OAuth2Service.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2Service });
840
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2Service, decorators: [{
841
+ type: Injectable
842
+ }], ctorParameters: function () { return [{ type: i1.ActivatedRoute }, { type: i2$1.HttpClient }, { type: OAuth2Config, decorators: [{
843
+ type: Inject,
844
+ args: [DDR_OAUTH2_CONFIG]
845
+ }] }]; } });
846
+
847
+ class OAuth2RefreshTokenInterceptor {
848
+ constructor(oAuth2Service) {
849
+ this.oAuth2Service = oAuth2Service;
850
+ }
851
+ /**
852
+ * @override
853
+ */
854
+ intercept(req, next) {
855
+ if (this.oAuth2Service.isRefreshPossibleAndRequired(req)) {
856
+ return this.oAuth2Service.performRefresh().pipe(switchMap(() => next.handle(req)));
857
+ }
858
+ return next.handle(req);
859
+ }
860
+ }
861
+ OAuth2RefreshTokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2RefreshTokenInterceptor, deps: [{ token: OAuth2Service }], target: i0.ɵɵFactoryTarget.Injectable });
862
+ OAuth2RefreshTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2RefreshTokenInterceptor });
863
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2RefreshTokenInterceptor, decorators: [{
864
+ type: Injectable
865
+ }], ctorParameters: function () { return [{ type: OAuth2Service }]; } });
866
+
867
+ class RedirectToOAuth2LoginInterceptor {
868
+ constructor(oAuth2Service, router, oAuth2Config) {
869
+ this.oAuth2Service = oAuth2Service;
870
+ this.router = router;
871
+ this.oAuth2Config = oAuth2Config;
872
+ }
873
+ /**
874
+ * @override
875
+ */
876
+ intercept(req, next) {
877
+ return next.handle(req).pipe(catchError((err) => {
878
+ if (err instanceof HttpErrorResponse) {
879
+ if (err.status === 401) {
880
+ if (!window.location.href.startsWith(this.oAuth2Config.redirectUri)) {
881
+ this.oAuth2Service.setReturnUrl(this.router.routerState.snapshot.url);
882
+ this.oAuth2Service.redirectToLogin();
883
+ }
884
+ }
885
+ }
886
+ return throwError(err);
887
+ }));
888
+ }
889
+ }
890
+ RedirectToOAuth2LoginInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: RedirectToOAuth2LoginInterceptor, deps: [{ token: OAuth2Service }, { token: i1.Router }, { token: DDR_OAUTH2_CONFIG }], target: i0.ɵɵFactoryTarget.Injectable });
891
+ RedirectToOAuth2LoginInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: RedirectToOAuth2LoginInterceptor });
892
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: RedirectToOAuth2LoginInterceptor, decorators: [{
893
+ type: Injectable
894
+ }], ctorParameters: function () { return [{ type: OAuth2Service }, { type: i1.Router }, { type: OAuth2Config, decorators: [{
895
+ type: Inject,
896
+ args: [DDR_OAUTH2_CONFIG]
897
+ }] }]; } });
898
+
899
+ class OAuth2AccessTokenInterceptor {
900
+ constructor(oAuth2Service) {
901
+ this.oAuth2Service = oAuth2Service;
902
+ }
903
+ /**
904
+ * @override
905
+ */
906
+ intercept(req, next) {
907
+ const accessTokenString = this.oAuth2Service.getAccessTokenString();
908
+ if (null !== accessTokenString && !this.oAuth2Service.isAccessTokenExpired()) {
909
+ req = req.clone({
910
+ headers: req.headers.set('Authorization', 'Bearer ' + accessTokenString)
911
+ });
912
+ }
913
+ return next.handle(req);
914
+ }
915
+ }
916
+ OAuth2AccessTokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2AccessTokenInterceptor, deps: [{ token: OAuth2Service }], target: i0.ɵɵFactoryTarget.Injectable });
917
+ OAuth2AccessTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2AccessTokenInterceptor });
918
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2AccessTokenInterceptor, decorators: [{
919
+ type: Injectable
920
+ }], ctorParameters: function () { return [{ type: OAuth2Service }]; } });
921
+
922
+ class OAuth2Module {
923
+ static forRoot(config) {
924
+ return {
925
+ ngModule: OAuth2Module,
926
+ providers: [
927
+ OAuth2Service,
928
+ {
929
+ provide: DDR_OAUTH2_CONFIG,
930
+ useValue: config
931
+ },
932
+ {
933
+ provide: HTTP_INTERCEPTORS,
934
+ useClass: OAuth2RefreshTokenInterceptor,
935
+ multi: true
936
+ },
937
+ {
938
+ provide: HTTP_INTERCEPTORS,
939
+ useClass: RedirectToOAuth2LoginInterceptor,
940
+ multi: true
941
+ },
942
+ {
943
+ provide: HTTP_INTERCEPTORS,
944
+ useClass: OAuth2AccessTokenInterceptor,
945
+ multi: true
946
+ }
947
+ ],
948
+ };
949
+ }
950
+ }
951
+ OAuth2Module.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2Module, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
952
+ OAuth2Module.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.12", ngImport: i0, type: OAuth2Module });
953
+ OAuth2Module.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2Module });
954
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2Module, decorators: [{
955
+ type: NgModule
956
+ }] });
957
+
597
958
  class JwtService {
598
- constructor(storagePrefix) {
599
- this.storagePrefix = storagePrefix;
959
+ constructor(storageService) {
960
+ this.storageService = storageService;
600
961
  /**
601
962
  * The current token.
602
963
  */
@@ -611,7 +972,7 @@ class JwtService {
611
972
  */
612
973
  setTokens(token, refreshToken) {
613
974
  this.setToken(token);
614
- localStorage.setItem(this.getRefreshTokenStorageKey(), refreshToken);
975
+ this.storageService.store(this.getRefreshTokenStorageKey(), refreshToken);
615
976
  }
616
977
  /**
617
978
  * Sets the current token.
@@ -632,7 +993,7 @@ class JwtService {
632
993
  * Gets the refresh token.
633
994
  */
634
995
  getRefreshToken() {
635
- return localStorage.getItem(this.getRefreshTokenStorageKey());
996
+ return this.storageService.retrieve(this.getRefreshTokenStorageKey());
636
997
  }
637
998
  /**
638
999
  * Checks if the current token expired.
@@ -655,23 +1016,20 @@ class JwtService {
655
1016
  clear() {
656
1017
  this.token = null;
657
1018
  this.tokenExpiry = null;
658
- localStorage.removeItem(this.getRefreshTokenStorageKey());
1019
+ this.storageService.remove(this.getRefreshTokenStorageKey());
659
1020
  }
660
1021
  getRefreshTokenStorageKey() {
661
- return this.storagePrefix + '.jwt.refresh_token';
1022
+ return 'jwt.refresh_token';
662
1023
  }
663
1024
  }
664
- JwtService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: JwtService, deps: [{ token: DDR_STORAGE_PREFIX }], target: i0.ɵɵFactoryTarget.Injectable });
665
- JwtService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: JwtService, providedIn: 'root' });
666
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: JwtService, decorators: [{
1025
+ JwtService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: JwtService, deps: [{ token: StorageService }], target: i0.ɵɵFactoryTarget.Injectable });
1026
+ JwtService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: JwtService, providedIn: 'root' });
1027
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: JwtService, decorators: [{
667
1028
  type: Injectable,
668
1029
  args: [{
669
1030
  providedIn: 'root'
670
1031
  }]
671
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
672
- type: Inject,
673
- args: [DDR_STORAGE_PREFIX]
674
- }] }]; } });
1032
+ }], ctorParameters: function () { return [{ type: StorageService }]; } });
675
1033
 
676
1034
  class JwtInterceptor {
677
1035
  constructor(jwtService) {
@@ -690,9 +1048,9 @@ class JwtInterceptor {
690
1048
  return next.handle(req);
691
1049
  }
692
1050
  }
693
- JwtInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: JwtInterceptor, deps: [{ token: JwtService }], target: i0.ɵɵFactoryTarget.Injectable });
694
- JwtInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: JwtInterceptor });
695
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: JwtInterceptor, decorators: [{
1051
+ JwtInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: JwtInterceptor, deps: [{ token: JwtService }], target: i0.ɵɵFactoryTarget.Injectable });
1052
+ JwtInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: JwtInterceptor });
1053
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: JwtInterceptor, decorators: [{
696
1054
  type: Injectable
697
1055
  }], ctorParameters: function () { return [{ type: JwtService }]; } });
698
1056
 
@@ -730,9 +1088,9 @@ class JwtRefreshTokenInterceptor {
730
1088
  return this.refreshTokenRequest$;
731
1089
  }
732
1090
  }
733
- JwtRefreshTokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: JwtRefreshTokenInterceptor, deps: [{ token: JwtService }, { token: i2$1.HttpClient }, { token: DDR_JWT_REFRESH_TOKEN_URL }], target: i0.ɵɵFactoryTarget.Injectable });
734
- JwtRefreshTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: JwtRefreshTokenInterceptor });
735
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: JwtRefreshTokenInterceptor, decorators: [{
1091
+ JwtRefreshTokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: JwtRefreshTokenInterceptor, deps: [{ token: JwtService }, { token: i2$1.HttpClient }, { token: DDR_JWT_REFRESH_TOKEN_URL }], target: i0.ɵɵFactoryTarget.Injectable });
1092
+ JwtRefreshTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: JwtRefreshTokenInterceptor });
1093
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: JwtRefreshTokenInterceptor, decorators: [{
736
1094
  type: Injectable
737
1095
  }], ctorParameters: function () { return [{ type: JwtService }, { type: i2$1.HttpClient }, { type: undefined, decorators: [{
738
1096
  type: Inject,
@@ -747,5 +1105,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImpor
747
1105
  * Generated bundle index. Do not edit.
748
1106
  */
749
1107
 
750
- export { BottomHitDirective, CollectionUtils, CookieService, DDR_JWT_REFRESH_TOKEN_URL, DDR_LOGIN_PATH, DDR_STORAGE_PREFIX, DdrExtensionsModule, Debounce, JwtInterceptor, JwtRefreshTokenInterceptor, JwtService, LazyImageDirective, Limit, NumberUtils, ObjectUtils, RedirectToLoginInterceptor, ScrollService, StringUtils, TypeUtils, UrlInfo, VisibilityService, WithCredentialsInterceptor };
1108
+ 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 };
751
1109
  //# sourceMappingURL=dontdrinkandroot-ngx-extensions.mjs.map