@firebase/util 1.10.0 → 1.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2129 +0,0 @@
1
- import { __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
- */
22
- var 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
- */
56
- var assert = function (assertion, message) {
57
- if (!assertion) {
58
- throw assertionError(message);
59
- }
60
- };
61
- /**
62
- * Returns an Error object suitable for throwing.
63
- */
64
- var 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
- */
87
- var 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
- */
124
- var 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_()
158
- var 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
- */
349
- var 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
- */
361
- var 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
- */
369
- var 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
- */
382
- var 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
- */
411
- function 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
- */
428
- function 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
- }
460
- function 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
- */
485
- function 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
- */
514
- var 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
- */
525
- var 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
- };
534
- var 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
- */
557
- var 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
- */
580
- var 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
- */
587
- var 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
- */
610
- var 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
- */
616
- var 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
- */
634
- var 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 promisified 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
- */
692
- function 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
- */
742
- function 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
- */
758
- function 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/
771
- function 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
- * Note: This will return true for certain test frameworks that are incompletely
790
- * mimicking a browser, and should not lead to assuming all browser APIs are
791
- * available.
792
- */
793
- function isBrowser() {
794
- return typeof window !== 'undefined' || isWebWorker();
795
- }
796
- /**
797
- * Detect Web Worker context.
798
- */
799
- function isWebWorker() {
800
- return (typeof WorkerGlobalScope !== 'undefined' &&
801
- typeof self !== 'undefined' &&
802
- self instanceof WorkerGlobalScope);
803
- }
804
- /**
805
- * Detect Cloudflare Worker context.
806
- */
807
- function isCloudflareWorker() {
808
- return (typeof navigator !== 'undefined' &&
809
- navigator.userAgent === 'Cloudflare-Workers');
810
- }
811
- function isBrowserExtension() {
812
- var runtime = typeof chrome === 'object'
813
- ? chrome.runtime
814
- : typeof browser === 'object'
815
- ? browser.runtime
816
- : undefined;
817
- return typeof runtime === 'object' && runtime.id !== undefined;
818
- }
819
- /**
820
- * Detect React Native.
821
- *
822
- * @return true if ReactNative environment is detected.
823
- */
824
- function isReactNative() {
825
- return (typeof navigator === 'object' && navigator['product'] === 'ReactNative');
826
- }
827
- /** Detects Electron apps. */
828
- function isElectron() {
829
- return getUA().indexOf('Electron/') >= 0;
830
- }
831
- /** Detects Internet Explorer. */
832
- function isIE() {
833
- var ua = getUA();
834
- return ua.indexOf('MSIE ') >= 0 || ua.indexOf('Trident/') >= 0;
835
- }
836
- /** Detects Universal Windows Platform apps. */
837
- function isUWP() {
838
- return getUA().indexOf('MSAppHost/') >= 0;
839
- }
840
- /**
841
- * Detect whether the current SDK build is the Node version.
842
- *
843
- * @return true if it's the Node SDK build.
844
- */
845
- function isNodeSdk() {
846
- return CONSTANTS.NODE_CLIENT === true || CONSTANTS.NODE_ADMIN === true;
847
- }
848
- /** Returns true if we are running in Safari. */
849
- function isSafari() {
850
- return (!isNode() &&
851
- !!navigator.userAgent &&
852
- navigator.userAgent.includes('Safari') &&
853
- !navigator.userAgent.includes('Chrome'));
854
- }
855
- /**
856
- * This method checks if indexedDB is supported by current browser/service worker context
857
- * @return true if indexedDB is supported by current browser/service worker context
858
- */
859
- function isIndexedDBAvailable() {
860
- try {
861
- return typeof indexedDB === 'object';
862
- }
863
- catch (e) {
864
- return false;
865
- }
866
- }
867
- /**
868
- * This method validates browser/sw context for indexedDB by opening a dummy indexedDB database and reject
869
- * if errors occur during the database open operation.
870
- *
871
- * @throws exception if current browser/sw context can't run idb.open (ex: Safari iframe, Firefox
872
- * private browsing)
873
- */
874
- function validateIndexedDBOpenable() {
875
- return new Promise(function (resolve, reject) {
876
- try {
877
- var preExist_1 = true;
878
- var DB_CHECK_NAME_1 = 'validate-browser-context-for-indexeddb-analytics-module';
879
- var request_1 = self.indexedDB.open(DB_CHECK_NAME_1);
880
- request_1.onsuccess = function () {
881
- request_1.result.close();
882
- // delete database only when it doesn't pre-exist
883
- if (!preExist_1) {
884
- self.indexedDB.deleteDatabase(DB_CHECK_NAME_1);
885
- }
886
- resolve(true);
887
- };
888
- request_1.onupgradeneeded = function () {
889
- preExist_1 = false;
890
- };
891
- request_1.onerror = function () {
892
- var _a;
893
- reject(((_a = request_1.error) === null || _a === void 0 ? void 0 : _a.message) || '');
894
- };
895
- }
896
- catch (error) {
897
- reject(error);
898
- }
899
- });
900
- }
901
- /**
902
- *
903
- * This method checks whether cookie is enabled within current browser
904
- * @return true if cookie is enabled within current browser
905
- */
906
- function areCookiesEnabled() {
907
- if (typeof navigator === 'undefined' || !navigator.cookieEnabled) {
908
- return false;
909
- }
910
- return true;
911
- }
912
-
913
- /**
914
- * @license
915
- * Copyright 2017 Google LLC
916
- *
917
- * Licensed under the Apache License, Version 2.0 (the "License");
918
- * you may not use this file except in compliance with the License.
919
- * You may obtain a copy of the License at
920
- *
921
- * http://www.apache.org/licenses/LICENSE-2.0
922
- *
923
- * Unless required by applicable law or agreed to in writing, software
924
- * distributed under the License is distributed on an "AS IS" BASIS,
925
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
926
- * See the License for the specific language governing permissions and
927
- * limitations under the License.
928
- */
929
- var ERROR_NAME = 'FirebaseError';
930
- // Based on code from:
931
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Custom_Error_Types
932
- var FirebaseError = /** @class */ (function (_super) {
933
- __extends(FirebaseError, _super);
934
- function FirebaseError(
935
- /** The error code for this error. */
936
- code, message,
937
- /** Custom data for this error. */
938
- customData) {
939
- var _this = _super.call(this, message) || this;
940
- _this.code = code;
941
- _this.customData = customData;
942
- /** The custom name for all FirebaseErrors. */
943
- _this.name = ERROR_NAME;
944
- // Fix For ES5
945
- // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
946
- Object.setPrototypeOf(_this, FirebaseError.prototype);
947
- // Maintains proper stack trace for where our error was thrown.
948
- // Only available on V8.
949
- if (Error.captureStackTrace) {
950
- Error.captureStackTrace(_this, ErrorFactory.prototype.create);
951
- }
952
- return _this;
953
- }
954
- return FirebaseError;
955
- }(Error));
956
- var ErrorFactory = /** @class */ (function () {
957
- function ErrorFactory(service, serviceName, errors) {
958
- this.service = service;
959
- this.serviceName = serviceName;
960
- this.errors = errors;
961
- }
962
- ErrorFactory.prototype.create = function (code) {
963
- var data = [];
964
- for (var _i = 1; _i < arguments.length; _i++) {
965
- data[_i - 1] = arguments[_i];
966
- }
967
- var customData = data[0] || {};
968
- var fullCode = "".concat(this.service, "/").concat(code);
969
- var template = this.errors[code];
970
- var message = template ? replaceTemplate(template, customData) : 'Error';
971
- // Service Name: Error message (service/code).
972
- var fullMessage = "".concat(this.serviceName, ": ").concat(message, " (").concat(fullCode, ").");
973
- var error = new FirebaseError(fullCode, fullMessage, customData);
974
- return error;
975
- };
976
- return ErrorFactory;
977
- }());
978
- function replaceTemplate(template, data) {
979
- return template.replace(PATTERN, function (_, key) {
980
- var value = data[key];
981
- return value != null ? String(value) : "<".concat(key, "?>");
982
- });
983
- }
984
- var PATTERN = /\{\$([^}]+)}/g;
985
-
986
- /**
987
- * @license
988
- * Copyright 2017 Google LLC
989
- *
990
- * Licensed under the Apache License, Version 2.0 (the "License");
991
- * you may not use this file except in compliance with the License.
992
- * You may obtain a copy of the License at
993
- *
994
- * http://www.apache.org/licenses/LICENSE-2.0
995
- *
996
- * Unless required by applicable law or agreed to in writing, software
997
- * distributed under the License is distributed on an "AS IS" BASIS,
998
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
999
- * See the License for the specific language governing permissions and
1000
- * limitations under the License.
1001
- */
1002
- /**
1003
- * Evaluates a JSON string into a javascript object.
1004
- *
1005
- * @param {string} str A string containing JSON.
1006
- * @return {*} The javascript object representing the specified JSON.
1007
- */
1008
- function jsonEval(str) {
1009
- return JSON.parse(str);
1010
- }
1011
- /**
1012
- * Returns JSON representing a javascript object.
1013
- * @param {*} data JavaScript object to be stringified.
1014
- * @return {string} The JSON contents of the object.
1015
- */
1016
- function stringify(data) {
1017
- return JSON.stringify(data);
1018
- }
1019
-
1020
- /**
1021
- * @license
1022
- * Copyright 2017 Google LLC
1023
- *
1024
- * Licensed under the Apache License, Version 2.0 (the "License");
1025
- * you may not use this file except in compliance with the License.
1026
- * You may obtain a copy of the License at
1027
- *
1028
- * http://www.apache.org/licenses/LICENSE-2.0
1029
- *
1030
- * Unless required by applicable law or agreed to in writing, software
1031
- * distributed under the License is distributed on an "AS IS" BASIS,
1032
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1033
- * See the License for the specific language governing permissions and
1034
- * limitations under the License.
1035
- */
1036
- /**
1037
- * Decodes a Firebase auth. token into constituent parts.
1038
- *
1039
- * Notes:
1040
- * - May return with invalid / incomplete claims if there's no native base64 decoding support.
1041
- * - Doesn't check if the token is actually valid.
1042
- */
1043
- var decode = function (token) {
1044
- var header = {}, claims = {}, data = {}, signature = '';
1045
- try {
1046
- var parts = token.split('.');
1047
- header = jsonEval(base64Decode(parts[0]) || '');
1048
- claims = jsonEval(base64Decode(parts[1]) || '');
1049
- signature = parts[2];
1050
- data = claims['d'] || {};
1051
- delete claims['d'];
1052
- }
1053
- catch (e) { }
1054
- return {
1055
- header: header,
1056
- claims: claims,
1057
- data: data,
1058
- signature: signature
1059
- };
1060
- };
1061
- /**
1062
- * Decodes a Firebase auth. token and checks the validity of its time-based claims. Will return true if the
1063
- * token is within the time window authorized by the 'nbf' (not-before) and 'iat' (issued-at) claims.
1064
- *
1065
- * Notes:
1066
- * - May return a false negative if there's no native base64 decoding support.
1067
- * - Doesn't check if the token is actually valid.
1068
- */
1069
- var isValidTimestamp = function (token) {
1070
- var claims = decode(token).claims;
1071
- var now = Math.floor(new Date().getTime() / 1000);
1072
- var validSince = 0, validUntil = 0;
1073
- if (typeof claims === 'object') {
1074
- if (claims.hasOwnProperty('nbf')) {
1075
- validSince = claims['nbf'];
1076
- }
1077
- else if (claims.hasOwnProperty('iat')) {
1078
- validSince = claims['iat'];
1079
- }
1080
- if (claims.hasOwnProperty('exp')) {
1081
- validUntil = claims['exp'];
1082
- }
1083
- else {
1084
- // token will expire after 24h by default
1085
- validUntil = validSince + 86400;
1086
- }
1087
- }
1088
- return (!!now &&
1089
- !!validSince &&
1090
- !!validUntil &&
1091
- now >= validSince &&
1092
- now <= validUntil);
1093
- };
1094
- /**
1095
- * Decodes a Firebase auth. token and returns its issued at time if valid, null otherwise.
1096
- *
1097
- * Notes:
1098
- * - May return null if there's no native base64 decoding support.
1099
- * - Doesn't check if the token is actually valid.
1100
- */
1101
- var issuedAtTime = function (token) {
1102
- var claims = decode(token).claims;
1103
- if (typeof claims === 'object' && claims.hasOwnProperty('iat')) {
1104
- return claims['iat'];
1105
- }
1106
- return null;
1107
- };
1108
- /**
1109
- * Decodes a Firebase auth. token and checks the validity of its format. Expects a valid issued-at time.
1110
- *
1111
- * Notes:
1112
- * - May return a false negative if there's no native base64 decoding support.
1113
- * - Doesn't check if the token is actually valid.
1114
- */
1115
- var isValidFormat = function (token) {
1116
- var decoded = decode(token), claims = decoded.claims;
1117
- return !!claims && typeof claims === 'object' && claims.hasOwnProperty('iat');
1118
- };
1119
- /**
1120
- * Attempts to peer into an auth token and determine if it's an admin auth token by looking at the claims portion.
1121
- *
1122
- * Notes:
1123
- * - May return a false negative if there's no native base64 decoding support.
1124
- * - Doesn't check if the token is actually valid.
1125
- */
1126
- var isAdmin = function (token) {
1127
- var claims = decode(token).claims;
1128
- return typeof claims === 'object' && claims['admin'] === true;
1129
- };
1130
-
1131
- /**
1132
- * @license
1133
- * Copyright 2017 Google LLC
1134
- *
1135
- * Licensed under the Apache License, Version 2.0 (the "License");
1136
- * you may not use this file except in compliance with the License.
1137
- * You may obtain a copy of the License at
1138
- *
1139
- * http://www.apache.org/licenses/LICENSE-2.0
1140
- *
1141
- * Unless required by applicable law or agreed to in writing, software
1142
- * distributed under the License is distributed on an "AS IS" BASIS,
1143
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1144
- * See the License for the specific language governing permissions and
1145
- * limitations under the License.
1146
- */
1147
- function contains(obj, key) {
1148
- return Object.prototype.hasOwnProperty.call(obj, key);
1149
- }
1150
- function safeGet(obj, key) {
1151
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
1152
- return obj[key];
1153
- }
1154
- else {
1155
- return undefined;
1156
- }
1157
- }
1158
- function isEmpty(obj) {
1159
- for (var key in obj) {
1160
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
1161
- return false;
1162
- }
1163
- }
1164
- return true;
1165
- }
1166
- function map(obj, fn, contextObj) {
1167
- var res = {};
1168
- for (var key in obj) {
1169
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
1170
- res[key] = fn.call(contextObj, obj[key], key, obj);
1171
- }
1172
- }
1173
- return res;
1174
- }
1175
- /**
1176
- * Deep equal two objects. Support Arrays and Objects.
1177
- */
1178
- function deepEqual(a, b) {
1179
- if (a === b) {
1180
- return true;
1181
- }
1182
- var aKeys = Object.keys(a);
1183
- var bKeys = Object.keys(b);
1184
- for (var _i = 0, aKeys_1 = aKeys; _i < aKeys_1.length; _i++) {
1185
- var k = aKeys_1[_i];
1186
- if (!bKeys.includes(k)) {
1187
- return false;
1188
- }
1189
- var aProp = a[k];
1190
- var bProp = b[k];
1191
- if (isObject(aProp) && isObject(bProp)) {
1192
- if (!deepEqual(aProp, bProp)) {
1193
- return false;
1194
- }
1195
- }
1196
- else if (aProp !== bProp) {
1197
- return false;
1198
- }
1199
- }
1200
- for (var _a = 0, bKeys_1 = bKeys; _a < bKeys_1.length; _a++) {
1201
- var k = bKeys_1[_a];
1202
- if (!aKeys.includes(k)) {
1203
- return false;
1204
- }
1205
- }
1206
- return true;
1207
- }
1208
- function isObject(thing) {
1209
- return thing !== null && typeof thing === 'object';
1210
- }
1211
-
1212
- /**
1213
- * @license
1214
- * Copyright 2022 Google LLC
1215
- *
1216
- * Licensed under the Apache License, Version 2.0 (the "License");
1217
- * you may not use this file except in compliance with the License.
1218
- * You may obtain a copy of the License at
1219
- *
1220
- * http://www.apache.org/licenses/LICENSE-2.0
1221
- *
1222
- * Unless required by applicable law or agreed to in writing, software
1223
- * distributed under the License is distributed on an "AS IS" BASIS,
1224
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1225
- * See the License for the specific language governing permissions and
1226
- * limitations under the License.
1227
- */
1228
- /**
1229
- * Rejects if the given promise doesn't resolve in timeInMS milliseconds.
1230
- * @internal
1231
- */
1232
- function promiseWithTimeout(promise, timeInMS) {
1233
- if (timeInMS === void 0) { timeInMS = 2000; }
1234
- var deferredPromise = new Deferred();
1235
- setTimeout(function () { return deferredPromise.reject('timeout!'); }, timeInMS);
1236
- promise.then(deferredPromise.resolve, deferredPromise.reject);
1237
- return deferredPromise.promise;
1238
- }
1239
-
1240
- /**
1241
- * @license
1242
- * Copyright 2017 Google LLC
1243
- *
1244
- * Licensed under the Apache License, Version 2.0 (the "License");
1245
- * you may not use this file except in compliance with the License.
1246
- * You may obtain a copy of the License at
1247
- *
1248
- * http://www.apache.org/licenses/LICENSE-2.0
1249
- *
1250
- * Unless required by applicable law or agreed to in writing, software
1251
- * distributed under the License is distributed on an "AS IS" BASIS,
1252
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1253
- * See the License for the specific language governing permissions and
1254
- * limitations under the License.
1255
- */
1256
- /**
1257
- * Returns a querystring-formatted string (e.g. &arg=val&arg2=val2) from a
1258
- * params object (e.g. {arg: 'val', arg2: 'val2'})
1259
- * Note: You must prepend it with ? when adding it to a URL.
1260
- */
1261
- function querystring(querystringParams) {
1262
- var params = [];
1263
- var _loop_1 = function (key, value) {
1264
- if (Array.isArray(value)) {
1265
- value.forEach(function (arrayVal) {
1266
- params.push(encodeURIComponent(key) + '=' + encodeURIComponent(arrayVal));
1267
- });
1268
- }
1269
- else {
1270
- params.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
1271
- }
1272
- };
1273
- for (var _i = 0, _a = Object.entries(querystringParams); _i < _a.length; _i++) {
1274
- var _b = _a[_i], key = _b[0], value = _b[1];
1275
- _loop_1(key, value);
1276
- }
1277
- return params.length ? '&' + params.join('&') : '';
1278
- }
1279
- /**
1280
- * Decodes a querystring (e.g. ?arg=val&arg2=val2) into a params object
1281
- * (e.g. {arg: 'val', arg2: 'val2'})
1282
- */
1283
- function querystringDecode(querystring) {
1284
- var obj = {};
1285
- var tokens = querystring.replace(/^\?/, '').split('&');
1286
- tokens.forEach(function (token) {
1287
- if (token) {
1288
- var _a = token.split('='), key = _a[0], value = _a[1];
1289
- obj[decodeURIComponent(key)] = decodeURIComponent(value);
1290
- }
1291
- });
1292
- return obj;
1293
- }
1294
- /**
1295
- * Extract the query string part of a URL, including the leading question mark (if present).
1296
- */
1297
- function extractQuerystring(url) {
1298
- var queryStart = url.indexOf('?');
1299
- if (!queryStart) {
1300
- return '';
1301
- }
1302
- var fragmentStart = url.indexOf('#', queryStart);
1303
- return url.substring(queryStart, fragmentStart > 0 ? fragmentStart : undefined);
1304
- }
1305
-
1306
- /**
1307
- * @license
1308
- * Copyright 2017 Google LLC
1309
- *
1310
- * Licensed under the Apache License, Version 2.0 (the "License");
1311
- * you may not use this file except in compliance with the License.
1312
- * You may obtain a copy of the License at
1313
- *
1314
- * http://www.apache.org/licenses/LICENSE-2.0
1315
- *
1316
- * Unless required by applicable law or agreed to in writing, software
1317
- * distributed under the License is distributed on an "AS IS" BASIS,
1318
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1319
- * See the License for the specific language governing permissions and
1320
- * limitations under the License.
1321
- */
1322
- /**
1323
- * @fileoverview SHA-1 cryptographic hash.
1324
- * Variable names follow the notation in FIPS PUB 180-3:
1325
- * http://csrc.nist.gov/publications/fips/fips180-3/fips180-3_final.pdf.
1326
- *
1327
- * Usage:
1328
- * var sha1 = new sha1();
1329
- * sha1.update(bytes);
1330
- * var hash = sha1.digest();
1331
- *
1332
- * Performance:
1333
- * Chrome 23: ~400 Mbit/s
1334
- * Firefox 16: ~250 Mbit/s
1335
- *
1336
- */
1337
- /**
1338
- * SHA-1 cryptographic hash constructor.
1339
- *
1340
- * The properties declared here are discussed in the above algorithm document.
1341
- * @constructor
1342
- * @final
1343
- * @struct
1344
- */
1345
- var Sha1 = /** @class */ (function () {
1346
- function Sha1() {
1347
- /**
1348
- * Holds the previous values of accumulated variables a-e in the compress_
1349
- * function.
1350
- * @private
1351
- */
1352
- this.chain_ = [];
1353
- /**
1354
- * A buffer holding the partially computed hash result.
1355
- * @private
1356
- */
1357
- this.buf_ = [];
1358
- /**
1359
- * An array of 80 bytes, each a part of the message to be hashed. Referred to
1360
- * as the message schedule in the docs.
1361
- * @private
1362
- */
1363
- this.W_ = [];
1364
- /**
1365
- * Contains data needed to pad messages less than 64 bytes.
1366
- * @private
1367
- */
1368
- this.pad_ = [];
1369
- /**
1370
- * @private {number}
1371
- */
1372
- this.inbuf_ = 0;
1373
- /**
1374
- * @private {number}
1375
- */
1376
- this.total_ = 0;
1377
- this.blockSize = 512 / 8;
1378
- this.pad_[0] = 128;
1379
- for (var i = 1; i < this.blockSize; ++i) {
1380
- this.pad_[i] = 0;
1381
- }
1382
- this.reset();
1383
- }
1384
- Sha1.prototype.reset = function () {
1385
- this.chain_[0] = 0x67452301;
1386
- this.chain_[1] = 0xefcdab89;
1387
- this.chain_[2] = 0x98badcfe;
1388
- this.chain_[3] = 0x10325476;
1389
- this.chain_[4] = 0xc3d2e1f0;
1390
- this.inbuf_ = 0;
1391
- this.total_ = 0;
1392
- };
1393
- /**
1394
- * Internal compress helper function.
1395
- * @param buf Block to compress.
1396
- * @param offset Offset of the block in the buffer.
1397
- * @private
1398
- */
1399
- Sha1.prototype.compress_ = function (buf, offset) {
1400
- if (!offset) {
1401
- offset = 0;
1402
- }
1403
- var W = this.W_;
1404
- // get 16 big endian words
1405
- if (typeof buf === 'string') {
1406
- for (var i = 0; i < 16; i++) {
1407
- // TODO(user): [bug 8140122] Recent versions of Safari for Mac OS and iOS
1408
- // have a bug that turns the post-increment ++ operator into pre-increment
1409
- // during JIT compilation. We have code that depends heavily on SHA-1 for
1410
- // correctness and which is affected by this bug, so I've removed all uses
1411
- // of post-increment ++ in which the result value is used. We can revert
1412
- // this change once the Safari bug
1413
- // (https://bugs.webkit.org/show_bug.cgi?id=109036) has been fixed and
1414
- // most clients have been updated.
1415
- W[i] =
1416
- (buf.charCodeAt(offset) << 24) |
1417
- (buf.charCodeAt(offset + 1) << 16) |
1418
- (buf.charCodeAt(offset + 2) << 8) |
1419
- buf.charCodeAt(offset + 3);
1420
- offset += 4;
1421
- }
1422
- }
1423
- else {
1424
- for (var i = 0; i < 16; i++) {
1425
- W[i] =
1426
- (buf[offset] << 24) |
1427
- (buf[offset + 1] << 16) |
1428
- (buf[offset + 2] << 8) |
1429
- buf[offset + 3];
1430
- offset += 4;
1431
- }
1432
- }
1433
- // expand to 80 words
1434
- for (var i = 16; i < 80; i++) {
1435
- var t = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
1436
- W[i] = ((t << 1) | (t >>> 31)) & 0xffffffff;
1437
- }
1438
- var a = this.chain_[0];
1439
- var b = this.chain_[1];
1440
- var c = this.chain_[2];
1441
- var d = this.chain_[3];
1442
- var e = this.chain_[4];
1443
- var f, k;
1444
- // TODO(user): Try to unroll this loop to speed up the computation.
1445
- for (var i = 0; i < 80; i++) {
1446
- if (i < 40) {
1447
- if (i < 20) {
1448
- f = d ^ (b & (c ^ d));
1449
- k = 0x5a827999;
1450
- }
1451
- else {
1452
- f = b ^ c ^ d;
1453
- k = 0x6ed9eba1;
1454
- }
1455
- }
1456
- else {
1457
- if (i < 60) {
1458
- f = (b & c) | (d & (b | c));
1459
- k = 0x8f1bbcdc;
1460
- }
1461
- else {
1462
- f = b ^ c ^ d;
1463
- k = 0xca62c1d6;
1464
- }
1465
- }
1466
- var t = (((a << 5) | (a >>> 27)) + f + e + k + W[i]) & 0xffffffff;
1467
- e = d;
1468
- d = c;
1469
- c = ((b << 30) | (b >>> 2)) & 0xffffffff;
1470
- b = a;
1471
- a = t;
1472
- }
1473
- this.chain_[0] = (this.chain_[0] + a) & 0xffffffff;
1474
- this.chain_[1] = (this.chain_[1] + b) & 0xffffffff;
1475
- this.chain_[2] = (this.chain_[2] + c) & 0xffffffff;
1476
- this.chain_[3] = (this.chain_[3] + d) & 0xffffffff;
1477
- this.chain_[4] = (this.chain_[4] + e) & 0xffffffff;
1478
- };
1479
- Sha1.prototype.update = function (bytes, length) {
1480
- // TODO(johnlenz): tighten the function signature and remove this check
1481
- if (bytes == null) {
1482
- return;
1483
- }
1484
- if (length === undefined) {
1485
- length = bytes.length;
1486
- }
1487
- var lengthMinusBlock = length - this.blockSize;
1488
- var n = 0;
1489
- // Using local instead of member variables gives ~5% speedup on Firefox 16.
1490
- var buf = this.buf_;
1491
- var inbuf = this.inbuf_;
1492
- // The outer while loop should execute at most twice.
1493
- while (n < length) {
1494
- // When we have no data in the block to top up, we can directly process the
1495
- // input buffer (assuming it contains sufficient data). This gives ~25%
1496
- // speedup on Chrome 23 and ~15% speedup on Firefox 16, but requires that
1497
- // the data is provided in large chunks (or in multiples of 64 bytes).
1498
- if (inbuf === 0) {
1499
- while (n <= lengthMinusBlock) {
1500
- this.compress_(bytes, n);
1501
- n += this.blockSize;
1502
- }
1503
- }
1504
- if (typeof bytes === 'string') {
1505
- while (n < length) {
1506
- buf[inbuf] = bytes.charCodeAt(n);
1507
- ++inbuf;
1508
- ++n;
1509
- if (inbuf === this.blockSize) {
1510
- this.compress_(buf);
1511
- inbuf = 0;
1512
- // Jump to the outer loop so we use the full-block optimization.
1513
- break;
1514
- }
1515
- }
1516
- }
1517
- else {
1518
- while (n < length) {
1519
- buf[inbuf] = bytes[n];
1520
- ++inbuf;
1521
- ++n;
1522
- if (inbuf === this.blockSize) {
1523
- this.compress_(buf);
1524
- inbuf = 0;
1525
- // Jump to the outer loop so we use the full-block optimization.
1526
- break;
1527
- }
1528
- }
1529
- }
1530
- }
1531
- this.inbuf_ = inbuf;
1532
- this.total_ += length;
1533
- };
1534
- /** @override */
1535
- Sha1.prototype.digest = function () {
1536
- var digest = [];
1537
- var totalBits = this.total_ * 8;
1538
- // Add pad 0x80 0x00*.
1539
- if (this.inbuf_ < 56) {
1540
- this.update(this.pad_, 56 - this.inbuf_);
1541
- }
1542
- else {
1543
- this.update(this.pad_, this.blockSize - (this.inbuf_ - 56));
1544
- }
1545
- // Add # bits.
1546
- for (var i = this.blockSize - 1; i >= 56; i--) {
1547
- this.buf_[i] = totalBits & 255;
1548
- totalBits /= 256; // Don't use bit-shifting here!
1549
- }
1550
- this.compress_(this.buf_);
1551
- var n = 0;
1552
- for (var i = 0; i < 5; i++) {
1553
- for (var j = 24; j >= 0; j -= 8) {
1554
- digest[n] = (this.chain_[i] >> j) & 255;
1555
- ++n;
1556
- }
1557
- }
1558
- return digest;
1559
- };
1560
- return Sha1;
1561
- }());
1562
-
1563
- /**
1564
- * Helper to make a Subscribe function (just like Promise helps make a
1565
- * Thenable).
1566
- *
1567
- * @param executor Function which can make calls to a single Observer
1568
- * as a proxy.
1569
- * @param onNoObservers Callback when count of Observers goes to zero.
1570
- */
1571
- function createSubscribe(executor, onNoObservers) {
1572
- var proxy = new ObserverProxy(executor, onNoObservers);
1573
- return proxy.subscribe.bind(proxy);
1574
- }
1575
- /**
1576
- * Implement fan-out for any number of Observers attached via a subscribe
1577
- * function.
1578
- */
1579
- var ObserverProxy = /** @class */ (function () {
1580
- /**
1581
- * @param executor Function which can make calls to a single Observer
1582
- * as a proxy.
1583
- * @param onNoObservers Callback when count of Observers goes to zero.
1584
- */
1585
- function ObserverProxy(executor, onNoObservers) {
1586
- var _this = this;
1587
- this.observers = [];
1588
- this.unsubscribes = [];
1589
- this.observerCount = 0;
1590
- // Micro-task scheduling by calling task.then().
1591
- this.task = Promise.resolve();
1592
- this.finalized = false;
1593
- this.onNoObservers = onNoObservers;
1594
- // Call the executor asynchronously so subscribers that are called
1595
- // synchronously after the creation of the subscribe function
1596
- // can still receive the very first value generated in the executor.
1597
- this.task
1598
- .then(function () {
1599
- executor(_this);
1600
- })
1601
- .catch(function (e) {
1602
- _this.error(e);
1603
- });
1604
- }
1605
- ObserverProxy.prototype.next = function (value) {
1606
- this.forEachObserver(function (observer) {
1607
- observer.next(value);
1608
- });
1609
- };
1610
- ObserverProxy.prototype.error = function (error) {
1611
- this.forEachObserver(function (observer) {
1612
- observer.error(error);
1613
- });
1614
- this.close(error);
1615
- };
1616
- ObserverProxy.prototype.complete = function () {
1617
- this.forEachObserver(function (observer) {
1618
- observer.complete();
1619
- });
1620
- this.close();
1621
- };
1622
- /**
1623
- * Subscribe function that can be used to add an Observer to the fan-out list.
1624
- *
1625
- * - We require that no event is sent to a subscriber synchronously to their
1626
- * call to subscribe().
1627
- */
1628
- ObserverProxy.prototype.subscribe = function (nextOrObserver, error, complete) {
1629
- var _this = this;
1630
- var observer;
1631
- if (nextOrObserver === undefined &&
1632
- error === undefined &&
1633
- complete === undefined) {
1634
- throw new Error('Missing Observer.');
1635
- }
1636
- // Assemble an Observer object when passed as callback functions.
1637
- if (implementsAnyMethods(nextOrObserver, [
1638
- 'next',
1639
- 'error',
1640
- 'complete'
1641
- ])) {
1642
- observer = nextOrObserver;
1643
- }
1644
- else {
1645
- observer = {
1646
- next: nextOrObserver,
1647
- error: error,
1648
- complete: complete
1649
- };
1650
- }
1651
- if (observer.next === undefined) {
1652
- observer.next = noop;
1653
- }
1654
- if (observer.error === undefined) {
1655
- observer.error = noop;
1656
- }
1657
- if (observer.complete === undefined) {
1658
- observer.complete = noop;
1659
- }
1660
- var unsub = this.unsubscribeOne.bind(this, this.observers.length);
1661
- // Attempt to subscribe to a terminated Observable - we
1662
- // just respond to the Observer with the final error or complete
1663
- // event.
1664
- if (this.finalized) {
1665
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
1666
- this.task.then(function () {
1667
- try {
1668
- if (_this.finalError) {
1669
- observer.error(_this.finalError);
1670
- }
1671
- else {
1672
- observer.complete();
1673
- }
1674
- }
1675
- catch (e) {
1676
- // nothing
1677
- }
1678
- return;
1679
- });
1680
- }
1681
- this.observers.push(observer);
1682
- return unsub;
1683
- };
1684
- // Unsubscribe is synchronous - we guarantee that no events are sent to
1685
- // any unsubscribed Observer.
1686
- ObserverProxy.prototype.unsubscribeOne = function (i) {
1687
- if (this.observers === undefined || this.observers[i] === undefined) {
1688
- return;
1689
- }
1690
- delete this.observers[i];
1691
- this.observerCount -= 1;
1692
- if (this.observerCount === 0 && this.onNoObservers !== undefined) {
1693
- this.onNoObservers(this);
1694
- }
1695
- };
1696
- ObserverProxy.prototype.forEachObserver = function (fn) {
1697
- if (this.finalized) {
1698
- // Already closed by previous event....just eat the additional values.
1699
- return;
1700
- }
1701
- // Since sendOne calls asynchronously - there is no chance that
1702
- // this.observers will become undefined.
1703
- for (var i = 0; i < this.observers.length; i++) {
1704
- this.sendOne(i, fn);
1705
- }
1706
- };
1707
- // Call the Observer via one of it's callback function. We are careful to
1708
- // confirm that the observe has not been unsubscribed since this asynchronous
1709
- // function had been queued.
1710
- ObserverProxy.prototype.sendOne = function (i, fn) {
1711
- var _this = this;
1712
- // Execute the callback asynchronously
1713
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
1714
- this.task.then(function () {
1715
- if (_this.observers !== undefined && _this.observers[i] !== undefined) {
1716
- try {
1717
- fn(_this.observers[i]);
1718
- }
1719
- catch (e) {
1720
- // Ignore exceptions raised in Observers or missing methods of an
1721
- // Observer.
1722
- // Log error to console. b/31404806
1723
- if (typeof console !== 'undefined' && console.error) {
1724
- console.error(e);
1725
- }
1726
- }
1727
- }
1728
- });
1729
- };
1730
- ObserverProxy.prototype.close = function (err) {
1731
- var _this = this;
1732
- if (this.finalized) {
1733
- return;
1734
- }
1735
- this.finalized = true;
1736
- if (err !== undefined) {
1737
- this.finalError = err;
1738
- }
1739
- // Proxy is no longer needed - garbage collect references
1740
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
1741
- this.task.then(function () {
1742
- _this.observers = undefined;
1743
- _this.onNoObservers = undefined;
1744
- });
1745
- };
1746
- return ObserverProxy;
1747
- }());
1748
- /** Turn synchronous function into one called asynchronously. */
1749
- // eslint-disable-next-line @typescript-eslint/ban-types
1750
- function async(fn, onError) {
1751
- return function () {
1752
- var args = [];
1753
- for (var _i = 0; _i < arguments.length; _i++) {
1754
- args[_i] = arguments[_i];
1755
- }
1756
- Promise.resolve(true)
1757
- .then(function () {
1758
- fn.apply(void 0, args);
1759
- })
1760
- .catch(function (error) {
1761
- if (onError) {
1762
- onError(error);
1763
- }
1764
- });
1765
- };
1766
- }
1767
- /**
1768
- * Return true if the object passed in implements any of the named methods.
1769
- */
1770
- function implementsAnyMethods(obj, methods) {
1771
- if (typeof obj !== 'object' || obj === null) {
1772
- return false;
1773
- }
1774
- for (var _i = 0, methods_1 = methods; _i < methods_1.length; _i++) {
1775
- var method = methods_1[_i];
1776
- if (method in obj && typeof obj[method] === 'function') {
1777
- return true;
1778
- }
1779
- }
1780
- return false;
1781
- }
1782
- function noop() {
1783
- // do nothing
1784
- }
1785
-
1786
- /**
1787
- * @license
1788
- * Copyright 2017 Google LLC
1789
- *
1790
- * Licensed under the Apache License, Version 2.0 (the "License");
1791
- * you may not use this file except in compliance with the License.
1792
- * You may obtain a copy of the License at
1793
- *
1794
- * http://www.apache.org/licenses/LICENSE-2.0
1795
- *
1796
- * Unless required by applicable law or agreed to in writing, software
1797
- * distributed under the License is distributed on an "AS IS" BASIS,
1798
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1799
- * See the License for the specific language governing permissions and
1800
- * limitations under the License.
1801
- */
1802
- /**
1803
- * Check to make sure the appropriate number of arguments are provided for a public function.
1804
- * Throws an error if it fails.
1805
- *
1806
- * @param fnName The function name
1807
- * @param minCount The minimum number of arguments to allow for the function call
1808
- * @param maxCount The maximum number of argument to allow for the function call
1809
- * @param argCount The actual number of arguments provided.
1810
- */
1811
- var validateArgCount = function (fnName, minCount, maxCount, argCount) {
1812
- var argError;
1813
- if (argCount < minCount) {
1814
- argError = 'at least ' + minCount;
1815
- }
1816
- else if (argCount > maxCount) {
1817
- argError = maxCount === 0 ? 'none' : 'no more than ' + maxCount;
1818
- }
1819
- if (argError) {
1820
- var error = fnName +
1821
- ' failed: Was called with ' +
1822
- argCount +
1823
- (argCount === 1 ? ' argument.' : ' arguments.') +
1824
- ' Expects ' +
1825
- argError +
1826
- '.';
1827
- throw new Error(error);
1828
- }
1829
- };
1830
- /**
1831
- * Generates a string to prefix an error message about failed argument validation
1832
- *
1833
- * @param fnName The function name
1834
- * @param argName The name of the argument
1835
- * @return The prefix to add to the error thrown for validation.
1836
- */
1837
- function errorPrefix(fnName, argName) {
1838
- return "".concat(fnName, " failed: ").concat(argName, " argument ");
1839
- }
1840
- /**
1841
- * @param fnName
1842
- * @param argumentNumber
1843
- * @param namespace
1844
- * @param optional
1845
- */
1846
- function validateNamespace(fnName, namespace, optional) {
1847
- if (optional && !namespace) {
1848
- return;
1849
- }
1850
- if (typeof namespace !== 'string') {
1851
- //TODO: I should do more validation here. We only allow certain chars in namespaces.
1852
- throw new Error(errorPrefix(fnName, 'namespace') + 'must be a valid firebase namespace.');
1853
- }
1854
- }
1855
- function validateCallback(fnName, argumentName,
1856
- // eslint-disable-next-line @typescript-eslint/ban-types
1857
- callback, optional) {
1858
- if (optional && !callback) {
1859
- return;
1860
- }
1861
- if (typeof callback !== 'function') {
1862
- throw new Error(errorPrefix(fnName, argumentName) + 'must be a valid function.');
1863
- }
1864
- }
1865
- function validateContextObject(fnName, argumentName, context, optional) {
1866
- if (optional && !context) {
1867
- return;
1868
- }
1869
- if (typeof context !== 'object' || context === null) {
1870
- throw new Error(errorPrefix(fnName, argumentName) + 'must be a valid context object.');
1871
- }
1872
- }
1873
-
1874
- /**
1875
- * @license
1876
- * Copyright 2017 Google LLC
1877
- *
1878
- * Licensed under the Apache License, Version 2.0 (the "License");
1879
- * you may not use this file except in compliance with the License.
1880
- * You may obtain a copy of the License at
1881
- *
1882
- * http://www.apache.org/licenses/LICENSE-2.0
1883
- *
1884
- * Unless required by applicable law or agreed to in writing, software
1885
- * distributed under the License is distributed on an "AS IS" BASIS,
1886
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1887
- * See the License for the specific language governing permissions and
1888
- * limitations under the License.
1889
- */
1890
- // Code originally came from goog.crypt.stringToUtf8ByteArray, but for some reason they
1891
- // automatically replaced '\r\n' with '\n', and they didn't handle surrogate pairs,
1892
- // so it's been modified.
1893
- // Note that not all Unicode characters appear as single characters in JavaScript strings.
1894
- // fromCharCode returns the UTF-16 encoding of a character - so some Unicode characters
1895
- // use 2 characters in JavaScript. All 4-byte UTF-8 characters begin with a first
1896
- // character in the range 0xD800 - 0xDBFF (the first character of a so-called surrogate
1897
- // pair).
1898
- // See http://www.ecma-international.org/ecma-262/5.1/#sec-15.1.3
1899
- /**
1900
- * @param {string} str
1901
- * @return {Array}
1902
- */
1903
- var stringToByteArray = function (str) {
1904
- var out = [];
1905
- var p = 0;
1906
- for (var i = 0; i < str.length; i++) {
1907
- var c = str.charCodeAt(i);
1908
- // Is this the lead surrogate in a surrogate pair?
1909
- if (c >= 0xd800 && c <= 0xdbff) {
1910
- var high = c - 0xd800; // the high 10 bits.
1911
- i++;
1912
- assert(i < str.length, 'Surrogate pair missing trail surrogate.');
1913
- var low = str.charCodeAt(i) - 0xdc00; // the low 10 bits.
1914
- c = 0x10000 + (high << 10) + low;
1915
- }
1916
- if (c < 128) {
1917
- out[p++] = c;
1918
- }
1919
- else if (c < 2048) {
1920
- out[p++] = (c >> 6) | 192;
1921
- out[p++] = (c & 63) | 128;
1922
- }
1923
- else if (c < 65536) {
1924
- out[p++] = (c >> 12) | 224;
1925
- out[p++] = ((c >> 6) & 63) | 128;
1926
- out[p++] = (c & 63) | 128;
1927
- }
1928
- else {
1929
- out[p++] = (c >> 18) | 240;
1930
- out[p++] = ((c >> 12) & 63) | 128;
1931
- out[p++] = ((c >> 6) & 63) | 128;
1932
- out[p++] = (c & 63) | 128;
1933
- }
1934
- }
1935
- return out;
1936
- };
1937
- /**
1938
- * Calculate length without actually converting; useful for doing cheaper validation.
1939
- * @param {string} str
1940
- * @return {number}
1941
- */
1942
- var stringLength = function (str) {
1943
- var p = 0;
1944
- for (var i = 0; i < str.length; i++) {
1945
- var c = str.charCodeAt(i);
1946
- if (c < 128) {
1947
- p++;
1948
- }
1949
- else if (c < 2048) {
1950
- p += 2;
1951
- }
1952
- else if (c >= 0xd800 && c <= 0xdbff) {
1953
- // Lead surrogate of a surrogate pair. The pair together will take 4 bytes to represent.
1954
- p += 4;
1955
- i++; // skip trail surrogate.
1956
- }
1957
- else {
1958
- p += 3;
1959
- }
1960
- }
1961
- return p;
1962
- };
1963
-
1964
- /**
1965
- * @license
1966
- * Copyright 2022 Google LLC
1967
- *
1968
- * Licensed under the Apache License, Version 2.0 (the "License");
1969
- * you may not use this file except in compliance with the License.
1970
- * You may obtain a copy of the License at
1971
- *
1972
- * http://www.apache.org/licenses/LICENSE-2.0
1973
- *
1974
- * Unless required by applicable law or agreed to in writing, software
1975
- * distributed under the License is distributed on an "AS IS" BASIS,
1976
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1977
- * See the License for the specific language governing permissions and
1978
- * limitations under the License.
1979
- */
1980
- /**
1981
- * Copied from https://stackoverflow.com/a/2117523
1982
- * Generates a new uuid.
1983
- * @public
1984
- */
1985
- var uuidv4 = function () {
1986
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
1987
- var r = (Math.random() * 16) | 0, v = c === 'x' ? r : (r & 0x3) | 0x8;
1988
- return v.toString(16);
1989
- });
1990
- };
1991
-
1992
- /**
1993
- * @license
1994
- * Copyright 2019 Google LLC
1995
- *
1996
- * Licensed under the Apache License, Version 2.0 (the "License");
1997
- * you may not use this file except in compliance with the License.
1998
- * You may obtain a copy of the License at
1999
- *
2000
- * http://www.apache.org/licenses/LICENSE-2.0
2001
- *
2002
- * Unless required by applicable law or agreed to in writing, software
2003
- * distributed under the License is distributed on an "AS IS" BASIS,
2004
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2005
- * See the License for the specific language governing permissions and
2006
- * limitations under the License.
2007
- */
2008
- /**
2009
- * The amount of milliseconds to exponentially increase.
2010
- */
2011
- var DEFAULT_INTERVAL_MILLIS = 1000;
2012
- /**
2013
- * The factor to backoff by.
2014
- * Should be a number greater than 1.
2015
- */
2016
- var DEFAULT_BACKOFF_FACTOR = 2;
2017
- /**
2018
- * The maximum milliseconds to increase to.
2019
- *
2020
- * <p>Visible for testing
2021
- */
2022
- var MAX_VALUE_MILLIS = 4 * 60 * 60 * 1000; // Four hours, like iOS and Android.
2023
- /**
2024
- * The percentage of backoff time to randomize by.
2025
- * See
2026
- * http://go/safe-client-behavior#step-1-determine-the-appropriate-retry-interval-to-handle-spike-traffic
2027
- * for context.
2028
- *
2029
- * <p>Visible for testing
2030
- */
2031
- var RANDOM_FACTOR = 0.5;
2032
- /**
2033
- * Based on the backoff method from
2034
- * https://github.com/google/closure-library/blob/master/closure/goog/math/exponentialbackoff.js.
2035
- * Extracted here so we don't need to pass metadata and a stateful ExponentialBackoff object around.
2036
- */
2037
- function calculateBackoffMillis(backoffCount, intervalMillis, backoffFactor) {
2038
- if (intervalMillis === void 0) { intervalMillis = DEFAULT_INTERVAL_MILLIS; }
2039
- if (backoffFactor === void 0) { backoffFactor = DEFAULT_BACKOFF_FACTOR; }
2040
- // Calculates an exponentially increasing value.
2041
- // Deviation: calculates value from count and a constant interval, so we only need to save value
2042
- // and count to restore state.
2043
- var currBaseValue = intervalMillis * Math.pow(backoffFactor, backoffCount);
2044
- // A random "fuzz" to avoid waves of retries.
2045
- // Deviation: randomFactor is required.
2046
- var randomWait = Math.round(
2047
- // A fraction of the backoff value to add/subtract.
2048
- // Deviation: changes multiplication order to improve readability.
2049
- RANDOM_FACTOR *
2050
- currBaseValue *
2051
- // A random float (rounded to int by Math.round above) in the range [-1, 1]. Determines
2052
- // if we add or subtract.
2053
- (Math.random() - 0.5) *
2054
- 2);
2055
- // Limits backoff to max to avoid effectively permanent backoff.
2056
- return Math.min(MAX_VALUE_MILLIS, currBaseValue + randomWait);
2057
- }
2058
-
2059
- /**
2060
- * @license
2061
- * Copyright 2020 Google LLC
2062
- *
2063
- * Licensed under the Apache License, Version 2.0 (the "License");
2064
- * you may not use this file except in compliance with the License.
2065
- * You may obtain a copy of the License at
2066
- *
2067
- * http://www.apache.org/licenses/LICENSE-2.0
2068
- *
2069
- * Unless required by applicable law or agreed to in writing, software
2070
- * distributed under the License is distributed on an "AS IS" BASIS,
2071
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2072
- * See the License for the specific language governing permissions and
2073
- * limitations under the License.
2074
- */
2075
- /**
2076
- * Provide English ordinal letters after a number
2077
- */
2078
- function ordinal(i) {
2079
- if (!Number.isFinite(i)) {
2080
- return "".concat(i);
2081
- }
2082
- return i + indicator(i);
2083
- }
2084
- function indicator(i) {
2085
- i = Math.abs(i);
2086
- var cent = i % 100;
2087
- if (cent >= 10 && cent <= 20) {
2088
- return 'th';
2089
- }
2090
- var dec = i % 10;
2091
- if (dec === 1) {
2092
- return 'st';
2093
- }
2094
- if (dec === 2) {
2095
- return 'nd';
2096
- }
2097
- if (dec === 3) {
2098
- return 'rd';
2099
- }
2100
- return 'th';
2101
- }
2102
-
2103
- /**
2104
- * @license
2105
- * Copyright 2021 Google LLC
2106
- *
2107
- * Licensed under the Apache License, Version 2.0 (the "License");
2108
- * you may not use this file except in compliance with the License.
2109
- * You may obtain a copy of the License at
2110
- *
2111
- * http://www.apache.org/licenses/LICENSE-2.0
2112
- *
2113
- * Unless required by applicable law or agreed to in writing, software
2114
- * distributed under the License is distributed on an "AS IS" BASIS,
2115
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2116
- * See the License for the specific language governing permissions and
2117
- * limitations under the License.
2118
- */
2119
- function getModularInstance(service) {
2120
- if (service && service._delegate) {
2121
- return service._delegate;
2122
- }
2123
- else {
2124
- return service;
2125
- }
2126
- }
2127
-
2128
- export { 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, isCloudflareWorker, isElectron, isEmpty, isIE, isIndexedDBAvailable, isMobileCordova, isNode, isNodeSdk, isReactNative, isSafari, isUWP, isValidFormat, isValidTimestamp, isWebWorker, issuedAtTime, jsonEval, map, ordinal, promiseWithTimeout, querystring, querystringDecode, safeGet, stringLength, stringToByteArray, stringify, uuidv4, validateArgCount, validateCallback, validateContextObject, validateIndexedDBOpenable, validateNamespace };
2129
- //# sourceMappingURL=index.esm5.js.map