fmode-ng 0.0.106 → 0.0.107

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.
@@ -5,6 +5,6 @@
5
5
  * 保留所有权利 All Rights Reserved.
6
6
  * /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/core/parse/fmode.user.mjs
7
7
  */
8
- import{FmodeObject}from"./fmode.object";export class FmodeUser extends FmodeObject{static{this._instance=null}static{this.instanceKey=()=>{if(!this._instance)throw new Error("FmodeParse not initialized before using User");return"FMODE/"+this._instance.appId+"/current"}}static bindInstance(e){this._instance=e}static get instance(){if(!this._instance)throw new Error("FmodeParse not initialized");return this._instance}get username(){return this.get("username")}set username(e){this.set("username",e)}get email(){return this.get("email")}set email(e){this.set("email",e)}get password(){return this.get("password")}set password(e){this.set("password",e)}constructor(e){super("_User"),e&&(this.id=e?.objectId,this.createdAt=new Date(e?.createdAt),this.updatedAt=new Date(e?.updatedAt),e.sessionToken&&(this.sessionToken=e.sessionToken,delete e.sessionToken),this.set(e))}static async logIn(e,s){const t=`${this.instance.serverURL}/login`,r=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json","X-Parse-Application-Id":this.instance.appId},body:JSON.stringify({username:e,password:s})}),n=await r.json();if(n.error)throw new Error(n.error);const o=new this({...n,username:e,password:s});return o._saveToCache(),o}static async become(e){const s=`${this.instance.serverURL}/users/me`;let t={"X-Parse-Session-Token":e,"X-Parse-Application-Id":this.instance.appId};console.log(s,t);const r=await fetch(s,{headers:t}),n=await r.json();if(n.error)throw new Error(n.error);const o=new this({...n,sessionToken:e});return o._saveToCache(),o}static async signUp(e,s,t={}){return new this({...t,username:e,password:s}).signUp()}static async logOut(){if(this.current())try{await fetch(`${this.instance.serverURL}/logout`,{method:"POST",headers:{"X-Parse-Session-Token":this.current().sessionToken,"X-Parse-Application-Id":this.instance.appId}})}finally{this._clearCurrentUser()}}static async requestPasswordReset(e){const s=`${this.instance.serverURL}/requestPasswordReset`,t=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json","X-Parse-Application-Id":this.instance.appId},body:JSON.stringify({email:e})}),r=await t.json();if(r.error)throw new Error(r.error)}static{this._currentUser=null}static current(){if(this._currentUser)return this._currentUser;try{const e=localStorage.getItem(this.instanceKey());if(!e)return null;const s=JSON.parse(e);if(!s.sessionToken)return null;console.log("restore",s);const t=new this(s);return this._currentUser=t,t}catch(e){return console.warn("Failed to restore user from cache",e),null}}static _clearCurrentUser(){this._currentUser=null,localStorage.removeItem(this.instanceKey())}async signUp(e){if(e&&this.set(e),!this.username)throw new Error("Username is required");if(!this.password)throw new Error("Password is required");const s=`${FmodeUser.instance.serverURL}/users`,t=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json","X-Parse-Application-Id":FmodeUser.instance.appId},body:JSON.stringify(this.toJSON())}),r=await t.json();if(r.error)throw new Error(r.error);return this.id=r.objectId,this.createdAt=new Date(r.createdAt),this.sessionToken=r.sessionToken,this._saveToCache(),this}async save(){const e=`${FmodeUser.instance.serverURL}/users/${this.id||this.data.objectId}`,s={"Content-Type":"application/json","X-Parse-Application-Id":FmodeUser.instance.appId,"X-Parse-Session-Token":this.sessionToken};console.log("headers",e,s);const t=this.toJSON();delete t.__type,delete t.objectId,delete t.className,delete t.sessionToken,delete t.username,delete t.createdAt,delete t.updatedAt,console.log("dataToSave",t);const r=await fetch(e,{method:"PUT",headers:s,body:JSON.stringify(t)}),n=await r.json();if(n.error)throw 209===n.code&&FmodeUser._clearCurrentUser(),new Error(n.error);return this.set("updatedAt",new Date(n.updatedAt)),this._saveToCache(),this}_saveToCache(){console.log("_saveToCache",this,FmodeUser.instanceKey()),this.sessionToken&&(FmodeUser._currentUser=this,localStorage.setItem(FmodeUser.instanceKey(),JSON.stringify(this.toJSONForCache())))}toJSONForCache(){return{...super.toJSON(),sessionToken:this.sessionToken}}async destroy(e){if(!this.id)throw new Error("Cannot destroy unsaved user");const s=`${FmodeUser.instance.serverURL}/users/${this.id}`,t={"X-Parse-Session-Token":this.sessionToken,"X-Parse-Application-Id":FmodeUser.instance.appId};e?.useMasterKey&&FmodeUser.instance.config.masterKey&&(t["X-Parse-Master-Key"]=FmodeUser.instance.config.masterKey);const r=await fetch(s,{method:"DELETE",headers:t});if(!r.ok){const e=await r.json();throw new Error(e.error||"Failed to delete user")}FmodeUser._clearCurrentUser()}}
8
+ import{FmodeObject}from"./fmode.object";export class FmodeUser extends FmodeObject{static{this._instance=null}static{this.instanceKey=()=>{if(!this._instance)throw new Error("FmodeParse not initialized before using User");return"FMODE/"+this._instance.appId+"/current"}}static bindInstance(e){this._instance=e}static get instance(){if(!this._instance)throw new Error("FmodeParse not initialized");return this._instance}get username(){return this.get("username")}set username(e){this.set("username",e)}get email(){return this.get("email")}set email(e){this.set("email",e)}get password(){return this.get("password")}set password(e){this.set("password",e)}constructor(e){super("_User"),e&&(this.id=e?.objectId,this.createdAt=new Date(e?.createdAt),this.updatedAt=new Date(e?.updatedAt),e.sessionToken&&(this.sessionToken=e.sessionToken,delete e.sessionToken),this.set(e))}static async logIn(e,s){const t=`${this.instance.serverURL}/login`,r=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json","X-Parse-Application-Id":this.instance.appId},body:JSON.stringify({username:e,password:s})}),n=await r.json();if(console.log("login result",n),n.error)throw new Error(n.error);const o=new this({...n,username:e,password:s});return console.log("login user",o),o._saveToCache(),o}static async become(e){const s=`${this.instance.serverURL}/users/me`;let t={"X-Parse-Session-Token":e,"X-Parse-Application-Id":this.instance.appId};console.log(s,t);const r=await fetch(s,{headers:t}),n=await r.json();if(n.error)throw new Error(n.error);const o=new this({...n,sessionToken:e});return o._saveToCache(),o}static async signUp(e,s,t={}){return new this({...t,username:e,password:s}).signUp()}static async logOut(){if(this.current())try{await fetch(`${this.instance.serverURL}/logout`,{method:"POST",headers:{"X-Parse-Session-Token":this.current().sessionToken,"X-Parse-Application-Id":this.instance.appId}})}finally{this._clearCurrentUser()}}static async requestPasswordReset(e){const s=`${this.instance.serverURL}/requestPasswordReset`,t=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json","X-Parse-Application-Id":this.instance.appId},body:JSON.stringify({email:e})}),r=await t.json();if(r.error)throw new Error(r.error)}static{this._currentUser=null}static current(){if(this._currentUser)return this._currentUser;try{const e=localStorage.getItem(this.instanceKey());if(!e)return null;const s=JSON.parse(e);if(!s.sessionToken)return null;console.log("restore",s);const t=new this(s);return this._currentUser=t,t}catch(e){return console.warn("Failed to restore user from cache",e),null}}static _clearCurrentUser(){this._currentUser=null,localStorage.removeItem(this.instanceKey())}async signUp(e){if(e&&this.set(e),!this.username)throw new Error("Username is required");if(!this.password)throw new Error("Password is required");const s=`${FmodeUser.instance.serverURL}/users`,t=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json","X-Parse-Application-Id":FmodeUser.instance.appId},body:JSON.stringify(this.toJSON())}),r=await t.json();if(r.error)throw new Error(r.error);return this.id=r.objectId,this.createdAt=new Date(r.createdAt),this.sessionToken=r.sessionToken,this._saveToCache(),this}async save(){const e=`${FmodeUser.instance.serverURL}/users/${this.id||this.data.objectId}`,s={"Content-Type":"application/json","X-Parse-Application-Id":FmodeUser.instance.appId,"X-Parse-Session-Token":this.sessionToken};console.log("headers",e,s);const t=this.toJSON();delete t.__type,delete t.objectId,delete t.className,delete t.sessionToken,delete t.username,delete t.createdAt,delete t.updatedAt,console.log("dataToSave",t);const r=await fetch(e,{method:"PUT",headers:s,body:JSON.stringify(t)}),n=await r.json();if(n.error)throw 209===n.code&&FmodeUser._clearCurrentUser(),new Error(n.error);return this.set("updatedAt",new Date(n.updatedAt)),this._saveToCache(),this}_saveToCache(){console.log("_saveToCache",this,this.sessionToken),console.log("_saveToCache",FmodeUser.instanceKey()),this.sessionToken&&(FmodeUser._currentUser=this,localStorage.setItem(FmodeUser.instanceKey(),JSON.stringify(this.toJSONForCache())))}toJSONForCache(){return{...super.toJSON(),sessionToken:this.sessionToken}}async destroy(e){if(!this.id)throw new Error("Cannot destroy unsaved user");const s=`${FmodeUser.instance.serverURL}/users/${this.id}`,t={"X-Parse-Session-Token":this.sessionToken,"X-Parse-Application-Id":FmodeUser.instance.appId};e?.useMasterKey&&FmodeUser.instance.config.masterKey&&(t["X-Parse-Master-Key"]=FmodeUser.instance.config.masterKey);const r=await fetch(s,{method:"DELETE",headers:t});if(!r.ok){const e=await r.json();throw new Error(e.error||"Failed to delete user")}FmodeUser._clearCurrentUser()}}
9
9
  var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9jb3JlL3BhcnNlL2Ztb2RlLnVzZXIubWpz`
10
10