@firebase/storage 0.13.6 → 0.13.7-auth-redirect-credentials.82faa0828

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.
@@ -658,7 +658,7 @@ function isRetryStatusCode(status, additionalRetryCodes) {
658
658
  * happens in the specified `callback_`.
659
659
  */
660
660
  class NetworkRequest {
661
- constructor(url_, method_, headers_, body_, successCodes_, additionalRetryCodes_, callback_, errorCallback_, timeout_, progressCallback_, connectionFactory_, retry = true) {
661
+ constructor(url_, method_, headers_, body_, successCodes_, additionalRetryCodes_, callback_, errorCallback_, timeout_, progressCallback_, connectionFactory_, retry = true, isUsingEmulator = false) {
662
662
  this.url_ = url_;
663
663
  this.method_ = method_;
664
664
  this.headers_ = headers_;
@@ -671,6 +671,7 @@ class NetworkRequest {
671
671
  this.progressCallback_ = progressCallback_;
672
672
  this.connectionFactory_ = connectionFactory_;
673
673
  this.retry = retry;
674
+ this.isUsingEmulator = isUsingEmulator;
674
675
  this.pendingConnection_ = null;
675
676
  this.backoffId_ = null;
676
677
  this.canceled_ = false;
@@ -705,7 +706,7 @@ class NetworkRequest {
705
706
  // connection.send() never rejects, so we don't need to have a error handler or use catch on the returned promise.
706
707
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
707
708
  connection
708
- .send(this.url_, this.method_, this.body_, this.headers_)
709
+ .send(this.url_, this.method_, this.body_, this.headers_, this.isUsingEmulator)
709
710
  .then(() => {
710
711
  if (this.progressCallback_ !== null) {
711
712
  connection.removeUploadProgressListener(progressListener);
@@ -822,7 +823,7 @@ function addAppCheckHeader_(headers, appCheckToken) {
822
823
  headers['X-Firebase-AppCheck'] = appCheckToken;
823
824
  }
824
825
  }
825
- function makeRequest(requestInfo, appId, authToken, appCheckToken, requestFactory, firebaseVersion, retry = true) {
826
+ function makeRequest(requestInfo, appId, authToken, appCheckToken, requestFactory, firebaseVersion, retry = true, isUsingEmulator = false) {
826
827
  const queryPart = makeQueryString(requestInfo.urlParams);
827
828
  const url = requestInfo.url + queryPart;
828
829
  const headers = Object.assign({}, requestInfo.headers);
@@ -830,7 +831,7 @@ function makeRequest(requestInfo, appId, authToken, appCheckToken, requestFactor
830
831
  addAuthHeader_(headers, authToken);
831
832
  addVersionHeader_(headers, firebaseVersion);
832
833
  addAppCheckHeader_(headers, appCheckToken);
833
- return new NetworkRequest(url, requestInfo.method, headers, requestInfo.body, requestInfo.successCodes, requestInfo.additionalRetryCodes, requestInfo.handler, requestInfo.errorHandler, requestInfo.timeout, requestInfo.progressCallback, requestFactory, retry);
834
+ return new NetworkRequest(url, requestInfo.method, headers, requestInfo.body, requestInfo.successCodes, requestInfo.additionalRetryCodes, requestInfo.handler, requestInfo.errorHandler, requestInfo.timeout, requestInfo.progressCallback, requestFactory, retry, isUsingEmulator);
834
835
  }
835
836
 
836
837
  /**
@@ -2149,17 +2150,13 @@ class FetchConnection {
2149
2150
  this.sent_ = false;
2150
2151
  this.errorCode_ = ErrorCode.NO_ERROR;
2151
2152
  }
2152
- async send(url, method, body, headers) {
2153
+ async send(url, method, body, headers, isUsingEmulator) {
2153
2154
  if (this.sent_) {
2154
2155
  throw internalError('cannot .send() more than once');
2155
2156
  }
2156
2157
  this.sent_ = true;
2157
2158
  try {
2158
- const response = await fetch(url, {
2159
- method,
2160
- headers: headers || {},
2161
- body: body
2162
- });
2159
+ const response = await newFetch(url, method, headers, body, isUsingEmulator);
2163
2160
  this.headers_ = response.headers;
2164
2161
  this.statusCode_ = response.status;
2165
2162
  this.errorCode_ = ErrorCode.NO_ERROR;
@@ -2238,11 +2235,7 @@ class FetchStreamConnection extends FetchConnection {
2238
2235
  }
2239
2236
  this.sent_ = true;
2240
2237
  try {
2241
- const response = await fetch(url, {
2242
- method,
2243
- headers: headers || {},
2244
- body: body
2245
- });
2238
+ const response = await newFetch(url, method, headers, body);
2246
2239
  this.headers_ = response.headers;
2247
2240
  this.statusCode_ = response.status;
2248
2241
  this.errorCode_ = ErrorCode.NO_ERROR;
@@ -2262,6 +2255,17 @@ class FetchStreamConnection extends FetchConnection {
2262
2255
  return this.stream_;
2263
2256
  }
2264
2257
  }
2258
+ function newFetch(url, method, headers, body, isUsingEmulator) {
2259
+ const fetchArgs = {
2260
+ method,
2261
+ headers: headers || {},
2262
+ body: body
2263
+ };
2264
+ if (util.isCloudWorkstation(url) && isUsingEmulator) {
2265
+ fetchArgs.credentials = 'include';
2266
+ }
2267
+ return fetch(url, fetchArgs);
2268
+ }
2265
2269
  function newStreamConnection() {
2266
2270
  return new FetchStreamConnection();
2267
2271
  }
@@ -3225,12 +3229,13 @@ class FirebaseStorageImpl {
3225
3229
  /**
3226
3230
  * @internal
3227
3231
  */
3228
- _url, _firebaseVersion) {
3232
+ _url, _firebaseVersion, _isUsingEmulator = false) {
3229
3233
  this.app = app;
3230
3234
  this._authProvider = _authProvider;
3231
3235
  this._appCheckProvider = _appCheckProvider;
3232
3236
  this._url = _url;
3233
3237
  this._firebaseVersion = _firebaseVersion;
3238
+ this._isUsingEmulator = _isUsingEmulator;
3234
3239
  this._bucket = null;
3235
3240
  /**
3236
3241
  * This string can be in the formats:
@@ -3344,7 +3349,7 @@ class FirebaseStorageImpl {
3344
3349
  */
3345
3350
  _makeRequest(requestInfo, requestFactory, authToken, appCheckToken, retry = true) {
3346
3351
  if (!this._deleted) {
3347
- const request = makeRequest(requestInfo, this._appId, authToken, appCheckToken, requestFactory, this._firebaseVersion, retry);
3352
+ const request = makeRequest(requestInfo, this._appId, authToken, appCheckToken, requestFactory, this._firebaseVersion, retry, this._isUsingEmulator);
3348
3353
  this._requests.add(request);
3349
3354
  // Request removes itself from set when complete.
3350
3355
  request.getPromise().then(() => this._requests.delete(request), () => this._requests.delete(request));
@@ -3364,7 +3369,7 @@ class FirebaseStorageImpl {
3364
3369
  }
3365
3370
 
3366
3371
  const name = "@firebase/storage";
3367
- const version = "0.13.6";
3372
+ const version = "0.13.7-auth-redirect-credentials.82faa0828";
3368
3373
 
3369
3374
  /**
3370
3375
  * @license