lombongo-api-client 0.0.30 → 0.0.32
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.
- package/dist/esm/base.js +1 -1
- package/dist/types.d.ts +8 -0
- 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 i{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,i=await this.client.request("post","/users",t,{},s);return delete t.password,this.authState={authenticated:!0,user:t,token:i.data.token},this.notifyObservers(),i}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 i=this.client.lombongoIdBaseUrl;return await this.client.request("post","/users",{email:t,password:s},{},i)}async _loginWithUsernameAndPassword(t,s){const i=this.client.lombongoIdBaseUrl;return await this.client.request("post","/users",{username:t,password:s},{},i)}_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 e{constructor(t){this.client=t,this.endpoint="/current-commission"}async getCurrentCommission(){return await this.client.request("get",this.endpoint)}}class
|
|
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 i{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,i=await this.client.request("post","/users",t,{},s);return delete t.password,this.authState={authenticated:!0,user:t,token:i.data.token},this.notifyObservers(),i}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 i=this.client.lombongoIdBaseUrl;return await this.client.request("post","/users",{email:t,password:s},{},i)}async _loginWithUsernameAndPassword(t,s){const i=this.client.lombongoIdBaseUrl;return await this.client.request("post","/users",{username:t,password:s},{},i)}_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 e{constructor(t){this.client=t,this.endpoint="/current-commission"}async getCurrentCommission(){return await this.client.request("get",this.endpoint)}}class n{constructor(t){this.client=t,this.endpoint="/currencies"}async getCurrencies(){return await this.client.request("get",this.endpoint)}}class r{constructor(t){this.client=t,this.endpoint="/fx-rates"}async getFxRates(){return await this.client.request("get",this.endpoint)}async getFxRate(t,s){return await this.client.request("post",this.endpoint,{originalCurrencyId:t,finalCurrencyId:s})}}class a{constructor(t){this.client=t,this.endpoint="/transactions"}async doCrossCurrency(t){const s=`${this.endpoint}/cross-currency`;return await this.client.request("post",s,t)}async getFXConfig(t,s,i){const e=`${this.endpoint}/sepa/config`;return await this.client.request("post",e,{originalCurrencyId:t,finalCurrencyId:s,amount:i})}}class o{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}/currency/${t}`;return await this.client.request("get",s)}}class c{constructor(t){this.client=t,this.endpoint="/api/plaid/create_link_token"}async createLinkToken(){return await this.client.request("post",this.endpoint)}}class h{constructor({baseUrl:t,token:h,lombongoIdBaseUrl:u}){this.baseUrl=t,this.token=h,this.lombongoIdBaseUrl=u,this.auth=new i(this),this.accounts=new s(this),this.currencies=new n(this),this.currentCommision=new e(this),this.fxRates=new r(this),this.paymentMethods=new o(this),this.transactions=new a(this),this.plaid=new c(this)}static init(t){return h.instance?(t?.token&&(h.instance.token=t.token),t?.baseUrl&&(h.instance.baseUrl=t.baseUrl),t?.lombongoIdBaseUrl&&(h.instance.lombongoIdBaseUrl=t.lombongoIdBaseUrl),h.instance):(h.instance=new h(t),h.instance)}async request(s,i,e={},n={},r){const a=`${r||this.baseUrl}${i}`,o={...n,headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`,...n.headers},method:s,url:a};return"GET"!==s.toUpperCase()&&Object.keys(e).length>0&&(o.data=e),t(o)}setToken(t){this.token=t}}export{h as default};
|
package/dist/types.d.ts
CHANGED
|
@@ -101,6 +101,13 @@ declare class PaymentMethod {
|
|
|
101
101
|
getPaymentMethodsByCurrency(currencyId: number): Promise<object>;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
declare class Plaid {
|
|
105
|
+
private readonly client;
|
|
106
|
+
private endpoint;
|
|
107
|
+
constructor(client: ApiClient);
|
|
108
|
+
createLinkToken(): Promise<object>;
|
|
109
|
+
}
|
|
110
|
+
|
|
104
111
|
interface ApiClientOptions {
|
|
105
112
|
baseUrl: string;
|
|
106
113
|
lombongoIdBaseUrl: string;
|
|
@@ -122,6 +129,7 @@ declare class ApiClient {
|
|
|
122
129
|
fxRates: FxRate;
|
|
123
130
|
paymentMethods: PaymentMethod;
|
|
124
131
|
transactions: Transactions;
|
|
132
|
+
plaid: Plaid;
|
|
125
133
|
private constructor();
|
|
126
134
|
static init(options: ApiClientOptions): ApiClient;
|
|
127
135
|
request(method: Method, endpoint: string, body?: object, options?: CustomRequestInit, overrideBaseUrl?: string): Promise<object>;
|