@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/dist/index.js CHANGED
@@ -29,7 +29,7 @@ function createSolvaPayClient(opts) {
29
29
  if (!res.ok) {
30
30
  const error = await res.text();
31
31
  log(`\u274C API Error: ${res.status} - ${error}`);
32
- throw new SolvaPayError(`Check limits failed (${res.status}): ${error}`);
32
+ throw new SolvaPayError(`Check limits failed (${res.status}): ${error}`, { status: res.status });
33
33
  }
34
34
  const result = await res.json();
35
35
  return result;
@@ -45,7 +45,7 @@ function createSolvaPayClient(opts) {
45
45
  if (!res.ok) {
46
46
  const error = await res.text();
47
47
  log(`\u274C API Error: ${res.status} - ${error}`);
48
- throw new SolvaPayError(`Track usage failed (${res.status}): ${error}`);
48
+ throw new SolvaPayError(`Track usage failed (${res.status}): ${error}`, { status: res.status });
49
49
  }
50
50
  },
51
51
  // POST: /v1/sdk/customers
@@ -59,7 +59,7 @@ function createSolvaPayClient(opts) {
59
59
  if (!res.ok) {
60
60
  const error = await res.text();
61
61
  log(`\u274C API Error: ${res.status} - ${error}`);
62
- throw new SolvaPayError(`Create customer failed (${res.status}): ${error}`);
62
+ throw new SolvaPayError(`Create customer failed (${res.status}): ${error}`, { status: res.status });
63
63
  }
64
64
  const result = await res.json();
65
65
  return {
@@ -77,7 +77,7 @@ function createSolvaPayClient(opts) {
77
77
  if (!res.ok) {
78
78
  const error = await res.text();
79
79
  log(`\u274C API Error: ${res.status} - ${error}`);
80
- throw new SolvaPayError(`Update customer failed (${res.status}): ${error}`);
80
+ throw new SolvaPayError(`Update customer failed (${res.status}): ${error}`, { status: res.status });
81
81
  }
82
82
  const result = await res.json();
83
83
  return {
@@ -107,7 +107,7 @@ function createSolvaPayClient(opts) {
107
107
  if (!res.ok) {
108
108
  const error = await res.text();
109
109
  log(`\u274C API Error: ${res.status} - ${error}`);
110
- throw new SolvaPayError(`Get customer failed (${res.status}): ${error}`);
110
+ throw new SolvaPayError(`Get customer failed (${res.status}): ${error}`, { status: res.status });
111
111
  }
112
112
  const result = await res.json();
113
113
  let customer = result;
@@ -138,7 +138,7 @@ function createSolvaPayClient(opts) {
138
138
  if (!res.ok) {
139
139
  const error = await res.text();
140
140
  log(`\u274C API Error: ${res.status} - ${error}`);
141
- throw new SolvaPayError(`Get merchant failed (${res.status}): ${error}`);
141
+ throw new SolvaPayError(`Get merchant failed (${res.status}): ${error}`, { status: res.status });
142
142
  }
143
143
  return res.json();
144
144
  },
@@ -152,7 +152,7 @@ function createSolvaPayClient(opts) {
152
152
  if (!res.ok) {
153
153
  const error = await res.text();
154
154
  log(`\u274C API Error: ${res.status} - ${error}`);
155
- throw new SolvaPayError(`Get platform config failed (${res.status}): ${error}`);
155
+ throw new SolvaPayError(`Get platform config failed (${res.status}): ${error}`, { status: res.status });
156
156
  }
157
157
  return res.json();
158
158
  },
@@ -166,7 +166,7 @@ function createSolvaPayClient(opts) {
166
166
  if (!res.ok) {
167
167
  const error = await res.text();
168
168
  log(`\u274C API Error: ${res.status} - ${error}`);
169
- throw new SolvaPayError(`Get product failed (${res.status}): ${error}`);
169
+ throw new SolvaPayError(`Get product failed (${res.status}): ${error}`, { status: res.status });
170
170
  }
171
171
  const result = await res.json();
172
172
  const data = result.data || {};
@@ -183,7 +183,7 @@ function createSolvaPayClient(opts) {
183
183
  if (!res.ok) {
184
184
  const error = await res.text();
185
185
  log(`\u274C API Error: ${res.status} - ${error}`);
186
- throw new SolvaPayError(`List products failed (${res.status}): ${error}`);
186
+ throw new SolvaPayError(`List products failed (${res.status}): ${error}`, { status: res.status });
187
187
  }
188
188
  const result = await res.json();
189
189
  const products = Array.isArray(result) ? result : result.products || [];
@@ -203,7 +203,7 @@ function createSolvaPayClient(opts) {
203
203
  if (!res.ok) {
204
204
  const error = await res.text();
205
205
  log(`\u274C API Error: ${res.status} - ${error}`);
206
- throw new SolvaPayError(`Create product failed (${res.status}): ${error}`);
206
+ throw new SolvaPayError(`Create product failed (${res.status}): ${error}`, { status: res.status });
207
207
  }
208
208
  const result = await res.json();
209
209
  return result;
@@ -219,7 +219,7 @@ function createSolvaPayClient(opts) {
219
219
  if (!res.ok) {
220
220
  const error = await res.text();
221
221
  log(`\u274C API Error: ${res.status} - ${error}`);
222
- throw new SolvaPayError(`Bootstrap MCP product failed (${res.status}): ${error}`);
222
+ throw new SolvaPayError(`Bootstrap MCP product failed (${res.status}): ${error}`, { status: res.status });
223
223
  }
224
224
  return await res.json();
225
225
  },
@@ -234,7 +234,7 @@ function createSolvaPayClient(opts) {
234
234
  if (!res.ok) {
235
235
  const error = await res.text();
236
236
  log(`\u274C API Error: ${res.status} - ${error}`);
237
- throw new SolvaPayError(`Configure MCP plans failed (${res.status}): ${error}`);
237
+ throw new SolvaPayError(`Configure MCP plans failed (${res.status}): ${error}`, { status: res.status });
238
238
  }
239
239
  return await res.json();
240
240
  },
@@ -248,7 +248,7 @@ function createSolvaPayClient(opts) {
248
248
  if (!res.ok && res.status !== 404) {
249
249
  const error = await res.text();
250
250
  log(`\u274C API Error: ${res.status} - ${error}`);
251
- throw new SolvaPayError(`Delete product failed (${res.status}): ${error}`);
251
+ throw new SolvaPayError(`Delete product failed (${res.status}): ${error}`, { status: res.status });
252
252
  }
253
253
  },
254
254
  // POST: /v1/sdk/products/{productRef}/clone
@@ -262,7 +262,7 @@ function createSolvaPayClient(opts) {
262
262
  if (!res.ok) {
263
263
  const error = await res.text();
264
264
  log(`\u274C API Error: ${res.status} - ${error}`);
265
- throw new SolvaPayError(`Clone product failed (${res.status}): ${error}`);
265
+ throw new SolvaPayError(`Clone product failed (${res.status}): ${error}`, { status: res.status });
266
266
  }
267
267
  return await res.json();
268
268
  },
@@ -276,7 +276,7 @@ function createSolvaPayClient(opts) {
276
276
  if (!res.ok) {
277
277
  const error = await res.text();
278
278
  log(`\u274C API Error: ${res.status} - ${error}`);
279
- throw new SolvaPayError(`List plans failed (${res.status}): ${error}`);
279
+ throw new SolvaPayError(`List plans failed (${res.status}): ${error}`, { status: res.status });
280
280
  }
281
281
  const result = await res.json();
282
282
  const plans = Array.isArray(result) ? result : result.plans || [];
@@ -303,7 +303,7 @@ function createSolvaPayClient(opts) {
303
303
  if (!res.ok) {
304
304
  const error = await res.text();
305
305
  log(`\u274C API Error: ${res.status} - ${error}`);
306
- throw new SolvaPayError(`Create plan failed (${res.status}): ${error}`);
306
+ throw new SolvaPayError(`Create plan failed (${res.status}): ${error}`, { status: res.status });
307
307
  }
308
308
  const result = await res.json();
309
309
  return result;
@@ -319,7 +319,7 @@ function createSolvaPayClient(opts) {
319
319
  if (!res.ok) {
320
320
  const error = await res.text();
321
321
  log(`\u274C API Error: ${res.status} - ${error}`);
322
- throw new SolvaPayError(`Update plan failed (${res.status}): ${error}`);
322
+ throw new SolvaPayError(`Update plan failed (${res.status}): ${error}`, { status: res.status });
323
323
  }
324
324
  return await res.json();
325
325
  },
@@ -333,7 +333,7 @@ function createSolvaPayClient(opts) {
333
333
  if (!res.ok && res.status !== 404) {
334
334
  const error = await res.text();
335
335
  log(`\u274C API Error: ${res.status} - ${error}`);
336
- throw new SolvaPayError(`Delete plan failed (${res.status}): ${error}`);
336
+ throw new SolvaPayError(`Delete plan failed (${res.status}): ${error}`, { status: res.status });
337
337
  }
338
338
  },
339
339
  // POST: /payment-intents
@@ -355,7 +355,7 @@ function createSolvaPayClient(opts) {
355
355
  if (!res.ok) {
356
356
  const error = await res.text();
357
357
  log(`\u274C API Error: ${res.status} - ${error}`);
358
- throw new SolvaPayError(`Create payment intent failed (${res.status}): ${error}`);
358
+ throw new SolvaPayError(`Create payment intent failed (${res.status}): ${error}`, { status: res.status });
359
359
  }
360
360
  return await res.json();
361
361
  },
@@ -380,7 +380,7 @@ function createSolvaPayClient(opts) {
380
380
  if (!res.ok) {
381
381
  const error = await res.text();
382
382
  log(`\u274C API Error: ${res.status} - ${error}`);
383
- throw new SolvaPayError(`Create topup payment intent failed (${res.status}): ${error}`);
383
+ throw new SolvaPayError(`Create topup payment intent failed (${res.status}): ${error}`, { status: res.status });
384
384
  }
385
385
  return await res.json();
386
386
  },
@@ -402,7 +402,7 @@ function createSolvaPayClient(opts) {
402
402
  if (!res.ok) {
403
403
  const error = await res.text();
404
404
  log(`\u274C API Error: ${res.status} - ${error}`);
405
- throw new SolvaPayError(`Process payment failed (${res.status}): ${error}`);
405
+ throw new SolvaPayError(`Process payment failed (${res.status}): ${error}`, { status: res.status });
406
406
  }
407
407
  const result = await res.json();
408
408
  return result;
@@ -422,14 +422,15 @@ function createSolvaPayClient(opts) {
422
422
  const error = await res.text();
423
423
  log(`\u274C API Error: ${res.status} - ${error}`);
424
424
  if (res.status === 404) {
425
- throw new SolvaPayError(`Purchase not found: ${error}`);
425
+ throw new SolvaPayError(`Purchase not found: ${error}`, { status: 404 });
426
426
  }
427
427
  if (res.status === 400) {
428
428
  throw new SolvaPayError(
429
- `Purchase cannot be cancelled or does not belong to provider: ${error}`
429
+ `Purchase cannot be cancelled or does not belong to provider: ${error}`,
430
+ { status: 400 }
430
431
  );
431
432
  }
432
- throw new SolvaPayError(`Cancel purchase failed (${res.status}): ${error}`);
433
+ throw new SolvaPayError(`Cancel purchase failed (${res.status}): ${error}`, { status: res.status });
433
434
  }
434
435
  const responseText = await res.text();
435
436
  let responseData;
@@ -470,14 +471,15 @@ function createSolvaPayClient(opts) {
470
471
  const error = await res.text();
471
472
  log(`\u274C API Error: ${res.status} - ${error}`);
472
473
  if (res.status === 404) {
473
- throw new SolvaPayError(`Purchase not found: ${error}`);
474
+ throw new SolvaPayError(`Purchase not found: ${error}`, { status: 404 });
474
475
  }
475
476
  if (res.status === 400) {
476
477
  throw new SolvaPayError(
477
- `Purchase cannot be reactivated: ${error}`
478
+ `Purchase cannot be reactivated: ${error}`,
479
+ { status: 400 }
478
480
  );
479
481
  }
480
- throw new SolvaPayError(`Reactivate purchase failed (${res.status}): ${error}`);
482
+ throw new SolvaPayError(`Reactivate purchase failed (${res.status}): ${error}`, { status: res.status });
481
483
  }
482
484
  const responseText = await res.text();
483
485
  let responseData;
@@ -518,7 +520,7 @@ function createSolvaPayClient(opts) {
518
520
  if (!res.ok) {
519
521
  const error = await res.text();
520
522
  log(`\u274C API Error: ${res.status} - ${error}`);
521
- throw new SolvaPayError(`Get user info failed (${res.status}): ${error}`);
523
+ throw new SolvaPayError(`Get user info failed (${res.status}): ${error}`, { status: res.status });
522
524
  }
523
525
  return await res.json();
524
526
  },
@@ -532,7 +534,7 @@ function createSolvaPayClient(opts) {
532
534
  if (!res.ok) {
533
535
  const error = await res.text();
534
536
  log(`\u274C API Error: ${res.status} - ${error}`);
535
- throw new SolvaPayError(`Get customer balance failed (${res.status}): ${error}`);
537
+ throw new SolvaPayError(`Get customer balance failed (${res.status}): ${error}`, { status: res.status });
536
538
  }
537
539
  return await res.json();
538
540
  },
@@ -547,7 +549,7 @@ function createSolvaPayClient(opts) {
547
549
  if (!res.ok) {
548
550
  const error = await res.text();
549
551
  log(`\u274C API Error: ${res.status} - ${error}`);
550
- throw new SolvaPayError(`Create checkout session failed (${res.status}): ${error}`);
552
+ throw new SolvaPayError(`Create checkout session failed (${res.status}): ${error}`, { status: res.status });
551
553
  }
552
554
  const result = await res.json();
553
555
  return result;
@@ -563,7 +565,7 @@ function createSolvaPayClient(opts) {
563
565
  if (!res.ok) {
564
566
  const error = await res.text();
565
567
  log(`\u274C API Error: ${res.status} - ${error}`);
566
- throw new SolvaPayError(`Create customer session failed (${res.status}): ${error}`);
568
+ throw new SolvaPayError(`Create customer session failed (${res.status}): ${error}`, { status: res.status });
567
569
  }
568
570
  const result = await res.json();
569
571
  return result;
@@ -579,7 +581,7 @@ function createSolvaPayClient(opts) {
579
581
  if (!res.ok) {
580
582
  const error = await res.text();
581
583
  log(`\u274C API Error: ${res.status} - ${error}`);
582
- throw new SolvaPayError(`Activate plan failed (${res.status}): ${error}`);
584
+ throw new SolvaPayError(`Activate plan failed (${res.status}): ${error}`, { status: res.status });
583
585
  }
584
586
  return await res.json();
585
587
  },
@@ -590,7 +592,7 @@ function createSolvaPayClient(opts) {
590
592
  if (!res.ok) {
591
593
  const error = await res.text();
592
594
  log(`\u274C API Error: ${res.status} - ${error}`);
593
- throw new SolvaPayError(`Get payment method failed (${res.status}): ${error}`);
595
+ throw new SolvaPayError(`Get payment method failed (${res.status}): ${error}`, { status: res.status });
594
596
  }
595
597
  return await res.json();
596
598
  }
@@ -973,14 +975,14 @@ var SolvaPayPaywall = class {
973
975
  }
974
976
  if (!withinLimits) {
975
977
  const latencyMs = Date.now() - startTime;
976
- this.trackUsage(
978
+ await this.trackUsage(
977
979
  backendCustomerRef,
978
980
  product,
979
981
  resolvedMeterName || usageType,
980
982
  "paywall",
981
983
  requestId,
982
984
  latencyMs
983
- );
985
+ ).catch(() => void 0);
984
986
  const gate = buildPaywallGate(
985
987
  product,
986
988
  lastLimitsCheck ?? {
@@ -1034,14 +1036,14 @@ var SolvaPayPaywall = class {
1034
1036
  try {
1035
1037
  const result = await handler(args, handlerContext);
1036
1038
  const latencyMs = Date.now() - startTime;
1037
- this.trackUsage(
1039
+ await this.trackUsage(
1038
1040
  decision.customerRef,
1039
1041
  product,
1040
1042
  decision.limits.meterName || usageType,
1041
1043
  "success",
1042
1044
  requestId,
1043
1045
  latencyMs
1044
- );
1046
+ ).catch(() => void 0);
1045
1047
  return result;
1046
1048
  } catch (error) {
1047
1049
  if (error instanceof Error) {
@@ -1052,14 +1054,14 @@ var SolvaPayPaywall = class {
1052
1054
  }
1053
1055
  if (!(error instanceof PaywallError)) {
1054
1056
  const latencyMs = Date.now() - startTime;
1055
- this.trackUsage(
1057
+ await this.trackUsage(
1056
1058
  decision.customerRef,
1057
1059
  product,
1058
1060
  decision.limits.meterName || usageType,
1059
1061
  "fail",
1060
1062
  requestId,
1061
1063
  latencyMs
1062
- );
1064
+ ).catch(() => void 0);
1063
1065
  }
1064
1066
  throw error;
1065
1067
  }
@@ -2080,7 +2082,7 @@ function handleRouteError(error, operationName, defaultMessage) {
2080
2082
  const errorMessage2 = error.message;
2081
2083
  return {
2082
2084
  error: errorMessage2,
2083
- status: 500,
2085
+ status: error.status ?? 500,
2084
2086
  details: errorMessage2
2085
2087
  };
2086
2088
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solvapay/server",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -62,8 +62,8 @@
62
62
  "typescript": "^5.9.3",
63
63
  "vitest": "^4.1.2",
64
64
  "zod": "^4.3.6",
65
- "@solvapay/demo-services": "0.0.0",
66
65
  "@solvapay/auth": "1.0.8",
66
+ "@solvapay/demo-services": "0.0.0",
67
67
  "@solvapay/test-utils": "^0.0.0"
68
68
  },
69
69
  "scripts": {