@firebase/storage 0.8.3 → 0.8.4-canary.1048c4f2d

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/dist/index.cjs.js CHANGED
@@ -4,39 +4,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var app = require('@firebase/app');
6
6
  var util = require('@firebase/util');
7
- var nodeFetch = require('node-fetch');
8
7
  var component = require('@firebase/component');
8
+ var nodeFetch = require('node-fetch');
9
9
 
10
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
11
 
12
12
  var nodeFetch__default = /*#__PURE__*/_interopDefaultLegacy(nodeFetch);
13
13
 
14
- /**
15
- * @license
16
- * Copyright 2017 Google LLC
17
- *
18
- * Licensed under the Apache License, Version 2.0 (the "License");
19
- * you may not use this file except in compliance with the License.
20
- * You may obtain a copy of the License at
21
- *
22
- * http://www.apache.org/licenses/LICENSE-2.0
23
- *
24
- * Unless required by applicable law or agreed to in writing, software
25
- * distributed under the License is distributed on an "AS IS" BASIS,
26
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27
- * See the License for the specific language governing permissions and
28
- * limitations under the License.
29
- */
30
- /**
31
- * Error codes for requests made by the the XhrIo wrapper.
32
- */
33
- var ErrorCode;
34
- (function (ErrorCode) {
35
- ErrorCode[ErrorCode["NO_ERROR"] = 0] = "NO_ERROR";
36
- ErrorCode[ErrorCode["NETWORK_ERROR"] = 1] = "NETWORK_ERROR";
37
- ErrorCode[ErrorCode["ABORT"] = 2] = "ABORT";
38
- })(ErrorCode || (ErrorCode = {}));
39
-
40
14
  /**
41
15
  * @license
42
16
  * Copyright 2017 Google LLC
@@ -209,120 +183,6 @@ function internalError(message) {
209
183
  throw new StorageError("internal-error" /* INTERNAL_ERROR */, 'Internal error: ' + message);
210
184
  }
211
185
 
212
- /**
213
- * @license
214
- * Copyright 2021 Google LLC
215
- *
216
- * Licensed under the Apache License, Version 2.0 (the "License");
217
- * you may not use this file except in compliance with the License.
218
- * You may obtain a copy of the License at
219
- *
220
- * http://www.apache.org/licenses/LICENSE-2.0
221
- *
222
- * Unless required by applicable law or agreed to in writing, software
223
- * distributed under the License is distributed on an "AS IS" BASIS,
224
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
225
- * See the License for the specific language governing permissions and
226
- * limitations under the License.
227
- */
228
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
229
- const fetch = nodeFetch__default['default'];
230
- /**
231
- * Network layer that works in Node.
232
- *
233
- * This network implementation should not be used in browsers as it does not
234
- * support progress updates.
235
- */
236
- class FetchConnection {
237
- constructor() {
238
- this.sent_ = false;
239
- this.errorCode_ = ErrorCode.NO_ERROR;
240
- }
241
- send(url, method, body, headers) {
242
- if (this.sent_) {
243
- throw internalError('cannot .send() more than once');
244
- }
245
- this.sent_ = true;
246
- return fetch(url, {
247
- method,
248
- headers: headers || {},
249
- body
250
- })
251
- .then(resp => {
252
- this.headers_ = resp.headers;
253
- this.statusCode_ = resp.status;
254
- return resp.text();
255
- })
256
- .then(body => {
257
- this.body_ = body;
258
- });
259
- }
260
- getErrorCode() {
261
- if (this.errorCode_ === undefined) {
262
- throw internalError('cannot .getErrorCode() before receiving response');
263
- }
264
- return this.errorCode_;
265
- }
266
- getStatus() {
267
- if (this.statusCode_ === undefined) {
268
- throw internalError('cannot .getStatus() before receiving response');
269
- }
270
- return this.statusCode_;
271
- }
272
- getResponseText() {
273
- if (this.body_ === undefined) {
274
- throw internalError('cannot .getResponseText() before receiving response');
275
- }
276
- return this.body_;
277
- }
278
- abort() {
279
- // Not supported
280
- }
281
- getResponseHeader(header) {
282
- if (!this.headers_) {
283
- throw internalError('cannot .getResponseText() before receiving response');
284
- }
285
- return this.headers_.get(header);
286
- }
287
- addUploadProgressListener(listener) {
288
- // Not supported
289
- }
290
- /**
291
- * @override
292
- */
293
- removeUploadProgressListener(listener) {
294
- // Not supported
295
- }
296
- }
297
- function newConnection() {
298
- return new FetchConnection();
299
- }
300
-
301
- /**
302
- * @license
303
- * Copyright 2017 Google LLC
304
- *
305
- * Licensed under the Apache License, Version 2.0 (the "License");
306
- * you may not use this file except in compliance with the License.
307
- * You may obtain a copy of the License at
308
- *
309
- * http://www.apache.org/licenses/LICENSE-2.0
310
- *
311
- * Unless required by applicable law or agreed to in writing, software
312
- * distributed under the License is distributed on an "AS IS" BASIS,
313
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
314
- * See the License for the specific language governing permissions and
315
- * limitations under the License.
316
- */
317
- /**
318
- * Factory-like class for creating XhrIo instances.
319
- */
320
- class ConnectionPool {
321
- createConnection() {
322
- return newConnection();
323
- }
324
- }
325
-
326
186
  /**
327
187
  * @license
328
188
  * Copyright 2017 Google LLC
@@ -652,6 +512,32 @@ function makeQueryString(params) {
652
512
  return queryPart;
653
513
  }
654
514
 
515
+ /**
516
+ * @license
517
+ * Copyright 2017 Google LLC
518
+ *
519
+ * Licensed under the Apache License, Version 2.0 (the "License");
520
+ * you may not use this file except in compliance with the License.
521
+ * You may obtain a copy of the License at
522
+ *
523
+ * http://www.apache.org/licenses/LICENSE-2.0
524
+ *
525
+ * Unless required by applicable law or agreed to in writing, software
526
+ * distributed under the License is distributed on an "AS IS" BASIS,
527
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
528
+ * See the License for the specific language governing permissions and
529
+ * limitations under the License.
530
+ */
531
+ /**
532
+ * Error codes for requests made by the the XhrIo wrapper.
533
+ */
534
+ var ErrorCode;
535
+ (function (ErrorCode) {
536
+ ErrorCode[ErrorCode["NO_ERROR"] = 0] = "NO_ERROR";
537
+ ErrorCode[ErrorCode["NETWORK_ERROR"] = 1] = "NETWORK_ERROR";
538
+ ErrorCode[ErrorCode["ABORT"] = 2] = "ABORT";
539
+ })(ErrorCode || (ErrorCode = {}));
540
+
655
541
  /**
656
542
  * @license
657
543
  * Copyright 2017 Google LLC
@@ -669,22 +555,22 @@ function makeQueryString(params) {
669
555
  * limitations under the License.
670
556
  */
671
557
  class NetworkRequest {
672
- constructor(url, method, headers, body, successCodes, additionalRetryCodes, callback, errorCallback, timeout, progressCallback, pool) {
558
+ constructor(url_, method_, headers_, body_, successCodes_, additionalRetryCodes_, callback_, errorCallback_, timeout_, progressCallback_, pool_) {
559
+ this.url_ = url_;
560
+ this.method_ = method_;
561
+ this.headers_ = headers_;
562
+ this.body_ = body_;
563
+ this.successCodes_ = successCodes_;
564
+ this.additionalRetryCodes_ = additionalRetryCodes_;
565
+ this.callback_ = callback_;
566
+ this.errorCallback_ = errorCallback_;
567
+ this.timeout_ = timeout_;
568
+ this.progressCallback_ = progressCallback_;
569
+ this.pool_ = pool_;
673
570
  this.pendingConnection_ = null;
674
571
  this.backoffId_ = null;
675
572
  this.canceled_ = false;
676
573
  this.appDelete_ = false;
677
- this.url_ = url;
678
- this.method_ = method;
679
- this.headers_ = headers;
680
- this.body_ = body;
681
- this.successCodes_ = successCodes.slice();
682
- this.additionalRetryCodes_ = additionalRetryCodes.slice();
683
- this.callback_ = callback;
684
- this.errorCallback_ = errorCallback;
685
- this.progressCallback_ = progressCallback;
686
- this.timeout_ = timeout;
687
- this.pool_ = pool;
688
574
  this.promise_ = new Promise((resolve, reject) => {
689
575
  this.resolve_ = resolve;
690
576
  this.reject_ = reject;
@@ -695,54 +581,56 @@ class NetworkRequest {
695
581
  * Actually starts the retry loop.
696
582
  */
697
583
  start_() {
698
- const self = this;
699
- function doTheRequest(backoffCallback, canceled) {
584
+ const doTheRequest = (backoffCallback, canceled) => {
700
585
  if (canceled) {
701
586
  backoffCallback(false, new RequestEndStatus(false, null, true));
702
587
  return;
703
588
  }
704
- const connection = self.pool_.createConnection();
705
- self.pendingConnection_ = connection;
706
- function progressListener(progressEvent) {
589
+ const connection = this.pool_.createConnection();
590
+ this.pendingConnection_ = connection;
591
+ const progressListener = progressEvent => {
707
592
  const loaded = progressEvent.loaded;
708
- const total = progressEvent.lengthComputable ? progressEvent.total : -1;
709
- if (self.progressCallback_ !== null) {
710
- self.progressCallback_(loaded, total);
593
+ const total = progressEvent.lengthComputable
594
+ ? progressEvent.total
595
+ : -1;
596
+ if (this.progressCallback_ !== null) {
597
+ this.progressCallback_(loaded, total);
711
598
  }
712
- }
713
- if (self.progressCallback_ !== null) {
599
+ };
600
+ if (this.progressCallback_ !== null) {
714
601
  connection.addUploadProgressListener(progressListener);
715
602
  }
603
+ // connection.send() never rejects, so we don't need to have a error handler or use catch on the returned promise.
716
604
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
717
605
  connection
718
- .send(self.url_, self.method_, self.body_, self.headers_)
606
+ .send(this.url_, this.method_, this.body_, this.headers_)
719
607
  .then(() => {
720
- if (self.progressCallback_ !== null) {
608
+ if (this.progressCallback_ !== null) {
721
609
  connection.removeUploadProgressListener(progressListener);
722
610
  }
723
- self.pendingConnection_ = null;
611
+ this.pendingConnection_ = null;
724
612
  const hitServer = connection.getErrorCode() === ErrorCode.NO_ERROR;
725
613
  const status = connection.getStatus();
726
- if (!hitServer || self.isRetryStatusCode_(status)) {
614
+ if (!hitServer || this.isRetryStatusCode_(status)) {
727
615
  const wasCanceled = connection.getErrorCode() === ErrorCode.ABORT;
728
616
  backoffCallback(false, new RequestEndStatus(false, null, wasCanceled));
729
617
  return;
730
618
  }
731
- const successCode = self.successCodes_.indexOf(status) !== -1;
619
+ const successCode = this.successCodes_.indexOf(status) !== -1;
732
620
  backoffCallback(true, new RequestEndStatus(successCode, connection));
733
621
  });
734
- }
622
+ };
735
623
  /**
736
624
  * @param requestWentThrough - True if the request eventually went
737
625
  * through, false if it hit the retry limit or was canceled.
738
626
  */
739
- function backoffDone(requestWentThrough, status) {
740
- const resolve = self.resolve_;
741
- const reject = self.reject_;
627
+ const backoffDone = (requestWentThrough, status) => {
628
+ const resolve = this.resolve_;
629
+ const reject = this.reject_;
742
630
  const connection = status.connection;
743
631
  if (status.wasSuccessCode) {
744
632
  try {
745
- const result = self.callback_(connection, connection.getResponseText());
633
+ const result = this.callback_(connection, connection.getResponseText());
746
634
  if (isJustDef(result)) {
747
635
  resolve(result);
748
636
  }
@@ -758,8 +646,8 @@ class NetworkRequest {
758
646
  if (connection !== null) {
759
647
  const err = unknown();
760
648
  err.serverResponse = connection.getResponseText();
761
- if (self.errorCallback_) {
762
- reject(self.errorCallback_(connection, err));
649
+ if (this.errorCallback_) {
650
+ reject(this.errorCallback_(connection, err));
763
651
  }
764
652
  else {
765
653
  reject(err);
@@ -767,7 +655,7 @@ class NetworkRequest {
767
655
  }
768
656
  else {
769
657
  if (status.canceled) {
770
- const err = self.appDelete_ ? appDeleted() : canceled();
658
+ const err = this.appDelete_ ? appDeleted() : canceled();
771
659
  reject(err);
772
660
  }
773
661
  else {
@@ -776,7 +664,7 @@ class NetworkRequest {
776
664
  }
777
665
  }
778
666
  }
779
- }
667
+ };
780
668
  if (this.canceled_) {
781
669
  backoffDone(false, new RequestEndStatus(false, null, true));
782
670
  }
@@ -3141,7 +3029,7 @@ class FirebaseStorageImpl {
3141
3029
  }
3142
3030
 
3143
3031
  const name = "@firebase/storage";
3144
- const version = "0.8.3";
3032
+ const version = "0.8.4-canary.1048c4f2d";
3145
3033
 
3146
3034
  /**
3147
3035
  * @license
@@ -3164,6 +3052,122 @@ const version = "0.8.3";
3164
3052
  */
3165
3053
  const STORAGE_TYPE = 'storage';
3166
3054
 
3055
+ /**
3056
+ * @license
3057
+ * Copyright 2021 Google LLC
3058
+ *
3059
+ * Licensed under the Apache License, Version 2.0 (the "License");
3060
+ * you may not use this file except in compliance with the License.
3061
+ * You may obtain a copy of the License at
3062
+ *
3063
+ * http://www.apache.org/licenses/LICENSE-2.0
3064
+ *
3065
+ * Unless required by applicable law or agreed to in writing, software
3066
+ * distributed under the License is distributed on an "AS IS" BASIS,
3067
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3068
+ * See the License for the specific language governing permissions and
3069
+ * limitations under the License.
3070
+ */
3071
+ /**
3072
+ * Network layer that works in Node.
3073
+ *
3074
+ * This network implementation should not be used in browsers as it does not
3075
+ * support progress updates.
3076
+ */
3077
+ class FetchConnection {
3078
+ constructor() {
3079
+ this.sent_ = false;
3080
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3081
+ this.fetch_ = nodeFetch__default["default"];
3082
+ this.errorCode_ = ErrorCode.NO_ERROR;
3083
+ }
3084
+ send(url, method, body, headers) {
3085
+ if (this.sent_) {
3086
+ throw internalError('cannot .send() more than once');
3087
+ }
3088
+ this.sent_ = true;
3089
+ return this.fetch_(url, {
3090
+ method,
3091
+ headers: headers || {},
3092
+ body
3093
+ }).then(resp => {
3094
+ this.headers_ = resp.headers;
3095
+ this.statusCode_ = resp.status;
3096
+ return resp.text().then(body => {
3097
+ this.body_ = body;
3098
+ });
3099
+ }, (_err) => {
3100
+ this.errorCode_ = ErrorCode.NETWORK_ERROR;
3101
+ // emulate XHR which sets status to 0 when encountering a network error
3102
+ this.statusCode_ = 0;
3103
+ });
3104
+ }
3105
+ getErrorCode() {
3106
+ if (this.errorCode_ === undefined) {
3107
+ throw internalError('cannot .getErrorCode() before receiving response');
3108
+ }
3109
+ return this.errorCode_;
3110
+ }
3111
+ getStatus() {
3112
+ if (this.statusCode_ === undefined) {
3113
+ throw internalError('cannot .getStatus() before receiving response');
3114
+ }
3115
+ return this.statusCode_;
3116
+ }
3117
+ getResponseText() {
3118
+ if (this.body_ === undefined) {
3119
+ throw internalError('cannot .getResponseText() before receiving response');
3120
+ }
3121
+ return this.body_;
3122
+ }
3123
+ abort() {
3124
+ // Not supported
3125
+ }
3126
+ getResponseHeader(header) {
3127
+ if (!this.headers_) {
3128
+ throw internalError('cannot .getResponseText() before receiving response');
3129
+ }
3130
+ return this.headers_.get(header);
3131
+ }
3132
+ addUploadProgressListener(listener) {
3133
+ // Not supported
3134
+ }
3135
+ /**
3136
+ * @override
3137
+ */
3138
+ removeUploadProgressListener(listener) {
3139
+ // Not supported
3140
+ }
3141
+ }
3142
+ function newConnection() {
3143
+ return new FetchConnection();
3144
+ }
3145
+
3146
+ /**
3147
+ * @license
3148
+ * Copyright 2017 Google LLC
3149
+ *
3150
+ * Licensed under the Apache License, Version 2.0 (the "License");
3151
+ * you may not use this file except in compliance with the License.
3152
+ * You may obtain a copy of the License at
3153
+ *
3154
+ * http://www.apache.org/licenses/LICENSE-2.0
3155
+ *
3156
+ * Unless required by applicable law or agreed to in writing, software
3157
+ * distributed under the License is distributed on an "AS IS" BASIS,
3158
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3159
+ * See the License for the specific language governing permissions and
3160
+ * limitations under the License.
3161
+ */
3162
+ /**
3163
+ * Factory-like class for creating XhrIo instances.
3164
+ */
3165
+ class ConnectionPool {
3166
+ createConnection() {
3167
+ return newConnection();
3168
+ }
3169
+ }
3170
+
3167
3171
  /**
3168
3172
  * @license
3169
3173
  * Copyright 2020 Google LLC