@purr-core/services.firebase 0.0.1

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.
@@ -0,0 +1,2136 @@
1
+ import { bj as He, bk as y, b6 as $e, bl as je, bd as ze, bm as Xe, b9 as Ge, bn as We, a_ as ce, a$ as Ve } from "./index-B2y0TOTi.js";
2
+ /**
3
+ * @license
4
+ * Copyright 2017 Google LLC
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ const ge = "firebasestorage.googleapis.com", be = "storageBucket", Ke = 2 * 60 * 1e3, Ye = 10 * 60 * 1e3, Ze = 1e3;
19
+ /**
20
+ * @license
21
+ * Copyright 2017 Google LLC
22
+ *
23
+ * Licensed under the Apache License, Version 2.0 (the "License");
24
+ * you may not use this file except in compliance with the License.
25
+ * You may obtain a copy of the License at
26
+ *
27
+ * http://www.apache.org/licenses/LICENSE-2.0
28
+ *
29
+ * Unless required by applicable law or agreed to in writing, software
30
+ * distributed under the License is distributed on an "AS IS" BASIS,
31
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
+ * See the License for the specific language governing permissions and
33
+ * limitations under the License.
34
+ */
35
+ class d extends He {
36
+ /**
37
+ * @param code - A `StorageErrorCode` string to be prefixed with 'storage/' and
38
+ * added to the end of the message.
39
+ * @param message - Error message.
40
+ * @param status_ - Corresponding HTTP Status Code
41
+ */
42
+ constructor(e, n, s = 0) {
43
+ super(Z(e), `Firebase Storage: ${n} (${Z(e)})`), this.status_ = s, this.customData = { serverResponse: null }, this._baseMessage = this.message, Object.setPrototypeOf(this, d.prototype);
44
+ }
45
+ get status() {
46
+ return this.status_;
47
+ }
48
+ set status(e) {
49
+ this.status_ = e;
50
+ }
51
+ /**
52
+ * Compares a `StorageErrorCode` against this error's code, filtering out the prefix.
53
+ */
54
+ _codeEquals(e) {
55
+ return Z(e) === this.code;
56
+ }
57
+ /**
58
+ * Optional response message that was added by the server.
59
+ */
60
+ get serverResponse() {
61
+ return this.customData.serverResponse;
62
+ }
63
+ set serverResponse(e) {
64
+ this.customData.serverResponse = e, this.customData.serverResponse ? this.message = `${this._baseMessage}
65
+ ${this.customData.serverResponse}` : this.message = this._baseMessage;
66
+ }
67
+ }
68
+ var h;
69
+ (function(t) {
70
+ t.UNKNOWN = "unknown", t.OBJECT_NOT_FOUND = "object-not-found", t.BUCKET_NOT_FOUND = "bucket-not-found", t.PROJECT_NOT_FOUND = "project-not-found", t.QUOTA_EXCEEDED = "quota-exceeded", t.UNAUTHENTICATED = "unauthenticated", t.UNAUTHORIZED = "unauthorized", t.UNAUTHORIZED_APP = "unauthorized-app", t.RETRY_LIMIT_EXCEEDED = "retry-limit-exceeded", t.INVALID_CHECKSUM = "invalid-checksum", t.CANCELED = "canceled", t.INVALID_EVENT_NAME = "invalid-event-name", t.INVALID_URL = "invalid-url", t.INVALID_DEFAULT_BUCKET = "invalid-default-bucket", t.NO_DEFAULT_BUCKET = "no-default-bucket", t.CANNOT_SLICE_BLOB = "cannot-slice-blob", t.SERVER_FILE_WRONG_SIZE = "server-file-wrong-size", t.NO_DOWNLOAD_URL = "no-download-url", t.INVALID_ARGUMENT = "invalid-argument", t.INVALID_ARGUMENT_COUNT = "invalid-argument-count", t.APP_DELETED = "app-deleted", t.INVALID_ROOT_OPERATION = "invalid-root-operation", t.INVALID_FORMAT = "invalid-format", t.INTERNAL_ERROR = "internal-error", t.UNSUPPORTED_ENVIRONMENT = "unsupported-environment";
71
+ })(h || (h = {}));
72
+ function Z(t) {
73
+ return "storage/" + t;
74
+ }
75
+ function ne() {
76
+ const t = "An unknown error occurred, please check the error payload for server response.";
77
+ return new d(h.UNKNOWN, t);
78
+ }
79
+ function Je(t) {
80
+ return new d(h.OBJECT_NOT_FOUND, "Object '" + t + "' does not exist.");
81
+ }
82
+ function Qe(t) {
83
+ return new d(h.QUOTA_EXCEEDED, "Quota for bucket '" + t + "' exceeded, please view quota on https://firebase.google.com/pricing/.");
84
+ }
85
+ function et() {
86
+ const t = "User is not authenticated, please authenticate using Firebase Authentication and try again.";
87
+ return new d(h.UNAUTHENTICATED, t);
88
+ }
89
+ function tt() {
90
+ return new d(h.UNAUTHORIZED_APP, "This app does not have permission to access Firebase Storage on this project.");
91
+ }
92
+ function nt(t) {
93
+ return new d(h.UNAUTHORIZED, "User does not have permission to access '" + t + "'.");
94
+ }
95
+ function Re() {
96
+ return new d(h.RETRY_LIMIT_EXCEEDED, "Max retry time for operation exceeded, please try again.");
97
+ }
98
+ function Te() {
99
+ return new d(h.CANCELED, "User canceled the upload/download.");
100
+ }
101
+ function st(t) {
102
+ return new d(h.INVALID_URL, "Invalid URL '" + t + "'.");
103
+ }
104
+ function rt(t) {
105
+ return new d(h.INVALID_DEFAULT_BUCKET, "Invalid default bucket '" + t + "'.");
106
+ }
107
+ function ot() {
108
+ return new d(h.NO_DEFAULT_BUCKET, "No default bucket found. Did you set the '" + be + "' property when initializing the app?");
109
+ }
110
+ function ke() {
111
+ return new d(h.CANNOT_SLICE_BLOB, "Cannot slice blob for upload. Please retry the upload.");
112
+ }
113
+ function it() {
114
+ return new d(h.SERVER_FILE_WRONG_SIZE, "Server recorded incorrect upload file size, please retry the upload.");
115
+ }
116
+ function at() {
117
+ return new d(h.NO_DOWNLOAD_URL, "The given file does not have any download URLs.");
118
+ }
119
+ function ut(t) {
120
+ return new d(h.UNSUPPORTED_ENVIRONMENT, `${t} is missing. Make sure to install the required polyfills. See https://firebase.google.com/docs/web/environments-js-sdk#polyfills for more information.`);
121
+ }
122
+ function ee(t) {
123
+ return new d(h.INVALID_ARGUMENT, t);
124
+ }
125
+ function we() {
126
+ return new d(h.APP_DELETED, "The Firebase app was deleted.");
127
+ }
128
+ function ct(t) {
129
+ return new d(h.INVALID_ROOT_OPERATION, "The operation '" + t + "' cannot be performed on a root reference, create a non-root reference using child, such as .child('file.png').");
130
+ }
131
+ function H(t, e) {
132
+ return new d(h.INVALID_FORMAT, "String does not match format '" + t + "': " + e);
133
+ }
134
+ function F(t) {
135
+ throw new d(h.INTERNAL_ERROR, "Internal error: " + t);
136
+ }
137
+ /**
138
+ * @license
139
+ * Copyright 2017 Google LLC
140
+ *
141
+ * Licensed under the Apache License, Version 2.0 (the "License");
142
+ * you may not use this file except in compliance with the License.
143
+ * You may obtain a copy of the License at
144
+ *
145
+ * http://www.apache.org/licenses/LICENSE-2.0
146
+ *
147
+ * Unless required by applicable law or agreed to in writing, software
148
+ * distributed under the License is distributed on an "AS IS" BASIS,
149
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
150
+ * See the License for the specific language governing permissions and
151
+ * limitations under the License.
152
+ */
153
+ class k {
154
+ constructor(e, n) {
155
+ this.bucket = e, this.path_ = n;
156
+ }
157
+ get path() {
158
+ return this.path_;
159
+ }
160
+ get isRoot() {
161
+ return this.path.length === 0;
162
+ }
163
+ fullServerUrl() {
164
+ const e = encodeURIComponent;
165
+ return "/b/" + e(this.bucket) + "/o/" + e(this.path);
166
+ }
167
+ bucketOnlyServerUrl() {
168
+ return "/b/" + encodeURIComponent(this.bucket) + "/o";
169
+ }
170
+ static makeFromBucketSpec(e, n) {
171
+ let s;
172
+ try {
173
+ s = k.makeFromUrl(e, n);
174
+ } catch {
175
+ return new k(e, "");
176
+ }
177
+ if (s.path === "")
178
+ return s;
179
+ throw rt(e);
180
+ }
181
+ static makeFromUrl(e, n) {
182
+ let s = null;
183
+ const r = "([A-Za-z0-9.\\-_]+)";
184
+ function o(b) {
185
+ b.path.charAt(b.path.length - 1) === "/" && (b.path_ = b.path_.slice(0, -1));
186
+ }
187
+ const i = "(/(.*))?$", u = new RegExp("^gs://" + r + i, "i"), a = { bucket: 1, path: 3 };
188
+ function c(b) {
189
+ b.path_ = decodeURIComponent(b.path);
190
+ }
191
+ const l = "v[A-Za-z0-9_]+", f = n.replace(/[.]/g, "\\."), p = "(/([^?#]*).*)?$", m = new RegExp(`^https?://${f}/${l}/b/${r}/o${p}`, "i"), g = { bucket: 1, path: 3 }, E = n === ge ? "(?:storage.googleapis.com|storage.cloud.google.com)" : n, _ = "([^?#]*)", S = new RegExp(`^https?://${E}/${r}/${_}`, "i"), R = [
192
+ { regex: u, indices: a, postModify: o },
193
+ {
194
+ regex: m,
195
+ indices: g,
196
+ postModify: c
197
+ },
198
+ {
199
+ regex: S,
200
+ indices: { bucket: 1, path: 2 },
201
+ postModify: c
202
+ }
203
+ ];
204
+ for (let b = 0; b < R.length; b++) {
205
+ const D = R[b], L = D.regex.exec(e);
206
+ if (L) {
207
+ const K = L[D.indices.bucket];
208
+ let M = L[D.indices.path];
209
+ M || (M = ""), s = new k(K, M), D.postModify(s);
210
+ break;
211
+ }
212
+ }
213
+ if (s == null)
214
+ throw st(e);
215
+ return s;
216
+ }
217
+ }
218
+ class lt {
219
+ constructor(e) {
220
+ this.promise_ = Promise.reject(e);
221
+ }
222
+ /** @inheritDoc */
223
+ getPromise() {
224
+ return this.promise_;
225
+ }
226
+ /** @inheritDoc */
227
+ cancel(e = !1) {
228
+ }
229
+ }
230
+ /**
231
+ * @license
232
+ * Copyright 2017 Google LLC
233
+ *
234
+ * Licensed under the Apache License, Version 2.0 (the "License");
235
+ * you may not use this file except in compliance with the License.
236
+ * You may obtain a copy of the License at
237
+ *
238
+ * http://www.apache.org/licenses/LICENSE-2.0
239
+ *
240
+ * Unless required by applicable law or agreed to in writing, software
241
+ * distributed under the License is distributed on an "AS IS" BASIS,
242
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
243
+ * See the License for the specific language governing permissions and
244
+ * limitations under the License.
245
+ */
246
+ function ht(t, e, n) {
247
+ let s = 1, r = null, o = null, i = !1, u = 0;
248
+ function a() {
249
+ return u === 2;
250
+ }
251
+ let c = !1;
252
+ function l(..._) {
253
+ c || (c = !0, e.apply(null, _));
254
+ }
255
+ function f(_) {
256
+ r = setTimeout(() => {
257
+ r = null, t(m, a());
258
+ }, _);
259
+ }
260
+ function p() {
261
+ o && clearTimeout(o);
262
+ }
263
+ function m(_, ...S) {
264
+ if (c) {
265
+ p();
266
+ return;
267
+ }
268
+ if (_) {
269
+ p(), l.call(null, _, ...S);
270
+ return;
271
+ }
272
+ if (a() || i) {
273
+ p(), l.call(null, _, ...S);
274
+ return;
275
+ }
276
+ s < 64 && (s *= 2);
277
+ let R;
278
+ u === 1 ? (u = 2, R = 0) : R = (s + Math.random()) * 1e3, f(R);
279
+ }
280
+ let g = !1;
281
+ function E(_) {
282
+ g || (g = !0, p(), !c && (r !== null ? (_ || (u = 2), clearTimeout(r), f(0)) : _ || (u = 1)));
283
+ }
284
+ return f(0), o = setTimeout(() => {
285
+ i = !0, E(!0);
286
+ }, n), E;
287
+ }
288
+ function dt(t) {
289
+ t(!1);
290
+ }
291
+ /**
292
+ * @license
293
+ * Copyright 2017 Google LLC
294
+ *
295
+ * Licensed under the Apache License, Version 2.0 (the "License");
296
+ * you may not use this file except in compliance with the License.
297
+ * You may obtain a copy of the License at
298
+ *
299
+ * http://www.apache.org/licenses/LICENSE-2.0
300
+ *
301
+ * Unless required by applicable law or agreed to in writing, software
302
+ * distributed under the License is distributed on an "AS IS" BASIS,
303
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
304
+ * See the License for the specific language governing permissions and
305
+ * limitations under the License.
306
+ */
307
+ function ft(t) {
308
+ return t !== void 0;
309
+ }
310
+ function _t(t) {
311
+ return typeof t == "function";
312
+ }
313
+ function pt(t) {
314
+ return typeof t == "object" && !Array.isArray(t);
315
+ }
316
+ function W(t) {
317
+ return typeof t == "string" || t instanceof String;
318
+ }
319
+ function le(t) {
320
+ return se() && t instanceof Blob;
321
+ }
322
+ function se() {
323
+ return typeof Blob < "u";
324
+ }
325
+ function te(t, e, n, s) {
326
+ if (s < e)
327
+ throw ee(`Invalid value for '${t}'. Expected ${e} or greater.`);
328
+ if (s > n)
329
+ throw ee(`Invalid value for '${t}'. Expected ${n} or less.`);
330
+ }
331
+ /**
332
+ * @license
333
+ * Copyright 2017 Google LLC
334
+ *
335
+ * Licensed under the Apache License, Version 2.0 (the "License");
336
+ * you may not use this file except in compliance with the License.
337
+ * You may obtain a copy of the License at
338
+ *
339
+ * http://www.apache.org/licenses/LICENSE-2.0
340
+ *
341
+ * Unless required by applicable law or agreed to in writing, software
342
+ * distributed under the License is distributed on an "AS IS" BASIS,
343
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
344
+ * See the License for the specific language governing permissions and
345
+ * limitations under the License.
346
+ */
347
+ function x(t, e, n) {
348
+ let s = e;
349
+ return n == null && (s = `https://${e}`), `${n}://${s}/v0${t}`;
350
+ }
351
+ function ye(t) {
352
+ const e = encodeURIComponent;
353
+ let n = "?";
354
+ for (const s in t)
355
+ if (t.hasOwnProperty(s)) {
356
+ const r = e(s) + "=" + e(t[s]);
357
+ n = n + r + "&";
358
+ }
359
+ return n = n.slice(0, -1), n;
360
+ }
361
+ var N;
362
+ (function(t) {
363
+ t[t.NO_ERROR = 0] = "NO_ERROR", t[t.NETWORK_ERROR = 1] = "NETWORK_ERROR", t[t.ABORT = 2] = "ABORT";
364
+ })(N || (N = {}));
365
+ /**
366
+ * @license
367
+ * Copyright 2022 Google LLC
368
+ *
369
+ * Licensed under the Apache License, Version 2.0 (the "License");
370
+ * you may not use this file except in compliance with the License.
371
+ * You may obtain a copy of the License at
372
+ *
373
+ * http://www.apache.org/licenses/LICENSE-2.0
374
+ *
375
+ * Unless required by applicable law or agreed to in writing, software
376
+ * distributed under the License is distributed on an "AS IS" BASIS,
377
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
378
+ * See the License for the specific language governing permissions and
379
+ * limitations under the License.
380
+ */
381
+ function Ee(t, e) {
382
+ const n = t >= 500 && t < 600, r = [
383
+ // Request Timeout: web server didn't receive full request in time.
384
+ 408,
385
+ // Too Many Requests: you're getting rate-limited, basically.
386
+ 429
387
+ ].indexOf(t) !== -1, o = e.indexOf(t) !== -1;
388
+ return n || r || o;
389
+ }
390
+ /**
391
+ * @license
392
+ * Copyright 2017 Google LLC
393
+ *
394
+ * Licensed under the Apache License, Version 2.0 (the "License");
395
+ * you may not use this file except in compliance with the License.
396
+ * You may obtain a copy of the License at
397
+ *
398
+ * http://www.apache.org/licenses/LICENSE-2.0
399
+ *
400
+ * Unless required by applicable law or agreed to in writing, software
401
+ * distributed under the License is distributed on an "AS IS" BASIS,
402
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
403
+ * See the License for the specific language governing permissions and
404
+ * limitations under the License.
405
+ */
406
+ class mt {
407
+ constructor(e, n, s, r, o, i, u, a, c, l, f, p = !0) {
408
+ this.url_ = e, this.method_ = n, this.headers_ = s, this.body_ = r, this.successCodes_ = o, this.additionalRetryCodes_ = i, this.callback_ = u, this.errorCallback_ = a, this.timeout_ = c, this.progressCallback_ = l, this.connectionFactory_ = f, this.retry = p, this.pendingConnection_ = null, this.backoffId_ = null, this.canceled_ = !1, this.appDelete_ = !1, this.promise_ = new Promise((m, g) => {
409
+ this.resolve_ = m, this.reject_ = g, this.start_();
410
+ });
411
+ }
412
+ /**
413
+ * Actually starts the retry loop.
414
+ */
415
+ start_() {
416
+ const e = (s, r) => {
417
+ if (r) {
418
+ s(!1, new z(!1, null, !0));
419
+ return;
420
+ }
421
+ const o = this.connectionFactory_();
422
+ this.pendingConnection_ = o;
423
+ const i = (u) => {
424
+ const a = u.loaded, c = u.lengthComputable ? u.total : -1;
425
+ this.progressCallback_ !== null && this.progressCallback_(a, c);
426
+ };
427
+ this.progressCallback_ !== null && o.addUploadProgressListener(i), o.send(this.url_, this.method_, this.body_, this.headers_).then(() => {
428
+ this.progressCallback_ !== null && o.removeUploadProgressListener(i), this.pendingConnection_ = null;
429
+ const u = o.getErrorCode() === N.NO_ERROR, a = o.getStatus();
430
+ if (!u || Ee(a, this.additionalRetryCodes_) && this.retry) {
431
+ const l = o.getErrorCode() === N.ABORT;
432
+ s(!1, new z(!1, null, l));
433
+ return;
434
+ }
435
+ const c = this.successCodes_.indexOf(a) !== -1;
436
+ s(!0, new z(c, o));
437
+ });
438
+ }, n = (s, r) => {
439
+ const o = this.resolve_, i = this.reject_, u = r.connection;
440
+ if (r.wasSuccessCode)
441
+ try {
442
+ const a = this.callback_(u, u.getResponse());
443
+ ft(a) ? o(a) : o();
444
+ } catch (a) {
445
+ i(a);
446
+ }
447
+ else if (u !== null) {
448
+ const a = ne();
449
+ a.serverResponse = u.getErrorText(), this.errorCallback_ ? i(this.errorCallback_(u, a)) : i(a);
450
+ } else if (r.canceled) {
451
+ const a = this.appDelete_ ? we() : Te();
452
+ i(a);
453
+ } else {
454
+ const a = Re();
455
+ i(a);
456
+ }
457
+ };
458
+ this.canceled_ ? n(!1, new z(!1, null, !0)) : this.backoffId_ = ht(e, n, this.timeout_);
459
+ }
460
+ /** @inheritDoc */
461
+ getPromise() {
462
+ return this.promise_;
463
+ }
464
+ /** @inheritDoc */
465
+ cancel(e) {
466
+ this.canceled_ = !0, this.appDelete_ = e || !1, this.backoffId_ !== null && dt(this.backoffId_), this.pendingConnection_ !== null && this.pendingConnection_.abort();
467
+ }
468
+ }
469
+ class z {
470
+ constructor(e, n, s) {
471
+ this.wasSuccessCode = e, this.connection = n, this.canceled = !!s;
472
+ }
473
+ }
474
+ function gt(t, e) {
475
+ e !== null && e.length > 0 && (t.Authorization = "Firebase " + e);
476
+ }
477
+ function bt(t, e) {
478
+ t["X-Firebase-Storage-Version"] = "webjs/" + (e ?? "AppManager");
479
+ }
480
+ function Rt(t, e) {
481
+ e && (t["X-Firebase-GMPID"] = e);
482
+ }
483
+ function Tt(t, e) {
484
+ e !== null && (t["X-Firebase-AppCheck"] = e);
485
+ }
486
+ function kt(t, e, n, s, r, o, i = !0) {
487
+ const u = ye(t.urlParams), a = t.url + u, c = Object.assign({}, t.headers);
488
+ return Rt(c, e), gt(c, n), bt(c, o), Tt(c, s), new mt(a, t.method, c, t.body, t.successCodes, t.additionalRetryCodes, t.handler, t.errorHandler, t.timeout, t.progressCallback, r, i);
489
+ }
490
+ /**
491
+ * @license
492
+ * Copyright 2017 Google LLC
493
+ *
494
+ * Licensed under the Apache License, Version 2.0 (the "License");
495
+ * you may not use this file except in compliance with the License.
496
+ * You may obtain a copy of the License at
497
+ *
498
+ * http://www.apache.org/licenses/LICENSE-2.0
499
+ *
500
+ * Unless required by applicable law or agreed to in writing, software
501
+ * distributed under the License is distributed on an "AS IS" BASIS,
502
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
503
+ * See the License for the specific language governing permissions and
504
+ * limitations under the License.
505
+ */
506
+ function wt() {
507
+ return typeof BlobBuilder < "u" ? BlobBuilder : typeof WebKitBlobBuilder < "u" ? WebKitBlobBuilder : void 0;
508
+ }
509
+ function yt(...t) {
510
+ const e = wt();
511
+ if (e !== void 0) {
512
+ const n = new e();
513
+ for (let s = 0; s < t.length; s++)
514
+ n.append(t[s]);
515
+ return n.getBlob();
516
+ } else {
517
+ if (se())
518
+ return new Blob(t);
519
+ throw new d(h.UNSUPPORTED_ENVIRONMENT, "This browser doesn't seem to support creating Blobs");
520
+ }
521
+ }
522
+ function Et(t, e, n) {
523
+ return t.webkitSlice ? t.webkitSlice(e, n) : t.mozSlice ? t.mozSlice(e, n) : t.slice ? t.slice(e, n) : null;
524
+ }
525
+ /**
526
+ * @license
527
+ * Copyright 2021 Google LLC
528
+ *
529
+ * Licensed under the Apache License, Version 2.0 (the "License");
530
+ * you may not use this file except in compliance with the License.
531
+ * You may obtain a copy of the License at
532
+ *
533
+ * http://www.apache.org/licenses/LICENSE-2.0
534
+ *
535
+ * Unless required by applicable law or agreed to in writing, software
536
+ * distributed under the License is distributed on an "AS IS" BASIS,
537
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
538
+ * See the License for the specific language governing permissions and
539
+ * limitations under the License.
540
+ */
541
+ function Ut(t) {
542
+ if (typeof atob > "u")
543
+ throw ut("base-64");
544
+ return atob(t);
545
+ }
546
+ /**
547
+ * @license
548
+ * Copyright 2017 Google LLC
549
+ *
550
+ * Licensed under the Apache License, Version 2.0 (the "License");
551
+ * you may not use this file except in compliance with the License.
552
+ * You may obtain a copy of the License at
553
+ *
554
+ * http://www.apache.org/licenses/LICENSE-2.0
555
+ *
556
+ * Unless required by applicable law or agreed to in writing, software
557
+ * distributed under the License is distributed on an "AS IS" BASIS,
558
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
559
+ * See the License for the specific language governing permissions and
560
+ * limitations under the License.
561
+ */
562
+ const A = {
563
+ /**
564
+ * Indicates the string should be interpreted "raw", that is, as normal text.
565
+ * The string will be interpreted as UTF-16, then uploaded as a UTF-8 byte
566
+ * sequence.
567
+ * Example: The string 'Hello! \\ud83d\\ude0a' becomes the byte sequence
568
+ * 48 65 6c 6c 6f 21 20 f0 9f 98 8a
569
+ */
570
+ RAW: "raw",
571
+ /**
572
+ * Indicates the string should be interpreted as base64-encoded data.
573
+ * Padding characters (trailing '='s) are optional.
574
+ * Example: The string 'rWmO++E6t7/rlw==' becomes the byte sequence
575
+ * ad 69 8e fb e1 3a b7 bf eb 97
576
+ */
577
+ BASE64: "base64",
578
+ /**
579
+ * Indicates the string should be interpreted as base64url-encoded data.
580
+ * Padding characters (trailing '='s) are optional.
581
+ * Example: The string 'rWmO--E6t7_rlw==' becomes the byte sequence
582
+ * ad 69 8e fb e1 3a b7 bf eb 97
583
+ */
584
+ BASE64URL: "base64url",
585
+ /**
586
+ * Indicates the string is a data URL, such as one obtained from
587
+ * canvas.toDataURL().
588
+ * Example: the string 'data:application/octet-stream;base64,aaaa'
589
+ * becomes the byte sequence
590
+ * 69 a6 9a
591
+ * (the content-type "application/octet-stream" is also applied, but can
592
+ * be overridden in the metadata object).
593
+ */
594
+ DATA_URL: "data_url"
595
+ };
596
+ class J {
597
+ constructor(e, n) {
598
+ this.data = e, this.contentType = n || null;
599
+ }
600
+ }
601
+ function Ue(t, e) {
602
+ switch (t) {
603
+ case A.RAW:
604
+ return new J(Ae(e));
605
+ case A.BASE64:
606
+ case A.BASE64URL:
607
+ return new J(Oe(t, e));
608
+ case A.DATA_URL:
609
+ return new J(Ot(e), It(e));
610
+ }
611
+ throw ne();
612
+ }
613
+ function Ae(t) {
614
+ const e = [];
615
+ for (let n = 0; n < t.length; n++) {
616
+ let s = t.charCodeAt(n);
617
+ if (s <= 127)
618
+ e.push(s);
619
+ else if (s <= 2047)
620
+ e.push(192 | s >> 6, 128 | s & 63);
621
+ else if ((s & 64512) === 55296)
622
+ if (!(n < t.length - 1 && (t.charCodeAt(n + 1) & 64512) === 56320))
623
+ e.push(239, 191, 189);
624
+ else {
625
+ const o = s, i = t.charCodeAt(++n);
626
+ s = 65536 | (o & 1023) << 10 | i & 1023, e.push(240 | s >> 18, 128 | s >> 12 & 63, 128 | s >> 6 & 63, 128 | s & 63);
627
+ }
628
+ else
629
+ (s & 64512) === 56320 ? e.push(239, 191, 189) : e.push(224 | s >> 12, 128 | s >> 6 & 63, 128 | s & 63);
630
+ }
631
+ return new Uint8Array(e);
632
+ }
633
+ function At(t) {
634
+ let e;
635
+ try {
636
+ e = decodeURIComponent(t);
637
+ } catch {
638
+ throw H(A.DATA_URL, "Malformed data URL.");
639
+ }
640
+ return Ae(e);
641
+ }
642
+ function Oe(t, e) {
643
+ switch (t) {
644
+ case A.BASE64: {
645
+ const r = e.indexOf("-") !== -1, o = e.indexOf("_") !== -1;
646
+ if (r || o)
647
+ throw H(t, "Invalid character '" + (r ? "-" : "_") + "' found: is it base64url encoded?");
648
+ break;
649
+ }
650
+ case A.BASE64URL: {
651
+ const r = e.indexOf("+") !== -1, o = e.indexOf("/") !== -1;
652
+ if (r || o)
653
+ throw H(t, "Invalid character '" + (r ? "+" : "/") + "' found: is it base64 encoded?");
654
+ e = e.replace(/-/g, "+").replace(/_/g, "/");
655
+ break;
656
+ }
657
+ }
658
+ let n;
659
+ try {
660
+ n = Ut(e);
661
+ } catch (r) {
662
+ throw r.message.includes("polyfill") ? r : H(t, "Invalid character found");
663
+ }
664
+ const s = new Uint8Array(n.length);
665
+ for (let r = 0; r < n.length; r++)
666
+ s[r] = n.charCodeAt(r);
667
+ return s;
668
+ }
669
+ class Ie {
670
+ constructor(e) {
671
+ this.base64 = !1, this.contentType = null;
672
+ const n = e.match(/^data:([^,]+)?,/);
673
+ if (n === null)
674
+ throw H(A.DATA_URL, "Must be formatted 'data:[<mediatype>][;base64],<data>");
675
+ const s = n[1] || null;
676
+ s != null && (this.base64 = St(s, ";base64"), this.contentType = this.base64 ? s.substring(0, s.length - 7) : s), this.rest = e.substring(e.indexOf(",") + 1);
677
+ }
678
+ }
679
+ function Ot(t) {
680
+ const e = new Ie(t);
681
+ return e.base64 ? Oe(A.BASE64, e.rest) : At(e.rest);
682
+ }
683
+ function It(t) {
684
+ return new Ie(t).contentType;
685
+ }
686
+ function St(t, e) {
687
+ return t.length >= e.length ? t.substring(t.length - e.length) === e : !1;
688
+ }
689
+ /**
690
+ * @license
691
+ * Copyright 2017 Google LLC
692
+ *
693
+ * Licensed under the Apache License, Version 2.0 (the "License");
694
+ * you may not use this file except in compliance with the License.
695
+ * You may obtain a copy of the License at
696
+ *
697
+ * http://www.apache.org/licenses/LICENSE-2.0
698
+ *
699
+ * Unless required by applicable law or agreed to in writing, software
700
+ * distributed under the License is distributed on an "AS IS" BASIS,
701
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
702
+ * See the License for the specific language governing permissions and
703
+ * limitations under the License.
704
+ */
705
+ class C {
706
+ constructor(e, n) {
707
+ let s = 0, r = "";
708
+ le(e) ? (this.data_ = e, s = e.size, r = e.type) : e instanceof ArrayBuffer ? (n ? this.data_ = new Uint8Array(e) : (this.data_ = new Uint8Array(e.byteLength), this.data_.set(new Uint8Array(e))), s = this.data_.length) : e instanceof Uint8Array && (n ? this.data_ = e : (this.data_ = new Uint8Array(e.length), this.data_.set(e)), s = e.length), this.size_ = s, this.type_ = r;
709
+ }
710
+ size() {
711
+ return this.size_;
712
+ }
713
+ type() {
714
+ return this.type_;
715
+ }
716
+ slice(e, n) {
717
+ if (le(this.data_)) {
718
+ const s = this.data_, r = Et(s, e, n);
719
+ return r === null ? null : new C(r);
720
+ } else {
721
+ const s = new Uint8Array(this.data_.buffer, e, n - e);
722
+ return new C(s, !0);
723
+ }
724
+ }
725
+ static getBlob(...e) {
726
+ if (se()) {
727
+ const n = e.map((s) => s instanceof C ? s.data_ : s);
728
+ return new C(yt.apply(null, n));
729
+ } else {
730
+ const n = e.map((i) => W(i) ? Ue(A.RAW, i).data : i.data_);
731
+ let s = 0;
732
+ n.forEach((i) => {
733
+ s += i.byteLength;
734
+ });
735
+ const r = new Uint8Array(s);
736
+ let o = 0;
737
+ return n.forEach((i) => {
738
+ for (let u = 0; u < i.length; u++)
739
+ r[o++] = i[u];
740
+ }), new C(r, !0);
741
+ }
742
+ }
743
+ uploadData() {
744
+ return this.data_;
745
+ }
746
+ }
747
+ /**
748
+ * @license
749
+ * Copyright 2017 Google LLC
750
+ *
751
+ * Licensed under the Apache License, Version 2.0 (the "License");
752
+ * you may not use this file except in compliance with the License.
753
+ * You may obtain a copy of the License at
754
+ *
755
+ * http://www.apache.org/licenses/LICENSE-2.0
756
+ *
757
+ * Unless required by applicable law or agreed to in writing, software
758
+ * distributed under the License is distributed on an "AS IS" BASIS,
759
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
760
+ * See the License for the specific language governing permissions and
761
+ * limitations under the License.
762
+ */
763
+ function re(t) {
764
+ let e;
765
+ try {
766
+ e = JSON.parse(t);
767
+ } catch {
768
+ return null;
769
+ }
770
+ return pt(e) ? e : null;
771
+ }
772
+ /**
773
+ * @license
774
+ * Copyright 2017 Google LLC
775
+ *
776
+ * Licensed under the Apache License, Version 2.0 (the "License");
777
+ * you may not use this file except in compliance with the License.
778
+ * You may obtain a copy of the License at
779
+ *
780
+ * http://www.apache.org/licenses/LICENSE-2.0
781
+ *
782
+ * Unless required by applicable law or agreed to in writing, software
783
+ * distributed under the License is distributed on an "AS IS" BASIS,
784
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
785
+ * See the License for the specific language governing permissions and
786
+ * limitations under the License.
787
+ */
788
+ function Pt(t) {
789
+ if (t.length === 0)
790
+ return null;
791
+ const e = t.lastIndexOf("/");
792
+ return e === -1 ? "" : t.slice(0, e);
793
+ }
794
+ function Ct(t, e) {
795
+ const n = e.split("/").filter((s) => s.length > 0).join("/");
796
+ return t.length === 0 ? n : t + "/" + n;
797
+ }
798
+ function Se(t) {
799
+ const e = t.lastIndexOf("/", t.length - 2);
800
+ return e === -1 ? t : t.slice(e + 1);
801
+ }
802
+ /**
803
+ * @license
804
+ * Copyright 2017 Google LLC
805
+ *
806
+ * Licensed under the Apache License, Version 2.0 (the "License");
807
+ * you may not use this file except in compliance with the License.
808
+ * You may obtain a copy of the License at
809
+ *
810
+ * http://www.apache.org/licenses/LICENSE-2.0
811
+ *
812
+ * Unless required by applicable law or agreed to in writing, software
813
+ * distributed under the License is distributed on an "AS IS" BASIS,
814
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
815
+ * See the License for the specific language governing permissions and
816
+ * limitations under the License.
817
+ */
818
+ function xt(t, e) {
819
+ return e;
820
+ }
821
+ class T {
822
+ constructor(e, n, s, r) {
823
+ this.server = e, this.local = n || e, this.writable = !!s, this.xform = r || xt;
824
+ }
825
+ }
826
+ let X = null;
827
+ function Nt(t) {
828
+ return !W(t) || t.length < 2 ? t : Se(t);
829
+ }
830
+ function $() {
831
+ if (X)
832
+ return X;
833
+ const t = [];
834
+ t.push(new T("bucket")), t.push(new T("generation")), t.push(new T("metageneration")), t.push(new T("name", "fullPath", !0));
835
+ function e(o, i) {
836
+ return Nt(i);
837
+ }
838
+ const n = new T("name");
839
+ n.xform = e, t.push(n);
840
+ function s(o, i) {
841
+ return i !== void 0 ? Number(i) : i;
842
+ }
843
+ const r = new T("size");
844
+ return r.xform = s, t.push(r), t.push(new T("timeCreated")), t.push(new T("updated")), t.push(new T("md5Hash", null, !0)), t.push(new T("cacheControl", null, !0)), t.push(new T("contentDisposition", null, !0)), t.push(new T("contentEncoding", null, !0)), t.push(new T("contentLanguage", null, !0)), t.push(new T("contentType", null, !0)), t.push(new T("metadata", "customMetadata", !0)), X = t, X;
845
+ }
846
+ function vt(t, e) {
847
+ function n() {
848
+ const s = t.bucket, r = t.fullPath, o = new k(s, r);
849
+ return e._makeStorageReference(o);
850
+ }
851
+ Object.defineProperty(t, "ref", { get: n });
852
+ }
853
+ function Dt(t, e, n) {
854
+ const s = {};
855
+ s.type = "file";
856
+ const r = n.length;
857
+ for (let o = 0; o < r; o++) {
858
+ const i = n[o];
859
+ s[i.local] = i.xform(s, e[i.server]);
860
+ }
861
+ return vt(s, t), s;
862
+ }
863
+ function Pe(t, e, n) {
864
+ const s = re(e);
865
+ return s === null ? null : Dt(t, s, n);
866
+ }
867
+ function Lt(t, e, n, s) {
868
+ const r = re(e);
869
+ if (r === null || !W(r.downloadTokens))
870
+ return null;
871
+ const o = r.downloadTokens;
872
+ if (o.length === 0)
873
+ return null;
874
+ const i = encodeURIComponent;
875
+ return o.split(",").map((c) => {
876
+ const l = t.bucket, f = t.fullPath, p = "/b/" + i(l) + "/o/" + i(f), m = x(p, n, s), g = ye({
877
+ alt: "media",
878
+ token: c
879
+ });
880
+ return m + g;
881
+ })[0];
882
+ }
883
+ function oe(t, e) {
884
+ const n = {}, s = e.length;
885
+ for (let r = 0; r < s; r++) {
886
+ const o = e[r];
887
+ o.writable && (n[o.server] = t[o.local]);
888
+ }
889
+ return JSON.stringify(n);
890
+ }
891
+ /**
892
+ * @license
893
+ * Copyright 2019 Google LLC
894
+ *
895
+ * Licensed under the Apache License, Version 2.0 (the "License");
896
+ * you may not use this file except in compliance with the License.
897
+ * You may obtain a copy of the License at
898
+ *
899
+ * http://www.apache.org/licenses/LICENSE-2.0
900
+ *
901
+ * Unless required by applicable law or agreed to in writing, software
902
+ * distributed under the License is distributed on an "AS IS" BASIS,
903
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
904
+ * See the License for the specific language governing permissions and
905
+ * limitations under the License.
906
+ */
907
+ const he = "prefixes", de = "items";
908
+ function Bt(t, e, n) {
909
+ const s = {
910
+ prefixes: [],
911
+ items: [],
912
+ nextPageToken: n.nextPageToken
913
+ };
914
+ if (n[he])
915
+ for (const r of n[he]) {
916
+ const o = r.replace(/\/$/, ""), i = t._makeStorageReference(new k(e, o));
917
+ s.prefixes.push(i);
918
+ }
919
+ if (n[de])
920
+ for (const r of n[de]) {
921
+ const o = t._makeStorageReference(new k(e, r.name));
922
+ s.items.push(o);
923
+ }
924
+ return s;
925
+ }
926
+ function qt(t, e, n) {
927
+ const s = re(n);
928
+ return s === null ? null : Bt(t, e, s);
929
+ }
930
+ class I {
931
+ constructor(e, n, s, r) {
932
+ this.url = e, this.method = n, this.handler = s, this.timeout = r, this.urlParams = {}, this.headers = {}, this.body = null, this.errorHandler = null, this.progressCallback = null, this.successCodes = [200], this.additionalRetryCodes = [];
933
+ }
934
+ }
935
+ /**
936
+ * @license
937
+ * Copyright 2017 Google LLC
938
+ *
939
+ * Licensed under the Apache License, Version 2.0 (the "License");
940
+ * you may not use this file except in compliance with the License.
941
+ * You may obtain a copy of the License at
942
+ *
943
+ * http://www.apache.org/licenses/LICENSE-2.0
944
+ *
945
+ * Unless required by applicable law or agreed to in writing, software
946
+ * distributed under the License is distributed on an "AS IS" BASIS,
947
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
948
+ * See the License for the specific language governing permissions and
949
+ * limitations under the License.
950
+ */
951
+ function O(t) {
952
+ if (!t)
953
+ throw ne();
954
+ }
955
+ function V(t, e) {
956
+ function n(s, r) {
957
+ const o = Pe(t, r, e);
958
+ return O(o !== null), o;
959
+ }
960
+ return n;
961
+ }
962
+ function Mt(t, e) {
963
+ function n(s, r) {
964
+ const o = qt(t, e, r);
965
+ return O(o !== null), o;
966
+ }
967
+ return n;
968
+ }
969
+ function Ft(t, e) {
970
+ function n(s, r) {
971
+ const o = Pe(t, r, e);
972
+ return O(o !== null), Lt(o, r, t.host, t._protocol);
973
+ }
974
+ return n;
975
+ }
976
+ function q(t) {
977
+ function e(n, s) {
978
+ let r;
979
+ return n.getStatus() === 401 ? /* This exact message string is the only consistent part of the */ /* server's error response that identifies it as an App Check error. */ n.getErrorText().includes("Firebase App Check token is invalid") ? r = tt() : r = et() : n.getStatus() === 402 ? r = Qe(t.bucket) : n.getStatus() === 403 ? r = nt(t.path) : r = s, r.status = n.getStatus(), r.serverResponse = s.serverResponse, r;
980
+ }
981
+ return e;
982
+ }
983
+ function j(t) {
984
+ const e = q(t);
985
+ function n(s, r) {
986
+ let o = e(s, r);
987
+ return s.getStatus() === 404 && (o = Je(t.path)), o.serverResponse = r.serverResponse, o;
988
+ }
989
+ return n;
990
+ }
991
+ function Ce(t, e, n) {
992
+ const s = e.fullServerUrl(), r = x(s, t.host, t._protocol), o = "GET", i = t.maxOperationRetryTime, u = new I(r, o, V(t, n), i);
993
+ return u.errorHandler = j(e), u;
994
+ }
995
+ function Ht(t, e, n, s, r) {
996
+ const o = {};
997
+ e.isRoot ? o.prefix = "" : o.prefix = e.path + "/", n.length > 0 && (o.delimiter = n), s && (o.pageToken = s), r && (o.maxResults = r);
998
+ const i = e.bucketOnlyServerUrl(), u = x(i, t.host, t._protocol), a = "GET", c = t.maxOperationRetryTime, l = new I(u, a, Mt(t, e.bucket), c);
999
+ return l.urlParams = o, l.errorHandler = q(e), l;
1000
+ }
1001
+ function xe(t, e, n) {
1002
+ const s = e.fullServerUrl(), r = x(s, t.host, t._protocol) + "?alt=media", o = "GET", i = t.maxOperationRetryTime, u = new I(r, o, (a, c) => c, i);
1003
+ return u.errorHandler = j(e), n !== void 0 && (u.headers.Range = `bytes=0-${n}`, u.successCodes = [
1004
+ 200,
1005
+ 206
1006
+ /* Partial Content */
1007
+ ]), u;
1008
+ }
1009
+ function $t(t, e, n) {
1010
+ const s = e.fullServerUrl(), r = x(s, t.host, t._protocol), o = "GET", i = t.maxOperationRetryTime, u = new I(r, o, Ft(t, n), i);
1011
+ return u.errorHandler = j(e), u;
1012
+ }
1013
+ function jt(t, e, n, s) {
1014
+ const r = e.fullServerUrl(), o = x(r, t.host, t._protocol), i = "PATCH", u = oe(n, s), a = { "Content-Type": "application/json; charset=utf-8" }, c = t.maxOperationRetryTime, l = new I(o, i, V(t, s), c);
1015
+ return l.headers = a, l.body = u, l.errorHandler = j(e), l;
1016
+ }
1017
+ function zt(t, e) {
1018
+ const n = e.fullServerUrl(), s = x(n, t.host, t._protocol), r = "DELETE", o = t.maxOperationRetryTime;
1019
+ function i(a, c) {
1020
+ }
1021
+ const u = new I(s, r, i, o);
1022
+ return u.successCodes = [200, 204], u.errorHandler = j(e), u;
1023
+ }
1024
+ function Xt(t, e) {
1025
+ return t && t.contentType || e && e.type() || "application/octet-stream";
1026
+ }
1027
+ function Ne(t, e, n) {
1028
+ const s = Object.assign({}, n);
1029
+ return s.fullPath = t.path, s.size = e.size(), s.contentType || (s.contentType = Xt(null, e)), s;
1030
+ }
1031
+ function ve(t, e, n, s, r) {
1032
+ const o = e.bucketOnlyServerUrl(), i = {
1033
+ "X-Goog-Upload-Protocol": "multipart"
1034
+ };
1035
+ function u() {
1036
+ let R = "";
1037
+ for (let b = 0; b < 2; b++)
1038
+ R = R + Math.random().toString().slice(2);
1039
+ return R;
1040
+ }
1041
+ const a = u();
1042
+ i["Content-Type"] = "multipart/related; boundary=" + a;
1043
+ const c = Ne(e, s, r), l = oe(c, n), f = "--" + a + `\r
1044
+ Content-Type: application/json; charset=utf-8\r
1045
+ \r
1046
+ ` + l + `\r
1047
+ --` + a + `\r
1048
+ Content-Type: ` + c.contentType + `\r
1049
+ \r
1050
+ `, p = `\r
1051
+ --` + a + "--", m = C.getBlob(f, s, p);
1052
+ if (m === null)
1053
+ throw ke();
1054
+ const g = { name: c.fullPath }, E = x(o, t.host, t._protocol), _ = "POST", S = t.maxUploadRetryTime, P = new I(E, _, V(t, n), S);
1055
+ return P.urlParams = g, P.headers = i, P.body = m.uploadData(), P.errorHandler = q(e), P;
1056
+ }
1057
+ class G {
1058
+ constructor(e, n, s, r) {
1059
+ this.current = e, this.total = n, this.finalized = !!s, this.metadata = r || null;
1060
+ }
1061
+ }
1062
+ function ie(t, e) {
1063
+ let n = null;
1064
+ try {
1065
+ n = t.getResponseHeader("X-Goog-Upload-Status");
1066
+ } catch {
1067
+ O(!1);
1068
+ }
1069
+ return O(!!n && (e || ["active"]).indexOf(n) !== -1), n;
1070
+ }
1071
+ function Gt(t, e, n, s, r) {
1072
+ const o = e.bucketOnlyServerUrl(), i = Ne(e, s, r), u = { name: i.fullPath }, a = x(o, t.host, t._protocol), c = "POST", l = {
1073
+ "X-Goog-Upload-Protocol": "resumable",
1074
+ "X-Goog-Upload-Command": "start",
1075
+ "X-Goog-Upload-Header-Content-Length": `${s.size()}`,
1076
+ "X-Goog-Upload-Header-Content-Type": i.contentType,
1077
+ "Content-Type": "application/json; charset=utf-8"
1078
+ }, f = oe(i, n), p = t.maxUploadRetryTime;
1079
+ function m(E) {
1080
+ ie(E);
1081
+ let _;
1082
+ try {
1083
+ _ = E.getResponseHeader("X-Goog-Upload-URL");
1084
+ } catch {
1085
+ O(!1);
1086
+ }
1087
+ return O(W(_)), _;
1088
+ }
1089
+ const g = new I(a, c, m, p);
1090
+ return g.urlParams = u, g.headers = l, g.body = f, g.errorHandler = q(e), g;
1091
+ }
1092
+ function Wt(t, e, n, s) {
1093
+ const r = { "X-Goog-Upload-Command": "query" };
1094
+ function o(c) {
1095
+ const l = ie(c, ["active", "final"]);
1096
+ let f = null;
1097
+ try {
1098
+ f = c.getResponseHeader("X-Goog-Upload-Size-Received");
1099
+ } catch {
1100
+ O(!1);
1101
+ }
1102
+ f || O(!1);
1103
+ const p = Number(f);
1104
+ return O(!isNaN(p)), new G(p, s.size(), l === "final");
1105
+ }
1106
+ const i = "POST", u = t.maxUploadRetryTime, a = new I(n, i, o, u);
1107
+ return a.headers = r, a.errorHandler = q(e), a;
1108
+ }
1109
+ const fe = 256 * 1024;
1110
+ function Vt(t, e, n, s, r, o, i, u) {
1111
+ const a = new G(0, 0);
1112
+ if (i ? (a.current = i.current, a.total = i.total) : (a.current = 0, a.total = s.size()), s.size() !== a.total)
1113
+ throw it();
1114
+ const c = a.total - a.current;
1115
+ let l = c;
1116
+ r > 0 && (l = Math.min(l, r));
1117
+ const f = a.current, p = f + l;
1118
+ let m = "";
1119
+ l === 0 ? m = "finalize" : c === l ? m = "upload, finalize" : m = "upload";
1120
+ const g = {
1121
+ "X-Goog-Upload-Command": m,
1122
+ "X-Goog-Upload-Offset": `${a.current}`
1123
+ }, E = s.slice(f, p);
1124
+ if (E === null)
1125
+ throw ke();
1126
+ function _(b, D) {
1127
+ const L = ie(b, ["active", "final"]), K = a.current + l, M = s.size();
1128
+ let Y;
1129
+ return L === "final" ? Y = V(e, o)(b, D) : Y = null, new G(K, M, L === "final", Y);
1130
+ }
1131
+ const S = "POST", P = e.maxUploadRetryTime, R = new I(n, S, _, P);
1132
+ return R.headers = g, R.body = E.uploadData(), R.progressCallback = u || null, R.errorHandler = q(t), R;
1133
+ }
1134
+ /**
1135
+ * @license
1136
+ * Copyright 2017 Google LLC
1137
+ *
1138
+ * Licensed under the Apache License, Version 2.0 (the "License");
1139
+ * you may not use this file except in compliance with the License.
1140
+ * You may obtain a copy of the License at
1141
+ *
1142
+ * http://www.apache.org/licenses/LICENSE-2.0
1143
+ *
1144
+ * Unless required by applicable law or agreed to in writing, software
1145
+ * distributed under the License is distributed on an "AS IS" BASIS,
1146
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1147
+ * See the License for the specific language governing permissions and
1148
+ * limitations under the License.
1149
+ */
1150
+ const Tn = {
1151
+ /**
1152
+ * For this event,
1153
+ * <ul>
1154
+ * <li>The `next` function is triggered on progress updates and when the
1155
+ * task is paused/resumed with an `UploadTaskSnapshot` as the first
1156
+ * argument.</li>
1157
+ * <li>The `error` function is triggered if the upload is canceled or fails
1158
+ * for another reason.</li>
1159
+ * <li>The `complete` function is triggered if the upload completes
1160
+ * successfully.</li>
1161
+ * </ul>
1162
+ */
1163
+ STATE_CHANGED: "state_changed"
1164
+ }, w = {
1165
+ /** The task is currently transferring data. */
1166
+ RUNNING: "running",
1167
+ /** The task was paused by the user. */
1168
+ PAUSED: "paused",
1169
+ /** The task completed successfully. */
1170
+ SUCCESS: "success",
1171
+ /** The task was canceled. */
1172
+ CANCELED: "canceled",
1173
+ /** The task failed with an error. */
1174
+ ERROR: "error"
1175
+ };
1176
+ function Q(t) {
1177
+ switch (t) {
1178
+ case "running":
1179
+ case "pausing":
1180
+ case "canceling":
1181
+ return w.RUNNING;
1182
+ case "paused":
1183
+ return w.PAUSED;
1184
+ case "success":
1185
+ return w.SUCCESS;
1186
+ case "canceled":
1187
+ return w.CANCELED;
1188
+ case "error":
1189
+ return w.ERROR;
1190
+ default:
1191
+ return w.ERROR;
1192
+ }
1193
+ }
1194
+ /**
1195
+ * @license
1196
+ * Copyright 2017 Google LLC
1197
+ *
1198
+ * Licensed under the Apache License, Version 2.0 (the "License");
1199
+ * you may not use this file except in compliance with the License.
1200
+ * You may obtain a copy of the License at
1201
+ *
1202
+ * http://www.apache.org/licenses/LICENSE-2.0
1203
+ *
1204
+ * Unless required by applicable law or agreed to in writing, software
1205
+ * distributed under the License is distributed on an "AS IS" BASIS,
1206
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1207
+ * See the License for the specific language governing permissions and
1208
+ * limitations under the License.
1209
+ */
1210
+ class Kt {
1211
+ constructor(e, n, s) {
1212
+ if (_t(e) || n != null || s != null)
1213
+ this.next = e, this.error = n ?? void 0, this.complete = s ?? void 0;
1214
+ else {
1215
+ const o = e;
1216
+ this.next = o.next, this.error = o.error, this.complete = o.complete;
1217
+ }
1218
+ }
1219
+ }
1220
+ /**
1221
+ * @license
1222
+ * Copyright 2017 Google LLC
1223
+ *
1224
+ * Licensed under the Apache License, Version 2.0 (the "License");
1225
+ * you may not use this file except in compliance with the License.
1226
+ * You may obtain a copy of the License at
1227
+ *
1228
+ * http://www.apache.org/licenses/LICENSE-2.0
1229
+ *
1230
+ * Unless required by applicable law or agreed to in writing, software
1231
+ * distributed under the License is distributed on an "AS IS" BASIS,
1232
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1233
+ * See the License for the specific language governing permissions and
1234
+ * limitations under the License.
1235
+ */
1236
+ function B(t) {
1237
+ return (...e) => {
1238
+ Promise.resolve().then(() => t(...e));
1239
+ };
1240
+ }
1241
+ class ae {
1242
+ constructor() {
1243
+ this.sent_ = !1, this.xhr_ = new XMLHttpRequest(), this.initXhr(), this.errorCode_ = N.NO_ERROR, this.sendPromise_ = new Promise((e) => {
1244
+ this.xhr_.addEventListener("abort", () => {
1245
+ this.errorCode_ = N.ABORT, e();
1246
+ }), this.xhr_.addEventListener("error", () => {
1247
+ this.errorCode_ = N.NETWORK_ERROR, e();
1248
+ }), this.xhr_.addEventListener("load", () => {
1249
+ e();
1250
+ });
1251
+ });
1252
+ }
1253
+ send(e, n, s, r) {
1254
+ if (this.sent_)
1255
+ throw F("cannot .send() more than once");
1256
+ if (this.sent_ = !0, this.xhr_.open(n, e, !0), r !== void 0)
1257
+ for (const o in r)
1258
+ r.hasOwnProperty(o) && this.xhr_.setRequestHeader(o, r[o].toString());
1259
+ return s !== void 0 ? this.xhr_.send(s) : this.xhr_.send(), this.sendPromise_;
1260
+ }
1261
+ getErrorCode() {
1262
+ if (!this.sent_)
1263
+ throw F("cannot .getErrorCode() before sending");
1264
+ return this.errorCode_;
1265
+ }
1266
+ getStatus() {
1267
+ if (!this.sent_)
1268
+ throw F("cannot .getStatus() before sending");
1269
+ try {
1270
+ return this.xhr_.status;
1271
+ } catch {
1272
+ return -1;
1273
+ }
1274
+ }
1275
+ getResponse() {
1276
+ if (!this.sent_)
1277
+ throw F("cannot .getResponse() before sending");
1278
+ return this.xhr_.response;
1279
+ }
1280
+ getErrorText() {
1281
+ if (!this.sent_)
1282
+ throw F("cannot .getErrorText() before sending");
1283
+ return this.xhr_.statusText;
1284
+ }
1285
+ /** Aborts the request. */
1286
+ abort() {
1287
+ this.xhr_.abort();
1288
+ }
1289
+ getResponseHeader(e) {
1290
+ return this.xhr_.getResponseHeader(e);
1291
+ }
1292
+ addUploadProgressListener(e) {
1293
+ this.xhr_.upload != null && this.xhr_.upload.addEventListener("progress", e);
1294
+ }
1295
+ removeUploadProgressListener(e) {
1296
+ this.xhr_.upload != null && this.xhr_.upload.removeEventListener("progress", e);
1297
+ }
1298
+ }
1299
+ class Yt extends ae {
1300
+ initXhr() {
1301
+ this.xhr_.responseType = "text";
1302
+ }
1303
+ }
1304
+ function U() {
1305
+ return new Yt();
1306
+ }
1307
+ class Zt extends ae {
1308
+ initXhr() {
1309
+ this.xhr_.responseType = "arraybuffer";
1310
+ }
1311
+ }
1312
+ function Jt() {
1313
+ return new Zt();
1314
+ }
1315
+ class Qt extends ae {
1316
+ initXhr() {
1317
+ this.xhr_.responseType = "blob";
1318
+ }
1319
+ }
1320
+ function en() {
1321
+ return new Qt();
1322
+ }
1323
+ /**
1324
+ * @license
1325
+ * Copyright 2017 Google LLC
1326
+ *
1327
+ * Licensed under the Apache License, Version 2.0 (the "License");
1328
+ * you may not use this file except in compliance with the License.
1329
+ * You may obtain a copy of the License at
1330
+ *
1331
+ * http://www.apache.org/licenses/LICENSE-2.0
1332
+ *
1333
+ * Unless required by applicable law or agreed to in writing, software
1334
+ * distributed under the License is distributed on an "AS IS" BASIS,
1335
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1336
+ * See the License for the specific language governing permissions and
1337
+ * limitations under the License.
1338
+ */
1339
+ class tn {
1340
+ /**
1341
+ * @param ref - The firebaseStorage.Reference object this task came
1342
+ * from, untyped to avoid cyclic dependencies.
1343
+ * @param blob - The blob to upload.
1344
+ */
1345
+ constructor(e, n, s = null) {
1346
+ this._transferred = 0, this._needToFetchStatus = !1, this._needToFetchMetadata = !1, this._observers = [], this._error = void 0, this._uploadUrl = void 0, this._request = void 0, this._chunkMultiplier = 1, this._resolve = void 0, this._reject = void 0, this._ref = e, this._blob = n, this._metadata = s, this._mappings = $(), this._resumable = this._shouldDoResumable(this._blob), this._state = "running", this._errorHandler = (r) => {
1347
+ if (this._request = void 0, this._chunkMultiplier = 1, r._codeEquals(h.CANCELED))
1348
+ this._needToFetchStatus = !0, this.completeTransitions_();
1349
+ else {
1350
+ const o = this.isExponentialBackoffExpired();
1351
+ if (Ee(r.status, []))
1352
+ if (o)
1353
+ r = Re();
1354
+ else {
1355
+ this.sleepTime = Math.max(this.sleepTime * 2, Ze), this._needToFetchStatus = !0, this.completeTransitions_();
1356
+ return;
1357
+ }
1358
+ this._error = r, this._transition(
1359
+ "error"
1360
+ /* InternalTaskState.ERROR */
1361
+ );
1362
+ }
1363
+ }, this._metadataErrorHandler = (r) => {
1364
+ this._request = void 0, r._codeEquals(h.CANCELED) ? this.completeTransitions_() : (this._error = r, this._transition(
1365
+ "error"
1366
+ /* InternalTaskState.ERROR */
1367
+ ));
1368
+ }, this.sleepTime = 0, this.maxSleepTime = this._ref.storage.maxUploadRetryTime, this._promise = new Promise((r, o) => {
1369
+ this._resolve = r, this._reject = o, this._start();
1370
+ }), this._promise.then(null, () => {
1371
+ });
1372
+ }
1373
+ isExponentialBackoffExpired() {
1374
+ return this.sleepTime > this.maxSleepTime;
1375
+ }
1376
+ _makeProgressCallback() {
1377
+ const e = this._transferred;
1378
+ return (n) => this._updateProgress(e + n);
1379
+ }
1380
+ _shouldDoResumable(e) {
1381
+ return e.size() > 256 * 1024;
1382
+ }
1383
+ _start() {
1384
+ this._state === "running" && this._request === void 0 && (this._resumable ? this._uploadUrl === void 0 ? this._createResumable() : this._needToFetchStatus ? this._fetchStatus() : this._needToFetchMetadata ? this._fetchMetadata() : this.pendingTimeout = setTimeout(() => {
1385
+ this.pendingTimeout = void 0, this._continueUpload();
1386
+ }, this.sleepTime) : this._oneShotUpload());
1387
+ }
1388
+ _resolveToken(e) {
1389
+ Promise.all([
1390
+ this._ref.storage._getAuthToken(),
1391
+ this._ref.storage._getAppCheckToken()
1392
+ ]).then(([n, s]) => {
1393
+ switch (this._state) {
1394
+ case "running":
1395
+ e(n, s);
1396
+ break;
1397
+ case "canceling":
1398
+ this._transition(
1399
+ "canceled"
1400
+ /* InternalTaskState.CANCELED */
1401
+ );
1402
+ break;
1403
+ case "pausing":
1404
+ this._transition(
1405
+ "paused"
1406
+ /* InternalTaskState.PAUSED */
1407
+ );
1408
+ break;
1409
+ }
1410
+ });
1411
+ }
1412
+ // TODO(andysoto): assert false
1413
+ _createResumable() {
1414
+ this._resolveToken((e, n) => {
1415
+ const s = Gt(this._ref.storage, this._ref._location, this._mappings, this._blob, this._metadata), r = this._ref.storage._makeRequest(s, U, e, n);
1416
+ this._request = r, r.getPromise().then((o) => {
1417
+ this._request = void 0, this._uploadUrl = o, this._needToFetchStatus = !1, this.completeTransitions_();
1418
+ }, this._errorHandler);
1419
+ });
1420
+ }
1421
+ _fetchStatus() {
1422
+ const e = this._uploadUrl;
1423
+ this._resolveToken((n, s) => {
1424
+ const r = Wt(this._ref.storage, this._ref._location, e, this._blob), o = this._ref.storage._makeRequest(r, U, n, s);
1425
+ this._request = o, o.getPromise().then((i) => {
1426
+ i = i, this._request = void 0, this._updateProgress(i.current), this._needToFetchStatus = !1, i.finalized && (this._needToFetchMetadata = !0), this.completeTransitions_();
1427
+ }, this._errorHandler);
1428
+ });
1429
+ }
1430
+ _continueUpload() {
1431
+ const e = fe * this._chunkMultiplier, n = new G(this._transferred, this._blob.size()), s = this._uploadUrl;
1432
+ this._resolveToken((r, o) => {
1433
+ let i;
1434
+ try {
1435
+ i = Vt(this._ref._location, this._ref.storage, s, this._blob, e, this._mappings, n, this._makeProgressCallback());
1436
+ } catch (a) {
1437
+ this._error = a, this._transition(
1438
+ "error"
1439
+ /* InternalTaskState.ERROR */
1440
+ );
1441
+ return;
1442
+ }
1443
+ const u = this._ref.storage._makeRequest(
1444
+ i,
1445
+ U,
1446
+ r,
1447
+ o,
1448
+ /*retry=*/
1449
+ !1
1450
+ // Upload requests should not be retried as each retry should be preceded by another query request. Which is handled in this file.
1451
+ );
1452
+ this._request = u, u.getPromise().then((a) => {
1453
+ this._increaseMultiplier(), this._request = void 0, this._updateProgress(a.current), a.finalized ? (this._metadata = a.metadata, this._transition(
1454
+ "success"
1455
+ /* InternalTaskState.SUCCESS */
1456
+ )) : this.completeTransitions_();
1457
+ }, this._errorHandler);
1458
+ });
1459
+ }
1460
+ _increaseMultiplier() {
1461
+ fe * this._chunkMultiplier * 2 < 32 * 1024 * 1024 && (this._chunkMultiplier *= 2);
1462
+ }
1463
+ _fetchMetadata() {
1464
+ this._resolveToken((e, n) => {
1465
+ const s = Ce(this._ref.storage, this._ref._location, this._mappings), r = this._ref.storage._makeRequest(s, U, e, n);
1466
+ this._request = r, r.getPromise().then((o) => {
1467
+ this._request = void 0, this._metadata = o, this._transition(
1468
+ "success"
1469
+ /* InternalTaskState.SUCCESS */
1470
+ );
1471
+ }, this._metadataErrorHandler);
1472
+ });
1473
+ }
1474
+ _oneShotUpload() {
1475
+ this._resolveToken((e, n) => {
1476
+ const s = ve(this._ref.storage, this._ref._location, this._mappings, this._blob, this._metadata), r = this._ref.storage._makeRequest(s, U, e, n);
1477
+ this._request = r, r.getPromise().then((o) => {
1478
+ this._request = void 0, this._metadata = o, this._updateProgress(this._blob.size()), this._transition(
1479
+ "success"
1480
+ /* InternalTaskState.SUCCESS */
1481
+ );
1482
+ }, this._errorHandler);
1483
+ });
1484
+ }
1485
+ _updateProgress(e) {
1486
+ const n = this._transferred;
1487
+ this._transferred = e, this._transferred !== n && this._notifyObservers();
1488
+ }
1489
+ _transition(e) {
1490
+ if (this._state !== e)
1491
+ switch (e) {
1492
+ case "canceling":
1493
+ case "pausing":
1494
+ this._state = e, this._request !== void 0 ? this._request.cancel() : this.pendingTimeout && (clearTimeout(this.pendingTimeout), this.pendingTimeout = void 0, this.completeTransitions_());
1495
+ break;
1496
+ case "running":
1497
+ const n = this._state === "paused";
1498
+ this._state = e, n && (this._notifyObservers(), this._start());
1499
+ break;
1500
+ case "paused":
1501
+ this._state = e, this._notifyObservers();
1502
+ break;
1503
+ case "canceled":
1504
+ this._error = Te(), this._state = e, this._notifyObservers();
1505
+ break;
1506
+ case "error":
1507
+ this._state = e, this._notifyObservers();
1508
+ break;
1509
+ case "success":
1510
+ this._state = e, this._notifyObservers();
1511
+ break;
1512
+ }
1513
+ }
1514
+ completeTransitions_() {
1515
+ switch (this._state) {
1516
+ case "pausing":
1517
+ this._transition(
1518
+ "paused"
1519
+ /* InternalTaskState.PAUSED */
1520
+ );
1521
+ break;
1522
+ case "canceling":
1523
+ this._transition(
1524
+ "canceled"
1525
+ /* InternalTaskState.CANCELED */
1526
+ );
1527
+ break;
1528
+ case "running":
1529
+ this._start();
1530
+ break;
1531
+ }
1532
+ }
1533
+ /**
1534
+ * A snapshot of the current task state.
1535
+ */
1536
+ get snapshot() {
1537
+ const e = Q(this._state);
1538
+ return {
1539
+ bytesTransferred: this._transferred,
1540
+ totalBytes: this._blob.size(),
1541
+ state: e,
1542
+ metadata: this._metadata,
1543
+ task: this,
1544
+ ref: this._ref
1545
+ };
1546
+ }
1547
+ /**
1548
+ * Adds a callback for an event.
1549
+ * @param type - The type of event to listen for.
1550
+ * @param nextOrObserver -
1551
+ * The `next` function, which gets called for each item in
1552
+ * the event stream, or an observer object with some or all of these three
1553
+ * properties (`next`, `error`, `complete`).
1554
+ * @param error - A function that gets called with a `StorageError`
1555
+ * if the event stream ends due to an error.
1556
+ * @param completed - A function that gets called if the
1557
+ * event stream ends normally.
1558
+ * @returns
1559
+ * If only the event argument is passed, returns a function you can use to
1560
+ * add callbacks (see the examples above). If more than just the event
1561
+ * argument is passed, returns a function you can call to unregister the
1562
+ * callbacks.
1563
+ */
1564
+ on(e, n, s, r) {
1565
+ const o = new Kt(n || void 0, s || void 0, r || void 0);
1566
+ return this._addObserver(o), () => {
1567
+ this._removeObserver(o);
1568
+ };
1569
+ }
1570
+ /**
1571
+ * This object behaves like a Promise, and resolves with its snapshot data
1572
+ * when the upload completes.
1573
+ * @param onFulfilled - The fulfillment callback. Promise chaining works as normal.
1574
+ * @param onRejected - The rejection callback.
1575
+ */
1576
+ then(e, n) {
1577
+ return this._promise.then(e, n);
1578
+ }
1579
+ /**
1580
+ * Equivalent to calling `then(null, onRejected)`.
1581
+ */
1582
+ catch(e) {
1583
+ return this.then(null, e);
1584
+ }
1585
+ /**
1586
+ * Adds the given observer.
1587
+ */
1588
+ _addObserver(e) {
1589
+ this._observers.push(e), this._notifyObserver(e);
1590
+ }
1591
+ /**
1592
+ * Removes the given observer.
1593
+ */
1594
+ _removeObserver(e) {
1595
+ const n = this._observers.indexOf(e);
1596
+ n !== -1 && this._observers.splice(n, 1);
1597
+ }
1598
+ _notifyObservers() {
1599
+ this._finishPromise(), this._observers.slice().forEach((n) => {
1600
+ this._notifyObserver(n);
1601
+ });
1602
+ }
1603
+ _finishPromise() {
1604
+ if (this._resolve !== void 0) {
1605
+ let e = !0;
1606
+ switch (Q(this._state)) {
1607
+ case w.SUCCESS:
1608
+ B(this._resolve.bind(null, this.snapshot))();
1609
+ break;
1610
+ case w.CANCELED:
1611
+ case w.ERROR:
1612
+ const n = this._reject;
1613
+ B(n.bind(null, this._error))();
1614
+ break;
1615
+ default:
1616
+ e = !1;
1617
+ break;
1618
+ }
1619
+ e && (this._resolve = void 0, this._reject = void 0);
1620
+ }
1621
+ }
1622
+ _notifyObserver(e) {
1623
+ switch (Q(this._state)) {
1624
+ case w.RUNNING:
1625
+ case w.PAUSED:
1626
+ e.next && B(e.next.bind(e, this.snapshot))();
1627
+ break;
1628
+ case w.SUCCESS:
1629
+ e.complete && B(e.complete.bind(e))();
1630
+ break;
1631
+ case w.CANCELED:
1632
+ case w.ERROR:
1633
+ e.error && B(e.error.bind(e, this._error))();
1634
+ break;
1635
+ default:
1636
+ e.error && B(e.error.bind(e, this._error))();
1637
+ }
1638
+ }
1639
+ /**
1640
+ * Resumes a paused task. Has no effect on a currently running or failed task.
1641
+ * @returns True if the operation took effect, false if ignored.
1642
+ */
1643
+ resume() {
1644
+ const e = this._state === "paused" || this._state === "pausing";
1645
+ return e && this._transition(
1646
+ "running"
1647
+ /* InternalTaskState.RUNNING */
1648
+ ), e;
1649
+ }
1650
+ /**
1651
+ * Pauses a currently running task. Has no effect on a paused or failed task.
1652
+ * @returns True if the operation took effect, false if ignored.
1653
+ */
1654
+ pause() {
1655
+ const e = this._state === "running";
1656
+ return e && this._transition(
1657
+ "pausing"
1658
+ /* InternalTaskState.PAUSING */
1659
+ ), e;
1660
+ }
1661
+ /**
1662
+ * Cancels a currently running or paused task. Has no effect on a complete or
1663
+ * failed task.
1664
+ * @returns True if the operation took effect, false if ignored.
1665
+ */
1666
+ cancel() {
1667
+ const e = this._state === "running" || this._state === "pausing";
1668
+ return e && this._transition(
1669
+ "canceling"
1670
+ /* InternalTaskState.CANCELING */
1671
+ ), e;
1672
+ }
1673
+ }
1674
+ /**
1675
+ * @license
1676
+ * Copyright 2019 Google LLC
1677
+ *
1678
+ * Licensed under the Apache License, Version 2.0 (the "License");
1679
+ * you may not use this file except in compliance with the License.
1680
+ * You may obtain a copy of the License at
1681
+ *
1682
+ * http://www.apache.org/licenses/LICENSE-2.0
1683
+ *
1684
+ * Unless required by applicable law or agreed to in writing, software
1685
+ * distributed under the License is distributed on an "AS IS" BASIS,
1686
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1687
+ * See the License for the specific language governing permissions and
1688
+ * limitations under the License.
1689
+ */
1690
+ class v {
1691
+ constructor(e, n) {
1692
+ this._service = e, n instanceof k ? this._location = n : this._location = k.makeFromUrl(n, e.host);
1693
+ }
1694
+ /**
1695
+ * Returns the URL for the bucket and path this object references,
1696
+ * in the form gs://<bucket>/<object-path>
1697
+ * @override
1698
+ */
1699
+ toString() {
1700
+ return "gs://" + this._location.bucket + "/" + this._location.path;
1701
+ }
1702
+ _newRef(e, n) {
1703
+ return new v(e, n);
1704
+ }
1705
+ /**
1706
+ * A reference to the root of this object's bucket.
1707
+ */
1708
+ get root() {
1709
+ const e = new k(this._location.bucket, "");
1710
+ return this._newRef(this._service, e);
1711
+ }
1712
+ /**
1713
+ * The name of the bucket containing this reference's object.
1714
+ */
1715
+ get bucket() {
1716
+ return this._location.bucket;
1717
+ }
1718
+ /**
1719
+ * The full path of this object.
1720
+ */
1721
+ get fullPath() {
1722
+ return this._location.path;
1723
+ }
1724
+ /**
1725
+ * The short name of this object, which is the last component of the full path.
1726
+ * For example, if fullPath is 'full/path/image.png', name is 'image.png'.
1727
+ */
1728
+ get name() {
1729
+ return Se(this._location.path);
1730
+ }
1731
+ /**
1732
+ * The `StorageService` instance this `StorageReference` is associated with.
1733
+ */
1734
+ get storage() {
1735
+ return this._service;
1736
+ }
1737
+ /**
1738
+ * A `StorageReference` pointing to the parent location of this `StorageReference`, or null if
1739
+ * this reference is the root.
1740
+ */
1741
+ get parent() {
1742
+ const e = Pt(this._location.path);
1743
+ if (e === null)
1744
+ return null;
1745
+ const n = new k(this._location.bucket, e);
1746
+ return new v(this._service, n);
1747
+ }
1748
+ /**
1749
+ * Utility function to throw an error in methods that do not accept a root reference.
1750
+ */
1751
+ _throwIfRoot(e) {
1752
+ if (this._location.path === "")
1753
+ throw ct(e);
1754
+ }
1755
+ }
1756
+ function nn(t, e) {
1757
+ t._throwIfRoot("getBytes");
1758
+ const n = xe(t.storage, t._location, e);
1759
+ return t.storage.makeRequestWithTokens(n, Jt).then((s) => e !== void 0 ? (
1760
+ // GCS may not honor the Range header for small files
1761
+ s.slice(0, e)
1762
+ ) : s);
1763
+ }
1764
+ function sn(t, e) {
1765
+ t._throwIfRoot("getBlob");
1766
+ const n = xe(t.storage, t._location, e);
1767
+ return t.storage.makeRequestWithTokens(n, en).then((s) => e !== void 0 ? (
1768
+ // GCS may not honor the Range header for small files
1769
+ s.slice(0, e)
1770
+ ) : s);
1771
+ }
1772
+ function De(t, e, n) {
1773
+ t._throwIfRoot("uploadBytes");
1774
+ const s = ve(t.storage, t._location, $(), new C(e, !0), n);
1775
+ return t.storage.makeRequestWithTokens(s, U).then((r) => ({
1776
+ metadata: r,
1777
+ ref: t
1778
+ }));
1779
+ }
1780
+ function rn(t, e, n) {
1781
+ return t._throwIfRoot("uploadBytesResumable"), new tn(t, new C(e), n);
1782
+ }
1783
+ function on(t, e, n = A.RAW, s) {
1784
+ t._throwIfRoot("uploadString");
1785
+ const r = Ue(n, e), o = Object.assign({}, s);
1786
+ return o.contentType == null && r.contentType != null && (o.contentType = r.contentType), De(t, r.data, o);
1787
+ }
1788
+ function an(t) {
1789
+ const e = {
1790
+ prefixes: [],
1791
+ items: []
1792
+ };
1793
+ return Le(t, e).then(() => e);
1794
+ }
1795
+ async function Le(t, e, n) {
1796
+ const r = await Be(t, {
1797
+ // maxResults is 1000 by default.
1798
+ pageToken: n
1799
+ });
1800
+ e.prefixes.push(...r.prefixes), e.items.push(...r.items), r.nextPageToken != null && await Le(t, e, r.nextPageToken);
1801
+ }
1802
+ function Be(t, e) {
1803
+ e != null && typeof e.maxResults == "number" && te(
1804
+ "options.maxResults",
1805
+ /* minValue= */
1806
+ 1,
1807
+ /* maxValue= */
1808
+ 1e3,
1809
+ e.maxResults
1810
+ );
1811
+ const n = e || {}, s = Ht(
1812
+ t.storage,
1813
+ t._location,
1814
+ /*delimiter= */
1815
+ "/",
1816
+ n.pageToken,
1817
+ n.maxResults
1818
+ );
1819
+ return t.storage.makeRequestWithTokens(s, U);
1820
+ }
1821
+ function un(t) {
1822
+ t._throwIfRoot("getMetadata");
1823
+ const e = Ce(t.storage, t._location, $());
1824
+ return t.storage.makeRequestWithTokens(e, U);
1825
+ }
1826
+ function cn(t, e) {
1827
+ t._throwIfRoot("updateMetadata");
1828
+ const n = jt(t.storage, t._location, e, $());
1829
+ return t.storage.makeRequestWithTokens(n, U);
1830
+ }
1831
+ function ln(t) {
1832
+ t._throwIfRoot("getDownloadURL");
1833
+ const e = $t(t.storage, t._location, $());
1834
+ return t.storage.makeRequestWithTokens(e, U).then((n) => {
1835
+ if (n === null)
1836
+ throw at();
1837
+ return n;
1838
+ });
1839
+ }
1840
+ function hn(t) {
1841
+ t._throwIfRoot("deleteObject");
1842
+ const e = zt(t.storage, t._location);
1843
+ return t.storage.makeRequestWithTokens(e, U);
1844
+ }
1845
+ function qe(t, e) {
1846
+ const n = Ct(t._location.path, e), s = new k(t._location.bucket, n);
1847
+ return new v(t.storage, s);
1848
+ }
1849
+ /**
1850
+ * @license
1851
+ * Copyright 2017 Google LLC
1852
+ *
1853
+ * Licensed under the Apache License, Version 2.0 (the "License");
1854
+ * you may not use this file except in compliance with the License.
1855
+ * You may obtain a copy of the License at
1856
+ *
1857
+ * http://www.apache.org/licenses/LICENSE-2.0
1858
+ *
1859
+ * Unless required by applicable law or agreed to in writing, software
1860
+ * distributed under the License is distributed on an "AS IS" BASIS,
1861
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1862
+ * See the License for the specific language governing permissions and
1863
+ * limitations under the License.
1864
+ */
1865
+ function dn(t) {
1866
+ return /^[A-Za-z]+:\/\//.test(t);
1867
+ }
1868
+ function fn(t, e) {
1869
+ return new v(t, e);
1870
+ }
1871
+ function Me(t, e) {
1872
+ if (t instanceof ue) {
1873
+ const n = t;
1874
+ if (n._bucket == null)
1875
+ throw ot();
1876
+ const s = new v(n, n._bucket);
1877
+ return e != null ? Me(s, e) : s;
1878
+ } else
1879
+ return e !== void 0 ? qe(t, e) : t;
1880
+ }
1881
+ function _n(t, e) {
1882
+ if (e && dn(e)) {
1883
+ if (t instanceof ue)
1884
+ return fn(t, e);
1885
+ throw ee("To use ref(service, url), the first argument must be a Storage instance.");
1886
+ } else
1887
+ return Me(t, e);
1888
+ }
1889
+ function _e(t, e) {
1890
+ const n = e == null ? void 0 : e[be];
1891
+ return n == null ? null : k.makeFromBucketSpec(n, t);
1892
+ }
1893
+ function pn(t, e, n, s = {}) {
1894
+ t.host = `${e}:${n}`, t._protocol = "http";
1895
+ const { mockUserToken: r } = s;
1896
+ r && (t._overrideAuthToken = typeof r == "string" ? r : Xe(r, t.app.options.projectId));
1897
+ }
1898
+ class ue {
1899
+ constructor(e, n, s, r, o) {
1900
+ this.app = e, this._authProvider = n, this._appCheckProvider = s, this._url = r, this._firebaseVersion = o, this._bucket = null, this._host = ge, this._protocol = "https", this._appId = null, this._deleted = !1, this._maxOperationRetryTime = Ke, this._maxUploadRetryTime = Ye, this._requests = /* @__PURE__ */ new Set(), r != null ? this._bucket = k.makeFromBucketSpec(r, this._host) : this._bucket = _e(this._host, this.app.options);
1901
+ }
1902
+ /**
1903
+ * The host string for this service, in the form of `host` or
1904
+ * `host:port`.
1905
+ */
1906
+ get host() {
1907
+ return this._host;
1908
+ }
1909
+ set host(e) {
1910
+ this._host = e, this._url != null ? this._bucket = k.makeFromBucketSpec(this._url, e) : this._bucket = _e(e, this.app.options);
1911
+ }
1912
+ /**
1913
+ * The maximum time to retry uploads in milliseconds.
1914
+ */
1915
+ get maxUploadRetryTime() {
1916
+ return this._maxUploadRetryTime;
1917
+ }
1918
+ set maxUploadRetryTime(e) {
1919
+ te(
1920
+ "time",
1921
+ /* minValue=*/
1922
+ 0,
1923
+ /* maxValue= */
1924
+ Number.POSITIVE_INFINITY,
1925
+ e
1926
+ ), this._maxUploadRetryTime = e;
1927
+ }
1928
+ /**
1929
+ * The maximum time to retry operations other than uploads or downloads in
1930
+ * milliseconds.
1931
+ */
1932
+ get maxOperationRetryTime() {
1933
+ return this._maxOperationRetryTime;
1934
+ }
1935
+ set maxOperationRetryTime(e) {
1936
+ te(
1937
+ "time",
1938
+ /* minValue=*/
1939
+ 0,
1940
+ /* maxValue= */
1941
+ Number.POSITIVE_INFINITY,
1942
+ e
1943
+ ), this._maxOperationRetryTime = e;
1944
+ }
1945
+ async _getAuthToken() {
1946
+ if (this._overrideAuthToken)
1947
+ return this._overrideAuthToken;
1948
+ const e = this._authProvider.getImmediate({ optional: !0 });
1949
+ if (e) {
1950
+ const n = await e.getToken();
1951
+ if (n !== null)
1952
+ return n.accessToken;
1953
+ }
1954
+ return null;
1955
+ }
1956
+ async _getAppCheckToken() {
1957
+ const e = this._appCheckProvider.getImmediate({ optional: !0 });
1958
+ return e ? (await e.getToken()).token : null;
1959
+ }
1960
+ /**
1961
+ * Stop running requests and prevent more from being created.
1962
+ */
1963
+ _delete() {
1964
+ return this._deleted || (this._deleted = !0, this._requests.forEach((e) => e.cancel()), this._requests.clear()), Promise.resolve();
1965
+ }
1966
+ /**
1967
+ * Returns a new firebaseStorage.Reference object referencing this StorageService
1968
+ * at the given Location.
1969
+ */
1970
+ _makeStorageReference(e) {
1971
+ return new v(this, e);
1972
+ }
1973
+ /**
1974
+ * @param requestInfo - HTTP RequestInfo object
1975
+ * @param authToken - Firebase auth token
1976
+ */
1977
+ _makeRequest(e, n, s, r, o = !0) {
1978
+ if (this._deleted)
1979
+ return new lt(we());
1980
+ {
1981
+ const i = kt(e, this._appId, s, r, n, this._firebaseVersion, o);
1982
+ return this._requests.add(i), i.getPromise().then(() => this._requests.delete(i), () => this._requests.delete(i)), i;
1983
+ }
1984
+ }
1985
+ async makeRequestWithTokens(e, n) {
1986
+ const [s, r] = await Promise.all([
1987
+ this._getAuthToken(),
1988
+ this._getAppCheckToken()
1989
+ ]);
1990
+ return this._makeRequest(e, n, s, r).getPromise();
1991
+ }
1992
+ }
1993
+ const pe = "@firebase/storage", me = "0.13.2";
1994
+ /**
1995
+ * @license
1996
+ * Copyright 2020 Google LLC
1997
+ *
1998
+ * Licensed under the Apache License, Version 2.0 (the "License");
1999
+ * you may not use this file except in compliance with the License.
2000
+ * You may obtain a copy of the License at
2001
+ *
2002
+ * http://www.apache.org/licenses/LICENSE-2.0
2003
+ *
2004
+ * Unless required by applicable law or agreed to in writing, software
2005
+ * distributed under the License is distributed on an "AS IS" BASIS,
2006
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2007
+ * See the License for the specific language governing permissions and
2008
+ * limitations under the License.
2009
+ */
2010
+ const Fe = "storage";
2011
+ /**
2012
+ * @license
2013
+ * Copyright 2020 Google LLC
2014
+ *
2015
+ * Licensed under the Apache License, Version 2.0 (the "License");
2016
+ * you may not use this file except in compliance with the License.
2017
+ * You may obtain a copy of the License at
2018
+ *
2019
+ * http://www.apache.org/licenses/LICENSE-2.0
2020
+ *
2021
+ * Unless required by applicable law or agreed to in writing, software
2022
+ * distributed under the License is distributed on an "AS IS" BASIS,
2023
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2024
+ * See the License for the specific language governing permissions and
2025
+ * limitations under the License.
2026
+ */
2027
+ function kn(t, e) {
2028
+ return t = y(t), nn(t, e);
2029
+ }
2030
+ function wn(t, e, n) {
2031
+ return t = y(t), De(t, e, n);
2032
+ }
2033
+ function yn(t, e, n, s) {
2034
+ return t = y(t), on(t, e, n, s);
2035
+ }
2036
+ function En(t, e, n) {
2037
+ return t = y(t), rn(t, e, n);
2038
+ }
2039
+ function Un(t) {
2040
+ return t = y(t), un(t);
2041
+ }
2042
+ function An(t, e) {
2043
+ return t = y(t), cn(t, e);
2044
+ }
2045
+ function On(t, e) {
2046
+ return t = y(t), Be(t, e);
2047
+ }
2048
+ function In(t) {
2049
+ return t = y(t), an(t);
2050
+ }
2051
+ function Sn(t) {
2052
+ return t = y(t), ln(t);
2053
+ }
2054
+ function Pn(t) {
2055
+ return t = y(t), hn(t);
2056
+ }
2057
+ function Cn(t, e) {
2058
+ return t = y(t), _n(t, e);
2059
+ }
2060
+ function xn(t, e) {
2061
+ return qe(t, e);
2062
+ }
2063
+ function Nn(t = ze(), e) {
2064
+ t = y(t);
2065
+ const s = $e(t, Fe).getImmediate({
2066
+ identifier: e
2067
+ }), r = je("storage");
2068
+ return r && mn(s, ...r), s;
2069
+ }
2070
+ function mn(t, e, n, s = {}) {
2071
+ pn(t, e, n, s);
2072
+ }
2073
+ /**
2074
+ * @license
2075
+ * Copyright 2021 Google LLC
2076
+ *
2077
+ * Licensed under the Apache License, Version 2.0 (the "License");
2078
+ * you may not use this file except in compliance with the License.
2079
+ * You may obtain a copy of the License at
2080
+ *
2081
+ * http://www.apache.org/licenses/LICENSE-2.0
2082
+ *
2083
+ * Unless required by applicable law or agreed to in writing, software
2084
+ * distributed under the License is distributed on an "AS IS" BASIS,
2085
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2086
+ * See the License for the specific language governing permissions and
2087
+ * limitations under the License.
2088
+ */
2089
+ function vn(t, e) {
2090
+ return t = y(t), sn(t, e);
2091
+ }
2092
+ function Dn(t, e) {
2093
+ throw new Error("getStream() is only supported by NodeJS builds");
2094
+ }
2095
+ function gn(t, { instanceIdentifier: e }) {
2096
+ const n = t.getProvider("app").getImmediate(), s = t.getProvider("auth-internal"), r = t.getProvider("app-check-internal");
2097
+ return new ue(n, s, r, e, Ve);
2098
+ }
2099
+ function bn() {
2100
+ Ge(new We(
2101
+ Fe,
2102
+ gn,
2103
+ "PUBLIC"
2104
+ /* ComponentType.PUBLIC */
2105
+ ).setMultipleInstances(!0)), ce(pe, me, ""), ce(pe, me, "esm2017");
2106
+ }
2107
+ bn();
2108
+ export {
2109
+ d as StorageError,
2110
+ h as StorageErrorCode,
2111
+ A as StringFormat,
2112
+ C as _FbsBlob,
2113
+ k as _Location,
2114
+ Tn as _TaskEvent,
2115
+ w as _TaskState,
2116
+ tn as _UploadTask,
2117
+ Ue as _dataFromString,
2118
+ xn as _getChild,
2119
+ ee as _invalidArgument,
2120
+ ct as _invalidRootOperation,
2121
+ mn as connectStorageEmulator,
2122
+ Pn as deleteObject,
2123
+ vn as getBlob,
2124
+ kn as getBytes,
2125
+ Sn as getDownloadURL,
2126
+ Un as getMetadata,
2127
+ Nn as getStorage,
2128
+ Dn as getStream,
2129
+ On as list,
2130
+ In as listAll,
2131
+ Cn as ref,
2132
+ An as updateMetadata,
2133
+ wn as uploadBytes,
2134
+ En as uploadBytesResumable,
2135
+ yn as uploadString
2136
+ };