adb-shared 6.0.28 → 6.0.31

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,22 +2052,11 @@ 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
- });
2066
- const accessToken = sessionStorage.getItem(SessionIds.ACCESS_TOKEN);
2055
+ const accessToken = sessionStorage.getItem(UserModuleConstants.ACCESS_TOKEN);
2067
2056
  if (accessToken) {
2068
2057
  const user = this.getUser(accessToken);
2069
2058
  this.userSubject.next(user);
2059
+ this.startMainLoop();
2070
2060
  }
2071
2061
  }
2072
2062
  startMainLoop() {
@@ -2074,9 +2064,9 @@ class AdbUserService {
2074
2064
  this.intervalId = setInterval(() => this.checkStatus(), 60 * 1000); // 60 seconds * 1000 milliseconds
2075
2065
  }
2076
2066
  login() {
2077
- this.log('login at url', this.router.url);
2078
- sessionStorage.setItem(SessionIds.CURRENT_URL, this.router.url);
2079
- this.checkStatus();
2067
+ this.log('url when login', this.router.url);
2068
+ sessionStorage.setItem(UserModuleConstants.CURRENT_URL, this.router.url);
2069
+ this.authorize();
2080
2070
  }
2081
2071
  logout() {
2082
2072
  clearInterval(this.intervalId);
@@ -2086,12 +2076,13 @@ class AdbUserService {
2086
2076
  }
2087
2077
  checkStatus() {
2088
2078
  this.log('checkStatus runs');
2089
- const accessToken = sessionStorage.getItem(SessionIds.ACCESS_TOKEN);
2079
+ const accessToken = sessionStorage.getItem(UserModuleConstants.ACCESS_TOKEN);
2090
2080
  if (accessToken) {
2091
2081
  this.log('has accesstoken');
2092
2082
  const timeToLive = this.getTokenTimeToLive();
2093
2083
  this.log('timeToLive', timeToLive);
2094
2084
  if (timeToLive === 0) {
2085
+ sessionStorage.removeItem(UserModuleConstants.ACCESS_TOKEN);
2095
2086
  this.authorize();
2096
2087
  }
2097
2088
  else {
@@ -2107,14 +2098,11 @@ class AdbUserService {
2107
2098
  }
2108
2099
  }
2109
2100
  }
2110
- else {
2111
- this.authorize();
2112
- }
2113
2101
  }
2114
2102
  refreshToken() {
2115
2103
  const body = `client_id=${encodeURIComponent(this.config.clientId)}&` +
2116
2104
  `grant_type=${encodeURIComponent("refresh_token")}&` +
2117
- `refresh_token=${encodeURIComponent(sessionStorage.getItem(SessionIds.REFRESH_TOKEN))}`;
2105
+ `refresh_token=${encodeURIComponent(sessionStorage.getItem(UserModuleConstants.REFRESH_TOKEN))}`;
2118
2106
  this.http.post(`${this.config.issuer}/connect/token`, body, { headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' }) }).subscribe({
2119
2107
  next: response => {
2120
2108
  this.setTokensInSession(response);
@@ -2124,19 +2112,19 @@ class AdbUserService {
2124
2112
  }
2125
2113
  setTokensInSession(params) {
2126
2114
  if (params.refresh_token) {
2127
- sessionStorage.setItem(SessionIds.REFRESH_TOKEN, params.refresh_token);
2115
+ sessionStorage.setItem(UserModuleConstants.REFRESH_TOKEN, params.refresh_token);
2128
2116
  }
2129
2117
  if (params.access_token) {
2130
- sessionStorage.setItem(SessionIds.ACCESS_TOKEN, params.access_token);
2118
+ sessionStorage.setItem(UserModuleConstants.ACCESS_TOKEN, params.access_token);
2131
2119
  }
2132
2120
  if (params.expires_in) {
2133
2121
  const expireTime = addSeconds(new Date(), params.expires_in);
2134
- 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'));
2135
2123
  }
2136
2124
  }
2137
2125
  async authorize() {
2138
2126
  const codeVerifier = Array.from(crypto.getRandomValues(new Uint8Array(64)), byte => 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'[byte % 62]).join('');
2139
- sessionStorage.setItem(SessionIds.CODE_VERIFIER, codeVerifier);
2127
+ sessionStorage.setItem(UserModuleConstants.CODE_VERIFIER, codeVerifier);
2140
2128
  const encoder = new TextEncoder();
2141
2129
  const data = encoder.encode(codeVerifier);
2142
2130
  const hashBuffer = await crypto.subtle.digest('SHA-256', data);
@@ -2168,7 +2156,7 @@ class AdbUserService {
2168
2156
  return urlParams;
2169
2157
  }
2170
2158
  getTokenTimeToLive() {
2171
- const expires = sessionStorage.getItem(SessionIds.TOKEN_EXPIRES);
2159
+ const expires = sessionStorage.getItem(UserModuleConstants.TOKEN_EXPIRES);
2172
2160
  if (expires) {
2173
2161
  const expireDate = new Date(expires);
2174
2162
  const now = new Date();
@@ -2186,7 +2174,7 @@ class AdbUserService {
2186
2174
  return false;
2187
2175
  }
2188
2176
  hasUserBeenActive() {
2189
- const lastActive = sessionStorage.getItem(SessionIds.USER_LAST_ACTIVE);
2177
+ const lastActive = sessionStorage.getItem(UserModuleConstants.USER_LAST_ACTIVE);
2190
2178
  if (!lastActive) {
2191
2179
  return false;
2192
2180
  }
@@ -2196,7 +2184,7 @@ class AdbUserService {
2196
2184
  }
2197
2185
  log(message, ...optionalParams) {
2198
2186
  if (this.config?.log) {
2199
- if (optionalParams) {
2187
+ if (optionalParams?.length > 0) {
2200
2188
  console.log(message, optionalParams);
2201
2189
  }
2202
2190
  else {
@@ -2230,6 +2218,54 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImpor
2230
2218
  args: [ADB_USER_SERVICE_CONFIG]
2231
2219
  }] }, { type: i1.HttpClient }, { type: i1$1.Router }] });
2232
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
+
2233
2269
  class AdbUserInterceptor {
2234
2270
  static { this.UNAUTHENTICATED = 401; }
2235
2271
  constructor(adbUserService) {
@@ -2237,9 +2273,9 @@ class AdbUserInterceptor {
2237
2273
  }
2238
2274
  intercept(req, next) {
2239
2275
  if (req.headers.get('X-System-Request') !== 'true') {
2240
- sessionStorage.setItem(SessionIds.USER_LAST_ACTIVE, Date.now().toString());
2276
+ sessionStorage.setItem(UserModuleConstants.USER_LAST_ACTIVE, Date.now().toString());
2241
2277
  }
2242
- const accessToken = sessionStorage.getItem(SessionIds.ACCESS_TOKEN);
2278
+ const accessToken = sessionStorage.getItem(UserModuleConstants.ACCESS_TOKEN);
2243
2279
  if (accessToken) {
2244
2280
  const clonedRequest = req.clone({
2245
2281
  setHeaders: {
@@ -2259,7 +2295,7 @@ class AdbUserInterceptor {
2259
2295
  }
2260
2296
  else {
2261
2297
  if (error.status === AdbUserInterceptor.UNAUTHENTICATED) {
2262
- this.adbUserService.init();
2298
+ this.adbUserService.login();
2263
2299
  }
2264
2300
  }
2265
2301
  return throwError(() => error);
@@ -2271,50 +2307,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImpor
2271
2307
  type: Injectable
2272
2308
  }], ctorParameters: () => [{ type: AdbUserService }] });
2273
2309
 
2274
- class AuthCallbackComponent {
2275
- constructor(activatedRoute, router, http, adbUserService) {
2276
- this.activatedRoute = activatedRoute;
2277
- this.router = router;
2278
- this.http = http;
2279
- this.adbUserService = adbUserService;
2280
- this.subscriptions = new Subscription();
2281
- }
2282
- ngOnInit() {
2283
- this.subscriptions.add(this.activatedRoute.queryParamMap.subscribe(qParmas => {
2284
- if (qParmas.has('code')) {
2285
- const body = `grant_type=authorization_code` +
2286
- `&code=${encodeURIComponent(qParmas.get('code'))}` +
2287
- `&code_verifier=${encodeURIComponent(sessionStorage.getItem(SessionIds.CODE_VERIFIER))}` +
2288
- `&redirect_uri=${encodeURIComponent(this.adbUserService.config.redirectUrl)}` +
2289
- `&client_id=${encodeURIComponent(this.adbUserService.config.clientId)}`;
2290
- this.http.post(`${this.adbUserService.config.issuer}/connect/token`, body, { headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' }) }).subscribe({
2291
- next: response => {
2292
- this.adbUserService.setTokensInSession(response);
2293
- let requestedUrl = sessionStorage.getItem(SessionIds.CURRENT_URL) ?? null;
2294
- this.adbUserService.startMainLoop();
2295
- console.log('redirect url', requestedUrl);
2296
- if (requestedUrl) {
2297
- this.router.navigate([requestedUrl], { replaceUrl: true });
2298
- sessionStorage.removeItem(SessionIds.CURRENT_URL);
2299
- }
2300
- else {
2301
- this.router.navigate(['/'], { replaceUrl: true });
2302
- }
2303
- }
2304
- });
2305
- }
2306
- }));
2307
- }
2308
- /** @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 }); }
2309
- /** @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 }); }
2310
- }
2311
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: AuthCallbackComponent, decorators: [{
2312
- type: Component,
2313
- args: [{
2314
- template: '<div class="loading-dead-spinner"></div>'
2315
- }]
2316
- }], ctorParameters: () => [{ type: i1$1.ActivatedRoute }, { type: i1$1.Router }, { type: i1.HttpClient }, { type: AdbUserService }] });
2317
-
2318
2310
  const routes = [
2319
2311
  { path: 'auth-callback', component: AuthCallbackComponent }
2320
2312
  ];
@@ -2325,8 +2317,8 @@ class AdbUserModule {
2325
2317
  providers: [
2326
2318
  {
2327
2319
  provide: ADB_USER_SERVICE_CONFIG,
2328
- useValue: { ...DEFAULT_ADB_USER_SERVICE_CONFIG, ...config },
2329
- },
2320
+ useValue: { ...DEFAULT_ADB_USER_SERVICE_CONFIG, ...config }
2321
+ }
2330
2322
  ],
2331
2323
  };
2332
2324
  }
@@ -2366,5 +2358,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImpor
2366
2358
  * Generated bundle index. Do not edit.
2367
2359
  */
2368
2360
 
2369
- 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, 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, ToastType, UserModuleConstants };
2370
2362
  //# sourceMappingURL=adb-shared.mjs.map