@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,137 @@ 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 () {
366
+ return [{ type: undefined, decorators: [{
367
+ type: Inject,
368
+ args: [DDR_STORAGE_PREFIX]
369
+ }] }, { type: LoggerService }];
370
+ } });
371
+
269
372
  const DDR_JWT_REFRESH_TOKEN_URL = new InjectionToken('DDR_JWT_REFRESH_TOKEN_URL');
270
373
  const DDR_LOGIN_PATH = new InjectionToken('DDR_LOGIN_PATH');
271
374
  class DdrExtensionsModule {
272
375
  }
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,
376
+ DdrExtensionsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: DdrExtensionsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
377
+ DdrExtensionsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.12", ngImport: i0, type: DdrExtensionsModule, declarations: [LazyImageDirective,
275
378
  BottomHitDirective], exports: [LazyImageDirective,
276
379
  BottomHitDirective] });
277
- DdrExtensionsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: DdrExtensionsModule, providers: [
380
+ DdrExtensionsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: DdrExtensionsModule, providers: [
278
381
  {
279
382
  provide: DDR_LOGIN_PATH,
280
383
  useValue: '/login'
281
- }
384
+ },
385
+ {
386
+ provide: LoggerService,
387
+ useClass: ConsoleLoggerService
388
+ },
389
+ {
390
+ provide: DDR_STORAGE_PREFIX,
391
+ useValue: 'ddr'
392
+ },
393
+ {
394
+ provide: StorageService,
395
+ useClass: LocalStorageService
396
+ },
282
397
  ] });
283
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: DdrExtensionsModule, decorators: [{
398
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: DdrExtensionsModule, decorators: [{
284
399
  type: NgModule,
285
400
  args: [{
286
401
  declarations: [
@@ -292,7 +407,19 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImpor
292
407
  {
293
408
  provide: DDR_LOGIN_PATH,
294
409
  useValue: '/login'
295
- }
410
+ },
411
+ {
412
+ provide: LoggerService,
413
+ useClass: ConsoleLoggerService
414
+ },
415
+ {
416
+ provide: DDR_STORAGE_PREFIX,
417
+ useValue: 'ddr'
418
+ },
419
+ {
420
+ provide: StorageService,
421
+ useClass: LocalStorageService
422
+ },
296
423
  ],
297
424
  exports: [
298
425
  LazyImageDirective,
@@ -419,9 +546,9 @@ class CookieService {
419
546
  return new RegExp('(?:^' + escapedName + '|;\\s*' + escapedName + ')=(.*?)(?:;|$)', 'g');
420
547
  }
421
548
  }
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: [{
549
+ CookieService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: CookieService, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
550
+ CookieService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: CookieService, providedIn: 'root' });
551
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: CookieService, decorators: [{
425
552
  type: Injectable,
426
553
  args: [{
427
554
  providedIn: 'root'
@@ -502,9 +629,9 @@ class ScrollService {
502
629
  }
503
630
  }
504
631
  }
505
- 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 });
506
- ScrollService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: ScrollService, providedIn: 'root' });
507
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: ScrollService, decorators: [{
632
+ 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 });
633
+ ScrollService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: ScrollService, providedIn: 'root' });
634
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: ScrollService, decorators: [{
508
635
  type: Injectable,
509
636
  args: [{
510
637
  providedIn: 'root'
@@ -519,9 +646,9 @@ class VisibilityService {
519
646
  return this.visibility$;
520
647
  }
521
648
  }
522
- VisibilityService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: VisibilityService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
523
- VisibilityService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: VisibilityService, providedIn: 'root' });
524
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: VisibilityService, decorators: [{
649
+ VisibilityService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: VisibilityService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
650
+ VisibilityService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: VisibilityService, providedIn: 'root' });
651
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: VisibilityService, decorators: [{
525
652
  type: Injectable,
526
653
  args: [{ providedIn: 'root' }]
527
654
  }], ctorParameters: function () { return []; } });
@@ -537,9 +664,9 @@ class WithCredentialsInterceptor {
537
664
  return next.handle(cloned);
538
665
  }
539
666
  }
540
- WithCredentialsInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: WithCredentialsInterceptor, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
541
- WithCredentialsInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: WithCredentialsInterceptor });
542
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: WithCredentialsInterceptor, decorators: [{
667
+ WithCredentialsInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WithCredentialsInterceptor, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
668
+ WithCredentialsInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WithCredentialsInterceptor });
669
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WithCredentialsInterceptor, decorators: [{
543
670
  type: Injectable
544
671
  }] });
545
672
 
@@ -588,9 +715,9 @@ class RedirectToLoginInterceptor {
588
715
  }));
589
716
  }
590
717
  }
591
- 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 });
592
- RedirectToLoginInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: RedirectToLoginInterceptor });
593
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: RedirectToLoginInterceptor, decorators: [{
718
+ 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 });
719
+ RedirectToLoginInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: RedirectToLoginInterceptor });
720
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: RedirectToLoginInterceptor, decorators: [{
594
721
  type: Injectable
595
722
  }], ctorParameters: function () {
596
723
  return [{ type: i1.Router }, { type: undefined, decorators: [{
@@ -599,9 +726,249 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImpor
599
726
  }] }];
600
727
  } });
601
728
 
729
+ const DDR_OAUTH2_CONFIG = new InjectionToken('DDR_OAUTH2_CONFIG');
730
+ class OAuth2Config {
731
+ constructor(clientId, redirectUri, authorizeUri, tokenUri) {
732
+ this.clientId = clientId;
733
+ this.redirectUri = redirectUri;
734
+ this.authorizeUri = authorizeUri;
735
+ this.tokenUri = tokenUri;
736
+ }
737
+ }
738
+
739
+ class OAuth2Error extends Error {
740
+ constructor(error) {
741
+ super(error);
742
+ }
743
+ }
744
+ OAuth2Error.CODE_NOT_FOUND = 'code_not_found';
745
+ OAuth2Error.ACCESS_DENIED = 'access_denied';
746
+
747
+ class OAuth2Service {
748
+ constructor(route, httpClient, config) {
749
+ this.route = route;
750
+ this.httpClient = httpClient;
751
+ this.config = config;
752
+ this.accessTokenString = null;
753
+ this.accessToken = null;
754
+ this.REFRESH_MARGIN_SECONDS = 60 * 10;
755
+ this.refreshTokenRequest$ = null;
756
+ }
757
+ redirectToLogin() {
758
+ const challenge = this.createChallenge();
759
+ localStorage.setItem(OAuth2Service.STORAGE_KEY_CHALLENGE, challenge);
760
+ const params = new HttpParams()
761
+ .set('client_id', this.config.clientId)
762
+ .set('response_type', 'code')
763
+ .set('redirect_uri', this.config.redirectUri)
764
+ .set('code_challenge', challenge)
765
+ .set('code_challenge_method', 'plain');
766
+ window.location.href = this.config.authorizeUri + '?' + params.toString();
767
+ }
768
+ handleCode() {
769
+ if (this.route.snapshot.queryParamMap.has('error')) {
770
+ const error = this.route.snapshot.queryParamMap.get('error');
771
+ return throwError(() => new OAuth2Error(error !== null && error !== void 0 ? error : 'Unknown error'));
772
+ }
773
+ if (!this.route.snapshot.queryParamMap.has('code')) {
774
+ return throwError(() => new OAuth2Error(OAuth2Error.CODE_NOT_FOUND));
775
+ }
776
+ const code = TypeUtils.notNull(this.route.snapshot.queryParamMap.get('code'));
777
+ const params = new HttpParams()
778
+ .set('grant_type', 'authorization_code')
779
+ .set('code', code)
780
+ .set('redirect_uri', this.config.redirectUri)
781
+ .set('code_verifier', TypeUtils.notNull(localStorage.getItem(OAuth2Service.STORAGE_KEY_CHALLENGE)))
782
+ .set('client_id', this.config.clientId);
783
+ return this.httpClient.post(this.config.tokenUri, params).pipe(map(tokenResponse => this.processTokenResponse(tokenResponse)));
784
+ }
785
+ createChallenge() {
786
+ return StringUtils.createRandomString(64, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-._~');
787
+ }
788
+ getRefreshToken() {
789
+ return localStorage.getItem(OAuth2Service.STORAGE_KEY_REFRESH_TOKEN);
790
+ }
791
+ getAccessTokenString() {
792
+ return this.accessTokenString;
793
+ }
794
+ isAccessTokenExpired() {
795
+ return (null == this.accessToken
796
+ || this.accessToken.exp * 1000 < Date.now());
797
+ }
798
+ isRefreshPossibleAndRequired(req = null) {
799
+ return ((null == req || !req.url.endsWith(this.config.tokenUri))
800
+ && null != this.getRefreshToken()
801
+ && (null == this.accessToken
802
+ || (this.accessToken.exp - this.REFRESH_MARGIN_SECONDS) * 1000 < Date.now()));
803
+ }
804
+ performRefresh() {
805
+ if (null == this.refreshTokenRequest$) {
806
+ console.log('Performing token refesh');
807
+ const params = new HttpParams()
808
+ .set('grant_type', 'refresh_token')
809
+ .set('refresh_token', TypeUtils.notNull(this.getRefreshToken()))
810
+ .set('client_id', this.config.clientId);
811
+ this.refreshTokenRequest$ = this.httpClient.post(this.config.tokenUri, params).pipe(map(tokenResponse => this.processTokenResponse(tokenResponse)), catchError(error => {
812
+ this.accessTokenString = null;
813
+ this.accessToken = null;
814
+ localStorage.removeItem(OAuth2Service.STORAGE_KEY_REFRESH_TOKEN);
815
+ this.refreshTokenRequest$ = null;
816
+ return throwError(error);
817
+ }), shareReplay(1));
818
+ }
819
+ return this.refreshTokenRequest$;
820
+ }
821
+ processTokenResponse(tokenResponse) {
822
+ localStorage.removeItem(OAuth2Service.STORAGE_KEY_CHALLENGE);
823
+ this.accessTokenString = tokenResponse.access_token;
824
+ this.accessToken = JSON.parse(atob(tokenResponse.access_token.split('.')[1]));
825
+ console.log('Access Token Expiry', new Date(this.accessToken.exp * 1000));
826
+ localStorage.setItem(OAuth2Service.STORAGE_KEY_REFRESH_TOKEN, tokenResponse.refresh_token);
827
+ return this.accessToken;
828
+ }
829
+ clear() {
830
+ this.accessToken = null;
831
+ this.accessTokenString = null;
832
+ localStorage.removeItem(OAuth2Service.STORAGE_KEY_REFRESH_TOKEN);
833
+ localStorage.removeItem(OAuth2Service.STORAGE_KEY_RETURN_URL);
834
+ }
835
+ setReturnUrl(url) {
836
+ localStorage.setItem(OAuth2Service.STORAGE_KEY_RETURN_URL, url);
837
+ }
838
+ getReturnUrl() {
839
+ return localStorage.getItem(OAuth2Service.STORAGE_KEY_RETURN_URL);
840
+ }
841
+ }
842
+ OAuth2Service.STORAGE_KEY_CHALLENGE = 'ddr_oauth2_challenge';
843
+ OAuth2Service.STORAGE_KEY_REFRESH_TOKEN = 'ddr_oauth2_refresh_token';
844
+ OAuth2Service.STORAGE_KEY_RETURN_URL = 'ddr_oauth2_return_url';
845
+ 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 });
846
+ OAuth2Service.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2Service });
847
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2Service, decorators: [{
848
+ type: Injectable
849
+ }], ctorParameters: function () {
850
+ return [{ type: i1.ActivatedRoute }, { type: i2$1.HttpClient }, { type: OAuth2Config, decorators: [{
851
+ type: Inject,
852
+ args: [DDR_OAUTH2_CONFIG]
853
+ }] }];
854
+ } });
855
+
856
+ class OAuth2RefreshTokenInterceptor {
857
+ constructor(oAuth2Service) {
858
+ this.oAuth2Service = oAuth2Service;
859
+ }
860
+ /**
861
+ * @override
862
+ */
863
+ intercept(req, next) {
864
+ if (this.oAuth2Service.isRefreshPossibleAndRequired(req)) {
865
+ return this.oAuth2Service.performRefresh().pipe(switchMap(() => next.handle(req)));
866
+ }
867
+ return next.handle(req);
868
+ }
869
+ }
870
+ OAuth2RefreshTokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2RefreshTokenInterceptor, deps: [{ token: OAuth2Service }], target: i0.ɵɵFactoryTarget.Injectable });
871
+ OAuth2RefreshTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2RefreshTokenInterceptor });
872
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2RefreshTokenInterceptor, decorators: [{
873
+ type: Injectable
874
+ }], ctorParameters: function () { return [{ type: OAuth2Service }]; } });
875
+
876
+ class RedirectToOAuth2LoginInterceptor {
877
+ constructor(oAuth2Service, router, oAuth2Config) {
878
+ this.oAuth2Service = oAuth2Service;
879
+ this.router = router;
880
+ this.oAuth2Config = oAuth2Config;
881
+ }
882
+ /**
883
+ * @override
884
+ */
885
+ intercept(req, next) {
886
+ return next.handle(req).pipe(catchError((err) => {
887
+ if (err instanceof HttpErrorResponse) {
888
+ if (err.status === 401) {
889
+ if (!window.location.href.startsWith(this.oAuth2Config.redirectUri)) {
890
+ this.oAuth2Service.setReturnUrl(this.router.routerState.snapshot.url);
891
+ this.oAuth2Service.redirectToLogin();
892
+ }
893
+ }
894
+ }
895
+ return throwError(err);
896
+ }));
897
+ }
898
+ }
899
+ 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 });
900
+ RedirectToOAuth2LoginInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: RedirectToOAuth2LoginInterceptor });
901
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: RedirectToOAuth2LoginInterceptor, decorators: [{
902
+ type: Injectable
903
+ }], ctorParameters: function () {
904
+ return [{ type: OAuth2Service }, { type: i1.Router }, { type: OAuth2Config, decorators: [{
905
+ type: Inject,
906
+ args: [DDR_OAUTH2_CONFIG]
907
+ }] }];
908
+ } });
909
+
910
+ class OAuth2AccessTokenInterceptor {
911
+ constructor(oAuth2Service) {
912
+ this.oAuth2Service = oAuth2Service;
913
+ }
914
+ /**
915
+ * @override
916
+ */
917
+ intercept(req, next) {
918
+ const accessTokenString = this.oAuth2Service.getAccessTokenString();
919
+ if (null !== accessTokenString && !this.oAuth2Service.isAccessTokenExpired()) {
920
+ req = req.clone({
921
+ headers: req.headers.set('Authorization', 'Bearer ' + accessTokenString)
922
+ });
923
+ }
924
+ return next.handle(req);
925
+ }
926
+ }
927
+ OAuth2AccessTokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2AccessTokenInterceptor, deps: [{ token: OAuth2Service }], target: i0.ɵɵFactoryTarget.Injectable });
928
+ OAuth2AccessTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2AccessTokenInterceptor });
929
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2AccessTokenInterceptor, decorators: [{
930
+ type: Injectable
931
+ }], ctorParameters: function () { return [{ type: OAuth2Service }]; } });
932
+
933
+ class OAuth2Module {
934
+ static forRoot(config) {
935
+ return {
936
+ ngModule: OAuth2Module,
937
+ providers: [
938
+ OAuth2Service,
939
+ {
940
+ provide: DDR_OAUTH2_CONFIG,
941
+ useValue: config
942
+ },
943
+ {
944
+ provide: HTTP_INTERCEPTORS,
945
+ useClass: OAuth2RefreshTokenInterceptor,
946
+ multi: true
947
+ },
948
+ {
949
+ provide: HTTP_INTERCEPTORS,
950
+ useClass: RedirectToOAuth2LoginInterceptor,
951
+ multi: true
952
+ },
953
+ {
954
+ provide: HTTP_INTERCEPTORS,
955
+ useClass: OAuth2AccessTokenInterceptor,
956
+ multi: true
957
+ }
958
+ ],
959
+ };
960
+ }
961
+ }
962
+ OAuth2Module.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2Module, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
963
+ OAuth2Module.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.12", ngImport: i0, type: OAuth2Module });
964
+ OAuth2Module.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2Module });
965
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: OAuth2Module, decorators: [{
966
+ type: NgModule
967
+ }] });
968
+
602
969
  class JwtService {
603
- constructor(storagePrefix) {
604
- this.storagePrefix = storagePrefix;
970
+ constructor(storageService) {
971
+ this.storageService = storageService;
605
972
  /**
606
973
  * The current token.
607
974
  */
@@ -616,7 +983,7 @@ class JwtService {
616
983
  */
617
984
  setTokens(token, refreshToken) {
618
985
  this.setToken(token);
619
- localStorage.setItem(this.getRefreshTokenStorageKey(), refreshToken);
986
+ this.storageService.store(this.getRefreshTokenStorageKey(), refreshToken);
620
987
  }
621
988
  /**
622
989
  * Sets the current token.
@@ -637,7 +1004,7 @@ class JwtService {
637
1004
  * Gets the refresh token.
638
1005
  */
639
1006
  getRefreshToken() {
640
- return localStorage.getItem(this.getRefreshTokenStorageKey());
1007
+ return this.storageService.retrieve(this.getRefreshTokenStorageKey());
641
1008
  }
642
1009
  /**
643
1010
  * Checks if the current token expired.
@@ -660,25 +1027,20 @@ class JwtService {
660
1027
  clear() {
661
1028
  this.token = null;
662
1029
  this.tokenExpiry = null;
663
- localStorage.removeItem(this.getRefreshTokenStorageKey());
1030
+ this.storageService.remove(this.getRefreshTokenStorageKey());
664
1031
  }
665
1032
  getRefreshTokenStorageKey() {
666
- return this.storagePrefix + '.jwt.refresh_token';
1033
+ return 'jwt.refresh_token';
667
1034
  }
668
1035
  }
669
- 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 });
670
- JwtService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: JwtService, providedIn: 'root' });
671
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: JwtService, decorators: [{
1036
+ JwtService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: JwtService, deps: [{ token: StorageService }], target: i0.ɵɵFactoryTarget.Injectable });
1037
+ JwtService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: JwtService, providedIn: 'root' });
1038
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: JwtService, decorators: [{
672
1039
  type: Injectable,
673
1040
  args: [{
674
1041
  providedIn: 'root'
675
1042
  }]
676
- }], ctorParameters: function () {
677
- return [{ type: undefined, decorators: [{
678
- type: Inject,
679
- args: [DDR_STORAGE_PREFIX]
680
- }] }];
681
- } });
1043
+ }], ctorParameters: function () { return [{ type: StorageService }]; } });
682
1044
 
683
1045
  class JwtInterceptor {
684
1046
  constructor(jwtService) {
@@ -697,9 +1059,9 @@ class JwtInterceptor {
697
1059
  return next.handle(req);
698
1060
  }
699
1061
  }
700
- JwtInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: JwtInterceptor, deps: [{ token: JwtService }], target: i0.ɵɵFactoryTarget.Injectable });
701
- JwtInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: JwtInterceptor });
702
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: JwtInterceptor, decorators: [{
1062
+ JwtInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: JwtInterceptor, deps: [{ token: JwtService }], target: i0.ɵɵFactoryTarget.Injectable });
1063
+ JwtInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: JwtInterceptor });
1064
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: JwtInterceptor, decorators: [{
703
1065
  type: Injectable
704
1066
  }], ctorParameters: function () { return [{ type: JwtService }]; } });
705
1067
 
@@ -737,9 +1099,9 @@ class JwtRefreshTokenInterceptor {
737
1099
  return this.refreshTokenRequest$;
738
1100
  }
739
1101
  }
740
- 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 });
741
- JwtRefreshTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: JwtRefreshTokenInterceptor });
742
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: JwtRefreshTokenInterceptor, decorators: [{
1102
+ 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 });
1103
+ JwtRefreshTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: JwtRefreshTokenInterceptor });
1104
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: JwtRefreshTokenInterceptor, decorators: [{
743
1105
  type: Injectable
744
1106
  }], ctorParameters: function () {
745
1107
  return [{ type: JwtService }, { type: i2$1.HttpClient }, { type: undefined, decorators: [{
@@ -756,5 +1118,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImpor
756
1118
  * Generated bundle index. Do not edit.
757
1119
  */
758
1120
 
759
- 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 };
1121
+ 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 };
760
1122
  //# sourceMappingURL=dontdrinkandroot-ngx-extensions.mjs.map