@bloque/sdk-accounts 0.0.35 → 0.0.36
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 +20 -8
- package/dist/card/card-client.d.ts +23 -5
- package/dist/card/types.d.ts +21 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/wire-types.d.ts +12 -3
- package/dist/types.d.ts +21 -2
- package/package.json +2 -2
|
@@ -6,7 +6,7 @@ import { CardClient } from './card/card-client';
|
|
|
6
6
|
import type { CardAccount, ListMovementsParams } from './card/types';
|
|
7
7
|
import { PolygonClient } from './polygon/polygon-client';
|
|
8
8
|
import type { PolygonAccount } from './polygon/types';
|
|
9
|
-
import type { BatchTransferParams, BatchTransferResult, ListAccountsParams, ListAccountsResult,
|
|
9
|
+
import type { BatchTransferParams, BatchTransferResult, ListAccountsParams, ListAccountsResult, ListMovementsResult, TokenBalance, TransferParams, TransferResult } from './types';
|
|
10
10
|
import type { UsAccount } from './us/types';
|
|
11
11
|
import { UsClient } from './us/us-client';
|
|
12
12
|
import type { VirtualAccount } from './virtual/types';
|
|
@@ -151,19 +151,21 @@ export declare class AccountsClient extends BaseClient {
|
|
|
151
151
|
* List account movements/transactions
|
|
152
152
|
*
|
|
153
153
|
* Retrieves transaction history for a specific account using its URN.
|
|
154
|
+
* Returns a paged result with data, pageSize, hasMore, and optional next token.
|
|
154
155
|
*
|
|
155
156
|
* @param params - Movement list parameters
|
|
156
|
-
* @returns Promise resolving to
|
|
157
|
+
* @returns Promise resolving to paged movements result
|
|
157
158
|
*
|
|
158
159
|
* @example
|
|
159
160
|
* ```typescript
|
|
160
161
|
* // Basic usage
|
|
161
|
-
* const
|
|
162
|
+
* const { data, pageSize, hasMore, next } = await bloque.accounts.movements({
|
|
162
163
|
* urn: 'did:bloque:account:card:usr-123:crd-456',
|
|
164
|
+
* asset: 'DUSD/6',
|
|
163
165
|
* });
|
|
164
166
|
*
|
|
165
167
|
* // With filters
|
|
166
|
-
* const
|
|
168
|
+
* const result = await bloque.accounts.movements({
|
|
167
169
|
* urn: 'did:bloque:account:card:usr-123:crd-456',
|
|
168
170
|
* asset: 'DUSD/6',
|
|
169
171
|
* limit: 50,
|
|
@@ -171,14 +173,24 @@ export declare class AccountsClient extends BaseClient {
|
|
|
171
173
|
* after: '2025-01-01T00:00:00Z',
|
|
172
174
|
* });
|
|
173
175
|
*
|
|
174
|
-
* //
|
|
175
|
-
*
|
|
176
|
+
* // Next page
|
|
177
|
+
* if (result.hasMore && result.next) {
|
|
178
|
+
* const nextPage = await bloque.accounts.movements({
|
|
179
|
+
* urn: params.urn,
|
|
180
|
+
* asset: params.asset,
|
|
181
|
+
* next: result.next,
|
|
182
|
+
* });
|
|
183
|
+
* }
|
|
184
|
+
*
|
|
185
|
+
* // Filter by pocket (main = confirmed, pending = pending movements)
|
|
186
|
+
* const confirmed = await bloque.accounts.movements({
|
|
176
187
|
* urn: 'did:bloque:account:virtual:acc-123',
|
|
177
|
-
*
|
|
188
|
+
* asset: 'KSM/12',
|
|
189
|
+
* pocket: 'main',
|
|
178
190
|
* });
|
|
179
191
|
* ```
|
|
180
192
|
*/
|
|
181
|
-
movements(params: ListMovementsParams): Promise<
|
|
193
|
+
movements(params: ListMovementsParams): Promise<ListMovementsResult>;
|
|
182
194
|
/**
|
|
183
195
|
* Dispatches the wire account to the correct per-medium mapper.
|
|
184
196
|
* Returns a properly typed account (CardAccount, VirtualAccount, etc.)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseClient } from '@bloque/sdk-core';
|
|
2
2
|
import type { AccountWithBalance, CardDetails, TokenBalance } from '../internal/wire-types';
|
|
3
3
|
import type { CreateAccountOptions } from '../types';
|
|
4
|
-
import type { CardAccount,
|
|
4
|
+
import type { CardAccount, CreateCardParams, GetBalanceParams, ListCardAccountsParams, ListCardAccountsResult, ListMovementsPagedResult, ListMovementsParams, UpdateCardMetadataParams } from './types';
|
|
5
5
|
/**
|
|
6
6
|
* Maps a wire card account to the SDK CardAccount type.
|
|
7
7
|
* Exported so AccountsClient.get() can dispatch by medium.
|
|
@@ -61,28 +61,46 @@ export declare class CardClient extends BaseClient {
|
|
|
61
61
|
/**
|
|
62
62
|
* List card account movements/transactions
|
|
63
63
|
*
|
|
64
|
+
* Returns a paged result with data, pageSize, hasMore, and optional next token.
|
|
65
|
+
*
|
|
64
66
|
* @param params - Movement list parameters
|
|
65
|
-
* @returns Promise resolving to
|
|
67
|
+
* @returns Promise resolving to paged card movements result
|
|
66
68
|
*
|
|
67
69
|
* @example
|
|
68
70
|
* ```typescript
|
|
69
71
|
* // Basic usage
|
|
70
|
-
* const
|
|
72
|
+
* const { data, pageSize, hasMore, next } = await bloque.accounts.card.movements({
|
|
71
73
|
* urn: 'did:bloque:account:card:usr-123:crd-456',
|
|
72
74
|
* asset: 'DUSD/6',
|
|
73
75
|
* });
|
|
74
76
|
*
|
|
75
77
|
* // With pagination and filters
|
|
76
|
-
* const
|
|
78
|
+
* const result = await bloque.accounts.card.movements({
|
|
77
79
|
* urn: 'did:bloque:account:card:usr-123:crd-456',
|
|
78
80
|
* asset: 'DUSD/6',
|
|
79
81
|
* limit: 50,
|
|
80
82
|
* direction: 'in',
|
|
81
83
|
* after: '2025-01-01T00:00:00Z',
|
|
82
84
|
* });
|
|
85
|
+
*
|
|
86
|
+
* // Next page
|
|
87
|
+
* if (result.hasMore && result.next) {
|
|
88
|
+
* const nextPage = await bloque.accounts.card.movements({
|
|
89
|
+
* urn: params.urn,
|
|
90
|
+
* asset: params.asset,
|
|
91
|
+
* next: result.next,
|
|
92
|
+
* });
|
|
93
|
+
* }
|
|
94
|
+
*
|
|
95
|
+
* // Filter by pocket (main = confirmed, pending = pending movements)
|
|
96
|
+
* const confirmed = await bloque.accounts.card.movements({
|
|
97
|
+
* urn: 'did:bloque:account:card:usr-123:crd-456',
|
|
98
|
+
* asset: 'DUSD/6',
|
|
99
|
+
* pocket: 'main',
|
|
100
|
+
* });
|
|
83
101
|
* ```
|
|
84
102
|
*/
|
|
85
|
-
movements(params: ListMovementsParams): Promise<
|
|
103
|
+
movements(params: ListMovementsParams): Promise<ListMovementsPagedResult>;
|
|
86
104
|
/**
|
|
87
105
|
* Get card account balance
|
|
88
106
|
*
|
package/dist/card/types.d.ts
CHANGED
|
@@ -70,6 +70,27 @@ export interface ListMovementsParams {
|
|
|
70
70
|
* See API docs: GET /api/accounts/{urn}/movements
|
|
71
71
|
*/
|
|
72
72
|
collapsed_view?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Filter by pocket: 'main' for confirmed movements, 'pending' for pending movements
|
|
75
|
+
*/
|
|
76
|
+
pocket?: 'main' | 'pending';
|
|
77
|
+
/**
|
|
78
|
+
* Pagination token for fetching the next page (from previous response's next)
|
|
79
|
+
*/
|
|
80
|
+
next?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Paged result for list movements (wire/snake_case from API)
|
|
84
|
+
*/
|
|
85
|
+
export interface ListMovementsPagedResult {
|
|
86
|
+
/** Array of movements */
|
|
87
|
+
data: CardMovement[];
|
|
88
|
+
/** Number of results in this page */
|
|
89
|
+
pageSize: number;
|
|
90
|
+
/** Whether more results are available */
|
|
91
|
+
hasMore: boolean;
|
|
92
|
+
/** Pagination token for the next page (if hasMore is true) */
|
|
93
|
+
next?: string;
|
|
73
94
|
}
|
|
74
95
|
export interface CardMovement extends Transaction {
|
|
75
96
|
}
|
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=(t,e)=>{for(var a in e)__webpack_require__.o(e,a)&&!__webpack_require__.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:e[a]})},__webpack_require__.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),__webpack_require__.r=t=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{BancolombiaClient:()=>BancolombiaClient,PolygonClient:()=>PolygonClient,AccountsClient:()=>AccountsClient,UsClient:()=>UsClient,mapUsAccountFromWire:()=>mapUsAccountFromWire,CardClient:()=>CardClient,mapCardAccountFromWire:()=>mapCardAccountFromWire,mapPolygonAccountFromWire:()=>mapPolygonAccountFromWire,mapBancolombiaAccountFromWire:()=>mapBancolombiaAccountFromWire,mapVirtualAccountFromWire:()=>mapVirtualAccountFromWire,VirtualClient:()=>VirtualClient});const sdk_core_namespaceObject=require("@bloque/sdk-core");function mapBancolombiaAccountFromWire(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 BancolombiaClient extends sdk_core_namespaceObject.BaseClient{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 mapBancolombiaAccountFromWire(t)}}function mapCardAccountFromWire(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 CardClient extends sdk_core_namespaceObject.BaseClient{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,a=t.asset||"DUSD/6";if("DUSD/6"!==a&&"KSM/12"!==a)throw Error("Invalid asset type. Supported assets are USD and KSM.");e.set("asset",a),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));let r=e.toString(),n=`/api/accounts/${t.urn}/movements${r?`?${r}`:""}`;return(await this.httpClient.request({method:"GET",path:n})).transactions}async balance(t){return(await this.httpClient.request({method:"GET",path:`/api/accounts/${t.urn}/balance`})).balance}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async updateName(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{metadata:{name:e}}});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return mapCardAccountFromWire(t)}}function mapPolygonAccountFromWire(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 PolygonClient extends sdk_core_namespaceObject.BaseClient{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 mapPolygonAccountFromWire(t)}}function mapUsAccountFromWire(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 UsClient extends sdk_core_namespaceObject.BaseClient{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 mapUsAccountFromWire(t)}}function mapVirtualAccountFromWire(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 VirtualClient extends sdk_core_namespaceObject.BaseClient{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 mapVirtualAccountFromWire(t)}}class AccountsClient extends sdk_core_namespaceObject.BaseClient{bancolombia;card;polygon;us;virtual;constructor(t){super(t),this.bancolombia=new BancolombiaClient(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(t){if(!t?.trim())throw Error("Account URN is required");return(await this.httpClient.request({method:"GET",path:`/api/accounts/${t}/balance`})).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(!(0,sdk_core_namespaceObject.isSupportedAsset)(e))throw Error(`Invalid asset type "${e}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let a={destination_account_urn:t.destinationUrn,amount:t.amount,asset:e,metadata:t.metadata},r=await this.httpClient.request({method:"POST",path:`/api/accounts/${t.sourceUrn}/transfer`,body:a});return{queueId:r.result.queue_id,status:r.result.status,message:r.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(!(0,sdk_core_namespaceObject.isSupportedAsset)(e.asset))throw Error(`Invalid asset type "${e.asset}" in operation "${e.reference}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.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},a=await this.httpClient.request({method:"POST",path:"/api/accounts/batch/transfer",body:e});return{chunks:a.result.chunks.map(t=>({queueId:t.queue_id,status:t.status,message:t.message})),totalOperations:a.result.total_operations,totalChunks:a.result.total_chunks}}async movements(t){if(!t.urn)throw Error("Account URN is required");let e=t.asset||"DUSD/6";if(!(0,sdk_core_namespaceObject.isSupportedAsset)(e))throw Error(`Invalid asset type "${e}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let a=new URLSearchParams;a.set("asset",e),void 0!==t.limit&&a.set("limit",t.limit.toString()),t.before&&a.set("before",t.before),t.after&&a.set("after",t.after),t.reference&&a.set("reference",t.reference),t.direction&&a.set("direction",t.direction),void 0!==t.collapsed_view&&a.set("collapsed_view",String(t.collapsed_view)),console.log("queryParams: ",a.toString());let r=`/api/accounts/${t.urn}/movements?${a.toString()}`;return(await this.httpClient.request({method:"GET",path:r})).transactions.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}))}_mapByMedium(t){switch(t.medium){case"card":return mapCardAccountFromWire(t);case"virtual":return mapVirtualAccountFromWire(t);case"polygon":return mapPolygonAccountFromWire(t);case"bancolombia":return mapBancolombiaAccountFromWire(t);case"us-account":return mapUsAccountFromWire(t);default:throw Error(`Unknown account medium: ${t.medium}`)}}}for(var __rspack_i in exports.AccountsClient=__webpack_exports__.AccountsClient,exports.BancolombiaClient=__webpack_exports__.BancolombiaClient,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.mapCardAccountFromWire=__webpack_exports__.mapCardAccountFromWire,exports.mapPolygonAccountFromWire=__webpack_exports__.mapPolygonAccountFromWire,exports.mapUsAccountFromWire=__webpack_exports__.mapUsAccountFromWire,exports.mapVirtualAccountFromWire=__webpack_exports__.mapVirtualAccountFromWire,__webpack_exports__)-1===["AccountsClient","BancolombiaClient","CardClient","PolygonClient","UsClient","VirtualClient","mapBancolombiaAccountFromWire","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=(t,e)=>{for(var a in e)__webpack_require__.o(e,a)&&!__webpack_require__.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:e[a]})},__webpack_require__.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),__webpack_require__.r=t=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{BancolombiaClient:()=>BancolombiaClient,PolygonClient:()=>PolygonClient,AccountsClient:()=>AccountsClient,UsClient:()=>UsClient,mapUsAccountFromWire:()=>mapUsAccountFromWire,CardClient:()=>CardClient,mapCardAccountFromWire:()=>mapCardAccountFromWire,mapPolygonAccountFromWire:()=>mapPolygonAccountFromWire,mapBancolombiaAccountFromWire:()=>mapBancolombiaAccountFromWire,mapVirtualAccountFromWire:()=>mapVirtualAccountFromWire,VirtualClient:()=>VirtualClient});const sdk_core_namespaceObject=require("@bloque/sdk-core");function mapBancolombiaAccountFromWire(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 BancolombiaClient extends sdk_core_namespaceObject.BaseClient{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 mapBancolombiaAccountFromWire(t)}}function mapCardAccountFromWire(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 CardClient extends sdk_core_namespaceObject.BaseClient{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,a=t.asset||"DUSD/6";if("DUSD/6"!==a&&"KSM/12"!==a)throw Error("Invalid asset type. Supported assets are USD and KSM.");e.set("asset",a),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 r=e.toString(),n=`/api/accounts/${t.urn}/movements${r?`?${r}`:""}`,s=await this.httpClient.request({method:"GET",path:n});return{data:s.data,pageSize:s.page_size,hasMore:s.has_more,next:s.next}}async balance(t){return(await this.httpClient.request({method:"GET",path:`/api/accounts/${t.urn}/balance`})).balance}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async updateName(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{metadata:{name:e}}});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return mapCardAccountFromWire(t)}}function mapPolygonAccountFromWire(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 PolygonClient extends sdk_core_namespaceObject.BaseClient{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 mapPolygonAccountFromWire(t)}}function mapUsAccountFromWire(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 UsClient extends sdk_core_namespaceObject.BaseClient{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 mapUsAccountFromWire(t)}}function mapVirtualAccountFromWire(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 VirtualClient extends sdk_core_namespaceObject.BaseClient{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 mapVirtualAccountFromWire(t)}}class AccountsClient extends sdk_core_namespaceObject.BaseClient{bancolombia;card;polygon;us;virtual;constructor(t){super(t),this.bancolombia=new BancolombiaClient(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(t){if(!t?.trim())throw Error("Account URN is required");return(await this.httpClient.request({method:"GET",path:`/api/accounts/${t}/balance`})).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(!(0,sdk_core_namespaceObject.isSupportedAsset)(e))throw Error(`Invalid asset type "${e}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let a={destination_account_urn:t.destinationUrn,amount:t.amount,asset:e,metadata:t.metadata},r=await this.httpClient.request({method:"POST",path:`/api/accounts/${t.sourceUrn}/transfer`,body:a});return{queueId:r.result.queue_id,status:r.result.status,message:r.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(!(0,sdk_core_namespaceObject.isSupportedAsset)(e.asset))throw Error(`Invalid asset type "${e.asset}" in operation "${e.reference}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.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},a=await this.httpClient.request({method:"POST",path:"/api/accounts/batch/transfer",body:e});return{chunks:a.result.chunks.map(t=>({queueId:t.queue_id,status:t.status,message:t.message})),totalOperations:a.result.total_operations,totalChunks:a.result.total_chunks}}async movements(t){if(!t.urn)throw Error("Account URN is required");let e=t.asset||"DUSD/6";if(!(0,sdk_core_namespaceObject.isSupportedAsset)(e))throw Error(`Invalid asset type "${e}". Supported assets: ${sdk_core_namespaceObject.SUPPORTED_ASSETS.join(", ")}`);let a=new URLSearchParams;a.set("asset",e),void 0!==t.limit&&a.set("limit",t.limit.toString()),t.before&&a.set("before",t.before),t.after&&a.set("after",t.after),t.reference&&a.set("reference",t.reference),t.direction&&a.set("direction",t.direction),void 0!==t.collapsed_view&&a.set("collapsed_view",String(t.collapsed_view)),t.pocket&&a.set("pocket",t.pocket),t.next&&a.set("next",t.next);let r=`/api/accounts/${t.urn}/movements?${a.toString()}`,n=await this.httpClient.request({method:"GET",path:r});return{data:n.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:n.page_size,hasMore:n.has_more,next:n.next}}_mapByMedium(t){switch(t.medium){case"card":return mapCardAccountFromWire(t);case"virtual":return mapVirtualAccountFromWire(t);case"polygon":return mapPolygonAccountFromWire(t);case"bancolombia":return mapBancolombiaAccountFromWire(t);case"us-account":return mapUsAccountFromWire(t);default:throw Error(`Unknown account medium: ${t.medium}`)}}}for(var __rspack_i in exports.AccountsClient=__webpack_exports__.AccountsClient,exports.BancolombiaClient=__webpack_exports__.BancolombiaClient,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.mapCardAccountFromWire=__webpack_exports__.mapCardAccountFromWire,exports.mapPolygonAccountFromWire=__webpack_exports__.mapPolygonAccountFromWire,exports.mapUsAccountFromWire=__webpack_exports__.mapUsAccountFromWire,exports.mapVirtualAccountFromWire=__webpack_exports__.mapVirtualAccountFromWire,__webpack_exports__)-1===["AccountsClient","BancolombiaClient","CardClient","PolygonClient","UsClient","VirtualClient","mapBancolombiaAccountFromWire","mapCardAccountFromWire","mapPolygonAccountFromWire","mapUsAccountFromWire","mapVirtualAccountFromWire"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{BaseClient as t,SUPPORTED_ASSETS as e,isSupportedAsset as a}from"@bloque/sdk-core";function r(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 n 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 r(t)}}function s(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 i 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,a=t.asset||"DUSD/6";if("DUSD/6"!==a&&"KSM/12"!==a)throw Error("Invalid asset type. Supported assets are USD and KSM.");e.set("asset",a),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));let r=e.toString(),n=`/api/accounts/${t.urn}/movements${r?`?${r}`:""}`;return(await this.httpClient.request({method:"GET",path:n})).transactions}async balance(t){return(await this.httpClient.request({method:"GET",path:`/api/accounts/${t.urn}/balance`})).balance}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async updateName(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{metadata:{name:e}}});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return s(t)}}function o(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 u 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 o(t)}}function c(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 d extends t{async getTosLink(t){let e=new URLSearchParams({redirect_uri:t.redirectUri});return{url:(await this.httpClient.request({method:"POST",path:`/api/mediums/us-account/tos-link?${e.toString()}`})).result.url}}async create(t,e){let a={street_line_1:t.address.streetLine1,street_line_2:t.address.streetLine2,city:t.address.city,state:t.address.state,postal_code:t.address.postalCode,country:t.address.country},r={type:t.type,first_name:t.firstName,middle_name:t.middleName,last_name:t.lastName,email:t.email,phone:t.phone,address:a,birth_date:t.birthDate,tax_identification_number:t.taxIdentificationNumber,gov_id_country:t.govIdCountry,gov_id_image_front:t.govIdImageFront,signed_agreement_id:t.signedAgreementId},n={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:r,metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},s=await this.httpClient.request({method:"POST",path:"/api/mediums/us-account",body:n}),i=this._mapAccountResponse(s.result.account);return e?.waitLedger?this._waitForActiveStatus(i.urn,e.timeout||6e4):i}async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","us-account"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({urn:t.urn,id:t.id,type:t.details.type,firstName:t.details.first_name,middleName:t.details.middle_name,lastName:t.details.last_name,email:t.details.email,phone:t.details.phone,address:{streetLine1:t.details.address.street_line_1,streetLine2:t.details.address.street_line_2,city:t.details.address.city,state:t.details.address.state,postalCode:t.details.address.postal_code,country:t.details.address.country},birthDate:t.details.birth_date,accountNumber:t.details.account_number,routingNumber:t.details.routing_number,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return c(t)}}function l(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 p 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 l(t)}}class h extends t{bancolombia;card;polygon;us;virtual;constructor(t){super(t),this.bancolombia=new n(this.httpClient),this.card=new i(this.httpClient),this.polygon=new u(this.httpClient),this.us=new d(this.httpClient),this.virtual=new p(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 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 r=t.asset||"DUSD/6";if(!a(r))throw Error(`Invalid asset type "${r}". Supported assets: ${e.join(", ")}`);let n={destination_account_urn:t.destinationUrn,amount:t.amount,asset:r,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 r of t.operations)if(!a(r.asset))throw Error(`Invalid asset type "${r.asset}" in operation "${r.reference}". Supported assets: ${e.join(", ")}`);let r={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:r});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 r=t.asset||"DUSD/6";if(!a(r))throw Error(`Invalid asset type "${r}". Supported assets: ${e.join(", ")}`);let n=new URLSearchParams;n.set("asset",r),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)),console.log("queryParams: ",n.toString());let s=`/api/accounts/${t.urn}/movements?${n.toString()}`;return(await this.httpClient.request({method:"GET",path:s})).transactions.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}))}_mapByMedium(t){switch(t.medium){case"card":return s(t);case"virtual":return l(t);case"polygon":return o(t);case"bancolombia":return r(t);case"us-account":return c(t);default:throw Error(`Unknown account medium: ${t.medium}`)}}}export{h as AccountsClient,n as BancolombiaClient,i as CardClient,u as PolygonClient,d as UsClient,p as VirtualClient,r as mapBancolombiaAccountFromWire,s as mapCardAccountFromWire,o as mapPolygonAccountFromWire,c as mapUsAccountFromWire,l as mapVirtualAccountFromWire};
|
|
1
|
+
import{BaseClient as t,SUPPORTED_ASSETS as e,isSupportedAsset as a}from"@bloque/sdk-core";function r(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 n 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 r(t)}}function s(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 i 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,a=t.asset||"DUSD/6";if("DUSD/6"!==a&&"KSM/12"!==a)throw Error("Invalid asset type. Supported assets are USD and KSM.");e.set("asset",a),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 r=e.toString(),n=`/api/accounts/${t.urn}/movements${r?`?${r}`:""}`,s=await this.httpClient.request({method:"GET",path:n});return{data:s.data,pageSize:s.page_size,hasMore:s.has_more,next:s.next}}async balance(t){return(await this.httpClient.request({method:"GET",path:`/api/accounts/${t.urn}/balance`})).balance}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async updateName(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{metadata:{name:e}}});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return s(t)}}function o(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 u 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 o(t)}}function c(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 d extends t{async getTosLink(t){let e=new URLSearchParams({redirect_uri:t.redirectUri});return{url:(await this.httpClient.request({method:"POST",path:`/api/mediums/us-account/tos-link?${e.toString()}`})).result.url}}async create(t,e){let a={street_line_1:t.address.streetLine1,street_line_2:t.address.streetLine2,city:t.address.city,state:t.address.state,postal_code:t.address.postalCode,country:t.address.country},r={type:t.type,first_name:t.firstName,middle_name:t.middleName,last_name:t.lastName,email:t.email,phone:t.phone,address:a,birth_date:t.birthDate,tax_identification_number:t.taxIdentificationNumber,gov_id_country:t.govIdCountry,gov_id_image_front:t.govIdImageFront,signed_agreement_id:t.signedAgreementId},n={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:r,metadata:{source:"sdk-typescript",name:t.name,...t.metadata}},s=await this.httpClient.request({method:"POST",path:"/api/mediums/us-account",body:n}),i=this._mapAccountResponse(s.result.account);return e?.waitLedger?this._waitForActiveStatus(i.urn,e.timeout||6e4):i}async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;a.append("medium","us-account"),e&&a.append("holder_urn",e),t?.urn&&a.append("urn",t.urn);let r=`/api/accounts?${a.toString()}`;return{accounts:(await this.httpClient.request({method:"GET",path:r})).accounts.map(t=>({urn:t.urn,id:t.id,type:t.details.type,firstName:t.details.first_name,middleName:t.details.middle_name,lastName:t.details.last_name,email:t.details.email,phone:t.details.phone,address:{streetLine1:t.details.address.street_line_1,streetLine2:t.details.address.street_line_2,city:t.details.address.city,state:t.details.address.state,postalCode:t.details.address.postal_code,country:t.details.address.country},birthDate:t.details.birth_date,accountNumber:t.details.account_number,routingNumber:t.details.routing_number,status:t.status,ownerUrn:t.owner_urn,ledgerId:t.ledger_account_id,webhookUrl:t.webhook_url,metadata:t.metadata,createdAt:t.created_at,updatedAt:t.updated_at,balance:t.balance}))}}async updateMetadata(t){let e={metadata:t.metadata},a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t.urn}`,body:e});return this._mapAccountResponse(a.result.account)}async activate(t){return this._updateStatus(t,"active")}async freeze(t){return this._updateStatus(t,"frozen")}async disable(t){return this._updateStatus(t,"disabled")}async _waitForActiveStatus(t,e){let a=Date.now();for(;;){if(Date.now()-a>e)throw Error(`Timeout waiting for account to become active. URN: ${t}`);let r=(await this.list({urn:t})).accounts[0];if(!r)throw Error(`Account not found. URN: ${t}`);if("active"===r.status)return r;if("creation_failed"===r.status)throw Error(`Account creation failed. URN: ${t}`);await new Promise(t=>setTimeout(t,2e3))}}async _updateStatus(t,e){let a=await this.httpClient.request({method:"PATCH",path:`/api/accounts/${t}`,body:{status:e}});return this._mapAccountResponse(a.result.account)}_mapAccountResponse(t){return c(t)}}function l(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 p 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 l(t)}}class h extends t{bancolombia;card;polygon;us;virtual;constructor(t){super(t),this.bancolombia=new n(this.httpClient),this.card=new i(this.httpClient),this.polygon=new u(this.httpClient),this.us=new d(this.httpClient),this.virtual=new p(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 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 r=t.asset||"DUSD/6";if(!a(r))throw Error(`Invalid asset type "${r}". Supported assets: ${e.join(", ")}`);let n={destination_account_urn:t.destinationUrn,amount:t.amount,asset:r,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 r of t.operations)if(!a(r.asset))throw Error(`Invalid asset type "${r.asset}" in operation "${r.reference}". Supported assets: ${e.join(", ")}`);let r={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:r});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 r=t.asset||"DUSD/6";if(!a(r))throw Error(`Invalid asset type "${r}". Supported assets: ${e.join(", ")}`);let n=new URLSearchParams;n.set("asset",r),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}}_mapByMedium(t){switch(t.medium){case"card":return s(t);case"virtual":return l(t);case"polygon":return o(t);case"bancolombia":return r(t);case"us-account":return c(t);default:throw Error(`Unknown account medium: ${t.medium}`)}}}export{h as AccountsClient,n as BancolombiaClient,i as CardClient,u as PolygonClient,d as UsClient,p as VirtualClient,r as mapBancolombiaAccountFromWire,s as mapCardAccountFromWire,o as mapPolygonAccountFromWire,c as mapUsAccountFromWire,l as mapVirtualAccountFromWire};
|
|
@@ -278,6 +278,11 @@ export declare enum TransactionStatus {
|
|
|
278
278
|
FAILED = "failed",
|
|
279
279
|
IGNORED = "ignored"
|
|
280
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* @internal
|
|
283
|
+
* Transaction type from API
|
|
284
|
+
*/
|
|
285
|
+
export type TransactionType = 'deposit' | 'withdraw' | 'transfer';
|
|
281
286
|
/**
|
|
282
287
|
* @internal
|
|
283
288
|
* Transaction from API
|
|
@@ -287,7 +292,8 @@ export interface Transaction {
|
|
|
287
292
|
asset: string;
|
|
288
293
|
from_account_id: string;
|
|
289
294
|
to_account_id: string;
|
|
290
|
-
direction: 'in' | 'out'
|
|
295
|
+
direction: 'in' | 'out';
|
|
296
|
+
type: TransactionType;
|
|
291
297
|
reference: string;
|
|
292
298
|
rail_name: string;
|
|
293
299
|
status: TransactionStatus;
|
|
@@ -296,10 +302,13 @@ export interface Transaction {
|
|
|
296
302
|
}
|
|
297
303
|
/**
|
|
298
304
|
* @internal
|
|
299
|
-
* List movements response
|
|
305
|
+
* List movements response (paged)
|
|
300
306
|
*/
|
|
301
307
|
export interface ListMovementsResponse {
|
|
302
|
-
|
|
308
|
+
data: Transaction[];
|
|
309
|
+
page_size: number;
|
|
310
|
+
has_more: boolean;
|
|
311
|
+
next?: string;
|
|
303
312
|
}
|
|
304
313
|
/**
|
|
305
314
|
* @internal
|
package/dist/types.d.ts
CHANGED
|
@@ -218,6 +218,10 @@ export interface ListAccountsResult {
|
|
|
218
218
|
/** Array of medium-specific mapped accounts */
|
|
219
219
|
accounts: Array<import('./card/types').CardAccount | import('./virtual/types').VirtualAccount | import('./polygon/types').PolygonAccount | import('./bancolombia/types').BancolombiaAccount | import('./us/types').UsAccount>;
|
|
220
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Transaction type (deposit, withdraw, transfer)
|
|
223
|
+
*/
|
|
224
|
+
export type MovementType = 'deposit' | 'withdraw' | 'transfer';
|
|
221
225
|
/**
|
|
222
226
|
* Transaction details metadata
|
|
223
227
|
*/
|
|
@@ -231,7 +235,7 @@ export interface MovementDetails {
|
|
|
231
235
|
* Account movement/transaction
|
|
232
236
|
*/
|
|
233
237
|
export interface Movement {
|
|
234
|
-
/**
|
|
238
|
+
/** Settlement status of the movement */
|
|
235
239
|
status: TransactionStatus;
|
|
236
240
|
/** Transaction amount */
|
|
237
241
|
amount: string;
|
|
@@ -242,7 +246,9 @@ export interface Movement {
|
|
|
242
246
|
/** Destination account ID */
|
|
243
247
|
toAccountId: string;
|
|
244
248
|
/** Transaction direction */
|
|
245
|
-
direction: 'in' | 'out'
|
|
249
|
+
direction: 'in' | 'out';
|
|
250
|
+
/** Transaction type (deposit, withdraw, transfer) */
|
|
251
|
+
type: MovementType;
|
|
246
252
|
/** Transaction reference */
|
|
247
253
|
reference: string;
|
|
248
254
|
/** Rail/network name */
|
|
@@ -252,3 +258,16 @@ export interface Movement {
|
|
|
252
258
|
/** Creation timestamp */
|
|
253
259
|
createdAt: string;
|
|
254
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* Paged result for list movements
|
|
263
|
+
*/
|
|
264
|
+
export interface ListMovementsResult {
|
|
265
|
+
/** Array of movements */
|
|
266
|
+
data: Movement[];
|
|
267
|
+
/** Number of results in this page */
|
|
268
|
+
pageSize: number;
|
|
269
|
+
/** Whether more results are available */
|
|
270
|
+
hasMore: boolean;
|
|
271
|
+
/** Pagination token for the next page (if hasMore is true) */
|
|
272
|
+
next?: string;
|
|
273
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bloque/sdk-accounts",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.36",
|
|
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.0.
|
|
39
|
+
"@bloque/sdk-core": "0.0.36"
|
|
40
40
|
}
|
|
41
41
|
}
|