@solvapay/server 1.1.0 → 1.1.1

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
@@ -262,7 +262,7 @@ Choose the adapter based on your context:
262
262
 
263
263
  The `createSolvaPayClient` returns an object implementing `SolvaPayClient`:
264
264
 
265
- - `checkLimits(params)` - Check if customer is within usage limits
265
+ - `checkLimits(params)` - Check if customer is within usage limits. For products whose default plan is free and non-usage-based, the first call also auto-enrolls the customer (creates a `Purchase` with `origin: 'free_default'`). Merchants who want explicit enrollment at signup can still call `purchases.activate(...)`.
266
266
  - `trackUsage(params)` - Track usage for metered billing
267
267
  - `createCustomer(params)` - Create a new customer
268
268
  - `getCustomer(params)` - Get customer details by reference
package/dist/edge.js CHANGED
@@ -28,7 +28,7 @@ function createSolvaPayClient(opts) {
28
28
  if (!res.ok) {
29
29
  const error = await res.text();
30
30
  log(`\u274C API Error: ${res.status} - ${error}`);
31
- throw new SolvaPayError(`Check limits failed (${res.status}): ${error}`);
31
+ throw new SolvaPayError(`Check limits failed (${res.status}): ${error}`, { status: res.status });
32
32
  }
33
33
  const result = await res.json();
34
34
  return result;
@@ -44,7 +44,7 @@ function createSolvaPayClient(opts) {
44
44
  if (!res.ok) {
45
45
  const error = await res.text();
46
46
  log(`\u274C API Error: ${res.status} - ${error}`);
47
- throw new SolvaPayError(`Track usage failed (${res.status}): ${error}`);
47
+ throw new SolvaPayError(`Track usage failed (${res.status}): ${error}`, { status: res.status });
48
48
  }
49
49
  },
50
50
  // POST: /v1/sdk/customers
@@ -58,7 +58,7 @@ function createSolvaPayClient(opts) {
58
58
  if (!res.ok) {
59
59
  const error = await res.text();
60
60
  log(`\u274C API Error: ${res.status} - ${error}`);
61
- throw new SolvaPayError(`Create customer failed (${res.status}): ${error}`);
61
+ throw new SolvaPayError(`Create customer failed (${res.status}): ${error}`, { status: res.status });
62
62
  }
63
63
  const result = await res.json();
64
64
  return {
@@ -76,7 +76,7 @@ function createSolvaPayClient(opts) {
76
76
  if (!res.ok) {
77
77
  const error = await res.text();
78
78
  log(`\u274C API Error: ${res.status} - ${error}`);
79
- throw new SolvaPayError(`Update customer failed (${res.status}): ${error}`);
79
+ throw new SolvaPayError(`Update customer failed (${res.status}): ${error}`, { status: res.status });
80
80
  }
81
81
  const result = await res.json();
82
82
  return {
@@ -106,7 +106,7 @@ function createSolvaPayClient(opts) {
106
106
  if (!res.ok) {
107
107
  const error = await res.text();
108
108
  log(`\u274C API Error: ${res.status} - ${error}`);
109
- throw new SolvaPayError(`Get customer failed (${res.status}): ${error}`);
109
+ throw new SolvaPayError(`Get customer failed (${res.status}): ${error}`, { status: res.status });
110
110
  }
111
111
  const result = await res.json();
112
112
  let customer = result;
@@ -137,7 +137,7 @@ function createSolvaPayClient(opts) {
137
137
  if (!res.ok) {
138
138
  const error = await res.text();
139
139
  log(`\u274C API Error: ${res.status} - ${error}`);
140
- throw new SolvaPayError(`Get merchant failed (${res.status}): ${error}`);
140
+ throw new SolvaPayError(`Get merchant failed (${res.status}): ${error}`, { status: res.status });
141
141
  }
142
142
  return res.json();
143
143
  },
@@ -151,7 +151,7 @@ function createSolvaPayClient(opts) {
151
151
  if (!res.ok) {
152
152
  const error = await res.text();
153
153
  log(`\u274C API Error: ${res.status} - ${error}`);
154
- throw new SolvaPayError(`Get platform config failed (${res.status}): ${error}`);
154
+ throw new SolvaPayError(`Get platform config failed (${res.status}): ${error}`, { status: res.status });
155
155
  }
156
156
  return res.json();
157
157
  },
@@ -165,7 +165,7 @@ function createSolvaPayClient(opts) {
165
165
  if (!res.ok) {
166
166
  const error = await res.text();
167
167
  log(`\u274C API Error: ${res.status} - ${error}`);
168
- throw new SolvaPayError(`Get product failed (${res.status}): ${error}`);
168
+ throw new SolvaPayError(`Get product failed (${res.status}): ${error}`, { status: res.status });
169
169
  }
170
170
  const result = await res.json();
171
171
  const data = result.data || {};
@@ -182,7 +182,7 @@ function createSolvaPayClient(opts) {
182
182
  if (!res.ok) {
183
183
  const error = await res.text();
184
184
  log(`\u274C API Error: ${res.status} - ${error}`);
185
- throw new SolvaPayError(`List products failed (${res.status}): ${error}`);
185
+ throw new SolvaPayError(`List products failed (${res.status}): ${error}`, { status: res.status });
186
186
  }
187
187
  const result = await res.json();
188
188
  const products = Array.isArray(result) ? result : result.products || [];
@@ -202,7 +202,7 @@ function createSolvaPayClient(opts) {
202
202
  if (!res.ok) {
203
203
  const error = await res.text();
204
204
  log(`\u274C API Error: ${res.status} - ${error}`);
205
- throw new SolvaPayError(`Create product failed (${res.status}): ${error}`);
205
+ throw new SolvaPayError(`Create product failed (${res.status}): ${error}`, { status: res.status });
206
206
  }
207
207
  const result = await res.json();
208
208
  return result;
@@ -218,7 +218,7 @@ function createSolvaPayClient(opts) {
218
218
  if (!res.ok) {
219
219
  const error = await res.text();
220
220
  log(`\u274C API Error: ${res.status} - ${error}`);
221
- throw new SolvaPayError(`Bootstrap MCP product failed (${res.status}): ${error}`);
221
+ throw new SolvaPayError(`Bootstrap MCP product failed (${res.status}): ${error}`, { status: res.status });
222
222
  }
223
223
  return await res.json();
224
224
  },
@@ -233,7 +233,7 @@ function createSolvaPayClient(opts) {
233
233
  if (!res.ok) {
234
234
  const error = await res.text();
235
235
  log(`\u274C API Error: ${res.status} - ${error}`);
236
- throw new SolvaPayError(`Configure MCP plans failed (${res.status}): ${error}`);
236
+ throw new SolvaPayError(`Configure MCP plans failed (${res.status}): ${error}`, { status: res.status });
237
237
  }
238
238
  return await res.json();
239
239
  },
@@ -247,7 +247,7 @@ function createSolvaPayClient(opts) {
247
247
  if (!res.ok && res.status !== 404) {
248
248
  const error = await res.text();
249
249
  log(`\u274C API Error: ${res.status} - ${error}`);
250
- throw new SolvaPayError(`Delete product failed (${res.status}): ${error}`);
250
+ throw new SolvaPayError(`Delete product failed (${res.status}): ${error}`, { status: res.status });
251
251
  }
252
252
  },
253
253
  // POST: /v1/sdk/products/{productRef}/clone
@@ -261,7 +261,7 @@ function createSolvaPayClient(opts) {
261
261
  if (!res.ok) {
262
262
  const error = await res.text();
263
263
  log(`\u274C API Error: ${res.status} - ${error}`);
264
- throw new SolvaPayError(`Clone product failed (${res.status}): ${error}`);
264
+ throw new SolvaPayError(`Clone product failed (${res.status}): ${error}`, { status: res.status });
265
265
  }
266
266
  return await res.json();
267
267
  },
@@ -275,7 +275,7 @@ function createSolvaPayClient(opts) {
275
275
  if (!res.ok) {
276
276
  const error = await res.text();
277
277
  log(`\u274C API Error: ${res.status} - ${error}`);
278
- throw new SolvaPayError(`List plans failed (${res.status}): ${error}`);
278
+ throw new SolvaPayError(`List plans failed (${res.status}): ${error}`, { status: res.status });
279
279
  }
280
280
  const result = await res.json();
281
281
  const plans = Array.isArray(result) ? result : result.plans || [];
@@ -302,7 +302,7 @@ function createSolvaPayClient(opts) {
302
302
  if (!res.ok) {
303
303
  const error = await res.text();
304
304
  log(`\u274C API Error: ${res.status} - ${error}`);
305
- throw new SolvaPayError(`Create plan failed (${res.status}): ${error}`);
305
+ throw new SolvaPayError(`Create plan failed (${res.status}): ${error}`, { status: res.status });
306
306
  }
307
307
  const result = await res.json();
308
308
  return result;
@@ -318,7 +318,7 @@ function createSolvaPayClient(opts) {
318
318
  if (!res.ok) {
319
319
  const error = await res.text();
320
320
  log(`\u274C API Error: ${res.status} - ${error}`);
321
- throw new SolvaPayError(`Update plan failed (${res.status}): ${error}`);
321
+ throw new SolvaPayError(`Update plan failed (${res.status}): ${error}`, { status: res.status });
322
322
  }
323
323
  return await res.json();
324
324
  },
@@ -332,7 +332,7 @@ function createSolvaPayClient(opts) {
332
332
  if (!res.ok && res.status !== 404) {
333
333
  const error = await res.text();
334
334
  log(`\u274C API Error: ${res.status} - ${error}`);
335
- throw new SolvaPayError(`Delete plan failed (${res.status}): ${error}`);
335
+ throw new SolvaPayError(`Delete plan failed (${res.status}): ${error}`, { status: res.status });
336
336
  }
337
337
  },
338
338
  // POST: /payment-intents
@@ -354,7 +354,7 @@ function createSolvaPayClient(opts) {
354
354
  if (!res.ok) {
355
355
  const error = await res.text();
356
356
  log(`\u274C API Error: ${res.status} - ${error}`);
357
- throw new SolvaPayError(`Create payment intent failed (${res.status}): ${error}`);
357
+ throw new SolvaPayError(`Create payment intent failed (${res.status}): ${error}`, { status: res.status });
358
358
  }
359
359
  return await res.json();
360
360
  },
@@ -379,7 +379,7 @@ function createSolvaPayClient(opts) {
379
379
  if (!res.ok) {
380
380
  const error = await res.text();
381
381
  log(`\u274C API Error: ${res.status} - ${error}`);
382
- throw new SolvaPayError(`Create topup payment intent failed (${res.status}): ${error}`);
382
+ throw new SolvaPayError(`Create topup payment intent failed (${res.status}): ${error}`, { status: res.status });
383
383
  }
384
384
  return await res.json();
385
385
  },
@@ -401,7 +401,7 @@ function createSolvaPayClient(opts) {
401
401
  if (!res.ok) {
402
402
  const error = await res.text();
403
403
  log(`\u274C API Error: ${res.status} - ${error}`);
404
- throw new SolvaPayError(`Process payment failed (${res.status}): ${error}`);
404
+ throw new SolvaPayError(`Process payment failed (${res.status}): ${error}`, { status: res.status });
405
405
  }
406
406
  const result = await res.json();
407
407
  return result;
@@ -421,14 +421,15 @@ function createSolvaPayClient(opts) {
421
421
  const error = await res.text();
422
422
  log(`\u274C API Error: ${res.status} - ${error}`);
423
423
  if (res.status === 404) {
424
- throw new SolvaPayError(`Purchase not found: ${error}`);
424
+ throw new SolvaPayError(`Purchase not found: ${error}`, { status: 404 });
425
425
  }
426
426
  if (res.status === 400) {
427
427
  throw new SolvaPayError(
428
- `Purchase cannot be cancelled or does not belong to provider: ${error}`
428
+ `Purchase cannot be cancelled or does not belong to provider: ${error}`,
429
+ { status: 400 }
429
430
  );
430
431
  }
431
- throw new SolvaPayError(`Cancel purchase failed (${res.status}): ${error}`);
432
+ throw new SolvaPayError(`Cancel purchase failed (${res.status}): ${error}`, { status: res.status });
432
433
  }
433
434
  const responseText = await res.text();
434
435
  let responseData;
@@ -469,14 +470,15 @@ function createSolvaPayClient(opts) {
469
470
  const error = await res.text();
470
471
  log(`\u274C API Error: ${res.status} - ${error}`);
471
472
  if (res.status === 404) {
472
- throw new SolvaPayError(`Purchase not found: ${error}`);
473
+ throw new SolvaPayError(`Purchase not found: ${error}`, { status: 404 });
473
474
  }
474
475
  if (res.status === 400) {
475
476
  throw new SolvaPayError(
476
- `Purchase cannot be reactivated: ${error}`
477
+ `Purchase cannot be reactivated: ${error}`,
478
+ { status: 400 }
477
479
  );
478
480
  }
479
- throw new SolvaPayError(`Reactivate purchase failed (${res.status}): ${error}`);
481
+ throw new SolvaPayError(`Reactivate purchase failed (${res.status}): ${error}`, { status: res.status });
480
482
  }
481
483
  const responseText = await res.text();
482
484
  let responseData;
@@ -517,7 +519,7 @@ function createSolvaPayClient(opts) {
517
519
  if (!res.ok) {
518
520
  const error = await res.text();
519
521
  log(`\u274C API Error: ${res.status} - ${error}`);
520
- throw new SolvaPayError(`Get user info failed (${res.status}): ${error}`);
522
+ throw new SolvaPayError(`Get user info failed (${res.status}): ${error}`, { status: res.status });
521
523
  }
522
524
  return await res.json();
523
525
  },
@@ -531,7 +533,7 @@ function createSolvaPayClient(opts) {
531
533
  if (!res.ok) {
532
534
  const error = await res.text();
533
535
  log(`\u274C API Error: ${res.status} - ${error}`);
534
- throw new SolvaPayError(`Get customer balance failed (${res.status}): ${error}`);
536
+ throw new SolvaPayError(`Get customer balance failed (${res.status}): ${error}`, { status: res.status });
535
537
  }
536
538
  return await res.json();
537
539
  },
@@ -546,7 +548,7 @@ function createSolvaPayClient(opts) {
546
548
  if (!res.ok) {
547
549
  const error = await res.text();
548
550
  log(`\u274C API Error: ${res.status} - ${error}`);
549
- throw new SolvaPayError(`Create checkout session failed (${res.status}): ${error}`);
551
+ throw new SolvaPayError(`Create checkout session failed (${res.status}): ${error}`, { status: res.status });
550
552
  }
551
553
  const result = await res.json();
552
554
  return result;
@@ -562,7 +564,7 @@ function createSolvaPayClient(opts) {
562
564
  if (!res.ok) {
563
565
  const error = await res.text();
564
566
  log(`\u274C API Error: ${res.status} - ${error}`);
565
- throw new SolvaPayError(`Create customer session failed (${res.status}): ${error}`);
567
+ throw new SolvaPayError(`Create customer session failed (${res.status}): ${error}`, { status: res.status });
566
568
  }
567
569
  const result = await res.json();
568
570
  return result;
@@ -578,7 +580,7 @@ function createSolvaPayClient(opts) {
578
580
  if (!res.ok) {
579
581
  const error = await res.text();
580
582
  log(`\u274C API Error: ${res.status} - ${error}`);
581
- throw new SolvaPayError(`Activate plan failed (${res.status}): ${error}`);
583
+ throw new SolvaPayError(`Activate plan failed (${res.status}): ${error}`, { status: res.status });
582
584
  }
583
585
  return await res.json();
584
586
  },
@@ -589,7 +591,7 @@ function createSolvaPayClient(opts) {
589
591
  if (!res.ok) {
590
592
  const error = await res.text();
591
593
  log(`\u274C API Error: ${res.status} - ${error}`);
592
- throw new SolvaPayError(`Get payment method failed (${res.status}): ${error}`);
594
+ throw new SolvaPayError(`Get payment method failed (${res.status}): ${error}`, { status: res.status });
593
595
  }
594
596
  return await res.json();
595
597
  }
@@ -972,14 +974,14 @@ var SolvaPayPaywall = class {
972
974
  }
973
975
  if (!withinLimits) {
974
976
  const latencyMs = Date.now() - startTime;
975
- this.trackUsage(
977
+ await this.trackUsage(
976
978
  backendCustomerRef,
977
979
  product,
978
980
  resolvedMeterName || usageType,
979
981
  "paywall",
980
982
  requestId,
981
983
  latencyMs
982
- );
984
+ ).catch(() => void 0);
983
985
  const gate = buildPaywallGate(
984
986
  product,
985
987
  lastLimitsCheck ?? {
@@ -1033,14 +1035,14 @@ var SolvaPayPaywall = class {
1033
1035
  try {
1034
1036
  const result = await handler(args, handlerContext);
1035
1037
  const latencyMs = Date.now() - startTime;
1036
- this.trackUsage(
1038
+ await this.trackUsage(
1037
1039
  decision.customerRef,
1038
1040
  product,
1039
1041
  decision.limits.meterName || usageType,
1040
1042
  "success",
1041
1043
  requestId,
1042
1044
  latencyMs
1043
- );
1045
+ ).catch(() => void 0);
1044
1046
  return result;
1045
1047
  } catch (error) {
1046
1048
  if (error instanceof Error) {
@@ -1051,14 +1053,14 @@ var SolvaPayPaywall = class {
1051
1053
  }
1052
1054
  if (!(error instanceof PaywallError)) {
1053
1055
  const latencyMs = Date.now() - startTime;
1054
- this.trackUsage(
1056
+ await this.trackUsage(
1055
1057
  decision.customerRef,
1056
1058
  product,
1057
1059
  decision.limits.meterName || usageType,
1058
1060
  "fail",
1059
1061
  requestId,
1060
1062
  latencyMs
1061
- );
1063
+ ).catch(() => void 0);
1062
1064
  }
1063
1065
  throw error;
1064
1066
  }
@@ -2078,7 +2080,7 @@ function handleRouteError(error, operationName, defaultMessage) {
2078
2080
  const errorMessage2 = error.message;
2079
2081
  return {
2080
2082
  error: errorMessage2,
2081
- status: 500,
2083
+ status: error.status ?? 500,
2082
2084
  details: errorMessage2
2083
2085
  };
2084
2086
  }
@@ -62,7 +62,7 @@ function handleRouteError(error, operationName, defaultMessage) {
62
62
  const errorMessage2 = error.message;
63
63
  return {
64
64
  error: errorMessage2,
65
- status: 500,
65
+ status: error.status ?? 500,
66
66
  details: errorMessage2
67
67
  };
68
68
  }
@@ -231,7 +231,7 @@ function createSolvaPayClient(opts) {
231
231
  if (!res.ok) {
232
232
  const error = await res.text();
233
233
  log(`\u274C API Error: ${res.status} - ${error}`);
234
- throw new import_core2.SolvaPayError(`Check limits failed (${res.status}): ${error}`);
234
+ throw new import_core2.SolvaPayError(`Check limits failed (${res.status}): ${error}`, { status: res.status });
235
235
  }
236
236
  const result = await res.json();
237
237
  return result;
@@ -247,7 +247,7 @@ function createSolvaPayClient(opts) {
247
247
  if (!res.ok) {
248
248
  const error = await res.text();
249
249
  log(`\u274C API Error: ${res.status} - ${error}`);
250
- throw new import_core2.SolvaPayError(`Track usage failed (${res.status}): ${error}`);
250
+ throw new import_core2.SolvaPayError(`Track usage failed (${res.status}): ${error}`, { status: res.status });
251
251
  }
252
252
  },
253
253
  // POST: /v1/sdk/customers
@@ -261,7 +261,7 @@ function createSolvaPayClient(opts) {
261
261
  if (!res.ok) {
262
262
  const error = await res.text();
263
263
  log(`\u274C API Error: ${res.status} - ${error}`);
264
- throw new import_core2.SolvaPayError(`Create customer failed (${res.status}): ${error}`);
264
+ throw new import_core2.SolvaPayError(`Create customer failed (${res.status}): ${error}`, { status: res.status });
265
265
  }
266
266
  const result = await res.json();
267
267
  return {
@@ -279,7 +279,7 @@ function createSolvaPayClient(opts) {
279
279
  if (!res.ok) {
280
280
  const error = await res.text();
281
281
  log(`\u274C API Error: ${res.status} - ${error}`);
282
- throw new import_core2.SolvaPayError(`Update customer failed (${res.status}): ${error}`);
282
+ throw new import_core2.SolvaPayError(`Update customer failed (${res.status}): ${error}`, { status: res.status });
283
283
  }
284
284
  const result = await res.json();
285
285
  return {
@@ -309,7 +309,7 @@ function createSolvaPayClient(opts) {
309
309
  if (!res.ok) {
310
310
  const error = await res.text();
311
311
  log(`\u274C API Error: ${res.status} - ${error}`);
312
- throw new import_core2.SolvaPayError(`Get customer failed (${res.status}): ${error}`);
312
+ throw new import_core2.SolvaPayError(`Get customer failed (${res.status}): ${error}`, { status: res.status });
313
313
  }
314
314
  const result = await res.json();
315
315
  let customer = result;
@@ -340,7 +340,7 @@ function createSolvaPayClient(opts) {
340
340
  if (!res.ok) {
341
341
  const error = await res.text();
342
342
  log(`\u274C API Error: ${res.status} - ${error}`);
343
- throw new import_core2.SolvaPayError(`Get merchant failed (${res.status}): ${error}`);
343
+ throw new import_core2.SolvaPayError(`Get merchant failed (${res.status}): ${error}`, { status: res.status });
344
344
  }
345
345
  return res.json();
346
346
  },
@@ -354,7 +354,7 @@ function createSolvaPayClient(opts) {
354
354
  if (!res.ok) {
355
355
  const error = await res.text();
356
356
  log(`\u274C API Error: ${res.status} - ${error}`);
357
- throw new import_core2.SolvaPayError(`Get platform config failed (${res.status}): ${error}`);
357
+ throw new import_core2.SolvaPayError(`Get platform config failed (${res.status}): ${error}`, { status: res.status });
358
358
  }
359
359
  return res.json();
360
360
  },
@@ -368,7 +368,7 @@ function createSolvaPayClient(opts) {
368
368
  if (!res.ok) {
369
369
  const error = await res.text();
370
370
  log(`\u274C API Error: ${res.status} - ${error}`);
371
- throw new import_core2.SolvaPayError(`Get product failed (${res.status}): ${error}`);
371
+ throw new import_core2.SolvaPayError(`Get product failed (${res.status}): ${error}`, { status: res.status });
372
372
  }
373
373
  const result = await res.json();
374
374
  const data = result.data || {};
@@ -385,7 +385,7 @@ function createSolvaPayClient(opts) {
385
385
  if (!res.ok) {
386
386
  const error = await res.text();
387
387
  log(`\u274C API Error: ${res.status} - ${error}`);
388
- throw new import_core2.SolvaPayError(`List products failed (${res.status}): ${error}`);
388
+ throw new import_core2.SolvaPayError(`List products failed (${res.status}): ${error}`, { status: res.status });
389
389
  }
390
390
  const result = await res.json();
391
391
  const products = Array.isArray(result) ? result : result.products || [];
@@ -405,7 +405,7 @@ function createSolvaPayClient(opts) {
405
405
  if (!res.ok) {
406
406
  const error = await res.text();
407
407
  log(`\u274C API Error: ${res.status} - ${error}`);
408
- throw new import_core2.SolvaPayError(`Create product failed (${res.status}): ${error}`);
408
+ throw new import_core2.SolvaPayError(`Create product failed (${res.status}): ${error}`, { status: res.status });
409
409
  }
410
410
  const result = await res.json();
411
411
  return result;
@@ -421,7 +421,7 @@ function createSolvaPayClient(opts) {
421
421
  if (!res.ok) {
422
422
  const error = await res.text();
423
423
  log(`\u274C API Error: ${res.status} - ${error}`);
424
- throw new import_core2.SolvaPayError(`Bootstrap MCP product failed (${res.status}): ${error}`);
424
+ throw new import_core2.SolvaPayError(`Bootstrap MCP product failed (${res.status}): ${error}`, { status: res.status });
425
425
  }
426
426
  return await res.json();
427
427
  },
@@ -436,7 +436,7 @@ function createSolvaPayClient(opts) {
436
436
  if (!res.ok) {
437
437
  const error = await res.text();
438
438
  log(`\u274C API Error: ${res.status} - ${error}`);
439
- throw new import_core2.SolvaPayError(`Configure MCP plans failed (${res.status}): ${error}`);
439
+ throw new import_core2.SolvaPayError(`Configure MCP plans failed (${res.status}): ${error}`, { status: res.status });
440
440
  }
441
441
  return await res.json();
442
442
  },
@@ -450,7 +450,7 @@ function createSolvaPayClient(opts) {
450
450
  if (!res.ok && res.status !== 404) {
451
451
  const error = await res.text();
452
452
  log(`\u274C API Error: ${res.status} - ${error}`);
453
- throw new import_core2.SolvaPayError(`Delete product failed (${res.status}): ${error}`);
453
+ throw new import_core2.SolvaPayError(`Delete product failed (${res.status}): ${error}`, { status: res.status });
454
454
  }
455
455
  },
456
456
  // POST: /v1/sdk/products/{productRef}/clone
@@ -464,7 +464,7 @@ function createSolvaPayClient(opts) {
464
464
  if (!res.ok) {
465
465
  const error = await res.text();
466
466
  log(`\u274C API Error: ${res.status} - ${error}`);
467
- throw new import_core2.SolvaPayError(`Clone product failed (${res.status}): ${error}`);
467
+ throw new import_core2.SolvaPayError(`Clone product failed (${res.status}): ${error}`, { status: res.status });
468
468
  }
469
469
  return await res.json();
470
470
  },
@@ -478,7 +478,7 @@ function createSolvaPayClient(opts) {
478
478
  if (!res.ok) {
479
479
  const error = await res.text();
480
480
  log(`\u274C API Error: ${res.status} - ${error}`);
481
- throw new import_core2.SolvaPayError(`List plans failed (${res.status}): ${error}`);
481
+ throw new import_core2.SolvaPayError(`List plans failed (${res.status}): ${error}`, { status: res.status });
482
482
  }
483
483
  const result = await res.json();
484
484
  const plans = Array.isArray(result) ? result : result.plans || [];
@@ -505,7 +505,7 @@ function createSolvaPayClient(opts) {
505
505
  if (!res.ok) {
506
506
  const error = await res.text();
507
507
  log(`\u274C API Error: ${res.status} - ${error}`);
508
- throw new import_core2.SolvaPayError(`Create plan failed (${res.status}): ${error}`);
508
+ throw new import_core2.SolvaPayError(`Create plan failed (${res.status}): ${error}`, { status: res.status });
509
509
  }
510
510
  const result = await res.json();
511
511
  return result;
@@ -521,7 +521,7 @@ function createSolvaPayClient(opts) {
521
521
  if (!res.ok) {
522
522
  const error = await res.text();
523
523
  log(`\u274C API Error: ${res.status} - ${error}`);
524
- throw new import_core2.SolvaPayError(`Update plan failed (${res.status}): ${error}`);
524
+ throw new import_core2.SolvaPayError(`Update plan failed (${res.status}): ${error}`, { status: res.status });
525
525
  }
526
526
  return await res.json();
527
527
  },
@@ -535,7 +535,7 @@ function createSolvaPayClient(opts) {
535
535
  if (!res.ok && res.status !== 404) {
536
536
  const error = await res.text();
537
537
  log(`\u274C API Error: ${res.status} - ${error}`);
538
- throw new import_core2.SolvaPayError(`Delete plan failed (${res.status}): ${error}`);
538
+ throw new import_core2.SolvaPayError(`Delete plan failed (${res.status}): ${error}`, { status: res.status });
539
539
  }
540
540
  },
541
541
  // POST: /payment-intents
@@ -557,7 +557,7 @@ function createSolvaPayClient(opts) {
557
557
  if (!res.ok) {
558
558
  const error = await res.text();
559
559
  log(`\u274C API Error: ${res.status} - ${error}`);
560
- throw new import_core2.SolvaPayError(`Create payment intent failed (${res.status}): ${error}`);
560
+ throw new import_core2.SolvaPayError(`Create payment intent failed (${res.status}): ${error}`, { status: res.status });
561
561
  }
562
562
  return await res.json();
563
563
  },
@@ -582,7 +582,7 @@ function createSolvaPayClient(opts) {
582
582
  if (!res.ok) {
583
583
  const error = await res.text();
584
584
  log(`\u274C API Error: ${res.status} - ${error}`);
585
- throw new import_core2.SolvaPayError(`Create topup payment intent failed (${res.status}): ${error}`);
585
+ throw new import_core2.SolvaPayError(`Create topup payment intent failed (${res.status}): ${error}`, { status: res.status });
586
586
  }
587
587
  return await res.json();
588
588
  },
@@ -604,7 +604,7 @@ function createSolvaPayClient(opts) {
604
604
  if (!res.ok) {
605
605
  const error = await res.text();
606
606
  log(`\u274C API Error: ${res.status} - ${error}`);
607
- throw new import_core2.SolvaPayError(`Process payment failed (${res.status}): ${error}`);
607
+ throw new import_core2.SolvaPayError(`Process payment failed (${res.status}): ${error}`, { status: res.status });
608
608
  }
609
609
  const result = await res.json();
610
610
  return result;
@@ -624,14 +624,15 @@ function createSolvaPayClient(opts) {
624
624
  const error = await res.text();
625
625
  log(`\u274C API Error: ${res.status} - ${error}`);
626
626
  if (res.status === 404) {
627
- throw new import_core2.SolvaPayError(`Purchase not found: ${error}`);
627
+ throw new import_core2.SolvaPayError(`Purchase not found: ${error}`, { status: 404 });
628
628
  }
629
629
  if (res.status === 400) {
630
630
  throw new import_core2.SolvaPayError(
631
- `Purchase cannot be cancelled or does not belong to provider: ${error}`
631
+ `Purchase cannot be cancelled or does not belong to provider: ${error}`,
632
+ { status: 400 }
632
633
  );
633
634
  }
634
- throw new import_core2.SolvaPayError(`Cancel purchase failed (${res.status}): ${error}`);
635
+ throw new import_core2.SolvaPayError(`Cancel purchase failed (${res.status}): ${error}`, { status: res.status });
635
636
  }
636
637
  const responseText = await res.text();
637
638
  let responseData;
@@ -672,14 +673,15 @@ function createSolvaPayClient(opts) {
672
673
  const error = await res.text();
673
674
  log(`\u274C API Error: ${res.status} - ${error}`);
674
675
  if (res.status === 404) {
675
- throw new import_core2.SolvaPayError(`Purchase not found: ${error}`);
676
+ throw new import_core2.SolvaPayError(`Purchase not found: ${error}`, { status: 404 });
676
677
  }
677
678
  if (res.status === 400) {
678
679
  throw new import_core2.SolvaPayError(
679
- `Purchase cannot be reactivated: ${error}`
680
+ `Purchase cannot be reactivated: ${error}`,
681
+ { status: 400 }
680
682
  );
681
683
  }
682
- throw new import_core2.SolvaPayError(`Reactivate purchase failed (${res.status}): ${error}`);
684
+ throw new import_core2.SolvaPayError(`Reactivate purchase failed (${res.status}): ${error}`, { status: res.status });
683
685
  }
684
686
  const responseText = await res.text();
685
687
  let responseData;
@@ -720,7 +722,7 @@ function createSolvaPayClient(opts) {
720
722
  if (!res.ok) {
721
723
  const error = await res.text();
722
724
  log(`\u274C API Error: ${res.status} - ${error}`);
723
- throw new import_core2.SolvaPayError(`Get user info failed (${res.status}): ${error}`);
725
+ throw new import_core2.SolvaPayError(`Get user info failed (${res.status}): ${error}`, { status: res.status });
724
726
  }
725
727
  return await res.json();
726
728
  },
@@ -734,7 +736,7 @@ function createSolvaPayClient(opts) {
734
736
  if (!res.ok) {
735
737
  const error = await res.text();
736
738
  log(`\u274C API Error: ${res.status} - ${error}`);
737
- throw new import_core2.SolvaPayError(`Get customer balance failed (${res.status}): ${error}`);
739
+ throw new import_core2.SolvaPayError(`Get customer balance failed (${res.status}): ${error}`, { status: res.status });
738
740
  }
739
741
  return await res.json();
740
742
  },
@@ -749,7 +751,7 @@ function createSolvaPayClient(opts) {
749
751
  if (!res.ok) {
750
752
  const error = await res.text();
751
753
  log(`\u274C API Error: ${res.status} - ${error}`);
752
- throw new import_core2.SolvaPayError(`Create checkout session failed (${res.status}): ${error}`);
754
+ throw new import_core2.SolvaPayError(`Create checkout session failed (${res.status}): ${error}`, { status: res.status });
753
755
  }
754
756
  const result = await res.json();
755
757
  return result;
@@ -765,7 +767,7 @@ function createSolvaPayClient(opts) {
765
767
  if (!res.ok) {
766
768
  const error = await res.text();
767
769
  log(`\u274C API Error: ${res.status} - ${error}`);
768
- throw new import_core2.SolvaPayError(`Create customer session failed (${res.status}): ${error}`);
770
+ throw new import_core2.SolvaPayError(`Create customer session failed (${res.status}): ${error}`, { status: res.status });
769
771
  }
770
772
  const result = await res.json();
771
773
  return result;
@@ -781,7 +783,7 @@ function createSolvaPayClient(opts) {
781
783
  if (!res.ok) {
782
784
  const error = await res.text();
783
785
  log(`\u274C API Error: ${res.status} - ${error}`);
784
- throw new import_core2.SolvaPayError(`Activate plan failed (${res.status}): ${error}`);
786
+ throw new import_core2.SolvaPayError(`Activate plan failed (${res.status}): ${error}`, { status: res.status });
785
787
  }
786
788
  return await res.json();
787
789
  },
@@ -792,7 +794,7 @@ function createSolvaPayClient(opts) {
792
794
  if (!res.ok) {
793
795
  const error = await res.text();
794
796
  log(`\u274C API Error: ${res.status} - ${error}`);
795
- throw new import_core2.SolvaPayError(`Get payment method failed (${res.status}): ${error}`);
797
+ throw new import_core2.SolvaPayError(`Get payment method failed (${res.status}): ${error}`, { status: res.status });
796
798
  }
797
799
  return await res.json();
798
800
  }
@@ -1161,14 +1163,14 @@ var SolvaPayPaywall = class {
1161
1163
  }
1162
1164
  if (!withinLimits) {
1163
1165
  const latencyMs = Date.now() - startTime;
1164
- this.trackUsage(
1166
+ await this.trackUsage(
1165
1167
  backendCustomerRef,
1166
1168
  product,
1167
1169
  resolvedMeterName || usageType,
1168
1170
  "paywall",
1169
1171
  requestId,
1170
1172
  latencyMs
1171
- );
1173
+ ).catch(() => void 0);
1172
1174
  const gate = buildPaywallGate(
1173
1175
  product,
1174
1176
  lastLimitsCheck ?? {
@@ -1222,14 +1224,14 @@ var SolvaPayPaywall = class {
1222
1224
  try {
1223
1225
  const result = await handler(args, handlerContext);
1224
1226
  const latencyMs = Date.now() - startTime;
1225
- this.trackUsage(
1227
+ await this.trackUsage(
1226
1228
  decision.customerRef,
1227
1229
  product,
1228
1230
  decision.limits.meterName || usageType,
1229
1231
  "success",
1230
1232
  requestId,
1231
1233
  latencyMs
1232
- );
1234
+ ).catch(() => void 0);
1233
1235
  return result;
1234
1236
  } catch (error) {
1235
1237
  if (error instanceof Error) {
@@ -1240,14 +1242,14 @@ var SolvaPayPaywall = class {
1240
1242
  }
1241
1243
  if (!(error instanceof PaywallError)) {
1242
1244
  const latencyMs = Date.now() - startTime;
1243
- this.trackUsage(
1245
+ await this.trackUsage(
1244
1246
  decision.customerRef,
1245
1247
  product,
1246
1248
  decision.limits.meterName || usageType,
1247
1249
  "fail",
1248
1250
  requestId,
1249
1251
  latencyMs
1250
- );
1252
+ ).catch(() => void 0);
1251
1253
  }
1252
1254
  throw error;
1253
1255
  }