@diviswap/sdk 1.8.1 → 1.9.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.
package/dist/cli/index.js CHANGED
@@ -681,7 +681,9 @@ async function init(options) {
681
681
  }
682
682
  }
683
683
  if (!framework) {
684
- console.log(kleur__default.default.yellow("\nNo framework selected. Aborting setup."));
684
+ console.log(
685
+ kleur__default.default.yellow("\nNo framework selected. Aborting setup.")
686
+ );
685
687
  process.exit(1);
686
688
  }
687
689
  let environment = options.env || "sandbox";
@@ -770,7 +772,9 @@ async function init(options) {
770
772
  keyId = partnerCredentials.keyId;
771
773
  secretKey = partnerCredentials.secretKey;
772
774
  if (!keyId || !secretKey) {
773
- console.log(kleur__default.default.yellow("\nCredentials not provided. Aborting setup."));
775
+ console.log(
776
+ kleur__default.default.yellow("\nCredentials not provided. Aborting setup.")
777
+ );
774
778
  process.exit(1);
775
779
  }
776
780
  console.log(
@@ -2181,7 +2185,7 @@ async function uninstall(options = {}) {
2181
2185
  }
2182
2186
 
2183
2187
  // package.json
2184
- var version = "1.8.1";
2188
+ var version = "1.9.0";
2185
2189
 
2186
2190
  // src/cli/index.ts
2187
2191
  var program = new commander.Command();
@@ -133,58 +133,14 @@ const postHandlers: Record<string, ActionHandler> = {
133
133
  // Set customer context before API calls
134
134
  setCustomerContext(diviswap, params);
135
135
 
136
-
137
- // Check if the SDK is sending structured debit card data
138
- if (params.debitCard) {
139
- // New SDK structure - debitCard object is already properly formatted
140
- const debitCardPayload = {
141
- nickname: params.nickname,
142
- accountType: 'debit_card' as const,
143
- debitCard: params.debitCard,
144
- setAsDefault: params.setAsDefault || false
145
- };
146
-
147
- const payee = await diviswap.payees.create(debitCardPayload);
148
- return NextResponse.json(payee);
149
- }
150
- // Handle legacy flat structure for debit cards
151
- else if (params.accountType === 'debit_card' || params.payeeType === 'debit') {
152
- // Parse expiry date if needed
153
- let expirationMonth = params.expirationMonth;
154
- let expirationYear = params.expirationYear;
155
-
156
- // If expiry is in MM/YY format in routingNumber field
157
- if (params.routingNumber && params.routingNumber.includes('/')) {
158
- const expiryParts = params.routingNumber.split('/');
159
- expirationMonth = expiryParts[0];
160
- expirationYear = expiryParts[1] ? `20${expiryParts[1]}` : '2025';
161
- }
162
-
163
- const debitCardPayload = {
164
- nickname: params.nickname,
165
- accountType: 'debit_card' as const,
166
- debitCard: {
167
- number: params.accountNumber?.replace(/\s+/g, '') || '', // Remove spaces
168
- expirationMonth: expirationMonth || '12',
169
- expirationYear: expirationYear || '2025',
170
- cvv: params.cvv || '123'
171
- },
172
- setAsDefault: params.setAsDefault || false
173
- };
174
-
175
- const payee = await diviswap.payees.create(debitCardPayload);
176
- return NextResponse.json(payee);
177
- } else {
178
- // Bank account structure
179
- const payee = await diviswap.payees.create({
180
- nickname: params.nickname,
181
- accountNumber: params.accountNumber,
182
- routingNumber: params.routingNumber,
183
- accountType: params.accountType || 'checking',
184
- setAsDefault: params.setAsDefault || false
185
- });
186
- return NextResponse.json(payee);
187
- }
136
+ const payee = await diviswap.payees.create({
137
+ nickname: params.nickname,
138
+ accountNumber: params.accountNumber,
139
+ routingNumber: params.routingNumber,
140
+ accountType: params.accountType || 'checking',
141
+ setAsDefault: params.setAsDefault || false
142
+ });
143
+ return NextResponse.json(payee);
188
144
  },
189
145
 
190
146
  {{#if (includes features "fees")}}
@@ -49,7 +49,7 @@ export interface TransactionFees {
49
49
 
50
50
  export interface PaymentMethod {
51
51
  id: string;
52
- type: 'bank_account' | 'debit_card' | 'credit_card' | 'wire_transfer';
52
+ type: 'bank_account' | 'wire_transfer';
53
53
  last4?: string;
54
54
  bankName?: string;
55
55
  isDefault?: boolean;
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-Ca1U51kT.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-Cohx6L51.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-Ca1U51kT.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-Cohx6L51.js';
2
2
 
3
3
  /**
4
4
  * Custom error classes for Diviswap SDK
package/dist/index.js CHANGED
@@ -252,12 +252,28 @@ var PayeesModule = class {
252
252
  constructor(client) {
253
253
  this.client = client;
254
254
  }
255
+ /**
256
+ * Validate ABA routing number checksum
257
+ */
258
+ validateRoutingNumber(routing) {
259
+ if (routing.length !== 9 || !/^\d{9}$/.test(routing)) {
260
+ return false;
261
+ }
262
+ const d = routing.split("").map(Number);
263
+ const checksum = 3 * (d[0] + d[3] + d[6]) + 7 * (d[1] + d[4] + d[7]) + 1 * (d[2] + d[5] + d[8]);
264
+ return checksum % 10 === 0;
265
+ }
266
+ /**
267
+ * Validate account number format
268
+ */
269
+ validateAccountNumber(account) {
270
+ return /^\d{4,17}$/.test(account);
271
+ }
255
272
  /**
256
273
  * Create a new payee (bank account)
257
274
  *
258
275
  * @example
259
276
  * ```typescript
260
- * // Bank account
261
277
  * const bankAccount = await diviswap.payees.create({
262
278
  * nickname: 'My Checking',
263
279
  * accountNumber: '123456789',
@@ -265,54 +281,32 @@ var PayeesModule = class {
265
281
  * accountType: 'checking',
266
282
  * setAsDefault: true
267
283
  * });
268
- *
269
- * // Debit card
270
- * const debitCard = await diviswap.payees.create({
271
- * nickname: 'My Debit Card',
272
- * accountType: 'debit_card',
273
- * debitCard: {
274
- * number: '4111111111111111',
275
- * expirationMonth: '12',
276
- * expirationYear: '2025',
277
- * cvv: '123'
278
- * },
279
- * setAsDefault: false
280
- * });
281
284
  * ```
282
285
  */
283
286
  async create(data) {
284
287
  try {
285
- let response;
286
- if (data.accountType === "debit_card") {
287
- if (!data.debitCard) {
288
- throw new Error(
289
- "Debit card information is required for debit_card account type"
290
- );
291
- }
292
- response = await this.client.post("/api/v1/payees", {
293
- name: data.nickname,
294
- debit_card: {
295
- number: data.debitCard.number,
296
- expiration_month: data.debitCard.expirationMonth,
297
- expiration_year: data.debitCard.expirationYear,
298
- cvv: data.debitCard.cvv
299
- },
300
- set_as_default: data.setAsDefault || false
301
- });
302
- } else {
303
- if (!data.accountNumber || !data.routingNumber) {
304
- throw new Error(
305
- "Account number and routing number are required for bank accounts"
306
- );
307
- }
308
- response = await this.client.post("/api/v1/payees", {
309
- name: data.nickname,
310
- account_number: data.accountNumber,
311
- routing_number: data.routingNumber,
312
- type: (data.accountType || "checking").toUpperCase(),
313
- set_as_default: data.setAsDefault || false
314
- });
288
+ if (!data.accountNumber || !data.routingNumber) {
289
+ throw new Error(
290
+ "Account number and routing number are required for bank accounts"
291
+ );
292
+ }
293
+ if (!this.validateRoutingNumber(data.routingNumber)) {
294
+ throw new Error(
295
+ "Invalid routing number. Please provide a valid 9-digit ABA routing number."
296
+ );
297
+ }
298
+ if (!this.validateAccountNumber(data.accountNumber)) {
299
+ throw new Error(
300
+ "Invalid account number. Must be 4-17 digits with no letters or special characters."
301
+ );
315
302
  }
303
+ const response = await this.client.post("/api/v1/payees", {
304
+ name: data.nickname,
305
+ account_number: data.accountNumber,
306
+ routing_number: data.routingNumber,
307
+ type: (data.accountType || "checking").toUpperCase(),
308
+ set_as_default: data.setAsDefault || false
309
+ });
316
310
  return this.transformPayee(response);
317
311
  } catch (error) {
318
312
  throw new Error(`Failed to create payee: ${error.message}`);