UNPKG

@logback4js/google-analytics

Version:

Google Analytics Appenders for Logback4js.

1,536 lines 74.1 kB
import { JsonAppender as ve } from "@logback4js/core"; class zr extends ve { constructor(t) { super(), this.eventName = t; } get name() { return `ga@${this.eventName}`; } doAppend(t) { t.level.priority && gtag("event", this.eventName, this.getMessage(t)); } } var d = {}, b, y; function K() { throw new Error("setTimeout has not been defined"); } function z() { throw new Error("clearTimeout has not been defined"); } (function() { try { typeof setTimeout == "function" ? b = setTimeout : b = K; } catch { b = K; } try { typeof clearTimeout == "function" ? y = clearTimeout : y = z; } catch { y = z; } })(); function Ce(e) { if (b === setTimeout) return setTimeout(e, 0); if ((b === K || !b) && setTimeout) return b = setTimeout, setTimeout(e, 0); try { return b(e, 0); } catch { try { return b.call(null, e, 0); } catch { return b.call(this, e, 0); } } } function dt(e) { if (y === clearTimeout) return clearTimeout(e); if ((y === z || !y) && clearTimeout) return y = clearTimeout, clearTimeout(e); try { return y(e); } catch { try { return y.call(null, e); } catch { return y.call(this, e); } } } var w = [], M = !1, A, N = -1; function ft() { !M || !A || (M = !1, A.length ? w = A.concat(w) : N = -1, w.length && De()); } function De() { if (!M) { var e = Ce(ft); M = !0; for (var t = w.length; t; ) { for (A = w, w = []; ++N < t; ) A && A[N].run(); N = -1, t = w.length; } A = null, M = !1, dt(e); } } d.nextTick = function(e) { var t = new Array(arguments.length - 1); if (arguments.length > 1) for (var n = 1; n < arguments.length; n++) t[n - 1] = arguments[n]; w.push(new Re(e, t)), w.length === 1 && !M && Ce(De); }; function Re(e, t) { this.fun = e, this.array = t; } Re.prototype.run = function() { this.fun.apply(null, this.array); }; d.title = "browser"; d.browser = !0; d.env = {}; d.argv = []; d.version = ""; d.versions = {}; function T() { } d.on = T; d.addListener = T; d.once = T; d.off = T; d.removeListener = T; d.removeAllListeners = T; d.emit = T; d.prependListener = T; d.prependOnceListener = T; d.listeners = function(e) { return []; }; d.binding = function(e) { throw new Error("process.binding is not supported"); }; d.cwd = function() { return "/"; }; d.chdir = function(e) { throw new Error("process.chdir is not supported"); }; d.umask = function() { return 0; }; /** * @license * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const Be = function(e) { const t = []; let n = 0; for (let r = 0; r < e.length; r++) { let a = e.charCodeAt(r); a < 128 ? t[n++] = a : a < 2048 ? (t[n++] = a >> 6 | 192, t[n++] = a & 63 | 128) : (a & 64512) === 55296 && r + 1 < e.length && (e.charCodeAt(r + 1) & 64512) === 56320 ? (a = 65536 + ((a & 1023) << 10) + (e.charCodeAt(++r) & 1023), t[n++] = a >> 18 | 240, t[n++] = a >> 12 & 63 | 128, t[n++] = a >> 6 & 63 | 128, t[n++] = a & 63 | 128) : (t[n++] = a >> 12 | 224, t[n++] = a >> 6 & 63 | 128, t[n++] = a & 63 | 128); } return t; }, ht = function(e) { const t = []; let n = 0, r = 0; for (; n < e.length; ) { const a = e[n++]; if (a < 128) t[r++] = String.fromCharCode(a); else if (a > 191 && a < 224) { const s = e[n++]; t[r++] = String.fromCharCode((a & 31) << 6 | s & 63); } else if (a > 239 && a < 365) { const s = e[n++], i = e[n++], o = e[n++], c = ((a & 7) << 18 | (s & 63) << 12 | (i & 63) << 6 | o & 63) - 65536; t[r++] = String.fromCharCode(55296 + (c >> 10)), t[r++] = String.fromCharCode(56320 + (c & 1023)); } else { const s = e[n++], i = e[n++]; t[r++] = String.fromCharCode((a & 15) << 12 | (s & 63) << 6 | i & 63); } } return t.join(""); }, pt = { /** * Maps bytes to characters. */ byteToCharMap_: null, /** * Maps characters to bytes. */ charToByteMap_: null, /** * Maps bytes to websafe characters. * @private */ byteToCharMapWebSafe_: null, /** * Maps websafe characters to bytes. * @private */ charToByteMapWebSafe_: null, /** * Our default alphabet, shared between * ENCODED_VALS and ENCODED_VALS_WEBSAFE */ ENCODED_VALS_BASE: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", /** * Our default alphabet. Value 64 (=) is special; it means "nothing." */ get ENCODED_VALS() { return this.ENCODED_VALS_BASE + "+/="; }, /** * Our websafe alphabet. */ get ENCODED_VALS_WEBSAFE() { return this.ENCODED_VALS_BASE + "-_."; }, /** * Whether this browser supports the atob and btoa functions. This extension * started at Mozilla but is now implemented by many browsers. We use the * ASSUME_* variables to avoid pulling in the full useragent detection library * but still allowing the standard per-browser compilations. * */ HAS_NATIVE_SUPPORT: typeof atob == "function", /** * Base64-encode an array of bytes. * * @param input An array of bytes (numbers with * value in [0, 255]) to encode. * @param webSafe Boolean indicating we should use the * alternative alphabet. * @return The base64 encoded string. */ encodeByteArray(e, t) { if (!Array.isArray(e)) throw Error("encodeByteArray takes an array as a parameter"); this.init_(); const n = t ? this.byteToCharMapWebSafe_ : this.byteToCharMap_, r = []; for (let a = 0; a < e.length; a += 3) { const s = e[a], i = a + 1 < e.length, o = i ? e[a + 1] : 0, c = a + 2 < e.length, l = c ? e[a + 2] : 0, h = s >> 2, g = (s & 3) << 4 | o >> 4; let p = (o & 15) << 2 | l >> 6, P = l & 63; c || (P = 64, i || (p = 64)), r.push(n[h], n[g], n[p], n[P]); } return r.join(""); }, /** * Base64-encode a string. * * @param input A string to encode. * @param webSafe If true, we should use the * alternative alphabet. * @return The base64 encoded string. */ encodeString(e, t) { return this.HAS_NATIVE_SUPPORT && !t ? btoa(e) : this.encodeByteArray(Be(e), t); }, /** * Base64-decode a string. * * @param input to decode. * @param webSafe True if we should use the * alternative alphabet. * @return string representing the decoded value. */ decodeString(e, t) { return this.HAS_NATIVE_SUPPORT && !t ? atob(e) : ht(this.decodeStringToByteArray(e, t)); }, /** * Base64-decode a string. * * In base-64 decoding, groups of four characters are converted into three * bytes. If the encoder did not apply padding, the input length may not * be a multiple of 4. * * In this case, the last group will have fewer than 4 characters, and * padding will be inferred. If the group has one or two characters, it decodes * to one byte. If the group has three characters, it decodes to two bytes. * * @param input Input to decode. * @param webSafe True if we should use the web-safe alphabet. * @return bytes representing the decoded value. */ decodeStringToByteArray(e, t) { this.init_(); const n = t ? this.charToByteMapWebSafe_ : this.charToByteMap_, r = []; for (let a = 0; a < e.length; ) { const s = n[e.charAt(a++)], o = a < e.length ? n[e.charAt(a)] : 0; ++a; const l = a < e.length ? n[e.charAt(a)] : 64; ++a; const g = a < e.length ? n[e.charAt(a)] : 64; if (++a, s == null || o == null || l == null || g == null) throw new gt(); const p = s << 2 | o >> 4; if (r.push(p), l !== 64) { const P = o << 4 & 240 | l >> 2; if (r.push(P), g !== 64) { const ut = l << 6 & 192 | g; r.push(ut); } } } return r; }, /** * Lazy static initialization function. Called before * accessing any of the static map variables. * @private */ init_() { if (!this.byteToCharMap_) { this.byteToCharMap_ = {}, this.charToByteMap_ = {}, this.byteToCharMapWebSafe_ = {}, this.charToByteMapWebSafe_ = {}; for (let e = 0; e < this.ENCODED_VALS.length; e++) this.byteToCharMap_[e] = this.ENCODED_VALS.charAt(e), this.charToByteMap_[this.byteToCharMap_[e]] = e, this.byteToCharMapWebSafe_[e] = this.ENCODED_VALS_WEBSAFE.charAt(e), this.charToByteMapWebSafe_[this.byteToCharMapWebSafe_[e]] = e, e >= this.ENCODED_VALS_BASE.length && (this.charToByteMap_[this.ENCODED_VALS_WEBSAFE.charAt(e)] = e, this.charToByteMapWebSafe_[this.ENCODED_VALS.charAt(e)] = e); } } }; class gt extends Error { constructor() { super(...arguments), this.name = "DecodeBase64StringError"; } } const mt = function(e) { const t = Be(e); return pt.encodeByteArray(t, !0); }, Me = function(e) { return mt(e).replace(/\./g, ""); }; function bt() { const e = typeof chrome == "object" ? chrome.runtime : typeof browser == "object" ? browser.runtime : void 0; return typeof e == "object" && e.id !== void 0; } function $e() { try { return typeof indexedDB == "object"; } catch { return !1; } } function Oe() { return new Promise((e, t) => { try { let n = !0; const r = "validate-browser-context-for-indexeddb-analytics-module", a = self.indexedDB.open(r); a.onsuccess = () => { a.result.close(), n || self.indexedDB.deleteDatabase(r), e(!0); }, a.onupgradeneeded = () => { n = !1; }, a.onerror = () => { t(a.error?.message || ""); }; } catch (n) { t(n); } }); } function yt() { return !(typeof navigator > "u" || !navigator.cookieEnabled); } /** * @license * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const wt = "FirebaseError"; class B extends Error { constructor(t, n, r) { super(n), this.code = t, this.customData = r, this.name = wt, Object.setPrototypeOf(this, B.prototype), Error.captureStackTrace && Error.captureStackTrace(this, L.prototype.create); } } class L { constructor(t, n, r) { this.service = t, this.serviceName = n, this.errors = r; } create(t, ...n) { const r = n[0] || {}, a = `${this.service}/${t}`, s = this.errors[t], i = s ? It(s, r) : "Error", o = `${this.serviceName}: ${i} (${a}).`; return new B(a, o, r); } } function It(e, t) { return e.replace(Tt, (n, r) => { const a = t[r]; return a != null ? String(a) : `<${r}?>`; }); } const Tt = /\{\$([^}]+)}/g; /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const Et = 1e3, At = 2, St = 14400 * 1e3, _t = 0.5; function oe(e, t = Et, n = At) { const r = t * Math.pow(n, e), a = Math.round( // A fraction of the backoff value to add/subtract. // Deviation: changes multiplication order to improve readability. _t * r * // A random float (rounded to int by Math.round above) in the range [-1, 1]. Determines // if we add or subtract. (Math.random() - 0.5) * 2 ); return Math.min(St, r + a); } /** * @license * Copyright 2021 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function Pe(e) { return e && e._delegate ? e._delegate : e; } class v { /** * * @param name The public service name, e.g. app, auth, firestore, database * @param instanceFactory Service factory responsible for creating the public interface * @param type whether the service provided by the component is public or private */ constructor(t, n, r) { this.name = t, this.instanceFactory = n, this.type = r, this.multipleInstances = !1, this.serviceProps = {}, this.instantiationMode = "LAZY", this.onInstanceCreated = null; } setInstantiationMode(t) { return this.instantiationMode = t, this; } setMultipleInstances(t) { return this.multipleInstances = t, this; } setServiceProps(t) { return this.serviceProps = t, this; } setInstanceCreatedCallback(t) { return this.onInstanceCreated = t, this; } } /** * @license * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var u; (function(e) { e[e.DEBUG = 0] = "DEBUG", e[e.VERBOSE = 1] = "VERBOSE", e[e.INFO = 2] = "INFO", e[e.WARN = 3] = "WARN", e[e.ERROR = 4] = "ERROR", e[e.SILENT = 5] = "SILENT"; })(u || (u = {})); const vt = { debug: u.DEBUG, verbose: u.VERBOSE, info: u.INFO, warn: u.WARN, error: u.ERROR, silent: u.SILENT }, Ct = u.INFO, Dt = { [u.DEBUG]: "log", [u.VERBOSE]: "log", [u.INFO]: "info", [u.WARN]: "warn", [u.ERROR]: "error" }, Rt = (e, t, ...n) => { if (t < e.logLevel) return; const r = (/* @__PURE__ */ new Date()).toISOString(), a = Dt[t]; if (a) console[a](`[${r}] ${e.name}:`, ...n); else throw new Error(`Attempted to log a message with an invalid logType (value: ${t})`); }; class Ne { /** * Gives you an instance of a Logger to capture messages according to * Firebase's logging scheme. * * @param name The name that the logs will be associated with */ constructor(t) { this.name = t, this._logLevel = Ct, this._logHandler = Rt, this._userLogHandler = null; } get logLevel() { return this._logLevel; } set logLevel(t) { if (!(t in u)) throw new TypeError(`Invalid value "${t}" assigned to \`logLevel\``); this._logLevel = t; } // Workaround for setter/getter having to be the same type. setLogLevel(t) { this._logLevel = typeof t == "string" ? vt[t] : t; } get logHandler() { return this._logHandler; } set logHandler(t) { if (typeof t != "function") throw new TypeError("Value assigned to `logHandler` must be a function"); this._logHandler = t; } get userLogHandler() { return this._userLogHandler; } set userLogHandler(t) { this._userLogHandler = t; } /** * The functions below are all based on the `console` interface */ debug(...t) { this._userLogHandler && this._userLogHandler(this, u.DEBUG, ...t), this._logHandler(this, u.DEBUG, ...t); } log(...t) { this._userLogHandler && this._userLogHandler(this, u.VERBOSE, ...t), this._logHandler(this, u.VERBOSE, ...t); } info(...t) { this._userLogHandler && this._userLogHandler(this, u.INFO, ...t), this._logHandler(this, u.INFO, ...t); } warn(...t) { this._userLogHandler && this._userLogHandler(this, u.WARN, ...t), this._logHandler(this, u.WARN, ...t); } error(...t) { this._userLogHandler && this._userLogHandler(this, u.ERROR, ...t), this._logHandler(this, u.ERROR, ...t); } } const Bt = (e, t) => t.some((n) => e instanceof n); let ce, le; function Mt() { return ce || (ce = [ IDBDatabase, IDBObjectStore, IDBIndex, IDBCursor, IDBTransaction ]); } function $t() { return le || (le = [ IDBCursor.prototype.advance, IDBCursor.prototype.continue, IDBCursor.prototype.continuePrimaryKey ]); } const xe = /* @__PURE__ */ new WeakMap(), Y = /* @__PURE__ */ new WeakMap(), Le = /* @__PURE__ */ new WeakMap(), H = /* @__PURE__ */ new WeakMap(), Z = /* @__PURE__ */ new WeakMap(); function Ot(e) { const t = new Promise((n, r) => { const a = () => { e.removeEventListener("success", s), e.removeEventListener("error", i); }, s = () => { n(E(e.result)), a(); }, i = () => { r(e.error), a(); }; e.addEventListener("success", s), e.addEventListener("error", i); }); return t.then((n) => { n instanceof IDBCursor && xe.set(n, e); }).catch(() => { }), Z.set(t, e), t; } function Pt(e) { if (Y.has(e)) return; const t = new Promise((n, r) => { const a = () => { e.removeEventListener("complete", s), e.removeEventListener("error", i), e.removeEventListener("abort", i); }, s = () => { n(), a(); }, i = () => { r(e.error || new DOMException("AbortError", "AbortError")), a(); }; e.addEventListener("complete", s), e.addEventListener("error", i), e.addEventListener("abort", i); }); Y.set(e, t); } let J = { get(e, t, n) { if (e instanceof IDBTransaction) { if (t === "done") return Y.get(e); if (t === "objectStoreNames") return e.objectStoreNames || Le.get(e); if (t === "store") return n.objectStoreNames[1] ? void 0 : n.objectStore(n.objectStoreNames[0]); } return E(e[t]); }, set(e, t, n) { return e[t] = n, !0; }, has(e, t) { return e instanceof IDBTransaction && (t === "done" || t === "store") ? !0 : t in e; } }; function Nt(e) { J = e(J); } function xt(e) { return e === IDBDatabase.prototype.transaction && !("objectStoreNames" in IDBTransaction.prototype) ? function(t, ...n) { const r = e.call(V(this), t, ...n); return Le.set(r, t.sort ? t.sort() : [t]), E(r); } : $t().includes(e) ? function(...t) { return e.apply(V(this), t), E(xe.get(this)); } : function(...t) { return E(e.apply(V(this), t)); }; } function Lt(e) { return typeof e == "function" ? xt(e) : (e instanceof IDBTransaction && Pt(e), Bt(e, Mt()) ? new Proxy(e, J) : e); } function E(e) { if (e instanceof IDBRequest) return Ot(e); if (H.has(e)) return H.get(e); const t = Lt(e); return t !== e && (H.set(e, t), Z.set(t, e)), t; } const V = (e) => Z.get(e); function ke(e, t, { blocked: n, upgrade: r, blocking: a, terminated: s } = {}) { const i = indexedDB.open(e, t), o = E(i); return r && i.addEventListener("upgradeneeded", (c) => { r(E(i.result), c.oldVersion, c.newVersion, E(i.transaction), c); }), n && i.addEventListener("blocked", (c) => n( // Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405 c.oldVersion, c.newVersion, c )), o.then((c) => { s && c.addEventListener("close", () => s()), a && c.addEventListener("versionchange", (l) => a(l.oldVersion, l.newVersion, l)); }).catch(() => { }), o; } const kt = ["get", "getKey", "getAll", "getAllKeys", "count"], Ft = ["put", "add", "delete", "clear"], j = /* @__PURE__ */ new Map(); function ue(e, t) { if (!(e instanceof IDBDatabase && !(t in e) && typeof t == "string")) return; if (j.get(t)) return j.get(t); const n = t.replace(/FromIndex$/, ""), r = t !== n, a = Ft.includes(n); if ( // Bail if the target doesn't exist on the target. Eg, getAll isn't in Edge. !(n in (r ? IDBIndex : IDBObjectStore).prototype) || !(a || kt.includes(n)) ) return; const s = async function(i, ...o) { const c = this.transaction(i, a ? "readwrite" : "readonly"); let l = c.store; return r && (l = l.index(o.shift())), (await Promise.all([ l[n](...o), a && c.done ]))[0]; }; return j.set(t, s), s; } Nt((e) => ({ ...e, get: (t, n, r) => ue(t, n) || e.get(t, n, r), has: (t, n) => !!ue(t, n) || e.has(t, n) })); /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ class Ht { constructor(t) { this.container = t; } // In initial implementation, this will be called by installations on // auth token refresh, and installations will send this string. getPlatformInfoString() { return this.container.getProviders().map((n) => { if (Vt(n)) { const r = n.getImmediate(); return `${r.library}/${r.version}`; } else return null; }).filter((n) => n).join(" "); } } function Vt(e) { return e.getComponent()?.type === "VERSION"; } const X = "@firebase/app", de = "0.14.4"; /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const I = new Ne("@firebase/app"), jt = "@firebase/app-compat", Ut = "@firebase/analytics-compat", Wt = "@firebase/analytics", qt = "@firebase/app-check-compat", Gt = "@firebase/app-check", Kt = "@firebase/auth", zt = "@firebase/auth-compat", Yt = "@firebase/database", Jt = "@firebase/data-connect", Xt = "@firebase/database-compat", Qt = "@firebase/functions", Zt = "@firebase/functions-compat", en = "@firebase/installations", tn = "@firebase/installations-compat", nn = "@firebase/messaging", rn = "@firebase/messaging-compat", an = "@firebase/performance", sn = "@firebase/performance-compat", on = "@firebase/remote-config", cn = "@firebase/remote-config-compat", ln = "@firebase/storage", un = "@firebase/storage-compat", dn = "@firebase/firestore", fn = "@firebase/ai", hn = "@firebase/firestore-compat", pn = "firebase", gn = { [X]: "fire-core", [jt]: "fire-core-compat", [Wt]: "fire-analytics", [Ut]: "fire-analytics-compat", [Gt]: "fire-app-check", [qt]: "fire-app-check-compat", [Kt]: "fire-auth", [zt]: "fire-auth-compat", [Yt]: "fire-rtdb", [Jt]: "fire-data-connect", [Xt]: "fire-rtdb-compat", [Qt]: "fire-fn", [Zt]: "fire-fn-compat", [en]: "fire-iid", [tn]: "fire-iid-compat", [nn]: "fire-fcm", [rn]: "fire-fcm-compat", [an]: "fire-perf", [sn]: "fire-perf-compat", [on]: "fire-rc", [cn]: "fire-rc-compat", [ln]: "fire-gcs", [un]: "fire-gcs-compat", [dn]: "fire-fst", [hn]: "fire-fst-compat", [fn]: "fire-vertex", "fire-js": "fire-js", // Platform identifier for JS SDK. [pn]: "fire-js-all" }; /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const mn = /* @__PURE__ */ new Map(), bn = /* @__PURE__ */ new Map(), fe = /* @__PURE__ */ new Map(); function he(e, t) { try { e.container.addComponent(t); } catch (n) { I.debug(`Component ${t.name} failed to register with FirebaseApp ${e.name}`, n); } } function C(e) { const t = e.name; if (fe.has(t)) return I.debug(`There were multiple attempts to register component ${t}.`), !1; fe.set(t, e); for (const n of mn.values()) he(n, e); for (const n of bn.values()) he(n, e); return !0; } function Fe(e, t) { const n = e.container.getProvider("heartbeat").getImmediate({ optional: !0 }); return n && n.triggerHeartbeat(), e.container.getProvider(t); } /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const yn = { "no-app": "No Firebase App '{$appName}' has been created - call initializeApp() first", "bad-app-name": "Illegal App name: '{$appName}'", "duplicate-app": "Firebase App named '{$appName}' already exists with different options or config", "app-deleted": "Firebase App named '{$appName}' already deleted", "server-app-deleted": "Firebase Server App has been deleted", "no-options": "Need to provide options, when not being deployed to hosting via source.", "invalid-app-argument": "firebase.{$appName}() takes either no argument or a Firebase App instance.", "invalid-log-argument": "First argument to `onLog` must be null or a function.", "idb-open": "Error thrown when opening IndexedDB. Original error: {$originalErrorMessage}.", "idb-get": "Error thrown when reading from IndexedDB. Original error: {$originalErrorMessage}.", "idb-set": "Error thrown when writing to IndexedDB. Original error: {$originalErrorMessage}.", "idb-delete": "Error thrown when deleting from IndexedDB. Original error: {$originalErrorMessage}.", "finalization-registry-not-supported": "FirebaseServerApp deleteOnDeref field defined but the JS runtime does not support FinalizationRegistry.", "invalid-server-app-environment": "FirebaseServerApp is not for use in browser environments." }, ee = new L("app", "Firebase", yn); function _(e, t, n) { let r = gn[e] ?? e; n && (r += `-${n}`); const a = r.match(/\s|\//), s = t.match(/\s|\//); if (a || s) { const i = [ `Unable to register library "${r}" with version "${t}":` ]; a && i.push(`library name "${r}" contains illegal characters (whitespace or "/")`), a && s && i.push("and"), s && i.push(`version name "${t}" contains illegal characters (whitespace or "/")`), I.warn(i.join(" ")); return; } C(new v( `${r}-version`, () => ({ library: r, version: t }), "VERSION" /* ComponentType.VERSION */ )); } /** * @license * Copyright 2021 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const wn = "firebase-heartbeat-database", In = 1, O = "firebase-heartbeat-store"; let U = null; function He() { return U || (U = ke(wn, In, { upgrade: (e, t) => { switch (t) { case 0: try { e.createObjectStore(O); } catch (n) { console.warn(n); } } } }).catch((e) => { throw ee.create("idb-open", { originalErrorMessage: e.message }); })), U; } async function Tn(e) { try { const n = (await He()).transaction(O), r = await n.objectStore(O).get(Ve(e)); return await n.done, r; } catch (t) { if (t instanceof B) I.warn(t.message); else { const n = ee.create("idb-get", { originalErrorMessage: t?.message }); I.warn(n.message); } } } async function pe(e, t) { try { const r = (await He()).transaction(O, "readwrite"); await r.objectStore(O).put(t, Ve(e)), await r.done; } catch (n) { if (n instanceof B) I.warn(n.message); else { const r = ee.create("idb-set", { originalErrorMessage: n?.message }); I.warn(r.message); } } } function Ve(e) { return `${e.name}!${e.options.appId}`; } /** * @license * Copyright 2021 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const En = 1024, An = 30; class Sn { constructor(t) { this.container = t, this._heartbeatsCache = null; const n = this.container.getProvider("app").getImmediate(); this._storage = new vn(n), this._heartbeatsCachePromise = this._storage.read().then((r) => (this._heartbeatsCache = r, r)); } /** * Called to report a heartbeat. The function will generate * a HeartbeatsByUserAgent object, update heartbeatsCache, and persist it * to IndexedDB. * Note that we only store one heartbeat per day. So if a heartbeat for today is * already logged, subsequent calls to this function in the same day will be ignored. */ async triggerHeartbeat() { try { const n = this.container.getProvider("platform-logger").getImmediate().getPlatformInfoString(), r = ge(); if (this._heartbeatsCache?.heartbeats == null && (this._heartbeatsCache = await this._heartbeatsCachePromise, this._heartbeatsCache?.heartbeats == null) || this._heartbeatsCache.lastSentHeartbeatDate === r || this._heartbeatsCache.heartbeats.some((a) => a.date === r)) return; if (this._heartbeatsCache.heartbeats.push({ date: r, agent: n }), this._heartbeatsCache.heartbeats.length > An) { const a = Cn(this._heartbeatsCache.heartbeats); this._heartbeatsCache.heartbeats.splice(a, 1); } return this._storage.overwrite(this._heartbeatsCache); } catch (t) { I.warn(t); } } /** * Returns a base64 encoded string which can be attached to the heartbeat-specific header directly. * It also clears all heartbeats from memory as well as in IndexedDB. * * NOTE: Consuming product SDKs should not send the header if this method * returns an empty string. */ async getHeartbeatsHeader() { try { if (this._heartbeatsCache === null && await this._heartbeatsCachePromise, this._heartbeatsCache?.heartbeats == null || this._heartbeatsCache.heartbeats.length === 0) return ""; const t = ge(), { heartbeatsToSend: n, unsentEntries: r } = _n(this._heartbeatsCache.heartbeats), a = Me(JSON.stringify({ version: 2, heartbeats: n })); return this._heartbeatsCache.lastSentHeartbeatDate = t, r.length > 0 ? (this._heartbeatsCache.heartbeats = r, await this._storage.overwrite(this._heartbeatsCache)) : (this._heartbeatsCache.heartbeats = [], this._storage.overwrite(this._heartbeatsCache)), a; } catch (t) { return I.warn(t), ""; } } } function ge() { return (/* @__PURE__ */ new Date()).toISOString().substring(0, 10); } function _n(e, t = En) { const n = []; let r = e.slice(); for (const a of e) { const s = n.find((i) => i.agent === a.agent); if (s) { if (s.dates.push(a.date), me(n) > t) { s.dates.pop(); break; } } else if (n.push({ agent: a.agent, dates: [a.date] }), me(n) > t) { n.pop(); break; } r = r.slice(1); } return { heartbeatsToSend: n, unsentEntries: r }; } class vn { constructor(t) { this.app = t, this._canUseIndexedDBPromise = this.runIndexedDBEnvironmentCheck(); } async runIndexedDBEnvironmentCheck() { return $e() ? Oe().then(() => !0).catch(() => !1) : !1; } /** * Read all heartbeats. */ async read() { if (await this._canUseIndexedDBPromise) { const n = await Tn(this.app); return n?.heartbeats ? n : { heartbeats: [] }; } else return { heartbeats: [] }; } // overwrite the storage with the provided heartbeats async overwrite(t) { if (await this._canUseIndexedDBPromise) { const r = await this.read(); return pe(this.app, { lastSentHeartbeatDate: t.lastSentHeartbeatDate ?? r.lastSentHeartbeatDate, heartbeats: t.heartbeats }); } else return; } // add heartbeats async add(t) { if (await this._canUseIndexedDBPromise) { const r = await this.read(); return pe(this.app, { lastSentHeartbeatDate: t.lastSentHeartbeatDate ?? r.lastSentHeartbeatDate, heartbeats: [ ...r.heartbeats, ...t.heartbeats ] }); } else return; } } function me(e) { return Me( // heartbeatsCache wrapper properties JSON.stringify({ version: 2, heartbeats: e }) ).length; } function Cn(e) { if (e.length === 0) return -1; let t = 0, n = e[0].date; for (let r = 1; r < e.length; r++) e[r].date < n && (n = e[r].date, t = r); return t; } /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function Dn(e) { C(new v( "platform-logger", (t) => new Ht(t), "PRIVATE" /* ComponentType.PRIVATE */ )), C(new v( "heartbeat", (t) => new Sn(t), "PRIVATE" /* ComponentType.PRIVATE */ )), _(X, de, e), _(X, de, "esm2020"), _("fire-js", ""); } Dn(""); const je = "@firebase/installations", te = "0.6.19"; /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const Ue = 1e4, We = `w:${te}`, qe = "FIS_v2", Rn = "https://firebaseinstallations.googleapis.com/v1", Bn = 3600 * 1e3, Mn = "installations", $n = "Installations"; /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const On = { "missing-app-config-values": 'Missing App configuration value: "{$valueName}"', "not-registered": "Firebase Installation is not registered.", "installation-not-found": "Firebase Installation not found.", "request-failed": '{$requestName} request failed with error "{$serverCode} {$serverStatus}: {$serverMessage}"', "app-offline": "Could not process request. Application offline.", "delete-pending-registration": "Can't delete installation while there is a pending registration request." }, D = new L(Mn, $n, On); function Ge(e) { return e instanceof B && e.code.includes( "request-failed" /* ErrorCode.REQUEST_FAILED */ ); } /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function Ke({ projectId: e }) { return `${Rn}/projects/${e}/installations`; } function ze(e) { return { token: e.token, requestStatus: 2, expiresIn: Nn(e.expiresIn), creationTime: Date.now() }; } async function Ye(e, t) { const r = (await t.json()).error; return D.create("request-failed", { requestName: e, serverCode: r.code, serverMessage: r.message, serverStatus: r.status }); } function Je({ apiKey: e }) { return new Headers({ "Content-Type": "application/json", Accept: "application/json", "x-goog-api-key": e }); } function Pn(e, { refreshToken: t }) { const n = Je(e); return n.append("Authorization", xn(t)), n; } async function Xe(e) { const t = await e(); return t.status >= 500 && t.status < 600 ? e() : t; } function Nn(e) { return Number(e.replace("s", "000")); } function xn(e) { return `${qe} ${e}`; } /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ async function Ln({ appConfig: e, heartbeatServiceProvider: t }, { fid: n }) { const r = Ke(e), a = Je(e), s = t.getImmediate({ optional: !0 }); if (s) { const l = await s.getHeartbeatsHeader(); l && a.append("x-firebase-client", l); } const i = { fid: n, authVersion: qe, appId: e.appId, sdkVersion: We }, o = { method: "POST", headers: a, body: JSON.stringify(i) }, c = await Xe(() => fetch(r, o)); if (c.ok) { const l = await c.json(); return { fid: l.fid || n, registrationStatus: 2, refreshToken: l.refreshToken, authToken: ze(l.authToken) }; } else throw await Ye("Create Installation", c); } /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function Qe(e) { return new Promise((t) => { setTimeout(t, e); }); } /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function kn(e) { return btoa(String.fromCharCode(...e)).replace(/\+/g, "-").replace(/\//g, "_"); } /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const Fn = /^[cdef][\w-]{21}$/, Q = ""; function Hn() { try { const e = new Uint8Array(17); (self.crypto || self.msCrypto).getRandomValues(e), e[0] = 112 + e[0] % 16; const n = Vn(e); return Fn.test(n) ? n : Q; } catch { return Q; } } function Vn(e) { return kn(e).substr(0, 22); } /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function k(e) { return `${e.appName}!${e.appId}`; } /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const Ze = /* @__PURE__ */ new Map(); function et(e, t) { const n = k(e); tt(n, t), jn(n, t); } function tt(e, t) { const n = Ze.get(e); if (n) for (const r of n) r(t); } function jn(e, t) { const n = Un(); n && n.postMessage({ key: e, fid: t }), Wn(); } let S = null; function Un() { return !S && "BroadcastChannel" in self && (S = new BroadcastChannel("[Firebase] FID Change"), S.onmessage = (e) => { tt(e.data.key, e.data.fid); }), S; } function Wn() { Ze.size === 0 && S && (S.close(), S = null); } /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const qn = "firebase-installations-database", Gn = 1, R = "firebase-installations-store"; let W = null; function ne() { return W || (W = ke(qn, Gn, { upgrade: (e, t) => { switch (t) { case 0: e.createObjectStore(R); } } })), W; } async function x(e, t) { const n = k(e), a = (await ne()).transaction(R, "readwrite"), s = a.objectStore(R), i = await s.get(n); return await s.put(t, n), await a.done, (!i || i.fid !== t.fid) && et(e, t.fid), t; } async function nt(e) { const t = k(e), r = (await ne()).transaction(R, "readwrite"); await r.objectStore(R).delete(t), await r.done; } async function F(e, t) { const n = k(e), a = (await ne()).transaction(R, "readwrite"), s = a.objectStore(R), i = await s.get(n), o = t(i); return o === void 0 ? await s.delete(n) : await s.put(o, n), await a.done, o && (!i || i.fid !== o.fid) && et(e, o.fid), o; } /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ async function re(e) { let t; const n = await F(e.appConfig, (r) => { const a = Kn(r), s = zn(e, a); return t = s.registrationPromise, s.installationEntry; }); return n.fid === Q ? { installationEntry: await t } : { installationEntry: n, registrationPromise: t }; } function Kn(e) { const t = e || { fid: Hn(), registrationStatus: 0 /* RequestStatus.NOT_STARTED */ }; return rt(t); } function zn(e, t) { if (t.registrationStatus === 0) { if (!navigator.onLine) { const a = Promise.reject(D.create( "app-offline" /* ErrorCode.APP_OFFLINE */ )); return { installationEntry: t, registrationPromise: a }; } const n = { fid: t.fid, registrationStatus: 1, registrationTime: Date.now() }, r = Yn(e, n); return { installationEntry: n, registrationPromise: r }; } else return t.registrationStatus === 1 ? { installationEntry: t, registrationPromise: Jn(e) } : { installationEntry: t }; } async function Yn(e, t) { try { const n = await Ln(e, t); return x(e.appConfig, n); } catch (n) { throw Ge(n) && n.customData.serverCode === 409 ? await nt(e.appConfig) : await x(e.appConfig, { fid: t.fid, registrationStatus: 0 /* RequestStatus.NOT_STARTED */ }), n; } } async function Jn(e) { let t = await be(e.appConfig); for (; t.registrationStatus === 1; ) await Qe(100), t = await be(e.appConfig); if (t.registrationStatus === 0) { const { installationEntry: n, registrationPromise: r } = await re(e); return r || n; } return t; } function be(e) { return F(e, (t) => { if (!t) throw D.create( "installation-not-found" /* ErrorCode.INSTALLATION_NOT_FOUND */ ); return rt(t); }); } function rt(e) { return Xn(e) ? { fid: e.fid, registrationStatus: 0 /* RequestStatus.NOT_STARTED */ } : e; } function Xn(e) { return e.registrationStatus === 1 && e.registrationTime + Ue < Date.now(); } /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ async function Qn({ appConfig: e,