@bloque/sdk-swap 0.0.30 → 0.0.32

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.args.customerEmail&&{customer_email:e.args.customerEmail},...e.args.userLegalIdType&&{user_legal_id_type:e.args.userLegalIdType},...e.args.userLegalId&&{user_legal_id:e.args.userLegalId},...e.args.customerData&&{customer_data:{full_name:e.args.customerData.fullName}}}),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{urn:e.urn}}_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,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how,callbackToken:e.result.callback_token}}}}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(),s=`/api/rates?${r}`;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}}}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 s=e.type??"src",r={taker_urn:a,type:s,rate_sig:e.rateSig,from_medium:"pse",to_medium:e.toMedium,deposit_information:this._mapDepositInformationToWire(e.depositInformation)};"src"===s&&e.amountSrc?r.amount_src=e.amountSrc:"dst"===s&&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.args.customerEmail&&{customer_email:e.args.customerEmail},...e.args.userLegalIdType&&{user_legal_id_type:e.args.userLegalIdType},...e.args.userLegalId&&{user_legal_id:e.args.userLegalId},...e.args.customerData&&{customer_data:{full_name:e.args.customerData.fullName}}}),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{urn:e.urn}}_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,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how,callbackToken:e.result.callback_token}}}}class s 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 s=t.toString(),r=`/api/rates?${s}`;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,s as SwapClient};
@@ -68,122 +68,89 @@ 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 PSE top-up
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 DepositInformation {
81
+ urn: string;
100
82
  }
101
83
  /**
102
84
  * @internal
103
- * Payment item in response
85
+ * Create order input for PUT /api/order
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 CreateOrderInput {
88
+ taker_urn: string;
89
+ type: OrderType;
90
+ rate_sig: string;
91
+ from_medium: string;
92
+ to_medium: string;
93
+ amount_src?: string;
94
+ amount_dst?: string;
95
+ deposit_information: DepositInformation;
96
+ args?: Record<string, unknown>;
97
+ node_id?: string;
98
+ metadata?: Record<string, unknown>;
112
99
  }
113
100
  /**
114
101
  * @internal
115
- * Payment summary from API
102
+ * Order from API response
116
103
  */
117
- export interface PaymentSummaryResponse {
104
+ export interface OrderResponse {
105
+ id: string;
106
+ order_sig: string;
107
+ rate_sig: string;
108
+ swap_sig: string;
109
+ taker: string;
110
+ maker: string;
111
+ from_asset: string;
112
+ to_asset: string;
113
+ from_medium: string;
114
+ to_medium: string;
115
+ from_amount: string;
116
+ to_amount: string;
117
+ at: string;
118
+ graph_id: string;
118
119
  status: string;
119
- }
120
- /**
121
- * @internal
122
- * Payment response from API
123
- */
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;
135
120
  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
121
  created_at: string;
143
122
  updated_at: string;
144
- payment_type: string;
145
- items: PaymentItemResponse[];
146
123
  }
147
124
  /**
148
125
  * @internal
149
- * Create payment API response wrapper
126
+ * Execution redirect instructions
150
127
  */
151
- export interface CreatePaymentResponse {
152
- payment: PaymentResponse;
153
- }
154
- /**
155
- * @internal
156
- * Payee info for PSE payment
157
- */
158
- export interface PsePayeeInput {
159
- name: string;
160
- email: string;
161
- id_type: string;
162
- id_number: string;
128
+ export interface ExecutionHow {
129
+ type: string;
130
+ url: string;
163
131
  }
164
132
  /**
165
133
  * @internal
166
- * Initiate PSE payment request body
134
+ * Execution result from auto-execution
167
135
  */
168
- export interface InitiatePsePaymentInput {
169
- payment_urn: string;
170
- payee: PsePayeeInput;
171
- person_type: string;
172
- bank_code: string;
136
+ export interface ExecutionResult {
137
+ node_id: string;
138
+ result: {
139
+ status: string;
140
+ name?: string;
141
+ description?: string;
142
+ how?: ExecutionHow;
143
+ callback_token?: string;
144
+ };
173
145
  }
174
146
  /**
175
147
  * @internal
176
- * Initiate PSE payment response
148
+ * Create order response from PUT /api/order
177
149
  */
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;
150
+ export interface CreateOrderResponse {
151
+ result: {
152
+ order: OrderResponse;
153
+ execution?: ExecutionResult;
154
+ };
155
+ req_id: string;
188
156
  }
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,70 @@ 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: ['kusama'],
43
+ * amountSrc: '10000000'
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',
46
+ * // Create order with auto-execution
47
+ * const result = await bloque.swap.pse.create({
48
+ * rateSig: rates.rates[0].sig,
49
+ * toMedium: 'kusama',
50
+ * amountSrc: '10000000',
51
+ * depositInformation: {
52
+ * urn: 'did:bloque:account:card:usr-xxx:crd-xxx'
71
53
  * },
72
- * personType: 'natural',
73
- * bankCode: '1',
54
+ * args: {
55
+ * bankCode: '1',
56
+ * userType: 'natural',
57
+ * customerEmail: 'user@example.com',
58
+ * userLegalIdType: 'CC',
59
+ * userLegalId: '1234567890',
60
+ * customerData: {
61
+ * fullName: 'John Doe'
62
+ * }
63
+ * }
74
64
  * });
75
65
  *
76
- * // Redirect user to PSE
77
- * window.location.href = result.checkoutUrl;
66
+ * // If execution returned a checkout URL, redirect user
67
+ * if (result.execution?.result.checkoutUrl) {
68
+ * window.location.href = result.execution.result.checkoutUrl;
69
+ * }
78
70
  * ```
79
71
  */
80
- initiatePayment(params: InitiatePsePaymentParams): Promise<InitiatePsePaymentResult>;
72
+ create(params: CreatePseOrderParams): Promise<CreatePseOrderResult>;
81
73
  /**
82
74
  * Maps API bank response to SDK format
83
75
  * @internal
84
76
  */
85
77
  private _mapBankResponse;
86
78
  /**
87
- * Maps API payment response to SDK format
79
+ * Maps SDK deposit information to wire format
80
+ * @internal
81
+ */
82
+ private _mapDepositInformationToWire;
83
+ /**
84
+ * Maps API order response to SDK format
88
85
  * @internal
89
86
  */
90
- private _mapPaymentResponse;
87
+ private _mapOrderResponse;
91
88
  /**
92
- * Maps API payment item response to SDK format
89
+ * Maps API execution result to SDK format
93
90
  * @internal
94
91
  */
95
- private _mapPaymentItemResponse;
92
+ private _mapExecutionResult;
96
93
  }
@@ -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,218 +11,240 @@ export interface Bank {
12
11
  export interface ListBanksResult {
13
12
  banks: Bank[];
14
13
  }
15
- export interface CreateTopUpParams {
16
- /**
17
- * Top-up amount as string (scaled by currency precision)
18
- */
19
- amount: string;
20
- /**
21
- * Currency with precision (e.g., "DUSD/6")
22
- */
23
- currency: Currency;
24
- /**
25
- * URL to redirect on successful payment
26
- */
27
- successUrl?: string;
28
- /**
29
- * Webhook URL for payment notifications
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 PSE top-up
22
+ */
23
+ export interface DepositInformation {
24
+ /**
25
+ * Account URN where funds will be deposited
26
+ * @example "did:bloque:account:card:usr-xxx:crd-xxx"
30
27
  */
31
- webhookUrl?: string;
28
+ urn: string;
32
29
  }
33
- export interface PaymentItemResult {
30
+ /**
31
+ * Customer data for PSE payment
32
+ */
33
+ export interface PseCustomerData {
34
34
  /**
35
- * Item name
35
+ * Customer's full name
36
36
  */
37
- name: string;
37
+ fullName: string;
38
+ }
39
+ /**
40
+ * PSE payment arguments for auto-execution
41
+ */
42
+ export interface PsePaymentArgs {
38
43
  /**
39
- * Item amount (as number)
44
+ * Bank code from PSE banks list
40
45
  */
41
- amount: number;
46
+ bankCode: string;
42
47
  /**
43
- * Stock keeping unit identifier
48
+ * User type: 'natural' for natural person, 'juridica' for legal entity
44
49
  */
45
- sku?: string;
50
+ userType?: 'natural' | 'juridica';
46
51
  /**
47
- * Item description
52
+ * Customer email address
48
53
  */
49
- description?: string;
54
+ customerEmail?: string;
50
55
  /**
51
- * Item quantity
56
+ * User legal ID type (e.g., 'CC', 'NIT', 'CE')
52
57
  */
53
- quantity: number;
58
+ userLegalIdType?: 'CC' | 'NIT' | 'CE';
54
59
  /**
55
- * URL to item image
60
+ * User legal ID number
56
61
  */
57
- imageUrl?: string;
58
- }
59
- export interface PaymentSummary {
62
+ userLegalId?: string;
60
63
  /**
61
- * Payment status
64
+ * Additional customer data
62
65
  */
63
- status: string;
66
+ customerData?: PseCustomerData;
64
67
  }
65
- export interface Payment {
68
+ /**
69
+ * Parameters for creating a PSE swap order
70
+ */
71
+ export interface CreatePseOrderParams {
66
72
  /**
67
- * Payment URN identifier
73
+ * Rate signature from findRates
68
74
  */
69
- urn: string;
75
+ rateSig: string;
70
76
  /**
71
- * Owner URN
77
+ * Destination medium (e.g., 'kreivo', 'bloque')
72
78
  */
73
- ownerUrn: string;
79
+ toMedium: string;
74
80
  /**
75
- * Payment name/title
81
+ * Source amount as bigint string (required if type is 'src')
82
+ * @example "1000000" represents 10000.00 for COP/2
76
83
  */
77
- name: string;
84
+ amountSrc?: string;
78
85
  /**
79
- * Payment description
86
+ * Destination amount as bigint string (required if type is 'dst')
80
87
  */
81
- description?: string;
88
+ amountDst?: string;
82
89
  /**
83
- * Currency with precision
90
+ * Order type (default: 'src')
84
91
  */
85
- currency: Currency;
92
+ type?: OrderType;
86
93
  /**
87
- * Total amount
94
+ * Deposit information with the account URN where funds will be deposited
88
95
  */
89
- amount: number;
96
+ depositInformation: DepositInformation;
90
97
  /**
91
- * Hosted payment URL
98
+ * PSE payment arguments for auto-execution
92
99
  */
93
- url: string;
100
+ args?: PsePaymentArgs;
94
101
  /**
95
- * Success redirect URL
102
+ * Specific node ID to execute (defaults to first node)
96
103
  */
97
- successUrl?: string;
104
+ nodeId?: string;
98
105
  /**
99
- * Cancel redirect URL
100
- */
101
- cancelUrl?: string;
102
- /**
103
- * Payment image URL
104
- */
105
- imageUrl?: string;
106
- /**
107
- * Additional metadata
106
+ * Additional metadata for the order
108
107
  */
109
108
  metadata?: Record<string, unknown>;
109
+ }
110
+ /**
111
+ * Swap order details
112
+ */
113
+ export interface SwapOrder {
110
114
  /**
111
- * Tax amount
115
+ * Unique order identifier
112
116
  */
113
- tax?: number;
117
+ id: string;
114
118
  /**
115
- * Applied discount code
119
+ * Order signature
116
120
  */
117
- discountCode?: string;
121
+ orderSig: string;
118
122
  /**
119
- * Webhook URL
123
+ * Rate signature used for this order
120
124
  */
121
- webhookUrl?: string;
125
+ rateSig: string;
122
126
  /**
123
- * Payout route configuration
127
+ * Swap signature
124
128
  */
125
- payoutRoute: unknown[];
129
+ swapSig: string;
126
130
  /**
127
- * Payment summary
131
+ * Taker URN
128
132
  */
129
- summary: PaymentSummary;
133
+ taker: string;
130
134
  /**
131
- * Expiration date
135
+ * Maker URN
132
136
  */
133
- expiresAt?: string;
137
+ maker: string;
134
138
  /**
135
- * Creation timestamp
139
+ * Source asset
136
140
  */
137
- createdAt: string;
141
+ fromAsset: string;
138
142
  /**
139
- * Last update timestamp
143
+ * Destination asset
140
144
  */
141
- updatedAt: string;
145
+ toAsset: string;
142
146
  /**
143
- * Payment type
147
+ * Source medium
144
148
  */
145
- paymentType: string;
149
+ fromMedium: string;
146
150
  /**
147
- * Payment items
151
+ * Destination medium
148
152
  */
149
- items: PaymentItemResult[];
150
- }
151
- export interface CreateTopUpResult {
152
- payment: Payment;
153
- }
154
- export interface PsePayee {
153
+ toMedium: string;
155
154
  /**
156
- * Full name of the payee
155
+ * Source amount
157
156
  */
158
- name: string;
157
+ fromAmount: string;
159
158
  /**
160
- * Email address
159
+ * Destination amount
161
160
  */
162
- email: string;
161
+ toAmount: string;
163
162
  /**
164
- * ID document type (e.g., "CC" for Cédula de Ciudadanía)
163
+ * Timestamp when the order was created (as string)
165
164
  */
166
- idType: string;
165
+ at: string;
167
166
  /**
168
- * ID document number
167
+ * Instruction graph ID for tracking execution
169
168
  */
170
- idNumber: string;
171
- }
172
- export type PersonType = 'natural' | 'juridica';
173
- export interface InitiatePsePaymentParams {
169
+ graphId: string;
174
170
  /**
175
- * Payment URN from createTopUp
171
+ * Order status (pending, in_progress, completed, failed)
176
172
  */
177
- paymentUrn: string;
173
+ status: string;
178
174
  /**
179
- * Payee information
175
+ * Additional metadata
180
176
  */
181
- payee: PsePayee;
177
+ metadata?: Record<string, unknown>;
182
178
  /**
183
- * Person type (natural or juridica)
179
+ * Creation timestamp
184
180
  */
185
- personType: PersonType;
181
+ createdAt: string;
186
182
  /**
187
- * Bank code from banks list
183
+ * Last update timestamp
188
184
  */
189
- bankCode: string;
185
+ updatedAt: string;
190
186
  }
191
- export interface InitiatePsePaymentResult {
192
- /**
193
- * Payment ID
194
- */
195
- paymentId: string;
196
- /**
197
- * Payment status
198
- */
199
- status: string;
187
+ /**
188
+ * Redirect instructions for completing the payment
189
+ */
190
+ export interface ExecutionHow {
200
191
  /**
201
- * Status message
192
+ * Type of action required (e.g., "REDIRECT")
202
193
  */
203
- message: string;
194
+ type: string;
204
195
  /**
205
- * Payment amount
196
+ * URL to redirect the user to complete the payment
206
197
  */
207
- amount: string;
208
- /**
209
- * Currency
210
- */
211
- currency: Currency;
212
- /**
213
- * PSE checkout URL to redirect the user
214
- */
215
- checkoutUrl: string;
198
+ url: string;
199
+ }
200
+ /**
201
+ * Execution result from auto-execution
202
+ */
203
+ export interface ExecutionResult {
204
+ /**
205
+ * Node ID that was executed
206
+ */
207
+ nodeId: string;
208
+ /**
209
+ * Execution result details
210
+ */
211
+ result: {
212
+ /**
213
+ * Execution status (e.g., "paused")
214
+ */
215
+ status: string;
216
+ /**
217
+ * Name of the current step
218
+ */
219
+ name?: string;
220
+ /**
221
+ * Description of what the user needs to do
222
+ */
223
+ description?: string;
224
+ /**
225
+ * Instructions for completing this step
226
+ */
227
+ how?: ExecutionHow;
228
+ /**
229
+ * Callback token for tracking
230
+ */
231
+ callbackToken?: string;
232
+ };
233
+ }
234
+ /**
235
+ * Result of creating a PSE swap order
236
+ */
237
+ export interface CreatePseOrderResult {
216
238
  /**
217
- * Order ID
239
+ * The created order
218
240
  */
219
- orderId: string;
241
+ order: SwapOrder;
220
242
  /**
221
- * Order status
243
+ * Execution result (if args were provided for auto-execution)
222
244
  */
223
- orderStatus: string;
245
+ execution?: ExecutionResult;
224
246
  /**
225
- * Creation timestamp
247
+ * Request ID for tracking
226
248
  */
227
- createdAt: string;
249
+ requestId: string;
228
250
  }
229
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bloque/sdk-swap",
3
- "version": "0.0.30",
3
+ "version": "0.0.32",
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.30"
37
+ "@bloque/sdk-core": "0.0.32"
38
38
  }
39
39
  }