@firebase/auth 1.7.9 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (435) hide show
  1. package/README.md +32 -1
  2. package/dist/auth-public.d.ts +22 -10
  3. package/dist/auth.d.ts +22 -10
  4. package/dist/browser-cjs/{index-e2e765e6.js → index-b60d3212.js} +393 -176
  5. package/dist/browser-cjs/index-b60d3212.js.map +1 -0
  6. package/dist/browser-cjs/index.js +1 -1
  7. package/dist/browser-cjs/internal.js +1 -1
  8. package/dist/browser-cjs/src/api/account_management/mfa.d.ts +5 -1
  9. package/dist/browser-cjs/src/api/authentication/mfa.d.ts +5 -1
  10. package/dist/browser-cjs/src/api/authentication/sms.d.ts +5 -1
  11. package/dist/browser-cjs/src/api/index.d.ts +7 -3
  12. package/dist/browser-cjs/src/platform_browser/providers/phone.d.ts +7 -5
  13. package/dist/browser-cjs/src/platform_browser/recaptcha/recaptcha.d.ts +7 -0
  14. package/dist/browser-cjs/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +4 -4
  15. package/dist/browser-cjs/src/platform_browser/strategies/phone.d.ts +10 -6
  16. package/dist/cordova/auth-cordova-public.d.ts +7 -0
  17. package/dist/cordova/auth-cordova.d.ts +7 -0
  18. package/dist/cordova/index.js +6 -7
  19. package/dist/cordova/index.js.map +1 -1
  20. package/dist/cordova/internal.js +660 -985
  21. package/dist/cordova/internal.js.map +1 -1
  22. package/dist/cordova/popup_redirect-6fcd583a.js +9635 -0
  23. package/dist/cordova/popup_redirect-6fcd583a.js.map +1 -0
  24. package/dist/cordova/src/api/account_management/mfa.d.ts +5 -1
  25. package/dist/cordova/src/api/authentication/mfa.d.ts +5 -1
  26. package/dist/cordova/src/api/authentication/sms.d.ts +5 -1
  27. package/dist/cordova/src/api/index.d.ts +7 -3
  28. package/dist/cordova/src/platform_browser/providers/phone.d.ts +7 -5
  29. package/dist/cordova/src/platform_browser/recaptcha/recaptcha.d.ts +7 -0
  30. package/dist/cordova/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +4 -4
  31. package/dist/cordova/src/platform_browser/strategies/phone.d.ts +10 -6
  32. package/dist/{esm5/src/api/account_management/mfa.test.d.ts → cordova/test/integration/flows/recaptcha_enterprise.test.d.ts} +1 -1
  33. package/dist/esm2017/{index-68602d24.js → index-a7d5cfcc.js} +393 -176
  34. package/dist/esm2017/index-a7d5cfcc.js.map +1 -0
  35. package/dist/esm2017/index.js +1 -1
  36. package/dist/esm2017/internal.js +2 -2
  37. package/dist/esm2017/src/api/account_management/mfa.d.ts +5 -1
  38. package/dist/esm2017/src/api/authentication/mfa.d.ts +5 -1
  39. package/dist/esm2017/src/api/authentication/sms.d.ts +5 -1
  40. package/dist/esm2017/src/api/index.d.ts +7 -3
  41. package/dist/esm2017/src/platform_browser/providers/phone.d.ts +7 -5
  42. package/dist/esm2017/src/platform_browser/recaptcha/recaptcha.d.ts +7 -0
  43. package/dist/esm2017/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +4 -4
  44. package/dist/esm2017/src/platform_browser/strategies/phone.d.ts +10 -6
  45. package/dist/{esm5/src/api/account_management/email_and_password.test.d.ts → esm2017/test/integration/flows/recaptcha_enterprise.test.d.ts} +1 -1
  46. package/dist/index.webworker.js +7912 -0
  47. package/dist/index.webworker.js.map +1 -0
  48. package/dist/node/index.js +2 -3
  49. package/dist/node/index.js.map +1 -1
  50. package/dist/node/internal.js +555 -844
  51. package/dist/node/internal.js.map +1 -1
  52. package/dist/node/src/api/account_management/mfa.d.ts +5 -1
  53. package/dist/node/src/api/authentication/mfa.d.ts +5 -1
  54. package/dist/node/src/api/authentication/sms.d.ts +5 -1
  55. package/dist/node/src/api/index.d.ts +7 -3
  56. package/dist/node/src/platform_browser/providers/phone.d.ts +7 -5
  57. package/dist/node/src/platform_browser/recaptcha/recaptcha.d.ts +7 -0
  58. package/dist/node/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +4 -4
  59. package/dist/node/src/platform_browser/strategies/phone.d.ts +10 -6
  60. package/dist/node/test/integration/flows/recaptcha_enterprise.test.d.ts +17 -0
  61. package/dist/node/totp-ab108bed.js +7582 -0
  62. package/dist/node/totp-ab108bed.js.map +1 -0
  63. package/dist/node-esm/index.js +1 -2
  64. package/dist/node-esm/index.js.map +1 -1
  65. package/dist/node-esm/internal.js +2 -3
  66. package/dist/node-esm/internal.js.map +1 -1
  67. package/dist/node-esm/src/api/account_management/mfa.d.ts +5 -1
  68. package/dist/node-esm/src/api/authentication/mfa.d.ts +5 -1
  69. package/dist/node-esm/src/api/authentication/sms.d.ts +5 -1
  70. package/dist/node-esm/src/api/index.d.ts +7 -3
  71. package/dist/node-esm/src/platform_browser/providers/phone.d.ts +7 -5
  72. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha.d.ts +7 -0
  73. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +4 -4
  74. package/dist/node-esm/src/platform_browser/strategies/phone.d.ts +10 -6
  75. package/dist/{esm5/scripts/run_node_tests.d.ts → node-esm/test/integration/flows/recaptcha_enterprise.test.d.ts} +1 -1
  76. package/dist/node-esm/{totp-219bb96f.js → totp-f311e20a.js} +170 -33
  77. package/dist/node-esm/totp-f311e20a.js.map +1 -0
  78. package/dist/rn/index-4d73adbf.js +8575 -0
  79. package/dist/rn/index-4d73adbf.js.map +1 -0
  80. package/dist/rn/index.js +45 -55
  81. package/dist/rn/index.js.map +1 -1
  82. package/dist/rn/internal.js +1195 -1890
  83. package/dist/rn/internal.js.map +1 -1
  84. package/dist/rn/src/api/account_management/mfa.d.ts +5 -1
  85. package/dist/rn/src/api/authentication/mfa.d.ts +5 -1
  86. package/dist/rn/src/api/authentication/sms.d.ts +5 -1
  87. package/dist/rn/src/api/index.d.ts +7 -3
  88. package/dist/rn/src/platform_browser/providers/phone.d.ts +7 -5
  89. package/dist/rn/src/platform_browser/recaptcha/recaptcha.d.ts +7 -0
  90. package/dist/rn/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +4 -4
  91. package/dist/rn/src/platform_browser/strategies/phone.d.ts +10 -6
  92. package/dist/rn/test/integration/flows/recaptcha_enterprise.test.d.ts +17 -0
  93. package/dist/src/api/account_management/mfa.d.ts +5 -1
  94. package/dist/src/api/authentication/mfa.d.ts +5 -1
  95. package/dist/src/api/authentication/sms.d.ts +5 -1
  96. package/dist/src/api/index.d.ts +7 -3
  97. package/dist/src/platform_browser/providers/phone.d.ts +7 -5
  98. package/dist/src/platform_browser/recaptcha/recaptcha.d.ts +7 -0
  99. package/dist/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +4 -4
  100. package/dist/src/platform_browser/strategies/phone.d.ts +10 -6
  101. package/dist/test/integration/flows/recaptcha_enterprise.test.d.ts +17 -0
  102. package/dist/web-extension-cjs/index.js +1 -1
  103. package/dist/web-extension-cjs/internal.js +115 -147
  104. package/dist/web-extension-cjs/internal.js.map +1 -1
  105. package/dist/web-extension-cjs/{register-674a8250.js → register-17c71bd5.js} +284 -31
  106. package/dist/web-extension-cjs/register-17c71bd5.js.map +1 -0
  107. package/dist/web-extension-cjs/src/api/account_management/mfa.d.ts +5 -1
  108. package/dist/web-extension-cjs/src/api/authentication/mfa.d.ts +5 -1
  109. package/dist/web-extension-cjs/src/api/authentication/sms.d.ts +5 -1
  110. package/dist/web-extension-cjs/src/api/index.d.ts +7 -3
  111. package/dist/web-extension-cjs/src/platform_browser/providers/phone.d.ts +7 -5
  112. package/dist/web-extension-cjs/src/platform_browser/recaptcha/recaptcha.d.ts +7 -0
  113. package/dist/web-extension-cjs/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +4 -4
  114. package/dist/web-extension-cjs/src/platform_browser/strategies/phone.d.ts +10 -6
  115. package/dist/web-extension-cjs/test/integration/flows/recaptcha_enterprise.test.d.ts +17 -0
  116. package/dist/web-extension-esm2017/auth-web-extension-public.d.ts +7 -0
  117. package/dist/web-extension-esm2017/auth-web-extension.d.ts +7 -0
  118. package/dist/web-extension-esm2017/index.js +2 -2
  119. package/dist/web-extension-esm2017/internal.js +115 -147
  120. package/dist/web-extension-esm2017/internal.js.map +1 -1
  121. package/dist/web-extension-esm2017/{register-428f8789.js → register-77f1d56a.js} +281 -32
  122. package/dist/web-extension-esm2017/register-77f1d56a.js.map +1 -0
  123. package/dist/web-extension-esm2017/src/api/account_management/mfa.d.ts +5 -1
  124. package/dist/web-extension-esm2017/src/api/authentication/mfa.d.ts +5 -1
  125. package/dist/web-extension-esm2017/src/api/authentication/sms.d.ts +5 -1
  126. package/dist/web-extension-esm2017/src/api/index.d.ts +7 -3
  127. package/dist/web-extension-esm2017/src/platform_browser/providers/phone.d.ts +7 -5
  128. package/dist/web-extension-esm2017/src/platform_browser/recaptcha/recaptcha.d.ts +7 -0
  129. package/dist/web-extension-esm2017/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +4 -4
  130. package/dist/web-extension-esm2017/src/platform_browser/strategies/phone.d.ts +10 -6
  131. package/dist/web-extension-esm2017/test/integration/flows/recaptcha_enterprise.test.d.ts +17 -0
  132. package/internal/package.json +5 -3
  133. package/package.json +10 -11
  134. package/dist/browser-cjs/index-e2e765e6.js.map +0 -1
  135. package/dist/cordova/popup_redirect-abcbab4c.js +0 -11249
  136. package/dist/cordova/popup_redirect-abcbab4c.js.map +0 -1
  137. package/dist/esm2017/index-68602d24.js.map +0 -1
  138. package/dist/esm5/index-c0803b14.js +0 -12741
  139. package/dist/esm5/index-c0803b14.js.map +0 -1
  140. package/dist/esm5/index.cordova.d.ts +0 -32
  141. package/dist/esm5/index.d.ts +0 -37
  142. package/dist/esm5/index.doc.d.ts +0 -24
  143. package/dist/esm5/index.js +0 -7
  144. package/dist/esm5/index.js.map +0 -1
  145. package/dist/esm5/index.node.d.ts +0 -17
  146. package/dist/esm5/index.rn.d.ts +0 -40
  147. package/dist/esm5/index.shared.d.ts +0 -19
  148. package/dist/esm5/index.web-extension.d.ts +0 -31
  149. package/dist/esm5/index.webworker.d.ts +0 -21
  150. package/dist/esm5/internal/index.d.ts +0 -42
  151. package/dist/esm5/internal.js +0 -682
  152. package/dist/esm5/internal.js.map +0 -1
  153. package/dist/esm5/src/api/account_management/account.d.ts +0 -59
  154. package/dist/esm5/src/api/account_management/account.test.d.ts +0 -17
  155. package/dist/esm5/src/api/account_management/email_and_password.d.ts +0 -49
  156. package/dist/esm5/src/api/account_management/mfa.d.ts +0 -103
  157. package/dist/esm5/src/api/account_management/profile.d.ts +0 -29
  158. package/dist/esm5/src/api/account_management/profile.test.d.ts +0 -17
  159. package/dist/esm5/src/api/authentication/create_auth_uri.d.ts +0 -26
  160. package/dist/esm5/src/api/authentication/create_auth_uri.test.d.ts +0 -17
  161. package/dist/esm5/src/api/authentication/custom_token.d.ts +0 -26
  162. package/dist/esm5/src/api/authentication/custom_token.test.d.ts +0 -17
  163. package/dist/esm5/src/api/authentication/email_and_password.d.ts +0 -85
  164. package/dist/esm5/src/api/authentication/email_and_password.test.d.ts +0 -17
  165. package/dist/esm5/src/api/authentication/email_link.d.ts +0 -32
  166. package/dist/esm5/src/api/authentication/email_link.test.d.ts +0 -17
  167. package/dist/esm5/src/api/authentication/idp.d.ts +0 -40
  168. package/dist/esm5/src/api/authentication/idp.test.d.ts +0 -17
  169. package/dist/esm5/src/api/authentication/mfa.d.ts +0 -69
  170. package/dist/esm5/src/api/authentication/mfa.test.d.ts +0 -17
  171. package/dist/esm5/src/api/authentication/recaptcha.d.ts +0 -34
  172. package/dist/esm5/src/api/authentication/recaptcha.test.d.ts +0 -17
  173. package/dist/esm5/src/api/authentication/sign_up.d.ts +0 -34
  174. package/dist/esm5/src/api/authentication/sign_up.test.d.ts +0 -17
  175. package/dist/esm5/src/api/authentication/sms.d.ts +0 -50
  176. package/dist/esm5/src/api/authentication/sms.test.d.ts +0 -17
  177. package/dist/esm5/src/api/authentication/token.d.ts +0 -37
  178. package/dist/esm5/src/api/authentication/token.test.d.ts +0 -17
  179. package/dist/esm5/src/api/errors.d.ts +0 -128
  180. package/dist/esm5/src/api/index.d.ts +0 -97
  181. package/dist/esm5/src/api/index.test.d.ts +0 -17
  182. package/dist/esm5/src/api/password_policy/get_password_policy.d.ts +0 -48
  183. package/dist/esm5/src/api/password_policy/get_password_policy.test.d.ts +0 -17
  184. package/dist/esm5/src/api/project_config/get_project_config.d.ts +0 -25
  185. package/dist/esm5/src/api/project_config/get_project_config.test.d.ts +0 -17
  186. package/dist/esm5/src/core/action_code_url.d.ts +0 -73
  187. package/dist/esm5/src/core/action_code_url.test.d.ts +0 -17
  188. package/dist/esm5/src/core/auth/auth_event_manager.d.ts +0 -34
  189. package/dist/esm5/src/core/auth/auth_event_manager.test.d.ts +0 -17
  190. package/dist/esm5/src/core/auth/auth_impl.d.ts +0 -130
  191. package/dist/esm5/src/core/auth/auth_impl.test.d.ts +0 -17
  192. package/dist/esm5/src/core/auth/emulator.d.ts +0 -42
  193. package/dist/esm5/src/core/auth/emulator.test.d.ts +0 -17
  194. package/dist/esm5/src/core/auth/firebase_internal.d.ts +0 -35
  195. package/dist/esm5/src/core/auth/firebase_internal.test.d.ts +0 -17
  196. package/dist/esm5/src/core/auth/initialize.d.ts +0 -46
  197. package/dist/esm5/src/core/auth/initialize.test.d.ts +0 -17
  198. package/dist/esm5/src/core/auth/middleware.d.ts +0 -25
  199. package/dist/esm5/src/core/auth/middleware.test.d.ts +0 -17
  200. package/dist/esm5/src/core/auth/password_policy_impl.d.ts +0 -59
  201. package/dist/esm5/src/core/auth/password_policy_impl.test.d.ts +0 -17
  202. package/dist/esm5/src/core/auth/register.d.ts +0 -23
  203. package/dist/esm5/src/core/credentials/auth_credential.d.ts +0 -75
  204. package/dist/esm5/src/core/credentials/email.d.ts +0 -60
  205. package/dist/esm5/src/core/credentials/email.test.d.ts +0 -17
  206. package/dist/esm5/src/core/credentials/index.d.ts +0 -23
  207. package/dist/esm5/src/core/credentials/oauth.d.ts +0 -81
  208. package/dist/esm5/src/core/credentials/oauth.test.d.ts +0 -17
  209. package/dist/esm5/src/core/credentials/phone.d.ts +0 -52
  210. package/dist/esm5/src/core/credentials/phone.test.d.ts +0 -17
  211. package/dist/esm5/src/core/credentials/saml.d.ts +0 -52
  212. package/dist/esm5/src/core/credentials/saml.test.d.ts +0 -17
  213. package/dist/esm5/src/core/errors.d.ts +0 -325
  214. package/dist/esm5/src/core/errors.test.d.ts +0 -17
  215. package/dist/esm5/src/core/index.d.ts +0 -230
  216. package/dist/esm5/src/core/persistence/in_memory.d.ts +0 -35
  217. package/dist/esm5/src/core/persistence/in_memory.test.d.ts +0 -17
  218. package/dist/esm5/src/core/persistence/index.d.ts +0 -41
  219. package/dist/esm5/src/core/persistence/persistence_user_manager.d.ts +0 -45
  220. package/dist/esm5/src/core/persistence/persistence_user_manager.test.d.ts +0 -17
  221. package/dist/esm5/src/core/providers/email.d.ts +0 -83
  222. package/dist/esm5/src/core/providers/email.test.d.ts +0 -17
  223. package/dist/esm5/src/core/providers/facebook.d.ts +0 -93
  224. package/dist/esm5/src/core/providers/facebook.test.d.ts +0 -17
  225. package/dist/esm5/src/core/providers/federated.d.ts +0 -64
  226. package/dist/esm5/src/core/providers/federated.test.d.ts +0 -17
  227. package/dist/esm5/src/core/providers/github.d.ts +0 -89
  228. package/dist/esm5/src/core/providers/github.test.d.ts +0 -17
  229. package/dist/esm5/src/core/providers/google.d.ts +0 -96
  230. package/dist/esm5/src/core/providers/google.test.d.ts +0 -17
  231. package/dist/esm5/src/core/providers/oauth.d.ts +0 -151
  232. package/dist/esm5/src/core/providers/oauth.test.d.ts +0 -17
  233. package/dist/esm5/src/core/providers/saml.d.ts +0 -62
  234. package/dist/esm5/src/core/providers/saml.test.d.ts +0 -17
  235. package/dist/esm5/src/core/providers/twitter.d.ts +0 -103
  236. package/dist/esm5/src/core/providers/twitter.test.d.ts +0 -17
  237. package/dist/esm5/src/core/strategies/abstract_popup_redirect_operation.d.ts +0 -44
  238. package/dist/esm5/src/core/strategies/abstract_popup_redirect_operation.test.d.ts +0 -17
  239. package/dist/esm5/src/core/strategies/action_code_settings.d.ts +0 -19
  240. package/dist/esm5/src/core/strategies/action_code_settings.test.d.ts +0 -17
  241. package/dist/esm5/src/core/strategies/anonymous.d.ts +0 -32
  242. package/dist/esm5/src/core/strategies/anonymous.test.d.ts +0 -17
  243. package/dist/esm5/src/core/strategies/credential.d.ts +0 -64
  244. package/dist/esm5/src/core/strategies/credential.test.d.ts +0 -17
  245. package/dist/esm5/src/core/strategies/custom_token.d.ts +0 -37
  246. package/dist/esm5/src/core/strategies/custom_token.test.d.ts +0 -17
  247. package/dist/esm5/src/core/strategies/email.d.ts +0 -104
  248. package/dist/esm5/src/core/strategies/email.test.d.ts +0 -17
  249. package/dist/esm5/src/core/strategies/email_and_password.d.ts +0 -139
  250. package/dist/esm5/src/core/strategies/email_and_password.test.d.ts +0 -17
  251. package/dist/esm5/src/core/strategies/email_link.d.ts +0 -107
  252. package/dist/esm5/src/core/strategies/email_link.test.d.ts +0 -17
  253. package/dist/esm5/src/core/strategies/idp.d.ts +0 -32
  254. package/dist/esm5/src/core/strategies/idp.test.d.ts +0 -17
  255. package/dist/esm5/src/core/strategies/redirect.d.ts +0 -36
  256. package/dist/esm5/src/core/strategies/redirect.test.d.ts +0 -17
  257. package/dist/esm5/src/core/user/account_info.d.ts +0 -68
  258. package/dist/esm5/src/core/user/account_info.test.d.ts +0 -17
  259. package/dist/esm5/src/core/user/additional_user_info.d.ts +0 -31
  260. package/dist/esm5/src/core/user/additional_user_info.test.d.ts +0 -17
  261. package/dist/esm5/src/core/user/id_token_result.d.ts +0 -48
  262. package/dist/esm5/src/core/user/id_token_result.test.d.ts +0 -17
  263. package/dist/esm5/src/core/user/invalidation.d.ts +0 -18
  264. package/dist/esm5/src/core/user/invalidation.test.d.ts +0 -17
  265. package/dist/esm5/src/core/user/link_unlink.d.ts +0 -30
  266. package/dist/esm5/src/core/user/link_unlink.test.d.ts +0 -17
  267. package/dist/esm5/src/core/user/proactive_refresh.d.ts +0 -34
  268. package/dist/esm5/src/core/user/proactive_refresh.test.d.ts +0 -17
  269. package/dist/esm5/src/core/user/reauthenticate.d.ts +0 -20
  270. package/dist/esm5/src/core/user/reauthenticate.test.d.ts +0 -17
  271. package/dist/esm5/src/core/user/reload.d.ts +0 -29
  272. package/dist/esm5/src/core/user/reload.test.d.ts +0 -17
  273. package/dist/esm5/src/core/user/token_manager.d.ts +0 -50
  274. package/dist/esm5/src/core/user/token_manager.test.d.ts +0 -17
  275. package/dist/esm5/src/core/user/user_credential_impl.d.ts +0 -37
  276. package/dist/esm5/src/core/user/user_credential_impl.test.d.ts +0 -17
  277. package/dist/esm5/src/core/user/user_impl.d.ts +0 -74
  278. package/dist/esm5/src/core/user/user_impl.test.d.ts +0 -17
  279. package/dist/esm5/src/core/user/user_metadata.d.ts +0 -27
  280. package/dist/esm5/src/core/util/assert.d.ts +0 -94
  281. package/dist/esm5/src/core/util/assert.test.d.ts +0 -17
  282. package/dist/esm5/src/core/util/browser.d.ts +0 -50
  283. package/dist/esm5/src/core/util/browser.test.d.ts +0 -17
  284. package/dist/esm5/src/core/util/delay.d.ts +0 -31
  285. package/dist/esm5/src/core/util/delay.test.d.ts +0 -17
  286. package/dist/esm5/src/core/util/emulator.d.ts +0 -18
  287. package/dist/esm5/src/core/util/emulator.test.d.ts +0 -17
  288. package/dist/esm5/src/core/util/event_id.d.ts +0 -17
  289. package/dist/esm5/src/core/util/event_id.test.d.ts +0 -17
  290. package/dist/esm5/src/core/util/fetch_provider.d.ts +0 -25
  291. package/dist/esm5/src/core/util/handler.d.ts +0 -20
  292. package/dist/esm5/src/core/util/instantiator.d.ts +0 -28
  293. package/dist/esm5/src/core/util/instantiator.test.d.ts +0 -17
  294. package/dist/esm5/src/core/util/location.d.ts +0 -19
  295. package/dist/esm5/src/core/util/log.d.ts +0 -23
  296. package/dist/esm5/src/core/util/navigator.d.ts +0 -21
  297. package/dist/esm5/src/core/util/providers.d.ts +0 -23
  298. package/dist/esm5/src/core/util/resolver.d.ts +0 -25
  299. package/dist/esm5/src/core/util/time.d.ts +0 -17
  300. package/dist/esm5/src/core/util/validate_origin.d.ts +0 -18
  301. package/dist/esm5/src/core/util/validate_origin.test.d.ts +0 -17
  302. package/dist/esm5/src/core/util/version.d.ts +0 -31
  303. package/dist/esm5/src/core/util/version.test.d.ts +0 -17
  304. package/dist/esm5/src/index.d.ts +0 -18
  305. package/dist/esm5/src/mfa/assertions/totp.d.ts +0 -124
  306. package/dist/esm5/src/mfa/assertions/totp.test.d.ts +0 -17
  307. package/dist/esm5/src/mfa/index.d.ts +0 -18
  308. package/dist/esm5/src/mfa/mfa_assertion.d.ts +0 -27
  309. package/dist/esm5/src/mfa/mfa_error.d.ts +0 -35
  310. package/dist/esm5/src/mfa/mfa_info.d.ts +0 -36
  311. package/dist/esm5/src/mfa/mfa_info.test.d.ts +0 -17
  312. package/dist/esm5/src/mfa/mfa_resolver.d.ts +0 -41
  313. package/dist/esm5/src/mfa/mfa_resolver.test.d.ts +0 -17
  314. package/dist/esm5/src/mfa/mfa_session.d.ts +0 -39
  315. package/dist/esm5/src/mfa/mfa_session.test.d.ts +0 -17
  316. package/dist/esm5/src/mfa/mfa_user.d.ts +0 -38
  317. package/dist/esm5/src/mfa/mfa_user.test.d.ts +0 -17
  318. package/dist/esm5/src/model/application_verifier.d.ts +0 -23
  319. package/dist/esm5/src/model/auth.d.ts +0 -87
  320. package/dist/esm5/src/model/enum_maps.d.ts +0 -98
  321. package/dist/esm5/src/model/enums.d.ts +0 -74
  322. package/dist/esm5/src/model/id_token.d.ts +0 -87
  323. package/dist/esm5/src/model/password_policy.d.ts +0 -111
  324. package/dist/esm5/src/model/popup_redirect.d.ts +0 -94
  325. package/dist/esm5/src/model/public_types.d.ts +0 -1285
  326. package/dist/esm5/src/model/user.d.ts +0 -83
  327. package/dist/esm5/src/platform_browser/auth.test.d.ts +0 -17
  328. package/dist/esm5/src/platform_browser/auth_window.d.ts +0 -37
  329. package/dist/esm5/src/platform_browser/iframe/gapi.d.ts +0 -19
  330. package/dist/esm5/src/platform_browser/iframe/gapi.iframes.d.ts +0 -47
  331. package/dist/esm5/src/platform_browser/iframe/gapi.test.d.ts +0 -17
  332. package/dist/esm5/src/platform_browser/iframe/iframe.d.ts +0 -18
  333. package/dist/esm5/src/platform_browser/iframe/iframe.test.d.ts +0 -17
  334. package/dist/esm5/src/platform_browser/index.d.ts +0 -27
  335. package/dist/esm5/src/platform_browser/load_js.d.ts +0 -29
  336. package/dist/esm5/src/platform_browser/load_js.test.d.ts +0 -17
  337. package/dist/esm5/src/platform_browser/messagechannel/index.d.ts +0 -87
  338. package/dist/esm5/src/platform_browser/messagechannel/promise.d.ts +0 -33
  339. package/dist/esm5/src/platform_browser/messagechannel/promise.test.d.ts +0 -17
  340. package/dist/esm5/src/platform_browser/messagechannel/receiver.d.ts +0 -63
  341. package/dist/esm5/src/platform_browser/messagechannel/receiver.test.d.ts +0 -17
  342. package/dist/esm5/src/platform_browser/messagechannel/sender.d.ts +0 -46
  343. package/dist/esm5/src/platform_browser/messagechannel/sender.test.d.ts +0 -17
  344. package/dist/esm5/src/platform_browser/mfa/assertions/phone.d.ts +0 -59
  345. package/dist/esm5/src/platform_browser/mfa/assertions/phone.test.d.ts +0 -17
  346. package/dist/esm5/src/platform_browser/persistence/browser.d.ts +0 -27
  347. package/dist/esm5/src/platform_browser/persistence/browser.test.d.ts +0 -17
  348. package/dist/esm5/src/platform_browser/persistence/indexed_db.d.ts +0 -33
  349. package/dist/esm5/src/platform_browser/persistence/indexed_db.test.d.ts +0 -17
  350. package/dist/esm5/src/platform_browser/persistence/local_storage.d.ts +0 -25
  351. package/dist/esm5/src/platform_browser/persistence/local_storage.test.d.ts +0 -17
  352. package/dist/esm5/src/platform_browser/persistence/session_storage.d.ts +0 -24
  353. package/dist/esm5/src/platform_browser/persistence/session_storage.test.d.ts +0 -17
  354. package/dist/esm5/src/platform_browser/popup_redirect.d.ts +0 -27
  355. package/dist/esm5/src/platform_browser/popup_redirect.test.d.ts +0 -17
  356. package/dist/esm5/src/platform_browser/providers/phone.d.ts +0 -152
  357. package/dist/esm5/src/platform_browser/providers/phone.test.d.ts +0 -17
  358. package/dist/esm5/src/platform_browser/recaptcha/recaptcha.d.ts +0 -71
  359. package/dist/esm5/src/platform_browser/recaptcha/recaptcha.test.d.ts +0 -17
  360. package/dist/esm5/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +0 -45
  361. package/dist/esm5/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.test.d.ts +0 -17
  362. package/dist/esm5/src/platform_browser/recaptcha/recaptcha_loader.d.ts +0 -49
  363. package/dist/esm5/src/platform_browser/recaptcha/recaptcha_loader.test.d.ts +0 -17
  364. package/dist/esm5/src/platform_browser/recaptcha/recaptcha_mock.d.ts +0 -66
  365. package/dist/esm5/src/platform_browser/recaptcha/recaptcha_mock.test.d.ts +0 -17
  366. package/dist/esm5/src/platform_browser/recaptcha/recaptcha_verifier.d.ts +0 -92
  367. package/dist/esm5/src/platform_browser/recaptcha/recaptcha_verifier.test.d.ts +0 -17
  368. package/dist/esm5/src/platform_browser/strategies/phone.d.ts +0 -112
  369. package/dist/esm5/src/platform_browser/strategies/phone.test.d.ts +0 -17
  370. package/dist/esm5/src/platform_browser/strategies/popup.d.ts +0 -109
  371. package/dist/esm5/src/platform_browser/strategies/popup.test.d.ts +0 -17
  372. package/dist/esm5/src/platform_browser/strategies/redirect.d.ts +0 -176
  373. package/dist/esm5/src/platform_browser/strategies/redirect.test.d.ts +0 -17
  374. package/dist/esm5/src/platform_browser/util/popup.d.ts +0 -24
  375. package/dist/esm5/src/platform_browser/util/popup.test.d.ts +0 -17
  376. package/dist/esm5/src/platform_browser/util/worker.d.ts +0 -20
  377. package/dist/esm5/src/platform_cordova/plugins.d.ts +0 -42
  378. package/dist/esm5/src/platform_cordova/popup_redirect/events.d.ts +0 -39
  379. package/dist/esm5/src/platform_cordova/popup_redirect/events.test.d.ts +0 -17
  380. package/dist/esm5/src/platform_cordova/popup_redirect/popup_redirect.d.ts +0 -24
  381. package/dist/esm5/src/platform_cordova/popup_redirect/popup_redirect.test.d.ts +0 -17
  382. package/dist/esm5/src/platform_cordova/popup_redirect/utils.d.ts +0 -47
  383. package/dist/esm5/src/platform_cordova/popup_redirect/utils.test.d.ts +0 -17
  384. package/dist/esm5/src/platform_cordova/strategies/redirect.d.ts +0 -20
  385. package/dist/esm5/src/platform_node/index.d.ts +0 -50
  386. package/dist/esm5/src/platform_react_native/persistence/react_native.d.ts +0 -25
  387. package/dist/esm5/src/platform_react_native/persistence/react_native.test.d.ts +0 -17
  388. package/dist/esm5/test/helpers/api/helper.d.ts +0 -22
  389. package/dist/esm5/test/helpers/delay.d.ts +0 -20
  390. package/dist/esm5/test/helpers/erroring_unavailable_persistence.d.ts +0 -36
  391. package/dist/esm5/test/helpers/fake_service_worker.d.ts +0 -22
  392. package/dist/esm5/test/helpers/id_token_response.d.ts +0 -18
  393. package/dist/esm5/test/helpers/iframe_event.d.ts +0 -19
  394. package/dist/esm5/test/helpers/integration/emulator_rest_helpers.d.ts +0 -35
  395. package/dist/esm5/test/helpers/integration/helpers.d.ts +0 -32
  396. package/dist/esm5/test/helpers/integration/settings.d.ts +0 -23
  397. package/dist/esm5/test/helpers/jwt.d.ts +0 -17
  398. package/dist/esm5/test/helpers/mock_auth.d.ts +0 -47
  399. package/dist/esm5/test/helpers/mock_auth_credential.d.ts +0 -31
  400. package/dist/esm5/test/helpers/mock_fetch.d.ts +0 -30
  401. package/dist/esm5/test/helpers/mock_fetch.test.d.ts +0 -17
  402. package/dist/esm5/test/helpers/mock_popup_redirect_resolver.d.ts +0 -24
  403. package/dist/esm5/test/helpers/redirect_persistence.d.ts +0 -24
  404. package/dist/esm5/test/helpers/timeout_stub.d.ts +0 -34
  405. package/dist/esm5/test/integration/flows/anonymous.test.d.ts +0 -17
  406. package/dist/esm5/test/integration/flows/custom.local.test.d.ts +0 -17
  407. package/dist/esm5/test/integration/flows/email.test.d.ts +0 -17
  408. package/dist/esm5/test/integration/flows/idp.local.test.d.ts +0 -17
  409. package/dist/esm5/test/integration/flows/middleware_test_generator.d.ts +0 -18
  410. package/dist/esm5/test/integration/flows/oob.local.test.d.ts +0 -17
  411. package/dist/esm5/test/integration/flows/password_policy.test.d.ts +0 -17
  412. package/dist/esm5/test/integration/flows/phone.test.d.ts +0 -17
  413. package/dist/esm5/test/integration/flows/totp.test.d.ts +0 -17
  414. package/dist/esm5/test/integration/webdriver/anonymous.test.d.ts +0 -17
  415. package/dist/esm5/test/integration/webdriver/compat/firebaseui.test.d.ts +0 -17
  416. package/dist/esm5/test/integration/webdriver/persistence.test.d.ts +0 -17
  417. package/dist/esm5/test/integration/webdriver/popup.test.d.ts +0 -17
  418. package/dist/esm5/test/integration/webdriver/redirect.test.d.ts +0 -17
  419. package/dist/esm5/test/integration/webdriver/util/auth_driver.d.ts +0 -46
  420. package/dist/esm5/test/integration/webdriver/util/functions.d.ts +0 -81
  421. package/dist/esm5/test/integration/webdriver/util/idp_page.d.ts +0 -31
  422. package/dist/esm5/test/integration/webdriver/util/js_load_condition.d.ts +0 -25
  423. package/dist/esm5/test/integration/webdriver/util/test_runner.d.ts +0 -19
  424. package/dist/esm5/test/integration/webdriver/util/test_server.d.ts +0 -27
  425. package/dist/esm5/test/integration/webdriver/util/ui_page.d.ts +0 -33
  426. package/dist/index.webworker.esm5.js +0 -9265
  427. package/dist/index.webworker.esm5.js.map +0 -1
  428. package/dist/node/totp-259483a2.js +0 -8762
  429. package/dist/node/totp-259483a2.js.map +0 -1
  430. package/dist/node-esm/totp-219bb96f.js.map +0 -1
  431. package/dist/rn/index-2f66320e.js +0 -9819
  432. package/dist/rn/index-2f66320e.js.map +0 -1
  433. package/dist/web-extension-cjs/register-674a8250.js.map +0 -1
  434. package/dist/web-extension-esm2017/register-428f8789.js.map +0 -1
  435. /package/dist/{esm5/test/integration/flows/firebaseserverapp.test.d.ts → browser-cjs/test/integration/flows/recaptcha_enterprise.test.d.ts} +0 -0
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-2f66320e.js');
6
- var tslib = require('tslib');
7
- var util = require('@firebase/util');
5
+ var index = require('./index-4d73adbf.js');
8
6
  var app = require('@firebase/app');
7
+ var util = require('@firebase/util');
8
+ require('tslib');
9
9
  require('@firebase/component');
10
10
  require('@firebase/logger');
11
11
 
@@ -28,12 +28,12 @@ require('@firebase/logger');
28
28
  // There are two different browser persistence types: local and session.
29
29
  // Both have the same implementation but use a different underlying storage
30
30
  // object.
31
- var BrowserPersistenceClass = /** @class */ (function () {
32
- function BrowserPersistenceClass(storageRetriever, type) {
31
+ class BrowserPersistenceClass {
32
+ constructor(storageRetriever, type) {
33
33
  this.storageRetriever = storageRetriever;
34
34
  this.type = type;
35
35
  }
36
- BrowserPersistenceClass.prototype._isAvailable = function () {
36
+ _isAvailable() {
37
37
  try {
38
38
  if (!this.storage) {
39
39
  return Promise.resolve(false);
@@ -45,28 +45,23 @@ var BrowserPersistenceClass = /** @class */ (function () {
45
45
  catch (_a) {
46
46
  return Promise.resolve(false);
47
47
  }
48
- };
49
- BrowserPersistenceClass.prototype._set = function (key, value) {
48
+ }
49
+ _set(key, value) {
50
50
  this.storage.setItem(key, JSON.stringify(value));
51
51
  return Promise.resolve();
52
- };
53
- BrowserPersistenceClass.prototype._get = function (key) {
54
- var json = this.storage.getItem(key);
52
+ }
53
+ _get(key) {
54
+ const json = this.storage.getItem(key);
55
55
  return Promise.resolve(json ? JSON.parse(json) : null);
56
- };
57
- BrowserPersistenceClass.prototype._remove = function (key) {
56
+ }
57
+ _remove(key) {
58
58
  this.storage.removeItem(key);
59
59
  return Promise.resolve();
60
- };
61
- Object.defineProperty(BrowserPersistenceClass.prototype, "storage", {
62
- get: function () {
63
- return this.storageRetriever();
64
- },
65
- enumerable: false,
66
- configurable: true
67
- });
68
- return BrowserPersistenceClass;
69
- }());
60
+ }
61
+ get storage() {
62
+ return this.storageRetriever();
63
+ }
64
+ }
70
65
 
71
66
  /**
72
67
  * @license
@@ -85,49 +80,44 @@ var BrowserPersistenceClass = /** @class */ (function () {
85
80
  * limitations under the License.
86
81
  */
87
82
  // The polling period in case events are not supported
88
- var _POLLING_INTERVAL_MS$1 = 1000;
83
+ const _POLLING_INTERVAL_MS$1 = 1000;
89
84
  // The IE 10 localStorage cross tab synchronization delay in milliseconds
90
- var IE10_LOCAL_STORAGE_SYNC_DELAY = 10;
91
- var BrowserLocalPersistence = /** @class */ (function (_super) {
92
- tslib.__extends(BrowserLocalPersistence, _super);
93
- function BrowserLocalPersistence() {
94
- var _this = _super.call(this, function () { return window.localStorage; }, "LOCAL" /* PersistenceType.LOCAL */) || this;
95
- _this.boundEventHandler = function (event, poll) { return _this.onStorageEvent(event, poll); };
96
- _this.listeners = {};
97
- _this.localCache = {};
85
+ const IE10_LOCAL_STORAGE_SYNC_DELAY = 10;
86
+ class BrowserLocalPersistence extends BrowserPersistenceClass {
87
+ constructor() {
88
+ super(() => window.localStorage, "LOCAL" /* PersistenceType.LOCAL */);
89
+ this.boundEventHandler = (event, poll) => this.onStorageEvent(event, poll);
90
+ this.listeners = {};
91
+ this.localCache = {};
98
92
  // setTimeout return value is platform specific
99
93
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
100
- _this.pollTimer = null;
94
+ this.pollTimer = null;
101
95
  // Whether to use polling instead of depending on window events
102
- _this.fallbackToPolling = index._isMobileBrowser();
103
- _this._shouldAllowMigration = true;
104
- return _this;
96
+ this.fallbackToPolling = index._isMobileBrowser();
97
+ this._shouldAllowMigration = true;
105
98
  }
106
- BrowserLocalPersistence.prototype.forAllChangedKeys = function (cb) {
99
+ forAllChangedKeys(cb) {
107
100
  // Check all keys with listeners on them.
108
- for (var _i = 0, _a = Object.keys(this.listeners); _i < _a.length; _i++) {
109
- var key = _a[_i];
101
+ for (const key of Object.keys(this.listeners)) {
110
102
  // Get value from localStorage.
111
- var newValue = this.storage.getItem(key);
112
- var oldValue = this.localCache[key];
103
+ const newValue = this.storage.getItem(key);
104
+ const oldValue = this.localCache[key];
113
105
  // If local map value does not match, trigger listener with storage event.
114
106
  // Differentiate this simulated event from the real storage event.
115
107
  if (newValue !== oldValue) {
116
108
  cb(key, oldValue, newValue);
117
109
  }
118
110
  }
119
- };
120
- BrowserLocalPersistence.prototype.onStorageEvent = function (event, poll) {
121
- var _this = this;
122
- if (poll === void 0) { poll = false; }
111
+ }
112
+ onStorageEvent(event, poll = false) {
123
113
  // Key would be null in some situations, like when localStorage is cleared
124
114
  if (!event.key) {
125
- this.forAllChangedKeys(function (key, _oldValue, newValue) {
126
- _this.notifyListeners(key, newValue);
115
+ this.forAllChangedKeys((key, _oldValue, newValue) => {
116
+ this.notifyListeners(key, newValue);
127
117
  });
128
118
  return;
129
119
  }
130
- var key = event.key;
120
+ const key = event.key;
131
121
  // Check the mechanism how this event was detected.
132
122
  // The first event will dictate the mechanism to be used.
133
123
  if (poll) {
@@ -140,18 +130,18 @@ var BrowserLocalPersistence = /** @class */ (function (_super) {
140
130
  // Remove polling listener to prevent possible event duplication.
141
131
  this.stopPolling();
142
132
  }
143
- var triggerListeners = function () {
133
+ const triggerListeners = () => {
144
134
  // Keep local map up to date in case storage event is triggered before
145
135
  // poll.
146
- var storedValue = _this.storage.getItem(key);
147
- if (!poll && _this.localCache[key] === storedValue) {
136
+ const storedValue = this.storage.getItem(key);
137
+ if (!poll && this.localCache[key] === storedValue) {
148
138
  // Real storage event which has already been detected, do nothing.
149
139
  // This seems to trigger in some IE browsers for some reason.
150
140
  return;
151
141
  }
152
- _this.notifyListeners(key, storedValue);
142
+ this.notifyListeners(key, storedValue);
153
143
  };
154
- var storedValue = this.storage.getItem(key);
144
+ const storedValue = this.storage.getItem(key);
155
145
  if (index._isIE10() &&
156
146
  storedValue !== event.newValue &&
157
147
  event.newValue !== event.oldValue) {
@@ -164,44 +154,42 @@ var BrowserLocalPersistence = /** @class */ (function (_super) {
164
154
  else {
165
155
  triggerListeners();
166
156
  }
167
- };
168
- BrowserLocalPersistence.prototype.notifyListeners = function (key, value) {
157
+ }
158
+ notifyListeners(key, value) {
169
159
  this.localCache[key] = value;
170
- var listeners = this.listeners[key];
160
+ const listeners = this.listeners[key];
171
161
  if (listeners) {
172
- for (var _i = 0, _a = Array.from(listeners); _i < _a.length; _i++) {
173
- var listener = _a[_i];
162
+ for (const listener of Array.from(listeners)) {
174
163
  listener(value ? JSON.parse(value) : value);
175
164
  }
176
165
  }
177
- };
178
- BrowserLocalPersistence.prototype.startPolling = function () {
179
- var _this = this;
166
+ }
167
+ startPolling() {
180
168
  this.stopPolling();
181
- this.pollTimer = setInterval(function () {
182
- _this.forAllChangedKeys(function (key, oldValue, newValue) {
183
- _this.onStorageEvent(new StorageEvent('storage', {
184
- key: key,
185
- oldValue: oldValue,
186
- newValue: newValue
169
+ this.pollTimer = setInterval(() => {
170
+ this.forAllChangedKeys((key, oldValue, newValue) => {
171
+ this.onStorageEvent(new StorageEvent('storage', {
172
+ key,
173
+ oldValue,
174
+ newValue
187
175
  }),
188
176
  /* poll */ true);
189
177
  });
190
178
  }, _POLLING_INTERVAL_MS$1);
191
- };
192
- BrowserLocalPersistence.prototype.stopPolling = function () {
179
+ }
180
+ stopPolling() {
193
181
  if (this.pollTimer) {
194
182
  clearInterval(this.pollTimer);
195
183
  this.pollTimer = null;
196
184
  }
197
- };
198
- BrowserLocalPersistence.prototype.attachListener = function () {
185
+ }
186
+ attachListener() {
199
187
  window.addEventListener('storage', this.boundEventHandler);
200
- };
201
- BrowserLocalPersistence.prototype.detachListener = function () {
188
+ }
189
+ detachListener() {
202
190
  window.removeEventListener('storage', this.boundEventHandler);
203
- };
204
- BrowserLocalPersistence.prototype._addListener = function (key, listener) {
191
+ }
192
+ _addListener(key, listener) {
205
193
  if (Object.keys(this.listeners).length === 0) {
206
194
  // Whether browser can detect storage event when it had already been pushed to the background.
207
195
  // This may happen in some mobile browsers. A localStorage change in the foreground window
@@ -220,8 +208,8 @@ var BrowserLocalPersistence = /** @class */ (function (_super) {
220
208
  this.localCache[key] = this.storage.getItem(key);
221
209
  }
222
210
  this.listeners[key].add(listener);
223
- };
224
- BrowserLocalPersistence.prototype._removeListener = function (key, listener) {
211
+ }
212
+ _removeListener(key, listener) {
225
213
  if (this.listeners[key]) {
226
214
  this.listeners[key].delete(listener);
227
215
  if (this.listeners[key].size === 0) {
@@ -232,58 +220,30 @@ var BrowserLocalPersistence = /** @class */ (function (_super) {
232
220
  this.detachListener();
233
221
  this.stopPolling();
234
222
  }
235
- };
223
+ }
236
224
  // Update local cache on base operations:
237
- BrowserLocalPersistence.prototype._set = function (key, value) {
238
- return tslib.__awaiter(this, void 0, void 0, function () {
239
- return tslib.__generator(this, function (_a) {
240
- switch (_a.label) {
241
- case 0: return [4 /*yield*/, _super.prototype._set.call(this, key, value)];
242
- case 1:
243
- _a.sent();
244
- this.localCache[key] = JSON.stringify(value);
245
- return [2 /*return*/];
246
- }
247
- });
248
- });
249
- };
250
- BrowserLocalPersistence.prototype._get = function (key) {
251
- return tslib.__awaiter(this, void 0, void 0, function () {
252
- var value;
253
- return tslib.__generator(this, function (_a) {
254
- switch (_a.label) {
255
- case 0: return [4 /*yield*/, _super.prototype._get.call(this, key)];
256
- case 1:
257
- value = _a.sent();
258
- this.localCache[key] = JSON.stringify(value);
259
- return [2 /*return*/, value];
260
- }
261
- });
262
- });
263
- };
264
- BrowserLocalPersistence.prototype._remove = function (key) {
265
- return tslib.__awaiter(this, void 0, void 0, function () {
266
- return tslib.__generator(this, function (_a) {
267
- switch (_a.label) {
268
- case 0: return [4 /*yield*/, _super.prototype._remove.call(this, key)];
269
- case 1:
270
- _a.sent();
271
- delete this.localCache[key];
272
- return [2 /*return*/];
273
- }
274
- });
275
- });
276
- };
277
- BrowserLocalPersistence.type = 'LOCAL';
278
- return BrowserLocalPersistence;
279
- }(BrowserPersistenceClass));
225
+ async _set(key, value) {
226
+ await super._set(key, value);
227
+ this.localCache[key] = JSON.stringify(value);
228
+ }
229
+ async _get(key) {
230
+ const value = await super._get(key);
231
+ this.localCache[key] = JSON.stringify(value);
232
+ return value;
233
+ }
234
+ async _remove(key) {
235
+ await super._remove(key);
236
+ delete this.localCache[key];
237
+ }
238
+ }
239
+ BrowserLocalPersistence.type = 'LOCAL';
280
240
  /**
281
241
  * An implementation of {@link Persistence} of type `LOCAL` using `localStorage`
282
242
  * for the underlying storage.
283
243
  *
284
244
  * @public
285
245
  */
286
- var browserLocalPersistence = BrowserLocalPersistence;
246
+ const browserLocalPersistence = BrowserLocalPersistence;
287
247
 
288
248
  /**
289
249
  * @license
@@ -301,29 +261,27 @@ var browserLocalPersistence = BrowserLocalPersistence;
301
261
  * See the License for the specific language governing permissions and
302
262
  * limitations under the License.
303
263
  */
304
- var BrowserSessionPersistence = /** @class */ (function (_super) {
305
- tslib.__extends(BrowserSessionPersistence, _super);
306
- function BrowserSessionPersistence() {
307
- return _super.call(this, function () { return window.sessionStorage; }, "SESSION" /* PersistenceType.SESSION */) || this;
264
+ class BrowserSessionPersistence extends BrowserPersistenceClass {
265
+ constructor() {
266
+ super(() => window.sessionStorage, "SESSION" /* PersistenceType.SESSION */);
308
267
  }
309
- BrowserSessionPersistence.prototype._addListener = function (_key, _listener) {
268
+ _addListener(_key, _listener) {
310
269
  // Listeners are not supported for session storage since it cannot be shared across windows
311
270
  return;
312
- };
313
- BrowserSessionPersistence.prototype._removeListener = function (_key, _listener) {
271
+ }
272
+ _removeListener(_key, _listener) {
314
273
  // Listeners are not supported for session storage since it cannot be shared across windows
315
274
  return;
316
- };
317
- BrowserSessionPersistence.type = 'SESSION';
318
- return BrowserSessionPersistence;
319
- }(BrowserPersistenceClass));
275
+ }
276
+ }
277
+ BrowserSessionPersistence.type = 'SESSION';
320
278
  /**
321
279
  * An implementation of {@link Persistence} of `SESSION` using `sessionStorage`
322
280
  * for the underlying storage.
323
281
  *
324
282
  * @public
325
283
  */
326
- var browserSessionPersistence = BrowserSessionPersistence;
284
+ const browserSessionPersistence = BrowserSessionPersistence;
327
285
 
328
286
  /**
329
287
  * @license
@@ -347,30 +305,21 @@ var browserSessionPersistence = BrowserSessionPersistence;
347
305
  * @param promises - Array of promises to wait on.
348
306
  */
349
307
  function _allSettled(promises) {
350
- var _this = this;
351
- return Promise.all(promises.map(function (promise) { return tslib.__awaiter(_this, void 0, void 0, function () {
352
- var value, reason_1;
353
- return tslib.__generator(this, function (_a) {
354
- switch (_a.label) {
355
- case 0:
356
- _a.trys.push([0, 2, , 3]);
357
- return [4 /*yield*/, promise];
358
- case 1:
359
- value = _a.sent();
360
- return [2 /*return*/, {
361
- fulfilled: true,
362
- value: value
363
- }];
364
- case 2:
365
- reason_1 = _a.sent();
366
- return [2 /*return*/, {
367
- fulfilled: false,
368
- reason: reason_1
369
- }];
370
- case 3: return [2 /*return*/];
371
- }
372
- });
373
- }); }));
308
+ return Promise.all(promises.map(async (promise) => {
309
+ try {
310
+ const value = await promise;
311
+ return {
312
+ fulfilled: true,
313
+ value
314
+ };
315
+ }
316
+ catch (reason) {
317
+ return {
318
+ fulfilled: false,
319
+ reason
320
+ };
321
+ }
322
+ }));
374
323
  }
375
324
 
376
325
  /**
@@ -393,8 +342,8 @@ function _allSettled(promises) {
393
342
  * Interface class for receiving messages.
394
343
  *
395
344
  */
396
- var Receiver = /** @class */ (function () {
397
- function Receiver(eventTarget) {
345
+ class Receiver {
346
+ constructor(eventTarget) {
398
347
  this.eventTarget = eventTarget;
399
348
  this.handlersMap = {};
400
349
  this.boundEventHandler = this.handleEvent.bind(this);
@@ -405,23 +354,21 @@ var Receiver = /** @class */ (function () {
405
354
  * @param eventTarget - An event target (such as window or self) through which the underlying
406
355
  * messages will be received.
407
356
  */
408
- Receiver._getInstance = function (eventTarget) {
357
+ static _getInstance(eventTarget) {
409
358
  // The results are stored in an array since objects can't be keys for other
410
359
  // objects. In addition, setting a unique property on an event target as a
411
360
  // hash map key may not be allowed due to CORS restrictions.
412
- var existingInstance = this.receivers.find(function (receiver) {
413
- return receiver.isListeningto(eventTarget);
414
- });
361
+ const existingInstance = this.receivers.find(receiver => receiver.isListeningto(eventTarget));
415
362
  if (existingInstance) {
416
363
  return existingInstance;
417
364
  }
418
- var newInstance = new Receiver(eventTarget);
365
+ const newInstance = new Receiver(eventTarget);
419
366
  this.receivers.push(newInstance);
420
367
  return newInstance;
421
- };
422
- Receiver.prototype.isListeningto = function (eventTarget) {
368
+ }
369
+ isListeningto(eventTarget) {
423
370
  return this.eventTarget === eventTarget;
424
- };
371
+ }
425
372
  /**
426
373
  * Fans out a MessageEvent to the appropriate listeners.
427
374
  *
@@ -432,41 +379,27 @@ var Receiver = /** @class */ (function () {
432
379
  * @param event - The MessageEvent.
433
380
  *
434
381
  */
435
- Receiver.prototype.handleEvent = function (event) {
436
- return tslib.__awaiter(this, void 0, void 0, function () {
437
- var messageEvent, _a, eventId, eventType, data, handlers, promises, response;
438
- var _this = this;
439
- return tslib.__generator(this, function (_b) {
440
- switch (_b.label) {
441
- case 0:
442
- messageEvent = event;
443
- _a = messageEvent.data, eventId = _a.eventId, eventType = _a.eventType, data = _a.data;
444
- handlers = this.handlersMap[eventType];
445
- if (!(handlers === null || handlers === void 0 ? void 0 : handlers.size)) {
446
- return [2 /*return*/];
447
- }
448
- messageEvent.ports[0].postMessage({
449
- status: "ack" /* _Status.ACK */,
450
- eventId: eventId,
451
- eventType: eventType
452
- });
453
- promises = Array.from(handlers).map(function (handler) { return tslib.__awaiter(_this, void 0, void 0, function () { return tslib.__generator(this, function (_a) {
454
- return [2 /*return*/, handler(messageEvent.origin, data)];
455
- }); }); });
456
- return [4 /*yield*/, _allSettled(promises)];
457
- case 1:
458
- response = _b.sent();
459
- messageEvent.ports[0].postMessage({
460
- status: "done" /* _Status.DONE */,
461
- eventId: eventId,
462
- eventType: eventType,
463
- response: response
464
- });
465
- return [2 /*return*/];
466
- }
467
- });
382
+ async handleEvent(event) {
383
+ const messageEvent = event;
384
+ const { eventId, eventType, data } = messageEvent.data;
385
+ const handlers = this.handlersMap[eventType];
386
+ if (!(handlers === null || handlers === void 0 ? void 0 : handlers.size)) {
387
+ return;
388
+ }
389
+ messageEvent.ports[0].postMessage({
390
+ status: "ack" /* _Status.ACK */,
391
+ eventId,
392
+ eventType
468
393
  });
469
- };
394
+ const promises = Array.from(handlers).map(async (handler) => handler(messageEvent.origin, data));
395
+ const response = await _allSettled(promises);
396
+ messageEvent.ports[0].postMessage({
397
+ status: "done" /* _Status.DONE */,
398
+ eventId,
399
+ eventType,
400
+ response
401
+ });
402
+ }
470
403
  /**
471
404
  * Subscribe an event handler for a particular event.
472
405
  *
@@ -474,7 +407,7 @@ var Receiver = /** @class */ (function () {
474
407
  * @param eventHandler - The event handler which should receive the events.
475
408
  *
476
409
  */
477
- Receiver.prototype._subscribe = function (eventType, eventHandler) {
410
+ _subscribe(eventType, eventHandler) {
478
411
  if (Object.keys(this.handlersMap).length === 0) {
479
412
  this.eventTarget.addEventListener('message', this.boundEventHandler);
480
413
  }
@@ -482,7 +415,7 @@ var Receiver = /** @class */ (function () {
482
415
  this.handlersMap[eventType] = new Set();
483
416
  }
484
417
  this.handlersMap[eventType].add(eventHandler);
485
- };
418
+ }
486
419
  /**
487
420
  * Unsubscribe an event handler from a particular event.
488
421
  *
@@ -490,7 +423,7 @@ var Receiver = /** @class */ (function () {
490
423
  * @param eventHandler - Optional event handler, if none provided, unsubscribe all handlers on this event.
491
424
  *
492
425
  */
493
- Receiver.prototype._unsubscribe = function (eventType, eventHandler) {
426
+ _unsubscribe(eventType, eventHandler) {
494
427
  if (this.handlersMap[eventType] && eventHandler) {
495
428
  this.handlersMap[eventType].delete(eventHandler);
496
429
  }
@@ -500,10 +433,9 @@ var Receiver = /** @class */ (function () {
500
433
  if (Object.keys(this.handlersMap).length === 0) {
501
434
  this.eventTarget.removeEventListener('message', this.boundEventHandler);
502
435
  }
503
- };
504
- Receiver.receivers = [];
505
- return Receiver;
506
- }());
436
+ }
437
+ }
438
+ Receiver.receivers = [];
507
439
 
508
440
  /**
509
441
  * @license
@@ -521,11 +453,9 @@ var Receiver = /** @class */ (function () {
521
453
  * See the License for the specific language governing permissions and
522
454
  * limitations under the License.
523
455
  */
524
- function _generateEventId(prefix, digits) {
525
- if (prefix === void 0) { prefix = ''; }
526
- if (digits === void 0) { digits = 10; }
527
- var random = '';
528
- for (var i = 0; i < digits; i++) {
456
+ function _generateEventId(prefix = '', digits = 10) {
457
+ let random = '';
458
+ for (let i = 0; i < digits; i++) {
529
459
  random += Math.floor(Math.random() * 10);
530
460
  }
531
461
  return prefix + random;
@@ -551,8 +481,8 @@ function _generateEventId(prefix, digits) {
551
481
  * Interface for sending messages and waiting for a completion response.
552
482
  *
553
483
  */
554
- var Sender = /** @class */ (function () {
555
- function Sender(target) {
484
+ class Sender {
485
+ constructor(target) {
556
486
  this.target = target;
557
487
  this.handlers = new Set();
558
488
  }
@@ -561,13 +491,13 @@ var Sender = /** @class */ (function () {
561
491
  *
562
492
  * @param handler - The handler to unsubscribe.
563
493
  */
564
- Sender.prototype.removeMessageHandler = function (handler) {
494
+ removeMessageHandler(handler) {
565
495
  if (handler.messageChannel) {
566
496
  handler.messageChannel.port1.removeEventListener('message', handler.onMessage);
567
497
  handler.messageChannel.port1.close();
568
498
  }
569
499
  this.handlers.delete(handler);
570
- };
500
+ }
571
501
  /**
572
502
  * Send a message to the Receiver located at {@link target}.
573
503
  *
@@ -581,67 +511,65 @@ var Sender = /** @class */ (function () {
581
511
  *
582
512
  * @returns An array of settled promises from all the handlers that were listening on the receiver.
583
513
  */
584
- Sender.prototype._send = function (eventType, data, timeout) {
585
- if (timeout === void 0) { timeout = 50 /* _TimeoutDuration.ACK */; }
586
- return tslib.__awaiter(this, void 0, void 0, function () {
587
- var messageChannel, completionTimer, handler;
588
- var _this = this;
589
- return tslib.__generator(this, function (_a) {
590
- messageChannel = typeof MessageChannel !== 'undefined' ? new MessageChannel() : null;
591
- if (!messageChannel) {
592
- throw new Error("connection_unavailable" /* _MessageError.CONNECTION_UNAVAILABLE */);
514
+ async _send(eventType, data, timeout = 50 /* _TimeoutDuration.ACK */) {
515
+ const messageChannel = typeof MessageChannel !== 'undefined' ? new MessageChannel() : null;
516
+ if (!messageChannel) {
517
+ throw new Error("connection_unavailable" /* _MessageError.CONNECTION_UNAVAILABLE */);
518
+ }
519
+ // Node timers and browser timers return fundamentally different types.
520
+ // We don't actually care what the value is but TS won't accept unknown and
521
+ // we can't cast properly in both environments.
522
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
523
+ let completionTimer;
524
+ let handler;
525
+ return new Promise((resolve, reject) => {
526
+ const eventId = _generateEventId('', 20);
527
+ messageChannel.port1.start();
528
+ const ackTimer = setTimeout(() => {
529
+ reject(new Error("unsupported_event" /* _MessageError.UNSUPPORTED_EVENT */));
530
+ }, timeout);
531
+ handler = {
532
+ messageChannel,
533
+ onMessage(event) {
534
+ const messageEvent = event;
535
+ if (messageEvent.data.eventId !== eventId) {
536
+ return;
537
+ }
538
+ switch (messageEvent.data.status) {
539
+ case "ack" /* _Status.ACK */:
540
+ // The receiver should ACK first.
541
+ clearTimeout(ackTimer);
542
+ completionTimer = setTimeout(() => {
543
+ reject(new Error("timeout" /* _MessageError.TIMEOUT */));
544
+ }, 3000 /* _TimeoutDuration.COMPLETION */);
545
+ break;
546
+ case "done" /* _Status.DONE */:
547
+ // Once the receiver's handlers are finished we will get the results.
548
+ clearTimeout(completionTimer);
549
+ resolve(messageEvent.data.response);
550
+ break;
551
+ default:
552
+ clearTimeout(ackTimer);
553
+ clearTimeout(completionTimer);
554
+ reject(new Error("invalid_response" /* _MessageError.INVALID_RESPONSE */));
555
+ break;
556
+ }
593
557
  }
594
- return [2 /*return*/, new Promise(function (resolve, reject) {
595
- var eventId = _generateEventId('', 20);
596
- messageChannel.port1.start();
597
- var ackTimer = setTimeout(function () {
598
- reject(new Error("unsupported_event" /* _MessageError.UNSUPPORTED_EVENT */));
599
- }, timeout);
600
- handler = {
601
- messageChannel: messageChannel,
602
- onMessage: function (event) {
603
- var messageEvent = event;
604
- if (messageEvent.data.eventId !== eventId) {
605
- return;
606
- }
607
- switch (messageEvent.data.status) {
608
- case "ack" /* _Status.ACK */:
609
- // The receiver should ACK first.
610
- clearTimeout(ackTimer);
611
- completionTimer = setTimeout(function () {
612
- reject(new Error("timeout" /* _MessageError.TIMEOUT */));
613
- }, 3000 /* _TimeoutDuration.COMPLETION */);
614
- break;
615
- case "done" /* _Status.DONE */:
616
- // Once the receiver's handlers are finished we will get the results.
617
- clearTimeout(completionTimer);
618
- resolve(messageEvent.data.response);
619
- break;
620
- default:
621
- clearTimeout(ackTimer);
622
- clearTimeout(completionTimer);
623
- reject(new Error("invalid_response" /* _MessageError.INVALID_RESPONSE */));
624
- break;
625
- }
626
- }
627
- };
628
- _this.handlers.add(handler);
629
- messageChannel.port1.addEventListener('message', handler.onMessage);
630
- _this.target.postMessage({
631
- eventType: eventType,
632
- eventId: eventId,
633
- data: data
634
- }, [messageChannel.port2]);
635
- }).finally(function () {
636
- if (handler) {
637
- _this.removeMessageHandler(handler);
638
- }
639
- })];
640
- });
558
+ };
559
+ this.handlers.add(handler);
560
+ messageChannel.port1.addEventListener('message', handler.onMessage);
561
+ this.target.postMessage({
562
+ eventType,
563
+ eventId,
564
+ data
565
+ }, [messageChannel.port2]);
566
+ }).finally(() => {
567
+ if (handler) {
568
+ this.removeMessageHandler(handler);
569
+ }
641
570
  });
642
- };
643
- return Sender;
644
- }());
571
+ }
572
+ }
645
573
 
646
574
  /**
647
575
  * @license
@@ -659,51 +587,48 @@ var Sender = /** @class */ (function () {
659
587
  * See the License for the specific language governing permissions and
660
588
  * limitations under the License.
661
589
  */
662
- var DB_NAME = 'firebaseLocalStorageDb';
663
- var DB_VERSION = 1;
664
- var DB_OBJECTSTORE_NAME = 'firebaseLocalStorage';
665
- var DB_DATA_KEYPATH = 'fbase_key';
590
+ const DB_NAME = 'firebaseLocalStorageDb';
591
+ const DB_VERSION = 1;
592
+ const DB_OBJECTSTORE_NAME = 'firebaseLocalStorage';
593
+ const DB_DATA_KEYPATH = 'fbase_key';
666
594
  /**
667
595
  * Promise wrapper for IDBRequest
668
596
  *
669
597
  * Unfortunately we can't cleanly extend Promise<T> since promises are not callable in ES6
670
598
  *
671
599
  */
672
- var DBPromise = /** @class */ (function () {
673
- function DBPromise(request) {
600
+ class DBPromise {
601
+ constructor(request) {
674
602
  this.request = request;
675
603
  }
676
- DBPromise.prototype.toPromise = function () {
677
- var _this = this;
678
- return new Promise(function (resolve, reject) {
679
- _this.request.addEventListener('success', function () {
680
- resolve(_this.request.result);
604
+ toPromise() {
605
+ return new Promise((resolve, reject) => {
606
+ this.request.addEventListener('success', () => {
607
+ resolve(this.request.result);
681
608
  });
682
- _this.request.addEventListener('error', function () {
683
- reject(_this.request.error);
609
+ this.request.addEventListener('error', () => {
610
+ reject(this.request.error);
684
611
  });
685
612
  });
686
- };
687
- return DBPromise;
688
- }());
613
+ }
614
+ }
689
615
  function getObjectStore(db, isReadWrite) {
690
616
  return db
691
617
  .transaction([DB_OBJECTSTORE_NAME], isReadWrite ? 'readwrite' : 'readonly')
692
618
  .objectStore(DB_OBJECTSTORE_NAME);
693
619
  }
694
620
  function _deleteDatabase() {
695
- var request = indexedDB.deleteDatabase(DB_NAME);
621
+ const request = indexedDB.deleteDatabase(DB_NAME);
696
622
  return new DBPromise(request).toPromise();
697
623
  }
698
624
  function _openDatabase() {
699
- var _this = this;
700
- var request = indexedDB.open(DB_NAME, DB_VERSION);
701
- return new Promise(function (resolve, reject) {
702
- request.addEventListener('error', function () {
625
+ const request = indexedDB.open(DB_NAME, DB_VERSION);
626
+ return new Promise((resolve, reject) => {
627
+ request.addEventListener('error', () => {
703
628
  reject(request.error);
704
629
  });
705
- request.addEventListener('upgradeneeded', function () {
706
- var db = request.result;
630
+ request.addEventListener('upgradeneeded', () => {
631
+ const db = request.result;
707
632
  try {
708
633
  db.createObjectStore(DB_OBJECTSTORE_NAME, { keyPath: DB_DATA_KEYPATH });
709
634
  }
@@ -711,68 +636,44 @@ function _openDatabase() {
711
636
  reject(e);
712
637
  }
713
638
  });
714
- request.addEventListener('success', function () { return tslib.__awaiter(_this, void 0, void 0, function () {
715
- var db, _a;
716
- return tslib.__generator(this, function (_b) {
717
- switch (_b.label) {
718
- case 0:
719
- db = request.result;
720
- if (!!db.objectStoreNames.contains(DB_OBJECTSTORE_NAME)) return [3 /*break*/, 3];
721
- // Need to close the database or else you get a `blocked` event
722
- db.close();
723
- return [4 /*yield*/, _deleteDatabase()];
724
- case 1:
725
- _b.sent();
726
- _a = resolve;
727
- return [4 /*yield*/, _openDatabase()];
728
- case 2:
729
- _a.apply(void 0, [_b.sent()]);
730
- return [3 /*break*/, 4];
731
- case 3:
732
- resolve(db);
733
- _b.label = 4;
734
- case 4: return [2 /*return*/];
735
- }
736
- });
737
- }); });
738
- });
739
- }
740
- function _putObject(db, key, value) {
741
- return tslib.__awaiter(this, void 0, void 0, function () {
742
- var request;
743
- var _a;
744
- return tslib.__generator(this, function (_b) {
745
- request = getObjectStore(db, true).put((_a = {},
746
- _a[DB_DATA_KEYPATH] = key,
747
- _a.value = value,
748
- _a));
749
- return [2 /*return*/, new DBPromise(request).toPromise()];
639
+ request.addEventListener('success', async () => {
640
+ const db = request.result;
641
+ // Strange bug that occurs in Firefox when multiple tabs are opened at the
642
+ // same time. The only way to recover seems to be deleting the database
643
+ // and re-initializing it.
644
+ // https://github.com/firebase/firebase-js-sdk/issues/634
645
+ if (!db.objectStoreNames.contains(DB_OBJECTSTORE_NAME)) {
646
+ // Need to close the database or else you get a `blocked` event
647
+ db.close();
648
+ await _deleteDatabase();
649
+ resolve(await _openDatabase());
650
+ }
651
+ else {
652
+ resolve(db);
653
+ }
750
654
  });
751
655
  });
752
656
  }
753
- function getObject(db, key) {
754
- return tslib.__awaiter(this, void 0, void 0, function () {
755
- var request, data;
756
- return tslib.__generator(this, function (_a) {
757
- switch (_a.label) {
758
- case 0:
759
- request = getObjectStore(db, false).get(key);
760
- return [4 /*yield*/, new DBPromise(request).toPromise()];
761
- case 1:
762
- data = _a.sent();
763
- return [2 /*return*/, data === undefined ? null : data.value];
764
- }
765
- });
657
+ async function _putObject(db, key, value) {
658
+ const request = getObjectStore(db, true).put({
659
+ [DB_DATA_KEYPATH]: key,
660
+ value
766
661
  });
662
+ return new DBPromise(request).toPromise();
663
+ }
664
+ async function getObject(db, key) {
665
+ const request = getObjectStore(db, false).get(key);
666
+ const data = await new DBPromise(request).toPromise();
667
+ return data === undefined ? null : data.value;
767
668
  }
768
669
  function _deleteObject(db, key) {
769
- var request = getObjectStore(db, true).delete(key);
670
+ const request = getObjectStore(db, true).delete(key);
770
671
  return new DBPromise(request).toPromise();
771
672
  }
772
- var _POLLING_INTERVAL_MS = 800;
773
- var _TRANSACTION_RETRY_COUNT = 3;
774
- var IndexedDBLocalPersistence = /** @class */ (function () {
775
- function IndexedDBLocalPersistence() {
673
+ const _POLLING_INTERVAL_MS = 800;
674
+ const _TRANSACTION_RETRY_COUNT = 3;
675
+ class IndexedDBLocalPersistence {
676
+ constructor() {
776
677
  this.type = "LOCAL" /* PersistenceType.LOCAL */;
777
678
  this._shouldAllowMigration = true;
778
679
  this.listeners = {};
@@ -787,102 +688,58 @@ var IndexedDBLocalPersistence = /** @class */ (function () {
787
688
  this.activeServiceWorker = null;
788
689
  // Fire & forget the service worker registration as it may never resolve
789
690
  this._workerInitializationPromise =
790
- this.initializeServiceWorkerMessaging().then(function () { }, function () { });
691
+ this.initializeServiceWorkerMessaging().then(() => { }, () => { });
791
692
  }
792
- IndexedDBLocalPersistence.prototype._openDb = function () {
793
- return tslib.__awaiter(this, void 0, void 0, function () {
794
- var _a;
795
- return tslib.__generator(this, function (_b) {
796
- switch (_b.label) {
797
- case 0:
798
- if (this.db) {
799
- return [2 /*return*/, this.db];
800
- }
801
- _a = this;
802
- return [4 /*yield*/, _openDatabase()];
803
- case 1:
804
- _a.db = _b.sent();
805
- return [2 /*return*/, this.db];
693
+ async _openDb() {
694
+ if (this.db) {
695
+ return this.db;
696
+ }
697
+ this.db = await _openDatabase();
698
+ return this.db;
699
+ }
700
+ async _withRetries(op) {
701
+ let numAttempts = 0;
702
+ while (true) {
703
+ try {
704
+ const db = await this._openDb();
705
+ return await op(db);
706
+ }
707
+ catch (e) {
708
+ if (numAttempts++ > _TRANSACTION_RETRY_COUNT) {
709
+ throw e;
806
710
  }
807
- });
808
- });
809
- };
810
- IndexedDBLocalPersistence.prototype._withRetries = function (op) {
811
- return tslib.__awaiter(this, void 0, void 0, function () {
812
- var numAttempts, db, e_1;
813
- return tslib.__generator(this, function (_a) {
814
- switch (_a.label) {
815
- case 0:
816
- numAttempts = 0;
817
- _a.label = 1;
818
- case 1:
819
- _a.label = 2;
820
- case 2:
821
- _a.trys.push([2, 5, , 6]);
822
- return [4 /*yield*/, this._openDb()];
823
- case 3:
824
- db = _a.sent();
825
- return [4 /*yield*/, op(db)];
826
- case 4: return [2 /*return*/, _a.sent()];
827
- case 5:
828
- e_1 = _a.sent();
829
- if (numAttempts++ > _TRANSACTION_RETRY_COUNT) {
830
- throw e_1;
831
- }
832
- if (this.db) {
833
- this.db.close();
834
- this.db = undefined;
835
- }
836
- return [3 /*break*/, 6];
837
- case 6: return [3 /*break*/, 1];
838
- case 7: return [2 /*return*/];
711
+ if (this.db) {
712
+ this.db.close();
713
+ this.db = undefined;
839
714
  }
840
- });
841
- });
842
- };
715
+ // TODO: consider adding exponential backoff
716
+ }
717
+ }
718
+ }
843
719
  /**
844
720
  * IndexedDB events do not propagate from the main window to the worker context. We rely on a
845
721
  * postMessage interface to send these events to the worker ourselves.
846
722
  */
847
- IndexedDBLocalPersistence.prototype.initializeServiceWorkerMessaging = function () {
848
- return tslib.__awaiter(this, void 0, void 0, function () {
849
- return tslib.__generator(this, function (_a) {
850
- return [2 /*return*/, index._isWorker() ? this.initializeReceiver() : this.initializeSender()];
851
- });
852
- });
853
- };
723
+ async initializeServiceWorkerMessaging() {
724
+ return index._isWorker() ? this.initializeReceiver() : this.initializeSender();
725
+ }
854
726
  /**
855
727
  * As the worker we should listen to events from the main window.
856
728
  */
857
- IndexedDBLocalPersistence.prototype.initializeReceiver = function () {
858
- return tslib.__awaiter(this, void 0, void 0, function () {
859
- var _this = this;
860
- return tslib.__generator(this, function (_a) {
861
- this.receiver = Receiver._getInstance(index._getWorkerGlobalScope());
862
- // Refresh from persistence if we receive a KeyChanged message.
863
- this.receiver._subscribe("keyChanged" /* _EventType.KEY_CHANGED */, function (_origin, data) { return tslib.__awaiter(_this, void 0, void 0, function () {
864
- var keys;
865
- return tslib.__generator(this, function (_a) {
866
- switch (_a.label) {
867
- case 0: return [4 /*yield*/, this._poll()];
868
- case 1:
869
- keys = _a.sent();
870
- return [2 /*return*/, {
871
- keyProcessed: keys.includes(data.key)
872
- }];
873
- }
874
- });
875
- }); });
876
- // Let the sender know that we are listening so they give us more timeout.
877
- this.receiver._subscribe("ping" /* _EventType.PING */, function (_origin, _data) { return tslib.__awaiter(_this, void 0, void 0, function () {
878
- return tslib.__generator(this, function (_a) {
879
- return [2 /*return*/, ["keyChanged" /* _EventType.KEY_CHANGED */]];
880
- });
881
- }); });
882
- return [2 /*return*/];
883
- });
729
+ async initializeReceiver() {
730
+ this.receiver = Receiver._getInstance(index._getWorkerGlobalScope());
731
+ // Refresh from persistence if we receive a KeyChanged message.
732
+ this.receiver._subscribe("keyChanged" /* _EventType.KEY_CHANGED */, async (_origin, data) => {
733
+ const keys = await this._poll();
734
+ return {
735
+ keyProcessed: keys.includes(data.key)
736
+ };
884
737
  });
885
- };
738
+ // Let the sender know that we are listening so they give us more timeout.
739
+ this.receiver._subscribe("ping" /* _EventType.PING */, async (_origin, _data) => {
740
+ return ["keyChanged" /* _EventType.KEY_CHANGED */];
741
+ });
742
+ }
886
743
  /**
887
744
  * As the main window, we should let the worker know when keys change (set and remove).
888
745
  *
@@ -890,38 +747,24 @@ var IndexedDBLocalPersistence = /** @class */ (function () {
890
747
  * {@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/ready | ServiceWorkerContainer.ready}
891
748
  * may not resolve.
892
749
  */
893
- IndexedDBLocalPersistence.prototype.initializeSender = function () {
750
+ async initializeSender() {
894
751
  var _a, _b;
895
- return tslib.__awaiter(this, void 0, void 0, function () {
896
- var _c, results;
897
- return tslib.__generator(this, function (_d) {
898
- switch (_d.label) {
899
- case 0:
900
- // Check to see if there's an active service worker.
901
- _c = this;
902
- return [4 /*yield*/, index._getActiveServiceWorker()];
903
- case 1:
904
- // Check to see if there's an active service worker.
905
- _c.activeServiceWorker = _d.sent();
906
- if (!this.activeServiceWorker) {
907
- return [2 /*return*/];
908
- }
909
- this.sender = new Sender(this.activeServiceWorker);
910
- return [4 /*yield*/, this.sender._send("ping" /* _EventType.PING */, {}, 800 /* _TimeoutDuration.LONG_ACK */)];
911
- case 2:
912
- results = _d.sent();
913
- if (!results) {
914
- return [2 /*return*/];
915
- }
916
- if (((_a = results[0]) === null || _a === void 0 ? void 0 : _a.fulfilled) &&
917
- ((_b = results[0]) === null || _b === void 0 ? void 0 : _b.value.includes("keyChanged" /* _EventType.KEY_CHANGED */))) {
918
- this.serviceWorkerReceiverAvailable = true;
919
- }
920
- return [2 /*return*/];
921
- }
922
- });
923
- });
924
- };
752
+ // Check to see if there's an active service worker.
753
+ this.activeServiceWorker = await index._getActiveServiceWorker();
754
+ if (!this.activeServiceWorker) {
755
+ return;
756
+ }
757
+ this.sender = new Sender(this.activeServiceWorker);
758
+ // Ping the service worker to check what events they can handle.
759
+ const results = await this.sender._send("ping" /* _EventType.PING */, {}, 800 /* _TimeoutDuration.LONG_ACK */);
760
+ if (!results) {
761
+ return;
762
+ }
763
+ if (((_a = results[0]) === null || _a === void 0 ? void 0 : _a.fulfilled) &&
764
+ ((_b = results[0]) === null || _b === void 0 ? void 0 : _b.value.includes("keyChanged" /* _EventType.KEY_CHANGED */))) {
765
+ this.serviceWorkerReceiverAvailable = true;
766
+ }
767
+ }
925
768
  /**
926
769
  * Let the worker know about a changed key, the exact key doesn't technically matter since the
927
770
  * worker will just trigger a full sync anyway.
@@ -931,203 +774,117 @@ var IndexedDBLocalPersistence = /** @class */ (function () {
931
774
  *
932
775
  * @param key - Storage key which changed.
933
776
  */
934
- IndexedDBLocalPersistence.prototype.notifyServiceWorker = function (key) {
935
- return tslib.__awaiter(this, void 0, void 0, function () {
936
- return tslib.__generator(this, function (_b) {
937
- switch (_b.label) {
938
- case 0:
939
- if (!this.sender ||
940
- !this.activeServiceWorker ||
941
- index._getServiceWorkerController() !== this.activeServiceWorker) {
942
- return [2 /*return*/];
943
- }
944
- _b.label = 1;
945
- case 1:
946
- _b.trys.push([1, 3, , 4]);
947
- return [4 /*yield*/, this.sender._send("keyChanged" /* _EventType.KEY_CHANGED */, { key: key },
948
- // Use long timeout if receiver has previously responded to a ping from us.
949
- this.serviceWorkerReceiverAvailable
950
- ? 800 /* _TimeoutDuration.LONG_ACK */
951
- : 50 /* _TimeoutDuration.ACK */)];
952
- case 2:
953
- _b.sent();
954
- return [3 /*break*/, 4];
955
- case 3:
956
- _b.sent();
957
- return [3 /*break*/, 4];
958
- case 4: return [2 /*return*/];
959
- }
960
- });
961
- });
962
- };
963
- IndexedDBLocalPersistence.prototype._isAvailable = function () {
964
- return tslib.__awaiter(this, void 0, void 0, function () {
965
- var db;
966
- return tslib.__generator(this, function (_b) {
967
- switch (_b.label) {
968
- case 0:
969
- _b.trys.push([0, 4, , 5]);
970
- if (!indexedDB) {
971
- return [2 /*return*/, false];
972
- }
973
- return [4 /*yield*/, _openDatabase()];
974
- case 1:
975
- db = _b.sent();
976
- return [4 /*yield*/, _putObject(db, index.STORAGE_AVAILABLE_KEY, '1')];
977
- case 2:
978
- _b.sent();
979
- return [4 /*yield*/, _deleteObject(db, index.STORAGE_AVAILABLE_KEY)];
980
- case 3:
981
- _b.sent();
982
- return [2 /*return*/, true];
983
- case 4:
984
- _b.sent();
985
- return [3 /*break*/, 5];
986
- case 5: return [2 /*return*/, false];
987
- }
988
- });
989
- });
990
- };
991
- IndexedDBLocalPersistence.prototype._withPendingWrite = function (write) {
992
- return tslib.__awaiter(this, void 0, void 0, function () {
993
- return tslib.__generator(this, function (_a) {
994
- switch (_a.label) {
995
- case 0:
996
- this.pendingWrites++;
997
- _a.label = 1;
998
- case 1:
999
- _a.trys.push([1, , 3, 4]);
1000
- return [4 /*yield*/, write()];
1001
- case 2:
1002
- _a.sent();
1003
- return [3 /*break*/, 4];
1004
- case 3:
1005
- this.pendingWrites--;
1006
- return [7 /*endfinally*/];
1007
- case 4: return [2 /*return*/];
1008
- }
1009
- });
1010
- });
1011
- };
1012
- IndexedDBLocalPersistence.prototype._set = function (key, value) {
1013
- return tslib.__awaiter(this, void 0, void 0, function () {
1014
- var _this = this;
1015
- return tslib.__generator(this, function (_a) {
1016
- return [2 /*return*/, this._withPendingWrite(function () { return tslib.__awaiter(_this, void 0, void 0, function () {
1017
- return tslib.__generator(this, function (_a) {
1018
- switch (_a.label) {
1019
- case 0: return [4 /*yield*/, this._withRetries(function (db) { return _putObject(db, key, value); })];
1020
- case 1:
1021
- _a.sent();
1022
- this.localCache[key] = value;
1023
- return [2 /*return*/, this.notifyServiceWorker(key)];
1024
- }
1025
- });
1026
- }); })];
1027
- });
777
+ async notifyServiceWorker(key) {
778
+ if (!this.sender ||
779
+ !this.activeServiceWorker ||
780
+ index._getServiceWorkerController() !== this.activeServiceWorker) {
781
+ return;
782
+ }
783
+ try {
784
+ await this.sender._send("keyChanged" /* _EventType.KEY_CHANGED */, { key },
785
+ // Use long timeout if receiver has previously responded to a ping from us.
786
+ this.serviceWorkerReceiverAvailable
787
+ ? 800 /* _TimeoutDuration.LONG_ACK */
788
+ : 50 /* _TimeoutDuration.ACK */);
789
+ }
790
+ catch (_a) {
791
+ // This is a best effort approach. Ignore errors.
792
+ }
793
+ }
794
+ async _isAvailable() {
795
+ try {
796
+ if (!indexedDB) {
797
+ return false;
798
+ }
799
+ const db = await _openDatabase();
800
+ await _putObject(db, index.STORAGE_AVAILABLE_KEY, '1');
801
+ await _deleteObject(db, index.STORAGE_AVAILABLE_KEY);
802
+ return true;
803
+ }
804
+ catch (_a) { }
805
+ return false;
806
+ }
807
+ async _withPendingWrite(write) {
808
+ this.pendingWrites++;
809
+ try {
810
+ await write();
811
+ }
812
+ finally {
813
+ this.pendingWrites--;
814
+ }
815
+ }
816
+ async _set(key, value) {
817
+ return this._withPendingWrite(async () => {
818
+ await this._withRetries((db) => _putObject(db, key, value));
819
+ this.localCache[key] = value;
820
+ return this.notifyServiceWorker(key);
1028
821
  });
1029
- };
1030
- IndexedDBLocalPersistence.prototype._get = function (key) {
1031
- return tslib.__awaiter(this, void 0, void 0, function () {
1032
- var obj;
1033
- return tslib.__generator(this, function (_a) {
1034
- switch (_a.label) {
1035
- case 0: return [4 /*yield*/, this._withRetries(function (db) {
1036
- return getObject(db, key);
1037
- })];
1038
- case 1:
1039
- obj = (_a.sent());
1040
- this.localCache[key] = obj;
1041
- return [2 /*return*/, obj];
1042
- }
1043
- });
822
+ }
823
+ async _get(key) {
824
+ const obj = (await this._withRetries((db) => getObject(db, key)));
825
+ this.localCache[key] = obj;
826
+ return obj;
827
+ }
828
+ async _remove(key) {
829
+ return this._withPendingWrite(async () => {
830
+ await this._withRetries((db) => _deleteObject(db, key));
831
+ delete this.localCache[key];
832
+ return this.notifyServiceWorker(key);
1044
833
  });
1045
- };
1046
- IndexedDBLocalPersistence.prototype._remove = function (key) {
1047
- return tslib.__awaiter(this, void 0, void 0, function () {
1048
- var _this = this;
1049
- return tslib.__generator(this, function (_a) {
1050
- return [2 /*return*/, this._withPendingWrite(function () { return tslib.__awaiter(_this, void 0, void 0, function () {
1051
- return tslib.__generator(this, function (_a) {
1052
- switch (_a.label) {
1053
- case 0: return [4 /*yield*/, this._withRetries(function (db) { return _deleteObject(db, key); })];
1054
- case 1:
1055
- _a.sent();
1056
- delete this.localCache[key];
1057
- return [2 /*return*/, this.notifyServiceWorker(key)];
1058
- }
1059
- });
1060
- }); })];
1061
- });
834
+ }
835
+ async _poll() {
836
+ // TODO: check if we need to fallback if getAll is not supported
837
+ const result = await this._withRetries((db) => {
838
+ const getAllRequest = getObjectStore(db, false).getAll();
839
+ return new DBPromise(getAllRequest).toPromise();
1062
840
  });
1063
- };
1064
- IndexedDBLocalPersistence.prototype._poll = function () {
1065
- return tslib.__awaiter(this, void 0, void 0, function () {
1066
- var result, keys, keysInResult, _i, result_1, _a, key, value, _b, _c, localKey;
1067
- return tslib.__generator(this, function (_d) {
1068
- switch (_d.label) {
1069
- case 0: return [4 /*yield*/, this._withRetries(function (db) {
1070
- var getAllRequest = getObjectStore(db, false).getAll();
1071
- return new DBPromise(getAllRequest).toPromise();
1072
- })];
1073
- case 1:
1074
- result = _d.sent();
1075
- if (!result) {
1076
- return [2 /*return*/, []];
1077
- }
1078
- // If we have pending writes in progress abort, we'll get picked up on the next poll
1079
- if (this.pendingWrites !== 0) {
1080
- return [2 /*return*/, []];
1081
- }
1082
- keys = [];
1083
- keysInResult = new Set();
1084
- if (result.length !== 0) {
1085
- for (_i = 0, result_1 = result; _i < result_1.length; _i++) {
1086
- _a = result_1[_i], key = _a.fbase_key, value = _a.value;
1087
- keysInResult.add(key);
1088
- if (JSON.stringify(this.localCache[key]) !== JSON.stringify(value)) {
1089
- this.notifyListeners(key, value);
1090
- keys.push(key);
1091
- }
1092
- }
1093
- }
1094
- for (_b = 0, _c = Object.keys(this.localCache); _b < _c.length; _b++) {
1095
- localKey = _c[_b];
1096
- if (this.localCache[localKey] && !keysInResult.has(localKey)) {
1097
- // Deleted
1098
- this.notifyListeners(localKey, null);
1099
- keys.push(localKey);
1100
- }
1101
- }
1102
- return [2 /*return*/, keys];
841
+ if (!result) {
842
+ return [];
843
+ }
844
+ // If we have pending writes in progress abort, we'll get picked up on the next poll
845
+ if (this.pendingWrites !== 0) {
846
+ return [];
847
+ }
848
+ const keys = [];
849
+ const keysInResult = new Set();
850
+ if (result.length !== 0) {
851
+ for (const { fbase_key: key, value } of result) {
852
+ keysInResult.add(key);
853
+ if (JSON.stringify(this.localCache[key]) !== JSON.stringify(value)) {
854
+ this.notifyListeners(key, value);
855
+ keys.push(key);
1103
856
  }
1104
- });
1105
- });
1106
- };
1107
- IndexedDBLocalPersistence.prototype.notifyListeners = function (key, newValue) {
857
+ }
858
+ }
859
+ for (const localKey of Object.keys(this.localCache)) {
860
+ if (this.localCache[localKey] && !keysInResult.has(localKey)) {
861
+ // Deleted
862
+ this.notifyListeners(localKey, null);
863
+ keys.push(localKey);
864
+ }
865
+ }
866
+ return keys;
867
+ }
868
+ notifyListeners(key, newValue) {
1108
869
  this.localCache[key] = newValue;
1109
- var listeners = this.listeners[key];
870
+ const listeners = this.listeners[key];
1110
871
  if (listeners) {
1111
- for (var _i = 0, _a = Array.from(listeners); _i < _a.length; _i++) {
1112
- var listener = _a[_i];
872
+ for (const listener of Array.from(listeners)) {
1113
873
  listener(newValue);
1114
874
  }
1115
875
  }
1116
- };
1117
- IndexedDBLocalPersistence.prototype.startPolling = function () {
1118
- var _this = this;
876
+ }
877
+ startPolling() {
1119
878
  this.stopPolling();
1120
- this.pollTimer = setInterval(function () { return tslib.__awaiter(_this, void 0, void 0, function () { return tslib.__generator(this, function (_a) {
1121
- return [2 /*return*/, this._poll()];
1122
- }); }); }, _POLLING_INTERVAL_MS);
1123
- };
1124
- IndexedDBLocalPersistence.prototype.stopPolling = function () {
879
+ this.pollTimer = setInterval(async () => this._poll(), _POLLING_INTERVAL_MS);
880
+ }
881
+ stopPolling() {
1125
882
  if (this.pollTimer) {
1126
883
  clearInterval(this.pollTimer);
1127
884
  this.pollTimer = null;
1128
885
  }
1129
- };
1130
- IndexedDBLocalPersistence.prototype._addListener = function (key, listener) {
886
+ }
887
+ _addListener(key, listener) {
1131
888
  if (Object.keys(this.listeners).length === 0) {
1132
889
  this.startPolling();
1133
890
  }
@@ -1137,8 +894,8 @@ var IndexedDBLocalPersistence = /** @class */ (function () {
1137
894
  void this._get(key); // This can happen in the background async and we can return immediately.
1138
895
  }
1139
896
  this.listeners[key].add(listener);
1140
- };
1141
- IndexedDBLocalPersistence.prototype._removeListener = function (key, listener) {
897
+ }
898
+ _removeListener(key, listener) {
1142
899
  if (this.listeners[key]) {
1143
900
  this.listeners[key].delete(listener);
1144
901
  if (this.listeners[key].size === 0) {
@@ -1148,17 +905,16 @@ var IndexedDBLocalPersistence = /** @class */ (function () {
1148
905
  if (Object.keys(this.listeners).length === 0) {
1149
906
  this.stopPolling();
1150
907
  }
1151
- };
1152
- IndexedDBLocalPersistence.type = 'LOCAL';
1153
- return IndexedDBLocalPersistence;
1154
- }());
908
+ }
909
+ }
910
+ IndexedDBLocalPersistence.type = 'LOCAL';
1155
911
  /**
1156
912
  * An implementation of {@link Persistence} of type `LOCAL` using `indexedDB`
1157
913
  * for the underlying storage.
1158
914
  *
1159
915
  * @public
1160
916
  */
1161
- var indexedDBLocalPersistence = IndexedDBLocalPersistence;
917
+ const indexedDBLocalPersistence = IndexedDBLocalPersistence;
1162
918
 
1163
919
  /**
1164
920
  * @license
@@ -1205,24 +961,22 @@ function _withDefaultResolver(auth, resolverOverride) {
1205
961
  * See the License for the specific language governing permissions and
1206
962
  * limitations under the License.
1207
963
  */
1208
- var IdpCredential = /** @class */ (function (_super) {
1209
- tslib.__extends(IdpCredential, _super);
1210
- function IdpCredential(params) {
1211
- var _this = _super.call(this, "custom" /* ProviderId.CUSTOM */, "custom" /* ProviderId.CUSTOM */) || this;
1212
- _this.params = params;
1213
- return _this;
1214
- }
1215
- IdpCredential.prototype._getIdTokenResponse = function (auth) {
964
+ class IdpCredential extends index.AuthCredential {
965
+ constructor(params) {
966
+ super("custom" /* ProviderId.CUSTOM */, "custom" /* ProviderId.CUSTOM */);
967
+ this.params = params;
968
+ }
969
+ _getIdTokenResponse(auth) {
1216
970
  return index.signInWithIdp(auth, this._buildIdpRequest());
1217
- };
1218
- IdpCredential.prototype._linkToIdToken = function (auth, idToken) {
971
+ }
972
+ _linkToIdToken(auth, idToken) {
1219
973
  return index.signInWithIdp(auth, this._buildIdpRequest(idToken));
1220
- };
1221
- IdpCredential.prototype._getReauthenticationResolver = function (auth) {
974
+ }
975
+ _getReauthenticationResolver(auth) {
1222
976
  return index.signInWithIdp(auth, this._buildIdpRequest());
1223
- };
1224
- IdpCredential.prototype._buildIdpRequest = function (idToken) {
1225
- var request = {
977
+ }
978
+ _buildIdpRequest(idToken) {
979
+ const request = {
1226
980
  requestUri: this.params.requestUri,
1227
981
  sessionId: this.params.sessionId,
1228
982
  postBody: this.params.postBody,
@@ -1235,26 +989,20 @@ var IdpCredential = /** @class */ (function (_super) {
1235
989
  request.idToken = idToken;
1236
990
  }
1237
991
  return request;
1238
- };
1239
- return IdpCredential;
1240
- }(index.AuthCredential));
992
+ }
993
+ }
1241
994
  function _signIn(params) {
1242
995
  return index._signInWithCredential(params.auth, new IdpCredential(params), params.bypassAuthState);
1243
996
  }
1244
997
  function _reauth(params) {
1245
- var auth = params.auth, user = params.user;
998
+ const { auth, user } = params;
1246
999
  index._assert(user, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
1247
1000
  return index._reauthenticate(user, new IdpCredential(params), params.bypassAuthState);
1248
1001
  }
1249
- function _link(params) {
1250
- return tslib.__awaiter(this, void 0, void 0, function () {
1251
- var auth, user;
1252
- return tslib.__generator(this, function (_a) {
1253
- auth = params.auth, user = params.user;
1254
- index._assert(user, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
1255
- return [2 /*return*/, index._link(user, new IdpCredential(params), params.bypassAuthState)];
1256
- });
1257
- });
1002
+ async function _link(params) {
1003
+ const { auth, user } = params;
1004
+ index._assert(user, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
1005
+ return index._link(user, new IdpCredential(params), params.bypassAuthState);
1258
1006
  }
1259
1007
 
1260
1008
  /**
@@ -1277,9 +1025,8 @@ function _link(params) {
1277
1025
  * Popup event manager. Handles the popup's entire lifecycle; listens to auth
1278
1026
  * events
1279
1027
  */
1280
- var AbstractPopupRedirectOperation = /** @class */ (function () {
1281
- function AbstractPopupRedirectOperation(auth, filter, resolver, user, bypassAuthState) {
1282
- if (bypassAuthState === void 0) { bypassAuthState = false; }
1028
+ class AbstractPopupRedirectOperation {
1029
+ constructor(auth, filter, resolver, user, bypassAuthState = false) {
1283
1030
  this.auth = auth;
1284
1031
  this.resolver = resolver;
1285
1032
  this.user = user;
@@ -1288,76 +1035,45 @@ var AbstractPopupRedirectOperation = /** @class */ (function () {
1288
1035
  this.eventManager = null;
1289
1036
  this.filter = Array.isArray(filter) ? filter : [filter];
1290
1037
  }
1291
- AbstractPopupRedirectOperation.prototype.execute = function () {
1292
- var _this = this;
1293
- return new Promise(function (resolve, reject) { return tslib.__awaiter(_this, void 0, void 0, function () {
1294
- var _a, e_1;
1295
- return tslib.__generator(this, function (_b) {
1296
- switch (_b.label) {
1297
- case 0:
1298
- this.pendingPromise = { resolve: resolve, reject: reject };
1299
- _b.label = 1;
1300
- case 1:
1301
- _b.trys.push([1, 4, , 5]);
1302
- _a = this;
1303
- return [4 /*yield*/, this.resolver._initialize(this.auth)];
1304
- case 2:
1305
- _a.eventManager = _b.sent();
1306
- return [4 /*yield*/, this.onExecution()];
1307
- case 3:
1308
- _b.sent();
1309
- this.eventManager.registerConsumer(this);
1310
- return [3 /*break*/, 5];
1311
- case 4:
1312
- e_1 = _b.sent();
1313
- this.reject(e_1);
1314
- return [3 /*break*/, 5];
1315
- case 5: return [2 /*return*/];
1316
- }
1317
- });
1318
- }); });
1319
- };
1320
- AbstractPopupRedirectOperation.prototype.onAuthEvent = function (event) {
1321
- return tslib.__awaiter(this, void 0, void 0, function () {
1322
- var urlResponse, sessionId, postBody, tenantId, error, type, params, _a, e_2;
1323
- return tslib.__generator(this, function (_b) {
1324
- switch (_b.label) {
1325
- case 0:
1326
- urlResponse = event.urlResponse, sessionId = event.sessionId, postBody = event.postBody, tenantId = event.tenantId, error = event.error, type = event.type;
1327
- if (error) {
1328
- this.reject(error);
1329
- return [2 /*return*/];
1330
- }
1331
- params = {
1332
- auth: this.auth,
1333
- requestUri: urlResponse,
1334
- sessionId: sessionId,
1335
- tenantId: tenantId || undefined,
1336
- postBody: postBody || undefined,
1337
- user: this.user,
1338
- bypassAuthState: this.bypassAuthState
1339
- };
1340
- _b.label = 1;
1341
- case 1:
1342
- _b.trys.push([1, 3, , 4]);
1343
- _a = this.resolve;
1344
- return [4 /*yield*/, this.getIdpTask(type)(params)];
1345
- case 2:
1346
- _a.apply(this, [_b.sent()]);
1347
- return [3 /*break*/, 4];
1348
- case 3:
1349
- e_2 = _b.sent();
1350
- this.reject(e_2);
1351
- return [3 /*break*/, 4];
1352
- case 4: return [2 /*return*/];
1353
- }
1354
- });
1038
+ execute() {
1039
+ return new Promise(async (resolve, reject) => {
1040
+ this.pendingPromise = { resolve, reject };
1041
+ try {
1042
+ this.eventManager = await this.resolver._initialize(this.auth);
1043
+ await this.onExecution();
1044
+ this.eventManager.registerConsumer(this);
1045
+ }
1046
+ catch (e) {
1047
+ this.reject(e);
1048
+ }
1355
1049
  });
1356
- };
1357
- AbstractPopupRedirectOperation.prototype.onError = function (error) {
1050
+ }
1051
+ async onAuthEvent(event) {
1052
+ const { urlResponse, sessionId, postBody, tenantId, error, type } = event;
1053
+ if (error) {
1054
+ this.reject(error);
1055
+ return;
1056
+ }
1057
+ const params = {
1058
+ auth: this.auth,
1059
+ requestUri: urlResponse,
1060
+ sessionId: sessionId,
1061
+ tenantId: tenantId || undefined,
1062
+ postBody: postBody || undefined,
1063
+ user: this.user,
1064
+ bypassAuthState: this.bypassAuthState
1065
+ };
1066
+ try {
1067
+ this.resolve(await this.getIdpTask(type)(params));
1068
+ }
1069
+ catch (e) {
1070
+ this.reject(e);
1071
+ }
1072
+ }
1073
+ onError(error) {
1358
1074
  this.reject(error);
1359
- };
1360
- AbstractPopupRedirectOperation.prototype.getIdpTask = function (type) {
1075
+ }
1076
+ getIdpTask(type) {
1361
1077
  switch (type) {
1362
1078
  case "signInViaPopup" /* AuthEventType.SIGN_IN_VIA_POPUP */:
1363
1079
  case "signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */:
@@ -1371,26 +1087,25 @@ var AbstractPopupRedirectOperation = /** @class */ (function () {
1371
1087
  default:
1372
1088
  index._fail(this.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
1373
1089
  }
1374
- };
1375
- AbstractPopupRedirectOperation.prototype.resolve = function (cred) {
1090
+ }
1091
+ resolve(cred) {
1376
1092
  index.debugAssert(this.pendingPromise, 'Pending promise was never set');
1377
1093
  this.pendingPromise.resolve(cred);
1378
1094
  this.unregisterAndCleanUp();
1379
- };
1380
- AbstractPopupRedirectOperation.prototype.reject = function (error) {
1095
+ }
1096
+ reject(error) {
1381
1097
  index.debugAssert(this.pendingPromise, 'Pending promise was never set');
1382
1098
  this.pendingPromise.reject(error);
1383
1099
  this.unregisterAndCleanUp();
1384
- };
1385
- AbstractPopupRedirectOperation.prototype.unregisterAndCleanUp = function () {
1100
+ }
1101
+ unregisterAndCleanUp() {
1386
1102
  if (this.eventManager) {
1387
1103
  this.eventManager.unregisterConsumer(this);
1388
1104
  }
1389
1105
  this.pendingPromise = null;
1390
1106
  this.cleanUp();
1391
- };
1392
- return AbstractPopupRedirectOperation;
1393
- }());
1107
+ }
1108
+ }
1394
1109
 
1395
1110
  /**
1396
1111
  * @license
@@ -1408,7 +1123,7 @@ var AbstractPopupRedirectOperation = /** @class */ (function () {
1408
1123
  * See the License for the specific language governing permissions and
1409
1124
  * limitations under the License.
1410
1125
  */
1411
- var _POLL_WINDOW_CLOSE_TIMEOUT = new index.Delay(2000, 10000);
1126
+ const _POLL_WINDOW_CLOSE_TIMEOUT = new index.Delay(2000, 10000);
1412
1127
  /**
1413
1128
  * Authenticates a Firebase client using a popup-based OAuth authentication flow.
1414
1129
  *
@@ -1440,20 +1155,15 @@ var _POLL_WINDOW_CLOSE_TIMEOUT = new index.Delay(2000, 10000);
1440
1155
  *
1441
1156
  * @public
1442
1157
  */
1443
- function signInWithPopup(auth, provider, resolver) {
1444
- return tslib.__awaiter(this, void 0, void 0, function () {
1445
- var authInternal, resolverInternal, action;
1446
- return tslib.__generator(this, function (_a) {
1447
- if (app._isFirebaseServerApp(auth.app)) {
1448
- return [2 /*return*/, Promise.reject(index._createError(auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */))];
1449
- }
1450
- authInternal = index._castAuth(auth);
1451
- index._assertInstanceOf(auth, provider, index.FederatedAuthProvider);
1452
- resolverInternal = _withDefaultResolver(authInternal, resolver);
1453
- action = new PopupOperation(authInternal, "signInViaPopup" /* AuthEventType.SIGN_IN_VIA_POPUP */, provider, resolverInternal);
1454
- return [2 /*return*/, action.executeNotNull()];
1455
- });
1456
- });
1158
+ async function signInWithPopup(auth, provider, resolver) {
1159
+ if (app._isFirebaseServerApp(auth.app)) {
1160
+ return Promise.reject(index._createError(auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */));
1161
+ }
1162
+ const authInternal = index._castAuth(auth);
1163
+ index._assertInstanceOf(auth, provider, index.FederatedAuthProvider);
1164
+ const resolverInternal = _withDefaultResolver(authInternal, resolver);
1165
+ const action = new PopupOperation(authInternal, "signInViaPopup" /* AuthEventType.SIGN_IN_VIA_POPUP */, provider, resolverInternal);
1166
+ return action.executeNotNull();
1457
1167
  }
1458
1168
  /**
1459
1169
  * Reauthenticates the current user with the specified {@link OAuthProvider} using a pop-up based
@@ -1483,20 +1193,15 @@ function signInWithPopup(auth, provider, resolver) {
1483
1193
  *
1484
1194
  * @public
1485
1195
  */
1486
- function reauthenticateWithPopup(user, provider, resolver) {
1487
- return tslib.__awaiter(this, void 0, void 0, function () {
1488
- var userInternal, resolverInternal, action;
1489
- return tslib.__generator(this, function (_a) {
1490
- userInternal = util.getModularInstance(user);
1491
- if (app._isFirebaseServerApp(userInternal.auth.app)) {
1492
- return [2 /*return*/, Promise.reject(index._createError(userInternal.auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */))];
1493
- }
1494
- index._assertInstanceOf(userInternal.auth, provider, index.FederatedAuthProvider);
1495
- resolverInternal = _withDefaultResolver(userInternal.auth, resolver);
1496
- action = new PopupOperation(userInternal.auth, "reauthViaPopup" /* AuthEventType.REAUTH_VIA_POPUP */, provider, resolverInternal, userInternal);
1497
- return [2 /*return*/, action.executeNotNull()];
1498
- });
1499
- });
1196
+ async function reauthenticateWithPopup(user, provider, resolver) {
1197
+ const userInternal = util.getModularInstance(user);
1198
+ if (app._isFirebaseServerApp(userInternal.auth.app)) {
1199
+ return Promise.reject(index._createError(userInternal.auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */));
1200
+ }
1201
+ index._assertInstanceOf(userInternal.auth, provider, index.FederatedAuthProvider);
1202
+ const resolverInternal = _withDefaultResolver(userInternal.auth, resolver);
1203
+ const action = new PopupOperation(userInternal.auth, "reauthViaPopup" /* AuthEventType.REAUTH_VIA_POPUP */, provider, resolverInternal, userInternal);
1204
+ return action.executeNotNull();
1500
1205
  }
1501
1206
  /**
1502
1207
  * Links the authenticated provider to the user account using a pop-up based OAuth flow.
@@ -1523,99 +1228,66 @@ function reauthenticateWithPopup(user, provider, resolver) {
1523
1228
  *
1524
1229
  * @public
1525
1230
  */
1526
- function linkWithPopup(user, provider, resolver) {
1527
- return tslib.__awaiter(this, void 0, void 0, function () {
1528
- var userInternal, resolverInternal, action;
1529
- return tslib.__generator(this, function (_a) {
1530
- userInternal = util.getModularInstance(user);
1531
- index._assertInstanceOf(userInternal.auth, provider, index.FederatedAuthProvider);
1532
- resolverInternal = _withDefaultResolver(userInternal.auth, resolver);
1533
- action = new PopupOperation(userInternal.auth, "linkViaPopup" /* AuthEventType.LINK_VIA_POPUP */, provider, resolverInternal, userInternal);
1534
- return [2 /*return*/, action.executeNotNull()];
1535
- });
1536
- });
1231
+ async function linkWithPopup(user, provider, resolver) {
1232
+ const userInternal = util.getModularInstance(user);
1233
+ index._assertInstanceOf(userInternal.auth, provider, index.FederatedAuthProvider);
1234
+ const resolverInternal = _withDefaultResolver(userInternal.auth, resolver);
1235
+ const action = new PopupOperation(userInternal.auth, "linkViaPopup" /* AuthEventType.LINK_VIA_POPUP */, provider, resolverInternal, userInternal);
1236
+ return action.executeNotNull();
1537
1237
  }
1538
1238
  /**
1539
1239
  * Popup event manager. Handles the popup's entire lifecycle; listens to auth
1540
1240
  * events
1541
1241
  *
1542
1242
  */
1543
- var PopupOperation = /** @class */ (function (_super) {
1544
- tslib.__extends(PopupOperation, _super);
1545
- function PopupOperation(auth, filter, provider, resolver, user) {
1546
- var _this = _super.call(this, auth, filter, resolver, user) || this;
1547
- _this.provider = provider;
1548
- _this.authWindow = null;
1549
- _this.pollId = null;
1243
+ class PopupOperation extends AbstractPopupRedirectOperation {
1244
+ constructor(auth, filter, provider, resolver, user) {
1245
+ super(auth, filter, resolver, user);
1246
+ this.provider = provider;
1247
+ this.authWindow = null;
1248
+ this.pollId = null;
1550
1249
  if (PopupOperation.currentPopupAction) {
1551
1250
  PopupOperation.currentPopupAction.cancel();
1552
1251
  }
1553
- PopupOperation.currentPopupAction = _this;
1554
- return _this;
1555
- }
1556
- PopupOperation.prototype.executeNotNull = function () {
1557
- return tslib.__awaiter(this, void 0, void 0, function () {
1558
- var result;
1559
- return tslib.__generator(this, function (_a) {
1560
- switch (_a.label) {
1561
- case 0: return [4 /*yield*/, this.execute()];
1562
- case 1:
1563
- result = _a.sent();
1564
- index._assert(result, this.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
1565
- return [2 /*return*/, result];
1566
- }
1567
- });
1252
+ PopupOperation.currentPopupAction = this;
1253
+ }
1254
+ async executeNotNull() {
1255
+ const result = await this.execute();
1256
+ index._assert(result, this.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
1257
+ return result;
1258
+ }
1259
+ async onExecution() {
1260
+ index.debugAssert(this.filter.length === 1, 'Popup operations only handle one event');
1261
+ const eventId = _generateEventId();
1262
+ this.authWindow = await this.resolver._openPopup(this.auth, this.provider, this.filter[0], // There's always one, see constructor
1263
+ eventId);
1264
+ this.authWindow.associatedEvent = eventId;
1265
+ // Check for web storage support and origin validation _after_ the popup is
1266
+ // loaded. These operations are slow (~1 second or so) Rather than
1267
+ // waiting on them before opening the window, optimistically open the popup
1268
+ // and check for storage support at the same time. If storage support is
1269
+ // not available, this will cause the whole thing to reject properly. It
1270
+ // will also close the popup, but since the promise has already rejected,
1271
+ // the popup closed by user poll will reject into the void.
1272
+ this.resolver._originValidation(this.auth).catch(e => {
1273
+ this.reject(e);
1568
1274
  });
1569
- };
1570
- PopupOperation.prototype.onExecution = function () {
1571
- return tslib.__awaiter(this, void 0, void 0, function () {
1572
- var eventId, _a;
1573
- var _this = this;
1574
- return tslib.__generator(this, function (_b) {
1575
- switch (_b.label) {
1576
- case 0:
1577
- index.debugAssert(this.filter.length === 1, 'Popup operations only handle one event');
1578
- eventId = _generateEventId();
1579
- _a = this;
1580
- return [4 /*yield*/, this.resolver._openPopup(this.auth, this.provider, this.filter[0], // There's always one, see constructor
1581
- eventId)];
1582
- case 1:
1583
- _a.authWindow = _b.sent();
1584
- this.authWindow.associatedEvent = eventId;
1585
- // Check for web storage support and origin validation _after_ the popup is
1586
- // loaded. These operations are slow (~1 second or so) Rather than
1587
- // waiting on them before opening the window, optimistically open the popup
1588
- // and check for storage support at the same time. If storage support is
1589
- // not available, this will cause the whole thing to reject properly. It
1590
- // will also close the popup, but since the promise has already rejected,
1591
- // the popup closed by user poll will reject into the void.
1592
- this.resolver._originValidation(this.auth).catch(function (e) {
1593
- _this.reject(e);
1594
- });
1595
- this.resolver._isIframeWebStorageSupported(this.auth, function (isSupported) {
1596
- if (!isSupported) {
1597
- _this.reject(index._createError(_this.auth, "web-storage-unsupported" /* AuthErrorCode.WEB_STORAGE_UNSUPPORTED */));
1598
- }
1599
- });
1600
- // Handle user closure. Notice this does *not* use await
1601
- this.pollUserCancellation();
1602
- return [2 /*return*/];
1603
- }
1604
- });
1275
+ this.resolver._isIframeWebStorageSupported(this.auth, isSupported => {
1276
+ if (!isSupported) {
1277
+ this.reject(index._createError(this.auth, "web-storage-unsupported" /* AuthErrorCode.WEB_STORAGE_UNSUPPORTED */));
1278
+ }
1605
1279
  });
1606
- };
1607
- Object.defineProperty(PopupOperation.prototype, "eventId", {
1608
- get: function () {
1609
- var _a;
1610
- return ((_a = this.authWindow) === null || _a === void 0 ? void 0 : _a.associatedEvent) || null;
1611
- },
1612
- enumerable: false,
1613
- configurable: true
1614
- });
1615
- PopupOperation.prototype.cancel = function () {
1280
+ // Handle user closure. Notice this does *not* use await
1281
+ this.pollUserCancellation();
1282
+ }
1283
+ get eventId() {
1284
+ var _a;
1285
+ return ((_a = this.authWindow) === null || _a === void 0 ? void 0 : _a.associatedEvent) || null;
1286
+ }
1287
+ cancel() {
1616
1288
  this.reject(index._createError(this.auth, "cancelled-popup-request" /* AuthErrorCode.EXPIRED_POPUP_REQUEST */));
1617
- };
1618
- PopupOperation.prototype.cleanUp = function () {
1289
+ }
1290
+ cleanUp() {
1619
1291
  if (this.authWindow) {
1620
1292
  this.authWindow.close();
1621
1293
  }
@@ -1625,32 +1297,30 @@ var PopupOperation = /** @class */ (function (_super) {
1625
1297
  this.authWindow = null;
1626
1298
  this.pollId = null;
1627
1299
  PopupOperation.currentPopupAction = null;
1628
- };
1629
- PopupOperation.prototype.pollUserCancellation = function () {
1630
- var _this = this;
1631
- var poll = function () {
1300
+ }
1301
+ pollUserCancellation() {
1302
+ const poll = () => {
1632
1303
  var _a, _b;
1633
- if ((_b = (_a = _this.authWindow) === null || _a === void 0 ? void 0 : _a.window) === null || _b === void 0 ? void 0 : _b.closed) {
1304
+ if ((_b = (_a = this.authWindow) === null || _a === void 0 ? void 0 : _a.window) === null || _b === void 0 ? void 0 : _b.closed) {
1634
1305
  // Make sure that there is sufficient time for whatever action to
1635
1306
  // complete. The window could have closed but the sign in network
1636
1307
  // call could still be in flight. This is specifically true for
1637
1308
  // Firefox or if the opener is in an iframe, in which case the oauth
1638
1309
  // helper closes the popup.
1639
- _this.pollId = window.setTimeout(function () {
1640
- _this.pollId = null;
1641
- _this.reject(index._createError(_this.auth, "popup-closed-by-user" /* AuthErrorCode.POPUP_CLOSED_BY_USER */));
1310
+ this.pollId = window.setTimeout(() => {
1311
+ this.pollId = null;
1312
+ this.reject(index._createError(this.auth, "popup-closed-by-user" /* AuthErrorCode.POPUP_CLOSED_BY_USER */));
1642
1313
  }, 8000 /* _Timeout.AUTH_EVENT */);
1643
1314
  return;
1644
1315
  }
1645
- _this.pollId = window.setTimeout(poll, _POLL_WINDOW_CLOSE_TIMEOUT.get());
1316
+ this.pollId = window.setTimeout(poll, _POLL_WINDOW_CLOSE_TIMEOUT.get());
1646
1317
  };
1647
1318
  poll();
1648
- };
1649
- // Only one popup is ever shown at once. The lifecycle of the current popup
1650
- // can be managed / cancelled by the constructor.
1651
- PopupOperation.currentPopupAction = null;
1652
- return PopupOperation;
1653
- }(AbstractPopupRedirectOperation));
1319
+ }
1320
+ }
1321
+ // Only one popup is ever shown at once. The lifecycle of the current popup
1322
+ // can be managed / cancelled by the constructor.
1323
+ PopupOperation.currentPopupAction = null;
1654
1324
 
1655
1325
  /**
1656
1326
  * @license
@@ -1668,140 +1338,79 @@ var PopupOperation = /** @class */ (function (_super) {
1668
1338
  * See the License for the specific language governing permissions and
1669
1339
  * limitations under the License.
1670
1340
  */
1671
- var PENDING_REDIRECT_KEY = 'pendingRedirect';
1341
+ const PENDING_REDIRECT_KEY = 'pendingRedirect';
1672
1342
  // We only get one redirect outcome for any one auth, so just store it
1673
1343
  // in here.
1674
- var redirectOutcomeMap = new Map();
1675
- var RedirectAction = /** @class */ (function (_super) {
1676
- tslib.__extends(RedirectAction, _super);
1677
- function RedirectAction(auth, resolver, bypassAuthState) {
1678
- if (bypassAuthState === void 0) { bypassAuthState = false; }
1679
- var _this = _super.call(this, auth, [
1344
+ const redirectOutcomeMap = new Map();
1345
+ class RedirectAction extends AbstractPopupRedirectOperation {
1346
+ constructor(auth, resolver, bypassAuthState = false) {
1347
+ super(auth, [
1680
1348
  "signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */,
1681
1349
  "linkViaRedirect" /* AuthEventType.LINK_VIA_REDIRECT */,
1682
1350
  "reauthViaRedirect" /* AuthEventType.REAUTH_VIA_REDIRECT */,
1683
1351
  "unknown" /* AuthEventType.UNKNOWN */
1684
- ], resolver, undefined, bypassAuthState) || this;
1685
- _this.eventId = null;
1686
- return _this;
1352
+ ], resolver, undefined, bypassAuthState);
1353
+ this.eventId = null;
1687
1354
  }
1688
1355
  /**
1689
1356
  * Override the execute function; if we already have a redirect result, then
1690
1357
  * just return it.
1691
1358
  */
1692
- RedirectAction.prototype.execute = function () {
1693
- return tslib.__awaiter(this, void 0, void 0, function () {
1694
- var readyOutcome, hasPendingRedirect, result_1, _a, e_1;
1695
- return tslib.__generator(this, function (_b) {
1696
- switch (_b.label) {
1697
- case 0:
1698
- readyOutcome = redirectOutcomeMap.get(this.auth._key());
1699
- if (!!readyOutcome) return [3 /*break*/, 8];
1700
- _b.label = 1;
1701
- case 1:
1702
- _b.trys.push([1, 6, , 7]);
1703
- return [4 /*yield*/, _getAndClearPendingRedirectStatus(this.resolver, this.auth)];
1704
- case 2:
1705
- hasPendingRedirect = _b.sent();
1706
- if (!hasPendingRedirect) return [3 /*break*/, 4];
1707
- return [4 /*yield*/, _super.prototype.execute.call(this)];
1708
- case 3:
1709
- _a = _b.sent();
1710
- return [3 /*break*/, 5];
1711
- case 4:
1712
- _a = null;
1713
- _b.label = 5;
1714
- case 5:
1715
- result_1 = _a;
1716
- readyOutcome = function () { return Promise.resolve(result_1); };
1717
- return [3 /*break*/, 7];
1718
- case 6:
1719
- e_1 = _b.sent();
1720
- readyOutcome = function () { return Promise.reject(e_1); };
1721
- return [3 /*break*/, 7];
1722
- case 7:
1723
- redirectOutcomeMap.set(this.auth._key(), readyOutcome);
1724
- _b.label = 8;
1725
- case 8:
1726
- // If we're not bypassing auth state, the ready outcome should be set to
1727
- // null.
1728
- if (!this.bypassAuthState) {
1729
- redirectOutcomeMap.set(this.auth._key(), function () { return Promise.resolve(null); });
1730
- }
1731
- return [2 /*return*/, readyOutcome()];
1732
- }
1733
- });
1734
- });
1735
- };
1736
- RedirectAction.prototype.onAuthEvent = function (event) {
1737
- return tslib.__awaiter(this, void 0, void 0, function () {
1738
- var user;
1739
- return tslib.__generator(this, function (_a) {
1740
- switch (_a.label) {
1741
- case 0:
1742
- if (event.type === "signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */) {
1743
- return [2 /*return*/, _super.prototype.onAuthEvent.call(this, event)];
1744
- }
1745
- else if (event.type === "unknown" /* AuthEventType.UNKNOWN */) {
1746
- // This is a sentinel value indicating there's no pending redirect
1747
- this.resolve(null);
1748
- return [2 /*return*/];
1749
- }
1750
- if (!event.eventId) return [3 /*break*/, 2];
1751
- return [4 /*yield*/, this.auth._redirectUserForId(event.eventId)];
1752
- case 1:
1753
- user = _a.sent();
1754
- if (user) {
1755
- this.user = user;
1756
- return [2 /*return*/, _super.prototype.onAuthEvent.call(this, event)];
1757
- }
1758
- else {
1759
- this.resolve(null);
1760
- }
1761
- _a.label = 2;
1762
- case 2: return [2 /*return*/];
1763
- }
1764
- });
1765
- });
1766
- };
1767
- RedirectAction.prototype.onExecution = function () {
1768
- return tslib.__awaiter(this, void 0, void 0, function () { return tslib.__generator(this, function (_a) {
1769
- return [2 /*return*/];
1770
- }); });
1771
- };
1772
- RedirectAction.prototype.cleanUp = function () { };
1773
- return RedirectAction;
1774
- }(AbstractPopupRedirectOperation));
1775
- function _getAndClearPendingRedirectStatus(resolver, auth) {
1776
- return tslib.__awaiter(this, void 0, void 0, function () {
1777
- var key, persistence, hasPendingRedirect;
1778
- return tslib.__generator(this, function (_a) {
1779
- switch (_a.label) {
1780
- case 0:
1781
- key = pendingRedirectKey(auth);
1782
- persistence = resolverPersistence(resolver);
1783
- return [4 /*yield*/, persistence._isAvailable()];
1784
- case 1:
1785
- if (!(_a.sent())) {
1786
- return [2 /*return*/, false];
1787
- }
1788
- return [4 /*yield*/, persistence._get(key)];
1789
- case 2:
1790
- hasPendingRedirect = (_a.sent()) === 'true';
1791
- return [4 /*yield*/, persistence._remove(key)];
1792
- case 3:
1793
- _a.sent();
1794
- return [2 /*return*/, hasPendingRedirect];
1359
+ async execute() {
1360
+ let readyOutcome = redirectOutcomeMap.get(this.auth._key());
1361
+ if (!readyOutcome) {
1362
+ try {
1363
+ const hasPendingRedirect = await _getAndClearPendingRedirectStatus(this.resolver, this.auth);
1364
+ const result = hasPendingRedirect ? await super.execute() : null;
1365
+ readyOutcome = () => Promise.resolve(result);
1795
1366
  }
1796
- });
1797
- });
1367
+ catch (e) {
1368
+ readyOutcome = () => Promise.reject(e);
1369
+ }
1370
+ redirectOutcomeMap.set(this.auth._key(), readyOutcome);
1371
+ }
1372
+ // If we're not bypassing auth state, the ready outcome should be set to
1373
+ // null.
1374
+ if (!this.bypassAuthState) {
1375
+ redirectOutcomeMap.set(this.auth._key(), () => Promise.resolve(null));
1376
+ }
1377
+ return readyOutcome();
1378
+ }
1379
+ async onAuthEvent(event) {
1380
+ if (event.type === "signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */) {
1381
+ return super.onAuthEvent(event);
1382
+ }
1383
+ else if (event.type === "unknown" /* AuthEventType.UNKNOWN */) {
1384
+ // This is a sentinel value indicating there's no pending redirect
1385
+ this.resolve(null);
1386
+ return;
1387
+ }
1388
+ if (event.eventId) {
1389
+ const user = await this.auth._redirectUserForId(event.eventId);
1390
+ if (user) {
1391
+ this.user = user;
1392
+ return super.onAuthEvent(event);
1393
+ }
1394
+ else {
1395
+ this.resolve(null);
1396
+ }
1397
+ }
1398
+ }
1399
+ async onExecution() { }
1400
+ cleanUp() { }
1798
1401
  }
1799
- function _setPendingRedirectStatus(resolver, auth) {
1800
- return tslib.__awaiter(this, void 0, void 0, function () {
1801
- return tslib.__generator(this, function (_a) {
1802
- return [2 /*return*/, resolverPersistence(resolver)._set(pendingRedirectKey(auth), 'true')];
1803
- });
1804
- });
1402
+ async function _getAndClearPendingRedirectStatus(resolver, auth) {
1403
+ const key = pendingRedirectKey(auth);
1404
+ const persistence = resolverPersistence(resolver);
1405
+ if (!(await persistence._isAvailable())) {
1406
+ return false;
1407
+ }
1408
+ const hasPendingRedirect = (await persistence._get(key)) === 'true';
1409
+ await persistence._remove(key);
1410
+ return hasPendingRedirect;
1411
+ }
1412
+ async function _setPendingRedirectStatus(resolver, auth) {
1413
+ return resolverPersistence(resolver)._set(pendingRedirectKey(auth), 'true');
1805
1414
  }
1806
1415
  function _clearRedirectOutcomes() {
1807
1416
  redirectOutcomeMap.clear();
@@ -1879,34 +1488,19 @@ function pendingRedirectKey(auth) {
1879
1488
  function signInWithRedirect(auth, provider, resolver) {
1880
1489
  return _signInWithRedirect(auth, provider, resolver);
1881
1490
  }
1882
- function _signInWithRedirect(auth, provider, resolver) {
1883
- return tslib.__awaiter(this, void 0, void 0, function () {
1884
- var authInternal, resolverInternal;
1885
- return tslib.__generator(this, function (_a) {
1886
- switch (_a.label) {
1887
- case 0:
1888
- if (app._isFirebaseServerApp(auth.app)) {
1889
- return [2 /*return*/, Promise.reject(index._serverAppCurrentUserOperationNotSupportedError(auth))];
1890
- }
1891
- authInternal = index._castAuth(auth);
1892
- index._assertInstanceOf(auth, provider, index.FederatedAuthProvider);
1893
- // Wait for auth initialization to complete, this will process pending redirects and clear the
1894
- // PENDING_REDIRECT_KEY in persistence. This should be completed before starting a new
1895
- // redirect and creating a PENDING_REDIRECT_KEY entry.
1896
- return [4 /*yield*/, authInternal._initializationPromise];
1897
- case 1:
1898
- // Wait for auth initialization to complete, this will process pending redirects and clear the
1899
- // PENDING_REDIRECT_KEY in persistence. This should be completed before starting a new
1900
- // redirect and creating a PENDING_REDIRECT_KEY entry.
1901
- _a.sent();
1902
- resolverInternal = _withDefaultResolver(authInternal, resolver);
1903
- return [4 /*yield*/, _setPendingRedirectStatus(resolverInternal, authInternal)];
1904
- case 2:
1905
- _a.sent();
1906
- return [2 /*return*/, resolverInternal._openRedirect(authInternal, provider, "signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */)];
1907
- }
1908
- });
1909
- });
1491
+ async function _signInWithRedirect(auth, provider, resolver) {
1492
+ if (app._isFirebaseServerApp(auth.app)) {
1493
+ return Promise.reject(index._serverAppCurrentUserOperationNotSupportedError(auth));
1494
+ }
1495
+ const authInternal = index._castAuth(auth);
1496
+ index._assertInstanceOf(auth, provider, index.FederatedAuthProvider);
1497
+ // Wait for auth initialization to complete, this will process pending redirects and clear the
1498
+ // PENDING_REDIRECT_KEY in persistence. This should be completed before starting a new
1499
+ // redirect and creating a PENDING_REDIRECT_KEY entry.
1500
+ await authInternal._initializationPromise;
1501
+ const resolverInternal = _withDefaultResolver(authInternal, resolver);
1502
+ await _setPendingRedirectStatus(resolverInternal, authInternal);
1503
+ return resolverInternal._openRedirect(authInternal, provider, "signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */);
1910
1504
  }
1911
1505
  /**
1912
1506
  * Reauthenticates the current user with the specified {@link OAuthProvider} using a full-page redirect flow.
@@ -1946,37 +1540,21 @@ function _signInWithRedirect(auth, provider, resolver) {
1946
1540
  function reauthenticateWithRedirect(user, provider, resolver) {
1947
1541
  return _reauthenticateWithRedirect(user, provider, resolver);
1948
1542
  }
1949
- function _reauthenticateWithRedirect(user, provider, resolver) {
1950
- return tslib.__awaiter(this, void 0, void 0, function () {
1951
- var userInternal, resolverInternal, eventId;
1952
- return tslib.__generator(this, function (_a) {
1953
- switch (_a.label) {
1954
- case 0:
1955
- userInternal = util.getModularInstance(user);
1956
- index._assertInstanceOf(userInternal.auth, provider, index.FederatedAuthProvider);
1957
- if (app._isFirebaseServerApp(userInternal.auth.app)) {
1958
- return [2 /*return*/, Promise.reject(index._serverAppCurrentUserOperationNotSupportedError(userInternal.auth))];
1959
- }
1960
- // Wait for auth initialization to complete, this will process pending redirects and clear the
1961
- // PENDING_REDIRECT_KEY in persistence. This should be completed before starting a new
1962
- // redirect and creating a PENDING_REDIRECT_KEY entry.
1963
- return [4 /*yield*/, userInternal.auth._initializationPromise];
1964
- case 1:
1965
- // Wait for auth initialization to complete, this will process pending redirects and clear the
1966
- // PENDING_REDIRECT_KEY in persistence. This should be completed before starting a new
1967
- // redirect and creating a PENDING_REDIRECT_KEY entry.
1968
- _a.sent();
1969
- resolverInternal = _withDefaultResolver(userInternal.auth, resolver);
1970
- return [4 /*yield*/, _setPendingRedirectStatus(resolverInternal, userInternal.auth)];
1971
- case 2:
1972
- _a.sent();
1973
- return [4 /*yield*/, prepareUserForRedirect(userInternal)];
1974
- case 3:
1975
- eventId = _a.sent();
1976
- return [2 /*return*/, resolverInternal._openRedirect(userInternal.auth, provider, "reauthViaRedirect" /* AuthEventType.REAUTH_VIA_REDIRECT */, eventId)];
1977
- }
1978
- });
1979
- });
1543
+ async function _reauthenticateWithRedirect(user, provider, resolver) {
1544
+ const userInternal = util.getModularInstance(user);
1545
+ index._assertInstanceOf(userInternal.auth, provider, index.FederatedAuthProvider);
1546
+ if (app._isFirebaseServerApp(userInternal.auth.app)) {
1547
+ return Promise.reject(index._serverAppCurrentUserOperationNotSupportedError(userInternal.auth));
1548
+ }
1549
+ // Wait for auth initialization to complete, this will process pending redirects and clear the
1550
+ // PENDING_REDIRECT_KEY in persistence. This should be completed before starting a new
1551
+ // redirect and creating a PENDING_REDIRECT_KEY entry.
1552
+ await userInternal.auth._initializationPromise;
1553
+ // Allow the resolver to error before persisting the redirect user
1554
+ const resolverInternal = _withDefaultResolver(userInternal.auth, resolver);
1555
+ await _setPendingRedirectStatus(resolverInternal, userInternal.auth);
1556
+ const eventId = await prepareUserForRedirect(userInternal);
1557
+ return resolverInternal._openRedirect(userInternal.auth, provider, "reauthViaRedirect" /* AuthEventType.REAUTH_VIA_REDIRECT */, eventId);
1980
1558
  }
1981
1559
  /**
1982
1560
  * Links the {@link OAuthProvider} to the user account using a full-page redirect flow.
@@ -2012,37 +1590,19 @@ function _reauthenticateWithRedirect(user, provider, resolver) {
2012
1590
  function linkWithRedirect(user, provider, resolver) {
2013
1591
  return _linkWithRedirect(user, provider, resolver);
2014
1592
  }
2015
- function _linkWithRedirect(user, provider, resolver) {
2016
- return tslib.__awaiter(this, void 0, void 0, function () {
2017
- var userInternal, resolverInternal, eventId;
2018
- return tslib.__generator(this, function (_a) {
2019
- switch (_a.label) {
2020
- case 0:
2021
- userInternal = util.getModularInstance(user);
2022
- index._assertInstanceOf(userInternal.auth, provider, index.FederatedAuthProvider);
2023
- // Wait for auth initialization to complete, this will process pending redirects and clear the
2024
- // PENDING_REDIRECT_KEY in persistence. This should be completed before starting a new
2025
- // redirect and creating a PENDING_REDIRECT_KEY entry.
2026
- return [4 /*yield*/, userInternal.auth._initializationPromise];
2027
- case 1:
2028
- // Wait for auth initialization to complete, this will process pending redirects and clear the
2029
- // PENDING_REDIRECT_KEY in persistence. This should be completed before starting a new
2030
- // redirect and creating a PENDING_REDIRECT_KEY entry.
2031
- _a.sent();
2032
- resolverInternal = _withDefaultResolver(userInternal.auth, resolver);
2033
- return [4 /*yield*/, index._assertLinkedStatus(false, userInternal, provider.providerId)];
2034
- case 2:
2035
- _a.sent();
2036
- return [4 /*yield*/, _setPendingRedirectStatus(resolverInternal, userInternal.auth)];
2037
- case 3:
2038
- _a.sent();
2039
- return [4 /*yield*/, prepareUserForRedirect(userInternal)];
2040
- case 4:
2041
- eventId = _a.sent();
2042
- return [2 /*return*/, resolverInternal._openRedirect(userInternal.auth, provider, "linkViaRedirect" /* AuthEventType.LINK_VIA_REDIRECT */, eventId)];
2043
- }
2044
- });
2045
- });
1593
+ async function _linkWithRedirect(user, provider, resolver) {
1594
+ const userInternal = util.getModularInstance(user);
1595
+ index._assertInstanceOf(userInternal.auth, provider, index.FederatedAuthProvider);
1596
+ // Wait for auth initialization to complete, this will process pending redirects and clear the
1597
+ // PENDING_REDIRECT_KEY in persistence. This should be completed before starting a new
1598
+ // redirect and creating a PENDING_REDIRECT_KEY entry.
1599
+ await userInternal.auth._initializationPromise;
1600
+ // Allow the resolver to error before persisting the redirect user
1601
+ const resolverInternal = _withDefaultResolver(userInternal.auth, resolver);
1602
+ await index._assertLinkedStatus(false, userInternal, provider.providerId);
1603
+ await _setPendingRedirectStatus(resolverInternal, userInternal.auth);
1604
+ const eventId = await prepareUserForRedirect(userInternal);
1605
+ return resolverInternal._openRedirect(userInternal.auth, provider, "linkViaRedirect" /* AuthEventType.LINK_VIA_REDIRECT */, eventId);
2046
1606
  }
2047
1607
  /**
2048
1608
  * Returns a {@link UserCredential} from the redirect-based sign-in flow.
@@ -2085,66 +1645,31 @@ function _linkWithRedirect(user, provider, resolver) {
2085
1645
  *
2086
1646
  * @public
2087
1647
  */
2088
- function getRedirectResult(auth, resolver) {
2089
- return tslib.__awaiter(this, void 0, void 0, function () {
2090
- return tslib.__generator(this, function (_a) {
2091
- switch (_a.label) {
2092
- case 0: return [4 /*yield*/, index._castAuth(auth)._initializationPromise];
2093
- case 1:
2094
- _a.sent();
2095
- return [2 /*return*/, _getRedirectResult(auth, resolver, false)];
2096
- }
2097
- });
2098
- });
1648
+ async function getRedirectResult(auth, resolver) {
1649
+ await index._castAuth(auth)._initializationPromise;
1650
+ return _getRedirectResult(auth, resolver, false);
2099
1651
  }
2100
- function _getRedirectResult(auth, resolverExtern, bypassAuthState) {
2101
- if (bypassAuthState === void 0) { bypassAuthState = false; }
2102
- return tslib.__awaiter(this, void 0, void 0, function () {
2103
- var authInternal, resolver, action, result;
2104
- return tslib.__generator(this, function (_a) {
2105
- switch (_a.label) {
2106
- case 0:
2107
- if (app._isFirebaseServerApp(auth.app)) {
2108
- return [2 /*return*/, Promise.reject(index._serverAppCurrentUserOperationNotSupportedError(auth))];
2109
- }
2110
- authInternal = index._castAuth(auth);
2111
- resolver = _withDefaultResolver(authInternal, resolverExtern);
2112
- action = new RedirectAction(authInternal, resolver, bypassAuthState);
2113
- return [4 /*yield*/, action.execute()];
2114
- case 1:
2115
- result = _a.sent();
2116
- if (!(result && !bypassAuthState)) return [3 /*break*/, 4];
2117
- delete result.user._redirectEventId;
2118
- return [4 /*yield*/, authInternal._persistUserIfCurrent(result.user)];
2119
- case 2:
2120
- _a.sent();
2121
- return [4 /*yield*/, authInternal._setRedirectUser(null, resolverExtern)];
2122
- case 3:
2123
- _a.sent();
2124
- _a.label = 4;
2125
- case 4: return [2 /*return*/, result];
2126
- }
2127
- });
2128
- });
1652
+ async function _getRedirectResult(auth, resolverExtern, bypassAuthState = false) {
1653
+ if (app._isFirebaseServerApp(auth.app)) {
1654
+ return Promise.reject(index._serverAppCurrentUserOperationNotSupportedError(auth));
1655
+ }
1656
+ const authInternal = index._castAuth(auth);
1657
+ const resolver = _withDefaultResolver(authInternal, resolverExtern);
1658
+ const action = new RedirectAction(authInternal, resolver, bypassAuthState);
1659
+ const result = await action.execute();
1660
+ if (result && !bypassAuthState) {
1661
+ delete result.user._redirectEventId;
1662
+ await authInternal._persistUserIfCurrent(result.user);
1663
+ await authInternal._setRedirectUser(null, resolverExtern);
1664
+ }
1665
+ return result;
2129
1666
  }
2130
- function prepareUserForRedirect(user) {
2131
- return tslib.__awaiter(this, void 0, void 0, function () {
2132
- var eventId;
2133
- return tslib.__generator(this, function (_a) {
2134
- switch (_a.label) {
2135
- case 0:
2136
- eventId = _generateEventId("".concat(user.uid, ":::"));
2137
- user._redirectEventId = eventId;
2138
- return [4 /*yield*/, user.auth._setRedirectUser(user)];
2139
- case 1:
2140
- _a.sent();
2141
- return [4 /*yield*/, user.auth._persistUserIfCurrent(user)];
2142
- case 2:
2143
- _a.sent();
2144
- return [2 /*return*/, eventId];
2145
- }
2146
- });
2147
- });
1667
+ async function prepareUserForRedirect(user) {
1668
+ const eventId = _generateEventId(`${user.uid}:::`);
1669
+ user._redirectEventId = eventId;
1670
+ await user.auth._setRedirectUser(user);
1671
+ await user.auth._persistUserIfCurrent(user);
1672
+ return eventId;
2148
1673
  }
2149
1674
 
2150
1675
  /**
@@ -2165,9 +1690,9 @@ function prepareUserForRedirect(user) {
2165
1690
  */
2166
1691
  // The amount of time to store the UIDs of seen events; this is
2167
1692
  // set to 10 min by default
2168
- var EVENT_DUPLICATION_CACHE_DURATION_MS = 10 * 60 * 1000;
2169
- var AuthEventManager = /** @class */ (function () {
2170
- function AuthEventManager(auth) {
1693
+ const EVENT_DUPLICATION_CACHE_DURATION_MS = 10 * 60 * 1000;
1694
+ class AuthEventManager {
1695
+ constructor(auth) {
2171
1696
  this.auth = auth;
2172
1697
  this.cachedEventUids = new Set();
2173
1698
  this.consumers = new Set();
@@ -2175,7 +1700,7 @@ var AuthEventManager = /** @class */ (function () {
2175
1700
  this.hasHandledPotentialRedirect = false;
2176
1701
  this.lastProcessedEventTime = Date.now();
2177
1702
  }
2178
- AuthEventManager.prototype.registerConsumer = function (authEventConsumer) {
1703
+ registerConsumer(authEventConsumer) {
2179
1704
  this.consumers.add(authEventConsumer);
2180
1705
  if (this.queuedRedirectEvent &&
2181
1706
  this.isEventForConsumer(this.queuedRedirectEvent, authEventConsumer)) {
@@ -2183,22 +1708,21 @@ var AuthEventManager = /** @class */ (function () {
2183
1708
  this.saveEventToCache(this.queuedRedirectEvent);
2184
1709
  this.queuedRedirectEvent = null;
2185
1710
  }
2186
- };
2187
- AuthEventManager.prototype.unregisterConsumer = function (authEventConsumer) {
1711
+ }
1712
+ unregisterConsumer(authEventConsumer) {
2188
1713
  this.consumers.delete(authEventConsumer);
2189
- };
2190
- AuthEventManager.prototype.onEvent = function (event) {
2191
- var _this = this;
1714
+ }
1715
+ onEvent(event) {
2192
1716
  // Check if the event has already been handled
2193
1717
  if (this.hasEventBeenHandled(event)) {
2194
1718
  return false;
2195
1719
  }
2196
- var handled = false;
2197
- this.consumers.forEach(function (consumer) {
2198
- if (_this.isEventForConsumer(event, consumer)) {
1720
+ let handled = false;
1721
+ this.consumers.forEach(consumer => {
1722
+ if (this.isEventForConsumer(event, consumer)) {
2199
1723
  handled = true;
2200
- _this.sendToConsumer(event, consumer);
2201
- _this.saveEventToCache(event);
1724
+ this.sendToConsumer(event, consumer);
1725
+ this.saveEventToCache(event);
2202
1726
  }
2203
1727
  });
2204
1728
  if (this.hasHandledPotentialRedirect || !isRedirectEvent(event)) {
@@ -2213,43 +1737,41 @@ var AuthEventManager = /** @class */ (function () {
2213
1737
  handled = true;
2214
1738
  }
2215
1739
  return handled;
2216
- };
2217
- AuthEventManager.prototype.sendToConsumer = function (event, consumer) {
1740
+ }
1741
+ sendToConsumer(event, consumer) {
2218
1742
  var _a;
2219
1743
  if (event.error && !isNullRedirectEvent(event)) {
2220
- var code = ((_a = event.error.code) === null || _a === void 0 ? void 0 : _a.split('auth/')[1]) ||
1744
+ const code = ((_a = event.error.code) === null || _a === void 0 ? void 0 : _a.split('auth/')[1]) ||
2221
1745
  "internal-error" /* AuthErrorCode.INTERNAL_ERROR */;
2222
1746
  consumer.onError(index._createError(this.auth, code));
2223
1747
  }
2224
1748
  else {
2225
1749
  consumer.onAuthEvent(event);
2226
1750
  }
2227
- };
2228
- AuthEventManager.prototype.isEventForConsumer = function (event, consumer) {
2229
- var eventIdMatches = consumer.eventId === null ||
1751
+ }
1752
+ isEventForConsumer(event, consumer) {
1753
+ const eventIdMatches = consumer.eventId === null ||
2230
1754
  (!!event.eventId && event.eventId === consumer.eventId);
2231
1755
  return consumer.filter.includes(event.type) && eventIdMatches;
2232
- };
2233
- AuthEventManager.prototype.hasEventBeenHandled = function (event) {
1756
+ }
1757
+ hasEventBeenHandled(event) {
2234
1758
  if (Date.now() - this.lastProcessedEventTime >=
2235
1759
  EVENT_DUPLICATION_CACHE_DURATION_MS) {
2236
1760
  this.cachedEventUids.clear();
2237
1761
  }
2238
1762
  return this.cachedEventUids.has(eventUid(event));
2239
- };
2240
- AuthEventManager.prototype.saveEventToCache = function (event) {
1763
+ }
1764
+ saveEventToCache(event) {
2241
1765
  this.cachedEventUids.add(eventUid(event));
2242
1766
  this.lastProcessedEventTime = Date.now();
2243
- };
2244
- return AuthEventManager;
2245
- }());
1767
+ }
1768
+ }
2246
1769
  function eventUid(e) {
2247
- return [e.type, e.eventId, e.sessionId, e.tenantId].filter(function (v) { return v; }).join('-');
1770
+ return [e.type, e.eventId, e.sessionId, e.tenantId].filter(v => v).join('-');
2248
1771
  }
2249
- function isNullRedirectEvent(_a) {
2250
- var type = _a.type, error = _a.error;
1772
+ function isNullRedirectEvent({ type, error }) {
2251
1773
  return (type === "unknown" /* AuthEventType.UNKNOWN */ &&
2252
- (error === null || error === void 0 ? void 0 : error.code) === "auth/".concat("no-auth-event" /* AuthErrorCode.NO_AUTH_EVENT */));
1774
+ (error === null || error === void 0 ? void 0 : error.code) === `auth/${"no-auth-event" /* AuthErrorCode.NO_AUTH_EVENT */}`);
2253
1775
  }
2254
1776
  function isRedirectEvent(event) {
2255
1777
  switch (event.type) {
@@ -2280,13 +1802,8 @@ function isRedirectEvent(event) {
2280
1802
  * See the License for the specific language governing permissions and
2281
1803
  * limitations under the License.
2282
1804
  */
2283
- function _getProjectConfig(auth, request) {
2284
- if (request === void 0) { request = {}; }
2285
- return tslib.__awaiter(this, void 0, void 0, function () {
2286
- return tslib.__generator(this, function (_a) {
2287
- return [2 /*return*/, index._performApiRequest(auth, "GET" /* HttpMethod.GET */, "/v1/projects" /* Endpoint.GET_PROJECT_CONFIG */, request)];
2288
- });
2289
- });
1805
+ async function _getProjectConfig(auth, request = {}) {
1806
+ return index._performApiRequest(auth, "GET" /* HttpMethod.GET */, "/v1/projects" /* Endpoint.GET_PROJECT_CONFIG */, request);
2290
1807
  }
2291
1808
 
2292
1809
  /**
@@ -2305,44 +1822,32 @@ function _getProjectConfig(auth, request) {
2305
1822
  * See the License for the specific language governing permissions and
2306
1823
  * limitations under the License.
2307
1824
  */
2308
- var IP_ADDRESS_REGEX = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
2309
- var HTTP_REGEX = /^https?/;
2310
- function _validateOrigin$1(auth) {
2311
- return tslib.__awaiter(this, void 0, void 0, function () {
2312
- var authorizedDomains, _i, authorizedDomains_1, domain;
2313
- return tslib.__generator(this, function (_a) {
2314
- switch (_a.label) {
2315
- case 0:
2316
- // Skip origin validation if we are in an emulated environment
2317
- if (auth.config.emulator) {
2318
- return [2 /*return*/];
2319
- }
2320
- return [4 /*yield*/, _getProjectConfig(auth)];
2321
- case 1:
2322
- authorizedDomains = (_a.sent()).authorizedDomains;
2323
- for (_i = 0, authorizedDomains_1 = authorizedDomains; _i < authorizedDomains_1.length; _i++) {
2324
- domain = authorizedDomains_1[_i];
2325
- try {
2326
- if (matchDomain(domain)) {
2327
- return [2 /*return*/];
2328
- }
2329
- }
2330
- catch (_b) {
2331
- // Do nothing if there's a URL error; just continue searching
2332
- }
2333
- }
2334
- // In the old SDK, this error also provides helpful messages.
2335
- index._fail(auth, "unauthorized-domain" /* AuthErrorCode.INVALID_ORIGIN */);
2336
- return [2 /*return*/];
1825
+ const IP_ADDRESS_REGEX = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
1826
+ const HTTP_REGEX = /^https?/;
1827
+ async function _validateOrigin$1(auth) {
1828
+ // Skip origin validation if we are in an emulated environment
1829
+ if (auth.config.emulator) {
1830
+ return;
1831
+ }
1832
+ const { authorizedDomains } = await _getProjectConfig(auth);
1833
+ for (const domain of authorizedDomains) {
1834
+ try {
1835
+ if (matchDomain(domain)) {
1836
+ return;
2337
1837
  }
2338
- });
2339
- });
1838
+ }
1839
+ catch (_a) {
1840
+ // Do nothing if there's a URL error; just continue searching
1841
+ }
1842
+ }
1843
+ // In the old SDK, this error also provides helpful messages.
1844
+ index._fail(auth, "unauthorized-domain" /* AuthErrorCode.INVALID_ORIGIN */);
2340
1845
  }
2341
1846
  function matchDomain(expected) {
2342
- var currentUrl = index._getCurrentUrl();
2343
- var _a = new URL(currentUrl), protocol = _a.protocol, hostname = _a.hostname;
1847
+ const currentUrl = index._getCurrentUrl();
1848
+ const { protocol, hostname } = new URL(currentUrl);
2344
1849
  if (expected.startsWith('chrome-extension://')) {
2345
- var ceUrl = new URL(expected);
1850
+ const ceUrl = new URL(expected);
2346
1851
  if (ceUrl.hostname === '' && hostname === '') {
2347
1852
  // For some reason we're not parsing chrome URLs properly
2348
1853
  return (protocol === 'chrome-extension:' &&
@@ -2360,10 +1865,10 @@ function matchDomain(expected) {
2360
1865
  return hostname === expected;
2361
1866
  }
2362
1867
  // Dots in pattern should be escaped.
2363
- var escapedDomainPattern = expected.replace(/\./g, '\\.');
1868
+ const escapedDomainPattern = expected.replace(/\./g, '\\.');
2364
1869
  // Non ip address domains.
2365
1870
  // domain.com = *.domain.com OR domain.com
2366
- var re = new RegExp('^(.+\\.' + escapedDomainPattern + '|' + escapedDomainPattern + ')$', 'i');
1871
+ const re = new RegExp('^(.+\\.' + escapedDomainPattern + '|' + escapedDomainPattern + ')$', 'i');
2367
1872
  return re.test(hostname);
2368
1873
  }
2369
1874
 
@@ -2383,7 +1888,7 @@ function matchDomain(expected) {
2383
1888
  * See the License for the specific language governing permissions and
2384
1889
  * limitations under the License.
2385
1890
  */
2386
- var NETWORK_TIMEOUT = new index.Delay(30000, 60000);
1891
+ const NETWORK_TIMEOUT = new index.Delay(30000, 60000);
2387
1892
  /**
2388
1893
  * Reset unloaded GApi modules. If gapi.load fails due to a network error,
2389
1894
  * it will stop working after a retrial. This is a hack to fix this issue.
@@ -2392,21 +1897,20 @@ function resetUnloadedGapiModules() {
2392
1897
  // Clear last failed gapi.load state to force next gapi.load to first
2393
1898
  // load the failed gapi.iframes module.
2394
1899
  // Get gapix.beacon context.
2395
- var beacon = index._window().___jsl;
1900
+ const beacon = index._window().___jsl;
2396
1901
  // Get current hint.
2397
1902
  if (beacon === null || beacon === void 0 ? void 0 : beacon.H) {
2398
1903
  // Get gapi hint.
2399
- for (var _i = 0, _a = Object.keys(beacon.H); _i < _a.length; _i++) {
2400
- var hint = _a[_i];
1904
+ for (const hint of Object.keys(beacon.H)) {
2401
1905
  // Requested modules.
2402
1906
  beacon.H[hint].r = beacon.H[hint].r || [];
2403
1907
  // Loaded modules.
2404
1908
  beacon.H[hint].L = beacon.H[hint].L || [];
2405
1909
  // Set requested modules to a copy of the loaded modules.
2406
- beacon.H[hint].r = tslib.__spreadArray([], beacon.H[hint].L, true);
1910
+ beacon.H[hint].r = [...beacon.H[hint].L];
2407
1911
  // Clear pending callbacks.
2408
1912
  if (beacon.CP) {
2409
- for (var i = 0; i < beacon.CP.length; i++) {
1913
+ for (let i = 0; i < beacon.CP.length; i++) {
2410
1914
  // Remove all failed pending callbacks.
2411
1915
  beacon.CP[i] = null;
2412
1916
  }
@@ -2415,7 +1919,7 @@ function resetUnloadedGapiModules() {
2415
1919
  }
2416
1920
  }
2417
1921
  function loadGapi(auth) {
2418
- return new Promise(function (resolve, reject) {
1922
+ return new Promise((resolve, reject) => {
2419
1923
  var _a, _b, _c;
2420
1924
  // Function to run when gapi.load is ready.
2421
1925
  function loadGapiIframe() {
@@ -2423,10 +1927,10 @@ function loadGapi(auth) {
2423
1927
  // Run this to fix that.
2424
1928
  resetUnloadedGapiModules();
2425
1929
  gapi.load('gapi.iframes', {
2426
- callback: function () {
1930
+ callback: () => {
2427
1931
  resolve(gapi.iframes.getContext());
2428
1932
  },
2429
- ontimeout: function () {
1933
+ ontimeout: () => {
2430
1934
  // The above reset may be sufficient, but having this reset after
2431
1935
  // failure ensures that if the developer calls gapi.load after the
2432
1936
  // connection is re-established and before another attempt to embed
@@ -2453,9 +1957,9 @@ function loadGapi(auth) {
2453
1957
  // multiple times in parallel and could result in the later callback
2454
1958
  // overwriting the previous one. This would end up with a iframe
2455
1959
  // timeout.
2456
- var cbName = index._generateCallbackName('iframefcb');
1960
+ const cbName = index._generateCallbackName('iframefcb');
2457
1961
  // GApi loader not available, dynamically load platform.js.
2458
- index._window()[cbName] = function () {
1962
+ index._window()[cbName] = () => {
2459
1963
  // GApi loader should be ready.
2460
1964
  if (!!gapi.load) {
2461
1965
  loadGapiIframe();
@@ -2466,16 +1970,16 @@ function loadGapi(auth) {
2466
1970
  }
2467
1971
  };
2468
1972
  // Load GApi loader.
2469
- return index._loadJS("".concat(index._gapiScriptUrl(), "?onload=").concat(cbName))
2470
- .catch(function (e) { return reject(e); });
1973
+ return index._loadJS(`${index._gapiScriptUrl()}?onload=${cbName}`)
1974
+ .catch(e => reject(e));
2471
1975
  }
2472
- }).catch(function (error) {
1976
+ }).catch(error => {
2473
1977
  // Reset cached promise to allow for retrial.
2474
1978
  cachedGApiLoader = null;
2475
1979
  throw error;
2476
1980
  });
2477
1981
  }
2478
- var cachedGApiLoader = null;
1982
+ let cachedGApiLoader = null;
2479
1983
  function _loadGapi(auth) {
2480
1984
  cachedGApiLoader = cachedGApiLoader || loadGapi(auth);
2481
1985
  return cachedGApiLoader;
@@ -2497,10 +2001,10 @@ function _loadGapi(auth) {
2497
2001
  * See the License for the specific language governing permissions and
2498
2002
  * limitations under the License.
2499
2003
  */
2500
- var PING_TIMEOUT = new index.Delay(5000, 15000);
2501
- var IFRAME_PATH = '__/auth/iframe';
2502
- var EMULATED_IFRAME_PATH = 'emulator/auth/iframe';
2503
- var IFRAME_ATTRIBUTES = {
2004
+ const PING_TIMEOUT = new index.Delay(5000, 15000);
2005
+ const IFRAME_PATH = '__/auth/iframe';
2006
+ const EMULATED_IFRAME_PATH = 'emulator/auth/iframe';
2007
+ const IFRAME_ATTRIBUTES = {
2504
2008
  style: {
2505
2009
  position: 'absolute',
2506
2010
  top: '-100px',
@@ -2512,82 +2016,64 @@ var IFRAME_ATTRIBUTES = {
2512
2016
  };
2513
2017
  // Map from apiHost to endpoint ID for passing into iframe. In current SDK, apiHost can be set to
2514
2018
  // anything (not from a list of endpoints with IDs as in legacy), so this is the closest we can get.
2515
- var EID_FROM_APIHOST = new Map([
2019
+ const EID_FROM_APIHOST = new Map([
2516
2020
  ["identitytoolkit.googleapis.com" /* DefaultConfig.API_HOST */, 'p'],
2517
2021
  ['staging-identitytoolkit.sandbox.googleapis.com', 's'],
2518
2022
  ['test-identitytoolkit.sandbox.googleapis.com', 't'] // test
2519
2023
  ]);
2520
2024
  function getIframeUrl(auth) {
2521
- var config = auth.config;
2025
+ const config = auth.config;
2522
2026
  index._assert(config.authDomain, auth, "auth-domain-config-required" /* AuthErrorCode.MISSING_AUTH_DOMAIN */);
2523
- var url = config.emulator
2027
+ const url = config.emulator
2524
2028
  ? index._emulatorUrl(config, EMULATED_IFRAME_PATH)
2525
- : "https://".concat(auth.config.authDomain, "/").concat(IFRAME_PATH);
2526
- var params = {
2029
+ : `https://${auth.config.authDomain}/${IFRAME_PATH}`;
2030
+ const params = {
2527
2031
  apiKey: config.apiKey,
2528
2032
  appName: auth.name,
2529
2033
  v: app.SDK_VERSION
2530
2034
  };
2531
- var eid = EID_FROM_APIHOST.get(auth.config.apiHost);
2035
+ const eid = EID_FROM_APIHOST.get(auth.config.apiHost);
2532
2036
  if (eid) {
2533
2037
  params.eid = eid;
2534
2038
  }
2535
- var frameworks = auth._getFrameworks();
2039
+ const frameworks = auth._getFrameworks();
2536
2040
  if (frameworks.length) {
2537
2041
  params.fw = frameworks.join(',');
2538
2042
  }
2539
- return "".concat(url, "?").concat(util.querystring(params).slice(1));
2043
+ return `${url}?${util.querystring(params).slice(1)}`;
2540
2044
  }
2541
- function _openIframe(auth) {
2542
- return tslib.__awaiter(this, void 0, void 0, function () {
2543
- var context, gapi;
2544
- var _this = this;
2545
- return tslib.__generator(this, function (_a) {
2546
- switch (_a.label) {
2547
- case 0: return [4 /*yield*/, _loadGapi(auth)];
2548
- case 1:
2549
- context = _a.sent();
2550
- gapi = index._window().gapi;
2551
- index._assert(gapi, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
2552
- return [2 /*return*/, context.open({
2553
- where: document.body,
2554
- url: getIframeUrl(auth),
2555
- messageHandlersFilter: gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER,
2556
- attributes: IFRAME_ATTRIBUTES,
2557
- dontclear: true
2558
- }, function (iframe) {
2559
- return new Promise(function (resolve, reject) { return tslib.__awaiter(_this, void 0, void 0, function () {
2560
- // Clear timer and resolve pending iframe ready promise.
2561
- function clearTimerAndResolve() {
2562
- index._window().clearTimeout(networkErrorTimer);
2563
- resolve(iframe);
2564
- }
2565
- var networkError, networkErrorTimer;
2566
- return tslib.__generator(this, function (_a) {
2567
- switch (_a.label) {
2568
- case 0: return [4 /*yield*/, iframe.restyle({
2569
- // Prevent iframe from closing on mouse out.
2570
- setHideOnLeave: false
2571
- })];
2572
- case 1:
2573
- _a.sent();
2574
- networkError = index._createError(auth, "network-request-failed" /* AuthErrorCode.NETWORK_REQUEST_FAILED */);
2575
- networkErrorTimer = index._window().setTimeout(function () {
2576
- reject(networkError);
2577
- }, PING_TIMEOUT.get());
2578
- // This returns an IThenable. However the reject part does not call
2579
- // when the iframe is not loaded.
2580
- iframe.ping(clearTimerAndResolve).then(clearTimerAndResolve, function () {
2581
- reject(networkError);
2582
- });
2583
- return [2 /*return*/];
2584
- }
2585
- });
2586
- }); });
2587
- })];
2588
- }
2045
+ async function _openIframe(auth) {
2046
+ const context = await _loadGapi(auth);
2047
+ const gapi = index._window().gapi;
2048
+ index._assert(gapi, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
2049
+ return context.open({
2050
+ where: document.body,
2051
+ url: getIframeUrl(auth),
2052
+ messageHandlersFilter: gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER,
2053
+ attributes: IFRAME_ATTRIBUTES,
2054
+ dontclear: true
2055
+ }, (iframe) => new Promise(async (resolve, reject) => {
2056
+ await iframe.restyle({
2057
+ // Prevent iframe from closing on mouse out.
2058
+ setHideOnLeave: false
2589
2059
  });
2590
- });
2060
+ const networkError = index._createError(auth, "network-request-failed" /* AuthErrorCode.NETWORK_REQUEST_FAILED */);
2061
+ // Confirm iframe is correctly loaded.
2062
+ // To fallback on failure, set a timeout.
2063
+ const networkErrorTimer = index._window().setTimeout(() => {
2064
+ reject(networkError);
2065
+ }, PING_TIMEOUT.get());
2066
+ // Clear timer and resolve pending iframe ready promise.
2067
+ function clearTimerAndResolve() {
2068
+ index._window().clearTimeout(networkErrorTimer);
2069
+ resolve(iframe);
2070
+ }
2071
+ // This returns an IThenable. However the reject part does not call
2072
+ // when the iframe is not loaded.
2073
+ iframe.ping(clearTimerAndResolve).then(clearTimerAndResolve, () => {
2074
+ reject(networkError);
2075
+ });
2076
+ }));
2591
2077
  }
2592
2078
 
2593
2079
  /**
@@ -2606,41 +2092,39 @@ function _openIframe(auth) {
2606
2092
  * See the License for the specific language governing permissions and
2607
2093
  * limitations under the License.
2608
2094
  */
2609
- var BASE_POPUP_OPTIONS = {
2095
+ const BASE_POPUP_OPTIONS = {
2610
2096
  location: 'yes',
2611
2097
  resizable: 'yes',
2612
2098
  statusbar: 'yes',
2613
2099
  toolbar: 'no'
2614
2100
  };
2615
- var DEFAULT_WIDTH = 500;
2616
- var DEFAULT_HEIGHT = 600;
2617
- var TARGET_BLANK = '_blank';
2618
- var FIREFOX_EMPTY_URL = 'http://localhost';
2619
- var AuthPopup = /** @class */ (function () {
2620
- function AuthPopup(window) {
2101
+ const DEFAULT_WIDTH = 500;
2102
+ const DEFAULT_HEIGHT = 600;
2103
+ const TARGET_BLANK = '_blank';
2104
+ const FIREFOX_EMPTY_URL = 'http://localhost';
2105
+ class AuthPopup {
2106
+ constructor(window) {
2621
2107
  this.window = window;
2622
2108
  this.associatedEvent = null;
2623
2109
  }
2624
- AuthPopup.prototype.close = function () {
2110
+ close() {
2625
2111
  if (this.window) {
2626
2112
  try {
2627
2113
  this.window.close();
2628
2114
  }
2629
2115
  catch (e) { }
2630
2116
  }
2631
- };
2632
- return AuthPopup;
2633
- }());
2634
- function _open(auth, url, name, width, height) {
2635
- if (width === void 0) { width = DEFAULT_WIDTH; }
2636
- if (height === void 0) { height = DEFAULT_HEIGHT; }
2637
- var top = Math.max((window.screen.availHeight - height) / 2, 0).toString();
2638
- var left = Math.max((window.screen.availWidth - width) / 2, 0).toString();
2639
- var target = '';
2640
- var options = tslib.__assign(tslib.__assign({}, BASE_POPUP_OPTIONS), { width: width.toString(), height: height.toString(), top: top, left: left });
2117
+ }
2118
+ }
2119
+ function _open(auth, url, name, width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT) {
2120
+ const top = Math.max((window.screen.availHeight - height) / 2, 0).toString();
2121
+ const left = Math.max((window.screen.availWidth - width) / 2, 0).toString();
2122
+ let target = '';
2123
+ const options = Object.assign(Object.assign({}, BASE_POPUP_OPTIONS), { width: width.toString(), height: height.toString(), top,
2124
+ left });
2641
2125
  // Chrome iOS 7 and 8 is returning an undefined popup win when target is
2642
2126
  // specified, even though the popup is not necessarily blocked.
2643
- var ua = util.getUA().toLowerCase();
2127
+ const ua = util.getUA().toLowerCase();
2644
2128
  if (name) {
2645
2129
  target = index._isChromeIOS(ua) ? TARGET_BLANK : name;
2646
2130
  }
@@ -2651,17 +2135,14 @@ function _open(auth, url, name, width, height) {
2651
2135
  // issues when the user has many Google accounts, for instance.
2652
2136
  options.scrollbars = 'yes';
2653
2137
  }
2654
- var optionsString = Object.entries(options).reduce(function (accum, _a) {
2655
- var key = _a[0], value = _a[1];
2656
- return "".concat(accum).concat(key, "=").concat(value, ",");
2657
- }, '');
2138
+ const optionsString = Object.entries(options).reduce((accum, [key, value]) => `${accum}${key}=${value},`, '');
2658
2139
  if (index._isIOSStandalone(ua) && target !== '_self') {
2659
2140
  openAsNewWindowIOS(url || '', target);
2660
2141
  return new AuthPopup(null);
2661
2142
  }
2662
2143
  // about:blank getting sanitized causing browsers like IE/Edge to display
2663
2144
  // brief error message before redirecting to handler.
2664
- var newWin = window.open(url || '', target, optionsString);
2145
+ const newWin = window.open(url || '', target, optionsString);
2665
2146
  index._assert(newWin, auth, "popup-blocked" /* AuthErrorCode.POPUP_BLOCKED */);
2666
2147
  // Flaky on IE edge, encapsulate with a try and catch.
2667
2148
  try {
@@ -2671,10 +2152,10 @@ function _open(auth, url, name, width, height) {
2671
2152
  return new AuthPopup(newWin);
2672
2153
  }
2673
2154
  function openAsNewWindowIOS(url, target) {
2674
- var el = document.createElement('a');
2155
+ const el = document.createElement('a');
2675
2156
  el.href = url;
2676
2157
  el.target = target;
2677
- var click = document.createEvent('MouseEvent');
2158
+ const click = document.createEvent('MouseEvent');
2678
2159
  click.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 1, null);
2679
2160
  el.dispatchEvent(click);
2680
2161
  }
@@ -2700,79 +2181,69 @@ function openAsNewWindowIOS(url, target) {
2700
2181
  *
2701
2182
  * @internal
2702
2183
  */
2703
- var WIDGET_PATH = '__/auth/handler';
2184
+ const WIDGET_PATH = '__/auth/handler';
2704
2185
  /**
2705
2186
  * URL for emulated environment
2706
2187
  *
2707
2188
  * @internal
2708
2189
  */
2709
- var EMULATOR_WIDGET_PATH = 'emulator/auth/handler';
2190
+ const EMULATOR_WIDGET_PATH = 'emulator/auth/handler';
2710
2191
  /**
2711
2192
  * Fragment name for the App Check token that gets passed to the widget
2712
2193
  *
2713
2194
  * @internal
2714
2195
  */
2715
- var FIREBASE_APP_CHECK_FRAGMENT_ID = encodeURIComponent('fac');
2716
- function _getRedirectUrl(auth, provider, authType, redirectUrl, eventId, additionalParams) {
2717
- return tslib.__awaiter(this, void 0, void 0, function () {
2718
- var params, _i, _a, _b, key, value, scopes, paramsDict, _c, _d, key, appCheckToken, appCheckTokenFragment;
2719
- return tslib.__generator(this, function (_e) {
2720
- switch (_e.label) {
2721
- case 0:
2722
- index._assert(auth.config.authDomain, auth, "auth-domain-config-required" /* AuthErrorCode.MISSING_AUTH_DOMAIN */);
2723
- index._assert(auth.config.apiKey, auth, "invalid-api-key" /* AuthErrorCode.INVALID_API_KEY */);
2724
- params = {
2725
- apiKey: auth.config.apiKey,
2726
- appName: auth.name,
2727
- authType: authType,
2728
- redirectUrl: redirectUrl,
2729
- v: app.SDK_VERSION,
2730
- eventId: eventId
2731
- };
2732
- if (provider instanceof index.FederatedAuthProvider) {
2733
- provider.setDefaultLanguage(auth.languageCode);
2734
- params.providerId = provider.providerId || '';
2735
- if (!util.isEmpty(provider.getCustomParameters())) {
2736
- params.customParameters = JSON.stringify(provider.getCustomParameters());
2737
- }
2738
- // TODO set additionalParams from the provider as well?
2739
- for (_i = 0, _a = Object.entries(additionalParams || {}); _i < _a.length; _i++) {
2740
- _b = _a[_i], key = _b[0], value = _b[1];
2741
- params[key] = value;
2742
- }
2743
- }
2744
- if (provider instanceof index.BaseOAuthProvider) {
2745
- scopes = provider.getScopes().filter(function (scope) { return scope !== ''; });
2746
- if (scopes.length > 0) {
2747
- params.scopes = scopes.join(',');
2748
- }
2749
- }
2750
- if (auth.tenantId) {
2751
- params.tid = auth.tenantId;
2752
- }
2753
- paramsDict = params;
2754
- for (_c = 0, _d = Object.keys(paramsDict); _c < _d.length; _c++) {
2755
- key = _d[_c];
2756
- if (paramsDict[key] === undefined) {
2757
- delete paramsDict[key];
2758
- }
2759
- }
2760
- return [4 /*yield*/, auth._getAppCheckToken()];
2761
- case 1:
2762
- appCheckToken = _e.sent();
2763
- appCheckTokenFragment = appCheckToken
2764
- ? "#".concat(FIREBASE_APP_CHECK_FRAGMENT_ID, "=").concat(encodeURIComponent(appCheckToken))
2765
- : '';
2766
- // Start at index 1 to skip the leading '&' in the query string
2767
- return [2 /*return*/, "".concat(getHandlerBase(auth), "?").concat(util.querystring(paramsDict).slice(1)).concat(appCheckTokenFragment)];
2768
- }
2769
- });
2770
- });
2196
+ const FIREBASE_APP_CHECK_FRAGMENT_ID = encodeURIComponent('fac');
2197
+ async function _getRedirectUrl(auth, provider, authType, redirectUrl, eventId, additionalParams) {
2198
+ index._assert(auth.config.authDomain, auth, "auth-domain-config-required" /* AuthErrorCode.MISSING_AUTH_DOMAIN */);
2199
+ index._assert(auth.config.apiKey, auth, "invalid-api-key" /* AuthErrorCode.INVALID_API_KEY */);
2200
+ const params = {
2201
+ apiKey: auth.config.apiKey,
2202
+ appName: auth.name,
2203
+ authType,
2204
+ redirectUrl,
2205
+ v: app.SDK_VERSION,
2206
+ eventId
2207
+ };
2208
+ if (provider instanceof index.FederatedAuthProvider) {
2209
+ provider.setDefaultLanguage(auth.languageCode);
2210
+ params.providerId = provider.providerId || '';
2211
+ if (!util.isEmpty(provider.getCustomParameters())) {
2212
+ params.customParameters = JSON.stringify(provider.getCustomParameters());
2213
+ }
2214
+ // TODO set additionalParams from the provider as well?
2215
+ for (const [key, value] of Object.entries(additionalParams || {})) {
2216
+ params[key] = value;
2217
+ }
2218
+ }
2219
+ if (provider instanceof index.BaseOAuthProvider) {
2220
+ const scopes = provider.getScopes().filter(scope => scope !== '');
2221
+ if (scopes.length > 0) {
2222
+ params.scopes = scopes.join(',');
2223
+ }
2224
+ }
2225
+ if (auth.tenantId) {
2226
+ params.tid = auth.tenantId;
2227
+ }
2228
+ // TODO: maybe set eid as endpointId
2229
+ // TODO: maybe set fw as Frameworks.join(",")
2230
+ const paramsDict = params;
2231
+ for (const key of Object.keys(paramsDict)) {
2232
+ if (paramsDict[key] === undefined) {
2233
+ delete paramsDict[key];
2234
+ }
2235
+ }
2236
+ // Sets the App Check token to pass to the widget
2237
+ const appCheckToken = await auth._getAppCheckToken();
2238
+ const appCheckTokenFragment = appCheckToken
2239
+ ? `#${FIREBASE_APP_CHECK_FRAGMENT_ID}=${encodeURIComponent(appCheckToken)}`
2240
+ : '';
2241
+ // Start at index 1 to skip the leading '&' in the query string
2242
+ return `${getHandlerBase(auth)}?${util.querystring(paramsDict).slice(1)}${appCheckTokenFragment}`;
2771
2243
  }
2772
- function getHandlerBase(_a) {
2773
- var config = _a.config;
2244
+ function getHandlerBase({ config }) {
2774
2245
  if (!config.emulator) {
2775
- return "https://".concat(config.authDomain, "/").concat(WIDGET_PATH);
2246
+ return `https://${config.authDomain}/${WIDGET_PATH}`;
2776
2247
  }
2777
2248
  return index._emulatorUrl(config, EMULATOR_WIDGET_PATH);
2778
2249
  }
@@ -2797,9 +2268,9 @@ function getHandlerBase(_a) {
2797
2268
  * The special web storage event
2798
2269
  *
2799
2270
  */
2800
- var WEB_STORAGE_SUPPORT_KEY = 'webStorageSupport';
2801
- var BrowserPopupRedirectResolver = /** @class */ (function () {
2802
- function BrowserPopupRedirectResolver() {
2271
+ const WEB_STORAGE_SUPPORT_KEY = 'webStorageSupport';
2272
+ class BrowserPopupRedirectResolver {
2273
+ constructor() {
2803
2274
  this.eventManagers = {};
2804
2275
  this.iframes = {};
2805
2276
  this.originValidationPromises = {};
@@ -2809,111 +2280,75 @@ var BrowserPopupRedirectResolver = /** @class */ (function () {
2809
2280
  }
2810
2281
  // Wrapping in async even though we don't await anywhere in order
2811
2282
  // to make sure errors are raised as promise rejections
2812
- BrowserPopupRedirectResolver.prototype._openPopup = function (auth, provider, authType, eventId) {
2283
+ async _openPopup(auth, provider, authType, eventId) {
2813
2284
  var _a;
2814
- return tslib.__awaiter(this, void 0, void 0, function () {
2815
- var url;
2816
- return tslib.__generator(this, function (_b) {
2817
- switch (_b.label) {
2818
- case 0:
2819
- index.debugAssert((_a = this.eventManagers[auth._key()]) === null || _a === void 0 ? void 0 : _a.manager, '_initialize() not called before _openPopup()');
2820
- return [4 /*yield*/, _getRedirectUrl(auth, provider, authType, index._getCurrentUrl(), eventId)];
2821
- case 1:
2822
- url = _b.sent();
2823
- return [2 /*return*/, _open(auth, url, _generateEventId())];
2824
- }
2825
- });
2826
- });
2827
- };
2828
- BrowserPopupRedirectResolver.prototype._openRedirect = function (auth, provider, authType, eventId) {
2829
- return tslib.__awaiter(this, void 0, void 0, function () {
2830
- var url;
2831
- return tslib.__generator(this, function (_a) {
2832
- switch (_a.label) {
2833
- case 0: return [4 /*yield*/, this._originValidation(auth)];
2834
- case 1:
2835
- _a.sent();
2836
- return [4 /*yield*/, _getRedirectUrl(auth, provider, authType, index._getCurrentUrl(), eventId)];
2837
- case 2:
2838
- url = _a.sent();
2839
- index._setWindowLocation(url);
2840
- return [2 /*return*/, new Promise(function () { })];
2841
- }
2842
- });
2843
- });
2844
- };
2845
- BrowserPopupRedirectResolver.prototype._initialize = function (auth) {
2846
- var _this = this;
2847
- var key = auth._key();
2285
+ index.debugAssert((_a = this.eventManagers[auth._key()]) === null || _a === void 0 ? void 0 : _a.manager, '_initialize() not called before _openPopup()');
2286
+ const url = await _getRedirectUrl(auth, provider, authType, index._getCurrentUrl(), eventId);
2287
+ return _open(auth, url, _generateEventId());
2288
+ }
2289
+ async _openRedirect(auth, provider, authType, eventId) {
2290
+ await this._originValidation(auth);
2291
+ const url = await _getRedirectUrl(auth, provider, authType, index._getCurrentUrl(), eventId);
2292
+ index._setWindowLocation(url);
2293
+ return new Promise(() => { });
2294
+ }
2295
+ _initialize(auth) {
2296
+ const key = auth._key();
2848
2297
  if (this.eventManagers[key]) {
2849
- var _a = this.eventManagers[key], manager = _a.manager, promise_1 = _a.promise;
2298
+ const { manager, promise } = this.eventManagers[key];
2850
2299
  if (manager) {
2851
2300
  return Promise.resolve(manager);
2852
2301
  }
2853
2302
  else {
2854
- index.debugAssert(promise_1, 'If manager is not set, promise should be');
2855
- return promise_1;
2303
+ index.debugAssert(promise, 'If manager is not set, promise should be');
2304
+ return promise;
2856
2305
  }
2857
2306
  }
2858
- var promise = this.initAndGetManager(auth);
2859
- this.eventManagers[key] = { promise: promise };
2307
+ const promise = this.initAndGetManager(auth);
2308
+ this.eventManagers[key] = { promise };
2860
2309
  // If the promise is rejected, the key should be removed so that the
2861
2310
  // operation can be retried later.
2862
- promise.catch(function () {
2863
- delete _this.eventManagers[key];
2311
+ promise.catch(() => {
2312
+ delete this.eventManagers[key];
2864
2313
  });
2865
2314
  return promise;
2866
- };
2867
- BrowserPopupRedirectResolver.prototype.initAndGetManager = function (auth) {
2868
- return tslib.__awaiter(this, void 0, void 0, function () {
2869
- var iframe, manager;
2870
- return tslib.__generator(this, function (_a) {
2871
- switch (_a.label) {
2872
- case 0: return [4 /*yield*/, _openIframe(auth)];
2873
- case 1:
2874
- iframe = _a.sent();
2875
- manager = new AuthEventManager(auth);
2876
- iframe.register('authEvent', function (iframeEvent) {
2877
- index._assert(iframeEvent === null || iframeEvent === void 0 ? void 0 : iframeEvent.authEvent, auth, "invalid-auth-event" /* AuthErrorCode.INVALID_AUTH_EVENT */);
2878
- // TODO: Consider splitting redirect and popup events earlier on
2879
- var handled = manager.onEvent(iframeEvent.authEvent);
2880
- return { status: handled ? "ACK" /* GapiOutcome.ACK */ : "ERROR" /* GapiOutcome.ERROR */ };
2881
- }, gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER);
2882
- this.eventManagers[auth._key()] = { manager: manager };
2883
- this.iframes[auth._key()] = iframe;
2884
- return [2 /*return*/, manager];
2885
- }
2886
- });
2887
- });
2888
- };
2889
- BrowserPopupRedirectResolver.prototype._isIframeWebStorageSupported = function (auth, cb) {
2890
- var iframe = this.iframes[auth._key()];
2891
- iframe.send(WEB_STORAGE_SUPPORT_KEY, { type: WEB_STORAGE_SUPPORT_KEY }, function (result) {
2315
+ }
2316
+ async initAndGetManager(auth) {
2317
+ const iframe = await _openIframe(auth);
2318
+ const manager = new AuthEventManager(auth);
2319
+ iframe.register('authEvent', (iframeEvent) => {
2320
+ index._assert(iframeEvent === null || iframeEvent === void 0 ? void 0 : iframeEvent.authEvent, auth, "invalid-auth-event" /* AuthErrorCode.INVALID_AUTH_EVENT */);
2321
+ // TODO: Consider splitting redirect and popup events earlier on
2322
+ const handled = manager.onEvent(iframeEvent.authEvent);
2323
+ return { status: handled ? "ACK" /* GapiOutcome.ACK */ : "ERROR" /* GapiOutcome.ERROR */ };
2324
+ }, gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER);
2325
+ this.eventManagers[auth._key()] = { manager };
2326
+ this.iframes[auth._key()] = iframe;
2327
+ return manager;
2328
+ }
2329
+ _isIframeWebStorageSupported(auth, cb) {
2330
+ const iframe = this.iframes[auth._key()];
2331
+ iframe.send(WEB_STORAGE_SUPPORT_KEY, { type: WEB_STORAGE_SUPPORT_KEY }, result => {
2892
2332
  var _a;
2893
- var isSupported = (_a = result === null || result === void 0 ? void 0 : result[0]) === null || _a === void 0 ? void 0 : _a[WEB_STORAGE_SUPPORT_KEY];
2333
+ const isSupported = (_a = result === null || result === void 0 ? void 0 : result[0]) === null || _a === void 0 ? void 0 : _a[WEB_STORAGE_SUPPORT_KEY];
2894
2334
  if (isSupported !== undefined) {
2895
2335
  cb(!!isSupported);
2896
2336
  }
2897
2337
  index._fail(auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
2898
2338
  }, gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER);
2899
- };
2900
- BrowserPopupRedirectResolver.prototype._originValidation = function (auth) {
2901
- var key = auth._key();
2339
+ }
2340
+ _originValidation(auth) {
2341
+ const key = auth._key();
2902
2342
  if (!this.originValidationPromises[key]) {
2903
2343
  this.originValidationPromises[key] = _validateOrigin$1(auth);
2904
2344
  }
2905
2345
  return this.originValidationPromises[key];
2906
- };
2907
- Object.defineProperty(BrowserPopupRedirectResolver.prototype, "_shouldInitProactively", {
2908
- get: function () {
2909
- // Mobile browsers and Safari need to optimistically initialize
2910
- return index._isMobileBrowser() || index._isSafari() || index._isIOS();
2911
- },
2912
- enumerable: false,
2913
- configurable: true
2914
- });
2915
- return BrowserPopupRedirectResolver;
2916
- }());
2346
+ }
2347
+ get _shouldInitProactively() {
2348
+ // Mobile browsers and Safari need to optimistically initialize
2349
+ return index._isMobileBrowser() || index._isSafari() || index._isIOS();
2350
+ }
2351
+ }
2917
2352
  /**
2918
2353
  * An implementation of {@link PopupRedirectResolver} suitable for browser
2919
2354
  * based applications.
@@ -2923,7 +2358,7 @@ var BrowserPopupRedirectResolver = /** @class */ (function () {
2923
2358
  *
2924
2359
  * @public
2925
2360
  */
2926
- var browserPopupRedirectResolver = BrowserPopupRedirectResolver;
2361
+ const browserPopupRedirectResolver = BrowserPopupRedirectResolver;
2927
2362
 
2928
2363
  /**
2929
2364
  * @license
@@ -2941,46 +2376,31 @@ var browserPopupRedirectResolver = BrowserPopupRedirectResolver;
2941
2376
  * See the License for the specific language governing permissions and
2942
2377
  * limitations under the License.
2943
2378
  */
2944
- var DEFAULT_ID_TOKEN_MAX_AGE = 5 * 60;
2945
- var authIdTokenMaxAge = util.getExperimentalSetting('authIdTokenMaxAge') || DEFAULT_ID_TOKEN_MAX_AGE;
2946
- var lastPostedIdToken = null;
2947
- var mintCookieFactory = function (url) { return function (user) { return tslib.__awaiter(void 0, void 0, void 0, function () {
2948
- var idTokenResult, _a, idTokenAge, idToken;
2949
- return tslib.__generator(this, function (_b) {
2950
- switch (_b.label) {
2951
- case 0:
2952
- _a = user;
2953
- if (!_a) return [3 /*break*/, 2];
2954
- return [4 /*yield*/, user.getIdTokenResult()];
2955
- case 1:
2956
- _a = (_b.sent());
2957
- _b.label = 2;
2958
- case 2:
2959
- idTokenResult = _a;
2960
- idTokenAge = idTokenResult &&
2961
- (new Date().getTime() - Date.parse(idTokenResult.issuedAtTime)) / 1000;
2962
- if (idTokenAge && idTokenAge > authIdTokenMaxAge) {
2963
- return [2 /*return*/];
2964
- }
2965
- idToken = idTokenResult === null || idTokenResult === void 0 ? void 0 : idTokenResult.token;
2966
- if (lastPostedIdToken === idToken) {
2967
- return [2 /*return*/];
2968
- }
2969
- lastPostedIdToken = idToken;
2970
- return [4 /*yield*/, fetch(url, {
2971
- method: idToken ? 'POST' : 'DELETE',
2972
- headers: idToken
2973
- ? {
2974
- 'Authorization': "Bearer ".concat(idToken)
2975
- }
2976
- : {}
2977
- })];
2978
- case 3:
2979
- _b.sent();
2980
- return [2 /*return*/];
2981
- }
2379
+ const DEFAULT_ID_TOKEN_MAX_AGE = 5 * 60;
2380
+ const authIdTokenMaxAge = util.getExperimentalSetting('authIdTokenMaxAge') || DEFAULT_ID_TOKEN_MAX_AGE;
2381
+ let lastPostedIdToken = null;
2382
+ const mintCookieFactory = (url) => async (user) => {
2383
+ const idTokenResult = user && (await user.getIdTokenResult());
2384
+ const idTokenAge = idTokenResult &&
2385
+ (new Date().getTime() - Date.parse(idTokenResult.issuedAtTime)) / 1000;
2386
+ if (idTokenAge && idTokenAge > authIdTokenMaxAge) {
2387
+ return;
2388
+ }
2389
+ // Specifically trip null => undefined when logged out, to delete any existing cookie
2390
+ const idToken = idTokenResult === null || idTokenResult === void 0 ? void 0 : idTokenResult.token;
2391
+ if (lastPostedIdToken === idToken) {
2392
+ return;
2393
+ }
2394
+ lastPostedIdToken = idToken;
2395
+ await fetch(url, {
2396
+ method: idToken ? 'POST' : 'DELETE',
2397
+ headers: idToken
2398
+ ? {
2399
+ 'Authorization': `Bearer ${idToken}`
2400
+ }
2401
+ : {}
2982
2402
  });
2983
- }); }; };
2403
+ };
2984
2404
  /**
2985
2405
  * Returns the Auth instance associated with the provided {@link @firebase/app#FirebaseApp}.
2986
2406
  * If no instance exists, initializes an Auth instance with platform-specific default dependencies.
@@ -2989,13 +2409,12 @@ var mintCookieFactory = function (url) { return function (user) { return tslib._
2989
2409
  *
2990
2410
  * @public
2991
2411
  */
2992
- function getAuth(app$1) {
2993
- if (app$1 === void 0) { app$1 = app.getApp(); }
2994
- var provider = app._getProvider(app$1, 'auth');
2412
+ function getAuth(app$1 = app.getApp()) {
2413
+ const provider = app._getProvider(app$1, 'auth');
2995
2414
  if (provider.isInitialized()) {
2996
2415
  return provider.getImmediate();
2997
2416
  }
2998
- var auth = index.initializeAuth(app$1, {
2417
+ const auth = index.initializeAuth(app$1, {
2999
2418
  popupRedirectResolver: browserPopupRedirectResolver,
3000
2419
  persistence: [
3001
2420
  indexedDBLocalPersistence,
@@ -3003,24 +2422,22 @@ function getAuth(app$1) {
3003
2422
  browserSessionPersistence
3004
2423
  ]
3005
2424
  });
3006
- var authTokenSyncPath = util.getExperimentalSetting('authTokenSyncURL');
2425
+ const authTokenSyncPath = util.getExperimentalSetting('authTokenSyncURL');
3007
2426
  // Only do the Cookie exchange in a secure context
3008
2427
  if (authTokenSyncPath &&
3009
2428
  typeof isSecureContext === 'boolean' &&
3010
2429
  isSecureContext) {
3011
2430
  // Don't allow urls (XSS possibility), only paths on the same domain
3012
- var authTokenSyncUrl = new URL(authTokenSyncPath, location.origin);
2431
+ const authTokenSyncUrl = new URL(authTokenSyncPath, location.origin);
3013
2432
  if (location.origin === authTokenSyncUrl.origin) {
3014
- var mintCookie_1 = mintCookieFactory(authTokenSyncUrl.toString());
3015
- index.beforeAuthStateChanged(auth, mintCookie_1, function () {
3016
- return mintCookie_1(auth.currentUser);
3017
- });
3018
- index.onIdTokenChanged(auth, function (user) { return mintCookie_1(user); });
2433
+ const mintCookie = mintCookieFactory(authTokenSyncUrl.toString());
2434
+ index.beforeAuthStateChanged(auth, mintCookie, () => mintCookie(auth.currentUser));
2435
+ index.onIdTokenChanged(auth, user => mintCookie(user));
3019
2436
  }
3020
2437
  }
3021
- var authEmulatorHost = util.getDefaultEmulatorHost('auth');
2438
+ const authEmulatorHost = util.getDefaultEmulatorHost('auth');
3022
2439
  if (authEmulatorHost) {
3023
- index.connectAuthEmulator(auth, "http://".concat(authEmulatorHost));
2440
+ index.connectAuthEmulator(auth, `http://${authEmulatorHost}`);
3024
2441
  }
3025
2442
  return auth;
3026
2443
  }
@@ -3029,14 +2446,14 @@ function getScriptParentElement() {
3029
2446
  return (_b = (_a = document.getElementsByTagName('head')) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : document;
3030
2447
  }
3031
2448
  index._setExternalJSProvider({
3032
- loadJS: function (url) {
2449
+ loadJS(url) {
3033
2450
  // TODO: consider adding timeout support & cancellation
3034
- return new Promise(function (resolve, reject) {
3035
- var el = document.createElement('script');
2451
+ return new Promise((resolve, reject) => {
2452
+ const el = document.createElement('script');
3036
2453
  el.setAttribute('src', url);
3037
2454
  el.onload = resolve;
3038
- el.onerror = function (e) {
3039
- var error = index._createError("internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
2455
+ el.onerror = e => {
2456
+ const error = index._createError("internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
3040
2457
  error.customData = e;
3041
2458
  reject(error);
3042
2459
  };
@@ -3091,81 +2508,60 @@ function _cordovaWindow() {
3091
2508
  * How long to wait after the app comes back into focus before concluding that
3092
2509
  * the user closed the sign in tab.
3093
2510
  */
3094
- var REDIRECT_TIMEOUT_MS = 2000;
2511
+ const REDIRECT_TIMEOUT_MS = 2000;
3095
2512
  /**
3096
2513
  * Generates the URL for the OAuth handler.
3097
2514
  */
3098
- function _generateHandlerUrl(auth, event, provider) {
2515
+ async function _generateHandlerUrl(auth, event, provider) {
3099
2516
  var _a;
3100
- return tslib.__awaiter(this, void 0, void 0, function () {
3101
- var BuildInfo, sessionDigest, additionalParams;
3102
- return tslib.__generator(this, function (_b) {
3103
- switch (_b.label) {
3104
- case 0:
3105
- BuildInfo = _cordovaWindow().BuildInfo;
3106
- index.debugAssert(event.sessionId, 'AuthEvent did not contain a session ID');
3107
- return [4 /*yield*/, computeSha256(event.sessionId)];
3108
- case 1:
3109
- sessionDigest = _b.sent();
3110
- additionalParams = {};
3111
- if (index._isIOS()) {
3112
- // iOS app identifier
3113
- additionalParams['ibi'] = BuildInfo.packageName;
3114
- }
3115
- else if (index._isAndroid()) {
3116
- // Android app identifier
3117
- additionalParams['apn'] = BuildInfo.packageName;
3118
- }
3119
- else {
3120
- index._fail(auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */);
3121
- }
3122
- // Add the display name if available
3123
- if (BuildInfo.displayName) {
3124
- additionalParams['appDisplayName'] = BuildInfo.displayName;
3125
- }
3126
- // Attached the hashed session ID
3127
- additionalParams['sessionId'] = sessionDigest;
3128
- return [2 /*return*/, _getRedirectUrl(auth, provider, event.type, undefined, (_a = event.eventId) !== null && _a !== void 0 ? _a : undefined, additionalParams)];
3129
- }
3130
- });
3131
- });
2517
+ // Get the cordova plugins
2518
+ const { BuildInfo } = _cordovaWindow();
2519
+ index.debugAssert(event.sessionId, 'AuthEvent did not contain a session ID');
2520
+ const sessionDigest = await computeSha256(event.sessionId);
2521
+ const additionalParams = {};
2522
+ if (index._isIOS()) {
2523
+ // iOS app identifier
2524
+ additionalParams['ibi'] = BuildInfo.packageName;
2525
+ }
2526
+ else if (index._isAndroid()) {
2527
+ // Android app identifier
2528
+ additionalParams['apn'] = BuildInfo.packageName;
2529
+ }
2530
+ else {
2531
+ index._fail(auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */);
2532
+ }
2533
+ // Add the display name if available
2534
+ if (BuildInfo.displayName) {
2535
+ additionalParams['appDisplayName'] = BuildInfo.displayName;
2536
+ }
2537
+ // Attached the hashed session ID
2538
+ additionalParams['sessionId'] = sessionDigest;
2539
+ return _getRedirectUrl(auth, provider, event.type, undefined, (_a = event.eventId) !== null && _a !== void 0 ? _a : undefined, additionalParams);
3132
2540
  }
3133
2541
  /**
3134
2542
  * Validates that this app is valid for this project configuration
3135
2543
  */
3136
- function _validateOrigin(auth) {
3137
- return tslib.__awaiter(this, void 0, void 0, function () {
3138
- var BuildInfo, request;
3139
- return tslib.__generator(this, function (_a) {
3140
- switch (_a.label) {
3141
- case 0:
3142
- BuildInfo = _cordovaWindow().BuildInfo;
3143
- request = {};
3144
- if (index._isIOS()) {
3145
- request.iosBundleId = BuildInfo.packageName;
3146
- }
3147
- else if (index._isAndroid()) {
3148
- request.androidPackageName = BuildInfo.packageName;
3149
- }
3150
- else {
3151
- index._fail(auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */);
3152
- }
3153
- // Will fail automatically if package name is not authorized
3154
- return [4 /*yield*/, _getProjectConfig(auth, request)];
3155
- case 1:
3156
- // Will fail automatically if package name is not authorized
3157
- _a.sent();
3158
- return [2 /*return*/];
3159
- }
3160
- });
3161
- });
2544
+ async function _validateOrigin(auth) {
2545
+ const { BuildInfo } = _cordovaWindow();
2546
+ const request = {};
2547
+ if (index._isIOS()) {
2548
+ request.iosBundleId = BuildInfo.packageName;
2549
+ }
2550
+ else if (index._isAndroid()) {
2551
+ request.androidPackageName = BuildInfo.packageName;
2552
+ }
2553
+ else {
2554
+ index._fail(auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */);
2555
+ }
2556
+ // Will fail automatically if package name is not authorized
2557
+ await _getProjectConfig(auth, request);
3162
2558
  }
3163
2559
  function _performRedirect(handlerUrl) {
3164
2560
  // Get the cordova plugins
3165
- var cordova = _cordovaWindow().cordova;
3166
- return new Promise(function (resolve) {
3167
- cordova.plugins.browsertab.isAvailable(function (browserTabIsAvailable) {
3168
- var iabRef = null;
2561
+ const { cordova } = _cordovaWindow();
2562
+ return new Promise(resolve => {
2563
+ cordova.plugins.browsertab.isAvailable(browserTabIsAvailable => {
2564
+ let iabRef = null;
3169
2565
  if (browserTabIsAvailable) {
3170
2566
  cordova.plugins.browsertab.openUrl(handlerUrl);
3171
2567
  }
@@ -3183,78 +2579,66 @@ function _performRedirect(handlerUrl) {
3183
2579
  * to be visible, this promise resolves. AFTER that resolution, the listeners
3184
2580
  * are detached and any browser tabs left open will be closed.
3185
2581
  */
3186
- function _waitForAppResume(auth, eventListener, iabRef) {
3187
- return tslib.__awaiter(this, void 0, void 0, function () {
3188
- var cordova, cleanup;
3189
- return tslib.__generator(this, function (_a) {
3190
- switch (_a.label) {
3191
- case 0:
3192
- cordova = _cordovaWindow().cordova;
3193
- cleanup = function () { };
3194
- _a.label = 1;
3195
- case 1:
3196
- _a.trys.push([1, , 3, 4]);
3197
- return [4 /*yield*/, new Promise(function (resolve, reject) {
3198
- var onCloseTimer = null;
3199
- // DEFINE ALL THE CALLBACKS =====
3200
- function authEventSeen() {
3201
- var _a;
3202
- // Auth event was detected. Resolve this promise and close the extra
3203
- // window if it's still open.
3204
- resolve();
3205
- var closeBrowserTab = (_a = cordova.plugins.browsertab) === null || _a === void 0 ? void 0 : _a.close;
3206
- if (typeof closeBrowserTab === 'function') {
3207
- closeBrowserTab();
3208
- }
3209
- // Close inappbrowser embedded webview in iOS7 and 8 case if still
3210
- // open.
3211
- if (typeof (iabRef === null || iabRef === void 0 ? void 0 : iabRef.close) === 'function') {
3212
- iabRef.close();
3213
- }
3214
- }
3215
- function resumed() {
3216
- if (onCloseTimer) {
3217
- // This code already ran; do not rerun.
3218
- return;
3219
- }
3220
- onCloseTimer = window.setTimeout(function () {
3221
- // Wait two seconds after resume then reject.
3222
- reject(index._createError(auth, "redirect-cancelled-by-user" /* AuthErrorCode.REDIRECT_CANCELLED_BY_USER */));
3223
- }, REDIRECT_TIMEOUT_MS);
3224
- }
3225
- function visibilityChanged() {
3226
- if ((document === null || document === void 0 ? void 0 : document.visibilityState) === 'visible') {
3227
- resumed();
3228
- }
3229
- }
3230
- // ATTACH ALL THE LISTENERS =====
3231
- // Listen for the auth event
3232
- eventListener.addPassiveListener(authEventSeen);
3233
- // Listen for resume and visibility events
3234
- document.addEventListener('resume', resumed, false);
3235
- if (index._isAndroid()) {
3236
- document.addEventListener('visibilitychange', visibilityChanged, false);
3237
- }
3238
- // SETUP THE CLEANUP FUNCTION =====
3239
- cleanup = function () {
3240
- eventListener.removePassiveListener(authEventSeen);
3241
- document.removeEventListener('resume', resumed, false);
3242
- document.removeEventListener('visibilitychange', visibilityChanged, false);
3243
- if (onCloseTimer) {
3244
- window.clearTimeout(onCloseTimer);
3245
- }
3246
- };
3247
- })];
3248
- case 2:
3249
- _a.sent();
3250
- return [3 /*break*/, 4];
3251
- case 3:
3252
- cleanup();
3253
- return [7 /*endfinally*/];
3254
- case 4: return [2 /*return*/];
2582
+ async function _waitForAppResume(auth, eventListener, iabRef) {
2583
+ // Get the cordova plugins
2584
+ const { cordova } = _cordovaWindow();
2585
+ let cleanup = () => { };
2586
+ try {
2587
+ await new Promise((resolve, reject) => {
2588
+ let onCloseTimer = null;
2589
+ // DEFINE ALL THE CALLBACKS =====
2590
+ function authEventSeen() {
2591
+ var _a;
2592
+ // Auth event was detected. Resolve this promise and close the extra
2593
+ // window if it's still open.
2594
+ resolve();
2595
+ const closeBrowserTab = (_a = cordova.plugins.browsertab) === null || _a === void 0 ? void 0 : _a.close;
2596
+ if (typeof closeBrowserTab === 'function') {
2597
+ closeBrowserTab();
2598
+ }
2599
+ // Close inappbrowser embedded webview in iOS7 and 8 case if still
2600
+ // open.
2601
+ if (typeof (iabRef === null || iabRef === void 0 ? void 0 : iabRef.close) === 'function') {
2602
+ iabRef.close();
2603
+ }
2604
+ }
2605
+ function resumed() {
2606
+ if (onCloseTimer) {
2607
+ // This code already ran; do not rerun.
2608
+ return;
2609
+ }
2610
+ onCloseTimer = window.setTimeout(() => {
2611
+ // Wait two seconds after resume then reject.
2612
+ reject(index._createError(auth, "redirect-cancelled-by-user" /* AuthErrorCode.REDIRECT_CANCELLED_BY_USER */));
2613
+ }, REDIRECT_TIMEOUT_MS);
2614
+ }
2615
+ function visibilityChanged() {
2616
+ if ((document === null || document === void 0 ? void 0 : document.visibilityState) === 'visible') {
2617
+ resumed();
2618
+ }
2619
+ }
2620
+ // ATTACH ALL THE LISTENERS =====
2621
+ // Listen for the auth event
2622
+ eventListener.addPassiveListener(authEventSeen);
2623
+ // Listen for resume and visibility events
2624
+ document.addEventListener('resume', resumed, false);
2625
+ if (index._isAndroid()) {
2626
+ document.addEventListener('visibilitychange', visibilityChanged, false);
3255
2627
  }
2628
+ // SETUP THE CLEANUP FUNCTION =====
2629
+ cleanup = () => {
2630
+ eventListener.removePassiveListener(authEventSeen);
2631
+ document.removeEventListener('resume', resumed, false);
2632
+ document.removeEventListener('visibilitychange', visibilityChanged, false);
2633
+ if (onCloseTimer) {
2634
+ window.clearTimeout(onCloseTimer);
2635
+ }
2636
+ };
3256
2637
  });
3257
- });
2638
+ }
2639
+ finally {
2640
+ cleanup();
2641
+ }
3258
2642
  }
3259
2643
  /**
3260
2644
  * Checks the configuration of the Cordova environment. This has no side effect
@@ -3263,7 +2647,7 @@ function _waitForAppResume(auth, eventListener, iabRef) {
3263
2647
  */
3264
2648
  function _checkCordovaConfiguration(auth) {
3265
2649
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
3266
- var win = _cordovaWindow();
2650
+ const win = _cordovaWindow();
3267
2651
  // Check all dependencies installed.
3268
2652
  // https://github.com/nordnet/cordova-universal-links-plugin
3269
2653
  // Note that cordova-universal-links-plugin has been abandoned.
@@ -3293,21 +2677,15 @@ function _checkCordovaConfiguration(auth) {
3293
2677
  * available in "secure" contexts, which covers Cordova (which is served on a file
3294
2678
  * protocol).
3295
2679
  */
3296
- function computeSha256(sessionId) {
3297
- return tslib.__awaiter(this, void 0, void 0, function () {
3298
- var bytes, buf, arr;
3299
- return tslib.__generator(this, function (_a) {
3300
- switch (_a.label) {
3301
- case 0:
3302
- bytes = stringToArrayBuffer(sessionId);
3303
- return [4 /*yield*/, crypto.subtle.digest('SHA-256', bytes)];
3304
- case 1:
3305
- buf = _a.sent();
3306
- arr = Array.from(new Uint8Array(buf));
3307
- return [2 /*return*/, arr.map(function (num) { return num.toString(16).padStart(2, '0'); }).join('')];
3308
- }
3309
- });
3310
- });
2680
+ async function computeSha256(sessionId) {
2681
+ const bytes = stringToArrayBuffer(sessionId);
2682
+ // TODO: For IE11 crypto has a different name and this operation comes back
2683
+ // as an object, not a promise. This is the old proposed standard that
2684
+ // is used by IE11:
2685
+ // https://www.w3.org/TR/2013/WD-WebCryptoAPI-20130108/#cryptooperation-interface
2686
+ const buf = await crypto.subtle.digest('SHA-256', bytes);
2687
+ const arr = Array.from(new Uint8Array(buf));
2688
+ return arr.map(num => num.toString(16).padStart(2, '0')).join('');
3311
2689
  }
3312
2690
  function stringToArrayBuffer(str) {
3313
2691
  // This function is only meant to deal with an ASCII charset and makes
@@ -3316,9 +2694,9 @@ function stringToArrayBuffer(str) {
3316
2694
  if (typeof TextEncoder !== 'undefined') {
3317
2695
  return new TextEncoder().encode(str);
3318
2696
  }
3319
- var buff = new ArrayBuffer(str.length);
3320
- var view = new Uint8Array(buff);
3321
- for (var i = 0; i < str.length; i++) {
2697
+ const buff = new ArrayBuffer(str.length);
2698
+ const view = new Uint8Array(buff);
2699
+ for (let i = 0; i < str.length; i++) {
3322
2700
  view[i] = str.charCodeAt(i);
3323
2701
  }
3324
2702
  return view;
@@ -3340,58 +2718,45 @@ function stringToArrayBuffer(str) {
3340
2718
  * See the License for the specific language governing permissions and
3341
2719
  * limitations under the License.
3342
2720
  */
3343
- var SESSION_ID_LENGTH = 20;
2721
+ const SESSION_ID_LENGTH = 20;
3344
2722
  /** Custom AuthEventManager that adds passive listeners to events */
3345
- var CordovaAuthEventManager = /** @class */ (function (_super) {
3346
- tslib.__extends(CordovaAuthEventManager, _super);
3347
- function CordovaAuthEventManager() {
3348
- var _this = _super !== null && _super.apply(this, arguments) || this;
3349
- _this.passiveListeners = new Set();
3350
- _this.initPromise = new Promise(function (resolve) {
3351
- _this.resolveInitialized = resolve;
2723
+ class CordovaAuthEventManager extends AuthEventManager {
2724
+ constructor() {
2725
+ super(...arguments);
2726
+ this.passiveListeners = new Set();
2727
+ this.initPromise = new Promise(resolve => {
2728
+ this.resolveInitialized = resolve;
3352
2729
  });
3353
- return _this;
3354
2730
  }
3355
- CordovaAuthEventManager.prototype.addPassiveListener = function (cb) {
2731
+ addPassiveListener(cb) {
3356
2732
  this.passiveListeners.add(cb);
3357
- };
3358
- CordovaAuthEventManager.prototype.removePassiveListener = function (cb) {
2733
+ }
2734
+ removePassiveListener(cb) {
3359
2735
  this.passiveListeners.delete(cb);
3360
- };
2736
+ }
3361
2737
  // In a Cordova environment, this manager can live through multiple redirect
3362
2738
  // operations
3363
- CordovaAuthEventManager.prototype.resetRedirect = function () {
2739
+ resetRedirect() {
3364
2740
  this.queuedRedirectEvent = null;
3365
2741
  this.hasHandledPotentialRedirect = false;
3366
- };
2742
+ }
3367
2743
  /** Override the onEvent method */
3368
- CordovaAuthEventManager.prototype.onEvent = function (event) {
2744
+ onEvent(event) {
3369
2745
  this.resolveInitialized();
3370
- this.passiveListeners.forEach(function (cb) { return cb(event); });
3371
- return _super.prototype.onEvent.call(this, event);
3372
- };
3373
- CordovaAuthEventManager.prototype.initialized = function () {
3374
- return tslib.__awaiter(this, void 0, void 0, function () {
3375
- return tslib.__generator(this, function (_a) {
3376
- switch (_a.label) {
3377
- case 0: return [4 /*yield*/, this.initPromise];
3378
- case 1:
3379
- _a.sent();
3380
- return [2 /*return*/];
3381
- }
3382
- });
3383
- });
3384
- };
3385
- return CordovaAuthEventManager;
3386
- }(AuthEventManager));
2746
+ this.passiveListeners.forEach(cb => cb(event));
2747
+ return super.onEvent(event);
2748
+ }
2749
+ async initialized() {
2750
+ await this.initPromise;
2751
+ }
2752
+ }
3387
2753
  /**
3388
2754
  * Generates a (partial) {@link AuthEvent}.
3389
2755
  */
3390
- function _generateNewEvent(auth, type, eventId) {
3391
- if (eventId === void 0) { eventId = null; }
2756
+ function _generateNewEvent(auth, type, eventId = null) {
3392
2757
  return {
3393
- type: type,
3394
- eventId: eventId,
2758
+ type,
2759
+ eventId,
3395
2760
  urlResponse: null,
3396
2761
  sessionId: generateSessionId(),
3397
2762
  postBody: null,
@@ -3402,28 +2767,17 @@ function _generateNewEvent(auth, type, eventId) {
3402
2767
  function _savePartialEvent(auth, event) {
3403
2768
  return storage()._set(persistenceKey(auth), event);
3404
2769
  }
3405
- function _getAndRemoveEvent(auth) {
3406
- return tslib.__awaiter(this, void 0, void 0, function () {
3407
- var event;
3408
- return tslib.__generator(this, function (_a) {
3409
- switch (_a.label) {
3410
- case 0: return [4 /*yield*/, storage()._get(persistenceKey(auth))];
3411
- case 1:
3412
- event = (_a.sent());
3413
- if (!event) return [3 /*break*/, 3];
3414
- return [4 /*yield*/, storage()._remove(persistenceKey(auth))];
3415
- case 2:
3416
- _a.sent();
3417
- _a.label = 3;
3418
- case 3: return [2 /*return*/, event];
3419
- }
3420
- });
3421
- });
2770
+ async function _getAndRemoveEvent(auth) {
2771
+ const event = (await storage()._get(persistenceKey(auth)));
2772
+ if (event) {
2773
+ await storage()._remove(persistenceKey(auth));
2774
+ }
2775
+ return event;
3422
2776
  }
3423
2777
  function _eventFromPartialAndUrl(partialEvent, url) {
3424
2778
  var _a, _b;
3425
2779
  // Parse the deep link within the dynamic link URL.
3426
- var callbackUrl = _getDeepLinkFromCallback(url);
2780
+ const callbackUrl = _getDeepLinkFromCallback(url);
3427
2781
  // Confirm it is actually a callback URL.
3428
2782
  // Currently the universal link will be of this format:
3429
2783
  // https://<AUTH_DOMAIN>/__/auth/callback<OAUTH_RESPONSE>
@@ -3433,19 +2787,19 @@ function _eventFromPartialAndUrl(partialEvent, url) {
3433
2787
  // Check if there is an error in the URL.
3434
2788
  // This mechanism is also used to pass errors back to the app:
3435
2789
  // https://<AUTH_DOMAIN>/__/auth/callback?firebaseError=<STRINGIFIED_ERROR>
3436
- var params = searchParamsOrEmpty(callbackUrl);
2790
+ const params = searchParamsOrEmpty(callbackUrl);
3437
2791
  // Get the error object corresponding to the stringified error if found.
3438
- var errorObject = params['firebaseError']
2792
+ const errorObject = params['firebaseError']
3439
2793
  ? parseJsonOrNull(decodeURIComponent(params['firebaseError']))
3440
2794
  : null;
3441
- var code = (_b = (_a = errorObject === null || errorObject === void 0 ? void 0 : errorObject['code']) === null || _a === void 0 ? void 0 : _a.split('auth/')) === null || _b === void 0 ? void 0 : _b[1];
3442
- var error = code ? index._createError(code) : null;
2795
+ const code = (_b = (_a = errorObject === null || errorObject === void 0 ? void 0 : errorObject['code']) === null || _a === void 0 ? void 0 : _a.split('auth/')) === null || _b === void 0 ? void 0 : _b[1];
2796
+ const error = code ? index._createError(code) : null;
3443
2797
  if (error) {
3444
2798
  return {
3445
2799
  type: partialEvent.type,
3446
2800
  eventId: partialEvent.eventId,
3447
2801
  tenantId: partialEvent.tenantId,
3448
- error: error,
2802
+ error,
3449
2803
  urlResponse: null,
3450
2804
  sessionId: null,
3451
2805
  postBody: null
@@ -3465,10 +2819,10 @@ function _eventFromPartialAndUrl(partialEvent, url) {
3465
2819
  return null;
3466
2820
  }
3467
2821
  function generateSessionId() {
3468
- var chars = [];
3469
- var allowedChars = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
3470
- for (var i = 0; i < SESSION_ID_LENGTH; i++) {
3471
- var idx = Math.floor(Math.random() * allowedChars.length);
2822
+ const chars = [];
2823
+ const allowedChars = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
2824
+ for (let i = 0; i < SESSION_ID_LENGTH; i++) {
2825
+ const idx = Math.floor(Math.random() * allowedChars.length);
3472
2826
  chars.push(allowedChars.charAt(idx));
3473
2827
  }
3474
2828
  return chars.join('');
@@ -3489,15 +2843,15 @@ function parseJsonOrNull(json) {
3489
2843
  }
3490
2844
  // Exported for testing
3491
2845
  function _getDeepLinkFromCallback(url) {
3492
- var params = searchParamsOrEmpty(url);
3493
- var link = params['link'] ? decodeURIComponent(params['link']) : undefined;
2846
+ const params = searchParamsOrEmpty(url);
2847
+ const link = params['link'] ? decodeURIComponent(params['link']) : undefined;
3494
2848
  // Double link case (automatic redirect)
3495
- var doubleDeepLink = searchParamsOrEmpty(link)['link'];
2849
+ const doubleDeepLink = searchParamsOrEmpty(link)['link'];
3496
2850
  // iOS custom scheme links.
3497
- var iOSDeepLink = params['deep_link_id']
2851
+ const iOSDeepLink = params['deep_link_id']
3498
2852
  ? decodeURIComponent(params['deep_link_id'])
3499
2853
  : undefined;
3500
- var iOSDoubleDeepLink = searchParamsOrEmpty(iOSDeepLink)['link'];
2854
+ const iOSDoubleDeepLink = searchParamsOrEmpty(iOSDeepLink)['link'];
3501
2855
  return iOSDoubleDeepLink || iOSDeepLink || doubleDeepLink || link || url;
3502
2856
  }
3503
2857
  /**
@@ -3508,7 +2862,7 @@ function searchParamsOrEmpty(url) {
3508
2862
  if (!(url === null || url === void 0 ? void 0 : url.includes('?'))) {
3509
2863
  return {};
3510
2864
  }
3511
- var _a = url.split('?'); _a[0]; var rest = _a.slice(1);
2865
+ const [_, ...rest] = url.split('?');
3512
2866
  return util.querystringDecode(rest.join('?'));
3513
2867
  }
3514
2868
 
@@ -3532,9 +2886,9 @@ function searchParamsOrEmpty(url) {
3532
2886
  * How long to wait for the initial auth event before concluding no
3533
2887
  * redirect pending
3534
2888
  */
3535
- var INITIAL_EVENT_TIMEOUT_MS = 500;
3536
- var CordovaPopupRedirectResolver = /** @class */ (function () {
3537
- function CordovaPopupRedirectResolver() {
2889
+ const INITIAL_EVENT_TIMEOUT_MS = 500;
2890
+ class CordovaPopupRedirectResolver {
2891
+ constructor() {
3538
2892
  this._redirectPersistence = browserSessionPersistence;
3539
2893
  this._shouldInitProactively = true; // This is lightweight for Cordova
3540
2894
  this.eventManagers = new Map();
@@ -3542,110 +2896,65 @@ var CordovaPopupRedirectResolver = /** @class */ (function () {
3542
2896
  this._completeRedirectFn = _getRedirectResult;
3543
2897
  this._overrideRedirectResult = _overrideRedirectResult;
3544
2898
  }
3545
- CordovaPopupRedirectResolver.prototype._initialize = function (auth) {
3546
- return tslib.__awaiter(this, void 0, void 0, function () {
3547
- var key, manager;
3548
- return tslib.__generator(this, function (_a) {
3549
- key = auth._key();
3550
- manager = this.eventManagers.get(key);
3551
- if (!manager) {
3552
- manager = new CordovaAuthEventManager(auth);
3553
- this.eventManagers.set(key, manager);
3554
- this.attachCallbackListeners(auth, manager);
3555
- }
3556
- return [2 /*return*/, manager];
3557
- });
3558
- });
3559
- };
3560
- CordovaPopupRedirectResolver.prototype._openPopup = function (auth) {
2899
+ async _initialize(auth) {
2900
+ const key = auth._key();
2901
+ let manager = this.eventManagers.get(key);
2902
+ if (!manager) {
2903
+ manager = new CordovaAuthEventManager(auth);
2904
+ this.eventManagers.set(key, manager);
2905
+ this.attachCallbackListeners(auth, manager);
2906
+ }
2907
+ return manager;
2908
+ }
2909
+ _openPopup(auth) {
3561
2910
  index._fail(auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */);
3562
- };
3563
- CordovaPopupRedirectResolver.prototype._openRedirect = function (auth, provider, authType, eventId) {
3564
- return tslib.__awaiter(this, void 0, void 0, function () {
3565
- var manager, event, url, iabRef;
3566
- return tslib.__generator(this, function (_a) {
3567
- switch (_a.label) {
3568
- case 0:
3569
- _checkCordovaConfiguration(auth);
3570
- return [4 /*yield*/, this._initialize(auth)];
3571
- case 1:
3572
- manager = _a.sent();
3573
- return [4 /*yield*/, manager.initialized()];
3574
- case 2:
3575
- _a.sent();
3576
- // Reset the persisted redirect states. This does not matter on Web where
3577
- // the redirect always blows away application state entirely. On Cordova,
3578
- // the app maintains control flow through the redirect.
3579
- manager.resetRedirect();
3580
- _clearRedirectOutcomes();
3581
- return [4 /*yield*/, this._originValidation(auth)];
3582
- case 3:
3583
- _a.sent();
3584
- event = _generateNewEvent(auth, authType, eventId);
3585
- return [4 /*yield*/, _savePartialEvent(auth, event)];
3586
- case 4:
3587
- _a.sent();
3588
- return [4 /*yield*/, _generateHandlerUrl(auth, event, provider)];
3589
- case 5:
3590
- url = _a.sent();
3591
- return [4 /*yield*/, _performRedirect(url)];
3592
- case 6:
3593
- iabRef = _a.sent();
3594
- return [2 /*return*/, _waitForAppResume(auth, manager, iabRef)];
3595
- }
3596
- });
3597
- });
3598
- };
3599
- CordovaPopupRedirectResolver.prototype._isIframeWebStorageSupported = function (_auth, _cb) {
2911
+ }
2912
+ async _openRedirect(auth, provider, authType, eventId) {
2913
+ _checkCordovaConfiguration(auth);
2914
+ const manager = await this._initialize(auth);
2915
+ await manager.initialized();
2916
+ // Reset the persisted redirect states. This does not matter on Web where
2917
+ // the redirect always blows away application state entirely. On Cordova,
2918
+ // the app maintains control flow through the redirect.
2919
+ manager.resetRedirect();
2920
+ _clearRedirectOutcomes();
2921
+ await this._originValidation(auth);
2922
+ const event = _generateNewEvent(auth, authType, eventId);
2923
+ await _savePartialEvent(auth, event);
2924
+ const url = await _generateHandlerUrl(auth, event, provider);
2925
+ const iabRef = await _performRedirect(url);
2926
+ return _waitForAppResume(auth, manager, iabRef);
2927
+ }
2928
+ _isIframeWebStorageSupported(_auth, _cb) {
3600
2929
  throw new Error('Method not implemented.');
3601
- };
3602
- CordovaPopupRedirectResolver.prototype._originValidation = function (auth) {
3603
- var key = auth._key();
2930
+ }
2931
+ _originValidation(auth) {
2932
+ const key = auth._key();
3604
2933
  if (!this.originValidationPromises[key]) {
3605
2934
  this.originValidationPromises[key] = _validateOrigin(auth);
3606
2935
  }
3607
2936
  return this.originValidationPromises[key];
3608
- };
3609
- CordovaPopupRedirectResolver.prototype.attachCallbackListeners = function (auth, manager) {
3610
- var _this = this;
2937
+ }
2938
+ attachCallbackListeners(auth, manager) {
3611
2939
  // Get the global plugins
3612
- var _a = _cordovaWindow(), universalLinks = _a.universalLinks, handleOpenURL = _a.handleOpenURL, BuildInfo = _a.BuildInfo;
3613
- var noEventTimeout = setTimeout(function () { return tslib.__awaiter(_this, void 0, void 0, function () {
3614
- return tslib.__generator(this, function (_a) {
3615
- switch (_a.label) {
3616
- case 0:
3617
- // We didn't see that initial event. Clear any pending object and
3618
- // dispatch no event
3619
- return [4 /*yield*/, _getAndRemoveEvent(auth)];
3620
- case 1:
3621
- // We didn't see that initial event. Clear any pending object and
3622
- // dispatch no event
3623
- _a.sent();
3624
- manager.onEvent(generateNoEvent());
3625
- return [2 /*return*/];
3626
- }
3627
- });
3628
- }); }, INITIAL_EVENT_TIMEOUT_MS);
3629
- var universalLinksCb = function (eventData) { return tslib.__awaiter(_this, void 0, void 0, function () {
3630
- var partialEvent, finalEvent;
3631
- return tslib.__generator(this, function (_a) {
3632
- switch (_a.label) {
3633
- case 0:
3634
- // We have an event so we can clear the no event timeout
3635
- clearTimeout(noEventTimeout);
3636
- return [4 /*yield*/, _getAndRemoveEvent(auth)];
3637
- case 1:
3638
- partialEvent = _a.sent();
3639
- finalEvent = null;
3640
- if (partialEvent && (eventData === null || eventData === void 0 ? void 0 : eventData['url'])) {
3641
- finalEvent = _eventFromPartialAndUrl(partialEvent, eventData['url']);
3642
- }
3643
- // If finalEvent is never filled, trigger with no event
3644
- manager.onEvent(finalEvent || generateNoEvent());
3645
- return [2 /*return*/];
3646
- }
3647
- });
3648
- }); };
2940
+ const { universalLinks, handleOpenURL, BuildInfo } = _cordovaWindow();
2941
+ const noEventTimeout = setTimeout(async () => {
2942
+ // We didn't see that initial event. Clear any pending object and
2943
+ // dispatch no event
2944
+ await _getAndRemoveEvent(auth);
2945
+ manager.onEvent(generateNoEvent());
2946
+ }, INITIAL_EVENT_TIMEOUT_MS);
2947
+ const universalLinksCb = async (eventData) => {
2948
+ // We have an event so we can clear the no event timeout
2949
+ clearTimeout(noEventTimeout);
2950
+ const partialEvent = await _getAndRemoveEvent(auth);
2951
+ let finalEvent = null;
2952
+ if (partialEvent && (eventData === null || eventData === void 0 ? void 0 : eventData['url'])) {
2953
+ finalEvent = _eventFromPartialAndUrl(partialEvent, eventData['url']);
2954
+ }
2955
+ // If finalEvent is never filled, trigger with no event
2956
+ manager.onEvent(finalEvent || generateNoEvent());
2957
+ };
3649
2958
  // Universal links subscriber doesn't exist for iOS, so we need to check
3650
2959
  if (typeof universalLinks !== 'undefined' &&
3651
2960
  typeof universalLinks.subscribe === 'function') {
@@ -3656,38 +2965,34 @@ var CordovaPopupRedirectResolver = /** @class */ (function () {
3656
2965
  // For this to work, cordova-plugin-customurlscheme needs to be installed.
3657
2966
  // https://github.com/EddyVerbruggen/Custom-URL-scheme
3658
2967
  // Do not overwrite the existing developer's URL handler.
3659
- var existingHandleOpenURL = handleOpenURL;
3660
- var packagePrefix = "".concat(BuildInfo.packageName.toLowerCase(), "://");
3661
- _cordovaWindow().handleOpenURL = function (url) { return tslib.__awaiter(_this, void 0, void 0, function () {
3662
- return tslib.__generator(this, function (_a) {
3663
- if (url.toLowerCase().startsWith(packagePrefix)) {
3664
- // We want this intentionally to float
3665
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
3666
- universalLinksCb({ url: url });
2968
+ const existingHandleOpenURL = handleOpenURL;
2969
+ const packagePrefix = `${BuildInfo.packageName.toLowerCase()}://`;
2970
+ _cordovaWindow().handleOpenURL = async (url) => {
2971
+ if (url.toLowerCase().startsWith(packagePrefix)) {
2972
+ // We want this intentionally to float
2973
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
2974
+ universalLinksCb({ url });
2975
+ }
2976
+ // Call the developer's handler if it is present.
2977
+ if (typeof existingHandleOpenURL === 'function') {
2978
+ try {
2979
+ existingHandleOpenURL(url);
3667
2980
  }
3668
- // Call the developer's handler if it is present.
3669
- if (typeof existingHandleOpenURL === 'function') {
3670
- try {
3671
- existingHandleOpenURL(url);
3672
- }
3673
- catch (e) {
3674
- // This is a developer error. Don't stop the flow of the SDK.
3675
- console.error(e);
3676
- }
2981
+ catch (e) {
2982
+ // This is a developer error. Don't stop the flow of the SDK.
2983
+ console.error(e);
3677
2984
  }
3678
- return [2 /*return*/];
3679
- });
3680
- }); };
3681
- };
3682
- return CordovaPopupRedirectResolver;
3683
- }());
2985
+ }
2986
+ };
2987
+ }
2988
+ }
3684
2989
  /**
3685
2990
  * An implementation of {@link PopupRedirectResolver} suitable for Cordova
3686
2991
  * based applications.
3687
2992
  *
3688
2993
  * @public
3689
2994
  */
3690
- var cordovaPopupRedirectResolver = CordovaPopupRedirectResolver;
2995
+ const cordovaPopupRedirectResolver = CordovaPopupRedirectResolver;
3691
2996
  function generateNoEvent() {
3692
2997
  return {
3693
2998
  type: "unknown" /* AuthEventType.UNKNOWN */,