@bloque/sdk-accounts 0.0.25 → 0.0.26

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.
@@ -3,7 +3,8 @@ import { BaseClient } from '@bloque/sdk-core';
3
3
  import { BancolombiaClient } from './bancolombia/bancolombia-client';
4
4
  import { CardClient } from './card/card-client';
5
5
  import { PolygonClient } from './polygon/polygon-client';
6
- import type { TransferParams, TransferResult } from './types';
6
+ import type { ListAccountsParams, ListAccountsResult, TransferParams, TransferResult } from './types';
7
+ import { UsClient } from './us/us-client';
7
8
  import { VirtualClient } from './virtual/virtual-client';
8
9
  /**
9
10
  * Accounts client for managing financial accounts and payment methods
@@ -19,8 +20,29 @@ export declare class AccountsClient extends BaseClient {
19
20
  readonly bancolombia: BancolombiaClient;
20
21
  readonly card: CardClient;
21
22
  readonly polygon: PolygonClient;
23
+ readonly us: UsClient;
22
24
  readonly virtual: VirtualClient;
23
25
  constructor(httpClient: HttpClient);
26
+ /**
27
+ * List accounts
28
+ *
29
+ * Retrieves a list of accounts, optionally filtered by holder URN.
30
+ *
31
+ * @param params - List parameters (optional)
32
+ * @returns Promise resolving to list of accounts
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * // List all accounts for the authenticated holder
37
+ * const result = await bloque.accounts.list();
38
+ *
39
+ * // List accounts for a specific holder
40
+ * const result = await bloque.accounts.list({
41
+ * medium: 'card'
42
+ * });
43
+ * ```
44
+ */
45
+ list(params?: ListAccountsParams): Promise<ListAccountsResult>;
24
46
  /**
25
47
  * Transfer funds between accounts
26
48
  *
@@ -42,4 +64,9 @@ export declare class AccountsClient extends BaseClient {
42
64
  * ```
43
65
  */
44
66
  transfer(params: TransferParams): Promise<TransferResult>;
67
+ /**
68
+ * Maps API account response to SDK format
69
+ * @internal
70
+ */
71
+ private _mapAccountResponse;
45
72
  }
@@ -1,20 +1,57 @@
1
1
  import { BaseClient } from '@bloque/sdk-core';
2
- import type { BancolombiaAccount, CreateBancolombiaAccountParams, UpdateBancolombiaMetadataParams } from './types';
2
+ import type { CreateAccountOptions } from '../types';
3
+ import type { BancolombiaAccount, CreateBancolombiaAccountParams, ListBancolombiaAccountsParams, ListBancolombiaAccountsResult, UpdateBancolombiaMetadataParams } from './types';
3
4
  export declare class BancolombiaClient extends BaseClient {
5
+ /**
6
+ * List Bancolombia accounts
7
+ *
8
+ * Retrieves a list of Bancolombia accounts, optionally filtered by holder URN or specific account URN.
9
+ *
10
+ * @param params - List parameters (optional)
11
+ * @returns Promise resolving to list of Bancolombia accounts
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // List all Bancolombia accounts for the authenticated holder
16
+ * const result = await bloque.accounts.bancolombia.list();
17
+ *
18
+ * // List Bancolombia accounts for a specific holder
19
+ * const result = await bloque.accounts.bancolombia.list({
20
+ * holderUrn: 'did:bloque:bloque-root:nestor'
21
+ * });
22
+ *
23
+ * // Get a specific Bancolombia account
24
+ * const result = await bloque.accounts.bancolombia.list({
25
+ * urn: 'did:bloque:account:bancolombia:abc-123'
26
+ * });
27
+ * ```
28
+ */
29
+ list(params?: ListBancolombiaAccountsParams): Promise<ListBancolombiaAccountsResult>;
4
30
  /**
5
31
  * Create a new Bancolombia account
6
32
  *
7
33
  * @param params - Bancolombia account creation parameters
34
+ * @param options - Creation options (optional)
8
35
  * @returns Promise resolving to the created Bancolombia account
9
36
  *
10
37
  * @example
11
38
  * ```typescript
39
+ * // Create without waiting
12
40
  * const account = await bloque.accounts.bancolombia.create({
13
41
  * name: 'Main Account'
14
42
  * });
43
+ *
44
+ * // Create and wait for active status
45
+ * const account = await bloque.accounts.bancolombia.create({
46
+ * name: 'Main Account'
47
+ * }, { waitLedger: true });
15
48
  * ```
16
49
  */
17
- create(params?: CreateBancolombiaAccountParams): Promise<BancolombiaAccount>;
50
+ create(params?: CreateBancolombiaAccountParams, options?: CreateAccountOptions): Promise<BancolombiaAccount>;
51
+ /**
52
+ * Private method to poll account status until it becomes active
53
+ */
54
+ private _waitForActiveStatus;
18
55
  /**
19
56
  * Update Bancolombia account metadata
20
57
  *
@@ -1,3 +1,25 @@
1
+ /**
2
+ * Parameters for listing Bancolombia accounts
3
+ */
4
+ export interface ListBancolombiaAccountsParams {
5
+ /**
6
+ * URN of the account holder (user or organization) to filter by
7
+ * @example "did:bloque:bloque-root:nestor"
8
+ */
9
+ holderUrn?: string;
10
+ /**
11
+ * URN of a specific Bancolombia account to retrieve
12
+ * @example "did:bloque:account:bancolombia:abc-123"
13
+ */
14
+ urn?: string;
15
+ }
16
+ /**
17
+ * Result of listing Bancolombia accounts
18
+ */
19
+ export interface ListBancolombiaAccountsResult {
20
+ /** Array of Bancolombia accounts with balance information */
21
+ accounts: BancolombiaAccount[];
22
+ }
1
23
  export interface CreateBancolombiaAccountParams {
2
24
  /**
3
25
  * URN of the account holder (user or organization)
@@ -81,4 +103,13 @@ export interface BancolombiaAccount {
81
103
  * Last update timestamp
82
104
  */
83
105
  updatedAt: string;
106
+ /**
107
+ * Token balances (optional, included in list responses and after creation)
108
+ */
109
+ balance?: Record<string, {
110
+ current: string;
111
+ pending: string;
112
+ in: string;
113
+ out: string;
114
+ }>;
84
115
  }
@@ -1,33 +1,58 @@
1
1
  import { BaseClient } from '@bloque/sdk-core';
2
2
  import type { TokenBalance } from '../internal/wire-types';
3
- import type { CardAccount, CardMovement, CreateCardParams, GetBalanceParams, ListCardParams, ListMovementsParams, UpdateCardMetadataParams } from './types';
3
+ import type { CreateAccountOptions } from '../types';
4
+ import type { CardAccount, CardMovement, CreateCardParams, GetBalanceParams, ListCardAccountsParams, ListCardAccountsResult, ListMovementsParams, UpdateCardMetadataParams } from './types';
4
5
  export declare class CardClient extends BaseClient {
5
6
  /**
6
7
  * Create a new card account
7
8
  *
8
9
  * @param params - Card creation parameters
10
+ * @param options - Creation options (optional)
9
11
  * @returns Promise resolving to the created card account
10
12
  *
11
13
  * @example
12
14
  * ```typescript
15
+ * // Create without waiting
13
16
  * const card = await bloque.accounts.card.create({
14
17
  * name: 'My Card',
15
18
  * });
19
+ *
20
+ * // Create and wait for active status
21
+ * const card = await bloque.accounts.card.create({
22
+ * name: 'My Card',
23
+ * }, { waitLedger: true });
16
24
  * ```
17
25
  */
18
- create(params?: CreateCardParams): Promise<CardAccount>;
26
+ create(params?: CreateCardParams, options?: CreateAccountOptions): Promise<CardAccount>;
27
+ /**
28
+ * Private method to poll account status until it becomes active
29
+ */
30
+ private _waitForActiveStatus;
19
31
  /**
20
- * List card accounts for a holder
32
+ * List card accounts
21
33
  *
22
- * @param params - List parameters
23
- * @returns Promise resolving to array of card accounts with balances
34
+ * Retrieves a list of card accounts, optionally filtered by holder URN or specific account URN.
35
+ *
36
+ * @param params - List parameters (optional)
37
+ * @returns Promise resolving to list of card accounts with balances
24
38
  *
25
39
  * @example
26
40
  * ```typescript
27
- * const cards = await bloque.accounts.card.list();
41
+ * // List all card accounts for the authenticated holder
42
+ * const result = await bloque.accounts.card.list();
43
+ *
44
+ * // List card accounts for a specific holder
45
+ * const result = await bloque.accounts.card.list({
46
+ * holderUrn: 'did:bloque:bloque-root:nestor'
47
+ * });
48
+ *
49
+ * // Get a specific card account
50
+ * const result = await bloque.accounts.card.list({
51
+ * urn: 'did:bloque:account:card:usr-123:crd-456'
52
+ * });
28
53
  * ```
29
54
  */
30
- list(params?: ListCardParams): Promise<CardAccount[]>;
55
+ list(params?: ListCardAccountsParams): Promise<ListCardAccountsResult>;
31
56
  /**
32
57
  * List card account movements/transactions
33
58
  *
@@ -1,12 +1,26 @@
1
1
  import type { CardType, TokenBalance, Transaction } from '../internal/wire-types';
2
2
  import type { SupportedAsset } from '../types';
3
- export interface ListCardParams {
3
+ /**
4
+ * Parameters for listing card accounts
5
+ */
6
+ export interface ListCardAccountsParams {
4
7
  /**
5
- * URN of the account holder (user or organization)
6
- *
7
- * @example "did:bloque:user:123e4567"
8
+ * URN of the account holder (user or organization) to filter by
9
+ * @example "did:bloque:bloque-root:nestor"
8
10
  */
9
11
  holderUrn?: string;
12
+ /**
13
+ * URN of a specific card account to retrieve
14
+ * @example "did:bloque:account:card:usr-123:crd-456"
15
+ */
16
+ urn?: string;
17
+ }
18
+ /**
19
+ * Result of listing card accounts
20
+ */
21
+ export interface ListCardAccountsResult {
22
+ /** Array of card accounts with balance information */
23
+ accounts: CardAccount[];
10
24
  }
11
25
  export interface ListMovementsParams {
12
26
  /**
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__,{CardClient:()=>CardClient,VirtualClient:()=>VirtualClient,PolygonClient:()=>PolygonClient,AccountsClient:()=>AccountsClient,BancolombiaClient:()=>BancolombiaClient});const sdk_core_namespaceObject=require("@bloque/sdk-core");class BancolombiaClient extends sdk_core_namespaceObject.BaseClient{async create(t={}){let e={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}},a=await this.httpClient.request({method:"POST",path:"/api/mediums/bancolombia",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 _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{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}}}class CardClient extends sdk_core_namespaceObject.BaseClient{async create(t={}){let e={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}},a=await this.httpClient.request({method:"POST",path:"/api/mediums/card",body:e});return this._mapAccountResponse(a.result.account)}async list(t){let e=new URLSearchParams({holder_urn:t?.holderUrn||this.httpClient.urn||"",medium:"card"});return(await this.httpClient.request({method:"GET",path:`/api/accounts?${e.toString()}`})).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);let r=e.toString(),s=`/api/accounts/${t.urn}/movements${r?`?${r}`:""}`;return(await this.httpClient.request({method:"GET",path:s})).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{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}}}class PolygonClient extends sdk_core_namespaceObject.BaseClient{async create(t={}){let e={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{},metadata:{source:"sdk-typescript",...t.metadata}},a=await this.httpClient.request({method:"POST",path:"/api/mediums/polygon",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 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{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}}}class VirtualClient extends sdk_core_namespaceObject.BaseClient{async create(t){let e={first_name:t.firstName,last_name:t.lastName},a={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:e,metadata:{source:"sdk-typescript",...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/virtual",body:a});return this._mapAccountResponse(r.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 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{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}}}class AccountsClient extends sdk_core_namespaceObject.BaseClient{bancolombia;card;polygon;virtual;constructor(t){super(t),this.bancolombia=new BancolombiaClient(this.httpClient),this.card=new CardClient(this.httpClient),this.polygon=new PolygonClient(this.httpClient),this.virtual=new VirtualClient(this.httpClient)}async transfer(t){let e=t.asset||"DUSD/6";if("DUSD/6"!==e&&"KSM/12"!==e)throw Error("Invalid asset type. Supported assets are USD and KSM.");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}}}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.VirtualClient=__webpack_exports__.VirtualClient,__webpack_exports__)-1===["AccountsClient","BancolombiaClient","CardClient","PolygonClient","VirtualClient"].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__,{CardClient:()=>CardClient,VirtualClient:()=>VirtualClient,PolygonClient:()=>PolygonClient,AccountsClient:()=>AccountsClient,UsClient:()=>UsClient,BancolombiaClient:()=>BancolombiaClient});const sdk_core_namespaceObject=require("@bloque/sdk-core");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{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 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);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{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}}}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",...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{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 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",...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{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}}}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={first_name:t.firstName,last_name:t.lastName},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}},n=await this.httpClient.request({method:"POST",path:"/api/mediums/virtual",body:r}),s=this._mapAccountResponse(n.result.account);return e?.waitLedger?this._waitForActiveStatus(s.urn,e.timeout||6e4):s}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(console.log(r),!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{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 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 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._mapAccountResponse(t))}}async transfer(t){let e=t.asset||"DUSD/6";if("DUSD/6"!==e&&"KSM/12"!==e)throw Error("Invalid asset type. Supported assets are USD and KSM.");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}}_mapAccountResponse(t){let e={};for(let[a,r]of Object.entries(t.balance))e[a]={current:r.current,pending:r.pending,in:r.in,out:r.out};return{id:t.id,urn:t.urn,medium:t.medium,details:t.details,ledgerId:t.ledger_account_id,status:t.status,ownerUrn:t.owner_urn,createdAt:t.created_at,updatedAt:t.updated_at,webhookUrl:t.webhook_url,metadata:t.metadata,balance:e}}}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,__webpack_exports__)-1===["AccountsClient","BancolombiaClient","CardClient","PolygonClient","UsClient","VirtualClient"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
package/dist/index.d.ts CHANGED
@@ -6,5 +6,7 @@ export * from './card/types';
6
6
  export * from './polygon/polygon-client';
7
7
  export * from './polygon/types';
8
8
  export * from './types';
9
+ export * from './us/types';
10
+ export * from './us/us-client';
9
11
  export * from './virtual/types';
10
12
  export * from './virtual/virtual-client';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{BaseClient as t}from"@bloque/sdk-core";class e extends t{async create(t={}){let e={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}},a=await this.httpClient.request({method:"POST",path:"/api/mediums/bancolombia",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 _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{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}}}class a extends t{async create(t={}){let e={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}},a=await this.httpClient.request({method:"POST",path:"/api/mediums/card",body:e});return this._mapAccountResponse(a.result.account)}async list(t){let e=new URLSearchParams({holder_urn:t?.holderUrn||this.httpClient.urn||"",medium:"card"});return(await this.httpClient.request({method:"GET",path:`/api/accounts?${e.toString()}`})).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);let s=e.toString(),r=`/api/accounts/${t.urn}/movements${s?`?${s}`:""}`;return(await this.httpClient.request({method:"GET",path:r})).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{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}}}class s extends t{async create(t={}){let e={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:{},metadata:{source:"sdk-typescript",...t.metadata}},a=await this.httpClient.request({method:"POST",path:"/api/mediums/polygon",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 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{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}}}class r extends t{async create(t){let e={first_name:t.firstName,last_name:t.lastName},a={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:e,metadata:{source:"sdk-typescript",...t.metadata}},s=await this.httpClient.request({method:"POST",path:"/api/mediums/virtual",body:a});return this._mapAccountResponse(s.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 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{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}}}class n extends t{bancolombia;card;polygon;virtual;constructor(t){super(t),this.bancolombia=new e(this.httpClient),this.card=new a(this.httpClient),this.polygon=new s(this.httpClient),this.virtual=new r(this.httpClient)}async transfer(t){let e=t.asset||"DUSD/6";if("DUSD/6"!==e&&"KSM/12"!==e)throw Error("Invalid asset type. Supported assets are USD and KSM.");let a={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:a});return{queueId:s.result.queue_id,status:s.result.status,message:s.result.message}}}export{n as AccountsClient,e as BancolombiaClient,a as CardClient,s as PolygonClient,r as VirtualClient};
1
+ import{BaseClient as t}from"@bloque/sdk-core";class e 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}),s=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(s.urn,e.timeout||6e4):s}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{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 a 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}),s=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(s.urn,e.timeout||6e4):s}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);let r=e.toString(),s=`/api/accounts/${t.urn}/movements${r?`?${r}`:""}`;return(await this.httpClient.request({method:"GET",path:s})).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{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}}}class r 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",...t.metadata}},r=await this.httpClient.request({method:"POST",path:"/api/mediums/polygon",body:a}),s=this._mapAccountResponse(r.result.account);return e?.waitLedger?this._waitForActiveStatus(s.urn,e.timeout||6e4):s}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{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 s 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},s={holder_urn:t.holderUrn||this.httpClient.urn||"",webhook_url:t.webhookUrl,ledger_account_id:t.ledgerId,input:r,metadata:{source:"sdk-typescript",...t.metadata}},n=await this.httpClient.request({method:"POST",path:"/api/mediums/us-account",body:s}),i=this._mapAccountResponse(n.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{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}}}class n 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={first_name:t.firstName,last_name:t.lastName},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}},s=await this.httpClient.request({method:"POST",path:"/api/mediums/virtual",body:r}),n=this._mapAccountResponse(s.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(console.log(r),!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{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 i extends t{bancolombia;card;polygon;us;virtual;constructor(t){super(t),this.bancolombia=new e(this.httpClient),this.card=new a(this.httpClient),this.polygon=new r(this.httpClient),this.us=new s(this.httpClient),this.virtual=new n(this.httpClient)}async list(t){let e=t?.holderUrn||this.httpClient.urn,a=new URLSearchParams;e&&a.append("holder_urn",e);let r=a.toString(),s=r?`/api/accounts?${r}`:"/api/accounts";return{accounts:(await this.httpClient.request({method:"GET",path:s})).accounts.map(t=>this._mapAccountResponse(t))}}async transfer(t){let e=t.asset||"DUSD/6";if("DUSD/6"!==e&&"KSM/12"!==e)throw Error("Invalid asset type. Supported assets are USD and KSM.");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}}_mapAccountResponse(t){let e={};for(let[a,r]of Object.entries(t.balance))e[a]={current:r.current,pending:r.pending,in:r.in,out:r.out};return{id:t.id,urn:t.urn,medium:t.medium,details:t.details,ledgerId:t.ledger_account_id,status:t.status,ownerUrn:t.owner_urn,createdAt:t.created_at,updatedAt:t.updated_at,webhookUrl:t.webhook_url,metadata:t.metadata,balance:e}}}export{i as AccountsClient,e as BancolombiaClient,a as CardClient,r as PolygonClient,s as UsClient,n as VirtualClient};
@@ -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' | 'card' | 'virtual' | 'polygon';
19
+ medium: 'bancolombia' | 'card' | 'virtual' | 'us-account' | 'polygon';
20
20
  details: TDetails;
21
21
  ledger_account_id: string;
22
22
  status: AccountStatus;
@@ -120,6 +120,68 @@ export type PolygonDetails = {
120
120
  address: string;
121
121
  network: string;
122
122
  };
123
+ /**
124
+ * @internal
125
+ * US account type
126
+ */
127
+ export type UsAccountType = 'individual' | 'business';
128
+ /**
129
+ * @internal
130
+ * US account address for creation
131
+ */
132
+ export interface UsAccountAddress {
133
+ street_line_1: string;
134
+ street_line_2?: string;
135
+ city: string;
136
+ state: string;
137
+ postal_code: string;
138
+ country: string;
139
+ }
140
+ /**
141
+ * @internal
142
+ * US account input for creation
143
+ */
144
+ export interface CreateUsAccountInput {
145
+ type: UsAccountType;
146
+ first_name: string;
147
+ middle_name?: string;
148
+ last_name: string;
149
+ email: string;
150
+ phone: string;
151
+ address: UsAccountAddress;
152
+ birth_date: string;
153
+ tax_identification_number: string;
154
+ gov_id_country: string;
155
+ gov_id_image_front: string;
156
+ signed_agreement_id: string;
157
+ }
158
+ /**
159
+ * @internal
160
+ * US account details from API
161
+ */
162
+ export interface UsDetails {
163
+ id: string;
164
+ type: UsAccountType;
165
+ first_name: string;
166
+ middle_name?: string;
167
+ last_name: string;
168
+ email: string;
169
+ phone: string;
170
+ address: UsAccountAddress;
171
+ birth_date: string;
172
+ account_number?: string;
173
+ routing_number?: string;
174
+ }
175
+ /**
176
+ * @internal
177
+ * TOS link response
178
+ */
179
+ export interface TosLinkResponse {
180
+ result: {
181
+ url: string;
182
+ };
183
+ req_id: string;
184
+ }
123
185
  /**
124
186
  * @internal
125
187
  * Update account request body
@@ -1,6 +1,32 @@
1
1
  import { BaseClient } from '@bloque/sdk-core';
2
- import type { CreatePolygonAccountParams, PolygonAccount, UpdatePolygonMetadataParams } from './types';
2
+ import type { CreateAccountOptions } from '../types';
3
+ import type { CreatePolygonAccountParams, ListPolygonAccountsParams, ListPolygonAccountsResult, PolygonAccount, UpdatePolygonMetadataParams } from './types';
3
4
  export declare class PolygonClient extends BaseClient {
5
+ /**
6
+ * List polygon accounts
7
+ *
8
+ * Retrieves a list of polygon accounts, optionally filtered by holder URN or specific account URN.
9
+ *
10
+ * @param params - List parameters (optional)
11
+ * @returns Promise resolving to list of polygon accounts
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // List all polygon accounts for the authenticated holder
16
+ * const result = await bloque.accounts.polygon.list();
17
+ *
18
+ * // List polygon accounts for a specific holder
19
+ * const result = await bloque.accounts.polygon.list({
20
+ * holderUrn: 'did:bloque:bloque-root:nestor'
21
+ * });
22
+ *
23
+ * // Get a specific polygon account
24
+ * const result = await bloque.accounts.polygon.list({
25
+ * urn: 'did:bloque:account:polygon:0x05B10c9B6241b73fc8c906fB7979eFc7764AB731'
26
+ * });
27
+ * ```
28
+ */
29
+ list(params?: ListPolygonAccountsParams): Promise<ListPolygonAccountsResult>;
4
30
  /**
5
31
  * Create a new polygon account
6
32
  *
@@ -8,14 +34,23 @@ export declare class PolygonClient extends BaseClient {
8
34
  * They're created automatically without requiring additional input.
9
35
  *
10
36
  * @param params - Polygon account creation parameters
37
+ * @param options - Creation options (optional)
11
38
  * @returns Promise resolving to the created polygon account
12
39
  *
13
40
  * @example
14
41
  * ```typescript
42
+ * // Create without waiting
15
43
  * const account = await bloque.accounts.polygon.create();
44
+ *
45
+ * // Create and wait for active status
46
+ * const account = await bloque.accounts.polygon.create({}, { waitLedger: true });
16
47
  * ```
17
48
  */
18
- create(params?: CreatePolygonAccountParams): Promise<PolygonAccount>;
49
+ create(params?: CreatePolygonAccountParams, options?: CreateAccountOptions): Promise<PolygonAccount>;
50
+ /**
51
+ * Private method to poll account status until it becomes active
52
+ */
53
+ private _waitForActiveStatus;
19
54
  /**
20
55
  * Update polygon account metadata
21
56
  *
@@ -1,3 +1,25 @@
1
+ /**
2
+ * Parameters for listing polygon accounts
3
+ */
4
+ export interface ListPolygonAccountsParams {
5
+ /**
6
+ * URN of the account holder (user or organization) to filter by
7
+ * @example "did:bloque:bloque-root:nestor"
8
+ */
9
+ holderUrn?: string;
10
+ /**
11
+ * URN of a specific polygon account to retrieve
12
+ * @example "did:bloque:account:polygon:0x05B10c9B6241b73fc8c906fB7979eFc7764AB731"
13
+ */
14
+ urn?: string;
15
+ }
16
+ /**
17
+ * Result of listing polygon accounts
18
+ */
19
+ export interface ListPolygonAccountsResult {
20
+ /** Array of polygon accounts with balance information */
21
+ accounts: PolygonAccount[];
22
+ }
1
23
  /**
2
24
  * Parameters for creating a polygon account
3
25
  */
@@ -89,4 +111,13 @@ export interface PolygonAccount {
89
111
  * Last update timestamp
90
112
  */
91
113
  updatedAt: string;
114
+ /**
115
+ * Token balances (optional, included in list responses and after creation)
116
+ */
117
+ balance?: Record<string, {
118
+ current: string;
119
+ pending: string;
120
+ in: string;
121
+ out: string;
122
+ }>;
92
123
  }
package/dist/types.d.ts CHANGED
@@ -1,6 +1,22 @@
1
1
  /**
2
2
  * Public types for @bloque/sdk-accounts
3
3
  */
4
+ /**
5
+ * Options for account creation
6
+ */
7
+ export interface CreateAccountOptions {
8
+ /**
9
+ * If true, wait for the account to become active before returning
10
+ * This will poll the account status every second until it's active
11
+ * @default false
12
+ */
13
+ waitLedger?: boolean;
14
+ /**
15
+ * Maximum time to wait in milliseconds (only applies when waitLedger is true)
16
+ * @default 60000 (60 seconds)
17
+ */
18
+ timeout?: number;
19
+ }
4
20
  /**
5
21
  * Supported asset types for transfers and movements
6
22
  */
@@ -46,3 +62,80 @@ export interface TransferResult {
46
62
  /** Human-readable message about the transfer status */
47
63
  message: string;
48
64
  }
65
+ /**
66
+ * Account status
67
+ */
68
+ export type AccountStatus = 'active' | 'disabled' | 'frozen' | 'deleted' | 'creation_in_progress' | 'creation_failed';
69
+ /**
70
+ * Account medium/type
71
+ */
72
+ export type AccountMedium = 'bancolombia' | 'card' | 'virtual' | 'polygon' | 'us-account';
73
+ /**
74
+ * Token balance information
75
+ */
76
+ export interface TokenBalance {
77
+ /** Current balance */
78
+ current: string;
79
+ /** Pending balance */
80
+ pending: string;
81
+ /** Incoming amount */
82
+ in: string;
83
+ /** Outgoing amount */
84
+ out: string;
85
+ }
86
+ /**
87
+ * Generic account response
88
+ * Details type varies based on account medium
89
+ */
90
+ export interface Account<TDetails = unknown> {
91
+ /** Unique account identifier */
92
+ id: string;
93
+ /** Unique resource name for the account */
94
+ urn: string;
95
+ /** Account type/medium */
96
+ medium: AccountMedium;
97
+ /** Account-specific details (structure varies by medium) */
98
+ details: TDetails;
99
+ /** Ledger account ID */
100
+ ledgerId: string;
101
+ /** Account status */
102
+ status: AccountStatus;
103
+ /** Owner URN */
104
+ ownerUrn: string;
105
+ /** Creation timestamp */
106
+ createdAt: string;
107
+ /** Last update timestamp */
108
+ updatedAt: string;
109
+ /** Webhook URL (if configured) */
110
+ webhookUrl: string | null;
111
+ /** Custom metadata */
112
+ metadata?: Record<string, unknown>;
113
+ /** Token balances by asset */
114
+ balance: Record<string, TokenBalance>;
115
+ }
116
+ /**
117
+ * Parameters for listing accounts
118
+ */
119
+ export interface ListAccountsParams {
120
+ /**
121
+ * URN of the account holder (user or organization) to filter by
122
+ * @example "did:bloque:bloque-root:nestor"
123
+ */
124
+ holderUrn?: string;
125
+ /**
126
+ * Specific account URN to retrieve
127
+ * @example "did:bloque:account:card:usr-123:crd-456"
128
+ */
129
+ urn?: string;
130
+ /**
131
+ * Account medium/type to filter by
132
+ */
133
+ medium?: AccountMedium;
134
+ }
135
+ /**
136
+ * Result of listing accounts
137
+ */
138
+ export interface ListAccountsResult {
139
+ /** Array of accounts */
140
+ accounts: Account[];
141
+ }
@@ -0,0 +1,257 @@
1
+ import type { TokenBalance, UsAccountType } from '../internal/wire-types';
2
+ /**
3
+ * Address information for US account creation
4
+ */
5
+ export interface UsAccountAddress {
6
+ /**
7
+ * Street address line 1
8
+ * @example "456 Wall Street"
9
+ */
10
+ streetLine1: string;
11
+ /**
12
+ * Street address line 2 (optional)
13
+ * @example "Suite 789"
14
+ */
15
+ streetLine2?: string;
16
+ /**
17
+ * City
18
+ * @example "New York"
19
+ */
20
+ city: string;
21
+ /**
22
+ * State code (2 letters)
23
+ * @example "NY"
24
+ */
25
+ state: string;
26
+ /**
27
+ * Postal code
28
+ * @example "10005"
29
+ */
30
+ postalCode: string;
31
+ /**
32
+ * Country code (2 letters)
33
+ * @example "US"
34
+ */
35
+ country: string;
36
+ }
37
+ /**
38
+ * Parameters for creating a US account
39
+ */
40
+ export interface CreateUsAccountParams {
41
+ /**
42
+ * URN of the account holder (user or organization)
43
+ * @internal - Not exposed in public documentation
44
+ */
45
+ holderUrn?: string;
46
+ /**
47
+ * Account type (individual or business)
48
+ * @example "individual"
49
+ */
50
+ type: UsAccountType;
51
+ /**
52
+ * First name
53
+ * @example "Robert"
54
+ */
55
+ firstName: string;
56
+ /**
57
+ * Middle name (optional)
58
+ * @example "James"
59
+ */
60
+ middleName?: string;
61
+ /**
62
+ * Last name
63
+ * @example "Johnson"
64
+ */
65
+ lastName: string;
66
+ /**
67
+ * Email address
68
+ * @example "robert.johnson@example.com"
69
+ */
70
+ email: string;
71
+ /**
72
+ * Phone number with country code
73
+ * @example "+12125551234"
74
+ */
75
+ phone: string;
76
+ /**
77
+ * Address information
78
+ */
79
+ address: UsAccountAddress;
80
+ /**
81
+ * Birth date in YYYY-MM-DD format
82
+ * @example "1985-03-15"
83
+ */
84
+ birthDate: string;
85
+ /**
86
+ * Tax identification number (SSN for individuals, EIN for businesses)
87
+ * @example "123-45-6789"
88
+ */
89
+ taxIdentificationNumber: string;
90
+ /**
91
+ * Government ID issuing country (2-letter code)
92
+ * @example "US"
93
+ */
94
+ govIdCountry: string;
95
+ /**
96
+ * Base64-encoded image of government ID front
97
+ */
98
+ govIdImageFront: string;
99
+ /**
100
+ * Signed agreement ID obtained from getTosLink
101
+ * @example "0d139f8e-14b0-4540-92ba-4e66c619b533"
102
+ */
103
+ signedAgreementId: string;
104
+ /**
105
+ * Webhook URL to receive account events
106
+ */
107
+ webhookUrl?: string;
108
+ /**
109
+ * Ledger account ID to associate with this account
110
+ */
111
+ ledgerId?: string;
112
+ /**
113
+ * Custom metadata to associate with the account
114
+ */
115
+ metadata?: Record<string, unknown>;
116
+ }
117
+ /**
118
+ * Parameters for getting TOS link
119
+ */
120
+ export interface GetTosLinkParams {
121
+ /**
122
+ * Redirect URI after user accepts terms of service
123
+ * @example "https://myapp.com/callback"
124
+ */
125
+ redirectUri: string;
126
+ }
127
+ /**
128
+ * Result of getting TOS link
129
+ */
130
+ export interface TosLinkResult {
131
+ /**
132
+ * URL to redirect user to accept terms of service
133
+ * @example "https://dashboard.bridge.xyz/accept-terms-of-service?session_token=4d5d8c45-9feb-422a-bb5e-0fd32e3b3c53"
134
+ */
135
+ url: string;
136
+ }
137
+ /**
138
+ * Parameters for listing US accounts
139
+ */
140
+ export interface ListUsAccountsParams {
141
+ /**
142
+ * URN of the account holder (user or organization) to filter by
143
+ * @example "did:bloque:bloque-root:nestor"
144
+ */
145
+ holderUrn?: string;
146
+ /**
147
+ * URN of a specific US account to retrieve
148
+ * @example "did:bloque:account:us-account:usr-123:us-456"
149
+ */
150
+ urn?: string;
151
+ }
152
+ /**
153
+ * Result of listing US accounts
154
+ */
155
+ export interface ListUsAccountsResult {
156
+ /** Array of US accounts with balance information */
157
+ accounts: UsAccount[];
158
+ }
159
+ /**
160
+ * Parameters for updating US account metadata
161
+ */
162
+ export interface UpdateUsMetadataParams {
163
+ /**
164
+ * URN of the US account to update
165
+ * @example "did:bloque:mediums:us-account:account:123e4567"
166
+ */
167
+ urn: string;
168
+ /**
169
+ * Metadata to update
170
+ */
171
+ metadata: Record<string, unknown>;
172
+ }
173
+ /**
174
+ * US account information
175
+ */
176
+ export interface UsAccount {
177
+ /**
178
+ * Unique resource name for the US account
179
+ */
180
+ urn: string;
181
+ /**
182
+ * US account ID
183
+ */
184
+ id: string;
185
+ /**
186
+ * Account type (individual or business)
187
+ */
188
+ type: UsAccountType;
189
+ /**
190
+ * First name
191
+ */
192
+ firstName: string;
193
+ /**
194
+ * Middle name (if provided)
195
+ */
196
+ middleName?: string;
197
+ /**
198
+ * Last name
199
+ */
200
+ lastName: string;
201
+ /**
202
+ * Email address
203
+ */
204
+ email: string;
205
+ /**
206
+ * Phone number
207
+ */
208
+ phone: string;
209
+ /**
210
+ * Address information
211
+ */
212
+ address: UsAccountAddress;
213
+ /**
214
+ * Birth date in YYYY-MM-DD format
215
+ */
216
+ birthDate: string;
217
+ /**
218
+ * Bank account number (if available)
219
+ */
220
+ accountNumber?: string;
221
+ /**
222
+ * Bank routing number (if available)
223
+ */
224
+ routingNumber?: string;
225
+ /**
226
+ * Current status of the account
227
+ */
228
+ status: 'active' | 'disabled' | 'frozen' | 'deleted' | 'creation_in_progress' | 'creation_failed';
229
+ /**
230
+ * Owner URN
231
+ */
232
+ ownerUrn: string;
233
+ /**
234
+ * Ledger account ID associated with this account
235
+ */
236
+ ledgerId: string;
237
+ /**
238
+ * Webhook URL (if configured)
239
+ */
240
+ webhookUrl: string | null;
241
+ /**
242
+ * Custom metadata
243
+ */
244
+ metadata?: Record<string, unknown>;
245
+ /**
246
+ * Creation timestamp
247
+ */
248
+ createdAt: string;
249
+ /**
250
+ * Last update timestamp
251
+ */
252
+ updatedAt: string;
253
+ /**
254
+ * Token balances (only included in list responses)
255
+ */
256
+ balance?: Record<string, TokenBalance>;
257
+ }
@@ -0,0 +1,170 @@
1
+ import { BaseClient } from '@bloque/sdk-core';
2
+ import type { CreateAccountOptions } from '../types';
3
+ import type { CreateUsAccountParams, GetTosLinkParams, ListUsAccountsParams, ListUsAccountsResult, TosLinkResult, UpdateUsMetadataParams, UsAccount } from './types';
4
+ export declare class UsClient extends BaseClient {
5
+ /**
6
+ * Get Terms of Service acceptance link
7
+ *
8
+ * This method generates a URL where users can accept the terms of service
9
+ * required for US account creation. After acceptance, a signed_agreement_id
10
+ * will be provided which is required for account creation.
11
+ *
12
+ * @param params - TOS link parameters
13
+ * @returns Promise resolving to the TOS acceptance URL
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const tosLink = await bloque.accounts.us.getTosLink({
18
+ * redirectUri: 'https://myapp.com/callback'
19
+ * });
20
+ *
21
+ * // Redirect user to tosLink.url
22
+ * // After acceptance, extract signed_agreement_id from callback
23
+ * ```
24
+ */
25
+ getTosLink(params: GetTosLinkParams): Promise<TosLinkResult>;
26
+ /**
27
+ * Create a new US bank account
28
+ *
29
+ * Creates a US bank account after the user has accepted the terms of service.
30
+ * You must first call getTosLink to obtain a signed_agreement_id.
31
+ *
32
+ * @param params - US account creation parameters
33
+ * @param options - Creation options (optional)
34
+ * @returns Promise resolving to the created US account
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * // First, get TOS link and have user accept
39
+ * const tosLink = await bloque.accounts.us.getTosLink({
40
+ * redirectUri: 'https://myapp.com/callback'
41
+ * });
42
+ *
43
+ * // After user accepts, create account with signed_agreement_id
44
+ * const account = await bloque.accounts.us.create({
45
+ * type: 'individual',
46
+ * firstName: 'Robert',
47
+ * middleName: 'James',
48
+ * lastName: 'Johnson',
49
+ * email: 'robert.johnson@example.com',
50
+ * phone: '+12125551234',
51
+ * address: {
52
+ * streetLine1: '456 Wall Street',
53
+ * streetLine2: 'Suite 789',
54
+ * city: 'New York',
55
+ * state: 'NY',
56
+ * postalCode: '10005',
57
+ * country: 'US'
58
+ * },
59
+ * birthDate: '1985-03-15',
60
+ * taxIdentificationNumber: '123-45-6789',
61
+ * govIdCountry: 'US',
62
+ * govIdImageFront: 'base64_encoded_image',
63
+ * signedAgreementId: '0d139f8e-14b0-4540-92ba-4e66c619b533'
64
+ * });
65
+ *
66
+ * // Create and wait for active status
67
+ * const account = await bloque.accounts.us.create({
68
+ * // ... params
69
+ * }, { waitLedger: true });
70
+ * ```
71
+ */
72
+ create(params: CreateUsAccountParams, options?: CreateAccountOptions): Promise<UsAccount>;
73
+ /**
74
+ * List US bank accounts
75
+ *
76
+ * Retrieves a list of US bank accounts, optionally filtered by holder URN or specific account URN.
77
+ *
78
+ * @param params - List parameters (optional)
79
+ * @returns Promise resolving to list of US accounts with balances
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * // List all US accounts for the authenticated holder
84
+ * const result = await bloque.accounts.us.list();
85
+ *
86
+ * // List US accounts for a specific holder
87
+ * const result = await bloque.accounts.us.list({
88
+ * holderUrn: 'did:bloque:bloque-root:nestor'
89
+ * });
90
+ *
91
+ * // Get a specific US account
92
+ * const result = await bloque.accounts.us.list({
93
+ * urn: 'did:bloque:account:us-account:usr-123:us-456'
94
+ * });
95
+ * ```
96
+ */
97
+ list(params?: ListUsAccountsParams): Promise<ListUsAccountsResult>;
98
+ /**
99
+ * Update US account metadata
100
+ *
101
+ * @param params - Metadata update parameters
102
+ * @returns Promise resolving to the updated US account
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * const account = await bloque.accounts.us.updateMetadata({
107
+ * urn: 'did:bloque:mediums:us-account:account:123',
108
+ * metadata: {
109
+ * updated_by: 'admin',
110
+ * update_reason: 'customer_request'
111
+ * }
112
+ * });
113
+ * ```
114
+ */
115
+ updateMetadata(params: UpdateUsMetadataParams): Promise<UsAccount>;
116
+ /**
117
+ * Activate a US account
118
+ *
119
+ * @param urn - US account URN
120
+ * @returns Promise resolving to the updated US account
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * const account = await bloque.accounts.us.activate(
125
+ * 'did:bloque:mediums:us-account:account:123'
126
+ * );
127
+ * ```
128
+ */
129
+ activate(urn: string): Promise<UsAccount>;
130
+ /**
131
+ * Freeze a US account
132
+ *
133
+ * @param urn - US account URN
134
+ * @returns Promise resolving to the updated US account
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * const account = await bloque.accounts.us.freeze(
139
+ * 'did:bloque:mediums:us-account:account:123'
140
+ * );
141
+ * ```
142
+ */
143
+ freeze(urn: string): Promise<UsAccount>;
144
+ /**
145
+ * Disable a US account
146
+ *
147
+ * @param urn - US account URN
148
+ * @returns Promise resolving to the updated US account
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * const account = await bloque.accounts.us.disable(
153
+ * 'did:bloque:mediums:us-account:account:123'
154
+ * );
155
+ * ```
156
+ */
157
+ disable(urn: string): Promise<UsAccount>;
158
+ /**
159
+ * Private method to poll account status until it becomes active
160
+ */
161
+ private _waitForActiveStatus;
162
+ /**
163
+ * Private method to update account status
164
+ */
165
+ private _updateStatus;
166
+ /**
167
+ * Private method to map API response to UsAccount
168
+ */
169
+ private _mapAccountResponse;
170
+ }
@@ -1,3 +1,25 @@
1
+ /**
2
+ * Parameters for listing virtual accounts
3
+ */
4
+ export interface ListVirtualAccountsParams {
5
+ /**
6
+ * URN of the account holder (user or organization) to filter by
7
+ * @example "did:bloque:bloque-root:nestor"
8
+ */
9
+ holderUrn?: string;
10
+ /**
11
+ * URN of a specific virtual account to retrieve
12
+ * @example "did:bloque:account:virtual:275d10a2-0854-4081-9d61-ea506e917335"
13
+ */
14
+ urn?: string;
15
+ }
16
+ /**
17
+ * Result of listing virtual accounts
18
+ */
19
+ export interface ListVirtualAccountsResult {
20
+ /** Array of virtual accounts with balance information */
21
+ accounts: VirtualAccount[];
22
+ }
1
23
  /**
2
24
  * Parameters for creating a virtual account
3
25
  */
@@ -101,4 +123,13 @@ export interface VirtualAccount {
101
123
  * Last update timestamp
102
124
  */
103
125
  updatedAt: string;
126
+ /**
127
+ * Token balances (optional, included in list responses and after creation)
128
+ */
129
+ balance?: Record<string, {
130
+ current: string;
131
+ pending: string;
132
+ in: string;
133
+ out: string;
134
+ }>;
104
135
  }
@@ -1,6 +1,32 @@
1
1
  import { BaseClient } from '@bloque/sdk-core';
2
- import type { CreateVirtualAccountParams, UpdateVirtualMetadataParams, VirtualAccount } from './types';
2
+ import type { CreateAccountOptions } from '../types';
3
+ import type { CreateVirtualAccountParams, ListVirtualAccountsParams, ListVirtualAccountsResult, UpdateVirtualMetadataParams, VirtualAccount } from './types';
3
4
  export declare class VirtualClient extends BaseClient {
5
+ /**
6
+ * List virtual accounts
7
+ *
8
+ * Retrieves a list of virtual accounts, optionally filtered by holder URN or specific account URN.
9
+ *
10
+ * @param params - List parameters (optional)
11
+ * @returns Promise resolving to list of virtual accounts
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // List all virtual accounts for the authenticated holder
16
+ * const result = await bloque.accounts.virtual.list();
17
+ *
18
+ * // List virtual accounts for a specific holder
19
+ * const result = await bloque.accounts.virtual.list({
20
+ * holderUrn: 'did:bloque:bloque-root:nestor'
21
+ * });
22
+ *
23
+ * // Get a specific virtual account
24
+ * const result = await bloque.accounts.virtual.list({
25
+ * urn: 'did:bloque:account:virtual:275d10a2-0854-4081-9d61-ea506e917335'
26
+ * });
27
+ * ```
28
+ */
29
+ list(params?: ListVirtualAccountsParams): Promise<ListVirtualAccountsResult>;
4
30
  /**
5
31
  * Create a new virtual account
6
32
  *
@@ -8,17 +34,29 @@ export declare class VirtualClient extends BaseClient {
8
34
  * They're useful for development and testing purposes.
9
35
  *
10
36
  * @param params - Virtual account creation parameters
37
+ * @param options - Creation options (optional)
11
38
  * @returns Promise resolving to the created virtual account
12
39
  *
13
40
  * @example
14
41
  * ```typescript
42
+ * // Create without waiting
15
43
  * const account = await bloque.accounts.virtual.create({
16
44
  * firstName: 'John',
17
45
  * lastName: 'Doe'
18
46
  * });
47
+ *
48
+ * // Create and wait for active status
49
+ * const account = await bloque.accounts.virtual.create({
50
+ * firstName: 'John',
51
+ * lastName: 'Doe'
52
+ * }, { waitLedger: true });
19
53
  * ```
20
54
  */
21
- create(params: CreateVirtualAccountParams): Promise<VirtualAccount>;
55
+ create(params: CreateVirtualAccountParams, options?: CreateAccountOptions): Promise<VirtualAccount>;
56
+ /**
57
+ * Private method to poll account status until it becomes active
58
+ */
59
+ private _waitForActiveStatus;
22
60
  /**
23
61
  * Update virtual account metadata
24
62
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bloque/sdk-accounts",
3
- "version": "0.0.25",
3
+ "version": "0.0.26",
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.25"
39
+ "@bloque/sdk-core": "0.0.26"
40
40
  }
41
41
  }