lombongo-api-client 0.0.7 → 0.0.8

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.
Files changed (2) hide show
  1. package/dist/esm/base.js +1 -1
  2. package/package.json +1 -1
package/dist/esm/base.js CHANGED
@@ -1 +1 @@
1
- import t from"axios";class s{constructor(t){this.client=t,this.endpoint="/accounts"}async createAoaAccount(){return this.client.request("post",this.endpoint,{currency:"aoa"},{})}async createEurAccount(){return this.client.request("post",this.endpoint,{currency:"eur"},{})}}class e{constructor(t){this.observers=[],this.authState={authenticated:!1},this.client=t}notifyObservers(){for(const t of this.observers)t(this.authState)}listObservers(){for(const t of this.observers)console.log(t)}onAuthStateChange(t){this.observers.push(t)}isAuthenticated(){return Boolean(this.client.token)}async createUser(t){const s=this.client.lombongoIdBaseUrl,e=await this.client.request("post","/users",t,{},s);return delete t.password,this.authState={authenticated:!0,user:t},this.notifyObservers(),e}async login(t){const s=this._loginFactory(t);return await s(t)}async _verifyToken(t){const s=this.client.lombongoIdBaseUrl;return this.client.request("post","/token",{token:t},{},s)}async _loginWithEmailAndPassword(t,s){const e=this.client.lombongoIdBaseUrl;return this.client.request("post","/users",{email:t,password:s},{},e)}async _loginWithUsernameAndPassword(t,s){const e=this.client.lombongoIdBaseUrl;return this.client.request("post","/users",{username:t,password:s},{},e)}_loginFactory(t){if(!("email"in t)&&!("username"in t))throw new Error("Login credentials must include either an email or a username.");return async t=>{if(t.email)return this._loginWithEmailAndPassword(t.email,t.password);if(t.username)return this._loginWithUsernameAndPassword(t.username,t.password);throw new Error("Invalid login credentials provided.")}}}class r{constructor({baseUrl:t,token:r,lombongoIdBaseUrl:n}){this.baseUrl=t,this.token=r,this.lombongoIdBaseUrl=n,this.auth=new e(this),this.accounts=new s(this)}static init(t){return r.instance?(t?.token&&(r.instance.token=t.token),t?.baseUrl&&(r.instance.baseUrl=t.baseUrl),t?.lombongoIdBaseUrl&&(r.instance.lombongoIdBaseUrl=t.lombongoIdBaseUrl),r.instance):(r.instance=new r(t),r.instance)}async request(s,e,r={},n={},i){const o=`${i||this.baseUrl}${e}`,a={...n,headers:{"Content-Type":"application/json",...this.token?{Authorization:`Bearer ${this.token}`}:{},...n.headers},method:s,url:o,...r&&{data:r}};return t(a)}setToken(t){this.token=t}}export{r as default};
1
+ import t from"axios";class s{constructor(t){this.client=t,this.endpoint="/accounts"}async createAoaAccount(){return this.client.request("post",this.endpoint,{currency:"aoa"},{})}async createEurAccount(){return this.client.request("post",this.endpoint,{currency:"eur"},{})}}class e{constructor(t){this.observers=[],this.authState={authenticated:!1},this.client=t}notifyObservers(){for(const t of this.observers)t(this.authState)}listObservers(){for(const t of this.observers)console.log(t)}onAuthStateChange(t){this.observers.push(t)}isAuthenticated(){return Boolean(this.client.token)}async createUser(t){const s=this.client.lombongoIdBaseUrl,e=await this.client.request("post","/users",t,{},s);return delete t.password,this.authState={authenticated:!0,user:t},this.notifyObservers(),e}async login(t){const s=this._loginFactory(t);return await s(t)}async _verifyToken(t){const s=this.client.lombongoIdBaseUrl;return this.client.request("post","/token",{token:t},{},s)}async _loginWithEmailAndPassword(t,s){const e=this.client.lombongoIdBaseUrl;return this.client.request("post","/users",{email:t,password:s},{},e)}async _loginWithUsernameAndPassword(t,s){const e=this.client.lombongoIdBaseUrl;return this.client.request("post","/users",{username:t,password:s},{},e)}_loginFactory(t){if(!("email"in t)&&!("username"in t))throw new Error("Login credentials must include either an email or a username.");return async t=>{if(t.email)return this._loginWithEmailAndPassword(t.email,t.password);if(t.username)return this._loginWithUsernameAndPassword(t.username,t.password);throw new Error("Invalid login credentials provided.")}}}class r{constructor({baseUrl:t,token:r,lombongoIdBaseUrl:n}){this.baseUrl=t,this.token=r,this.lombongoIdBaseUrl=n,this.auth=new e(this),this.accounts=new s(this)}static init(t){return r.instance?(t?.token&&(r.instance.token=t.token),t?.baseUrl&&(r.instance.baseUrl=t.baseUrl),t?.lombongoIdBaseUrl&&(r.instance.lombongoIdBaseUrl=t.lombongoIdBaseUrl),r.instance):(r.instance=new r(t),r.instance)}async request(s,e,r={},n={},i){const o=`${i||this.baseUrl}${e}`,a={...n,headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`,...n.headers},method:s,url:o,...r&&{data:r}};return t(a)}setToken(t){this.token=t}}export{r as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lombongo-api-client",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/esm/base.js",