@bravobit/bb-foundation 0.14.3 → 0.15.2

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