@firebase/storage 0.8.4-2021920175447 → 0.8.4-canary.dfed7f83f

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,8 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var app = require('@firebase/app');
6
6
  var util = require('@firebase/util');
7
- var component = require('@firebase/component');
8
7
  var nodeFetch = require('node-fetch');
8
+ var component = require('@firebase/component');
9
9
 
10
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
11
 
@@ -555,7 +555,7 @@ var ErrorCode;
555
555
  * limitations under the License.
556
556
  */
557
557
  class NetworkRequest {
558
- constructor(url_, method_, headers_, body_, successCodes_, additionalRetryCodes_, callback_, errorCallback_, timeout_, progressCallback_, pool_) {
558
+ constructor(url_, method_, headers_, body_, successCodes_, additionalRetryCodes_, callback_, errorCallback_, timeout_, progressCallback_, connectionFactory_) {
559
559
  this.url_ = url_;
560
560
  this.method_ = method_;
561
561
  this.headers_ = headers_;
@@ -566,7 +566,7 @@ class NetworkRequest {
566
566
  this.errorCallback_ = errorCallback_;
567
567
  this.timeout_ = timeout_;
568
568
  this.progressCallback_ = progressCallback_;
569
- this.pool_ = pool_;
569
+ this.connectionFactory_ = connectionFactory_;
570
570
  this.pendingConnection_ = null;
571
571
  this.backoffId_ = null;
572
572
  this.canceled_ = false;
@@ -586,7 +586,7 @@ class NetworkRequest {
586
586
  backoffCallback(false, new RequestEndStatus(false, null, true));
587
587
  return;
588
588
  }
589
- const connection = this.pool_.createConnection();
589
+ const connection = this.connectionFactory_();
590
590
  this.pendingConnection_ = connection;
591
591
  const progressListener = progressEvent => {
592
592
  const loaded = progressEvent.loaded;
@@ -732,7 +732,7 @@ function addAppCheckHeader_(headers, appCheckToken) {
732
732
  headers['X-Firebase-AppCheck'] = appCheckToken;
733
733
  }
734
734
  }
735
- function makeRequest(requestInfo, appId, authToken, appCheckToken, pool, firebaseVersion) {
735
+ function makeRequest(requestInfo, appId, authToken, appCheckToken, requestFactory, firebaseVersion) {
736
736
  const queryPart = makeQueryString(requestInfo.urlParams);
737
737
  const url = requestInfo.url + queryPart;
738
738
  const headers = Object.assign({}, requestInfo.headers);
@@ -740,7 +740,7 @@ function makeRequest(requestInfo, appId, authToken, appCheckToken, pool, firebas
740
740
  addAuthHeader_(headers, authToken);
741
741
  addVersionHeader_(headers, firebaseVersion);
742
742
  addAppCheckHeader_(headers, appCheckToken);
743
- return new NetworkRequest(url, requestInfo.method, headers, requestInfo.body, requestInfo.successCodes, requestInfo.additionalRetryCodes, requestInfo.handler, requestInfo.errorHandler, requestInfo.timeout, requestInfo.progressCallback, pool);
743
+ return new NetworkRequest(url, requestInfo.method, headers, requestInfo.body, requestInfo.successCodes, requestInfo.additionalRetryCodes, requestInfo.handler, requestInfo.errorHandler, requestInfo.timeout, requestInfo.progressCallback, requestFactory);
744
744
  }
745
745
 
746
746
  /**
@@ -1997,6 +1997,101 @@ function async(f) {
1997
1997
  };
1998
1998
  }
1999
1999
 
2000
+ /**
2001
+ * @license
2002
+ * Copyright 2021 Google LLC
2003
+ *
2004
+ * Licensed under the Apache License, Version 2.0 (the "License");
2005
+ * you may not use this file except in compliance with the License.
2006
+ * You may obtain a copy of the License at
2007
+ *
2008
+ * http://www.apache.org/licenses/LICENSE-2.0
2009
+ *
2010
+ * Unless required by applicable law or agreed to in writing, software
2011
+ * distributed under the License is distributed on an "AS IS" BASIS,
2012
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2013
+ * See the License for the specific language governing permissions and
2014
+ * limitations under the License.
2015
+ */
2016
+ /** An override for the text-based Connection. Used in tests. */
2017
+ let connectionFactoryOverride = null;
2018
+ /**
2019
+ * Network layer that works in Node.
2020
+ *
2021
+ * This network implementation should not be used in browsers as it does not
2022
+ * support progress updates.
2023
+ */
2024
+ class FetchConnection {
2025
+ constructor() {
2026
+ this.sent_ = false;
2027
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2028
+ this.fetch_ = nodeFetch__default["default"];
2029
+ this.errorCode_ = ErrorCode.NO_ERROR;
2030
+ }
2031
+ send(url, method, body, headers) {
2032
+ if (this.sent_) {
2033
+ throw internalError('cannot .send() more than once');
2034
+ }
2035
+ this.sent_ = true;
2036
+ return this.fetch_(url, {
2037
+ method,
2038
+ headers: headers || {},
2039
+ body
2040
+ }).then(resp => {
2041
+ this.headers_ = resp.headers;
2042
+ this.statusCode_ = resp.status;
2043
+ return resp.text().then(body => {
2044
+ this.body_ = body;
2045
+ });
2046
+ }, (_err) => {
2047
+ this.errorCode_ = ErrorCode.NETWORK_ERROR;
2048
+ // emulate XHR which sets status to 0 when encountering a network error
2049
+ this.statusCode_ = 0;
2050
+ });
2051
+ }
2052
+ getErrorCode() {
2053
+ if (this.errorCode_ === undefined) {
2054
+ throw internalError('cannot .getErrorCode() before receiving response');
2055
+ }
2056
+ return this.errorCode_;
2057
+ }
2058
+ getStatus() {
2059
+ if (this.statusCode_ === undefined) {
2060
+ throw internalError('cannot .getStatus() before receiving response');
2061
+ }
2062
+ return this.statusCode_;
2063
+ }
2064
+ getResponseText() {
2065
+ if (this.body_ === undefined) {
2066
+ throw internalError('cannot .getResponseText() before receiving response');
2067
+ }
2068
+ return this.body_;
2069
+ }
2070
+ abort() {
2071
+ // Not supported
2072
+ }
2073
+ getResponseHeader(header) {
2074
+ if (!this.headers_) {
2075
+ throw internalError('cannot .getResponseText() before receiving response');
2076
+ }
2077
+ return this.headers_.get(header);
2078
+ }
2079
+ addUploadProgressListener(listener) {
2080
+ // Not supported
2081
+ }
2082
+ /**
2083
+ * @override
2084
+ */
2085
+ removeUploadProgressListener(listener) {
2086
+ // Not supported
2087
+ }
2088
+ }
2089
+ function newConnection() {
2090
+ return connectionFactoryOverride
2091
+ ? connectionFactoryOverride()
2092
+ : new FetchConnection();
2093
+ }
2094
+
2000
2095
  /**
2001
2096
  * @license
2002
2097
  * Copyright 2017 Google LLC
@@ -2136,7 +2231,7 @@ class UploadTask {
2136
2231
  _createResumable() {
2137
2232
  this._resolveToken((authToken, appCheckToken) => {
2138
2233
  const requestInfo = createResumableUpload(this._ref.storage, this._ref._location, this._mappings, this._blob, this._metadata);
2139
- const createRequest = this._ref.storage._makeRequest(requestInfo, authToken, appCheckToken);
2234
+ const createRequest = this._ref.storage._makeRequest(requestInfo, newConnection, authToken, appCheckToken);
2140
2235
  this._request = createRequest;
2141
2236
  createRequest.getPromise().then((url) => {
2142
2237
  this._request = undefined;
@@ -2151,7 +2246,7 @@ class UploadTask {
2151
2246
  const url = this._uploadUrl;
2152
2247
  this._resolveToken((authToken, appCheckToken) => {
2153
2248
  const requestInfo = getResumableUploadStatus(this._ref.storage, this._ref._location, url, this._blob);
2154
- const statusRequest = this._ref.storage._makeRequest(requestInfo, authToken, appCheckToken);
2249
+ const statusRequest = this._ref.storage._makeRequest(requestInfo, newConnection, authToken, appCheckToken);
2155
2250
  this._request = statusRequest;
2156
2251
  statusRequest.getPromise().then(status => {
2157
2252
  status = status;
@@ -2180,7 +2275,7 @@ class UploadTask {
2180
2275
  this._transition("error" /* ERROR */);
2181
2276
  return;
2182
2277
  }
2183
- const uploadRequest = this._ref.storage._makeRequest(requestInfo, authToken, appCheckToken);
2278
+ const uploadRequest = this._ref.storage._makeRequest(requestInfo, newConnection, authToken, appCheckToken);
2184
2279
  this._request = uploadRequest;
2185
2280
  uploadRequest.getPromise().then((newStatus) => {
2186
2281
  this._increaseMultiplier();
@@ -2206,7 +2301,7 @@ class UploadTask {
2206
2301
  _fetchMetadata() {
2207
2302
  this._resolveToken((authToken, appCheckToken) => {
2208
2303
  const requestInfo = getMetadata$2(this._ref.storage, this._ref._location, this._mappings);
2209
- const metadataRequest = this._ref.storage._makeRequest(requestInfo, authToken, appCheckToken);
2304
+ const metadataRequest = this._ref.storage._makeRequest(requestInfo, newConnection, authToken, appCheckToken);
2210
2305
  this._request = metadataRequest;
2211
2306
  metadataRequest.getPromise().then(metadata => {
2212
2307
  this._request = undefined;
@@ -2218,7 +2313,7 @@ class UploadTask {
2218
2313
  _oneShotUpload() {
2219
2314
  this._resolveToken((authToken, appCheckToken) => {
2220
2315
  const requestInfo = multipartUpload(this._ref.storage, this._ref._location, this._mappings, this._blob, this._metadata);
2221
- const multipartRequest = this._ref.storage._makeRequest(requestInfo, authToken, appCheckToken);
2316
+ const multipartRequest = this._ref.storage._makeRequest(requestInfo, newConnection, authToken, appCheckToken);
2222
2317
  this._request = multipartRequest;
2223
2318
  multipartRequest.getPromise().then(metadata => {
2224
2319
  this._request = undefined;
@@ -2596,8 +2691,7 @@ function uploadBytes$1(ref, data, metadata) {
2596
2691
  ref._throwIfRoot('uploadBytes');
2597
2692
  const requestInfo = multipartUpload(ref.storage, ref._location, getMappings(), new FbsBlob(data, true), metadata);
2598
2693
  return ref.storage
2599
- .makeRequestWithTokens(requestInfo)
2600
- .then(request => request.getPromise())
2694
+ .makeRequestWithTokens(requestInfo, newConnection)
2601
2695
  .then(finalMetadata => {
2602
2696
  return {
2603
2697
  metadata: finalMetadata,
@@ -2703,7 +2797,7 @@ async function listAllHelper(ref, accumulator, pageToken) {
2703
2797
  * contains references to objects in this folder. `nextPageToken`
2704
2798
  * can be used to get the rest of the results.
2705
2799
  */
2706
- async function list$1(ref, options) {
2800
+ function list$1(ref, options) {
2707
2801
  if (options != null) {
2708
2802
  if (typeof options.maxResults === 'number') {
2709
2803
  validateNumber('options.maxResults',
@@ -2714,7 +2808,7 @@ async function list$1(ref, options) {
2714
2808
  const op = options || {};
2715
2809
  const requestInfo = list$2(ref.storage, ref._location,
2716
2810
  /*delimiter= */ '/', op.pageToken, op.maxResults);
2717
- return (await ref.storage.makeRequestWithTokens(requestInfo)).getPromise();
2811
+ return ref.storage.makeRequestWithTokens(requestInfo, newConnection);
2718
2812
  }
2719
2813
  /**
2720
2814
  * A `Promise` that resolves with the metadata for this object. If this
@@ -2723,10 +2817,10 @@ async function list$1(ref, options) {
2723
2817
  * @public
2724
2818
  * @param ref - StorageReference to get metadata from.
2725
2819
  */
2726
- async function getMetadata$1(ref) {
2820
+ function getMetadata$1(ref) {
2727
2821
  ref._throwIfRoot('getMetadata');
2728
2822
  const requestInfo = getMetadata$2(ref.storage, ref._location, getMappings());
2729
- return (await ref.storage.makeRequestWithTokens(requestInfo)).getPromise();
2823
+ return ref.storage.makeRequestWithTokens(requestInfo, newConnection);
2730
2824
  }
2731
2825
  /**
2732
2826
  * Updates the metadata for this object.
@@ -2739,10 +2833,10 @@ async function getMetadata$1(ref) {
2739
2833
  * with the new metadata for this object.
2740
2834
  * See `firebaseStorage.Reference.prototype.getMetadata`
2741
2835
  */
2742
- async function updateMetadata$1(ref, metadata) {
2836
+ function updateMetadata$1(ref, metadata) {
2743
2837
  ref._throwIfRoot('updateMetadata');
2744
2838
  const requestInfo = updateMetadata$2(ref.storage, ref._location, metadata, getMappings());
2745
- return (await ref.storage.makeRequestWithTokens(requestInfo)).getPromise();
2839
+ return ref.storage.makeRequestWithTokens(requestInfo, newConnection);
2746
2840
  }
2747
2841
  /**
2748
2842
  * Returns the download URL for the given Reference.
@@ -2750,11 +2844,11 @@ async function updateMetadata$1(ref, metadata) {
2750
2844
  * @returns A `Promise` that resolves with the download
2751
2845
  * URL for this object.
2752
2846
  */
2753
- async function getDownloadURL$1(ref) {
2847
+ function getDownloadURL$1(ref) {
2754
2848
  ref._throwIfRoot('getDownloadURL');
2755
2849
  const requestInfo = getDownloadUrl(ref.storage, ref._location, getMappings());
2756
- return (await ref.storage.makeRequestWithTokens(requestInfo))
2757
- .getPromise()
2850
+ return ref.storage
2851
+ .makeRequestWithTokens(requestInfo, newConnection)
2758
2852
  .then(url => {
2759
2853
  if (url === null) {
2760
2854
  throw noDownloadURL();
@@ -2768,10 +2862,10 @@ async function getDownloadURL$1(ref) {
2768
2862
  * @param ref - StorageReference for object to delete.
2769
2863
  * @returns A `Promise` that resolves if the deletion succeeds.
2770
2864
  */
2771
- async function deleteObject$1(ref) {
2865
+ function deleteObject$1(ref) {
2772
2866
  ref._throwIfRoot('deleteObject');
2773
2867
  const requestInfo = deleteObject$2(ref.storage, ref._location);
2774
- return (await ref.storage.makeRequestWithTokens(requestInfo)).getPromise();
2868
+ return ref.storage.makeRequestWithTokens(requestInfo, newConnection);
2775
2869
  }
2776
2870
  /**
2777
2871
  * Returns reference for object obtained by appending `childPath` to `ref`.
@@ -2892,11 +2986,10 @@ class FirebaseStorageImpl {
2892
2986
  /**
2893
2987
  * @internal
2894
2988
  */
2895
- _pool, _url, _firebaseVersion) {
2989
+ _url, _firebaseVersion) {
2896
2990
  this.app = app;
2897
2991
  this._authProvider = _authProvider;
2898
2992
  this._appCheckProvider = _appCheckProvider;
2899
- this._pool = _pool;
2900
2993
  this._url = _url;
2901
2994
  this._firebaseVersion = _firebaseVersion;
2902
2995
  this._bucket = null;
@@ -3007,9 +3100,9 @@ class FirebaseStorageImpl {
3007
3100
  * @param requestInfo - HTTP RequestInfo object
3008
3101
  * @param authToken - Firebase auth token
3009
3102
  */
3010
- _makeRequest(requestInfo, authToken, appCheckToken) {
3103
+ _makeRequest(requestInfo, requestFactory, authToken, appCheckToken) {
3011
3104
  if (!this._deleted) {
3012
- const request = makeRequest(requestInfo, this._appId, authToken, appCheckToken, this._pool, this._firebaseVersion);
3105
+ const request = makeRequest(requestInfo, this._appId, authToken, appCheckToken, requestFactory, this._firebaseVersion);
3013
3106
  this._requests.add(request);
3014
3107
  // Request removes itself from set when complete.
3015
3108
  request.getPromise().then(() => this._requests.delete(request), () => this._requests.delete(request));
@@ -3019,17 +3112,17 @@ class FirebaseStorageImpl {
3019
3112
  return new FailRequest(appDeleted());
3020
3113
  }
3021
3114
  }
3022
- async makeRequestWithTokens(requestInfo) {
3115
+ async makeRequestWithTokens(requestInfo, requestFactory) {
3023
3116
  const [authToken, appCheckToken] = await Promise.all([
3024
3117
  this._getAuthToken(),
3025
3118
  this._getAppCheckToken()
3026
3119
  ]);
3027
- return this._makeRequest(requestInfo, authToken, appCheckToken);
3120
+ return this._makeRequest(requestInfo, requestFactory, authToken, appCheckToken).getPromise();
3028
3121
  }
3029
3122
  }
3030
3123
 
3031
3124
  const name = "@firebase/storage";
3032
- const version = "0.8.4-2021920175447";
3125
+ const version = "0.8.4-canary.dfed7f83f";
3033
3126
 
3034
3127
  /**
3035
3128
  * @license
@@ -3052,122 +3145,6 @@ const version = "0.8.4-2021920175447";
3052
3145
  */
3053
3146
  const STORAGE_TYPE = 'storage';
3054
3147
 
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
-
3171
3148
  /**
3172
3149
  * @license
3173
3150
  * Copyright 2020 Google LLC
@@ -3367,7 +3344,7 @@ function factory(container, { instanceIdentifier: url }) {
3367
3344
  const app$1 = container.getProvider('app').getImmediate();
3368
3345
  const authProvider = container.getProvider('auth-internal');
3369
3346
  const appCheckProvider = container.getProvider('app-check-internal');
3370
- return new FirebaseStorageImpl(app$1, authProvider, appCheckProvider, new ConnectionPool(), url, app.SDK_VERSION);
3347
+ return new FirebaseStorageImpl(app$1, authProvider, appCheckProvider, url, app.SDK_VERSION);
3371
3348
  }
3372
3349
  function registerStorage() {
3373
3350
  app._registerComponent(new component.Component(STORAGE_TYPE, factory, "PUBLIC" /* PUBLIC */).setMultipleInstances(true));