1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185 |
- 'use strict';
-
- Object.defineProperty(exports, '__esModule', { value: true });
-
- var tslib = require('tslib');
-
-
-
- var CONSTANTS = {
-
-
- NODE_CLIENT: false,
-
-
- NODE_ADMIN: false,
-
-
- SDK_VERSION: '${JSCORE_VERSION}'
- };
-
-
-
- var assert = function (assertion, message) {
- if (!assertion) {
- throw assertionError(message);
- }
- };
-
- var assertionError = function (message) {
- return new Error('Firebase Database (' +
- CONSTANTS.SDK_VERSION +
- ') INTERNAL ASSERT FAILED: ' +
- message);
- };
-
-
- var stringToByteArray$1 = function (str) {
-
- var out = [];
- var p = 0;
- for (var i = 0; i < str.length; i++) {
- var 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;
- };
-
- var byteArrayToString = function (bytes) {
-
- var out = [];
- var pos = 0, c = 0;
- while (pos < bytes.length) {
- var c1 = bytes[pos++];
- if (c1 < 128) {
- out[c++] = String.fromCharCode(c1);
- }
- else if (c1 > 191 && c1 < 224) {
- var c2 = bytes[pos++];
- out[c++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
- }
- else if (c1 > 239 && c1 < 365) {
-
- var c2 = bytes[pos++];
- var c3 = bytes[pos++];
- var c4 = bytes[pos++];
- var 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 {
- var c2 = bytes[pos++];
- var c3 = bytes[pos++];
- out[c++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
- }
- }
- return out.join('');
- };
-
-
-
- var 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: function (input, webSafe) {
- if (!Array.isArray(input)) {
- throw Error('encodeByteArray takes an array as a parameter');
- }
- this.init_();
- var byteToCharMap = webSafe
- ? this.byteToCharMapWebSafe_
- : this.byteToCharMap_;
- var output = [];
- for (var i = 0; i < input.length; i += 3) {
- var byte1 = input[i];
- var haveByte2 = i + 1 < input.length;
- var byte2 = haveByte2 ? input[i + 1] : 0;
- var haveByte3 = i + 2 < input.length;
- var byte3 = haveByte3 ? input[i + 2] : 0;
- var outByte1 = byte1 >> 2;
- var outByte2 = ((byte1 & 0x03) << 4) | (byte2 >> 4);
- var outByte3 = ((byte2 & 0x0f) << 2) | (byte3 >> 6);
- var 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: function (input, webSafe) {
-
-
- if (this.HAS_NATIVE_SUPPORT && !webSafe) {
- return btoa(input);
- }
- return this.encodeByteArray(stringToByteArray$1(input), webSafe);
- },
-
-
- decodeString: function (input, webSafe) {
-
-
- if (this.HAS_NATIVE_SUPPORT && !webSafe) {
- return atob(input);
- }
- return byteArrayToString(this.decodeStringToByteArray(input, webSafe));
- },
-
-
- decodeStringToByteArray: function (input, webSafe) {
- this.init_();
- var charToByteMap = webSafe
- ? this.charToByteMapWebSafe_
- : this.charToByteMap_;
- var output = [];
- for (var i = 0; i < input.length;) {
- var byte1 = charToByteMap[input.charAt(i++)];
- var haveByte2 = i < input.length;
- var byte2 = haveByte2 ? charToByteMap[input.charAt(i)] : 0;
- ++i;
- var haveByte3 = i < input.length;
- var byte3 = haveByte3 ? charToByteMap[input.charAt(i)] : 64;
- ++i;
- var haveByte4 = i < input.length;
- var byte4 = haveByte4 ? charToByteMap[input.charAt(i)] : 64;
- ++i;
- if (byte1 == null || byte2 == null || byte3 == null || byte4 == null) {
- throw Error();
- }
- var outByte1 = (byte1 << 2) | (byte2 >> 4);
- output.push(outByte1);
- if (byte3 !== 64) {
- var outByte2 = ((byte2 << 4) & 0xf0) | (byte3 >> 2);
- output.push(outByte2);
- if (byte4 !== 64) {
- var outByte3 = ((byte3 << 6) & 0xc0) | byte4;
- output.push(outByte3);
- }
- }
- }
- return output;
- },
-
-
- init_: function () {
- if (!this.byteToCharMap_) {
- this.byteToCharMap_ = {};
- this.charToByteMap_ = {};
- this.byteToCharMapWebSafe_ = {};
- this.charToByteMapWebSafe_ = {};
-
- for (var 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;
- }
- }
- }
- }
- };
-
- var base64Encode = function (str) {
- var utf8Bytes = stringToByteArray$1(str);
- return base64.encodeByteArray(utf8Bytes, true);
- };
-
- var base64urlEncodeWithoutPadding = function (str) {
-
- return base64Encode(str).replace(/\./g, '');
- };
-
- var 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:
-
-
- var dateValue = source;
- return new Date(dateValue.getTime());
- case Object:
- if (target === undefined) {
- target = {};
- }
- break;
- case Array:
-
- target = [];
- break;
- default:
-
- return source;
- }
- for (var 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.');
- }
-
-
- var getDefaultsFromGlobal = function () {
- return getGlobal().__FIREBASE_DEFAULTS__;
- };
-
- var getDefaultsFromEnvVariable = function () {
- if (typeof process === 'undefined' || typeof process.env === 'undefined') {
- return;
- }
- var defaultsJsonString = process.env.__FIREBASE_DEFAULTS__;
- if (defaultsJsonString) {
- return JSON.parse(defaultsJsonString);
- }
- };
- var getDefaultsFromCookie = function () {
- if (typeof document === 'undefined') {
- return;
- }
- var match;
- try {
- match = document.cookie.match(/__FIREBASE_DEFAULTS__=([^;]+)/);
- }
- catch (e) {
-
-
- return;
- }
- var decoded = match && base64Decode(match[1]);
- return decoded && JSON.parse(decoded);
- };
-
- var getDefaults = function () {
- try {
- return (getDefaultsFromGlobal() ||
- getDefaultsFromEnvVariable() ||
- getDefaultsFromCookie());
- }
- catch (e) {
-
-
- console.info("Unable to get __FIREBASE_DEFAULTS__ due to: ".concat(e));
- return;
- }
- };
-
- 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]; };
-
- var getDefaultEmulatorHostnameAndPort = function (productName) {
- var host = getDefaultEmulatorHost(productName);
- if (!host) {
- return undefined;
- }
- var separatorIndex = host.lastIndexOf(':');
- if (separatorIndex <= 0 || separatorIndex + 1 === host.length) {
- throw new Error("Invalid host ".concat(host, " with no separate hostname and port!"));
- }
-
- var port = parseInt(host.substring(separatorIndex + 1), 10);
- if (host[0] === '[') {
-
- return [host.substring(1, separatorIndex - 1), port];
- }
- else {
- return [host.substring(0, separatorIndex), port];
- }
- };
-
- var getDefaultAppConfig = function () { var _a; return (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a.config; };
-
- var getExperimentalSetting = function (name) { var _a; return (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a["_".concat(name)]; };
-
-
- var Deferred = (function () {
- function Deferred() {
- var _this = this;
- this.reject = function () { };
- this.resolve = function () { };
- this.promise = new Promise(function (resolve, reject) {
- _this.resolve = resolve;
- _this.reject = reject;
- });
- }
-
-
- Deferred.prototype.wrapCallback = function (callback) {
- var _this = this;
- return function (error, value) {
- if (error) {
- _this.reject(error);
- }
- else {
- _this.resolve(value);
- }
- if (typeof callback === 'function') {
-
-
- _this.promise.catch(function () { });
-
-
- if (callback.length === 1) {
- callback(error);
- }
- else {
- callback(error, value);
- }
- }
- };
- };
- return Deferred;
- }());
-
-
- 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.');
- }
-
- var header = {
- alg: 'none',
- type: 'JWT'
- };
- var project = projectId || 'demo-project';
- var iat = token.iat || 0;
- var sub = token.sub || token.user_id;
- if (!sub) {
- throw new Error("mockUserToken must contain 'sub' or 'user_id' field!");
- }
- var payload = tslib.__assign({
-
- iss: "https://securetoken.google.com/".concat(project), aud: project, iat: iat, exp: iat + 3600, auth_time: iat, sub: sub, user_id: sub, firebase: {
- sign_in_provider: 'custom',
- identities: {}
- } }, token);
-
- var 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;
- var 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() {
- var 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() {
- var 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(function (resolve, reject) {
- try {
- var preExist_1 = true;
- var DB_CHECK_NAME_1 = 'validate-browser-context-for-indexeddb-analytics-module';
- var request_1 = self.indexedDB.open(DB_CHECK_NAME_1);
- request_1.onsuccess = function () {
- request_1.result.close();
-
- if (!preExist_1) {
- self.indexedDB.deleteDatabase(DB_CHECK_NAME_1);
- }
- resolve(true);
- };
- request_1.onupgradeneeded = function () {
- preExist_1 = false;
- };
- request_1.onerror = function () {
- var _a;
- reject(((_a = request_1.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;
- }
-
-
- var ERROR_NAME = 'FirebaseError';
-
-
- var FirebaseError = (function (_super) {
- tslib.__extends(FirebaseError, _super);
- function FirebaseError(
- /** The error code for this error. */
- code, message,
- /** Custom data for this error. */
- customData) {
- var _this = _super.call(this, message) || this;
- _this.code = code;
- _this.customData = customData;
-
- _this.name = ERROR_NAME;
-
-
- Object.setPrototypeOf(_this, FirebaseError.prototype);
-
-
- if (Error.captureStackTrace) {
- Error.captureStackTrace(_this, ErrorFactory.prototype.create);
- }
- return _this;
- }
- return FirebaseError;
- }(Error));
- var ErrorFactory = (function () {
- function ErrorFactory(service, serviceName, errors) {
- this.service = service;
- this.serviceName = serviceName;
- this.errors = errors;
- }
- ErrorFactory.prototype.create = function (code) {
- var data = [];
- for (var _i = 1; _i < arguments.length; _i++) {
- data[_i - 1] = arguments[_i];
- }
- var customData = data[0] || {};
- var fullCode = "".concat(this.service, "/").concat(code);
- var template = this.errors[code];
- var message = template ? replaceTemplate(template, customData) : 'Error';
-
- var fullMessage = "".concat(this.serviceName, ": ").concat(message, " (").concat(fullCode, ").");
- var error = new FirebaseError(fullCode, fullMessage, customData);
- return error;
- };
- return ErrorFactory;
- }());
- function replaceTemplate(template, data) {
- return template.replace(PATTERN, function (_, key) {
- var value = data[key];
- return value != null ? String(value) : "<".concat(key, "?>");
- });
- }
- var PATTERN = /\{\$([^}]+)}/g;
-
-
-
- function jsonEval(str) {
- return JSON.parse(str);
- }
-
- function stringify(data) {
- return JSON.stringify(data);
- }
-
-
-
- var decode = function (token) {
- var header = {}, claims = {}, data = {}, signature = '';
- try {
- var 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: header,
- claims: claims,
- data: data,
- signature: signature
- };
- };
-
- var isValidTimestamp = function (token) {
- var claims = decode(token).claims;
- var now = Math.floor(new Date().getTime() / 1000);
- var 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);
- };
-
- var issuedAtTime = function (token) {
- var claims = decode(token).claims;
- if (typeof claims === 'object' && claims.hasOwnProperty('iat')) {
- return claims['iat'];
- }
- return null;
- };
-
- var isValidFormat = function (token) {
- var decoded = decode(token), claims = decoded.claims;
- return !!claims && typeof claims === 'object' && claims.hasOwnProperty('iat');
- };
-
- var isAdmin = function (token) {
- var 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 (var key in obj) {
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
- return false;
- }
- }
- return true;
- }
- function map(obj, fn, contextObj) {
- var res = {};
- for (var 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;
- }
- var aKeys = Object.keys(a);
- var bKeys = Object.keys(b);
- for (var _i = 0, aKeys_1 = aKeys; _i < aKeys_1.length; _i++) {
- var k = aKeys_1[_i];
- if (!bKeys.includes(k)) {
- return false;
- }
- var aProp = a[k];
- var bProp = b[k];
- if (isObject(aProp) && isObject(bProp)) {
- if (!deepEqual(aProp, bProp)) {
- return false;
- }
- }
- else if (aProp !== bProp) {
- return false;
- }
- }
- for (var _a = 0, bKeys_1 = bKeys; _a < bKeys_1.length; _a++) {
- var k = bKeys_1[_a];
- if (!aKeys.includes(k)) {
- return false;
- }
- }
- return true;
- }
- function isObject(thing) {
- return thing !== null && typeof thing === 'object';
- }
-
-
-
- function promiseWithTimeout(promise, timeInMS) {
- if (timeInMS === void 0) { timeInMS = 2000; }
- var deferredPromise = new Deferred();
- setTimeout(function () { return deferredPromise.reject('timeout!'); }, timeInMS);
- promise.then(deferredPromise.resolve, deferredPromise.reject);
- return deferredPromise.promise;
- }
-
-
-
- function querystring(querystringParams) {
- var params = [];
- var _loop_1 = function (key, value) {
- if (Array.isArray(value)) {
- value.forEach(function (arrayVal) {
- params.push(encodeURIComponent(key) + '=' + encodeURIComponent(arrayVal));
- });
- }
- else {
- params.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
- }
- };
- for (var _i = 0, _a = Object.entries(querystringParams); _i < _a.length; _i++) {
- var _b = _a[_i], key = _b[0], value = _b[1];
- _loop_1(key, value);
- }
- return params.length ? '&' + params.join('&') : '';
- }
-
- function querystringDecode(querystring) {
- var obj = {};
- var tokens = querystring.replace(/^\?/, '').split('&');
- tokens.forEach(function (token) {
- if (token) {
- var _a = token.split('='), key = _a[0], value = _a[1];
- obj[decodeURIComponent(key)] = decodeURIComponent(value);
- }
- });
- return obj;
- }
-
- function extractQuerystring(url) {
- var queryStart = url.indexOf('?');
- if (!queryStart) {
- return '';
- }
- var fragmentStart = url.indexOf('#', queryStart);
- return url.substring(queryStart, fragmentStart > 0 ? fragmentStart : undefined);
- }
-
-
-
-
- var Sha1 = (function () {
- function Sha1() {
-
-
- this.chain_ = [];
-
-
- this.buf_ = [];
-
-
- this.W_ = [];
-
-
- this.pad_ = [];
-
-
- this.inbuf_ = 0;
-
-
- this.total_ = 0;
- this.blockSize = 512 / 8;
- this.pad_[0] = 128;
- for (var i = 1; i < this.blockSize; ++i) {
- this.pad_[i] = 0;
- }
- this.reset();
- }
- Sha1.prototype.reset = function () {
- 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;
- };
-
-
- Sha1.prototype.compress_ = function (buf, offset) {
- if (!offset) {
- offset = 0;
- }
- var W = this.W_;
-
- if (typeof buf === 'string') {
- for (var 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 (var i = 0; i < 16; i++) {
- W[i] =
- (buf[offset] << 24) |
- (buf[offset + 1] << 16) |
- (buf[offset + 2] << 8) |
- buf[offset + 3];
- offset += 4;
- }
- }
-
- for (var i = 16; i < 80; i++) {
- var t = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
- W[i] = ((t << 1) | (t >>> 31)) & 0xffffffff;
- }
- var a = this.chain_[0];
- var b = this.chain_[1];
- var c = this.chain_[2];
- var d = this.chain_[3];
- var e = this.chain_[4];
- var f, k;
-
- for (var 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;
- }
- }
- var 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;
- };
- Sha1.prototype.update = function (bytes, length) {
-
- if (bytes == null) {
- return;
- }
- if (length === undefined) {
- length = bytes.length;
- }
- var lengthMinusBlock = length - this.blockSize;
- var n = 0;
-
- var buf = this.buf_;
- var 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;
- };
-
- Sha1.prototype.digest = function () {
- var digest = [];
- var 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 (var i = this.blockSize - 1; i >= 56; i--) {
- this.buf_[i] = totalBits & 255;
- totalBits /= 256;
- }
- this.compress_(this.buf_);
- var n = 0;
- for (var i = 0; i < 5; i++) {
- for (var j = 24; j >= 0; j -= 8) {
- digest[n] = (this.chain_[i] >> j) & 255;
- ++n;
- }
- }
- return digest;
- };
- return Sha1;
- }());
-
-
- function createSubscribe(executor, onNoObservers) {
- var proxy = new ObserverProxy(executor, onNoObservers);
- return proxy.subscribe.bind(proxy);
- }
-
- var ObserverProxy = (function () {
-
-
- function ObserverProxy(executor, onNoObservers) {
- var _this = this;
- this.observers = [];
- this.unsubscribes = [];
- this.observerCount = 0;
-
- this.task = Promise.resolve();
- this.finalized = false;
- this.onNoObservers = onNoObservers;
-
-
-
- this.task
- .then(function () {
- executor(_this);
- })
- .catch(function (e) {
- _this.error(e);
- });
- }
- ObserverProxy.prototype.next = function (value) {
- this.forEachObserver(function (observer) {
- observer.next(value);
- });
- };
- ObserverProxy.prototype.error = function (error) {
- this.forEachObserver(function (observer) {
- observer.error(error);
- });
- this.close(error);
- };
- ObserverProxy.prototype.complete = function () {
- this.forEachObserver(function (observer) {
- observer.complete();
- });
- this.close();
- };
-
-
- ObserverProxy.prototype.subscribe = function (nextOrObserver, error, complete) {
- var _this = this;
- var 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: error,
- complete: complete
- };
- }
- if (observer.next === undefined) {
- observer.next = noop;
- }
- if (observer.error === undefined) {
- observer.error = noop;
- }
- if (observer.complete === undefined) {
- observer.complete = noop;
- }
- var unsub = this.unsubscribeOne.bind(this, this.observers.length);
-
-
-
- if (this.finalized) {
-
- this.task.then(function () {
- try {
- if (_this.finalError) {
- observer.error(_this.finalError);
- }
- else {
- observer.complete();
- }
- }
- catch (e) {
-
- }
- return;
- });
- }
- this.observers.push(observer);
- return unsub;
- };
-
-
- ObserverProxy.prototype.unsubscribeOne = function (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);
- }
- };
- ObserverProxy.prototype.forEachObserver = function (fn) {
- if (this.finalized) {
-
- return;
- }
-
-
- for (var i = 0; i < this.observers.length; i++) {
- this.sendOne(i, fn);
- }
- };
-
-
-
- ObserverProxy.prototype.sendOne = function (i, fn) {
- var _this = this;
-
-
- this.task.then(function () {
- if (_this.observers !== undefined && _this.observers[i] !== undefined) {
- try {
- fn(_this.observers[i]);
- }
- catch (e) {
-
-
-
- if (typeof console !== 'undefined' && console.error) {
- console.error(e);
- }
- }
- }
- });
- };
- ObserverProxy.prototype.close = function (err) {
- var _this = this;
- if (this.finalized) {
- return;
- }
- this.finalized = true;
- if (err !== undefined) {
- this.finalError = err;
- }
-
-
- this.task.then(function () {
- _this.observers = undefined;
- _this.onNoObservers = undefined;
- });
- };
- return ObserverProxy;
- }());
-
-
- function async(fn, onError) {
- return function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- Promise.resolve(true)
- .then(function () {
- fn.apply(void 0, args);
- })
- .catch(function (error) {
- if (onError) {
- onError(error);
- }
- });
- };
- }
-
- function implementsAnyMethods(obj, methods) {
- if (typeof obj !== 'object' || obj === null) {
- return false;
- }
- for (var _i = 0, methods_1 = methods; _i < methods_1.length; _i++) {
- var method = methods_1[_i];
- if (method in obj && typeof obj[method] === 'function') {
- return true;
- }
- }
- return false;
- }
- function noop() {
-
- }
-
-
-
- var validateArgCount = function (fnName, minCount, maxCount, argCount) {
- var argError;
- if (argCount < minCount) {
- argError = 'at least ' + minCount;
- }
- else if (argCount > maxCount) {
- argError = maxCount === 0 ? 'none' : 'no more than ' + maxCount;
- }
- if (argError) {
- var error = fnName +
- ' failed: Was called with ' +
- argCount +
- (argCount === 1 ? ' argument.' : ' arguments.') +
- ' Expects ' +
- argError +
- '.';
- throw new Error(error);
- }
- };
-
- function errorPrefix(fnName, argName) {
- return "".concat(fnName, " failed: ").concat(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}
- */
- var stringToByteArray = function (str) {
- var out = [];
- var p = 0;
- for (var i = 0; i < str.length; i++) {
- var c = str.charCodeAt(i);
- // Is this the lead surrogate in a surrogate pair?
- if (c >= 0xd800 && c <= 0xdbff) {
- var high = c - 0xd800; // the high 10 bits.
- i++;
- assert(i < str.length, 'Surrogate pair missing trail surrogate.');
- var 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}
- */
- var stringLength = function (str) {
- var p = 0;
- for (var i = 0; i < str.length; i++) {
- var 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
- */
- var uuidv4 = function () {
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
- var r = (Math.random() * 16) | 0, v = c === 'x' ? r : (r & 0x3) | 0x8;
- return v.toString(16);
- });
- };
-
-
-
- var DEFAULT_INTERVAL_MILLIS = 1000;
-
- var DEFAULT_BACKOFF_FACTOR = 2;
-
- var MAX_VALUE_MILLIS = 4 * 60 * 60 * 1000;
-
- var RANDOM_FACTOR = 0.5;
-
- function calculateBackoffMillis(backoffCount, intervalMillis, backoffFactor) {
- if (intervalMillis === void 0) { intervalMillis = DEFAULT_INTERVAL_MILLIS; }
- if (backoffFactor === void 0) { backoffFactor = DEFAULT_BACKOFF_FACTOR; }
-
-
-
- var currBaseValue = intervalMillis * Math.pow(backoffFactor, backoffCount);
-
-
- var 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 "".concat(i);
- }
- return i + indicator(i);
- }
- function indicator(i) {
- i = Math.abs(i);
- var cent = i % 100;
- if (cent >= 10 && cent <= 20) {
- return 'th';
- }
- var 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;
- }
- }
-
-
-
- CONSTANTS.NODE_CLIENT = true;
-
- exports.CONSTANTS = CONSTANTS;
- exports.Deferred = Deferred;
- exports.ErrorFactory = ErrorFactory;
- exports.FirebaseError = FirebaseError;
- exports.MAX_VALUE_MILLIS = MAX_VALUE_MILLIS;
- exports.RANDOM_FACTOR = RANDOM_FACTOR;
- exports.Sha1 = Sha1;
- exports.areCookiesEnabled = areCookiesEnabled;
- exports.assert = assert;
- exports.assertionError = assertionError;
- exports.async = async;
- exports.base64 = base64;
- exports.base64Decode = base64Decode;
- exports.base64Encode = base64Encode;
- exports.base64urlEncodeWithoutPadding = base64urlEncodeWithoutPadding;
- exports.calculateBackoffMillis = calculateBackoffMillis;
- exports.contains = contains;
- exports.createMockUserToken = createMockUserToken;
- exports.createSubscribe = createSubscribe;
- exports.decode = decode;
- exports.deepCopy = deepCopy;
- exports.deepEqual = deepEqual;
- exports.deepExtend = deepExtend;
- exports.errorPrefix = errorPrefix;
- exports.extractQuerystring = extractQuerystring;
- exports.getDefaultAppConfig = getDefaultAppConfig;
- exports.getDefaultEmulatorHost = getDefaultEmulatorHost;
- exports.getDefaultEmulatorHostnameAndPort = getDefaultEmulatorHostnameAndPort;
- exports.getDefaults = getDefaults;
- exports.getExperimentalSetting = getExperimentalSetting;
- exports.getGlobal = getGlobal;
- exports.getModularInstance = getModularInstance;
- exports.getUA = getUA;
- exports.isAdmin = isAdmin;
- exports.isBrowser = isBrowser;
- exports.isBrowserExtension = isBrowserExtension;
- exports.isElectron = isElectron;
- exports.isEmpty = isEmpty;
- exports.isIE = isIE;
- exports.isIndexedDBAvailable = isIndexedDBAvailable;
- exports.isMobileCordova = isMobileCordova;
- exports.isNode = isNode;
- exports.isNodeSdk = isNodeSdk;
- exports.isReactNative = isReactNative;
- exports.isSafari = isSafari;
- exports.isUWP = isUWP;
- exports.isValidFormat = isValidFormat;
- exports.isValidTimestamp = isValidTimestamp;
- exports.issuedAtTime = issuedAtTime;
- exports.jsonEval = jsonEval;
- exports.map = map;
- exports.ordinal = ordinal;
- exports.promiseWithTimeout = promiseWithTimeout;
- exports.querystring = querystring;
- exports.querystringDecode = querystringDecode;
- exports.safeGet = safeGet;
- exports.stringLength = stringLength;
- exports.stringToByteArray = stringToByteArray;
- exports.stringify = stringify;
- exports.uuidv4 = uuidv4;
- exports.validateArgCount = validateArgCount;
- exports.validateCallback = validateCallback;
- exports.validateContextObject = validateContextObject;
- exports.validateIndexedDBOpenable = validateIndexedDBOpenable;
- exports.validateNamespace = validateNamespace;
|