@zendfi/sdk 0.2.0 → 0.3.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.
@@ -1,4 +1,4 @@
1
- import { W as WebhookHandlerConfig, a as WebhookHandlers } from './webhook-handler-BIze3Qop.mjs';
1
+ import { W as WebhookHandlerConfig, a as WebhookHandlers } from './webhook-handler-DG-zic8m.mjs';
2
2
 
3
3
  /**
4
4
  * Express Webhook Handler
package/dist/express.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { W as WebhookHandlerConfig, a as WebhookHandlers } from './webhook-handler-BIze3Qop.js';
1
+ import { W as WebhookHandlerConfig, a as WebhookHandlers } from './webhook-handler-DG-zic8m.js';
2
2
 
3
3
  /**
4
4
  * Express Webhook Handler
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
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-BIze3Qop.mjs';
2
- export { F as AuthenticationError, K as CreateInstallmentPlanResponse, q as Currency, o as Environment, v as EscrowStatus, u as InstallmentPlanStatus, J as InstallmentScheduleItem, O as InvoiceLineItem, w as InvoiceStatus, N as NetworkError, s as PaymentStatus, r as PaymentToken, H as RateLimitError, M as ReleaseCondition, z as SplitRecipient, x as SplitStatus, t as SubscriptionStatus, G as ValidationError, y as WebhookEvent, n as WebhookEventHandler, W as WebhookHandlerConfig, a as WebhookHandlers, m as WebhookResult, B as ZendFiError, p as processWebhook } from './webhook-handler-BIze3Qop.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-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';
3
3
 
4
4
  /**
5
5
  * ZendFi SDK Client.
@@ -196,6 +196,10 @@ declare class ConfigLoader {
196
196
  * Load configuration from various sources
197
197
  */
198
198
  static load(options?: Partial<ZendFiConfig>): Required<ZendFiConfig>;
199
+ /**
200
+ * Detect mode (test/live) from API key prefix
201
+ */
202
+ private static detectMode;
199
203
  /**
200
204
  * Detect environment based on various signals
201
205
  */
@@ -206,6 +210,8 @@ declare class ConfigLoader {
206
210
  private static loadApiKey;
207
211
  /**
208
212
  * Get base URL for API
213
+ * Note: Both test and live modes use the same API endpoint.
214
+ * The backend routes requests to devnet or mainnet based on API key prefix.
209
215
  */
210
216
  private static getBaseURL;
211
217
  /**
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
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-BIze3Qop.js';
2
- export { F as AuthenticationError, K as CreateInstallmentPlanResponse, q as Currency, o as Environment, v as EscrowStatus, u as InstallmentPlanStatus, J as InstallmentScheduleItem, O as InvoiceLineItem, w as InvoiceStatus, N as NetworkError, s as PaymentStatus, r as PaymentToken, H as RateLimitError, M as ReleaseCondition, z as SplitRecipient, x as SplitStatus, t as SubscriptionStatus, G as ValidationError, y as WebhookEvent, n as WebhookEventHandler, W as WebhookHandlerConfig, a as WebhookHandlers, m as WebhookResult, B as ZendFiError, p as processWebhook } from './webhook-handler-BIze3Qop.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-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';
3
3
 
4
4
  /**
5
5
  * ZendFi SDK Client.
@@ -196,6 +196,10 @@ declare class ConfigLoader {
196
196
  * Load configuration from various sources
197
197
  */
198
198
  static load(options?: Partial<ZendFiConfig>): Required<ZendFiConfig>;
199
+ /**
200
+ * Detect mode (test/live) from API key prefix
201
+ */
202
+ private static detectMode;
199
203
  /**
200
204
  * Detect environment based on various signals
201
205
  */
@@ -206,6 +210,8 @@ declare class ConfigLoader {
206
210
  private static loadApiKey;
207
211
  /**
208
212
  * Get base URL for API
213
+ * Note: Both test and live modes use the same API endpoint.
214
+ * The backend routes requests to devnet or mainnet based on API key prefix.
209
215
  */
210
216
  private static getBaseURL;
211
217
  /**
package/dist/index.js CHANGED
@@ -92,16 +92,30 @@ var ConfigLoader = class {
92
92
  static load(options) {
93
93
  const environment = this.detectEnvironment();
94
94
  const apiKey = this.loadApiKey(options?.apiKey);
95
- const baseURL = this.getBaseURL(environment, options?.baseURL);
95
+ const mode = this.detectMode(apiKey);
96
+ const baseURL = this.getBaseURL(environment, mode, options?.baseURL);
96
97
  return {
97
98
  apiKey,
98
99
  baseURL,
99
100
  environment,
101
+ mode,
100
102
  timeout: options?.timeout ?? 3e4,
101
103
  retries: options?.retries ?? 3,
102
104
  idempotencyEnabled: options?.idempotencyEnabled ?? true
103
105
  };
104
106
  }
107
+ /**
108
+ * Detect mode (test/live) from API key prefix
109
+ */
110
+ static detectMode(apiKey) {
111
+ if (apiKey.startsWith("zfi_test_")) {
112
+ return "test";
113
+ }
114
+ if (apiKey.startsWith("zfi_live_")) {
115
+ return "live";
116
+ }
117
+ return "live";
118
+ }
105
119
  /**
106
120
  * Detect environment based on various signals
107
121
  */
@@ -150,8 +164,10 @@ var ConfigLoader = class {
150
164
  }
151
165
  /**
152
166
  * Get base URL for API
167
+ * Note: Both test and live modes use the same API endpoint.
168
+ * The backend routes requests to devnet or mainnet based on API key prefix.
153
169
  */
154
- static getBaseURL(_environment, explicitURL) {
170
+ static getBaseURL(_environment, _mode, explicitURL) {
155
171
  if (explicitURL) return explicitURL;
156
172
  return process.env.ZENDFI_API_URL || "https://api.zendfi.tech";
157
173
  }
@@ -183,13 +199,17 @@ var ConfigLoader = class {
183
199
  'Invalid API key format. ZendFi API keys should start with "zfi_test_" or "zfi_live_"'
184
200
  );
185
201
  }
186
- if (apiKey.startsWith("zfi_live_")) {
187
- const env = this.detectEnvironment();
188
- if (env === "development") {
189
- console.warn(
190
- "\u26A0\uFE0F Warning: Using a live API key (zfi_live_) in development environment. This will create real transactions. Use a test key (zfi_test_) for development."
191
- );
192
- }
202
+ const mode = this.detectMode(apiKey);
203
+ const env = this.detectEnvironment();
204
+ if (mode === "live" && env === "development") {
205
+ console.warn(
206
+ "\u26A0\uFE0F Warning: Using a live API key (zfi_live_) in development environment. This will create real mainnet transactions. Use a test key (zfi_test_) for devnet testing."
207
+ );
208
+ }
209
+ if (mode === "test" && env === "production") {
210
+ console.warn(
211
+ "\u26A0\uFE0F Warning: Using a test API key (zfi_test_) in production environment. This will create devnet transactions only. Use a live key (zfi_live_) for mainnet."
212
+ );
193
213
  }
194
214
  }
195
215
  };
@@ -230,6 +250,11 @@ var ZendFiClient = class {
230
250
  constructor(options) {
231
251
  this.config = ConfigLoader.load(options);
232
252
  ConfigLoader.validateApiKey(this.config.apiKey);
253
+ if (this.config.environment === "development") {
254
+ console.log(
255
+ `\u2713 ZendFi SDK initialized in ${this.config.mode} mode (${this.config.mode === "test" ? "devnet" : "mainnet"})`
256
+ );
257
+ }
233
258
  }
234
259
  /**
235
260
  * Create a new payment
package/dist/index.mjs CHANGED
@@ -50,16 +50,30 @@ var ConfigLoader = class {
50
50
  static load(options) {
51
51
  const environment = this.detectEnvironment();
52
52
  const apiKey = this.loadApiKey(options?.apiKey);
53
- const baseURL = this.getBaseURL(environment, options?.baseURL);
53
+ const mode = this.detectMode(apiKey);
54
+ const baseURL = this.getBaseURL(environment, mode, options?.baseURL);
54
55
  return {
55
56
  apiKey,
56
57
  baseURL,
57
58
  environment,
59
+ mode,
58
60
  timeout: options?.timeout ?? 3e4,
59
61
  retries: options?.retries ?? 3,
60
62
  idempotencyEnabled: options?.idempotencyEnabled ?? true
61
63
  };
62
64
  }
65
+ /**
66
+ * Detect mode (test/live) from API key prefix
67
+ */
68
+ static detectMode(apiKey) {
69
+ if (apiKey.startsWith("zfi_test_")) {
70
+ return "test";
71
+ }
72
+ if (apiKey.startsWith("zfi_live_")) {
73
+ return "live";
74
+ }
75
+ return "live";
76
+ }
63
77
  /**
64
78
  * Detect environment based on various signals
65
79
  */
@@ -108,8 +122,10 @@ var ConfigLoader = class {
108
122
  }
109
123
  /**
110
124
  * Get base URL for API
125
+ * Note: Both test and live modes use the same API endpoint.
126
+ * The backend routes requests to devnet or mainnet based on API key prefix.
111
127
  */
112
- static getBaseURL(_environment, explicitURL) {
128
+ static getBaseURL(_environment, _mode, explicitURL) {
113
129
  if (explicitURL) return explicitURL;
114
130
  return process.env.ZENDFI_API_URL || "https://api.zendfi.tech";
115
131
  }
@@ -141,13 +157,17 @@ var ConfigLoader = class {
141
157
  'Invalid API key format. ZendFi API keys should start with "zfi_test_" or "zfi_live_"'
142
158
  );
143
159
  }
144
- if (apiKey.startsWith("zfi_live_")) {
145
- const env = this.detectEnvironment();
146
- if (env === "development") {
147
- console.warn(
148
- "\u26A0\uFE0F Warning: Using a live API key (zfi_live_) in development environment. This will create real transactions. Use a test key (zfi_test_) for development."
149
- );
150
- }
160
+ const mode = this.detectMode(apiKey);
161
+ const env = this.detectEnvironment();
162
+ if (mode === "live" && env === "development") {
163
+ console.warn(
164
+ "\u26A0\uFE0F Warning: Using a live API key (zfi_live_) in development environment. This will create real mainnet transactions. Use a test key (zfi_test_) for devnet testing."
165
+ );
166
+ }
167
+ if (mode === "test" && env === "production") {
168
+ console.warn(
169
+ "\u26A0\uFE0F Warning: Using a test API key (zfi_test_) in production environment. This will create devnet transactions only. Use a live key (zfi_live_) for mainnet."
170
+ );
151
171
  }
152
172
  }
153
173
  };
@@ -188,6 +208,11 @@ var ZendFiClient = class {
188
208
  constructor(options) {
189
209
  this.config = ConfigLoader.load(options);
190
210
  ConfigLoader.validateApiKey(this.config.apiKey);
211
+ if (this.config.environment === "development") {
212
+ console.log(
213
+ `\u2713 ZendFi SDK initialized in ${this.config.mode} mode (${this.config.mode === "test" ? "devnet" : "mainnet"})`
214
+ );
215
+ }
191
216
  }
192
217
  /**
193
218
  * Create a new payment
package/dist/nextjs.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { W as WebhookHandlerConfig, a as WebhookHandlers } from './webhook-handler-BIze3Qop.mjs';
1
+ import { W as WebhookHandlerConfig, a as WebhookHandlers } from './webhook-handler-DG-zic8m.mjs';
2
2
 
3
3
  /**
4
4
  * Next.js Webhook Handler for App Router
package/dist/nextjs.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { W as WebhookHandlerConfig, a as WebhookHandlers } from './webhook-handler-BIze3Qop.js';
1
+ import { W as WebhookHandlerConfig, a as WebhookHandlers } from './webhook-handler-DG-zic8m.js';
2
2
 
3
3
  /**
4
4
  * Next.js Webhook Handler for App Router
@@ -3,6 +3,7 @@
3
3
  * Complete type definitions for the ZendFi API
4
4
  */
5
5
  type Environment = 'development' | 'staging' | 'production';
6
+ type ApiKeyMode = 'test' | 'live';
6
7
  type Currency = 'USD' | 'EUR' | 'GBP';
7
8
  type PaymentToken = 'SOL' | 'USDC' | 'USDT';
8
9
  type PaymentStatus = 'pending' | 'confirmed' | 'failed' | 'expired';
@@ -16,6 +17,7 @@ interface ZendFiConfig {
16
17
  apiKey?: string;
17
18
  baseURL?: string;
18
19
  environment?: Environment;
20
+ mode?: ApiKeyMode;
19
21
  timeout?: number;
20
22
  retries?: number;
21
23
  idempotencyEnabled?: boolean;
@@ -385,4 +387,4 @@ interface WebhookResult {
385
387
  }
386
388
  declare function processWebhook(a: any, b?: any, c?: any): Promise<WebhookResult>;
387
389
 
388
- export { type ApproveEscrowRequest as A, ZendFiError as B, type CreatePaymentRequest as C, type DisputeEscrowRequest as D, type Escrow as E, AuthenticationError as F, ValidationError as G, RateLimitError as H, type InstallmentPlan as I, type InstallmentScheduleItem as J, type CreateInstallmentPlanResponse as K, type ListPaymentsRequest as L, type ReleaseCondition as M, NetworkError as N, type InvoiceLineItem as O, 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 Currency as q, type PaymentToken as r, type PaymentStatus as s, type SubscriptionStatus as t, type InstallmentPlanStatus as u, type EscrowStatus as v, type InvoiceStatus as w, type SplitStatus as x, type WebhookEvent as y, type SplitRecipient as z };
390
+ export { type ApproveEscrowRequest as A, type SplitRecipient as B, type CreatePaymentRequest as C, type DisputeEscrowRequest as D, type Escrow as E, ZendFiError as F, AuthenticationError as G, ValidationError as H, type InstallmentPlan as I, RateLimitError as J, type InstallmentScheduleItem as K, type ListPaymentsRequest as L, type CreateInstallmentPlanResponse as M, NetworkError as N, type ReleaseCondition as O, type Payment as P, type InvoiceLineItem as Q, 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 };
@@ -3,6 +3,7 @@
3
3
  * Complete type definitions for the ZendFi API
4
4
  */
5
5
  type Environment = 'development' | 'staging' | 'production';
6
+ type ApiKeyMode = 'test' | 'live';
6
7
  type Currency = 'USD' | 'EUR' | 'GBP';
7
8
  type PaymentToken = 'SOL' | 'USDC' | 'USDT';
8
9
  type PaymentStatus = 'pending' | 'confirmed' | 'failed' | 'expired';
@@ -16,6 +17,7 @@ interface ZendFiConfig {
16
17
  apiKey?: string;
17
18
  baseURL?: string;
18
19
  environment?: Environment;
20
+ mode?: ApiKeyMode;
19
21
  timeout?: number;
20
22
  retries?: number;
21
23
  idempotencyEnabled?: boolean;
@@ -385,4 +387,4 @@ interface WebhookResult {
385
387
  }
386
388
  declare function processWebhook(a: any, b?: any, c?: any): Promise<WebhookResult>;
387
389
 
388
- export { type ApproveEscrowRequest as A, ZendFiError as B, type CreatePaymentRequest as C, type DisputeEscrowRequest as D, type Escrow as E, AuthenticationError as F, ValidationError as G, RateLimitError as H, type InstallmentPlan as I, type InstallmentScheduleItem as J, type CreateInstallmentPlanResponse as K, type ListPaymentsRequest as L, type ReleaseCondition as M, NetworkError as N, type InvoiceLineItem as O, 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 Currency as q, type PaymentToken as r, type PaymentStatus as s, type SubscriptionStatus as t, type InstallmentPlanStatus as u, type EscrowStatus as v, type InvoiceStatus as w, type SplitStatus as x, type WebhookEvent as y, type SplitRecipient as z };
390
+ export { type ApproveEscrowRequest as A, type SplitRecipient as B, type CreatePaymentRequest as C, type DisputeEscrowRequest as D, type Escrow as E, ZendFiError as F, AuthenticationError as G, ValidationError as H, type InstallmentPlan as I, RateLimitError as J, type InstallmentScheduleItem as K, type ListPaymentsRequest as L, type CreateInstallmentPlanResponse as M, NetworkError as N, type ReleaseCondition as O, type Payment as P, type InvoiceLineItem as Q, 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zendfi/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Zero-config TypeScript SDK for ZendFi crypto payments",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",