UNPKG

firebase

Version:

Firebase JavaScript library for web and Node.js

3 lines (2 loc) • 32.5 kB
import{getApp as e,_getProvider as t,_registerComponent as n,registerVersion as r,SDK_VERSION as s}from"https://www.gstatic.com/firebasejs/9.0.0-beta.7/firebase-app.js";var o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};var i=function(e){function t(n,r,s){var o=e.call(this,r)||this;return o.code=n,o.customData=s,o.name="FirebaseError",Object.setPrototypeOf(o,t.prototype),Error.captureStackTrace&&Error.captureStackTrace(o,a.prototype.create),o}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,e),t}(Error),a=function(){function e(e,t,n){this.service=e,this.serviceName=t,this.errors=n}return e.prototype.create=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var r=t[0]||{},s=this.service+"/"+e,o=this.errors[e],a=o?c(o,r):"Error",u=this.serviceName+": "+a+" ("+s+").",l=new i(s,u,r);return l},e}();function c(e,t){return e.replace(u,(function(e,n){var r=t[n];return null!=r?String(r):"<"+n+"?>"}))}var u=/\{\$([^}]+)}/g;function l(e){return e&&e._delegate?e._delegate:e}var h,d=function(){function e(e,t,n){this.name=e,this.instanceFactory=t,this.type=n,this.multipleInstances=!1,this.serviceProps={},this.instantiationMode="LAZY",this.onInstanceCreated=null}return e.prototype.setInstantiationMode=function(e){return this.instantiationMode=e,this},e.prototype.setMultipleInstances=function(e){return this.multipleInstances=e,this},e.prototype.setServiceProps=function(e){return this.serviceProps=e,this},e.prototype.setInstanceCreatedCallback=function(e){return this.onInstanceCreated=e,this},e}();!function(e){e[e.NO_ERROR=0]="NO_ERROR",e[e.NETWORK_ERROR=1]="NETWORK_ERROR",e[e.ABORT=2]="ABORT"}(h||(h={}));class p extends i{constructor(e,t){super(_(e),`Firebase Storage: ${t} (${_(e)})`),this.customData={serverResponse:null},this._baseMessage=this.message,Object.setPrototypeOf(this,p.prototype)}_codeEquals(e){return _(e)===this.code}get serverResponse(){return this.customData.serverResponse}set serverResponse(e){this.customData.serverResponse=e,this.customData.serverResponse?this.message=`${this._baseMessage}\n${this.customData.serverResponse}`:this.message=this._baseMessage}}function _(e){return"storage/"+e}function f(){return new p("unknown","An unknown error occurred, please check the error payload for server response.")}function g(){return new p("canceled","User canceled the upload/download.")}function m(){return new p("cannot-slice-blob","Cannot slice blob for upload. Please retry the upload.")}function b(e){return new p("invalid-argument",e)}function w(){return new p("app-deleted","The Firebase app was deleted.")}function v(e,t){return new p("invalid-format","String does not match format '"+e+"': "+t)}function y(e){throw new p("internal-error","Internal error: "+e)}class k{constructor(){this.sent_=!1,this.xhr_=new XMLHttpRequest,this.errorCode_=h.NO_ERROR,this.sendPromise_=new Promise((e=>{this.xhr_.addEventListener("abort",(()=>{this.errorCode_=h.ABORT,e()})),this.xhr_.addEventListener("error",(()=>{this.errorCode_=h.NETWORK_ERROR,e()})),this.xhr_.addEventListener("load",(()=>{e()}))}))}send(e,t,n,r){if(this.sent_)throw y("cannot .send() more than once");if(this.sent_=!0,this.xhr_.open(t,e,!0),void 0!==r)for(const e in r)r.hasOwnProperty(e)&&this.xhr_.setRequestHeader(e,r[e].toString());return void 0!==n?this.xhr_.send(n):this.xhr_.send(),this.sendPromise_}getErrorCode(){if(!this.sent_)throw y("cannot .getErrorCode() before sending");return this.errorCode_}getStatus(){if(!this.sent_)throw y("cannot .getStatus() before sending");try{return this.xhr_.status}catch(e){return-1}}getResponseText(){if(!this.sent_)throw y("cannot .getResponseText() before sending");return this.xhr_.responseText}abort(){this.xhr_.abort()}getResponseHeader(e){return this.xhr_.getResponseHeader(e)}addUploadProgressListener(e){null!=this.xhr_.upload&&this.xhr_.upload.addEventListener("progress",e)}removeUploadProgressListener(e){null!=this.xhr_.upload&&this.xhr_.upload.removeEventListener("progress",e)}}class R{createConnection(){return new k}}class T{constructor(e,t){this.bucket=e,this.path_=t}get path(){return this.path_}get isRoot(){return 0===this.path.length}fullServerUrl(){const e=encodeURIComponent;return"/b/"+e(this.bucket)+"/o/"+e(this.path)}bucketOnlyServerUrl(){return"/b/"+encodeURIComponent(this.bucket)+"/o"}static makeFromBucketSpec(e,t){let n;try{n=T.makeFromUrl(e,t)}catch(t){return new T(e,"")}if(""===n.path)return n;throw new p("invalid-default-bucket","Invalid default bucket '"+e+"'.")}static makeFromUrl(e,t){let n=null;const r="([A-Za-z0-9.\\-_]+)";const s=new RegExp("^gs://"+r+"(/(.*))?$","i");function o(e){e.path_=decodeURIComponent(e.path)}const i=t.replace(/[.]/g,"\\."),a=[{regex:s,indices:{bucket:1,path:3},postModify:function(e){"/"===e.path.charAt(e.path.length-1)&&(e.path_=e.path_.slice(0,-1))}},{regex:new RegExp(`^https?://${i}/v[A-Za-z0-9_]+/b/${r}/o(/([^?#]*).*)?$`,"i"),indices:{bucket:1,path:3},postModify:o},{regex:new RegExp(`^https?://${"firebasestorage.googleapis.com"===t?"(?:storage.googleapis.com|storage.cloud.google.com)":t}/${r}/([^?#]*)`,"i"),indices:{bucket:1,path:2},postModify:o}];for(let t=0;t<a.length;t++){const r=a[t],s=r.regex.exec(e);if(s){const e=s[r.indices.bucket];let t=s[r.indices.path];t||(t=""),n=new T(e,t),r.postModify(n);break}}if(null==n)throw function(e){return new p("invalid-url","Invalid URL '"+e+"'.")}(e);return n}}class x{constructor(e){this.promise_=Promise.reject(e)}getPromise(){return this.promise_}cancel(e=!1){}}function O(e){return"string"==typeof e||e instanceof String}function P(e){return C()&&e instanceof Blob}function C(){return"undefined"!=typeof Blob}function U(e,t,n,r){if(r<t)throw b(`Invalid value for '${e}'. Expected ${t} or greater.`);if(r>n)throw b(`Invalid value for '${e}'. Expected ${n} or less.`)}function S(e,t){const n=t.match(/^(\w+):\/\/.+/);let r=t;return null==(null==n?void 0:n[1])&&(r=`https://${t}`),`${r}/v0${e}`}function A(e){const t=encodeURIComponent;let n="?";for(const r in e)if(e.hasOwnProperty(r)){n=n+(t(r)+"="+t(e[r]))+"&"}return n=n.slice(0,-1),n}class E{constructor(e,t,n,r,s,o,i,a,c,u,l){this.pendingConnection_=null,this.backoffId_=null,this.canceled_=!1,this.appDelete_=!1,this.url_=e,this.method_=t,this.headers_=n,this.body_=r,this.successCodes_=s.slice(),this.additionalRetryCodes_=o.slice(),this.callback_=i,this.errorCallback_=a,this.progressCallback_=u,this.timeout_=c,this.pool_=l,this.promise_=new Promise(((e,t)=>{this.resolve_=e,this.reject_=t,this.start_()}))}start_(){const e=this;function t(t,n){const r=e.resolve_,s=e.reject_,o=n.connection;if(n.wasSuccessCode)try{const t=e.callback_(o,o.getResponseText());void 0!==t?r(t):r()}catch(e){s(e)}else if(null!==o){const t=f();t.serverResponse=o.getResponseText(),e.errorCallback_?s(e.errorCallback_(o,t)):s(t)}else if(n.canceled){s(e.appDelete_?w():g())}else{s(new p("retry-limit-exceeded","Max retry time for operation exceeded, please try again."))}}this.canceled_?t(0,new I(!1,null,!0)):this.backoffId_=function(e,t,n){let r=1,s=null,o=!1,i=0;function a(){return 2===i}let c=!1;function u(...e){c||(c=!0,t.apply(null,e))}function l(t){s=setTimeout((()=>{s=null,e(h,a())}),t)}function h(e,...t){if(c)return;if(e)return void u.call(null,e,...t);if(a()||o)return void u.call(null,e,...t);let n;r<64&&(r*=2),1===i?(i=2,n=0):n=1e3*(r+Math.random()),l(n)}let d=!1;function p(e){d||(d=!0,c||(null!==s?(e||(i=2),clearTimeout(s),l(0)):e||(i=1)))}return l(0),setTimeout((()=>{o=!0,p(!0)}),n),p}((function(t,n){if(n)return void t(!1,new I(!1,null,!0));const r=e.pool_.createConnection();function s(t){const n=t.loaded,r=t.lengthComputable?t.total:-1;null!==e.progressCallback_&&e.progressCallback_(n,r)}e.pendingConnection_=r,null!==e.progressCallback_&&r.addUploadProgressListener(s),r.send(e.url_,e.method_,e.body_,e.headers_).then((()=>{null!==e.progressCallback_&&r.removeUploadProgressListener(s),e.pendingConnection_=null;const n=r.getErrorCode()===h.NO_ERROR,o=r.getStatus();if(!n||e.isRetryStatusCode_(o)){const e=r.getErrorCode()===h.ABORT;return void t(!1,new I(!1,null,e))}const i=-1!==e.successCodes_.indexOf(o);t(!0,new I(i,r))}))}),t,this.timeout_)}getPromise(){return this.promise_}cancel(e){this.canceled_=!0,this.appDelete_=e||!1,null!==this.backoffId_&&(0,this.backoffId_)(!1),null!==this.pendingConnection_&&this.pendingConnection_.abort()}isRetryStatusCode_(e){const t=e>=500&&e<600,n=-1!==[408,429].indexOf(e),r=-1!==this.additionalRetryCodes_.indexOf(e);return t||n||r}}class I{constructor(e,t,n){this.wasSuccessCode=e,this.connection=t,this.canceled=!!n}}function q(){return"undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof WebKitBlobBuilder?WebKitBlobBuilder:void 0}function B(...e){const t=q();if(void 0!==t){const n=new t;for(let t=0;t<e.length;t++)n.append(e[t]);return n.getBlob()}if(C())return new Blob(e);throw new p("unsupported-environment","This browser doesn't seem to support creating Blobs")}const M={RAW:"raw",BASE64:"base64",BASE64URL:"base64url",DATA_URL:"data_url"};class z{constructor(e,t){this.data=e,this.contentType=t||null}}function L(e,t){switch(e){case M.RAW:return new z(F(t));case M.BASE64:case M.BASE64URL:return new z(H(e,t));case M.DATA_URL:return new z(function(e){const t=new j(e);return t.base64?H(M.BASE64,t.rest):function(e){let t;try{t=decodeURIComponent(e)}catch(e){throw v(M.DATA_URL,"Malformed data URL.")}return F(t)}(t.rest)}(t),new j(t).contentType)}throw f()}function F(e){const t=[];for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);if(r<=127)t.push(r);else if(r<=2047)t.push(192|r>>6,128|63&r);else if(55296==(64512&r)){if(n<e.length-1&&56320==(64512&e.charCodeAt(n+1))){r=65536|(1023&r)<<10|1023&e.charCodeAt(++n),t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r)}else t.push(239,191,189)}else 56320==(64512&r)?t.push(239,191,189):t.push(224|r>>12,128|r>>6&63,128|63&r)}return new Uint8Array(t)}function H(e,t){switch(e){case M.BASE64:{const n=-1!==t.indexOf("-"),r=-1!==t.indexOf("_");if(n||r){throw v(e,"Invalid character '"+(n?"-":"_")+"' found: is it base64url encoded?")}break}case M.BASE64URL:{const n=-1!==t.indexOf("+"),r=-1!==t.indexOf("/");if(n||r){throw v(e,"Invalid character '"+(n?"+":"/")+"' found: is it base64 encoded?")}t=t.replace(/-/g,"+").replace(/_/g,"/");break}}let n;try{n=atob(t)}catch(t){throw v(e,"Invalid character found")}const r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return r}class j{constructor(e){this.base64=!1,this.contentType=null;const t=e.match(/^data:([^,]+)?,/);if(null===t)throw v(M.DATA_URL,"Must be formatted 'data:[<mediatype>][;base64],<data>");const n=t[1]||null;null!=n&&(this.base64=function(e,t){if(!(e.length>=t.length))return!1;return e.substring(e.length-t.length)===t}(n,";base64"),this.contentType=this.base64?n.substring(0,n.length-";base64".length):n),this.rest=e.substring(e.indexOf(",")+1)}}class D{constructor(e,t){let n=0,r="";P(e)?(this.data_=e,n=e.size,r=e.type):e instanceof ArrayBuffer?(t?this.data_=new Uint8Array(e):(this.data_=new Uint8Array(e.byteLength),this.data_.set(new Uint8Array(e))),n=this.data_.length):e instanceof Uint8Array&&(t?this.data_=e:(this.data_=new Uint8Array(e.length),this.data_.set(e)),n=e.length),this.size_=n,this.type_=r}size(){return this.size_}type(){return this.type_}slice(e,t){if(P(this.data_)){const n=function(e,t,n){return e.webkitSlice?e.webkitSlice(t,n):e.mozSlice?e.mozSlice(t,n):e.slice?e.slice(t,n):null}(this.data_,e,t);return null===n?null:new D(n)}{const n=new Uint8Array(this.data_.buffer,e,t-e);return new D(n,!0)}}static getBlob(...e){if(C()){const t=e.map((e=>e instanceof D?e.data_:e));return new D(B.apply(null,t))}{const t=e.map((e=>O(e)?L(M.RAW,e).data:e.data_));let n=0;t.forEach((e=>{n+=e.byteLength}));const r=new Uint8Array(n);let s=0;return t.forEach((e=>{for(let t=0;t<e.length;t++)r[s++]=e[t]})),new D(r,!0)}}uploadData(){return this.data_}}function $(e){let t;try{t=JSON.parse(e)}catch(e){return null}return"object"!=typeof(n=t)||Array.isArray(n)?null:t;var n}function N(e){const t=e.lastIndexOf("/",e.length-2);return-1===t?e:e.slice(t+1)}function W(e,t){return t}class G{constructor(e,t,n,r){this.server=e,this.local=t||e,this.writable=!!n,this.xform=r||W}}let X=null;function K(){if(X)return X;const e=[];e.push(new G("bucket")),e.push(new G("generation")),e.push(new G("metageneration")),e.push(new G("name","fullPath",!0));const t=new G("name");t.xform=function(e,t){return function(e){return!O(e)||e.length<2?e:N(e)}(t)},e.push(t);const n=new G("size");return n.xform=function(e,t){return void 0!==t?Number(t):t},e.push(n),e.push(new G("timeCreated")),e.push(new G("updated")),e.push(new G("md5Hash",null,!0)),e.push(new G("cacheControl",null,!0)),e.push(new G("contentDisposition",null,!0)),e.push(new G("contentEncoding",null,!0)),e.push(new G("contentLanguage",null,!0)),e.push(new G("contentType",null,!0)),e.push(new G("metadata","customMetadata",!0)),X=e,X}function V(e,t,n){const r={type:"file"},s=n.length;for(let e=0;e<s;e++){const s=n[e];r[s.local]=s.xform(r,t[s.server])}return function(e,t){Object.defineProperty(e,"ref",{get:function(){const n=e.bucket,r=e.fullPath,s=new T(n,r);return t._makeStorageReference(s)}})}(r,e),r}function Z(e,t,n){const r=$(t);if(null===r)return null;return V(e,r,n)}function Y(e,t){const n={},r=t.length;for(let s=0;s<r;s++){const r=t[s];r.writable&&(n[r.server]=e[r.local])}return JSON.stringify(n)}function J(e,t,n){const r=$(n);if(null===r)return null;return function(e,t,n){const r={prefixes:[],items:[],nextPageToken:n.nextPageToken};if(n.prefixes)for(const s of n.prefixes){const n=s.replace(/\/$/,""),o=e._makeStorageReference(new T(t,n));r.prefixes.push(o)}if(n.items)for(const s of n.items){const n=e._makeStorageReference(new T(t,s.name));r.items.push(n)}return r}(e,t,r)}class Q{constructor(e,t,n,r){this.url=e,this.method=t,this.handler=n,this.timeout=r,this.urlParams={},this.headers={},this.body=null,this.errorHandler=null,this.progressCallback=null,this.successCodes=[200],this.additionalRetryCodes=[]}}function ee(e){if(!e)throw f()}function te(e,t){return function(n,r){const s=Z(e,r,t);return ee(null!==s),s}}function ne(e,t){return function(n,r){const s=Z(e,r,t);return ee(null!==s),function(e,t,n){const r=$(t);if(null===r)return null;if(!O(r.downloadTokens))return null;const s=r.downloadTokens;if(0===s.length)return null;const o=encodeURIComponent;return s.split(",").map((t=>{const r=e.bucket,s=e.fullPath;return S("/b/"+o(r)+"/o/"+o(s),n)+A({alt:"media",token:t})}))[0]}(s,r,e.host)}}function re(e){return function(t,n){let r;var s,o;return 401===t.getStatus()?r=t.getResponseText().includes("Firebase App Check token is invalid")?new p("unauthorized-app","This app does not have permission to access Firebase Storage on this project."):new p("unauthenticated","User is not authenticated, please authenticate using Firebase Authentication and try again."):402===t.getStatus()?(o=e.bucket,r=new p("quota-exceeded","Quota for bucket '"+o+"' exceeded, please view quota on https://firebase.google.com/pricing/.")):403===t.getStatus()?(s=e.path,r=new p("unauthorized","User does not have permission to access '"+s+"'.")):r=n,r.serverResponse=n.serverResponse,r}}function se(e){const t=re(e);return function(n,r){let s=t(n,r);var o;return 404===n.getStatus()&&(o=e.path,s=new p("object-not-found","Object '"+o+"' does not exist.")),s.serverResponse=r.serverResponse,s}}function oe(e,t,n){const r=S(t.fullServerUrl(),e.host),s=e.maxOperationRetryTime,o=new Q(r,"GET",te(e,n),s);return o.errorHandler=se(t),o}function ie(e,t,n,r,s){const o={};t.isRoot?o.prefix="":o.prefix=t.path+"/",n&&n.length>0&&(o.delimiter=n),r&&(o.pageToken=r),s&&(o.maxResults=s);const i=S(t.bucketOnlyServerUrl(),e.host),a=e.maxOperationRetryTime,c=new Q(i,"GET",function(e,t){return function(n,r){const s=J(e,t,r);return ee(null!==s),s}}(e,t.bucket),a);return c.urlParams=o,c.errorHandler=re(t),c}function ae(e,t,n){const r=Object.assign({},n);return r.fullPath=e.path,r.size=t.size(),r.contentType||(r.contentType=function(e,t){return e&&e.contentType||t&&t.type()||"application/octet-stream"}(null,t)),r}function ce(e,t,n,r,s){const o=t.bucketOnlyServerUrl(),i={"X-Goog-Upload-Protocol":"multipart"};const a=function(){let e="";for(let t=0;t<2;t++)e+=Math.random().toString().slice(2);return e}();i["Content-Type"]="multipart/related; boundary="+a;const c=ae(t,r,s),u="--"+a+"\r\nContent-Type: application/json; charset=utf-8\r\n\r\n"+Y(c,n)+"\r\n--"+a+"\r\nContent-Type: "+c.contentType+"\r\n\r\n",l="\r\n--"+a+"--",h=D.getBlob(u,r,l);if(null===h)throw m();const d={name:c.fullPath},p=S(o,e.host),_=e.maxUploadRetryTime,f=new Q(p,"POST",te(e,n),_);return f.urlParams=d,f.headers=i,f.body=h.uploadData(),f.errorHandler=re(t),f}class ue{constructor(e,t,n,r){this.current=e,this.total=t,this.finalized=!!n,this.metadata=r||null}}function le(e,t){let n=null;try{n=e.getResponseHeader("X-Goog-Upload-Status")}catch(e){ee(!1)}return ee(!!n&&-1!==(t||["active"]).indexOf(n)),n}function he(e,t,n,r,s,o,i,a){const c=new ue(0,0);if(i?(c.current=i.current,c.total=i.total):(c.current=0,c.total=r.size()),r.size()!==c.total)throw new p("server-file-wrong-size","Server recorded incorrect upload file size, please retry the upload.");const u=c.total-c.current;let l=u;s>0&&(l=Math.min(l,s));const h=c.current,d=h+l,_={"X-Goog-Upload-Command":l===u?"upload, finalize":"upload","X-Goog-Upload-Offset":`${c.current}`},f=r.slice(h,d);if(null===f)throw m();const g=t.maxUploadRetryTime,b=new Q(n,"POST",(function(e,n){const s=le(e,["active","final"]),i=c.current+l,a=r.size();let u;return u="final"===s?te(t,o)(e,n):null,new ue(i,a,"final"===s,u)}),g);return b.headers=_,b.body=f.uploadData(),b.progressCallback=a||null,b.errorHandler=re(e),b}const de="running",pe="paused",_e="success",fe="canceled",ge="error";function me(e){switch(e){case"running":case"pausing":case"canceling":return de;case"paused":return pe;case"success":return _e;case"canceled":return fe;case"error":default:return ge}}class be{constructor(e,t,n){if("function"==typeof e||null!=t||null!=n)this.next=e,this.error=t,this.complete=n;else{const t=e;this.next=t.next,this.error=t.error,this.complete=t.complete}}}function we(e){return(...t)=>{Promise.resolve().then((()=>e(...t)))}}class ve{constructor(e,t,n=null){this._transferred=0,this._needToFetchStatus=!1,this._needToFetchMetadata=!1,this._observers=[],this._error=void 0,this._uploadUrl=void 0,this._request=void 0,this._chunkMultiplier=1,this._resolve=void 0,this._reject=void 0,this._ref=e,this._blob=t,this._metadata=n,this._mappings=K(),this._resumable=this._shouldDoResumable(this._blob),this._state="running",this._errorHandler=e=>{this._request=void 0,this._chunkMultiplier=1,e._codeEquals("canceled")?(this._needToFetchStatus=!0,this.completeTransitions_()):(this._error=e,this._transition("error"))},this._metadataErrorHandler=e=>{this._request=void 0,e._codeEquals("canceled")?this.completeTransitions_():(this._error=e,this._transition("error"))},this._promise=new Promise(((e,t)=>{this._resolve=e,this._reject=t,this._start()})),this._promise.then(null,(()=>{}))}_makeProgressCallback(){const e=this._transferred;return t=>this._updateProgress(e+t)}_shouldDoResumable(e){return e.size()>262144}_start(){"running"===this._state&&void 0===this._request&&(this._resumable?void 0===this._uploadUrl?this._createResumable():this._needToFetchStatus?this._fetchStatus():this._needToFetchMetadata?this._fetchMetadata():this._continueUpload():this._oneShotUpload())}_resolveToken(e){Promise.all([this._ref.storage._getAuthToken(),this._ref.storage._getAppCheckToken()]).then((([t,n])=>{switch(this._state){case"running":e(t,n);break;case"canceling":this._transition("canceled");break;case"pausing":this._transition("paused")}}))}_createResumable(){this._resolveToken(((e,t)=>{const n=function(e,t,n,r,s){const o=t.bucketOnlyServerUrl(),i=ae(t,r,s),a={name:i.fullPath},c=S(o,e.host),u={"X-Goog-Upload-Protocol":"resumable","X-Goog-Upload-Command":"start","X-Goog-Upload-Header-Content-Length":`${r.size()}`,"X-Goog-Upload-Header-Content-Type":i.contentType,"Content-Type":"application/json; charset=utf-8"},l=Y(i,n),h=e.maxUploadRetryTime,d=new Q(c,"POST",(function(e){let t;le(e);try{t=e.getResponseHeader("X-Goog-Upload-URL")}catch(e){ee(!1)}return ee(O(t)),t}),h);return d.urlParams=a,d.headers=u,d.body=l,d.errorHandler=re(t),d}(this._ref.storage,this._ref._location,this._mappings,this._blob,this._metadata),r=this._ref.storage._makeRequest(n,e,t);this._request=r,r.getPromise().then((e=>{this._request=void 0,this._uploadUrl=e,this._needToFetchStatus=!1,this.completeTransitions_()}),this._errorHandler)}))}_fetchStatus(){const e=this._uploadUrl;this._resolveToken(((t,n)=>{const r=function(e,t,n,r){const s=e.maxUploadRetryTime,o=new Q(n,"POST",(function(e){const t=le(e,["active","final"]);let n=null;try{n=e.getResponseHeader("X-Goog-Upload-Size-Received")}catch(e){ee(!1)}n||ee(!1);const s=Number(n);return ee(!isNaN(s)),new ue(s,r.size(),"final"===t)}),s);return o.headers={"X-Goog-Upload-Command":"query"},o.errorHandler=re(t),o}(this._ref.storage,this._ref._location,e,this._blob),s=this._ref.storage._makeRequest(r,t,n);this._request=s,s.getPromise().then((e=>{e=e,this._request=void 0,this._updateProgress(e.current),this._needToFetchStatus=!1,e.finalized&&(this._needToFetchMetadata=!0),this.completeTransitions_()}),this._errorHandler)}))}_continueUpload(){const e=262144*this._chunkMultiplier,t=new ue(this._transferred,this._blob.size()),n=this._uploadUrl;this._resolveToken(((r,s)=>{let o;try{o=he(this._ref._location,this._ref.storage,n,this._blob,e,this._mappings,t,this._makeProgressCallback())}catch(e){return this._error=e,void this._transition("error")}const i=this._ref.storage._makeRequest(o,r,s);this._request=i,i.getPromise().then((e=>{this._increaseMultiplier(),this._request=void 0,this._updateProgress(e.current),e.finalized?(this._metadata=e.metadata,this._transition("success")):this.completeTransitions_()}),this._errorHandler)}))}_increaseMultiplier(){262144*this._chunkMultiplier<33554432&&(this._chunkMultiplier*=2)}_fetchMetadata(){this._resolveToken(((e,t)=>{const n=oe(this._ref.storage,this._ref._location,this._mappings),r=this._ref.storage._makeRequest(n,e,t);this._request=r,r.getPromise().then((e=>{this._request=void 0,this._metadata=e,this._transition("success")}),this._metadataErrorHandler)}))}_oneShotUpload(){this._resolveToken(((e,t)=>{const n=ce(this._ref.storage,this._ref._location,this._mappings,this._blob,this._metadata),r=this._ref.storage._makeRequest(n,e,t);this._request=r,r.getPromise().then((e=>{this._request=void 0,this._metadata=e,this._updateProgress(this._blob.size()),this._transition("success")}),this._errorHandler)}))}_updateProgress(e){const t=this._transferred;this._transferred=e,this._transferred!==t&&this._notifyObservers()}_transition(e){if(this._state!==e)switch(e){case"canceling":case"pausing":this._state=e,void 0!==this._request&&this._request.cancel();break;case"running":const t="paused"===this._state;this._state=e,t&&(this._notifyObservers(),this._start());break;case"paused":this._state=e,this._notifyObservers();break;case"canceled":this._error=g(),this._state=e,this._notifyObservers();break;case"error":case"success":this._state=e,this._notifyObservers()}}completeTransitions_(){switch(this._state){case"pausing":this._transition("paused");break;case"canceling":this._transition("canceled");break;case"running":this._start()}}get snapshot(){const e=me(this._state);return{bytesTransferred:this._transferred,totalBytes:this._blob.size(),state:e,metadata:this._metadata,task:this,ref:this._ref}}on(e,t,n,r){const s=new be(t,n,r);return this._addObserver(s),()=>{this._removeObserver(s)}}then(e,t){return this._promise.then(e,t)}catch(e){return this.then(null,e)}_addObserver(e){this._observers.push(e),this._notifyObserver(e)}_removeObserver(e){const t=this._observers.indexOf(e);-1!==t&&this._observers.splice(t,1)}_notifyObservers(){this._finishPromise();this._observers.slice().forEach((e=>{this._notifyObserver(e)}))}_finishPromise(){if(void 0!==this._resolve){let e=!0;switch(me(this._state)){case _e:we(this._resolve.bind(null,this.snapshot))();break;case fe:case ge:we(this._reject.bind(null,this._error))();break;default:e=!1}e&&(this._resolve=void 0,this._reject=void 0)}}_notifyObserver(e){switch(me(this._state)){case de:case pe:e.next&&we(e.next.bind(e,this.snapshot))();break;case _e:e.complete&&we(e.complete.bind(e))();break;case fe:case ge:e.error&&we(e.error.bind(e,this._error))();break;default:e.error&&we(e.error.bind(e,this._error))()}}resume(){const e="paused"===this._state||"pausing"===this._state;return e&&this._transition("running"),e}pause(){const e="running"===this._state;return e&&this._transition("pausing"),e}cancel(){const e="running"===this._state||"pausing"===this._state;return e&&this._transition("canceling"),e}}class ye{constructor(e,t){this._service=e,this._location=t instanceof T?t:T.makeFromUrl(t,e.host)}toString(){return"gs://"+this._location.bucket+"/"+this._location.path}_newRef(e,t){return new ye(e,t)}get root(){const e=new T(this._location.bucket,"");return this._newRef(this._service,e)}get bucket(){return this._location.bucket}get fullPath(){return this._location.path}get name(){return N(this._location.path)}get storage(){return this._service}get parent(){const e=function(e){if(0===e.length)return null;const t=e.lastIndexOf("/");return-1===t?"":e.slice(0,t)}(this._location.path);if(null===e)return null;const t=new T(this._location.bucket,e);return new ye(this._service,t)}_throwIfRoot(e){if(""===this._location.path)throw function(e){return new p("invalid-root-operation","The operation '"+e+"' cannot be performed on a root reference, create a non-root reference using child, such as .child('file.png').")}(e)}}function ke(e,t,n){e._throwIfRoot("uploadBytes");const r=ce(e.storage,e._location,K(),new D(t,!0),n);return e.storage.makeRequestWithTokens(r).then((e=>e.getPromise())).then((t=>({metadata:t,ref:e})))}function Re(e){const t={prefixes:[],items:[]};return Te(e,t).then((()=>t))}async function Te(e,t,n){const r={pageToken:n},s=await xe(e,r);t.prefixes.push(...s.prefixes),t.items.push(...s.items),null!=s.nextPageToken&&await Te(e,t,s.nextPageToken)}async function xe(e,t){null!=t&&"number"==typeof t.maxResults&&U("options.maxResults",1,1e3,t.maxResults);const n=t||{},r=ie(e.storage,e._location,"/",n.pageToken,n.maxResults);return(await e.storage.makeRequestWithTokens(r)).getPromise()}async function Oe(e,t){e._throwIfRoot("updateMetadata");const n=function(e,t,n,r){const s=S(t.fullServerUrl(),e.host),o=Y(n,r),i=e.maxOperationRetryTime,a=new Q(s,"PATCH",te(e,r),i);return a.headers={"Content-Type":"application/json; charset=utf-8"},a.body=o,a.errorHandler=se(t),a}(e.storage,e._location,t,K());return(await e.storage.makeRequestWithTokens(n)).getPromise()}async function Pe(e){e._throwIfRoot("getDownloadURL");const t=function(e,t,n){const r=S(t.fullServerUrl(),e.host),s=e.maxOperationRetryTime,o=new Q(r,"GET",ne(e,n),s);return o.errorHandler=se(t),o}(e.storage,e._location,K());return(await e.storage.makeRequestWithTokens(t)).getPromise().then((e=>{if(null===e)throw new p("no-download-url","The given file does not have any download URLs.");return e}))}async function Ce(e){e._throwIfRoot("deleteObject");const t=function(e,t){const n=S(t.fullServerUrl(),e.host),r=e.maxOperationRetryTime,s=new Q(n,"DELETE",(function(e,t){}),r);return s.successCodes=[200,204],s.errorHandler=se(t),s}(e.storage,e._location);return(await e.storage.makeRequestWithTokens(t)).getPromise()}function Ue(e,t){const n=function(e,t){const n=t.split("/").filter((e=>e.length>0)).join("/");return 0===e.length?n:e+"/"+n}(e._location.path,t),r=new T(e._location.bucket,n);return new ye(e.storage,r)}function Se(e,t){if(e instanceof Ie){const n=e;if(null==n._bucket)throw new p("no-default-bucket","No default bucket found. Did you set the 'storageBucket' property when initializing the app?");const r=new ye(n,n._bucket);return null!=t?Se(r,t):r}if(void 0!==t){if(t.includes(".."))throw b('`path` param cannot contain ".."');return Ue(e,t)}return e}function Ae(e,t){if(t&&/^[A-Za-z]+:\/\//.test(t)){if(e instanceof Ie)return new ye(e,t);throw b("To use ref(service, url), the first argument must be a Storage instance.")}return Se(e,t)}function Ee(e,t){const n=null==t?void 0:t.storageBucket;return null==n?null:T.makeFromBucketSpec(n,e)}class Ie{constructor(e,t,n,r,s,o){this.app=e,this._authProvider=t,this._appCheckProvider=n,this._pool=r,this._url=s,this._firebaseVersion=o,this._bucket=null,this._host="firebasestorage.googleapis.com",this._appId=null,this._deleted=!1,this._maxOperationRetryTime=12e4,this._maxUploadRetryTime=6e5,this._requests=new Set,this._bucket=null!=s?T.makeFromBucketSpec(s,this._host):Ee(this._host,this.app.options)}get host(){return this._host}set host(e){this._host=e,null!=this._url?this._bucket=T.makeFromBucketSpec(this._url,e):this._bucket=Ee(e,this.app.options)}get maxUploadRetryTime(){return this._maxUploadRetryTime}set maxUploadRetryTime(e){U("time",0,Number.POSITIVE_INFINITY,e),this._maxUploadRetryTime=e}get maxOperationRetryTime(){return this._maxOperationRetryTime}set maxOperationRetryTime(e){U("time",0,Number.POSITIVE_INFINITY,e),this._maxOperationRetryTime=e}async _getAuthToken(){const e=this._authProvider.getImmediate({optional:!0});if(e){const t=await e.getToken();if(null!==t)return t.accessToken}return null}async _getAppCheckToken(){const e=this._appCheckProvider.getImmediate({optional:!0});if(e){return(await e.getToken()).token}return null}_delete(){return this._deleted=!0,this._requests.forEach((e=>e.cancel())),this._requests.clear(),Promise.resolve()}_makeStorageReference(e){return new ye(this,e)}_makeRequest(e,t,n){if(this._deleted)return new x(w());{const r=function(e,t,n,r,s,o){const i=A(e.urlParams),a=e.url+i,c=Object.assign({},e.headers);return function(e,t){t&&(e["X-Firebase-GMPID"]=t)}(c,t),function(e,t){null!==t&&t.length>0&&(e.Authorization="Firebase "+t)}(c,n),function(e,t){e["X-Firebase-Storage-Version"]="webjs/"+(null!=t?t:"AppManager")}(c,o),function(e,t){null!==t&&(e["X-Firebase-AppCheck"]=t)}(c,r),new E(a,e.method,c,e.body,e.successCodes,e.additionalRetryCodes,e.handler,e.errorHandler,e.timeout,e.progressCallback,s)}(e,this._appId,t,n,this._pool,this._firebaseVersion);return this._requests.add(r),r.getPromise().then((()=>this._requests.delete(r)),(()=>this._requests.delete(r))),r}}async makeRequestWithTokens(e){const[t,n]=await Promise.all([this._getAuthToken(),this._getAppCheckToken()]);return this._makeRequest(e,t,n)}}function qe(e,t,n){return ke(e=l(e),t,n)}function Be(e,t,n,r){return function(e,t,n=M.RAW,r){e._throwIfRoot("uploadString");const s=L(n,t),o=Object.assign({},r);return null==o.contentType&&null!=s.contentType&&(o.contentType=s.contentType),ke(e,s.data,o)}(e=l(e),t,n,r)}function Me(e,t,n){return function(e,t,n){return e._throwIfRoot("uploadBytesResumable"),new ve(e,new D(t),n)}(e=l(e),t,n)}function ze(e){return async function(e){e._throwIfRoot("getMetadata");const t=oe(e.storage,e._location,K());return(await e.storage.makeRequestWithTokens(t)).getPromise()}(e=l(e))}function Le(e,t){return Oe(e=l(e),t)}function Fe(e,t){return xe(e=l(e),t)}function He(e){return Re(e=l(e))}function je(e){return Pe(e=l(e))}function De(e){return Ce(e=l(e))}function $e(e,t){return Ae(e=l(e),t)}function Ne(e,t){return Ue(e,t)}function We(n=e(),r){n=l(n);return t(n,"storage-exp").getImmediate({identifier:r})}function Ge(e,t,n){!function(e,t,n){e.host=`http://${t}:${n}`}(e,t,n)}function Xe(e,{instanceIdentifier:t}){const n=e.getProvider("app-exp").getImmediate(),r=e.getProvider("auth-internal"),o=e.getProvider("app-check-internal");return new Ie(n,r,o,new R,t,s)}n(new d("storage-exp",Xe,"PUBLIC").setMultipleInstances(!0)),r("@firebase/storage","0.0.900-exp.6ef484a04");export{M as StringFormat,D as _FbsBlob,T as _Location,ve as _UploadTask,Ne as _getChild,Ge as connectStorageEmulator,De as deleteObject,je as getDownloadURL,ze as getMetadata,We as getStorage,Fe as list,He as listAll,$e as ref,Le as updateMetadata,qe as uploadBytes,Me as uploadBytesResumable,Be as uploadString}; //# sourceMappingURL=firebase-storage.js.map