{"version":3,"sources":["webpack:///./node_modules/@firebase/installations/dist/index.esm.js","webpack:///./node_modules/@firebase/functions/dist/index.esm.js","webpack:///./node_modules/@firebase/logger/dist/index.esm.js","webpack:///./node_modules/@firebase/firestore/dist/esm5/bundle.js","webpack:///./node_modules/@firebase/firestore/dist/esm5/index.js","webpack:///./node_modules/@firebase/component/dist/index.esm.js"],"names":["_a","name","version","PENDING_TIMEOUT_MS","PACKAGE_VERSION","INTERNAL_AUTH_VERSION","INSTALLATIONS_API_URL","TOKEN_EXPIRATION_BUFFER","SERVICE","SERVICE_NAME","ERROR_DESCRIPTION_MAP","ERROR_FACTORY","isServerError","error","code","includes","getInstallationsEndpoint","projectId","extractAuthTokenInfoFromResponse","response","token","requestStatus","expiresIn","getExpiresInFromResponseExpiresIn","creationTime","Date","now","getErrorFromResponse","requestName","this","responseJson","errorData","label","json","sent","create","serverCode","serverMessage","message","serverStatus","status","getHeaders","apiKey","Headers","Accept","getHeadersWithAuth","appConfig","refreshToken","headers","append","getAuthorizationHeader","retryIfServerError","fn","result","responseExpiresIn","Number","replace","createInstallationRequest","fid","endpoint","body","request","responseValue","registeredInstallationEntry","_b","authVersion","appId","sdkVersion","method","JSON","stringify","fetch","ok","registrationStatus","authToken","sleep","ms","Promise","resolve","setTimeout","bufferToBase64UrlSafe","array","b64","btoa","String","fromCharCode","apply","VALID_FID_PATTERN","INVALID_FID","generateFid","fidByteArray","Uint8Array","crypto_1","self","crypto","msCrypto","getRandomValues","encode","test","b64String","substr","getKey","appName","fidChangeCallbacks","Map","fidChanged","key","callFidChangeCallbacks","broadcastFidChange","addCallback","callback","getBroadcastChannel","callbackSet","get","Set","set","add","removeCallback","delete","size","closeBroadcastChannel","e_1","callbacks","callbacks_1","callbacks_1_1","next","done","value","e_1_1","return","call","channel","postMessage","broadcastChannel","BroadcastChannel","onmessage","e","data","close","DATABASE_NAME","DATABASE_VERSION","OBJECT_STORE_NAME","dbPromise","getDbPromise","upgradeDB","oldVersion","createObjectStore","db","tx","objectStore","oldValue","transaction","put","complete","remove","update","updateFn","store","newValue","undefined","getInstallationEntry","registrationPromise","installationEntry","oldEntry","updateOrCreateInstallationEntry","entryWithPromise","triggerRegistrationIfNecessary","entry","clearTimedOutRequest","navigator","onLine","registrationPromiseWithError","reject","inProgressEntry","registrationTime","registerInstallation","waitUntilFidRegistration","trys","push","customData","updateInstallationRequest","hasInstallationRequestTimedOut","generateAuthTokenRequest","platformLoggerProvider","platformLogger","completedAuthToken","getGenerateAuthTokenEndpoint","getImmediate","optional","getPlatformInfoString","installation","refreshAuthToken","dependencies","forceRefresh","tokenPromise","isEntryRegistered","oldAuthToken","isAuthTokenValid","waitUntilAuthTokenRequest","makeAuthTokenRequestInProgressEntry","fetchAuthTokenFromServer","updateAuthTokenRequest","hasAuthTokenRequestTimedOut","updatedInstallationEntry","isAuthTokenExpired","inProgressAuthToken","requestTime","getId","catch","console","getToken","completeInstallationRegistration","deleteInstallationRequest","getDeleteEndpoint","deleteInstallation","onIdChange","extractAppConfig","app","options","getMissingValueError","configKeys","configKeys_1","configKeys_1_1","keyName","valueName","registerInstallations","instance","installationsName","INTERNAL","registerComponent","container","getProvider","installations","registerVersion","errorCodeMap","OK","CANCELLED","UNKNOWN","INVALID_ARGUMENT","DEADLINE_EXCEEDED","NOT_FOUND","ALREADY_EXISTS","PERMISSION_DENIED","UNAUTHENTICATED","RESOURCE_EXHAUSTED","FAILED_PRECONDITION","ABORTED","OUT_OF_RANGE","UNIMPLEMENTED","UNAVAILABLE","DATA_LOSS","HttpsErrorImpl","_super","details","_this","Object","setPrototypeOf","prototype","Error","codeForHTTPStatus","_errorForResponse","bodyJSON","serializer","description","errorJSON","status_1","decode","ContextProvider","authProvider","messagingProvider","auth","messaging","then","getAuthToken","accessToken","getInstanceIdToken","Notification","permission","getContext","instanceIdToken","LONG_TYPE","UNSIGNED_LONG_TYPE","mapValues","o","f","hasOwnProperty","Serializer","valueOf","isFinite","toString","toISOString","Array","isArray","map","x","isNaN","failAfter","millis","timer","promise","_","Service","app_","appCheckProvider","regionOrCustomDomain_","fetchImpl","emulatorOrigin","deleteService","contextProvider","cancelAllRequests","url","URL","customDomain","origin","region","defineProperty","enumerable","configurable","_url","origin_1","useEmulator","host","port","useFunctionsEmulator","httpsCallable","postJSON","appCheckToken","getAppCheckToken","appCheck","context","timeout","failAfterPromise","responseData","decodedData","race","clearTimeoutWrapper","clearTimeout","FUNCTIONS_TYPE","registerFunctions","namespaceExports","Functions","factory","regionOrCustomDomain","instanceIdentifier","setServiceProps","setMultipleInstances","bind","__spreadArrays","s","i","il","arguments","length","r","k","a","j","jl","LogLevel","instances","levelStringToEnum","DEBUG","VERBOSE","INFO","WARN","ERROR","SILENT","defaultLogLevel","ConsoleMethod","defaultLogHandler","logType","args","_i","logLevel","Logger","_logLevel","_logHandler","_userLogHandler","val","TypeError","setLogLevel","debug","log","info","warn","level","forEach","inst","setUserLogHandler","logCallback","_loop_1","customLogLevel","userLogHandler","arg","ignored","filter","join","toLowerCase","type","instances_1","t","loadBundle","namedQuery","C","Firestore","GeoPoint","Timestamp","Blob","Transaction","WriteBatch","DocumentReference","DocumentSnapshot","Query","QueryDocumentSnapshot","QuerySnapshot","CollectionReference","FieldPath","FieldValue","CACHE_SIZE_UNLIMITED","I","assign","Component","instanceFactory","multipleInstances","serviceProps","instantiationMode","onInstanceCreated","setInstantiationMode","mode","props","setInstanceCreatedCallback","DEFAULT_ENTRY_NAME","Provider","component","instancesDeferred","instancesOptions","onInitCallbacks","identifier","normalizedIdentifier","normalizeInstanceIdentifier","has","deferred","isInitialized","shouldAutoInitialize","getOrInitializeService","getComponent","setComponent","isComponentEager","entries","_c","_d","instanceDeferred","clearInstance","services","from","values","all","service","_delete","isComponentSet","getOptions","initialize","opts","e_2","_e","normalizedDeferredIdentifier","e_2_1","onInit","existingCallbacks","existingInstance","invokeOnInitCallbacks","e_3","e_3_1","normalizeIdentifierForFactory","ComponentContainer","providers","addComponent","provider","addOrOverwriteComponent","getProviders"],"mappings":"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AUnC,IAAIvb,GACnB,OAAO4B,KAAK8b,UAAU1W,IAAIhH,GAG9B,IAAI4d,EAAW,IAAI7C,EAAS/a,EAAM4B,MAElC,OADAA,KAAK8b,UAAUxW,IAAIlH,EAAM4d,GAClBA,GAEXH,EAAmBzN,UAAU8N,aAAe,WACxC,OAAO5L,MAAMmK,KAAKza,KAAK8b,UAAUpB,WAE9BmB,EAhD4B","file":"js/chunk-vendors~1fb195ae.a7b86a5d.js","sourcesContent":["import firebase from '@firebase/app';\nimport { Component } from '@firebase/component';\nimport { __awaiter, __generator, __spreadArray, __read, __values, __assign } from 'tslib';\nimport { ErrorFactory, FirebaseError } from '@firebase/util';\nimport { openDb } from 'idb';\n\nvar name = \"@firebase/installations\";\nvar version = \"0.4.32\";\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nvar PENDING_TIMEOUT_MS = 10000;\r\nvar PACKAGE_VERSION = \"w:\" + version;\r\nvar INTERNAL_AUTH_VERSION = 'FIS_v2';\r\nvar INSTALLATIONS_API_URL = 'https://firebaseinstallations.googleapis.com/v1';\r\nvar TOKEN_EXPIRATION_BUFFER = 60 * 60 * 1000; // One hour\r\nvar SERVICE = 'installations';\r\nvar SERVICE_NAME = 'Installations';\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nvar _a;\r\nvar ERROR_DESCRIPTION_MAP = (_a = {},\r\n _a[\"missing-app-config-values\" /* MISSING_APP_CONFIG_VALUES */] = 'Missing App configuration value: \"{$valueName}\"',\r\n _a[\"not-registered\" /* NOT_REGISTERED */] = 'Firebase Installation is not registered.',\r\n _a[\"installation-not-found\" /* INSTALLATION_NOT_FOUND */] = 'Firebase Installation not found.',\r\n _a[\"request-failed\" /* REQUEST_FAILED */] = '{$requestName} request failed with error \"{$serverCode} {$serverStatus}: {$serverMessage}\"',\r\n _a[\"app-offline\" /* APP_OFFLINE */] = 'Could not process request. Application offline.',\r\n _a[\"delete-pending-registration\" /* DELETE_PENDING_REGISTRATION */] = \"Can't delete installation while there is a pending registration request.\",\r\n _a);\r\nvar ERROR_FACTORY = new ErrorFactory(SERVICE, SERVICE_NAME, ERROR_DESCRIPTION_MAP);\r\n/** Returns true if error is a FirebaseError that is based on an error from the server. */\r\nfunction isServerError(error) {\r\n return (error instanceof FirebaseError &&\r\n error.code.includes(\"request-failed\" /* REQUEST_FAILED */));\r\n}\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nfunction getInstallationsEndpoint(_a) {\r\n var projectId = _a.projectId;\r\n return INSTALLATIONS_API_URL + \"/projects/\" + projectId + \"/installations\";\r\n}\r\nfunction extractAuthTokenInfoFromResponse(response) {\r\n return {\r\n token: response.token,\r\n requestStatus: 2 /* COMPLETED */,\r\n expiresIn: getExpiresInFromResponseExpiresIn(response.expiresIn),\r\n creationTime: Date.now()\r\n };\r\n}\r\nfunction getErrorFromResponse(requestName, response) {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var responseJson, errorData;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0: return [4 /*yield*/, response.json()];\r\n case 1:\r\n responseJson = _a.sent();\r\n errorData = responseJson.error;\r\n return [2 /*return*/, ERROR_FACTORY.create(\"request-failed\" /* REQUEST_FAILED */, {\r\n requestName: requestName,\r\n serverCode: errorData.code,\r\n serverMessage: errorData.message,\r\n serverStatus: errorData.status\r\n })];\r\n }\r\n });\r\n });\r\n}\r\nfunction getHeaders(_a) {\r\n var apiKey = _a.apiKey;\r\n return new Headers({\r\n 'Content-Type': 'application/json',\r\n Accept: 'application/json',\r\n 'x-goog-api-key': apiKey\r\n });\r\n}\r\nfunction getHeadersWithAuth(appConfig, _a) {\r\n var refreshToken = _a.refreshToken;\r\n var headers = getHeaders(appConfig);\r\n headers.append('Authorization', getAuthorizationHeader(refreshToken));\r\n return headers;\r\n}\r\n/**\r\n * Calls the passed in fetch wrapper and returns the response.\r\n * If the returned response has a status of 5xx, re-runs the function once and\r\n * returns the response.\r\n */\r\nfunction retryIfServerError(fn) {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var result;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0: return [4 /*yield*/, fn()];\r\n case 1:\r\n result = _a.sent();\r\n if (result.status >= 500 && result.status < 600) {\r\n // Internal Server Error. Retry request.\r\n return [2 /*return*/, fn()];\r\n }\r\n return [2 /*return*/, result];\r\n }\r\n });\r\n });\r\n}\r\nfunction getExpiresInFromResponseExpiresIn(responseExpiresIn) {\r\n // This works because the server will never respond with fractions of a second.\r\n return Number(responseExpiresIn.replace('s', '000'));\r\n}\r\nfunction getAuthorizationHeader(refreshToken) {\r\n return INTERNAL_AUTH_VERSION + \" \" + refreshToken;\r\n}\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nfunction createInstallationRequest(appConfig, _a) {\r\n var fid = _a.fid;\r\n return __awaiter(this, void 0, void 0, function () {\r\n var endpoint, headers, body, request, response, responseValue, registeredInstallationEntry;\r\n return __generator(this, function (_b) {\r\n switch (_b.label) {\r\n case 0:\r\n endpoint = getInstallationsEndpoint(appConfig);\r\n headers = getHeaders(appConfig);\r\n body = {\r\n fid: fid,\r\n authVersion: INTERNAL_AUTH_VERSION,\r\n appId: appConfig.appId,\r\n sdkVersion: PACKAGE_VERSION\r\n };\r\n request = {\r\n method: 'POST',\r\n headers: headers,\r\n body: JSON.stringify(body)\r\n };\r\n return [4 /*yield*/, retryIfServerError(function () { return fetch(endpoint, request); })];\r\n case 1:\r\n response = _b.sent();\r\n if (!response.ok) return [3 /*break*/, 3];\r\n return [4 /*yield*/, response.json()];\r\n case 2:\r\n responseValue = _b.sent();\r\n registeredInstallationEntry = {\r\n fid: responseValue.fid || fid,\r\n registrationStatus: 2 /* COMPLETED */,\r\n refreshToken: responseValue.refreshToken,\r\n authToken: extractAuthTokenInfoFromResponse(responseValue.authToken)\r\n };\r\n return [2 /*return*/, registeredInstallationEntry];\r\n case 3: return [4 /*yield*/, getErrorFromResponse('Create Installation', response)];\r\n case 4: throw _b.sent();\r\n }\r\n });\r\n });\r\n}\n\n/**\r\n * @license\r\n * Copyright 2020 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n/** Returns a promise that resolves after given time passes. */\r\nfunction sleep(ms) {\r\n return new Promise(function (resolve) {\r\n setTimeout(resolve, ms);\r\n });\r\n}\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nfunction bufferToBase64UrlSafe(array) {\r\n var b64 = btoa(String.fromCharCode.apply(String, __spreadArray([], __read(array))));\r\n return b64.replace(/\\+/g, '-').replace(/\\//g, '_');\r\n}\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nvar VALID_FID_PATTERN = /^[cdef][\\w-]{21}$/;\r\nvar INVALID_FID = '';\r\n/**\r\n * Generates a new FID using random values from Web Crypto API.\r\n * Returns an empty string if FID generation fails for any reason.\r\n */\r\nfunction generateFid() {\r\n try {\r\n // A valid FID has exactly 22 base64 characters, which is 132 bits, or 16.5\r\n // bytes. our implementation generates a 17 byte array instead.\r\n var fidByteArray = new Uint8Array(17);\r\n var crypto_1 = self.crypto || self.msCrypto;\r\n crypto_1.getRandomValues(fidByteArray);\r\n // Replace the first 4 random bits with the constant FID header of 0b0111.\r\n fidByteArray[0] = 112 + (fidByteArray[0] % 16);\r\n var fid = encode(fidByteArray);\r\n return VALID_FID_PATTERN.test(fid) ? fid : INVALID_FID;\r\n }\r\n catch (_a) {\r\n // FID generation errored\r\n return INVALID_FID;\r\n }\r\n}\r\n/** Converts a FID Uint8Array to a base64 string representation. */\r\nfunction encode(fidByteArray) {\r\n var b64String = bufferToBase64UrlSafe(fidByteArray);\r\n // Remove the 23rd character that was added because of the extra 4 bits at the\r\n // end of our 17 byte array, and the '=' padding.\r\n return b64String.substr(0, 22);\r\n}\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n/** Returns a string key that can be used to identify the app. */\r\nfunction getKey(appConfig) {\r\n return appConfig.appName + \"!\" + appConfig.appId;\r\n}\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nvar fidChangeCallbacks = new Map();\r\n/**\r\n * Calls the onIdChange callbacks with the new FID value, and broadcasts the\r\n * change to other tabs.\r\n */\r\nfunction fidChanged(appConfig, fid) {\r\n var key = getKey(appConfig);\r\n callFidChangeCallbacks(key, fid);\r\n broadcastFidChange(key, fid);\r\n}\r\nfunction addCallback(appConfig, callback) {\r\n // Open the broadcast channel if it's not already open,\r\n // to be able to listen to change events from other tabs.\r\n getBroadcastChannel();\r\n var key = getKey(appConfig);\r\n var callbackSet = fidChangeCallbacks.get(key);\r\n if (!callbackSet) {\r\n callbackSet = new Set();\r\n fidChangeCallbacks.set(key, callbackSet);\r\n }\r\n callbackSet.add(callback);\r\n}\r\nfunction removeCallback(appConfig, callback) {\r\n var key = getKey(appConfig);\r\n var callbackSet = fidChangeCallbacks.get(key);\r\n if (!callbackSet) {\r\n return;\r\n }\r\n callbackSet.delete(callback);\r\n if (callbackSet.size === 0) {\r\n fidChangeCallbacks.delete(key);\r\n }\r\n // Close broadcast channel if there are no more callbacks.\r\n closeBroadcastChannel();\r\n}\r\nfunction callFidChangeCallbacks(key, fid) {\r\n var e_1, _a;\r\n var callbacks = fidChangeCallbacks.get(key);\r\n if (!callbacks) {\r\n return;\r\n }\r\n try {\r\n for (var callbacks_1 = __values(callbacks), callbacks_1_1 = callbacks_1.next(); !callbacks_1_1.done; callbacks_1_1 = callbacks_1.next()) {\r\n var callback = callbacks_1_1.value;\r\n callback(fid);\r\n }\r\n }\r\n catch (e_1_1) { e_1 = { error: e_1_1 }; }\r\n finally {\r\n try {\r\n if (callbacks_1_1 && !callbacks_1_1.done && (_a = callbacks_1.return)) _a.call(callbacks_1);\r\n }\r\n finally { if (e_1) throw e_1.error; }\r\n }\r\n}\r\nfunction broadcastFidChange(key, fid) {\r\n var channel = getBroadcastChannel();\r\n if (channel) {\r\n channel.postMessage({ key: key, fid: fid });\r\n }\r\n closeBroadcastChannel();\r\n}\r\nvar broadcastChannel = null;\r\n/** Opens and returns a BroadcastChannel if it is supported by the browser. */\r\nfunction getBroadcastChannel() {\r\n if (!broadcastChannel && 'BroadcastChannel' in self) {\r\n broadcastChannel = new BroadcastChannel('[Firebase] FID Change');\r\n broadcastChannel.onmessage = function (e) {\r\n callFidChangeCallbacks(e.data.key, e.data.fid);\r\n };\r\n }\r\n return broadcastChannel;\r\n}\r\nfunction closeBroadcastChannel() {\r\n if (fidChangeCallbacks.size === 0 && broadcastChannel) {\r\n broadcastChannel.close();\r\n broadcastChannel = null;\r\n }\r\n}\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nvar DATABASE_NAME = 'firebase-installations-database';\r\nvar DATABASE_VERSION = 1;\r\nvar OBJECT_STORE_NAME = 'firebase-installations-store';\r\nvar dbPromise = null;\r\nfunction getDbPromise() {\r\n if (!dbPromise) {\r\n dbPromise = openDb(DATABASE_NAME, DATABASE_VERSION, function (upgradeDB) {\r\n // We don't use 'break' in this switch statement, the fall-through\r\n // behavior is what we want, because if there are multiple versions between\r\n // the old version and the current version, we want ALL the migrations\r\n // that correspond to those versions to run, not only the last one.\r\n // eslint-disable-next-line default-case\r\n switch (upgradeDB.oldVersion) {\r\n case 0:\r\n upgradeDB.createObjectStore(OBJECT_STORE_NAME);\r\n }\r\n });\r\n }\r\n return dbPromise;\r\n}\r\n/** Assigns or overwrites the record for the given key with the given value. */\r\nfunction set(appConfig, value) {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var key, db, tx, objectStore, oldValue;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n key = getKey(appConfig);\r\n return [4 /*yield*/, getDbPromise()];\r\n case 1:\r\n db = _a.sent();\r\n tx = db.transaction(OBJECT_STORE_NAME, 'readwrite');\r\n objectStore = tx.objectStore(OBJECT_STORE_NAME);\r\n return [4 /*yield*/, objectStore.get(key)];\r\n case 2:\r\n oldValue = _a.sent();\r\n return [4 /*yield*/, objectStore.put(value, key)];\r\n case 3:\r\n _a.sent();\r\n return [4 /*yield*/, tx.complete];\r\n case 4:\r\n _a.sent();\r\n if (!oldValue || oldValue.fid !== value.fid) {\r\n fidChanged(appConfig, value.fid);\r\n }\r\n return [2 /*return*/, value];\r\n }\r\n });\r\n });\r\n}\r\n/** Removes record(s) from the objectStore that match the given key. */\r\nfunction remove(appConfig) {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var key, db, tx;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n key = getKey(appConfig);\r\n return [4 /*yield*/, getDbPromise()];\r\n case 1:\r\n db = _a.sent();\r\n tx = db.transaction(OBJECT_STORE_NAME, 'readwrite');\r\n return [4 /*yield*/, tx.objectStore(OBJECT_STORE_NAME).delete(key)];\r\n case 2:\r\n _a.sent();\r\n return [4 /*yield*/, tx.complete];\r\n case 3:\r\n _a.sent();\r\n return [2 /*return*/];\r\n }\r\n });\r\n });\r\n}\r\n/**\r\n * Atomically updates a record with the result of updateFn, which gets\r\n * called with the current value. If newValue is undefined, the record is\r\n * deleted instead.\r\n * @return Updated value\r\n */\r\nfunction update(appConfig, updateFn) {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var key, db, tx, store, oldValue, newValue;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n key = getKey(appConfig);\r\n return [4 /*yield*/, getDbPromise()];\r\n case 1:\r\n db = _a.sent();\r\n tx = db.transaction(OBJECT_STORE_NAME, 'readwrite');\r\n store = tx.objectStore(OBJECT_STORE_NAME);\r\n return [4 /*yield*/, store.get(key)];\r\n case 2:\r\n oldValue = _a.sent();\r\n newValue = updateFn(oldValue);\r\n if (!(newValue === undefined)) return [3 /*break*/, 4];\r\n return [4 /*yield*/, store.delete(key)];\r\n case 3:\r\n _a.sent();\r\n return [3 /*break*/, 6];\r\n case 4: return [4 /*yield*/, store.put(newValue, key)];\r\n case 5:\r\n _a.sent();\r\n _a.label = 6;\r\n case 6: return [4 /*yield*/, tx.complete];\r\n case 7:\r\n _a.sent();\r\n if (newValue && (!oldValue || oldValue.fid !== newValue.fid)) {\r\n fidChanged(appConfig, newValue.fid);\r\n }\r\n return [2 /*return*/, newValue];\r\n }\r\n });\r\n });\r\n}\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n/**\r\n * Updates and returns the InstallationEntry from the database.\r\n * Also triggers a registration request if it is necessary and possible.\r\n */\r\nfunction getInstallationEntry(appConfig) {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var registrationPromise, installationEntry;\r\n var _a;\r\n return __generator(this, function (_b) {\r\n switch (_b.label) {\r\n case 0: return [4 /*yield*/, update(appConfig, function (oldEntry) {\r\n var installationEntry = updateOrCreateInstallationEntry(oldEntry);\r\n var entryWithPromise = triggerRegistrationIfNecessary(appConfig, installationEntry);\r\n registrationPromise = entryWithPromise.registrationPromise;\r\n return entryWithPromise.installationEntry;\r\n })];\r\n case 1:\r\n installationEntry = _b.sent();\r\n if (!(installationEntry.fid === INVALID_FID)) return [3 /*break*/, 3];\r\n _a = {};\r\n return [4 /*yield*/, registrationPromise];\r\n case 2: \r\n // FID generation failed. Waiting for the FID from the server.\r\n return [2 /*return*/, (_a.installationEntry = _b.sent(), _a)];\r\n case 3: return [2 /*return*/, {\r\n installationEntry: installationEntry,\r\n registrationPromise: registrationPromise\r\n }];\r\n }\r\n });\r\n });\r\n}\r\n/**\r\n * Creates a new Installation Entry if one does not exist.\r\n * Also clears timed out pending requests.\r\n */\r\nfunction updateOrCreateInstallationEntry(oldEntry) {\r\n var entry = oldEntry || {\r\n fid: generateFid(),\r\n registrationStatus: 0 /* NOT_STARTED */\r\n };\r\n return clearTimedOutRequest(entry);\r\n}\r\n/**\r\n * If the Firebase Installation is not registered yet, this will trigger the\r\n * registration and return an InProgressInstallationEntry.\r\n *\r\n * If registrationPromise does not exist, the installationEntry is guaranteed\r\n * to be registered.\r\n */\r\nfunction triggerRegistrationIfNecessary(appConfig, installationEntry) {\r\n if (installationEntry.registrationStatus === 0 /* NOT_STARTED */) {\r\n if (!navigator.onLine) {\r\n // Registration required but app is offline.\r\n var registrationPromiseWithError = Promise.reject(ERROR_FACTORY.create(\"app-offline\" /* APP_OFFLINE */));\r\n return {\r\n installationEntry: installationEntry,\r\n registrationPromise: registrationPromiseWithError\r\n };\r\n }\r\n // Try registering. Change status to IN_PROGRESS.\r\n var inProgressEntry = {\r\n fid: installationEntry.fid,\r\n registrationStatus: 1 /* IN_PROGRESS */,\r\n registrationTime: Date.now()\r\n };\r\n var registrationPromise = registerInstallation(appConfig, inProgressEntry);\r\n return { installationEntry: inProgressEntry, registrationPromise: registrationPromise };\r\n }\r\n else if (installationEntry.registrationStatus === 1 /* IN_PROGRESS */) {\r\n return {\r\n installationEntry: installationEntry,\r\n registrationPromise: waitUntilFidRegistration(appConfig)\r\n };\r\n }\r\n else {\r\n return { installationEntry: installationEntry };\r\n }\r\n}\r\n/** This will be executed only once for each new Firebase Installation. */\r\nfunction registerInstallation(appConfig, installationEntry) {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var registeredInstallationEntry, e_1;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n _a.trys.push([0, 2, , 7]);\r\n return [4 /*yield*/, createInstallationRequest(appConfig, installationEntry)];\r\n case 1:\r\n registeredInstallationEntry = _a.sent();\r\n return [2 /*return*/, set(appConfig, registeredInstallationEntry)];\r\n case 2:\r\n e_1 = _a.sent();\r\n if (!(isServerError(e_1) && e_1.customData.serverCode === 409)) return [3 /*break*/, 4];\r\n // Server returned a \"FID can not be used\" error.\r\n // Generate a new ID next time.\r\n return [4 /*yield*/, remove(appConfig)];\r\n case 3:\r\n // Server returned a \"FID can not be used\" error.\r\n // Generate a new ID next time.\r\n _a.sent();\r\n return [3 /*break*/, 6];\r\n case 4: \r\n // Registration failed. Set FID as not registered.\r\n return [4 /*yield*/, set(appConfig, {\r\n fid: installationEntry.fid,\r\n registrationStatus: 0 /* NOT_STARTED */\r\n })];\r\n case 5:\r\n // Registration failed. Set FID as not registered.\r\n _a.sent();\r\n _a.label = 6;\r\n case 6: throw e_1;\r\n case 7: return [2 /*return*/];\r\n }\r\n });\r\n });\r\n}\r\n/** Call if FID registration is pending in another request. */\r\nfunction waitUntilFidRegistration(appConfig) {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var entry, _a, installationEntry, registrationPromise;\r\n return __generator(this, function (_b) {\r\n switch (_b.label) {\r\n case 0: return [4 /*yield*/, updateInstallationRequest(appConfig)];\r\n case 1:\r\n entry = _b.sent();\r\n _b.label = 2;\r\n case 2:\r\n if (!(entry.registrationStatus === 1 /* IN_PROGRESS */)) return [3 /*break*/, 5];\r\n // createInstallation request still in progress.\r\n return [4 /*yield*/, sleep(100)];\r\n case 3:\r\n // createInstallation request still in progress.\r\n _b.sent();\r\n return [4 /*yield*/, updateInstallationRequest(appConfig)];\r\n case 4:\r\n entry = _b.sent();\r\n return [3 /*break*/, 2];\r\n case 5:\r\n if (!(entry.registrationStatus === 0 /* NOT_STARTED */)) return [3 /*break*/, 7];\r\n return [4 /*yield*/, getInstallationEntry(appConfig)];\r\n case 6:\r\n _a = _b.sent(), installationEntry = _a.installationEntry, registrationPromise = _a.registrationPromise;\r\n if (registrationPromise) {\r\n return [2 /*return*/, registrationPromise];\r\n }\r\n else {\r\n // if there is no registrationPromise, entry is registered.\r\n return [2 /*return*/, installationEntry];\r\n }\r\n case 7: return [2 /*return*/, entry];\r\n }\r\n });\r\n });\r\n}\r\n/**\r\n * Called only if there is a CreateInstallation request in progress.\r\n *\r\n * Updates the InstallationEntry in the DB based on the status of the\r\n * CreateInstallation request.\r\n *\r\n * Returns the updated InstallationEntry.\r\n */\r\nfunction updateInstallationRequest(appConfig) {\r\n return update(appConfig, function (oldEntry) {\r\n if (!oldEntry) {\r\n throw ERROR_FACTORY.create(\"installation-not-found\" /* INSTALLATION_NOT_FOUND */);\r\n }\r\n return clearTimedOutRequest(oldEntry);\r\n });\r\n}\r\nfunction clearTimedOutRequest(entry) {\r\n if (hasInstallationRequestTimedOut(entry)) {\r\n return {\r\n fid: entry.fid,\r\n registrationStatus: 0 /* NOT_STARTED */\r\n };\r\n }\r\n return entry;\r\n}\r\nfunction hasInstallationRequestTimedOut(installationEntry) {\r\n return (installationEntry.registrationStatus === 1 /* IN_PROGRESS */ &&\r\n installationEntry.registrationTime + PENDING_TIMEOUT_MS < Date.now());\r\n}\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nfunction generateAuthTokenRequest(_a, installationEntry) {\r\n var appConfig = _a.appConfig, platformLoggerProvider = _a.platformLoggerProvider;\r\n return __awaiter(this, void 0, void 0, function () {\r\n var endpoint, headers, platformLogger, body, request, response, responseValue, completedAuthToken;\r\n return __generator(this, function (_b) {\r\n switch (_b.label) {\r\n case 0:\r\n endpoint = getGenerateAuthTokenEndpoint(appConfig, installationEntry);\r\n headers = getHeadersWithAuth(appConfig, installationEntry);\r\n platformLogger = platformLoggerProvider.getImmediate({\r\n optional: true\r\n });\r\n if (platformLogger) {\r\n headers.append('x-firebase-client', platformLogger.getPlatformInfoString());\r\n }\r\n body = {\r\n installation: {\r\n sdkVersion: PACKAGE_VERSION\r\n }\r\n };\r\n request = {\r\n method: 'POST',\r\n headers: headers,\r\n body: JSON.stringify(body)\r\n };\r\n return [4 /*yield*/, retryIfServerError(function () { return fetch(endpoint, request); })];\r\n case 1:\r\n response = _b.sent();\r\n if (!response.ok) return [3 /*break*/, 3];\r\n return [4 /*yield*/, response.json()];\r\n case 2:\r\n responseValue = _b.sent();\r\n completedAuthToken = extractAuthTokenInfoFromResponse(responseValue);\r\n return [2 /*return*/, completedAuthToken];\r\n case 3: return [4 /*yield*/, getErrorFromResponse('Generate Auth Token', response)];\r\n case 4: throw _b.sent();\r\n }\r\n });\r\n });\r\n}\r\nfunction getGenerateAuthTokenEndpoint(appConfig, _a) {\r\n var fid = _a.fid;\r\n return getInstallationsEndpoint(appConfig) + \"/\" + fid + \"/authTokens:generate\";\r\n}\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n/**\r\n * Returns a valid authentication token for the installation. Generates a new\r\n * token if one doesn't exist, is expired or about to expire.\r\n *\r\n * Should only be called if the Firebase Installation is registered.\r\n */\r\nfunction refreshAuthToken(dependencies, forceRefresh) {\r\n if (forceRefresh === void 0) { forceRefresh = false; }\r\n return __awaiter(this, void 0, void 0, function () {\r\n var tokenPromise, entry, authToken, _a;\r\n return __generator(this, function (_b) {\r\n switch (_b.label) {\r\n case 0: return [4 /*yield*/, update(dependencies.appConfig, function (oldEntry) {\r\n if (!isEntryRegistered(oldEntry)) {\r\n throw ERROR_FACTORY.create(\"not-registered\" /* NOT_REGISTERED */);\r\n }\r\n var oldAuthToken = oldEntry.authToken;\r\n if (!forceRefresh && isAuthTokenValid(oldAuthToken)) {\r\n // There is a valid token in the DB.\r\n return oldEntry;\r\n }\r\n else if (oldAuthToken.requestStatus === 1 /* IN_PROGRESS */) {\r\n // There already is a token request in progress.\r\n tokenPromise = waitUntilAuthTokenRequest(dependencies, forceRefresh);\r\n return oldEntry;\r\n }\r\n else {\r\n // No token or token expired.\r\n if (!navigator.onLine) {\r\n throw ERROR_FACTORY.create(\"app-offline\" /* APP_OFFLINE */);\r\n }\r\n var inProgressEntry = makeAuthTokenRequestInProgressEntry(oldEntry);\r\n tokenPromise = fetchAuthTokenFromServer(dependencies, inProgressEntry);\r\n return inProgressEntry;\r\n }\r\n })];\r\n case 1:\r\n entry = _b.sent();\r\n if (!tokenPromise) return [3 /*break*/, 3];\r\n return [4 /*yield*/, tokenPromise];\r\n case 2:\r\n _a = _b.sent();\r\n return [3 /*break*/, 4];\r\n case 3:\r\n _a = entry.authToken;\r\n _b.label = 4;\r\n case 4:\r\n authToken = _a;\r\n return [2 /*return*/, authToken];\r\n }\r\n });\r\n });\r\n}\r\n/**\r\n * Call only if FID is registered and Auth Token request is in progress.\r\n *\r\n * Waits until the current pending request finishes. If the request times out,\r\n * tries once in this thread as well.\r\n */\r\nfunction waitUntilAuthTokenRequest(dependencies, forceRefresh) {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var entry, authToken;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0: return [4 /*yield*/, updateAuthTokenRequest(dependencies.appConfig)];\r\n case 1:\r\n entry = _a.sent();\r\n _a.label = 2;\r\n case 2:\r\n if (!(entry.authToken.requestStatus === 1 /* IN_PROGRESS */)) return [3 /*break*/, 5];\r\n // generateAuthToken still in progress.\r\n return [4 /*yield*/, sleep(100)];\r\n case 3:\r\n // generateAuthToken still in progress.\r\n _a.sent();\r\n return [4 /*yield*/, updateAuthTokenRequest(dependencies.appConfig)];\r\n case 4:\r\n entry = _a.sent();\r\n return [3 /*break*/, 2];\r\n case 5:\r\n authToken = entry.authToken;\r\n if (authToken.requestStatus === 0 /* NOT_STARTED */) {\r\n // The request timed out or failed in a different call. Try again.\r\n return [2 /*return*/, refreshAuthToken(dependencies, forceRefresh)];\r\n }\r\n else {\r\n return [2 /*return*/, authToken];\r\n }\r\n }\r\n });\r\n });\r\n}\r\n/**\r\n * Called only if there is a GenerateAuthToken request in progress.\r\n *\r\n * Updates the InstallationEntry in the DB based on the status of the\r\n * GenerateAuthToken request.\r\n *\r\n * Returns the updated InstallationEntry.\r\n */\r\nfunction updateAuthTokenRequest(appConfig) {\r\n return update(appConfig, function (oldEntry) {\r\n if (!isEntryRegistered(oldEntry)) {\r\n throw ERROR_FACTORY.create(\"not-registered\" /* NOT_REGISTERED */);\r\n }\r\n var oldAuthToken = oldEntry.authToken;\r\n if (hasAuthTokenRequestTimedOut(oldAuthToken)) {\r\n return __assign(__assign({}, oldEntry), { authToken: { requestStatus: 0 /* NOT_STARTED */ } });\r\n }\r\n return oldEntry;\r\n });\r\n}\r\nfunction fetchAuthTokenFromServer(dependencies, installationEntry) {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var authToken, updatedInstallationEntry, e_1, updatedInstallationEntry;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n _a.trys.push([0, 3, , 8]);\r\n return [4 /*yield*/, generateAuthTokenRequest(dependencies, installationEntry)];\r\n case 1:\r\n authToken = _a.sent();\r\n updatedInstallationEntry = __assign(__assign({}, installationEntry), { authToken: authToken });\r\n return [4 /*yield*/, set(dependencies.appConfig, updatedInstallationEntry)];\r\n case 2:\r\n _a.sent();\r\n return [2 /*return*/, authToken];\r\n case 3:\r\n e_1 = _a.sent();\r\n if (!(isServerError(e_1) &&\r\n (e_1.customData.serverCode === 401 || e_1.customData.serverCode === 404))) return [3 /*break*/, 5];\r\n // Server returned a \"FID not found\" or a \"Invalid authentication\" error.\r\n // Generate a new ID next time.\r\n return [4 /*yield*/, remove(dependencies.appConfig)];\r\n case 4:\r\n // Server returned a \"FID not found\" or a \"Invalid authentication\" error.\r\n // Generate a new ID next time.\r\n _a.sent();\r\n return [3 /*break*/, 7];\r\n case 5:\r\n updatedInstallationEntry = __assign(__assign({}, installationEntry), { authToken: { requestStatus: 0 /* NOT_STARTED */ } });\r\n return [4 /*yield*/, set(dependencies.appConfig, updatedInstallationEntry)];\r\n case 6:\r\n _a.sent();\r\n _a.label = 7;\r\n case 7: throw e_1;\r\n case 8: return [2 /*return*/];\r\n }\r\n });\r\n });\r\n}\r\nfunction isEntryRegistered(installationEntry) {\r\n return (installationEntry !== undefined &&\r\n installationEntry.registrationStatus === 2 /* COMPLETED */);\r\n}\r\nfunction isAuthTokenValid(authToken) {\r\n return (authToken.requestStatus === 2 /* COMPLETED */ &&\r\n !isAuthTokenExpired(authToken));\r\n}\r\nfunction isAuthTokenExpired(authToken) {\r\n var now = Date.now();\r\n return (now < authToken.creationTime ||\r\n authToken.creationTime + authToken.expiresIn < now + TOKEN_EXPIRATION_BUFFER);\r\n}\r\n/** Returns an updated InstallationEntry with an InProgressAuthToken. */\r\nfunction makeAuthTokenRequestInProgressEntry(oldEntry) {\r\n var inProgressAuthToken = {\r\n requestStatus: 1 /* IN_PROGRESS */,\r\n requestTime: Date.now()\r\n };\r\n return __assign(__assign({}, oldEntry), { authToken: inProgressAuthToken });\r\n}\r\nfunction hasAuthTokenRequestTimedOut(authToken) {\r\n return (authToken.requestStatus === 1 /* IN_PROGRESS */ &&\r\n authToken.requestTime + PENDING_TIMEOUT_MS < Date.now());\r\n}\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nfunction getId(dependencies) {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var _a, installationEntry, registrationPromise;\r\n return __generator(this, function (_b) {\r\n switch (_b.label) {\r\n case 0: return [4 /*yield*/, getInstallationEntry(dependencies.appConfig)];\r\n case 1:\r\n _a = _b.sent(), installationEntry = _a.installationEntry, registrationPromise = _a.registrationPromise;\r\n if (registrationPromise) {\r\n registrationPromise.catch(console.error);\r\n }\r\n else {\r\n // If the installation is already registered, update the authentication\r\n // token if needed.\r\n refreshAuthToken(dependencies).catch(console.error);\r\n }\r\n return [2 /*return*/, installationEntry.fid];\r\n }\r\n });\r\n });\r\n}\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nfunction getToken(dependencies, forceRefresh) {\r\n if (forceRefresh === void 0) { forceRefresh = false; }\r\n return __awaiter(this, void 0, void 0, function () {\r\n var authToken;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0: return [4 /*yield*/, completeInstallationRegistration(dependencies.appConfig)];\r\n case 1:\r\n _a.sent();\r\n return [4 /*yield*/, refreshAuthToken(dependencies, forceRefresh)];\r\n case 2:\r\n authToken = _a.sent();\r\n return [2 /*return*/, authToken.token];\r\n }\r\n });\r\n });\r\n}\r\nfunction completeInstallationRegistration(appConfig) {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var registrationPromise;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0: return [4 /*yield*/, getInstallationEntry(appConfig)];\r\n case 1:\r\n registrationPromise = (_a.sent()).registrationPromise;\r\n if (!registrationPromise) return [3 /*break*/, 3];\r\n // A createInstallation request is in progress. Wait until it finishes.\r\n return [4 /*yield*/, registrationPromise];\r\n case 2:\r\n // A createInstallation request is in progress. Wait until it finishes.\r\n _a.sent();\r\n _a.label = 3;\r\n case 3: return [2 /*return*/];\r\n }\r\n });\r\n });\r\n}\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nfunction deleteInstallationRequest(appConfig, installationEntry) {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var endpoint, headers, request, response;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n endpoint = getDeleteEndpoint(appConfig, installationEntry);\r\n headers = getHeadersWithAuth(appConfig, installationEntry);\r\n request = {\r\n method: 'DELETE',\r\n headers: headers\r\n };\r\n return [4 /*yield*/, retryIfServerError(function () { return fetch(endpoint, request); })];\r\n case 1:\r\n response = _a.sent();\r\n if (!!response.ok) return [3 /*break*/, 3];\r\n return [4 /*yield*/, getErrorFromResponse('Delete Installation', response)];\r\n case 2: throw _a.sent();\r\n case 3: return [2 /*return*/];\r\n }\r\n });\r\n });\r\n}\r\nfunction getDeleteEndpoint(appConfig, _a) {\r\n var fid = _a.fid;\r\n return getInstallationsEndpoint(appConfig) + \"/\" + fid;\r\n}\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nfunction deleteInstallation(dependencies) {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var appConfig, entry;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n appConfig = dependencies.appConfig;\r\n return [4 /*yield*/, update(appConfig, function (oldEntry) {\r\n if (oldEntry && oldEntry.registrationStatus === 0 /* NOT_STARTED */) {\r\n // Delete the unregistered entry without sending a deleteInstallation request.\r\n return undefined;\r\n }\r\n return oldEntry;\r\n })];\r\n case 1:\r\n entry = _a.sent();\r\n if (!entry) return [3 /*break*/, 6];\r\n if (!(entry.registrationStatus === 1 /* IN_PROGRESS */)) return [3 /*break*/, 2];\r\n // Can't delete while trying to register.\r\n throw ERROR_FACTORY.create(\"delete-pending-registration\" /* DELETE_PENDING_REGISTRATION */);\r\n case 2:\r\n if (!(entry.registrationStatus === 2 /* COMPLETED */)) return [3 /*break*/, 6];\r\n if (!!navigator.onLine) return [3 /*break*/, 3];\r\n throw ERROR_FACTORY.create(\"app-offline\" /* APP_OFFLINE */);\r\n case 3: return [4 /*yield*/, deleteInstallationRequest(appConfig, entry)];\r\n case 4:\r\n _a.sent();\r\n return [4 /*yield*/, remove(appConfig)];\r\n case 5:\r\n _a.sent();\r\n _a.label = 6;\r\n case 6: return [2 /*return*/];\r\n }\r\n });\r\n });\r\n}\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n/**\r\n * Sets a new callback that will get called when Installation ID changes.\r\n * Returns an unsubscribe function that will remove the callback when called.\r\n */\r\nfunction onIdChange(_a, callback) {\r\n var appConfig = _a.appConfig;\r\n addCallback(appConfig, callback);\r\n return function () {\r\n removeCallback(appConfig, callback);\r\n };\r\n}\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nfunction extractAppConfig(app) {\r\n var e_1, _a;\r\n if (!app || !app.options) {\r\n throw getMissingValueError('App Configuration');\r\n }\r\n if (!app.name) {\r\n throw getMissingValueError('App Name');\r\n }\r\n // Required app config keys\r\n var configKeys = [\r\n 'projectId',\r\n 'apiKey',\r\n 'appId'\r\n ];\r\n try {\r\n for (var configKeys_1 = __values(configKeys), configKeys_1_1 = configKeys_1.next(); !configKeys_1_1.done; configKeys_1_1 = configKeys_1.next()) {\r\n var keyName = configKeys_1_1.value;\r\n if (!app.options[keyName]) {\r\n throw getMissingValueError(keyName);\r\n }\r\n }\r\n }\r\n catch (e_1_1) { e_1 = { error: e_1_1 }; }\r\n finally {\r\n try {\r\n if (configKeys_1_1 && !configKeys_1_1.done && (_a = configKeys_1.return)) _a.call(configKeys_1);\r\n }\r\n finally { if (e_1) throw e_1.error; }\r\n }\r\n return {\r\n appName: app.name,\r\n projectId: app.options.projectId,\r\n apiKey: app.options.apiKey,\r\n appId: app.options.appId\r\n };\r\n}\r\nfunction getMissingValueError(valueName) {\r\n return ERROR_FACTORY.create(\"missing-app-config-values\" /* MISSING_APP_CONFIG_VALUES */, {\r\n valueName: valueName\r\n });\r\n}\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nfunction registerInstallations(instance) {\r\n var installationsName = 'installations';\r\n instance.INTERNAL.registerComponent(new Component(installationsName, function (container) {\r\n var app = container.getProvider('app').getImmediate();\r\n // Throws if app isn't configured properly.\r\n var appConfig = extractAppConfig(app);\r\n var platformLoggerProvider = container.getProvider('platform-logger');\r\n var dependencies = {\r\n appConfig: appConfig,\r\n platformLoggerProvider: platformLoggerProvider\r\n };\r\n var installations = {\r\n app: app,\r\n getId: function () { return getId(dependencies); },\r\n getToken: function (forceRefresh) {\r\n return getToken(dependencies, forceRefresh);\r\n },\r\n delete: function () { return deleteInstallation(dependencies); },\r\n onIdChange: function (callback) {\r\n return onIdChange(dependencies, callback);\r\n }\r\n };\r\n return installations;\r\n }, \"PUBLIC\" /* PUBLIC */));\r\n instance.registerVersion(name, version);\r\n}\r\nregisterInstallations(firebase);\n\nexport { registerInstallations };\n//# sourceMappingURL=index.esm.js.map\n","import firebase from '@firebase/app';\nimport { __extends, __awaiter, __generator } from 'tslib';\nimport { Component } from '@firebase/component';\n\n/**\r\n * @license\r\n * Copyright 2017 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n/**\r\n * Standard error codes for different ways a request can fail, as defined by:\r\n * https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto\r\n *\r\n * This map is used primarily to convert from a backend error code string to\r\n * a client SDK error code string, and make sure it's in the supported set.\r\n */\r\nvar errorCodeMap = {\r\n OK: 'ok',\r\n CANCELLED: 'cancelled',\r\n UNKNOWN: 'unknown',\r\n INVALID_ARGUMENT: 'invalid-argument',\r\n DEADLINE_EXCEEDED: 'deadline-exceeded',\r\n NOT_FOUND: 'not-found',\r\n ALREADY_EXISTS: 'already-exists',\r\n PERMISSION_DENIED: 'permission-denied',\r\n UNAUTHENTICATED: 'unauthenticated',\r\n RESOURCE_EXHAUSTED: 'resource-exhausted',\r\n FAILED_PRECONDITION: 'failed-precondition',\r\n ABORTED: 'aborted',\r\n OUT_OF_RANGE: 'out-of-range',\r\n UNIMPLEMENTED: 'unimplemented',\r\n INTERNAL: 'internal',\r\n UNAVAILABLE: 'unavailable',\r\n DATA_LOSS: 'data-loss'\r\n};\r\n/**\r\n * An explicit error that can be thrown from a handler to send an error to the\r\n * client that called the function.\r\n */\r\nvar HttpsErrorImpl = /** @class */ (function (_super) {\r\n __extends(HttpsErrorImpl, _super);\r\n function HttpsErrorImpl(code, message, details) {\r\n var _this = _super.call(this, message) || this;\r\n // This is a workaround for a bug in TypeScript when extending Error:\r\n // tslint:disable-next-line\r\n // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work\r\n Object.setPrototypeOf(_this, HttpsErrorImpl.prototype);\r\n _this.code = code;\r\n _this.details = details;\r\n return _this;\r\n }\r\n return HttpsErrorImpl;\r\n}(Error));\r\n/**\r\n * Takes an HTTP status code and returns the corresponding ErrorCode.\r\n * This is the standard HTTP status code -> error mapping defined in:\r\n * https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto\r\n *\r\n * @param status An HTTP status code.\r\n * @return The corresponding ErrorCode, or ErrorCode.UNKNOWN if none.\r\n */\r\nfunction codeForHTTPStatus(status) {\r\n // Make sure any successful status is OK.\r\n if (status >= 200 && status < 300) {\r\n return 'ok';\r\n }\r\n switch (status) {\r\n case 0:\r\n // This can happen if the server returns 500.\r\n return 'internal';\r\n case 400:\r\n return 'invalid-argument';\r\n case 401:\r\n return 'unauthenticated';\r\n case 403:\r\n return 'permission-denied';\r\n case 404:\r\n return 'not-found';\r\n case 409:\r\n return 'aborted';\r\n case 429:\r\n return 'resource-exhausted';\r\n case 499:\r\n return 'cancelled';\r\n case 500:\r\n return 'internal';\r\n case 501:\r\n return 'unimplemented';\r\n case 503:\r\n return 'unavailable';\r\n case 504:\r\n return 'deadline-exceeded';\r\n }\r\n return 'unknown';\r\n}\r\n/**\r\n * Takes an HTTP response and returns the corresponding Error, if any.\r\n */\r\nfunction _errorForResponse(status, bodyJSON, serializer) {\r\n var code = codeForHTTPStatus(status);\r\n // Start with reasonable defaults from the status code.\r\n var description = code;\r\n var details = undefined;\r\n // Then look through the body for explicit details.\r\n try {\r\n var errorJSON = bodyJSON && bodyJSON.error;\r\n if (errorJSON) {\r\n var status_1 = errorJSON.status;\r\n if (typeof status_1 === 'string') {\r\n if (!errorCodeMap[status_1]) {\r\n // They must've included an unknown error code in the body.\r\n return new HttpsErrorImpl('internal', 'internal');\r\n }\r\n code = errorCodeMap[status_1];\r\n // TODO(klimt): Add better default descriptions for error enums.\r\n // The default description needs to be updated for the new code.\r\n description = status_1;\r\n }\r\n var message = errorJSON.message;\r\n if (typeof message === 'string') {\r\n description = message;\r\n }\r\n details = errorJSON.details;\r\n if (details !== undefined) {\r\n details = serializer.decode(details);\r\n }\r\n }\r\n }\r\n catch (e) {\r\n // If we couldn't parse explicit error data, that's fine.\r\n }\r\n if (code === 'ok') {\r\n // Technically, there's an edge case where a developer could explicitly\r\n // return an error code of OK, and we will treat it as success, but that\r\n // seems reasonable.\r\n return null;\r\n }\r\n return new HttpsErrorImpl(code, description, details);\r\n}\n\n/**\r\n * Helper class to get metadata that should be included with a function call.\r\n */\r\nvar ContextProvider = /** @class */ (function () {\r\n function ContextProvider(authProvider, messagingProvider) {\r\n var _this = this;\r\n this.auth = null;\r\n this.messaging = null;\r\n this.auth = authProvider.getImmediate({ optional: true });\r\n this.messaging = messagingProvider.getImmediate({\r\n optional: true\r\n });\r\n if (!this.auth) {\r\n authProvider.get().then(function (auth) { return (_this.auth = auth); }, function () {\r\n /* get() never rejects */\r\n });\r\n }\r\n if (!this.messaging) {\r\n messagingProvider.get().then(function (messaging) { return (_this.messaging = messaging); }, function () {\r\n /* get() never rejects */\r\n });\r\n }\r\n }\r\n ContextProvider.prototype.getAuthToken = function () {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var token;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n if (!this.auth) {\r\n return [2 /*return*/, undefined];\r\n }\r\n _a.label = 1;\r\n case 1:\r\n _a.trys.push([1, 3, , 4]);\r\n return [4 /*yield*/, this.auth.getToken()];\r\n case 2:\r\n token = _a.sent();\r\n if (!token) {\r\n return [2 /*return*/, undefined];\r\n }\r\n return [2 /*return*/, token.accessToken];\r\n case 3:\r\n _a.sent();\r\n // If there's any error when trying to get the auth token, leave it off.\r\n return [2 /*return*/, undefined];\r\n case 4: return [2 /*return*/];\r\n }\r\n });\r\n });\r\n };\r\n ContextProvider.prototype.getInstanceIdToken = function () {\r\n return __awaiter(this, void 0, void 0, function () {\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n if (!this.messaging ||\r\n !('Notification' in self) ||\r\n Notification.permission !== 'granted') {\r\n return [2 /*return*/, undefined];\r\n }\r\n _a.label = 1;\r\n case 1:\r\n _a.trys.push([1, 3, , 4]);\r\n return [4 /*yield*/, this.messaging.getToken()];\r\n case 2: return [2 /*return*/, _a.sent()];\r\n case 3:\r\n _a.sent();\r\n // We don't warn on this, because it usually means messaging isn't set up.\r\n // console.warn('Failed to retrieve instance id token.', e);\r\n // If there's any error when trying to get the token, leave it off.\r\n return [2 /*return*/, undefined];\r\n case 4: return [2 /*return*/];\r\n }\r\n });\r\n });\r\n };\r\n ContextProvider.prototype.getContext = function () {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var authToken, instanceIdToken;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0: return [4 /*yield*/, this.getAuthToken()];\r\n case 1:\r\n authToken = _a.sent();\r\n return [4 /*yield*/, this.getInstanceIdToken()];\r\n case 2:\r\n instanceIdToken = _a.sent();\r\n return [2 /*return*/, { authToken: authToken, instanceIdToken: instanceIdToken }];\r\n }\r\n });\r\n });\r\n };\r\n return ContextProvider;\r\n}());\n\n/**\r\n * @license\r\n * Copyright 2017 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nvar LONG_TYPE = 'type.googleapis.com/google.protobuf.Int64Value';\r\nvar UNSIGNED_LONG_TYPE = 'type.googleapis.com/google.protobuf.UInt64Value';\r\nfunction mapValues(\r\n// { [k: string]: unknown } is no longer a wildcard assignment target after typescript 3.5\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\no, f) {\r\n var result = {};\r\n for (var key in o) {\r\n if (o.hasOwnProperty(key)) {\r\n result[key] = f(o[key]);\r\n }\r\n }\r\n return result;\r\n}\r\nvar Serializer = /** @class */ (function () {\r\n function Serializer() {\r\n }\r\n // Takes data and encodes it in a JSON-friendly way, such that types such as\r\n // Date are preserved.\r\n Serializer.prototype.encode = function (data) {\r\n var _this = this;\r\n if (data == null) {\r\n return null;\r\n }\r\n if (data instanceof Number) {\r\n data = data.valueOf();\r\n }\r\n if (typeof data === 'number' && isFinite(data)) {\r\n // Any number in JS is safe to put directly in JSON and parse as a double\r\n // without any loss of precision.\r\n return data;\r\n }\r\n if (data === true || data === false) {\r\n return data;\r\n }\r\n if (Object.prototype.toString.call(data) === '[object String]') {\r\n return data;\r\n }\r\n if (data instanceof Date) {\r\n return data.toISOString();\r\n }\r\n if (Array.isArray(data)) {\r\n return data.map(function (x) { return _this.encode(x); });\r\n }\r\n if (typeof data === 'function' || typeof data === 'object') {\r\n return mapValues(data, function (x) { return _this.encode(x); });\r\n }\r\n // If we got this far, the data is not encodable.\r\n throw new Error('Data cannot be encoded in JSON: ' + data);\r\n };\r\n // Takes data that's been encoded in a JSON-friendly form and returns a form\r\n // with richer datatypes, such as Dates, etc.\r\n Serializer.prototype.decode = function (json) {\r\n var _this = this;\r\n if (json == null) {\r\n return json;\r\n }\r\n if (json['@type']) {\r\n switch (json['@type']) {\r\n case LONG_TYPE:\r\n // Fall through and handle this the same as unsigned.\r\n case UNSIGNED_LONG_TYPE: {\r\n // Technically, this could work return a valid number for malformed\r\n // data if there was a number followed by garbage. But it's just not\r\n // worth all the extra code to detect that case.\r\n var value = Number(json['value']);\r\n if (isNaN(value)) {\r\n throw new Error('Data cannot be decoded from JSON: ' + json);\r\n }\r\n return value;\r\n }\r\n default: {\r\n throw new Error('Data cannot be decoded from JSON: ' + json);\r\n }\r\n }\r\n }\r\n if (Array.isArray(json)) {\r\n return json.map(function (x) { return _this.decode(x); });\r\n }\r\n if (typeof json === 'function' || typeof json === 'object') {\r\n return mapValues(json, function (x) { return _this.decode(x); });\r\n }\r\n // Anything else is safe to return.\r\n return json;\r\n };\r\n return Serializer;\r\n}());\n\n/**\r\n * @license\r\n * Copyright 2017 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n/**\r\n * Returns a Promise that will be rejected after the given duration.\r\n * The error will be of type HttpsErrorImpl.\r\n *\r\n * @param millis Number of milliseconds to wait before rejecting.\r\n */\r\nfunction failAfter(millis) {\r\n var timer;\r\n var promise = new Promise(function (_, reject) {\r\n timer = setTimeout(function () {\r\n reject(new HttpsErrorImpl('deadline-exceeded', 'deadline-exceeded'));\r\n }, millis);\r\n });\r\n return {\r\n timer: timer,\r\n promise: promise\r\n };\r\n}\r\n/**\r\n * The main class for the Firebase Functions SDK.\r\n */\r\nvar Service = /** @class */ (function () {\r\n /**\r\n * Creates a new Functions service for the given app and (optional) region or custom domain.\r\n * @param app_ The FirebaseApp to use.\r\n * @param regionOrCustomDomain_ one of:\r\n * a) A region to call functions from, such as us-central1\r\n * b) A custom domain to use as a functions prefix, such as https://mydomain.com\r\n */\r\n function Service(app_, authProvider, messagingProvider, appCheckProvider, regionOrCustomDomain_, fetchImpl) {\r\n var _this = this;\r\n if (regionOrCustomDomain_ === void 0) { regionOrCustomDomain_ = 'us-central1'; }\r\n this.app_ = app_;\r\n this.appCheckProvider = appCheckProvider;\r\n this.fetchImpl = fetchImpl;\r\n this.serializer = new Serializer();\r\n this.emulatorOrigin = null;\r\n this.INTERNAL = {\r\n delete: function () {\r\n return Promise.resolve(_this.deleteService());\r\n }\r\n };\r\n this.contextProvider = new ContextProvider(authProvider, messagingProvider);\r\n // Cancels all ongoing requests when resolved.\r\n this.cancelAllRequests = new Promise(function (resolve) {\r\n _this.deleteService = function () {\r\n return resolve();\r\n };\r\n });\r\n // Resolve the region or custom domain overload by attempting to parse it.\r\n try {\r\n var url = new URL(regionOrCustomDomain_);\r\n this.customDomain = url.origin;\r\n this.region = 'us-central1';\r\n }\r\n catch (e) {\r\n this.customDomain = null;\r\n this.region = regionOrCustomDomain_;\r\n }\r\n }\r\n Object.defineProperty(Service.prototype, \"app\", {\r\n get: function () {\r\n return this.app_;\r\n },\r\n enumerable: false,\r\n configurable: true\r\n });\r\n /**\r\n * Returns the URL for a callable with the given name.\r\n * @param name The name of the callable.\r\n */\r\n Service.prototype._url = function (name) {\r\n var projectId = this.app_.options.projectId;\r\n if (this.emulatorOrigin !== null) {\r\n var origin_1 = this.emulatorOrigin;\r\n return origin_1 + \"/\" + projectId + \"/\" + this.region + \"/\" + name;\r\n }\r\n if (this.customDomain !== null) {\r\n return this.customDomain + \"/\" + name;\r\n }\r\n return \"https://\" + this.region + \"-\" + projectId + \".cloudfunctions.net/\" + name;\r\n };\r\n /**\r\n * Modify this instance to communicate with the Cloud Functions emulator.\r\n *\r\n * Note: this must be called before this instance has been used to do any operations.\r\n *\r\n * @param host The emulator host (ex: localhost)\r\n * @param port The emulator port (ex: 5001)\r\n */\r\n Service.prototype.useEmulator = function (host, port) {\r\n this.emulatorOrigin = \"http://\" + host + \":\" + port;\r\n };\r\n /**\r\n * Changes this instance to point to a Cloud Functions emulator running\r\n * locally. See https://firebase.google.com/docs/functions/local-emulator\r\n *\r\n * @deprecated Prefer the useEmulator(host, port) method.\r\n * @param origin The origin of the local emulator, such as\r\n * \"http://localhost:5005\".\r\n */\r\n Service.prototype.useFunctionsEmulator = function (origin) {\r\n this.emulatorOrigin = origin;\r\n };\r\n /**\r\n * Returns a reference to the callable https trigger with the given name.\r\n * @param name The name of the trigger.\r\n */\r\n Service.prototype.httpsCallable = function (name, options) {\r\n var _this = this;\r\n return function (data) {\r\n return _this.call(name, data, options || {});\r\n };\r\n };\r\n /**\r\n * Does an HTTP POST and returns the completed response.\r\n * @param url The url to post to.\r\n * @param body The JSON body of the post.\r\n * @param headers The HTTP headers to include in the request.\r\n * @return A Promise that will succeed when the request finishes.\r\n */\r\n Service.prototype.postJSON = function (url, body, headers) {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var appCheckToken, response, json;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n headers['Content-Type'] = 'application/json';\r\n return [4 /*yield*/, this.getAppCheckToken()];\r\n case 1:\r\n appCheckToken = _a.sent();\r\n if (appCheckToken !== null) {\r\n headers['X-Firebase-AppCheck'] = appCheckToken;\r\n }\r\n _a.label = 2;\r\n case 2:\r\n _a.trys.push([2, 4, , 5]);\r\n return [4 /*yield*/, this.fetchImpl(url, {\r\n method: 'POST',\r\n body: JSON.stringify(body),\r\n headers: headers\r\n })];\r\n case 3:\r\n response = _a.sent();\r\n return [3 /*break*/, 5];\r\n case 4:\r\n _a.sent();\r\n // This could be an unhandled error on the backend, or it could be a\r\n // network error. There's no way to know, since an unhandled error on the\r\n // backend will fail to set the proper CORS header, and thus will be\r\n // treated as a network error by fetch.\r\n return [2 /*return*/, {\r\n status: 0,\r\n json: null\r\n }];\r\n case 5:\r\n json = null;\r\n _a.label = 6;\r\n case 6:\r\n _a.trys.push([6, 8, , 9]);\r\n return [4 /*yield*/, response.json()];\r\n case 7:\r\n json = _a.sent();\r\n return [3 /*break*/, 9];\r\n case 8:\r\n _a.sent();\r\n return [3 /*break*/, 9];\r\n case 9: return [2 /*return*/, {\r\n status: response.status,\r\n json: json\r\n }];\r\n }\r\n });\r\n });\r\n };\r\n Service.prototype.getAppCheckToken = function () {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var appCheck, result;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n appCheck = this.appCheckProvider.getImmediate({ optional: true });\r\n if (!appCheck) return [3 /*break*/, 2];\r\n return [4 /*yield*/, appCheck.getToken()];\r\n case 1:\r\n result = _a.sent();\r\n // If getToken() fails, it will still return a dummy token that also has\r\n // an error field containing the error message. We will send any token\r\n // provided here and show an error if/when it is rejected by the functions\r\n // endpoint.\r\n return [2 /*return*/, result.token];\r\n case 2: return [2 /*return*/, null];\r\n }\r\n });\r\n });\r\n };\r\n /**\r\n * Calls a callable function asynchronously and returns the result.\r\n * @param name The name of the callable trigger.\r\n * @param data The data to pass as params to the function.s\r\n */\r\n Service.prototype.call = function (name, data, options) {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var url, body, headers, context, timeout, _a, timer, failAfterPromise, response, error, responseData, decodedData;\r\n return __generator(this, function (_b) {\r\n switch (_b.label) {\r\n case 0:\r\n url = this._url(name);\r\n // Encode any special types, such as dates, in the input data.\r\n data = this.serializer.encode(data);\r\n body = { data: data };\r\n headers = {};\r\n return [4 /*yield*/, this.contextProvider.getContext()];\r\n case 1:\r\n context = _b.sent();\r\n if (context.authToken) {\r\n headers['Authorization'] = 'Bearer ' + context.authToken;\r\n }\r\n if (context.instanceIdToken) {\r\n headers['Firebase-Instance-ID-Token'] = context.instanceIdToken;\r\n }\r\n timeout = options.timeout || 70000;\r\n _a = failAfter(timeout), timer = _a.timer, failAfterPromise = _a.promise;\r\n return [4 /*yield*/, Promise.race([\r\n clearTimeoutWrapper(timer, this.postJSON(url, body, headers)),\r\n failAfterPromise,\r\n clearTimeoutWrapper(timer, this.cancelAllRequests)\r\n ])];\r\n case 2:\r\n response = _b.sent();\r\n // If service was deleted, interrupted response throws an error.\r\n if (!response) {\r\n throw new HttpsErrorImpl('cancelled', 'Firebase Functions instance was deleted.');\r\n }\r\n error = _errorForResponse(response.status, response.json, this.serializer);\r\n if (error) {\r\n throw error;\r\n }\r\n if (!response.json) {\r\n throw new HttpsErrorImpl('internal', 'Response is not valid JSON object.');\r\n }\r\n responseData = response.json.data;\r\n // TODO(klimt): For right now, allow \"result\" instead of \"data\", for\r\n // backwards compatibility.\r\n if (typeof responseData === 'undefined') {\r\n responseData = response.json.result;\r\n }\r\n if (typeof responseData === 'undefined') {\r\n // Consider the response malformed.\r\n throw new HttpsErrorImpl('internal', 'Response is missing data field.');\r\n }\r\n decodedData = this.serializer.decode(responseData);\r\n return [2 /*return*/, { data: decodedData }];\r\n }\r\n });\r\n });\r\n };\r\n return Service;\r\n}());\r\nfunction clearTimeoutWrapper(timer, promise) {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var result;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0: return [4 /*yield*/, promise];\r\n case 1:\r\n result = _a.sent();\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n clearTimeout(timer);\r\n return [2 /*return*/, result];\r\n }\r\n });\r\n });\r\n}\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n/**\r\n * Type constant for Firebase Functions.\r\n */\r\nvar FUNCTIONS_TYPE = 'functions';\r\nfunction registerFunctions(instance, fetchImpl) {\r\n var namespaceExports = {\r\n // no-inline\r\n Functions: Service\r\n };\r\n function factory(container, _a) {\r\n var regionOrCustomDomain = _a.instanceIdentifier;\r\n // Dependencies\r\n var app = container.getProvider('app').getImmediate();\r\n var authProvider = container.getProvider('auth-internal');\r\n var appCheckProvider = container.getProvider('app-check-internal');\r\n var messagingProvider = container.getProvider('messaging');\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n return new Service(app, authProvider, messagingProvider, appCheckProvider, regionOrCustomDomain, fetchImpl);\r\n }\r\n instance.INTERNAL.registerComponent(new Component(FUNCTIONS_TYPE, factory, \"PUBLIC\" /* PUBLIC */)\r\n .setServiceProps(namespaceExports)\r\n .setMultipleInstances(true));\r\n}\n\nvar name = \"@firebase/functions\";\nvar version = \"0.6.16\";\n\n/**\r\n * @license\r\n * Copyright 2017 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nregisterFunctions(firebase, fetch.bind(self));\r\nfirebase.registerVersion(name, version);\n//# sourceMappingURL=index.esm.js.map\n","/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation. All rights reserved.\r\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\r\nthis file except in compliance with the License. You may obtain a copy of the\r\nLicense at http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nTHIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r\nKIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED\r\nWARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,\r\nMERCHANTABLITY OR NON-INFRINGEMENT.\r\n\r\nSee the Apache Version 2.0 License for specific language governing permissions\r\nand limitations under the License.\r\n***************************************************************************** */\r\n\r\nfunction __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\n\n/**\r\n * @license\r\n * Copyright 2017 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nvar _a;\r\n/**\r\n * A container for all of the Logger instances\r\n */\r\nvar instances = [];\r\n/**\r\n * The JS SDK supports 5 log levels and also allows a user the ability to\r\n * silence the logs altogether.\r\n *\r\n * The order is a follows:\r\n * DEBUG < VERBOSE < INFO < WARN < ERROR\r\n *\r\n * All of the log types above the current log level will be captured (i.e. if\r\n * you set the log level to `INFO`, errors will still be logged, but `DEBUG` and\r\n * `VERBOSE` logs will not)\r\n */\r\nvar LogLevel;\r\n(function (LogLevel) {\r\n LogLevel[LogLevel[\"DEBUG\"] = 0] = \"DEBUG\";\r\n LogLevel[LogLevel[\"VERBOSE\"] = 1] = \"VERBOSE\";\r\n LogLevel[LogLevel[\"INFO\"] = 2] = \"INFO\";\r\n LogLevel[LogLevel[\"WARN\"] = 3] = \"WARN\";\r\n LogLevel[LogLevel[\"ERROR\"] = 4] = \"ERROR\";\r\n LogLevel[LogLevel[\"SILENT\"] = 5] = \"SILENT\";\r\n})(LogLevel || (LogLevel = {}));\r\nvar levelStringToEnum = {\r\n 'debug': LogLevel.DEBUG,\r\n 'verbose': LogLevel.VERBOSE,\r\n 'info': LogLevel.INFO,\r\n 'warn': LogLevel.WARN,\r\n 'error': LogLevel.ERROR,\r\n 'silent': LogLevel.SILENT\r\n};\r\n/**\r\n * The default log level\r\n */\r\nvar defaultLogLevel = LogLevel.INFO;\r\n/**\r\n * By default, `console.debug` is not displayed in the developer console (in\r\n * chrome). To avoid forcing users to have to opt-in to these logs twice\r\n * (i.e. once for firebase, and once in the console), we are sending `DEBUG`\r\n * logs to the `console.log` function.\r\n */\r\nvar ConsoleMethod = (_a = {},\r\n _a[LogLevel.DEBUG] = 'log',\r\n _a[LogLevel.VERBOSE] = 'log',\r\n _a[LogLevel.INFO] = 'info',\r\n _a[LogLevel.WARN] = 'warn',\r\n _a[LogLevel.ERROR] = 'error',\r\n _a);\r\n/**\r\n * The default log handler will forward DEBUG, VERBOSE, INFO, WARN, and ERROR\r\n * messages on to their corresponding console counterparts (if the log method\r\n * is supported by the current log level)\r\n */\r\nvar defaultLogHandler = function (instance, logType) {\r\n var args = [];\r\n for (var _i = 2; _i < arguments.length; _i++) {\r\n args[_i - 2] = arguments[_i];\r\n }\r\n if (logType < instance.logLevel) {\r\n return;\r\n }\r\n var now = new Date().toISOString();\r\n var method = ConsoleMethod[logType];\r\n if (method) {\r\n console[method].apply(console, __spreadArrays([\"[\" + now + \"] \" + instance.name + \":\"], args));\r\n }\r\n else {\r\n throw new Error(\"Attempted to log a message with an invalid logType (value: \" + logType + \")\");\r\n }\r\n};\r\nvar Logger = /** @class */ (function () {\r\n /**\r\n * Gives you an instance of a Logger to capture messages according to\r\n * Firebase's logging scheme.\r\n *\r\n * @param name The name that the logs will be associated with\r\n */\r\n function Logger(name) {\r\n this.name = name;\r\n /**\r\n * The log level of the given Logger instance.\r\n */\r\n this._logLevel = defaultLogLevel;\r\n /**\r\n * The main (internal) log handler for the Logger instance.\r\n * Can be set to a new function in internal package code but not by user.\r\n */\r\n this._logHandler = defaultLogHandler;\r\n /**\r\n * The optional, additional, user-defined log handler for the Logger instance.\r\n */\r\n this._userLogHandler = null;\r\n /**\r\n * Capture the current instance for later use\r\n */\r\n instances.push(this);\r\n }\r\n Object.defineProperty(Logger.prototype, \"logLevel\", {\r\n get: function () {\r\n return this._logLevel;\r\n },\r\n set: function (val) {\r\n if (!(val in LogLevel)) {\r\n throw new TypeError(\"Invalid value \\\"\" + val + \"\\\" assigned to `logLevel`\");\r\n }\r\n this._logLevel = val;\r\n },\r\n enumerable: false,\r\n configurable: true\r\n });\r\n // Workaround for setter/getter having to be the same type.\r\n Logger.prototype.setLogLevel = function (val) {\r\n this._logLevel = typeof val === 'string' ? levelStringToEnum[val] : val;\r\n };\r\n Object.defineProperty(Logger.prototype, \"logHandler\", {\r\n get: function () {\r\n return this._logHandler;\r\n },\r\n set: function (val) {\r\n if (typeof val !== 'function') {\r\n throw new TypeError('Value assigned to `logHandler` must be a function');\r\n }\r\n this._logHandler = val;\r\n },\r\n enumerable: false,\r\n configurable: true\r\n });\r\n Object.defineProperty(Logger.prototype, \"userLogHandler\", {\r\n get: function () {\r\n return this._userLogHandler;\r\n },\r\n set: function (val) {\r\n this._userLogHandler = val;\r\n },\r\n enumerable: false,\r\n configurable: true\r\n });\r\n /**\r\n * The functions below are all based on the `console` interface\r\n */\r\n Logger.prototype.debug = function () {\r\n var args = [];\r\n for (var _i = 0; _i < arguments.length; _i++) {\r\n args[_i] = arguments[_i];\r\n }\r\n this._userLogHandler && this._userLogHandler.apply(this, __spreadArrays([this, LogLevel.DEBUG], args));\r\n this._logHandler.apply(this, __spreadArrays([this, LogLevel.DEBUG], args));\r\n };\r\n Logger.prototype.log = function () {\r\n var args = [];\r\n for (var _i = 0; _i < arguments.length; _i++) {\r\n args[_i] = arguments[_i];\r\n }\r\n this._userLogHandler && this._userLogHandler.apply(this, __spreadArrays([this, LogLevel.VERBOSE], args));\r\n this._logHandler.apply(this, __spreadArrays([this, LogLevel.VERBOSE], args));\r\n };\r\n Logger.prototype.info = function () {\r\n var args = [];\r\n for (var _i = 0; _i < arguments.length; _i++) {\r\n args[_i] = arguments[_i];\r\n }\r\n this._userLogHandler && this._userLogHandler.apply(this, __spreadArrays([this, LogLevel.INFO], args));\r\n this._logHandler.apply(this, __spreadArrays([this, LogLevel.INFO], args));\r\n };\r\n Logger.prototype.warn = function () {\r\n var args = [];\r\n for (var _i = 0; _i < arguments.length; _i++) {\r\n args[_i] = arguments[_i];\r\n }\r\n this._userLogHandler && this._userLogHandler.apply(this, __spreadArrays([this, LogLevel.WARN], args));\r\n this._logHandler.apply(this, __spreadArrays([this, LogLevel.WARN], args));\r\n };\r\n Logger.prototype.error = function () {\r\n var args = [];\r\n for (var _i = 0; _i < arguments.length; _i++) {\r\n args[_i] = arguments[_i];\r\n }\r\n this._userLogHandler && this._userLogHandler.apply(this, __spreadArrays([this, LogLevel.ERROR], args));\r\n this._logHandler.apply(this, __spreadArrays([this, LogLevel.ERROR], args));\r\n };\r\n return Logger;\r\n}());\r\nfunction setLogLevel(level) {\r\n instances.forEach(function (inst) {\r\n inst.setLogLevel(level);\r\n });\r\n}\r\nfunction setUserLogHandler(logCallback, options) {\r\n var _loop_1 = function (instance) {\r\n var customLogLevel = null;\r\n if (options && options.level) {\r\n customLogLevel = levelStringToEnum[options.level];\r\n }\r\n if (logCallback === null) {\r\n instance.userLogHandler = null;\r\n }\r\n else {\r\n instance.userLogHandler = function (instance, level) {\r\n var args = [];\r\n for (var _i = 2; _i < arguments.length; _i++) {\r\n args[_i - 2] = arguments[_i];\r\n }\r\n var message = args\r\n .map(function (arg) {\r\n if (arg == null) {\r\n return null;\r\n }\r\n else if (typeof arg === 'string') {\r\n return arg;\r\n }\r\n else if (typeof arg === 'number' || typeof arg === 'boolean') {\r\n return arg.toString();\r\n }\r\n else if (arg instanceof Error) {\r\n return arg.message;\r\n }\r\n else {\r\n try {\r\n return JSON.stringify(arg);\r\n }\r\n catch (ignored) {\r\n return null;\r\n }\r\n }\r\n })\r\n .filter(function (arg) { return arg; })\r\n .join(' ');\r\n if (level >= (customLogLevel !== null && customLogLevel !== void 0 ? customLogLevel : instance.logLevel)) {\r\n logCallback({\r\n level: LogLevel[level].toLowerCase(),\r\n message: message,\r\n args: args,\r\n type: instance.name\r\n });\r\n }\r\n };\r\n }\r\n };\r\n for (var _i = 0, instances_1 = instances; _i < instances_1.length; _i++) {\r\n var instance = instances_1[_i];\r\n _loop_1(instance);\r\n }\r\n}\n\nexport { LogLevel, Logger, setLogLevel, setUserLogHandler };\n//# sourceMappingURL=index.esm.js.map\n","import { u as e, a as r, K as o } from \"./prebuilt-2d830653-6eee25bb.js\";\n\nimport \"tslib\";\n\nimport \"@firebase/util\";\n\nimport \"@firebase/logger\";\n\nimport \"@firebase/webchannel-wrapper\";\n\n/**\n * @license\n * Copyright 2020 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n/**\n * Prototype patches bundle loading to Firestore.\n */ function t(o) {\n o.prototype.loadBundle = e, o.prototype.namedQuery = r;\n}\n\nt(o);\n\nexport { t as registerBundle };\n//# sourceMappingURL=bundle.js.map\n","import e from \"@firebase/app\";\n\nimport { K as r, T as t, U as a, C as s, M as o, L as i, W as n, G as p, H as m, Z as c, e as f, t as u, s as b, i as l, o as g, c as h, j as d, E as v } from \"./prebuilt-2d830653-6eee25bb.js\";\n\nimport { Component as w } from \"@firebase/component\";\n\nimport \"tslib\";\n\nimport \"@firebase/util\";\n\nimport \"@firebase/logger\";\n\nimport \"@firebase/webchannel-wrapper\";\n\nvar C = {\n Firestore: r,\n GeoPoint: s,\n Timestamp: o,\n Blob: i,\n Transaction: n,\n WriteBatch: p,\n DocumentReference: m,\n DocumentSnapshot: c,\n Query: f,\n QueryDocumentSnapshot: u,\n QuerySnapshot: b,\n CollectionReference: l,\n FieldPath: g,\n FieldValue: h,\n setLogLevel: d,\n CACHE_SIZE_UNLIMITED: v\n};\n\n/**\n * @license\n * Copyright 2017 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n/**\n * Registers the main Firestore build with the components framework.\n * Persistence can be enabled via `firebase.firestore().enablePersistence()`.\n */\nfunction I(e) {\n !\n /**\n * Configures Firestore as part of the Firebase SDK by calling registerService.\n *\n * @param firebase - The FirebaseNamespace to register Firestore with\n * @param firestoreFactory - A factory function that returns a new Firestore\n * instance.\n */\n function(e, r) {\n e.INTERNAL.registerComponent(new w(\"firestore\", (function(e) {\n var t = e.getProvider(\"app\").getImmediate();\n return r(t, e.getProvider(\"auth-internal\"));\n }), \"PUBLIC\" /* PUBLIC */).setServiceProps(Object.assign({}, C)));\n }(e, (function(e, s) {\n return new r(e, new t(e, s), new a);\n })), e.registerVersion(\"@firebase/firestore\", \"2.4.1\");\n}\n\nI(e);\n\nexport { I as registerFirestore };\n//# sourceMappingURL=index.js.map\n","import { __values, __read, __awaiter, __generator, __spreadArray } from 'tslib';\nimport { Deferred } from '@firebase/util';\n\n/**\r\n * Component for service name T, e.g. `auth`, `auth-internal`\r\n */\r\nvar Component = /** @class */ (function () {\r\n /**\r\n *\r\n * @param name The public service name, e.g. app, auth, firestore, database\r\n * @param instanceFactory Service factory responsible for creating the public interface\r\n * @param type whether the service provided by the component is public or private\r\n */\r\n function Component(name, instanceFactory, type) {\r\n this.name = name;\r\n this.instanceFactory = instanceFactory;\r\n this.type = type;\r\n this.multipleInstances = false;\r\n /**\r\n * Properties to be added to the service namespace\r\n */\r\n this.serviceProps = {};\r\n this.instantiationMode = \"LAZY\" /* LAZY */;\r\n this.onInstanceCreated = null;\r\n }\r\n Component.prototype.setInstantiationMode = function (mode) {\r\n this.instantiationMode = mode;\r\n return this;\r\n };\r\n Component.prototype.setMultipleInstances = function (multipleInstances) {\r\n this.multipleInstances = multipleInstances;\r\n return this;\r\n };\r\n Component.prototype.setServiceProps = function (props) {\r\n this.serviceProps = props;\r\n return this;\r\n };\r\n Component.prototype.setInstanceCreatedCallback = function (callback) {\r\n this.onInstanceCreated = callback;\r\n return this;\r\n };\r\n return Component;\r\n}());\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\nvar DEFAULT_ENTRY_NAME = '[DEFAULT]';\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n/**\r\n * Provider for instance for service name T, e.g. 'auth', 'auth-internal'\r\n * NameServiceMapping[T] is an alias for the type of the instance\r\n */\r\nvar Provider = /** @class */ (function () {\r\n function Provider(name, container) {\r\n this.name = name;\r\n this.container = container;\r\n this.component = null;\r\n this.instances = new Map();\r\n this.instancesDeferred = new Map();\r\n this.instancesOptions = new Map();\r\n this.onInitCallbacks = new Map();\r\n }\r\n /**\r\n * @param identifier A provider can provide mulitple instances of a service\r\n * if this.component.multipleInstances is true.\r\n */\r\n Provider.prototype.get = function (identifier) {\r\n // if multipleInstances is not supported, use the default name\r\n var normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);\r\n if (!this.instancesDeferred.has(normalizedIdentifier)) {\r\n var deferred = new Deferred();\r\n this.instancesDeferred.set(normalizedIdentifier, deferred);\r\n if (this.isInitialized(normalizedIdentifier) ||\r\n this.shouldAutoInitialize()) {\r\n // initialize the service if it can be auto-initialized\r\n try {\r\n var instance = this.getOrInitializeService({\r\n instanceIdentifier: normalizedIdentifier\r\n });\r\n if (instance) {\r\n deferred.resolve(instance);\r\n }\r\n }\r\n catch (e) {\r\n // when the instance factory throws an exception during get(), it should not cause\r\n // a fatal error. We just return the unresolved promise in this case.\r\n }\r\n }\r\n }\r\n return this.instancesDeferred.get(normalizedIdentifier).promise;\r\n };\r\n Provider.prototype.getImmediate = function (options) {\r\n var _a;\r\n // if multipleInstances is not supported, use the default name\r\n var normalizedIdentifier = this.normalizeInstanceIdentifier(options === null || options === void 0 ? void 0 : options.identifier);\r\n var optional = (_a = options === null || options === void 0 ? void 0 : options.optional) !== null && _a !== void 0 ? _a : false;\r\n if (this.isInitialized(normalizedIdentifier) ||\r\n this.shouldAutoInitialize()) {\r\n try {\r\n return this.getOrInitializeService({\r\n instanceIdentifier: normalizedIdentifier\r\n });\r\n }\r\n catch (e) {\r\n if (optional) {\r\n return null;\r\n }\r\n else {\r\n throw e;\r\n }\r\n }\r\n }\r\n else {\r\n // In case a component is not initialized and should/can not be auto-initialized at the moment, return null if the optional flag is set, or throw\r\n if (optional) {\r\n return null;\r\n }\r\n else {\r\n throw Error(\"Service \" + this.name + \" is not available\");\r\n }\r\n }\r\n };\r\n Provider.prototype.getComponent = function () {\r\n return this.component;\r\n };\r\n Provider.prototype.setComponent = function (component) {\r\n var e_1, _a;\r\n if (component.name !== this.name) {\r\n throw Error(\"Mismatching Component \" + component.name + \" for Provider \" + this.name + \".\");\r\n }\r\n if (this.component) {\r\n throw Error(\"Component for \" + this.name + \" has already been provided\");\r\n }\r\n this.component = component;\r\n // return early without attempting to initialize the component if the component requires explicit initialization (calling `Provider.initialize()`)\r\n if (!this.shouldAutoInitialize()) {\r\n return;\r\n }\r\n // if the service is eager, initialize the default instance\r\n if (isComponentEager(component)) {\r\n try {\r\n this.getOrInitializeService({ instanceIdentifier: DEFAULT_ENTRY_NAME });\r\n }\r\n catch (e) {\r\n // when the instance factory for an eager Component throws an exception during the eager\r\n // initialization, it should not cause a fatal error.\r\n // TODO: Investigate if we need to make it configurable, because some component may want to cause\r\n // a fatal error in this case?\r\n }\r\n }\r\n try {\r\n // Create service instances for the pending promises and resolve them\r\n // NOTE: if this.multipleInstances is false, only the default instance will be created\r\n // and all promises with resolve with it regardless of the identifier.\r\n for (var _b = __values(this.instancesDeferred.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {\r\n var _d = __read(_c.value, 2), instanceIdentifier = _d[0], instanceDeferred = _d[1];\r\n var normalizedIdentifier = this.normalizeInstanceIdentifier(instanceIdentifier);\r\n try {\r\n // `getOrInitializeService()` should always return a valid instance since a component is guaranteed. use ! to make typescript happy.\r\n var instance = this.getOrInitializeService({\r\n instanceIdentifier: normalizedIdentifier\r\n });\r\n instanceDeferred.resolve(instance);\r\n }\r\n catch (e) {\r\n // when the instance factory throws an exception, it should not cause\r\n // a fatal error. We just leave the promise unresolved.\r\n }\r\n }\r\n }\r\n catch (e_1_1) { e_1 = { error: e_1_1 }; }\r\n finally {\r\n try {\r\n if (_c && !_c.done && (_a = _b.return)) _a.call(_b);\r\n }\r\n finally { if (e_1) throw e_1.error; }\r\n }\r\n };\r\n Provider.prototype.clearInstance = function (identifier) {\r\n if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }\r\n this.instancesDeferred.delete(identifier);\r\n this.instancesOptions.delete(identifier);\r\n this.instances.delete(identifier);\r\n };\r\n // app.delete() will call this method on every provider to delete the services\r\n // TODO: should we mark the provider as deleted?\r\n Provider.prototype.delete = function () {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var services;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n services = Array.from(this.instances.values());\r\n return [4 /*yield*/, Promise.all(__spreadArray(__spreadArray([], __read(services\r\n .filter(function (service) { return 'INTERNAL' in service; }) // legacy services\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n .map(function (service) { return service.INTERNAL.delete(); }))), __read(services\r\n .filter(function (service) { return '_delete' in service; }) // modularized services\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n .map(function (service) { return service._delete(); }))))];\r\n case 1:\r\n _a.sent();\r\n return [2 /*return*/];\r\n }\r\n });\r\n });\r\n };\r\n Provider.prototype.isComponentSet = function () {\r\n return this.component != null;\r\n };\r\n Provider.prototype.isInitialized = function (identifier) {\r\n if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }\r\n return this.instances.has(identifier);\r\n };\r\n Provider.prototype.getOptions = function (identifier) {\r\n if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }\r\n return this.instancesOptions.get(identifier) || {};\r\n };\r\n Provider.prototype.initialize = function (opts) {\r\n var e_2, _a;\r\n if (opts === void 0) { opts = {}; }\r\n var _b = opts.options, options = _b === void 0 ? {} : _b;\r\n var normalizedIdentifier = this.normalizeInstanceIdentifier(opts.instanceIdentifier);\r\n if (this.isInitialized(normalizedIdentifier)) {\r\n throw Error(this.name + \"(\" + normalizedIdentifier + \") has already been initialized\");\r\n }\r\n if (!this.isComponentSet()) {\r\n throw Error(\"Component \" + this.name + \" has not been registered yet\");\r\n }\r\n var instance = this.getOrInitializeService({\r\n instanceIdentifier: normalizedIdentifier,\r\n options: options\r\n });\r\n try {\r\n // resolve any pending promise waiting for the service instance\r\n for (var _c = __values(this.instancesDeferred.entries()), _d = _c.next(); !_d.done; _d = _c.next()) {\r\n var _e = __read(_d.value, 2), instanceIdentifier = _e[0], instanceDeferred = _e[1];\r\n var normalizedDeferredIdentifier = this.normalizeInstanceIdentifier(instanceIdentifier);\r\n if (normalizedIdentifier === normalizedDeferredIdentifier) {\r\n instanceDeferred.resolve(instance);\r\n }\r\n }\r\n }\r\n catch (e_2_1) { e_2 = { error: e_2_1 }; }\r\n finally {\r\n try {\r\n if (_d && !_d.done && (_a = _c.return)) _a.call(_c);\r\n }\r\n finally { if (e_2) throw e_2.error; }\r\n }\r\n return instance;\r\n };\r\n /**\r\n *\r\n * @param callback - a function that will be invoked after the provider has been initialized by calling provider.initialize().\r\n * The function is invoked SYNCHRONOUSLY, so it should not execute any longrunning tasks in order to not block the program.\r\n *\r\n * @param identifier An optional instance identifier\r\n * @returns a function to unregister the callback\r\n */\r\n Provider.prototype.onInit = function (callback, identifier) {\r\n var _a;\r\n var normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);\r\n var existingCallbacks = (_a = this.onInitCallbacks.get(normalizedIdentifier)) !== null && _a !== void 0 ? _a : new Set();\r\n existingCallbacks.add(callback);\r\n this.onInitCallbacks.set(normalizedIdentifier, existingCallbacks);\r\n var existingInstance = this.instances.get(normalizedIdentifier);\r\n if (existingInstance) {\r\n callback(existingInstance, normalizedIdentifier);\r\n }\r\n return function () {\r\n existingCallbacks.delete(callback);\r\n };\r\n };\r\n /**\r\n * Invoke onInit callbacks synchronously\r\n * @param instance the service instance`\r\n */\r\n Provider.prototype.invokeOnInitCallbacks = function (instance, identifier) {\r\n var e_3, _a;\r\n var callbacks = this.onInitCallbacks.get(identifier);\r\n if (!callbacks) {\r\n return;\r\n }\r\n try {\r\n for (var callbacks_1 = __values(callbacks), callbacks_1_1 = callbacks_1.next(); !callbacks_1_1.done; callbacks_1_1 = callbacks_1.next()) {\r\n var callback = callbacks_1_1.value;\r\n try {\r\n callback(instance, identifier);\r\n }\r\n catch (_b) {\r\n // ignore errors in the onInit callback\r\n }\r\n }\r\n }\r\n catch (e_3_1) { e_3 = { error: e_3_1 }; }\r\n finally {\r\n try {\r\n if (callbacks_1_1 && !callbacks_1_1.done && (_a = callbacks_1.return)) _a.call(callbacks_1);\r\n }\r\n finally { if (e_3) throw e_3.error; }\r\n }\r\n };\r\n Provider.prototype.getOrInitializeService = function (_a) {\r\n var instanceIdentifier = _a.instanceIdentifier, _b = _a.options, options = _b === void 0 ? {} : _b;\r\n var instance = this.instances.get(instanceIdentifier);\r\n if (!instance && this.component) {\r\n instance = this.component.instanceFactory(this.container, {\r\n instanceIdentifier: normalizeIdentifierForFactory(instanceIdentifier),\r\n options: options\r\n });\r\n this.instances.set(instanceIdentifier, instance);\r\n this.instancesOptions.set(instanceIdentifier, options);\r\n /**\r\n * Invoke onInit listeners.\r\n * Note this.component.onInstanceCreated is different, which is used by the component creator,\r\n * while onInit listeners are registered by consumers of the provider.\r\n */\r\n this.invokeOnInitCallbacks(instance, instanceIdentifier);\r\n /**\r\n * Order is important\r\n * onInstanceCreated() should be called after this.instances.set(instanceIdentifier, instance); which\r\n * makes `isInitialized()` return true.\r\n */\r\n if (this.component.onInstanceCreated) {\r\n try {\r\n this.component.onInstanceCreated(this.container, instanceIdentifier, instance);\r\n }\r\n catch (_c) {\r\n // ignore errors in the onInstanceCreatedCallback\r\n }\r\n }\r\n }\r\n return instance || null;\r\n };\r\n Provider.prototype.normalizeInstanceIdentifier = function (identifier) {\r\n if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }\r\n if (this.component) {\r\n return this.component.multipleInstances ? identifier : DEFAULT_ENTRY_NAME;\r\n }\r\n else {\r\n return identifier; // assume multiple instances are supported before the component is provided.\r\n }\r\n };\r\n Provider.prototype.shouldAutoInitialize = function () {\r\n return (!!this.component &&\r\n this.component.instantiationMode !== \"EXPLICIT\" /* EXPLICIT */);\r\n };\r\n return Provider;\r\n}());\r\n// undefined should be passed to the service factory for the default instance\r\nfunction normalizeIdentifierForFactory(identifier) {\r\n return identifier === DEFAULT_ENTRY_NAME ? undefined : identifier;\r\n}\r\nfunction isComponentEager(component) {\r\n return component.instantiationMode === \"EAGER\" /* EAGER */;\r\n}\n\n/**\r\n * @license\r\n * Copyright 2019 Google LLC\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n/**\r\n * ComponentContainer that provides Providers for service name T, e.g. `auth`, `auth-internal`\r\n */\r\nvar ComponentContainer = /** @class */ (function () {\r\n function ComponentContainer(name) {\r\n this.name = name;\r\n this.providers = new Map();\r\n }\r\n /**\r\n *\r\n * @param component Component being added\r\n * @param overwrite When a component with the same name has already been registered,\r\n * if overwrite is true: overwrite the existing component with the new component and create a new\r\n * provider with the new component. It can be useful in tests where you want to use different mocks\r\n * for different tests.\r\n * if overwrite is false: throw an exception\r\n */\r\n ComponentContainer.prototype.addComponent = function (component) {\r\n var provider = this.getProvider(component.name);\r\n if (provider.isComponentSet()) {\r\n throw new Error(\"Component \" + component.name + \" has already been registered with \" + this.name);\r\n }\r\n provider.setComponent(component);\r\n };\r\n ComponentContainer.prototype.addOrOverwriteComponent = function (component) {\r\n var provider = this.getProvider(component.name);\r\n if (provider.isComponentSet()) {\r\n // delete the existing provider from the container, so we can register the new component\r\n this.providers.delete(component.name);\r\n }\r\n this.addComponent(component);\r\n };\r\n /**\r\n * getProvider provides a type safe interface where it can only be called with a field name\r\n * present in NameServiceMapping interface.\r\n *\r\n * Firebase SDKs providing services should extend NameServiceMapping interface to register\r\n * themselves.\r\n */\r\n ComponentContainer.prototype.getProvider = function (name) {\r\n if (this.providers.has(name)) {\r\n return this.providers.get(name);\r\n }\r\n // create a Provider for a service that hasn't registered with Firebase\r\n var provider = new Provider(name, this);\r\n this.providers.set(name, provider);\r\n return provider;\r\n };\r\n ComponentContainer.prototype.getProviders = function () {\r\n return Array.from(this.providers.values());\r\n };\r\n return ComponentContainer;\r\n}());\n\nexport { Component, ComponentContainer, Provider };\n//# sourceMappingURL=index.esm.js.map\n"],"sourceRoot":""}