@arsedizioni/ars-utils 20.3.65 → 20.4.1

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.
@@ -192,7 +192,6 @@ interface ClipperUserInfo {
192
192
  }
193
193
  interface ClipperLoginResult extends LoginResult<ClipperUserInfo> {
194
194
  settings?: ClipperChannelSettings[];
195
- token?: string;
196
195
  }
197
196
  interface ClipperLoginInfo {
198
197
  context?: ClipperUserInfo;
@@ -969,18 +968,6 @@ declare class ClipperAuthInterceptor implements HttpInterceptor {
969
968
  private broadcastService;
970
969
  private lastErrorTime;
971
970
  intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>;
972
- /**
973
- * Handle 401 error
974
- * @param request : the request
975
- * @param next : the http handler
976
- */
977
- private handle401Error;
978
- /**
979
- * Add token to request
980
- * @param request : the request
981
- * @param token: the token or null to use curre3nt
982
- */
983
- private addTokenToRequest;
984
971
  static ɵfac: _angular_core.ɵɵFactoryDeclaration<ClipperAuthInterceptor, never>;
985
972
  static ɵprov: _angular_core.ɵɵInjectableDeclaration<ClipperAuthInterceptor>;
986
973
  }
@@ -990,7 +977,6 @@ declare class ClipperService implements OnDestroy {
990
977
  private broadcastServiceSubscription?;
991
978
  private broadcastService;
992
979
  private dialogService;
993
- private keepAlive;
994
980
  private _appUri?;
995
981
  get appUri(): string | undefined;
996
982
  private _serviceUri;
@@ -1025,30 +1011,9 @@ declare class ClipperService implements OnDestroy {
1025
1011
  */
1026
1012
  initialize(serviceUri: string, appUri?: string, flags?: ClipperServiceFlags): void;
1027
1013
  /**
1028
- * Get access token expiration date
1029
- */
1030
- private getTokenExpirationDate;
1031
- /**
1032
- * Set keep alive
1033
- */
1034
- private setKeepAlive;
1035
- /**
1036
- * Remove keep alive
1037
- */
1038
- private removeKeepAlive;
1039
- /**
1040
1014
  * Ping
1041
1015
  */
1042
1016
  ping(): void;
1043
- /**
1044
- * Set JWT tokens
1045
- * @param value : the login result
1046
- */
1047
- private setToken;
1048
- /**
1049
- * Return current auth token
1050
- */
1051
- getAuthToken(): string | undefined;
1052
1017
  /**
1053
1018
  * Store context
1054
1019
  */
@@ -1102,10 +1067,6 @@ declare class ClipperService implements OnDestroy {
1102
1067
  */
1103
1068
  clear(clearOAuthToken?: boolean): void;
1104
1069
  /**
1105
- * Perform token refresh
1106
- */
1107
- refresh(): rxjs.Observable<ApiResult<ClipperLoginResult>>;
1108
- /**
1109
1070
  * Initialize channels
1110
1071
  */
1111
1072
  private initializeChannels;
package/core/index.d.ts CHANGED
@@ -565,7 +565,6 @@ declare class DateInterval {
565
565
  interface LoginResult<T> extends ApiResult<boolean> {
566
566
  context: T;
567
567
  oauth?: number;
568
- authToken: string;
569
568
  requiresMfa?: boolean;
570
569
  }
571
570
 
@@ -16,7 +16,6 @@ declare const EvolutionMessages: {
16
16
  };
17
17
 
18
18
  interface EvolutionLoginResult extends LoginResult<EvolutionUserInfo> {
19
- token?: string;
20
19
  }
21
20
  interface EvolutionLoginInfo {
22
21
  context: EvolutionUserInfo;
@@ -701,18 +700,6 @@ declare class EvolutionAuthInterceptor implements HttpInterceptor {
701
700
  private broadcastService;
702
701
  private lastErrorTime;
703
702
  intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>;
704
- /**
705
- * Handle 401 error
706
- * @param request : the request
707
- * @param next : the http handler
708
- */
709
- private handle401Error;
710
- /**
711
- * Add token to request
712
- * @param request : the request
713
- * @param token: the token or null to use curre3nt
714
- */
715
- private addTokenToRequest;
716
703
  static ɵfac: i0.ɵɵFactoryDeclaration<EvolutionAuthInterceptor, never>;
717
704
  static ɵprov: i0.ɵɵInjectableDeclaration<EvolutionAuthInterceptor>;
718
705
  }
@@ -730,7 +717,6 @@ declare class EvolutionService implements OnDestroy {
730
717
  get loginInfo(): EvolutionLoginInfo | undefined;
731
718
  readonly loggedIn: i0.WritableSignal<boolean>;
732
719
  readonly loggingIn: i0.WritableSignal<boolean>;
733
- private keepAlive;
734
720
  ngOnDestroy(): void;
735
721
  /**
736
722
  * Initialize service
@@ -739,31 +725,10 @@ declare class EvolutionService implements OnDestroy {
739
725
  */
740
726
  initialize(serviceUri: string, flags?: EvolutionServiceFlags): void;
741
727
  /**
742
- * Get access token expiration date
743
- */
744
- private getTokenExpirationDate;
745
- /**
746
- * Set keep alive
747
- */
748
- private setKeepAlive;
749
- /**
750
- * Remove keep alive
751
- */
752
- private removeKeepAlive;
753
- /**
754
728
  * Ping
755
729
  */
756
730
  ping(): void;
757
731
  /**
758
- * Set auth token
759
- * @param value : the login result
760
- */
761
- private setToken;
762
- /**
763
- * Return current auth token
764
- */
765
- getAuthToken(): string | undefined;
766
- /**
767
732
  * Store login info
768
733
  */
769
734
  storeContext(): void;
@@ -820,10 +785,6 @@ declare class EvolutionService implements OnDestroy {
820
785
  * @param clearOAuthToken: true to clear oauth token also
821
786
  */
822
787
  clear(clearOAuthToken?: boolean): void;
823
- /**
824
- * Perform token refresh
825
- */
826
- refresh(): rxjs.Observable<ApiResult<EvolutionLoginResult>>;
827
788
  /**
828
789
  * Convert folders in a tree of Node object.
829
790
  * @param folders : the subfolders group or null to root
@@ -1,8 +1,8 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { signal, computed, inject, Injectable, NgModule } from '@angular/core';
3
- import { HttpClient, HttpHeaders, HttpRequest, HttpErrorResponse } from '@angular/common/http';
4
3
  import { BroadcastService, SystemUtils } from '@arsedizioni/ars-utils/core';
5
- import { EMPTY, throwError, of, catchError as catchError$1, switchMap } from 'rxjs';
4
+ import { EMPTY, throwError, of, catchError as catchError$1 } from 'rxjs';
5
+ import { HttpClient, HttpHeaders, HttpRequest } from '@angular/common/http';
6
6
  import { DialogService } from '@arsedizioni/ars-utils/ui';
7
7
  import { catchError, finalize, map } from 'rxjs/operators';
8
8
 
@@ -1996,7 +1996,6 @@ class ClipperService {
1996
1996
  this.httpClient = inject(HttpClient);
1997
1997
  this.broadcastService = inject(BroadcastService);
1998
1998
  this.dialogService = inject(DialogService);
1999
- this.keepAlive = 0;
2000
1999
  this._serviceUri = '';
2001
2000
  this._flags = ClipperServiceFlags.None;
2002
2001
  this.loggedIn = signal(sessionStorage.getItem("clipper_oauth_token") !== null, ...(ngDevMode ? [{ debugName: "loggedIn" }] : []));
@@ -2050,7 +2049,6 @@ class ClipperService {
2050
2049
  if (this.broadcastServiceSubscription) {
2051
2050
  this.broadcastServiceSubscription.unsubscribe();
2052
2051
  }
2053
- this.removeKeepAlive();
2054
2052
  }
2055
2053
  /**
2056
2054
  * Initialize service
@@ -2112,14 +2110,9 @@ class ClipperService {
2112
2110
  });
2113
2111
  }
2114
2112
  // Eveluate current session storage in case of page refresh (F5)
2115
- const tokenExpirationDate = this.getTokenExpirationDate();
2116
- const tokenExpired = !tokenExpirationDate || tokenExpirationDate.getTime() < Date.now();
2117
- if (!tokenExpired || this.loggedIn()) {
2113
+ if (this.loggedIn()) {
2118
2114
  // Auto login
2119
- this.loggedIn.set(true);
2120
2115
  this.loggingIn.set(false);
2121
- // Keep alive
2122
- this.setKeepAlive();
2123
2116
  // Initialize channels
2124
2117
  this.initializeChannels();
2125
2118
  // Notify
@@ -2127,38 +2120,6 @@ class ClipperService {
2127
2120
  }
2128
2121
  }
2129
2122
  /**
2130
- * Get access token expiration date
2131
- */
2132
- getTokenExpirationDate() {
2133
- const token = this.getAuthToken();
2134
- if (!token || token.length === 0)
2135
- return undefined;
2136
- // Parse json object from base64 encoded jwt token
2137
- const jwtToken = JSON.parse(atob(token.split('.')[1]));
2138
- // Set a timeout to refresh the token a minute before it expires
2139
- return new Date(jwtToken.exp * 1000);
2140
- }
2141
- /**
2142
- * Set keep alive
2143
- */
2144
- setKeepAlive() {
2145
- // Keep alive every 1 min
2146
- if (this.keepAlive === 0) {
2147
- this.keepAlive = window.setInterval(() => {
2148
- this.ping();
2149
- }, 1000 * 60 * 5);
2150
- }
2151
- }
2152
- /**
2153
- * Remove keep alive
2154
- */
2155
- removeKeepAlive() {
2156
- if (this.keepAlive > 0) {
2157
- window.clearInterval(this.keepAlive);
2158
- this.keepAlive = 0;
2159
- }
2160
- }
2161
- /**
2162
2123
  * Ping
2163
2124
  */
2164
2125
  ping() {
@@ -2166,25 +2127,6 @@ class ClipperService {
2166
2127
  .pipe(catchError(() => { return EMPTY; }))
2167
2128
  .subscribe();
2168
2129
  }
2169
- /**
2170
- * Set JWT tokens
2171
- * @param value : the login result
2172
- */
2173
- setToken(value) {
2174
- if (value.authToken ?? value.token) {
2175
- sessionStorage.setItem('clipper_auth', value.authToken ?? value.token);
2176
- }
2177
- }
2178
- /**
2179
- * Return current auth token
2180
- */
2181
- getAuthToken() {
2182
- let token = sessionStorage.getItem('clipper_auth');
2183
- if (token && token[0] === '"') {
2184
- return token.substring(1, token.length - 1);
2185
- }
2186
- return token;
2187
- }
2188
2130
  /**
2189
2131
  * Store context
2190
2132
  */
@@ -2201,7 +2143,6 @@ class ClipperService {
2201
2143
  }
2202
2144
  this._loginInfo.context = result.context;
2203
2145
  this._loginInfo.channels = result.settings;
2204
- this.setToken(result);
2205
2146
  this.storeContext();
2206
2147
  }
2207
2148
  /**
@@ -2307,8 +2248,6 @@ class ClipperService {
2307
2248
  this.updateContext(result);
2308
2249
  this.loggedIn.set(!result.context?.isTemporary);
2309
2250
  this.loggingIn.set(false);
2310
- // Keep alive
2311
- this.setKeepAlive();
2312
2251
  // Initialize channels
2313
2252
  this.initializeChannels();
2314
2253
  // Notify
@@ -2337,7 +2276,6 @@ class ClipperService {
2337
2276
  logout(forget = false) {
2338
2277
  return this.httpClient.post(this._serviceUri + '/logout/?forget=' + forget, {})
2339
2278
  .pipe(finalize(() => {
2340
- this.removeKeepAlive();
2341
2279
  this.clear(true);
2342
2280
  // Clean up
2343
2281
  localStorage.removeItem('clipper_context');
@@ -2373,16 +2311,6 @@ class ClipperService {
2373
2311
  this.reset();
2374
2312
  }
2375
2313
  /**
2376
- * Perform token refresh
2377
- */
2378
- refresh() {
2379
- return this.httpClient.get(this._serviceUri + '/refresh2').pipe(map((r) => {
2380
- // Update token
2381
- this.setToken(r.value);
2382
- return r;
2383
- }));
2384
- }
2385
- /**
2386
2314
  * Initialize channels
2387
2315
  */
2388
2316
  initializeChannels() {
@@ -3129,14 +3057,9 @@ class ClipperAuthInterceptor {
3129
3057
  intercept(request, next) {
3130
3058
  if (request.url.startsWith(this.clipperService.serviceUri)) {
3131
3059
  request = request.clone({ withCredentials: true });
3132
- return next.handle(this.addTokenToRequest(request))
3060
+ return next.handle(request)
3133
3061
  .pipe(catchError$1(error => {
3134
3062
  if (error.url.startsWith(this.clipperService.serviceUri)) {
3135
- if (error instanceof HttpErrorResponse &&
3136
- error.status === 401 &&
3137
- !request.url.includes("/login")) {
3138
- return this.handle401Error(request, next);
3139
- }
3140
3063
  const errorStatus = parseInt(error.status ?? "0");
3141
3064
  if ((errorStatus > 0 && errorStatus < 500) || (this.clipperService.flags & ClipperServiceFlags.NotifySystemErrors) > 0) {
3142
3065
  const errorTime = new Date().getTime();
@@ -3169,43 +3092,6 @@ class ClipperAuthInterceptor {
3169
3092
  }
3170
3093
  return next.handle(request);
3171
3094
  }
3172
- /**
3173
- * Handle 401 error
3174
- * @param request : the request
3175
- * @param next : the http handler
3176
- */
3177
- handle401Error(request, next) {
3178
- if (this.clipperService.loggedIn()) {
3179
- return this.clipperService.refresh().pipe(switchMap(() => {
3180
- return next.handle(this.addTokenToRequest(request));
3181
- }), catchError$1(error => {
3182
- return throwError(() => error);
3183
- }));
3184
- }
3185
- return next.handle(request);
3186
- }
3187
- /**
3188
- * Add token to request
3189
- * @param request : the request
3190
- * @param token: the token or null to use curre3nt
3191
- */
3192
- addTokenToRequest(request, token) {
3193
- if (request.url.startsWith(this.clipperService.serviceUri)) {
3194
- if (this.clipperService.loggedIn()) {
3195
- if (!token)
3196
- token = this.clipperService.getAuthToken();
3197
- if (token) {
3198
- return request.clone({
3199
- setHeaders: {
3200
- Authorization: 'Bearer ' + token,
3201
- 'ngsw-bypass': 'ngsw-bypass'
3202
- },
3203
- });
3204
- }
3205
- }
3206
- }
3207
- return request;
3208
- }
3209
3095
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: ClipperAuthInterceptor, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
3210
3096
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: ClipperAuthInterceptor }); }
3211
3097
  }