@solvapay/server 1.0.0-preview.1 → 1.0.0-preview.3

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 CHANGED
@@ -160,11 +160,7 @@ type Plan = components['schemas']['Plan'];
160
160
 
161
161
  ## Testing
162
162
 
163
- > **📖 For detailed integration test setup**, see:
164
- > - [`packages/test-utils/INTEGRATION_TESTING.md`](../test-utils/INTEGRATION_TESTING.md) - Complete setup guide
165
- > - [`SDK_INTEGRATION_TESTS_IMPLEMENTATION.md`](../../SDK_INTEGRATION_TESTS_IMPLEMENTATION.md) - Implementation details
166
-
167
- This package includes comprehensive tests for SDK functionality.
163
+ This package includes comprehensive tests for SDK functionality, including unit tests and integration tests with real backend.
168
164
 
169
165
  ### Running Tests
170
166
 
@@ -198,7 +194,7 @@ Unit tests (`__tests__/paywall.test.ts`) use a mock API client and test:
198
194
 
199
195
  ### Integration Tests
200
196
 
201
- Integration tests (`__tests__/paywall.integration.with-fetched-defaults.test.ts`) connect to a real SolvaPay backend and test:
197
+ Integration tests (`__tests__/backend.integration.test.ts`) connect to a real SolvaPay backend and test:
202
198
  - SDK API methods with real responses
203
199
  - Actual limit enforcement
204
200
  - Real usage tracking
@@ -213,17 +209,106 @@ Set environment variables before running tests:
213
209
  # Option 1: Export in your shell (persists in session)
214
210
  export USE_REAL_BACKEND=true
215
211
  export SOLVAPAY_SECRET_KEY=your_secret_key_here
216
- export SOLVAPAY_API_BASE_URL=https://api-dev.solvapay.com # optional
212
+ export SOLVAPAY_API_BASE_URL=http://localhost:3001 # optional, defaults to dev API
217
213
  pnpm test:integration
218
214
 
219
215
  # Option 2: Inline with command (single use)
220
216
  USE_REAL_BACKEND=true SOLVAPAY_SECRET_KEY=your_key pnpm test:integration
221
217
  ```
222
218
 
223
- **Note:** This follows the industry standard used by major SDKs (Stripe, AWS, Twilio). No `.env` file is required.
224
-
225
219
  **Note:** Integration tests are automatically skipped if `USE_REAL_BACKEND` or `SOLVAPAY_SECRET_KEY` are not set. This allows CI/CD to run unit tests without backend credentials.
226
220
 
221
+ ### Payment Integration Tests (Stripe)
222
+
223
+ Payment tests (`__tests__/payment-stripe.integration.test.ts`) verify the complete payment flow with Stripe:
224
+ - Creating payment intents
225
+ - Confirming payments with test cards
226
+ - Webhook processing (optional)
227
+ - Credit management and usage tracking
228
+
229
+ **Required Setup:**
230
+
231
+ ```bash
232
+ export USE_REAL_BACKEND=true
233
+ export SOLVAPAY_SECRET_KEY=your_secret_key_here
234
+ export STRIPE_TEST_SECRET_KEY=sk_test_your_stripe_key
235
+ export SOLVAPAY_API_BASE_URL=http://localhost:3001
236
+ ```
237
+
238
+ **Optional - Webhook Tests:**
239
+
240
+ The E2E webhook test is skipped by default because it requires Stripe webhooks to be forwarded to your local backend. To enable webhook testing:
241
+
242
+ 1. **Install Stripe CLI:**
243
+ ```bash
244
+ # macOS
245
+ brew install stripe/stripe-cli/stripe
246
+
247
+ # Linux / Windows - see https://stripe.com/docs/stripe-cli
248
+ ```
249
+
250
+ 2. **Login to Stripe:**
251
+ ```bash
252
+ stripe login
253
+ ```
254
+
255
+ 3. **Forward webhooks to your local backend:**
256
+ ```bash
257
+ # Terminal 1: Start your backend
258
+ cd path/to/solvapay-backend
259
+ pnpm dev
260
+
261
+ # Terminal 2: Forward Stripe webhooks
262
+ stripe listen --forward-to localhost:3001/webhooks/stripe
263
+ ```
264
+
265
+ 4. **Run payment tests with webhook testing enabled:**
266
+ ```bash
267
+ ENABLE_WEBHOOK_TESTS=true pnpm test:integration:payment
268
+ ```
269
+
270
+ The Stripe CLI will forward webhook events from Stripe to your local backend, allowing the E2E test to verify the complete payment flow including webhook processing.
271
+
272
+ ### Debugging and Logging
273
+
274
+ The SDK and tests provide environment variable controls for logging:
275
+
276
+ **SDK Debug Logging**
277
+
278
+ Enable detailed logging for SDK operations (API calls, responses, errors):
279
+
280
+ ```bash
281
+ # Enable SDK debug logging
282
+ export SOLVAPAY_DEBUG=true
283
+
284
+ # Run tests or your application
285
+ pnpm test:integration
286
+ ```
287
+
288
+ **Test Verbose Logging**
289
+
290
+ Enable verbose logging for integration test progress and debug information:
291
+
292
+ ```bash
293
+ # Enable verbose test logging (test setup, progress, debug info)
294
+ export VERBOSE_TEST_LOGS=true
295
+
296
+ # Run integration tests
297
+ pnpm test:integration
298
+ ```
299
+
300
+ **Combined Usage:**
301
+
302
+ ```bash
303
+ # Enable all logging for maximum debugging
304
+ SOLVAPAY_DEBUG=true VERBOSE_TEST_LOGS=true pnpm test:integration
305
+
306
+ # Quiet mode (default) - minimal output
307
+ pnpm test:integration
308
+ ```
309
+
310
+ By default, both are **disabled** to keep test output clean and readable. Enable them when troubleshooting test failures or debugging SDK behavior.
311
+
227
312
  ### CI/CD
228
313
 
229
314
  ```yaml
package/dist/edge.js CHANGED
@@ -14,15 +14,21 @@ function createSolvaPayClient(opts) {
14
14
  "Content-Type": "application/json",
15
15
  "Authorization": `Bearer ${opts.apiKey}`
16
16
  };
17
- console.log(`\u{1F50C} SolvaPay API Client initialized`);
18
- console.log(` Backend URL: ${base}`);
19
- console.log(` API Key: ${opts.apiKey.substring(0, 10)}...`);
17
+ const debug = process.env.SOLVAPAY_DEBUG === "true";
18
+ const log = (...args) => {
19
+ if (debug) {
20
+ console.log(...args);
21
+ }
22
+ };
23
+ log(`\u{1F50C} SolvaPay API Client initialized`);
24
+ log(` Backend URL: ${base}`);
25
+ log(` API Key: ${opts.apiKey.substring(0, 10)}...`);
20
26
  return {
21
27
  // POST: /v1/sdk/limits
22
28
  async checkLimits(params) {
23
29
  const url = `${base}/v1/sdk/limits`;
24
- console.log(`\u{1F4E1} API Request: POST ${url}`);
25
- console.log(` Params:`, JSON.stringify(params, null, 2));
30
+ log(`\u{1F4E1} API Request: POST ${url}`);
31
+ log(` Params:`, JSON.stringify(params, null, 2));
26
32
  const res = await fetch(url, {
27
33
  method: "POST",
28
34
  headers,
@@ -30,24 +36,24 @@ function createSolvaPayClient(opts) {
30
36
  });
31
37
  if (!res.ok) {
32
38
  const error = await res.text();
33
- console.error(`\u274C API Error: ${res.status} - ${error}`);
39
+ log(`\u274C API Error: ${res.status} - ${error}`);
34
40
  throw new SolvaPayError(`Check limits failed (${res.status}): ${error}`);
35
41
  }
36
42
  const result = await res.json();
37
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
38
- console.log(`\u{1F50D} DEBUG - checkLimits breakdown:`);
39
- console.log(` - withinLimits: ${result.withinLimits}`);
40
- console.log(` - remaining: ${result.remaining}`);
41
- console.log(` - plan: ${result.plan || "N/A"}`);
42
- console.log(` - checkoutUrl: ${result.checkoutUrl || "N/A"}`);
43
- console.log(` - Full response keys:`, Object.keys(result));
43
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
44
+ log(`\u{1F50D} DEBUG - checkLimits breakdown:`);
45
+ log(` - withinLimits: ${result.withinLimits}`);
46
+ log(` - remaining: ${result.remaining}`);
47
+ log(` - plan: ${result.plan || "N/A"}`);
48
+ log(` - checkoutUrl: ${result.checkoutUrl || "N/A"}`);
49
+ log(` - Full response keys:`, Object.keys(result));
44
50
  return result;
45
51
  },
46
52
  // POST: /v1/sdk/usages
47
53
  async trackUsage(params) {
48
54
  const url = `${base}/v1/sdk/usages`;
49
- console.log(`\u{1F4E1} API Request: POST ${url}`);
50
- console.log(` Params:`, JSON.stringify(params, null, 2));
55
+ log(`\u{1F4E1} API Request: POST ${url}`);
56
+ log(` Params:`, JSON.stringify(params, null, 2));
51
57
  const res = await fetch(url, {
52
58
  method: "POST",
53
59
  headers,
@@ -55,16 +61,16 @@ function createSolvaPayClient(opts) {
55
61
  });
56
62
  if (!res.ok) {
57
63
  const error = await res.text();
58
- console.error(`\u274C API Error: ${res.status} - ${error}`);
64
+ log(`\u274C API Error: ${res.status} - ${error}`);
59
65
  throw new SolvaPayError(`Track usage failed (${res.status}): ${error}`);
60
66
  }
61
- console.log(`\u2705 Usage tracked successfully`);
67
+ log(`\u2705 Usage tracked successfully`);
62
68
  },
63
69
  // POST: /v1/sdk/customers
64
70
  async createCustomer(params) {
65
71
  const url = `${base}/v1/sdk/customers`;
66
- console.log(`\u{1F4E1} API Request: POST ${url}`);
67
- console.log(` Params:`, JSON.stringify(params, null, 2));
72
+ log(`\u{1F4E1} API Request: POST ${url}`);
73
+ log(` Params:`, JSON.stringify(params, null, 2));
68
74
  const res = await fetch(url, {
69
75
  method: "POST",
70
76
  headers,
@@ -72,51 +78,51 @@ function createSolvaPayClient(opts) {
72
78
  });
73
79
  if (!res.ok) {
74
80
  const error = await res.text();
75
- console.error(`\u274C API Error: ${res.status} - ${error}`);
81
+ log(`\u274C API Error: ${res.status} - ${error}`);
76
82
  throw new SolvaPayError(`Create customer failed (${res.status}): ${error}`);
77
83
  }
78
84
  const result = await res.json();
79
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
80
- console.log(`\u{1F50D} DEBUG - createCustomer response:`);
81
- console.log(` - reference/customerRef: ${result.reference || result.customerRef}`);
82
- console.log(` - Has plan info: ${result.plan ? "YES" : "NO"}`);
83
- console.log(` - Has subscription info: ${result.subscription ? "YES" : "NO"}`);
84
- console.log(` - Full response keys:`, Object.keys(result));
85
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
86
+ log(`\u{1F50D} DEBUG - createCustomer response:`);
87
+ log(` - reference/customerRef: ${result.reference || result.customerRef}`);
88
+ log(` - Has plan info: ${result.plan ? "YES" : "NO"}`);
89
+ log(` - Has subscription info: ${result.subscription ? "YES" : "NO"}`);
90
+ log(` - Full response keys:`, Object.keys(result));
85
91
  return result;
86
92
  },
87
93
  // GET: /v1/sdk/customers/{reference}
88
94
  async getCustomer(params) {
89
95
  const url = `${base}/v1/sdk/customers/${params.customerRef}`;
90
- console.log(`\u{1F4E1} API Request: GET ${url}`);
96
+ log(`\u{1F4E1} API Request: GET ${url}`);
91
97
  const res = await fetch(url, {
92
98
  method: "GET",
93
99
  headers
94
100
  });
95
101
  if (!res.ok) {
96
102
  const error = await res.text();
97
- console.error(`\u274C API Error: ${res.status} - ${error}`);
103
+ log(`\u274C API Error: ${res.status} - ${error}`);
98
104
  throw new SolvaPayError(`Get customer failed (${res.status}): ${error}`);
99
105
  }
100
106
  const result = await res.json();
101
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
107
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
102
108
  return result;
103
109
  },
104
110
  // Management methods (primarily for integration tests)
105
111
  // GET: /v1/sdk/agents
106
112
  async listAgents() {
107
113
  const url = `${base}/v1/sdk/agents`;
108
- console.log(`\u{1F4E1} API Request: GET ${url}`);
114
+ log(`\u{1F4E1} API Request: GET ${url}`);
109
115
  const res = await fetch(url, {
110
116
  method: "GET",
111
117
  headers
112
118
  });
113
119
  if (!res.ok) {
114
120
  const error = await res.text();
115
- console.error(`\u274C API Error: ${res.status} - ${error}`);
121
+ log(`\u274C API Error: ${res.status} - ${error}`);
116
122
  throw new SolvaPayError(`List agents failed (${res.status}): ${error}`);
117
123
  }
118
124
  const result = await res.json();
119
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
125
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
120
126
  const agents = Array.isArray(result) ? result : result.agents || [];
121
127
  return agents.map((agent) => ({
122
128
  ...agent,
@@ -126,8 +132,8 @@ function createSolvaPayClient(opts) {
126
132
  // POST: /v1/sdk/agents
127
133
  async createAgent(params) {
128
134
  const url = `${base}/v1/sdk/agents`;
129
- console.log(`\u{1F4E1} API Request: POST ${url}`);
130
- console.log(` Params:`, JSON.stringify(params, null, 2));
135
+ log(`\u{1F4E1} API Request: POST ${url}`);
136
+ log(` Params:`, JSON.stringify(params, null, 2));
131
137
  const res = await fetch(url, {
132
138
  method: "POST",
133
139
  headers,
@@ -135,43 +141,43 @@ function createSolvaPayClient(opts) {
135
141
  });
136
142
  if (!res.ok) {
137
143
  const error = await res.text();
138
- console.error(`\u274C API Error: ${res.status} - ${error}`);
144
+ log(`\u274C API Error: ${res.status} - ${error}`);
139
145
  throw new SolvaPayError(`Create agent failed (${res.status}): ${error}`);
140
146
  }
141
147
  const result = await res.json();
142
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
148
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
143
149
  return result;
144
150
  },
145
151
  // DELETE: /v1/sdk/agents/{agentRef}
146
152
  async deleteAgent(agentRef) {
147
153
  const url = `${base}/v1/sdk/agents/${agentRef}`;
148
- console.log(`\u{1F4E1} API Request: DELETE ${url}`);
154
+ log(`\u{1F4E1} API Request: DELETE ${url}`);
149
155
  const res = await fetch(url, {
150
156
  method: "DELETE",
151
157
  headers
152
158
  });
153
159
  if (!res.ok && res.status !== 404) {
154
160
  const error = await res.text();
155
- console.error(`\u274C API Error: ${res.status} - ${error}`);
161
+ log(`\u274C API Error: ${res.status} - ${error}`);
156
162
  throw new SolvaPayError(`Delete agent failed (${res.status}): ${error}`);
157
163
  }
158
- console.log(`\u2705 Agent deleted successfully`);
164
+ log(`\u2705 Agent deleted successfully`);
159
165
  },
160
166
  // GET: /v1/sdk/agents/{agentRef}/plans
161
167
  async listPlans(agentRef) {
162
168
  const url = `${base}/v1/sdk/agents/${agentRef}/plans`;
163
- console.log(`\u{1F4E1} API Request: GET ${url}`);
169
+ log(`\u{1F4E1} API Request: GET ${url}`);
164
170
  const res = await fetch(url, {
165
171
  method: "GET",
166
172
  headers
167
173
  });
168
174
  if (!res.ok) {
169
175
  const error = await res.text();
170
- console.error(`\u274C API Error: ${res.status} - ${error}`);
176
+ log(`\u274C API Error: ${res.status} - ${error}`);
171
177
  throw new SolvaPayError(`List plans failed (${res.status}): ${error}`);
172
178
  }
173
179
  const result = await res.json();
174
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
180
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
175
181
  const plans = Array.isArray(result) ? result : result.plans || [];
176
182
  return plans.map((plan) => ({
177
183
  ...plan,
@@ -181,8 +187,8 @@ function createSolvaPayClient(opts) {
181
187
  // POST: /v1/sdk/agents/{agentRef}/plans
182
188
  async createPlan(params) {
183
189
  const url = `${base}/v1/sdk/agents/${params.agentRef}/plans`;
184
- console.log(`\u{1F4E1} API Request: POST ${url}`);
185
- console.log(` Params:`, JSON.stringify(params, null, 2));
190
+ log(`\u{1F4E1} API Request: POST ${url}`);
191
+ log(` Params:`, JSON.stringify(params, null, 2));
186
192
  const res = await fetch(url, {
187
193
  method: "POST",
188
194
  headers,
@@ -190,37 +196,37 @@ function createSolvaPayClient(opts) {
190
196
  });
191
197
  if (!res.ok) {
192
198
  const error = await res.text();
193
- console.error(`\u274C API Error: ${res.status} - ${error}`);
199
+ log(`\u274C API Error: ${res.status} - ${error}`);
194
200
  throw new SolvaPayError(`Create plan failed (${res.status}): ${error}`);
195
201
  }
196
202
  const result = await res.json();
197
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
203
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
198
204
  return result;
199
205
  },
200
206
  // DELETE: /v1/sdk/agents/{agentRef}/plans/{planRef}
201
207
  async deletePlan(agentRef, planRef) {
202
208
  const url = `${base}/v1/sdk/agents/${agentRef}/plans/${planRef}`;
203
- console.log(`\u{1F4E1} API Request: DELETE ${url}`);
209
+ log(`\u{1F4E1} API Request: DELETE ${url}`);
204
210
  const res = await fetch(url, {
205
211
  method: "DELETE",
206
212
  headers
207
213
  });
208
214
  if (!res.ok && res.status !== 404) {
209
215
  const error = await res.text();
210
- console.error(`\u274C API Error: ${res.status} - ${error}`);
216
+ log(`\u274C API Error: ${res.status} - ${error}`);
211
217
  throw new SolvaPayError(`Delete plan failed (${res.status}): ${error}`);
212
218
  }
213
- console.log(`\u2705 Plan deleted successfully`);
219
+ log(`\u2705 Plan deleted successfully`);
214
220
  },
215
221
  // POST: /payment-intents
216
222
  async createPaymentIntent(params) {
217
223
  const idempotencyKey = params.idempotencyKey || `payment-${params.planRef}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
218
224
  const url = `${base}/v1/sdk/payment-intents`;
219
- console.log(`\u{1F4E1} API Request: POST ${url}`);
220
- console.log(` Agent Ref: ${params.agentRef}`);
221
- console.log(` Plan Ref: ${params.planRef}`);
222
- console.log(` Customer Ref: ${params.customerRef}`);
223
- console.log(` Idempotency Key: ${idempotencyKey}`);
225
+ log(`\u{1F4E1} API Request: POST ${url}`);
226
+ log(` Agent Ref: ${params.agentRef}`);
227
+ log(` Plan Ref: ${params.planRef}`);
228
+ log(` Customer Ref: ${params.customerRef}`);
229
+ log(` Idempotency Key: ${idempotencyKey}`);
224
230
  const res = await fetch(url, {
225
231
  method: "POST",
226
232
  headers: {
@@ -235,11 +241,11 @@ function createSolvaPayClient(opts) {
235
241
  });
236
242
  if (!res.ok) {
237
243
  const error = await res.text();
238
- console.error(`\u274C API Error: ${res.status} - ${error}`);
244
+ log(`\u274C API Error: ${res.status} - ${error}`);
239
245
  throw new SolvaPayError(`Create payment intent failed (${res.status}): ${error}`);
240
246
  }
241
247
  const result = await res.json();
242
- console.log(`\u2705 Payment intent created:`, {
248
+ log(`\u2705 Payment intent created:`, {
243
249
  id: result.id,
244
250
  hasClientSecret: !!result.clientSecret,
245
251
  hasPublishableKey: !!result.publishableKey,
@@ -308,7 +314,7 @@ var PaywallError = class extends Error {
308
314
  var SolvaPayPaywall = class {
309
315
  constructor(apiClient, options = {}) {
310
316
  this.apiClient = apiClient;
311
- this.debug = options.debug ?? process.env.SOLVAPAY_DEBUG !== "false";
317
+ this.debug = options.debug ?? process.env.SOLVAPAY_DEBUG === "true";
312
318
  }
313
319
  customerCreationAttempts = /* @__PURE__ */ new Set();
314
320
  customerRefMapping = /* @__PURE__ */ new Map();
package/dist/index.cjs CHANGED
@@ -4273,15 +4273,21 @@ function createSolvaPayClient(opts) {
4273
4273
  "Content-Type": "application/json",
4274
4274
  "Authorization": `Bearer ${opts.apiKey}`
4275
4275
  };
4276
- console.log(`\u{1F50C} SolvaPay API Client initialized`);
4277
- console.log(` Backend URL: ${base}`);
4278
- console.log(` API Key: ${opts.apiKey.substring(0, 10)}...`);
4276
+ const debug = process.env.SOLVAPAY_DEBUG === "true";
4277
+ const log = (...args) => {
4278
+ if (debug) {
4279
+ console.log(...args);
4280
+ }
4281
+ };
4282
+ log(`\u{1F50C} SolvaPay API Client initialized`);
4283
+ log(` Backend URL: ${base}`);
4284
+ log(` API Key: ${opts.apiKey.substring(0, 10)}...`);
4279
4285
  return {
4280
4286
  // POST: /v1/sdk/limits
4281
4287
  async checkLimits(params) {
4282
4288
  const url = `${base}/v1/sdk/limits`;
4283
- console.log(`\u{1F4E1} API Request: POST ${url}`);
4284
- console.log(` Params:`, JSON.stringify(params, null, 2));
4289
+ log(`\u{1F4E1} API Request: POST ${url}`);
4290
+ log(` Params:`, JSON.stringify(params, null, 2));
4285
4291
  const res = await fetch(url, {
4286
4292
  method: "POST",
4287
4293
  headers,
@@ -4289,24 +4295,24 @@ function createSolvaPayClient(opts) {
4289
4295
  });
4290
4296
  if (!res.ok) {
4291
4297
  const error = await res.text();
4292
- console.error(`\u274C API Error: ${res.status} - ${error}`);
4298
+ log(`\u274C API Error: ${res.status} - ${error}`);
4293
4299
  throw new import_core.SolvaPayError(`Check limits failed (${res.status}): ${error}`);
4294
4300
  }
4295
4301
  const result = await res.json();
4296
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
4297
- console.log(`\u{1F50D} DEBUG - checkLimits breakdown:`);
4298
- console.log(` - withinLimits: ${result.withinLimits}`);
4299
- console.log(` - remaining: ${result.remaining}`);
4300
- console.log(` - plan: ${result.plan || "N/A"}`);
4301
- console.log(` - checkoutUrl: ${result.checkoutUrl || "N/A"}`);
4302
- console.log(` - Full response keys:`, Object.keys(result));
4302
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
4303
+ log(`\u{1F50D} DEBUG - checkLimits breakdown:`);
4304
+ log(` - withinLimits: ${result.withinLimits}`);
4305
+ log(` - remaining: ${result.remaining}`);
4306
+ log(` - plan: ${result.plan || "N/A"}`);
4307
+ log(` - checkoutUrl: ${result.checkoutUrl || "N/A"}`);
4308
+ log(` - Full response keys:`, Object.keys(result));
4303
4309
  return result;
4304
4310
  },
4305
4311
  // POST: /v1/sdk/usages
4306
4312
  async trackUsage(params) {
4307
4313
  const url = `${base}/v1/sdk/usages`;
4308
- console.log(`\u{1F4E1} API Request: POST ${url}`);
4309
- console.log(` Params:`, JSON.stringify(params, null, 2));
4314
+ log(`\u{1F4E1} API Request: POST ${url}`);
4315
+ log(` Params:`, JSON.stringify(params, null, 2));
4310
4316
  const res = await fetch(url, {
4311
4317
  method: "POST",
4312
4318
  headers,
@@ -4314,16 +4320,16 @@ function createSolvaPayClient(opts) {
4314
4320
  });
4315
4321
  if (!res.ok) {
4316
4322
  const error = await res.text();
4317
- console.error(`\u274C API Error: ${res.status} - ${error}`);
4323
+ log(`\u274C API Error: ${res.status} - ${error}`);
4318
4324
  throw new import_core.SolvaPayError(`Track usage failed (${res.status}): ${error}`);
4319
4325
  }
4320
- console.log(`\u2705 Usage tracked successfully`);
4326
+ log(`\u2705 Usage tracked successfully`);
4321
4327
  },
4322
4328
  // POST: /v1/sdk/customers
4323
4329
  async createCustomer(params) {
4324
4330
  const url = `${base}/v1/sdk/customers`;
4325
- console.log(`\u{1F4E1} API Request: POST ${url}`);
4326
- console.log(` Params:`, JSON.stringify(params, null, 2));
4331
+ log(`\u{1F4E1} API Request: POST ${url}`);
4332
+ log(` Params:`, JSON.stringify(params, null, 2));
4327
4333
  const res = await fetch(url, {
4328
4334
  method: "POST",
4329
4335
  headers,
@@ -4331,51 +4337,51 @@ function createSolvaPayClient(opts) {
4331
4337
  });
4332
4338
  if (!res.ok) {
4333
4339
  const error = await res.text();
4334
- console.error(`\u274C API Error: ${res.status} - ${error}`);
4340
+ log(`\u274C API Error: ${res.status} - ${error}`);
4335
4341
  throw new import_core.SolvaPayError(`Create customer failed (${res.status}): ${error}`);
4336
4342
  }
4337
4343
  const result = await res.json();
4338
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
4339
- console.log(`\u{1F50D} DEBUG - createCustomer response:`);
4340
- console.log(` - reference/customerRef: ${result.reference || result.customerRef}`);
4341
- console.log(` - Has plan info: ${result.plan ? "YES" : "NO"}`);
4342
- console.log(` - Has subscription info: ${result.subscription ? "YES" : "NO"}`);
4343
- console.log(` - Full response keys:`, Object.keys(result));
4344
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
4345
+ log(`\u{1F50D} DEBUG - createCustomer response:`);
4346
+ log(` - reference/customerRef: ${result.reference || result.customerRef}`);
4347
+ log(` - Has plan info: ${result.plan ? "YES" : "NO"}`);
4348
+ log(` - Has subscription info: ${result.subscription ? "YES" : "NO"}`);
4349
+ log(` - Full response keys:`, Object.keys(result));
4344
4350
  return result;
4345
4351
  },
4346
4352
  // GET: /v1/sdk/customers/{reference}
4347
4353
  async getCustomer(params) {
4348
4354
  const url = `${base}/v1/sdk/customers/${params.customerRef}`;
4349
- console.log(`\u{1F4E1} API Request: GET ${url}`);
4355
+ log(`\u{1F4E1} API Request: GET ${url}`);
4350
4356
  const res = await fetch(url, {
4351
4357
  method: "GET",
4352
4358
  headers
4353
4359
  });
4354
4360
  if (!res.ok) {
4355
4361
  const error = await res.text();
4356
- console.error(`\u274C API Error: ${res.status} - ${error}`);
4362
+ log(`\u274C API Error: ${res.status} - ${error}`);
4357
4363
  throw new import_core.SolvaPayError(`Get customer failed (${res.status}): ${error}`);
4358
4364
  }
4359
4365
  const result = await res.json();
4360
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
4366
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
4361
4367
  return result;
4362
4368
  },
4363
4369
  // Management methods (primarily for integration tests)
4364
4370
  // GET: /v1/sdk/agents
4365
4371
  async listAgents() {
4366
4372
  const url = `${base}/v1/sdk/agents`;
4367
- console.log(`\u{1F4E1} API Request: GET ${url}`);
4373
+ log(`\u{1F4E1} API Request: GET ${url}`);
4368
4374
  const res = await fetch(url, {
4369
4375
  method: "GET",
4370
4376
  headers
4371
4377
  });
4372
4378
  if (!res.ok) {
4373
4379
  const error = await res.text();
4374
- console.error(`\u274C API Error: ${res.status} - ${error}`);
4380
+ log(`\u274C API Error: ${res.status} - ${error}`);
4375
4381
  throw new import_core.SolvaPayError(`List agents failed (${res.status}): ${error}`);
4376
4382
  }
4377
4383
  const result = await res.json();
4378
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
4384
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
4379
4385
  const agents = Array.isArray(result) ? result : result.agents || [];
4380
4386
  return agents.map((agent) => ({
4381
4387
  ...agent,
@@ -4385,8 +4391,8 @@ function createSolvaPayClient(opts) {
4385
4391
  // POST: /v1/sdk/agents
4386
4392
  async createAgent(params) {
4387
4393
  const url = `${base}/v1/sdk/agents`;
4388
- console.log(`\u{1F4E1} API Request: POST ${url}`);
4389
- console.log(` Params:`, JSON.stringify(params, null, 2));
4394
+ log(`\u{1F4E1} API Request: POST ${url}`);
4395
+ log(` Params:`, JSON.stringify(params, null, 2));
4390
4396
  const res = await fetch(url, {
4391
4397
  method: "POST",
4392
4398
  headers,
@@ -4394,43 +4400,43 @@ function createSolvaPayClient(opts) {
4394
4400
  });
4395
4401
  if (!res.ok) {
4396
4402
  const error = await res.text();
4397
- console.error(`\u274C API Error: ${res.status} - ${error}`);
4403
+ log(`\u274C API Error: ${res.status} - ${error}`);
4398
4404
  throw new import_core.SolvaPayError(`Create agent failed (${res.status}): ${error}`);
4399
4405
  }
4400
4406
  const result = await res.json();
4401
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
4407
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
4402
4408
  return result;
4403
4409
  },
4404
4410
  // DELETE: /v1/sdk/agents/{agentRef}
4405
4411
  async deleteAgent(agentRef) {
4406
4412
  const url = `${base}/v1/sdk/agents/${agentRef}`;
4407
- console.log(`\u{1F4E1} API Request: DELETE ${url}`);
4413
+ log(`\u{1F4E1} API Request: DELETE ${url}`);
4408
4414
  const res = await fetch(url, {
4409
4415
  method: "DELETE",
4410
4416
  headers
4411
4417
  });
4412
4418
  if (!res.ok && res.status !== 404) {
4413
4419
  const error = await res.text();
4414
- console.error(`\u274C API Error: ${res.status} - ${error}`);
4420
+ log(`\u274C API Error: ${res.status} - ${error}`);
4415
4421
  throw new import_core.SolvaPayError(`Delete agent failed (${res.status}): ${error}`);
4416
4422
  }
4417
- console.log(`\u2705 Agent deleted successfully`);
4423
+ log(`\u2705 Agent deleted successfully`);
4418
4424
  },
4419
4425
  // GET: /v1/sdk/agents/{agentRef}/plans
4420
4426
  async listPlans(agentRef) {
4421
4427
  const url = `${base}/v1/sdk/agents/${agentRef}/plans`;
4422
- console.log(`\u{1F4E1} API Request: GET ${url}`);
4428
+ log(`\u{1F4E1} API Request: GET ${url}`);
4423
4429
  const res = await fetch(url, {
4424
4430
  method: "GET",
4425
4431
  headers
4426
4432
  });
4427
4433
  if (!res.ok) {
4428
4434
  const error = await res.text();
4429
- console.error(`\u274C API Error: ${res.status} - ${error}`);
4435
+ log(`\u274C API Error: ${res.status} - ${error}`);
4430
4436
  throw new import_core.SolvaPayError(`List plans failed (${res.status}): ${error}`);
4431
4437
  }
4432
4438
  const result = await res.json();
4433
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
4439
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
4434
4440
  const plans = Array.isArray(result) ? result : result.plans || [];
4435
4441
  return plans.map((plan) => ({
4436
4442
  ...plan,
@@ -4440,8 +4446,8 @@ function createSolvaPayClient(opts) {
4440
4446
  // POST: /v1/sdk/agents/{agentRef}/plans
4441
4447
  async createPlan(params) {
4442
4448
  const url = `${base}/v1/sdk/agents/${params.agentRef}/plans`;
4443
- console.log(`\u{1F4E1} API Request: POST ${url}`);
4444
- console.log(` Params:`, JSON.stringify(params, null, 2));
4449
+ log(`\u{1F4E1} API Request: POST ${url}`);
4450
+ log(` Params:`, JSON.stringify(params, null, 2));
4445
4451
  const res = await fetch(url, {
4446
4452
  method: "POST",
4447
4453
  headers,
@@ -4449,37 +4455,37 @@ function createSolvaPayClient(opts) {
4449
4455
  });
4450
4456
  if (!res.ok) {
4451
4457
  const error = await res.text();
4452
- console.error(`\u274C API Error: ${res.status} - ${error}`);
4458
+ log(`\u274C API Error: ${res.status} - ${error}`);
4453
4459
  throw new import_core.SolvaPayError(`Create plan failed (${res.status}): ${error}`);
4454
4460
  }
4455
4461
  const result = await res.json();
4456
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
4462
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
4457
4463
  return result;
4458
4464
  },
4459
4465
  // DELETE: /v1/sdk/agents/{agentRef}/plans/{planRef}
4460
4466
  async deletePlan(agentRef, planRef) {
4461
4467
  const url = `${base}/v1/sdk/agents/${agentRef}/plans/${planRef}`;
4462
- console.log(`\u{1F4E1} API Request: DELETE ${url}`);
4468
+ log(`\u{1F4E1} API Request: DELETE ${url}`);
4463
4469
  const res = await fetch(url, {
4464
4470
  method: "DELETE",
4465
4471
  headers
4466
4472
  });
4467
4473
  if (!res.ok && res.status !== 404) {
4468
4474
  const error = await res.text();
4469
- console.error(`\u274C API Error: ${res.status} - ${error}`);
4475
+ log(`\u274C API Error: ${res.status} - ${error}`);
4470
4476
  throw new import_core.SolvaPayError(`Delete plan failed (${res.status}): ${error}`);
4471
4477
  }
4472
- console.log(`\u2705 Plan deleted successfully`);
4478
+ log(`\u2705 Plan deleted successfully`);
4473
4479
  },
4474
4480
  // POST: /payment-intents
4475
4481
  async createPaymentIntent(params) {
4476
4482
  const idempotencyKey = params.idempotencyKey || `payment-${params.planRef}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
4477
4483
  const url = `${base}/v1/sdk/payment-intents`;
4478
- console.log(`\u{1F4E1} API Request: POST ${url}`);
4479
- console.log(` Agent Ref: ${params.agentRef}`);
4480
- console.log(` Plan Ref: ${params.planRef}`);
4481
- console.log(` Customer Ref: ${params.customerRef}`);
4482
- console.log(` Idempotency Key: ${idempotencyKey}`);
4484
+ log(`\u{1F4E1} API Request: POST ${url}`);
4485
+ log(` Agent Ref: ${params.agentRef}`);
4486
+ log(` Plan Ref: ${params.planRef}`);
4487
+ log(` Customer Ref: ${params.customerRef}`);
4488
+ log(` Idempotency Key: ${idempotencyKey}`);
4483
4489
  const res = await fetch(url, {
4484
4490
  method: "POST",
4485
4491
  headers: {
@@ -4494,11 +4500,11 @@ function createSolvaPayClient(opts) {
4494
4500
  });
4495
4501
  if (!res.ok) {
4496
4502
  const error = await res.text();
4497
- console.error(`\u274C API Error: ${res.status} - ${error}`);
4503
+ log(`\u274C API Error: ${res.status} - ${error}`);
4498
4504
  throw new import_core.SolvaPayError(`Create payment intent failed (${res.status}): ${error}`);
4499
4505
  }
4500
4506
  const result = await res.json();
4501
- console.log(`\u2705 Payment intent created:`, {
4507
+ log(`\u2705 Payment intent created:`, {
4502
4508
  id: result.id,
4503
4509
  hasClientSecret: !!result.clientSecret,
4504
4510
  hasPublishableKey: !!result.publishableKey,
@@ -4567,7 +4573,7 @@ var PaywallError = class extends Error {
4567
4573
  var SolvaPayPaywall = class {
4568
4574
  constructor(apiClient, options = {}) {
4569
4575
  this.apiClient = apiClient;
4570
- this.debug = options.debug ?? process.env.SOLVAPAY_DEBUG !== "false";
4576
+ this.debug = options.debug ?? process.env.SOLVAPAY_DEBUG === "true";
4571
4577
  }
4572
4578
  customerCreationAttempts = /* @__PURE__ */ new Set();
4573
4579
  customerRefMapping = /* @__PURE__ */ new Map();
package/dist/index.js CHANGED
@@ -15,15 +15,21 @@ function createSolvaPayClient(opts) {
15
15
  "Content-Type": "application/json",
16
16
  "Authorization": `Bearer ${opts.apiKey}`
17
17
  };
18
- console.log(`\u{1F50C} SolvaPay API Client initialized`);
19
- console.log(` Backend URL: ${base}`);
20
- console.log(` API Key: ${opts.apiKey.substring(0, 10)}...`);
18
+ const debug = process.env.SOLVAPAY_DEBUG === "true";
19
+ const log = (...args) => {
20
+ if (debug) {
21
+ console.log(...args);
22
+ }
23
+ };
24
+ log(`\u{1F50C} SolvaPay API Client initialized`);
25
+ log(` Backend URL: ${base}`);
26
+ log(` API Key: ${opts.apiKey.substring(0, 10)}...`);
21
27
  return {
22
28
  // POST: /v1/sdk/limits
23
29
  async checkLimits(params) {
24
30
  const url = `${base}/v1/sdk/limits`;
25
- console.log(`\u{1F4E1} API Request: POST ${url}`);
26
- console.log(` Params:`, JSON.stringify(params, null, 2));
31
+ log(`\u{1F4E1} API Request: POST ${url}`);
32
+ log(` Params:`, JSON.stringify(params, null, 2));
27
33
  const res = await fetch(url, {
28
34
  method: "POST",
29
35
  headers,
@@ -31,24 +37,24 @@ function createSolvaPayClient(opts) {
31
37
  });
32
38
  if (!res.ok) {
33
39
  const error = await res.text();
34
- console.error(`\u274C API Error: ${res.status} - ${error}`);
40
+ log(`\u274C API Error: ${res.status} - ${error}`);
35
41
  throw new SolvaPayError(`Check limits failed (${res.status}): ${error}`);
36
42
  }
37
43
  const result = await res.json();
38
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
39
- console.log(`\u{1F50D} DEBUG - checkLimits breakdown:`);
40
- console.log(` - withinLimits: ${result.withinLimits}`);
41
- console.log(` - remaining: ${result.remaining}`);
42
- console.log(` - plan: ${result.plan || "N/A"}`);
43
- console.log(` - checkoutUrl: ${result.checkoutUrl || "N/A"}`);
44
- console.log(` - Full response keys:`, Object.keys(result));
44
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
45
+ log(`\u{1F50D} DEBUG - checkLimits breakdown:`);
46
+ log(` - withinLimits: ${result.withinLimits}`);
47
+ log(` - remaining: ${result.remaining}`);
48
+ log(` - plan: ${result.plan || "N/A"}`);
49
+ log(` - checkoutUrl: ${result.checkoutUrl || "N/A"}`);
50
+ log(` - Full response keys:`, Object.keys(result));
45
51
  return result;
46
52
  },
47
53
  // POST: /v1/sdk/usages
48
54
  async trackUsage(params) {
49
55
  const url = `${base}/v1/sdk/usages`;
50
- console.log(`\u{1F4E1} API Request: POST ${url}`);
51
- console.log(` Params:`, JSON.stringify(params, null, 2));
56
+ log(`\u{1F4E1} API Request: POST ${url}`);
57
+ log(` Params:`, JSON.stringify(params, null, 2));
52
58
  const res = await fetch(url, {
53
59
  method: "POST",
54
60
  headers,
@@ -56,16 +62,16 @@ function createSolvaPayClient(opts) {
56
62
  });
57
63
  if (!res.ok) {
58
64
  const error = await res.text();
59
- console.error(`\u274C API Error: ${res.status} - ${error}`);
65
+ log(`\u274C API Error: ${res.status} - ${error}`);
60
66
  throw new SolvaPayError(`Track usage failed (${res.status}): ${error}`);
61
67
  }
62
- console.log(`\u2705 Usage tracked successfully`);
68
+ log(`\u2705 Usage tracked successfully`);
63
69
  },
64
70
  // POST: /v1/sdk/customers
65
71
  async createCustomer(params) {
66
72
  const url = `${base}/v1/sdk/customers`;
67
- console.log(`\u{1F4E1} API Request: POST ${url}`);
68
- console.log(` Params:`, JSON.stringify(params, null, 2));
73
+ log(`\u{1F4E1} API Request: POST ${url}`);
74
+ log(` Params:`, JSON.stringify(params, null, 2));
69
75
  const res = await fetch(url, {
70
76
  method: "POST",
71
77
  headers,
@@ -73,51 +79,51 @@ function createSolvaPayClient(opts) {
73
79
  });
74
80
  if (!res.ok) {
75
81
  const error = await res.text();
76
- console.error(`\u274C API Error: ${res.status} - ${error}`);
82
+ log(`\u274C API Error: ${res.status} - ${error}`);
77
83
  throw new SolvaPayError(`Create customer failed (${res.status}): ${error}`);
78
84
  }
79
85
  const result = await res.json();
80
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
81
- console.log(`\u{1F50D} DEBUG - createCustomer response:`);
82
- console.log(` - reference/customerRef: ${result.reference || result.customerRef}`);
83
- console.log(` - Has plan info: ${result.plan ? "YES" : "NO"}`);
84
- console.log(` - Has subscription info: ${result.subscription ? "YES" : "NO"}`);
85
- console.log(` - Full response keys:`, Object.keys(result));
86
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
87
+ log(`\u{1F50D} DEBUG - createCustomer response:`);
88
+ log(` - reference/customerRef: ${result.reference || result.customerRef}`);
89
+ log(` - Has plan info: ${result.plan ? "YES" : "NO"}`);
90
+ log(` - Has subscription info: ${result.subscription ? "YES" : "NO"}`);
91
+ log(` - Full response keys:`, Object.keys(result));
86
92
  return result;
87
93
  },
88
94
  // GET: /v1/sdk/customers/{reference}
89
95
  async getCustomer(params) {
90
96
  const url = `${base}/v1/sdk/customers/${params.customerRef}`;
91
- console.log(`\u{1F4E1} API Request: GET ${url}`);
97
+ log(`\u{1F4E1} API Request: GET ${url}`);
92
98
  const res = await fetch(url, {
93
99
  method: "GET",
94
100
  headers
95
101
  });
96
102
  if (!res.ok) {
97
103
  const error = await res.text();
98
- console.error(`\u274C API Error: ${res.status} - ${error}`);
104
+ log(`\u274C API Error: ${res.status} - ${error}`);
99
105
  throw new SolvaPayError(`Get customer failed (${res.status}): ${error}`);
100
106
  }
101
107
  const result = await res.json();
102
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
108
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
103
109
  return result;
104
110
  },
105
111
  // Management methods (primarily for integration tests)
106
112
  // GET: /v1/sdk/agents
107
113
  async listAgents() {
108
114
  const url = `${base}/v1/sdk/agents`;
109
- console.log(`\u{1F4E1} API Request: GET ${url}`);
115
+ log(`\u{1F4E1} API Request: GET ${url}`);
110
116
  const res = await fetch(url, {
111
117
  method: "GET",
112
118
  headers
113
119
  });
114
120
  if (!res.ok) {
115
121
  const error = await res.text();
116
- console.error(`\u274C API Error: ${res.status} - ${error}`);
122
+ log(`\u274C API Error: ${res.status} - ${error}`);
117
123
  throw new SolvaPayError(`List agents failed (${res.status}): ${error}`);
118
124
  }
119
125
  const result = await res.json();
120
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
126
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
121
127
  const agents = Array.isArray(result) ? result : result.agents || [];
122
128
  return agents.map((agent) => ({
123
129
  ...agent,
@@ -127,8 +133,8 @@ function createSolvaPayClient(opts) {
127
133
  // POST: /v1/sdk/agents
128
134
  async createAgent(params) {
129
135
  const url = `${base}/v1/sdk/agents`;
130
- console.log(`\u{1F4E1} API Request: POST ${url}`);
131
- console.log(` Params:`, JSON.stringify(params, null, 2));
136
+ log(`\u{1F4E1} API Request: POST ${url}`);
137
+ log(` Params:`, JSON.stringify(params, null, 2));
132
138
  const res = await fetch(url, {
133
139
  method: "POST",
134
140
  headers,
@@ -136,43 +142,43 @@ function createSolvaPayClient(opts) {
136
142
  });
137
143
  if (!res.ok) {
138
144
  const error = await res.text();
139
- console.error(`\u274C API Error: ${res.status} - ${error}`);
145
+ log(`\u274C API Error: ${res.status} - ${error}`);
140
146
  throw new SolvaPayError(`Create agent failed (${res.status}): ${error}`);
141
147
  }
142
148
  const result = await res.json();
143
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
149
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
144
150
  return result;
145
151
  },
146
152
  // DELETE: /v1/sdk/agents/{agentRef}
147
153
  async deleteAgent(agentRef) {
148
154
  const url = `${base}/v1/sdk/agents/${agentRef}`;
149
- console.log(`\u{1F4E1} API Request: DELETE ${url}`);
155
+ log(`\u{1F4E1} API Request: DELETE ${url}`);
150
156
  const res = await fetch(url, {
151
157
  method: "DELETE",
152
158
  headers
153
159
  });
154
160
  if (!res.ok && res.status !== 404) {
155
161
  const error = await res.text();
156
- console.error(`\u274C API Error: ${res.status} - ${error}`);
162
+ log(`\u274C API Error: ${res.status} - ${error}`);
157
163
  throw new SolvaPayError(`Delete agent failed (${res.status}): ${error}`);
158
164
  }
159
- console.log(`\u2705 Agent deleted successfully`);
165
+ log(`\u2705 Agent deleted successfully`);
160
166
  },
161
167
  // GET: /v1/sdk/agents/{agentRef}/plans
162
168
  async listPlans(agentRef) {
163
169
  const url = `${base}/v1/sdk/agents/${agentRef}/plans`;
164
- console.log(`\u{1F4E1} API Request: GET ${url}`);
170
+ log(`\u{1F4E1} API Request: GET ${url}`);
165
171
  const res = await fetch(url, {
166
172
  method: "GET",
167
173
  headers
168
174
  });
169
175
  if (!res.ok) {
170
176
  const error = await res.text();
171
- console.error(`\u274C API Error: ${res.status} - ${error}`);
177
+ log(`\u274C API Error: ${res.status} - ${error}`);
172
178
  throw new SolvaPayError(`List plans failed (${res.status}): ${error}`);
173
179
  }
174
180
  const result = await res.json();
175
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
181
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
176
182
  const plans = Array.isArray(result) ? result : result.plans || [];
177
183
  return plans.map((plan) => ({
178
184
  ...plan,
@@ -182,8 +188,8 @@ function createSolvaPayClient(opts) {
182
188
  // POST: /v1/sdk/agents/{agentRef}/plans
183
189
  async createPlan(params) {
184
190
  const url = `${base}/v1/sdk/agents/${params.agentRef}/plans`;
185
- console.log(`\u{1F4E1} API Request: POST ${url}`);
186
- console.log(` Params:`, JSON.stringify(params, null, 2));
191
+ log(`\u{1F4E1} API Request: POST ${url}`);
192
+ log(` Params:`, JSON.stringify(params, null, 2));
187
193
  const res = await fetch(url, {
188
194
  method: "POST",
189
195
  headers,
@@ -191,37 +197,37 @@ function createSolvaPayClient(opts) {
191
197
  });
192
198
  if (!res.ok) {
193
199
  const error = await res.text();
194
- console.error(`\u274C API Error: ${res.status} - ${error}`);
200
+ log(`\u274C API Error: ${res.status} - ${error}`);
195
201
  throw new SolvaPayError(`Create plan failed (${res.status}): ${error}`);
196
202
  }
197
203
  const result = await res.json();
198
- console.log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
204
+ log(`\u2705 API Response:`, JSON.stringify(result, null, 2));
199
205
  return result;
200
206
  },
201
207
  // DELETE: /v1/sdk/agents/{agentRef}/plans/{planRef}
202
208
  async deletePlan(agentRef, planRef) {
203
209
  const url = `${base}/v1/sdk/agents/${agentRef}/plans/${planRef}`;
204
- console.log(`\u{1F4E1} API Request: DELETE ${url}`);
210
+ log(`\u{1F4E1} API Request: DELETE ${url}`);
205
211
  const res = await fetch(url, {
206
212
  method: "DELETE",
207
213
  headers
208
214
  });
209
215
  if (!res.ok && res.status !== 404) {
210
216
  const error = await res.text();
211
- console.error(`\u274C API Error: ${res.status} - ${error}`);
217
+ log(`\u274C API Error: ${res.status} - ${error}`);
212
218
  throw new SolvaPayError(`Delete plan failed (${res.status}): ${error}`);
213
219
  }
214
- console.log(`\u2705 Plan deleted successfully`);
220
+ log(`\u2705 Plan deleted successfully`);
215
221
  },
216
222
  // POST: /payment-intents
217
223
  async createPaymentIntent(params) {
218
224
  const idempotencyKey = params.idempotencyKey || `payment-${params.planRef}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
219
225
  const url = `${base}/v1/sdk/payment-intents`;
220
- console.log(`\u{1F4E1} API Request: POST ${url}`);
221
- console.log(` Agent Ref: ${params.agentRef}`);
222
- console.log(` Plan Ref: ${params.planRef}`);
223
- console.log(` Customer Ref: ${params.customerRef}`);
224
- console.log(` Idempotency Key: ${idempotencyKey}`);
226
+ log(`\u{1F4E1} API Request: POST ${url}`);
227
+ log(` Agent Ref: ${params.agentRef}`);
228
+ log(` Plan Ref: ${params.planRef}`);
229
+ log(` Customer Ref: ${params.customerRef}`);
230
+ log(` Idempotency Key: ${idempotencyKey}`);
225
231
  const res = await fetch(url, {
226
232
  method: "POST",
227
233
  headers: {
@@ -236,11 +242,11 @@ function createSolvaPayClient(opts) {
236
242
  });
237
243
  if (!res.ok) {
238
244
  const error = await res.text();
239
- console.error(`\u274C API Error: ${res.status} - ${error}`);
245
+ log(`\u274C API Error: ${res.status} - ${error}`);
240
246
  throw new SolvaPayError(`Create payment intent failed (${res.status}): ${error}`);
241
247
  }
242
248
  const result = await res.json();
243
- console.log(`\u2705 Payment intent created:`, {
249
+ log(`\u2705 Payment intent created:`, {
244
250
  id: result.id,
245
251
  hasClientSecret: !!result.clientSecret,
246
252
  hasPublishableKey: !!result.publishableKey,
@@ -309,7 +315,7 @@ var PaywallError = class extends Error {
309
315
  var SolvaPayPaywall = class {
310
316
  constructor(apiClient, options = {}) {
311
317
  this.apiClient = apiClient;
312
- this.debug = options.debug ?? process.env.SOLVAPAY_DEBUG !== "false";
318
+ this.debug = options.debug ?? process.env.SOLVAPAY_DEBUG === "true";
313
319
  }
314
320
  customerCreationAttempts = /* @__PURE__ */ new Set();
315
321
  customerRefMapping = /* @__PURE__ */ new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solvapay/server",
3
- "version": "1.0.0-preview.1",
3
+ "version": "1.0.0-preview.3",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -13,6 +13,11 @@
13
13
  "deno": "./dist/edge.js",
14
14
  "import": "./dist/index.js",
15
15
  "require": "./dist/index.cjs"
16
+ },
17
+ "./edge": {
18
+ "types": "./dist/edge.d.ts",
19
+ "import": "./dist/edge.js",
20
+ "default": "./dist/edge.js"
16
21
  }
17
22
  },
18
23
  "files": [
@@ -32,7 +37,7 @@
32
37
  },
33
38
  "sideEffects": false,
34
39
  "dependencies": {
35
- "@solvapay/core": "1.0.0-preview.1"
40
+ "@solvapay/core": "1.0.0-preview.3"
36
41
  },
37
42
  "devDependencies": {
38
43
  "dotenv": "^17.2.3",