@coin-voyage/shared 2.3.1 → 2.3.3-beta.0

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 PayOrder, PayOrderMode } from "../types";
2
- import type { ClaimFeesRequest, ClaimFeesResponse, CreateWebhookRequest, GetFeeBalancesResponse, OrderStatusSocket, PaymentDetails, PaymentDetailsParams, PayOrderParams, PayOrderQuoteParams, QuoteWithBalance, RouteQuote, SwapDataRequest, SwapDataResponse, SwapQuoteRequest, UpdateWebhookRequest, WebhookResponse } from "../types/api";
2
+ import type { ClaimFeesRequest, ClaimFeesResponse, CreateWebhookRequest, GetFeeBalancesResponse, OrderStatusSocket, PaymentDetails, PaymentDetailsParams, PayOrderParams, PayOrderQuoteParams, RouteQuote, SwapDataRequest, SwapDataResponse, SwapQuoteRequest, SwapQuoteResponse, 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 {
@@ -262,9 +262,9 @@ export declare class ApiClient {
262
262
  * Gets a quote for swapping between two currencies.
263
263
  *
264
264
  * @param {SwapQuoteRequest} params - Parameters for the swap quote.
265
- * @returns {Promise<APIResponse<QuoteWithBalance>>} - Swap quote wrapped in an API response.
265
+ * @returns {Promise<APIResponse<SwapQuoteResponse>>} - Swap quote wrapped in an API response.
266
266
  */
267
- swapQuote(params: SwapQuoteRequest): Promise<APIResponse<QuoteWithBalance>>;
267
+ swapQuote(params: SwapQuoteRequest): Promise<APIResponse<SwapQuoteResponse>>;
268
268
  /**
269
269
  * Gets transaction data for executing a swap.
270
270
  *
@@ -174,8 +174,26 @@ export class ApiClient {
174
174
  */
175
175
  async createRefundPayOrder(payOrderId, params, apiSecret) {
176
176
  try {
177
+ const result = zPayOrder.safeParse(params);
178
+ if (!result.success) {
179
+ throw new Error(result.error.issues.map((e) => e.message).join(", "));
180
+ }
181
+ if (params.metadata) {
182
+ const result = zPayOrderMetadata.safeParse(params.metadata);
183
+ if (!result.success) {
184
+ throw new Error(result.error.issues.map((e) => e.message).join(", "));
185
+ }
186
+ }
187
+ const path = `/pay-orders/${payOrderId}/refund`;
177
188
  const signature = this.generateAuthorizationSignature(apiSecret, "POST", `/pay-orders/${payOrderId}/refund`);
178
- return this.createPayOrder(params, PayOrderMode.REFUND, signature);
189
+ return this.request({
190
+ path,
191
+ options: {
192
+ method: "POST",
193
+ body: JSON.stringify({ ...params }),
194
+ headers: { Authorization: signature },
195
+ },
196
+ });
179
197
  }
180
198
  catch (error) {
181
199
  return {
@@ -430,7 +448,7 @@ export class ApiClient {
430
448
  * Gets a quote for swapping between two currencies.
431
449
  *
432
450
  * @param {SwapQuoteRequest} params - Parameters for the swap quote.
433
- * @returns {Promise<APIResponse<QuoteWithBalance>>} - Swap quote wrapped in an API response.
451
+ * @returns {Promise<APIResponse<SwapQuoteResponse>>} - Swap quote wrapped in an API response.
434
452
  */
435
453
  async swapQuote(params) {
436
454
  return this.request({
@@ -31,7 +31,7 @@ export const isBitcoinAddress = (address) => {
31
31
  };
32
32
  export const isEthereumAddress = (addr) => /^0x[a-fA-F0-9]{40}$/.test(addr);
33
33
  export const isSolanaAddress = (addr) => /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(addr);
34
- export const isSuiAddress = (addr) => /^0x[a-fA-F0-9]{64}$/.test(addr);
34
+ export const isSuiAddress = (addr) => /^0x[a-fA-F0-9]{1,64}$/.test(addr);
35
35
  export const isTronAddress = (addr) => /^T[1-9A-HJ-NP-Za-km-z]{33}$/.test(addr);
36
36
  export const isValidAddress = (addr, chain) => {
37
37
  switch (chain) {
@@ -65,6 +65,7 @@ export type GetFeeBalancesResponse = FeeBalance;
65
65
  export type ClaimFeesRequest = {
66
66
  currency: CurrencyBase;
67
67
  recipient: string;
68
+ metadata?: PayOrderMetadata;
68
69
  };
69
70
  export type ClaimFeesResponse = {
70
71
  transaction_hash: string;
@@ -99,6 +100,13 @@ export type SwapIntent = {
99
100
  export type SwapQuoteRequest = {
100
101
  intent: SwapIntent;
101
102
  };
103
+ export type SwapQuoteResponse = {
104
+ input: QuoteWithBalance;
105
+ output: CurrencyWithAmount;
106
+ price_impact: number;
107
+ slippage_bps?: number;
108
+ swap_mode: SwapMode;
109
+ };
102
110
  export type RouteQuote = QuoteWithBalance & {
103
111
  qoute_id: string;
104
112
  output: CurrencyWithAmount;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coin-voyage/shared",
3
3
  "description": "Shared utilities for Coin Voyage",
4
- "version": "2.3.1",
4
+ "version": "2.3.3-beta.0",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {