swapped-commerce-sdk 1.0.1 → 1.0.3
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.js +17 -12
- package/package.json +1 -1
- package/src/resources/balances.ts +2 -2
- package/src/resources/kyc.ts +2 -2
- package/src/resources/orders.ts +2 -2
- package/src/resources/paymentRoutes.ts +1 -1
- package/src/resources/payouts.ts +3 -3
- package/src/resources/quotes.ts +20 -8
- package/src/types/index.ts +3 -0
- package/src/types/quotes.ts +40 -8
package/dist/index.js
CHANGED
|
@@ -166,12 +166,12 @@ async function request(config, method, path, options) {
|
|
|
166
166
|
|
|
167
167
|
// src/resources/orders.ts
|
|
168
168
|
async function listOrders(httpConfig, params) {
|
|
169
|
-
return request(httpConfig.config, "GET", "/v1/
|
|
169
|
+
return request(httpConfig.config, "GET", "/v1/orders", {
|
|
170
170
|
params
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
173
|
async function getOrder(httpConfig, orderId) {
|
|
174
|
-
return request(httpConfig.config, "GET", `/v1/
|
|
174
|
+
return request(httpConfig.config, "GET", `/v1/orders/${encodeURIComponent(orderId)}`);
|
|
175
175
|
}
|
|
176
176
|
async function refundOrder(httpConfig, orderId, params) {
|
|
177
177
|
return request(httpConfig.config, "POST", `/v1/merchants/orders/${encodeURIComponent(orderId)}/refund`, {
|
|
@@ -188,7 +188,7 @@ async function createPaymentLink(httpConfig, params) {
|
|
|
188
188
|
|
|
189
189
|
// src/resources/paymentRoutes.ts
|
|
190
190
|
async function createPaymentRoute(httpConfig, params) {
|
|
191
|
-
return request(httpConfig.config, "POST", "/v1/
|
|
191
|
+
return request(httpConfig.config, "POST", "/v1/payment-routes", {
|
|
192
192
|
body: params
|
|
193
193
|
});
|
|
194
194
|
}
|
|
@@ -200,42 +200,47 @@ async function getPayment(httpConfig, paymentId) {
|
|
|
200
200
|
|
|
201
201
|
// src/resources/balances.ts
|
|
202
202
|
async function listBalances(httpConfig, params) {
|
|
203
|
-
return request(httpConfig.config, "GET", "/v1/
|
|
203
|
+
return request(httpConfig.config, "GET", "/v1/balances", {
|
|
204
204
|
params
|
|
205
205
|
});
|
|
206
206
|
}
|
|
207
207
|
async function getBalance(httpConfig, currencyId) {
|
|
208
|
-
return request(httpConfig.config, "GET", `/v1/
|
|
208
|
+
return request(httpConfig.config, "GET", `/v1/balances/${encodeURIComponent(currencyId)}`);
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
// src/resources/quotes.ts
|
|
212
212
|
async function getQuote(httpConfig, params) {
|
|
213
|
-
return request(httpConfig.config, "
|
|
214
|
-
|
|
213
|
+
return request(httpConfig.config, "GET", "/v1/quotes", {
|
|
214
|
+
params: {
|
|
215
|
+
fromAmount: String(params.fromAmount),
|
|
216
|
+
fromFiatCurrency: params.fromFiatCurrency,
|
|
217
|
+
toCurrency: params.toCurrency,
|
|
218
|
+
toBlockchain: params.toBlockchain
|
|
219
|
+
}
|
|
215
220
|
});
|
|
216
221
|
}
|
|
217
222
|
|
|
218
223
|
// src/resources/payouts.ts
|
|
219
224
|
async function createPayout(httpConfig, params) {
|
|
220
|
-
return request(httpConfig.config, "POST", "/v1/
|
|
225
|
+
return request(httpConfig.config, "POST", "/v1/payouts", {
|
|
221
226
|
body: params
|
|
222
227
|
});
|
|
223
228
|
}
|
|
224
229
|
async function listPayouts(httpConfig, params) {
|
|
225
|
-
return request(httpConfig.config, "GET", "/v1/
|
|
230
|
+
return request(httpConfig.config, "GET", "/v1/payouts", {
|
|
226
231
|
params
|
|
227
232
|
});
|
|
228
233
|
}
|
|
229
234
|
async function getPayout(httpConfig, payoutId) {
|
|
230
|
-
return request(httpConfig.config, "GET", `/v1/
|
|
235
|
+
return request(httpConfig.config, "GET", `/v1/payouts/${encodeURIComponent(payoutId)}`);
|
|
231
236
|
}
|
|
232
237
|
|
|
233
238
|
// src/resources/kyc.ts
|
|
234
239
|
async function getKYCStatus(httpConfig, customerId) {
|
|
235
|
-
return request(httpConfig.config, "GET", `/v1/
|
|
240
|
+
return request(httpConfig.config, "GET", `/v1/kyc/${encodeURIComponent(customerId)}`);
|
|
236
241
|
}
|
|
237
242
|
async function submitKYC(httpConfig, params) {
|
|
238
|
-
return request(httpConfig.config, "POST", "/v1/
|
|
243
|
+
return request(httpConfig.config, "POST", "/v1/kyc", {
|
|
239
244
|
body: params
|
|
240
245
|
});
|
|
241
246
|
}
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@ export async function listBalances(
|
|
|
17
17
|
return request<BalancesResponse>(
|
|
18
18
|
httpConfig.config,
|
|
19
19
|
'GET',
|
|
20
|
-
'/v1/
|
|
20
|
+
'/v1/balances',
|
|
21
21
|
{
|
|
22
22
|
params,
|
|
23
23
|
}
|
|
@@ -34,6 +34,6 @@ export async function getBalance(
|
|
|
34
34
|
return request<Balance>(
|
|
35
35
|
httpConfig.config,
|
|
36
36
|
'GET',
|
|
37
|
-
`/v1/
|
|
37
|
+
`/v1/balances/${encodeURIComponent(currencyId)}`
|
|
38
38
|
)
|
|
39
39
|
}
|
package/src/resources/kyc.ts
CHANGED
|
@@ -17,7 +17,7 @@ export async function getKYCStatus(
|
|
|
17
17
|
return request<KYCStatusResponse>(
|
|
18
18
|
httpConfig.config,
|
|
19
19
|
'GET',
|
|
20
|
-
`/v1/
|
|
20
|
+
`/v1/kyc/${encodeURIComponent(customerId)}`
|
|
21
21
|
)
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -31,7 +31,7 @@ export async function submitKYC(
|
|
|
31
31
|
return request<SubmitKYCResponse>(
|
|
32
32
|
httpConfig.config,
|
|
33
33
|
'POST',
|
|
34
|
-
'/v1/
|
|
34
|
+
'/v1/kyc',
|
|
35
35
|
{
|
|
36
36
|
body: params,
|
|
37
37
|
}
|
package/src/resources/orders.ts
CHANGED
|
@@ -16,7 +16,7 @@ export async function listOrders(
|
|
|
16
16
|
httpConfig: HttpConfig,
|
|
17
17
|
params?: Readonly<ListOrdersParams>
|
|
18
18
|
): Promise<ApiResponse<OrdersResponse>> {
|
|
19
|
-
return request<OrdersResponse>(httpConfig.config, 'GET', '/v1/
|
|
19
|
+
return request<OrdersResponse>(httpConfig.config, 'GET', '/v1/orders', {
|
|
20
20
|
params,
|
|
21
21
|
})
|
|
22
22
|
}
|
|
@@ -31,7 +31,7 @@ export async function getOrder(
|
|
|
31
31
|
return request<Order>(
|
|
32
32
|
httpConfig.config,
|
|
33
33
|
'GET',
|
|
34
|
-
`/v1/
|
|
34
|
+
`/v1/orders/${encodeURIComponent(orderId)}`
|
|
35
35
|
)
|
|
36
36
|
}
|
|
37
37
|
|
package/src/resources/payouts.ts
CHANGED
|
@@ -19,7 +19,7 @@ export async function createPayout(
|
|
|
19
19
|
return request<CreatePayoutResponse>(
|
|
20
20
|
httpConfig.config,
|
|
21
21
|
'POST',
|
|
22
|
-
'/v1/
|
|
22
|
+
'/v1/payouts',
|
|
23
23
|
{
|
|
24
24
|
body: params,
|
|
25
25
|
}
|
|
@@ -36,7 +36,7 @@ export async function listPayouts(
|
|
|
36
36
|
return request<PayoutsResponse>(
|
|
37
37
|
httpConfig.config,
|
|
38
38
|
'GET',
|
|
39
|
-
'/v1/
|
|
39
|
+
'/v1/payouts',
|
|
40
40
|
{
|
|
41
41
|
params,
|
|
42
42
|
}
|
|
@@ -53,6 +53,6 @@ export async function getPayout(
|
|
|
53
53
|
return request<Payout>(
|
|
54
54
|
httpConfig.config,
|
|
55
55
|
'GET',
|
|
56
|
-
`/v1/
|
|
56
|
+
`/v1/payouts/${encodeURIComponent(payoutId)}`
|
|
57
57
|
)
|
|
58
58
|
}
|
package/src/resources/quotes.ts
CHANGED
|
@@ -8,17 +8,29 @@ import { request } from '../utils/http'
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Get a quote for currency conversion
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const response = await client.quotes.get({
|
|
15
|
+
* fromAmount: 25,
|
|
16
|
+
* fromFiatCurrency: 'EUR',
|
|
17
|
+
* toCurrency: 'TRX',
|
|
18
|
+
* toBlockchain: 'tron',
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* console.log(response.data.toAmount.afterFees) // "103.802"
|
|
22
|
+
* ```
|
|
11
23
|
*/
|
|
12
24
|
export async function getQuote(
|
|
13
25
|
httpConfig: HttpConfig,
|
|
14
26
|
params: Readonly<GetQuoteParams>
|
|
15
27
|
): Promise<ApiResponse<QuoteResponse>> {
|
|
16
|
-
return request<QuoteResponse>(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
)
|
|
28
|
+
return request<QuoteResponse>(httpConfig.config, 'GET', '/v1/quotes', {
|
|
29
|
+
params: {
|
|
30
|
+
fromAmount: String(params.fromAmount),
|
|
31
|
+
fromFiatCurrency: params.fromFiatCurrency,
|
|
32
|
+
toCurrency: params.toCurrency,
|
|
33
|
+
toBlockchain: params.toBlockchain,
|
|
34
|
+
},
|
|
35
|
+
})
|
|
24
36
|
}
|
package/src/types/index.ts
CHANGED
package/src/types/quotes.ts
CHANGED
|
@@ -1,13 +1,40 @@
|
|
|
1
|
-
import type { Currency } from './currencies'
|
|
1
|
+
import type { Blockchain, Currency } from './currencies'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Simplified currency info returned in quote responses
|
|
5
|
+
*/
|
|
6
|
+
export interface QuoteCurrency {
|
|
7
|
+
readonly symbol: string
|
|
8
|
+
readonly precision: number
|
|
9
|
+
readonly type: 'FIAT' | 'CRYPTO'
|
|
10
|
+
readonly blockchain: { readonly name: string } | null
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Money amount with currency (used in orders and other contexts)
|
|
5
15
|
*/
|
|
6
16
|
export interface MoneyAmount {
|
|
7
17
|
readonly amount: string
|
|
8
18
|
readonly currency: Currency
|
|
9
19
|
}
|
|
10
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Quote from amount with currency
|
|
23
|
+
*/
|
|
24
|
+
export interface QuoteFromAmount {
|
|
25
|
+
readonly amount: string
|
|
26
|
+
readonly currency: QuoteCurrency
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Quote to amount with before/after fees
|
|
31
|
+
*/
|
|
32
|
+
export interface QuoteToAmount {
|
|
33
|
+
readonly beforeFees: string
|
|
34
|
+
readonly afterFees: string
|
|
35
|
+
readonly currency: QuoteCurrency
|
|
36
|
+
}
|
|
37
|
+
|
|
11
38
|
/**
|
|
12
39
|
* Fee information
|
|
13
40
|
*/
|
|
@@ -21,7 +48,7 @@ export interface Fee {
|
|
|
21
48
|
}
|
|
22
49
|
|
|
23
50
|
/**
|
|
24
|
-
* Exchange quote
|
|
51
|
+
* Exchange quote (used in orders)
|
|
25
52
|
*/
|
|
26
53
|
export interface Quote {
|
|
27
54
|
readonly fromAmount: MoneyAmount
|
|
@@ -34,16 +61,21 @@ export interface Quote {
|
|
|
34
61
|
* Parameters for getting a quote
|
|
35
62
|
*/
|
|
36
63
|
export interface GetQuoteParams {
|
|
37
|
-
|
|
64
|
+
/** Amount to convert from */
|
|
65
|
+
readonly fromAmount: string | number
|
|
66
|
+
/** Source fiat currency symbol (e.g., 'EUR', 'USD') */
|
|
67
|
+
readonly fromFiatCurrency: string
|
|
68
|
+
/** Target currency symbol (e.g., 'TRX', 'USDT') */
|
|
38
69
|
readonly toCurrency: string
|
|
39
|
-
|
|
40
|
-
readonly
|
|
70
|
+
/** Target blockchain name (e.g., 'tron', 'ethereum') */
|
|
71
|
+
readonly toBlockchain: string
|
|
41
72
|
}
|
|
42
73
|
|
|
43
74
|
/**
|
|
44
75
|
* Response for getting a quote
|
|
45
76
|
*/
|
|
46
77
|
export interface QuoteResponse {
|
|
47
|
-
readonly
|
|
48
|
-
readonly
|
|
78
|
+
readonly exchangeRateSnapshotId: string
|
|
79
|
+
readonly fromAmount: QuoteFromAmount
|
|
80
|
+
readonly toAmount: QuoteToAmount
|
|
49
81
|
}
|