lombongo-api-client 0.0.146 → 0.0.150
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 +32 -5
- package/package.json +1 -1
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)}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)}async getSocialSignInUrl(t,s){return(await this.client.request("post","/api/auth/sign-in/social",{provider:t,callbackURL:s,disableRedirect:!0})).data.url}async signInWithSocialToken(t,s){const e=(await this.client.request("post","/api/auth/sign-in/social",{provider:t,idToken:{token:s}})).data;return this.authState={authenticated:!0,user:e.user,token:e.token},this._notifyObservers(),e}async handleSocialCallback(t){console.log("[Auth.handleSocialCallback] callbackUrl:",t);const s=new URL(t).searchParams.get("token");if(console.log("[Auth.handleSocialCallback] extracted token:",s?`${s.substring(0,20)}...`:"null"),!s)throw new Error("No token found in callback URL");this.client.setToken(s),console.log("[Auth.handleSocialCallback] Token set on client, calling getSession...");const e=await this.getSession();console.log("[Auth.handleSocialCallback] getSession response:",JSON.stringify(e,null,2));const i=e.data;return console.log("[Auth.handleSocialCallback] parsed user:",JSON.stringify(i?.user)),this.authState={authenticated:!0,user:i.user,token:s},console.log("[Auth.handleSocialCallback] Notifying observers, isAuthenticated:",this.authState.authenticated),this._notifyObservers(),i}}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,a=!1){return await this.client.request("post",this.endpoint,{name:t,iban:s,type:e,phoneNumber:i,address:n,isMe:a})}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 a{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 r{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 c{constructor(t){this.client=t,this.endpoint="/currencies"}async getCurrencies(){return await this.client.request("get",this.endpoint)}}class h{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}async lookup(t){const s=`/iban-lookup?iban=${encodeURIComponent(t)}`;return await this.client.request("get",s)}}class u{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 y{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 l{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 l(Math.round(100*t),s)}static fromCents(t,s){return new l(t,s)}static fromClientInput(t,s){return new l(t,s)}add(t){return this.ensureSameCurrency(t),new l(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 l(this.amount-t.amount,this.currencyCode)}multiply(t){if(t<0)throw new Error("Multiplication factor cannot be negative");return new l(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="/onboarding-questions"}async get(){return(await this.client.request("get",this.endpoint)).data}}class g{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 d=(t=>(t.NOT_VERIFIED="NOT_VERIFIED",t.VERIFICATION_STARTED="VERIFICATION_STARTED",t.VERIFICATION_PENDING="VERIFICATION_PENDING",t.VERIFICATION_FAILED="VERIFICATION_FAILED",t.VERIFIED="VERIFIED",t))(d||{});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 updateKycInfo(t){return this.client.request("patch",`${this.endpoint}/me/kyc-info`,t)}async getKycInfo(){return this.client.request("get",`${this.endpoint}/me/kyc-info`)}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(d);if(i.includes(e))return e;throw new Error(`Invalid KYC status received: "${e}". Expected one of: ${i.join(", ")}`)}}class p{constructor(t){this.client=t,this.endpoint="/veriff/sessions"}async createSession(t){return await this.client.request("post",this.endpoint,{userId:t})}}class f{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 m{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="/payments"}async getPaymentByTransactionId(t){const s=`${this.endpoint}?transaction_id=${t}`;return await this.client.request("get",s)}}class b{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 k{constructor({baseUrl:d,token:k}){this.unauthorizedListeners=[],this.baseUrl=d,this.token=k,this.auth=new s(this),this.accounts=new t(this),this.beneficiaries=new e(this),this.commissions=new i(this),this.currencies=new c(this),this.currentCommision=new n(this),this.crossCurrencyTransferType=new a(this),this.crossCurrencyTransferLimits=new r(this),this.fxRates=new h(this),this.ibans=new o(this),this.invitationCodes=new u(this),this.liquidityPools=new y(this),this.money=l,this.onboardingQuestions=new w(this),this.paymentMethods=new m(this),this.payments=new C(this),this.transactions=new g(this),this.users=new $(this),this.offers=new f(this),this.plaid=new b(this),this.veriff=new p(this),this.setupInterceptors()}static init(t){return k.instance?(t?.token&&(k.instance.token=t.token),t?.baseUrl&&(k.instance.baseUrl=t.baseUrl),k.instance):(k.instance=new k(t),k.instance)}setupInterceptors(){}async request(t,s,e={},i={}){const n=`${this.baseUrl}${s}`,a="GET"!==t.toUpperCase()&&e&&Object.keys(e).length>0,r={...i,method:t.toUpperCase(),headers:{Authorization:`Bearer ${this.token}`,...a?{"Content-Type":"application/json"}:{},...i.headers}};a&&(r.body=JSON.stringify(e));const c=await fetch(n,r);if(401===c.status&&this.emit401Event(n),!c.ok)throw new Error(`HTTP ${c.status}: ${c.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}}(c)}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{d as KycVerified,l as Money,k 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)}async getSocialSignInUrl(t,s){return(await this.client.request("post","/api/auth/sign-in/social",{provider:t,callbackURL:s,disableRedirect:!0})).data.url}async signInWithSocialToken(t,s){const e=(await this.client.request("post","/api/auth/sign-in/social",{provider:t,idToken:{token:s}})).data;return this.authState={authenticated:!0,user:e.user,token:e.token},this._notifyObservers(),e}async handleSocialCallback(t){console.log("[Auth.handleSocialCallback] callbackUrl:",t);const s=new URL(t).searchParams.get("token");if(console.log("[Auth.handleSocialCallback] extracted token:",s?`${s.substring(0,20)}...`:"null"),!s)throw new Error("No token found in callback URL");this.client.setToken(s),console.log("[Auth.handleSocialCallback] Token set on client, calling getSession...");const e=await this.getSession();console.log("[Auth.handleSocialCallback] getSession response:",JSON.stringify(e,null,2));const i=e.data;return console.log("[Auth.handleSocialCallback] parsed user:",JSON.stringify(i?.user)),this.authState={authenticated:!0,user:i.user,token:s},console.log("[Auth.handleSocialCallback] Notifying observers, isAuthenticated:",this.authState.authenticated),this._notifyObservers(),i}}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,a=!1){return await this.client.request("post",this.endpoint,{name:t,iban:s,type:e,phoneNumber:i,address:n,isMe:a})}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 a{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 r{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 c{constructor(t){this.client=t,this.endpoint="/currencies"}async getCurrencies(){return await this.client.request("get",this.endpoint)}}class h{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}async lookup(t){const s=`/iban-lookup?iban=${encodeURIComponent(t)}`;return await this.client.request("get",s)}}class u{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 y{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 l{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 l(Math.round(100*t),s)}static fromCents(t,s){return new l(t,s)}static fromClientInput(t,s){return new l(t,s)}add(t){return this.ensureSameCurrency(t),new l(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 l(this.amount-t.amount,this.currencyCode)}multiply(t){if(t<0)throw new Error("Multiplication factor cannot be negative");return new l(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 g{constructor(t){this.client=t,this.endpoint="/onboarding-questions"}async get(){return(await this.client.request("get",this.endpoint)).data}}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 d=(t=>(t.NOT_VERIFIED="NOT_VERIFIED",t.VERIFICATION_STARTED="VERIFICATION_STARTED",t.VERIFICATION_PENDING="VERIFICATION_PENDING",t.VERIFICATION_FAILED="VERIFICATION_FAILED",t.VERIFIED="VERIFIED",t))(d||{});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 updateKycInfo(t){return this.client.request("patch",`${this.endpoint}/me/kyc-info`,t)}async getKycInfo(){return this.client.request("get",`${this.endpoint}/me/kyc-info`)}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(d);if(i.includes(e))return e;throw new Error(`Invalid KYC status received: "${e}". Expected one of: ${i.join(", ")}`)}}class p{constructor(t){this.client=t,this.endpoint="/veriff/sessions"}async createSession(t){return await this.client.request("post",this.endpoint,{userId:t})}}class f{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 m{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="/payments"}async getPaymentByTransactionId(t){const s=`${this.endpoint}?transaction_id=${t}`;return await this.client.request("get",s)}}class k{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 b{constructor({baseUrl:d,token:b,apiKey:I}){this.unauthorizedListeners=[],this.baseUrl=d,this.token=b,this.apiKey=I,this.auth=new s(this),this.accounts=new t(this),this.beneficiaries=new e(this),this.commissions=new i(this),this.currencies=new c(this),this.currentCommision=new n(this),this.crossCurrencyTransferType=new a(this),this.crossCurrencyTransferLimits=new r(this),this.fxRates=new h(this),this.ibans=new o(this),this.invitationCodes=new u(this),this.liquidityPools=new y(this),this.money=l,this.onboardingQuestions=new g(this),this.paymentMethods=new m(this),this.payments=new C(this),this.transactions=new w(this),this.users=new $(this),this.offers=new f(this),this.plaid=new k(this),this.veriff=new p(this),this.setupInterceptors()}static init(t){return b.instance?(t?.token&&(b.instance.token=t.token),t?.apiKey&&(b.instance.apiKey=t.apiKey),t?.baseUrl&&(b.instance.baseUrl=t.baseUrl),b.instance):(b.instance=new b(t),b.instance)}setupInterceptors(){}async request(t,s,e={},i={}){const n=`${this.baseUrl}${s}`,a="GET"!==t.toUpperCase()&&e&&Object.keys(e).length>0,r={...i,method:t.toUpperCase(),headers:{Authorization:`Bearer ${this.token}`,...this.apiKey?{"x-api-key":this.apiKey}:{},...a?{"Content-Type":"application/json"}:{},...i.headers}};a&&(r.body=JSON.stringify(e));const c=await fetch(n,r);if(401===c.status&&this.emit401Event(n),!c.ok)throw new Error(`HTTP ${c.status}: ${c.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}}(c)}setToken(t){this.token=t}getToken(){return this.token}setApiKey(t){this.apiKey=t}getApiKey(){return this.apiKey}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{d as KycVerified,l as Money,b as default};
|
package/dist/types.d.ts
CHANGED
|
@@ -174,17 +174,26 @@ declare class Money {
|
|
|
174
174
|
private ensureSameCurrency;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
type PepCategory = "self" | "family";
|
|
178
|
+
type IncomeRangesByCurrency = {
|
|
179
|
+
currency_id: number;
|
|
180
|
+
currency_code: string;
|
|
181
|
+
ranges: {
|
|
182
|
+
id: number;
|
|
183
|
+
label: string;
|
|
184
|
+
value: number;
|
|
185
|
+
}[];
|
|
186
|
+
};
|
|
177
187
|
type OnboardingQuestionsResponse = {
|
|
178
188
|
occupations: {
|
|
179
189
|
id: number;
|
|
180
190
|
label: string;
|
|
181
191
|
}[];
|
|
182
|
-
|
|
183
|
-
|
|
192
|
+
income_ranges_by_currency: IncomeRangesByCurrency[];
|
|
193
|
+
pep_categories: {
|
|
194
|
+
value: PepCategory;
|
|
184
195
|
label: string;
|
|
185
|
-
value: number;
|
|
186
196
|
}[];
|
|
187
|
-
income_currency_id: number;
|
|
188
197
|
};
|
|
189
198
|
declare class OnboardingQuestions {
|
|
190
199
|
private readonly client;
|
|
@@ -228,6 +237,17 @@ declare class Transactions {
|
|
|
228
237
|
generatePdfReceipt(transactionUid: string): Promise<ApiResponse>;
|
|
229
238
|
}
|
|
230
239
|
|
|
240
|
+
type KycInfo = {
|
|
241
|
+
given_fullname: string | null;
|
|
242
|
+
occupation_id: number | null;
|
|
243
|
+
occupation_description: string | null;
|
|
244
|
+
annual_income: number | null;
|
|
245
|
+
income_currency_id: number | null;
|
|
246
|
+
is_dependent: boolean | null;
|
|
247
|
+
is_pep: boolean | null;
|
|
248
|
+
pep_category: PepCategory | null;
|
|
249
|
+
pep_description: string | null;
|
|
250
|
+
};
|
|
231
251
|
declare enum KycVerified {
|
|
232
252
|
NOT_VERIFIED = "NOT_VERIFIED",
|
|
233
253
|
VERIFICATION_STARTED = "VERIFICATION_STARTED",
|
|
@@ -247,8 +267,11 @@ declare class Users {
|
|
|
247
267
|
annual_income?: number;
|
|
248
268
|
income_currency_id?: number;
|
|
249
269
|
is_dependent?: boolean;
|
|
270
|
+
is_pep?: boolean;
|
|
271
|
+
pep_category?: PepCategory | null;
|
|
272
|
+
pep_description?: string | null;
|
|
250
273
|
}): Promise<ApiResponse>;
|
|
251
|
-
getKycInfo(): Promise<ApiResponse
|
|
274
|
+
getKycInfo(): Promise<ApiResponse<KycInfo>>;
|
|
252
275
|
verifyKyc(): Promise<KycVerified>;
|
|
253
276
|
}
|
|
254
277
|
|
|
@@ -303,6 +326,7 @@ declare class Plaid {
|
|
|
303
326
|
interface ApiClientOptions {
|
|
304
327
|
baseUrl: string;
|
|
305
328
|
token?: string;
|
|
329
|
+
apiKey?: string;
|
|
306
330
|
}
|
|
307
331
|
interface CustomRequestInit extends Omit<RequestInit, "headers" | "method" | "body"> {
|
|
308
332
|
headers?: Record<string, string>;
|
|
@@ -311,6 +335,7 @@ type Method = "get" | "post" | "put" | "patch" | "delete";
|
|
|
311
335
|
declare class ApiClient {
|
|
312
336
|
private static instance;
|
|
313
337
|
private token?;
|
|
338
|
+
private apiKey?;
|
|
314
339
|
private unauthorizedListeners;
|
|
315
340
|
baseUrl: string;
|
|
316
341
|
accounts: Account;
|
|
@@ -340,6 +365,8 @@ declare class ApiClient {
|
|
|
340
365
|
request(method: Method, endpoint: string, body?: object, options?: CustomRequestInit): Promise<ApiResponse>;
|
|
341
366
|
setToken(token: string): void;
|
|
342
367
|
getToken(): string | undefined;
|
|
368
|
+
setApiKey(apiKey: string): void;
|
|
369
|
+
getApiKey(): string | undefined;
|
|
343
370
|
onUnauthorized(listener: (url: string) => void): void;
|
|
344
371
|
offUnauthorized(listener: (url: string) => void): void;
|
|
345
372
|
private emit401Event;
|