@bloque/sdk-swap 0.0.29 → 0.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";const __rslib_import_meta_url__="u"<typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,t)=>{for(var a in t)__webpack_require__.o(t,a)&&!__webpack_require__.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{SwapClient:()=>SwapClient,PseClient:()=>PseClient});const sdk_core_namespaceObject=require("@bloque/sdk-core");class PseClient extends sdk_core_namespaceObject.BaseClient{async banks(){return{banks:(await this.httpClient.request({method:"GET",path:"/api/utils/pse/banks"})).banks.map(e=>this._mapBankResponse(e))}}async createTopUp(e){let t={name:"PSE Top-up",description:"PSE Top-up",currency:e.currency,payment_type:"shopping_cart",items:[{name:"PSE Top-up",amount:e.amount,quantity:1}],success_url:e.successUrl,webhook_url:e.webhookUrl},a=await this.httpClient.request({method:"POST",path:"/api/payments",body:t});return{payment:this._mapPaymentResponse(a.payment)}}async initiatePayment(e){let t={payment_urn:e.paymentUrn,payee:{name:e.payee.name,email:e.payee.email,id_type:e.payee.idType,id_number:e.payee.idNumber},person_type:e.personType,bank_code:e.bankCode},a=await this.httpClient.request({method:"POST",path:"/api/payments/pse",body:t});return{paymentId:a.payment_id,status:a.status,message:a.message,amount:a.amount,currency:a.currency,checkoutUrl:a.checkout_url,orderId:a.order_id,orderStatus:a.order_status,createdAt:a.created_at}}_mapBankResponse(e){return{code:e.financial_institution_code,name:e.financial_institution_name}}_mapPaymentResponse(e){return{urn:e.urn,ownerUrn:e.owner_urn,name:e.name,description:e.description,currency:e.currency,amount:e.amount,url:e.url,successUrl:e.success_url,cancelUrl:e.cancel_url,imageUrl:e.image_url,metadata:e.metadata,tax:e.tax,discountCode:e.discount_code,webhookUrl:e.webhook_url,payoutRoute:e.payout_route,summary:{status:e.summary.status},expiresAt:e.expires_at,createdAt:e.created_at,updatedAt:e.updated_at,paymentType:e.payment_type,items:e.items.map(e=>this._mapPaymentItemResponse(e))}}_mapPaymentItemResponse(e){return{name:e.name,amount:e.amount,sku:e.sku,description:e.description,quantity:e.quantity,imageUrl:e.image_url}}}class SwapClient extends sdk_core_namespaceObject.BaseClient{pse;constructor(e){super(e),this.pse=new PseClient(this.httpClient)}async findRates(e){let t=new URLSearchParams,a=JSON.stringify([e.fromAsset,e.toAsset]);t.append("edge",a),t.append("from_medium",JSON.stringify(e.fromMediums)),t.append("to_medium",JSON.stringify(e.toMediums)),void 0!==e.amountSrc&&t.append("amount_src",e.amountSrc),void 0!==e.amountDst&&t.append("amount_dst",e.amountDst),e.sort&&t.append("sort",e.sort),e.sortBy&&t.append("sort_by",e.sortBy);let r=t.toString(),n=`/api/rates?${r}`;return{rates:(await this.httpClient.request({method:"GET",path:n})).rates.map(e=>this._mapRateResponse(e))}}_mapRateResponse(e){return{id:e.id,sig:e.sig,swapSig:e.swap_sig,maker:e.maker,edge:e.edge,fee:{at:e.fee.at,value:e.fee.value,formula:e.fee.formula,components:e.fee.components.map(e=>({at:e.at,name:e.name,type:e.type,value:e.value,percentage:e.percentage,pair:e.pair,amount:e.amount}))},at:e.at,until:e.until,fromMediums:e.from_medium,toMediums:e.to_medium,rate:e.rate,ratio:e.ratio,fromLimits:e.from_limits,toLimits:e.to_limits,createdAt:e.created_at,updatedAt:e.updated_at}}}for(var __rspack_i in exports.PseClient=__webpack_exports__.PseClient,exports.SwapClient=__webpack_exports__.SwapClient,__webpack_exports__)-1===["PseClient","SwapClient"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
1
+ "use strict";const __rslib_import_meta_url__="u"<typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,t)=>{for(var a in t)__webpack_require__.o(t,a)&&!__webpack_require__.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{SwapClient:()=>SwapClient,PseClient:()=>PseClient});const sdk_core_namespaceObject=require("@bloque/sdk-core");class PseClient extends sdk_core_namespaceObject.BaseClient{async banks(){return{banks:(await this.httpClient.request({method:"GET",path:"/api/utils/pse/banks"})).banks.map(e=>this._mapBankResponse(e))}}async create(e){let t=this.httpClient.urn;if(!t)throw new sdk_core_namespaceObject.BloqueConfigError("User URN is not available. Please connect to a session first.");let a=e.type??"src",r={taker_urn:t,type:a,rate_sig:e.rateSig,from_medium:"pse",to_medium:e.toMedium,deposit_information:this._mapDepositInformationToWire(e.depositInformation??{})};"src"===a&&e.amountSrc?r.amount_src=e.amountSrc:"dst"===a&&e.amountDst&&(r.amount_dst=e.amountDst),e.args&&(r.args={bank_code:e.args.bankCode,...e.args.userType&&{user_type:e.args.userType}}),e.nodeId&&(r.node_id=e.nodeId),e.metadata&&(r.metadata=e.metadata);let o=await this.httpClient.request({method:"PUT",path:"/api/order",body:r});return{order:this._mapOrderResponse(o.result.order),execution:o.result.execution?this._mapExecutionResult(o.result.execution):void 0,requestId:o.req_id}}_mapBankResponse(e){return{code:e.financial_institution_code,name:e.financial_institution_name}}_mapDepositInformationToWire(e){return"ledgerAccountId"in e&&e.ledgerAccountId?{ledger_account_id:e.ledgerAccountId}:"bankCode"in e&&e.bankCode?{bank_code:e.bankCode,account_number:e.accountNumber,account_type:e.accountType}:e}_mapDepositInformationFromWire(e){return"ledger_account_id"in e&&e.ledger_account_id?{ledgerAccountId:e.ledger_account_id}:"bank_code"in e&&e.bank_code?{bankCode:e.bank_code,accountNumber:e.account_number,accountType:e.account_type}:e}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,depositInformation:this._mapDepositInformationFromWire(e.deposit_information),at:e.at,graphId:e.graph_id,status:e.status,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,args:e.result.args,description:e.result.description,checkoutUrl:e.result.checkout_url}}}}class SwapClient extends sdk_core_namespaceObject.BaseClient{pse;constructor(e){super(e),this.pse=new PseClient(this.httpClient)}async findRates(e){let t=new URLSearchParams,a=JSON.stringify([e.fromAsset,e.toAsset]);t.append("edge",a),t.append("from_medium",JSON.stringify(e.fromMediums)),t.append("to_medium",JSON.stringify(e.toMediums)),void 0!==e.amountSrc&&t.append("amount_src",e.amountSrc),void 0!==e.amountDst&&t.append("amount_dst",e.amountDst),e.sort&&t.append("sort",e.sort),e.sortBy&&t.append("sort_by",e.sortBy);let r=t.toString(),o=`/api/rates?${r}`;return{rates:(await this.httpClient.request({method:"GET",path:o})).rates.map(e=>this._mapRateResponse(e))}}_mapRateResponse(e){return{id:e.id,sig:e.sig,swapSig:e.swap_sig,maker:e.maker,edge:e.edge,fee:{at:e.fee.at,value:e.fee.value,formula:e.fee.formula,components:e.fee.components.map(e=>({at:e.at,name:e.name,type:e.type,value:e.value,percentage:e.percentage,pair:e.pair,amount:e.amount}))},at:e.at,until:e.until,fromMediums:e.from_medium,toMediums:e.to_medium,rate:e.rate,ratio:e.ratio,fromLimits:e.from_limits,toLimits:e.to_limits,createdAt:e.created_at,updatedAt:e.updated_at}}}for(var __rspack_i in exports.PseClient=__webpack_exports__.PseClient,exports.SwapClient=__webpack_exports__.SwapClient,__webpack_exports__)-1===["PseClient","SwapClient"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{BaseClient as e}from"@bloque/sdk-core";class t extends e{async banks(){return{banks:(await this.httpClient.request({method:"GET",path:"/api/utils/pse/banks"})).banks.map(e=>this._mapBankResponse(e))}}async createTopUp(e){let t={name:"PSE Top-up",description:"PSE Top-up",currency:e.currency,payment_type:"shopping_cart",items:[{name:"PSE Top-up",amount:e.amount,quantity:1}],success_url:e.successUrl,webhook_url:e.webhookUrl},a=await this.httpClient.request({method:"POST",path:"/api/payments",body:t});return{payment:this._mapPaymentResponse(a.payment)}}async initiatePayment(e){let t={payment_urn:e.paymentUrn,payee:{name:e.payee.name,email:e.payee.email,id_type:e.payee.idType,id_number:e.payee.idNumber},person_type:e.personType,bank_code:e.bankCode},a=await this.httpClient.request({method:"POST",path:"/api/payments/pse",body:t});return{paymentId:a.payment_id,status:a.status,message:a.message,amount:a.amount,currency:a.currency,checkoutUrl:a.checkout_url,orderId:a.order_id,orderStatus:a.order_status,createdAt:a.created_at}}_mapBankResponse(e){return{code:e.financial_institution_code,name:e.financial_institution_name}}_mapPaymentResponse(e){return{urn:e.urn,ownerUrn:e.owner_urn,name:e.name,description:e.description,currency:e.currency,amount:e.amount,url:e.url,successUrl:e.success_url,cancelUrl:e.cancel_url,imageUrl:e.image_url,metadata:e.metadata,tax:e.tax,discountCode:e.discount_code,webhookUrl:e.webhook_url,payoutRoute:e.payout_route,summary:{status:e.summary.status},expiresAt:e.expires_at,createdAt:e.created_at,updatedAt:e.updated_at,paymentType:e.payment_type,items:e.items.map(e=>this._mapPaymentItemResponse(e))}}_mapPaymentItemResponse(e){return{name:e.name,amount:e.amount,sku:e.sku,description:e.description,quantity:e.quantity,imageUrl:e.image_url}}}class a extends e{pse;constructor(e){super(e),this.pse=new t(this.httpClient)}async findRates(e){let t=new URLSearchParams,a=JSON.stringify([e.fromAsset,e.toAsset]);t.append("edge",a),t.append("from_medium",JSON.stringify(e.fromMediums)),t.append("to_medium",JSON.stringify(e.toMediums)),void 0!==e.amountSrc&&t.append("amount_src",e.amountSrc),void 0!==e.amountDst&&t.append("amount_dst",e.amountDst),e.sort&&t.append("sort",e.sort),e.sortBy&&t.append("sort_by",e.sortBy);let n=t.toString(),s=`/api/rates?${n}`;return{rates:(await this.httpClient.request({method:"GET",path:s})).rates.map(e=>this._mapRateResponse(e))}}_mapRateResponse(e){return{id:e.id,sig:e.sig,swapSig:e.swap_sig,maker:e.maker,edge:e.edge,fee:{at:e.fee.at,value:e.fee.value,formula:e.fee.formula,components:e.fee.components.map(e=>({at:e.at,name:e.name,type:e.type,value:e.value,percentage:e.percentage,pair:e.pair,amount:e.amount}))},at:e.at,until:e.until,fromMediums:e.from_medium,toMediums:e.to_medium,rate:e.rate,ratio:e.ratio,fromLimits:e.from_limits,toLimits:e.to_limits,createdAt:e.created_at,updatedAt:e.updated_at}}}export{t as PseClient,a as SwapClient};
1
+ import{BaseClient as e,BloqueConfigError as t}from"@bloque/sdk-core";class a extends e{async banks(){return{banks:(await this.httpClient.request({method:"GET",path:"/api/utils/pse/banks"})).banks.map(e=>this._mapBankResponse(e))}}async create(e){let a=this.httpClient.urn;if(!a)throw new t("User URN is not available. Please connect to a session first.");let o=e.type??"src",r={taker_urn:a,type:o,rate_sig:e.rateSig,from_medium:"pse",to_medium:e.toMedium,deposit_information:this._mapDepositInformationToWire(e.depositInformation??{})};"src"===o&&e.amountSrc?r.amount_src=e.amountSrc:"dst"===o&&e.amountDst&&(r.amount_dst=e.amountDst),e.args&&(r.args={bank_code:e.args.bankCode,...e.args.userType&&{user_type:e.args.userType}}),e.nodeId&&(r.node_id=e.nodeId),e.metadata&&(r.metadata=e.metadata);let s=await this.httpClient.request({method:"PUT",path:"/api/order",body:r});return{order:this._mapOrderResponse(s.result.order),execution:s.result.execution?this._mapExecutionResult(s.result.execution):void 0,requestId:s.req_id}}_mapBankResponse(e){return{code:e.financial_institution_code,name:e.financial_institution_name}}_mapDepositInformationToWire(e){return"ledgerAccountId"in e&&e.ledgerAccountId?{ledger_account_id:e.ledgerAccountId}:"bankCode"in e&&e.bankCode?{bank_code:e.bankCode,account_number:e.accountNumber,account_type:e.accountType}:e}_mapDepositInformationFromWire(e){return"ledger_account_id"in e&&e.ledger_account_id?{ledgerAccountId:e.ledger_account_id}:"bank_code"in e&&e.bank_code?{bankCode:e.bank_code,accountNumber:e.account_number,accountType:e.account_type}:e}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,depositInformation:this._mapDepositInformationFromWire(e.deposit_information),at:e.at,graphId:e.graph_id,status:e.status,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,args:e.result.args,description:e.result.description,checkoutUrl:e.result.checkout_url}}}}class o extends e{pse;constructor(e){super(e),this.pse=new a(this.httpClient)}async findRates(e){let t=new URLSearchParams,a=JSON.stringify([e.fromAsset,e.toAsset]);t.append("edge",a),t.append("from_medium",JSON.stringify(e.fromMediums)),t.append("to_medium",JSON.stringify(e.toMediums)),void 0!==e.amountSrc&&t.append("amount_src",e.amountSrc),void 0!==e.amountDst&&t.append("amount_dst",e.amountDst),e.sort&&t.append("sort",e.sort),e.sortBy&&t.append("sort_by",e.sortBy);let o=t.toString(),r=`/api/rates?${o}`;return{rates:(await this.httpClient.request({method:"GET",path:r})).rates.map(e=>this._mapRateResponse(e))}}_mapRateResponse(e){return{id:e.id,sig:e.sig,swapSig:e.swap_sig,maker:e.maker,edge:e.edge,fee:{at:e.fee.at,value:e.fee.value,formula:e.fee.formula,components:e.fee.components.map(e=>({at:e.at,name:e.name,type:e.type,value:e.value,percentage:e.percentage,pair:e.pair,amount:e.amount}))},at:e.at,until:e.until,fromMediums:e.from_medium,toMediums:e.to_medium,rate:e.rate,ratio:e.ratio,fromLimits:e.from_limits,toLimits:e.to_limits,createdAt:e.created_at,updatedAt:e.updated_at}}}export{a as PseClient,o as SwapClient};
@@ -68,122 +68,94 @@ export interface PseBank {
68
68
  export interface ListPseBanksResponse {
69
69
  banks: PseBank[];
70
70
  }
71
- type Currency = 'DUSD/6' | 'COP/2' | 'KSM/12';
72
71
  /**
73
72
  * @internal
74
- * Payment item in request (snake_case)
73
+ * Order type for swap (source or destination amount specified)
75
74
  */
76
- export interface CreatePaymentItemInput {
77
- name: string;
78
- amount: string;
79
- sku?: string;
80
- description?: string;
81
- quantity: number;
82
- image_url?: string;
83
- }
75
+ export type OrderType = 'src' | 'dst';
84
76
  /**
85
77
  * @internal
86
- * Create payment request body
78
+ * Deposit information for cash-in (fiat to crypto)
87
79
  */
88
- export interface CreatePaymentInput {
89
- name: string;
90
- description?: string;
91
- currency: Currency;
92
- payment_type: string;
93
- image_url?: string;
94
- items: CreatePaymentItemInput[];
95
- success_url?: string;
96
- cancel_url?: string;
97
- metadata?: Record<string, unknown>;
98
- expires_at?: string;
99
- webhook_url?: string;
80
+ export interface DepositInformationCashIn {
81
+ ledger_account_id?: string;
100
82
  }
101
83
  /**
102
84
  * @internal
103
- * Payment item in response
85
+ * Deposit information for cash-out (crypto to fiat)
104
86
  */
105
- export interface PaymentItemResponse {
106
- name: string;
107
- amount: number;
108
- sku?: string;
109
- description?: string;
110
- quantity: number;
111
- image_url?: string;
87
+ export interface DepositInformationCashOut {
88
+ bank_code?: string;
89
+ account_number?: string;
90
+ account_type?: string;
112
91
  }
113
92
  /**
114
93
  * @internal
115
- * Payment summary from API
94
+ * Deposit information union type
116
95
  */
117
- export interface PaymentSummaryResponse {
118
- status: string;
119
- }
96
+ export type DepositInformation = DepositInformationCashIn | DepositInformationCashOut | Record<string, unknown>;
120
97
  /**
121
98
  * @internal
122
- * Payment response from API
99
+ * Create order input for PUT /api/order
123
100
  */
124
- export interface PaymentResponse {
125
- urn: string;
126
- owner_urn: string;
127
- name: string;
128
- description?: string;
129
- currency: Currency;
130
- amount: number;
131
- url: string;
132
- success_url?: string;
133
- cancel_url?: string;
134
- image_url?: string;
101
+ export interface CreateOrderInput {
102
+ taker_urn: string;
103
+ type: OrderType;
104
+ rate_sig: string;
105
+ from_medium: string;
106
+ to_medium: string;
107
+ amount_src?: string;
108
+ amount_dst?: string;
109
+ deposit_information: DepositInformation;
110
+ args?: Record<string, unknown>;
111
+ node_id?: string;
135
112
  metadata?: Record<string, unknown>;
136
- tax?: number;
137
- discount_code?: string;
138
- webhook_url?: string;
139
- payout_route: unknown[];
140
- summary: PaymentSummaryResponse;
141
- expires_at?: string;
142
- created_at: string;
143
- updated_at: string;
144
- payment_type: string;
145
- items: PaymentItemResponse[];
146
- }
147
- /**
148
- * @internal
149
- * Create payment API response wrapper
150
- */
151
- export interface CreatePaymentResponse {
152
- payment: PaymentResponse;
153
113
  }
154
114
  /**
155
115
  * @internal
156
- * Payee info for PSE payment
116
+ * Order from API response
157
117
  */
158
- export interface PsePayeeInput {
159
- name: string;
160
- email: string;
161
- id_type: string;
162
- id_number: string;
118
+ export interface OrderResponse {
119
+ id: string;
120
+ order_sig: string;
121
+ rate_sig: string;
122
+ swap_sig: string;
123
+ taker: string;
124
+ maker: string;
125
+ from_asset: string;
126
+ to_asset: string;
127
+ from_medium: string;
128
+ to_medium: string;
129
+ from_amount: string;
130
+ to_amount: string;
131
+ deposit_information: DepositInformation;
132
+ at: number;
133
+ graph_id: string;
134
+ status: string;
135
+ created_at: string;
136
+ updated_at: string;
163
137
  }
164
138
  /**
165
139
  * @internal
166
- * Initiate PSE payment request body
140
+ * Execution result from auto-execution
167
141
  */
168
- export interface InitiatePsePaymentInput {
169
- payment_urn: string;
170
- payee: PsePayeeInput;
171
- person_type: string;
172
- bank_code: string;
142
+ export interface ExecutionResult {
143
+ node_id: string;
144
+ result: {
145
+ status: string;
146
+ args?: unknown[];
147
+ description?: string;
148
+ checkout_url?: string;
149
+ };
173
150
  }
174
151
  /**
175
152
  * @internal
176
- * Initiate PSE payment response
153
+ * Create order response from PUT /api/order
177
154
  */
178
- export interface InitiatePsePaymentResponse {
179
- payment_id: string;
180
- status: string;
181
- message: string;
182
- amount: string;
183
- currency: Currency;
184
- checkout_url: string;
185
- order_id: string;
186
- order_status: string;
187
- created_at: string;
155
+ export interface CreateOrderResponse {
156
+ result: {
157
+ order: OrderResponse;
158
+ execution?: ExecutionResult;
159
+ };
160
+ req_id: string;
188
161
  }
189
- export {};
@@ -1,5 +1,5 @@
1
1
  import { BaseClient } from '@bloque/sdk-core';
2
- import type { CreateTopUpParams, CreateTopUpResult, InitiatePsePaymentParams, InitiatePsePaymentResult, ListBanksResult } from './types';
2
+ import type { CreatePseOrderParams, CreatePseOrderResult, ListBanksResult } from './types';
3
3
  /**
4
4
  * PSE client for PSE-related utilities
5
5
  *
@@ -24,73 +24,64 @@ export declare class PseClient extends BaseClient {
24
24
  */
25
25
  banks(): Promise<ListBanksResult>;
26
26
  /**
27
- * Create a PSE top-up
27
+ * Create a PSE swap order
28
28
  *
29
- * Creates a payment intent for a PSE top-up/recharge.
30
- * Use the returned payment URN with initiatePayment() to start the PSE flow.
29
+ * Creates a swap order using PSE as the source payment medium.
30
+ * Optionally auto-executes the first instruction node if args are provided.
31
31
  *
32
- * @param params - Top-up creation parameters
33
- * @returns Promise resolving to the created payment
32
+ * @param params - PSE order parameters
33
+ * @returns Promise resolving to the created order with optional execution result
34
34
  *
35
35
  * @example
36
36
  * ```typescript
37
- * const result = await bloque.swap.pse.createTopUp({
38
- * amount: '50000000',
39
- * currency: 'DUSD/6',
40
- * successUrl: 'https://example.com/payment/success',
41
- * webhookUrl: 'https://myapp.com/webhooks/payment',
37
+ * // First find available rates
38
+ * const rates = await bloque.swap.findRates({
39
+ * fromAsset: 'COP/2',
40
+ * toAsset: 'DUSD/6',
41
+ * fromMediums: ['pse'],
42
+ * toMediums: ['kreivo'],
43
+ * amountSrc: '1000000'
42
44
  * });
43
45
  *
44
- * // Use the URN to initiate PSE payment
45
- * console.log(result.payment.urn);
46
- * ```
47
- */
48
- createTopUp(params: CreateTopUpParams): Promise<CreateTopUpResult>;
49
- /**
50
- * Initiate a PSE payment
51
- *
52
- * Initiates the PSE payment flow for a previously created top-up.
53
- * Returns a checkout URL where the user should be redirected to complete the payment.
54
- *
55
- * @param params - PSE payment parameters
56
- * @returns Promise resolving to PSE payment result with checkout URL
57
- *
58
- * @example
59
- * ```typescript
60
- * // First create a top-up
61
- * const topUp = await bloque.swap.pse.createTopUp({...});
62
- *
63
- * // Then initiate PSE payment with user details
64
- * const result = await bloque.swap.pse.initiatePayment({
65
- * paymentUrn: topUp.payment.urn,
66
- * payee: {
67
- * name: 'Juan Pérez García',
68
- * email: 'juan.perez@example.com',
69
- * idType: 'CC',
70
- * idNumber: '1055228746',
71
- * },
72
- * personType: 'natural',
73
- * bankCode: '1',
46
+ * // Create order with auto-execution
47
+ * const result = await bloque.swap.pse.create({
48
+ * rateSig: rates.rates[0].sig,
49
+ * toMedium: 'kreivo',
50
+ * amountSrc: '1000000',
51
+ * depositInformation: { ledgerAccountId: '0x123...' },
52
+ * args: { bankCode: '1007' }
74
53
  * });
75
54
  *
76
- * // Redirect user to PSE
77
- * window.location.href = result.checkoutUrl;
55
+ * // If execution returned a checkout URL, redirect user
56
+ * if (result.execution?.result.checkoutUrl) {
57
+ * window.location.href = result.execution.result.checkoutUrl;
58
+ * }
78
59
  * ```
79
60
  */
80
- initiatePayment(params: InitiatePsePaymentParams): Promise<InitiatePsePaymentResult>;
61
+ create(params: CreatePseOrderParams): Promise<CreatePseOrderResult>;
81
62
  /**
82
63
  * Maps API bank response to SDK format
83
64
  * @internal
84
65
  */
85
66
  private _mapBankResponse;
86
67
  /**
87
- * Maps API payment response to SDK format
68
+ * Maps SDK deposit information to wire format
69
+ * @internal
70
+ */
71
+ private _mapDepositInformationToWire;
72
+ /**
73
+ * Maps wire deposit information to SDK format
74
+ * @internal
75
+ */
76
+ private _mapDepositInformationFromWire;
77
+ /**
78
+ * Maps API order response to SDK format
88
79
  * @internal
89
80
  */
90
- private _mapPaymentResponse;
81
+ private _mapOrderResponse;
91
82
  /**
92
- * Maps API payment item response to SDK format
83
+ * Maps API execution result to SDK format
93
84
  * @internal
94
85
  */
95
- private _mapPaymentItemResponse;
86
+ private _mapExecutionResult;
96
87
  }
@@ -1,4 +1,3 @@
1
- type Currency = 'DUSD/6' | 'COP/2' | 'KSM/12';
2
1
  export interface Bank {
3
2
  /**
4
3
  * Financial institution code
@@ -12,125 +11,153 @@ export interface Bank {
12
11
  export interface ListBanksResult {
13
12
  banks: Bank[];
14
13
  }
15
- export interface CreateTopUpParams {
14
+ /**
15
+ * Order type for swap
16
+ * - 'src': Taker specifies exact source amount to pay
17
+ * - 'dst': Taker specifies exact destination amount to receive
18
+ */
19
+ export type OrderType = 'src' | 'dst';
20
+ /**
21
+ * Deposit information for cash-in (fiat to crypto)
22
+ */
23
+ export interface DepositInformationCashIn {
24
+ ledgerAccountId?: string;
25
+ }
26
+ /**
27
+ * Deposit information for cash-out (crypto to fiat)
28
+ */
29
+ export interface DepositInformationCashOut {
30
+ bankCode?: string;
31
+ accountNumber?: string;
32
+ accountType?: string;
33
+ }
34
+ /**
35
+ * Deposit information union type
36
+ */
37
+ export type DepositInformation = DepositInformationCashIn | DepositInformationCashOut | Record<string, unknown>;
38
+ /**
39
+ * PSE payment arguments for auto-execution
40
+ */
41
+ export interface PsePaymentArgs {
16
42
  /**
17
- * Top-up amount as string (scaled by currency precision)
43
+ * Bank code from PSE banks list
18
44
  */
19
- amount: string;
45
+ bankCode: string;
20
46
  /**
21
- * Currency with precision (e.g., "DUSD/6")
47
+ * User type: '0' for natural person, '1' for legal entity
22
48
  */
23
- currency: Currency;
49
+ userType?: string;
50
+ }
51
+ /**
52
+ * Parameters for creating a PSE swap order
53
+ */
54
+ export interface CreatePseOrderParams {
24
55
  /**
25
- * URL to redirect on successful payment
56
+ * Rate signature from findRates
26
57
  */
27
- successUrl?: string;
58
+ rateSig: string;
28
59
  /**
29
- * Webhook URL for payment notifications
60
+ * Destination medium (e.g., 'kreivo', 'bloque')
30
61
  */
31
- webhookUrl?: string;
32
- }
33
- export interface PaymentItemResult {
62
+ toMedium: string;
34
63
  /**
35
- * Item name
64
+ * Source amount as bigint string (required if type is 'src')
65
+ * @example "1000000" represents 10000.00 for COP/2
36
66
  */
37
- name: string;
67
+ amountSrc?: string;
38
68
  /**
39
- * Item amount (as number)
69
+ * Destination amount as bigint string (required if type is 'dst')
40
70
  */
41
- amount: number;
71
+ amountDst?: string;
42
72
  /**
43
- * Stock keeping unit identifier
73
+ * Order type (default: 'src')
44
74
  */
45
- sku?: string;
75
+ type?: OrderType;
46
76
  /**
47
- * Item description
77
+ * Deposit information for fund delivery
48
78
  */
49
- description?: string;
79
+ depositInformation?: DepositInformation;
50
80
  /**
51
- * Item quantity
81
+ * PSE payment arguments for auto-execution
52
82
  */
53
- quantity: number;
83
+ args?: PsePaymentArgs;
54
84
  /**
55
- * URL to item image
85
+ * Specific node ID to execute (defaults to first node)
56
86
  */
57
- imageUrl?: string;
58
- }
59
- export interface PaymentSummary {
87
+ nodeId?: string;
60
88
  /**
61
- * Payment status
89
+ * Additional metadata for the order
62
90
  */
63
- status: string;
91
+ metadata?: Record<string, unknown>;
64
92
  }
65
- export interface Payment {
93
+ /**
94
+ * Swap order details
95
+ */
96
+ export interface SwapOrder {
66
97
  /**
67
- * Payment URN identifier
98
+ * Unique order identifier
68
99
  */
69
- urn: string;
100
+ id: string;
70
101
  /**
71
- * Owner URN
102
+ * Order signature
72
103
  */
73
- ownerUrn: string;
104
+ orderSig: string;
74
105
  /**
75
- * Payment name/title
106
+ * Rate signature used for this order
76
107
  */
77
- name: string;
108
+ rateSig: string;
78
109
  /**
79
- * Payment description
110
+ * Swap signature
80
111
  */
81
- description?: string;
112
+ swapSig: string;
82
113
  /**
83
- * Currency with precision
114
+ * Taker URN
84
115
  */
85
- currency: Currency;
116
+ taker: string;
86
117
  /**
87
- * Total amount
118
+ * Maker URN
88
119
  */
89
- amount: number;
120
+ maker: string;
90
121
  /**
91
- * Hosted payment URL
122
+ * Source asset
92
123
  */
93
- url: string;
124
+ fromAsset: string;
94
125
  /**
95
- * Success redirect URL
126
+ * Destination asset
96
127
  */
97
- successUrl?: string;
128
+ toAsset: string;
98
129
  /**
99
- * Cancel redirect URL
130
+ * Source medium
100
131
  */
101
- cancelUrl?: string;
132
+ fromMedium: string;
102
133
  /**
103
- * Payment image URL
134
+ * Destination medium
104
135
  */
105
- imageUrl?: string;
136
+ toMedium: string;
106
137
  /**
107
- * Additional metadata
138
+ * Source amount
108
139
  */
109
- metadata?: Record<string, unknown>;
140
+ fromAmount: string;
110
141
  /**
111
- * Tax amount
142
+ * Destination amount
112
143
  */
113
- tax?: number;
144
+ toAmount: string;
114
145
  /**
115
- * Applied discount code
146
+ * Deposit information
116
147
  */
117
- discountCode?: string;
148
+ depositInformation: DepositInformation;
118
149
  /**
119
- * Webhook URL
150
+ * Timestamp when the order was created
120
151
  */
121
- webhookUrl?: string;
152
+ at: number;
122
153
  /**
123
- * Payout route configuration
154
+ * Instruction graph ID for tracking execution
124
155
  */
125
- payoutRoute: unknown[];
156
+ graphId: string;
126
157
  /**
127
- * Payment summary
158
+ * Order status (pending, in_progress, completed, failed)
128
159
  */
129
- summary: PaymentSummary;
130
- /**
131
- * Expiration date
132
- */
133
- expiresAt?: string;
160
+ status: string;
134
161
  /**
135
162
  * Creation timestamp
136
163
  */
@@ -139,91 +166,51 @@ export interface Payment {
139
166
  * Last update timestamp
140
167
  */
141
168
  updatedAt: string;
142
- /**
143
- * Payment type
144
- */
145
- paymentType: string;
146
- /**
147
- * Payment items
148
- */
149
- items: PaymentItemResult[];
150
169
  }
151
- export interface CreateTopUpResult {
152
- payment: Payment;
170
+ /**
171
+ * Execution result from auto-execution
172
+ */
173
+ export interface ExecutionResult {
174
+ /**
175
+ * Node ID that was executed
176
+ */
177
+ nodeId: string;
178
+ /**
179
+ * Execution result details
180
+ */
181
+ result: {
182
+ /**
183
+ * Execution status
184
+ */
185
+ status: string;
186
+ /**
187
+ * Additional arguments
188
+ */
189
+ args?: unknown[];
190
+ /**
191
+ * Description of the result
192
+ */
193
+ description?: string;
194
+ /**
195
+ * PSE checkout URL (if applicable)
196
+ */
197
+ checkoutUrl?: string;
198
+ };
153
199
  }
154
- export interface PsePayee {
155
- /**
156
- * Full name of the payee
157
- */
158
- name: string;
200
+ /**
201
+ * Result of creating a PSE swap order
202
+ */
203
+ export interface CreatePseOrderResult {
159
204
  /**
160
- * Email address
205
+ * The created order
161
206
  */
162
- email: string;
207
+ order: SwapOrder;
163
208
  /**
164
- * ID document type (e.g., "CC" for Cédula de Ciudadanía)
209
+ * Execution result (if args were provided for auto-execution)
165
210
  */
166
- idType: string;
211
+ execution?: ExecutionResult;
167
212
  /**
168
- * ID document number
213
+ * Request ID for tracking
169
214
  */
170
- idNumber: string;
171
- }
172
- export type PersonType = 'natural' | 'juridica';
173
- export interface InitiatePsePaymentParams {
174
- /**
175
- * Payment URN from createTopUp
176
- */
177
- paymentUrn: string;
178
- /**
179
- * Payee information
180
- */
181
- payee: PsePayee;
182
- /**
183
- * Person type (natural or juridica)
184
- */
185
- personType: PersonType;
186
- /**
187
- * Bank code from banks list
188
- */
189
- bankCode: string;
190
- }
191
- export interface InitiatePsePaymentResult {
192
- /**
193
- * Payment ID
194
- */
195
- paymentId: string;
196
- /**
197
- * Payment status
198
- */
199
- status: string;
200
- /**
201
- * Status message
202
- */
203
- message: string;
204
- /**
205
- * Payment amount
206
- */
207
- amount: string;
208
- /**
209
- * Currency
210
- */
211
- currency: Currency;
212
- /**
213
- * PSE checkout URL to redirect the user
214
- */
215
- checkoutUrl: string;
216
- /**
217
- * Order ID
218
- */
219
- orderId: string;
220
- /**
221
- * Order status
222
- */
223
- orderStatus: string;
224
- /**
225
- * Creation timestamp
226
- */
227
- createdAt: string;
215
+ requestId: string;
228
216
  }
229
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bloque/sdk-swap",
3
- "version": "0.0.29",
3
+ "version": "0.0.31",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "bloque",
@@ -34,6 +34,6 @@
34
34
  "node": ">=22"
35
35
  },
36
36
  "dependencies": {
37
- "@bloque/sdk-core": "0.0.28"
37
+ "@bloque/sdk-core": "0.0.31"
38
38
  }
39
39
  }