@bloque/sdk-accounts 0.1.11 → 0.1.12
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/breb/types.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/breb/types.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const __rslib_import_meta_url__="u"<typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,t)=>{for(var a in t)__webpack_require__.o(t,a)&&!__webpack_require__.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{mapUs2AccountFromWire:()=>mapUs2AccountFromWire,mapBrebAccountFromWire:()=>mapBrebAccountFromWire,mapUsAccountFromWire:()=>mapUsAccountFromWire,mapBancolombiaAccountFromWire:()=>mapBancolombiaAccountFromWire,mapVirtualAccountFromWire:()=>mapVirtualAccountFromWire,VirtualClient:()=>VirtualClient,BancolombiaClient:()=>BancolombiaClient,mapExternalUsBankAccountFromWire:()=>mapExternalUsBankAccountFromWire,ExternalUsBankClient:()=>ExternalUsBankClient,AccountsClient:()=>AccountsClient,PolygonClient:()=>PolygonClient,UsClient:()=>UsClient,CardClient:()=>CardClient,mapCardAccountFromWire:()=>mapCardAccountFromWire,mapPolygonAccountFromWire:()=>mapPolygonAccountFromWire,Us2Client:()=>Us2Client,BrebClient:()=>BrebClient});const sdk_core_namespaceObject=require("@bloque/sdk-core");function mapBancolombiaAccountFromWire(e){return{urn:e.urn,id:e.id,referenceCode:e.details.reference_code,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:"balance"in e&&e.balance?e.balance:void 0}}class BancolombiaClient extends sdk_core_namespaceObject.BaseClient{async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","bancolombia"),t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(e=>({...this._mapAccountResponse(e),balance:e.balance}))}}async create(e={},t){let a={holder_urn:e?.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{},metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/bancolombia",body:a,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return t?.waitLedger?this._waitForActiveStatus(n.urn,t.timeout||6e4):n}async _waitForActiveStatus(e,t){let a=Date.now();for(;;){if(Date.now()-a>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let r=(await this.list({urn:e})).accounts[0];if(!r)throw Error(`Account not found. URN: ${e}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${e}`);await new Promise(e=>setTimeout(e,2e3))}}async updateMetadata(e){let t={metadata:e.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(a.result.account)}async updateName(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{metadata:{name:t}}});return this._mapAccountResponse(a.result.account)}async activate(e){return this._updateStatus(e,"active")}async freeze(e){return this._updateStatus(e,"frozen")}async disable(e){return this._updateStatus(e,"disabled")}async _updateStatus(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{status:t}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(e){return mapBancolombiaAccountFromWire(e)}}function mapBrebAccountFromWire(e){return{id:e.id,urn:e.urn,ownerUrn:e.owner_urn,medium:"breb",remoteKeyId:e.details.remote_key_id,accountId:e.details.account_id,keyType:e.details.key.key_type,key:e.details.key.key_value,displayName:e.details.display_name??null,status:e.status,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,details:e.details,balance:"balance"in e&&e.balance?e.balance:void 0}}function mapDecodedQrFromWire(e){return{amount:e.amount,additionalInfo:e.additional_info?{transactionPurpose:e.additional_info.transaction_purpose,terminalLabel:e.additional_info.terminal_label,invoiceNumber:e.additional_info.invoice_number,mobilePhoneNumber:e.additional_info.mobile_phone_number,storeLabel:e.additional_info.store_label,loyaltyLabel:e.additional_info.loyalty_label,referenceLabel:e.additional_info.reference_label,customerLabel:e.additional_info.customer_label,customerInfo:e.additional_info.customer_info,channelPresentation:e.additional_info.channel_presentation}:null,key:e.key?{keyType:e.key.key_type,keyValue:e.key.key_value}:null,qrCodeData:e.qr_code_data,status:e.status,acquirerNetworkIdentifier:e.acquirer_network_identifier,merchant:e.merchant?{merchantCategoryCode:e.merchant.merchant_category_code,merchantCountry:e.merchant.merchant_country,merchantName:e.merchant.merchant_name,merchantCity:e.merchant.merchant_city,merchantPostCode:e.merchant.merchant_post_code}:null,channel:e.channel,qrCodeReference:e.qr_code_reference,type:e.type,resolutionId:e.resolution_id,resolution:e.resolution}}class BrebClient extends sdk_core_namespaceObject.BaseClient{mapError(e){if(e instanceof sdk_core_namespaceObject.BloqueAPIError){let t=e.response;return{code:t?.extra_details?.provider_code??e.code??null,message:e.message}}return e instanceof Error?{code:null,message:e.message}:{code:null,message:"Unknown BRE-B error"}}async createKey(e){try{let t=this.httpClient.urn;if(!t?.trim())throw Error("Holder URN is required");if(!e.key?.trim())throw Error("BRE-B key value is required");let a=await this.httpClient.request({method:"POST",path:"/api/mediums/breb",body:{holder_urn:t,input:{key_type:e.keyType,key_value:e.key,display_name:e.displayName},webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,metadata:{source:"sdk-typescript",...e.metadata}}});return{data:mapBrebAccountFromWire(a.result.account),error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async resolveKey(e){try{if(!e.key?.trim())throw Error("BRE-B key value is required");return{data:(await this.httpClient.request({method:"POST",path:"/api/mediums/breb/resolve-key",body:{key_type:e.keyType,key:e.key}})).result,error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async decodeQr(e){try{if(!e.qrCodeData?.trim())throw Error("BRE-B QR code data is required");let t=await this.httpClient.request({method:"POST",path:"/api/mediums/breb/decode-qr",body:{qr_code_data:e.qrCodeData}});return{data:mapDecodedQrFromWire(t.result),error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async deleteKey(e){try{if(!e.accountUrn?.trim())throw Error("BRE-B account URN is required");let t=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(e.accountUrn)}`,body:{status:"deleted"}});return{data:{deleted:!0,accountUrn:t.result.account.urn,keyId:t.result.account.details.id,status:"deleted"},error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async suspendKey(e){try{if(!e.accountUrn?.trim())throw Error("BRE-B account URN is required");let t=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(e.accountUrn)}`,body:{status:"frozen"}});return{data:{accountUrn:t.result.account.urn,keyId:t.result.account.details.id,keyStatus:t.result.account.details.status,status:"frozen"},error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async activateKey(e){try{if(!e.accountUrn?.trim())throw Error("BRE-B account URN is required");let t=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(e.accountUrn)}`,body:{status:"active"}});return{data:{accountUrn:t.result.account.urn,keyId:t.result.account.details.id,keyStatus:t.result.account.details.status,status:"active"},error:null}}catch(e){return{data:null,error:this.mapError(e)}}}}function mapCardAccountFromWire(e){return{urn:e.urn,id:e.id,lastFour:e.details.card_last_four,productType:e.details.card_product_type,status:e.status,cardType:e.details.card_type,detailsUrl:e.details.card_url_details,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}}class CardClient extends sdk_core_namespaceObject.BaseClient{async create(e={},t){let a={holder_urn:e?.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{create:{card_type:"VIRTUAL"}},metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/card",body:a,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return t?.waitLedger?this._waitForActiveStatus(n.urn,t.timeout||6e4):n}async _waitForActiveStatus(e,t){let a=Date.now();for(;;){if(Date.now()-a>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let r=(await this.list({urn:e})).accounts[0];if(!r)throw Error(`Account not found. URN: ${e}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${e}`);await new Promise(e=>setTimeout(e,2e3))}}async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","card"),t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(e=>({urn:e.urn,id:e.id,lastFour:e.details.card_last_four,productType:e.details.card_product_type,status:e.status,cardType:e.details.card_type,detailsUrl:e.details.card_url_details,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}))}}async movements(e){let t=new URLSearchParams,a=e.asset||"DUSD/6";if(!(0,sdk_core_namespaceObject.isSupportedAsset)(a))throw Error(`Invalid asset type "${a}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);t.set("asset",a),void 0!==e.limit&&t.set("limit",e.limit.toString()),e.before&&t.set("before",e.before),e.after&&t.set("after",e.after),e.reference&&t.set("reference",e.reference),e.direction&&t.set("direction",e.direction),void 0!==e.collapsed_view&&t.set("collapsed_view",String(e.collapsed_view)),e.pocket&&t.set("pocket",e.pocket),e.next&&t.set("next",e.next);let r=t.toString(),n=`/api/accounts/${e.urn}/movements${r?`?${r}`:""}`,o=await this.httpClient.request({method:"GET",path:n});return{data:o.data,pageSize:o.page_size,hasMore:o.has_more,next:o.next}}async balance(e){return(await this.httpClient.request({method:"GET",path:`/api/accounts/${e.urn}/balance`})).balance}async update(e){let t={...e.metadata&&{metadata:e.metadata},...e.status&&{status:e.status},...e.webhookUrl&&{webhook_url:e.webhookUrl},...e.ledgerId&&{ledger_account_id:e.ledgerId}},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(a.result.account)}async updateMetadata(e){let t={metadata:e.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(a.result.account)}async updateName(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{metadata:{name:t}}});return this._mapAccountResponse(a.result.account)}async activate(e){return this._updateStatus(e,"active")}async freeze(e){return this._updateStatus(e,"frozen")}async disable(e){return this._updateStatus(e,"disabled")}async tokenizeApple(e,t){let a={certificates:t.certificates,nonce:t.nonce,nonce_signature:t.nonceSignature},r=await this.httpClient.request({method:"POST",path:`/api/accounts/${e}/tokenize/apple`,body:a});return{activationData:r.result.tokenization.activation_data,encryptedPassData:r.result.tokenization.encrypted_pass_data,ephemeralPublicKey:r.result.tokenization.ephemeral_public_key}}async tokenizeGoogle(e,t){let a={device_id:t.deviceId,wallet_account_id:t.walletAccountId};return{opc:(await this.httpClient.request({method:"POST",path:`/api/accounts/${e}/tokenize/google`,body:a})).result.tokenization.opc}}async _updateStatus(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{status:t}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(e){return mapCardAccountFromWire(e)}}function mapBankAddressFromWire(e){if(e)return{streetLine1:e.street_line_1,...void 0!==e.street_line_2?{streetLine2:e.street_line_2}:{},city:e.city,state:e.state,zip:e.zip,...void 0!==e.country?{country:e.country}:{}}}function mapExternalUsBankAccountFromWire(e){return{urn:e.urn,id:e.id,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance,details:{id:e.details.id,linkStatus:e.details.link_status,braleAccountId:e.details.brale_account_id,braleAddressId:e.details.brale_address_id,linkToken:e.details.link_token,linkTokenExpiration:e.details.link_token_expiration,linkUrl:e.details.link_url,jwt:e.details.jwt,bankAccountLast4:e.details.bank_account_last4,bankName:e.details.bank_name,failureReason:e.details.failure_reason,owner:e.details.owner,routingNumber:e.details.routing_number,accountNumber:e.details.account_number,accountType:e.details.account_type,bankAddress:mapBankAddressFromWire(e.details.bank_address),beneficiaryAddress:mapBankAddressFromWire(e.details.beneficiary_address),transferTypes:e.details.transfer_types,needsUpdate:e.details.needs_update,lastUpdated:e.details.last_updated}}}class ExternalUsBankClient extends sdk_core_namespaceObject.BaseClient{async create(e,t){let a={holder_urn:e.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{label:e.label,...void 0!==e.returnUrl?{return_url:e.returnUrl}:{},...void 0!==e.state?{state:e.state}:{}},metadata:{source:"sdk-typescript",...e.metadata}};return mapExternalUsBankAccountFromWire((await this.httpClient.request({method:"POST",path:"/api/mediums/external-us-bank",body:a})).result.account)}async exchangePublicToken(e){let t={input:{public_token:e.publicToken}};return mapExternalUsBankAccountFromWire((await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t})).result.account)}async pull(e){if(!e?.urn?.trim())throw Error("Bank account URN is required");if("string"!=typeof e.amount||""===e.amount.trim())throw Error('Amount is required and must be a string (e.g. "100.00")');let t={amount:e.amount,...void 0!==e.idempotencyKey?{idempotency_key:e.idempotencyKey}:{}},a=await this.httpClient.request({method:"POST",path:`/api/mediums/external-us-bank/${encodeURIComponent(e.urn)}/pull`,body:t});return{orderSig:a.result?.order_sig,graphId:a.result?.graph_id,status:a.result?.status,execution:a.result?.execution,requestId:a.req_id}}}function mapPolygonAccountFromWire(e){return{urn:e.urn,id:e.id,address:e.details.address,network:e.details.network,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:"balance"in e&&e.balance?e.balance:void 0}}class PolygonClient extends sdk_core_namespaceObject.BaseClient{async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","polygon"),t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(e=>({...this._mapAccountResponse(e),balance:e.balance}))}}async create(e={},t){let a={holder_urn:e.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{},metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/polygon",body:a,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return t?.waitLedger?this._waitForActiveStatus(n.urn,t.timeout||6e4):n}async _waitForActiveStatus(e,t){let a=Date.now();for(;;){if(Date.now()-a>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let r=(await this.list({urn:e})).accounts[0];if(!r)throw Error(`Account not found. URN: ${e}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${e}`);await new Promise(e=>setTimeout(e,2e3))}}async updateMetadata(e){let t={metadata:e.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(a.result.account)}async activate(e){return this._updateStatus(e,"active")}async freeze(e){return this._updateStatus(e,"frozen")}async disable(e){return this._updateStatus(e,"disabled")}async _updateStatus(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{status:t}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(e){return mapPolygonAccountFromWire(e)}}function mapUsAccountFromWire(e){return{urn:e.urn,id:e.id,type:e.details.type,firstName:e.details.first_name,middleName:e.details.middle_name,lastName:e.details.last_name,email:e.details.email,phone:e.details.phone,address:{streetLine1:e.details.address.street_line_1,streetLine2:e.details.address.street_line_2,city:e.details.address.city,state:e.details.address.state,postalCode:e.details.address.postal_code,country:e.details.address.country},birthDate:e.details.birth_date,accountNumber:e.details.account_number,routingNumber:e.details.routing_number,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}}class UsClient extends sdk_core_namespaceObject.BaseClient{async getTosLink(e){let t=new URLSearchParams({redirect_uri:e.redirectUri}),a=(await this.httpClient.request({method:"POST",path:`/api/mediums/us-account/tos-link?${t.toString()}`})).result.url;try{let t=new URL(a);t.searchParams.has("redirect_uri")||(t.searchParams.set("redirect_uri",e.redirectUri),a=t.toString())}catch{let t=a.includes("?")?"&":"?";/[?&]redirect_uri=/.test(a)||(a=`${a}${t}redirect_uri=${encodeURIComponent(e.redirectUri)}`)}return{url:a}}async create(e,t){let a={street_line_1:e.address.streetLine1,street_line_2:e.address.streetLine2,city:e.address.city,state:e.address.state,postal_code:e.address.postalCode,country:e.address.country},r={type:e.type,first_name:e.firstName,middle_name:e.middleName,last_name:e.lastName,email:e.email,phone:e.phone,address:a,birth_date:e.birthDate,tax_identification_number:e.taxIdentificationNumber,gov_id_country:e.govIdCountry,gov_id_image_front:e.govIdImageFront,signed_agreement_id:e.signedAgreementId},n={holder_urn:e.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:r,metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},o=await this.httpClient.request({method:"POST",path:"/api/mediums/us-account",body:n,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),s=this._mapAccountResponse(o.result.account);return t?.waitLedger?this._waitForActiveStatus(s.urn,t.timeout||6e4):s}async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","us-account"),t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(e=>({urn:e.urn,id:e.id,type:e.details.type,firstName:e.details.first_name,middleName:e.details.middle_name,lastName:e.details.last_name,email:e.details.email,phone:e.details.phone,address:{streetLine1:e.details.address.street_line_1,streetLine2:e.details.address.street_line_2,city:e.details.address.city,state:e.details.address.state,postalCode:e.details.address.postal_code,country:e.details.address.country},birthDate:e.details.birth_date,accountNumber:e.details.account_number,routingNumber:e.details.routing_number,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}))}}async updateMetadata(e){let t={metadata:e.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(a.result.account)}async activate(e){return this._updateStatus(e,"active")}async freeze(e){return this._updateStatus(e,"frozen")}async disable(e){return this._updateStatus(e,"disabled")}async _waitForActiveStatus(e,t){let a=Date.now();for(;;){if(Date.now()-a>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let r=(await this.list({urn:e})).accounts[0];if(!r)throw Error(`Account not found. URN: ${e}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${e}`);await new Promise(e=>setTimeout(e,2e3))}}async _updateStatus(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{status:t}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(e){return mapUsAccountFromWire(e)}}function mapUs2AccountFromWire(e){return{urn:e.urn,id:e.id,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance,details:{id:e.details.id,userId:e.details.user_id,virtualAccountId:e.details.virtual_account_id,type:e.details.type,currency:e.details.currency}}}class Us2Client extends sdk_core_namespaceObject.BaseClient{async create(e,t){let a={type:e.type,email:e.email,phone:e.phone,proof_of_address:e.proofOfAddress,business_formation_document:e.businessFormationDocument,tax_id:e.taxId,address:e.address?{street:e.address.street,city:e.address.city,state:e.address.state,postal_code:e.address.postalCode,country:e.address.country}:void 0},r={holder_urn:e.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:a,metadata:{source:"sdk-typescript",...e.metadata}};return mapUs2AccountFromWire((await this.httpClient.request({method:"POST",path:"/api/mediums/us2-account",body:r})).result.account)}async list(e={}){let t=e.holderUrn||this.httpClient.urn,a=new URLSearchParams;return a.append("medium","us2-account"),t&&a.append("holder_urn",t),e.urn&&a.append("urn",e.urn),{accounts:(await this.httpClient.request({method:"GET",path:`/api/accounts?${a.toString()}`})).accounts.map(e=>mapUs2AccountFromWire(e))}}}function mapVirtualAccountFromWire(e){return{urn:e.urn,id:e.id,firstName:e.details.first_name,lastName:e.details.last_name,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:"balance"in e&&e.balance?e.balance:void 0}}class VirtualClient extends sdk_core_namespaceObject.BaseClient{async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","virtual"),t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(e=>({...this._mapAccountResponse(e),balance:e.balance}))}}async create(e,t){let a={holder_urn:e.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{},metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/virtual",body:a,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return t?.waitLedger?this._waitForActiveStatus(n.urn,t.timeout||6e4):n}async _waitForActiveStatus(e,t){let a=Date.now();for(;;){if(Date.now()-a>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let r=(await this.list({urn:e})).accounts[0];if(!r)throw Error(`Account not found. URN: ${e}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${e}`);await new Promise(e=>setTimeout(e,2e3))}}async updateMetadata(e){let t={metadata:e.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(a.result.account)}async activate(e){return this._updateStatus(e,"active")}async freeze(e){return this._updateStatus(e,"frozen")}async disable(e){return this._updateStatus(e,"disabled")}async _updateStatus(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{status:t}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(e){return mapVirtualAccountFromWire(e)}}class AccountsClient extends sdk_core_namespaceObject.BaseClient{bancolombia;breb;card;externalUsBank;polygon;us;us2;virtual;constructor(e){super(e),this.bancolombia=new BancolombiaClient(this.httpClient),this.breb=new BrebClient(this.httpClient),this.card=new CardClient(this.httpClient),this.externalUsBank=new ExternalUsBankClient(this.httpClient),this.polygon=new PolygonClient(this.httpClient),this.us=new UsClient(this.httpClient),this.us2=new Us2Client(this.httpClient),this.virtual=new VirtualClient(this.httpClient)}async balance(e){if(!e?.trim())throw Error("Account URN is required");return(await this.httpClient.request({method:"GET",path:`/api/accounts/${e}/balance`})).balance}async balances(){return(await this.httpClient.request({method:"GET",path:"/api/accounts/balances"})).balance}async get(e){if(!e?.trim())throw Error("Account URN is required");let t=await this.httpClient.request({method:"GET",path:`/api/accounts/${e}`});return this._mapByMedium(t.account)}async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;t&&a.append("holder_urn",t);let r=a.toString(),n=r?`/api/accounts?${r}`:"/api/accounts";return{accounts:(await this.httpClient.request({method:"GET",path:n})).accounts.map(e=>this._mapByMedium(e))}}async transfer(e,t){let a=e.asset||"DUSD/6";if(!(0,sdk_core_namespaceObject.isSupportedAsset)(a))throw Error(`Invalid asset type "${a}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let r={destination_account_urn:e.destinationUrn,amount:e.amount,asset:a,metadata:e.metadata},n=await this.httpClient.request({method:"POST",path:`/api/accounts/${e.sourceUrn}/transfer`,body:r,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0});return{queueId:n.result.queue_id,status:n.result.status,message:n.result.message}}async batchTransfer(e,t){if(!e.operations||0===e.operations.length)throw Error("At least one operation is required");if(!e.reference)throw Error("Batch reference is required");for(let t of e.operations)if(!(0,sdk_core_namespaceObject.isSupportedAsset)(t.asset))throw Error(`Invalid asset type "${t.asset}" in operation "${t.reference}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let a={operations:e.operations.map(e=>({from_account_urn:e.fromUrn,to_account_urn:e.toUrn,reference:e.reference,amount:e.amount,asset:e.asset,metadata:e.metadata})),reference:e.reference,metadata:e.metadata,webhook_url:e.webhookUrl},r=await this.httpClient.request({method:"POST",path:"/api/accounts/batch/transfer",body:a,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0});return{chunks:r.result.chunks.map(e=>({queueId:e.queue_id,status:e.status,message:e.message})),totalOperations:r.result.total_operations,totalChunks:r.result.total_chunks}}async movements(e){if(!e.urn)throw Error("Account URN is required");let t=e.asset||"DUSD/6";if(!(0,sdk_core_namespaceObject.isSupportedAsset)(t))throw Error(`Invalid asset type "${t}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let a=new URLSearchParams;a.set("asset",t),void 0!==e.limit&&a.set("limit",e.limit.toString()),e.before&&a.set("before",e.before),e.after&&a.set("after",e.after),e.reference&&a.set("reference",e.reference),e.direction&&a.set("direction",e.direction),void 0!==e.collapsed_view&&a.set("collapsed_view",String(e.collapsed_view)),e.pocket&&a.set("pocket",e.pocket),e.next&&a.set("next",e.next);let r=`/api/accounts/${e.urn}/movements?${a.toString()}`,n=await this.httpClient.request({method:"GET",path:r});return{data:n.data.map(e=>({amount:e.amount,asset:e.asset,fromAccountId:e.from_account_id,toAccountId:e.to_account_id,direction:e.direction,type:e.type,reference:e.reference,status:e.status,railName:e.rail_name,details:e.details,createdAt:e.created_at})),pageSize:n.page_size,hasMore:n.has_more,next:n.next}}async transactions(e={}){let t=e.asset||"DUSD/6";if(!(0,sdk_core_namespaceObject.isSupportedAsset)(t))throw Error(`Invalid asset type "${t}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let a=new URLSearchParams;a.set("asset",t),void 0!==e.limit&&a.set("limit",e.limit.toString()),e.before&&a.set("before",e.before),e.after&&a.set("after",e.after),e.reference&&a.set("reference",e.reference),e.direction&&a.set("direction",e.direction),void 0!==e.collapsed_view&&a.set("collapsed_view",String(e.collapsed_view)),e.pocket&&a.set("pocket",e.pocket),e.next&&a.set("next",e.next);let r=await this.httpClient.request({method:"GET",path:`/api/accounts/transactions?${a.toString()}`});return{data:r.data.map(e=>({amount:e.amount,asset:e.asset,fromAccountId:e.from_account_id,toAccountId:e.to_account_id,direction:e.direction,reference:e.reference,status:e.status,railName:e.rail_name,details:e.details??{},createdAt:e.created_at,type:e.type})),pageSize:r.page_size,hasMore:r.has_more,next:r.next}}_mapByMedium(e){switch(e.medium){case"card":return mapCardAccountFromWire(e);case"virtual":return mapVirtualAccountFromWire(e);case"polygon":return mapPolygonAccountFromWire(e);case"bancolombia":return mapBancolombiaAccountFromWire(e);case"breb":return mapBrebAccountFromWire(e);case"external-us-bank":return mapExternalUsBankAccountFromWire(e);case"us-account":return mapUsAccountFromWire(e);case"us2-account":return mapUs2AccountFromWire(e);default:throw Error(`Unknown account medium: ${e.medium}`)}}}for(var __rspack_i in exports.AccountsClient=__webpack_exports__.AccountsClient,exports.BancolombiaClient=__webpack_exports__.BancolombiaClient,exports.BrebClient=__webpack_exports__.BrebClient,exports.CardClient=__webpack_exports__.CardClient,exports.ExternalUsBankClient=__webpack_exports__.ExternalUsBankClient,exports.PolygonClient=__webpack_exports__.PolygonClient,exports.Us2Client=__webpack_exports__.Us2Client,exports.UsClient=__webpack_exports__.UsClient,exports.VirtualClient=__webpack_exports__.VirtualClient,exports.mapBancolombiaAccountFromWire=__webpack_exports__.mapBancolombiaAccountFromWire,exports.mapBrebAccountFromWire=__webpack_exports__.mapBrebAccountFromWire,exports.mapCardAccountFromWire=__webpack_exports__.mapCardAccountFromWire,exports.mapExternalUsBankAccountFromWire=__webpack_exports__.mapExternalUsBankAccountFromWire,exports.mapPolygonAccountFromWire=__webpack_exports__.mapPolygonAccountFromWire,exports.mapUs2AccountFromWire=__webpack_exports__.mapUs2AccountFromWire,exports.mapUsAccountFromWire=__webpack_exports__.mapUsAccountFromWire,exports.mapVirtualAccountFromWire=__webpack_exports__.mapVirtualAccountFromWire,__webpack_exports__)-1===["AccountsClient","BancolombiaClient","BrebClient","CardClient","ExternalUsBankClient","PolygonClient","Us2Client","UsClient","VirtualClient","mapBancolombiaAccountFromWire","mapBrebAccountFromWire","mapCardAccountFromWire","mapExternalUsBankAccountFromWire","mapPolygonAccountFromWire","mapUs2AccountFromWire","mapUsAccountFromWire","mapVirtualAccountFromWire"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
|
|
1
|
+
"use strict";const __rslib_import_meta_url__="u"<typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,t)=>{for(var a in t)__webpack_require__.o(t,a)&&!__webpack_require__.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{mapUs2AccountFromWire:()=>mapUs2AccountFromWire,mapBrebAccountFromWire:()=>mapBrebAccountFromWire,mapUsAccountFromWire:()=>mapUsAccountFromWire,mapBancolombiaAccountFromWire:()=>mapBancolombiaAccountFromWire,mapVirtualAccountFromWire:()=>mapVirtualAccountFromWire,VirtualClient:()=>VirtualClient,BancolombiaClient:()=>BancolombiaClient,mapExternalUsBankAccountFromWire:()=>mapExternalUsBankAccountFromWire,ExternalUsBankClient:()=>ExternalUsBankClient,AccountsClient:()=>AccountsClient,PolygonClient:()=>PolygonClient,UsClient:()=>UsClient,CardClient:()=>CardClient,mapCardAccountFromWire:()=>mapCardAccountFromWire,mapPolygonAccountFromWire:()=>mapPolygonAccountFromWire,Us2Client:()=>Us2Client,BrebClient:()=>BrebClient});const sdk_core_namespaceObject=require("@bloque/sdk-core");function mapBancolombiaAccountFromWire(e){return{urn:e.urn,id:e.id,referenceCode:e.details.reference_code,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:"balance"in e&&e.balance?e.balance:void 0}}class BancolombiaClient extends sdk_core_namespaceObject.BaseClient{async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","bancolombia"),t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(e=>({...this._mapAccountResponse(e),balance:e.balance}))}}async create(e={},t){let a={holder_urn:e?.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{},metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/bancolombia",body:a,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return t?.waitLedger?this._waitForActiveStatus(n.urn,t.timeout||6e4):n}async _waitForActiveStatus(e,t){let a=Date.now();for(;;){if(Date.now()-a>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let r=(await this.list({urn:e})).accounts[0];if(!r)throw Error(`Account not found. URN: ${e}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${e}`);await new Promise(e=>setTimeout(e,2e3))}}async updateMetadata(e){let t={metadata:e.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(a.result.account)}async updateName(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{metadata:{name:t}}});return this._mapAccountResponse(a.result.account)}async activate(e){return this._updateStatus(e,"active")}async freeze(e){return this._updateStatus(e,"frozen")}async disable(e){return this._updateStatus(e,"disabled")}async _updateStatus(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{status:t}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(e){return mapBancolombiaAccountFromWire(e)}}function mapBrebAccountFromWire(e){return{id:e.id,urn:e.urn,ownerUrn:e.owner_urn,medium:"breb",remoteKeyId:e.details.remote_key_id,accountId:e.details.account_id,keyType:e.details.key.key_type,key:e.details.key.key_value,displayName:e.details.display_name??null,status:e.status,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,details:e.details,balance:"balance"in e&&e.balance?e.balance:void 0}}function mapDecodedQrFromWire(e){return{amount:e.amount,additionalInfo:e.additional_info?{transactionPurpose:e.additional_info.transaction_purpose,terminalLabel:e.additional_info.terminal_label,invoiceNumber:e.additional_info.invoice_number,mobilePhoneNumber:e.additional_info.mobile_phone_number,storeLabel:e.additional_info.store_label,loyaltyLabel:e.additional_info.loyalty_label,referenceLabel:e.additional_info.reference_label,customerLabel:e.additional_info.customer_label,customerInfo:e.additional_info.customer_info,channelPresentation:e.additional_info.channel_presentation}:null,key:e.key?{keyType:e.key.key_type,keyValue:e.key.key_value}:null,qrCodeData:e.qr_code_data,status:e.status,acquirerNetworkIdentifier:e.acquirer_network_identifier,merchant:e.merchant?{merchantCategoryCode:e.merchant.merchant_category_code,merchantCountry:e.merchant.merchant_country,merchantName:e.merchant.merchant_name,merchantCity:e.merchant.merchant_city,merchantPostCode:e.merchant.merchant_post_code}:null,channel:e.channel,qrCodeReference:e.qr_code_reference,type:e.type,resolutionId:e.resolution_id,resolution:e.resolution}}class BrebClient extends sdk_core_namespaceObject.BaseClient{mapError(e){if(e instanceof sdk_core_namespaceObject.BloqueAPIError){let t=e.response;return{code:t?.extra_details?.provider_code??e.code??null,message:e.message}}return e instanceof Error?{code:null,message:e.message}:{code:null,message:"Unknown BRE-B error"}}async createKey(e){try{let t=this.httpClient.urn;if(!t?.trim())throw Error("Holder URN is required");if(!e.key?.trim())throw Error("BRE-B key value is required");let a=await this.httpClient.request({method:"POST",path:"/api/mediums/breb",body:{holder_urn:t,input:{key_type:e.keyType,key_value:e.key,display_name:e.displayName},webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,metadata:{source:"sdk-typescript",...e.metadata}}});return{data:mapBrebAccountFromWire(a.result.account),error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async resolveKey(e){try{if(!e.key?.trim())throw Error("BRE-B key value is required");return{data:(await this.httpClient.request({method:"POST",path:"/api/mediums/breb/resolve-key",body:{...e.keyType&&{key_type:e.keyType},key:e.key}})).result,error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async decodeQr(e){try{if(!e.qrCodeData?.trim())throw Error("BRE-B QR code data is required");let t=await this.httpClient.request({method:"POST",path:"/api/mediums/breb/decode-qr",body:{qr_code_data:e.qrCodeData}});return{data:mapDecodedQrFromWire(t.result),error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async deleteKey(e){try{if(!e.accountUrn?.trim())throw Error("BRE-B account URN is required");let t=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(e.accountUrn)}`,body:{status:"deleted"}});return{data:{deleted:!0,accountUrn:t.result.account.urn,keyId:t.result.account.details.id,status:"deleted"},error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async suspendKey(e){try{if(!e.accountUrn?.trim())throw Error("BRE-B account URN is required");let t=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(e.accountUrn)}`,body:{status:"frozen"}});return{data:{accountUrn:t.result.account.urn,keyId:t.result.account.details.id,keyStatus:t.result.account.details.status,status:"frozen"},error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async activateKey(e){try{if(!e.accountUrn?.trim())throw Error("BRE-B account URN is required");let t=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(e.accountUrn)}`,body:{status:"active"}});return{data:{accountUrn:t.result.account.urn,keyId:t.result.account.details.id,keyStatus:t.result.account.details.status,status:"active"},error:null}}catch(e){return{data:null,error:this.mapError(e)}}}}function mapCardAccountFromWire(e){return{urn:e.urn,id:e.id,lastFour:e.details.card_last_four,productType:e.details.card_product_type,status:e.status,cardType:e.details.card_type,detailsUrl:e.details.card_url_details,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}}class CardClient extends sdk_core_namespaceObject.BaseClient{async create(e={},t){let a={holder_urn:e?.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{create:{card_type:"VIRTUAL"}},metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/card",body:a,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return t?.waitLedger?this._waitForActiveStatus(n.urn,t.timeout||6e4):n}async _waitForActiveStatus(e,t){let a=Date.now();for(;;){if(Date.now()-a>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let r=(await this.list({urn:e})).accounts[0];if(!r)throw Error(`Account not found. URN: ${e}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${e}`);await new Promise(e=>setTimeout(e,2e3))}}async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","card"),t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(e=>({urn:e.urn,id:e.id,lastFour:e.details.card_last_four,productType:e.details.card_product_type,status:e.status,cardType:e.details.card_type,detailsUrl:e.details.card_url_details,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}))}}async movements(e){let t=new URLSearchParams,a=e.asset||"DUSD/6";if(!(0,sdk_core_namespaceObject.isSupportedAsset)(a))throw Error(`Invalid asset type "${a}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);t.set("asset",a),void 0!==e.limit&&t.set("limit",e.limit.toString()),e.before&&t.set("before",e.before),e.after&&t.set("after",e.after),e.reference&&t.set("reference",e.reference),e.direction&&t.set("direction",e.direction),void 0!==e.collapsed_view&&t.set("collapsed_view",String(e.collapsed_view)),e.pocket&&t.set("pocket",e.pocket),e.next&&t.set("next",e.next);let r=t.toString(),n=`/api/accounts/${e.urn}/movements${r?`?${r}`:""}`,o=await this.httpClient.request({method:"GET",path:n});return{data:o.data,pageSize:o.page_size,hasMore:o.has_more,next:o.next}}async balance(e){return(await this.httpClient.request({method:"GET",path:`/api/accounts/${e.urn}/balance`})).balance}async update(e){let t={...e.metadata&&{metadata:e.metadata},...e.status&&{status:e.status},...e.webhookUrl&&{webhook_url:e.webhookUrl},...e.ledgerId&&{ledger_account_id:e.ledgerId}},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(a.result.account)}async updateMetadata(e){let t={metadata:e.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(a.result.account)}async updateName(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{metadata:{name:t}}});return this._mapAccountResponse(a.result.account)}async activate(e){return this._updateStatus(e,"active")}async freeze(e){return this._updateStatus(e,"frozen")}async disable(e){return this._updateStatus(e,"disabled")}async tokenizeApple(e,t){let a={certificates:t.certificates,nonce:t.nonce,nonce_signature:t.nonceSignature},r=await this.httpClient.request({method:"POST",path:`/api/accounts/${e}/tokenize/apple`,body:a});return{activationData:r.result.tokenization.activation_data,encryptedPassData:r.result.tokenization.encrypted_pass_data,ephemeralPublicKey:r.result.tokenization.ephemeral_public_key}}async tokenizeGoogle(e,t){let a={device_id:t.deviceId,wallet_account_id:t.walletAccountId};return{opc:(await this.httpClient.request({method:"POST",path:`/api/accounts/${e}/tokenize/google`,body:a})).result.tokenization.opc}}async _updateStatus(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{status:t}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(e){return mapCardAccountFromWire(e)}}function mapBankAddressFromWire(e){if(e)return{streetLine1:e.street_line_1,...void 0!==e.street_line_2?{streetLine2:e.street_line_2}:{},city:e.city,state:e.state,zip:e.zip,...void 0!==e.country?{country:e.country}:{}}}function mapExternalUsBankAccountFromWire(e){return{urn:e.urn,id:e.id,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance,details:{id:e.details.id,linkStatus:e.details.link_status,braleAccountId:e.details.brale_account_id,braleAddressId:e.details.brale_address_id,linkToken:e.details.link_token,linkTokenExpiration:e.details.link_token_expiration,linkUrl:e.details.link_url,jwt:e.details.jwt,bankAccountLast4:e.details.bank_account_last4,bankName:e.details.bank_name,failureReason:e.details.failure_reason,owner:e.details.owner,routingNumber:e.details.routing_number,accountNumber:e.details.account_number,accountType:e.details.account_type,bankAddress:mapBankAddressFromWire(e.details.bank_address),beneficiaryAddress:mapBankAddressFromWire(e.details.beneficiary_address),transferTypes:e.details.transfer_types,needsUpdate:e.details.needs_update,lastUpdated:e.details.last_updated}}}class ExternalUsBankClient extends sdk_core_namespaceObject.BaseClient{async create(e,t){let a={holder_urn:e.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{label:e.label,...void 0!==e.returnUrl?{return_url:e.returnUrl}:{},...void 0!==e.state?{state:e.state}:{}},metadata:{source:"sdk-typescript",...e.metadata}};return mapExternalUsBankAccountFromWire((await this.httpClient.request({method:"POST",path:"/api/mediums/external-us-bank",body:a})).result.account)}async exchangePublicToken(e){let t={input:{public_token:e.publicToken}};return mapExternalUsBankAccountFromWire((await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t})).result.account)}async pull(e){if(!e?.urn?.trim())throw Error("Bank account URN is required");if("string"!=typeof e.amount||""===e.amount.trim())throw Error('Amount is required and must be a string (e.g. "100.00")');let t={amount:e.amount,...void 0!==e.idempotencyKey?{idempotency_key:e.idempotencyKey}:{}},a=await this.httpClient.request({method:"POST",path:`/api/mediums/external-us-bank/${encodeURIComponent(e.urn)}/pull`,body:t});return{orderSig:a.result?.order_sig,graphId:a.result?.graph_id,status:a.result?.status,execution:a.result?.execution,requestId:a.req_id}}}function mapPolygonAccountFromWire(e){return{urn:e.urn,id:e.id,address:e.details.address,network:e.details.network,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:"balance"in e&&e.balance?e.balance:void 0}}class PolygonClient extends sdk_core_namespaceObject.BaseClient{async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","polygon"),t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(e=>({...this._mapAccountResponse(e),balance:e.balance}))}}async create(e={},t){let a={holder_urn:e.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{},metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/polygon",body:a,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return t?.waitLedger?this._waitForActiveStatus(n.urn,t.timeout||6e4):n}async _waitForActiveStatus(e,t){let a=Date.now();for(;;){if(Date.now()-a>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let r=(await this.list({urn:e})).accounts[0];if(!r)throw Error(`Account not found. URN: ${e}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${e}`);await new Promise(e=>setTimeout(e,2e3))}}async updateMetadata(e){let t={metadata:e.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(a.result.account)}async activate(e){return this._updateStatus(e,"active")}async freeze(e){return this._updateStatus(e,"frozen")}async disable(e){return this._updateStatus(e,"disabled")}async _updateStatus(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{status:t}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(e){return mapPolygonAccountFromWire(e)}}function mapUsAccountFromWire(e){return{urn:e.urn,id:e.id,type:e.details.type,firstName:e.details.first_name,middleName:e.details.middle_name,lastName:e.details.last_name,email:e.details.email,phone:e.details.phone,address:{streetLine1:e.details.address.street_line_1,streetLine2:e.details.address.street_line_2,city:e.details.address.city,state:e.details.address.state,postalCode:e.details.address.postal_code,country:e.details.address.country},birthDate:e.details.birth_date,accountNumber:e.details.account_number,routingNumber:e.details.routing_number,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}}class UsClient extends sdk_core_namespaceObject.BaseClient{async getTosLink(e){let t=new URLSearchParams({redirect_uri:e.redirectUri}),a=(await this.httpClient.request({method:"POST",path:`/api/mediums/us-account/tos-link?${t.toString()}`})).result.url;try{let t=new URL(a);t.searchParams.has("redirect_uri")||(t.searchParams.set("redirect_uri",e.redirectUri),a=t.toString())}catch{let t=a.includes("?")?"&":"?";/[?&]redirect_uri=/.test(a)||(a=`${a}${t}redirect_uri=${encodeURIComponent(e.redirectUri)}`)}return{url:a}}async create(e,t){let a={street_line_1:e.address.streetLine1,street_line_2:e.address.streetLine2,city:e.address.city,state:e.address.state,postal_code:e.address.postalCode,country:e.address.country},r={type:e.type,first_name:e.firstName,middle_name:e.middleName,last_name:e.lastName,email:e.email,phone:e.phone,address:a,birth_date:e.birthDate,tax_identification_number:e.taxIdentificationNumber,gov_id_country:e.govIdCountry,gov_id_image_front:e.govIdImageFront,signed_agreement_id:e.signedAgreementId},n={holder_urn:e.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:r,metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},o=await this.httpClient.request({method:"POST",path:"/api/mediums/us-account",body:n,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),s=this._mapAccountResponse(o.result.account);return t?.waitLedger?this._waitForActiveStatus(s.urn,t.timeout||6e4):s}async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","us-account"),t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(e=>({urn:e.urn,id:e.id,type:e.details.type,firstName:e.details.first_name,middleName:e.details.middle_name,lastName:e.details.last_name,email:e.details.email,phone:e.details.phone,address:{streetLine1:e.details.address.street_line_1,streetLine2:e.details.address.street_line_2,city:e.details.address.city,state:e.details.address.state,postalCode:e.details.address.postal_code,country:e.details.address.country},birthDate:e.details.birth_date,accountNumber:e.details.account_number,routingNumber:e.details.routing_number,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}))}}async updateMetadata(e){let t={metadata:e.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(a.result.account)}async activate(e){return this._updateStatus(e,"active")}async freeze(e){return this._updateStatus(e,"frozen")}async disable(e){return this._updateStatus(e,"disabled")}async _waitForActiveStatus(e,t){let a=Date.now();for(;;){if(Date.now()-a>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let r=(await this.list({urn:e})).accounts[0];if(!r)throw Error(`Account not found. URN: ${e}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${e}`);await new Promise(e=>setTimeout(e,2e3))}}async _updateStatus(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{status:t}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(e){return mapUsAccountFromWire(e)}}function mapUs2AccountFromWire(e){return{urn:e.urn,id:e.id,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance,details:{id:e.details.id,userId:e.details.user_id,virtualAccountId:e.details.virtual_account_id,type:e.details.type,currency:e.details.currency}}}class Us2Client extends sdk_core_namespaceObject.BaseClient{async create(e,t){let a={type:e.type,email:e.email,phone:e.phone,proof_of_address:e.proofOfAddress,business_formation_document:e.businessFormationDocument,tax_id:e.taxId,address:e.address?{street:e.address.street,city:e.address.city,state:e.address.state,postal_code:e.address.postalCode,country:e.address.country}:void 0},r={holder_urn:e.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:a,metadata:{source:"sdk-typescript",...e.metadata}};return mapUs2AccountFromWire((await this.httpClient.request({method:"POST",path:"/api/mediums/us2-account",body:r})).result.account)}async list(e={}){let t=e.holderUrn||this.httpClient.urn,a=new URLSearchParams;return a.append("medium","us2-account"),t&&a.append("holder_urn",t),e.urn&&a.append("urn",e.urn),{accounts:(await this.httpClient.request({method:"GET",path:`/api/accounts?${a.toString()}`})).accounts.map(e=>mapUs2AccountFromWire(e))}}}function mapVirtualAccountFromWire(e){return{urn:e.urn,id:e.id,firstName:e.details.first_name,lastName:e.details.last_name,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:"balance"in e&&e.balance?e.balance:void 0}}class VirtualClient extends sdk_core_namespaceObject.BaseClient{async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","virtual"),t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(e=>({...this._mapAccountResponse(e),balance:e.balance}))}}async create(e,t){let a={holder_urn:e.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{},metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/virtual",body:a,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return t?.waitLedger?this._waitForActiveStatus(n.urn,t.timeout||6e4):n}async _waitForActiveStatus(e,t){let a=Date.now();for(;;){if(Date.now()-a>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let r=(await this.list({urn:e})).accounts[0];if(!r)throw Error(`Account not found. URN: ${e}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${e}`);await new Promise(e=>setTimeout(e,2e3))}}async updateMetadata(e){let t={metadata:e.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(a.result.account)}async activate(e){return this._updateStatus(e,"active")}async freeze(e){return this._updateStatus(e,"frozen")}async disable(e){return this._updateStatus(e,"disabled")}async _updateStatus(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{status:t}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(e){return mapVirtualAccountFromWire(e)}}class AccountsClient extends sdk_core_namespaceObject.BaseClient{bancolombia;breb;card;externalUsBank;polygon;us;us2;virtual;constructor(e){super(e),this.bancolombia=new BancolombiaClient(this.httpClient),this.breb=new BrebClient(this.httpClient),this.card=new CardClient(this.httpClient),this.externalUsBank=new ExternalUsBankClient(this.httpClient),this.polygon=new PolygonClient(this.httpClient),this.us=new UsClient(this.httpClient),this.us2=new Us2Client(this.httpClient),this.virtual=new VirtualClient(this.httpClient)}async balance(e){if(!e?.trim())throw Error("Account URN is required");return(await this.httpClient.request({method:"GET",path:`/api/accounts/${e}/balance`})).balance}async balances(){return(await this.httpClient.request({method:"GET",path:"/api/accounts/balances"})).balance}async get(e){if(!e?.trim())throw Error("Account URN is required");let t=await this.httpClient.request({method:"GET",path:`/api/accounts/${e}`});return this._mapByMedium(t.account)}async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;t&&a.append("holder_urn",t);let r=a.toString(),n=r?`/api/accounts?${r}`:"/api/accounts";return{accounts:(await this.httpClient.request({method:"GET",path:n})).accounts.map(e=>this._mapByMedium(e))}}async transfer(e,t){let a=e.asset||"DUSD/6";if(!(0,sdk_core_namespaceObject.isSupportedAsset)(a))throw Error(`Invalid asset type "${a}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let r={destination_account_urn:e.destinationUrn,amount:e.amount,asset:a,metadata:e.metadata},n=await this.httpClient.request({method:"POST",path:`/api/accounts/${e.sourceUrn}/transfer`,body:r,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0});return{queueId:n.result.queue_id,status:n.result.status,message:n.result.message}}async batchTransfer(e,t){if(!e.operations||0===e.operations.length)throw Error("At least one operation is required");if(!e.reference)throw Error("Batch reference is required");for(let t of e.operations)if(!(0,sdk_core_namespaceObject.isSupportedAsset)(t.asset))throw Error(`Invalid asset type "${t.asset}" in operation "${t.reference}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let a={operations:e.operations.map(e=>({from_account_urn:e.fromUrn,to_account_urn:e.toUrn,reference:e.reference,amount:e.amount,asset:e.asset,metadata:e.metadata})),reference:e.reference,metadata:e.metadata,webhook_url:e.webhookUrl},r=await this.httpClient.request({method:"POST",path:"/api/accounts/batch/transfer",body:a,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0});return{chunks:r.result.chunks.map(e=>({queueId:e.queue_id,status:e.status,message:e.message})),totalOperations:r.result.total_operations,totalChunks:r.result.total_chunks}}async movements(e){if(!e.urn)throw Error("Account URN is required");let t=e.asset||"DUSD/6";if(!(0,sdk_core_namespaceObject.isSupportedAsset)(t))throw Error(`Invalid asset type "${t}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let a=new URLSearchParams;a.set("asset",t),void 0!==e.limit&&a.set("limit",e.limit.toString()),e.before&&a.set("before",e.before),e.after&&a.set("after",e.after),e.reference&&a.set("reference",e.reference),e.direction&&a.set("direction",e.direction),void 0!==e.collapsed_view&&a.set("collapsed_view",String(e.collapsed_view)),e.pocket&&a.set("pocket",e.pocket),e.next&&a.set("next",e.next);let r=`/api/accounts/${e.urn}/movements?${a.toString()}`,n=await this.httpClient.request({method:"GET",path:r});return{data:n.data.map(e=>({amount:e.amount,asset:e.asset,fromAccountId:e.from_account_id,toAccountId:e.to_account_id,direction:e.direction,type:e.type,reference:e.reference,status:e.status,railName:e.rail_name,details:e.details,createdAt:e.created_at})),pageSize:n.page_size,hasMore:n.has_more,next:n.next}}async transactions(e={}){let t=e.asset||"DUSD/6";if(!(0,sdk_core_namespaceObject.isSupportedAsset)(t))throw Error(`Invalid asset type "${t}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let a=new URLSearchParams;a.set("asset",t),void 0!==e.limit&&a.set("limit",e.limit.toString()),e.before&&a.set("before",e.before),e.after&&a.set("after",e.after),e.reference&&a.set("reference",e.reference),e.direction&&a.set("direction",e.direction),void 0!==e.collapsed_view&&a.set("collapsed_view",String(e.collapsed_view)),e.pocket&&a.set("pocket",e.pocket),e.next&&a.set("next",e.next);let r=await this.httpClient.request({method:"GET",path:`/api/accounts/transactions?${a.toString()}`});return{data:r.data.map(e=>({amount:e.amount,asset:e.asset,fromAccountId:e.from_account_id,toAccountId:e.to_account_id,direction:e.direction,reference:e.reference,status:e.status,railName:e.rail_name,details:e.details??{},createdAt:e.created_at,type:e.type})),pageSize:r.page_size,hasMore:r.has_more,next:r.next}}_mapByMedium(e){switch(e.medium){case"card":return mapCardAccountFromWire(e);case"virtual":return mapVirtualAccountFromWire(e);case"polygon":return mapPolygonAccountFromWire(e);case"bancolombia":return mapBancolombiaAccountFromWire(e);case"breb":return mapBrebAccountFromWire(e);case"external-us-bank":return mapExternalUsBankAccountFromWire(e);case"us-account":return mapUsAccountFromWire(e);case"us2-account":return mapUs2AccountFromWire(e);default:throw Error(`Unknown account medium: ${e.medium}`)}}}for(var __rspack_i in exports.AccountsClient=__webpack_exports__.AccountsClient,exports.BancolombiaClient=__webpack_exports__.BancolombiaClient,exports.BrebClient=__webpack_exports__.BrebClient,exports.CardClient=__webpack_exports__.CardClient,exports.ExternalUsBankClient=__webpack_exports__.ExternalUsBankClient,exports.PolygonClient=__webpack_exports__.PolygonClient,exports.Us2Client=__webpack_exports__.Us2Client,exports.UsClient=__webpack_exports__.UsClient,exports.VirtualClient=__webpack_exports__.VirtualClient,exports.mapBancolombiaAccountFromWire=__webpack_exports__.mapBancolombiaAccountFromWire,exports.mapBrebAccountFromWire=__webpack_exports__.mapBrebAccountFromWire,exports.mapCardAccountFromWire=__webpack_exports__.mapCardAccountFromWire,exports.mapExternalUsBankAccountFromWire=__webpack_exports__.mapExternalUsBankAccountFromWire,exports.mapPolygonAccountFromWire=__webpack_exports__.mapPolygonAccountFromWire,exports.mapUs2AccountFromWire=__webpack_exports__.mapUs2AccountFromWire,exports.mapUsAccountFromWire=__webpack_exports__.mapUsAccountFromWire,exports.mapVirtualAccountFromWire=__webpack_exports__.mapVirtualAccountFromWire,__webpack_exports__)-1===["AccountsClient","BancolombiaClient","BrebClient","CardClient","ExternalUsBankClient","PolygonClient","Us2Client","UsClient","VirtualClient","mapBancolombiaAccountFromWire","mapBrebAccountFromWire","mapCardAccountFromWire","mapExternalUsBankAccountFromWire","mapPolygonAccountFromWire","mapUs2AccountFromWire","mapUsAccountFromWire","mapVirtualAccountFromWire"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{BaseClient as t,BloqueAPIError as e,SUPPORTED_ASSETS as a,isSupportedAsset as r}from"@bloque/sdk-core";function n(t){return{urn:t.urn,id:t.id,referenceCode:t.details.reference_code,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:"balance"in t&&t.balance?t.balance:void 0}}class s extends t{async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","bancolombia"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({...this._mapAccountResponse(t),balance:t.balance}))}}async create(t={},e){let a={holder_urn:t?.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{},metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/bancolombia",body:a,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(n.urn,e.timeout||6e4):n}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async updateName(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{metadata:{name:e}}});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return n(t)}}function i(t){return{id:t.id,urn:t.urn,ownerUrn:t.owner_urn,medium:"breb",remoteKeyId:t.details.remote_key_id,accountId:t.details.account_id,keyType:t.details.key.key_type,key:t.details.key.key_value,displayName:t.details.display_name??null,status:t.status,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,details:t.details,balance:"balance"in t&&t.balance?t.balance:void 0}}class o extends t{mapError(t){if(t instanceof e){let e=t.response;return{code:e?.extra_details?.provider_code??t.code??null,message:t.message}}return t instanceof Error?{code:null,message:t.message}:{code:null,message:"Unknown BRE-B error"}}async createKey(t){try{let e=this.httpClient.urn;if(!e?.trim())throw Error("Holder URN is required");if(!t.key?.trim())throw Error("BRE-B key value is required");let a=await this.httpClient.request({method:"POST",path:"/api/mediums/breb",body:{holder_urn:e,input:{key_type:t.keyType,key_value:t.key,display_name:t.displayName},webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,metadata:{source:"sdk-typescript",...t.metadata}}});return{data:i(a.result.account),error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async resolveKey(t){try{if(!t.key?.trim())throw Error("BRE-B key value is required");return{data:(await this.httpClient.request({method:"POST",path:"/api/mediums/breb/resolve-key",body:{key_type:t.keyType,key:t.key}})).result,error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async decodeQr(t){try{var e;if(!t.qrCodeData?.trim())throw Error("BRE-B QR code data is required");return{data:{amount:(e=(await this.httpClient.request({method:"POST",path:"/api/mediums/breb/decode-qr",body:{qr_code_data:t.qrCodeData}})).result).amount,additionalInfo:e.additional_info?{transactionPurpose:e.additional_info.transaction_purpose,terminalLabel:e.additional_info.terminal_label,invoiceNumber:e.additional_info.invoice_number,mobilePhoneNumber:e.additional_info.mobile_phone_number,storeLabel:e.additional_info.store_label,loyaltyLabel:e.additional_info.loyalty_label,referenceLabel:e.additional_info.reference_label,customerLabel:e.additional_info.customer_label,customerInfo:e.additional_info.customer_info,channelPresentation:e.additional_info.channel_presentation}:null,key:e.key?{keyType:e.key.key_type,keyValue:e.key.key_value}:null,qrCodeData:e.qr_code_data,status:e.status,acquirerNetworkIdentifier:e.acquirer_network_identifier,merchant:e.merchant?{merchantCategoryCode:e.merchant.merchant_category_code,merchantCountry:e.merchant.merchant_country,merchantName:e.merchant.merchant_name,merchantCity:e.merchant.merchant_city,merchantPostCode:e.merchant.merchant_post_code}:null,channel:e.channel,qrCodeReference:e.qr_code_reference,type:e.type,resolutionId:e.resolution_id,resolution:e.resolution},error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async deleteKey(t){try{if(!t.accountUrn?.trim())throw Error("BRE-B account URN is required");let e=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(t.accountUrn)}`,body:{status:"deleted"}});return{data:{deleted:!0,accountUrn:e.result.account.urn,keyId:e.result.account.details.id,status:"deleted"},error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async suspendKey(t){try{if(!t.accountUrn?.trim())throw Error("BRE-B account URN is required");let e=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(t.accountUrn)}`,body:{status:"frozen"}});return{data:{accountUrn:e.result.account.urn,keyId:e.result.account.details.id,keyStatus:e.result.account.details.status,status:"frozen"},error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async activateKey(t){try{if(!t.accountUrn?.trim())throw Error("BRE-B account URN is required");let e=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(t.accountUrn)}`,body:{status:"active"}});return{data:{accountUrn:e.result.account.urn,keyId:e.result.account.details.id,keyStatus:e.result.account.details.status,status:"active"},error:null}}catch(t){return{data:null,error:this.mapError(t)}}}}function d(t){return{urn:t.urn,id:t.id,lastFour:t.details.card_last_four,productType:t.details.card_product_type,status:t.status,cardType:t.details.card_type,detailsUrl:t.details.card_url_details,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}}class u extends t{async create(t={},e){let a={holder_urn:t?.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{create:{card_type:"VIRTUAL"}},metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/card",body:a,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(n.urn,e.timeout||6e4):n}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","card"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({urn:t.urn,id:t.id,lastFour:t.details.card_last_four,productType:t.details.card_product_type,status:t.status,cardType:t.details.card_type,detailsUrl:t.details.card_url_details,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}))}}async movements(t){let e=new URLSearchParams,n=t.asset||"DUSD/6";if(!r(n))throw Error(`Invalid asset type "${n}". Supported assets: ${a.join(", ")}`);e.set("asset",n),void 0!==t.limit&&e.set("limit",t.limit.toString()),t.before&&e.set("before",t.before),t.after&&e.set("after",t.after),t.reference&&e.set("reference",t.reference),t.direction&&e.set("direction",t.direction),void 0!==t.collapsed_view&&e.set("collapsed_view",String(t.collapsed_view)),t.pocket&&e.set("pocket",t.pocket),t.next&&e.set("next",t.next);let s=e.toString(),i=`/api/accounts/${t.urn}/movements${s?`?${s}`:""}`,o=await this.httpClient.request({method:"GET",path:i});return{data:o.data,pageSize:o.page_size,hasMore:o.has_more,next:o.next}}async balance(t){return(await this.httpClient.request({method:"GET",path:`/api/accounts/${t.urn}/balance`})).balance}async update(t){let e={...t.metadata&&{metadata:t.metadata},...t.status&&{status:t.status},...t.webhookUrl&&{webhook_url:t.webhookUrl},...t.ledgerId&&{ledger_account_id:t.ledgerId}},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async updateName(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{metadata:{name:e}}});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async tokenizeApple(t,e){let a={certificates:e.certificates,nonce:e.nonce,nonce_signature:e.nonceSignature},r=await this.httpClient.request({method:"POST",path:`/api/accounts/${t}/tokenize/apple`,body:a});return{activationData:r.result.tokenization.activation_data,encryptedPassData:r.result.tokenization.encrypted_pass_data,ephemeralPublicKey:r.result.tokenization.ephemeral_public_key}}async tokenizeGoogle(t,e){let a={device_id:e.deviceId,wallet_account_id:e.walletAccountId};return{opc:(await this.httpClient.request({method:"POST",path:`/api/accounts/${t}/tokenize/google`,body:a})).result.tokenization.opc}}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return d(t)}}function c(t){if(t)return{streetLine1:t.street_line_1,...void 0!==t.street_line_2?{streetLine2:t.street_line_2}:{},city:t.city,state:t.state,zip:t.zip,...void 0!==t.country?{country:t.country}:{}}}function l(t){return{urn:t.urn,id:t.id,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance,details:{id:t.details.id,linkStatus:t.details.link_status,braleAccountId:t.details.brale_account_id,braleAddressId:t.details.brale_address_id,linkToken:t.details.link_token,linkTokenExpiration:t.details.link_token_expiration,linkUrl:t.details.link_url,jwt:t.details.jwt,bankAccountLast4:t.details.bank_account_last4,bankName:t.details.bank_name,failureReason:t.details.failure_reason,owner:t.details.owner,routingNumber:t.details.routing_number,accountNumber:t.details.account_number,accountType:t.details.account_type,bankAddress:c(t.details.bank_address),beneficiaryAddress:c(t.details.beneficiary_address),transferTypes:t.details.transfer_types,needsUpdate:t.details.needs_update,lastUpdated:t.details.last_updated}}}class p extends t{async create(t,e){let a={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{label:t.label,...void 0!==t.returnUrl?{return_url:t.returnUrl}:{},...void 0!==t.state?{state:t.state}:{}},metadata:{source:"sdk-typescript",...t.metadata}};return l((await this.httpClient.request({method:"POST",path:"/api/mediums/external-us-bank",body:a})).result.account)}async exchangePublicToken(t){let e={input:{public_token:t.publicToken}};return l((await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e})).result.account)}async pull(t){if(!t?.urn?.trim())throw Error("Bank account URN is required");if("string"!=typeof t.amount||""===t.amount.trim())throw Error('Amount is required and must be a string (e.g. "100.00")');let e={amount:t.amount,...void 0!==t.idempotencyKey?{idempotency_key:t.idempotencyKey}:{}},a=await this.httpClient.request({method:"POST",path:`/api/mediums/external-us-bank/${encodeURIComponent(t.urn)}/pull`,body:e});return{orderSig:a.result?.order_sig,graphId:a.result?.graph_id,status:a.result?.status,execution:a.result?.execution,requestId:a.req_id}}}function h(t){return{urn:t.urn,id:t.id,address:t.details.address,network:t.details.network,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:"balance"in t&&t.balance?t.balance:void 0}}class m extends t{async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","polygon"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({...this._mapAccountResponse(t),balance:t.balance}))}}async create(t={},e){let a={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{},metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/polygon",body:a,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(n.urn,e.timeout||6e4):n}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return h(t)}}function _(t){return{urn:t.urn,id:t.id,type:t.details.type,firstName:t.details.first_name,middleName:t.details.middle_name,lastName:t.details.last_name,email:t.details.email,phone:t.details.phone,address:{streetLine1:t.details.address.street_line_1,streetLine2:t.details.address.street_line_2,city:t.details.address.city,state:t.details.address.state,postalCode:t.details.address.postal_code,country:t.details.address.country},birthDate:t.details.birth_date,accountNumber:t.details.account_number,routingNumber:t.details.routing_number,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}}class y extends t{async getTosLink(t){let e=new URLSearchParams({redirect_uri:t.redirectUri}),a=(await this.httpClient.request({method:"POST",path:`/api/mediums/us-account/tos-link?${e.toString()}`})).result.url;try{let e=new URL(a);e.searchParams.has("redirect_uri")||(e.searchParams.set("redirect_uri",t.redirectUri),a=e.toString())}catch{let e=a.includes("?")?"&":"?";/[?&]redirect_uri=/.test(a)||(a=`${a}${e}redirect_uri=${encodeURIComponent(t.redirectUri)}`)}return{url:a}}async create(t,e){let a={street_line_1:t.address.streetLine1,street_line_2:t.address.streetLine2,city:t.address.city,state:t.address.state,postal_code:t.address.postalCode,country:t.address.country},r={type:t.type,first_name:t.firstName,middle_name:t.middleName,last_name:t.lastName,email:t.email,phone:t.phone,address:a,birth_date:t.birthDate,tax_identification_number:t.taxIdentificationNumber,gov_id_country:t.govIdCountry,gov_id_image_front:t.govIdImageFront,signed_agreement_id:t.signedAgreementId},n={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:r,metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},s=await this.httpClient.request({method:"POST",path:"/api/mediums/us-account",body:n,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0}),i=this._mapAccountResponse(s.result.account);return e?.waitLedger?this._waitForActiveStatus(i.urn,e.timeout||6e4):i}async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","us-account"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({urn:t.urn,id:t.id,type:t.details.type,firstName:t.details.first_name,middleName:t.details.middle_name,lastName:t.details.last_name,email:t.details.email,phone:t.details.phone,address:{streetLine1:t.details.address.street_line_1,streetLine2:t.details.address.street_line_2,city:t.details.address.city,state:t.details.address.state,postalCode:t.details.address.postal_code,country:t.details.address.country},birthDate:t.details.birth_date,accountNumber:t.details.account_number,routingNumber:t.details.routing_number,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return _(t)}}function b(t){return{urn:t.urn,id:t.id,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance,details:{id:t.details.id,userId:t.details.user_id,virtualAccountId:t.details.virtual_account_id,type:t.details.type,currency:t.details.currency}}}class w extends t{async create(t,e){let a={type:t.type,email:t.email,phone:t.phone,proof_of_address:t.proofOfAddress,business_formation_document:t.businessFormationDocument,tax_id:t.taxId,address:t.address?{street:t.address.street,city:t.address.city,state:t.address.state,postal_code:t.address.postalCode,country:t.address.country}:void 0},r={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:a,metadata:{source:"sdk-typescript",...t.metadata}};return b((await this.httpClient.request({method:"POST",path:"/api/mediums/us2-account",body:r})).result.account)}async list(t={}){let e=t.holderUrn||this.httpClient.urn,a=new URLSearchParams;return a.append("medium","us2-account"),e&&a.append("holder_urn",e),t.urn&&a.append("urn",t.urn),{accounts:(await this.httpClient.request({method:"GET",path:`/api/accounts?${a.toString()}`})).accounts.map(t=>b(t))}}}function f(t){return{urn:t.urn,id:t.id,firstName:t.details.first_name,lastName:t.details.last_name,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:"balance"in t&&t.balance?t.balance:void 0}}class k extends t{async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","virtual"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({...this._mapAccountResponse(t),balance:t.balance}))}}async create(t,e){let a={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{},metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/virtual",body:a,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(n.urn,e.timeout||6e4):n}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return f(t)}}class g extends t{bancolombia;breb;card;externalUsBank;polygon;us;us2;virtual;constructor(t){super(t),this.bancolombia=new s(this.httpClient),this.breb=new o(this.httpClient),this.card=new u(this.httpClient),this.externalUsBank=new p(this.httpClient),this.polygon=new m(this.httpClient),this.us=new y(this.httpClient),this.us2=new w(this.httpClient),this.virtual=new k(this.httpClient)}async balance(t){if(!t?.trim())throw Error("Account URN is required");return(await this.httpClient.request({method:"GET",path:`/api/accounts/${t}/balance`})).balance}async balances(){return(await this.httpClient.request({method:"GET",path:"/api/accounts/balances"})).balance}async get(t){if(!t?.trim())throw Error("Account URN is required");let e=await this.httpClient.request({method:"GET",path:`/api/accounts/${t}`});return this._mapByMedium(e.account)}async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;e&&a.append("holder_urn",e);let r=a.toString(),n=r?`/api/accounts?${r}`:"/api/accounts";return{accounts:(await this.httpClient.request({method:"GET",path:n})).accounts.map(t=>this._mapByMedium(t))}}async transfer(t,e){let n=t.asset||"DUSD/6";if(!r(n))throw Error(`Invalid asset type "${n}". Supported assets: ${a.join(", ")}`);let s={destination_account_urn:t.destinationUrn,amount:t.amount,asset:n,metadata:t.metadata},i=await this.httpClient.request({method:"POST",path:`/api/accounts/${t.sourceUrn}/transfer`,body:s,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0});return{queueId:i.result.queue_id,status:i.result.status,message:i.result.message}}async batchTransfer(t,e){if(!t.operations||0===t.operations.length)throw Error("At least one operation is required");if(!t.reference)throw Error("Batch reference is required");for(let e of t.operations)if(!r(e.asset))throw Error(`Invalid asset type "${e.asset}" in operation "${e.reference}". Supported assets: ${a.join(", ")}`);let n={operations:t.operations.map(t=>({from_account_urn:t.fromUrn,to_account_urn:t.toUrn,reference:t.reference,amount:t.amount,asset:t.asset,metadata:t.metadata})),reference:t.reference,metadata:t.metadata,webhook_url:t.webhookUrl},s=await this.httpClient.request({method:"POST",path:"/api/accounts/batch/transfer",body:n,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0});return{chunks:s.result.chunks.map(t=>({queueId:t.queue_id,status:t.status,message:t.message})),totalOperations:s.result.total_operations,totalChunks:s.result.total_chunks}}async movements(t){if(!t.urn)throw Error("Account URN is required");let e=t.asset||"DUSD/6";if(!r(e))throw Error(`Invalid asset type "${e}". Supported assets: ${a.join(", ")}`);let n=new URLSearchParams;n.set("asset",e),void 0!==t.limit&&n.set("limit",t.limit.toString()),t.before&&n.set("before",t.before),t.after&&n.set("after",t.after),t.reference&&n.set("reference",t.reference),t.direction&&n.set("direction",t.direction),void 0!==t.collapsed_view&&n.set("collapsed_view",String(t.collapsed_view)),t.pocket&&n.set("pocket",t.pocket),t.next&&n.set("next",t.next);let s=`/api/accounts/${t.urn}/movements?${n.toString()}`,i=await this.httpClient.request({method:"GET",path:s});return{data:i.data.map(t=>({amount:t.amount,asset:t.asset,fromAccountId:t.from_account_id,toAccountId:t.to_account_id,direction:t.direction,type:t.type,reference:t.reference,status:t.status,railName:t.rail_name,details:t.details,createdAt:t.created_at})),pageSize:i.page_size,hasMore:i.has_more,next:i.next}}async transactions(t={}){let e=t.asset||"DUSD/6";if(!r(e))throw Error(`Invalid asset type "${e}". Supported assets: ${a.join(", ")}`);let n=new URLSearchParams;n.set("asset",e),void 0!==t.limit&&n.set("limit",t.limit.toString()),t.before&&n.set("before",t.before),t.after&&n.set("after",t.after),t.reference&&n.set("reference",t.reference),t.direction&&n.set("direction",t.direction),void 0!==t.collapsed_view&&n.set("collapsed_view",String(t.collapsed_view)),t.pocket&&n.set("pocket",t.pocket),t.next&&n.set("next",t.next);let s=await this.httpClient.request({method:"GET",path:`/api/accounts/transactions?${n.toString()}`});return{data:s.data.map(t=>({amount:t.amount,asset:t.asset,fromAccountId:t.from_account_id,toAccountId:t.to_account_id,direction:t.direction,reference:t.reference,status:t.status,railName:t.rail_name,details:t.details??{},createdAt:t.created_at,type:t.type})),pageSize:s.page_size,hasMore:s.has_more,next:s.next}}_mapByMedium(t){switch(t.medium){case"card":return d(t);case"virtual":return f(t);case"polygon":return h(t);case"bancolombia":return n(t);case"breb":return i(t);case"external-us-bank":return l(t);case"us-account":return _(t);case"us2-account":return b(t);default:throw Error(`Unknown account medium: ${t.medium}`)}}}export{g as AccountsClient,s as BancolombiaClient,o as BrebClient,u as CardClient,p as ExternalUsBankClient,m as PolygonClient,w as Us2Client,y as UsClient,k as VirtualClient,n as mapBancolombiaAccountFromWire,i as mapBrebAccountFromWire,d as mapCardAccountFromWire,l as mapExternalUsBankAccountFromWire,h as mapPolygonAccountFromWire,b as mapUs2AccountFromWire,_ as mapUsAccountFromWire,f as mapVirtualAccountFromWire};
|
|
1
|
+
import{BaseClient as t,BloqueAPIError as e,SUPPORTED_ASSETS as a,isSupportedAsset as r}from"@bloque/sdk-core";function n(t){return{urn:t.urn,id:t.id,referenceCode:t.details.reference_code,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:"balance"in t&&t.balance?t.balance:void 0}}class s extends t{async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","bancolombia"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({...this._mapAccountResponse(t),balance:t.balance}))}}async create(t={},e){let a={holder_urn:t?.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{},metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/bancolombia",body:a,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(n.urn,e.timeout||6e4):n}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async updateName(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{metadata:{name:e}}});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return n(t)}}function i(t){return{id:t.id,urn:t.urn,ownerUrn:t.owner_urn,medium:"breb",remoteKeyId:t.details.remote_key_id,accountId:t.details.account_id,keyType:t.details.key.key_type,key:t.details.key.key_value,displayName:t.details.display_name??null,status:t.status,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,details:t.details,balance:"balance"in t&&t.balance?t.balance:void 0}}class o extends t{mapError(t){if(t instanceof e){let e=t.response;return{code:e?.extra_details?.provider_code??t.code??null,message:t.message}}return t instanceof Error?{code:null,message:t.message}:{code:null,message:"Unknown BRE-B error"}}async createKey(t){try{let e=this.httpClient.urn;if(!e?.trim())throw Error("Holder URN is required");if(!t.key?.trim())throw Error("BRE-B key value is required");let a=await this.httpClient.request({method:"POST",path:"/api/mediums/breb",body:{holder_urn:e,input:{key_type:t.keyType,key_value:t.key,display_name:t.displayName},webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,metadata:{source:"sdk-typescript",...t.metadata}}});return{data:i(a.result.account),error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async resolveKey(t){try{if(!t.key?.trim())throw Error("BRE-B key value is required");return{data:(await this.httpClient.request({method:"POST",path:"/api/mediums/breb/resolve-key",body:{...t.keyType&&{key_type:t.keyType},key:t.key}})).result,error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async decodeQr(t){try{var e;if(!t.qrCodeData?.trim())throw Error("BRE-B QR code data is required");return{data:{amount:(e=(await this.httpClient.request({method:"POST",path:"/api/mediums/breb/decode-qr",body:{qr_code_data:t.qrCodeData}})).result).amount,additionalInfo:e.additional_info?{transactionPurpose:e.additional_info.transaction_purpose,terminalLabel:e.additional_info.terminal_label,invoiceNumber:e.additional_info.invoice_number,mobilePhoneNumber:e.additional_info.mobile_phone_number,storeLabel:e.additional_info.store_label,loyaltyLabel:e.additional_info.loyalty_label,referenceLabel:e.additional_info.reference_label,customerLabel:e.additional_info.customer_label,customerInfo:e.additional_info.customer_info,channelPresentation:e.additional_info.channel_presentation}:null,key:e.key?{keyType:e.key.key_type,keyValue:e.key.key_value}:null,qrCodeData:e.qr_code_data,status:e.status,acquirerNetworkIdentifier:e.acquirer_network_identifier,merchant:e.merchant?{merchantCategoryCode:e.merchant.merchant_category_code,merchantCountry:e.merchant.merchant_country,merchantName:e.merchant.merchant_name,merchantCity:e.merchant.merchant_city,merchantPostCode:e.merchant.merchant_post_code}:null,channel:e.channel,qrCodeReference:e.qr_code_reference,type:e.type,resolutionId:e.resolution_id,resolution:e.resolution},error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async deleteKey(t){try{if(!t.accountUrn?.trim())throw Error("BRE-B account URN is required");let e=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(t.accountUrn)}`,body:{status:"deleted"}});return{data:{deleted:!0,accountUrn:e.result.account.urn,keyId:e.result.account.details.id,status:"deleted"},error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async suspendKey(t){try{if(!t.accountUrn?.trim())throw Error("BRE-B account URN is required");let e=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(t.accountUrn)}`,body:{status:"frozen"}});return{data:{accountUrn:e.result.account.urn,keyId:e.result.account.details.id,keyStatus:e.result.account.details.status,status:"frozen"},error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async activateKey(t){try{if(!t.accountUrn?.trim())throw Error("BRE-B account URN is required");let e=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(t.accountUrn)}`,body:{status:"active"}});return{data:{accountUrn:e.result.account.urn,keyId:e.result.account.details.id,keyStatus:e.result.account.details.status,status:"active"},error:null}}catch(t){return{data:null,error:this.mapError(t)}}}}function d(t){return{urn:t.urn,id:t.id,lastFour:t.details.card_last_four,productType:t.details.card_product_type,status:t.status,cardType:t.details.card_type,detailsUrl:t.details.card_url_details,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}}class u extends t{async create(t={},e){let a={holder_urn:t?.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{create:{card_type:"VIRTUAL"}},metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/card",body:a,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(n.urn,e.timeout||6e4):n}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","card"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({urn:t.urn,id:t.id,lastFour:t.details.card_last_four,productType:t.details.card_product_type,status:t.status,cardType:t.details.card_type,detailsUrl:t.details.card_url_details,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}))}}async movements(t){let e=new URLSearchParams,n=t.asset||"DUSD/6";if(!r(n))throw Error(`Invalid asset type "${n}". Supported assets: ${a.join(", ")}`);e.set("asset",n),void 0!==t.limit&&e.set("limit",t.limit.toString()),t.before&&e.set("before",t.before),t.after&&e.set("after",t.after),t.reference&&e.set("reference",t.reference),t.direction&&e.set("direction",t.direction),void 0!==t.collapsed_view&&e.set("collapsed_view",String(t.collapsed_view)),t.pocket&&e.set("pocket",t.pocket),t.next&&e.set("next",t.next);let s=e.toString(),i=`/api/accounts/${t.urn}/movements${s?`?${s}`:""}`,o=await this.httpClient.request({method:"GET",path:i});return{data:o.data,pageSize:o.page_size,hasMore:o.has_more,next:o.next}}async balance(t){return(await this.httpClient.request({method:"GET",path:`/api/accounts/${t.urn}/balance`})).balance}async update(t){let e={...t.metadata&&{metadata:t.metadata},...t.status&&{status:t.status},...t.webhookUrl&&{webhook_url:t.webhookUrl},...t.ledgerId&&{ledger_account_id:t.ledgerId}},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async updateName(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{metadata:{name:e}}});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async tokenizeApple(t,e){let a={certificates:e.certificates,nonce:e.nonce,nonce_signature:e.nonceSignature},r=await this.httpClient.request({method:"POST",path:`/api/accounts/${t}/tokenize/apple`,body:a});return{activationData:r.result.tokenization.activation_data,encryptedPassData:r.result.tokenization.encrypted_pass_data,ephemeralPublicKey:r.result.tokenization.ephemeral_public_key}}async tokenizeGoogle(t,e){let a={device_id:e.deviceId,wallet_account_id:e.walletAccountId};return{opc:(await this.httpClient.request({method:"POST",path:`/api/accounts/${t}/tokenize/google`,body:a})).result.tokenization.opc}}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return d(t)}}function c(t){if(t)return{streetLine1:t.street_line_1,...void 0!==t.street_line_2?{streetLine2:t.street_line_2}:{},city:t.city,state:t.state,zip:t.zip,...void 0!==t.country?{country:t.country}:{}}}function l(t){return{urn:t.urn,id:t.id,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance,details:{id:t.details.id,linkStatus:t.details.link_status,braleAccountId:t.details.brale_account_id,braleAddressId:t.details.brale_address_id,linkToken:t.details.link_token,linkTokenExpiration:t.details.link_token_expiration,linkUrl:t.details.link_url,jwt:t.details.jwt,bankAccountLast4:t.details.bank_account_last4,bankName:t.details.bank_name,failureReason:t.details.failure_reason,owner:t.details.owner,routingNumber:t.details.routing_number,accountNumber:t.details.account_number,accountType:t.details.account_type,bankAddress:c(t.details.bank_address),beneficiaryAddress:c(t.details.beneficiary_address),transferTypes:t.details.transfer_types,needsUpdate:t.details.needs_update,lastUpdated:t.details.last_updated}}}class p extends t{async create(t,e){let a={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{label:t.label,...void 0!==t.returnUrl?{return_url:t.returnUrl}:{},...void 0!==t.state?{state:t.state}:{}},metadata:{source:"sdk-typescript",...t.metadata}};return l((await this.httpClient.request({method:"POST",path:"/api/mediums/external-us-bank",body:a})).result.account)}async exchangePublicToken(t){let e={input:{public_token:t.publicToken}};return l((await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e})).result.account)}async pull(t){if(!t?.urn?.trim())throw Error("Bank account URN is required");if("string"!=typeof t.amount||""===t.amount.trim())throw Error('Amount is required and must be a string (e.g. "100.00")');let e={amount:t.amount,...void 0!==t.idempotencyKey?{idempotency_key:t.idempotencyKey}:{}},a=await this.httpClient.request({method:"POST",path:`/api/mediums/external-us-bank/${encodeURIComponent(t.urn)}/pull`,body:e});return{orderSig:a.result?.order_sig,graphId:a.result?.graph_id,status:a.result?.status,execution:a.result?.execution,requestId:a.req_id}}}function h(t){return{urn:t.urn,id:t.id,address:t.details.address,network:t.details.network,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:"balance"in t&&t.balance?t.balance:void 0}}class m extends t{async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","polygon"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({...this._mapAccountResponse(t),balance:t.balance}))}}async create(t={},e){let a={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{},metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/polygon",body:a,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(n.urn,e.timeout||6e4):n}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return h(t)}}function _(t){return{urn:t.urn,id:t.id,type:t.details.type,firstName:t.details.first_name,middleName:t.details.middle_name,lastName:t.details.last_name,email:t.details.email,phone:t.details.phone,address:{streetLine1:t.details.address.street_line_1,streetLine2:t.details.address.street_line_2,city:t.details.address.city,state:t.details.address.state,postalCode:t.details.address.postal_code,country:t.details.address.country},birthDate:t.details.birth_date,accountNumber:t.details.account_number,routingNumber:t.details.routing_number,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}}class y extends t{async getTosLink(t){let e=new URLSearchParams({redirect_uri:t.redirectUri}),a=(await this.httpClient.request({method:"POST",path:`/api/mediums/us-account/tos-link?${e.toString()}`})).result.url;try{let e=new URL(a);e.searchParams.has("redirect_uri")||(e.searchParams.set("redirect_uri",t.redirectUri),a=e.toString())}catch{let e=a.includes("?")?"&":"?";/[?&]redirect_uri=/.test(a)||(a=`${a}${e}redirect_uri=${encodeURIComponent(t.redirectUri)}`)}return{url:a}}async create(t,e){let a={street_line_1:t.address.streetLine1,street_line_2:t.address.streetLine2,city:t.address.city,state:t.address.state,postal_code:t.address.postalCode,country:t.address.country},r={type:t.type,first_name:t.firstName,middle_name:t.middleName,last_name:t.lastName,email:t.email,phone:t.phone,address:a,birth_date:t.birthDate,tax_identification_number:t.taxIdentificationNumber,gov_id_country:t.govIdCountry,gov_id_image_front:t.govIdImageFront,signed_agreement_id:t.signedAgreementId},n={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:r,metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},s=await this.httpClient.request({method:"POST",path:"/api/mediums/us-account",body:n,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0}),i=this._mapAccountResponse(s.result.account);return e?.waitLedger?this._waitForActiveStatus(i.urn,e.timeout||6e4):i}async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","us-account"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({urn:t.urn,id:t.id,type:t.details.type,firstName:t.details.first_name,middleName:t.details.middle_name,lastName:t.details.last_name,email:t.details.email,phone:t.details.phone,address:{streetLine1:t.details.address.street_line_1,streetLine2:t.details.address.street_line_2,city:t.details.address.city,state:t.details.address.state,postalCode:t.details.address.postal_code,country:t.details.address.country},birthDate:t.details.birth_date,accountNumber:t.details.account_number,routingNumber:t.details.routing_number,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return _(t)}}function b(t){return{urn:t.urn,id:t.id,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance,details:{id:t.details.id,userId:t.details.user_id,virtualAccountId:t.details.virtual_account_id,type:t.details.type,currency:t.details.currency}}}class w extends t{async create(t,e){let a={type:t.type,email:t.email,phone:t.phone,proof_of_address:t.proofOfAddress,business_formation_document:t.businessFormationDocument,tax_id:t.taxId,address:t.address?{street:t.address.street,city:t.address.city,state:t.address.state,postal_code:t.address.postalCode,country:t.address.country}:void 0},r={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:a,metadata:{source:"sdk-typescript",...t.metadata}};return b((await this.httpClient.request({method:"POST",path:"/api/mediums/us2-account",body:r})).result.account)}async list(t={}){let e=t.holderUrn||this.httpClient.urn,a=new URLSearchParams;return a.append("medium","us2-account"),e&&a.append("holder_urn",e),t.urn&&a.append("urn",t.urn),{accounts:(await this.httpClient.request({method:"GET",path:`/api/accounts?${a.toString()}`})).accounts.map(t=>b(t))}}}function f(t){return{urn:t.urn,id:t.id,firstName:t.details.first_name,lastName:t.details.last_name,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:"balance"in t&&t.balance?t.balance:void 0}}class k extends t{async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","virtual"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({...this._mapAccountResponse(t),balance:t.balance}))}}async create(t,e){let a={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{},metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/virtual",body:a,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(n.urn,e.timeout||6e4):n}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return f(t)}}class g extends t{bancolombia;breb;card;externalUsBank;polygon;us;us2;virtual;constructor(t){super(t),this.bancolombia=new s(this.httpClient),this.breb=new o(this.httpClient),this.card=new u(this.httpClient),this.externalUsBank=new p(this.httpClient),this.polygon=new m(this.httpClient),this.us=new y(this.httpClient),this.us2=new w(this.httpClient),this.virtual=new k(this.httpClient)}async balance(t){if(!t?.trim())throw Error("Account URN is required");return(await this.httpClient.request({method:"GET",path:`/api/accounts/${t}/balance`})).balance}async balances(){return(await this.httpClient.request({method:"GET",path:"/api/accounts/balances"})).balance}async get(t){if(!t?.trim())throw Error("Account URN is required");let e=await this.httpClient.request({method:"GET",path:`/api/accounts/${t}`});return this._mapByMedium(e.account)}async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;e&&a.append("holder_urn",e);let r=a.toString(),n=r?`/api/accounts?${r}`:"/api/accounts";return{accounts:(await this.httpClient.request({method:"GET",path:n})).accounts.map(t=>this._mapByMedium(t))}}async transfer(t,e){let n=t.asset||"DUSD/6";if(!r(n))throw Error(`Invalid asset type "${n}". Supported assets: ${a.join(", ")}`);let s={destination_account_urn:t.destinationUrn,amount:t.amount,asset:n,metadata:t.metadata},i=await this.httpClient.request({method:"POST",path:`/api/accounts/${t.sourceUrn}/transfer`,body:s,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0});return{queueId:i.result.queue_id,status:i.result.status,message:i.result.message}}async batchTransfer(t,e){if(!t.operations||0===t.operations.length)throw Error("At least one operation is required");if(!t.reference)throw Error("Batch reference is required");for(let e of t.operations)if(!r(e.asset))throw Error(`Invalid asset type "${e.asset}" in operation "${e.reference}". Supported assets: ${a.join(", ")}`);let n={operations:t.operations.map(t=>({from_account_urn:t.fromUrn,to_account_urn:t.toUrn,reference:t.reference,amount:t.amount,asset:t.asset,metadata:t.metadata})),reference:t.reference,metadata:t.metadata,webhook_url:t.webhookUrl},s=await this.httpClient.request({method:"POST",path:"/api/accounts/batch/transfer",body:n,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0});return{chunks:s.result.chunks.map(t=>({queueId:t.queue_id,status:t.status,message:t.message})),totalOperations:s.result.total_operations,totalChunks:s.result.total_chunks}}async movements(t){if(!t.urn)throw Error("Account URN is required");let e=t.asset||"DUSD/6";if(!r(e))throw Error(`Invalid asset type "${e}". Supported assets: ${a.join(", ")}`);let n=new URLSearchParams;n.set("asset",e),void 0!==t.limit&&n.set("limit",t.limit.toString()),t.before&&n.set("before",t.before),t.after&&n.set("after",t.after),t.reference&&n.set("reference",t.reference),t.direction&&n.set("direction",t.direction),void 0!==t.collapsed_view&&n.set("collapsed_view",String(t.collapsed_view)),t.pocket&&n.set("pocket",t.pocket),t.next&&n.set("next",t.next);let s=`/api/accounts/${t.urn}/movements?${n.toString()}`,i=await this.httpClient.request({method:"GET",path:s});return{data:i.data.map(t=>({amount:t.amount,asset:t.asset,fromAccountId:t.from_account_id,toAccountId:t.to_account_id,direction:t.direction,type:t.type,reference:t.reference,status:t.status,railName:t.rail_name,details:t.details,createdAt:t.created_at})),pageSize:i.page_size,hasMore:i.has_more,next:i.next}}async transactions(t={}){let e=t.asset||"DUSD/6";if(!r(e))throw Error(`Invalid asset type "${e}". Supported assets: ${a.join(", ")}`);let n=new URLSearchParams;n.set("asset",e),void 0!==t.limit&&n.set("limit",t.limit.toString()),t.before&&n.set("before",t.before),t.after&&n.set("after",t.after),t.reference&&n.set("reference",t.reference),t.direction&&n.set("direction",t.direction),void 0!==t.collapsed_view&&n.set("collapsed_view",String(t.collapsed_view)),t.pocket&&n.set("pocket",t.pocket),t.next&&n.set("next",t.next);let s=await this.httpClient.request({method:"GET",path:`/api/accounts/transactions?${n.toString()}`});return{data:s.data.map(t=>({amount:t.amount,asset:t.asset,fromAccountId:t.from_account_id,toAccountId:t.to_account_id,direction:t.direction,reference:t.reference,status:t.status,railName:t.rail_name,details:t.details??{},createdAt:t.created_at,type:t.type})),pageSize:s.page_size,hasMore:s.has_more,next:s.next}}_mapByMedium(t){switch(t.medium){case"card":return d(t);case"virtual":return f(t);case"polygon":return h(t);case"bancolombia":return n(t);case"breb":return i(t);case"external-us-bank":return l(t);case"us-account":return _(t);case"us2-account":return b(t);default:throw Error(`Unknown account medium: ${t.medium}`)}}}export{g as AccountsClient,s as BancolombiaClient,o as BrebClient,u as CardClient,p as ExternalUsBankClient,m as PolygonClient,w as Us2Client,y as UsClient,k as VirtualClient,n as mapBancolombiaAccountFromWire,i as mapBrebAccountFromWire,d as mapCardAccountFromWire,l as mapExternalUsBankAccountFromWire,h as mapPolygonAccountFromWire,b as mapUs2AccountFromWire,_ as mapUsAccountFromWire,f as mapVirtualAccountFromWire};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bloque/sdk-accounts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bloque",
|
|
@@ -36,6 +36,6 @@
|
|
|
36
36
|
"node": ">=22"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@bloque/sdk-core": "0.1.
|
|
39
|
+
"@bloque/sdk-core": "0.1.12"
|
|
40
40
|
}
|
|
41
41
|
}
|