@seniorsistemas/components-ai 2.0.0 → 2.0.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.
@@ -4,7 +4,7 @@ import * as i2 from '@angular/common';
4
4
  import { CommonModule, DOCUMENT } from '@angular/common';
5
5
  import * as i1 from '@angular/common/http';
6
6
  import { HttpParams } from '@angular/common/http';
7
- import { throwError, BehaviorSubject, of, Subject, filter, takeUntil, share, from, concatMap, catchError as catchError$1 } from 'rxjs';
7
+ import { throwError, of, BehaviorSubject, Subject, filter, takeUntil, share, from, concatMap, catchError as catchError$1 } from 'rxjs';
8
8
  import { map, catchError, filter as filter$1, debounceTime, distinctUntilChanged } from 'rxjs/operators';
9
9
  import * as i1$1 from 'primeng/config';
10
10
  import { providePrimeNG } from 'primeng/config';
@@ -392,155 +392,62 @@ class AuthService {
392
392
  TOKEN_COOKIE_NAME = 'com.senior.token';
393
393
  API_URL_COOKIE_NAME = 'com.senior.base.url';
394
394
  API_PATH_SUFFIX = '/t/senior.com.br/bridge/1.0/rest';
395
- currentUserSubject = new BehaviorSubject(null);
396
- currentUser$ = this.currentUserSubject.asObservable();
397
395
  constructor(cookieService) {
398
396
  this.cookieService = cookieService;
399
- this.loadUserFromCookie();
400
397
  }
401
398
  /**
402
- * Load user token from cookie
399
+ * Parse token from cookie. Always reads fresh from cookie, no cache.
403
400
  */
404
- loadUserFromCookie() {
401
+ parseTokenFromCookie() {
405
402
  const tokenString = this.cookieService.getCookie(this.TOKEN_COOKIE_NAME);
406
- if (tokenString) {
407
- try {
408
- const token = JSON.parse(tokenString);
409
- if (this.isTokenValid(token)) {
410
- this.currentUserSubject.next(token);
411
- }
412
- else {
413
- this.currentUserSubject.next(null);
414
- }
415
- }
416
- catch (error) {
417
- console.error('[AuthService] Error parsing token from cookie:', error);
418
- this.currentUserSubject.next(null);
419
- }
403
+ if (!tokenString)
404
+ return null;
405
+ try {
406
+ const token = JSON.parse(tokenString);
407
+ return token?.access_token ? token : null;
408
+ }
409
+ catch {
410
+ return null;
420
411
  }
421
412
  }
422
- /**
423
- * Get current user token
424
- */
425
413
  getCurrentUser() {
426
- return this.currentUserSubject.value;
414
+ return this.parseTokenFromCookie();
427
415
  }
428
- /**
429
- * Get access token
430
- */
431
416
  getAccessToken() {
432
- const user = this.getCurrentUser();
433
- return user?.access_token || null;
417
+ return this.parseTokenFromCookie()?.access_token || null;
434
418
  }
435
- /**
436
- * Get token type (e.g., "Bearer")
437
- */
438
419
  getTokenType() {
439
- const user = this.getCurrentUser();
440
- return user?.token_type || 'Bearer';
420
+ return this.parseTokenFromCookie()?.token_type || 'Bearer';
441
421
  }
442
- /**
443
- * Get refresh token
444
- */
445
422
  getRefreshToken() {
446
- const user = this.getCurrentUser();
447
- return user?.refresh_token || null;
423
+ return this.parseTokenFromCookie()?.refresh_token || null;
448
424
  }
449
- /**
450
- * Get API base URL from cookie
451
- */
452
425
  getApiBaseUrl() {
453
426
  const baseUrl = this.cookieService.getCookie(this.API_URL_COOKIE_NAME);
454
- // In development, use proxy
455
427
  if (!baseUrl) {
456
- // Check if we're in development mode
457
428
  const isDevelopment = !window.location.hostname.includes('senior.com.br');
458
- if (isDevelopment) {
459
- return '/api';
460
- }
461
- return null;
429
+ return isDevelopment ? '/api' : null;
462
430
  }
463
- // Remove trailing slash from base URL
464
- const cleanBaseUrl = baseUrl.replace(/\/$/, '');
465
- // Combine with API path suffix
466
- return `${cleanBaseUrl}${this.API_PATH_SUFFIX}`;
431
+ return `${baseUrl.replace(/\/$/, '')}${this.API_PATH_SUFFIX}`;
467
432
  }
468
- /**
469
- * Check if user is authenticated
470
- */
471
433
  isAuthenticated() {
472
- const user = this.getCurrentUser();
473
- return user !== null && this.isTokenValid(user);
434
+ const user = this.parseTokenFromCookie();
435
+ return user !== null;
474
436
  }
475
- /**
476
- * Check if token is valid (not expired)
477
- */
478
- isTokenValid(token) {
479
- if (!token || !token.access_token) {
480
- return false;
481
- }
482
- // Check if token is expired
483
- const now = Math.floor(Date.now() / 1000);
484
- const tokenExpiry = token.expires_in;
485
- // If expires_in is a timestamp, compare directly
486
- // If it's a duration, we'd need the token creation time
487
- // For now, assume it's a timestamp
488
- // If expires_in is very large (like a duration in seconds), skip expiry check
489
- if (tokenExpiry > 1000000000) {
490
- // Looks like a timestamp
491
- return tokenExpiry > now;
492
- }
493
- else {
494
- // Looks like a duration, assume token is valid
495
- return true;
496
- }
497
- }
498
- /**
499
- * Check if refresh token is valid
500
- */
501
- isRefreshTokenValid() {
502
- const user = this.getCurrentUser();
503
- if (!user || !user.refresh_token) {
504
- return false;
505
- }
506
- const now = Math.floor(Date.now() / 1000);
507
- const refreshExpiry = user.refresh_expires_in;
508
- return refreshExpiry > now;
509
- }
510
- /**
511
- * Get user locale
512
- */
513
437
  getUserLocale() {
514
- const user = this.getCurrentUser();
515
- return user?.locale || 'pt-BR';
438
+ return this.parseTokenFromCookie()?.locale || 'pt-BR';
516
439
  }
517
- /**
518
- * Get user full name
519
- */
520
440
  getUserFullName() {
521
- const user = this.getCurrentUser();
522
- return user?.fullName || '';
441
+ return this.parseTokenFromCookie()?.fullName || '';
523
442
  }
524
- /**
525
- * Get user email
526
- */
527
443
  getUserEmail() {
528
- const user = this.getCurrentUser();
529
- return user?.email || '';
444
+ return this.parseTokenFromCookie()?.email || '';
530
445
  }
531
- /**
532
- * Get tenant name
533
- */
534
446
  getTenantName() {
535
- const user = this.getCurrentUser();
536
- return user?.tenantName || '';
447
+ return this.parseTokenFromCookie()?.tenantName || '';
537
448
  }
538
- /**
539
- * Get username
540
- */
541
449
  getUsername() {
542
- const user = this.getCurrentUser();
543
- return user?.username || '';
450
+ return this.parseTokenFromCookie()?.username || '';
544
451
  }
545
452
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: AuthService, deps: [{ token: CookieService }], target: i0.ɵɵFactoryTarget.Injectable });
546
453
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: AuthService, providedIn: 'root' });
@@ -5767,9 +5674,11 @@ class DynamicFormComponent {
5767
5674
  if (target.tagName === 'TEXTAREA')
5768
5675
  return;
5769
5676
  event.preventDefault();
5770
- // In inline-edit mode, Enter saves the current field
5771
- if (this.isInlineEditMode && this.editingField) {
5772
- this.saveInlineField(this.editingField);
5677
+ // In inline-edit mode, Enter saves the current field but never triggers form submit
5678
+ if (this.isInlineEditMode) {
5679
+ if (this.editingField) {
5680
+ this.saveInlineField(this.editingField);
5681
+ }
5773
5682
  }
5774
5683
  else {
5775
5684
  this.handleSubmit();