Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

index.node.cjs.js 73KB

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