UNPKG

firebase

Version:

Firebase JavaScript library for web and Node.js

3 lines (2 loc) • 10.7 kB
((e,t)=>{"object"==typeof exports&&"undefined"!=typeof module?t(require("@firebase/app-compat"),require("@firebase/app")):"function"==typeof define&&define.amd?define(["@firebase/app-compat","@firebase/app"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).firebase,e.firebase.INTERNAL.modularAPIs)})(this,function(x,U){try{!(function(){function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t,r=e(x);class s extends Error{constructor(e,t,r){super(t),this.code=e,this.customData=r,this.name="FirebaseError",Object.setPrototypeOf(this,s.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,n.prototype.create)}}class n{constructor(e,t,r){this.service=e,this.serviceName=t,this.errors=r}create(e,...t){var n,r=t[0]||{},a=this.service+"/"+e,i=this.errors[e],i=i?(n=r,i.replace(o,(e,t)=>{var r=n[t];return null!=r?String(r):`<${t}?>`})):"Error",i=this.serviceName+`: ${i} (${a}).`;return new s(a,i,r)}}let o=/\{\$([^}]+)}/g;function c(e){return e&&e._delegate?e._delegate:e}function a(e){try{return(e.startsWith("http://")||e.startsWith("https://")?new URL(e).hostname:e).endsWith(".cloudworkstations.dev")}catch{return!1}}class i{constructor(e,t,r){this.name=e,this.instanceFactory=t,this.type=r,this.multipleInstances=!1,this.serviceProps={},this.instantiationMode="LAZY",this.onInstanceCreated=null}setInstantiationMode(e){return this.instantiationMode=e,this}setMultipleInstances(e){return this.multipleInstances=e,this}setServiceProps(e){return this.serviceProps=e,this}setInstanceCreatedCallback(e){return this.onInstanceCreated=e,this}}let u="type.googleapis.com/google.protobuf.Int64Value",l="type.googleapis.com/google.protobuf.UInt64Value";function d(e,t){var r,n={};for(r in e)e.hasOwnProperty(r)&&(n[r]=t(e[r]));return n}function h(e){if(null==e)return null;if("number"==typeof(e=e instanceof Number?e.valueOf():e)&&isFinite(e))return e;if(!0===e||!1===e)return e;if("[object String]"===Object.prototype.toString.call(e))return e;if(e instanceof Date)return e.toISOString();if(Array.isArray(e))return e.map(e=>h(e));if("function"==typeof e||"object"==typeof e)return d(e,e=>h(e));throw new Error("Data cannot be encoded in JSON: "+e)}function p(e){if(null==e)return e;if(e["@type"])switch(e["@type"]){case u:case l:var t=Number(e.value);if(isNaN(t))throw new Error("Data cannot be decoded from JSON: "+e);return t;default:throw new Error("Data cannot be decoded from JSON: "+e)}return Array.isArray(e)?e.map(e=>p(e)):"function"==typeof e||"object"==typeof e?d(e,e=>p(e)):e}let m="functions",f={OK:"ok",CANCELLED:"cancelled",UNKNOWN:"unknown",INVALID_ARGUMENT:"invalid-argument",DEADLINE_EXCEEDED:"deadline-exceeded",NOT_FOUND:"not-found",ALREADY_EXISTS:"already-exists",PERMISSION_DENIED:"permission-denied",UNAUTHENTICATED:"unauthenticated",RESOURCE_EXHAUSTED:"resource-exhausted",FAILED_PRECONDITION:"failed-precondition",ABORTED:"aborted",OUT_OF_RANGE:"out-of-range",UNIMPLEMENTED:"unimplemented",INTERNAL:"internal",UNAVAILABLE:"unavailable",DATA_LOSS:"data-loss"};class g extends s{constructor(e,t,r){super(m+"/"+e,t||""),this.details=r,Object.setPrototypeOf(this,g.prototype)}}function v(e,t){let r=(e=>{if(200<=e&&e<300)return"ok";switch(e){case 0:return"internal";case 400:return"invalid-argument";case 401:return"unauthenticated";case 403:return"permission-denied";case 404:return"not-found";case 409:return"aborted";case 429:return"resource-exhausted";case 499:return"cancelled";case 500:return"internal";case 501:return"unimplemented";case 503:return"unavailable";case 504:return"deadline-exceeded"}return"unknown"})(e),n=r,a=void 0;try{var i=t&&t.error;if(i){let e=i.status;if("string"==typeof e){if(!f[e])return new g("internal","internal");r=f[e],n=e}var s=i.message;"string"==typeof s&&(n=s),void 0!==(a=i.details)&&(a=p(a))}}catch(e){}return"ok"===r?null:new g(r,n,a)}class w{constructor(e,t,r,n){this.app=e,this.auth=null,this.messaging=null,this.appCheck=null,this.serverAppAppCheckToken=null,U._isFirebaseServerApp(e)&&e.settings.appCheckToken&&(this.serverAppAppCheckToken=e.settings.appCheckToken),this.auth=t.getImmediate({optional:!0}),this.messaging=r.getImmediate({optional:!0}),this.auth||t.get().then(e=>this.auth=e,()=>{}),this.messaging||r.get().then(e=>this.messaging=e,()=>{}),this.appCheck||n?.get().then(e=>this.appCheck=e,()=>{})}async getAuthToken(){if(this.auth)try{return(await this.auth.getToken())?.accessToken}catch(e){}}async getMessagingToken(){if(this.messaging&&"Notification"in self&&"granted"===Notification.permission)try{return await this.messaging.getToken()}catch(e){}}async getAppCheckToken(e){var t;return this.serverAppAppCheckToken||(!this.appCheck||(t=e?await this.appCheck.getLimitedUseToken():await this.appCheck.getToken()).error?null:t.token)}async getContext(e){return{authToken:await this.getAuthToken(),messagingToken:await this.getMessagingToken(),appCheckToken:await this.getAppCheckToken(e)}}}let y="us-central1",k=/^data: (.*?)(?:\n|$)/;class b{constructor(e,t,r,n,a=y,i=(...e)=>fetch(...e)){this.app=e,this.fetchImpl=i,this.emulatorOrigin=null,this.contextProvider=new w(e,t,r,n),this.cancelAllRequests=new Promise(e=>{this.deleteService=()=>Promise.resolve(e())});try{var s=new URL(a);this.customDomain=s.origin+("/"===s.pathname?"":s.pathname),this.region=y}catch(e){this.customDomain=null,this.region=a}}_delete(){return this.deleteService()}_url(e){var t=this.app.options.projectId;return null!==this.emulatorOrigin?`${this.emulatorOrigin}/${t}/${this.region}/`+e:null!==this.customDomain?this.customDomain+"/"+e:`https://${this.region}-${t}.cloudfunctions.net/`+e}}function T(e,t,r){var n=a(t);e.emulatorOrigin=`http${n?"s":""}://${t}:`+r,n&&(async e=>(await fetch(e,{credentials:"include"})).ok)(e.emulatorOrigin+"/backends")}function E(a,i,s){var e=e=>{return e=e,r=s||{},n=(t=a)._url(i),N(t,n,e,r);var t,r,n};return e.stream=(e,t)=>{return e=e,t=t,n=(r=a)._url(i),C(r,n,e,t||{});var r,n},e}function I(e){return e.emulatorOrigin&&a(e.emulatorOrigin)?"include":void 0}async function A(e,t){var r={},n=await e.contextProvider.getContext(t.limitedUseAppCheckTokens);return n.authToken&&(r.Authorization="Bearer "+n.authToken),n.messagingToken&&(r["Firebase-Instance-ID-Token"]=n.messagingToken),null!==n.appCheckToken&&(r["X-Firebase-AppCheck"]=n.appCheckToken),r}async function N(e,t,r,n){var a={data:r=h(r)},i=await A(e,n),s=(r=>{let n=null;return{promise:new Promise((e,t)=>{n=setTimeout(()=>{t(new g("deadline-exceeded","deadline-exceeded"))},r)}),cancel:()=>{n&&clearTimeout(n)}}})(n.timeout||7e4),a=await Promise.race([(async(e,t,r,n,a)=>{r["Content-Type"]="application/json";let i;try{i=await n(e,{method:"POST",body:JSON.stringify(t),headers:r,credentials:I(a)})}catch(e){return{status:0,json:null}}let s=null;try{s=await i.json()}catch(e){}return{status:i.status,json:s}})(t,a,i,e.fetchImpl,e),s.promise,e.cancelAllRequests]);if(s.cancel(),!a)throw new g("cancelled","Firebase Functions instance was deleted.");i=v(a.status,a.json);if(i)throw i;if(!a.json)throw new g("internal","Response is not valid JSON object.");let o=a.json.data;if(void 0===(o=void 0===o?a.json.result:o))throw new g("internal","Response is missing data field.");return{data:p(o)}}async function C(e,t,r,n){var a={data:r=h(r)},i=await A(e,n);i["Content-Type"]="application/json",i.Accept="text/event-stream";let s;try{s=await e.fetchImpl(t,{method:"POST",body:JSON.stringify(a),headers:i,signal:n?.signal,credentials:I(e)})}catch(e){if(e instanceof Error&&"AbortError"===e.name){let e=new g("cancelled","Request was cancelled.");return{data:Promise.reject(e),stream:{[Symbol.asyncIterator](){return{next(){return Promise.reject(e)}}}}}}let t=v(0,null);return{data:Promise.reject(t),stream:{[Symbol.asyncIterator](){return{next(){return Promise.reject(t)}}}}}}let o,c;a=new Promise((e,t)=>{o=e,c=t}),n?.signal?.addEventListener("abort",()=>{var e=new g("cancelled","Request was cancelled.");c(e)}),i=s.body.getReader();let u=((s,i,o,c)=>{let u=(e,t)=>{var r=e.match(k);if(r){r=r[1];try{var n,a=JSON.parse(r);"result"in a?i(p(a.result)):"message"in a?t.enqueue(p(a.message)):"error"in a&&(n=v(0,a),t.error(n),o(n))}catch(e){e instanceof g&&(t.error(e),o(e))}}},l=new TextDecoder;return new ReadableStream({start(a){let i="";return async function r(){if(c?.aborted){let e=new g("cancelled","Request was cancelled");return a.error(e),o(e),Promise.resolve()}try{let{value:t,done:e}=await s.read();if(e)i.trim()&&u(i.trim(),a),a.close();else{if(!c?.aborted){let e=(i+=l.decode(t,{stream:!0})).split("\n");i=e.pop()||"";for(var n of e)n.trim()&&u(n.trim(),a);return r()}{let e=new g("cancelled","Request was cancelled");a.error(e),o(e),void await s.cancel()}}}catch(e){let t=e instanceof g?e:v(0,null);a.error(t),o(t)}}()},cancel(){return s.cancel()}})})(i,o,c,n?.signal);return{stream:{[Symbol.asyncIterator](){let r=u.getReader();return{async next(){var{value:e,done:t}=await r.read();return{value:e,done:t}},async return(){return await r.cancel(),{done:!0,value:void 0}}}}},data:a}}let O="@firebase/functions",P="0.13.3";function S(e,t,r){T(c(e),t,r)}function D(e,t,r){return n=c(e),a=t,i=r,(s=e=>N(n,a,e,i||{})).stream=(e,t)=>C(n,a,e,t||{}),s;var n,a,i,s}U._registerComponent(new i(m,(e,{instanceIdentifier:t})=>{var r=e.getProvider("app").getImmediate(),n=e.getProvider("auth-internal"),a=e.getProvider("messaging-internal"),i=e.getProvider("app-check-internal");return new b(r,n,a,i,t)},"PUBLIC").setMultipleInstances(!0)),U.registerVersion(O,P,t),U.registerVersion(O,P,"esm2020");var _;class j{constructor(e,t){this.app=e,this._delegate=t,this._region=this._delegate.region,this._customDomain=this._delegate.customDomain}httpsCallable(e,t){return E(c(this._delegate),e,t)}httpsCallableFromURL(e,t){return D(this._delegate,e,t)}useFunctionsEmulator(e){var t=e.match("[a-zA-Z]+://([a-zA-Z0-9.-]+)(?::([0-9]+))?");if(null==t)throw new s("functions","No origin provided to useFunctionsEmulator()");if(null==t[2])throw new s("functions","Port missing in origin provided to useFunctionsEmulator()");return S(this._delegate,t[1],Number(t[2]))}useEmulator(e,t){return S(this._delegate,e,t)}}let R="us-central1",L=(e,{instanceIdentifier:t})=>{var r=e.getProvider("app-compat").getImmediate(),n=e.getProvider("functions").getImmediate({identifier:t??R});return new j(r,n)};_={Functions:j},r.default.INTERNAL.registerComponent(new i("functions-compat",L,"PUBLIC").setServiceProps(_).setMultipleInstances(!0)),r.default.registerVersion("@firebase/functions-compat","0.4.3")}).apply(this,arguments)}catch(e){throw console.error(e),new Error("Cannot instantiate firebase-functions-compat.js - be sure to load firebase-app.js first.")}}); //# sourceMappingURL=firebase-functions-compat.js.map