@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.
@@ -9,7 +9,7 @@ function handleRouteError(error, operationName, defaultMessage) {
9
9
  const errorMessage2 = error.message;
10
10
  return {
11
11
  error: errorMessage2,
12
- status: 500,
12
+ status: error.status ?? 500,
13
13
  details: errorMessage2
14
14
  };
15
15
  }
@@ -178,7 +178,7 @@ function createSolvaPayClient(opts) {
178
178
  if (!res.ok) {
179
179
  const error = await res.text();
180
180
  log(`\u274C API Error: ${res.status} - ${error}`);
181
- throw new SolvaPayError2(`Check limits failed (${res.status}): ${error}`);
181
+ throw new SolvaPayError2(`Check limits failed (${res.status}): ${error}`, { status: res.status });
182
182
  }
183
183
  const result = await res.json();
184
184
  return result;
@@ -194,7 +194,7 @@ function createSolvaPayClient(opts) {
194
194
  if (!res.ok) {
195
195
  const error = await res.text();
196
196
  log(`\u274C API Error: ${res.status} - ${error}`);
197
- throw new SolvaPayError2(`Track usage failed (${res.status}): ${error}`);
197
+ throw new SolvaPayError2(`Track usage failed (${res.status}): ${error}`, { status: res.status });
198
198
  }
199
199
  },
200
200
  // POST: /v1/sdk/customers
@@ -208,7 +208,7 @@ function createSolvaPayClient(opts) {
208
208
  if (!res.ok) {
209
209
  const error = await res.text();
210
210
  log(`\u274C API Error: ${res.status} - ${error}`);
211
- throw new SolvaPayError2(`Create customer failed (${res.status}): ${error}`);
211
+ throw new SolvaPayError2(`Create customer failed (${res.status}): ${error}`, { status: res.status });
212
212
  }
213
213
  const result = await res.json();
214
214
  return {
@@ -226,7 +226,7 @@ function createSolvaPayClient(opts) {
226
226
  if (!res.ok) {
227
227
  const error = await res.text();
228
228
  log(`\u274C API Error: ${res.status} - ${error}`);
229
- throw new SolvaPayError2(`Update customer failed (${res.status}): ${error}`);
229
+ throw new SolvaPayError2(`Update customer failed (${res.status}): ${error}`, { status: res.status });
230
230
  }
231
231
  const result = await res.json();
232
232
  return {
@@ -256,7 +256,7 @@ function createSolvaPayClient(opts) {
256
256
  if (!res.ok) {
257
257
  const error = await res.text();
258
258
  log(`\u274C API Error: ${res.status} - ${error}`);
259
- throw new SolvaPayError2(`Get customer failed (${res.status}): ${error}`);
259
+ throw new SolvaPayError2(`Get customer failed (${res.status}): ${error}`, { status: res.status });
260
260
  }
261
261
  const result = await res.json();
262
262
  let customer = result;
@@ -287,7 +287,7 @@ function createSolvaPayClient(opts) {
287
287
  if (!res.ok) {
288
288
  const error = await res.text();
289
289
  log(`\u274C API Error: ${res.status} - ${error}`);
290
- throw new SolvaPayError2(`Get merchant failed (${res.status}): ${error}`);
290
+ throw new SolvaPayError2(`Get merchant failed (${res.status}): ${error}`, { status: res.status });
291
291
  }
292
292
  return res.json();
293
293
  },
@@ -301,7 +301,7 @@ function createSolvaPayClient(opts) {
301
301
  if (!res.ok) {
302
302
  const error = await res.text();
303
303
  log(`\u274C API Error: ${res.status} - ${error}`);
304
- throw new SolvaPayError2(`Get platform config failed (${res.status}): ${error}`);
304
+ throw new SolvaPayError2(`Get platform config failed (${res.status}): ${error}`, { status: res.status });
305
305
  }
306
306
  return res.json();
307
307
  },
@@ -315,7 +315,7 @@ function createSolvaPayClient(opts) {
315
315
  if (!res.ok) {
316
316
  const error = await res.text();
317
317
  log(`\u274C API Error: ${res.status} - ${error}`);
318
- throw new SolvaPayError2(`Get product failed (${res.status}): ${error}`);
318
+ throw new SolvaPayError2(`Get product failed (${res.status}): ${error}`, { status: res.status });
319
319
  }
320
320
  const result = await res.json();
321
321
  const data = result.data || {};
@@ -332,7 +332,7 @@ function createSolvaPayClient(opts) {
332
332
  if (!res.ok) {
333
333
  const error = await res.text();
334
334
  log(`\u274C API Error: ${res.status} - ${error}`);
335
- throw new SolvaPayError2(`List products failed (${res.status}): ${error}`);
335
+ throw new SolvaPayError2(`List products failed (${res.status}): ${error}`, { status: res.status });
336
336
  }
337
337
  const result = await res.json();
338
338
  const products = Array.isArray(result) ? result : result.products || [];
@@ -352,7 +352,7 @@ function createSolvaPayClient(opts) {
352
352
  if (!res.ok) {
353
353
  const error = await res.text();
354
354
  log(`\u274C API Error: ${res.status} - ${error}`);
355
- throw new SolvaPayError2(`Create product failed (${res.status}): ${error}`);
355
+ throw new SolvaPayError2(`Create product failed (${res.status}): ${error}`, { status: res.status });
356
356
  }
357
357
  const result = await res.json();
358
358
  return result;
@@ -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 SolvaPayError2(`Bootstrap MCP product failed (${res.status}): ${error}`);
371
+ throw new SolvaPayError2(`Bootstrap MCP product failed (${res.status}): ${error}`, { status: res.status });
372
372
  }
373
373
  return await res.json();
374
374
  },
@@ -383,7 +383,7 @@ function createSolvaPayClient(opts) {
383
383
  if (!res.ok) {
384
384
  const error = await res.text();
385
385
  log(`\u274C API Error: ${res.status} - ${error}`);
386
- throw new SolvaPayError2(`Configure MCP plans failed (${res.status}): ${error}`);
386
+ throw new SolvaPayError2(`Configure MCP plans failed (${res.status}): ${error}`, { status: res.status });
387
387
  }
388
388
  return await res.json();
389
389
  },
@@ -397,7 +397,7 @@ function createSolvaPayClient(opts) {
397
397
  if (!res.ok && res.status !== 404) {
398
398
  const error = await res.text();
399
399
  log(`\u274C API Error: ${res.status} - ${error}`);
400
- throw new SolvaPayError2(`Delete product failed (${res.status}): ${error}`);
400
+ throw new SolvaPayError2(`Delete product failed (${res.status}): ${error}`, { status: res.status });
401
401
  }
402
402
  },
403
403
  // POST: /v1/sdk/products/{productRef}/clone
@@ -411,7 +411,7 @@ function createSolvaPayClient(opts) {
411
411
  if (!res.ok) {
412
412
  const error = await res.text();
413
413
  log(`\u274C API Error: ${res.status} - ${error}`);
414
- throw new SolvaPayError2(`Clone product failed (${res.status}): ${error}`);
414
+ throw new SolvaPayError2(`Clone product failed (${res.status}): ${error}`, { status: res.status });
415
415
  }
416
416
  return await res.json();
417
417
  },
@@ -425,7 +425,7 @@ function createSolvaPayClient(opts) {
425
425
  if (!res.ok) {
426
426
  const error = await res.text();
427
427
  log(`\u274C API Error: ${res.status} - ${error}`);
428
- throw new SolvaPayError2(`List plans failed (${res.status}): ${error}`);
428
+ throw new SolvaPayError2(`List plans failed (${res.status}): ${error}`, { status: res.status });
429
429
  }
430
430
  const result = await res.json();
431
431
  const plans = Array.isArray(result) ? result : result.plans || [];
@@ -452,7 +452,7 @@ function createSolvaPayClient(opts) {
452
452
  if (!res.ok) {
453
453
  const error = await res.text();
454
454
  log(`\u274C API Error: ${res.status} - ${error}`);
455
- throw new SolvaPayError2(`Create plan failed (${res.status}): ${error}`);
455
+ throw new SolvaPayError2(`Create plan failed (${res.status}): ${error}`, { status: res.status });
456
456
  }
457
457
  const result = await res.json();
458
458
  return result;
@@ -468,7 +468,7 @@ function createSolvaPayClient(opts) {
468
468
  if (!res.ok) {
469
469
  const error = await res.text();
470
470
  log(`\u274C API Error: ${res.status} - ${error}`);
471
- throw new SolvaPayError2(`Update plan failed (${res.status}): ${error}`);
471
+ throw new SolvaPayError2(`Update plan failed (${res.status}): ${error}`, { status: res.status });
472
472
  }
473
473
  return await res.json();
474
474
  },
@@ -482,7 +482,7 @@ function createSolvaPayClient(opts) {
482
482
  if (!res.ok && res.status !== 404) {
483
483
  const error = await res.text();
484
484
  log(`\u274C API Error: ${res.status} - ${error}`);
485
- throw new SolvaPayError2(`Delete plan failed (${res.status}): ${error}`);
485
+ throw new SolvaPayError2(`Delete plan failed (${res.status}): ${error}`, { status: res.status });
486
486
  }
487
487
  },
488
488
  // POST: /payment-intents
@@ -504,7 +504,7 @@ function createSolvaPayClient(opts) {
504
504
  if (!res.ok) {
505
505
  const error = await res.text();
506
506
  log(`\u274C API Error: ${res.status} - ${error}`);
507
- throw new SolvaPayError2(`Create payment intent failed (${res.status}): ${error}`);
507
+ throw new SolvaPayError2(`Create payment intent failed (${res.status}): ${error}`, { status: res.status });
508
508
  }
509
509
  return await res.json();
510
510
  },
@@ -529,7 +529,7 @@ function createSolvaPayClient(opts) {
529
529
  if (!res.ok) {
530
530
  const error = await res.text();
531
531
  log(`\u274C API Error: ${res.status} - ${error}`);
532
- throw new SolvaPayError2(`Create topup payment intent failed (${res.status}): ${error}`);
532
+ throw new SolvaPayError2(`Create topup payment intent failed (${res.status}): ${error}`, { status: res.status });
533
533
  }
534
534
  return await res.json();
535
535
  },
@@ -551,7 +551,7 @@ function createSolvaPayClient(opts) {
551
551
  if (!res.ok) {
552
552
  const error = await res.text();
553
553
  log(`\u274C API Error: ${res.status} - ${error}`);
554
- throw new SolvaPayError2(`Process payment failed (${res.status}): ${error}`);
554
+ throw new SolvaPayError2(`Process payment failed (${res.status}): ${error}`, { status: res.status });
555
555
  }
556
556
  const result = await res.json();
557
557
  return result;
@@ -571,14 +571,15 @@ function createSolvaPayClient(opts) {
571
571
  const error = await res.text();
572
572
  log(`\u274C API Error: ${res.status} - ${error}`);
573
573
  if (res.status === 404) {
574
- throw new SolvaPayError2(`Purchase not found: ${error}`);
574
+ throw new SolvaPayError2(`Purchase not found: ${error}`, { status: 404 });
575
575
  }
576
576
  if (res.status === 400) {
577
577
  throw new SolvaPayError2(
578
- `Purchase cannot be cancelled or does not belong to provider: ${error}`
578
+ `Purchase cannot be cancelled or does not belong to provider: ${error}`,
579
+ { status: 400 }
579
580
  );
580
581
  }
581
- throw new SolvaPayError2(`Cancel purchase failed (${res.status}): ${error}`);
582
+ throw new SolvaPayError2(`Cancel purchase failed (${res.status}): ${error}`, { status: res.status });
582
583
  }
583
584
  const responseText = await res.text();
584
585
  let responseData;
@@ -619,14 +620,15 @@ function createSolvaPayClient(opts) {
619
620
  const error = await res.text();
620
621
  log(`\u274C API Error: ${res.status} - ${error}`);
621
622
  if (res.status === 404) {
622
- throw new SolvaPayError2(`Purchase not found: ${error}`);
623
+ throw new SolvaPayError2(`Purchase not found: ${error}`, { status: 404 });
623
624
  }
624
625
  if (res.status === 400) {
625
626
  throw new SolvaPayError2(
626
- `Purchase cannot be reactivated: ${error}`
627
+ `Purchase cannot be reactivated: ${error}`,
628
+ { status: 400 }
627
629
  );
628
630
  }
629
- throw new SolvaPayError2(`Reactivate purchase failed (${res.status}): ${error}`);
631
+ throw new SolvaPayError2(`Reactivate purchase failed (${res.status}): ${error}`, { status: res.status });
630
632
  }
631
633
  const responseText = await res.text();
632
634
  let responseData;
@@ -667,7 +669,7 @@ function createSolvaPayClient(opts) {
667
669
  if (!res.ok) {
668
670
  const error = await res.text();
669
671
  log(`\u274C API Error: ${res.status} - ${error}`);
670
- throw new SolvaPayError2(`Get user info failed (${res.status}): ${error}`);
672
+ throw new SolvaPayError2(`Get user info failed (${res.status}): ${error}`, { status: res.status });
671
673
  }
672
674
  return await res.json();
673
675
  },
@@ -681,7 +683,7 @@ function createSolvaPayClient(opts) {
681
683
  if (!res.ok) {
682
684
  const error = await res.text();
683
685
  log(`\u274C API Error: ${res.status} - ${error}`);
684
- throw new SolvaPayError2(`Get customer balance failed (${res.status}): ${error}`);
686
+ throw new SolvaPayError2(`Get customer balance failed (${res.status}): ${error}`, { status: res.status });
685
687
  }
686
688
  return await res.json();
687
689
  },
@@ -696,7 +698,7 @@ function createSolvaPayClient(opts) {
696
698
  if (!res.ok) {
697
699
  const error = await res.text();
698
700
  log(`\u274C API Error: ${res.status} - ${error}`);
699
- throw new SolvaPayError2(`Create checkout session failed (${res.status}): ${error}`);
701
+ throw new SolvaPayError2(`Create checkout session failed (${res.status}): ${error}`, { status: res.status });
700
702
  }
701
703
  const result = await res.json();
702
704
  return result;
@@ -712,7 +714,7 @@ function createSolvaPayClient(opts) {
712
714
  if (!res.ok) {
713
715
  const error = await res.text();
714
716
  log(`\u274C API Error: ${res.status} - ${error}`);
715
- throw new SolvaPayError2(`Create customer session failed (${res.status}): ${error}`);
717
+ throw new SolvaPayError2(`Create customer session failed (${res.status}): ${error}`, { status: res.status });
716
718
  }
717
719
  const result = await res.json();
718
720
  return result;
@@ -728,7 +730,7 @@ function createSolvaPayClient(opts) {
728
730
  if (!res.ok) {
729
731
  const error = await res.text();
730
732
  log(`\u274C API Error: ${res.status} - ${error}`);
731
- throw new SolvaPayError2(`Activate plan failed (${res.status}): ${error}`);
733
+ throw new SolvaPayError2(`Activate plan failed (${res.status}): ${error}`, { status: res.status });
732
734
  }
733
735
  return await res.json();
734
736
  },
@@ -739,7 +741,7 @@ function createSolvaPayClient(opts) {
739
741
  if (!res.ok) {
740
742
  const error = await res.text();
741
743
  log(`\u274C API Error: ${res.status} - ${error}`);
742
- throw new SolvaPayError2(`Get payment method failed (${res.status}): ${error}`);
744
+ throw new SolvaPayError2(`Get payment method failed (${res.status}): ${error}`, { status: res.status });
743
745
  }
744
746
  return await res.json();
745
747
  }
@@ -1108,14 +1110,14 @@ var SolvaPayPaywall = class {
1108
1110
  }
1109
1111
  if (!withinLimits) {
1110
1112
  const latencyMs = Date.now() - startTime;
1111
- this.trackUsage(
1113
+ await this.trackUsage(
1112
1114
  backendCustomerRef,
1113
1115
  product,
1114
1116
  resolvedMeterName || usageType,
1115
1117
  "paywall",
1116
1118
  requestId,
1117
1119
  latencyMs
1118
- );
1120
+ ).catch(() => void 0);
1119
1121
  const gate = buildPaywallGate(
1120
1122
  product,
1121
1123
  lastLimitsCheck ?? {
@@ -1169,14 +1171,14 @@ var SolvaPayPaywall = class {
1169
1171
  try {
1170
1172
  const result = await handler(args, handlerContext);
1171
1173
  const latencyMs = Date.now() - startTime;
1172
- this.trackUsage(
1174
+ await this.trackUsage(
1173
1175
  decision.customerRef,
1174
1176
  product,
1175
1177
  decision.limits.meterName || usageType,
1176
1178
  "success",
1177
1179
  requestId,
1178
1180
  latencyMs
1179
- );
1181
+ ).catch(() => void 0);
1180
1182
  return result;
1181
1183
  } catch (error) {
1182
1184
  if (error instanceof Error) {
@@ -1187,14 +1189,14 @@ var SolvaPayPaywall = class {
1187
1189
  }
1188
1190
  if (!(error instanceof PaywallError)) {
1189
1191
  const latencyMs = Date.now() - startTime;
1190
- this.trackUsage(
1192
+ await this.trackUsage(
1191
1193
  decision.customerRef,
1192
1194
  product,
1193
1195
  decision.limits.meterName || usageType,
1194
1196
  "fail",
1195
1197
  requestId,
1196
1198
  latencyMs
1197
- );
1199
+ ).catch(() => void 0);
1198
1200
  }
1199
1201
  throw error;
1200
1202
  }
package/dist/index.cjs CHANGED
@@ -99,7 +99,7 @@ function createSolvaPayClient(opts) {
99
99
  if (!res.ok) {
100
100
  const error = await res.text();
101
101
  log(`\u274C API Error: ${res.status} - ${error}`);
102
- throw new import_core.SolvaPayError(`Check limits failed (${res.status}): ${error}`);
102
+ throw new import_core.SolvaPayError(`Check limits failed (${res.status}): ${error}`, { status: res.status });
103
103
  }
104
104
  const result = await res.json();
105
105
  return result;
@@ -115,7 +115,7 @@ function createSolvaPayClient(opts) {
115
115
  if (!res.ok) {
116
116
  const error = await res.text();
117
117
  log(`\u274C API Error: ${res.status} - ${error}`);
118
- throw new import_core.SolvaPayError(`Track usage failed (${res.status}): ${error}`);
118
+ throw new import_core.SolvaPayError(`Track usage failed (${res.status}): ${error}`, { status: res.status });
119
119
  }
120
120
  },
121
121
  // POST: /v1/sdk/customers
@@ -129,7 +129,7 @@ function createSolvaPayClient(opts) {
129
129
  if (!res.ok) {
130
130
  const error = await res.text();
131
131
  log(`\u274C API Error: ${res.status} - ${error}`);
132
- throw new import_core.SolvaPayError(`Create customer failed (${res.status}): ${error}`);
132
+ throw new import_core.SolvaPayError(`Create customer failed (${res.status}): ${error}`, { status: res.status });
133
133
  }
134
134
  const result = await res.json();
135
135
  return {
@@ -147,7 +147,7 @@ function createSolvaPayClient(opts) {
147
147
  if (!res.ok) {
148
148
  const error = await res.text();
149
149
  log(`\u274C API Error: ${res.status} - ${error}`);
150
- throw new import_core.SolvaPayError(`Update customer failed (${res.status}): ${error}`);
150
+ throw new import_core.SolvaPayError(`Update customer failed (${res.status}): ${error}`, { status: res.status });
151
151
  }
152
152
  const result = await res.json();
153
153
  return {
@@ -177,7 +177,7 @@ function createSolvaPayClient(opts) {
177
177
  if (!res.ok) {
178
178
  const error = await res.text();
179
179
  log(`\u274C API Error: ${res.status} - ${error}`);
180
- throw new import_core.SolvaPayError(`Get customer failed (${res.status}): ${error}`);
180
+ throw new import_core.SolvaPayError(`Get customer failed (${res.status}): ${error}`, { status: res.status });
181
181
  }
182
182
  const result = await res.json();
183
183
  let customer = result;
@@ -208,7 +208,7 @@ function createSolvaPayClient(opts) {
208
208
  if (!res.ok) {
209
209
  const error = await res.text();
210
210
  log(`\u274C API Error: ${res.status} - ${error}`);
211
- throw new import_core.SolvaPayError(`Get merchant failed (${res.status}): ${error}`);
211
+ throw new import_core.SolvaPayError(`Get merchant failed (${res.status}): ${error}`, { status: res.status });
212
212
  }
213
213
  return res.json();
214
214
  },
@@ -222,7 +222,7 @@ function createSolvaPayClient(opts) {
222
222
  if (!res.ok) {
223
223
  const error = await res.text();
224
224
  log(`\u274C API Error: ${res.status} - ${error}`);
225
- throw new import_core.SolvaPayError(`Get platform config failed (${res.status}): ${error}`);
225
+ throw new import_core.SolvaPayError(`Get platform config failed (${res.status}): ${error}`, { status: res.status });
226
226
  }
227
227
  return res.json();
228
228
  },
@@ -236,7 +236,7 @@ function createSolvaPayClient(opts) {
236
236
  if (!res.ok) {
237
237
  const error = await res.text();
238
238
  log(`\u274C API Error: ${res.status} - ${error}`);
239
- throw new import_core.SolvaPayError(`Get product failed (${res.status}): ${error}`);
239
+ throw new import_core.SolvaPayError(`Get product failed (${res.status}): ${error}`, { status: res.status });
240
240
  }
241
241
  const result = await res.json();
242
242
  const data = result.data || {};
@@ -253,7 +253,7 @@ function createSolvaPayClient(opts) {
253
253
  if (!res.ok) {
254
254
  const error = await res.text();
255
255
  log(`\u274C API Error: ${res.status} - ${error}`);
256
- throw new import_core.SolvaPayError(`List products failed (${res.status}): ${error}`);
256
+ throw new import_core.SolvaPayError(`List products failed (${res.status}): ${error}`, { status: res.status });
257
257
  }
258
258
  const result = await res.json();
259
259
  const products = Array.isArray(result) ? result : result.products || [];
@@ -273,7 +273,7 @@ function createSolvaPayClient(opts) {
273
273
  if (!res.ok) {
274
274
  const error = await res.text();
275
275
  log(`\u274C API Error: ${res.status} - ${error}`);
276
- throw new import_core.SolvaPayError(`Create product failed (${res.status}): ${error}`);
276
+ throw new import_core.SolvaPayError(`Create product failed (${res.status}): ${error}`, { status: res.status });
277
277
  }
278
278
  const result = await res.json();
279
279
  return result;
@@ -289,7 +289,7 @@ function createSolvaPayClient(opts) {
289
289
  if (!res.ok) {
290
290
  const error = await res.text();
291
291
  log(`\u274C API Error: ${res.status} - ${error}`);
292
- throw new import_core.SolvaPayError(`Bootstrap MCP product failed (${res.status}): ${error}`);
292
+ throw new import_core.SolvaPayError(`Bootstrap MCP product failed (${res.status}): ${error}`, { status: res.status });
293
293
  }
294
294
  return await res.json();
295
295
  },
@@ -304,7 +304,7 @@ function createSolvaPayClient(opts) {
304
304
  if (!res.ok) {
305
305
  const error = await res.text();
306
306
  log(`\u274C API Error: ${res.status} - ${error}`);
307
- throw new import_core.SolvaPayError(`Configure MCP plans failed (${res.status}): ${error}`);
307
+ throw new import_core.SolvaPayError(`Configure MCP plans failed (${res.status}): ${error}`, { status: res.status });
308
308
  }
309
309
  return await res.json();
310
310
  },
@@ -318,7 +318,7 @@ function createSolvaPayClient(opts) {
318
318
  if (!res.ok && res.status !== 404) {
319
319
  const error = await res.text();
320
320
  log(`\u274C API Error: ${res.status} - ${error}`);
321
- throw new import_core.SolvaPayError(`Delete product failed (${res.status}): ${error}`);
321
+ throw new import_core.SolvaPayError(`Delete product failed (${res.status}): ${error}`, { status: res.status });
322
322
  }
323
323
  },
324
324
  // POST: /v1/sdk/products/{productRef}/clone
@@ -332,7 +332,7 @@ function createSolvaPayClient(opts) {
332
332
  if (!res.ok) {
333
333
  const error = await res.text();
334
334
  log(`\u274C API Error: ${res.status} - ${error}`);
335
- throw new import_core.SolvaPayError(`Clone product failed (${res.status}): ${error}`);
335
+ throw new import_core.SolvaPayError(`Clone product failed (${res.status}): ${error}`, { status: res.status });
336
336
  }
337
337
  return await res.json();
338
338
  },
@@ -346,7 +346,7 @@ function createSolvaPayClient(opts) {
346
346
  if (!res.ok) {
347
347
  const error = await res.text();
348
348
  log(`\u274C API Error: ${res.status} - ${error}`);
349
- throw new import_core.SolvaPayError(`List plans failed (${res.status}): ${error}`);
349
+ throw new import_core.SolvaPayError(`List plans failed (${res.status}): ${error}`, { status: res.status });
350
350
  }
351
351
  const result = await res.json();
352
352
  const plans = Array.isArray(result) ? result : result.plans || [];
@@ -373,7 +373,7 @@ function createSolvaPayClient(opts) {
373
373
  if (!res.ok) {
374
374
  const error = await res.text();
375
375
  log(`\u274C API Error: ${res.status} - ${error}`);
376
- throw new import_core.SolvaPayError(`Create plan failed (${res.status}): ${error}`);
376
+ throw new import_core.SolvaPayError(`Create plan failed (${res.status}): ${error}`, { status: res.status });
377
377
  }
378
378
  const result = await res.json();
379
379
  return result;
@@ -389,7 +389,7 @@ function createSolvaPayClient(opts) {
389
389
  if (!res.ok) {
390
390
  const error = await res.text();
391
391
  log(`\u274C API Error: ${res.status} - ${error}`);
392
- throw new import_core.SolvaPayError(`Update plan failed (${res.status}): ${error}`);
392
+ throw new import_core.SolvaPayError(`Update plan failed (${res.status}): ${error}`, { status: res.status });
393
393
  }
394
394
  return await res.json();
395
395
  },
@@ -403,7 +403,7 @@ function createSolvaPayClient(opts) {
403
403
  if (!res.ok && res.status !== 404) {
404
404
  const error = await res.text();
405
405
  log(`\u274C API Error: ${res.status} - ${error}`);
406
- throw new import_core.SolvaPayError(`Delete plan failed (${res.status}): ${error}`);
406
+ throw new import_core.SolvaPayError(`Delete plan failed (${res.status}): ${error}`, { status: res.status });
407
407
  }
408
408
  },
409
409
  // POST: /payment-intents
@@ -425,7 +425,7 @@ function createSolvaPayClient(opts) {
425
425
  if (!res.ok) {
426
426
  const error = await res.text();
427
427
  log(`\u274C API Error: ${res.status} - ${error}`);
428
- throw new import_core.SolvaPayError(`Create payment intent failed (${res.status}): ${error}`);
428
+ throw new import_core.SolvaPayError(`Create payment intent failed (${res.status}): ${error}`, { status: res.status });
429
429
  }
430
430
  return await res.json();
431
431
  },
@@ -450,7 +450,7 @@ function createSolvaPayClient(opts) {
450
450
  if (!res.ok) {
451
451
  const error = await res.text();
452
452
  log(`\u274C API Error: ${res.status} - ${error}`);
453
- throw new import_core.SolvaPayError(`Create topup payment intent failed (${res.status}): ${error}`);
453
+ throw new import_core.SolvaPayError(`Create topup payment intent failed (${res.status}): ${error}`, { status: res.status });
454
454
  }
455
455
  return await res.json();
456
456
  },
@@ -472,7 +472,7 @@ function createSolvaPayClient(opts) {
472
472
  if (!res.ok) {
473
473
  const error = await res.text();
474
474
  log(`\u274C API Error: ${res.status} - ${error}`);
475
- throw new import_core.SolvaPayError(`Process payment failed (${res.status}): ${error}`);
475
+ throw new import_core.SolvaPayError(`Process payment failed (${res.status}): ${error}`, { status: res.status });
476
476
  }
477
477
  const result = await res.json();
478
478
  return result;
@@ -492,14 +492,15 @@ function createSolvaPayClient(opts) {
492
492
  const error = await res.text();
493
493
  log(`\u274C API Error: ${res.status} - ${error}`);
494
494
  if (res.status === 404) {
495
- throw new import_core.SolvaPayError(`Purchase not found: ${error}`);
495
+ throw new import_core.SolvaPayError(`Purchase not found: ${error}`, { status: 404 });
496
496
  }
497
497
  if (res.status === 400) {
498
498
  throw new import_core.SolvaPayError(
499
- `Purchase cannot be cancelled or does not belong to provider: ${error}`
499
+ `Purchase cannot be cancelled or does not belong to provider: ${error}`,
500
+ { status: 400 }
500
501
  );
501
502
  }
502
- throw new import_core.SolvaPayError(`Cancel purchase failed (${res.status}): ${error}`);
503
+ throw new import_core.SolvaPayError(`Cancel purchase failed (${res.status}): ${error}`, { status: res.status });
503
504
  }
504
505
  const responseText = await res.text();
505
506
  let responseData;
@@ -540,14 +541,15 @@ function createSolvaPayClient(opts) {
540
541
  const error = await res.text();
541
542
  log(`\u274C API Error: ${res.status} - ${error}`);
542
543
  if (res.status === 404) {
543
- throw new import_core.SolvaPayError(`Purchase not found: ${error}`);
544
+ throw new import_core.SolvaPayError(`Purchase not found: ${error}`, { status: 404 });
544
545
  }
545
546
  if (res.status === 400) {
546
547
  throw new import_core.SolvaPayError(
547
- `Purchase cannot be reactivated: ${error}`
548
+ `Purchase cannot be reactivated: ${error}`,
549
+ { status: 400 }
548
550
  );
549
551
  }
550
- throw new import_core.SolvaPayError(`Reactivate purchase failed (${res.status}): ${error}`);
552
+ throw new import_core.SolvaPayError(`Reactivate purchase failed (${res.status}): ${error}`, { status: res.status });
551
553
  }
552
554
  const responseText = await res.text();
553
555
  let responseData;
@@ -588,7 +590,7 @@ function createSolvaPayClient(opts) {
588
590
  if (!res.ok) {
589
591
  const error = await res.text();
590
592
  log(`\u274C API Error: ${res.status} - ${error}`);
591
- throw new import_core.SolvaPayError(`Get user info failed (${res.status}): ${error}`);
593
+ throw new import_core.SolvaPayError(`Get user info failed (${res.status}): ${error}`, { status: res.status });
592
594
  }
593
595
  return await res.json();
594
596
  },
@@ -602,7 +604,7 @@ function createSolvaPayClient(opts) {
602
604
  if (!res.ok) {
603
605
  const error = await res.text();
604
606
  log(`\u274C API Error: ${res.status} - ${error}`);
605
- throw new import_core.SolvaPayError(`Get customer balance failed (${res.status}): ${error}`);
607
+ throw new import_core.SolvaPayError(`Get customer balance failed (${res.status}): ${error}`, { status: res.status });
606
608
  }
607
609
  return await res.json();
608
610
  },
@@ -617,7 +619,7 @@ function createSolvaPayClient(opts) {
617
619
  if (!res.ok) {
618
620
  const error = await res.text();
619
621
  log(`\u274C API Error: ${res.status} - ${error}`);
620
- throw new import_core.SolvaPayError(`Create checkout session failed (${res.status}): ${error}`);
622
+ throw new import_core.SolvaPayError(`Create checkout session failed (${res.status}): ${error}`, { status: res.status });
621
623
  }
622
624
  const result = await res.json();
623
625
  return result;
@@ -633,7 +635,7 @@ function createSolvaPayClient(opts) {
633
635
  if (!res.ok) {
634
636
  const error = await res.text();
635
637
  log(`\u274C API Error: ${res.status} - ${error}`);
636
- throw new import_core.SolvaPayError(`Create customer session failed (${res.status}): ${error}`);
638
+ throw new import_core.SolvaPayError(`Create customer session failed (${res.status}): ${error}`, { status: res.status });
637
639
  }
638
640
  const result = await res.json();
639
641
  return result;
@@ -649,7 +651,7 @@ function createSolvaPayClient(opts) {
649
651
  if (!res.ok) {
650
652
  const error = await res.text();
651
653
  log(`\u274C API Error: ${res.status} - ${error}`);
652
- throw new import_core.SolvaPayError(`Activate plan failed (${res.status}): ${error}`);
654
+ throw new import_core.SolvaPayError(`Activate plan failed (${res.status}): ${error}`, { status: res.status });
653
655
  }
654
656
  return await res.json();
655
657
  },
@@ -660,7 +662,7 @@ function createSolvaPayClient(opts) {
660
662
  if (!res.ok) {
661
663
  const error = await res.text();
662
664
  log(`\u274C API Error: ${res.status} - ${error}`);
663
- throw new import_core.SolvaPayError(`Get payment method failed (${res.status}): ${error}`);
665
+ throw new import_core.SolvaPayError(`Get payment method failed (${res.status}): ${error}`, { status: res.status });
664
666
  }
665
667
  return await res.json();
666
668
  }
@@ -1043,14 +1045,14 @@ var SolvaPayPaywall = class {
1043
1045
  }
1044
1046
  if (!withinLimits) {
1045
1047
  const latencyMs = Date.now() - startTime;
1046
- this.trackUsage(
1048
+ await this.trackUsage(
1047
1049
  backendCustomerRef,
1048
1050
  product,
1049
1051
  resolvedMeterName || usageType,
1050
1052
  "paywall",
1051
1053
  requestId,
1052
1054
  latencyMs
1053
- );
1055
+ ).catch(() => void 0);
1054
1056
  const gate = buildPaywallGate(
1055
1057
  product,
1056
1058
  lastLimitsCheck ?? {
@@ -1104,14 +1106,14 @@ var SolvaPayPaywall = class {
1104
1106
  try {
1105
1107
  const result = await handler(args, handlerContext);
1106
1108
  const latencyMs = Date.now() - startTime;
1107
- this.trackUsage(
1109
+ await this.trackUsage(
1108
1110
  decision.customerRef,
1109
1111
  product,
1110
1112
  decision.limits.meterName || usageType,
1111
1113
  "success",
1112
1114
  requestId,
1113
1115
  latencyMs
1114
- );
1116
+ ).catch(() => void 0);
1115
1117
  return result;
1116
1118
  } catch (error) {
1117
1119
  if (error instanceof Error) {
@@ -1122,14 +1124,14 @@ var SolvaPayPaywall = class {
1122
1124
  }
1123
1125
  if (!(error instanceof PaywallError)) {
1124
1126
  const latencyMs = Date.now() - startTime;
1125
- this.trackUsage(
1127
+ await this.trackUsage(
1126
1128
  decision.customerRef,
1127
1129
  product,
1128
1130
  decision.limits.meterName || usageType,
1129
1131
  "fail",
1130
1132
  requestId,
1131
1133
  latencyMs
1132
- );
1134
+ ).catch(() => void 0);
1133
1135
  }
1134
1136
  throw error;
1135
1137
  }
@@ -2150,7 +2152,7 @@ function handleRouteError(error, operationName, defaultMessage) {
2150
2152
  const errorMessage2 = error.message;
2151
2153
  return {
2152
2154
  error: errorMessage2,
2153
- status: 500,
2155
+ status: error.status ?? 500,
2154
2156
  details: errorMessage2
2155
2157
  };
2156
2158
  }