@firebase/storage 0.13.7-canary.058afa280 → 0.13.7-canary.0e1276649

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.
@@ -1,5 +1,5 @@
1
1
  import { _isFirebaseServerApp, _getProvider, getApp, _registerComponent, registerVersion, SDK_VERSION } from '@firebase/app';
2
- import { FirebaseError, createMockUserToken, getModularInstance, getDefaultEmulatorHostnameAndPort } from '@firebase/util';
2
+ import { FirebaseError, isCloudWorkstation, createMockUserToken, getModularInstance, getDefaultEmulatorHostnameAndPort } from '@firebase/util';
3
3
  import { Component } from '@firebase/component';
4
4
 
5
5
  /**
@@ -657,7 +657,7 @@ function isRetryStatusCode(status, additionalRetryCodes) {
657
657
  * happens in the specified `callback_`.
658
658
  */
659
659
  class NetworkRequest {
660
- constructor(url_, method_, headers_, body_, successCodes_, additionalRetryCodes_, callback_, errorCallback_, timeout_, progressCallback_, connectionFactory_, retry = true) {
660
+ constructor(url_, method_, headers_, body_, successCodes_, additionalRetryCodes_, callback_, errorCallback_, timeout_, progressCallback_, connectionFactory_, retry = true, isUsingEmulator = false) {
661
661
  this.url_ = url_;
662
662
  this.method_ = method_;
663
663
  this.headers_ = headers_;
@@ -670,6 +670,7 @@ class NetworkRequest {
670
670
  this.progressCallback_ = progressCallback_;
671
671
  this.connectionFactory_ = connectionFactory_;
672
672
  this.retry = retry;
673
+ this.isUsingEmulator = isUsingEmulator;
673
674
  this.pendingConnection_ = null;
674
675
  this.backoffId_ = null;
675
676
  this.canceled_ = false;
@@ -704,7 +705,7 @@ class NetworkRequest {
704
705
  // connection.send() never rejects, so we don't need to have a error handler or use catch on the returned promise.
705
706
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
706
707
  connection
707
- .send(this.url_, this.method_, this.body_, this.headers_)
708
+ .send(this.url_, this.method_, this.isUsingEmulator, this.body_, this.headers_)
708
709
  .then(() => {
709
710
  if (this.progressCallback_ !== null) {
710
711
  connection.removeUploadProgressListener(progressListener);
@@ -821,7 +822,7 @@ function addAppCheckHeader_(headers, appCheckToken) {
821
822
  headers['X-Firebase-AppCheck'] = appCheckToken;
822
823
  }
823
824
  }
824
- function makeRequest(requestInfo, appId, authToken, appCheckToken, requestFactory, firebaseVersion, retry = true) {
825
+ function makeRequest(requestInfo, appId, authToken, appCheckToken, requestFactory, firebaseVersion, retry = true, isUsingEmulator = false) {
825
826
  const queryPart = makeQueryString(requestInfo.urlParams);
826
827
  const url = requestInfo.url + queryPart;
827
828
  const headers = Object.assign({}, requestInfo.headers);
@@ -829,7 +830,7 @@ function makeRequest(requestInfo, appId, authToken, appCheckToken, requestFactor
829
830
  addAuthHeader_(headers, authToken);
830
831
  addVersionHeader_(headers, firebaseVersion);
831
832
  addAppCheckHeader_(headers, appCheckToken);
832
- return new NetworkRequest(url, requestInfo.method, headers, requestInfo.body, requestInfo.successCodes, requestInfo.additionalRetryCodes, requestInfo.handler, requestInfo.errorHandler, requestInfo.timeout, requestInfo.progressCallback, requestFactory, retry);
833
+ return new NetworkRequest(url, requestInfo.method, headers, requestInfo.body, requestInfo.successCodes, requestInfo.additionalRetryCodes, requestInfo.handler, requestInfo.errorHandler, requestInfo.timeout, requestInfo.progressCallback, requestFactory, retry, isUsingEmulator);
833
834
  }
834
835
 
835
836
  /**
@@ -2158,10 +2159,13 @@ class XhrConnection {
2158
2159
  });
2159
2160
  });
2160
2161
  }
2161
- send(url, method, body, headers) {
2162
+ send(url, method, isUsingEmulator, body, headers) {
2162
2163
  if (this.sent_) {
2163
2164
  throw internalError('cannot .send() more than once');
2164
2165
  }
2166
+ if (isCloudWorkstation(url) && isUsingEmulator) {
2167
+ this.xhr_.withCredentials = true;
2168
+ }
2165
2169
  this.sent_ = true;
2166
2170
  this.xhr_.open(method, url, true);
2167
2171
  if (headers !== undefined) {
@@ -3166,7 +3170,9 @@ function extractBucket(host, config) {
3166
3170
  }
3167
3171
  function connectStorageEmulator$1(storage, host, port, options = {}) {
3168
3172
  storage.host = `${host}:${port}`;
3169
- storage._protocol = 'http';
3173
+ const useSsl = isCloudWorkstation(host);
3174
+ storage._isUsingEmulator = true;
3175
+ storage._protocol = useSsl ? 'https' : 'http';
3170
3176
  const { mockUserToken } = options;
3171
3177
  if (mockUserToken) {
3172
3178
  storage._overrideAuthToken =
@@ -3194,12 +3200,13 @@ class FirebaseStorageImpl {
3194
3200
  /**
3195
3201
  * @internal
3196
3202
  */
3197
- _url, _firebaseVersion) {
3203
+ _url, _firebaseVersion, _isUsingEmulator = false) {
3198
3204
  this.app = app;
3199
3205
  this._authProvider = _authProvider;
3200
3206
  this._appCheckProvider = _appCheckProvider;
3201
3207
  this._url = _url;
3202
3208
  this._firebaseVersion = _firebaseVersion;
3209
+ this._isUsingEmulator = _isUsingEmulator;
3203
3210
  this._bucket = null;
3204
3211
  /**
3205
3212
  * This string can be in the formats:
@@ -3313,7 +3320,7 @@ class FirebaseStorageImpl {
3313
3320
  */
3314
3321
  _makeRequest(requestInfo, requestFactory, authToken, appCheckToken, retry = true) {
3315
3322
  if (!this._deleted) {
3316
- const request = makeRequest(requestInfo, this._appId, authToken, appCheckToken, requestFactory, this._firebaseVersion, retry);
3323
+ const request = makeRequest(requestInfo, this._appId, authToken, appCheckToken, requestFactory, this._firebaseVersion, retry, this._isUsingEmulator);
3317
3324
  this._requests.add(request);
3318
3325
  // Request removes itself from set when complete.
3319
3326
  request.getPromise().then(() => this._requests.delete(request), () => this._requests.delete(request));
@@ -3333,7 +3340,7 @@ class FirebaseStorageImpl {
3333
3340
  }
3334
3341
 
3335
3342
  const name = "@firebase/storage";
3336
- const version = "0.13.7-canary.058afa280";
3343
+ const version = "0.13.7-canary.0e1276649";
3337
3344
 
3338
3345
  /**
3339
3346
  * @license