adb-shared 6.0.27 → 6.0.30

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.
@@ -7,7 +7,7 @@ import { TranslateModule } from '@ngx-translate/core';
7
7
  import * as i1 from '@angular/common/http';
8
8
  import { provideHttpClient, withInterceptorsFromDi, HttpHeaders, HTTP_INTERCEPTORS } from '@angular/common/http';
9
9
  import * as i1$1 from '@angular/router';
10
- import { NavigationEnd, RouterModule, NavigationStart } from '@angular/router';
10
+ import { NavigationEnd, RouterModule } from '@angular/router';
11
11
  import { Subscription, Subject, of, BehaviorSubject, catchError, throwError } from 'rxjs';
12
12
  import { startOfDay, subYears, endOfDay, addYears, getMonth, subMonths, addMonths, isSameYear, startOfMonth, endOfMonth, eachWeekOfInterval, getISOWeek, addDays, eachDayOfInterval, getHours, getMinutes, isSameDay, isSameMonth, isWithinInterval, isValid, parseISO, addSeconds, format } from 'date-fns';
13
13
  import * as i2$1 from '@angular/forms';
@@ -2020,15 +2020,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImpor
2020
2020
  }]
2021
2021
  }] });
2022
2022
 
2023
- class SessionIds {
2024
- static { this.CURRENT_URL = "current_url"; }
2025
- static { this.CODE_VERIFIER = 'nonce'; }
2026
- static { this.REFRESH_TOKEN = 'refresh-token'; }
2027
- static { this.TOKEN_EXPIRES = 'token_expires'; }
2028
- static { this.ACCESS_TOKEN = 'access-token'; }
2029
- static { this.USER_LAST_ACTIVE = 'lastActive'; }
2030
- }
2031
-
2032
2023
  const ADB_USER_SERVICE_CONFIG = new InjectionToken('ADB_DATA_SERVICE_CONFIG');
2033
2024
  const DEFAULT_ADB_USER_SERVICE_CONFIG = {
2034
2025
  scope: 'roles profile email',
@@ -2038,6 +2029,16 @@ const DEFAULT_ADB_USER_SERVICE_CONFIG = {
2038
2029
  log: false
2039
2030
  };
2040
2031
 
2032
+ class UserModuleConstants {
2033
+ static { this.CURRENT_URL = "current_url"; }
2034
+ static { this.CODE_VERIFIER = 'nonce'; }
2035
+ static { this.REFRESH_TOKEN = 'refresh-token'; }
2036
+ static { this.TOKEN_EXPIRES = 'token_expires'; }
2037
+ static { this.ACCESS_TOKEN = 'access-token'; }
2038
+ static { this.USER_LAST_ACTIVE = 'lastActive'; }
2039
+ static { this.ONGOING_CODEFLOW = 'ongoing-codeflow'; }
2040
+ }
2041
+
2041
2042
  class AdbUserService {
2042
2043
  constructor(config, http, router) {
2043
2044
  this.config = config;
@@ -2051,27 +2052,21 @@ class AdbUserService {
2051
2052
  this.config = { ...{ scope: 'roles', idleTime: 30, response_type: 'code' }, ...config };
2052
2053
  }
2053
2054
  init() {
2054
- this.router.events.subscribe((event) => {
2055
- if (event instanceof NavigationStart) {
2056
- this.log('init with url', event.url);
2057
- if (event.url.includes('auth-callback')) {
2058
- return;
2059
- }
2060
- if (event.url && event.url !== '/') {
2061
- sessionStorage.setItem(SessionIds.CURRENT_URL, event.url);
2062
- }
2063
- this.checkStatus();
2064
- }
2065
- });
2055
+ const accessToken = sessionStorage.getItem(UserModuleConstants.ACCESS_TOKEN);
2056
+ if (accessToken) {
2057
+ const user = this.getUser(accessToken);
2058
+ this.userSubject.next(user);
2059
+ this.startMainLoop();
2060
+ }
2066
2061
  }
2067
2062
  startMainLoop() {
2068
2063
  this.checkStatus();
2069
2064
  this.intervalId = setInterval(() => this.checkStatus(), 60 * 1000); // 60 seconds * 1000 milliseconds
2070
2065
  }
2071
2066
  login() {
2072
- this.log('login at url', this.router.url);
2073
- sessionStorage.setItem(SessionIds.CURRENT_URL, this.router.url);
2074
- this.checkStatus();
2067
+ this.log('url when login', this.router.url);
2068
+ sessionStorage.setItem(UserModuleConstants.CURRENT_URL, this.router.url);
2069
+ this.authorize();
2075
2070
  }
2076
2071
  logout() {
2077
2072
  clearInterval(this.intervalId);
@@ -2081,12 +2076,13 @@ class AdbUserService {
2081
2076
  }
2082
2077
  checkStatus() {
2083
2078
  this.log('checkStatus runs');
2084
- const accessToken = sessionStorage.getItem(SessionIds.ACCESS_TOKEN);
2079
+ const accessToken = sessionStorage.getItem(UserModuleConstants.ACCESS_TOKEN);
2085
2080
  if (accessToken) {
2086
2081
  this.log('has accesstoken');
2087
2082
  const timeToLive = this.getTokenTimeToLive();
2088
2083
  this.log('timeToLive', timeToLive);
2089
2084
  if (timeToLive === 0) {
2085
+ sessionStorage.removeItem(UserModuleConstants.ACCESS_TOKEN);
2090
2086
  this.authorize();
2091
2087
  }
2092
2088
  else {
@@ -2102,14 +2098,11 @@ class AdbUserService {
2102
2098
  }
2103
2099
  }
2104
2100
  }
2105
- else {
2106
- this.authorize();
2107
- }
2108
2101
  }
2109
2102
  refreshToken() {
2110
2103
  const body = `client_id=${encodeURIComponent(this.config.clientId)}&` +
2111
2104
  `grant_type=${encodeURIComponent("refresh_token")}&` +
2112
- `refresh_token=${encodeURIComponent(sessionStorage.getItem(SessionIds.REFRESH_TOKEN))}`;
2105
+ `refresh_token=${encodeURIComponent(sessionStorage.getItem(UserModuleConstants.REFRESH_TOKEN))}`;
2113
2106
  this.http.post(`${this.config.issuer}/connect/token`, body, { headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' }) }).subscribe({
2114
2107
  next: response => {
2115
2108
  this.setTokensInSession(response);
@@ -2119,19 +2112,19 @@ class AdbUserService {
2119
2112
  }
2120
2113
  setTokensInSession(params) {
2121
2114
  if (params.refresh_token) {
2122
- sessionStorage.setItem(SessionIds.REFRESH_TOKEN, params.refresh_token);
2115
+ sessionStorage.setItem(UserModuleConstants.REFRESH_TOKEN, params.refresh_token);
2123
2116
  }
2124
2117
  if (params.access_token) {
2125
- sessionStorage.setItem(SessionIds.ACCESS_TOKEN, params.access_token);
2118
+ sessionStorage.setItem(UserModuleConstants.ACCESS_TOKEN, params.access_token);
2126
2119
  }
2127
2120
  if (params.expires_in) {
2128
2121
  const expireTime = addSeconds(new Date(), params.expires_in);
2129
- sessionStorage.setItem(SessionIds.TOKEN_EXPIRES, format(expireTime, 'yyyy-MM-dd HH:mm:ss'));
2122
+ sessionStorage.setItem(UserModuleConstants.TOKEN_EXPIRES, format(expireTime, 'yyyy-MM-dd HH:mm:ss'));
2130
2123
  }
2131
2124
  }
2132
2125
  async authorize() {
2133
2126
  const codeVerifier = Array.from(crypto.getRandomValues(new Uint8Array(64)), byte => 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'[byte % 62]).join('');
2134
- sessionStorage.setItem(SessionIds.CODE_VERIFIER, codeVerifier);
2127
+ sessionStorage.setItem(UserModuleConstants.CODE_VERIFIER, codeVerifier);
2135
2128
  const encoder = new TextEncoder();
2136
2129
  const data = encoder.encode(codeVerifier);
2137
2130
  const hashBuffer = await crypto.subtle.digest('SHA-256', data);
@@ -2163,7 +2156,7 @@ class AdbUserService {
2163
2156
  return urlParams;
2164
2157
  }
2165
2158
  getTokenTimeToLive() {
2166
- const expires = sessionStorage.getItem(SessionIds.TOKEN_EXPIRES);
2159
+ const expires = sessionStorage.getItem(UserModuleConstants.TOKEN_EXPIRES);
2167
2160
  if (expires) {
2168
2161
  const expireDate = new Date(expires);
2169
2162
  const now = new Date();
@@ -2181,7 +2174,7 @@ class AdbUserService {
2181
2174
  return false;
2182
2175
  }
2183
2176
  hasUserBeenActive() {
2184
- const lastActive = sessionStorage.getItem(SessionIds.USER_LAST_ACTIVE);
2177
+ const lastActive = sessionStorage.getItem(UserModuleConstants.USER_LAST_ACTIVE);
2185
2178
  if (!lastActive) {
2186
2179
  return false;
2187
2180
  }
@@ -2191,7 +2184,7 @@ class AdbUserService {
2191
2184
  }
2192
2185
  log(message, ...optionalParams) {
2193
2186
  if (this.config?.log) {
2194
- if (optionalParams) {
2187
+ if (optionalParams?.length > 0) {
2195
2188
  console.log(message, optionalParams);
2196
2189
  }
2197
2190
  else {
@@ -2225,6 +2218,54 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImpor
2225
2218
  args: [ADB_USER_SERVICE_CONFIG]
2226
2219
  }] }, { type: i1.HttpClient }, { type: i1$1.Router }] });
2227
2220
 
2221
+ class AuthCallbackComponent {
2222
+ constructor(activatedRoute, router, http, adbUserService) {
2223
+ this.activatedRoute = activatedRoute;
2224
+ this.router = router;
2225
+ this.http = http;
2226
+ this.adbUserService = adbUserService;
2227
+ this.subscriptions = new Subscription();
2228
+ }
2229
+ ngOnInit() {
2230
+ this.subscriptions.add(this.activatedRoute.queryParamMap.subscribe(qParmas => {
2231
+ if (qParmas.has('code')) {
2232
+ const body = `grant_type=authorization_code` +
2233
+ `&code=${encodeURIComponent(qParmas.get('code'))}` +
2234
+ `&code_verifier=${encodeURIComponent(sessionStorage.getItem(UserModuleConstants.CODE_VERIFIER))}` +
2235
+ `&redirect_uri=${encodeURIComponent(this.adbUserService.config.redirectUrl)}` +
2236
+ `&client_id=${encodeURIComponent(this.adbUserService.config.clientId)}`;
2237
+ this.http.post(`${this.adbUserService.config.issuer}/connect/token`, body, { headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' }) }).subscribe({
2238
+ next: response => {
2239
+ this.adbUserService.setTokensInSession(response);
2240
+ let requestedUrl = sessionStorage.getItem(UserModuleConstants.CURRENT_URL) ?? null;
2241
+ this.adbUserService.log('redirect url in auth-callback', requestedUrl);
2242
+ if (requestedUrl) {
2243
+ this.router.navigate([requestedUrl], { replaceUrl: true }).then(() => {
2244
+ this.adbUserService.startMainLoop();
2245
+ });
2246
+ sessionStorage.removeItem(UserModuleConstants.CURRENT_URL);
2247
+ }
2248
+ else {
2249
+ this.router.navigate(['/'], { replaceUrl: true }).then(() => {
2250
+ this.adbUserService.startMainLoop();
2251
+ });
2252
+ ;
2253
+ }
2254
+ }
2255
+ });
2256
+ }
2257
+ }));
2258
+ }
2259
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: AuthCallbackComponent, deps: [{ token: i1$1.ActivatedRoute }, { token: i1$1.Router }, { token: i1.HttpClient }, { token: AdbUserService }], target: i0.ɵɵFactoryTarget.Component }); }
2260
+ /** @nocollapse */ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.8", type: AuthCallbackComponent, selector: "ng-component", ngImport: i0, template: '<div class="loading-dead-spinner"></div>', isInline: true }); }
2261
+ }
2262
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: AuthCallbackComponent, decorators: [{
2263
+ type: Component,
2264
+ args: [{
2265
+ template: '<div class="loading-dead-spinner"></div>'
2266
+ }]
2267
+ }], ctorParameters: () => [{ type: i1$1.ActivatedRoute }, { type: i1$1.Router }, { type: i1.HttpClient }, { type: AdbUserService }] });
2268
+
2228
2269
  class AdbUserInterceptor {
2229
2270
  static { this.UNAUTHENTICATED = 401; }
2230
2271
  constructor(adbUserService) {
@@ -2232,9 +2273,9 @@ class AdbUserInterceptor {
2232
2273
  }
2233
2274
  intercept(req, next) {
2234
2275
  if (req.headers.get('X-System-Request') !== 'true') {
2235
- sessionStorage.setItem(SessionIds.USER_LAST_ACTIVE, Date.now().toString());
2276
+ sessionStorage.setItem(UserModuleConstants.USER_LAST_ACTIVE, Date.now().toString());
2236
2277
  }
2237
- const accessToken = sessionStorage.getItem(SessionIds.ACCESS_TOKEN);
2278
+ const accessToken = sessionStorage.getItem(UserModuleConstants.ACCESS_TOKEN);
2238
2279
  if (accessToken) {
2239
2280
  const clonedRequest = req.clone({
2240
2281
  setHeaders: {
@@ -2254,7 +2295,7 @@ class AdbUserInterceptor {
2254
2295
  }
2255
2296
  else {
2256
2297
  if (error.status === AdbUserInterceptor.UNAUTHENTICATED) {
2257
- this.adbUserService.init();
2298
+ this.adbUserService.login();
2258
2299
  }
2259
2300
  }
2260
2301
  return throwError(() => error);
@@ -2266,68 +2307,24 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImpor
2266
2307
  type: Injectable
2267
2308
  }], ctorParameters: () => [{ type: AdbUserService }] });
2268
2309
 
2269
- class AuthCallbackComponent {
2270
- constructor(activatedRoute, router, http, adbUserService) {
2271
- this.activatedRoute = activatedRoute;
2272
- this.router = router;
2273
- this.http = http;
2274
- this.adbUserService = adbUserService;
2275
- this.subscriptions = new Subscription();
2276
- }
2277
- ngOnInit() {
2278
- this.subscriptions.add(this.activatedRoute.queryParamMap.subscribe(qParmas => {
2279
- if (qParmas.has('code')) {
2280
- const body = `grant_type=authorization_code` +
2281
- `&code=${encodeURIComponent(qParmas.get('code'))}` +
2282
- `&code_verifier=${encodeURIComponent(sessionStorage.getItem(SessionIds.CODE_VERIFIER))}` +
2283
- `&redirect_uri=${encodeURIComponent(this.adbUserService.config.redirectUrl)}` +
2284
- `&client_id=${encodeURIComponent(this.adbUserService.config.clientId)}`;
2285
- this.http.post(`${this.adbUserService.config.issuer}/connect/token`, body, { headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' }) }).subscribe({
2286
- next: response => {
2287
- this.adbUserService.setTokensInSession(response);
2288
- let requestedUrl = sessionStorage.getItem(SessionIds.CURRENT_URL) ?? null;
2289
- this.adbUserService.startMainLoop();
2290
- console.log('redirect url', requestedUrl);
2291
- if (requestedUrl) {
2292
- this.router.navigate([requestedUrl], { replaceUrl: true });
2293
- sessionStorage.removeItem(SessionIds.CURRENT_URL);
2294
- }
2295
- else {
2296
- this.router.navigate(['/'], { replaceUrl: true });
2297
- }
2298
- }
2299
- });
2300
- }
2301
- }));
2302
- }
2303
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: AuthCallbackComponent, deps: [{ token: i1$1.ActivatedRoute }, { token: i1$1.Router }, { token: i1.HttpClient }, { token: AdbUserService }], target: i0.ɵɵFactoryTarget.Component }); }
2304
- /** @nocollapse */ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.8", type: AuthCallbackComponent, selector: "ng-component", ngImport: i0, template: '<div class="loading-dead-spinner"></div>', isInline: true }); }
2305
- }
2306
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: AuthCallbackComponent, decorators: [{
2307
- type: Component,
2308
- args: [{
2309
- template: '<div class="loading-dead-spinner"></div>'
2310
- }]
2311
- }], ctorParameters: () => [{ type: i1$1.ActivatedRoute }, { type: i1$1.Router }, { type: i1.HttpClient }, { type: AdbUserService }] });
2312
-
2313
2310
  const routes = [
2314
2311
  { path: 'auth-callback', component: AuthCallbackComponent }
2315
2312
  ];
2316
- class AdbUserModule {
2313
+ class AdbUserModule2 {
2317
2314
  static forRoot(config) {
2318
2315
  return {
2319
- ngModule: AdbUserModule,
2316
+ ngModule: AdbUserModule2,
2320
2317
  providers: [
2321
2318
  {
2322
2319
  provide: ADB_USER_SERVICE_CONFIG,
2323
- useValue: { ...DEFAULT_ADB_USER_SERVICE_CONFIG, ...config },
2324
- },
2320
+ useValue: { ...DEFAULT_ADB_USER_SERVICE_CONFIG, ...config }
2321
+ }
2325
2322
  ],
2326
2323
  };
2327
2324
  }
2328
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: AdbUserModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
2329
- /** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.8", ngImport: i0, type: AdbUserModule, declarations: [AuthCallbackComponent], imports: [CommonModule, i1$1.RouterModule, i1$2.TranslateModule], exports: [AuthCallbackComponent] }); }
2330
- /** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: AdbUserModule, providers: [
2325
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: AdbUserModule2, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
2326
+ /** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.8", ngImport: i0, type: AdbUserModule2, declarations: [AuthCallbackComponent], imports: [CommonModule, i1$1.RouterModule, i1$2.TranslateModule], exports: [AuthCallbackComponent] }); }
2327
+ /** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: AdbUserModule2, providers: [
2331
2328
  AdbUserService,
2332
2329
  {
2333
2330
  provide: HTTP_INTERCEPTORS,
@@ -2336,7 +2333,7 @@ class AdbUserModule {
2336
2333
  }
2337
2334
  ], imports: [CommonModule, RouterModule.forChild(routes), TranslateModule.forChild()] }); }
2338
2335
  }
2339
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: AdbUserModule, decorators: [{
2336
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: AdbUserModule2, decorators: [{
2340
2337
  type: NgModule,
2341
2338
  args: [{
2342
2339
  imports: [CommonModule, RouterModule.forChild(routes), TranslateModule.forChild()],
@@ -2361,5 +2358,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImpor
2361
2358
  * Generated bundle index. Do not edit.
2362
2359
  */
2363
2360
 
2364
- export { ADBHeaderModule, ADBNavComponent, ADB_USER_SERVICE_CONFIG, AdbButtonsModule, AdbConfirmModal, AdbDatePickerComponent, AdbDatePickerDirective, AdbDatePickerModule, AdbDirectivesModule, AdbDropdown2Directive, AdbDropdownDirective, AdbDropdownModule, AdbFilterSectionModule, AdbHelpButtonComponent, AdbModalModule, AdbModalService, AdbPagersModule, AdbPipesModule, AdbRichEditorComponent, AdbRichEditorModule, AdbToast, AdbToastModule, AdbToastService, AdbUserInterceptor, AdbUserModule, AdbUserService, ArtportalenFooterComponent, ArtportalenNavComponent, ArtportalenNavModule, AuthCallbackComponent, ClickOutsideDirective, DEFAULT_ADB_USER_SERVICE_CONFIG, EmptyValuePipe, FileUploadDirective, FilterSectionComponent, FocusDirective, HighlightHtmlPipe, HighlightPipe, InfiniteScrollComponent, LocaleDatePipe, NumberSpacingPipe, PagerComponent, PagerInlineComponent, RedListBadgeClassDirective, RichTextComponent, RiskClassDirective, SessionIds, ToastType };
2361
+ export { ADBHeaderModule, ADBNavComponent, ADB_USER_SERVICE_CONFIG, AdbButtonsModule, AdbConfirmModal, AdbDatePickerComponent, AdbDatePickerDirective, AdbDatePickerModule, AdbDirectivesModule, AdbDropdown2Directive, AdbDropdownDirective, AdbDropdownModule, AdbFilterSectionModule, AdbHelpButtonComponent, AdbModalModule, AdbModalService, AdbPagersModule, AdbPipesModule, AdbRichEditorComponent, AdbRichEditorModule, AdbToast, AdbToastModule, AdbToastService, AdbUserInterceptor, AdbUserModule2, AdbUserService, ArtportalenFooterComponent, ArtportalenNavComponent, ArtportalenNavModule, AuthCallbackComponent, ClickOutsideDirective, DEFAULT_ADB_USER_SERVICE_CONFIG, EmptyValuePipe, FileUploadDirective, FilterSectionComponent, FocusDirective, HighlightHtmlPipe, HighlightPipe, InfiniteScrollComponent, LocaleDatePipe, NumberSpacingPipe, PagerComponent, PagerInlineComponent, RedListBadgeClassDirective, RichTextComponent, RiskClassDirective, ToastType, UserModuleConstants };
2365
2362
  //# sourceMappingURL=adb-shared.mjs.map