@diviswap/sdk 1.7.21 → 1.7.24

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 CHANGED
@@ -1937,7 +1937,7 @@ async function uninstall(options = {}) {
1937
1937
  }
1938
1938
 
1939
1939
  // package.json
1940
- var version = "1.7.21";
1940
+ var version = "1.7.24";
1941
1941
 
1942
1942
  // src/cli/index.ts
1943
1943
  var program = new commander.Command();
@@ -5,12 +5,15 @@ import type { Transaction, Payee } from '@diviswap/sdk';
5
5
  import { revalidatePath } from 'next/cache';
6
6
 
7
7
  // Initialize Diviswap SDK in Partner mode
8
- function getDiviswap(customerId?: string) {
8
+ // customerId: unique identifier for the customer in YOUR system (required for user-specific operations)
9
+ // customerEmail: optional, only needed if you want Diviswap to send email notifications
10
+ function getDiviswap(customerId?: string, customerEmail?: string) {
9
11
  return Diviswap.init({
10
12
  keyId: process.env.DIVISWAP_PARTNER_KEY_ID!,
11
13
  secretKey: process.env.DIVISWAP_PARTNER_SECRET_KEY!,
12
14
  environment: (process.env.NEXT_PUBLIC_DIVISWAP_ENV as 'production' | 'sandbox') || 'sandbox',
13
- customerId, // Associate operations with this customer
15
+ customerId, // Your unique identifier for this customer (e.g., email, UUID, username)
16
+ customerEmail, // Optional: for email notifications
14
17
  debug: process.env.NODE_ENV === 'development'
15
18
  });
16
19
  }
@@ -26,9 +29,12 @@ export async function createTransactionAction(data: {
26
29
  fromAddress?: string;
27
30
  chain?: string;
28
31
  txHash?: string; // Required for offramp - transaction hash from blockchain
32
+ // Customer identification for partner auth
33
+ customerId?: string; // Required: unique identifier in your system
34
+ customerEmail?: string; // Optional: for email notifications
29
35
  }) {
30
36
  try {
31
- const diviswap = getDiviswap();
37
+ const diviswap = getDiviswap(data.customerId, data.customerEmail);
32
38
 
33
39
  // Use the appropriate method based on transaction type
34
40
  let transaction;
@@ -61,14 +67,18 @@ export async function createTransactionAction(data: {
61
67
  }
62
68
  }
63
69
 
64
- export async function getTransactionsAction(filters?: {
65
- limit?: number;
66
- offset?: number;
67
- status?: 'pending' | 'processing' | 'completed' | 'failed';
68
- type?: 'onramp' | 'offramp';
69
- }) {
70
+ export async function getTransactionsAction(
71
+ customerId?: string,
72
+ customerEmail?: string,
73
+ filters?: {
74
+ limit?: number;
75
+ offset?: number;
76
+ status?: 'pending' | 'processing' | 'completed' | 'failed';
77
+ type?: 'onramp' | 'offramp';
78
+ }
79
+ ) {
70
80
  try {
71
- const diviswap = getDiviswap();
81
+ const diviswap = getDiviswap(customerId, customerEmail);
72
82
  const transactions = await diviswap.transactions.list(filters);
73
83
 
74
84
  return { success: true, transactions };
@@ -81,9 +91,9 @@ export async function getTransactionsAction(filters?: {
81
91
  }
82
92
 
83
93
  // Payee Server Actions
84
- export async function getPayeesAction() {
94
+ export async function getPayeesAction(customerId?: string, customerEmail?: string) {
85
95
  try {
86
- const diviswap = getDiviswap();
96
+ const diviswap = getDiviswap(customerId, customerEmail);
87
97
  const payees = await diviswap.payees.list();
88
98
 
89
99
  return { success: true, payees };
@@ -100,9 +110,11 @@ export async function createPayeeAction(data: {
100
110
  accountNumber: string;
101
111
  routingNumber: string;
102
112
  accountType: 'checking' | 'savings';
113
+ customerId?: string; // Required: unique identifier in your system
114
+ customerEmail?: string; // Optional: for email notifications
103
115
  }) {
104
116
  try {
105
- const diviswap = getDiviswap();
117
+ const diviswap = getDiviswap(data.customerId, data.customerEmail);
106
118
  const payee = await diviswap.payees.create({
107
119
  nickname: data.nickname,
108
120
  accountNumber: data.accountNumber,
@@ -121,9 +133,9 @@ export async function createPayeeAction(data: {
121
133
  }
122
134
  }
123
135
 
124
- export async function deletePayeeAction(payeeId: string) {
136
+ export async function deletePayeeAction(payeeId: string, customerId?: string, customerEmail?: string) {
125
137
  try {
126
- const diviswap = getDiviswap();
138
+ const diviswap = getDiviswap(customerId, customerEmail);
127
139
  await diviswap.payees.delete(payeeId);
128
140
 
129
141
  revalidatePath('/diviswap');
@@ -164,9 +176,9 @@ export async function getDepositAddressesAction() {
164
176
  }
165
177
 
166
178
  // Fee Calculation Actions
167
- export async function calculateFeesAction(amount: number) {
179
+ export async function calculateFeesAction(amount: number, customerId?: string, customerEmail?: string) {
168
180
  try {
169
- const diviswap = getDiviswap();
181
+ const diviswap = getDiviswap(customerId, customerEmail);
170
182
  const fees = await diviswap.fees.calculateFees({ amount });
171
183
  return { success: true, fees };
172
184
  } catch (error) {
@@ -179,6 +191,7 @@ export async function calculateFeesAction(amount: number) {
179
191
 
180
192
  export async function getIntegratorFeesAction() {
181
193
  try {
194
+ // Integrator fees are partner-wide, no customer context needed
182
195
  const diviswap = getDiviswap();
183
196
  const fees = await diviswap.fees.getFees();
184
197
 
@@ -196,6 +209,7 @@ export async function updateIntegratorFeeAction(data: {
196
209
  userId?: number;
197
210
  }) {
198
211
  try {
212
+ // Integrator fee updates are partner-wide, no customer context needed
199
213
  const diviswap = getDiviswap();
200
214
  const fee = await diviswap.fees.setFee(data);
201
215
 
@@ -210,9 +224,9 @@ export async function updateIntegratorFeeAction(data: {
210
224
  }
211
225
 
212
226
  // Authentication Server Actions (for server components that need auth status)
213
- export async function getCurrentUserAction() {
227
+ export async function getCurrentUserAction(customerId?: string, customerEmail?: string) {
214
228
  try {
215
- const diviswap = getDiviswap();
229
+ const diviswap = getDiviswap(customerId, customerEmail);
216
230
  const user = await diviswap.auth.getProfile();
217
231
 
218
232
  return { success: true, user };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { d as Address, x as ApiResponse, A as AuthCredentials, m as AuthMode, u as AuthResponse, h as CHAIN_IDS, g as ChainName, C as ComplianceStatus, e as CreateAddressRequest, v as CreatePayeeRequest, f as DeleteAddressRequest, D as Diviswap, a as DiviswapConfig, E as Environment, k as EthereumWallet, I as IndividualData, z as KybMetadata, b as KybStatus, F as KycDocumentRequest, y as KycMetadata, G as KycPersonalInfo, c as KycSessionResponse, K as KycStatus, r as LegacyDiviswapConfig, D as LiberEx, L as LiberExConfig, w as OfframpRequest, O as OnrampRequest, B as OrganizationInfo, o as PartnerDiviswapConfig, q as PartnerLiberExConfig, P as Payee, R as RegisterRequest, S as SetDefaultAddressRequest, T as Transaction, U as User, n as UserDiviswapConfig, p as UserLiberExConfig, W as WalletConnection, i as WalletTracker, l as WalletTrackingConfig, j as connectWallet, s as setupWalletTracking, t as trackCurrentWallet } from './wallet-CNiPxV5L.mjs';
1
+ export { d as Address, x as ApiResponse, A as AuthCredentials, m as AuthMode, u as AuthResponse, h as CHAIN_IDS, g as ChainName, C as ComplianceStatus, e as CreateAddressRequest, v as CreatePayeeRequest, f as DeleteAddressRequest, D as Diviswap, a as DiviswapConfig, E as Environment, k as EthereumWallet, I as IndividualData, z as KybMetadata, b as KybStatus, F as KycDocumentRequest, y as KycMetadata, G as KycPersonalInfo, c as KycSessionResponse, K as KycStatus, r as LegacyDiviswapConfig, D as LiberEx, L as LiberExConfig, w as OfframpRequest, O as OnrampRequest, B as OrganizationInfo, o as PartnerDiviswapConfig, q as PartnerLiberExConfig, P as Payee, R as RegisterRequest, S as SetDefaultAddressRequest, T as Transaction, U as User, n as UserDiviswapConfig, p as UserLiberExConfig, W as WalletConnection, i as WalletTracker, l as WalletTrackingConfig, j as connectWallet, s as setupWalletTracking, t as trackCurrentWallet } from './wallet-DZymADRo.mjs';
2
2
 
3
3
  /**
4
4
  * Custom error classes for Diviswap SDK
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { d as Address, x as ApiResponse, A as AuthCredentials, m as AuthMode, u as AuthResponse, h as CHAIN_IDS, g as ChainName, C as ComplianceStatus, e as CreateAddressRequest, v as CreatePayeeRequest, f as DeleteAddressRequest, D as Diviswap, a as DiviswapConfig, E as Environment, k as EthereumWallet, I as IndividualData, z as KybMetadata, b as KybStatus, F as KycDocumentRequest, y as KycMetadata, G as KycPersonalInfo, c as KycSessionResponse, K as KycStatus, r as LegacyDiviswapConfig, D as LiberEx, L as LiberExConfig, w as OfframpRequest, O as OnrampRequest, B as OrganizationInfo, o as PartnerDiviswapConfig, q as PartnerLiberExConfig, P as Payee, R as RegisterRequest, S as SetDefaultAddressRequest, T as Transaction, U as User, n as UserDiviswapConfig, p as UserLiberExConfig, W as WalletConnection, i as WalletTracker, l as WalletTrackingConfig, j as connectWallet, s as setupWalletTracking, t as trackCurrentWallet } from './wallet-CNiPxV5L.js';
1
+ export { d as Address, x as ApiResponse, A as AuthCredentials, m as AuthMode, u as AuthResponse, h as CHAIN_IDS, g as ChainName, C as ComplianceStatus, e as CreateAddressRequest, v as CreatePayeeRequest, f as DeleteAddressRequest, D as Diviswap, a as DiviswapConfig, E as Environment, k as EthereumWallet, I as IndividualData, z as KybMetadata, b as KybStatus, F as KycDocumentRequest, y as KycMetadata, G as KycPersonalInfo, c as KycSessionResponse, K as KycStatus, r as LegacyDiviswapConfig, D as LiberEx, L as LiberExConfig, w as OfframpRequest, O as OnrampRequest, B as OrganizationInfo, o as PartnerDiviswapConfig, q as PartnerLiberExConfig, P as Payee, R as RegisterRequest, S as SetDefaultAddressRequest, T as Transaction, U as User, n as UserDiviswapConfig, p as UserLiberExConfig, W as WalletConnection, i as WalletTracker, l as WalletTrackingConfig, j as connectWallet, s as setupWalletTracking, t as trackCurrentWallet } from './wallet-DZymADRo.js';
2
2
 
3
3
  /**
4
4
  * Custom error classes for Diviswap SDK
package/dist/index.js CHANGED
@@ -266,11 +266,12 @@ var PayeesModule = class {
266
266
  */
267
267
  async create(data) {
268
268
  try {
269
+ let response;
269
270
  if (data.accountType === "debit_card") {
270
271
  if (!data.debitCard) {
271
272
  throw new Error("Debit card information is required for debit_card account type");
272
273
  }
273
- return await this.client.post("/api/v1/payees", {
274
+ response = await this.client.post("/api/v1/payees", {
274
275
  name: data.nickname,
275
276
  debit_card: {
276
277
  number: data.debitCard.number,
@@ -284,7 +285,7 @@ var PayeesModule = class {
284
285
  if (!data.accountNumber || !data.routingNumber) {
285
286
  throw new Error("Account number and routing number are required for bank accounts");
286
287
  }
287
- return await this.client.post("/api/v1/payees", {
288
+ response = await this.client.post("/api/v1/payees", {
288
289
  name: data.nickname,
289
290
  account_number: data.accountNumber,
290
291
  routing_number: data.routingNumber,
@@ -292,6 +293,7 @@ var PayeesModule = class {
292
293
  set_as_default: data.setAsDefault || false
293
294
  });
294
295
  }
296
+ return this.transformPayee(response);
295
297
  } catch (error) {
296
298
  throw new Error(`Failed to create payee: ${error.message}`);
297
299
  }
@@ -322,7 +324,10 @@ var PayeesModule = class {
322
324
  payeesArray = response.results;
323
325
  }
324
326
  }
325
- return payeesArray.map((p) => ({
327
+ return payeesArray.map((p) => this.transformPayee(p));
328
+ }
329
+ transformPayee(p) {
330
+ return {
326
331
  id: p.id,
327
332
  nickname: p.nickname || p.name,
328
333
  accountNumber: p.accountNumber || p.account_number || "",
@@ -332,7 +337,7 @@ var PayeesModule = class {
332
337
  verified: p.verified ?? false,
333
338
  createdAt: p.createdAt || p.created_at || "",
334
339
  updatedAt: p.updatedAt || p.updated_at || ""
335
- }));
340
+ };
336
341
  }
337
342
  /**
338
343
  * Get a specific payee
@@ -359,10 +364,11 @@ var PayeesModule = class {
359
364
  * ```
360
365
  */
361
366
  async setDefault(payeeId) {
362
- return this.client.put("/api/v1/users/payees", {
367
+ const response = await this.client.put("/api/v1/users/payees", {
363
368
  payeeId,
364
369
  setAsDefault: true
365
370
  }, { useApiKey: false });
371
+ return this.transformPayee(response);
366
372
  }
367
373
  /**
368
374
  * Delete a payee
@@ -1835,6 +1841,9 @@ var UnifiedApiClient = class _UnifiedApiClient {
1835
1841
  try {
1836
1842
  const controller = new AbortController();
1837
1843
  const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
1844
+ if (this.config.debug) {
1845
+ console.log(`[Diviswap SDK] ${method} ${url}`);
1846
+ }
1838
1847
  const response = await fetch(url, {
1839
1848
  method,
1840
1849
  headers: requestHeaders,
@@ -1849,6 +1858,9 @@ var UnifiedApiClient = class _UnifiedApiClient {
1849
1858
  } catch {
1850
1859
  responseData = responseText;
1851
1860
  }
1861
+ if (this.config.debug) {
1862
+ console.log(`[Diviswap SDK] Response ${response.status}: ${responseText.substring(0, 500)}`);
1863
+ }
1852
1864
  if (!response.ok) {
1853
1865
  await this.handleErrorResponse(response, responseData);
1854
1866
  }