@coin-voyage/shared 2.3.5-beta.2 → 2.4.0-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.
Files changed (59) hide show
  1. package/dist/api/client.d.ts +20 -4
  2. package/dist/api/client.js +64 -53
  3. package/dist/api/config.d.ts +6 -2
  4. package/dist/api/fetcher.d.ts +1 -1
  5. package/dist/api/fetcher.js +11 -5
  6. package/dist/chain/index.d.ts +3 -0
  7. package/dist/chain/index.js +3 -0
  8. package/dist/{common → currency}/currencies.js +6 -6
  9. package/dist/currency/index.d.ts +2 -0
  10. package/dist/currency/index.js +2 -0
  11. package/dist/{common → currency}/token-list.d.ts +2 -1
  12. package/dist/hooks/use-is-mobile.js +1 -1
  13. package/dist/payment/index.d.ts +1 -0
  14. package/dist/payment/index.js +1 -0
  15. package/dist/payment/payment-steps.d.ts +12 -0
  16. package/dist/payment/payment-steps.js +53 -0
  17. package/dist/schemas/index.d.ts +1 -0
  18. package/dist/schemas/index.js +1 -0
  19. package/dist/{common/validation.js → schemas/pay-order.js} +2 -2
  20. package/dist/types/api.d.ts +24 -6
  21. package/dist/types/enums.d.ts +14 -0
  22. package/dist/types/enums.js +17 -0
  23. package/dist/types/index.d.ts +1 -0
  24. package/dist/types/index.js +1 -0
  25. package/dist/types/model.d.ts +62 -3
  26. package/dist/{common → types}/organization.d.ts +1 -1
  27. package/dist/{common → utils}/browser.d.ts +1 -1
  28. package/dist/utils/index.d.ts +7 -0
  29. package/dist/utils/index.js +7 -0
  30. package/package.json +48 -13
  31. package/dist/common/index.d.ts +0 -14
  32. package/dist/common/index.js +0 -14
  33. /package/dist/{common → chain}/address.d.ts +0 -0
  34. /package/dist/{common → chain}/address.js +0 -0
  35. /package/dist/{common → chain}/chain-explorer.d.ts +0 -0
  36. /package/dist/{common → chain}/chain-explorer.js +0 -0
  37. /package/dist/{common → chain}/chains.d.ts +0 -0
  38. /package/dist/{common → chain}/chains.js +0 -0
  39. /package/dist/{common → currency}/currencies.d.ts +0 -0
  40. /package/dist/{common → currency}/token-list.js +0 -0
  41. /package/dist/{common/validation.d.ts → schemas/pay-order.d.ts} +0 -0
  42. /package/dist/{common → types}/organization.js +0 -0
  43. /package/dist/{common → utils}/assert.d.ts +0 -0
  44. /package/dist/{common → utils}/assert.js +0 -0
  45. /package/dist/{common → utils}/browser.js +0 -0
  46. /package/dist/{common → utils}/debug.d.ts +0 -0
  47. /package/dist/{common → utils}/debug.js +0 -0
  48. /package/dist/{common → utils}/format.d.ts +0 -0
  49. /package/dist/{common → utils}/format.js +0 -0
  50. /package/dist/{common → utils}/i18n/index.d.ts +0 -0
  51. /package/dist/{common → utils}/i18n/index.js +0 -0
  52. /package/dist/{common → utils}/i18n/languages/en.d.ts +0 -0
  53. /package/dist/{common → utils}/i18n/languages/en.js +0 -0
  54. /package/dist/{common → utils}/local-storage.d.ts +0 -0
  55. /package/dist/{common → utils}/local-storage.js +0 -0
  56. /package/dist/{common → utils}/plural.d.ts +0 -0
  57. /package/dist/{common → utils}/plural.js +0 -0
  58. /package/dist/{common → utils}/time.d.ts +0 -0
  59. /package/dist/{common → utils}/time.js +0 -0
@@ -1,5 +1,6 @@
1
- import { type PayOrder, PayOrderMode } from "../types";
2
- import type { ClaimFeesRequest, ClaimFeesResponse, CreateWebhookRequest, GetFeeBalancesResponse, OrderStatusSocket, PaymentDetails, PaymentDetailsParams, PayOrderParams, PayOrderQuoteParams, RouteQuote, SwapDataRequest, SwapDataResponse, SwapQuoteRequest, SwapQuoteResponse, UpdateWebhookRequest, WebhookResponse } from "../types/api";
1
+ import type { ClaimFeesRequest, ClaimFeesResponse, CreateWebhookRequest, GetFeeBalancesResponse, OrderStatusSocket, PaymentDetails, PaymentDetailsParams, PaymentMethodsResponse, PayOrderParams, PayOrderQuoteParams, RouteQuote, SwapDataRequest, SwapDataResponse, SwapQuoteRequest, SwapQuoteResponse, UpdateWebhookRequest, WebhookResponse } from "../types/api";
2
+ import { PayOrderMode } from "../types/enums";
3
+ import type { PayOrder } from "../types/model";
3
4
  import { type APIEnvironment } from "./config";
4
5
  import { type APIResponse } from "./fetcher";
5
6
  type Opts = {
@@ -17,6 +18,9 @@ export declare class ApiClient {
17
18
  version?: string;
18
19
  });
19
20
  private request;
21
+ private getErrorMessage;
22
+ private createBadRequestResponse;
23
+ private validatePayOrderParams;
20
24
  /**
21
25
  * Fetches a PayOrder by its ID.
22
26
  *
@@ -30,6 +34,17 @@ export declare class ApiClient {
30
34
  * const { data: payOrder, error } = await getPayOrder('123456');
31
35
  */
32
36
  getPayOrder(payOrderId: string): Promise<APIResponse<PayOrder>>;
37
+ /**
38
+ * Fetches payment method availability for a PayOrder.
39
+ *
40
+ * Retrieves the currently available payment methods for the provided PayOrder ID,
41
+ * including optional availability reasons and minimum fiat amounts.
42
+ *
43
+ * @param {string} payOrderId - The unique identifier of the PayOrder.
44
+ * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
45
+ * @returns {Promise<APIResponse<PaymentMethodsResponse>>} - Payment method availability wrapped in an API response.
46
+ */
47
+ getPayOrderPaymentMethods(payOrderId: string, opts?: Opts): Promise<APIResponse<PaymentMethodsResponse>>;
33
48
  /**
34
49
  * Creates a `DEPOSIT` PayOrder.
35
50
  *
@@ -175,9 +190,10 @@ export declare class ApiClient {
175
190
  *
176
191
  * @param {PaymentDetailsParams} params - Parameters to retrieve the payment details.
177
192
  * @param {string} params.payorder_id - The unique identifier of the PayOrder for which payment details are fetched.
193
+ * @param {PaymentRail} [params.payment_rail] - (Optional) The payment rail for which to fetch the payment details. default: CRYPTO.
178
194
  * @param {CurrencyBase} [params.source_currency] - (Optional) The source currency information.
179
- * @param {string} params.quote_id - (Optional) The quote ID for the PayOrder.
180
- * @param {string} params.refund_address - The address where funds will be refunded in case of a failed transaction.
195
+ * @param {string} [params.quote_id] - (Optional) The quote ID for the PayOrder.
196
+ * @param {string} [params.refund_address] - (Optional) The address where funds will be refunded in case of a failed transaction.
181
197
  * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
182
198
  *
183
199
  * @returns {Promise<APIResponse<PaymentDetails>>} - The payment details object wrapped in an API response if the request is successful.
@@ -1,6 +1,7 @@
1
1
  import { createHmac } from "crypto";
2
- import { now, zPayOrder, zPayOrderMetadata } from "../common";
3
- import { PayOrderMode } from "../types";
2
+ import { now } from "../utils/time";
3
+ import { zPayOrder, zPayOrderMetadata } from "../schemas/pay-order";
4
+ import { PayOrderMode } from "../types/enums";
4
5
  import { WS_URL } from "./config";
5
6
  import { fetchApi } from "./fetcher";
6
7
  export class ApiClient {
@@ -25,6 +26,35 @@ export class ApiClient {
25
26
  },
26
27
  });
27
28
  }
29
+ getErrorMessage(error) {
30
+ if (error instanceof Error) {
31
+ return error.message;
32
+ }
33
+ return "An unknown error occurred";
34
+ }
35
+ createBadRequestResponse(path, error) {
36
+ return {
37
+ error: {
38
+ path,
39
+ statusCode: 400,
40
+ status: "Bad Request",
41
+ message: this.getErrorMessage(error),
42
+ },
43
+ };
44
+ }
45
+ validatePayOrderParams(params) {
46
+ const payOrderResult = zPayOrder.safeParse(params);
47
+ if (!payOrderResult.success) {
48
+ throw new Error(payOrderResult.error.issues.map((issue) => issue.message).join(", "));
49
+ }
50
+ if (!params.metadata) {
51
+ return;
52
+ }
53
+ const metadataResult = zPayOrderMetadata.safeParse(params.metadata);
54
+ if (!metadataResult.success) {
55
+ throw new Error(metadataResult.error.issues.map((issue) => issue.message).join(", "));
56
+ }
57
+ }
28
58
  /**
29
59
  * Fetches a PayOrder by its ID.
30
60
  *
@@ -40,6 +70,25 @@ export class ApiClient {
40
70
  async getPayOrder(payOrderId) {
41
71
  return this.request({ path: `/pay-orders/${payOrderId}` });
42
72
  }
73
+ /**
74
+ * Fetches payment method availability for a PayOrder.
75
+ *
76
+ * Retrieves the currently available payment methods for the provided PayOrder ID,
77
+ * including optional availability reasons and minimum fiat amounts.
78
+ *
79
+ * @param {string} payOrderId - The unique identifier of the PayOrder.
80
+ * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
81
+ * @returns {Promise<APIResponse<PaymentMethodsResponse>>} - Payment method availability wrapped in an API response.
82
+ */
83
+ async getPayOrderPaymentMethods(payOrderId, opts) {
84
+ return this.request({
85
+ path: `/pay-orders/${payOrderId}/payment-methods`,
86
+ options: {
87
+ method: "GET",
88
+ headers: opts?.headers,
89
+ },
90
+ });
91
+ }
43
92
  /**
44
93
  * Creates a `DEPOSIT` PayOrder.
45
94
  *
@@ -65,17 +114,10 @@ export class ApiClient {
65
114
  */
66
115
  async createDepositPayOrder(params, opts) {
67
116
  try {
68
- return this.createPayOrder(params, PayOrderMode.DEPOSIT, undefined, opts);
117
+ return await this.createPayOrder(params, PayOrderMode.DEPOSIT, undefined, opts);
69
118
  }
70
119
  catch (error) {
71
- return {
72
- error: {
73
- path: `/pay-orders`,
74
- statusCode: 400,
75
- status: "Bad Request",
76
- message: error.message,
77
- },
78
- };
120
+ return this.createBadRequestResponse(`/pay-orders`, error);
79
121
  }
80
122
  }
81
123
  /**
@@ -121,17 +163,10 @@ export class ApiClient {
121
163
  async createSalePayOrder(params, apiSecret, opts) {
122
164
  try {
123
165
  const signature = this.generateAuthorizationSignature(apiSecret, "POST", "/pay-orders");
124
- return this.createPayOrder(params, PayOrderMode.SALE, signature, opts);
166
+ return await this.createPayOrder(params, PayOrderMode.SALE, signature, opts);
125
167
  }
126
168
  catch (error) {
127
- return {
128
- error: {
129
- path: `/pay-orders`,
130
- statusCode: 400,
131
- status: "Bad Request",
132
- message: error.message,
133
- },
134
- };
169
+ return this.createBadRequestResponse(`/pay-orders`, error);
135
170
  }
136
171
  }
137
172
  /**
@@ -176,20 +211,11 @@ export class ApiClient {
176
211
  * }
177
212
  */
178
213
  async createRefundPayOrder(payOrderId, params, apiSecret, opts) {
214
+ const path = `/pay-orders/${payOrderId}/refund`;
179
215
  try {
180
- const result = zPayOrder.safeParse(params);
181
- if (!result.success) {
182
- throw new Error(result.error.issues.map((e) => e.message).join(", "));
183
- }
184
- if (params.metadata) {
185
- const result = zPayOrderMetadata.safeParse(params.metadata);
186
- if (!result.success) {
187
- throw new Error(result.error.issues.map((e) => e.message).join(", "));
188
- }
189
- }
190
- const path = `/pay-orders/${payOrderId}/refund`;
216
+ this.validatePayOrderParams(params);
191
217
  const signature = this.generateAuthorizationSignature(apiSecret, "POST", path);
192
- return this.request({
218
+ return await this.request({
193
219
  path,
194
220
  options: {
195
221
  method: "POST",
@@ -199,27 +225,11 @@ export class ApiClient {
199
225
  });
200
226
  }
201
227
  catch (error) {
202
- return {
203
- error: {
204
- path: `/pay-orders/${payOrderId}/refund`,
205
- statusCode: 400,
206
- status: "Bad Request",
207
- message: error.message,
208
- },
209
- };
228
+ return this.createBadRequestResponse(path, error);
210
229
  }
211
230
  }
212
231
  async createPayOrder(params, mode, signature, opts) {
213
- const result = zPayOrder.safeParse(params);
214
- if (!result.success) {
215
- throw new Error(result.error.issues.map((e) => e.message).join(", "));
216
- }
217
- if (params.metadata) {
218
- const result = zPayOrderMetadata.safeParse(params.metadata);
219
- if (!result.success) {
220
- throw new Error(result.error.issues.map((e) => e.message).join(", "));
221
- }
222
- }
232
+ this.validatePayOrderParams(params);
223
233
  if ([PayOrderMode.SALE, PayOrderMode.REFUND].includes(mode) && !signature) {
224
234
  throw new Error(`Signature is required for ${mode} PayOrders`);
225
235
  }
@@ -278,9 +288,10 @@ export class ApiClient {
278
288
  *
279
289
  * @param {PaymentDetailsParams} params - Parameters to retrieve the payment details.
280
290
  * @param {string} params.payorder_id - The unique identifier of the PayOrder for which payment details are fetched.
291
+ * @param {PaymentRail} [params.payment_rail] - (Optional) The payment rail for which to fetch the payment details. default: CRYPTO.
281
292
  * @param {CurrencyBase} [params.source_currency] - (Optional) The source currency information.
282
- * @param {string} params.quote_id - (Optional) The quote ID for the PayOrder.
283
- * @param {string} params.refund_address - The address where funds will be refunded in case of a failed transaction.
293
+ * @param {string} [params.quote_id] - (Optional) The quote ID for the PayOrder.
294
+ * @param {string} [params.refund_address] - (Optional) The address where funds will be refunded in case of a failed transaction.
284
295
  * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
285
296
  *
286
297
  * @returns {Promise<APIResponse<PaymentDetails>>} - The payment details object wrapped in an API response if the request is successful.
@@ -357,7 +368,7 @@ export class ApiClient {
357
368
  * @returns {Promise<APIResponse<WebhookResponse[]>>} - List of webhooks wrapped in an API response.
358
369
  */
359
370
  async listWebhooks(apiSecret, opts) {
360
- const signature = this.generateAuthorizationSignature(apiSecret, "GET", "/organizations/webhooks");
371
+ const signature = this.generateAuthorizationSignature(apiSecret, "GET", "/webhooks");
361
372
  return this.request({
362
373
  path: "/webhooks",
363
374
  options: {
@@ -1,3 +1,7 @@
1
- export declare const API_URL: Record<string, string>;
2
- export declare const WS_URL: Record<string, string>;
1
+ export declare const API_URL: {
2
+ readonly production: "https://api.coinvoyage.io/v2";
3
+ readonly development: "https://acc-api.coinvoyage.io/v2";
4
+ readonly local: "http://localhost:8000/v2";
5
+ };
3
6
  export type APIEnvironment = keyof typeof API_URL;
7
+ export declare const WS_URL: Record<APIEnvironment, string>;
@@ -1,4 +1,4 @@
1
- import { APIEnvironment } from "./config";
1
+ import { type APIEnvironment } from "./config";
2
2
  type FetchApiOptions = {
3
3
  path: string;
4
4
  environment?: APIEnvironment;
@@ -1,14 +1,20 @@
1
1
  import { API_URL } from "./config";
2
+ function buildHeaders(options) {
3
+ const headers = new Headers(options?.headers);
4
+ if (!headers.has("Accept")) {
5
+ headers.set("Accept", "application/json");
6
+ }
7
+ if (options?.body !== undefined && !headers.has("Content-Type")) {
8
+ headers.set("Content-Type", "application/json");
9
+ }
10
+ return headers;
11
+ }
2
12
  export async function fetchApi(opts) {
3
13
  try {
4
14
  const baseUrl = API_URL[opts.environment || "production"];
5
15
  const response = await fetch(`${baseUrl}${opts.path}`, {
6
16
  ...opts.options,
7
- headers: {
8
- ...opts.options?.headers,
9
- "Content-Type": "application/json",
10
- "Accept-Encoding": "gzip, deflate, br",
11
- },
17
+ headers: buildHeaders(opts.options),
12
18
  });
13
19
  if (!response.ok) {
14
20
  const message = await response.text();
@@ -0,0 +1,3 @@
1
+ export * from "./address";
2
+ export * from "./chain-explorer";
3
+ export * from "./chains";
@@ -0,0 +1,3 @@
1
+ export * from "./address";
2
+ export * from "./chain-explorer";
3
+ export * from "./chains";
@@ -7,13 +7,13 @@ export const currencyRateUSD = {
7
7
  rateUSD: 1,
8
8
  };
9
9
  const data = [
10
- ["Euro", "", "EUR", 2],
11
- ["British Pound", "£", "GBP", 2],
10
+ ["Euro", "€", "EUR", 2],
11
+ ["British Pound", "£", "GBP", 2],
12
12
  ["New Taiwan Dollar", "NT$", "TWD", 0],
13
- ["Swiss Franc", "", "CHF", 2],
14
- ["Japanese Yen", "¥", "JPY", 0],
15
- ["Korean Won", "", "KRW", 0],
16
- ["Yuan", "¥", "CNY", 0],
13
+ ["Swiss Franc", "â‚£", "CHF", 2],
14
+ ["Japanese Yen", "Â¥", "JPY", 0],
15
+ ["Korean Won", "â‚©", "KRW", 0],
16
+ ["Yuan", "Â¥", "CNY", 0],
17
17
  ["Canadian Dollar", "C$", "CAD", 2],
18
18
  ["Australian Dollar", "A$", "AUD", 2],
19
19
  ["Singapore Dollar", "S$", "SGD", 2],
@@ -0,0 +1,2 @@
1
+ export * from "./currencies";
2
+ export * from "./token-list";
@@ -0,0 +1,2 @@
1
+ export * from "./currencies";
2
+ export * from "./token-list";
@@ -1,4 +1,5 @@
1
- import type { ChainId, Currency, CurrencyBase } from "../types";
1
+ import type { ChainId } from "../types/enums";
2
+ import type { Currency, CurrencyBase } from "../types/model";
2
3
  export interface Token {
3
4
  name: string;
4
5
  address?: string;
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useState } from "react";
2
- import { isMobile } from "../common/browser";
2
+ import { isMobile } from "../utils/browser";
3
3
  export default function useIsMobile() {
4
4
  const [mobile, setMobile] = useState(isMobile());
5
5
  useEffect(() => {
@@ -0,0 +1 @@
1
+ export * from "./payment-steps";
@@ -0,0 +1 @@
1
+ export * from "./payment-steps";
@@ -0,0 +1,12 @@
1
+ import { type BitcoinPaymentData, type CryptoPaymentData, type EVMPaymentData, type FiatPaymentData, type PaymentData, type PaymentStep, type SolanaPaymentData, type SuiPaymentData } from "../types/model";
2
+ export declare function getFiatPaymentStep(payment?: PaymentData): PaymentStep | undefined;
3
+ export declare function getFiatPaymentData(payment?: PaymentData): FiatPaymentData | undefined;
4
+ export declare function getCryptoDepositStep(payment?: PaymentData): PaymentStep | undefined;
5
+ export declare function getCryptoTransactionStep(payment?: PaymentData): PaymentStep | undefined;
6
+ export declare function getWalletPaymentStep(payment?: PaymentData): PaymentStep | undefined;
7
+ export declare function getWalletPaymentData(payment?: PaymentData): CryptoPaymentData | undefined;
8
+ export declare function getDepositAddress(payment?: PaymentData): string | undefined;
9
+ export declare function getEvmPaymentData(paymentData?: CryptoPaymentData): EVMPaymentData | undefined;
10
+ export declare function getBitcoinPaymentData(paymentData?: CryptoPaymentData): BitcoinPaymentData | undefined;
11
+ export declare function getSolanaPaymentData(paymentData?: CryptoPaymentData): SolanaPaymentData | undefined;
12
+ export declare function getSuiPaymentData(paymentData?: CryptoPaymentData): SuiPaymentData | undefined;
@@ -0,0 +1,53 @@
1
+ import { PaymentRail, StepKind } from "../types/enums";
2
+ export function getFiatPaymentStep(payment) {
3
+ return payment?.steps.find((step) => {
4
+ return (step.rail === PaymentRail.FIAT || step.kind === StepKind.KIND_STRIPE_ONRAMP) && step.data?.fiat;
5
+ });
6
+ }
7
+ export function getFiatPaymentData(payment) {
8
+ const data = getFiatPaymentStep(payment)?.data;
9
+ return data?.fiat;
10
+ }
11
+ export function getCryptoDepositStep(payment) {
12
+ return payment?.steps.find((step) => {
13
+ return step.rail === PaymentRail.CRYPTO && step.kind === StepKind.KIND_DEPOSIT;
14
+ });
15
+ }
16
+ export function getCryptoTransactionStep(payment) {
17
+ return payment?.steps.find((step) => {
18
+ return step.rail === PaymentRail.CRYPTO && step.kind === StepKind.KIND_TRANSACTION && step.data?.crypto;
19
+ });
20
+ }
21
+ export function getWalletPaymentStep(payment) {
22
+ return getCryptoTransactionStep(payment) ?? getCryptoDepositStep(payment);
23
+ }
24
+ export function getWalletPaymentData(payment) {
25
+ const data = getCryptoTransactionStep(payment)?.data;
26
+ return data?.crypto;
27
+ }
28
+ export function getDepositAddress(payment) {
29
+ const depositStep = getCryptoDepositStep(payment);
30
+ if (depositStep?.deposit_address) {
31
+ return depositStep.deposit_address;
32
+ }
33
+ if (getCryptoTransactionStep(payment)) {
34
+ return undefined;
35
+ }
36
+ return payment?.deposit_address;
37
+ }
38
+ export function getEvmPaymentData(paymentData) {
39
+ const data = paymentData;
40
+ return data?.evm;
41
+ }
42
+ export function getBitcoinPaymentData(paymentData) {
43
+ const data = paymentData;
44
+ return data?.bitcoin;
45
+ }
46
+ export function getSolanaPaymentData(paymentData) {
47
+ const data = paymentData;
48
+ return data?.solana;
49
+ }
50
+ export function getSuiPaymentData(paymentData) {
51
+ const data = paymentData;
52
+ return data?.sui;
53
+ }
@@ -0,0 +1 @@
1
+ export * from "./pay-order";
@@ -0,0 +1 @@
1
+ export * from "./pay-order";
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { ChainId } from "../types/enums";
3
- import { isBitcoinAddress, isEthereumAddress, isSolanaAddress, isSuiAddress, isTronAddress } from "./address";
4
- import { FIAT_CURRENCIES } from "./currencies";
3
+ import { isBitcoinAddress, isEthereumAddress, isSolanaAddress, isSuiAddress, isTronAddress } from "../chain/address";
4
+ import { FIAT_CURRENCIES } from "../currency/currencies";
5
5
  const knownKeys = ["items", "refund"];
6
6
  const customFieldSchema = z.union([z.string(), z.number(), z.boolean(), z.array(z.any()), z.object({}).loose()]).refine((val) => {
7
7
  if (typeof val === "string")
@@ -1,7 +1,7 @@
1
- import { FiatCurrency } from "../common/currencies";
2
- import { ChainId, ChainType, PayOrderStatus } from "./enums";
1
+ import { FiatCurrency } from "../currency/currencies";
2
+ import { ChainId, ChainType, PaymentMethod, PaymentRail, PayOrderStatus } from "./enums";
3
3
  import { PayOrderEvent } from "./events";
4
- import { CurrencyAmount, CurrencyBase, CurrencyWithAmount, PaymentData, PayOrderMetadata, QuoteWithCurrency } from "./model";
4
+ import { CurrencyAmount, CurrencyBase, CurrencyWithAmount, FiatAmount, PaymentData, PayOrderMetadata, QuoteWithCurrency } from "./model";
5
5
  export type PayOrderParams = {
6
6
  /**
7
7
  * Intent of the order.
@@ -17,12 +17,21 @@ export type PayOrderQuoteParams = {
17
17
  chain_type: ChainType;
18
18
  chain_id?: ChainId;
19
19
  };
20
- export type PaymentDetailsParams = {
20
+ type PaymentDetailsBaseParams = {
21
21
  payorder_id: string;
22
- } & ({
22
+ payment_rail?: PaymentRail;
23
+ };
24
+ export type PaymentDetailsParams = (PaymentDetailsBaseParams & {
25
+ source_currency?: never;
26
+ refund_address?: never;
27
+ quote_id?: never;
28
+ }) | (PaymentDetailsBaseParams & {
23
29
  source_currency: CurrencyBase;
24
30
  refund_address?: string;
25
- } | {
31
+ quote_id?: never;
32
+ }) | (PaymentDetailsBaseParams & {
33
+ source_currency?: never;
34
+ refund_address?: never;
26
35
  quote_id: string;
27
36
  });
28
37
  export type PaymentDetails = {
@@ -30,6 +39,15 @@ export type PaymentDetails = {
30
39
  status: PayOrderStatus;
31
40
  data: PaymentData;
32
41
  };
42
+ export type PaymentMethodAvailability = {
43
+ method: PaymentMethod;
44
+ available: boolean;
45
+ reason?: string;
46
+ minimum_amount?: FiatAmount;
47
+ };
48
+ export type PaymentMethodsResponse = {
49
+ methods: PaymentMethodAvailability[];
50
+ };
33
51
  export type PayOrderIntent = {
34
52
  /**
35
53
  * Desired fulfillment asset.
@@ -26,6 +26,20 @@ export declare enum ChainId {
26
26
  SUI = 30000000000002,
27
27
  TRX = 30000000000003
28
28
  }
29
+ export declare enum PaymentMethod {
30
+ WALLET = "WALLET",
31
+ DEPOSIT_ADDRESS = "DEPOSIT_ADDRESS",
32
+ CARD = "CARD"
33
+ }
34
+ export declare enum PaymentRail {
35
+ CRYPTO = "CRYPTO",
36
+ FIAT = "FIAT"
37
+ }
38
+ export declare enum StepKind {
39
+ KIND_DEPOSIT = "deposit",
40
+ KIND_TRANSACTION = "transaction",
41
+ KIND_STRIPE_ONRAMP = "stripe_onramp"
42
+ }
29
43
  export declare enum PayOrderMode {
30
44
  SALE = "SALE",
31
45
  DEPOSIT = "DEPOSIT",
@@ -36,6 +36,23 @@ export var ChainId;
36
36
  ChainId[ChainId["TRX"] = 30000000000003] = "TRX";
37
37
  // XRPL = 30000000000004,
38
38
  })(ChainId || (ChainId = {}));
39
+ export var PaymentMethod;
40
+ (function (PaymentMethod) {
41
+ PaymentMethod["WALLET"] = "WALLET";
42
+ PaymentMethod["DEPOSIT_ADDRESS"] = "DEPOSIT_ADDRESS";
43
+ PaymentMethod["CARD"] = "CARD";
44
+ })(PaymentMethod || (PaymentMethod = {}));
45
+ export var PaymentRail;
46
+ (function (PaymentRail) {
47
+ PaymentRail["CRYPTO"] = "CRYPTO";
48
+ PaymentRail["FIAT"] = "FIAT";
49
+ })(PaymentRail || (PaymentRail = {}));
50
+ export var StepKind;
51
+ (function (StepKind) {
52
+ StepKind["KIND_DEPOSIT"] = "deposit";
53
+ StepKind["KIND_TRANSACTION"] = "transaction";
54
+ StepKind["KIND_STRIPE_ONRAMP"] = "stripe_onramp";
55
+ })(StepKind || (StepKind = {}));
39
56
  export var PayOrderMode;
40
57
  (function (PayOrderMode) {
41
58
  PayOrderMode["SALE"] = "SALE";
@@ -3,4 +3,5 @@ export * from "./crypto";
3
3
  export * from "./enums";
4
4
  export * from "./events";
5
5
  export * from "./model";
6
+ export * from "./organization";
6
7
  export * from "./webhooks";
@@ -3,4 +3,5 @@ export * from "./crypto";
3
3
  export * from "./enums";
4
4
  export * from "./events";
5
5
  export * from "./model";
6
+ export * from "./organization";
6
7
  export * from "./webhooks";
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
- import { zPayOrderMetadata } from "../common/validation";
3
- import { FiatCurrency } from "../common/currencies";
4
- import { ChainId, PayOrderMode, PayOrderStatus, ProviderStatus } from "./enums";
2
+ import { FiatCurrency } from "../currency/currencies";
3
+ import { zPayOrderMetadata } from "../schemas/pay-order";
4
+ import { ChainId, PaymentRail, PayOrderMode, PayOrderStatus, ProviderStatus, StepKind } from "./enums";
5
5
  export type PayOrder = {
6
6
  id: string;
7
7
  mode: PayOrderMode;
@@ -51,6 +51,54 @@ export interface FeeBreakdown {
51
51
  protocol_fee?: CurrencyAmount;
52
52
  custom_fee?: CurrencyAmount;
53
53
  }
54
+ export interface FiatQuoteData {
55
+ source_currency: string;
56
+ source_amount: string;
57
+ source_total_amount: string;
58
+ destination_currency: string;
59
+ destination_network: string;
60
+ destination_amount: string;
61
+ network_fee_amount?: string;
62
+ transaction_fee_amount?: string;
63
+ }
64
+ export interface FiatPaymentData {
65
+ session_id: string;
66
+ stripe_publishable_key: string;
67
+ client_secret: string;
68
+ status: string;
69
+ source_currency?: string;
70
+ destination_currency?: string;
71
+ destination_network?: string;
72
+ destination_amount?: string;
73
+ wallet_address?: string;
74
+ quote?: FiatQuoteData;
75
+ }
76
+ export type SerializedSuiTransaction = unknown;
77
+ export type SerializedSolanaTransaction = unknown;
78
+ export interface CryptoPaymentData {
79
+ evm?: EVMPaymentData;
80
+ bitcoin?: BitcoinPaymentData;
81
+ solana?: SolanaPaymentData;
82
+ sui?: SuiPaymentData;
83
+ }
84
+ export interface SuiPaymentData {
85
+ transaction: SerializedSuiTransaction;
86
+ }
87
+ export interface SolanaPaymentData {
88
+ transaction: SerializedSolanaTransaction;
89
+ }
90
+ export interface BitcoinPaymentData {
91
+ psbt: string;
92
+ }
93
+ export interface EVMPaymentData {
94
+ from: string;
95
+ to: string;
96
+ data: string;
97
+ value: string;
98
+ chainId: ChainId;
99
+ maxFeePerGas?: string;
100
+ maxPriorityFeePerGas?: string;
101
+ }
54
102
  export type TokenAmount = {
55
103
  ui_amount: number;
56
104
  raw_amount: BigIntStr;
@@ -84,8 +132,19 @@ export type PaymentData = {
84
132
  destination_tx_hash?: string;
85
133
  refund_tx_hash?: string;
86
134
  fee_tx_hash?: string;
135
+ steps: PaymentStep[];
87
136
  expires_at: Date;
88
137
  };
138
+ export type PaymentStep = {
139
+ rail: PaymentRail;
140
+ kind: StepKind;
141
+ deposit_address?: string;
142
+ data?: PaymentStepData;
143
+ };
144
+ export type PaymentStepData = {
145
+ crypto?: CryptoPaymentData;
146
+ fiat?: FiatPaymentData;
147
+ };
89
148
  export type ExecutionStep = {
90
149
  id: string;
91
150
  status: ProviderStatus;
@@ -1,4 +1,4 @@
1
- import { Currency } from "../types/model";
1
+ import { Currency } from "./model";
2
2
  export type SettlementCurrency = {
3
3
  receiving_address: string;
4
4
  } & Currency;
@@ -1,4 +1,4 @@
1
- declare const detectBrowser: () => import("detect-browser").Browser | "bot" | "node" | "react-native" | "";
1
+ declare const detectBrowser: () => "" | import("detect-browser").Browser | "bot" | "node" | "react-native";
2
2
  declare const detectOS: () => "" | import("detect-browser").OperatingSystem | NodeJS.Platform;
3
3
  declare const isIOS: () => boolean;
4
4
  declare const isAndroid: () => boolean;
@@ -0,0 +1,7 @@
1
+ export * from "./assert";
2
+ export * from "./browser";
3
+ export * from "./debug";
4
+ export * from "./format";
5
+ export * from "./local-storage";
6
+ export * from "./plural";
7
+ export * from "./time";
@@ -0,0 +1,7 @@
1
+ export * from "./assert";
2
+ export * from "./browser";
3
+ export * from "./debug";
4
+ export * from "./format";
5
+ export * from "./local-storage";
6
+ export * from "./plural";
7
+ export * from "./time";
package/package.json CHANGED
@@ -1,21 +1,41 @@
1
1
  {
2
2
  "name": "@coin-voyage/shared",
3
3
  "description": "Shared utilities for Coin Voyage",
4
- "version": "2.3.5-beta.2",
4
+ "version": "2.4.0-beta.0",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {
8
- "./common/chains": {
9
- "types": "./dist/common/chains.d.ts",
10
- "default": "./dist/common/chains.js"
8
+ "./api": {
9
+ "types": "./dist/api/index.d.ts",
10
+ "default": "./dist/api/index.js"
11
11
  },
12
- "./types/*": {
12
+ "./chain": {
13
+ "types": "./dist/chain/index.d.ts",
14
+ "default": "./dist/chain/index.js"
15
+ },
16
+ "./currency": {
17
+ "types": "./dist/currency/index.d.ts",
18
+ "default": "./dist/currency/index.js"
19
+ },
20
+ "./hooks": {
21
+ "types": "./dist/hooks/index.d.ts",
22
+ "default": "./dist/hooks/index.js"
23
+ },
24
+ "./payment": {
25
+ "types": "./dist/payment/index.d.ts",
26
+ "default": "./dist/payment/index.js"
27
+ },
28
+ "./schemas": {
29
+ "types": "./dist/schemas/index.d.ts",
30
+ "default": "./dist/schemas/index.js"
31
+ },
32
+ "./types": {
13
33
  "types": "./dist/types/index.d.ts",
14
34
  "default": "./dist/types/index.js"
15
35
  },
16
- "./*": {
17
- "types": "./dist/*/index.d.ts",
18
- "default": "./dist/*/index.js"
36
+ "./utils": {
37
+ "types": "./dist/utils/index.d.ts",
38
+ "default": "./dist/utils/index.js"
19
39
  }
20
40
  },
21
41
  "files": [
@@ -23,14 +43,29 @@
23
43
  ],
24
44
  "typesVersions": {
25
45
  "*": {
26
- "common/chains": [
27
- "dist/common/chains.d.ts"
46
+ "api": [
47
+ "dist/api/index.d.ts"
48
+ ],
49
+ "chain": [
50
+ "dist/chain/index.d.ts"
51
+ ],
52
+ "currency": [
53
+ "dist/currency/index.d.ts"
54
+ ],
55
+ "hooks": [
56
+ "dist/hooks/index.d.ts"
57
+ ],
58
+ "payment": [
59
+ "dist/payment/index.d.ts"
60
+ ],
61
+ "schemas": [
62
+ "dist/schemas/index.d.ts"
28
63
  ],
29
- "types/*": [
64
+ "types": [
30
65
  "dist/types/index.d.ts"
31
66
  ],
32
- "*": [
33
- "dist/*/index.d.ts"
67
+ "utils": [
68
+ "dist/utils/index.d.ts"
34
69
  ]
35
70
  }
36
71
  },
@@ -1,14 +0,0 @@
1
- export * from "./address";
2
- export * from "./assert";
3
- export * from "./browser";
4
- export * from "./chain-explorer";
5
- export * from "./chains";
6
- export * from "./currencies";
7
- export * from "./debug";
8
- export * from "./format";
9
- export * from "./local-storage";
10
- export * from "./organization";
11
- export * from "./plural";
12
- export * from "./time";
13
- export * from "./validation";
14
- export * from "./token-list";
@@ -1,14 +0,0 @@
1
- export * from "./address";
2
- export * from "./assert";
3
- export * from "./browser";
4
- export * from "./chain-explorer";
5
- export * from "./chains";
6
- export * from "./currencies";
7
- export * from "./debug";
8
- export * from "./format";
9
- export * from "./local-storage";
10
- export * from "./organization";
11
- export * from "./plural";
12
- export * from "./time";
13
- export * from "./validation";
14
- export * from "./token-list";
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes