123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103 |
-
-
- const CONSTANTS = {
-
-
- NODE_CLIENT: false,
-
-
- NODE_ADMIN: false,
-
-
- SDK_VERSION: '${JSCORE_VERSION}'
- };
-
-
-
- const assert = function (assertion, message) {
- if (!assertion) {
- throw assertionError(message);
- }
- };
-
- const assertionError = function (message) {
- return new Error('Firebase Database (' +
- CONSTANTS.SDK_VERSION +
- ') INTERNAL ASSERT FAILED: ' +
- message);
- };
-
-
- const stringToByteArray$1 = function (str) {
-
- const out = [];
- let p = 0;
- for (let i = 0; i < str.length; i++) {
- let c = str.charCodeAt(i);
- if (c < 128) {
- out[p++] = c;
- }
- else if (c < 2048) {
- out[p++] = (c >> 6) | 192;
- out[p++] = (c & 63) | 128;
- }
- else if ((c & 0xfc00) === 0xd800 &&
- i + 1 < str.length &&
- (str.charCodeAt(i + 1) & 0xfc00) === 0xdc00) {
-
- c = 0x10000 + ((c & 0x03ff) << 10) + (str.charCodeAt(++i) & 0x03ff);
- out[p++] = (c >> 18) | 240;
- out[p++] = ((c >> 12) & 63) | 128;
- out[p++] = ((c >> 6) & 63) | 128;
- out[p++] = (c & 63) | 128;
- }
- else {
- out[p++] = (c >> 12) | 224;
- out[p++] = ((c >> 6) & 63) | 128;
- out[p++] = (c & 63) | 128;
- }
- }
- return out;
- };
-
- const byteArrayToString = function (bytes) {
-
- const out = [];
- let pos = 0, c = 0;
- while (pos < bytes.length) {
- const c1 = bytes[pos++];
- if (c1 < 128) {
- out[c++] = String.fromCharCode(c1);
- }
- else if (c1 > 191 && c1 < 224) {
- const c2 = bytes[pos++];
- out[c++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
- }
- else if (c1 > 239 && c1 < 365) {
-
- const c2 = bytes[pos++];
- const c3 = bytes[pos++];
- const c4 = bytes[pos++];
- const u = (((c1 & 7) << 18) | ((c2 & 63) << 12) | ((c3 & 63) << 6) | (c4 & 63)) -
- 0x10000;
- out[c++] = String.fromCharCode(0xd800 + (u >> 10));
- out[c++] = String.fromCharCode(0xdc00 + (u & 1023));
- }
- else {
- const c2 = bytes[pos++];
- const c3 = bytes[pos++];
- out[c++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
- }
- }
- return out.join('');
- };
-
-
-
- const base64 = {
-
-
- byteToCharMap_: null,
-
-
- charToByteMap_: null,
-
-
- byteToCharMapWebSafe_: null,
-
-
- charToByteMapWebSafe_: null,
-
-
- ENCODED_VALS_BASE: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + 'abcdefghijklmnopqrstuvwxyz' + '0123456789',
-
-
- get ENCODED_VALS() {
- return this.ENCODED_VALS_BASE + '+/=';
- },
-
-
- get ENCODED_VALS_WEBSAFE() {
- return this.ENCODED_VALS_BASE + '-_.';
- },
-
-
- HAS_NATIVE_SUPPORT: typeof atob === 'function',
-
-
- encodeByteArray(input, webSafe) {
- if (!Array.isArray(input)) {
- throw Error('encodeByteArray takes an array as a parameter');
- }
- this.init_();
- const byteToCharMap = webSafe
- ? this.byteToCharMapWebSafe_
- : this.byteToCharMap_;
- const output = [];
- for (let i = 0; i < input.length; i += 3) {
- const byte1 = input[i];
- const haveByte2 = i + 1 < input.length;
- const byte2 = haveByte2 ? input[i + 1] : 0;
- const haveByte3 = i + 2 < input.length;
- const byte3 = haveByte3 ? input[i + 2] : 0;
- const outByte1 = byte1 >> 2;
- const outByte2 = ((byte1 & 0x03) << 4) | (byte2 >> 4);
- let outByte3 = ((byte2 & 0x0f) << 2) | (byte3 >> 6);
- let outByte4 = byte3 & 0x3f;
- if (!haveByte3) {
- outByte4 = 64;
- if (!haveByte2) {
- outByte3 = 64;
- }
- }
- output.push(byteToCharMap[outByte1], byteToCharMap[outByte2], byteToCharMap[outByte3], byteToCharMap[outByte4]);
- }
- return output.join('');
- },
-
-
- encodeString(input, webSafe) {
-
-
- if (this.HAS_NATIVE_SUPPORT && !webSafe) {
- return btoa(input);
- }
- return this.encodeByteArray(stringToByteArray$1(input), webSafe);
- },
-
-
- decodeString(input, webSafe) {
-
-
- if (this.HAS_NATIVE_SUPPORT && !webSafe) {
- return atob(input);
- }
- return byteArrayToString(this.decodeStringToByteArray(input, webSafe));
- },
-
-
- decodeStringToByteArray(input, webSafe) {
- this.init_();
- const charToByteMap = webSafe
- ? this.charToByteMapWebSafe_
- : this.charToByteMap_;
- const output = [];
- for (let i = 0; i < input.length;) {
- const byte1 = charToByteMap[input.charAt(i++)];
- const haveByte2 = i < input.length;
- const byte2 = haveByte2 ? charToByteMap[input.charAt(i)] : 0;
- ++i;
- const haveByte3 = i < input.length;
- const byte3 = haveByte3 ? charToByteMap[input.charAt(i)] : 64;
- ++i;
- const haveByte4 = i < input.length;
- const byte4 = haveByte4 ? charToByteMap[input.charAt(i)] : 64;
- ++i;
- if (byte1 == null || byte2 == null || byte3 == null || byte4 == null) {
- throw Error();
- }
- const outByte1 = (byte1 << 2) | (byte2 >> 4);
- output.push(outByte1);
- if (byte3 !== 64) {
- const outByte2 = ((byte2 << 4) & 0xf0) | (byte3 >> 2);
- output.push(outByte2);
- if (byte4 !== 64) {
- const outByte3 = ((byte3 << 6) & 0xc0) | byte4;
- output.push(outByte3);
- }
- }
- }
- return output;
- },
-
-
- init_() {
- if (!this.byteToCharMap_) {
- this.byteToCharMap_ = {};
- this.charToByteMap_ = {};
- this.byteToCharMapWebSafe_ = {};
- this.charToByteMapWebSafe_ = {};
-
- for (let i = 0; i < this.ENCODED_VALS.length; i++) {
- this.byteToCharMap_[i] = this.ENCODED_VALS.charAt(i);
- this.charToByteMap_[this.byteToCharMap_[i]] = i;
- this.byteToCharMapWebSafe_[i] = this.ENCODED_VALS_WEBSAFE.charAt(i);
- this.charToByteMapWebSafe_[this.byteToCharMapWebSafe_[i]] = i;
-
- if (i >= this.ENCODED_VALS_BASE.length) {
- this.charToByteMap_[this.ENCODED_VALS_WEBSAFE.charAt(i)] = i;
- this.charToByteMapWebSafe_[this.ENCODED_VALS.charAt(i)] = i;
- }
- }
- }
- }
- };
-
- const base64Encode = function (str) {
- const utf8Bytes = stringToByteArray$1(str);
- return base64.encodeByteArray(utf8Bytes, true);
- };
-
- const base64urlEncodeWithoutPadding = function (str) {
-
- return base64Encode(str).replace(/\./g, '');
- };
-
- const base64Decode = function (str) {
- try {
- return base64.decodeString(str, true);
- }
- catch (e) {
- console.error('base64Decode failed: ', e);
- }
- return null;
- };
-
-
-
- function deepCopy(value) {
- return deepExtend(undefined, value);
- }
-
- function deepExtend(target, source) {
- if (!(source instanceof Object)) {
- return source;
- }
- switch (source.constructor) {
- case Date:
-
-
- const dateValue = source;
- return new Date(dateValue.getTime());
- case Object:
- if (target === undefined) {
- target = {};
- }
- break;
- case Array:
-
- target = [];
- break;
- default:
-
- return source;
- }
- for (const prop in source) {
-
- if (!source.hasOwnProperty(prop) || !isValidKey(prop)) {
- continue;
- }
- target[prop] = deepExtend(target[prop], source[prop]);
- }
- return target;
- }
- function isValidKey(key) {
- return key !== '__proto__';
- }
-
-
-
- function getGlobal() {
- if (typeof self !== 'undefined') {
- return self;
- }
- if (typeof window !== 'undefined') {
- return window;
- }
- if (typeof global !== 'undefined') {
- return global;
- }
- throw new Error('Unable to locate global object.');
- }
-
-
- const getDefaultsFromGlobal = () => getGlobal().__FIREBASE_DEFAULTS__;
-
- const getDefaultsFromEnvVariable = () => {
- if (typeof process === 'undefined' || typeof process.env === 'undefined') {
- return;
- }
- const defaultsJsonString = process.env.__FIREBASE_DEFAULTS__;
- if (defaultsJsonString) {
- return JSON.parse(defaultsJsonString);
- }
- };
- const getDefaultsFromCookie = () => {
- if (typeof document === 'undefined') {
- return;
- }
- let match;
- try {
- match = document.cookie.match(/__FIREBASE_DEFAULTS__=([^;]+)/);
- }
- catch (e) {
-
-
- return;
- }
- const decoded = match && base64Decode(match[1]);
- return decoded && JSON.parse(decoded);
- };
-
- const getDefaults = () => {
- try {
- return (getDefaultsFromGlobal() ||
- getDefaultsFromEnvVariable() ||
- getDefaultsFromCookie());
- }
- catch (e) {
-
-
- console.info(`Unable to get __FIREBASE_DEFAULTS__ due to: ${e}`);
- return;
- }
- };
-
- const getDefaultEmulatorHost = (productName) => { var _a, _b; return (_b = (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a.emulatorHosts) === null || _b === void 0 ? void 0 : _b[productName]; };
-
- const getDefaultEmulatorHostnameAndPort = (productName) => {
- const host = getDefaultEmulatorHost(productName);
- if (!host) {
- return undefined;
- }
- const separatorIndex = host.lastIndexOf(':');
- if (separatorIndex <= 0 || separatorIndex + 1 === host.length) {
- throw new Error(`Invalid host ${host} with no separate hostname and port!`);
- }
-
- const port = parseInt(host.substring(separatorIndex + 1), 10);
- if (host[0] === '[') {
-
- return [host.substring(1, separatorIndex - 1), port];
- }
- else {
- return [host.substring(0, separatorIndex), port];
- }
- };
-
- const getDefaultAppConfig = () => { var _a; return (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a.config; };
-
- const getExperimentalSetting = (name) => { var _a; return (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a[`_${name}`]; };
-
-
- class Deferred {
- constructor() {
- this.reject = () => { };
- this.resolve = () => { };
- this.promise = new Promise((resolve, reject) => {
- this.resolve = resolve;
- this.reject = reject;
- });
- }
-
-
- wrapCallback(callback) {
- return (error, value) => {
- if (error) {
- this.reject(error);
- }
- else {
- this.resolve(value);
- }
- if (typeof callback === 'function') {
-
-
- this.promise.catch(() => { });
-
-
- if (callback.length === 1) {
- callback(error);
- }
- else {
- callback(error, value);
- }
- }
- };
- }
- }
-
-
- function createMockUserToken(token, projectId) {
- if (token.uid) {
- throw new Error('The "uid" field is no longer supported by mockUserToken. Please use "sub" instead for Firebase Auth User ID.');
- }
-
- const header = {
- alg: 'none',
- type: 'JWT'
- };
- const project = projectId || 'demo-project';
- const iat = token.iat || 0;
- const sub = token.sub || token.user_id;
- if (!sub) {
- throw new Error("mockUserToken must contain 'sub' or 'user_id' field!");
- }
- const payload = Object.assign({
-
- iss: `https://securetoken.google.com/${project}`, aud: project, iat, exp: iat + 3600, auth_time: iat, sub, user_id: sub, firebase: {
- sign_in_provider: 'custom',
- identities: {}
- } }, token);
-
- const signature = '';
- return [
- base64urlEncodeWithoutPadding(JSON.stringify(header)),
- base64urlEncodeWithoutPadding(JSON.stringify(payload)),
- signature
- ].join('.');
- }
-
-
-
- function getUA() {
- if (typeof navigator !== 'undefined' &&
- typeof navigator['userAgent'] === 'string') {
- return navigator['userAgent'];
- }
- else {
- return '';
- }
- }
-
- function isMobileCordova() {
- return (typeof window !== 'undefined' &&
-
-
- !!(window['cordova'] || window['phonegap'] || window['PhoneGap']) &&
- /ios|iphone|ipod|ipad|android|blackberry|iemobile/i.test(getUA()));
- }
-
-
- function isNode() {
- var _a;
- const forceEnvironment = (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a.forceEnvironment;
- if (forceEnvironment === 'node') {
- return true;
- }
- else if (forceEnvironment === 'browser') {
- return false;
- }
- try {
- return (Object.prototype.toString.call(global.process) === '[object process]');
- }
- catch (e) {
- return false;
- }
- }
-
- function isBrowser() {
- return typeof self === 'object' && self.self === self;
- }
- function isBrowserExtension() {
- const runtime = typeof chrome === 'object'
- ? chrome.runtime
- : typeof browser === 'object'
- ? browser.runtime
- : undefined;
- return typeof runtime === 'object' && runtime.id !== undefined;
- }
-
- function isReactNative() {
- return (typeof navigator === 'object' && navigator['product'] === 'ReactNative');
- }
-
- function isElectron() {
- return getUA().indexOf('Electron/') >= 0;
- }
-
- function isIE() {
- const ua = getUA();
- return ua.indexOf('MSIE ') >= 0 || ua.indexOf('Trident/') >= 0;
- }
-
- function isUWP() {
- return getUA().indexOf('MSAppHost/') >= 0;
- }
-
- function isNodeSdk() {
- return CONSTANTS.NODE_CLIENT === true || CONSTANTS.NODE_ADMIN === true;
- }
-
- function isSafari() {
- return (!isNode() &&
- navigator.userAgent.includes('Safari') &&
- !navigator.userAgent.includes('Chrome'));
- }
-
- function isIndexedDBAvailable() {
- try {
- return typeof indexedDB === 'object';
- }
- catch (e) {
- return false;
- }
- }
-
- function validateIndexedDBOpenable() {
- return new Promise((resolve, reject) => {
- try {
- let preExist = true;
- const DB_CHECK_NAME = 'validate-browser-context-for-indexeddb-analytics-module';
- const request = self.indexedDB.open(DB_CHECK_NAME);
- request.onsuccess = () => {
- request.result.close();
-
- if (!preExist) {
- self.indexedDB.deleteDatabase(DB_CHECK_NAME);
- }
- resolve(true);
- };
- request.onupgradeneeded = () => {
- preExist = false;
- };
- request.onerror = () => {
- var _a;
- reject(((_a = request.error) === null || _a === void 0 ? void 0 : _a.message) || '');
- };
- }
- catch (error) {
- reject(error);
- }
- });
- }
-
- function areCookiesEnabled() {
- if (typeof navigator === 'undefined' || !navigator.cookieEnabled) {
- return false;
- }
- return true;
- }
-
-
-
- const ERROR_NAME = 'FirebaseError';
-
-
- class FirebaseError extends Error {
- constructor(
- /** The error code for this error. */
- code, message,
- /** Custom data for this error. */
- customData) {
- super(message);
- this.code = code;
- this.customData = customData;
-
- this.name = ERROR_NAME;
-
-
- Object.setPrototypeOf(this, FirebaseError.prototype);
-
-
- if (Error.captureStackTrace) {
- Error.captureStackTrace(this, ErrorFactory.prototype.create);
- }
- }
- }
- class ErrorFactory {
- constructor(service, serviceName, errors) {
- this.service = service;
- this.serviceName = serviceName;
- this.errors = errors;
- }
- create(code, ...data) {
- const customData = data[0] || {};
- const fullCode = `${this.service}/${code}`;
- const template = this.errors[code];
- const message = template ? replaceTemplate(template, customData) : 'Error';
-
- const fullMessage = `${this.serviceName}: ${message} (${fullCode}).`;
- const error = new FirebaseError(fullCode, fullMessage, customData);
- return error;
- }
- }
- function replaceTemplate(template, data) {
- return template.replace(PATTERN, (_, key) => {
- const value = data[key];
- return value != null ? String(value) : `<${key}?>`;
- });
- }
- const PATTERN = /\{\$([^}]+)}/g;
-
-
-
- function jsonEval(str) {
- return JSON.parse(str);
- }
-
- function stringify(data) {
- return JSON.stringify(data);
- }
-
-
-
- const decode = function (token) {
- let header = {}, claims = {}, data = {}, signature = '';
- try {
- const parts = token.split('.');
- header = jsonEval(base64Decode(parts[0]) || '');
- claims = jsonEval(base64Decode(parts[1]) || '');
- signature = parts[2];
- data = claims['d'] || {};
- delete claims['d'];
- }
- catch (e) { }
- return {
- header,
- claims,
- data,
- signature
- };
- };
-
- const isValidTimestamp = function (token) {
- const claims = decode(token).claims;
- const now = Math.floor(new Date().getTime() / 1000);
- let validSince = 0, validUntil = 0;
- if (typeof claims === 'object') {
- if (claims.hasOwnProperty('nbf')) {
- validSince = claims['nbf'];
- }
- else if (claims.hasOwnProperty('iat')) {
- validSince = claims['iat'];
- }
- if (claims.hasOwnProperty('exp')) {
- validUntil = claims['exp'];
- }
- else {
-
- validUntil = validSince + 86400;
- }
- }
- return (!!now &&
- !!validSince &&
- !!validUntil &&
- now >= validSince &&
- now <= validUntil);
- };
-
- const issuedAtTime = function (token) {
- const claims = decode(token).claims;
- if (typeof claims === 'object' && claims.hasOwnProperty('iat')) {
- return claims['iat'];
- }
- return null;
- };
-
- const isValidFormat = function (token) {
- const decoded = decode(token), claims = decoded.claims;
- return !!claims && typeof claims === 'object' && claims.hasOwnProperty('iat');
- };
-
- const isAdmin = function (token) {
- const claims = decode(token).claims;
- return typeof claims === 'object' && claims['admin'] === true;
- };
-
-
- function contains(obj, key) {
- return Object.prototype.hasOwnProperty.call(obj, key);
- }
- function safeGet(obj, key) {
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
- return obj[key];
- }
- else {
- return undefined;
- }
- }
- function isEmpty(obj) {
- for (const key in obj) {
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
- return false;
- }
- }
- return true;
- }
- function map(obj, fn, contextObj) {
- const res = {};
- for (const key in obj) {
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
- res[key] = fn.call(contextObj, obj[key], key, obj);
- }
- }
- return res;
- }
-
- function deepEqual(a, b) {
- if (a === b) {
- return true;
- }
- const aKeys = Object.keys(a);
- const bKeys = Object.keys(b);
- for (const k of aKeys) {
- if (!bKeys.includes(k)) {
- return false;
- }
- const aProp = a[k];
- const bProp = b[k];
- if (isObject(aProp) && isObject(bProp)) {
- if (!deepEqual(aProp, bProp)) {
- return false;
- }
- }
- else if (aProp !== bProp) {
- return false;
- }
- }
- for (const k of bKeys) {
- if (!aKeys.includes(k)) {
- return false;
- }
- }
- return true;
- }
- function isObject(thing) {
- return thing !== null && typeof thing === 'object';
- }
-
-
-
- function promiseWithTimeout(promise, timeInMS = 2000) {
- const deferredPromise = new Deferred();
- setTimeout(() => deferredPromise.reject('timeout!'), timeInMS);
- promise.then(deferredPromise.resolve, deferredPromise.reject);
- return deferredPromise.promise;
- }
-
-
-
- function querystring(querystringParams) {
- const params = [];
- for (const [key, value] of Object.entries(querystringParams)) {
- if (Array.isArray(value)) {
- value.forEach(arrayVal => {
- params.push(encodeURIComponent(key) + '=' + encodeURIComponent(arrayVal));
- });
- }
- else {
- params.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
- }
- }
- return params.length ? '&' + params.join('&') : '';
- }
-
- function querystringDecode(querystring) {
- const obj = {};
- const tokens = querystring.replace(/^\?/, '').split('&');
- tokens.forEach(token => {
- if (token) {
- const [key, value] = token.split('=');
- obj[decodeURIComponent(key)] = decodeURIComponent(value);
- }
- });
- return obj;
- }
-
- function extractQuerystring(url) {
- const queryStart = url.indexOf('?');
- if (!queryStart) {
- return '';
- }
- const fragmentStart = url.indexOf('#', queryStart);
- return url.substring(queryStart, fragmentStart > 0 ? fragmentStart : undefined);
- }
-
-
-
-
- class Sha1 {
- constructor() {
-
-
- this.chain_ = [];
-
-
- this.buf_ = [];
-
-
- this.W_ = [];
-
-
- this.pad_ = [];
-
-
- this.inbuf_ = 0;
-
-
- this.total_ = 0;
- this.blockSize = 512 / 8;
- this.pad_[0] = 128;
- for (let i = 1; i < this.blockSize; ++i) {
- this.pad_[i] = 0;
- }
- this.reset();
- }
- reset() {
- this.chain_[0] = 0x67452301;
- this.chain_[1] = 0xefcdab89;
- this.chain_[2] = 0x98badcfe;
- this.chain_[3] = 0x10325476;
- this.chain_[4] = 0xc3d2e1f0;
- this.inbuf_ = 0;
- this.total_ = 0;
- }
-
-
- compress_(buf, offset) {
- if (!offset) {
- offset = 0;
- }
- const W = this.W_;
-
- if (typeof buf === 'string') {
- for (let i = 0; i < 16; i++) {
-
-
-
-
-
-
-
-
- W[i] =
- (buf.charCodeAt(offset) << 24) |
- (buf.charCodeAt(offset + 1) << 16) |
- (buf.charCodeAt(offset + 2) << 8) |
- buf.charCodeAt(offset + 3);
- offset += 4;
- }
- }
- else {
- for (let i = 0; i < 16; i++) {
- W[i] =
- (buf[offset] << 24) |
- (buf[offset + 1] << 16) |
- (buf[offset + 2] << 8) |
- buf[offset + 3];
- offset += 4;
- }
- }
-
- for (let i = 16; i < 80; i++) {
- const t = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
- W[i] = ((t << 1) | (t >>> 31)) & 0xffffffff;
- }
- let a = this.chain_[0];
- let b = this.chain_[1];
- let c = this.chain_[2];
- let d = this.chain_[3];
- let e = this.chain_[4];
- let f, k;
-
- for (let i = 0; i < 80; i++) {
- if (i < 40) {
- if (i < 20) {
- f = d ^ (b & (c ^ d));
- k = 0x5a827999;
- }
- else {
- f = b ^ c ^ d;
- k = 0x6ed9eba1;
- }
- }
- else {
- if (i < 60) {
- f = (b & c) | (d & (b | c));
- k = 0x8f1bbcdc;
- }
- else {
- f = b ^ c ^ d;
- k = 0xca62c1d6;
- }
- }
- const t = (((a << 5) | (a >>> 27)) + f + e + k + W[i]) & 0xffffffff;
- e = d;
- d = c;
- c = ((b << 30) | (b >>> 2)) & 0xffffffff;
- b = a;
- a = t;
- }
- this.chain_[0] = (this.chain_[0] + a) & 0xffffffff;
- this.chain_[1] = (this.chain_[1] + b) & 0xffffffff;
- this.chain_[2] = (this.chain_[2] + c) & 0xffffffff;
- this.chain_[3] = (this.chain_[3] + d) & 0xffffffff;
- this.chain_[4] = (this.chain_[4] + e) & 0xffffffff;
- }
- update(bytes, length) {
-
- if (bytes == null) {
- return;
- }
- if (length === undefined) {
- length = bytes.length;
- }
- const lengthMinusBlock = length - this.blockSize;
- let n = 0;
-
- const buf = this.buf_;
- let inbuf = this.inbuf_;
-
- while (n < length) {
-
-
-
-
- if (inbuf === 0) {
- while (n <= lengthMinusBlock) {
- this.compress_(bytes, n);
- n += this.blockSize;
- }
- }
- if (typeof bytes === 'string') {
- while (n < length) {
- buf[inbuf] = bytes.charCodeAt(n);
- ++inbuf;
- ++n;
- if (inbuf === this.blockSize) {
- this.compress_(buf);
- inbuf = 0;
-
- break;
- }
- }
- }
- else {
- while (n < length) {
- buf[inbuf] = bytes[n];
- ++inbuf;
- ++n;
- if (inbuf === this.blockSize) {
- this.compress_(buf);
- inbuf = 0;
-
- break;
- }
- }
- }
- }
- this.inbuf_ = inbuf;
- this.total_ += length;
- }
-
- digest() {
- const digest = [];
- let totalBits = this.total_ * 8;
-
- if (this.inbuf_ < 56) {
- this.update(this.pad_, 56 - this.inbuf_);
- }
- else {
- this.update(this.pad_, this.blockSize - (this.inbuf_ - 56));
- }
-
- for (let i = this.blockSize - 1; i >= 56; i--) {
- this.buf_[i] = totalBits & 255;
- totalBits /= 256;
- }
- this.compress_(this.buf_);
- let n = 0;
- for (let i = 0; i < 5; i++) {
- for (let j = 24; j >= 0; j -= 8) {
- digest[n] = (this.chain_[i] >> j) & 255;
- ++n;
- }
- }
- return digest;
- }
- }
-
-
- function createSubscribe(executor, onNoObservers) {
- const proxy = new ObserverProxy(executor, onNoObservers);
- return proxy.subscribe.bind(proxy);
- }
-
- class ObserverProxy {
-
-
- constructor(executor, onNoObservers) {
- this.observers = [];
- this.unsubscribes = [];
- this.observerCount = 0;
-
- this.task = Promise.resolve();
- this.finalized = false;
- this.onNoObservers = onNoObservers;
-
-
-
- this.task
- .then(() => {
- executor(this);
- })
- .catch(e => {
- this.error(e);
- });
- }
- next(value) {
- this.forEachObserver((observer) => {
- observer.next(value);
- });
- }
- error(error) {
- this.forEachObserver((observer) => {
- observer.error(error);
- });
- this.close(error);
- }
- complete() {
- this.forEachObserver((observer) => {
- observer.complete();
- });
- this.close();
- }
-
-
- subscribe(nextOrObserver, error, complete) {
- let observer;
- if (nextOrObserver === undefined &&
- error === undefined &&
- complete === undefined) {
- throw new Error('Missing Observer.');
- }
-
- if (implementsAnyMethods(nextOrObserver, [
- 'next',
- 'error',
- 'complete'
- ])) {
- observer = nextOrObserver;
- }
- else {
- observer = {
- next: nextOrObserver,
- error,
- complete
- };
- }
- if (observer.next === undefined) {
- observer.next = noop;
- }
- if (observer.error === undefined) {
- observer.error = noop;
- }
- if (observer.complete === undefined) {
- observer.complete = noop;
- }
- const unsub = this.unsubscribeOne.bind(this, this.observers.length);
-
-
-
- if (this.finalized) {
-
- this.task.then(() => {
- try {
- if (this.finalError) {
- observer.error(this.finalError);
- }
- else {
- observer.complete();
- }
- }
- catch (e) {
-
- }
- return;
- });
- }
- this.observers.push(observer);
- return unsub;
- }
-
-
- unsubscribeOne(i) {
- if (this.observers === undefined || this.observers[i] === undefined) {
- return;
- }
- delete this.observers[i];
- this.observerCount -= 1;
- if (this.observerCount === 0 && this.onNoObservers !== undefined) {
- this.onNoObservers(this);
- }
- }
- forEachObserver(fn) {
- if (this.finalized) {
-
- return;
- }
-
-
- for (let i = 0; i < this.observers.length; i++) {
- this.sendOne(i, fn);
- }
- }
-
-
-
- sendOne(i, fn) {
-
-
- this.task.then(() => {
- if (this.observers !== undefined && this.observers[i] !== undefined) {
- try {
- fn(this.observers[i]);
- }
- catch (e) {
-
-
-
- if (typeof console !== 'undefined' && console.error) {
- console.error(e);
- }
- }
- }
- });
- }
- close(err) {
- if (this.finalized) {
- return;
- }
- this.finalized = true;
- if (err !== undefined) {
- this.finalError = err;
- }
-
-
- this.task.then(() => {
- this.observers = undefined;
- this.onNoObservers = undefined;
- });
- }
- }
-
-
- function async(fn, onError) {
- return (...args) => {
- Promise.resolve(true)
- .then(() => {
- fn(...args);
- })
- .catch((error) => {
- if (onError) {
- onError(error);
- }
- });
- };
- }
-
- function implementsAnyMethods(obj, methods) {
- if (typeof obj !== 'object' || obj === null) {
- return false;
- }
- for (const method of methods) {
- if (method in obj && typeof obj[method] === 'function') {
- return true;
- }
- }
- return false;
- }
- function noop() {
-
- }
-
-
-
- const validateArgCount = function (fnName, minCount, maxCount, argCount) {
- let argError;
- if (argCount < minCount) {
- argError = 'at least ' + minCount;
- }
- else if (argCount > maxCount) {
- argError = maxCount === 0 ? 'none' : 'no more than ' + maxCount;
- }
- if (argError) {
- const error = fnName +
- ' failed: Was called with ' +
- argCount +
- (argCount === 1 ? ' argument.' : ' arguments.') +
- ' Expects ' +
- argError +
- '.';
- throw new Error(error);
- }
- };
-
- function errorPrefix(fnName, argName) {
- return `${fnName} failed: ${argName} argument `;
- }
-
- function validateNamespace(fnName, namespace, optional) {
- if (optional && !namespace) {
- return;
- }
- if (typeof namespace !== 'string') {
-
- throw new Error(errorPrefix(fnName, 'namespace') + 'must be a valid firebase namespace.');
- }
- }
- function validateCallback(fnName, argumentName,
- // eslint-disable-next-line @typescript-eslint/ban-types
- callback, optional) {
- if (optional && !callback) {
- return;
- }
- if (typeof callback !== 'function') {
- throw new Error(errorPrefix(fnName, argumentName) + 'must be a valid function.');
- }
- }
- function validateContextObject(fnName, argumentName, context, optional) {
- if (optional && !context) {
- return;
- }
- if (typeof context !== 'object' || context === null) {
- throw new Error(errorPrefix(fnName, argumentName) + 'must be a valid context object.');
- }
- }
-
- /**
- * @license
- * Copyright 2017 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- // Code originally came from goog.crypt.stringToUtf8ByteArray, but for some reason they
- // automatically replaced '\r\n' with '\n', and they didn't handle surrogate pairs,
- // so it's been modified.
- // Note that not all Unicode characters appear as single characters in JavaScript strings.
- // fromCharCode returns the UTF-16 encoding of a character - so some Unicode characters
- // use 2 characters in Javascript. All 4-byte UTF-8 characters begin with a first
- // character in the range 0xD800 - 0xDBFF (the first character of a so-called surrogate
- // pair).
- // See http://www.ecma-international.org/ecma-262/5.1/#sec-15.1.3
- /**
- * @param {string} str
- * @return {Array}
- */
- const stringToByteArray = function (str) {
- const out = [];
- let p = 0;
- for (let i = 0; i < str.length; i++) {
- let c = str.charCodeAt(i);
- // Is this the lead surrogate in a surrogate pair?
- if (c >= 0xd800 && c <= 0xdbff) {
- const high = c - 0xd800; // the high 10 bits.
- i++;
- assert(i < str.length, 'Surrogate pair missing trail surrogate.');
- const low = str.charCodeAt(i) - 0xdc00; // the low 10 bits.
- c = 0x10000 + (high << 10) + low;
- }
- if (c < 128) {
- out[p++] = c;
- }
- else if (c < 2048) {
- out[p++] = (c >> 6) | 192;
- out[p++] = (c & 63) | 128;
- }
- else if (c < 65536) {
- out[p++] = (c >> 12) | 224;
- out[p++] = ((c >> 6) & 63) | 128;
- out[p++] = (c & 63) | 128;
- }
- else {
- out[p++] = (c >> 18) | 240;
- out[p++] = ((c >> 12) & 63) | 128;
- out[p++] = ((c >> 6) & 63) | 128;
- out[p++] = (c & 63) | 128;
- }
- }
- return out;
- };
- /**
- * Calculate length without actually converting; useful for doing cheaper validation.
- * @param {string} str
- * @return {number}
- */
- const stringLength = function (str) {
- let p = 0;
- for (let i = 0; i < str.length; i++) {
- const c = str.charCodeAt(i);
- if (c < 128) {
- p++;
- }
- else if (c < 2048) {
- p += 2;
- }
- else if (c >= 0xd800 && c <= 0xdbff) {
- // Lead surrogate of a surrogate pair. The pair together will take 4 bytes to represent.
- p += 4;
- i++; // skip trail surrogate.
- }
- else {
- p += 3;
- }
- }
- return p;
- };
-
- /**
- * @license
- * Copyright 2022 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http:
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- /**
- * Copied from https:
- * Generates a new uuid.
- * @public
- */
- const uuidv4 = function () {
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
- const r = (Math.random() * 16) | 0, v = c === 'x' ? r : (r & 0x3) | 0x8;
- return v.toString(16);
- });
- };
-
-
-
- const DEFAULT_INTERVAL_MILLIS = 1000;
-
- const DEFAULT_BACKOFF_FACTOR = 2;
-
- const MAX_VALUE_MILLIS = 4 * 60 * 60 * 1000;
-
- const RANDOM_FACTOR = 0.5;
-
- function calculateBackoffMillis(backoffCount, intervalMillis = DEFAULT_INTERVAL_MILLIS, backoffFactor = DEFAULT_BACKOFF_FACTOR) {
-
-
-
- const currBaseValue = intervalMillis * Math.pow(backoffFactor, backoffCount);
-
-
- const randomWait = Math.round(
-
-
- RANDOM_FACTOR *
- currBaseValue *
-
-
- (Math.random() - 0.5) *
- 2);
-
- return Math.min(MAX_VALUE_MILLIS, currBaseValue + randomWait);
- }
-
-
-
- function ordinal(i) {
- if (!Number.isFinite(i)) {
- return `${i}`;
- }
- return i + indicator(i);
- }
- function indicator(i) {
- i = Math.abs(i);
- const cent = i % 100;
- if (cent >= 10 && cent <= 20) {
- return 'th';
- }
- const dec = i % 10;
- if (dec === 1) {
- return 'st';
- }
- if (dec === 2) {
- return 'nd';
- }
- if (dec === 3) {
- return 'rd';
- }
- return 'th';
- }
-
-
- function getModularInstance(service) {
- if (service && service._delegate) {
- return service._delegate;
- }
- else {
- return service;
- }
- }
-
- export { CONSTANTS, Deferred, ErrorFactory, FirebaseError, MAX_VALUE_MILLIS, RANDOM_FACTOR, Sha1, areCookiesEnabled, assert, assertionError, async, base64, base64Decode, base64Encode, base64urlEncodeWithoutPadding, calculateBackoffMillis, contains, createMockUserToken, createSubscribe, decode, deepCopy, deepEqual, deepExtend, errorPrefix, extractQuerystring, getDefaultAppConfig, getDefaultEmulatorHost, getDefaultEmulatorHostnameAndPort, getDefaults, getExperimentalSetting, getGlobal, getModularInstance, getUA, isAdmin, isBrowser, isBrowserExtension, isElectron, isEmpty, isIE, isIndexedDBAvailable, isMobileCordova, isNode, isNodeSdk, isReactNative, isSafari, isUWP, isValidFormat, isValidTimestamp, issuedAtTime, jsonEval, map, ordinal, promiseWithTimeout, querystring, querystringDecode, safeGet, stringLength, stringToByteArray, stringify, uuidv4, validateArgCount, validateCallback, validateContextObject, validateIndexedDBOpenable, validateNamespace };
|