@arsedizioni/ars-utils 20.2.4 → 20.2.5

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.
@@ -198,7 +198,7 @@ interface ClipperLoginInfo {
198
198
  complianceContext?: any;
199
199
  channels?: ClipperChannelSettings[];
200
200
  credentials?: string;
201
- OAUTH?: LoginOAuthType;
201
+ oauth?: LoginOAuthType;
202
202
  }
203
203
  declare class ClipperSearchParams {
204
204
  version: number;
@@ -1059,9 +1059,14 @@ declare class ClipperService implements OnDestroy {
1059
1059
  */
1060
1060
  getMFAToken(): string | null;
1061
1061
  /**
1062
- * Store login info
1062
+ * Store context
1063
1063
  */
1064
- storeLogin(): void;
1064
+ storeContext(): void;
1065
+ /**
1066
+ * Update context
1067
+ * @param newContext: the new context
1068
+ */
1069
+ updateContext(newContext?: ClipperUserInfo): void;
1065
1070
  /**
1066
1071
  * Perform auto login using current link data
1067
1072
  * @param email: the optional email if using OAuth2
package/core/index.d.ts CHANGED
@@ -567,7 +567,7 @@ interface LoginResult<T> extends ApiResult<boolean> {
567
567
  token: string;
568
568
  refreshToken?: string;
569
569
  requiresMFA?: boolean;
570
- MFAToken?: string;
570
+ mfaToken?: string;
571
571
  }
572
572
 
573
573
  declare class DateIntervalChangeDirective implements OnInit, OnDestroy {
@@ -2031,7 +2031,7 @@ class ClipperService {
2031
2031
  }
2032
2032
  get loginInfo() {
2033
2033
  if (!this._loginInfo) {
2034
- const loginInfo = localStorage.getItem('clipper_login');
2034
+ const loginInfo = localStorage.getItem('clipper_context');
2035
2035
  if (loginInfo) {
2036
2036
  try {
2037
2037
  this._loginInfo = JSON.parse(loginInfo);
@@ -2183,7 +2183,7 @@ class ClipperService {
2183
2183
  setToken(value) {
2184
2184
  sessionStorage.setItem('clipper_jwt', value.token);
2185
2185
  sessionStorage.setItem('clipper_jwt_refresh', value.refreshToken ?? '');
2186
- localStorage.setItem('clipper_mfa', value.MFAToken ?? '');
2186
+ localStorage.setItem('clipper_mfa', value.mfaToken ?? '');
2187
2187
  }
2188
2188
  /**
2189
2189
  * Return current JWT token
@@ -2203,10 +2203,22 @@ class ClipperService {
2203
2203
  return localStorage.getItem("clipper_mfa");
2204
2204
  }
2205
2205
  /**
2206
- * Store login info
2206
+ * Store context
2207
2207
  */
2208
- storeLogin() {
2209
- localStorage.setItem('clipper_login', JSON.stringify(this._loginInfo));
2208
+ storeContext() {
2209
+ localStorage.setItem('clipper_context', JSON.stringify(this._loginInfo));
2210
+ }
2211
+ /**
2212
+ * Update context
2213
+ * @param newContext: the new context
2214
+ */
2215
+ updateContext(newContext) {
2216
+ // Update login info
2217
+ if (!this._loginInfo)
2218
+ this._loginInfo = { context: newContext };
2219
+ else
2220
+ this._loginInfo.context = newContext;
2221
+ this.storeContext();
2210
2222
  }
2211
2223
  /**
2212
2224
  * Perform auto login using current link data
@@ -2285,26 +2297,25 @@ class ClipperService {
2285
2297
  })
2286
2298
  .pipe(catchError(err => {
2287
2299
  this.loggingIn.set(false);
2288
- localStorage.removeItem('clipper_login');
2300
+ localStorage.removeItem('clipper_context');
2289
2301
  localStorage.removeItem('clipper_mfa');
2290
2302
  return throwError(() => err);
2291
2303
  }), map((r) => {
2292
2304
  if (r.success) {
2293
- // Store access token
2294
- const loginInfo = {
2295
- context: r.value.context,
2296
- channels: r.value.settings,
2297
- OAUTH: oauth
2298
- };
2299
- if (!oauth) {
2300
- loginInfo.credentials =
2301
- SystemUtils.cipher(JSON.stringify({
2302
- email: email,
2303
- password: password,
2304
- remember: remember,
2305
- }), loginInfo.context.userId.toString());
2306
- this.storeLogin();
2305
+ if (!this._loginInfo)
2306
+ this._loginInfo = { context: undefined };
2307
+ this._loginInfo.oauth = oauth;
2308
+ if (!this._loginInfo.oauth) {
2309
+ this._loginInfo.credentials = SystemUtils.cipher(JSON.stringify({
2310
+ email: email,
2311
+ password: password,
2312
+ remember: remember
2313
+ }), r.value.context?.userId?.toString() ?? '');
2314
+ }
2315
+ else {
2316
+ this._loginInfo.credentials = undefined;
2307
2317
  }
2318
+ console.log(r.value.requiresMFA ?? "no");
2308
2319
  if (!oauth && r.value.requiresMFA) {
2309
2320
  // Notify login is pending
2310
2321
  this.broadcastService.sendMessage(ClipperMessages.LOGIN_PENDING);
@@ -2324,6 +2335,7 @@ class ClipperService {
2324
2335
  completeLogin(result) {
2325
2336
  // Update info
2326
2337
  this.setToken(result);
2338
+ this.updateContext(result.context);
2327
2339
  this.loggedIn.set(true);
2328
2340
  this.loggingIn.set(false);
2329
2341
  // Keep alive
@@ -2341,7 +2353,7 @@ class ClipperService {
2341
2353
  return this.httpClient
2342
2354
  .post(this._serviceUri + '/login/confirm/' + code, {})
2343
2355
  .pipe(catchError((err) => {
2344
- localStorage.removeItem('clipper_login');
2356
+ localStorage.removeItem('clipper_context');
2345
2357
  localStorage.removeItem('clipper_mfa');
2346
2358
  this.loggingIn.set(false);
2347
2359
  return throwError(() => err);
@@ -2361,7 +2373,7 @@ class ClipperService {
2361
2373
  this.removeKeepAlive();
2362
2374
  this.clear(true);
2363
2375
  // Remove credentials
2364
- localStorage.removeItem('clipper_login');
2376
+ localStorage.removeItem('clipper_context');
2365
2377
  localStorage.removeItem('clipper_mfa');
2366
2378
  }), catchError((_e) => {
2367
2379
  return of([]);
@@ -2808,7 +2820,7 @@ class ClipperService {
2808
2820
  if (params.channels) {
2809
2821
  // Update channels
2810
2822
  this._loginInfo.channels = params.channels;
2811
- this.storeLogin();
2823
+ this.storeContext();
2812
2824
  this.initializeChannels();
2813
2825
  }
2814
2826
  }
@@ -2831,7 +2843,7 @@ class ClipperService {
2831
2843
  this.dashboard.isTrial = r.value.isTrial;
2832
2844
  this.dashboard.items.set(r.value.items ?? []);
2833
2845
  this.broadcastService.sendMessage(ClipperMessages.COMMAND_DASHBOARD_UPDATED);
2834
- this.storeLogin();
2846
+ this.storeContext();
2835
2847
  this.initializeChannels();
2836
2848
  }
2837
2849
  return r;