@arsedizioni/ars-utils 20.2.33 → 20.3.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.
@@ -1009,7 +1009,6 @@ declare class ClipperService implements OnDestroy {
1009
1009
  readonly loggingIn: _angular_core.WritableSignal<boolean>;
1010
1010
  readonly snapshot: _angular_core.WritableSignal<ClipperSearchResult>;
1011
1011
  readonly supportsRS: _angular_core.WritableSignal<boolean>;
1012
- readonly shouldRefreshToken: _angular_core.WritableSignal<boolean>;
1013
1012
  readonly referencesSnapshot: _angular_core.WritableSignal<ClipperSearchResult>;
1014
1013
  readonly dashboard: ClipperDashboard;
1015
1014
  readonly bag: _angular_core.WritableSignal<ClipperDocumentInfo[]>;
@@ -1035,10 +1034,6 @@ declare class ClipperService implements OnDestroy {
1035
1034
  * Get access token expiration date
1036
1035
  */
1037
1036
  private getTokenExpirationDate;
1038
- /**
1039
- * Checks if access token in expired
1040
- */
1041
- isTokenExpired(): boolean;
1042
1037
  /**
1043
1038
  * Set keep alive
1044
1039
  */
@@ -1058,17 +1053,12 @@ declare class ClipperService implements OnDestroy {
1058
1053
  private setToken;
1059
1054
  /**
1060
1055
  * Return current auth token
1061
- * @param refresh: true to get the refresh token. Default is false.
1062
1056
  */
1063
- getAuthToken(refresh?: boolean): string | undefined;
1057
+ getAuthToken(): string | undefined;
1064
1058
  /**
1065
1059
  * Get the two form factor authentication token
1066
1060
  */
1067
1061
  getRememberToken(): string | null;
1068
- /**
1069
- * Get the two form factor authentication token
1070
- */
1071
- getMfaToken(): string | null;
1072
1062
  /**
1073
1063
  * Store context
1074
1064
  */
@@ -1118,9 +1108,8 @@ declare class ClipperService implements OnDestroy {
1118
1108
  confirmIdentity(code: string, flags?: number): rxjs.Observable<ApiResult<ClipperLoginResult>>;
1119
1109
  /**
1120
1110
  * Perform logout
1121
- * @param soft: true if is a soft logout (mfa and remember tokens remains). Default is false.
1122
1111
  */
1123
- logout(soft?: boolean): rxjs.Observable<any>;
1112
+ logout(): rxjs.Observable<any>;
1124
1113
  /**
1125
1114
  * Reset login refresh timer and login state
1126
1115
  */
package/core/index.d.ts CHANGED
@@ -564,11 +564,10 @@ declare class DateInterval {
564
564
  }
565
565
  interface LoginResult<T> extends ApiResult<boolean> {
566
566
  context: T;
567
+ oauth?: number;
567
568
  authToken: string;
568
- refreshToken?: string;
569
569
  rememberToken?: string;
570
570
  requiresMfa?: boolean;
571
- mfaToken?: string;
572
571
  }
573
572
 
574
573
  declare class DateIntervalChangeDirective implements OnInit, OnDestroy {
@@ -11,16 +11,23 @@ declare const EvolutionMessages: {
11
11
  LOGIN_CHANGED: string;
12
12
  LOGIN_COMPLETED: string;
13
13
  LOGOUT_COMPLETED: string;
14
+ LOGIN_PENDING: string;
14
15
  LOGOUT: string;
15
16
  };
16
17
 
18
+ declare enum EvolutionLoginFlags {
19
+ None = 0,
20
+ RememberCredentials = 1,
21
+ DisableMfa = 2,
22
+ ExtendMfaValidity = 4,
23
+ ExtendRememberCredentialsValidity = 8
24
+ }
17
25
  interface EvolutionLoginResult extends LoginResult<EvolutionUserInfo> {
18
26
  token?: string;
19
27
  }
20
28
  interface EvolutionLoginInfo {
21
29
  context: EvolutionUserInfo;
22
- userCredentials?: string;
23
- OAUTH?: LoginOAuthType;
30
+ oauth?: LoginOAuthType;
24
31
  }
25
32
  interface EvolutionUserLink {
26
33
  id?: number;
@@ -726,10 +733,9 @@ declare class EvolutionService implements OnDestroy {
726
733
  private _flags;
727
734
  get flags(): EvolutionServiceFlags;
728
735
  private _loginInfo?;
729
- get loginInfo(): EvolutionUserInfo | undefined;
736
+ get loginInfo(): EvolutionLoginInfo | undefined;
730
737
  readonly loggedIn: i0.WritableSignal<boolean>;
731
738
  readonly loggingIn: i0.WritableSignal<boolean>;
732
- readonly shouldRefreshToken: i0.WritableSignal<boolean>;
733
739
  private keepAlive;
734
740
  ngOnDestroy(): void;
735
741
  /**
@@ -742,10 +748,6 @@ declare class EvolutionService implements OnDestroy {
742
748
  * Get access token expiration date
743
749
  */
744
750
  private getTokenExpirationDate;
745
- /**
746
- * Checks if access token in expired
747
- */
748
- isTokenExpired(): boolean;
749
751
  /**
750
752
  * Set keep alive
751
753
  */
@@ -767,11 +769,20 @@ declare class EvolutionService implements OnDestroy {
767
769
  * Return current JWT token
768
770
  * @param refresh: true to get the refresh token. Default is false.
769
771
  */
770
- getToken(refresh?: boolean): string | undefined;
772
+ getAuthToken(): string | undefined;
773
+ /**
774
+ * Get the two form factor authentication token
775
+ */
776
+ getRememberToken(): string | undefined;
771
777
  /**
772
778
  * Store login info
773
779
  */
774
- storeLogin(): void;
780
+ storeContext(): void;
781
+ /**
782
+ * Update context
783
+ * @param result: the new context
784
+ */
785
+ updateContext(result: EvolutionLoginResult): void;
775
786
  /**
776
787
  * Perform auto login using current link data
777
788
  * @param email: the optional email if using OAuth2
@@ -781,7 +792,7 @@ declare class EvolutionService implements OnDestroy {
781
792
  * @param oauthAccessToken: the optional OAuth2 access token
782
793
  * @param onSuccess: function to execute on seccess
783
794
  */
784
- autoLogin(email?: string, password?: string, remember?: boolean, oauth?: LoginOAuthType, oauthAccessToken?: string, onSuccess?: Function): boolean;
795
+ autoLogin(email?: string, password?: string, remember?: boolean, oauth?: LoginOAuthType, oauthAccessToken?: string, onSuccess?: Function, flags?: EvolutionLoginFlags): boolean;
785
796
  /**
786
797
  * Perform auto logout
787
798
  * @param onSuccess: function to execute on seccess
@@ -794,9 +805,21 @@ declare class EvolutionService implements OnDestroy {
794
805
  * @param remember: remember credentials
795
806
  * @param oauth: the optional open authentication supported
796
807
  * @param oauthAccessToken: the optional OAuth2 access token
808
+ * @param flags: the optional login flags
797
809
  * @returns: the login result
798
810
  */
799
- login(email?: string, password?: string, remember?: boolean, oauth?: LoginOAuthType, oauthAccessToken?: string): rxjs.Observable<ApiResult<EvolutionLoginResult>>;
811
+ login(email?: string, password?: string, remember?: boolean, oauth?: LoginOAuthType, oauthAccessToken?: string, flags?: EvolutionLoginFlags): rxjs.Observable<ApiResult<EvolutionLoginResult>>;
812
+ /**
813
+ * Complete login
814
+ * @param result : the login result
815
+ */
816
+ private completeLogin;
817
+ /**
818
+ * Confirm MFA procedure
819
+ * @param code: the confirm code
820
+ * @param flags: the login flags
821
+ */
822
+ confirmIdentity(code: string, flags?: number): rxjs.Observable<ApiResult<EvolutionLoginResult>>;
800
823
  /**
801
824
  * Perform logout
802
825
  */
@@ -806,18 +829,15 @@ declare class EvolutionService implements OnDestroy {
806
829
  * @param id : new user id
807
830
  */
808
831
  loginSwitch(id: number): rxjs.Observable<ApiResult<EvolutionLoginResult>>;
809
- /**
810
- * Handle login error
811
- */
812
- private handleLoginError;
813
832
  /**
814
833
  * Reset login refresh timer and login state
815
834
  */
816
835
  reset(): void;
817
836
  /**
818
837
  * Clear login data
838
+ * @param clearOAuthToken: true to clear oauth token also
819
839
  */
820
- clear(): void;
840
+ clear(clearOAuthToken?: boolean): void;
821
841
  /**
822
842
  * Perform token refresh
823
843
  */
@@ -891,5 +911,5 @@ declare class EvolutionCommonModule {
891
911
  static ɵinj: i0.ɵɵInjectorDeclaration<EvolutionCommonModule>;
892
912
  }
893
913
 
894
- export { ERPComplianceActivityState, ERPComplianceLawOrigin, ERPComplianceLawState, ERPComplianceLawsSelectionType, ERPComplianceNotificationLimit, ERPComplianceProfileFlags, ERPComplianceProfileRole, ERPComplianceRegisterNotificationType, ERPComplianceRegisterSiteImportOptions, ERPComplianceScope, ERPExportFormat, ERPExportPart, ERPExportSource, ERPExportType, ERPModule, ERPPlace, ERPPlacePermission, ERPRecurrenceFrequencyType, EvolutionAuthInterceptor, EvolutionCommonModule, EvolutionComplianceActivityStates, EvolutionComplianceContextInfo, EvolutionComplianceLawChangeStates, EvolutionComplianceLawOrigins, EvolutionComplianceLawStates, EvolutionComplianceNotificationLimits, EvolutionComplianceNotifications, EvolutionComplianceObligationAuthorities, EvolutionComplianceObligationTypes, EvolutionComplianceProfileFlags, EvolutionComplianceProfileRoles, EvolutionComplianceScopes, EvolutionMessages, EvolutionRecurrenceFrequencyTypes, EvolutionService, EvolutionServiceFlags };
914
+ export { ERPComplianceActivityState, ERPComplianceLawOrigin, ERPComplianceLawState, ERPComplianceLawsSelectionType, ERPComplianceNotificationLimit, ERPComplianceProfileFlags, ERPComplianceProfileRole, ERPComplianceRegisterNotificationType, ERPComplianceRegisterSiteImportOptions, ERPComplianceScope, ERPExportFormat, ERPExportPart, ERPExportSource, ERPExportType, ERPModule, ERPPlace, ERPPlacePermission, ERPRecurrenceFrequencyType, EvolutionAuthInterceptor, EvolutionCommonModule, EvolutionComplianceActivityStates, EvolutionComplianceContextInfo, EvolutionComplianceLawChangeStates, EvolutionComplianceLawOrigins, EvolutionComplianceLawStates, EvolutionComplianceNotificationLimits, EvolutionComplianceNotifications, EvolutionComplianceObligationAuthorities, EvolutionComplianceObligationTypes, EvolutionComplianceProfileFlags, EvolutionComplianceProfileRoles, EvolutionComplianceScopes, EvolutionLoginFlags, EvolutionMessages, EvolutionRecurrenceFrequencyTypes, EvolutionService, EvolutionServiceFlags };
895
915
  export type { ComplianceRegisterUsersResultModel, EvolutionChangeContextModel, EvolutionChangeContextResultModel, EvolutionComplianceActivitiesAddParams, EvolutionComplianceActivity, EvolutionComplianceLaswExportParams, EvolutionComplianceLaw, EvolutionComplianceLawDocumentInfo, EvolutionComplianceLawReference, EvolutionComplianceLawsAddParams, EvolutionComplianceRegister, EvolutionComplianceRegisterProfile, EvolutionComplianceRegisterSite, EvolutionContextInfo, EvolutionExportModel, EvolutionLicenceModuleInfo, EvolutionLoginInfo, EvolutionLoginResult, EvolutionPermission, EvolutionPlacePermission, EvolutionPlaceable, EvolutionQueryRegisterProfilesModel, EvolutionRegisterProfileSiteInfo, EvolutionRegisterProfileUserInfo, EvolutionUserInfo, EvolutionUserLink, EvolutionUserModuleInfo };
@@ -2011,7 +2011,6 @@ class ClipperService {
2011
2011
  this.loggingIn = signal(false, ...(ngDevMode ? [{ debugName: "loggingIn" }] : []));
2012
2012
  this.snapshot = signal(undefined, ...(ngDevMode ? [{ debugName: "snapshot" }] : []));
2013
2013
  this.supportsRS = signal(false, ...(ngDevMode ? [{ debugName: "supportsRS" }] : []));
2014
- this.shouldRefreshToken = signal(false, ...(ngDevMode ? [{ debugName: "shouldRefreshToken" }] : []));
2015
2014
  this.referencesSnapshot = signal(undefined, ...(ngDevMode ? [{ debugName: "referencesSnapshot" }] : []));
2016
2015
  this.dashboard = new ClipperDashboard();
2017
2016
  this.bag = signal([], ...(ngDevMode ? [{ debugName: "bag" }] : []));
@@ -2101,7 +2100,7 @@ class ClipperService {
2101
2100
  }
2102
2101
  else if (message.id === ClipperMessages.LOGOUT) {
2103
2102
  if (this.loggedIn()) {
2104
- this.logout(true).subscribe(r => {
2103
+ this.logout().subscribe(r => {
2105
2104
  if (!r.success) {
2106
2105
  if (r.message) {
2107
2106
  this.dialogService.error("<p>" + r.message + "</p><br><br><hr><p class='small'><i>Per eliminare la configurazione di Clipper accedere a:<br><b>menu > personalizza > collegamenti</b></i></p>", undefined, "Errore di Clipper");
@@ -2128,8 +2127,6 @@ class ClipperService {
2128
2127
  if (!tokenExpired || this.loggedIn()) {
2129
2128
  // Auto login
2130
2129
  this.loggedIn.set(true);
2131
- // Should refresh
2132
- this.shouldRefreshToken.set(!!tokenExpirationDate);
2133
2130
  // Keep alive
2134
2131
  this.setKeepAlive();
2135
2132
  // Initialize channels
@@ -2150,14 +2147,6 @@ class ClipperService {
2150
2147
  // Set a timeout to refresh the token a minute before it expires
2151
2148
  return new Date(jwtToken.exp * 1000);
2152
2149
  }
2153
- /**
2154
- * Checks if access token in expired
2155
- */
2156
- isTokenExpired() {
2157
- const expires = this.getTokenExpirationDate();
2158
- const expired = !expires || expires.getTime() < Date.now();
2159
- return expired;
2160
- }
2161
2150
  /**
2162
2151
  * Set keep alive
2163
2152
  */
@@ -2194,22 +2183,15 @@ class ClipperService {
2194
2183
  if (value.authToken ?? value.token) {
2195
2184
  sessionStorage.setItem('clipper_auth', value.authToken ?? value.token);
2196
2185
  }
2197
- if (value.refreshToken) {
2198
- sessionStorage.setItem('clipper_refresh', value.refreshToken);
2199
- }
2200
2186
  if (value.rememberToken) {
2201
2187
  localStorage.setItem('clipper_remember', value.rememberToken);
2202
2188
  }
2203
- if (value.mfaToken) {
2204
- localStorage.setItem('clipper_mfa', value.mfaToken);
2205
- }
2206
2189
  }
2207
2190
  /**
2208
2191
  * Return current auth token
2209
- * @param refresh: true to get the refresh token. Default is false.
2210
2192
  */
2211
- getAuthToken(refresh = false) {
2212
- let token = sessionStorage.getItem(refresh ? 'clipper_refresh' : 'clipper_auth');
2193
+ getAuthToken() {
2194
+ let token = sessionStorage.getItem('clipper_auth');
2213
2195
  if (token && token[0] === '"') {
2214
2196
  return token.substring(1, token.length - 1);
2215
2197
  }
@@ -2221,12 +2203,6 @@ class ClipperService {
2221
2203
  getRememberToken() {
2222
2204
  return localStorage.getItem("clipper_remember");
2223
2205
  }
2224
- /**
2225
- * Get the two form factor authentication token
2226
- */
2227
- getMfaToken() {
2228
- return localStorage.getItem("clipper_mfa");
2229
- }
2230
2206
  /**
2231
2207
  * Store context
2232
2208
  */
@@ -2260,7 +2236,7 @@ class ClipperService {
2260
2236
  if (remember) {
2261
2237
  flags |= ClipperLoginFlags.RememberCredentials;
2262
2238
  }
2263
- this.login(email, password, remember, oauth, oauthAccessToken, flags)
2239
+ this.login(email ?? this.getRememberToken(), password, remember, oauth, oauthAccessToken, flags)
2264
2240
  .subscribe({
2265
2241
  next: r => {
2266
2242
  if (!r.success) {
@@ -2284,10 +2260,11 @@ class ClipperService {
2284
2260
  autoLogout(onSuccess) {
2285
2261
  if (!this.loggedIn())
2286
2262
  return;
2287
- this.logout(true).subscribe({
2263
+ this.logout().subscribe({
2288
2264
  next: r => {
2289
2265
  if (!r.success) {
2290
2266
  this.dialogService.error(r.message, undefined, "Errore in Clipper");
2267
+ this.broadcastService.sendMessage(ClipperMessages.LOGIN_CHANGED);
2291
2268
  }
2292
2269
  else {
2293
2270
  this.dialogService.toast('Disconnesso da Clipper', 1500, 'power_off');
@@ -2326,14 +2303,12 @@ class ClipperService {
2326
2303
  }, {
2327
2304
  headers: !oauth || !oauthAccessToken
2328
2305
  ? new HttpHeaders()
2329
- .set("X-MFA", this.getMfaToken() ?? '')
2330
2306
  : new HttpHeaders()
2331
2307
  .set("Authorization", 'Bearer ' + oauthAccessToken)
2332
2308
  })
2333
2309
  .pipe(catchError(err => {
2334
2310
  this.loggingIn.set(false);
2335
2311
  localStorage.removeItem('clipper_context');
2336
- localStorage.removeItem('clipper_mfa');
2337
2312
  localStorage.removeItem('clipper_remember');
2338
2313
  return throwError(() => err);
2339
2314
  }), map((r) => {
@@ -2379,7 +2354,6 @@ class ClipperService {
2379
2354
  .post(this._serviceUri + '/login/confirm/' + code + '/?flags=' + flags, {})
2380
2355
  .pipe(catchError((err) => {
2381
2356
  localStorage.removeItem('clipper_context');
2382
- localStorage.removeItem('clipper_mfa');
2383
2357
  localStorage.removeItem('clipper_remember');
2384
2358
  this.loggingIn.set(false);
2385
2359
  return throwError(() => err);
@@ -2393,18 +2367,14 @@ class ClipperService {
2393
2367
  }
2394
2368
  /**
2395
2369
  * Perform logout
2396
- * @param soft: true if is a soft logout (mfa and remember tokens remains). Default is false.
2397
2370
  */
2398
- logout(soft = false) {
2371
+ logout() {
2399
2372
  return this.httpClient.post(this._serviceUri + '/logout', {}).pipe(finalize(() => {
2400
2373
  this.removeKeepAlive();
2401
2374
  this.clear(true);
2402
- // Remove credentials
2375
+ // Clean up
2403
2376
  localStorage.removeItem('clipper_context');
2404
2377
  localStorage.removeItem('clipper_remember');
2405
- if (!soft) {
2406
- localStorage.removeItem('clipper_mfa');
2407
- }
2408
2378
  }), catchError((_e) => {
2409
2379
  return of([]);
2410
2380
  }));
@@ -2428,8 +2398,8 @@ class ClipperService {
2428
2398
  */
2429
2399
  clear(clearOAuthToken = false) {
2430
2400
  // Clear local storage
2401
+ localStorage.removeItem('clipper_context');
2431
2402
  sessionStorage.removeItem('clipper_auth');
2432
- sessionStorage.removeItem('clipper_refresh');
2433
2403
  sessionStorage.removeItem('clipper_oauth');
2434
2404
  if (clearOAuthToken) {
2435
2405
  sessionStorage.removeItem('clipper_oauth_token');
@@ -2441,7 +2411,7 @@ class ClipperService {
2441
2411
  * Perform token refresh
2442
2412
  */
2443
2413
  refresh() {
2444
- return this.httpClient.get(this._serviceUri + '/refresh2/?token=' + this.getAuthToken(true)).pipe(map((r) => {
2414
+ return this.httpClient.get(this._serviceUri + '/refresh2').pipe(map((r) => {
2445
2415
  // Update token
2446
2416
  this.setToken(r.value);
2447
2417
  return r;