swapped-commerce-sdk 1.0.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.
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Type exports for Swapped Commerce SDK
3
+ */
4
+
5
+ // Common types
6
+ export type {
7
+ SwappedConfig,
8
+ RequiredSwappedConfig,
9
+ ApiResponse,
10
+ PaginationParams,
11
+ PaginationResponse,
12
+ HttpConfig,
13
+ } from './common'
14
+
15
+ // Currency types
16
+ export type {
17
+ CurrencyType,
18
+ CurrencyFlow,
19
+ Blockchain,
20
+ Currency,
21
+ } from './currencies'
22
+
23
+ // Quote types
24
+ export type {
25
+ MoneyAmount,
26
+ Fee,
27
+ Quote,
28
+ GetQuoteParams,
29
+ QuoteResponse,
30
+ } from './quotes'
31
+
32
+ // Payment types
33
+ export type {
34
+ DepositAddress,
35
+ Payment,
36
+ Purchase,
37
+ PurchaseInput,
38
+ PreferredPayCurrency,
39
+ OrderMetadataInput,
40
+ CreateLinkParams,
41
+ PaymentLinkResponse,
42
+ CreateRouteParams,
43
+ PaymentRouteResponse,
44
+ } from './payments'
45
+
46
+ // Order types
47
+ export type {
48
+ OrderInitType,
49
+ OrderStatus,
50
+ OrderMetadata,
51
+ OrderUpdate,
52
+ Settlement,
53
+ Order,
54
+ ListOrdersParams,
55
+ OrdersResponse,
56
+ RefundParams,
57
+ RefundResponse,
58
+ } from './orders'
59
+
60
+ // Balance types
61
+ export type {
62
+ Balance,
63
+ ListBalancesParams,
64
+ BalancesResponse,
65
+ } from './balances'
66
+
67
+ // Payout types
68
+ export type {
69
+ BankDestination,
70
+ CryptoDestination,
71
+ PayoutStatus,
72
+ Payout,
73
+ CreatePayoutParams,
74
+ CreatePayoutResponse,
75
+ PayoutsResponse,
76
+ } from './payouts'
77
+
78
+ // KYC types
79
+ export type {
80
+ KYCStatus,
81
+ Address,
82
+ DocumentType,
83
+ Document,
84
+ KYCStatusResponse,
85
+ SubmitKYCParams,
86
+ SubmitKYCResponse,
87
+ } from './kyc'
88
+
89
+ // Webhook types
90
+ export type {
91
+ WebhookEventType,
92
+ WebhookEvent,
93
+ } from './webhooks'
@@ -0,0 +1,65 @@
1
+ /**
2
+ * KYC status
3
+ */
4
+ export type KYCStatus = 'NOT_STARTED' | 'PENDING' | 'APPROVED' | 'REJECTED'
5
+
6
+ /**
7
+ * Address information
8
+ */
9
+ export interface Address {
10
+ readonly street: string
11
+ readonly city: string
12
+ readonly state?: string
13
+ readonly postalCode: string
14
+ readonly country: string
15
+ }
16
+
17
+ /**
18
+ * Document type
19
+ */
20
+ export type DocumentType =
21
+ | 'PASSPORT'
22
+ | 'DRIVERS_LICENSE'
23
+ | 'ID_CARD'
24
+ | 'PROOF_OF_ADDRESS'
25
+
26
+ /**
27
+ * Document information
28
+ */
29
+ export interface Document {
30
+ readonly type: DocumentType
31
+ readonly frontImage: string // Base64 or URL
32
+ readonly backImage?: string
33
+ }
34
+
35
+ /**
36
+ * Response for KYC status
37
+ */
38
+ export interface KYCStatusResponse {
39
+ readonly customerId: string
40
+ readonly status: KYCStatus
41
+ readonly submittedAt?: string
42
+ readonly reviewedAt?: string
43
+ readonly rejectionReason?: string
44
+ }
45
+
46
+ /**
47
+ * Parameters for submitting KYC
48
+ */
49
+ export interface SubmitKYCParams {
50
+ readonly customerId: string
51
+ readonly firstName: string
52
+ readonly lastName: string
53
+ readonly dateOfBirth: string
54
+ readonly nationality: string
55
+ readonly address: Address
56
+ readonly documents: readonly Document[]
57
+ }
58
+
59
+ /**
60
+ * Response for submitting KYC
61
+ */
62
+ export interface SubmitKYCResponse {
63
+ readonly submissionId: string
64
+ readonly status: string
65
+ }
@@ -0,0 +1,122 @@
1
+ import type { Currency } from './currencies'
2
+ import type { Quote } from './quotes'
3
+ import type { DepositAddress, Payment, Purchase } from './payments'
4
+
5
+ /**
6
+ * Order initialization type
7
+ */
8
+ export type OrderInitType = 'STANDARD' | 'INVOICE' | 'PAYMENT_ROUTE'
9
+
10
+ /**
11
+ * Order status
12
+ */
13
+ export type OrderStatus =
14
+ | 'PENDING_USER_CREATION'
15
+ | 'PENDING_CURRENCY_SELECTION'
16
+ | 'AWAITING_PAYMENT'
17
+ | 'PAYMENT_CONFIRMED_ACCURATE'
18
+ | 'PAYMENT_CONFIRMED_UNDERPAID'
19
+ | 'PAYMENT_CONFIRMED_OVERPAID'
20
+ | 'COMPLETED'
21
+ | 'EXPIRED'
22
+ | 'CANCELLED'
23
+
24
+ /**
25
+ * Order metadata
26
+ */
27
+ export interface OrderMetadata {
28
+ readonly externalId?: string
29
+ readonly userId?: string
30
+ readonly customerId?: string
31
+ readonly userName?: string
32
+ readonly customerName?: string
33
+ readonly userLang?: string
34
+ readonly customerLang?: string
35
+ readonly userCountry?: string
36
+ readonly customerCountry?: string
37
+ readonly userEmail?: string
38
+ readonly customerEmail?: string
39
+ readonly redirectUrl?: string
40
+ }
41
+
42
+ /**
43
+ * Order update
44
+ */
45
+ export interface OrderUpdate {
46
+ readonly id: string
47
+ readonly message: string
48
+ readonly entityType: string
49
+ readonly authorId: string
50
+ readonly metadata: Readonly<Record<string, unknown>>
51
+ readonly timestamp: string
52
+ }
53
+
54
+ /**
55
+ * Settlement information
56
+ */
57
+ export interface Settlement {
58
+ readonly id: string
59
+ readonly type: string
60
+ readonly status: string
61
+ }
62
+
63
+ /**
64
+ * Complete order information
65
+ */
66
+ export interface Order {
67
+ readonly id: string
68
+ readonly link: string
69
+ readonly externalId: string
70
+ readonly userId: string
71
+ readonly customerId: string
72
+ readonly merchant: {
73
+ readonly id: string
74
+ }
75
+ readonly initType: OrderInitType
76
+ readonly quote: Quote
77
+ readonly depositAddress: DepositAddress
78
+ readonly settlements: readonly Settlement[]
79
+ readonly payments: readonly Payment[]
80
+ readonly expiresAt: string
81
+ readonly createdAt: string
82
+ readonly status: OrderStatus
83
+ readonly purchase?: Purchase
84
+ readonly updates: readonly OrderUpdate[]
85
+ readonly metadata: OrderMetadata
86
+ readonly preferredPayCurrency?: Currency
87
+ }
88
+
89
+ /**
90
+ * Parameters for listing orders
91
+ */
92
+ export interface ListOrdersParams {
93
+ readonly page?: number
94
+ readonly limit?: number
95
+ readonly searchId?: string
96
+ readonly startDate?: number
97
+ readonly endDate?: number
98
+ readonly type?: OrderInitType
99
+ }
100
+
101
+ /**
102
+ * Response for listing orders
103
+ */
104
+ export interface OrdersResponse {
105
+ readonly orders: readonly Order[]
106
+ readonly pagination: import('./common').PaginationResponse
107
+ }
108
+
109
+ /**
110
+ * Parameters for refunding an order
111
+ */
112
+ export interface RefundParams {
113
+ readonly amount?: string
114
+ readonly reason?: string
115
+ }
116
+
117
+ /**
118
+ * Response for refund operation
119
+ */
120
+ export interface RefundResponse {
121
+ readonly refundId: string
122
+ }
@@ -0,0 +1,115 @@
1
+ import type { Currency } from './currencies'
2
+ import type { Quote } from './quotes'
3
+
4
+ /**
5
+ * Deposit address for payments
6
+ */
7
+ export interface DepositAddress {
8
+ readonly id: string
9
+ readonly address: string
10
+ readonly available: boolean
11
+ readonly memo?: string
12
+ readonly supportedCurrencies: readonly Currency[]
13
+ }
14
+
15
+ /**
16
+ * Payment information
17
+ */
18
+ export interface Payment {
19
+ readonly id: string
20
+ readonly orderId: string
21
+ readonly receivedAmount: string
22
+ readonly receivedCurrency: Currency
23
+ readonly txHash: string
24
+ readonly confirmedAt: string
25
+ readonly status: string
26
+ readonly createdAt: string
27
+ readonly depositAddress: DepositAddress
28
+ readonly sourceAddress: string
29
+ readonly fireblocksTxId?: string
30
+ }
31
+
32
+ /**
33
+ * Purchase information
34
+ */
35
+ export interface Purchase {
36
+ readonly id: string
37
+ readonly name: string
38
+ readonly notes?: string
39
+ readonly imageUrl?: string
40
+ readonly price: string
41
+ readonly currency: Currency
42
+ readonly rateMerchantOverOrder: string
43
+ }
44
+
45
+ /**
46
+ * Purchase object for order creation
47
+ */
48
+ export interface PurchaseInput {
49
+ readonly name: string
50
+ readonly description?: string
51
+ readonly notes?: string
52
+ readonly imageUrl?: string
53
+ readonly price: string
54
+ readonly currency: string
55
+ }
56
+
57
+ /**
58
+ * Preferred payment currency
59
+ */
60
+ export interface PreferredPayCurrency {
61
+ readonly symbol: string
62
+ readonly blockchain: string
63
+ }
64
+
65
+ /**
66
+ * Order metadata
67
+ */
68
+ export interface OrderMetadataInput {
69
+ readonly externalId?: string
70
+ readonly customerId?: string
71
+ readonly customerCountry?: string
72
+ readonly customerName?: string
73
+ readonly customerLang?: string
74
+ readonly customerEmail?: string
75
+ readonly redirectUrl?: string
76
+ }
77
+
78
+ /**
79
+ * Parameters for creating a payment link/order
80
+ */
81
+ export interface CreateLinkParams {
82
+ readonly purchase: PurchaseInput
83
+ readonly metadata?: OrderMetadataInput
84
+ readonly testMode?: boolean
85
+ readonly preferredPayCurrency?: PreferredPayCurrency
86
+ }
87
+
88
+ /**
89
+ * Response for creating a payment link
90
+ */
91
+ export interface PaymentLinkResponse {
92
+ readonly orderId: string
93
+ readonly paymentLink: string
94
+ }
95
+
96
+ /**
97
+ * Parameters for creating a payment route
98
+ */
99
+ export interface CreateRouteParams {
100
+ readonly purchaseAmount: string
101
+ readonly purchaseCurrency: string
102
+ readonly preferredPayCurrency?: string
103
+ readonly externalId?: string
104
+ readonly customerId?: string
105
+ readonly metadata?: Readonly<Record<string, unknown>>
106
+ }
107
+
108
+ /**
109
+ * Response for creating a payment route
110
+ */
111
+ export interface PaymentRouteResponse {
112
+ readonly orderId: string
113
+ readonly depositAddress: DepositAddress
114
+ readonly quote: Quote
115
+ }
@@ -0,0 +1,68 @@
1
+ import type { Currency } from './currencies'
2
+
3
+ /**
4
+ * Bank destination for payouts
5
+ */
6
+ export interface BankDestination {
7
+ readonly accountNumber: string
8
+ readonly routingNumber?: string
9
+ readonly iban?: string
10
+ readonly swift?: string
11
+ readonly accountHolderName: string
12
+ }
13
+
14
+ /**
15
+ * Crypto destination for payouts
16
+ */
17
+ export interface CryptoDestination {
18
+ readonly address: string
19
+ readonly blockchain: string
20
+ readonly memo?: string
21
+ }
22
+
23
+ /**
24
+ * Payout status
25
+ */
26
+ export type PayoutStatus = 'PENDING' | 'PROCESSING' | 'COMPLETED' | 'FAILED'
27
+
28
+ /**
29
+ * Payout information
30
+ */
31
+ export interface Payout {
32
+ readonly id: string
33
+ readonly amount: string
34
+ readonly currency: Currency
35
+ readonly destination: BankDestination | CryptoDestination
36
+ readonly status: PayoutStatus
37
+ readonly createdAt: string
38
+ readonly completedAt?: string
39
+ readonly failureReason?: string
40
+ }
41
+
42
+ /**
43
+ * Parameters for creating a payout
44
+ */
45
+ export interface CreatePayoutParams {
46
+ readonly amount: string
47
+ readonly currency: string
48
+ readonly destinationType: 'BANK' | 'CRYPTO'
49
+ readonly destination: BankDestination | CryptoDestination
50
+ readonly reference?: string
51
+ }
52
+
53
+ /**
54
+ * Response for creating a payout
55
+ */
56
+ export interface CreatePayoutResponse {
57
+ readonly payoutId: string
58
+ readonly status: string
59
+ readonly estimatedArrival: string
60
+ }
61
+
62
+ /**
63
+ * Response for listing payouts
64
+ */
65
+ export interface PayoutsResponse {
66
+ readonly payouts: readonly Payout[]
67
+ readonly pagination: import('./common').PaginationResponse
68
+ }
@@ -0,0 +1,49 @@
1
+ import type { Currency } from './currencies'
2
+
3
+ /**
4
+ * Money amount with currency
5
+ */
6
+ export interface MoneyAmount {
7
+ readonly amount: string
8
+ readonly currency: Currency
9
+ }
10
+
11
+ /**
12
+ * Fee information
13
+ */
14
+ export interface Fee {
15
+ readonly id: string
16
+ readonly type: string
17
+ readonly label: string
18
+ readonly amount: string
19
+ readonly currency: Currency
20
+ readonly createdAt: string
21
+ }
22
+
23
+ /**
24
+ * Exchange quote
25
+ */
26
+ export interface Quote {
27
+ readonly fromAmount: MoneyAmount
28
+ readonly toAmount: MoneyAmount
29
+ readonly exchangeRateSnapshotId: string
30
+ readonly fees: readonly Fee[]
31
+ }
32
+
33
+ /**
34
+ * Parameters for getting a quote
35
+ */
36
+ export interface GetQuoteParams {
37
+ readonly fromCurrency: string
38
+ readonly toCurrency: string
39
+ readonly amount: string
40
+ readonly amountType: 'FROM' | 'TO'
41
+ }
42
+
43
+ /**
44
+ * Response for getting a quote
45
+ */
46
+ export interface QuoteResponse {
47
+ readonly quote: Quote
48
+ readonly expiresAt: string
49
+ }
@@ -0,0 +1,31 @@
1
+ import type { OrderStatus } from './orders'
2
+
3
+ /**
4
+ * Webhook event types
5
+ */
6
+ export type WebhookEventType =
7
+ | 'ORDER_CREATED'
8
+ | 'PAYMENT_RECEIVED'
9
+ | 'ORDER_COMPLETED'
10
+ | 'SETTLEMENT_CREATED'
11
+ | 'PAYMENT_CONVERSION_SETTLED'
12
+
13
+ /**
14
+ * Webhook event payload
15
+ */
16
+ export interface WebhookEvent {
17
+ readonly event_type: WebhookEventType
18
+ readonly order_id: string
19
+ readonly order_status: OrderStatus
20
+ readonly merchant_id: string
21
+ readonly order_purchase_amount: number
22
+ readonly order_purchase_currency: string
23
+ readonly order_crypto?: string
24
+ readonly order_crypto_amount?: number
25
+ readonly network?: string
26
+ readonly settlement_id?: string
27
+ readonly from_amount?: number
28
+ readonly from_currency?: string
29
+ readonly from_network?: string
30
+ readonly to_currency?: string
31
+ }
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Base error class for Swapped Commerce SDK
3
+ */
4
+ export class SwappedError extends Error {
5
+ public readonly statusCode?: number
6
+ public readonly code?: string
7
+ public readonly details?: Readonly<Record<string, unknown>>
8
+
9
+ constructor(
10
+ message: string,
11
+ statusCode?: number,
12
+ code?: string,
13
+ details?: Readonly<Record<string, unknown>>
14
+ ) {
15
+ super(message)
16
+ this.name = 'SwappedError'
17
+ this.statusCode = statusCode
18
+ this.code = code
19
+ this.details = details
20
+
21
+ // Maintains proper stack trace for where error was thrown (V8 only)
22
+ if (Error.captureStackTrace) {
23
+ Error.captureStackTrace(this, SwappedError)
24
+ }
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Authentication error (401)
30
+ */
31
+ export class SwappedAuthenticationError extends SwappedError {
32
+ constructor(message: string = 'Authentication failed') {
33
+ super(message, 401, 'AUTHENTICATION_ERROR')
34
+ this.name = 'SwappedAuthenticationError'
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Validation error (400)
40
+ */
41
+ export class SwappedValidationError extends SwappedError {
42
+ constructor(
43
+ message: string,
44
+ details?: Readonly<Record<string, unknown>>
45
+ ) {
46
+ super(message, 400, 'VALIDATION_ERROR', details)
47
+ this.name = 'SwappedValidationError'
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Rate limit error (429)
53
+ */
54
+ export class SwappedRateLimitError extends SwappedError {
55
+ constructor(message: string = 'Rate limit exceeded') {
56
+ super(message, 429, 'RATE_LIMIT_ERROR')
57
+ this.name = 'SwappedRateLimitError'
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Not found error (404)
63
+ */
64
+ export class SwappedNotFoundError extends SwappedError {
65
+ constructor(resource: string) {
66
+ super(`${resource} not found`, 404, 'NOT_FOUND_ERROR')
67
+ this.name = 'SwappedNotFoundError'
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Factory function for authentication errors
73
+ */
74
+ export function createAuthenticationError(
75
+ message?: string
76
+ ): SwappedAuthenticationError {
77
+ return new SwappedAuthenticationError(message)
78
+ }
79
+
80
+ /**
81
+ * Factory function for validation errors
82
+ */
83
+ export function createValidationError(
84
+ message: string,
85
+ details?: Readonly<Record<string, unknown>>
86
+ ): SwappedValidationError {
87
+ return new SwappedValidationError(message, details)
88
+ }
89
+
90
+ /**
91
+ * Factory function for rate limit errors
92
+ */
93
+ export function createRateLimitError(
94
+ message?: string
95
+ ): SwappedRateLimitError {
96
+ return new SwappedRateLimitError(message)
97
+ }
98
+
99
+ /**
100
+ * Factory function for not found errors
101
+ */
102
+ export function createNotFoundError(resource: string): SwappedNotFoundError {
103
+ return new SwappedNotFoundError(resource)
104
+ }