@bravobit/bb-foundation 0.23.7 → 0.24.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.
Files changed (207) hide show
  1. package/auth/lib/auth.module.d.ts +2 -3
  2. package/auth/lib/interfaces/config.interface.d.ts +0 -4
  3. package/auth/public_api.d.ts +0 -5
  4. package/esm2020/auth/lib/auth.interceptor.mjs +4 -4
  5. package/esm2020/auth/lib/auth.module.mjs +7 -16
  6. package/esm2020/auth/lib/auth.service.mjs +5 -5
  7. package/esm2020/auth/lib/directives/authenticated.directive.mjs +4 -4
  8. package/esm2020/auth/lib/guards/anonymous.guard.mjs +4 -4
  9. package/esm2020/auth/lib/guards/authenticated.guard.mjs +4 -4
  10. package/esm2020/auth/lib/interfaces/config.interface.mjs +1 -1
  11. package/esm2020/auth/public_api.mjs +1 -6
  12. package/esm2020/collections/lib/collections.module.mjs +5 -5
  13. package/esm2020/collections/lib/components/collections-pager/collections-pager.component.mjs +4 -4
  14. package/esm2020/collections/lib/components/collections-viewer/collections-viewer.component.mjs +4 -4
  15. package/esm2020/collections/lib/components/collections.directive.mjs +13 -13
  16. package/esm2020/controls/lib/checkbox/checkbox/checkbox.component.mjs +4 -4
  17. package/esm2020/controls/lib/checkbox/checkbox-group/checkbox-group.component.mjs +4 -4
  18. package/esm2020/controls/lib/checkbox/checkbox.module.mjs +5 -5
  19. package/esm2020/controls/lib/control-error/control-error/control-error.component.mjs +4 -4
  20. package/esm2020/controls/lib/control-error/control-error-submit.directive.mjs +4 -4
  21. package/esm2020/controls/lib/control-error/control-error.module.mjs +5 -5
  22. package/esm2020/controls/lib/controls.module.mjs +5 -5
  23. package/esm2020/controls/lib/form-control/form-control/form-control.component.mjs +4 -4
  24. package/esm2020/controls/lib/form-control/form-control-addon/form-control-addon.component.mjs +4 -4
  25. package/esm2020/controls/lib/form-control/form-control-input.directive.mjs +4 -4
  26. package/esm2020/controls/lib/form-control/form-control.module.mjs +5 -5
  27. package/esm2020/controls/lib/radio/radio-button/radio-button.component.mjs +4 -4
  28. package/esm2020/controls/lib/radio/radio-group/radio-group.component.mjs +4 -4
  29. package/esm2020/controls/lib/radio/radio.module.mjs +5 -5
  30. package/esm2020/controls/lib/toggle/toggle/toggle.component.mjs +4 -4
  31. package/esm2020/controls/lib/toggle/toggle-group/toggle-group.component.mjs +4 -4
  32. package/esm2020/controls/lib/toggle/toggle.module.mjs +5 -5
  33. package/esm2020/dashboard/lib/dashboard/dashboard.component.mjs +4 -4
  34. package/esm2020/dashboard/lib/dashboard-header/dashboard-header.component.mjs +4 -4
  35. package/esm2020/dashboard/lib/dashboard-menu/dashboard-menu.component.mjs +4 -4
  36. package/esm2020/dashboard/lib/dashboard-menu-item/dashboard-menu-item.component.mjs +4 -4
  37. package/esm2020/dashboard/lib/dashboard-sidebar/dashboard-sidebar.component.mjs +4 -4
  38. package/esm2020/dashboard/lib/dashboard-sidebar-group/dashboard-sidebar-group.component.mjs +4 -4
  39. package/esm2020/dashboard/lib/dashboard-sidebar-item/dashboard-sidebar-item.component.mjs +4 -4
  40. package/esm2020/dashboard/lib/dashboard.module.mjs +5 -5
  41. package/esm2020/dialog/lib/dialog-actions/dialog-actions.component.mjs +4 -4
  42. package/esm2020/dialog/lib/dialog-confirm/dialog-confirm.component.mjs +4 -4
  43. package/esm2020/dialog/lib/dialog-container/dialog-container.component.mjs +4 -4
  44. package/esm2020/dialog/lib/dialog-header/dialog-header.component.mjs +4 -4
  45. package/esm2020/dialog/lib/dialog-link/dialog-link.component.mjs +4 -4
  46. package/esm2020/dialog/lib/dialog-modal/dialog-modal.component.mjs +4 -4
  47. package/esm2020/dialog/lib/dialog-overlay/dialog-overlay.component.mjs +4 -4
  48. package/esm2020/dialog/lib/dialog.insertion.mjs +4 -4
  49. package/esm2020/dialog/lib/dialog.module.mjs +5 -5
  50. package/esm2020/dialog/lib/dialog.service.mjs +4 -4
  51. package/esm2020/elements/lib/avatar/avatar.component.mjs +4 -4
  52. package/esm2020/elements/lib/button/button.component.mjs +7 -7
  53. package/esm2020/elements/lib/checkbox/checkbox.component.mjs +4 -4
  54. package/esm2020/elements/lib/date-picker/date-picker.component.mjs +4 -4
  55. package/esm2020/elements/lib/directives/addon.directive.mjs +7 -7
  56. package/esm2020/elements/lib/directives/form-submit.directive.mjs +4 -4
  57. package/esm2020/elements/lib/directives/form-submitter.directive.mjs +4 -4
  58. package/esm2020/elements/lib/directives/input.directive.mjs +7 -7
  59. package/esm2020/elements/lib/dropdown/dropdown.component.mjs +7 -7
  60. package/esm2020/elements/lib/elements.module.mjs +5 -5
  61. package/esm2020/elements/lib/file-picker/file-picker.component.mjs +4 -4
  62. package/esm2020/elements/lib/form-control/form-control.component.mjs +4 -4
  63. package/esm2020/elements/lib/form-error/form-error.component.mjs +4 -4
  64. package/esm2020/elements/lib/form-group/form-group.component.mjs +4 -4
  65. package/esm2020/elements/lib/icon/icon.component.mjs +4 -4
  66. package/esm2020/elements/lib/image-picker/image-picker.component.mjs +4 -4
  67. package/esm2020/elements/lib/pipes/file-image.pipe.mjs +4 -4
  68. package/esm2020/elements/lib/pipes/file-size.pipe.mjs +4 -4
  69. package/esm2020/elements/lib/pipes/relative-time.pipe.mjs +4 -4
  70. package/esm2020/elements/lib/spinner/spinner.component.mjs +4 -4
  71. package/esm2020/elements/lib/tag/tag.component.mjs +4 -4
  72. package/esm2020/http/lib/http.module.mjs +5 -5
  73. package/esm2020/http/lib/interceptors/base-url.interceptor.mjs +4 -4
  74. package/esm2020/http/lib/interceptors/error.interceptor.mjs +4 -4
  75. package/esm2020/lib/core/services/clipboard.service.mjs +4 -4
  76. package/esm2020/lib/core/services/exif.service.mjs +4 -4
  77. package/esm2020/lib/core/services/file-loader.service.mjs +4 -4
  78. package/esm2020/lib/core/services/image-converter.service.mjs +4 -4
  79. package/esm2020/lib/core/services/languages.service.mjs +4 -4
  80. package/esm2020/lib/core/services/network.service.mjs +4 -4
  81. package/esm2020/lib/core/services/patch.service.mjs +4 -4
  82. package/esm2020/localize/lib/localize.module.mjs +5 -5
  83. package/esm2020/localize/lib/localize.pipe.mjs +4 -4
  84. package/esm2020/localize/lib/localize.service.mjs +4 -4
  85. package/esm2020/localize/lib/views/localize-string/localize-string.component.mjs +4 -4
  86. package/esm2020/localize/lib/views/localize-template.directive.mjs +4 -4
  87. package/esm2020/masking/lib/directives/currency-mask.directive.mjs +4 -4
  88. package/esm2020/masking/lib/directives/date-mask.directive.mjs +4 -4
  89. package/esm2020/masking/lib/directives/input-mask.directive.mjs +4 -4
  90. package/esm2020/masking/lib/masking.module.mjs +5 -5
  91. package/esm2020/masking/lib/masking.service.mjs +4 -4
  92. package/esm2020/notifications/lib/notifications-item/notifications-item.component.mjs +4 -4
  93. package/esm2020/notifications/lib/notifications-list/notifications-list.component.mjs +4 -4
  94. package/esm2020/notifications/lib/notifications.module.mjs +5 -5
  95. package/esm2020/notifications/lib/notifications.service.mjs +4 -4
  96. package/esm2020/permissions/bravobit-bb-foundation-permissions.mjs +5 -0
  97. package/esm2020/permissions/lib/directives/permission.directive.mjs +88 -0
  98. package/esm2020/permissions/lib/guards/permission.guard.mjs +56 -0
  99. package/esm2020/permissions/lib/handlers/abstract.handler.mjs +3 -0
  100. package/esm2020/permissions/lib/handlers/local.handler.mjs +27 -0
  101. package/esm2020/permissions/lib/permissions.interface.mjs +3 -0
  102. package/esm2020/permissions/lib/permissions.module.mjs +39 -0
  103. package/esm2020/permissions/lib/permissions.service.mjs +96 -0
  104. package/esm2020/permissions/public_api.mjs +8 -0
  105. package/esm2020/recaptcha/lib/recaptcha/recaptcha.component.mjs +4 -4
  106. package/esm2020/recaptcha/lib/recaptcha-loader.service.mjs +4 -4
  107. package/esm2020/recaptcha/lib/recaptcha.module.mjs +5 -5
  108. package/esm2020/storage/lib/storage.service.mjs +4 -4
  109. package/esm2020/table/lib/components/table/table.component.mjs +10 -10
  110. package/esm2020/table/lib/components/table-cell/table-cell.component.mjs +4 -4
  111. package/esm2020/table/lib/components/table-header-cell/table-header-cell.component.mjs +4 -4
  112. package/esm2020/table/lib/components/table-pager/table-pager.component.mjs +4 -4
  113. package/esm2020/table/lib/table.module.mjs +5 -5
  114. package/esm2020/theming/lib/theming.directive.mjs +4 -4
  115. package/esm2020/theming/lib/theming.module.mjs +5 -5
  116. package/esm2020/utils/lib/directives/autosize.directive.mjs +4 -4
  117. package/esm2020/utils/lib/directives/focus-trap.directive.mjs +4 -4
  118. package/esm2020/utils/lib/directives/focus.directive.mjs +4 -4
  119. package/esm2020/utils/lib/directives/template.directive.mjs +4 -4
  120. package/esm2020/utils/lib/utils.module.mjs +5 -5
  121. package/fesm2015/bravobit-bb-foundation-auth.mjs +30 -261
  122. package/fesm2015/bravobit-bb-foundation-auth.mjs.map +1 -1
  123. package/fesm2015/bravobit-bb-foundation-collections.mjs +22 -22
  124. package/fesm2015/bravobit-bb-foundation-collections.mjs.map +1 -1
  125. package/fesm2015/bravobit-bb-foundation-controls.mjs +57 -57
  126. package/fesm2015/bravobit-bb-foundation-controls.mjs.map +1 -1
  127. package/fesm2015/bravobit-bb-foundation-dashboard.mjs +25 -25
  128. package/fesm2015/bravobit-bb-foundation-dashboard.mjs.map +1 -1
  129. package/fesm2015/bravobit-bb-foundation-dialog.mjs +31 -31
  130. package/fesm2015/bravobit-bb-foundation-dialog.mjs.map +1 -1
  131. package/fesm2015/bravobit-bb-foundation-elements.mjs +76 -76
  132. package/fesm2015/bravobit-bb-foundation-elements.mjs.map +1 -1
  133. package/fesm2015/bravobit-bb-foundation-http.mjs +10 -10
  134. package/fesm2015/bravobit-bb-foundation-http.mjs.map +1 -1
  135. package/fesm2015/bravobit-bb-foundation-localize.mjs +16 -16
  136. package/fesm2015/bravobit-bb-foundation-localize.mjs.map +1 -1
  137. package/fesm2015/bravobit-bb-foundation-masking.mjs +16 -16
  138. package/fesm2015/bravobit-bb-foundation-masking.mjs.map +1 -1
  139. package/fesm2015/bravobit-bb-foundation-notifications.mjs +13 -13
  140. package/fesm2015/bravobit-bb-foundation-notifications.mjs.map +1 -1
  141. package/fesm2015/bravobit-bb-foundation-permissions.mjs +310 -0
  142. package/fesm2015/bravobit-bb-foundation-permissions.mjs.map +1 -0
  143. package/fesm2015/bravobit-bb-foundation-recaptcha.mjs +10 -10
  144. package/fesm2015/bravobit-bb-foundation-recaptcha.mjs.map +1 -1
  145. package/fesm2015/bravobit-bb-foundation-storage.mjs +3 -3
  146. package/fesm2015/bravobit-bb-foundation-storage.mjs.map +1 -1
  147. package/fesm2015/bravobit-bb-foundation-table.mjs +22 -22
  148. package/fesm2015/bravobit-bb-foundation-table.mjs.map +1 -1
  149. package/fesm2015/bravobit-bb-foundation-theming.mjs +7 -7
  150. package/fesm2015/bravobit-bb-foundation-theming.mjs.map +1 -1
  151. package/fesm2015/bravobit-bb-foundation-utils.mjs +16 -16
  152. package/fesm2015/bravobit-bb-foundation-utils.mjs.map +1 -1
  153. package/fesm2015/bravobit-bb-foundation.mjs +21 -21
  154. package/fesm2015/bravobit-bb-foundation.mjs.map +1 -1
  155. package/fesm2020/bravobit-bb-foundation-auth.mjs +25 -239
  156. package/fesm2020/bravobit-bb-foundation-auth.mjs.map +1 -1
  157. package/fesm2020/bravobit-bb-foundation-collections.mjs +22 -22
  158. package/fesm2020/bravobit-bb-foundation-collections.mjs.map +1 -1
  159. package/fesm2020/bravobit-bb-foundation-controls.mjs +57 -57
  160. package/fesm2020/bravobit-bb-foundation-controls.mjs.map +1 -1
  161. package/fesm2020/bravobit-bb-foundation-dashboard.mjs +25 -25
  162. package/fesm2020/bravobit-bb-foundation-dashboard.mjs.map +1 -1
  163. package/fesm2020/bravobit-bb-foundation-dialog.mjs +31 -31
  164. package/fesm2020/bravobit-bb-foundation-dialog.mjs.map +1 -1
  165. package/fesm2020/bravobit-bb-foundation-elements.mjs +76 -76
  166. package/fesm2020/bravobit-bb-foundation-elements.mjs.map +1 -1
  167. package/fesm2020/bravobit-bb-foundation-http.mjs +10 -10
  168. package/fesm2020/bravobit-bb-foundation-http.mjs.map +1 -1
  169. package/fesm2020/bravobit-bb-foundation-localize.mjs +16 -16
  170. package/fesm2020/bravobit-bb-foundation-localize.mjs.map +1 -1
  171. package/fesm2020/bravobit-bb-foundation-masking.mjs +16 -16
  172. package/fesm2020/bravobit-bb-foundation-masking.mjs.map +1 -1
  173. package/fesm2020/bravobit-bb-foundation-notifications.mjs +13 -13
  174. package/fesm2020/bravobit-bb-foundation-notifications.mjs.map +1 -1
  175. package/fesm2020/bravobit-bb-foundation-permissions.mjs +298 -0
  176. package/fesm2020/bravobit-bb-foundation-permissions.mjs.map +1 -0
  177. package/fesm2020/bravobit-bb-foundation-recaptcha.mjs +10 -10
  178. package/fesm2020/bravobit-bb-foundation-recaptcha.mjs.map +1 -1
  179. package/fesm2020/bravobit-bb-foundation-storage.mjs +3 -3
  180. package/fesm2020/bravobit-bb-foundation-storage.mjs.map +1 -1
  181. package/fesm2020/bravobit-bb-foundation-table.mjs +22 -22
  182. package/fesm2020/bravobit-bb-foundation-table.mjs.map +1 -1
  183. package/fesm2020/bravobit-bb-foundation-theming.mjs +7 -7
  184. package/fesm2020/bravobit-bb-foundation-theming.mjs.map +1 -1
  185. package/fesm2020/bravobit-bb-foundation-utils.mjs +16 -16
  186. package/fesm2020/bravobit-bb-foundation-utils.mjs.map +1 -1
  187. package/fesm2020/bravobit-bb-foundation.mjs +21 -21
  188. package/fesm2020/bravobit-bb-foundation.mjs.map +1 -1
  189. package/package.json +13 -5
  190. package/permissions/index.d.ts +5 -0
  191. package/{auth → permissions}/lib/directives/permission.directive.d.ts +11 -6
  192. package/{auth → permissions}/lib/guards/permission.guard.d.ts +4 -5
  193. package/permissions/lib/handlers/abstract.handler.d.ts +4 -0
  194. package/permissions/lib/handlers/local.handler.d.ts +10 -0
  195. package/permissions/lib/permissions.interface.d.ts +12 -0
  196. package/permissions/lib/permissions.module.d.ts +10 -0
  197. package/permissions/lib/permissions.service.d.ts +23 -0
  198. package/permissions/public_api.d.ts +7 -0
  199. package/README.md +0 -47
  200. package/auth/lib/interfaces/permission.interface.d.ts +0 -6
  201. package/auth/lib/permissions/permissions.handler.d.ts +0 -9
  202. package/auth/lib/permissions/permissions.service.d.ts +0 -18
  203. package/esm2020/auth/lib/directives/permission.directive.mjs +0 -58
  204. package/esm2020/auth/lib/guards/permission.guard.mjs +0 -63
  205. package/esm2020/auth/lib/interfaces/permission.interface.mjs +0 -2
  206. package/esm2020/auth/lib/permissions/permissions.handler.mjs +0 -33
  207. package/esm2020/auth/lib/permissions/permissions.service.mjs +0 -73
@@ -2,8 +2,8 @@ import * as i0 from '@angular/core';
2
2
  import { InjectionToken, Injectable, Optional, Inject, Directive, Input, APP_INITIALIZER, NgModule } from '@angular/core';
3
3
  import * as i3 from '@angular/common/http';
4
4
  import { HttpContextToken, HttpContext, HttpErrorResponse, HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
5
- import { shareReplay, tap, map, distinctUntilChanged, switchMap, catchError, filter, take, finalize } from 'rxjs/operators';
6
- import { firstValueFrom, BehaviorSubject, of, Subscription, combineLatest, first, throwError } from 'rxjs';
5
+ import { shareReplay, tap, map, distinctUntilChanged, catchError, filter, take, switchMap, finalize } from 'rxjs/operators';
6
+ import { firstValueFrom, BehaviorSubject, of, Subscription, first, throwError } from 'rxjs';
7
7
  import * as i5 from '@angular/platform-browser';
8
8
  import { makeStateKey } from '@angular/platform-browser';
9
9
  import * as i2$1 from '@angular/router';
@@ -368,7 +368,7 @@ class Auth {
368
368
  async signIn(provider, as) {
369
369
  const { accessToken, refreshToken, user, ...result } = await provider.authenticate(this._httpClient);
370
370
  // Check if the role matches.
371
- const role = this._config?.permissions?.getRole?.(user) ?? user?.role ?? null;
371
+ const role = user?.role ?? null;
372
372
  if (as && !as.includes(role)) {
373
373
  throw new Error('Invalid role.');
374
374
  }
@@ -542,9 +542,9 @@ class Auth {
542
542
  .join('/');
543
543
  }
544
544
  }
545
- Auth.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: Auth, deps: [{ token: i1.Storage }, { token: i0.Injector }, { token: i2.Platform }, { token: i3.HttpClient }, { token: AuthConfig, optional: true }, { token: i5.TransferState, optional: true }, { token: i6.HttpConfig, optional: true }, { token: AUTH_REDIRECT_HANDLER, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
546
- Auth.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: Auth });
547
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: Auth, decorators: [{
545
+ Auth.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.10", ngImport: i0, type: Auth, deps: [{ token: i1.Storage }, { token: i0.Injector }, { token: i2.Platform }, { token: i3.HttpClient }, { token: AuthConfig, optional: true }, { token: i5.TransferState, optional: true }, { token: i6.HttpConfig, optional: true }, { token: AUTH_REDIRECT_HANDLER, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
546
+ Auth.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.10", ngImport: i0, type: Auth });
547
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.10", ngImport: i0, type: Auth, decorators: [{
548
548
  type: Injectable
549
549
  }], ctorParameters: function () { return [{ type: i1.Storage }, { type: i0.Injector }, { type: i2.Platform }, { type: i3.HttpClient }, { type: AuthConfig, decorators: [{
550
550
  type: Optional
@@ -584,9 +584,9 @@ class BbAuthenticated extends AbstractAuthDirective {
584
584
  this._subscription?.unsubscribe();
585
585
  }
586
586
  }
587
- BbAuthenticated.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: BbAuthenticated, deps: [{ token: Auth }, { token: i0.TemplateRef }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
588
- BbAuthenticated.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.5", type: BbAuthenticated, selector: "[bbAuthenticated]", inputs: { bbAuthenticatedElse: "bbAuthenticatedElse" }, usesInheritance: true, ngImport: i0 });
589
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: BbAuthenticated, decorators: [{
587
+ BbAuthenticated.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.10", ngImport: i0, type: BbAuthenticated, deps: [{ token: Auth }, { token: i0.TemplateRef }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
588
+ BbAuthenticated.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.10", type: BbAuthenticated, selector: "[bbAuthenticated]", inputs: { bbAuthenticatedElse: "bbAuthenticatedElse" }, usesInheritance: true, ngImport: i0 });
589
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.10", ngImport: i0, type: BbAuthenticated, decorators: [{
590
590
  type: Directive,
591
591
  args: [{
592
592
  selector: '[bbAuthenticated]'
@@ -595,158 +595,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.5", ngImpor
595
595
  type: Input
596
596
  }] } });
597
597
 
598
- class Permissions {
599
- constructor(_auth, _config) {
600
- this._auth = _auth;
601
- this._config = _config;
602
- // Data.
603
- this._permissionHandler = this._config?.permissions ?? null;
604
- }
605
- has(value, options) {
606
- const requiredPermissions = this.getRequiredPermissions(value);
607
- if (requiredPermissions?.length <= 0) {
608
- return of(false);
609
- }
610
- return this._auth.user.pipe(map(user => this.hasPermission(requiredPermissions, user, options)), distinctUntilChanged());
611
- }
612
- hasSync(value, options) {
613
- const requiredPermissions = this.getRequiredPermissions(value);
614
- if (requiredPermissions?.length <= 0) {
615
- return false;
616
- }
617
- const user = this._auth?.session?.snapshot?.user ?? null;
618
- return this.hasPermission(requiredPermissions, user, options);
619
- }
620
- hasPermission(requiredPermissions, user, options) {
621
- if (user === null || user === undefined || !this._permissionHandler) {
622
- return false;
623
- }
624
- const mode = options?.mode ?? 'and';
625
- switch (mode) {
626
- case 'or':
627
- return this.verifyModeOr(requiredPermissions, user);
628
- case 'and':
629
- default:
630
- return this.verifyModeAnd(requiredPermissions, user);
631
- }
632
- }
633
- verifyModeAnd(permissions, user) {
634
- for (const permission of permissions) {
635
- const verified = this._permissionHandler.verifyForUser(permission, user);
636
- if (!verified) {
637
- return false;
638
- }
639
- }
640
- return true;
641
- }
642
- verifyModeOr(permissions, user) {
643
- for (const permission of permissions) {
644
- const verified = this._permissionHandler.verifyForUser(permission, user);
645
- if (verified) {
646
- return true;
647
- }
648
- }
649
- return false;
650
- }
651
- getRequiredPermissions(value) {
652
- return Array.isArray(value)
653
- ? value
654
- : [value];
655
- }
656
- }
657
- Permissions.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: Permissions, deps: [{ token: Auth }, { token: AuthConfig, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
658
- Permissions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: Permissions });
659
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: Permissions, decorators: [{
660
- type: Injectable
661
- }], ctorParameters: function () { return [{ type: Auth }, { type: AuthConfig, decorators: [{
662
- type: Optional
663
- }] }]; } });
664
-
665
- class BbPermission extends AbstractAuthDirective {
666
- constructor(_permissions, _templateRef, _viewContainerRef) {
667
- super(_templateRef, _viewContainerRef);
668
- this._permissions = _permissions;
669
- this._templateRef = _templateRef;
670
- this._viewContainerRef = _viewContainerRef;
671
- // Data.
672
- this._permission$ = new BehaviorSubject([]);
673
- this._mode$ = new BehaviorSubject('and');
674
- // Subscriptions.
675
- this._subscription = new Subscription();
676
- }
677
- set bbPermission(value) {
678
- const permissions = Array.isArray(value) ? value : [value];
679
- this._permission$.next(permissions);
680
- this.updateView();
681
- }
682
- set bbPermissionElse(templateRef) {
683
- this.assertTemplate('bbPermissionElse', templateRef);
684
- this.elseTemplateRef = templateRef;
685
- this.updateView();
686
- }
687
- set bbPermissionMode(mode) {
688
- this._mode$.next(mode);
689
- }
690
- ngOnInit() {
691
- const check$ = combineLatest([this._permission$, this._mode$]).pipe(switchMap(([permissions, mode]) => this._permissions.has(permissions, { mode })), distinctUntilChanged());
692
- const subscription = check$.subscribe(valid => {
693
- this.valid = valid;
694
- this.updateView();
695
- });
696
- this._subscription.add(subscription);
697
- }
698
- ngOnDestroy() {
699
- this._subscription?.unsubscribe();
700
- }
701
- }
702
- BbPermission.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: BbPermission, deps: [{ token: Permissions }, { token: i0.TemplateRef }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
703
- BbPermission.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.5", type: BbPermission, selector: "[bbPermission]", inputs: { bbPermission: "bbPermission", bbPermissionElse: "bbPermissionElse", bbPermissionMode: "bbPermissionMode" }, usesInheritance: true, ngImport: i0 });
704
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: BbPermission, decorators: [{
705
- type: Directive,
706
- args: [{
707
- selector: '[bbPermission]'
708
- }]
709
- }], ctorParameters: function () { return [{ type: Permissions }, { type: i0.TemplateRef }, { type: i0.ViewContainerRef }]; }, propDecorators: { bbPermission: [{
710
- type: Input
711
- }], bbPermissionElse: [{
712
- type: Input
713
- }], bbPermissionMode: [{
714
- type: Input
715
- }] } });
716
-
717
- class AppPermissions {
718
- constructor(_data) {
719
- this._data = _data;
720
- }
721
- verify(permission, role) {
722
- if ((typeof ngDevMode === 'undefined' || ngDevMode) && !this._data?.[role]) {
723
- console?.warn?.(`Current permissions do not include role: "${role}".`);
724
- }
725
- const availablePermissions = this._data?.[role] ?? [];
726
- return availablePermissions.includes(permission);
727
- }
728
- verifyForUser(permission, data) {
729
- const role = this.getRole(data);
730
- return this.verify(permission, role);
731
- }
732
- getRole(data) {
733
- return data?.['role'] ?? null;
734
- }
735
- static forRoles(data) {
736
- const permissions = Object.keys(data) ?? [];
737
- const roles = permissions.reduce((previous, current) => ([
738
- ...previous,
739
- ...(data?.[current] ?? [])
740
- ]), []);
741
- const uniqueRoles = [...new Set(roles)];
742
- const formattedData = uniqueRoles.reduce((previous, current) => {
743
- const rolePermissions = permissions.filter(permission => data?.[permission]?.includes(current));
744
- return { ...previous, [current]: rolePermissions };
745
- }, {});
746
- return new AppPermissions(formattedData);
747
- }
748
- }
749
-
750
598
  class BbAnonymousGuard {
751
599
  constructor(_auth, _router, _config, _handler) {
752
600
  this._auth = _auth;
@@ -776,9 +624,9 @@ class BbAnonymousGuard {
776
624
  return this.canActivate(childRoute, state);
777
625
  }
778
626
  }
779
- BbAnonymousGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: BbAnonymousGuard, deps: [{ token: Auth }, { token: i2$1.Router }, { token: AuthConfig, optional: true }, { token: AUTH_REDIRECT_HANDLER, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
780
- BbAnonymousGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: BbAnonymousGuard, providedIn: 'root' });
781
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: BbAnonymousGuard, decorators: [{
627
+ BbAnonymousGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.10", ngImport: i0, type: BbAnonymousGuard, deps: [{ token: Auth }, { token: i2$1.Router }, { token: AuthConfig, optional: true }, { token: AUTH_REDIRECT_HANDLER, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
628
+ BbAnonymousGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.10", ngImport: i0, type: BbAnonymousGuard, providedIn: 'root' });
629
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.10", ngImport: i0, type: BbAnonymousGuard, decorators: [{
782
630
  type: Injectable,
783
631
  args: [{
784
632
  providedIn: 'root'
@@ -824,9 +672,9 @@ class BbAuthenticatedGuard {
824
672
  return this.canActivate(childRoute, state);
825
673
  }
826
674
  }
827
- BbAuthenticatedGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: BbAuthenticatedGuard, deps: [{ token: Auth }, { token: i2$1.Router }, { token: AuthConfig, optional: true }, { token: AUTH_REDIRECT_HANDLER, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
828
- BbAuthenticatedGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: BbAuthenticatedGuard, providedIn: 'root' });
829
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: BbAuthenticatedGuard, decorators: [{
675
+ BbAuthenticatedGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.10", ngImport: i0, type: BbAuthenticatedGuard, deps: [{ token: Auth }, { token: i2$1.Router }, { token: AuthConfig, optional: true }, { token: AUTH_REDIRECT_HANDLER, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
676
+ BbAuthenticatedGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.10", ngImport: i0, type: BbAuthenticatedGuard, providedIn: 'root' });
677
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.10", ngImport: i0, type: BbAuthenticatedGuard, decorators: [{
830
678
  type: Injectable,
831
679
  args: [{
832
680
  providedIn: 'root'
@@ -840,61 +688,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.5", ngImpor
840
688
  args: [AUTH_REDIRECT_HANDLER]
841
689
  }] }]; } });
842
690
 
843
- class BbPermissionGuard {
844
- constructor(_router, _permissions, _config, _handler) {
845
- this._router = _router;
846
- this._permissions = _permissions;
847
- this._config = _config;
848
- this._handler = _handler;
849
- }
850
- canActivate(snapshot, state) {
851
- const permission = snapshot?.data?.['permission'] ?? null;
852
- const permission$ = this.parsePermission(permission);
853
- return permission$.pipe(map(valid => {
854
- if (valid) {
855
- return true;
856
- }
857
- if (this._handler) {
858
- return this._handler.onPermissionDenied(snapshot, state);
859
- }
860
- const nextUrl = this._config?.redirects?.permissionDenied ?? null;
861
- if (!nextUrl) {
862
- return false;
863
- }
864
- const commands = Array.isArray(nextUrl) ? nextUrl : [nextUrl];
865
- return valid ? true : this._router.createUrlTree(commands);
866
- }));
867
- }
868
- canActivateChild(childRoute, state) {
869
- return this.canActivate(childRoute, state);
870
- }
871
- parsePermission(data) {
872
- if ((typeof ngDevMode === 'undefined' || ngDevMode) && (data === undefined || data === null)) {
873
- console?.warn?.(`No "data.permission" property was passed.`);
874
- return of(false);
875
- }
876
- if (Array.isArray(data) || typeof data === 'string') {
877
- return this._permissions.has(data);
878
- }
879
- return this._permissions.has(data?.value, data?.options);
880
- }
881
- }
882
- BbPermissionGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: BbPermissionGuard, deps: [{ token: i2$1.Router }, { token: Permissions }, { token: AuthConfig, optional: true }, { token: AUTH_REDIRECT_HANDLER, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
883
- BbPermissionGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: BbPermissionGuard, providedIn: 'root' });
884
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: BbPermissionGuard, decorators: [{
885
- type: Injectable,
886
- args: [{
887
- providedIn: 'root'
888
- }]
889
- }], ctorParameters: function () { return [{ type: i2$1.Router }, { type: Permissions }, { type: AuthConfig, decorators: [{
890
- type: Optional
891
- }] }, { type: undefined, decorators: [{
892
- type: Optional
893
- }, {
894
- type: Inject,
895
- args: [AUTH_REDIRECT_HANDLER]
896
- }] }]; } });
897
-
898
691
  class AuthInterceptor {
899
692
  constructor(_auth, _config) {
900
693
  this._auth = _auth;
@@ -968,25 +761,20 @@ class AuthInterceptor {
968
761
  return of(null);
969
762
  }
970
763
  }
971
- AuthInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: AuthInterceptor, deps: [{ token: Auth }, { token: AuthConfig, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
972
- AuthInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: AuthInterceptor });
973
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: AuthInterceptor, decorators: [{
764
+ AuthInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.10", ngImport: i0, type: AuthInterceptor, deps: [{ token: Auth }, { token: AuthConfig, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
765
+ AuthInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.10", ngImport: i0, type: AuthInterceptor });
766
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.10", ngImport: i0, type: AuthInterceptor, decorators: [{
974
767
  type: Injectable
975
768
  }], ctorParameters: function () { return [{ type: Auth }, { type: AuthConfig, decorators: [{
976
769
  type: Optional
977
770
  }] }]; } });
978
771
 
979
- const DECLARATIONS_EXPORTS = [
980
- BbAuthenticated,
981
- BbPermission
982
- ];
983
772
  class AuthModule {
984
773
  static forRoot(config) {
985
774
  return {
986
775
  ngModule: AuthModule,
987
776
  providers: [
988
777
  Auth,
989
- Permissions,
990
778
  { provide: AuthConfig, useValue: config },
991
779
  { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true },
992
780
  { useFactory: initializeAuth, provide: APP_INITIALIZER, deps: [Auth], multi: true }
@@ -994,17 +782,15 @@ class AuthModule {
994
782
  };
995
783
  }
996
784
  }
997
- AuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: AuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
998
- AuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.5", ngImport: i0, type: AuthModule, declarations: [BbAuthenticated,
999
- BbPermission], imports: [HttpClientModule], exports: [BbAuthenticated,
1000
- BbPermission] });
1001
- AuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: AuthModule, imports: [HttpClientModule] });
1002
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.5", ngImport: i0, type: AuthModule, decorators: [{
785
+ AuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.10", ngImport: i0, type: AuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
786
+ AuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.10", ngImport: i0, type: AuthModule, declarations: [BbAuthenticated], imports: [HttpClientModule], exports: [BbAuthenticated] });
787
+ AuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.10", ngImport: i0, type: AuthModule, imports: [HttpClientModule] });
788
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.10", ngImport: i0, type: AuthModule, decorators: [{
1003
789
  type: NgModule,
1004
790
  args: [{
1005
791
  imports: [HttpClientModule],
1006
- declarations: [...DECLARATIONS_EXPORTS],
1007
- exports: [...DECLARATIONS_EXPORTS]
792
+ declarations: [BbAuthenticated],
793
+ exports: [BbAuthenticated]
1008
794
  }]
1009
795
  }] });
1010
796
  function initializeAuth(auth) {
@@ -1015,5 +801,5 @@ function initializeAuth(auth) {
1015
801
  * Generated bundle index. Do not edit.
1016
802
  */
1017
803
 
1018
- export { AUTH_REDIRECT_HANDLER, AppPermissions, Auth, AuthConfig, AuthEmailProvider, AuthModule, AuthSession, AuthVerifyProvider, BbAnonymousGuard, BbAuthenticated, BbAuthenticatedGuard, BbPermission, BbPermissionGuard, JwtHelper, Permissions, USE_AUTHORIZATION, initializeAuth };
804
+ export { AUTH_REDIRECT_HANDLER, Auth, AuthConfig, AuthEmailProvider, AuthModule, AuthSession, AuthVerifyProvider, BbAnonymousGuard, BbAuthenticated, BbAuthenticatedGuard, JwtHelper, USE_AUTHORIZATION, initializeAuth };
1019
805
  //# sourceMappingURL=bravobit-bb-foundation-auth.mjs.map