UNPKG

firebase

Version:

Firebase JavaScript library for web and Node.js

3 lines (2 loc) • 7.39 kB
import{getApp as t,_getProvider as e,registerVersion as n,_registerComponent as r}from"https://www.gstatic.com/firebasejs/9.0.0-beta.7/firebase-app.js";var i=function(t,e){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)};var o=function(t){function e(n,r,i){var o=t.call(this,r)||this;return o.code=n,o.customData=i,o.name="FirebaseError",Object.setPrototypeOf(o,e.prototype),Error.captureStackTrace&&Error.captureStackTrace(o,s.prototype.create),o}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(e,t),e}(Error),s=function(){function t(t,e,n){this.service=t,this.serviceName=e,this.errors=n}return t.prototype.create=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=e[0]||{},i=this.service+"/"+t,s=this.errors[t],c=s?a(s,r):"Error",u=this.serviceName+": "+c+" ("+i+").",l=new o(i,u,r);return l},t}();function a(t,e){return t.replace(c,(function(t,n){var r=e[n];return null!=r?String(r):"<"+n+"?>"}))}var c=/\{\$([^}]+)}/g;function u(t){return t&&t._delegate?t._delegate:t}var l=function(){function t(t,e,n){this.name=t,this.instanceFactory=e,this.type=n,this.multipleInstances=!1,this.serviceProps={},this.instantiationMode="LAZY",this.onInstanceCreated=null}return t.prototype.setInstantiationMode=function(t){return this.instantiationMode=t,this},t.prototype.setMultipleInstances=function(t){return this.multipleInstances=t,this},t.prototype.setServiceProps=function(t){return this.serviceProps=t,this},t.prototype.setInstanceCreatedCallback=function(t){return this.onInstanceCreated=t,this},t}();function h(t,e){const n={};for(const r in t)t.hasOwnProperty(r)&&(n[r]=e(t[r]));return n}function p(t){if(null==t)return null;if(t instanceof Number&&(t=t.valueOf()),"number"==typeof t&&isFinite(t))return t;if(!0===t||!1===t)return t;if("[object String]"===Object.prototype.toString.call(t))return t;if(t instanceof Date)return t.toISOString();if(Array.isArray(t))return t.map((t=>p(t)));if("function"==typeof t||"object"==typeof t)return h(t,(t=>p(t)));throw new Error("Data cannot be encoded in JSON: "+t)}function f(t){if(null==t)return t;if(t["@type"])switch(t["@type"]){case"type.googleapis.com/google.protobuf.Int64Value":case"type.googleapis.com/google.protobuf.UInt64Value":{const e=Number(t.value);if(isNaN(e))throw new Error("Data cannot be decoded from JSON: "+t);return e}default:throw new Error("Data cannot be decoded from JSON: "+t)}return Array.isArray(t)?t.map((t=>f(t))):"function"==typeof t||"object"==typeof t?h(t,(t=>f(t))):t}const d={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 o{constructor(t,e,n){super(`functions-exp/${t}`,e||""),this.details=n}}class m{constructor(t,e,n){this.auth=null,this.messaging=null,this.appCheck=null,this.auth=t.getImmediate({optional:!0}),this.messaging=e.getImmediate({optional:!0}),this.auth||t.get().then((t=>this.auth=t),(()=>{})),this.messaging||e.get().then((t=>this.messaging=t),(()=>{})),this.appCheck||n.get().then((t=>this.appCheck=t),(()=>{}))}async getAuthToken(){if(this.auth)try{const t=await this.auth.getToken();return null==t?void 0:t.accessToken}catch(t){return}}async getMessagingToken(){if(this.messaging&&"Notification"in self&&"granted"===Notification.permission)try{return await this.messaging.getToken()}catch(t){return}}async getAppCheckToken(){if(this.appCheck){return(await this.appCheck.getToken()).token}return null}async getContext(){return{authToken:await this.getAuthToken(),messagingToken:await this.getMessagingToken(),appCheckToken:await this.getAppCheckToken()}}}function y(t){return new Promise(((e,n)=>{setTimeout((()=>{n(new g("deadline-exceeded","deadline-exceeded"))}),t)}))}class w{constructor(t,e,n,r,i="us-central1",o){this.app=t,this.fetchImpl=o,this.emulatorOrigin=null,this.contextProvider=new m(e,n,r),this.cancelAllRequests=new Promise((t=>{this.deleteService=()=>Promise.resolve(t())}));try{const t=new URL(i);this.customDomain=t.origin,this.region="us-central1"}catch(t){this.customDomain=null,this.region=i}}_delete(){return this.deleteService()}_url(t){const e=this.app.options.projectId;if(null!==this.emulatorOrigin){return`${this.emulatorOrigin}/${e}/${this.region}/${t}`}return null!==this.customDomain?`${this.customDomain}/${t}`:`https://${this.region}-${e}.cloudfunctions.net/${t}`}}function k(t,e,n){return r=>async function(t,e,n,r){const i=t._url(e),o={data:n=p(n)},s={},a=await t.contextProvider.getContext();a.authToken&&(s.Authorization="Bearer "+a.authToken);a.messagingToken&&(s["Firebase-Instance-ID-Token"]=a.messagingToken);null!==a.appCheckToken&&(s["X-Firebase-AppCheck"]=a.appCheckToken);const c=r.timeout||7e4,u=await Promise.race([T(i,o,s,t.fetchImpl),y(c),t.cancelAllRequests]);if(!u)throw new g("cancelled","Firebase Functions instance was deleted.");const l=function(t,e){let n,r=function(t){if(t>=200&&t<300)return"ok";switch(t){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"}(t),i=r;try{const t=e&&e.error;if(t){const e=t.status;if("string"==typeof e){if(!d[e])return new g("internal","internal");r=d[e],i=e}const o=t.message;"string"==typeof o&&(i=o),n=t.details,void 0!==n&&(n=f(n))}}catch(t){}return"ok"===r?null:new g(r,i,n)}(u.status,u.json);if(l)throw l;if(!u.json)throw new g("internal","Response is not valid JSON object.");let h=u.json.data;void 0===h&&(h=u.json.result);if(void 0===h)throw new g("internal","Response is missing data field.");return{data:f(h)}}(t,e,r,n||{})}async function T(t,e,n,r){let i;n["Content-Type"]="application/json";try{i=await r(t,{method:"POST",body:JSON.stringify(e),headers:n})}catch(t){return{status:0,json:null}}let o=null;try{o=await i.json()}catch(t){}return{status:i.status,json:o}}function v(n=t(),r="us-central1"){return e(u(n),"functions-exp").getImmediate({identifier:r})}function E(t,e,n){!function(t,e,n){t.emulatorOrigin=`http://${e}:${n}`}(u(t),e,n)}function I(t,e,n){return k(u(t),e,n)}var N;N=fetch.bind(self),r(new l("functions-exp",((t,{instanceIdentifier:e})=>{const n=t.getProvider("app-exp").getImmediate(),r=t.getProvider("auth-internal"),i=t.getProvider("messaging"),o=t.getProvider("app-check-internal");return new w(n,r,i,o,e,N)}),"PUBLIC").setMultipleInstances(!0)),n("@firebase/functions-exp","0.0.900-exp.6ef484a04");export{E as connectFunctionsEmulator,v as getFunctions,I as httpsCallable}; //# sourceMappingURL=firebase-functions.js.map