@coin-voyage/shared 2.1.0 → 2.2.0-beta.1

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.
@@ -1,5 +1,5 @@
1
1
  import { type CurrencyWithBalance, type PayOrder, PayOrderMode } from "../common/index";
2
- import type { PaymentDetails, PaymentDetailsParams, PayOrderParams, PayOrderQuoteParams } from "../types/api";
2
+ import type { ClaimFeesRequest, ClaimFeesResponse, CreateWebhookRequest, GetFeeBalancesResponse, PaymentDetails, PaymentDetailsParams, PayOrderParams, PayOrderQuoteParams, QuoteWithBalance, SwapDataRequest, SwapDataResponse, SwapQuoteRequest, UpdateWebhookRequest, WebhookResponse } from "../types/api";
3
3
  import { type APIEnvironment } from "./config";
4
4
  import { type APIResponse } from "./fetcher";
5
5
  export declare class ApiClient {
@@ -7,7 +7,7 @@ export declare class ApiClient {
7
7
  private readonly environment?;
8
8
  private readonly sessionId?;
9
9
  private readonly version?;
10
- constructor({ apiKey, sessionId, environment, version }: {
10
+ constructor({ apiKey, sessionId, environment, version, }: {
11
11
  apiKey: string;
12
12
  sessionId?: string;
13
13
  environment?: APIEnvironment;
@@ -15,176 +15,176 @@ export declare class ApiClient {
15
15
  });
16
16
  private request;
17
17
  /**
18
- * Fetches a PayOrder by its ID.
19
- *
20
- * Retrieves a PayOrder object from the API using the provided payOrderId.
21
- * This function requires an API key for authentication.
22
- *
23
- * @param {string} payOrderId - The unique identifier of the PayOrder.
24
- * @returns {Promise<APIResponse<PayOrder>>} - The PayOrder object wrapped in an API response if the request is successful.
25
- *
26
- * @example
27
- * const { data: payOrder, error } = await getPayOrder('123456');
28
- */
18
+ * Fetches a PayOrder by its ID.
19
+ *
20
+ * Retrieves a PayOrder object from the API using the provided payOrderId.
21
+ * This function requires an API key for authentication.
22
+ *
23
+ * @param {string} payOrderId - The unique identifier of the PayOrder.
24
+ * @returns {Promise<APIResponse<PayOrder>>} - The PayOrder object wrapped in an API response if the request is successful.
25
+ *
26
+ * @example
27
+ * const { data: payOrder, error } = await getPayOrder('123456');
28
+ */
29
29
  getPayOrder(payOrderId: string): Promise<APIResponse<PayOrder>>;
30
30
  /**
31
- * Creates a `DEPOSIT` PayOrder.
32
- *
33
- * Creates a PayOrder of type `DEPOSIT` with the provided parameters.
34
- *
35
- * @param {PayOrderParams} params - Parameters required to create a deposit PayOrder.
36
- * @returns {Promise<APIResponse<PayOrder>>} - The PayOrder object wrapped in an API response if the request is successful.
37
- *
38
- * @example
39
- * const depositOrderParams = {
40
- * intent: {
41
- * asset: { chain_id: 1, address: null },
42
- * amount: { token_amount: 100 },
43
- * receiving_address: '0x1234...abcd'
44
- * },
45
- * metadata: { description: 'Deposit for account' }
46
- * };
47
- * const { data, error } = await createDepositPayOrder(depositOrderParams);
48
- * if (data) {
49
- * console.log('Deposit PayOrder created:', data);
50
- * }
51
- */
31
+ * Creates a `DEPOSIT` PayOrder.
32
+ *
33
+ * Creates a PayOrder of type `DEPOSIT` with the provided parameters.
34
+ *
35
+ * @param {PayOrderParams} params - Parameters required to create a deposit PayOrder.
36
+ * @returns {Promise<APIResponse<PayOrder>>} - The PayOrder object wrapped in an API response if the request is successful.
37
+ *
38
+ * @example
39
+ * const depositOrderParams = {
40
+ * intent: {
41
+ * asset: { chain_id: 1, address: null },
42
+ * amount: { token_amount: 100 },
43
+ * receiving_address: '0x1234...abcd'
44
+ * },
45
+ * metadata: { description: 'Deposit for account' }
46
+ * };
47
+ * const { data, error } = await createDepositPayOrder(depositOrderParams);
48
+ * if (data) {
49
+ * console.log('Deposit PayOrder created:', data);
50
+ * }
51
+ */
52
52
  createDepositPayOrder(params: PayOrderParams): Promise<APIResponse<PayOrder>>;
53
53
  /**
54
- * Creates a `SALE` PayOrder.
55
- *
56
- * Creates a PayOrder with mode `SALE` with the provided params.
57
- *
58
- * Requires a valid HMAC-SHA256 signature generated by `generateAuthorizationSignature`.
59
- *
60
- * @param {SalePayOrderParams} params - Params required to create a sale PayOrder.
61
- * @param {string} apiSecret - API secret used to generate the authorization signature.
62
- * @returns {Promise<APIResponse<PayOrder>>} - A PayOrder object wrapped in an API response if the request was successful.
63
- *
64
- * @example
65
- * const apiSecret = 'yourApiSecret';
66
- * const response = await createSalePayOrder({
67
- * intent: {
68
- * asset: { chain_id: 1, address: null },
69
- * amount: {
70
- * fiat: {
71
- * amount: 200,
72
- * unit: "USD"
73
- * },
74
- * },
75
- * metadata: {
76
- * items: [
77
- * {
78
- * name: "t-shirt",
79
- * description: "a nice t-shirt",
80
- * image: "https://example.com/tshirt.jpg",
81
- * quantity: 1,
82
- * unit_price: 200,
83
- * currency: "USD"
84
- * }
85
- * ]
86
- * }
87
- * }, apiSecret);
88
- * if (response.data) {
89
- * console.log('Sale PayOrder created:', response.data);
90
- * }
91
- */
54
+ * Creates a `SALE` PayOrder.
55
+ *
56
+ * Creates a PayOrder with mode `SALE` with the provided params.
57
+ *
58
+ * Requires a valid HMAC-SHA256 signature generated by `generateAuthorizationSignature`.
59
+ *
60
+ * @param {SalePayOrderParams} params - Params required to create a sale PayOrder.
61
+ * @param {string} apiSecret - API secret used to generate the authorization signature.
62
+ * @returns {Promise<APIResponse<PayOrder>>} - A PayOrder object wrapped in an API response if the request was successful.
63
+ *
64
+ * @example
65
+ * const apiSecret = 'yourApiSecret';
66
+ * const response = await createSalePayOrder({
67
+ * intent: {
68
+ * asset: { chain_id: 1, address: null },
69
+ * amount: {
70
+ * fiat: {
71
+ * amount: 200,
72
+ * unit: "USD"
73
+ * },
74
+ * },
75
+ * metadata: {
76
+ * items: [
77
+ * {
78
+ * name: "t-shirt",
79
+ * description: "a nice t-shirt",
80
+ * image: "https://example.com/tshirt.jpg",
81
+ * quantity: 1,
82
+ * unit_price: 200,
83
+ * currency: "USD"
84
+ * }
85
+ * ]
86
+ * }
87
+ * }, apiSecret);
88
+ * if (response.data) {
89
+ * console.log('Sale PayOrder created:', response.data);
90
+ * }
91
+ */
92
92
  createSalePayOrder(params: PayOrderParams, apiSecret: string): Promise<APIResponse<PayOrder>>;
93
93
  /**
94
- * Creates a `REFUND` PayOrder.
95
- *
96
- * Creates a PayOrder with mode `REFUND` with the provided params.
97
- *
98
- * Requires a valid HMAC-SHA256 signature generated by `generateAuthorizationSignature`.
99
- *
100
- * @param {string} payOrderId - The unique identifier of the PayOrder to be refunded.
101
- * @param {PayOrderParams} params - Params required to create a refund PayOrder.
102
- * @param {string} apiSecret - API secret used to generate the authorization signature.
103
- * @returns {Promise<APIResponse<PayOrder>>} - A PayOrder object wrapped in an API response if the request was successful.
104
- *
105
- * @example
106
- * const apiSecret = 'yourApiSecret';
107
- * const response = await createRefundPayOrder(refundOrderId, {
108
- * intent: {
109
- * asset: { chain_id: 1, address: null },
110
- * receiving_address: '0x5678...efgh',
111
- * amount: {
112
- * fiat: {
113
- * value: 100,
114
- * unit: "USD"
115
- * }
116
- * }
117
- * },
118
- * metadata: {
119
- * items: [
120
- * {
121
- * name: "refund",
122
- * description: "Refund for t-shirt purchase",
123
- * unit_price: 100,
124
- * currency: "USD"
125
- * }
126
- * ]
127
- * }
128
- * }, apiSecret);
129
- * if (response.data) {
130
- * console.log('Refund PayOrder created:', response.data);
131
- * }
132
- */
94
+ * Creates a `REFUND` PayOrder.
95
+ *
96
+ * Creates a PayOrder with mode `REFUND` with the provided params.
97
+ *
98
+ * Requires a valid HMAC-SHA256 signature generated by `generateAuthorizationSignature`.
99
+ *
100
+ * @param {string} payOrderId - The unique identifier of the PayOrder to be refunded.
101
+ * @param {PayOrderParams} params - Params required to create a refund PayOrder.
102
+ * @param {string} apiSecret - API secret used to generate the authorization signature.
103
+ * @returns {Promise<APIResponse<PayOrder>>} - A PayOrder object wrapped in an API response if the request was successful.
104
+ *
105
+ * @example
106
+ * const apiSecret = 'yourApiSecret';
107
+ * const response = await createRefundPayOrder(refundOrderId, {
108
+ * intent: {
109
+ * asset: { chain_id: 1, address: null },
110
+ * receiving_address: '0x5678...efgh',
111
+ * amount: {
112
+ * fiat: {
113
+ * value: 100,
114
+ * unit: "USD"
115
+ * }
116
+ * }
117
+ * },
118
+ * metadata: {
119
+ * items: [
120
+ * {
121
+ * name: "refund",
122
+ * description: "Refund for t-shirt purchase",
123
+ * unit_price: 100,
124
+ * currency: "USD"
125
+ * }
126
+ * ]
127
+ * }
128
+ * }, apiSecret);
129
+ * if (response.data) {
130
+ * console.log('Refund PayOrder created:', response.data);
131
+ * }
132
+ */
133
133
  createRefundPayOrder(payOrderId: string, params: PayOrderParams, apiSecret: string): Promise<APIResponse<PayOrder>>;
134
134
  createPayOrder(params: PayOrderParams, mode: PayOrderMode, signature?: string): Promise<APIResponse<PayOrder>>;
135
135
  /**
136
- * Generates a PayOrder Quote.
137
- *
138
- * Creates a PayOrder Quote for an existing PayOrder by providing wallet information and chain details.
139
- * This function requires an API key for authentication.
140
- *
141
- * @param {string} orderId - The unique identifier of the PayOrder for which the quote is requested.
142
- * @param {PayOrderQuoteParams} quoteParams - Contains `wallet_address`, `chain_type`, `chain_id`.
143
- * @returns {Promise<APIResponse<CurrencyWithBalance[]>>} - An array of PayTokens wrapped in an API response if the request was successful.
144
- *
145
- * @example
146
- * const orderId = 'existingOrderId';
147
- * const quoteParams = {
148
- * wallet_address: '0x1234...abcd',
149
- * chain_type: ChainType.EVM,
150
- * chain_id: 1 // Ethereum Mainnet
151
- * };
152
- *
153
- * const response = await payOrderQuote(orderId, quoteParams);
154
- * if (response.data) {
155
- * console.log('Available tokens:', response.data);
156
- * }
157
- */
136
+ * Generates a PayOrder Quote.
137
+ *
138
+ * Creates a PayOrder Quote for an existing PayOrder by providing wallet information and chain details.
139
+ * This function requires an API key for authentication.
140
+ *
141
+ * @param {string} orderId - The unique identifier of the PayOrder for which the quote is requested.
142
+ * @param {PayOrderQuoteParams} quoteParams - Contains `wallet_address`, `chain_type`, `chain_id`.
143
+ * @returns {Promise<APIResponse<CurrencyWithBalance[]>>} - An array of PayTokens wrapped in an API response if the request was successful.
144
+ *
145
+ * @example
146
+ * const orderId = 'existingOrderId';
147
+ * const quoteParams = {
148
+ * wallet_address: '0x1234...abcd',
149
+ * chain_type: ChainType.EVM,
150
+ * chain_id: 1 // Ethereum Mainnet
151
+ * };
152
+ *
153
+ * const response = await payOrderQuote(orderId, quoteParams);
154
+ * if (response.data) {
155
+ * console.log('Available tokens:', response.data);
156
+ * }
157
+ */
158
158
  payOrderQuote(orderId: string, quoteParams: PayOrderQuoteParams): Promise<APIResponse<CurrencyWithBalance[]>>;
159
159
  /**
160
- * Retrieves payment details for a specific PayOrder.
161
- *
162
- * This function fetches payment details associated with a specific PayOrder ID.
163
- * It allows specifying the token and blockchain network (via `token_address` and `chain_id`)
164
- * to retrieve source currency information, as well as a refund address for the transaction.
165
- *
166
- * The request is authenticated using the provided API key in the headers.
167
- *
168
- * @param {PaymentDetailsParams} params - Parameters to retrieve the payment details.
169
- * @param {string} params.payorder_id - The unique identifier of the PayOrder for which payment details are fetched.
170
- * @param {string} [params.token_address] - (Optional) The token address of the source currency.
171
- * @param {ChainId} params.chain_id - The blockchain network ID where the token resides.
172
- * @param {string} params.refund_address - The address where funds will be refunded in case of a failed transaction.
173
- *
174
- * @returns {Promise<APIResponse<PaymentDetails>>} - The payment details object wrapped in an API response if the request is successful.
175
- *
176
- * @example
177
- * const response = await payOrderPaymentDetails({
178
- * payorder_id: '12345',
179
- * token_address: '0x1234567890abcdef1234567890abcdef12345678',
180
- * chain_id: 1,
181
- * refund_address: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd',
182
- * });
183
- *
184
- * if (response.data) {
185
- * console.log('Payment details:', response.data);
186
- * }
187
- */
160
+ * Retrieves payment details for a specific PayOrder.
161
+ *
162
+ * This function fetches payment details associated with a specific PayOrder ID.
163
+ * It allows specifying the token and blockchain network (via `token_address` and `chain_id`)
164
+ * to retrieve source currency information, as well as a refund address for the transaction.
165
+ *
166
+ * The request is authenticated using the provided API key in the headers.
167
+ *
168
+ * @param {PaymentDetailsParams} params - Parameters to retrieve the payment details.
169
+ * @param {string} params.payorder_id - The unique identifier of the PayOrder for which payment details are fetched.
170
+ * @param {string} [params.token_address] - (Optional) The token address of the source currency.
171
+ * @param {ChainId} params.chain_id - The blockchain network ID where the token resides.
172
+ * @param {string} params.refund_address - The address where funds will be refunded in case of a failed transaction.
173
+ *
174
+ * @returns {Promise<APIResponse<PaymentDetails>>} - The payment details object wrapped in an API response if the request is successful.
175
+ *
176
+ * @example
177
+ * const response = await payOrderPaymentDetails({
178
+ * payorder_id: '12345',
179
+ * token_address: '0x1234567890abcdef1234567890abcdef12345678',
180
+ * chain_id: 1,
181
+ * refund_address: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd',
182
+ * });
183
+ *
184
+ * if (response.data) {
185
+ * console.log('Payment details:', response.data);
186
+ * }
187
+ */
188
188
  payOrderPaymentDetails(params: PaymentDetailsParams): Promise<APIResponse<PaymentDetails>>;
189
189
  /**
190
190
  * Generates an authorization signature for API requests using HMAC-SHA256.
@@ -211,4 +211,65 @@ export declare class ApiClient {
211
211
  * // APIKey=yourApiKey,signature=a1b2c3d4...,timestamp=1737106896
212
212
  */
213
213
  generateAuthorizationSignature(apiSecret: string, method: string, path: string): string;
214
+ /**
215
+ * Retrieves the claimable fee balances for the authenticated organization.
216
+ *
217
+ * @param {string} apiSecret - API secret used to generate the authorization signature.
218
+ * @returns {Promise<APIResponse<GetFeeBalancesResponse>>} - Fee balances wrapped in an API response.
219
+ */
220
+ getFeeBalances(apiSecret: string): Promise<APIResponse<GetFeeBalancesResponse>>;
221
+ /**
222
+ * Claims accrued fees for the authenticated organization.
223
+ *
224
+ * @param {ClaimFeesRequest} params - Parameters for claiming fees.
225
+ * @param {string} apiSecret - API secret used to generate the authorization signature.
226
+ * @returns {Promise<APIResponse<ClaimFeesResponse>>} - Claim result wrapped in an API response.
227
+ */
228
+ claimFees(params: ClaimFeesRequest, apiSecret: string): Promise<APIResponse<ClaimFeesResponse>>;
229
+ /**
230
+ * Retrieves all webhooks for the authenticated organization.
231
+ *
232
+ * @param {string} apiSecret - API secret used to generate the authorization signature.
233
+ * @returns {Promise<APIResponse<WebhookResponse[]>>} - List of webhooks wrapped in an API response.
234
+ */
235
+ listWebhooks(apiSecret: string): Promise<APIResponse<WebhookResponse[]>>;
236
+ /**
237
+ * Creates a new webhook for the authenticated organization.
238
+ *
239
+ * @param {CreateWebhookRequest} params - Parameters for creating the webhook.
240
+ * @param {string} apiSecret - API secret used to generate the authorization signature.
241
+ * @returns {Promise<APIResponse<WebhookResponse>>} - Created webhook wrapped in an API response.
242
+ */
243
+ createWebhook(params: CreateWebhookRequest, apiSecret: string): Promise<APIResponse<WebhookResponse>>;
244
+ /**
245
+ * Updates an existing webhook for the authenticated organization.
246
+ *
247
+ * @param {string} webhookId - The unique identifier of the webhook to update.
248
+ * @param {UpdateWebhookRequest} params - Parameters for updating the webhook.
249
+ * @param {string} apiSecret - API secret used to generate the authorization signature.
250
+ * @returns {Promise<APIResponse<WebhookResponse>>} - Updated webhook wrapped in an API response.
251
+ */
252
+ updateWebhook(webhookId: string, params: UpdateWebhookRequest, apiSecret: string): Promise<APIResponse<WebhookResponse>>;
253
+ /**
254
+ * Deletes an existing webhook for the authenticated organization.
255
+ *
256
+ * @param {string} webhookId - The unique identifier of the webhook to delete.
257
+ * @param {string} apiSecret - API secret used to generate the authorization signature.
258
+ * @returns {Promise<APIResponse<void>>} - Empty response on success.
259
+ */
260
+ deleteWebhook(webhookId: string, apiSecret: string): Promise<APIResponse<void>>;
261
+ /**
262
+ * Gets a quote for swapping between two currencies.
263
+ *
264
+ * @param {SwapQuoteRequest} params - Parameters for the swap quote.
265
+ * @returns {Promise<APIResponse<QuoteWithBalance>>} - Swap quote wrapped in an API response.
266
+ */
267
+ swapQuote(params: SwapQuoteRequest): Promise<APIResponse<QuoteWithBalance>>;
268
+ /**
269
+ * Gets transaction data for executing a swap.
270
+ *
271
+ * @param {SwapDataRequest} params - Parameters for the swap data.
272
+ * @returns {Promise<APIResponse<SwapDataResponse>>} - Swap data wrapped in an API response.
273
+ */
274
+ swapData(params: SwapDataRequest): Promise<APIResponse<SwapDataResponse>>;
214
275
  }