@bravobit/bb-foundation 0.15.5 → 0.16.2

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 (388) hide show
  1. package/auth/lib/auth.interceptor.d.ts +1 -1
  2. package/auth/lib/auth.service.d.ts +1 -1
  3. package/auth/package.json +5 -5
  4. package/collections/package.json +5 -5
  5. package/controls/bravobit-bb-foundation-controls.d.ts +5 -0
  6. package/controls/lib/checkbox/checkbox/checkbox.component.d.ts +47 -0
  7. package/controls/lib/checkbox/checkbox-group/checkbox-group.component.d.ts +18 -0
  8. package/controls/lib/checkbox/checkbox.module.d.ts +9 -0
  9. package/controls/lib/controls.module.d.ts +7 -0
  10. package/controls/package.json +10 -0
  11. package/controls/public_api.d.ts +4 -0
  12. package/dashboard/package.json +5 -5
  13. package/dialog/package.json +5 -5
  14. package/elements/package.json +5 -5
  15. package/{esm2015/auth/bravobit-bb-foundation-auth.js → esm2020/auth/bravobit-bb-foundation-auth.mjs} +0 -0
  16. package/esm2020/auth/lib/auth.interceptor.mjs +94 -0
  17. package/{esm2015/auth/lib/auth.module.js → esm2020/auth/lib/auth.module.mjs} +5 -5
  18. package/esm2020/auth/lib/auth.service.mjs +276 -0
  19. package/esm2020/auth/lib/auth.session.mjs +131 -0
  20. package/{esm2015/auth/lib/directives/authenticated.directive.js → esm2020/auth/lib/directives/authenticated.directive.mjs} +5 -6
  21. package/esm2020/auth/lib/directives/permission.directive.mjs +80 -0
  22. package/esm2020/auth/lib/directives/role.directive.mjs +37 -0
  23. package/esm2020/auth/lib/guards/anonymous.guard.mjs +34 -0
  24. package/esm2020/auth/lib/guards/authenticated.guard.mjs +35 -0
  25. package/{esm2015/auth/lib/helpers/jwt.helper.js → esm2020/auth/lib/helpers/jwt.helper.mjs} +3 -3
  26. package/{esm2015/auth/lib/helpers/mapper.helper.js → esm2020/auth/lib/helpers/mapper.helper.mjs} +4 -4
  27. package/{esm2015/auth/lib/interfaces/config.interface.js → esm2020/auth/lib/interfaces/config.interface.mjs} +0 -0
  28. package/{esm2015/auth/lib/interfaces/mapper.interface.js → esm2020/auth/lib/interfaces/mapper.interface.mjs} +0 -0
  29. package/{esm2015/auth/lib/interfaces/provider.interface.js → esm2020/auth/lib/interfaces/provider.interface.mjs} +0 -0
  30. package/{esm2015/auth/lib/interfaces/token.interface.js → esm2020/auth/lib/interfaces/token.interface.mjs} +0 -0
  31. package/esm2020/auth/lib/permissions.service.mjs +56 -0
  32. package/esm2020/auth/lib/providers/email.provider.mjs +25 -0
  33. package/esm2020/auth/lib/providers/verify.provider.mjs +19 -0
  34. package/{esm2015/auth/lib/tokens/use-authorization.token.js → esm2020/auth/lib/tokens/use-authorization.token.mjs} +0 -0
  35. package/{esm2015/auth/public_api.js → esm2020/auth/public_api.mjs} +0 -0
  36. package/{esm2015/bravobit-bb-foundation.js → esm2020/bravobit-bb-foundation.mjs} +0 -0
  37. package/{esm2015/collections/bravobit-bb-foundation-collections.js → esm2020/collections/bravobit-bb-foundation-collections.mjs} +0 -0
  38. package/esm2020/collections/lib/collection.mjs +98 -0
  39. package/{esm2015/collections/lib/collections.module.js → esm2020/collections/lib/collections.module.mjs} +5 -5
  40. package/esm2020/collections/lib/components/collections-pager/collections-pager.component.mjs +123 -0
  41. package/esm2020/collections/lib/components/collections-viewer/collections-viewer.component.mjs +31 -0
  42. package/{esm2015/collections/lib/components/collections.directive.js → esm2020/collections/lib/components/collections.directive.mjs} +13 -13
  43. package/{esm2015/collections/lib/interfaces/collection.interface.js → esm2020/collections/lib/interfaces/collection.interface.mjs} +0 -0
  44. package/esm2020/collections/lib/providers/api-collection.provider.mjs +71 -0
  45. package/esm2020/collections/lib/providers/collection.provider.mjs +13 -0
  46. package/{esm2015/collections/lib/providers/local-collection.provider.js → esm2020/collections/lib/providers/local-collection.provider.mjs} +0 -0
  47. package/{esm2015/collections/public_api.js → esm2020/collections/public_api.mjs} +0 -0
  48. package/esm2020/controls/bravobit-bb-foundation-controls.mjs +5 -0
  49. package/esm2020/controls/lib/checkbox/checkbox/checkbox.component.mjs +153 -0
  50. package/esm2020/controls/lib/checkbox/checkbox-group/checkbox-group.component.mjs +48 -0
  51. package/esm2020/controls/lib/checkbox/checkbox.module.mjs +19 -0
  52. package/esm2020/controls/lib/controls.module.mjs +16 -0
  53. package/esm2020/controls/public_api.mjs +5 -0
  54. package/{esm2015/dashboard/bravobit-bb-foundation-dashboard.js → esm2020/dashboard/bravobit-bb-foundation-dashboard.mjs} +0 -0
  55. package/esm2020/dashboard/lib/dashboard/dashboard.component.mjs +56 -0
  56. package/esm2020/dashboard/lib/dashboard-header/dashboard-header.component.mjs +30 -0
  57. package/esm2020/dashboard/lib/dashboard-menu/dashboard-menu.component.mjs +31 -0
  58. package/esm2020/dashboard/lib/dashboard-menu-item/dashboard-menu-item.component.mjs +29 -0
  59. package/esm2020/dashboard/lib/dashboard-sidebar/dashboard-sidebar.component.mjs +75 -0
  60. package/esm2020/dashboard/lib/dashboard-sidebar-group/dashboard-sidebar-group.component.mjs +99 -0
  61. package/esm2020/dashboard/lib/dashboard-sidebar-item/dashboard-sidebar-item.component.mjs +62 -0
  62. package/{esm2015/dashboard/lib/dashboard.module.js → esm2020/dashboard/lib/dashboard.module.mjs} +5 -5
  63. package/{esm2015/dashboard/public_api.js → esm2020/dashboard/public_api.mjs} +0 -0
  64. package/{esm2015/dialog/bravobit-bb-foundation-dialog.js → esm2020/dialog/bravobit-bb-foundation-dialog.mjs} +0 -0
  65. package/esm2020/dialog/lib/dialog-actions/dialog-actions.component.mjs +12 -0
  66. package/esm2020/dialog/lib/dialog-confirm/dialog-confirm.component.mjs +37 -0
  67. package/{esm2015/dialog/lib/dialog-container/dialog-container.component.js → esm2020/dialog/lib/dialog-container/dialog-container.component.mjs} +6 -15
  68. package/esm2020/dialog/lib/dialog-header/dialog-header.component.mjs +25 -0
  69. package/esm2020/dialog/lib/dialog-link/dialog-link.component.mjs +11 -0
  70. package/esm2020/dialog/lib/dialog-modal/dialog-modal.component.mjs +46 -0
  71. package/esm2020/dialog/lib/dialog-overlay/dialog-overlay.component.mjs +134 -0
  72. package/{esm2015/dialog/lib/dialog.injector.js → esm2020/dialog/lib/dialog.injector.mjs} +0 -0
  73. package/{esm2015/dialog/lib/dialog.insertion.js → esm2020/dialog/lib/dialog.insertion.mjs} +4 -4
  74. package/{esm2015/dialog/lib/dialog.interfaces.js → esm2020/dialog/lib/dialog.interfaces.mjs} +0 -0
  75. package/{esm2015/dialog/lib/dialog.module.js → esm2020/dialog/lib/dialog.module.mjs} +5 -9
  76. package/{esm2015/dialog/lib/dialog.ref.js → esm2020/dialog/lib/dialog.ref.mjs} +0 -0
  77. package/{esm2015/dialog/lib/dialog.service.js → esm2020/dialog/lib/dialog.service.mjs} +5 -5
  78. package/{esm2015/dialog/public_api.js → esm2020/dialog/public_api.mjs} +0 -0
  79. package/{esm2015/elements/bravobit-bb-foundation-elements.js → esm2020/elements/bravobit-bb-foundation-elements.mjs} +0 -0
  80. package/esm2020/elements/lib/avatar/avatar.component.mjs +142 -0
  81. package/esm2020/elements/lib/button/button.component.mjs +61 -0
  82. package/esm2020/elements/lib/checkbox/checkbox.component.mjs +73 -0
  83. package/esm2020/elements/lib/date-picker/date-picker.component.mjs +304 -0
  84. package/{esm2015/elements/lib/directives/addon.directive.js → esm2020/elements/lib/directives/addon.directive.mjs} +7 -7
  85. package/esm2020/elements/lib/directives/autosize.directive.mjs +72 -0
  86. package/{esm2015/elements/lib/directives/focus-trap.directive.js → esm2020/elements/lib/directives/focus-trap.directive.mjs} +4 -4
  87. package/{esm2015/elements/lib/directives/focus.directive.js → esm2020/elements/lib/directives/focus.directive.mjs} +4 -4
  88. package/esm2020/elements/lib/directives/form-submit.directive.mjs +50 -0
  89. package/esm2020/elements/lib/directives/input.directive.mjs +136 -0
  90. package/{esm2015/elements/lib/directives/template.directive.js → esm2020/elements/lib/directives/template.directive.mjs} +4 -4
  91. package/esm2020/elements/lib/dropdown/dropdown.component.mjs +100 -0
  92. package/{esm2015/elements/lib/elements.interfaces.js → esm2020/elements/lib/elements.interfaces.mjs} +0 -0
  93. package/{esm2015/elements/lib/elements.module.js → esm2020/elements/lib/elements.module.mjs} +5 -5
  94. package/esm2020/elements/lib/file-picker/file-picker.component.mjs +236 -0
  95. package/esm2020/elements/lib/form-control/form-control.component.mjs +49 -0
  96. package/esm2020/elements/lib/form-error/form-error.component.mjs +108 -0
  97. package/esm2020/elements/lib/form-group/form-group.component.mjs +18 -0
  98. package/esm2020/elements/lib/icon/icon.component.mjs +102 -0
  99. package/esm2020/elements/lib/image-picker/image-picker.component.mjs +106 -0
  100. package/esm2020/elements/lib/pipes/file-image.pipe.mjs +42 -0
  101. package/{esm2015/elements/lib/pipes/file-size.pipe.js → esm2020/elements/lib/pipes/file-size.pipe.mjs} +4 -4
  102. package/esm2020/elements/lib/pipes/relative-time.pipe.mjs +94 -0
  103. package/esm2020/elements/lib/spinner/spinner.component.mjs +25 -0
  104. package/esm2020/elements/lib/tag/tag.component.mjs +18 -0
  105. package/{esm2015/elements/public_api.js → esm2020/elements/public_api.mjs} +0 -0
  106. package/{esm2015/http/bravobit-bb-foundation-http.js → esm2020/http/bravobit-bb-foundation-http.mjs} +0 -0
  107. package/esm2020/http/lib/classes/http.config.mjs +29 -0
  108. package/esm2020/http/lib/classes/http.error.mjs +20 -0
  109. package/{esm2015/http/lib/http.interfaces.js → esm2020/http/lib/http.interfaces.mjs} +0 -0
  110. package/{esm2015/http/lib/http.module.js → esm2020/http/lib/http.module.mjs} +5 -5
  111. package/esm2020/http/lib/interceptors/base-url.interceptor.mjs +50 -0
  112. package/esm2020/http/lib/interceptors/error.interceptor.mjs +32 -0
  113. package/{esm2015/http/public_api.js → esm2020/http/public_api.mjs} +0 -0
  114. package/{esm2015/lib/core/miscellaneous/regex.js → esm2020/lib/core/miscellaneous/regex.mjs} +0 -0
  115. package/esm2020/lib/core/miscellaneous/validator.mjs +85 -0
  116. package/esm2020/lib/core/mixins/can-disable.mjs +16 -0
  117. package/{esm2015/lib/core/mixins/can-hide-errors.js → esm2020/lib/core/mixins/can-hide-errors.mjs} +2 -2
  118. package/esm2020/lib/core/mixins/can-load.mjs +16 -0
  119. package/{esm2015/lib/core/mixins/constructor.js → esm2020/lib/core/mixins/constructor.mjs} +0 -0
  120. package/esm2020/lib/core/mixins/has-error.mjs +16 -0
  121. package/esm2020/lib/core/mixins/is-focused.mjs +16 -0
  122. package/esm2020/lib/core/mixins/is-grouped.mjs +16 -0
  123. package/esm2020/lib/core/mixins/is-readonly.mjs +16 -0
  124. package/esm2020/lib/core/mixins/is-required.mjs +16 -0
  125. package/esm2020/lib/core/services/clipboard.service.mjs +70 -0
  126. package/esm2020/lib/core/services/exif.service.mjs +163 -0
  127. package/esm2020/lib/core/services/file-loader.service.mjs +87 -0
  128. package/esm2020/lib/core/services/image-converter.service.mjs +123 -0
  129. package/{esm2015/lib/core/services/languages.service.js → esm2020/lib/core/services/languages.service.mjs} +4 -4
  130. package/{esm2015/lib/core/services/network.service.js → esm2020/lib/core/services/network.service.mjs} +5 -6
  131. package/esm2020/lib/core/services/patch.service.mjs +63 -0
  132. package/{esm2015/lib/core/services/platform.service.js → esm2020/lib/core/services/platform.service.mjs} +5 -5
  133. package/{esm2015/lib/core/tokens/accept-language.token.js → esm2020/lib/core/tokens/accept-language.token.mjs} +0 -0
  134. package/{esm2015/lib/core/tokens/base-url.token.js → esm2020/lib/core/tokens/base-url.token.mjs} +0 -0
  135. package/{esm2015/lib/core/tokens/cookie.token.js → esm2020/lib/core/tokens/cookie.token.mjs} +0 -0
  136. package/{esm2015/lib/core/tokens/location.token.js → esm2020/lib/core/tokens/location.token.mjs} +0 -0
  137. package/{esm2015/lib/core/tokens/navigator.token.js → esm2020/lib/core/tokens/navigator.token.mjs} +0 -0
  138. package/{esm2015/lib/core/tokens/window.token.js → esm2020/lib/core/tokens/window.token.mjs} +0 -0
  139. package/{esm2015/localize/bravobit-bb-foundation-localize.js → esm2020/localize/bravobit-bb-foundation-localize.mjs} +0 -0
  140. package/{esm2015/localize/lib/functions/date.function.js → esm2020/localize/lib/functions/date.function.mjs} +0 -0
  141. package/{esm2015/localize/lib/functions/lowercase.function.js → esm2020/localize/lib/functions/lowercase.function.mjs} +0 -0
  142. package/{esm2015/localize/lib/functions/uppercase.function.js → esm2020/localize/lib/functions/uppercase.function.mjs} +0 -0
  143. package/{esm2015/localize/lib/handlers/missing.handler.js → esm2020/localize/lib/handlers/missing.handler.mjs} +0 -0
  144. package/{esm2015/localize/lib/interfaces/config.interfaces.js → esm2020/localize/lib/interfaces/config.interfaces.mjs} +0 -0
  145. package/{esm2015/localize/lib/interfaces/dictionary.interfaces.js → esm2020/localize/lib/interfaces/dictionary.interfaces.mjs} +0 -0
  146. package/{esm2015/localize/lib/interfaces/functions.interfaces.js → esm2020/localize/lib/interfaces/functions.interfaces.mjs} +0 -0
  147. package/{esm2015/localize/lib/interfaces/handlers.interfaces.js → esm2020/localize/lib/interfaces/handlers.interfaces.mjs} +0 -0
  148. package/{esm2015/localize/lib/interfaces/options.interfaces.js → esm2020/localize/lib/interfaces/options.interfaces.mjs} +0 -0
  149. package/{esm2015/localize/lib/localizations/dutch.localization.js → esm2020/localize/lib/localizations/dutch.localization.mjs} +0 -0
  150. package/{esm2015/localize/lib/localizations/english.localization.js → esm2020/localize/lib/localizations/english.localization.mjs} +0 -0
  151. package/esm2020/localize/lib/localize.dictionary.mjs +135 -0
  152. package/{esm2015/localize/lib/localize.module.js → esm2020/localize/lib/localize.module.mjs} +5 -5
  153. package/{esm2015/localize/lib/localize.pipe.js → esm2020/localize/lib/localize.pipe.mjs} +5 -5
  154. package/esm2020/localize/lib/localize.service.mjs +277 -0
  155. package/esm2020/localize/lib/views/localize-string/localize-string.component.mjs +88 -0
  156. package/{esm2015/localize/lib/views/localize-template-or-string.directive.js → esm2020/localize/lib/views/localize-template-or-string.directive.mjs} +4 -4
  157. package/{esm2015/localize/lib/views/localize-template.directive.js → esm2020/localize/lib/views/localize-template.directive.mjs} +4 -4
  158. package/{esm2015/localize/public_api.js → esm2020/localize/public_api.mjs} +0 -0
  159. package/{esm2015/notifications/bravobit-bb-foundation-notifications.js → esm2020/notifications/bravobit-bb-foundation-notifications.mjs} +0 -0
  160. package/esm2020/notifications/lib/notifications-item/notifications-item.component.mjs +100 -0
  161. package/esm2020/notifications/lib/notifications-list/notifications-list.component.mjs +47 -0
  162. package/{esm2015/notifications/lib/notifications.animations.js → esm2020/notifications/lib/notifications.animations.mjs} +0 -0
  163. package/{esm2015/notifications/lib/notifications.injector.js → esm2020/notifications/lib/notifications.injector.mjs} +0 -0
  164. package/{esm2015/notifications/lib/notifications.interfaces.js → esm2020/notifications/lib/notifications.interfaces.mjs} +0 -0
  165. package/{esm2015/notifications/lib/notifications.module.js → esm2020/notifications/lib/notifications.module.mjs} +6 -7
  166. package/{esm2015/notifications/lib/notifications.service.js → esm2020/notifications/lib/notifications.service.mjs} +5 -5
  167. package/{esm2015/notifications/public_api.js → esm2020/notifications/public_api.mjs} +0 -0
  168. package/{esm2015/public_api.js → esm2020/public_api.mjs} +1 -2
  169. package/{esm2015/recaptcha/bravobit-bb-foundation-recaptcha.js → esm2020/recaptcha/bravobit-bb-foundation-recaptcha.mjs} +0 -0
  170. package/esm2020/recaptcha/lib/recaptcha/recaptcha.component.mjs +185 -0
  171. package/esm2020/recaptcha/lib/recaptcha-loader.service.mjs +90 -0
  172. package/{esm2015/recaptcha/lib/recaptcha.interface.js → esm2020/recaptcha/lib/recaptcha.interface.mjs} +0 -0
  173. package/{esm2015/recaptcha/lib/recaptcha.module.js → esm2020/recaptcha/lib/recaptcha.module.mjs} +5 -5
  174. package/{esm2015/recaptcha/public_api.js → esm2020/recaptcha/public_api.mjs} +0 -0
  175. package/{esm2015/rxjs/bravobit-bb-foundation-rxjs.js → esm2020/rxjs/bravobit-bb-foundation-rxjs.mjs} +0 -0
  176. package/esm2020/rxjs/lib/operators/combine-latest-map.operator.mjs +10 -0
  177. package/{esm2015/rxjs/lib/operators/filter-nil.operator.js → esm2020/rxjs/lib/operators/filter-nil.operator.mjs} +0 -0
  178. package/{esm2015/rxjs/public_api.js → esm2020/rxjs/public_api.mjs} +0 -0
  179. package/{esm2015/storage/bravobit-bb-foundation-storage.js → esm2020/storage/bravobit-bb-foundation-storage.mjs} +0 -0
  180. package/{esm2015/storage/lib/interfaces/attributes.interface.js → esm2020/storage/lib/interfaces/attributes.interface.mjs} +0 -0
  181. package/{esm2015/storage/lib/interfaces/memory.interface.js → esm2020/storage/lib/interfaces/memory.interface.mjs} +0 -0
  182. package/{esm2015/storage/lib/interfaces/strategy.interface.js → esm2020/storage/lib/interfaces/strategy.interface.mjs} +0 -0
  183. package/esm2020/storage/lib/storage.service.mjs +109 -0
  184. package/esm2020/storage/lib/strategies/cookie-storage.strategy.mjs +142 -0
  185. package/{esm2015/storage/lib/strategies/memory-storage.strategy.js → esm2020/storage/lib/strategies/memory-storage.strategy.mjs} +2 -2
  186. package/esm2020/storage/lib/strategies/polyfill-storage.strategy.mjs +102 -0
  187. package/{esm2015/storage/public_api.js → esm2020/storage/public_api.mjs} +0 -0
  188. package/{esm2015/table/bravobit-bb-foundation-table.js → esm2020/table/bravobit-bb-foundation-table.mjs} +0 -0
  189. package/esm2020/table/lib/components/table/table.component.mjs +191 -0
  190. package/esm2020/table/lib/components/table-cell/table-cell.component.mjs +11 -0
  191. package/esm2020/table/lib/components/table-header-cell/table-header-cell.component.mjs +131 -0
  192. package/esm2020/table/lib/components/table-pager/table-pager.component.mjs +136 -0
  193. package/esm2020/table/lib/data/datasource.data.mjs +32 -0
  194. package/esm2020/table/lib/data/generic.data.mjs +72 -0
  195. package/{esm2015/table/lib/interfaces/datasource.interface.js → esm2020/table/lib/interfaces/datasource.interface.mjs} +0 -0
  196. package/{esm2015/table/lib/interfaces/table.interfaces.js → esm2020/table/lib/interfaces/table.interfaces.mjs} +0 -0
  197. package/{esm2015/table/lib/table.module.js → esm2020/table/lib/table.module.mjs} +5 -5
  198. package/{esm2015/table/public_api.js → esm2020/table/public_api.mjs} +0 -0
  199. package/fesm2015/{bravobit-bb-foundation-auth.js → bravobit-bb-foundation-auth.mjs} +79 -68
  200. package/fesm2015/bravobit-bb-foundation-auth.mjs.map +1 -0
  201. package/fesm2015/{bravobit-bb-foundation-collections.js → bravobit-bb-foundation-collections.mjs} +36 -47
  202. package/fesm2015/bravobit-bb-foundation-collections.mjs.map +1 -0
  203. package/fesm2015/bravobit-bb-foundation-controls.mjs +235 -0
  204. package/fesm2015/bravobit-bb-foundation-controls.mjs.map +1 -0
  205. package/fesm2015/bravobit-bb-foundation-dashboard.mjs +416 -0
  206. package/fesm2015/bravobit-bb-foundation-dashboard.mjs.map +1 -0
  207. package/fesm2015/{bravobit-bb-foundation-dialog.js → bravobit-bb-foundation-dialog.mjs} +45 -106
  208. package/fesm2015/bravobit-bb-foundation-dialog.mjs.map +1 -0
  209. package/fesm2015/{bravobit-bb-foundation-elements.js → bravobit-bb-foundation-elements.mjs} +195 -303
  210. package/fesm2015/bravobit-bb-foundation-elements.mjs.map +1 -0
  211. package/fesm2015/{bravobit-bb-foundation-http.js → bravobit-bb-foundation-http.mjs} +18 -16
  212. package/fesm2015/bravobit-bb-foundation-http.mjs.map +1 -0
  213. package/fesm2015/{bravobit-bb-foundation-localize.js → bravobit-bb-foundation-localize.mjs} +63 -69
  214. package/fesm2015/bravobit-bb-foundation-localize.mjs.map +1 -0
  215. package/fesm2015/bravobit-bb-foundation-notifications.mjs +377 -0
  216. package/fesm2015/bravobit-bb-foundation-notifications.mjs.map +1 -0
  217. package/fesm2015/{bravobit-bb-foundation-recaptcha.js → bravobit-bb-foundation-recaptcha.mjs} +40 -47
  218. package/fesm2015/bravobit-bb-foundation-recaptcha.mjs.map +1 -0
  219. package/fesm2015/{bravobit-bb-foundation-rxjs.js → bravobit-bb-foundation-rxjs.mjs} +1 -1
  220. package/fesm2015/bravobit-bb-foundation-rxjs.mjs.map +1 -0
  221. package/fesm2015/{bravobit-bb-foundation-storage.js → bravobit-bb-foundation-storage.mjs} +12 -10
  222. package/fesm2015/bravobit-bb-foundation-storage.mjs.map +1 -0
  223. package/fesm2015/bravobit-bb-foundation-table.mjs +603 -0
  224. package/fesm2015/bravobit-bb-foundation-table.mjs.map +1 -0
  225. package/fesm2015/{bravobit-bb-foundation.js → bravobit-bb-foundation.mjs} +76 -69
  226. package/fesm2015/bravobit-bb-foundation.mjs.map +1 -0
  227. package/fesm2020/bravobit-bb-foundation-auth.mjs +928 -0
  228. package/fesm2020/bravobit-bb-foundation-auth.mjs.map +1 -0
  229. package/fesm2020/bravobit-bb-foundation-collections.mjs +437 -0
  230. package/fesm2020/bravobit-bb-foundation-collections.mjs.map +1 -0
  231. package/fesm2020/bravobit-bb-foundation-controls.mjs +233 -0
  232. package/fesm2020/bravobit-bb-foundation-controls.mjs.map +1 -0
  233. package/fesm2020/bravobit-bb-foundation-dashboard.mjs +404 -0
  234. package/fesm2020/bravobit-bb-foundation-dashboard.mjs.map +1 -0
  235. package/fesm2020/bravobit-bb-foundation-dialog.mjs +584 -0
  236. package/fesm2020/bravobit-bb-foundation-dialog.mjs.map +1 -0
  237. package/fesm2020/bravobit-bb-foundation-elements.mjs +1994 -0
  238. package/fesm2020/bravobit-bb-foundation-elements.mjs.map +1 -0
  239. package/fesm2020/bravobit-bb-foundation-http.mjs +168 -0
  240. package/fesm2020/bravobit-bb-foundation-http.mjs.map +1 -0
  241. package/fesm2020/bravobit-bb-foundation-localize.mjs +832 -0
  242. package/fesm2020/bravobit-bb-foundation-localize.mjs.map +1 -0
  243. package/fesm2020/bravobit-bb-foundation-notifications.mjs +375 -0
  244. package/fesm2020/bravobit-bb-foundation-notifications.mjs.map +1 -0
  245. package/fesm2020/bravobit-bb-foundation-recaptcha.mjs +300 -0
  246. package/fesm2020/bravobit-bb-foundation-recaptcha.mjs.map +1 -0
  247. package/fesm2020/bravobit-bb-foundation-rxjs.mjs +21 -0
  248. package/fesm2020/bravobit-bb-foundation-rxjs.mjs.map +1 -0
  249. package/fesm2020/bravobit-bb-foundation-storage.mjs +413 -0
  250. package/fesm2020/bravobit-bb-foundation-storage.mjs.map +1 -0
  251. package/fesm2020/bravobit-bb-foundation-table.mjs +592 -0
  252. package/fesm2020/bravobit-bb-foundation-table.mjs.map +1 -0
  253. package/fesm2020/bravobit-bb-foundation.mjs +892 -0
  254. package/fesm2020/bravobit-bb-foundation.mjs.map +1 -0
  255. package/http/package.json +5 -5
  256. package/localize/package.json +5 -5
  257. package/notifications/package.json +5 -5
  258. package/package.json +126 -8
  259. package/public_api.d.ts +0 -1
  260. package/recaptcha/package.json +5 -5
  261. package/rxjs/package.json +5 -5
  262. package/storage/package.json +5 -5
  263. package/table/lib/components/table/table.component.d.ts +3 -0
  264. package/table/package.json +5 -5
  265. package/bundles/bravobit-bb-foundation-auth.umd.js +0 -1483
  266. package/bundles/bravobit-bb-foundation-auth.umd.js.map +0 -1
  267. package/bundles/bravobit-bb-foundation-collections.umd.js +0 -868
  268. package/bundles/bravobit-bb-foundation-collections.umd.js.map +0 -1
  269. package/bundles/bravobit-bb-foundation-dashboard.umd.js +0 -876
  270. package/bundles/bravobit-bb-foundation-dashboard.umd.js.map +0 -1
  271. package/bundles/bravobit-bb-foundation-dialog.umd.js +0 -716
  272. package/bundles/bravobit-bb-foundation-dialog.umd.js.map +0 -1
  273. package/bundles/bravobit-bb-foundation-elements.umd.js +0 -2768
  274. package/bundles/bravobit-bb-foundation-elements.umd.js.map +0 -1
  275. package/bundles/bravobit-bb-foundation-http.umd.js +0 -535
  276. package/bundles/bravobit-bb-foundation-http.umd.js.map +0 -1
  277. package/bundles/bravobit-bb-foundation-localize.umd.js +0 -1292
  278. package/bundles/bravobit-bb-foundation-localize.umd.js.map +0 -1
  279. package/bundles/bravobit-bb-foundation-notifications.umd.js +0 -794
  280. package/bundles/bravobit-bb-foundation-notifications.umd.js.map +0 -1
  281. package/bundles/bravobit-bb-foundation-recaptcha.umd.js +0 -683
  282. package/bundles/bravobit-bb-foundation-recaptcha.umd.js.map +0 -1
  283. package/bundles/bravobit-bb-foundation-rxjs.umd.js +0 -29
  284. package/bundles/bravobit-bb-foundation-rxjs.umd.js.map +0 -1
  285. package/bundles/bravobit-bb-foundation-storage.umd.js +0 -799
  286. package/bundles/bravobit-bb-foundation-storage.umd.js.map +0 -1
  287. package/bundles/bravobit-bb-foundation-table.umd.js +0 -1070
  288. package/bundles/bravobit-bb-foundation-table.umd.js.map +0 -1
  289. package/bundles/bravobit-bb-foundation.umd.js +0 -1440
  290. package/bundles/bravobit-bb-foundation.umd.js.map +0 -1
  291. package/esm2015/auth/lib/auth.interceptor.js +0 -95
  292. package/esm2015/auth/lib/auth.service.js +0 -299
  293. package/esm2015/auth/lib/auth.session.js +0 -136
  294. package/esm2015/auth/lib/directives/permission.directive.js +0 -81
  295. package/esm2015/auth/lib/directives/role.directive.js +0 -38
  296. package/esm2015/auth/lib/guards/anonymous.guard.js +0 -35
  297. package/esm2015/auth/lib/guards/authenticated.guard.js +0 -36
  298. package/esm2015/auth/lib/permissions.service.js +0 -58
  299. package/esm2015/auth/lib/providers/email.provider.js +0 -26
  300. package/esm2015/auth/lib/providers/verify.provider.js +0 -20
  301. package/esm2015/collections/lib/collection.js +0 -104
  302. package/esm2015/collections/lib/components/collections-pager/collections-pager.component.js +0 -136
  303. package/esm2015/collections/lib/components/collections-viewer/collections-viewer.component.js +0 -39
  304. package/esm2015/collections/lib/providers/api-collection.provider.js +0 -69
  305. package/esm2015/collections/lib/providers/collection.provider.js +0 -14
  306. package/esm2015/dashboard/lib/dashboard/dashboard.component.js +0 -64
  307. package/esm2015/dashboard/lib/dashboard-header/dashboard-header.component.js +0 -41
  308. package/esm2015/dashboard/lib/dashboard-menu/dashboard-menu.component.js +0 -39
  309. package/esm2015/dashboard/lib/dashboard-menu-item/dashboard-menu-item.component.js +0 -38
  310. package/esm2015/dashboard/lib/dashboard-sidebar/dashboard-sidebar.component.js +0 -83
  311. package/esm2015/dashboard/lib/dashboard-sidebar-group/dashboard-sidebar-group.component.js +0 -110
  312. package/esm2015/dashboard/lib/dashboard-sidebar-item/dashboard-sidebar-item.component.js +0 -71
  313. package/esm2015/dialog/lib/dialog-actions/dialog-actions.component.js +0 -20
  314. package/esm2015/dialog/lib/dialog-confirm/dialog-confirm.component.js +0 -45
  315. package/esm2015/dialog/lib/dialog-header/dialog-header.component.js +0 -33
  316. package/esm2015/dialog/lib/dialog-link/dialog-link.component.js +0 -19
  317. package/esm2015/dialog/lib/dialog-modal/dialog-modal.component.js +0 -54
  318. package/esm2015/dialog/lib/dialog-overlay/dialog-overlay.component.js +0 -143
  319. package/esm2015/elements/lib/avatar/avatar.component.js +0 -151
  320. package/esm2015/elements/lib/button/button.component.js +0 -79
  321. package/esm2015/elements/lib/checkbox/checkbox.component.js +0 -83
  322. package/esm2015/elements/lib/date-picker/date-picker.component.js +0 -322
  323. package/esm2015/elements/lib/directives/autosize.directive.js +0 -74
  324. package/esm2015/elements/lib/directives/form-submit.directive.js +0 -53
  325. package/esm2015/elements/lib/directives/input.directive.js +0 -139
  326. package/esm2015/elements/lib/dropdown/dropdown.component.js +0 -111
  327. package/esm2015/elements/lib/file-picker/file-picker.component.js +0 -247
  328. package/esm2015/elements/lib/form-control/form-control.component.js +0 -58
  329. package/esm2015/elements/lib/form-error/form-error.component.js +0 -116
  330. package/esm2015/elements/lib/form-group/form-group.component.js +0 -27
  331. package/esm2015/elements/lib/icon/icon.component.js +0 -110
  332. package/esm2015/elements/lib/image-picker/image-picker.component.js +0 -119
  333. package/esm2015/elements/lib/pipes/file-image.pipe.js +0 -45
  334. package/esm2015/elements/lib/pipes/relative-time.pipe.js +0 -96
  335. package/esm2015/elements/lib/spinner/spinner.component.js +0 -34
  336. package/esm2015/elements/lib/tag/tag.component.js +0 -26
  337. package/esm2015/http/lib/classes/http.config.js +0 -31
  338. package/esm2015/http/lib/classes/http.error.js +0 -21
  339. package/esm2015/http/lib/interceptors/base-url.interceptor.js +0 -52
  340. package/esm2015/http/lib/interceptors/error.interceptor.js +0 -33
  341. package/esm2015/lib/core/coercions/boolean-coercion.js +0 -4
  342. package/esm2015/lib/core/miscellaneous/validator.js +0 -86
  343. package/esm2015/lib/core/mixins/can-disable.js +0 -16
  344. package/esm2015/lib/core/mixins/can-load.js +0 -16
  345. package/esm2015/lib/core/mixins/has-error.js +0 -16
  346. package/esm2015/lib/core/mixins/is-focused.js +0 -16
  347. package/esm2015/lib/core/mixins/is-grouped.js +0 -16
  348. package/esm2015/lib/core/mixins/is-readonly.js +0 -16
  349. package/esm2015/lib/core/mixins/is-required.js +0 -16
  350. package/esm2015/lib/core/services/clipboard.service.js +0 -72
  351. package/esm2015/lib/core/services/exif.service.js +0 -168
  352. package/esm2015/lib/core/services/file-loader.service.js +0 -90
  353. package/esm2015/lib/core/services/image-converter.service.js +0 -130
  354. package/esm2015/lib/core/services/patch.service.js +0 -65
  355. package/esm2015/localize/lib/localize.dictionary.js +0 -137
  356. package/esm2015/localize/lib/localize.service.js +0 -282
  357. package/esm2015/localize/lib/views/localize-string/localize-string.component.js +0 -99
  358. package/esm2015/notifications/lib/notifications-item/notifications-item.component.js +0 -108
  359. package/esm2015/notifications/lib/notifications-list/notifications-list.component.js +0 -56
  360. package/esm2015/recaptcha/lib/recaptcha/recaptcha.component.js +0 -199
  361. package/esm2015/recaptcha/lib/recaptcha-loader.service.js +0 -93
  362. package/esm2015/rxjs/lib/operators/combine-latest-map.operator.js +0 -7
  363. package/esm2015/storage/lib/storage.service.js +0 -111
  364. package/esm2015/storage/lib/strategies/cookie-storage.strategy.js +0 -143
  365. package/esm2015/storage/lib/strategies/polyfill-storage.strategy.js +0 -102
  366. package/esm2015/table/lib/components/table/table.component.js +0 -196
  367. package/esm2015/table/lib/components/table-cell/table-cell.component.js +0 -19
  368. package/esm2015/table/lib/components/table-header-cell/table-header-cell.component.js +0 -141
  369. package/esm2015/table/lib/components/table-pager/table-pager.component.js +0 -146
  370. package/esm2015/table/lib/data/datasource.data.js +0 -32
  371. package/esm2015/table/lib/data/generic.data.js +0 -73
  372. package/fesm2015/bravobit-bb-foundation-auth.js.map +0 -1
  373. package/fesm2015/bravobit-bb-foundation-collections.js.map +0 -1
  374. package/fesm2015/bravobit-bb-foundation-dashboard.js +0 -468
  375. package/fesm2015/bravobit-bb-foundation-dashboard.js.map +0 -1
  376. package/fesm2015/bravobit-bb-foundation-dialog.js.map +0 -1
  377. package/fesm2015/bravobit-bb-foundation-elements.js.map +0 -1
  378. package/fesm2015/bravobit-bb-foundation-http.js.map +0 -1
  379. package/fesm2015/bravobit-bb-foundation-localize.js.map +0 -1
  380. package/fesm2015/bravobit-bb-foundation-notifications.js +0 -393
  381. package/fesm2015/bravobit-bb-foundation-notifications.js.map +0 -1
  382. package/fesm2015/bravobit-bb-foundation-recaptcha.js.map +0 -1
  383. package/fesm2015/bravobit-bb-foundation-rxjs.js.map +0 -1
  384. package/fesm2015/bravobit-bb-foundation-storage.js.map +0 -1
  385. package/fesm2015/bravobit-bb-foundation-table.js +0 -626
  386. package/fesm2015/bravobit-bb-foundation-table.js.map +0 -1
  387. package/fesm2015/bravobit-bb-foundation.js.map +0 -1
  388. package/lib/core/coercions/boolean-coercion.d.ts +0 -1
@@ -0,0 +1,928 @@
1
+ import * as i4 from '@angular/common/http';
2
+ import { HttpContextToken, HttpContext, HttpErrorResponse, HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
3
+ import * as i0 from '@angular/core';
4
+ import { Injectable, Optional, Directive, Input, APP_INITIALIZER, NgModule } from '@angular/core';
5
+ import { shareReplay, map, tap, distinctUntilChanged, switchMap, catchError, filter, take, finalize } from 'rxjs/operators';
6
+ import * as i6 from '@angular/platform-browser';
7
+ import { makeStateKey } from '@angular/platform-browser';
8
+ import { firstValueFrom, BehaviorSubject, of, throwError } from 'rxjs';
9
+ import { Router } from '@angular/router';
10
+ import * as i1 from '@bravobit/bb-foundation/storage';
11
+ import * as i3 from '@bravobit/bb-foundation';
12
+ import * as i7 from '@bravobit/bb-foundation/http';
13
+ import { HttpError } from '@bravobit/bb-foundation/http';
14
+
15
+ class AuthConfig {
16
+ }
17
+
18
+ const USE_AUTHORIZATION = new HttpContextToken(() => true);
19
+
20
+ class JwtHelper {
21
+ constructor() {
22
+ this.baseDecodeUnicode = (value) => {
23
+ return decodeURIComponent(atob(value).replace(/(.)/g, (_, p) => {
24
+ let code = p.charCodeAt(0).toString(16).toUpperCase();
25
+ if (code.length < 2) {
26
+ code = '0' + code;
27
+ }
28
+ return '%' + code;
29
+ }));
30
+ };
31
+ this.parse = (data) => {
32
+ return {
33
+ id: data['iss'] || null,
34
+ type: data['typ'] || null,
35
+ audience: data['aud'] || null,
36
+ issuer: data['iss'] || null,
37
+ subject: data['sub'] || null,
38
+ role: data['role'] || null,
39
+ notValidBefore: this.parseDate(data['nbf']),
40
+ expiresAt: this.parseDate(data['exp']),
41
+ issuedAt: this.parseDate(data['iat'])
42
+ };
43
+ };
44
+ this.parseDate = (epochInSeconds) => {
45
+ if (!epochInSeconds || epochInSeconds <= 0) {
46
+ return null;
47
+ }
48
+ return new Date(epochInSeconds * 1000);
49
+ };
50
+ }
51
+ decode(token) {
52
+ try {
53
+ if (token === null || token === undefined) {
54
+ return null;
55
+ }
56
+ const json = JSON.parse(this.urlDecode(token.split('.')[1]));
57
+ return this.parse(json);
58
+ }
59
+ catch {
60
+ return null;
61
+ }
62
+ }
63
+ urlDecode(token) {
64
+ const value = token || '';
65
+ let output = value
66
+ .replace(/-/g, '+')
67
+ .replace(/_/g, '/');
68
+ switch (output.length % 4) {
69
+ case 0:
70
+ break;
71
+ case 2:
72
+ output += '==';
73
+ break;
74
+ case 3:
75
+ output += '=';
76
+ break;
77
+ default:
78
+ throw 'Illegal base64url string!';
79
+ }
80
+ try {
81
+ return this.baseDecodeUnicode(output);
82
+ }
83
+ catch {
84
+ return atob(output);
85
+ }
86
+ }
87
+ }
88
+
89
+ class AuthMapper {
90
+ constructor() {
91
+ // Routes.
92
+ this.me = 'auth/me';
93
+ this.register = 'auth/register';
94
+ this.resendCode = 'auth/resend';
95
+ this.logout = 'auth/logout';
96
+ this.refresh = 'auth/refresh';
97
+ this.requestPassword = 'auth/reset';
98
+ this.resetPassword = 'auth/reset-password';
99
+ }
100
+ role(data) {
101
+ return (data && data.role) || null;
102
+ }
103
+ toRegister(data) {
104
+ // Retrieve the params.
105
+ const { token, refresh_token, user } = data;
106
+ // Map the data to the correct format.
107
+ return { accessToken: token, refreshToken: refresh_token, user: user };
108
+ }
109
+ toRefresh(data) {
110
+ // Retrieve the params.
111
+ const { token, refresh_token } = data;
112
+ // Map the data to the correct format.
113
+ return { accessToken: token, refreshToken: refresh_token };
114
+ }
115
+ }
116
+ AuthMapper.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: AuthMapper, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
117
+ AuthMapper.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: AuthMapper });
118
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: AuthMapper, decorators: [{
119
+ type: Injectable
120
+ }] });
121
+
122
+ class AuthVerifyProvider {
123
+ constructor(_code, _verifyToken, _endpoint) {
124
+ this._code = _code;
125
+ this._verifyToken = _verifyToken;
126
+ this._endpoint = _endpoint;
127
+ }
128
+ async authenticate(httpClient) {
129
+ // Execute API call.
130
+ const data$ = await httpClient.post(this._endpoint, {
131
+ token: this._code,
132
+ verify_token: this._verifyToken
133
+ });
134
+ const { token, refresh_token, user } = await firstValueFrom(data$);
135
+ // Map the data to the correct format.
136
+ return { accessToken: token, refreshToken: refresh_token, user: user };
137
+ }
138
+ }
139
+
140
+ class AuthEmailProvider {
141
+ constructor(_email, _password, _endpoint) {
142
+ this._email = _email;
143
+ this._password = _password;
144
+ this._endpoint = _endpoint;
145
+ }
146
+ async authenticate(httpClient) {
147
+ // Execute API call.
148
+ const data$ = await httpClient.post(this._endpoint, {
149
+ email: this._email,
150
+ password: this._password
151
+ });
152
+ const { token, refresh_token, user, provider, verify_token } = await firstValueFrom(data$);
153
+ // Map the data to the correct format.
154
+ return {
155
+ accessToken: token,
156
+ refreshToken: refresh_token,
157
+ user: user,
158
+ provider: provider,
159
+ verifyToken: verify_token
160
+ };
161
+ }
162
+ }
163
+
164
+ class AuthSession {
165
+ constructor(options) {
166
+ // Readonly data.
167
+ this._jwt = new JwtHelper();
168
+ // Token strings.
169
+ this._accessTokenString = null;
170
+ this._refreshTokenString = null;
171
+ // Token payloads.
172
+ this._accessTokenPayload = null;
173
+ this._refreshTokenPayload = null;
174
+ // Private user data.
175
+ this._user$ = new BehaviorSubject(null);
176
+ // Public user data.
177
+ this.user = this._user$.pipe(shareReplay(1));
178
+ this.generateKey = (applicationId, key) => {
179
+ return [applicationId, key].join('_');
180
+ };
181
+ this.isTokenValid = (token) => {
182
+ if (!token) {
183
+ return false;
184
+ }
185
+ return token?.expiresAt?.getTime() > Date.now();
186
+ };
187
+ const applicationId = options?.id ?? 'ng';
188
+ // Setting up the readonly storage keys.
189
+ this._accessTokenStorageKey = this.generateKey(applicationId, 'au_act');
190
+ this._refreshTokenStorageKey = this.generateKey(applicationId, 'au_rft');
191
+ this._userStorageKey = this.generateKey(applicationId, 'au_usr');
192
+ // Setting up the storage.
193
+ this._storage = options?.storage ?? null;
194
+ // Init methods.
195
+ this.restoreFromStorage();
196
+ }
197
+ get accessToken() {
198
+ return this.isTokenValid(this._accessTokenPayload)
199
+ ? this._accessTokenString
200
+ : null;
201
+ }
202
+ get refreshToken() {
203
+ return this.isTokenValid(this.refreshTokenPayload)
204
+ ? this._refreshTokenString
205
+ : null;
206
+ }
207
+ get accessTokenPayload() {
208
+ return this._accessTokenPayload ?? null;
209
+ }
210
+ get refreshTokenPayload() {
211
+ return this._refreshTokenPayload ?? null;
212
+ }
213
+ authenticated() {
214
+ return this.isTokenValid(this._accessTokenPayload) || this.isTokenValid(this._refreshTokenPayload);
215
+ }
216
+ setTokens(accessToken, refreshToken) {
217
+ this.setAccessToken(accessToken);
218
+ this.setRefreshToken(refreshToken);
219
+ this.syncTokensInStorage();
220
+ }
221
+ setUser(user) {
222
+ this._user$.next(user ?? null);
223
+ this.syncUserInStorage();
224
+ }
225
+ clear() {
226
+ this.setTokens(null, null);
227
+ this.setUser(null);
228
+ }
229
+ restoreFromStorage() {
230
+ if (!this._storage) {
231
+ return;
232
+ }
233
+ // Set the access token.
234
+ const accessToken = this._storage.get(this._accessTokenStorageKey);
235
+ this.setAccessToken(accessToken);
236
+ // Set the refresh token.
237
+ const refreshToken = this._storage.get(this._refreshTokenStorageKey);
238
+ this.setRefreshToken(refreshToken);
239
+ // Set the user if we have any correct token payloads.
240
+ if (this._accessTokenPayload || this._refreshTokenPayload) {
241
+ const user = this._storage.get(this._userStorageKey);
242
+ this._user$.next(user ?? null); // Note: just settings here instead of setUser() because of syncing to the storage.
243
+ }
244
+ }
245
+ syncTokensInStorage() {
246
+ if (!this._storage) {
247
+ return;
248
+ }
249
+ // Set the access token if completely valid.
250
+ if (!!this.accessToken) {
251
+ this._storage.set(this._accessTokenStorageKey, this._accessTokenString, {
252
+ expires: this._accessTokenPayload?.expiresAt
253
+ });
254
+ }
255
+ else {
256
+ this._storage.remove(this._accessTokenStorageKey);
257
+ }
258
+ // Set the refresh token if completely valid.
259
+ if (!!this.refreshToken) {
260
+ this._storage.set(this._refreshTokenStorageKey, this._refreshTokenString, {
261
+ expires: this._refreshTokenPayload?.expiresAt
262
+ });
263
+ }
264
+ else {
265
+ this._storage.remove(this._refreshTokenStorageKey);
266
+ }
267
+ }
268
+ syncUserInStorage() {
269
+ if (!this._storage) {
270
+ return;
271
+ }
272
+ const user = this._user$.getValue();
273
+ if (!user) {
274
+ return this._storage.remove(this._userStorageKey);
275
+ }
276
+ const date = new Date();
277
+ date.setFullYear(date.getFullYear() + 1);
278
+ this._storage.set(this._userStorageKey, user, {
279
+ expires: new Date(date.getTime())
280
+ });
281
+ }
282
+ setAccessToken(value) {
283
+ this._accessTokenString = value ?? null;
284
+ this._accessTokenPayload = this._jwt.decode(this._accessTokenString);
285
+ }
286
+ setRefreshToken(value) {
287
+ this._refreshTokenString = value ?? null;
288
+ this._refreshTokenPayload = this._jwt.decode(this._refreshTokenString);
289
+ }
290
+ }
291
+
292
+ class Auth {
293
+ constructor(_storage, _mapper, _injector, _platform, _httpClient, _config, _state, _httpConfig) {
294
+ this._storage = _storage;
295
+ this._mapper = _mapper;
296
+ this._injector = _injector;
297
+ this._platform = _platform;
298
+ this._httpClient = _httpClient;
299
+ this._config = _config;
300
+ this._state = _state;
301
+ this._httpConfig = _httpConfig;
302
+ // Readonly data.
303
+ this._authStateKey = makeStateKey(`bbAuthStateKey`);
304
+ this._httpAlias = this._httpConfig?.defaultAlias ?? null;
305
+ this._refreshHandler = null;
306
+ // Starting the new session.
307
+ this.session = new AuthSession({
308
+ id: this._config?.applicationId,
309
+ storage: this._storage.select(["cookie" /* Cookie */, "local" /* Local */])
310
+ });
311
+ this.user = this.session.user;
312
+ }
313
+ initialize() {
314
+ return async () => {
315
+ // Check if the app should bootstrap the authentication.
316
+ const shouldBootstrap = this._config?.bootstrap ?? true;
317
+ if (!shouldBootstrap) {
318
+ return this.handleAutoRefreshing();
319
+ }
320
+ // Only retrieve from the server when we are actually authenticated.
321
+ if (!this.session.authenticated()) {
322
+ return;
323
+ }
324
+ // Get the key from the server state.
325
+ if (this._state && this._state?.hasKey(this._authStateKey)) {
326
+ const user = this._state?.get(this._authStateKey, null) ?? null;
327
+ return this.session.setUser(user);
328
+ }
329
+ // Try to fetch the user from the server.
330
+ const user$ = this.me();
331
+ const user = await firstValueFrom(user$, { defaultValue: null });
332
+ // Set the state if exists.
333
+ if (this._state) {
334
+ this._state?.set(this._authStateKey, user ?? null);
335
+ }
336
+ // Save the user in the storage and handle auto refreshing.
337
+ this.session.setUser(user);
338
+ this.handleAutoRefreshing();
339
+ };
340
+ }
341
+ me() {
342
+ const url = this.getUrl('auth/me');
343
+ return this._httpClient.get(url);
344
+ }
345
+ async signIn(provider, as) {
346
+ const { accessToken, refreshToken, user, ...result } = await provider.authenticate(this._httpClient);
347
+ // Check if the role matches.
348
+ if (as && !as.includes(this._mapper.role(user))) {
349
+ throw new Error('Invalid role.');
350
+ }
351
+ // Validate if the provider is one of the available
352
+ // providers then return the user object and the provider.
353
+ const apiProvider = result?.provider ?? null;
354
+ const apiVerifyToken = result?.verifyToken ?? null;
355
+ const availableProviders = ['email', 'sms', 'totp'];
356
+ if (availableProviders.includes(apiProvider)) {
357
+ return { user, provider: apiProvider, verifyToken: apiVerifyToken };
358
+ }
359
+ // Set the tokens in storage.
360
+ this.setTokens(accessToken, refreshToken);
361
+ // Set the user in storage.
362
+ this.session.setUser(user);
363
+ // Return the user.
364
+ return { user };
365
+ }
366
+ async signInWithEmail(email, password, as) {
367
+ const url = this.getUrl('auth/login');
368
+ return this.signIn(new AuthEmailProvider(email, password, url), as);
369
+ }
370
+ async signInWithVerifyCode(code, verifyToken) {
371
+ const url = this.getUrl('auth/verify');
372
+ return this.signIn(new AuthVerifyProvider(code, verifyToken, url));
373
+ }
374
+ async resendVerifyCode(verifyToken) {
375
+ const url = this.getUrl('auth/resend');
376
+ const result$ = this._httpClient.post(url, {
377
+ verify_token: verifyToken
378
+ });
379
+ return firstValueFrom(result$);
380
+ }
381
+ async register(data, options) {
382
+ // Execute API call.
383
+ const url = this.getUrl('auth/register');
384
+ const result$ = this._httpClient.post(url, data, options);
385
+ const result = await firstValueFrom(result$);
386
+ // Map to the correct response.
387
+ const { accessToken, refreshToken, user } = this._mapper.toRegister(result);
388
+ // Set the tokens in storage.
389
+ this.setTokens(accessToken, refreshToken);
390
+ // Set the user in storage.
391
+ this.session.setUser(user);
392
+ // Return the user.
393
+ return user;
394
+ }
395
+ logout() {
396
+ // If we don't have a refresh token just clear the session.
397
+ // Note: We do this because else we try to invalidate
398
+ // an "undefined" refresh token.
399
+ const refreshToken = this.session.refreshToken;
400
+ if (!refreshToken) {
401
+ return this.session.clear();
402
+ }
403
+ // We do have a refresh token, so try to
404
+ // invalidate it in the backend.
405
+ try {
406
+ const url = this.getUrl('auth/logout');
407
+ const observable$ = this._httpClient.get(url, {
408
+ headers: { Authorization: refreshToken }
409
+ });
410
+ firstValueFrom(observable$).then(_ => _);
411
+ }
412
+ catch {
413
+ // Do nothing because the tokens will be deleted anyways from the session.
414
+ }
415
+ // Delete the tokens from the session.
416
+ return this.session.clear();
417
+ }
418
+ refresh() {
419
+ // If the refresh token does
420
+ // not exist just return an observable of null.
421
+ const refreshToken = this.session.refreshToken;
422
+ if (!refreshToken) {
423
+ return of(null);
424
+ }
425
+ // Perform the refresh call.
426
+ const scheme = this._config?.scheme ?? 'Bearer';
427
+ const url = this.getUrl('auth/refresh');
428
+ const context = new HttpContext()
429
+ .set(USE_AUTHORIZATION, false);
430
+ return this._httpClient.get(url, {
431
+ headers: { Authorization: `${scheme} ${refreshToken}` },
432
+ context: context
433
+ }).pipe(map(data => this._mapper.toRefresh(data)), tap(({ accessToken, refreshToken }) => this.setTokens(accessToken, refreshToken)), map(({ accessToken }) => accessToken));
434
+ }
435
+ async requestPassword(email, extraParams = {}) {
436
+ const url = this.getUrl('auth/reset');
437
+ const observable$ = this._httpClient.post(url, { ...extraParams, email });
438
+ return firstValueFrom(observable$);
439
+ }
440
+ async resetPassword(token, newPassword, extraParams = {}) {
441
+ const url = this.getUrl('auth/reset-password');
442
+ const observable$ = this._httpClient.post(url, { ...extraParams, token, password: newPassword });
443
+ return firstValueFrom(observable$);
444
+ }
445
+ guard(type, redirectUrl) {
446
+ let newUrl = null;
447
+ // Get the correct new url.
448
+ switch (type) {
449
+ case 'authenticated':
450
+ newUrl = this._config?.loggedInUrl ?? null;
451
+ break;
452
+ case 'unauthenticated':
453
+ newUrl = this._config?.redirectUrl ?? null;
454
+ break;
455
+ }
456
+ // Append a redirect url if the user is deemed
457
+ // unauthenticated.
458
+ if (type === 'unauthenticated') {
459
+ const setRedirectOnFailedAuth = this._config?.setRedirectOnFailedAuth ?? true;
460
+ if (setRedirectOnFailedAuth && redirectUrl && newUrl) {
461
+ newUrl += `?redirectUrl=${redirectUrl}`;
462
+ }
463
+ }
464
+ // Parse the url if it exists.
465
+ if (this.router && newUrl) {
466
+ return this.router.parseUrl(newUrl);
467
+ }
468
+ // Return false if the user is not allowed.
469
+ return false;
470
+ }
471
+ clearAndRedirect() {
472
+ // 1. Delete the tokens from the session.
473
+ this.session.clear();
474
+ // 2. Compose the route url.
475
+ const redirectUrl = this._config?.redirectUrl ?? null;
476
+ // 3. Route back if the user provided a redirect url.
477
+ if (this.router && redirectUrl) {
478
+ this.router.navigate([redirectUrl]).then(_ => _);
479
+ }
480
+ }
481
+ setTokens(accessToken, refreshToken) {
482
+ // Set the tokens in our session.
483
+ this.session.setTokens(accessToken, refreshToken);
484
+ // We need to update the auto refresh of the refresh token.
485
+ this.handleAutoRefreshing();
486
+ }
487
+ handleAutoRefreshing() {
488
+ const shouldAutoRefresh = this._config?.autoRefresh ?? false;
489
+ if (!shouldAutoRefresh) {
490
+ return;
491
+ }
492
+ const expiresAt = this.session.refreshTokenPayload?.expiresAt ?? null;
493
+ if (expiresAt === null || !this._platform.isBrowser) {
494
+ return;
495
+ }
496
+ const differenceInMilliseconds = expiresAt.getTime() - Date.now();
497
+ const offsetInMilliseconds = 10000; // 10 seconds.
498
+ // We want to start the refresh 10 seconds before it expires.
499
+ const actualTiming = differenceInMilliseconds - offsetInMilliseconds;
500
+ if (actualTiming <= 0) {
501
+ return;
502
+ }
503
+ // We need to cap the timings because if
504
+ // we get large numbers it might cause unwanted results.
505
+ const maxTiming = 1000 * 60 * 60 * 24; // 24 hours.
506
+ const cappedTiming = Math.max(1, Math.min(actualTiming, maxTiming));
507
+ try {
508
+ if (this._refreshHandler !== null) {
509
+ clearTimeout?.(this._refreshHandler);
510
+ this._refreshHandler = null;
511
+ }
512
+ this._refreshHandler = setTimeout?.(() => this.autoRefresh(), cappedTiming);
513
+ }
514
+ catch {
515
+ // Just ignore it.
516
+ }
517
+ }
518
+ async autoRefresh() {
519
+ try {
520
+ // We just need to wait for it to refresh.
521
+ const refresh$ = this.refresh();
522
+ await firstValueFrom(refresh$);
523
+ }
524
+ catch {
525
+ // Something went wrong refreshing, we need to clear.
526
+ this.clearAndRedirect();
527
+ }
528
+ }
529
+ get router() {
530
+ return this._injector.get(Router);
531
+ }
532
+ getUrl(endpoint) {
533
+ return [this._httpAlias, endpoint]
534
+ .filter(item => !!item)
535
+ .join('/');
536
+ }
537
+ }
538
+ Auth.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: Auth, deps: [{ token: i1.Storage }, { token: AuthMapper }, { token: i0.Injector }, { token: i3.Platform }, { token: i4.HttpClient }, { token: AuthConfig, optional: true }, { token: i6.TransferState, optional: true }, { token: i7.HttpConfig, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
539
+ Auth.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: Auth });
540
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: Auth, decorators: [{
541
+ type: Injectable
542
+ }], ctorParameters: function () { return [{ type: i1.Storage }, { type: AuthMapper }, { type: i0.Injector }, { type: i3.Platform }, { type: i4.HttpClient }, { type: AuthConfig, decorators: [{
543
+ type: Optional
544
+ }] }, { type: i6.TransferState, decorators: [{
545
+ type: Optional
546
+ }] }, { type: i7.HttpConfig, decorators: [{
547
+ type: Optional
548
+ }] }]; } });
549
+
550
+ class BbAuthenticated {
551
+ constructor(_auth, _template, _viewContainerRef) {
552
+ this._auth = _auth;
553
+ this._template = _template;
554
+ this._viewContainerRef = _viewContainerRef;
555
+ }
556
+ ngOnInit() {
557
+ this._subscription = this._auth.user.pipe(map(user => !!user), distinctUntilChanged()).subscribe(isAuthenticated => {
558
+ if (!isAuthenticated) {
559
+ return this._viewContainerRef.clear();
560
+ }
561
+ this._viewContainerRef.createEmbeddedView(this._template);
562
+ });
563
+ }
564
+ ngOnDestroy() {
565
+ this._subscription?.unsubscribe();
566
+ }
567
+ }
568
+ BbAuthenticated.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: BbAuthenticated, deps: [{ token: Auth }, { token: i0.TemplateRef }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
569
+ BbAuthenticated.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.1.0", type: BbAuthenticated, selector: "[bbAuthenticated]", ngImport: i0 });
570
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: BbAuthenticated, decorators: [{
571
+ type: Directive,
572
+ args: [{
573
+ selector: '[bbAuthenticated]'
574
+ }]
575
+ }], ctorParameters: function () { return [{ type: Auth }, { type: i0.TemplateRef }, { type: i0.ViewContainerRef }]; } });
576
+
577
+ class BbRole {
578
+ constructor(_auth, _template, _viewContainerRef) {
579
+ this._auth = _auth;
580
+ this._template = _template;
581
+ this._viewContainerRef = _viewContainerRef;
582
+ this.getAllowedRoles = (value) => {
583
+ return Array.isArray(value) ? value : [value];
584
+ };
585
+ }
586
+ ngOnInit() {
587
+ this._subscription = this._auth.user.pipe(map(user => user?.role ?? null), distinctUntilChanged()).subscribe(role => {
588
+ const allowedRoles = this.getAllowedRoles(this.bbRole);
589
+ if (!allowedRoles.includes(role)) {
590
+ return this._viewContainerRef.clear();
591
+ }
592
+ this._viewContainerRef.createEmbeddedView(this._template);
593
+ });
594
+ }
595
+ ngOnDestroy() {
596
+ this._subscription?.unsubscribe();
597
+ }
598
+ }
599
+ BbRole.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: BbRole, deps: [{ token: Auth }, { token: i0.TemplateRef }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
600
+ BbRole.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.1.0", type: BbRole, selector: "[bbRole]", inputs: { bbRole: "bbRole" }, ngImport: i0 });
601
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: BbRole, decorators: [{
602
+ type: Directive,
603
+ args: [{
604
+ selector: '[bbRole]'
605
+ }]
606
+ }], ctorParameters: function () { return [{ type: Auth }, { type: i0.TemplateRef }, { type: i0.ViewContainerRef }]; }, propDecorators: { bbRole: [{
607
+ type: Input
608
+ }] } });
609
+
610
+ class Permissions {
611
+ constructor(_auth, _config) {
612
+ this._auth = _auth;
613
+ this._config = _config;
614
+ // Data.
615
+ this._permissions = this._config?.permissions ?? {};
616
+ this._role$ = this._auth.user.pipe(map(user => user?.role ?? null), distinctUntilChanged());
617
+ }
618
+ has(value) {
619
+ const requiredPermissions = Array.isArray(value)
620
+ ? value
621
+ : [value];
622
+ return this._role$.pipe(map(role => {
623
+ if (role === null || role === undefined) {
624
+ return false;
625
+ }
626
+ for (const requiredPermission of requiredPermissions) {
627
+ const result = this.validatePermission(requiredPermission, role);
628
+ if (!result) {
629
+ return false;
630
+ }
631
+ }
632
+ return true;
633
+ }));
634
+ }
635
+ validatePermission(type, role) {
636
+ const permission = this._permissions?.[type] ?? null;
637
+ if (!permission) {
638
+ console?.warn?.(`Permissions: Invalid permission requested "${type}".`);
639
+ return false;
640
+ }
641
+ if (permission?.length <= 0) {
642
+ console?.warn?.(`Permissions: No roles were set, please add some roles to this permission.`);
643
+ return false;
644
+ }
645
+ // If the permission includes a "*" we allow everyone.
646
+ if (permission.includes('*')) {
647
+ return true;
648
+ }
649
+ // Validate the role against the permissions.
650
+ return permission?.includes(role) ?? false;
651
+ }
652
+ }
653
+ Permissions.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: Permissions, deps: [{ token: Auth }, { token: AuthConfig, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
654
+ Permissions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: Permissions });
655
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: Permissions, decorators: [{
656
+ type: Injectable
657
+ }], ctorParameters: function () { return [{ type: Auth }, { type: AuthConfig, decorators: [{
658
+ type: Optional
659
+ }] }]; } });
660
+
661
+ class BbPermission {
662
+ constructor(_permissions, _templateRef, _viewContainerRef) {
663
+ this._permissions = _permissions;
664
+ this._templateRef = _templateRef;
665
+ this._viewContainerRef = _viewContainerRef;
666
+ // Data.
667
+ this._permission$ = new BehaviorSubject([]);
668
+ this._valid = false;
669
+ this._elseTemplateRef = null;
670
+ this._thenViewRef = null;
671
+ this._elseViewRef = null;
672
+ this.getAllowedPermissions = (value) => {
673
+ return Array.isArray(value) ? value : [value];
674
+ };
675
+ this.assertTemplate = (property, templateRef) => {
676
+ const isTemplateRefOrNull = !!(!templateRef || templateRef.createEmbeddedView);
677
+ if (!isTemplateRefOrNull) {
678
+ throw new Error(`${property} must be a TemplateRef.`);
679
+ }
680
+ };
681
+ }
682
+ set bbPermission(value) {
683
+ const permissions = this.getAllowedPermissions(value);
684
+ this._permission$.next(permissions);
685
+ this.updateView();
686
+ }
687
+ set bbPermissionElse(templateRef) {
688
+ this.assertTemplate('bbPermissionElse', templateRef);
689
+ this._elseTemplateRef = templateRef;
690
+ this.updateView();
691
+ }
692
+ ngOnInit() {
693
+ const check$ = this._permission$.pipe(switchMap(permissions => this._permissions.has(permissions)));
694
+ this._subscription = check$.subscribe(valid => {
695
+ this._valid = valid;
696
+ this.updateView();
697
+ });
698
+ }
699
+ ngOnDestroy() {
700
+ this._subscription?.unsubscribe();
701
+ }
702
+ updateView() {
703
+ if (this._valid) {
704
+ if (!this._thenViewRef) {
705
+ this._viewContainerRef.clear();
706
+ this._elseViewRef = null;
707
+ if (this._templateRef) {
708
+ this._thenViewRef = this._viewContainerRef.createEmbeddedView(this._templateRef);
709
+ }
710
+ }
711
+ }
712
+ else {
713
+ if (!this._elseViewRef) {
714
+ this._viewContainerRef.clear();
715
+ this._thenViewRef = null;
716
+ if (this._elseTemplateRef) {
717
+ this._elseViewRef = this._viewContainerRef.createEmbeddedView(this._elseTemplateRef);
718
+ }
719
+ }
720
+ }
721
+ }
722
+ }
723
+ BbPermission.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: BbPermission, deps: [{ token: Permissions }, { token: i0.TemplateRef }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
724
+ BbPermission.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.1.0", type: BbPermission, selector: "[bbPermission]", inputs: { bbPermission: "bbPermission", bbPermissionElse: "bbPermissionElse" }, ngImport: i0 });
725
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: BbPermission, decorators: [{
726
+ type: Directive,
727
+ args: [{
728
+ selector: '[bbPermission]'
729
+ }]
730
+ }], ctorParameters: function () { return [{ type: Permissions }, { type: i0.TemplateRef }, { type: i0.ViewContainerRef }]; }, propDecorators: { bbPermission: [{
731
+ type: Input
732
+ }], bbPermissionElse: [{
733
+ type: Input
734
+ }] } });
735
+
736
+ class BbAnonymousGuard {
737
+ constructor(_auth) {
738
+ this._auth = _auth;
739
+ }
740
+ async canActivate(_, state) {
741
+ // Check if the user is authenticated.
742
+ const isAuthenticated$ = await this._auth.user.pipe(map(user => !!user));
743
+ // If the user is not authenticated it can
744
+ // access the anonymous page.
745
+ const isAuthenticated = await firstValueFrom(isAuthenticated$, { defaultValue: null });
746
+ if (!isAuthenticated) {
747
+ return true;
748
+ }
749
+ // Return the user back to the authenticated page.
750
+ return this._auth.guard('authenticated', state.url);
751
+ }
752
+ canActivateChild(childRoute, state) {
753
+ return this.canActivate(childRoute, state);
754
+ }
755
+ }
756
+ BbAnonymousGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: BbAnonymousGuard, deps: [{ token: Auth }], target: i0.ɵɵFactoryTarget.Injectable });
757
+ BbAnonymousGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: BbAnonymousGuard, providedIn: 'root' });
758
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: BbAnonymousGuard, decorators: [{
759
+ type: Injectable,
760
+ args: [{
761
+ providedIn: 'root'
762
+ }]
763
+ }], ctorParameters: function () { return [{ type: Auth }]; } });
764
+
765
+ class BbAuthenticatedGuard {
766
+ constructor(_auth) {
767
+ this._auth = _auth;
768
+ }
769
+ async canActivate(_, state) {
770
+ // Check if the user is authenticated.
771
+ const isAuthenticated$ = await this._auth.user.pipe(map(user => !!user));
772
+ // If the user is authenticated it can
773
+ // access the authenticated page.
774
+ const isAuthenticated = await firstValueFrom(isAuthenticated$, { defaultValue: null });
775
+ if (isAuthenticated) {
776
+ return true;
777
+ }
778
+ // The user is not authorized to see that
779
+ // page so un-authorize him.
780
+ return this._auth.guard('unauthenticated', state.url);
781
+ }
782
+ canActivateChild(childRoute, state) {
783
+ return this.canActivate(childRoute, state);
784
+ }
785
+ }
786
+ BbAuthenticatedGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: BbAuthenticatedGuard, deps: [{ token: Auth }], target: i0.ɵɵFactoryTarget.Injectable });
787
+ BbAuthenticatedGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: BbAuthenticatedGuard, providedIn: 'root' });
788
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: BbAuthenticatedGuard, decorators: [{
789
+ type: Injectable,
790
+ args: [{
791
+ providedIn: 'root'
792
+ }]
793
+ }], ctorParameters: function () { return [{ type: Auth }]; } });
794
+
795
+ class AuthInterceptor {
796
+ constructor(_auth, _config) {
797
+ this._auth = _auth;
798
+ this._config = _config;
799
+ // Readonly data.
800
+ this._authHeaderString = 'Authorization';
801
+ // Data.
802
+ this.isRefreshing = false;
803
+ this.refreshingAccessToken$ = new BehaviorSubject(null);
804
+ this.getAccessToken = (request) => {
805
+ // Get the token based on header.
806
+ if (request.headers.has('Authorization')) {
807
+ return request.headers.get('Authorization');
808
+ }
809
+ // Return the default access token.
810
+ return this._auth.session.accessToken;
811
+ };
812
+ this.addAuthorizationHeader = (request, accessToken = null) => {
813
+ // Remove auth header when we do not have
814
+ // an access token.
815
+ if (!accessToken) {
816
+ return request.clone({
817
+ headers: request.headers.delete(this._authHeaderString)
818
+ });
819
+ }
820
+ // Add the auth header to the request.
821
+ return request.clone({
822
+ setHeaders: { [this._authHeaderString]: this.getFullAuthorizationHeader(accessToken) }
823
+ });
824
+ };
825
+ this.getFullAuthorizationHeader = (token) => {
826
+ const authScheme = this._config?.scheme ?? 'Bearer';
827
+ return [authScheme, token].join(' ');
828
+ };
829
+ }
830
+ intercept(request, next) {
831
+ // 1. Check if the user wants to use the authorization for this request.
832
+ if (!request.context.get(USE_AUTHORIZATION)) {
833
+ return next.handle(request);
834
+ }
835
+ // 2. Compose the new request.
836
+ const accessToken = this.getAccessToken(request);
837
+ const newRequest = this.addAuthorizationHeader(request, accessToken);
838
+ // 3. Handle all errors.
839
+ return next.handle(newRequest).pipe(catchError(error => {
840
+ // Handle the HTTP401 error.
841
+ if ((error instanceof HttpErrorResponse || error instanceof HttpError) && error?.status === 401) {
842
+ return this.handle401Error(request, next);
843
+ }
844
+ // Just re-throw the parsed error.
845
+ return throwError(error);
846
+ }));
847
+ }
848
+ handle401Error(request, next) {
849
+ // If already refreshing wait for the refresh token to complete.
850
+ if (this.isRefreshing) {
851
+ return this.refreshingAccessToken$.pipe(filter(accessToken => accessToken !== null), take(1), switchMap(accessToken => next.handle(this.addAuthorizationHeader(request, accessToken))));
852
+ }
853
+ // Set the refreshing to true.
854
+ this.isRefreshing = true;
855
+ this.refreshingAccessToken$.next(null);
856
+ return this._auth.refresh().pipe(switchMap(newAccessToken => {
857
+ if (!newAccessToken) {
858
+ const error = new Error('No refresh token was available.');
859
+ return throwError(error);
860
+ }
861
+ this.refreshingAccessToken$.next(newAccessToken);
862
+ return next.handle(this.addAuthorizationHeader(request, newAccessToken));
863
+ }), catchError(() => this.logoutUser()), finalize(() => this.isRefreshing = false));
864
+ }
865
+ logoutUser() {
866
+ // Handle the refresh error.
867
+ this._auth.clearAndRedirect();
868
+ // Return null as data.
869
+ return of(null);
870
+ }
871
+ }
872
+ AuthInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: AuthInterceptor, deps: [{ token: Auth }, { token: AuthConfig, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
873
+ AuthInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: AuthInterceptor });
874
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: AuthInterceptor, decorators: [{
875
+ type: Injectable
876
+ }], ctorParameters: function () { return [{ type: Auth }, { type: AuthConfig, decorators: [{
877
+ type: Optional
878
+ }] }]; } });
879
+
880
+ const DECLARATIONS_EXPORTS = [
881
+ BbAuthenticated,
882
+ BbRole,
883
+ BbPermission
884
+ ];
885
+ class AuthModule {
886
+ static forRoot(config) {
887
+ return {
888
+ ngModule: AuthModule,
889
+ providers: [
890
+ Auth,
891
+ Permissions,
892
+ { provide: AuthConfig, useValue: config },
893
+ { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true },
894
+ { useFactory: initializeAuth, provide: APP_INITIALIZER, deps: [Auth], multi: true }
895
+ ]
896
+ };
897
+ }
898
+ }
899
+ AuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: AuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
900
+ AuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: AuthModule, declarations: [BbAuthenticated,
901
+ BbRole,
902
+ BbPermission], imports: [HttpClientModule], exports: [BbAuthenticated,
903
+ BbRole,
904
+ BbPermission] });
905
+ AuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: AuthModule, providers: [
906
+ { provide: AuthMapper, useClass: AuthMapper }
907
+ ], imports: [[HttpClientModule]] });
908
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: AuthModule, decorators: [{
909
+ type: NgModule,
910
+ args: [{
911
+ imports: [HttpClientModule],
912
+ declarations: [...DECLARATIONS_EXPORTS],
913
+ exports: [...DECLARATIONS_EXPORTS],
914
+ providers: [
915
+ { provide: AuthMapper, useClass: AuthMapper }
916
+ ]
917
+ }]
918
+ }] });
919
+ function initializeAuth(auth) {
920
+ return auth.initialize();
921
+ }
922
+
923
+ /**
924
+ * Generated bundle index. Do not edit.
925
+ */
926
+
927
+ export { Auth, AuthConfig, AuthEmailProvider, AuthMapper, AuthModule, AuthSession, AuthVerifyProvider, BbAnonymousGuard, BbAuthenticated, BbAuthenticatedGuard, BbPermission, BbRole, JwtHelper, Permissions, USE_AUTHORIZATION, initializeAuth };
928
+ //# sourceMappingURL=bravobit-bb-foundation-auth.mjs.map