@dev-tcloud/tcloud-ui 7.7.6 → 7.8.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.
|
@@ -2,16 +2,31 @@ import * as i0 from '@angular/core';
|
|
|
2
2
|
import { Injectable, Component, EventEmitter, Input, Output, InjectionToken, Optional, Inject, inject, signal, Pipe, forwardRef, ViewChild, input, effect, Directive, ViewEncapsulation, HostListener, HostBinding, SkipSelf, ChangeDetectionStrategy, ChangeDetectorRef, computed, ApplicationRef, output, model, numberAttribute, booleanAttribute, ContentChildren, viewChild, EnvironmentInjector, createComponent, ViewContainerRef, NgModule, makeEnvironmentProviders, DOCUMENT } from '@angular/core';
|
|
3
3
|
import * as i1$1 from '@angular/common';
|
|
4
4
|
import { DatePipe, CommonModule } from '@angular/common';
|
|
5
|
-
import { Subject, Subscription, BehaviorSubject, debounceTime, distinctUntilChanged, map } from 'rxjs';
|
|
5
|
+
import { Subject, Subscription, BehaviorSubject, firstValueFrom, debounceTime, distinctUntilChanged, map, catchError, switchMap, throwError } from 'rxjs';
|
|
6
6
|
import * as i1 from '@angular/forms';
|
|
7
7
|
import { NG_VALUE_ACCESSOR, FormsModule, FormControl, ReactiveFormsModule, NG_VALIDATORS, Validators, FormGroup } from '@angular/forms';
|
|
8
8
|
import * as i1$2 from '@angular/router';
|
|
9
9
|
import { Router, RouterModule } from '@angular/router';
|
|
10
|
+
import * as i1$3 from '@angular/common/http';
|
|
11
|
+
import { HttpClient, HttpErrorResponse, provideHttpClient, withInterceptorsFromDi, withInterceptors } from '@angular/common/http';
|
|
10
12
|
import hljs from 'highlight.js';
|
|
11
13
|
import * as i2 from 'ngx-markdown';
|
|
12
14
|
import { MarkdownModule, provideMarkdown } from 'ngx-markdown';
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
+
import { map as map$1 } from 'rxjs/operators';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Aplica os defaults da configuração de auth. Centraliza as chaves padrão
|
|
19
|
+
* (`currentUser`/`currentEnv`/versão 2) para os serviços lerem sem repetir lógica.
|
|
20
|
+
*/
|
|
21
|
+
function withAuthDefaults(config) {
|
|
22
|
+
return {
|
|
23
|
+
host: '',
|
|
24
|
+
...(config ?? {}),
|
|
25
|
+
localStorageName: config?.localStorageName ?? 'currentUser',
|
|
26
|
+
sessionStorageName: config?.sessionStorageName ?? 'currentEnv',
|
|
27
|
+
userInfoVersion: config?.userInfoVersion ?? 2,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
15
30
|
|
|
16
31
|
class TCloudUiAccordionService {
|
|
17
32
|
constructor() {
|
|
@@ -192,6 +207,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
192
207
|
* Token de injeção para a configuração do TCloud UI
|
|
193
208
|
*/
|
|
194
209
|
const TCLOUD_UI_CONFIG = new InjectionToken('TCLOUD_UI_CONFIG');
|
|
210
|
+
/**
|
|
211
|
+
* Token de injeção para a configuração do núcleo de autenticação.
|
|
212
|
+
* Alimentado pelo projeto consumidor via `provideTCloudUi({ auth: {...} })`
|
|
213
|
+
* ou `TCloudUiModule.forRoot({ auth: {...} })`.
|
|
214
|
+
*/
|
|
215
|
+
const TCLOUD_UI_AUTH_CONFIG = new InjectionToken('TCLOUD_UI_AUTH_CONFIG');
|
|
195
216
|
/**
|
|
196
217
|
* Token de injeção para o serviço de usuário customizado
|
|
197
218
|
*/
|
|
@@ -7561,11 +7582,158 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
7561
7582
|
type: Input
|
|
7562
7583
|
}] } });
|
|
7563
7584
|
|
|
7585
|
+
/**
|
|
7586
|
+
* Wrapper simples de localStorage/sessionStorage em texto plano, compartilhado
|
|
7587
|
+
* pelo núcleo de autenticação. Portado do `storage.service.ts` do front-tcloud.
|
|
7588
|
+
*
|
|
7589
|
+
* Mantém a detecção de dados legados cifrados (prefixo OpenSSL "Salted__" em
|
|
7590
|
+
* base64) apenas para descartá-los — a cifragem AES foi removida.
|
|
7591
|
+
*/
|
|
7592
|
+
class TCloudUiStorageService {
|
|
7593
|
+
constructor() {
|
|
7594
|
+
this.legacyEncryptedPrefix = 'U2FsdGVkX1';
|
|
7595
|
+
}
|
|
7596
|
+
/**
|
|
7597
|
+
* Lê o valor em texto plano. Se encontrar um dado legado cifrado, descarta-o
|
|
7598
|
+
* e retorna null, para o consumidor tratar como ausente (ex.: re-login).
|
|
7599
|
+
*/
|
|
7600
|
+
read(storage, key) {
|
|
7601
|
+
const data = storage.getItem(key);
|
|
7602
|
+
if (!data) {
|
|
7603
|
+
return null;
|
|
7604
|
+
}
|
|
7605
|
+
if (data.startsWith(this.legacyEncryptedPrefix)) {
|
|
7606
|
+
storage.removeItem(key);
|
|
7607
|
+
return null;
|
|
7608
|
+
}
|
|
7609
|
+
return data;
|
|
7610
|
+
}
|
|
7611
|
+
setLocalStorage(key, data) {
|
|
7612
|
+
localStorage.setItem(key, data);
|
|
7613
|
+
}
|
|
7614
|
+
getLocalStorage(key) {
|
|
7615
|
+
return this.read(localStorage, key);
|
|
7616
|
+
}
|
|
7617
|
+
removeLocalStorage(key) {
|
|
7618
|
+
localStorage.removeItem(key);
|
|
7619
|
+
}
|
|
7620
|
+
setSessionStorage(key, data) {
|
|
7621
|
+
sessionStorage.setItem(key, data);
|
|
7622
|
+
}
|
|
7623
|
+
getSessionStorage(key) {
|
|
7624
|
+
return this.read(sessionStorage, key);
|
|
7625
|
+
}
|
|
7626
|
+
removeSessionStorage(key) {
|
|
7627
|
+
sessionStorage.removeItem(key);
|
|
7628
|
+
}
|
|
7629
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: TCloudUiStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
7630
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: TCloudUiStorageService, providedIn: 'root' }); }
|
|
7631
|
+
}
|
|
7632
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: TCloudUiStorageService, decorators: [{
|
|
7633
|
+
type: Injectable,
|
|
7634
|
+
args: [{
|
|
7635
|
+
providedIn: 'root'
|
|
7636
|
+
}]
|
|
7637
|
+
}] });
|
|
7638
|
+
|
|
7639
|
+
/**
|
|
7640
|
+
* Núcleo de gestão da sessão do usuário, compartilhado entre os apps.
|
|
7641
|
+
* Portado do subset de autenticação do `user.service.ts` do front-tcloud —
|
|
7642
|
+
* sem as regras de negócio (billing/tss/topologias/alertify/controllers).
|
|
7643
|
+
*/
|
|
7644
|
+
class TCloudUiUserService {
|
|
7645
|
+
constructor() {
|
|
7646
|
+
this.http = inject(HttpClient);
|
|
7647
|
+
this.storageService = inject(TCloudUiStorageService);
|
|
7648
|
+
this.config = withAuthDefaults(inject(TCLOUD_UI_AUTH_CONFIG, { optional: true }));
|
|
7649
|
+
}
|
|
7650
|
+
get localStorageName() { return this.config.localStorageName; }
|
|
7651
|
+
get sessionStorageName() { return this.config.sessionStorageName; }
|
|
7652
|
+
/** Retorna o usuário logado do localStorage (ou null se ausente). */
|
|
7653
|
+
getUser() {
|
|
7654
|
+
const raw = this.storageService.getLocalStorage(this.localStorageName);
|
|
7655
|
+
return raw ? JSON.parse(raw) : null;
|
|
7656
|
+
}
|
|
7657
|
+
/** Retorna o base64 do email do usuário logado. */
|
|
7658
|
+
getUserHash() {
|
|
7659
|
+
const email = this.getUser()?.user?.email ?? '';
|
|
7660
|
+
return btoa(email);
|
|
7661
|
+
}
|
|
7662
|
+
/** Guarda o usuário logado no localStorage, carimbando o timestamp. */
|
|
7663
|
+
storeUser(user) {
|
|
7664
|
+
user.timestamp = new Date();
|
|
7665
|
+
this.storageService.setLocalStorage(this.localStorageName, JSON.stringify(user));
|
|
7666
|
+
}
|
|
7667
|
+
/** Retorna informações do ambiente da aba atual (sessionStorage). */
|
|
7668
|
+
getCurrentEnv() {
|
|
7669
|
+
const env = this.storageService.getSessionStorage(this.sessionStorageName);
|
|
7670
|
+
return env ? JSON.parse(env) : {};
|
|
7671
|
+
}
|
|
7672
|
+
/** Guarda informações do ambiente da aba atual (sessionStorage). */
|
|
7673
|
+
setCurrentEnv(env) {
|
|
7674
|
+
this.storageService.setSessionStorage(this.sessionStorageName, JSON.stringify(env));
|
|
7675
|
+
}
|
|
7676
|
+
/** Busca as informações do usuário na API (`/user/info?version=N`). */
|
|
7677
|
+
async asyncInfo() {
|
|
7678
|
+
const env = this.getCurrentEnv();
|
|
7679
|
+
const version = this.config.userInfoVersion;
|
|
7680
|
+
let url = `${this.config.host}/user/info?version=${version}`;
|
|
7681
|
+
if (env?.currentCloudID?.t_code && env?.currentCloudID?.cloud_id) {
|
|
7682
|
+
url += `&t_code=${env.currentCloudID.t_code}&cloud_id=${env.currentCloudID.cloud_id}`;
|
|
7683
|
+
}
|
|
7684
|
+
return await firstValueFrom(this.http.get(url));
|
|
7685
|
+
}
|
|
7686
|
+
/**
|
|
7687
|
+
* Hidrata o perfil básico do usuário logado com os dados de `/user/info`.
|
|
7688
|
+
* Versão enxuta (apenas campos de identidade/perfil) para uso compartilhado.
|
|
7689
|
+
* @returns `true` se hidratou com sucesso; `false` se não há usuário em sessão.
|
|
7690
|
+
*/
|
|
7691
|
+
async getInfo() {
|
|
7692
|
+
const currentUser = this.getUser();
|
|
7693
|
+
if (!currentUser) {
|
|
7694
|
+
return false;
|
|
7695
|
+
}
|
|
7696
|
+
const info = await this.asyncInfo();
|
|
7697
|
+
currentUser.user.firstName = info?.given_name;
|
|
7698
|
+
currentUser.user.lastName = info?.middle_name;
|
|
7699
|
+
currentUser.user.fullName = `${info?.given_name ?? ''} ${info?.middle_name ?? ''}`.trim();
|
|
7700
|
+
currentUser.user.email = info?.email;
|
|
7701
|
+
currentUser.user.profile = info?.profile;
|
|
7702
|
+
currentUser.user.type_home = info?.type_home?.toLowerCase() ?? 'default';
|
|
7703
|
+
currentUser.user.user_role = info?.type_home ?? 'default';
|
|
7704
|
+
if (info?.url_logout) {
|
|
7705
|
+
currentUser.logoutUrl = info.url_logout;
|
|
7706
|
+
}
|
|
7707
|
+
this.storeUser(currentUser);
|
|
7708
|
+
// Persiste no ambiente da aba os dados de acesso vindos do login. É o que as
|
|
7709
|
+
// diretivas `*ngTCCheckAccess` / `*ngTCFeatureFlags` consomem via
|
|
7710
|
+
// `getCurrentEnv().ui` e `getCurrentEnv().feature_flags`.
|
|
7711
|
+
const currentEnv = this.getCurrentEnv();
|
|
7712
|
+
currentEnv.ui = info?.ui;
|
|
7713
|
+
currentEnv.features = info?.features;
|
|
7714
|
+
currentEnv.feature_flags = info?.feature_flags ?? [];
|
|
7715
|
+
this.setCurrentEnv(currentEnv);
|
|
7716
|
+
return true;
|
|
7717
|
+
}
|
|
7718
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: TCloudUiUserService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
7719
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: TCloudUiUserService, providedIn: 'root' }); }
|
|
7720
|
+
}
|
|
7721
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: TCloudUiUserService, decorators: [{
|
|
7722
|
+
type: Injectable,
|
|
7723
|
+
args: [{
|
|
7724
|
+
providedIn: 'root'
|
|
7725
|
+
}]
|
|
7726
|
+
}] });
|
|
7727
|
+
|
|
7564
7728
|
class TCloudUiCheckAccessService {
|
|
7565
|
-
constructor(_UserService) {
|
|
7729
|
+
constructor(_UserService, _sharedUserService) {
|
|
7566
7730
|
this._UserService = _UserService;
|
|
7731
|
+
this._sharedUserService = _sharedUserService;
|
|
7567
7732
|
this.userService = {};
|
|
7568
|
-
|
|
7733
|
+
// Prioriza o user service legado do app (token string 'UserService'); se o app
|
|
7734
|
+
// não fornecer um, usa o núcleo de auth compartilhado da própria lib. Assim as
|
|
7735
|
+
// diretivas de acesso funcionam out-of-the-box quando a app usa a auth da lib.
|
|
7736
|
+
this.userService = this._UserService ?? this._sharedUserService;
|
|
7569
7737
|
}
|
|
7570
7738
|
check(checkAccess) {
|
|
7571
7739
|
const temp_user = this.getImpersonalizeUserInfo();
|
|
@@ -7714,7 +7882,7 @@ class TCloudUiCheckAccessService {
|
|
|
7714
7882
|
removeLocalStorage() {
|
|
7715
7883
|
localStorage.removeItem('temp_user_info');
|
|
7716
7884
|
}
|
|
7717
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: TCloudUiCheckAccessService, deps: [{ token: 'UserService', optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
7885
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: TCloudUiCheckAccessService, deps: [{ token: 'UserService', optional: true }, { token: TCloudUiUserService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
7718
7886
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: TCloudUiCheckAccessService, providedIn: 'root' }); }
|
|
7719
7887
|
}
|
|
7720
7888
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: TCloudUiCheckAccessService, decorators: [{
|
|
@@ -7727,7 +7895,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
7727
7895
|
}, {
|
|
7728
7896
|
type: Inject,
|
|
7729
7897
|
args: ['UserService']
|
|
7730
|
-
}] }] });
|
|
7898
|
+
}] }, { type: TCloudUiUserService }] });
|
|
7731
7899
|
|
|
7732
7900
|
class TCloudUiCheckAccessDirective {
|
|
7733
7901
|
set TCCheckAccess(checkAccess) {
|
|
@@ -10881,6 +11049,10 @@ class TCloudUiModule {
|
|
|
10881
11049
|
const providers = [
|
|
10882
11050
|
// Configuração principal
|
|
10883
11051
|
{ provide: TCLOUD_UI_CONFIG, useValue: config?.data ?? {} },
|
|
11052
|
+
// Configuração do núcleo de autenticação (URLs/chaves vindas do app consumidor).
|
|
11053
|
+
// Obs.: em apps NgModule, registre o interceptor com
|
|
11054
|
+
// `provideHttpClient(withInterceptors([tcloudUiJwtInterceptor]))` nos providers do app.
|
|
11055
|
+
{ provide: TCLOUD_UI_AUTH_CONFIG, useValue: config?.auth ?? {} },
|
|
10884
11056
|
DatePipe,
|
|
10885
11057
|
StatusInfoPipe
|
|
10886
11058
|
];
|
|
@@ -11165,6 +11337,151 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
11165
11337
|
}]
|
|
11166
11338
|
}] });
|
|
11167
11339
|
|
|
11340
|
+
/**
|
|
11341
|
+
* Modelos do núcleo de autenticação compartilhado.
|
|
11342
|
+
* Contém apenas os campos usados pelo fluxo de auth/sessão — regras de negócio
|
|
11343
|
+
* (billing, tss, topologias, etc.) ficam fora da lib.
|
|
11344
|
+
*/
|
|
11345
|
+
|
|
11346
|
+
/**
|
|
11347
|
+
* Núcleo de autenticação compartilhado: login/token/refresh/logout e checagem de sessão.
|
|
11348
|
+
* Portado do `authentication.service.ts` do front-tcloud, desacoplado de analytics/genesys
|
|
11349
|
+
* e lendo as URLs via `TCLOUD_UI_AUTH_CONFIG` (fornecido pelo app consumidor).
|
|
11350
|
+
*/
|
|
11351
|
+
class TCloudUiAuthenticationService {
|
|
11352
|
+
constructor() {
|
|
11353
|
+
this.http = inject(HttpClient);
|
|
11354
|
+
this.userService = inject(TCloudUiUserService);
|
|
11355
|
+
this.storageService = inject(TCloudUiStorageService);
|
|
11356
|
+
this.config = withAuthDefaults(inject(TCLOUD_UI_AUTH_CONFIG, { optional: true }));
|
|
11357
|
+
/** Emite quando o token é renovado (consumidores podem reagir, ex.: Genesys). */
|
|
11358
|
+
this.tokenRefreshed = new BehaviorSubject(false);
|
|
11359
|
+
}
|
|
11360
|
+
/** Verifica se o usuário está logado (possui token em sessão). */
|
|
11361
|
+
isLoggedIn() {
|
|
11362
|
+
return !!this.userService.getUser()?.user?.token;
|
|
11363
|
+
}
|
|
11364
|
+
/** Verifica se há dados de usuário carregados. */
|
|
11365
|
+
hasUserData() {
|
|
11366
|
+
return !!this.userService.getUser();
|
|
11367
|
+
}
|
|
11368
|
+
/** Retorna o token de autenticação do usuário logado. */
|
|
11369
|
+
getAuthToken() {
|
|
11370
|
+
return this.userService.getUser()?.user?.token ?? '';
|
|
11371
|
+
}
|
|
11372
|
+
/** Guarda o novo par de tokens na sessão. */
|
|
11373
|
+
storeNewToken(authToken, refreshToken) {
|
|
11374
|
+
const storageUser = this.userService.getUser();
|
|
11375
|
+
if (!storageUser) {
|
|
11376
|
+
return;
|
|
11377
|
+
}
|
|
11378
|
+
storageUser.user.token = authToken;
|
|
11379
|
+
storageUser.user.refresh_token = refreshToken;
|
|
11380
|
+
this.userService.storeUser(storageUser);
|
|
11381
|
+
this.tokenRefreshed.next(true);
|
|
11382
|
+
}
|
|
11383
|
+
/** Solicita token de autenticação (troca do código Cognito). */
|
|
11384
|
+
requestToken(queryParams) {
|
|
11385
|
+
const url = `${this.config.host}/cognito/authorization`;
|
|
11386
|
+
return this.http.get(url, { params: queryParams });
|
|
11387
|
+
}
|
|
11388
|
+
/** Solicita novo token de segurança quando o atual expira; atualiza a sessão. */
|
|
11389
|
+
refreshToken() {
|
|
11390
|
+
const storedUser = this.userService.getUser();
|
|
11391
|
+
const refreshAuth = storedUser?.user?.refresh_token ?? '';
|
|
11392
|
+
const app = this.config.appToken ?? '';
|
|
11393
|
+
const url = `${this.config.host}/cognito/refresh?app=${app}`;
|
|
11394
|
+
return this.http.post(url, refreshAuth).pipe(map$1((response) => {
|
|
11395
|
+
this.storeNewToken(response.token, response.refresh_token);
|
|
11396
|
+
return response.token;
|
|
11397
|
+
}));
|
|
11398
|
+
}
|
|
11399
|
+
/**
|
|
11400
|
+
* Realiza logout: registra o signout (best-effort), limpa a sessão e redireciona.
|
|
11401
|
+
* Destino: `logoutUrl` do usuário > `logoutRedirectUrl` da config > `loginUrl`.
|
|
11402
|
+
*/
|
|
11403
|
+
logout() {
|
|
11404
|
+
const cleanupAndRedirect = () => {
|
|
11405
|
+
const storedUrl = this.userService.getUser()?.logoutUrl;
|
|
11406
|
+
this.storageService.removeLocalStorage(this.config.localStorageName);
|
|
11407
|
+
this.storageService.removeSessionStorage(this.config.sessionStorageName);
|
|
11408
|
+
const target = storedUrl || this.config.logoutRedirectUrl || this.config.loginUrl;
|
|
11409
|
+
if (target) {
|
|
11410
|
+
window.location.href = target;
|
|
11411
|
+
}
|
|
11412
|
+
};
|
|
11413
|
+
if (this.isLoggedIn()) {
|
|
11414
|
+
const body = { token: this.getAuthToken() };
|
|
11415
|
+
this.http.post(`${this.config.host}/audit/cognito/signout`, body).subscribe({
|
|
11416
|
+
next: () => cleanupAndRedirect(),
|
|
11417
|
+
error: () => cleanupAndRedirect(),
|
|
11418
|
+
});
|
|
11419
|
+
}
|
|
11420
|
+
else {
|
|
11421
|
+
cleanupAndRedirect();
|
|
11422
|
+
}
|
|
11423
|
+
}
|
|
11424
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: TCloudUiAuthenticationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
11425
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: TCloudUiAuthenticationService, providedIn: 'root' }); }
|
|
11426
|
+
}
|
|
11427
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: TCloudUiAuthenticationService, decorators: [{
|
|
11428
|
+
type: Injectable,
|
|
11429
|
+
args: [{
|
|
11430
|
+
providedIn: 'root'
|
|
11431
|
+
}]
|
|
11432
|
+
}] });
|
|
11433
|
+
|
|
11434
|
+
/**
|
|
11435
|
+
* Interceptor funcional do núcleo de autenticação.
|
|
11436
|
+
* - Injeta o header `Authorization` em requisições destinadas à API configurada (`host`).
|
|
11437
|
+
* - Em respostas 401, tenta `refreshToken()` e refaz a requisição uma vez; se o refresh
|
|
11438
|
+
* falhar, dispara `logout()`.
|
|
11439
|
+
*
|
|
11440
|
+
* Registre no app consumidor via `withInterceptors([tcloudUiJwtInterceptor])` ou deixe
|
|
11441
|
+
* que `provideTCloudUi()`/`TCloudUiModule.forRoot()` o registrem.
|
|
11442
|
+
*/
|
|
11443
|
+
const tcloudUiJwtInterceptor = (req, next) => {
|
|
11444
|
+
const auth = inject(TCloudUiAuthenticationService);
|
|
11445
|
+
const config = withAuthDefaults(inject(TCLOUD_UI_AUTH_CONFIG, { optional: true }));
|
|
11446
|
+
// Só anexa o token em chamadas para a própria API, evitando vazar credencial a terceiros.
|
|
11447
|
+
const targetsApi = !!config.host && req.url.startsWith(config.host);
|
|
11448
|
+
const withAuth = (request) => {
|
|
11449
|
+
const token = auth.getAuthToken();
|
|
11450
|
+
if (!targetsApi || !token) {
|
|
11451
|
+
return request;
|
|
11452
|
+
}
|
|
11453
|
+
return request.clone({ setHeaders: { Authorization: token } });
|
|
11454
|
+
};
|
|
11455
|
+
return next(withAuth(req)).pipe(catchError((error) => {
|
|
11456
|
+
if (error instanceof HttpErrorResponse && error.status === 401 && targetsApi) {
|
|
11457
|
+
return auth.refreshToken().pipe(switchMap(() => next(withAuth(req))), catchError((refreshError) => {
|
|
11458
|
+
auth.logout();
|
|
11459
|
+
return throwError(() => refreshError);
|
|
11460
|
+
}));
|
|
11461
|
+
}
|
|
11462
|
+
return throwError(() => error);
|
|
11463
|
+
}));
|
|
11464
|
+
};
|
|
11465
|
+
|
|
11466
|
+
/**
|
|
11467
|
+
* Guard de rota do núcleo de autenticação.
|
|
11468
|
+
* Libera a navegação se o usuário estiver logado; caso contrário redireciona
|
|
11469
|
+
* para `loginUrl` (quando configurado) e bloqueia a rota.
|
|
11470
|
+
*
|
|
11471
|
+
* Uso: `{ path: 'x', canActivate: [tcloudUiAuthGuard], component: ... }`
|
|
11472
|
+
*/
|
|
11473
|
+
const tcloudUiAuthGuard = () => {
|
|
11474
|
+
const auth = inject(TCloudUiAuthenticationService);
|
|
11475
|
+
const config = withAuthDefaults(inject(TCLOUD_UI_AUTH_CONFIG, { optional: true }));
|
|
11476
|
+
if (auth.isLoggedIn()) {
|
|
11477
|
+
return true;
|
|
11478
|
+
}
|
|
11479
|
+
if (config.loginUrl) {
|
|
11480
|
+
window.location.href = config.loginUrl;
|
|
11481
|
+
}
|
|
11482
|
+
return false;
|
|
11483
|
+
};
|
|
11484
|
+
|
|
11168
11485
|
/**
|
|
11169
11486
|
* Função provider para configurar o TCloud UI em aplicações standalone do Angular.
|
|
11170
11487
|
* Use esta função no `main.ts` ou em `app.config.ts` com `bootstrapApplication`.
|
|
@@ -11198,6 +11515,8 @@ function provideTCloudUi(config) {
|
|
|
11198
11515
|
const providers = [
|
|
11199
11516
|
// Configuração principal
|
|
11200
11517
|
{ provide: TCLOUD_UI_CONFIG, useValue: config?.data ?? {} },
|
|
11518
|
+
// Configuração do núcleo de autenticação (URLs/chaves vindas do app consumidor)
|
|
11519
|
+
{ provide: TCLOUD_UI_AUTH_CONFIG, useValue: config?.auth ?? {} },
|
|
11201
11520
|
// Pipes necessários para os serviços
|
|
11202
11521
|
DatePipe,
|
|
11203
11522
|
StatusInfoPipe
|
|
@@ -11216,7 +11535,7 @@ function provideTCloudUi(config) {
|
|
|
11216
11535
|
providers.push({ provide: TCLOUD_UI_VIEWPORT_SERVICE, useClass: config.services.viewportService });
|
|
11217
11536
|
}
|
|
11218
11537
|
return makeEnvironmentProviders([
|
|
11219
|
-
provideHttpClient(withInterceptorsFromDi()),
|
|
11538
|
+
provideHttpClient(withInterceptorsFromDi(), withInterceptors([tcloudUiJwtInterceptor])),
|
|
11220
11539
|
provideMarkdown(),
|
|
11221
11540
|
...providers
|
|
11222
11541
|
]);
|
|
@@ -13165,5 +13484,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
13165
13484
|
* Generated bundle index. Do not edit.
|
|
13166
13485
|
*/
|
|
13167
13486
|
|
|
13168
|
-
export { AcceptedFileType, BytesPipe, CNPJPipe, CPFPipe, CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR$2 as CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR, DateBRPipe, DropdownGroupedSize, DropdownMultiSize$1 as DropdownMultiSize, DropdownSize$1 as DropdownSize, MonthNamePipe, MultiLevelDropdownSize$1 as MultiLevelDropdownSize, ProductActionPipe, ProgressStatusBarGradientStatus$1 as ProgressStatusBarGradientStatus, RespectivePipe, StatusInfoPipe, TCCondition, TCFiltersType, TCLOUD_UI_CONFIG, TCLOUD_UI_LAYOUT_SERVICE, TCLOUD_UI_LOCALE_SERVICE, TCLOUD_UI_USER_SERVICE, TCLOUD_UI_VIEWPORT_SERVICE, TCloudUiAccordionBodyComponent, TCloudUiAccordionComponent, TCloudUiAccordionTitleComponent, TCloudUiAlertBannerComponent, TCloudUiAlignDirective, TCloudUiBreadcrumbComponent, TCloudUiBreadcrumbService, TCloudUiButtonDirective, TCloudUiCalendarComponent, TCloudUiCardAccordionComponent, TCloudUiCardComponent, TCloudUiCardTitleComponent, TCloudUiCarouselComponent, TCloudUiCheckAccessDirective, TCloudUiCheckAccessService, TCloudUiCheckboxDirective, TCloudUiChoiceIssuesComponent, TCloudUiContainerColComponent, TCloudUiContainerComponent, TCloudUiContainerContentComponent, TCloudUiCubesComponent, TCloudUiCurrencyDirective, TCloudUiDataListComponent, TCloudUiDataListOptionComponent, TCloudUiDatepickerComponent, TCloudUiDatepickerTimeComponent, TCloudUiDialogComponent, TCloudUiDialogEventsEnum, TCloudUiDialogHostComponent, TCloudUiDialogModel, TCloudUiDialogService, TCloudUiDialogStatusEnum, TCloudUiDialogTextConfirmationEnum, TCloudUiDigitOnlyDirective, TCloudUiDropdownComponent, TCloudUiDropdownMultiComponent, TCloudUiDropdownMultiLevelComponent, TCloudUiEditorComponent, TCloudUiEditorDiffComponent, TCloudUiElCopyDirective, TCloudUiEmptyContentComponent, TCloudUiFaqComponent, TCloudUiFilterBarComponent, TCloudUiFiltersComponent, TCloudUiFooterComponent, TCloudUiFormDirective, TCloudUiHighLightDirective, TCloudUiHoverParentDirective, TCloudUiIconButtonDirective, TCloudUiInputContainerComponent, TCloudUiInputDirective, TCloudUiInputPasswordComponent, TCloudUiInputSearchComponent, TCloudUiIpMaskDirective, TCloudUiLabelTokenComponent, TCloudUiLegendComponent, TCloudUiLineStepCircleComponent, TCloudUiLineStepTitleComponent, TCloudUiLinhaLogoComponent, TCloudUiLoadingComponent, TCloudUiLoadingTransitionsService, TCloudUiMarkReadmeComponent, TCloudUiMessageComponent, TCloudUiModalBodyComponent, TCloudUiModalComponent, TCloudUiModalFooterComponent, TCloudUiModalHeaderComponent, TCloudUiModule, TCloudUiMultiInputComponent, TCloudUiMultiSelectComponent, TCloudUiMultiplesValuesComponent, TCloudUiNavbarComponent, TCloudUiNavbarFooterComponent, TCloudUiNavbarItemComponent, TCloudUiNgCheckAccessDirective, TCloudUiNgFeatureFlagsDirective, TCloudUiNotFoundComponent, TCloudUiNumberStepComponent, TCloudUiPaginationComponent, TCloudUiPaginationPipe, TCloudUiPopoverComponent, TCloudUiProgressBarComponent, TCloudUiProgressStatusBarComponent, TCloudUiRadioDirective, TCloudUiRangeDateComponent, TCloudUiReorderItemsComponent, TCloudUiScrollBoxComponent, TCloudUiSearchBarComponent, TCloudUiSearchInObjectService, TCloudUiSearchInputComponent, TCloudUiSkeletonLoadingComponent, TCloudUiSkeletonLoadingComponentStyle, TCloudUiSlideToggleDirective, TCloudUiSubNavbarComponent, TCloudUiSubNavbarGroupComponent, TCloudUiSubNavbarItemComponent, TCloudUiTabContentComponent, TCloudUiTabGroupComponent, TCloudUiTabHeadComponent, TCloudUiTabItemComponent, TCloudUiTabMenuComponent, TCloudUiTabOptionComponent, TCloudUiTabSubtitleComponent, TCloudUiTabTitleComponent, TCloudUiTableComponent, TCloudUiTagComponent, TCloudUiToastComponent, TCloudUiTooltipDirective, TCloudUiTopNavigationComponent, TCloudUiUploadAreaComponent, TCloudUiWelcomeComponent, TCloudUiWizardStepsComponent, TagColorsEnum, TcRevButtonDirective, TcRevCalendarComponent, TcRevCardAccordionComponent, TcRevCardComponent, TcRevCardTitleComponent, TcRevCheckboxDirective, TcRevComponentsLibModule, TcRevDropdownComponent, TcRevDropdownGroupedComponent, TcRevDropdownMultiComponent, TcRevDropdownMultiLevelComponent, TcRevEmptyContentComponent, TcRevFaqComponent, TcRevIconButtonDirective, TcRevInputContainerComponent, TcRevInputDirective, TcRevLoadingComponent, TcRevMessageComponent, TcRevMultiInputComponent, TcRevPaginationComponent, TcRevProgressStatusBarComponent, TcRevRadioDirective, TcRevSearchInputComponent, TcRevSideDrawerComponent, TcRevSkeletonLoadingComponent, TcRevSkeletonLoadingComponentStyle, TcRevSlideToggleDirective, TcRevSmallLoadingComponent, TcRevSmallLoadingComponentStyle, TcRevSubNavbarComponent, TcRevSubNavbarItemComponent, TcRevTabGroupComponent, TcRevTabItemComponent, TcRevTagComponent, TcRevToastComponent, TcRevTooltipDirective, TcRevWizardStepsComponent, ToTextPipe, TopologyEnvironmentPipe, TopologyProductPipe, TopologyRegionPipe, TopologyStatusPipe, echartBarConfig, isTextEllipsed, provideTCloudUi };
|
|
13487
|
+
export { AcceptedFileType, BytesPipe, CNPJPipe, CPFPipe, CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR$2 as CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR, DateBRPipe, DropdownGroupedSize, DropdownMultiSize$1 as DropdownMultiSize, DropdownSize$1 as DropdownSize, MonthNamePipe, MultiLevelDropdownSize$1 as MultiLevelDropdownSize, ProductActionPipe, ProgressStatusBarGradientStatus$1 as ProgressStatusBarGradientStatus, RespectivePipe, StatusInfoPipe, TCCondition, TCFiltersType, TCLOUD_UI_AUTH_CONFIG, TCLOUD_UI_CONFIG, TCLOUD_UI_LAYOUT_SERVICE, TCLOUD_UI_LOCALE_SERVICE, TCLOUD_UI_USER_SERVICE, TCLOUD_UI_VIEWPORT_SERVICE, TCloudUiAccordionBodyComponent, TCloudUiAccordionComponent, TCloudUiAccordionTitleComponent, TCloudUiAlertBannerComponent, TCloudUiAlignDirective, TCloudUiAuthenticationService, TCloudUiBreadcrumbComponent, TCloudUiBreadcrumbService, TCloudUiButtonDirective, TCloudUiCalendarComponent, TCloudUiCardAccordionComponent, TCloudUiCardComponent, TCloudUiCardTitleComponent, TCloudUiCarouselComponent, TCloudUiCheckAccessDirective, TCloudUiCheckAccessService, TCloudUiCheckboxDirective, TCloudUiChoiceIssuesComponent, TCloudUiContainerColComponent, TCloudUiContainerComponent, TCloudUiContainerContentComponent, TCloudUiCubesComponent, TCloudUiCurrencyDirective, TCloudUiDataListComponent, TCloudUiDataListOptionComponent, TCloudUiDatepickerComponent, TCloudUiDatepickerTimeComponent, TCloudUiDialogComponent, TCloudUiDialogEventsEnum, TCloudUiDialogHostComponent, TCloudUiDialogModel, TCloudUiDialogService, TCloudUiDialogStatusEnum, TCloudUiDialogTextConfirmationEnum, TCloudUiDigitOnlyDirective, TCloudUiDropdownComponent, TCloudUiDropdownMultiComponent, TCloudUiDropdownMultiLevelComponent, TCloudUiEditorComponent, TCloudUiEditorDiffComponent, TCloudUiElCopyDirective, TCloudUiEmptyContentComponent, TCloudUiFaqComponent, TCloudUiFilterBarComponent, TCloudUiFiltersComponent, TCloudUiFooterComponent, TCloudUiFormDirective, TCloudUiHighLightDirective, TCloudUiHoverParentDirective, TCloudUiIconButtonDirective, TCloudUiInputContainerComponent, TCloudUiInputDirective, TCloudUiInputPasswordComponent, TCloudUiInputSearchComponent, TCloudUiIpMaskDirective, TCloudUiLabelTokenComponent, TCloudUiLegendComponent, TCloudUiLineStepCircleComponent, TCloudUiLineStepTitleComponent, TCloudUiLinhaLogoComponent, TCloudUiLoadingComponent, TCloudUiLoadingTransitionsService, TCloudUiMarkReadmeComponent, TCloudUiMessageComponent, TCloudUiModalBodyComponent, TCloudUiModalComponent, TCloudUiModalFooterComponent, TCloudUiModalHeaderComponent, TCloudUiModule, TCloudUiMultiInputComponent, TCloudUiMultiSelectComponent, TCloudUiMultiplesValuesComponent, TCloudUiNavbarComponent, TCloudUiNavbarFooterComponent, TCloudUiNavbarItemComponent, TCloudUiNgCheckAccessDirective, TCloudUiNgFeatureFlagsDirective, TCloudUiNotFoundComponent, TCloudUiNumberStepComponent, TCloudUiPaginationComponent, TCloudUiPaginationPipe, TCloudUiPopoverComponent, TCloudUiProgressBarComponent, TCloudUiProgressStatusBarComponent, TCloudUiRadioDirective, TCloudUiRangeDateComponent, TCloudUiReorderItemsComponent, TCloudUiScrollBoxComponent, TCloudUiSearchBarComponent, TCloudUiSearchInObjectService, TCloudUiSearchInputComponent, TCloudUiSkeletonLoadingComponent, TCloudUiSkeletonLoadingComponentStyle, TCloudUiSlideToggleDirective, TCloudUiStorageService, TCloudUiSubNavbarComponent, TCloudUiSubNavbarGroupComponent, TCloudUiSubNavbarItemComponent, TCloudUiTabContentComponent, TCloudUiTabGroupComponent, TCloudUiTabHeadComponent, TCloudUiTabItemComponent, TCloudUiTabMenuComponent, TCloudUiTabOptionComponent, TCloudUiTabSubtitleComponent, TCloudUiTabTitleComponent, TCloudUiTableComponent, TCloudUiTagComponent, TCloudUiToastComponent, TCloudUiTooltipDirective, TCloudUiTopNavigationComponent, TCloudUiUploadAreaComponent, TCloudUiUserService, TCloudUiWelcomeComponent, TCloudUiWizardStepsComponent, TagColorsEnum, TcRevButtonDirective, TcRevCalendarComponent, TcRevCardAccordionComponent, TcRevCardComponent, TcRevCardTitleComponent, TcRevCheckboxDirective, TcRevComponentsLibModule, TcRevDropdownComponent, TcRevDropdownGroupedComponent, TcRevDropdownMultiComponent, TcRevDropdownMultiLevelComponent, TcRevEmptyContentComponent, TcRevFaqComponent, TcRevIconButtonDirective, TcRevInputContainerComponent, TcRevInputDirective, TcRevLoadingComponent, TcRevMessageComponent, TcRevMultiInputComponent, TcRevPaginationComponent, TcRevProgressStatusBarComponent, TcRevRadioDirective, TcRevSearchInputComponent, TcRevSideDrawerComponent, TcRevSkeletonLoadingComponent, TcRevSkeletonLoadingComponentStyle, TcRevSlideToggleDirective, TcRevSmallLoadingComponent, TcRevSmallLoadingComponentStyle, TcRevSubNavbarComponent, TcRevSubNavbarItemComponent, TcRevTabGroupComponent, TcRevTabItemComponent, TcRevTagComponent, TcRevToastComponent, TcRevTooltipDirective, TcRevWizardStepsComponent, ToTextPipe, TopologyEnvironmentPipe, TopologyProductPipe, TopologyRegionPipe, TopologyStatusPipe, echartBarConfig, isTextEllipsed, provideTCloudUi, tcloudUiAuthGuard, tcloudUiJwtInterceptor, withAuthDefaults };
|
|
13169
13488
|
//# sourceMappingURL=dev-tcloud-tcloud-ui.mjs.map
|