@depup/firebase__util 1.14.0-depup.0

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