UNPKG

firebase

Version:

Firebase JavaScript library for web and Node.js

5 lines (4 loc) • 21.2 kB
!function(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(ge,ye){"use strict";try{!function(){function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t=e(ge),n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(e,t)};function a(e,t){for(var r=0,n=t.length,o=e.length;r<n;r++,o++)e[o]=t[r];return e}function s(e){try{return p.decodeString(e,!0)}catch(e){console.error("base64Decode failed: ",e)}return null}var p={byteToCharMap_:null,charToByteMap_:null,byteToCharMapWebSafe_:null,charToByteMapWebSafe_:null,ENCODED_VALS_BASE:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",get ENCODED_VALS(){return this.ENCODED_VALS_BASE+"+/="},get ENCODED_VALS_WEBSAFE(){return this.ENCODED_VALS_BASE+"-_."},HAS_NATIVE_SUPPORT:"function"==typeof atob,encodeByteArray:function(e,t){if(!Array.isArray(e))throw Error("encodeByteArray takes an array as a parameter");this.init_();for(var r=t?this.byteToCharMapWebSafe_:this.byteToCharMap_,n=[],o=0;o<e.length;o+=3){var i=e[o],a=o+1<e.length,s=a?e[o+1]:0,c=o+2<e.length,p=c?e[o+2]:0,l=(15&s)<<2|p>>6,p=63&p;c||(p=64,a||(l=64)),n.push(r[i>>2],r[(3&i)<<4|s>>4],r[l],r[p])}return n.join("")},encodeString:function(e,t){return this.HAS_NATIVE_SUPPORT&&!t?btoa(e):this.encodeByteArray(function(e){for(var t=[],r=0,n=0;n<e.length;n++){var o=e.charCodeAt(n);o<128?t[r++]=o:(o<2048?t[r++]=o>>6|192:(55296==(64512&o)&&n+1<e.length&&56320==(64512&e.charCodeAt(n+1))?(o=65536+((1023&o)<<10)+(1023&e.charCodeAt(++n)),t[r++]=o>>18|240,t[r++]=o>>12&63|128):t[r++]=o>>12|224,t[r++]=o>>6&63|128),t[r++]=63&o|128)}return t}(e),t)},decodeString:function(e,t){return this.HAS_NATIVE_SUPPORT&&!t?atob(e):function(e){for(var t=[],r=0,n=0;r<e.length;){var o,i,a,s=e[r++];s<128?t[n++]=String.fromCharCode(s):191<s&&s<224?(i=e[r++],t[n++]=String.fromCharCode((31&s)<<6|63&i)):239<s&&s<365?(o=((7&s)<<18|(63&(i=e[r++]))<<12|(63&(a=e[r++]))<<6|63&e[r++])-65536,t[n++]=String.fromCharCode(55296+(o>>10)),t[n++]=String.fromCharCode(56320+(1023&o))):(i=e[r++],a=e[r++],t[n++]=String.fromCharCode((15&s)<<12|(63&i)<<6|63&a))}return t.join("")}(this.decodeStringToByteArray(e,t))},decodeStringToByteArray:function(e,t){this.init_();for(var r=t?this.charToByteMapWebSafe_:this.charToByteMap_,n=[],o=0;o<e.length;){var i=r[e.charAt(o++)],a=o<e.length?r[e.charAt(o)]:0,s=++o<e.length?r[e.charAt(o)]:64,c=++o<e.length?r[e.charAt(o)]:64;if(++o,null==i||null==a||null==s||null==c)throw Error();n.push(i<<2|a>>4),64!==s&&(n.push(a<<4&240|s>>2),64!==c&&n.push(s<<6&192|c))}return n},init_:function(){if(!this.byteToCharMap_){this.byteToCharMap_={},this.charToByteMap_={},this.byteToCharMapWebSafe_={},this.charToByteMapWebSafe_={};for(var e=0;e<this.ENCODED_VALS.length;e++)this.byteToCharMap_[e]=this.ENCODED_VALS.charAt(e),this.charToByteMap_[this.byteToCharMap_[e]]=e,this.byteToCharMapWebSafe_[e]=this.ENCODED_VALS_WEBSAFE.charAt(e),(this.charToByteMapWebSafe_[this.byteToCharMapWebSafe_[e]]=e)>=this.ENCODED_VALS_BASE.length&&(this.charToByteMap_[this.ENCODED_VALS_WEBSAFE.charAt(e)]=e,this.charToByteMapWebSafe_[this.ENCODED_VALS.charAt(e)]=e)}}},c=(r.prototype.wrapCallback=function(r){var n=this;return function(e,t){e?n.reject(e):n.resolve(t),"function"==typeof r&&(n.promise.catch(function(){}),1===r.length?r(e):r(e,t))}},r);function r(){var r=this;this.reject=function(){},this.resolve=function(){},this.promise=new Promise(function(e,t){r.resolve=e,r.reject=t})}function o(){return"indexedDB"in self&&null!=indexedDB}var i,l="FirebaseError",h=(function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}(u,i=Error),u);function u(e,t,r){t=i.call(this,t)||this;return t.code=e,t.customData=r,t.name=l,Object.setPrototypeOf(t,u.prototype),Error.captureStackTrace&&Error.captureStackTrace(t,f.prototype.create),t}var f=(d.prototype.create=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];var n,o=t[0]||{},i=this.service+"/"+e,e=this.errors[e],e=e?(n=o,e.replace(g,function(e,t){var r=n[t];return null!=r?String(r):"<"+t+"?>"})):"Error",e=this.serviceName+": "+e+" ("+i+").";return new h(i,e,o)},d);function d(e,t,r){this.service=e,this.serviceName=t,this.errors=r}var g=/\{\$([^}]+)}/g;function y(e){return JSON.parse(e)}function v(e){return"object"==typeof(e=function(e){var t={},r={},n={},o="";try{var i=e.split("."),t=y(s(i[0])||""),r=y(s(i[1])||""),o=i[2],n=r.d||{};delete r.d}catch(e){}return{header:t,claims:r,data:n,signature:o}}(e).claims)&&e.hasOwnProperty("iat")?e.iat:null}var b,E=(_.prototype.setInstantiationMode=function(e){return this.instantiationMode=e,this},_.prototype.setMultipleInstances=function(e){return this.multipleInstances=e,this},_.prototype.setServiceProps=function(e){return this.serviceProps=e,this},_.prototype.setInstanceCreatedCallback=function(e){return this.onInstanceCreated=e,this},_);function _(e,t,r){this.name=e,this.instanceFactory=t,this.type=r,this.multipleInstances=!1,this.serviceProps={},this.instantiationMode="LAZY",this.onInstanceCreated=null}(T=b=b||{})[T.DEBUG=0]="DEBUG",T[T.VERBOSE=1]="VERBOSE",T[T.INFO=2]="INFO",T[T.WARN=3]="WARN",T[T.ERROR=4]="ERROR",T[T.SILENT=5]="SILENT";function m(e,t){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];if(!(t<e.logLevel)){var o=(new Date).toISOString(),i=A[t];if(!i)throw new Error("Attempted to log a message with an invalid logType (value: "+t+")");console[i].apply(console,a(["["+o+"] "+e.name+":"],r))}}var k={debug:b.DEBUG,verbose:b.VERBOSE,info:b.INFO,warn:b.WARN,error:b.ERROR,silent:b.SILENT},w=b.INFO,A=((T={})[b.DEBUG]="log",T[b.VERBOSE]="log",T[b.INFO]="info",T[b.WARN]="warn",T[b.ERROR]="error",T),T=(Object.defineProperty(O.prototype,"logLevel",{get:function(){return this._logLevel},set:function(e){if(!(e in b))throw new TypeError('Invalid value "'+e+'" assigned to `logLevel`');this._logLevel=e},enumerable:!1,configurable:!0}),O.prototype.setLogLevel=function(e){this._logLevel="string"==typeof e?k[e]:e},Object.defineProperty(O.prototype,"logHandler",{get:function(){return this._logHandler},set:function(e){if("function"!=typeof e)throw new TypeError("Value assigned to `logHandler` must be a function");this._logHandler=e},enumerable:!1,configurable:!0}),Object.defineProperty(O.prototype,"userLogHandler",{get:function(){return this._userLogHandler},set:function(e){this._userLogHandler=e},enumerable:!1,configurable:!0}),O.prototype.debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._userLogHandler&&this._userLogHandler.apply(this,a([this,b.DEBUG],e)),this._logHandler.apply(this,a([this,b.DEBUG],e))},O.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._userLogHandler&&this._userLogHandler.apply(this,a([this,b.VERBOSE],e)),this._logHandler.apply(this,a([this,b.VERBOSE],e))},O.prototype.info=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._userLogHandler&&this._userLogHandler.apply(this,a([this,b.INFO],e)),this._logHandler.apply(this,a([this,b.INFO],e))},O.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._userLogHandler&&this._userLogHandler.apply(this,a([this,b.WARN],e)),this._logHandler.apply(this,a([this,b.WARN],e))},O.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._userLogHandler&&this._userLogHandler.apply(this,a([this,b.ERROR],e)),this._logHandler.apply(this,a([this,b.ERROR],e))},O);function O(e){this.name=e,this._logLevel=w,this._logHandler=m,this._userLogHandler=null}const C=new Map,S={activated:!1,tokenObservers:[]},R={enabled:!1};function I(e){return C.get(e)||S}function P(e,t){C.set(e,t)}const N="https://content-firebaseappcheck.googleapis.com/v1beta",x="exchangeDebugToken",L={OFFSET_DURATION:3e5,RETRIAL_MIN_WAIT:3e4,RETRIAL_MAX_WAIT:96e4};class B{constructor(e,t,r,n,o){if(this.operation=e,this.retryPolicy=t,this.getWaitDuration=r,this.lowerBound=n,this.upperBound=o,this.pending=null,o<(this.nextErrorWaitInterval=n))throw new Error("Proactive refresh lower bound greater than upper bound!")}start(){this.nextErrorWaitInterval=this.lowerBound,this.process(!0).catch(()=>{})}stop(){this.pending&&(this.pending.reject("cancelled"),this.pending=null)}isRunning(){return!!this.pending}async process(e){this.stop();try{this.pending=new c,t=this.getNextRun(e),await new Promise(e=>{setTimeout(e,t)}),this.pending.resolve(),await this.pending.promise,this.pending=new c,await this.operation(),this.pending.resolve(),await this.pending.promise,this.process(!0).catch(()=>{})}catch(e){this.retryPolicy(e)?this.process(!1).catch(()=>{}):this.stop()}var t}getNextRun(e){if(e)return this.nextErrorWaitInterval=this.lowerBound,this.getWaitDuration();e=this.nextErrorWaitInterval;return this.nextErrorWaitInterval*=2,this.nextErrorWaitInterval>this.upperBound&&(this.nextErrorWaitInterval=this.upperBound),e}}const M=new f("appCheck","AppCheck",{"already-initialized":"You have already called initializeAppCheck() for FirebaseApp {$appName} with different options. To avoid this error, call initializeAppCheck() with the same options as when it was originally called. This will return the already initialized instance.","use-before-activation":"App Check is being used before initializeAppCheck() is called for FirebaseApp {$appName}. Call initializeAppCheck() before instantiating other Firebase services.","fetch-network-error":"Fetch failed to connect to a network. Check Internet connection. Original error: {$originalErrorMessage}.","fetch-parse-error":"Fetch client could not parse response. Original error: {$originalErrorMessage}.","fetch-status-error":"Fetch server returned an HTTP error status. HTTP status: {$httpStatus}.","storage-open":"Error thrown when opening storage. Original error: {$originalErrorMessage}.","storage-get":"Error thrown when reading from storage. Original error: {$originalErrorMessage}.","storage-set":"Error thrown when writing to storage. Original error: {$originalErrorMessage}.","recaptcha-error":"ReCAPTCHA error."});function j(){return self.grecaptcha}function D(e){if(!I(e).activated)throw M.create("use-before-activation",{appName:e.name})}async function H({url:e,body:t},r){const n={"Content-Type":"application/json"},o=r.getImmediate({optional:!0});o&&(n["X-Firebase-Client"]=o.getPlatformInfoString());t={method:"POST",body:JSON.stringify(t),headers:n};let i;try{i=await fetch(e,t)}catch(e){throw M.create("fetch-network-error",{originalErrorMessage:e.message})}if(200!==i.status)throw M.create("fetch-status-error",{httpStatus:i.status});let a;try{a=await i.json()}catch(e){throw M.create("fetch-parse-error",{originalErrorMessage:e.message})}e=a.ttl.match(/^([\d.]+)(s)$/);if(!e||!e[2]||isNaN(Number(e[1])))throw M.create("fetch-parse-error",{originalErrorMessage:"ttl field (timeToLive) is not in standard Protobuf Duration "+`format: ${a.ttl}`});t=1e3*Number(e[1]),e=Date.now();return{token:a.attestationToken,expireTimeMillis:e+t,issuedAtTimeMillis:e}}const W="firebase-app-check-database",F=1,$="firebase-app-check-store",V="debug-token";let U=null;function K(){return U||(U=new Promise((t,r)=>{try{const e=indexedDB.open(W,F);e.onsuccess=e=>{t(e.target.result)},e.onerror=e=>{r(M.create("storage-open",{originalErrorMessage:null===(e=e.target.error)||void 0===e?void 0:e.message}))},e.onupgradeneeded=e=>{const t=e.target.result;0===e.oldVersion&&t.createObjectStore($,{keyPath:"compositeKey"})}}catch(e){r(M.create("storage-open",{originalErrorMessage:e.message}))}}),U)}async function z(e,t){const r=await K(),n=r.transaction($,"readwrite"),o=n.objectStore($),i=o.put({compositeKey:e,value:t});return new Promise((t,r)=>{i.onsuccess=e=>{t()},n.onerror=e=>{r(M.create("storage-set",{originalErrorMessage:null===(e=e.target.error)||void 0===e?void 0:e.message}))}})}async function G(e){const t=await K(),n=t.transaction($,"readonly"),r=n.objectStore($),o=r.get(e);return new Promise((t,r)=>{o.onsuccess=e=>{e=e.target.result;t(e?e.value:void 0)},n.onerror=e=>{r(M.create("storage-get",{originalErrorMessage:null===(e=e.target.error)||void 0===e?void 0:e.message}))}})}function X(e){return`${e.options.appId}-${e.name}`}const q=new T("@firebase/app-check");async function J(t){if(o()){let e=void 0;try{e=await G(X(t))}catch(e){q.warn(`Failed to read token from IndexedDB. Error: ${e}`)}return e}}function Y(e,t){return o()?z(X(e),t).catch(e=>{q.warn(`Failed to write token to IndexedDB. Error: ${e}`)}):Promise.resolve()}async function Z(){let e=void 0;try{e=await G(V)}catch(e){}if(e)return e;var t,r="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0,r="x"===e?t:3&t|8;return r.toString(16)});return t=r,z(V,t).catch(e=>q.warn(`Failed to persist debug token to IndexedDB. Error: ${e}`)),console.log(`App Check debug token: ${r}. You will need to add it to your app's App Check settings in the Firebase console for it to work`),r}const Q={error:"UNKNOWN_ERROR"};async function ee(e,t=!1){var r,n=e.app;D(n);const o=I(n);let i=o.token,a=void 0;if(i||(r=await o.cachedTokenPromise)&&oe(r)&&(i=r,P(n,Object.assign(Object.assign({},o),{token:i})),ne(n,{token:i.token})),!t&&i&&oe(i))return{token:i.token};if(R.enabled){var s=await H(function(e,t){var{projectId:r,appId:n,apiKey:e}=e.options;return{url:`${N}/projects/${r}/apps/${n}:${x}?key=${e}`,body:{debug_token:t}}}(n,await async function(){var e=R;if(e.enabled&&e.token)return e.token.promise;throw Error(` Can't get debug token in production mode. `)}()),e.platformLoggerProvider);return await Y(n,s),P(n,Object.assign(Object.assign({},o),{token:s})),{token:s.token}}try{i=await o.provider.getToken()}catch(e){q.error(e),a=e}let c;return i?(c={token:i.token},P(n,Object.assign(Object.assign({},o),{token:i})),await Y(n,i)):c=(s=a,{token:function(e){return p.encodeString(JSON.stringify(e),!1)}(Q),error:s}),ne(n,c),c}function te(e,t,r,n){var{app:o}=e;const i=I(o);t={next:r,error:n,type:t};const a=Object.assign(Object.assign({},i),{tokenObservers:[...i.tokenObservers,t]});if(a.tokenRefresher||(e=function(r){const{app:n}=r;return new B(async()=>{var e=I(n);let t;if(t=e.token?await ee(r,!0):await ee(r),t.error)throw t.error},()=>!0,()=>{var e=I(n);if(e.token){var t=e.token.issuedAtTimeMillis+.5*(e.token.expireTimeMillis-e.token.issuedAtTimeMillis)+3e5,e=e.token.expireTimeMillis-3e5,t=Math.min(t,e);return Math.max(0,t-Date.now())}return 0},L.RETRIAL_MIN_WAIT,L.RETRIAL_MAX_WAIT)}(e),a.tokenRefresher=e),!a.tokenRefresher.isRunning()&&i.isTokenAutoRefreshEnabled&&a.tokenRefresher.start(),i.token&&oe(i.token)){const s=i.token;Promise.resolve().then(()=>r({token:s.token})).catch(()=>{})}else null==i.token&&i.cachedTokenPromise.then(e=>{e&&oe(e)&&r({token:e.token})}).catch(()=>{});P(o,a)}function re(e,t){const r=I(e);var n=r.tokenObservers.filter(e=>e.next!==t);0===n.length&&r.tokenRefresher&&r.tokenRefresher.isRunning()&&r.tokenRefresher.stop(),P(e,Object.assign(Object.assign({},r),{tokenObservers:n}))}function ne(e,t){for(const r of I(e).tokenObservers)try{"EXTERNAL"===r.type&&null!=t.error?r.error(t.error):r.next(t)}catch(e){}}function oe(e){return 0<e.expireTimeMillis-Date.now()}class ie{constructor(e,t){this.app=e,this.platformLoggerProvider=t}_delete(){var{tokenObservers:e}=I(this.app);for(const t of e)re(this.app,t.next);return Promise.resolve()}}const ae="https://www.google.com/recaptcha/api.js";function se(t,r){var e=I(t);const n=new c;P(t,Object.assign(Object.assign({},e),{reCAPTCHAState:{initialized:n}}));const o=`fire_app_check_${t.name}`,i=document.createElement("div");i.id=o,i.style.display="none",document.body.appendChild(i);const a=j();return a?a.ready(()=>{ce(t,r,a,o),n.resolve(a)}):function(e){const t=document.createElement("script");t.src=`${ae}`,t.onload=e,document.head.appendChild(t)}(()=>{const e=j();if(!e)throw new Error("no recaptcha");e.ready(()=>{ce(t,r,e,o),n.resolve(e)})}),n.promise}function ce(e,t,r,n){n=r.render(n,{sitekey:t,size:"invisible"}),t=I(e);P(e,Object.assign(Object.assign({},t),{reCAPTCHAState:Object.assign(Object.assign({},t.reCAPTCHAState),{widgetId:n})}))}class pe{constructor(e){this._siteKey=e}async getToken(){if(!this._app||!this._platformLoggerProvider)throw M.create("use-before-activation",{appName:""});var e=await async function(n){D(n);const o=await I(n).reCAPTCHAState.initialized.promise;return new Promise((e,t)=>{const r=I(n).reCAPTCHAState;o.ready(()=>{e(o.execute(r.widgetId,{action:"fire_app_check"}))})})}(this._app).catch(e=>{throw M.create("recaptcha-error")});return H(function(e,t){var{projectId:r,appId:n,apiKey:e}=e.options;return{url:`${N}/projects/${r}/apps/${n}:exchangeRecaptchaToken?key=${e}`,body:{recaptcha_token:t}}}(this._app,e),this._platformLoggerProvider)}initialize(e){this._app=e,this._platformLoggerProvider=ye._getProvider(e,"platform-logger"),se(e,this._siteKey).catch(()=>{})}isEqual(e){return e instanceof pe&&this._siteKey===e._siteKey}}class le{constructor(e){this._customProviderOptions=e}async getToken(){if(!this._app)throw M.create("use-before-activation",{appName:""});var e=await this._customProviderOptions.getToken(),t=v(e.token),t=null!==t&&t<Date.now()&&0<t?1e3*t:Date.now();return Object.assign(Object.assign({},e),{issuedAtTimeMillis:t})}initialize(e){this._app=e}isEqual(e){return e instanceof le&&this._customProviderOptions.getToken.toString()===e._customProviderOptions.getToken.toString()}}function he(e=ye.getApp(),t){var r;e=(r=e)&&r._delegate?r._delegate:r;const n=ye._getProvider(e,"app-check");if(n.isInitialized()){var o=n.getImmediate();const i=n.getOptions();if(i.isTokenAutoRefreshEnabled===t.isTokenAutoRefreshEnabled&&i.provider.isEqual(t.provider))return o;throw M.create("already-initialized",{appName:e.name})}o=n.initialize({options:t});return function(t,e,r){const n=I(t),o=Object.assign(Object.assign({},n),{activated:!0});o.provider=e,o.cachedTokenPromise=J(t).then(e=>(e&&oe(e)&&P(t,Object.assign(Object.assign({},I(t)),{token:e})),e)),o.isTokenAutoRefreshEnabled=void 0===r?t.automaticDataCollectionEnabled:r,P(t,o),o.provider.initialize(t)}(e,t.provider,t.isTokenAutoRefreshEnabled),o}const ue="app-check-internal";ye._registerComponent(new E("app-check",e=>{var t=e.getProvider("app").getImmediate(),e=e.getProvider("platform-logger");return t=t,e=e,new ie(t,e)},"PUBLIC").setInstantiationMode("EXPLICIT").setInstanceCreatedCallback((e,t,r)=>{e.getProvider(ue).initialize()})),ye._registerComponent(new E(ue,e=>{var t,e=e.getProvider("app-check").getImmediate();return t=e,{getToken:e=>ee(t,e),addTokenListener:e=>te(t,"INTERNAL",e),removeTokenListener:e=>re(t.app,e)}},"PUBLIC").setInstantiationMode("EXPLICIT")),ye.registerVersion("@firebase/app-check","0.4.0"),function(){var e=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("Unable to locate global object.")}();if("string"==typeof e.FIREBASE_APPCHECK_DEBUG_TOKEN||!0===e.FIREBASE_APPCHECK_DEBUG_TOKEN){const t=R;t.enabled=!0;const r=new c;t.token=r,"string"==typeof e.FIREBASE_APPCHECK_DEBUG_TOKEN?r.resolve(e.FIREBASE_APPCHECK_DEBUG_TOKEN):r.resolve(Z())}}();const fe=new f("appCheck","AppCheck",{"use-before-activation":"App Check is being used before activate() is called for FirebaseApp {$appName}. Call activate() before instantiating other Firebase services."});class de{constructor(e){this.app=e}activate(e,t){let r;r="string"==typeof e?new pe(e):new le({getToken:e.getToken}),this._delegate=he(this.app,{provider:r,isTokenAutoRefreshEnabled:t})}setTokenAutoRefreshEnabled(e){if(!this._delegate)throw fe.create("use-before-activation",{appName:this.app.name});!function(e,t){const r=I(e=e.app);r.tokenRefresher&&(!0===t?r.tokenRefresher.start():r.tokenRefresher.stop()),P(e,Object.assign(Object.assign({},r),{isTokenAutoRefreshEnabled:t}))}(this._delegate,e)}getToken(e){if(!this._delegate)throw fe.create("use-before-activation",{appName:this.app.name});return async function(e,t){if((t=await ee(e,t)).error)throw t.error;return{token:t.token}}(this._delegate,e)}onTokenChanged(e,t,r){if(!this._delegate)throw fe.create("use-before-activation",{appName:this.app.name});return function(e,t,r){let n=()=>{},o=()=>{};return n=null!=t.next?t.next.bind(t):t,null!=t.error?o=t.error.bind(t):r&&(o=r),te(e,"EXTERNAL",n,o),()=>re(e.app,n)}(this._delegate,e,t)}}t.default.INTERNAL.registerComponent(new E("appCheck-compat",e=>{e=e.getProvider("app-compat").getImmediate();return new de(e)},"PUBLIC")),t.default.registerVersion("@firebase/app-check-compat","0.1.0")}.apply(this,arguments)}catch(e){throw console.error(e),new Error("Cannot instantiate firebase-app-check-compat.js - be sure to load firebase-app.js first.")}}); //# sourceMappingURL=firebase-app-check-compat.js.map