index.esm5.js 73 KB

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