@bravobit/bb-foundation 0.16.5 → 0.20.0

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