lombongo-api-client 0.0.131 → 0.0.133

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 CHANGED
@@ -1 +1 @@
1
- class t{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 s{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 signOut(){const t=this.client.lombongoIdBaseUrl,s=this.client.getToken();s&&await this.client.request("post","/users/logout",{token:s},{},t),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)).data;return t.password&&delete t.password,this.authState={authenticated:!0,user:e.user,token:e.token},this._notifyObservers(),e}async login(t){const s=this._loginFactory(t),e=(await s(t)).data;return this.authState={authenticated:!0,user:{id:e.user.id,email:e.user.email,username:e.user.username},token:e.token},this._notifyObservers(),e}async verifyToken(t){const s=this.client.lombongoIdBaseUrl;return await this.client.request("post","/token",{token:t},{},s)}async checkUsernameAvailability(t){const s=this.client.lombongoIdBaseUrl,e=`/users/${t}/check-availability`;return await this.client.request("get",e,{},{},s)}async _loginWithEmailAndPassword(t,s){const e=this.client.lombongoIdBaseUrl;return await this.client.request("post","/users/login",{email:t,password:s},{},e)}async _loginWithUsernameAndPassword(t,s){const e=this.client.lombongoIdBaseUrl;return await this.client.request("post","/users/login",{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 e{constructor(t){this.client=t,this.endpoint="/beneficiaries"}async getBeneficiaries(){return await this.client.request("get",this.endpoint)}async getBeneficiary(t){const s=`${this.endpoint}/${t}`;return await this.client.request("get",s)}async getBeneficiariesByType(t){const s=`${this.endpoint}?type=${t}`;return await this.client.request("get",s)}async getMyOwnBeneficiaries(t){let s;return s=t?`${this.endpoint}/my-own?type=${t}`:`${this.endpoint}/my-own`,await this.client.request("get",s)}async createBeneficiary(t,s,e,i=!1){return await this.client.request("post",this.endpoint,{name:t,iban:s,type:e,isMe:i})}async setAddress(t,s){const e=`${this.endpoint}/${t}/address`;return await this.client.request("patch",e,{address:s})}async setPhoneNumber(t,s){const e=`${this.endpoint}/${t}/phone-number`;return await this.client.request("patch",e,{phoneNumber:s})}}class i{constructor(t){this.client=t,this.endpoint="/commissions"}async get(){const t=`${this.endpoint}`;return await this.client.request("get",t)}async getHighCommission(){const t=`${this.endpoint}/high`;return await this.client.request("get",t)}}class n{constructor(t){this.client=t,this.endpoint="/current-commission"}async getCurrentCommission(t){const s=`${this.endpoint}/${t}`;return await this.client.request("get",s)}}class r{constructor(t){this.client=t,this.endpoint="/cross-currency-transfer-types"}async getCrossCurrencyTypes(){return await this.client.request("get",this.endpoint)}async getCrossCurrencyType(t,s){const e=`${this.endpoint}?origin_currency=${t}&final_currency=${s}`;return await this.client.request("get",e)}}class a{constructor(t){this.client=t,this.endpoint="/cross-currency-transfer-limits"}async getCrossCurrencyTransferLimits(){return await this.client.request("get",this.endpoint)}async getCrossCurrencyTransferLimitsById(t){const s=`${this.endpoint}/${t}`;return await this.client.request("get",s)}}class h{constructor(t){this.client=t,this.endpoint="/currencies"}async getCurrencies(){return await this.client.request("get",this.endpoint)}}class o{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("get",`${this.endpoint}/${t}/${s}`)}async getFxRateHistory(t,s,e){const i=e?`?limit=${e}`:"";return await this.client.request("get",`${this.endpoint}/${t}/${s}/history${i}`)}async getFxRateAtDate(t,s,e){return await this.client.request("get",`${this.endpoint}/${t}/${s}/at-date?date=${e}`)}async getBaseFxRates(){return await this.client.request("get",`${this.endpoint}/base-rates`)}async getBaseFxRate(t,s){return await this.client.request("get",`${this.endpoint}/base-rates/${t}/${s}`)}async getFxSpreads(){return await this.client.request("get",`${this.endpoint}/spreads`)}async getFxSpread(t,s){return await this.client.request("get",`${this.endpoint}/spreads/${t}/${s}`)}async getFxSpreadHistory(t,s,e){const i=e?`?limit=${e}`:"";return await this.client.request("get",`${this.endpoint}/spreads/${t}/${s}/history${i}`)}}class c{constructor(t){this.client=t,this.endpoint="/invitation-codes"}async generateNew(){return await this.client.request("get",`${this.endpoint}/new`)}async sendCodeTo(t,s){return await this.client.request("post",`${this.endpoint}/send`,{code:t,username:s})}async getMyInvitationCodes(){return await this.client.request("get",this.endpoint)}async redeemInvitationCode(t){return await this.client.request("get",`${this.endpoint}/${t}/redeem`)}}class u{constructor(t){this.client=t,this.endpoint="/liquidity-pools"}async getLiquidityPools(){return await this.client.request("get",this.endpoint)}async getLiquidityRatio(t){const s=`${this.endpoint}/${t}/liquidity-ratio`;return await this.client.request("get",s)}}class y{constructor(t,s){let e;if("string"==typeof t){if(!/^-?\d+$/.test(t))throw new Error(`Amount string "${t}" is not parseable as an integer`);e=parseInt(t,10)}else e=t;if(e<0)throw new Error("Amount cannot be negative");if(!Number.isInteger(e))throw new Error(`Amount must be in smallest currency unit (cents) and be an integer, received: ${e} (${typeof t})`);this.amount=e,this.currencyCode=s.toUpperCase()}static fromDecimal(t,s){if(t<0)throw new Error("Amount cannot be negative");return new y(Math.round(100*t),s)}static fromCents(t,s){return new y(t,s)}static fromClientInput(t,s){return new y(t,s)}add(t){return this.ensureSameCurrency(t),new y(this.amount+t.amount,this.currencyCode)}subtract(t){if(this.ensureSameCurrency(t),this.amount<t.amount)throw new Error("Insufficient funds: cannot subtract larger amount");return new y(this.amount-t.amount,this.currencyCode)}multiply(t){if(t<0)throw new Error("Multiplication factor cannot be negative");return new y(Math.round(this.amount*t),this.currencyCode)}applyPercentage(t){if(t<0)throw new Error("Percentage cannot be negative");return this.multiply(t/100)}toDecimal(){const t=this.amount/100;return"AOA"===this.currencyCode?Math.round(t):t}toCents(){return this.amount}getCurrencyCode(){return this.currencyCode}isZero(){return 0===this.amount}equals(t){return this.amount===t.amount&&this.currencyCode===t.currencyCode}isGreaterThan(t){return this.ensureSameCurrency(t),this.amount>t.amount}toString(){return`${this.toDecimal().toFixed(2)} ${this.currencyCode}`}ensureSameCurrency(t){if(this.currencyCode!==t.currencyCode)throw new Error(`Cannot operate on different currencies: ${this.currencyCode} vs ${t.currencyCode}`)}}class w{constructor(t){this.client=t,this.endpoint="/transactions"}async get(){return await this.client.request("get",this.endpoint)}async getTransaction(t){const s=`${this.endpoint}/${t}`;return await this.client.request("get",s)}async doCrossCurrency(t){const s=`${this.endpoint}/cross-currency`;return await this.client.request("post",s,t)}async doP2P(t){const s=`${this.endpoint}/p2p`;return await this.client.request("post",s,t)}async getFXConfig(t,s,e){const i=`${this.endpoint}/sepa/config`;return await this.client.request("post",i,{originalCurrencyId:t,finalCurrencyId:s,amount:e})}async generatePdfReceipt(t){const s=`${this.endpoint}/${t}/receipt`;return await this.client.request("get",s)}}var g=(t=>(t.NOT_VERIFIED="NOT_VERIFIED",t.VERIFICATION_PENDING="VERIFICATION_PENDING",t.VERIFICATION_FAILED="VERIFICATION_FAILED",t.VERIFIED="VERIFIED",t))(g||{});class l{constructor(t){this.client=t,this.endpoint="/users"}async getInvitedStatus(){const t=await this.client.request("get",`${this.endpoint}/me/check-if-invited`);if(null===t.data||void 0===t.data)throw new Error(`Invalid response for invited status: ${t.status} ${t.statusText}`);if("boolean"==typeof t.data)return t.data;if("string"==typeof t.data){const s=t.data.trim().toLowerCase();if("true"===s)return!0;if("false"===s)return!1}throw new Error(`Invalid invited status received: "${t.data}". Expected boolean or "true"/"false" string.`)}async verifyKyc(){const t=`${this.endpoint}/me/check-kyc-status`,s=await this.client.request("get",t);if(null===s.data||void 0===s.data)throw new Error(`Invalid response for KYC status: ${s.status} ${s.statusText}`);const e="string"==typeof s.data?s.data.trim():String(s.data).trim(),i=Object.values(g);if(i.includes(e))return e;throw new Error(`Invalid KYC status received: "${e}". Expected one of: ${i.join(", ")}`)}}class d{constructor(t){this.client=t,this.endpoint="/veriff/sessions"}async createSession(t){return await this.client.request("post",this.endpoint,{userId:t})}}class ${constructor(t){this.client=t,this.endpoint="/offers"}async createOffer(t){return await this.client.request("post",this.endpoint,{...t})}async getOffers(){return await this.client.request("get",this.endpoint)}async getMyOffers(){const t=`${this.endpoint}/me`;return await this.client.request("get",t)}async getOffer(t){const s=`${this.endpoint}/${t}`;return await this.client.request("get",s)}}class f{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 p{constructor(t){this.client=t,this.endpoint="/payments"}async getPaymentByTransactionId(t){const s=`${this.endpoint}?transaction_id=${t}`;return await this.client.request("get",s)}}class m{constructor(t){this.client=t,this.endpoint="/api/plaid/"}async createPaymentInitiationLinkToken(t){const s=this.endpoint+"create_link_token";return await this.client.request("post",s,{payment_id:t})}async createPaymentInitiation(t){const s=this.endpoint+"payment_initiation/payment/create";return await this.client.request("post",s,{amount:t})}}class v{constructor({baseUrl:g,token:v,lombongoIdBaseUrl:C}){this.unauthorizedListeners=[],this.baseUrl=g,this.token=v,this.lombongoIdBaseUrl=C,this.auth=new s(this),this.accounts=new t(this),this.beneficiaries=new e(this),this.commissions=new i(this),this.currencies=new h(this),this.currentCommision=new n(this),this.crossCurrencyTransferType=new r(this),this.crossCurrencyTransferLimits=new a(this),this.fxRates=new o(this),this.invitationCodes=new c(this),this.liquidityPools=new u(this),this.money=y,this.paymentMethods=new f(this),this.payments=new p(this),this.transactions=new w(this),this.users=new l(this),this.offers=new $(this),this.plaid=new m(this),this.veriff=new d(this),this.setupInterceptors()}static init(t){return v.instance?(t?.token&&(v.instance.token=t.token),t?.baseUrl&&(v.instance.baseUrl=t.baseUrl),t?.lombongoIdBaseUrl&&(v.instance.lombongoIdBaseUrl=t.lombongoIdBaseUrl),v.instance):(v.instance=new v(t),v.instance)}setupInterceptors(){}async request(t,s,e={},i={},n){const r=`${n||this.baseUrl}${s}`,a={...i,method:t.toUpperCase(),headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`,...i.headers}};"GET"!==t.toUpperCase()&&e&&Object.keys(e).length>0&&(a.body=JSON.stringify(e));const h=await fetch(r,a);if(401===h.status&&this.emit401Event(r),!h.ok)throw new Error(`HTTP ${h.status}: ${h.statusText}`);return await async function(t){let s;try{const e=await t.text();if(""===e)s=null;else if(""===e.trim())s=null;else try{s=JSON.parse(e)}catch(t){s=e}}catch(t){s=null}return{data:s,status:t.status,statusText:t.statusText,headers:t.headers}}(h)}setToken(t){this.token=t}getToken(){return this.token}onUnauthorized(t){this.unauthorizedListeners.push(t)}offUnauthorized(t){const s=this.unauthorizedListeners.indexOf(t);s>-1&&this.unauthorizedListeners.splice(s,1)}emit401Event(t){for(const s of this.unauthorizedListeners)s(t)}}export{g as KycVerified,y as Money,v as default};
1
+ class t{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 s{constructor(t){this.observers=[],this.authState={authenticated:!1},this.client=t}_notifyObservers(){for(const t of this.observers)t(this.authState)}onAuthStateChange(t){this.observers.push(t)}isAuthenticated(){return Boolean(this.client.token)}async signUp(t){const s=(await this.client.request("post","/api/auth/sign-up/email",t)).data;return this.authState={authenticated:!0,user:s.user,token:s.token},this._notifyObservers(),s}async login(t){const s=(await this.client.request("post","/api/auth/sign-in/email",t)).data;return this.authState={authenticated:!0,user:s.user,token:s.token},this._notifyObservers(),s}async signOut(){await this.client.request("post","/api/auth/sign-out"),delete this.client.token,this.authState={authenticated:!1,user:void 0,token:void 0},this._notifyObservers()}async getSession(){return await this.client.request("get","/api/auth/get-session")}async checkUsernameAvailability(t){const s=`/auth/users/${t}/check-availability`;return await this.client.request("get",s)}}class e{constructor(t){this.client=t,this.endpoint="/beneficiaries"}async getBeneficiaries(){return await this.client.request("get",this.endpoint)}async getBeneficiary(t){const s=`${this.endpoint}/${t}`;return await this.client.request("get",s)}async getBeneficiariesByType(t){const s=`${this.endpoint}?type=${t}`;return await this.client.request("get",s)}async getMyOwnBeneficiaries(t){let s;return s=t?`${this.endpoint}/my-own?type=${t}`:`${this.endpoint}/my-own`,await this.client.request("get",s)}async createBeneficiary(t,s,e,i,n,r=!1){return await this.client.request("post",this.endpoint,{name:t,iban:s,type:e,phoneNumber:i,address:n,isMe:r})}async setAddress(t,s){const e=`${this.endpoint}/${t}/address`;return await this.client.request("patch",e,{address:s})}async setPhoneNumber(t,s){const e=`${this.endpoint}/${t}/phone-number`;return await this.client.request("patch",e,{phoneNumber:s})}async setNickname(t,s){const e=`${this.endpoint}/${t}/nickname`;return await this.client.request("patch",e,{nickname:s})}}class i{constructor(t){this.client=t,this.endpoint="/commissions"}async get(){const t=`${this.endpoint}`;return await this.client.request("get",t)}async getHighCommission(){const t=`${this.endpoint}/high`;return await this.client.request("get",t)}}class n{constructor(t){this.client=t,this.endpoint="/current-commission"}async getCurrentCommission(t){const s=`${this.endpoint}/${t}`;return await this.client.request("get",s)}}class r{constructor(t){this.client=t,this.endpoint="/cross-currency-transfer-types"}async getCrossCurrencyTypes(){return await this.client.request("get",this.endpoint)}async getCrossCurrencyType(t,s){const e=`${this.endpoint}?origin_currency=${t}&final_currency=${s}`;return await this.client.request("get",e)}}class a{constructor(t){this.client=t,this.endpoint="/cross-currency-transfer-limits"}async getCrossCurrencyTransferLimits(){return await this.client.request("get",this.endpoint)}async getCrossCurrencyTransferLimitsById(t){const s=`${this.endpoint}/${t}`;return await this.client.request("get",s)}}class h{constructor(t){this.client=t,this.endpoint="/currencies"}async getCurrencies(){return await this.client.request("get",this.endpoint)}}class c{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("get",`${this.endpoint}/${t}/${s}`)}async getFxRateHistory(t,s,e){const i=e?`?limit=${e}`:"";return await this.client.request("get",`${this.endpoint}/${t}/${s}/history${i}`)}async getFxRateAtDate(t,s,e){return await this.client.request("get",`${this.endpoint}/${t}/${s}/at-date?date=${e}`)}async getBaseFxRates(){return await this.client.request("get",`${this.endpoint}/base-rates`)}async getBaseFxRate(t,s){return await this.client.request("get",`${this.endpoint}/base-rates/${t}/${s}`)}async getFxSpreads(){return await this.client.request("get",`${this.endpoint}/spreads`)}async getFxSpread(t,s){return await this.client.request("get",`${this.endpoint}/spreads/${t}/${s}`)}async getFxSpreadHistory(t,s,e){const i=e?`?limit=${e}`:"";return await this.client.request("get",`${this.endpoint}/spreads/${t}/${s}/history${i}`)}}class o{constructor(t){this.client=t,this.endpoint="/invitation-codes"}async generateNew(){return await this.client.request("get",`${this.endpoint}/new`)}async sendCodeTo(t,s){return await this.client.request("post",`${this.endpoint}/send`,{code:t,username:s})}async getMyInvitationCodes(){return await this.client.request("get",this.endpoint)}async redeemInvitationCode(t){return await this.client.request("get",`${this.endpoint}/${t}/redeem`)}}class u{constructor(t){this.client=t,this.endpoint="/liquidity-pools"}async getLiquidityPools(){return await this.client.request("get",this.endpoint)}async getLiquidityRatio(t){const s=`${this.endpoint}/${t}/liquidity-ratio`;return await this.client.request("get",s)}}class y{constructor(t,s){let e;if("string"==typeof t){if(!/^-?\d+$/.test(t))throw new Error(`Amount string "${t}" is not parseable as an integer`);e=parseInt(t,10)}else e=t;if(e<0)throw new Error("Amount cannot be negative");if(!Number.isInteger(e))throw new Error(`Amount must be in smallest currency unit (cents) and be an integer, received: ${e} (${typeof t})`);this.amount=e,this.currencyCode=s.toUpperCase()}static fromDecimal(t,s){if(t<0)throw new Error("Amount cannot be negative");return new y(Math.round(100*t),s)}static fromCents(t,s){return new y(t,s)}static fromClientInput(t,s){return new y(t,s)}add(t){return this.ensureSameCurrency(t),new y(this.amount+t.amount,this.currencyCode)}subtract(t){if(this.ensureSameCurrency(t),this.amount<t.amount)throw new Error("Insufficient funds: cannot subtract larger amount");return new y(this.amount-t.amount,this.currencyCode)}multiply(t){if(t<0)throw new Error("Multiplication factor cannot be negative");return new y(Math.round(this.amount*t),this.currencyCode)}applyPercentage(t){if(t<0)throw new Error("Percentage cannot be negative");return this.multiply(t/100)}toDecimal(){const t=this.amount/100;return"AOA"===this.currencyCode?Math.round(t):t}toCents(){return this.amount}getCurrencyCode(){return this.currencyCode}isZero(){return 0===this.amount}equals(t){return this.amount===t.amount&&this.currencyCode===t.currencyCode}isGreaterThan(t){return this.ensureSameCurrency(t),this.amount>t.amount}toString(){return`${this.toDecimal().toFixed(2)} ${this.currencyCode}`}ensureSameCurrency(t){if(this.currencyCode!==t.currencyCode)throw new Error(`Cannot operate on different currencies: ${this.currencyCode} vs ${t.currencyCode}`)}}class w{constructor(t){this.client=t,this.endpoint="/transactions"}async get(){return await this.client.request("get",this.endpoint)}async getTransaction(t){const s=`${this.endpoint}/${t}`;return await this.client.request("get",s)}async doCrossCurrency(t){const s=`${this.endpoint}/cross-currency`;return await this.client.request("post",s,t)}async doP2P(t){const s=`${this.endpoint}/p2p`;return await this.client.request("post",s,t)}async getFXConfig(t,s,e){const i=`${this.endpoint}/sepa/config`;return await this.client.request("post",i,{originalCurrencyId:t,finalCurrencyId:s,amount:e})}async generatePdfReceipt(t){const s=`${this.endpoint}/${t}/receipt`;return await this.client.request("get",s)}}var g=(t=>(t.NOT_VERIFIED="NOT_VERIFIED",t.VERIFICATION_PENDING="VERIFICATION_PENDING",t.VERIFICATION_FAILED="VERIFICATION_FAILED",t.VERIFIED="VERIFIED",t))(g||{});class ${constructor(t){this.client=t,this.endpoint="/users"}async getInvitedStatus(){const t=await this.client.request("get",`${this.endpoint}/me/check-if-invited`);if(null===t.data||void 0===t.data)throw new Error(`Invalid response for invited status: ${t.status} ${t.statusText}`);if("boolean"==typeof t.data)return t.data;if("string"==typeof t.data){const s=t.data.trim().toLowerCase();if("true"===s)return!0;if("false"===s)return!1}throw new Error(`Invalid invited status received: "${t.data}". Expected boolean or "true"/"false" string.`)}async verifyKyc(){const t=`${this.endpoint}/me/check-kyc-status`,s=await this.client.request("get",t);if(null===s.data||void 0===s.data)throw new Error(`Invalid response for KYC status: ${s.status} ${s.statusText}`);const e="string"==typeof s.data?s.data.trim():String(s.data).trim(),i=Object.values(g);if(i.includes(e))return e;throw new Error(`Invalid KYC status received: "${e}". Expected one of: ${i.join(", ")}`)}}class l{constructor(t){this.client=t,this.endpoint="/veriff/sessions"}async createSession(t){return await this.client.request("post",this.endpoint,{userId:t})}}class d{constructor(t){this.client=t,this.endpoint="/offers"}async createOffer(t){return await this.client.request("post",this.endpoint,{...t})}async getOffers(){return await this.client.request("get",this.endpoint)}async getMyOffers(){const t=`${this.endpoint}/me`;return await this.client.request("get",t)}async getOffer(t){const s=`${this.endpoint}/${t}`;return await this.client.request("get",s)}}class f{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 p{constructor(t){this.client=t,this.endpoint="/payments"}async getPaymentByTransactionId(t){const s=`${this.endpoint}?transaction_id=${t}`;return await this.client.request("get",s)}}class m{constructor(t){this.client=t,this.endpoint="/api/plaid/"}async createPaymentInitiationLinkToken(t){const s=this.endpoint+"create_link_token";return await this.client.request("post",s,{payment_id:t})}async createPaymentInitiation(t){const s=this.endpoint+"payment_initiation/payment/create";return await this.client.request("post",s,{amount:t})}}class C{constructor({baseUrl:g,token:C}){this.unauthorizedListeners=[],this.baseUrl=g,this.token=C,this.auth=new s(this),this.accounts=new t(this),this.beneficiaries=new e(this),this.commissions=new i(this),this.currencies=new h(this),this.currentCommision=new n(this),this.crossCurrencyTransferType=new r(this),this.crossCurrencyTransferLimits=new a(this),this.fxRates=new c(this),this.invitationCodes=new o(this),this.liquidityPools=new u(this),this.money=y,this.paymentMethods=new f(this),this.payments=new p(this),this.transactions=new w(this),this.users=new $(this),this.offers=new d(this),this.plaid=new m(this),this.veriff=new l(this),this.setupInterceptors()}static init(t){return C.instance?(t?.token&&(C.instance.token=t.token),t?.baseUrl&&(C.instance.baseUrl=t.baseUrl),C.instance):(C.instance=new C(t),C.instance)}setupInterceptors(){}async request(t,s,e={},i={}){const n=`${this.baseUrl}${s}`,r={...i,method:t.toUpperCase(),headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`,...i.headers}};"GET"!==t.toUpperCase()&&e&&Object.keys(e).length>0&&(r.body=JSON.stringify(e));const a=await fetch(n,r);if(401===a.status&&this.emit401Event(n),!a.ok)throw new Error(`HTTP ${a.status}: ${a.statusText}`);return await async function(t){let s;try{const e=await t.text();if(""===e)s=null;else if(""===e.trim())s=null;else try{s=JSON.parse(e)}catch(t){s=e}}catch(t){s=null}return{data:s,status:t.status,statusText:t.statusText,headers:t.headers}}(a)}setToken(t){this.token=t}getToken(){return this.token}onUnauthorized(t){this.unauthorizedListeners.push(t)}offUnauthorized(t){const s=this.unauthorizedListeners.indexOf(t);s>-1&&this.unauthorizedListeners.splice(s,1)}emit401Event(t){for(const s of this.unauthorizedListeners)s(t)}}export{g as KycVerified,y as Money,C as default};
package/dist/types.d.ts CHANGED
@@ -14,26 +14,30 @@ declare class Account {
14
14
  createEurAccount(): Promise<ApiResponse>;
15
15
  }
16
16
 
17
- type CreateUser = {
17
+ type SignUpParams = {
18
+ email: string;
19
+ password: string;
20
+ name: string;
21
+ username: string;
22
+ };
23
+ type AuthUser = {
18
24
  id: number;
19
25
  email: string;
20
- password?: string;
21
26
  username: string;
22
- fullname: string;
27
+ name: string;
23
28
  };
24
- type CreatedUser = {
25
- user: CreateUser;
29
+ type AuthResponse = {
30
+ user: AuthUser;
26
31
  token: string;
27
32
  };
28
33
  type LoginParameter = {
29
- email?: string;
34
+ email: string;
30
35
  password: string;
31
- username?: string;
32
36
  };
33
37
  type AuthState = {
34
38
  authenticated: boolean;
35
39
  token?: string;
36
- user?: CreateUser;
40
+ user?: AuthUser;
37
41
  };
38
42
  declare class Auth {
39
43
  private client;
@@ -41,17 +45,13 @@ declare class Auth {
41
45
  private authState;
42
46
  constructor(client: ApiClient);
43
47
  private _notifyObservers;
44
- listObservers(): void;
45
48
  onAuthStateChange(observer: (authState: AuthState) => void): void;
46
49
  isAuthenticated(): boolean;
50
+ signUp(params: SignUpParams): Promise<AuthResponse>;
51
+ login(credentials: LoginParameter): Promise<AuthResponse>;
47
52
  signOut(): Promise<void>;
48
- createUser(user: Omit<CreateUser, "id">): Promise<CreatedUser>;
49
- login(credentials: LoginParameter): Promise<CreatedUser>;
50
- verifyToken(token: string): Promise<ApiResponse>;
53
+ getSession(): Promise<ApiResponse>;
51
54
  checkUsernameAvailability(username: string): Promise<ApiResponse>;
52
- _loginWithEmailAndPassword(email: string, password: string): Promise<ApiResponse>;
53
- _loginWithUsernameAndPassword(username: string, password: string): Promise<ApiResponse>;
54
- _loginFactory(credentials: LoginParameter): (credentials: LoginParameter) => Promise<ApiResponse>;
55
55
  }
56
56
 
57
57
  declare class Beneficiaries {
@@ -62,9 +62,10 @@ declare class Beneficiaries {
62
62
  getBeneficiary(id: number): Promise<ApiResponse>;
63
63
  getBeneficiariesByType(type: "AO" | "EU"): Promise<ApiResponse>;
64
64
  getMyOwnBeneficiaries(type?: "AO" | "EU"): Promise<ApiResponse>;
65
- createBeneficiary(name: string, iban: string, type: "AO" | "EU", isMe?: boolean): Promise<ApiResponse>;
65
+ createBeneficiary(name: string, iban: string, type: "AO" | "EU", phoneNumber: string, address: string, isMe?: boolean): Promise<ApiResponse>;
66
66
  setAddress(id: number, address: string): Promise<ApiResponse>;
67
67
  setPhoneNumber(id: number, phoneNumber: string): Promise<ApiResponse>;
68
+ setNickname(id: number, nickname: string): Promise<ApiResponse>;
68
69
  }
69
70
 
70
71
  declare class Commission {
@@ -258,7 +259,6 @@ declare class Plaid {
258
259
 
259
260
  interface ApiClientOptions {
260
261
  baseUrl: string;
261
- lombongoIdBaseUrl: string;
262
262
  token?: string;
263
263
  }
264
264
  interface CustomRequestInit extends Omit<RequestInit, "headers" | "method" | "body"> {
@@ -270,7 +270,6 @@ declare class ApiClient {
270
270
  private token?;
271
271
  private unauthorizedListeners;
272
272
  baseUrl: string;
273
- lombongoIdBaseUrl: string;
274
273
  accounts: Account;
275
274
  auth: Auth;
276
275
  beneficiaries: Beneficiaries;
@@ -293,7 +292,7 @@ declare class ApiClient {
293
292
  private constructor();
294
293
  static init(options: ApiClientOptions): ApiClient;
295
294
  private setupInterceptors;
296
- request(method: Method, endpoint: string, body?: object, options?: CustomRequestInit, overrideBaseUrl?: string): Promise<ApiResponse>;
295
+ request(method: Method, endpoint: string, body?: object, options?: CustomRequestInit): Promise<ApiResponse>;
297
296
  setToken(token: string): void;
298
297
  getToken(): string | undefined;
299
298
  onUnauthorized(listener: (url: string) => void): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lombongo-api-client",
3
- "version": "0.0.131",
3
+ "version": "0.0.133",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/esm/base.js",