lombongo-api-client 0.0.21 → 0.0.22

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 getAccounts(){return await this.client.request("get",this.endpoint)}async createAoaAccount(){return await this.client.request("post",this.endpoint,{currency:"aoa"},{})}async createEurAccount(){return await 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)}signOut(){delete this.client.token,this.authState.authenticated=!1,this.authState.user=void 0,this.authState.token=void 0,this.notifyObservers()}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,token:e.data.token},this.notifyObservers(),e}async login(t){const s=this._loginFactory(t);return await s(t)}async _verifyToken(t){const s=this.client.lombongoIdBaseUrl;return await this.client.request("post","/token",{token:t},{},s)}async _loginWithEmailAndPassword(t,s){const e=this.client.lombongoIdBaseUrl;return await this.client.request("post","/users",{email:t,password:s},{},e)}async _loginWithUsernameAndPassword(t,s){const e=this.client.lombongoIdBaseUrl;return await 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 i{constructor(t){this.client=t,this.endpoint="/payment-methods"}async getPaymentMethods(){return await this.client.request("get",this.endpoint)}async getPaymentMethodsByCurrency(t){const s=`${this.endpoint}/${t}`;return await this.client.request("get",s)}}class n{constructor({baseUrl:t,token:n,lombongoIdBaseUrl:r}){this.baseUrl=t,this.token=n,this.lombongoIdBaseUrl=r,this.auth=new e(this),this.accounts=new s(this),this.paymentMethods=new i(this)}static init(t){return n.instance?(t?.token&&(n.instance.token=t.token),t?.baseUrl&&(n.instance.baseUrl=t.baseUrl),t?.lombongoIdBaseUrl&&(n.instance.lombongoIdBaseUrl=t.lombongoIdBaseUrl),n.instance):(n.instance=new n(t),n.instance)}async request(s,e,i={},n={},r){const a=`${r||this.baseUrl}${e}`,o={...n,headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`,...n.headers},method:s,url:a,...i&&{data:i}};return t(o)}setToken(t){this.token=t}}export{n as default};
1
+ import t from"axios";class s{constructor(t){this.client=t,this.endpoint="/accounts"}async getAccounts(){return await this.client.request("get",this.endpoint)}async createAoaAccount(){return await this.client.request("post",this.endpoint,{currency:"aoa"},{})}async createEurAccount(){return await 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)}signOut(){delete this.client.token,this.authState.authenticated=!1,this.authState.user=void 0,this.authState.token=void 0,this.notifyObservers()}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,token:e.data.token},this.notifyObservers(),e}async login(t){const s=this._loginFactory(t);return await s(t)}async _verifyToken(t){const s=this.client.lombongoIdBaseUrl;return await this.client.request("post","/token",{token:t},{},s)}async _loginWithEmailAndPassword(t,s){const e=this.client.lombongoIdBaseUrl;return await this.client.request("post","/users",{email:t,password:s},{},e)}async _loginWithUsernameAndPassword(t,s){const e=this.client.lombongoIdBaseUrl;return await 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 i{constructor(t){this.client=t,this.endpoint="/payment-methods"}async getPaymentMethods(){return await this.client.request("get",this.endpoint)}async getPaymentMethodsByCurrency(t){const s=`${this.endpoint}/${t}`;return await this.client.request("get",s)}}class n{constructor({baseUrl:t,token:n,lombongoIdBaseUrl:r}){this.baseUrl=t,this.token=n,this.lombongoIdBaseUrl=r,this.auth=new e(this),this.accounts=new s(this),this.paymentMethods=new i(this)}static init(t){return n.instance?(t?.token&&(n.instance.token=t.token),t?.baseUrl&&(n.instance.baseUrl=t.baseUrl),t?.lombongoIdBaseUrl&&(n.instance.lombongoIdBaseUrl=t.lombongoIdBaseUrl),n.instance):(n.instance=new n(t),n.instance)}async request(s,e,i={},n={},r){const a=`${r||this.baseUrl}${e}`,o={...n,headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`,...n.headers},method:s,url:a};return"GET"!==s.toUpperCase()&&Object.keys(i).length>0&&(o.data=i),t(o)}setToken(t){this.token=t}}export{n as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lombongo-api-client",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/esm/base.js",