ngx-sp-auth 4.3.7 → 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.
@@ -228,10 +228,136 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImpo
228
228
  args: [LIB_CUSTOM_ENVIRONMENT_SERVICE]
229
229
  }] }] });
230
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
+
231
356
  class AuthStorageService {
232
- constructor(_httpBackend, _customStorageService, _customEnvironmentService) {
357
+ constructor(_httpBackend, _customStorageService, _indexedDBService, _customEnvironmentService) {
233
358
  this._httpBackend = _httpBackend;
234
359
  this._customStorageService = _customStorageService;
360
+ this._indexedDBService = _indexedDBService;
235
361
  this._customEnvironmentService = _customEnvironmentService;
236
362
  this._BASE_URL = ''; // SpInfra2WS
237
363
  this.__local_key = 'user_auth_v6';
@@ -574,6 +700,8 @@ class AuthStorageService {
574
700
  this.__azureTenantId = "";
575
701
  this.__azureClientId = "";
576
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();
577
705
  // Método com customizações para finalizações da storage
578
706
  this._customStorageService.storageLogout();
579
707
  }
@@ -649,13 +777,13 @@ class AuthStorageService {
649
777
  return false;
650
778
  }
651
779
  }
652
- 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 }); }
653
781
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: AuthStorageService, providedIn: 'root' }); }
654
782
  }
655
783
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: AuthStorageService, decorators: [{
656
784
  type: Injectable,
657
785
  args: [{ providedIn: 'root' }]
658
- }], ctorParameters: () => [{ type: i1.HttpBackend }, { type: LibCustomStorageService }, { type: LibCustomEnvironmentService }] });
786
+ }], ctorParameters: () => [{ type: i1.HttpBackend }, { type: LibCustomStorageService }, { type: IndexedDBService }, { type: LibCustomEnvironmentService }] });
659
787
 
660
788
  class LibCustomLoginService {
661
789
  constructor(_customLoginService) {
@@ -817,7 +945,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImpo
817
945
  class AuthService {
818
946
  // #endregion PRIVATE
819
947
  // #endregion ==========> PROPERTIES <==========
820
- constructor(_httpClient, _router, _authStorageService, _ipServiceService, _customLoginService, _projectUtilservice, _customEnvironmentService) {
948
+ constructor(_httpClient, _router, _authStorageService, _ipServiceService, _customLoginService, _projectUtilservice, _customEnvironmentService, _indexedDBService) {
821
949
  this._httpClient = _httpClient;
822
950
  this._router = _router;
823
951
  this._authStorageService = _authStorageService;
@@ -825,6 +953,7 @@ class AuthService {
825
953
  this._customLoginService = _customLoginService;
826
954
  this._projectUtilservice = _projectUtilservice;
827
955
  this._customEnvironmentService = _customEnvironmentService;
956
+ this._indexedDBService = _indexedDBService;
828
957
  // #region ==========> PROPERTIES <==========
829
958
  // #region PRIVATE
830
959
  this._pendingWarning = null;
@@ -931,6 +1060,8 @@ class AuthService {
931
1060
  return this._httpClient
932
1061
  .post(url, login, { 'params': params, 'headers': headers })
933
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();
934
1065
  if (response.FeedbackMessage != "") {
935
1066
  return;
936
1067
  }
@@ -1274,13 +1405,13 @@ class AuthService {
1274
1405
  this._pendingWarning = null;
1275
1406
  return message;
1276
1407
  }
1277
- 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 }); }
1278
1409
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: AuthService, providedIn: 'root' }); }
1279
1410
  }
1280
1411
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: AuthService, decorators: [{
1281
1412
  type: Injectable,
1282
1413
  args: [{ providedIn: 'root' }]
1283
- }], 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 }] });
1284
1415
 
1285
1416
  class MenuServicesService {
1286
1417
  constructor(_authStorageService, _httpClient, _customEnvironmentService) {
@@ -1644,131 +1775,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImpo
1644
1775
  args: [LIB_CUSTOM_MENU_SERVICE]
1645
1776
  }] }, { type: LibMenuConfigService }, { type: AuthStorageService }] });
1646
1777
 
1647
- class IndexedDBService {
1648
- // #endregion ==========> PROPERTIES <==========
1649
- constructor(_customEnvironment) {
1650
- this._customEnvironment = _customEnvironment;
1651
- this._dbName = "Sp_Filtros_";
1652
- if (!window.indexedDB) {
1653
- alert("Seu navegador não suporta uma versão estável do IndexedDB. Salvamento de filtros em sessão não estará disponível.");
1654
- }
1655
- this._dbName = `Sp_${_customEnvironment.product}_Filtros`;
1656
- }
1657
- // #region ==========> ACTIONS <==========
1658
- // #region ADD
1659
- /**
1660
- * Cria um registro dentro de um objectStore.
1661
- * O valor a ser inserido precisa ser um objeto com pelo **menos a propriedade `key`**, ela é a nossa *chave-primária* dos registros
1662
- *
1663
- * @param value Valor a ser inserido
1664
- */
1665
- async add(value) {
1666
- const db = await openDB(this._dbName, 1);
1667
- await db.add('filters', value);
1668
- }
1669
- // #endregion ADD
1670
- // #region GET
1671
- /**
1672
- * Busca um valor na base dentro de um objectStore.
1673
- *
1674
- * @param storeName Nome do objectStore
1675
- * @param key Valor da chave única
1676
- * @returns Promise<> com o valor encontrado ou undefined se não encontrar
1677
- */
1678
- async get(key) {
1679
- const db = await openDB(this._dbName, 1);
1680
- return await db.get('filters', key);
1681
- }
1682
- // #endregion GET
1683
- // #region UPDATE
1684
- /**
1685
- * Atualiza o valor de um registro dentro de um objectStore.
1686
- *
1687
- * @param value Valor atualizado
1688
- */
1689
- async update(value) {
1690
- const db = await openDB(this._dbName, 1);
1691
- await db.put('filters', value);
1692
- }
1693
- // #endregion UPDATE
1694
- // #region DELETE
1695
- /**
1696
- * Exclui um registro na base dentro de um objectStore.
1697
- *
1698
- * @param key Valor da chave única
1699
- */
1700
- async delete(key) {
1701
- const db = await openDB(this._dbName, 1);
1702
- await db.delete('filters', key);
1703
- }
1704
- // #endregion DELETE
1705
- // #endregion ==========> ACTIONS <==========
1706
- // #region ==========> UTILS <==========
1707
- /**
1708
- * Inicializa as configurações iniciais do IndexedDB e já cria o objectStore que será utilizado caso não exista.
1709
- *
1710
- * 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`.
1711
- * Deve ser chamado no constructor do seu componente para garantir inicialização correta pelo componente
1712
- *
1713
- * @param dbName Nome da base de dados que será usada
1714
- */
1715
- async initializeDatabase(dbName = this._dbName) {
1716
- this.request = await openDB(dbName, 1, {
1717
- upgrade(db) {
1718
- // Criar objectStore se não houver um mesmo com este nome
1719
- if (!db.objectStoreNames.contains('filters')) {
1720
- const store = db.createObjectStore('filters', { keyPath: 'key' });
1721
- store.createIndex('context', 'context');
1722
- }
1723
- },
1724
- blocked() {
1725
- // notify user / log: another tab has old version open
1726
- console.warn('IndexedDB blocked — feche outras abas');
1727
- },
1728
- blocking() {
1729
- // this instance is blocking a future version request
1730
- console.warn('IndexedDB blocking — considere fechar esta conexão');
1731
- }
1732
- });
1733
- }
1734
- /**
1735
- * Exclui uma database do IndexedDB com base no nome.
1736
- *
1737
- * @param name Nome da database
1738
- */
1739
- async deleteDatabase(name) {
1740
- return await deleteDB(name);
1741
- }
1742
- /**
1743
- * 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.
1744
- *
1745
- * @param key Valor da chave única
1746
- * @param value (opcional) Valor placeholder caso não exista um valor previamente criado
1747
- *
1748
- * @returns Estrutura encontrada no objectStore com a chave-única informada
1749
- */
1750
- async validate(key, value) {
1751
- // Valida se já existe registro no DB local
1752
- this._restored = await this.get(key);
1753
- if (!this._restored && value) {
1754
- // Se não existir nada, inicializa um registro placeholder dentro do objectStore existente
1755
- await this.add(value);
1756
- }
1757
- else {
1758
- // Se encontrar valor retorna apenas o payload com os dados que serão usados na tela
1759
- return this._restored?.payload;
1760
- }
1761
- }
1762
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: IndexedDBService, deps: [{ token: LibCustomEnvironmentService }], target: i0.ɵɵFactoryTarget.Injectable }); }
1763
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: IndexedDBService, providedIn: 'root' }); }
1764
- }
1765
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: IndexedDBService, decorators: [{
1766
- type: Injectable,
1767
- args: [{
1768
- providedIn: 'root'
1769
- }]
1770
- }], ctorParameters: () => [{ type: LibCustomEnvironmentService }] });
1771
-
1772
1778
  /**
1773
1779
  * Serviço responsável por criar e gerenciar uma instância global do componente SearchInput.
1774
1780
  *