@depup/firebase__auth-compat 0.6.3-depup.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 (56) hide show
  1. package/README.md +31 -0
  2. package/changes.json +10 -0
  3. package/dist/auth-compat/index.d.ts +112 -0
  4. package/dist/auth-compat/index.node.d.ts +24 -0
  5. package/dist/auth-compat/scripts/run_node_tests.d.ts +17 -0
  6. package/dist/auth-compat/src/auth.d.ts +72 -0
  7. package/dist/auth-compat/src/auth.test.d.ts +17 -0
  8. package/dist/auth-compat/src/persistence.d.ts +29 -0
  9. package/dist/auth-compat/src/phone_auth_provider.d.ts +29 -0
  10. package/dist/auth-compat/src/platform.d.ts +39 -0
  11. package/dist/auth-compat/src/popup_redirect.d.ts +34 -0
  12. package/dist/auth-compat/src/popup_redirect.test.d.ts +17 -0
  13. package/dist/auth-compat/src/recaptcha_verifier.d.ts +28 -0
  14. package/dist/auth-compat/src/user.d.ts +64 -0
  15. package/dist/auth-compat/src/user_credential.d.ts +20 -0
  16. package/dist/auth-compat/src/wrap.d.ts +26 -0
  17. package/dist/auth-compat/test/helpers/helpers.d.ts +24 -0
  18. package/dist/auth-compat/test/integration/flows/anonymous.test.d.ts +17 -0
  19. package/dist/auth-compat/test/integration/flows/custom.test.d.ts +17 -0
  20. package/dist/auth-compat/test/integration/flows/email.test.d.ts +17 -0
  21. package/dist/auth-compat/test/integration/flows/idp.test.d.ts +17 -0
  22. package/dist/auth-compat/test/integration/flows/oob.test.d.ts +17 -0
  23. package/dist/auth-compat/test/integration/flows/phone.test.d.ts +17 -0
  24. package/dist/esm/auth-compat/index.d.ts +50 -0
  25. package/dist/esm/auth-compat/index.node.d.ts +24 -0
  26. package/dist/esm/auth-compat/scripts/run_node_tests.d.ts +17 -0
  27. package/dist/esm/auth-compat/src/auth.d.ts +72 -0
  28. package/dist/esm/auth-compat/src/auth.test.d.ts +17 -0
  29. package/dist/esm/auth-compat/src/persistence.d.ts +29 -0
  30. package/dist/esm/auth-compat/src/phone_auth_provider.d.ts +29 -0
  31. package/dist/esm/auth-compat/src/platform.d.ts +39 -0
  32. package/dist/esm/auth-compat/src/popup_redirect.d.ts +34 -0
  33. package/dist/esm/auth-compat/src/popup_redirect.test.d.ts +17 -0
  34. package/dist/esm/auth-compat/src/recaptcha_verifier.d.ts +28 -0
  35. package/dist/esm/auth-compat/src/user.d.ts +64 -0
  36. package/dist/esm/auth-compat/src/user_credential.d.ts +20 -0
  37. package/dist/esm/auth-compat/src/wrap.d.ts +26 -0
  38. package/dist/esm/auth-compat/test/helpers/helpers.d.ts +24 -0
  39. package/dist/esm/auth-compat/test/integration/flows/anonymous.test.d.ts +17 -0
  40. package/dist/esm/auth-compat/test/integration/flows/custom.test.d.ts +17 -0
  41. package/dist/esm/auth-compat/test/integration/flows/email.test.d.ts +17 -0
  42. package/dist/esm/auth-compat/test/integration/flows/idp.test.d.ts +17 -0
  43. package/dist/esm/auth-compat/test/integration/flows/oob.test.d.ts +17 -0
  44. package/dist/esm/auth-compat/test/integration/flows/phone.test.d.ts +17 -0
  45. package/dist/esm/index.node.esm.js +1020 -0
  46. package/dist/esm/index.node.esm.js.map +1 -0
  47. package/dist/esm/package.json +1 -0
  48. package/dist/firebase-auth.js +15 -0
  49. package/dist/firebase-auth.js.map +1 -0
  50. package/dist/index.cjs.js +1026 -0
  51. package/dist/index.cjs.js.map +1 -0
  52. package/dist/index.esm.js +1001 -0
  53. package/dist/index.esm.js.map +1 -0
  54. package/dist/index.node.cjs.js +1044 -0
  55. package/dist/index.node.cjs.js.map +1 -0
  56. package/package.json +107 -0
@@ -0,0 +1,1020 @@
1
+ import firebase from '@firebase/app-compat';
2
+ import * as exp from '@firebase/auth/internal';
3
+ import { FetchProvider } from '@firebase/auth/internal';
4
+ import { Component } from '@firebase/component';
5
+ import { isBrowserExtension, getUA, isReactNative, isNode, isIndexedDBAvailable, isIE, FirebaseError } from '@firebase/util';
6
+
7
+ var name = "@firebase/auth-compat";
8
+ var version = "0.6.3";
9
+
10
+ /**
11
+ * @license
12
+ * Copyright 2020 Google LLC
13
+ *
14
+ * Licensed under the Apache License, Version 2.0 (the "License");
15
+ * you may not use this file except in compliance with the License.
16
+ * You may obtain a copy of the License at
17
+ *
18
+ * http://www.apache.org/licenses/LICENSE-2.0
19
+ *
20
+ * Unless required by applicable law or agreed to in writing, software
21
+ * distributed under the License is distributed on an "AS IS" BASIS,
22
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
+ * See the License for the specific language governing permissions and
24
+ * limitations under the License.
25
+ */
26
+ const CORDOVA_ONDEVICEREADY_TIMEOUT_MS = 1000;
27
+ function _getCurrentScheme() {
28
+ return self?.location?.protocol || null;
29
+ }
30
+ /**
31
+ * @return {boolean} Whether the current environment is http or https.
32
+ */
33
+ function _isHttpOrHttps() {
34
+ return _getCurrentScheme() === 'http:' || _getCurrentScheme() === 'https:';
35
+ }
36
+ /**
37
+ * @param {?string=} ua The user agent.
38
+ * @return {boolean} Whether the app is rendered in a mobile iOS or Android
39
+ * Cordova environment.
40
+ */
41
+ function _isAndroidOrIosCordovaScheme(ua = getUA()) {
42
+ return !!((_getCurrentScheme() === 'file:' ||
43
+ _getCurrentScheme() === 'ionic:' ||
44
+ _getCurrentScheme() === 'capacitor:') &&
45
+ ua.toLowerCase().match(/iphone|ipad|ipod|android/));
46
+ }
47
+ /**
48
+ * @return {boolean} Whether the environment is a native environment, where
49
+ * CORS checks do not apply.
50
+ */
51
+ function _isNativeEnvironment() {
52
+ return isReactNative() || isNode();
53
+ }
54
+ /**
55
+ * Checks whether the user agent is IE11.
56
+ * @return {boolean} True if it is IE11.
57
+ */
58
+ function _isIe11() {
59
+ return isIE() && document?.documentMode === 11;
60
+ }
61
+ /**
62
+ * Checks whether the user agent is Edge.
63
+ * @param {string} userAgent The browser user agent string.
64
+ * @return {boolean} True if it is Edge.
65
+ */
66
+ function _isEdge(ua = getUA()) {
67
+ return /Edge\/\d+/.test(ua);
68
+ }
69
+ /**
70
+ * @param {?string=} opt_userAgent The navigator user agent.
71
+ * @return {boolean} Whether local storage is not synchronized between an iframe
72
+ * and a popup of the same domain.
73
+ */
74
+ function _isLocalStorageNotSynchronized(ua = getUA()) {
75
+ return _isIe11() || _isEdge(ua);
76
+ }
77
+ /** @return {boolean} Whether web storage is supported. */
78
+ function _isWebStorageSupported() {
79
+ try {
80
+ const storage = self.localStorage;
81
+ const key = exp._generateEventId();
82
+ if (storage) {
83
+ // setItem will throw an exception if we cannot access WebStorage (e.g.,
84
+ // Safari in private mode).
85
+ storage['setItem'](key, '1');
86
+ storage['removeItem'](key);
87
+ // For browsers where iframe web storage does not synchronize with a popup
88
+ // of the same domain, indexedDB is used for persistent storage. These
89
+ // browsers include IE11 and Edge.
90
+ // Make sure it is supported (IE11 and Edge private mode does not support
91
+ // that).
92
+ if (_isLocalStorageNotSynchronized()) {
93
+ // In such browsers, if indexedDB is not supported, an iframe cannot be
94
+ // notified of the popup sign in result.
95
+ return isIndexedDBAvailable();
96
+ }
97
+ return true;
98
+ }
99
+ }
100
+ catch (e) {
101
+ // localStorage is not available from a worker. Test availability of
102
+ // indexedDB.
103
+ return _isWorker() && isIndexedDBAvailable();
104
+ }
105
+ return false;
106
+ }
107
+ /**
108
+ * @param {?Object=} global The optional global scope.
109
+ * @return {boolean} Whether current environment is a worker.
110
+ */
111
+ function _isWorker() {
112
+ // WorkerGlobalScope only defined in worker environment.
113
+ return (typeof global !== 'undefined' &&
114
+ 'WorkerGlobalScope' in global &&
115
+ 'importScripts' in global);
116
+ }
117
+ function _isPopupRedirectSupported() {
118
+ return ((_isHttpOrHttps() ||
119
+ isBrowserExtension() ||
120
+ _isAndroidOrIosCordovaScheme()) &&
121
+ // React Native with remote debugging reports its location.protocol as
122
+ // http.
123
+ !_isNativeEnvironment() &&
124
+ // Local storage has to be supported for browser popup and redirect
125
+ // operations to work.
126
+ _isWebStorageSupported() &&
127
+ // DOM, popups and redirects are not supported within a worker.
128
+ !_isWorker());
129
+ }
130
+ /** Quick check that indicates the platform *may* be Cordova */
131
+ function _isLikelyCordova() {
132
+ return _isAndroidOrIosCordovaScheme() && typeof document !== 'undefined';
133
+ }
134
+ async function _isCordova() {
135
+ if (!_isLikelyCordova()) {
136
+ return false;
137
+ }
138
+ return new Promise(resolve => {
139
+ const timeoutId = setTimeout(() => {
140
+ // We've waited long enough; the telltale Cordova event didn't happen
141
+ resolve(false);
142
+ }, CORDOVA_ONDEVICEREADY_TIMEOUT_MS);
143
+ document.addEventListener('deviceready', () => {
144
+ clearTimeout(timeoutId);
145
+ resolve(true);
146
+ });
147
+ });
148
+ }
149
+ function _getSelfWindow() {
150
+ return typeof window !== 'undefined' ? window : null;
151
+ }
152
+
153
+ /**
154
+ * @license
155
+ * Copyright 2020 Google LLC
156
+ *
157
+ * Licensed under the Apache License, Version 2.0 (the "License");
158
+ * you may not use this file except in compliance with the License.
159
+ * You may obtain a copy of the License at
160
+ *
161
+ * http://www.apache.org/licenses/LICENSE-2.0
162
+ *
163
+ * Unless required by applicable law or agreed to in writing, software
164
+ * distributed under the License is distributed on an "AS IS" BASIS,
165
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
166
+ * See the License for the specific language governing permissions and
167
+ * limitations under the License.
168
+ */
169
+ const Persistence = {
170
+ LOCAL: 'local',
171
+ NONE: 'none',
172
+ SESSION: 'session'
173
+ };
174
+ const _assert$3 = exp._assert;
175
+ const PERSISTENCE_KEY = 'persistence';
176
+ /**
177
+ * Validates that an argument is a valid persistence value. If an invalid type
178
+ * is specified, an error is thrown synchronously.
179
+ */
180
+ function _validatePersistenceArgument(auth, persistence) {
181
+ _assert$3(Object.values(Persistence).includes(persistence), auth, "invalid-persistence-type" /* exp.AuthErrorCode.INVALID_PERSISTENCE */);
182
+ // Validate if the specified type is supported in the current environment.
183
+ if (isReactNative()) {
184
+ // This is only supported in a browser.
185
+ _assert$3(persistence !== Persistence.SESSION, auth, "unsupported-persistence-type" /* exp.AuthErrorCode.UNSUPPORTED_PERSISTENCE */);
186
+ return;
187
+ }
188
+ if (isNode()) {
189
+ // Only none is supported in Node.js.
190
+ _assert$3(persistence === Persistence.NONE, auth, "unsupported-persistence-type" /* exp.AuthErrorCode.UNSUPPORTED_PERSISTENCE */);
191
+ return;
192
+ }
193
+ if (_isWorker()) {
194
+ // In a worker environment, either LOCAL or NONE are supported.
195
+ // If indexedDB not supported and LOCAL provided, throw an error
196
+ _assert$3(persistence === Persistence.NONE ||
197
+ (persistence === Persistence.LOCAL && isIndexedDBAvailable()), auth, "unsupported-persistence-type" /* exp.AuthErrorCode.UNSUPPORTED_PERSISTENCE */);
198
+ return;
199
+ }
200
+ // This is restricted by what the browser supports.
201
+ _assert$3(persistence === Persistence.NONE || _isWebStorageSupported(), auth, "unsupported-persistence-type" /* exp.AuthErrorCode.UNSUPPORTED_PERSISTENCE */);
202
+ }
203
+ async function _savePersistenceForRedirect(auth) {
204
+ await auth._initializationPromise;
205
+ const session = getSessionStorageIfAvailable();
206
+ const key = exp._persistenceKeyName(PERSISTENCE_KEY, auth.config.apiKey, auth.name);
207
+ if (session) {
208
+ session.setItem(key, auth._getPersistenceType());
209
+ }
210
+ }
211
+ function _getPersistencesFromRedirect(apiKey, appName) {
212
+ const session = getSessionStorageIfAvailable();
213
+ if (!session) {
214
+ return [];
215
+ }
216
+ const key = exp._persistenceKeyName(PERSISTENCE_KEY, apiKey, appName);
217
+ const persistence = session.getItem(key);
218
+ switch (persistence) {
219
+ case Persistence.NONE:
220
+ return [exp.inMemoryPersistence];
221
+ case Persistence.LOCAL:
222
+ return [exp.indexedDBLocalPersistence, exp.browserSessionPersistence];
223
+ case Persistence.SESSION:
224
+ return [exp.browserSessionPersistence];
225
+ default:
226
+ return [];
227
+ }
228
+ }
229
+ /** Returns session storage, or null if the property access errors */
230
+ function getSessionStorageIfAvailable() {
231
+ try {
232
+ return _getSelfWindow()?.sessionStorage || null;
233
+ }
234
+ catch (e) {
235
+ return null;
236
+ }
237
+ }
238
+
239
+ /**
240
+ * @license
241
+ * Copyright 2020 Google LLC
242
+ *
243
+ * Licensed under the Apache License, Version 2.0 (the "License");
244
+ * you may not use this file except in compliance with the License.
245
+ * You may obtain a copy of the License at
246
+ *
247
+ * http://www.apache.org/licenses/LICENSE-2.0
248
+ *
249
+ * Unless required by applicable law or agreed to in writing, software
250
+ * distributed under the License is distributed on an "AS IS" BASIS,
251
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
252
+ * See the License for the specific language governing permissions and
253
+ * limitations under the License.
254
+ */
255
+ const _assert$2 = exp._assert;
256
+ /** Platform-agnostic popup-redirect resolver */
257
+ class CompatPopupRedirectResolver {
258
+ constructor() {
259
+ // Create both resolvers for dynamic resolution later
260
+ this.browserResolver = exp._getInstance(exp.browserPopupRedirectResolver);
261
+ this.cordovaResolver = exp._getInstance(exp.cordovaPopupRedirectResolver);
262
+ // The actual resolver in use: either browserResolver or cordovaResolver.
263
+ this.underlyingResolver = null;
264
+ this._redirectPersistence = exp.browserSessionPersistence;
265
+ this._completeRedirectFn = exp._getRedirectResult;
266
+ this._overrideRedirectResult = exp._overrideRedirectResult;
267
+ }
268
+ async _initialize(auth) {
269
+ await this.selectUnderlyingResolver();
270
+ return this.assertedUnderlyingResolver._initialize(auth);
271
+ }
272
+ async _openPopup(auth, provider, authType, eventId) {
273
+ await this.selectUnderlyingResolver();
274
+ return this.assertedUnderlyingResolver._openPopup(auth, provider, authType, eventId);
275
+ }
276
+ async _openRedirect(auth, provider, authType, eventId) {
277
+ await this.selectUnderlyingResolver();
278
+ return this.assertedUnderlyingResolver._openRedirect(auth, provider, authType, eventId);
279
+ }
280
+ _isIframeWebStorageSupported(auth, cb) {
281
+ this.assertedUnderlyingResolver._isIframeWebStorageSupported(auth, cb);
282
+ }
283
+ _originValidation(auth) {
284
+ return this.assertedUnderlyingResolver._originValidation(auth);
285
+ }
286
+ get _shouldInitProactively() {
287
+ return _isLikelyCordova() || this.browserResolver._shouldInitProactively;
288
+ }
289
+ get assertedUnderlyingResolver() {
290
+ _assert$2(this.underlyingResolver, "internal-error" /* exp.AuthErrorCode.INTERNAL_ERROR */);
291
+ return this.underlyingResolver;
292
+ }
293
+ async selectUnderlyingResolver() {
294
+ if (this.underlyingResolver) {
295
+ return;
296
+ }
297
+ // We haven't yet determined whether or not we're in Cordova; go ahead
298
+ // and determine that state now.
299
+ const isCordova = await _isCordova();
300
+ this.underlyingResolver = isCordova
301
+ ? this.cordovaResolver
302
+ : this.browserResolver;
303
+ }
304
+ }
305
+
306
+ /**
307
+ * @license
308
+ * Copyright 2020 Google LLC
309
+ *
310
+ * Licensed under the Apache License, Version 2.0 (the "License");
311
+ * you may not use this file except in compliance with the License.
312
+ * You may obtain a copy of the License at
313
+ *
314
+ * http://www.apache.org/licenses/LICENSE-2.0
315
+ *
316
+ * Unless required by applicable law or agreed to in writing, software
317
+ * distributed under the License is distributed on an "AS IS" BASIS,
318
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
319
+ * See the License for the specific language governing permissions and
320
+ * limitations under the License.
321
+ */
322
+ function unwrap(object) {
323
+ return object.unwrap();
324
+ }
325
+ function wrapped(object) {
326
+ return object.wrapped();
327
+ }
328
+
329
+ /**
330
+ * @license
331
+ * Copyright 2020 Google LLC
332
+ *
333
+ * Licensed under the Apache License, Version 2.0 (the "License");
334
+ * you may not use this file except in compliance with the License.
335
+ * You may obtain a copy of the License at
336
+ *
337
+ * http://www.apache.org/licenses/LICENSE-2.0
338
+ *
339
+ * Unless required by applicable law or agreed to in writing, software
340
+ * distributed under the License is distributed on an "AS IS" BASIS,
341
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
342
+ * See the License for the specific language governing permissions and
343
+ * limitations under the License.
344
+ */
345
+ function credentialFromResponse(userCredential) {
346
+ return credentialFromObject(userCredential);
347
+ }
348
+ function attachExtraErrorFields(auth, e) {
349
+ // The response contains all fields from the server which may or may not
350
+ // actually match the underlying type
351
+ const response = e.customData
352
+ ?._tokenResponse;
353
+ if (e?.code === 'auth/multi-factor-auth-required') {
354
+ const mfaErr = e;
355
+ mfaErr.resolver = new MultiFactorResolver(auth, exp.getMultiFactorResolver(auth, e));
356
+ }
357
+ else if (response) {
358
+ const credential = credentialFromObject(e);
359
+ const credErr = e;
360
+ if (credential) {
361
+ credErr.credential = credential;
362
+ credErr.tenantId = response.tenantId || undefined;
363
+ credErr.email = response.email || undefined;
364
+ credErr.phoneNumber = response.phoneNumber || undefined;
365
+ }
366
+ }
367
+ }
368
+ function credentialFromObject(object) {
369
+ const { _tokenResponse } = (object instanceof FirebaseError ? object.customData : object);
370
+ if (!_tokenResponse) {
371
+ return null;
372
+ }
373
+ // Handle phone Auth credential responses, as they have a different format
374
+ // from other backend responses (i.e. no providerId). This is also only the
375
+ // case for user credentials (does not work for errors).
376
+ if (!(object instanceof FirebaseError)) {
377
+ if ('temporaryProof' in _tokenResponse && 'phoneNumber' in _tokenResponse) {
378
+ return exp.PhoneAuthProvider.credentialFromResult(object);
379
+ }
380
+ }
381
+ const providerId = _tokenResponse.providerId;
382
+ // Email and password is not supported as there is no situation where the
383
+ // server would return the password to the client.
384
+ if (!providerId || providerId === exp.ProviderId.PASSWORD) {
385
+ return null;
386
+ }
387
+ let provider;
388
+ switch (providerId) {
389
+ case exp.ProviderId.GOOGLE:
390
+ provider = exp.GoogleAuthProvider;
391
+ break;
392
+ case exp.ProviderId.FACEBOOK:
393
+ provider = exp.FacebookAuthProvider;
394
+ break;
395
+ case exp.ProviderId.GITHUB:
396
+ provider = exp.GithubAuthProvider;
397
+ break;
398
+ case exp.ProviderId.TWITTER:
399
+ provider = exp.TwitterAuthProvider;
400
+ break;
401
+ default:
402
+ const { oauthIdToken, oauthAccessToken, oauthTokenSecret, pendingToken, nonce } = _tokenResponse;
403
+ if (!oauthAccessToken &&
404
+ !oauthTokenSecret &&
405
+ !oauthIdToken &&
406
+ !pendingToken) {
407
+ return null;
408
+ }
409
+ // TODO(avolkovi): uncomment this and get it working with SAML & OIDC
410
+ if (pendingToken) {
411
+ if (providerId.startsWith('saml.')) {
412
+ return exp.SAMLAuthCredential._create(providerId, pendingToken);
413
+ }
414
+ else {
415
+ // OIDC and non-default providers excluding Twitter.
416
+ return exp.OAuthCredential._fromParams({
417
+ providerId,
418
+ signInMethod: providerId,
419
+ pendingToken,
420
+ idToken: oauthIdToken,
421
+ accessToken: oauthAccessToken
422
+ });
423
+ }
424
+ }
425
+ return new exp.OAuthProvider(providerId).credential({
426
+ idToken: oauthIdToken,
427
+ accessToken: oauthAccessToken,
428
+ rawNonce: nonce
429
+ });
430
+ }
431
+ return object instanceof FirebaseError
432
+ ? provider.credentialFromError(object)
433
+ : provider.credentialFromResult(object);
434
+ }
435
+ function convertCredential(auth, credentialPromise) {
436
+ return credentialPromise
437
+ .catch(e => {
438
+ if (e instanceof FirebaseError) {
439
+ attachExtraErrorFields(auth, e);
440
+ }
441
+ throw e;
442
+ })
443
+ .then(credential => {
444
+ const operationType = credential.operationType;
445
+ const user = credential.user;
446
+ return {
447
+ operationType,
448
+ credential: credentialFromResponse(credential),
449
+ additionalUserInfo: exp.getAdditionalUserInfo(credential),
450
+ user: User.getOrCreate(user)
451
+ };
452
+ });
453
+ }
454
+ async function convertConfirmationResult(auth, confirmationResultPromise) {
455
+ const confirmationResultExp = await confirmationResultPromise;
456
+ return {
457
+ verificationId: confirmationResultExp.verificationId,
458
+ confirm: (verificationCode) => convertCredential(auth, confirmationResultExp.confirm(verificationCode))
459
+ };
460
+ }
461
+ class MultiFactorResolver {
462
+ constructor(auth, resolver) {
463
+ this.resolver = resolver;
464
+ this.auth = wrapped(auth);
465
+ }
466
+ get session() {
467
+ return this.resolver.session;
468
+ }
469
+ get hints() {
470
+ return this.resolver.hints;
471
+ }
472
+ resolveSignIn(assertion) {
473
+ return convertCredential(unwrap(this.auth), this.resolver.resolveSignIn(assertion));
474
+ }
475
+ }
476
+
477
+ /**
478
+ * @license
479
+ * Copyright 2020 Google LLC
480
+ *
481
+ * Licensed under the Apache License, Version 2.0 (the "License");
482
+ * you may not use this file except in compliance with the License.
483
+ * You may obtain a copy of the License at
484
+ *
485
+ * http://www.apache.org/licenses/LICENSE-2.0
486
+ *
487
+ * Unless required by applicable law or agreed to in writing, software
488
+ * distributed under the License is distributed on an "AS IS" BASIS,
489
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
490
+ * See the License for the specific language governing permissions and
491
+ * limitations under the License.
492
+ */
493
+ class User {
494
+ constructor(_delegate) {
495
+ this._delegate = _delegate;
496
+ this.multiFactor = exp.multiFactor(_delegate);
497
+ }
498
+ static getOrCreate(user) {
499
+ if (!User.USER_MAP.has(user)) {
500
+ User.USER_MAP.set(user, new User(user));
501
+ }
502
+ return User.USER_MAP.get(user);
503
+ }
504
+ delete() {
505
+ return this._delegate.delete();
506
+ }
507
+ reload() {
508
+ return this._delegate.reload();
509
+ }
510
+ toJSON() {
511
+ return this._delegate.toJSON();
512
+ }
513
+ getIdTokenResult(forceRefresh) {
514
+ return this._delegate.getIdTokenResult(forceRefresh);
515
+ }
516
+ getIdToken(forceRefresh) {
517
+ return this._delegate.getIdToken(forceRefresh);
518
+ }
519
+ linkAndRetrieveDataWithCredential(credential) {
520
+ return this.linkWithCredential(credential);
521
+ }
522
+ async linkWithCredential(credential) {
523
+ return convertCredential(this.auth, exp.linkWithCredential(this._delegate, credential));
524
+ }
525
+ async linkWithPhoneNumber(phoneNumber, applicationVerifier) {
526
+ return convertConfirmationResult(this.auth, exp.linkWithPhoneNumber(this._delegate, phoneNumber, applicationVerifier));
527
+ }
528
+ async linkWithPopup(provider) {
529
+ return convertCredential(this.auth, exp.linkWithPopup(this._delegate, provider, CompatPopupRedirectResolver));
530
+ }
531
+ async linkWithRedirect(provider) {
532
+ await _savePersistenceForRedirect(exp._castAuth(this.auth));
533
+ return exp.linkWithRedirect(this._delegate, provider, CompatPopupRedirectResolver);
534
+ }
535
+ reauthenticateAndRetrieveDataWithCredential(credential) {
536
+ return this.reauthenticateWithCredential(credential);
537
+ }
538
+ async reauthenticateWithCredential(credential) {
539
+ return convertCredential(this.auth, exp.reauthenticateWithCredential(this._delegate, credential));
540
+ }
541
+ reauthenticateWithPhoneNumber(phoneNumber, applicationVerifier) {
542
+ return convertConfirmationResult(this.auth, exp.reauthenticateWithPhoneNumber(this._delegate, phoneNumber, applicationVerifier));
543
+ }
544
+ reauthenticateWithPopup(provider) {
545
+ return convertCredential(this.auth, exp.reauthenticateWithPopup(this._delegate, provider, CompatPopupRedirectResolver));
546
+ }
547
+ async reauthenticateWithRedirect(provider) {
548
+ await _savePersistenceForRedirect(exp._castAuth(this.auth));
549
+ return exp.reauthenticateWithRedirect(this._delegate, provider, CompatPopupRedirectResolver);
550
+ }
551
+ sendEmailVerification(actionCodeSettings) {
552
+ return exp.sendEmailVerification(this._delegate, actionCodeSettings);
553
+ }
554
+ async unlink(providerId) {
555
+ await exp.unlink(this._delegate, providerId);
556
+ return this;
557
+ }
558
+ updateEmail(newEmail) {
559
+ return exp.updateEmail(this._delegate, newEmail);
560
+ }
561
+ updatePassword(newPassword) {
562
+ return exp.updatePassword(this._delegate, newPassword);
563
+ }
564
+ updatePhoneNumber(phoneCredential) {
565
+ return exp.updatePhoneNumber(this._delegate, phoneCredential);
566
+ }
567
+ updateProfile(profile) {
568
+ return exp.updateProfile(this._delegate, profile);
569
+ }
570
+ verifyBeforeUpdateEmail(newEmail, actionCodeSettings) {
571
+ return exp.verifyBeforeUpdateEmail(this._delegate, newEmail, actionCodeSettings);
572
+ }
573
+ get emailVerified() {
574
+ return this._delegate.emailVerified;
575
+ }
576
+ get isAnonymous() {
577
+ return this._delegate.isAnonymous;
578
+ }
579
+ get metadata() {
580
+ return this._delegate.metadata;
581
+ }
582
+ get phoneNumber() {
583
+ return this._delegate.phoneNumber;
584
+ }
585
+ get providerData() {
586
+ return this._delegate.providerData;
587
+ }
588
+ get refreshToken() {
589
+ return this._delegate.refreshToken;
590
+ }
591
+ get tenantId() {
592
+ return this._delegate.tenantId;
593
+ }
594
+ get displayName() {
595
+ return this._delegate.displayName;
596
+ }
597
+ get email() {
598
+ return this._delegate.email;
599
+ }
600
+ get photoURL() {
601
+ return this._delegate.photoURL;
602
+ }
603
+ get providerId() {
604
+ return this._delegate.providerId;
605
+ }
606
+ get uid() {
607
+ return this._delegate.uid;
608
+ }
609
+ get auth() {
610
+ return this._delegate.auth;
611
+ }
612
+ }
613
+ // Maintain a map so that there's always a 1:1 mapping between new User and
614
+ // legacy compat users
615
+ User.USER_MAP = new WeakMap();
616
+
617
+ /**
618
+ * @license
619
+ * Copyright 2020 Google LLC
620
+ *
621
+ * Licensed under the Apache License, Version 2.0 (the "License");
622
+ * you may not use this file except in compliance with the License.
623
+ * You may obtain a copy of the License at
624
+ *
625
+ * http://www.apache.org/licenses/LICENSE-2.0
626
+ *
627
+ * Unless required by applicable law or agreed to in writing, software
628
+ * distributed under the License is distributed on an "AS IS" BASIS,
629
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
630
+ * See the License for the specific language governing permissions and
631
+ * limitations under the License.
632
+ */
633
+ const _assert$1 = exp._assert;
634
+ class Auth {
635
+ constructor(app, provider) {
636
+ this.app = app;
637
+ if (provider.isInitialized()) {
638
+ this._delegate = provider.getImmediate();
639
+ this.linkUnderlyingAuth();
640
+ return;
641
+ }
642
+ const { apiKey } = app.options;
643
+ // TODO: platform needs to be determined using heuristics
644
+ _assert$1(apiKey, "invalid-api-key" /* exp.AuthErrorCode.INVALID_API_KEY */, {
645
+ appName: app.name
646
+ });
647
+ // TODO: platform needs to be determined using heuristics
648
+ _assert$1(apiKey, "invalid-api-key" /* exp.AuthErrorCode.INVALID_API_KEY */, {
649
+ appName: app.name
650
+ });
651
+ // Only use a popup/redirect resolver in browser environments
652
+ const resolver = typeof window !== 'undefined' ? CompatPopupRedirectResolver : undefined;
653
+ this._delegate = provider.initialize({
654
+ options: {
655
+ persistence: buildPersistenceHierarchy(apiKey, app.name),
656
+ popupRedirectResolver: resolver
657
+ }
658
+ });
659
+ this._delegate._updateErrorMap(exp.debugErrorMap);
660
+ this.linkUnderlyingAuth();
661
+ }
662
+ get emulatorConfig() {
663
+ return this._delegate.emulatorConfig;
664
+ }
665
+ get currentUser() {
666
+ if (!this._delegate.currentUser) {
667
+ return null;
668
+ }
669
+ return User.getOrCreate(this._delegate.currentUser);
670
+ }
671
+ get languageCode() {
672
+ return this._delegate.languageCode;
673
+ }
674
+ set languageCode(languageCode) {
675
+ this._delegate.languageCode = languageCode;
676
+ }
677
+ get settings() {
678
+ return this._delegate.settings;
679
+ }
680
+ get tenantId() {
681
+ return this._delegate.tenantId;
682
+ }
683
+ set tenantId(tid) {
684
+ this._delegate.tenantId = tid;
685
+ }
686
+ useDeviceLanguage() {
687
+ this._delegate.useDeviceLanguage();
688
+ }
689
+ signOut() {
690
+ return this._delegate.signOut();
691
+ }
692
+ useEmulator(url, options) {
693
+ exp.connectAuthEmulator(this._delegate, url, options);
694
+ }
695
+ applyActionCode(code) {
696
+ return exp.applyActionCode(this._delegate, code);
697
+ }
698
+ checkActionCode(code) {
699
+ return exp.checkActionCode(this._delegate, code);
700
+ }
701
+ confirmPasswordReset(code, newPassword) {
702
+ return exp.confirmPasswordReset(this._delegate, code, newPassword);
703
+ }
704
+ async createUserWithEmailAndPassword(email, password) {
705
+ return convertCredential(this._delegate, exp.createUserWithEmailAndPassword(this._delegate, email, password));
706
+ }
707
+ fetchProvidersForEmail(email) {
708
+ return this.fetchSignInMethodsForEmail(email);
709
+ }
710
+ fetchSignInMethodsForEmail(email) {
711
+ return exp.fetchSignInMethodsForEmail(this._delegate, email);
712
+ }
713
+ isSignInWithEmailLink(emailLink) {
714
+ return exp.isSignInWithEmailLink(this._delegate, emailLink);
715
+ }
716
+ async getRedirectResult() {
717
+ _assert$1(_isPopupRedirectSupported(), this._delegate, "operation-not-supported-in-this-environment" /* exp.AuthErrorCode.OPERATION_NOT_SUPPORTED */);
718
+ const credential = await exp.getRedirectResult(this._delegate, CompatPopupRedirectResolver);
719
+ if (!credential) {
720
+ return {
721
+ credential: null,
722
+ user: null
723
+ };
724
+ }
725
+ return convertCredential(this._delegate, Promise.resolve(credential));
726
+ }
727
+ // This function should only be called by frameworks (e.g. FirebaseUI-web) to log their usage.
728
+ // It is not intended for direct use by developer apps. NO jsdoc here to intentionally leave it
729
+ // out of autogenerated documentation pages to reduce accidental misuse.
730
+ addFrameworkForLogging(framework) {
731
+ exp.addFrameworkForLogging(this._delegate, framework);
732
+ }
733
+ onAuthStateChanged(nextOrObserver, errorFn, completed) {
734
+ const { next, error, complete } = wrapObservers(nextOrObserver, errorFn, completed);
735
+ return this._delegate.onAuthStateChanged(next, error, complete);
736
+ }
737
+ onIdTokenChanged(nextOrObserver, errorFn, completed) {
738
+ const { next, error, complete } = wrapObservers(nextOrObserver, errorFn, completed);
739
+ return this._delegate.onIdTokenChanged(next, error, complete);
740
+ }
741
+ sendSignInLinkToEmail(email, actionCodeSettings) {
742
+ return exp.sendSignInLinkToEmail(this._delegate, email, actionCodeSettings);
743
+ }
744
+ sendPasswordResetEmail(email, actionCodeSettings) {
745
+ return exp.sendPasswordResetEmail(this._delegate, email, actionCodeSettings || undefined);
746
+ }
747
+ async setPersistence(persistence) {
748
+ _validatePersistenceArgument(this._delegate, persistence);
749
+ let converted;
750
+ switch (persistence) {
751
+ case Persistence.SESSION:
752
+ converted = exp.browserSessionPersistence;
753
+ break;
754
+ case Persistence.LOCAL:
755
+ // Not using isIndexedDBAvailable() since it only checks if indexedDB is defined.
756
+ const isIndexedDBFullySupported = await exp
757
+ ._getInstance(exp.indexedDBLocalPersistence)
758
+ ._isAvailable();
759
+ converted = isIndexedDBFullySupported
760
+ ? exp.indexedDBLocalPersistence
761
+ : exp.browserLocalPersistence;
762
+ break;
763
+ case Persistence.NONE:
764
+ converted = exp.inMemoryPersistence;
765
+ break;
766
+ default:
767
+ return exp._fail("argument-error" /* exp.AuthErrorCode.ARGUMENT_ERROR */, {
768
+ appName: this._delegate.name
769
+ });
770
+ }
771
+ return this._delegate.setPersistence(converted);
772
+ }
773
+ signInAndRetrieveDataWithCredential(credential) {
774
+ return this.signInWithCredential(credential);
775
+ }
776
+ signInAnonymously() {
777
+ return convertCredential(this._delegate, exp.signInAnonymously(this._delegate));
778
+ }
779
+ signInWithCredential(credential) {
780
+ return convertCredential(this._delegate, exp.signInWithCredential(this._delegate, credential));
781
+ }
782
+ signInWithCustomToken(token) {
783
+ return convertCredential(this._delegate, exp.signInWithCustomToken(this._delegate, token));
784
+ }
785
+ signInWithEmailAndPassword(email, password) {
786
+ return convertCredential(this._delegate, exp.signInWithEmailAndPassword(this._delegate, email, password));
787
+ }
788
+ signInWithEmailLink(email, emailLink) {
789
+ return convertCredential(this._delegate, exp.signInWithEmailLink(this._delegate, email, emailLink));
790
+ }
791
+ signInWithPhoneNumber(phoneNumber, applicationVerifier) {
792
+ return convertConfirmationResult(this._delegate, exp.signInWithPhoneNumber(this._delegate, phoneNumber, applicationVerifier));
793
+ }
794
+ async signInWithPopup(provider) {
795
+ _assert$1(_isPopupRedirectSupported(), this._delegate, "operation-not-supported-in-this-environment" /* exp.AuthErrorCode.OPERATION_NOT_SUPPORTED */);
796
+ return convertCredential(this._delegate, exp.signInWithPopup(this._delegate, provider, CompatPopupRedirectResolver));
797
+ }
798
+ async signInWithRedirect(provider) {
799
+ _assert$1(_isPopupRedirectSupported(), this._delegate, "operation-not-supported-in-this-environment" /* exp.AuthErrorCode.OPERATION_NOT_SUPPORTED */);
800
+ await _savePersistenceForRedirect(this._delegate);
801
+ return exp.signInWithRedirect(this._delegate, provider, CompatPopupRedirectResolver);
802
+ }
803
+ updateCurrentUser(user) {
804
+ // remove ts-ignore once overloads are defined for exp functions to accept compat objects
805
+ // @ts-ignore
806
+ return this._delegate.updateCurrentUser(user);
807
+ }
808
+ verifyPasswordResetCode(code) {
809
+ return exp.verifyPasswordResetCode(this._delegate, code);
810
+ }
811
+ unwrap() {
812
+ return this._delegate;
813
+ }
814
+ _delete() {
815
+ return this._delegate._delete();
816
+ }
817
+ linkUnderlyingAuth() {
818
+ this._delegate.wrapped = () => this;
819
+ }
820
+ }
821
+ Auth.Persistence = Persistence;
822
+ function wrapObservers(nextOrObserver, error, complete) {
823
+ let next = nextOrObserver;
824
+ if (typeof nextOrObserver !== 'function') {
825
+ ({ next, error, complete } = nextOrObserver);
826
+ }
827
+ // We know 'next' is now a function
828
+ const oldNext = next;
829
+ const newNext = (user) => oldNext(user && User.getOrCreate(user));
830
+ return {
831
+ next: newNext,
832
+ error: error,
833
+ complete
834
+ };
835
+ }
836
+ function buildPersistenceHierarchy(apiKey, appName) {
837
+ // Note this is slightly different behavior: in this case, the stored
838
+ // persistence is checked *first* rather than last. This is because we want
839
+ // to prefer stored persistence type in the hierarchy. This is an empty
840
+ // array if window is not available or there is no pending redirect
841
+ const persistences = _getPersistencesFromRedirect(apiKey, appName);
842
+ // If "self" is available, add indexedDB
843
+ if (typeof self !== 'undefined' &&
844
+ !persistences.includes(exp.indexedDBLocalPersistence)) {
845
+ persistences.push(exp.indexedDBLocalPersistence);
846
+ }
847
+ // If "window" is available, add HTML Storage persistences
848
+ if (typeof window !== 'undefined') {
849
+ for (const persistence of [
850
+ exp.browserLocalPersistence,
851
+ exp.browserSessionPersistence
852
+ ]) {
853
+ if (!persistences.includes(persistence)) {
854
+ persistences.push(persistence);
855
+ }
856
+ }
857
+ }
858
+ // Add in-memory as a final fallback
859
+ if (!persistences.includes(exp.inMemoryPersistence)) {
860
+ persistences.push(exp.inMemoryPersistence);
861
+ }
862
+ return persistences;
863
+ }
864
+
865
+ /**
866
+ * @license
867
+ * Copyright 2020 Google LLC
868
+ *
869
+ * Licensed under the Apache License, Version 2.0 (the "License");
870
+ * you may not use this file except in compliance with the License.
871
+ * You may obtain a copy of the License at
872
+ *
873
+ * http://www.apache.org/licenses/LICENSE-2.0
874
+ *
875
+ * Unless required by applicable law or agreed to in writing, software
876
+ * distributed under the License is distributed on an "AS IS" BASIS,
877
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
878
+ * See the License for the specific language governing permissions and
879
+ * limitations under the License.
880
+ */
881
+ class PhoneAuthProvider {
882
+ static credential(verificationId, verificationCode) {
883
+ return exp.PhoneAuthProvider.credential(verificationId, verificationCode);
884
+ }
885
+ constructor() {
886
+ this.providerId = 'phone';
887
+ // TODO: remove ts-ignore when moving types from auth-types to auth-compat
888
+ // @ts-ignore
889
+ this._delegate = new exp.PhoneAuthProvider(unwrap(firebase.auth()));
890
+ }
891
+ verifyPhoneNumber(phoneInfoOptions, applicationVerifier) {
892
+ return this._delegate.verifyPhoneNumber(
893
+ // The implementation matches but the types are subtly incompatible
894
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
895
+ phoneInfoOptions, applicationVerifier);
896
+ }
897
+ unwrap() {
898
+ return this._delegate;
899
+ }
900
+ }
901
+ PhoneAuthProvider.PHONE_SIGN_IN_METHOD = exp.PhoneAuthProvider.PHONE_SIGN_IN_METHOD;
902
+ PhoneAuthProvider.PROVIDER_ID = exp.PhoneAuthProvider.PROVIDER_ID;
903
+
904
+ /**
905
+ * @license
906
+ * Copyright 2020 Google LLC
907
+ *
908
+ * Licensed under the Apache License, Version 2.0 (the "License");
909
+ * you may not use this file except in compliance with the License.
910
+ * You may obtain a copy of the License at
911
+ *
912
+ * http://www.apache.org/licenses/LICENSE-2.0
913
+ *
914
+ * Unless required by applicable law or agreed to in writing, software
915
+ * distributed under the License is distributed on an "AS IS" BASIS,
916
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
917
+ * See the License for the specific language governing permissions and
918
+ * limitations under the License.
919
+ */
920
+ const _assert = exp._assert;
921
+ class RecaptchaVerifier {
922
+ constructor(container, parameters, app = firebase.app()) {
923
+ // API key is required for web client RPC calls.
924
+ _assert(app.options?.apiKey, "invalid-api-key" /* exp.AuthErrorCode.INVALID_API_KEY */, {
925
+ appName: app.name
926
+ });
927
+ this._delegate = new exp.RecaptchaVerifier(
928
+ // TODO: remove ts-ignore when moving types from auth-types to auth-compat
929
+ // @ts-ignore
930
+ app.auth(), container,
931
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
932
+ parameters);
933
+ this.type = this._delegate.type;
934
+ }
935
+ clear() {
936
+ this._delegate.clear();
937
+ }
938
+ render() {
939
+ return this._delegate.render();
940
+ }
941
+ verify() {
942
+ return this._delegate.verify();
943
+ }
944
+ }
945
+
946
+ /**
947
+ * @license
948
+ * Copyright 2020 Google LLC
949
+ *
950
+ * Licensed under the Apache License, Version 2.0 (the "License");
951
+ * you may not use this file except in compliance with the License.
952
+ * You may obtain a copy of the License at
953
+ *
954
+ * http://www.apache.org/licenses/LICENSE-2.0
955
+ *
956
+ * Unless required by applicable law or agreed to in writing, software
957
+ * distributed under the License is distributed on an "AS IS" BASIS,
958
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
959
+ * See the License for the specific language governing permissions and
960
+ * limitations under the License.
961
+ */
962
+ const AUTH_TYPE = 'auth-compat';
963
+ // Create auth components to register with firebase.
964
+ // Provides Auth public APIs.
965
+ function registerAuthCompat(instance) {
966
+ instance.INTERNAL.registerComponent(new Component(AUTH_TYPE, container => {
967
+ // getImmediate for FirebaseApp will always succeed
968
+ const app = container.getProvider('app-compat').getImmediate();
969
+ const authProvider = container.getProvider('auth');
970
+ return new Auth(app, authProvider);
971
+ }, "PUBLIC" /* ComponentType.PUBLIC */)
972
+ .setServiceProps({
973
+ ActionCodeInfo: {
974
+ Operation: {
975
+ EMAIL_SIGNIN: exp.ActionCodeOperation.EMAIL_SIGNIN,
976
+ PASSWORD_RESET: exp.ActionCodeOperation.PASSWORD_RESET,
977
+ RECOVER_EMAIL: exp.ActionCodeOperation.RECOVER_EMAIL,
978
+ REVERT_SECOND_FACTOR_ADDITION: exp.ActionCodeOperation.REVERT_SECOND_FACTOR_ADDITION,
979
+ VERIFY_AND_CHANGE_EMAIL: exp.ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL,
980
+ VERIFY_EMAIL: exp.ActionCodeOperation.VERIFY_EMAIL
981
+ }
982
+ },
983
+ EmailAuthProvider: exp.EmailAuthProvider,
984
+ FacebookAuthProvider: exp.FacebookAuthProvider,
985
+ GithubAuthProvider: exp.GithubAuthProvider,
986
+ GoogleAuthProvider: exp.GoogleAuthProvider,
987
+ OAuthProvider: exp.OAuthProvider,
988
+ SAMLAuthProvider: exp.SAMLAuthProvider,
989
+ PhoneAuthProvider: PhoneAuthProvider,
990
+ PhoneMultiFactorGenerator: exp.PhoneMultiFactorGenerator,
991
+ RecaptchaVerifier: RecaptchaVerifier,
992
+ TwitterAuthProvider: exp.TwitterAuthProvider,
993
+ Auth,
994
+ AuthCredential: exp.AuthCredential,
995
+ Error: FirebaseError
996
+ })
997
+ .setInstantiationMode("LAZY" /* InstantiationMode.LAZY */)
998
+ .setMultipleInstances(false));
999
+ instance.registerVersion(name, version);
1000
+ }
1001
+ registerAuthCompat(firebase);
1002
+
1003
+ /**
1004
+ * @license
1005
+ * Copyright 2017 Google LLC
1006
+ *
1007
+ * Licensed under the Apache License, Version 2.0 (the "License");
1008
+ * you may not use this file except in compliance with the License.
1009
+ * You may obtain a copy of the License at
1010
+ *
1011
+ * http://www.apache.org/licenses/LICENSE-2.0
1012
+ *
1013
+ * Unless required by applicable law or agreed to in writing, software
1014
+ * distributed under the License is distributed on an "AS IS" BASIS,
1015
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1016
+ * See the License for the specific language governing permissions and
1017
+ * limitations under the License.
1018
+ */
1019
+ FetchProvider.initialize(fetch, Headers, Response);
1020
+ //# sourceMappingURL=index.node.esm.js.map