UNPKG

74.9 kBJavaScriptView Raw
1import { __extends, __assign } from 'tslib';
2
3/**
4 * @license
5 * Copyright 2017 Google LLC
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19/**
20 * @fileoverview Firebase constants. Some of these (@defines) can be overridden at compile-time.
21 */
22var CONSTANTS = {
23 /**
24 * @define {boolean} Whether this is the client Node.js SDK.
25 */
26 NODE_CLIENT: false,
27 /**
28 * @define {boolean} Whether this is the Admin Node.js SDK.
29 */
30 NODE_ADMIN: false,
31 /**
32 * Firebase SDK Version
33 */
34 SDK_VERSION: '${JSCORE_VERSION}'
35};
36
37/**
38 * @license
39 * Copyright 2017 Google LLC
40 *
41 * Licensed under the Apache License, Version 2.0 (the "License");
42 * you may not use this file except in compliance with the License.
43 * You may obtain a copy of the License at
44 *
45 * http://www.apache.org/licenses/LICENSE-2.0
46 *
47 * Unless required by applicable law or agreed to in writing, software
48 * distributed under the License is distributed on an "AS IS" BASIS,
49 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
50 * See the License for the specific language governing permissions and
51 * limitations under the License.
52 */
53/**
54 * Throws an error if the provided assertion is falsy
55 */
56var assert = function (assertion, message) {
57 if (!assertion) {
58 throw assertionError(message);
59 }
60};
61/**
62 * Returns an Error object suitable for throwing.
63 */
64var assertionError = function (message) {
65 return new Error('Firebase Database (' +
66 CONSTANTS.SDK_VERSION +
67 ') INTERNAL ASSERT FAILED: ' +
68 message);
69};
70
71/**
72 * @license
73 * Copyright 2017 Google LLC
74 *
75 * Licensed under the Apache License, Version 2.0 (the "License");
76 * you may not use this file except in compliance with the License.
77 * You may obtain a copy of the License at
78 *
79 * http://www.apache.org/licenses/LICENSE-2.0
80 *
81 * Unless required by applicable law or agreed to in writing, software
82 * distributed under the License is distributed on an "AS IS" BASIS,
83 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
84 * See the License for the specific language governing permissions and
85 * limitations under the License.
86 */
87var stringToByteArray$1 = function (str) {
88 // TODO(user): Use native implementations if/when available
89 var out = [];
90 var p = 0;
91 for (var i = 0; i < str.length; i++) {
92 var c = str.charCodeAt(i);
93 if (c < 128) {
94 out[p++] = c;
95 }
96 else if (c < 2048) {
97 out[p++] = (c >> 6) | 192;
98 out[p++] = (c & 63) | 128;
99 }
100 else if ((c & 0xfc00) === 0xd800 &&
101 i + 1 < str.length &&
102 (str.charCodeAt(i + 1) & 0xfc00) === 0xdc00) {
103 // Surrogate Pair
104 c = 0x10000 + ((c & 0x03ff) << 10) + (str.charCodeAt(++i) & 0x03ff);
105 out[p++] = (c >> 18) | 240;
106 out[p++] = ((c >> 12) & 63) | 128;
107 out[p++] = ((c >> 6) & 63) | 128;
108 out[p++] = (c & 63) | 128;
109 }
110 else {
111 out[p++] = (c >> 12) | 224;
112 out[p++] = ((c >> 6) & 63) | 128;
113 out[p++] = (c & 63) | 128;
114 }
115 }
116 return out;
117};
118/**
119 * Turns an array of numbers into the string given by the concatenation of the
120 * characters to which the numbers correspond.
121 * @param bytes Array of numbers representing characters.
122 * @return Stringification of the array.
123 */
124var byteArrayToString = function (bytes) {
125 // TODO(user): Use native implementations if/when available
126 var out = [];
127 var pos = 0, c = 0;
128 while (pos < bytes.length) {
129 var c1 = bytes[pos++];
130 if (c1 < 128) {
131 out[c++] = String.fromCharCode(c1);
132 }
133 else if (c1 > 191 && c1 < 224) {
134 var c2 = bytes[pos++];
135 out[c++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
136 }
137 else if (c1 > 239 && c1 < 365) {
138 // Surrogate Pair
139 var c2 = bytes[pos++];
140 var c3 = bytes[pos++];
141 var c4 = bytes[pos++];
142 var u = (((c1 & 7) << 18) | ((c2 & 63) << 12) | ((c3 & 63) << 6) | (c4 & 63)) -
143 0x10000;
144 out[c++] = String.fromCharCode(0xd800 + (u >> 10));
145 out[c++] = String.fromCharCode(0xdc00 + (u & 1023));
146 }
147 else {
148 var c2 = bytes[pos++];
149 var c3 = bytes[pos++];
150 out[c++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
151 }
152 }
153 return out.join('');
154};
155// We define it as an object literal instead of a class because a class compiled down to es5 can't
156// be treeshaked. https://github.com/rollup/rollup/issues/1691
157// Static lookup maps, lazily populated by init_()
158var base64 = {
159 /**
160 * Maps bytes to characters.
161 */
162 byteToCharMap_: null,
163 /**
164 * Maps characters to bytes.
165 */
166 charToByteMap_: null,
167 /**
168 * Maps bytes to websafe characters.
169 * @private
170 */
171 byteToCharMapWebSafe_: null,
172 /**
173 * Maps websafe characters to bytes.
174 * @private
175 */
176 charToByteMapWebSafe_: null,
177 /**
178 * Our default alphabet, shared between
179 * ENCODED_VALS and ENCODED_VALS_WEBSAFE
180 */
181 ENCODED_VALS_BASE: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + 'abcdefghijklmnopqrstuvwxyz' + '0123456789',
182 /**
183 * Our default alphabet. Value 64 (=) is special; it means "nothing."
184 */
185 get ENCODED_VALS() {
186 return this.ENCODED_VALS_BASE + '+/=';
187 },
188 /**
189 * Our websafe alphabet.
190 */
191 get ENCODED_VALS_WEBSAFE() {
192 return this.ENCODED_VALS_BASE + '-_.';
193 },
194 /**
195 * Whether this browser supports the atob and btoa functions. This extension
196 * started at Mozilla but is now implemented by many browsers. We use the
197 * ASSUME_* variables to avoid pulling in the full useragent detection library
198 * but still allowing the standard per-browser compilations.
199 *
200 */
201 HAS_NATIVE_SUPPORT: typeof atob === 'function',
202 /**
203 * Base64-encode an array of bytes.
204 *
205 * @param input An array of bytes (numbers with
206 * value in [0, 255]) to encode.
207 * @param webSafe Boolean indicating we should use the
208 * alternative alphabet.
209 * @return The base64 encoded string.
210 */
211 encodeByteArray: function (input, webSafe) {
212 if (!Array.isArray(input)) {
213 throw Error('encodeByteArray takes an array as a parameter');
214 }
215 this.init_();
216 var byteToCharMap = webSafe
217 ? this.byteToCharMapWebSafe_
218 : this.byteToCharMap_;
219 var output = [];
220 for (var i = 0; i < input.length; i += 3) {
221 var byte1 = input[i];
222 var haveByte2 = i + 1 < input.length;
223 var byte2 = haveByte2 ? input[i + 1] : 0;
224 var haveByte3 = i + 2 < input.length;
225 var byte3 = haveByte3 ? input[i + 2] : 0;
226 var outByte1 = byte1 >> 2;
227 var outByte2 = ((byte1 & 0x03) << 4) | (byte2 >> 4);
228 var outByte3 = ((byte2 & 0x0f) << 2) | (byte3 >> 6);
229 var outByte4 = byte3 & 0x3f;
230 if (!haveByte3) {
231 outByte4 = 64;
232 if (!haveByte2) {
233 outByte3 = 64;
234 }
235 }
236 output.push(byteToCharMap[outByte1], byteToCharMap[outByte2], byteToCharMap[outByte3], byteToCharMap[outByte4]);
237 }
238 return output.join('');
239 },
240 /**
241 * Base64-encode a string.
242 *
243 * @param input A string to encode.
244 * @param webSafe If true, we should use the
245 * alternative alphabet.
246 * @return The base64 encoded string.
247 */
248 encodeString: function (input, webSafe) {
249 // Shortcut for Mozilla browsers that implement
250 // a native base64 encoder in the form of "btoa/atob"
251 if (this.HAS_NATIVE_SUPPORT && !webSafe) {
252 return btoa(input);
253 }
254 return this.encodeByteArray(stringToByteArray$1(input), webSafe);
255 },
256 /**
257 * Base64-decode a string.
258 *
259 * @param input to decode.
260 * @param webSafe True if we should use the
261 * alternative alphabet.
262 * @return string representing the decoded value.
263 */
264 decodeString: function (input, webSafe) {
265 // Shortcut for Mozilla browsers that implement
266 // a native base64 encoder in the form of "btoa/atob"
267 if (this.HAS_NATIVE_SUPPORT && !webSafe) {
268 return atob(input);
269 }
270 return byteArrayToString(this.decodeStringToByteArray(input, webSafe));
271 },
272 /**
273 * Base64-decode a string.
274 *
275 * In base-64 decoding, groups of four characters are converted into three
276 * bytes. If the encoder did not apply padding, the input length may not
277 * be a multiple of 4.
278 *
279 * In this case, the last group will have fewer than 4 characters, and
280 * padding will be inferred. If the group has one or two characters, it decodes
281 * to one byte. If the group has three characters, it decodes to two bytes.
282 *
283 * @param input Input to decode.
284 * @param webSafe True if we should use the web-safe alphabet.
285 * @return bytes representing the decoded value.
286 */
287 decodeStringToByteArray: function (input, webSafe) {
288 this.init_();
289 var charToByteMap = webSafe
290 ? this.charToByteMapWebSafe_
291 : this.charToByteMap_;
292 var output = [];
293 for (var i = 0; i < input.length;) {
294 var byte1 = charToByteMap[input.charAt(i++)];
295 var haveByte2 = i < input.length;
296 var byte2 = haveByte2 ? charToByteMap[input.charAt(i)] : 0;
297 ++i;
298 var haveByte3 = i < input.length;
299 var byte3 = haveByte3 ? charToByteMap[input.charAt(i)] : 64;
300 ++i;
301 var haveByte4 = i < input.length;
302 var byte4 = haveByte4 ? charToByteMap[input.charAt(i)] : 64;
303 ++i;
304 if (byte1 == null || byte2 == null || byte3 == null || byte4 == null) {
305 throw new DecodeBase64StringError();
306 }
307 var outByte1 = (byte1 << 2) | (byte2 >> 4);
308 output.push(outByte1);
309 if (byte3 !== 64) {
310 var outByte2 = ((byte2 << 4) & 0xf0) | (byte3 >> 2);
311 output.push(outByte2);
312 if (byte4 !== 64) {
313 var outByte3 = ((byte3 << 6) & 0xc0) | byte4;
314 output.push(outByte3);
315 }
316 }
317 }
318 return output;
319 },
320 /**
321 * Lazy static initialization function. Called before
322 * accessing any of the static map variables.
323 * @private
324 */
325 init_: function () {
326 if (!this.byteToCharMap_) {
327 this.byteToCharMap_ = {};
328 this.charToByteMap_ = {};
329 this.byteToCharMapWebSafe_ = {};
330 this.charToByteMapWebSafe_ = {};
331 // We want quick mappings back and forth, so we precompute two maps.
332 for (var i = 0; i < this.ENCODED_VALS.length; i++) {
333 this.byteToCharMap_[i] = this.ENCODED_VALS.charAt(i);
334 this.charToByteMap_[this.byteToCharMap_[i]] = i;
335 this.byteToCharMapWebSafe_[i] = this.ENCODED_VALS_WEBSAFE.charAt(i);
336 this.charToByteMapWebSafe_[this.byteToCharMapWebSafe_[i]] = i;
337 // Be forgiving when decoding and correctly decode both encodings.
338 if (i >= this.ENCODED_VALS_BASE.length) {
339 this.charToByteMap_[this.ENCODED_VALS_WEBSAFE.charAt(i)] = i;
340 this.charToByteMapWebSafe_[this.ENCODED_VALS.charAt(i)] = i;
341 }
342 }
343 }
344 }
345};
346/**
347 * An error encountered while decoding base64 string.
348 */
349var DecodeBase64StringError = /** @class */ (function (_super) {
350 __extends(DecodeBase64StringError, _super);
351 function DecodeBase64StringError() {
352 var _this = _super !== null && _super.apply(this, arguments) || this;
353 _this.name = 'DecodeBase64StringError';
354 return _this;
355 }
356 return DecodeBase64StringError;
357}(Error));
358/**
359 * URL-safe base64 encoding
360 */
361var base64Encode = function (str) {
362 var utf8Bytes = stringToByteArray$1(str);
363 return base64.encodeByteArray(utf8Bytes, true);
364};
365/**
366 * URL-safe base64 encoding (without "." padding in the end).
367 * e.g. Used in JSON Web Token (JWT) parts.
368 */
369var base64urlEncodeWithoutPadding = function (str) {
370 // Use base64url encoding and remove padding in the end (dot characters).
371 return base64Encode(str).replace(/\./g, '');
372};
373/**
374 * URL-safe base64 decoding
375 *
376 * NOTE: DO NOT use the global atob() function - it does NOT support the
377 * base64Url variant encoding.
378 *
379 * @param str To be decoded
380 * @return Decoded result, if possible
381 */
382var base64Decode = function (str) {
383 try {
384 return base64.decodeString(str, true);
385 }
386 catch (e) {
387 console.error('base64Decode failed: ', e);
388 }
389 return null;
390};
391
392/**
393 * @license
394 * Copyright 2017 Google LLC
395 *
396 * Licensed under the Apache License, Version 2.0 (the "License");
397 * you may not use this file except in compliance with the License.
398 * You may obtain a copy of the License at
399 *
400 * http://www.apache.org/licenses/LICENSE-2.0
401 *
402 * Unless required by applicable law or agreed to in writing, software
403 * distributed under the License is distributed on an "AS IS" BASIS,
404 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
405 * See the License for the specific language governing permissions and
406 * limitations under the License.
407 */
408/**
409 * Do a deep-copy of basic JavaScript Objects or Arrays.
410 */
411function deepCopy(value) {
412 return deepExtend(undefined, value);
413}
414/**
415 * Copy properties from source to target (recursively allows extension
416 * of Objects and Arrays). Scalar values in the target are over-written.
417 * If target is undefined, an object of the appropriate type will be created
418 * (and returned).
419 *
420 * We recursively copy all child properties of plain Objects in the source- so
421 * that namespace- like dictionaries are merged.
422 *
423 * Note that the target can be a function, in which case the properties in
424 * the source Object are copied onto it as static properties of the Function.
425 *
426 * Note: we don't merge __proto__ to prevent prototype pollution
427 */
428function deepExtend(target, source) {
429 if (!(source instanceof Object)) {
430 return source;
431 }
432 switch (source.constructor) {
433 case Date:
434 // Treat Dates like scalars; if the target date object had any child
435 // properties - they will be lost!
436 var dateValue = source;
437 return new Date(dateValue.getTime());
438 case Object:
439 if (target === undefined) {
440 target = {};
441 }
442 break;
443 case Array:
444 // Always copy the array source and overwrite the target.
445 target = [];
446 break;
447 default:
448 // Not a plain Object - treat it as a scalar.
449 return source;
450 }
451 for (var prop in source) {
452 // use isValidKey to guard against prototype pollution. See https://snyk.io/vuln/SNYK-JS-LODASH-450202
453 if (!source.hasOwnProperty(prop) || !isValidKey(prop)) {
454 continue;
455 }
456 target[prop] = deepExtend(target[prop], source[prop]);
457 }
458 return target;
459}
460function isValidKey(key) {
461 return key !== '__proto__';
462}
463
464/**
465 * @license
466 * Copyright 2022 Google LLC
467 *
468 * Licensed under the Apache License, Version 2.0 (the "License");
469 * you may not use this file except in compliance with the License.
470 * You may obtain a copy of the License at
471 *
472 * http://www.apache.org/licenses/LICENSE-2.0
473 *
474 * Unless required by applicable law or agreed to in writing, software
475 * distributed under the License is distributed on an "AS IS" BASIS,
476 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
477 * See the License for the specific language governing permissions and
478 * limitations under the License.
479 */
480/**
481 * Polyfill for `globalThis` object.
482 * @returns the `globalThis` object for the given environment.
483 * @public
484 */
485function getGlobal() {
486 if (typeof self !== 'undefined') {
487 return self;
488 }
489 if (typeof window !== 'undefined') {
490 return window;
491 }
492 if (typeof global !== 'undefined') {
493 return global;
494 }
495 throw new Error('Unable to locate global object.');
496}
497
498/**
499 * @license
500 * Copyright 2022 Google LLC
501 *
502 * Licensed under the Apache License, Version 2.0 (the "License");
503 * you may not use this file except in compliance with the License.
504 * You may obtain a copy of the License at
505 *
506 * http://www.apache.org/licenses/LICENSE-2.0
507 *
508 * Unless required by applicable law or agreed to in writing, software
509 * distributed under the License is distributed on an "AS IS" BASIS,
510 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
511 * See the License for the specific language governing permissions and
512 * limitations under the License.
513 */
514var getDefaultsFromGlobal = function () {
515 return getGlobal().__FIREBASE_DEFAULTS__;
516};
517/**
518 * Attempt to read defaults from a JSON string provided to
519 * process(.)env(.)__FIREBASE_DEFAULTS__ or a JSON file whose path is in
520 * process(.)env(.)__FIREBASE_DEFAULTS_PATH__
521 * The dots are in parens because certain compilers (Vite?) cannot
522 * handle seeing that variable in comments.
523 * See https://github.com/firebase/firebase-js-sdk/issues/6838
524 */
525var getDefaultsFromEnvVariable = function () {
526 if (typeof process === 'undefined' || typeof process.env === 'undefined') {
527 return;
528 }
529 var defaultsJsonString = process.env.__FIREBASE_DEFAULTS__;
530 if (defaultsJsonString) {
531 return JSON.parse(defaultsJsonString);
532 }
533};
534var getDefaultsFromCookie = function () {
535 if (typeof document === 'undefined') {
536 return;
537 }
538 var match;
539 try {
540 match = document.cookie.match(/__FIREBASE_DEFAULTS__=([^;]+)/);
541 }
542 catch (e) {
543 // Some environments such as Angular Universal SSR have a
544 // `document` object but error on accessing `document.cookie`.
545 return;
546 }
547 var decoded = match && base64Decode(match[1]);
548 return decoded && JSON.parse(decoded);
549};
550/**
551 * Get the __FIREBASE_DEFAULTS__ object. It checks in order:
552 * (1) if such an object exists as a property of `globalThis`
553 * (2) if such an object was provided on a shell environment variable
554 * (3) if such an object exists in a cookie
555 * @public
556 */
557var getDefaults = function () {
558 try {
559 return (getDefaultsFromGlobal() ||
560 getDefaultsFromEnvVariable() ||
561 getDefaultsFromCookie());
562 }
563 catch (e) {
564 /**
565 * Catch-all for being unable to get __FIREBASE_DEFAULTS__ due
566 * to any environment case we have not accounted for. Log to
567 * info instead of swallowing so we can find these unknown cases
568 * and add paths for them if needed.
569 */
570 console.info("Unable to get __FIREBASE_DEFAULTS__ due to: ".concat(e));
571 return;
572 }
573};
574/**
575 * Returns emulator host stored in the __FIREBASE_DEFAULTS__ object
576 * for the given product.
577 * @returns a URL host formatted like `127.0.0.1:9999` or `[::1]:4000` if available
578 * @public
579 */
580var getDefaultEmulatorHost = function (productName) { var _a, _b; return (_b = (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a.emulatorHosts) === null || _b === void 0 ? void 0 : _b[productName]; };
581/**
582 * Returns emulator hostname and port stored in the __FIREBASE_DEFAULTS__ object
583 * for the given product.
584 * @returns a pair of hostname and port like `["::1", 4000]` if available
585 * @public
586 */
587var getDefaultEmulatorHostnameAndPort = function (productName) {
588 var host = getDefaultEmulatorHost(productName);
589 if (!host) {
590 return undefined;
591 }
592 var separatorIndex = host.lastIndexOf(':'); // Finding the last since IPv6 addr also has colons.
593 if (separatorIndex <= 0 || separatorIndex + 1 === host.length) {
594 throw new Error("Invalid host ".concat(host, " with no separate hostname and port!"));
595 }
596 // eslint-disable-next-line no-restricted-globals
597 var port = parseInt(host.substring(separatorIndex + 1), 10);
598 if (host[0] === '[') {
599 // Bracket-quoted `[ipv6addr]:port` => return "ipv6addr" (without brackets).
600 return [host.substring(1, separatorIndex - 1), port];
601 }
602 else {
603 return [host.substring(0, separatorIndex), port];
604 }
605};
606/**
607 * Returns Firebase app config stored in the __FIREBASE_DEFAULTS__ object.
608 * @public
609 */
610var getDefaultAppConfig = function () { var _a; return (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a.config; };
611/**
612 * Returns an experimental setting on the __FIREBASE_DEFAULTS__ object (properties
613 * prefixed by "_")
614 * @public
615 */
616var getExperimentalSetting = function (name) { var _a; return (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a["_".concat(name)]; };
617
618/**
619 * @license
620 * Copyright 2017 Google LLC
621 *
622 * Licensed under the Apache License, Version 2.0 (the "License");
623 * you may not use this file except in compliance with the License.
624 * You may obtain a copy of the License at
625 *
626 * http://www.apache.org/licenses/LICENSE-2.0
627 *
628 * Unless required by applicable law or agreed to in writing, software
629 * distributed under the License is distributed on an "AS IS" BASIS,
630 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
631 * See the License for the specific language governing permissions and
632 * limitations under the License.
633 */
634var Deferred = /** @class */ (function () {
635 function Deferred() {
636 var _this = this;
637 this.reject = function () { };
638 this.resolve = function () { };
639 this.promise = new Promise(function (resolve, reject) {
640 _this.resolve = resolve;
641 _this.reject = reject;
642 });
643 }
644 /**
645 * Our API internals are not promiseified and cannot because our callback APIs have subtle expectations around
646 * invoking promises inline, which Promises are forbidden to do. This method accepts an optional node-style callback
647 * and returns a node-style callback which will resolve or reject the Deferred's promise.
648 */
649 Deferred.prototype.wrapCallback = function (callback) {
650 var _this = this;
651 return function (error, value) {
652 if (error) {
653 _this.reject(error);
654 }
655 else {
656 _this.resolve(value);
657 }
658 if (typeof callback === 'function') {
659 // Attaching noop handler just in case developer wasn't expecting
660 // promises
661 _this.promise.catch(function () { });
662 // Some of our callbacks don't expect a value and our own tests
663 // assert that the parameter length is 1
664 if (callback.length === 1) {
665 callback(error);
666 }
667 else {
668 callback(error, value);
669 }
670 }
671 };
672 };
673 return Deferred;
674}());
675
676/**
677 * @license
678 * Copyright 2021 Google LLC
679 *
680 * Licensed under the Apache License, Version 2.0 (the "License");
681 * you may not use this file except in compliance with the License.
682 * You may obtain a copy of the License at
683 *
684 * http://www.apache.org/licenses/LICENSE-2.0
685 *
686 * Unless required by applicable law or agreed to in writing, software
687 * distributed under the License is distributed on an "AS IS" BASIS,
688 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
689 * See the License for the specific language governing permissions and
690 * limitations under the License.
691 */
692function createMockUserToken(token, projectId) {
693 if (token.uid) {
694 throw new Error('The "uid" field is no longer supported by mockUserToken. Please use "sub" instead for Firebase Auth User ID.');
695 }
696 // Unsecured JWTs use "none" as the algorithm.
697 var header = {
698 alg: 'none',
699 type: 'JWT'
700 };
701 var project = projectId || 'demo-project';
702 var iat = token.iat || 0;
703 var sub = token.sub || token.user_id;
704 if (!sub) {
705 throw new Error("mockUserToken must contain 'sub' or 'user_id' field!");
706 }
707 var payload = __assign({
708 // Set all required fields to decent defaults
709 iss: "https://securetoken.google.com/".concat(project), aud: project, iat: iat, exp: iat + 3600, auth_time: iat, sub: sub, user_id: sub, firebase: {
710 sign_in_provider: 'custom',
711 identities: {}
712 } }, token);
713 // Unsecured JWTs use the empty string as a signature.
714 var signature = '';
715 return [
716 base64urlEncodeWithoutPadding(JSON.stringify(header)),
717 base64urlEncodeWithoutPadding(JSON.stringify(payload)),
718 signature
719 ].join('.');
720}
721
722/**
723 * @license
724 * Copyright 2017 Google LLC
725 *
726 * Licensed under the Apache License, Version 2.0 (the "License");
727 * you may not use this file except in compliance with the License.
728 * You may obtain a copy of the License at
729 *
730 * http://www.apache.org/licenses/LICENSE-2.0
731 *
732 * Unless required by applicable law or agreed to in writing, software
733 * distributed under the License is distributed on an "AS IS" BASIS,
734 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
735 * See the License for the specific language governing permissions and
736 * limitations under the License.
737 */
738/**
739 * Returns navigator.userAgent string or '' if it's not defined.
740 * @return user agent string
741 */
742function getUA() {
743 if (typeof navigator !== 'undefined' &&
744 typeof navigator['userAgent'] === 'string') {
745 return navigator['userAgent'];
746 }
747 else {
748 return '';
749 }
750}
751/**
752 * Detect Cordova / PhoneGap / Ionic frameworks on a mobile device.
753 *
754 * Deliberately does not rely on checking `file://` URLs (as this fails PhoneGap
755 * in the Ripple emulator) nor Cordova `onDeviceReady`, which would normally
756 * wait for a callback.
757 */
758function isMobileCordova() {
759 return (typeof window !== 'undefined' &&
760 // @ts-ignore Setting up an broadly applicable index signature for Window
761 // just to deal with this case would probably be a bad idea.
762 !!(window['cordova'] || window['phonegap'] || window['PhoneGap']) &&
763 /ios|iphone|ipod|ipad|android|blackberry|iemobile/i.test(getUA()));
764}
765/**
766 * Detect Node.js.
767 *
768 * @return true if Node.js environment is detected or specified.
769 */
770// Node detection logic from: https://github.com/iliakan/detect-node/
771function isNode() {
772 var _a;
773 var forceEnvironment = (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a.forceEnvironment;
774 if (forceEnvironment === 'node') {
775 return true;
776 }
777 else if (forceEnvironment === 'browser') {
778 return false;
779 }
780 try {
781 return (Object.prototype.toString.call(global.process) === '[object process]');
782 }
783 catch (e) {
784 return false;
785 }
786}
787/**
788 * Detect Browser Environment
789 */
790function isBrowser() {
791 return typeof self === 'object' && self.self === self;
792}
793function isBrowserExtension() {
794 var runtime = typeof chrome === 'object'
795 ? chrome.runtime
796 : typeof browser === 'object'
797 ? browser.runtime
798 : undefined;
799 return typeof runtime === 'object' && runtime.id !== undefined;
800}
801/**
802 * Detect React Native.
803 *
804 * @return true if ReactNative environment is detected.
805 */
806function isReactNative() {
807 return (typeof navigator === 'object' && navigator['product'] === 'ReactNative');
808}
809/** Detects Electron apps. */
810function isElectron() {
811 return getUA().indexOf('Electron/') >= 0;
812}
813/** Detects Internet Explorer. */
814function isIE() {
815 var ua = getUA();
816 return ua.indexOf('MSIE ') >= 0 || ua.indexOf('Trident/') >= 0;
817}
818/** Detects Universal Windows Platform apps. */
819function isUWP() {
820 return getUA().indexOf('MSAppHost/') >= 0;
821}
822/**
823 * Detect whether the current SDK build is the Node version.
824 *
825 * @return true if it's the Node SDK build.
826 */
827function isNodeSdk() {
828 return CONSTANTS.NODE_CLIENT === true || CONSTANTS.NODE_ADMIN === true;
829}
830/** Returns true if we are running in Safari. */
831function isSafari() {
832 return (!isNode() &&
833 navigator.userAgent.includes('Safari') &&
834 !navigator.userAgent.includes('Chrome'));
835}
836/**
837 * This method checks if indexedDB is supported by current browser/service worker context
838 * @return true if indexedDB is supported by current browser/service worker context
839 */
840function isIndexedDBAvailable() {
841 try {
842 return typeof indexedDB === 'object';
843 }
844 catch (e) {
845 return false;
846 }
847}
848/**
849 * This method validates browser/sw context for indexedDB by opening a dummy indexedDB database and reject
850 * if errors occur during the database open operation.
851 *
852 * @throws exception if current browser/sw context can't run idb.open (ex: Safari iframe, Firefox
853 * private browsing)
854 */
855function validateIndexedDBOpenable() {
856 return new Promise(function (resolve, reject) {
857 try {
858 var preExist_1 = true;
859 var DB_CHECK_NAME_1 = 'validate-browser-context-for-indexeddb-analytics-module';
860 var request_1 = self.indexedDB.open(DB_CHECK_NAME_1);
861 request_1.onsuccess = function () {
862 request_1.result.close();
863 // delete database only when it doesn't pre-exist
864 if (!preExist_1) {
865 self.indexedDB.deleteDatabase(DB_CHECK_NAME_1);
866 }
867 resolve(true);
868 };
869 request_1.onupgradeneeded = function () {
870 preExist_1 = false;
871 };
872 request_1.onerror = function () {
873 var _a;
874 reject(((_a = request_1.error) === null || _a === void 0 ? void 0 : _a.message) || '');
875 };
876 }
877 catch (error) {
878 reject(error);
879 }
880 });
881}
882/**
883 *
884 * This method checks whether cookie is enabled within current browser
885 * @return true if cookie is enabled within current browser
886 */
887function areCookiesEnabled() {
888 if (typeof navigator === 'undefined' || !navigator.cookieEnabled) {
889 return false;
890 }
891 return true;
892}
893
894/**
895 * @license
896 * Copyright 2017 Google LLC
897 *
898 * Licensed under the Apache License, Version 2.0 (the "License");
899 * you may not use this file except in compliance with the License.
900 * You may obtain a copy of the License at
901 *
902 * http://www.apache.org/licenses/LICENSE-2.0
903 *
904 * Unless required by applicable law or agreed to in writing, software
905 * distributed under the License is distributed on an "AS IS" BASIS,
906 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
907 * See the License for the specific language governing permissions and
908 * limitations under the License.
909 */
910var ERROR_NAME = 'FirebaseError';
911// Based on code from:
912// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Custom_Error_Types
913var FirebaseError = /** @class */ (function (_super) {
914 __extends(FirebaseError, _super);
915 function FirebaseError(
916 /** The error code for this error. */
917 code, message,
918 /** Custom data for this error. */
919 customData) {
920 var _this = _super.call(this, message) || this;
921 _this.code = code;
922 _this.customData = customData;
923 /** The custom name for all FirebaseErrors. */
924 _this.name = ERROR_NAME;
925 // Fix For ES5
926 // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
927 Object.setPrototypeOf(_this, FirebaseError.prototype);
928 // Maintains proper stack trace for where our error was thrown.
929 // Only available on V8.
930 if (Error.captureStackTrace) {
931 Error.captureStackTrace(_this, ErrorFactory.prototype.create);
932 }
933 return _this;
934 }
935 return FirebaseError;
936}(Error));
937var ErrorFactory = /** @class */ (function () {
938 function ErrorFactory(service, serviceName, errors) {
939 this.service = service;
940 this.serviceName = serviceName;
941 this.errors = errors;
942 }
943 ErrorFactory.prototype.create = function (code) {
944 var data = [];
945 for (var _i = 1; _i < arguments.length; _i++) {
946 data[_i - 1] = arguments[_i];
947 }
948 var customData = data[0] || {};
949 var fullCode = "".concat(this.service, "/").concat(code);
950 var template = this.errors[code];
951 var message = template ? replaceTemplate(template, customData) : 'Error';
952 // Service Name: Error message (service/code).
953 var fullMessage = "".concat(this.serviceName, ": ").concat(message, " (").concat(fullCode, ").");
954 var error = new FirebaseError(fullCode, fullMessage, customData);
955 return error;
956 };
957 return ErrorFactory;
958}());
959function replaceTemplate(template, data) {
960 return template.replace(PATTERN, function (_, key) {
961 var value = data[key];
962 return value != null ? String(value) : "<".concat(key, "?>");
963 });
964}
965var PATTERN = /\{\$([^}]+)}/g;
966
967/**
968 * @license
969 * Copyright 2017 Google LLC
970 *
971 * Licensed under the Apache License, Version 2.0 (the "License");
972 * you may not use this file except in compliance with the License.
973 * You may obtain a copy of the License at
974 *
975 * http://www.apache.org/licenses/LICENSE-2.0
976 *
977 * Unless required by applicable law or agreed to in writing, software
978 * distributed under the License is distributed on an "AS IS" BASIS,
979 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
980 * See the License for the specific language governing permissions and
981 * limitations under the License.
982 */
983/**
984 * Evaluates a JSON string into a javascript object.
985 *
986 * @param {string} str A string containing JSON.
987 * @return {*} The javascript object representing the specified JSON.
988 */
989function jsonEval(str) {
990 return JSON.parse(str);
991}
992/**
993 * Returns JSON representing a javascript object.
994 * @param {*} data Javascript object to be stringified.
995 * @return {string} The JSON contents of the object.
996 */
997function stringify(data) {
998 return JSON.stringify(data);
999}
1000
1001/**
1002 * @license
1003 * Copyright 2017 Google LLC
1004 *
1005 * Licensed under the Apache License, Version 2.0 (the "License");
1006 * you may not use this file except in compliance with the License.
1007 * You may obtain a copy of the License at
1008 *
1009 * http://www.apache.org/licenses/LICENSE-2.0
1010 *
1011 * Unless required by applicable law or agreed to in writing, software
1012 * distributed under the License is distributed on an "AS IS" BASIS,
1013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1014 * See the License for the specific language governing permissions and
1015 * limitations under the License.
1016 */
1017/**
1018 * Decodes a Firebase auth. token into constituent parts.
1019 *
1020 * Notes:
1021 * - May return with invalid / incomplete claims if there's no native base64 decoding support.
1022 * - Doesn't check if the token is actually valid.
1023 */
1024var decode = function (token) {
1025 var header = {}, claims = {}, data = {}, signature = '';
1026 try {
1027 var parts = token.split('.');
1028 header = jsonEval(base64Decode(parts[0]) || '');
1029 claims = jsonEval(base64Decode(parts[1]) || '');
1030 signature = parts[2];
1031 data = claims['d'] || {};
1032 delete claims['d'];
1033 }
1034 catch (e) { }
1035 return {
1036 header: header,
1037 claims: claims,
1038 data: data,
1039 signature: signature
1040 };
1041};
1042/**
1043 * Decodes a Firebase auth. token and checks the validity of its time-based claims. Will return true if the
1044 * token is within the time window authorized by the 'nbf' (not-before) and 'iat' (issued-at) claims.
1045 *
1046 * Notes:
1047 * - May return a false negative if there's no native base64 decoding support.
1048 * - Doesn't check if the token is actually valid.
1049 */
1050var isValidTimestamp = function (token) {
1051 var claims = decode(token).claims;
1052 var now = Math.floor(new Date().getTime() / 1000);
1053 var validSince = 0, validUntil = 0;
1054 if (typeof claims === 'object') {
1055 if (claims.hasOwnProperty('nbf')) {
1056 validSince = claims['nbf'];
1057 }
1058 else if (claims.hasOwnProperty('iat')) {
1059 validSince = claims['iat'];
1060 }
1061 if (claims.hasOwnProperty('exp')) {
1062 validUntil = claims['exp'];
1063 }
1064 else {
1065 // token will expire after 24h by default
1066 validUntil = validSince + 86400;
1067 }
1068 }
1069 return (!!now &&
1070 !!validSince &&
1071 !!validUntil &&
1072 now >= validSince &&
1073 now <= validUntil);
1074};
1075/**
1076 * Decodes a Firebase auth. token and returns its issued at time if valid, null otherwise.
1077 *
1078 * Notes:
1079 * - May return null if there's no native base64 decoding support.
1080 * - Doesn't check if the token is actually valid.
1081 */
1082var issuedAtTime = function (token) {
1083 var claims = decode(token).claims;
1084 if (typeof claims === 'object' && claims.hasOwnProperty('iat')) {
1085 return claims['iat'];
1086 }
1087 return null;
1088};
1089/**
1090 * Decodes a Firebase auth. token and checks the validity of its format. Expects a valid issued-at time.
1091 *
1092 * Notes:
1093 * - May return a false negative if there's no native base64 decoding support.
1094 * - Doesn't check if the token is actually valid.
1095 */
1096var isValidFormat = function (token) {
1097 var decoded = decode(token), claims = decoded.claims;
1098 return !!claims && typeof claims === 'object' && claims.hasOwnProperty('iat');
1099};
1100/**
1101 * Attempts to peer into an auth token and determine if it's an admin auth token by looking at the claims portion.
1102 *
1103 * Notes:
1104 * - May return a false negative if there's no native base64 decoding support.
1105 * - Doesn't check if the token is actually valid.
1106 */
1107var isAdmin = function (token) {
1108 var claims = decode(token).claims;
1109 return typeof claims === 'object' && claims['admin'] === true;
1110};
1111
1112/**
1113 * @license
1114 * Copyright 2017 Google LLC
1115 *
1116 * Licensed under the Apache License, Version 2.0 (the "License");
1117 * you may not use this file except in compliance with the License.
1118 * You may obtain a copy of the License at
1119 *
1120 * http://www.apache.org/licenses/LICENSE-2.0
1121 *
1122 * Unless required by applicable law or agreed to in writing, software
1123 * distributed under the License is distributed on an "AS IS" BASIS,
1124 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1125 * See the License for the specific language governing permissions and
1126 * limitations under the License.
1127 */
1128function contains(obj, key) {
1129 return Object.prototype.hasOwnProperty.call(obj, key);
1130}
1131function safeGet(obj, key) {
1132 if (Object.prototype.hasOwnProperty.call(obj, key)) {
1133 return obj[key];
1134 }
1135 else {
1136 return undefined;
1137 }
1138}
1139function isEmpty(obj) {
1140 for (var key in obj) {
1141 if (Object.prototype.hasOwnProperty.call(obj, key)) {
1142 return false;
1143 }
1144 }
1145 return true;
1146}
1147function map(obj, fn, contextObj) {
1148 var res = {};
1149 for (var key in obj) {
1150 if (Object.prototype.hasOwnProperty.call(obj, key)) {
1151 res[key] = fn.call(contextObj, obj[key], key, obj);
1152 }
1153 }
1154 return res;
1155}
1156/**
1157 * Deep equal two objects. Support Arrays and Objects.
1158 */
1159function deepEqual(a, b) {
1160 if (a === b) {
1161 return true;
1162 }
1163 var aKeys = Object.keys(a);
1164 var bKeys = Object.keys(b);
1165 for (var _i = 0, aKeys_1 = aKeys; _i < aKeys_1.length; _i++) {
1166 var k = aKeys_1[_i];
1167 if (!bKeys.includes(k)) {
1168 return false;
1169 }
1170 var aProp = a[k];
1171 var bProp = b[k];
1172 if (isObject(aProp) && isObject(bProp)) {
1173 if (!deepEqual(aProp, bProp)) {
1174 return false;
1175 }
1176 }
1177 else if (aProp !== bProp) {
1178 return false;
1179 }
1180 }
1181 for (var _a = 0, bKeys_1 = bKeys; _a < bKeys_1.length; _a++) {
1182 var k = bKeys_1[_a];
1183 if (!aKeys.includes(k)) {
1184 return false;
1185 }
1186 }
1187 return true;
1188}
1189function isObject(thing) {
1190 return thing !== null && typeof thing === 'object';
1191}
1192
1193/**
1194 * @license
1195 * Copyright 2022 Google LLC
1196 *
1197 * Licensed under the Apache License, Version 2.0 (the "License");
1198 * you may not use this file except in compliance with the License.
1199 * You may obtain a copy of the License at
1200 *
1201 * http://www.apache.org/licenses/LICENSE-2.0
1202 *
1203 * Unless required by applicable law or agreed to in writing, software
1204 * distributed under the License is distributed on an "AS IS" BASIS,
1205 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1206 * See the License for the specific language governing permissions and
1207 * limitations under the License.
1208 */
1209/**
1210 * Rejects if the given promise doesn't resolve in timeInMS milliseconds.
1211 * @internal
1212 */
1213function promiseWithTimeout(promise, timeInMS) {
1214 if (timeInMS === void 0) { timeInMS = 2000; }
1215 var deferredPromise = new Deferred();
1216 setTimeout(function () { return deferredPromise.reject('timeout!'); }, timeInMS);
1217 promise.then(deferredPromise.resolve, deferredPromise.reject);
1218 return deferredPromise.promise;
1219}
1220
1221/**
1222 * @license
1223 * Copyright 2017 Google LLC
1224 *
1225 * Licensed under the Apache License, Version 2.0 (the "License");
1226 * you may not use this file except in compliance with the License.
1227 * You may obtain a copy of the License at
1228 *
1229 * http://www.apache.org/licenses/LICENSE-2.0
1230 *
1231 * Unless required by applicable law or agreed to in writing, software
1232 * distributed under the License is distributed on an "AS IS" BASIS,
1233 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1234 * See the License for the specific language governing permissions and
1235 * limitations under the License.
1236 */
1237/**
1238 * Returns a querystring-formatted string (e.g. &arg=val&arg2=val2) from a
1239 * params object (e.g. {arg: 'val', arg2: 'val2'})
1240 * Note: You must prepend it with ? when adding it to a URL.
1241 */
1242function querystring(querystringParams) {
1243 var params = [];
1244 var _loop_1 = function (key, value) {
1245 if (Array.isArray(value)) {
1246 value.forEach(function (arrayVal) {
1247 params.push(encodeURIComponent(key) + '=' + encodeURIComponent(arrayVal));
1248 });
1249 }
1250 else {
1251 params.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
1252 }
1253 };
1254 for (var _i = 0, _a = Object.entries(querystringParams); _i < _a.length; _i++) {
1255 var _b = _a[_i], key = _b[0], value = _b[1];
1256 _loop_1(key, value);
1257 }
1258 return params.length ? '&' + params.join('&') : '';
1259}
1260/**
1261 * Decodes a querystring (e.g. ?arg=val&arg2=val2) into a params object
1262 * (e.g. {arg: 'val', arg2: 'val2'})
1263 */
1264function querystringDecode(querystring) {
1265 var obj = {};
1266 var tokens = querystring.replace(/^\?/, '').split('&');
1267 tokens.forEach(function (token) {
1268 if (token) {
1269 var _a = token.split('='), key = _a[0], value = _a[1];
1270 obj[decodeURIComponent(key)] = decodeURIComponent(value);
1271 }
1272 });
1273 return obj;
1274}
1275/**
1276 * Extract the query string part of a URL, including the leading question mark (if present).
1277 */
1278function extractQuerystring(url) {
1279 var queryStart = url.indexOf('?');
1280 if (!queryStart) {
1281 return '';
1282 }
1283 var fragmentStart = url.indexOf('#', queryStart);
1284 return url.substring(queryStart, fragmentStart > 0 ? fragmentStart : undefined);
1285}
1286
1287/**
1288 * @license
1289 * Copyright 2017 Google LLC
1290 *
1291 * Licensed under the Apache License, Version 2.0 (the "License");
1292 * you may not use this file except in compliance with the License.
1293 * You may obtain a copy of the License at
1294 *
1295 * http://www.apache.org/licenses/LICENSE-2.0
1296 *
1297 * Unless required by applicable law or agreed to in writing, software
1298 * distributed under the License is distributed on an "AS IS" BASIS,
1299 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1300 * See the License for the specific language governing permissions and
1301 * limitations under the License.
1302 */
1303/**
1304 * @fileoverview SHA-1 cryptographic hash.
1305 * Variable names follow the notation in FIPS PUB 180-3:
1306 * http://csrc.nist.gov/publications/fips/fips180-3/fips180-3_final.pdf.
1307 *
1308 * Usage:
1309 * var sha1 = new sha1();
1310 * sha1.update(bytes);
1311 * var hash = sha1.digest();
1312 *
1313 * Performance:
1314 * Chrome 23: ~400 Mbit/s
1315 * Firefox 16: ~250 Mbit/s
1316 *
1317 */
1318/**
1319 * SHA-1 cryptographic hash constructor.
1320 *
1321 * The properties declared here are discussed in the above algorithm document.
1322 * @constructor
1323 * @final
1324 * @struct
1325 */
1326var Sha1 = /** @class */ (function () {
1327 function Sha1() {
1328 /**
1329 * Holds the previous values of accumulated variables a-e in the compress_
1330 * function.
1331 * @private
1332 */
1333 this.chain_ = [];
1334 /**
1335 * A buffer holding the partially computed hash result.
1336 * @private
1337 */
1338 this.buf_ = [];
1339 /**
1340 * An array of 80 bytes, each a part of the message to be hashed. Referred to
1341 * as the message schedule in the docs.
1342 * @private
1343 */
1344 this.W_ = [];
1345 /**
1346 * Contains data needed to pad messages less than 64 bytes.
1347 * @private
1348 */
1349 this.pad_ = [];
1350 /**
1351 * @private {number}
1352 */
1353 this.inbuf_ = 0;
1354 /**
1355 * @private {number}
1356 */
1357 this.total_ = 0;
1358 this.blockSize = 512 / 8;
1359 this.pad_[0] = 128;
1360 for (var i = 1; i < this.blockSize; ++i) {
1361 this.pad_[i] = 0;
1362 }
1363 this.reset();
1364 }
1365 Sha1.prototype.reset = function () {
1366 this.chain_[0] = 0x67452301;
1367 this.chain_[1] = 0xefcdab89;
1368 this.chain_[2] = 0x98badcfe;
1369 this.chain_[3] = 0x10325476;
1370 this.chain_[4] = 0xc3d2e1f0;
1371 this.inbuf_ = 0;
1372 this.total_ = 0;
1373 };
1374 /**
1375 * Internal compress helper function.
1376 * @param buf Block to compress.
1377 * @param offset Offset of the block in the buffer.
1378 * @private
1379 */
1380 Sha1.prototype.compress_ = function (buf, offset) {
1381 if (!offset) {
1382 offset = 0;
1383 }
1384 var W = this.W_;
1385 // get 16 big endian words
1386 if (typeof buf === 'string') {
1387 for (var i = 0; i < 16; i++) {
1388 // TODO(user): [bug 8140122] Recent versions of Safari for Mac OS and iOS
1389 // have a bug that turns the post-increment ++ operator into pre-increment
1390 // during JIT compilation. We have code that depends heavily on SHA-1 for
1391 // correctness and which is affected by this bug, so I've removed all uses
1392 // of post-increment ++ in which the result value is used. We can revert
1393 // this change once the Safari bug
1394 // (https://bugs.webkit.org/show_bug.cgi?id=109036) has been fixed and
1395 // most clients have been updated.
1396 W[i] =
1397 (buf.charCodeAt(offset) << 24) |
1398 (buf.charCodeAt(offset + 1) << 16) |
1399 (buf.charCodeAt(offset + 2) << 8) |
1400 buf.charCodeAt(offset + 3);
1401 offset += 4;
1402 }
1403 }
1404 else {
1405 for (var i = 0; i < 16; i++) {
1406 W[i] =
1407 (buf[offset] << 24) |
1408 (buf[offset + 1] << 16) |
1409 (buf[offset + 2] << 8) |
1410 buf[offset + 3];
1411 offset += 4;
1412 }
1413 }
1414 // expand to 80 words
1415 for (var i = 16; i < 80; i++) {
1416 var t = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
1417 W[i] = ((t << 1) | (t >>> 31)) & 0xffffffff;
1418 }
1419 var a = this.chain_[0];
1420 var b = this.chain_[1];
1421 var c = this.chain_[2];
1422 var d = this.chain_[3];
1423 var e = this.chain_[4];
1424 var f, k;
1425 // TODO(user): Try to unroll this loop to speed up the computation.
1426 for (var i = 0; i < 80; i++) {
1427 if (i < 40) {
1428 if (i < 20) {
1429 f = d ^ (b & (c ^ d));
1430 k = 0x5a827999;
1431 }
1432 else {
1433 f = b ^ c ^ d;
1434 k = 0x6ed9eba1;
1435 }
1436 }
1437 else {
1438 if (i < 60) {
1439 f = (b & c) | (d & (b | c));
1440 k = 0x8f1bbcdc;
1441 }
1442 else {
1443 f = b ^ c ^ d;
1444 k = 0xca62c1d6;
1445 }
1446 }
1447 var t = (((a << 5) | (a >>> 27)) + f + e + k + W[i]) & 0xffffffff;
1448 e = d;
1449 d = c;
1450 c = ((b << 30) | (b >>> 2)) & 0xffffffff;
1451 b = a;
1452 a = t;
1453 }
1454 this.chain_[0] = (this.chain_[0] + a) & 0xffffffff;
1455 this.chain_[1] = (this.chain_[1] + b) & 0xffffffff;
1456 this.chain_[2] = (this.chain_[2] + c) & 0xffffffff;
1457 this.chain_[3] = (this.chain_[3] + d) & 0xffffffff;
1458 this.chain_[4] = (this.chain_[4] + e) & 0xffffffff;
1459 };
1460 Sha1.prototype.update = function (bytes, length) {
1461 // TODO(johnlenz): tighten the function signature and remove this check
1462 if (bytes == null) {
1463 return;
1464 }
1465 if (length === undefined) {
1466 length = bytes.length;
1467 }
1468 var lengthMinusBlock = length - this.blockSize;
1469 var n = 0;
1470 // Using local instead of member variables gives ~5% speedup on Firefox 16.
1471 var buf = this.buf_;
1472 var inbuf = this.inbuf_;
1473 // The outer while loop should execute at most twice.
1474 while (n < length) {
1475 // When we have no data in the block to top up, we can directly process the
1476 // input buffer (assuming it contains sufficient data). This gives ~25%
1477 // speedup on Chrome 23 and ~15% speedup on Firefox 16, but requires that
1478 // the data is provided in large chunks (or in multiples of 64 bytes).
1479 if (inbuf === 0) {
1480 while (n <= lengthMinusBlock) {
1481 this.compress_(bytes, n);
1482 n += this.blockSize;
1483 }
1484 }
1485 if (typeof bytes === 'string') {
1486 while (n < length) {
1487 buf[inbuf] = bytes.charCodeAt(n);
1488 ++inbuf;
1489 ++n;
1490 if (inbuf === this.blockSize) {
1491 this.compress_(buf);
1492 inbuf = 0;
1493 // Jump to the outer loop so we use the full-block optimization.
1494 break;
1495 }
1496 }
1497 }
1498 else {
1499 while (n < length) {
1500 buf[inbuf] = bytes[n];
1501 ++inbuf;
1502 ++n;
1503 if (inbuf === this.blockSize) {
1504 this.compress_(buf);
1505 inbuf = 0;
1506 // Jump to the outer loop so we use the full-block optimization.
1507 break;
1508 }
1509 }
1510 }
1511 }
1512 this.inbuf_ = inbuf;
1513 this.total_ += length;
1514 };
1515 /** @override */
1516 Sha1.prototype.digest = function () {
1517 var digest = [];
1518 var totalBits = this.total_ * 8;
1519 // Add pad 0x80 0x00*.
1520 if (this.inbuf_ < 56) {
1521 this.update(this.pad_, 56 - this.inbuf_);
1522 }
1523 else {
1524 this.update(this.pad_, this.blockSize - (this.inbuf_ - 56));
1525 }
1526 // Add # bits.
1527 for (var i = this.blockSize - 1; i >= 56; i--) {
1528 this.buf_[i] = totalBits & 255;
1529 totalBits /= 256; // Don't use bit-shifting here!
1530 }
1531 this.compress_(this.buf_);
1532 var n = 0;
1533 for (var i = 0; i < 5; i++) {
1534 for (var j = 24; j >= 0; j -= 8) {
1535 digest[n] = (this.chain_[i] >> j) & 255;
1536 ++n;
1537 }
1538 }
1539 return digest;
1540 };
1541 return Sha1;
1542}());
1543
1544/**
1545 * Helper to make a Subscribe function (just like Promise helps make a
1546 * Thenable).
1547 *
1548 * @param executor Function which can make calls to a single Observer
1549 * as a proxy.
1550 * @param onNoObservers Callback when count of Observers goes to zero.
1551 */
1552function createSubscribe(executor, onNoObservers) {
1553 var proxy = new ObserverProxy(executor, onNoObservers);
1554 return proxy.subscribe.bind(proxy);
1555}
1556/**
1557 * Implement fan-out for any number of Observers attached via a subscribe
1558 * function.
1559 */
1560var ObserverProxy = /** @class */ (function () {
1561 /**
1562 * @param executor Function which can make calls to a single Observer
1563 * as a proxy.
1564 * @param onNoObservers Callback when count of Observers goes to zero.
1565 */
1566 function ObserverProxy(executor, onNoObservers) {
1567 var _this = this;
1568 this.observers = [];
1569 this.unsubscribes = [];
1570 this.observerCount = 0;
1571 // Micro-task scheduling by calling task.then().
1572 this.task = Promise.resolve();
1573 this.finalized = false;
1574 this.onNoObservers = onNoObservers;
1575 // Call the executor asynchronously so subscribers that are called
1576 // synchronously after the creation of the subscribe function
1577 // can still receive the very first value generated in the executor.
1578 this.task
1579 .then(function () {
1580 executor(_this);
1581 })
1582 .catch(function (e) {
1583 _this.error(e);
1584 });
1585 }
1586 ObserverProxy.prototype.next = function (value) {
1587 this.forEachObserver(function (observer) {
1588 observer.next(value);
1589 });
1590 };
1591 ObserverProxy.prototype.error = function (error) {
1592 this.forEachObserver(function (observer) {
1593 observer.error(error);
1594 });
1595 this.close(error);
1596 };
1597 ObserverProxy.prototype.complete = function () {
1598 this.forEachObserver(function (observer) {
1599 observer.complete();
1600 });
1601 this.close();
1602 };
1603 /**
1604 * Subscribe function that can be used to add an Observer to the fan-out list.
1605 *
1606 * - We require that no event is sent to a subscriber sychronously to their
1607 * call to subscribe().
1608 */
1609 ObserverProxy.prototype.subscribe = function (nextOrObserver, error, complete) {
1610 var _this = this;
1611 var observer;
1612 if (nextOrObserver === undefined &&
1613 error === undefined &&
1614 complete === undefined) {
1615 throw new Error('Missing Observer.');
1616 }
1617 // Assemble an Observer object when passed as callback functions.
1618 if (implementsAnyMethods(nextOrObserver, [
1619 'next',
1620 'error',
1621 'complete'
1622 ])) {
1623 observer = nextOrObserver;
1624 }
1625 else {
1626 observer = {
1627 next: nextOrObserver,
1628 error: error,
1629 complete: complete
1630 };
1631 }
1632 if (observer.next === undefined) {
1633 observer.next = noop;
1634 }
1635 if (observer.error === undefined) {
1636 observer.error = noop;
1637 }
1638 if (observer.complete === undefined) {
1639 observer.complete = noop;
1640 }
1641 var unsub = this.unsubscribeOne.bind(this, this.observers.length);
1642 // Attempt to subscribe to a terminated Observable - we
1643 // just respond to the Observer with the final error or complete
1644 // event.
1645 if (this.finalized) {
1646 // eslint-disable-next-line @typescript-eslint/no-floating-promises
1647 this.task.then(function () {
1648 try {
1649 if (_this.finalError) {
1650 observer.error(_this.finalError);
1651 }
1652 else {
1653 observer.complete();
1654 }
1655 }
1656 catch (e) {
1657 // nothing
1658 }
1659 return;
1660 });
1661 }
1662 this.observers.push(observer);
1663 return unsub;
1664 };
1665 // Unsubscribe is synchronous - we guarantee that no events are sent to
1666 // any unsubscribed Observer.
1667 ObserverProxy.prototype.unsubscribeOne = function (i) {
1668 if (this.observers === undefined || this.observers[i] === undefined) {
1669 return;
1670 }
1671 delete this.observers[i];
1672 this.observerCount -= 1;
1673 if (this.observerCount === 0 && this.onNoObservers !== undefined) {
1674 this.onNoObservers(this);
1675 }
1676 };
1677 ObserverProxy.prototype.forEachObserver = function (fn) {
1678 if (this.finalized) {
1679 // Already closed by previous event....just eat the additional values.
1680 return;
1681 }
1682 // Since sendOne calls asynchronously - there is no chance that
1683 // this.observers will become undefined.
1684 for (var i = 0; i < this.observers.length; i++) {
1685 this.sendOne(i, fn);
1686 }
1687 };
1688 // Call the Observer via one of it's callback function. We are careful to
1689 // confirm that the observe has not been unsubscribed since this asynchronous
1690 // function had been queued.
1691 ObserverProxy.prototype.sendOne = function (i, fn) {
1692 var _this = this;
1693 // Execute the callback asynchronously
1694 // eslint-disable-next-line @typescript-eslint/no-floating-promises
1695 this.task.then(function () {
1696 if (_this.observers !== undefined && _this.observers[i] !== undefined) {
1697 try {
1698 fn(_this.observers[i]);
1699 }
1700 catch (e) {
1701 // Ignore exceptions raised in Observers or missing methods of an
1702 // Observer.
1703 // Log error to console. b/31404806
1704 if (typeof console !== 'undefined' && console.error) {
1705 console.error(e);
1706 }
1707 }
1708 }
1709 });
1710 };
1711 ObserverProxy.prototype.close = function (err) {
1712 var _this = this;
1713 if (this.finalized) {
1714 return;
1715 }
1716 this.finalized = true;
1717 if (err !== undefined) {
1718 this.finalError = err;
1719 }
1720 // Proxy is no longer needed - garbage collect references
1721 // eslint-disable-next-line @typescript-eslint/no-floating-promises
1722 this.task.then(function () {
1723 _this.observers = undefined;
1724 _this.onNoObservers = undefined;
1725 });
1726 };
1727 return ObserverProxy;
1728}());
1729/** Turn synchronous function into one called asynchronously. */
1730// eslint-disable-next-line @typescript-eslint/ban-types
1731function async(fn, onError) {
1732 return function () {
1733 var args = [];
1734 for (var _i = 0; _i < arguments.length; _i++) {
1735 args[_i] = arguments[_i];
1736 }
1737 Promise.resolve(true)
1738 .then(function () {
1739 fn.apply(void 0, args);
1740 })
1741 .catch(function (error) {
1742 if (onError) {
1743 onError(error);
1744 }
1745 });
1746 };
1747}
1748/**
1749 * Return true if the object passed in implements any of the named methods.
1750 */
1751function implementsAnyMethods(obj, methods) {
1752 if (typeof obj !== 'object' || obj === null) {
1753 return false;
1754 }
1755 for (var _i = 0, methods_1 = methods; _i < methods_1.length; _i++) {
1756 var method = methods_1[_i];
1757 if (method in obj && typeof obj[method] === 'function') {
1758 return true;
1759 }
1760 }
1761 return false;
1762}
1763function noop() {
1764 // do nothing
1765}
1766
1767/**
1768 * @license
1769 * Copyright 2017 Google LLC
1770 *
1771 * Licensed under the Apache License, Version 2.0 (the "License");
1772 * you may not use this file except in compliance with the License.
1773 * You may obtain a copy of the License at
1774 *
1775 * http://www.apache.org/licenses/LICENSE-2.0
1776 *
1777 * Unless required by applicable law or agreed to in writing, software
1778 * distributed under the License is distributed on an "AS IS" BASIS,
1779 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1780 * See the License for the specific language governing permissions and
1781 * limitations under the License.
1782 */
1783/**
1784 * Check to make sure the appropriate number of arguments are provided for a public function.
1785 * Throws an error if it fails.
1786 *
1787 * @param fnName The function name
1788 * @param minCount The minimum number of arguments to allow for the function call
1789 * @param maxCount The maximum number of argument to allow for the function call
1790 * @param argCount The actual number of arguments provided.
1791 */
1792var validateArgCount = function (fnName, minCount, maxCount, argCount) {
1793 var argError;
1794 if (argCount < minCount) {
1795 argError = 'at least ' + minCount;
1796 }
1797 else if (argCount > maxCount) {
1798 argError = maxCount === 0 ? 'none' : 'no more than ' + maxCount;
1799 }
1800 if (argError) {
1801 var error = fnName +
1802 ' failed: Was called with ' +
1803 argCount +
1804 (argCount === 1 ? ' argument.' : ' arguments.') +
1805 ' Expects ' +
1806 argError +
1807 '.';
1808 throw new Error(error);
1809 }
1810};
1811/**
1812 * Generates a string to prefix an error message about failed argument validation
1813 *
1814 * @param fnName The function name
1815 * @param argName The name of the argument
1816 * @return The prefix to add to the error thrown for validation.
1817 */
1818function errorPrefix(fnName, argName) {
1819 return "".concat(fnName, " failed: ").concat(argName, " argument ");
1820}
1821/**
1822 * @param fnName
1823 * @param argumentNumber
1824 * @param namespace
1825 * @param optional
1826 */
1827function validateNamespace(fnName, namespace, optional) {
1828 if (optional && !namespace) {
1829 return;
1830 }
1831 if (typeof namespace !== 'string') {
1832 //TODO: I should do more validation here. We only allow certain chars in namespaces.
1833 throw new Error(errorPrefix(fnName, 'namespace') + 'must be a valid firebase namespace.');
1834 }
1835}
1836function validateCallback(fnName, argumentName,
1837// eslint-disable-next-line @typescript-eslint/ban-types
1838callback, optional) {
1839 if (optional && !callback) {
1840 return;
1841 }
1842 if (typeof callback !== 'function') {
1843 throw new Error(errorPrefix(fnName, argumentName) + 'must be a valid function.');
1844 }
1845}
1846function validateContextObject(fnName, argumentName, context, optional) {
1847 if (optional && !context) {
1848 return;
1849 }
1850 if (typeof context !== 'object' || context === null) {
1851 throw new Error(errorPrefix(fnName, argumentName) + 'must be a valid context object.');
1852 }
1853}
1854
1855/**
1856 * @license
1857 * Copyright 2017 Google LLC
1858 *
1859 * Licensed under the Apache License, Version 2.0 (the "License");
1860 * you may not use this file except in compliance with the License.
1861 * You may obtain a copy of the License at
1862 *
1863 * http://www.apache.org/licenses/LICENSE-2.0
1864 *
1865 * Unless required by applicable law or agreed to in writing, software
1866 * distributed under the License is distributed on an "AS IS" BASIS,
1867 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1868 * See the License for the specific language governing permissions and
1869 * limitations under the License.
1870 */
1871// Code originally came from goog.crypt.stringToUtf8ByteArray, but for some reason they
1872// automatically replaced '\r\n' with '\n', and they didn't handle surrogate pairs,
1873// so it's been modified.
1874// Note that not all Unicode characters appear as single characters in JavaScript strings.
1875// fromCharCode returns the UTF-16 encoding of a character - so some Unicode characters
1876// use 2 characters in Javascript. All 4-byte UTF-8 characters begin with a first
1877// character in the range 0xD800 - 0xDBFF (the first character of a so-called surrogate
1878// pair).
1879// See http://www.ecma-international.org/ecma-262/5.1/#sec-15.1.3
1880/**
1881 * @param {string} str
1882 * @return {Array}
1883 */
1884var stringToByteArray = function (str) {
1885 var out = [];
1886 var p = 0;
1887 for (var i = 0; i < str.length; i++) {
1888 var c = str.charCodeAt(i);
1889 // Is this the lead surrogate in a surrogate pair?
1890 if (c >= 0xd800 && c <= 0xdbff) {
1891 var high = c - 0xd800; // the high 10 bits.
1892 i++;
1893 assert(i < str.length, 'Surrogate pair missing trail surrogate.');
1894 var low = str.charCodeAt(i) - 0xdc00; // the low 10 bits.
1895 c = 0x10000 + (high << 10) + low;
1896 }
1897 if (c < 128) {
1898 out[p++] = c;
1899 }
1900 else if (c < 2048) {
1901 out[p++] = (c >> 6) | 192;
1902 out[p++] = (c & 63) | 128;
1903 }
1904 else if (c < 65536) {
1905 out[p++] = (c >> 12) | 224;
1906 out[p++] = ((c >> 6) & 63) | 128;
1907 out[p++] = (c & 63) | 128;
1908 }
1909 else {
1910 out[p++] = (c >> 18) | 240;
1911 out[p++] = ((c >> 12) & 63) | 128;
1912 out[p++] = ((c >> 6) & 63) | 128;
1913 out[p++] = (c & 63) | 128;
1914 }
1915 }
1916 return out;
1917};
1918/**
1919 * Calculate length without actually converting; useful for doing cheaper validation.
1920 * @param {string} str
1921 * @return {number}
1922 */
1923var stringLength = function (str) {
1924 var p = 0;
1925 for (var i = 0; i < str.length; i++) {
1926 var c = str.charCodeAt(i);
1927 if (c < 128) {
1928 p++;
1929 }
1930 else if (c < 2048) {
1931 p += 2;
1932 }
1933 else if (c >= 0xd800 && c <= 0xdbff) {
1934 // Lead surrogate of a surrogate pair. The pair together will take 4 bytes to represent.
1935 p += 4;
1936 i++; // skip trail surrogate.
1937 }
1938 else {
1939 p += 3;
1940 }
1941 }
1942 return p;
1943};
1944
1945/**
1946 * @license
1947 * Copyright 2022 Google LLC
1948 *
1949 * Licensed under the Apache License, Version 2.0 (the "License");
1950 * you may not use this file except in compliance with the License.
1951 * You may obtain a copy of the License at
1952 *
1953 * http://www.apache.org/licenses/LICENSE-2.0
1954 *
1955 * Unless required by applicable law or agreed to in writing, software
1956 * distributed under the License is distributed on an "AS IS" BASIS,
1957 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1958 * See the License for the specific language governing permissions and
1959 * limitations under the License.
1960 */
1961/**
1962 * Copied from https://stackoverflow.com/a/2117523
1963 * Generates a new uuid.
1964 * @public
1965 */
1966var uuidv4 = function () {
1967 return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
1968 var r = (Math.random() * 16) | 0, v = c === 'x' ? r : (r & 0x3) | 0x8;
1969 return v.toString(16);
1970 });
1971};
1972
1973/**
1974 * @license
1975 * Copyright 2019 Google LLC
1976 *
1977 * Licensed under the Apache License, Version 2.0 (the "License");
1978 * you may not use this file except in compliance with the License.
1979 * You may obtain a copy of the License at
1980 *
1981 * http://www.apache.org/licenses/LICENSE-2.0
1982 *
1983 * Unless required by applicable law or agreed to in writing, software
1984 * distributed under the License is distributed on an "AS IS" BASIS,
1985 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1986 * See the License for the specific language governing permissions and
1987 * limitations under the License.
1988 */
1989/**
1990 * The amount of milliseconds to exponentially increase.
1991 */
1992var DEFAULT_INTERVAL_MILLIS = 1000;
1993/**
1994 * The factor to backoff by.
1995 * Should be a number greater than 1.
1996 */
1997var DEFAULT_BACKOFF_FACTOR = 2;
1998/**
1999 * The maximum milliseconds to increase to.
2000 *
2001 * <p>Visible for testing
2002 */
2003var MAX_VALUE_MILLIS = 4 * 60 * 60 * 1000; // Four hours, like iOS and Android.
2004/**
2005 * The percentage of backoff time to randomize by.
2006 * See
2007 * http://go/safe-client-behavior#step-1-determine-the-appropriate-retry-interval-to-handle-spike-traffic
2008 * for context.
2009 *
2010 * <p>Visible for testing
2011 */
2012var RANDOM_FACTOR = 0.5;
2013/**
2014 * Based on the backoff method from
2015 * https://github.com/google/closure-library/blob/master/closure/goog/math/exponentialbackoff.js.
2016 * Extracted here so we don't need to pass metadata and a stateful ExponentialBackoff object around.
2017 */
2018function calculateBackoffMillis(backoffCount, intervalMillis, backoffFactor) {
2019 if (intervalMillis === void 0) { intervalMillis = DEFAULT_INTERVAL_MILLIS; }
2020 if (backoffFactor === void 0) { backoffFactor = DEFAULT_BACKOFF_FACTOR; }
2021 // Calculates an exponentially increasing value.
2022 // Deviation: calculates value from count and a constant interval, so we only need to save value
2023 // and count to restore state.
2024 var currBaseValue = intervalMillis * Math.pow(backoffFactor, backoffCount);
2025 // A random "fuzz" to avoid waves of retries.
2026 // Deviation: randomFactor is required.
2027 var randomWait = Math.round(
2028 // A fraction of the backoff value to add/subtract.
2029 // Deviation: changes multiplication order to improve readability.
2030 RANDOM_FACTOR *
2031 currBaseValue *
2032 // A random float (rounded to int by Math.round above) in the range [-1, 1]. Determines
2033 // if we add or subtract.
2034 (Math.random() - 0.5) *
2035 2);
2036 // Limits backoff to max to avoid effectively permanent backoff.
2037 return Math.min(MAX_VALUE_MILLIS, currBaseValue + randomWait);
2038}
2039
2040/**
2041 * @license
2042 * Copyright 2020 Google LLC
2043 *
2044 * Licensed under the Apache License, Version 2.0 (the "License");
2045 * you may not use this file except in compliance with the License.
2046 * You may obtain a copy of the License at
2047 *
2048 * http://www.apache.org/licenses/LICENSE-2.0
2049 *
2050 * Unless required by applicable law or agreed to in writing, software
2051 * distributed under the License is distributed on an "AS IS" BASIS,
2052 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2053 * See the License for the specific language governing permissions and
2054 * limitations under the License.
2055 */
2056/**
2057 * Provide English ordinal letters after a number
2058 */
2059function ordinal(i) {
2060 if (!Number.isFinite(i)) {
2061 return "".concat(i);
2062 }
2063 return i + indicator(i);
2064}
2065function indicator(i) {
2066 i = Math.abs(i);
2067 var cent = i % 100;
2068 if (cent >= 10 && cent <= 20) {
2069 return 'th';
2070 }
2071 var dec = i % 10;
2072 if (dec === 1) {
2073 return 'st';
2074 }
2075 if (dec === 2) {
2076 return 'nd';
2077 }
2078 if (dec === 3) {
2079 return 'rd';
2080 }
2081 return 'th';
2082}
2083
2084/**
2085 * @license
2086 * Copyright 2021 Google LLC
2087 *
2088 * Licensed under the Apache License, Version 2.0 (the "License");
2089 * you may not use this file except in compliance with the License.
2090 * You may obtain a copy of the License at
2091 *
2092 * http://www.apache.org/licenses/LICENSE-2.0
2093 *
2094 * Unless required by applicable law or agreed to in writing, software
2095 * distributed under the License is distributed on an "AS IS" BASIS,
2096 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2097 * See the License for the specific language governing permissions and
2098 * limitations under the License.
2099 */
2100function getModularInstance(service) {
2101 if (service && service._delegate) {
2102 return service._delegate;
2103 }
2104 else {
2105 return service;
2106 }
2107}
2108
2109export { CONSTANTS, DecodeBase64StringError, Deferred, ErrorFactory, FirebaseError, MAX_VALUE_MILLIS, RANDOM_FACTOR, Sha1, areCookiesEnabled, assert, assertionError, async, base64, base64Decode, base64Encode, base64urlEncodeWithoutPadding, calculateBackoffMillis, contains, createMockUserToken, createSubscribe, decode, deepCopy, deepEqual, deepExtend, errorPrefix, extractQuerystring, getDefaultAppConfig, getDefaultEmulatorHost, getDefaultEmulatorHostnameAndPort, getDefaults, getExperimentalSetting, getGlobal, getModularInstance, getUA, isAdmin, isBrowser, isBrowserExtension, isElectron, isEmpty, isIE, isIndexedDBAvailable, isMobileCordova, isNode, isNodeSdk, isReactNative, isSafari, isUWP, isValidFormat, isValidTimestamp, issuedAtTime, jsonEval, map, ordinal, promiseWithTimeout, querystring, querystringDecode, safeGet, stringLength, stringToByteArray, stringify, uuidv4, validateArgCount, validateCallback, validateContextObject, validateIndexedDBOpenable, validateNamespace };
2110//# sourceMappingURL=index.esm5.js.map