@entropic-bond/firebase 1.13.3 → 1.13.4
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.
|
@@ -3675,3 +3675,4 @@ Content-Type: `+u.contentType+`\r
|
|
|
3675
3675
|
* See the License for the specific language governing permissions and
|
|
3676
3676
|
* limitations under the License.
|
|
3677
3677
|
*/function jI(t=zr(),e=Ja){const r=Mn(x(t),Xa).getImmediate({identifier:e}),s=Ti("functions");return s&&Cf(r,...s),r}function Cf(t,e,n){NI(x(t),e,n)}function $I(t,e,n){return OI(x(t),e,n)}BI(fetch.bind(self));const Le=class Le{static setFirebaseConfig(e){Le._firebaseConfig=e}static useEmulator(e){this._emulatorConfig={...Le.defaultEmulatorConfig,emulate:!0,...e}}static get emulator(){return this._emulatorConfig}constructor(){if(!Le._firebaseConfig)throw new Error("You should set a firebase config object before using Firebase");this._firebaseApp=pc(Le._firebaseConfig)}static get instance(){return this._instance||(this._instance=new Le)}firestore(){return Qy(this._firebaseApp)}storage(){return wI(this._firebaseApp)}auth(){return aw(this._firebaseApp)}functions(){return jI(this._firebaseApp,Le._region)}static setRegion(e){this._region=e}};Le.defaultEmulatorConfig={host:"localhost",firestorePort:8080,storagePort:9199,authPort:9099,functionsPort:5001,emulate:!1},Le._emulatorConfig=Le.defaultEmulatorConfig;let b=Le;class qI extends Js{constructor(e){var n;if(super(),this._lastLimit=0,e&&b.useEmulator(e),(n=b.emulator)!=null&&n.emulate){const{host:r,firestorePort:s}=b.emulator;Ih(b.instance.firestore(),r,s)}}findById(e,n){const r=b.instance.firestore();return new Promise(async s=>{try{const i=await _v(ca(r,n,e));s(i.data())}catch(i){return console.log(i),null}})}save(e){const n=b.instance.firestore(),r=Av(n);return Object.entries(e).forEach(([s,i])=>{i==null||i.forEach(o=>{const a=ca(n,s,o.id);r.set(a,o)})}),r.commit()}find(e,n){const r=this.queryObjectToQueryConstraints(e,n);return this.getFromQuery(r)}async count(e,n){const r=this.queryObjectToQueryConstraints(e,n);return(await Tv(r)).data().count}delete(e,n){const r=b.instance.firestore();return vv(ca(r,n,e))}next(e){if(!this._lastConstraints||!this._lastCollectionName)throw new Error("You should perform a query prior to using method next");const n=b.instance.firestore();this._lastLimit=e||this._lastLimit;const r=this._lastConstraints.nonFilterConstraints.concat(Vh(this._lastLimit),lv(this._lastDocRetrieved));return this.getFromQuery(Nh(Ah(n,this._lastCollectionName),...r))}queryObjectToQueryConstraints(e,n){var a;const r=b.instance.firestore(),s=[],i=[],o=[];return Js.toPropertyPathOperations(e.operations).forEach(c=>{const u=this.toFirebaseOperator(c.operator);c.aggregate?i.push(Oh(c.property,u,c.value)):s.push(Oh(c.property,u,c.value))}),(a=e.sort)!=null&&a.propertyName&&o.push(uv(e.sort.propertyName,e.sort.order)),this._lastConstraints={orConstraints:i,andConstraints:s,nonFilterConstraints:o},this._lastCollectionName=n,e.limit&&(this._lastLimit=e.limit,o.push(Vh(e.limit))),Nh(Ah(r,n),av(...i,cv(...s)),...o)}toFirebaseOperator(e){switch(e){case"==":case"!=":case"<":case"<=":case">":case">=":return e;case"contains":return"array-contains";case"containsAny":return"array-contains-any";default:return e}}getFromQuery(e){return new Promise(async n=>{const r=await yv(e);this._lastDocRetrieved=r.docs[r.docs.length-1],n(r.docs.map(s=>s.data()))})}}var zI=Object.defineProperty,HI=Object.getOwnPropertyDescriptor,WI=(t,e,n,r)=>{for(var s=r>1?void 0:r?HI(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(s=(r?o(e,n,s):o(s))||s);return r&&s&&zI(e,n,s),s};ve.FirebaseCloudStorage=class extends wn{constructor(e){var n;if(super(),e&&b.useEmulator(e),(n=b.emulator)!=null&&n.emulate){const{host:r,storagePort:s}=b.emulator;Af(b.instance.storage(),r,s)}}save(e,n,r){const s=b.instance.storage();return new Promise((i,o)=>{if(this._uploadTask=vI(Qa(s,e),n),r)var a=this._uploadTask.on("state_changed",c=>{r(c.bytesTransferred,c.totalBytes)},null,()=>a());this._uploadTask.then(()=>i(e)).catch(c=>o(c))})}getUrl(e){if(!e)return Promise.reject("needs a reference");const n=b.instance.storage();return EI(Qa(n,e))}uploadControl(){if(!this._uploadTask)throw new Error("You should call save() before uploadControl()");return{cancel:()=>{var e;return(e=this._uploadTask)==null?void 0:e.cancel()},pause:()=>{var e;return(e=this._uploadTask)==null?void 0:e.pause()},resume:()=>{var e;return(e=this._uploadTask)==null?void 0:e.resume()},onProgress:e=>{var n;return(n=this._uploadTask)==null?void 0:n.on("state_changed",r=>{e&&e(r.bytesTransferred,r.totalBytes)})}}}delete(e){const n=b.instance.storage();return TI(Qa(n,e))}},ve.FirebaseCloudStorage=WI([Hh("FirebaseCloudStorage",()=>new ve.FirebaseCloudStorage)],ve.FirebaseCloudStorage);const kf={twitter:()=>new Ve,facebook:()=>new We,google:()=>new Ge};class Za extends Wh{constructor(e){var n;if(super(),this.credentialProviders={},e&&b.useEmulator(e),(n=b.emulator)!=null&&n.emulate){const{host:r,authPort:s}=b.emulator;if(!r||!s)throw new Error("You should define a host and an auth emulator port to use the emulator");vd(b.instance.auth(),`http://${r}:${s}`)}this.registerCredentialProviders()}signUp(e){const{authProvider:n,verificationLink:r}=e;return n.slice(0,5)==="email"?new Promise(async(s,i)=>{try{const o=this.credentialProviders["email-sign-up"];if(!o)throw new Error(`The provider ${n} is not registered`);const a=await o(e);e.name&&await KE(a.user,{displayName:e.name}),r&&await Dd(a.user,{url:r}),s(await this.toUserCredentials(a.user))}catch(o){i({code:Zs(o.code.slice(5)),message:o.message})}}):this.login(e)}login(e){const{authProvider:n}=e;return new Promise(async(r,s)=>{try{const i=this.credentialProviders[n];if(!i)throw new Error(`The provider ${n} is not registered`);const o=await i(e);r(await this.toUserCredentials(o.user))}catch(i){s({code:i.code===400?"missingPassword":Zs(i.code.slice(5)),message:i.message})}})}logout(){return b.instance.auth().signOut()}resetEmailPassword(e){return new Promise(async(n,r)=>{try{await HE(b.instance.auth(),e),n()}catch(s){r({code:Zs(s.code.slice(5)),message:s.message})}})}resendVerificationEmail(e,n,r){return new Promise(async(s,i)=>{try{await kd(b.instance.auth(),e,n);const o=b.instance.auth().currentUser;if(!o){i({code:"userNotFound",message:"There is no logged in user"});return}await Dd(o,{url:r}),s()}catch(o){i({code:Zs(o.code.slice(5)),message:r})}})}refreshToken(){var e;return(e=b.instance.auth().currentUser)==null?void 0:e.getIdToken(!0)}onAuthStateChange(e){b.instance.auth().onAuthStateChanged(async n=>{e(n?await this.toUserCredentials(n):void 0)})}linkAdditionalProvider(e){const n=kf[e](),r=b.instance.auth().currentUser;if(!r)throw new Error("There is no logged in user");return qd(r,n)}unlinkProvider(e){const{currentUser:n}=b.instance.auth();if(!n)throw new Error("There is no logged in user");return n.providerData,BE(n,kf[e]().providerId)}async toUserCredentials(e){if(!e)throw new Error("The user in user credentials is not defined");const n=(await e.getIdTokenResult()).claims;return Za.convertCredentials(e,n)}static convertCredentials(e,n){return{id:e.uid,email:e.email??"",name:e.displayName??void 0,pictureUrl:e.photoURL??void 0,phoneNumber:e.phoneNumber??void 0,emailVerified:e.emailVerified,customData:{...n},lastLogin:Date.now(),creationDate:e.metadata.creationTime?new Date(e.metadata.creationTime).getTime():void 0}}registerCredentialProvider(e,n){this.credentialProviders[e]=n}registerCredentialProviders(){this.registerCredentialProvider("email-sign-up",e=>{if(!e.email||!e.password)throw new Error("Email and password are required");return WE(b.instance.auth(),e.email,e.password)}),this.registerCredentialProvider("email",e=>{if(!e.email||!e.password)throw new Error("Email and password are required");return kd(b.instance.auth(),e.email,e.password)}),this.registerCredentialProvider("google",()=>xa(b.instance.auth(),new Ge)),this.registerCredentialProvider("facebook",()=>xa(b.instance.auth(),new We)),this.registerCredentialProvider("twitter",()=>xa(b.instance.auth(),new Ve)),this.registerCredentialProvider("link-twitter",()=>{const e=b.instance.auth().currentUser;if(!e)throw new Error("There is no logged in user");return qd(e,new Ve)}),this.registerCredentialProvider("anonymous",()=>FE(b.instance.auth()))}}class GI{constructor(e,n){var r;if(e&&b.setRegion(e),n&&b.useEmulator(n),(r=b.emulator)!=null&&r.emulate){const{host:s,functionsPort:i}=b.emulator;Cf(b.instance.functions(),s,i)}}retrieveFunction(e){return $I(b.instance.functions(),e)}async callFunction(e,n){return(await e(n)).data}}ve.FirebaseAuth=Za,ve.FirebaseCloudFunctions=GI,ve.FirebaseDatasource=qI,ve.FirebaseHelper=b,Object.defineProperty(ve,Symbol.toStringTag,{value:"Module"})});
|
|
3678
|
+
//# sourceMappingURL=entropic-bond-firebase.umd.cjs.map
|