@zendfi/sdk 0.3.0 → 0.4.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/README.md +0 -290
- package/README.md.old +326 -0
- package/dist/express.d.mts +1 -1
- package/dist/express.d.ts +1 -1
- package/dist/index.d.mts +166 -4
- package/dist/index.d.ts +166 -4
- package/dist/index.js +339 -74
- package/dist/index.mjs +332 -74
- package/dist/nextjs.d.mts +1 -1
- package/dist/nextjs.d.ts +1 -1
- package/dist/{webhook-handler-DG-zic8m.d.mts → webhook-handler-B9ZczHQn.d.mts} +2 -19
- package/dist/{webhook-handler-DG-zic8m.d.ts → webhook-handler-B9ZczHQn.d.ts} +2 -19
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7,41 +7,6 @@ import {
|
|
|
7
7
|
import fetch from "cross-fetch";
|
|
8
8
|
import { createHmac, timingSafeEqual } from "crypto";
|
|
9
9
|
|
|
10
|
-
// src/types.ts
|
|
11
|
-
var ZendFiError = class extends Error {
|
|
12
|
-
constructor(message, statusCode, code, details) {
|
|
13
|
-
super(message);
|
|
14
|
-
this.statusCode = statusCode;
|
|
15
|
-
this.code = code;
|
|
16
|
-
this.details = details;
|
|
17
|
-
this.name = "ZendFiError";
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
var AuthenticationError = class extends ZendFiError {
|
|
21
|
-
constructor(message = "Authentication failed") {
|
|
22
|
-
super(message, 401, "AUTHENTICATION_ERROR");
|
|
23
|
-
this.name = "AuthenticationError";
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
var ValidationError = class extends ZendFiError {
|
|
27
|
-
constructor(message, details) {
|
|
28
|
-
super(message, 400, "VALIDATION_ERROR", details);
|
|
29
|
-
this.name = "ValidationError";
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
var NetworkError = class extends ZendFiError {
|
|
33
|
-
constructor(message) {
|
|
34
|
-
super(message, 0, "NETWORK_ERROR");
|
|
35
|
-
this.name = "NetworkError";
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var RateLimitError = class extends ZendFiError {
|
|
39
|
-
constructor(message = "Rate limit exceeded") {
|
|
40
|
-
super(message, 429, "RATE_LIMIT_ERROR");
|
|
41
|
-
this.name = "RateLimitError";
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
10
|
// src/utils.ts
|
|
46
11
|
var ConfigLoader = class {
|
|
47
12
|
/**
|
|
@@ -59,7 +24,8 @@ var ConfigLoader = class {
|
|
|
59
24
|
mode,
|
|
60
25
|
timeout: options?.timeout ?? 3e4,
|
|
61
26
|
retries: options?.retries ?? 3,
|
|
62
|
-
idempotencyEnabled: options?.idempotencyEnabled ?? true
|
|
27
|
+
idempotencyEnabled: options?.idempotencyEnabled ?? true,
|
|
28
|
+
debug: options?.debug ?? false
|
|
63
29
|
};
|
|
64
30
|
}
|
|
65
31
|
/**
|
|
@@ -171,28 +137,6 @@ var ConfigLoader = class {
|
|
|
171
137
|
}
|
|
172
138
|
}
|
|
173
139
|
};
|
|
174
|
-
function parseError(response, body) {
|
|
175
|
-
const statusCode = response.status;
|
|
176
|
-
const errorMessage = body?.error || body?.message || response.statusText || "Unknown error";
|
|
177
|
-
const errorCode = body?.code;
|
|
178
|
-
const details = body?.details;
|
|
179
|
-
switch (statusCode) {
|
|
180
|
-
case 401:
|
|
181
|
-
case 403:
|
|
182
|
-
return new AuthenticationError(errorMessage);
|
|
183
|
-
case 400:
|
|
184
|
-
return new ValidationError(errorMessage, details);
|
|
185
|
-
case 429:
|
|
186
|
-
return new RateLimitError(errorMessage);
|
|
187
|
-
case 500:
|
|
188
|
-
case 502:
|
|
189
|
-
case 503:
|
|
190
|
-
case 504:
|
|
191
|
-
return new NetworkError(errorMessage);
|
|
192
|
-
default:
|
|
193
|
-
return new ZendFiError(errorMessage, statusCode, errorCode, details);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
140
|
function generateIdempotencyKey() {
|
|
197
141
|
const timestamp = Date.now();
|
|
198
142
|
const random = Math.random().toString(36).substring(2, 15);
|
|
@@ -202,16 +146,261 @@ function sleep(ms) {
|
|
|
202
146
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
203
147
|
}
|
|
204
148
|
|
|
149
|
+
// src/errors.ts
|
|
150
|
+
var ZendFiError2 = class _ZendFiError extends Error {
|
|
151
|
+
code;
|
|
152
|
+
type;
|
|
153
|
+
suggestion;
|
|
154
|
+
docs_url;
|
|
155
|
+
statusCode;
|
|
156
|
+
response;
|
|
157
|
+
constructor(data) {
|
|
158
|
+
super(data.message);
|
|
159
|
+
this.name = "ZendFiError";
|
|
160
|
+
this.code = data.code;
|
|
161
|
+
this.type = data.type;
|
|
162
|
+
this.suggestion = data.suggestion;
|
|
163
|
+
this.statusCode = data.statusCode;
|
|
164
|
+
this.response = data.response;
|
|
165
|
+
this.docs_url = `https://docs.zendfi.com/errors/${data.code}`;
|
|
166
|
+
if (Error.captureStackTrace) {
|
|
167
|
+
Error.captureStackTrace(this, _ZendFiError);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Format error for display
|
|
172
|
+
*/
|
|
173
|
+
toString() {
|
|
174
|
+
let message = `[${this.code}] ${this.message}`;
|
|
175
|
+
if (this.suggestion) {
|
|
176
|
+
message += `
|
|
177
|
+
\u{1F4A1} Suggestion: ${this.suggestion}`;
|
|
178
|
+
}
|
|
179
|
+
message += `
|
|
180
|
+
\u{1F4DA} Docs: ${this.docs_url}`;
|
|
181
|
+
return message;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Convert error to JSON
|
|
185
|
+
*/
|
|
186
|
+
toJSON() {
|
|
187
|
+
return {
|
|
188
|
+
name: this.name,
|
|
189
|
+
code: this.code,
|
|
190
|
+
type: this.type,
|
|
191
|
+
message: this.message,
|
|
192
|
+
suggestion: this.suggestion,
|
|
193
|
+
docs_url: this.docs_url,
|
|
194
|
+
statusCode: this.statusCode
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
var AuthenticationError2 = class extends ZendFiError2 {
|
|
199
|
+
constructor(message, code = "authentication_failed", suggestion) {
|
|
200
|
+
super({
|
|
201
|
+
code,
|
|
202
|
+
message,
|
|
203
|
+
type: "authentication_error",
|
|
204
|
+
suggestion: suggestion || "Check your API key in the dashboard at https://app.zendfi.com/settings/api-keys",
|
|
205
|
+
statusCode: 401
|
|
206
|
+
});
|
|
207
|
+
this.name = "AuthenticationError";
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
var PaymentError = class extends ZendFiError2 {
|
|
211
|
+
constructor(message, code = "payment_failed", suggestion) {
|
|
212
|
+
super({
|
|
213
|
+
code,
|
|
214
|
+
message,
|
|
215
|
+
type: "payment_error",
|
|
216
|
+
suggestion,
|
|
217
|
+
statusCode: 400
|
|
218
|
+
});
|
|
219
|
+
this.name = "PaymentError";
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
var ValidationError2 = class extends ZendFiError2 {
|
|
223
|
+
constructor(message, code = "validation_failed", suggestion) {
|
|
224
|
+
super({
|
|
225
|
+
code,
|
|
226
|
+
message,
|
|
227
|
+
type: "validation_error",
|
|
228
|
+
suggestion,
|
|
229
|
+
statusCode: 400
|
|
230
|
+
});
|
|
231
|
+
this.name = "ValidationError";
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
var NetworkError2 = class extends ZendFiError2 {
|
|
235
|
+
constructor(message, code = "network_error", suggestion) {
|
|
236
|
+
super({
|
|
237
|
+
code,
|
|
238
|
+
message,
|
|
239
|
+
type: "network_error",
|
|
240
|
+
suggestion: suggestion || "Check your internet connection and try again",
|
|
241
|
+
statusCode: 0
|
|
242
|
+
});
|
|
243
|
+
this.name = "NetworkError";
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
var RateLimitError2 = class extends ZendFiError2 {
|
|
247
|
+
constructor(message, retryAfter) {
|
|
248
|
+
super({
|
|
249
|
+
code: "rate_limit_exceeded",
|
|
250
|
+
message,
|
|
251
|
+
type: "rate_limit_error",
|
|
252
|
+
suggestion: retryAfter ? `Wait ${retryAfter} seconds before retrying` : "You are making too many requests. Please slow down.",
|
|
253
|
+
statusCode: 429
|
|
254
|
+
});
|
|
255
|
+
this.name = "RateLimitError";
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
var ApiError = class extends ZendFiError2 {
|
|
259
|
+
constructor(message, code, statusCode, response) {
|
|
260
|
+
super({
|
|
261
|
+
code,
|
|
262
|
+
message,
|
|
263
|
+
type: "api_error",
|
|
264
|
+
statusCode,
|
|
265
|
+
response
|
|
266
|
+
});
|
|
267
|
+
this.name = "ApiError";
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
var WebhookError = class extends ZendFiError2 {
|
|
271
|
+
constructor(message, code = "webhook_verification_failed", suggestion) {
|
|
272
|
+
super({
|
|
273
|
+
code,
|
|
274
|
+
message,
|
|
275
|
+
type: "webhook_error",
|
|
276
|
+
suggestion: suggestion || "Check your webhook secret matches the one in your dashboard",
|
|
277
|
+
statusCode: 400
|
|
278
|
+
});
|
|
279
|
+
this.name = "WebhookError";
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
function createZendFiError(statusCode, responseBody, message) {
|
|
283
|
+
const errorMessage = message || responseBody?.error?.message || responseBody?.message || "An error occurred";
|
|
284
|
+
const errorCode = responseBody?.error?.code || responseBody?.code || "unknown_error";
|
|
285
|
+
if (statusCode === 401) {
|
|
286
|
+
return new AuthenticationError2(
|
|
287
|
+
errorMessage,
|
|
288
|
+
errorCode,
|
|
289
|
+
"Verify your API key is correct and not expired"
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
if (statusCode === 429) {
|
|
293
|
+
const retryAfter = responseBody?.retry_after;
|
|
294
|
+
return new RateLimitError2(errorMessage, retryAfter);
|
|
295
|
+
}
|
|
296
|
+
if (statusCode === 400 || statusCode === 422) {
|
|
297
|
+
return new ValidationError2(errorMessage, errorCode);
|
|
298
|
+
}
|
|
299
|
+
if (statusCode === 402) {
|
|
300
|
+
return new PaymentError(errorMessage, errorCode);
|
|
301
|
+
}
|
|
302
|
+
if (statusCode === 0 || statusCode >= 500) {
|
|
303
|
+
return new NetworkError2(
|
|
304
|
+
errorMessage,
|
|
305
|
+
errorCode,
|
|
306
|
+
statusCode >= 500 ? "The ZendFi API is experiencing issues. Please try again later." : void 0
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
return new ApiError(errorMessage, errorCode, statusCode, responseBody);
|
|
310
|
+
}
|
|
311
|
+
var ERROR_CODES = {
|
|
312
|
+
// Authentication
|
|
313
|
+
INVALID_API_KEY: "invalid_api_key",
|
|
314
|
+
API_KEY_EXPIRED: "api_key_expired",
|
|
315
|
+
API_KEY_REVOKED: "api_key_revoked",
|
|
316
|
+
// Payment
|
|
317
|
+
INSUFFICIENT_BALANCE: "insufficient_balance",
|
|
318
|
+
PAYMENT_DECLINED: "payment_declined",
|
|
319
|
+
PAYMENT_EXPIRED: "payment_expired",
|
|
320
|
+
INVALID_AMOUNT: "invalid_amount",
|
|
321
|
+
INVALID_CURRENCY: "invalid_currency",
|
|
322
|
+
// Validation
|
|
323
|
+
MISSING_REQUIRED_FIELD: "missing_required_field",
|
|
324
|
+
INVALID_PARAMETER: "invalid_parameter",
|
|
325
|
+
// Network
|
|
326
|
+
NETWORK_ERROR: "network_error",
|
|
327
|
+
TIMEOUT: "timeout",
|
|
328
|
+
// Rate limiting
|
|
329
|
+
RATE_LIMIT_EXCEEDED: "rate_limit_exceeded",
|
|
330
|
+
// Webhook
|
|
331
|
+
WEBHOOK_SIGNATURE_INVALID: "webhook_signature_invalid",
|
|
332
|
+
WEBHOOK_TIMESTAMP_TOO_OLD: "webhook_timestamp_too_old"
|
|
333
|
+
};
|
|
334
|
+
function isZendFiError(error) {
|
|
335
|
+
return error instanceof ZendFiError2;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// src/interceptors.ts
|
|
339
|
+
var InterceptorManager = class {
|
|
340
|
+
handlers = [];
|
|
341
|
+
/**
|
|
342
|
+
* Add an interceptor
|
|
343
|
+
*/
|
|
344
|
+
use(handler) {
|
|
345
|
+
this.handlers.push(handler);
|
|
346
|
+
return this.handlers.length - 1;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Remove an interceptor
|
|
350
|
+
*/
|
|
351
|
+
eject(id) {
|
|
352
|
+
if (this.handlers[id]) {
|
|
353
|
+
this.handlers[id] = null;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Execute all interceptors in sequence
|
|
358
|
+
*/
|
|
359
|
+
async execute(initialValue) {
|
|
360
|
+
let result = initialValue;
|
|
361
|
+
for (const handler of this.handlers) {
|
|
362
|
+
if (handler !== null) {
|
|
363
|
+
result = await handler(result);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return result;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Check if any interceptors are registered
|
|
370
|
+
*/
|
|
371
|
+
has() {
|
|
372
|
+
return this.handlers.some((h) => h !== null);
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Clear all interceptors
|
|
376
|
+
*/
|
|
377
|
+
clear() {
|
|
378
|
+
this.handlers = [];
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
function createInterceptors() {
|
|
382
|
+
return {
|
|
383
|
+
request: new InterceptorManager(),
|
|
384
|
+
response: new InterceptorManager(),
|
|
385
|
+
error: new InterceptorManager()
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
|
|
205
389
|
// src/client.ts
|
|
206
390
|
var ZendFiClient = class {
|
|
207
391
|
config;
|
|
392
|
+
interceptors;
|
|
208
393
|
constructor(options) {
|
|
209
394
|
this.config = ConfigLoader.load(options);
|
|
210
395
|
ConfigLoader.validateApiKey(this.config.apiKey);
|
|
211
|
-
|
|
396
|
+
this.interceptors = createInterceptors();
|
|
397
|
+
if (this.config.environment === "development" || this.config.debug) {
|
|
212
398
|
console.log(
|
|
213
399
|
`\u2713 ZendFi SDK initialized in ${this.config.mode} mode (${this.config.mode === "test" ? "devnet" : "mainnet"})`
|
|
214
400
|
);
|
|
401
|
+
if (this.config.debug) {
|
|
402
|
+
console.log("[ZendFi] Debug mode enabled");
|
|
403
|
+
}
|
|
215
404
|
}
|
|
216
405
|
}
|
|
217
406
|
/**
|
|
@@ -531,11 +720,12 @@ var ZendFiClient = class {
|
|
|
531
720
|
return result === 0;
|
|
532
721
|
}
|
|
533
722
|
/**
|
|
534
|
-
* Make an HTTP request with retry logic
|
|
723
|
+
* Make an HTTP request with retry logic, interceptors, and debug logging
|
|
535
724
|
*/
|
|
536
725
|
async request(method, endpoint, data, options = {}) {
|
|
537
726
|
const attempt = options.attempt || 1;
|
|
538
727
|
const idempotencyKey = options.idempotencyKey || (this.config.idempotencyEnabled && method !== "GET" ? generateIdempotencyKey() : void 0);
|
|
728
|
+
const startTime = Date.now();
|
|
539
729
|
try {
|
|
540
730
|
const url = `${this.config.baseURL}${endpoint}`;
|
|
541
731
|
const headers = {
|
|
@@ -545,12 +735,27 @@ var ZendFiClient = class {
|
|
|
545
735
|
if (idempotencyKey) {
|
|
546
736
|
headers["Idempotency-Key"] = idempotencyKey;
|
|
547
737
|
}
|
|
548
|
-
|
|
549
|
-
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
550
|
-
const response = await fetch(url, {
|
|
738
|
+
let requestConfig = {
|
|
551
739
|
method,
|
|
740
|
+
url,
|
|
552
741
|
headers,
|
|
553
|
-
body: data
|
|
742
|
+
body: data
|
|
743
|
+
};
|
|
744
|
+
if (this.interceptors.request.has()) {
|
|
745
|
+
requestConfig = await this.interceptors.request.execute(requestConfig);
|
|
746
|
+
}
|
|
747
|
+
if (this.config.debug) {
|
|
748
|
+
console.log(`[ZendFi] ${method} ${endpoint}`);
|
|
749
|
+
if (data) {
|
|
750
|
+
console.log("[ZendFi] Request:", JSON.stringify(data, null, 2));
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
const controller = new AbortController();
|
|
754
|
+
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
755
|
+
const response = await fetch(requestConfig.url, {
|
|
756
|
+
method: requestConfig.method,
|
|
757
|
+
headers: requestConfig.headers,
|
|
758
|
+
body: requestConfig.body ? JSON.stringify(requestConfig.body) : void 0,
|
|
554
759
|
signal: controller.signal
|
|
555
760
|
});
|
|
556
761
|
clearTimeout(timeoutId);
|
|
@@ -560,32 +765,78 @@ var ZendFiClient = class {
|
|
|
560
765
|
} catch {
|
|
561
766
|
body = null;
|
|
562
767
|
}
|
|
768
|
+
const duration = Date.now() - startTime;
|
|
563
769
|
if (!response.ok) {
|
|
564
|
-
const error =
|
|
770
|
+
const error = createZendFiError(response.status, body);
|
|
771
|
+
if (this.config.debug) {
|
|
772
|
+
console.error(`[ZendFi] \u274C ${response.status} ${response.statusText} (${duration}ms)`);
|
|
773
|
+
console.error(`[ZendFi] Error:`, error.toString());
|
|
774
|
+
}
|
|
565
775
|
if (response.status >= 500 && attempt < this.config.retries) {
|
|
566
776
|
const delay = Math.pow(2, attempt) * 1e3;
|
|
777
|
+
if (this.config.debug) {
|
|
778
|
+
console.log(`[ZendFi] Retrying in ${delay}ms... (attempt ${attempt + 1}/${this.config.retries})`);
|
|
779
|
+
}
|
|
567
780
|
await sleep(delay);
|
|
568
781
|
return this.request(method, endpoint, data, {
|
|
569
782
|
idempotencyKey,
|
|
570
783
|
attempt: attempt + 1
|
|
571
784
|
});
|
|
572
785
|
}
|
|
786
|
+
if (this.interceptors.error.has()) {
|
|
787
|
+
const interceptedError = await this.interceptors.error.execute(error);
|
|
788
|
+
throw interceptedError;
|
|
789
|
+
}
|
|
573
790
|
throw error;
|
|
574
791
|
}
|
|
575
|
-
|
|
792
|
+
if (this.config.debug) {
|
|
793
|
+
console.log(`[ZendFi] \u2713 ${response.status} ${response.statusText} (${duration}ms)`);
|
|
794
|
+
if (body) {
|
|
795
|
+
console.log("[ZendFi] Response:", JSON.stringify(body, null, 2));
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
const headersObj = {};
|
|
799
|
+
response.headers.forEach((value, key) => {
|
|
800
|
+
headersObj[key] = value;
|
|
801
|
+
});
|
|
802
|
+
let responseData = {
|
|
803
|
+
status: response.status,
|
|
804
|
+
statusText: response.statusText,
|
|
805
|
+
headers: headersObj,
|
|
806
|
+
data: body,
|
|
807
|
+
config: requestConfig
|
|
808
|
+
};
|
|
809
|
+
if (this.interceptors.response.has()) {
|
|
810
|
+
responseData = await this.interceptors.response.execute(responseData);
|
|
811
|
+
}
|
|
812
|
+
return responseData.data;
|
|
576
813
|
} catch (error) {
|
|
577
814
|
if (error.name === "AbortError") {
|
|
578
|
-
|
|
815
|
+
const timeoutError = createZendFiError(0, {}, `Request timeout after ${this.config.timeout}ms`);
|
|
816
|
+
if (this.config.debug) {
|
|
817
|
+
console.error(`[ZendFi] \u274C Timeout (${this.config.timeout}ms)`);
|
|
818
|
+
}
|
|
819
|
+
throw timeoutError;
|
|
579
820
|
}
|
|
580
|
-
if (attempt < this.config.retries && error.message?.includes("fetch")) {
|
|
821
|
+
if (attempt < this.config.retries && (error.message?.includes("fetch") || error.message?.includes("network"))) {
|
|
581
822
|
const delay = Math.pow(2, attempt) * 1e3;
|
|
823
|
+
if (this.config.debug) {
|
|
824
|
+
console.log(`[ZendFi] Network error, retrying in ${delay}ms... (attempt ${attempt + 1}/${this.config.retries})`);
|
|
825
|
+
}
|
|
582
826
|
await sleep(delay);
|
|
583
827
|
return this.request(method, endpoint, data, {
|
|
584
828
|
idempotencyKey,
|
|
585
829
|
attempt: attempt + 1
|
|
586
830
|
});
|
|
587
831
|
}
|
|
588
|
-
|
|
832
|
+
if (isZendFiError(error)) {
|
|
833
|
+
throw error;
|
|
834
|
+
}
|
|
835
|
+
const wrappedError = createZendFiError(0, {}, error.message || "An unknown error occurred");
|
|
836
|
+
if (this.config.debug) {
|
|
837
|
+
console.error(`[ZendFi] \u274C Unexpected error:`, error);
|
|
838
|
+
}
|
|
839
|
+
throw wrappedError;
|
|
589
840
|
}
|
|
590
841
|
}
|
|
591
842
|
};
|
|
@@ -663,13 +914,20 @@ function verifyWebhookSignature(payload, signature, secret) {
|
|
|
663
914
|
});
|
|
664
915
|
}
|
|
665
916
|
export {
|
|
666
|
-
|
|
917
|
+
ApiError,
|
|
918
|
+
AuthenticationError2 as AuthenticationError,
|
|
667
919
|
ConfigLoader,
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
920
|
+
ERROR_CODES,
|
|
921
|
+
InterceptorManager,
|
|
922
|
+
NetworkError2 as NetworkError,
|
|
923
|
+
PaymentError,
|
|
924
|
+
RateLimitError2 as RateLimitError,
|
|
925
|
+
ValidationError2 as ValidationError,
|
|
926
|
+
WebhookError,
|
|
671
927
|
ZendFiClient,
|
|
672
|
-
ZendFiError,
|
|
928
|
+
ZendFiError2 as ZendFiError,
|
|
929
|
+
createZendFiError,
|
|
930
|
+
isZendFiError,
|
|
673
931
|
processWebhook,
|
|
674
932
|
verifyExpressWebhook,
|
|
675
933
|
verifyNextWebhook,
|
package/dist/nextjs.d.mts
CHANGED
package/dist/nextjs.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ interface ZendFiConfig {
|
|
|
21
21
|
timeout?: number;
|
|
22
22
|
retries?: number;
|
|
23
23
|
idempotencyEnabled?: boolean;
|
|
24
|
+
debug?: boolean;
|
|
24
25
|
}
|
|
25
26
|
interface SplitRecipient {
|
|
26
27
|
recipient_wallet: string;
|
|
@@ -168,24 +169,6 @@ interface VerifyWebhookRequest {
|
|
|
168
169
|
signature: string;
|
|
169
170
|
secret: string;
|
|
170
171
|
}
|
|
171
|
-
declare class ZendFiError extends Error {
|
|
172
|
-
statusCode?: number | undefined;
|
|
173
|
-
code?: string | undefined;
|
|
174
|
-
details?: any | undefined;
|
|
175
|
-
constructor(message: string, statusCode?: number | undefined, code?: string | undefined, details?: any | undefined);
|
|
176
|
-
}
|
|
177
|
-
declare class AuthenticationError extends ZendFiError {
|
|
178
|
-
constructor(message?: string);
|
|
179
|
-
}
|
|
180
|
-
declare class ValidationError extends ZendFiError {
|
|
181
|
-
constructor(message: string, details?: any);
|
|
182
|
-
}
|
|
183
|
-
declare class NetworkError extends ZendFiError {
|
|
184
|
-
constructor(message: string);
|
|
185
|
-
}
|
|
186
|
-
declare class RateLimitError extends ZendFiError {
|
|
187
|
-
constructor(message?: string);
|
|
188
|
-
}
|
|
189
172
|
/**
|
|
190
173
|
* Installment Plans - Pay over time
|
|
191
174
|
*/
|
|
@@ -387,4 +370,4 @@ interface WebhookResult {
|
|
|
387
370
|
}
|
|
388
371
|
declare function processWebhook(a: any, b?: any, c?: any): Promise<WebhookResult>;
|
|
389
372
|
|
|
390
|
-
export { type ApproveEscrowRequest as A, type SplitRecipient as B, type CreatePaymentRequest as C, type DisputeEscrowRequest as D, type Escrow as E,
|
|
373
|
+
export { type ApproveEscrowRequest as A, type SplitRecipient as B, type CreatePaymentRequest as C, type DisputeEscrowRequest as D, type Escrow as E, type InstallmentScheduleItem as F, type CreateInstallmentPlanResponse as G, type ReleaseCondition as H, type InstallmentPlan as I, type InvoiceLineItem as J, type ListPaymentsRequest as L, type Payment as P, type RefundEscrowRequest as R, type SubscriptionPlan as S, type VerifyWebhookRequest as V, type WebhookHandlerConfig as W, type ZendFiConfig as Z, type WebhookHandlers as a, type PaginatedResponse as b, type CreateSubscriptionPlanRequest as c, type CreateSubscriptionRequest as d, type Subscription as e, type CreatePaymentLinkRequest as f, type PaymentLink as g, type CreateInstallmentPlanRequest as h, type CreateEscrowRequest as i, type CreateInvoiceRequest as j, type Invoice as k, type WebhookPayload as l, type WebhookResult as m, type WebhookEventHandler as n, type Environment as o, processWebhook as p, type ApiKeyMode as q, type Currency as r, type PaymentToken as s, type PaymentStatus as t, type SubscriptionStatus as u, type InstallmentPlanStatus as v, type EscrowStatus as w, type InvoiceStatus as x, type SplitStatus as y, type WebhookEvent as z };
|
|
@@ -21,6 +21,7 @@ interface ZendFiConfig {
|
|
|
21
21
|
timeout?: number;
|
|
22
22
|
retries?: number;
|
|
23
23
|
idempotencyEnabled?: boolean;
|
|
24
|
+
debug?: boolean;
|
|
24
25
|
}
|
|
25
26
|
interface SplitRecipient {
|
|
26
27
|
recipient_wallet: string;
|
|
@@ -168,24 +169,6 @@ interface VerifyWebhookRequest {
|
|
|
168
169
|
signature: string;
|
|
169
170
|
secret: string;
|
|
170
171
|
}
|
|
171
|
-
declare class ZendFiError extends Error {
|
|
172
|
-
statusCode?: number | undefined;
|
|
173
|
-
code?: string | undefined;
|
|
174
|
-
details?: any | undefined;
|
|
175
|
-
constructor(message: string, statusCode?: number | undefined, code?: string | undefined, details?: any | undefined);
|
|
176
|
-
}
|
|
177
|
-
declare class AuthenticationError extends ZendFiError {
|
|
178
|
-
constructor(message?: string);
|
|
179
|
-
}
|
|
180
|
-
declare class ValidationError extends ZendFiError {
|
|
181
|
-
constructor(message: string, details?: any);
|
|
182
|
-
}
|
|
183
|
-
declare class NetworkError extends ZendFiError {
|
|
184
|
-
constructor(message: string);
|
|
185
|
-
}
|
|
186
|
-
declare class RateLimitError extends ZendFiError {
|
|
187
|
-
constructor(message?: string);
|
|
188
|
-
}
|
|
189
172
|
/**
|
|
190
173
|
* Installment Plans - Pay over time
|
|
191
174
|
*/
|
|
@@ -387,4 +370,4 @@ interface WebhookResult {
|
|
|
387
370
|
}
|
|
388
371
|
declare function processWebhook(a: any, b?: any, c?: any): Promise<WebhookResult>;
|
|
389
372
|
|
|
390
|
-
export { type ApproveEscrowRequest as A, type SplitRecipient as B, type CreatePaymentRequest as C, type DisputeEscrowRequest as D, type Escrow as E,
|
|
373
|
+
export { type ApproveEscrowRequest as A, type SplitRecipient as B, type CreatePaymentRequest as C, type DisputeEscrowRequest as D, type Escrow as E, type InstallmentScheduleItem as F, type CreateInstallmentPlanResponse as G, type ReleaseCondition as H, type InstallmentPlan as I, type InvoiceLineItem as J, type ListPaymentsRequest as L, type Payment as P, type RefundEscrowRequest as R, type SubscriptionPlan as S, type VerifyWebhookRequest as V, type WebhookHandlerConfig as W, type ZendFiConfig as Z, type WebhookHandlers as a, type PaginatedResponse as b, type CreateSubscriptionPlanRequest as c, type CreateSubscriptionRequest as d, type Subscription as e, type CreatePaymentLinkRequest as f, type PaymentLink as g, type CreateInstallmentPlanRequest as h, type CreateEscrowRequest as i, type CreateInvoiceRequest as j, type Invoice as k, type WebhookPayload as l, type WebhookResult as m, type WebhookEventHandler as n, type Environment as o, processWebhook as p, type ApiKeyMode as q, type Currency as r, type PaymentToken as s, type PaymentStatus as t, type SubscriptionStatus as u, type InstallmentPlanStatus as v, type EscrowStatus as w, type InvoiceStatus as x, type SplitStatus as y, type WebhookEvent as z };
|