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