@solvapay/server 2.2.0 → 2.2.1-preview-7d806cc7af767dec26b099517bc6ededc85adf9a

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/edge.js CHANGED
@@ -3273,6 +3273,7 @@ async function checkPurchaseCore(request, options = {}) {
3273
3273
  }
3274
3274
 
3275
3275
  // src/helpers/usage.ts
3276
+ import { countsUsage } from "@solvapay/core";
3276
3277
  async function getUsageCore(request, options = {}) {
3277
3278
  const purchaseResult = await checkPurchaseCore(request, options);
3278
3279
  if (isErrorResult(purchaseResult)) return purchaseResult;
@@ -3292,8 +3293,8 @@ async function getUsageCore(request, options = {}) {
3292
3293
  ...usage?.periodStart ? { periodStart: usage.periodStart } : {},
3293
3294
  ...usage?.periodEnd ? { periodEnd: usage.periodEnd } : {}
3294
3295
  };
3295
- const isMetered = activePurchase.planSnapshot?.isMetered === true;
3296
- if (!isMetered || !activePurchase.productRef) {
3296
+ const usageCounted = countsUsage(activePurchase.planSnapshot) || activePurchase.planSnapshot?.isMetered === true;
3297
+ if (!usageCounted || !activePurchase.productRef) {
3297
3298
  return {
3298
3299
  meterRef: null,
3299
3300
  total: null,
@@ -3050,6 +3050,7 @@ async function checkPurchaseCore(request, options = {}) {
3050
3050
  }
3051
3051
 
3052
3052
  // src/helpers/usage.ts
3053
+ var import_core10 = require("@solvapay/core");
3053
3054
  async function trackUsageCore(request, body, options = {}) {
3054
3055
  try {
3055
3056
  const userResult = await getAuthenticatedUserCore(request);
@@ -3078,7 +3079,7 @@ async function trackUsageCore(request, body, options = {}) {
3078
3079
  }
3079
3080
 
3080
3081
  // src/edge.ts
3081
- var import_core10 = require("@solvapay/core");
3082
+ var import_core11 = require("@solvapay/core");
3082
3083
  function timingSafeEqual(a, b) {
3083
3084
  if (a.length !== b.length) return false;
3084
3085
  let mismatch = 0;
@@ -3093,22 +3094,22 @@ async function verifyWebhook({
3093
3094
  secret
3094
3095
  }) {
3095
3096
  const toleranceSec = 300;
3096
- if (!signature) throw new import_core10.SolvaPayError("Missing webhook signature");
3097
+ if (!signature) throw new import_core11.SolvaPayError("Missing webhook signature");
3097
3098
  const parts = signature.split(",");
3098
3099
  const tPart = parts.find((p) => p.startsWith("t="));
3099
3100
  const v1Part = parts.find((p) => p.startsWith("v1="));
3100
3101
  if (!tPart || !v1Part) {
3101
- throw new import_core10.SolvaPayError("Malformed webhook signature");
3102
+ throw new import_core11.SolvaPayError("Malformed webhook signature");
3102
3103
  }
3103
3104
  const timestamp = parseInt(tPart.slice(2), 10);
3104
3105
  const receivedHmac = v1Part.slice(3);
3105
3106
  if (Number.isNaN(timestamp) || !receivedHmac) {
3106
- throw new import_core10.SolvaPayError("Malformed webhook signature");
3107
+ throw new import_core11.SolvaPayError("Malformed webhook signature");
3107
3108
  }
3108
3109
  if (toleranceSec > 0) {
3109
3110
  const age = Math.abs(Math.floor(Date.now() / 1e3) - timestamp);
3110
3111
  if (age > toleranceSec) {
3111
- throw new import_core10.SolvaPayError("Webhook signature timestamp too old");
3112
+ throw new import_core11.SolvaPayError("Webhook signature timestamp too old");
3112
3113
  }
3113
3114
  }
3114
3115
  const enc = new TextEncoder();
@@ -3122,12 +3123,12 @@ async function verifyWebhook({
3122
3123
  const sigBuf = await crypto.subtle.sign("HMAC", key, enc.encode(`${timestamp}.${body}`));
3123
3124
  const expectedHmac = Array.from(new Uint8Array(sigBuf)).map((b) => b.toString(16).padStart(2, "0")).join("");
3124
3125
  if (!timingSafeEqual(expectedHmac, receivedHmac)) {
3125
- throw new import_core10.SolvaPayError("Invalid webhook signature");
3126
+ throw new import_core11.SolvaPayError("Invalid webhook signature");
3126
3127
  }
3127
3128
  try {
3128
3129
  return JSON.parse(body);
3129
3130
  } catch {
3130
- throw new import_core10.SolvaPayError("Invalid webhook payload: body is not valid JSON");
3131
+ throw new import_core11.SolvaPayError("Invalid webhook payload: body is not valid JSON");
3131
3132
  }
3132
3133
  }
3133
3134
 
@@ -2999,6 +2999,7 @@ async function checkPurchaseCore(request, options = {}) {
2999
2999
  }
3000
3000
 
3001
3001
  // src/helpers/usage.ts
3002
+ import { countsUsage } from "@solvapay/core";
3002
3003
  async function trackUsageCore(request, body, options = {}) {
3003
3004
  try {
3004
3005
  const userResult = await getAuthenticatedUserCore(request);
package/dist/index.cjs CHANGED
@@ -78,7 +78,7 @@ __export(index_exports, {
78
78
  });
79
79
  module.exports = __toCommonJS(index_exports);
80
80
  var import_node_crypto = __toESM(require("crypto"), 1);
81
- var import_core11 = require("@solvapay/core");
81
+ var import_core12 = require("@solvapay/core");
82
82
 
83
83
  // src/client.ts
84
84
  var import_core = require("@solvapay/core");
@@ -3351,6 +3351,7 @@ async function checkPurchaseCore(request, options = {}) {
3351
3351
  }
3352
3352
 
3353
3353
  // src/helpers/usage.ts
3354
+ var import_core11 = require("@solvapay/core");
3354
3355
  async function getUsageCore(request, options = {}) {
3355
3356
  const purchaseResult = await checkPurchaseCore(request, options);
3356
3357
  if (isErrorResult(purchaseResult)) return purchaseResult;
@@ -3370,8 +3371,8 @@ async function getUsageCore(request, options = {}) {
3370
3371
  ...usage?.periodStart ? { periodStart: usage.periodStart } : {},
3371
3372
  ...usage?.periodEnd ? { periodEnd: usage.periodEnd } : {}
3372
3373
  };
3373
- const isMetered = activePurchase.planSnapshot?.isMetered === true;
3374
- if (!isMetered || !activePurchase.productRef) {
3374
+ const usageCounted = (0, import_core11.countsUsage)(activePurchase.planSnapshot) || activePurchase.planSnapshot?.isMetered === true;
3375
+ if (!usageCounted || !activePurchase.productRef) {
3375
3376
  return {
3376
3377
  meterRef: null,
3377
3378
  total: null,
@@ -3435,34 +3436,34 @@ function verifyWebhook({
3435
3436
  secret
3436
3437
  }) {
3437
3438
  const toleranceSec = 300;
3438
- if (!signature) throw new import_core11.SolvaPayError("Missing webhook signature");
3439
+ if (!signature) throw new import_core12.SolvaPayError("Missing webhook signature");
3439
3440
  const parts = signature.split(",");
3440
3441
  const tPart = parts.find((p) => p.startsWith("t="));
3441
3442
  const v1Part = parts.find((p) => p.startsWith("v1="));
3442
3443
  if (!tPart || !v1Part) {
3443
- throw new import_core11.SolvaPayError("Malformed webhook signature");
3444
+ throw new import_core12.SolvaPayError("Malformed webhook signature");
3444
3445
  }
3445
3446
  const timestamp = parseInt(tPart.slice(2), 10);
3446
3447
  const receivedHmac = v1Part.slice(3);
3447
3448
  if (Number.isNaN(timestamp) || !receivedHmac) {
3448
- throw new import_core11.SolvaPayError("Malformed webhook signature");
3449
+ throw new import_core12.SolvaPayError("Malformed webhook signature");
3449
3450
  }
3450
3451
  if (toleranceSec > 0) {
3451
3452
  const age = Math.abs(Math.floor(Date.now() / 1e3) - timestamp);
3452
3453
  if (age > toleranceSec) {
3453
- throw new import_core11.SolvaPayError("Webhook signature timestamp too old");
3454
+ throw new import_core12.SolvaPayError("Webhook signature timestamp too old");
3454
3455
  }
3455
3456
  }
3456
3457
  const expectedHmac = import_node_crypto.default.createHmac("sha256", secret).update(`${timestamp}.${body}`).digest("hex");
3457
3458
  if (receivedHmac.length !== expectedHmac.length) {
3458
- throw new import_core11.SolvaPayError("Invalid webhook signature");
3459
+ throw new import_core12.SolvaPayError("Invalid webhook signature");
3459
3460
  }
3460
3461
  const ok = import_node_crypto.default.timingSafeEqual(Buffer.from(expectedHmac), Buffer.from(receivedHmac));
3461
- if (!ok) throw new import_core11.SolvaPayError("Invalid webhook signature");
3462
+ if (!ok) throw new import_core12.SolvaPayError("Invalid webhook signature");
3462
3463
  try {
3463
3464
  return JSON.parse(body);
3464
3465
  } catch {
3465
- throw new import_core11.SolvaPayError("Invalid webhook payload: body is not valid JSON");
3466
+ throw new import_core12.SolvaPayError("Invalid webhook payload: body is not valid JSON");
3466
3467
  }
3467
3468
  }
3468
3469
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.js CHANGED
@@ -3275,6 +3275,7 @@ async function checkPurchaseCore(request, options = {}) {
3275
3275
  }
3276
3276
 
3277
3277
  // src/helpers/usage.ts
3278
+ import { countsUsage } from "@solvapay/core";
3278
3279
  async function getUsageCore(request, options = {}) {
3279
3280
  const purchaseResult = await checkPurchaseCore(request, options);
3280
3281
  if (isErrorResult(purchaseResult)) return purchaseResult;
@@ -3294,8 +3295,8 @@ async function getUsageCore(request, options = {}) {
3294
3295
  ...usage?.periodStart ? { periodStart: usage.periodStart } : {},
3295
3296
  ...usage?.periodEnd ? { periodEnd: usage.periodEnd } : {}
3296
3297
  };
3297
- const isMetered = activePurchase.planSnapshot?.isMetered === true;
3298
- if (!isMetered || !activePurchase.productRef) {
3298
+ const usageCounted = countsUsage(activePurchase.planSnapshot) || activePurchase.planSnapshot?.isMetered === true;
3299
+ if (!usageCounted || !activePurchase.productRef) {
3299
3300
  return {
3300
3301
  meterRef: null,
3301
3302
  total: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solvapay/server",
3
- "version": "2.2.0",
3
+ "version": "2.2.1-preview-7d806cc7af767dec26b099517bc6ededc85adf9a",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "sideEffects": false,
44
44
  "dependencies": {
45
- "@solvapay/core": "1.4.0"
45
+ "@solvapay/core": "1.5.0-preview-7d806cc7af767dec26b099517bc6ededc85adf9a"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "zod": "^4.2.0",