@frontegg/redux-store 5.61.0 → 6.0.1-alpha.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 (389) hide show
  1. package/audits/AuditLogsState/index.d.ts +47 -47
  2. package/audits/AuditLogsState/index.js +28 -0
  3. package/audits/AuditLogsState/interfaces.d.ts +19 -19
  4. package/audits/AuditLogsState/interfaces.js +1 -0
  5. package/audits/AuditLogsState/saga.d.ts +2 -2
  6. package/audits/AuditLogsState/saga.js +166 -0
  7. package/audits/AuditsMetadataState/index.d.ts +35 -35
  8. package/audits/AuditsMetadataState/index.js +18 -0
  9. package/audits/AuditsMetadataState/interfaces.d.ts +17 -17
  10. package/audits/AuditsMetadataState/interfaces.js +1 -0
  11. package/audits/AuditsMetadataState/saga.d.ts +2 -2
  12. package/audits/AuditsMetadataState/saga.js +56 -0
  13. package/audits/backward-compatibility/index.d.ts +4 -4
  14. package/audits/backward-compatibility/index.js +4 -4
  15. package/audits/backward-compatibility/initialState.d.ts +2 -2
  16. package/audits/backward-compatibility/initialState.js +20 -0
  17. package/audits/backward-compatibility/interfaces.d.ts +55 -55
  18. package/audits/backward-compatibility/interfaces.js +1 -0
  19. package/audits/backward-compatibility/reducer.d.ts +35 -35
  20. package/audits/backward-compatibility/reducer.js +129 -0
  21. package/audits/backward-compatibility/saga.d.ts +1 -1
  22. package/audits/backward-compatibility/saga.js +187 -0
  23. package/audits/dummy.d.ts +10 -10
  24. package/audits/dummy.js +191 -0
  25. package/audits/index.d.ts +40 -40
  26. package/audits/index.js +18 -362
  27. package/audits/initialState.d.ts +2 -2
  28. package/audits/initialState.js +6 -0
  29. package/audits/interfaces.d.ts +6 -6
  30. package/audits/interfaces.js +1 -0
  31. package/audits/reducer.d.ts +31 -31
  32. package/audits/reducer.js +23 -0
  33. package/audits/saga.d.ts +2 -2
  34. package/audits/saga.js +9 -0
  35. package/audits/utils.d.ts +14 -14
  36. package/audits/utils.js +13 -0
  37. package/auth/AcceptInvitationState/index.d.ts +85 -85
  38. package/auth/AcceptInvitationState/index.js +20 -0
  39. package/auth/AcceptInvitationState/interfaces.d.ts +11 -11
  40. package/auth/AcceptInvitationState/interfaces.js +9 -0
  41. package/auth/AcceptInvitationState/saga.d.ts +1 -1
  42. package/auth/AcceptInvitationState/saga.js +41 -0
  43. package/auth/AccountSettingsState/index.d.ts +92 -92
  44. package/auth/AccountSettingsState/index.js +22 -0
  45. package/auth/AccountSettingsState/interfaces.d.ts +10 -10
  46. package/auth/AccountSettingsState/interfaces.js +1 -0
  47. package/auth/AccountSettingsState/saga.d.ts +2 -2
  48. package/auth/AccountSettingsState/saga.js +133 -0
  49. package/auth/ActivateState/index.d.ts +130 -130
  50. package/auth/ActivateState/index.js +35 -0
  51. package/auth/ActivateState/interfaces.d.ts +26 -26
  52. package/auth/ActivateState/interfaces.js +8 -0
  53. package/auth/ActivateState/saga.d.ts +1 -1
  54. package/auth/ActivateState/saga.js +187 -0
  55. package/auth/ApiTokensState/index.d.ts +119 -119
  56. package/auth/ApiTokensState/index.js +54 -0
  57. package/auth/ApiTokensState/interfaces.d.ts +49 -49
  58. package/auth/ApiTokensState/interfaces.js +7 -0
  59. package/auth/ApiTokensState/saga.d.ts +2 -2
  60. package/auth/ApiTokensState/saga.js +410 -0
  61. package/auth/ForgotPasswordState/index.d.ts +90 -90
  62. package/auth/ForgotPasswordState/index.js +29 -0
  63. package/auth/ForgotPasswordState/interfaces.d.ts +18 -18
  64. package/auth/ForgotPasswordState/interfaces.js +6 -0
  65. package/auth/ForgotPasswordState/saga.d.ts +8 -8
  66. package/auth/ForgotPasswordState/saga.js +83 -0
  67. package/auth/LoginState/index.d.ts +132 -144
  68. package/auth/LoginState/index.js +64 -0
  69. package/auth/LoginState/interfaces.d.ts +41 -60
  70. package/auth/LoginState/interfaces.js +17 -0
  71. package/auth/LoginState/saga.d.ts +80 -84
  72. package/auth/LoginState/saga.js +860 -0
  73. package/auth/MfaState/index.d.ts +92 -92
  74. package/auth/MfaState/index.js +28 -0
  75. package/auth/MfaState/interfaces.d.ts +12 -12
  76. package/auth/MfaState/interfaces.js +6 -0
  77. package/auth/MfaState/saga.d.ts +2 -2
  78. package/auth/MfaState/saga.js +252 -0
  79. package/auth/ProfileState/index.d.ts +90 -90
  80. package/auth/ProfileState/index.js +24 -0
  81. package/auth/ProfileState/interfaces.d.ts +9 -9
  82. package/auth/ProfileState/interfaces.js +1 -0
  83. package/auth/ProfileState/saga.d.ts +2 -2
  84. package/auth/ProfileState/saga.js +230 -0
  85. package/auth/ResetPhoneNumberState/index.d.ts +96 -96
  86. package/auth/ResetPhoneNumberState/index.js +27 -0
  87. package/auth/ResetPhoneNumberState/interfaces.d.ts +18 -18
  88. package/auth/ResetPhoneNumberState/interfaces.js +7 -0
  89. package/auth/ResetPhoneNumberState/saga.d.ts +17 -17
  90. package/auth/ResetPhoneNumberState/saga.js +127 -0
  91. package/auth/RolesState/index.d.ts +100 -100
  92. package/auth/RolesState/index.js +37 -0
  93. package/auth/RolesState/interfaces.d.ts +7 -7
  94. package/auth/RolesState/interfaces.js +1 -0
  95. package/auth/RolesState/saga.d.ts +1 -1
  96. package/auth/RolesState/saga.js +197 -0
  97. package/auth/SSOState/index.d.ts +224 -224
  98. package/auth/SSOState/index.js +83 -0
  99. package/auth/SSOState/interfaces.d.ts +92 -92
  100. package/auth/SSOState/interfaces.js +28 -0
  101. package/auth/SSOState/saga.d.ts +2 -2
  102. package/auth/SSOState/saga.js +523 -0
  103. package/auth/SSOState/saga.v2.d.ts +1 -1
  104. package/auth/SSOState/saga.v2.js +501 -0
  105. package/auth/SecurityPolicyState/index.d.ts +456 -502
  106. package/auth/SecurityPolicyState/index.js +64 -0
  107. package/auth/SecurityPolicyState/interfaces.d.ts +26 -28
  108. package/auth/SecurityPolicyState/interfaces.js +1 -0
  109. package/auth/SecurityPolicyState/saga.d.ts +18 -24
  110. package/auth/SecurityPolicyState/saga.js +464 -0
  111. package/auth/SignUp/index.d.ts +86 -86
  112. package/auth/SignUp/index.js +25 -0
  113. package/auth/SignUp/interfaces.d.ts +19 -19
  114. package/auth/SignUp/interfaces.js +6 -0
  115. package/auth/SignUp/saga.d.ts +49 -49
  116. package/auth/SignUp/saga.js +147 -0
  117. package/auth/SocialLogins/index.d.ts +91 -91
  118. package/auth/SocialLogins/index.js +26 -0
  119. package/auth/SocialLogins/interfaces.d.ts +13 -13
  120. package/auth/SocialLogins/interfaces.js +1 -0
  121. package/auth/SocialLogins/saga.d.ts +10 -10
  122. package/auth/SocialLogins/saga.js +140 -0
  123. package/auth/TeamState/index.d.ts +168 -168
  124. package/auth/TeamState/index.js +111 -0
  125. package/auth/TeamState/interfaces.d.ts +78 -78
  126. package/auth/TeamState/interfaces.js +16 -0
  127. package/auth/TeamState/saga.d.ts +2 -2
  128. package/auth/TeamState/saga.js +1123 -0
  129. package/auth/TenantsState/index.d.ts +104 -104
  130. package/auth/TenantsState/index.js +31 -0
  131. package/auth/TenantsState/interfaces.d.ts +9 -9
  132. package/auth/TenantsState/interfaces.js +1 -0
  133. package/auth/TenantsState/saga.d.ts +2 -2
  134. package/auth/TenantsState/saga.js +136 -0
  135. package/auth/dummy.d.ts +28 -28
  136. package/auth/dummy.js +250 -0
  137. package/auth/index.d.ts +378 -392
  138. package/auth/index.js +46 -4078
  139. package/auth/initialState.d.ts +3 -3
  140. package/auth/initialState.js +58 -0
  141. package/auth/interfaces.d.ts +161 -161
  142. package/auth/interfaces.js +14 -0
  143. package/auth/reducer.d.ts +356 -370
  144. package/auth/reducer.js +39 -0
  145. package/auth/saga.d.ts +2 -2
  146. package/auth/saga.js +24 -0
  147. package/auth/utils.d.ts +162 -165
  148. package/auth/utils.js +74 -0
  149. package/connectivity/ConnectivityState/index.d.ts +292 -292
  150. package/connectivity/ConnectivityState/index.js +94 -0
  151. package/connectivity/consts.d.ts +12 -12
  152. package/connectivity/consts.js +71 -0
  153. package/connectivity/index.d.ts +40 -40
  154. package/connectivity/index.js +12 -454
  155. package/connectivity/interfaces.d.ts +112 -112
  156. package/connectivity/interfaces.js +1 -0
  157. package/connectivity/reducer.d.ts +31 -31
  158. package/connectivity/reducer.js +25 -0
  159. package/connectivity/saga.d.ts +1 -1
  160. package/connectivity/saga.js +546 -0
  161. package/constants.d.ts +7 -7
  162. package/constants.js +7 -0
  163. package/helpers.d.ts +5 -5
  164. package/helpers.js +37 -0
  165. package/index.d.ts +28 -28
  166. package/index.js +17 -15
  167. package/interfaces.d.ts +15 -15
  168. package/interfaces.js +1 -0
  169. package/node/audits/AuditLogsState/index.js +43 -0
  170. package/node/audits/AuditLogsState/interfaces.js +5 -0
  171. package/node/audits/AuditLogsState/saga.js +181 -0
  172. package/node/audits/AuditsMetadataState/index.js +33 -0
  173. package/node/audits/AuditsMetadataState/interfaces.js +5 -0
  174. package/node/audits/AuditsMetadataState/saga.js +67 -0
  175. package/node/audits/backward-compatibility/index.js +52 -12
  176. package/node/audits/backward-compatibility/initialState.js +27 -0
  177. package/node/audits/backward-compatibility/interfaces.js +5 -0
  178. package/node/audits/backward-compatibility/reducer.js +144 -0
  179. package/node/audits/backward-compatibility/saga.js +199 -0
  180. package/node/audits/dummy.js +204 -0
  181. package/node/audits/index.js +124 -364
  182. package/node/audits/initialState.js +16 -0
  183. package/node/audits/interfaces.js +5 -0
  184. package/node/audits/reducer.js +37 -0
  185. package/node/audits/saga.js +21 -0
  186. package/node/audits/utils.js +25 -0
  187. package/node/auth/AcceptInvitationState/index.js +33 -0
  188. package/node/auth/AcceptInvitationState/interfaces.js +16 -0
  189. package/node/auth/AcceptInvitationState/saga.js +51 -0
  190. package/node/auth/AccountSettingsState/index.js +34 -0
  191. package/node/auth/AccountSettingsState/interfaces.js +5 -0
  192. package/node/auth/AccountSettingsState/saga.js +145 -0
  193. package/node/auth/ActivateState/index.js +48 -0
  194. package/node/auth/ActivateState/interfaces.js +15 -0
  195. package/node/auth/ActivateState/saga.js +201 -0
  196. package/node/auth/ApiTokensState/index.js +66 -0
  197. package/node/auth/ApiTokensState/interfaces.js +14 -0
  198. package/node/auth/ApiTokensState/saga.js +424 -0
  199. package/node/auth/ForgotPasswordState/index.js +42 -0
  200. package/node/auth/ForgotPasswordState/interfaces.js +13 -0
  201. package/node/auth/ForgotPasswordState/saga.js +98 -0
  202. package/node/auth/LoginState/index.js +77 -0
  203. package/node/auth/LoginState/interfaces.js +31 -0
  204. package/node/auth/LoginState/saga.js +918 -0
  205. package/node/auth/MfaState/index.js +41 -0
  206. package/node/auth/MfaState/interfaces.js +13 -0
  207. package/node/auth/MfaState/saga.js +265 -0
  208. package/node/auth/ProfileState/index.js +36 -0
  209. package/node/auth/ProfileState/interfaces.js +5 -0
  210. package/node/auth/ProfileState/saga.js +245 -0
  211. package/node/auth/ResetPhoneNumberState/index.js +40 -0
  212. package/node/auth/ResetPhoneNumberState/interfaces.js +14 -0
  213. package/node/auth/ResetPhoneNumberState/saga.js +141 -0
  214. package/node/auth/RolesState/index.js +49 -0
  215. package/node/auth/RolesState/interfaces.js +5 -0
  216. package/node/auth/RolesState/saga.js +205 -0
  217. package/node/auth/SSOState/index.js +95 -0
  218. package/node/auth/SSOState/interfaces.js +36 -0
  219. package/node/auth/SSOState/saga.js +535 -0
  220. package/node/auth/SSOState/saga.v2.js +512 -0
  221. package/node/auth/SecurityPolicyState/index.js +76 -0
  222. package/node/auth/SecurityPolicyState/interfaces.js +5 -0
  223. package/node/auth/SecurityPolicyState/saga.js +472 -0
  224. package/node/auth/SignUp/index.js +38 -0
  225. package/node/auth/SignUp/interfaces.js +13 -0
  226. package/node/auth/SignUp/saga.js +173 -0
  227. package/node/auth/SocialLogins/index.js +38 -0
  228. package/node/auth/SocialLogins/interfaces.js +5 -0
  229. package/node/auth/SocialLogins/saga.js +162 -0
  230. package/node/auth/TeamState/index.js +123 -0
  231. package/node/auth/TeamState/interfaces.js +23 -0
  232. package/node/auth/TeamState/saga.js +1118 -0
  233. package/node/auth/TenantsState/index.js +43 -0
  234. package/node/auth/TenantsState/interfaces.js +5 -0
  235. package/node/auth/TenantsState/saga.js +149 -0
  236. package/node/auth/dummy.js +284 -0
  237. package/node/auth/index.js +528 -170
  238. package/node/auth/initialState.js +86 -0
  239. package/node/auth/interfaces.js +22 -0
  240. package/node/auth/reducer.js +68 -0
  241. package/node/auth/saga.js +51 -0
  242. package/node/auth/utils.js +104 -0
  243. package/node/connectivity/ConnectivityState/index.js +107 -0
  244. package/node/connectivity/consts.js +84 -0
  245. package/node/connectivity/index.js +64 -455
  246. package/node/connectivity/interfaces.js +5 -0
  247. package/node/connectivity/reducer.js +38 -0
  248. package/node/connectivity/saga.js +560 -0
  249. package/node/{constants-52e37c08.js → constants.js} +14 -11
  250. package/node/helpers.js +57 -0
  251. package/node/index.js +120 -293
  252. package/node/interfaces.js +5 -0
  253. package/node/subscriptions/Billing/Information/index.js +42 -0
  254. package/node/subscriptions/Billing/Information/interfaces.js +5 -0
  255. package/node/subscriptions/Billing/Information/saga.js +141 -0
  256. package/node/subscriptions/Billing/Invoices/index.js +55 -0
  257. package/node/subscriptions/Billing/Invoices/interfaces.js +5 -0
  258. package/node/subscriptions/Billing/Invoices/saga.js +92 -0
  259. package/node/subscriptions/Billing/PaymentMethod/index.js +51 -0
  260. package/node/subscriptions/Billing/PaymentMethod/interfaces.js +13 -0
  261. package/node/subscriptions/Billing/PaymentMethod/saga.js +98 -0
  262. package/node/subscriptions/Billing/Subscription/index.js +53 -0
  263. package/node/subscriptions/Billing/Subscription/interfaces.js +5 -0
  264. package/node/subscriptions/Billing/Subscription/saga.js +131 -0
  265. package/node/subscriptions/Billing/index.js +38 -0
  266. package/node/subscriptions/Billing/interfaces.js +57 -0
  267. package/node/subscriptions/Billing/saga.js +25 -0
  268. package/node/subscriptions/Checkout/index.js +47 -0
  269. package/node/subscriptions/Checkout/interfaces.js +5 -0
  270. package/node/subscriptions/Checkout/saga.js +129 -0
  271. package/node/subscriptions/Config/index.js +39 -0
  272. package/node/subscriptions/Config/interfaces.js +5 -0
  273. package/node/subscriptions/Config/saga.js +71 -0
  274. package/node/subscriptions/Plans/index.js +38 -0
  275. package/node/subscriptions/Plans/interfaces.js +5 -0
  276. package/node/subscriptions/Plans/saga.js +73 -0
  277. package/node/subscriptions/Stripe/index.js +39 -0
  278. package/node/subscriptions/Stripe/interfaces.js +5 -0
  279. package/node/subscriptions/Stripe/saga.js +44 -0
  280. package/node/subscriptions/dummy.js +84 -0
  281. package/node/subscriptions/general.interfaces.js +30 -0
  282. package/node/subscriptions/index.js +70 -906
  283. package/node/subscriptions/interfaces.js +83 -0
  284. package/node/subscriptions/mapper.js +51 -0
  285. package/node/subscriptions/reducer.js +52 -0
  286. package/node/subscriptions/saga.js +27 -0
  287. package/node/subscriptions/utils.js +68 -0
  288. package/node/toolkit/index.js +163 -99
  289. package/node/toolkit/redux-saga.js +59 -0
  290. package/node/toolkit/redux.js +43 -0
  291. package/node/vendor/VendorState/index.js +26 -0
  292. package/node/vendor/index.js +66 -13
  293. package/node/vendor/interfaces.js +5 -0
  294. package/node/vendor/reducer.js +32 -0
  295. package/node/vendor/saga.js +48 -0
  296. package/package.json +12 -11
  297. package/subscriptions/Billing/Information/index.d.ts +12 -12
  298. package/subscriptions/Billing/Information/index.js +30 -0
  299. package/subscriptions/Billing/Information/interfaces.d.ts +14 -14
  300. package/subscriptions/Billing/Information/interfaces.js +1 -0
  301. package/subscriptions/Billing/Information/saga.d.ts +52 -52
  302. package/subscriptions/Billing/Information/saga.js +118 -0
  303. package/subscriptions/Billing/Invoices/index.d.ts +18 -18
  304. package/subscriptions/Billing/Invoices/index.js +44 -0
  305. package/subscriptions/Billing/Invoices/interfaces.d.ts +19 -19
  306. package/subscriptions/Billing/Invoices/interfaces.js +1 -0
  307. package/subscriptions/Billing/Invoices/saga.d.ts +13 -13
  308. package/subscriptions/Billing/Invoices/saga.js +75 -0
  309. package/subscriptions/Billing/PaymentMethod/index.d.ts +20 -20
  310. package/subscriptions/Billing/PaymentMethod/index.js +40 -0
  311. package/subscriptions/Billing/PaymentMethod/interfaces.d.ts +46 -46
  312. package/subscriptions/Billing/PaymentMethod/interfaces.js +6 -0
  313. package/subscriptions/Billing/PaymentMethod/saga.d.ts +13 -13
  314. package/subscriptions/Billing/PaymentMethod/saga.js +81 -0
  315. package/subscriptions/Billing/Subscription/index.d.ts +16 -16
  316. package/subscriptions/Billing/Subscription/index.js +42 -0
  317. package/subscriptions/Billing/Subscription/interfaces.d.ts +18 -18
  318. package/subscriptions/Billing/Subscription/interfaces.js +1 -0
  319. package/subscriptions/Billing/Subscription/saga.d.ts +13 -13
  320. package/subscriptions/Billing/Subscription/saga.js +117 -0
  321. package/subscriptions/Billing/index.d.ts +54 -54
  322. package/subscriptions/Billing/index.js +23 -0
  323. package/subscriptions/Billing/interfaces.d.ts +20 -20
  324. package/subscriptions/Billing/interfaces.js +5 -0
  325. package/subscriptions/Billing/saga.d.ts +2 -2
  326. package/subscriptions/Billing/saga.js +11 -0
  327. package/subscriptions/Checkout/index.d.ts +14 -14
  328. package/subscriptions/Checkout/index.js +36 -0
  329. package/subscriptions/Checkout/interfaces.d.ts +17 -17
  330. package/subscriptions/Checkout/interfaces.js +1 -0
  331. package/subscriptions/Checkout/saga.d.ts +5 -5
  332. package/subscriptions/Checkout/saga.js +110 -0
  333. package/subscriptions/Config/index.d.ts +10 -10
  334. package/subscriptions/Config/index.js +28 -0
  335. package/subscriptions/Config/interfaces.d.ts +16 -16
  336. package/subscriptions/Config/interfaces.js +1 -0
  337. package/subscriptions/Config/saga.d.ts +2 -2
  338. package/subscriptions/Config/saga.js +59 -0
  339. package/subscriptions/Plans/index.d.ts +10 -10
  340. package/subscriptions/Plans/index.js +25 -0
  341. package/subscriptions/Plans/interfaces.d.ts +10 -10
  342. package/subscriptions/Plans/interfaces.js +1 -0
  343. package/subscriptions/Plans/saga.d.ts +2 -2
  344. package/subscriptions/Plans/saga.js +58 -0
  345. package/subscriptions/Stripe/index.d.ts +11 -11
  346. package/subscriptions/Stripe/index.js +28 -0
  347. package/subscriptions/Stripe/interfaces.d.ts +10 -10
  348. package/subscriptions/Stripe/interfaces.js +1 -0
  349. package/subscriptions/Stripe/saga.d.ts +1 -1
  350. package/subscriptions/Stripe/saga.js +34 -0
  351. package/subscriptions/dummy.d.ts +5 -5
  352. package/subscriptions/dummy.js +72 -0
  353. package/subscriptions/general.interfaces.d.ts +49 -49
  354. package/subscriptions/general.interfaces.js +21 -0
  355. package/subscriptions/index.d.ts +100 -100
  356. package/subscriptions/index.js +13 -906
  357. package/subscriptions/interfaces.d.ts +25 -25
  358. package/subscriptions/interfaces.js +7 -0
  359. package/subscriptions/mapper.d.ts +6 -6
  360. package/subscriptions/mapper.js +36 -0
  361. package/subscriptions/reducer.d.ts +92 -92
  362. package/subscriptions/reducer.js +29 -0
  363. package/subscriptions/saga.d.ts +2 -2
  364. package/subscriptions/saga.js +12 -0
  365. package/subscriptions/utils.d.ts +68 -68
  366. package/subscriptions/utils.js +52 -0
  367. package/toolkit/index.d.ts +24 -23
  368. package/toolkit/index.js +106 -94
  369. package/toolkit/redux-saga.d.ts +4 -4
  370. package/toolkit/redux-saga.js +3 -0
  371. package/toolkit/redux.d.ts +3 -2
  372. package/toolkit/redux.js +1 -0
  373. package/vendor/VendorState/index.d.ts +20 -20
  374. package/vendor/VendorState/index.js +13 -0
  375. package/vendor/index.d.ts +17 -17
  376. package/vendor/index.js +12 -18
  377. package/vendor/interfaces.d.ts +3 -3
  378. package/vendor/interfaces.js +1 -0
  379. package/vendor/reducer.d.ts +8 -8
  380. package/vendor/reducer.js +19 -0
  381. package/vendor/saga.d.ts +8 -8
  382. package/vendor/saga.js +34 -0
  383. package/audits/backward-compatibility/package.json +0 -6
  384. package/constants-4d9682b2.js +0 -9
  385. package/node/index-5642a636.js +0 -4131
  386. package/node/index-6906e508.js +0 -151
  387. package/node/saga-b0d1a607.js +0 -230
  388. package/saga-7a267fe0.js +0 -223
  389. package/saga-b6529ffb.js +0 -36
@@ -1,4131 +0,0 @@
1
- 'use strict';
2
-
3
- var toolkit = require('@reduxjs/toolkit');
4
- var vendor_index = require('./index-6906e508.js');
5
- var restApi = require('@frontegg/rest-api');
6
- var constants = require('./constants-52e37c08.js');
7
- var tslib = require('tslib');
8
- var effects = require('redux-saga/effects');
9
- var uuid = require('uuid');
10
- var audits_index = require('./audits/index.js');
11
- var connectivity_index = require('./connectivity/index.js');
12
- var subscriptions_index = require('./subscriptions/index.js');
13
- var saga = require('./saga-b0d1a607.js');
14
- var createSagaMiddleware = require('redux-saga');
15
-
16
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
-
18
- var createSagaMiddleware__default = /*#__PURE__*/_interopDefaultLegacy(createSagaMiddleware);
19
-
20
- exports.LoginStep = void 0;
21
- (function (LoginStep) {
22
- LoginStep["preLogin"] = "preLogin";
23
- LoginStep["magicLinkPreLoginSuccess"] = "magicLinkPreLoginSuccess";
24
- LoginStep["loginWithSmsOtc"] = "loginWithSmsOtc";
25
- LoginStep["loginWithOtc"] = "loginWithOtc";
26
- LoginStep["loginWithPassword"] = "loginWithPassword";
27
- LoginStep["loginWithTwoFactor"] = "loginWithTwoFactor";
28
- LoginStep["redirectToSSO"] = "redirectToSSO";
29
- LoginStep["loginWithSSOFailed"] = "loginWithSSOFailed";
30
- LoginStep["success"] = "success";
31
- LoginStep["forceTwoFactor"] = "forceTwoFactor";
32
- LoginStep["recoverTwoFactor"] = "recoverTwoFactor";
33
- })(exports.LoginStep || (exports.LoginStep = {}));
34
- exports.LoginFlow = void 0;
35
- (function (LoginFlow) {
36
- LoginFlow["Login"] = "login";
37
- LoginFlow["RegisterQuickLogin"] = "registerQuickLogin";
38
- })(exports.LoginFlow || (exports.LoginFlow = {}));
39
- exports.QuickLoginStrategy = void 0;
40
- (function (QuickLoginStrategy) {
41
- QuickLoginStrategy["Internal"] = "internal";
42
- QuickLoginStrategy["UsbKey"] = "usb-key";
43
- QuickLoginStrategy["Android"] = "android";
44
- QuickLoginStrategy["Sms"] = "sms";
45
- })(exports.QuickLoginStrategy || (exports.QuickLoginStrategy = {}));
46
-
47
- const loginState = {
48
- flow: exports.LoginFlow.Login,
49
- step: exports.LoginStep.preLogin,
50
- loading: false,
51
- email: '',
52
- tenants: [],
53
- };
54
- const reducers$f = {
55
- setLoginState: vendor_index.typeReducerForKey('loginState'),
56
- resetLoginState: vendor_index.resetStateByKey('loginState', { loginState }),
57
- };
58
- const actions$g = {
59
- requestAuthorize: toolkit.createAction(`${constants.authStoreName}/requestAuthorize`, (payload = false) => ({ payload })),
60
- requestAuthorizeSSR: toolkit.createAction(`${constants.authStoreName}/requestAuthorizeSSR`, (payload) => ({ payload })),
61
- requestHostedLoginAuthorize: toolkit.createAction(`${constants.authStoreName}/requestHostedLoginAuthorize`),
62
- handleHostedLoginCallback: toolkit.createAction(`${constants.authStoreName}/handleHostedLoginCallback`, (payload) => ({ payload })),
63
- afterAuthNavigation: toolkit.createAction(`${constants.authStoreName}/afterAuthNavigation`),
64
- preLogin: toolkit.createAction(`${constants.authStoreName}/preLogin`, (payload) => ({ payload })),
65
- postLogin: toolkit.createAction(`${constants.authStoreName}/postLogin`, (payload) => ({ payload })),
66
- login: toolkit.createAction(`${constants.authStoreName}/login`, (payload) => ({ payload })),
67
- loginWithMfa: toolkit.createAction(`${constants.authStoreName}/loginWithMfa`, (payload) => ({ payload })),
68
- recoverMfa: toolkit.createAction(`${constants.authStoreName}/recoverMfa`, (payload) => ({ payload })),
69
- logout: toolkit.createAction(`${constants.authStoreName}/logout`, (payload) => ({ payload })),
70
- silentLogout: toolkit.createAction(`${constants.authStoreName}/silentLogout`, (payload) => ({ payload })),
71
- checkIfAllowToRememberMfaDevice: toolkit.createAction(`${constants.authStoreName}/checkIfAllowToRememberMfaDevice`, (payload) => ({ payload })),
72
- passwordlessPreLogin: toolkit.createAction(`${constants.authStoreName}/passwordlessPreLogin`, (payload) => ({ payload })),
73
- passwordlessPostLogin: toolkit.createAction(`${constants.authStoreName}/passwordlessPostLogin`, (payload) => ({ payload })),
74
- verifyInviteToken: toolkit.createAction(`${constants.authStoreName}/verifyInviteToken`, (payload) => ({ payload })),
75
- webAuthnPrelogin: toolkit.createAction(`${constants.authStoreName}/webAuthnPrelogin`, (payload) => ({ payload })),
76
- webAuthnPostLogin: toolkit.createAction(`${constants.authStoreName}/webAuthnPostLogin`, (payload) => ({ payload })),
77
- webAuthnCreateNewDeviceSession: toolkit.createAction(`${constants.authStoreName}/webAuthnCreateNewDeviceSession`, (payload) => ({ payload })),
78
- webAuthnVerifyNewDeviceSession: toolkit.createAction(`${constants.authStoreName}/webAuthnVerifyNewDeviceSession`, (payload) => ({ payload })),
79
- };
80
-
81
- exports.ActivateAccountStep = void 0;
82
- (function (ActivateAccountStep) {
83
- ActivateAccountStep["activating"] = "activating";
84
- ActivateAccountStep["success"] = "success";
85
- ActivateAccountStep["resend"] = "resend";
86
- ActivateAccountStep["activatingForm"] = "activatingForm";
87
- })(exports.ActivateAccountStep || (exports.ActivateAccountStep = {}));
88
-
89
- const activateState = {
90
- step: exports.ActivateAccountStep.activating,
91
- loading: false,
92
- resentEmail: false,
93
- activationStrategy: {
94
- loading: false,
95
- },
96
- };
97
- const reducers$e = {
98
- setActivateState: vendor_index.typeReducerForKey('activateState'),
99
- resetActivateState: vendor_index.resetStateByKey('activateState', { activateState }),
100
- setActivateStrategyState: vendor_index.typeReducerNestedKey('activateState', 'activationStrategy'),
101
- };
102
- const actions$f = {
103
- activateAccount: toolkit.createAction(`${constants.authStoreName}/activateAccount`, (payload) => ({ payload })),
104
- preActivateAccount: toolkit.createAction(`${constants.authStoreName}/preActivateAccount`, (payload) => ({ payload })),
105
- getActivateAccountStrategy: toolkit.createAction(`${constants.authStoreName}/getActivateAccountStrategy`, (payload) => ({ payload })),
106
- resendActivationEmail: toolkit.createAction(`${constants.authStoreName}/resendActivationEmail`, (payload) => ({
107
- payload,
108
- })),
109
- };
110
-
111
- exports.AcceptInvitationStep = void 0;
112
- (function (AcceptInvitationStep) {
113
- AcceptInvitationStep["validate"] = "validate";
114
- AcceptInvitationStep["invalid"] = "invalid";
115
- AcceptInvitationStep["pending"] = "pending";
116
- AcceptInvitationStep["success"] = "success";
117
- AcceptInvitationStep["failed"] = "failed";
118
- })(exports.AcceptInvitationStep || (exports.AcceptInvitationStep = {}));
119
-
120
- const acceptInvitationState = {
121
- step: exports.AcceptInvitationStep.validate,
122
- };
123
- const reducers$d = {
124
- setAcceptInvitationState: vendor_index.typeReducerForKey('acceptInvitationState'),
125
- resetAcceptInvitationState: vendor_index.resetStateByKey('acceptInvitationState', {
126
- acceptInvitationState,
127
- }),
128
- };
129
- const actions$e = {
130
- acceptInvitation: toolkit.createAction(`${constants.authStoreName}/acceptInvitation`, (payload) => ({ payload })),
131
- };
132
-
133
- exports.ForgotPasswordStep = void 0;
134
- (function (ForgotPasswordStep) {
135
- ForgotPasswordStep["forgotPassword"] = "forgotPassword";
136
- ForgotPasswordStep["success"] = "success";
137
- })(exports.ForgotPasswordStep || (exports.ForgotPasswordStep = {}));
138
-
139
- const forgotPasswordState = {
140
- step: exports.ForgotPasswordStep.forgotPassword,
141
- loading: false,
142
- email: '',
143
- passwordConfig: null,
144
- };
145
- const reducers$c = {
146
- setForgotPasswordState: vendor_index.typeReducerForKey('forgotPasswordState'),
147
- resetForgotPasswordState: vendor_index.resetStateByKey('forgotPasswordState', { forgotPasswordState }),
148
- };
149
- const actions$d = {
150
- forgotPassword: toolkit.createAction(`${constants.authStoreName}/forgotPassword`, (payload) => ({ payload })),
151
- resetPassword: toolkit.createAction(`${constants.authStoreName}/resetPassword`, (payload) => ({ payload })),
152
- loadPasswordConfig: toolkit.createAction(`${constants.authStoreName}/loadPasswordConfig`, (payload) => ({
153
- payload,
154
- })),
155
- };
156
-
157
- exports.ResetPhoneNumberStep = void 0;
158
- (function (ResetPhoneNumberStep) {
159
- ResetPhoneNumberStep["ResetPhoneNumber"] = "ResetPhoneNumber";
160
- ResetPhoneNumberStep["VerifyResetPhoneNumber"] = "VerifyResetPhoneNumber";
161
- ResetPhoneNumberStep["ChangePhoneNumber"] = "ChangePhoneNumber";
162
- })(exports.ResetPhoneNumberStep || (exports.ResetPhoneNumberStep = {}));
163
-
164
- const resetPhoneNumberState = {
165
- step: exports.ResetPhoneNumberStep.ResetPhoneNumber,
166
- loading: false,
167
- };
168
- const reducers$b = {
169
- setResetPhoneNumberState: vendor_index.typeReducerForKey('resetPhoneNumberState'),
170
- resetResetPhoneNumberState: vendor_index.resetStateByKey('resetPhoneNumberState', { resetPhoneNumberState }),
171
- };
172
- const actions$c = {
173
- resetPhoneNumber: toolkit.createAction(`${constants.authStoreName}/resetPhoneNumber`, (payload) => ({ payload })),
174
- verifyResetPhoneNumber: toolkit.createAction(`${constants.authStoreName}/verifyResetPhoneNumber`, (payload) => ({ payload })),
175
- changePhoneNumber: toolkit.createAction(`${constants.authStoreName}/changePhoneNumber`, (payload) => ({ payload })),
176
- };
177
-
178
- const ssoState = {
179
- firstLoad: true,
180
- loading: true,
181
- saving: false,
182
- errors: {},
183
- loaders: {},
184
- ssoConfigurations: []
185
- };
186
- const reducers$a = {
187
- setSSOLoader: vendor_index.loadersReducerForKey('ssoState'),
188
- setSSOError: vendor_index.errorsReducerForKey('ssoState'),
189
- setSSOState: vendor_index.typeReducerForKey('ssoState'),
190
- resetSSOState: vendor_index.resetStateByKey('ssoState', { ssoState }),
191
- };
192
- const actions$b = {
193
- loadSSOConfigurationsV2: toolkit.createAction(`${constants.authStoreName}/loadSSOConfigurationsV2`),
194
- saveSSOConfigurationV2: toolkit.createAction(`${constants.authStoreName}/saveSSOConfigurationV2`, (payload) => ({ payload })),
195
- updateSSOConfiguration: toolkit.createAction(`${constants.authStoreName}/updateSSOConfiguration`, (payload) => ({ payload })),
196
- deleteSSOConfiguration: toolkit.createAction(`${constants.authStoreName}/deleteSSOConfiguration`, (payload) => ({ payload })),
197
- saveSSODomain: toolkit.createAction(`${constants.authStoreName}/saveSSODomain`, (payload) => ({ payload })),
198
- deleteSSODomain: toolkit.createAction(`${constants.authStoreName}/deleteSSODomain`, (payload) => ({ payload })),
199
- validateSSODomainV2: toolkit.createAction(`${constants.authStoreName}/validateSSODomainV2`, (payload) => ({ payload })),
200
- setSSODefaultRoles: toolkit.createAction(`${constants.authStoreName}/setSSODefaultRoles`, (payload) => ({ payload })),
201
- setSSOGroups: toolkit.createAction(`${constants.authStoreName}/setSSOGroups`, (payload) => ({ payload })),
202
- updateSSOGroups: toolkit.createAction(`${constants.authStoreName}/updateSSOGroups`, (payload) => ({ payload })),
203
- saveSSOConfigurationByMetadata: toolkit.createAction(`${constants.authStoreName}/saveSSOConfigurationByMetadata`, (payload) => ({ payload })),
204
- updateSSOConfigurationByMetadata: toolkit.createAction(`${constants.authStoreName}/updateSSOConfigurationByMetadata`, (payload) => ({ payload })),
205
- loadSSOConfigurations: toolkit.createAction(`${constants.authStoreName}/loadSSOConfigurations`),
206
- loadSSOAuthorizationRoles: toolkit.createAction(`${constants.authStoreName}/loadSSOAuthorizationRoles`),
207
- saveSSOConfigurations: toolkit.createAction(`${constants.authStoreName}/saveSSOConfigurations`, (payload) => ({ payload })),
208
- // NOTE: use withCallback in case of promise response
209
- saveSSOConfigurationsFile: toolkit.createAction(`${constants.authStoreName}/saveSSOConfigurationsFile`, (payload) => ({
210
- payload,
211
- })),
212
- saveSSOConfigurationsFileWithCallback: toolkit.createAction(`${constants.authStoreName}/saveSSOConfigurationsFileWithCallback`, (payload) => ({ payload })),
213
- validateSSODomain: toolkit.createAction(`${constants.authStoreName}/validateSSODomain`, (payload) => ({ payload })),
214
- updateSSOAuthorizationRoles: toolkit.createAction(`${constants.authStoreName}/updateSSOAuthorizationRoles`, (payload) => ({ payload })),
215
- deleteSamlGroup: toolkit.createAction(`${constants.authStoreName}/deleteSamlGroup`, (payload) => ({ payload })),
216
- createSamlGroup: toolkit.createAction(`${constants.authStoreName}/createSamlGroup`, (payload) => ({ payload })),
217
- oidcPostlogin: toolkit.createAction(`${constants.authStoreName}/oidcPostlogin`, (payload) => ({
218
- payload,
219
- })),
220
- };
221
-
222
- const profileState = {
223
- loading: false,
224
- error: null,
225
- };
226
- const reducers$9 = {
227
- setProfileState: vendor_index.typeReducerForKey('profileState'),
228
- resetProfileState: vendor_index.resetStateByKey('profileState', { profileState }),
229
- };
230
- const actions$a = {
231
- loadProfile: toolkit.createAction(`${constants.authStoreName}/loadProfile`),
232
- saveProfile: toolkit.createAction(`${constants.authStoreName}/saveProfile`, (payload) => ({ payload })),
233
- changePassword: toolkit.createAction(`${constants.authStoreName}/changePassword`, (payload) => ({
234
- payload,
235
- })),
236
- };
237
-
238
- exports.MFAStep = void 0;
239
- (function (MFAStep) {
240
- MFAStep["verify"] = "verify";
241
- MFAStep["recoveryCode"] = "recoveryCode";
242
- })(exports.MFAStep || (exports.MFAStep = {}));
243
-
244
- const mfaState = {
245
- step: exports.MFAStep.verify,
246
- loading: false,
247
- };
248
- const reducers$8 = {
249
- setMfaState: vendor_index.typeReducerForKey('mfaState'),
250
- resetMfaState: vendor_index.resetStateByKey('mfaState', { mfaState }),
251
- };
252
- const actions$9 = {
253
- enrollMfa: toolkit.createAction(`${constants.authStoreName}/enrollMfa`),
254
- verifyMfa: toolkit.createAction(`${constants.authStoreName}/verifyMfa`, (payload) => ({
255
- payload,
256
- })),
257
- verifyMfaAfterForce: toolkit.createAction(`${constants.authStoreName}/verifyMfaAfterForce`, (payload) => ({
258
- payload,
259
- })),
260
- disableMfa: toolkit.createAction(`${constants.authStoreName}/disableMfa`, (payload) => ({ payload })),
261
- };
262
-
263
- const teamState = {
264
- loaders: {},
265
- pageOffset: 0,
266
- pageSize: 20,
267
- errors: {},
268
- users: [],
269
- allUsers: [],
270
- roles: [],
271
- permissions: [],
272
- totalPages: 0,
273
- filter: [],
274
- sort: [],
275
- allUsersQueryParams: {
276
- _filter: null,
277
- _offset: 0,
278
- _limit: 20,
279
- _order: 'DESC',
280
- _sortBy: 'name',
281
- },
282
- addUserDialogState: {
283
- loading: false,
284
- open: false,
285
- },
286
- deleteUserDialogState: {
287
- loading: false,
288
- open: false,
289
- },
290
- lockUserDialogState: {
291
- loading: false,
292
- open: false,
293
- },
294
- };
295
- const reducers$7 = {
296
- setTeamLoader: vendor_index.loadersReducerForKey('teamState'),
297
- setTeamError: vendor_index.errorsReducerForKey('teamState'),
298
- setTeamState: vendor_index.typeReducerForKey('teamState'),
299
- resetTeamState: vendor_index.resetStateByKey('teamState', { teamState }),
300
- };
301
- const actions$8 = {
302
- loadUsers: toolkit.createAction(`${constants.authStoreName}/loadUsers`, (payload) => ({ payload })),
303
- loadAllSubTenantsUsers: toolkit.createAction(`${constants.authStoreName}/loadAllSubTenantsUsers`, (payload) => ({ payload })),
304
- loadRoles: toolkit.createAction(`${constants.authStoreName}/loadRoles`, (payload) => ({ payload })),
305
- addUser: toolkit.createAction(`${constants.authStoreName}/addUser`, (payload) => ({ payload })),
306
- addUserToSubTenants: toolkit.createAction(`${constants.authStoreName}/addUserToSubTenants`, (payload) => ({ payload })),
307
- updateUser: toolkit.createAction(`${constants.authStoreName}/updateUser`, (payload) => ({
308
- payload,
309
- })),
310
- deleteUser: toolkit.createAction(`${constants.authStoreName}/deleteUser`, (payload) => ({ payload })),
311
- setUserRolesForSubTenants: toolkit.createAction(`${constants.authStoreName}/setUserRolesForSubTenants`, (payload) => ({ payload })),
312
- deleteUserFromSubTenants: toolkit.createAction(`${constants.authStoreName}/deleteUserFromSubTenants`, (payload) => ({ payload })),
313
- lockUser: toolkit.createAction(`${constants.authStoreName}/lockUser`, (payload) => ({ payload })),
314
- resendActivationLink: toolkit.createAction(`${constants.authStoreName}/resendActivationLink`, (payload) => ({ payload })),
315
- resendInvitationLink: toolkit.createAction(`${constants.authStoreName}/resendInvitationLink`, (payload) => ({ payload })),
316
- getInvitationLink: toolkit.createAction(`${constants.authStoreName}/getInvitationLink`),
317
- createInvitationLink: toolkit.createAction(`${constants.authStoreName}/createInvitationLink`, (payload) => ({ payload })),
318
- updateInvitationLink: toolkit.createAction(`${constants.authStoreName}/updateInvitationLink`, (payload) => ({ payload })),
319
- deleteInvitationLink: toolkit.createAction(`${constants.authStoreName}/deleteInvitationLink`, (payload) => ({ payload })),
320
- openAddUserDialog: toolkit.createAction(`${constants.authStoreName}/openAddUserDialog`, (payload) => ({ payload })),
321
- closeAddUserDialog: toolkit.createAction(`${constants.authStoreName}/closeAddUserDialog`, (payload) => ({ payload })),
322
- openDeleteUserDialog: toolkit.createAction(`${constants.authStoreName}/openDeleteUserDialog`, (payload) => ({
323
- payload,
324
- })),
325
- closeDeleteUserDialog: toolkit.createAction(`${constants.authStoreName}/closeDeleteUserDialog`, (payload) => ({ payload })),
326
- openLockUserDialog: toolkit.createAction(`${constants.authStoreName}/openLockUserDialog`, (payload) => ({
327
- payload,
328
- })),
329
- closeLockUserDialog: toolkit.createAction(`${constants.authStoreName}/closeLockUserDialog`, (payload) => ({ payload })),
330
- };
331
-
332
- const socialLoginState = {
333
- firstLoad: true,
334
- loading: false,
335
- error: '',
336
- };
337
- const reducers$6 = {
338
- setSocialLoginsState: vendor_index.typeReducerForKey('socialLoginState'),
339
- resetSocialLoginsState: vendor_index.resetStateByKey('socialLoginState', { socialLoginState }),
340
- };
341
- const actions$7 = {
342
- loadSocialLoginsConfiguration: toolkit.createAction(`${constants.authStoreName}/loadSocialLoginsConfiguration`),
343
- loadSocialLoginsConfigurationV2: toolkit.createAction(`${constants.authStoreName}/loadSocialLoginsConfigurationV2`),
344
- loginViaSocialLogin: toolkit.createAction(`${constants.authStoreName}/loginViaSocialLogin`, (payload) => ({
345
- payload,
346
- })),
347
- setSocialLoginError: toolkit.createAction(`${constants.authStoreName}/setSocialLoginError`, (payload) => ({
348
- payload,
349
- })),
350
- };
351
-
352
- exports.SignUpStage = void 0;
353
- (function (SignUpStage) {
354
- SignUpStage["SignUp"] = "SignUp";
355
- SignUpStage["SignUpSuccess"] = "SignUpSuccess";
356
- })(exports.SignUpStage || (exports.SignUpStage = {}));
357
-
358
- const signUpState = {
359
- loading: false,
360
- allowSignUps: false,
361
- allowNotVerifiedUsersLogin: false,
362
- firstLoad: true,
363
- stage: exports.SignUpStage.SignUp,
364
- };
365
- const reducers$5 = {
366
- setSignUpState: vendor_index.typeReducerForKey('signUpState'),
367
- resetSignUpState: vendor_index.resetStateByKey('signUpState', { signUpState }),
368
- };
369
- const actions$6 = {
370
- signUpUser: toolkit.createAction(`${constants.authStoreName}/signUpUser`, (payload) => ({ payload })),
371
- resetSignUpStateSoft: toolkit.createAction(`${constants.authStoreName}/resetSignUpStateSoft`),
372
- };
373
-
374
- const apiTokensState = {
375
- apiTokenType: null,
376
- searchValue: '',
377
- showAddTokenDialog: false,
378
- createdByUserIdColumn: 'show',
379
- deleteTokenDialog: {
380
- open: false,
381
- clientId: '',
382
- },
383
- successDialog: {
384
- open: false,
385
- secret: '',
386
- clientId: '',
387
- },
388
- loaders: {},
389
- apiTokensDataTenant: [],
390
- apiTokensDataUser: [],
391
- roles: [],
392
- permissions: [],
393
- errors: {},
394
- };
395
- const reducers$4 = {
396
- setApiTokensLoader: vendor_index.loadersReducerForKey('apiTokensState'),
397
- setApiTokensError: vendor_index.errorsReducerForKey('apiTokensState'),
398
- setApiTokensState: vendor_index.typeReducerForKey('apiTokensState'),
399
- resetApiTokensState: vendor_index.resetStateByKey('apiTokensState', { apiTokensState }),
400
- };
401
- const actions$5 = {
402
- loadApiTokens: toolkit.createAction(`${constants.authStoreName}/loadApiTokens`, (payload) => ({
403
- payload,
404
- })),
405
- initApiTokensData: toolkit.createAction(`${constants.authStoreName}/initApiTokensData`, (payload) => ({ payload })),
406
- addTenantApiToken: toolkit.createAction(`${constants.authStoreName}/addTenantApiToken`, (payload) => ({
407
- payload,
408
- })),
409
- addUserApiToken: toolkit.createAction(`${constants.authStoreName}/addUserApiToken`, (payload) => ({ payload })),
410
- deleteUserApiToken: toolkit.createAction(`${constants.authStoreName}/deleteUserApiToken`, (payload) => ({ payload })),
411
- deleteTenantApiToken: toolkit.createAction(`${constants.authStoreName}/deleteTenantApiToken`, (payload) => ({ payload })),
412
- };
413
-
414
- const securityPolicyState = {
415
- globalPolicy: {
416
- loading: true,
417
- },
418
- publicPolicy: {
419
- loading: false,
420
- },
421
- vendorMfaPolicy: {
422
- loading: true,
423
- },
424
- mfaPolicy: {
425
- loading: true,
426
- },
427
- lockoutPolicy: {
428
- loading: true,
429
- },
430
- captchaPolicy: {
431
- loading: true,
432
- },
433
- passwordHistoryPolicy: {
434
- loading: true,
435
- },
436
- passwordPolicy: {
437
- loading: true,
438
- },
439
- publicAuthStrategyPolicy: {
440
- loading: true,
441
- },
442
- };
443
- const reducers$3 = {
444
- setSecurityPolicyState: vendor_index.typeReducerForKey('securityPolicyState'),
445
- setSecurityPolicyGlobalState: vendor_index.typeReducerNestedKey('securityPolicyState', 'globalPolicy'),
446
- setSecurityPolicyPublicState: vendor_index.typeReducerNestedKey('securityPolicyState', 'publicPolicy'),
447
- setSecurityPolicyAuthStrategyPublicState: vendor_index.typeReducerNestedKey('securityPolicyState', 'publicAuthStrategyPolicy'),
448
- setSecurityPolicyMfaState: vendor_index.typeReducerNestedKey('securityPolicyState', 'mfaPolicy'),
449
- setSecurityPolicyVendorMfaState: vendor_index.typeReducerNestedKey('securityPolicyState', 'vendorMfaPolicy'),
450
- setSecurityPolicyLockoutState: vendor_index.typeReducerNestedKey('securityPolicyState', 'lockoutPolicy'),
451
- setSecurityPolicyCaptchaState: vendor_index.typeReducerNestedKey('securityPolicyState', 'captchaPolicy'),
452
- setSecurityPolicyPasswordHistoryState: vendor_index.typeReducerNestedKey('securityPolicyState', 'passwordHistoryPolicy'),
453
- setSecurityPolicyPasswordState: vendor_index.typeReducerNestedKey('securityPolicyState', 'passwordPolicy'),
454
- resetSecurityPolicyState: vendor_index.resetStateByKey('securityPolicyState', { securityPolicyState }),
455
- };
456
- const actions$4 = {
457
- loadSecurityPolicy: toolkit.createAction(`${constants.authStoreName}/loadSecurityPolicy`),
458
- loadPublicSecurityPolicy: toolkit.createAction(`${constants.authStoreName}/loadPublicSecurityPolicy`),
459
- loadSecurityPolicyMfa: toolkit.createAction(`${constants.authStoreName}/loadSecurityPolicyMfa`),
460
- loadSecurityPolicyVendorMfa: toolkit.createAction(`${constants.authStoreName}/loadSecurityPolicyVendorMfa`),
461
- saveSecurityPolicyMfa: toolkit.createAction(`${constants.authStoreName}/saveSecurityPolicyMfa`, (payload) => ({ payload })),
462
- loadSecurityPolicyLockout: toolkit.createAction(`${constants.authStoreName}/loadSecurityPolicyLockout`),
463
- saveSecurityPolicyLockout: toolkit.createAction(`${constants.authStoreName}/saveSecurityPolicyLockout`, (payload) => ({ payload })),
464
- loadSecurityPolicyCaptcha: toolkit.createAction(`${constants.authStoreName}/loadSecurityPolicyCaptcha`),
465
- loadSecurityPolicyPasswordHistory: toolkit.createAction(`${constants.authStoreName}/loadSecurityPolicyPasswordHistory`),
466
- saveSecurityPolicyPasswordHistory: toolkit.createAction(`${constants.authStoreName}/saveSecurityPolicyPasswordHistory`, (payload) => ({ payload })),
467
- loadVendorPasswordConfig: toolkit.createAction(`${constants.authStoreName}/loadVendorPasswordConfig`),
468
- loadPublicAuthStrategiesPolicy: toolkit.createAction(`${constants.authStoreName}/loadPublicAuthStrategiesPolicy`),
469
- };
470
-
471
- const accountSettingsState = {
472
- loading: false,
473
- };
474
- const reducers$2 = {
475
- setAccountSettingsState: vendor_index.typeReducerForKey('accountSettingsState'),
476
- resetAccountSettingsState: vendor_index.resetStateByKey('accountSettingsState', { accountSettingsState }),
477
- };
478
- const actions$3 = {
479
- loadAccountSettings: toolkit.createAction(`${constants.authStoreName}/loadAccountSettings`, (payload) => ({ payload })),
480
- saveAccountSettings: toolkit.createAction(`${constants.authStoreName}/saveAccountSettings`, (payload) => ({ payload })),
481
- };
482
-
483
- const tenantsState = {
484
- tenants: [],
485
- subTenants: [],
486
- loading: true,
487
- tenantTree: null,
488
- };
489
- const reducers$1 = {
490
- setTenantsState: vendor_index.typeReducerForKey('tenantsState'),
491
- resetTenantsState: vendor_index.resetStateByKey('tenantsState', { tenantsState }),
492
- };
493
- const actions$2 = {
494
- switchTenant: toolkit.createAction(`${constants.authStoreName}/switchTenant`, (payload) => ({ payload })),
495
- loadTenants: toolkit.createAction(`${constants.authStoreName}/loadTenants`, (payload) => ({
496
- payload,
497
- })),
498
- loadSubTenants: toolkit.createAction(`${constants.authStoreName}/loadSubTenants`, (payload) => ({
499
- payload,
500
- })),
501
- loadSubTenantsTree: toolkit.createAction(`${constants.authStoreName}/loadSubTenantsTree`, (payload) => ({
502
- payload,
503
- })),
504
- };
505
-
506
- const rolesState = {
507
- loading: false,
508
- roles: [],
509
- permissions: [],
510
- permissionCategories: [],
511
- };
512
- const reducers = {
513
- setRolesState: vendor_index.typeReducerForKey('rolesState'),
514
- resetRolesState: vendor_index.resetStateByKey('rolesState', { rolesState }),
515
- };
516
- const actions$1 = {
517
- loadRolesAndPermissions: toolkit.createAction(`${constants.authStoreName}/loadRoles`, (payload) => ({ payload })),
518
- addRole: toolkit.createAction(`${constants.authStoreName}/addRole`, (payload) => ({ payload })),
519
- updateRole: toolkit.createAction(`${constants.authStoreName}/updateRole`, (payload) => ({ payload })),
520
- deleteRole: toolkit.createAction(`${constants.authStoreName}/deleteRole`, (payload) => ({ payload })),
521
- attachPermissionsToRole: toolkit.createAction(`${constants.authStoreName}/attachPermissionsToRole`, (payload) => ({ payload })),
522
- attachPermissionToRoles: toolkit.createAction(`${constants.authStoreName}/attachPermissionToRoles`, (payload) => ({ payload })),
523
- };
524
-
525
- const reinitializeState = {
526
- isAuthenticated: false,
527
- isLoading: true,
528
- isSSOAuth: false,
529
- user: null,
530
- signUpState,
531
- loginState,
532
- activateState,
533
- acceptInvitationState,
534
- forgotPasswordState,
535
- ssoState,
536
- profileState,
537
- mfaState,
538
- teamState,
539
- socialLoginState,
540
- apiTokensState,
541
- securityPolicyState,
542
- accountSettingsState,
543
- tenantsState,
544
- rolesState,
545
- resetPhoneNumberState
546
- };
547
- const initialState$1 = Object.assign({ routes: {
548
- authenticatedUrl: '/',
549
- loginUrl: '/account/login',
550
- logoutUrl: '/account/logout',
551
- activateUrl: '/account/activate',
552
- acceptInvitationUrl: '/account/invitation/accept',
553
- forgetPasswordUrl: '/account/forget-password',
554
- resetPhoneNumberUrl: '/account/reset-phone-number',
555
- resetPasswordUrl: '/account/reset-password',
556
- socialLoginCallbackUrl: '/account/social/success',
557
- signUpUrl: '/account/sign-up',
558
- oidcRedirectUrl: '/account/oidc/callback',
559
- samlCallbackUrl: '/account/saml/callback',
560
- magicLinkCallbackUrl: '/account/login/magic-link',
561
- hostedLoginRedirectUrl: '/oauth/callback'
562
- }, onRedirectTo: () => { } }, reinitializeState);
563
-
564
- const { reducer, actions: sliceActions } = toolkit.createSlice({
565
- name: constants.authStoreName,
566
- initialState: initialState$1,
567
- reducers: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ resetState: (state) => (Object.assign(Object.assign({}, state), reinitializeState)), setState: (state, { payload }) => (Object.assign(Object.assign({}, state), payload)), setUser: vendor_index.typeReducer('user') }, reducers$f), reducers$6), reducers$e), reducers$d), reducers$c), reducers$b), reducers$5), reducers$9), reducers$a), reducers$8), reducers$7), reducers$4), reducers$3), reducers$2), reducers$1), reducers),
568
- });
569
- const actions = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, sliceActions), actions$g), actions$7), actions$f), actions$e), actions$d), actions$c), actions$6), actions$a), actions$b), actions$9), actions$8), actions$5), actions$4), actions$3), actions$2), actions$1);
570
-
571
- exports.SSOStateKeys = void 0;
572
- (function (SSOStateKeys) {
573
- SSOStateKeys["LOAD_SSO_CONFIGURATIONS"] = "LOAD_SSO_CONFIGURATIONS";
574
- SSOStateKeys["SAVE_SSO_CONFIGURATION"] = "SAVE_SSO_CONFIGURATION";
575
- SSOStateKeys["UPDATE_SSO_CONFIGURATION"] = "UPDATE_SSO_CONFIGURATION";
576
- SSOStateKeys["SAVE_SSO_CONFIGURATION_BY_METADATA"] = "SAVE_SSO_CONFIGURATION_BY_METADATA";
577
- SSOStateKeys["UPDATE_SSO_CONFIGURATION_BY_METADATA"] = "UPDATE_SSO_CONFIGURATION";
578
- SSOStateKeys["DELETE_SSO_CONFIGURATION"] = "DELETE_SSO_CONFIGURATION";
579
- SSOStateKeys["SAVE_SSO_DOMAIN"] = "SAVE_SSO_DOMAIN";
580
- SSOStateKeys["DELETE_SSO_DOMAIN"] = "DELETE_SSO_DOMAIN";
581
- SSOStateKeys["VALIDATE_SSO_DOMAIN"] = "VALIDATE_SSO_DOMAIN";
582
- SSOStateKeys["UPDATE_SSO_DEFAULT_ROLES"] = "UPDATE_SSO_DEFAULT_ROLES";
583
- SSOStateKeys["DELETE_SSO_GROUPS"] = "DELETE_SSO_GROUPS";
584
- SSOStateKeys["SAVE_SSO_GROUPS"] = "SAVE_SSO_GROUPS";
585
- SSOStateKeys["GET_SSO_AUTHORIZATION_ROLES"] = "GET_SSO_AUTHORIZATION_ROLES";
586
- })(exports.SSOStateKeys || (exports.SSOStateKeys = {}));
587
- exports.SamlVendors = void 0;
588
- (function (SamlVendors) {
589
- SamlVendors["Saml"] = "saml";
590
- SamlVendors["Okta"] = "okta";
591
- SamlVendors["Azure"] = "azure";
592
- SamlVendors["Google"] = "google";
593
- SamlVendors["Oidc"] = "oidc";
594
- })(exports.SamlVendors || (exports.SamlVendors = {}));
595
-
596
- function omitProps(props, keys) {
597
- const newProps = Object.assign({}, props);
598
- keys.forEach((key) => {
599
- delete newProps[key];
600
- });
601
- return newProps;
602
- }
603
- function generateCodeChallenge(codeVerifier) {
604
- return tslib.__awaiter(this, void 0, void 0, function* () {
605
- const digest = yield crypto.subtle.digest('SHA-256', new TextEncoder().encode(codeVerifier));
606
- // @ts-ignore
607
- return btoa(String.fromCharCode(...new Uint8Array(digest)))
608
- .replace(/=/g, '')
609
- .replace(/\+/g, '-')
610
- .replace(/\//g, '_');
611
- });
612
- }
613
- function createRandomString(length = 16) {
614
- let text = '';
615
- const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
616
- for (let i = 0; i < length; i++) {
617
- text += possible.charAt(Math.floor(Math.random() * possible.length));
618
- }
619
- return text;
620
- }
621
- const readFileAsText = (file) => new Promise((resolve, reject) => {
622
- const reader = new FileReader();
623
- reader.readAsText(file);
624
- reader.onload = () => resolve(reader.result);
625
- reader.onerror = reject;
626
- });
627
-
628
- const apiTokensDataDemo = {
629
- clientId: 'CLIENT_ID_16806d3d-8fc3-4450-be97-abdaf66b723e',
630
- secret: 'SECRET_16806d3d-8fc3-4450-be97-abdaf66b723e',
631
- createdAt: 'createdAt',
632
- description: 'Demo API Token (preview only)',
633
- };
634
- const apiTokensDataTenantDemo = Object.assign(Object.assign({}, apiTokensDataDemo), { roleIds: [], tenantId: 'my-tenant-id', createdByUserId: 'createdByUserId' });
635
- const roleDemo = [
636
- {
637
- id: 'roleId',
638
- key: 'admin',
639
- isDefault: false,
640
- name: 'Admin',
641
- description: null,
642
- permissions: ['adminPermissionId'],
643
- tenantId: 'tenantId',
644
- vendorId: 'vendorId',
645
- createdAt: new Date(),
646
- updatedAt: new Date(),
647
- },
648
- ];
649
- const rolePermissionDemo = [
650
- {
651
- id: 'adminPermissionId',
652
- key: 'fe.*',
653
- name: 'General Admin',
654
- description: undefined,
655
- categoryId: 'category',
656
- fePermission: true,
657
- createdAt: new Date(),
658
- updatedAt: new Date(),
659
- },
660
- ];
661
- const userProfileDemo = {
662
- id: 'testId',
663
- name: 'Demo User Name',
664
- email: 'demo-user@frontegg.com',
665
- mfaEnrolled: true,
666
- profileImage: undefined,
667
- profilePictureUrl: 'https://www.gravatar.com/avatar/42b2ad2bad6fc9b9db5086dfcf8072ac?d=https://ui-avatars.com/api/fe/128/random?t=1617261890875?t=1617261917434',
668
- roles: roleDemo,
669
- permissions: rolePermissionDemo,
670
- tenantId: 'my-tenant-id',
671
- tenantIds: ['my-tenant-id'],
672
- activatedForTenant: true,
673
- metadata: JSON.stringify({
674
- phoneNumber: '+972-54123456',
675
- jobTitle: 'Developer',
676
- address: {
677
- city: "Tel Aviv",
678
- country: "Israel"
679
- }
680
- }),
681
- roleIds: undefined,
682
- verified: undefined,
683
- };
684
- const userDemo = Object.assign(Object.assign({}, userProfileDemo), { accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1MTY5YmY0Zi02YmI5LTQ5NGMtOGNkZS05MDc4NDQ0NWY4MDciLCJuYW1lIjoiRHVtbXkgVXNlciIsImVtYWlsIjoiZHVtbXlAZnJvbnRlZ2cuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsIm1ldGFkYXRhIjp7fSwicm9sZXMiOlsiYWRtaW4iXSwicGVybWlzc2lvbnMiOlsiZmUuKiJdLCJ0ZW5hbnRJZCI6Im15LXRlbmFudC1pZCIsInRlbmFudElkcyI6WyJteS10ZW5hbnQtaWQiXSwicHJvZmlsZVBpY3R1cmVVcmwiOiJodHRwczovL3d3dy5ncmF2YXRhci5jb20vYXZhdGFyLzQyYjJhZDJiYWQ2ZmM5YjlkYjUwODZkZmNmODA3MmFjP2Q9aHR0cHM6Ly91aS1hdmF0YXJzLmNvbS9hcGkvZmUvMTI4L3JhbmRvbT90PTE2MTcyNjE4OTA4NzU_dD0xNjE3MjYxOTE3NDM0IiwidHlwZSI6InVzZXJUb2tlbiIsImlhdCI6MTYxNzkwNjMyNCwiZXhwIjoxNjE3OTkyNzI0LCJpc3MiOiJmcm9udGVnZyJ9.paaXLkpWEWbQmUtoK2P8IwXCxK4WJp7XhXonvzF8g1I', expiresIn: 86400, mfaRequired: false, refreshToken: 'refresh-token-dummy-de39dc9c-9d22-4852-b7f5-c3c0aa613b58', type: 'userToken', iat: 1617906324, exp: 1617992724, iss: 'frontegg', email_verified: true });
685
- const profileStateDemo = {
686
- loading: false,
687
- error: undefined,
688
- saving: true,
689
- profile: userProfileDemo,
690
- };
691
- const policyDemo = {
692
- id: 'id',
693
- enforceMFAType: 'DontForce',
694
- createdAt: new Date(),
695
- updatedAt: new Date(),
696
- allowOverrideEnforcePasswordHistory: true,
697
- allowOverridePasswordComplexity: false,
698
- allowOverridePasswordExpiration: false,
699
- allowSignups: true,
700
- apiTokensEnabled: true,
701
- cookieSameSite: 'cookieSameSite',
702
- defaultRefreshTokenExpiration: 0,
703
- defaultTokenExpiration: 1,
704
- publicKey: 'publicKey',
705
- };
706
- const publicSecurityPolicy = {
707
- allowSignups: true,
708
- allowNotVerifiedUsersLogin: false,
709
- apiTokensEnabled: true,
710
- forcePermissions: false,
711
- authStrategy: restApi.AuthStrategyEnum.EmailAndPassword,
712
- };
713
- const policyMfaDemo = {
714
- id: 'id',
715
- enforceMFAType: 'DontForce',
716
- createdAt: new Date(),
717
- updatedAt: new Date(),
718
- };
719
- const policyLockoutDemo = {
720
- id: 'id',
721
- enabled: true,
722
- maxAttempts: 1,
723
- createdAt: new Date(),
724
- updatedAt: new Date(),
725
- };
726
- const policyPasswordHistoryDemo = {
727
- id: 'id',
728
- enabled: true,
729
- historySize: 1,
730
- createdAt: new Date(),
731
- updatedAt: new Date(),
732
- };
733
- const samlConfigurationDemo = {
734
- enabled: true,
735
- domain: 'domain',
736
- validated: true,
737
- generatedVerification: 'generatedVerification',
738
- ssoEndpoint: 'ssoEndpoint',
739
- publicCertificate: 'publicCertificate',
740
- signRequest: true,
741
- createdAt: new Date(),
742
- updatedAt: new Date(),
743
- acsUrl: undefined,
744
- spEntityId: undefined,
745
- oidcClientId: undefined,
746
- oidcSecret: undefined,
747
- type: undefined,
748
- };
749
- const samlMetadataDemo = {
750
- id: 'id',
751
- createdAt: 'createdAt',
752
- updatedAt: 'updatedAt',
753
- properties: [],
754
- vendorId: 'vendorId',
755
- entityName: 'saml',
756
- isActive: true,
757
- configuration: {
758
- acsUrl: 'acsUrl',
759
- spEntityId: 'spEntityId',
760
- },
761
- };
762
- const rolesDemo = [
763
- {
764
- id: 'id',
765
- description: 'description',
766
- key: 'key',
767
- name: 'name',
768
- permissions: [],
769
- permissionLevel: 1,
770
- },
771
- ];
772
- const ssoStateDemo = {
773
- firstLoad: false,
774
- loading: false,
775
- error: undefined,
776
- saving: false,
777
- samlConfiguration: samlConfigurationDemo,
778
- roles: rolesDemo,
779
- authorizationRoles: [],
780
- errors: {},
781
- loaders: {},
782
- ssoConfigurations: [],
783
- };
784
- const permissionsDemo = [
785
- {
786
- description: 'string',
787
- fePermission: true,
788
- id: 'id',
789
- key: 'key',
790
- name: 'name',
791
- roleIds: [],
792
- createdAt: new Date(),
793
- updatedAt: new Date(),
794
- categoryId: 'categoryId',
795
- },
796
- ];
797
- const userTeamDemo2 = {
798
- id: 'id2',
799
- email: 'demo-user2@frontegg.com',
800
- name: 'Demo User Name2',
801
- phone: undefined,
802
- profileImage: undefined,
803
- profileImageUrl: undefined,
804
- tenantId: 'tenantId',
805
- vendorId: 'vendorId',
806
- roleIds: [],
807
- activatedForTenant: true,
808
- verified: false,
809
- createdAt: new Date().toISOString(),
810
- customData: undefined,
811
- lastLogin: undefined,
812
- mfaEnabled: undefined,
813
- roles: [],
814
- }; // TODO add verified to ITeamUser
815
- const userTeamDemo = {
816
- id: 'id',
817
- email: 'demo-user@frontegg.com',
818
- name: 'Demo User Name',
819
- phone: undefined,
820
- profileImage: undefined,
821
- profileImageUrl: undefined,
822
- tenantId: 'tenantId',
823
- vendorId: 'vendorId',
824
- roleIds: [],
825
- activatedForTenant: true,
826
- createdAt: new Date(2022, 4, 1).toISOString(),
827
- verified: true,
828
- customData: undefined,
829
- lastLogin: new Date(2022, 5, 25).toISOString(),
830
- mfaEnabled: undefined,
831
- roles: [],
832
- };
833
- const userSubTenantDemo = {
834
- metadata: '',
835
- mfaEnrolled: false,
836
- permissions: [],
837
- provider: '',
838
- sub: '',
839
- tenantIds: [],
840
- tenants: [],
841
- verified: false,
842
- id: 'id',
843
- email: 'email',
844
- name: 'name',
845
- tenantId: 'tenantId',
846
- activatedForTenant: true,
847
- createdAt: new Date(),
848
- lastLogin: new Date(),
849
- roles: [],
850
- };
851
- const usersDemo = [userTeamDemo, userTeamDemo2];
852
- const allUsersDemo = [userSubTenantDemo];
853
- const tenantsDemo = [
854
- {
855
- id: 'my-tenant-id',
856
- isReseller: false,
857
- name: 'Frontegg demo',
858
- deletedAt: null,
859
- metadata: undefined,
860
- tenantId: 'my-tenant-id',
861
- vendorId: 'vendorId',
862
- createdAt: new Date(),
863
- updatedAt: new Date(),
864
- address: undefined,
865
- timezone: undefined,
866
- dateFormat: undefined,
867
- timeFormat: undefined,
868
- currency: undefined,
869
- logo: undefined,
870
- },
871
- ];
872
-
873
- exports.UserVeirifedOriginTypes = void 0;
874
- (function (UserVeirifedOriginTypes) {
875
- UserVeirifedOriginTypes["SOCIAL_LOGIN"] = "SOCIAL_LOGIN";
876
- UserVeirifedOriginTypes["PASSWORDLESS"] = "PASSWORDLESS";
877
- UserVeirifedOriginTypes["ACTIVATION_LINK"] = "ACTIVATION_LINK";
878
- })(exports.UserVeirifedOriginTypes || (exports.UserVeirifedOriginTypes = {}));
879
- exports.AuthenticationTypes = void 0;
880
- (function (AuthenticationTypes) {
881
- AuthenticationTypes["SOCIAL_LOGIN"] = "SOCIAL_LOGIN";
882
- AuthenticationTypes["PASSWORD"] = "PASSWORD";
883
- })(exports.AuthenticationTypes || (exports.AuthenticationTypes = {}));
884
-
885
- function* loadAllowSignUps() {
886
- yield effects.put(actions.setSignUpState({ loading: true }));
887
- try {
888
- const policy = yield effects.call(restApi.api.auth.getVendorConfig);
889
- const { allowSignups: allowSignUps, allowNotVerifiedUsersLogin } = policy;
890
- yield effects.put(actions.setSignUpState({ loading: false, allowSignUps, allowNotVerifiedUsersLogin, firstLoad: false }));
891
- yield effects.put(actions.setSecurityPolicyPublicState({ policy, loading: false }));
892
- }
893
- catch (e) {
894
- yield effects.put(actions.setSignUpState({ loading: false, error: e.message, firstLoad: false }));
895
- }
896
- }
897
- function* signUpUser(_a) {
898
- var _b;
899
- var _c = _a.payload, { events, url } = _c, payload = tslib.__rest(_c, ["events", "url"]);
900
- yield effects.put(actions.setSignUpState({ loading: true }));
901
- try {
902
- const { routes, onRedirectTo } = yield effects.select((state) => state.auth);
903
- const { shouldActivate, user, tenantId, userId } = yield effects.call(restApi.api.auth.signUpUser, payload);
904
- if (!payload.invitationToken) {
905
- const { email, name, companyName } = payload;
906
- (_b = events === null || events === void 0 ? void 0 : events.signUpComplete) === null || _b === void 0 ? void 0 : _b.call(events, {
907
- email,
908
- name,
909
- companyName,
910
- url,
911
- authenticationType: exports.AuthenticationTypes.PASSWORD,
912
- id: userId,
913
- tenantId,
914
- createdAt: new Date(),
915
- });
916
- }
917
- restApi.ContextHolder.setAccessToken(user === null || user === void 0 ? void 0 : user.accessToken);
918
- restApi.ContextHolder.setUser(user);
919
- if (!shouldActivate && (user === null || user === void 0 ? void 0 : user.mfaRequired) && (user === null || user === void 0 ? void 0 : user.mfaToken)) {
920
- let step = exports.LoginStep.loginWithTwoFactor;
921
- if (user.hasOwnProperty('mfaEnrolled') && !user.mfaEnrolled) {
922
- yield effects.put(actions.setMfaState({
923
- step: exports.MFAStep.verify,
924
- qrCode: user.qrCode,
925
- recoveryCode: user.recoveryCode,
926
- mfaToken: user.mfaToken,
927
- loading: false,
928
- }));
929
- step = exports.LoginStep.forceTwoFactor;
930
- }
931
- yield effects.put(actions.setLoginState({ step }));
932
- onRedirectTo(routes.loginUrl);
933
- }
934
- else {
935
- yield effects.put(actions.setSignUpState({ loading: false, shouldActivate, stage: exports.SignUpStage.SignUpSuccess }));
936
- yield effects.put(actions.setState({
937
- user,
938
- isAuthenticated: !!(user === null || user === void 0 ? void 0 : user.accessToken),
939
- }));
940
- if (!shouldActivate) {
941
- yield effects.put(actions.loadTenants());
942
- }
943
- }
944
- }
945
- catch (e) {
946
- restApi.ContextHolder.setAccessToken(null);
947
- restApi.ContextHolder.setUser(null);
948
- yield effects.put(actions.setSignUpState({ loading: false, error: e.message }));
949
- }
950
- yield effects.put(actions.setSignUpState({ loading: false }));
951
- }
952
- function* resetSignUpStateSoft() {
953
- const { allowSignUps, allowNotVerifiedUsersLogin } = yield effects.select((state) => state.auth.signUpState);
954
- yield effects.put(actions.resetSignUpState());
955
- yield effects.put(actions.setSignUpState({ allowSignUps, allowNotVerifiedUsersLogin }));
956
- }
957
- function* signUpSaga() {
958
- yield effects.takeLeading(actions.signUpUser, signUpUser);
959
- yield effects.takeLeading(actions.resetSignUpStateSoft, resetSignUpStateSoft);
960
- }
961
-
962
- const authStrategyLoginStepMap = {
963
- [restApi.AuthStrategyEnum.Code]: exports.LoginStep.loginWithOtc,
964
- [restApi.AuthStrategyEnum.EmailAndPassword]: exports.LoginStep.loginWithPassword,
965
- [restApi.AuthStrategyEnum.MagicLink]: exports.LoginStep.magicLinkPreLoginSuccess,
966
- [restApi.AuthStrategyEnum.SmsCode]: exports.LoginStep.loginWithSmsOtc,
967
- };
968
- function* afterAuthNavigation() {
969
- var _a;
970
- const onRedirectTo = restApi.ContextHolder.onRedirectTo;
971
- const { routes, includeQueryParam } = yield effects.select((state) => state.auth);
972
- const { loginUrl, logoutUrl, socialLoginCallbackUrl, activateUrl } = routes;
973
- let { authenticatedUrl } = routes;
974
- const afterAuthRedirect = window.localStorage.getItem(constants.FRONTEGG_AFTER_AUTH_REDIRECT_URL);
975
- if (afterAuthRedirect && ![loginUrl, logoutUrl, socialLoginCallbackUrl, activateUrl].includes(afterAuthRedirect)) {
976
- authenticatedUrl = afterAuthRedirect;
977
- }
978
- window.localStorage.removeItem(constants.FRONTEGG_AFTER_AUTH_REDIRECT_URL);
979
- yield effects.delay(200);
980
- effects.put(actions.resetLoginState());
981
- const url = new URL(window === null || window === void 0 ? void 0 : window.location.href);
982
- let redirectUrl = authenticatedUrl;
983
- if (url.searchParams.get('redirectUrl')) {
984
- redirectUrl = (_a = url.searchParams.get('redirectUrl')) !== null && _a !== void 0 ? _a : authenticatedUrl;
985
- }
986
- else if (includeQueryParam) {
987
- redirectUrl += window.location.search;
988
- }
989
- onRedirectTo(redirectUrl, { refresh: redirectUrl.startsWith('http') });
990
- }
991
- function* refreshMetadata() {
992
- var _a;
993
- let ssoACS;
994
- try {
995
- const metadata = yield effects.call(restApi.api.metadata.getSamlMetadata);
996
- ssoACS = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.configuration) === null || _a === void 0 ? void 0 : _a.acsUrl;
997
- }
998
- catch (e) {
999
- console.error(e);
1000
- }
1001
- yield effects.put(actions.setState({ ssoACS }));
1002
- }
1003
- function* loadSSOPublicConfigurationFunction() {
1004
- try {
1005
- const { isActive } = yield effects.call(restApi.api.auth.getSSOPublicConfiguration);
1006
- yield effects.put(actions.setState({ isSSOAuth: isActive }));
1007
- }
1008
- catch (e) {
1009
- console.error(e);
1010
- }
1011
- }
1012
- const isMfaRequired = (user) => {
1013
- if (user.mfaRequired && user.mfaToken) {
1014
- restApi.ContextHolder.setAccessToken(null);
1015
- restApi.ContextHolder.setUser(null);
1016
- return true;
1017
- }
1018
- else {
1019
- restApi.ContextHolder.setAccessToken(user.accessToken);
1020
- restApi.ContextHolder.setUser(user);
1021
- return false;
1022
- }
1023
- };
1024
- function* getMfaRequiredState(user) {
1025
- let setMfaState = {};
1026
- let step = exports.LoginStep.loginWithTwoFactor;
1027
- const { loginState } = yield effects.select((state) => state.auth);
1028
- const { isAllowedToRemember, mfaDeviceExpiration } = yield effects.call(restApi.api.auth.checkIfAllowToRememberMfaDevice, user.mfaToken);
1029
- if (user.hasOwnProperty('mfaEnrolled') && !user.mfaEnrolled) {
1030
- setMfaState = {
1031
- mfaState: {
1032
- step: exports.MFAStep.verify,
1033
- qrCode: user.qrCode,
1034
- recoveryCode: user.recoveryCode,
1035
- loading: false,
1036
- mfaToken: user.mfaToken,
1037
- },
1038
- };
1039
- step = exports.LoginStep.forceTwoFactor;
1040
- }
1041
- return Object.assign(Object.assign({ user: undefined, isAuthenticated: false }, setMfaState), { loginState: Object.assign(Object.assign({}, loginState), { mfaToken: user.mfaToken, mfaRequired: user.mfaRequired, loading: false, error: undefined, step, tenantsLoading: true, tenants: [], allowRememberMfaDevice: isAllowedToRemember, mfaDeviceExpiration }) });
1042
- }
1043
- function* refreshToken() {
1044
- var _a;
1045
- try {
1046
- const onRedirectTo = restApi.ContextHolder.onRedirectTo;
1047
- const { routes, loginState } = yield effects.select((state) => state.auth);
1048
- const { user, tenants } = yield effects.call(restApi.api.auth.refreshTokenV2);
1049
- if (isMfaRequired(user)) {
1050
- const mfaRequiredState = yield getMfaRequiredState(user);
1051
- yield effects.put(actions.setState(mfaRequiredState));
1052
- onRedirectTo(routes.loginUrl, { preserveQueryParams: true });
1053
- }
1054
- else {
1055
- if (user.email) {
1056
- localStorage.setItem('email', user.email);
1057
- }
1058
- const quickLoginToRegister = (_a = localStorage.getItem('register-quick-login')) !== null && _a !== void 0 ? _a : loginState.quickLoginToRegister;
1059
- const shouldNavigateToRegisterQuicKLogin = quickLoginToRegister && localStorage.getItem(`${user.email}-${quickLoginToRegister}`) !== 'true';
1060
- yield effects.put(actions.setTenantsState({ tenants, loading: false }));
1061
- yield effects.put(actions.setState({
1062
- user,
1063
- isAuthenticated: true,
1064
- loginState: Object.assign(Object.assign({}, loginState), { quickLoginToRegister, flow: shouldNavigateToRegisterQuicKLogin ? exports.LoginFlow.RegisterQuickLogin : exports.LoginFlow.Login })
1065
- }));
1066
- if (shouldNavigateToRegisterQuicKLogin) {
1067
- onRedirectTo(routes.loginUrl);
1068
- }
1069
- else if ([routes.loginUrl, routes.socialLoginCallbackUrl, routes.signUpUrl, routes.oidcRedirectUrl, routes.samlCallbackUrl]
1070
- .some(url => url && window.location.pathname.endsWith(url))) {
1071
- if (loginState.isNewUser && routes.signUpSuccessUrl && routes.socialLoginCallbackUrl === window.location.pathname) {
1072
- onRedirectTo(routes.signUpSuccessUrl, { refresh: routes.signUpSuccessUrl.startsWith('http') });
1073
- }
1074
- else {
1075
- yield afterAuthNavigation();
1076
- }
1077
- }
1078
- }
1079
- }
1080
- catch (e) {
1081
- restApi.ContextHolder.setAccessToken(null);
1082
- restApi.ContextHolder.setUser(null);
1083
- yield effects.put(actions.setState({ user: undefined, isAuthenticated: false }));
1084
- }
1085
- }
1086
- function* requestAuthorize({ payload: firstTime }) {
1087
- const calls = [];
1088
- if (firstTime) {
1089
- yield effects.put(actions.setState({ isLoading: true }));
1090
- yield effects.put(actions.loadSocialLoginsConfigurationV2());
1091
- calls.push(effects.call(loadAllowSignUps));
1092
- calls.push(effects.call(loadSSOPublicConfigurationFunction));
1093
- calls.push(effects.call(vendor_index.loadVendorPublicInfo));
1094
- calls.push(effects.call(refreshMetadata));
1095
- }
1096
- calls.push(effects.call(refreshToken));
1097
- yield effects.all(calls);
1098
- yield effects.put(actions.setState({ isLoading: false }));
1099
- }
1100
- function* refreshTokenSSR(accessToken) {
1101
- if (!accessToken) {
1102
- restApi.ContextHolder.setAccessToken(null);
1103
- restApi.ContextHolder.setUser(null);
1104
- yield effects.put(actions.setState({ user: undefined, isAuthenticated: false }));
1105
- return;
1106
- }
1107
- try {
1108
- const onRedirectTo = restApi.ContextHolder.onRedirectTo;
1109
- const { routes } = yield effects.select((state) => state.auth);
1110
- const { user, tenants } = yield effects.call(restApi.api.auth.generateLoginResponseV2, { accessToken });
1111
- if (isMfaRequired(user)) {
1112
- const mfaRequiredState = yield getMfaRequiredState(user);
1113
- yield effects.put(actions.setState(mfaRequiredState));
1114
- onRedirectTo(routes.loginUrl, { preserveQueryParams: true });
1115
- }
1116
- else {
1117
- yield effects.put(actions.setTenantsState({ tenants, loading: false }));
1118
- yield effects.put(actions.setState({ user, isAuthenticated: true }));
1119
- }
1120
- }
1121
- catch (e) {
1122
- restApi.ContextHolder.setAccessToken(null);
1123
- restApi.ContextHolder.setUser(null);
1124
- yield effects.put(actions.setState({ user: undefined, isAuthenticated: false }));
1125
- }
1126
- }
1127
- function* requestAuthorizeSSR({ payload: accessToken }) {
1128
- const calls = [];
1129
- yield effects.put(actions.setState({ isLoading: true }));
1130
- yield effects.put(actions.loadSocialLoginsConfigurationV2());
1131
- calls.push(effects.call(loadAllowSignUps));
1132
- calls.push(effects.call(loadSSOPublicConfigurationFunction));
1133
- calls.push(effects.call(vendor_index.loadVendorPublicInfo));
1134
- calls.push(effects.call(refreshMetadata));
1135
- calls.push(effects.call(refreshTokenSSR, accessToken));
1136
- yield effects.all(calls);
1137
- yield effects.put(actions.setState({ isLoading: false }));
1138
- }
1139
- function* requestHostedLoginAuthorize() {
1140
- const { routes, context, onRedirectTo } = yield effects.select((state) => ({
1141
- routes: state.auth.routes,
1142
- onRedirectTo: state.auth.onRedirectTo,
1143
- context: state.root.context,
1144
- }));
1145
- // Generate the relevant params for the redirect
1146
- const nonce = createRandomString();
1147
- const code_verifier = createRandomString();
1148
- const code_challenge = yield effects.call(generateCodeChallenge, code_verifier);
1149
- // We are saving the verifier in session storage to be able to validate the response
1150
- localStorage.setItem(constants.HOSTED_LOGIN_VERIFIER_KEY, code_verifier);
1151
- const redirectUrl = `${window.location.origin}${routes.hostedLoginRedirectUrl}`;
1152
- const baseUrl = restApi.fetch.getBaseUrl(context, '/oauth/authorize');
1153
- // Hard coded for now
1154
- const oauthUrl = `${baseUrl}/oauth/authorize`;
1155
- const params = {
1156
- response_type: 'code',
1157
- client_id: context.clientId || 'INVALID-CLIENT-ID',
1158
- scope: 'openid email profile',
1159
- redirect_uri: redirectUrl,
1160
- code_challenge: code_challenge,
1161
- code_challenge_method: 'S256',
1162
- nonce,
1163
- };
1164
- const searchParams = new URLSearchParams(params);
1165
- const url = `${oauthUrl}?${searchParams.toString()}`;
1166
- onRedirectTo(url, { refresh: true });
1167
- }
1168
- function* handleHostedLoginCallback({ payload }) {
1169
- // Hard coded for now
1170
- const code_verifier = localStorage.getItem(constants.HOSTED_LOGIN_VERIFIER_KEY) || 'INVALID-CODE-VERIFIER';
1171
- const routes = yield effects.select((state) => state.auth.routes);
1172
- const redirectUrl = `${window.location.origin}${routes.hostedLoginRedirectUrl}`;
1173
- const body = {
1174
- code: payload.code,
1175
- redirect_uri: redirectUrl,
1176
- code_verifier,
1177
- grant_type: 'authorization_code',
1178
- };
1179
- const user = yield effects.call(restApi.api.auth.exchangeOAuthTokens, body);
1180
- // TODO: Validate nonce and aud
1181
- yield effects.put(actions.setState({ user, isAuthenticated: true }));
1182
- yield effects.put(actions.loadTenants());
1183
- yield afterAuthNavigation();
1184
- }
1185
- function* passwordlessPreLogin(_a) {
1186
- var _b = _a.payload, { callback } = _b, payload = tslib.__rest(_b, ["callback"]);
1187
- try {
1188
- const { onRedirectTo, routes } = yield effects.select(({ auth: { onRedirectTo, routes } }) => ({ onRedirectTo, routes }));
1189
- yield effects.put(actions.setLoginState({ loading: true }));
1190
- const preloginRes = yield effects.call(restApi.api.auth.passwordlessPreLogin, payload);
1191
- const step = authStrategyLoginStepMap[payload.type];
1192
- if (step === exports.LoginStep.loginWithSmsOtc && preloginRes.resetPhoneNumberToken) {
1193
- yield effects.put(actions.setResetPhoneNumberState({
1194
- resetPhoneNumberToken: preloginRes.resetPhoneNumberToken,
1195
- step: exports.ResetPhoneNumberStep.VerifyResetPhoneNumber,
1196
- }));
1197
- onRedirectTo(routes.resetPhoneNumberUrl);
1198
- return;
1199
- }
1200
- yield effects.put(actions.setLoginState({
1201
- step,
1202
- loading: false,
1203
- email: payload.email,
1204
- phoneNumber: preloginRes === null || preloginRes === void 0 ? void 0 : preloginRes.phoneNumber,
1205
- }));
1206
- callback === null || callback === void 0 ? void 0 : callback();
1207
- }
1208
- catch (e) {
1209
- yield effects.put(actions.setLoginState({ error: e.message, loading: false }));
1210
- callback === null || callback === void 0 ? void 0 : callback();
1211
- }
1212
- }
1213
- function* passwordlessPostLogin(_a) {
1214
- var _b, _c;
1215
- var _d = _a.payload, { callback, events } = _d, payload = tslib.__rest(_d, ["callback", "events"]);
1216
- try {
1217
- yield effects.put(actions.setLoginState({ loading: true }));
1218
- const data = yield effects.call(restApi.api.auth.passwordlessPostLogin, payload);
1219
- const onRedirectTo = restApi.ContextHolder.onRedirectTo;
1220
- const { routes } = yield effects.select((state) => state.auth);
1221
- if (isMfaRequired(data)) {
1222
- const mfaRequiredState = yield getMfaRequiredState(data);
1223
- yield effects.put(actions.setState(mfaRequiredState));
1224
- onRedirectTo(routes.loginUrl, { preserveQueryParams: true });
1225
- }
1226
- else {
1227
- const { loginState } = yield effects.select((state) => state.auth);
1228
- const user = yield effects.call(restApi.api.auth.generateLoginResponse, data);
1229
- if (data.emailVerified) {
1230
- (_b = events === null || events === void 0 ? void 0 : events.userVerified) === null || _b === void 0 ? void 0 : _b.call(events, {
1231
- email: user.email,
1232
- origin: exports.UserVeirifedOriginTypes.PASSWORDLESS,
1233
- id: user.id,
1234
- tenantId: user.tenantId,
1235
- createdAt: new Date(),
1236
- name: user.name,
1237
- });
1238
- }
1239
- if (user.email) {
1240
- localStorage.setItem('email', user.email);
1241
- }
1242
- yield effects.put(actions.setState({ user, isAuthenticated: true }));
1243
- yield effects.put(actions.loadTenants());
1244
- if (loginState.flow === exports.LoginFlow.Login) {
1245
- yield afterAuthNavigation();
1246
- }
1247
- else {
1248
- onRedirectTo(routes.loginUrl, { preserveQueryParams: true });
1249
- }
1250
- }
1251
- callback === null || callback === void 0 ? void 0 : callback(true);
1252
- }
1253
- catch (e) {
1254
- yield effects.put(actions.setLoginState({ error: (_c = e.message) !== null && _c !== void 0 ? _c : 'Failed to authenticate' }));
1255
- }
1256
- finally {
1257
- yield effects.put(actions.setLoginState({ loading: false }));
1258
- }
1259
- }
1260
- function* verifyInviteToken({ payload }) {
1261
- var _a;
1262
- try {
1263
- yield effects.put(actions.setLoginState({ loading: true }));
1264
- const { name: inviteTokenTenantName } = yield effects.call(restApi.api.auth.verifyInviteToken, payload);
1265
- yield effects.put(actions.setLoginState({ inviteTokenTenantName }));
1266
- }
1267
- catch (e) {
1268
- console.error(e);
1269
- yield effects.put(actions.setLoginState({ inviteTokenError: (_a = e.message) !== null && _a !== void 0 ? _a : `We couldn't verify your invitation` }));
1270
- }
1271
- finally {
1272
- yield effects.put(actions.setLoginState({ loading: false }));
1273
- }
1274
- }
1275
- function* preLogin({ payload: { email, recaptchaToken, invitationToken, callback, }, }) {
1276
- yield effects.put(actions.setLoginState({ loading: true }));
1277
- try {
1278
- const onRedirectTo = yield effects.select(({ auth: { onRedirectTo } }) => onRedirectTo);
1279
- let { address, idpType } = yield effects.call(restApi.api.auth.preLoginV2, { email });
1280
- if (address) {
1281
- if (idpType === exports.SamlVendors.Oidc && !address.includes('redirect_uri')) {
1282
- const { routes: { oidcRedirectUrl } } = yield effects.select(({ auth: { routes } }) => ({ routes }));
1283
- address += `&redirect_uri=${window.location.origin}${oidcRedirectUrl}`;
1284
- }
1285
- yield effects.put(actions.setLoginState({ step: exports.LoginStep.redirectToSSO, loading: false, ssoRedirectUrl: address }));
1286
- setTimeout(() => {
1287
- onRedirectTo(address, { refresh: true });
1288
- }, 2000);
1289
- }
1290
- else {
1291
- yield ssoPreloginFailed({ email, recaptchaToken, callback, invitationToken });
1292
- }
1293
- }
1294
- catch (e) {
1295
- yield ssoPreloginFailed({ email, recaptchaToken, callback, invitationToken });
1296
- }
1297
- }
1298
- function* ssoPreloginFailed(_a) {
1299
- var { callback } = _a, body = tslib.__rest(_a, ["callback"]);
1300
- const publicPolicy = yield effects.select(({ auth: { securityPolicyState: { publicPolicy: { policy: publicPolicy } } } }) => publicPolicy);
1301
- if (!(publicPolicy === null || publicPolicy === void 0 ? void 0 : publicPolicy.authStrategy)) {
1302
- yield effects.put(actions.setLoginState({ step: exports.LoginStep.loginWithPassword, loading: false }));
1303
- callback === null || callback === void 0 ? void 0 : callback();
1304
- return;
1305
- }
1306
- if ((publicPolicy === null || publicPolicy === void 0 ? void 0 : publicPolicy.authStrategy) === restApi.AuthStrategyEnum.EmailAndPassword) {
1307
- yield effects.put(actions.setLoginState({ step: exports.LoginStep.loginWithPassword, loading: false }));
1308
- callback === null || callback === void 0 ? void 0 : callback();
1309
- }
1310
- else if ([restApi.AuthStrategyEnum.MagicLink, restApi.AuthStrategyEnum.Code, restApi.AuthStrategyEnum.SmsCode].includes(publicPolicy === null || publicPolicy === void 0 ? void 0 : publicPolicy.authStrategy)) {
1311
- yield effects.put(actions.passwordlessPreLogin(Object.assign(Object.assign({}, body), { type: publicPolicy === null || publicPolicy === void 0 ? void 0 : publicPolicy.authStrategy, callback })));
1312
- }
1313
- else {
1314
- yield effects.put(actions.setLoginState({ step: exports.LoginStep.loginWithPassword, loading: false }));
1315
- callback === null || callback === void 0 ? void 0 : callback();
1316
- }
1317
- }
1318
- function* webAuthnCreateNewDeviceSession({ payload: { callback } }) {
1319
- try {
1320
- yield effects.put(actions.setLoginState({ loading: true }));
1321
- const { options } = yield effects.call(restApi.api.auth.webAuthnCreateNewDeviceSession);
1322
- options.user.id = vendor_index.base64urlDecode(options.user.id);
1323
- options.challenge = vendor_index.base64urlDecode(options.challenge);
1324
- options.excludeCredentials = [];
1325
- callback === null || callback === void 0 ? void 0 : callback(options);
1326
- }
1327
- catch (e) {
1328
- yield effects.put(actions.setLoginState({ error: e.message }));
1329
- callback === null || callback === void 0 ? void 0 : callback(null);
1330
- }
1331
- finally {
1332
- yield effects.put(actions.setLoginState({ loading: false }));
1333
- }
1334
- }
1335
- function* webAuthnVerifyNewDeviceSession(_a) {
1336
- var _b = _a.payload, { callback } = _b, body = tslib.__rest(_b, ["callback"]);
1337
- try {
1338
- yield effects.put(actions.setLoginState({ loading: true }));
1339
- const publicKey = vendor_index.publicKeyCredentialToJSON(body.publicKey);
1340
- yield effects.call(restApi.api.auth.verifyNewDeviceSession, {
1341
- id: publicKey.id,
1342
- response: publicKey.response
1343
- });
1344
- callback === null || callback === void 0 ? void 0 : callback(true);
1345
- }
1346
- catch (e) {
1347
- yield effects.put(actions.setLoginState({ error: e.message }));
1348
- callback === null || callback === void 0 ? void 0 : callback(null);
1349
- }
1350
- finally {
1351
- yield effects.put(actions.setLoginState({ loading: false }));
1352
- }
1353
- }
1354
- function* webAuthnPrelogin(_a) {
1355
- var _b;
1356
- var _c = _a.payload, { callback } = _c, body = tslib.__rest(_c, ["callback"]);
1357
- try {
1358
- yield effects.put(actions.setLoginState({ loading: true }));
1359
- const { options } = yield effects.call(restApi.api.auth.webAuthnPreLogin, body);
1360
- options.challenge = vendor_index.base64urlDecode(options.challenge);
1361
- options.allowCredentials = (_b = options.allowCredentials) === null || _b === void 0 ? void 0 : _b.map((credentials) => (Object.assign(Object.assign({}, credentials), { id: vendor_index.base64urlDecode(credentials.id) })));
1362
- callback === null || callback === void 0 ? void 0 : callback(options);
1363
- }
1364
- catch (e) {
1365
- yield effects.put(actions.setLoginState({ error: e.message }));
1366
- callback === null || callback === void 0 ? void 0 : callback(null);
1367
- }
1368
- finally {
1369
- yield effects.put(actions.setLoginState({ loading: false }));
1370
- }
1371
- }
1372
- function* webAuthnPostLogin(_a) {
1373
- var _b;
1374
- var _c = _a.payload, { callback } = _c, body = tslib.__rest(_c, ["callback"]);
1375
- try {
1376
- yield effects.put(actions.setLoginState({ loading: true }));
1377
- const publicKey = vendor_index.publicKeyCredentialToJSON(body.publicKey);
1378
- const data = yield effects.call(restApi.api.auth.webAuthnPostLogin, Object.assign(Object.assign({}, publicKey), { response: Object.assign(Object.assign({}, publicKey.response), { userHandle: (_b = publicKey.response.userHandle) !== null && _b !== void 0 ? _b : undefined }), recaptchaToken: body.recaptchaToken, invitationToken: body.invitationToken }));
1379
- if (isMfaRequired(data)) {
1380
- const onRedirectTo = restApi.ContextHolder.onRedirectTo;
1381
- const { routes } = yield effects.select((state) => state.auth);
1382
- const mfaRequiredState = yield getMfaRequiredState(data);
1383
- yield effects.put(actions.setState(mfaRequiredState));
1384
- onRedirectTo(routes.loginUrl, { preserveQueryParams: true });
1385
- }
1386
- else {
1387
- const user = yield effects.call(restApi.api.auth.generateLoginResponse, data);
1388
- yield effects.put(actions.loadTenants());
1389
- yield effects.put(actions.setState({ user, isAuthenticated: true }));
1390
- yield afterAuthNavigation();
1391
- }
1392
- callback === null || callback === void 0 ? void 0 : callback(true);
1393
- }
1394
- catch (e) {
1395
- yield effects.put(actions.setLoginState({ error: e.message }));
1396
- callback === null || callback === void 0 ? void 0 : callback(null);
1397
- }
1398
- finally {
1399
- yield effects.put(actions.setLoginState({ loading: false }));
1400
- }
1401
- }
1402
- function* postLogin({ payload }) {
1403
- const { onRedirectTo, routes } = yield effects.select(({ auth: { onRedirectTo, routes } }) => ({ onRedirectTo, routes }));
1404
- yield effects.put(actions.setLoginState({ loading: true }));
1405
- try {
1406
- const user = yield effects.call(restApi.api.auth.postLogin, payload);
1407
- restApi.ContextHolder.setAccessToken(user.accessToken);
1408
- restApi.ContextHolder.setUser(user);
1409
- yield effects.put(actions.setState({
1410
- user: !!user.accessToken ? user : undefined,
1411
- isAuthenticated: !!user.accessToken,
1412
- }));
1413
- yield afterAuthNavigation();
1414
- }
1415
- catch (e) {
1416
- setTimeout(() => {
1417
- onRedirectTo(routes.authenticatedUrl);
1418
- }, 1000);
1419
- yield effects.put(actions.setLoginState({ step: exports.LoginStep.loginWithSSOFailed, loading: false }));
1420
- }
1421
- }
1422
- function* login({ payload: { email, password, recaptchaToken, invitationToken, callback, }, }) {
1423
- yield effects.put(actions.setLoginState({ loading: true }));
1424
- try {
1425
- const user = yield effects.call(restApi.api.auth.login, {
1426
- email,
1427
- password,
1428
- recaptchaToken,
1429
- invitationToken,
1430
- });
1431
- restApi.ContextHolder.setAccessToken(user.accessToken);
1432
- restApi.ContextHolder.setUser(user);
1433
- let setMfaState = {};
1434
- let step = exports.LoginStep.success;
1435
- if (user.mfaRequired && user.mfaToken) {
1436
- step = exports.LoginStep.loginWithTwoFactor;
1437
- if (user.hasOwnProperty('mfaEnrolled') && !user.mfaEnrolled) {
1438
- setMfaState = {
1439
- mfaState: {
1440
- step: exports.MFAStep.verify,
1441
- qrCode: user.qrCode,
1442
- recoveryCode: user.recoveryCode,
1443
- mfaToken: user.mfaToken,
1444
- loading: false,
1445
- },
1446
- };
1447
- step = exports.LoginStep.forceTwoFactor;
1448
- }
1449
- }
1450
- const { loginState } = yield effects.select((state) => state.auth);
1451
- const isLoginSucceeded = step === exports.LoginStep.success;
1452
- const isAuthenticated = isLoginSucceeded && !!user.accessToken;
1453
- const loggedInUser = isLoginSucceeded ? user : undefined;
1454
- let allowRememberDevice = { isAllowedToRemember: false, mfaDeviceExpiration: 0 };
1455
- if (user.mfaRequired && user.mfaToken) {
1456
- allowRememberDevice = yield effects.call(restApi.api.auth.checkIfAllowToRememberMfaDevice, user.mfaToken);
1457
- }
1458
- const { isAllowedToRemember, mfaDeviceExpiration } = allowRememberDevice;
1459
- if (user.email) {
1460
- localStorage.setItem('email', user.email);
1461
- }
1462
- yield effects.put(actions.setState(Object.assign(Object.assign({ user: loggedInUser, isAuthenticated }, setMfaState), { loginState: {
1463
- flow: loginState.flow,
1464
- quickLoginToRegister: loginState.quickLoginToRegister,
1465
- email,
1466
- loading: false,
1467
- error: undefined,
1468
- mfaToken: user.mfaToken,
1469
- step: (!isLoginSucceeded || loginState.flow === exports.LoginFlow.Login) ? step : loginState.step,
1470
- tenants: [],
1471
- tenantsLoading: true,
1472
- allowRememberMfaDevice: isAllowedToRemember,
1473
- mfaDeviceExpiration,
1474
- } })));
1475
- if (isLoginSucceeded) {
1476
- yield effects.put(actions.loadTenants());
1477
- }
1478
- if (isAuthenticated && loginState.flow === exports.LoginFlow.Login) {
1479
- yield afterAuthNavigation();
1480
- }
1481
- callback === null || callback === void 0 ? void 0 : callback(true);
1482
- }
1483
- catch (e) {
1484
- restApi.ContextHolder.setAccessToken(null);
1485
- restApi.ContextHolder.setUser(null);
1486
- yield effects.put(actions.setLoginState({
1487
- email,
1488
- error: e.message,
1489
- loading: false,
1490
- }));
1491
- }
1492
- }
1493
- function* loginWithMfa({ payload: { mfaToken, value, rememberDevice, callback }, }) {
1494
- yield effects.put(actions.setLoginState({ loading: true }));
1495
- try {
1496
- const user = yield effects.call(restApi.api.auth.loginWithMfa, { mfaToken, value, rememberDevice });
1497
- const { loginState } = yield effects.select((state) => state.auth);
1498
- const step = loginState.flow === exports.LoginFlow.Login ? exports.LoginStep.success : loginState.step;
1499
- yield effects.put(actions.setState({
1500
- loginState: { flow: loginState.flow, quickLoginToRegister: loginState.quickLoginToRegister, loading: false, step, error: undefined, tenantsLoading: true, tenants: [] },
1501
- user,
1502
- isAuthenticated: true,
1503
- }));
1504
- if (user.email) {
1505
- localStorage.setItem('email', user.email);
1506
- }
1507
- yield effects.put(actions.loadTenants());
1508
- if (loginState.flow === exports.LoginFlow.Login) {
1509
- yield afterAuthNavigation();
1510
- }
1511
- callback === null || callback === void 0 ? void 0 : callback(true);
1512
- }
1513
- catch (e) {
1514
- yield effects.put(actions.setLoginState({ error: e.message, loading: false }));
1515
- callback === null || callback === void 0 ? void 0 : callback(false, e);
1516
- }
1517
- }
1518
- function* recoverMfa({ payload }) {
1519
- yield effects.put(actions.setLoginState({ loading: true }));
1520
- try {
1521
- yield effects.call(restApi.api.auth.recoverMfaToken, payload);
1522
- yield effects.put(actions.setLoginState({ loading: false, error: undefined, step: exports.LoginStep.preLogin }));
1523
- yield effects.put(actions.setState({ user: undefined, isAuthenticated: false }));
1524
- }
1525
- catch (e) {
1526
- yield effects.put(actions.setLoginState({ error: e.message, loading: false }));
1527
- }
1528
- }
1529
- function* logout({ payload }) {
1530
- yield effects.put(actions.setState({ isLoading: true }));
1531
- try {
1532
- yield effects.call(restApi.api.auth.logout);
1533
- }
1534
- catch (_a) {
1535
- }
1536
- yield effects.put(actions.resetState());
1537
- yield effects.put(actions.requestAuthorize(true));
1538
- payload === null || payload === void 0 ? void 0 : payload();
1539
- }
1540
- function* silentLogout({ payload }) {
1541
- try {
1542
- yield effects.call(restApi.api.auth.logout);
1543
- }
1544
- catch (_a) {
1545
- }
1546
- setTimeout(() => payload === null || payload === void 0 ? void 0 : payload(), 500);
1547
- }
1548
- function* loginSagas() {
1549
- yield effects.takeLeading(actions.requestAuthorize, requestAuthorize);
1550
- yield effects.takeLeading(actions.requestAuthorizeSSR, requestAuthorizeSSR);
1551
- yield effects.takeLeading(actions.requestHostedLoginAuthorize, requestHostedLoginAuthorize);
1552
- yield effects.takeLeading(actions.handleHostedLoginCallback, handleHostedLoginCallback);
1553
- yield effects.takeLeading(actions.preLogin, preLogin);
1554
- yield effects.takeLeading(actions.postLogin, postLogin);
1555
- yield effects.takeLeading(actions.login, login);
1556
- yield effects.takeLeading(actions.logout, logout);
1557
- yield effects.takeLeading(actions.silentLogout, silentLogout);
1558
- yield effects.takeLeading(actions.loginWithMfa, loginWithMfa);
1559
- yield effects.takeLeading(actions.recoverMfa, recoverMfa);
1560
- yield effects.takeLeading(actions.passwordlessPreLogin, passwordlessPreLogin);
1561
- yield effects.takeLeading(actions.passwordlessPostLogin, passwordlessPostLogin);
1562
- yield effects.takeLeading(actions.verifyInviteToken, verifyInviteToken);
1563
- yield effects.takeLeading(actions.webAuthnPrelogin, webAuthnPrelogin);
1564
- yield effects.takeLeading(actions.webAuthnPostLogin, webAuthnPostLogin);
1565
- yield effects.takeLeading(actions.webAuthnCreateNewDeviceSession, webAuthnCreateNewDeviceSession);
1566
- yield effects.takeLeading(actions.webAuthnVerifyNewDeviceSession, webAuthnVerifyNewDeviceSession);
1567
- yield effects.takeLeading(actions.afterAuthNavigation, afterAuthNavigation);
1568
- }
1569
- /*********************************
1570
- * Preview Sagas
1571
- *********************************/
1572
- function* requestAuthorizeMock({ payload: firstTime }) {
1573
- if (firstTime) {
1574
- yield effects.put(actions.setState({ isLoading: true }));
1575
- }
1576
- const user = userDemo;
1577
- yield effects.put(actions.loadTenants());
1578
- yield effects.put(actions.setState({ user, isAuthenticated: true, isLoading: false }));
1579
- }
1580
- function* loginSagasMock() {
1581
- yield effects.takeLeading(actions.requestAuthorize, requestAuthorizeMock);
1582
- yield effects.takeLeading(actions.afterAuthNavigation, afterAuthNavigation);
1583
- }
1584
-
1585
- function* loadSSOConfigurations() {
1586
- var _a, _b;
1587
- try {
1588
- yield effects.put(actions.setSSOState({ loading: true }));
1589
- const samlConfiguration = yield effects.call(restApi.api.auth.getSamlConfiguration);
1590
- const oidcConfiguration = yield effects.call(restApi.api.auth.getOidcConfiguration);
1591
- const samlMetadata = yield effects.call(restApi.api.metadata.getSamlMetadata);
1592
- samlConfiguration.acsUrl = (_a = samlMetadata === null || samlMetadata === void 0 ? void 0 : samlMetadata.configuration) === null || _a === void 0 ? void 0 : _a.acsUrl;
1593
- samlConfiguration.spEntityId = (_b = samlMetadata === null || samlMetadata === void 0 ? void 0 : samlMetadata.configuration) === null || _b === void 0 ? void 0 : _b.spEntityId;
1594
- samlConfiguration.isSamlActive = samlMetadata === null || samlMetadata === void 0 ? void 0 : samlMetadata.isActive;
1595
- yield effects.put(actions.setSSOState({ samlConfiguration, oidcConfiguration, loading: false, firstLoad: false }));
1596
- }
1597
- catch (e) {
1598
- yield effects.put(actions.setSSOState({ error: e.message, loading: false }));
1599
- }
1600
- }
1601
- function* saveSSOConfigurationsFile({ payload: configFile }) {
1602
- const oldSamlConfiguration = yield effects.select((state) => state.auth.ssoState.samlConfiguration);
1603
- const loaderKey = 'saving';
1604
- yield effects.put(actions.setSSOState({ error: undefined, [loaderKey]: true }));
1605
- try {
1606
- const metadata = yield readFileAsText(configFile[0]);
1607
- const newSamlConfiguration = yield effects.call(restApi.api.auth.updateSamlVendorMetadata, { metadata });
1608
- newSamlConfiguration.isSamlActive = oldSamlConfiguration === null || oldSamlConfiguration === void 0 ? void 0 : oldSamlConfiguration.isSamlActive;
1609
- yield effects.put(actions.setSSOState({ samlConfiguration: newSamlConfiguration, error: undefined, [loaderKey]: false }));
1610
- }
1611
- catch (e) {
1612
- yield effects.put(actions.setSSOState({ samlConfiguration: oldSamlConfiguration, error: e.message, [loaderKey]: false }));
1613
- }
1614
- }
1615
- function* saveSSOConfigurationsFileWithCallback({ payload }) {
1616
- const { configFile, callback } = payload;
1617
- const oldSamlConfiguration = yield effects.select((state) => state.auth.ssoState.samlConfiguration);
1618
- const loaderKey = 'saving';
1619
- yield effects.put(actions.setSSOState({ error: undefined, [loaderKey]: true }));
1620
- try {
1621
- const metadata = yield readFileAsText(configFile);
1622
- const newSamlConfiguration = yield effects.call(restApi.api.auth.updateSamlVendorMetadata, { metadata });
1623
- newSamlConfiguration.isSamlActive = oldSamlConfiguration === null || oldSamlConfiguration === void 0 ? void 0 : oldSamlConfiguration.isSamlActive;
1624
- yield effects.put(actions.setSSOState({ samlConfiguration: newSamlConfiguration, error: undefined, [loaderKey]: false }));
1625
- callback === null || callback === void 0 ? void 0 : callback(true);
1626
- }
1627
- catch (e) {
1628
- yield effects.put(actions.setSSOState({ samlConfiguration: oldSamlConfiguration, error: e.message, [loaderKey]: false }));
1629
- callback === null || callback === void 0 ? void 0 : callback(null, e);
1630
- }
1631
- }
1632
- function* saveSSOConfigurations({ payload }) {
1633
- var _a, _b;
1634
- const { callback, samlVendor } = payload, newSamlConfiguration = tslib.__rest(payload, ["callback", "samlVendor"]);
1635
- const oldSamlConfiguration = yield effects.select((state) => state.auth.ssoState.samlConfiguration);
1636
- const samlConfiguration = Object.assign(Object.assign({}, oldSamlConfiguration), newSamlConfiguration);
1637
- let loaderKey = 'saving';
1638
- if ((samlConfiguration === null || samlConfiguration === void 0 ? void 0 : samlConfiguration.enabled) !== oldSamlConfiguration.enabled) {
1639
- loaderKey = 'loading';
1640
- }
1641
- try {
1642
- const firstTimeConfigure = !(samlConfiguration === null || samlConfiguration === void 0 ? void 0 : samlConfiguration.domain);
1643
- if (firstTimeConfigure) {
1644
- yield effects.put(actions.setSSOState({ samlConfiguration: Object.assign(Object.assign({}, oldSamlConfiguration), samlConfiguration) }));
1645
- return;
1646
- }
1647
- else {
1648
- yield effects.put(actions.setSSOState({ error: undefined, [loaderKey]: true }));
1649
- }
1650
- if (payload.type === exports.SamlVendors.Saml) {
1651
- const samlMetadata = yield effects.call(restApi.api.metadata.getSamlMetadata);
1652
- samlConfiguration.acsUrl = (_a = samlMetadata === null || samlMetadata === void 0 ? void 0 : samlMetadata.configuration) === null || _a === void 0 ? void 0 : _a.acsUrl;
1653
- samlConfiguration.spEntityId = (_b = samlMetadata === null || samlMetadata === void 0 ? void 0 : samlMetadata.configuration) === null || _b === void 0 ? void 0 : _b.spEntityId;
1654
- }
1655
- const updateSamlConfiguration = omitProps(samlConfiguration, [
1656
- 'validated',
1657
- 'generatedVerification',
1658
- 'createdAt',
1659
- 'updatedAt',
1660
- ]);
1661
- if ((oldSamlConfiguration === null || oldSamlConfiguration === void 0 ? void 0 : oldSamlConfiguration.domain) !== (updateSamlConfiguration === null || updateSamlConfiguration === void 0 ? void 0 : updateSamlConfiguration.domain)) {
1662
- updateSamlConfiguration.ssoEndpoint = '';
1663
- updateSamlConfiguration.publicCertificate = '';
1664
- updateSamlConfiguration.signRequest = false;
1665
- }
1666
- updateSamlConfiguration.type = samlVendor === null || samlVendor === void 0 ? void 0 : samlVendor.toLowerCase();
1667
- const newSamlConfiguration = yield effects.call(restApi.api.auth.updateSamlConfiguration, updateSamlConfiguration);
1668
- newSamlConfiguration.isSamlActive = oldSamlConfiguration === null || oldSamlConfiguration === void 0 ? void 0 : oldSamlConfiguration.isSamlActive;
1669
- yield effects.put(actions.setSSOState({ samlConfiguration: newSamlConfiguration, error: undefined, [loaderKey]: false }));
1670
- callback === null || callback === void 0 ? void 0 : callback(true);
1671
- }
1672
- catch (e) {
1673
- yield effects.put(actions.setSSOState({ samlConfiguration: oldSamlConfiguration, error: e.message, [loaderKey]: false }));
1674
- callback === null || callback === void 0 ? void 0 : callback(null, e);
1675
- }
1676
- }
1677
- function* validateSSODomain({ payload: { callback } = {} }) {
1678
- const samlConfiguration = yield effects.select((state) => state.auth.ssoState.samlConfiguration);
1679
- try {
1680
- yield effects.put(actions.setSSOState({ error: undefined, saving: true }));
1681
- yield effects.call(restApi.api.auth.validateSamlDomain);
1682
- yield effects.put(actions.setSSOState({
1683
- samlConfiguration: Object.assign(Object.assign({}, samlConfiguration), { validated: true }),
1684
- error: undefined,
1685
- saving: false,
1686
- }));
1687
- callback === null || callback === void 0 ? void 0 : callback(true);
1688
- }
1689
- catch (e) {
1690
- yield effects.put(actions.setSSOState({
1691
- samlConfiguration: Object.assign(Object.assign({}, samlConfiguration), { validated: false }),
1692
- error: e.message,
1693
- saving: false,
1694
- }));
1695
- callback === null || callback === void 0 ? void 0 : callback(null, e);
1696
- }
1697
- }
1698
- function* getAuthorizationRoles() {
1699
- try {
1700
- const data = yield effects.call(restApi.api.auth.getSamlRoles);
1701
- const groupsData = yield effects.call(restApi.api.auth.getSamlRolesGroups);
1702
- yield effects.put(actions.setSSOState({
1703
- authorizationRoles: data.roleIds,
1704
- rolesGroups: groupsData,
1705
- error: undefined,
1706
- }));
1707
- }
1708
- catch (e) {
1709
- yield effects.put(actions.setSSOState({
1710
- error: e.message,
1711
- }));
1712
- }
1713
- }
1714
- function* updateRolesGroups(groups) {
1715
- try {
1716
- yield effects.all(groups.map((group) => effects.call(restApi.api.auth.updateSamlGroup, { id: group.id, roleIds: group.roleIds, group: group.group })));
1717
- }
1718
- catch (e) {
1719
- yield effects.put(actions.setSSOState({
1720
- error: e.message,
1721
- }));
1722
- }
1723
- }
1724
- function* updateAuthorizationRoles({ payload: { callback, authorizationRoles, groups }, }) {
1725
- try {
1726
- yield effects.put(actions.setSSOState({ error: undefined, saving: true }));
1727
- yield effects.call(restApi.api.auth.updateSamlRoles, { roleIds: authorizationRoles });
1728
- if (groups) {
1729
- yield updateRolesGroups(groups);
1730
- }
1731
- yield getAuthorizationRoles();
1732
- yield effects.put(actions.setSSOState({ error: undefined, saving: false }));
1733
- callback === null || callback === void 0 ? void 0 : callback(true);
1734
- }
1735
- catch (e) {
1736
- yield effects.put(actions.setSSOState({
1737
- error: e.message,
1738
- saving: false,
1739
- }));
1740
- callback === null || callback === void 0 ? void 0 : callback(null, e);
1741
- }
1742
- }
1743
- function* deleteSamlGroupFunction({ payload: { callback, id } }) {
1744
- try {
1745
- yield effects.put(actions.setSSOState({ error: undefined, saving: true }));
1746
- yield effects.call(restApi.api.auth.deleteSamlGroup, { id });
1747
- yield getAuthorizationRoles();
1748
- yield effects.put(actions.setSSOState({ error: undefined, saving: false }));
1749
- callback === null || callback === void 0 ? void 0 : callback(true);
1750
- }
1751
- catch (e) {
1752
- yield effects.put(actions.setSSOState({
1753
- error: e.message,
1754
- saving: false,
1755
- }));
1756
- callback === null || callback === void 0 ? void 0 : callback(null, e);
1757
- }
1758
- }
1759
- function* createSamlGroupFunction({ payload: { group, roleIds, callback } }) {
1760
- try {
1761
- yield effects.put(actions.setSSOState({ error: undefined, saving: true }));
1762
- yield effects.call(restApi.api.auth.createSamlGroup, { group, roleIds });
1763
- yield getAuthorizationRoles();
1764
- yield effects.put(actions.setSSOState({ error: undefined, saving: false }));
1765
- callback === null || callback === void 0 ? void 0 : callback(true);
1766
- }
1767
- catch (e) {
1768
- yield effects.put(actions.setSSOState({
1769
- error: e.message,
1770
- saving: false,
1771
- }));
1772
- callback === null || callback === void 0 ? void 0 : callback(null, e);
1773
- }
1774
- }
1775
- function* oidcPostloginFunction({ payload }) {
1776
- var _a;
1777
- const data = { code: payload.code, redirectUri: payload.redirectUri, RelayState: payload.state };
1778
- try {
1779
- yield effects.put(actions.setSSOState({ loading: true }));
1780
- yield effects.call(restApi.api.auth.oidcPostLoginV2, data);
1781
- yield refreshToken();
1782
- yield effects.put(actions.setSSOState({ loading: false }));
1783
- }
1784
- catch (e) {
1785
- yield effects.put(actions.setSSOState({ loading: false, error: (_a = e.message) !== null && _a !== void 0 ? _a : 'Failed to authenticate', firstLoad: false }));
1786
- }
1787
- }
1788
- function* ssoSagas$1() {
1789
- yield effects.takeEvery(actions.loadSSOConfigurations, loadSSOConfigurations);
1790
- yield effects.takeEvery(actions.saveSSOConfigurations, saveSSOConfigurations);
1791
- yield effects.takeEvery(actions.saveSSOConfigurationsFile, saveSSOConfigurationsFile);
1792
- yield effects.takeEvery(actions.saveSSOConfigurationsFileWithCallback, saveSSOConfigurationsFileWithCallback);
1793
- yield effects.takeEvery(actions.validateSSODomain, validateSSODomain);
1794
- yield effects.takeEvery(actions.loadSSOAuthorizationRoles, getAuthorizationRoles);
1795
- yield effects.takeEvery(actions.updateSSOAuthorizationRoles, updateAuthorizationRoles);
1796
- yield effects.takeEvery(actions.deleteSamlGroup, deleteSamlGroupFunction);
1797
- yield effects.takeEvery(actions.createSamlGroup, createSamlGroupFunction);
1798
- yield effects.takeEvery(actions.oidcPostlogin, oidcPostloginFunction);
1799
- }
1800
- /*********************************
1801
- * Preview Sagas
1802
- *********************************/
1803
- function* loadSSOConfigurationsMock() {
1804
- yield effects.put(actions.setSSOState({ loading: true }));
1805
- yield vendor_index.delay();
1806
- yield effects.put(actions.setSSOState({ samlConfiguration: samlConfigurationDemo, loading: false, firstLoad: false }));
1807
- }
1808
- function* saveSSOConfigurationsFileMock({ payload: configFile }) {
1809
- const loaderKey = 'saving';
1810
- yield effects.put(actions.setSSOState({ error: undefined, [loaderKey]: true }));
1811
- const oldSamlConfiguration = yield effects.select((state) => state.auth.ssoState.samlConfiguration);
1812
- const newSamlConfiguration = Object.assign(Object.assign(Object.assign({}, oldSamlConfiguration), { enabled: true }), configFile[0]);
1813
- yield effects.put(actions.setSSOState({ samlConfiguration: newSamlConfiguration, error: undefined, [loaderKey]: false }));
1814
- }
1815
- function* saveSSOConfigurationsMock({ payload }) {
1816
- var _a, _b;
1817
- const { callback, samlVendor } = payload, newSamlConfiguration = tslib.__rest(payload, ["callback", "samlVendor"]);
1818
- const oldSamlConfiguration = ssoStateDemo.samlConfiguration;
1819
- const samlConfiguration = Object.assign(Object.assign({}, oldSamlConfiguration), newSamlConfiguration);
1820
- let loaderKey = 'saving';
1821
- if ((samlConfiguration === null || samlConfiguration === void 0 ? void 0 : samlConfiguration.enabled) !== oldSamlConfiguration.enabled) {
1822
- loaderKey = 'loading';
1823
- }
1824
- const firstTimeConfigure = !(samlConfiguration === null || samlConfiguration === void 0 ? void 0 : samlConfiguration.domain);
1825
- if (firstTimeConfigure) {
1826
- yield effects.put(actions.setSSOState({ samlConfiguration: Object.assign(Object.assign({}, oldSamlConfiguration), samlConfiguration) }));
1827
- return;
1828
- }
1829
- else {
1830
- yield effects.put(actions.setSSOState({ error: undefined, [loaderKey]: true }));
1831
- }
1832
- yield vendor_index.delay();
1833
- samlConfiguration.acsUrl = (_a = samlMetadataDemo === null || samlMetadataDemo === void 0 ? void 0 : samlMetadataDemo.configuration) === null || _a === void 0 ? void 0 : _a.acsUrl;
1834
- samlConfiguration.spEntityId = (_b = samlMetadataDemo === null || samlMetadataDemo === void 0 ? void 0 : samlMetadataDemo.configuration) === null || _b === void 0 ? void 0 : _b.spEntityId;
1835
- const updateSamlConfiguration = omitProps(samlConfiguration, [
1836
- 'validated',
1837
- 'generatedVerification',
1838
- 'createdAt',
1839
- 'updatedAt',
1840
- ]);
1841
- if ((oldSamlConfiguration === null || oldSamlConfiguration === void 0 ? void 0 : oldSamlConfiguration.domain) !== (updateSamlConfiguration === null || updateSamlConfiguration === void 0 ? void 0 : updateSamlConfiguration.domain)) {
1842
- updateSamlConfiguration.ssoEndpoint = '';
1843
- updateSamlConfiguration.publicCertificate = '';
1844
- updateSamlConfiguration.signRequest = false;
1845
- }
1846
- updateSamlConfiguration.type = samlVendor === null || samlVendor === void 0 ? void 0 : samlVendor.toLowerCase();
1847
- yield vendor_index.delay();
1848
- yield effects.put(actions.setSSOState({ samlConfiguration: updateSamlConfiguration, error: undefined, [loaderKey]: false }));
1849
- callback === null || callback === void 0 ? void 0 : callback(true);
1850
- }
1851
- function* validateSSODomainMock({ payload: { callback } = {} }) {
1852
- const samlConfiguration = ssoStateDemo.samlConfiguration;
1853
- yield effects.put(actions.setSSOState({ error: undefined, saving: true }));
1854
- yield vendor_index.delay();
1855
- yield effects.put(actions.setSSOState({
1856
- samlConfiguration: Object.assign(Object.assign({}, samlConfiguration), { validated: true }),
1857
- error: undefined,
1858
- saving: false,
1859
- }));
1860
- callback === null || callback === void 0 ? void 0 : callback(true);
1861
- }
1862
- function* getAuthorizationRolesMock() {
1863
- yield vendor_index.delay();
1864
- const data = { roleIds: ['1', '2', '3'] };
1865
- yield effects.put(actions.setSSOState({
1866
- authorizationRoles: data.roleIds,
1867
- error: undefined,
1868
- }));
1869
- }
1870
- function* updateAuthorizationRolesMock({ payload: { callback, authorizationRoles }, }) {
1871
- yield effects.put(actions.setSSOState({ error: undefined, saving: true }));
1872
- yield vendor_index.delay();
1873
- yield effects.put(actions.setSSOState({ authorizationRoles, error: undefined, saving: false }));
1874
- callback === null || callback === void 0 ? void 0 : callback(true);
1875
- }
1876
- function* ssoSagasMock() {
1877
- yield effects.takeEvery(actions.loadSSOConfigurations, loadSSOConfigurationsMock);
1878
- yield effects.takeEvery(actions.saveSSOConfigurations, saveSSOConfigurationsMock);
1879
- yield effects.takeEvery(actions.saveSSOConfigurationsFile, saveSSOConfigurationsFileMock);
1880
- yield effects.takeEvery(actions.validateSSODomain, validateSSODomainMock);
1881
- yield effects.takeEvery(actions.loadSSOAuthorizationRoles, getAuthorizationRolesMock);
1882
- yield effects.takeEvery(actions.updateSSOAuthorizationRoles, updateAuthorizationRolesMock);
1883
- }
1884
-
1885
- function* loadOidc() {
1886
- try {
1887
- const oidcConfiguration = yield effects.call(restApi.api.auth.getOidcConfiguration);
1888
- return oidcConfiguration;
1889
- }
1890
- catch (e) {
1891
- return null;
1892
- }
1893
- }
1894
- function* loadSaml() {
1895
- try {
1896
- const samlMetadata = yield effects.call(restApi.api.metadata.getSamlMetadata);
1897
- return samlMetadata;
1898
- }
1899
- catch (e) {
1900
- return null;
1901
- }
1902
- }
1903
- function* loadSSOConfigurationsV2() {
1904
- try {
1905
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.LOAD_SSO_CONFIGURATIONS, value: true }));
1906
- const [oidcConfiguration, samlMetadata] = yield effects.all([effects.call(loadOidc), effects.call(loadSaml)]);
1907
- const ssoConfigurations = yield effects.call(restApi.api.auth.getSSOConfigurations);
1908
- yield effects.put(actions.setSSOState({
1909
- ssoConfigurations,
1910
- oidcConfiguration,
1911
- samlMetadata
1912
- }));
1913
- }
1914
- catch (error) {
1915
- yield effects.put(actions.setSSOError({ key: exports.SSOStateKeys.LOAD_SSO_CONFIGURATIONS, value: error.message }));
1916
- }
1917
- finally {
1918
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.LOAD_SSO_CONFIGURATIONS, value: false }));
1919
- }
1920
- }
1921
- function* saveSSOConfigurationV2({ payload }) {
1922
- var _a;
1923
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.SAVE_SSO_CONFIGURATION, value: true }));
1924
- const { callback } = payload, ssoConfiguration = tslib.__rest(payload, ["callback"]);
1925
- const ssoConfigurations = yield effects.select((state) => state.auth.ssoState.ssoConfigurations);
1926
- try {
1927
- const newSsoConfiguration = yield effects.call(restApi.api.auth.createSSOConfiguration, Object.assign(Object.assign({}, ssoConfiguration), { enabled: (_a = ssoConfiguration.enabled) !== null && _a !== void 0 ? _a : false }));
1928
- yield effects.put(actions.setSSOState({ ssoConfigurations: [...ssoConfigurations, newSsoConfiguration] }));
1929
- callback === null || callback === void 0 ? void 0 : callback(newSsoConfiguration);
1930
- }
1931
- catch (error) {
1932
- yield effects.put(actions.setSSOError({ key: exports.SSOStateKeys.SAVE_SSO_CONFIGURATION, value: error.message }));
1933
- callback === null || callback === void 0 ? void 0 : callback(null, error);
1934
- }
1935
- finally {
1936
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.SAVE_SSO_CONFIGURATION, value: false }));
1937
- }
1938
- }
1939
- function* saveSSOConfigurationByMetadata({ payload }) {
1940
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.SAVE_SSO_CONFIGURATION_BY_METADATA, value: true }));
1941
- const { configFile, callback } = payload;
1942
- const ssoConfigurations = yield effects.select((state) => state.auth.ssoState.ssoConfigurations);
1943
- try {
1944
- const metadata = yield readFileAsText(configFile);
1945
- const newSsoConfiguration = yield effects.call(restApi.api.auth.createSSOConfigurationByMetadata, { metadata });
1946
- yield effects.put(actions.setSSOState({ ssoConfigurations: [...ssoConfigurations, newSsoConfiguration] }));
1947
- callback === null || callback === void 0 ? void 0 : callback(newSsoConfiguration);
1948
- }
1949
- catch (error) {
1950
- yield effects.put(actions.setSSOError({ key: exports.SSOStateKeys.SAVE_SSO_CONFIGURATION_BY_METADATA, value: error.message }));
1951
- callback === null || callback === void 0 ? void 0 : callback(null, error);
1952
- }
1953
- finally {
1954
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.SAVE_SSO_CONFIGURATION_BY_METADATA, value: false }));
1955
- }
1956
- }
1957
- function* updateSSOConfiguration({ payload }) {
1958
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.UPDATE_SSO_CONFIGURATION, value: true }));
1959
- const { callback, ssoConfigId } = payload, ssoConfiguration = tslib.__rest(payload, ["callback", "ssoConfigId"]);
1960
- const ssoConfigurations = yield effects.select((state) => state.auth.ssoState.ssoConfigurations);
1961
- try {
1962
- const newSsoConfiguration = yield effects.call(restApi.api.auth.updateSSOConfiguration, ssoConfigId, ssoConfiguration);
1963
- const newSsoConfigurations = ssoConfigurations.map((ssoConfig) => ssoConfig.id === ssoConfigId ? newSsoConfiguration : ssoConfig);
1964
- yield effects.put(actions.setSSOState({ ssoConfigurations: newSsoConfigurations }));
1965
- callback === null || callback === void 0 ? void 0 : callback(newSsoConfiguration);
1966
- }
1967
- catch (error) {
1968
- yield effects.put(actions.setSSOError({ key: exports.SSOStateKeys.UPDATE_SSO_CONFIGURATION, value: error.message }));
1969
- callback === null || callback === void 0 ? void 0 : callback(null, error);
1970
- }
1971
- finally {
1972
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.UPDATE_SSO_CONFIGURATION, value: false }));
1973
- }
1974
- }
1975
- function* updateSSOConfigurationByMetadata({ payload }) {
1976
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.UPDATE_SSO_CONFIGURATION_BY_METADATA, value: true }));
1977
- const { callback, ssoConfigId, configFile } = payload;
1978
- const ssoConfigurations = yield effects.select((state) => state.auth.ssoState.ssoConfigurations);
1979
- try {
1980
- const metadata = yield readFileAsText(configFile);
1981
- const newSsoConfiguration = yield effects.call(restApi.api.auth.updateSSOConfigurationByMetadata, ssoConfigId, { metadata });
1982
- const newSsoConfigurations = ssoConfigurations.map((ssoConfig) => ssoConfig.id === ssoConfigId ? newSsoConfiguration : ssoConfig);
1983
- yield effects.put(actions.setSSOState({ ssoConfigurations: newSsoConfigurations }));
1984
- callback === null || callback === void 0 ? void 0 : callback(newSsoConfiguration);
1985
- }
1986
- catch (error) {
1987
- yield effects.put(actions.setSSOError({ key: exports.SSOStateKeys.UPDATE_SSO_CONFIGURATION, value: error.message }));
1988
- callback === null || callback === void 0 ? void 0 : callback(null, error);
1989
- }
1990
- finally {
1991
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.UPDATE_SSO_CONFIGURATION, value: false }));
1992
- }
1993
- }
1994
- function* deleteSSOConfiguration({ payload }) {
1995
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.DELETE_SSO_CONFIGURATION, value: true }));
1996
- const { ssoConfigId, callback } = payload;
1997
- const ssoConfigurations = yield effects.select((state) => state.auth.ssoState.ssoConfigurations);
1998
- try {
1999
- yield effects.call(restApi.api.auth.deleteSSOConfiguration, ssoConfigId);
2000
- yield effects.put(actions.setSSOState({ ssoConfigurations: ssoConfigurations.filter(({ id }) => id !== ssoConfigId) }));
2001
- callback === null || callback === void 0 ? void 0 : callback(true);
2002
- }
2003
- catch (error) {
2004
- yield effects.put(actions.setSSOError({ key: exports.SSOStateKeys.DELETE_SSO_CONFIGURATION, value: error.message }));
2005
- callback === null || callback === void 0 ? void 0 : callback(null, error);
2006
- }
2007
- finally {
2008
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.DELETE_SSO_CONFIGURATION, value: false }));
2009
- }
2010
- }
2011
- function* saveSSODomain({ payload }) {
2012
- const { callback, ssoConfigId } = payload, body = tslib.__rest(payload, ["callback", "ssoConfigId"]);
2013
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.SAVE_SSO_DOMAIN, value: true }));
2014
- const ssoConfigurations = yield effects.select((state) => state.auth.ssoState.ssoConfigurations);
2015
- try {
2016
- const domain = yield effects.call(restApi.api.auth.createSSODomain, ssoConfigId, body);
2017
- const newSsoConfigurations = ssoConfigurations.map((ssoConfig) => {
2018
- if (ssoConfig.id === ssoConfigId) {
2019
- return Object.assign(Object.assign({}, ssoConfig), { domains: [...ssoConfig.domains, domain] });
2020
- }
2021
- return ssoConfig;
2022
- });
2023
- yield effects.put(actions.setSSOState({ ssoConfigurations: newSsoConfigurations }));
2024
- callback === null || callback === void 0 ? void 0 : callback(domain);
2025
- }
2026
- catch (error) {
2027
- yield effects.put(actions.setSSOError({ key: exports.SSOStateKeys.SAVE_SSO_DOMAIN, value: error.message }));
2028
- callback === null || callback === void 0 ? void 0 : callback(null, error);
2029
- }
2030
- finally {
2031
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.SAVE_SSO_DOMAIN, value: false }));
2032
- }
2033
- }
2034
- function* deleteSSODomain({ payload }) {
2035
- const { ssoConfigId, domainId, callback } = payload;
2036
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.DELETE_SSO_DOMAIN, value: true }));
2037
- const ssoConfigurations = yield effects.select((state) => state.auth.ssoState.ssoConfigurations);
2038
- try {
2039
- yield effects.call(restApi.api.auth.deleteSSODomain, ssoConfigId, domainId);
2040
- const newSsoConfigurations = ssoConfigurations.map((ssoConfig) => {
2041
- if (ssoConfig.id === ssoConfigId) {
2042
- return Object.assign(Object.assign({}, ssoConfig), { domains: ssoConfig.domains.filter(({ id }) => id !== domainId) });
2043
- }
2044
- return ssoConfig;
2045
- });
2046
- yield effects.put(actions.setSSOState({ ssoConfigurations: newSsoConfigurations }));
2047
- callback === null || callback === void 0 ? void 0 : callback(true);
2048
- }
2049
- catch (error) {
2050
- yield effects.put(actions.setSSOError({ key: exports.SSOStateKeys.DELETE_SSO_DOMAIN, value: error.message }));
2051
- callback === null || callback === void 0 ? void 0 : callback(null, error);
2052
- }
2053
- finally {
2054
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.DELETE_SSO_DOMAIN, value: false }));
2055
- }
2056
- }
2057
- function* validateSSODomainV2({ payload }) {
2058
- const { callback, domainId, ssoConfigId } = payload;
2059
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.VALIDATE_SSO_DOMAIN, value: true }));
2060
- const ssoConfigurations = yield effects.select((state) => state.auth.ssoState.ssoConfigurations);
2061
- try {
2062
- yield effects.call(restApi.api.auth.validateSSODomain, ssoConfigId, domainId);
2063
- const newSsoConfigurations = ssoConfigurations.map((ssoConfig) => {
2064
- if (ssoConfig.id === ssoConfigId) {
2065
- return Object.assign(Object.assign({}, ssoConfig), { domains: ssoConfig.domains.map((ssoDomain) => ssoDomain.id === domainId ? Object.assign(Object.assign({}, ssoDomain), { validated: true }) : ssoDomain) });
2066
- }
2067
- return ssoConfig;
2068
- });
2069
- yield effects.put(actions.setSSOState({ ssoConfigurations: newSsoConfigurations }));
2070
- callback === null || callback === void 0 ? void 0 : callback(true);
2071
- }
2072
- catch (error) {
2073
- yield effects.put(actions.setSSOError({ key: exports.SSOStateKeys.VALIDATE_SSO_DOMAIN, value: error.message }));
2074
- callback === null || callback === void 0 ? void 0 : callback(null, error);
2075
- }
2076
- finally {
2077
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.VALIDATE_SSO_DOMAIN, value: false }));
2078
- }
2079
- }
2080
- function* setSSODefaultRoles({ payload: { callback, ssoConfigId, roleIds }, }) {
2081
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.UPDATE_SSO_DEFAULT_ROLES, value: true }));
2082
- const ssoConfigurations = yield effects.select((state) => state.auth.ssoState.ssoConfigurations);
2083
- try {
2084
- yield effects.call(restApi.api.auth.setSSODefaultRoles, ssoConfigId, { roleIds });
2085
- const newSsoConfigurations = ssoConfigurations.map((ssoConfig) => {
2086
- if (ssoConfig.id === ssoConfigId) {
2087
- return Object.assign(Object.assign({}, ssoConfig), { roleIds });
2088
- }
2089
- return ssoConfig;
2090
- });
2091
- yield effects.put(actions.setSSOState({ ssoConfigurations: newSsoConfigurations }));
2092
- callback === null || callback === void 0 ? void 0 : callback(true);
2093
- }
2094
- catch (error) {
2095
- yield effects.put(actions.setSSOError({ key: exports.SSOStateKeys.UPDATE_SSO_DEFAULT_ROLES, value: error.message }));
2096
- callback === null || callback === void 0 ? void 0 : callback(null, error);
2097
- }
2098
- finally {
2099
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.UPDATE_SSO_DEFAULT_ROLES, value: false }));
2100
- }
2101
- }
2102
- function* setSSOGroups({ payload: { groupsToAdd, groupsToDelete, ssoConfigId, callback } }) {
2103
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.SAVE_SSO_GROUPS, value: true }));
2104
- const ssoConfigurations = yield effects.select((state) => state.auth.ssoState.ssoConfigurations);
2105
- try {
2106
- yield effects.all(groupsToDelete.map((groupId) => effects.call(restApi.api.auth.deleteSSOGroup, ssoConfigId, groupId)));
2107
- yield effects.all(groupsToAdd.map((group) => effects.call(restApi.api.auth.createSSOGroup, ssoConfigId, group)));
2108
- const groups = yield effects.call(restApi.api.auth.getSSOGroups, ssoConfigId);
2109
- const newSsoConfigurations = ssoConfigurations.map((ssoConfig) => {
2110
- if (ssoConfig.id === ssoConfigId) {
2111
- return Object.assign(Object.assign({}, ssoConfig), { groups });
2112
- }
2113
- return ssoConfig;
2114
- });
2115
- yield effects.put(actions.setSSOState({ ssoConfigurations: newSsoConfigurations }));
2116
- callback === null || callback === void 0 ? void 0 : callback(true);
2117
- }
2118
- catch (error) {
2119
- yield effects.put(actions.setSSOError({ key: exports.SSOStateKeys.SAVE_SSO_GROUPS, value: error.message }));
2120
- callback === null || callback === void 0 ? void 0 : callback(null, error);
2121
- }
2122
- finally {
2123
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.SAVE_SSO_GROUPS, value: false }));
2124
- }
2125
- }
2126
- function* updateSSOGroups({ payload: { ssoConfigId, changedGroups, callback } }) {
2127
- try {
2128
- yield effects.all(changedGroups.map((group) => effects.call(restApi.api.auth.updateSSOGroup, ssoConfigId, group)));
2129
- callback === null || callback === void 0 ? void 0 : callback(true);
2130
- }
2131
- catch (error) {
2132
- yield effects.put(actions.setSSOError({ key: exports.SSOStateKeys.SAVE_SSO_GROUPS, value: error.message }));
2133
- callback === null || callback === void 0 ? void 0 : callback(null, error);
2134
- }
2135
- finally {
2136
- yield effects.put(actions.setSSOLoader({ key: exports.SSOStateKeys.SAVE_SSO_GROUPS, value: false }));
2137
- }
2138
- }
2139
- function* ssoSagas() {
2140
- yield effects.takeEvery(actions.loadSSOConfigurationsV2, loadSSOConfigurationsV2);
2141
- yield effects.takeEvery(actions.saveSSOConfigurationV2, saveSSOConfigurationV2);
2142
- yield effects.takeEvery(actions.saveSSODomain, saveSSODomain);
2143
- yield effects.takeEvery(actions.deleteSSODomain, deleteSSODomain);
2144
- yield effects.takeEvery(actions.validateSSODomainV2, validateSSODomainV2);
2145
- yield effects.takeEvery(actions.updateSSOConfiguration, updateSSOConfiguration);
2146
- yield effects.takeEvery(actions.deleteSSOConfiguration, deleteSSOConfiguration);
2147
- yield effects.takeEvery(actions.setSSOGroups, setSSOGroups);
2148
- yield effects.takeEvery(actions.updateSSOGroups, updateSSOGroups);
2149
- yield effects.takeEvery(actions.setSSODefaultRoles, setSSODefaultRoles);
2150
- yield effects.takeEvery(actions.saveSSOConfigurationByMetadata, saveSSOConfigurationByMetadata);
2151
- yield effects.takeEvery(actions.updateSSOConfigurationByMetadata, updateSSOConfigurationByMetadata);
2152
- }
2153
-
2154
- function* loadProfile() {
2155
- yield effects.put(actions.setProfileState({ loading: true }));
2156
- try {
2157
- const profile = yield effects.retry(3, 2000, restApi.api.teams.getProfile);
2158
- const currentUser = yield effects.select((state) => state.auth.user);
2159
- actions.setUser(Object.assign(Object.assign({}, currentUser), profile));
2160
- yield effects.put(actions.setProfileState({ profile, loading: false }));
2161
- }
2162
- catch (e) {
2163
- yield effects.put(actions.setProfileState({ loading: false, error: e.message }));
2164
- }
2165
- }
2166
- function b64toBlob(base64, contentType) {
2167
- const sliceSize = 512;
2168
- const byteCharacters = atob(base64);
2169
- const byteArrays = [];
2170
- for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
2171
- const slice = byteCharacters.slice(offset, offset + sliceSize);
2172
- const byteNumbers = new Array(slice.length);
2173
- for (let i = 0; i < slice.length; i++) {
2174
- byteNumbers[i] = slice.charCodeAt(i);
2175
- }
2176
- byteArrays.push(new Uint8Array(byteNumbers));
2177
- }
2178
- return new Blob(byteArrays, { type: contentType });
2179
- }
2180
- function base64ToFormData(base64, key = 'file') {
2181
- const matchResult = base64.match(/^data:image\/([A-Za-z-+\/]+);base64,(.+)$/);
2182
- if (matchResult == null) {
2183
- return null;
2184
- }
2185
- // Get the content type of the image
2186
- const contentType = `image/${matchResult[1]}`;
2187
- // get the real base64 content of the file
2188
- const data = matchResult[2];
2189
- // Convert it to a blob to upload
2190
- const blob = b64toBlob(data, contentType);
2191
- // Create a FormData and append the file with "image" as parameter name
2192
- const formDataToUpload = new FormData();
2193
- formDataToUpload.append(key, new File([blob], key, { type: contentType }));
2194
- return formDataToUpload;
2195
- }
2196
- function* saveProfile(_a) {
2197
- var _b = _a.payload, { callback, profilePictureUrl } = _b, payload = tslib.__rest(_b, ["callback", "profilePictureUrl"]);
2198
- yield effects.put(actions.setProfileState({ saving: true, error: null }));
2199
- try {
2200
- const oldProfileData = yield effects.select((state) => state.auth.profileState.profile);
2201
- let newProfilePictureUrl = oldProfileData.profilePictureUrl;
2202
- if (profilePictureUrl !== oldProfileData.profilePictureUrl && profilePictureUrl) {
2203
- const matchResult = (profilePictureUrl || '').match(/^data:image\/([A-Za-z-+\/]+);base64,(.+)$/);
2204
- if (matchResult) {
2205
- const profileImage = base64ToFormData(profilePictureUrl, 'image');
2206
- if (profileImage) {
2207
- newProfilePictureUrl = yield effects.call(restApi.api.teams.updateProfileImage, profileImage);
2208
- const imageTimeStamp = Date.now().toString();
2209
- const urlTemplate = new URL(newProfilePictureUrl);
2210
- urlTemplate.searchParams.set('t', imageTimeStamp);
2211
- newProfilePictureUrl = urlTemplate.href;
2212
- }
2213
- }
2214
- }
2215
- const newProfileData = Object.assign(Object.assign(Object.assign({}, oldProfileData), payload), { profilePictureUrl: newProfilePictureUrl });
2216
- const profile = yield effects.call(restApi.api.teams.updateProfile, newProfileData);
2217
- const currentUser = yield effects.select((state) => state.auth.user);
2218
- yield effects.put(actions.setUser(Object.assign(Object.assign({}, currentUser), profile)));
2219
- yield effects.put(actions.setProfileState({ profile, saving: false }));
2220
- callback === null || callback === void 0 ? void 0 : callback(newProfileData);
2221
- }
2222
- catch (e) {
2223
- yield effects.put(actions.setProfileState({ saving: false, error: e.message }));
2224
- callback === null || callback === void 0 ? void 0 : callback(null, e);
2225
- }
2226
- }
2227
- function* changePassword({ payload }) {
2228
- var _a, _b;
2229
- yield effects.put(actions.setProfileState({ loading: true }));
2230
- try {
2231
- yield effects.call(restApi.api.teams.changePassword, payload);
2232
- yield effects.put(actions.setProfileState({ loading: false, error: undefined }));
2233
- (_a = payload.callback) === null || _a === void 0 ? void 0 : _a.call(payload, true);
2234
- }
2235
- catch (e) {
2236
- yield effects.put(actions.setProfileState({ loading: false, error: e.message }));
2237
- (_b = payload.callback) === null || _b === void 0 ? void 0 : _b.call(payload, null, e);
2238
- }
2239
- }
2240
- function* profileSagas() {
2241
- yield effects.takeLeading(actions.loadProfile, loadProfile);
2242
- yield effects.takeEvery(actions.saveProfile, saveProfile);
2243
- yield effects.takeEvery(actions.changePassword, changePassword);
2244
- }
2245
- /*********************************
2246
- * Preview Sagas
2247
- *********************************/
2248
- function* loadProfileMock() {
2249
- yield effects.put(actions.setProfileState({ loading: true }));
2250
- yield vendor_index.delay();
2251
- yield effects.put(actions.setUser(Object.assign(Object.assign({}, (userDemo)), userProfileDemo)));
2252
- yield effects.put(actions.setProfileState({ loading: false, profile: userProfileDemo }));
2253
- }
2254
- function* saveProfileMock(_a) {
2255
- var _b = _a.payload, { callback, profilePictureUrl } = _b, payload = tslib.__rest(_b, ["callback", "profilePictureUrl"]);
2256
- yield effects.put(actions.setProfileState({ saving: true, error: null }));
2257
- const oldProfileData = profileStateDemo;
2258
- let newProfilePictureUrl = oldProfileData.profile.profilePictureUrl;
2259
- if (profilePictureUrl !== oldProfileData.profile.profilePictureUrl && profilePictureUrl) {
2260
- const matchResult = (profilePictureUrl || '').match(/^data:image\/([A-Za-z-+\/]+);base64,(.+)$/);
2261
- if (matchResult) {
2262
- newProfilePictureUrl = profilePictureUrl;
2263
- }
2264
- }
2265
- const newProfileData = Object.assign(Object.assign(Object.assign({}, oldProfileData.profile), payload), { profilePictureUrl: newProfilePictureUrl });
2266
- const currentUser = userDemo;
2267
- yield vendor_index.delay();
2268
- yield effects.put(actions.setUser(Object.assign(Object.assign({}, currentUser), newProfileData)));
2269
- yield effects.put(actions.setProfileState({ loading: false, error: null, saving: false, profile: newProfileData }));
2270
- callback === null || callback === void 0 ? void 0 : callback(newProfileData);
2271
- }
2272
- function* changePasswordMock({ payload }) {
2273
- var _a;
2274
- yield effects.put(actions.setProfileState({ loading: true }));
2275
- yield vendor_index.delay();
2276
- yield effects.put(actions.setProfileState({ loading: false, error: undefined }));
2277
- (_a = payload.callback) === null || _a === void 0 ? void 0 : _a.call(payload, true);
2278
- }
2279
- function* profileSagasMock() {
2280
- yield effects.takeLeading(actions.loadProfile, loadProfileMock);
2281
- yield effects.takeEvery(actions.saveProfile, saveProfileMock);
2282
- yield effects.takeEvery(actions.changePassword, changePasswordMock);
2283
- }
2284
-
2285
- function* enrollMfa() {
2286
- yield effects.put(actions.setMfaState({ loading: true }));
2287
- try {
2288
- const { qrCode } = yield effects.call(restApi.api.auth.enrollMfa);
2289
- yield effects.put(actions.setMfaState({ loading: false, error: undefined, qrCode }));
2290
- }
2291
- catch (e) {
2292
- yield effects.put(actions.setMfaState({ loading: false, error: e.message }));
2293
- }
2294
- }
2295
- function* verifyMfa(_a) {
2296
- var _b = _a.payload, { callback } = _b, payload = tslib.__rest(_b, ["callback"]);
2297
- yield effects.put(actions.setMfaState({ loading: true }));
2298
- try {
2299
- const user = yield effects.select((state) => state.auth.user);
2300
- const data = yield effects.call(restApi.api.auth.verifyMfa, payload);
2301
- const mfaState = {
2302
- step: exports.MFAStep.recoveryCode,
2303
- loading: false,
2304
- error: undefined,
2305
- };
2306
- if (data === null || data === void 0 ? void 0 : data.recoveryCode) {
2307
- mfaState.recoveryCode = data.recoveryCode;
2308
- }
2309
- yield effects.put(actions.setMfaState(mfaState));
2310
- yield effects.put(actions.setUser(Object.assign(Object.assign({}, user), { mfaEnrolled: true })));
2311
- callback === null || callback === void 0 ? void 0 : callback(mfaState.recoveryCode);
2312
- }
2313
- catch (e) {
2314
- yield effects.put(actions.setMfaState({ loading: false, error: e.message }));
2315
- callback === null || callback === void 0 ? void 0 : callback(null, e);
2316
- }
2317
- }
2318
- function* verifyMfaAfterForce(_a) {
2319
- var _b = _a.payload, { callback } = _b, payload = tslib.__rest(_b, ["callback"]);
2320
- yield effects.put(actions.setMfaState({ loading: true }));
2321
- try {
2322
- const user = yield effects.call(restApi.api.auth.loginWithMfa, payload);
2323
- const mfaState = {
2324
- step: exports.MFAStep.recoveryCode,
2325
- loading: false,
2326
- error: undefined,
2327
- };
2328
- if (user === null || user === void 0 ? void 0 : user.recoveryCode) {
2329
- mfaState.recoveryCode = user.recoveryCode;
2330
- }
2331
- yield effects.put(actions.setMfaState(mfaState));
2332
- yield effects.put(actions.setState({ user }));
2333
- yield effects.put(actions.loadTenants());
2334
- callback === null || callback === void 0 ? void 0 : callback(mfaState.recoveryCode);
2335
- }
2336
- catch (e) {
2337
- yield effects.put(actions.setMfaState({ loading: false, error: e.message }));
2338
- callback === null || callback === void 0 ? void 0 : callback(null, e);
2339
- }
2340
- }
2341
- function* disableMfa({ payload }) {
2342
- var _a, _b;
2343
- yield effects.put(actions.setMfaState({ loading: true }));
2344
- try {
2345
- const user = yield effects.select((state) => state.auth.user);
2346
- yield restApi.api.auth.disableMfa(payload);
2347
- yield effects.put(actions.setMfaState({ loading: false, error: undefined }));
2348
- yield effects.put(actions.setUser(Object.assign(Object.assign({}, user), { mfaEnrolled: false })));
2349
- (_a = payload.callback) === null || _a === void 0 ? void 0 : _a.call(payload, true);
2350
- }
2351
- catch (e) {
2352
- yield effects.put(actions.setMfaState({ loading: false, error: e.message }));
2353
- (_b = payload.callback) === null || _b === void 0 ? void 0 : _b.call(payload, false, e);
2354
- }
2355
- }
2356
- function* mfaSagas() {
2357
- yield effects.takeEvery(actions.enrollMfa, enrollMfa);
2358
- yield effects.takeEvery(actions.verifyMfa, verifyMfa);
2359
- yield effects.takeEvery(actions.disableMfa, disableMfa);
2360
- yield effects.takeEvery(actions.verifyMfaAfterForce, verifyMfaAfterForce);
2361
- }
2362
- /*********************************
2363
- * Preview Sagas
2364
- *********************************/
2365
- function* enrollMfaMock() {
2366
- yield effects.put(actions.setMfaState({ loading: true }));
2367
- const qrCode = 'test';
2368
- yield effects.put(actions.setMfaState({ loading: false, error: undefined, qrCode }));
2369
- }
2370
- function* verifyMfaMock({ payload: { callback }, }) {
2371
- yield effects.put(actions.setMfaState({ loading: true }));
2372
- yield vendor_index.delay();
2373
- const data = { token: 'token', recoveryCode: 'recoveryCode' };
2374
- const mfaState = {
2375
- step: exports.MFAStep.recoveryCode,
2376
- loading: false,
2377
- error: undefined,
2378
- };
2379
- if (data === null || data === void 0 ? void 0 : data.recoveryCode) {
2380
- mfaState.recoveryCode = data.recoveryCode;
2381
- }
2382
- yield effects.put(actions.setMfaState(mfaState));
2383
- yield effects.put(actions.setUser(Object.assign(Object.assign({}, userDemo), { mfaEnrolled: true })));
2384
- callback === null || callback === void 0 ? void 0 : callback(mfaState.recoveryCode);
2385
- }
2386
- function* verifyMfaAfterForceMock(_a) {
2387
- var _b = _a.payload, { callback } = _b, payload = tslib.__rest(_b, ["callback"]);
2388
- yield effects.put(actions.setMfaState({ loading: true }));
2389
- yield vendor_index.delay();
2390
- const data = Object.assign(Object.assign({}, payload), { recoveryCode: 'recoveryCode' });
2391
- const mfaState = {
2392
- step: exports.MFAStep.recoveryCode,
2393
- loading: false,
2394
- error: undefined,
2395
- };
2396
- if (data === null || data === void 0 ? void 0 : data.recoveryCode) {
2397
- mfaState.recoveryCode = data.recoveryCode;
2398
- }
2399
- yield effects.put(actions.setMfaState(mfaState));
2400
- yield vendor_index.delay();
2401
- yield effects.put(actions.setUser(Object.assign(Object.assign({}, userDemo), { mfaEnrolled: true })));
2402
- callback === null || callback === void 0 ? void 0 : callback(mfaState.recoveryCode);
2403
- }
2404
- function* disableMfaMock({ payload }) {
2405
- var _a;
2406
- yield effects.put(actions.setMfaState({ loading: true }));
2407
- yield vendor_index.delay();
2408
- yield effects.put(actions.setMfaState({ loading: false, error: undefined }));
2409
- yield effects.put(actions.setUser(Object.assign(Object.assign({}, userDemo), { mfaEnrolled: false })));
2410
- (_a = payload.callback) === null || _a === void 0 ? void 0 : _a.call(payload, true);
2411
- }
2412
- function* mfaSagasMock() {
2413
- yield effects.takeEvery(actions.enrollMfa, enrollMfaMock);
2414
- yield effects.takeEvery(actions.verifyMfa, verifyMfaMock);
2415
- yield effects.takeEvery(actions.disableMfa, disableMfaMock);
2416
- yield effects.takeEvery(actions.verifyMfaAfterForce, verifyMfaAfterForceMock);
2417
- }
2418
-
2419
- function* forgotPassword({ payload }) {
2420
- yield effects.put(actions.setForgotPasswordState({ loading: true }));
2421
- try {
2422
- yield effects.call(restApi.api.auth.forgotPassword, payload);
2423
- yield effects.put(actions.setForgotPasswordState({ loading: false, error: undefined, step: exports.ForgotPasswordStep.success }));
2424
- }
2425
- catch (e) {
2426
- yield effects.put(actions.setForgotPasswordState({ loading: false, error: e.message || 'Unknown error occurred' }));
2427
- }
2428
- }
2429
- function* resetPassword(_a) {
2430
- var _b = _a.payload, { callback } = _b, body = tslib.__rest(_b, ["callback"]);
2431
- yield effects.put(actions.setForgotPasswordState({ loading: true }));
2432
- try {
2433
- yield effects.call(restApi.api.auth.resetPassword, body);
2434
- yield effects.put(actions.setForgotPasswordState({ loading: false, error: undefined, step: exports.ForgotPasswordStep.success }));
2435
- callback === null || callback === void 0 ? void 0 : callback(true);
2436
- }
2437
- catch (e) {
2438
- yield effects.put(actions.setForgotPasswordState({ loading: false, error: e.message }));
2439
- callback === null || callback === void 0 ? void 0 : callback(false);
2440
- }
2441
- }
2442
- function* loadPasswordConfig({ payload }) {
2443
- yield effects.put(actions.setForgotPasswordState({ loading: true }));
2444
- try {
2445
- const passwordConfig = yield effects.call(restApi.api.auth.loadPasswordConfig, payload);
2446
- yield effects.put(actions.setForgotPasswordState({ loading: false, passwordConfig }));
2447
- }
2448
- catch (e) {
2449
- yield effects.put(actions.setForgotPasswordState({ loading: false, error: e.message }));
2450
- }
2451
- }
2452
- function* forgotPasswordSagas() {
2453
- yield effects.takeLeading(actions.forgotPassword, forgotPassword);
2454
- yield effects.takeLeading(actions.resetPassword, resetPassword);
2455
- yield effects.takeLeading(actions.loadPasswordConfig, loadPasswordConfig);
2456
- }
2457
-
2458
- function* preActivateAccount({ payload: { userId, token } }) {
2459
- yield effects.put(actions.setActivateState({ loading: true, step: exports.ActivateAccountStep.activating }));
2460
- try {
2461
- const { isAuthenticated } = yield effects.select((state) => state.auth);
2462
- if (isAuthenticated) {
2463
- yield effects.put(actions.silentLogout());
2464
- }
2465
- const strategy = yield effects.call(restApi.api.auth.getActivateAccountStrategy, { userId, token });
2466
- yield effects.put(actions.setActivateStrategyState({ strategy, loading: false, error: undefined }));
2467
- if (strategy.shouldSetPassword) {
2468
- yield effects.put(actions.setActivateState({ loading: false, step: exports.ActivateAccountStep.activatingForm }));
2469
- }
2470
- }
2471
- catch (e) {
2472
- yield effects.put(actions.setActivateState({ loading: false, error: e.message }));
2473
- }
2474
- }
2475
- function* activateAccount(_a) {
2476
- var _b;
2477
- var _c = _a.payload, { callback, events } = _c, payload = tslib.__rest(_c, ["callback", "events"]);
2478
- yield effects.put(actions.setActivateState({ loading: true }));
2479
- try {
2480
- const onRedirectTo = restApi.ContextHolder.onRedirectTo;
2481
- const { routes } = yield effects.select((state) => state.auth);
2482
- const data = yield effects.call(restApi.api.auth.activateAccount, payload);
2483
- if (data.redirectLocation) {
2484
- window.location.href = data.redirectLocation;
2485
- return;
2486
- }
2487
- if (isMfaRequired(data)) {
2488
- yield effects.put(actions.setActivateState({ step: exports.ActivateAccountStep.success }));
2489
- const mfaRequiredState = yield getMfaRequiredState(data);
2490
- yield effects.put(actions.setState(mfaRequiredState));
2491
- yield effects.delay(1000);
2492
- onRedirectTo(routes.loginUrl, { preserveQueryParams: true });
2493
- }
2494
- else {
2495
- yield effects.put(actions.setActivateState({ step: exports.ActivateAccountStep.success }));
2496
- const { user, tenants } = yield effects.call(restApi.api.auth.generateLoginResponseV2, data);
2497
- (_b = events === null || events === void 0 ? void 0 : events.userVerified) === null || _b === void 0 ? void 0 : _b.call(events, { email: user.email, origin: exports.UserVeirifedOriginTypes.ACTIVATION_LINK, id: user.id, tenantId: user.tenantId, name: user.name, createdAt: new Date() });
2498
- yield effects.put(actions.setTenantsState({ tenants, loading: false }));
2499
- yield effects.put(actions.setState({ user, isAuthenticated: true }));
2500
- yield effects.delay(1000);
2501
- yield afterAuthNavigation();
2502
- yield effects.put(actions.resetActivateState());
2503
- }
2504
- callback === null || callback === void 0 ? void 0 : callback(true);
2505
- }
2506
- catch (e) {
2507
- yield effects.put(actions.setActivateState({ loading: false, error: e.message }));
2508
- }
2509
- }
2510
- function* getActivateAccountStrategy({ payload, }) {
2511
- const { callback } = payload, params = tslib.__rest(payload, ["callback"]);
2512
- yield effects.put(actions.setActivateStrategyState({ loading: true }));
2513
- try {
2514
- const strategy = yield effects.call(restApi.api.auth.getActivateAccountStrategy, params);
2515
- yield effects.put(actions.setActivateStrategyState({ strategy, loading: false, error: undefined }));
2516
- callback === null || callback === void 0 ? void 0 : callback(strategy);
2517
- }
2518
- catch (e) {
2519
- yield effects.put(actions.setActivateStrategyState({ loading: false, error: e.message }));
2520
- }
2521
- }
2522
- function* resendActivationEmailFunction({ payload }) {
2523
- yield effects.put(actions.setActivateState({ loading: true }));
2524
- try {
2525
- yield effects.call(restApi.api.auth.resendActivationEmail, { email: payload.email });
2526
- yield effects.put(actions.setActivateState({ loading: false, error: undefined, resentEmail: true }));
2527
- }
2528
- catch (e) {
2529
- yield effects.put(actions.setActivateState({ loading: false, error: e.message }));
2530
- }
2531
- }
2532
- function* activateSagas() {
2533
- yield effects.takeLeading(actions.activateAccount, activateAccount);
2534
- yield effects.takeLeading(actions.preActivateAccount, preActivateAccount);
2535
- yield effects.takeLeading(actions.getActivateAccountStrategy, getActivateAccountStrategy);
2536
- yield effects.takeLeading(actions.resendActivationEmail, resendActivationEmailFunction);
2537
- }
2538
-
2539
- function* acceptInvitation({ payload }) {
2540
- if (!payload.token || !payload.userId) {
2541
- yield effects.put(actions.setAcceptInvitationState({ error: undefined, step: exports.AcceptInvitationStep.invalid }));
2542
- return;
2543
- }
2544
- try {
2545
- yield effects.put(actions.setAcceptInvitationState({ error: undefined, step: exports.AcceptInvitationStep.pending }));
2546
- yield effects.call(restApi.api.auth.acceptInvitation, payload);
2547
- yield effects.put(actions.setState({
2548
- isAuthenticated: false,
2549
- user: null,
2550
- acceptInvitationState: { error: undefined, step: exports.AcceptInvitationStep.success },
2551
- }));
2552
- }
2553
- catch (e) {
2554
- yield effects.put(actions.setAcceptInvitationState({ step: exports.AcceptInvitationStep.failed, error: e.message }));
2555
- }
2556
- }
2557
- function* acceptInvitationSagas() {
2558
- yield effects.takeLeading(actions.acceptInvitation, acceptInvitation);
2559
- }
2560
-
2561
- exports.TeamStateKeys = void 0;
2562
- (function (TeamStateKeys) {
2563
- TeamStateKeys["USERS"] = "USERS";
2564
- TeamStateKeys["STATS"] = "STATS";
2565
- TeamStateKeys["UPDATE_USER"] = "UPDATE_USER";
2566
- TeamStateKeys["DELETE_USER"] = "DELETE_USER";
2567
- TeamStateKeys["RESEND_ACTIVATE_LINK"] = "RESEND_ACTIVATE_LINK";
2568
- TeamStateKeys["RESEND_INVITATION_LINK"] = "RESEND_INVITATION_LINK";
2569
- TeamStateKeys["ROLES_AND_PERMISSIONS"] = "ROLES_AND_PERMISSIONS";
2570
- TeamStateKeys["CREATE_TOKEN_LINK"] = "CREATE_TOKEN_LINK";
2571
- TeamStateKeys["GET_TOKEN_LINK"] = "GET_TOKEN_LINK";
2572
- TeamStateKeys["UPDATE_TOKEN_LINK"] = "UPDATE_TOKEN_LINK";
2573
- TeamStateKeys["DELETE_TOKEN_LINK"] = "DELETE_TOKEN_LINK";
2574
- TeamStateKeys["CONFIG_TOKEN_LINK"] = "CONFIG_TOKEN_LINK";
2575
- })(exports.TeamStateKeys || (exports.TeamStateKeys = {}));
2576
-
2577
- const selectTeamState = () => effects.select((_) => _[constants.authStoreName].teamState);
2578
- function* loadUsers({ payload }) {
2579
- var _a, _b, _c, _d;
2580
- const { silentLoading, callback } = payload;
2581
- const teamState = yield selectTeamState();
2582
- const pageSize = (_a = payload.pageSize) !== null && _a !== void 0 ? _a : teamState.pageSize;
2583
- const pageOffset = (_b = payload.pageOffset) !== null && _b !== void 0 ? _b : teamState.pageOffset;
2584
- const filter = (_c = payload.filter) !== null && _c !== void 0 ? _c : teamState.filter;
2585
- const sort = (_d = payload.sort) !== null && _d !== void 0 ? _d : teamState.sort;
2586
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.USERS, value: !silentLoading }));
2587
- yield effects.put(actions.setTeamState({
2588
- pageSize,
2589
- pageOffset,
2590
- filter,
2591
- sort,
2592
- }));
2593
- try {
2594
- const [{ items: users, totalPages, totalItems }, { items: roles }, { items: permissions }] = yield effects.all([
2595
- effects.call(restApi.api.teams.loadUsers, {
2596
- pageSize,
2597
- pageOffset,
2598
- filter,
2599
- sort,
2600
- }),
2601
- effects.call(restApi.api.teams.loadAvailableRoles),
2602
- effects.call(restApi.api.teams.loadAvailablePermissions),
2603
- ]);
2604
- yield effects.put(actions.setTeamState({ users, totalPages, totalItems, roles, permissions }));
2605
- callback === null || callback === void 0 ? void 0 : callback(users);
2606
- }
2607
- catch (e) {
2608
- yield effects.put(actions.setTeamError({ key: exports.TeamStateKeys.USERS, value: e.message }));
2609
- yield effects.put(actions.setTeamState({ totalPages: 0, users: [] }));
2610
- callback === null || callback === void 0 ? void 0 : callback(null, e);
2611
- }
2612
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.USERS, value: false }));
2613
- }
2614
- function* loadAllSubTenantsUsers({ payload, }) {
2615
- var _a, _b, _c, _d, _e;
2616
- const { silentLoading, callback } = payload;
2617
- const teamState = yield selectTeamState();
2618
- const _limit = (_a = payload._limit) !== null && _a !== void 0 ? _a : teamState.allUsersQueryParams._limit;
2619
- const _offset = (_b = payload._offset) !== null && _b !== void 0 ? _b : teamState.allUsersQueryParams._offset;
2620
- const _filter = (_c = payload._filter) !== null && _c !== void 0 ? _c : teamState.allUsersQueryParams._filter;
2621
- const _sortBy = (_d = payload._sortBy) !== null && _d !== void 0 ? _d : teamState.allUsersQueryParams._sortBy;
2622
- const _order = (_e = payload._order) !== null && _e !== void 0 ? _e : teamState.allUsersQueryParams._order;
2623
- const allUsersQueryParams = {
2624
- _limit: _limit || 20,
2625
- _offset: _offset || 0,
2626
- _filter: _filter || '',
2627
- _sortBy: _sortBy || 'name',
2628
- _order: _order || 'DESC',
2629
- };
2630
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.USERS, value: !silentLoading }));
2631
- yield effects.put(actions.setTeamState({
2632
- allUsersQueryParams,
2633
- }));
2634
- try {
2635
- const [{ items: users, _metadata: { totalPages, totalItems }, }, { items: roles }, { items: permissions },] = yield effects.all([
2636
- effects.call(restApi.api.subTenants.loadAllUsers, Object.assign({}, allUsersQueryParams)),
2637
- effects.call(restApi.api.teams.loadAvailableRoles),
2638
- effects.call(restApi.api.teams.loadAvailablePermissions),
2639
- ]);
2640
- yield effects.put(actions.setTeamState({
2641
- allUsers: users,
2642
- totalPages,
2643
- totalItems,
2644
- roles,
2645
- permissions,
2646
- }));
2647
- callback === null || callback === void 0 ? void 0 : callback(users);
2648
- }
2649
- catch (e) {
2650
- yield effects.put(actions.setTeamError({ key: exports.TeamStateKeys.USERS, value: e.message }));
2651
- yield effects.put(actions.setTeamState({ totalPages: 0, users: [] }));
2652
- callback === null || callback === void 0 ? void 0 : callback(null, e);
2653
- }
2654
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.USERS, value: false }));
2655
- }
2656
- function* loadRoles({ payload }) {
2657
- var _a, _b;
2658
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.ROLES_AND_PERMISSIONS, value: true }));
2659
- try {
2660
- const [{ items: roles }, { items: permissions }] = yield effects.all([
2661
- effects.call(restApi.api.teams.loadAvailableRoles),
2662
- effects.call(restApi.api.teams.loadAvailablePermissions),
2663
- ]);
2664
- yield effects.put(actions.setTeamState({ roles, permissions }));
2665
- (_a = payload === null || payload === void 0 ? void 0 : payload.callback) === null || _a === void 0 ? void 0 : _a.call(payload, { roles, permissions });
2666
- }
2667
- catch (e) {
2668
- (_b = payload === null || payload === void 0 ? void 0 : payload.callback) === null || _b === void 0 ? void 0 : _b.call(payload, null, e);
2669
- yield effects.put(actions.setTeamError({ key: exports.TeamStateKeys.ROLES_AND_PERMISSIONS, value: e.message }));
2670
- }
2671
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.ROLES_AND_PERMISSIONS, value: true }));
2672
- }
2673
- function* addUser({ payload }) {
2674
- const { callback } = payload, body = tslib.__rest(payload, ["callback"]);
2675
- const teamState = yield selectTeamState();
2676
- yield effects.put(actions.setTeamState({ addUserDialogState: Object.assign(Object.assign({}, teamState.addUserDialogState), { loading: true }) }));
2677
- try {
2678
- const res = yield effects.call(restApi.api.teams.addUser, body);
2679
- const { roles } = res, userWithoutRoleIds = tslib.__rest(res, ["roles"]);
2680
- const roleIds = roles.map((role) => role.id);
2681
- const newUser = Object.assign(Object.assign({}, userWithoutRoleIds), { roleIds });
2682
- callback === null || callback === void 0 ? void 0 : callback(newUser);
2683
- yield effects.put(actions.setTeamState({
2684
- users: [newUser, ...teamState.users],
2685
- addUserDialogState: { open: false, loading: false },
2686
- }));
2687
- }
2688
- catch (e) {
2689
- yield effects.put(actions.setTeamState({
2690
- addUserDialogState: Object.assign(Object.assign({}, teamState.addUserDialogState), { loading: false, error: e.message }),
2691
- }));
2692
- callback === null || callback === void 0 ? void 0 : callback(null, e.message);
2693
- }
2694
- }
2695
- function* addUserToSubTenants({ payload }) {
2696
- const { callback } = payload, body = tslib.__rest(payload, ["callback"]);
2697
- const teamState = yield selectTeamState();
2698
- yield effects.put(actions.setTeamState({ addUserDialogState: Object.assign(Object.assign({}, teamState.addUserDialogState), { loading: true }) }));
2699
- try {
2700
- yield effects.call(restApi.api.subTenants.addUserToTenantAndSubTenants, body);
2701
- const { items: users, _metadata: { totalPages, totalItems }, } = yield effects.call(restApi.api.subTenants.loadAllUsers, {
2702
- _limit: 20,
2703
- _offset: 0,
2704
- _filter: '',
2705
- _sortBy: 'name',
2706
- _order: 'DESC',
2707
- });
2708
- yield effects.put(actions.setTeamState({
2709
- allUsers: users,
2710
- totalPages,
2711
- totalItems,
2712
- addUserDialogState: { open: false, loading: false },
2713
- }));
2714
- callback === null || callback === void 0 ? void 0 : callback(null);
2715
- }
2716
- catch (e) {
2717
- yield effects.put(actions.setTeamState({
2718
- addUserDialogState: Object.assign(Object.assign({}, teamState.addUserDialogState), { loading: false, error: e.message }),
2719
- }));
2720
- callback === null || callback === void 0 ? void 0 : callback(null, e.message);
2721
- }
2722
- }
2723
- function* updateUser({ payload }) {
2724
- var _a;
2725
- const { callback, profileImage } = payload, body = tslib.__rest(payload, ["callback", "profileImage"]);
2726
- const { id: userId } = body;
2727
- const teamState = yield selectTeamState();
2728
- const oldUserData = teamState.users.find((user) => user.id === body.id);
2729
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.UPDATE_USER, value: userId || '' }));
2730
- yield effects.put(actions.setTeamState({ addUserDialogState: Object.assign(Object.assign({}, teamState.addUserDialogState), { loading: true }) }));
2731
- yield effects.put(actions.setTeamState({
2732
- addUserDialogState: Object.assign(Object.assign({}, teamState.addUserDialogState), { loading: true }),
2733
- users: teamState.users.map((user) => {
2734
- if (user.id === body.id) {
2735
- return Object.assign(Object.assign({}, user), body);
2736
- }
2737
- return user;
2738
- }),
2739
- }));
2740
- try {
2741
- if (oldUserData.roleIds.length > 0 && ((_a = body.roleIds) === null || _a === void 0 ? void 0 : _a.length) === 0) {
2742
- body.roleIds = [''];
2743
- }
2744
- const { item: newUser } = yield effects.call(restApi.api.teams.updateUser, body);
2745
- callback === null || callback === void 0 ? void 0 : callback(newUser);
2746
- yield effects.put(actions.setTeamState({
2747
- users: teamState.users.map((user) => user.id === newUser.id
2748
- ? Object.assign(Object.assign(Object.assign({}, user), newUser), { createdAt: user.createdAt, customData: user.customData, lastLogin: user.lastLogin }) : user),
2749
- }));
2750
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.UPDATE_USER, value: false }));
2751
- }
2752
- catch (e) {
2753
- yield effects.put(actions.setTeamState({
2754
- addUserDialogState: Object.assign(Object.assign({}, teamState.addUserDialogState), { loading: false, error: e.message }),
2755
- users: teamState.users.map((user) => (user.id === body.id ? Object.assign(Object.assign({}, user), oldUserData) : user)),
2756
- }));
2757
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.UPDATE_USER, value: false }));
2758
- callback === null || callback === void 0 ? void 0 : callback(null, e.message);
2759
- }
2760
- }
2761
- function* deleteUser({ payload }) {
2762
- const { callback } = payload, body = tslib.__rest(payload, ["callback"]);
2763
- const teamState = yield selectTeamState();
2764
- yield effects.put(actions.setTeamState({ deleteUserDialogState: Object.assign(Object.assign({}, teamState.deleteUserDialogState), { loading: true }) }));
2765
- try {
2766
- yield effects.call(restApi.api.teams.deleteUser, body);
2767
- callback === null || callback === void 0 ? void 0 : callback(true);
2768
- yield effects.put(actions.setTeamState({
2769
- users: teamState.users.filter((user) => user.id !== body.userId),
2770
- deleteUserDialogState: { open: false, loading: false },
2771
- }));
2772
- }
2773
- catch (e) {
2774
- yield effects.put(actions.setTeamState({
2775
- deleteUserDialogState: Object.assign(Object.assign({}, teamState.deleteUserDialogState), { loading: false, error: e.message }),
2776
- }));
2777
- callback === null || callback === void 0 ? void 0 : callback(null, e.message);
2778
- }
2779
- }
2780
- function* setUserRolesForSubTenants({ payload, }) {
2781
- const { callback, userId } = payload, body = tslib.__rest(payload, ["callback", "userId"]);
2782
- const teamState = yield selectTeamState();
2783
- yield effects.put(actions.setTeamState({ addUserDialogState: Object.assign(Object.assign({}, teamState.addUserDialogState), { loading: true }) }));
2784
- try {
2785
- yield effects.call(restApi.api.subTenants.setUserRolesForSubTenants, userId, body);
2786
- const updatedUser = teamState.allUsers.find((user) => user.id === userId);
2787
- if (updatedUser) {
2788
- updatedUser.tenants = updatedUser.tenants.map((tenant) => {
2789
- var _a;
2790
- return (Object.assign(Object.assign({}, tenant), { roles: ((_a = body.subTenantsRoles
2791
- .find((roleUpdate) => roleUpdate.tenantId === tenant.tenantId)) === null || _a === void 0 ? void 0 : _a.roleIds.map((roleId) => {
2792
- const role = teamState.roles.find(({ id }) => roleId === id);
2793
- return role;
2794
- }).filter((role) => role)) || tenant.roles }));
2795
- });
2796
- }
2797
- yield effects.put(actions.setTeamState({
2798
- allUsers: [
2799
- ...teamState.allUsers.filter((user) => user.id !== userId),
2800
- ...(updatedUser ? [updatedUser] : []),
2801
- ],
2802
- addUserDialogState: { open: false, loading: false },
2803
- }));
2804
- callback === null || callback === void 0 ? void 0 : callback(true);
2805
- }
2806
- catch (e) {
2807
- yield effects.put(actions.setTeamState({
2808
- addUserDialogState: Object.assign(Object.assign({}, teamState.addUserDialogState), { loading: false, error: e.message }),
2809
- }));
2810
- callback === null || callback === void 0 ? void 0 : callback(null, e.message);
2811
- }
2812
- }
2813
- function* deleteUserFromSubTenants({ payload }) {
2814
- const { callback } = payload, body = tslib.__rest(payload, ["callback"]);
2815
- const teamState = yield selectTeamState();
2816
- yield effects.put(actions.setTeamState({ deleteUserDialogState: Object.assign(Object.assign({}, teamState.deleteUserDialogState), { loading: true }) }));
2817
- try {
2818
- yield effects.call(restApi.api.subTenants.removeUserFromTenantAndSubTenants, body);
2819
- callback === null || callback === void 0 ? void 0 : callback(true);
2820
- yield effects.put(actions.setTeamState({
2821
- allUsers: teamState.allUsers.filter((user) => user.id !== body.userId && user.tenants.length === body.subTenants.length),
2822
- deleteUserDialogState: { open: false, loading: false },
2823
- }));
2824
- }
2825
- catch (e) {
2826
- yield effects.put(actions.setTeamState({
2827
- deleteUserDialogState: Object.assign(Object.assign({}, teamState.deleteUserDialogState), { loading: false, error: e.message }),
2828
- }));
2829
- callback === null || callback === void 0 ? void 0 : callback(null, e.message);
2830
- }
2831
- }
2832
- function* resendActivationLink({ payload }) {
2833
- const { callback } = payload, body = tslib.__rest(payload, ["callback"]);
2834
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.RESEND_ACTIVATE_LINK, value: body.userId }));
2835
- try {
2836
- yield effects.call(restApi.api.teams.resendActivationLink, body);
2837
- callback === null || callback === void 0 ? void 0 : callback(true);
2838
- }
2839
- catch (e) {
2840
- yield effects.put(actions.setTeamError({ key: exports.TeamStateKeys.RESEND_ACTIVATE_LINK, value: e.message }));
2841
- callback === null || callback === void 0 ? void 0 : callback(null, e.message);
2842
- }
2843
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.RESEND_ACTIVATE_LINK, value: false }));
2844
- }
2845
- function* resendInvitationLink({ payload }) {
2846
- const { callback } = payload, body = tslib.__rest(payload, ["callback"]);
2847
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.RESEND_INVITATION_LINK, value: body.email }));
2848
- try {
2849
- yield effects.call(restApi.api.teams.resendInvitationLink, body);
2850
- callback === null || callback === void 0 ? void 0 : callback(true);
2851
- }
2852
- catch (e) {
2853
- yield effects.put(actions.setTeamError({ key: exports.TeamStateKeys.RESEND_INVITATION_LINK, value: e.message }));
2854
- callback === null || callback === void 0 ? void 0 : callback(null, e.message);
2855
- }
2856
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.RESEND_INVITATION_LINK, value: false }));
2857
- }
2858
- function* getInvitationLinkConfig() {
2859
- yield effects.put(actions.setTeamError({ key: exports.TeamStateKeys.CONFIG_TOKEN_LINK, value: false }));
2860
- try {
2861
- const invitationLinkConfig = yield effects.call(restApi.api.teams.getInviteLinkConfiguration);
2862
- yield effects.put(actions.setTeamState({ inviteTokenState: Object.assign({}, invitationLinkConfig) }));
2863
- }
2864
- catch (e) {
2865
- yield effects.put(actions.setTeamError({ key: exports.TeamStateKeys.CONFIG_TOKEN_LINK, value: e.message }));
2866
- }
2867
- }
2868
- function* getInvitationLink() {
2869
- yield effects.put(actions.setTeamError({ key: exports.TeamStateKeys.GET_TOKEN_LINK, value: false }));
2870
- try {
2871
- yield effects.call(getInvitationLinkConfig);
2872
- const data = yield effects.call(restApi.api.teams.getInviteUserLink);
2873
- const { inviteTokenState } = yield selectTeamState();
2874
- yield effects.put(actions.setTeamState({ inviteTokenState: Object.assign(Object.assign({}, inviteTokenState), data) }));
2875
- }
2876
- catch (e) {
2877
- yield effects.put(actions.setTeamError({ key: exports.TeamStateKeys.GET_TOKEN_LINK, value: e.message }));
2878
- }
2879
- }
2880
- function* createInvitationLink({ payload: { callback }, }) {
2881
- yield effects.put(actions.setTeamError({ key: exports.TeamStateKeys.CREATE_TOKEN_LINK, value: false }));
2882
- const { inviteTokenState } = yield selectTeamState();
2883
- try {
2884
- const data = yield effects.call(restApi.api.teams.createInviteUserLink, { expiresInMinutes: 43200 });
2885
- yield effects.put(actions.setTeamState({ inviteTokenState: Object.assign(Object.assign({}, inviteTokenState), data) }));
2886
- callback === null || callback === void 0 ? void 0 : callback(data.token);
2887
- }
2888
- catch (e) {
2889
- callback === null || callback === void 0 ? void 0 : callback(null, e.message);
2890
- yield effects.put(actions.setTeamError({ key: exports.TeamStateKeys.CREATE_TOKEN_LINK, value: e.message }));
2891
- }
2892
- }
2893
- function* updateInvitationLink({ payload: { callback, expiresInMinutes, shouldSendEmail }, }) {
2894
- const { inviteTokenState } = yield selectTeamState();
2895
- yield effects.put(actions.setTeamError({ key: exports.TeamStateKeys.UPDATE_TOKEN_LINK, value: false }));
2896
- try {
2897
- const data = yield effects.call(restApi.api.teams.updateInviteUserLink, { expiresInMinutes, shouldSendEmail });
2898
- yield effects.put(actions.setTeamState({ inviteTokenState: Object.assign(Object.assign({}, inviteTokenState), data) }));
2899
- callback === null || callback === void 0 ? void 0 : callback(true);
2900
- }
2901
- catch (e) {
2902
- callback === null || callback === void 0 ? void 0 : callback(null, e.message);
2903
- yield effects.put(actions.setTeamError({ key: exports.TeamStateKeys.UPDATE_TOKEN_LINK, value: e.message }));
2904
- }
2905
- }
2906
- function* deleteInvitationLink({ payload }) {
2907
- const { callback } = payload !== null && payload !== void 0 ? payload : {};
2908
- yield effects.put(actions.setTeamError({ key: exports.TeamStateKeys.DELETE_TOKEN_LINK, value: false }));
2909
- try {
2910
- yield effects.call(restApi.api.teams.deleteInviteUserLink);
2911
- yield effects.put(actions.setTeamState({ inviteTokenState: undefined }));
2912
- callback === null || callback === void 0 ? void 0 : callback(true);
2913
- }
2914
- catch (e) {
2915
- yield effects.put(actions.setTeamError({ key: exports.TeamStateKeys.DELETE_TOKEN_LINK, value: e.message }));
2916
- callback === null || callback === void 0 ? void 0 : callback(false, e.message);
2917
- }
2918
- }
2919
- function* openAddUserDialog({ payload }) {
2920
- yield effects.put(actions.setTeamState({
2921
- addUserDialogState: Object.assign({ open: true, loading: false, error: false }, payload),
2922
- }));
2923
- }
2924
- function* closeAddUserDialog({ payload }) {
2925
- const teamState = yield selectTeamState();
2926
- const { addUserDialogState: { onClose }, } = teamState;
2927
- onClose === null || onClose === void 0 ? void 0 : onClose(payload);
2928
- yield effects.put(actions.setTeamState({
2929
- addUserDialogState: {
2930
- loading: false,
2931
- error: false,
2932
- open: false,
2933
- },
2934
- }));
2935
- }
2936
- function* openDeleteUserDialog({ payload }) {
2937
- yield effects.put(actions.setTeamState({
2938
- deleteUserDialogState: Object.assign({ open: true, loading: false, error: false }, payload),
2939
- }));
2940
- }
2941
- function* closeDeleteUserDialog({ payload }) {
2942
- const teamState = yield selectTeamState();
2943
- const { deleteUserDialogState: { onClose }, } = teamState;
2944
- onClose === null || onClose === void 0 ? void 0 : onClose(payload);
2945
- yield effects.put(actions.setTeamState({
2946
- deleteUserDialogState: {
2947
- loading: false,
2948
- error: false,
2949
- open: false,
2950
- },
2951
- }));
2952
- }
2953
- function* teamSagas() {
2954
- yield effects.takeLatest(actions.loadUsers, loadUsers);
2955
- yield effects.takeLatest(actions.loadAllSubTenantsUsers, loadAllSubTenantsUsers);
2956
- yield effects.takeLatest(actions.loadRoles, loadRoles);
2957
- yield effects.takeEvery(actions.addUser, addUser);
2958
- yield effects.takeEvery(actions.addUserToSubTenants, addUserToSubTenants);
2959
- yield effects.takeEvery(actions.updateUser, updateUser);
2960
- yield effects.takeEvery(actions.setUserRolesForSubTenants, setUserRolesForSubTenants);
2961
- yield effects.takeEvery(actions.deleteUser, deleteUser);
2962
- yield effects.takeEvery(actions.deleteUserFromSubTenants, deleteUserFromSubTenants);
2963
- yield effects.takeEvery(actions.resendActivationLink, resendActivationLink);
2964
- yield effects.takeEvery(actions.resendInvitationLink, resendInvitationLink);
2965
- yield effects.takeEvery(actions.getInvitationLink, getInvitationLink);
2966
- yield effects.takeEvery(actions.createInvitationLink, createInvitationLink);
2967
- yield effects.takeEvery(actions.updateInvitationLink, updateInvitationLink);
2968
- yield effects.takeEvery(actions.deleteInvitationLink, deleteInvitationLink);
2969
- yield effects.takeEvery(actions.openAddUserDialog, openAddUserDialog);
2970
- yield effects.takeEvery(actions.closeAddUserDialog, closeAddUserDialog);
2971
- yield effects.takeEvery(actions.openDeleteUserDialog, openDeleteUserDialog);
2972
- yield effects.takeEvery(actions.closeDeleteUserDialog, closeDeleteUserDialog);
2973
- }
2974
- /*********************************
2975
- * Preview Sagas
2976
- *********************************/
2977
- function* loadUsersMock({ payload }) {
2978
- var _a, _b, _c, _d;
2979
- const { silentLoading, callback } = payload;
2980
- const teamState = yield selectTeamState();
2981
- const pageSize = (_a = payload.pageSize) !== null && _a !== void 0 ? _a : teamState.pageSize;
2982
- const pageOffset = (_b = payload.pageOffset) !== null && _b !== void 0 ? _b : teamState.pageOffset;
2983
- const filter = (_c = payload.filter) !== null && _c !== void 0 ? _c : teamState.filter;
2984
- const sort = (_d = payload.sort) !== null && _d !== void 0 ? _d : teamState.sort;
2985
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.USERS, value: !silentLoading }));
2986
- yield effects.put(actions.setTeamState({
2987
- pageSize,
2988
- pageOffset,
2989
- filter,
2990
- sort,
2991
- }));
2992
- const totalPages = 2;
2993
- const totalItems = 10;
2994
- yield vendor_index.delay();
2995
- yield effects.put(actions.setTeamState({ users: usersDemo, totalPages, totalItems, roles: rolesDemo, permissions: permissionsDemo }));
2996
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.USERS, value: false }));
2997
- callback === null || callback === void 0 ? void 0 : callback(usersDemo);
2998
- }
2999
- function* loadAllSubTenantsUsersMock({ payload, }) {
3000
- var _a, _b, _c, _d, _e;
3001
- const { silentLoading, callback } = payload;
3002
- const teamState = yield selectTeamState();
3003
- const _limit = (_a = payload._limit) !== null && _a !== void 0 ? _a : teamState.allUsersQueryParams._limit;
3004
- const _offset = (_b = payload._offset) !== null && _b !== void 0 ? _b : teamState.allUsersQueryParams._offset;
3005
- const _filter = (_c = payload._filter) !== null && _c !== void 0 ? _c : teamState.allUsersQueryParams._filter;
3006
- const _sortBy = (_d = payload._sortBy) !== null && _d !== void 0 ? _d : teamState.allUsersQueryParams._sortBy;
3007
- const _order = (_e = payload._order) !== null && _e !== void 0 ? _e : teamState.allUsersQueryParams._order;
3008
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.USERS, value: !silentLoading }));
3009
- yield effects.put(actions.setTeamState({
3010
- allUsersQueryParams: {
3011
- _limit,
3012
- _offset,
3013
- _filter,
3014
- _sortBy,
3015
- _order,
3016
- },
3017
- }));
3018
- const totalPages = 2;
3019
- const totalItems = 10;
3020
- yield vendor_index.delay();
3021
- yield effects.put(actions.setTeamState({
3022
- allUsers: allUsersDemo,
3023
- totalPages,
3024
- totalItems,
3025
- roles: rolesDemo,
3026
- permissions: permissionsDemo,
3027
- }));
3028
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.USERS, value: false }));
3029
- callback === null || callback === void 0 ? void 0 : callback(allUsersDemo);
3030
- }
3031
- function* loadRolesMock({ payload }) {
3032
- var _a;
3033
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.ROLES_AND_PERMISSIONS, value: true }));
3034
- yield vendor_index.delay();
3035
- yield effects.put(actions.setTeamState({ roles: rolesDemo, permissions: permissionsDemo }));
3036
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.ROLES_AND_PERMISSIONS, value: true }));
3037
- (_a = payload === null || payload === void 0 ? void 0 : payload.callback) === null || _a === void 0 ? void 0 : _a.call(payload, { roles: rolesDemo, permissions: permissionsDemo });
3038
- }
3039
- function* addUserMock({ payload }) {
3040
- const { callback } = payload, body = tslib.__rest(payload, ["callback"]);
3041
- const teamState = yield selectTeamState();
3042
- yield effects.put(actions.setTeamState({ addUserDialogState: Object.assign(Object.assign({}, teamState.addUserDialogState), { loading: true }) }));
3043
- yield vendor_index.delay();
3044
- const newUser = Object.assign(Object.assign(Object.assign({}, userTeamDemo), body), { id: `${uuid.v4()}` });
3045
- callback === null || callback === void 0 ? void 0 : callback(newUser);
3046
- yield effects.put(actions.setTeamState({
3047
- users: [newUser, ...teamState.users],
3048
- addUserDialogState: { open: false, loading: false },
3049
- }));
3050
- }
3051
- function* addUserToSubTenantsMock({ payload }) {
3052
- const { callback } = payload, body = tslib.__rest(payload, ["callback"]);
3053
- const teamState = yield selectTeamState();
3054
- yield effects.put(actions.setTeamState({ addUserDialogState: Object.assign(Object.assign({}, teamState.addUserDialogState), { loading: true }) }));
3055
- yield vendor_index.delay();
3056
- const newUser = Object.assign(Object.assign(Object.assign({}, userTeamDemo), body), { id: `${uuid.v4()}` });
3057
- yield effects.put(actions.setTeamState({
3058
- users: [newUser, ...teamState.users],
3059
- addUserDialogState: { open: false, loading: false },
3060
- }));
3061
- callback === null || callback === void 0 ? void 0 : callback(null);
3062
- }
3063
- function* updateUserMock({ payload }) {
3064
- var _a;
3065
- const { callback, profileImage } = payload, body = tslib.__rest(payload, ["callback", "profileImage"]);
3066
- const { id: userId } = body;
3067
- const teamState = yield selectTeamState();
3068
- const oldUserData = teamState.users.find((user) => user.id === body.id);
3069
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.UPDATE_USER, value: userId || '' }));
3070
- yield effects.put(actions.setTeamState({ addUserDialogState: Object.assign(Object.assign({}, teamState.addUserDialogState), { loading: true }) }));
3071
- yield effects.put(actions.setTeamState({
3072
- addUserDialogState: Object.assign(Object.assign({}, teamState.addUserDialogState), { loading: true }),
3073
- users: teamState.users.map((user) => {
3074
- if (user.id === body.id) {
3075
- return Object.assign(Object.assign({}, user), body);
3076
- }
3077
- return user;
3078
- }),
3079
- }));
3080
- if (oldUserData.roleIds.length > 0 && ((_a = body.roleIds) === null || _a === void 0 ? void 0 : _a.length) === 0) {
3081
- body.roleIds = [''];
3082
- }
3083
- yield vendor_index.delay();
3084
- const newUser = Object.assign(Object.assign({}, oldUserData), body);
3085
- callback === null || callback === void 0 ? void 0 : callback(newUser);
3086
- yield effects.put(actions.setTeamState({
3087
- users: teamState.users.map((user) => user.id === newUser.id
3088
- ? Object.assign(Object.assign(Object.assign({}, user), newUser), { createdAt: user.createdAt, customData: user.customData, lastLogin: user.lastLogin }) : user),
3089
- }));
3090
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.UPDATE_USER, value: false }));
3091
- }
3092
- function* deleteUserMock({ payload }) {
3093
- const { callback } = payload, body = tslib.__rest(payload, ["callback"]);
3094
- const teamState = yield selectTeamState();
3095
- yield effects.put(actions.setTeamState({ deleteUserDialogState: Object.assign(Object.assign({}, teamState.deleteUserDialogState), { loading: true }) }));
3096
- yield vendor_index.delay();
3097
- callback === null || callback === void 0 ? void 0 : callback(true);
3098
- yield effects.put(actions.setTeamState({
3099
- users: teamState.users.filter((user) => user.id !== body.userId),
3100
- deleteUserDialogState: { open: false, loading: false },
3101
- }));
3102
- }
3103
- function* deleteUserFromSubTenantsMock({ payload }) {
3104
- const { callback } = payload, body = tslib.__rest(payload, ["callback"]);
3105
- const teamState = yield selectTeamState();
3106
- yield effects.put(actions.setTeamState({ deleteUserDialogState: Object.assign(Object.assign({}, teamState.deleteUserDialogState), { loading: true }) }));
3107
- yield vendor_index.delay();
3108
- callback === null || callback === void 0 ? void 0 : callback(true);
3109
- yield effects.put(actions.setTeamState({
3110
- allUsers: teamState.allUsers.filter((user) => user.id !== body.userId),
3111
- deleteUserDialogState: { open: false, loading: false },
3112
- }));
3113
- }
3114
- function* resendActivationLinkMock({ payload }) {
3115
- const { callback } = payload, body = tslib.__rest(payload, ["callback"]);
3116
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.RESEND_ACTIVATE_LINK, value: body.userId }));
3117
- yield vendor_index.delay();
3118
- callback === null || callback === void 0 ? void 0 : callback(true);
3119
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.RESEND_ACTIVATE_LINK, value: false }));
3120
- }
3121
- function* resendInvitationLinkMock({ payload }) {
3122
- const { callback } = payload, body = tslib.__rest(payload, ["callback"]);
3123
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.RESEND_INVITATION_LINK, value: body.email }));
3124
- yield vendor_index.delay();
3125
- callback === null || callback === void 0 ? void 0 : callback(true);
3126
- yield effects.put(actions.setTeamLoader({ key: exports.TeamStateKeys.RESEND_INVITATION_LINK, value: false }));
3127
- }
3128
- function* teamSagasMock() {
3129
- yield effects.takeLatest(actions.loadUsers, loadUsersMock);
3130
- yield effects.takeLatest(actions.loadAllSubTenantsUsers, loadAllSubTenantsUsersMock);
3131
- yield effects.takeLatest(actions.loadRoles, loadRolesMock);
3132
- yield effects.takeEvery(actions.addUser, addUserMock);
3133
- yield effects.takeEvery(actions.addUserToSubTenants, addUserToSubTenantsMock);
3134
- yield effects.takeEvery(actions.updateUser, updateUserMock);
3135
- yield effects.takeEvery(actions.deleteUser, deleteUserMock);
3136
- yield effects.takeEvery(actions.deleteUserFromSubTenants, deleteUserFromSubTenantsMock);
3137
- yield effects.takeEvery(actions.resendActivationLink, resendActivationLinkMock);
3138
- yield effects.takeEvery(actions.resendInvitationLink, resendInvitationLinkMock);
3139
- yield effects.takeEvery(actions.openAddUserDialog, openAddUserDialog);
3140
- yield effects.takeEvery(actions.closeAddUserDialog, closeAddUserDialog);
3141
- yield effects.takeEvery(actions.openDeleteUserDialog, openDeleteUserDialog);
3142
- yield effects.takeEvery(actions.closeDeleteUserDialog, closeDeleteUserDialog);
3143
- }
3144
-
3145
- function* loadSocialLoginsConfigurations() {
3146
- try {
3147
- yield effects.put(actions.setSocialLoginsState({ loading: true }));
3148
- const socialLoginsConfig = yield effects.call(restApi.api.auth.getSocialLoginProviders);
3149
- yield effects.put(actions.setSocialLoginsState({ socialLoginsConfig, loading: false, firstLoad: false }));
3150
- }
3151
- catch (e) {
3152
- yield effects.put(actions.setSocialLoginsState({ error: e.message, loading: false, firstLoad: false }));
3153
- }
3154
- }
3155
- function* loadSocialLoginsConfigurationsV2() {
3156
- try {
3157
- const context = yield effects.select((state) => state.root.context);
3158
- yield effects.put(actions.setSocialLoginsState({ loading: true }));
3159
- const socialLoginsConfigV2 = yield effects.call(restApi.api.auth.getSocialLoginProvidersV2);
3160
- const socialLoginsConfigWithFullUrl = socialLoginsConfigV2.map((_a) => {
3161
- var { authorizationUrl } = _a, config = tslib.__rest(_a, ["authorizationUrl"]);
3162
- const baseUrl = restApi.fetch.getBaseUrl(context, authorizationUrl !== null && authorizationUrl !== void 0 ? authorizationUrl : '');
3163
- return (Object.assign(Object.assign({}, config), { authorizationUrl: authorizationUrl ? `${baseUrl}${authorizationUrl}` : null }));
3164
- });
3165
- yield effects.put(actions.setSocialLoginsState({ socialLoginsConfigV2: socialLoginsConfigWithFullUrl, loading: false, firstLoad: false }));
3166
- }
3167
- catch (e) {
3168
- yield effects.put(actions.setSocialLoginsState({ error: e.message, loading: false, firstLoad: false }));
3169
- }
3170
- }
3171
- function* loginViaSocialLogin(_a) {
3172
- var _b, _c, _d;
3173
- var _e = _a.payload, { events, url } = _e, payload = tslib.__rest(_e, ["events", "url"]);
3174
- try {
3175
- yield effects.put(actions.setSocialLoginsState({ loading: true }));
3176
- const { email, isNewUser, userId, tenantId, name, } = yield effects.call(restApi.api.auth.loginViaSocialLogin, payload);
3177
- if (isNewUser) {
3178
- (_b = events === null || events === void 0 ? void 0 : events.signUpComplete) === null || _b === void 0 ? void 0 : _b.call(events, {
3179
- email,
3180
- url,
3181
- authenticationType: exports.AuthenticationTypes.SOCIAL_LOGIN,
3182
- createdAt: new Date(),
3183
- id: userId,
3184
- socialProvider: payload.provider,
3185
- tenantId,
3186
- });
3187
- (_c = events === null || events === void 0 ? void 0 : events.userVerified) === null || _c === void 0 ? void 0 : _c.call(events, {
3188
- email,
3189
- origin: exports.UserVeirifedOriginTypes.SOCIAL_LOGIN,
3190
- createdAt: new Date(),
3191
- id: userId,
3192
- url,
3193
- tenantId,
3194
- name,
3195
- });
3196
- }
3197
- if (email) {
3198
- localStorage.setItem('email', email);
3199
- }
3200
- yield effects.put(actions.setLoginState({ email, isNewUser }));
3201
- yield refreshToken();
3202
- yield effects.put(actions.setSocialLoginsState({ loading: false }));
3203
- }
3204
- catch (e) {
3205
- yield effects.put(actions.setSocialLoginsState({ loading: false, error: (_d = e.message) !== null && _d !== void 0 ? _d : 'Failed to authenticate', firstLoad: false }));
3206
- }
3207
- }
3208
- function* setSocialLoginError({ payload }) {
3209
- yield effects.put(actions.setSocialLoginsState({ error: payload.error, loading: false, firstLoad: false }));
3210
- }
3211
- function* socialLoginsSaga() {
3212
- yield effects.takeLeading(actions.loadSocialLoginsConfiguration, loadSocialLoginsConfigurations);
3213
- yield effects.takeLeading(actions.loadSocialLoginsConfigurationV2, loadSocialLoginsConfigurationsV2);
3214
- yield effects.takeLeading(actions.loginViaSocialLogin, loginViaSocialLogin);
3215
- yield effects.takeLatest(actions.setSocialLoginError, setSocialLoginError);
3216
- }
3217
-
3218
- exports.ApiStateKeys = void 0;
3219
- (function (ApiStateKeys) {
3220
- ApiStateKeys["LOAD_API_TOKENS"] = "LOAD_API_TOKENS";
3221
- ApiStateKeys["ADD_API_TOKEN"] = "ADD_API_TOKEN";
3222
- ApiStateKeys["DELETE_API_TOKEN"] = "DELETE_API_TOKEN";
3223
- })(exports.ApiStateKeys || (exports.ApiStateKeys = {}));
3224
-
3225
- function* loadApiTokensData({ payload: apiTokenType }) {
3226
- yield effects.put(actions.setApiTokensState({ apiTokenType }));
3227
- try {
3228
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.LOAD_API_TOKENS, value: true }));
3229
- if (apiTokenType === 'user') {
3230
- const apiTokensData = yield effects.call(restApi.api.auth.getUserApiTokensData);
3231
- yield effects.put(actions.setApiTokensState({ apiTokensDataUser: apiTokensData !== null && apiTokensData !== void 0 ? apiTokensData : [] }));
3232
- }
3233
- else {
3234
- const apiTenantTokensData = yield effects.call(restApi.api.auth.getTenantApiTokensData);
3235
- const { items: roles } = yield effects.call(restApi.api.teams.loadAvailableRoles);
3236
- const { items: permissions } = yield effects.call(restApi.api.teams.loadAvailablePermissions);
3237
- yield effects.put(actions.setApiTokensState({
3238
- apiTokensDataTenant: apiTenantTokensData !== null && apiTenantTokensData !== void 0 ? apiTenantTokensData : [],
3239
- roles: roles !== null && roles !== void 0 ? roles : [],
3240
- permissions: permissions !== null && permissions !== void 0 ? permissions : [],
3241
- }));
3242
- }
3243
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.LOAD_API_TOKENS, value: false }));
3244
- }
3245
- catch (e) {
3246
- yield effects.put(actions.setApiTokensError({ key: exports.ApiStateKeys.LOAD_API_TOKENS, value: e.message }));
3247
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.LOAD_API_TOKENS, value: false }));
3248
- }
3249
- }
3250
- function* addUserApiToken({ payload }) {
3251
- const { description, callback } = payload;
3252
- const { apiTokensDataUser } = yield effects.select((state) => state.auth.apiTokensState);
3253
- try {
3254
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.ADD_API_TOKEN, value: true }));
3255
- const data = yield effects.call(restApi.api.auth.updateUserApiTokensData, { description });
3256
- yield effects.put(actions.setApiTokensState({ showAddTokenDialog: false }));
3257
- yield effects.delay(200);
3258
- yield effects.put(actions.setApiTokensState({
3259
- apiTokensDataUser: [data, ...apiTokensDataUser],
3260
- successDialog: { open: true, secret: data.secret, clientId: data.clientId },
3261
- }));
3262
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.ADD_API_TOKEN, value: false }));
3263
- callback === null || callback === void 0 ? void 0 : callback(null);
3264
- }
3265
- catch (e) {
3266
- yield effects.put(actions.setApiTokensError({ key: exports.ApiStateKeys.ADD_API_TOKEN, value: e.message }));
3267
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.ADD_API_TOKEN, value: false }));
3268
- callback === null || callback === void 0 ? void 0 : callback(null, e.message);
3269
- }
3270
- }
3271
- function* addTenantApiToken({ payload }) {
3272
- const { description, roleIds, callback } = payload;
3273
- const { apiTokensDataTenant } = yield effects.select((state) => state.auth.apiTokensState);
3274
- try {
3275
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.ADD_API_TOKEN, value: true }));
3276
- const data = yield effects.call(restApi.api.auth.updateTenantApiTokensData, { description, roleIds });
3277
- yield effects.put(actions.setApiTokensState({ showAddTokenDialog: false }));
3278
- yield effects.delay(200);
3279
- yield effects.put(actions.setApiTokensState({
3280
- apiTokensDataTenant: [data, ...apiTokensDataTenant],
3281
- successDialog: { open: true, secret: data.secret, clientId: data.clientId },
3282
- }));
3283
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.ADD_API_TOKEN, value: false }));
3284
- callback === null || callback === void 0 ? void 0 : callback(null);
3285
- }
3286
- catch (e) {
3287
- yield effects.put(actions.setApiTokensError({ key: exports.ApiStateKeys.ADD_API_TOKEN, value: e.message }));
3288
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.ADD_API_TOKEN, value: false }));
3289
- callback === null || callback === void 0 ? void 0 : callback(null, e.message);
3290
- }
3291
- }
3292
- function* deleteUserApiToken({ payload }) {
3293
- const { apiTokensDataUser } = yield effects.select((state) => state.auth.apiTokensState);
3294
- try {
3295
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.DELETE_API_TOKEN, value: true }));
3296
- yield effects.call(restApi.api.auth.deleteUserApiToken, { tokenId: payload });
3297
- yield effects.put(actions.setApiTokensState({
3298
- apiTokensDataUser: apiTokensDataUser.filter((i) => i.clientId !== payload),
3299
- deleteTokenDialog: { open: false, clientId: payload },
3300
- }));
3301
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.DELETE_API_TOKEN, value: false }));
3302
- }
3303
- catch (e) {
3304
- yield effects.put(actions.setApiTokensError({ key: exports.ApiStateKeys.DELETE_API_TOKEN, value: e.message }));
3305
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.DELETE_API_TOKEN, value: false }));
3306
- }
3307
- }
3308
- function* deleteTenantApiToken({ payload }) {
3309
- const { apiTokensDataTenant } = yield effects.select((state) => state.auth.apiTokensState);
3310
- try {
3311
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.DELETE_API_TOKEN, value: true }));
3312
- yield effects.call(restApi.api.auth.deleteTenantApiToken, { tokenId: payload });
3313
- yield effects.put(actions.setApiTokensState({
3314
- apiTokensDataTenant: apiTokensDataTenant.filter((i) => i.clientId !== payload),
3315
- deleteTokenDialog: { open: false, clientId: payload },
3316
- }));
3317
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.DELETE_API_TOKEN, value: false }));
3318
- }
3319
- catch (e) {
3320
- yield effects.put(actions.setApiTokensError({ key: exports.ApiStateKeys.DELETE_API_TOKEN, value: e.message }));
3321
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.DELETE_API_TOKEN, value: false }));
3322
- }
3323
- }
3324
- function* loadApiTokens({ payload }) {
3325
- var _a, _b;
3326
- if (!(payload === null || payload === void 0 ? void 0 : payload.silentLoading)) {
3327
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.LOAD_API_TOKENS, value: true }));
3328
- }
3329
- try {
3330
- const [apiTokensDataUser = [], apiTokensDataTenant = []] = yield effects.all([
3331
- effects.call(restApi.api.auth.getUserApiTokensData),
3332
- effects.call(restApi.api.auth.getTenantApiTokensData),
3333
- ]);
3334
- yield effects.put(actions.setApiTokensState({
3335
- apiTokensDataUser,
3336
- apiTokensDataTenant,
3337
- }));
3338
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.LOAD_API_TOKENS, value: false }));
3339
- (_a = payload === null || payload === void 0 ? void 0 : payload.callback) === null || _a === void 0 ? void 0 : _a.call(payload, true);
3340
- }
3341
- catch (e) {
3342
- yield effects.put(actions.setApiTokensError({ key: exports.ApiStateKeys.LOAD_API_TOKENS, value: e.message }));
3343
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.LOAD_API_TOKENS, value: false }));
3344
- (_b = payload === null || payload === void 0 ? void 0 : payload.callback) === null || _b === void 0 ? void 0 : _b.call(payload, null, e);
3345
- }
3346
- }
3347
- function* apiTokensSaga() {
3348
- yield effects.takeLeading(actions.loadApiTokens, loadApiTokens);
3349
- yield effects.takeLeading(actions.initApiTokensData, loadApiTokensData);
3350
- yield effects.takeEvery(actions.addUserApiToken, addUserApiToken);
3351
- yield effects.takeEvery(actions.addTenantApiToken, addTenantApiToken);
3352
- yield effects.takeLatest(actions.deleteTenantApiToken, deleteTenantApiToken);
3353
- yield effects.takeLatest(actions.deleteUserApiToken, deleteUserApiToken);
3354
- }
3355
- /*********************************
3356
- * Preview Sagas
3357
- *********************************/
3358
- function* loadApiTokensDataMock({ payload: apiTokenType }) {
3359
- var _a;
3360
- yield effects.put(actions.setApiTokensState({ apiTokenType }));
3361
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.LOAD_API_TOKENS, value: true }));
3362
- if (apiTokenType === 'user') {
3363
- yield effects.delay(200);
3364
- const apiTokensData = [apiTokensDataDemo];
3365
- yield effects.put(actions.setApiTokensState({ apiTokensDataUser: apiTokensData !== null && apiTokensData !== void 0 ? apiTokensData : [] }));
3366
- }
3367
- else {
3368
- yield effects.delay(200);
3369
- yield effects.put(actions.setApiTokensState({
3370
- apiTokensDataTenant: (_a = [apiTokensDataTenantDemo]) !== null && _a !== void 0 ? _a : [],
3371
- roles: rolesDemo !== null && rolesDemo !== void 0 ? rolesDemo : [],
3372
- permissions: permissionsDemo !== null && permissionsDemo !== void 0 ? permissionsDemo : [],
3373
- }));
3374
- }
3375
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.LOAD_API_TOKENS, value: false }));
3376
- }
3377
- function* addTenantApiTokenMock({ payload }) {
3378
- const { description, roleIds, callback } = payload;
3379
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.ADD_API_TOKEN, value: true }));
3380
- const { apiTokensDataTenant } = yield effects.select((state) => state.auth.apiTokensState);
3381
- const newToken = Object.assign(Object.assign({}, apiTokensDataTenantDemo), { description,
3382
- roleIds, clientId: `CLIENT_ID_${uuid.v4()}` });
3383
- yield effects.put(actions.setApiTokensState({ showAddTokenDialog: false }));
3384
- yield effects.delay(200);
3385
- yield effects.put(actions.setApiTokensState({
3386
- apiTokensDataTenant: [...apiTokensDataTenant, newToken],
3387
- successDialog: { open: true, secret: newToken.secret, clientId: newToken.clientId },
3388
- }));
3389
- yield effects.delay(200);
3390
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.ADD_API_TOKEN, value: false }));
3391
- callback === null || callback === void 0 ? void 0 : callback(null);
3392
- }
3393
- function* deleteTenantApiTokenMock({ payload }) {
3394
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.DELETE_API_TOKEN, value: true }));
3395
- yield effects.delay(200);
3396
- const apiTokensDataTenant = [apiTokensDataTenantDemo];
3397
- yield effects.put(actions.setApiTokensState({
3398
- apiTokensDataTenant: apiTokensDataTenant.filter((i) => i.clientId !== payload),
3399
- deleteTokenDialog: { open: false, clientId: payload },
3400
- }));
3401
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.DELETE_API_TOKEN, value: false }));
3402
- }
3403
- function* loadApiTokensMock({ payload }) {
3404
- var _a;
3405
- if (!(payload === null || payload === void 0 ? void 0 : payload.silentLoading)) {
3406
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.LOAD_API_TOKENS, value: true }));
3407
- }
3408
- const apiTokensDataUser = [apiTokensDataDemo];
3409
- const apiTokensDataTenant = [apiTokensDataTenantDemo];
3410
- yield effects.put(actions.setApiTokensState({
3411
- apiTokensDataUser,
3412
- apiTokensDataTenant,
3413
- }));
3414
- yield effects.delay(200);
3415
- yield effects.put(actions.setApiTokensLoader({ key: exports.ApiStateKeys.LOAD_API_TOKENS, value: false }));
3416
- (_a = payload === null || payload === void 0 ? void 0 : payload.callback) === null || _a === void 0 ? void 0 : _a.call(payload, true);
3417
- }
3418
- function* apiTokensSagaMock() {
3419
- yield effects.takeLeading(actions.loadApiTokens, loadApiTokensMock);
3420
- yield effects.takeLeading(actions.initApiTokensData, loadApiTokensDataMock);
3421
- yield effects.takeEvery(actions.addTenantApiToken, addTenantApiTokenMock);
3422
- yield effects.takeLatest(actions.deleteTenantApiToken, deleteTenantApiTokenMock);
3423
- }
3424
-
3425
- function* loadSecurityPolicy() {
3426
- yield effects.put(actions.setSecurityPolicyGlobalState({ loading: true, error: null }));
3427
- try {
3428
- const policy = yield effects.call(restApi.api.auth.getGlobalSecurityPolicy);
3429
- yield effects.put(actions.setSecurityPolicyGlobalState({ policy, loading: false }));
3430
- }
3431
- catch (e) {
3432
- yield effects.put(actions.setSecurityPolicyGlobalState({ error: e.message, loading: false }));
3433
- }
3434
- yield effects.put(actions.loadSecurityPolicyMfa());
3435
- yield effects.put(actions.loadSecurityPolicyVendorMfa());
3436
- yield effects.put(actions.loadSecurityPolicyLockout());
3437
- yield effects.put(actions.loadSecurityPolicyCaptcha());
3438
- yield effects.put(actions.loadPublicAuthStrategiesPolicy());
3439
- }
3440
- function* loadPublicSecurityPolicy() {
3441
- yield effects.put(actions.setSecurityPolicyPublicState({ loading: true, error: null }));
3442
- try {
3443
- const policy = yield effects.call(restApi.api.auth.getVendorConfig);
3444
- yield effects.put(actions.setSecurityPolicyPublicState({ policy, loading: false }));
3445
- }
3446
- catch (e) {
3447
- yield effects.put(actions.setSecurityPolicyPublicState({ error: e.message, loading: false }));
3448
- }
3449
- }
3450
- function* loadPublicAuthStrategiesPolicy() {
3451
- yield effects.put(actions.setSecurityPolicyAuthStrategyPublicState({ loading: true, error: null }));
3452
- try {
3453
- const policy = yield effects.call(restApi.api.auth.getVendorPublicAuthStrategiesConfig);
3454
- yield effects.put(actions.setSecurityPolicyAuthStrategyPublicState({ policy, loading: false }));
3455
- }
3456
- catch (e) {
3457
- yield effects.put(actions.setSecurityPolicyAuthStrategyPublicState({ error: e.message, loading: false }));
3458
- }
3459
- }
3460
- function* loadSecurityPolicyMfa() {
3461
- yield effects.put(actions.setSecurityPolicyMfaState({ loading: true, error: null }));
3462
- try {
3463
- const policy = yield effects.call(restApi.api.auth.getMfaPolicy);
3464
- yield effects.put(actions.setSecurityPolicyMfaState({ policy, loading: false }));
3465
- }
3466
- catch (e) {
3467
- yield effects.put(actions.setSecurityPolicyMfaState({ error: e.message, loading: false }));
3468
- }
3469
- }
3470
- function* loadSecurityPolicyVendorMfa() {
3471
- yield effects.put(actions.setSecurityPolicyMfaState({ loading: true, error: null }));
3472
- try {
3473
- const policy = yield effects.call(restApi.api.auth.getVendorMfaPolicy);
3474
- yield effects.put(actions.setSecurityPolicyVendorMfaState({ policy, loading: false }));
3475
- }
3476
- catch (e) {
3477
- yield effects.put(actions.setSecurityPolicyVendorMfaState({ error: e.message, loading: false }));
3478
- }
3479
- }
3480
- function* saveSecurityPolicyMfa(_a) {
3481
- var _b = _a.payload, { callback } = _b, newSecurityPolicy = tslib.__rest(_b, ["callback"]);
3482
- yield effects.put(actions.setSecurityPolicyMfaState({ saving: true, error: null }));
3483
- try {
3484
- const policy = yield effects.call(restApi.api.auth.saveMfaPolicy, newSecurityPolicy);
3485
- yield effects.put(actions.setSecurityPolicyMfaState({ policy, saving: false }));
3486
- callback === null || callback === void 0 ? void 0 : callback(policy);
3487
- }
3488
- catch (e) {
3489
- yield effects.put(actions.setSecurityPolicyMfaState({ saving: false, error: e.message }));
3490
- callback === null || callback === void 0 ? void 0 : callback(null, e);
3491
- }
3492
- }
3493
- function* loadSecurityPolicyLockout() {
3494
- yield effects.put(actions.setSecurityPolicyLockoutState({ loading: true, error: null }));
3495
- try {
3496
- const policy = yield effects.call(restApi.api.auth.getLockoutPolicy);
3497
- yield effects.put(actions.setSecurityPolicyLockoutState({ policy, loading: false }));
3498
- }
3499
- catch (e) {
3500
- yield effects.put(actions.setSecurityPolicyLockoutState({ error: e.message, loading: false }));
3501
- }
3502
- }
3503
- function* saveSecurityPolicyLockout(_a) {
3504
- var _b = _a.payload, { callback } = _b, newSecurityPolicy = tslib.__rest(_b, ["callback"]);
3505
- yield effects.put(actions.setSecurityPolicyLockoutState({ saving: true, error: null }));
3506
- try {
3507
- const policy = yield effects.call(restApi.api.auth.saveLockoutPolicy, newSecurityPolicy);
3508
- yield effects.put(actions.setSecurityPolicyLockoutState({ policy, saving: false }));
3509
- callback === null || callback === void 0 ? void 0 : callback(policy);
3510
- }
3511
- catch (e) {
3512
- yield effects.put(actions.setSecurityPolicyLockoutState({ saving: false, error: e.message }));
3513
- callback === null || callback === void 0 ? void 0 : callback(null, e);
3514
- }
3515
- }
3516
- function* loadSecurityPolicyCaptcha() {
3517
- yield effects.put(actions.setSecurityPolicyLockoutState({ loading: true, error: null }));
3518
- try {
3519
- const policy = yield effects.call(restApi.api.auth.getCaptchaPolicy);
3520
- yield effects.put(actions.setSecurityPolicyCaptchaState({ policy, loading: false }));
3521
- }
3522
- catch (e) {
3523
- yield effects.put(actions.setSecurityPolicyCaptchaState({ error: e.message, loading: false }));
3524
- }
3525
- }
3526
- function* loadSecurityPolicyPasswordHistory() {
3527
- yield effects.put(actions.setSecurityPolicyPasswordHistoryState({ loading: true, error: null }));
3528
- try {
3529
- const policy = yield effects.call(restApi.api.auth.getPasswordHistoryPolicy);
3530
- yield effects.put(actions.setSecurityPolicyPasswordHistoryState({ policy, loading: false }));
3531
- }
3532
- catch (e) {
3533
- yield effects.put(actions.setSecurityPolicyPasswordHistoryState({ error: e.message, loading: false }));
3534
- }
3535
- }
3536
- function* saveSecurityPolicyPasswordHistory(_a) {
3537
- var _b = _a.payload, { callback } = _b, newSecurityPolicy = tslib.__rest(_b, ["callback"]);
3538
- yield effects.put(actions.setSecurityPolicyPasswordHistoryState({ saving: true, error: null }));
3539
- try {
3540
- const policy = yield effects.call(restApi.api.auth.savePasswordHistoryPolicy, newSecurityPolicy);
3541
- yield effects.put(actions.setSecurityPolicyPasswordHistoryState({ policy, saving: false }));
3542
- callback === null || callback === void 0 ? void 0 : callback(policy);
3543
- }
3544
- catch (e) {
3545
- yield effects.put(actions.setSecurityPolicyPasswordHistoryState({ saving: false, error: e.message }));
3546
- callback === null || callback === void 0 ? void 0 : callback(null, e);
3547
- }
3548
- }
3549
- function* loadVendorPasswordConfig() {
3550
- yield effects.put(actions.setSecurityPolicyPasswordState({ loading: true, error: null }));
3551
- try {
3552
- const policy = yield effects.call(restApi.api.auth.getPasswordConfigPolicy);
3553
- yield effects.put(actions.setSecurityPolicyPasswordState({ policy, loading: false }));
3554
- }
3555
- catch (e) {
3556
- yield effects.put(actions.setSecurityPolicyPasswordState({ error: e.message, loading: false }));
3557
- }
3558
- }
3559
- function* securityPolicySagas() {
3560
- yield effects.takeLeading(actions.loadSecurityPolicy, loadSecurityPolicy);
3561
- yield effects.takeEvery(actions.saveSecurityPolicyMfa, saveSecurityPolicyMfa);
3562
- yield effects.takeEvery(actions.loadSecurityPolicyMfa, loadSecurityPolicyMfa);
3563
- yield effects.takeEvery(actions.loadSecurityPolicyVendorMfa, loadSecurityPolicyVendorMfa);
3564
- yield effects.takeEvery(actions.saveSecurityPolicyLockout, saveSecurityPolicyLockout);
3565
- yield effects.takeEvery(actions.loadSecurityPolicyLockout, loadSecurityPolicyLockout);
3566
- yield effects.takeEvery(actions.loadSecurityPolicyCaptcha, loadSecurityPolicyCaptcha);
3567
- yield effects.takeEvery(actions.saveSecurityPolicyPasswordHistory, saveSecurityPolicyPasswordHistory);
3568
- yield effects.takeEvery(actions.loadSecurityPolicyPasswordHistory, loadSecurityPolicyPasswordHistory);
3569
- yield effects.takeEvery(actions.loadVendorPasswordConfig, loadVendorPasswordConfig);
3570
- yield effects.takeEvery(actions.loadPublicSecurityPolicy, loadPublicSecurityPolicy);
3571
- yield effects.takeEvery(actions.loadPublicAuthStrategiesPolicy, loadPublicAuthStrategiesPolicy);
3572
- }
3573
- /*********************************
3574
- * Preview Sagas
3575
- *********************************/
3576
- function* loadPublicSecurityPolicyMock() {
3577
- yield effects.put(actions.setSecurityPolicyPublicState({ loading: true, error: null }));
3578
- try {
3579
- yield effects.put(actions.setSecurityPolicyPublicState({ policy: publicSecurityPolicy, loading: false }));
3580
- }
3581
- catch (e) {
3582
- yield effects.put(actions.setSecurityPolicyPublicState({ error: e.message, loading: false }));
3583
- }
3584
- }
3585
- function* loadSecurityPolicyMock() {
3586
- yield effects.put(actions.setSecurityPolicyGlobalState({ loading: true, error: null }));
3587
- yield vendor_index.delay();
3588
- yield effects.put(actions.setSecurityPolicyGlobalState({ policy: policyDemo, loading: false }));
3589
- yield effects.put(actions.loadSecurityPolicyMfa());
3590
- yield effects.put(actions.loadSecurityPolicyVendorMfa());
3591
- yield effects.put(actions.loadSecurityPolicyLockout());
3592
- yield effects.put(actions.loadSecurityPolicyCaptcha());
3593
- }
3594
- function* loadSecurityPolicyMfaMock() {
3595
- yield effects.put(actions.setSecurityPolicyMfaState({ loading: true, error: null }));
3596
- yield vendor_index.delay();
3597
- yield effects.put(actions.setSecurityPolicyMfaState({ policy: policyMfaDemo, loading: false }));
3598
- }
3599
- function* loadSecurityPolicyVendorMfaMock() {
3600
- yield effects.put(actions.setSecurityPolicyVendorMfaState({ loading: true, error: null }));
3601
- yield vendor_index.delay();
3602
- yield effects.put(actions.setSecurityPolicyVendorMfaState({ policy: policyMfaDemo, loading: false }));
3603
- }
3604
- function* saveSecurityPolicyMfaMock(_a) {
3605
- var _b;
3606
- var _c = _a.payload, { callback } = _c, newSecurityPolicy = tslib.__rest(_c, ["callback"]);
3607
- yield effects.put(actions.setSecurityPolicyMfaState({ saving: true, error: null }));
3608
- const policy = Object.assign(Object.assign({}, policyLockoutDemo), { id: (_b = newSecurityPolicy.id) !== null && _b !== void 0 ? _b : policyLockoutDemo.id, enforceMFAType: newSecurityPolicy.enforceMFAType });
3609
- yield vendor_index.delay();
3610
- yield effects.put(actions.setSecurityPolicyMfaState({ policy, saving: false }));
3611
- callback === null || callback === void 0 ? void 0 : callback(policy);
3612
- }
3613
- function* loadSecurityPolicyLockoutMock() {
3614
- yield effects.put(actions.setSecurityPolicyLockoutState({ loading: true, error: null }));
3615
- yield vendor_index.delay();
3616
- yield effects.put(actions.setSecurityPolicyLockoutState({ policy: policyLockoutDemo, loading: false }));
3617
- }
3618
- function* saveSecurityPolicyLockoutMock(_a) {
3619
- var _b = _a.payload, { callback } = _b, newSecurityPolicy = tslib.__rest(_b, ["callback"]);
3620
- yield effects.put(actions.setSecurityPolicyLockoutState({ saving: true, error: null }));
3621
- yield vendor_index.delay();
3622
- const policy = Object.assign(Object.assign(Object.assign({}, newSecurityPolicy), policyLockoutDemo), { id: newSecurityPolicy.id ? newSecurityPolicy.id : policyLockoutDemo.id });
3623
- callback === null || callback === void 0 ? void 0 : callback(policy);
3624
- yield effects.put(actions.setSecurityPolicyLockoutState({ policy, saving: false }));
3625
- }
3626
- function* loadSecurityPolicyCaptchaMock() {
3627
- yield effects.put(actions.setSecurityPolicyLockoutState({ loading: true, error: null }));
3628
- yield vendor_index.delay();
3629
- yield effects.put(actions.setSecurityPolicyLockoutState({ policy: policyLockoutDemo, loading: false }));
3630
- }
3631
- function* loadSecurityPolicyPasswordHistoryMock() {
3632
- yield effects.put(actions.setSecurityPolicyPasswordHistoryState({ loading: true, error: null }));
3633
- yield vendor_index.delay();
3634
- yield effects.put(actions.setSecurityPolicyPasswordHistoryState({ policy: policyPasswordHistoryDemo, loading: false }));
3635
- }
3636
- function* saveSecurityPolicyPasswordHistoryMock(_a) {
3637
- var _b = _a.payload, { callback } = _b, newSecurityPolicy = tslib.__rest(_b, ["callback"]);
3638
- yield effects.put(actions.setSecurityPolicyPasswordHistoryState({ saving: true, error: null }));
3639
- yield vendor_index.delay();
3640
- const policy = Object.assign(Object.assign(Object.assign({}, newSecurityPolicy), policyPasswordHistoryDemo), { id: newSecurityPolicy.id ? newSecurityPolicy.id : policyPasswordHistoryDemo.id });
3641
- callback === null || callback === void 0 ? void 0 : callback(policy);
3642
- yield effects.put(actions.setSecurityPolicyPasswordHistoryState({ policy, saving: false }));
3643
- }
3644
- function* securityPolicySagasMock() {
3645
- yield effects.takeLeading(actions.loadSecurityPolicy, loadSecurityPolicyMock);
3646
- yield effects.takeEvery(actions.loadPublicSecurityPolicy, loadPublicSecurityPolicyMock);
3647
- yield effects.takeEvery(actions.saveSecurityPolicyMfa, saveSecurityPolicyMfaMock);
3648
- yield effects.takeEvery(actions.loadSecurityPolicyMfa, loadSecurityPolicyMfaMock);
3649
- yield effects.takeEvery(actions.loadSecurityPolicyVendorMfa, loadSecurityPolicyVendorMfaMock);
3650
- yield effects.takeEvery(actions.saveSecurityPolicyLockout, saveSecurityPolicyLockoutMock);
3651
- yield effects.takeEvery(actions.loadSecurityPolicyLockout, loadSecurityPolicyLockoutMock);
3652
- yield effects.takeEvery(actions.loadSecurityPolicyCaptcha, loadSecurityPolicyCaptchaMock);
3653
- yield effects.takeEvery(actions.saveSecurityPolicyPasswordHistory, saveSecurityPolicyPasswordHistoryMock);
3654
- yield effects.takeEvery(actions.loadSecurityPolicyPasswordHistory, loadSecurityPolicyPasswordHistoryMock);
3655
- }
3656
-
3657
- function* saveAccountSettings({ payload }) {
3658
- var _a, _b;
3659
- try {
3660
- yield effects.put(actions.setAccountSettingsState({ loading: true }));
3661
- const { accountSettingsState } = yield effects.select((state) => state.auth);
3662
- const { address, timezone, dateFormat, timeFormat, currency, logo } = accountSettingsState;
3663
- const body = yield effects.call(restApi.api.accountSettings.updateSettings, Object.assign({ address,
3664
- timezone,
3665
- dateFormat,
3666
- timeFormat,
3667
- currency,
3668
- logo }, payload));
3669
- yield effects.put(actions.setAccountSettingsState(Object.assign(Object.assign({}, body), { loading: false })));
3670
- (_a = payload.callback) === null || _a === void 0 ? void 0 : _a.call(payload, body);
3671
- }
3672
- catch (e) {
3673
- yield effects.put(actions.setAccountSettingsState({ loading: false, error: e.message }));
3674
- (_b = payload.callback) === null || _b === void 0 ? void 0 : _b.call(payload, null, e);
3675
- }
3676
- }
3677
- function* loadAccountSettings({ payload }) {
3678
- yield effects.put(actions.setAccountSettingsState({ loading: !(payload === null || payload === void 0 ? void 0 : payload.silentLoading), error: null }));
3679
- try {
3680
- const body = yield effects.call(restApi.api.accountSettings.getSettings);
3681
- yield effects.put(actions.setAccountSettingsState(Object.assign(Object.assign({}, body), { loading: false })));
3682
- }
3683
- catch (e) {
3684
- yield effects.put(actions.setAccountSettingsState({ loading: false, error: e.message }));
3685
- }
3686
- }
3687
- function* accountSettingsSaga() {
3688
- yield effects.takeLeading(actions.saveAccountSettings, saveAccountSettings);
3689
- yield effects.takeLeading(actions.loadAccountSettings, loadAccountSettings);
3690
- }
3691
- /*********************************
3692
- * Preview Sagas
3693
- *********************************/
3694
- function* saveAccountSettingsMock({ payload }) {
3695
- var _a;
3696
- yield effects.put(actions.setAccountSettingsState({ loading: true }));
3697
- yield vendor_index.delay();
3698
- const { accountSettingsState } = yield effects.select((state) => state.auth);
3699
- const { address, timezone, dateFormat, timeFormat, currency, logo } = accountSettingsState;
3700
- const body = Object.assign({ address,
3701
- timezone,
3702
- dateFormat,
3703
- timeFormat,
3704
- currency,
3705
- logo }, payload);
3706
- yield effects.put(actions.setAccountSettingsState(Object.assign(Object.assign({}, body), { loading: false })));
3707
- (_a = payload.callback) === null || _a === void 0 ? void 0 : _a.call(payload, body);
3708
- }
3709
- function* loadAccountSettingsMock({ payload }) {
3710
- yield effects.put(actions.setAccountSettingsState({ loading: !(payload === null || payload === void 0 ? void 0 : payload.silentLoading), error: null }));
3711
- yield vendor_index.delay();
3712
- yield effects.put(actions.setAccountSettingsState({
3713
- address: 'Tel-aviv',
3714
- timezone: 'Asia/Jerusalem',
3715
- dateFormat: 'DD/MM/YYYY',
3716
- timeFormat: 'HH:mm',
3717
- currency: 'USD',
3718
- loading: false,
3719
- }));
3720
- }
3721
- function* accountSettingsSagaMock() {
3722
- yield effects.takeLeading(actions.saveAccountSettings, saveAccountSettingsMock);
3723
- yield effects.takeLeading(actions.loadAccountSettings, loadAccountSettingsMock);
3724
- }
3725
-
3726
- function* switchTenant({ payload: { tenantId, callback } }) {
3727
- yield effects.put(actions.setState({ isLoading: true }));
3728
- try {
3729
- yield effects.call(restApi.api.tenants.switchTenant, { tenantId });
3730
- yield effects.call(refreshToken);
3731
- const callbackConsumed = callback === null || callback === void 0 ? void 0 : callback(true);
3732
- if (!callbackConsumed) {
3733
- yield effects.put(actions.setState({ isLoading: false }));
3734
- }
3735
- }
3736
- catch (e) {
3737
- yield effects.put(actions.setState({ isLoading: false }));
3738
- callback === null || callback === void 0 ? void 0 : callback(false, e);
3739
- }
3740
- }
3741
- function* loadTenants({ payload }) {
3742
- var _a, _b;
3743
- yield effects.put(actions.setTenantsState({ loading: true }));
3744
- try {
3745
- const tenants = yield effects.call(restApi.api.tenants.getTenants);
3746
- yield effects.put(actions.setTenantsState({ tenants, loading: false }));
3747
- (_a = payload === null || payload === void 0 ? void 0 : payload.callback) === null || _a === void 0 ? void 0 : _a.call(payload, []);
3748
- }
3749
- catch (e) {
3750
- (_b = payload === null || payload === void 0 ? void 0 : payload.callback) === null || _b === void 0 ? void 0 : _b.call(payload, [], e);
3751
- yield effects.put(actions.setTenantsState({ loading: false }));
3752
- }
3753
- }
3754
- function* loadSubTenants({ payload }) {
3755
- var _a, _b;
3756
- yield effects.put(actions.setTenantsState({ loading: true }));
3757
- try {
3758
- const subTenants = yield effects.call(restApi.api.tenants.getSubTenants);
3759
- yield effects.put(actions.setTenantsState({ subTenants, loading: false }));
3760
- (_a = payload === null || payload === void 0 ? void 0 : payload.callback) === null || _a === void 0 ? void 0 : _a.call(payload, true);
3761
- }
3762
- catch (e) {
3763
- yield effects.put(actions.setTenantsState({ loading: false }));
3764
- (_b = payload === null || payload === void 0 ? void 0 : payload.callback) === null || _b === void 0 ? void 0 : _b.call(payload, null, e);
3765
- }
3766
- }
3767
- function* loadSubTenantsTree({ payload }) {
3768
- var _a, _b;
3769
- yield effects.put(actions.setTenantsState({ loading: true }));
3770
- try {
3771
- const tenantTree = yield effects.call(restApi.api.tenants.getSubTenantsAsTree);
3772
- yield effects.put(actions.setTenantsState({ tenantTree, loading: false }));
3773
- (_a = payload === null || payload === void 0 ? void 0 : payload.callback) === null || _a === void 0 ? void 0 : _a.call(payload, true);
3774
- }
3775
- catch (e) {
3776
- yield effects.put(actions.setTenantsState({ loading: false }));
3777
- (_b = payload === null || payload === void 0 ? void 0 : payload.callback) === null || _b === void 0 ? void 0 : _b.call(payload, null, e);
3778
- }
3779
- }
3780
- function* tenantsSagas() {
3781
- yield effects.takeEvery(actions.loadTenants, loadTenants);
3782
- yield effects.takeEvery(actions.loadSubTenants, loadSubTenants);
3783
- yield effects.takeEvery(actions.switchTenant, switchTenant);
3784
- yield effects.takeEvery(actions.loadSubTenantsTree, loadSubTenantsTree);
3785
- }
3786
- /*********************************
3787
- * Preview Sagas
3788
- *********************************/
3789
- function* loadTenantsMock({}) {
3790
- yield effects.put(actions.setTenantsState({ loading: true }));
3791
- yield vendor_index.delay();
3792
- yield effects.put(actions.setTenantsState({ tenants: tenantsDemo, loading: false }));
3793
- }
3794
- function* tenantsSagasMock() {
3795
- yield effects.takeEvery(actions.loadTenants, loadTenantsMock);
3796
- }
3797
-
3798
- function* loadRolesAndPermissions({ payload }) {
3799
- var _a;
3800
- yield effects.put(actions.setRolesState({ loading: !((_a = payload === null || payload === void 0 ? void 0 : payload.silentLoading) !== null && _a !== void 0 ? _a : false), error: null }));
3801
- try {
3802
- const result = yield effects.all([
3803
- effects.call(restApi.api.roles.getRoles),
3804
- effects.call(restApi.api.roles.getPermissions),
3805
- effects.call(restApi.api.roles.getPermissionCategories),
3806
- ]);
3807
- const [roles, permissions, permissionCategories] = result;
3808
- yield effects.put(actions.setRolesState({ roles, permissions, permissionCategories, loading: false }));
3809
- }
3810
- catch (e) {
3811
- yield effects.put(actions.setRolesState({ error: e.message, loading: false }));
3812
- }
3813
- }
3814
- function* addRole(_a) {
3815
- var _b = _a.payload, { callback } = _b, body = tslib.__rest(_b, ["callback"]);
3816
- yield effects.put(actions.setRolesState({ saving: true }));
3817
- try {
3818
- const role = yield effects.call(restApi.api.roles.addRole, body);
3819
- const roles = yield effects.call(restApi.api.roles.getRoles);
3820
- yield effects.put(actions.loadRolesAndPermissions({ silentLoading: true }));
3821
- yield effects.put(actions.setRolesState({ roles, saving: false }));
3822
- callback === null || callback === void 0 ? void 0 : callback(role);
3823
- }
3824
- catch (e) {
3825
- yield effects.put(actions.setRolesState({ error: e.message, saving: false }));
3826
- callback === null || callback === void 0 ? void 0 : callback(null, e);
3827
- }
3828
- }
3829
- function* deleteRole(_a) {
3830
- var _b = _a.payload, { callback } = _b, body = tslib.__rest(_b, ["callback"]);
3831
- yield effects.put(actions.setRolesState({ saving: true }));
3832
- try {
3833
- yield effects.call(restApi.api.roles.deleteRole, body);
3834
- yield effects.put(actions.loadRolesAndPermissions({ silentLoading: true }));
3835
- yield effects.put(actions.setRolesState({ saving: false }));
3836
- callback === null || callback === void 0 ? void 0 : callback(true);
3837
- }
3838
- catch (e) {
3839
- yield effects.put(actions.setRolesState({ error: e.message, saving: false }));
3840
- callback === null || callback === void 0 ? void 0 : callback(false, e);
3841
- }
3842
- }
3843
- function* updateRole(_a) {
3844
- var _b = _a.payload, { callback } = _b, body = tslib.__rest(_b, ["callback"]);
3845
- yield effects.put(actions.setRolesState({ saving: true }));
3846
- try {
3847
- const role = yield effects.call(restApi.api.roles.updateRole, body);
3848
- yield effects.put(actions.loadRolesAndPermissions({ silentLoading: true }));
3849
- yield effects.put(actions.setRolesState({ saving: false }));
3850
- callback === null || callback === void 0 ? void 0 : callback(role);
3851
- }
3852
- catch (e) {
3853
- yield effects.put(actions.setRolesState({ error: e.message, saving: false }));
3854
- callback === null || callback === void 0 ? void 0 : callback(null, e);
3855
- }
3856
- }
3857
- function* attachPermissionsToRole(_a) {
3858
- var _b = _a.payload, { callback } = _b, body = tslib.__rest(_b, ["callback"]);
3859
- yield effects.put(actions.setRolesState({ saving: true }));
3860
- try {
3861
- const role = yield effects.call(restApi.api.roles.attachPermissionsToRole, body);
3862
- yield effects.put(actions.loadRolesAndPermissions({ silentLoading: true }));
3863
- yield effects.put(actions.setRolesState({ saving: false }));
3864
- callback === null || callback === void 0 ? void 0 : callback(role);
3865
- }
3866
- catch (e) {
3867
- yield effects.put(actions.setRolesState({ error: e.message, saving: false }));
3868
- callback === null || callback === void 0 ? void 0 : callback(null, e);
3869
- }
3870
- }
3871
- function* attachPermissionToRoles(_a) {
3872
- var _b = _a.payload, { callback } = _b, body = tslib.__rest(_b, ["callback"]);
3873
- yield effects.put(actions.setRolesState({ saving: true }));
3874
- try {
3875
- const permission = yield effects.call(restApi.api.roles.attachPermissionToRoles, body);
3876
- yield effects.put(actions.loadRolesAndPermissions({ silentLoading: true }));
3877
- yield effects.put(actions.setRolesState({ saving: false }));
3878
- callback === null || callback === void 0 ? void 0 : callback(permission);
3879
- }
3880
- catch (e) {
3881
- yield effects.put(actions.setRolesState({ error: e.message, saving: false }));
3882
- callback === null || callback === void 0 ? void 0 : callback(null, e);
3883
- }
3884
- }
3885
- function* rolesSagas() {
3886
- yield effects.takeLeading(actions.loadRolesAndPermissions, loadRolesAndPermissions);
3887
- yield effects.takeEvery(actions.addRole, addRole);
3888
- yield effects.takeEvery(actions.deleteRole, deleteRole);
3889
- yield effects.takeEvery(actions.updateRole, updateRole);
3890
- yield effects.takeEvery(actions.attachPermissionsToRole, attachPermissionsToRole);
3891
- yield effects.takeEvery(actions.attachPermissionToRoles, attachPermissionToRoles);
3892
- }
3893
-
3894
- function* resetPhoneNumber(_a) {
3895
- var _b = _a.payload, { callback } = _b, body = tslib.__rest(_b, ["callback"]);
3896
- yield effects.put(actions.setResetPhoneNumberState({ loading: true }));
3897
- try {
3898
- const res = yield effects.call(restApi.api.auth.resetPhoneNumber, body);
3899
- yield effects.put(actions.setResetPhoneNumberState({ loading: false, error: undefined, resetPhoneNumberToken: res.resetPhoneNumberToken, step: exports.ResetPhoneNumberStep.VerifyResetPhoneNumber }));
3900
- yield effects.put(actions.setLoginState({ email: body.email }));
3901
- }
3902
- catch (e) {
3903
- yield effects.put(actions.setResetPhoneNumberState({ loading: false, error: e.message }));
3904
- callback === null || callback === void 0 ? void 0 : callback(null, e);
3905
- }
3906
- }
3907
- function* verifyResetPhoneNumber(_a) {
3908
- var _b = _a.payload, { callback } = _b, body = tslib.__rest(_b, ["callback"]);
3909
- yield effects.put(actions.setResetPhoneNumberState({ loading: true }));
3910
- try {
3911
- const res = yield effects.call(restApi.api.auth.verifyResetPhoneNumber, body);
3912
- yield effects.put(actions.setResetPhoneNumberState({ loading: false, error: undefined, changePhoneNumberToken: res.changePhoneNumberToken, step: exports.ResetPhoneNumberStep.ChangePhoneNumber }));
3913
- callback === null || callback === void 0 ? void 0 : callback(true);
3914
- }
3915
- catch (e) {
3916
- yield effects.put(actions.setResetPhoneNumberState({ loading: false, error: e.message }));
3917
- callback === null || callback === void 0 ? void 0 : callback(null, e);
3918
- }
3919
- }
3920
- function* changePhoneNumber(_a) {
3921
- var _b = _a.payload, { callback } = _b, body = tslib.__rest(_b, ["callback"]);
3922
- yield effects.put(actions.setResetPhoneNumberState({ loading: true }));
3923
- try {
3924
- const { onRedirectTo, routes } = yield effects.select(({ auth: { onRedirectTo, routes } }) => ({ onRedirectTo, routes }));
3925
- yield effects.call(restApi.api.auth.changePhoneNumber, { phoneNumber: body.phoneNumber, changePhoneNumberToken: body.changePhoneNumberToken });
3926
- yield effects.put(actions.setLoginState({ step: exports.LoginStep.loginWithSmsOtc }));
3927
- yield effects.put(actions.passwordlessPreLogin({
3928
- type: restApi.AuthStrategyEnum.SmsCode,
3929
- email: body.email,
3930
- recaptchaToken: body.recaptchaToken,
3931
- }));
3932
- onRedirectTo(routes.loginUrl);
3933
- yield effects.put(actions.setResetPhoneNumberState({ loading: false }));
3934
- callback === null || callback === void 0 ? void 0 : callback(true);
3935
- }
3936
- catch (e) {
3937
- yield effects.put(actions.setResetPhoneNumberState({ loading: false, error: e.message }));
3938
- callback === null || callback === void 0 ? void 0 : callback(null, e);
3939
- }
3940
- }
3941
- function* resetPhoneNumberSagas() {
3942
- yield effects.takeLeading(actions.resetPhoneNumber, resetPhoneNumber);
3943
- yield effects.takeLeading(actions.verifyResetPhoneNumber, verifyResetPhoneNumber);
3944
- yield effects.takeLeading(actions.changePhoneNumber, changePhoneNumber);
3945
- }
3946
-
3947
- function* sagas() {
3948
- yield effects.all([
3949
- effects.call(loginSagas),
3950
- effects.call(activateSagas),
3951
- effects.call(acceptInvitationSagas),
3952
- effects.call(forgotPasswordSagas),
3953
- effects.call(resetPhoneNumberSagas),
3954
- effects.call(ssoSagas$1),
3955
- effects.call(ssoSagas),
3956
- effects.call(profileSagas),
3957
- effects.call(mfaSagas),
3958
- effects.call(teamSagas),
3959
- effects.call(socialLoginsSaga),
3960
- effects.call(signUpSaga),
3961
- effects.call(apiTokensSaga),
3962
- effects.call(securityPolicySagas),
3963
- effects.call(accountSettingsSaga),
3964
- effects.call(tenantsSagas),
3965
- effects.call(rolesSagas),
3966
- ]);
3967
- }
3968
- function* mockSagas() {
3969
- yield effects.all([
3970
- effects.call(loginSagasMock),
3971
- // call(activateSagas),
3972
- // call(acceptInvitationSagas),
3973
- // call(forgotPasswordSagas),
3974
- // call(socialLoginsSaga),
3975
- // call(signUpSaga),
3976
- effects.call(ssoSagasMock),
3977
- effects.call(profileSagasMock),
3978
- effects.call(mfaSagasMock),
3979
- effects.call(teamSagasMock),
3980
- effects.call(apiTokensSagaMock),
3981
- effects.call(securityPolicySagasMock),
3982
- effects.call(accountSettingsSagaMock),
3983
- effects.call(tenantsSagasMock),
3984
- ]);
3985
- }
3986
-
3987
- // export store
3988
- var authStore = {
3989
- sagas,
3990
- mockSagas,
3991
- storeName: constants.authStoreName,
3992
- initialState: initialState$1,
3993
- reducer,
3994
- actions,
3995
- };
3996
-
3997
- const initialState = {
3998
- context: undefined,
3999
- };
4000
- const { reducer: rootReducer } = toolkit.createSlice({
4001
- name: 'root',
4002
- initialState,
4003
- reducers: {
4004
- setContext: {
4005
- prepare: (context) => ({ payload: context }),
4006
- reducer: (state, { payload }) => {
4007
- restApi.ContextHolder.setContext(payload);
4008
- return Object.assign(Object.assign({}, state), { context: payload });
4009
- },
4010
- },
4011
- },
4012
- });
4013
- const createFronteggStore = (rootInitialState, storeHolder, previewMode = false, authInitialState, overrideInitialState, builderMode = false) => {
4014
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
4015
- const isSSR = typeof window === 'undefined';
4016
- let holder = storeHolder;
4017
- if (isSSR && storeHolder == null) {
4018
- throw Error('createFronteggStore(initState, storeHolder) failed, storeHolder must not be null in Server-Side rendering');
4019
- }
4020
- if (!holder) {
4021
- holder = window;
4022
- }
4023
- if (!holder.store) {
4024
- if (!previewMode && !builderMode) {
4025
- restApi.ContextHolder.setContext(rootInitialState.context);
4026
- }
4027
- const sagaMiddleware = createSagaMiddleware__default['default']();
4028
- const middleware = [
4029
- ...toolkit.getDefaultMiddleware({ thunk: false, immutableCheck: false, serializableCheck: false }),
4030
- sagaMiddleware,
4031
- ];
4032
- holder.store = toolkit.configureStore({
4033
- middleware,
4034
- preloadedState: {
4035
- root: Object.assign(Object.assign({}, rootInitialState), { previewMode }),
4036
- [authStore.storeName]: Object.assign(Object.assign(Object.assign(Object.assign({}, authStore.initialState), authInitialState), ((_a = overrideInitialState === null || overrideInitialState === void 0 ? void 0 : overrideInitialState.auth) !== null && _a !== void 0 ? _a : {})), { routes: Object.assign(Object.assign(Object.assign({}, authStore.initialState.routes), ((_b = authInitialState === null || authInitialState === void 0 ? void 0 : authInitialState.routes) !== null && _b !== void 0 ? _b : {})), ((_d = (_c = overrideInitialState === null || overrideInitialState === void 0 ? void 0 : overrideInitialState.auth) === null || _c === void 0 ? void 0 : _c.routes) !== null && _d !== void 0 ? _d : {})) }),
4037
- [audits_index['default'].storeName]: Object.assign(Object.assign(Object.assign({}, audits_index['default'].initialState), ((_e = overrideInitialState === null || overrideInitialState === void 0 ? void 0 : overrideInitialState.auditLogs) !== null && _e !== void 0 ? _e : {})), { auditLogsState: Object.assign(Object.assign({}, audits_index['default'].initialState.auditLogsState), ((_g = (_f = overrideInitialState === null || overrideInitialState === void 0 ? void 0 : overrideInitialState.auditLogs) === null || _f === void 0 ? void 0 : _f.auditLogsState) !== null && _g !== void 0 ? _g : {})), auditsMetadataState: Object.assign(Object.assign({}, audits_index['default'].initialState.auditsMetadataState), ((_j = (_h = overrideInitialState === null || overrideInitialState === void 0 ? void 0 : overrideInitialState.auditLogs) === null || _h === void 0 ? void 0 : _h.auditsMetadataState) !== null && _j !== void 0 ? _j : {})) }),
4038
- [saga.storeName]: Object.assign(Object.assign({}, saga.initialState), ((_k = overrideInitialState === null || overrideInitialState === void 0 ? void 0 : overrideInitialState.audits) !== null && _k !== void 0 ? _k : {})),
4039
- [connectivity_index['default'].storeName]: connectivity_index['default'].initialState,
4040
- [subscriptions_index['default'].storeName]: subscriptions_index['default'].initialState,
4041
- [vendor_index.vendorStore.storeName]: vendor_index.vendorStore.initialState,
4042
- },
4043
- reducer: toolkit.combineReducers({
4044
- root: rootReducer,
4045
- [authStore.storeName]: authStore.reducer,
4046
- [audits_index['default'].storeName]: audits_index['default'].reducer,
4047
- [saga.storeName]: saga.reducer,
4048
- [connectivity_index['default'].storeName]: connectivity_index['default'].reducer,
4049
- [subscriptions_index['default'].storeName]: subscriptions_index['default'].reducer,
4050
- [vendor_index.vendorStore.storeName]: vendor_index.vendorStore.reducer,
4051
- }),
4052
- });
4053
- const rootSaga = function* () {
4054
- yield effects.all([
4055
- effects.call(authStore.sagas),
4056
- effects.call(audits_index['default'].sagas),
4057
- effects.call(saga.sagas),
4058
- effects.call(connectivity_index['default'].sagas),
4059
- effects.call(subscriptions_index['default'].sagas),
4060
- effects.call(vendor_index.vendorStore.sagas),
4061
- ]);
4062
- };
4063
- const rootMockSaga = function* () {
4064
- yield effects.all([effects.call(authStore.mockSagas), effects.call(audits_index['default'].mockSagas), effects.call(subscriptions_index['default'].mockSagas)]);
4065
- };
4066
- if (previewMode) {
4067
- holder.store.destroy = sagaMiddleware.run(rootMockSaga).cancel;
4068
- holder.store.dispatch(actions.requestAuthorize(true));
4069
- }
4070
- else {
4071
- holder.store.destroy = sagaMiddleware.run(rootSaga).cancel;
4072
- }
4073
- }
4074
- return holder.store;
4075
- };
4076
-
4077
- exports.acceptInvitationState = acceptInvitationState;
4078
- exports.accountSettingsState = accountSettingsState;
4079
- exports.actions = actions;
4080
- exports.actions$1 = actions$g;
4081
- exports.actions$10 = actions$7;
4082
- exports.actions$11 = actions$6;
4083
- exports.actions$12 = actions$5;
4084
- exports.actions$13 = actions$4;
4085
- exports.actions$14 = actions$3;
4086
- exports.actions$15 = actions$2;
4087
- exports.actions$16 = actions$1;
4088
- exports.actions$2 = actions$f;
4089
- exports.actions$3 = actions$e;
4090
- exports.actions$4 = actions$d;
4091
- exports.actions$5 = actions$c;
4092
- exports.actions$6 = actions$b;
4093
- exports.actions$7 = actions$9;
4094
- exports.actions$8 = actions$a;
4095
- exports.actions$9 = actions$8;
4096
- exports.activateState = activateState;
4097
- exports.apiTokensState = apiTokensState;
4098
- exports.authStore = authStore;
4099
- exports.createFronteggStore = createFronteggStore;
4100
- exports.forgotPasswordState = forgotPasswordState;
4101
- exports.initialState = initialState$1;
4102
- exports.loginState = loginState;
4103
- exports.mfaState = mfaState;
4104
- exports.mockSagas = mockSagas;
4105
- exports.profileState = profileState;
4106
- exports.reducer = reducer;
4107
- exports.reducers = reducers$f;
4108
- exports.reducers$1 = reducers$e;
4109
- exports.reducers$10 = reducers$5;
4110
- exports.reducers$11 = reducers$4;
4111
- exports.reducers$12 = reducers$3;
4112
- exports.reducers$13 = reducers$2;
4113
- exports.reducers$14 = reducers$1;
4114
- exports.reducers$15 = reducers;
4115
- exports.reducers$2 = reducers$d;
4116
- exports.reducers$3 = reducers$c;
4117
- exports.reducers$4 = reducers$b;
4118
- exports.reducers$5 = reducers$a;
4119
- exports.reducers$6 = reducers$8;
4120
- exports.reducers$7 = reducers$9;
4121
- exports.reducers$8 = reducers$7;
4122
- exports.reducers$9 = reducers$6;
4123
- exports.resetPhoneNumberState = resetPhoneNumberState;
4124
- exports.rolesState = rolesState;
4125
- exports.sagas = sagas;
4126
- exports.securityPolicyState = securityPolicyState;
4127
- exports.signUpState = signUpState;
4128
- exports.socialLoginState = socialLoginState;
4129
- exports.ssoState = ssoState;
4130
- exports.teamState = teamState;
4131
- exports.tenantsState = tenantsState;