@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/dist/index.d.mts CHANGED
@@ -1,5 +1,61 @@
1
- import { Z as ZendFiConfig, C as CreatePaymentRequest, P as Payment, L as ListPaymentsRequest, b as PaginatedResponse, c as CreateSubscriptionPlanRequest, S as SubscriptionPlan, d as CreateSubscriptionRequest, e as Subscription, f as CreatePaymentLinkRequest, g as PaymentLink, h as CreateInstallmentPlanRequest, I as InstallmentPlan, i as CreateEscrowRequest, E as Escrow, A as ApproveEscrowRequest, R as RefundEscrowRequest, D as DisputeEscrowRequest, j as CreateInvoiceRequest, k as Invoice, V as VerifyWebhookRequest, l as WebhookPayload } from './webhook-handler-DG-zic8m.mjs';
2
- export { q as ApiKeyMode, G as AuthenticationError, M as CreateInstallmentPlanResponse, r as Currency, o as Environment, w as EscrowStatus, v as InstallmentPlanStatus, K as InstallmentScheduleItem, Q as InvoiceLineItem, x as InvoiceStatus, N as NetworkError, t as PaymentStatus, s as PaymentToken, J as RateLimitError, O as ReleaseCondition, B as SplitRecipient, y as SplitStatus, u as SubscriptionStatus, H as ValidationError, z as WebhookEvent, n as WebhookEventHandler, W as WebhookHandlerConfig, a as WebhookHandlers, m as WebhookResult, F as ZendFiError, p as processWebhook } from './webhook-handler-DG-zic8m.mjs';
1
+ import { Z as ZendFiConfig, C as CreatePaymentRequest, P as Payment, L as ListPaymentsRequest, b as PaginatedResponse, c as CreateSubscriptionPlanRequest, S as SubscriptionPlan, d as CreateSubscriptionRequest, e as Subscription, f as CreatePaymentLinkRequest, g as PaymentLink, h as CreateInstallmentPlanRequest, I as InstallmentPlan, i as CreateEscrowRequest, E as Escrow, A as ApproveEscrowRequest, R as RefundEscrowRequest, D as DisputeEscrowRequest, j as CreateInvoiceRequest, k as Invoice, V as VerifyWebhookRequest, l as WebhookPayload } from './webhook-handler-B9ZczHQn.mjs';
2
+ export { q as ApiKeyMode, G as CreateInstallmentPlanResponse, r as Currency, o as Environment, w as EscrowStatus, v as InstallmentPlanStatus, F as InstallmentScheduleItem, J as InvoiceLineItem, x as InvoiceStatus, t as PaymentStatus, s as PaymentToken, H as ReleaseCondition, B as SplitRecipient, y as SplitStatus, u as SubscriptionStatus, z as WebhookEvent, n as WebhookEventHandler, W as WebhookHandlerConfig, a as WebhookHandlers, m as WebhookResult, p as processWebhook } from './webhook-handler-B9ZczHQn.mjs';
3
+
4
+ /**
5
+ * Request/Response Interceptor System
6
+ *
7
+ * Allows modifying requests before they're sent and responses after they're received
8
+ */
9
+ interface RequestConfig {
10
+ method: string;
11
+ url: string;
12
+ headers: Record<string, string>;
13
+ body?: any;
14
+ }
15
+ interface ResponseData {
16
+ status: number;
17
+ statusText: string;
18
+ headers: Record<string, string>;
19
+ data: any;
20
+ config: RequestConfig;
21
+ }
22
+ type RequestInterceptor = (config: RequestConfig) => RequestConfig | Promise<RequestConfig>;
23
+ type ResponseInterceptor = (response: ResponseData) => ResponseData | Promise<ResponseData>;
24
+ type ErrorInterceptor = (error: Error) => Error | Promise<Error>;
25
+ /**
26
+ * Interceptor Manager
27
+ */
28
+ declare class InterceptorManager<T extends (...args: any[]) => any> {
29
+ private handlers;
30
+ /**
31
+ * Add an interceptor
32
+ */
33
+ use(handler: T): number;
34
+ /**
35
+ * Remove an interceptor
36
+ */
37
+ eject(id: number): void;
38
+ /**
39
+ * Execute all interceptors in sequence
40
+ */
41
+ execute(initialValue: Parameters<T>[0]): Promise<ReturnType<T>>;
42
+ /**
43
+ * Check if any interceptors are registered
44
+ */
45
+ has(): boolean;
46
+ /**
47
+ * Clear all interceptors
48
+ */
49
+ clear(): void;
50
+ }
51
+ /**
52
+ * Interceptors collection
53
+ */
54
+ interface Interceptors {
55
+ request: InterceptorManager<RequestInterceptor>;
56
+ response: InterceptorManager<ResponseInterceptor>;
57
+ error: InterceptorManager<ErrorInterceptor>;
58
+ }
3
59
 
4
60
  /**
5
61
  * ZendFi SDK Client.
@@ -7,6 +63,7 @@ export { q as ApiKeyMode, G as AuthenticationError, M as CreateInstallmentPlanRe
7
63
  */
8
64
  declare class ZendFiClient {
9
65
  private config;
66
+ readonly interceptors: Interceptors;
10
67
  constructor(options?: Partial<ZendFiConfig>);
11
68
  /**
12
69
  * Create a new payment
@@ -174,7 +231,7 @@ declare class ZendFiClient {
174
231
  */
175
232
  private timingSafeEqual;
176
233
  /**
177
- * Make an HTTP request with retry logic
234
+ * Make an HTTP request with retry logic, interceptors, and debug logging
178
235
  */
179
236
  private request;
180
237
  }
@@ -295,4 +352,109 @@ declare function verifyExpressWebhook(request: any, secret?: string): Promise<We
295
352
  */
296
353
  declare function verifyWebhookSignature(payload: string, signature: string, secret: string): boolean;
297
354
 
298
- export { ApproveEscrowRequest, ConfigLoader, CreateEscrowRequest, CreateInstallmentPlanRequest, CreateInvoiceRequest, CreatePaymentLinkRequest, CreatePaymentRequest, CreateSubscriptionPlanRequest, CreateSubscriptionRequest, DisputeEscrowRequest, Escrow, InstallmentPlan, Invoice, ListPaymentsRequest, PaginatedResponse, Payment, PaymentLink, RefundEscrowRequest, Subscription, SubscriptionPlan, VerifyWebhookRequest, WebhookPayload, ZendFiClient, ZendFiConfig, verifyExpressWebhook, verifyNextWebhook, verifyWebhookSignature, zendfi };
355
+ /**
356
+ * ZendFi SDK Error Classes
357
+ *
358
+ * Custom error types with helpful messages, error codes, and documentation links
359
+ */
360
+ type ZendFiErrorType = 'authentication_error' | 'payment_error' | 'validation_error' | 'network_error' | 'rate_limit_error' | 'api_error' | 'webhook_error' | 'unknown_error';
361
+ interface ZendFiErrorData {
362
+ code: string;
363
+ message: string;
364
+ type: ZendFiErrorType;
365
+ suggestion?: string;
366
+ statusCode?: number;
367
+ response?: unknown;
368
+ }
369
+ /**
370
+ * Base ZendFi Error class with enhanced developer experience
371
+ */
372
+ declare class ZendFiError extends Error {
373
+ readonly code: string;
374
+ readonly type: ZendFiErrorType;
375
+ readonly suggestion?: string;
376
+ readonly docs_url: string;
377
+ readonly statusCode?: number;
378
+ readonly response?: unknown;
379
+ constructor(data: ZendFiErrorData);
380
+ /**
381
+ * Format error for display
382
+ */
383
+ toString(): string;
384
+ /**
385
+ * Convert error to JSON
386
+ */
387
+ toJSON(): Record<string, unknown>;
388
+ }
389
+ /**
390
+ * Authentication errors
391
+ */
392
+ declare class AuthenticationError extends ZendFiError {
393
+ constructor(message: string, code?: string, suggestion?: string);
394
+ }
395
+ /**
396
+ * Payment processing errors
397
+ */
398
+ declare class PaymentError extends ZendFiError {
399
+ constructor(message: string, code?: string, suggestion?: string);
400
+ }
401
+ /**
402
+ * Validation errors
403
+ */
404
+ declare class ValidationError extends ZendFiError {
405
+ constructor(message: string, code?: string, suggestion?: string);
406
+ }
407
+ /**
408
+ * Network/connection errors
409
+ */
410
+ declare class NetworkError extends ZendFiError {
411
+ constructor(message: string, code?: string, suggestion?: string);
412
+ }
413
+ /**
414
+ * Rate limit errors
415
+ */
416
+ declare class RateLimitError extends ZendFiError {
417
+ constructor(message: string, retryAfter?: number);
418
+ }
419
+ /**
420
+ * Generic API errors
421
+ */
422
+ declare class ApiError extends ZendFiError {
423
+ constructor(message: string, code: string, statusCode: number, response?: unknown);
424
+ }
425
+ /**
426
+ * Webhook verification errors
427
+ */
428
+ declare class WebhookError extends ZendFiError {
429
+ constructor(message: string, code?: string, suggestion?: string);
430
+ }
431
+ /**
432
+ * Error factory - creates appropriate error based on response
433
+ */
434
+ declare function createZendFiError(statusCode: number, responseBody: any, message?: string): ZendFiError;
435
+ /**
436
+ * Common error codes and their messages
437
+ */
438
+ declare const ERROR_CODES: {
439
+ readonly INVALID_API_KEY: "invalid_api_key";
440
+ readonly API_KEY_EXPIRED: "api_key_expired";
441
+ readonly API_KEY_REVOKED: "api_key_revoked";
442
+ readonly INSUFFICIENT_BALANCE: "insufficient_balance";
443
+ readonly PAYMENT_DECLINED: "payment_declined";
444
+ readonly PAYMENT_EXPIRED: "payment_expired";
445
+ readonly INVALID_AMOUNT: "invalid_amount";
446
+ readonly INVALID_CURRENCY: "invalid_currency";
447
+ readonly MISSING_REQUIRED_FIELD: "missing_required_field";
448
+ readonly INVALID_PARAMETER: "invalid_parameter";
449
+ readonly NETWORK_ERROR: "network_error";
450
+ readonly TIMEOUT: "timeout";
451
+ readonly RATE_LIMIT_EXCEEDED: "rate_limit_exceeded";
452
+ readonly WEBHOOK_SIGNATURE_INVALID: "webhook_signature_invalid";
453
+ readonly WEBHOOK_TIMESTAMP_TOO_OLD: "webhook_timestamp_too_old";
454
+ };
455
+ /**
456
+ * Helper to check if error is a ZendFi error
457
+ */
458
+ declare function isZendFiError(error: unknown): error is ZendFiError;
459
+
460
+ export { ApiError, ApproveEscrowRequest, AuthenticationError, ConfigLoader, CreateEscrowRequest, CreateInstallmentPlanRequest, CreateInvoiceRequest, CreatePaymentLinkRequest, CreatePaymentRequest, CreateSubscriptionPlanRequest, CreateSubscriptionRequest, DisputeEscrowRequest, ERROR_CODES, type ErrorInterceptor, Escrow, InstallmentPlan, InterceptorManager, type Interceptors, Invoice, ListPaymentsRequest, NetworkError, PaginatedResponse, Payment, PaymentError, PaymentLink, RateLimitError, RefundEscrowRequest, type RequestConfig, type RequestInterceptor, type ResponseData, type ResponseInterceptor, Subscription, SubscriptionPlan, ValidationError, VerifyWebhookRequest, WebhookError, WebhookPayload, ZendFiClient, ZendFiConfig, ZendFiError, type ZendFiErrorData, type ZendFiErrorType, createZendFiError, isZendFiError, verifyExpressWebhook, verifyNextWebhook, verifyWebhookSignature, zendfi };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,61 @@
1
- import { Z as ZendFiConfig, C as CreatePaymentRequest, P as Payment, L as ListPaymentsRequest, b as PaginatedResponse, c as CreateSubscriptionPlanRequest, S as SubscriptionPlan, d as CreateSubscriptionRequest, e as Subscription, f as CreatePaymentLinkRequest, g as PaymentLink, h as CreateInstallmentPlanRequest, I as InstallmentPlan, i as CreateEscrowRequest, E as Escrow, A as ApproveEscrowRequest, R as RefundEscrowRequest, D as DisputeEscrowRequest, j as CreateInvoiceRequest, k as Invoice, V as VerifyWebhookRequest, l as WebhookPayload } from './webhook-handler-DG-zic8m.js';
2
- export { q as ApiKeyMode, G as AuthenticationError, M as CreateInstallmentPlanResponse, r as Currency, o as Environment, w as EscrowStatus, v as InstallmentPlanStatus, K as InstallmentScheduleItem, Q as InvoiceLineItem, x as InvoiceStatus, N as NetworkError, t as PaymentStatus, s as PaymentToken, J as RateLimitError, O as ReleaseCondition, B as SplitRecipient, y as SplitStatus, u as SubscriptionStatus, H as ValidationError, z as WebhookEvent, n as WebhookEventHandler, W as WebhookHandlerConfig, a as WebhookHandlers, m as WebhookResult, F as ZendFiError, p as processWebhook } from './webhook-handler-DG-zic8m.js';
1
+ import { Z as ZendFiConfig, C as CreatePaymentRequest, P as Payment, L as ListPaymentsRequest, b as PaginatedResponse, c as CreateSubscriptionPlanRequest, S as SubscriptionPlan, d as CreateSubscriptionRequest, e as Subscription, f as CreatePaymentLinkRequest, g as PaymentLink, h as CreateInstallmentPlanRequest, I as InstallmentPlan, i as CreateEscrowRequest, E as Escrow, A as ApproveEscrowRequest, R as RefundEscrowRequest, D as DisputeEscrowRequest, j as CreateInvoiceRequest, k as Invoice, V as VerifyWebhookRequest, l as WebhookPayload } from './webhook-handler-B9ZczHQn.js';
2
+ export { q as ApiKeyMode, G as CreateInstallmentPlanResponse, r as Currency, o as Environment, w as EscrowStatus, v as InstallmentPlanStatus, F as InstallmentScheduleItem, J as InvoiceLineItem, x as InvoiceStatus, t as PaymentStatus, s as PaymentToken, H as ReleaseCondition, B as SplitRecipient, y as SplitStatus, u as SubscriptionStatus, z as WebhookEvent, n as WebhookEventHandler, W as WebhookHandlerConfig, a as WebhookHandlers, m as WebhookResult, p as processWebhook } from './webhook-handler-B9ZczHQn.js';
3
+
4
+ /**
5
+ * Request/Response Interceptor System
6
+ *
7
+ * Allows modifying requests before they're sent and responses after they're received
8
+ */
9
+ interface RequestConfig {
10
+ method: string;
11
+ url: string;
12
+ headers: Record<string, string>;
13
+ body?: any;
14
+ }
15
+ interface ResponseData {
16
+ status: number;
17
+ statusText: string;
18
+ headers: Record<string, string>;
19
+ data: any;
20
+ config: RequestConfig;
21
+ }
22
+ type RequestInterceptor = (config: RequestConfig) => RequestConfig | Promise<RequestConfig>;
23
+ type ResponseInterceptor = (response: ResponseData) => ResponseData | Promise<ResponseData>;
24
+ type ErrorInterceptor = (error: Error) => Error | Promise<Error>;
25
+ /**
26
+ * Interceptor Manager
27
+ */
28
+ declare class InterceptorManager<T extends (...args: any[]) => any> {
29
+ private handlers;
30
+ /**
31
+ * Add an interceptor
32
+ */
33
+ use(handler: T): number;
34
+ /**
35
+ * Remove an interceptor
36
+ */
37
+ eject(id: number): void;
38
+ /**
39
+ * Execute all interceptors in sequence
40
+ */
41
+ execute(initialValue: Parameters<T>[0]): Promise<ReturnType<T>>;
42
+ /**
43
+ * Check if any interceptors are registered
44
+ */
45
+ has(): boolean;
46
+ /**
47
+ * Clear all interceptors
48
+ */
49
+ clear(): void;
50
+ }
51
+ /**
52
+ * Interceptors collection
53
+ */
54
+ interface Interceptors {
55
+ request: InterceptorManager<RequestInterceptor>;
56
+ response: InterceptorManager<ResponseInterceptor>;
57
+ error: InterceptorManager<ErrorInterceptor>;
58
+ }
3
59
 
4
60
  /**
5
61
  * ZendFi SDK Client.
@@ -7,6 +63,7 @@ export { q as ApiKeyMode, G as AuthenticationError, M as CreateInstallmentPlanRe
7
63
  */
8
64
  declare class ZendFiClient {
9
65
  private config;
66
+ readonly interceptors: Interceptors;
10
67
  constructor(options?: Partial<ZendFiConfig>);
11
68
  /**
12
69
  * Create a new payment
@@ -174,7 +231,7 @@ declare class ZendFiClient {
174
231
  */
175
232
  private timingSafeEqual;
176
233
  /**
177
- * Make an HTTP request with retry logic
234
+ * Make an HTTP request with retry logic, interceptors, and debug logging
178
235
  */
179
236
  private request;
180
237
  }
@@ -295,4 +352,109 @@ declare function verifyExpressWebhook(request: any, secret?: string): Promise<We
295
352
  */
296
353
  declare function verifyWebhookSignature(payload: string, signature: string, secret: string): boolean;
297
354
 
298
- export { ApproveEscrowRequest, ConfigLoader, CreateEscrowRequest, CreateInstallmentPlanRequest, CreateInvoiceRequest, CreatePaymentLinkRequest, CreatePaymentRequest, CreateSubscriptionPlanRequest, CreateSubscriptionRequest, DisputeEscrowRequest, Escrow, InstallmentPlan, Invoice, ListPaymentsRequest, PaginatedResponse, Payment, PaymentLink, RefundEscrowRequest, Subscription, SubscriptionPlan, VerifyWebhookRequest, WebhookPayload, ZendFiClient, ZendFiConfig, verifyExpressWebhook, verifyNextWebhook, verifyWebhookSignature, zendfi };
355
+ /**
356
+ * ZendFi SDK Error Classes
357
+ *
358
+ * Custom error types with helpful messages, error codes, and documentation links
359
+ */
360
+ type ZendFiErrorType = 'authentication_error' | 'payment_error' | 'validation_error' | 'network_error' | 'rate_limit_error' | 'api_error' | 'webhook_error' | 'unknown_error';
361
+ interface ZendFiErrorData {
362
+ code: string;
363
+ message: string;
364
+ type: ZendFiErrorType;
365
+ suggestion?: string;
366
+ statusCode?: number;
367
+ response?: unknown;
368
+ }
369
+ /**
370
+ * Base ZendFi Error class with enhanced developer experience
371
+ */
372
+ declare class ZendFiError extends Error {
373
+ readonly code: string;
374
+ readonly type: ZendFiErrorType;
375
+ readonly suggestion?: string;
376
+ readonly docs_url: string;
377
+ readonly statusCode?: number;
378
+ readonly response?: unknown;
379
+ constructor(data: ZendFiErrorData);
380
+ /**
381
+ * Format error for display
382
+ */
383
+ toString(): string;
384
+ /**
385
+ * Convert error to JSON
386
+ */
387
+ toJSON(): Record<string, unknown>;
388
+ }
389
+ /**
390
+ * Authentication errors
391
+ */
392
+ declare class AuthenticationError extends ZendFiError {
393
+ constructor(message: string, code?: string, suggestion?: string);
394
+ }
395
+ /**
396
+ * Payment processing errors
397
+ */
398
+ declare class PaymentError extends ZendFiError {
399
+ constructor(message: string, code?: string, suggestion?: string);
400
+ }
401
+ /**
402
+ * Validation errors
403
+ */
404
+ declare class ValidationError extends ZendFiError {
405
+ constructor(message: string, code?: string, suggestion?: string);
406
+ }
407
+ /**
408
+ * Network/connection errors
409
+ */
410
+ declare class NetworkError extends ZendFiError {
411
+ constructor(message: string, code?: string, suggestion?: string);
412
+ }
413
+ /**
414
+ * Rate limit errors
415
+ */
416
+ declare class RateLimitError extends ZendFiError {
417
+ constructor(message: string, retryAfter?: number);
418
+ }
419
+ /**
420
+ * Generic API errors
421
+ */
422
+ declare class ApiError extends ZendFiError {
423
+ constructor(message: string, code: string, statusCode: number, response?: unknown);
424
+ }
425
+ /**
426
+ * Webhook verification errors
427
+ */
428
+ declare class WebhookError extends ZendFiError {
429
+ constructor(message: string, code?: string, suggestion?: string);
430
+ }
431
+ /**
432
+ * Error factory - creates appropriate error based on response
433
+ */
434
+ declare function createZendFiError(statusCode: number, responseBody: any, message?: string): ZendFiError;
435
+ /**
436
+ * Common error codes and their messages
437
+ */
438
+ declare const ERROR_CODES: {
439
+ readonly INVALID_API_KEY: "invalid_api_key";
440
+ readonly API_KEY_EXPIRED: "api_key_expired";
441
+ readonly API_KEY_REVOKED: "api_key_revoked";
442
+ readonly INSUFFICIENT_BALANCE: "insufficient_balance";
443
+ readonly PAYMENT_DECLINED: "payment_declined";
444
+ readonly PAYMENT_EXPIRED: "payment_expired";
445
+ readonly INVALID_AMOUNT: "invalid_amount";
446
+ readonly INVALID_CURRENCY: "invalid_currency";
447
+ readonly MISSING_REQUIRED_FIELD: "missing_required_field";
448
+ readonly INVALID_PARAMETER: "invalid_parameter";
449
+ readonly NETWORK_ERROR: "network_error";
450
+ readonly TIMEOUT: "timeout";
451
+ readonly RATE_LIMIT_EXCEEDED: "rate_limit_exceeded";
452
+ readonly WEBHOOK_SIGNATURE_INVALID: "webhook_signature_invalid";
453
+ readonly WEBHOOK_TIMESTAMP_TOO_OLD: "webhook_timestamp_too_old";
454
+ };
455
+ /**
456
+ * Helper to check if error is a ZendFi error
457
+ */
458
+ declare function isZendFiError(error: unknown): error is ZendFiError;
459
+
460
+ export { ApiError, ApproveEscrowRequest, AuthenticationError, ConfigLoader, CreateEscrowRequest, CreateInstallmentPlanRequest, CreateInvoiceRequest, CreatePaymentLinkRequest, CreatePaymentRequest, CreateSubscriptionPlanRequest, CreateSubscriptionRequest, DisputeEscrowRequest, ERROR_CODES, type ErrorInterceptor, Escrow, InstallmentPlan, InterceptorManager, type Interceptors, Invoice, ListPaymentsRequest, NetworkError, PaginatedResponse, Payment, PaymentError, PaymentLink, RateLimitError, RefundEscrowRequest, type RequestConfig, type RequestInterceptor, type ResponseData, type ResponseInterceptor, Subscription, SubscriptionPlan, ValidationError, VerifyWebhookRequest, WebhookError, WebhookPayload, ZendFiClient, ZendFiConfig, ZendFiError, type ZendFiErrorData, type ZendFiErrorType, createZendFiError, isZendFiError, verifyExpressWebhook, verifyNextWebhook, verifyWebhookSignature, zendfi };