UNPKG

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