@firebase/storage 0.13.7 → 0.13.8-20250505162014

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, pingServer, 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,13 @@ 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
+ // Workaround to get cookies in Firebase Studio
3175
+ if (useSsl) {
3176
+ void pingServer(`https://${storage.host}`);
3177
+ }
3178
+ storage._isUsingEmulator = true;
3179
+ storage._protocol = useSsl ? 'https' : 'http';
3170
3180
  const { mockUserToken } = options;
3171
3181
  if (mockUserToken) {
3172
3182
  storage._overrideAuthToken =
@@ -3194,12 +3204,13 @@ class FirebaseStorageImpl {
3194
3204
  /**
3195
3205
  * @internal
3196
3206
  */
3197
- _url, _firebaseVersion) {
3207
+ _url, _firebaseVersion, _isUsingEmulator = false) {
3198
3208
  this.app = app;
3199
3209
  this._authProvider = _authProvider;
3200
3210
  this._appCheckProvider = _appCheckProvider;
3201
3211
  this._url = _url;
3202
3212
  this._firebaseVersion = _firebaseVersion;
3213
+ this._isUsingEmulator = _isUsingEmulator;
3203
3214
  this._bucket = null;
3204
3215
  /**
3205
3216
  * This string can be in the formats:
@@ -3313,7 +3324,7 @@ class FirebaseStorageImpl {
3313
3324
  */
3314
3325
  _makeRequest(requestInfo, requestFactory, authToken, appCheckToken, retry = true) {
3315
3326
  if (!this._deleted) {
3316
- const request = makeRequest(requestInfo, this._appId, authToken, appCheckToken, requestFactory, this._firebaseVersion, retry);
3327
+ const request = makeRequest(requestInfo, this._appId, authToken, appCheckToken, requestFactory, this._firebaseVersion, retry, this._isUsingEmulator);
3317
3328
  this._requests.add(request);
3318
3329
  // Request removes itself from set when complete.
3319
3330
  request.getPromise().then(() => this._requests.delete(request), () => this._requests.delete(request));
@@ -3333,7 +3344,7 @@ class FirebaseStorageImpl {
3333
3344
  }
3334
3345
 
3335
3346
  const name = "@firebase/storage";
3336
- const version = "0.13.7";
3347
+ const version = "0.13.8-20250505162014";
3337
3348
 
3338
3349
  /**
3339
3350
  * @license