prompt-api-polyfill 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +27 -7
- package/dist/backends/firebase.js +1808 -0
- package/dist/backends/gemini.js +55 -0
- package/dist/backends/openai.js +199 -0
- package/dist/backends/transformers.js +254 -0
- package/{backends/base.js → dist/chunks/defaults-CNQngzSd.js} +28 -23
- package/dist/prompt-api-polyfill.js +1040 -0
- package/dot_env.json +3 -0
- package/package.json +21 -16
- package/async-iterator-polyfill.js +0 -16
- package/backends/defaults.js +0 -13
- package/backends/firebase.js +0 -49
- package/backends/gemini.js +0 -52
- package/backends/openai.js +0 -337
- package/backends/transformers.js +0 -451
- package/json-schema-converter.js +0 -88
- package/multimodal-converter.js +0 -383
- package/prompt-api-polyfill.js +0 -1467
|
@@ -0,0 +1,1808 @@
|
|
|
1
|
+
import { initializeApp as Fe } from "firebase/app";
|
|
2
|
+
import { VertexAIBackend as ze, GoogleAIBackend as Ue, getAI as je, getGenerativeModel as Ve, InferenceMode as We } from "firebase/ai";
|
|
3
|
+
import { P as Ke, D as Ge } from "../chunks/defaults-CNQngzSd.js";
|
|
4
|
+
const qe = () => {
|
|
5
|
+
};
|
|
6
|
+
const be = function(t) {
|
|
7
|
+
const e = [];
|
|
8
|
+
let r = 0;
|
|
9
|
+
for (let n = 0; n < t.length; n++) {
|
|
10
|
+
let s = t.charCodeAt(n);
|
|
11
|
+
s < 128 ? e[r++] = s : s < 2048 ? (e[r++] = s >> 6 | 192, e[r++] = s & 63 | 128) : (s & 64512) === 55296 && n + 1 < t.length && (t.charCodeAt(n + 1) & 64512) === 56320 ? (s = 65536 + ((s & 1023) << 10) + (t.charCodeAt(++n) & 1023), e[r++] = s >> 18 | 240, e[r++] = s >> 12 & 63 | 128, e[r++] = s >> 6 & 63 | 128, e[r++] = s & 63 | 128) : (e[r++] = s >> 12 | 224, e[r++] = s >> 6 & 63 | 128, e[r++] = s & 63 | 128);
|
|
12
|
+
}
|
|
13
|
+
return e;
|
|
14
|
+
}, Xe = function(t) {
|
|
15
|
+
const e = [];
|
|
16
|
+
let r = 0, n = 0;
|
|
17
|
+
for (; r < t.length; ) {
|
|
18
|
+
const s = t[r++];
|
|
19
|
+
if (s < 128)
|
|
20
|
+
e[n++] = String.fromCharCode(s);
|
|
21
|
+
else if (s > 191 && s < 224) {
|
|
22
|
+
const o = t[r++];
|
|
23
|
+
e[n++] = String.fromCharCode((s & 31) << 6 | o & 63);
|
|
24
|
+
} else if (s > 239 && s < 365) {
|
|
25
|
+
const o = t[r++], i = t[r++], c = t[r++], a = ((s & 7) << 18 | (o & 63) << 12 | (i & 63) << 6 | c & 63) - 65536;
|
|
26
|
+
e[n++] = String.fromCharCode(55296 + (a >> 10)), e[n++] = String.fromCharCode(56320 + (a & 1023));
|
|
27
|
+
} else {
|
|
28
|
+
const o = t[r++], i = t[r++];
|
|
29
|
+
e[n++] = String.fromCharCode((s & 15) << 12 | (o & 63) << 6 | i & 63);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return e.join("");
|
|
33
|
+
}, q = {
|
|
34
|
+
/**
|
|
35
|
+
* Maps bytes to characters.
|
|
36
|
+
*/
|
|
37
|
+
byteToCharMap_: null,
|
|
38
|
+
/**
|
|
39
|
+
* Maps characters to bytes.
|
|
40
|
+
*/
|
|
41
|
+
charToByteMap_: null,
|
|
42
|
+
/**
|
|
43
|
+
* Maps bytes to websafe characters.
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
byteToCharMapWebSafe_: null,
|
|
47
|
+
/**
|
|
48
|
+
* Maps websafe characters to bytes.
|
|
49
|
+
* @private
|
|
50
|
+
*/
|
|
51
|
+
charToByteMapWebSafe_: null,
|
|
52
|
+
/**
|
|
53
|
+
* Our default alphabet, shared between
|
|
54
|
+
* ENCODED_VALS and ENCODED_VALS_WEBSAFE
|
|
55
|
+
*/
|
|
56
|
+
ENCODED_VALS_BASE: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
|
57
|
+
/**
|
|
58
|
+
* Our default alphabet. Value 64 (=) is special; it means "nothing."
|
|
59
|
+
*/
|
|
60
|
+
get ENCODED_VALS() {
|
|
61
|
+
return this.ENCODED_VALS_BASE + "+/=";
|
|
62
|
+
},
|
|
63
|
+
/**
|
|
64
|
+
* Our websafe alphabet.
|
|
65
|
+
*/
|
|
66
|
+
get ENCODED_VALS_WEBSAFE() {
|
|
67
|
+
return this.ENCODED_VALS_BASE + "-_.";
|
|
68
|
+
},
|
|
69
|
+
/**
|
|
70
|
+
* Whether this browser supports the atob and btoa functions. This extension
|
|
71
|
+
* started at Mozilla but is now implemented by many browsers. We use the
|
|
72
|
+
* ASSUME_* variables to avoid pulling in the full useragent detection library
|
|
73
|
+
* but still allowing the standard per-browser compilations.
|
|
74
|
+
*
|
|
75
|
+
*/
|
|
76
|
+
HAS_NATIVE_SUPPORT: typeof atob == "function",
|
|
77
|
+
/**
|
|
78
|
+
* Base64-encode an array of bytes.
|
|
79
|
+
*
|
|
80
|
+
* @param input An array of bytes (numbers with
|
|
81
|
+
* value in [0, 255]) to encode.
|
|
82
|
+
* @param webSafe Boolean indicating we should use the
|
|
83
|
+
* alternative alphabet.
|
|
84
|
+
* @return The base64 encoded string.
|
|
85
|
+
*/
|
|
86
|
+
encodeByteArray(t, e) {
|
|
87
|
+
if (!Array.isArray(t))
|
|
88
|
+
throw Error("encodeByteArray takes an array as a parameter");
|
|
89
|
+
this.init_();
|
|
90
|
+
const r = e ? this.byteToCharMapWebSafe_ : this.byteToCharMap_, n = [];
|
|
91
|
+
for (let s = 0; s < t.length; s += 3) {
|
|
92
|
+
const o = t[s], i = s + 1 < t.length, c = i ? t[s + 1] : 0, a = s + 2 < t.length, l = a ? t[s + 2] : 0, y = o >> 2, f = (o & 3) << 4 | c >> 4;
|
|
93
|
+
let k = (c & 15) << 2 | l >> 6, S = l & 63;
|
|
94
|
+
a || (S = 64, i || (k = 64)), n.push(r[y], r[f], r[k], r[S]);
|
|
95
|
+
}
|
|
96
|
+
return n.join("");
|
|
97
|
+
},
|
|
98
|
+
/**
|
|
99
|
+
* Base64-encode a string.
|
|
100
|
+
*
|
|
101
|
+
* @param input A string to encode.
|
|
102
|
+
* @param webSafe If true, we should use the
|
|
103
|
+
* alternative alphabet.
|
|
104
|
+
* @return The base64 encoded string.
|
|
105
|
+
*/
|
|
106
|
+
encodeString(t, e) {
|
|
107
|
+
return this.HAS_NATIVE_SUPPORT && !e ? btoa(t) : this.encodeByteArray(be(t), e);
|
|
108
|
+
},
|
|
109
|
+
/**
|
|
110
|
+
* Base64-decode a string.
|
|
111
|
+
*
|
|
112
|
+
* @param input to decode.
|
|
113
|
+
* @param webSafe True if we should use the
|
|
114
|
+
* alternative alphabet.
|
|
115
|
+
* @return string representing the decoded value.
|
|
116
|
+
*/
|
|
117
|
+
decodeString(t, e) {
|
|
118
|
+
return this.HAS_NATIVE_SUPPORT && !e ? atob(t) : Xe(this.decodeStringToByteArray(t, e));
|
|
119
|
+
},
|
|
120
|
+
/**
|
|
121
|
+
* Base64-decode a string.
|
|
122
|
+
*
|
|
123
|
+
* In base-64 decoding, groups of four characters are converted into three
|
|
124
|
+
* bytes. If the encoder did not apply padding, the input length may not
|
|
125
|
+
* be a multiple of 4.
|
|
126
|
+
*
|
|
127
|
+
* In this case, the last group will have fewer than 4 characters, and
|
|
128
|
+
* padding will be inferred. If the group has one or two characters, it decodes
|
|
129
|
+
* to one byte. If the group has three characters, it decodes to two bytes.
|
|
130
|
+
*
|
|
131
|
+
* @param input Input to decode.
|
|
132
|
+
* @param webSafe True if we should use the web-safe alphabet.
|
|
133
|
+
* @return bytes representing the decoded value.
|
|
134
|
+
*/
|
|
135
|
+
decodeStringToByteArray(t, e) {
|
|
136
|
+
this.init_();
|
|
137
|
+
const r = e ? this.charToByteMapWebSafe_ : this.charToByteMap_, n = [];
|
|
138
|
+
for (let s = 0; s < t.length; ) {
|
|
139
|
+
const o = r[t.charAt(s++)], c = s < t.length ? r[t.charAt(s)] : 0;
|
|
140
|
+
++s;
|
|
141
|
+
const l = s < t.length ? r[t.charAt(s)] : 64;
|
|
142
|
+
++s;
|
|
143
|
+
const f = s < t.length ? r[t.charAt(s)] : 64;
|
|
144
|
+
if (++s, o == null || c == null || l == null || f == null)
|
|
145
|
+
throw new Ye();
|
|
146
|
+
const k = o << 2 | c >> 4;
|
|
147
|
+
if (n.push(k), l !== 64) {
|
|
148
|
+
const S = c << 4 & 240 | l >> 2;
|
|
149
|
+
if (n.push(S), f !== 64) {
|
|
150
|
+
const He = l << 6 & 192 | f;
|
|
151
|
+
n.push(He);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return n;
|
|
156
|
+
},
|
|
157
|
+
/**
|
|
158
|
+
* Lazy static initialization function. Called before
|
|
159
|
+
* accessing any of the static map variables.
|
|
160
|
+
* @private
|
|
161
|
+
*/
|
|
162
|
+
init_() {
|
|
163
|
+
if (!this.byteToCharMap_) {
|
|
164
|
+
this.byteToCharMap_ = {}, this.charToByteMap_ = {}, this.byteToCharMapWebSafe_ = {}, this.charToByteMapWebSafe_ = {};
|
|
165
|
+
for (let t = 0; t < this.ENCODED_VALS.length; t++)
|
|
166
|
+
this.byteToCharMap_[t] = this.ENCODED_VALS.charAt(t), this.charToByteMap_[this.byteToCharMap_[t]] = t, this.byteToCharMapWebSafe_[t] = this.ENCODED_VALS_WEBSAFE.charAt(t), this.charToByteMapWebSafe_[this.byteToCharMapWebSafe_[t]] = t, t >= this.ENCODED_VALS_BASE.length && (this.charToByteMap_[this.ENCODED_VALS_WEBSAFE.charAt(t)] = t, this.charToByteMapWebSafe_[this.ENCODED_VALS.charAt(t)] = t);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
class Ye extends Error {
|
|
171
|
+
constructor() {
|
|
172
|
+
super(...arguments), this.name = "DecodeBase64StringError";
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const Je = function(t) {
|
|
176
|
+
const e = be(t);
|
|
177
|
+
return q.encodeByteArray(e, !0);
|
|
178
|
+
}, Ee = function(t) {
|
|
179
|
+
return Je(t).replace(/\./g, "");
|
|
180
|
+
}, Ze = function(t) {
|
|
181
|
+
try {
|
|
182
|
+
return q.decodeString(t, !0);
|
|
183
|
+
} catch (e) {
|
|
184
|
+
console.error("base64Decode failed: ", e);
|
|
185
|
+
}
|
|
186
|
+
return null;
|
|
187
|
+
};
|
|
188
|
+
function _e() {
|
|
189
|
+
if (typeof self < "u")
|
|
190
|
+
return self;
|
|
191
|
+
if (typeof window < "u")
|
|
192
|
+
return window;
|
|
193
|
+
if (typeof global < "u")
|
|
194
|
+
return global;
|
|
195
|
+
throw new Error("Unable to locate global object.");
|
|
196
|
+
}
|
|
197
|
+
const Qe = () => _e().__FIREBASE_DEFAULTS__, et = () => {
|
|
198
|
+
if (typeof process > "u" || typeof process.env > "u")
|
|
199
|
+
return;
|
|
200
|
+
const t = process.env.__FIREBASE_DEFAULTS__;
|
|
201
|
+
if (t)
|
|
202
|
+
return JSON.parse(t);
|
|
203
|
+
}, tt = () => {
|
|
204
|
+
if (typeof document > "u")
|
|
205
|
+
return;
|
|
206
|
+
let t;
|
|
207
|
+
try {
|
|
208
|
+
t = document.cookie.match(/__FIREBASE_DEFAULTS__=([^;]+)/);
|
|
209
|
+
} catch {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const e = t && Ze(t[1]);
|
|
213
|
+
return e && JSON.parse(e);
|
|
214
|
+
}, rt = () => {
|
|
215
|
+
try {
|
|
216
|
+
return qe() || Qe() || et() || tt();
|
|
217
|
+
} catch (t) {
|
|
218
|
+
console.info(`Unable to get __FIREBASE_DEFAULTS__ due to: ${t}`);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
}, we = () => rt()?.config;
|
|
222
|
+
class A {
|
|
223
|
+
constructor() {
|
|
224
|
+
this.reject = () => {
|
|
225
|
+
}, this.resolve = () => {
|
|
226
|
+
}, this.promise = new Promise((e, r) => {
|
|
227
|
+
this.resolve = e, this.reject = r;
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Our API internals are not promisified and cannot because our callback APIs have subtle expectations around
|
|
232
|
+
* invoking promises inline, which Promises are forbidden to do. This method accepts an optional node-style callback
|
|
233
|
+
* and returns a node-style callback which will resolve or reject the Deferred's promise.
|
|
234
|
+
*/
|
|
235
|
+
wrapCallback(e) {
|
|
236
|
+
return (r, n) => {
|
|
237
|
+
r ? this.reject(r) : this.resolve(n), typeof e == "function" && (this.promise.catch(() => {
|
|
238
|
+
}), e.length === 1 ? e(r) : e(r, n));
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function X() {
|
|
243
|
+
try {
|
|
244
|
+
return typeof indexedDB == "object";
|
|
245
|
+
} catch {
|
|
246
|
+
return !1;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
function nt() {
|
|
250
|
+
return new Promise((t, e) => {
|
|
251
|
+
try {
|
|
252
|
+
let r = !0;
|
|
253
|
+
const n = "validate-browser-context-for-indexeddb-analytics-module", s = self.indexedDB.open(n);
|
|
254
|
+
s.onsuccess = () => {
|
|
255
|
+
s.result.close(), r || self.indexedDB.deleteDatabase(n), t(!0);
|
|
256
|
+
}, s.onupgradeneeded = () => {
|
|
257
|
+
r = !1;
|
|
258
|
+
}, s.onerror = () => {
|
|
259
|
+
e(s.error?.message || "");
|
|
260
|
+
};
|
|
261
|
+
} catch (r) {
|
|
262
|
+
e(r);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
const st = "FirebaseError";
|
|
267
|
+
class D extends Error {
|
|
268
|
+
constructor(e, r, n) {
|
|
269
|
+
super(r), this.code = e, this.customData = n, this.name = st, Object.setPrototypeOf(this, D.prototype), Error.captureStackTrace && Error.captureStackTrace(this, Y.prototype.create);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
class Y {
|
|
273
|
+
constructor(e, r, n) {
|
|
274
|
+
this.service = e, this.serviceName = r, this.errors = n;
|
|
275
|
+
}
|
|
276
|
+
create(e, ...r) {
|
|
277
|
+
const n = r[0] || {}, s = `${this.service}/${e}`, o = this.errors[e], i = o ? ot(o, n) : "Error", c = `${this.serviceName}: ${i} (${s}).`;
|
|
278
|
+
return new D(s, c, n);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
function ot(t, e) {
|
|
282
|
+
return t.replace(it, (r, n) => {
|
|
283
|
+
const s = e[n];
|
|
284
|
+
return s != null ? String(s) : `<${n}?>`;
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
const it = /\{\$([^}]+)}/g;
|
|
288
|
+
function F(t, e) {
|
|
289
|
+
if (t === e)
|
|
290
|
+
return !0;
|
|
291
|
+
const r = Object.keys(t), n = Object.keys(e);
|
|
292
|
+
for (const s of r) {
|
|
293
|
+
if (!n.includes(s))
|
|
294
|
+
return !1;
|
|
295
|
+
const o = t[s], i = e[s];
|
|
296
|
+
if (ne(o) && ne(i)) {
|
|
297
|
+
if (!F(o, i))
|
|
298
|
+
return !1;
|
|
299
|
+
} else if (o !== i)
|
|
300
|
+
return !1;
|
|
301
|
+
}
|
|
302
|
+
for (const s of n)
|
|
303
|
+
if (!r.includes(s))
|
|
304
|
+
return !1;
|
|
305
|
+
return !0;
|
|
306
|
+
}
|
|
307
|
+
function ne(t) {
|
|
308
|
+
return t !== null && typeof t == "object";
|
|
309
|
+
}
|
|
310
|
+
const at = 1e3, ct = 2, lt = 14400 * 1e3, ht = 0.5;
|
|
311
|
+
function dt(t, e = at, r = ct) {
|
|
312
|
+
const n = e * Math.pow(r, t), s = Math.round(
|
|
313
|
+
// A fraction of the backoff value to add/subtract.
|
|
314
|
+
// Deviation: changes multiplication order to improve readability.
|
|
315
|
+
ht * n * // A random float (rounded to int by Math.round above) in the range [-1, 1]. Determines
|
|
316
|
+
// if we add or subtract.
|
|
317
|
+
(Math.random() - 0.5) * 2
|
|
318
|
+
);
|
|
319
|
+
return Math.min(lt, n + s);
|
|
320
|
+
}
|
|
321
|
+
function ut(t) {
|
|
322
|
+
return t && t._delegate ? t._delegate : t;
|
|
323
|
+
}
|
|
324
|
+
class w {
|
|
325
|
+
/**
|
|
326
|
+
*
|
|
327
|
+
* @param name The public service name, e.g. app, auth, firestore, database
|
|
328
|
+
* @param instanceFactory Service factory responsible for creating the public interface
|
|
329
|
+
* @param type whether the service provided by the component is public or private
|
|
330
|
+
*/
|
|
331
|
+
constructor(e, r, n) {
|
|
332
|
+
this.name = e, this.instanceFactory = r, this.type = n, this.multipleInstances = !1, this.serviceProps = {}, this.instantiationMode = "LAZY", this.onInstanceCreated = null;
|
|
333
|
+
}
|
|
334
|
+
setInstantiationMode(e) {
|
|
335
|
+
return this.instantiationMode = e, this;
|
|
336
|
+
}
|
|
337
|
+
setMultipleInstances(e) {
|
|
338
|
+
return this.multipleInstances = e, this;
|
|
339
|
+
}
|
|
340
|
+
setServiceProps(e) {
|
|
341
|
+
return this.serviceProps = e, this;
|
|
342
|
+
}
|
|
343
|
+
setInstanceCreatedCallback(e) {
|
|
344
|
+
return this.onInstanceCreated = e, this;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
const E = "[DEFAULT]";
|
|
348
|
+
class ft {
|
|
349
|
+
constructor(e, r) {
|
|
350
|
+
this.name = e, this.container = r, this.component = null, this.instances = /* @__PURE__ */ new Map(), this.instancesDeferred = /* @__PURE__ */ new Map(), this.instancesOptions = /* @__PURE__ */ new Map(), this.onInitCallbacks = /* @__PURE__ */ new Map();
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* @param identifier A provider can provide multiple instances of a service
|
|
354
|
+
* if this.component.multipleInstances is true.
|
|
355
|
+
*/
|
|
356
|
+
get(e) {
|
|
357
|
+
const r = this.normalizeInstanceIdentifier(e);
|
|
358
|
+
if (!this.instancesDeferred.has(r)) {
|
|
359
|
+
const n = new A();
|
|
360
|
+
if (this.instancesDeferred.set(r, n), this.isInitialized(r) || this.shouldAutoInitialize())
|
|
361
|
+
try {
|
|
362
|
+
const s = this.getOrInitializeService({
|
|
363
|
+
instanceIdentifier: r
|
|
364
|
+
});
|
|
365
|
+
s && n.resolve(s);
|
|
366
|
+
} catch {
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return this.instancesDeferred.get(r).promise;
|
|
370
|
+
}
|
|
371
|
+
getImmediate(e) {
|
|
372
|
+
const r = this.normalizeInstanceIdentifier(e?.identifier), n = e?.optional ?? !1;
|
|
373
|
+
if (this.isInitialized(r) || this.shouldAutoInitialize())
|
|
374
|
+
try {
|
|
375
|
+
return this.getOrInitializeService({
|
|
376
|
+
instanceIdentifier: r
|
|
377
|
+
});
|
|
378
|
+
} catch (s) {
|
|
379
|
+
if (n)
|
|
380
|
+
return null;
|
|
381
|
+
throw s;
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
if (n)
|
|
385
|
+
return null;
|
|
386
|
+
throw Error(`Service ${this.name} is not available`);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
getComponent() {
|
|
390
|
+
return this.component;
|
|
391
|
+
}
|
|
392
|
+
setComponent(e) {
|
|
393
|
+
if (e.name !== this.name)
|
|
394
|
+
throw Error(`Mismatching Component ${e.name} for Provider ${this.name}.`);
|
|
395
|
+
if (this.component)
|
|
396
|
+
throw Error(`Component for ${this.name} has already been provided`);
|
|
397
|
+
if (this.component = e, !!this.shouldAutoInitialize()) {
|
|
398
|
+
if (gt(e))
|
|
399
|
+
try {
|
|
400
|
+
this.getOrInitializeService({ instanceIdentifier: E });
|
|
401
|
+
} catch {
|
|
402
|
+
}
|
|
403
|
+
for (const [r, n] of this.instancesDeferred.entries()) {
|
|
404
|
+
const s = this.normalizeInstanceIdentifier(r);
|
|
405
|
+
try {
|
|
406
|
+
const o = this.getOrInitializeService({
|
|
407
|
+
instanceIdentifier: s
|
|
408
|
+
});
|
|
409
|
+
n.resolve(o);
|
|
410
|
+
} catch {
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
clearInstance(e = E) {
|
|
416
|
+
this.instancesDeferred.delete(e), this.instancesOptions.delete(e), this.instances.delete(e);
|
|
417
|
+
}
|
|
418
|
+
// app.delete() will call this method on every provider to delete the services
|
|
419
|
+
// TODO: should we mark the provider as deleted?
|
|
420
|
+
async delete() {
|
|
421
|
+
const e = Array.from(this.instances.values());
|
|
422
|
+
await Promise.all([
|
|
423
|
+
...e.filter((r) => "INTERNAL" in r).map((r) => r.INTERNAL.delete()),
|
|
424
|
+
...e.filter((r) => "_delete" in r).map((r) => r._delete())
|
|
425
|
+
]);
|
|
426
|
+
}
|
|
427
|
+
isComponentSet() {
|
|
428
|
+
return this.component != null;
|
|
429
|
+
}
|
|
430
|
+
isInitialized(e = E) {
|
|
431
|
+
return this.instances.has(e);
|
|
432
|
+
}
|
|
433
|
+
getOptions(e = E) {
|
|
434
|
+
return this.instancesOptions.get(e) || {};
|
|
435
|
+
}
|
|
436
|
+
initialize(e = {}) {
|
|
437
|
+
const { options: r = {} } = e, n = this.normalizeInstanceIdentifier(e.instanceIdentifier);
|
|
438
|
+
if (this.isInitialized(n))
|
|
439
|
+
throw Error(`${this.name}(${n}) has already been initialized`);
|
|
440
|
+
if (!this.isComponentSet())
|
|
441
|
+
throw Error(`Component ${this.name} has not been registered yet`);
|
|
442
|
+
const s = this.getOrInitializeService({
|
|
443
|
+
instanceIdentifier: n,
|
|
444
|
+
options: r
|
|
445
|
+
});
|
|
446
|
+
for (const [o, i] of this.instancesDeferred.entries()) {
|
|
447
|
+
const c = this.normalizeInstanceIdentifier(o);
|
|
448
|
+
n === c && i.resolve(s);
|
|
449
|
+
}
|
|
450
|
+
return s;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
*
|
|
454
|
+
* @param callback - a function that will be invoked after the provider has been initialized by calling provider.initialize().
|
|
455
|
+
* The function is invoked SYNCHRONOUSLY, so it should not execute any longrunning tasks in order to not block the program.
|
|
456
|
+
*
|
|
457
|
+
* @param identifier An optional instance identifier
|
|
458
|
+
* @returns a function to unregister the callback
|
|
459
|
+
*/
|
|
460
|
+
onInit(e, r) {
|
|
461
|
+
const n = this.normalizeInstanceIdentifier(r), s = this.onInitCallbacks.get(n) ?? /* @__PURE__ */ new Set();
|
|
462
|
+
s.add(e), this.onInitCallbacks.set(n, s);
|
|
463
|
+
const o = this.instances.get(n);
|
|
464
|
+
return o && e(o, n), () => {
|
|
465
|
+
s.delete(e);
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Invoke onInit callbacks synchronously
|
|
470
|
+
* @param instance the service instance`
|
|
471
|
+
*/
|
|
472
|
+
invokeOnInitCallbacks(e, r) {
|
|
473
|
+
const n = this.onInitCallbacks.get(r);
|
|
474
|
+
if (n)
|
|
475
|
+
for (const s of n)
|
|
476
|
+
try {
|
|
477
|
+
s(e, r);
|
|
478
|
+
} catch {
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
getOrInitializeService({ instanceIdentifier: e, options: r = {} }) {
|
|
482
|
+
let n = this.instances.get(e);
|
|
483
|
+
if (!n && this.component && (n = this.component.instanceFactory(this.container, {
|
|
484
|
+
instanceIdentifier: pt(e),
|
|
485
|
+
options: r
|
|
486
|
+
}), this.instances.set(e, n), this.instancesOptions.set(e, r), this.invokeOnInitCallbacks(n, e), this.component.onInstanceCreated))
|
|
487
|
+
try {
|
|
488
|
+
this.component.onInstanceCreated(this.container, e, n);
|
|
489
|
+
} catch {
|
|
490
|
+
}
|
|
491
|
+
return n || null;
|
|
492
|
+
}
|
|
493
|
+
normalizeInstanceIdentifier(e = E) {
|
|
494
|
+
return this.component ? this.component.multipleInstances ? e : E : e;
|
|
495
|
+
}
|
|
496
|
+
shouldAutoInitialize() {
|
|
497
|
+
return !!this.component && this.component.instantiationMode !== "EXPLICIT";
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
function pt(t) {
|
|
501
|
+
return t === E ? void 0 : t;
|
|
502
|
+
}
|
|
503
|
+
function gt(t) {
|
|
504
|
+
return t.instantiationMode === "EAGER";
|
|
505
|
+
}
|
|
506
|
+
class mt {
|
|
507
|
+
constructor(e) {
|
|
508
|
+
this.name = e, this.providers = /* @__PURE__ */ new Map();
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
*
|
|
512
|
+
* @param component Component being added
|
|
513
|
+
* @param overwrite When a component with the same name has already been registered,
|
|
514
|
+
* if overwrite is true: overwrite the existing component with the new component and create a new
|
|
515
|
+
* provider with the new component. It can be useful in tests where you want to use different mocks
|
|
516
|
+
* for different tests.
|
|
517
|
+
* if overwrite is false: throw an exception
|
|
518
|
+
*/
|
|
519
|
+
addComponent(e) {
|
|
520
|
+
const r = this.getProvider(e.name);
|
|
521
|
+
if (r.isComponentSet())
|
|
522
|
+
throw new Error(`Component ${e.name} has already been registered with ${this.name}`);
|
|
523
|
+
r.setComponent(e);
|
|
524
|
+
}
|
|
525
|
+
addOrOverwriteComponent(e) {
|
|
526
|
+
this.getProvider(e.name).isComponentSet() && this.providers.delete(e.name), this.addComponent(e);
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* getProvider provides a type safe interface where it can only be called with a field name
|
|
530
|
+
* present in NameServiceMapping interface.
|
|
531
|
+
*
|
|
532
|
+
* Firebase SDKs providing services should extend NameServiceMapping interface to register
|
|
533
|
+
* themselves.
|
|
534
|
+
*/
|
|
535
|
+
getProvider(e) {
|
|
536
|
+
if (this.providers.has(e))
|
|
537
|
+
return this.providers.get(e);
|
|
538
|
+
const r = new ft(e, this);
|
|
539
|
+
return this.providers.set(e, r), r;
|
|
540
|
+
}
|
|
541
|
+
getProviders() {
|
|
542
|
+
return Array.from(this.providers.values());
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
var h;
|
|
546
|
+
(function(t) {
|
|
547
|
+
t[t.DEBUG = 0] = "DEBUG", t[t.VERBOSE = 1] = "VERBOSE", t[t.INFO = 2] = "INFO", t[t.WARN = 3] = "WARN", t[t.ERROR = 4] = "ERROR", t[t.SILENT = 5] = "SILENT";
|
|
548
|
+
})(h || (h = {}));
|
|
549
|
+
const bt = {
|
|
550
|
+
debug: h.DEBUG,
|
|
551
|
+
verbose: h.VERBOSE,
|
|
552
|
+
info: h.INFO,
|
|
553
|
+
warn: h.WARN,
|
|
554
|
+
error: h.ERROR,
|
|
555
|
+
silent: h.SILENT
|
|
556
|
+
}, Et = h.INFO, _t = {
|
|
557
|
+
[h.DEBUG]: "log",
|
|
558
|
+
[h.VERBOSE]: "log",
|
|
559
|
+
[h.INFO]: "info",
|
|
560
|
+
[h.WARN]: "warn",
|
|
561
|
+
[h.ERROR]: "error"
|
|
562
|
+
}, wt = (t, e, ...r) => {
|
|
563
|
+
if (e < t.logLevel)
|
|
564
|
+
return;
|
|
565
|
+
const n = (/* @__PURE__ */ new Date()).toISOString(), s = _t[e];
|
|
566
|
+
if (s)
|
|
567
|
+
console[s](`[${n}] ${t.name}:`, ...r);
|
|
568
|
+
else
|
|
569
|
+
throw new Error(`Attempted to log a message with an invalid logType (value: ${e})`);
|
|
570
|
+
};
|
|
571
|
+
class ye {
|
|
572
|
+
/**
|
|
573
|
+
* Gives you an instance of a Logger to capture messages according to
|
|
574
|
+
* Firebase's logging scheme.
|
|
575
|
+
*
|
|
576
|
+
* @param name The name that the logs will be associated with
|
|
577
|
+
*/
|
|
578
|
+
constructor(e) {
|
|
579
|
+
this.name = e, this._logLevel = Et, this._logHandler = wt, this._userLogHandler = null;
|
|
580
|
+
}
|
|
581
|
+
get logLevel() {
|
|
582
|
+
return this._logLevel;
|
|
583
|
+
}
|
|
584
|
+
set logLevel(e) {
|
|
585
|
+
if (!(e in h))
|
|
586
|
+
throw new TypeError(`Invalid value "${e}" assigned to \`logLevel\``);
|
|
587
|
+
this._logLevel = e;
|
|
588
|
+
}
|
|
589
|
+
// Workaround for setter/getter having to be the same type.
|
|
590
|
+
setLogLevel(e) {
|
|
591
|
+
this._logLevel = typeof e == "string" ? bt[e] : e;
|
|
592
|
+
}
|
|
593
|
+
get logHandler() {
|
|
594
|
+
return this._logHandler;
|
|
595
|
+
}
|
|
596
|
+
set logHandler(e) {
|
|
597
|
+
if (typeof e != "function")
|
|
598
|
+
throw new TypeError("Value assigned to `logHandler` must be a function");
|
|
599
|
+
this._logHandler = e;
|
|
600
|
+
}
|
|
601
|
+
get userLogHandler() {
|
|
602
|
+
return this._userLogHandler;
|
|
603
|
+
}
|
|
604
|
+
set userLogHandler(e) {
|
|
605
|
+
this._userLogHandler = e;
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* The functions below are all based on the `console` interface
|
|
609
|
+
*/
|
|
610
|
+
debug(...e) {
|
|
611
|
+
this._userLogHandler && this._userLogHandler(this, h.DEBUG, ...e), this._logHandler(this, h.DEBUG, ...e);
|
|
612
|
+
}
|
|
613
|
+
log(...e) {
|
|
614
|
+
this._userLogHandler && this._userLogHandler(this, h.VERBOSE, ...e), this._logHandler(this, h.VERBOSE, ...e);
|
|
615
|
+
}
|
|
616
|
+
info(...e) {
|
|
617
|
+
this._userLogHandler && this._userLogHandler(this, h.INFO, ...e), this._logHandler(this, h.INFO, ...e);
|
|
618
|
+
}
|
|
619
|
+
warn(...e) {
|
|
620
|
+
this._userLogHandler && this._userLogHandler(this, h.WARN, ...e), this._logHandler(this, h.WARN, ...e);
|
|
621
|
+
}
|
|
622
|
+
error(...e) {
|
|
623
|
+
this._userLogHandler && this._userLogHandler(this, h.ERROR, ...e), this._logHandler(this, h.ERROR, ...e);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
const yt = (t, e) => e.some((r) => t instanceof r);
|
|
627
|
+
let se, oe;
|
|
628
|
+
function At() {
|
|
629
|
+
return se || (se = [
|
|
630
|
+
IDBDatabase,
|
|
631
|
+
IDBObjectStore,
|
|
632
|
+
IDBIndex,
|
|
633
|
+
IDBCursor,
|
|
634
|
+
IDBTransaction
|
|
635
|
+
]);
|
|
636
|
+
}
|
|
637
|
+
function It() {
|
|
638
|
+
return oe || (oe = [
|
|
639
|
+
IDBCursor.prototype.advance,
|
|
640
|
+
IDBCursor.prototype.continue,
|
|
641
|
+
IDBCursor.prototype.continuePrimaryKey
|
|
642
|
+
]);
|
|
643
|
+
}
|
|
644
|
+
const Ae = /* @__PURE__ */ new WeakMap(), z = /* @__PURE__ */ new WeakMap(), Ie = /* @__PURE__ */ new WeakMap(), O = /* @__PURE__ */ new WeakMap(), J = /* @__PURE__ */ new WeakMap();
|
|
645
|
+
function Tt(t) {
|
|
646
|
+
const e = new Promise((r, n) => {
|
|
647
|
+
const s = () => {
|
|
648
|
+
t.removeEventListener("success", o), t.removeEventListener("error", i);
|
|
649
|
+
}, o = () => {
|
|
650
|
+
r(m(t.result)), s();
|
|
651
|
+
}, i = () => {
|
|
652
|
+
n(t.error), s();
|
|
653
|
+
};
|
|
654
|
+
t.addEventListener("success", o), t.addEventListener("error", i);
|
|
655
|
+
});
|
|
656
|
+
return e.then((r) => {
|
|
657
|
+
r instanceof IDBCursor && Ae.set(r, t);
|
|
658
|
+
}).catch(() => {
|
|
659
|
+
}), J.set(e, t), e;
|
|
660
|
+
}
|
|
661
|
+
function Ct(t) {
|
|
662
|
+
if (z.has(t))
|
|
663
|
+
return;
|
|
664
|
+
const e = new Promise((r, n) => {
|
|
665
|
+
const s = () => {
|
|
666
|
+
t.removeEventListener("complete", o), t.removeEventListener("error", i), t.removeEventListener("abort", i);
|
|
667
|
+
}, o = () => {
|
|
668
|
+
r(), s();
|
|
669
|
+
}, i = () => {
|
|
670
|
+
n(t.error || new DOMException("AbortError", "AbortError")), s();
|
|
671
|
+
};
|
|
672
|
+
t.addEventListener("complete", o), t.addEventListener("error", i), t.addEventListener("abort", i);
|
|
673
|
+
});
|
|
674
|
+
z.set(t, e);
|
|
675
|
+
}
|
|
676
|
+
let U = {
|
|
677
|
+
get(t, e, r) {
|
|
678
|
+
if (t instanceof IDBTransaction) {
|
|
679
|
+
if (e === "done")
|
|
680
|
+
return z.get(t);
|
|
681
|
+
if (e === "objectStoreNames")
|
|
682
|
+
return t.objectStoreNames || Ie.get(t);
|
|
683
|
+
if (e === "store")
|
|
684
|
+
return r.objectStoreNames[1] ? void 0 : r.objectStore(r.objectStoreNames[0]);
|
|
685
|
+
}
|
|
686
|
+
return m(t[e]);
|
|
687
|
+
},
|
|
688
|
+
set(t, e, r) {
|
|
689
|
+
return t[e] = r, !0;
|
|
690
|
+
},
|
|
691
|
+
has(t, e) {
|
|
692
|
+
return t instanceof IDBTransaction && (e === "done" || e === "store") ? !0 : e in t;
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
function Dt(t) {
|
|
696
|
+
U = t(U);
|
|
697
|
+
}
|
|
698
|
+
function kt(t) {
|
|
699
|
+
return t === IDBDatabase.prototype.transaction && !("objectStoreNames" in IDBTransaction.prototype) ? function(e, ...r) {
|
|
700
|
+
const n = t.call(N(this), e, ...r);
|
|
701
|
+
return Ie.set(n, e.sort ? e.sort() : [e]), m(n);
|
|
702
|
+
} : It().includes(t) ? function(...e) {
|
|
703
|
+
return t.apply(N(this), e), m(Ae.get(this));
|
|
704
|
+
} : function(...e) {
|
|
705
|
+
return m(t.apply(N(this), e));
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
function St(t) {
|
|
709
|
+
return typeof t == "function" ? kt(t) : (t instanceof IDBTransaction && Ct(t), yt(t, At()) ? new Proxy(t, U) : t);
|
|
710
|
+
}
|
|
711
|
+
function m(t) {
|
|
712
|
+
if (t instanceof IDBRequest)
|
|
713
|
+
return Tt(t);
|
|
714
|
+
if (O.has(t))
|
|
715
|
+
return O.get(t);
|
|
716
|
+
const e = St(t);
|
|
717
|
+
return e !== t && (O.set(t, e), J.set(e, t)), e;
|
|
718
|
+
}
|
|
719
|
+
const N = (t) => J.get(t);
|
|
720
|
+
function vt(t, e, { blocked: r, upgrade: n, blocking: s, terminated: o } = {}) {
|
|
721
|
+
const i = indexedDB.open(t, e), c = m(i);
|
|
722
|
+
return n && i.addEventListener("upgradeneeded", (a) => {
|
|
723
|
+
n(m(i.result), a.oldVersion, a.newVersion, m(i.transaction), a);
|
|
724
|
+
}), r && i.addEventListener("blocked", (a) => r(
|
|
725
|
+
// Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405
|
|
726
|
+
a.oldVersion,
|
|
727
|
+
a.newVersion,
|
|
728
|
+
a
|
|
729
|
+
)), c.then((a) => {
|
|
730
|
+
o && a.addEventListener("close", () => o()), s && a.addEventListener("versionchange", (l) => s(l.oldVersion, l.newVersion, l));
|
|
731
|
+
}).catch(() => {
|
|
732
|
+
}), c;
|
|
733
|
+
}
|
|
734
|
+
const Rt = ["get", "getKey", "getAll", "getAllKeys", "count"], Bt = ["put", "add", "delete", "clear"], $ = /* @__PURE__ */ new Map();
|
|
735
|
+
function ie(t, e) {
|
|
736
|
+
if (!(t instanceof IDBDatabase && !(e in t) && typeof e == "string"))
|
|
737
|
+
return;
|
|
738
|
+
if ($.get(e))
|
|
739
|
+
return $.get(e);
|
|
740
|
+
const r = e.replace(/FromIndex$/, ""), n = e !== r, s = Bt.includes(r);
|
|
741
|
+
if (
|
|
742
|
+
// Bail if the target doesn't exist on the target. Eg, getAll isn't in Edge.
|
|
743
|
+
!(r in (n ? IDBIndex : IDBObjectStore).prototype) || !(s || Rt.includes(r))
|
|
744
|
+
)
|
|
745
|
+
return;
|
|
746
|
+
const o = async function(i, ...c) {
|
|
747
|
+
const a = this.transaction(i, s ? "readwrite" : "readonly");
|
|
748
|
+
let l = a.store;
|
|
749
|
+
return n && (l = l.index(c.shift())), (await Promise.all([
|
|
750
|
+
l[r](...c),
|
|
751
|
+
s && a.done
|
|
752
|
+
]))[0];
|
|
753
|
+
};
|
|
754
|
+
return $.set(e, o), o;
|
|
755
|
+
}
|
|
756
|
+
Dt((t) => ({
|
|
757
|
+
...t,
|
|
758
|
+
get: (e, r, n) => ie(e, r) || t.get(e, r, n),
|
|
759
|
+
has: (e, r) => !!ie(e, r) || t.has(e, r)
|
|
760
|
+
}));
|
|
761
|
+
class Pt {
|
|
762
|
+
constructor(e) {
|
|
763
|
+
this.container = e;
|
|
764
|
+
}
|
|
765
|
+
// In initial implementation, this will be called by installations on
|
|
766
|
+
// auth token refresh, and installations will send this string.
|
|
767
|
+
getPlatformInfoString() {
|
|
768
|
+
return this.container.getProviders().map((r) => {
|
|
769
|
+
if (Mt(r)) {
|
|
770
|
+
const n = r.getImmediate();
|
|
771
|
+
return `${n.library}/${n.version}`;
|
|
772
|
+
} else
|
|
773
|
+
return null;
|
|
774
|
+
}).filter((r) => r).join(" ");
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
function Mt(t) {
|
|
778
|
+
return t.getComponent()?.type === "VERSION";
|
|
779
|
+
}
|
|
780
|
+
const j = "@firebase/app", ae = "0.14.8";
|
|
781
|
+
const p = new ye("@firebase/app"), Ot = "@firebase/app-compat", Nt = "@firebase/analytics-compat", $t = "@firebase/analytics", xt = "@firebase/app-check-compat", Lt = "@firebase/app-check", Ht = "@firebase/auth", Ft = "@firebase/auth-compat", zt = "@firebase/database", Ut = "@firebase/data-connect", jt = "@firebase/database-compat", Vt = "@firebase/functions", Wt = "@firebase/functions-compat", Kt = "@firebase/installations", Gt = "@firebase/installations-compat", qt = "@firebase/messaging", Xt = "@firebase/messaging-compat", Yt = "@firebase/performance", Jt = "@firebase/performance-compat", Zt = "@firebase/remote-config", Qt = "@firebase/remote-config-compat", er = "@firebase/storage", tr = "@firebase/storage-compat", rr = "@firebase/firestore", nr = "@firebase/ai", sr = "@firebase/firestore-compat", or = "firebase";
|
|
782
|
+
const V = "[DEFAULT]", ir = {
|
|
783
|
+
[j]: "fire-core",
|
|
784
|
+
[Ot]: "fire-core-compat",
|
|
785
|
+
[$t]: "fire-analytics",
|
|
786
|
+
[Nt]: "fire-analytics-compat",
|
|
787
|
+
[Lt]: "fire-app-check",
|
|
788
|
+
[xt]: "fire-app-check-compat",
|
|
789
|
+
[Ht]: "fire-auth",
|
|
790
|
+
[Ft]: "fire-auth-compat",
|
|
791
|
+
[zt]: "fire-rtdb",
|
|
792
|
+
[Ut]: "fire-data-connect",
|
|
793
|
+
[jt]: "fire-rtdb-compat",
|
|
794
|
+
[Vt]: "fire-fn",
|
|
795
|
+
[Wt]: "fire-fn-compat",
|
|
796
|
+
[Kt]: "fire-iid",
|
|
797
|
+
[Gt]: "fire-iid-compat",
|
|
798
|
+
[qt]: "fire-fcm",
|
|
799
|
+
[Xt]: "fire-fcm-compat",
|
|
800
|
+
[Yt]: "fire-perf",
|
|
801
|
+
[Jt]: "fire-perf-compat",
|
|
802
|
+
[Zt]: "fire-rc",
|
|
803
|
+
[Qt]: "fire-rc-compat",
|
|
804
|
+
[er]: "fire-gcs",
|
|
805
|
+
[tr]: "fire-gcs-compat",
|
|
806
|
+
[rr]: "fire-fst",
|
|
807
|
+
[sr]: "fire-fst-compat",
|
|
808
|
+
[nr]: "fire-vertex",
|
|
809
|
+
"fire-js": "fire-js",
|
|
810
|
+
// Platform identifier for JS SDK.
|
|
811
|
+
[or]: "fire-js-all"
|
|
812
|
+
};
|
|
813
|
+
const P = /* @__PURE__ */ new Map(), ar = /* @__PURE__ */ new Map(), W = /* @__PURE__ */ new Map();
|
|
814
|
+
function ce(t, e) {
|
|
815
|
+
try {
|
|
816
|
+
t.container.addComponent(e);
|
|
817
|
+
} catch (r) {
|
|
818
|
+
p.debug(`Component ${e.name} failed to register with FirebaseApp ${t.name}`, r);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
function I(t) {
|
|
822
|
+
const e = t.name;
|
|
823
|
+
if (W.has(e))
|
|
824
|
+
return p.debug(`There were multiple attempts to register component ${e}.`), !1;
|
|
825
|
+
W.set(e, t);
|
|
826
|
+
for (const r of P.values())
|
|
827
|
+
ce(r, t);
|
|
828
|
+
for (const r of ar.values())
|
|
829
|
+
ce(r, t);
|
|
830
|
+
return !0;
|
|
831
|
+
}
|
|
832
|
+
function Te(t, e) {
|
|
833
|
+
const r = t.container.getProvider("heartbeat").getImmediate({ optional: !0 });
|
|
834
|
+
return r && r.triggerHeartbeat(), t.container.getProvider(e);
|
|
835
|
+
}
|
|
836
|
+
const cr = {
|
|
837
|
+
"no-app": "No Firebase App '{$appName}' has been created - call initializeApp() first",
|
|
838
|
+
"bad-app-name": "Illegal App name: '{$appName}'",
|
|
839
|
+
"duplicate-app": "Firebase App named '{$appName}' already exists with different options or config",
|
|
840
|
+
"app-deleted": "Firebase App named '{$appName}' already deleted",
|
|
841
|
+
"server-app-deleted": "Firebase Server App has been deleted",
|
|
842
|
+
"no-options": "Need to provide options, when not being deployed to hosting via source.",
|
|
843
|
+
"invalid-app-argument": "firebase.{$appName}() takes either no argument or a Firebase App instance.",
|
|
844
|
+
"invalid-log-argument": "First argument to `onLog` must be null or a function.",
|
|
845
|
+
"idb-open": "Error thrown when opening IndexedDB. Original error: {$originalErrorMessage}.",
|
|
846
|
+
"idb-get": "Error thrown when reading from IndexedDB. Original error: {$originalErrorMessage}.",
|
|
847
|
+
"idb-set": "Error thrown when writing to IndexedDB. Original error: {$originalErrorMessage}.",
|
|
848
|
+
"idb-delete": "Error thrown when deleting from IndexedDB. Original error: {$originalErrorMessage}.",
|
|
849
|
+
"finalization-registry-not-supported": "FirebaseServerApp deleteOnDeref field defined but the JS runtime does not support FinalizationRegistry.",
|
|
850
|
+
"invalid-server-app-environment": "FirebaseServerApp is not for use in browser environments."
|
|
851
|
+
}, b = new Y("app", "Firebase", cr);
|
|
852
|
+
class lr {
|
|
853
|
+
constructor(e, r, n) {
|
|
854
|
+
this._isDeleted = !1, this._options = { ...e }, this._config = { ...r }, this._name = r.name, this._automaticDataCollectionEnabled = r.automaticDataCollectionEnabled, this._container = n, this.container.addComponent(new w(
|
|
855
|
+
"app",
|
|
856
|
+
() => this,
|
|
857
|
+
"PUBLIC"
|
|
858
|
+
/* ComponentType.PUBLIC */
|
|
859
|
+
));
|
|
860
|
+
}
|
|
861
|
+
get automaticDataCollectionEnabled() {
|
|
862
|
+
return this.checkDestroyed(), this._automaticDataCollectionEnabled;
|
|
863
|
+
}
|
|
864
|
+
set automaticDataCollectionEnabled(e) {
|
|
865
|
+
this.checkDestroyed(), this._automaticDataCollectionEnabled = e;
|
|
866
|
+
}
|
|
867
|
+
get name() {
|
|
868
|
+
return this.checkDestroyed(), this._name;
|
|
869
|
+
}
|
|
870
|
+
get options() {
|
|
871
|
+
return this.checkDestroyed(), this._options;
|
|
872
|
+
}
|
|
873
|
+
get config() {
|
|
874
|
+
return this.checkDestroyed(), this._config;
|
|
875
|
+
}
|
|
876
|
+
get container() {
|
|
877
|
+
return this._container;
|
|
878
|
+
}
|
|
879
|
+
get isDeleted() {
|
|
880
|
+
return this._isDeleted;
|
|
881
|
+
}
|
|
882
|
+
set isDeleted(e) {
|
|
883
|
+
this._isDeleted = e;
|
|
884
|
+
}
|
|
885
|
+
/**
|
|
886
|
+
* This function will throw an Error if the App has already been deleted -
|
|
887
|
+
* use before performing API actions on the App.
|
|
888
|
+
*/
|
|
889
|
+
checkDestroyed() {
|
|
890
|
+
if (this.isDeleted)
|
|
891
|
+
throw b.create("app-deleted", { appName: this._name });
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
function hr(t, e = {}) {
|
|
895
|
+
let r = t;
|
|
896
|
+
typeof e != "object" && (e = { name: e });
|
|
897
|
+
const n = {
|
|
898
|
+
name: V,
|
|
899
|
+
automaticDataCollectionEnabled: !0,
|
|
900
|
+
...e
|
|
901
|
+
}, s = n.name;
|
|
902
|
+
if (typeof s != "string" || !s)
|
|
903
|
+
throw b.create("bad-app-name", {
|
|
904
|
+
appName: String(s)
|
|
905
|
+
});
|
|
906
|
+
if (r || (r = we()), !r)
|
|
907
|
+
throw b.create(
|
|
908
|
+
"no-options"
|
|
909
|
+
/* AppError.NO_OPTIONS */
|
|
910
|
+
);
|
|
911
|
+
const o = P.get(s);
|
|
912
|
+
if (o) {
|
|
913
|
+
if (F(r, o.options) && F(n, o.config))
|
|
914
|
+
return o;
|
|
915
|
+
throw b.create("duplicate-app", { appName: s });
|
|
916
|
+
}
|
|
917
|
+
const i = new mt(s);
|
|
918
|
+
for (const a of W.values())
|
|
919
|
+
i.addComponent(a);
|
|
920
|
+
const c = new lr(r, n, i);
|
|
921
|
+
return P.set(s, c), c;
|
|
922
|
+
}
|
|
923
|
+
function dr(t = V) {
|
|
924
|
+
const e = P.get(t);
|
|
925
|
+
if (!e && t === V && we())
|
|
926
|
+
return hr();
|
|
927
|
+
if (!e)
|
|
928
|
+
throw b.create("no-app", { appName: t });
|
|
929
|
+
return e;
|
|
930
|
+
}
|
|
931
|
+
function B(t, e, r) {
|
|
932
|
+
let n = ir[t] ?? t;
|
|
933
|
+
r && (n += `-${r}`);
|
|
934
|
+
const s = n.match(/\s|\//), o = e.match(/\s|\//);
|
|
935
|
+
if (s || o) {
|
|
936
|
+
const i = [
|
|
937
|
+
`Unable to register library "${n}" with version "${e}":`
|
|
938
|
+
];
|
|
939
|
+
s && i.push(`library name "${n}" contains illegal characters (whitespace or "/")`), s && o && i.push("and"), o && i.push(`version name "${e}" contains illegal characters (whitespace or "/")`), p.warn(i.join(" "));
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
I(new w(
|
|
943
|
+
`${n}-version`,
|
|
944
|
+
() => ({ library: n, version: e }),
|
|
945
|
+
"VERSION"
|
|
946
|
+
/* ComponentType.VERSION */
|
|
947
|
+
));
|
|
948
|
+
}
|
|
949
|
+
const ur = "firebase-heartbeat-database", fr = 1, T = "firebase-heartbeat-store";
|
|
950
|
+
let x = null;
|
|
951
|
+
function Ce() {
|
|
952
|
+
return x || (x = vt(ur, fr, {
|
|
953
|
+
upgrade: (t, e) => {
|
|
954
|
+
switch (e) {
|
|
955
|
+
case 0:
|
|
956
|
+
try {
|
|
957
|
+
t.createObjectStore(T);
|
|
958
|
+
} catch (r) {
|
|
959
|
+
console.warn(r);
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
}).catch((t) => {
|
|
964
|
+
throw b.create("idb-open", {
|
|
965
|
+
originalErrorMessage: t.message
|
|
966
|
+
});
|
|
967
|
+
})), x;
|
|
968
|
+
}
|
|
969
|
+
async function pr(t) {
|
|
970
|
+
try {
|
|
971
|
+
const r = (await Ce()).transaction(T), n = await r.objectStore(T).get(De(t));
|
|
972
|
+
return await r.done, n;
|
|
973
|
+
} catch (e) {
|
|
974
|
+
if (e instanceof D)
|
|
975
|
+
p.warn(e.message);
|
|
976
|
+
else {
|
|
977
|
+
const r = b.create("idb-get", {
|
|
978
|
+
originalErrorMessage: e?.message
|
|
979
|
+
});
|
|
980
|
+
p.warn(r.message);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
async function le(t, e) {
|
|
985
|
+
try {
|
|
986
|
+
const n = (await Ce()).transaction(T, "readwrite");
|
|
987
|
+
await n.objectStore(T).put(e, De(t)), await n.done;
|
|
988
|
+
} catch (r) {
|
|
989
|
+
if (r instanceof D)
|
|
990
|
+
p.warn(r.message);
|
|
991
|
+
else {
|
|
992
|
+
const n = b.create("idb-set", {
|
|
993
|
+
originalErrorMessage: r?.message
|
|
994
|
+
});
|
|
995
|
+
p.warn(n.message);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
function De(t) {
|
|
1000
|
+
return `${t.name}!${t.options.appId}`;
|
|
1001
|
+
}
|
|
1002
|
+
const gr = 1024, mr = 30;
|
|
1003
|
+
class br {
|
|
1004
|
+
constructor(e) {
|
|
1005
|
+
this.container = e, this._heartbeatsCache = null;
|
|
1006
|
+
const r = this.container.getProvider("app").getImmediate();
|
|
1007
|
+
this._storage = new _r(r), this._heartbeatsCachePromise = this._storage.read().then((n) => (this._heartbeatsCache = n, n));
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Called to report a heartbeat. The function will generate
|
|
1011
|
+
* a HeartbeatsByUserAgent object, update heartbeatsCache, and persist it
|
|
1012
|
+
* to IndexedDB.
|
|
1013
|
+
* Note that we only store one heartbeat per day. So if a heartbeat for today is
|
|
1014
|
+
* already logged, subsequent calls to this function in the same day will be ignored.
|
|
1015
|
+
*/
|
|
1016
|
+
async triggerHeartbeat() {
|
|
1017
|
+
try {
|
|
1018
|
+
const r = this.container.getProvider("platform-logger").getImmediate().getPlatformInfoString(), n = he();
|
|
1019
|
+
if (this._heartbeatsCache?.heartbeats == null && (this._heartbeatsCache = await this._heartbeatsCachePromise, this._heartbeatsCache?.heartbeats == null) || this._heartbeatsCache.lastSentHeartbeatDate === n || this._heartbeatsCache.heartbeats.some((s) => s.date === n))
|
|
1020
|
+
return;
|
|
1021
|
+
if (this._heartbeatsCache.heartbeats.push({ date: n, agent: r }), this._heartbeatsCache.heartbeats.length > mr) {
|
|
1022
|
+
const s = wr(this._heartbeatsCache.heartbeats);
|
|
1023
|
+
this._heartbeatsCache.heartbeats.splice(s, 1);
|
|
1024
|
+
}
|
|
1025
|
+
return this._storage.overwrite(this._heartbeatsCache);
|
|
1026
|
+
} catch (e) {
|
|
1027
|
+
p.warn(e);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
/**
|
|
1031
|
+
* Returns a base64 encoded string which can be attached to the heartbeat-specific header directly.
|
|
1032
|
+
* It also clears all heartbeats from memory as well as in IndexedDB.
|
|
1033
|
+
*
|
|
1034
|
+
* NOTE: Consuming product SDKs should not send the header if this method
|
|
1035
|
+
* returns an empty string.
|
|
1036
|
+
*/
|
|
1037
|
+
async getHeartbeatsHeader() {
|
|
1038
|
+
try {
|
|
1039
|
+
if (this._heartbeatsCache === null && await this._heartbeatsCachePromise, this._heartbeatsCache?.heartbeats == null || this._heartbeatsCache.heartbeats.length === 0)
|
|
1040
|
+
return "";
|
|
1041
|
+
const e = he(), { heartbeatsToSend: r, unsentEntries: n } = Er(this._heartbeatsCache.heartbeats), s = Ee(JSON.stringify({ version: 2, heartbeats: r }));
|
|
1042
|
+
return this._heartbeatsCache.lastSentHeartbeatDate = e, n.length > 0 ? (this._heartbeatsCache.heartbeats = n, await this._storage.overwrite(this._heartbeatsCache)) : (this._heartbeatsCache.heartbeats = [], this._storage.overwrite(this._heartbeatsCache)), s;
|
|
1043
|
+
} catch (e) {
|
|
1044
|
+
return p.warn(e), "";
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
function he() {
|
|
1049
|
+
return (/* @__PURE__ */ new Date()).toISOString().substring(0, 10);
|
|
1050
|
+
}
|
|
1051
|
+
function Er(t, e = gr) {
|
|
1052
|
+
const r = [];
|
|
1053
|
+
let n = t.slice();
|
|
1054
|
+
for (const s of t) {
|
|
1055
|
+
const o = r.find((i) => i.agent === s.agent);
|
|
1056
|
+
if (o) {
|
|
1057
|
+
if (o.dates.push(s.date), de(r) > e) {
|
|
1058
|
+
o.dates.pop();
|
|
1059
|
+
break;
|
|
1060
|
+
}
|
|
1061
|
+
} else if (r.push({
|
|
1062
|
+
agent: s.agent,
|
|
1063
|
+
dates: [s.date]
|
|
1064
|
+
}), de(r) > e) {
|
|
1065
|
+
r.pop();
|
|
1066
|
+
break;
|
|
1067
|
+
}
|
|
1068
|
+
n = n.slice(1);
|
|
1069
|
+
}
|
|
1070
|
+
return {
|
|
1071
|
+
heartbeatsToSend: r,
|
|
1072
|
+
unsentEntries: n
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
1075
|
+
class _r {
|
|
1076
|
+
constructor(e) {
|
|
1077
|
+
this.app = e, this._canUseIndexedDBPromise = this.runIndexedDBEnvironmentCheck();
|
|
1078
|
+
}
|
|
1079
|
+
async runIndexedDBEnvironmentCheck() {
|
|
1080
|
+
return X() ? nt().then(() => !0).catch(() => !1) : !1;
|
|
1081
|
+
}
|
|
1082
|
+
/**
|
|
1083
|
+
* Read all heartbeats.
|
|
1084
|
+
*/
|
|
1085
|
+
async read() {
|
|
1086
|
+
if (await this._canUseIndexedDBPromise) {
|
|
1087
|
+
const r = await pr(this.app);
|
|
1088
|
+
return r?.heartbeats ? r : { heartbeats: [] };
|
|
1089
|
+
} else
|
|
1090
|
+
return { heartbeats: [] };
|
|
1091
|
+
}
|
|
1092
|
+
// overwrite the storage with the provided heartbeats
|
|
1093
|
+
async overwrite(e) {
|
|
1094
|
+
if (await this._canUseIndexedDBPromise) {
|
|
1095
|
+
const n = await this.read();
|
|
1096
|
+
return le(this.app, {
|
|
1097
|
+
lastSentHeartbeatDate: e.lastSentHeartbeatDate ?? n.lastSentHeartbeatDate,
|
|
1098
|
+
heartbeats: e.heartbeats
|
|
1099
|
+
});
|
|
1100
|
+
} else
|
|
1101
|
+
return;
|
|
1102
|
+
}
|
|
1103
|
+
// add heartbeats
|
|
1104
|
+
async add(e) {
|
|
1105
|
+
if (await this._canUseIndexedDBPromise) {
|
|
1106
|
+
const n = await this.read();
|
|
1107
|
+
return le(this.app, {
|
|
1108
|
+
lastSentHeartbeatDate: e.lastSentHeartbeatDate ?? n.lastSentHeartbeatDate,
|
|
1109
|
+
heartbeats: [
|
|
1110
|
+
...n.heartbeats,
|
|
1111
|
+
...e.heartbeats
|
|
1112
|
+
]
|
|
1113
|
+
});
|
|
1114
|
+
} else
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
function de(t) {
|
|
1119
|
+
return Ee(
|
|
1120
|
+
// heartbeatsCache wrapper properties
|
|
1121
|
+
JSON.stringify({ version: 2, heartbeats: t })
|
|
1122
|
+
).length;
|
|
1123
|
+
}
|
|
1124
|
+
function wr(t) {
|
|
1125
|
+
if (t.length === 0)
|
|
1126
|
+
return -1;
|
|
1127
|
+
let e = 0, r = t[0].date;
|
|
1128
|
+
for (let n = 1; n < t.length; n++)
|
|
1129
|
+
t[n].date < r && (r = t[n].date, e = n);
|
|
1130
|
+
return e;
|
|
1131
|
+
}
|
|
1132
|
+
function yr(t) {
|
|
1133
|
+
I(new w(
|
|
1134
|
+
"platform-logger",
|
|
1135
|
+
(e) => new Pt(e),
|
|
1136
|
+
"PRIVATE"
|
|
1137
|
+
/* ComponentType.PRIVATE */
|
|
1138
|
+
)), I(new w(
|
|
1139
|
+
"heartbeat",
|
|
1140
|
+
(e) => new br(e),
|
|
1141
|
+
"PRIVATE"
|
|
1142
|
+
/* ComponentType.PRIVATE */
|
|
1143
|
+
)), B(j, ae, t), B(j, ae, "esm2020"), B("fire-js", "");
|
|
1144
|
+
}
|
|
1145
|
+
yr("");
|
|
1146
|
+
const K = /* @__PURE__ */ new Map(), ke = {
|
|
1147
|
+
activated: !1,
|
|
1148
|
+
tokenObservers: []
|
|
1149
|
+
}, Ar = {
|
|
1150
|
+
initialized: !1,
|
|
1151
|
+
enabled: !1
|
|
1152
|
+
};
|
|
1153
|
+
function d(t) {
|
|
1154
|
+
return K.get(t) || { ...ke };
|
|
1155
|
+
}
|
|
1156
|
+
function Ir(t, e) {
|
|
1157
|
+
return K.set(t, e), K.get(t);
|
|
1158
|
+
}
|
|
1159
|
+
function M() {
|
|
1160
|
+
return Ar;
|
|
1161
|
+
}
|
|
1162
|
+
const Se = "https://content-firebaseappcheck.googleapis.com/v1", Tr = "exchangeRecaptchaEnterpriseToken", Cr = "exchangeDebugToken", ue = {
|
|
1163
|
+
/**
|
|
1164
|
+
* This is the first retrial wait after an error. This is currently
|
|
1165
|
+
* 30 seconds.
|
|
1166
|
+
*/
|
|
1167
|
+
RETRIAL_MIN_WAIT: 30 * 1e3,
|
|
1168
|
+
/**
|
|
1169
|
+
* This is the maximum retrial wait, currently 16 minutes.
|
|
1170
|
+
*/
|
|
1171
|
+
RETRIAL_MAX_WAIT: 960 * 1e3
|
|
1172
|
+
}, Dr = 1440 * 60 * 1e3;
|
|
1173
|
+
class kr {
|
|
1174
|
+
constructor(e, r, n, s, o) {
|
|
1175
|
+
if (this.operation = e, this.retryPolicy = r, this.getWaitDuration = n, this.lowerBound = s, this.upperBound = o, this.pending = null, this.nextErrorWaitInterval = s, s > o)
|
|
1176
|
+
throw new Error("Proactive refresh lower bound greater than upper bound!");
|
|
1177
|
+
}
|
|
1178
|
+
start() {
|
|
1179
|
+
this.nextErrorWaitInterval = this.lowerBound, this.process(!0).catch(() => {
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
stop() {
|
|
1183
|
+
this.pending && (this.pending.reject("cancelled"), this.pending = null);
|
|
1184
|
+
}
|
|
1185
|
+
isRunning() {
|
|
1186
|
+
return !!this.pending;
|
|
1187
|
+
}
|
|
1188
|
+
async process(e) {
|
|
1189
|
+
this.stop();
|
|
1190
|
+
try {
|
|
1191
|
+
this.pending = new A(), this.pending.promise.catch((r) => {
|
|
1192
|
+
}), await Sr(this.getNextRun(e)), this.pending.resolve(), await this.pending.promise, this.pending = new A(), this.pending.promise.catch((r) => {
|
|
1193
|
+
}), await this.operation(), this.pending.resolve(), await this.pending.promise, this.process(!0).catch(() => {
|
|
1194
|
+
});
|
|
1195
|
+
} catch (r) {
|
|
1196
|
+
this.retryPolicy(r) ? this.process(!1).catch(() => {
|
|
1197
|
+
}) : this.stop();
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
getNextRun(e) {
|
|
1201
|
+
if (e)
|
|
1202
|
+
return this.nextErrorWaitInterval = this.lowerBound, this.getWaitDuration();
|
|
1203
|
+
{
|
|
1204
|
+
const r = this.nextErrorWaitInterval;
|
|
1205
|
+
return this.nextErrorWaitInterval *= 2, this.nextErrorWaitInterval > this.upperBound && (this.nextErrorWaitInterval = this.upperBound), r;
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
function Sr(t) {
|
|
1210
|
+
return new Promise((e) => {
|
|
1211
|
+
setTimeout(e, t);
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
const vr = {
|
|
1215
|
+
"already-initialized": "You have already called initializeAppCheck() for FirebaseApp {$appName} with different options. To avoid this error, call initializeAppCheck() with the same options as when it was originally called. This will return the already initialized instance.",
|
|
1216
|
+
"use-before-activation": "App Check is being used before initializeAppCheck() is called for FirebaseApp {$appName}. Call initializeAppCheck() before instantiating other Firebase services.",
|
|
1217
|
+
"fetch-network-error": "Fetch failed to connect to a network. Check Internet connection. Original error: {$originalErrorMessage}.",
|
|
1218
|
+
"fetch-parse-error": "Fetch client could not parse response. Original error: {$originalErrorMessage}.",
|
|
1219
|
+
"fetch-status-error": "Fetch server returned an HTTP error status. HTTP status: {$httpStatus}.",
|
|
1220
|
+
"storage-open": "Error thrown when opening storage. Original error: {$originalErrorMessage}.",
|
|
1221
|
+
"storage-get": "Error thrown when reading from storage. Original error: {$originalErrorMessage}.",
|
|
1222
|
+
"storage-set": "Error thrown when writing to storage. Original error: {$originalErrorMessage}.",
|
|
1223
|
+
"recaptcha-error": "ReCAPTCHA error.",
|
|
1224
|
+
"initial-throttle": "{$httpStatus} error. Attempts allowed again after {$time}",
|
|
1225
|
+
throttled: "Requests throttled due to previous {$httpStatus} error. Attempts allowed again after {$time}"
|
|
1226
|
+
}, u = new Y("appCheck", "AppCheck", vr);
|
|
1227
|
+
function fe(t = !1) {
|
|
1228
|
+
return t ? self.grecaptcha?.enterprise : self.grecaptcha;
|
|
1229
|
+
}
|
|
1230
|
+
function Z(t) {
|
|
1231
|
+
if (!d(t).activated)
|
|
1232
|
+
throw u.create("use-before-activation", {
|
|
1233
|
+
appName: t.name
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
function ve(t) {
|
|
1237
|
+
const e = Math.round(t / 1e3), r = Math.floor(e / (3600 * 24)), n = Math.floor((e - r * 3600 * 24) / 3600), s = Math.floor((e - r * 3600 * 24 - n * 3600) / 60), o = e - r * 3600 * 24 - n * 3600 - s * 60;
|
|
1238
|
+
let i = "";
|
|
1239
|
+
return r && (i += v(r) + "d:"), n && (i += v(n) + "h:"), i += v(s) + "m:" + v(o) + "s", i;
|
|
1240
|
+
}
|
|
1241
|
+
function v(t) {
|
|
1242
|
+
return t === 0 ? "00" : t >= 10 ? t.toString() : "0" + t;
|
|
1243
|
+
}
|
|
1244
|
+
async function Q({ url: t, body: e }, r) {
|
|
1245
|
+
const n = {
|
|
1246
|
+
"Content-Type": "application/json"
|
|
1247
|
+
}, s = r.getImmediate({
|
|
1248
|
+
optional: !0
|
|
1249
|
+
});
|
|
1250
|
+
if (s) {
|
|
1251
|
+
const f = await s.getHeartbeatsHeader();
|
|
1252
|
+
f && (n["X-Firebase-Client"] = f);
|
|
1253
|
+
}
|
|
1254
|
+
const o = {
|
|
1255
|
+
method: "POST",
|
|
1256
|
+
body: JSON.stringify(e),
|
|
1257
|
+
headers: n
|
|
1258
|
+
};
|
|
1259
|
+
let i;
|
|
1260
|
+
try {
|
|
1261
|
+
i = await fetch(t, o);
|
|
1262
|
+
} catch (f) {
|
|
1263
|
+
throw u.create("fetch-network-error", {
|
|
1264
|
+
originalErrorMessage: f?.message
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
if (i.status !== 200)
|
|
1268
|
+
throw u.create("fetch-status-error", {
|
|
1269
|
+
httpStatus: i.status
|
|
1270
|
+
});
|
|
1271
|
+
let c;
|
|
1272
|
+
try {
|
|
1273
|
+
c = await i.json();
|
|
1274
|
+
} catch (f) {
|
|
1275
|
+
throw u.create("fetch-parse-error", {
|
|
1276
|
+
originalErrorMessage: f?.message
|
|
1277
|
+
});
|
|
1278
|
+
}
|
|
1279
|
+
const a = c.ttl.match(/^([\d.]+)(s)$/);
|
|
1280
|
+
if (!a || !a[2] || isNaN(Number(a[1])))
|
|
1281
|
+
throw u.create("fetch-parse-error", {
|
|
1282
|
+
originalErrorMessage: `ttl field (timeToLive) is not in standard Protobuf Duration format: ${c.ttl}`
|
|
1283
|
+
});
|
|
1284
|
+
const l = Number(a[1]) * 1e3, y = Date.now();
|
|
1285
|
+
return {
|
|
1286
|
+
token: c.token,
|
|
1287
|
+
expireTimeMillis: y + l,
|
|
1288
|
+
issuedAtTimeMillis: y
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1291
|
+
function Rr(t, e) {
|
|
1292
|
+
const { projectId: r, appId: n, apiKey: s } = t.options;
|
|
1293
|
+
return {
|
|
1294
|
+
url: `${Se}/projects/${r}/apps/${n}:${Tr}?key=${s}`,
|
|
1295
|
+
body: {
|
|
1296
|
+
recaptcha_enterprise_token: e
|
|
1297
|
+
}
|
|
1298
|
+
};
|
|
1299
|
+
}
|
|
1300
|
+
function Re(t, e) {
|
|
1301
|
+
const { projectId: r, appId: n, apiKey: s } = t.options;
|
|
1302
|
+
return {
|
|
1303
|
+
url: `${Se}/projects/${r}/apps/${n}:${Cr}?key=${s}`,
|
|
1304
|
+
body: {
|
|
1305
|
+
// eslint-disable-next-line
|
|
1306
|
+
debug_token: e
|
|
1307
|
+
}
|
|
1308
|
+
};
|
|
1309
|
+
}
|
|
1310
|
+
const Br = "firebase-app-check-database", Pr = 1, C = "firebase-app-check-store", Be = "debug-token";
|
|
1311
|
+
let R = null;
|
|
1312
|
+
function Pe() {
|
|
1313
|
+
return R || (R = new Promise((t, e) => {
|
|
1314
|
+
try {
|
|
1315
|
+
const r = indexedDB.open(Br, Pr);
|
|
1316
|
+
r.onsuccess = (n) => {
|
|
1317
|
+
t(n.target.result);
|
|
1318
|
+
}, r.onerror = (n) => {
|
|
1319
|
+
e(u.create("storage-open", {
|
|
1320
|
+
originalErrorMessage: n.target.error?.message
|
|
1321
|
+
}));
|
|
1322
|
+
}, r.onupgradeneeded = (n) => {
|
|
1323
|
+
const s = n.target.result;
|
|
1324
|
+
n.oldVersion === 0 && s.createObjectStore(C, {
|
|
1325
|
+
keyPath: "compositeKey"
|
|
1326
|
+
});
|
|
1327
|
+
};
|
|
1328
|
+
} catch (r) {
|
|
1329
|
+
e(u.create("storage-open", {
|
|
1330
|
+
originalErrorMessage: r?.message
|
|
1331
|
+
}));
|
|
1332
|
+
}
|
|
1333
|
+
}), R);
|
|
1334
|
+
}
|
|
1335
|
+
function Mr(t) {
|
|
1336
|
+
return Oe(Ne(t));
|
|
1337
|
+
}
|
|
1338
|
+
function Or(t, e) {
|
|
1339
|
+
return Me(Ne(t), e);
|
|
1340
|
+
}
|
|
1341
|
+
function Nr(t) {
|
|
1342
|
+
return Me(Be, t);
|
|
1343
|
+
}
|
|
1344
|
+
function $r() {
|
|
1345
|
+
return Oe(Be);
|
|
1346
|
+
}
|
|
1347
|
+
async function Me(t, e) {
|
|
1348
|
+
const n = (await Pe()).transaction(C, "readwrite"), o = n.objectStore(C).put({
|
|
1349
|
+
compositeKey: t,
|
|
1350
|
+
value: e
|
|
1351
|
+
});
|
|
1352
|
+
return new Promise((i, c) => {
|
|
1353
|
+
o.onsuccess = (a) => {
|
|
1354
|
+
i();
|
|
1355
|
+
}, n.onerror = (a) => {
|
|
1356
|
+
c(u.create("storage-set", {
|
|
1357
|
+
originalErrorMessage: a.target.error?.message
|
|
1358
|
+
}));
|
|
1359
|
+
};
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
async function Oe(t) {
|
|
1363
|
+
const r = (await Pe()).transaction(C, "readonly"), s = r.objectStore(C).get(t);
|
|
1364
|
+
return new Promise((o, i) => {
|
|
1365
|
+
s.onsuccess = (c) => {
|
|
1366
|
+
const a = c.target.result;
|
|
1367
|
+
o(a ? a.value : void 0);
|
|
1368
|
+
}, r.onerror = (c) => {
|
|
1369
|
+
i(u.create("storage-get", {
|
|
1370
|
+
originalErrorMessage: c.target.error?.message
|
|
1371
|
+
}));
|
|
1372
|
+
};
|
|
1373
|
+
});
|
|
1374
|
+
}
|
|
1375
|
+
function Ne(t) {
|
|
1376
|
+
return `${t.options.appId}-${t.name}`;
|
|
1377
|
+
}
|
|
1378
|
+
const g = new ye("@firebase/app-check");
|
|
1379
|
+
async function xr(t) {
|
|
1380
|
+
if (X()) {
|
|
1381
|
+
let e;
|
|
1382
|
+
try {
|
|
1383
|
+
e = await Mr(t);
|
|
1384
|
+
} catch (r) {
|
|
1385
|
+
g.warn(`Failed to read token from IndexedDB. Error: ${r}`);
|
|
1386
|
+
}
|
|
1387
|
+
return e;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
function L(t, e) {
|
|
1391
|
+
return X() ? Or(t, e).catch((r) => {
|
|
1392
|
+
g.warn(`Failed to write token to IndexedDB. Error: ${r}`);
|
|
1393
|
+
}) : Promise.resolve();
|
|
1394
|
+
}
|
|
1395
|
+
async function Lr() {
|
|
1396
|
+
let t;
|
|
1397
|
+
try {
|
|
1398
|
+
t = await $r();
|
|
1399
|
+
} catch {
|
|
1400
|
+
}
|
|
1401
|
+
if (t)
|
|
1402
|
+
return t;
|
|
1403
|
+
{
|
|
1404
|
+
const e = crypto.randomUUID();
|
|
1405
|
+
return Nr(e).catch((r) => g.warn(`Failed to persist debug token to IndexedDB. Error: ${r}`)), e;
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
function ee() {
|
|
1409
|
+
return M().enabled;
|
|
1410
|
+
}
|
|
1411
|
+
async function te() {
|
|
1412
|
+
const t = M();
|
|
1413
|
+
if (t.enabled && t.token)
|
|
1414
|
+
return t.token.promise;
|
|
1415
|
+
throw Error(`
|
|
1416
|
+
Can't get debug token in production mode.
|
|
1417
|
+
`);
|
|
1418
|
+
}
|
|
1419
|
+
function Hr() {
|
|
1420
|
+
const t = _e(), e = M();
|
|
1421
|
+
if (e.initialized = !0, typeof t.FIREBASE_APPCHECK_DEBUG_TOKEN != "string" && t.FIREBASE_APPCHECK_DEBUG_TOKEN !== !0)
|
|
1422
|
+
return;
|
|
1423
|
+
e.enabled = !0;
|
|
1424
|
+
const r = new A();
|
|
1425
|
+
e.token = r, typeof t.FIREBASE_APPCHECK_DEBUG_TOKEN == "string" ? r.resolve(t.FIREBASE_APPCHECK_DEBUG_TOKEN) : r.resolve(Lr());
|
|
1426
|
+
}
|
|
1427
|
+
const Fr = { error: "UNKNOWN_ERROR" };
|
|
1428
|
+
function zr(t) {
|
|
1429
|
+
return q.encodeString(
|
|
1430
|
+
JSON.stringify(t),
|
|
1431
|
+
/* webSafe= */
|
|
1432
|
+
!1
|
|
1433
|
+
);
|
|
1434
|
+
}
|
|
1435
|
+
async function G(t, e = !1, r = !1) {
|
|
1436
|
+
const n = t.app;
|
|
1437
|
+
Z(n);
|
|
1438
|
+
const s = d(n);
|
|
1439
|
+
let o = s.token, i;
|
|
1440
|
+
if (o && !_(o) && (s.token = void 0, o = void 0), !o) {
|
|
1441
|
+
const l = await s.cachedTokenPromise;
|
|
1442
|
+
l && (_(l) ? o = l : await L(n, void 0));
|
|
1443
|
+
}
|
|
1444
|
+
if (!e && o && _(o))
|
|
1445
|
+
return {
|
|
1446
|
+
token: o.token
|
|
1447
|
+
};
|
|
1448
|
+
let c = !1;
|
|
1449
|
+
if (ee())
|
|
1450
|
+
try {
|
|
1451
|
+
s.exchangeTokenPromise || (s.exchangeTokenPromise = Q(Re(n, await te()), t.heartbeatServiceProvider).finally(() => {
|
|
1452
|
+
s.exchangeTokenPromise = void 0;
|
|
1453
|
+
}), c = !0);
|
|
1454
|
+
const l = await s.exchangeTokenPromise;
|
|
1455
|
+
return await L(n, l), s.token = l, { token: l.token };
|
|
1456
|
+
} catch (l) {
|
|
1457
|
+
return l.code === "appCheck/throttled" || l.code === "appCheck/initial-throttle" ? g.warn(l.message) : r && g.error(l), H(l);
|
|
1458
|
+
}
|
|
1459
|
+
try {
|
|
1460
|
+
s.exchangeTokenPromise || (s.exchangeTokenPromise = s.provider.getToken().finally(() => {
|
|
1461
|
+
s.exchangeTokenPromise = void 0;
|
|
1462
|
+
}), c = !0), o = await d(n).exchangeTokenPromise;
|
|
1463
|
+
} catch (l) {
|
|
1464
|
+
l.code === "appCheck/throttled" || l.code === "appCheck/initial-throttle" ? g.warn(l.message) : r && g.error(l), i = l;
|
|
1465
|
+
}
|
|
1466
|
+
let a;
|
|
1467
|
+
return o ? i ? _(o) ? a = {
|
|
1468
|
+
token: o.token,
|
|
1469
|
+
internalError: i
|
|
1470
|
+
} : a = H(i) : (a = {
|
|
1471
|
+
token: o.token
|
|
1472
|
+
}, s.token = o, await L(n, o)) : a = H(i), c && Le(n, a), a;
|
|
1473
|
+
}
|
|
1474
|
+
async function Ur(t) {
|
|
1475
|
+
const e = t.app;
|
|
1476
|
+
Z(e);
|
|
1477
|
+
const { provider: r } = d(e);
|
|
1478
|
+
if (ee()) {
|
|
1479
|
+
const n = await te(), { token: s } = await Q(Re(e, n), t.heartbeatServiceProvider);
|
|
1480
|
+
return { token: s };
|
|
1481
|
+
} else {
|
|
1482
|
+
const { token: n } = await r.getToken();
|
|
1483
|
+
return { token: n };
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
function $e(t, e, r, n) {
|
|
1487
|
+
const { app: s } = t, o = d(s), i = {
|
|
1488
|
+
next: r,
|
|
1489
|
+
error: n,
|
|
1490
|
+
type: e
|
|
1491
|
+
};
|
|
1492
|
+
if (o.tokenObservers = [...o.tokenObservers, i], o.token && _(o.token)) {
|
|
1493
|
+
const c = o.token;
|
|
1494
|
+
Promise.resolve().then(() => {
|
|
1495
|
+
r({ token: c.token }), pe(t);
|
|
1496
|
+
}).catch(() => {
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1499
|
+
o.cachedTokenPromise.then(() => pe(t));
|
|
1500
|
+
}
|
|
1501
|
+
function xe(t, e) {
|
|
1502
|
+
const r = d(t), n = r.tokenObservers.filter((s) => s.next !== e);
|
|
1503
|
+
n.length === 0 && r.tokenRefresher && r.tokenRefresher.isRunning() && r.tokenRefresher.stop(), r.tokenObservers = n;
|
|
1504
|
+
}
|
|
1505
|
+
function pe(t) {
|
|
1506
|
+
const { app: e } = t, r = d(e);
|
|
1507
|
+
let n = r.tokenRefresher;
|
|
1508
|
+
n || (n = jr(t), r.tokenRefresher = n), !n.isRunning() && r.isTokenAutoRefreshEnabled && n.start();
|
|
1509
|
+
}
|
|
1510
|
+
function jr(t) {
|
|
1511
|
+
const { app: e } = t;
|
|
1512
|
+
return new kr(
|
|
1513
|
+
// Keep in mind when this fails for any reason other than the ones
|
|
1514
|
+
// for which we should retry, it will effectively stop the proactive refresh.
|
|
1515
|
+
async () => {
|
|
1516
|
+
const r = d(e);
|
|
1517
|
+
let n;
|
|
1518
|
+
if (r.token ? n = await G(t, !0) : n = await G(t), n.error)
|
|
1519
|
+
throw n.error;
|
|
1520
|
+
if (n.internalError)
|
|
1521
|
+
throw n.internalError;
|
|
1522
|
+
},
|
|
1523
|
+
() => !0,
|
|
1524
|
+
() => {
|
|
1525
|
+
const r = d(e);
|
|
1526
|
+
if (r.token) {
|
|
1527
|
+
let n = r.token.issuedAtTimeMillis + (r.token.expireTimeMillis - r.token.issuedAtTimeMillis) * 0.5 + 3e5;
|
|
1528
|
+
const s = r.token.expireTimeMillis - 300 * 1e3;
|
|
1529
|
+
return n = Math.min(n, s), Math.max(0, n - Date.now());
|
|
1530
|
+
} else
|
|
1531
|
+
return 0;
|
|
1532
|
+
},
|
|
1533
|
+
ue.RETRIAL_MIN_WAIT,
|
|
1534
|
+
ue.RETRIAL_MAX_WAIT
|
|
1535
|
+
);
|
|
1536
|
+
}
|
|
1537
|
+
function Le(t, e) {
|
|
1538
|
+
const r = d(t).tokenObservers;
|
|
1539
|
+
for (const n of r)
|
|
1540
|
+
try {
|
|
1541
|
+
n.type === "EXTERNAL" && e.error != null ? n.error(e.error) : n.next(e);
|
|
1542
|
+
} catch {
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
function _(t) {
|
|
1546
|
+
return t.expireTimeMillis - Date.now() > 0;
|
|
1547
|
+
}
|
|
1548
|
+
function H(t) {
|
|
1549
|
+
return {
|
|
1550
|
+
token: zr(Fr),
|
|
1551
|
+
error: t
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
class Vr {
|
|
1555
|
+
constructor(e, r) {
|
|
1556
|
+
this.app = e, this.heartbeatServiceProvider = r;
|
|
1557
|
+
}
|
|
1558
|
+
_delete() {
|
|
1559
|
+
const { tokenObservers: e } = d(this.app);
|
|
1560
|
+
for (const r of e)
|
|
1561
|
+
xe(this.app, r.next);
|
|
1562
|
+
return Promise.resolve();
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
function Wr(t, e) {
|
|
1566
|
+
return new Vr(t, e);
|
|
1567
|
+
}
|
|
1568
|
+
function Kr(t) {
|
|
1569
|
+
return {
|
|
1570
|
+
getToken: (e) => G(t, e),
|
|
1571
|
+
getLimitedUseToken: () => Ur(t),
|
|
1572
|
+
addTokenListener: (e) => $e(t, "INTERNAL", e),
|
|
1573
|
+
removeTokenListener: (e) => xe(t.app, e)
|
|
1574
|
+
};
|
|
1575
|
+
}
|
|
1576
|
+
const Gr = "@firebase/app-check", qr = "0.11.0", Xr = "https://www.google.com/recaptcha/enterprise.js";
|
|
1577
|
+
function Yr(t, e) {
|
|
1578
|
+
const r = new A(), n = d(t);
|
|
1579
|
+
n.reCAPTCHAState = { initialized: r };
|
|
1580
|
+
const s = Jr(t), o = fe(!0);
|
|
1581
|
+
return o ? ge(t, e, o, s, r) : en(() => {
|
|
1582
|
+
const i = fe(!0);
|
|
1583
|
+
if (!i)
|
|
1584
|
+
throw new Error("no recaptcha");
|
|
1585
|
+
ge(t, e, i, s, r);
|
|
1586
|
+
}), r.promise;
|
|
1587
|
+
}
|
|
1588
|
+
function ge(t, e, r, n, s) {
|
|
1589
|
+
r.ready(() => {
|
|
1590
|
+
Qr(t, e, r, n), s.resolve(r);
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1593
|
+
function Jr(t) {
|
|
1594
|
+
const e = `fire_app_check_${t.name}`, r = document.createElement("div");
|
|
1595
|
+
return r.id = e, r.style.display = "none", document.body.appendChild(r), e;
|
|
1596
|
+
}
|
|
1597
|
+
async function Zr(t) {
|
|
1598
|
+
Z(t);
|
|
1599
|
+
const r = await d(t).reCAPTCHAState.initialized.promise;
|
|
1600
|
+
return new Promise((n, s) => {
|
|
1601
|
+
const o = d(t).reCAPTCHAState;
|
|
1602
|
+
r.ready(() => {
|
|
1603
|
+
n(
|
|
1604
|
+
// widgetId is guaranteed to be available if reCAPTCHAState.initialized.promise resolved.
|
|
1605
|
+
r.execute(o.widgetId, {
|
|
1606
|
+
action: "fire_app_check"
|
|
1607
|
+
})
|
|
1608
|
+
);
|
|
1609
|
+
});
|
|
1610
|
+
});
|
|
1611
|
+
}
|
|
1612
|
+
function Qr(t, e, r, n) {
|
|
1613
|
+
const s = r.render(n, {
|
|
1614
|
+
sitekey: e,
|
|
1615
|
+
size: "invisible",
|
|
1616
|
+
// Success callback - set state
|
|
1617
|
+
callback: () => {
|
|
1618
|
+
d(t).reCAPTCHAState.succeeded = !0;
|
|
1619
|
+
},
|
|
1620
|
+
// Failure callback - set state
|
|
1621
|
+
"error-callback": () => {
|
|
1622
|
+
d(t).reCAPTCHAState.succeeded = !1;
|
|
1623
|
+
}
|
|
1624
|
+
}), o = d(t);
|
|
1625
|
+
o.reCAPTCHAState = {
|
|
1626
|
+
...o.reCAPTCHAState,
|
|
1627
|
+
// state.reCAPTCHAState is set in the initialize()
|
|
1628
|
+
widgetId: s
|
|
1629
|
+
};
|
|
1630
|
+
}
|
|
1631
|
+
function en(t) {
|
|
1632
|
+
const e = document.createElement("script");
|
|
1633
|
+
e.src = Xr, e.onload = t, document.head.appendChild(e);
|
|
1634
|
+
}
|
|
1635
|
+
class re {
|
|
1636
|
+
/**
|
|
1637
|
+
* Create a ReCaptchaEnterpriseProvider instance.
|
|
1638
|
+
* @param siteKey - reCAPTCHA Enterprise score-based site key.
|
|
1639
|
+
*/
|
|
1640
|
+
constructor(e) {
|
|
1641
|
+
this._siteKey = e, this._throttleData = null;
|
|
1642
|
+
}
|
|
1643
|
+
/**
|
|
1644
|
+
* Returns an App Check token.
|
|
1645
|
+
* @internal
|
|
1646
|
+
*/
|
|
1647
|
+
async getToken() {
|
|
1648
|
+
rn(this._throttleData);
|
|
1649
|
+
const e = await Zr(this._app).catch((n) => {
|
|
1650
|
+
throw u.create(
|
|
1651
|
+
"recaptcha-error"
|
|
1652
|
+
/* AppCheckError.RECAPTCHA_ERROR */
|
|
1653
|
+
);
|
|
1654
|
+
});
|
|
1655
|
+
if (!d(this._app).reCAPTCHAState?.succeeded)
|
|
1656
|
+
throw u.create(
|
|
1657
|
+
"recaptcha-error"
|
|
1658
|
+
/* AppCheckError.RECAPTCHA_ERROR */
|
|
1659
|
+
);
|
|
1660
|
+
let r;
|
|
1661
|
+
try {
|
|
1662
|
+
r = await Q(Rr(this._app, e), this._heartbeatServiceProvider);
|
|
1663
|
+
} catch (n) {
|
|
1664
|
+
throw n.code?.includes(
|
|
1665
|
+
"fetch-status-error"
|
|
1666
|
+
/* AppCheckError.FETCH_STATUS_ERROR */
|
|
1667
|
+
) ? (this._throttleData = tn(Number(n.customData?.httpStatus), this._throttleData), u.create("initial-throttle", {
|
|
1668
|
+
time: ve(this._throttleData.allowRequestsAfter - Date.now()),
|
|
1669
|
+
httpStatus: this._throttleData.httpStatus
|
|
1670
|
+
})) : n;
|
|
1671
|
+
}
|
|
1672
|
+
return this._throttleData = null, r;
|
|
1673
|
+
}
|
|
1674
|
+
/**
|
|
1675
|
+
* @internal
|
|
1676
|
+
*/
|
|
1677
|
+
initialize(e) {
|
|
1678
|
+
this._app = e, this._heartbeatServiceProvider = Te(e, "heartbeat"), Yr(e, this._siteKey).catch(() => {
|
|
1679
|
+
});
|
|
1680
|
+
}
|
|
1681
|
+
/**
|
|
1682
|
+
* @internal
|
|
1683
|
+
*/
|
|
1684
|
+
isEqual(e) {
|
|
1685
|
+
return e instanceof re ? this._siteKey === e._siteKey : !1;
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
function tn(t, e) {
|
|
1689
|
+
if (t === 404 || t === 403)
|
|
1690
|
+
return {
|
|
1691
|
+
backoffCount: 1,
|
|
1692
|
+
allowRequestsAfter: Date.now() + Dr,
|
|
1693
|
+
httpStatus: t
|
|
1694
|
+
};
|
|
1695
|
+
{
|
|
1696
|
+
const r = e ? e.backoffCount : 0, n = dt(r, 1e3, 2);
|
|
1697
|
+
return {
|
|
1698
|
+
backoffCount: r + 1,
|
|
1699
|
+
allowRequestsAfter: Date.now() + n,
|
|
1700
|
+
httpStatus: t
|
|
1701
|
+
};
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
function rn(t) {
|
|
1705
|
+
if (t && Date.now() - t.allowRequestsAfter <= 0)
|
|
1706
|
+
throw u.create("throttled", {
|
|
1707
|
+
time: ve(t.allowRequestsAfter - Date.now()),
|
|
1708
|
+
httpStatus: t.httpStatus
|
|
1709
|
+
});
|
|
1710
|
+
}
|
|
1711
|
+
function nn(t = dr(), e) {
|
|
1712
|
+
t = ut(t);
|
|
1713
|
+
const r = Te(t, "app-check");
|
|
1714
|
+
if (M().initialized || Hr(), ee() && te().then((s) => (
|
|
1715
|
+
// Not using logger because I don't think we ever want this accidentally hidden.
|
|
1716
|
+
console.log(`App Check debug token: ${s}. You will need to add it to your app's App Check settings in the Firebase console for it to work.`)
|
|
1717
|
+
)), r.isInitialized()) {
|
|
1718
|
+
const s = r.getImmediate(), o = r.getOptions();
|
|
1719
|
+
if (o.isTokenAutoRefreshEnabled === e.isTokenAutoRefreshEnabled && o.provider.isEqual(e.provider))
|
|
1720
|
+
return s;
|
|
1721
|
+
throw u.create("already-initialized", {
|
|
1722
|
+
appName: t.name
|
|
1723
|
+
});
|
|
1724
|
+
}
|
|
1725
|
+
const n = r.initialize({ options: e });
|
|
1726
|
+
return sn(t, e.provider, e.isTokenAutoRefreshEnabled), d(t).isTokenAutoRefreshEnabled && $e(n, "INTERNAL", () => {
|
|
1727
|
+
}), n;
|
|
1728
|
+
}
|
|
1729
|
+
function sn(t, e, r = !1) {
|
|
1730
|
+
const n = Ir(t, { ...ke });
|
|
1731
|
+
n.activated = !0, n.provider = e, n.cachedTokenPromise = xr(t).then((s) => (s && _(s) && (n.token = s, Le(t, { token: s.token })), s)), n.isTokenAutoRefreshEnabled = r && t.automaticDataCollectionEnabled, !t.automaticDataCollectionEnabled && r && g.warn("`isTokenAutoRefreshEnabled` is true but `automaticDataCollectionEnabled` was set to false during `initializeApp()`. This blocks automatic token refresh."), n.provider.initialize(t);
|
|
1732
|
+
}
|
|
1733
|
+
const on = "app-check", me = "app-check-internal";
|
|
1734
|
+
function an() {
|
|
1735
|
+
I(new w(
|
|
1736
|
+
on,
|
|
1737
|
+
(t) => {
|
|
1738
|
+
const e = t.getProvider("app").getImmediate(), r = t.getProvider("heartbeat");
|
|
1739
|
+
return Wr(e, r);
|
|
1740
|
+
},
|
|
1741
|
+
"PUBLIC"
|
|
1742
|
+
/* ComponentType.PUBLIC */
|
|
1743
|
+
).setInstantiationMode(
|
|
1744
|
+
"EXPLICIT"
|
|
1745
|
+
/* InstantiationMode.EXPLICIT */
|
|
1746
|
+
).setInstanceCreatedCallback((t, e, r) => {
|
|
1747
|
+
t.getProvider(me).initialize();
|
|
1748
|
+
})), I(new w(
|
|
1749
|
+
me,
|
|
1750
|
+
(t) => {
|
|
1751
|
+
const e = t.getProvider("app-check").getImmediate();
|
|
1752
|
+
return Kr(e);
|
|
1753
|
+
},
|
|
1754
|
+
"PUBLIC"
|
|
1755
|
+
/* ComponentType.PUBLIC */
|
|
1756
|
+
).setInstantiationMode(
|
|
1757
|
+
"EXPLICIT"
|
|
1758
|
+
/* InstantiationMode.EXPLICIT */
|
|
1759
|
+
)), B(Gr, qr);
|
|
1760
|
+
}
|
|
1761
|
+
an();
|
|
1762
|
+
class dn extends Ke {
|
|
1763
|
+
#e;
|
|
1764
|
+
#t;
|
|
1765
|
+
constructor(e) {
|
|
1766
|
+
const {
|
|
1767
|
+
geminiApiProvider: r,
|
|
1768
|
+
modelName: n,
|
|
1769
|
+
useAppCheck: s,
|
|
1770
|
+
reCaptchaSiteKey: o,
|
|
1771
|
+
useLimitedUseAppCheckTokens: i,
|
|
1772
|
+
...c
|
|
1773
|
+
} = e;
|
|
1774
|
+
super(n || Ge.firebase.modelName);
|
|
1775
|
+
const a = Fe(c);
|
|
1776
|
+
s && o && nn(a, {
|
|
1777
|
+
provider: new re(o),
|
|
1778
|
+
isTokenAutoRefreshEnabled: !0
|
|
1779
|
+
});
|
|
1780
|
+
const l = r === "vertex" ? new ze() : new Ue();
|
|
1781
|
+
this.ai = je(a, {
|
|
1782
|
+
backend: l,
|
|
1783
|
+
useLimitedUseAppCheckTokens: i || !0
|
|
1784
|
+
});
|
|
1785
|
+
}
|
|
1786
|
+
createSession(e, r) {
|
|
1787
|
+
return this.#t = r, this.#e = Ve(this.ai, {
|
|
1788
|
+
mode: We.ONLY_IN_CLOUD,
|
|
1789
|
+
inCloudParams: r
|
|
1790
|
+
}), this.#e;
|
|
1791
|
+
}
|
|
1792
|
+
async generateContent(e) {
|
|
1793
|
+
const r = await this.#e.generateContent({ contents: e }), n = r.response.usageMetadata?.promptTokenCount || 0;
|
|
1794
|
+
return { text: r.response.text(), usage: n };
|
|
1795
|
+
}
|
|
1796
|
+
async generateContentStream(e) {
|
|
1797
|
+
return (await this.#e.generateContentStream({ contents: e })).stream;
|
|
1798
|
+
}
|
|
1799
|
+
async countTokens(e) {
|
|
1800
|
+
const { totalTokens: r } = await this.#e.countTokens({
|
|
1801
|
+
contents: e
|
|
1802
|
+
});
|
|
1803
|
+
return r;
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
export {
|
|
1807
|
+
dn as default
|
|
1808
|
+
};
|