@bravobit/bb-foundation 0.21.1 → 0.21.4

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