@bloque/sdk-accounts 0.0.22 → 0.0.24
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/README.md +3 -809
- package/dist/accounts-client.d.ts +43 -0
- package/dist/bancolombia/{client.d.ts → bancolombia-client.d.ts} +1 -2
- package/dist/bancolombia/types.d.ts +1 -1
- package/dist/card/{client.d.ts → card-client.d.ts} +54 -3
- package/dist/card/types.d.ts +69 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.js +1 -1
- package/dist/internal/wire-types.d.ts +243 -0
- package/dist/types.d.ts +48 -0
- package/dist/virtual/types.d.ts +104 -0
- package/dist/virtual/virtual-client.d.ts +90 -0
- package/package.json +2 -2
- package/dist/api-types.d.ts +0 -65
- package/dist/client.d.ts +0 -19
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { HttpClient } from '@bloque/sdk-core';
|
|
2
|
+
import { BaseClient } from '@bloque/sdk-core';
|
|
3
|
+
import { BancolombiaClient } from './bancolombia/bancolombia-client';
|
|
4
|
+
import { CardClient } from './card/card-client';
|
|
5
|
+
import type { TransferParams, TransferResult } from './types';
|
|
6
|
+
import { VirtualClient } from './virtual/virtual-client';
|
|
7
|
+
/**
|
|
8
|
+
* Accounts client for managing financial accounts and payment methods
|
|
9
|
+
*
|
|
10
|
+
* Provides access to various account types through specialized sub-clients:
|
|
11
|
+
* - card: Credit/debit cards
|
|
12
|
+
* - virtual: Virtual accounts
|
|
13
|
+
* - bancolombia: Bancolombia accounts
|
|
14
|
+
* - us: US bank accounts
|
|
15
|
+
* - polygon: Polygon wallets
|
|
16
|
+
*/
|
|
17
|
+
export declare class AccountsClient extends BaseClient {
|
|
18
|
+
readonly bancolombia: BancolombiaClient;
|
|
19
|
+
readonly card: CardClient;
|
|
20
|
+
readonly virtual: VirtualClient;
|
|
21
|
+
constructor(httpClient: HttpClient);
|
|
22
|
+
/**
|
|
23
|
+
* Transfer funds between accounts
|
|
24
|
+
*
|
|
25
|
+
* @param params - Transfer parameters
|
|
26
|
+
* @returns Promise resolving to transfer result
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const transfer = await bloque.accounts.transfer({
|
|
31
|
+
* sourceUrn: 'did:bloque:account:card:usr-123:crd-456',
|
|
32
|
+
* destinationUrn: 'did:bloque:account:virtual:acc-67890',
|
|
33
|
+
* amount: '1000000000000',
|
|
34
|
+
* asset: 'KSM/12',
|
|
35
|
+
* metadata: {
|
|
36
|
+
* reference: 'payment-123',
|
|
37
|
+
* note: 'Monthly subscription'
|
|
38
|
+
* }
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
transfer(params: TransferParams): Promise<TransferResult>;
|
|
43
|
+
}
|
|
@@ -10,12 +10,11 @@ export declare class BancolombiaClient extends BaseClient {
|
|
|
10
10
|
* @example
|
|
11
11
|
* ```typescript
|
|
12
12
|
* const account = await bloque.accounts.bancolombia.create({
|
|
13
|
-
* urn: 'did:bloque:user:123',
|
|
14
13
|
* name: 'Main Account'
|
|
15
14
|
* });
|
|
16
15
|
* ```
|
|
17
16
|
*/
|
|
18
|
-
create(params
|
|
17
|
+
create(params?: CreateBancolombiaAccountParams): Promise<BancolombiaAccount>;
|
|
19
18
|
/**
|
|
20
19
|
* Update Bancolombia account metadata
|
|
21
20
|
*
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BaseClient } from '@bloque/sdk-core';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TokenBalance } from '../internal/wire-types';
|
|
3
|
+
import type { CardAccount, CardMovement, CreateCardParams, GetBalanceParams, ListCardParams, ListMovementsParams, UpdateCardMetadataParams } from './types';
|
|
3
4
|
export declare class CardClient extends BaseClient {
|
|
4
5
|
/**
|
|
5
6
|
* Create a new card account
|
|
@@ -10,12 +11,62 @@ export declare class CardClient extends BaseClient {
|
|
|
10
11
|
* @example
|
|
11
12
|
* ```typescript
|
|
12
13
|
* const card = await bloque.accounts.card.create({
|
|
13
|
-
* urn: 'did:bloque:user:123',
|
|
14
14
|
* name: 'My Card',
|
|
15
15
|
* });
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
|
-
create(params
|
|
18
|
+
create(params?: CreateCardParams): Promise<CardAccount>;
|
|
19
|
+
/**
|
|
20
|
+
* List card accounts for a holder
|
|
21
|
+
*
|
|
22
|
+
* @param params - List parameters
|
|
23
|
+
* @returns Promise resolving to array of card accounts with balances
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const cards = await bloque.accounts.card.list();
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
list(params?: ListCardParams): Promise<CardAccount[]>;
|
|
31
|
+
/**
|
|
32
|
+
* List card account movements/transactions
|
|
33
|
+
*
|
|
34
|
+
* @param params - Movement list parameters
|
|
35
|
+
* @returns Promise resolving to array of card movements
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* // Basic usage
|
|
40
|
+
* const movements = await bloque.accounts.card.movements({
|
|
41
|
+
* urn: 'did:bloque:account:card:usr-123:crd-456',
|
|
42
|
+
* asset: 'DUSD/6',
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* // With pagination and filters
|
|
46
|
+
* const recentMovements = await bloque.accounts.card.movements({
|
|
47
|
+
* urn: 'did:bloque:account:card:usr-123:crd-456',
|
|
48
|
+
* asset: 'DUSD/6',
|
|
49
|
+
* limit: 50,
|
|
50
|
+
* direction: 'in',
|
|
51
|
+
* after: '2025-01-01T00:00:00Z',
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
movements(params: ListMovementsParams): Promise<CardMovement[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Get card account balance
|
|
58
|
+
*
|
|
59
|
+
* @param params - Balance query parameters
|
|
60
|
+
* @returns Promise resolving to token balances
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const balances = await bloque.accounts.card.balance({
|
|
65
|
+
* urn: 'did:bloque:account:card:usr-123:crd-456',
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
balance(params: GetBalanceParams): Promise<Record<string, TokenBalance>>;
|
|
19
70
|
/**
|
|
20
71
|
* Update card account metadata
|
|
21
72
|
*
|
package/dist/card/types.d.ts
CHANGED
|
@@ -1,11 +1,74 @@
|
|
|
1
|
-
import type { CardType } from '../
|
|
2
|
-
|
|
1
|
+
import type { CardType, TokenBalance, Transaction } from '../internal/wire-types';
|
|
2
|
+
import type { SupportedAsset } from '../types';
|
|
3
|
+
export interface ListCardParams {
|
|
3
4
|
/**
|
|
4
5
|
* URN of the account holder (user or organization)
|
|
5
6
|
*
|
|
6
7
|
* @example "did:bloque:user:123e4567"
|
|
7
8
|
*/
|
|
9
|
+
holderUrn?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ListMovementsParams {
|
|
12
|
+
/**
|
|
13
|
+
* URN of the card account
|
|
14
|
+
*
|
|
15
|
+
* @example "did:bloque:account:card:usr-123:crd-456"
|
|
16
|
+
*/
|
|
8
17
|
urn: string;
|
|
18
|
+
/**
|
|
19
|
+
* Asset to filter transactions by
|
|
20
|
+
*
|
|
21
|
+
* @example "USD" (defaults to "USD" if "USD" is provided)
|
|
22
|
+
*/
|
|
23
|
+
asset?: SupportedAsset;
|
|
24
|
+
/**
|
|
25
|
+
* Maximum number of transactions to return
|
|
26
|
+
*
|
|
27
|
+
* @example 50
|
|
28
|
+
*/
|
|
29
|
+
limit?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Filter transactions before this date (ISO 8601)
|
|
32
|
+
*
|
|
33
|
+
* @example "2025-01-01T00:00:00Z"
|
|
34
|
+
*/
|
|
35
|
+
before?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Filter transactions after this date (ISO 8601)
|
|
38
|
+
*
|
|
39
|
+
* @example "2025-01-01T00:00:00Z"
|
|
40
|
+
*/
|
|
41
|
+
after?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Filter by transaction reference
|
|
44
|
+
*
|
|
45
|
+
* @example "0xbff43fa587e0efa275f8b643d95881713c0f0ee13682d049cc452f607241b752"
|
|
46
|
+
*/
|
|
47
|
+
reference?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Filter by transaction direction
|
|
50
|
+
* - 'in' for incoming funds (deposits, transfers received)
|
|
51
|
+
* - 'out' for outgoing funds (withdrawals, transfers sent)
|
|
52
|
+
*/
|
|
53
|
+
direction?: 'in' | 'out';
|
|
54
|
+
}
|
|
55
|
+
export interface CardMovement extends Transaction {
|
|
56
|
+
}
|
|
57
|
+
export interface GetBalanceParams {
|
|
58
|
+
/**
|
|
59
|
+
* URN of the card account
|
|
60
|
+
*
|
|
61
|
+
* @example "did:bloque:account:card:usr-123:crd-456"
|
|
62
|
+
*/
|
|
63
|
+
urn: string;
|
|
64
|
+
}
|
|
65
|
+
export interface CreateCardParams {
|
|
66
|
+
/**
|
|
67
|
+
* URN of the account holder (user or organization)
|
|
68
|
+
*
|
|
69
|
+
* @example "did:bloque:user:123e4567"
|
|
70
|
+
*/
|
|
71
|
+
holderUrn?: string;
|
|
9
72
|
/**
|
|
10
73
|
* Display name for the card
|
|
11
74
|
*/
|
|
@@ -91,4 +154,8 @@ export interface CardAccount {
|
|
|
91
154
|
* Last update timestamp
|
|
92
155
|
*/
|
|
93
156
|
updatedAt: string;
|
|
157
|
+
/**
|
|
158
|
+
* Token balances (only included in list responses)
|
|
159
|
+
*/
|
|
160
|
+
balance?: Record<string, TokenBalance>;
|
|
94
161
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const __rslib_import_meta_url__="u"<typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e
|
|
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,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 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;virtual;constructor(t){super(t),this.bancolombia=new BancolombiaClient(this.httpClient),this.card=new CardClient(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.VirtualClient=__webpack_exports__.VirtualClient,__webpack_exports__)-1===["AccountsClient","BancolombiaClient","CardClient","VirtualClient"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './accounts-client';
|
|
2
|
+
export * from './bancolombia/bancolombia-client';
|
|
2
3
|
export * from './bancolombia/types';
|
|
3
|
-
export * from './card/client';
|
|
4
|
+
export * from './card/card-client';
|
|
4
5
|
export * from './card/types';
|
|
5
|
-
export * from './
|
|
6
|
+
export * from './types';
|
|
7
|
+
export * from './virtual/types';
|
|
8
|
+
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.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.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 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{bancolombia;card;constructor(t){super(t),this.bancolombia=new e(this.httpClient),this.card=new a(this.httpClient)}}export{s as AccountsClient,e as BancolombiaClient,a as CardClient};
|
|
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 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 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 s extends t{bancolombia;card;virtual;constructor(t){super(t),this.bancolombia=new e(this.httpClient),this.card=new a(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},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}}}export{s as AccountsClient,e as BancolombiaClient,a as CardClient,r as VirtualClient};
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
* Wire types for API communication (snake_case format)
|
|
4
|
+
* These types represent the raw API request/response format
|
|
5
|
+
* and should not be used directly by SDK consumers.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
* Account status from API
|
|
10
|
+
*/
|
|
11
|
+
export type AccountStatus = 'active' | 'disabled' | 'frozen' | 'deleted' | 'creation_in_progress' | 'creation_failed';
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
* Raw account from API
|
|
15
|
+
*/
|
|
16
|
+
export interface Account<TDetails = unknown> {
|
|
17
|
+
id: string;
|
|
18
|
+
urn: string;
|
|
19
|
+
medium: 'bancolombia' | 'card' | 'virtual';
|
|
20
|
+
details: TDetails;
|
|
21
|
+
ledger_account_id: string;
|
|
22
|
+
status: AccountStatus;
|
|
23
|
+
owner_urn: string;
|
|
24
|
+
created_at: string;
|
|
25
|
+
updated_at: string;
|
|
26
|
+
webhook_url: string | null;
|
|
27
|
+
metadata?: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @internal
|
|
31
|
+
* Card type enum
|
|
32
|
+
*/
|
|
33
|
+
export type CardType = 'VIRTUAL' | 'PHYSICAL';
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
* Create account request body
|
|
37
|
+
*/
|
|
38
|
+
export interface CreateAccountRequest<TInput = unknown> {
|
|
39
|
+
holder_urn: string;
|
|
40
|
+
ledger_account_id?: string;
|
|
41
|
+
input: TInput;
|
|
42
|
+
metadata?: Record<string, unknown>;
|
|
43
|
+
webhook_url?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @internal
|
|
47
|
+
* Card account input for creation
|
|
48
|
+
*/
|
|
49
|
+
export type CreateCardAccountInput = {
|
|
50
|
+
create: {
|
|
51
|
+
card_type: CardType;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* @internal
|
|
56
|
+
* Create account response
|
|
57
|
+
*/
|
|
58
|
+
export interface CreateAccountResponse<TDetails = unknown> {
|
|
59
|
+
result: {
|
|
60
|
+
account: Account<TDetails>;
|
|
61
|
+
};
|
|
62
|
+
req_id: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @internal
|
|
66
|
+
* Card details from API
|
|
67
|
+
*/
|
|
68
|
+
export type CardDetails = {
|
|
69
|
+
id: string;
|
|
70
|
+
email: string;
|
|
71
|
+
operational_country: 'COL';
|
|
72
|
+
client_id: string;
|
|
73
|
+
card_id: string;
|
|
74
|
+
card_last_four: string;
|
|
75
|
+
card_provider: 'VISA';
|
|
76
|
+
card_product_type: 'CREDIT';
|
|
77
|
+
card_status: 'ACTIVE';
|
|
78
|
+
card_url_details: string;
|
|
79
|
+
card_type: CardType;
|
|
80
|
+
user_id: string;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* @internal
|
|
84
|
+
* Bancolombia details from API
|
|
85
|
+
*/
|
|
86
|
+
export type BancolombiaDetails = {
|
|
87
|
+
id: string;
|
|
88
|
+
reference_code: string;
|
|
89
|
+
payment_agreement_code: string;
|
|
90
|
+
network: string[];
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* @internal
|
|
94
|
+
* Virtual account input for creation
|
|
95
|
+
*/
|
|
96
|
+
export type CreateVirtualAccountInput = {
|
|
97
|
+
first_name: string;
|
|
98
|
+
last_name: string;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* @internal
|
|
102
|
+
* Virtual account details from API
|
|
103
|
+
*/
|
|
104
|
+
export type VirtualDetails = {
|
|
105
|
+
id: string;
|
|
106
|
+
first_name: string;
|
|
107
|
+
last_name: string;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* @internal
|
|
111
|
+
* Update account request body
|
|
112
|
+
*/
|
|
113
|
+
export interface UpdateAccountRequest<TInput = unknown> {
|
|
114
|
+
input?: TInput;
|
|
115
|
+
metadata?: Record<string, unknown>;
|
|
116
|
+
status?: AccountStatus;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* @internal
|
|
120
|
+
* Update account response
|
|
121
|
+
*/
|
|
122
|
+
export interface UpdateAccountResponse<TDetails = unknown> {
|
|
123
|
+
result: {
|
|
124
|
+
account: Account<TDetails>;
|
|
125
|
+
};
|
|
126
|
+
req_id: string;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* @internal
|
|
130
|
+
* Token balance from API
|
|
131
|
+
*/
|
|
132
|
+
export interface TokenBalance {
|
|
133
|
+
current: string;
|
|
134
|
+
pending: string;
|
|
135
|
+
in: string;
|
|
136
|
+
out: string;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* @internal
|
|
140
|
+
* Account with balance from API
|
|
141
|
+
*/
|
|
142
|
+
export interface AccountWithBalance<TDetails = unknown> extends Account<TDetails> {
|
|
143
|
+
balance: Record<string, TokenBalance>;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* @internal
|
|
147
|
+
* List accounts response
|
|
148
|
+
*/
|
|
149
|
+
export interface ListAccountsResponse<TDetails = unknown> {
|
|
150
|
+
accounts: AccountWithBalance<TDetails>[];
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* @internal
|
|
154
|
+
* Transaction metadata from API
|
|
155
|
+
*/
|
|
156
|
+
export interface TransactionMetadata {
|
|
157
|
+
amount?: string;
|
|
158
|
+
asset_type?: string;
|
|
159
|
+
card_id?: string;
|
|
160
|
+
card_last_four?: string;
|
|
161
|
+
card_product_type?: string;
|
|
162
|
+
card_provider?: string;
|
|
163
|
+
currency?: string;
|
|
164
|
+
installments?: string;
|
|
165
|
+
local_amount?: string;
|
|
166
|
+
local_currency?: string;
|
|
167
|
+
local_to_usd_rate?: string;
|
|
168
|
+
merchant_address?: string;
|
|
169
|
+
merchant_city?: string;
|
|
170
|
+
merchant_country?: string;
|
|
171
|
+
merchant_id?: string;
|
|
172
|
+
merchant_mcc?: string;
|
|
173
|
+
merchant_name?: string;
|
|
174
|
+
merchant_terminal_id?: string;
|
|
175
|
+
operation_type?: string;
|
|
176
|
+
original_transaction_id?: string;
|
|
177
|
+
selected_asset?: string;
|
|
178
|
+
transaction_id?: string;
|
|
179
|
+
transaction_type?: string;
|
|
180
|
+
type?: string;
|
|
181
|
+
usd_amount?: string;
|
|
182
|
+
user_id?: string;
|
|
183
|
+
[key: string]: unknown;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* @internal
|
|
187
|
+
* Transaction details from API
|
|
188
|
+
*/
|
|
189
|
+
export interface TransactionDetails {
|
|
190
|
+
metadata: TransactionMetadata;
|
|
191
|
+
type: string;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* @internal
|
|
195
|
+
* Transaction from API
|
|
196
|
+
*/
|
|
197
|
+
export interface Transaction {
|
|
198
|
+
amount: string;
|
|
199
|
+
asset: string;
|
|
200
|
+
from_account_id: string;
|
|
201
|
+
to_account_id: string;
|
|
202
|
+
direction: 'in' | 'out';
|
|
203
|
+
reference: string;
|
|
204
|
+
rail_name: string;
|
|
205
|
+
details: TransactionDetails;
|
|
206
|
+
created_at: string;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* @internal
|
|
210
|
+
* List movements response
|
|
211
|
+
*/
|
|
212
|
+
export interface ListMovementsResponse {
|
|
213
|
+
transactions: Transaction[];
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* @internal
|
|
217
|
+
* Get balance response
|
|
218
|
+
*/
|
|
219
|
+
export interface GetBalanceResponse {
|
|
220
|
+
balance: Record<string, TokenBalance>;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* @internal
|
|
224
|
+
* Transfer request body
|
|
225
|
+
*/
|
|
226
|
+
export interface TransferRequest {
|
|
227
|
+
destination_account_urn: string;
|
|
228
|
+
amount: string;
|
|
229
|
+
asset: string;
|
|
230
|
+
metadata?: Record<string, unknown>;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* @internal
|
|
234
|
+
* Transfer response from API
|
|
235
|
+
*/
|
|
236
|
+
export interface TransferResponse {
|
|
237
|
+
result: {
|
|
238
|
+
queue_id: string;
|
|
239
|
+
status: 'queued' | 'processing' | 'completed' | 'failed';
|
|
240
|
+
message: string;
|
|
241
|
+
};
|
|
242
|
+
req_id: string;
|
|
243
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for @bloque/sdk-accounts
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Supported asset types for transfers and movements
|
|
6
|
+
*/
|
|
7
|
+
export type SupportedAsset = 'DUSD/6' | 'KSM/12';
|
|
8
|
+
/**
|
|
9
|
+
* Parameters for transferring funds between accounts
|
|
10
|
+
*/
|
|
11
|
+
export interface TransferParams {
|
|
12
|
+
/**
|
|
13
|
+
* URN of the source account
|
|
14
|
+
* @example "did:bloque:account:card:usr-123:crd-456"
|
|
15
|
+
*/
|
|
16
|
+
sourceUrn: string;
|
|
17
|
+
/**
|
|
18
|
+
* URN of the destination account
|
|
19
|
+
* @example "did:bloque:account:virtual:acc-67890"
|
|
20
|
+
*/
|
|
21
|
+
destinationUrn: string;
|
|
22
|
+
/**
|
|
23
|
+
* Amount to transfer (as string to preserve precision)
|
|
24
|
+
* @example "1000000000000"
|
|
25
|
+
*/
|
|
26
|
+
amount: string;
|
|
27
|
+
/**
|
|
28
|
+
* Asset to transfer
|
|
29
|
+
* @example "DUSD/6"
|
|
30
|
+
*/
|
|
31
|
+
asset: SupportedAsset;
|
|
32
|
+
/**
|
|
33
|
+
* Optional metadata for the transfer
|
|
34
|
+
* @example { reference: "payment-123", note: "Monthly subscription" }
|
|
35
|
+
*/
|
|
36
|
+
metadata?: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Result of a transfer operation
|
|
40
|
+
*/
|
|
41
|
+
export interface TransferResult {
|
|
42
|
+
/** Unique identifier for the queued transfer */
|
|
43
|
+
queueId: string;
|
|
44
|
+
/** Current status of the transfer */
|
|
45
|
+
status: 'queued' | 'processing' | 'completed' | 'failed';
|
|
46
|
+
/** Human-readable message about the transfer status */
|
|
47
|
+
message: string;
|
|
48
|
+
}
|