@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
  /**
@@ -654,7 +654,7 @@ function isRetryStatusCode(status, additionalRetryCodes) {
654
654
  * happens in the specified `callback_`.
655
655
  */
656
656
  class NetworkRequest {
657
- constructor(url_, method_, headers_, body_, successCodes_, additionalRetryCodes_, callback_, errorCallback_, timeout_, progressCallback_, connectionFactory_, retry = true) {
657
+ constructor(url_, method_, headers_, body_, successCodes_, additionalRetryCodes_, callback_, errorCallback_, timeout_, progressCallback_, connectionFactory_, retry = true, isUsingEmulator = false) {
658
658
  this.url_ = url_;
659
659
  this.method_ = method_;
660
660
  this.headers_ = headers_;
@@ -667,6 +667,7 @@ class NetworkRequest {
667
667
  this.progressCallback_ = progressCallback_;
668
668
  this.connectionFactory_ = connectionFactory_;
669
669
  this.retry = retry;
670
+ this.isUsingEmulator = isUsingEmulator;
670
671
  this.pendingConnection_ = null;
671
672
  this.backoffId_ = null;
672
673
  this.canceled_ = false;
@@ -701,7 +702,7 @@ class NetworkRequest {
701
702
  // connection.send() never rejects, so we don't need to have a error handler or use catch on the returned promise.
702
703
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
703
704
  connection
704
- .send(this.url_, this.method_, this.body_, this.headers_)
705
+ .send(this.url_, this.method_, this.isUsingEmulator, this.body_, this.headers_)
705
706
  .then(() => {
706
707
  if (this.progressCallback_ !== null) {
707
708
  connection.removeUploadProgressListener(progressListener);
@@ -818,7 +819,7 @@ function addAppCheckHeader_(headers, appCheckToken) {
818
819
  headers['X-Firebase-AppCheck'] = appCheckToken;
819
820
  }
820
821
  }
821
- function makeRequest(requestInfo, appId, authToken, appCheckToken, requestFactory, firebaseVersion, retry = true) {
822
+ function makeRequest(requestInfo, appId, authToken, appCheckToken, requestFactory, firebaseVersion, retry = true, isUsingEmulator = false) {
822
823
  const queryPart = makeQueryString(requestInfo.urlParams);
823
824
  const url = requestInfo.url + queryPart;
824
825
  const headers = Object.assign({}, requestInfo.headers);
@@ -826,7 +827,7 @@ function makeRequest(requestInfo, appId, authToken, appCheckToken, requestFactor
826
827
  addAuthHeader_(headers, authToken);
827
828
  addVersionHeader_(headers, firebaseVersion);
828
829
  addAppCheckHeader_(headers, appCheckToken);
829
- return new NetworkRequest(url, requestInfo.method, headers, requestInfo.body, requestInfo.successCodes, requestInfo.additionalRetryCodes, requestInfo.handler, requestInfo.errorHandler, requestInfo.timeout, requestInfo.progressCallback, requestFactory, retry);
830
+ return new NetworkRequest(url, requestInfo.method, headers, requestInfo.body, requestInfo.successCodes, requestInfo.additionalRetryCodes, requestInfo.handler, requestInfo.errorHandler, requestInfo.timeout, requestInfo.progressCallback, requestFactory, retry, isUsingEmulator);
830
831
  }
831
832
 
832
833
  /**
@@ -2145,17 +2146,13 @@ class FetchConnection {
2145
2146
  this.sent_ = false;
2146
2147
  this.errorCode_ = ErrorCode.NO_ERROR;
2147
2148
  }
2148
- async send(url, method, body, headers) {
2149
+ async send(url, method, isUsingEmulator, body, headers) {
2149
2150
  if (this.sent_) {
2150
2151
  throw internalError('cannot .send() more than once');
2151
2152
  }
2152
2153
  this.sent_ = true;
2153
2154
  try {
2154
- const response = await fetch(url, {
2155
- method,
2156
- headers: headers || {},
2157
- body: body
2158
- });
2155
+ const response = await newFetch(url, method, isUsingEmulator, headers, body);
2159
2156
  this.headers_ = response.headers;
2160
2157
  this.statusCode_ = response.status;
2161
2158
  this.errorCode_ = ErrorCode.NO_ERROR;
@@ -2228,17 +2225,13 @@ class FetchStreamConnection extends FetchConnection {
2228
2225
  super(...arguments);
2229
2226
  this.stream_ = null;
2230
2227
  }
2231
- async send(url, method, body, headers) {
2228
+ async send(url, method, isUsingEmulator, body, headers) {
2232
2229
  if (this.sent_) {
2233
2230
  throw internalError('cannot .send() more than once');
2234
2231
  }
2235
2232
  this.sent_ = true;
2236
2233
  try {
2237
- const response = await fetch(url, {
2238
- method,
2239
- headers: headers || {},
2240
- body: body
2241
- });
2234
+ const response = await newFetch(url, method, isUsingEmulator, headers, body);
2242
2235
  this.headers_ = response.headers;
2243
2236
  this.statusCode_ = response.status;
2244
2237
  this.errorCode_ = ErrorCode.NO_ERROR;
@@ -2258,6 +2251,17 @@ class FetchStreamConnection extends FetchConnection {
2258
2251
  return this.stream_;
2259
2252
  }
2260
2253
  }
2254
+ function newFetch(url, method, isUsingEmulator, headers, body) {
2255
+ const fetchArgs = {
2256
+ method,
2257
+ headers: headers || {},
2258
+ body: body
2259
+ };
2260
+ if (isCloudWorkstation(url) && isUsingEmulator) {
2261
+ fetchArgs.credentials = 'include';
2262
+ }
2263
+ return fetch(url, fetchArgs);
2264
+ }
2261
2265
  function newStreamConnection() {
2262
2266
  return new FetchStreamConnection();
2263
2267
  }
@@ -3193,7 +3197,13 @@ function extractBucket(host, config) {
3193
3197
  }
3194
3198
  function connectStorageEmulator$1(storage, host, port, options = {}) {
3195
3199
  storage.host = `${host}:${port}`;
3196
- storage._protocol = 'http';
3200
+ const useSsl = isCloudWorkstation(host);
3201
+ // Workaround to get cookies in Firebase Studio
3202
+ if (useSsl) {
3203
+ void pingServer(`https://${storage.host}`);
3204
+ }
3205
+ storage._isUsingEmulator = true;
3206
+ storage._protocol = useSsl ? 'https' : 'http';
3197
3207
  const { mockUserToken } = options;
3198
3208
  if (mockUserToken) {
3199
3209
  storage._overrideAuthToken =
@@ -3221,12 +3231,13 @@ class FirebaseStorageImpl {
3221
3231
  /**
3222
3232
  * @internal
3223
3233
  */
3224
- _url, _firebaseVersion) {
3234
+ _url, _firebaseVersion, _isUsingEmulator = false) {
3225
3235
  this.app = app;
3226
3236
  this._authProvider = _authProvider;
3227
3237
  this._appCheckProvider = _appCheckProvider;
3228
3238
  this._url = _url;
3229
3239
  this._firebaseVersion = _firebaseVersion;
3240
+ this._isUsingEmulator = _isUsingEmulator;
3230
3241
  this._bucket = null;
3231
3242
  /**
3232
3243
  * This string can be in the formats:
@@ -3340,7 +3351,7 @@ class FirebaseStorageImpl {
3340
3351
  */
3341
3352
  _makeRequest(requestInfo, requestFactory, authToken, appCheckToken, retry = true) {
3342
3353
  if (!this._deleted) {
3343
- const request = makeRequest(requestInfo, this._appId, authToken, appCheckToken, requestFactory, this._firebaseVersion, retry);
3354
+ const request = makeRequest(requestInfo, this._appId, authToken, appCheckToken, requestFactory, this._firebaseVersion, retry, this._isUsingEmulator);
3344
3355
  this._requests.add(request);
3345
3356
  // Request removes itself from set when complete.
3346
3357
  request.getPromise().then(() => this._requests.delete(request), () => this._requests.delete(request));
@@ -3360,7 +3371,7 @@ class FirebaseStorageImpl {
3360
3371
  }
3361
3372
 
3362
3373
  const name = "@firebase/storage";
3363
- const version = "0.13.7";
3374
+ const version = "0.13.8-20250505162014";
3364
3375
 
3365
3376
  /**
3366
3377
  * @license