@bloque/sdk-accounts 0.9.1 → 0.11.0
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/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/wire-types.d.ts +15 -1
- package/dist/polygon/types.d.ts +7 -2
- package/dist/types.d.ts +10 -2
- package/dist/virtual/types.d.ts +25 -3
- package/dist/virtual/virtual-client.d.ts +13 -4
- package/package.json +2 -2
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,vat:e.vat?{vatValue:e.vat.vat_value,vatBaseValue:e.vat.vat_base_value,vatType:e.vat.vat_type}:null,inc:e.inc?{incValue:e.inc.inc_value,incType:e.inc.inc_type}:null,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 mapSpendingControlMetadataToRaw(e){let t={};return void 0!==e.spendingControl&&(t.spending_control=e.spendingControl),void 0!==e.priorityMcc&&(t.priority_mcc=e.priorityMcc),void 0!==e.mccWhitelist&&(t.mcc_whitelist=e.mccWhitelist),void 0!==e.cashbackPrograms&&(t.cashback_programs=e.cashbackPrograms.map(e=>({program_name:e.programName,type:e.type,target_pocket_urn:e.targetPocketUrn,...e.feeType&&{fee_type:e.feeType},...void 0!==e.value&&{value:e.value}}))),void 0!==e.spendingFees&&(t.spending_fees=e.spendingFees.map(e=>({fee_name:e.feeName,account_urn:e.accountUrn,type:e.type,value:e.value,...e.category&&{category:e.category},...e.rule&&{rule:e.rule},...e.ruleParams&&{rule_params:e.ruleParams}}))),void 0!==e.fallbackAsset&&(t.fallback_asset=e.fallbackAsset),void 0!==e.whatsappNotification&&(t.whatsapp_notification=e.whatsappNotification),void 0!==e.currencyAssetMap&&(t.currency_asset_map=e.currencyAssetMap),t}function mapSpendingControlMetadataFromRaw(e){if(!e)return;let t={};return("default"===e.spending_control||"smart"===e.spending_control)&&(t.spendingControl=e.spending_control),Array.isArray(e.priority_mcc)&&(t.priorityMcc=e.priority_mcc),e.mcc_whitelist&&"object"==typeof e.mcc_whitelist&&(t.mccWhitelist=e.mcc_whitelist),Array.isArray(e.cashback_programs)&&(t.cashbackPrograms=e.cashback_programs.map(e=>({programName:e.program_name,type:e.type,targetPocketUrn:e.target_pocket_urn,...void 0!==e.fee_type&&{feeType:e.fee_type},...void 0!==e.value&&{value:e.value}}))),Array.isArray(e.spending_fees)&&(t.spendingFees=e.spending_fees.map(e=>({feeName:e.fee_name,accountUrn:e.account_urn,type:e.type,value:e.value,...void 0!==e.category&&{category:e.category},...void 0!==e.rule&&{rule:e.rule},...void 0!==e.rule_params&&{ruleParams:e.rule_params}}))),"string"==typeof e.fallback_asset&&(t.fallbackAsset=e.fallback_asset),"boolean"==typeof e.whatsapp_notification&&(t.whatsappNotification=e.whatsapp_notification),e.currency_asset_map&&"object"==typeof e.currency_asset_map&&(t.currencyAssetMap=e.currency_asset_map),Object.keys(t).length>0?t:void 0}function mapCardAccountFromWire(e){let t=e.metadata?.default_asset;return{urn:e.urn,id:e.id,program:e.medium,lastFour:e.details.card_last_four,productType:e.details.card_product_type,status:e.status,cardType:e.details.card_type,statusReason:e.details.status_reason,detailsUrl:e.details.card_url_details,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,defaultAsset:"string"==typeof t&&(0,sdk_core_namespaceObject.isSupportedAsset)(t)?t:void 0,spendingControlMetadata:mapSpendingControlMetadataFromRaw(e.metadata),createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}}class CardClient extends sdk_core_namespaceObject.BaseClient{async create(e={},t){if(e.defaultAsset&&!(0,sdk_core_namespaceObject.isSupportedAsset)(e.defaultAsset))throw Error(`Invalid asset type "${e.defaultAsset}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let a=e.program||"card",r=e.cardType||"VIRTUAL";if("PHYSICAL"===r&&!e.cardAddress)throw Error('cardAddress is required when cardType is "PHYSICAL"');let n={holder_urn:e?.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{create:{card_type:r,...e.cardAddress&&{card_address:{street_name:e.cardAddress.streetName,street_number:e.cardAddress.streetNumber,floor:e.cardAddress.floor,apartment:e.cardAddress.apartment,city:e.cardAddress.city,region:e.cardAddress.region,country:e.cardAddress.country,zip_code:e.cardAddress.zipCode,neighborhood:e.cardAddress.neighborhood}}}},metadata:{source:"sdk-typescript",name:e.name,...e.metadata,...e.spendingControlMetadata&&mapSpendingControlMetadataToRaw(e.spendingControlMetadata),...e.defaultAsset&&{default_asset:e.defaultAsset}}},o=await this.httpClient.request({method:"POST",path:`/api/mediums/${a}`,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,a):s}async _waitForActiveStatus(e,t,a){let r=Date.now();for(;;){if(Date.now()-r>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let n=(await this.list({urn:e,program:a})).accounts[0];if(!n)throw Error(`Account not found. URN: ${e}`);if("active"===n.status)return n;if("creation_failed"===n.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=e?.program||"card",r=new URLSearchParams;r.append("medium",a),t&&r.append("holder_urn",t),e?.urn&&r.append("urn",e.urn);let n=`/api/accounts?${r.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:n})).accounts.map(mapCardAccountFromWire)}}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.statusReason||e.pin?{...e.statusReason&&{status_reason:e.statusReason},...e.pin&&{pin:e.pin}}:void 0,a={...e.metadata&&{metadata:e.metadata},...e.status&&{status:e.status},...e.webhookUrl&&{webhook_url:e.webhookUrl},...e.ledgerId&&{ledger_account_id:e.ledgerId},...t&&{input:t}},r=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:a});return this._mapAccountResponse(r.result.account)}async updateMetadata(e){if(e.defaultAsset&&!(0,sdk_core_namespaceObject.isSupportedAsset)(e.defaultAsset))throw Error(`Invalid asset type "${e.defaultAsset}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);if(!e.metadata&&!e.defaultAsset&&!e.spendingControlMetadata)throw Error("updateMetadata requires `metadata`, `defaultAsset`, or `spendingControlMetadata`");let t={metadata:{...e.metadata,...e.spendingControlMetadata&&mapSpendingControlMetadataToRaw(e.spendingControlMetadata),...e.defaultAsset&&{default_asset:e.defaultAsset}}},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 updateStatus(e,t,a){return this._updateStatus(e,t,a)}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,a){let r={status:t,...a&&{input:{status_reason:a}}},n=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:r});return this._mapAccountResponse(n.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=e.idempotencyKey??(void 0!==globalThis.crypto&&"function"==typeof globalThis.crypto.randomUUID?globalThis.crypto.randomUUID():`idem_${Date.now()}_${Math.random().toString(36).slice(2)}`),a={amount:e.amount,idempotency_key:t},r=await this.httpClient.request({method:"POST",path:`/api/mediums/external-us-bank/${encodeURIComponent(e.urn)}/pull`,body:a,headers:{"Idempotency-Key":t}});return{orderSig:r.result?.order_sig,graphId:r.result?.graph_id,status:r.result?.status,execution:r.result?.execution,requestId:r.req_id}}}function mapPolygonAccountFromWire(e){return{urn:e.urn,id:e.id,address:e.details.address,fundingTx:e.details.funding_tx,network:e.details.network,openDeposits:e.details.open_deposits?Object.fromEntries(Object.entries(e.details.open_deposits).map(([e,t])=>[e,{fromAccountId:t.from_account_id,sweptHash:t.swept_hash,toLedgerAccountId:t.to_ledger_account_id,fromAmount:t.from_amount}])):void 0,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,transliterated_first_name:e.transliteratedFirstName,transliterated_middle_name:e.transliteratedMiddleName,transliterated_last_name:e.transliteratedLastName,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,gov_id_image_back:e.govIdImageBack,proof_of_address_document:e.proofOfAddressDocument,signed_agreement_id:e.signedAgreementId,...e.sofEuQuestionnaire&&{sof_eu_questionnaire:{acting_as_intermediary:e.sofEuQuestionnaire.actingAsIntermediary,employment_status:e.sofEuQuestionnaire.employmentStatus,expected_monthly_payments:e.sofEuQuestionnaire.expectedMonthlyPayments,most_recent_occupation:e.sofEuQuestionnaire.mostRecentOccupation,primary_purpose:e.sofEuQuestionnaire.primaryPurpose,primary_purpose_other:e.sofEuQuestionnaire.primaryPurposeOther,source_of_funds:e.sofEuQuestionnaire.sourceOfFunds}}},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(e){let t=new URLSearchParams;for(let a of e?.accountUrns??[])t.append("account_urns",a);let a=t.toString(),r=a?`/api/accounts/balances?${a}`:"/api/accounts/balances";return(await this.httpClient.request({method:"GET",path:r})).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;for(let r of(t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn),e?.urns??[]))a.append("urns",r);for(let t of(e?.medium&&a.append("medium",e.medium),e?.q&&a.append("q",e.q),e?.customId&&a.append("custom_id",e.customId),Array.isArray(e?.status)?e?.status??[]:e?.status?[e.status]:[]))a.append("status",t);for(let t of(e?.createdAfter&&a.append("created_after",e.createdAfter),e?.createdBefore&&a.append("created_before",e.createdBefore),e?.ledgerAccountId&&a.append("ledger_account_id",e.ledgerAccountId),e?.ledgerAccountIds??[]))a.append("ledger_account_ids",t);for(let[t,r]of(e?.limit!==void 0&&a.append("limit",e.limit.toString()),e?.offset!==void 0&&a.append("offset",e.offset.toString()),e?.order&&a.append("order",e.order),Object.entries(e?.metadata??{})))a.append(`metadata[${t}]`,r);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}),n=r.result.chunks.map(e=>({queueId:e.queue_id,status:e.status,message:e.message}));return{status:r.result.status,chunks:n,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;for(let r of(a.set("asset",t),e.accountUrns??[]))a.append("account_urns",r);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){let t=e.medium;if("card"===t||t.startsWith("card-"))return mapCardAccountFromWire(e);switch(t){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,vat:e.vat?{vatValue:e.vat.vat_value,vatBaseValue:e.vat.vat_base_value,vatType:e.vat.vat_type}:null,inc:e.inc?{incValue:e.inc.inc_value,incType:e.inc.inc_type}:null,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 mapSpendingControlMetadataToRaw(e){let t={};return void 0!==e.spendingControl&&(t.spending_control=e.spendingControl),void 0!==e.priorityMcc&&(t.priority_mcc=e.priorityMcc),void 0!==e.mccWhitelist&&(t.mcc_whitelist=e.mccWhitelist),void 0!==e.cashbackPrograms&&(t.cashback_programs=e.cashbackPrograms.map(e=>({program_name:e.programName,type:e.type,target_pocket_urn:e.targetPocketUrn,...e.feeType&&{fee_type:e.feeType},...void 0!==e.value&&{value:e.value}}))),void 0!==e.spendingFees&&(t.spending_fees=e.spendingFees.map(e=>({fee_name:e.feeName,account_urn:e.accountUrn,type:e.type,value:e.value,...e.category&&{category:e.category},...e.rule&&{rule:e.rule},...e.ruleParams&&{rule_params:e.ruleParams}}))),void 0!==e.fallbackAsset&&(t.fallback_asset=e.fallbackAsset),void 0!==e.whatsappNotification&&(t.whatsapp_notification=e.whatsappNotification),void 0!==e.currencyAssetMap&&(t.currency_asset_map=e.currencyAssetMap),t}function mapSpendingControlMetadataFromRaw(e){if(!e)return;let t={};return("default"===e.spending_control||"smart"===e.spending_control)&&(t.spendingControl=e.spending_control),Array.isArray(e.priority_mcc)&&(t.priorityMcc=e.priority_mcc),e.mcc_whitelist&&"object"==typeof e.mcc_whitelist&&(t.mccWhitelist=e.mcc_whitelist),Array.isArray(e.cashback_programs)&&(t.cashbackPrograms=e.cashback_programs.map(e=>({programName:e.program_name,type:e.type,targetPocketUrn:e.target_pocket_urn,...void 0!==e.fee_type&&{feeType:e.fee_type},...void 0!==e.value&&{value:e.value}}))),Array.isArray(e.spending_fees)&&(t.spendingFees=e.spending_fees.map(e=>({feeName:e.fee_name,accountUrn:e.account_urn,type:e.type,value:e.value,...void 0!==e.category&&{category:e.category},...void 0!==e.rule&&{rule:e.rule},...void 0!==e.rule_params&&{ruleParams:e.rule_params}}))),"string"==typeof e.fallback_asset&&(t.fallbackAsset=e.fallback_asset),"boolean"==typeof e.whatsapp_notification&&(t.whatsappNotification=e.whatsapp_notification),e.currency_asset_map&&"object"==typeof e.currency_asset_map&&(t.currencyAssetMap=e.currency_asset_map),Object.keys(t).length>0?t:void 0}function mapCardAccountFromWire(e){let t=e.metadata?.default_asset;return{urn:e.urn,id:e.id,program:e.medium,lastFour:e.details.card_last_four,productType:e.details.card_product_type,status:e.status,cardType:e.details.card_type,statusReason:e.details.status_reason,detailsUrl:e.details.card_url_details,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,defaultAsset:"string"==typeof t&&(0,sdk_core_namespaceObject.isSupportedAsset)(t)?t:void 0,spendingControlMetadata:mapSpendingControlMetadataFromRaw(e.metadata),createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}}class CardClient extends sdk_core_namespaceObject.BaseClient{async create(e={},t){if(e.defaultAsset&&!(0,sdk_core_namespaceObject.isSupportedAsset)(e.defaultAsset))throw Error(`Invalid asset type "${e.defaultAsset}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let a=e.program||"card",r=e.cardType||"VIRTUAL";if("PHYSICAL"===r&&!e.cardAddress)throw Error('cardAddress is required when cardType is "PHYSICAL"');let n={holder_urn:e?.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{create:{card_type:r,...e.cardAddress&&{card_address:{street_name:e.cardAddress.streetName,street_number:e.cardAddress.streetNumber,floor:e.cardAddress.floor,apartment:e.cardAddress.apartment,city:e.cardAddress.city,region:e.cardAddress.region,country:e.cardAddress.country,zip_code:e.cardAddress.zipCode,neighborhood:e.cardAddress.neighborhood}}}},metadata:{source:"sdk-typescript",name:e.name,...e.metadata,...e.spendingControlMetadata&&mapSpendingControlMetadataToRaw(e.spendingControlMetadata),...e.defaultAsset&&{default_asset:e.defaultAsset}}},o=await this.httpClient.request({method:"POST",path:`/api/mediums/${a}`,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,a):s}async _waitForActiveStatus(e,t,a){let r=Date.now();for(;;){if(Date.now()-r>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let n=(await this.list({urn:e,program:a})).accounts[0];if(!n)throw Error(`Account not found. URN: ${e}`);if("active"===n.status)return n;if("creation_failed"===n.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=e?.program||"card",r=new URLSearchParams;r.append("medium",a),t&&r.append("holder_urn",t),e?.urn&&r.append("urn",e.urn);let n=`/api/accounts?${r.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:n})).accounts.map(mapCardAccountFromWire)}}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.statusReason||e.pin?{...e.statusReason&&{status_reason:e.statusReason},...e.pin&&{pin:e.pin}}:void 0,a={...e.metadata&&{metadata:e.metadata},...e.status&&{status:e.status},...e.webhookUrl&&{webhook_url:e.webhookUrl},...e.ledgerId&&{ledger_account_id:e.ledgerId},...t&&{input:t}},r=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:a});return this._mapAccountResponse(r.result.account)}async updateMetadata(e){if(e.defaultAsset&&!(0,sdk_core_namespaceObject.isSupportedAsset)(e.defaultAsset))throw Error(`Invalid asset type "${e.defaultAsset}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);if(!e.metadata&&!e.defaultAsset&&!e.spendingControlMetadata)throw Error("updateMetadata requires `metadata`, `defaultAsset`, or `spendingControlMetadata`");let t={metadata:{...e.metadata,...e.spendingControlMetadata&&mapSpendingControlMetadataToRaw(e.spendingControlMetadata),...e.defaultAsset&&{default_asset:e.defaultAsset}}},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 updateStatus(e,t,a){return this._updateStatus(e,t,a)}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,a){let r={status:t,...a&&{input:{status_reason:a}}},n=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:r});return this._mapAccountResponse(n.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=e.idempotencyKey??(void 0!==globalThis.crypto&&"function"==typeof globalThis.crypto.randomUUID?globalThis.crypto.randomUUID():`idem_${Date.now()}_${Math.random().toString(36).slice(2)}`),a={amount:e.amount,idempotency_key:t},r=await this.httpClient.request({method:"POST",path:`/api/mediums/external-us-bank/${encodeURIComponent(e.urn)}/pull`,body:a,headers:{"Idempotency-Key":t}});return{orderSig:r.result?.order_sig,graphId:r.result?.graph_id,status:r.result?.status,execution:r.result?.execution,requestId:r.req_id}}}function mapPolygonAccountFromWire(e){return{urn:e.urn,id:e.id,address:e.details.address,fundingTx:e.details.funding_tx,network:e.details.network,openDeposits:e.details.open_deposits?Object.fromEntries(Object.entries(e.details.open_deposits).map(([e,t])=>[e,{fromAccountId:t.from_account_id,sweptHash:t.swept_hash,toLedgerAccountId:t.to_ledger_account_id,fromAmount:t.from_amount}])):void 0,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,transliterated_first_name:e.transliteratedFirstName,transliterated_middle_name:e.transliteratedMiddleName,transliterated_last_name:e.transliteratedLastName,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,gov_id_image_back:e.govIdImageBack,proof_of_address_document:e.proofOfAddressDocument,signed_agreement_id:e.signedAgreementId,...e.sofEuQuestionnaire&&{sof_eu_questionnaire:{acting_as_intermediary:e.sofEuQuestionnaire.actingAsIntermediary,employment_status:e.sofEuQuestionnaire.employmentStatus,expected_monthly_payments:e.sofEuQuestionnaire.expectedMonthlyPayments,most_recent_occupation:e.sofEuQuestionnaire.mostRecentOccupation,primary_purpose:e.sofEuQuestionnaire.primaryPurpose,primary_purpose_other:e.sofEuQuestionnaire.primaryPurposeOther,source_of_funds:e.sofEuQuestionnaire.sourceOfFunds}}},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,ledgerAccountUrn:e.metadata?.ledger_account_urn,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(e){let t=new URLSearchParams;for(let a of e?.accountUrns??[])t.append("account_urns",a);let a=t.toString(),r=a?`/api/accounts/balances?${a}`:"/api/accounts/balances";return(await this.httpClient.request({method:"GET",path:r})).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;for(let r of(t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn),e?.urns??[]))a.append("urns",r);for(let t of(e?.medium&&a.append("medium",e.medium),e?.q&&a.append("q",e.q),e?.customId&&a.append("custom_id",e.customId),Array.isArray(e?.status)?e?.status??[]:e?.status?[e.status]:[]))a.append("status",t);for(let t of(e?.createdAfter&&a.append("created_after",e.createdAfter),e?.createdBefore&&a.append("created_before",e.createdBefore),e?.ledgerAccountId&&a.append("ledger_account_id",e.ledgerAccountId),e?.ledgerAccountIds??[]))a.append("ledger_account_ids",t);for(let[t,r]of(e?.limit!==void 0&&a.append("limit",e.limit.toString()),e?.offset!==void 0&&a.append("offset",e.offset.toString()),e?.order&&a.append("order",e.order),Object.entries(e?.metadata??{})))a.append(`metadata[${t}]`,r);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}),n=r.result.chunks.map(e=>({queueId:e.queue_id,status:e.status,message:e.message}));return{status:r.result.status,chunks:n,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;for(let r of(a.set("asset",t),e.accountUrns??[]))a.append("account_urns",r);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){let t=e.medium;if("card"===t||t.startsWith("card-"))return mapCardAccountFromWire(e);switch(t){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 e,BloqueAPIError as t,SUPPORTED_ASSETS as a,isSupportedAsset as r}from"@bloque/sdk-core";function n(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 s extends e{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 n(e)}}function o(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}}class i extends e{mapError(e){if(e instanceof t){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:o(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{var t;if(!e.qrCodeData?.trim())throw Error("BRE-B QR code data is required");return{data:{amount:(t=(await this.httpClient.request({method:"POST",path:"/api/mediums/breb/decode-qr",body:{qr_code_data:e.qrCodeData}})).result).amount,additionalInfo:t.additional_info?{transactionPurpose:t.additional_info.transaction_purpose,terminalLabel:t.additional_info.terminal_label,invoiceNumber:t.additional_info.invoice_number,mobilePhoneNumber:t.additional_info.mobile_phone_number,storeLabel:t.additional_info.store_label,loyaltyLabel:t.additional_info.loyalty_label,referenceLabel:t.additional_info.reference_label,customerLabel:t.additional_info.customer_label,customerInfo:t.additional_info.customer_info,channelPresentation:t.additional_info.channel_presentation}:null,key:t.key?{keyType:t.key.key_type,keyValue:t.key.key_value}:null,qrCodeData:t.qr_code_data,status:t.status,acquirerNetworkIdentifier:t.acquirer_network_identifier,merchant:t.merchant?{merchantCategoryCode:t.merchant.merchant_category_code,merchantCountry:t.merchant.merchant_country,merchantName:t.merchant.merchant_name,merchantCity:t.merchant.merchant_city,merchantPostCode:t.merchant.merchant_post_code}:null,channel:t.channel,vat:t.vat?{vatValue:t.vat.vat_value,vatBaseValue:t.vat.vat_base_value,vatType:t.vat.vat_type}:null,inc:t.inc?{incValue:t.inc.inc_value,incType:t.inc.inc_type}:null,qrCodeReference:t.qr_code_reference,type:t.type,resolutionId:t.resolution_id,resolution:t.resolution},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 d(e){let t={};return void 0!==e.spendingControl&&(t.spending_control=e.spendingControl),void 0!==e.priorityMcc&&(t.priority_mcc=e.priorityMcc),void 0!==e.mccWhitelist&&(t.mcc_whitelist=e.mccWhitelist),void 0!==e.cashbackPrograms&&(t.cashback_programs=e.cashbackPrograms.map(e=>({program_name:e.programName,type:e.type,target_pocket_urn:e.targetPocketUrn,...e.feeType&&{fee_type:e.feeType},...void 0!==e.value&&{value:e.value}}))),void 0!==e.spendingFees&&(t.spending_fees=e.spendingFees.map(e=>({fee_name:e.feeName,account_urn:e.accountUrn,type:e.type,value:e.value,...e.category&&{category:e.category},...e.rule&&{rule:e.rule},...e.ruleParams&&{rule_params:e.ruleParams}}))),void 0!==e.fallbackAsset&&(t.fallback_asset=e.fallbackAsset),void 0!==e.whatsappNotification&&(t.whatsapp_notification=e.whatsappNotification),void 0!==e.currencyAssetMap&&(t.currency_asset_map=e.currencyAssetMap),t}function c(e){let t=e.metadata?.default_asset;return{urn:e.urn,id:e.id,program:e.medium,lastFour:e.details.card_last_four,productType:e.details.card_product_type,status:e.status,cardType:e.details.card_type,statusReason:e.details.status_reason,detailsUrl:e.details.card_url_details,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,defaultAsset:"string"==typeof t&&r(t)?t:void 0,spendingControlMetadata:function(e){if(!e)return;let t={};return("default"===e.spending_control||"smart"===e.spending_control)&&(t.spendingControl=e.spending_control),Array.isArray(e.priority_mcc)&&(t.priorityMcc=e.priority_mcc),e.mcc_whitelist&&"object"==typeof e.mcc_whitelist&&(t.mccWhitelist=e.mcc_whitelist),Array.isArray(e.cashback_programs)&&(t.cashbackPrograms=e.cashback_programs.map(e=>({programName:e.program_name,type:e.type,targetPocketUrn:e.target_pocket_urn,...void 0!==e.fee_type&&{feeType:e.fee_type},...void 0!==e.value&&{value:e.value}}))),Array.isArray(e.spending_fees)&&(t.spendingFees=e.spending_fees.map(e=>({feeName:e.fee_name,accountUrn:e.account_urn,type:e.type,value:e.value,...void 0!==e.category&&{category:e.category},...void 0!==e.rule&&{rule:e.rule},...void 0!==e.rule_params&&{ruleParams:e.rule_params}}))),"string"==typeof e.fallback_asset&&(t.fallbackAsset=e.fallback_asset),"boolean"==typeof e.whatsapp_notification&&(t.whatsappNotification=e.whatsapp_notification),e.currency_asset_map&&"object"==typeof e.currency_asset_map&&(t.currencyAssetMap=e.currency_asset_map),Object.keys(t).length>0?t:void 0}(e.metadata),createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}}class u extends e{async create(e={},t){if(e.defaultAsset&&!r(e.defaultAsset))throw Error(`Invalid asset type "${e.defaultAsset}". Supported assets: ${a.join(", ")}`);let n=e.program||"card",s=e.cardType||"VIRTUAL";if("PHYSICAL"===s&&!e.cardAddress)throw Error('cardAddress is required when cardType is "PHYSICAL"');let o={holder_urn:e?.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{create:{card_type:s,...e.cardAddress&&{card_address:{street_name:e.cardAddress.streetName,street_number:e.cardAddress.streetNumber,floor:e.cardAddress.floor,apartment:e.cardAddress.apartment,city:e.cardAddress.city,region:e.cardAddress.region,country:e.cardAddress.country,zip_code:e.cardAddress.zipCode,neighborhood:e.cardAddress.neighborhood}}}},metadata:{source:"sdk-typescript",name:e.name,...e.metadata,...e.spendingControlMetadata&&d(e.spendingControlMetadata),...e.defaultAsset&&{default_asset:e.defaultAsset}}},i=await this.httpClient.request({method:"POST",path:`/api/mediums/${n}`,body:o,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),c=this._mapAccountResponse(i.result.account);return t?.waitLedger?this._waitForActiveStatus(c.urn,t.timeout||6e4,n):c}async _waitForActiveStatus(e,t,a){let r=Date.now();for(;;){if(Date.now()-r>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let n=(await this.list({urn:e,program:a})).accounts[0];if(!n)throw Error(`Account not found. URN: ${e}`);if("active"===n.status)return n;if("creation_failed"===n.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=e?.program||"card",r=new URLSearchParams;r.append("medium",a),t&&r.append("holder_urn",t),e?.urn&&r.append("urn",e.urn);let n=`/api/accounts?${r.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:n})).accounts.map(c)}}async movements(e){let t=new URLSearchParams,n=e.asset||"DUSD/6";if(!r(n))throw Error(`Invalid asset type "${n}". Supported assets: ${a.join(", ")}`);t.set("asset",n),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 s=t.toString(),o=`/api/accounts/${e.urn}/movements${s?`?${s}`:""}`,i=await this.httpClient.request({method:"GET",path:o});return{data:i.data,pageSize:i.page_size,hasMore:i.has_more,next:i.next}}async balance(e){return(await this.httpClient.request({method:"GET",path:`/api/accounts/${e.urn}/balance`})).balance}async update(e){let t=e.statusReason||e.pin?{...e.statusReason&&{status_reason:e.statusReason},...e.pin&&{pin:e.pin}}:void 0,a={...e.metadata&&{metadata:e.metadata},...e.status&&{status:e.status},...e.webhookUrl&&{webhook_url:e.webhookUrl},...e.ledgerId&&{ledger_account_id:e.ledgerId},...t&&{input:t}},r=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:a});return this._mapAccountResponse(r.result.account)}async updateMetadata(e){if(e.defaultAsset&&!r(e.defaultAsset))throw Error(`Invalid asset type "${e.defaultAsset}". Supported assets: ${a.join(", ")}`);if(!e.metadata&&!e.defaultAsset&&!e.spendingControlMetadata)throw Error("updateMetadata requires `metadata`, `defaultAsset`, or `spendingControlMetadata`");let t={metadata:{...e.metadata,...e.spendingControlMetadata&&d(e.spendingControlMetadata),...e.defaultAsset&&{default_asset:e.defaultAsset}}},n=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(n.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 updateStatus(e,t,a){return this._updateStatus(e,t,a)}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,a){let r={status:t,...a&&{input:{status_reason:a}}},n=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:r});return this._mapAccountResponse(n.result.account)}_mapAccountResponse(e){return c(e)}}function l(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 p(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:l(e.details.bank_address),beneficiaryAddress:l(e.details.beneficiary_address),transferTypes:e.details.transfer_types,needsUpdate:e.details.needs_update,lastUpdated:e.details.last_updated}}}class m extends e{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 p((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 p((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=e.idempotencyKey??(void 0!==globalThis.crypto&&"function"==typeof globalThis.crypto.randomUUID?globalThis.crypto.randomUUID():`idem_${Date.now()}_${Math.random().toString(36).slice(2)}`),a={amount:e.amount,idempotency_key:t},r=await this.httpClient.request({method:"POST",path:`/api/mediums/external-us-bank/${encodeURIComponent(e.urn)}/pull`,body:a,headers:{"Idempotency-Key":t}});return{orderSig:r.result?.order_sig,graphId:r.result?.graph_id,status:r.result?.status,execution:r.result?.execution,requestId:r.req_id}}}function h(e){return{urn:e.urn,id:e.id,address:e.details.address,fundingTx:e.details.funding_tx,network:e.details.network,openDeposits:e.details.open_deposits?Object.fromEntries(Object.entries(e.details.open_deposits).map(([e,t])=>[e,{fromAccountId:t.from_account_id,sweptHash:t.swept_hash,toLedgerAccountId:t.to_ledger_account_id,fromAmount:t.from_amount}])):void 0,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 _ extends e{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 h(e)}}function y(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 f extends e{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,transliterated_first_name:e.transliteratedFirstName,transliterated_middle_name:e.transliteratedMiddleName,transliterated_last_name:e.transliteratedLastName,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,gov_id_image_back:e.govIdImageBack,proof_of_address_document:e.proofOfAddressDocument,signed_agreement_id:e.signedAgreementId,...e.sofEuQuestionnaire&&{sof_eu_questionnaire:{acting_as_intermediary:e.sofEuQuestionnaire.actingAsIntermediary,employment_status:e.sofEuQuestionnaire.employmentStatus,expected_monthly_payments:e.sofEuQuestionnaire.expectedMonthlyPayments,most_recent_occupation:e.sofEuQuestionnaire.mostRecentOccupation,primary_purpose:e.sofEuQuestionnaire.primaryPurpose,primary_purpose_other:e.sofEuQuestionnaire.primaryPurposeOther,source_of_funds:e.sofEuQuestionnaire.sourceOfFunds}}},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}},s=await this.httpClient.request({method:"POST",path:"/api/mediums/us-account",body:n,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),o=this._mapAccountResponse(s.result.account);return t?.waitLedger?this._waitForActiveStatus(o.urn,t.timeout||6e4):o}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 y(e)}}function b(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 w extends e{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 b((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=>b(e))}}}function g(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 A extends e{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 g(e)}}class k extends e{bancolombia;breb;card;externalUsBank;polygon;us;us2;virtual;constructor(e){super(e),this.bancolombia=new s(this.httpClient),this.breb=new i(this.httpClient),this.card=new u(this.httpClient),this.externalUsBank=new m(this.httpClient),this.polygon=new _(this.httpClient),this.us=new f(this.httpClient),this.us2=new w(this.httpClient),this.virtual=new A(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(e){let t=new URLSearchParams;for(let a of e?.accountUrns??[])t.append("account_urns",a);let a=t.toString(),r=a?`/api/accounts/balances?${a}`:"/api/accounts/balances";return(await this.httpClient.request({method:"GET",path:r})).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;for(let r of(t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn),e?.urns??[]))a.append("urns",r);for(let t of(e?.medium&&a.append("medium",e.medium),e?.q&&a.append("q",e.q),e?.customId&&a.append("custom_id",e.customId),Array.isArray(e?.status)?e?.status??[]:e?.status?[e.status]:[]))a.append("status",t);for(let t of(e?.createdAfter&&a.append("created_after",e.createdAfter),e?.createdBefore&&a.append("created_before",e.createdBefore),e?.ledgerAccountId&&a.append("ledger_account_id",e.ledgerAccountId),e?.ledgerAccountIds??[]))a.append("ledger_account_ids",t);for(let[t,r]of(e?.limit!==void 0&&a.append("limit",e.limit.toString()),e?.offset!==void 0&&a.append("offset",e.offset.toString()),e?.order&&a.append("order",e.order),Object.entries(e?.metadata??{})))a.append(`metadata[${t}]`,r);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 n=e.asset||"DUSD/6";if(!r(n))throw Error(`Invalid asset type "${n}". Supported assets: ${a.join(", ")}`);let s={destination_account_urn:e.destinationUrn,amount:e.amount,asset:n,metadata:e.metadata},o=await this.httpClient.request({method:"POST",path:`/api/accounts/${e.sourceUrn}/transfer`,body:s,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0});return{queueId:o.result.queue_id,status:o.result.status,message:o.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(!r(t.asset))throw Error(`Invalid asset type "${t.asset}" in operation "${t.reference}". Supported assets: ${a.join(", ")}`);let n={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},s=await this.httpClient.request({method:"POST",path:"/api/accounts/batch/transfer",body:n,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),o=s.result.chunks.map(e=>({queueId:e.queue_id,status:e.status,message:e.message}));return{status:s.result.status,chunks:o,totalOperations:s.result.total_operations,totalChunks:s.result.total_chunks}}async movements(e){if(!e.urn)throw Error("Account URN is required");let t=e.asset||"DUSD/6";if(!r(t))throw Error(`Invalid asset type "${t}". Supported assets: ${a.join(", ")}`);let n=new URLSearchParams;n.set("asset",t),void 0!==e.limit&&n.set("limit",e.limit.toString()),e.before&&n.set("before",e.before),e.after&&n.set("after",e.after),e.reference&&n.set("reference",e.reference),e.direction&&n.set("direction",e.direction),void 0!==e.collapsed_view&&n.set("collapsed_view",String(e.collapsed_view)),e.pocket&&n.set("pocket",e.pocket),e.next&&n.set("next",e.next);let s=`/api/accounts/${e.urn}/movements?${n.toString()}`,o=await this.httpClient.request({method:"GET",path:s});return{data:o.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:o.page_size,hasMore:o.has_more,next:o.next}}async transactions(e={}){let t=e.asset||"DUSD/6";if(!r(t))throw Error(`Invalid asset type "${t}". Supported assets: ${a.join(", ")}`);let n=new URLSearchParams;for(let a of(n.set("asset",t),e.accountUrns??[]))n.append("account_urns",a);void 0!==e.limit&&n.set("limit",e.limit.toString()),e.before&&n.set("before",e.before),e.after&&n.set("after",e.after),e.reference&&n.set("reference",e.reference),e.direction&&n.set("direction",e.direction),void 0!==e.collapsed_view&&n.set("collapsed_view",String(e.collapsed_view)),e.pocket&&n.set("pocket",e.pocket),e.next&&n.set("next",e.next);let s=await this.httpClient.request({method:"GET",path:`/api/accounts/transactions?${n.toString()}`});return{data:s.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:s.page_size,hasMore:s.has_more,next:s.next}}_mapByMedium(e){let t=e.medium;if("card"===t||t.startsWith("card-"))return c(e);switch(t){case"virtual":return g(e);case"polygon":return h(e);case"bancolombia":return n(e);case"breb":return o(e);case"external-us-bank":return p(e);case"us-account":return y(e);case"us2-account":return b(e);default:throw Error(`Unknown account medium: ${e.medium}`)}}}export{k as AccountsClient,s as BancolombiaClient,i as BrebClient,u as CardClient,m as ExternalUsBankClient,_ as PolygonClient,w as Us2Client,f as UsClient,A as VirtualClient,n as mapBancolombiaAccountFromWire,o as mapBrebAccountFromWire,c as mapCardAccountFromWire,p as mapExternalUsBankAccountFromWire,h as mapPolygonAccountFromWire,b as mapUs2AccountFromWire,y as mapUsAccountFromWire,g as mapVirtualAccountFromWire};
|
|
1
|
+
import{BaseClient as e,BloqueAPIError as t,SUPPORTED_ASSETS as a,isSupportedAsset as r}from"@bloque/sdk-core";function n(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 s extends e{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 n(e)}}function o(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}}class i extends e{mapError(e){if(e instanceof t){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:o(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{var t;if(!e.qrCodeData?.trim())throw Error("BRE-B QR code data is required");return{data:{amount:(t=(await this.httpClient.request({method:"POST",path:"/api/mediums/breb/decode-qr",body:{qr_code_data:e.qrCodeData}})).result).amount,additionalInfo:t.additional_info?{transactionPurpose:t.additional_info.transaction_purpose,terminalLabel:t.additional_info.terminal_label,invoiceNumber:t.additional_info.invoice_number,mobilePhoneNumber:t.additional_info.mobile_phone_number,storeLabel:t.additional_info.store_label,loyaltyLabel:t.additional_info.loyalty_label,referenceLabel:t.additional_info.reference_label,customerLabel:t.additional_info.customer_label,customerInfo:t.additional_info.customer_info,channelPresentation:t.additional_info.channel_presentation}:null,key:t.key?{keyType:t.key.key_type,keyValue:t.key.key_value}:null,qrCodeData:t.qr_code_data,status:t.status,acquirerNetworkIdentifier:t.acquirer_network_identifier,merchant:t.merchant?{merchantCategoryCode:t.merchant.merchant_category_code,merchantCountry:t.merchant.merchant_country,merchantName:t.merchant.merchant_name,merchantCity:t.merchant.merchant_city,merchantPostCode:t.merchant.merchant_post_code}:null,channel:t.channel,vat:t.vat?{vatValue:t.vat.vat_value,vatBaseValue:t.vat.vat_base_value,vatType:t.vat.vat_type}:null,inc:t.inc?{incValue:t.inc.inc_value,incType:t.inc.inc_type}:null,qrCodeReference:t.qr_code_reference,type:t.type,resolutionId:t.resolution_id,resolution:t.resolution},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 d(e){let t={};return void 0!==e.spendingControl&&(t.spending_control=e.spendingControl),void 0!==e.priorityMcc&&(t.priority_mcc=e.priorityMcc),void 0!==e.mccWhitelist&&(t.mcc_whitelist=e.mccWhitelist),void 0!==e.cashbackPrograms&&(t.cashback_programs=e.cashbackPrograms.map(e=>({program_name:e.programName,type:e.type,target_pocket_urn:e.targetPocketUrn,...e.feeType&&{fee_type:e.feeType},...void 0!==e.value&&{value:e.value}}))),void 0!==e.spendingFees&&(t.spending_fees=e.spendingFees.map(e=>({fee_name:e.feeName,account_urn:e.accountUrn,type:e.type,value:e.value,...e.category&&{category:e.category},...e.rule&&{rule:e.rule},...e.ruleParams&&{rule_params:e.ruleParams}}))),void 0!==e.fallbackAsset&&(t.fallback_asset=e.fallbackAsset),void 0!==e.whatsappNotification&&(t.whatsapp_notification=e.whatsappNotification),void 0!==e.currencyAssetMap&&(t.currency_asset_map=e.currencyAssetMap),t}function c(e){let t=e.metadata?.default_asset;return{urn:e.urn,id:e.id,program:e.medium,lastFour:e.details.card_last_four,productType:e.details.card_product_type,status:e.status,cardType:e.details.card_type,statusReason:e.details.status_reason,detailsUrl:e.details.card_url_details,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,defaultAsset:"string"==typeof t&&r(t)?t:void 0,spendingControlMetadata:function(e){if(!e)return;let t={};return("default"===e.spending_control||"smart"===e.spending_control)&&(t.spendingControl=e.spending_control),Array.isArray(e.priority_mcc)&&(t.priorityMcc=e.priority_mcc),e.mcc_whitelist&&"object"==typeof e.mcc_whitelist&&(t.mccWhitelist=e.mcc_whitelist),Array.isArray(e.cashback_programs)&&(t.cashbackPrograms=e.cashback_programs.map(e=>({programName:e.program_name,type:e.type,targetPocketUrn:e.target_pocket_urn,...void 0!==e.fee_type&&{feeType:e.fee_type},...void 0!==e.value&&{value:e.value}}))),Array.isArray(e.spending_fees)&&(t.spendingFees=e.spending_fees.map(e=>({feeName:e.fee_name,accountUrn:e.account_urn,type:e.type,value:e.value,...void 0!==e.category&&{category:e.category},...void 0!==e.rule&&{rule:e.rule},...void 0!==e.rule_params&&{ruleParams:e.rule_params}}))),"string"==typeof e.fallback_asset&&(t.fallbackAsset=e.fallback_asset),"boolean"==typeof e.whatsapp_notification&&(t.whatsappNotification=e.whatsapp_notification),e.currency_asset_map&&"object"==typeof e.currency_asset_map&&(t.currencyAssetMap=e.currency_asset_map),Object.keys(t).length>0?t:void 0}(e.metadata),createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}}class u extends e{async create(e={},t){if(e.defaultAsset&&!r(e.defaultAsset))throw Error(`Invalid asset type "${e.defaultAsset}". Supported assets: ${a.join(", ")}`);let n=e.program||"card",s=e.cardType||"VIRTUAL";if("PHYSICAL"===s&&!e.cardAddress)throw Error('cardAddress is required when cardType is "PHYSICAL"');let o={holder_urn:e?.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{create:{card_type:s,...e.cardAddress&&{card_address:{street_name:e.cardAddress.streetName,street_number:e.cardAddress.streetNumber,floor:e.cardAddress.floor,apartment:e.cardAddress.apartment,city:e.cardAddress.city,region:e.cardAddress.region,country:e.cardAddress.country,zip_code:e.cardAddress.zipCode,neighborhood:e.cardAddress.neighborhood}}}},metadata:{source:"sdk-typescript",name:e.name,...e.metadata,...e.spendingControlMetadata&&d(e.spendingControlMetadata),...e.defaultAsset&&{default_asset:e.defaultAsset}}},i=await this.httpClient.request({method:"POST",path:`/api/mediums/${n}`,body:o,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),c=this._mapAccountResponse(i.result.account);return t?.waitLedger?this._waitForActiveStatus(c.urn,t.timeout||6e4,n):c}async _waitForActiveStatus(e,t,a){let r=Date.now();for(;;){if(Date.now()-r>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let n=(await this.list({urn:e,program:a})).accounts[0];if(!n)throw Error(`Account not found. URN: ${e}`);if("active"===n.status)return n;if("creation_failed"===n.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=e?.program||"card",r=new URLSearchParams;r.append("medium",a),t&&r.append("holder_urn",t),e?.urn&&r.append("urn",e.urn);let n=`/api/accounts?${r.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:n})).accounts.map(c)}}async movements(e){let t=new URLSearchParams,n=e.asset||"DUSD/6";if(!r(n))throw Error(`Invalid asset type "${n}". Supported assets: ${a.join(", ")}`);t.set("asset",n),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 s=t.toString(),o=`/api/accounts/${e.urn}/movements${s?`?${s}`:""}`,i=await this.httpClient.request({method:"GET",path:o});return{data:i.data,pageSize:i.page_size,hasMore:i.has_more,next:i.next}}async balance(e){return(await this.httpClient.request({method:"GET",path:`/api/accounts/${e.urn}/balance`})).balance}async update(e){let t=e.statusReason||e.pin?{...e.statusReason&&{status_reason:e.statusReason},...e.pin&&{pin:e.pin}}:void 0,a={...e.metadata&&{metadata:e.metadata},...e.status&&{status:e.status},...e.webhookUrl&&{webhook_url:e.webhookUrl},...e.ledgerId&&{ledger_account_id:e.ledgerId},...t&&{input:t}},r=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:a});return this._mapAccountResponse(r.result.account)}async updateMetadata(e){if(e.defaultAsset&&!r(e.defaultAsset))throw Error(`Invalid asset type "${e.defaultAsset}". Supported assets: ${a.join(", ")}`);if(!e.metadata&&!e.defaultAsset&&!e.spendingControlMetadata)throw Error("updateMetadata requires `metadata`, `defaultAsset`, or `spendingControlMetadata`");let t={metadata:{...e.metadata,...e.spendingControlMetadata&&d(e.spendingControlMetadata),...e.defaultAsset&&{default_asset:e.defaultAsset}}},n=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(n.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 updateStatus(e,t,a){return this._updateStatus(e,t,a)}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,a){let r={status:t,...a&&{input:{status_reason:a}}},n=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:r});return this._mapAccountResponse(n.result.account)}_mapAccountResponse(e){return c(e)}}function l(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 p(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:l(e.details.bank_address),beneficiaryAddress:l(e.details.beneficiary_address),transferTypes:e.details.transfer_types,needsUpdate:e.details.needs_update,lastUpdated:e.details.last_updated}}}class m extends e{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 p((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 p((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=e.idempotencyKey??(void 0!==globalThis.crypto&&"function"==typeof globalThis.crypto.randomUUID?globalThis.crypto.randomUUID():`idem_${Date.now()}_${Math.random().toString(36).slice(2)}`),a={amount:e.amount,idempotency_key:t},r=await this.httpClient.request({method:"POST",path:`/api/mediums/external-us-bank/${encodeURIComponent(e.urn)}/pull`,body:a,headers:{"Idempotency-Key":t}});return{orderSig:r.result?.order_sig,graphId:r.result?.graph_id,status:r.result?.status,execution:r.result?.execution,requestId:r.req_id}}}function h(e){return{urn:e.urn,id:e.id,address:e.details.address,fundingTx:e.details.funding_tx,network:e.details.network,openDeposits:e.details.open_deposits?Object.fromEntries(Object.entries(e.details.open_deposits).map(([e,t])=>[e,{fromAccountId:t.from_account_id,sweptHash:t.swept_hash,toLedgerAccountId:t.to_ledger_account_id,fromAmount:t.from_amount}])):void 0,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 _ extends e{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 h(e)}}function y(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 f extends e{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,transliterated_first_name:e.transliteratedFirstName,transliterated_middle_name:e.transliteratedMiddleName,transliterated_last_name:e.transliteratedLastName,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,gov_id_image_back:e.govIdImageBack,proof_of_address_document:e.proofOfAddressDocument,signed_agreement_id:e.signedAgreementId,...e.sofEuQuestionnaire&&{sof_eu_questionnaire:{acting_as_intermediary:e.sofEuQuestionnaire.actingAsIntermediary,employment_status:e.sofEuQuestionnaire.employmentStatus,expected_monthly_payments:e.sofEuQuestionnaire.expectedMonthlyPayments,most_recent_occupation:e.sofEuQuestionnaire.mostRecentOccupation,primary_purpose:e.sofEuQuestionnaire.primaryPurpose,primary_purpose_other:e.sofEuQuestionnaire.primaryPurposeOther,source_of_funds:e.sofEuQuestionnaire.sourceOfFunds}}},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}},s=await this.httpClient.request({method:"POST",path:"/api/mediums/us-account",body:n,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),o=this._mapAccountResponse(s.result.account);return t?.waitLedger?this._waitForActiveStatus(o.urn,t.timeout||6e4):o}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 y(e)}}function b(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 w extends e{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 b((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=>b(e))}}}function g(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,ledgerAccountUrn:e.metadata?.ledger_account_urn,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 A extends e{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 g(e)}}class k extends e{bancolombia;breb;card;externalUsBank;polygon;us;us2;virtual;constructor(e){super(e),this.bancolombia=new s(this.httpClient),this.breb=new i(this.httpClient),this.card=new u(this.httpClient),this.externalUsBank=new m(this.httpClient),this.polygon=new _(this.httpClient),this.us=new f(this.httpClient),this.us2=new w(this.httpClient),this.virtual=new A(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(e){let t=new URLSearchParams;for(let a of e?.accountUrns??[])t.append("account_urns",a);let a=t.toString(),r=a?`/api/accounts/balances?${a}`:"/api/accounts/balances";return(await this.httpClient.request({method:"GET",path:r})).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;for(let r of(t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn),e?.urns??[]))a.append("urns",r);for(let t of(e?.medium&&a.append("medium",e.medium),e?.q&&a.append("q",e.q),e?.customId&&a.append("custom_id",e.customId),Array.isArray(e?.status)?e?.status??[]:e?.status?[e.status]:[]))a.append("status",t);for(let t of(e?.createdAfter&&a.append("created_after",e.createdAfter),e?.createdBefore&&a.append("created_before",e.createdBefore),e?.ledgerAccountId&&a.append("ledger_account_id",e.ledgerAccountId),e?.ledgerAccountIds??[]))a.append("ledger_account_ids",t);for(let[t,r]of(e?.limit!==void 0&&a.append("limit",e.limit.toString()),e?.offset!==void 0&&a.append("offset",e.offset.toString()),e?.order&&a.append("order",e.order),Object.entries(e?.metadata??{})))a.append(`metadata[${t}]`,r);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 n=e.asset||"DUSD/6";if(!r(n))throw Error(`Invalid asset type "${n}". Supported assets: ${a.join(", ")}`);let s={destination_account_urn:e.destinationUrn,amount:e.amount,asset:n,metadata:e.metadata},o=await this.httpClient.request({method:"POST",path:`/api/accounts/${e.sourceUrn}/transfer`,body:s,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0});return{queueId:o.result.queue_id,status:o.result.status,message:o.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(!r(t.asset))throw Error(`Invalid asset type "${t.asset}" in operation "${t.reference}". Supported assets: ${a.join(", ")}`);let n={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},s=await this.httpClient.request({method:"POST",path:"/api/accounts/batch/transfer",body:n,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),o=s.result.chunks.map(e=>({queueId:e.queue_id,status:e.status,message:e.message}));return{status:s.result.status,chunks:o,totalOperations:s.result.total_operations,totalChunks:s.result.total_chunks}}async movements(e){if(!e.urn)throw Error("Account URN is required");let t=e.asset||"DUSD/6";if(!r(t))throw Error(`Invalid asset type "${t}". Supported assets: ${a.join(", ")}`);let n=new URLSearchParams;n.set("asset",t),void 0!==e.limit&&n.set("limit",e.limit.toString()),e.before&&n.set("before",e.before),e.after&&n.set("after",e.after),e.reference&&n.set("reference",e.reference),e.direction&&n.set("direction",e.direction),void 0!==e.collapsed_view&&n.set("collapsed_view",String(e.collapsed_view)),e.pocket&&n.set("pocket",e.pocket),e.next&&n.set("next",e.next);let s=`/api/accounts/${e.urn}/movements?${n.toString()}`,o=await this.httpClient.request({method:"GET",path:s});return{data:o.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:o.page_size,hasMore:o.has_more,next:o.next}}async transactions(e={}){let t=e.asset||"DUSD/6";if(!r(t))throw Error(`Invalid asset type "${t}". Supported assets: ${a.join(", ")}`);let n=new URLSearchParams;for(let a of(n.set("asset",t),e.accountUrns??[]))n.append("account_urns",a);void 0!==e.limit&&n.set("limit",e.limit.toString()),e.before&&n.set("before",e.before),e.after&&n.set("after",e.after),e.reference&&n.set("reference",e.reference),e.direction&&n.set("direction",e.direction),void 0!==e.collapsed_view&&n.set("collapsed_view",String(e.collapsed_view)),e.pocket&&n.set("pocket",e.pocket),e.next&&n.set("next",e.next);let s=await this.httpClient.request({method:"GET",path:`/api/accounts/transactions?${n.toString()}`});return{data:s.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:s.page_size,hasMore:s.has_more,next:s.next}}_mapByMedium(e){let t=e.medium;if("card"===t||t.startsWith("card-"))return c(e);switch(t){case"virtual":return g(e);case"polygon":return h(e);case"bancolombia":return n(e);case"breb":return o(e);case"external-us-bank":return p(e);case"us-account":return y(e);case"us2-account":return b(e);default:throw Error(`Unknown account medium: ${e.medium}`)}}}export{k as AccountsClient,s as BancolombiaClient,i as BrebClient,u as CardClient,m as ExternalUsBankClient,_ as PolygonClient,w as Us2Client,f as UsClient,A as VirtualClient,n as mapBancolombiaAccountFromWire,o as mapBrebAccountFromWire,c as mapCardAccountFromWire,p as mapExternalUsBankAccountFromWire,h as mapPolygonAccountFromWire,b as mapUs2AccountFromWire,y as mapUsAccountFromWire,g as mapVirtualAccountFromWire};
|
|
@@ -24,8 +24,22 @@ export interface Account<TDetails = unknown> {
|
|
|
24
24
|
created_at: string;
|
|
25
25
|
updated_at: string;
|
|
26
26
|
webhook_url: string | null;
|
|
27
|
-
metadata?:
|
|
27
|
+
metadata?: AccountMetadata;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* @internal
|
|
31
|
+
* Free-form account metadata, with the keys the platform sets itself called out.
|
|
32
|
+
*/
|
|
33
|
+
export type AccountMetadata = Record<string, unknown> & {
|
|
34
|
+
/**
|
|
35
|
+
* URN of the ledger account backing this account.
|
|
36
|
+
*
|
|
37
|
+
* Set on `virtual` accounts created without an explicit `ledger_account_id` —
|
|
38
|
+
* the ledger service mints the account and returns both its address
|
|
39
|
+
* (`ledger_account_id`) and its URN in the same response.
|
|
40
|
+
*/
|
|
41
|
+
ledger_account_urn?: string;
|
|
42
|
+
};
|
|
29
43
|
/**
|
|
30
44
|
* @internal
|
|
31
45
|
* Card type enum
|
package/dist/polygon/types.d.ts
CHANGED
|
@@ -35,8 +35,13 @@ export interface CreatePolygonAccountParams {
|
|
|
35
35
|
*/
|
|
36
36
|
name?: string;
|
|
37
37
|
/**
|
|
38
|
-
* Ledger account ID to associate with the polygon account
|
|
39
|
-
*
|
|
38
|
+
* Ledger account ID to associate with the polygon account.
|
|
39
|
+
*
|
|
40
|
+
* If not provided, a new ledger account is created automatically — but
|
|
41
|
+
* unlike `accounts.virtual.create()`, its id is not available in this
|
|
42
|
+
* response; it arrives once provisioning settles. Prefer creating a virtual
|
|
43
|
+
* account first and passing its `ledgerId` here when you need the two to
|
|
44
|
+
* share a balance.
|
|
40
45
|
*/
|
|
41
46
|
ledgerId?: string;
|
|
42
47
|
/**
|
package/dist/types.d.ts
CHANGED
|
@@ -9,8 +9,16 @@ export type { SupportedAsset } from '@bloque/sdk-core';
|
|
|
9
9
|
*/
|
|
10
10
|
export interface CreateAccountOptions {
|
|
11
11
|
/**
|
|
12
|
-
* If true,
|
|
13
|
-
*
|
|
12
|
+
* If true, poll until the account reaches `active` before returning, instead
|
|
13
|
+
* of returning as soon as it is created.
|
|
14
|
+
*
|
|
15
|
+
* What this waits for is the account's ledger account finishing its
|
|
16
|
+
* registration on-chain — not its `ledgerId`, which is already present on the
|
|
17
|
+
* create response. Until then the account can receive funds but not send
|
|
18
|
+
* them, so this only matters when the next thing you do is spend from it.
|
|
19
|
+
*
|
|
20
|
+
* Polls every 2 seconds, and throws if the account ends up `creation_failed`.
|
|
21
|
+
*
|
|
14
22
|
* @default false
|
|
15
23
|
*/
|
|
16
24
|
waitLedger?: boolean;
|
package/dist/virtual/types.d.ts
CHANGED
|
@@ -35,8 +35,17 @@ export interface CreateVirtualAccountParams {
|
|
|
35
35
|
*/
|
|
36
36
|
name?: string;
|
|
37
37
|
/**
|
|
38
|
-
* Ledger account ID to associate with the virtual account
|
|
39
|
-
*
|
|
38
|
+
* Ledger account ID to associate with the virtual account.
|
|
39
|
+
*
|
|
40
|
+
* Pass one to share an existing balance — the account is `active` straight
|
|
41
|
+
* away, since the ledger it points at is already on-chain.
|
|
42
|
+
*
|
|
43
|
+
* Omit it and a new ledger account is minted for you. Its `ledgerId` is
|
|
44
|
+
* derived rather than assigned by the chain, so it comes back in the create
|
|
45
|
+
* response and is immediately usable to link cards and Polygon accounts. The
|
|
46
|
+
* account itself starts `creation_in_progress` and can *receive* right away;
|
|
47
|
+
* it can *send* once the ledger account finishes registering on-chain and the
|
|
48
|
+
* status flips to `active`.
|
|
40
49
|
*/
|
|
41
50
|
ledgerId?: string;
|
|
42
51
|
/**
|
|
@@ -96,9 +105,22 @@ export interface VirtualAccount {
|
|
|
96
105
|
*/
|
|
97
106
|
ownerUrn: string;
|
|
98
107
|
/**
|
|
99
|
-
* Ledger account ID associated with the virtual account
|
|
108
|
+
* Ledger account ID associated with the virtual account.
|
|
109
|
+
*
|
|
110
|
+
* This is the ledger account's on-chain address, and it is the value other
|
|
111
|
+
* account types take as their own `ledgerId` to share this balance. Always
|
|
112
|
+
* populated, including on the create response.
|
|
100
113
|
*/
|
|
101
114
|
ledgerId: string;
|
|
115
|
+
/**
|
|
116
|
+
* URN of the ledger account backing this virtual account.
|
|
117
|
+
*
|
|
118
|
+
* A stable handle for the same ledger account that `ledgerId` addresses:
|
|
119
|
+
* `ledgerId` is the address, this is the name. Present on accounts whose
|
|
120
|
+
* ledger account was minted for them; absent when the account was attached to
|
|
121
|
+
* a pre-existing `ledgerId`.
|
|
122
|
+
*/
|
|
123
|
+
ledgerAccountUrn?: string;
|
|
102
124
|
/**
|
|
103
125
|
* Webhook URL (if configured)
|
|
104
126
|
*/
|
|
@@ -36,8 +36,16 @@ export declare class VirtualClient extends BaseClient {
|
|
|
36
36
|
/**
|
|
37
37
|
* Create a new virtual account
|
|
38
38
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
39
|
+
* A virtual account is the account type that holds a balance. Creating one
|
|
40
|
+
* without a `ledgerId` mints a new ledger account for it; passing a
|
|
41
|
+
* `ledgerId` attaches it to an existing balance instead.
|
|
42
|
+
*
|
|
43
|
+
* `ledgerId` is populated on the returned account either way, so you can link
|
|
44
|
+
* cards and Polygon accounts to it immediately — there is nothing to wait for
|
|
45
|
+
* to learn it. What you may need to wait for is `status: 'active'`: a freshly
|
|
46
|
+
* minted ledger account is registering on-chain behind this response, and
|
|
47
|
+
* until it finishes the account can receive funds but not send them. Pass
|
|
48
|
+
* `waitLedger: true` when the next thing you do is spend from it.
|
|
41
49
|
*
|
|
42
50
|
* @param params - Virtual account creation parameters
|
|
43
51
|
* @param options - Creation options (optional)
|
|
@@ -45,13 +53,14 @@ export declare class VirtualClient extends BaseClient {
|
|
|
45
53
|
*
|
|
46
54
|
* @example
|
|
47
55
|
* ```typescript
|
|
48
|
-
* // Create
|
|
56
|
+
* // Create and link straight away — no waiting needed to get the ledgerId
|
|
49
57
|
* const account = await bloque.accounts.virtual.create({
|
|
50
58
|
* firstName: 'John',
|
|
51
59
|
* lastName: 'Doe'
|
|
52
60
|
* });
|
|
61
|
+
* await bloque.accounts.polygon.create({ ledgerId: account.ledgerId });
|
|
53
62
|
*
|
|
54
|
-
* //
|
|
63
|
+
* // Wait until it can send, with an explicit idempotency key
|
|
55
64
|
* const account = await bloque.accounts.virtual.create({
|
|
56
65
|
* firstName: 'John',
|
|
57
66
|
* lastName: 'Doe'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bloque/sdk-accounts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
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.
|
|
39
|
+
"@bloque/sdk-core": "0.11.0"
|
|
40
40
|
}
|
|
41
41
|
}
|