@diviswap/sdk 1.7.19 → 1.7.21
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/cli/index.js +1 -1
- package/dist/cli/templates/nextjs-app/actions.ts.hbs +70 -100
- package/dist/cli/templates/nextjs-app/api-hooks.ts.hbs +1 -1
- package/dist/cli/templates/nextjs-app/api-route.ts.hbs +40 -0
- package/dist/cli/templates/nextjs-app/kyc-hooks.ts.hbs +1 -1
- package/dist/cli/templates/nextjs-app/kyc-wizard.tsx.hbs +2 -1
- package/dist/index.js +19 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -2
- package/src/cli/templates/nextjs-app/actions.ts.hbs +70 -100
- package/src/cli/templates/nextjs-app/api-hooks.ts.hbs +1 -1
- package/src/cli/templates/nextjs-app/api-route.ts.hbs +40 -0
- package/src/cli/templates/nextjs-app/kyc-hooks.ts.hbs +1 -1
- package/src/cli/templates/nextjs-app/kyc-wizard.tsx.hbs +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diviswap/sdk",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.21",
|
|
4
4
|
"description": "Official Diviswap SDK - Crypto rails made simple",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -71,7 +71,6 @@
|
|
|
71
71
|
"typescript": "^5.7.3"
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@diviswap/sdk": "1.7.12",
|
|
75
74
|
"@solana/wallet-adapter-base": "0.9.27",
|
|
76
75
|
"@solana/wallet-adapter-react": "0.15.39",
|
|
77
76
|
"@solana/wallet-adapter-react-ui": "0.9.39",
|
|
@@ -3,25 +3,18 @@
|
|
|
3
3
|
import { Diviswap } from '@diviswap/sdk';
|
|
4
4
|
import type { Transaction, Payee } from '@diviswap/sdk';
|
|
5
5
|
import { revalidatePath } from 'next/cache';
|
|
6
|
-
import { cookies } from 'next/headers';
|
|
7
6
|
|
|
8
|
-
// Initialize Diviswap SDK
|
|
9
|
-
function getDiviswap() {
|
|
7
|
+
// Initialize Diviswap SDK in Partner mode
|
|
8
|
+
function getDiviswap(customerId?: string) {
|
|
10
9
|
return Diviswap.init({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
environment: (process.env.NEXT_PUBLIC_DIVISWAP_ENV as 'production' | 'sandbox') || '
|
|
14
|
-
|
|
10
|
+
keyId: process.env.DIVISWAP_PARTNER_KEY_ID!,
|
|
11
|
+
secretKey: process.env.DIVISWAP_PARTNER_SECRET_KEY!,
|
|
12
|
+
environment: (process.env.NEXT_PUBLIC_DIVISWAP_ENV as 'production' | 'sandbox') || 'sandbox',
|
|
13
|
+
customerId, // Associate operations with this customer
|
|
14
|
+
debug: process.env.NODE_ENV === 'development'
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
// Helper to get session token from cookies
|
|
19
|
-
async function getSessionToken() {
|
|
20
|
-
const cookieStore = await cookies();
|
|
21
|
-
const session = cookieStore.get('diviswap_session');
|
|
22
|
-
return session?.value;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
18
|
// Transaction Server Actions
|
|
26
19
|
export async function createTransactionAction(data: {
|
|
27
20
|
type: 'onramp' | 'offramp';
|
|
@@ -35,11 +28,6 @@ export async function createTransactionAction(data: {
|
|
|
35
28
|
txHash?: string; // Required for offramp - transaction hash from blockchain
|
|
36
29
|
}) {
|
|
37
30
|
try {
|
|
38
|
-
const sessionToken = await getSessionToken();
|
|
39
|
-
if (!sessionToken) {
|
|
40
|
-
return { success: false, error: 'Not authenticated' };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
31
|
const diviswap = getDiviswap();
|
|
44
32
|
|
|
45
33
|
// Use the appropriate method based on transaction type
|
|
@@ -80,19 +68,14 @@ export async function getTransactionsAction(filters?: {
|
|
|
80
68
|
type?: 'onramp' | 'offramp';
|
|
81
69
|
}) {
|
|
82
70
|
try {
|
|
83
|
-
const sessionToken = await getSessionToken();
|
|
84
|
-
if (!sessionToken) {
|
|
85
|
-
return { success: false, error: 'Not authenticated' };
|
|
86
|
-
}
|
|
87
|
-
|
|
88
71
|
const diviswap = getDiviswap();
|
|
89
72
|
const transactions = await diviswap.transactions.list(filters);
|
|
90
|
-
|
|
73
|
+
|
|
91
74
|
return { success: true, transactions };
|
|
92
75
|
} catch (error) {
|
|
93
|
-
return {
|
|
94
|
-
success: false,
|
|
95
|
-
error: error instanceof Error ? error.message : 'Failed to fetch transactions'
|
|
76
|
+
return {
|
|
77
|
+
success: false,
|
|
78
|
+
error: error instanceof Error ? error.message : 'Failed to fetch transactions'
|
|
96
79
|
};
|
|
97
80
|
}
|
|
98
81
|
}
|
|
@@ -100,19 +83,14 @@ export async function getTransactionsAction(filters?: {
|
|
|
100
83
|
// Payee Server Actions
|
|
101
84
|
export async function getPayeesAction() {
|
|
102
85
|
try {
|
|
103
|
-
const sessionToken = await getSessionToken();
|
|
104
|
-
if (!sessionToken) {
|
|
105
|
-
return { success: false, error: 'Not authenticated' };
|
|
106
|
-
}
|
|
107
|
-
|
|
108
86
|
const diviswap = getDiviswap();
|
|
109
87
|
const payees = await diviswap.payees.list();
|
|
110
|
-
|
|
88
|
+
|
|
111
89
|
return { success: true, payees };
|
|
112
90
|
} catch (error) {
|
|
113
|
-
return {
|
|
114
|
-
success: false,
|
|
115
|
-
error: error instanceof Error ? error.message : 'Failed to fetch payees'
|
|
91
|
+
return {
|
|
92
|
+
success: false,
|
|
93
|
+
error: error instanceof Error ? error.message : 'Failed to fetch payees'
|
|
116
94
|
};
|
|
117
95
|
}
|
|
118
96
|
}
|
|
@@ -124,11 +102,6 @@ export async function createPayeeAction(data: {
|
|
|
124
102
|
accountType: 'checking' | 'savings';
|
|
125
103
|
}) {
|
|
126
104
|
try {
|
|
127
|
-
const sessionToken = await getSessionToken();
|
|
128
|
-
if (!sessionToken) {
|
|
129
|
-
return { success: false, error: 'Not authenticated' };
|
|
130
|
-
}
|
|
131
|
-
|
|
132
105
|
const diviswap = getDiviswap();
|
|
133
106
|
const payee = await diviswap.payees.create({
|
|
134
107
|
nickname: data.nickname,
|
|
@@ -137,114 +110,111 @@ export async function createPayeeAction(data: {
|
|
|
137
110
|
accountType: data.accountType,
|
|
138
111
|
setAsDefault: false
|
|
139
112
|
});
|
|
140
|
-
|
|
113
|
+
|
|
141
114
|
revalidatePath('/diviswap');
|
|
142
115
|
return { success: true, payee };
|
|
143
116
|
} catch (error) {
|
|
144
|
-
return {
|
|
145
|
-
success: false,
|
|
146
|
-
error: error instanceof Error ? error.message : 'Payee creation failed'
|
|
117
|
+
return {
|
|
118
|
+
success: false,
|
|
119
|
+
error: error instanceof Error ? error.message : 'Payee creation failed'
|
|
147
120
|
};
|
|
148
121
|
}
|
|
149
122
|
}
|
|
150
123
|
|
|
151
124
|
export async function deletePayeeAction(payeeId: string) {
|
|
152
125
|
try {
|
|
153
|
-
const sessionToken = await getSessionToken();
|
|
154
|
-
if (!sessionToken) {
|
|
155
|
-
return { success: false, error: 'Not authenticated' };
|
|
156
|
-
}
|
|
157
|
-
|
|
158
126
|
const diviswap = getDiviswap();
|
|
159
127
|
await diviswap.payees.delete(payeeId);
|
|
160
|
-
|
|
128
|
+
|
|
161
129
|
revalidatePath('/diviswap');
|
|
162
130
|
return { success: true };
|
|
163
131
|
} catch (error) {
|
|
164
|
-
return {
|
|
165
|
-
success: false,
|
|
166
|
-
error: error instanceof Error ? error.message : 'Failed to delete payee'
|
|
132
|
+
return {
|
|
133
|
+
success: false,
|
|
134
|
+
error: error instanceof Error ? error.message : 'Failed to delete payee'
|
|
167
135
|
};
|
|
168
136
|
}
|
|
169
137
|
}
|
|
170
138
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
export async function calculateFeesAction(data: {
|
|
174
|
-
amount: number;
|
|
175
|
-
type: 'onramp' | 'offramp';
|
|
176
|
-
currency?: string;
|
|
177
|
-
}) {
|
|
139
|
+
// Deposit Address Actions
|
|
140
|
+
export async function getDepositAddressAction(chain: string) {
|
|
178
141
|
try {
|
|
179
142
|
const diviswap = getDiviswap();
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
143
|
+
const address = diviswap.transactions.getDepositAddressForChain(chain);
|
|
144
|
+
return { success: true, address };
|
|
145
|
+
} catch (error) {
|
|
146
|
+
return {
|
|
147
|
+
success: false,
|
|
148
|
+
error: error instanceof Error ? error.message : 'Failed to get deposit address'
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export async function getDepositAddressesAction() {
|
|
154
|
+
try {
|
|
155
|
+
const diviswap = getDiviswap();
|
|
156
|
+
const addresses = diviswap.transactions.getDepositAddresses();
|
|
157
|
+
return { success: true, addresses };
|
|
158
|
+
} catch (error) {
|
|
159
|
+
return {
|
|
160
|
+
success: false,
|
|
161
|
+
error: error instanceof Error ? error.message : 'Failed to get deposit addresses'
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Fee Calculation Actions
|
|
167
|
+
export async function calculateFeesAction(amount: number) {
|
|
168
|
+
try {
|
|
169
|
+
const diviswap = getDiviswap();
|
|
170
|
+
const fees = await diviswap.fees.calculateFees({ amount });
|
|
185
171
|
return { success: true, fees };
|
|
186
172
|
} catch (error) {
|
|
187
|
-
return {
|
|
188
|
-
success: false,
|
|
189
|
-
error: error instanceof Error ? error.message : '
|
|
173
|
+
return {
|
|
174
|
+
success: false,
|
|
175
|
+
error: error instanceof Error ? error.message : 'Failed to calculate fees'
|
|
190
176
|
};
|
|
191
177
|
}
|
|
192
178
|
}
|
|
193
179
|
|
|
194
180
|
export async function getIntegratorFeesAction() {
|
|
195
181
|
try {
|
|
196
|
-
const sessionToken = await getSessionToken();
|
|
197
|
-
if (!sessionToken) {
|
|
198
|
-
return { success: false, error: 'Not authenticated' };
|
|
199
|
-
}
|
|
200
|
-
|
|
201
182
|
const diviswap = getDiviswap();
|
|
202
183
|
const fees = await diviswap.fees.getFees();
|
|
203
|
-
|
|
184
|
+
|
|
204
185
|
return { success: true, fees };
|
|
205
186
|
} catch (error) {
|
|
206
|
-
return {
|
|
207
|
-
success: false,
|
|
208
|
-
error: error instanceof Error ? error.message : 'Failed to fetch integrator fees'
|
|
187
|
+
return {
|
|
188
|
+
success: false,
|
|
189
|
+
error: error instanceof Error ? error.message : 'Failed to fetch integrator fees'
|
|
209
190
|
};
|
|
210
191
|
}
|
|
211
192
|
}
|
|
212
193
|
|
|
213
194
|
export async function updateIntegratorFeeAction(data: {
|
|
214
195
|
percentage: number;
|
|
215
|
-
userId?:
|
|
196
|
+
userId?: number;
|
|
216
197
|
}) {
|
|
217
198
|
try {
|
|
218
|
-
const sessionToken = await getSessionToken();
|
|
219
|
-
if (!sessionToken) {
|
|
220
|
-
return { success: false, error: 'Not authenticated' };
|
|
221
|
-
}
|
|
222
|
-
|
|
223
199
|
const diviswap = getDiviswap();
|
|
224
200
|
const fee = await diviswap.fees.setFee(data);
|
|
225
|
-
|
|
201
|
+
|
|
226
202
|
revalidatePath('/diviswap');
|
|
227
203
|
return { success: true, fee };
|
|
228
204
|
} catch (error) {
|
|
229
|
-
return {
|
|
230
|
-
success: false,
|
|
231
|
-
error: error instanceof Error ? error.message : 'Failed to update fee'
|
|
205
|
+
return {
|
|
206
|
+
success: false,
|
|
207
|
+
error: error instanceof Error ? error.message : 'Failed to update fee'
|
|
232
208
|
};
|
|
233
209
|
}
|
|
234
210
|
}
|
|
235
|
-
{{/if}}
|
|
236
211
|
|
|
237
212
|
// Authentication Server Actions (for server components that need auth status)
|
|
238
213
|
export async function getCurrentUserAction() {
|
|
239
214
|
try {
|
|
240
|
-
const sessionToken = await getSessionToken();
|
|
241
|
-
if (!sessionToken) {
|
|
242
|
-
return { success: false, user: null };
|
|
243
|
-
}
|
|
244
|
-
|
|
245
215
|
const diviswap = getDiviswap();
|
|
246
216
|
const user = await diviswap.auth.getProfile();
|
|
247
|
-
|
|
217
|
+
|
|
248
218
|
return { success: true, user };
|
|
249
219
|
} catch (error) {
|
|
250
220
|
return { success: false, user: null };
|
|
@@ -258,9 +228,9 @@ export async function checkApiStatusAction() {
|
|
|
258
228
|
// Note: Health check endpoint not available in SDK
|
|
259
229
|
return { success: true, status: 'OK' };
|
|
260
230
|
} catch (error) {
|
|
261
|
-
return {
|
|
262
|
-
success: false,
|
|
263
|
-
error: error instanceof Error ? error.message : 'API health check failed'
|
|
231
|
+
return {
|
|
232
|
+
success: false,
|
|
233
|
+
error: error instanceof Error ? error.message : 'API health check failed'
|
|
264
234
|
};
|
|
265
235
|
}
|
|
266
|
-
}
|
|
236
|
+
}
|
|
@@ -202,6 +202,46 @@ const postHandlers: Record<string, ActionHandler> = {
|
|
|
202
202
|
},
|
|
203
203
|
{{/if}}
|
|
204
204
|
|
|
205
|
+
registerCustomer: async (params, { diviswap }) => {
|
|
206
|
+
// Register a new customer (user) in the Diviswap system
|
|
207
|
+
// This must be called before creating payees
|
|
208
|
+
try {
|
|
209
|
+
const personalInfo = params.personalInfo || {};
|
|
210
|
+
const address = params.address || {};
|
|
211
|
+
|
|
212
|
+
// Build the registration payload
|
|
213
|
+
const registrationData = {
|
|
214
|
+
email: personalInfo.email || params.customerEmail || `${params.customerId}@partner.local`,
|
|
215
|
+
password: `Partner_${Date.now()}_${Math.random().toString(36).slice(2)}`,
|
|
216
|
+
firstName: personalInfo.firstName,
|
|
217
|
+
lastName: personalInfo.lastName,
|
|
218
|
+
individual: {
|
|
219
|
+
residential_country_code: address.country || 'USA',
|
|
220
|
+
residential_address_line_one: address.addressLine1 || address.street || '123 Main St',
|
|
221
|
+
residential_address_line_two: address.addressLine2 || '',
|
|
222
|
+
residential_city: address.city || 'Anytown',
|
|
223
|
+
residential_state: address.state || 'CA',
|
|
224
|
+
residential_postal_code: address.postalCode || '12345',
|
|
225
|
+
id_type: 'ssn',
|
|
226
|
+
id_country_code: address.country || 'USA',
|
|
227
|
+
dob: personalInfo.dateOfBirth || '1990-01-01',
|
|
228
|
+
id_number: personalInfo.ssn?.replace(/-/g, '') || '123456789'
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const result = await diviswap.auth.register(registrationData);
|
|
233
|
+
|
|
234
|
+
return NextResponse.json({
|
|
235
|
+
success: true,
|
|
236
|
+
user: result.user,
|
|
237
|
+
customerId: result.user?.id
|
|
238
|
+
});
|
|
239
|
+
} catch (error: any) {
|
|
240
|
+
console.error('[API Route] Customer registration failed:', error);
|
|
241
|
+
throw error;
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
|
|
205
245
|
submitKYC: async (params, { diviswap }) => {
|
|
206
246
|
// Set customer context before KYC submission
|
|
207
247
|
setCustomerContext(diviswap, params);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { useState, useEffect } from "react";
|
|
4
4
|
import { ArrowRight, ArrowLeft, CheckCircle, AlertCircle, Loader2 } from 'lucide-react';
|
|
5
|
+
import './diviswap-kyc-wizard.css';
|
|
5
6
|
|
|
6
7
|
// Types
|
|
7
8
|
type KYCStep = 'intro' | 'personal' | 'identification' | 'address' | 'review' | 'success';
|
|
@@ -143,7 +144,7 @@ export function DiviswapKYC({
|
|
|
143
144
|
method: 'POST',
|
|
144
145
|
headers: { 'Content-Type': 'application/json' },
|
|
145
146
|
body: JSON.stringify({
|
|
146
|
-
action: '
|
|
147
|
+
action: 'registerCustomer',
|
|
147
148
|
...kycData
|
|
148
149
|
}),
|
|
149
150
|
});
|