@solvapay/server 2.9.0 → 2.10.0-preview-01847ff5f57eafaa4bca393519caeaf6856d968c

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.d.ts CHANGED
@@ -1782,8 +1782,20 @@ interface components {
1782
1782
  * @example active
1783
1783
  */
1784
1784
  status: string;
1785
- /** @description Usage billing state for usage-based plans */
1786
- usage?: components['schemas']['UsageBillingDto'];
1785
+ /** @description Billing period of the active usage window; counts come from `/v1/sdk/limits` */
1786
+ usage?: components['schemas']['SdkUsagePeriodDto'];
1787
+ };
1788
+ SdkUsagePeriodDto: {
1789
+ /**
1790
+ * Billing period of the active usage window; counts come from `/v1/sdk/limits`
1791
+ * @example 2025-11-01T00:00:00Z
1792
+ */
1793
+ periodEnd?: string;
1794
+ /**
1795
+ * Billing period of the active usage window; counts come from `/v1/sdk/limits`
1796
+ * @example 2025-10-01T00:00:00Z
1797
+ */
1798
+ periodStart?: string;
1787
1799
  };
1788
1800
  TaxBreakdownDto: {
1789
1801
  /** @description ISO 4217 currency code */
@@ -1931,33 +1943,6 @@ interface components {
1931
1943
  /** @enum {string} */
1932
1944
  taxBehavior?: 'auto' | 'inclusive' | 'exclusive';
1933
1945
  };
1934
- UsageBillingDto: {
1935
- /**
1936
- * Overage cost in cents
1937
- * @example 0
1938
- */
1939
- overageCost: number;
1940
- /**
1941
- * Units exceeding the plan included amount
1942
- * @example 0
1943
- */
1944
- overageUnits: number;
1945
- /**
1946
- * Period end date
1947
- * @example 2025-11-01T00:00:00Z
1948
- */
1949
- periodEnd?: string;
1950
- /**
1951
- * Period start date
1952
- * @example 2025-10-01T00:00:00Z
1953
- */
1954
- periodStart?: string;
1955
- /**
1956
- * Units consumed in current period
1957
- * @example 150
1958
- */
1959
- used: number;
1960
- };
1961
1946
  UsageRecordResponse: {
1962
1947
  creditDebit?: components['schemas']['CreditDebitSuccessResponse'] | components['schemas']['CreditDebitSkippedResponse'];
1963
1948
  /** @example usage_A1B2C3D4 */
@@ -6316,7 +6301,13 @@ declare function checkPurchaseCore(request: Request, options?: {
6316
6301
  interface GetUsageResult {
6317
6302
  meterRef: string | null;
6318
6303
  total: number | null;
6319
- used: number;
6304
+ /**
6305
+ * Consumed units this period. `limits.used` when the backend measured a
6306
+ * finite cap, otherwise `total - remaining` when both are finite.
6307
+ * `null` means this response did not measure consumption (`limits` null,
6308
+ * unlimited, or credit-based).
6309
+ */
6310
+ used: number | null;
6320
6311
  remaining: number | null;
6321
6312
  /** 0–100, rounded to 2dp. `null` when `total` is unknown. */
6322
6313
  percentUsed: number | null;
@@ -6344,7 +6335,6 @@ interface UsageLimitsInput {
6344
6335
  * `remaining === -1` on a real limits object.
6345
6336
  */
6346
6337
  declare function deriveUsageSnapshot(input: {
6347
- used: number;
6348
6338
  periodStart?: string;
6349
6339
  periodEnd?: string;
6350
6340
  purchaseRef?: string;
@@ -6353,10 +6343,9 @@ declare function deriveUsageSnapshot(input: {
6353
6343
  /**
6354
6344
  * Fetch the authenticated customer's usage snapshot for the active purchase.
6355
6345
  *
6356
- * Consumption (`used`, period window) comes from `checkPurchaseCore`. The cap
6357
- * (`total`, `remaining`, `meterRef`) comes from `checkLimits` — the plan
6358
- * snapshot no longer carries `limit` or `meterRef` on the wire, so a metered
6359
- * plan costs one extra backend call unless the caller already has a
6346
+ * The period window and `purchaseRef` come from the active purchase. Consumption
6347
+ * and the cap (`used`, `total`, `remaining`, `meterRef`) come from `checkLimits`.
6348
+ * A metered plan costs one extra backend call unless the caller already has a
6360
6349
  * `LimitResponse` (`options.limits`).
6361
6350
  *
6362
6351
  * Pass `limits` (including `null` for a failed fetch) to skip the
package/dist/edge.js CHANGED
@@ -3600,7 +3600,7 @@ function deriveUsageSnapshot(input) {
3600
3600
  return {
3601
3601
  meterRef: null,
3602
3602
  total: null,
3603
- used: input.used,
3603
+ used: null,
3604
3604
  remaining: null,
3605
3605
  percentUsed: null,
3606
3606
  ...period,
@@ -3610,8 +3610,8 @@ function deriveUsageSnapshot(input) {
3610
3610
  const hasFiniteCap = input.limits.remaining >= 0;
3611
3611
  const remaining = hasFiniteCap ? input.limits.remaining : null;
3612
3612
  const total = typeof input.limits.limit === "number" && input.limits.limit > 0 ? input.limits.limit : null;
3613
- const used = typeof input.limits.used === "number" ? input.limits.used : total !== null && remaining !== null ? Math.max(0, total - remaining) : input.used;
3614
- const percentUsed = total !== null && total > 0 ? Math.min(100, Math.round(used / total * 1e4) / 100) : null;
3613
+ const used = typeof input.limits.used === "number" ? input.limits.used : total !== null && remaining !== null ? Math.max(0, total - remaining) : null;
3614
+ const percentUsed = total !== null && total > 0 && used !== null ? Math.min(100, Math.round(used / total * 1e4) / 100) : null;
3615
3615
  return {
3616
3616
  meterRef: input.limits.meterName ?? null,
3617
3617
  total,
@@ -3627,28 +3627,27 @@ async function getUsageCore(request, options = {}) {
3627
3627
  if (isErrorResult(purchaseResult)) return purchaseResult;
3628
3628
  const activePurchase = (purchaseResult.purchases ?? []).find((p) => p.status === "active");
3629
3629
  if (!activePurchase) {
3630
- return deriveUsageSnapshot({ used: 0, limits: options.limits ?? null });
3630
+ return deriveUsageSnapshot({ limits: options.limits ?? null });
3631
3631
  }
3632
3632
  const usage = activePurchase.usage;
3633
- const used = typeof usage?.used === "number" ? usage.used : 0;
3634
3633
  const period = {
3635
3634
  periodStart: usage?.periodStart,
3636
3635
  periodEnd: usage?.periodEnd,
3637
3636
  purchaseRef: activePurchase.reference
3638
3637
  };
3639
3638
  if ("limits" in options) {
3640
- return deriveUsageSnapshot({ used, ...period, limits: options.limits ?? null });
3639
+ return deriveUsageSnapshot({ ...period, limits: options.limits ?? null });
3641
3640
  }
3642
3641
  const usageCounted = countsUsage(activePurchase.planSnapshot) || activePurchase.planSnapshot?.isMetered === true;
3643
3642
  if (!usageCounted || !activePurchase.productRef) {
3644
- return deriveUsageSnapshot({ used, ...period, limits: null });
3643
+ return deriveUsageSnapshot({ ...period, limits: null });
3645
3644
  }
3646
3645
  const solvaPay = options.solvaPay || createSolvaPay();
3647
3646
  const limits = await solvaPay.apiClient.checkLimits({
3648
3647
  customerRef: purchaseResult.customerRef,
3649
3648
  productRef: activePurchase.productRef
3650
3649
  });
3651
- return deriveUsageSnapshot({ used, ...period, limits });
3650
+ return deriveUsageSnapshot({ ...period, limits });
3652
3651
  }
3653
3652
  async function trackUsageCore(request, body, options = {}) {
3654
3653
  try {
@@ -1779,8 +1779,20 @@ interface components {
1779
1779
  * @example active
1780
1780
  */
1781
1781
  status: string;
1782
- /** @description Usage billing state for usage-based plans */
1783
- usage?: components['schemas']['UsageBillingDto'];
1782
+ /** @description Billing period of the active usage window; counts come from `/v1/sdk/limits` */
1783
+ usage?: components['schemas']['SdkUsagePeriodDto'];
1784
+ };
1785
+ SdkUsagePeriodDto: {
1786
+ /**
1787
+ * Billing period of the active usage window; counts come from `/v1/sdk/limits`
1788
+ * @example 2025-11-01T00:00:00Z
1789
+ */
1790
+ periodEnd?: string;
1791
+ /**
1792
+ * Billing period of the active usage window; counts come from `/v1/sdk/limits`
1793
+ * @example 2025-10-01T00:00:00Z
1794
+ */
1795
+ periodStart?: string;
1784
1796
  };
1785
1797
  TaxBreakdownDto: {
1786
1798
  /** @description ISO 4217 currency code */
@@ -1928,33 +1940,6 @@ interface components {
1928
1940
  /** @enum {string} */
1929
1941
  taxBehavior?: 'auto' | 'inclusive' | 'exclusive';
1930
1942
  };
1931
- UsageBillingDto: {
1932
- /**
1933
- * Overage cost in cents
1934
- * @example 0
1935
- */
1936
- overageCost: number;
1937
- /**
1938
- * Units exceeding the plan included amount
1939
- * @example 0
1940
- */
1941
- overageUnits: number;
1942
- /**
1943
- * Period end date
1944
- * @example 2025-11-01T00:00:00Z
1945
- */
1946
- periodEnd?: string;
1947
- /**
1948
- * Period start date
1949
- * @example 2025-10-01T00:00:00Z
1950
- */
1951
- periodStart?: string;
1952
- /**
1953
- * Units consumed in current period
1954
- * @example 150
1955
- */
1956
- used: number;
1957
- };
1958
1943
  UsageRecordResponse: {
1959
1944
  creditDebit?: components['schemas']['CreditDebitSuccessResponse'] | components['schemas']['CreditDebitSkippedResponse'];
1960
1945
  /** @example usage_A1B2C3D4 */
@@ -1779,8 +1779,20 @@ interface components {
1779
1779
  * @example active
1780
1780
  */
1781
1781
  status: string;
1782
- /** @description Usage billing state for usage-based plans */
1783
- usage?: components['schemas']['UsageBillingDto'];
1782
+ /** @description Billing period of the active usage window; counts come from `/v1/sdk/limits` */
1783
+ usage?: components['schemas']['SdkUsagePeriodDto'];
1784
+ };
1785
+ SdkUsagePeriodDto: {
1786
+ /**
1787
+ * Billing period of the active usage window; counts come from `/v1/sdk/limits`
1788
+ * @example 2025-11-01T00:00:00Z
1789
+ */
1790
+ periodEnd?: string;
1791
+ /**
1792
+ * Billing period of the active usage window; counts come from `/v1/sdk/limits`
1793
+ * @example 2025-10-01T00:00:00Z
1794
+ */
1795
+ periodStart?: string;
1784
1796
  };
1785
1797
  TaxBreakdownDto: {
1786
1798
  /** @description ISO 4217 currency code */
@@ -1928,33 +1940,6 @@ interface components {
1928
1940
  /** @enum {string} */
1929
1941
  taxBehavior?: 'auto' | 'inclusive' | 'exclusive';
1930
1942
  };
1931
- UsageBillingDto: {
1932
- /**
1933
- * Overage cost in cents
1934
- * @example 0
1935
- */
1936
- overageCost: number;
1937
- /**
1938
- * Units exceeding the plan included amount
1939
- * @example 0
1940
- */
1941
- overageUnits: number;
1942
- /**
1943
- * Period end date
1944
- * @example 2025-11-01T00:00:00Z
1945
- */
1946
- periodEnd?: string;
1947
- /**
1948
- * Period start date
1949
- * @example 2025-10-01T00:00:00Z
1950
- */
1951
- periodStart?: string;
1952
- /**
1953
- * Units consumed in current period
1954
- * @example 150
1955
- */
1956
- used: number;
1957
- };
1958
1943
  UsageRecordResponse: {
1959
1944
  creditDebit?: components['schemas']['CreditDebitSuccessResponse'] | components['schemas']['CreditDebitSkippedResponse'];
1960
1945
  /** @example usage_A1B2C3D4 */
package/dist/index.cjs CHANGED
@@ -3685,7 +3685,7 @@ function deriveUsageSnapshot(input) {
3685
3685
  return {
3686
3686
  meterRef: null,
3687
3687
  total: null,
3688
- used: input.used,
3688
+ used: null,
3689
3689
  remaining: null,
3690
3690
  percentUsed: null,
3691
3691
  ...period,
@@ -3695,8 +3695,8 @@ function deriveUsageSnapshot(input) {
3695
3695
  const hasFiniteCap = input.limits.remaining >= 0;
3696
3696
  const remaining = hasFiniteCap ? input.limits.remaining : null;
3697
3697
  const total = typeof input.limits.limit === "number" && input.limits.limit > 0 ? input.limits.limit : null;
3698
- const used = typeof input.limits.used === "number" ? input.limits.used : total !== null && remaining !== null ? Math.max(0, total - remaining) : input.used;
3699
- const percentUsed = total !== null && total > 0 ? Math.min(100, Math.round(used / total * 1e4) / 100) : null;
3698
+ const used = typeof input.limits.used === "number" ? input.limits.used : total !== null && remaining !== null ? Math.max(0, total - remaining) : null;
3699
+ const percentUsed = total !== null && total > 0 && used !== null ? Math.min(100, Math.round(used / total * 1e4) / 100) : null;
3700
3700
  return {
3701
3701
  meterRef: input.limits.meterName ?? null,
3702
3702
  total,
@@ -3712,28 +3712,27 @@ async function getUsageCore(request, options = {}) {
3712
3712
  if (isErrorResult(purchaseResult)) return purchaseResult;
3713
3713
  const activePurchase = (purchaseResult.purchases ?? []).find((p) => p.status === "active");
3714
3714
  if (!activePurchase) {
3715
- return deriveUsageSnapshot({ used: 0, limits: options.limits ?? null });
3715
+ return deriveUsageSnapshot({ limits: options.limits ?? null });
3716
3716
  }
3717
3717
  const usage = activePurchase.usage;
3718
- const used = typeof usage?.used === "number" ? usage.used : 0;
3719
3718
  const period = {
3720
3719
  periodStart: usage?.periodStart,
3721
3720
  periodEnd: usage?.periodEnd,
3722
3721
  purchaseRef: activePurchase.reference
3723
3722
  };
3724
3723
  if ("limits" in options) {
3725
- return deriveUsageSnapshot({ used, ...period, limits: options.limits ?? null });
3724
+ return deriveUsageSnapshot({ ...period, limits: options.limits ?? null });
3726
3725
  }
3727
3726
  const usageCounted = (0, import_core13.countsUsage)(activePurchase.planSnapshot) || activePurchase.planSnapshot?.isMetered === true;
3728
3727
  if (!usageCounted || !activePurchase.productRef) {
3729
- return deriveUsageSnapshot({ used, ...period, limits: null });
3728
+ return deriveUsageSnapshot({ ...period, limits: null });
3730
3729
  }
3731
3730
  const solvaPay = options.solvaPay || createSolvaPay();
3732
3731
  const limits = await solvaPay.apiClient.checkLimits({
3733
3732
  customerRef: purchaseResult.customerRef,
3734
3733
  productRef: activePurchase.productRef
3735
3734
  });
3736
- return deriveUsageSnapshot({ used, ...period, limits });
3735
+ return deriveUsageSnapshot({ ...period, limits });
3737
3736
  }
3738
3737
  async function trackUsageCore(request, body, options = {}) {
3739
3738
  try {
package/dist/index.d.cts CHANGED
@@ -1782,8 +1782,20 @@ interface components {
1782
1782
  * @example active
1783
1783
  */
1784
1784
  status: string;
1785
- /** @description Usage billing state for usage-based plans */
1786
- usage?: components['schemas']['UsageBillingDto'];
1785
+ /** @description Billing period of the active usage window; counts come from `/v1/sdk/limits` */
1786
+ usage?: components['schemas']['SdkUsagePeriodDto'];
1787
+ };
1788
+ SdkUsagePeriodDto: {
1789
+ /**
1790
+ * Billing period of the active usage window; counts come from `/v1/sdk/limits`
1791
+ * @example 2025-11-01T00:00:00Z
1792
+ */
1793
+ periodEnd?: string;
1794
+ /**
1795
+ * Billing period of the active usage window; counts come from `/v1/sdk/limits`
1796
+ * @example 2025-10-01T00:00:00Z
1797
+ */
1798
+ periodStart?: string;
1787
1799
  };
1788
1800
  TaxBreakdownDto: {
1789
1801
  /** @description ISO 4217 currency code */
@@ -1931,33 +1943,6 @@ interface components {
1931
1943
  /** @enum {string} */
1932
1944
  taxBehavior?: 'auto' | 'inclusive' | 'exclusive';
1933
1945
  };
1934
- UsageBillingDto: {
1935
- /**
1936
- * Overage cost in cents
1937
- * @example 0
1938
- */
1939
- overageCost: number;
1940
- /**
1941
- * Units exceeding the plan included amount
1942
- * @example 0
1943
- */
1944
- overageUnits: number;
1945
- /**
1946
- * Period end date
1947
- * @example 2025-11-01T00:00:00Z
1948
- */
1949
- periodEnd?: string;
1950
- /**
1951
- * Period start date
1952
- * @example 2025-10-01T00:00:00Z
1953
- */
1954
- periodStart?: string;
1955
- /**
1956
- * Units consumed in current period
1957
- * @example 150
1958
- */
1959
- used: number;
1960
- };
1961
1946
  UsageRecordResponse: {
1962
1947
  creditDebit?: components['schemas']['CreditDebitSuccessResponse'] | components['schemas']['CreditDebitSkippedResponse'];
1963
1948
  /** @example usage_A1B2C3D4 */
@@ -6381,7 +6366,13 @@ declare function checkPurchaseCore(request: Request, options?: {
6381
6366
  interface GetUsageResult {
6382
6367
  meterRef: string | null;
6383
6368
  total: number | null;
6384
- used: number;
6369
+ /**
6370
+ * Consumed units this period. `limits.used` when the backend measured a
6371
+ * finite cap, otherwise `total - remaining` when both are finite.
6372
+ * `null` means this response did not measure consumption (`limits` null,
6373
+ * unlimited, or credit-based).
6374
+ */
6375
+ used: number | null;
6385
6376
  remaining: number | null;
6386
6377
  /** 0–100, rounded to 2dp. `null` when `total` is unknown. */
6387
6378
  percentUsed: number | null;
@@ -6409,7 +6400,6 @@ interface UsageLimitsInput {
6409
6400
  * `remaining === -1` on a real limits object.
6410
6401
  */
6411
6402
  declare function deriveUsageSnapshot(input: {
6412
- used: number;
6413
6403
  periodStart?: string;
6414
6404
  periodEnd?: string;
6415
6405
  purchaseRef?: string;
@@ -6418,10 +6408,9 @@ declare function deriveUsageSnapshot(input: {
6418
6408
  /**
6419
6409
  * Fetch the authenticated customer's usage snapshot for the active purchase.
6420
6410
  *
6421
- * Consumption (`used`, period window) comes from `checkPurchaseCore`. The cap
6422
- * (`total`, `remaining`, `meterRef`) comes from `checkLimits` — the plan
6423
- * snapshot no longer carries `limit` or `meterRef` on the wire, so a metered
6424
- * plan costs one extra backend call unless the caller already has a
6411
+ * The period window and `purchaseRef` come from the active purchase. Consumption
6412
+ * and the cap (`used`, `total`, `remaining`, `meterRef`) come from `checkLimits`.
6413
+ * A metered plan costs one extra backend call unless the caller already has a
6425
6414
  * `LimitResponse` (`options.limits`).
6426
6415
  *
6427
6416
  * Pass `limits` (including `null` for a failed fetch) to skip the
package/dist/index.d.ts CHANGED
@@ -1782,8 +1782,20 @@ interface components {
1782
1782
  * @example active
1783
1783
  */
1784
1784
  status: string;
1785
- /** @description Usage billing state for usage-based plans */
1786
- usage?: components['schemas']['UsageBillingDto'];
1785
+ /** @description Billing period of the active usage window; counts come from `/v1/sdk/limits` */
1786
+ usage?: components['schemas']['SdkUsagePeriodDto'];
1787
+ };
1788
+ SdkUsagePeriodDto: {
1789
+ /**
1790
+ * Billing period of the active usage window; counts come from `/v1/sdk/limits`
1791
+ * @example 2025-11-01T00:00:00Z
1792
+ */
1793
+ periodEnd?: string;
1794
+ /**
1795
+ * Billing period of the active usage window; counts come from `/v1/sdk/limits`
1796
+ * @example 2025-10-01T00:00:00Z
1797
+ */
1798
+ periodStart?: string;
1787
1799
  };
1788
1800
  TaxBreakdownDto: {
1789
1801
  /** @description ISO 4217 currency code */
@@ -1931,33 +1943,6 @@ interface components {
1931
1943
  /** @enum {string} */
1932
1944
  taxBehavior?: 'auto' | 'inclusive' | 'exclusive';
1933
1945
  };
1934
- UsageBillingDto: {
1935
- /**
1936
- * Overage cost in cents
1937
- * @example 0
1938
- */
1939
- overageCost: number;
1940
- /**
1941
- * Units exceeding the plan included amount
1942
- * @example 0
1943
- */
1944
- overageUnits: number;
1945
- /**
1946
- * Period end date
1947
- * @example 2025-11-01T00:00:00Z
1948
- */
1949
- periodEnd?: string;
1950
- /**
1951
- * Period start date
1952
- * @example 2025-10-01T00:00:00Z
1953
- */
1954
- periodStart?: string;
1955
- /**
1956
- * Units consumed in current period
1957
- * @example 150
1958
- */
1959
- used: number;
1960
- };
1961
1946
  UsageRecordResponse: {
1962
1947
  creditDebit?: components['schemas']['CreditDebitSuccessResponse'] | components['schemas']['CreditDebitSkippedResponse'];
1963
1948
  /** @example usage_A1B2C3D4 */
@@ -6381,7 +6366,13 @@ declare function checkPurchaseCore(request: Request, options?: {
6381
6366
  interface GetUsageResult {
6382
6367
  meterRef: string | null;
6383
6368
  total: number | null;
6384
- used: number;
6369
+ /**
6370
+ * Consumed units this period. `limits.used` when the backend measured a
6371
+ * finite cap, otherwise `total - remaining` when both are finite.
6372
+ * `null` means this response did not measure consumption (`limits` null,
6373
+ * unlimited, or credit-based).
6374
+ */
6375
+ used: number | null;
6385
6376
  remaining: number | null;
6386
6377
  /** 0–100, rounded to 2dp. `null` when `total` is unknown. */
6387
6378
  percentUsed: number | null;
@@ -6409,7 +6400,6 @@ interface UsageLimitsInput {
6409
6400
  * `remaining === -1` on a real limits object.
6410
6401
  */
6411
6402
  declare function deriveUsageSnapshot(input: {
6412
- used: number;
6413
6403
  periodStart?: string;
6414
6404
  periodEnd?: string;
6415
6405
  purchaseRef?: string;
@@ -6418,10 +6408,9 @@ declare function deriveUsageSnapshot(input: {
6418
6408
  /**
6419
6409
  * Fetch the authenticated customer's usage snapshot for the active purchase.
6420
6410
  *
6421
- * Consumption (`used`, period window) comes from `checkPurchaseCore`. The cap
6422
- * (`total`, `remaining`, `meterRef`) comes from `checkLimits` — the plan
6423
- * snapshot no longer carries `limit` or `meterRef` on the wire, so a metered
6424
- * plan costs one extra backend call unless the caller already has a
6411
+ * The period window and `purchaseRef` come from the active purchase. Consumption
6412
+ * and the cap (`used`, `total`, `remaining`, `meterRef`) come from `checkLimits`.
6413
+ * A metered plan costs one extra backend call unless the caller already has a
6425
6414
  * `LimitResponse` (`options.limits`).
6426
6415
  *
6427
6416
  * Pass `limits` (including `null` for a failed fetch) to skip the
package/dist/index.js CHANGED
@@ -3602,7 +3602,7 @@ function deriveUsageSnapshot(input) {
3602
3602
  return {
3603
3603
  meterRef: null,
3604
3604
  total: null,
3605
- used: input.used,
3605
+ used: null,
3606
3606
  remaining: null,
3607
3607
  percentUsed: null,
3608
3608
  ...period,
@@ -3612,8 +3612,8 @@ function deriveUsageSnapshot(input) {
3612
3612
  const hasFiniteCap = input.limits.remaining >= 0;
3613
3613
  const remaining = hasFiniteCap ? input.limits.remaining : null;
3614
3614
  const total = typeof input.limits.limit === "number" && input.limits.limit > 0 ? input.limits.limit : null;
3615
- const used = typeof input.limits.used === "number" ? input.limits.used : total !== null && remaining !== null ? Math.max(0, total - remaining) : input.used;
3616
- const percentUsed = total !== null && total > 0 ? Math.min(100, Math.round(used / total * 1e4) / 100) : null;
3615
+ const used = typeof input.limits.used === "number" ? input.limits.used : total !== null && remaining !== null ? Math.max(0, total - remaining) : null;
3616
+ const percentUsed = total !== null && total > 0 && used !== null ? Math.min(100, Math.round(used / total * 1e4) / 100) : null;
3617
3617
  return {
3618
3618
  meterRef: input.limits.meterName ?? null,
3619
3619
  total,
@@ -3629,28 +3629,27 @@ async function getUsageCore(request, options = {}) {
3629
3629
  if (isErrorResult(purchaseResult)) return purchaseResult;
3630
3630
  const activePurchase = (purchaseResult.purchases ?? []).find((p) => p.status === "active");
3631
3631
  if (!activePurchase) {
3632
- return deriveUsageSnapshot({ used: 0, limits: options.limits ?? null });
3632
+ return deriveUsageSnapshot({ limits: options.limits ?? null });
3633
3633
  }
3634
3634
  const usage = activePurchase.usage;
3635
- const used = typeof usage?.used === "number" ? usage.used : 0;
3636
3635
  const period = {
3637
3636
  periodStart: usage?.periodStart,
3638
3637
  periodEnd: usage?.periodEnd,
3639
3638
  purchaseRef: activePurchase.reference
3640
3639
  };
3641
3640
  if ("limits" in options) {
3642
- return deriveUsageSnapshot({ used, ...period, limits: options.limits ?? null });
3641
+ return deriveUsageSnapshot({ ...period, limits: options.limits ?? null });
3643
3642
  }
3644
3643
  const usageCounted = countsUsage(activePurchase.planSnapshot) || activePurchase.planSnapshot?.isMetered === true;
3645
3644
  if (!usageCounted || !activePurchase.productRef) {
3646
- return deriveUsageSnapshot({ used, ...period, limits: null });
3645
+ return deriveUsageSnapshot({ ...period, limits: null });
3647
3646
  }
3648
3647
  const solvaPay = options.solvaPay || createSolvaPay();
3649
3648
  const limits = await solvaPay.apiClient.checkLimits({
3650
3649
  customerRef: purchaseResult.customerRef,
3651
3650
  productRef: activePurchase.productRef
3652
3651
  });
3653
- return deriveUsageSnapshot({ used, ...period, limits });
3652
+ return deriveUsageSnapshot({ ...period, limits });
3654
3653
  }
3655
3654
  async function trackUsageCore(request, body, options = {}) {
3656
3655
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solvapay/server",
3
- "version": "2.9.0",
3
+ "version": "2.10.0-preview-01847ff5f57eafaa4bca393519caeaf6856d968c",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",