index.node.cjs.js 75 KB

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