@bloque/sdk-accounts 0.0.49 → 0.1.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/card/card-client.d.ts +58 -1
- package/dist/card/types.d.ts +47 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/wire-types.d.ts +45 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseClient } from '@bloque/sdk-core';
|
|
2
2
|
import type { AccountWithBalance, CardDetails, TokenBalance } from '../internal/wire-types';
|
|
3
3
|
import type { CreateAccountOptions } from '../types';
|
|
4
|
-
import type { CardAccount, CreateCardParams, GetBalanceParams, ListCardAccountsParams, ListCardAccountsResult, ListMovementsPagedResult, ListMovementsParams, UpdateCardMetadataParams } from './types';
|
|
4
|
+
import type { CardAccount, CreateCardParams, GetBalanceParams, ListCardAccountsParams, ListCardAccountsResult, ListMovementsPagedResult, ListMovementsParams, TokenizeAppleParams, TokenizeAppleResult, TokenizeGoogleParams, TokenizeGoogleResult, UpdateCardMetadataParams, UpdateCardParams } from './types';
|
|
5
5
|
/**
|
|
6
6
|
* Maps a wire card account to the SDK CardAccount type.
|
|
7
7
|
* Exported so AccountsClient.get() can dispatch by medium.
|
|
@@ -115,6 +115,22 @@ export declare class CardClient extends BaseClient {
|
|
|
115
115
|
* ```
|
|
116
116
|
*/
|
|
117
117
|
balance(params: GetBalanceParams): Promise<Record<string, TokenBalance>>;
|
|
118
|
+
/**
|
|
119
|
+
* Update a card account (metadata, webhook URL, ledger ID, or status)
|
|
120
|
+
*
|
|
121
|
+
* @param params - Update parameters
|
|
122
|
+
* @returns Promise resolving to the updated card account
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const card = await bloque.accounts.card.update({
|
|
127
|
+
* urn: 'did:bloque:account:card:usr-123:crd-456',
|
|
128
|
+
* webhookUrl: 'https://api.example.com/webhooks/cards',
|
|
129
|
+
* metadata: { name: 'Updated Card' },
|
|
130
|
+
* });
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
update(params: UpdateCardParams): Promise<CardAccount>;
|
|
118
134
|
/**
|
|
119
135
|
* Update card account metadata
|
|
120
136
|
*
|
|
@@ -191,6 +207,47 @@ export declare class CardClient extends BaseClient {
|
|
|
191
207
|
* ```
|
|
192
208
|
*/
|
|
193
209
|
disable(urn: string): Promise<CardAccount>;
|
|
210
|
+
/**
|
|
211
|
+
* Tokenize a card for Apple Pay
|
|
212
|
+
*
|
|
213
|
+
* @param urn - Card account URN
|
|
214
|
+
* @param params - Apple Pay tokenization parameters
|
|
215
|
+
* @returns Promise resolving to tokenization data
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* const result = await bloque.accounts.card.tokenizeApple(
|
|
220
|
+
* 'did:bloque:mediums:card:account:123',
|
|
221
|
+
* {
|
|
222
|
+
* certificates: ['cert1', 'cert2'],
|
|
223
|
+
* nonce: 'random_nonce',
|
|
224
|
+
* nonceSignature: 'signed_nonce',
|
|
225
|
+
* },
|
|
226
|
+
* );
|
|
227
|
+
* console.log(result.activationData);
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
tokenizeApple(urn: string, params: TokenizeAppleParams): Promise<TokenizeAppleResult>;
|
|
231
|
+
/**
|
|
232
|
+
* Tokenize a card for Google Pay
|
|
233
|
+
*
|
|
234
|
+
* @param urn - Card account URN
|
|
235
|
+
* @param params - Google Pay tokenization parameters
|
|
236
|
+
* @returns Promise resolving to tokenization data
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```typescript
|
|
240
|
+
* const result = await bloque.accounts.card.tokenizeGoogle(
|
|
241
|
+
* 'did:bloque:mediums:card:account:123',
|
|
242
|
+
* {
|
|
243
|
+
* deviceId: 'device_123',
|
|
244
|
+
* walletAccountId: 'wallet_456',
|
|
245
|
+
* },
|
|
246
|
+
* );
|
|
247
|
+
* console.log(result.opc);
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
tokenizeGoogle(urn: string, params: TokenizeGoogleParams): Promise<TokenizeGoogleResult>;
|
|
194
251
|
/**
|
|
195
252
|
* Private method to update card status
|
|
196
253
|
*/
|
package/dist/card/types.d.ts
CHANGED
|
@@ -126,6 +126,18 @@ export interface CreateCardParams {
|
|
|
126
126
|
*/
|
|
127
127
|
metadata?: Record<string, unknown>;
|
|
128
128
|
}
|
|
129
|
+
export interface UpdateCardParams {
|
|
130
|
+
/** URN of the card account to update */
|
|
131
|
+
urn: string;
|
|
132
|
+
/** Metadata to update */
|
|
133
|
+
metadata?: Record<string, unknown>;
|
|
134
|
+
/** Account status */
|
|
135
|
+
status?: string;
|
|
136
|
+
/** Webhook URL for card events */
|
|
137
|
+
webhookUrl?: string;
|
|
138
|
+
/** Ledger account ID to link */
|
|
139
|
+
ledgerId?: string;
|
|
140
|
+
}
|
|
129
141
|
export interface UpdateCardMetadataParams {
|
|
130
142
|
/**
|
|
131
143
|
* URN of the card account to update
|
|
@@ -141,6 +153,41 @@ export interface UpdateCardMetadataParams {
|
|
|
141
153
|
source?: never;
|
|
142
154
|
};
|
|
143
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Parameters for Apple Pay tokenization
|
|
158
|
+
*/
|
|
159
|
+
export interface TokenizeAppleParams {
|
|
160
|
+
/** Apple Pay certificates */
|
|
161
|
+
certificates: string[];
|
|
162
|
+
/** Cryptographic nonce */
|
|
163
|
+
nonce: string;
|
|
164
|
+
/** Signature of the nonce */
|
|
165
|
+
nonceSignature: string;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Result of Apple Pay tokenization
|
|
169
|
+
*/
|
|
170
|
+
export interface TokenizeAppleResult {
|
|
171
|
+
activationData: string;
|
|
172
|
+
encryptedPassData: string;
|
|
173
|
+
ephemeralPublicKey: string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Parameters for Google Pay tokenization
|
|
177
|
+
*/
|
|
178
|
+
export interface TokenizeGoogleParams {
|
|
179
|
+
/** Device ID for Google Pay */
|
|
180
|
+
deviceId: string;
|
|
181
|
+
/** Google wallet account ID */
|
|
182
|
+
walletAccountId: string;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Result of Google Pay tokenization
|
|
186
|
+
*/
|
|
187
|
+
export interface TokenizeGoogleResult {
|
|
188
|
+
/** One-time passcode */
|
|
189
|
+
opc: string;
|
|
190
|
+
}
|
|
144
191
|
export interface CardAccount {
|
|
145
192
|
/**
|
|
146
193
|
* Unique resource name for the card account
|
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__,{VirtualClient:()=>VirtualClient,BrebClient:()=>BrebClient,PolygonClient:()=>PolygonClient,AccountsClient:()=>AccountsClient,UsClient:()=>UsClient,mapBrebAccountFromWire:()=>mapBrebAccountFromWire,mapUsAccountFromWire:()=>mapUsAccountFromWire,CardClient:()=>CardClient,mapCardAccountFromWire:()=>mapCardAccountFromWire,mapPolygonAccountFromWire:()=>mapPolygonAccountFromWire,mapBancolombiaAccountFromWire:()=>mapBancolombiaAccountFromWire,mapVirtualAccountFromWire:()=>mapVirtualAccountFromWire,BancolombiaClient:()=>BancolombiaClient});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}),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}}class BrebClient extends sdk_core_namespaceObject.BaseClient{mapError(e){if(e instanceof sdk_core_namespaceObject.BloqueAPIError){let t=e.response;return{code:t?.extra_details?.provider_code??e.code??null,message:e.message}}return e instanceof Error?{code:null,message:e.message}:{code:null,message:"Unknown BRE-B error"}}async createKey(e){try{let t=this.httpClient.urn;if(!t?.trim())throw Error("Holder URN is required");if(!e.key?.trim())throw Error("BRE-B key value is required");let a=await this.httpClient.request({method:"POST",path:"/api/mediums/breb",body:{holder_urn:t,input:{key_type:e.keyType,key_value:e.key,display_name:e.displayName},webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,metadata:{source:"sdk-typescript",...e.metadata}}});return{data:mapBrebAccountFromWire(a.result.account),error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async resolveKey(e){try{if(!e.key?.trim())throw Error("BRE-B key value is required");return{data:(await this.httpClient.request({method:"POST",path:"/api/mediums/breb/resolve-key",body:{key_type:e.keyType,key:e.key}})).result,error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async deleteKey(e){try{if(!e.accountUrn?.trim())throw Error("BRE-B account URN is required");return{data:(await this.httpClient.request({method:"DELETE",path:`/api/accounts/${encodeURIComponent(e.accountUrn)}/breb/key`})).result,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");return{data:(await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(e.accountUrn)}/breb/key/suspend`})).result,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");return{data:(await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(e.accountUrn)}/breb/key/activate`})).result,error:null}}catch(e){return{data:null,error:this.mapError(e)}}}}function mapCardAccountFromWire(e){return{urn:e.urn,id:e.id,lastFour:e.details.card_last_four,productType:e.details.card_product_type,status:e.status,cardType:e.details.card_type,detailsUrl:e.details.card_url_details,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}}class CardClient extends sdk_core_namespaceObject.BaseClient{async create(e={},t){let a={holder_urn:e?.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{create:{card_type:"VIRTUAL"}},metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/card",body:a}),n=this._mapAccountResponse(r.result.account);return t?.waitLedger?this._waitForActiveStatus(n.urn,t.timeout||6e4):n}async _waitForActiveStatus(e,t){let a=Date.now();for(;;){if(Date.now()-a>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let r=(await this.list({urn:e})).accounts[0];if(!r)throw Error(`Account not found. URN: ${e}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${e}`);await new Promise(e=>setTimeout(e,2e3))}}async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","card"),t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(e=>({urn:e.urn,id:e.id,lastFour:e.details.card_last_four,productType:e.details.card_product_type,status:e.status,cardType:e.details.card_type,detailsUrl:e.details.card_url_details,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}))}}async movements(e){let t=new URLSearchParams,a=e.asset||"DUSD/6";if(!(0,sdk_core_namespaceObject.isSupportedAsset)(a))throw Error(`Invalid asset type "${a}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);t.set("asset",a),void 0!==e.limit&&t.set("limit",e.limit.toString()),e.before&&t.set("before",e.before),e.after&&t.set("after",e.after),e.reference&&t.set("reference",e.reference),e.direction&&t.set("direction",e.direction),void 0!==e.collapsed_view&&t.set("collapsed_view",String(e.collapsed_view)),e.pocket&&t.set("pocket",e.pocket),e.next&&t.set("next",e.next);let r=t.toString(),n=`/api/accounts/${e.urn}/movements${r?`?${r}`:""}`,o=await this.httpClient.request({method:"GET",path:n});return{data:o.data,pageSize:o.page_size,hasMore:o.has_more,next:o.next}}async balance(e){return(await this.httpClient.request({method:"GET",path:`/api/accounts/${e.urn}/balance`})).balance}async 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 mapCardAccountFromWire(e)}}function mapPolygonAccountFromWire(e){return{urn:e.urn,id:e.id,address:e.details.address,network:e.details.network,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:"balance"in e&&e.balance?e.balance:void 0}}class PolygonClient extends sdk_core_namespaceObject.BaseClient{async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","polygon"),t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(e=>({...this._mapAccountResponse(e),balance:e.balance}))}}async create(e={},t){let a={holder_urn:e.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{},metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/polygon",body:a}),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});return{url:(await this.httpClient.request({method:"POST",path:`/api/mediums/us-account/tos-link?${t.toString()}`})).result.url}}async create(e,t){let a={street_line_1:e.address.streetLine1,street_line_2:e.address.streetLine2,city:e.address.city,state:e.address.state,postal_code:e.address.postalCode,country:e.address.country},r={type:e.type,first_name:e.firstName,middle_name:e.middleName,last_name:e.lastName,email:e.email,phone:e.phone,address:a,birth_date:e.birthDate,tax_identification_number:e.taxIdentificationNumber,gov_id_country:e.govIdCountry,gov_id_image_front:e.govIdImageFront,signed_agreement_id:e.signedAgreementId},n={holder_urn:e.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:r,metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},o=await this.httpClient.request({method:"POST",path:"/api/mediums/us-account",body:n}),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 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}),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;polygon;us;virtual;constructor(e){super(e),this.bancolombia=new BancolombiaClient(this.httpClient),this.breb=new BrebClient(this.httpClient),this.card=new CardClient(this.httpClient),this.polygon=new PolygonClient(this.httpClient),this.us=new UsClient(this.httpClient),this.virtual=new VirtualClient(this.httpClient)}async balance(e){if(!e?.trim())throw Error("Account URN is required");return(await this.httpClient.request({method:"GET",path:`/api/accounts/${e}/balance`})).balance}async balances(){return(await this.httpClient.request({method:"GET",path:"/api/accounts/balances"})).balance}async get(e){if(!e?.trim())throw Error("Account URN is required");let t=await this.httpClient.request({method:"GET",path:`/api/accounts/${e}`});return this._mapByMedium(t.account)}async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;t&&a.append("holder_urn",t);let r=a.toString(),n=r?`/api/accounts?${r}`:"/api/accounts";return{accounts:(await this.httpClient.request({method:"GET",path:n})).accounts.map(e=>this._mapByMedium(e))}}async transfer(e){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={destination_account_urn:e.destinationUrn,amount:e.amount,asset:t,metadata:e.metadata},r=await this.httpClient.request({method:"POST",path:`/api/accounts/${e.sourceUrn}/transfer`,body:a});return{queueId:r.result.queue_id,status:r.result.status,message:r.result.message}}async batchTransfer(e){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 t={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},a=await this.httpClient.request({method:"POST",path:"/api/accounts/batch/transfer",body:t});return{chunks:a.result.chunks.map(e=>({queueId:e.queue_id,status:e.status,message:e.message})),totalOperations:a.result.total_operations,totalChunks:a.result.total_chunks}}async movements(e){if(!e.urn)throw Error("Account URN is required");let t=e.asset||"DUSD/6";if(!(0,sdk_core_namespaceObject.isSupportedAsset)(t))throw Error(`Invalid asset type "${t}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let a=new URLSearchParams;a.set("asset",t),void 0!==e.limit&&a.set("limit",e.limit.toString()),e.before&&a.set("before",e.before),e.after&&a.set("after",e.after),e.reference&&a.set("reference",e.reference),e.direction&&a.set("direction",e.direction),void 0!==e.collapsed_view&&a.set("collapsed_view",String(e.collapsed_view)),e.pocket&&a.set("pocket",e.pocket),e.next&&a.set("next",e.next);let r=`/api/accounts/${e.urn}/movements?${a.toString()}`,n=await this.httpClient.request({method:"GET",path:r});return{data:n.data.map(e=>({amount:e.amount,asset:e.asset,fromAccountId:e.from_account_id,toAccountId:e.to_account_id,direction:e.direction,type:e.type,reference:e.reference,status:e.status,railName:e.rail_name,details:e.details,createdAt:e.created_at})),pageSize:n.page_size,hasMore:n.has_more,next:n.next}}async transactions(e={}){let t=e.asset||"DUSD/6";if(!(0,sdk_core_namespaceObject.isSupportedAsset)(t))throw Error(`Invalid asset type "${t}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let a=new URLSearchParams;a.set("asset",t),void 0!==e.limit&&a.set("limit",e.limit.toString()),e.before&&a.set("before",e.before),e.after&&a.set("after",e.after),e.reference&&a.set("reference",e.reference),e.direction&&a.set("direction",e.direction),void 0!==e.collapsed_view&&a.set("collapsed_view",String(e.collapsed_view)),e.pocket&&a.set("pocket",e.pocket),e.next&&a.set("next",e.next);let r=await this.httpClient.request({method:"GET",path:`/api/accounts/transactions?${a.toString()}`});return{data:r.data.map(e=>({amount:e.amount,asset:e.asset,fromAccountId:e.from_account_id,toAccountId:e.to_account_id,direction:e.direction,reference:e.reference,status:e.status,railName:e.rail_name,details:e.details??{},createdAt:e.created_at,type:e.type})),pageSize:r.page_size,hasMore:r.has_more,next:r.next}}_mapByMedium(e){switch(e.medium){case"card":return mapCardAccountFromWire(e);case"virtual":return mapVirtualAccountFromWire(e);case"polygon":return mapPolygonAccountFromWire(e);case"bancolombia":return mapBancolombiaAccountFromWire(e);case"breb":return mapBrebAccountFromWire(e);case"us-account":return mapUsAccountFromWire(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.PolygonClient=__webpack_exports__.PolygonClient,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.mapPolygonAccountFromWire=__webpack_exports__.mapPolygonAccountFromWire,exports.mapUsAccountFromWire=__webpack_exports__.mapUsAccountFromWire,exports.mapVirtualAccountFromWire=__webpack_exports__.mapVirtualAccountFromWire,__webpack_exports__)-1===["AccountsClient","BancolombiaClient","BrebClient","CardClient","PolygonClient","UsClient","VirtualClient","mapBancolombiaAccountFromWire","mapBrebAccountFromWire","mapCardAccountFromWire","mapPolygonAccountFromWire","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__,{VirtualClient:()=>VirtualClient,BrebClient:()=>BrebClient,PolygonClient:()=>PolygonClient,AccountsClient:()=>AccountsClient,UsClient:()=>UsClient,mapBrebAccountFromWire:()=>mapBrebAccountFromWire,mapUsAccountFromWire:()=>mapUsAccountFromWire,CardClient:()=>CardClient,mapCardAccountFromWire:()=>mapCardAccountFromWire,mapPolygonAccountFromWire:()=>mapPolygonAccountFromWire,mapBancolombiaAccountFromWire:()=>mapBancolombiaAccountFromWire,mapVirtualAccountFromWire:()=>mapVirtualAccountFromWire,BancolombiaClient:()=>BancolombiaClient});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}),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}}class BrebClient extends sdk_core_namespaceObject.BaseClient{mapError(e){if(e instanceof sdk_core_namespaceObject.BloqueAPIError){let t=e.response;return{code:t?.extra_details?.provider_code??e.code??null,message:e.message}}return e instanceof Error?{code:null,message:e.message}:{code:null,message:"Unknown BRE-B error"}}async createKey(e){try{let t=this.httpClient.urn;if(!t?.trim())throw Error("Holder URN is required");if(!e.key?.trim())throw Error("BRE-B key value is required");let a=await this.httpClient.request({method:"POST",path:"/api/mediums/breb",body:{holder_urn:t,input:{key_type:e.keyType,key_value:e.key,display_name:e.displayName},webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,metadata:{source:"sdk-typescript",...e.metadata}}});return{data:mapBrebAccountFromWire(a.result.account),error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async resolveKey(e){try{if(!e.key?.trim())throw Error("BRE-B key value is required");return{data:(await this.httpClient.request({method:"POST",path:"/api/mediums/breb/resolve-key",body:{key_type:e.keyType,key:e.key}})).result,error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async deleteKey(e){try{if(!e.accountUrn?.trim())throw Error("BRE-B account URN is required");return{data:(await this.httpClient.request({method:"DELETE",path:`/api/accounts/${encodeURIComponent(e.accountUrn)}/breb/key`})).result,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");return{data:(await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(e.accountUrn)}/breb/key/suspend`})).result,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");return{data:(await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(e.accountUrn)}/breb/key/activate`})).result,error:null}}catch(e){return{data:null,error:this.mapError(e)}}}}function mapCardAccountFromWire(e){return{urn:e.urn,id:e.id,lastFour:e.details.card_last_four,productType:e.details.card_product_type,status:e.status,cardType:e.details.card_type,detailsUrl:e.details.card_url_details,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}}class CardClient extends sdk_core_namespaceObject.BaseClient{async create(e={},t){let a={holder_urn:e?.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{create:{card_type:"VIRTUAL"}},metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/card",body:a}),n=this._mapAccountResponse(r.result.account);return t?.waitLedger?this._waitForActiveStatus(n.urn,t.timeout||6e4):n}async _waitForActiveStatus(e,t){let a=Date.now();for(;;){if(Date.now()-a>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let r=(await this.list({urn:e})).accounts[0];if(!r)throw Error(`Account not found. URN: ${e}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${e}`);await new Promise(e=>setTimeout(e,2e3))}}async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","card"),t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(e=>({urn:e.urn,id:e.id,lastFour:e.details.card_last_four,productType:e.details.card_product_type,status:e.status,cardType:e.details.card_type,detailsUrl:e.details.card_url_details,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}))}}async movements(e){let t=new URLSearchParams,a=e.asset||"DUSD/6";if(!(0,sdk_core_namespaceObject.isSupportedAsset)(a))throw Error(`Invalid asset type "${a}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);t.set("asset",a),void 0!==e.limit&&t.set("limit",e.limit.toString()),e.before&&t.set("before",e.before),e.after&&t.set("after",e.after),e.reference&&t.set("reference",e.reference),e.direction&&t.set("direction",e.direction),void 0!==e.collapsed_view&&t.set("collapsed_view",String(e.collapsed_view)),e.pocket&&t.set("pocket",e.pocket),e.next&&t.set("next",e.next);let r=t.toString(),n=`/api/accounts/${e.urn}/movements${r?`?${r}`:""}`,o=await this.httpClient.request({method:"GET",path:n});return{data:o.data,pageSize:o.page_size,hasMore:o.has_more,next:o.next}}async balance(e){return(await this.httpClient.request({method:"GET",path:`/api/accounts/${e.urn}/balance`})).balance}async update(e){let t={...e.metadata&&{metadata:e.metadata},...e.status&&{status:e.status},...e.webhookUrl&&{webhook_url:e.webhookUrl},...e.ledgerId&&{ledger_account_id:e.ledgerId}},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(a.result.account)}async updateMetadata(e){let t={metadata:e.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(a.result.account)}async updateName(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{metadata:{name:t}}});return this._mapAccountResponse(a.result.account)}async activate(e){return this._updateStatus(e,"active")}async freeze(e){return this._updateStatus(e,"frozen")}async disable(e){return this._updateStatus(e,"disabled")}async tokenizeApple(e,t){let a={certificates:t.certificates,nonce:t.nonce,nonce_signature:t.nonceSignature},r=await this.httpClient.request({method:"POST",path:`/api/accounts/${e}/tokenize/apple`,body:a});return{activationData:r.result.tokenization.activation_data,encryptedPassData:r.result.tokenization.encrypted_pass_data,ephemeralPublicKey:r.result.tokenization.ephemeral_public_key}}async tokenizeGoogle(e,t){let a={device_id:t.deviceId,wallet_account_id:t.walletAccountId};return{opc:(await this.httpClient.request({method:"POST",path:`/api/accounts/${e}/tokenize/google`,body:a})).result.tokenization.opc}}async _updateStatus(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{status:t}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(e){return mapCardAccountFromWire(e)}}function mapPolygonAccountFromWire(e){return{urn:e.urn,id:e.id,address:e.details.address,network:e.details.network,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:"balance"in e&&e.balance?e.balance:void 0}}class PolygonClient extends sdk_core_namespaceObject.BaseClient{async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","polygon"),t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(e=>({...this._mapAccountResponse(e),balance:e.balance}))}}async create(e={},t){let a={holder_urn:e.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{},metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/polygon",body:a}),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});return{url:(await this.httpClient.request({method:"POST",path:`/api/mediums/us-account/tos-link?${t.toString()}`})).result.url}}async create(e,t){let a={street_line_1:e.address.streetLine1,street_line_2:e.address.streetLine2,city:e.address.city,state:e.address.state,postal_code:e.address.postalCode,country:e.address.country},r={type:e.type,first_name:e.firstName,middle_name:e.middleName,last_name:e.lastName,email:e.email,phone:e.phone,address:a,birth_date:e.birthDate,tax_identification_number:e.taxIdentificationNumber,gov_id_country:e.govIdCountry,gov_id_image_front:e.govIdImageFront,signed_agreement_id:e.signedAgreementId},n={holder_urn:e.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:r,metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},o=await this.httpClient.request({method:"POST",path:"/api/mediums/us-account",body:n}),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 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}),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;polygon;us;virtual;constructor(e){super(e),this.bancolombia=new BancolombiaClient(this.httpClient),this.breb=new BrebClient(this.httpClient),this.card=new CardClient(this.httpClient),this.polygon=new PolygonClient(this.httpClient),this.us=new UsClient(this.httpClient),this.virtual=new VirtualClient(this.httpClient)}async balance(e){if(!e?.trim())throw Error("Account URN is required");return(await this.httpClient.request({method:"GET",path:`/api/accounts/${e}/balance`})).balance}async balances(){return(await this.httpClient.request({method:"GET",path:"/api/accounts/balances"})).balance}async get(e){if(!e?.trim())throw Error("Account URN is required");let t=await this.httpClient.request({method:"GET",path:`/api/accounts/${e}`});return this._mapByMedium(t.account)}async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;t&&a.append("holder_urn",t);let r=a.toString(),n=r?`/api/accounts?${r}`:"/api/accounts";return{accounts:(await this.httpClient.request({method:"GET",path:n})).accounts.map(e=>this._mapByMedium(e))}}async transfer(e){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={destination_account_urn:e.destinationUrn,amount:e.amount,asset:t,metadata:e.metadata},r=await this.httpClient.request({method:"POST",path:`/api/accounts/${e.sourceUrn}/transfer`,body:a});return{queueId:r.result.queue_id,status:r.result.status,message:r.result.message}}async batchTransfer(e){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 t={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},a=await this.httpClient.request({method:"POST",path:"/api/accounts/batch/transfer",body:t});return{chunks:a.result.chunks.map(e=>({queueId:e.queue_id,status:e.status,message:e.message})),totalOperations:a.result.total_operations,totalChunks:a.result.total_chunks}}async movements(e){if(!e.urn)throw Error("Account URN is required");let t=e.asset||"DUSD/6";if(!(0,sdk_core_namespaceObject.isSupportedAsset)(t))throw Error(`Invalid asset type "${t}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let a=new URLSearchParams;a.set("asset",t),void 0!==e.limit&&a.set("limit",e.limit.toString()),e.before&&a.set("before",e.before),e.after&&a.set("after",e.after),e.reference&&a.set("reference",e.reference),e.direction&&a.set("direction",e.direction),void 0!==e.collapsed_view&&a.set("collapsed_view",String(e.collapsed_view)),e.pocket&&a.set("pocket",e.pocket),e.next&&a.set("next",e.next);let r=`/api/accounts/${e.urn}/movements?${a.toString()}`,n=await this.httpClient.request({method:"GET",path:r});return{data:n.data.map(e=>({amount:e.amount,asset:e.asset,fromAccountId:e.from_account_id,toAccountId:e.to_account_id,direction:e.direction,type:e.type,reference:e.reference,status:e.status,railName:e.rail_name,details:e.details,createdAt:e.created_at})),pageSize:n.page_size,hasMore:n.has_more,next:n.next}}async transactions(e={}){let t=e.asset||"DUSD/6";if(!(0,sdk_core_namespaceObject.isSupportedAsset)(t))throw Error(`Invalid asset type "${t}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let a=new URLSearchParams;a.set("asset",t),void 0!==e.limit&&a.set("limit",e.limit.toString()),e.before&&a.set("before",e.before),e.after&&a.set("after",e.after),e.reference&&a.set("reference",e.reference),e.direction&&a.set("direction",e.direction),void 0!==e.collapsed_view&&a.set("collapsed_view",String(e.collapsed_view)),e.pocket&&a.set("pocket",e.pocket),e.next&&a.set("next",e.next);let r=await this.httpClient.request({method:"GET",path:`/api/accounts/transactions?${a.toString()}`});return{data:r.data.map(e=>({amount:e.amount,asset:e.asset,fromAccountId:e.from_account_id,toAccountId:e.to_account_id,direction:e.direction,reference:e.reference,status:e.status,railName:e.rail_name,details:e.details??{},createdAt:e.created_at,type:e.type})),pageSize:r.page_size,hasMore:r.has_more,next:r.next}}_mapByMedium(e){switch(e.medium){case"card":return mapCardAccountFromWire(e);case"virtual":return mapVirtualAccountFromWire(e);case"polygon":return mapPolygonAccountFromWire(e);case"bancolombia":return mapBancolombiaAccountFromWire(e);case"breb":return mapBrebAccountFromWire(e);case"us-account":return mapUsAccountFromWire(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.PolygonClient=__webpack_exports__.PolygonClient,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.mapPolygonAccountFromWire=__webpack_exports__.mapPolygonAccountFromWire,exports.mapUsAccountFromWire=__webpack_exports__.mapUsAccountFromWire,exports.mapVirtualAccountFromWire=__webpack_exports__.mapVirtualAccountFromWire,__webpack_exports__)-1===["AccountsClient","BancolombiaClient","BrebClient","CardClient","PolygonClient","UsClient","VirtualClient","mapBancolombiaAccountFromWire","mapBrebAccountFromWire","mapCardAccountFromWire","mapPolygonAccountFromWire","mapUsAccountFromWire","mapVirtualAccountFromWire"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{BaseClient as t,BloqueAPIError as e,SUPPORTED_ASSETS as a,isSupportedAsset as r}from"@bloque/sdk-core";function n(t){return{urn:t.urn,id:t.id,referenceCode:t.details.reference_code,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:"balance"in t&&t.balance?t.balance:void 0}}class s extends t{async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","bancolombia"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({...this._mapAccountResponse(t),balance:t.balance}))}}async create(t={},e){let a={holder_urn:t?.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{},metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/bancolombia",body:a}),n=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(n.urn,e.timeout||6e4):n}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async updateName(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{metadata:{name:e}}});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return n(t)}}function i(t){return{id:t.id,urn:t.urn,ownerUrn:t.owner_urn,medium:"breb",remoteKeyId:t.details.remote_key_id,accountId:t.details.account_id,keyType:t.details.key.key_type,key:t.details.key.key_value,displayName:t.details.display_name??null,status:t.status,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,details:t.details,balance:"balance"in t&&t.balance?t.balance:void 0}}class o extends t{mapError(t){if(t instanceof e){let e=t.response;return{code:e?.extra_details?.provider_code??t.code??null,message:t.message}}return t instanceof Error?{code:null,message:t.message}:{code:null,message:"Unknown BRE-B error"}}async createKey(t){try{let e=this.httpClient.urn;if(!e?.trim())throw Error("Holder URN is required");if(!t.key?.trim())throw Error("BRE-B key value is required");let a=await this.httpClient.request({method:"POST",path:"/api/mediums/breb",body:{holder_urn:e,input:{key_type:t.keyType,key_value:t.key,display_name:t.displayName},webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,metadata:{source:"sdk-typescript",...t.metadata}}});return{data:i(a.result.account),error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async resolveKey(t){try{if(!t.key?.trim())throw Error("BRE-B key value is required");return{data:(await this.httpClient.request({method:"POST",path:"/api/mediums/breb/resolve-key",body:{key_type:t.keyType,key:t.key}})).result,error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async deleteKey(t){try{if(!t.accountUrn?.trim())throw Error("BRE-B account URN is required");return{data:(await this.httpClient.request({method:"DELETE",path:`/api/accounts/${encodeURIComponent(t.accountUrn)}/breb/key`})).result,error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async suspendKey(t){try{if(!t.accountUrn?.trim())throw Error("BRE-B account URN is required");return{data:(await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(t.accountUrn)}/breb/key/suspend`})).result,error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async activateKey(t){try{if(!t.accountUrn?.trim())throw Error("BRE-B account URN is required");return{data:(await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(t.accountUrn)}/breb/key/activate`})).result,error:null}}catch(t){return{data:null,error:this.mapError(t)}}}}function u(t){return{urn:t.urn,id:t.id,lastFour:t.details.card_last_four,productType:t.details.card_product_type,status:t.status,cardType:t.details.card_type,detailsUrl:t.details.card_url_details,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}}class c extends t{async create(t={},e){let a={holder_urn:t?.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{create:{card_type:"VIRTUAL"}},metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/card",body:a}),n=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(n.urn,e.timeout||6e4):n}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","card"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({urn:t.urn,id:t.id,lastFour:t.details.card_last_four,productType:t.details.card_product_type,status:t.status,cardType:t.details.card_type,detailsUrl:t.details.card_url_details,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}))}}async movements(t){let e=new URLSearchParams,n=t.asset||"DUSD/6";if(!r(n))throw Error(`Invalid asset type "${n}". Supported assets: ${a.join(", ")}`);e.set("asset",n),void 0!==t.limit&&e.set("limit",t.limit.toString()),t.before&&e.set("before",t.before),t.after&&e.set("after",t.after),t.reference&&e.set("reference",t.reference),t.direction&&e.set("direction",t.direction),void 0!==t.collapsed_view&&e.set("collapsed_view",String(t.collapsed_view)),t.pocket&&e.set("pocket",t.pocket),t.next&&e.set("next",t.next);let s=e.toString(),i=`/api/accounts/${t.urn}/movements${s?`?${s}`:""}`,o=await this.httpClient.request({method:"GET",path:i});return{data:o.data,pageSize:o.page_size,hasMore:o.has_more,next:o.next}}async balance(t){return(await this.httpClient.request({method:"GET",path:`/api/accounts/${t.urn}/balance`})).balance}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async updateName(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{metadata:{name:e}}});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return u(t)}}function d(t){return{urn:t.urn,id:t.id,address:t.details.address,network:t.details.network,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:"balance"in t&&t.balance?t.balance:void 0}}class l extends t{async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","polygon"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({...this._mapAccountResponse(t),balance:t.balance}))}}async create(t={},e){let a={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{},metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/polygon",body:a}),n=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(n.urn,e.timeout||6e4):n}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return d(t)}}function p(t){return{urn:t.urn,id:t.id,type:t.details.type,firstName:t.details.first_name,middleName:t.details.middle_name,lastName:t.details.last_name,email:t.details.email,phone:t.details.phone,address:{streetLine1:t.details.address.street_line_1,streetLine2:t.details.address.street_line_2,city:t.details.address.city,state:t.details.address.state,postalCode:t.details.address.postal_code,country:t.details.address.country},birthDate:t.details.birth_date,accountNumber:t.details.account_number,routingNumber:t.details.routing_number,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}}class h extends t{async getTosLink(t){let e=new URLSearchParams({redirect_uri:t.redirectUri});return{url:(await this.httpClient.request({method:"POST",path:`/api/mediums/us-account/tos-link?${e.toString()}`})).result.url}}async create(t,e){let a={street_line_1:t.address.streetLine1,street_line_2:t.address.streetLine2,city:t.address.city,state:t.address.state,postal_code:t.address.postalCode,country:t.address.country},r={type:t.type,first_name:t.firstName,middle_name:t.middleName,last_name:t.lastName,email:t.email,phone:t.phone,address:a,birth_date:t.birthDate,tax_identification_number:t.taxIdentificationNumber,gov_id_country:t.govIdCountry,gov_id_image_front:t.govIdImageFront,signed_agreement_id:t.signedAgreementId},n={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:r,metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},s=await this.httpClient.request({method:"POST",path:"/api/mediums/us-account",body:n}),i=this._mapAccountResponse(s.result.account);return e?.waitLedger?this._waitForActiveStatus(i.urn,e.timeout||6e4):i}async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","us-account"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({urn:t.urn,id:t.id,type:t.details.type,firstName:t.details.first_name,middleName:t.details.middle_name,lastName:t.details.last_name,email:t.details.email,phone:t.details.phone,address:{streetLine1:t.details.address.street_line_1,streetLine2:t.details.address.street_line_2,city:t.details.address.city,state:t.details.address.state,postalCode:t.details.address.postal_code,country:t.details.address.country},birthDate:t.details.birth_date,accountNumber:t.details.account_number,routingNumber:t.details.routing_number,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return p(t)}}function m(t){return{urn:t.urn,id:t.id,firstName:t.details.first_name,lastName:t.details.last_name,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:"balance"in t&&t.balance?t.balance:void 0}}class _ extends t{async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","virtual"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({...this._mapAccountResponse(t),balance:t.balance}))}}async create(t,e){let a={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{},metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/virtual",body:a}),n=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(n.urn,e.timeout||6e4):n}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return m(t)}}class w extends t{bancolombia;breb;card;polygon;us;virtual;constructor(t){super(t),this.bancolombia=new s(this.httpClient),this.breb=new o(this.httpClient),this.card=new c(this.httpClient),this.polygon=new l(this.httpClient),this.us=new h(this.httpClient),this.virtual=new _(this.httpClient)}async balance(t){if(!t?.trim())throw Error("Account URN is required");return(await this.httpClient.request({method:"GET",path:`/api/accounts/${t}/balance`})).balance}async balances(){return(await this.httpClient.request({method:"GET",path:"/api/accounts/balances"})).balance}async get(t){if(!t?.trim())throw Error("Account URN is required");let e=await this.httpClient.request({method:"GET",path:`/api/accounts/${t}`});return this._mapByMedium(e.account)}async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;e&&a.append("holder_urn",e);let r=a.toString(),n=r?`/api/accounts?${r}`:"/api/accounts";return{accounts:(await this.httpClient.request({method:"GET",path:n})).accounts.map(t=>this._mapByMedium(t))}}async transfer(t){let e=t.asset||"DUSD/6";if(!r(e))throw Error(`Invalid asset type "${e}". Supported assets: ${a.join(", ")}`);let n={destination_account_urn:t.destinationUrn,amount:t.amount,asset:e,metadata:t.metadata},s=await this.httpClient.request({method:"POST",path:`/api/accounts/${t.sourceUrn}/transfer`,body:n});return{queueId:s.result.queue_id,status:s.result.status,message:s.result.message}}async batchTransfer(t){if(!t.operations||0===t.operations.length)throw Error("At least one operation is required");if(!t.reference)throw Error("Batch reference is required");for(let e of t.operations)if(!r(e.asset))throw Error(`Invalid asset type "${e.asset}" in operation "${e.reference}". Supported assets: ${a.join(", ")}`);let e={operations:t.operations.map(t=>({from_account_urn:t.fromUrn,to_account_urn:t.toUrn,reference:t.reference,amount:t.amount,asset:t.asset,metadata:t.metadata})),reference:t.reference,metadata:t.metadata,webhook_url:t.webhookUrl},n=await this.httpClient.request({method:"POST",path:"/api/accounts/batch/transfer",body:e});return{chunks:n.result.chunks.map(t=>({queueId:t.queue_id,status:t.status,message:t.message})),totalOperations:n.result.total_operations,totalChunks:n.result.total_chunks}}async movements(t){if(!t.urn)throw Error("Account URN is required");let e=t.asset||"DUSD/6";if(!r(e))throw Error(`Invalid asset type "${e}". Supported assets: ${a.join(", ")}`);let n=new URLSearchParams;n.set("asset",e),void 0!==t.limit&&n.set("limit",t.limit.toString()),t.before&&n.set("before",t.before),t.after&&n.set("after",t.after),t.reference&&n.set("reference",t.reference),t.direction&&n.set("direction",t.direction),void 0!==t.collapsed_view&&n.set("collapsed_view",String(t.collapsed_view)),t.pocket&&n.set("pocket",t.pocket),t.next&&n.set("next",t.next);let s=`/api/accounts/${t.urn}/movements?${n.toString()}`,i=await this.httpClient.request({method:"GET",path:s});return{data:i.data.map(t=>({amount:t.amount,asset:t.asset,fromAccountId:t.from_account_id,toAccountId:t.to_account_id,direction:t.direction,type:t.type,reference:t.reference,status:t.status,railName:t.rail_name,details:t.details,createdAt:t.created_at})),pageSize:i.page_size,hasMore:i.has_more,next:i.next}}async transactions(t={}){let e=t.asset||"DUSD/6";if(!r(e))throw Error(`Invalid asset type "${e}". Supported assets: ${a.join(", ")}`);let n=new URLSearchParams;n.set("asset",e),void 0!==t.limit&&n.set("limit",t.limit.toString()),t.before&&n.set("before",t.before),t.after&&n.set("after",t.after),t.reference&&n.set("reference",t.reference),t.direction&&n.set("direction",t.direction),void 0!==t.collapsed_view&&n.set("collapsed_view",String(t.collapsed_view)),t.pocket&&n.set("pocket",t.pocket),t.next&&n.set("next",t.next);let s=await this.httpClient.request({method:"GET",path:`/api/accounts/transactions?${n.toString()}`});return{data:s.data.map(t=>({amount:t.amount,asset:t.asset,fromAccountId:t.from_account_id,toAccountId:t.to_account_id,direction:t.direction,reference:t.reference,status:t.status,railName:t.rail_name,details:t.details??{},createdAt:t.created_at,type:t.type})),pageSize:s.page_size,hasMore:s.has_more,next:s.next}}_mapByMedium(t){switch(t.medium){case"card":return u(t);case"virtual":return m(t);case"polygon":return d(t);case"bancolombia":return n(t);case"breb":return i(t);case"us-account":return p(t);default:throw Error(`Unknown account medium: ${t.medium}`)}}}export{w as AccountsClient,s as BancolombiaClient,o as BrebClient,c as CardClient,l as PolygonClient,h as UsClient,_ as VirtualClient,n as mapBancolombiaAccountFromWire,i as mapBrebAccountFromWire,u as mapCardAccountFromWire,d as mapPolygonAccountFromWire,p as mapUsAccountFromWire,m as mapVirtualAccountFromWire};
|
|
1
|
+
import{BaseClient as t,BloqueAPIError as e,SUPPORTED_ASSETS as a,isSupportedAsset as r}from"@bloque/sdk-core";function n(t){return{urn:t.urn,id:t.id,referenceCode:t.details.reference_code,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:"balance"in t&&t.balance?t.balance:void 0}}class s extends t{async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","bancolombia"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({...this._mapAccountResponse(t),balance:t.balance}))}}async create(t={},e){let a={holder_urn:t?.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{},metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/bancolombia",body:a}),n=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(n.urn,e.timeout||6e4):n}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async updateName(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{metadata:{name:e}}});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return n(t)}}function i(t){return{id:t.id,urn:t.urn,ownerUrn:t.owner_urn,medium:"breb",remoteKeyId:t.details.remote_key_id,accountId:t.details.account_id,keyType:t.details.key.key_type,key:t.details.key.key_value,displayName:t.details.display_name??null,status:t.status,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,details:t.details,balance:"balance"in t&&t.balance?t.balance:void 0}}class o extends t{mapError(t){if(t instanceof e){let e=t.response;return{code:e?.extra_details?.provider_code??t.code??null,message:t.message}}return t instanceof Error?{code:null,message:t.message}:{code:null,message:"Unknown BRE-B error"}}async createKey(t){try{let e=this.httpClient.urn;if(!e?.trim())throw Error("Holder URN is required");if(!t.key?.trim())throw Error("BRE-B key value is required");let a=await this.httpClient.request({method:"POST",path:"/api/mediums/breb",body:{holder_urn:e,input:{key_type:t.keyType,key_value:t.key,display_name:t.displayName},webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,metadata:{source:"sdk-typescript",...t.metadata}}});return{data:i(a.result.account),error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async resolveKey(t){try{if(!t.key?.trim())throw Error("BRE-B key value is required");return{data:(await this.httpClient.request({method:"POST",path:"/api/mediums/breb/resolve-key",body:{key_type:t.keyType,key:t.key}})).result,error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async deleteKey(t){try{if(!t.accountUrn?.trim())throw Error("BRE-B account URN is required");return{data:(await this.httpClient.request({method:"DELETE",path:`/api/accounts/${encodeURIComponent(t.accountUrn)}/breb/key`})).result,error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async suspendKey(t){try{if(!t.accountUrn?.trim())throw Error("BRE-B account URN is required");return{data:(await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(t.accountUrn)}/breb/key/suspend`})).result,error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async activateKey(t){try{if(!t.accountUrn?.trim())throw Error("BRE-B account URN is required");return{data:(await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(t.accountUrn)}/breb/key/activate`})).result,error:null}}catch(t){return{data:null,error:this.mapError(t)}}}}function u(t){return{urn:t.urn,id:t.id,lastFour:t.details.card_last_four,productType:t.details.card_product_type,status:t.status,cardType:t.details.card_type,detailsUrl:t.details.card_url_details,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}}class c extends t{async create(t={},e){let a={holder_urn:t?.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{create:{card_type:"VIRTUAL"}},metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/card",body:a}),n=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(n.urn,e.timeout||6e4):n}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","card"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({urn:t.urn,id:t.id,lastFour:t.details.card_last_four,productType:t.details.card_product_type,status:t.status,cardType:t.details.card_type,detailsUrl:t.details.card_url_details,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}))}}async movements(t){let e=new URLSearchParams,n=t.asset||"DUSD/6";if(!r(n))throw Error(`Invalid asset type "${n}". Supported assets: ${a.join(", ")}`);e.set("asset",n),void 0!==t.limit&&e.set("limit",t.limit.toString()),t.before&&e.set("before",t.before),t.after&&e.set("after",t.after),t.reference&&e.set("reference",t.reference),t.direction&&e.set("direction",t.direction),void 0!==t.collapsed_view&&e.set("collapsed_view",String(t.collapsed_view)),t.pocket&&e.set("pocket",t.pocket),t.next&&e.set("next",t.next);let s=e.toString(),i=`/api/accounts/${t.urn}/movements${s?`?${s}`:""}`,o=await this.httpClient.request({method:"GET",path:i});return{data:o.data,pageSize:o.page_size,hasMore:o.has_more,next:o.next}}async balance(t){return(await this.httpClient.request({method:"GET",path:`/api/accounts/${t.urn}/balance`})).balance}async update(t){let e={...t.metadata&&{metadata:t.metadata},...t.status&&{status:t.status},...t.webhookUrl&&{webhook_url:t.webhookUrl},...t.ledgerId&&{ledger_account_id:t.ledgerId}},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async updateName(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{metadata:{name:e}}});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async tokenizeApple(t,e){let a={certificates:e.certificates,nonce:e.nonce,nonce_signature:e.nonceSignature},r=await this.httpClient.request({method:"POST",path:`/api/accounts/${t}/tokenize/apple`,body:a});return{activationData:r.result.tokenization.activation_data,encryptedPassData:r.result.tokenization.encrypted_pass_data,ephemeralPublicKey:r.result.tokenization.ephemeral_public_key}}async tokenizeGoogle(t,e){let a={device_id:e.deviceId,wallet_account_id:e.walletAccountId};return{opc:(await this.httpClient.request({method:"POST",path:`/api/accounts/${t}/tokenize/google`,body:a})).result.tokenization.opc}}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return u(t)}}function d(t){return{urn:t.urn,id:t.id,address:t.details.address,network:t.details.network,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:"balance"in t&&t.balance?t.balance:void 0}}class l extends t{async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","polygon"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({...this._mapAccountResponse(t),balance:t.balance}))}}async create(t={},e){let a={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{},metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/polygon",body:a}),n=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(n.urn,e.timeout||6e4):n}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return d(t)}}function p(t){return{urn:t.urn,id:t.id,type:t.details.type,firstName:t.details.first_name,middleName:t.details.middle_name,lastName:t.details.last_name,email:t.details.email,phone:t.details.phone,address:{streetLine1:t.details.address.street_line_1,streetLine2:t.details.address.street_line_2,city:t.details.address.city,state:t.details.address.state,postalCode:t.details.address.postal_code,country:t.details.address.country},birthDate:t.details.birth_date,accountNumber:t.details.account_number,routingNumber:t.details.routing_number,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}}class h extends t{async getTosLink(t){let e=new URLSearchParams({redirect_uri:t.redirectUri});return{url:(await this.httpClient.request({method:"POST",path:`/api/mediums/us-account/tos-link?${e.toString()}`})).result.url}}async create(t,e){let a={street_line_1:t.address.streetLine1,street_line_2:t.address.streetLine2,city:t.address.city,state:t.address.state,postal_code:t.address.postalCode,country:t.address.country},r={type:t.type,first_name:t.firstName,middle_name:t.middleName,last_name:t.lastName,email:t.email,phone:t.phone,address:a,birth_date:t.birthDate,tax_identification_number:t.taxIdentificationNumber,gov_id_country:t.govIdCountry,gov_id_image_front:t.govIdImageFront,signed_agreement_id:t.signedAgreementId},n={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:r,metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},s=await this.httpClient.request({method:"POST",path:"/api/mediums/us-account",body:n}),i=this._mapAccountResponse(s.result.account);return e?.waitLedger?this._waitForActiveStatus(i.urn,e.timeout||6e4):i}async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","us-account"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({urn:t.urn,id:t.id,type:t.details.type,firstName:t.details.first_name,middleName:t.details.middle_name,lastName:t.details.last_name,email:t.details.email,phone:t.details.phone,address:{streetLine1:t.details.address.street_line_1,streetLine2:t.details.address.street_line_2,city:t.details.address.city,state:t.details.address.state,postalCode:t.details.address.postal_code,country:t.details.address.country},birthDate:t.details.birth_date,accountNumber:t.details.account_number,routingNumber:t.details.routing_number,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return p(t)}}function m(t){return{urn:t.urn,id:t.id,firstName:t.details.first_name,lastName:t.details.last_name,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:"balance"in t&&t.balance?t.balance:void 0}}class _ extends t{async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","virtual"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({...this._mapAccountResponse(t),balance:t.balance}))}}async create(t,e){let a={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{},metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/virtual",body:a}),n=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(n.urn,e.timeout||6e4):n}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return m(t)}}class w extends t{bancolombia;breb;card;polygon;us;virtual;constructor(t){super(t),this.bancolombia=new s(this.httpClient),this.breb=new o(this.httpClient),this.card=new c(this.httpClient),this.polygon=new l(this.httpClient),this.us=new h(this.httpClient),this.virtual=new _(this.httpClient)}async balance(t){if(!t?.trim())throw Error("Account URN is required");return(await this.httpClient.request({method:"GET",path:`/api/accounts/${t}/balance`})).balance}async balances(){return(await this.httpClient.request({method:"GET",path:"/api/accounts/balances"})).balance}async get(t){if(!t?.trim())throw Error("Account URN is required");let e=await this.httpClient.request({method:"GET",path:`/api/accounts/${t}`});return this._mapByMedium(e.account)}async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;e&&a.append("holder_urn",e);let r=a.toString(),n=r?`/api/accounts?${r}`:"/api/accounts";return{accounts:(await this.httpClient.request({method:"GET",path:n})).accounts.map(t=>this._mapByMedium(t))}}async transfer(t){let e=t.asset||"DUSD/6";if(!r(e))throw Error(`Invalid asset type "${e}". Supported assets: ${a.join(", ")}`);let n={destination_account_urn:t.destinationUrn,amount:t.amount,asset:e,metadata:t.metadata},s=await this.httpClient.request({method:"POST",path:`/api/accounts/${t.sourceUrn}/transfer`,body:n});return{queueId:s.result.queue_id,status:s.result.status,message:s.result.message}}async batchTransfer(t){if(!t.operations||0===t.operations.length)throw Error("At least one operation is required");if(!t.reference)throw Error("Batch reference is required");for(let e of t.operations)if(!r(e.asset))throw Error(`Invalid asset type "${e.asset}" in operation "${e.reference}". Supported assets: ${a.join(", ")}`);let e={operations:t.operations.map(t=>({from_account_urn:t.fromUrn,to_account_urn:t.toUrn,reference:t.reference,amount:t.amount,asset:t.asset,metadata:t.metadata})),reference:t.reference,metadata:t.metadata,webhook_url:t.webhookUrl},n=await this.httpClient.request({method:"POST",path:"/api/accounts/batch/transfer",body:e});return{chunks:n.result.chunks.map(t=>({queueId:t.queue_id,status:t.status,message:t.message})),totalOperations:n.result.total_operations,totalChunks:n.result.total_chunks}}async movements(t){if(!t.urn)throw Error("Account URN is required");let e=t.asset||"DUSD/6";if(!r(e))throw Error(`Invalid asset type "${e}". Supported assets: ${a.join(", ")}`);let n=new URLSearchParams;n.set("asset",e),void 0!==t.limit&&n.set("limit",t.limit.toString()),t.before&&n.set("before",t.before),t.after&&n.set("after",t.after),t.reference&&n.set("reference",t.reference),t.direction&&n.set("direction",t.direction),void 0!==t.collapsed_view&&n.set("collapsed_view",String(t.collapsed_view)),t.pocket&&n.set("pocket",t.pocket),t.next&&n.set("next",t.next);let s=`/api/accounts/${t.urn}/movements?${n.toString()}`,i=await this.httpClient.request({method:"GET",path:s});return{data:i.data.map(t=>({amount:t.amount,asset:t.asset,fromAccountId:t.from_account_id,toAccountId:t.to_account_id,direction:t.direction,type:t.type,reference:t.reference,status:t.status,railName:t.rail_name,details:t.details,createdAt:t.created_at})),pageSize:i.page_size,hasMore:i.has_more,next:i.next}}async transactions(t={}){let e=t.asset||"DUSD/6";if(!r(e))throw Error(`Invalid asset type "${e}". Supported assets: ${a.join(", ")}`);let n=new URLSearchParams;n.set("asset",e),void 0!==t.limit&&n.set("limit",t.limit.toString()),t.before&&n.set("before",t.before),t.after&&n.set("after",t.after),t.reference&&n.set("reference",t.reference),t.direction&&n.set("direction",t.direction),void 0!==t.collapsed_view&&n.set("collapsed_view",String(t.collapsed_view)),t.pocket&&n.set("pocket",t.pocket),t.next&&n.set("next",t.next);let s=await this.httpClient.request({method:"GET",path:`/api/accounts/transactions?${n.toString()}`});return{data:s.data.map(t=>({amount:t.amount,asset:t.asset,fromAccountId:t.from_account_id,toAccountId:t.to_account_id,direction:t.direction,reference:t.reference,status:t.status,railName:t.rail_name,details:t.details??{},createdAt:t.created_at,type:t.type})),pageSize:s.page_size,hasMore:s.has_more,next:s.next}}_mapByMedium(t){switch(t.medium){case"card":return u(t);case"virtual":return m(t);case"polygon":return d(t);case"bancolombia":return n(t);case"breb":return i(t);case"us-account":return p(t);default:throw Error(`Unknown account medium: ${t.medium}`)}}}export{w as AccountsClient,s as BancolombiaClient,o as BrebClient,c as CardClient,l as PolygonClient,h as UsClient,_ as VirtualClient,n as mapBancolombiaAccountFromWire,i as mapBrebAccountFromWire,u as mapCardAccountFromWire,d as mapPolygonAccountFromWire,p as mapUsAccountFromWire,m as mapVirtualAccountFromWire};
|
|
@@ -205,6 +205,8 @@ export interface UpdateAccountRequest<TInput = unknown> {
|
|
|
205
205
|
input?: TInput;
|
|
206
206
|
metadata?: Record<string, unknown>;
|
|
207
207
|
status?: AccountStatus;
|
|
208
|
+
webhook_url?: string;
|
|
209
|
+
ledger_account_id?: string;
|
|
208
210
|
}
|
|
209
211
|
/**
|
|
210
212
|
* @internal
|
|
@@ -374,6 +376,49 @@ export interface GetBalancesResponse {
|
|
|
374
376
|
out?: string;
|
|
375
377
|
}>;
|
|
376
378
|
}
|
|
379
|
+
/**
|
|
380
|
+
* @internal
|
|
381
|
+
* Apple Pay tokenization request body
|
|
382
|
+
*/
|
|
383
|
+
export interface TokenizeAppleCardRequest {
|
|
384
|
+
certificates: string[];
|
|
385
|
+
nonce: string;
|
|
386
|
+
nonce_signature: string;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* @internal
|
|
390
|
+
* Apple Pay tokenization response
|
|
391
|
+
*/
|
|
392
|
+
export interface TokenizeAppleCardResponse {
|
|
393
|
+
result: {
|
|
394
|
+
tokenization: {
|
|
395
|
+
activation_data: string;
|
|
396
|
+
encrypted_pass_data: string;
|
|
397
|
+
ephemeral_public_key: string;
|
|
398
|
+
};
|
|
399
|
+
};
|
|
400
|
+
req_id: string;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* @internal
|
|
404
|
+
* Google Pay tokenization request body
|
|
405
|
+
*/
|
|
406
|
+
export interface TokenizeGoogleCardRequest {
|
|
407
|
+
device_id: string;
|
|
408
|
+
wallet_account_id: string;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* @internal
|
|
412
|
+
* Google Pay tokenization response
|
|
413
|
+
*/
|
|
414
|
+
export interface TokenizeGoogleCardResponse {
|
|
415
|
+
result: {
|
|
416
|
+
tokenization: {
|
|
417
|
+
opc: string;
|
|
418
|
+
};
|
|
419
|
+
};
|
|
420
|
+
req_id: string;
|
|
421
|
+
}
|
|
377
422
|
/**
|
|
378
423
|
* @internal
|
|
379
424
|
* Transfer request body
|