@bloque/sdk-accounts 0.1.5 → 0.1.6
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/accounts-client.d.ts +48 -36
- package/dist/bancolombia/bancolombia-client.d.ts +5 -2
- package/dist/card/card-client.d.ts +5 -2
- package/dist/external-us-bank/external-us-bank-client.d.ts +29 -0
- package/dist/external-us-bank/types.d.ts +70 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1 -1
- package/dist/internal/wire-types.d.ts +66 -1
- package/dist/polygon/polygon-client.d.ts +5 -2
- package/dist/types.d.ts +18 -2
- package/dist/us/us-client.d.ts +5 -2
- package/dist/us2/types.d.ts +48 -0
- package/dist/us2/us2-client.d.ts +9 -0
- package/dist/virtual/virtual-client.d.ts +5 -2
- package/package.json +2 -2
|
@@ -6,18 +6,22 @@ import { BrebClient } from './breb/breb-client';
|
|
|
6
6
|
import type { BrebKeyAccount } from './breb/types';
|
|
7
7
|
import { CardClient } from './card/card-client';
|
|
8
8
|
import type { CardAccount, ListMovementsParams } from './card/types';
|
|
9
|
+
import { ExternalUsBankClient } from './external-us-bank/external-us-bank-client';
|
|
10
|
+
import type { ExternalUsBankAccount } from './external-us-bank/types';
|
|
9
11
|
import { PolygonClient } from './polygon/polygon-client';
|
|
10
12
|
import type { PolygonAccount } from './polygon/types';
|
|
11
|
-
import type { BatchTransferParams, BatchTransferResult, GeneralTokenBalance, ListAccountsParams, ListAccountsResult, ListMovementsResult, ListTransactionsParams, ListTransactionsResult, TokenBalance, TransferParams, TransferResult } from './types';
|
|
13
|
+
import type { BatchTransferOptions, BatchTransferParams, BatchTransferResult, GeneralTokenBalance, ListAccountsParams, ListAccountsResult, ListMovementsResult, ListTransactionsParams, ListTransactionsResult, TokenBalance, TransferOptions, TransferParams, TransferResult } from './types';
|
|
12
14
|
import type { UsAccount } from './us/types';
|
|
13
15
|
import { UsClient } from './us/us-client';
|
|
16
|
+
import type { Us2Account } from './us2/types';
|
|
17
|
+
import { Us2Client } from './us2/us2-client';
|
|
14
18
|
import type { VirtualAccount } from './virtual/types';
|
|
15
19
|
import { VirtualClient } from './virtual/virtual-client';
|
|
16
20
|
/**
|
|
17
21
|
* Union of all medium-specific mapped account types.
|
|
18
22
|
* Returned by `AccountsClient.get()` and used in `AccountsClient.list()`.
|
|
19
23
|
*/
|
|
20
|
-
export type MappedAccount = CardAccount | VirtualAccount | PolygonAccount | BancolombiaAccount | BrebKeyAccount | UsAccount;
|
|
24
|
+
export type MappedAccount = CardAccount | VirtualAccount | PolygonAccount | BancolombiaAccount | BrebKeyAccount | ExternalUsBankAccount | Us2Account | UsAccount;
|
|
21
25
|
/**
|
|
22
26
|
* Accounts client for managing financial accounts and payment methods
|
|
23
27
|
*
|
|
@@ -33,8 +37,10 @@ export declare class AccountsClient extends BaseClient {
|
|
|
33
37
|
readonly bancolombia: BancolombiaClient;
|
|
34
38
|
readonly breb: BrebClient;
|
|
35
39
|
readonly card: CardClient;
|
|
40
|
+
readonly externalUsBank: ExternalUsBankClient;
|
|
36
41
|
readonly polygon: PolygonClient;
|
|
37
42
|
readonly us: UsClient;
|
|
43
|
+
readonly us2: Us2Client;
|
|
38
44
|
readonly virtual: VirtualClient;
|
|
39
45
|
constructor(httpClient: HttpClient);
|
|
40
46
|
/**
|
|
@@ -117,19 +123,22 @@ export declare class AccountsClient extends BaseClient {
|
|
|
117
123
|
*
|
|
118
124
|
* @example
|
|
119
125
|
* ```typescript
|
|
120
|
-
* const transfer = await bloque.accounts.transfer(
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
126
|
+
* const transfer = await bloque.accounts.transfer(
|
|
127
|
+
* {
|
|
128
|
+
* sourceUrn: 'did:bloque:account:card:usr-123:crd-456',
|
|
129
|
+
* destinationUrn: 'did:bloque:account:virtual:acc-67890',
|
|
130
|
+
* amount: '1000000000000',
|
|
131
|
+
* asset: 'KSM/12',
|
|
132
|
+
* metadata: {
|
|
133
|
+
* reference: 'payment-123',
|
|
134
|
+
* note: 'Monthly subscription'
|
|
135
|
+
* }
|
|
136
|
+
* },
|
|
137
|
+
* { idempotencyKey: 'transfer-payment-123' }
|
|
138
|
+
* );
|
|
130
139
|
* ```
|
|
131
140
|
*/
|
|
132
|
-
transfer(params: TransferParams): Promise<TransferResult>;
|
|
141
|
+
transfer(params: TransferParams, options?: TransferOptions): Promise<TransferResult>;
|
|
133
142
|
/**
|
|
134
143
|
* Batch transfer funds between multiple accounts
|
|
135
144
|
*
|
|
@@ -141,31 +150,34 @@ export declare class AccountsClient extends BaseClient {
|
|
|
141
150
|
*
|
|
142
151
|
* @example
|
|
143
152
|
* ```typescript
|
|
144
|
-
* const result = await bloque.accounts.batchTransfer(
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
153
|
+
* const result = await bloque.accounts.batchTransfer(
|
|
154
|
+
* {
|
|
155
|
+
* reference: 'batch-payroll-2024-01-15',
|
|
156
|
+
* operations: [
|
|
157
|
+
* {
|
|
158
|
+
* fromUrn: 'did:bloque:account:virtual:acc-12345',
|
|
159
|
+
* toUrn: 'did:bloque:account:virtual:acc-67890',
|
|
160
|
+
* reference: 'transfer-001',
|
|
161
|
+
* amount: '1000000000000',
|
|
162
|
+
* asset: 'KSM/12',
|
|
163
|
+
* metadata: { note: 'Payment for order #123' }
|
|
164
|
+
* },
|
|
165
|
+
* {
|
|
166
|
+
* fromUrn: 'did:bloque:account:virtual:acc-12345',
|
|
167
|
+
* toUrn: 'did:bloque:account:card:usr-456:crd-789',
|
|
168
|
+
* reference: 'transfer-002',
|
|
169
|
+
* amount: '500000000000',
|
|
170
|
+
* asset: 'KSM/12'
|
|
171
|
+
* }
|
|
172
|
+
* ],
|
|
173
|
+
* metadata: { batch_id: 'batch-2024-01-15' },
|
|
174
|
+
* webhookUrl: 'https://api.example.com/webhooks/batch-settlement'
|
|
175
|
+
* },
|
|
176
|
+
* { idempotencyKey: 'batch-payroll-2024-01-15' }
|
|
177
|
+
* );
|
|
166
178
|
* ```
|
|
167
179
|
*/
|
|
168
|
-
batchTransfer(params: BatchTransferParams): Promise<BatchTransferResult>;
|
|
180
|
+
batchTransfer(params: BatchTransferParams, options?: BatchTransferOptions): Promise<BatchTransferResult>;
|
|
169
181
|
/**
|
|
170
182
|
* List account movements/transactions
|
|
171
183
|
*
|
|
@@ -47,10 +47,13 @@ export declare class BancolombiaClient extends BaseClient {
|
|
|
47
47
|
* name: 'Main Account'
|
|
48
48
|
* });
|
|
49
49
|
*
|
|
50
|
-
* // Create and wait for active status
|
|
50
|
+
* // Create and wait for active status with explicit idempotency key
|
|
51
51
|
* const account = await bloque.accounts.bancolombia.create({
|
|
52
52
|
* name: 'Main Account'
|
|
53
|
-
* }, {
|
|
53
|
+
* }, {
|
|
54
|
+
* waitLedger: true,
|
|
55
|
+
* idempotencyKey: 'create-bancolombia-main-account'
|
|
56
|
+
* });
|
|
54
57
|
* ```
|
|
55
58
|
*/
|
|
56
59
|
create(params?: CreateBancolombiaAccountParams, options?: CreateAccountOptions): Promise<BancolombiaAccount>;
|
|
@@ -22,10 +22,13 @@ export declare class CardClient extends BaseClient {
|
|
|
22
22
|
* name: 'My Card',
|
|
23
23
|
* });
|
|
24
24
|
*
|
|
25
|
-
* // Create and wait for active status
|
|
25
|
+
* // Create and wait for active status with explicit idempotency key
|
|
26
26
|
* const card = await bloque.accounts.card.create({
|
|
27
27
|
* name: 'My Card',
|
|
28
|
-
* }, {
|
|
28
|
+
* }, {
|
|
29
|
+
* waitLedger: true,
|
|
30
|
+
* idempotencyKey: 'create-card-my-card'
|
|
31
|
+
* });
|
|
29
32
|
* ```
|
|
30
33
|
*/
|
|
31
34
|
create(params?: CreateCardParams, options?: CreateAccountOptions): Promise<CardAccount>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BaseClient } from '@bloque/sdk-core';
|
|
2
|
+
import type { AccountWithBalance, ExternalUsBankDetails } from '../internal/wire-types';
|
|
3
|
+
import type { CreateAccountOptions } from '../types';
|
|
4
|
+
import type { CreateExternalUsBankAccountParams, ExchangeExternalUsBankPublicTokenParams, ExternalUsBankAccount } from './types';
|
|
5
|
+
export declare function mapExternalUsBankAccountFromWire(account: AccountWithBalance<ExternalUsBankDetails>): ExternalUsBankAccount;
|
|
6
|
+
export declare class ExternalUsBankClient extends BaseClient {
|
|
7
|
+
/**
|
|
8
|
+
* Start the Plaid linkage flow.
|
|
9
|
+
*
|
|
10
|
+
* Two ways to finish linking:
|
|
11
|
+
* - **Hosted page** — pass `returnUrl` (and optionally `state`). The
|
|
12
|
+
* response includes `details.linkUrl`; open it in a browser and the
|
|
13
|
+
* page exchanges the Plaid `public_token` on behalf of the user, then
|
|
14
|
+
* redirects to `returnUrl?status=…&state=…`. Zero frontend code.
|
|
15
|
+
* - **Embedded Plaid Link** — omit `returnUrl`. Use `details.linkToken`
|
|
16
|
+
* to drive Plaid Link in your own frontend, then call
|
|
17
|
+
* {@link ExternalUsBankClient.exchangePublicToken} from your backend.
|
|
18
|
+
*/
|
|
19
|
+
create(params: CreateExternalUsBankAccountParams, _options?: CreateAccountOptions): Promise<ExternalUsBankAccount>;
|
|
20
|
+
/**
|
|
21
|
+
* Finish the Plaid linkage flow by exchanging the Plaid `public_token`.
|
|
22
|
+
*
|
|
23
|
+
* Only needed when you drove Plaid Link yourself. If the user completed
|
|
24
|
+
* linking through the hosted page (`details.linkUrl`), the server already
|
|
25
|
+
* exchanged the token on redirect — call {@link AccountsClient.get} on the
|
|
26
|
+
* URN to read the final state instead.
|
|
27
|
+
*/
|
|
28
|
+
exchangePublicToken(params: ExchangeExternalUsBankPublicTokenParams): Promise<ExternalUsBankAccount>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { AccountStatus, TokenBalance } from '../types';
|
|
2
|
+
export type ExternalUsBankLinkStatus = 'pending_link' | 'active' | 'link_failed' | 'closed';
|
|
3
|
+
export interface ExternalUsBankAccountDetails {
|
|
4
|
+
id: string;
|
|
5
|
+
linkStatus: ExternalUsBankLinkStatus;
|
|
6
|
+
braleAccountId?: string;
|
|
7
|
+
braleAddressId?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Short-lived Plaid `link_token`. Embed Plaid Link with this token to drive
|
|
10
|
+
* the browser-side flow yourself, or open `linkUrl` to use the Bloque-hosted
|
|
11
|
+
* page instead.
|
|
12
|
+
*/
|
|
13
|
+
linkToken?: string;
|
|
14
|
+
/** ISO 8601 expiration of `linkToken`, as reported by Brale. */
|
|
15
|
+
linkTokenExpiration?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Fully-qualified URL of the Bloque-hosted Plaid Link page for this pending
|
|
18
|
+
* account. Open it in a browser (or redirect the user to it) to complete
|
|
19
|
+
* linking without embedding Plaid Link yourself. Carries a short-lived
|
|
20
|
+
* `plaid-link` JWT bound to this account URN; only present when the server
|
|
21
|
+
* issued one (typically when `returnUrl` was supplied at create time).
|
|
22
|
+
*/
|
|
23
|
+
linkUrl?: string;
|
|
24
|
+
bankAccountLast4?: string;
|
|
25
|
+
bankName?: string;
|
|
26
|
+
failureReason?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ExternalUsBankAccount {
|
|
29
|
+
urn: string;
|
|
30
|
+
id: string;
|
|
31
|
+
status: AccountStatus;
|
|
32
|
+
ownerUrn: string;
|
|
33
|
+
ledgerId: string;
|
|
34
|
+
webhookUrl: string | null;
|
|
35
|
+
metadata?: Record<string, unknown>;
|
|
36
|
+
createdAt: string;
|
|
37
|
+
updatedAt: string;
|
|
38
|
+
balance: Record<string, TokenBalance>;
|
|
39
|
+
details: ExternalUsBankAccountDetails;
|
|
40
|
+
}
|
|
41
|
+
export interface CreateExternalUsBankAccountParams {
|
|
42
|
+
holderUrn?: string;
|
|
43
|
+
webhookUrl?: string;
|
|
44
|
+
ledgerId?: string;
|
|
45
|
+
metadata?: Record<string, unknown>;
|
|
46
|
+
label?: string;
|
|
47
|
+
/**
|
|
48
|
+
* URL the user is redirected to after the hosted Plaid Link page finishes.
|
|
49
|
+
* Origin must be allowlisted by the server (`PLAID_LINK_RETURN_URL_ALLOWLIST`).
|
|
50
|
+
*
|
|
51
|
+
* Supplying this opts into the hosted-page flow: the response's
|
|
52
|
+
* `details.linkUrl` becomes the destination to open, and the server mints
|
|
53
|
+
* a short-lived `plaid-link` JWT bound to the returned account URN.
|
|
54
|
+
*
|
|
55
|
+
* @example "https://app.example.com/wallet/plaid-return"
|
|
56
|
+
*/
|
|
57
|
+
returnUrl?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Opaque correlator forwarded back through `returnUrl` as `state`
|
|
60
|
+
* (max 256 characters). Use it to resume your UI flow after the hosted page
|
|
61
|
+
* redirects the user.
|
|
62
|
+
*
|
|
63
|
+
* @example "user-session-xyz"
|
|
64
|
+
*/
|
|
65
|
+
state?: string;
|
|
66
|
+
}
|
|
67
|
+
export interface ExchangeExternalUsBankPublicTokenParams {
|
|
68
|
+
urn: string;
|
|
69
|
+
publicToken: string;
|
|
70
|
+
}
|
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}}function mapDecodedQrFromWire(e){return{amount:e.amount,additionalInfo:e.additional_info?{transactionPurpose:e.additional_info.transaction_purpose,terminalLabel:e.additional_info.terminal_label,invoiceNumber:e.additional_info.invoice_number,mobilePhoneNumber:e.additional_info.mobile_phone_number,storeLabel:e.additional_info.store_label,loyaltyLabel:e.additional_info.loyalty_label,referenceLabel:e.additional_info.reference_label,customerLabel:e.additional_info.customer_label,customerInfo:e.additional_info.customer_info,channelPresentation:e.additional_info.channel_presentation}:null,key:e.key?{keyType:e.key.key_type,keyValue:e.key.key_value}:null,qrCodeData:e.qr_code_data,status:e.status,acquirerNetworkIdentifier:e.acquirer_network_identifier,merchant:e.merchant?{merchantCategoryCode:e.merchant.merchant_category_code,merchantCountry:e.merchant.merchant_country,merchantName:e.merchant.merchant_name,merchantCity:e.merchant.merchant_city,merchantPostCode:e.merchant.merchant_post_code}:null,channel:e.channel,qrCodeReference:e.qr_code_reference,type:e.type,resolutionId:e.resolution_id,resolution:e.resolution}}class BrebClient extends sdk_core_namespaceObject.BaseClient{mapError(e){if(e instanceof sdk_core_namespaceObject.BloqueAPIError){let t=e.response;return{code:t?.extra_details?.provider_code??e.code??null,message:e.message}}return e instanceof Error?{code:null,message:e.message}:{code:null,message:"Unknown BRE-B error"}}async createKey(e){try{let t=this.httpClient.urn;if(!t?.trim())throw Error("Holder URN is required");if(!e.key?.trim())throw Error("BRE-B key value is required");let a=await this.httpClient.request({method:"POST",path:"/api/mediums/breb",body:{holder_urn:t,input:{key_type:e.keyType,key_value:e.key,display_name:e.displayName},webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,metadata:{source:"sdk-typescript",...e.metadata}}});return{data:mapBrebAccountFromWire(a.result.account),error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async resolveKey(e){try{if(!e.key?.trim())throw Error("BRE-B key value is required");return{data:(await this.httpClient.request({method:"POST",path:"/api/mediums/breb/resolve-key",body:{key_type:e.keyType,key:e.key}})).result,error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async decodeQr(e){try{if(!e.qrCodeData?.trim())throw Error("BRE-B QR code data is required");let t=await this.httpClient.request({method:"POST",path:"/api/mediums/breb/decode-qr",body:{qr_code_data:e.qrCodeData}});return{data:mapDecodedQrFromWire(t.result),error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async deleteKey(e){try{if(!e.accountUrn?.trim())throw Error("BRE-B account URN is required");let t=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(e.accountUrn)}`,body:{status:"deleted"}});return{data:{deleted:!0,accountUrn:t.result.account.urn,keyId:t.result.account.details.id,status:"deleted"},error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async suspendKey(e){try{if(!e.accountUrn?.trim())throw Error("BRE-B account URN is required");let t=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(e.accountUrn)}`,body:{status:"frozen"}});return{data:{accountUrn:t.result.account.urn,keyId:t.result.account.details.id,keyStatus:t.result.account.details.status,status:"frozen"},error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async activateKey(e){try{if(!e.accountUrn?.trim())throw Error("BRE-B account URN is required");let t=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(e.accountUrn)}`,body:{status:"active"}});return{data:{accountUrn:t.result.account.urn,keyId:t.result.account.details.id,keyStatus:t.result.account.details.status,status:"active"},error:null}}catch(e){return{data:null,error:this.mapError(e)}}}}function mapCardAccountFromWire(e){return{urn:e.urn,id:e.id,lastFour:e.details.card_last_four,productType:e.details.card_product_type,status:e.status,cardType:e.details.card_type,detailsUrl:e.details.card_url_details,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}}class CardClient extends sdk_core_namespaceObject.BaseClient{async create(e={},t){let a={holder_urn:e?.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{create:{card_type:"VIRTUAL"}},metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/card",body:a}),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});
|
|
1
|
+
"use strict";const __rslib_import_meta_url__="u"<typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,t)=>{for(var a in t)__webpack_require__.o(t,a)&&!__webpack_require__.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{mapUs2AccountFromWire:()=>mapUs2AccountFromWire,mapBrebAccountFromWire:()=>mapBrebAccountFromWire,mapUsAccountFromWire:()=>mapUsAccountFromWire,mapBancolombiaAccountFromWire:()=>mapBancolombiaAccountFromWire,mapVirtualAccountFromWire:()=>mapVirtualAccountFromWire,VirtualClient:()=>VirtualClient,BancolombiaClient:()=>BancolombiaClient,mapExternalUsBankAccountFromWire:()=>mapExternalUsBankAccountFromWire,ExternalUsBankClient:()=>ExternalUsBankClient,AccountsClient:()=>AccountsClient,PolygonClient:()=>PolygonClient,UsClient:()=>UsClient,CardClient:()=>CardClient,mapCardAccountFromWire:()=>mapCardAccountFromWire,mapPolygonAccountFromWire:()=>mapPolygonAccountFromWire,Us2Client:()=>Us2Client,BrebClient:()=>BrebClient});const sdk_core_namespaceObject=require("@bloque/sdk-core");function mapBancolombiaAccountFromWire(e){return{urn:e.urn,id:e.id,referenceCode:e.details.reference_code,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:"balance"in e&&e.balance?e.balance:void 0}}class BancolombiaClient extends sdk_core_namespaceObject.BaseClient{async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","bancolombia"),t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(e=>({...this._mapAccountResponse(e),balance:e.balance}))}}async create(e={},t){let a={holder_urn:e?.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{},metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/bancolombia",body:a,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return t?.waitLedger?this._waitForActiveStatus(n.urn,t.timeout||6e4):n}async _waitForActiveStatus(e,t){let a=Date.now();for(;;){if(Date.now()-a>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let r=(await this.list({urn:e})).accounts[0];if(!r)throw Error(`Account not found. URN: ${e}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${e}`);await new Promise(e=>setTimeout(e,2e3))}}async updateMetadata(e){let t={metadata:e.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(a.result.account)}async updateName(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{metadata:{name:t}}});return this._mapAccountResponse(a.result.account)}async activate(e){return this._updateStatus(e,"active")}async freeze(e){return this._updateStatus(e,"frozen")}async disable(e){return this._updateStatus(e,"disabled")}async _updateStatus(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{status:t}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(e){return mapBancolombiaAccountFromWire(e)}}function mapBrebAccountFromWire(e){return{id:e.id,urn:e.urn,ownerUrn:e.owner_urn,medium:"breb",remoteKeyId:e.details.remote_key_id,accountId:e.details.account_id,keyType:e.details.key.key_type,key:e.details.key.key_value,displayName:e.details.display_name??null,status:e.status,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,details:e.details,balance:"balance"in e&&e.balance?e.balance:void 0}}function mapDecodedQrFromWire(e){return{amount:e.amount,additionalInfo:e.additional_info?{transactionPurpose:e.additional_info.transaction_purpose,terminalLabel:e.additional_info.terminal_label,invoiceNumber:e.additional_info.invoice_number,mobilePhoneNumber:e.additional_info.mobile_phone_number,storeLabel:e.additional_info.store_label,loyaltyLabel:e.additional_info.loyalty_label,referenceLabel:e.additional_info.reference_label,customerLabel:e.additional_info.customer_label,customerInfo:e.additional_info.customer_info,channelPresentation:e.additional_info.channel_presentation}:null,key:e.key?{keyType:e.key.key_type,keyValue:e.key.key_value}:null,qrCodeData:e.qr_code_data,status:e.status,acquirerNetworkIdentifier:e.acquirer_network_identifier,merchant:e.merchant?{merchantCategoryCode:e.merchant.merchant_category_code,merchantCountry:e.merchant.merchant_country,merchantName:e.merchant.merchant_name,merchantCity:e.merchant.merchant_city,merchantPostCode:e.merchant.merchant_post_code}:null,channel:e.channel,qrCodeReference:e.qr_code_reference,type:e.type,resolutionId:e.resolution_id,resolution:e.resolution}}class BrebClient extends sdk_core_namespaceObject.BaseClient{mapError(e){if(e instanceof sdk_core_namespaceObject.BloqueAPIError){let t=e.response;return{code:t?.extra_details?.provider_code??e.code??null,message:e.message}}return e instanceof Error?{code:null,message:e.message}:{code:null,message:"Unknown BRE-B error"}}async createKey(e){try{let t=this.httpClient.urn;if(!t?.trim())throw Error("Holder URN is required");if(!e.key?.trim())throw Error("BRE-B key value is required");let a=await this.httpClient.request({method:"POST",path:"/api/mediums/breb",body:{holder_urn:t,input:{key_type:e.keyType,key_value:e.key,display_name:e.displayName},webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,metadata:{source:"sdk-typescript",...e.metadata}}});return{data:mapBrebAccountFromWire(a.result.account),error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async resolveKey(e){try{if(!e.key?.trim())throw Error("BRE-B key value is required");return{data:(await this.httpClient.request({method:"POST",path:"/api/mediums/breb/resolve-key",body:{key_type:e.keyType,key:e.key}})).result,error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async decodeQr(e){try{if(!e.qrCodeData?.trim())throw Error("BRE-B QR code data is required");let t=await this.httpClient.request({method:"POST",path:"/api/mediums/breb/decode-qr",body:{qr_code_data:e.qrCodeData}});return{data:mapDecodedQrFromWire(t.result),error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async deleteKey(e){try{if(!e.accountUrn?.trim())throw Error("BRE-B account URN is required");let t=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(e.accountUrn)}`,body:{status:"deleted"}});return{data:{deleted:!0,accountUrn:t.result.account.urn,keyId:t.result.account.details.id,status:"deleted"},error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async suspendKey(e){try{if(!e.accountUrn?.trim())throw Error("BRE-B account URN is required");let t=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(e.accountUrn)}`,body:{status:"frozen"}});return{data:{accountUrn:t.result.account.urn,keyId:t.result.account.details.id,keyStatus:t.result.account.details.status,status:"frozen"},error:null}}catch(e){return{data:null,error:this.mapError(e)}}}async activateKey(e){try{if(!e.accountUrn?.trim())throw Error("BRE-B account URN is required");let t=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(e.accountUrn)}`,body:{status:"active"}});return{data:{accountUrn:t.result.account.urn,keyId:t.result.account.details.id,keyStatus:t.result.account.details.status,status:"active"},error:null}}catch(e){return{data:null,error:this.mapError(e)}}}}function mapCardAccountFromWire(e){return{urn:e.urn,id:e.id,lastFour:e.details.card_last_four,productType:e.details.card_product_type,status:e.status,cardType:e.details.card_type,detailsUrl:e.details.card_url_details,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}}class CardClient extends sdk_core_namespaceObject.BaseClient{async create(e={},t){let a={holder_urn:e?.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{create:{card_type:"VIRTUAL"}},metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/card",body:a,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return t?.waitLedger?this._waitForActiveStatus(n.urn,t.timeout||6e4):n}async _waitForActiveStatus(e,t){let a=Date.now();for(;;){if(Date.now()-a>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let r=(await this.list({urn:e})).accounts[0];if(!r)throw Error(`Account not found. URN: ${e}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${e}`);await new Promise(e=>setTimeout(e,2e3))}}async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","card"),t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(e=>({urn:e.urn,id:e.id,lastFour:e.details.card_last_four,productType:e.details.card_product_type,status:e.status,cardType:e.details.card_type,detailsUrl:e.details.card_url_details,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}))}}async movements(e){let t=new URLSearchParams,a=e.asset||"DUSD/6";if(!(0,sdk_core_namespaceObject.isSupportedAsset)(a))throw Error(`Invalid asset type "${a}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);t.set("asset",a),void 0!==e.limit&&t.set("limit",e.limit.toString()),e.before&&t.set("before",e.before),e.after&&t.set("after",e.after),e.reference&&t.set("reference",e.reference),e.direction&&t.set("direction",e.direction),void 0!==e.collapsed_view&&t.set("collapsed_view",String(e.collapsed_view)),e.pocket&&t.set("pocket",e.pocket),e.next&&t.set("next",e.next);let r=t.toString(),n=`/api/accounts/${e.urn}/movements${r?`?${r}`:""}`,o=await this.httpClient.request({method:"GET",path:n});return{data:o.data,pageSize:o.page_size,hasMore:o.has_more,next:o.next}}async balance(e){return(await this.httpClient.request({method:"GET",path:`/api/accounts/${e.urn}/balance`})).balance}async update(e){let t={...e.metadata&&{metadata:e.metadata},...e.status&&{status:e.status},...e.webhookUrl&&{webhook_url:e.webhookUrl},...e.ledgerId&&{ledger_account_id:e.ledgerId}},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(a.result.account)}async updateMetadata(e){let t={metadata:e.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(a.result.account)}async updateName(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{metadata:{name:t}}});return this._mapAccountResponse(a.result.account)}async activate(e){return this._updateStatus(e,"active")}async freeze(e){return this._updateStatus(e,"frozen")}async disable(e){return this._updateStatus(e,"disabled")}async tokenizeApple(e,t){let a={certificates:t.certificates,nonce:t.nonce,nonce_signature:t.nonceSignature},r=await this.httpClient.request({method:"POST",path:`/api/accounts/${e}/tokenize/apple`,body:a});return{activationData:r.result.tokenization.activation_data,encryptedPassData:r.result.tokenization.encrypted_pass_data,ephemeralPublicKey:r.result.tokenization.ephemeral_public_key}}async tokenizeGoogle(e,t){let a={device_id:t.deviceId,wallet_account_id:t.walletAccountId};return{opc:(await this.httpClient.request({method:"POST",path:`/api/accounts/${e}/tokenize/google`,body:a})).result.tokenization.opc}}async _updateStatus(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{status:t}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(e){return mapCardAccountFromWire(e)}}function mapExternalUsBankAccountFromWire(e){return{urn:e.urn,id:e.id,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance,details:{id:e.details.id,linkStatus:e.details.link_status,braleAccountId:e.details.brale_account_id,braleAddressId:e.details.brale_address_id,linkToken:e.details.link_token,linkTokenExpiration:e.details.link_token_expiration,linkUrl:e.details.link_url,bankAccountLast4:e.details.bank_account_last4,bankName:e.details.bank_name,failureReason:e.details.failure_reason}}}class ExternalUsBankClient extends sdk_core_namespaceObject.BaseClient{async create(e,t){let a={holder_urn:e.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{label:e.label},metadata:{source:"sdk-typescript",...e.metadata},return_url:e.returnUrl,state:e.state};return mapExternalUsBankAccountFromWire((await this.httpClient.request({method:"POST",path:"/api/mediums/external-us-bank",body:a})).result.account)}async exchangePublicToken(e){let t={input:{public_token:e.publicToken}};return mapExternalUsBankAccountFromWire((await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t})).result.account)}}function mapPolygonAccountFromWire(e){return{urn:e.urn,id:e.id,address:e.details.address,network:e.details.network,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:"balance"in e&&e.balance?e.balance:void 0}}class PolygonClient extends sdk_core_namespaceObject.BaseClient{async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","polygon"),t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(e=>({...this._mapAccountResponse(e),balance:e.balance}))}}async create(e={},t){let a={holder_urn:e.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{},metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/polygon",body:a,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return t?.waitLedger?this._waitForActiveStatus(n.urn,t.timeout||6e4):n}async _waitForActiveStatus(e,t){let a=Date.now();for(;;){if(Date.now()-a>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let r=(await this.list({urn:e})).accounts[0];if(!r)throw Error(`Account not found. URN: ${e}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${e}`);await new Promise(e=>setTimeout(e,2e3))}}async updateMetadata(e){let t={metadata:e.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(a.result.account)}async activate(e){return this._updateStatus(e,"active")}async freeze(e){return this._updateStatus(e,"frozen")}async disable(e){return this._updateStatus(e,"disabled")}async _updateStatus(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{status:t}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(e){return mapPolygonAccountFromWire(e)}}function mapUsAccountFromWire(e){return{urn:e.urn,id:e.id,type:e.details.type,firstName:e.details.first_name,middleName:e.details.middle_name,lastName:e.details.last_name,email:e.details.email,phone:e.details.phone,address:{streetLine1:e.details.address.street_line_1,streetLine2:e.details.address.street_line_2,city:e.details.address.city,state:e.details.address.state,postalCode:e.details.address.postal_code,country:e.details.address.country},birthDate:e.details.birth_date,accountNumber:e.details.account_number,routingNumber:e.details.routing_number,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}}class UsClient extends sdk_core_namespaceObject.BaseClient{async getTosLink(e){let t=new URLSearchParams({redirect_uri:e.redirectUri}),a=(await this.httpClient.request({method:"POST",path:`/api/mediums/us-account/tos-link?${t.toString()}`})).result.url;try{let t=new URL(a);t.searchParams.has("redirect_uri")||(t.searchParams.set("redirect_uri",e.redirectUri),a=t.toString())}catch{let t=a.includes("?")?"&":"?";/[?&]redirect_uri=/.test(a)||(a=`${a}${t}redirect_uri=${encodeURIComponent(e.redirectUri)}`)}return{url:a}}async create(e,t){let a={street_line_1:e.address.streetLine1,street_line_2:e.address.streetLine2,city:e.address.city,state:e.address.state,postal_code:e.address.postalCode,country:e.address.country},r={type:e.type,first_name:e.firstName,middle_name:e.middleName,last_name:e.lastName,email:e.email,phone:e.phone,address:a,birth_date:e.birthDate,tax_identification_number:e.taxIdentificationNumber,gov_id_country:e.govIdCountry,gov_id_image_front:e.govIdImageFront,signed_agreement_id:e.signedAgreementId},n={holder_urn:e.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:r,metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},o=await this.httpClient.request({method:"POST",path:"/api/mediums/us-account",body:n,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),s=this._mapAccountResponse(o.result.account);return t?.waitLedger?this._waitForActiveStatus(s.urn,t.timeout||6e4):s}async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","us-account"),t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(e=>({urn:e.urn,id:e.id,type:e.details.type,firstName:e.details.first_name,middleName:e.details.middle_name,lastName:e.details.last_name,email:e.details.email,phone:e.details.phone,address:{streetLine1:e.details.address.street_line_1,streetLine2:e.details.address.street_line_2,city:e.details.address.city,state:e.details.address.state,postalCode:e.details.address.postal_code,country:e.details.address.country},birthDate:e.details.birth_date,accountNumber:e.details.account_number,routingNumber:e.details.routing_number,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance}))}}async updateMetadata(e){let t={metadata:e.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(a.result.account)}async activate(e){return this._updateStatus(e,"active")}async freeze(e){return this._updateStatus(e,"frozen")}async disable(e){return this._updateStatus(e,"disabled")}async _waitForActiveStatus(e,t){let a=Date.now();for(;;){if(Date.now()-a>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let r=(await this.list({urn:e})).accounts[0];if(!r)throw Error(`Account not found. URN: ${e}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${e}`);await new Promise(e=>setTimeout(e,2e3))}}async _updateStatus(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{status:t}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(e){return mapUsAccountFromWire(e)}}function mapUs2AccountFromWire(e){return{urn:e.urn,id:e.id,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:e.balance,details:{id:e.details.id,userId:e.details.user_id,virtualAccountId:e.details.virtual_account_id,type:e.details.type,currency:e.details.currency}}}class Us2Client extends sdk_core_namespaceObject.BaseClient{async create(e,t){let a={type:e.type,email:e.email,phone:e.phone,proof_of_address:e.proofOfAddress,business_formation_document:e.businessFormationDocument,tax_id:e.taxId,address:e.address?{street:e.address.street,city:e.address.city,state:e.address.state,postal_code:e.address.postalCode,country:e.address.country}:void 0},r={holder_urn:e.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:a,metadata:{source:"sdk-typescript",...e.metadata}};return mapUs2AccountFromWire((await this.httpClient.request({method:"POST",path:"/api/mediums/us2-account",body:r})).result.account)}async list(e={}){let t=e.holderUrn||this.httpClient.urn,a=new URLSearchParams;return a.append("medium","us2-account"),t&&a.append("holder_urn",t),e.urn&&a.append("urn",e.urn),{accounts:(await this.httpClient.request({method:"GET",path:`/api/accounts?${a.toString()}`})).accounts.map(e=>mapUs2AccountFromWire(e))}}}function mapVirtualAccountFromWire(e){return{urn:e.urn,id:e.id,firstName:e.details.first_name,lastName:e.details.last_name,status:e.status,ownerUrn:e.owner_urn,ledgerId:e.ledger_account_id,webhookUrl:e.webhook_url,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at,balance:"balance"in e&&e.balance?e.balance:void 0}}class VirtualClient extends sdk_core_namespaceObject.BaseClient{async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","virtual"),t&&a.append("holder_urn",t),e?.urn&&a.append("urn",e.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(e=>({...this._mapAccountResponse(e),balance:e.balance}))}}async create(e,t){let a={holder_urn:e.holderUrn||this.httpClient.urn||"",webhook_url:e.webhookUrl,ledger_account_id:e.ledgerId,input:{},metadata:{source:"sdk-typescript",name:e.name,...e.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/virtual",body:a,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return t?.waitLedger?this._waitForActiveStatus(n.urn,t.timeout||6e4):n}async _waitForActiveStatus(e,t){let a=Date.now();for(;;){if(Date.now()-a>t)throw Error(`Timeout waiting for account to become active. URN: ${e}`);let r=(await this.list({urn:e})).accounts[0];if(!r)throw Error(`Account not found. URN: ${e}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${e}`);await new Promise(e=>setTimeout(e,2e3))}}async updateMetadata(e){let t={metadata:e.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e.urn}`,body:t});return this._mapAccountResponse(a.result.account)}async activate(e){return this._updateStatus(e,"active")}async freeze(e){return this._updateStatus(e,"frozen")}async disable(e){return this._updateStatus(e,"disabled")}async _updateStatus(e,t){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${e}`,body:{status:t}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(e){return mapVirtualAccountFromWire(e)}}class AccountsClient extends sdk_core_namespaceObject.BaseClient{bancolombia;breb;card;externalUsBank;polygon;us;us2;virtual;constructor(e){super(e),this.bancolombia=new BancolombiaClient(this.httpClient),this.breb=new BrebClient(this.httpClient),this.card=new CardClient(this.httpClient),this.externalUsBank=new ExternalUsBankClient(this.httpClient),this.polygon=new PolygonClient(this.httpClient),this.us=new UsClient(this.httpClient),this.us2=new Us2Client(this.httpClient),this.virtual=new VirtualClient(this.httpClient)}async balance(e){if(!e?.trim())throw Error("Account URN is required");return(await this.httpClient.request({method:"GET",path:`/api/accounts/${e}/balance`})).balance}async balances(){return(await this.httpClient.request({method:"GET",path:"/api/accounts/balances"})).balance}async get(e){if(!e?.trim())throw Error("Account URN is required");let t=await this.httpClient.request({method:"GET",path:`/api/accounts/${e}`});return this._mapByMedium(t.account)}async list(e){let t=e?.holderUrn||this.httpClient.urn,a=new URLSearchParams;t&&a.append("holder_urn",t);let r=a.toString(),n=r?`/api/accounts?${r}`:"/api/accounts";return{accounts:(await this.httpClient.request({method:"GET",path:n})).accounts.map(e=>this._mapByMedium(e))}}async transfer(e,t){let a=e.asset||"DUSD/6";if(!(0,sdk_core_namespaceObject.isSupportedAsset)(a))throw Error(`Invalid asset type "${a}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let r={destination_account_urn:e.destinationUrn,amount:e.amount,asset:a,metadata:e.metadata},n=await this.httpClient.request({method:"POST",path:`/api/accounts/${e.sourceUrn}/transfer`,body:r,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0});return{queueId:n.result.queue_id,status:n.result.status,message:n.result.message}}async batchTransfer(e,t){if(!e.operations||0===e.operations.length)throw Error("At least one operation is required");if(!e.reference)throw Error("Batch reference is required");for(let t of e.operations)if(!(0,sdk_core_namespaceObject.isSupportedAsset)(t.asset))throw Error(`Invalid asset type "${t.asset}" in operation "${t.reference}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let a={operations:e.operations.map(e=>({from_account_urn:e.fromUrn,to_account_urn:e.toUrn,reference:e.reference,amount:e.amount,asset:e.asset,metadata:e.metadata})),reference:e.reference,metadata:e.metadata,webhook_url:e.webhookUrl},r=await this.httpClient.request({method:"POST",path:"/api/accounts/batch/transfer",body:a,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0});return{chunks:r.result.chunks.map(e=>({queueId:e.queue_id,status:e.status,message:e.message})),totalOperations:r.result.total_operations,totalChunks:r.result.total_chunks}}async movements(e){if(!e.urn)throw Error("Account URN is required");let t=e.asset||"DUSD/6";if(!(0,sdk_core_namespaceObject.isSupportedAsset)(t))throw Error(`Invalid asset type "${t}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let a=new URLSearchParams;a.set("asset",t),void 0!==e.limit&&a.set("limit",e.limit.toString()),e.before&&a.set("before",e.before),e.after&&a.set("after",e.after),e.reference&&a.set("reference",e.reference),e.direction&&a.set("direction",e.direction),void 0!==e.collapsed_view&&a.set("collapsed_view",String(e.collapsed_view)),e.pocket&&a.set("pocket",e.pocket),e.next&&a.set("next",e.next);let r=`/api/accounts/${e.urn}/movements?${a.toString()}`,n=await this.httpClient.request({method:"GET",path:r});return{data:n.data.map(e=>({amount:e.amount,asset:e.asset,fromAccountId:e.from_account_id,toAccountId:e.to_account_id,direction:e.direction,type:e.type,reference:e.reference,status:e.status,railName:e.rail_name,details:e.details,createdAt:e.created_at})),pageSize:n.page_size,hasMore:n.has_more,next:n.next}}async transactions(e={}){let t=e.asset||"DUSD/6";if(!(0,sdk_core_namespaceObject.isSupportedAsset)(t))throw Error(`Invalid asset type "${t}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let a=new URLSearchParams;a.set("asset",t),void 0!==e.limit&&a.set("limit",e.limit.toString()),e.before&&a.set("before",e.before),e.after&&a.set("after",e.after),e.reference&&a.set("reference",e.reference),e.direction&&a.set("direction",e.direction),void 0!==e.collapsed_view&&a.set("collapsed_view",String(e.collapsed_view)),e.pocket&&a.set("pocket",e.pocket),e.next&&a.set("next",e.next);let r=await this.httpClient.request({method:"GET",path:`/api/accounts/transactions?${a.toString()}`});return{data:r.data.map(e=>({amount:e.amount,asset:e.asset,fromAccountId:e.from_account_id,toAccountId:e.to_account_id,direction:e.direction,reference:e.reference,status:e.status,railName:e.rail_name,details:e.details??{},createdAt:e.created_at,type:e.type})),pageSize:r.page_size,hasMore:r.has_more,next:r.next}}_mapByMedium(e){switch(e.medium){case"card":return mapCardAccountFromWire(e);case"virtual":return mapVirtualAccountFromWire(e);case"polygon":return mapPolygonAccountFromWire(e);case"bancolombia":return mapBancolombiaAccountFromWire(e);case"breb":return mapBrebAccountFromWire(e);case"external-us-bank":return mapExternalUsBankAccountFromWire(e);case"us-account":return mapUsAccountFromWire(e);case"us2-account":return mapUs2AccountFromWire(e);default:throw Error(`Unknown account medium: ${e.medium}`)}}}for(var __rspack_i in exports.AccountsClient=__webpack_exports__.AccountsClient,exports.BancolombiaClient=__webpack_exports__.BancolombiaClient,exports.BrebClient=__webpack_exports__.BrebClient,exports.CardClient=__webpack_exports__.CardClient,exports.ExternalUsBankClient=__webpack_exports__.ExternalUsBankClient,exports.PolygonClient=__webpack_exports__.PolygonClient,exports.Us2Client=__webpack_exports__.Us2Client,exports.UsClient=__webpack_exports__.UsClient,exports.VirtualClient=__webpack_exports__.VirtualClient,exports.mapBancolombiaAccountFromWire=__webpack_exports__.mapBancolombiaAccountFromWire,exports.mapBrebAccountFromWire=__webpack_exports__.mapBrebAccountFromWire,exports.mapCardAccountFromWire=__webpack_exports__.mapCardAccountFromWire,exports.mapExternalUsBankAccountFromWire=__webpack_exports__.mapExternalUsBankAccountFromWire,exports.mapPolygonAccountFromWire=__webpack_exports__.mapPolygonAccountFromWire,exports.mapUs2AccountFromWire=__webpack_exports__.mapUs2AccountFromWire,exports.mapUsAccountFromWire=__webpack_exports__.mapUsAccountFromWire,exports.mapVirtualAccountFromWire=__webpack_exports__.mapVirtualAccountFromWire,__webpack_exports__)-1===["AccountsClient","BancolombiaClient","BrebClient","CardClient","ExternalUsBankClient","PolygonClient","Us2Client","UsClient","VirtualClient","mapBancolombiaAccountFromWire","mapBrebAccountFromWire","mapCardAccountFromWire","mapExternalUsBankAccountFromWire","mapPolygonAccountFromWire","mapUs2AccountFromWire","mapUsAccountFromWire","mapVirtualAccountFromWire"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
|
package/dist/index.d.ts
CHANGED
|
@@ -5,10 +5,14 @@ export * from './breb/breb-client';
|
|
|
5
5
|
export * from './breb/types';
|
|
6
6
|
export * from './card/card-client';
|
|
7
7
|
export * from './card/types';
|
|
8
|
+
export * from './external-us-bank/external-us-bank-client';
|
|
9
|
+
export * from './external-us-bank/types';
|
|
8
10
|
export * from './polygon/polygon-client';
|
|
9
11
|
export * from './polygon/types';
|
|
10
12
|
export * from './types';
|
|
11
13
|
export * from './us/types';
|
|
12
14
|
export * from './us/us-client';
|
|
15
|
+
export * from './us2/types';
|
|
16
|
+
export * from './us2/us2-client';
|
|
13
17
|
export * from './virtual/types';
|
|
14
18
|
export * from './virtual/virtual-client';
|
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 o(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 i 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:o(a.result.account),error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async resolveKey(t){try{if(!t.key?.trim())throw Error("BRE-B key value is required");return{data:(await this.httpClient.request({method:"POST",path:"/api/mediums/breb/resolve-key",body:{key_type:t.keyType,key:t.key}})).result,error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async decodeQr(t){try{var e;if(!t.qrCodeData?.trim())throw Error("BRE-B QR code data is required");return{data:{amount:(e=(await this.httpClient.request({method:"POST",path:"/api/mediums/breb/decode-qr",body:{qr_code_data:t.qrCodeData}})).result).amount,additionalInfo:e.additional_info?{transactionPurpose:e.additional_info.transaction_purpose,terminalLabel:e.additional_info.terminal_label,invoiceNumber:e.additional_info.invoice_number,mobilePhoneNumber:e.additional_info.mobile_phone_number,storeLabel:e.additional_info.store_label,loyaltyLabel:e.additional_info.loyalty_label,referenceLabel:e.additional_info.reference_label,customerLabel:e.additional_info.customer_label,customerInfo:e.additional_info.customer_info,channelPresentation:e.additional_info.channel_presentation}:null,key:e.key?{keyType:e.key.key_type,keyValue:e.key.key_value}:null,qrCodeData:e.qr_code_data,status:e.status,acquirerNetworkIdentifier:e.acquirer_network_identifier,merchant:e.merchant?{merchantCategoryCode:e.merchant.merchant_category_code,merchantCountry:e.merchant.merchant_country,merchantName:e.merchant.merchant_name,merchantCity:e.merchant.merchant_city,merchantPostCode:e.merchant.merchant_post_code}:null,channel:e.channel,qrCodeReference:e.qr_code_reference,type:e.type,resolutionId:e.resolution_id,resolution:e.resolution},error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async deleteKey(t){try{if(!t.accountUrn?.trim())throw Error("BRE-B account URN is required");let e=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(t.accountUrn)}`,body:{status:"deleted"}});return{data:{deleted:!0,accountUrn:e.result.account.urn,keyId:e.result.account.details.id,status:"deleted"},error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async suspendKey(t){try{if(!t.accountUrn?.trim())throw Error("BRE-B account URN is required");let e=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(t.accountUrn)}`,body:{status:"frozen"}});return{data:{accountUrn:e.result.account.urn,keyId:e.result.account.details.id,keyStatus:e.result.account.details.status,status:"frozen"},error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async activateKey(t){try{if(!t.accountUrn?.trim())throw Error("BRE-B account URN is required");let e=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(t.accountUrn)}`,body:{status:"active"}});return{data:{accountUrn:e.result.account.urn,keyId:e.result.account.details.id,keyStatus:e.result.account.details.status,status:"active"},error:null}}catch(t){return{data:null,error:this.mapError(t)}}}}function c(t){return{urn:t.urn,id:t.id,lastFour:t.details.card_last_four,productType:t.details.card_product_type,status:t.status,cardType:t.details.card_type,detailsUrl:t.details.card_url_details,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}}class u extends t{async create(t={},e){let a={holder_urn:t?.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{create:{card_type:"VIRTUAL"}},metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/card",body:a}),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(),o=`/api/accounts/${t.urn}/movements${s?`?${s}`:""}`,i=await this.httpClient.request({method:"GET",path:o});return{data:i.data,pageSize:i.page_size,hasMore:i.has_more,next:i.next}}async balance(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 c(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}),o=this._mapAccountResponse(s.result.account);return e?.waitLedger?this._waitForActiveStatus(o.urn,e.timeout||6e4):o}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 y extends t{bancolombia;breb;card;polygon;us;virtual;constructor(t){super(t),this.bancolombia=new s(this.httpClient),this.breb=new i(this.httpClient),this.card=new u(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()}`,o=await this.httpClient.request({method:"GET",path:s});return{data:o.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:o.page_size,hasMore:o.has_more,next:o.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 c(t);case"virtual":return m(t);case"polygon":return d(t);case"bancolombia":return n(t);case"breb":return o(t);case"us-account":return p(t);default:throw Error(`Unknown account medium: ${t.medium}`)}}}export{y as AccountsClient,s as BancolombiaClient,i as BrebClient,u as CardClient,l as PolygonClient,h as UsClient,_ as VirtualClient,n as mapBancolombiaAccountFromWire,o as mapBrebAccountFromWire,c 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,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(n.urn,e.timeout||6e4):n}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async updateName(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{metadata:{name:e}}});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return n(t)}}function i(t){return{id:t.id,urn:t.urn,ownerUrn:t.owner_urn,medium:"breb",remoteKeyId:t.details.remote_key_id,accountId:t.details.account_id,keyType:t.details.key.key_type,key:t.details.key.key_value,displayName:t.details.display_name??null,status:t.status,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,details:t.details,balance:"balance"in t&&t.balance?t.balance:void 0}}class o extends t{mapError(t){if(t instanceof e){let e=t.response;return{code:e?.extra_details?.provider_code??t.code??null,message:t.message}}return t instanceof Error?{code:null,message:t.message}:{code:null,message:"Unknown BRE-B error"}}async createKey(t){try{let e=this.httpClient.urn;if(!e?.trim())throw Error("Holder URN is required");if(!t.key?.trim())throw Error("BRE-B key value is required");let a=await this.httpClient.request({method:"POST",path:"/api/mediums/breb",body:{holder_urn:e,input:{key_type:t.keyType,key_value:t.key,display_name:t.displayName},webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,metadata:{source:"sdk-typescript",...t.metadata}}});return{data:i(a.result.account),error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async resolveKey(t){try{if(!t.key?.trim())throw Error("BRE-B key value is required");return{data:(await this.httpClient.request({method:"POST",path:"/api/mediums/breb/resolve-key",body:{key_type:t.keyType,key:t.key}})).result,error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async decodeQr(t){try{var e;if(!t.qrCodeData?.trim())throw Error("BRE-B QR code data is required");return{data:{amount:(e=(await this.httpClient.request({method:"POST",path:"/api/mediums/breb/decode-qr",body:{qr_code_data:t.qrCodeData}})).result).amount,additionalInfo:e.additional_info?{transactionPurpose:e.additional_info.transaction_purpose,terminalLabel:e.additional_info.terminal_label,invoiceNumber:e.additional_info.invoice_number,mobilePhoneNumber:e.additional_info.mobile_phone_number,storeLabel:e.additional_info.store_label,loyaltyLabel:e.additional_info.loyalty_label,referenceLabel:e.additional_info.reference_label,customerLabel:e.additional_info.customer_label,customerInfo:e.additional_info.customer_info,channelPresentation:e.additional_info.channel_presentation}:null,key:e.key?{keyType:e.key.key_type,keyValue:e.key.key_value}:null,qrCodeData:e.qr_code_data,status:e.status,acquirerNetworkIdentifier:e.acquirer_network_identifier,merchant:e.merchant?{merchantCategoryCode:e.merchant.merchant_category_code,merchantCountry:e.merchant.merchant_country,merchantName:e.merchant.merchant_name,merchantCity:e.merchant.merchant_city,merchantPostCode:e.merchant.merchant_post_code}:null,channel:e.channel,qrCodeReference:e.qr_code_reference,type:e.type,resolutionId:e.resolution_id,resolution:e.resolution},error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async deleteKey(t){try{if(!t.accountUrn?.trim())throw Error("BRE-B account URN is required");let e=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(t.accountUrn)}`,body:{status:"deleted"}});return{data:{deleted:!0,accountUrn:e.result.account.urn,keyId:e.result.account.details.id,status:"deleted"},error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async suspendKey(t){try{if(!t.accountUrn?.trim())throw Error("BRE-B account URN is required");let e=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(t.accountUrn)}`,body:{status:"frozen"}});return{data:{accountUrn:e.result.account.urn,keyId:e.result.account.details.id,keyStatus:e.result.account.details.status,status:"frozen"},error:null}}catch(t){return{data:null,error:this.mapError(t)}}}async activateKey(t){try{if(!t.accountUrn?.trim())throw Error("BRE-B account URN is required");let e=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${encodeURIComponent(t.accountUrn)}`,body:{status:"active"}});return{data:{accountUrn:e.result.account.urn,keyId:e.result.account.details.id,keyStatus:e.result.account.details.status,status:"active"},error:null}}catch(t){return{data:null,error:this.mapError(t)}}}}function c(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 d extends t{async create(t={},e){let a={holder_urn:t?.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{create:{card_type:"VIRTUAL"}},metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/card",body:a,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(n.urn,e.timeout||6e4):n}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","card"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({urn:t.urn,id:t.id,lastFour:t.details.card_last_four,productType:t.details.card_product_type,status:t.status,cardType:t.details.card_type,detailsUrl:t.details.card_url_details,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}))}}async movements(t){let e=new URLSearchParams,n=t.asset||"DUSD/6";if(!r(n))throw Error(`Invalid asset type "${n}". Supported assets: ${a.join(", ")}`);e.set("asset",n),void 0!==t.limit&&e.set("limit",t.limit.toString()),t.before&&e.set("before",t.before),t.after&&e.set("after",t.after),t.reference&&e.set("reference",t.reference),t.direction&&e.set("direction",t.direction),void 0!==t.collapsed_view&&e.set("collapsed_view",String(t.collapsed_view)),t.pocket&&e.set("pocket",t.pocket),t.next&&e.set("next",t.next);let s=e.toString(),i=`/api/accounts/${t.urn}/movements${s?`?${s}`:""}`,o=await this.httpClient.request({method:"GET",path:i});return{data:o.data,pageSize:o.page_size,hasMore:o.has_more,next:o.next}}async balance(t){return(await this.httpClient.request({method:"GET",path:`/api/accounts/${t.urn}/balance`})).balance}async update(t){let e={...t.metadata&&{metadata:t.metadata},...t.status&&{status:t.status},...t.webhookUrl&&{webhook_url:t.webhookUrl},...t.ledgerId&&{ledger_account_id:t.ledgerId}},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async updateName(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{metadata:{name:e}}});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async tokenizeApple(t,e){let a={certificates:e.certificates,nonce:e.nonce,nonce_signature:e.nonceSignature},r=await this.httpClient.request({method:"POST",path:`/api/accounts/${t}/tokenize/apple`,body:a});return{activationData:r.result.tokenization.activation_data,encryptedPassData:r.result.tokenization.encrypted_pass_data,ephemeralPublicKey:r.result.tokenization.ephemeral_public_key}}async tokenizeGoogle(t,e){let a={device_id:e.deviceId,wallet_account_id:e.walletAccountId};return{opc:(await this.httpClient.request({method:"POST",path:`/api/accounts/${t}/tokenize/google`,body:a})).result.tokenization.opc}}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return c(t)}}function u(t){return{urn:t.urn,id:t.id,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance,details:{id:t.details.id,linkStatus:t.details.link_status,braleAccountId:t.details.brale_account_id,braleAddressId:t.details.brale_address_id,linkToken:t.details.link_token,linkTokenExpiration:t.details.link_token_expiration,linkUrl:t.details.link_url,bankAccountLast4:t.details.bank_account_last4,bankName:t.details.bank_name,failureReason:t.details.failure_reason}}}class l extends t{async create(t,e){let a={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{label:t.label},metadata:{source:"sdk-typescript",...t.metadata},return_url:t.returnUrl,state:t.state};return u((await this.httpClient.request({method:"POST",path:"/api/mediums/external-us-bank",body:a})).result.account)}async exchangePublicToken(t){let e={input:{public_token:t.publicToken}};return u((await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e})).result.account)}}function p(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 h extends t{async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","polygon"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({...this._mapAccountResponse(t),balance:t.balance}))}}async create(t={},e){let a={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{},metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/polygon",body:a,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(n.urn,e.timeout||6e4):n}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return p(t)}}function m(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 _ extends t{async getTosLink(t){let e=new URLSearchParams({redirect_uri:t.redirectUri}),a=(await this.httpClient.request({method:"POST",path:`/api/mediums/us-account/tos-link?${e.toString()}`})).result.url;try{let e=new URL(a);e.searchParams.has("redirect_uri")||(e.searchParams.set("redirect_uri",t.redirectUri),a=e.toString())}catch{let e=a.includes("?")?"&":"?";/[?&]redirect_uri=/.test(a)||(a=`${a}${e}redirect_uri=${encodeURIComponent(t.redirectUri)}`)}return{url:a}}async create(t,e){let a={street_line_1:t.address.streetLine1,street_line_2:t.address.streetLine2,city:t.address.city,state:t.address.state,postal_code:t.address.postalCode,country:t.address.country},r={type:t.type,first_name:t.firstName,middle_name:t.middleName,last_name:t.lastName,email:t.email,phone:t.phone,address:a,birth_date:t.birthDate,tax_identification_number:t.taxIdentificationNumber,gov_id_country:t.govIdCountry,gov_id_image_front:t.govIdImageFront,signed_agreement_id:t.signedAgreementId},n={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:r,metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},s=await this.httpClient.request({method:"POST",path:"/api/mediums/us-account",body:n,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0}),i=this._mapAccountResponse(s.result.account);return e?.waitLedger?this._waitForActiveStatus(i.urn,e.timeout||6e4):i}async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","us-account"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({urn:t.urn,id:t.id,type:t.details.type,firstName:t.details.first_name,middleName:t.details.middle_name,lastName:t.details.last_name,email:t.details.email,phone:t.details.phone,address:{streetLine1:t.details.address.street_line_1,streetLine2:t.details.address.street_line_2,city:t.details.address.city,state:t.details.address.state,postalCode:t.details.address.postal_code,country:t.details.address.country},birthDate:t.details.birth_date,accountNumber:t.details.account_number,routingNumber:t.details.routing_number,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return m(t)}}function y(t){return{urn:t.urn,id:t.id,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance,details:{id:t.details.id,userId:t.details.user_id,virtualAccountId:t.details.virtual_account_id,type:t.details.type,currency:t.details.currency}}}class w extends t{async create(t,e){let a={type:t.type,email:t.email,phone:t.phone,proof_of_address:t.proofOfAddress,business_formation_document:t.businessFormationDocument,tax_id:t.taxId,address:t.address?{street:t.address.street,city:t.address.city,state:t.address.state,postal_code:t.address.postalCode,country:t.address.country}:void 0},r={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:a,metadata:{source:"sdk-typescript",...t.metadata}};return y((await this.httpClient.request({method:"POST",path:"/api/mediums/us2-account",body:r})).result.account)}async list(t={}){let e=t.holderUrn||this.httpClient.urn,a=new URLSearchParams;return a.append("medium","us2-account"),e&&a.append("holder_urn",e),t.urn&&a.append("urn",t.urn),{accounts:(await this.httpClient.request({method:"GET",path:`/api/accounts?${a.toString()}`})).accounts.map(t=>y(t))}}}function b(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 f extends t{async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","virtual"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({...this._mapAccountResponse(t),balance:t.balance}))}}async create(t,e){let a={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{},metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/virtual",body:a,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0}),n=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(n.urn,e.timeout||6e4):n}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return b(t)}}class k extends t{bancolombia;breb;card;externalUsBank;polygon;us;us2;virtual;constructor(t){super(t),this.bancolombia=new s(this.httpClient),this.breb=new o(this.httpClient),this.card=new d(this.httpClient),this.externalUsBank=new l(this.httpClient),this.polygon=new h(this.httpClient),this.us=new _(this.httpClient),this.us2=new w(this.httpClient),this.virtual=new f(this.httpClient)}async balance(t){if(!t?.trim())throw Error("Account URN is required");return(await this.httpClient.request({method:"GET",path:`/api/accounts/${t}/balance`})).balance}async balances(){return(await this.httpClient.request({method:"GET",path:"/api/accounts/balances"})).balance}async get(t){if(!t?.trim())throw Error("Account URN is required");let e=await this.httpClient.request({method:"GET",path:`/api/accounts/${t}`});return this._mapByMedium(e.account)}async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;e&&a.append("holder_urn",e);let r=a.toString(),n=r?`/api/accounts?${r}`:"/api/accounts";return{accounts:(await this.httpClient.request({method:"GET",path:n})).accounts.map(t=>this._mapByMedium(t))}}async transfer(t,e){let n=t.asset||"DUSD/6";if(!r(n))throw Error(`Invalid asset type "${n}". Supported assets: ${a.join(", ")}`);let s={destination_account_urn:t.destinationUrn,amount:t.amount,asset:n,metadata:t.metadata},i=await this.httpClient.request({method:"POST",path:`/api/accounts/${t.sourceUrn}/transfer`,body:s,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0});return{queueId:i.result.queue_id,status:i.result.status,message:i.result.message}}async batchTransfer(t,e){if(!t.operations||0===t.operations.length)throw Error("At least one operation is required");if(!t.reference)throw Error("Batch reference is required");for(let e of t.operations)if(!r(e.asset))throw Error(`Invalid asset type "${e.asset}" in operation "${e.reference}". Supported assets: ${a.join(", ")}`);let n={operations:t.operations.map(t=>({from_account_urn:t.fromUrn,to_account_urn:t.toUrn,reference:t.reference,amount:t.amount,asset:t.asset,metadata:t.metadata})),reference:t.reference,metadata:t.metadata,webhook_url:t.webhookUrl},s=await this.httpClient.request({method:"POST",path:"/api/accounts/batch/transfer",body:n,headers:e?.idempotencyKey?{"Idempotency-Key":e.idempotencyKey}:void 0});return{chunks:s.result.chunks.map(t=>({queueId:t.queue_id,status:t.status,message:t.message})),totalOperations:s.result.total_operations,totalChunks:s.result.total_chunks}}async movements(t){if(!t.urn)throw Error("Account URN is required");let e=t.asset||"DUSD/6";if(!r(e))throw Error(`Invalid asset type "${e}". Supported assets: ${a.join(", ")}`);let n=new URLSearchParams;n.set("asset",e),void 0!==t.limit&&n.set("limit",t.limit.toString()),t.before&&n.set("before",t.before),t.after&&n.set("after",t.after),t.reference&&n.set("reference",t.reference),t.direction&&n.set("direction",t.direction),void 0!==t.collapsed_view&&n.set("collapsed_view",String(t.collapsed_view)),t.pocket&&n.set("pocket",t.pocket),t.next&&n.set("next",t.next);let s=`/api/accounts/${t.urn}/movements?${n.toString()}`,i=await this.httpClient.request({method:"GET",path:s});return{data:i.data.map(t=>({amount:t.amount,asset:t.asset,fromAccountId:t.from_account_id,toAccountId:t.to_account_id,direction:t.direction,type:t.type,reference:t.reference,status:t.status,railName:t.rail_name,details:t.details,createdAt:t.created_at})),pageSize:i.page_size,hasMore:i.has_more,next:i.next}}async transactions(t={}){let e=t.asset||"DUSD/6";if(!r(e))throw Error(`Invalid asset type "${e}". Supported assets: ${a.join(", ")}`);let n=new URLSearchParams;n.set("asset",e),void 0!==t.limit&&n.set("limit",t.limit.toString()),t.before&&n.set("before",t.before),t.after&&n.set("after",t.after),t.reference&&n.set("reference",t.reference),t.direction&&n.set("direction",t.direction),void 0!==t.collapsed_view&&n.set("collapsed_view",String(t.collapsed_view)),t.pocket&&n.set("pocket",t.pocket),t.next&&n.set("next",t.next);let s=await this.httpClient.request({method:"GET",path:`/api/accounts/transactions?${n.toString()}`});return{data:s.data.map(t=>({amount:t.amount,asset:t.asset,fromAccountId:t.from_account_id,toAccountId:t.to_account_id,direction:t.direction,reference:t.reference,status:t.status,railName:t.rail_name,details:t.details??{},createdAt:t.created_at,type:t.type})),pageSize:s.page_size,hasMore:s.has_more,next:s.next}}_mapByMedium(t){switch(t.medium){case"card":return c(t);case"virtual":return b(t);case"polygon":return p(t);case"bancolombia":return n(t);case"breb":return i(t);case"external-us-bank":return u(t);case"us-account":return m(t);case"us2-account":return y(t);default:throw Error(`Unknown account medium: ${t.medium}`)}}}export{k as AccountsClient,s as BancolombiaClient,o as BrebClient,d as CardClient,l as ExternalUsBankClient,h as PolygonClient,w as Us2Client,_ as UsClient,f as VirtualClient,n as mapBancolombiaAccountFromWire,i as mapBrebAccountFromWire,c as mapCardAccountFromWire,u as mapExternalUsBankAccountFromWire,p as mapPolygonAccountFromWire,y as mapUs2AccountFromWire,m as mapUsAccountFromWire,b as mapVirtualAccountFromWire};
|
|
@@ -16,7 +16,7 @@ export type AccountStatus = 'active' | 'disabled' | 'frozen' | 'deleted' | 'crea
|
|
|
16
16
|
export interface Account<TDetails = unknown> {
|
|
17
17
|
id: string;
|
|
18
18
|
urn: string;
|
|
19
|
-
medium: 'bancolombia' | 'breb' | 'card' | 'virtual' | 'us-account' | 'polygon';
|
|
19
|
+
medium: 'bancolombia' | 'breb' | 'card' | 'external-us-bank' | 'virtual' | 'us2-account' | 'us-account' | 'polygon';
|
|
20
20
|
details: TDetails;
|
|
21
21
|
ledger_account_id: string;
|
|
22
22
|
status: AccountStatus;
|
|
@@ -41,6 +41,18 @@ export interface CreateAccountRequest<TInput = unknown> {
|
|
|
41
41
|
input: TInput;
|
|
42
42
|
metadata?: Record<string, unknown>;
|
|
43
43
|
webhook_url?: string;
|
|
44
|
+
/**
|
|
45
|
+
* URL the user is redirected to after a browser-side link flow finishes.
|
|
46
|
+
* Currently consumed only by the `external-us-bank` medium's hosted Plaid
|
|
47
|
+
* Link page. Origin must be in the server's
|
|
48
|
+
* `PLAID_LINK_RETURN_URL_ALLOWLIST`.
|
|
49
|
+
*/
|
|
50
|
+
return_url?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Opaque caller-provided correlator forwarded back through `return_url`
|
|
53
|
+
* (max 256 characters). Echoed as the `state` query parameter on redirect.
|
|
54
|
+
*/
|
|
55
|
+
state?: string;
|
|
44
56
|
}
|
|
45
57
|
/**
|
|
46
58
|
* @internal
|
|
@@ -187,6 +199,59 @@ export interface UsDetails {
|
|
|
187
199
|
account_number?: string;
|
|
188
200
|
routing_number?: string;
|
|
189
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* @internal
|
|
204
|
+
* US2 account input for creation
|
|
205
|
+
*/
|
|
206
|
+
export interface CreateUs2AccountInput {
|
|
207
|
+
type: 'individual' | 'business';
|
|
208
|
+
email: string;
|
|
209
|
+
phone?: string;
|
|
210
|
+
proof_of_address?: string;
|
|
211
|
+
business_formation_document?: string;
|
|
212
|
+
tax_id?: string;
|
|
213
|
+
address?: {
|
|
214
|
+
street?: string;
|
|
215
|
+
city?: string;
|
|
216
|
+
state?: string;
|
|
217
|
+
postal_code?: string;
|
|
218
|
+
country?: string;
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* @internal
|
|
223
|
+
* US2 account details from API
|
|
224
|
+
*/
|
|
225
|
+
export interface Us2Details {
|
|
226
|
+
id: string;
|
|
227
|
+
user_id: string;
|
|
228
|
+
virtual_account_id: string;
|
|
229
|
+
type: string;
|
|
230
|
+
currency: string;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* @internal
|
|
234
|
+
* External US bank linkage details (Brale/Plaid).
|
|
235
|
+
*/
|
|
236
|
+
export interface ExternalUsBankDetails {
|
|
237
|
+
id: string;
|
|
238
|
+
link_status: 'pending_link' | 'active' | 'link_failed' | 'closed';
|
|
239
|
+
brale_account_id?: string;
|
|
240
|
+
brale_address_id?: string;
|
|
241
|
+
link_token?: string;
|
|
242
|
+
/** ISO 8601 expiration of `link_token`, as reported by Brale. */
|
|
243
|
+
link_token_expiration?: string;
|
|
244
|
+
/**
|
|
245
|
+
* Fully-qualified URL of the mediums-hosted Plaid Link page. Present when
|
|
246
|
+
* the server has minted a short-lived `plaid-link` JWT for this pending
|
|
247
|
+
* account. Open it in a browser to complete linking without embedding
|
|
248
|
+
* Plaid Link in the caller's frontend.
|
|
249
|
+
*/
|
|
250
|
+
link_url?: string;
|
|
251
|
+
bank_account_last4?: string;
|
|
252
|
+
bank_name?: string;
|
|
253
|
+
failure_reason?: string;
|
|
254
|
+
}
|
|
190
255
|
/**
|
|
191
256
|
* @internal
|
|
192
257
|
* TOS link response
|
|
@@ -48,8 +48,11 @@ export declare class PolygonClient extends BaseClient {
|
|
|
48
48
|
* // Create without waiting
|
|
49
49
|
* const account = await bloque.accounts.polygon.create();
|
|
50
50
|
*
|
|
51
|
-
* // Create and wait for active status
|
|
52
|
-
* const account = await bloque.accounts.polygon.create({}, {
|
|
51
|
+
* // Create and wait for active status with explicit idempotency key
|
|
52
|
+
* const account = await bloque.accounts.polygon.create({}, {
|
|
53
|
+
* waitLedger: true,
|
|
54
|
+
* idempotencyKey: 'create-polygon-main-wallet'
|
|
55
|
+
* });
|
|
53
56
|
* ```
|
|
54
57
|
*/
|
|
55
58
|
create(params?: CreatePolygonAccountParams, options?: CreateAccountOptions): Promise<PolygonAccount>;
|
package/dist/types.d.ts
CHANGED
|
@@ -19,6 +19,10 @@ export interface CreateAccountOptions {
|
|
|
19
19
|
* @default 60000 (60 seconds)
|
|
20
20
|
*/
|
|
21
21
|
timeout?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Custom idempotency key used for account creation POST requests.
|
|
24
|
+
*/
|
|
25
|
+
idempotencyKey?: string;
|
|
22
26
|
}
|
|
23
27
|
/**
|
|
24
28
|
* Parameters for transferring funds between accounts
|
|
@@ -50,6 +54,12 @@ export interface TransferParams {
|
|
|
50
54
|
*/
|
|
51
55
|
metadata?: Record<string, unknown>;
|
|
52
56
|
}
|
|
57
|
+
export interface TransferOptions {
|
|
58
|
+
/**
|
|
59
|
+
* Optional custom idempotency key sent as `Idempotency-Key` header.
|
|
60
|
+
*/
|
|
61
|
+
idempotencyKey?: string;
|
|
62
|
+
}
|
|
53
63
|
/**
|
|
54
64
|
* Result of a transfer operation
|
|
55
65
|
*/
|
|
@@ -117,6 +127,12 @@ export interface BatchTransferParams {
|
|
|
117
127
|
*/
|
|
118
128
|
webhookUrl?: string;
|
|
119
129
|
}
|
|
130
|
+
export interface BatchTransferOptions {
|
|
131
|
+
/**
|
|
132
|
+
* Optional custom idempotency key sent as `Idempotency-Key` header.
|
|
133
|
+
*/
|
|
134
|
+
idempotencyKey?: string;
|
|
135
|
+
}
|
|
120
136
|
/**
|
|
121
137
|
* Result of a single chunk in a batch transfer
|
|
122
138
|
*/
|
|
@@ -146,7 +162,7 @@ export type AccountStatus = 'active' | 'disabled' | 'frozen' | 'deleted' | 'crea
|
|
|
146
162
|
/**
|
|
147
163
|
* Account medium/type
|
|
148
164
|
*/
|
|
149
|
-
export type AccountMedium = 'bancolombia' | 'breb' | 'card' | 'virtual' | 'polygon' | 'us-account';
|
|
165
|
+
export type AccountMedium = 'bancolombia' | 'breb' | 'card' | 'external-us-bank' | 'virtual' | 'polygon' | 'us2-account' | 'us-account';
|
|
150
166
|
/**
|
|
151
167
|
* Token balance information
|
|
152
168
|
*/
|
|
@@ -230,7 +246,7 @@ export interface ListAccountsParams {
|
|
|
230
246
|
*/
|
|
231
247
|
export interface ListAccountsResult {
|
|
232
248
|
/** Array of medium-specific mapped accounts */
|
|
233
|
-
accounts: Array<import('./card/types').CardAccount | import('./virtual/types').VirtualAccount | import('./polygon/types').PolygonAccount | import('./bancolombia/types').BancolombiaAccount | import('./breb/types').BrebKeyAccount | import('./us/types').UsAccount>;
|
|
249
|
+
accounts: Array<import('./card/types').CardAccount | import('./virtual/types').VirtualAccount | import('./polygon/types').PolygonAccount | import('./bancolombia/types').BancolombiaAccount | import('./breb/types').BrebKeyAccount | import('./external-us-bank/types').ExternalUsBankAccount | import('./us2/types').Us2Account | import('./us/types').UsAccount>;
|
|
234
250
|
}
|
|
235
251
|
/**
|
|
236
252
|
* Transaction type (deposit, withdraw, transfer)
|
package/dist/us/us-client.d.ts
CHANGED
|
@@ -69,10 +69,13 @@ export declare class UsClient extends BaseClient {
|
|
|
69
69
|
* signedAgreementId: '0d139f8e-14b0-4540-92ba-4e66c619b533'
|
|
70
70
|
* });
|
|
71
71
|
*
|
|
72
|
-
* // Create and wait for active status
|
|
72
|
+
* // Create and wait for active status with explicit idempotency key
|
|
73
73
|
* const account = await bloque.accounts.us.create({
|
|
74
74
|
* // ... params
|
|
75
|
-
* }, {
|
|
75
|
+
* }, {
|
|
76
|
+
* waitLedger: true,
|
|
77
|
+
* idempotencyKey: 'create-us-account-robert-johnson'
|
|
78
|
+
* });
|
|
76
79
|
* ```
|
|
77
80
|
*/
|
|
78
81
|
create(params: CreateUsAccountParams, options?: CreateAccountOptions): Promise<UsAccount>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { AccountStatus, TokenBalance } from '../types';
|
|
2
|
+
export interface Us2AccountDetails {
|
|
3
|
+
id: string;
|
|
4
|
+
userId: string;
|
|
5
|
+
virtualAccountId: string;
|
|
6
|
+
type: string;
|
|
7
|
+
currency: string;
|
|
8
|
+
}
|
|
9
|
+
export interface Us2Account {
|
|
10
|
+
urn: string;
|
|
11
|
+
id: string;
|
|
12
|
+
status: AccountStatus;
|
|
13
|
+
ownerUrn: string;
|
|
14
|
+
ledgerId: string;
|
|
15
|
+
webhookUrl: string | null;
|
|
16
|
+
metadata?: Record<string, unknown>;
|
|
17
|
+
createdAt: string;
|
|
18
|
+
updatedAt: string;
|
|
19
|
+
balance: Record<string, TokenBalance>;
|
|
20
|
+
details: Us2AccountDetails;
|
|
21
|
+
}
|
|
22
|
+
export interface CreateUs2AccountAddress {
|
|
23
|
+
street?: string;
|
|
24
|
+
city?: string;
|
|
25
|
+
state?: string;
|
|
26
|
+
postalCode?: string;
|
|
27
|
+
country?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface CreateUs2AccountParams {
|
|
30
|
+
holderUrn?: string;
|
|
31
|
+
webhookUrl?: string;
|
|
32
|
+
ledgerId?: string;
|
|
33
|
+
metadata?: Record<string, unknown>;
|
|
34
|
+
type: 'individual' | 'business';
|
|
35
|
+
email: string;
|
|
36
|
+
phone?: string;
|
|
37
|
+
proofOfAddress?: string;
|
|
38
|
+
businessFormationDocument?: string;
|
|
39
|
+
taxId?: string;
|
|
40
|
+
address?: CreateUs2AccountAddress;
|
|
41
|
+
}
|
|
42
|
+
export interface ListUs2AccountsParams {
|
|
43
|
+
holderUrn?: string;
|
|
44
|
+
urn?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface ListUs2AccountsResult {
|
|
47
|
+
accounts: Us2Account[];
|
|
48
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseClient } from '@bloque/sdk-core';
|
|
2
|
+
import type { AccountWithBalance, Us2Details } from '../internal/wire-types';
|
|
3
|
+
import type { CreateAccountOptions } from '../types';
|
|
4
|
+
import type { CreateUs2AccountParams, ListUs2AccountsParams, ListUs2AccountsResult, Us2Account } from './types';
|
|
5
|
+
export declare function mapUs2AccountFromWire(account: AccountWithBalance<Us2Details>): Us2Account;
|
|
6
|
+
export declare class Us2Client extends BaseClient {
|
|
7
|
+
create(params: CreateUs2AccountParams, _options?: CreateAccountOptions): Promise<Us2Account>;
|
|
8
|
+
list(params?: ListUs2AccountsParams): Promise<ListUs2AccountsResult>;
|
|
9
|
+
}
|
|
@@ -51,11 +51,14 @@ export declare class VirtualClient extends BaseClient {
|
|
|
51
51
|
* lastName: 'Doe'
|
|
52
52
|
* });
|
|
53
53
|
*
|
|
54
|
-
* // Create and wait for active status
|
|
54
|
+
* // Create and wait for active status with explicit idempotency key
|
|
55
55
|
* const account = await bloque.accounts.virtual.create({
|
|
56
56
|
* firstName: 'John',
|
|
57
57
|
* lastName: 'Doe'
|
|
58
|
-
* }, {
|
|
58
|
+
* }, {
|
|
59
|
+
* waitLedger: true,
|
|
60
|
+
* idempotencyKey: 'create-virtual-john-doe'
|
|
61
|
+
* });
|
|
59
62
|
* ```
|
|
60
63
|
*/
|
|
61
64
|
create(params: CreateVirtualAccountParams, options?: CreateAccountOptions): Promise<VirtualAccount>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bloque/sdk-accounts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bloque",
|
|
@@ -36,6 +36,6 @@
|
|
|
36
36
|
"node": ">=22"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@bloque/sdk-core": "0.1.
|
|
39
|
+
"@bloque/sdk-core": "0.1.6"
|
|
40
40
|
}
|
|
41
41
|
}
|