ngx-sp-auth 4.3.6 → 4.3.8
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.
package/fesm2022/ngx-sp-auth.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import { RouterLink, NavigationEnd, RouterOutlet } from '@angular/router';
|
|
|
11
11
|
import { BehaviorSubject, take, tap, Subject, Subscription, debounceTime, distinctUntilChanged, filter, switchMap, timer, map as map$1, of, lastValueFrom, from } from 'rxjs';
|
|
12
12
|
import * as i3 from 'ngx-sp-infra';
|
|
13
13
|
import { Utils, SearchInputComponent, InfraModule, FormUtils, LibIconsComponent, ContentContainerComponent } from 'ngx-sp-infra';
|
|
14
|
+
import { openDB, deleteDB } from 'idb';
|
|
14
15
|
import * as i3$2 from '@angular/common';
|
|
15
16
|
import { NgIf, CommonModule } from '@angular/common';
|
|
16
17
|
import * as i3$1 from '@angular/forms';
|
|
@@ -227,10 +228,136 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImpo
|
|
|
227
228
|
args: [LIB_CUSTOM_ENVIRONMENT_SERVICE]
|
|
228
229
|
}] }] });
|
|
229
230
|
|
|
231
|
+
class IndexedDBService {
|
|
232
|
+
// #endregion ==========> PROPERTIES <==========
|
|
233
|
+
constructor(_customEnvironment) {
|
|
234
|
+
this._customEnvironment = _customEnvironment;
|
|
235
|
+
this._dbName = "Sp_Filtros_";
|
|
236
|
+
if (!window.indexedDB) {
|
|
237
|
+
alert("Seu navegador não suporta uma versão estável do IndexedDB. Salvamento de filtros em sessão não estará disponível.");
|
|
238
|
+
}
|
|
239
|
+
this._dbName = `Sp_${_customEnvironment.product}_Filtros`;
|
|
240
|
+
}
|
|
241
|
+
// #region ==========> ACTIONS <==========
|
|
242
|
+
// #region ADD
|
|
243
|
+
/**
|
|
244
|
+
* Cria um registro dentro de um objectStore.
|
|
245
|
+
* O valor a ser inserido precisa ser um objeto com pelo **menos a propriedade `key`**, ela é a nossa *chave-primária* dos registros
|
|
246
|
+
*
|
|
247
|
+
* @param value Valor a ser inserido
|
|
248
|
+
*/
|
|
249
|
+
async add(value) {
|
|
250
|
+
const db = await openDB(this._dbName, 1);
|
|
251
|
+
await db.add('filters', value);
|
|
252
|
+
}
|
|
253
|
+
// #endregion ADD
|
|
254
|
+
// #region GET
|
|
255
|
+
/**
|
|
256
|
+
* Busca um valor na base dentro de um objectStore.
|
|
257
|
+
*
|
|
258
|
+
* @param storeName Nome do objectStore
|
|
259
|
+
* @param key Valor da chave única
|
|
260
|
+
* @returns Promise<> com o valor encontrado ou undefined se não encontrar
|
|
261
|
+
*/
|
|
262
|
+
async get(key) {
|
|
263
|
+
const db = await openDB(this._dbName, 1);
|
|
264
|
+
return await db.get('filters', key);
|
|
265
|
+
}
|
|
266
|
+
// #endregion GET
|
|
267
|
+
// #region UPDATE
|
|
268
|
+
/**
|
|
269
|
+
* Atualiza o valor de um registro dentro de um objectStore.
|
|
270
|
+
*
|
|
271
|
+
* @param value Valor atualizado
|
|
272
|
+
*/
|
|
273
|
+
async update(value) {
|
|
274
|
+
const db = await openDB(this._dbName, 1);
|
|
275
|
+
await db.put('filters', value);
|
|
276
|
+
}
|
|
277
|
+
// #endregion UPDATE
|
|
278
|
+
// #region DELETE
|
|
279
|
+
/**
|
|
280
|
+
* Exclui um registro na base dentro de um objectStore.
|
|
281
|
+
*
|
|
282
|
+
* @param key Valor da chave única
|
|
283
|
+
*/
|
|
284
|
+
async delete(key) {
|
|
285
|
+
const db = await openDB(this._dbName, 1);
|
|
286
|
+
await db.delete('filters', key);
|
|
287
|
+
}
|
|
288
|
+
// #endregion DELETE
|
|
289
|
+
// #endregion ==========> ACTIONS <==========
|
|
290
|
+
// #region ==========> UTILS <==========
|
|
291
|
+
/**
|
|
292
|
+
* Inicializa as configurações iniciais do IndexedDB e já cria o objectStore que será utilizado caso não exista.
|
|
293
|
+
*
|
|
294
|
+
* O object store que será criado terá sua chave inline na propriedade `key` e o índice será a propriedade `context`, portanto todos os valores que forem inseridos **DEVEM** ser um objeto com pelo menos a propriedade `key` e `context`.
|
|
295
|
+
* Deve ser chamado no constructor do seu componente para garantir inicialização correta pelo componente
|
|
296
|
+
*
|
|
297
|
+
* @param dbName Nome da base de dados que será usada
|
|
298
|
+
*/
|
|
299
|
+
async initializeDatabase() {
|
|
300
|
+
this.request = await openDB(this._dbName, 1, {
|
|
301
|
+
upgrade(db) {
|
|
302
|
+
// Criar objectStore se não houver um mesmo com este nome
|
|
303
|
+
if (!db.objectStoreNames.contains('filters')) {
|
|
304
|
+
const store = db.createObjectStore('filters', { keyPath: 'key' });
|
|
305
|
+
store.createIndex('context', 'context');
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
blocked() {
|
|
309
|
+
// notify user / log: another tab has old version open
|
|
310
|
+
console.warn('IndexedDB blocked — feche outras abas');
|
|
311
|
+
},
|
|
312
|
+
blocking() {
|
|
313
|
+
// this instance is blocking a future version request
|
|
314
|
+
console.warn('IndexedDB blocking — considere fechar esta conexão');
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Exclui uma database do IndexedDB com base no nome.
|
|
320
|
+
*
|
|
321
|
+
* @param name Nome da database
|
|
322
|
+
*/
|
|
323
|
+
async deleteDatabase() {
|
|
324
|
+
return await deleteDB(this._dbName);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Valida se já existe um valor cadastrado na base com a chave-única que foi informada, se houver retorna ele, caso contrário cria um registro placeholder para poder atualizar depois.
|
|
328
|
+
*
|
|
329
|
+
* @param key Valor da chave única
|
|
330
|
+
* @param value (opcional) Valor placeholder caso não exista um valor previamente criado
|
|
331
|
+
*
|
|
332
|
+
* @returns Estrutura encontrada no objectStore com a chave-única informada
|
|
333
|
+
*/
|
|
334
|
+
async validate(key, value) {
|
|
335
|
+
// Valida se já existe registro no DB local
|
|
336
|
+
this._restored = await this.get(key);
|
|
337
|
+
if (!this._restored && value) {
|
|
338
|
+
// Se não existir nada, inicializa um registro placeholder dentro do objectStore existente
|
|
339
|
+
await this.add(value);
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
// Se encontrar valor retorna apenas o payload com os dados que serão usados na tela
|
|
343
|
+
return this._restored?.payload;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: IndexedDBService, deps: [{ token: LibCustomEnvironmentService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
347
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: IndexedDBService, providedIn: 'root' }); }
|
|
348
|
+
}
|
|
349
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: IndexedDBService, decorators: [{
|
|
350
|
+
type: Injectable,
|
|
351
|
+
args: [{
|
|
352
|
+
providedIn: 'root'
|
|
353
|
+
}]
|
|
354
|
+
}], ctorParameters: () => [{ type: LibCustomEnvironmentService }] });
|
|
355
|
+
|
|
230
356
|
class AuthStorageService {
|
|
231
|
-
constructor(_httpBackend, _customStorageService, _customEnvironmentService) {
|
|
357
|
+
constructor(_httpBackend, _customStorageService, _indexedDBService, _customEnvironmentService) {
|
|
232
358
|
this._httpBackend = _httpBackend;
|
|
233
359
|
this._customStorageService = _customStorageService;
|
|
360
|
+
this._indexedDBService = _indexedDBService;
|
|
234
361
|
this._customEnvironmentService = _customEnvironmentService;
|
|
235
362
|
this._BASE_URL = ''; // SpInfra2WS
|
|
236
363
|
this.__local_key = 'user_auth_v6';
|
|
@@ -573,6 +700,8 @@ class AuthStorageService {
|
|
|
573
700
|
this.__azureTenantId = "";
|
|
574
701
|
this.__azureClientId = "";
|
|
575
702
|
localStorage.removeItem(this.__local_key);
|
|
703
|
+
// Limnpa o armazenamento local do navegador que contém os filtros de um produto específico (com base na prop 'product' do environment)
|
|
704
|
+
this._indexedDBService.deleteDatabase();
|
|
576
705
|
// Método com customizações para finalizações da storage
|
|
577
706
|
this._customStorageService.storageLogout();
|
|
578
707
|
}
|
|
@@ -648,13 +777,13 @@ class AuthStorageService {
|
|
|
648
777
|
return false;
|
|
649
778
|
}
|
|
650
779
|
}
|
|
651
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: AuthStorageService, deps: [{ token: i1.HttpBackend }, { token: LibCustomStorageService }, { token: LibCustomEnvironmentService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
780
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: AuthStorageService, deps: [{ token: i1.HttpBackend }, { token: LibCustomStorageService }, { token: IndexedDBService }, { token: LibCustomEnvironmentService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
652
781
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: AuthStorageService, providedIn: 'root' }); }
|
|
653
782
|
}
|
|
654
783
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: AuthStorageService, decorators: [{
|
|
655
784
|
type: Injectable,
|
|
656
785
|
args: [{ providedIn: 'root' }]
|
|
657
|
-
}], ctorParameters: () => [{ type: i1.HttpBackend }, { type: LibCustomStorageService }, { type: LibCustomEnvironmentService }] });
|
|
786
|
+
}], ctorParameters: () => [{ type: i1.HttpBackend }, { type: LibCustomStorageService }, { type: IndexedDBService }, { type: LibCustomEnvironmentService }] });
|
|
658
787
|
|
|
659
788
|
class LibCustomLoginService {
|
|
660
789
|
constructor(_customLoginService) {
|
|
@@ -816,7 +945,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImpo
|
|
|
816
945
|
class AuthService {
|
|
817
946
|
// #endregion PRIVATE
|
|
818
947
|
// #endregion ==========> PROPERTIES <==========
|
|
819
|
-
constructor(_httpClient, _router, _authStorageService, _ipServiceService, _customLoginService, _projectUtilservice, _customEnvironmentService) {
|
|
948
|
+
constructor(_httpClient, _router, _authStorageService, _ipServiceService, _customLoginService, _projectUtilservice, _customEnvironmentService, _indexedDBService) {
|
|
820
949
|
this._httpClient = _httpClient;
|
|
821
950
|
this._router = _router;
|
|
822
951
|
this._authStorageService = _authStorageService;
|
|
@@ -824,6 +953,7 @@ class AuthService {
|
|
|
824
953
|
this._customLoginService = _customLoginService;
|
|
825
954
|
this._projectUtilservice = _projectUtilservice;
|
|
826
955
|
this._customEnvironmentService = _customEnvironmentService;
|
|
956
|
+
this._indexedDBService = _indexedDBService;
|
|
827
957
|
// #region ==========> PROPERTIES <==========
|
|
828
958
|
// #region PRIVATE
|
|
829
959
|
this._pendingWarning = null;
|
|
@@ -930,6 +1060,8 @@ class AuthService {
|
|
|
930
1060
|
return this._httpClient
|
|
931
1061
|
.post(url, login, { 'params': params, 'headers': headers })
|
|
932
1062
|
.pipe(take$1(1), tap$1((response) => {
|
|
1063
|
+
// Limnpa o armazenamento local do navegador que contém os filtros de um produto específico (com base na prop 'product' do environment)
|
|
1064
|
+
this._indexedDBService.deleteDatabase();
|
|
933
1065
|
if (response.FeedbackMessage != "") {
|
|
934
1066
|
return;
|
|
935
1067
|
}
|
|
@@ -1273,13 +1405,13 @@ class AuthService {
|
|
|
1273
1405
|
this._pendingWarning = null;
|
|
1274
1406
|
return message;
|
|
1275
1407
|
}
|
|
1276
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: AuthService, deps: [{ token: i1.HttpClient }, { token: i1$1.Router }, { token: AuthStorageService }, { token: i3.IpServiceService }, { token: LibCustomLoginService }, { token: ProjectUtilservice }, { token: LibCustomEnvironmentService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1408
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: AuthService, deps: [{ token: i1.HttpClient }, { token: i1$1.Router }, { token: AuthStorageService }, { token: i3.IpServiceService }, { token: LibCustomLoginService }, { token: ProjectUtilservice }, { token: LibCustomEnvironmentService }, { token: IndexedDBService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1277
1409
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: AuthService, providedIn: 'root' }); }
|
|
1278
1410
|
}
|
|
1279
1411
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: AuthService, decorators: [{
|
|
1280
1412
|
type: Injectable,
|
|
1281
1413
|
args: [{ providedIn: 'root' }]
|
|
1282
|
-
}], ctorParameters: () => [{ type: i1.HttpClient }, { type: i1$1.Router }, { type: AuthStorageService }, { type: i3.IpServiceService }, { type: LibCustomLoginService }, { type: ProjectUtilservice }, { type: LibCustomEnvironmentService }] });
|
|
1414
|
+
}], ctorParameters: () => [{ type: i1.HttpClient }, { type: i1$1.Router }, { type: AuthStorageService }, { type: i3.IpServiceService }, { type: LibCustomLoginService }, { type: ProjectUtilservice }, { type: LibCustomEnvironmentService }, { type: IndexedDBService }] });
|
|
1283
1415
|
|
|
1284
1416
|
class MenuServicesService {
|
|
1285
1417
|
constructor(_authStorageService, _httpClient, _customEnvironmentService) {
|
|
@@ -4214,5 +4346,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImpo
|
|
|
4214
4346
|
* Generated bundle index. Do not edit.
|
|
4215
4347
|
*/
|
|
4216
4348
|
|
|
4217
|
-
export { AUTH_ROUTES, AuthAplicInterceptor, AuthGuard, AuthInfraInterceptor, AuthModule, AuthService, AuthStorageService, DynamicMenuComponent, ErrorMenuNotAllowed, ExternaLoginlGuard, IMenu, InfraUsuarioImg, IsMenuAllowedlGuard, LIB_CUSTOM_ENVIRONMENT_SERVICE, LIB_CUSTOM_LOGIN_SERVICE, LIB_CUSTOM_MENU_SERVICE, LIB_CUSTOM_STORAGE_SERVICE, LIB_MENU_CONFIG, LibCustomEnvironmentService, LibCustomLoginService, LibCustomMenuService, LibCustomStorageService, LibMenuConfigService, ListComponent, LoginComponent, LoginGuard, LoginOSComponent, LoginOSGuard, LoginProgress, MenuLateralComponent, MenuServicesService, NavSubMenus, NavSubmenuCards, NavSubmenuSearchItem, NavTabsComponent, NotifSubmenuComponent, NovaSenhaComponent, PesquisaTelasGlobalService, PrimaryDropdownComponent, RetInfraUsuarioImg, RetMenuItemStructure, RetMenuLateral, RetMenuPromise, RetNavSubMenu, RetSubmenuWithCards, SecondaryDropdownComponent, SelecaoEstabelecimentosModalComponent, SituacaoLogin, SubMenuCardComponent, SubMenuComponent, SubMenuItem, TelaItem };
|
|
4349
|
+
export { AUTH_ROUTES, AuthAplicInterceptor, AuthGuard, AuthInfraInterceptor, AuthModule, AuthService, AuthStorageService, DynamicMenuComponent, ErrorMenuNotAllowed, ExternaLoginlGuard, IMenu, IndexedDBService, InfraUsuarioImg, IsMenuAllowedlGuard, LIB_CUSTOM_ENVIRONMENT_SERVICE, LIB_CUSTOM_LOGIN_SERVICE, LIB_CUSTOM_MENU_SERVICE, LIB_CUSTOM_STORAGE_SERVICE, LIB_MENU_CONFIG, LibCustomEnvironmentService, LibCustomLoginService, LibCustomMenuService, LibCustomStorageService, LibMenuConfigService, ListComponent, LoginComponent, LoginGuard, LoginOSComponent, LoginOSGuard, LoginProgress, MenuLateralComponent, MenuServicesService, NavSubMenus, NavSubmenuCards, NavSubmenuSearchItem, NavTabsComponent, NotifSubmenuComponent, NovaSenhaComponent, PesquisaTelasGlobalService, PrimaryDropdownComponent, RetInfraUsuarioImg, RetMenuItemStructure, RetMenuLateral, RetMenuPromise, RetNavSubMenu, RetSubmenuWithCards, SecondaryDropdownComponent, SelecaoEstabelecimentosModalComponent, SituacaoLogin, SubMenuCardComponent, SubMenuComponent, SubMenuItem, TelaItem };
|
|
4218
4350
|
//# sourceMappingURL=ngx-sp-auth.mjs.map
|